Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToString doesn't skip default elements and attributes on sdf::ElementPtr returned from ToElement #867

Open
azeey opened this issue Mar 5, 2022 · 0 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@azeey
Copy link
Collaborator

azeey commented Mar 5, 2022

Environment

  • OS Version: any
  • Source or binary build? sdf12

Description

When using sdf::Element::ToString, libsdformat currently checks to see if an element or attribute is set by the user and skips printing it if it's not. This helps avoid verbose SDFormat files with elements and attributes having default values. However, this behavior only works if the sdf::ElementPtr was obtained from loading a file/string via sdf::readFile/sdf::readString or calling the Element function on DOM objects (e.g., sdf::Model::Element). It does not work if the sdf::ElementPtr is obtained form calling the ToElement function on DOM objects (e.g., sdf::Model::ToElement).

Example:

<?xml version="1.0" ?>
<sdf version="1.6">
  <model name="test_model">
    <link name="link"/>
  </model>
</sdf>

Using model->Element()->ToString("")

<model name='test_model'>
  <link name='link'/>
</model>

Using model->ToElement()->ToString("")

<model name='test_model'>
  <static>false</static>
  <self_collide>false</self_collide>
  <allow_auto_disable>true</allow_auto_disable>
  <enable_wind>false</enable_wind>
  <pose>0 0 0 0 -0 0</pose>
  <link name='link'>
    <pose>0 0 0 0 -0 0</pose>
    <inertial>
      <pose>0 0 0 0 -0 0</pose>
      <mass>1</mass>
      <inertia>
        <ixx>1</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1</iyy>
        <iyz>0</iyz>
        <izz>1</izz>
      </inertia>
    </inertial>
    <enable_wind>false</enable_wind>
  </link>
</model>

Relates to : #575, #842

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants