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

贡献者指南