Skip to content

Commit

Permalink
11 ➡️ 12 (#627)
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <louise@openrobotics.org>
  • Loading branch information
chapulina authored Jul 17, 2021
2 parents 218a6f7 + 199c529 commit 6251baa
Show file tree
Hide file tree
Showing 43 changed files with 3,508 additions and 75 deletions.
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

### libsdformat 11.X.X (202X-XX-XX)

### libsdformat 11.2.2 (2021-07-01)

1. Fix segfault when checking for required elements in joint
* [Pull request #610](https://github.com/ignitionrobotics/sdformat/pull/610)

1. Add ValidateGraphs methods to Model/World
* [Pull request #601](https://github.com/ignitionrobotics/sdformat/pull/601)

1. Making `PrintValues()` and `ToString()` able to not print default elements
* [Pull request #575](https://github.com/ignitionrobotics/sdformat/pull/575)

### libsdformat 11.2.1 (2021-06-28)

1. Fix ABI break on sdf11
Expand Down
28 changes: 28 additions & 0 deletions include/sdf/Element.hh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ namespace sdf
/// \param[in] _prefix String value to prefix to the output.
public: void PrintValues(std::string _prefix) const;

/// \brief Output Element's values to stdout.
/// \param[in] _prefix String value to prefix to the output.
/// \param[in] _includeDefaultElements flag to print default elements.
/// \param[in] _includeDefaultAttributes flag to print default attributes.
public: void PrintValues(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes) const;

/// \brief Helper function for SDF::PrintDoc
///
/// This generates the SDF html documentation.
Expand All @@ -172,6 +180,18 @@ namespace sdf
/// \return The string representation.
public: std::string ToString(const std::string &_prefix) const;

/// \brief Convert the element values to a string representation.
/// Current behavior of ToString(const std::string &_prefix) can be
/// achieved by calling this function with _includeDefaultElements=true
/// and _includeDefaultAttributes=false
/// \param[in] _prefix String value to prefix to the output.
/// \param[in] _includeDefaultElements flag to include default elements.
/// \param[in] _includeDefaultAttributes flag to include default attributes.
/// \return The string representation.
public: std::string ToString(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes) const;

/// \brief Add an attribute value.
/// \param[in] _key Key value.
/// \param[in] _type Type of data the attribute will hold.
Expand Down Expand Up @@ -472,14 +492,22 @@ namespace sdf

/// \brief Generate a string (XML) representation of this object.
/// \param[in] _prefix arbitrary prefix to put on the string.
/// \param[in] _includeDefaultElements flag to include default elements.
/// \param[in] _includeDefaultAttributes flag to include default attributes.
/// \param[out] _out the std::ostreamstream to write output to.
private: void ToString(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes,
std::ostringstream &_out) const;

/// \brief Generate a string (XML) representation of this object.
/// \param[in] _prefix arbitrary prefix to put on the string.
/// \param[in] _includeDefaultElements flag to include default elements.
/// \param[in] _includeDefaultAttributes flag to include default attributes.
/// \param[out] _out the std::ostreamstream to write output to.
private: void PrintValuesImpl(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes,
std::ostringstream &_out) const;

/// \brief Create a new Param object and return it.
Expand Down
26 changes: 2 additions & 24 deletions include/sdf/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -221,30 +221,8 @@ namespace sdf
/// \param[in,out] _out The output stream.
/// \param[in] _err The error to output.
/// \return Reference to the given output stream
public: friend std::ostream &operator<<(std::ostream &_out,
const sdf::Error &_err)
{
std::string pathInfo = "";

if (_err.XmlPath().has_value())
pathInfo += _err.XmlPath().value();

if (_err.FilePath().has_value())
pathInfo += ":" + _err.FilePath().value();

if (_err.LineNumber().has_value())
pathInfo += ":L" + std::to_string(_err.LineNumber().value());

if (!pathInfo.empty())
pathInfo = "[" + pathInfo + "]: ";

_out << "Error Code "
<< static_cast<std::underlying_type<sdf::ErrorCode>::type>(
_err.Code()) << ": "
<< pathInfo
<< "Msg: " << _err.Message();
return _out;
}
public: friend SDFORMAT_VISIBLE std::ostream &operator<<(
std::ostream &_out, const sdf::Error &_err);

/// \brief Private data pointer.
IGN_UTILS_IMPL_PTR(dataPtr)
Expand Down
6 changes: 6 additions & 0 deletions include/sdf/Model.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ namespace sdf
/// an error code and message. An empty vector indicates no error.
public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);

/// \brief Check that the FrameAttachedToGraph and PoseRelativeToGraph
/// are valid.
/// \return Errors, which is a vector of Error objects. Each Error includes
/// an error code and message. An empty vector indicates no error.
public: Errors ValidateGraphs() const;

/// \brief Get the name of the model.
/// The name of the model should be unique within the scope of a World.
/// \return Name of the model.
Expand Down
6 changes: 6 additions & 0 deletions include/sdf/World.hh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ namespace sdf
/// an error code and message. An empty vector indicates no error.
public: Errors Load(sdf::ElementPtr _sdf, const ParserConfig &_config);

/// \brief Check that the FrameAttachedToGraph and PoseRelativeToGraph
/// are valid.
/// \return Errors, which is a vector of Error objects. Each Error includes
/// an error code and message. An empty vector indicates no error.
public: Errors ValidateGraphs() const;

/// \brief Get the name of the world.
/// \return Name of the world.
public: std::string Name() const;
Expand Down
11 changes: 11 additions & 0 deletions sdf/1.6/particle_emitter.sdf
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
</description>
</element>

<element name="particle_scatter_ratio" type="float" default="0.65" required="0">
<description>
This is used to determine the ratio of particles that will be detected
by sensors. Increasing the ratio means there is a higher chance of
particles reflecting and interfering with depth sensing, making the
emitter appear more dense. Decreasing the ratio decreases the chance
of particles reflecting and interfering with depth sensing, making it
appear less dense.
</description>
</element>

<include filename="pose.sdf" required="0"/>
<include filename="material.sdf" required="0"/>
</element>
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ set (sources
parser_urdf.cc
ParserConfig.cc
Param.cc
ParamPassing.cc
ParticleEmitter.cc
Pbr.cc
Physics.cc
Expand Down Expand Up @@ -197,6 +198,21 @@ if (BUILD_SDF_TEST)
target_link_libraries(UNIT_parser_urdf_TEST PRIVATE
${TinyXML2_LIBRARIES})
endif()

if (NOT WIN32)
set(SDF_BUILD_TESTS_EXTRA_EXE_SRCS ParamPassing.cc XmlUtils.cc parser.cc
parser_urdf.cc FrameSemantics.cc Converter.cc EmbeddedSdf.cc SDFExtension.cc Utils.cc)
sdf_build_tests(ParamPassing_TEST.cc)
if (NOT USE_INTERNAL_URDF)
target_compile_options(UNIT_ParamPassing_TEST PRIVATE ${URDF_CFLAGS})
if (${CMAKE_VERSION} VERSION_GREATER 3.13)
target_link_options(UNIT_ParamPassing_TEST PRIVATE ${URDF_LDFLAGS})
endif()
target_link_libraries(UNIT_ParamPassing_TEST PRIVATE ${URDF_LIBRARIES})
endif()
target_link_libraries(UNIT_ParamPassing_TEST PRIVATE
${TinyXML2_LIBRARIES})
endif()
endif()

sdf_add_library(${sdf_target} ${sources})
Expand Down
111 changes: 77 additions & 34 deletions src/Element.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,47 +485,59 @@ void Element::PrintDocLeftPane(std::string &_html, int _spacing,
}

void Element::PrintValuesImpl(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes,
std::ostringstream &_out) const
{
_out << _prefix << "<" << this->dataPtr->name;

Param_V::const_iterator aiter;
for (aiter = this->dataPtr->attributes.begin();
aiter != this->dataPtr->attributes.end(); ++aiter)
if (this->GetExplicitlySetInFile() || _includeDefaultElements)
{
// Only print attribute values if they were set
// TODO(anyone): GetRequired is added here to support up-conversions where a
// new required attribute with a default value is added. We would have
// better separation of concerns if the conversion process set the required
// attributes with their default values.
if ((*aiter)->GetSet() || (*aiter)->GetRequired())
{
_out << " " << (*aiter)->GetKey() << "='"
<< (*aiter)->GetAsString() << "'";
}
}
_out << _prefix << "<" << this->dataPtr->name;

if (this->dataPtr->elements.size() > 0)
{
_out << ">\n";
ElementPtr_V::const_iterator eiter;
for (eiter = this->dataPtr->elements.begin();
eiter != this->dataPtr->elements.end(); ++eiter)
Param_V::const_iterator aiter;
for (aiter = this->dataPtr->attributes.begin();
aiter != this->dataPtr->attributes.end(); ++aiter)
{
(*eiter)->ToString(_prefix + " ", _out);
// Only print attribute values if they were set
// TODO(anyone): GetRequired is added here to support up-conversions where
// a new required attribute with a default value is added. We would have
// better separation of concerns if the conversion process set the
// required attributes with their default values.
if ((*aiter)->GetSet() || (*aiter)->GetRequired() ||
_includeDefaultAttributes)
{
_out << " " << (*aiter)->GetKey() << "='"
<< (*aiter)->GetAsString() << "'";
}
}
_out << _prefix << "</" << this->dataPtr->name << ">\n";
}
else
{
if (this->dataPtr->value)

if (this->dataPtr->elements.size() > 0)
{
_out << ">" << this->dataPtr->value->GetAsString()
<< "</" << this->dataPtr->name << ">\n";
_out << ">\n";
ElementPtr_V::const_iterator eiter;
for (eiter = this->dataPtr->elements.begin();
eiter != this->dataPtr->elements.end(); ++eiter)
{
if ((*eiter)->GetExplicitlySetInFile() || _includeDefaultElements)
{
(*eiter)->ToString(_prefix + " ",
_includeDefaultElements,
_includeDefaultAttributes,
_out);
}
}
_out << _prefix << "</" << this->dataPtr->name << ">\n";
}
else
{
_out << "/>\n";
if (this->dataPtr->value)
{
_out << ">" << this->dataPtr->value->GetAsString()
<< "</" << this->dataPtr->name << ">\n";
}
else
{
_out << "/>\n";
}
}
}
}
Expand All @@ -534,23 +546,54 @@ void Element::PrintValuesImpl(const std::string &_prefix,
void Element::PrintValues(std::string _prefix) const
{
std::ostringstream ss;
PrintValuesImpl(_prefix, ss);
PrintValuesImpl(_prefix, true, false, ss);
std::cout << ss.str();
}

/////////////////////////////////////////////////
void Element::PrintValues(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes) const
{
std::ostringstream ss;
PrintValuesImpl(_prefix,
_includeDefaultElements,
_includeDefaultAttributes,
ss);
std::cout << ss.str();
}

/////////////////////////////////////////////////
std::string Element::ToString(const std::string &_prefix) const
{
std::ostringstream out;
this->ToString(_prefix, out);
this->ToString(_prefix, true, false, out);
return out.str();
}

/////////////////////////////////////////////////
std::string Element::ToString(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes) const
{
std::ostringstream out;
this->ToString(_prefix,
_includeDefaultElements,
_includeDefaultAttributes,
out);
return out.str();
}

/////////////////////////////////////////////////
void Element::ToString(const std::string &_prefix,
bool _includeDefaultElements,
bool _includeDefaultAttributes,
std::ostringstream &_out) const
{
PrintValuesImpl(_prefix, _out);
PrintValuesImpl(_prefix,
_includeDefaultElements,
_includeDefaultAttributes,
_out);
}

/////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 6251baa

Please sign in to comment.