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

adding element default check #542

Merged
merged 16 commits into from
May 18, 2021
Merged

Conversation

marcoag
Copy link
Member

@marcoag marcoag commented Apr 19, 2021

Signed-off-by: Marco A. Gutierrez marco@openrobotics.org

🎉 New feature

Related to #287

Summary

There's already a check for the Attribute class so adding a default attribute and check functions for the Element class. To keep consistency with the code from in the Attribute class, we set it to true if the element was set false if it was created by default.

Since there's many cases where elements are added the base case considers that the element was not set by default so the value is true. When an attribute is being added by default, the SetSet(bool _value) should be called and the set attribute set to false, as done in parser.cc.

Thinks to take into account:

  • elementDescriptions will have the set attribute to true

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)

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@github-actions github-actions bot added the 🏰 citadel Ignition Citadel label Apr 19, 2021
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.

Looks good! I have a few naming related comments and a request for additional testing.

include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
src/Element_TEST.cc Outdated Show resolved Hide resolved
Marco A. Gutierrez added 2 commits May 7, 2021 10:21
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag force-pushed the marcoag/add_default_check branch from 4c88ec6 to 0a3dca6 Compare May 7, 2021 02:23
src/Element.cc Outdated Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
@azeey azeey requested a review from aaronchongth May 10, 2021 22:46
Marco A. Gutierrez added 3 commits May 11, 2021 08:40
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
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.

Looks like codecheck is failing on github actions. Can you fix the style errors?

src/parser.cc Outdated Show resolved Hide resolved
Comment on lines 42 to 106
sdf::ElementPtr element_ptr = root.Element();
EXPECT_TRUE(root.Element()->GetExplicitlySetInFile());

element_ptr = element_ptr->GetFirstElement();
EXPECT_TRUE(element_ptr->GetExplicitlySetInFile());

element_ptr = element_ptr->GetFirstElement();
EXPECT_TRUE(element_ptr->GetExplicitlySetInFile());

sdf::ElementPtr road_ptr = element_ptr->GetFirstElement();
EXPECT_FALSE(road_ptr->GetExplicitlySetInFile());

road_ptr = road_ptr->GetNextElement();
EXPECT_FALSE(road_ptr->GetExplicitlySetInFile());

element_ptr = element_ptr->GetNextElement();
EXPECT_TRUE(element_ptr->GetExplicitlySetInFile());

sdf::ElementPtr spherical_coords_ptr = element_ptr->GetFirstElement();
EXPECT_FALSE(spherical_coords_ptr->GetExplicitlySetInFile());

spherical_coords_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(spherical_coords_ptr->GetExplicitlySetInFile());

spherical_coords_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(spherical_coords_ptr->GetExplicitlySetInFile());

spherical_coords_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(spherical_coords_ptr->GetExplicitlySetInFile());

spherical_coords_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(spherical_coords_ptr->GetExplicitlySetInFile());

element_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(element_ptr->GetExplicitlySetInFile());

element_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(element_ptr->GetExplicitlySetInFile());

element_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(element_ptr->GetExplicitlySetInFile());

element_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(element_ptr->GetExplicitlySetInFile());

sdf::ElementPtr physics_ptr = element_ptr->GetFirstElement();
EXPECT_FALSE(physics_ptr->GetExplicitlySetInFile());

physics_ptr = physics_ptr->GetNextElement();
EXPECT_FALSE(physics_ptr->GetExplicitlySetInFile());

physics_ptr = physics_ptr->GetNextElement();
EXPECT_FALSE(physics_ptr->GetExplicitlySetInFile());

element_ptr = element_ptr->GetNextElement();
EXPECT_FALSE(element_ptr->GetExplicitlySetInFile());

sdf::ElementPtr scene_ptr = element_ptr->GetFirstElement();
EXPECT_FALSE(scene_ptr->GetExplicitlySetInFile());

scene_ptr = scene_ptr->GetNextElement();
EXPECT_FALSE(scene_ptr->GetExplicitlySetInFile());

scene_ptr = scene_ptr->GetNextElement();
EXPECT_FALSE(scene_ptr->GetExplicitlySetInFile());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be refactored into a recursive function? Or is there a particular order of traversal of the elements that prevents generalization?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe it can't be generalized as I don't see a trivial way to figure out weather a certain element is expected to be ExplicitlySetInFile or not

include/sdf/Element.hh Show resolved Hide resolved
include/sdf/Element.hh Outdated Show resolved Hide resolved
src/Element.cc Outdated Show resolved Hide resolved
src/Element.cc Outdated Show resolved Hide resolved
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag requested a review from azeey May 12, 2021 08:06
Marco A. Gutierrez and others added 5 commits May 12, 2021 16:25
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
… sibling elements

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
Add failing test showing that SetExplicitlySetInFile incorrectly sets the flag on sibling elements
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
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.

Sorry for the delay, this looks great! I haven't taken a detailed look at what default elements are getting added in during parsing of empty_road_sph_coords.sdf and empty_axis.sdf, but would it be a good idea to have the missing default elements added in as comments in the sdf file so we know what to expect? For example the physics element (I might be placing it wrong here),

<sdf ...>
<!-- <physics .../> -->
<world name="default">
  ...
</world>

Other than that, just a few minor comments about the tests and test files below, thanks!

src/Element_TEST.cc Show resolved Hide resolved
src/Element_TEST.cc Show resolved Hide resolved
test/integration/default_elements.cc Outdated Show resolved Hide resolved
test/integration/default_elements.cc Outdated Show resolved Hide resolved
test/integration/default_elements.cc Outdated Show resolved Hide resolved
test/sdf/empty_road_sph_coords.sdf Outdated Show resolved Hide resolved
Marco A. Gutierrez added 3 commits May 17, 2021 06:52
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>
@marcoag marcoag requested a review from aaronchongth May 17, 2021 07:54
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.

Thanks for making the changes!

@azeey azeey merged commit 9876a60 into gazebosim:sdf9 May 18, 2021
@marcoag marcoag deleted the marcoag/add_default_check branch May 19, 2021 07:50
@EricCousineau-TRI
Copy link
Collaborator

FYI @SeanCurtis-TRI

azeey added a commit to azeey/sdformat that referenced this pull request Jun 28, 2021
…zebosim#542)"

This reverts commit 9876a60.

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
@chapulina chapulina mentioned this pull request Jun 28, 2021
7 tasks
jennuine pushed a commit that referenced this pull request Jul 29, 2021
There's already a way to do this for the Attribute class so adding a similar function for the Element class. To keep consistency with the code from in the Attribute class, we set it to true if the element was set, and false if it was created by default.

Signed-off-by: Marco A. Gutierrez <marco@openrobotics.org>

Co-authored-by: Addisu Z. Taddese <addisu@openrobotics.org>
Signed-off-by: Jenn Nguyen <jenn@openrobotics.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏰 citadel Ignition Citadel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants