def waitForSegmentLength(self): self.step = QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) self.GetDistClass.msg = QadMsg.translate("Command_MEASURE", "Enter the length of segment: ") self.GetDistClass.run()
def waitForTotalLength(self, msgMapTool, msg): self.step = 8 self.OpType = "length" # si appresta ad attendere una distanza if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter total length <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.plugIn.lastTotal_lengthen)) self.GetDistClass.startPt = self.startPt self.GetDistClass.dist = self.plugIn.lastTotal_lengthen self.GetDistClass.inputMode = QadInputModeEnum.NONE self.GetDistClass.run(msgMapTool, msg)
def waitForSegmentLength(self): self.step = QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) self.GetDistClass.msg = QadMsg.translate("Command_MEASURE", "Enter the length of segment: ") self.GetDistClass.run()
def waitForTotalLength(self, msgMapTool, msg): self.step = 8 self.OpType = "length" # si appresta ad attendere una distanza if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter total length <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.plugIn.lastTotal_lengthen)) self.GetDistClass.startPt = self.startPt self.GetDistClass.dist = self.plugIn.lastTotal_lengthen self.GetDistClass.inputMode = QadInputModeEnum.NONE self.GetDistClass.run(msgMapTool, msg)
class QadFILLETCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadFILLETCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "FILLET") def getEnglishName(self): return "FILLET" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runFILLETCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/fillet.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_FILLET", "Rounds and fillets the edges of objects.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.GetDistClass = None self.entity1 = QadEntity() self.atSubGeom1 = None self.linearObjectList1 = qad_utils.QadLinearObjectList() self.partAt1 = 0 self.pointAt1 = None self.entity2 = QadEntity() self.atSubGeom2 = None self.linearObjectList2 = qad_utils.QadLinearObjectList() self.partAt2 = 0 self.pointAt2 = None self.filletMode = plugIn.filletMode # modalità di raccordo; 1=Taglia-estendi, 2=Non taglia-estendi self.radius = QadVariables.get( QadMsg.translate("Environment variables", "FILLETRAD")) self.multi = False self.nOperationsToUndo = 0 def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass self.entity1.deselectOnLayer() self.entity2.deselectOnLayer() def getPointMapTool(self, drawMode=QadGetPointDrawModeEnum.NONE): # quando si é in fase di richiesta distanza if self.step == 3 or self.step == 5 or self.step == 7: return self.GetDistClass.getPointMapTool() elif (self.plugIn is not None): if self.PointMapTool is None: self.PointMapTool = Qad_fillet_maptool(self.plugIn) return self.PointMapTool else: return None def getCurrentContextualMenu(self): # quando si é in fase di richiesta distanza if self.step == 3 or self.step == 5 or self.step == 7: return self.GetDistClass.getCurrentContextualMenu() else: return self.contextualMenu #============================================================================ # setEntityInfo #============================================================================ def setEntityInfo(self, firstObj, layer, featureId, point): """ Setta self.entity, self.atSubGeom, self.linearObjectList, self.partAt, self.pointAt di primo o del secondo oggetto da raccordare (vedi <firstObj>) """ if firstObj: e = self.entity1 l = self.linearObjectList1 else: e = self.entity2 l = self.linearObjectList2 e.set(layer, featureId) # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, e.getGeometry()) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(point, geom) if dummy[2] is not None: # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) if firstObj: subGeom, self.atSubGeom1 = qad_utils.getSubGeomAtVertex( geom, dummy[2]) else: subGeom, self.atSubGeom2 = qad_utils.getSubGeomAtVertex( geom, dummy[2]) l.fromPolyline(subGeom.asPolyline()) e.selectOnLayer(False) # non incrementale # la funzione ritorna una lista con (<minima distanza al quadrato>, # <punto più vicino> # <indice della parte più vicina> # <"a sinistra di">) dummy = l.closestPartWithContext(point) if firstObj: self.partAt1 = dummy[2] self.pointAt1 = dummy[1] else: self.partAt2 = dummy[2] self.pointAt2 = dummy[1] return True else: e.deselectOnLayer() return False #============================================================================ # filletPolyline #============================================================================ def filletPolyline(self): layer = self.entity1.layer tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity1.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, f.getGeometry()) self.linearObjectList1.fillet(self.radius) updSubGeom = QgsGeometry.fromPolyline( self.linearObjectList1.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(layer, 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 #============================================================================ # fillet #============================================================================ def fillet(self): tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # 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 # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.plugIn.canvas.mapSettings().destinationCrs().authid() res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \ self.linearObjectList2, self.partAt2, self.pointAt2,\ self.filletMode, self.radius, 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() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity1.layer, 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 # trasformo la geometria nel crs del layer f.setGeometry( self.mapToLayerCoordinates(self.entity1.layer, 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 # se non si tratta della stessa entità if self.entity1 != self.entity2: # 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 tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity2.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity2.layer, f.geometry()) updSubGeom = QgsGeometry.fromPolyline( filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2) if updGeom is None: self.plugIn.destroyEditCommand() return False # trasformo la geometria nel crs del layer f.setGeometry( self.mapToLayerCoordinates(self.entity2.layer, 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 # se non si tratta della stessa entità if self.entity1 != self.entity2: # 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)) # trasformo la geometria nel crs del layer geom = self.mapToLayerCoordinates(self.entity1.layer, geom) # 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 #============================================================================ # waitForFirstEntSel #============================================================================ def waitForFirstEntSel(self): self.step = 1 # imposto il map tool self.getPointMapTool().setMode( Qad_fillet_maptool_ModeEnum.ASK_FOR_FIRST_LINESTRING) # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForFirstEntSel" keyWords = QadMsg.translate("Command_FILLET", "Undo") + "/" + \ QadMsg.translate("Command_FILLET", "Polyline") + "/" + \ QadMsg.translate("Command_FILLET", "Radius", "waitForFirstEntSel") + "/" + \ QadMsg.translate("Command_FILLET", "Trim") + "/" + \ QadMsg.translate("Command_FILLET", "Multiple") prompt = QadMsg.translate( "Command_FILLET", "Select first object or [{0}]: ").format(keyWords) englishKeyWords = "Undo" + "/" + "Polyline" + "/" + "Radius" + "/" + "Trim" + "/" + "Multiple" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, valore nullo non permesso self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) #============================================================================ # WaitForPolyline #============================================================================ def WaitForPolyline(self): self.step = 2 # imposto il map tool self.getPointMapTool().setMode( Qad_fillet_maptool_ModeEnum.ASK_FOR_POLYLINE) self.getPointMapTool().radius = self.radius # l'opzione Radius viene tradotta in italiano in "Raggio" nel contesto "WaitForPolyline" keyWords = QadMsg.translate("Command_FILLET", "Radius", "WaitForPolyline") prompt = QadMsg.translate( "Command_FILLET", "Select polyline or [{0}]: ").format(keyWords) englishKeyWords = "Radius" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, valore nullo non permesso self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) #============================================================================ # waitForFilletMode #============================================================================ def waitForFilletMode(self): self.step = 4 # imposto il map tool self.getPointMapTool().setMode(Qad_fillet_maptool_ModeEnum.NONE) keyWords = QadMsg.translate("Command_FILLET", "Trim-extend") + "/" + \ QadMsg.translate("Command_FILLET", "No trim-extend") if self.filletMode == 1: default = QadMsg.translate("Command_FILLET", "Trim-extend") elif self.filletMode == 2: default = QadMsg.translate("Command_FILLET", "No trim-extend") prompt = QadMsg.translate("Command_FILLET", "Specify trim mode [{0}] <{1}>: ").format( keyWords, default) englishKeyWords = "Trim-extend" + "/" + "No trim-extend" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave o un numero reale # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, default, \ keyWords) #============================================================================ # waitForSecondEntSel #============================================================================ def waitForSecondEntSel(self): self.step = 6 # imposto il map tool self.getPointMapTool().filletMode = self.filletMode self.getPointMapTool().radius = self.radius self.getPointMapTool().setEntityInfo(self.entity1.layer, self.entity1.featureId, self.linearObjectList1, \ self.partAt1, self.pointAt1) self.getPointMapTool().setMode( Qad_fillet_maptool_ModeEnum.ASK_FOR_SECOND_LINESTRING) # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForSecondEntSel" keyWords = QadMsg.translate("Command_FILLET", "Radius", "waitForSecondEntSel") prompt = QadMsg.translate( "Command_FILLET", "Select second object or shift-select to apply corner or [{0}]: " ).format(keyWords) englishKeyWords = "Radius" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, valore nullo non permesso self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando if self.step == 0: CurrSettingsMsg = QadMsg.translate("QAD", "\nCurrent settings: ") if self.filletMode == 1: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate( "Command_FILLET", "Mode = Trim-extend") else: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate( "Command_FILLET", "Mode = No trim-extend") CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate( "Command_FILLET", ", Radius = ") + str(self.radius) self.showMsg(CurrSettingsMsg) self.waitForFirstEntSel() return False # continua #========================================================================= # RISPOSTA ALLA SELEZIONE PRIMO OGGETTO elif self.step == 1: 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: if value == QadMsg.translate("Command_FILLET", "Undo") or value == "Undo": if self.nOperationsToUndo > 0: self.nOperationsToUndo = self.nOperationsToUndo - 1 self.plugIn.undoEditCommand() else: self.showMsg( QadMsg.translate( "QAD", "\nThe command has been canceled.")) self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto elif value == QadMsg.translate( "Command_FILLET", "Polyline") or value == "Polyline": self.WaitForPolyline() # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForFirstEntSel" elif value == QadMsg.translate( "Command_FILLET", "Radius", "waitForFirstEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 3 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_FILLET", "Trim") or value == "Trim": self.waitForFilletMode() elif value == QadMsg.translate( "Command_FILLET", "Multiple") or value == "Multiple": self.multi = True self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers( self.plugIn.canvas ): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto else: return True # fine comando return False #========================================================================= # RISPOSTA ALLA SELEZIONE DI UNA POLILINEA (da step = 1) elif self.step == 2: 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: # l'opzione Radius viene tradotta in italiano in "Raggio" nel contesto "WaitForPolyline" if value == QadMsg.translate( "Command_FILLET", "Radius", "WaitForPolyline") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 5 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers( self.plugIn.canvas ): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.WaitForPolyline() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 1) elif self.step == 3: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set( QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA MODALITA' DI TAGLIO (da step = 1) elif self.step == 4: # dopo aver atteso un punto o un numero reale 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 value = self.filletMode else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: if value == QadMsg.translate( "Command_FILLET", "Trim-extend") or value == "Trim-extend": self.filletMode = 1 elif value == QadMsg.translate( "Command_FILLET", "No trim-extend") or value == "No trim-extend": self.filletMode = 2 self.plugIn.setFilletMode(self.filletMode) self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 3) elif self.step == 5: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set( QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.WaitForPolyline() self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA SELEZIONE SECONDO OGGETTO elif self.step == 6: 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForSecondEntSel" if value == QadMsg.translate( "Command_FILLET", "Radius", "waitForSecondEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 7 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity2.clear() self.linearObjectList2.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(False, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.getPointMapTool().shiftKey == True: dummyRadius = self.radius self.radius = 0 dummyFilletMode = self.filletMode self.filletMode = 1 # modalità di raccordo; 1=Taglia-estendi result = self.fillet() self.radius = dummyRadius self.filletMode = dummyFilletMode else: result = self.fillet() if result == False: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers( self.plugIn.canvas ): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(False, result[1], result[0].id(), result[2]) == True: if self.fillet() == False: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 6) elif self.step == 7: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set( QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando
def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando if self.step == 0: CurrSettingsMsg = QadMsg.translate("QAD", "\nCurrent settings: ") if self.filletMode == 1: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate( "Command_FILLET", "Mode = Trim-extend") else: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate( "Command_FILLET", "Mode = No trim-extend") CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate( "Command_FILLET", ", Radius = ") + str(self.radius) self.showMsg(CurrSettingsMsg) self.waitForFirstEntSel() return False # continua #========================================================================= # RISPOSTA ALLA SELEZIONE PRIMO OGGETTO elif self.step == 1: 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: if value == QadMsg.translate("Command_FILLET", "Undo") or value == "Undo": if self.nOperationsToUndo > 0: self.nOperationsToUndo = self.nOperationsToUndo - 1 self.plugIn.undoEditCommand() else: self.showMsg( QadMsg.translate( "QAD", "\nThe command has been canceled.")) self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto elif value == QadMsg.translate( "Command_FILLET", "Polyline") or value == "Polyline": self.WaitForPolyline() # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForFirstEntSel" elif value == QadMsg.translate( "Command_FILLET", "Radius", "waitForFirstEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 3 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_FILLET", "Trim") or value == "Trim": self.waitForFilletMode() elif value == QadMsg.translate( "Command_FILLET", "Multiple") or value == "Multiple": self.multi = True self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers( self.plugIn.canvas ): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto else: return True # fine comando return False #========================================================================= # RISPOSTA ALLA SELEZIONE DI UNA POLILINEA (da step = 1) elif self.step == 2: 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: # l'opzione Radius viene tradotta in italiano in "Raggio" nel contesto "WaitForPolyline" if value == QadMsg.translate( "Command_FILLET", "Radius", "WaitForPolyline") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 5 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers( self.plugIn.canvas ): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.WaitForPolyline() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 1) elif self.step == 3: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set( QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA MODALITA' DI TAGLIO (da step = 1) elif self.step == 4: # dopo aver atteso un punto o un numero reale 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 value = self.filletMode else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: if value == QadMsg.translate( "Command_FILLET", "Trim-extend") or value == "Trim-extend": self.filletMode = 1 elif value == QadMsg.translate( "Command_FILLET", "No trim-extend") or value == "No trim-extend": self.filletMode = 2 self.plugIn.setFilletMode(self.filletMode) self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 3) elif self.step == 5: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set( QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.WaitForPolyline() self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA SELEZIONE SECONDO OGGETTO elif self.step == 6: 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForSecondEntSel" if value == QadMsg.translate( "Command_FILLET", "Radius", "waitForSecondEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 7 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity2.clear() self.linearObjectList2.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(False, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.getPointMapTool().shiftKey == True: dummyRadius = self.radius self.radius = 0 dummyFilletMode = self.filletMode self.filletMode = 1 # modalità di raccordo; 1=Taglia-estendi result = self.fillet() self.radius = dummyRadius self.filletMode = dummyFilletMode else: result = self.fillet() if result == False: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers( self.plugIn.canvas ): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(False, result[1], result[0].id(), result[2]) == True: if self.fillet() == False: self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel( ) # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 6) elif self.step == 7: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set( QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForSecondEntSel( ) # si appresta ad attendere la selezione del secondo oggetto self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando
class QadFILLETCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadFILLETCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "FILLET") def getEnglishName(self): return "FILLET" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runFILLETCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/fillet.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_FILLET", "Rounds and fillets the edges of objects.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.GetDistClass = None self.entity1 = QadEntity() self.atSubGeom1 = None self.linearObjectList1 = qad_utils.QadLinearObjectList() self.partAt1 = 0 self.pointAt1 = None self.entity2 = QadEntity() self.atSubGeom2 = None self.linearObjectList2 = qad_utils.QadLinearObjectList() self.partAt2 = 0 self.pointAt2 = None self.filletMode = plugIn.filletMode # modalità di raccordo; 1=Taglia-estendi, 2=Non taglia-estendi self.radius = QadVariables.get(QadMsg.translate("Environment variables", "FILLETRAD")) self.multi = False self.nOperationsToUndo = 0 def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass self.entity1.deselectOnLayer() self.entity2.deselectOnLayer() def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE): # quando si é in fase di richiesta distanza if self.step == 3 or self.step == 5 or self.step == 7: return self.GetDistClass.getPointMapTool() elif (self.plugIn is not None): if self.PointMapTool is None: self.PointMapTool = Qad_fillet_maptool(self.plugIn) return self.PointMapTool else: return None #============================================================================ # setEntityInfo #============================================================================ def setEntityInfo(self, firstObj, layer, featureId, point): """ Setta self.entity, self.atSubGeom, self.linearObjectList, self.partAt, self.pointAt di primo o del secondo oggetto da raccordare (vedi <firstObj>) """ if firstObj: e = self.entity1 l = self.linearObjectList1 else: e = self.entity2 l = self.linearObjectList2 e.set(layer, featureId) # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, e.getGeometry()) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(point, geom) if dummy[2] is not None: # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) if firstObj: subGeom, self.atSubGeom1 = qad_utils.getSubGeomAtVertex(geom, dummy[2]) else: subGeom, self.atSubGeom2 = qad_utils.getSubGeomAtVertex(geom, dummy[2]) l.fromPolyline(subGeom.asPolyline()) e.selectOnLayer(False) # non incrementale # la funzione ritorna una lista con (<minima distanza al quadrato>, # <punto più vicino> # <indice della parte più vicina> # <"a sinistra di">) dummy = l.closestPartWithContext(point) if firstObj: self.partAt1 = dummy[2] self.pointAt1 = dummy[1] else: self.partAt2 = dummy[2] self.pointAt2 = dummy[1] return True else: e.deselectOnLayer() return False #============================================================================ # filletPolyline #============================================================================ def filletPolyline(self): layer = self.entity1.layer tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity1.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, f.getGeometry()) self.linearObjectList1.fillet(self.radius) updSubGeom = QgsGeometry.fromPolyline(self.linearObjectList1.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1) if updGeom is None: return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(layer, 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 #============================================================================ # fillet #============================================================================ def fillet(self): tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # 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 # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.plugIn.canvas.mapRenderer().destinationCrs().authid() res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \ self.linearObjectList2, self.partAt2, self.pointAt2,\ self.filletMode, self.radius, 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() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity1.layer, 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 # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(self.entity1.layer, 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 # se non si tratta della stessa entità if self.entity1 != self.entity2: # 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 tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) f = self.entity2.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity2.layer, f.geometry()) updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve)) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2) if updGeom is None: self.plugIn.destroyEditCommand() return False # trasformo la geometria nel crs del layer f.setGeometry(self.mapToLayerCoordinates(self.entity2.layer, 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 # se non si tratta della stessa entità if self.entity1 != self.entity2: # 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)) # trasformo la geometria nel crs del layer geom = self.mapToLayerCoordinates(self.entity1.layer, geom) # 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 #============================================================================ # waitForFirstEntSel #============================================================================ def waitForFirstEntSel(self): self.step = 1 # imposto il map tool self.getPointMapTool().setMode(Qad_fillet_maptool_ModeEnum.ASK_FOR_FIRST_LINESTRING) # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForFirstEntSel" keyWords = QadMsg.translate("Command_FILLET", "Undo") + "/" + \ QadMsg.translate("Command_FILLET", "Polyline") + "/" + \ QadMsg.translate("Command_FILLET", "Radius", "waitForFirstEntSel") + "/" + \ QadMsg.translate("Command_FILLET", "Trim") + "/" + \ QadMsg.translate("Command_FILLET", "Multiple") prompt = QadMsg.translate("Command_FILLET", "Select first object or [{0}]: ").format(keyWords) englishKeyWords = "Undo" + "/" + "Polyline" + "/" + "Radius" + "/" + "Trim" + "/" + "Multiple" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, valore nullo non permesso self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) #============================================================================ # WaitForPolyline #============================================================================ def WaitForPolyline(self): self.step = 2 # imposto il map tool self.getPointMapTool().setMode(Qad_fillet_maptool_ModeEnum.ASK_FOR_POLYLINE) self.getPointMapTool().radius = self.radius # l'opzione Radius viene tradotta in italiano in "Raggio" nel contesto "WaitForPolyline" keyWords = QadMsg.translate("Command_FILLET", "Radius", "WaitForPolyline") prompt = QadMsg.translate("Command_FILLET", "Select polyline or [{0}]: ").format(keyWords) englishKeyWords = "Radius" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, valore nullo non permesso self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) #============================================================================ # waitForFilletMode #============================================================================ def waitForFilletMode(self): self.step = 4 # imposto il map tool self.getPointMapTool().setMode(Qad_fillet_maptool_ModeEnum.NONE) keyWords = QadMsg.translate("Command_FILLET", "Trim-extend") + "/" + \ QadMsg.translate("Command_FILLET", "No trim-extend") if self.filletMode == 1: default = QadMsg.translate("Command_FILLET", "Trim-extend") elif self.filletMode == 2: default = QadMsg.translate("Command_FILLET", "No trim-extend") prompt = QadMsg.translate("Command_FILLET", "Specify trim mode [{0}] <{1}>: ").format(keyWords, default) englishKeyWords = "Trim-extend" + "/" + "No trim-extend" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave o un numero reale # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, default, \ keyWords) #============================================================================ # waitForSecondEntSel #============================================================================ def waitForSecondEntSel(self): self.step = 6 # imposto il map tool self.getPointMapTool().filletMode = self.filletMode self.getPointMapTool().radius = self.radius self.getPointMapTool().setEntityInfo(self.entity1.layer, self.entity1.featureId, self.linearObjectList1, \ self.partAt1, self.pointAt1) self.getPointMapTool().setMode(Qad_fillet_maptool_ModeEnum.ASK_FOR_SECOND_LINESTRING) # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForSecondEntSel" keyWords = QadMsg.translate("Command_FILLET", "Radius", "waitForSecondEntSel") prompt = QadMsg.translate("Command_FILLET", "Select second object or shift-select to apply corner or [{0}]: ").format(keyWords) englishKeyWords = "Radius" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, valore nullo non permesso self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) def run(self, msgMapTool = False, msg = None): 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 # fine comando if self.step == 0: CurrSettingsMsg = QadMsg.translate("QAD", "\nCurrent settings: ") if self.filletMode == 1: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_FILLET", "Mode = Trim-extend") else: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_FILLET", "Mode = No trim-extend") CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_FILLET", ", Radius = ") + str(self.radius) self.showMsg(CurrSettingsMsg) self.waitForFirstEntSel() return False # continua #========================================================================= # RISPOSTA ALLA SELEZIONE PRIMO OGGETTO elif self.step == 1: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_FILLET", "Undo") or value == "Undo": if self.nOperationsToUndo > 0: self.nOperationsToUndo = self.nOperationsToUndo - 1 self.plugIn.undoEditCommand() else: self.showMsg(QadMsg.translate("QAD", "\nThe command has been canceled.")) self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto elif value == QadMsg.translate("Command_FILLET", "Polyline") or value == "Polyline": self.WaitForPolyline() # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForFirstEntSel" elif value == QadMsg.translate("Command_FILLET", "Radius", "waitForFirstEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 3 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_FILLET", "Trim") or value == "Trim": self.waitForFilletMode() elif value == QadMsg.translate("Command_FILLET", "Multiple") or value == "Multiple": self.multi = True self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto else: return True # fine comando return False #========================================================================= # RISPOSTA ALLA SELEZIONE DI UNA POLILINEA (da step = 1) elif self.step == 2: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: # l'opzione Radius viene tradotta in italiano in "Raggio" nel contesto "WaitForPolyline" if value == QadMsg.translate("Command_FILLET", "Radius", "WaitForPolyline") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 5 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.WaitForPolyline() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 1) elif self.step == 3: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set(QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA MODALITA' DI TAGLIO (da step = 1) elif self.step == 4: # dopo aver atteso un punto o un numero reale 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 value = self.filletMode else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_FILLET", "Trim-extend") or value == "Trim-extend": self.filletMode = 1 elif value == QadMsg.translate("Command_FILLET", "No trim-extend") or value == "No trim-extend": self.filletMode = 2 self.plugIn.setFilletMode(self.filletMode) self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 3) elif self.step == 5: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set(QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.WaitForPolyline() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA SELEZIONE SECONDO OGGETTO elif self.step == 6: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForSecondEntSel" if value == QadMsg.translate("Command_FILLET", "Radius", "waitForSecondEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 7 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity2.clear() self.linearObjectList2.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(False, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.getPointMapTool().shiftKey == True: dummyRadius = self.radius self.radius = 0 dummyFilletMode = self.filletMode self.filletMode = 1 # modalità di raccordo; 1=Taglia-estendi result = self.fillet() self.radius = dummyRadius self.filletMode = dummyFilletMode else: result = self.fillet() if result == False: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(False, result[1], result[0].id(), result[2]) == True: if self.fillet() == False: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 6) elif self.step == 7: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set(QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando
class QadMEASURECommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadMEASURECommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "MEASURE") def getEnglishName(self): return "MEASURE" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runMEASURECommand) def getIcon(self): return QIcon(":/plugins/qad/icons/measure.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate( "Command_MEASURE", "Creates punctual objects at measured intervals along the length or perimeter of an object." ) def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.entSelClass = None self.GetDistClass = None self.objectAlignment = True self.segmentLength = 1 def __del__(self): QadCommandClass.__del__(self) if self.entSelClass is not None: self.entSelClass.entity.deselectOnLayer() del self.entSelClass def getPointMapTool(self, drawMode=QadGetPointDrawModeEnum.NONE): if self.step == QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH: # quando si é in fase di richiesta distanza return self.GetDistClass.getPointMapTool() else: return QadCommandClass.getPointMapTool(self, drawMode) def getCurrentContextualMenu(self): if self.step == QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH: # quando si é in fase di richiesta distanza return self.GetDistClass.getCurrentContextualMenu() else: return self.contextualMenu #============================================================================ # waitForEntsel #============================================================================ def waitForEntsel(self, msgMapTool, msg): if self.entSelClass is not None: del self.entSelClass self.step = QadMEASURECommandClassStepEnum.ASK_FOR_ENT self.entSelClass = QadEntSelClass(self.plugIn) self.entSelClass.msg = QadMsg.translate("Command_MEASURE", "Select object to measure: ") # scarto la selezione di punti self.entSelClass.checkPointLayer = False self.entSelClass.checkLineLayer = True self.entSelClass.checkPolygonLayer = True self.entSelClass.checkDimLayers = False self.entSelClass.onlyEditableLayers = False self.entSelClass.run(msgMapTool, msg) #============================================================================ # waitForAlignmentObjs #============================================================================ def waitForAlignmentObjs(self): self.step = QadMEASURECommandClassStepEnum.ASK_FOR_ALIGNMENT keyWords = QadMsg.translate("QAD", "Yes") + "/" + QadMsg.translate( "QAD", "No") self.defaultValue = QadMsg.translate("QAD", "Yes") prompt = QadMsg.translate("Command_MEASURE", "Align with object ? [{0}] <{1}>: ").format( keyWords, self.defaultValue) englishKeyWords = "Yes" + "/" + "No" keyWords += "_" + englishKeyWords # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) #============================================================================ # waitForSegmentLength #============================================================================ def waitForSegmentLength(self): self.step = QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) self.GetDistClass.msg = QadMsg.translate( "Command_MEASURE", "Enter the length of segment: ") self.GetDistClass.run() #============================================================================ # addFeature #============================================================================ def addFeature(self, layer, insPt, rot): transformedPoint = self.mapToLayerCoordinates(layer, insPt) g = QgsGeometry.fromPoint(transformedPoint) f = QgsFeature() f.setGeometry(g) # Add attribute fields to feature. fields = layer.pendingFields() f.setFields(fields) # assegno i valori di default provider = layer.dataProvider() for field in fields.toList(): i = fields.indexFromName(field.name()) f[field.name()] = provider.defaultValue(i) # se la scala dipende da un campo scaleFldName = qad_layer.get_symbolScaleFieldName(layer) if len(scaleFldName) > 0: f.setAttribute(scaleFldName, 1.0) # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(layer) if len(rotFldName) > 0: f.setAttribute(rotFldName, qad_utils.toDegrees(rot)) return qad_layer.addFeatureToLayer(self.plugIn, layer, f) #============================================================================ # doMeasure #============================================================================ def doMeasure(self, dstLayer): f = self.entSelClass.entity.getFeature() if f is None: return layer = self.entSelClass.entity.layer # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, f.geometry()) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(self.entSelClass.point, geom) if dummy[2] is None: return False # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) pathLinearObjectList = qad_utils.QadLinearObjectList() geomType = subGeom.type() pathLinearObjectList.fromPolyline(subGeom.asPolyline()) length = pathLinearObjectList.length() self.plugIn.beginEditCommand("Feature measured", dstLayer) i = 1 distanceFromStart = self.segmentLength while distanceFromStart <= length: pt, rot = pathLinearObjectList.getPointFromStart(distanceFromStart) if self.addFeature(dstLayer, pt, rot if self.objectAlignment else 0) == False: self.plugIn.destroyEditCommand() return False i = i + 1 distanceFromStart = distanceFromStart + self.segmentLength self.plugIn.endEditCommand() return True def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable( self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isSymbolLayer(currLayer) == False: errMsg = QadMsg.translate( "QAD", "\nCurrent layer is not a symbol layer.") errMsg = errMsg + QadMsg.translate( "QAD", "\nA symbol layer is a vector punctual layer without label.\n") self.showErr(errMsg) return True # fine comando if len(QadDimStyles.getDimListByLayer(currLayer)) > 0: errMsg = QadMsg.translate( "QAD", "\nThe current layer belongs to a dimension style.\n") self.showErr(errMsg) return True # fine comando if self.step == 0: self.waitForEntsel(msgMapTool, msg) return False # continua #========================================================================= # RISPOSTA ALLA SELEZIONE DI UN'ENTITA' (da step = 0) elif self.step == QadMEASURECommandClassStepEnum.ASK_FOR_ENT: if self.entSelClass.run(msgMapTool, msg) == True: if self.entSelClass.entity.isInitialized(): # se il layer di destinazione è di tipo simbolo if qad_layer.isSymbolLayer(currLayer) == True: # se il simbolo può essere ruotato if len(qad_layer.get_symbolRotationFieldName( currLayer)) > 0: self.waitForAlignmentObjs() else: self.waitForSegmentLength() return False else: if self.entSelClass.canceledByUsr == True: # fine comando return True self.showMsg( QadMsg.translate("QAD", "No geometries in this position.")) self.waitForEntsel(msgMapTool, msg) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DI ALLINEARE GLI OGGETTI (da step = ASK_FOR_ENT) elif self.step == QadMEASURECommandClassStepEnum.ASK_FOR_ALIGNMENT: # dopo aver atteso una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica if self.getPointMapTool( ).rightButton == True: # se usato il tasto destro del mouse value = self.defaultValue else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: # la parola chiave arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("QAD", "Yes") or value == "Yes": self.objectAlignment = True else: self.objectAlignment = False self.waitForSegmentLength() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA LUNGHEZZA DEL SEGMENTO (da step = ASK_FOR_ALIGNMENT) #========================================================================= elif self.step == QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH: # dopo aver atteso un numero reale si riavvia il comando if self.GetDistClass.run(msgMapTool, msg) == True: self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato da altri maptool if self.GetDistClass.dist is not None: self.segmentLength = self.GetDistClass.dist self.doMeasure(currLayer) del self.GetDistClass return True # fine comando else: return False
class QadINSERTCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadINSERTCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "INSER") def getEnglishName(self): return "INSERT" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runINSERTCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/insert.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_INSERT", "Inserisce un simbolo.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.insPt = None self.scale = self.plugIn.lastScale self.rot = self.plugIn.lastRot self.GetDistClass = None self.GetAngleClass = None def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass if self.GetAngleClass is not None: del self.GetAngleClass def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE): # quando si é in fase di richiesta distanza (scala) if self.step == 2: return self.GetDistClass.getPointMapTool() # quando si é in fase di richiesta rotazione elif self.step == 3: return self.GetAngleClass.getPointMapTool() else: return QadCommandClass.getPointMapTool(self, drawMode) def addFeature(self, layer): transformedPoint = self.mapToLayerCoordinates(layer, self.insPt) g = QgsGeometry.fromPoint(transformedPoint) f = QgsFeature() f.setGeometry(g) # Add attribute fields to feature. fields = layer.pendingFields() f.setFields(fields) # assegno i valori di default provider = layer.dataProvider() for field in fields.toList(): i = fields.indexFromName(field.name()) f[field.name()] = provider.defaultValue(i) # se la scala dipende da un campo scaleFldName = qad_layer.get_symbolScaleFieldName(layer) if len(scaleFldName) > 0: f.setAttribute(scaleFldName, self.scale) # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(layer) if len(rotFldName) > 0: f.setAttribute(rotFldName, qad_utils.toDegrees(self.rot)) return qad_layer.addFeatureToLayer(self.plugIn, layer, f) def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nIl sistema di riferimento del progetto deve essere un sistema di coordinate proiettate.\n")) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isSymbolLayer(currLayer) == False: errMsg = QadMsg.translate("QAD", "\nIl layer corrente non é di tipo simbolo.") errMsg = errMsg + QadMsg.translate("QAD", "\nUn layer simbolo é un layer vettoriale di tipo punto senza etichetta.\n") self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PUNTO DI INSERIMENTO if self.step == 0: # inizio del comando self.waitForPoint() # si appresta ad attendere un punto self.step = self.step + 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO DI INSERIMENTO elif self.step == 1: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False pt = self.getPointMapTool().point else: # il punto arriva come parametro della funzione pt = msg self.insPt = QgsPoint(pt) self.plugIn.setLastPoint(self.insPt) # se la scala dipende da un campo scaleFldName = qad_layer.get_symbolScaleFieldName(currLayer) if len(scaleFldName) > 0: # si appresta ad attendere la scala self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_INSERT", "Specificare la scala del simbolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.scale)) self.GetDistClass.dist = self.scale self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE | QadInputModeEnum.NOT_ZERO self.GetDistClass.startPt = self.insPt self.step = 2 self.GetDistClass.run(msgMapTool, msg) return False else: # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(currLayer) if len(rotFldName) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_INSERT", "Specificare la rotazione del simbolo <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.addFeature(currLayer) return True #========================================================================= # RISPOSTA ALLA RICHIESTA SCALA (da step = 1) elif self.step == 2: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.scale = self.GetDistClass.dist self.plugIn.setLastScale(self.scale) del self.GetDistClass self.GetDistClass = None # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(currLayer) if len(rotFldName) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_INSERT", "Specificare la rotazione del simbolo <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.addFeature(currLayer) return True else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE (da step = 1 o 2) elif self.step == 3: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.addFeature(currLayer) return True # fine comando else: return True return False
class QadTEXTCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadTEXTCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "TEXT") def getEnglishName(self): return "TEXT" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runTEXTCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/text.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_TEXT", "Inserts a text.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.insPt = None self.hText = self.plugIn.lastHText self.rot = self.plugIn.lastRot self.GetDistClass = None self.GetAngleClass = None self.labelFields = None self.labelFieldNamesNdx = 0 self.labelFieldValues = [] def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass if self.GetAngleClass is not None: del self.GetAngleClass def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE): # quando si éin fase di richiesta distanza (altezza testo) if self.step == 2: return self.GetDistClass.getPointMapTool() # quando si éin fase di richiesta rotazione elif self.step == 3: return self.GetAngleClass.getPointMapTool() else: return QadCommandClass.getPointMapTool(self, drawMode) def addFeature(self, layer): transformedPoint = self.mapToLayerCoordinates(layer, self.insPt) g = QgsGeometry.fromPoint(transformedPoint) f = QgsFeature() f.setGeometry(g) # Add attribute fields to feature. fields = layer.pendingFields() f.setFields(fields) # assegno i valori di default provider = layer.dataProvider() for field in fields.toList(): i = fields.indexFromName(field.name()) f[field.name()] = provider.defaultValue(i) # se l'altezza testo dipende da un solo campo sizeFldNames = qad_label.get_labelSizeFieldNames(layer) if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0: f.setAttribute(sizeFldNames[0], self.hText) # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(layer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: f.setAttribute(rotFldNames[0], qad_utils.toDegrees(self.rot)) # setto i valori degli attributi che compongono l'etichetta i = 0 tot = len(self.labelFields) while i < tot: f.setAttribute(self.labelFields[i].name(), self.labelFieldValues[i]) i = i + 1 return qad_layer.addFeatureToLayer(self.plugIn, layer, f) def initLabelFields(self, layer): labelFieldNames = qad_label.get_labelFieldNames(layer) if len(labelFieldNames) > 0: self.labelFields = QgsFields() for field in layer.dataProvider().fields(): if field.name() in labelFieldNames: self.labelFields.append(QgsField(field.name(), field.type())) #============================================================================ # waitForFieldValue #============================================================================ def waitForFieldValue(self): self.step = 4 if self.labelFields is None: return False if self.labelFieldNamesNdx >= len(self.labelFields): return False field = self.labelFields[self.labelFieldNamesNdx] prompt = QadMsg.translate("Command_TEXT", "Enter the value of attribute \"{0}\": ").format(field.name()) if field.type() == QVariant.Double: # si appresta ad attendere un double o valore nullo self.waitForFloat(prompt, None, QadInputModeEnum.NONE) elif field.type() == QVariant.LongLong: # si appresta ad attendere un long a 64 bit o valore nullo self.waitForLong(prompt, None, QadInputModeEnum.NONE) elif field.type() == QVariant.Int: # si appresta ad attendere un integer o valore nullo self.waitForInt(prompt, None, QadInputModeEnum.NONE) elif field.type() == QVariant.Bool: # si appresta ad attendere un boolean o valore nullo self.waitForBool(prompt, None, QadInputModeEnum.NONE) else: # si appresta ad attendere una stringa o valore nullo self.waitForString(prompt, None, QadInputModeEnum.NONE) return True def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isTextLayer(currLayer) == False: errMsg = QadMsg.translate("QAD", "\nCurrent layer is not a textual layer.") errMsg = errMsg + QadMsg.translate("QAD", "\nA textual layer is a vector punctual layer having a label and the symbol transparency no more than 10%.\n") self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PUNTO DI INSERIMENTO if self.step == 0: # inizio del comando self.waitForPoint() # si appresta ad attendere un punto self.step = self.step + 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO DI INSERIMENTO elif self.step == 1: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False pt = self.getPointMapTool().point else: # il punto arriva come parametro della funzione pt = msg self.insPt = QgsPoint(pt) self.plugIn.setLastPoint(self.insPt) # se l'altezza testo dipende da un solo campo sizeFldNames = qad_label.get_labelSizeFieldNames(currLayer) if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0: # si appresta ad attendere la scala self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text height <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.hText)) self.GetDistClass.dist = self.hText self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE | QadInputModeEnum.NOT_ZERO self.GetDistClass.startPt = self.insPt self.step = 2 self.GetDistClass.run(msgMapTool, msg) return False else: # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ALTEZZA TESTO (da step = 1) elif self.step == 2: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.hText = self.GetDistClass.dist self.plugIn.setLastHText(self.hText) del self.GetDistClass self.GetDistClass = None # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE (da step = 1 o 2) elif self.step == 3: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL VALORE DI UN CAMPO elif self.step == 4: # dopo aver atteso un valore si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica self.waitForFieldValue() return False # il valore arriva come parametro della funzione self.labelFieldValues.append(msg) self.labelFieldNamesNdx = self.labelFieldNamesNdx + 1 if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando return False
def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable( self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isTextLayer(currLayer) == False: errMsg = QadMsg.translate( "QAD", "\nCurrent layer is not a textual layer.") errMsg = errMsg + QadMsg.translate( "QAD", "\nA textual layer is a vector punctual layer having a label and the symbol transparency no more than 10%.\n" ) self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PUNTO DI INSERIMENTO if self.step == 0: # inizio del comando self.waitForPoint() # si appresta ad attendere un punto self.step = self.step + 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO DI INSERIMENTO elif self.step == 1: # 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False pt = self.getPointMapTool().point else: # il punto arriva come parametro della funzione pt = msg self.insPt = QgsPoint(pt) self.plugIn.setLastPoint(self.insPt) # se l'altezza testo dipende da un solo campo sizeFldNames = qad_label.get_labelSizeFieldNames(currLayer) if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0: # si appresta ad attendere la scala self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text height <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.hText)) self.GetDistClass.dist = self.hText self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE | QadInputModeEnum.NOT_ZERO self.GetDistClass.startPt = self.insPt self.step = 2 self.GetDistClass.run(msgMapTool, msg) return False else: # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate( "Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format( str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ALTEZZA TESTO (da step = 1) elif self.step == 2: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.hText = self.GetDistClass.dist self.plugIn.setLastHText(self.hText) del self.GetDistClass self.GetDistClass = None # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames( currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate( "Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format( str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE (da step = 1 o 2) elif self.step == 3: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL VALORE DI UN CAMPO elif self.step == 4: # dopo aver atteso un valore si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica self.waitForFieldValue() return False # il valore arriva come parametro della funzione self.labelFieldValues.append(msg) self.labelFieldNamesNdx = self.labelFieldNamesNdx + 1 if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando return False
class QadMEASURECommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadMEASURECommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "MEASURE") def getEnglishName(self): return "MEASURE" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runMEASURECommand) def getIcon(self): return QIcon(":/plugins/qad/icons/measure.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_MEASURE", "Creates punctual objects at measured intervals along the length or perimeter of an object.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.entSelClass = None self.GetDistClass = None self.objectAlignment = True self.segmentLength = 1 def __del__(self): QadCommandClass.__del__(self) if self.entSelClass is not None: self.entSelClass.entity.deselectOnLayer() del self.entSelClass def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE): if self.step == QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH: # quando si é in fase di richiesta distanza return self.GetDistClass.getPointMapTool() else: return QadCommandClass.getPointMapTool(self, drawMode) #============================================================================ # waitForEntsel #============================================================================ def waitForEntsel(self, msgMapTool, msg): if self.entSelClass is not None: del self.entSelClass self.step = QadMEASURECommandClassStepEnum.ASK_FOR_ENT self.entSelClass = QadEntSelClass(self.plugIn) self.entSelClass.msg = QadMsg.translate("Command_MEASURE", "Select object to measure: ") # scarto la selezione di punti self.entSelClass.checkPointLayer = False self.entSelClass.checkLineLayer = True self.entSelClass.checkPolygonLayer = True self.entSelClass.checkDimLayers = False self.entSelClass.onlyEditableLayers = False self.entSelClass.run(msgMapTool, msg) #============================================================================ # waitForAlignmentObjs #============================================================================ def waitForAlignmentObjs(self): self.step = QadMEASURECommandClassStepEnum.ASK_FOR_ALIGNMENT keyWords = QadMsg.translate("QAD", "Yes") + "/" + QadMsg.translate("QAD", "No") self.defaultValue = QadMsg.translate("QAD", "Yes") prompt = QadMsg.translate("Command_MEASURE", "Align with object ? [{0}] <{1}>: ").format(keyWords, self.defaultValue) englishKeyWords = "Yes" + "/" + "No" keyWords += "_" + englishKeyWords # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) #============================================================================ # waitForSegmentLength #============================================================================ def waitForSegmentLength(self): self.step = QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) self.GetDistClass.msg = QadMsg.translate("Command_MEASURE", "Enter the length of segment: ") self.GetDistClass.run() #============================================================================ # addFeature #============================================================================ def addFeature(self, layer, insPt, rot): transformedPoint = self.mapToLayerCoordinates(layer, insPt) g = QgsGeometry.fromPoint(transformedPoint) f = QgsFeature() f.setGeometry(g) # Add attribute fields to feature. fields = layer.pendingFields() f.setFields(fields) # assegno i valori di default provider = layer.dataProvider() for field in fields.toList(): i = fields.indexFromName(field.name()) f[field.name()] = provider.defaultValue(i) # se la scala dipende da un campo scaleFldName = qad_layer.get_symbolScaleFieldName(layer) if len(scaleFldName) > 0: f.setAttribute(scaleFldName, 1.0) # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(layer) if len(rotFldName) > 0: f.setAttribute(rotFldName, qad_utils.toDegrees(rot)) return qad_layer.addFeatureToLayer(self.plugIn, layer, f) #============================================================================ # doMeasure #============================================================================ def doMeasure(self, dstLayer): f = self.entSelClass.entity.getFeature() if f is None: return layer = self.entSelClass.entity.layer # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(layer, f.geometry()) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(self.entSelClass.point, geom) if dummy[2] is None: return False # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) pathLinearObjectList = qad_utils.QadLinearObjectList() geomType = subGeom.type() pathLinearObjectList.fromPolyline(subGeom.asPolyline()) length = pathLinearObjectList.length() self.plugIn.beginEditCommand("Feature measured", dstLayer) i = 1 distanceFromStart = self.segmentLength while distanceFromStart <= length: pt, rot = pathLinearObjectList.getPointFromStart(distanceFromStart) if self.addFeature(dstLayer, pt, rot if self.objectAlignment else 0) == False: self.plugIn.destroyEditCommand() return False i = i + 1 distanceFromStart = distanceFromStart + self.segmentLength self.plugIn.endEditCommand() return True def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isSymbolLayer(currLayer) == False : errMsg = QadMsg.translate("QAD", "\nCurrent layer is not a symbol layer.") errMsg = errMsg + QadMsg.translate("QAD", "\nA symbol layer is a vector punctual layer without label.\n") self.showErr(errMsg) return True # fine comando if len(QadDimStyles.getDimListByLayer(currLayer)) > 0: errMsg = QadMsg.translate("QAD", "\nThe current layer belongs to a dimension style.\n") self.showErr(errMsg) return True # fine comando if self.step == 0: self.waitForEntsel(msgMapTool, msg) return False # continua #========================================================================= # RISPOSTA ALLA SELEZIONE DI UN'ENTITA' (da step = 0) elif self.step == QadMEASURECommandClassStepEnum.ASK_FOR_ENT: if self.entSelClass.run(msgMapTool, msg) == True: if self.entSelClass.entity.isInitialized(): # se il layer di destinazione è di tipo simbolo if qad_layer.isSymbolLayer(currLayer) == True: # se il simbolo può essere ruotato if len(qad_layer.get_symbolRotationFieldName(currLayer)) >0: self.waitForAlignmentObjs() else: self.waitForSegmentLength() return False else: if self.entSelClass.canceledByUsr == True: # fine comando return True self.showMsg(QadMsg.translate("QAD", "No geometries in this position.")) self.waitForEntsel(msgMapTool, msg) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DI ALLINEARE GLI OGGETTI (da step = ASK_FOR_ENT) elif self.step == QadMEASURECommandClassStepEnum.ASK_FOR_ALIGNMENT: # dopo aver atteso una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse value = self.defaultValue else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: # la parola chiave arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("QAD", "Yes") or value == "Yes": self.objectAlignment = True else: self.objectAlignment = False self.waitForSegmentLength() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA LUNGHEZZA DEL SEGMENTO (da step = ASK_FOR_ALIGNMENT) #========================================================================= elif self.step == QadMEASURECommandClassStepEnum.ASK_SEGMENT_LENGTH: # dopo aver atteso un numero reale si riavvia il comando if self.GetDistClass.run(msgMapTool, msg) == True: self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato da altri maptool if self.GetDistClass.dist is not None: self.segmentLength = self.GetDistClass.dist self.doMeasure(currLayer) del self.GetDistClass return True # fine comando else: return False
class QadLENGTHENCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadLENGTHENCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "LENGTHEN") def getEnglishName(self): return "LENGTHEN" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runLENGTHENCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/lengthen.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_LENGTHEN", "Lengthen an object.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.OpMode = plugIn.lastOpMode_lengthen # "DElta" o "Percent" o "Total" o "DYnamic" self.OpType = None # "length" o "Angle" self.value = None self.startPt = None self.GetDistClass = None self.GetAngleClass = None self.entity = QadEntity() self.linearObjectList = None self.atSubGeom = None self.move_startPt = None self.nOperationsToUndo = 0 def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass if self.GetAngleClass is not None: del self.GetAngleClass def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE): if self.step == 3: # quando si é in fase di richiesta distanza return self.GetDistClass.getPointMapTool() if self.step == 4: # quando si é in fase di richiesta angolo return self.GetAngleClass.getPointMapTool() elif (self.plugIn is not None): if self.PointMapTool is None: self.PointMapTool = Qad_lengthen_maptool(self.plugIn) return self.PointMapTool else: return None def setInfo(self, entity, point): # setta: self.entity, self.linearObjectList, self.atSubGeom e self.move_startPt if self.linearObjectList is not None: del self.linearObjectList self.linearObjectList = None self.entity.set(entity.layer, entity.featureId) transformedPt = self.mapToLayerCoordinates(self.entity.layer, point) f = self.entity.getFeature() geom = self.entity.getGeometry() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) res = False dummy = qad_utils.closestSegmentWithContext(transformedPt, geom) if dummy[2] is None: return False # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, self.atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) self.linearObjectList = qad_utils.QadLinearObjectList() self.linearObjectList.fromPolyline(subGeom.asPolyline()) if qad_utils.getDistance(self.linearObjectList.getStartPt(), transformedPt) <= \ qad_utils.getDistance(self.linearObjectList.getEndPt(), transformedPt): # si allunga dal punto iniziale self.move_startPt = True else: # si allunga dal punto finale self.move_startPt = False return True #============================================================================ # lengthen #============================================================================ def lengthen(self, point): layer = self.entity.layer f = self.entity.getFeature() if f is None: # non c'è più la feature return False geom = self.entity.getGeometry() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) res = False if self.OpMode == "DElta": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) if self.OpType == "length": res = newLinearObjectList.lengthen_delta(self.move_startPt, self.value) elif self.OpType == "Angle": res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, self.value) elif self.OpMode == "Percent": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) value = newLinearObjectList.length() * self.value / 100 value = value - newLinearObjectList.length() res = newLinearObjectList.lengthen_delta(self.move_startPt, value) elif self.OpMode == "Total": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) if self.OpType == "length": value = self.value - newLinearObjectList.length() res = newLinearObjectList.lengthen_delta(self.move_startPt, value) elif self.OpType == "Angle": if newLinearObjectList.qty() == 1: linearObject = newLinearObjectList.getLinearObjectAt(0) if linearObject.isArc() == True: # se è un arco value = self.value - linearObject.getArc().totalAngle() res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, value) elif self.OpMode == "DYnamic": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) transformedPt = self.mapToLayerCoordinates(layer, point) if self.move_startPt: linearObject = newLinearObjectList.getLinearObjectAt(0) else: linearObject = newLinearObjectList.getLinearObjectAt(-1) if linearObject.isSegment(): newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), transformedPt) else: # arco newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \ qad_utils.getAngleBy2Pts(linearObject.getArc().center, transformedPt), \ linearObject.getArc().radius) if newLinearObjectList.qty() > 1 and linearObject.isSegment(): ang = linearObject.getTanDirectionOnStartPt() if self.move_startPt: linearObject.setStartPt(newPt) else: linearObject.setEndPt(newPt) if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \ qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False: res = False else: res = True if res == False: # allungamento impossibile return False pts = newLinearObjectList.asPolyline() updSubGeom = QgsGeometry.fromPolyline(pts) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom) 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 showLength(self, entity, pt): # visualizza la lunghezza dell'entità in unità di mappa geom = entity.getGeometry() if geom is None: errMsg = QadMsg.translate("QAD", "Invalid object.") self.showErr("\n" + errMsg) return None # Trasformo il punto nel sistema di coordinate del layer convPt = self.mapToLayerCoordinates(entity.layer, pt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(pt, geom) if dummy[2] is None: errMsg = QadMsg.translate("QAD", "Invalid object.") self.showErr("\n" + errMsg) return None # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) LinearObjectListToMisure = qad_utils.QadLinearObjectList() pointList = subGeom.asPolyline() LinearObjectListToMisure.fromPolyline(pointList) # la trasformo in unità di mappa LinearObjectListToMisure.transformFromCRSToCRS(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) msg = QadMsg.translate("Command_LENGTHEN", "\nCurrent length: {0}") msg = msg.format(str(LinearObjectListToMisure.length())) arc = QadArc() startEndVertices = arc.fromPolyline(pointList, 0) # se la polilinea è composta solo da un arco if startEndVertices and startEndVertices[0] == 0 and startEndVertices[1] == len(pointList)-1: msg = msg + QadMsg.translate("Command_LENGTHEN", ", included angle: {0}") msg = msg.format(str(qad_utils.toDegrees(arc.totalAngle()))) self.showMsg(msg) def waitForObjectSelToMisure(self): self.step = 1 # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_OBJ_TO_MISURE) if self.plugIn.lastOpMode_lengthen == "DElta": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "DElta") elif self.plugIn.lastOpMode_lengthen == "Percent": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "Percent") elif self.plugIn.lastOpMode_lengthen == "Total": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "Total") elif self.plugIn.lastOpMode_lengthen == "DYnamic": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "DYnamic") else: self.defaultValue = None keyWords = QadMsg.translate("Command_LENGTHEN", "DElta") + "/" + \ QadMsg.translate("Command_LENGTHEN", "Percent") + "/" + \ QadMsg.translate("Command_LENGTHEN", "Total") + "/" + \ QadMsg.translate("Command_LENGTHEN", "DYnamic") if self.defaultValue is None: prompt = QadMsg.translate("Command_LENGTHEN", "Select an object or [{0}] <{1}>: ").format(keyWords, self.defaultValue) else: prompt = QadMsg.translate("Command_LENGTHEN", "Select an object or [{0}] <{1}>: ").format(keyWords, self.defaultValue) englishKeyWords = "DElta" + "/" + "Percent" + "/" + "Total" + "/" + "DYnamic" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) def waitForDelta(self): self.step = 2 self.OpMode = "DElta" self.plugIn.setLastOpMode_lengthen(self.OpMode) # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_DELTA) keyWords = QadMsg.translate("Command_LENGTHEN", "Angle") prompt = QadMsg.translate("Command_LENGTHEN", "Enter delta length or [{0}] <{1}>: ").format(keyWords, str(self.plugIn.lastDelta_lengthen)) englishKeyWords = "Angle" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS | QadInputTypeEnum.FLOAT, \ self.plugIn.lastDelta_lengthen, \ keyWords, QadInputModeEnum.NONE) def waitForDeltaLength(self, msgMapTool, msg): self.step = 3 self.OpType = "length" # si appresta ad attendere una distanza if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter delta length <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.plugIn.lastDelta_lengthen)) self.GetDistClass.startPt = self.startPt self.GetDistClass.dist = self.plugIn.lastDelta_lengthen self.GetDistClass.inputMode = QadInputModeEnum.NONE self.GetDistClass.run(msgMapTool, msg) def waitForDeltaAngle(self, msgMapTool, msg): self.step = 4 self.OpType = "Angle" # si appresta ad attendere l'angolo di rotazione if self.GetAngleClass is not None: del self.GetAngleClass self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter delta angle <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.plugIn.lastDeltaAngle_lengthen))) self.GetAngleClass.angle = self.plugIn.lastDeltaAngle_lengthen self.GetAngleClass.run(msgMapTool, msg) def waitForObjectSel(self): self.step = 5 # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_OBJ_TO_LENGTHEN) self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza o angolo self.getPointMapTool().OpType = self.OpType self.getPointMapTool().value = self.value keyWords = QadMsg.translate("Command_LENGTHEN", "Undo") prompt = QadMsg.translate("Command_LENGTHEN", "Select an object to change or [{0}]: ").format(QadMsg.translate("Command_LENGTHEN", "Undo")) englishKeyWords = "Undo" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NONE) def waitForPercent(self): self.step = 6 self.OpMode = "Percent" self.plugIn.setLastOpMode_lengthen(self.OpMode) # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_PERCENT) prompt = QadMsg.translate("Command_LENGTHEN", "Enter percentage length <{0}>: ") prompt = prompt.format(str(self.plugIn.lastPerc_lengthen)) # si appresta ad attendere un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.FLOAT, \ self.plugIn.lastPerc_lengthen, "", \ QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) def waitForTotal(self): self.step = 7 self.OpMode = "Total" self.plugIn.setLastOpMode_lengthen(self.OpMode) # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_TOTAL) keyWords = QadMsg.translate("Command_LENGTHEN", "Angle") prompt = QadMsg.translate("Command_LENGTHEN", "Specify total length or [{0}] <{1}>: ").format(keyWords, str(self.plugIn.lastTotal_lengthen)) englishKeyWords = "Angle" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS | QadInputTypeEnum.FLOAT, \ self.plugIn.lastTotal_lengthen, \ keyWords, QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) def waitForTotalLength(self, msgMapTool, msg): self.step = 8 self.OpType = "length" # si appresta ad attendere una distanza if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter total length <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.plugIn.lastTotal_lengthen)) self.GetDistClass.startPt = self.startPt self.GetDistClass.dist = self.plugIn.lastTotal_lengthen self.GetDistClass.inputMode = QadInputModeEnum.NONE self.GetDistClass.run(msgMapTool, msg) def waitForTotalAngle(self, msgMapTool, msg): self.step = 9 self.OpType = "Angle" # si appresta ad attendere l'angolo di rotazione if self.GetAngleClass is not None: del self.GetAngleClass self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter total angle <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.plugIn.lastTotalAngle_lengthen))) self.GetAngleClass.angle = self.plugIn.lastTotalAngle_lengthen self.GetAngleClass.run(msgMapTool, msg) def waitForDynamicPt(self): self.step = 10 # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_DYNAMIC_POINT) prompt = QadMsg.translate("Command_LENGTHEN", "Specify new endpoint: ") # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D, \ None, \ "", QadInputModeEnum.NONE) #============================================================================ # run #============================================================================ def run(self, msgMapTool = False, msg = None): 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 # fine comando #========================================================================= # RICHIESTA SELEZIONE OGGETTO if self.step == 0: # inizio del comando # si appresta ad attendere la selezione degli oggetti da estendere/tagliare self.waitForObjectSelToMisure() return False #========================================================================= # RISPOSTA ALLA SELEZIONE OGGETTI DA MISURARE elif self.step == 1: 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 value = self.defaultValue else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "DElta") or value == "DElta": self.waitForDelta() return False elif value == QadMsg.translate("Command_LENGTHEN", "Percent") or value == "Percent": self.waitForPercent() return False elif value == QadMsg.translate("Command_LENGTHEN", "Total") or value == "Total": self.waitForTotal() return False elif value == QadMsg.translate("Command_LENGTHEN", "DYnamic") or value == "DYnamic": self.OpMode = "DYnamic" self.plugIn.setLastOpMode_lengthen(self.OpMode) # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False elif type(value) == QgsPoint: # se é stato selezionato un punto if self.getPointMapTool().entity.isInitialized(): self.showLength(self.getPointMapTool().entity, value) else: # cerco se ci sono entità nel punto indicato considerando # solo layer di tipo lineari che non appartengano a quote o di tipo poligono layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon: if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: feature = result[0] layer = result[1] self.showLength(QadEntity().set(layer, feature.id()), value) else: return True # fine comando # si appresta ad attendere la selezione degli oggetti da misurare self.waitForObjectSelToMisure() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL DELTA (da step = 1) elif self.step == 2: # dopo aver atteso un punto o un numero reale 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 value = self.plugIn.lastDelta_lengthen # opzione di default "spostamento" else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "Angle") or value == "Angle": self.waitForDeltaAngle(msgMapTool, msg) elif type(value) == QgsPoint: # se é stato inserito un punto self.startPt = value self.waitForDeltaLength(msgMapTool, msg) elif type(value) == float: # se é stato inserito il delta self.plugIn.setLastDelta_lengthen(value) self.OpType = "length" self.value = value # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA LUNGHEZZA DEL DELTA (da step = 2) elif self.step == 3: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.plugIn.setLastDelta_lengthen(self.GetDistClass.dist) self.value = self.GetDistClass.dist # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() #========================================================================= # RISPOSTA ALLA RICHIESTA DELL'ANGOLO DEL DELTA (da step = 2) elif self.step == 4: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.plugIn.setLastDeltaAngle_lengthen(self.GetAngleClass.angle) self.value = self.GetAngleClass.angle # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() #========================================================================= # RISPOSTA ALLA SELEZIONE OGGETTI DA ALLUNGARE elif self.step == 5: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "Undo") or value == "Undo": if self.nOperationsToUndo > 0: self.nOperationsToUndo = self.nOperationsToUndo - 1 self.plugIn.undoEditCommand() else: self.showMsg(QadMsg.translate("QAD", "\nThe command has been canceled.")) elif type(value) == QgsPoint: # se é stato selezionato un punto if self.getPointMapTool().entity.isInitialized(): self.setInfo(self.getPointMapTool().entity, value) if self.OpMode != "DYnamic": self.lengthen(value) else: self.waitForDynamicPt() return False else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if layer.geometryType() == QGis.Line and layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: feature = result[0] layer = result[1] self.setInfo(QadEntity().set(layer, feature.id()), value) if self.OpMode != "DYnamic": self.lengthen(value) else: self.waitForDynamicPt() return False else: return True # fine comando # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA PERCENTUALE (da step = 1) elif self.step == 6: # dopo aver atteso un numero reale 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 value = self.plugIn.lastPerc_lengthen else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: return False else: # il punto arriva come parametro della funzione value = msg if type(value) == float: # é stata inserita la percentuale self.plugIn.setLastPerc_lengthen(value) self.value = value # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL TOTALE (da step = 1) elif self.step == 7: # dopo aver atteso un punto o un numero reale 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 value = self.plugIn.lastTotal_lengthen else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "Angle") or value == "Angle": self.waitForTotalAngle(msgMapTool, msg) elif type(value) == QgsPoint: # se é stato inserito un punto self.startPt = value self.waitForTotalLength(msgMapTool, msg) elif type(value) == float: # se é stato inserito il delta self.plugIn.setLastTotal_lengthen(value) self.OpType = "length" self.value = value # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA LUNGHEZZA DEL TOTALE (da step = 7) elif self.step == 8: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.plugIn.setLastTotal_lengthen(self.GetDistClass.dist) self.value = self.GetDistClass.dist # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELL'ANGOLO DEL DELTA (da step = 7) elif self.step == 9: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.plugIn.setLastTotalAngle_lengthen(self.GetAngleClass.angle) self.value = self.GetAngleClass.angle # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA NUOVA ESTREMITA' IN MODO DINAMICO (da step = 5) elif self.step == 10: # dopo aver atteso un punto 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 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: # se é stato inserito un punto self.lengthen(value) # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False
class QadINSERTCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadINSERTCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "INSERT") def getEnglishName(self): return "INSERT" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runINSERTCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/insert.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_INSERT", "Insert a symbol.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.insPt = None self.scale = self.plugIn.lastScale self.rot = self.plugIn.lastRot self.GetDistClass = None self.GetAngleClass = None def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass if self.GetAngleClass is not None: del self.GetAngleClass def getPointMapTool(self, drawMode=QadGetPointDrawModeEnum.NONE): # quando si é in fase di richiesta distanza (scala) if self.step == 2: return self.GetDistClass.getPointMapTool() # quando si é in fase di richiesta rotazione elif self.step == 3: return self.GetAngleClass.getPointMapTool() else: return QadCommandClass.getPointMapTool(self, drawMode) def getCurrentContextualMenu(self): # quando si é in fase di richiesta distanza (scala) if self.step == 2: return self.GetDistClass.getCurrentContextualMenu() # quando si é in fase di richiesta rotazione elif self.step == 3: return self.GetAngleClass.getCurrentContextualMenu() else: return self.contextualMenu def addFeature(self, layer): transformedPoint = self.mapToLayerCoordinates(layer, self.insPt) g = QgsGeometry.fromPoint(transformedPoint) f = QgsFeature() f.setGeometry(g) # Add attribute fields to feature. fields = layer.pendingFields() f.setFields(fields) # assegno i valori di default provider = layer.dataProvider() for field in fields.toList(): i = fields.indexFromName(field.name()) f[field.name()] = provider.defaultValue(i) # se la scala dipende da un campo scaleFldName = qad_layer.get_symbolScaleFieldName(layer) if len(scaleFldName) > 0: f.setAttribute(scaleFldName, self.scale) # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(layer) if len(rotFldName) > 0: f.setAttribute(rotFldName, qad_utils.toDegrees(self.rot)) return qad_layer.addFeatureToLayer(self.plugIn, layer, f) def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable( self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isSymbolLayer(currLayer) == False: errMsg = QadMsg.translate( "QAD", "\nCurrent layer is not a symbol layer.") errMsg = errMsg + QadMsg.translate( "QAD", "\nA symbol layer is a vector punctual layer without label.\n") self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PUNTO DI INSERIMENTO if self.step == 0: # inizio del comando self.waitForPoint() # si appresta ad attendere un punto self.step = self.step + 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO DI INSERIMENTO elif self.step == 1: # 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False pt = self.getPointMapTool().point else: # il punto arriva come parametro della funzione pt = msg self.insPt = QgsPoint(pt) self.plugIn.setLastPoint(self.insPt) # se la scala dipende da un campo scaleFldName = qad_layer.get_symbolScaleFieldName(currLayer) if len(scaleFldName) > 0: # si appresta ad attendere la scala self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_INSERT", "Specify the symbol scale <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.scale)) self.GetDistClass.dist = self.scale self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE | QadInputModeEnum.NOT_ZERO self.GetDistClass.startPt = self.insPt self.step = 2 self.GetDistClass.run(msgMapTool, msg) return False else: # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(currLayer) if len(rotFldName) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate( "Command_INSERT", "Specify the symbol rotation <{0}>: ") self.GetAngleClass.msg = prompt.format( str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.addFeature(currLayer) return True #========================================================================= # RISPOSTA ALLA RICHIESTA SCALA (da step = 1) elif self.step == 2: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.scale = self.GetDistClass.dist self.plugIn.setLastScale(self.scale) del self.GetDistClass self.GetDistClass = None # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName( currLayer) if len(rotFldName) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate( "Command_INSERT", "Specify the symbol rotation <{0}>: ") self.GetAngleClass.msg = prompt.format( str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.addFeature(currLayer) return True else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE (da step = 1 o 2) elif self.step == 3: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.addFeature(currLayer) return True # fine comando else: return True return False
def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nIl sistema di riferimento del progetto deve essere un sistema di coordinate proiettate.\n")) return True # fine comando currLayer = None if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer # il layer corrente deve essere editabile e di tipo linea o poligono currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, [QGis.Line, QGis.Polygon]) if currLayer is None: self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PRIMO PUNTO if self.step == 0: # inizio del comando self.WaitForFirstCorner() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DEL RETTANGOLO (da step = 0) elif self.step == 1: # 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_RECTANGLE", "La finestra non é stata specificata correttamente.")) self.WaitForFirstCorner() 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) == unicode: if value == QadMsg.translate("Command_RECTANGLE", "Cima") or value == "Chamfer": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specificare prima distanza di cimatura del rettangolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue1)) self.GetDistClass.dist = self.gapValue1 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 4 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "Raccordo") or value == "Fillet": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specificare raggio di raccordo del rettangolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue1)) self.GetDistClass.dist = self.gapValue1 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 3 self.GetDistClass.run(msgMapTool, msg) elif type(value) == QgsPoint: self.firstCorner = value self.getPointMapTool().firstCorner = self.firstCorner self.WaitForSecondCorner(currLayer) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DEL RETTANGOLO (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_RECTANGLE", "La finestra non é stata specificata correttamente.")) self.WaitForSecondCorner(currLayer) 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) == unicode: if value == QadMsg.translate("Command_RECTANGLE", "Area") or value == "Area": msg = QadMsg.translate("Command_RECTANGLE", "Digitare l'area del rettangolo in unità correnti <{0}>: ") # si appresta ad attendere un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(msg.format(str(self.area)), QadInputTypeEnum.FLOAT, \ self.area, "", \ QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER) self.step = 6 elif value == QadMsg.translate("Command_RECTANGLE", "Quote") or value == "Dimensions": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specificare lunghezza del rettangolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 10 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "Rotazione") or value == "Rotation": keyWords = QadMsg.translate("Command_RECTANGLE", "SCegli punti") self.defaultValue = self.rot prompt = QadMsg.translate("Command_RECTANGLE", "Specificare l'angolo di rotazione o [{0}] <{1}>: ").format(keyWords, str(qad_utils.toDegrees(self.rot))) englishKeyWords = "Points" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori non nulli self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \ self.rot, keyWords) self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER) self.step = 12 elif type(value) == QgsPoint: self.vertices.extend(qad_utils.getRectByCorners(self.firstCorner, value, self.rot, \ self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA RAGGIO DI CURVATURA (da step = 1) elif self.step == 3: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue1 = self.GetDistClass.dist if self.gapValue1 == 0: self.gapType = 0 # 0 = Angoli retti else: self.gapType = 1 # 1 = Raccorda i segmenti self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMA DISTANZA DI CIMATURA (da step = 1) elif self.step == 4: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue1 = self.GetDistClass.dist if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specificare seconda distanza di cimatura del rettangolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue2)) self.GetDistClass.dist = self.gapValue2 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 5 self.GetDistClass.run(msgMapTool, msg) else: self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDA DISTANZA DI CIMATURA (da step = 1) elif self.step == 5: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue2 = self.GetDistClass.dist if self.gapValue1 == 0 or self.gapValue2 == 0: self.gapType = 0 # 0 = Angoli retti else: self.gapType = 2 # 2 = Cima i segmenti self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA AREA RETTANGOLO (da step = 2) elif self.step == 6: # dopo aver atteso un punto si riavvia il comando keyWords = QadMsg.translate("Command_RECTANGLE", "Lunghezza") + "/" + \ QadMsg.translate("Command_RECTANGLE", "lArghezza") englishKeyWords = "Length" + "/" + "Width" 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.defaultValue = QadMsg.translate("Command_RECTANGLE", "Lunghezza") prompt = QadMsg.translate("Command_RECTANGLE", "Calcolare le quote rettangolo in base alla [{0}] <{1}>: ").format(keyWords, self.defaultValue) keyWords += "_" + englishKeyWords # si appresta ad attendere una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) self.step = 7 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) == float: # é stata inserita l'area self.area = value self.defaultValue = QadMsg.translate("Command_RECTANGLE", "Lunghezza") prompt = QadMsg.translate("Command_RECTANGLE", "Calcolare le quote rettangolo in base alla [{0}] <{1}>: ").format(keyWords, self.defaultValue) keyWords += "_" + englishKeyWords # si appresta ad attendere una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) self.step = 7 return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA MODALITA' (LUNGHEZZA / LARGHEZZA) DATA L'AREA (da step = 6) elif self.step == 7: # dopo aver atteso un punto o un numero reale 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 value = self.defaultValue return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: return False else: # il punto arriva come parametro della funzione value = msg if value == QadMsg.translate("Command_RECTANGLE", "Lunghezza") or value == "Length": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Digitare la lunghezza rettangolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 8 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "lArghezza") or value == "Width": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Digitare la larghezza rettangolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 9 self.GetDistClass.run(msgMapTool, msg) return False #========================================================================= # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO DATA L'AREA (da step = 7) elif self.step == 8: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByAreaAndLength(self.firstCorner, self.area, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO DATA L'AREA (da step = 7) elif self.step == 9: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByAreaAndWidth(self.firstCorner, self.area, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO (da step = 2) elif self.step == 10: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.dim1 = self.GetDistClass.dist if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Digitare la larghezza rettangolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 11 self.GetDistClass.run(msgMapTool, msg) return False #========================================================================= # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO (da step = 10) elif self.step == 11: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByCornerAndDims(self.firstCorner, self.dim1, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 2) elif self.step == 12: # 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 value = self.defaultValue else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_RECTANGLE", "SCegli punti") or value == "Points": # si appresta ad attendere l'angolo di rotazione if self.GetAngleClass is not None: del self.GetAngleClass self.GetAngleClass = QadGetAngleClass(self.plugIn) self.GetAngleClass.msg = QadMsg.translate("Command_RECTANGLE", "Specificare primo punto: ") self.GetAngleClass.angle = self.rot self.step = 13 self.GetAngleClass.run(msgMapTool, msg) elif type(value) == QgsPoint: self.rot = qad_utils.getAngleBy2Pts(self.firstCorner, value) self.WaitForSecondCorner(currLayer) elif type(value) == float: self.rot = qad_utils.toRadians(value) self.WaitForSecondCorner(currLayer) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 12) elif self.step == 13: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.WaitForSecondCorner(currLayer) self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di rotazione
class QadLENGTHENCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadLENGTHENCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "LENGTHEN") def getEnglishName(self): return "LENGTHEN" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runLENGTHENCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/lengthen.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_LENGTHEN", "Lengthen an object.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.OpMode = plugIn.lastOpMode_lengthen # "DElta" o "Percent" o "Total" o "DYnamic" self.OpType = None # "length" o "Angle" self.value = None self.startPt = None self.GetDistClass = None self.GetAngleClass = None self.entity = QadEntity() self.linearObjectList = None self.atSubGeom = None self.move_startPt = None self.nOperationsToUndo = 0 def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass if self.GetAngleClass is not None: del self.GetAngleClass def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE): if self.step == 3: # quando si é in fase di richiesta distanza return self.GetDistClass.getPointMapTool() if self.step == 4: # quando si é in fase di richiesta angolo return self.GetAngleClass.getPointMapTool() elif (self.plugIn is not None): if self.PointMapTool is None: self.PointMapTool = Qad_lengthen_maptool(self.plugIn) return self.PointMapTool else: return None def setInfo(self, entity, point): # setta: self.entity, self.linearObjectList, self.atSubGeom e self.move_startPt if self.linearObjectList is not None: del self.linearObjectList self.linearObjectList = None self.entity.set(entity.layer, entity.featureId) transformedPt = self.mapToLayerCoordinates(self.entity.layer, point) f = self.entity.getFeature() geom = self.entity.getGeometry() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) res = False dummy = qad_utils.closestSegmentWithContext(transformedPt, geom) if dummy[2] is None: return False # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, self.atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) self.linearObjectList = qad_utils.QadLinearObjectList() self.linearObjectList.fromPolyline(subGeom.asPolyline()) if qad_utils.getDistance(self.linearObjectList.getStartPt(), transformedPt) <= \ qad_utils.getDistance(self.linearObjectList.getEndPt(), transformedPt): # si allunga dal punto iniziale self.move_startPt = True else: # si allunga dal punto finale self.move_startPt = False return True #============================================================================ # lengthen #============================================================================ def lengthen(self, point): layer = self.entity.layer f = self.entity.getFeature() if f is None: # non c'è più la feature return False geom = self.entity.getGeometry() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) res = False if self.OpMode == "DElta": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) if self.OpType == "length": res = newLinearObjectList.lengthen_delta(self.move_startPt, self.value) elif self.OpType == "Angle": res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, self.value) elif self.OpMode == "Percent": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) value = newLinearObjectList.length() * self.value / 100 value = value - newLinearObjectList.length() res = newLinearObjectList.lengthen_delta(self.move_startPt, value) elif self.OpMode == "Total": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) if self.OpType == "length": value = self.value - newLinearObjectList.length() res = newLinearObjectList.lengthen_delta(self.move_startPt, value) elif self.OpType == "Angle": if newLinearObjectList.qty() == 1: linearObject = newLinearObjectList.getLinearObjectAt(0) if linearObject.isArc() == True: # se è un arco value = self.value - linearObject.getArc().totalAngle() res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, value) elif self.OpMode == "DYnamic": newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList) transformedPt = self.mapToLayerCoordinates(layer, point) if self.move_startPt: linearObject = newLinearObjectList.getLinearObjectAt(0) else: linearObject = newLinearObjectList.getLinearObjectAt(-1) if linearObject.isSegment(): newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), transformedPt) else: # arco newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \ qad_utils.getAngleBy2Pts(linearObject.getArc().center, transformedPt), \ linearObject.getArc().radius) if newLinearObjectList.qty() > 1 and linearObject.isSegment(): ang = linearObject.getTanDirectionOnStartPt() if self.move_startPt: linearObject.setStartPt(newPt) else: linearObject.setEndPt(newPt) if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \ qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False: res = False else: res = True if res == False: # allungamento impossibile return False pts = newLinearObjectList.asPolyline() updSubGeom = QgsGeometry.fromPolyline(pts) updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom) 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 showLength(self, entity, pt): # visualizza la lunghezza dell'entità in unità di mappa geom = entity.getGeometry() if geom is None: self.showErr(QadMsg.translate("QAD", "\nInvalid object.")) return None # Trasformo il punto nel sistema di coordinate del layer convPt = self.mapToLayerCoordinates(entity.layer, pt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(pt, geom) if dummy[2] is None: self.showErr(QadMsg.translate("QAD", "\nInvalid object.")) return None # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) LinearObjectListToMisure = qad_utils.QadLinearObjectList() pointList = subGeom.asPolyline() LinearObjectListToMisure.fromPolyline(pointList) # la trasformo in unità di mappa LinearObjectListToMisure.transformFromCRSToCRS(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) msg = QadMsg.translate("Command_LENGTHEN", "\nCurrent length: {0}") msg = msg.format(str(LinearObjectListToMisure.length())) arc = QadArc() startEndVertices = arc.fromPolyline(pointList, 0) # se la polilinea è composta solo da un arco if startEndVertices and startEndVertices[0] == 0 and startEndVertices[1] == len(pointList)-1: msg = msg + QadMsg.translate("Command_LENGTHEN", ", included angle: {0}") msg = msg.format(str(qad_utils.toDegrees(arc.totalAngle()))) self.showMsg(msg) def waitForObjectSelToMisure(self): self.step = 1 # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_OBJ_TO_MISURE) if self.plugIn.lastOpMode_lengthen == "DElta": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "DElta") elif self.plugIn.lastOpMode_lengthen == "Percent": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "Percent") elif self.plugIn.lastOpMode_lengthen == "Total": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "Total") elif self.plugIn.lastOpMode_lengthen == "DYnamic": self.defaultValue = QadMsg.translate("Command_LENGTHEN", "DYnamic") else: self.defaultValue = None keyWords = QadMsg.translate("Command_LENGTHEN", "DElta") + "/" + \ QadMsg.translate("Command_LENGTHEN", "Percent") + "/" + \ QadMsg.translate("Command_LENGTHEN", "Total") + "/" + \ QadMsg.translate("Command_LENGTHEN", "DYnamic") if self.defaultValue is None: prompt = QadMsg.translate("Command_LENGTHEN", "Select an object or [{0}] <{1}>: ").format(keyWords, self.defaultValue) else: prompt = QadMsg.translate("Command_LENGTHEN", "Select an object or [{0}] <{1}>: ").format(keyWords, self.defaultValue) englishKeyWords = "DElta" + "/" + "Percent" + "/" + "Total" + "/" + "DYnamic" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) def waitForDelta(self): self.step = 2 self.OpMode = "DElta" self.plugIn.setLastOpMode_lengthen(self.OpMode) # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_DELTA) keyWords = QadMsg.translate("Command_LENGTHEN", "Angle") prompt = QadMsg.translate("Command_LENGTHEN", "Enter delta length or [{0}] <{1}>: ").format(keyWords, str(self.plugIn.lastDelta_lengthen)) englishKeyWords = "Angle" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS | QadInputTypeEnum.FLOAT, \ self.plugIn.lastDelta_lengthen, \ keyWords, QadInputModeEnum.NONE) def waitForDeltaLength(self, msgMapTool, msg): self.step = 3 self.OpType = "length" # si appresta ad attendere una distanza if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter delta length <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.plugIn.lastDelta_lengthen)) self.GetDistClass.startPt = self.startPt self.GetDistClass.dist = self.plugIn.lastDelta_lengthen self.GetDistClass.inputMode = QadInputModeEnum.NONE self.GetDistClass.run(msgMapTool, msg) def waitForDeltaAngle(self, msgMapTool, msg): self.step = 4 self.OpType = "Angle" # si appresta ad attendere l'angolo di rotazione if self.GetAngleClass is not None: del self.GetAngleClass self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter delta angle <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.plugIn.lastDeltaAngle_lengthen))) self.GetAngleClass.angle = self.plugIn.lastDeltaAngle_lengthen self.GetAngleClass.run(msgMapTool, msg) def waitForObjectSel(self): self.step = 5 # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_OBJ_TO_LENGTHEN) self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza o angolo self.getPointMapTool().OpType = self.OpType self.getPointMapTool().value = self.value keyWords = QadMsg.translate("Command_LENGTHEN", "Undo") prompt = QadMsg.translate("Command_LENGTHEN", "Select an object to change or [{0}]: ").format(QadMsg.translate("Command_LENGTHEN", "Undo")) englishKeyWords = "Undo" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NONE) def waitForPercent(self): self.step = 6 self.OpMode = "Percent" self.plugIn.setLastOpMode_lengthen(self.OpMode) # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_PERCENT) prompt = QadMsg.translate("Command_LENGTHEN", "Enter percentage length <{0}>: ") prompt = prompt.format(str(self.plugIn.lastPerc_lengthen)) # si appresta ad attendere un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.FLOAT, \ self.plugIn.lastPerc_lengthen, "", \ QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) def waitForTotal(self): self.step = 7 self.OpMode = "Total" self.plugIn.setLastOpMode_lengthen(self.OpMode) # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_TOTAL) keyWords = QadMsg.translate("Command_LENGTHEN", "Angle") prompt = QadMsg.translate("Command_LENGTHEN", "Specify total length or [{0}] <{1}>: ").format(keyWords, str(self.plugIn.lastTotal_lengthen)) englishKeyWords = "Angle" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS | QadInputTypeEnum.FLOAT, \ self.plugIn.lastTotal_lengthen, \ keyWords, QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) def waitForTotalLength(self, msgMapTool, msg): self.step = 8 self.OpType = "length" # si appresta ad attendere una distanza if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter total length <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.plugIn.lastTotal_lengthen)) self.GetDistClass.startPt = self.startPt self.GetDistClass.dist = self.plugIn.lastTotal_lengthen self.GetDistClass.inputMode = QadInputModeEnum.NONE self.GetDistClass.run(msgMapTool, msg) def waitForTotalAngle(self, msgMapTool, msg): self.step = 9 self.OpType = "Angle" # si appresta ad attendere l'angolo di rotazione if self.GetAngleClass is not None: del self.GetAngleClass self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_LENGTHEN", "Enter total angle <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.plugIn.lastTotalAngle_lengthen))) self.GetAngleClass.angle = self.plugIn.lastTotalAngle_lengthen self.GetAngleClass.run(msgMapTool, msg) def waitForDynamicPt(self): self.step = 10 # imposto il map tool self.getPointMapTool().setMode(Qad_lengthen_maptool_ModeEnum.ASK_FOR_DYNAMIC_POINT) prompt = QadMsg.translate("Command_LENGTHEN", "Specify new endpoint: ") # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D, \ None, \ "", QadInputModeEnum.NONE) #============================================================================ # run #============================================================================ def run(self, msgMapTool = False, msg = None): 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 # fine comando #========================================================================= # RICHIESTA SELEZIONE OGGETTO if self.step == 0: # inizio del comando # si appresta ad attendere la selezione degli oggetti da estendere/tagliare self.waitForObjectSelToMisure() return False #========================================================================= # RISPOSTA ALLA SELEZIONE OGGETTI DA MISURARE elif self.step == 1: 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 value = self.defaultValue else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "DElta") or value == "DElta": self.waitForDelta() return False elif value == QadMsg.translate("Command_LENGTHEN", "Percent") or value == "Percent": self.waitForPercent() return False elif value == QadMsg.translate("Command_LENGTHEN", "Total") or value == "Total": self.waitForTotal() return False elif value == QadMsg.translate("Command_LENGTHEN", "DYnamic") or value == "DYnamic": self.OpMode = "DYnamic" self.plugIn.setLastOpMode_lengthen(self.OpMode) # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False elif type(value) == QgsPoint: # se é stato selezionato un punto if self.getPointMapTool().entity.isInitialized(): self.showLength(self.getPointMapTool().entity, value) else: # cerco se ci sono entità nel punto indicato considerando # solo layer di tipo lineari che non appartengano a quote o di tipo poligono layerList = [] for layer in self.plugIn.canvas.layers(): if layer.type() == QgsMapLayer.VectorLayer and \ layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon: if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), self.getPointMapTool(), \ layerList) if result is not None: feature = result[0] layer = result[1] self.showLength(QadEntity().set(layer, feature.id()), value) else: return True # fine comando # si appresta ad attendere la selezione degli oggetti da misurare self.waitForObjectSelToMisure() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL DELTA (da step = 1) elif self.step == 2: # dopo aver atteso un punto o un numero reale 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 value = self.plugIn.lastDelta_lengthen # opzione di default "spostamento" else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "Angle") or value == "Angle": self.waitForDeltaAngle(msgMapTool, msg) elif type(value) == QgsPoint: # se é stato inserito un punto self.startPt = value self.waitForDeltaLength(msgMapTool, msg) elif type(value) == float: # se é stato inserito il delta self.plugIn.setLastDelta_lengthen(value) self.OpType = "length" self.value = value # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA LUNGHEZZA DEL DELTA (da step = 2) elif self.step == 3: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.plugIn.setLastDelta_lengthen(self.GetDistClass.dist) self.value = self.GetDistClass.dist # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() #========================================================================= # RISPOSTA ALLA RICHIESTA DELL'ANGOLO DEL DELTA (da step = 2) elif self.step == 4: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.plugIn.setLastDeltaAngle_lengthen(self.GetAngleClass.angle) self.value = self.GetAngleClass.angle # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() #========================================================================= # RISPOSTA ALLA SELEZIONE OGGETTI DA ALLUNGARE elif self.step == 5: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "Undo") or value == "Undo": if self.nOperationsToUndo > 0: self.nOperationsToUndo = self.nOperationsToUndo - 1 self.plugIn.undoEditCommand() else: self.showMsg(QadMsg.translate("QAD", "\nThe command has been canceled.")) elif type(value) == QgsPoint: # se é stato selezionato un punto if self.getPointMapTool().entity.isInitialized(): self.setInfo(self.getPointMapTool().entity, value) if self.OpMode != "DYnamic": self.lengthen(value) else: self.waitForDynamicPt() return False else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari editabili che non appartengano a quote layerList = [] for layer in self.plugIn.canvas.layers(): if layer.type() == QgsMapLayer.VectorLayer and layer.geometryType() == QGis.Line and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), self.getPointMapTool(), \ layerList) if result is not None: feature = result[0] layer = result[1] self.setInfo(QadEntity().set(layer, feature.id()), value) if self.OpMode != "DYnamic": self.lengthen(value) else: self.waitForDynamicPt() return False else: return True # fine comando # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA PERCENTUALE (da step = 1) elif self.step == 6: # dopo aver atteso un numero reale 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 value = self.plugIn.lastPerc_lengthen else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: return False else: # il punto arriva come parametro della funzione value = msg if type(value) == float: # é stata inserita la percentuale self.plugIn.setLastPerc_lengthen(value) self.value = value # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL TOTALE (da step = 1) elif self.step == 7: # dopo aver atteso un punto o un numero reale 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 value = self.plugIn.lastTotal_lengthen else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_LENGTHEN", "Angle") or value == "Angle": self.waitForTotalAngle(msgMapTool, msg) elif type(value) == QgsPoint: # se é stato inserito un punto self.startPt = value self.waitForTotalLength(msgMapTool, msg) elif type(value) == float: # se é stato inserito il delta self.plugIn.setLastTotal_lengthen(value) self.OpType = "length" self.value = value # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA LUNGHEZZA DEL TOTALE (da step = 7) elif self.step == 8: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.plugIn.setLastTotal_lengthen(self.GetDistClass.dist) self.value = self.GetDistClass.dist # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELL'ANGOLO DEL DELTA (da step = 7) elif self.step == 9: # dopo aver atteso un punto o un numero reale si riavvia il comando if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.plugIn.setLastTotalAngle_lengthen(self.GetAngleClass.angle) self.value = self.GetAngleClass.angle # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA NUOVA ESTREMITA' IN MODO DINAMICO (da step = 5) elif self.step == 10: # dopo aver atteso un punto 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 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: # se é stato inserito un punto self.lengthen(value) # si appresta ad attendere la selezione degli oggetti da allungare self.waitForObjectSel() return False
def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isTextLayer(currLayer) == False: errMsg = QadMsg.translate("QAD", "\nCurrent layer is not a textual layer.") errMsg = errMsg + QadMsg.translate("QAD", "\nA textual layer is a vector punctual layer having a label and the symbol transparency no more than 10%.\n") self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PUNTO DI INSERIMENTO if self.step == 0: # inizio del comando self.waitForPoint() # si appresta ad attendere un punto self.step = self.step + 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO DI INSERIMENTO elif self.step == 1: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False pt = self.getPointMapTool().point else: # il punto arriva come parametro della funzione pt = msg self.insPt = QgsPoint(pt) self.plugIn.setLastPoint(self.insPt) # se l'altezza testo dipende da un solo campo sizeFldNames = qad_label.get_labelSizeFieldNames(currLayer) if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0: # si appresta ad attendere la scala self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text height <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.hText)) self.GetDistClass.dist = self.hText self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE | QadInputModeEnum.NOT_ZERO self.GetDistClass.startPt = self.insPt self.step = 2 self.GetDistClass.run(msgMapTool, msg) return False else: # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ALTEZZA TESTO (da step = 1) elif self.step == 2: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.hText = self.GetDistClass.dist self.plugIn.setLastHText(self.hText) del self.GetDistClass self.GetDistClass = None # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE (da step = 1 o 2) elif self.step == 3: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL VALORE DI UN CAMPO elif self.step == 4: # dopo aver atteso un valore si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica self.waitForFieldValue() return False # il valore arriva come parametro della funzione self.labelFieldValues.append(msg) self.labelFieldNamesNdx = self.labelFieldNamesNdx + 1 if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando return False
class QadTEXTCommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadTEXTCommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "TEXT") def getEnglishName(self): return "TEXT" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runTEXTCommand) def getIcon(self): return QIcon(":/plugins/qad/icons/text.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_TEXT", "Inserts a text.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) self.insPt = None self.hText = self.plugIn.lastHText self.rot = self.plugIn.lastRot self.GetDistClass = None self.GetAngleClass = None self.labelFields = None self.labelFieldNamesNdx = 0 self.labelFieldValues = [] def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass if self.GetAngleClass is not None: del self.GetAngleClass def getPointMapTool(self, drawMode=QadGetPointDrawModeEnum.NONE): # quando si éin fase di richiesta distanza (altezza testo) if self.step == 2: return self.GetDistClass.getPointMapTool() # quando si éin fase di richiesta rotazione elif self.step == 3: return self.GetAngleClass.getPointMapTool() else: return QadCommandClass.getPointMapTool(self, drawMode) def getCurrentContextualMenu(self): # quando si éin fase di richiesta distanza (altezza testo) if self.step == 2: return self.GetDistClass.getCurrentContextualMenu() # quando si éin fase di richiesta rotazione elif self.step == 3: return self.GetAngleClass.getCurrentContextualMenu() else: return self.contextualMenu def addFeature(self, layer): transformedPoint = self.mapToLayerCoordinates(layer, self.insPt) g = QgsGeometry.fromPoint(transformedPoint) f = QgsFeature() f.setGeometry(g) # Add attribute fields to feature. fields = layer.pendingFields() f.setFields(fields) # assegno i valori di default provider = layer.dataProvider() for field in fields.toList(): i = fields.indexFromName(field.name()) f[field.name()] = provider.defaultValue(i) # se l'altezza testo dipende da un solo campo sizeFldNames = qad_label.get_labelSizeFieldNames(layer) if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0: f.setAttribute(sizeFldNames[0], self.hText) # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(layer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: f.setAttribute(rotFldNames[0], qad_utils.toDegrees(self.rot)) # setto i valori degli attributi che compongono l'etichetta i = 0 tot = len(self.labelFields) while i < tot: f.setAttribute(self.labelFields[i].name(), self.labelFieldValues[i]) i = i + 1 return qad_layer.addFeatureToLayer(self.plugIn, layer, f) def initLabelFields(self, layer): labelFieldNames = qad_label.get_labelFieldNames(layer) if len(labelFieldNames) > 0: self.labelFields = QgsFields() for field in layer.dataProvider().fields(): if field.name() in labelFieldNames: self.labelFields.append( QgsField(field.name(), field.type())) #============================================================================ # waitForFieldValue #============================================================================ def waitForFieldValue(self): self.step = 4 if self.labelFields is None: return False if self.labelFieldNamesNdx >= len(self.labelFields): return False field = self.labelFields[self.labelFieldNamesNdx] prompt = QadMsg.translate( "Command_TEXT", "Enter the value of attribute \"{0}\": ").format(field.name()) if field.type( ) == QVariant.Double: # si appresta ad attendere un double o valore nullo self.waitForFloat(prompt, None, QadInputModeEnum.NONE) elif field.type( ) == QVariant.LongLong: # si appresta ad attendere un long a 64 bit o valore nullo self.waitForLong(prompt, None, QadInputModeEnum.NONE) elif field.type( ) == QVariant.Int: # si appresta ad attendere un integer o valore nullo self.waitForInt(prompt, None, QadInputModeEnum.NONE) elif field.type( ) == QVariant.Bool: # si appresta ad attendere un boolean o valore nullo self.waitForBool(prompt, None, QadInputModeEnum.NONE) else: # si appresta ad attendere una stringa o valore nullo self.waitForString(prompt, None, QadInputModeEnum.NONE) return True def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable( self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isTextLayer(currLayer) == False: errMsg = QadMsg.translate( "QAD", "\nCurrent layer is not a textual layer.") errMsg = errMsg + QadMsg.translate( "QAD", "\nA textual layer is a vector punctual layer having a label and the symbol transparency no more than 10%.\n" ) self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PUNTO DI INSERIMENTO if self.step == 0: # inizio del comando self.waitForPoint() # si appresta ad attendere un punto self.step = self.step + 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO DI INSERIMENTO elif self.step == 1: # 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 return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False pt = self.getPointMapTool().point else: # il punto arriva come parametro della funzione pt = msg self.insPt = QgsPoint(pt) self.plugIn.setLastPoint(self.insPt) # se l'altezza testo dipende da un solo campo sizeFldNames = qad_label.get_labelSizeFieldNames(currLayer) if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0: # si appresta ad attendere la scala self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_TEXT", "Specify the text height <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.hText)) self.GetDistClass.dist = self.hText self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE | QadInputModeEnum.NOT_ZERO self.GetDistClass.startPt = self.insPt self.step = 2 self.GetDistClass.run(msgMapTool, msg) return False else: # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate( "Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format( str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ALTEZZA TESTO (da step = 1) elif self.step == 2: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.hText = self.GetDistClass.dist self.plugIn.setLastHText(self.hText) del self.GetDistClass self.GetDistClass = None # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames( currLayer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate( "Command_TEXT", "Specify the text rotation <{0}>: ") self.GetAngleClass.msg = prompt.format( str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE (da step = 1 o 2) elif self.step == 3: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.initLabelFields(currLayer) if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL VALORE DI UN CAMPO elif self.step == 4: # dopo aver atteso un valore si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica self.waitForFieldValue() return False # il valore arriva come parametro della funzione self.labelFieldValues.append(msg) self.labelFieldNamesNdx = self.labelFieldNamesNdx + 1 if self.waitForFieldValue() == False: self.addFeature(currLayer) return True # fine comando return False
def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nIl sistema di riferimento del progetto deve essere un sistema di coordinate proiettate.\n")) return True # fine comando currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Point) if currLayer is None: self.showErr(errMsg) return True # fine comando if qad_layer.isSymbolLayer(currLayer) == False: errMsg = QadMsg.translate("QAD", "\nIl layer corrente non é di tipo simbolo.") errMsg = errMsg + QadMsg.translate("QAD", "\nUn layer simbolo é un layer vettoriale di tipo punto senza etichetta.\n") self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PUNTO DI INSERIMENTO if self.step == 0: # inizio del comando self.waitForPoint() # si appresta ad attendere un punto self.step = self.step + 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO DI INSERIMENTO elif self.step == 1: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False pt = self.getPointMapTool().point else: # il punto arriva come parametro della funzione pt = msg self.insPt = QgsPoint(pt) self.plugIn.setLastPoint(self.insPt) # se la scala dipende da un campo scaleFldName = qad_layer.get_symbolScaleFieldName(currLayer) if len(scaleFldName) > 0: # si appresta ad attendere la scala self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_INSERT", "Specificare la scala del simbolo <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.scale)) self.GetDistClass.dist = self.scale self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE | QadInputModeEnum.NOT_ZERO self.GetDistClass.startPt = self.insPt self.step = 2 self.GetDistClass.run(msgMapTool, msg) return False else: # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(currLayer) if len(rotFldName) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_INSERT", "Specificare la rotazione del simbolo <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.addFeature(currLayer) return True #========================================================================= # RISPOSTA ALLA RICHIESTA SCALA (da step = 1) elif self.step == 2: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.scale = self.GetDistClass.dist self.plugIn.setLastScale(self.scale) del self.GetDistClass self.GetDistClass = None # se la rotazione dipende da un campo rotFldName = qad_layer.get_symbolRotationFieldName(currLayer) if len(rotFldName) > 0: if self.GetAngleClass is not None: del self.GetAngleClass # si appresta ad attendere l'angolo di rotazione self.GetAngleClass = QadGetAngleClass(self.plugIn) prompt = QadMsg.translate("Command_INSERT", "Specificare la rotazione del simbolo <{0}>: ") self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.rot))) self.GetAngleClass.angle = self.rot self.GetAngleClass.startPt = self.insPt self.step = 3 self.GetAngleClass.run(msgMapTool, msg) return False else: self.addFeature(currLayer) return True else: return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE (da step = 1 o 2) elif self.step == 3: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.addFeature(currLayer) return True # fine comando else: return True return False
def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando currLayer = None if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer # il layer corrente deve essere editabile e di tipo linea o poligono currLayer, errMsg = qad_layer.getCurrLayerEditable( self.plugIn.canvas, [QGis.Line, QGis.Polygon]) if currLayer is None: self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PRIMO PUNTO if self.step == 0: # inizio del comando self.WaitForFirstCorner() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DEL RETTANGOLO (da step = 0) elif self.step == 1: # 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_RECTANGLE", "Window not correct.")) self.WaitForFirstCorner() 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) == unicode or type(value) == str: if value == QadMsg.translate("Command_RECTANGLE", "Chamfer") or value == "Chamfer": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate( "Command_RECTANGLE", "Specify first chamfer distance for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue1)) self.GetDistClass.dist = self.gapValue1 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 4 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "Fillet") or value == "Fillet": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate( "Command_RECTANGLE", "Specify rectangle fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue1)) self.GetDistClass.dist = self.gapValue1 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 3 self.GetDistClass.run(msgMapTool, msg) elif type(value) == QgsPoint: self.firstCorner = value self.getPointMapTool().firstCorner = self.firstCorner self.WaitForSecondCorner(currLayer) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DEL RETTANGOLO (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_RECTANGLE", "Window not correct.")) self.WaitForSecondCorner(currLayer) 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) == unicode or type(value) == str: if value == QadMsg.translate("Command_RECTANGLE", "Area") or value == "Area": msg = QadMsg.translate( "Command_RECTANGLE", "Enter rectangle area in current units <{0}>: ") # si appresta ad attendere un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(msg.format(str(self.area)), QadInputTypeEnum.FLOAT, \ self.area, "", \ QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.getPointMapTool().setMode( Qad_rectangle_maptool_ModeEnum. NONE_KNOWN_ASK_FOR_FIRST_CORNER) self.step = 6 elif value == QadMsg.translate( "Command_RECTANGLE", "Dimensions") or value == "Dimensions": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate( "Command_RECTANGLE", "Specify length for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 10 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate( "Command_RECTANGLE", "Rotation") or value == "Rotation": keyWords = QadMsg.translate("Command_RECTANGLE", "Points") self.defaultValue = self.rot prompt = QadMsg.translate( "Command_RECTANGLE", "Specify rotation angle or [{0}] <{1}>: ").format( keyWords, str(qad_utils.toDegrees(self.rot))) englishKeyWords = "Points" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori non nulli self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \ self.rot, keyWords) self.getPointMapTool().setMode( Qad_rectangle_maptool_ModeEnum. NONE_KNOWN_ASK_FOR_FIRST_CORNER) self.step = 12 elif type(value) == QgsPoint: self.vertices.extend(qad_utils.getRectByCorners(self.firstCorner, value, self.rot, \ self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA RAGGIO DI CURVATURA (da step = 1) elif self.step == 3: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue1 = self.GetDistClass.dist if self.gapValue1 == 0: self.gapType = 0 # 0 = Angoli retti else: self.gapType = 1 # 1 = Raccorda i segmenti self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMA DISTANZA DI CIMATURA (da step = 1) elif self.step == 4: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue1 = self.GetDistClass.dist if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate( "Command_RECTANGLE", "Specify second chamfer distance for rectangle <{0}>: " ) self.GetDistClass.msg = prompt.format(str(self.gapValue2)) self.GetDistClass.dist = self.gapValue2 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 5 self.GetDistClass.run(msgMapTool, msg) else: self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDA DISTANZA DI CIMATURA (da step = 1) elif self.step == 5: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue2 = self.GetDistClass.dist if self.gapValue1 == 0 or self.gapValue2 == 0: self.gapType = 0 # 0 = Angoli retti else: self.gapType = 2 # 2 = Cima i segmenti self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA AREA RETTANGOLO (da step = 2) elif self.step == 6: # dopo aver atteso un punto si riavvia il comando keyWords = QadMsg.translate("Command_RECTANGLE", "Length") + "/" + \ QadMsg.translate("Command_RECTANGLE", "Width") englishKeyWords = "Length" + "/" + "Width" 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.defaultValue = QadMsg.translate( "Command_RECTANGLE", "Length") prompt = QadMsg.translate( "Command_RECTANGLE", "Calcolate the rectangle dimensions based on [{0}] <{1}>: " ).format(keyWords, self.defaultValue) keyWords += "_" + englishKeyWords # si appresta ad attendere una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) self.step = 7 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) == float: # é stata inserita l'area self.area = value self.defaultValue = QadMsg.translate("Command_RECTANGLE", "Length") prompt = QadMsg.translate( "Command_RECTANGLE", "Calcolate the rectangle dimensions based on [{0}] <{1}>: " ).format(keyWords, self.defaultValue) keyWords += "_" + englishKeyWords # si appresta ad attendere una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) self.step = 7 return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA MODALITA' (LUNGHEZZA / LARGHEZZA) DATA L'AREA (da step = 6) elif self.step == 7: # dopo aver atteso un punto o un numero reale 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 value = self.defaultValue return True # fine comando else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: return False else: # il punto arriva come parametro della funzione value = msg if value == QadMsg.translate("Command_RECTANGLE", "Length") or value == "Length": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate( "Command_RECTANGLE", "Enter length for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 8 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "Width") or value == "Width": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Enter width for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 9 self.GetDistClass.run(msgMapTool, msg) return False #========================================================================= # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO DATA L'AREA (da step = 7) elif self.step == 8: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByAreaAndLength(self.firstCorner, self.area, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO DATA L'AREA (da step = 7) elif self.step == 9: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByAreaAndWidth(self.firstCorner, self.area, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO (da step = 2) elif self.step == 10: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.dim1 = self.GetDistClass.dist if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Enter width for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 11 self.GetDistClass.run(msgMapTool, msg) return False #========================================================================= # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO (da step = 10) elif self.step == 11: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByCornerAndDims(self.firstCorner, self.dim1, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 2) elif self.step == 12: # 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 value = self.defaultValue else: self.setMapTool( self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode or type(value) == str: if value == QadMsg.translate("Command_RECTANGLE", "Points") or value == "Points": # si appresta ad attendere l'angolo di rotazione if self.GetAngleClass is not None: del self.GetAngleClass self.GetAngleClass = QadGetAngleClass(self.plugIn) self.GetAngleClass.msg = QadMsg.translate( "Command_RECTANGLE", "Specify first point: ") self.GetAngleClass.angle = self.rot self.step = 13 self.GetAngleClass.run(msgMapTool, msg) elif type(value) == QgsPoint: self.rot = qad_utils.getAngleBy2Pts(self.firstCorner, value) self.WaitForSecondCorner(currLayer) elif type(value) == float: self.rot = qad_utils.toRadians(value) self.WaitForSecondCorner(currLayer) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 12) elif self.step == 13: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.WaitForSecondCorner(currLayer) self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di rotazione
class QadRECTANGLECommandClass(QadCommandClass): def instantiateNewCmd(self): """ istanzia un nuovo comando dello stesso tipo """ return QadRECTANGLECommandClass(self.plugIn) def getName(self): return QadMsg.translate("Command_list", "RECTANGLE") def getEnglishName(self): return "RECTANGLE" def connectQAction(self, action): QObject.connect(action, SIGNAL("triggered()"), self.plugIn.runRECTANGLECommand) def getIcon(self): return QIcon(":/plugins/qad/icons/rectangle.png") def getNote(self): # impostare le note esplicative del comando return QadMsg.translate("Command_RECTANGLE", "Creates a rectangle.") def __init__(self, plugIn): QadCommandClass.__init__(self, plugIn) # se questo flag = True il comando serve all'interno di un altro comando per disegnare un rettangolo # che non verrà salvato su un layer self.virtualCmd = False self.firstCorner = None self.gapType = 0 # 0 = Angoli retti; 1 = Raccorda i segmenti; 2 = Cima i segmenti self.gapValue1 = 0 # se gapType = 1 -> raggio di curvatura; se gapType = 2 -> prima distanza di cimatura self.gapValue2 = 0 # se gapType = 2 -> seconda distanza di cimatura self.area = 100 self.dim1 = 10 self.rot = 0 self.vertices = [] self.GetDistClass = None self.GetAngleClass = None self.defaultValue = None # usato per gestire il tasto dx del mouse def __del__(self): QadCommandClass.__del__(self) if self.GetDistClass is not None: del self.GetDistClass if self.GetAngleClass is not None: del self.GetAngleClass def getPointMapTool(self, drawMode = QadGetPointDrawModeEnum.NONE): # quando si é in fase di richiesta distanza if self.step == 3 or self.step == 4 or self.step == 5 or \ self.step == 8 or self.step == 9 or self.step == 10 or self.step == 11: return self.GetDistClass.getPointMapTool() # quando si é in fase di richiesta rotazione elif self.step == 13: return self.GetAngleClass.getPointMapTool() else: if (self.plugIn is not None): if self.PointMapTool is None: self.PointMapTool = Qad_rectangle_maptool(self.plugIn) return self.PointMapTool else: return None def addRectangleToLayer(self, layer): if layer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, layer, self.vertices) elif layer.geometryType() == QGis.Polygon: qad_layer.addPolygonToLayer(self.plugIn, layer, self.vertices) #============================================================================ # WaitForFirstCorner #============================================================================ def WaitForFirstCorner(self): self.step = 1 self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER) keyWords = QadMsg.translate("Command_RECTANGLE", "Chamfer") + "/" + \ QadMsg.translate("Command_RECTANGLE", "Fillet") prompt = QadMsg.translate("Command_RECTANGLE", "Specify first corner or [{0}]: ").format(keyWords) englishKeyWords = "Chamfer" + "/" + "Fillet" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, keyWords, QadInputModeEnum.NONE) #============================================================================ # WaitForSecondCorner #============================================================================ def WaitForSecondCorner(self, layer): self.step = 2 self.getPointMapTool().rot = self.rot self.getPointMapTool().gapType = self.gapType self.getPointMapTool().gapValue1 = self.gapValue1 self.getPointMapTool().gapValue2 = self.gapValue2 self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.FIRST_CORNER_KNOWN_ASK_FOR_SECOND_CORNER) if layer is not None: self.getPointMapTool().geomType = layer.geometryType() keyWords = QadMsg.translate("Command_RECTANGLE", "Area") + "/" + \ QadMsg.translate("Command_RECTANGLE", "Dimensions") + "/" + \ QadMsg.translate("Command_RECTANGLE", "Rotation") prompt = QadMsg.translate("Command_RECTANGLE", "Specify other corner or [{0}]: ").format(keyWords) englishKeyWords = "Area" + "/" + "Dimensions" + "/" + "Rotation" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, keyWords, QadInputModeEnum.NONE) #============================================================================ # run #============================================================================ def run(self, msgMapTool = False, msg = None): 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 # fine comando currLayer = None if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer # il layer corrente deve essere editabile e di tipo linea o poligono currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, [QGis.Line, QGis.Polygon]) if currLayer is None: self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PRIMO PUNTO if self.step == 0: # inizio del comando self.WaitForFirstCorner() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DEL RETTANGOLO (da step = 0) elif self.step == 1: # 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_RECTANGLE", "Window not correct.")) self.WaitForFirstCorner() 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) == unicode: if value == QadMsg.translate("Command_RECTANGLE", "Chamfer") or value == "Chamfer": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specify first chamfer distance for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue1)) self.GetDistClass.dist = self.gapValue1 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 4 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "Fillet") or value == "Fillet": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specify rectangle fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue1)) self.GetDistClass.dist = self.gapValue1 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 3 self.GetDistClass.run(msgMapTool, msg) elif type(value) == QgsPoint: self.firstCorner = value self.getPointMapTool().firstCorner = self.firstCorner self.WaitForSecondCorner(currLayer) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DEL RETTANGOLO (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_RECTANGLE", "Window not correct.")) self.WaitForSecondCorner(currLayer) 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) == unicode: if value == QadMsg.translate("Command_RECTANGLE", "Area") or value == "Area": msg = QadMsg.translate("Command_RECTANGLE", "Enter rectangle area in current units <{0}>: ") # si appresta ad attendere un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(msg.format(str(self.area)), QadInputTypeEnum.FLOAT, \ self.area, "", \ QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER) self.step = 6 elif value == QadMsg.translate("Command_RECTANGLE", "Dimensions") or value == "Dimensions": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specify length for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 10 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "Rotation") or value == "Rotation": keyWords = QadMsg.translate("Command_RECTANGLE", "Points") self.defaultValue = self.rot prompt = QadMsg.translate("Command_RECTANGLE", "Specify rotation angle or [{0}] <{1}>: ").format(keyWords, str(qad_utils.toDegrees(self.rot))) englishKeyWords = "Points" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori non nulli self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \ self.rot, keyWords) self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER) self.step = 12 elif type(value) == QgsPoint: self.vertices.extend(qad_utils.getRectByCorners(self.firstCorner, value, self.rot, \ self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA RAGGIO DI CURVATURA (da step = 1) elif self.step == 3: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue1 = self.GetDistClass.dist if self.gapValue1 == 0: self.gapType = 0 # 0 = Angoli retti else: self.gapType = 1 # 1 = Raccorda i segmenti self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMA DISTANZA DI CIMATURA (da step = 1) elif self.step == 4: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue1 = self.GetDistClass.dist if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Specify second chamfer distance for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.gapValue2)) self.GetDistClass.dist = self.gapValue2 self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 5 self.GetDistClass.run(msgMapTool, msg) else: self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDA DISTANZA DI CIMATURA (da step = 1) elif self.step == 5: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.gapValue2 = self.GetDistClass.dist if self.gapValue1 == 0 or self.gapValue2 == 0: self.gapType = 0 # 0 = Angoli retti else: self.gapType = 2 # 2 = Cima i segmenti self.WaitForFirstCorner() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA AREA RETTANGOLO (da step = 2) elif self.step == 6: # dopo aver atteso un punto si riavvia il comando keyWords = QadMsg.translate("Command_RECTANGLE", "Length") + "/" + \ QadMsg.translate("Command_RECTANGLE", "Width") englishKeyWords = "Length" + "/" + "Width" 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.defaultValue = QadMsg.translate("Command_RECTANGLE", "Length") prompt = QadMsg.translate("Command_RECTANGLE", "Calcolate the rectangle dimensions based on [{0}] <{1}>: ").format(keyWords, self.defaultValue) keyWords += "_" + englishKeyWords # si appresta ad attendere una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) self.step = 7 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) == float: # é stata inserita l'area self.area = value self.defaultValue = QadMsg.translate("Command_RECTANGLE", "Length") prompt = QadMsg.translate("Command_RECTANGLE", "Calcolate the rectangle dimensions based on [{0}] <{1}>: ").format(keyWords, self.defaultValue) keyWords += "_" + englishKeyWords # si appresta ad attendere una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \ self.defaultValue, \ keyWords, QadInputModeEnum.NONE) self.step = 7 return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA MODALITA' (LUNGHEZZA / LARGHEZZA) DATA L'AREA (da step = 6) elif self.step == 7: # dopo aver atteso un punto o un numero reale 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 value = self.defaultValue return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: return False else: # il punto arriva come parametro della funzione value = msg if value == QadMsg.translate("Command_RECTANGLE", "Length") or value == "Length": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Enter length for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 8 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_RECTANGLE", "Width") or value == "Width": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Enter width for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 9 self.GetDistClass.run(msgMapTool, msg) return False #========================================================================= # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO DATA L'AREA (da step = 7) elif self.step == 8: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByAreaAndLength(self.firstCorner, self.area, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO DATA L'AREA (da step = 7) elif self.step == 9: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByAreaAndWidth(self.firstCorner, self.area, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO (da step = 2) elif self.step == 10: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.dim1 = self.GetDistClass.dist if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_RECTANGLE", "Enter width for rectangle <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.dim1)) self.GetDistClass.dist = self.dim1 self.step = 11 self.GetDistClass.run(msgMapTool, msg) return False #========================================================================= # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO (da step = 10) elif self.step == 11: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.vertices.extend(qad_utils.getRectByCornerAndDims(self.firstCorner, self.dim1, self.GetDistClass.dist, \ self.rot, self.gapType, self.gapValue1, self.gapValue2)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addRectangleToLayer(currLayer) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 2) elif self.step == 12: # 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 value = self.defaultValue else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_RECTANGLE", "Points") or value == "Points": # si appresta ad attendere l'angolo di rotazione if self.GetAngleClass is not None: del self.GetAngleClass self.GetAngleClass = QadGetAngleClass(self.plugIn) self.GetAngleClass.msg = QadMsg.translate("Command_RECTANGLE", "Specify first point: ") self.GetAngleClass.angle = self.rot self.step = 13 self.GetAngleClass.run(msgMapTool, msg) elif type(value) == QgsPoint: self.rot = qad_utils.getAngleBy2Pts(self.firstCorner, value) self.WaitForSecondCorner(currLayer) elif type(value) == float: self.rot = qad_utils.toRadians(value) self.WaitForSecondCorner(currLayer) return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 12) elif self.step == 13: if self.GetAngleClass.run(msgMapTool, msg) == True: if self.GetAngleClass.angle is not None: self.rot = self.GetAngleClass.angle self.plugIn.setLastRot(self.rot) self.WaitForSecondCorner(currLayer) self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di rotazione
def run(self, msgMapTool = False, msg = None): 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 # fine comando if self.step == 0: CurrSettingsMsg = QadMsg.translate("QAD", "\nCurrent settings: ") if self.filletMode == 1: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_FILLET", "Mode = Trim-extend") else: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_FILLET", "Mode = No trim-extend") CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_FILLET", ", Radius = ") + str(self.radius) self.showMsg(CurrSettingsMsg) self.waitForFirstEntSel() return False # continua #========================================================================= # RISPOSTA ALLA SELEZIONE PRIMO OGGETTO elif self.step == 1: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_FILLET", "Undo") or value == "Undo": if self.nOperationsToUndo > 0: self.nOperationsToUndo = self.nOperationsToUndo - 1 self.plugIn.undoEditCommand() else: self.showMsg(QadMsg.translate("QAD", "\nThe command has been canceled.")) self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto elif value == QadMsg.translate("Command_FILLET", "Polyline") or value == "Polyline": self.WaitForPolyline() # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForFirstEntSel" elif value == QadMsg.translate("Command_FILLET", "Radius", "waitForFirstEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 3 self.GetDistClass.run(msgMapTool, msg) elif value == QadMsg.translate("Command_FILLET", "Trim") or value == "Trim": self.waitForFilletMode() elif value == QadMsg.translate("Command_FILLET", "Multiple") or value == "Multiple": self.multi = True self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto else: return True # fine comando return False #========================================================================= # RISPOSTA ALLA SELEZIONE DI UNA POLILINEA (da step = 1) elif self.step == 2: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: # l'opzione Radius viene tradotta in italiano in "Raggio" nel contesto "WaitForPolyline" if value == QadMsg.translate("Command_FILLET", "Radius", "WaitForPolyline") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 5 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity1.clear() self.linearObjectList1.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(True, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(True, result[1], result[0].id(), result[2]) == True: if self.filletPolyline() == False or self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.WaitForPolyline() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 1) elif self.step == 3: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set(QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA MODALITA' DI TAGLIO (da step = 1) elif self.step == 4: # dopo aver atteso un punto o un numero reale 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 value = self.filletMode else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_FILLET", "Trim-extend") or value == "Trim-extend": self.filletMode = 1 elif value == QadMsg.translate("Command_FILLET", "No trim-extend") or value == "No trim-extend": self.filletMode = 2 self.plugIn.setFilletMode(self.filletMode) self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 3) elif self.step == 5: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set(QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.WaitForPolyline() self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando #========================================================================= # RISPOSTA ALLA SELEZIONE SECONDO OGGETTO elif self.step == 6: 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: # l'opzione Radius viene tradotta in italiano in "RAggio" nel contesto "waitForSecondEntSel" if value == QadMsg.translate("Command_FILLET", "Radius", "waitForSecondEntSel") or value == "Radius": if self.GetDistClass is not None: del self.GetDistClass self.GetDistClass = QadGetDistClass(self.plugIn) prompt = QadMsg.translate("Command_FILLET", "Specify fillet radius <{0}>: ") self.GetDistClass.msg = prompt.format(str(self.radius)) self.GetDistClass.dist = self.radius self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE self.step = 7 self.GetDistClass.run(msgMapTool, msg) return False elif type(value) == QgsPoint: # se é stato selezionato un punto self.entity2.clear() self.linearObjectList2.removeAll() if self.getPointMapTool().entity.isInitialized(): if self.setEntityInfo(False, self.getPointMapTool().entity.layer, \ self.getPointMapTool().entity.featureId, value) == True: if self.getPointMapTool().shiftKey == True: dummyRadius = self.radius self.radius = 0 dummyFilletMode = self.filletMode self.filletMode = 1 # modalità di raccordo; 1=Taglia-estendi result = self.fillet() self.radius = dummyRadius self.filletMode = dummyFilletMode else: result = self.fillet() if result == False: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: # cerco se ci sono entità nel punto indicato considerando # solo layer lineari o poligono editabili che non appartengano a quote layerList = [] for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \ layer.isEditable(): if len(QadDimStyles.getDimListByLayer(layer)) == 0: layerList.append(layer) result = qad_utils.getEntSel(self.getPointMapTool().toCanvasCoordinates(value), \ self.getPointMapTool(), \ QadVariables.get(QadMsg.translate("Environment variables", "PICKBOX")), \ layerList) if result is not None: # result[0] = feature, result[1] = layer, result[0] = point if self.setEntityInfo(False, result[1], result[0].id(), result[2]) == True: if self.fillet() == False: self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False if self.multi: self.waitForFirstEntSel() # si appresta ad attendere la selezione del primo oggetto return False else: return True else: return True # fine comando self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO DI RACCORDO (da step = 6) elif self.step == 7: if self.GetDistClass.run(msgMapTool, msg) == True: if self.GetDistClass.dist is not None: self.radius = self.GetDistClass.dist QadVariables.set(QadMsg.translate("Environment variables", "FILLETRAD"), self.radius) QadVariables.save() self.waitForSecondEntSel() # si appresta ad attendere la selezione del secondo oggetto self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza return False # fine comando