15 , m_itemMountPoint(-1)
62 int normalizedRotation = (rotation % 360 + 360) % 360;
76 if (!node.hasAttribute(
"x"))
78 if (!node.hasAttribute(
"y"))
82 pos.setX(node.attribute(
"x").toInt());
83 pos.setY(node.attribute(
"y").toInt());
86 if (node.hasAttribute(
"offset-x") && node.hasAttribute(
"offset-y"))
88 QString offsetX = node.attribute(
"offset-x");
89 QString offsetY = node.attribute(
"offset-y");
91 QPointF offset = QPointF(offsetX.toFloat(), offsetY.toFloat());
95 if (node.hasAttribute(
"rotation"))
97 QString
rotation = node.attribute(
"rotation");
101 if (node.hasAttribute(
"mount-point"))
103 QString mountPointIndex = node.attribute(
"mount-point");
110 writer.writeStartElement(
"element");
111 writer.writeAttribute(
"type",
m_type->
name());
112 writer.writeAttribute(
"rotation", QString::number(
rotation()));
113 writer.writeAttribute(
"x", QString::number(
m_pos.x()));
114 writer.writeAttribute(
"y", QString::number(
m_pos.y()));
118 writer.writeAttribute(
"offset-x", QString::number(
m_itemOffset.x()));
119 writer.writeAttribute(
"offset-y", QString::number(
m_itemOffset.y()));
123 writer.writeEndElement();
128 writer.writeStartElement(
"model:physical");
131 writer.writeAttribute(
"name", name);
134 QList<ItemMountPoint> contextItemMountPoints;
147 itemMountPoint = qMax(itemMountPoint, 0);
155 if (itemMountPoint >= 0)
160 offsetX = mountPoint.second.x() - 0.6;
161 offsetZ = mountPoint.second.y();
166 QPointF mappedOffset = trans.map(QPointF(offsetX, 0));
171 QTextStream(&xyz) <<
m_pos.x() * 1.2 + mappedOffset.x() <<
" " 172 <<
m_pos.y() * 1.2 + mappedOffset.y() <<
" " << offsetZ;
173 writer.writeTextElement(
"xyz", xyz);
176 writer.writeTextElement(
"rpy", rpy);
177 writer.writeTextElement(
"static",
"true");
179 writer.writeStartElement(
"body:trimesh");
180 writer.writeAttribute(
"name", name +
"_body");
182 writer.writeStartElement(
"geom:trimesh");
183 writer.writeAttribute(
"name", name +
"_geom");
185 writer.writeTextElement(
"mesh",
m_type->
mesh());
186 writer.writeTextElement(
"scale",
"1.0 1.0 1.0");
188 writer.writeTextElement(
"genTexCoord",
"true");
190 writer.writeStartElement(
"visual");
191 writer.writeTextElement(
"scale",
"1.0 1.0 1.0");
192 writer.writeTextElement(
"rpy",
"0 0 0");
193 writer.writeTextElement(
"mesh",
m_type->
mesh());
196 writer.writeEndElement();
199 writer.writeEndElement();
202 writer.writeEndElement();
205 writer.writeEndElement();
210 writer.writeStartElement(
"model");
213 writer.writeAttribute(
"name", name);
214 writer.writeTextElement(
"static",
"true");
217 QList<ItemMountPoint> contextItemMountPoints;
230 itemMountPoint = qMax(itemMountPoint, 0);
238 if (itemMountPoint >= 0)
243 offsetX = mountPoint.second.x() - 0.6;
244 offsetZ = mountPoint.second.y();
249 QPointF mappedOffset = trans.map(QPointF(offsetX, 0));
254 QTextStream(&xyz) <<
m_pos.x() * 1.2 + mappedOffset.x() <<
" " 255 <<
m_pos.y() * 1.2 + mappedOffset.y() <<
" " << offsetZ;
258 QTextStream(&rpy) <<
"0 0 " << -(
m_rotation/180.0)*M_PI;
261 writer.writeStartElement(
"link");
262 writer.writeAttribute(
"name",name+
"_link");
264 writer.writeTextElement(
"pose", xyz +
" " + rpy);
266 writer.writeStartElement(
"collision");
267 writer.writeAttribute(
"name",name+
"_collision");
269 writer.writeStartElement(
"geometry");
271 writer.writeStartElement(
"mesh");
272 writer.writeTextElement(
"uri",
"file://" +
m_type->
mesh());
273 writer.writeTextElement(
"scale",
"1 1 1");
274 writer.writeEndElement();
276 writer.writeEndElement();
278 writer.writeEndElement();
280 writer.writeStartElement(
"visual");
281 writer.writeAttribute(
"name",name+
"_visual");
282 writer.writeTextElement(
"cast_shadows",
"false");
284 writer.writeStartElement(
"geometry");
286 writer.writeStartElement(
"mesh");
287 writer.writeTextElement(
"uri",
"file://" +
m_type->
mesh());
288 writer.writeTextElement(
"scale",
"1 1 1");
289 writer.writeEndElement();
291 writer.writeEndElement();
293 writer.writeEndElement();
295 writer.writeEndElement();
297 writer.writeEndElement();
void saveWorld(QXmlStreamWriter &writer)
Writes .world format-compliant XML.
void saveWorldSdf(QXmlStreamWriter &writer)
Item freely movable within a grid point.
ArenaElementType const * type() const
QList< ItemMountPoint > itemMountPoints() const
Arena * m_arena
Arena this element currently belongs to (exactly one)
void setItemMountPoint(int mountPoint)
See itemMountPoint(). Use -1 to set index to "unspecified".
int itemMountPoint() const
void setItemOffset(const QPointF &offset)
See itemOffset()
bool isItem() const
Convenience method returning true iff. this is an item element (freely movable)
QPointF m_itemOffset
See itemOffset()
ArenaElement * contextElement(ArenaElement *element) const
QPair< QString, QPointF > ItemMountPoint
int rotation() const
Returns the rotation in degrees.
void save(QXmlStreamWriter &writer)
Serializes this element in XML.
int m_rotation
rotation in degrees (only multiples of 90 degrees)
void load(const QDomElement &node)
Deserializes this element from XML.
void setRotation(int rotation)
Sets the rotation in degrees.
ArenaElement(const ArenaElementType *const type, int id)
Only meant for use by ArenaElementType::createInstance()
QPoint pos() const
Returns the position in arena coordinates.
void setPos(QPoint pos)
Sets the position in arena coordinates.
void rotationChanged(ArenaElement *element, int rotation)
void posChanged(ArenaElement *element, QPoint pos)
bool isFloor() const
Convenience method returning true iff. this is a floor element.
bool isMountableItem() const
Convenience method returning true iff. this is a mountable-item element.
Item that can be mounted to a wall element.
const int m_instanceId
Unique ID set by ArenaElementType.
bool isWall() const
Convenience method returning true iff. this is a wall element.
void modified(ArenaElement *element)
const ArenaElementType *const m_type