gazebosim/sdformat

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

開放

#867 建立於 2022年3月5日

 (0 則留言) (0 個反應) (0 位負責人)C++ (122 個分叉)auto 404
bughelp wanted

倉庫指標

星標
 (216 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南