def fromStartEndPtsTan(self, startPt, endPt, tan): """ setta le caratteristiche dell'arco attraverso: punto iniziale punto finale direzione della tangente sul punto iniziale """ if startPt == endPt: return False angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt) if tan == angleSegment or tan == angleSegment - math.pi: return False chord = qad_utils.getDistance(startPt, endPt) half_chord = chord / 2 ptMiddle = qad_utils.getMiddlePoint(startPt, endPt) angle = tan + (math.pi / 2) angle = angleSegment - angle distFromCenter = math.tan(angle) * half_chord self.center = qad_utils.getPolarPointByPtAngle(ptMiddle, angleSegment - (math.pi / 2), distFromCenter) pt = qad_utils.getPolarPointByPtAngle(startPt, tan, chord) if qad_utils.leftOfLine(endPt, startPt, pt) < 0: # arco si sviluppa a sinistra della tangente self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt) self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt) else: # arco si sviluppa a destra della tangente self.startAngle = qad_utils.getAngleBy2Pts(self.center, endPt) self.endAngle = qad_utils.getAngleBy2Pts(self.center, startPt) self.radius = qad_utils.getDistance(startPt, self.center) return True
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() result = False arc = QadArc() # noti il primo e il secondo punto dell'arco si richiede il terzo punto if self.mode == Qad_arc_maptool_ModeEnum.START_SECOND_PT_KNOWN_ASK_FOR_END_PT: result = arc.fromStartSecondEndPts(self.arcStartPt, self.arcSecondPt, self.tmpPoint) # noti il primo punto e il centro dell'arco si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_END_PT: result = arc.fromStartCenterEndPts(self.arcStartPt, self.arcCenterPt, self.tmpPoint) # noti il primo punto e il centro dell'arco si richiede l'angolo inscritto elif self.mode == Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_ANGLE: angle = qad_utils.getAngleBy2Pts(self.arcCenterPt, self.tmpPoint) result = arc.fromStartCenterPtsAngle(self.arcStartPt, self.arcCenterPt, angle) # noti il primo punto e il centro dell'arco si richiede la lunghezza della corda elif self.mode == Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_CHORD: chord = qad_utils.getDistance(self.arcStartPt, self.tmpPoint) result = arc.fromStartCenterPtsChord(self.arcStartPt, self.arcCenterPt, chord) # noti il punto iniziale e finale dell'arco si richiede il centro elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_CENTER: result = arc.fromStartCenterEndPts(self.arcStartPt, self.tmpPoint, self.arcEndPt) # noti il punto iniziale e finale dell'arco si richiede l'angolo inscritto elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_ANGLE: angle = qad_utils.getAngleBy2Pts(self.arcStartPt, self.tmpPoint) result = arc.fromStartEndPtsAngle(self.arcStartPt, self.arcEndPt, angle) # noti il punto iniziale e finale dell'arco si richiede la direzione della tangente elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_TAN: tan = qad_utils.getAngleBy2Pts(self.arcStartPt, self.tmpPoint) result = arc.fromStartEndPtsTan(self.arcStartPt, self.arcEndPt, tan) # noti il punto iniziale e finale dell'arco si richiede il raggio elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_RADIUS: radius = qad_utils.getDistance(self.arcEndPt, self.tmpPoint) result = arc.fromStartEndPtsRadius(self.arcStartPt, self.arcEndPt, radius) # noti il punto iniziale e la tangente al punto iniziale si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_TAN_KNOWN_ASK_FOR_END_PT: result = arc.fromStartEndPtsTan(self.arcStartPt, self.tmpPoint, self.arcTanOnStartPt) # noti il punto iniziale e l'angolo inscritto dell'arco si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_ANGLE_KNOWN_ASK_FOR_END_PT: result = arc.fromStartEndPtsAngle(self.arcStartPt, self.tmpPoint, self.arcAngle) # noti il punto iniziale e l'angolo inscritto dell'arco si richiede il centro elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_ANGLE_KNOWN_ASK_FOR_CENTER_PT: result = arc.fromStartCenterPtsAngle(self.arcStartPt, self.tmpPoint, self.arcAngle) # noti il punto iniziale, l'angolo inscritto e il raggio dell'arco si richiede la direzione della corda elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_ANGLE_RADIUS_KNOWN_ASK_FOR_CHORDDIRECTION: chordDirection = qad_utils.getAngleBy2Pts(self.arcStartPt, self.tmpPoint) result = arc.fromStartPtAngleRadiusChordDirection(self.arcStartPt, self.arcAngle, \ self.arcRadius, chordDirection) # noti il punto iniziale e il raggio dell'arco si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_RADIUS_KNOWN_ASK_FOR_END_PT: result = arc.fromStartEndPtsRadius(self.arcStartPt, self.tmpPoint, self.arcRadius) if result == True: points = arc.asPolyline() if points is not None: self.__rubberBand.setLine(points)
def setInfo(self, entity, point): # setta: self.layer, self.tmpLinearObjectList e self.move_startPt if self.tmpLinearObjectList is not None: del self.tmpLinearObjectList self.tmpLinearObjectList = None if entity.isInitialized() == False: return False self.layer = entity.layer transformedPt = self.canvas.mapSettings().mapToLayerCoordinates(self.layer, point) geom = entity.getGeometry() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, geom) if dummy[2] is None: return False # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) self.tmpLinearObjectList = qad_utils.QadLinearObjectList() self.tmpLinearObjectList.fromPolyline(subGeom.asPolyline()) if qad_utils.getDistance(self.tmpLinearObjectList.getStartPt(), transformedPt) <= \ qad_utils.getDistance(self.tmpLinearObjectList.getEndPt(), transformedPt): # si allunga/accorcia dal punto iniziale self.move_startPt = True else: # si allunga dal punto finale self.move_startPt = False return True
def setSelectedEntityGripPoints(self, entitySetGripPoints): # lista delle entityGripPoint con dei grip point selezionati # setta la prima entità con un grip selezionato self.entity = None for entityGripPoints in entitySetGripPoints.entityGripPoints: for gripPoint in entityGripPoints.gripPoints: # grip point selezionato if gripPoint.getStatus() == qad_grip.QadGripStatusEnum.SELECTED: # verifico se l'entità appartiene ad uno stile di quotatura if entityGripPoints.entity.isDimensionComponent(): return False if entityGripPoints.entity.getEntityType() != QadEntityGeomTypeEnum.ARC and \ entityGripPoints.entity.getEntityType() != QadEntityGeomTypeEnum.LINESTRING: return False # setta: self.entity, self.linearObjectList, self.atSubGeom e self.move_startPt self.entity = entityGripPoints.entity if self.linearObjectList is not None: del self.linearObjectList self.linearObjectList = None # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(self.entity.layer, self.entity.getGeometry()) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) res = False dummy = qad_utils.closestSegmentWithContext(gripPoint.getPoint(), geom) if dummy[2] is None: return False # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) subGeom, self.atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2]) self.linearObjectList = qad_utils.QadLinearObjectList() self.linearObjectList.fromPolyline(subGeom.asPolyline()) if qad_utils.getDistance(self.linearObjectList.getStartPt(), gripPoint.getPoint()) <= \ qad_utils.getDistance(self.linearObjectList.getEndPt(), gripPoint.getPoint()): # si allunga dal punto iniziale self.move_startPt = True else: # si allunga dal punto finale self.move_startPt = False # imposto il map tool if self.getPointMapTool().setInfo(self.entity, gripPoint.getPoint()) == False: return False return True return False
def fromStartEndPtsAngle(self, startPt, endPt, angle): """ setta le caratteristiche dell'arco attraverso: punto iniziale punto finale angolo inscritto """ if startPt == endPt or angle == 0: return False chord = qad_utils.getDistance(startPt, endPt) half_chord = chord / 2 # Teorema della corda self.radius = half_chord / math.sin(angle / 2) angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt) ptMiddle = qad_utils.getMiddlePoint(startPt, endPt) # Pitagora distFromCenter = math.sqrt((self.radius * self.radius) - (half_chord * half_chord)) if angle < math.pi: # se angolo < 180 gradi # aggiungo 90 gradi per cercare il centro a sinistra del segmento self.center = qad_utils.getPolarPointByPtAngle( ptMiddle, angleSegment + (math.pi / 2), distFromCenter) else: # sottraggo 90 gradi per cercare il centro a destra del segmento self.center = qad_utils.getPolarPointByPtAngle( ptMiddle, angleSegment - (math.pi / 2), distFromCenter) self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt) self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt) return True
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) # noto il punto base si richiede il secondo punto per il raggio if self.mode == Qad_gripChangeArcRadius_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_RADIUS_PT: radius = qad_utils.getDistance(self.basePt, self.tmpPoint) self.changeRadius(radius)
def fromStartEndPtsAngle(self, startPt, endPt, angle): """ setta le caratteristiche dell'arco attraverso: punto iniziale punto finale angolo inscritto """ if startPt == endPt or angle == 0: return False chord = qad_utils.getDistance(startPt, endPt) half_chord = chord / 2 # Teorema della corda self.radius = half_chord / math.sin(angle / 2) angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt) ptMiddle = qad_utils.getMiddlePoint(startPt, endPt) # Pitagora distFromCenter = math.sqrt((self.radius * self.radius) - (half_chord * half_chord)) if angle < math.pi: # se angolo < 180 gradi # aggiungo 90 gradi per cercare il centro a sinistra del segmento self.center = qad_utils.getPolarPointByPtAngle(ptMiddle, angleSegment + (math.pi / 2), distFromCenter) else: # sottraggo 90 gradi per cercare il centro a destra del segmento self.center = qad_utils.getPolarPointByPtAngle(ptMiddle, angleSegment - (math.pi / 2), distFromCenter) self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt) self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt) return True
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() # noto il primo punto si richiede la larghezza del buffer if self.mode == Qad_mbuffer_maptool_ModeEnum.FIRST_PT_ASK_FOR_BUFFER_WIDTH: width = qad_utils.getDistance(self.startPtForBufferWidth, self.tmpPoint) tolerance = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) for layerEntitySet in self.entitySet.layerEntitySetList: layer = layerEntitySet.layer geoms = layerEntitySet.getGeometryCollection() for geom in geoms: # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy newGeom = self.layerToMapCoordinates(layer, geom) bufferGeom = qad_utils.ApproxCurvesOnGeom(newGeom.buffer(width, self.segments), \ self.segments, self.segments, \ tolerance) if bufferGeom: # trasformo la geometria nel crs del layer self.__rubberBand.addGeometry( self.mapToLayerCoordinates(layer, bufferGeom), layer)
def arrayPolarEntity(plugIn, ent, basePt, centerPt, itemsNumber, angleBetween, rows, distanceBetweenRows, itemsRotation, \ addToLayer, highlightObj): """ serie polare ent = entità QAD di cui fare la serie (QadEntity o QadDimEntity) basePt = punto base in map coordinate (QgsPoint) centerPt = punto centrale in map coordinate (QgsPoint) itemsNumber = numero di copie da fare angleBetween = angolo tra un elemento e l'altro (radianti) rows = numero di righe distanceBetweenRows = distanza tra le righe in map coordinate itemsRotation = True se si vuole ruotare gli elementi intorno al cerchio addToLayer = se è True aggiunge le nuove entità al layer highlightObj = se è diverso da None vengono aggiunge le geometrie all'oggetto QadHighlight """ g = None coordTransform = None f = None if ent.whatIs() == "ENTITY": f = ent.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy CRS = qgis.utils.iface.mapCanvas().mapSettings().destinationCrs() # CRS corrente coordTransform = QgsCoordinateTransform(ent.crs(), CRS) g = f.geometry() g.transform(coordTransform) coordTransform = QgsCoordinateTransform(CRS, ent.crs()) rotFldName = "" if ent.getEntityType() == QadEntityGeomTypeEnum.TEXT: # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(ent.layer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: rotFldName = rotFldNames[0] elif ent.getEntityType() == QadEntityGeomTypeEnum.SYMBOL: rotFldName = qad_layer.get_symbolRotationFieldName(ent.layer) firstAngle = qad_utils.getAngleBy2Pts(centerPt, basePt) dist = qad_utils.getDistance(centerPt, basePt) for row in range(0, rows): angle = firstAngle for i in range(0, itemsNumber): newBasePt = qad_utils.getPolarPointByPtAngle(centerPt, angle, dist) offSetX = newBasePt.x() - basePt.x() offSetY = newBasePt.y() - basePt.y() if g is not None: # se l'entità non è una quotatura if doMoveAndRotateGeom(plugIn, f, g, ent.layer, offSetX, offSetY, \ i * angleBetween if itemsRotation else None, rotFldName, \ newBasePt, coordTransform, addToLayer, highlightObj) == False: return False else: # se l'entità è una quotatura if doMoveAndRotateDimEntity(plugIn, ent, offSetX, offSetY, \ i * angleBetween if itemsRotation else None, \ newBasePt, addToLayer, highlightObj) == False: return False angle = angle + angleBetween dist = dist + distanceBetweenRows return True
def gripStretchCircle(circle, basePt, ptListToStretch, offSetX, offSetY, tolerance2ApproxCurve): """ Stira i punti di grip di un cerchio che sono contenuti in ptListToStretch circle = cerchio da stirare basePt = punto base ptListToStretch = lista dei punti da stirare offSetX = spostamento X offSetY = spostamento Y """ if tolerance2ApproxCurve == None: tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) else: tolerance = tolerance2ApproxCurve newCenter = QgsPoint(circle.center) newRadius = circle.radius for ptToStretch in ptListToStretch: if qad_utils.ptNear(ptToStretch, circle.center): # se i punti sono sufficientemente vicini newCenter.set(circle.center.x() + offSetX, circle.center.y() + offSetY) elif circle.isPtOnCircle(ptToStretch): newPt = QgsPoint(basePt.x() + offSetX, basePt.y() + offSetY) newRadius = qad_utils.getDistance(circle.center, newPt) newCircle = qad_circle.QadCircle() if newCircle.set(newCenter, newRadius) == False: return None return newCircle
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() result = False del self.vertices[:] # svuoto la lista if self.mode is not None: # noto il centro si richiede il raggio if self.mode == Qad_polygon_maptool_ModeEnum.CENTER_PT_KNOWN_ASK_FOR_RADIUS: radius = qad_utils.getDistance(self.centerPt, self.tmpPoint) InscribedOption = True if self.constructionModeByCenter == QadMsg.translate( "Command_POLYGON", "Inscribed in circle") else False self.vertices.extend(qad_utils.getPolygonByNsidesCenterRadius(self.sideNumber, self.centerPt, radius, \ InscribedOption, self.tmpPoint)) result = True # si richiede il secondo punto dello spigolo elif self.mode == Qad_polygon_maptool_ModeEnum.FIRST_EDGE_PT_KNOWN_ASK_FOR_SECOND_EDGE_PT: self.vertices.extend(qad_utils.getPolygonByNsidesEdgePts(self.sideNumber, self.firstEdgePt, \ self.tmpPoint)) result = True if result == True: if self.vertices is not None: if self.geomType == QGis.Polygon: self.__rubberBand.setPolygon(self.vertices) else: self.__rubberBand.setLine(self.vertices)
def fromStartEndPtsRadius(self, startPt, endPt, radius): """ setta le caratteristiche dell'arco attraverso: punto iniziale punto finale raggio """ if startPt == endPt or radius <= 0: return False chord = qad_utils.getDistance(startPt, endPt) half_chord = chord / 2 if radius < half_chord: return False self.radius = radius angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt) ptMiddle = qad_utils.getMiddlePoint(startPt, endPt) # Pitagora distFromCenter = math.sqrt((self.radius * self.radius) - (half_chord * half_chord)) # aggiungo 90 gradi self.center = qad_utils.getPolarPointByPtAngle(ptMiddle, angleSegment + (math.pi / 2), distFromCenter) self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt) self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt) return True
def isPtOnArc(self, point): dist = qad_utils.getDistance(self.center, point) if qad_utils.doubleNear(self.radius, dist): angle = qad_utils.getAngleBy2Pts(self.center, point) return qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) else: return False
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() result = False del self.vertices[:] # svuoto la lista if self.mode is not None: # noto il centro si richiede il raggio if self.mode == Qad_polygon_maptool_ModeEnum.CENTER_PT_KNOWN_ASK_FOR_RADIUS: radius = qad_utils.getDistance(self.centerPt, self.tmpPoint) InscribedOption = True if self.constructionModeByCenter == QadMsg.translate("Command_POLYGON", "Inscribed in circle") else False self.vertices.extend(qad_utils.getPolygonByNsidesCenterRadius(self.sideNumber, self.centerPt, radius, \ InscribedOption, self.tmpPoint)) result = True # si richiede il secondo punto dello spigolo elif self.mode == Qad_polygon_maptool_ModeEnum.FIRST_EDGE_PT_KNOWN_ASK_FOR_SECOND_EDGE_PT: self.vertices.extend(qad_utils.getPolygonByNsidesEdgePts(self.sideNumber, self.firstEdgePt, \ self.tmpPoint)) result = True if result == True: if self.vertices is not None: if self.geomType == QGis.Polygon: self.__rubberBand.setPolygon(self.vertices) else: self.__rubberBand.setLine(self.vertices)
def fromStartEndPtsRadius(self, startPt, endPt, radius): """ setta le caratteristiche dell'arco attraverso: punto iniziale punto finale raggio """ if startPt == endPt or radius <= 0: return False chord = qad_utils.getDistance(startPt, endPt) half_chord = chord / 2 if radius < half_chord: return False self.radius = radius angleSegment = qad_utils.getAngleBy2Pts(startPt, endPt) ptMiddle = qad_utils.getMiddlePoint(startPt, endPt) # Pitagora distFromCenter = math.sqrt((self.radius * self.radius) - (half_chord * half_chord)) # aggiungo 90 gradi self.center = qad_utils.getPolarPointByPtAngle( ptMiddle, angleSegment + (math.pi / 2), distFromCenter) self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt) self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt) return True
def addFeatureCache(self, newPt): featureCacheLen = len(self.featureCache) layer = self.entity.layer f = self.entity.getFeature() transformedPt = self.mapToLayerCoordinates(layer, newPt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ transformedPt) offSetDistance = qad_utils.getDistance(transformedPt, pt) else: offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \ self.plugIn.canvas,\ layer) if self.multi == True: if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide self.lastOffSetOnLeftSide = offSetDistance self.getPointMapTool().lastOffSetOnLeftSide = self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide self.lastOffSetOnRightSide = offSetDistance self.getPointMapTool().lastOffSetOnRightSide = self.lastOffSetOnRightSide tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ layer) epsg = layer.crs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) added = False for line in lines: if layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) if offsetGeom.type() == QGis.Line or offsetGeom.type() == QGis.Polygon: offsetFeature = QgsFeature(f) offsetFeature.setGeometry(offsetGeom) self.featureCache.append([layer, offsetFeature]) self.addFeatureToRubberBand(layer, offsetFeature) added = True if added: self.undoFeatureCacheIndexes.append(featureCacheLen)
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) # noto il punto base si richiede il secondo punto per la scala if self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_SCALE_PT: scale = qad_utils.getDistance(self.basePt, self.tmpPoint) self.addScaledGeometries(scale) # noto il primo punto si richiede il secondo punto per la lunghezza di riferimento elif self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_LEN_PT: len = qad_utils.getDistance(self.basePt, self.tmpPoint) scale = len / self.ReferenceLen self.addScaledGeometries(scale) # noto il primo punto si richiede il secondo punto per la nuova lunghezza elif self.mode == Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT: len = qad_utils.getDistance(self.Pt1NewLen, self.tmpPoint) scale = len / self.ReferenceLen self.addScaledGeometries(scale)
def addFeatureCache(self, newPt): featureCacheLen = len(self.featureCache) layer = self.entity.layer f = self.entity.getFeature() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ newPt) offSetDistance = qad_utils.getDistance(newPt, pt) else: offSetDistance = self.offSet if self.multi == True: if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide self.lastOffSetOnLeftSide = offSetDistance self.getPointMapTool().lastOffSetOnLeftSide = self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide self.lastOffSetOnRightSide = offSetDistance self.getPointMapTool().lastOffSetOnRightSide = self.lastOffSetOnRightSide tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.plugIn.canvas.mapSettings().destinationCrs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) added = False for line in lines: if layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) if offsetGeom.type() == QGis.Line or offsetGeom.type() == QGis.Polygon: offsetFeature = QgsFeature(f) # trasformo la geometria nel crs del layer offsetFeature.setGeometry(self.mapToLayerCoordinates(layer, offsetGeom)) self.featureCache.append([layer, offsetFeature]) self.addFeatureToRubberBand(layer, offsetFeature) added = True if added: self.undoFeatureCacheIndexes.append(featureCacheLen)
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() result = False circle = QadCircle() # noto il centro del cerchio si richiede il raggio if self.mode == Qad_circle_maptool_ModeEnum.CENTER_PT_KNOWN_ASK_FOR_RADIUS: radius = qad_utils.getDistance(self.centerPt, self.tmpPoint) circle.set(self.centerPt, radius) result = True # noto il centro del cerchio si richiede il diametro elif self.mode == Qad_circle_maptool_ModeEnum.CENTER_PT_KNOWN_ASK_FOR_DIAM: diam = qad_utils.getDistance(self.centerPt, self.tmpPoint) result = circle.set(self.centerPt, diam / 2) result = True # noto il primo e il secondo punto si richiede il terzo punto elif self.mode == Qad_circle_maptool_ModeEnum.FIRST_SECOND_PT_KNOWN_ASK_FOR_THIRD_PT: if (self.firstPt is not None) and (self.secondPt is not None): result = circle.from3Pts(self.firstPt, self.secondPt, self.tmpPoint) # noto il primo punto di estremità diam si richiede il secondo punto di estremità diam elif self.mode == Qad_circle_maptool_ModeEnum.FIRST_DIAM_PT_KNOWN_ASK_FOR_SECOND_DIAM_PT: if self.firstDiamPt is not None: result = circle.fromDiamEnds(self.firstDiamPt, self.tmpPoint) # noto note la prima, la seconda entita dei punti di tangenza e il primo punto per misurare il raggio # si richiede il secondo punto per misurare il raggio elif self.mode == Qad_circle_maptool_ModeEnum.FIRST_SECOND_TAN_FIRSTPTRADIUS_KNOWN_ASK_FOR_SECONDPTRADIUS: radius = qad_utils.getDistance(self.startPtForRadius, self.tmpPoint) result = circle.from2TanPtsRadius(self.tanGeom1, self.tanPt1, \ self.tanGeom2, self.tanPt2, radius) if result == True: points = circle.asPolyline() if points is not None: if self.geomType == QGis.Polygon: self.__rubberBand.setPolygon(points) else: self.__rubberBand.setLine(points)
def fromStartCenterEndPts(self, startPt, centerPt, endPt): """ setta le caratteristiche dell'arco attraverso: punto iniziale centro punto finale """ if startPt == centerPt or startPt == endPt or endPt == centerPt: return False self.center = centerPt self.radius = qad_utils.getDistance(centerPt, startPt) self.startAngle = qad_utils.getAngleBy2Pts(centerPt, startPt) self.endAngle = qad_utils.getAngleBy2Pts(centerPt, endPt) return True
def fromStartCenterPtsAngle(self, startPt, centerPt, angle): """ setta le caratteristiche dell'arco attraverso: punto iniziale centro angolo inscritto """ if startPt == centerPt or angle == 0: return False self.center = centerPt self.radius = qad_utils.getDistance(centerPt, startPt) self.startAngle = qad_utils.getAngleBy2Pts(centerPt, startPt) self.endAngle = self.startAngle + angle if self.endAngle > math.pi * 2: self.endAngle = self.endAngle % (math.pi * 2) # modulo return True
def addOffSetGeometries(self, newPt): self.__rubberBand.reset() transformedPt = self.plugIn.canvas.mapRenderer().mapToLayerCoordinates(self.layer, newPt) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ transformedPt) offSetDistance = qad_utils.getDistance(transformedPt, pt) else: offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \ self.plugIn.canvas,\ self.layer) if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.plugIn.canvas,\ self.layer) epsg = self.layer.crs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) for line in lines: if self.layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) self.__rubberBand.addGeometry(offsetGeom, self.layer)
def fromStartCenterPtsChord(self, startPt, centerPt, chord): """ setta le caratteristiche dell'arco attraverso: punto iniziale centro lunghezza dela corda tra punto iniziale e finale """ if startPt == centerPt or chord == 0: return False self.center = centerPt self.radius = qad_utils.getDistance(centerPt, startPt) if chord > 2 * self.radius: return False self.startAngle = qad_utils.getAngleBy2Pts(centerPt, startPt) # Teorema della corda angle = 2 * math.asin(chord / (2 * self.radius)) self.endAngle = self.startAngle + angle return True
def addOffSetGeometries(self, newPt): self.__highlight.reset() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ newPt) offSetDistance = qad_utils.getDistance(newPt, pt) else: offSetDistance = self.offSet if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide tolerance2ApproxCurve = QadVariables.get( QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.canvas.mapRenderer().destinationCrs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) for line in lines: if self.layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) self.__highlight.addGeometry( self.mapToLayerCoordinates(self.layer, offsetGeom), self.layer)
def addOffSetGeometries(self, newPt): self.__highlight.reset() # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom) if self.offSet < 0: afterVertex = dummy[2] pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \ self.subGeom.vertexAt(afterVertex), \ newPt) offSetDistance = qad_utils.getDistance(newPt, pt) else: offSetDistance = self.offSet if dummy[3] < 0: # alla sinistra offSetDistance = offSetDistance + self.lastOffSetOnLeftSide else: # alla destra offSetDistance = offSetDistance + self.lastOffSetOnRightSide tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) # uso il crs del canvas per lavorare con coordinate piane xy epsg = self.canvas.mapSettings().destinationCrs().authid() lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \ offSetDistance, \ "left" if dummy[3] < 0 else "right", \ self.gapType, \ tolerance2ApproxCurve) for line in lines: if self.layer.geometryType() == QGis.Polygon: if line[0] == line[-1]: # se é una linea chiusa offsetGeom = QgsGeometry.fromPolygon([line]) else: offsetGeom = QgsGeometry.fromPolyline(line) else: offsetGeom = QgsGeometry.fromPolyline(line) self.__highlight.addGeometry(self.mapToLayerCoordinates(self.layer, offsetGeom), self.layer)
def fromStartCenterPtsLength(self, startPt, centerPt, length): """ setta le caratteristiche dell'arco attraverso: punto iniziale centro lunghezza dela corda tra punto iniziale e finale """ if startPt == centerPt or chord == 0: return False self.center = centerPt self.radius = qad_utils.getDistance(centerPt, startPt) circumference = 2 * math.pi * self.radius if length >= circumference: return False self.startAngle = qad_utils.getAngleBy2Pts(centerPt, startPt) #circumference : math.pi * 2 = length : angle angle = (math.pi * 2) * length / circumference self.endAngle = self.startAngle + angle return True
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() # noto il primo punto si richiede la larghezza del buffer if self.mode == Qad_mbuffer_maptool_ModeEnum.FIRST_PT_ASK_FOR_BUFFER_WIDTH: for layerEntitySet in self.entitySet.layerEntitySetList: transformedPt1 = self.canvas.mapRenderer().mapToLayerCoordinates(layerEntitySet.layer, self.startPtForBufferWidth) transformedPt2 = self.canvas.mapRenderer().mapToLayerCoordinates(layerEntitySet.layer, self.tmpPoint) width = qad_utils.getDistance(transformedPt1, transformedPt2) tolerance = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \ self.canvas,\ layerEntitySet.layer) geoms = layerEntitySet.getGeometryCollection() for geom in geoms: bufferGeom = qad_utils.ApproxCurvesOnGeom(geom.buffer(width, self.segments), \ self.segments, self.segments, \ tolerance) if bufferGeom: self.__rubberBand.addGeometry(bufferGeom, layerEntitySet.layer)
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() # noto il primo punto si richiede la larghezza del buffer if self.mode == Qad_mbuffer_maptool_ModeEnum.FIRST_PT_ASK_FOR_BUFFER_WIDTH: width = qad_utils.getDistance(self.startPtForBufferWidth, self.tmpPoint) tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) for layerEntitySet in self.entitySet.layerEntitySetList: layer = layerEntitySet.layer geoms = layerEntitySet.getGeometryCollection() for geom in geoms: # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy newGeom = self.layerToMapCoordinates(layer, geom) bufferGeom = qad_utils.ApproxCurvesOnGeom(newGeom.buffer(width, self.segments), \ self.segments, self.segments, \ tolerance) if bufferGeom: # trasformo la geometria nel crs del layer self.__rubberBand.addGeometry(self.mapToLayerCoordinates(layer, bufferGeom), layer)
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
def arrayPolarEntity(plugIn, ent, basePt, centerPt, itemsNumber, angleBetween, rows, distanceBetweenRows, itemsRotation, \ addToLayer, highlightObj): """ serie polare ent = entità QAD di cui fare la serie (QadEntity o QadDimEntity) basePt = punto base in map coordinate (QgsPoint) centerPt = punto centrale in map coordinate (QgsPoint) itemsNumber = numero di copie da fare angleBetween = angolo tra un elemento e l'altro (radianti) rows = numero di righe distanceBetweenRows = distanza tra le righe in map coordinate itemsRotation = True se si vuole ruotare gli elementi intorno al cerchio addToLayer = se è True aggiunge le nuove entità al layer highlightObj = se è diverso da None vengono aggiunge le geometrie all'oggetto QadHighlight """ g = None coordTransform = None f = None if ent.whatIs() == "ENTITY": f = ent.getFeature() # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy CRS = qgis.utils.iface.mapCanvas().mapSettings().destinationCrs( ) # CRS corrente coordTransform = QgsCoordinateTransform(ent.crs(), CRS) g = f.geometry() g.transform(coordTransform) coordTransform = QgsCoordinateTransform(CRS, ent.crs()) rotFldName = "" if ent.getEntityType() == QadEntityGeomTypeEnum.TEXT: # se la rotazione dipende da un solo campo rotFldNames = qad_label.get_labelRotationFieldNames(ent.layer) if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0: rotFldName = rotFldNames[0] elif ent.getEntityType() == QadEntityGeomTypeEnum.SYMBOL: rotFldName = qad_layer.get_symbolRotationFieldName(ent.layer) firstAngle = qad_utils.getAngleBy2Pts(centerPt, basePt) dist = qad_utils.getDistance(centerPt, basePt) for row in range(0, rows): angle = firstAngle for i in range(0, itemsNumber): newBasePt = qad_utils.getPolarPointByPtAngle(centerPt, angle, dist) offSetX = newBasePt.x() - basePt.x() offSetY = newBasePt.y() - basePt.y() if g is not None: # se l'entità non è una quotatura if doMoveAndRotateGeom(plugIn, f, g, ent.layer, offSetX, offSetY, \ i * angleBetween if itemsRotation else None, rotFldName, \ newBasePt, coordTransform, addToLayer, highlightObj) == False: return False else: # se l'entità è una quotatura if doMoveAndRotateDimEntity(plugIn, ent, offSetX, offSetY, \ i * angleBetween if itemsRotation else None, \ newBasePt, addToLayer, highlightObj) == False: return False angle = angle + angleBetween dist = dist + distanceBetweenRows return True
def fromPolyline(self, points, startVertex, atLeastNSegment=None): """ setta le caratteristiche del primo arco incontrato nella lista di punti partendo dalla posizione startVertex (0-indexed) ritorna la posizione nella lista del punto iniziale e finale se é stato trovato un arco altrimenti None N.B. in punti NON devono essere in coordinate geografiche """ if atLeastNSegment is None: _atLeastNSegment = QadVariables.get( QadMsg.translate("Environment variables", "ARCMINSEGMENTQTY"), 12) else: _atLeastNSegment = atLeastNSegment totPoints = len(points) # perché sia un arco ci vogliono almeno _atLeastNSegment segmenti if (totPoints - 1) - startVertex < _atLeastNSegment or _atLeastNSegment < 2: return None # per problemi di approssimazione dei calcoli epsilon = 1.e-4 # percentuale del raggio per ottenere max diff. di una distanza con il raggio InfinityLinePerpOnMiddle1 = None InfinityLinePerpOnMiddle2 = None nSegment = 0 i = startVertex while i < totPoints - 1: if InfinityLinePerpOnMiddle1 is None: InfinityLinePerpOnMiddle1 = qad_utils.getInfinityLinePerpOnMiddle( points[i], points[i + 1]) nStartVertex = i nSegment = 1 i = i + 1 continue elif InfinityLinePerpOnMiddle2 is None: InfinityLinePerpOnMiddle2 = qad_utils.getInfinityLinePerpOnMiddle( points[i], points[i + 1]) if InfinityLinePerpOnMiddle2 is None: InfinityLinePerpOnMiddle1 = None nSegment = 0 else: # calcolo il presunto centro con 2 segmenti center = qad_utils.getIntersectionPointOn2InfinityLines(InfinityLinePerpOnMiddle1[0], \ InfinityLinePerpOnMiddle1[1], \ InfinityLinePerpOnMiddle2[0], \ InfinityLinePerpOnMiddle2[1]) if center is None: # linee parallele InfinityLinePerpOnMiddle1 = InfinityLinePerpOnMiddle2 InfinityLinePerpOnMiddle2 = None nStartVertex = i nSegment = 1 else: nSegment = nSegment + 1 radius = qad_utils.getDistance( center, points[i + 1]) # calcolo il presunto raggio tolerance = radius * epsilon # calcolo il verso dell'arco e l'angolo dell'arco # se un punto intermedio dell'arco è a sinistra del # segmento che unisce i due punti allora il verso è antiorario startClockWise = True if qad_utils.leftOfLine( points[i], points[i - 1], points[i + 1]) < 0 else False angle = qad_utils.getAngleBy3Pts( points[i - 1], center, points[i + 1], startClockWise) prevInfinityLinePerpOnMiddle = InfinityLinePerpOnMiddle2 else: # e sono già stati valutati almeno 2 segmenti notInArc = False currInfinityLinePerpOnMiddle = qad_utils.getInfinityLinePerpOnMiddle( points[i], points[i + 1]) if currInfinityLinePerpOnMiddle is None: notInArc = True else: # calcolo il presunto centro con 2 segmenti currCenter = qad_utils.getIntersectionPointOn2InfinityLines(prevInfinityLinePerpOnMiddle[0], \ prevInfinityLinePerpOnMiddle[1], \ currInfinityLinePerpOnMiddle[0], \ currInfinityLinePerpOnMiddle[1]) if currCenter is None: # linee parallele notInArc = True else: # calcolo il verso dell'arco e l'angolo clockWise = True if qad_utils.leftOfLine( points[i], points[i - 1], points[i + 1]) < 0 else False angle = angle + qad_utils.getAngleBy3Pts( points[i], center, points[i + 1], startClockWise) # se la distanza è così vicina a quella del raggio # il verso dell'arco deve essere quello iniziale # l'angolo dell'arco non può essere >= 360 gradi if qad_utils.ptNear(center, currCenter, tolerance) and \ startClockWise == clockWise and \ angle < 2 * math.pi: nSegment = nSegment + 1 # anche questo segmento fa parte dell'arco prevInfinityLinePerpOnMiddle = currInfinityLinePerpOnMiddle else: notInArc = True # questo segmento non fa parte del cerchio if notInArc: # se sono stati trovati un numero sufficiente di segmenti successivi if nSegment >= _atLeastNSegment: # se é un angolo giro e il primo punto = ultimo punto allora points é un cerchio if qad_utils.doubleNear( angle, 2 * math.pi) and points[0] == points[-1]: return None break else: i = i - 2 InfinityLinePerpOnMiddle1 = None InfinityLinePerpOnMiddle2 = None i = i + 1 # se sono stati trovati un numero sufficiente di segmenti successivi if nSegment >= _atLeastNSegment: nEndVertex = nStartVertex + nSegment # se il punto iniziale e quello finale non coincidono é un arco if points[nStartVertex] != points[nEndVertex]: self.center = center self.radius = radius # se il verso é orario if startClockWise: # inverto l'angolo iniziale con quello finale self.endAngle = qad_utils.getAngleBy2Pts( center, points[nStartVertex]) self.startAngle = qad_utils.getAngleBy2Pts( center, points[nEndVertex]) else: self.startAngle = qad_utils.getAngleBy2Pts( center, points[nStartVertex]) self.endAngle = qad_utils.getAngleBy2Pts( center, points[nEndVertex]) return nStartVertex, nEndVertex return None
def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # fine comando currLayer = None if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer # il layer corrente deve essere editabile e di tipo linea o poligono currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, [QGis.Line, QGis.Polygon]) if currLayer is None: self.showErr(errMsg) return True # fine comando #========================================================================= # RICHIESTA NUMERO DI LATI DEL POLIGONO if self.step == 0: # inizio del comando self.WaitForSideNumber() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL NUMERO DI LATI DEL POLIGONO (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 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse value = self.sideNumber else: return False else: # il punto arriva come parametro della funzione value = msg if type(value) == int: if value < 3: self.showErr(QadMsg.translate("Command_POLYGON", "\nEnter an integer greater than 2.")) else: self.sideNumber = value self.getPointMapTool().sideNumber = self.sideNumber self.plugIn.setLastPolygonSideNumber(self.sideNumber) self.WaitForCenter() else: self.WaitForSideNumber() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL CENTRO DEL POLIGONO (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.WaitForCenter() 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_POLYGON", "Edge") or value == "Edge": self.WaitForFirstEdgePt() elif type(value) == QgsPoint: self.centerPt = value self.getPointMapTool().centerPt = self.centerPt self.WaitForInscribedCircumscribedOption() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DI POLIGONO INSCRITTO O CIRCOSCRITTO (da step = 2) elif self.step == 3: 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.constructionModeByCenter else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # la parola chiave arriva come parametro della funzione value = msg if type(value) == unicode: self.constructionModeByCenter = value self.plugIn.setLastPolygonConstructionModeByCenter(self.constructionModeByCenter) self.getPointMapTool().constructionModeByCenter = self.constructionModeByCenter if self.constructionModeByCenter == QadMsg.translate("Command_POLYGON", "Area") or self.constructionModeByCenter == "Area": self.WaitForArea() else: self.WaitForRadius(currLayer) return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO (da step = 3) elif self.step == 4: 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 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) ptStart = value else: self.radius = value ptStart = None self.plugIn.setLastRadius(self.radius) if self.constructionModeByCenter == QadMsg.translate("Command_POLYGON", "Inscribed in circle") or \ self.constructionModeByCenter == "Inscribed in circle": mode = True else: mode = False self.vertices.extend(qad_utils.getPolygonByNsidesCenterRadius(self.sideNumber, self.centerPt, self.radius, \ mode, ptStart)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addPolygonToLayer(currLayer) return True return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DELLO SPIGOLO (da step = 2) 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 value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.firstEdgePt = value self.WaitForSecondEdgePt(currLayer) return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DELLO SPIGOLO (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.vertices.extend(qad_utils.getPolygonByNsidesEdgePts(self.sideNumber, self.firstEdgePt, value)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addPolygonToLayer(currLayer) return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA AREA POLIGONO (da step = 3) elif self.step == 7: # dopo aver atteso un numero reale si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse value = self.area else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: return False else: # il punto arriva come parametro della funzione value = msg if type(value) == float: # é stata inserita l'area self.vertices.extend(qad_utils.getPolygonByNsidesArea(self.sideNumber, self.centerPt, value)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addPolygonToLayer(currLayer) return True return False
def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando currLayer = None if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer # il layer corrente deve essere editabile e di tipo linea o poligono currLayer, errMsg = qad_layer.getCurrLayerEditable( self.plugIn.canvas, [QGis.Line, QGis.Polygon]) if currLayer is None: self.showErr(errMsg) return True # fine comando # il layer corrente non deve appartenere a quotature dimStyleList = QadDimStyles.getDimListByLayer(currLayer) if len(dimStyleList) > 0: dimStyleNames = "" for i in xrange(0, len(dimStyleList), 1): if i > 0: dimStyleNames += ", " dimStyleNames += dimStyleList[i].name errMsg = QadMsg.translate( "QAD", "\nCurrent layer is a layer referenced to {0} dimension style and it is not valid.\n" ) self.showErr(errMsg.format(dimStyleNames)) return True # fine comando #========================================================================= # RICHIESTA SELEZIONE OGGETTI if self.step == 0: # inizio del comando if self.SSGetClass.run(msgMapTool, msg) == True: # selezione terminata self.step = 1 self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di selezione entità return self.run(msgMapTool, msg) #========================================================================= # BUFFER OGGETTI elif self.step == 1: self.entitySet.set(self.SSGetClass.entitySet) if self.entitySet.count() == 0: return True # fine comando # imposto il map tool self.getPointMapTool().setMode( Qad_mbuffer_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_PT) if currLayer is not None: self.getPointMapTool( ).geomType = QGis.Line if currLayer.geometryType( ) == QGis.Line else QGis.Polygon # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi msg = QadMsg.translate("Command_MBUFFER", "Specify the buffer length <{0}>: ") self.waitFor(msg.format(str(self.plugIn.lastRadius)), \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ self.plugIn.lastRadius, "", \ QadInputModeEnum.NOT_NULL | QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE) self.step = 2 return False #========================================================================= # RISPOSTA ALLA RICHIESTA LARGHEZZA (da step = 1) elif self.step == 2: # dopo aver atteso un punto o un numero reale si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool( ).point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool( ).rightButton == True: # se usato il tasto destro del mouse 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.startPtForBufferWidth = value # imposto il map tool self.getPointMapTool( ).startPtForBufferWidth = self.startPtForBufferWidth self.getPointMapTool().entitySet.set(self.entitySet) self.getPointMapTool().segments = self.segments self.getPointMapTool().setMode( Qad_mbuffer_maptool_ModeEnum.FIRST_PT_ASK_FOR_BUFFER_WIDTH) # si appresta ad attendere un punto self.waitForPoint( QadMsg.translate("Command_MBUFFER", "Specify second point: ")) self.step = 3 return False else: self.width = value self.plugIn.setLastRadius(self.width) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.AddGeoms(currLayer) return True # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO DELLA LARGHEZZA BUFFER (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.width = qad_utils.getDistance(self.startPtForBufferWidth, value) self.plugIn.setLastRadius(self.width) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.AddGeoms(currLayer) return True # fine comando
def canvasMoveEvent(self, event): QadGetPoint.canvasMoveEvent(self, event) self.__rubberBand.reset() if self.asToolForMPolygon: self.__polygonRubberBand.reset() result = False arc = QadArc() # noti il primo e il secondo punto dell'arco si richiede il terzo punto if self.mode == Qad_arc_maptool_ModeEnum.START_SECOND_PT_KNOWN_ASK_FOR_END_PT: result = arc.fromStartSecondEndPts(self.arcStartPt, self.arcSecondPt, self.tmpPoint) # noti il primo punto e il centro dell'arco si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_END_PT: result = arc.fromStartCenterEndPts(self.arcStartPt, self.arcCenterPt, self.tmpPoint) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il primo punto e il centro dell'arco si richiede l'angolo inscritto elif self.mode == Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_ANGLE: angle = qad_utils.getAngleBy2Pts(self.arcCenterPt, self.tmpPoint) result = arc.fromStartCenterPtsAngle(self.arcStartPt, self.arcCenterPt, angle) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il primo punto e il centro dell'arco si richiede la lunghezza della corda elif self.mode == Qad_arc_maptool_ModeEnum.START_CENTER_PT_KNOWN_ASK_FOR_CHORD: chord = qad_utils.getDistance(self.arcStartPt, self.tmpPoint) result = arc.fromStartCenterPtsChord(self.arcStartPt, self.arcCenterPt, chord) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e finale dell'arco si richiede il centro elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_CENTER: result = arc.fromStartCenterEndPts(self.arcStartPt, self.tmpPoint, self.arcEndPt) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e finale dell'arco si richiede l'angolo inscritto elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_ANGLE: angle = qad_utils.getAngleBy2Pts(self.arcStartPt, self.tmpPoint) result = arc.fromStartEndPtsAngle(self.arcStartPt, self.arcEndPt, angle) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e finale dell'arco si richiede la direzione della tangente elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_TAN: tan = qad_utils.getAngleBy2Pts(self.arcStartPt, self.tmpPoint) result = arc.fromStartEndPtsTan(self.arcStartPt, self.arcEndPt, tan) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e finale dell'arco si richiede il raggio elif self.mode == Qad_arc_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_RADIUS: radius = qad_utils.getDistance(self.arcEndPt, self.tmpPoint) result = arc.fromStartEndPtsRadius(self.arcStartPt, self.arcEndPt, radius) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e la tangente al punto iniziale si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_TAN_KNOWN_ASK_FOR_END_PT: result = arc.fromStartEndPtsTan(self.arcStartPt, self.tmpPoint, self.arcTanOnStartPt) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e l'angolo inscritto dell'arco si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_ANGLE_KNOWN_ASK_FOR_END_PT: result = arc.fromStartEndPtsAngle(self.arcStartPt, self.tmpPoint, self.arcAngle) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e l'angolo inscritto dell'arco si richiede il centro elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_ANGLE_KNOWN_ASK_FOR_CENTER_PT: result = arc.fromStartCenterPtsAngle(self.arcStartPt, self.tmpPoint, self.arcAngle) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale, l'angolo inscritto e il raggio dell'arco si richiede la direzione della corda elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_ANGLE_RADIUS_KNOWN_ASK_FOR_CHORDDIRECTION: chordDirection = qad_utils.getAngleBy2Pts(self.arcStartPt, self.tmpPoint) result = arc.fromStartPtAngleRadiusChordDirection(self.arcStartPt, self.arcAngle, \ self.arcRadius, chordDirection) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() # noti il punto iniziale e il raggio dell'arco si richiede il punto finale elif self.mode == Qad_arc_maptool_ModeEnum.START_PT_RADIUS_KNOWN_ASK_FOR_END_PT: result = arc.fromStartEndPtsRadius(self.arcStartPt, self.tmpPoint, self.arcRadius) if result == True and self.tmpCtrlKey: # cambio direzione arc.inverse() if result == True: points = arc.asPolyline() if points is not None: self.__rubberBand.setLine(points) if self.asToolForMPolygon == True: # se True significa che è usato per disegnare un poligono if self.endVertex is not None: points.insert(0, self.endVertex) self.__polygonRubberBand.setPolygon(points)
def fromPolyline(self, points, startVertex, atLeastNSegment=None): """ setta le caratteristiche del primo arco incontrato nella lista di punti partendo dalla posizione startVertex (0-indexed) ritorna la posizione nella lista del punto iniziale e finale se é stato trovato un arco altrimenti None N.B. in punti NON devono essere in coordinate geografiche """ if atLeastNSegment is None: _atLeastNSegment = QadVariables.get(QadMsg.translate("Environment variables", "ARCMINSEGMENTQTY"), 12) else: _atLeastNSegment = atLeastNSegment totPoints = len(points) # perché sia un arco ci vogliono almeno _atLeastNSegment segmenti if (totPoints - 1) - startVertex < _atLeastNSegment or _atLeastNSegment < 2: return None # per problemi di approssimazione dei calcoli epsilon = 1.0e-4 # percentuale del raggio per ottenere max diff. di una distanza con il raggio InfinityLinePerpOnMiddle1 = None InfinityLinePerpOnMiddle2 = None nSegment = 0 i = startVertex while i < totPoints - 1: if InfinityLinePerpOnMiddle1 is None: InfinityLinePerpOnMiddle1 = qad_utils.getInfinityLinePerpOnMiddle(points[i], points[i + 1]) nStartVertex = i nSegment = 1 i = i + 1 continue elif InfinityLinePerpOnMiddle2 is None: InfinityLinePerpOnMiddle2 = qad_utils.getInfinityLinePerpOnMiddle(points[i], points[i + 1]) if InfinityLinePerpOnMiddle2 is None: InfinityLinePerpOnMiddle1 = None nSegment = 0 else: # calcolo il presunto centro con 2 segmenti center = qad_utils.getIntersectionPointOn2InfinityLines( InfinityLinePerpOnMiddle1[0], InfinityLinePerpOnMiddle1[1], InfinityLinePerpOnMiddle2[0], InfinityLinePerpOnMiddle2[1], ) if center is None: # linee parallele InfinityLinePerpOnMiddle1 = InfinityLinePerpOnMiddle2 InfinityLinePerpOnMiddle2 = None nStartVertex = i nSegment = 1 else: nSegment = nSegment + 1 radius = qad_utils.getDistance(center, points[i + 1]) # calcolo il presunto raggio maxDifference = radius * epsilon # calcolo il verso dell'arco e l'angolo dell'arco # se un punto intermedio dell'arco è a sinistra del # segmento che unisce i due punti allora il verso è antiorario startClockWise = ( True if qad_utils.leftOfLine(points[i], points[i - 1], points[i + 1]) < 0 else False ) angle = qad_utils.getAngleBy3Pts(points[i - 1], center, points[i + 1], startClockWise) else: # e sono già stati valutati almeno 2 segmenti # calcolo la distanza del punto dal presunto centro dist = qad_utils.getDistance(center, points[i + 1]) # calcolo il verso dell'arco e l'angolo clockWise = True if qad_utils.leftOfLine(points[i], points[i - 1], points[i + 1]) < 0 else False angle = angle + qad_utils.getAngleBy3Pts(points[i], center, points[i + 1], startClockWise) # se la distanza è così vicina a quella del raggio # il verso dell'arco deve essere quello iniziale # l'angolo dell'arco non può essere >= 360 gradi if ( qad_utils.doubleNear(radius, dist, maxDifference) and startClockWise == clockWise and angle < 2 * math.pi ): nSegment = nSegment + 1 # anche questo segmento fa parte dell'arco else: # questo segmento non fa parte del cerchio # se sono stati trovati un numero sufficiente di segmenti successivi if nSegment >= _atLeastNSegment: # se é un angolo giro e il primo punto = ultimo punto allora points é un cerchio if qad_utils.doubleNear(angle, 2 * math.pi) and points[0] == points[-1]: return None break else: i = i - 2 InfinityLinePerpOnMiddle1 = None InfinityLinePerpOnMiddle2 = None i = i + 1 # se sono stati trovati un numero sufficiente di segmenti successivi if nSegment >= _atLeastNSegment: nEndVertex = nStartVertex + nSegment # se il punto iniziale e quello finale non coincidono é un arco if points[nStartVertex] != points[nEndVertex]: self.center = center self.radius = radius # se il verso é orario if startClockWise: # inverto l'angolo iniziale con quello finale self.endAngle = qad_utils.getAngleBy2Pts(center, points[nStartVertex]) self.startAngle = qad_utils.getAngleBy2Pts(center, points[nEndVertex]) else: self.startAngle = qad_utils.getAngleBy2Pts(center, points[nStartVertex]) self.endAngle = qad_utils.getAngleBy2Pts(center, points[nEndVertex]) return nStartVertex, nEndVertex return None
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 #========================================================================= # RICHIESTA PUNTO o ENTITA' if self.step == 0: # inizio del comando # si appresta ad attendere un punto o un numero reale # msg, inputType, default, keyWords, valori positivi self.waitFor(self.msg, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \ self.dist, "", \ QadInputModeEnum.NOT_NULL | self.inputMode) if self.startPt is not None: # imposto il map tool self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE) self.getPointMapTool().setStartPoint(self.startPt) self.step = 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO o numero reale 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 value = self.getPointMapTool().point self.ctrlKey = self.getPointMapTool().ctrlKey else: # il punto o il numero reale arriva come parametro della funzione value = msg if value is None: return True # fine comando if type(value) == float: self.dist = value return True # fine comando elif type(value) == QgsPoint: # il/i punto/i indicato/i da questa questa funzione non devono alterare lastpoint self.plugIn.setLastPoint(self.__prevLastPoint) if self.startPt is not None: self.dist = qad_utils.getDistance(self.startPt, value) return True # fine comando else: self.startPt = value # imposto il map tool self.getPointMapTool().setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE) self.getPointMapTool().setStartPoint(self.startPt) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("QAD", "Specify second point: ")) self.step = 2 return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO DELLA DISTANZA (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 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 # il/i punto/i indicato/i da questa questa funzione non devono alterare lastpoint self.plugIn.setLastPoint(self.__prevLastPoint) self.dist = qad_utils.getDistance(self.startPt, value) return True # fine comando
def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # fine comando if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, QGis.Line) if currLayer is None: self.showErr(errMsg) return True # fine comando # RICHIESTA PRIMO PUNTO if self.step == 0: # inizio del comando # imposto il map tool self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_PT) # si appresta ad attendere un punto o enter # msg, inputType, default, keyWords, nessun controllo self.waitFor(QadMsg.translate("Command_LINE", "Specify first point: "), \ QadInputTypeEnum.POINT2D, None, "", QadInputModeEnum.NONE) self.step = 1 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO OPPURE MENU PRINCIPALE 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 if self.virtualCmd == False: # se si vuole veramente salvare in un layer self.addLinesToLayer(currLayer) 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 if type(value) == unicode or type(value) == str: if value == QadMsg.translate("Command_LINE", "Undo") or value == "Undo": self.delLastVertex() # cancello ultimo vertice # imposto il map tool if len(self.vertices) == 0: self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_PT) # si appresta ad attendere un punto o enter # msg, inputType, default, keyWords, nessun controllo self.waitFor(QadMsg.translate("Command_LINE", "Specify first point: "), \ QadInputTypeEnum.POINT2D, None, "", QadInputModeEnum.NONE) return False else: self.getPointMapTool().firstPt = self.vertices[-1] self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) elif value == QadMsg.translate("Command_LINE", "Close") or value == "Close": newPt = self.vertices[0] self.addVertex(newPt) # aggiungo un nuovo vertice if self.virtualCmd == False: # se si vuole veramente salvare in un layer self.addLinesToLayer(currLayer) return True # fine comando else: if len(self.vertices) == 0: # primo punto if value is None: if self.plugIn.lastPoint is not None: value = self.plugIn.lastPoint else: return True # fine comando # se é stato selezionato un punto con la modalità TAN_DEF é un punto differito if snapTypeOnSel == QadSnapTypeEnum.TAN_DEF and entity.isInitialized(): # se era stato selezionato un punto esplicito if (self.firstPtTan is None) and (self.firstPtPer is None): self.firstPtPer = None self.firstPtTan = value self.firstGeom = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapSettings().destinationCrs()) # trasformo la geometria self.firstGeom.transform(coordTransform) # imposto il map tool self.getPointMapTool().tan1 = self.firstPtTan self.getPointMapTool().geom1 = self.firstGeom self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_TAN_KNOWN_ASK_FOR_SECOND_PT) # se era stato selezionato un punto con la modalità TAN_DEF elif self.firstPtTan is not None: secondGeom = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapSettings().destinationCrs()) # trasformo la geometria secondGeom.transform(coordTransform) tangent = qad_utils.lineFrom2TanPts(self.firstGeom, self.firstPtTan, secondGeom, value) if tangent is not None: # prendo il punto più vicino a value if qad_utils.getDistance(tangent[0], value) < qad_utils.getDistance(tangent[1], value): self.addVertex(tangent[1]) # aggiungo un nuovo vertice self.addVertex(tangent[0]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = tangent[0] else: self.addVertex(tangent[0]) # aggiungo un nuovo vertice self.addVertex(tangent[1]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = tangent[1] # imposto il map tool self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) else: self.showMsg(QadMsg.translate("Command_LINE", "\nNo tangent possible")) # se era stato selezionato un punto con la modalità PER_DEF elif self.firstPtPer is not None: secondGeom = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapSettings().destinationCrs()) # trasformo la geometria secondGeom.transform(coordTransform) tangent = qad_utils.lineFromTanPerPts(secondGeom, value, self.firstGeom, self.firstPtPer) if tangent is not None: # prendo il punto più vicino a value if qad_utils.getDistance(tangent[0], value) < qad_utils.getDistance(tangent[1], value): self.addVertex(tangent[1]) # aggiungo un nuovo vertice self.addVertex(tangent[0]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = tangent[0] else: self.addVertex(tangent[0]) # aggiungo un nuovo vertice self.addVertex(tangent[1]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = tangent[1] # imposto il map tool self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) else: self.showMsg(QadMsg.translate("Command_LINE", "\nNo tangent possible")) # se é stato selezionato un punto con la modalità PER_DEF é un punto differito elif snapTypeOnSel == QadSnapTypeEnum.PER_DEF and entity.isInitialized(): # se era stato selezionato un punto esplicito if (self.firstPtTan is None) and (self.firstPtPer is None): self.firstPtTan = None self.firstPtPer = value self.firstGeom = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapSettings().destinationCrs()) # trasformo la geometria self.firstGeom.transform(coordTransform) # imposto il map tool self.getPointMapTool().per1 = self.firstPtPer self.getPointMapTool().geom1 = self.firstGeom self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PER_KNOWN_ASK_FOR_SECOND_PT) # se era stato selezionato un punto con la modalità TAN_DEF elif self.firstPtTan is not None: secondGeom = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapSettings().destinationCrs()) # trasformo la geometria secondGeom.transform(coordTransform) tangent = qad_utils.lineFromTanPerPts(self.firstGeom, self.firstPtTan, secondGeom, value) if tangent is not None: # prendo il punto più vicino a value if qad_utils.getDistance(tangent[0], value) < qad_utils.getDistance(tangent[1], value): self.addVertex(tangent[1]) # aggiungo un nuovo vertice self.addVertex(tangent[0]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = tangent[0] else: self.addVertex(tangent[0]) # aggiungo un nuovo vertice self.addVertex(tangent[1]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = tangent[1] # imposto il map tool self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) else: self.showMsg(QadMsg.translate("Command_LINE", "\nNo perpendicular possible")) # se era stato selezionato un punto con la modalità PER_DEF elif self.firstPtPer is not None: secondGeom = QgsGeometry(entity.getGeometry()) # duplico la geometria coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.plugIn.canvas.mapSettings().destinationCrs()) # trasformo la geometria secondGeom.transform(coordTransform) line = qad_utils.lineFrom2PerPts(self.firstGeom, self.firstPtPer, secondGeom, value) if line is not None: # prendo il punto più vicino a value if qad_utils.getDistance(line[0], value) < qad_utils.getDistance(line[1], value): self.addVertex(line[1]) # aggiungo un nuovo vertice self.addVertex(line[0]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = line[0] else: self.addVertex(line[0]) # aggiungo un nuovo vertice self.addVertex(line[1]) # aggiungo un nuovo vertice self.getPointMapTool().firstPt = line[1] # imposto il map tool self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) else: self.showMsg(QadMsg.translate("Command_LINE", "\nNo perpendicular possible")) else: # altrimenti é un punto esplicito # se era stato selezionato un punto con la modalità TAN_DEF if self.firstPtTan is not None: snapper = QadSnapper() snapper.setSnapPointCRS(self.plugIn.canvas.mapSettings().destinationCrs()) snapper.setSnapType(QadSnapTypeEnum.TAN) snapper.setStartPoint(value) oSnapPoints = snapper.getSnapPoint(self.firstGeom, self.firstPtTan, self.plugIn.canvas.mapSettings().destinationCrs()) # memorizzo il punto di snap in point (prendo il primo valido) for item in oSnapPoints.items(): points = item[1] if points is not None: self.addVertex(points[0]) # aggiungo un nuovo vertice self.addVertex(value) # aggiungo un nuovo vertice break if len(self.vertices) == 0: self.showMsg(QadMsg.translate("Command_LINE", "\nNo tangent possible")) # se era stato selezionato un punto con la modalità PER_DEF elif self.firstPtPer is not None: snapper = QadSnapper() snapper.setSnapPointCRS(self.plugIn.canvas.mapSettings().destinationCrs()) snapper.setSnapType(QadSnapTypeEnum.PER) snapper.setStartPoint(value) oSnapPoints = snapper.getSnapPoint(self.firstGeom, self.firstPtPer, self.plugIn.canvas.mapSettings().destinationCrs()) # memorizzo il punto di snap in point (prendo il primo valido) for item in oSnapPoints.items(): points = item[1] if points is not None: self.addVertex(points[0]) # aggiungo un nuovo vertice self.addVertex(value) # aggiungo un nuovo vertice break if len(self.vertices) == 0: self.showMsg(QadMsg.translate("Command_LINE", "\nNo perpendicular possible")) else: self.addVertex(value) # aggiungo un nuovo vertice if len(self.vertices) > 0: # imposto il map tool self.getPointMapTool().firstPt = value self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) else: # secondo punto if value is None: if self.virtualCmd == False: # se si vuole veramente salvare in un layer self.addLinesToLayer(currLayer) return True # fine comando # se il primo punto é esplicito if len(self.vertices) > 0 is not None: self.addVertex(value) # aggiungo un nuovo vertice # imposto il map tool self.getPointMapTool().firstPt = value self.getPointMapTool().setMode(Qad_line_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT) if len(self.vertices) > 2: keyWords = QadMsg.translate("Command_LINE", "Close") + "/" + \ QadMsg.translate("Command_LINE", "Undo") else: keyWords = QadMsg.translate("Command_LINE", "Undo") prompt = QadMsg.translate("Command_LINE", "Specify next point or [{0}]: ").format(keyWords) englishKeyWords = "Close" + "/" + "Undo" keyWords += "_" + englishKeyWords # si appresta ad attendere un punto o enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.POINT2D | QadInputTypeEnum.KEYWORDS, \ None, \ keyWords, QadInputModeEnum.NONE) return False
def run(self, msgMapTool=False, msg=None): if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag(): self.showMsg( QadMsg.translate( "QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n" )) return True # fine comando #========================================================================= # RICHIESTA SELEZIONE OGGETTI if self.step == 0: # inizio del comando if self.SSGetClass.run(msgMapTool, msg) == True: # selezione terminata self.step = 1 self.getPointMapTool().refreshSnapType( ) # aggiorno lo snapType che può essere variato dal maptool di selezione entità return self.run(msgMapTool, msg) #========================================================================= # RUOTA OGGETTI elif self.step == 1: self.entitySet.set(self.SSGetClass.entitySet) if self.entitySet.count() == 0: return True # fine comando # imposto il map tool self.getPointMapTool().setMode( Qad_scale_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT) # si appresta ad attendere un punto self.waitForPoint( QadMsg.translate("Command_SCALE", "Specify base point: ")) self.step = 2 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO BASE (da step = 1) elif self.step == 2: # dopo aver atteso un punto o un numero reale si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool( ).point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool( ).rightButton == True: # se usato il tasto destro del mouse 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.basePt = QgsPoint(value) self.getPointMapTool().basePt = self.basePt self.getPointMapTool().entitySet.set(self.entitySet) # si appresta ad attendere la scala self.waitForScale() return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER SCALA (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) == unicode: if value == QadMsg.translate("Command_SCALE", "Copy") or value == "Copy": self.copyFeatures = True self.showMsg( QadMsg.translate( "Command_SCALE", "\nScale of a copy of the selected objects.")) # si appresta ad attendere la scala self.waitForScale() elif value == QadMsg.translate( "Command_SCALE", "Reference") or value == "Reference": # si appresta ad attendere la lunghezza di riferimento self.waitForReferenceLen() elif type(value) == QgsPoint or type( value) == float: # se é stato inserita la scala if type( value ) == QgsPoint: # se é stato inserita la scala con un punto if value == self.basePt: self.showMsg( QadMsg.translate( "QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForScale() return False scale = qad_utils.getDistance(self.basePt, value) else: scale = value self.plugIn.setLastScale(scale) self.scaleGeoms(scale) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 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) == float: # se é stato inserita la lunghezza self.ReferenceLen = value self.getPointMapTool().ReferenceLen = self.ReferenceLen # si appresta ad attendere la nuova lunghezza self.waitForNewReferenceLen() elif type( value ) == QgsPoint: # se é stato inserito la scala con un punto self.Pt1ReferenceLen = QgsPoint(value) self.getPointMapTool().Pt1ReferenceLen = self.Pt1ReferenceLen # imposto il map tool self.getPointMapTool().setMode( Qad_scale_maptool_ModeEnum. FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_LEN) # si appresta ad attendere un punto self.waitForPoint( QadMsg.translate("Command_SCALE", "Specify second point: ")) self.step = 5 return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 4) elif self.step == 5: # 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 self.Pt1ReferenceLen == value: self.showMsg( QadMsg.translate( "QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForPoint( QadMsg.translate("Command_SCALE", "Specify second point: ")) return False length = qad_utils.getDistance(self.Pt1ReferenceLen, value) self.ReferenceLen = length self.getPointMapTool().ReferenceLen = self.ReferenceLen # si appresta ad attendere la nuova lunghezza self.waitForNewReferenceLen() return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVA LUNGHEZZA (da step = 4 e 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) == unicode: if value == QadMsg.translate("Command_SCALE", "Points") or value == "Points": # imposto il map tool self.getPointMapTool().setMode( Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_NEW_LEN_PT) # si appresta ad attendere un punto self.waitForPoint( QadMsg.translate("Command_SCALE", "Specify first point: ")) self.step = 7 elif type(value) == QgsPoint or type( value) == float: # se é stato inserita la lunghezza if type( value ) == QgsPoint: # se é stato inserito la lunghezza con un punto if value == self.basePt: self.showMsg( QadMsg.translate( "QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForNewReferenceLen() return False length = qad_utils.getDistance(self.basePt, value) else: length = value scale = length / self.ReferenceLen self.plugIn.setLastScale(scale) self.scaleGeoms(scale) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER NUOVA LUNGHEZZA (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 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.Pt1NewLen = value # imposto il map tool self.getPointMapTool().Pt1NewLen = self.Pt1NewLen self.getPointMapTool().setMode( Qad_scale_maptool_ModeEnum. FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT) # si appresta ad attendere un punto self.waitForPoint( QadMsg.translate("Command_SCALE", "Specify second point: ")) self.step = 8 return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVA LUNGHEZZA (da step = 7) elif self.step == 8: # 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 value == self.Pt1NewLen: self.showMsg( QadMsg.translate( "QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForPoint( QadMsg.translate("Command_SCALE", "Specify second point: ")) return False length = qad_utils.getDistance(self.Pt1NewLen, value) scale = length / self.ReferenceLen self.plugIn.setLastScale(scale) self.scaleGeoms(scale) return True # fine comando
def stretchQgsLineStringGeometry(geom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve = None): """ Stira i punti di una linestring che sono contenuti in containerGeom point = punto da tirare containerGeom = può essere una QgsGeometry rappresentante un poligono contenente i punti di geom da stirare oppure una lista dei punti da stirare offSetX = spostamento X offSetY = spostamento Y """ if tolerance2ApproxCurve == None: tolerance = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) else: tolerance = tolerance2ApproxCurve obj = qad_utils.whatGeomIs(0, geom) if (type(obj) != list and type(obj) != tuple): objType = obj.whatIs() if objType == "CIRCLE": # se é cerchio if isPtContainedForStretch(obj.center, containerGeom): # se il punto è contenuto in containerGeom obj.center.setX(obj.center.x() + offSetX) obj.center.setY(obj.center.y() + offSetY) return QgsGeometry.fromPolyline(obj.asPolyline(tolerance)) stretchedGeom = QgsGeometry(geom) snapper = QadSnapper() points = snapper.getEndPoints(stretchedGeom) del snapper linearObjectListToStretch = qad_utils.QadLinearObjectList() linearObjectListToStretch.fromPolyline(geom.asPolyline()) for point in points: if isPtContainedForStretch(point, containerGeom): # se il punto è contenuto in containerGeom atPart = linearObjectListToStretch.containsPt(point) while atPart >= 0: linearObject = linearObjectListToStretch.getLinearObjectAt(atPart) pt = linearObject.getStartPt() if qad_utils.ptNear(pt, point): # cambio punto iniziale pt.setX(pt.x() + offSetX) pt.setY(pt.y() + offSetY) if linearObject.isSegment(): linearObject.setStartPt(pt) else: oldArc = linearObject.getArc() middlePt = oldArc.getMiddlePt() distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt)) newArc = QadArc() if linearObject.isInverseArc(): middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False: return None else: middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False: return None linearObject.setArc(newArc, linearObject.isInverseArc()) else: pt = linearObject.getEndPt() if qad_utils.ptNear(pt, point): # cambio punto finale pt.setX(pt.x() + offSetX) pt.setY(pt.y() + offSetY) if linearObject.isSegment(): linearObject.setEndPt(pt) else: oldArc = linearObject.getArc() middlePt = oldArc.getMiddlePt() distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt)) newArc = QadArc() if linearObject.isInverseArc(): middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False: return None else: middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False: return None linearObject.setArc(newArc, linearObject.isInverseArc()) atPart = linearObjectListToStretch.containsPt(point, atPart + 1) pts = linearObjectListToStretch.asPolyline(tolerance) stretchedGeom = QgsGeometry.fromPolyline(pts) return stretchedGeom
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 stretchQgsLineStringGeometry(geom, containerGeom, offSetX, offSetY, tolerance2ApproxCurve): """ Stira i punti di una linestring che sono contenuti in containerGeom point = punto da tirare containerGeom = può essere una QgsGeometry rappresentante un poligono contenente i punti di geom da stirare oppure una lista dei punti da stirare offSetX = spostamento X offSetY = spostamento Y """ obj = qad_utils.whatGeomIs(0, geom) if (type(obj) != list and type(obj) != tuple): objType = obj.whatIs() if objType == "CIRCLE": # se é cerchio if isPtContainedForStretch(obj.center, containerGeom): # se il punto è contenuto in containerGeom obj.center.setX(obj.center.x() + offSetX) obj.center.setY(obj.center.y() + offSetY) return QgsGeometry.fromPolyline(obj.asPolyline(tolerance2ApproxCurve)) stretchedGeom = QgsGeometry(geom) snapper = QadSnapper() points = snapper.getEndPoints(stretchedGeom) del snapper linearObjectListToStretch = qad_utils.QadLinearObjectList() linearObjectListToStretch.fromPolyline(geom.asPolyline()) for point in points: if isPtContainedForStretch(point, containerGeom): # se il punto è contenuto in containerGeom atPart = linearObjectListToStretch.containsPt(point) while atPart >= 0: linearObject = linearObjectListToStretch.getLinearObjectAt(atPart) pt = linearObject.getStartPt() if qad_utils.ptNear(pt, point): # cambio punto iniziale pt.setX(pt.x() + offSetX) pt.setY(pt.y() + offSetY) if linearObject.isSegment(): linearObject.setStartPt(pt) else: oldArc = linearObject.getArc() middlePt = oldArc.getMiddlePt() distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt)) newArc = QadArc() if linearObject.isInverseArc(): middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False: return None else: middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False: return None linearObject.setArc(newArc, linearObject.isInverseArc()) else: pt = linearObject.getEndPt() if qad_utils.ptNear(pt, point): # cambio punto finale pt.setX(pt.x() + offSetX) pt.setY(pt.y() + offSetY) if linearObject.isSegment(): linearObject.setEndPt(pt) else: oldArc = linearObject.getArc() middlePt = oldArc.getMiddlePt() distFromMiddleChord = qad_utils.getDistance(middlePt, qad_utils.getPerpendicularPointOnInfinityLine(oldArc.getStartPt(), oldArc.getEndPt(), middlePt)) newArc = QadArc() if linearObject.isInverseArc(): middlePt = qad_utils.getMiddlePoint(pt, oldArc.getEndPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getEndPt()) - math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(pt, middlePt, oldArc.getEndPt()) == False: return None else: middlePt = qad_utils.getMiddlePoint(pt, oldArc.getStartPt()) middlePt = qad_utils.getPolarPointByPtAngle(middlePt, \ qad_utils.getAngleBy2Pts(pt, oldArc.getStartPt()) + math.pi / 2, \ distFromMiddleChord) if newArc.fromStartSecondEndPts(oldArc.getStartPt(), middlePt, pt) == False: return None linearObject.setArc(newArc, linearObject.isInverseArc()) atPart = linearObjectListToStretch.containsPt(point, atPart + 1) pts = linearObjectListToStretch.asPolyline(tolerance2ApproxCurve) stretchedGeom = QgsGeometry.fromPolyline(pts) return stretchedGeom
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 # 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 DISTANZA DI OFFSET if self.step == 0: # inizio del comando CurrSettingsMsg = QadMsg.translate("QAD", "\nCurrent settings: ") CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", "OFFSETGAPTYPE = ") + str(self.gapType) if self.gapType == 0: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", " (extends the segments)") elif self.gapType == 1: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", " (fillets the segments)") elif self.gapType == 2: CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", " (chamfers the segments)") self.showMsg(CurrSettingsMsg) self.waitForDistance() #========================================================================= # RISPOSTA ALLA RICHIESTA DELLA DISTANZA DI OFFSET (da step = 0) elif self.step == 1: # 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 if self.offSet < 0: value = QadMsg.translate("Command_OFFSET", "Through") else: value = self.offSet 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_OFFSET", "Through") or value == "Through": self.offSet = -1 self.getPointMapTool().offSet = self.offSet QadVariables.set(QadMsg.translate("Environment variables", "OFFSETDIST"), self.offSet) QadVariables.save() # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() elif value == QadMsg.translate("Command_OFFSET", "Erase") or value == "Erase": keyWords = QadMsg.translate("QAD", "Yes") + "/" + \ QadMsg.translate("QAD", "No") if self.eraseEntity == True: default = QadMsg.translate("QAD", "Yes") else: default = QadMsg.translate("QAD", "No") prompt = QadMsg.translate("Command_OFFSET", "Erase source object after offsetting ? [{0}] <{1}>: ").format(keyWords, default) englishKeyWords = "Yes" + "/" + "No" keyWords += "_" + englishKeyWords # si appresta ad attendere enter o una parola chiave # msg, inputType, default, keyWords, nessun controllo self.waitFor(prompt, \ QadInputTypeEnum.KEYWORDS, \ default, \ keyWords, QadInputModeEnum.NONE) self.step = 5 elif value == QadMsg.translate("Command_OFFSET", "Multiple") or value == "Multiple": self.multi = True self.waitForBasePt() elif type(value) == QgsPoint: # se é stato inserito il primo punto per il calcolo della distanza self.firstPt.set(value.x(), value.y()) # imposto il map tool self.getPointMapTool().firstPt = self.firstPt self.getPointMapTool().setMode(Qad_offset_maptool_ModeEnum.FIRST_OFFSET_PT_KNOWN_ASK_FOR_SECOND_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_OFFSET", "Specify second point: ")) self.step = 6 elif type(value) == float: self.offSet = value self.getPointMapTool().offSet = self.offSet QadVariables.set(QadMsg.translate("Environment variables", "OFFSETDIST"), self.offSet) QadVariables.save() # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA SELEZIONE DI UN OGGETTO elif self.step == 2: entity = None 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 = QadMsg.translate("Command_OFFSET", "Exit") else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: entity = self.getPointMapTool().entity value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("Command_OFFSET", "Exit") or value == "Exit": self.offsetGeoms(currLayer) return True elif value == QadMsg.translate("Command_OFFSET", "Undo") or value == "Undo": self.undoGeomsInCache() # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() elif type(value) == QgsPoint: # se é stato selezionato un punto if entity is not None and entity.isInitialized(): # se é stata selezionata una entità self.entity.set(entity.layer, entity.featureId) self.getPointMapTool().layer = self.entity.layer # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy geom = self.layerToMapCoordinates(entity.layer, entity.getGeometry()) # ritorna una tupla (<The squared cartesian distance>, # <minDistPoint> # <afterVertex> # <leftOf>) dummy = qad_utils.closestSegmentWithContext(value, geom) if dummy[2] is not None: # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based) # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>]) self.subGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])[0] self.subGeomSelectedPt = QgsPoint(value) self.getPointMapTool().subGeom = self.subGeom if self.offSet < 0: # richiesta di punto di passaggio self.waitForPassagePt() else: # richiesta la parte dell'oggetto self.waitForSidePt() else: # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DI UN PUNTO PER STABILIRE LA PARTE DI OFFSET (da step = 2) elif self.step == 3: if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse if self.multi == False: # default = esci self.offsetGeoms(currLayer) 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: # oggetto successivo # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() else: if type(value) == unicode: if value == QadMsg.translate("Command_OFFSET", "Exit") or value == "Exit": self.offsetGeoms(currLayer) return True # fine comando elif value == QadMsg.translate("Command_OFFSET", "Multiple") or value == "Multiple": self.multi = True self.waitForSidePt() elif value == QadMsg.translate("Command_OFFSET", "Undo") or value == "Undo": self.undoGeomsInCache() # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() elif value == QadMsg.translate("Command_OFFSET", "Segment") or value == "Segment": self.OnlySegment = True linearObject = qad_utils.QadLinearObject() if linearObject.setByClosestSegmentOfGeom(self.subGeomSelectedPt, self.subGeom) == True: self.subGeom = QgsGeometry.fromPolyline(linearObject.asPolyline()) self.getPointMapTool().subGeom = self.subGeom self.waitForSidePt() elif type(value) == QgsPoint: # se é stato selezionato un punto self.addFeatureCache(value) if self.multi == False: # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() else: # richiesta la parte dell'oggetto self.waitForSidePt() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DI UN PUNTO DI PASSAGGIO DI OFFSET (da step = 2) elif self.step == 4: if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse if self.multi == False: # default = esci self.offsetGeoms(currLayer) 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: # oggetto successivo # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() else: if type(value) == unicode: if value == QadMsg.translate("Command_OFFSET", "Exit") or value == "Exit": self.offsetGeoms(currLayer) return True # fine comando elif value == QadMsg.translate("Command_OFFSET", "Multiple") or value == "Multiple": self.multi = True self.waitForPassagePt() elif value == QadMsg.translate("Command_OFFSET", "Undo") or value == "Undo": self.undoGeomsInCache() # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() elif value == QadMsg.translate("Command_OFFSET", "Segment") or value == "Segment": self.OnlySegment = True linearObject = qad_utils.QadLinearObject() if linearObject.setByClosestSegmentOfGeom(self.subGeomSelectedPt, self.subGeom) == True: self.subGeom = QgsGeometry.fromPolyline(linearObject.asPolyline()) self.getPointMapTool().subGeom = self.subGeom self.waitForPassagePt() elif type(value) == QgsPoint: # se é stato selezionato un punto self.addFeatureCache(value) if self.multi == False: # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() else: # richiesta di punto di passaggio self.waitForPassagePt() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DI CANCELLAZIONE OGGETTO SORGENTE (da step = 1) elif self.step == 5: # 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().rightButton == True: # se usato il tasto destro del mouse value = QadMsg.translate("QAD", "No") else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: # il valore arriva come parametro della funzione value = msg if type(value) == unicode: if value == QadMsg.translate("QAD", "Yes") or value == "Yes": self.eraseEntity = True self.waitForDistance() elif value == QadMsg.translate("QAD", "No") or value == "No": self.eraseEntity = False self.waitForDistance() return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER LUNGHEZZA OFFSET (da step = 1) 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 value == self.firstPt: self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_OFFSET", "Specify second point: ")) return False self.offSet = qad_utils.getDistance(self.firstPt, value) self.getPointMapTool().offSet = self.offSet QadVariables.set(QadMsg.translate("Environment variables", "OFFSETDIST"), self.offSet) QadVariables.save() # si appresta ad attendere la selezione di un oggetto self.waitForObjectSel() return False
def run(self, msgMapTool = False, msg = None): if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag(): self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n")) return True # fine comando #========================================================================= # RICHIESTA SELEZIONE OGGETTI if self.step == 0: # inizio del comando if self.SSGetClass.run(msgMapTool, msg) == True: # selezione terminata self.step = 1 self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di selezione entità return self.run(msgMapTool, msg) #========================================================================= # RUOTA OGGETTI elif self.step == 1: self.entitySet.set(self.SSGetClass.entitySet) if self.entitySet.count() == 0: return True # fine comando # imposto il map tool self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify base point: ")) self.step = 2 return False #========================================================================= # RISPOSTA ALLA RICHIESTA PUNTO BASE (da step = 1) elif self.step == 2: # dopo aver atteso un punto o un numero reale si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse 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.basePt = QgsPoint(value) self.getPointMapTool().basePt = self.basePt self.getPointMapTool().entitySet.set(self.entitySet) # si appresta ad attendere la scala self.waitForScale() return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER SCALA (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) == unicode: if value == QadMsg.translate("Command_SCALE", "Copy") or value == "Copy": self.copyFeatures = True self.showMsg(QadMsg.translate("Command_SCALE", "\nScale of a copy of the selected objects.")) # si appresta ad attendere la scala self.waitForScale() elif value == QadMsg.translate("Command_SCALE", "Reference") or value == "Reference": # si appresta ad attendere la lunghezza di riferimento self.waitForReferenceLen() elif type(value) == QgsPoint or type(value) == float: # se é stato inserita la scala if type(value) == QgsPoint: # se é stato inserita la scala con un punto if value == self.basePt: self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForScale() return False scale = qad_utils.getDistance(self.basePt, value) else: scale = value self.plugIn.setLastScale(scale) self.scaleGeoms(scale) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 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) == float: # se é stato inserita la lunghezza self.ReferenceLen = value self.getPointMapTool().ReferenceLen = self.ReferenceLen # si appresta ad attendere la nuova lunghezza self.waitForNewReferenceLen() elif type(value) == QgsPoint: # se é stato inserito la scala con un punto self.Pt1ReferenceLen = QgsPoint(value) self.getPointMapTool().Pt1ReferenceLen = self.Pt1ReferenceLen # imposto il map tool self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_LEN) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: ")) self.step = 5 return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER LUNGHEZZA DI RIFERIMENTO (da step = 4) elif self.step == 5: # 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 self.Pt1ReferenceLen == value: self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: ")) return False length = qad_utils.getDistance(self.Pt1ReferenceLen, value) self.ReferenceLen = length self.getPointMapTool().ReferenceLen = self.ReferenceLen # si appresta ad attendere la nuova lunghezza self.waitForNewReferenceLen() return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVA LUNGHEZZA (da step = 4 e 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) == unicode: if value == QadMsg.translate("Command_SCALE", "Points") or value == "Points": # imposto il map tool self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_NEW_LEN_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify first point: ")) self.step = 7 elif type(value) == QgsPoint or type(value) == float: # se é stato inserita la lunghezza if type(value) == QgsPoint: # se é stato inserito la lunghezza con un punto if value == self.basePt: self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForNewReferenceLen() return False length = qad_utils.getDistance(self.basePt, value) else: length = value scale = length / self.ReferenceLen self.plugIn.setLastScale(scale) self.scaleGeoms(scale) return True # fine comando return False #========================================================================= # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER NUOVA LUNGHEZZA (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 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.Pt1NewLen = value # imposto il map tool self.getPointMapTool().Pt1NewLen = self.Pt1NewLen self.getPointMapTool().setMode(Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: ")) self.step = 8 return False #========================================================================= # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVA LUNGHEZZA (da step = 7) elif self.step == 8: # 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 value == self.Pt1NewLen: self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero.")) # si appresta ad attendere un punto self.waitForPoint(QadMsg.translate("Command_SCALE", "Specify second point: ")) return False length = qad_utils.getDistance(self.Pt1NewLen, value) scale = length / self.ReferenceLen self.plugIn.setLastScale(scale) self.scaleGeoms(scale) return True # fine comando
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 NUMERO DI LATI DEL POLIGONO if self.step == 0: # inizio del comando self.WaitForSideNumber() return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL NUMERO DI LATI DEL POLIGONO (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 if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse value = self.sideNumber else: return False else: # il punto arriva come parametro della funzione value = msg if type(value) == int: if value < 3: self.showErr(QadMsg.translate("Command_POLYGON", "\nEnter an integer greater than 2.")) else: self.sideNumber = value self.getPointMapTool().sideNumber = self.sideNumber self.plugIn.setLastPolygonSideNumber(self.sideNumber) self.WaitForCenter() else: self.WaitForSideNumber() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DEL CENTRO DEL POLIGONO (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.WaitForCenter() 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_POLYGON", "Edge") or value == "Edge": self.WaitForFirstEdgePt() elif type(value) == QgsPoint: self.centerPt = value self.getPointMapTool().centerPt = self.centerPt self.WaitForInscribedCircumscribedOption() return False # continua #========================================================================= # RISPOSTA ALLA RICHIESTA DI POLIGONO INSCRITTO O CIRCOSCRITTO (da step = 2) elif self.step == 3: 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.constructionModeByCenter else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: value = self.getPointMapTool().point else: # la parola chiave arriva come parametro della funzione value = msg if type(value) == unicode: self.constructionModeByCenter = value self.plugIn.setLastPolygonConstructionModeByCenter(self.constructionModeByCenter) self.getPointMapTool().constructionModeByCenter = self.constructionModeByCenter if self.constructionModeByCenter == QadMsg.translate("Command_POLYGON", "Area") or self.constructionModeByCenter == "Area": self.WaitForArea() else: self.WaitForRadius(currLayer) return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DEL RAGGIO (da step = 3) elif self.step == 4: 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 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) ptStart = value else: self.radius = value ptStart = None self.plugIn.setLastRadius(self.radius) if self.constructionModeByCenter == QadMsg.translate("Command_POLYGON", "Inscribed in circle") or \ self.constructionModeByCenter == "Inscribed in circle": mode = True else: mode = False self.vertices.extend(qad_utils.getPolygonByNsidesCenterRadius(self.sideNumber, self.centerPt, self.radius, \ mode, ptStart)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addPolygonToLayer(currLayer) return True return False # fine comando #========================================================================= # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DELLO SPIGOLO (da step = 2) 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 value = self.getPointMapTool().point else: # il punto arriva come parametro della funzione value = msg if type(value) == QgsPoint: self.firstEdgePt = value self.WaitForSecondEdgePt(currLayer) return False #========================================================================= # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DELLO SPIGOLO (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.vertices.extend(qad_utils.getPolygonByNsidesEdgePts(self.sideNumber, self.firstEdgePt, value)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addPolygonToLayer(currLayer) return True return False #========================================================================= # RISPOSTA ALLA RICHIESTA AREA POLIGONO (da step = 3) elif self.step == 7: # dopo aver atteso un numero reale si riavvia il comando if msgMapTool == True: # il punto arriva da una selezione grafica # la condizione seguente si verifica se durante la selezione di un punto # é stato attivato un altro plugin che ha disattivato Qad # quindi stato riattivato il comando che torna qui senza che il maptool # abbia selezionato un punto if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse value = self.area else: self.setMapTool(self.getPointMapTool()) # riattivo il maptool return False else: return False else: # il punto arriva come parametro della funzione value = msg if type(value) == float: # é stata inserita l'area self.vertices.extend(qad_utils.getPolygonByNsidesArea(self.sideNumber, self.centerPt, value)) if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer self.addPolygonToLayer(currLayer) return True return False