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

Store include info in Element #509

Merged
merged 6 commits into from
Mar 23, 2021
Merged

Conversation

azeey
Copy link
Collaborator

@azeey azeey commented Mar 11, 2021

🎉 New feature

Closes #401

Summary

This stores the contents of <include> inside the Element loaded from the included file.
For example, given the following SDFormat:

<sdf version = '1.8'>
  <world name='default'>
    <include>
      <uri>model_uri</uri>
      <pose>1 2 3 0 0 0</pose>
    </include>
  </world>
</sdf>

The ElementPtr associated with the model loaded from 'model_uri' will
have its includeElement set to

    <include>
      <uri>model_uri</uri>
      <pose>1 2 3 0 0 0</pose>
    </include>

This can be used to retrieve additional information available under the tag after the entity has been loaded (eg. <name>, <pose>, <plugin>, etc.). An example use case for this is when saving a loaded world back to SDFormat in such a way that the <include> tags are left intact.

This also deprecates the functions Element::SetInclude and Element::GetInclude since they were never used. Based on the code in Element::ToString: https://github.com/osrf/sdformat/blob/54d9018599ce6605cee13d372c7dc51f0c0fcd2d/src/Element.cc#L528-L537
I think these functions were added a long time ago when the syntax for including files was <include filename="path">, which is not valid SDFormat anymore.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Code check passed (In source directory, run sh tools/code_check.sh)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge

Signed-off-by: Addisu Z. Taddese <[email protected]>
@azeey azeey self-assigned this Mar 11, 2021
@github-actions github-actions bot added the 🏢 edifice Ignition Edifice label Mar 11, 2021
Signed-off-by: Addisu Z. Taddese <[email protected]>
Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI left a comment

Choose a reason for hiding this comment

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

Sweet! Minor nits, and a testing update.

src/Element_TEST.cc Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
const std::string modelRootPath = sdf::filesystem::append(
PROJECT_SOURCE_PATH, "test", "integration", "model");

sdf::setFindCallback(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit Consider using non-global version? ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using non-global version in 2631da1

test/integration/nested_model.cc Show resolved Hide resolved
auto *testModel2 = test2->ModelByIndex(0);
ASSERT_NE(nullptr, testModel2);
checkIncludeElem(
testModel2->Element()->GetIncludeElement(), "test_model", "test_model");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not fully 1000% convinced that this preserves the information across load str -> element -> dump str.

Can you add a quick idempotent check that the include markup is preserved as-is?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Per f2f, this implies that the //include tags would be preserved, which should not be the default libsdformat behavior.

Perhaps there should be an option (API + cmdline) to preserve includes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I created an issue to capture this: #522. How about we tackle that in a follow up PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds great!

Copy link
Collaborator

@jennuine jennuine left a comment

Choose a reason for hiding this comment

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

Looks good! Did a first pass and left some minor comments. I'm curious, is includeFilename needed anymore?

If so, should Element::ToString() be updated since <include filename="path"> is no longer valid? (or removed)
https://github.com/osrf/sdformat/blob/69dc1542641df2586d2e8dcfb02e307a8a865fdb/src/Element.cc#L535-L536

src/Element.cc Show resolved Hide resolved
Copy link
Collaborator

@aaronchongth aaronchongth left a comment

Choose a reason for hiding this comment

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

This is awesome!

On the topic of the ToString function, would a good way of re-implementing it be to use the output of PrintValuesImpl, but modify the fields depending on what is stored in includeElement, the pose, static flags, etc?

src/Element.cc Show resolved Hide resolved
@chapulina chapulina added the beta Targeting beta release of upcoming collection label Mar 18, 2021
Signed-off-by: Addisu Z. Taddese <[email protected]>
@azeey
Copy link
Collaborator Author

azeey commented Mar 22, 2021

On the topic of the ToString function, would a good way of re-implementing it be to use the output of PrintValuesImpl, but modify the fields depending on what is stored in includeElement, the pose, static flags, etc?

I think this is actually how it works currently. The parser overrides all those parameters of the included model based on the contents of the <include> element when it first loads the include model: https://github.com/osrf/sdformat/blob/2631da14dff94ea7c66e2480be626ffd3e33e72e/src/parser.cc#L1225-L1291

Copy link
Collaborator

@jennuine jennuine left a comment

Choose a reason for hiding this comment

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

LGTM! Minor nit: I think one of your comments is missing "is" in the statement but feel free to disregard

include/sdf/Element.hh Outdated Show resolved Hide resolved
@azeey azeey merged commit ed13390 into gazebosim:master Mar 23, 2021
@azeey azeey deleted the save_include_uri branch March 23, 2021 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection 🏢 edifice Ignition Edifice
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should store an included model's source file name
5 participants