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)
def run(self, msgMapTool = False, msg = None): self.isValidPreviousInput = True # per gestire il comando anche in macro 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, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Line) if currLayer is None: self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA PRIMO PUNTO o CENTRO if self.step == 0: # inizio del comando # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_START_PT) keyWords = QadMsg.translate("Command_ARC", "Center") prompt = QadMsg.translate("Command_ARC", "Specify the start point of the arc or [{0}]:").format(keyWords) englishKeyWords = "Center" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo di modo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NONE) self.step = 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMO PUNTO o CENTRO elif self.step == 1: # dopo aver atteso un punto o enter o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse return True # fine comando 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 value is None: if self.plugIn.lastPoint is not None: value = self.plugIn.lastPoint else: return True # fine comando if type(value) == QgsPoint: # se é stato inserito il punto iniziale dell'arco self.startPt = value self.plugIn.setLastPoint(value) # imposto il map tool self.getPointMapTool().arcStartPt = self.startPt self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_PT_KNOWN_ASK_FOR_SECOND_PT) keyWords = QadMsg.translate("Command_ARC", "Center") + "/" + \ QadMsg.translate("Command_ARC", "End") prompt = QadMsg.translate("Command_ARC", "Specify second point of the arc or [{0}]:").format(keyWords) englishKeyWords = "Center" + "/" + "End" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NONE) self.step = 2 return False else: # si vuole inserire il centro dell'arco # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_CENTER_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_ARC", "Specify the center of the arc: ")) self.step = 13 return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO o CENTRO o FINE elif self.step == 2: # dopo aver atteso un punto o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse return True # fine comando 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_ARC", "Center") or value == "Center": # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_PT_KNOWN_ASK_FOR_CENTER_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_ARC", "Specify the center of the arc: ")) self.step = 4 elif value == QadMsg.translate("Command_ARC", "End") or value == "End": # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_PT_KNOWN_ASK_FOR_END_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_ARC", "Specify the final point of the arc: ")) self.step = 8 elif type(value) == QgsPoint: # se é stato inserito il secondo punto dell'arco self.secondPt = value # imposto il map tool self.getPointMapTool().arcSecondPt = self.secondPt self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_SECOND_PT_KNOWN_ASK_FOR_END_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_ARC", "Specify the final point of the arc: ")) self.step = 3 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO FINALE DELL'ARCO (da step = 2) elif self.step == 3: # dopo aver atteso un punto si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg self.endPt = value arc = QadArc() if arc.fromStartSecondEndPts(self.startPt, self.secondPt, self.endPt) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_ARC", "Specify the final point of the arc: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA CENTRO DELL'ARCO (da step = 2) elif self.step == 4: # 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 value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg self.centerPt = value self.plugIn.setLastPoint(value) # imposto il map tool self.getPointMapTool().arcCenterPt = self.centerPt self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_END_PT) keyWords = QadMsg.translate("Command_ARC", "Angle") + "/" + \ QadMsg.translate("Command_ARC", "chord Length") prompt = QadMsg.translate("Command_ARC", "Specify the final point of the arc or [{0}]: ").format(keyWords) englishKeyWords = "Angle" + "/" + "chord Length" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords, valori nulli non ammessi self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) self.step = 5 return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare punto finale dell'arco o [Angolo/Lunghezza corda]: " (da step = 4) elif self.step == 5: # dopo aver atteso un punto o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse return True # fine comando 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_ARC", "Angle") or value == "Angle": # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_ANGLE) # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori nulli non ammessi self.waitFor(QadMsg.translate("Command_ARC", "Specify the included angle: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.ANGLE, \ None, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO) self.step = 6 return False elif value == QadMsg.translate("Command_ARC", "chord Length") or value == "chord Length": # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_CHORD) # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(QadMsg.translate("Command_ARC", "Specify the chord length: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ None, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.step = 7 return False elif type(value) == QgsPoint: # se é stato inserito il punto finale dell'arco self.endPt = value arc = QadArc() if arc.fromStartCenterEndPts(self.startPt, self.centerPt, self.endPt) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando keyWords = QadMsg.translate("Command_ARC", "Angle") + "/" + \ QadMsg.translate("Command_ARC", "chord Length") prompt = QadMsg.translate("Command_ARC", "Specify the final point of the arc or [{0}]: ").format(keyWords) englishKeyWords = "Angle" + "/" + "chord Length" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords, valori nulli non ammessi self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare angolo inscritto: " (da step = 5) elif self.step == 6: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.angle = qad_utils.getAngleBy2Pts(self.centerPt, value) else: self.angle = value arc = QadArc() if arc.fromStartCenterPtsAngle(self.startPt, self.centerPt, self.angle) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori nulli non ammessi self.waitFor(QadMsg.translate("Command_ARC", "Specify the included angle: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.ANGLE, \ None, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare lunghezza della corda: " (da step = 5) 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.chord = qad_utils.getDistance(self.startPt, value) else: self.chord = value arc = QadArc() if arc.fromStartCenterPtsChord(self.startPt, self.centerPt, self.chord) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi ammessi self.waitFor(QadMsg.translate("Command_ARC", "Specify the chord length: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ None, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare punto finale dell'arco: " (da step = 1) elif self.step == 8: # 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 value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg self.endPt = value self.plugIn.setLastPoint(self.endPt) # imposto il map tool self.getPointMapTool().arcEndPt = self.endPt self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_CENTER) keyWords = QadMsg.translate("Command_ARC", "Angle") + "/" + \ QadMsg.translate("Command_ARC", "Direction") + "/" + \ QadMsg.translate("Command_ARC", "Radius") prompt = QadMsg.translate("Command_ARC", "Specify the center point of the arc or [{0}]: ").format(keyWords) englishKeyWords = "Angle" + "/" + "Direction" + "/" + "Radius" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords, valori nulli non ammessi self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) self.step = 9 return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare centro dell'arco o [Angolo/Direzione/Raggio]: " (da step = 8) elif self.step == 9: # dopo aver atteso un punto o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse return True # fine comando 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_ARC", "Angle") or value == "Angle": # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_ANGLE) # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, isNullable self.waitFor(QadMsg.translate("Command_ARC", "Specify the included angle: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.ANGLE, \ None, "", QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO) self.step = 10 return False elif value == QadMsg.translate("Command_ARC", "Direction") or value == "Direction": # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_TAN) # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, isNullable self.waitFor(QadMsg.translate("Command_ARC", "Specify the tangent direction for the start point of the arc: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.ANGLE, \ None, "", QadInputModeEnum.NOT_NULL) self.step = 11 return False elif value == QadMsg.translate("Command_ARC", "Radius") or value == "Radius": # imposto il map tool self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_RADIUS) # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, isNullable self.waitFor(QadMsg.translate("Command_ARC", "Specify the radius of the arc: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ None, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.step = 12 return False elif type(value) == QgsPoint: # se é stato inserito il centro dell'arco self.centerPt = value arc = QadArc() if arc.fromStartCenterEndPts(self.startPt, self.centerPt, self.endPt) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando keyWords = QadMsg.translate("Command_ARC", "Angle") + "/" + \ QadMsg.translate("Command_ARC", "Direction") + "/" + \ QadMsg.translate("Command_ARC", "Radius") prompt = QadMsg.translate("Command_ARC", "Specify the center point of the arc or [{0}]: ").format(keyWords) englishKeyWords = "Angle" + "/" + "Direction" + "/" + "Radius" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords, isNullable self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare angolo inscritto: " (da step = 9) elif self.step == 10: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.angle = qad_utils.getAngleBy2Pts(self.startPt, value) else: self.angle = value arc = QadArc() if arc.fromStartEndPtsAngle(self.startPt, self.endPt, self.angle) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori non nulli self.waitFor(QadMsg.translate("Command_ARC", "Specify the included angle: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.ANGLE, \ None, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare direzione tangente per il punto iniziale dell'arco: " (da step = 9) elif self.step == 11: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.angleTan = qad_utils.getAngleBy2Pts(self.startPt, value) else: self.angleTan = value arc = QadArc() if arc.fromStartEndPtsTan(self.startPt, self.endPt, self.angleTan) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, isNullable self.waitFor(QadMsg.translate("Command_ARC", "Specify the tangent direction for the start point of the arc: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.ANGLE, \ None, "", QadInputModeEnum.NOT_NULL) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA "Specificare raggio dell'arco: " (da step = 9) elif self.step == 12: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.radius = qad_utils.getDistance(self.endPt, value) else: self.radius = value self.plugIn.setLastRadius(self.radius) arc = QadArc() if arc.fromStartEndPtsRadius(self.startPt, self.endPt, self.radius) == True: self.plugIn.setLastPoint(arc.getEndPt()) points = arc.asPolyline() if points is not None: # se i punti sono così vicini da essere considerati uguali if qad_utils.ptNear(self.startPt, arc.getStartPt()): self.plugIn.setLastSegmentAng(arc.getTanDirectionOnEndPt()) else: self.plugIn.setLastSegmentAng(arc.getTanDirectionOnStartPt() + math.pi) qad_layer.addLineToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(QadMsg.translate("Command_ARC", "Specify the radius of the arc: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ None, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA CENTRO DELL'ARCO (da step = 1) elif self.step == 13: # 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 value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg self.centerPt = value self.plugIn.setLastPoint(value) # imposto il map tool self.getPointMapTool().arcCenterPt = self.centerPt self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.CENTER_PT_KNOWN_ASK_FOR_START_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_ARC", "Specify the start point of the arc: ")) self.step = 14 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO INIZIALE DELL'ARCO (da step = 13) elif self.step == 14: # 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 value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg self.startPt = value self.plugIn.setLastPoint(value) # imposto il map tool self.getPointMapTool().arcStartPt = self.startPt self.getPointMapTool().setMode(Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_END_PT) keyWords = QadMsg.translate("Command_ARC", "Angle") + "/" + \ QadMsg.translate("Command_ARC", "chord Length") prompt = QadMsg.translate("Command_ARC", "Specify the final point of the arc or [{0}]: ").format(keyWords) englishKeyWords = "Angle" + "/" + "chord Length" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords, isNullable self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_NULL) self.step = 5 return False
def addLinesToLayer(self, layer): i = 1 while i < len(self.vertices): qad_layer.addLineToLayer(self.plugIn, layer, [self.vertices[i - 1], self.vertices[i]]) i = i + 1
def run(self, msgMapTool = False, msg = None): self.isValidPreviousInput = True # per gestire il comando anche in macro 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 il cerchio 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 self.getPointMapTool().geomType = QGis.Line if currLayer.geometryType() == QGis.Line else QGis.Polygon #========================================================================= # RICHIESTA PRIMO PUNTO o CENTRO if self.step == 0: # inizio del comando # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_CENTER_PT) keyWords = QadMsg.translate("Command_CIRCLE", "3Points") + "/" + \ QadMsg.translate("Command_CIRCLE", "2POints") + "/" + \ QadMsg.translate("Command_CIRCLE", "Ttr (tangent tangent radius)") prompt = QadMsg.translate("Command_CIRCLE", "Specify the center point of the circle or [{0}]: ").format(keyWords) englishKeyWords = "3Points" + "/" + "2POints" + "/" + "Ttr (tangent tangent radius)" 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) self.step = 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA CENTRO elif self.step == 1: # dopo aver atteso un punto o enter o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi é stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse return True # fine comando 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 value is None: if self.plugIn.lastPoint is not None: value = self.plugIn.lastPoint else: return True # fine comando if type(value) == unicode: if value == QadMsg.translate("Command_CIRCLE", "3Points") or value == "3Points": # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify first point on the circle: ")) self.step = 4 elif value == QadMsg.translate("Command_CIRCLE", "2POints") or value == "2POints": # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_DIAM_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify first end of the circle diameter: ")) self.step = 7 elif value == QadMsg.translate("Command_CIRCLE", "Ttr (tangent tangent radius)") or \ value == "Ttr (tangent tangent radius)": # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_TAN) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify first tangent element of the circle: ")) self.step = 9 elif type(value) == QgsPoint: # se é stato inserito il centro del cerchio self.centerPt = value self.plugIn.setLastPoint(value) # imposto il map tool self.getPointMapTool().centerPt = self.centerPt self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.CENTER_PT_KNOWN_ASK_FOR_RADIUS) keyWords = QadMsg.translate("Command_CIRCLE", "Diameter") + "/" + \ QadMsg.translate("Command_CIRCLE", "Area") prompt = QadMsg.translate("Command_CIRCLE", "Specify the circle radius or [{0}]: ").format(keyWords) englishKeyWords = "Diameter" + "/" + "Area" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, \ QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.step = 2 return False #========================================================================= # RISPOSTA ALLA RICHIESTA RAGGIO O DIAMETRO O AREA elif self.step == 2: # dopo aver atteso un punto o una parola chiave si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse return True # fine comando 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_CIRCLE", "Diameter") or value == "Diameter": # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.CENTER_PT_KNOWN_ASK_FOR_DIAM) # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(QadMsg.translate("Command_CIRCLE", "Specify the circle diameter: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ None, \ "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.step = 3 elif value == QadMsg.translate("Command_CIRCLE", "Area") or value == "Area": msg = QadMsg.translate("Command_CIRCLE", "Enter circle area in current unit <{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_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_CENTER_PT) self.step = 13 elif type(value) == QgsPoint or type(value) == float: # se é stato inserito il raggio del cerchio if type(value) == QgsPoint: # se é stato inserito il raggio del cerchio con un punto self.radius = qad_utils.getDistance(self.centerPt, value) else: self.radius = value self.plugIn.setLastRadius(self.radius) circle = QadCircle() circle.set(self.centerPt, self.radius) points = circle.asPolyline() if points is not None: if self.virtualCmd == False: # se si vuole veramente salvare il cerchio in un layer if currLayer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, currLayer, points) else: qad_layer.addPolygonToLayer(self.plugIn, currLayer, points) return True # fine comando keyWords = QadMsg.translate("Command_CIRCLE", "Diameter") + "/" + \ QadMsg.translate("Command_CIRCLE", "Area") prompt = QadMsg.translate("Command_CIRCLE", "Specify the circle radius or [{0}]: ").format(keyWords) englishKeyWords = "Diameter" + "/" + "Area" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o una parola chiave # msg, inputType, default, keyWords, valori positivi self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA DIAMETRO DEL CERCHIO (da step = 2) elif self.step == 3: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: # se é stato inserito un punto self.radius = qad_utils.getDistance(self.centerPt, value) / 2 elif type(value) == float: # se é stato inserito un numero reale self.radius = value self.plugIn.setLastRadius(self.radius) circle = QadCircle() circle.set(self.centerPt, self.radius) points = circle.asPolyline() if points is not None: if self.virtualCmd == False: # se si vuole veramente salvare il cerchio in un layer if currLayer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, currLayer, points) else: qad_layer.addPolygonToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(QadMsg.translate("Command_CIRCLE", "Specify the circle diameter: "), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ None, \ "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DEL CERCHIO (da step = 1) elif self.step == 4: # 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 snapTypeOnSel = self.getPointMapTool().snapTypeOnSelection value = self.getPointMapTool().point entity = self.getPointMapTool().entity else: # il punto arriva come parametro della funzione value = msg snapTypeOnSel = QadSnapTypeEnum.NONE # se é stato selezionato un punto con la modalità TAN_DEF é un punto differito if snapTypeOnSel == QadSnapTypeEnum.TAN_DEF and entity.isInitialized(): self.firstPt = None self.firstPtTan = value self.firstGeomTan = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) # trasformo la geometria self.firstGeomTan.transform(coordTransform) # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) else: # altrimenti é un punto esplicito self.firstPt = value self.plugIn.setLastPoint(value) # imposto il map tool self.getPointMapTool().firstPt = self.firstPt self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second point on the circle: ")) self.step = 5 return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DEL CERCHIO (da step = 4) elif self.step == 5: # 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 snapTypeOnSel = self.getPointMapTool().snapTypeOnSelection value = self.getPointMapTool().point entity = self.getPointMapTool().entity else: # il punto arriva come parametro della funzione value = msg snapTypeOnSel = QadSnapTypeEnum.NONE # se é stato selezionato un punto con la modalità TAN_DEF é un punto differito if snapTypeOnSel == QadSnapTypeEnum.TAN_DEF and entity.isInitialized(): self.secondPt = None self.secondPtTan = value self.secondGeomTan = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) # trasformo la geometria self.secondGeomTan.transform(coordTransform) # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_SECOND_PT_KNOWN_ASK_FOR_THIRD_PT) else: # altrimenti é un punto esplicito self.secondPt = value self.plugIn.setLastPoint(value) # imposto il map tool self.getPointMapTool().secondPt = self.secondPt self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_SECOND_PT_KNOWN_ASK_FOR_THIRD_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify the third point on the circle: ")) self.step = 6 return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL TERZO PUNTO DEL CERCHIO (da step = 5) elif self.step == 6: # 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 snapTypeOnSel = self.getPointMapTool().snapTypeOnSelection value = self.getPointMapTool().point entity = self.getPointMapTool().entity else: # il punto arriva come parametro della funzione value = msg snapTypeOnSel = QadSnapTypeEnum.NONE # se é stato selezionato un punto con la modalità TAN_DEF é un punto differito if snapTypeOnSel == QadSnapTypeEnum.TAN_DEF and entity.isInitialized(): self.thirdPt = None self.thirdPtTan = value self.thirdGeomTan = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) # trasformo la geometria self.thirdGeomTan.transform(coordTransform) else: # altrimenti é un punto esplicito self.thirdPt = value self.plugIn.setLastPoint(value) circle = QadCircle() points = None if self.firstPt is None: # se il primo punto é definito con un punto differito if self.secondPt is None: # se il secondo punto é definito con un punto differito if self.thirdPt is None: # se il terzo punto é definito con un punto differito if circle.from3TanPts(self.firstGeomTan, self.firstPtTan, \ self.secondGeomTan, self.secondPtTan, \ self.thirdGeomTan, self.thirdPtTan) == True: points = circle.asPolyline() else: # se il terzo punto é definito con un punto esplicito if circle.from1IntPt2TanPts(self.thirdPt, self.firstGeomTan, self.firstPtTan, self.secondGeomTan, self.secondPtTan) == True: points = circle.asPolyline() else: # se il secondo punto é definito con un punto esplicito if self.thirdPt is None: # se il terzo punto é definito con un punto differito if circle.from1IntPt2TanPts(self.secondPt, self.firstGeomTan, self.firstPtTan, self.thirdGeomTan, self.thirdPtTan) == True: points = circle.asPolyline() else: # se il terzo punto é definito con un punto esplicito if circle.from2IntPts1TanPt(self.secondPt, self.thirdPt, \ self.firstGeomTan, self.firstPtTan) == True: points = circle.asPolyline() else: # se il primo punto é definito con un punto esplicito if self.secondPt is None: # se il secondo punto é definito con un punto differito if self.thirdPt is None: # se il terzo punto é definito con un punto differito if circle.from1IntPt2TanPts(self.firstPt, self.secondGeomTan, self.secondPtTan, self.thirdGeomTan, self.thirdPtTan) == True: points = circle.asPolyline() else: # se il terzo punto é definito con un punto esplicito if circle.from2IntPts1TanPt(self.firstPt, self.thirdPt, \ self.secondGeomTan, self.secondPtTan) == True: points = circle.asPolyline() else: # se il secondo punto é definito con un punto esplicito if self.thirdPt is None: # se il terzo punto é definito con un punto differito if circle.from2IntPts1TanPt(self.firstPt, self.secondPt, \ self.thirdGeomTan, self.thirdPtTan) == True: points = circle.asPolyline() else: # se il terzo punto é definito con un punto esplicito if circle.from3Pts(self.firstPt, self.secondPt, value) == True: points = circle.asPolyline() if points is not None: self.centerPt = circle.center self.radius = circle.radius if self.virtualCmd == False: # se si vuole veramente salvare il cerchio in un layer if currLayer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, currLayer, points) else: qad_layer.addPolygonToLayer(self.plugIn, currLayer, points) return True # fine comando # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify the third point on the circle: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA PRIMA ESTREMITA' DIAM DEL CERCHIO (da step = 1) elif self.step == 7: # 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 snapTypeOnSel = self.getPointMapTool().snapTypeOnSelection value = self.getPointMapTool().point entity = self.getPointMapTool().entity else: # il punto arriva come parametro della funzione value = msg snapTypeOnSel = QadSnapTypeEnum.NONE # se é stato selezionato un punto con la modalità TAN_DEF é un punto differito if snapTypeOnSel == QadSnapTypeEnum.TAN_DEF and entity.isInitialized(): self.firstDiamPt = None self.firstDiamPtTan = value self.firstDiamGeomTan = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) # trasformo la geometria self.firstDiamGeomTan.transform(coordTransform) # imposto il map tool self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_DIAM_PT_KNOWN_ASK_FOR_SECOND_DIAM_PT) else: # altrimenti é un punto esplicito self.firstDiamPt = value # imposto il map tool self.getPointMapTool().firstDiamPt = self.firstDiamPt self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_DIAM_PT_KNOWN_ASK_FOR_SECOND_DIAM_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second end of the circle diameter: ")) self.step = 8 return False #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA SECONDA ESTREMITA' DIAM DEL CERCHIO (da step = 7) elif self.step == 8: # 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 snapTypeOnSel = self.getPointMapTool().snapTypeOnSelection value = self.getPointMapTool().point entity = self.getPointMapTool().entity else: # il punto arriva come parametro della funzione value = msg snapTypeOnSel = QadSnapTypeEnum.NONE # se é stato selezionato un punto con la modalità TAN_DEF é un punto differito if snapTypeOnSel == QadSnapTypeEnum.TAN_DEF and entity.isInitialized(): self.secondDiamPt = None self.secondDiamPtTan = value self.secondDiamGeomTan = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) # trasformo la geometria self.secondDiamGeomTan.transform(coordTransform) else: # altrimenti é un punto esplicito self.secondDiamPt = value circle = QadCircle() points = None if self.firstDiamPt is None: # se il diametro é definito con il primo punto differito if self.secondDiamPt is None: # il diametro é definito con il secondo punto differito if circle.fromDiamEnds2TanPts(self.firstDiamGeomTan, self.firstDiamPtTan, \ self.secondDiamGeomTan, self.secondDiamPtTan) == True: points = circle.asPolyline() else: # se il diametro è definito con il secondo punto esplicito if circle.fromDiamEndsPtTanPt(self.secondDiamPt, self.firstDiamGeomTan, self.firstDiamPtTan) == True: points = circle.asPolyline() else: # se il diametro è definito con il primo punto esplicito if self.secondDiamPt is None: # il diametro è definito con il secondo punto differito if circle.fromDiamEndsPtTanPt(self.firstDiamPt, self.secondDiamGeomTan, self.secondDiamPtTan) == True: points = circle.asPolyline() else: # se il diametro è definito con il secondo punto esplicito if circle.fromDiamEnds(self.firstDiamPt, self.secondDiamPt) == True: points = circle.asPolyline() if points is not None: self.centerPt = circle.center self.radius = circle.radius if self.virtualCmd == False: # se si vuole veramente salvare il cerchio in un layer if currLayer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, currLayer, points) else: qad_layer.addPolygonToLayer(self.plugIn, currLayer, points) return True # fine comand # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second end of the circle diameter: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMA TANGENTE (da step = 1) elif self.step == 9: # 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 entity = self.getPointMapTool().entity else: # il punto arriva come parametro della funzione # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify first tangent element of the circle: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False if not entity.isInitialized(): # se non è stata selezionata una entità # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify first tangent element of the circle: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False wkbType = entity.getGeometry().wkbType() if wkbType == QGis.WKBPoint or wkbType == QGis.WKBMultiPoint: self.showErr(QadMsg.translate("Command_CIRCLE", "\nSelect a circle, an arc or a line.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify first tangent element of the circle: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False self.tanGeom1 = QgsGeometry(entity.getGeometry()) coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) # trasformo la geometria self.tanGeom1.transform(coordTransform) self.tanPt1 = self.getPointMapTool().point # imposto il map tool self.getPointMapTool().tanGeom1 = self.tanGeom1 self.getPointMapTool().tanPt1 = self.tanPt1 self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_TAN_KNOWN_ASK_FOR_SECOND_TAN) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second tangent element of the circle: ")) self.step = 10 return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDA TANGENTE (da step = 9) elif self.step == 10: # 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 entity = self.getPointMapTool().entity else: # il punto arriva come parametro della funzione # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second tangent element of the circle: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False if not entity.isInitialized(): # se non è stata selezionata una entità # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second tangent element of the circle: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False wkbType = entity.getGeometry().wkbType() if wkbType == QGis.WKBPoint or wkbType == QGis.WKBMultiPoint: self.showErr(QadMsg.translate("Command_CIRCLE", "\nSelect a circle, an arc or a line.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second tangent element of the circle: ")) self.isValidPreviousInput = False # per gestire il comando anche in macro return False self.tanGeom2 = QgsGeometry(entity.getGeometry()) coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs()) # trasformo la geometria self.tanGeom2.transform(coordTransform) self.tanPt2 = self.getPointMapTool().point # imposto il map tool self.getPointMapTool().tanGeom2 = self.tanGeom2 self.getPointMapTool().tanPt2 = self.tanPt2 self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_SECOND_TAN_KNOWN_ASK_FOR_RADIUS) # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi msg = QadMsg.translate("Command_CIRCLE", "Specify the circle radius <{0}>: ") self.waitFor(msg.format(str(self.plugIn.lastRadius)), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ self.plugIn.lastRadius, "", \ QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.step = 11 return False #========================================================================= # RISPOSTA ALLA RICHIESTA RAGGIO (da step = 10) elif self.step == 11: # 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.startPtForRadius = value # imposto il map tool self.getPointMapTool().startPtForRadius = self.startPtForRadius self.getPointMapTool().setMode(Qad_circle_maptool_ModeEnum.FIRST_SECOND_TAN_FIRSTPTRADIUS_KNOWN_ASK_FOR_SECONDPTRADIUS) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_CIRCLE", "Specify second point: ")) self.step = 12 return False else: self.plugIn.setLastRadius(value) circle = QadCircle() if circle.from2TanPtsRadius(self.tanGeom1, self.tanPt1, \ self.tanGeom2, self.tanPt2, value) == True: points = circle.asPolyline() if points is not None: self.centerPt = circle.center self.radius = circle.radius if self.virtualCmd == False: # se si vuole veramente salvare il cerchio in un layer if currLayer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, currLayer, points) else: qad_layer.addPolygonToLayer(self.plugIn, currLayer, points) else: self.showMsg(QadMsg.translate("Command_CIRCLE", "\nThe circle doesn't exist.")) else: self.showMsg(QadMsg.translate("Command_CIRCLE", "\nThe circle doesn't exist.")) return True # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO DEL RAGGIO (da step = 11) 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 return True # fine comando else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg self.radius = qad_utils.getDistance(self.startPtForRadius, value) self.plugIn.setLastRadius(self.radius) circle = QadCircle() if circle.from2TanPtsRadius(self.tanGeom1, self.tanPt1, \ self.tanGeom2, self.tanPt2, self.radius) == True: points = circle.asPolyline() if points is not None: self.centerPt = circle.center self.radius = circle.radius if self.virtualCmd == False: # se si vuole veramente salvare il cerchio in un layer if currLayer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, currLayer, points) else: qad_layer.addPolygonToLayer(self.plugIn, currLayer, points) else: self.showMsg(QadMsg.translate("Command_CIRCLE", "\nThe circle doesn't exist.")) else: self.showMsg(QadMsg.translate("Command_CIRCLE", "\nThe circle doesn't exist.")) return True # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA AREA DEL CERCHIO (da step = 2) elif self.step == 13: # dopo aver atteso un numero 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 NON usato il tasto destro del mouse 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 circle = QadCircle() circle.fromCenterArea(self.centerPt, self.area) self.radius = circle.radius self.plugIn.setLastRadius(self.radius) points = circle.asPolyline() if points is not None: if self.virtualCmd == False: # se si vuole veramente salvare il cerchio in un layer if currLayer.geometryType() == QGis.Line: qad_layer.addLineToLayer(self.plugIn, currLayer, points) else: qad_layer.addPolygonToLayer(self.plugIn, currLayer, points) return True # fine comando self.isValidPreviousInput = False # per gestire il comando anche in macro return False