def filletPolyline(self): layer = self.entity1.layer transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.plugIn.canvas, layer) tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugin.canvas, \ layer) f = self.entity1.getFeature() geom = f.geometry() self.linearObjectList1.fillet(transformedRadius) updSubGeom = QgsGeometry.fromPolyline(self.linearObjectList1.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: return False f.setGeometry(updGeom) self.plugIn.beginEditCommand("Feature edited", layer) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def addFeatureCache(self, newPt): featureCacheLen = len(self.featureCache) layer = self.entity.layer f = self.entity.getFeature() transformedPt = self.mapToLayerCoordinates(layer, newPt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ transformedPt) offSetDistance = qad_utils.getDistance(transformedPt, pt) else: offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \ self.plugIn.canvas,\ layer) if self.multi == True: if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide self.lastOffSetOnLeftSide = offSetDistance self.getPointMapTool().lastOffSetOnLeftSide = self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide self.lastOffSetOnRightSide = offSetDistance self.getPointMapTool().lastOffSetOnRightSide = self.lastOffSetOnRightSide tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ layer) epsg = layer.crs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) added = False for line in lines: if layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) if offsetGeom.type() == QGis.Line or offsetGeom.type() == QGis.Polygon: offsetFeature = QgsFeature(f) offsetFeature.setGeometry(offsetGeom) self.featureCache.append([layer, offsetFeature]) self.addFeatureToRubberBand(layer, offsetFeature) added = True if added: self.undoFeatureCacheIndexes.append(featureCacheLen)
def setEntityInfo(self, layer, featureId, linearObjectList, partAt, pointAt): """ Setta self.entity, self.atSubGeom, self.linearObjectList, self.partAt, self.pointAt di primo o del secondo oggetto da raccordare (vedi <firstObj>) """ self.layer = layer self.featureId = featureId self.linearObjectList.set(linearObjectList) self.partAt = partAt self.pointAt = pointAt self.transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.canvas, self.layer) self.tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.canvas,\ self.layer)
def addStretchedGeometries(self, newPt): self.__rubberBand.reset() for SSGeom in self.SSGeomList: # copio entitySet entitySet = QadEntitySet(SSGeom[0]) geomSel = SSGeom[1] for layerEntitySet in entitySet.layerEntitySetList: layer = layerEntitySet.layer tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.canvas,\ layer) g = QgsGeometry(geomSel) if self.plugIn.canvas.mapRenderer().destinationCrs() != layer.crs(): # Trasformo la geometria nel sistema di coordinate del layer coordTransform = QgsCoordinateTransform(self.canvas.mapRenderer().destinationCrs(), \ layer.crs()) g.transform(coordTransform) transformedBasePt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, self.basePt) transformedNewPt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, newPt) offSetX = transformedNewPt.x() - transformedBasePt.x() offSetY = transformedNewPt.y() - transformedBasePt.y() else: offSetX = newPt.x() - self.basePt.x() offSetY = newPt.y() - self.basePt.y() while len(layerEntitySet.featureIds) > 0: featureId = layerEntitySet.featureIds[0] f = layerEntitySet.getFeature(featureId) self.stretch(f, g, offSetX, offSetY, tolerance2ApproxCurve, layerEntitySet, entitySet)
def addOffSetGeometries(self, newPt): self.__rubberBand.reset() transformedPt = self.plugIn.canvas.mapRenderer().mapToLayerCoordinates(self.layer, newPt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ transformedPt) offSetDistance = qad_utils.getDistance(transformedPt, pt) else: offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \ self.plugIn.canvas,\ self.layer) if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ self.layer) epsg = self.layer.crs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) for line in lines: if self.layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) self.__rubberBand.addGeometry(offsetGeom, self.layer)
def stretchFeatures(self, newPt): # mi ricavo un unico QadEntitySet con le entità selezionate entitySet = QadEntitySet() for SSGeom in self.SSGeomList: entitySet.unite(SSGeom[0]) self.plugIn.beginEditCommand("Feature stretched", entitySet.getLayerList()) del entitySet for SSGeom in self.SSGeomList: # copio entitySet entitySet = QadEntitySet(SSGeom[0]) geomSel = SSGeom[1] for layerEntitySet in entitySet.layerEntitySetList: layer = layerEntitySet.layer tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ layer) g = QgsGeometry(geomSel) if self.plugIn.canvas.mapRenderer().destinationCrs() != layer.crs(): # Trasformo la geometria nel sistema di coordinate del layer coordTransform = QgsCoordinateTransform(self.plugIn.canvas.mapRenderer().destinationCrs(), \ layer.crs()) g.transform(coordTransform) transformedBasePt = self.mapToLayerCoordinates(layer, self.basePt) transformedNewPt = self.mapToLayerCoordinates(layer, newPt) offSetX = transformedNewPt.x() - transformedBasePt.x() offSetY = transformedNewPt.y() - transformedBasePt.y() else: offSetX = newPt.x() - self.basePt.x() offSetY = newPt.y() - self.basePt.y() while len(layerEntitySet.featureIds) > 0: featureId = layerEntitySet.featureIds[0] f = layerEntitySet.getFeature(featureId) if self.stretch(f, g, offSetX, offSetY, tolerance2ApproxCurve, layerEntitySet, entitySet) == False: self.plugIn.destroyEditCommand() return self.plugIn.endEditCommand()
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() # noto il primo punto si richiede la larghezza del buffer if self.mode == Qad_mbuffer_maptool_ModeEnum.FIRST_PT_ASK_FOR_BUFFER_WIDTH: for layerEntitySet in self.entitySet.layerEntitySetList: transformedPt1 = self.canvas.mapRenderer().mapToLayerCoordinates(layerEntitySet.layer, self.startPtForBufferWidth) transformedPt2 = self.canvas.mapRenderer().mapToLayerCoordinates(layerEntitySet.layer, self.tmpPoint) width = qad_utils.getDistance(transformedPt1, transformedPt2) tolerance = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.canvas,\ layerEntitySet.layer) geoms = layerEntitySet.getGeometryCollection() for geom in geoms: bufferGeom = qad_utils.ApproxCurvesOnGeom(geom.buffer(width, self.segments), \ self.segments, self.segments, \ tolerance) if bufferGeom: self.__rubberBand.addGeometry(bufferGeom, layerEntitySet.layer)
def setLinearObjectList(self, linearObjectList, layer): self.linearObjectList.set(linearObjectList) self.layer = layer self.tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.canvas,\ self.layer)
def run(self, msgMapTool = False, msg = None): # ritorna: # True per selezione non terminata # False per selezione terminata if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # errore #========================================================================= # RICHIESTA PRIMO PUNTO PER SELEZIONE OGGETTI if self.step == 0: # if you can also select objects before you start a command if QadVariables.get(QadMsg.translate("Environment variables", "PICKFIRST")) == 1: if self.AddCurrentQgsSelectedFeatures() == True: self.plugIn.setLastEntitySet(self.entitySet) return True; self.WaitForFirstPoint() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER SELEZIONE OGGETTI elif self.step == 1: # dopo aver atteso un punto o enter o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse if self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False # continua shiftKey = self.getPointMapTool().shiftKey # se é stata selezionata un'entità if self.getPointMapTool().entity.isInitialized(): value = self.getPointMapTool().entity else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione shiftKey = False value = msg if value is None: if self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if type(value) == unicode: self.currSelectionMode = value if value == QadMsg.translate("Command_SSGET", "Window") or value == "Window" or \ value == QadMsg.translate("Command_SSGET", "Crossing") or value == "Crossing": # "Finestra" = Seleziona tutti gli oggetti che si trovano completamente all'interno di un rettangolo definito da due punti # "Interseca" = Seleziona gli oggetti che intersecano o si trovano all'interno di un'area definita da due punti # imposto il map tool self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.NONE) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "First corner: ")) self.step = 2 if value == QadMsg.translate("Command_SSGET", "Last") or value == "Last": # Seleziona l'ultima entità inserita if self.plugIn.getLastEntity() is None: self.showMsgOnAddRemove(0) else: self.AddRemoveEntity(self.plugIn.getLastEntity(), self.AddOnSelection) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Box") or value == "Box": # Seleziona tutti gli oggetti che intersecano o si trovano all'interno di un rettangolo specificato da due punti. # Se i punti del rettangolo sono specificati da destra a sinistra, Riquadro equivale ad Interseca, # altrimenti é equivalente a Finestra # imposto il map tool self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.NONE) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "First corner: ")) self.step = 2 elif value == QadMsg.translate("Command_SSGET", "All") or value == "All": # Seleziona tutti gli oggetti selSet = qad_utils.getSelSet("X", self.getPointMapTool(), None, \ self.getLayersToCheck()) self.elaborateSelSet(selSet, False) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Fence") or value == "Fence": # Seleziona tutti gli oggetti che intersecano una polilinea self.PLINECommand = QadPLINECommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare una linea # che non verrà salvata su un layer self.PLINECommand.virtualCmd = True self.PLINECommand.run(msgMapTool, msg) self.step = 4 elif value == QadMsg.translate("Command_SSGET", "WPolygon") or value == "WPolygon" or \ value == QadMsg.translate("Command_SSGET", "CPolygon") or value == "CPolygon": # "FPoligono" = Seleziona oggetti che si trovano completamente all'interno di un poligono definito da punti # "IPoligono" = Seleziona gli oggetti che intersecano o si trovano all'interno di un poligono definito specificando dei punti self.MPOLYGONCommand = QadMPOLYGONCommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare una linea # che non verrà salvata su un layer self.MPOLYGONCommand.virtualCmd = True if value == QadMsg.translate("Command_SSGET", "WPolygon") or value == "WPolygon": self.MPOLYGONCommand.setRubberBandColor(None, getColorForWindowSelectionArea()) else: self.MPOLYGONCommand.setRubberBandColor(None, getColorForCrossingSelectionArea()) self.MPOLYGONCommand.run(msgMapTool, msg) self.step = 7 elif value == QadMsg.translate("Command_SSGET", "WCircle") or value == "WCircle" or \ value == QadMsg.translate("Command_SSGET", "CCircle") or value == "CCircle": # "FCerchio" = Seleziona oggetti che si trovano completamente all'interno di un cerchio # "ICerchio" = Seleziona oggetti che intersecano o si trovano all'interno di un cerchio self.CIRCLECommand = QadCIRCLECommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare un cerchio # che non verrà salvata su un layer self.CIRCLECommand.virtualCmd = True if value == QadMsg.translate("Command_SSGET", "WCircle") or value == "WCircle": self.CIRCLECommand.setRubberBandColor(None, getColorForWindowSelectionArea()) else: self.CIRCLECommand.setRubberBandColor(None, getColorForCrossingSelectionArea()) self.CIRCLECommand.run(msgMapTool, msg) self.step = 5 elif value == QadMsg.translate("Command_SSGET", "WObjects") or value == "WObjects" or \ value == QadMsg.translate("Command_SSGET", "CObjects") or value == "CObjects": # "FOggetti" = Seleziona oggetti che si trovano completamente all'interno di oggetti da selezionare # "IOggetti" = Seleziona oggetti che intersecano o si trovano all'interno di oggetti da selezionare self.SSGetClass = QadSSGetClass(self.plugIn) self.SSGetClass.run(msgMapTool, msg) self.step = 6 elif value == QadMsg.translate("Command_SSGET", "WBuffer") or value == "WBuffer" or \ value == QadMsg.translate("Command_SSGET", "CBuffer") or value == "CBuffer": # ho dovuto spostare questo import perché qad_mbuffer_cmd fa l'import di qad_ssget_cmd from qad_mbuffer_cmd import QadMBUFFERCommandClass # "FBuffer" = Seleziona oggetti che si trovano completamente all'interno di buffer intorno ad oggetti da selezionare # "IBuffer" = Seleziona oggetti che intersecano o si trovano all'interno di buffer intorno ad oggetti da selezionare self.MBUFFERCommand = QadMBUFFERCommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare un cerchio # che non verrà salvata su un layer self.MBUFFERCommand.virtualCmd = True if value == QadMsg.translate("Command_SSGET", "WBuffer") or value == "WBuffer": self.MBUFFERCommand.setRubberBandColor(None, getColorForWindowSelectionArea()) else: self.MBUFFERCommand.setRubberBandColor(None, getColorForCrossingSelectionArea()) self.MBUFFERCommand.run(msgMapTool, msg) self.step = 8 elif value == QadMsg.translate("Command_SSGET", "Add") or value == "Add": # Passa al metodo Aggiungi: gli oggetti selezionati possono essere aggiunti al gruppo di selezione self.AddOnSelection = True self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Remove") or value == "Remove": # Passa al metodo Rimuovi: gli oggetti possono essere rimossi dal gruppo di selezione self.AddOnSelection = False self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Previous") or value == "Previous": # Seleziona il gruppo di selezione più recente if self.plugIn.lastEntitySet is None: self.showMsgOnAddRemove(0) else: entitySet = QadEntitySet() entitySet.set(self.plugIn.lastEntitySet) # controllo sul layer if self.onlyEditableLayers == True: entitySet.removeNotEditable() # controllo sul tipo if self.checkPointLayer == False: entitySet.removeGeomType(QGis.Point) if self.checkLineLayer == False: entitySet.removeGeomType(QGis.Line) if self.checkPolygonLayer == False: entitySet.removeGeomType(QGis.Polygon) # controllo sulle quotature if self.checkDimLayers == False: QadDimStyles.removeAllDimLayersFromEntitySet(entitySet) entitySet.removeNotExisting() self.elaborateSelSet(entitySet, False) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Undo") or value == "Undo": # Annulla la selezione dell'oggetto aggiunto più recentemente al gruppo di selezione. # Inverto il tipo di selezione prevAddOnSelection = self.AddOnSelection self.AddOnSelection = not self.AddOnSelection self.elaborateSelSet(self.lastEntitySet, False) # Ripristino il tipo di selezione self.AddOnSelection = prevAddOnSelection if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "AUto") or value == "AUto": # Passa alla selezione automatica: vengono selezionati gli oggetti sui quali si posiziona il puntatore. # Facendo clic su un'area vuota all'interno o all'esterno di un oggetto, # si crea il primo angolo di un rettangolo di selezione, come per il metodo Riquadro self.SingleSelection = False self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "SIngle") or value == "SIngle": # Passa al metodo Singolo: viene selezionato il primo oggetto o gruppo di oggetti indicato, # senza che vengano richieste altre selezioni. self.SingleSelection = True if self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Help") or value == "Help": self.help = True self.WaitForFirstPoint() elif type(value) == QgsPoint: # se é stato inserito il punto iniziale del rettangolo self.currSelectionMode = QadMsg.translate("Command_SSGET", "Box") self.points.append(value) self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.ENTITYSET_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE) self.getPointMapTool().setStartPoint(value) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) self.step = 3 else: # se é stata selezionata un'entità self.elaborateEntity(value, shiftKey) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DEL RETTANGOLO DA OPZIONE # FINESTRA, INTERSECA, RIQUADRO (da step = 1) elif self.step == 2: # dopo aver atteso un punto si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) self.WaitForFirstPoint() return False else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.points.append(value) self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.ENTITYSET_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE) # cambio il colore impostato da setDrawMode if self.currSelectionMode == QadMsg.translate("Command_SSGET", "Window") or value == "Window": self.getPointMapTool().rectangleCrossingSelectionColor = self.getPointMapTool().rectangleWindowSelectionColor elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "Crossing") or value == "Crossing": self.getPointMapTool().rectangleWindowSelectionColor = self.getPointMapTool().rectangleCrossingSelectionColor self.rectangleCrossingSelectionColor = getColorForCrossingSelectionArea() self.rectangleWindowSelectionColor = getColorForWindowSelectionArea() self.getPointMapTool().setStartPoint(value) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) self.step = 3 else: self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) self.WaitForFirstPoint() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DEL RETTANGOLO (da step = 1) elif self.step == 3: # dopo aver atteso un punto si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) return False else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False shiftKey = self.getPointMapTool().shiftKey value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione shiftKey = False value = msg if type(value) == QgsPoint: self.getPointMapTool().clear() self.points.append(value) if self.currSelectionMode == QadMsg.translate("Command_SSGET", "Box") or \ self.currSelectionMode == "Box": if self.points[0].x() < value.x(): mode = "W" else: mode = "C" elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "Window") or \ self.currSelectionMode == "Window": mode = "W" else: # "Interseca" mode = "C" selSet = qad_utils.getSelSet(mode, self.getPointMapTool(), self.points, \ self.getLayersToCheck()) self.elaborateSelSet(selSet, shiftKey) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() else: self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO PER MODALITA' INTERCETTA (da step = 1 o 4) elif self.step == 4: # dopo aver atteso un punto si riavvia il comando if self.PLINECommand.run(msgMapTool, msg) == True: self.showMsg("\n") self.AddRemoveSelSetByFence(self.PLINECommand.vertices) del self.PLINECommand self.PLINECommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA PER MODALITA' FCERCHIO e ICERCHIO (da step = 1 o 5) elif self.step == 5: # dopo aver atteso un punto si riavvia il comando if self.CIRCLECommand.run(msgMapTool, msg) == True: self.showMsg("\n") if (self.CIRCLECommand.centerPt is not None) and \ (self.CIRCLECommand.radius is not None): circle = QadCircle() circle.set(self.CIRCLECommand.centerPt, self.CIRCLECommand.radius) points = circle.asPolyline() if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WCircle") or \ self.currSelectionMode == "WCircle": self.AddRemoveSelSetByPolygon("WP", points) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CCircle") or \ self.currSelectionMode == "CCircle": self.AddRemoveSelSetByPolygon("CP", points) del self.CIRCLECommand self.CIRCLECommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DI SELEZIONE DI OGGETTI PER MODALITA' FOGGETTI e IOGGETTI (da step = 1 o 6) elif self.step == 6: # dopo aver atteso un punto si riavvia il comando if self.SSGetClass.run(msgMapTool, msg) == True: self.showMsg("\n") destCRS = self.SSGetClass.getPointMapTool().canvas.mapRenderer().destinationCrs() geoms = self.SSGetClass.entitySet.getGeometryCollection(destCRS) # trasformo la geometria if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WObjects") or \ self.currSelectionMode == "WObjects": self.AddRemoveSelSetByGeometry("WO", geoms) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CObjects") or \ self.currSelectionMode == "CObjects": self.AddRemoveSelSetByGeometry("CO", geoms) del self.SSGetClass self.SSGetClass = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA PER MODALITA' FPOLIGONO e IPOLIGONO (da step = 1 o 7) elif self.step == 7: # dopo aver atteso un punto si riavvia il comando if self.MPOLYGONCommand.run(msgMapTool, msg) == True: self.showMsg("\n") if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WPolygon") or \ self.currSelectionMode == "WPolygon": self.AddRemoveSelSetByPolygon("WP", self.MPOLYGONCommand.vertices) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CPolygon") or \ self.currSelectionMode == "CPolygon": self.AddRemoveSelSetByPolygon("CP", self.MPOLYGONCommand.vertices) del self.MPOLYGONCommand self.MPOLYGONCommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DI SELEZIONE DI OGGETTI PER MODALITA' FBUFFER e IBUFFER (da step = 1 o 8) elif self.step == 8: # dopo aver atteso un punto si riavvia il comando if self.MBUFFERCommand.run(msgMapTool, msg) == True: self.showMsg("\n") bufferGeoms = [] for layerEntitySet in self.MBUFFERCommand.entitySet.layerEntitySetList: geoms = layerEntitySet.getGeometryCollection() width = qad_utils.distMapToLayerCoordinates(self.MBUFFERCommand.width, \ self.MBUFFERCommand.getPointMapTool().canvas,\ layerEntitySet.layer) for geom in geoms: bufferGeoms.append(geom.buffer(width, self.MBUFFERCommand.segments)) if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WBuffer") or \ self.currSelectionMode == "WBuffer": self.AddRemoveSelSetByGeometry("WO", bufferGeoms) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CBuffer") or \ self.currSelectionMode == "CBuffer": self.AddRemoveSelSetByGeometry("CO", bufferGeoms) del self.MBUFFERCommand self.MBUFFERCommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False
def run(self, msgMapTool = False, msg = None): # ritorna: # True per selezione non terminata # False per selezione terminata if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # errore #========================================================================= # RICHIESTA PRIMO PUNTO PER SELEZIONE OGGETTI if self.step == 0: # if you can also select objects before you start a command if QadVariables.get(QadMsg.translate("Environment variables", "PICKFIRST")) == 1: if self.AddCurrentQgsSelectedFeatures() == True: self.plugIn.setLastEntitySet(self.entitySet) return True; self.WaitForFirstPoint() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER SELEZIONE OGGETTI elif self.step == 1: # dopo aver atteso un punto o enter o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse if self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False # continua shiftKey = self.getPointMapTool().shiftKey # se é stata selezionata un'entità if self.getPointMapTool().entity.isInitialized(): value = self.getPointMapTool().entity else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione shiftKey = False value = msg if value is None: if self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if type(value) == unicode: self.currSelectionMode = value if value == QadMsg.translate("Command_SSGET", "Window") or value == "Window" or \ value == QadMsg.translate("Command_SSGET", "Crossing") or value == "Crossing": # "Finestra" = Seleziona tutti gli oggetti che si trovano completamente all'interno di un rettangolo definito da due punti # "Interseca" = Seleziona gli oggetti che intersecano o si trovano all'interno di un'area definita da due punti # imposto il map tool self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.NONE) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "First corner: ")) self.step = 2 if value == QadMsg.translate("Command_SSGET", "Last") or value == "Last": # Seleziona l'ultima entità inserita if self.plugIn.getLastEntity() is None: self.showMsgOnAddRemove(0) else: self.AddRemoveEntity(self.plugIn.getLastEntity(), self.AddOnSelection) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Box") or value == "Box": # Seleziona tutti gli oggetti che intersecano o si trovano all'interno di un rettangolo specificato da due punti. # Se i punti del rettangolo sono specificati da destra a sinistra, Riquadro equivale ad Interseca, # altrimenti é equivalente a Finestra # imposto il map tool self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.NONE) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "First corner: ")) self.step = 2 elif value == QadMsg.translate("Command_SSGET", "All") or value == "All": # Seleziona tutti gli oggetti selSet = qad_utils.getSelSet("X", self.getPointMapTool(), None, \ self.getLayersToCheck()) self.elaborateSelSet(selSet, False) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Fence") or value == "Fence": # Seleziona tutti gli oggetti che intersecano una polilinea self.PLINECommand = QadPLINECommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare una linea # che non verrà salvata su un layer self.PLINECommand.virtualCmd = True self.PLINECommand.run(msgMapTool, msg) self.step = 4 elif value == QadMsg.translate("Command_SSGET", "WPolygon") or value == "WPolygon" or \ value == QadMsg.translate("Command_SSGET", "CPolygon") or value == "CPolygon": # "FPoligono" = Seleziona oggetti che si trovano completamente all'interno di un poligono definito da punti # "IPoligono" = Seleziona gli oggetti che intersecano o si trovano all'interno di un poligono definito specificando dei punti self.MPOLYGONCommand = QadMPOLYGONCommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare una linea # che non verrà salvata su un layer self.MPOLYGONCommand.virtualCmd = True if value == QadMsg.translate("Command_SSGET", "WPolygon") or value == "WPolygon": self.MPOLYGONCommand.setRubberBandColor(None, getColorForWindowSelectionArea()) else: self.MPOLYGONCommand.setRubberBandColor(None, getColorForCrossingSelectionArea()) self.MPOLYGONCommand.run(msgMapTool, msg) self.step = 7 elif value == QadMsg.translate("Command_SSGET", "WCircle") or value == "WCircle" or \ value == QadMsg.translate("Command_SSGET", "CCircle") or value == "CCircle": # "FCerchio" = Seleziona oggetti che si trovano completamente all'interno di un cerchio # "ICerchio" = Seleziona oggetti che intersecano o si trovano all'interno di un cerchio self.CIRCLECommand = QadCIRCLECommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare un cerchio # che non verrà salvata su un layer self.CIRCLECommand.virtualCmd = True if value == QadMsg.translate("Command_SSGET", "WCircle") or value == "WCircle": self.CIRCLECommand.setRubberBandColor(None, getColorForWindowSelectionArea()) else: self.CIRCLECommand.setRubberBandColor(None, getColorForCrossingSelectionArea()) self.CIRCLECommand.run(msgMapTool, msg) self.step = 5 elif value == QadMsg.translate("Command_SSGET", "WObjects") or value == "WObjects" or \ value == QadMsg.translate("Command_SSGET", "CObjects") or value == "CObjects": # "FOggetti" = Seleziona oggetti che si trovano completamente all'interno di oggetti da selezionare # "IOggetti" = Seleziona oggetti che intersecano o si trovano all'interno di oggetti da selezionare self.SSGetClass = QadSSGetClass(self.plugIn) self.SSGetClass.run(msgMapTool, msg) self.step = 6 elif value == QadMsg.translate("Command_SSGET", "WBuffer") or value == "WBuffer" or \ value == QadMsg.translate("Command_SSGET", "CBuffer") or value == "CBuffer": # ho dovuto spostare questo import perché qad_mbuffer_cmd fa l'import di qad_ssget_cmd from qad_mbuffer_cmd import QadMBUFFERCommandClass # "FBuffer" = Seleziona oggetti che si trovano completamente all'interno di buffer intorno ad oggetti da selezionare # "IBuffer" = Seleziona oggetti che intersecano o si trovano all'interno di buffer intorno ad oggetti da selezionare self.MBUFFERCommand = QadMBUFFERCommandClass(self.plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare un cerchio # che non verrà salvata su un layer self.MBUFFERCommand.virtualCmd = True if value == QadMsg.translate("Command_SSGET", "WBuffer") or value == "WBuffer": self.MBUFFERCommand.setRubberBandColor(None, getColorForWindowSelectionArea()) else: self.MBUFFERCommand.setRubberBandColor(None, getColorForCrossingSelectionArea()) self.MBUFFERCommand.run(msgMapTool, msg) self.step = 8 elif value == QadMsg.translate("Command_SSGET", "Add") or value == "Add": # Passa al metodo Aggiungi: gli oggetti selezionati possono essere aggiunti al gruppo di selezione self.AddOnSelection = True self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Remove") or value == "Remove": # Passa al metodo Rimuovi: gli oggetti possono essere rimossi dal gruppo di selezione self.AddOnSelection = False self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Previous") or value == "Previous": # Seleziona il gruppo di selezione più recente if self.plugIn.lastEntitySet is None: self.showMsgOnAddRemove(0) else: entitySet = QadEntitySet() entitySet.set(self.plugIn.lastEntitySet) # controllo sul layer if self.onlyEditableLayers == True: entitySet.removeNotEditable() # controllo sul tipo if self.checkPointLayer == False: entitySet.removeGeomType(QGis.Point) if self.checkLineLayer == False: entitySet.removeGeomType(QGis.Line) if self.checkPolygonLayer == False: entitySet.removeGeomType(QGis.Polygon) # controllo sulle quotature if self.checkDimLayers == False: QadDimStyles.removeAllDimLayersFromEntitySet(entitySet) entitySet.removeNotExisting() self.elaborateSelSet(entitySet, False) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Undo") or value == "Undo": # Annulla la selezione dell'oggetto aggiunto più recentemente al gruppo di selezione. # Inverto il tipo di selezione prevAddOnSelection = self.AddOnSelection self.AddOnSelection = not self.AddOnSelection self.elaborateSelSet(self.lastEntitySet, False) # Ripristino il tipo di selezione self.AddOnSelection = prevAddOnSelection if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "AUto") or value == "AUto": # Passa alla selezione automatica: vengono selezionati gli oggetti sui quali si posiziona il puntatore. # Facendo clic su un'area vuota all'interno o all'esterno di un oggetto, # si crea il primo angolo di un rettangolo di selezione, come per il metodo Riquadro self.SingleSelection = False self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "SIngle") or value == "SIngle": # Passa al metodo Singolo: viene selezionato il primo oggetto o gruppo di oggetti indicato, # senza che vengano richieste altre selezioni. self.SingleSelection = True if self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine self.WaitForFirstPoint() elif value == QadMsg.translate("Command_SSGET", "Help") or value == "Help": self.help = True self.WaitForFirstPoint() elif type(value) == QgsPoint: # se é stato inserito il punto iniziale del rettangolo self.currSelectionMode = QadMsg.translate("Command_SSGET", "Box") self.points.append(value) self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.ENTITYSET_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE) self.getPointMapTool().setStartPoint(value) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) self.step = 3 else: # se é stata selezionata un'entità self.elaborateEntity(value, shiftKey) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DEL RETTANGOLO DA OPZIONE # FINESTRA, INTERSECA, RIQUADRO (da step = 1) elif self.step == 2: # dopo aver atteso un punto si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) self.WaitForFirstPoint() return False else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.points.append(value) self.getPointMapTool().setSelectionMode(QadGetPointSelectionModeEnum.ENTITYSET_SELECTION) self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE) # cambio il colore impostato da setDrawMode if self.currSelectionMode == QadMsg.translate("Command_SSGET", "Window") or value == "Window": self.getPointMapTool().rectangleCrossingSelectionColor = self.getPointMapTool().rectangleWindowSelectionColor elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "Crossing") or value == "Crossing": self.getPointMapTool().rectangleWindowSelectionColor = self.getPointMapTool().rectangleCrossingSelectionColor self.rectangleCrossingSelectionColor = getColorForCrossingSelectionArea() self.rectangleWindowSelectionColor = getColorForWindowSelectionArea() self.getPointMapTool().setStartPoint(value) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) self.step = 3 else: self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) self.WaitForFirstPoint() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DEL RETTANGOLO (da step = 1) elif self.step == 3: # dopo aver atteso un punto si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) return False else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False shiftKey = self.getPointMapTool().shiftKey value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione shiftKey = False value = msg if type(value) == QgsPoint: self.getPointMapTool().clear() self.points.append(value) if self.currSelectionMode == QadMsg.translate("Command_SSGET", "Box") or \ self.currSelectionMode == "Box": if self.points[0].x() < value.x(): mode = "W" else: mode = "C" elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "Window") or \ self.currSelectionMode == "Window": mode = "W" else: # "Interseca" mode = "C" selSet = qad_utils.getSelSet(mode, self.getPointMapTool(), self.points, \ self.getLayersToCheck()) self.elaborateSelSet(selSet, shiftKey) if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() else: self.showMsg(QadMsg.translate("Command_SSGET", "Window not correct.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SSGET", "Specify opposite corner: ")) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO PER MODALITA' INTERCETTA (da step = 1 o 4) elif self.step == 4: # dopo aver atteso un punto si riavvia il comando if self.PLINECommand.run(msgMapTool, msg) == True: self.showMsg("\n") self.AddRemoveSelSetByFence(self.PLINECommand.vertices) del self.PLINECommand self.PLINECommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA PER MODALITA' FCERCHIO e ICERCHIO (da step = 1 o 5) elif self.step == 5: # dopo aver atteso un punto si riavvia il comando if self.CIRCLECommand.run(msgMapTool, msg) == True: self.showMsg("\n") if (self.CIRCLECommand.centerPt is not None) and \ (self.CIRCLECommand.radius is not None): circle = QadCircle() circle.set(self.CIRCLECommand.centerPt, self.CIRCLECommand.radius) points = circle.asPolyline() if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WCircle") or \ self.currSelectionMode == "WCircle": self.AddRemoveSelSetByPolygon("WP", points) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CCircle") or \ self.currSelectionMode == "CCircle": self.AddRemoveSelSetByPolygon("CP", points) del self.CIRCLECommand self.CIRCLECommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DI SELEZIONE DI OGGETTI PER MODALITA' FOGGETTI e IOGGETTI (da step = 1 o 6) elif self.step == 6: # dopo aver atteso un punto si riavvia il comando if self.SSGetClass.run(msgMapTool, msg) == True: self.showMsg("\n") destCRS = self.SSGetClass.getPointMapTool().canvas.mapRenderer().destinationCrs() geoms = self.SSGetClass.entitySet.getGeometryCollection(destCRS) # trasformo la geometria if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WObjects") or \ self.currSelectionMode == "WObjects": self.AddRemoveSelSetByGeometry("WO", geoms) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CObjects") or \ self.currSelectionMode == "CObjects": self.AddRemoveSelSetByGeometry("CO", geoms) del self.SSGetClass self.SSGetClass = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA PER MODALITA' FPOLIGONO e IPOLIGONO (da step = 1 o 7) elif self.step == 7: # dopo aver atteso un punto si riavvia il comando if self.MPOLYGONCommand.run(msgMapTool, msg) == True: self.showMsg("\n") if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WPolygon") or \ self.currSelectionMode == "WPolygon": self.AddRemoveSelSetByPolygon("WP", self.MPOLYGONCommand.vertices) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CPolygon") or \ self.currSelectionMode == "CPolygon": self.AddRemoveSelSetByPolygon("CP", self.MPOLYGONCommand.vertices) del self.MPOLYGONCommand self.MPOLYGONCommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DI SELEZIONE DI OGGETTI PER MODALITA' FBUFFER e IBUFFER (da step = 1 o 8) elif self.step == 8: # dopo aver atteso un punto si riavvia il comando if self.MBUFFERCommand.run(msgMapTool, msg) == True: self.showMsg("\n") bufferGeoms = [] for layerEntitySet in self.MBUFFERCommand.entitySet.layerEntitySetList: geoms = layerEntitySet.getGeometryCollection() width = qad_utils.distMapToLayerCoordinates(self.MBUFFERCommand.width, \ self.MBUFFERCommand.getPointMapTool().canvas,\ layerEntitySet.layer) for geom in geoms: bufferGeoms.append(geom.buffer(width, self.MBUFFERCommand.segments)) if self.currSelectionMode == QadMsg.translate("Command_SSGET", "WBuffer") or \ self.currSelectionMode == "WBuffer": self.AddRemoveSelSetByGeometry("WO", bufferGeoms) elif self.currSelectionMode == QadMsg.translate("Command_SSGET", "CBuffer") or \ self.currSelectionMode == "CBuffer": self.AddRemoveSelSetByGeometry("CO", bufferGeoms) del self.MBUFFERCommand self.MBUFFERCommand = None if self.SingleSelection == True and self.entitySet.count() > 0: self.plugIn.setLastEntitySet(self.entitySet) return True # fine if self.exitAfterSelection == True: return True # fine self.WaitForFirstPoint() return False
def trimFeatures(self, geom, toExtend): LineTempLayer = None self.plugIn.beginEditCommand("Feature extended" if toExtend else "Feature trimmed", \ self.entitySet.getLayerList()) for layerEntitySet in self.entitySet.layerEntitySetList: layer = layerEntitySet.layer #layer.beginEditCommand("Feature extended") # test tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ layer) g = QgsGeometry(geom) if self.plugIn.canvas.mapRenderer().destinationCrs() != layer.crs(): # Trasformo la geometria nel sistema di coordinate del layer coordTransform = QgsCoordinateTransform(self.plugIn.canvas.mapRenderer().destinationCrs(), \ layer.crs()) g.transform(coordTransform) for featureId in layerEntitySet.featureIds: f = qad_utils.getFeatureById(layer, featureId) if f is None: continue if g.type() == QGis.Point: # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(g.asPoint(), f.geometry()) if dummy[1] is not None: intPts = [dummy[1]] else: intPts = qad_utils.getIntersectionPoints(g, f.geometry()) for intPt in intPts: if toExtend: newGeom = qad_utils.extendQgsGeometry(layer, f.geometry(), intPt, \ self.limitEntitySet, self.edgeMode, \ tolerance2ApproxCurve) if newGeom is not None: # aggiorno la feature con la geometria estesa extendedFeature = QgsFeature(f) extendedFeature.setGeometry(newGeom) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, extendedFeature, False, False) == False: self.plugIn.destroyEditCommand() return else: # trim result = qad_utils.trimQgsGeometry(layer, f.geometry(), intPt, \ self.limitEntitySet, self.edgeMode, \ tolerance2ApproxCurve) if result is not None: line1 = result[0] line2 = result[1] atSubGeom = result[2] if layer.geometryType() == QGis.Line: updGeom = qad_utils.setSubGeom(f.geometry(), line1, atSubGeom) if updGeom is None: self.plugIn.destroyEditCommand() return trimmedFeature1 = QgsFeature(f) trimmedFeature1.setGeometry(updGeom) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, trimmedFeature1, False, False) == False: self.plugIn.destroyEditCommand() return if line2 is not None: trimmedFeature2 = QgsFeature(f) trimmedFeature2.setGeometry(line2) # plugIn, layer, feature, coordTransform, refresh, check_validity if qad_layer.addFeatureToLayer(self.plugIn, layer, trimmedFeature2, None, False, False) == False: self.plugIn.destroyEditCommand() return else: # aggiungo le linee nei layer temporanei di QAD if LineTempLayer is None: LineTempLayer = qad_layer.createQADTempLayer(self.plugIn, QGis.Line) self.plugIn.addLayerToLastEditCommand("Feature trimmed", LineTempLayer) lineGeoms = [line1] if line2 is not None: lineGeoms.append(line2) # trasformo la geometria in quella dei layer temporanei # plugIn, pointGeoms, lineGeoms, polygonGeoms, coord, refresh if qad_layer.addGeometriesToQADTempLayers(self.plugIn, None, lineGeoms, None, layer.crs(), False) == False: self.plugIn.destroyEditCommand() return updGeom = qad_utils.delSubGeom(f.geometry(), atSubGeom) if updGeom is None or updGeom.isGeosEmpty(): # da cancellare # plugIn, layer, feature id, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, layer, f.id(), False) == False: self.plugIn.destroyEditCommand() return else: trimmedFeature1 = QgsFeature(f) trimmedFeature1.setGeometry(updGeom) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, layer, trimmedFeature1, False, False) == False: self.plugIn.destroyEditCommand() return self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1
def AddGeoms(self, currLayer): bufferGeoms = [] for layerEntitySet in self.entitySet.layerEntitySetList: geoms = layerEntitySet.getGeometryCollection() width = qad_utils.distMapToLayerCoordinates(self.width, \ self.SSGetClass.getPointMapTool().canvas,\ layerEntitySet.layer) tolerance = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.SSGetClass.getPointMapTool().canvas,\ layerEntitySet.layer) if layerEntitySet.layer.crs() != currLayer.crs(): coordTransform = QgsCoordinateTransform(layerEntitySet.layer.crs(),\ currLayer.crs()) # trasformo la geometria else: coordTransform = None for geom in geoms: g = qad_utils.ApproxCurvesOnGeom(geom.buffer(width, self.segments), \ self.segments, self.segments, \ tolerance) if coordTransform is not None: g.transform(coordTransform) bufferGeoms.append(g) self.plugIn.beginEditCommand("Feature buffered", currLayer) # filtro le features per tipo pointGeoms, lineGeoms, polygonGeoms = qad_utils.filterGeomsByType(bufferGeoms, \ currLayer.geometryType()) # aggiungo le geometrie del tipo corretto if currLayer.geometryType() == QGis.Line: polygonToLines = [] # Riduco le geometrie in linee for g in polygonGeoms: lines = qad_utils.asPointOrPolyline(g) for l in lines: if l.type() == QGis.Line: polygonToLines.append(l) # plugIn, layer, geoms, coordTransform , refresh, check_validity if qad_layer.addGeomsToLayer(self.plugIn, currLayer, polygonToLines, None, False, False) == False: self.plugIn.destroyEditCommand() return del polygonGeoms[:] # svuoto la lista # plugIn, layer, geoms, coordTransform , refresh, check_validity if qad_layer.addGeomsToLayer(self.plugIn, currLayer, bufferGeoms, None, False, False) == False: self.plugIn.destroyEditCommand() return if pointGeoms is not None and len(pointGeoms) > 0: PointTempLayer = qad_layer.createQADTempLayer(self.plugIn, QGis.Point) self.plugIn.addLayerToLastEditCommand("Feature buffered", PointTempLayer) if lineGeoms is not None and len(lineGeoms) > 0: LineTempLayer = qad_layer.createQADTempLayer(self.plugIn, QGis.Line) self.plugIn.addLayerToLastEditCommand("Feature buffered", LineTempLayer) if polygonGeoms is not None and len(polygonGeoms) > 0: PolygonTempLayer = qad_layer.createQADTempLayer(self.plugIn, QGis.Polygon) self.plugIn.addLayerToLastEditCommand("Feature buffered", PolygonTempLayer) # aggiungo gli scarti nei layer temporanei di QAD # trasformo la geometria in quella dei layer temporanei # plugIn, pointGeoms, lineGeoms, polygonGeoms, coord, refresh if qad_layer.addGeometriesToQADTempLayers(self.plugIn, pointGeoms, lineGeoms, polygonGeoms, \ currLayer.crs(), False) == False: self.plugIn.destroyEditCommand() return self.plugIn.endEditCommand()
def fillet(self): transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.plugIn.canvas, self.entity1.layer) tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ self.entity1.layer) if self.entity1.layer.crs() != self.entity2.layer.crs(): coordTransform = QgsCoordinateTransform(self.entity1.layer.crs(),\ self.entity2.layer.crs()) # trasformo la geometria transformedLinearObjectList2 = self.linearObjectList2.transform(coordTransform) transformedPointAt2 = coordTransform.transform(self.pointAt2) else: # stessa entità e stessa parte if self.entity1.layer.id() == self.entity2.layer.id() and \ self.entity1.featureId == self.entity2.featureId and \ self.partAt1 == self.partAt2: return False transformedLinearObjectList2 = qad_utils.QadLinearObjectList(self.linearObjectList2) transformedPointAt2 = self.pointAt2 epsg = self.entity1.layer.crs().authid() res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \ transformedLinearObjectList2, self.partAt2, transformedPointAt2,\ self.filletMode, transformedRadius, epsg) if res is None: # raccordo non possibile msg = QadMsg.translate("Command_FILLET", "\nFillet with radius <{0}> impossible.") #showMsg self.showMsg(msg.format(str(self.radius))) return False filletLinearObjectList = res[0] whatToDoPoly1 = res[1] whatToDoPoly2 = res[2] self.plugIn.beginEditCommand("Feature edited", [self.entity1.layer, self.entity2.layer]) if whatToDoPoly1 == 1: # 1=modificare f = self.entity1.getFeature() geom = f.geometry() updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: self.plugIn.destroyEditCommand() return False f.setGeometry(updGeom) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity1.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly1 == 2: # 2=cancellare # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity1.layer, \ self.entity1.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly2 == 1: # 1=modificare if self.entity1.layer.crs() != self.entity2.layer.crs(): coordTransform = QgsCoordinateTransform(self.entity2.layer.crs(),\ self.entity1.layer.crs()) # trasformo la geometria transformedLinearObjectList2 = self.filletLinearObjectList.transform(coordTransform) else: transformedLinearObjectList2 = filletLinearObjectList tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ self.entity2.layer) f = self.entity2.getFeature() geom = f.geometry() updSubGeom = QgsGeometry.fromPolyline(transformedLinearObjectList2.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2) if updGeom is None: self.plugIn.destroyEditCommand() return False f.setGeometry(updGeom) # plugIn, layer, feature, refresh, check_validity if qad_layer.updateFeatureToLayer(self.plugIn, self.entity2.layer, f, False, False) == False: self.plugIn.destroyEditCommand() return False elif whatToDoPoly2 == 2: # 2=cancellare # plugIn, layer, featureId, refresh if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity2.layer, \ self.entity2.featureId, False) == False: self.plugIn.destroyEditCommand() return False if whatToDoPoly1 == 0 and whatToDoPoly2 == 0: # 0=niente geom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) # plugIn, layer, geom, coordTransform, refresh, check_validity if qad_layer.addGeomToLayer(self.plugIn, self.entity1.layer, geom, None, False, False) == False: self.plugIn.destroyEditCommand() return False self.plugIn.endEditCommand() self.nOperationsToUndo = self.nOperationsToUndo + 1 return True
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() tmpLinearObjectList = None # si richiede la selezione del secondo oggetto if self.mode == Qad_fillet_maptool_ModeEnum.ASK_FOR_SECOND_LINESTRING: if self.tmpEntity.isInitialized(): transformedPt = self.canvas.mapRenderer().mapToLayerCoordinates(self.tmpEntity.layer, self.tmpPoint) geom = self.tmpEntity.getGeometry() if self.layer.crs() != self.tmpEntity.layer.crs(): coordTransform = QgsCoordinateTransform(self.tmpEntity.layer.crs(),\ self.layer.crs()) # trasformo la geometria geom.transform(coordTransform) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, geom) if dummy[2] is not None: # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) tmpLinearObjectList = qad_utils.QadLinearObjectList() tmpLinearObjectList.fromPolyline(subGeom.asPolyline()) # la funzione ritorna una lista con (<minima distanza al quadrato>, # <punto più vicino> # <indice della parte più vicina> # <"a sinistra di">) dummy = tmpLinearObjectList.closestPartWithContext(transformedPt) tmpPartAt = dummy[2] tmpPointAt = dummy[1] # stessa entità e stessa parte if self.layer.id() == self.tmpEntity.layer.id() and \ self.featureId == self.tmpEntity.featureId and \ self.partAt == tmpPartAt: return epsg = self.layer.crs().authid() if self.tmpShiftKey == True: # tasto shift premuto durante il movimento del mouse # filletMode = 1 # modalità di raccordo; 1=Taglia-estendi # raggio = 0 res = qad_utils.getFilletLinearObjectList(self.linearObjectList, self.partAt, self.pointAt, \ tmpLinearObjectList, tmpPartAt, tmpPointAt,\ 1, 0, epsg) else: res = qad_utils.getFilletLinearObjectList(self.linearObjectList, self.partAt, self.pointAt, \ tmpLinearObjectList, tmpPartAt, tmpPointAt,\ self.filletMode, self.transformedRadius, epsg) if res is None: # raccordo non possibile return tmpLinearObjectList = res[0] # si richiede la selezione della polilinea elif self.mode == Qad_fillet_maptool_ModeEnum.ASK_FOR_POLYLINE: if self.tmpEntity.isInitialized(): self.transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.canvas, self.tmpEntity.layer) transformedPt = self.canvas.mapRenderer().mapToLayerCoordinates(self.tmpEntity.layer, self.tmpPoint) self.tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.canvas,\ self.tmpEntity.layer) geom = self.tmpEntity.getGeometry() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, geom) if dummy[2] is not None: # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) tmpLinearObjectList = qad_utils.QadLinearObjectList() tmpLinearObjectList.fromPolyline(subGeom.asPolyline()) tmpLinearObjectList.fillet(self.transformedRadius) if tmpLinearObjectList is not None: pts = tmpLinearObjectList.asPolyline(self.tolerance2ApproxCurve) if self.layer.geometryType() == QGis.Polygon: geom = QgsGeometry.fromPolygon([pts]) else: geom = QgsGeometry.fromPolyline(pts) self.__rubberBand.addGeometry(geom, self.layer)