Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
    def mirror(self, f, pt1, pt2, rotFldName, layerEntitySet, entitySet,
               dimEntity):

        if dimEntity is None:
            # scalo la feature e la rimuovo da entitySet (é la prima)
            f.setGeometry(qad_utils.mirrorQgsGeometry(f.geometry(), pt1, pt2))
            if len(rotFldName) > 0:
                rotValue = f.attribute(rotFldName)
                # a volte vale None e a volte null (vai a capire...)
                rotValue = 0 if rotValue is None or isinstance(
                    rotValue, QPyNullVariant) else qad_utils.toRadians(
                        rotValue
                    )  # la rotazione é in gradi nel campo della feature
                ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
                mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
                ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
                rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
                f.setAttribute(
                    rotFldName,
                    qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))

            if self.copyFeatures == False:
                # plugIn, layer, feature, refresh, check_validity
                if qad_layer.updateFeatureToLayer(self.plugIn,
                                                  layerEntitySet.layer, f,
                                                  False, False) == False:
                    self.plugIn.destroyEditCommand()
                    return False
            else:
                # plugIn, layer, features, coordTransform, refresh, check_validity
                if qad_layer.addFeatureToLayer(self.plugIn,
                                               layerEntitySet.layer, f, None,
                                               False, False) == False:
                    self.plugIn.destroyEditCommand()
                    return False

            del layerEntitySet.featureIds[0]
        else:
            # scalo la quota e la rimuovo da entitySet
            mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
            dimEntitySet = dimEntity.getEntitySet()
            if self.copyFeatures == False:
                if dimEntity.deleteToLayers(self.plugIn) == False:
                    return False
            newDimEntity = QadDimEntity(dimEntity)  # la copio
            newDimEntity.mirror(pt1, mirrorAngle)
            if newDimEntity.addToLayers(self.plugIn) == False:
                return False
            entitySet.subtract(dimEntitySet)
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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
Ejemplo n.º 10
0
    def mirror(self, entity, pt1, pt2, rotFldName):
        # entity = entità da specchiare
        # pt1 e pt2 = linea di simmetria
        # rotFldName = campo della tabella che memorizza la rotazione
        # verifico se l'entità appartiene ad uno stile di quotatura
        if entity.whatIs() == "ENTITY":
            f = entity.getFeature()
            # specchio l'entità
            f.setGeometry(
                qad_utils.mirrorQgsGeometry(entity.getGeometry(), pt1, pt2))
            if len(rotFldName) > 0:
                rotValue = f.attribute(rotFldName)
                # a volte vale None e a volte null (vai a capire...)
                rotValue = 0 if rotValue is None or isinstance(
                    rotValue, QPyNullVariant) else qad_utils.toRadians(
                        rotValue
                    )  # la rotazione é in gradi nel campo della feature
                ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
                mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
                ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
                rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
                f.setAttribute(
                    rotFldName,
                    qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))

            if self.copyEntities == False:
                # plugIn, layer, feature, refresh, check_validity
                if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f,
                                                  False, False) == False:
                    return False
            else:
                # plugIn, layer, features, coordTransform, refresh, check_validity
                if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f,
                                               None, False, False) == False:
                    return False
        elif entity.whatIs() == "DIMENTITY":
            mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
            # specchio la quota
            if self.copyEntities == False:
                if entity.deleteToLayers(self.plugIn) == False:
                    return False

            newDimEntity = QadDimEntity(entity)  # la copio
            newDimEntity.mirror(pt1, mirrorAngle)
            if newDimEntity.addToLayers(self.plugIn) == False:
                return False

        return True
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
 def canvasMoveEvent(self, event):
    QadGetPoint.canvasMoveEvent(self, event)
                   
    # noto il punto base si richiede il secondo punto per l'angolo di rotazione
    if self.mode == Qad_rotate_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_ROTATION_PT:
       angle = qad_utils.getAngleBy2Pts(self.basePt, self.tmpPoint)
       self.addRotatedGeometries(angle)                           
    # noto il punto base si richiede il secondo punto per il nuovo angolo
    elif self.mode == Qad_rotate_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_ROTATION_PT:
       angle = qad_utils.getAngleBy2Pts(self.basePt, self.tmpPoint)
       diffAngle = angle - self.ReferenceAng
       self.addRotatedGeometries(diffAngle)                           
    # noto il primo punto si richiede il secondo punto per il nuovo angolo
    elif self.mode == Qad_rotate_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_ROTATION_PT:
       angle = qad_utils.getAngleBy2Pts(self.Pt1NewAng, self.tmpPoint)
       diffAngle = angle - self.ReferenceAng
       self.addRotatedGeometries(diffAngle)                           
Ejemplo n.º 15
0
 def canvasMoveEvent(self, event):
    QadGetPoint.canvasMoveEvent(self, event)
                   
    # noto il punto base si richiede il secondo punto per l'angolo di rotazione
    if self.mode == Qad_rotate_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_ROTATION_PT:
       angle = qad_utils.getAngleBy2Pts(self.basePt, self.tmpPoint)
       self.addRotatedGeometries(angle)                           
    # noto il punto base si richiede il secondo punto per il nuovo angolo
    elif self.mode == Qad_rotate_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_ROTATION_PT:
       angle = qad_utils.getAngleBy2Pts(self.basePt, self.tmpPoint)
       diffAngle = angle - self.ReferenceAng
       self.addRotatedGeometries(diffAngle)                           
    # noto il primo punto si richiede il secondo punto per il nuovo angolo
    elif self.mode == Qad_rotate_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_ROTATION_PT:
       angle = qad_utils.getAngleBy2Pts(self.Pt1NewAng, self.tmpPoint)
       diffAngle = angle - self.ReferenceAng
       self.addRotatedGeometries(diffAngle)                           
Ejemplo n.º 16
0
 def setStartAngleByPt(self, pt):
     # da usare per modificare un arco già definito
     angle = qad_utils.getAngleBy2Pts(self.center, pt)
     if angle == self.endAngle:
         return False
     else:
         self.startAngle = angle
         return True
Ejemplo n.º 17
0
 def setEndAngleByPt(self, pt):
     # da usare per modificare un arco già definito
     angle = qad_utils.getAngleBy2Pts(self.center, pt)
     if angle == self.startAngle:
         return False
     else:
         self.endAngle = angle
         return True
Ejemplo n.º 18
0
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      self.__rubberBand.reset()
      res = False
       
      # si richiede la selezione dell'oggetto da allungare
      if self.mode == Qad_lengthen_maptool_ModeEnum.ASK_FOR_OBJ_TO_LENGTHEN:
         if self.tmpEntity.isInitialized():
            if self.setInfo(self.tmpEntity, self.tmpPoint) == False:
               return
                  
            if self.OpMode == "DElta":
               if self.OpType == "length":
                  res = self.tmpLinearObjectList.lengthen_delta(self.move_startPt, self.value)
               elif self.OpType == "Angle":
                  res = self.tmpLinearObjectList.lengthen_deltaAngle(self.move_startPt, self.value)
            elif self.OpMode == "Percent":
               value = self.tmpLinearObjectList.length() * self.value / 100
               value = value - self.tmpLinearObjectList.length()
               res = self.tmpLinearObjectList.lengthen_delta(self.move_startPt, value)
            elif self.OpMode == "Total":
               if self.OpType == "length":
                  value = self.value - self.tmpLinearObjectList.length()
                  res = self.tmpLinearObjectList.lengthen_delta(self.move_startPt, value)
               elif self.OpType == "Angle":                     
                  if self.tmpLinearObjectList.qty() == 1:
                     linearObject = self.tmpLinearObjectList.getLinearObjectAt(0)
                     if linearObject.isArc() == True: # se è un arco
                        value = self.value - linearObject.getArc().totalAngle()
                        res = self.tmpLinearObjectList.lengthen_deltaAngle(self.move_startPt, value)
               
      # si richiede un punto per la nuova estremità
      elif self.mode == Qad_lengthen_maptool_ModeEnum.ASK_FOR_DYNAMIC_POINT:
         if self.tmpLinearObjectList.qty() == 1:
            transformedPt = self.canvas.mapRenderer().mapToLayerCoordinates(self.layer, self.tmpPoint)
            
            linearObject = self.tmpLinearObjectList.getLinearObjectAt(0)
            if linearObject.isSegment():
               newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), transformedPt)
            else: # arco
               newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \
                                                        qad_utils.getAngleBy2Pts(linearObject.getArc().center, transformedPt), \
                                                        linearObject.getArc().radius)                  

            if self.move_startPt:
               linearObject.setStartPt(newPt)
            else:
               linearObject.setEndPt(newPt)
            res = True
      

      if res == False: # allungamento impossibile
         return
      pts = self.tmpLinearObjectList.asPolyline()
      geom = QgsGeometry.fromPolyline(pts)
      self.__rubberBand.addGeometry(geom, self.layer)
Ejemplo n.º 19
0
    def fromStartPtAngleRadiusChordDirection(self, startPt, angle, radius, chordDirection):
        """
      setta le caratteristiche dell'arco attraverso:
      punto iniziale
      angolo inscritto
      raggio
      direzione della corda
      """
        if angle == 0 or angle == 2 * math.pi or radius <= 0:
            return False

        a = chordDirection + (math.pi / 2) - (angle / 2)
        self.radius = radius
        self.center = qad_utils.getPolarPointByPtAngle(startPt, a, radius)
        endPt = qad_utils.getPolarPointByPtAngle(self.center, a + math.pi + angle, radius)

        self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt)
        self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt)
        return True
Ejemplo n.º 20
0
   def fromStartPtAngleRadiusChordDirection(self, startPt, angle, radius, chordDirection):
      """
      setta le caratteristiche dell'arco attraverso:
      punto iniziale
      angolo inscritto
      raggio
      direzione della corda
      """
      if angle == 0 or angle == 2 * math.pi or radius <= 0:
         return False

      a = chordDirection + (math.pi / 2) - (angle / 2) 
      self.radius = radius
      self.center = qad_utils.getPolarPointByPtAngle(startPt, a, radius)
      endPt = qad_utils.getPolarPointByPtAngle(self.center, a + math.pi + angle, radius)
                 
      self.startAngle = qad_utils.getAngleBy2Pts(self.center, startPt)
      self.endAngle = qad_utils.getAngleBy2Pts(self.center, endPt)
      return True
Ejemplo n.º 21
0
    def getPerpendicularPoints(self, point):
        result = []
        angle = qad_utils.getAngleBy2Pts(self.center, point)
        if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
            result.append(qad_utils.getPolarPointByPtAngle(self.center, angle, self.radius))

        angle = angle + math.pi
        if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
            result.append(qad_utils.getPolarPointByPtAngle(self.center, angle, self.radius))

        return result
Ejemplo n.º 22
0
   def mirror(self, entity, pt1, pt2, rotFldName):
      # entity = entità da specchiare
      # pt1 e pt2 = linea di simmetria
      # rotFldName = campo della tabella che memorizza la rotazione
      # verifico se l'entità appartiene ad uno stile di quotatura
      if entity.whatIs() == "ENTITY":
         f = entity.getFeature()
         # specchio l'entità
         f.setGeometry(qad_utils.mirrorQgsGeometry(entity.getGeometry(), pt1, pt2))
         if len(rotFldName) > 0:
            rotValue = f.attribute(rotFldName)
            # a volte vale None e a volte null (vai a capire...)
            rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
            ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
            mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
            ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
            rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
            f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))               
                  
         if self.copyEntities == False:
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
               return False
         else:             
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
               return False
      elif entity.whatIs() == "DIMENTITY":
         mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
         # specchio la quota
         if self.copyEntities == False:
            if entity.deleteToLayers(self.plugIn) == False:
               return False
            
         newDimEntity = QadDimEntity(entity) # la copio
         newDimEntity.mirror(pt1, mirrorAngle)
         if newDimEntity.addToLayers(self.plugIn) == False:
            return False             

      return True
Ejemplo n.º 23
0
   def mirror(self, f, pt1, pt2, rotFldName, layerEntitySet, entitySet, dimEntity):
      
      if dimEntity is None:
         # scalo la feature e la rimuovo da entitySet (é la prima)
         f.setGeometry(qad_utils.mirrorQgsGeometry(f.geometry(), pt1, pt2))
         if len(rotFldName) > 0:
            rotValue = f.attribute(rotFldName)
            # a volte vale None e a volte null (vai a capire...)
            rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
            ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
            mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
            ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
            rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
            f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))               
                  
         if self.copyFeatures == False:
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False
         else:             
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False

         del layerEntitySet.featureIds[0]
      else:
         # scalo la quota e la rimuovo da entitySet
         mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
         dimEntitySet = dimEntity.getEntitySet()
         if self.copyFeatures == False:
            if dimEntity.deleteToLayers(self.plugIn) == False:
               return False
         newDimEntity = QadDimEntity(dimEntity) # la copio
         newDimEntity.mirror(pt1, mirrorAngle)
         if newDimEntity.addToLayers(self.plugIn) == False:
            return False             
         entitySet.subtract(dimEntitySet)
Ejemplo n.º 24
0
 def getTanPoints(self, point):
    result = []
    
    circle = QadCircle()
    circle.set(self.center, self.radius)
    points = circle.getTanPoints(point)
    tot = len(points)
    for p in points:
       angle = qad_utils.getAngleBy2Pts(self.center, p)
       if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
          result.append(p)
          
    return result
Ejemplo n.º 25
0
    def getTanPoints(self, point):
        result = []

        circle = QadCircle()
        circle.set(self.center, self.radius)
        points = circle.getTanPoints(point)
        tot = len(points)
        for p in points:
            angle = qad_utils.getAngleBy2Pts(self.center, p)
            if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
                result.append(p)

        return result
Ejemplo n.º 26
0
   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
Ejemplo n.º 27
0
   def getPerpendicularPoints(self, point):
      result = []
      angle = qad_utils.getAngleBy2Pts(self.center, point)
      if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
         result.append( qad_utils.getPolarPointByPtAngle(self.center,
                                                         angle,
                                                         self.radius))

      angle = angle + math.pi         
      if qad_utils.isAngleBetweenAngles(self.startAngle, self.endAngle, angle) == True:
         result.append( qad_utils.getPolarPointByPtAngle(self.center,
                                                         angle,
                                                         self.radius))
         
      return result
Ejemplo n.º 28
0
 def mirror(self, f, pt1, pt2, layerEntitySet, entitySet):
    # verifico se la feature appartiene ad una quotatura
    dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())
    
    if dimEntity is None:
       # specchio la feature e la rimuovo da entitySet (é la prima)
       f.setGeometry(qad_utils.mirrorQgsGeometry(f.geometry(), pt1, pt2))
       self.__highlight.addGeometry(f.geometry(), layerEntitySet.layer)
       del layerEntitySet.featureIds[0]
    else:
       # specchio la quota e la rimuovo da entitySet
       dimEntitySet = dimEntity.getEntitySet()         
       dimEntity.mirror(self.plugIn, pt1, qad_utils.getAngleBy2Pts(pt1, pt2))
       self.__highlight.addGeometry(dimEntity.textualFeature.geometry(), dimEntity.getTextualLayer())
       self.__highlight.addGeometries(dimEntity.getLinearGeometryCollection(), dimEntity.getLinearLayer())
       self.__highlight.addGeometries(dimEntity.getSymbolGeometryCollection(), dimEntity.getSymbolLayer())
       entitySet.subtract(dimEntitySet)
Ejemplo n.º 29
0
    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
Ejemplo n.º 30
0
 def mirror(self, f, pt1, pt2, layerEntitySet, entitySet):
    # verifico se la feature appartiene ad una quotatura
    dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())
    
    if dimEntity is None:
       # specchio la feature e la rimuovo da entitySet (é la prima)
       f.setGeometry(qad_utils.mirrorQgsGeometry(f.geometry(), pt1, pt2))
       self.__highlight.addGeometry(f.geometry(), layerEntitySet.layer)
       del layerEntitySet.featureIds[0]
    else:
       # specchio la quota e la rimuovo da entitySet
       dimEntitySet = dimEntity.getEntitySet()         
       dimEntity.mirror(pt1, qad_utils.getAngleBy2Pts(pt1, pt2))
       self.__highlight.addGeometry(dimEntity.textualFeature.geometry(), dimEntity.getTextualLayer())
       self.__highlight.addGeometries(dimEntity.getLinearGeometryCollection(), dimEntity.getLinearLayer())
       self.__highlight.addGeometries(dimEntity.getSymbolGeometryCollection(), dimEntity.getSymbolLayer())
       entitySet.subtract(dimEntitySet)
Ejemplo n.º 31
0
    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
Ejemplo n.º 32
0
    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
Ejemplo n.º 33
0
    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
Ejemplo n.º 34
0
Archivo: qad_arc.py Proyecto: gam17/QAD
   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
Ejemplo n.º 35
0
    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
Ejemplo n.º 36
0
 def getTanDirectionOnPt(self, pt):
     angle = qad_utils.getAngleBy2Pts(self.center, pt)
     return qad_utils.normalizeAngle(angle + math.pi / 2)
Ejemplo n.º 37
0
    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
Ejemplo n.º 38
0
   def lengthen(self, point):
      layer = self.entity.layer
      f = self.entity.getFeature()
      if f is None: # non c'è più la feature
         return False
      # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
      geom = self.layerToMapCoordinates(layer, self.entity.getGeometry())
                  
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      res = False
      newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         
      if self.move_startPt:
         linearObject = newLinearObjectList.getLinearObjectAt(0)
      else:
         linearObject = newLinearObjectList.getLinearObjectAt(-1)
         
      if linearObject.isSegment():
         newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), point)
      else: # arco
         newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \
                                                  qad_utils.getAngleBy2Pts(linearObject.getArc().center, point), \
                                                  linearObject.getArc().radius)                  

      if newLinearObjectList.qty() > 1 and linearObject.isSegment():
         ang = linearObject.getTanDirectionOnStartPt()

      if self.move_startPt:
         linearObject.setStartPt(newPt)
      else:
         linearObject.setEndPt(newPt)
         
      if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \
         qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False:
         res = False
      else:
         res = True

      if res == False: # allungamento impossibile
         return False
               
      pts = newLinearObjectList.asPolyline() 
      updSubGeom = QgsGeometry.fromPolyline(pts)
               
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom)
      if updGeom is None:
         return False
      # trasformo la geometria nel crs del layer
      f.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      if self.copyEntities == False:
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      else:
         # plugIn, layer, features, coordTransform, refresh, check_validity
         if qad_layer.addFeatureToLayer(self.plugIn, layer, f, None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      
      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
Ejemplo n.º 39
0
   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_rotate_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT)

         # si appresta ad attendere un punto
         self.waitForPoint(QadMsg.translate("Command_ROTATE", "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 l'angolo di rotazione                      
         self.waitForRotation()
         
         return False 
         
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER ANGOLO ROTAZIONE (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_ROTATE", "Copy") or value == "Copy":
               self.copyFeatures = True
               self.showMsg(QadMsg.translate("Command_ROTATE", "\nRotation of a copy of the selected objects."))
               # si appresta ad attendere l'angolo di rotazione               
               self.waitForRotation()                
            elif value == QadMsg.translate("Command_ROTATE", "Reference") or value == "Reference":
               # si appresta ad attendere l'angolo di riferimento                      
               self.waitForReferenceRot()
         elif type(value) == QgsPoint or type(value) == float: # se é stato inserito l'angolo di rotazione
            if type(value) == QgsPoint: # se é stato inserito l'angolo di rotazione con un punto
               angle = qad_utils.getAngleBy2Pts(self.basePt, value)
            else:
               angle = qad_utils.toRadians(value)
            self.plugIn.setLastRot(angle)

            self.RotateGeoms(angle)
            return True # fine comando
         
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER ANGOLO ROTAZIONE 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 inserito l'angolo di rotazione
            self.ReferenceAng = qad_utils.toRadians(value)
            self.getPointMapTool().ReferenceAng = self.ReferenceAng 
            # si appresta ad attendere il nuovo angolo                    
            self.waitForNewReferenceRot()

         elif type(value) == QgsPoint: # se é stato inserito l'angolo di rotazione con un punto                                 
            self.Pt1ReferenceAng = QgsPoint(value)
            self.getPointMapTool().Pt1ReferenceAng = self.Pt1ReferenceAng 
            # imposto il map tool
            self.getPointMapTool().setMode(Qad_rotate_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_ANG)
            # si appresta ad attendere un punto
            self.waitForPoint(QadMsg.translate("Command_ROTATE", "Specify second point: "))
            self.step = 5           
            
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER ANGOLO ROTAZIONE 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

         angle = qad_utils.getAngleBy2Pts(self.Pt1ReferenceAng, value)
         self.ReferenceAng = angle
         self.getPointMapTool().ReferenceAng = self.ReferenceAng 
         # si appresta ad attendere il nuovo angolo                    
         self.waitForNewReferenceRot()
            
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVO ANGOLO ROTAZIONE (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_ROTATE", "Points") or value == "Points":
               # imposto il map tool
               self.getPointMapTool().setMode(Qad_rotate_maptool_ModeEnum.ASK_FOR_FIRST_NEW_ROTATION_PT)
               # si appresta ad attendere un punto
               self.waitForPoint(QadMsg.translate("Command_ROTATE", "Specify first point: "))
               self.step = 7
         elif type(value) == QgsPoint or type(value) == float: # se é stato inserito l'angolo di rotazione
            if type(value) == QgsPoint: # se é stato inserito l'angolo di rotazione con un punto                        
               angle = qad_utils.getAngleBy2Pts(self.basePt, value)
            else:
               angle = qad_utils.toRadians(value)
            
            angle = angle - self.ReferenceAng
            self.plugIn.setLastRot(angle)
            self.RotateGeoms(angle)
            return True # fine comando

         return False
      
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER NUOVO ANGOLO ROTAZIONE (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.Pt1NewAng = value
         # imposto il map tool
         self.getPointMapTool().Pt1NewAng = self.Pt1NewAng
         self.getPointMapTool().setMode(Qad_rotate_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_ROTATION_PT)
         # si appresta ad attendere un punto
         self.waitForPoint(QadMsg.translate("Command_ROTATE", "Specify second point: "))
         self.step = 8
            
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVO ANGOLO ROTAZIONE (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
               
         angle = qad_utils.getAngleBy2Pts(self.Pt1NewAng, value)
         
         angle = angle - self.ReferenceAng
         self.plugIn.setLastRot(angle)
         self.RotateGeoms(angle)
         return True # fine comando
Ejemplo n.º 40
0
   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 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 non nulli
            self.waitFor(self.msg, \
                         QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \
                         self.angle, "", \
                         QadInputModeEnum.NOT_NULL)

            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
            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.angle = qad_utils.toRadians(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.angle = qad_utils.getAngleBy2Pts(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 ANGOLO (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)

            if qad_utils.ptNear(self.startPt, value):
                self.showMsg(
                    QadMsg.translate("QAD", "\nThe points must be different."))
                # si appresta ad attendere un punto
                self.waitForPoint(
                    QadMsg.translate("QAD", "Specify second point: "))
                return False
            else:
                self.angle = qad_utils.getAngleBy2Pts(self.startPt, value)
                return True  # fine comando
Ejemplo n.º 42
0
   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 non nulli
         self.waitFor(self.msg, \
                      QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT, \
                      self.angle, "", \
                      QadInputModeEnum.NOT_NULL)
         
         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
         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.angle = qad_utils.toRadians(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.angle = qad_utils.getAngleBy2Pts(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 ANGOLO (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)
         
         if qad_utils.ptNear(self.startPt, value):
            self.showMsg(QadMsg.translate("QAD", "\nThe points must be different."))
            # si appresta ad attendere un punto
            self.waitForPoint(QadMsg.translate("QAD", "Specify second point: "))
            return False
         else:
            self.angle = qad_utils.getAngleBy2Pts(self.startPt, value)
            return True # fine comando
Ejemplo n.º 43
0
Archivo: qad_arc.py Proyecto: gam17/QAD
 def scale(self, basePt, scale):
    self.center = qad_utils.scalePoint(self.center, basePt, scale)
    newStartPt = qad_utils.scalePoint(self.getStartPt(), basePt, scale)
    newEndPt = qad_utils.scalePoint(self.getEndPt(), basePt, scale)
    self.startAngle = qad_utils.getAngleBy2Pts(self.center, newStartPt)
    self.endAngle = qad_utils.getAngleBy2Pts(self.center, newEndPt)
Ejemplo n.º 44
0
    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
Ejemplo n.º 45
0
    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 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_rotate_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT)

            # si appresta ad attendere un punto
            self.waitForPoint(
                QadMsg.translate("Command_ROTATE", "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 l'angolo di rotazione
            self.waitForRotation()

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER ANGOLO ROTAZIONE (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_ROTATE",
                                             "Copy") or value == "Copy":
                    self.copyFeatures = True
                    self.showMsg(
                        QadMsg.translate(
                            "Command_ROTATE",
                            "\nRotation of a copy of the selected objects."))
                    # si appresta ad attendere l'angolo di rotazione
                    self.waitForRotation()
                elif value == QadMsg.translate(
                        "Command_ROTATE", "Reference") or value == "Reference":
                    # si appresta ad attendere l'angolo di riferimento
                    self.waitForReferenceRot()
            elif type(value) == QgsPoint or type(
                    value
            ) == float:  # se é stato inserito l'angolo di rotazione
                if type(
                        value
                ) == QgsPoint:  # se é stato inserito l'angolo di rotazione con un punto
                    angle = qad_utils.getAngleBy2Pts(self.basePt, value)
                else:
                    angle = qad_utils.toRadians(value)
                self.plugIn.setLastRot(angle)

                self.RotateGeoms(angle)
                return True  # fine comando

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER ANGOLO ROTAZIONE 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 inserito l'angolo di rotazione
                self.ReferenceAng = qad_utils.toRadians(value)
                self.getPointMapTool().ReferenceAng = self.ReferenceAng
                # si appresta ad attendere il nuovo angolo
                self.waitForNewReferenceRot()

            elif type(
                    value
            ) == QgsPoint:  # se é stato inserito l'angolo di rotazione con un punto
                self.Pt1ReferenceAng = QgsPoint(value)
                self.getPointMapTool().Pt1ReferenceAng = self.Pt1ReferenceAng
                # imposto il map tool
                self.getPointMapTool().setMode(
                    Qad_rotate_maptool_ModeEnum.
                    FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_ANG)
                # si appresta ad attendere un punto
                self.waitForPoint(
                    QadMsg.translate("Command_ROTATE",
                                     "Specify second point: "))
                self.step = 5

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER ANGOLO ROTAZIONE 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

            angle = qad_utils.getAngleBy2Pts(self.Pt1ReferenceAng, value)
            self.ReferenceAng = angle
            self.getPointMapTool().ReferenceAng = self.ReferenceAng
            # si appresta ad attendere il nuovo angolo
            self.waitForNewReferenceRot()

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVO ANGOLO ROTAZIONE (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_ROTATE",
                                             "Points") or value == "Points":
                    # imposto il map tool
                    self.getPointMapTool().setMode(
                        Qad_rotate_maptool_ModeEnum.
                        ASK_FOR_FIRST_NEW_ROTATION_PT)
                    # si appresta ad attendere un punto
                    self.waitForPoint(
                        QadMsg.translate("Command_ROTATE",
                                         "Specify first point: "))
                    self.step = 7
            elif type(value) == QgsPoint or type(
                    value
            ) == float:  # se é stato inserito l'angolo di rotazione
                if type(
                        value
                ) == QgsPoint:  # se é stato inserito l'angolo di rotazione con un punto
                    angle = qad_utils.getAngleBy2Pts(self.basePt, value)
                else:
                    angle = qad_utils.toRadians(value)

                angle = angle - self.ReferenceAng
                self.plugIn.setLastRot(angle)
                self.RotateGeoms(angle)
                return True  # fine comando

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER NUOVO ANGOLO ROTAZIONE (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.Pt1NewAng = value
            # imposto il map tool
            self.getPointMapTool().Pt1NewAng = self.Pt1NewAng
            self.getPointMapTool().setMode(
                Qad_rotate_maptool_ModeEnum.
                FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_ROTATION_PT)
            # si appresta ad attendere un punto
            self.waitForPoint(
                QadMsg.translate("Command_ROTATE", "Specify second point: "))
            self.step = 8

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVO ANGOLO ROTAZIONE (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

            angle = qad_utils.getAngleBy2Pts(self.Pt1NewAng, value)

            angle = angle - self.ReferenceAng
            self.plugIn.setLastRot(angle)
            self.RotateGeoms(angle)
            return True  # fine comando
Ejemplo n.º 46
0
   def lengthen(self, point):
      layer = self.entity.layer
      f = self.entity.getFeature()
      if f is None: # non c'è più la feature
         return False
      # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
      geom = self.layerToMapCoordinates(layer, self.entity.getGeometry())
                  
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      res = False
      newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         
      if self.move_startPt:
         linearObject = newLinearObjectList.getLinearObjectAt(0)
      else:
         linearObject = newLinearObjectList.getLinearObjectAt(-1)
         
      if linearObject.isSegment():
         newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), point)
      else: # arco
         newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \
                                                  qad_utils.getAngleBy2Pts(linearObject.getArc().center, point), \
                                                  linearObject.getArc().radius)                  

      if newLinearObjectList.qty() > 1 and linearObject.isSegment():
         ang = linearObject.getTanDirectionOnStartPt()

      if self.move_startPt:
         linearObject.setStartPt(newPt)
      else:
         linearObject.setEndPt(newPt)
         
      if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \
         qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False:
         res = False
      else:
         res = True

      if res == False: # allungamento impossibile
         return False
               
      pts = newLinearObjectList.asPolyline() 
      updSubGeom = QgsGeometry.fromPolyline(pts)
               
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom)
      if updGeom is None:
         return False
      # trasformo la geometria nel crs del layer
      f.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      if self.copyEntities == False:
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      else:
         # plugIn, layer, features, coordTransform, refresh, check_validity
         if qad_layer.addFeatureToLayer(self.plugIn, layer, f, None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      
      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
Ejemplo n.º 47
0
   def lengthen(self, point):
      layer = self.entity.layer
      f = self.entity.getFeature()
      if f is None: # non c'è più la feature
         return False
      geom = self.entity.getGeometry()
                  
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      res = False
      if self.OpMode == "DElta":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         if self.OpType == "length":
            res = newLinearObjectList.lengthen_delta(self.move_startPt, self.value)
         elif self.OpType == "Angle":
            res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, self.value)
      elif self.OpMode == "Percent":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         value = newLinearObjectList.length() * self.value / 100
         value = value - newLinearObjectList.length()
         res = newLinearObjectList.lengthen_delta(self.move_startPt, value)
      elif self.OpMode == "Total":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         if self.OpType == "length":
            value = self.value - newLinearObjectList.length()
            res = newLinearObjectList.lengthen_delta(self.move_startPt, value)
         elif self.OpType == "Angle":                     
            if newLinearObjectList.qty() == 1:
               linearObject = newLinearObjectList.getLinearObjectAt(0)
               if linearObject.isArc() == True: # se è un arco
                  value = self.value - linearObject.getArc().totalAngle()
                  res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, value)
      elif self.OpMode == "DYnamic":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         transformedPt = self.mapToLayerCoordinates(layer, point)
            
         if self.move_startPt:
            linearObject = newLinearObjectList.getLinearObjectAt(0)
         else:
            linearObject = newLinearObjectList.getLinearObjectAt(-1)
            
         if linearObject.isSegment():
            newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), transformedPt)
         else: # arco
            newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \
                                                     qad_utils.getAngleBy2Pts(linearObject.getArc().center, transformedPt), \
                                                     linearObject.getArc().radius)                  

         if newLinearObjectList.qty() > 1 and linearObject.isSegment():
            ang = linearObject.getTanDirectionOnStartPt()

         if self.move_startPt:
            linearObject.setStartPt(newPt)
         else:
            linearObject.setEndPt(newPt)
            
         if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \
            qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False:
            res = False
         else:
            res = True

      if res == False: # allungamento impossibile
         return False
               
      pts = newLinearObjectList.asPolyline() 
      updSubGeom = QgsGeometry.fromPolyline(pts)
               
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom)
      if updGeom is None:
         return False
      f.setGeometry(updGeom)
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
Ejemplo n.º 48
0
   def lengthen(self, point):
      layer = self.entity.layer
      f = self.entity.getFeature()
      if f is None: # non c'è più la feature
         return False
      geom = self.entity.getGeometry()
                  
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      res = False
      if self.OpMode == "DElta":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         if self.OpType == "length":
            res = newLinearObjectList.lengthen_delta(self.move_startPt, self.value)
         elif self.OpType == "Angle":
            res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, self.value)
      elif self.OpMode == "Percent":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         value = newLinearObjectList.length() * self.value / 100
         value = value - newLinearObjectList.length()
         res = newLinearObjectList.lengthen_delta(self.move_startPt, value)
      elif self.OpMode == "Total":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         if self.OpType == "length":
            value = self.value - newLinearObjectList.length()
            res = newLinearObjectList.lengthen_delta(self.move_startPt, value)
         elif self.OpType == "Angle":                     
            if newLinearObjectList.qty() == 1:
               linearObject = newLinearObjectList.getLinearObjectAt(0)
               if linearObject.isArc() == True: # se è un arco
                  value = self.value - linearObject.getArc().totalAngle()
                  res = newLinearObjectList.lengthen_deltaAngle(self.move_startPt, value)
      elif self.OpMode == "DYnamic":
         newLinearObjectList = qad_utils.QadLinearObjectList(self.linearObjectList)
         transformedPt = self.mapToLayerCoordinates(layer, point)
            
         if self.move_startPt:
            linearObject = newLinearObjectList.getLinearObjectAt(0)
         else:
            linearObject = newLinearObjectList.getLinearObjectAt(-1)
            
         if linearObject.isSegment():
            newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), transformedPt)
         else: # arco
            newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \
                                                     qad_utils.getAngleBy2Pts(linearObject.getArc().center, transformedPt), \
                                                     linearObject.getArc().radius)                  

         if newLinearObjectList.qty() > 1 and linearObject.isSegment():
            ang = linearObject.getTanDirectionOnStartPt()

         if self.move_startPt:
            linearObject.setStartPt(newPt)
         else:
            linearObject.setEndPt(newPt)
            
         if newLinearObjectList.qty() > 1 and linearObject.isSegment() and \
            qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False:
            res = False
         else:
            res = True

      if res == False: # allungamento impossibile
         return False
               
      pts = newLinearObjectList.asPolyline() 
      updSubGeom = QgsGeometry.fromPolyline(pts)
               
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom)
      if updGeom is None:
         return False
      f.setGeometry(updGeom)
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
Ejemplo n.º 49
0
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   
Ejemplo n.º 50
0
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   
Ejemplo n.º 51
0
 def getTanDirectionOnPt(self, pt):
     angle = qad_utils.getAngleBy2Pts(self.center, pt)
     return qad_utils.normalizeAngle(angle + math.pi / 2)
    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)
Ejemplo n.º 53
0
    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 SELEZIONE OGGETTI
        if self.step == 0:  # inizio del comando
            if self.entitySet.isEmpty():  # non ci sono oggetti da ruotare
                return True
            self.showMsg(
                QadMsg.translate("Command_GRIPROTATE", "\n** ROTATE **\n"))
            # si appresta ad attendere un punto di rotazione
            self.waitForRotatePoint()
            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA DI UN PUNTO DI ROTAZIONE
        elif self.step == 1:
            ctrlKey = False
            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 = None
                    else:
                        self.setMapTool(
                            self.getPointMapTool())  # riattivo il maptool
                        return False
                else:
                    value = self.getPointMapTool().point

                ctrlKey = self.getPointMapTool().ctrlKey
            else:  # il punto arriva come parametro della funzione
                value = msg

            if type(value) == unicode:
                if value == QadMsg.translate(
                        "Command_GRIPROTATE",
                        "Base point") or value == "Base point":
                    # si appresta ad attendere il punto base
                    self.waitForBasePt()
                elif value == QadMsg.translate("Command_GRIPROTATE",
                                               "Copy") or value == "Copy":
                    # Copia entità lasciando inalterate le originali
                    self.copyEntities = True
                    # si appresta ad attendere un punto di rotazione
                    self.waitForRotatePoint()
                elif value == QadMsg.translate("Command_GRIPROTATE",
                                               "Undo") or value == "Undo":
                    if self.nOperationsToUndo > 0:
                        self.nOperationsToUndo = self.nOperationsToUndo - 1
                        self.plugIn.undoEditCommand()
                    else:
                        self.showMsg(
                            QadMsg.translate(
                                "QAD", "\nThe command has been canceled."))
                    # si appresta ad attendere un punto di rotazione
                    self.waitForRotatePoint()
                elif value == QadMsg.translate(
                        "Command_GRIPROTATE",
                        "Reference") or value == "Reference":
                    # si appresta ad attendere l'angolo di riferimento
                    self.waitForReferenceRot()
                elif value == QadMsg.translate("Command_GRIPROTATE",
                                               "eXit") or value == "eXit":
                    return True  # fine comando
            elif type(value) == QgsPoint or type(
                    value
            ) == float:  # se é stato inserito l'angolo di rotazione
                if type(
                        value
                ) == QgsPoint:  # se é stato inserito l'angolo di rotazione con un punto
                    angle = qad_utils.getAngleBy2Pts(self.basePt, value)
                else:
                    angle = qad_utils.toRadians(value)
                angle = angle - self.ReferenceAng
                self.plugIn.setLastRot(angle)

                if ctrlKey:
                    self.copyEntities = True

                self.rotateFeatures(angle)

                if self.copyEntities == False:
                    return True

                # si appresta ad attendere un punto di rotazione
                self.waitForRotatePoint()

            else:
                if self.copyEntities == False:
                    self.skipToNextGripCommand = True
                return True  # fine comando

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA PUNTO BASE (da step = 1)
        elif self.step == 2:  # dopo aver atteso un punto
            if msgMapTool == True:  # il punto arriva da una selezione grafica
                # la condizione seguente si verifica se durante la selezione di un punto
                # é stato attivato un altro plugin che ha disattivato Qad
                # quindi stato riattivato il comando che torna qui senza che il maptool
                # abbia selezionato un punto
                if self.getPointMapTool(
                ).point is None:  # il maptool é stato attivato senza un punto
                    if self.getPointMapTool(
                    ).rightButton == True:  # se usato il tasto destro del mouse
                        pass  # opzione di default "spostamento"
                    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 il punto base
                self.basePt.set(value.x(), value.y())
                # imposto il map tool
                self.getPointMapTool().basePt = self.basePt

            # si appresta ad attendere un punto di rotazione
            self.waitForRotatePoint()

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER ANGOLO ROTAZIONE DI RIFERIMENTO (da step = 1)
        elif self.step == 3:  # dopo aver atteso un punto o un numero reale si riavvia il comando
            if msgMapTool == True:  # il punto arriva da una selezione grafica
                # la condizione seguente si verifica se durante la selezione di un punto
                # é stato attivato un altro plugin che ha disattivato Qad
                # quindi stato riattivato il comando che torna qui senza che il maptool
                # abbia selezionato un punto
                if self.getPointMapTool(
                ).point is None:  # il maptool é stato attivato senza un punto
                    if self.getPointMapTool(
                    ).rightButton == True:  # se usato il tasto destro del mouse
                        return True  # 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 inserito l'angolo di rotazione
                self.ReferenceAng = qad_utils.toRadians(value)
                self.getPointMapTool().ReferenceAng = self.ReferenceAng
                # si appresta ad attendere un punto di rotazione
                self.waitForRotatePoint()

            elif type(
                    value
            ) == QgsPoint:  # se é stato inserito l'angolo di rotazione con un punto
                self.Pt1ReferenceAng = QgsPoint(value)
                self.getPointMapTool().Pt1ReferenceAng = self.Pt1ReferenceAng
                # imposto il map tool
                self.getPointMapTool().setMode(
                    Qad_rotate_maptool_ModeEnum.
                    FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_ANG)
                # si appresta ad attendere un punto
                self.waitForPoint(
                    QadMsg.translate("Command_GRIPROTATE",
                                     "Specify second point: "))
                self.step = 4

            return False

        #=========================================================================
        # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVO ANGOLO ROTAZIONE (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) == QgsPoint or type(
                    value
            ) == float:  # se é stato inserito l'angolo di rotazione
                if type(
                        value
                ) == QgsPoint:  # se é stato inserito l'angolo di rotazione con un punto
                    self.ReferenceAng = qad_utils.getAngleBy2Pts(
                        self.Pt1ReferenceAng, value)
                else:
                    self.ReferenceAng = qad_utils.toRadians(value)
                self.getPointMapTool().ReferenceAng = self.ReferenceAng

            # si appresta ad attendere un punto di rotazione
            self.waitForRotatePoint()

            return False
Ejemplo n.º 54
0
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      self.__rubberBand.reset()
      res = False
       
      # si richiede la selezione dell'oggetto da allungare
      if self.mode == Qad_lengthen_maptool_ModeEnum.ASK_FOR_OBJ_TO_LENGTHEN:
         if self.tmpEntity.isInitialized():
            if self.setInfo(self.tmpEntity, self.tmpPoint) == False:
               return

            if self.OpMode == "DElta":
               newTmpLinearObjectList = qad_utils.QadLinearObjectList(self.tmpLinearObjectList)
               if self.OpType == "length":
                  res = newTmpLinearObjectList.lengthen_delta(self.move_startPt, self.value)
               elif self.OpType == "Angle":
                  res = newTmpLinearObjectList.lengthen_deltaAngle(self.move_startPt, self.value)
            elif self.OpMode == "Percent":
               newTmpLinearObjectList = qad_utils.QadLinearObjectList(self.tmpLinearObjectList)
               value = newTmpLinearObjectList.length() * self.value / 100
               value = value - newTmpLinearObjectList.length()
               res = newTmpLinearObjectList.lengthen_delta(self.move_startPt, value)
            elif self.OpMode == "Total":
               newTmpLinearObjectList = qad_utils.QadLinearObjectList(self.tmpLinearObjectList)
               if self.OpType == "length":
                  value = self.value - self.tmpLinearObjectList.length()
                  res = newTmpLinearObjectList.lengthen_delta(self.move_startPt, value)
               elif self.OpType == "Angle":                     
                  if newTmpLinearObjectList.qty() == 1:
                     linearObject = newTmpLinearObjectList.getLinearObjectAt(0)
                     if linearObject.isArc() == True: # se è un arco
                        value = self.value - linearObject.getArc().totalAngle()
                        res = newTmpLinearObjectList.lengthen_deltaAngle(self.move_startPt, value)
               
      # si richiede un punto per la nuova estremità
      elif self.mode == Qad_lengthen_maptool_ModeEnum.ASK_FOR_DYNAMIC_POINT:
         newTmpLinearObjectList = qad_utils.QadLinearObjectList(self.tmpLinearObjectList)
         transformedPt = self.canvas.mapSettings().mapToLayerCoordinates(self.layer, self.tmpPoint)
         
         if self.move_startPt:
            linearObject = newTmpLinearObjectList.getLinearObjectAt(0)
         else:
            linearObject = newTmpLinearObjectList.getLinearObjectAt(-1)
            
         if linearObject.isSegment():
            newPt = qad_utils.getPerpendicularPointOnInfinityLine(linearObject.getStartPt(), linearObject.getEndPt(), transformedPt)
         else: # arco
            newPt = qad_utils.getPolarPointByPtAngle(linearObject.getArc().center, \
                                                     qad_utils.getAngleBy2Pts(linearObject.getArc().center, transformedPt), \
                                                     linearObject.getArc().radius)                  

         if newTmpLinearObjectList.qty() > 1 and linearObject.isSegment():
            ang = linearObject.getTanDirectionOnStartPt()

         if self.move_startPt:
            linearObject.setStartPt(newPt)
         else:
            linearObject.setEndPt(newPt)

         if newTmpLinearObjectList.qty() > 1 and linearObject.isSegment() and \
            qad_utils.TanDirectionNear(ang, linearObject.getTanDirectionOnStartPt()) == False:
            res = False
         else:
            res = True
      
      if res == False: # allungamento impossibile
         return
      pts = newTmpLinearObjectList.asPolyline()
      geom = QgsGeometry.fromPolyline(pts)
      self.__rubberBand.addGeometry(geom, self.layer)
Ejemplo n.º 55
0
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
Ejemplo n.º 56
0
   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.entitySet.isEmpty(): # non ci sono oggetti da ruotare
            return True
         self.showMsg(QadMsg.translate("Command_GRIPROTATE", "\n** ROTATE **\n"))
         # si appresta ad attendere un punto di rotazione
         self.waitForRotatePoint()
         return False
      
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DI UN PUNTO DI ROTAZIONE
      elif self.step == 1:
         ctrlKey = False
         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 = None
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False
            else:
               value = self.getPointMapTool().point

            ctrlKey = self.getPointMapTool().ctrlKey
         else: # il punto arriva come parametro della funzione
            value = msg

         if type(value) == unicode:
            if value == QadMsg.translate("Command_GRIPROTATE", "Base point") or value == "Base point":
               # si appresta ad attendere il punto base
               self.waitForBasePt()
            elif value == QadMsg.translate("Command_GRIPROTATE", "Copy") or value == "Copy":
               # Copia entità lasciando inalterate le originali
               self.copyEntities = True                     
               # si appresta ad attendere un punto di rotazione
               self.waitForRotatePoint()
            elif value == QadMsg.translate("Command_GRIPROTATE", "Undo") or value == "Undo":
               if self.nOperationsToUndo > 0: 
                  self.nOperationsToUndo = self.nOperationsToUndo - 1
                  self.plugIn.undoEditCommand()
               else:
                  self.showMsg(QadMsg.translate("QAD", "\nThe command has been canceled."))                  
               # si appresta ad attendere un punto di rotazione
               self.waitForRotatePoint()
            elif value == QadMsg.translate("Command_GRIPROTATE", "Reference") or value == "Reference":
               # si appresta ad attendere l'angolo di riferimento                      
               self.waitForReferenceRot()
            elif value == QadMsg.translate("Command_GRIPROTATE", "eXit") or value == "eXit":
               return True # fine comando
         elif type(value) == QgsPoint or type(value) == float: # se é stato inserito l'angolo di rotazione
            if type(value) == QgsPoint: # se é stato inserito l'angolo di rotazione con un punto
               angle = qad_utils.getAngleBy2Pts(self.basePt, value)
            else:
               angle = qad_utils.toRadians(value)
            angle = angle - self.ReferenceAng
            self.plugIn.setLastRot(angle)

            if ctrlKey:
               self.copyEntities = True
            
            self.rotateFeatures(angle)

            if self.copyEntities == False:
               return True

            # si appresta ad attendere un punto di rotazione
            self.waitForRotatePoint()
          
         else:
            if self.copyEntities == False:
               self.skipToNextGripCommand = True
            return True # fine comando
                                          
         return False 

              
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA PUNTO BASE (da step = 1)
      elif self.step == 2: # dopo aver atteso un punto
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  pass # opzione di default "spostamento"
               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 il punto base
            self.basePt.set(value.x(), value.y())
            # imposto il map tool
            self.getPointMapTool().basePt = self.basePt
            
         # si appresta ad attendere un punto di rotazione
         self.waitForRotatePoint()

         return False


      #=========================================================================
      # RISPOSTA ALLA RICHIESTA PRIMO PUNTO PER ANGOLO ROTAZIONE DI RIFERIMENTO (da step = 1)
      elif self.step == 3: # dopo aver atteso un punto o un numero reale si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  return True # 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 inserito l'angolo di rotazione
            self.ReferenceAng = qad_utils.toRadians(value)
            self.getPointMapTool().ReferenceAng = self.ReferenceAng 
            # si appresta ad attendere un punto di rotazione
            self.waitForRotatePoint()

         elif type(value) == QgsPoint: # se é stato inserito l'angolo di rotazione con un punto                                 
            self.Pt1ReferenceAng = QgsPoint(value)
            self.getPointMapTool().Pt1ReferenceAng = self.Pt1ReferenceAng 
            # imposto il map tool
            self.getPointMapTool().setMode(Qad_rotate_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_ANG)
            # si appresta ad attendere un punto
            self.waitForPoint(QadMsg.translate("Command_GRIPROTATE", "Specify second point: "))
            self.step = 4
            
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER NUOVO ANGOLO ROTAZIONE (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) == QgsPoint or type(value) == float: # se é stato inserito l'angolo di rotazione
            if type(value) == QgsPoint: # se é stato inserito l'angolo di rotazione con un punto                        
               self.ReferenceAng = qad_utils.getAngleBy2Pts(self.Pt1ReferenceAng, value)
            else:
               self.ReferenceAng = qad_utils.toRadians(value)
            self.getPointMapTool().ReferenceAng = self.ReferenceAng 
            
         # si appresta ad attendere un punto di rotazione
         self.waitForRotatePoint()
         
         return False
Ejemplo n.º 57
0
   def run(self, msgMapTool = False, msg = None):
      if self.plugIn.canvas.mapRenderer().destinationCrs().geographicFlag():
         self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n"))
         return True # fine comando

      currLayer = None
      if self.virtualCmd == False: # se si vuole veramente salvare la polylinea in un layer   
         # il layer corrente deve essere editabile e di tipo linea o poligono
         currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, [QGis.Line, QGis.Polygon])
         if currLayer is None:
            self.showErr(errMsg)
            return True # fine comando
      
      #=========================================================================
      # RICHIESTA PRIMO PUNTO 
      if self.step == 0: # inizio del comando
         self.WaitForFirstCorner()         
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DEL PRIMO PUNTO DEL RETTANGOLO (da step = 0)
      elif self.step == 1: # dopo aver atteso un punto si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  self.showMsg(QadMsg.translate("Command_RECTANGLE", "Window not correct."))
                  self.WaitForFirstCorner()
                  return False
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False

            value = self.getPointMapTool().point
         else: # il punto arriva come parametro della funzione
            value = msg

         if type(value) == unicode:
            if value == QadMsg.translate("Command_RECTANGLE", "Chamfer") or value == "Chamfer":
               if self.GetDistClass is not None:
                  del self.GetDistClass
               self.GetDistClass = QadGetDistClass(self.plugIn)
               prompt = QadMsg.translate("Command_RECTANGLE", "Specify first chamfer distance for rectangle <{0}>: ")
               self.GetDistClass.msg = prompt.format(str(self.gapValue1))
               self.GetDistClass.dist = self.gapValue1
               self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE
               self.step = 4
               self.GetDistClass.run(msgMapTool, msg)     
            elif value == QadMsg.translate("Command_RECTANGLE", "Fillet") or value == "Fillet":
               if self.GetDistClass is not None:
                  del self.GetDistClass
               self.GetDistClass = QadGetDistClass(self.plugIn)
               prompt = QadMsg.translate("Command_RECTANGLE", "Specify rectangle fillet radius <{0}>: ")
               self.GetDistClass.msg = prompt.format(str(self.gapValue1))
               self.GetDistClass.dist = self.gapValue1
               self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE
               self.step = 3
               self.GetDistClass.run(msgMapTool, msg)     
         elif type(value) == QgsPoint:
            self.firstCorner = value
            self.getPointMapTool().firstCorner = self.firstCorner
            self.WaitForSecondCorner(currLayer)         

         return False # continua


      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DEL SECONDO PUNTO DEL RETTANGOLO (da step = 1)
      elif self.step == 2: # dopo aver atteso un punto si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  self.showMsg(QadMsg.translate("Command_RECTANGLE", "Window not correct."))
                  self.WaitForSecondCorner(currLayer)
                  return False
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False

            value = self.getPointMapTool().point
         else: # il punto arriva come parametro della funzione
            value = msg

         if type(value) == unicode:
            if value == QadMsg.translate("Command_RECTANGLE", "Area") or value == "Area":
               msg = QadMsg.translate("Command_RECTANGLE", "Enter rectangle area in current units <{0}>: ")
               # si appresta ad attendere un numero reale         
               # msg, inputType, default, keyWords, valori positivi
               self.waitFor(msg.format(str(self.area)), QadInputTypeEnum.FLOAT, \
                            self.area, "", \
                            QadInputModeEnum.NOT_ZERO | QadInputModeEnum.NOT_NEGATIVE)
               self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER)
                  
               self.step = 6
            elif value == QadMsg.translate("Command_RECTANGLE", "Dimensions") or value == "Dimensions":
               if self.GetDistClass is not None:
                  del self.GetDistClass
               self.GetDistClass = QadGetDistClass(self.plugIn)
               prompt = QadMsg.translate("Command_RECTANGLE", "Specify length for rectangle <{0}>: ")
               self.GetDistClass.msg = prompt.format(str(self.dim1))
               self.GetDistClass.dist = self.dim1
               self.step = 10
               self.GetDistClass.run(msgMapTool, msg)              
            elif value == QadMsg.translate("Command_RECTANGLE", "Rotation") or value == "Rotation":
               keyWords = QadMsg.translate("Command_RECTANGLE", "Points")
               self.defaultValue = self.rot
               prompt = QadMsg.translate("Command_RECTANGLE", "Specify rotation angle or [{0}] <{1}>: ").format(keyWords, str(qad_utils.toDegrees(self.rot)))
               
               englishKeyWords = "Points"
               keyWords += "_" + englishKeyWords
               # si appresta ad attendere un punto o un numero reale         
               # msg, inputType, default, keyWords, valori non nulli
               self.waitFor(prompt, \
                            QadInputTypeEnum.POINT2D | QadInputTypeEnum.FLOAT | QadInputTypeEnum.KEYWORDS, \
                            self.rot, keyWords)
               self.getPointMapTool().setMode(Qad_rectangle_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_CORNER)
               
               self.step = 12
         elif type(value) == QgsPoint:
            self.vertices.extend(qad_utils.getRectByCorners(self.firstCorner, value, self.rot, \
                                                            self.gapType, self.gapValue1, self.gapValue2))

            if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer
               self.addRectangleToLayer(currLayer)
            return True       

         return False # continua

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA RAGGIO DI CURVATURA (da step = 1)
      elif self.step == 3:
         if self.GetDistClass.run(msgMapTool, msg) == True:
            if self.GetDistClass.dist is not None:
               self.gapValue1 = self.GetDistClass.dist
               if self.gapValue1 == 0:
                  self.gapType = 0 # 0 = Angoli retti
               else:
                  self.gapType = 1 # 1 = Raccorda i segmenti

            self.WaitForFirstCorner()
            self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza                     
         return False # fine comando

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA PRIMA DISTANZA DI CIMATURA (da step = 1)
      elif self.step == 4:
         if self.GetDistClass.run(msgMapTool, msg) == True:
            if self.GetDistClass.dist is not None:
               self.gapValue1 = self.GetDistClass.dist
               
               if self.GetDistClass is not None:
                  del self.GetDistClass
               self.GetDistClass = QadGetDistClass(self.plugIn)
               prompt = QadMsg.translate("Command_RECTANGLE", "Specify second chamfer distance for rectangle <{0}>: ")
               self.GetDistClass.msg = prompt.format(str(self.gapValue2))
               self.GetDistClass.dist = self.gapValue2
               self.GetDistClass.inputMode = QadInputModeEnum.NOT_NEGATIVE
               self.step = 5
               self.GetDistClass.run(msgMapTool, msg)  
            else:   
               self.WaitForFirstCorner()
               self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza                                 
         return False # fine comando
 
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA SECONDA DISTANZA DI CIMATURA (da step = 1)
      elif self.step == 5:
         if self.GetDistClass.run(msgMapTool, msg) == True:
            if self.GetDistClass.dist is not None:
               self.gapValue2 = self.GetDistClass.dist               
               if self.gapValue1 == 0 or self.gapValue2 == 0:
                  self.gapType = 0 # 0 = Angoli retti
               else:
                  self.gapType = 2 # 2 = Cima i segmenti
                                   
            self.WaitForFirstCorner()
            self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di distanza                     
         return False # fine comando
 
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA AREA RETTANGOLO (da step = 2)
      elif self.step == 6: # dopo aver atteso un punto si riavvia il comando
         keyWords = QadMsg.translate("Command_RECTANGLE", "Length") + "/" + \
                    QadMsg.translate("Command_RECTANGLE", "Width")
         englishKeyWords = "Length" + "/" + "Width"
         
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  self.defaultValue = QadMsg.translate("Command_RECTANGLE", "Length")
                  prompt = QadMsg.translate("Command_RECTANGLE", "Calcolate the rectangle dimensions based on [{0}] <{1}>: ").format(keyWords, self.defaultValue)
                        
                  keyWords += "_" + englishKeyWords
                  # si appresta ad attendere una parola chiave         
                  # msg, inputType, default, keyWords, valori positivi
                  self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \
                               self.defaultValue, \
                               keyWords, QadInputModeEnum.NONE)                  
                  
                  self.step = 7
                  return False
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False

            value = self.getPointMapTool().point
         else: # il punto arriva come parametro della funzione
            value = msg

         if type(value) == float: # é stata inserita l'area
            self.area = value
            self.defaultValue = QadMsg.translate("Command_RECTANGLE", "Length")
            prompt = QadMsg.translate("Command_RECTANGLE", "Calcolate the rectangle dimensions based on [{0}] <{1}>: ").format(keyWords, self.defaultValue)
                  
            keyWords += "_" + englishKeyWords
            # si appresta ad attendere una parola chiave         
            # msg, inputType, default, keyWords, valori positivi
            self.waitFor(prompt, QadInputTypeEnum.KEYWORDS, \
                         self.defaultValue, \
                         keyWords, QadInputModeEnum.NONE)
            self.step = 7
         return False
            
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DELLA MODALITA' (LUNGHEZZA / LARGHEZZA) DATA L'AREA (da step = 6)
      elif self.step == 7: # dopo aver atteso un punto o un numero reale si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  value = self.defaultValue
                  return True # fine comando
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False
            else:
               return False
         else: # il punto arriva come parametro della funzione
            value = msg

         if value == QadMsg.translate("Command_RECTANGLE", "Length") or value == "Length":
            if self.GetDistClass is not None:
               del self.GetDistClass
            self.GetDistClass = QadGetDistClass(self.plugIn)
            prompt = QadMsg.translate("Command_RECTANGLE", "Enter length for rectangle <{0}>: ")
            self.GetDistClass.msg = prompt.format(str(self.dim1))
            self.GetDistClass.dist = self.dim1
            self.step = 8
            self.GetDistClass.run(msgMapTool, msg)              
         elif value == QadMsg.translate("Command_RECTANGLE", "Width") or value == "Width":
            if self.GetDistClass is not None:
               del self.GetDistClass
            self.GetDistClass = QadGetDistClass(self.plugIn)
            prompt = QadMsg.translate("Command_RECTANGLE", "Enter width for rectangle <{0}>: ")
            self.GetDistClass.msg = prompt.format(str(self.dim1))
            self.GetDistClass.dist = self.dim1
            self.step = 9
            self.GetDistClass.run(msgMapTool, msg)              
            
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO DATA L'AREA (da step = 7)
      elif self.step == 8:
         if self.GetDistClass.run(msgMapTool, msg) == True:
            if self.GetDistClass.dist is not None:
					self.vertices.extend(qad_utils.getRectByAreaAndLength(self.firstCorner, self.area, self.GetDistClass.dist, \
																							self.rot, self.gapType, self.gapValue1, self.gapValue2))	
					if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer
						self.addRectangleToLayer(currLayer)
					return True # fine comando		
         return False
            
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO DATA L'AREA (da step = 7)
      elif self.step == 9:
         if self.GetDistClass.run(msgMapTool, msg) == True:
            if self.GetDistClass.dist is not None:
					self.vertices.extend(qad_utils.getRectByAreaAndWidth(self.firstCorner, self.area, self.GetDistClass.dist, \
																							self.rot, self.gapType, self.gapValue1, self.gapValue2))	
					if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer
						self.addRectangleToLayer(currLayer)
					return True # fine comando		
         return False
            
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA LUNGHEZZA RETTANGOLO (da step = 2)
      elif self.step == 10:
         if self.GetDistClass.run(msgMapTool, msg) == True:
            if self.GetDistClass.dist is not None:
               self.dim1 = self.GetDistClass.dist

            if self.GetDistClass is not None:
               del self.GetDistClass
            self.GetDistClass = QadGetDistClass(self.plugIn)
            prompt = QadMsg.translate("Command_RECTANGLE", "Enter width for rectangle <{0}>: ")
            self.GetDistClass.msg = prompt.format(str(self.dim1))
            self.GetDistClass.dist = self.dim1
            self.step = 11
            self.GetDistClass.run(msgMapTool, msg)              
                         
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA LARGHEZZA RETTANGOLO (da step = 10)
      elif self.step == 11:
         if self.GetDistClass.run(msgMapTool, msg) == True:
            if self.GetDistClass.dist is not None:
               self.vertices.extend(qad_utils.getRectByCornerAndDims(self.firstCorner, self.dim1, self.GetDistClass.dist, \
                                                                     self.rot, self.gapType, self.gapValue1, self.gapValue2))   
               if self.virtualCmd == False: # se si vuole veramente salvare i buffer in un layer
                  self.addRectangleToLayer(currLayer)
               return True # fine comando      
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 2)
      elif self.step == 12: # dopo aver atteso un punto si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  value = self.defaultValue
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False
            else:
               value = self.getPointMapTool().point
         else: # il punto arriva come parametro della funzione
            value = msg

         if type(value) == unicode:
            if value == QadMsg.translate("Command_RECTANGLE", "Points") or value == "Points":
               # si appresta ad attendere l'angolo di rotazione                      
               if self.GetAngleClass is not None:
                  del self.GetAngleClass                  
               self.GetAngleClass = QadGetAngleClass(self.plugIn)
               self.GetAngleClass.msg = QadMsg.translate("Command_RECTANGLE", "Specify first point: ")
               self.GetAngleClass.angle = self.rot
               self.step = 13
               self.GetAngleClass.run(msgMapTool, msg)               
         elif type(value) == QgsPoint:
            self.rot = qad_utils.getAngleBy2Pts(self.firstCorner, value)
            self.WaitForSecondCorner(currLayer)
         elif type(value) == float:
            self.rot = qad_utils.toRadians(value)
            self.WaitForSecondCorner(currLayer)
            
         return False # continua
      
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA ROTAZIONE RETTANGOLO (da step = 12)
      elif self.step == 13:
         if self.GetAngleClass.run(msgMapTool, msg) == True:
            if self.GetAngleClass.angle is not None:
               self.rot = self.GetAngleClass.angle
               self.plugIn.setLastRot(self.rot)
               self.WaitForSecondCorner(currLayer)
               self.getPointMapTool().refreshSnapType() # aggiorno lo snapType che può essere variato dal maptool di rotazione                     
Ejemplo n.º 58
0
 def scale(self, basePt, scale):
     self.center = qad_utils.scalePoint(self.center, basePt, scale)
     newStartPt = qad_utils.scalePoint(self.getStartPt(), basePt, scale)
     newEndPt = qad_utils.scalePoint(self.getEndPt(), basePt, scale)
     self.startAngle = qad_utils.getAngleBy2Pts(self.center, newStartPt)
     self.endAngle = qad_utils.getAngleBy2Pts(self.center, newEndPt)