Skip to content

Fix parsing 'type' attibutes in plugins #809

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

Merged
merged 5 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Plugin_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ TEST(DOMPlugin, LoadWithChildren)
std::string pluginStr = R"(<plugin name='3D View' filename='MinimalScene'>
<ignition-gui>
<title>3D View</title>
<property type='bool' key='showTitleBar'>false</property>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is related to unrecognized type values, like ignition.msgs.Boolean in triggered_publisher.sdf

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just fixing the test failure. With my change, the parser is now converting false into 0.

I haven't touched the parser much before, so I'd appreciate some guidance on the proper fix. My assumption from #689 is that we only want to parse the /pose@type attributes here, but don't affect the rest, that's why I added the extra check for "pose" with a TODO to remove the special type handling from that function to a pose-specific function. But I suspect I may be missing some important detail.

<property type='bool' key='showTitleBar'>0</property>
<property type='string' key='state'>docked</property>
</ignition-gui>
<engine>ogre</engine>
Expand Down
12 changes: 7 additions & 5 deletions src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1912,13 +1912,13 @@ void copyChildren(ElementPtr _sdf,
for (elemXml = _xml->FirstChildElement(); elemXml;
elemXml = elemXml->NextSiblingElement())
{
std::string elem_name = elemXml->Name();
std::string elemName = elemXml->Name();

if (_sdf->HasElementDescription(elem_name))
if (_sdf->HasElementDescription(elemName))
{
if (!_onlyUnknown)
{
sdf::ElementPtr element = _sdf->AddElement(elem_name);
sdf::ElementPtr element = _sdf->AddElement(elemName);

// FIXME: copy attributes
for (const auto *attribute = elemXml->FirstAttribute();
Expand All @@ -1941,13 +1941,15 @@ void copyChildren(ElementPtr _sdf,
{
ElementPtr element(new Element);
element->SetParent(_sdf);
element->SetName(elem_name);
element->SetName(elemName);
std::optional<std::string> typeName = std::nullopt;
for (const tinyxml2::XMLAttribute *attribute = elemXml->FirstAttribute();
attribute; attribute = attribute->Next())
{
const std::string attributeName(attribute->Name());
if (attributeName == "type")
// TODO(chapulina) This isn't a good place to parse pose-specific
// attributes
if (elemName == "pose" && attributeName == "type")
typeName = attribute->Value();

element->AddAttribute(attributeName, "string", "", 1, "");
Expand Down