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 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.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