gazebosim/sdformat

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

オープン

#867 opened on 2022/03/05

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)C++ (122 件のフォーク)auto 404
bughelp wanted

Repository metrics

Stars
 (216 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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 : https://github.com/ignitionrobotics/sdformat/pull/575, https://github.com/ignitionrobotics/sdformat/pull/842

コントリビューターガイド