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

Fix flattening logic for nested model names (sdf6) #597

Merged
merged 9 commits into from
Jun 30, 2021

Conversation

j-rivero
Copy link
Contributor

🦟 Bug fix

Fixes #574

Summary

I think that the current flattening logic deal with names using <, >, \ or ' as separators. That leaves out some cases were the user use composed names (component::element) since the separator here is ::. I added some logic to deal with use cases were element is present in different situations with other components of the name:

  • case A: ::component1::element::component2
  • case B. >element::component
  • case C. ::component::element<

Checklist

  • Signed all commits for DCO
  • Added tests

Note to maintainers: Remember to use Squash-Merge

@j-rivero j-rivero changed the base branch from fix_pose_nested_models_sdf6 to sdf6 June 21, 2021 15:18
@j-rivero j-rivero changed the title Fix flattening logic for nested model names Fix flattening logic for nested model names (sdf6) Jun 21, 2021
j-rivero added 4 commits June 21, 2021 18:02
When nested models use names composed by several elements
(i.e: my_model::link) these were not converted by the
flattening logic inside parser.cc. The change makes the
logic to work with composed names.

Added a test to check that this is indeed working as
expected.

Signed-off-by: Jose Luis Rivero <[email protected]>
Signed-off-by: Jose Luis Rivero <[email protected]>
@j-rivero j-rivero force-pushed the nested_flattening_naming branch from 5e2362a to 338d966 Compare June 21, 2021 16:02
@chapulina chapulina requested a review from azeey June 21, 2021 18:04
Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

I think we only need to handle case B.

Case A handles a name that starts with :: and I don't think that's valid in SDFormat.

Case C handles a name where the old name is preceded by some other name, some_name::old_name, and it renames it to some_name::new_prefix::old_name. But for some_name::old_name to exist, there must be a nested model called some_name and a child element of that nested model called old_name:

<model name='included_model'>
  <link name='L1'/>
  <model name='some_name'>
     <link name='old_name'/>
  </model>
  <joint name='J1' type='fixed'>
      <parent>some_name::old_name</parent>
      <child>L1</child>
   </joint>
</model>

But if this was the case, case B would have already renamed some_name to new_prefix::some_name and so we would want <parent>some_name::old_name</parent> to be renamed to <parent>new_prefix::some_name::old_name</parent> not<parent>some_name::new_prefix::old_name</parent>

src/parser.cc Outdated Show resolved Hide resolved
src/parser.cc Outdated Show resolved Hide resolved
@j-rivero
Copy link
Contributor Author

I think we only need to handle case B.

I think you are right, changed in 4b97716

src/parser.cc Outdated
Comment on lines 1133 to 1138
std::string::size_type found = nameWithNestedPrefix.find(oldName);
if (found != std::string::npos)
{
std::string nestedPrefix = nameWithNestedPrefix;
nestedPrefix.erase(found, oldName.length());
replace_all(str, nestedPrefix + nestedPrefix, nestedPrefix);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this still needed after removing some of the replace_all cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Umm I think you are right, this is not needed anymore after reducing the cases to just one. Removed 0f7ccf8

{
std::string elemName = elem->Get<std::string>("name");
std::string newName = modelName + "::" + elemName;
replace[elemName] = newName;
}

if (elem->GetName() == "link")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Quick note that this will be in conflict with #596, but we'll definitely need the line from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1 going to merge both, I'll keep an eye on it, tests should fail we miss it.

@j-rivero j-rivero merged commit e17aef4 into sdf6 Jun 30, 2021
@j-rivero j-rivero deleted the nested_flattening_naming branch June 30, 2021 12:34
@scpeters
Copy link
Member

scpeters commented Aug 4, 2021

should this be merged forward to sdf9?

@azeey azeey mentioned this pull request Nov 5, 2021
scpeters added a commit that referenced this pull request Nov 13, 2021
The IncludeFlatteningNames test added in #597 is no longer
relevant because nested model names are no longer flattened.
The model used by the test is removed as well since it is
not used elsewhere.

Signed-off-by: Steve Peters <[email protected]>
@scpeters scpeters mentioned this pull request Nov 13, 2021
@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-01-10/1228/1

@osrf-triage
Copy link

This pull request has been mentioned on Gazebo Community. There might be relevant details there:

https://community.gazebosim.org/t/new-ignition-releases-2022-03-25-fortress-edifice-citadel/1343/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants