38 msgs::FuelMetadata &_meta)
40 gz::msgs::FuelMetadata meta;
45 [](
int c) {return !std::isspace(c);}));
49 [](
int c) {return !std::isspace(c);}).base(), _s.end());
55 tinyxml2::XMLDocument modelConfigDoc;
56 if (modelConfigDoc.Parse(_modelConfigStr.
c_str()) !=
57 tinyxml2::XML_SUCCESS)
59 std::cerr <<
"Unable to parse model config XML string.\n";
64 tinyxml2::XMLElement *topElement = modelConfigDoc.FirstChildElement(
69 topElement = modelConfigDoc.FirstChildElement(
"world");
72 std::cerr <<
"Model config string does not contain a "
73 <<
"<model> or <world> element\n";
80 tinyxml2::XMLElement *elem = topElement->FirstChildElement(
"name");
81 if (!elem || !elem->GetText())
83 std::cerr <<
"Model config string does not contain a <name> element\n";
86 meta.set_name(trimmed(elem->GetText()));
89 elem = topElement->FirstChildElement(
"version");
90 if (elem && elem->GetText())
92 auto version =
std::stoi(trimmed(elem->GetText()));
93 meta.set_version(version);
97 elem = topElement->FirstChildElement(
"description");
98 if (elem && elem->GetText())
99 meta.set_description(trimmed(elem->GetText()));
102 elem = topElement->FirstChildElement(
"depend");
105 auto modelElem = elem->FirstChildElement(
"model");
108 auto uriElem = modelElem->FirstChildElement(
"uri");
111 auto dependency = meta.add_dependencies();
112 dependency->set_uri(uriElem->GetText());
115 elem = elem->NextSiblingElement(
"depend");
119 elem = topElement->FirstChildElement(
"author");
122 gz::msgs::FuelMetadata::Contact *author = meta.add_authors();
124 if (elem->FirstChildElement(
"name") &&
125 elem->FirstChildElement(
"name")->GetText())
127 author->set_name(trimmed(elem->FirstChildElement(
"name")->GetText()));
129 if (elem->FirstChildElement(
"email") &&
130 elem->FirstChildElement(
"email")->GetText())
133 trimmed(elem->FirstChildElement(
"email")->GetText()));
136 elem = elem->NextSiblingElement(
"author");
140 elem = topElement->FirstChildElement(
"sdf");
144 if (elem->GetText() && elem->Attribute(
"version"))
150 gz::msgs::Version *verMsg;
154 meta.mutable_model()->mutable_file_format()->set_name(
"sdf");
156 meta.mutable_model()->mutable_file_format()->mutable_version();
157 meta.mutable_model()->set_file(trimmed(elem->GetText()));
161 meta.mutable_world()->mutable_file_format()->set_name(
"sdf");
163 meta.mutable_world()->mutable_file_format()->mutable_version();
164 meta.mutable_world()->set_file(trimmed(elem->GetText()));
167 verMsg->set_major(ver.
Major());
168 verMsg->set_minor(ver.
Minor());
169 verMsg->set_patch(ver.
Patch());
171 verMsg->set_build(ver.
Build());
175 elem = elem->NextSiblingElement(
"sdf");
177 if (meta.model().file().empty() && meta.world().file().empty())
179 std::cerr <<
"Model config string does not contain an <sdf> element\n";
183 _meta.CopyFrom(meta);
194 if (_meta.has_model())
196 if (_meta.model().file_format().name() !=
"sdf")
198 std::cerr <<
"Model _metadata does not contain an SDF file.\n";
202 out <<
"<?xml version='1.0'?>\n"
205 << _meta.model().file_format().version().major()
206 <<
"." << _meta.model().file_format().version().minor() <<
"'>"
207 << _meta.model().file() <<
"</sdf>\n";
211 if (_meta.world().file_format().name() !=
"sdf")
213 std::cerr <<
"World _metadata does not contain an SDF file.\n";
217 out <<
"<?xml version='1.0'?>\n"
220 << _meta.world().file_format().version().major()
221 <<
"." << _meta.world().file_format().version().minor() <<
"'>"
222 << _meta.world().file() <<
"</sdf>\n";
225 out <<
" <name>" << _meta.name() <<
"</name>\n"
226 <<
" <version>" << _meta.version() <<
"</version>\n"
227 <<
" <description>" << _meta.description() <<
"</description>\n";
230 for (
int i = 0; i < _meta.authors_size(); ++i)
233 <<
" <name>" << _meta.authors(i).name() <<
"</name>\n"
234 <<
" <email>" << _meta.authors(i).email() <<
"</email>\n"
239 for (
int i = 0; i < _meta.dependencies_size(); ++i)
243 <<
" <uri>" << _meta.dependencies(i).uri() <<
"</uri>\n"
249 if (_meta.has_model())
250 out <<
" </model>\n";
252 out <<
" </world>\n";
254 _modelConfigStr = out.
str();