def createNewMapObject(self): if (not self.mTile): return None newMapObject = MapObject() newMapObject.setShape(MapObject.Rectangle) newMapObject.setCell(Cell(self.mTile)) newMapObject.setSize(self.mTile.size()) return newMapObject
class CreateMultipointObjectTool(CreateObjectTool): def __init__(self, parent): super().__init__(CreationMode.CreateGeometry, parent) self.mOverlayPolygonObject = MapObject() self.mOverlayObjectGroup = ObjectGroup() self.mOverlayObjectGroup.addObject(self.mOverlayPolygonObject) highlight = QApplication.palette().highlight().color() self.mOverlayObjectGroup.setColor(highlight) def startNewMapObject(self, pos, objectGroup): super().startNewMapObject(pos, objectGroup) newMapObject = self.mNewMapObjectItem.mapObject() polygon = QPolygonF() polygon.append(QPointF()) newMapObject.setPolygon(polygon) polygon.append(QPointF()) # The last point is connected to the mouse self.mOverlayPolygonObject.setPolygon(polygon) self.mOverlayPolygonObject.setShape(newMapObject.shape()) self.mOverlayPolygonObject.setPosition(pos) self.mOverlayPolygonItem = MapObjectItem(self.mOverlayPolygonObject, self.mapDocument(), self.mObjectGroupItem) def languageChanged(self): pass def mouseMovedWhileCreatingObject(self, pos, modifiers): renderer = self.mapDocument().renderer() pixelCoords = renderer.screenToPixelCoords_(pos) SnapHelper(renderer, modifiers).snap(pixelCoords) pixelCoords -= self.mNewMapObjectItem.mapObject().position() polygon = self.mOverlayPolygonObject.polygon() polygon[-1] = pixelCoords self.mOverlayPolygonItem.setPolygon(polygon) def mousePressedWhileCreatingObject(self, event): if (event.button() == Qt.RightButton): self.finishNewMapObject() elif (event.button() == Qt.LeftButton): current = self.mNewMapObjectItem.mapObject().polygon() next = self.mOverlayPolygonObject.polygon() # If the last position is still the same, ignore the click if (next.last() == current.last()): return # Assign current overlay polygon to the new object self.mNewMapObjectItem.setPolygon(next) # Add a new editable point to the overlay next.append(next.last()) self.mOverlayPolygonItem.setPolygon(next)
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 createNewMapObject(self): newMapObject = MapObject() newMapObject.setShape(MapObject.Rectangle) return newMapObject
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 createNewMapObject(self): newMapObject = MapObject() newMapObject.setShape(MapObject.Polygon) return newMapObject
def createNewMapObject(self): newMapObject = MapObject() newMapObject.setShape(MapObject.Ellipse) return newMapObject
def createNewMapObject(self): newMapObject = MapObject() newMapObject.setShape(MapObject.Polyline) return newMapObject
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