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

Reference local schema files #535

Draft
wants to merge 9 commits into
base: sdf9
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions sdf/1.7/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
set (sdfs
actor.sdf
air_pressure.sdf
altimeter.sdf
atmosphere.sdf
audio_source.sdf
audio_sink.sdf
battery.sdf
box_shape.sdf
camera.sdf
collision_engine.sdf
collision.sdf
contact.sdf
cylinder_shape.sdf
Expand All @@ -21,6 +23,7 @@ set (sdfs
imu.sdf
inertial.sdf
joint.sdf
lidar.sdf
light.sdf
light_state.sdf
link.sdf
Expand Down Expand Up @@ -52,6 +55,7 @@ set (sdfs
state.sdf
surface.sdf
transceiver.sdf
urdf.sdf
visual.sdf
world.sdf
)
Expand Down
2 changes: 1 addition & 1 deletion sdf/1.7/light_state.sdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- State information for a light -->
<element name="light" required="*">
<element name="light_state" required="*">
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 sure if we should be changing these names because they are actually used by Gazebo-classic. If I remember correctly, keeping the original names causes an issue with the generated xsd. I was hoping we can fix that issue without renaming these elements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed them back in aef3ab8

<description>Light state</description>

<attribute name="name" type="string" default="__default__" required="1">
Expand Down
2 changes: 1 addition & 1 deletion sdf/1.7/link_state.sdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- State information for a link -->
<element name="link" required="*">
<element name="link_state" required="*">
<description>Link state</description>

<attribute name="name" type="string" default="__default__" required="1">
Expand Down
2 changes: 1 addition & 1 deletion sdf/1.7/model_state.sdf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- State information for a model -->
<element name="model" required="*">
<element name="model_state" required="*">
<description>Model state</description>

<attribute name="name" type="string" default="__default__" required="1">
Expand Down
36 changes: 31 additions & 5 deletions tools/xmlschema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ def printElem(_file, _spaces, _elem)
_elem.get_elements("element").each do |elem|
printElem(_file, _spaces+6, elem)
end

_elem.get_elements("include").each do |inc|
printIncludeRef(_file, _spaces+6, inc);
end

_file.printf("%*s</xsd:choice>\n", _spaces+4, "")

# Print the attributes for the complex type
Expand Down Expand Up @@ -130,8 +135,7 @@ def printIncludeRef(_file, _spaces, _inc)

#################################################
def printInclude(_file, _spaces, _attr)
loc = "http://sdformat.org/schemas/"
loc += _attr.attributes['filename'].sub("\.sdf","\.xsd")
loc = _attr.attributes['filename'].sub("\.sdf","\.xsd")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I should have been more clear in the issue description in that we do still want to be able to have xsd files that can be stored on sdformat.org/schemas. At a glance, this looks like it will embed the absolute paths of the local machine in to the generated schemas. That's useful for tests, but I think we do still want this script to generate xsd that can be uploaded to the website.

I wonder if instead of using <xsd:include>, we just paste the contents and generate one xsd file that can be used for both testing and for the website. This might also solve the problem I mentioned in https://github.com/osrf/sdformat/pull/535/files#r609021282

Copy link
Collaborator Author

@jennuine jennuine Apr 23, 2021

Choose a reason for hiding this comment

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

Thanks for the tip! How's this? aef3ab8

_file.printf("%*s<xsd:include schemaLocation='%s'/>\n", _spaces, "", loc)
end

Expand Down Expand Up @@ -181,22 +185,44 @@ def printXSD(_file, _spaces, _elem)
printDocumentation(_file, _spaces, _elem.elements["description"].text)
end

_file.printf("%*s<xsd:include schemaLocation='http://sdformat.org/schemas/types.xsd'/>\n", _spaces, "")
_file.printf("%*s<xsd:include schemaLocation='#{$path}/schema/types.xsd'/>\n", _spaces, "")

includedSchemas = []

# Print the inclues for the complex type
# Print the includes for the complex type
# The includes must appear first
_elem.get_elements("include").each do |inc|
filename = inc.attributes['filename']
includedSchemas << filename

printInclude(_file, _spaces, inc);
end

# Print the nested includes for the complex type
# that have not already been included
_elem.get_elements("element").each do |elem|
elem.get_elements("include").each do |inc|
filename = inc.attributes['filename']

if includedSchemas.grep(filename).size == 0
printInclude(_file, _spaces, inc)
end
end
end

if _elem.get_elements("element").size > 0 ||
_elem.get_elements("attribute").size > 0 ||
_elem.get_elements("include").size > 0

# Print the complex type with a name
_file.printf("%*s<xsd:element name='%s'>\n", _spaces, "",
_elem.attributes["name"])
_file.printf("%*s<xsd:complexType>\n", _spaces+2, "")

if _elem.attributes['name'] == "pose"
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we use printElem as I suggested, I'm not sure if we need a special treatment of pose here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed 75b33b6

_file.printf("%*s<xsd:complexType mixed='true'>\n", _spaces+2, "")
else
_file.printf("%*s<xsd:complexType>\n", _spaces+2, "")
end

if _elem.attributes['name'] != "plugin" &&
(_elem.get_elements("element").size > 0 ||
Expand Down