9 #include <QDomDocument> 12 #include <QDomNodeList> 13 #include <QMessageBox> 16 : m_typeRegistry(typeRegistry)
27 in.open(QFile::ReadOnly);
35 QList<ArenaElement*> loadedElements;
36 bool loadingSuccessful =
true;
40 QDomNodeList nodes = doc.elementsByTagName(
"element");
41 for(
int i = 0; i < nodes.count(); i++)
43 QDomElement node = nodes.at(i).toElement();
44 QString type = node.attribute(
"type");
47 qDebug() <<
"[Rescue Arena Designer] Error: Empty element type" 48 <<
"specified in" << filename <<
". Ignoring.";
54 qDebug() <<
"[Rescue Arena Designer] Error: Unknown element type" 55 << type <<
"in" << filename <<
". Ignoring.";
60 loadedElements.append(element);
67 loadingSuccessful =
false;
69 QTextStream(&msg) <<
"There's an error in the arena XML file in line " 72 QMessageBox msgBox(QMessageBox::Critical,
73 QString(
"Error while loading arena XML file"),
79 if (loadingSuccessful)
91 out.open(QFile::WriteOnly);
93 if (out.error() != QFile::NoError)
94 qDebug() <<
"[Hector Arena Designer] Error saving arena file:" << out.errorString();
96 QXmlStreamWriter writer(&out);
98 writer.setAutoFormatting(
true);
100 writer.writeStartDocument();
101 writer.writeStartElement(
"elements");
104 element->
save(writer);
106 writer.writeEndElement();
107 writer.writeEndDocument();
115 out.open(QFile::WriteOnly);
117 QXmlStreamWriter writer(&out);
119 writer.setAutoFormatting(
true);
121 writer.writeStartDocument();
123 writer.writeStartElement(
"gazebo:world");
124 writer.writeAttribute(
"xmlns:gazebo",
"http://playerstage.sourceforge.net/gazebo/xmlschema/#gz");
125 writer.writeAttribute(
"xmlns:model",
"http://playerstage.sourceforge.net/gazebo/xmlschema/#model");
126 writer.writeAttribute(
"xmlns:body",
"http://playerstage.sourceforge.net/gazebo/xmlschema/#body");
127 writer.writeAttribute(
"xmlns:geom",
"http://playerstage.sourceforge.net/gazebo/xmlschema/#geom");
128 writer.writeAttribute(
"xmlns:physics",
"http://playerstage.sourceforge.net/gazebo/xmlschema/#physics");
129 writer.writeAttribute(
"xmlns:rendering",
"http://playerstage.sourceforge.net/gazebo/xmlschema/#rendering");
131 writer.writeStartElement(
"physics:ode");
132 writer.writeTextElement(
"stepTime",
"0.001");
133 writer.writeTextElement(
"gravity",
"0 0 -9.81");
136 writer.writeTextElement(
"cfm",
"10e-10");
139 writer.writeTextElement(
"erp",
"0.2");
140 writer.writeTextElement(
"stepType",
"quick");
141 writer.writeTextElement(
"stepIters",
"10");
142 writer.writeTextElement(
"contactMaxCorrectingVel",
"100.0");
143 writer.writeTextElement(
"contactSurfaceLayer",
"0.001");
144 writer.writeTextElement(
"updateRate",
"-0.1");
146 writer.writeEndElement();
148 writer.writeStartElement(
"rendering:gui");
150 writer.writeTextElement(
"type",
"flkt");
151 writer.writeTextElement(
"size",
"800 600");
152 writer.writeTextElement(
"pos",
"0 0");
154 writer.writeStartElement(
"frames");
156 writer.writeStartElement(
"row");
157 writer.writeAttribute(
"height",
"100%");
158 writer.writeStartElement(
"camera");
159 writer.writeAttribute(
"width",
"100%");
161 writer.writeTextElement(
"xyz",
"0 0 3");
162 writer.writeTextElement(
"rpy",
"0 90 90");
165 writer.writeEndElement();
168 writer.writeEndElement();
171 writer.writeEndElement();
174 writer.writeEndElement();
176 writer.writeStartElement(
"rendering:ogre");
177 writer.writeTextElement(
"ambient",
"0.2 0.2 0.2 1.0");
178 writer.writeStartElement(
"sky");
179 writer.writeTextElement(
"material",
"Gazebo/CloudySky");
181 writer.writeEndElement();
182 writer.writeTextElement(
"grid",
"false");
184 writer.writeEndElement();
186 writer.writeStartElement(
"model:renderable");
187 writer.writeAttribute(
"name",
"point_white");
188 writer.writeTextElement(
"xyz",
"0 0 20");
189 writer.writeTextElement(
"rpy",
"0 50 50");
190 writer.writeTextElement(
"enableGravity",
"false");
191 writer.writeStartElement(
"light");
192 writer.writeTextElement(
"type",
"directional");
193 writer.writeTextElement(
"diffuseColor",
"0.7 0.7 0.7");
194 writer.writeTextElement(
"specularColor",
"0.1 0.1 0.1");
195 writer.writeTextElement(
"attenuation",
"0.2 0.1 0");
196 writer.writeTextElement(
"range",
"100.0");
198 writer.writeEndElement();
199 writer.writeEndElement();
218 writer.writeStartElement(
"model:physical");
219 writer.writeAttribute(
"name",
"gplane");
221 writer.writeTextElement(
"xyz",
"0 0 0");
222 writer.writeTextElement(
"rpy",
"0 0 0");
223 writer.writeTextElement(
"static",
"true");
225 writer.writeStartElement(
"body:plane");
226 writer.writeAttribute(
"name",
"plane");
228 writer.writeStartElement(
"geom:plane");
229 writer.writeAttribute(
"name",
"plane");
231 writer.writeTextElement(
"laserRetro",
"2000.0");
232 writer.writeTextElement(
"mu1",
"50.0");
233 writer.writeTextElement(
"mu2",
"50.0");
235 writer.writeTextElement(
"kp",
"1000000000.0");
236 writer.writeTextElement(
"kd",
"1.0");
238 writer.writeTextElement(
"normal",
"0 0 1");
239 writer.writeTextElement(
"size",
"120 120");
241 writer.writeTextElement(
"segments",
"10 10");
242 writer.writeTextElement(
"uvTile",
"100 100");
244 writer.writeTextElement(
"material",
"Gazebo/GrayGrid");
248 writer.writeEndElement();
250 writer.writeEndElement();
252 writer.writeEndElement();
257 writer.writeEndElement();
258 writer.writeEndDocument();
266 out.open(QFile::WriteOnly);
268 QXmlStreamWriter writer(&out);
270 writer.setAutoFormatting(
true);
271 writer.setAutoFormattingIndent(2);
273 writer.writeStartDocument();
275 writer.writeStartElement(
"sdf");
276 writer.writeAttribute(
"version",
"1.4");
278 writer.writeStartElement(
"world");
279 writer.writeAttribute(
"name",
"default");
281 writer.writeStartElement(
"scene");
282 writer.writeTextElement(
"ambient",
"0.5 0.5 0.5 1");
283 writer.writeTextElement(
"background",
"0.5 0.5 0.5 1");
284 writer.writeTextElement(
"shadows",
"false");
285 writer.writeEndElement();
287 writer.writeStartElement(
"physics");
288 writer.writeAttribute(
"type",
"ode");
290 writer.writeTextElement(
"gravity",
"0 0 -9.81");
292 writer.writeStartElement(
"ode");
294 writer.writeStartElement(
"solver");
295 writer.writeTextElement(
"type",
"quick");
296 writer.writeTextElement(
"iters",
"10");
297 writer.writeTextElement(
"sor",
"1.3");
298 writer.writeEndElement();
300 writer.writeStartElement(
"constraints");
301 writer.writeTextElement(
"cfm",
"0.0");
302 writer.writeTextElement(
"erp",
"0.2");
303 writer.writeTextElement(
"contact_max_correcting_vel",
"100.0");
304 writer.writeTextElement(
"contact_surface_layer",
"0.001");
305 writer.writeEndElement();
307 writer.writeEndElement();
308 writer.writeTextElement(
"real_time_update_rate",
"1000");
309 writer.writeTextElement(
"max_step_size",
"0.001");
311 writer.writeEndElement();
313 writer.writeStartElement(
"light");
314 writer.writeAttribute(
"type",
"directional");
315 writer.writeAttribute(
"name",
"directional_light_1");
316 writer.writeTextElement(
"cast_shadows",
"false");
318 writer.writeTextElement(
"pose",
"0 0 30 0.1 0.1 0");
319 writer.writeTextElement(
"diffuse",
"1.0 1.0 1.0 1");
320 writer.writeTextElement(
"specular",
".1 .1 .1 1");
322 writer.writeStartElement(
"attenuation");
323 writer.writeTextElement(
"range",
"300");
324 writer.writeEndElement();
326 writer.writeTextElement(
"direction",
"0.1 0.1 -1");
327 writer.writeEndElement();
329 writer.writeStartElement(
"model");
330 writer.writeAttribute(
"name",
"plane_model");
331 writer.writeTextElement(
"static",
"true");
333 writer.writeStartElement(
"link");
334 writer.writeAttribute(
"name",
"plane_model_link");
336 writer.writeStartElement(
"collision");
337 writer.writeAttribute(
"name",
"plane_model_collision");
339 writer.writeStartElement(
"geometry");
341 writer.writeStartElement(
"plane");
342 writer.writeTextElement(
"normal",
"0 0 1");
343 writer.writeEndElement();
345 writer.writeEndElement();
347 writer.writeStartElement(
"surface");
349 writer.writeStartElement(
"friction");
351 writer.writeStartElement(
"ode");
352 writer.writeTextElement(
"mu",
"10.0");
353 writer.writeTextElement(
"mu2",
"10.0");
354 writer.writeTextElement(
"fdir1",
"0 0 0");
355 writer.writeTextElement(
"slip1",
"0");
356 writer.writeTextElement(
"slip2",
"0");
357 writer.writeEndElement();
359 writer.writeEndElement();
361 writer.writeStartElement(
"bounce");
362 writer.writeTextElement(
"restitution_coefficient",
"0");
363 writer.writeTextElement(
"threshold",
"1000000.0");
364 writer.writeEndElement();
366 writer.writeStartElement(
"contact");
368 writer.writeStartElement(
"ode");
369 writer.writeTextElement(
"soft_cfm",
"0");
370 writer.writeTextElement(
"soft_erp",
"0.2");
371 writer.writeTextElement(
"kp",
"1e10");
372 writer.writeTextElement(
"kd",
"1");
373 writer.writeTextElement(
"max_vel",
"100.0");
374 writer.writeTextElement(
"min_depth",
"0.0001");
375 writer.writeEndElement();
377 writer.writeEndElement();
379 writer.writeEndElement();
380 writer.writeEndElement();
383 writer.writeStartElement(
"visual");
384 writer.writeAttribute(
"name",
"plane_model_visual");
385 writer.writeTextElement(
"cast_shadows",
"false");
387 writer.writeStartElement(
"geometry");
389 bool use_textured_ground_plane =
true;
391 if (!use_textured_ground_plane){
392 writer.writeStartElement(
"plane");
393 writer.writeTextElement(
"normal",
"0 0 1");
394 writer.writeEndElement();
396 writer.writeStartElement(
"mesh");
397 writer.writeTextElement(
"uri",
"file://ground_plane.dae");
398 writer.writeTextElement(
"scale",
"1 1 1");
399 writer.writeEndElement();
402 writer.writeEndElement();
404 writer.writeStartElement(
"material");
405 writer.writeTextElement(
"script",
"Gazebo/Grey");
406 writer.writeEndElement();
413 writer.writeEndElement();
415 writer.writeEndElement();
417 writer.writeEndElement();
432 writer.writeEndElement();
434 writer.writeEndDocument();
449 connect(element, SIGNAL(posChanged(
ArenaElement*,QPoint)),
451 connect(element, SIGNAL(rotationChanged(
ArenaElement*,
int)),
491 QList<ArenaElement*> res;
500 QList<ArenaElement*> elementsAtPos =
elementsAt(element->
pos());
void saveWorld(QXmlStreamWriter &writer)
Writes .world format-compliant XML.
void saveWorldSdf(QXmlStreamWriter &writer)
ArenaElementType const * type() const
void removeElement(ArenaElement *element)
void clear()
Removes all elements from this arena.
void setArena(Arena *arena)
Called from Arena::addElement()
void saveWorld(const QString &filename)
Writes .world format-compliant XML.
void load(const QString &filename)
Deserializes this arena from XML.
QList< ArenaElement * > elementsAt(const QPoint &pos) const
ArenaElementTypeRegistry *const m_typeRegistry
ArenaElement * contextElement(ArenaElement *element) const
int rotation() const
Returns the rotation in degrees.
void save(QXmlStreamWriter &writer)
Serializes this element in XML.
void load(const QDomElement &node)
Deserializes this element from XML.
ArenaElement * instantiateElement(const QString &typeName)
QPoint pos() const
Returns the position in arena coordinates.
ArenaElement * addElement(const QString &elementType)
Creates and adds an element of type elementType.
Arena(ArenaElementTypeRegistry *typeRegistry)
void elementRemoved(ArenaElement *element)
void saveWorldSdf(const QString &filename)
bool hasElement(const QString &typeName)
void elementAdded(ArenaElement *element)
QList< ArenaElement * > m_elements
void save(const QString &filename)
Serializes this arena in XML.