def __readObject(self): atts = self.xml.attributes() id = Int(atts.value("id")) name = atts.value("name") gid = Int(atts.value("gid")) x = Float(atts.value("x")) y = Float(atts.value("y")) width = Float(atts.value("width")) height = Float(atts.value("height")) type = atts.value("type") visibleRef = atts.value("visible") pos = QPointF(x, y) size = QSizeF(width, height) object = MapObject(name, type, pos, size) object.setId(id) try: rotation = Float(atts.value("rotation")) ok = True except: ok = False if (ok): object.setRotation(rotation) if (gid): object.setCell(self.__cellForGid(gid)) if (not object.cell().isEmpty()): tileSize = object.cell().tile.size() if (width == 0): object.setWidth(tileSize.width()) if (height == 0): object.setHeight(tileSize.height()) try: visible = int(visibleRef) ok = True except: ok = False if ok: object.setVisible(visible) while (self.xml.readNextStartElement()): if (self.xml.name() == "properties"): object.mergeProperties(self.__readProperties()) elif (self.xml.name() == "polygon"): object.setPolygon(self.__readPolygon()) object.setShape(MapObject.Polygon) elif (self.xml.name() == "polyline"): object.setPolygon(self.__readPolygon()) object.setShape(MapObject.Polyline) elif (self.xml.name() == "ellipse"): self.xml.skipCurrentElement() object.setShape(MapObject.Ellipse) else: self.__readUnknownElement() return object
def toObjectGroup(self, variantMap): objectGroup = ObjectGroup(variantMap.get("name", ''), variantMap.get("x", 0), variantMap.get("y", 0), variantMap.get("width", 0), variantMap.get("height", 0)) opacity = variantMap.get("opacity", 0.0) visible = variantMap.get("visible", True) objectGroup.setOpacity(opacity) objectGroup.setVisible(visible) objectGroup.setColor(variantMap.get("color", '')) drawOrderString = variantMap.get("draworder", '') if drawOrderString != '': objectGroup.setDrawOrder(drawOrderFromString(drawOrderString)) if (objectGroup.drawOrder() == ObjectGroup.DrawOrder.UnknownOrder): self.mError = self.tr("Invalid draw order: %s" % drawOrderString) return None for objectVariant in variantMap.get("objects", []): objectVariantMap = objectVariant name = objectVariantMap.get("name", '') type = objectVariantMap.get("type", '') id = objectVariantMap.get("id", 0.0) gid = objectVariantMap.get("gid", 0.0) x = objectVariantMap.get("x", 0.0) y = objectVariantMap.get("y", 0.0) width = objectVariantMap.get("width", 0.0) height = objectVariantMap.get("height", 0.0) rotation = objectVariantMap.get("rotation", 0.0) pos = QPointF(x, y) size = QSizeF(width, height) object = MapObject(name, type, pos, size) object.setId(id) object.setRotation(rotation) if (gid): cell, ok = self.mGidMapper.gidToCell(gid) object.setCell(cell) if not object.cell().isEmpty(): tileSize = object.cell().tile.size() if width == 0: object.setWidth(tileSize.width()) if height == 0: object.setHeight(tileSize.height()) if (objectVariantMap.__contains__("visible")): object.setVisible(objectVariantMap.get("visible", True)) object.setProperties( self.toProperties(objectVariantMap.get("properties", {}))) objectGroup.addObject(object) polylineVariant = objectVariantMap.get("polyline", []) polygonVariant = objectVariantMap.get("polygon", []) if len(polygonVariant) > 0: object.setShape(MapObject.Polygon) object.setPolygon(self.toPolygon(polygonVariant)) if len(polylineVariant) > 0: object.setShape(MapObject.Polyline) object.setPolygon(self.toPolygon(polylineVariant)) if (objectVariantMap.__contains__("ellipse")): object.setShape(MapObject.Ellipse) return objectGroup
def toObjectGroup(self, variantMap): objectGroup = ObjectGroup(variantMap.get("name",''), variantMap.get("x",0), variantMap.get("y",0), variantMap.get("width",0), variantMap.get("height",0)) opacity = variantMap.get("opacity", 0.0) visible = variantMap.get("visible", True) objectGroup.setOpacity(opacity) objectGroup.setVisible(visible) objectGroup.setColor(variantMap.get("color", '')) drawOrderString = variantMap.get("draworder", '') if drawOrderString != '': objectGroup.setDrawOrder(drawOrderFromString(drawOrderString)) if (objectGroup.drawOrder() == ObjectGroup.DrawOrder.UnknownOrder): self.mError = self.tr("Invalid draw order: %s"%drawOrderString) return None for objectVariant in variantMap.get("objects", []): objectVariantMap = objectVariant name = objectVariantMap.get("name",'') type = objectVariantMap.get("type", '') id = objectVariantMap.get("id",0.0) gid = objectVariantMap.get("gid",0.0) x = objectVariantMap.get("x",0.0) y = objectVariantMap.get("y",0.0) width = objectVariantMap.get("width",0.0) height = objectVariantMap.get("height",0.0) rotation = objectVariantMap.get("rotation", 0.0) pos = QPointF(x, y) size = QSizeF(width, height) object = MapObject(name, type, pos, size) object.setId(id) object.setRotation(rotation) if (gid): cell, ok = self.mGidMapper.gidToCell(gid) object.setCell(cell) if not object.cell().isEmpty(): tileSize = object.cell().tile.size() if width == 0: object.setWidth(tileSize.width()) if height == 0: object.setHeight(tileSize.height()) if (objectVariantMap.__contains__("visible")): object.setVisible(objectVariantMap.get("visible", True)) object.setProperties(self.toProperties(objectVariantMap.get("properties", {}))) objectGroup.addObject(object) polylineVariant = objectVariantMap.get("polyline", []) polygonVariant = objectVariantMap.get("polygon", []) if len(polygonVariant) > 0: object.setShape(MapObject.Polygon) object.setPolygon(self.toPolygon(polygonVariant)) if len(polylineVariant) > 0: object.setShape(MapObject.Polyline) object.setPolygon(self.toPolygon(polylineVariant)) if (objectVariantMap.__contains__("ellipse")): object.setShape(MapObject.Ellipse) return objectGroup