def rotate(self, basePt, angle):
# basePt = punto base espresso in map coordinate
# restituisce una feature ruotata
canvas = qgis.utils.iface.mapCanvas()
destinationCrs = canvas.mapSettings().destinationCrs()
f = self.getFeature()
g = g.geometry()
g.transform(QgsCoordinateTransform(self.crs(), destinationCrs))
# ruoto la feature
g = qad_utils.rotateQgsGeometry(g, basePt, angle)
g.transform(QgsCoordinateTransform(destinationCrs, self.crs()))
f.setGeometry(g)
rotFldName = ""
if self.getEntityType() == QadEntityGeomTypeEnum.TEXT:
# se la rotazione dipende da un solo campo
rotFldNames = qad_label.get_labelRotationFieldNames(self.layer)
if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0:
rotFldName = rotFldNames[0]
elif self.getEntityType() == QadEntityGeomTypeEnum.SYMBOL:
rotFldName = qad_layer.get_symbolRotationFieldName(self.layer)
if len(rotFldName) > 0:
rotValue = f.attribute(rotFldName)
# a volte vale None e a volte null (vai a capire...)
rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
rotValue = rotValue + angle
f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))
return f
开发者ID:geosim,项目名称:QAD,代码行数:31,代码来源:qad_entity.py
示例2: doMoveAndRotateGeom
def doMoveAndRotateGeom(plugIn, f, g, layer, offSetX, offSetY, angle, rotFldName, basePt, coordTransform, addToLayer, highlightObj):
# funzione di ausilio
newGeom = qad_utils.moveQgsGeometry(g, offSetX, offSetY)
if angle is not None:
newGeom = qad_utils.rotateQgsGeometry(newGeom, basePt, angle)
newGeom.transform(coordTransform)
if addToLayer:
newF = QgsFeature(f) # la copio perchè altrimenti qgis si incarta
newF.setGeometry(newGeom)
if len(rotFldName) > 0:
rotValue = newF.attribute(rotFldName)
# a volte vale None e a volte null (vai a capire...)
rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
rotValue = rotValue + angle
newF.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))
# plugIn, layer, feature, coordTransform, refresh, check_validity
if qad_layer.addFeatureToLayer(plugIn, layer, newF, None, False, False) == False:
return False
if highlightObj is not None:
highlightObj.addGeometry(newGeom, layer)
del newGeom
return True
def rotate(self, entity, basePt, angle, rotFldName):
# entity = entità da ruotare
# basePt = punto base
# angle = angolo di rotazione in gradi
# rotFldName = campo della tabella che memorizza la rotazione
# verifico se l'entità appartiene ad uno stile di quotatura
if entity.whatIs() == "ENTITY":
f = entity.getFeature()
# ruoto l'entità
f.setGeometry(qad_utils.rotateQgsGeometry(entity.getGeometry(), basePt, angle))
if len(rotFldName) > 0:
rotValue = f.attribute(rotFldName)
rotValue = 0 if rotValue is None else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
rotValue = rotValue + angle
f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))
if self.copyEntities == False:
# plugIn, layer, feature, refresh, check_validity
if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
return False
else:
# plugIn, layer, features, coordTransform, refresh, check_validity
if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
return False
elif entity.whatIs() == "DIMENTITY":
# stiro la quota
if self.copyEntities == False:
if entity.deleteToLayers(self.plugIn) == False:
return False
entity.rotate(self.plugIn, basePt, angle)
if entity.addToLayers(self.plugIn) == False:
return False
return True
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)
开发者ID:gam17,项目名称:QAD,代码行数:33,代码来源:qad_text_cmd.py
示例5: addFeature
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 waitForReferenceRot(self):
# imposto il map tool
self.getPointMapTool().setMode(Qad_rotate_maptool_ModeEnum.ASK_FOR_FIRST_PT_REFERENCE_ANG)
msg = QadMsg.translate("Command_GRIPROTATE", "Specify reference angle <{0}>: ")
# si appresta ad attendere un punto o enter o una parola chiave
# msg, inputType, default, keyWords, nessun controllo
self.waitFor(msg.format(str(qad_utils.toDegrees(self.plugIn.lastReferenceRot))), \
QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \
self.plugIn.lastReferenceRot, \
"")
self.step = 3
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.mapSettings().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 mirror(self, entity, pt1, pt2, rotFldName):
# entity = entità da specchiare
# pt1 e pt2 = linea di simmetria
# rotFldName = campo della tabella che memorizza la rotazione
# verifico se l'entità appartiene ad uno stile di quotatura
if entity.whatIs() == "ENTITY":
f = entity.getFeature()
# specchio l'entità
f.setGeometry(qad_utils.mirrorQgsGeometry(entity.getGeometry(), pt1, pt2))
if len(rotFldName) > 0:
rotValue = f.attribute(rotFldName)
# a volte vale None e a volte null (vai a capire...)
rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))
if self.copyEntities == False:
# plugIn, layer, feature, refresh, check_validity
if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
return False
else:
# plugIn, layer, features, coordTransform, refresh, check_validity
if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
return False
elif entity.whatIs() == "DIMENTITY":
mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
# specchio la quota
if self.copyEntities == False:
if entity.deleteToLayers(self.plugIn) == False:
return False
newDimEntity = QadDimEntity(entity) # la copio
newDimEntity.mirror(pt1, mirrorAngle)
if newDimEntity.addToLayers(self.plugIn) == False:
return False
return True
def rotate(self, f, basePt, angle, rotFldName, layerEntitySet, entitySet):
# verifico se l'entità appartiene ad uno stile di quotatura
dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())
if dimEntity is None:
# ruoto la feature e la rimuovo da entitySet (é la prima)
f.setGeometry(qad_utils.rotateQgsGeometry(f.geometry(), basePt, angle))
if len(rotFldName) > 0:
rotValue = f.attribute(rotFldName)
# a volte vale None e a volte null (vai a capire...)
rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
rotValue = rotValue + angle
f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))
if self.copyFeatures == False:
# plugIn, layer, feature, refresh, check_validity
if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
self.plugIn.destroyEditCommand()
return False
else:
# plugIn, layer, features, coordTransform, refresh, check_validity
if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:
self.plugIn.destroyEditCommand()
return False
del layerEntitySet.featureIds[0]
else:
# ruoto la quota e la rimuovo da entitySet
dimEntitySet = dimEntity.getEntitySet()
if self.copyFeatures == False:
if dimEntity.deleteToLayers(self.plugIn) == False:
return False
newDimEntity = QadDimEntity(dimEntity) # la copio
newDimEntity.rotate(basePt, angle)
if newDimEntity.addToLayers(self.plugIn) == False:
return False
entitySet.subtract(dimEntitySet)
return True
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
#.........这里部分代码省略.........
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}>: ")
#.........这里部分代码省略.........
#.........这里部分代码省略.........
if result is not None:
if (type(result) != list and type(result) != tuple): # se non é una lista di 2 punti
objType = result.whatIs()
if objType == "ARC": # se é arco
self.dimArc = result
return False
self.showMsg(QadMsg.translate("Command_DIM", "Select an arc."))
self.waitForEntsel(msgMapTool, msg)
else:
self.showMsg(QadMsg.translate("Command_DIM", "No geometries in this position."))
self.waitForEntsel(msgMapTool, msg)
return False # continua
#=========================================================================
# RISPOSTA ALLA RICHIESTA ORIGINE SECONDA LINEA DI ESTENSIONE (da step = 1)
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
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:
return True
if type(value) == QgsPoint: # se é stato inserito il secondo punto
self.dimPt2.set(value.x(), value.y())
self.waitForDimensionLinePos()
return False
#=========================================================================
# RISPOSTA ALLA RICHIESTA DELLA POSIZIONE DELLA LINEA DI QUOTA (da step = 2 e 3)
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
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_DIM", "Text") or value == "Text":
prompt = QadMsg.translate("Command_DIM", "Enter dimension text <{0}>: ")
dist = qad_utils.getDistance(self.dimPt1, self.dimPt2)
self.waitForString(prompt.format(str(dist)), dist)
self.getPointMapTool().setMode(Qad_dim_maptool_ModeEnum.ASK_FOR_TEXT)
self.step = 5
elif value == QadMsg.translate("Command_DIM", "Angle") or value == "Angle":
# si appresta ad attendere l'angolo di rotazione del testo
if self.GetAngleClass is not None:
del self.GetAngleClass
self.GetAngleClass = QadGetAngleClass(self.plugIn)
prompt = QadMsg.translate("Command_DIM", "Specify angle of dimension text <{0}>: ")
self.GetAngleClass.msg = prompt.format(str(qad_utils.toDegrees(self.dimStyle.textForcedRot)))
self.GetAngleClass.angle = self.dimStyle.textForcedRot
self.step = 6
self.GetAngleClass.run(msgMapTool, msg)
elif type(value) == QgsPoint: # se é stato inserito il punto di posizionamento linea quota
self.dimPt1 = self.getPointMapTool().dimPt1
self.dimPt2 = self.getPointMapTool().dimPt2
self.addDimToLayers(value)
return True # fine comando
return False
#=========================================================================
# RISPOSTA ALLA RICHIESTA DEL TESTO (da step = 4)
elif self.step == 5: # dopo aver atteso una stringa si riavvia il comando
if type(msg) == unicode:
text = msg.strip()
if len(text) > 0:
self.measure = text
self.getPointMapTool().measure = self.measure
self.waitForDimensionLinePos()
return False
#.........这里部分代码省略.........
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
请发表评论