Esempio n. 1
0
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.selectedEntityGripPoints = [
        ]  # lista in cui ogni elemento è una entità + una lista di punti da stirare
        self.__highlight = QadHighlight(self.canvas)
Esempio n. 2
0
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.entitySet = None
        self.basePt = None
        self.arrayType = None
        self.distanceBetweenRows = None
        self.distanceBetweenCols = None
        self.itemsRotation = None

        # serie rettangolare
        self.rectangleAngle = None
        self.rectangleCols = None
        self.rectangleRows = None
        self.firstPt = None

        # serie traiettoria
        self.pathTangentDirection = None
        self.pathRows = None
        self.pathItemsNumber = None
        self.pathLinearObjectList = None

        # serie polare
        self.centerPt = None
        self.polarItemsNumber = None
        self.polarAngleBetween = None
        self.polarRows = None

        self.__highlight = QadHighlight(self.canvas)
Esempio n. 3
0
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.SSGeomList = [
        ]  # lista di entità da stirare con geom di selezione
        self.__highlight = QadHighlight(self.canvas)
Esempio n. 4
0
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.entitySet = QadEntitySet()
        self.seriesLen = 0
        self.adjust = False
        self.__highlight = QadHighlight(self.canvas)
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.entity = None
        self.arc = None
        self.coordTransform = None
        self.__highlight = QadHighlight(self.canvas)
Esempio n. 6
0
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.Pt1ReferenceLen = None
        self.ReferenceLen = 0
        self.Pt1NewLen = None
        self.entitySet = QadEntitySet()
        self.__highlight = QadHighlight(self.canvas)
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.firstPt = None
        self.layer = None
        self.subGeom = None
        self.offSet = 0
        self.lastOffSetOnLeftSide = 0
        self.lastOffSetOnRightSide = 0
        self.gapType = 0
        self.__highlight = QadHighlight(self.canvas)
Esempio n. 8
0
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.firstPt = None
        self.mode = None

        self.layer = None
        self.linearObjectList = qad_utils.QadLinearObjectList()
        self.linearObject = None
        self.startPt = None
        self.endPt = None
        self.tolerance2ApproxCurve = None
        self.__highlight = QadHighlight(self.canvas)
Esempio n. 9
0
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.firstPt = None
        self.mode = None

        self.layer = None
        self.linearObjectList = qad_utils.QadLinearObjectList()
        self.tolerance2ApproxCurve = None
        self.vertexAt = 0
        self.vertexPt = None
        self.after = True
        self.basePt = None
        self.__highlight = QadHighlight(self.canvas)
Esempio n. 10
0
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.entitySet = None
      self.basePt = None
      self.arrayType = None
      self.distanceBetweenRows = None
      self.distanceBetweenCols = None
      self.itemsRotation = None

      # serie rettangolare
      self.rectangleAngle = None
      self.rectangleCols = None
      self.rectangleRows = None
      self.firstPt = None

      # serie traiettoria
      self.pathTangentDirection = None
      self.pathRows = None
      self.pathItemsNumber = None
      self.pathLinearObjectList = None

      # serie polare
      self.centerPt = None
      self.polarItemsNumber = None
      self.polarAngleBetween = None
      self.polarRows = None

      self.__highlight = QadHighlight(self.canvas)
Esempio n. 11
0
 def __init__(self, plugIn):
    QadGetPoint.__init__(self, plugIn)
                      
    self.basePt = None
    self.entitySet = QadEntitySet()
    self.seriesLen = 0
    self.adjust = False
    self.__highlight = QadHighlight(self.canvas)
Esempio n. 12
0
 def __init__(self, plugIn):
    QadGetPoint.__init__(self, plugIn)
                      
    self.basePt = None
    self.entity = None
    self.arc = None 
    self.coordTransform = None
    self.__highlight = QadHighlight(self.canvas)
Esempio n. 13
0
 def __init__(self, plugIn):
    QadGetPoint.__init__(self, plugIn)
                      
    self.basePt = None
    self.Pt1ReferenceLen = None
    self.ReferenceLen = 0
    self.Pt1NewLen = None
    self.entitySet = QadEntitySet()
    self.__highlight = QadHighlight(self.canvas)
Esempio n. 14
0
 def __init__(self, plugIn):
    QadGetPoint.__init__(self, plugIn)
                      
    self.firstPt = None
    self.layer = None
    self.subGeom = None
    self.offSet = 0
    self.lastOffSetOnLeftSide = 0
    self.lastOffSetOnRightSide = 0
    self.gapType = 0     
    self.__highlight = QadHighlight(self.canvas)
Esempio n. 15
0
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)

      self.firstPt = None
      self.mode = None
                       
      self.layer = None 
      self.linearObjectList = qad_utils.QadLinearObjectList()
      self.linearObject = None
      self.startPt = None
      self.endPt = None
      self.tolerance2ApproxCurve = None
      self.__highlight = QadHighlight(self.canvas)
Esempio n. 16
0
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)

      self.firstPt = None
      self.mode = None
                       
      self.layer = None
      self.linearObjectList = qad_utils.QadLinearObjectList()
      self.tolerance2ApproxCurve = None
      self.vertexAt = 0
      self.vertexPt = None
      self.after = True 
      self.basePt = None
      self.__highlight = QadHighlight(self.canvas)
Esempio n. 17
0
class Qad_array_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.entitySet = None
        self.basePt = None
        self.arrayType = None
        self.distanceBetweenRows = None
        self.distanceBetweenCols = None
        self.itemsRotation = None

        # serie rettangolare
        self.rectangleAngle = None
        self.rectangleCols = None
        self.rectangleRows = None
        self.firstPt = None

        # serie traiettoria
        self.pathTangentDirection = None
        self.pathRows = None
        self.pathItemsNumber = None
        self.pathLinearObjectList = None

        # serie polare
        self.centerPt = None
        self.polarItemsNumber = None
        self.polarAngleBetween = None
        self.polarRows = None

        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    #============================================================================
    # doRectangleArray
    #============================================================================
    def doRectangleArray(self):
        self.__highlight.reset()

        entity = QadEntity()
        # copio entitySet
        entitySet = QadEntitySet(self.entitySet)

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer

            while len(layerEntitySet.featureIds) > 0:
                featureId = layerEntitySet.featureIds[0]
                # verifico se l'entità appartiene ad uno stile di quotatura
                dimEntity = QadDimStyles.getDimEntity(layer, featureId)

                f = layerEntitySet.getFeature(featureId)
                if f is None:
                    del layerEntitySet.featureIds[0]
                    continue

                # verifico se l'entità appartiene ad uno stile di quotatura
                dimEntity = QadDimStyles.getDimEntity(layer, f.id())
                if dimEntity is None:
                    entity.set(layer, f.id())
                    if qad_array_fun.arrayRectangleEntity(self.plugIn, entity, self.basePt, self.rectangleRows, self.rectangleCols, \
                                                          self.distanceBetweenRows, self.distanceBetweenCols, self.rectangleAngle, self.itemsRotation,
                                                          False, self.__highlight) == False:
                        return
                    del layerEntitySet.featureIds[0]  # la rimuovo da entitySet
                else:
                    if qad_array_fun.arrayRectangleEntity(self.plugIn, dimEntity, self.basePt, self.rectangleRows, self.rectangleCols, \
                                                          self.distanceBetweenRows, self.distanceBetweenCols, self.rectangleAngle, self.itemsRotation,
                                                          False, self.__highlight) == False:
                        return
                    dimEntitySet = dimEntity.getEntitySet()
                    entitySet.subtract(dimEntitySet)  # la rimuovo da entitySet

    #============================================================================
    # doPathArray
    #============================================================================
    def doPathArray(self):
        self.__highlight.reset()

        entity = QadEntity()
        # copio entitySet
        entitySet = QadEntitySet(self.entitySet)

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer

            while len(layerEntitySet.featureIds) > 0:
                featureId = layerEntitySet.featureIds[0]

                f = layerEntitySet.getFeature(featureId)
                if f is None:
                    del layerEntitySet.featureIds[0]
                    continue

                # verifico se l'entità appartiene ad uno stile di quotatura
                dimEntity = QadDimStyles.getDimEntity(layer, f.id())
                if dimEntity is None:
                    entity.set(layer, f.id())
                    if qad_array_fun.arrayPathEntity(self.plugIn, entity, self.basePt, self.pathRows, self.pathItemsNumber, \
                                                     self.distanceBetweenRows, self.distanceBetweenCols, self.pathTangentDirection, self.itemsRotation, \
                                                     self.pathLinearObjectList, self.distanceFromStartPt, \
                                                     False, self.__highlight) == False:
                        return
                    del layerEntitySet.featureIds[0]  # la rimuovo da entitySet
                else:
                    if qad_array_fun.arrayPathEntity(self.plugIn, dimEntity, self.basePt, self.pathRows, self.pathItemsNumber, \
                                                     self.distanceBetweenRows, self.distanceBetweenCols, self.pathTangentDirection, self.itemsRotation, \
                                                     self.pathLinearObjectList, self.distanceFromStartPt, \
                                                     False, self.__highlight) == False:
                        return
                    dimEntitySet = dimEntity.getEntitySet()
                    entitySet.subtract(dimEntitySet)  # la rimuovo da entitySet

    #============================================================================
    # doPolarArray
    #============================================================================
    def doPolarArray(self):
        self.__highlight.reset()

        entity = QadEntity()
        # copio entitySet
        entitySet = QadEntitySet(self.entitySet)

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer

            while len(layerEntitySet.featureIds) > 0:
                featureId = layerEntitySet.featureIds[0]

                f = layerEntitySet.getFeature(featureId)
                if f is None:
                    del layerEntitySet.featureIds[0]
                    continue

                # verifico se l'entità appartiene ad uno stile di quotatura
                dimEntity = QadDimStyles.getDimEntity(layer, f.id())
                if dimEntity is None:
                    entity.set(layer, f.id())
                    if qad_array_fun.arrayPolarEntity(self.plugIn, entity, self.basePt, self.centerPt, self.polarItemsNumber, \
                                                      self.polarAngleBetween, self.polarRows, self.distanceBetweenRows, self.itemsRotation, \
                                                      False, self.__highlight) == False:
                        return
                    del layerEntitySet.featureIds[0]  # la rimuovo da entitySet
                else:
                    if qad_array_fun.arrayPolarEntity(self.plugIn, dimEntity, self.basePt, self.centerPt, self.polarItemsNumber, \
                                                      self.polarAngleBetween, self.polarRows, self.distanceBetweenRows, self.itemsRotation, \
                                                      False, self.__highlight) == False:
                        return
                    dimEntitySet = dimEntity.getEntitySet()
                    entitySet.subtract(dimEntitySet)  # la rimuovo da entitySet

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

#       # noto il punto base si richiede il secondo punto
#       if self.mode == Qad_array_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_COPY_PT:
#          self.setCopiedGeometries(self.tmpPoint)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode
        # non si richiede niente
        if self.mode == Qad_array_maptool_ModeEnum.NONE:
            self.setSelectionMode(QadGetPointSelectionModeEnum.NONE)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # si richiede il punto base
        elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_BASE_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # si richiede il primo punto per la distanza tra colonne
        elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_COLUMN_SPACE_FIRST_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # si richiede il primo punto per la dimensione della cella
        elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_1PT_CELL:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # si richiede il psecondo punto per la dimensione della cella
        elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_2PT_CELL:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE)
            self.setStartPoint(self.firstPt)
        # si richiede il primo punto per la distanza tra righe
        elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_ROW_SPACE_FIRST_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
Esempio n. 18
0
class Qad_scale_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.Pt1ReferenceLen = None
        self.ReferenceLen = 0
        self.Pt1NewLen = None
        self.entitySet = QadEntitySet()
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    #============================================================================
    # scale
    #============================================================================
    def scale(self, f, basePt, scale, layerEntitySet, entitySet):
        # verifico se l'entità appartiene ad uno stile di quotatura
        dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())

        if dimEntity is None:
            # scalo la feature e la rimuovo da entitySet (é la prima)
            f.setGeometry(
                qad_utils.scaleQgsGeometry(f.geometry(), basePt, scale))
            self.__highlight.addGeometry(f.geometry(), layerEntitySet.layer)
            del layerEntitySet.featureIds[0]
        else:
            # scalo la quota e la rimuovo da entitySet
            dimEntitySet = dimEntity.getEntitySet()
            dimEntity.scale(basePt, scale)
            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)

    #============================================================================
    # addScaledGeometries
    #============================================================================
    def addScaledGeometries(self, scale):
        self.__highlight.reset()

        # copio entitySet
        entitySet = QadEntitySet(self.entitySet)

        if scale <= 0:
            return

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer

            transformedBasePt = self.canvas.mapSettings(
            ).mapToLayerCoordinates(layer, self.basePt)

            while len(layerEntitySet.featureIds) > 0:
                featureId = layerEntitySet.featureIds[0]
                f = layerEntitySet.getFeature(featureId)
                self.scale(f, transformedBasePt, scale, layerEntitySet,
                           entitySet)

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        # noto il punto base si richiede il secondo punto per la scala
        if self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_SCALE_PT:
            scale = qad_utils.getDistance(self.basePt, self.tmpPoint)
            self.addScaledGeometries(scale)
        # noto il primo punto si richiede il secondo punto per la lunghezza di riferimento
        elif self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_LEN_PT:
            len = qad_utils.getDistance(self.basePt, self.tmpPoint)
            scale = len / self.ReferenceLen
            self.addScaledGeometries(scale)
        # noto il primo punto si richiede il secondo punto per la nuova lunghezza
        elif self.mode == Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT:
            len = qad_utils.getDistance(self.Pt1NewLen, self.tmpPoint)
            scale = len / self.ReferenceLen
            self.addScaledGeometries(scale)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode
        # noto niente si richiede il punto base
        if self.mode == Qad_scale_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
            self.clear()
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.__highlight.reset()
        # noto il punto base si richiede il secondo punto per la scala
        elif self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_SCALE_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.basePt)
        # si richiede il primo punto per la lunghezza di riferimento
        elif self.mode == Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_PT_REFERENCE_LEN:
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.__highlight.reset()
        # noto il primo punto si richiede il secondo punto per la lunghezza di riferimento
        elif self.mode == Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_LEN:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.Pt1ReferenceLen)
        # noto il punto base si richiede il secondo punto per la nuova lunghezza
        elif self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_LEN_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.basePt)
        # si richiede il primo punto per la nuova lunghezza
        elif self.mode == Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_NEW_LEN_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.__highlight.reset()
        # noto il primo punto si richiede il secondo punto per la nuova lunghezza
        elif self.mode == Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.Pt1NewLen)
Esempio n. 19
0
class Qad_gripLineToArcConvert_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)

      self.firstPt = None
      self.mode = None
                       
      self.layer = None 
      self.linearObjectList = qad_utils.QadLinearObjectList()
      self.linearObject = None
      self.startPt = None
      self.endPt = None
      self.tolerance2ApproxCurve = None
      self.__highlight = QadHighlight(self.canvas)


   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None

   def setLinearObjectList(self, linearObjectList, layer, partAt):
      self.linearObjectList.set(linearObjectList)
      self.layer = layer
      self.tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))                            
      self.linearObject = self.linearObjectList.getLinearObjectAt(partAt)
      self.firstPt = self.linearObject.getMiddlePt()
      self.startPt = self.linearObject.getStartPt()
      self.endPt = self.linearObject.getEndPt()
    
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      self.__highlight.reset()
      ok = False
       
      # noti il punto iniziale e finale dell'arco si richiede il punto intermedio
      if self.mode == Qad_gripLineToArcConvert_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_SECOND_PT:
         if self.linearObject is None:
            return
         arc = QadArc()
         if arc.fromStartSecondEndPts(self.startPt, self.tmpPoint, self.endPt) == False:
            return
         if qad_utils.ptNear(self.startPt, arc.getStartPt()):
            self.linearObject.setArc(arc, False) # arco non inverso
         else:
            self.linearObject.setArc(arc, True) # arco inverso
         ok = True
      
      if ok:
         pts = self.linearObjectList.asPolyline(self.tolerance2ApproxCurve)
         if self.layer.geometryType() == QGis.Polygon:
            geom = QgsGeometry.fromPolygon([pts])
         else:
            geom = QgsGeometry.fromPolyline(pts)
         # trasformo la geometria nel crs del layer
         self.__highlight.addGeometry(self.mapToLayerCoordinates(self.layer, geom), self.layer)
      
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
            
      # noti il punto iniziale e finale dell'arco si richiede il punto intermedio
      if self.mode == Qad_gripLineToArcConvert_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_SECOND_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)   
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.firstPt)
      # non si richiede niente
      elif self.mode == Qad_pedit_maptool_ModeEnum.NONE:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)   
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
Esempio n. 20
0
class Qad_scale_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.Pt1ReferenceLen = None
      self.ReferenceLen = 0
      self.Pt1NewLen = None
      self.entitySet = QadEntitySet()
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    


   #============================================================================
   # scale
   #============================================================================
   def scale(self, f, basePt, scale, layerEntitySet, entitySet):
      # verifico se l'entità appartiene ad uno stile di quotatura
      dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())
           
      if dimEntity is None:
         # scalo la feature e la rimuovo da entitySet (é la prima)
         f.setGeometry(qad_utils.scaleQgsGeometry(f.geometry(), basePt, scale))
         self.__highlight.addGeometry(f.geometry(), layerEntitySet.layer)
         del layerEntitySet.featureIds[0]
      else:
         # scalo la quota e la rimuovo da entitySet
         dimEntitySet = dimEntity.getEntitySet()
         dimEntity.scale(basePt, scale)
         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)

   
   #============================================================================
   # addScaledGeometries
   #============================================================================
   def addScaledGeometries(self, scale):
      self.__highlight.reset()
      
      # copio entitySet
      entitySet = QadEntitySet(self.entitySet)
      
      if scale <= 0:
         return
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer

         transformedBasePt = self.canvas.mapSettings().mapToLayerCoordinates(layer, self.basePt)

         while len(layerEntitySet.featureIds) > 0:
            featureId = layerEntitySet.featureIds[0]
            f = layerEntitySet.getFeature(featureId)        
            self.scale(f, transformedBasePt, scale, layerEntitySet, entitySet)
            
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
                     
      # noto il punto base si richiede il secondo punto per la scala
      if self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_SCALE_PT:
         scale = qad_utils.getDistance(self.basePt, self.tmpPoint)
         self.addScaledGeometries(scale)                           
      # noto il primo punto si richiede il secondo punto per la lunghezza di riferimento
      elif self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_LEN_PT:
         len = qad_utils.getDistance(self.basePt, self.tmpPoint)
         scale = len / self.ReferenceLen
         self.addScaledGeometries(scale)                           
      # noto il primo punto si richiede il secondo punto per la nuova lunghezza
      elif self.mode == Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT:
         len = qad_utils.getDistance(self.Pt1NewLen, self.tmpPoint)
         scale = len / self.ReferenceLen
         self.addScaledGeometries(scale)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il punto base
      if self.mode == Qad_scale_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
         self.clear()
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il punto base si richiede il secondo punto per la scala
      elif self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_SCALE_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
      # si richiede il primo punto per la lunghezza di riferimento
      elif self.mode == Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_PT_REFERENCE_LEN:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il primo punto si richiede il secondo punto per la lunghezza di riferimento
      elif self.mode == Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_LEN:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.Pt1ReferenceLen)
      # noto il punto base si richiede il secondo punto per la nuova lunghezza
      elif self.mode == Qad_scale_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_NEW_LEN_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
      # si richiede il primo punto per la nuova lunghezza
      elif self.mode == Qad_scale_maptool_ModeEnum.ASK_FOR_FIRST_NEW_LEN_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il primo punto si richiede il secondo punto per la nuova lunghezza
      elif self.mode == Qad_scale_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_NEW_LEN_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.Pt1NewLen)
Esempio n. 21
0
class Qad_stretch_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.SSGeomList = [
        ]  # lista di entità da stirare con geom di selezione
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    #============================================================================
    # stretch
    #============================================================================
    def stretch(self, entity, containerGeom, offSetX, offSetY,
                tolerance2ApproxCurve):
        # entity = entità da stirare
        # ptList = lista dei punti da stirare
        # offSetX, offSetY = spostamento da fare
        # tolerance2ApproxCurve = tolleranza per ricreare le curve
        # verifico se l'entità appartiene ad uno stile di quotatura
        if entity.whatIs() == "ENTITY":
            stretchedGeom = entity.getGeometry()
            # controllo inserito perchè con le quote, questa viene cancellata e ricreata quindi alcuni oggetti potrebbero non esistere più
            if stretchedGeom is None:  # se non c'è lo salto senza errore
                return True
            # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
            coordTransform = QgsCoordinateTransform(
                entity.layer.crs(),
                self.canvas.mapSettings().destinationCrs())
            stretchedGeom.transform(coordTransform)
            # stiro la feature
            stretchedGeom = qad_stretch_fun.stretchQgsGeometry(stretchedGeom, containerGeom, \
                                                               offSetX, offSetY, \
                                                               tolerance2ApproxCurve)

            if stretchedGeom is not None:
                # trasformo la geometria nel crs del layer
                coordTransform = QgsCoordinateTransform(
                    self.canvas.mapSettings().destinationCrs(),
                    entity.layer.crs())
                stretchedGeom.transform(coordTransform)
                self.__highlight.addGeometry(stretchedGeom, entity.layer)

        elif entity.whatIs() == "DIMENTITY":
            newDimEntity = QadDimEntity(entity)  # la copio
            # stiro la quota
            newDimEntity.stretch(containerGeom, offSetX, offSetY)
            self.__highlight.addGeometry(
                newDimEntity.textualFeature.geometry(),
                newDimEntity.getTextualLayer())
            self.__highlight.addGeometries(
                newDimEntity.getLinearGeometryCollection(),
                newDimEntity.getLinearLayer())
            self.__highlight.addGeometries(
                newDimEntity.getSymbolGeometryCollection(),
                newDimEntity.getSymbolLayer())

        return True

    #============================================================================
    # addStretchedGeometries
    #============================================================================
    def addStretchedGeometries(self, newPt):
        self.__highlight.reset()

        dimElaboratedList = []  # lista delle quotature già elaborate

        tolerance2ApproxCurve = QadVariables.get(
            QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
        offSetX = newPt.x() - self.basePt.x()
        offSetY = newPt.y() - self.basePt.y()

        entity = QadEntity()
        for SSGeom in self.SSGeomList:
            # copio entitySet
            entitySet = QadEntitySet(SSGeom[0])
            geomSel = SSGeom[1]

            for layerEntitySet in entitySet.layerEntitySetList:
                layer = layerEntitySet.layer

                for featureId in layerEntitySet.featureIds:
                    entity.set(layer, featureId)

                    # verifico se l'entità appartiene ad uno stile di quotatura
                    dimEntity = QadDimStyles.getDimEntity(entity)
                    if dimEntity is None:
                        self.stretch(entity, geomSel, offSetX, offSetY,
                                     tolerance2ApproxCurve)
                    else:
                        found = False
                        for dimElaborated in dimElaboratedList:
                            if dimElaborated == dimEntity:
                                found = True

                        if found == False:  # quota non ancora elaborata
                            dimElaboratedList.append(dimEntity)
                            self.stretch(dimEntity, geomSel, offSetX, offSetY,
                                         tolerance2ApproxCurve)

    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_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
            self.addStretchedGeometries(self.tmpPoint)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode

        # si richiede la selezione del primo punto del rettangolo per selezionare gli oggetti
        if self.mode == Qad_stretch_maptool_ModeEnum.ASK_FOR_FIRST_PT_RECTANGLE:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # noto niente il primo punto del rettangolo si richiede il secondo punto
        elif self.mode == Qad_stretch_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_RECTANGLE:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE)
        # noto niente si richiede il punto base
        elif self.mode == Qad_stretch_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # noto il punto base si richiede il secondo punto
        elif self.mode == Qad_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.basePt)
Esempio n. 22
0
class Qad_gripStretch_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.selectedEntityGripPoints = [
        ]  # lista in cui ogni elemento è una entità + una lista di punti da stirare
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    #============================================================================
    # getSelectedEntityGripPointNdx
    #============================================================================
    def getSelectedEntityGripPointNdx(self, entity):
        # lista delle entityGripPoint con dei grip point selezionati
        # cerca la posizione di un'entità nella lista in cui ogni elemento è una entità + una lista di punti da stirare
        i = 0
        tot = len(self.selectedEntityGripPoints)
        while i < tot:
            selectedEntityGripPoint = self.selectedEntityGripPoints[i]
            if selectedEntityGripPoint[0] == entity:
                return i
            i = i + 1
        return -1

    #============================================================================
    # stretch
    #============================================================================
    def stretch(self, entity, ptList, offSetX, offSetY, tolerance2ApproxCurve):
        # entity = entità da stirare
        # ptList = lista dei punti da stirare
        # offSetX, offSetY = spostamento da fare
        # tolerance2ApproxCurve = tolleranza per ricreare le curve
        # entitySet = gruppo di selezione delle entità da stirare
        # verifico se l'entità appartiene ad uno stile di quotatura
        if entity.whatIs() == "ENTITY":
            stretchedGeom = entity.gripGeomStretch(self.basePt, ptList,
                                                   offSetX, offSetY,
                                                   tolerance2ApproxCurve)

            if stretchedGeom is not None:
                self.__highlight.addGeometry(stretchedGeom, entity.layer)
        elif entity.whatIs() == "DIMENTITY":
            # stiro la quota
            entity.stretch(ptList, offSetX, offSetY)
            self.__highlight.addGeometry(entity.textualFeature.geometry(),
                                         entity.getTextualLayer())
            self.__highlight.addGeometries(
                entity.getLinearGeometryCollection(), entity.getLinearLayer())
            self.__highlight.addGeometries(
                entity.getSymbolGeometryCollection(), entity.getSymbolLayer())

    #============================================================================
    # addStretchedGeometries
    #============================================================================
    def addStretchedGeometries(self, newPt):
        self.__highlight.reset()

        dimElaboratedList = []  # lista delle quotature già elaborate

        for selectedEntity in self.selectedEntityGripPoints:
            entity = selectedEntity[0]
            ptList = selectedEntity[1]
            layer = entity.layer

            tolerance2ApproxCurve = QadVariables.get(
                QadMsg.translate("Environment variables",
                                 "TOLERANCE2APPROXCURVE"))
            offSetX = newPt.x() - self.basePt.x()
            offSetY = newPt.y() - self.basePt.y()

            # verifico se l'entità appartiene ad uno stile di quotatura
            if entity.isDimensionComponent() == False:
                self.stretch(entity, ptList, offSetX, offSetY,
                             tolerance2ApproxCurve)
            else:
                dimEntity = QadDimEntity()
                if dimEntity.initByDimId(entity.dimStyle, entity.dimId):
                    found = False
                    for dimElaborated in dimElaboratedList:
                        if dimElaborated == dimEntity:
                            found = True
                    if found == False:  # quota non ancora elaborata
                        dimEntitySet = dimEntity.getEntitySet()
                        # creo un'unica lista contenente i grip points di tutti i componenti della quota
                        dimPtlist = []
                        for layerEntitySet in dimEntitySet.layerEntitySetList:
                            for featureId in layerEntitySet.featureIds:
                                componentDim = QadEntity()
                                componentDim.set(layerEntitySet.layer,
                                                 featureId)
                                i = self.getSelectedEntityGripPointNdx(
                                    componentDim)
                                if i >= 0:
                                    dimPtlist.extend(
                                        self.selectedEntityGripPoints[i][1])

                        dimElaboratedList.append(dimEntity)
                        self.stretch(dimEntity, dimPtlist, offSetX, offSetY,
                                     tolerance2ApproxCurve)

    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_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
            self.addStretchedGeometries(self.tmpPoint)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode

        # noto niente si richiede il punto base
        if self.mode == Qad_stretch_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.__highlight.reset()
        # noto il punto base si richiede il secondo punto
        elif self.mode == Qad_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.basePt)
Esempio n. 23
0
class Qad_offset_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.firstPt = None
        self.layer = None
        self.subGeom = None
        self.offSet = 0
        self.lastOffSetOnLeftSide = 0
        self.lastOffSetOnRightSide = 0
        self.gapType = 0
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    def addOffSetGeometries(self, newPt):
        self.__highlight.reset()

        # ritorna una tupla (<The squared cartesian distance>,
        #                    <minDistPoint>
        #                    <afterVertex>
        #                    <leftOf>)
        dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom)
        if self.offSet < 0:
            afterVertex = dummy[2]
            pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \
                                                               self.subGeom.vertexAt(afterVertex), \
                                                               newPt)
            offSetDistance = qad_utils.getDistance(newPt, pt)
        else:
            offSetDistance = self.offSet

            if dummy[3] < 0:  # alla sinistra
                offSetDistance = offSetDistance + self.lastOffSetOnLeftSide
            else:  # alla destra
                offSetDistance = offSetDistance + self.lastOffSetOnRightSide

        tolerance2ApproxCurve = QadVariables.get(
            QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
        # uso il crs del canvas per lavorare con coordinate piane xy
        epsg = self.canvas.mapRenderer().destinationCrs().authid()
        lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \
                                         offSetDistance, \
                                         "left" if dummy[3] < 0 else "right", \
                                         self.gapType, \
                                         tolerance2ApproxCurve)

        for line in lines:
            if self.layer.geometryType() == QGis.Polygon:
                if line[0] == line[-1]:  # se é una linea chiusa
                    offsetGeom = QgsGeometry.fromPolygon([line])
                else:
                    offsetGeom = QgsGeometry.fromPolyline(line)
            else:
                offsetGeom = QgsGeometry.fromPolyline(line)

            self.__highlight.addGeometry(
                self.mapToLayerCoordinates(self.layer, offsetGeom), self.layer)

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        # nota la distanza di offset si richiede il punto per stabilire da che parte
        if self.mode == Qad_offset_maptool_ModeEnum.OFFSET_KNOWN_ASK_FOR_SIDE_PT:
            self.addOffSetGeometries(self.tmpPoint)
        # si richiede il punto di passaggio per stabilire da che parte e a quale offset
        elif self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_PASSAGE_PT:
            self.addOffSetGeometries(self.tmpPoint)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.clear()
        self.mode = mode
        # si richiede il primo punto per calcolo offset
        if self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_FIRST_OFFSET_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.onlyEditableLayers = False
        # noto il primo punto per calcolo offset si richiede il secondo punto
        if self.mode == Qad_offset_maptool_ModeEnum.FIRST_OFFSET_PT_KNOWN_ASK_FOR_SECOND_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.firstPt)
            self.onlyEditableLayers = False
        # nota la distanza di offset si richiede il punto per stabilire da che parte
        elif self.mode == Qad_offset_maptool_ModeEnum.OFFSET_KNOWN_ASK_FOR_SIDE_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.onlyEditableLayers = False
        # si richiede il punto di passaggio per stabilire da che parte e a quale offset
        elif self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_PASSAGE_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.onlyEditableLayers = False
        # si richiede la selezione di un oggetto
        elif self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_ENTITY_SELECTION:
            self.setSelectionMode(
                QadGetPointSelectionModeEnum.ENTITY_SELECTION)
            # solo layer lineari o poligono editabili che non appartengano a quote
            layerList = []
            for layer in qad_utils.getVisibleVectorLayers(
                    self.plugIn.canvas):  # Tutti i layer vettoriali visibili
                if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \
                   layer.isEditable():
                    if len(QadDimStyles.getDimListByLayer(layer)) == 0:
                        layerList.append(layer)

            self.layersToCheck = layerList
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.onlyEditableLayers = True
Esempio n. 24
0
 def __init__(self, plugIn):
    QadGetPoint.__init__(self, plugIn)
                      
    self.basePt = None
    self.selectedEntityGripPoints = [] # lista in cui ogni elemento è una entità + una lista di punti da stirare
    self.__highlight = QadHighlight(self.canvas)
Esempio n. 25
0
class Qad_pedit_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)

      self.firstPt = None
      self.mode = None
                       
      self.layer = None
      self.linearObjectList = qad_utils.QadLinearObjectList()
      self.tolerance2ApproxCurve = None
      self.vertexAt = 0
      self.vertexPt = None
      self.after = True 
      self.basePt = None
      self.__highlight = QadHighlight(self.canvas)


   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None
      if self.basePt is not None:
         del(self.basePt)
         self.basePt = None

   def setLinearObjectList(self, linearObjectList, layer):
      self.linearObjectList.set(linearObjectList)
      self.layer = layer
      self.tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))


   def setVertexAt(self, vertexAt, after = None):
      if vertexAt == self.linearObjectList.qty():
         self.firstPt = self.linearObjectList.getLinearObjectAt(-1).getEndPt()
      else:
         self.firstPt = self.linearObjectList.getLinearObjectAt(vertexAt).getStartPt()
      
      self.vertexPt = QgsPoint(self.firstPt)
      self.vertexAt = vertexAt
      self.after = after      
    
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      self.__highlight.reset()
      tmpLinearObjectList = None           
       
      # si richiede un nuovo vertice da inserire
      if self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_NEW_VERTEX:
         if self.basePt is not None:
            offSetX = self.tmpPoint.x() - self.basePt.x()
            offSetY = self.tmpPoint.y() - self.basePt.y()
            newPt = QgsPoint(self.vertexPt.x() + offSetX, self.vertexPt.y() + offSetY)
         else:
            newPt = QgsPoint(self.tmpPoint)
            
         tmpLinearObjectList = qad_utils.QadLinearObjectList()
         tmpLinearObjectList.set(self.linearObjectList)
         if self.after: # dopo
            if self.vertexAt == tmpLinearObjectList.qty() and tmpLinearObjectList.isClosed():
               tmpLinearObjectList.insertPoint(0, newPt)
            else:
               tmpLinearObjectList.insertPoint(self.vertexAt, newPt)
         else: # prima
            if self.vertexAt == 0 and tmpLinearObjectList.isClosed():
               tmpLinearObjectList.insertPoint(tmpLinearObjectList.qty() - 1, newPt)
            else:
               tmpLinearObjectList.insertPoint(self.vertexAt - 1, newPt)
      elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_MOVE_VERTEX:
         newPt = QgsPoint(self.tmpPoint)
         tmpLinearObjectList = qad_utils.QadLinearObjectList()
         tmpLinearObjectList.set(self.linearObjectList)         
         tmpLinearObjectList.movePoint(self.vertexAt, newPt)
      
      if tmpLinearObjectList is not None:
         pts = tmpLinearObjectList.asPolyline(self.tolerance2ApproxCurve) 
         if self.layer.geometryType() == QGis.Polygon:
            geom = QgsGeometry.fromPolygon([pts])
         else:
            geom = QgsGeometry.fromPolyline(pts)
            
         # trasformo la geometria nel crs del layer
         self.__highlight.addGeometry(self.mapToLayerCoordinates(self.layer, geom), self.layer)
      
    
   def activate(self):
      QadGetPoint.activate(self)
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
            
      # si richiede la selezione di un'entità
      if self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_ENTITY_SEL:
         self.setSelectionMode(QadGetPointSelectionModeEnum.ENTITY_SELECTION)
         
         # solo layer lineari o poligono editabili che non appartengano a quote
         layerList = []
         for layer in self.plugIn.canvas.layers():
            if layer.type() == QgsMapLayer.VectorLayer and \
               (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \
               layer.isEditable():
               if len(QadDimStyles.getDimListByLayer(layer)) == 0:
                  layerList.append(layer)
         
         self.layersToCheck = layerList
         self.setSnapType(QadSnapTypeEnum.DISABLE)
      # non si richiede niente
      elif self.mode == Qad_pedit_maptool_ModeEnum.NONE:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)   
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # si richiede il primo punto per calcolo distanza di approssimazione
      # si richiede la posizione più vicina ad un vertice
      elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_FIRST_TOLERANCE_PT:
         self.onlyEditableLayers = False
         self.checkPointLayer = True
         self.checkLineLayer = True
         self.checkPolygonLayer = True
         self.setSnapType()
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)   
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # noto il primo punto per calcolo distanza di approssimazione si richiede il secondo punto
      elif self.mode == Qad_pedit_maptool_ModeEnum.FIRST_TOLERANCE_PT_KNOWN_ASK_FOR_SECOND_PT or \
           self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_NEW_VERTEX or \
           self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_MOVE_VERTEX:         
         self.onlyEditableLayers = False
         self.checkPointLayer = True
         self.checkLineLayer = True
         self.checkPolygonLayer = True
         self.setSnapType()
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)   
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.firstPt)
      # si richiede la posizione più vicina ad un vertice
      elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_VERTEX:
         self.setSnapType(QadSnapTypeEnum.DISABLE)
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)   
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # si richede il punto base (grip mode)
      elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_BASE_PT:
         self.setSnapType()
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)   
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
Esempio n. 26
0
class Qad_pedit_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.firstPt = None
        self.mode = None

        self.layer = None
        self.linearObjectList = qad_utils.QadLinearObjectList()
        self.tolerance2ApproxCurve = None
        self.vertexAt = 0
        self.vertexPt = None
        self.after = True
        self.basePt = None
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None
        if self.basePt is not None:
            del (self.basePt)
            self.basePt = None

    def setLinearObjectList(self, linearObjectList, layer):
        self.linearObjectList.set(linearObjectList)
        self.layer = layer
        self.tolerance2ApproxCurve = QadVariables.get(
            QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))

    def setVertexAt(self, vertexAt, after=None):
        if vertexAt == self.linearObjectList.qty():
            self.firstPt = self.linearObjectList.getLinearObjectAt(
                -1).getEndPt()
        else:
            self.firstPt = self.linearObjectList.getLinearObjectAt(
                vertexAt).getStartPt()

        self.vertexPt = QgsPoint(self.firstPt)
        self.vertexAt = vertexAt
        self.after = after

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        self.__highlight.reset()
        tmpLinearObjectList = None

        # si richiede un nuovo vertice da inserire
        if self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_NEW_VERTEX:
            if self.basePt is not None:
                offSetX = self.tmpPoint.x() - self.basePt.x()
                offSetY = self.tmpPoint.y() - self.basePt.y()
                newPt = QgsPoint(self.vertexPt.x() + offSetX,
                                 self.vertexPt.y() + offSetY)
            else:
                newPt = QgsPoint(self.tmpPoint)

            tmpLinearObjectList = qad_utils.QadLinearObjectList()
            tmpLinearObjectList.set(self.linearObjectList)
            if self.after:  # dopo
                if self.vertexAt == tmpLinearObjectList.qty(
                ) and tmpLinearObjectList.isClosed():
                    tmpLinearObjectList.insertPoint(0, newPt)
                else:
                    tmpLinearObjectList.insertPoint(self.vertexAt, newPt)
            else:  # prima
                if self.vertexAt == 0 and tmpLinearObjectList.isClosed():
                    tmpLinearObjectList.insertPoint(
                        tmpLinearObjectList.qty() - 1, newPt)
                else:
                    tmpLinearObjectList.insertPoint(self.vertexAt - 1, newPt)
        elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_MOVE_VERTEX:
            newPt = QgsPoint(self.tmpPoint)
            tmpLinearObjectList = qad_utils.QadLinearObjectList()
            tmpLinearObjectList.set(self.linearObjectList)
            tmpLinearObjectList.movePoint(self.vertexAt, newPt)

        if tmpLinearObjectList is not None:
            pts = tmpLinearObjectList.asPolyline(self.tolerance2ApproxCurve)
            if self.layer.geometryType() == QGis.Polygon:
                geom = QgsGeometry.fromPolygon([pts])
            else:
                geom = QgsGeometry.fromPolyline(pts)

            # trasformo la geometria nel crs del layer
            self.__highlight.addGeometry(
                self.mapToLayerCoordinates(self.layer, geom), self.layer)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode

        # si richiede la selezione di un'entità
        if self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_ENTITY_SEL:
            self.setSelectionMode(
                QadGetPointSelectionModeEnum.ENTITY_SELECTION)

            # solo layer lineari o poligono editabili che non appartengano a quote
            layerList = []
            for layer in qad_utils.getVisibleVectorLayers(
                    self.plugIn.canvas):  # Tutti i layer vettoriali visibili
                if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \
                   layer.isEditable():
                    if len(QadDimStyles.getDimListByLayer(layer)) == 0:
                        layerList.append(layer)

            self.layersToCheck = layerList
            self.setSnapType(QadSnapTypeEnum.DISABLE)
        # non si richiede niente
        elif self.mode == Qad_pedit_maptool_ModeEnum.NONE:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # si richiede il primo punto per calcolo distanza di approssimazione
        # si richiede la posizione più vicina ad un vertice
        elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_FIRST_TOLERANCE_PT:
            self.onlyEditableLayers = False
            self.checkPointLayer = True
            self.checkLineLayer = True
            self.checkPolygonLayer = True
            self.setSnapType()
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # noto il primo punto per calcolo distanza di approssimazione si richiede il secondo punto
        elif self.mode == Qad_pedit_maptool_ModeEnum.FIRST_TOLERANCE_PT_KNOWN_ASK_FOR_SECOND_PT or \
             self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_NEW_VERTEX or \
             self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_MOVE_VERTEX:
            self.onlyEditableLayers = False
            self.checkPointLayer = True
            self.checkLineLayer = True
            self.checkPolygonLayer = True
            self.setSnapType()
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.firstPt)
        # si richiede la posizione più vicina ad un vertice
        elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_VERTEX:
            self.setSnapType(QadSnapTypeEnum.DISABLE)
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # si richede il punto base (grip mode)
        elif self.mode == Qad_pedit_maptool_ModeEnum.ASK_FOR_BASE_PT:
            self.setSnapType()
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
Esempio n. 27
0
class Qad_copy_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.entitySet = QadEntitySet()
      self.seriesLen = 0
      self.adjust = False
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    

   
   #============================================================================
   # move
   #============================================================================
   def move(self, f, offSetX, offSetY, layerEntitySet, entitySet, dimEntity):
      if dimEntity is None:
         # sposto la feature 
         f.setGeometry(qad_utils.moveQgsGeometry(f.geometry(), offSetX, offSetY))
         self.__highlight.addGeometry(f.geometry(), layerEntitySet.layer)
      else:
         # sposto la quota
         dimEntity.move(offSetX, offSetY)
         self.__highlight.addGeometry(dimEntity.textualFeature.geometry(), dimEntity.getTextualLayer())
         self.__highlight.addGeometries(dimEntity.getLinearGeometryCollection(), dimEntity.getLinearLayer())
         self.__highlight.addGeometries(dimEntity.getSymbolGeometryCollection(), dimEntity.getSymbolLayer())
   
   
   def setCopiedGeometries(self, newPt):
      self.__highlight.reset()            
      
      # copio entitySet
      entitySet = QadEntitySet(self.entitySet)
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer

         transformedBasePt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, self.basePt)
         transformedNewPt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, newPt)
         offSetX = transformedNewPt.x() - transformedBasePt.x()
         offSetY = transformedNewPt.y() - transformedBasePt.y()
         entity = QadEntity()

         while len(layerEntitySet.featureIds) > 0:
            featureId = layerEntitySet.featureIds[0]
            f = layerEntitySet.getFeature(featureId)
            if f is None:
               del layerEntitySet.featureIds[0]
               continue

            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, f.id())

            if self.seriesLen > 0: # devo fare una serie              
               if self.adjust == True:
                  offSetX = offSetX / (self.seriesLen - 1)
                  offSetY = offSetY / (self.seriesLen - 1)
   
               deltaX = offSetX
               deltaY = offSetY
                  
               for i in xrange(1, self.seriesLen, 1):
                  self.move(f, deltaX, deltaY, layerEntitySet, entitySet, dimEntity)
                  deltaX = deltaX + offSetX
                  deltaY = deltaY + offSetY     
            else:
               self.move(f, offSetX, offSetY, layerEntitySet, entitySet, dimEntity)
            
            # la rimuovo da entitySet
            if dimEntity is None:
               del layerEntitySet.featureIds[0]
            else:
               dimEntitySet = dimEntity.getEntitySet()
               entitySet.subtract(dimEntitySet)
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      # noto il punto base si richiede il secondo punto
      if self.mode == Qad_copy_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_COPY_PT:
         self.setCopiedGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il punto base
      if self.mode == Qad_copy_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # noto il punto base si richiede il secondo punto per l'angolo di rotazione
      elif self.mode == Qad_copy_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_COPY_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
Esempio n. 28
0
class Qad_gripLineToArcConvert_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.firstPt = None
        self.mode = None

        self.layer = None
        self.linearObjectList = qad_utils.QadLinearObjectList()
        self.linearObject = None
        self.startPt = None
        self.endPt = None
        self.tolerance2ApproxCurve = None
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    def setLinearObjectList(self, linearObjectList, layer, partAt):
        self.linearObjectList.set(linearObjectList)
        self.layer = layer
        self.tolerance2ApproxCurve = QadVariables.get(
            QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
        self.linearObject = self.linearObjectList.getLinearObjectAt(partAt)
        self.firstPt = self.linearObject.getMiddlePt()
        self.startPt = self.linearObject.getStartPt()
        self.endPt = self.linearObject.getEndPt()

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        self.__highlight.reset()
        ok = False

        # noti il punto iniziale e finale dell'arco si richiede il punto intermedio
        if self.mode == Qad_gripLineToArcConvert_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_SECOND_PT:
            if self.linearObject is None:
                return
            arc = QadArc()
            if arc.fromStartSecondEndPts(self.startPt, self.tmpPoint,
                                         self.endPt) == False:
                return
            if qad_utils.ptNear(self.startPt, arc.getStartPt()):
                self.linearObject.setArc(arc, False)  # arco non inverso
            else:
                self.linearObject.setArc(arc, True)  # arco inverso
            ok = True

        if ok:
            pts = self.linearObjectList.asPolyline(self.tolerance2ApproxCurve)
            if self.layer.geometryType() == QGis.Polygon:
                geom = QgsGeometry.fromPolygon([pts])
            else:
                geom = QgsGeometry.fromPolyline(pts)
            # trasformo la geometria nel crs del layer
            self.__highlight.addGeometry(
                self.mapToLayerCoordinates(self.layer, geom), self.layer)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode

        # noti il punto iniziale e finale dell'arco si richiede il punto intermedio
        if self.mode == Qad_gripLineToArcConvert_maptool_ModeEnum.START_END_PT_KNOWN_ASK_FOR_SECOND_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.firstPt)
        # non si richiede niente
        elif self.mode == Qad_pedit_maptool_ModeEnum.NONE:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
Esempio n. 29
0
class Qad_move_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.entitySet = QadEntitySet()
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    

   
   #============================================================================
   # move
   #============================================================================
   def move(self, entity, offSetX, offSetY):
      # verifico se l'entità appartiene ad uno stile di quotatura
      if entity.whatIs() == "ENTITY":
         # sposto l'entità
         movedGeom = qad_utils.moveQgsGeometry(entity.getGeometry(), offSetX, offSetY)
         if movedGeom is not None:
            self.__highlight.addGeometry(movedGeom, entity.layer)
      else:
         # sposto la quota
         entity.move(offSetX, offSetY)
         self.__highlight.addGeometry(entity.textualFeature.geometry(), entity.getTextualLayer())
         self.__highlight.addGeometries(entity.getLinearGeometryCollection(), entity.getLinearLayer())
         self.__highlight.addGeometries(entity.getSymbolGeometryCollection(), entity.getSymbolLayer())

   
   def addMovedGeometries(self, newPt):
      self.__highlight.reset()            

      dimElaboratedList = [] # lista delle quotature già elaborate
      entity = QadEntity()
      
      for layerEntitySet in self.entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         
         transformedBasePt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, self.basePt)
         transformedNewPt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, newPt)
         offSetX = transformedNewPt.x() - transformedBasePt.x()
         offSetY = transformedNewPt.y() - transformedBasePt.y()

         for featureId in layerEntitySet.featureIds:
            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, featureId)  
            if dimEntity is None:
               entity.set(layer, featureId)
               f = layerEntitySet.getFeature(featureId)
               self.move(entity, offSetX, offSetY)
            else:            
               found = False
               for dimElaborated in dimElaboratedList:
                  if dimElaborated == dimEntity:
                     found = True
               if found == False: # quota non ancora elaborata
                  dimElaboratedList.append(dimEntity)
                  self.stretch(dimEntity, offSetX, offSetY)


   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
                     
      # noto il punto base si richiede il secondo punto
      if self.mode == Qad_move_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
         self.addMovedGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il punto base
      if self.mode == Qad_move_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il punto base si richiede il secondo punto
      elif self.mode == Qad_move_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
Esempio n. 30
0
class Qad_mirror_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.firstMirrorPt = None
      self.entitySet = QadEntitySet()
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    
   

   #============================================================================
   # mirror
   #============================================================================
   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)
   
   
   def setMirroredGeometries(self, newPt):
      self.__highlight.reset()

      # copio entitySet
      entitySet = QadEntitySet(self.entitySet)
                
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer

         transformedFirstMirrorPt = self.canvas.mapSettings().mapToLayerCoordinates(layer, self.firstMirrorPt)
         transformedNewPtMirrorPt = self.canvas.mapSettings().mapToLayerCoordinates(layer, newPt)

         while len(layerEntitySet.featureIds) > 0:
            featureId = layerEntitySet.featureIds[0]
            f = layerEntitySet.getFeature(featureId)
            self.mirror(f, transformedFirstMirrorPt, transformedNewPtMirrorPt, layerEntitySet, entitySet)
                     
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
                     
      # noto il primo punto si richiede il secondo punto della linea speculare
      if self.mode == Qad_mirror_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT:
         self.setMirroredGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)  
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il primo punto della linea speculare
      if self.mode == Qad_mirror_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il primo punto si richiede il secondo punto della linea speculare
      elif self.mode == Qad_mirror_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.firstMirrorPt)
Esempio n. 31
0
 def __init__(self, plugIn):
    QadGetPoint.__init__(self, plugIn)
                      
    self.firstMirrorPt = None
    self.entitySet = QadEntitySet()
    self.__highlight = QadHighlight(self.canvas)
Esempio n. 32
0
class Qad_mirror_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.firstMirrorPt = None
      self.entitySet = QadEntitySet()
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    
   

   #============================================================================
   # mirror
   #============================================================================
   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)
   
   
   def setMirroredGeometries(self, newPt):
      self.__highlight.reset()

      # copio entitySet
      entitySet = QadEntitySet(self.entitySet)
                
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer

         transformedFirstMirrorPt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, self.firstMirrorPt)
         transformedNewPtMirrorPt = self.canvas.mapRenderer().mapToLayerCoordinates(layer, newPt)

         while len(layerEntitySet.featureIds) > 0:
            featureId = layerEntitySet.featureIds[0]
            f = layerEntitySet.getFeature(featureId)
            self.mirror(f, transformedFirstMirrorPt, transformedNewPtMirrorPt, layerEntitySet, entitySet)
                     
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
                     
      # noto il primo punto si richiede il secondo punto della linea speculare
      if self.mode == Qad_mirror_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT:
         self.setMirroredGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)  
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il primo punto della linea speculare
      if self.mode == Qad_mirror_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_FIRST_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il primo punto si richiede il secondo punto della linea speculare
      elif self.mode == Qad_mirror_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.firstMirrorPt)
Esempio n. 33
0
class Qad_rotate_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.Pt1ReferenceAng = None
      self.ReferenceAng = 0
      self.Pt1NewAng = None
      self.entitySet = QadEntitySet()
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    
   
   
   #============================================================================
   # rotate
   #============================================================================
   def rotate(self, entity, basePt, angle):
      # verifico se l'entità appartiene ad uno stile di quotatura
      if entity.whatIs() == "ENTITY":
         # ruoto l'entità
         rotatedGeom = qad_utils.rotateQgsGeometry(entity.getGeometry(), basePt, angle)
         if rotatedGeom is not None:
            self.__highlight.addGeometry(rotatedGeom, entity.layer)
      else:
         # ruoto la quota
         entity.rotate(basePt, angle)
         self.__highlight.addGeometry(entity.textualFeature.geometry(), entity.getTextualLayer())
         self.__highlight.addGeometries(entity.getLinearGeometryCollection(), entity.getLinearLayer())
         self.__highlight.addGeometries(entity.getSymbolGeometryCollection(), entity.getSymbolLayer())
   
   
   #============================================================================
   # addRotatedGeometries
   #============================================================================
   def addRotatedGeometries(self, angle):
      self.__highlight.reset()            
      
      dimElaboratedList = [] # lista delle quotature già elaborate
      entity = QadEntity()
      
      for layerEntitySet in self.entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         
         transformedBasePt = self.canvas.mapSettings().mapToLayerCoordinates(layer, self.basePt)

         for featureId in layerEntitySet.featureIds:
            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, featureId)  
            if dimEntity is None:
               entity.set(layer, featureId)
               self.rotate(entity, transformedBasePt, angle)
            else:            
               found = False
               for dimElaborated in dimElaboratedList:
                  if dimElaborated == dimEntity:
                     found = True
               if found == False: # quota non ancora elaborata
                  dimElaboratedList.append(dimEntity)
                  self.rotate(dimEntity, transformedBasePt, angle)


   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)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il punto base
      if self.mode == Qad_rotate_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il punto base si richiede il secondo punto per l'angolo di rotazione
      elif self.mode == Qad_rotate_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_ROTATION_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
      # si richiede il primo punto per l'angolo di riferimento
      elif self.mode == Qad_rotate_maptool_ModeEnum.ASK_FOR_FIRST_PT_REFERENCE_ANG:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()            
      # noto il primo punto si richiede il secondo punto per l'angolo di riferimento
      elif self.mode == Qad_rotate_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_ANG:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.Pt1ReferenceAng)
      # 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:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
      # si richiede il primo punto per il nuovo angolo
      elif self.mode == Qad_rotate_maptool_ModeEnum.ASK_FOR_FIRST_NEW_ROTATION_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # 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:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.Pt1NewAng)
class Qad_move_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.entitySet = QadEntitySet()
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    #============================================================================
    # move
    #============================================================================
    def move(self, entity, offSetX, offSetY):
        # verifico se l'entità appartiene ad uno stile di quotatura
        if entity.whatIs() == "ENTITY":
            # sposto l'entità
            movedGeom = qad_utils.moveQgsGeometry(entity.getGeometry(),
                                                  offSetX, offSetY)
            if movedGeom is not None:
                self.__highlight.addGeometry(movedGeom, entity.layer)
        else:
            newDimEntity = QadDimEntity(entity)  # la copio
            # sposto la quota
            newDimEntity.move(offSetX, offSetY)
            self.__highlight.addGeometry(
                newDimEntity.textualFeature.geometry(),
                newDimEntity.getTextualLayer())
            self.__highlight.addGeometries(
                newDimEntity.getLinearGeometryCollection(),
                newDimEntity.getLinearLayer())
            self.__highlight.addGeometries(
                newDimEntity.getSymbolGeometryCollection(),
                newDimEntity.getSymbolLayer())

    def addMovedGeometries(self, newPt):
        self.__highlight.reset()

        dimElaboratedList = []  # lista delle quotature già elaborate
        entity = QadEntity()

        for layerEntitySet in self.entitySet.layerEntitySetList:
            layer = layerEntitySet.layer

            transformedBasePt = self.canvas.mapSettings(
            ).mapToLayerCoordinates(layer, self.basePt)
            transformedNewPt = self.canvas.mapSettings().mapToLayerCoordinates(
                layer, newPt)
            offSetX = transformedNewPt.x() - transformedBasePt.x()
            offSetY = transformedNewPt.y() - transformedBasePt.y()

            for featureId in layerEntitySet.featureIds:
                # verifico se l'entità appartiene ad uno stile di quotatura
                dimEntity = QadDimStyles.getDimEntity(layer, featureId)
                if dimEntity is None:
                    entity.set(layer, featureId)
                    f = layerEntitySet.getFeature(featureId)
                    self.move(entity, offSetX, offSetY)
                else:
                    found = False
                    for dimElaborated in dimElaboratedList:
                        if dimElaborated == dimEntity:
                            found = True
                    if found == False:  # quota non ancora elaborata
                        dimElaboratedList.append(dimEntity)
                        self.move(dimEntity, offSetX, offSetY)

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        # noto il punto base si richiede il secondo punto
        if self.mode == Qad_move_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
            self.addMovedGeometries(self.tmpPoint)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode
        # noto niente si richiede il punto base
        if self.mode == Qad_move_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
            self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.__highlight.reset()
        # noto il punto base si richiede il secondo punto
        elif self.mode == Qad_move_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.basePt)
Esempio n. 35
0
class Qad_array_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.entitySet = None
      self.basePt = None
      self.arrayType = None
      self.distanceBetweenRows = None
      self.distanceBetweenCols = None
      self.itemsRotation = None

      # serie rettangolare
      self.rectangleAngle = None
      self.rectangleCols = None
      self.rectangleRows = None
      self.firstPt = None

      # serie traiettoria
      self.pathTangentDirection = None
      self.pathRows = None
      self.pathItemsNumber = None
      self.pathLinearObjectList = None

      # serie polare
      self.centerPt = None
      self.polarItemsNumber = None
      self.polarAngleBetween = None
      self.polarRows = None

      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    


   #============================================================================
   # doRectangleArray
   #============================================================================
   def doRectangleArray(self):
      self.__highlight.reset()

      entity = QadEntity()
      # copio entitySet
      entitySet = QadEntitySet(self.entitySet)
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         
         while len(layerEntitySet.featureIds) > 0:
            featureId = layerEntitySet.featureIds[0]
            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, featureId)
            
            f = layerEntitySet.getFeature(featureId)
            if f is None:
               del layerEntitySet.featureIds[0]
               continue

            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, f.id())
            if dimEntity is None:
               entity.set(layer, f.id())
               if qad_array_fun.arrayRectangleEntity(self.plugIn, entity, self.basePt, self.rectangleRows, self.rectangleCols, \
                                                     self.distanceBetweenRows, self.distanceBetweenCols, self.rectangleAngle, self.itemsRotation,
                                                     False, self.__highlight) == False:
                  return
               del layerEntitySet.featureIds[0] # la rimuovo da entitySet
            else:
               if qad_array_fun.arrayRectangleEntity(self.plugIn, dimEntity, self.basePt, self.rectangleRows, self.rectangleCols, \
                                                     self.distanceBetweenRows, self.distanceBetweenCols, self.rectangleAngle, self.itemsRotation,
                                                     False, self.__highlight) == False:
                  return
               dimEntitySet = dimEntity.getEntitySet()
               entitySet.subtract(dimEntitySet) # la rimuovo da entitySet


   #============================================================================
   # doPathArray
   #============================================================================
   def doPathArray(self):
      self.__highlight.reset()

      entity = QadEntity()
      # copio entitySet
      entitySet = QadEntitySet(self.entitySet)
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         
         while len(layerEntitySet.featureIds) > 0:
            featureId = layerEntitySet.featureIds[0]
            
            f = layerEntitySet.getFeature(featureId)
            if f is None:
               del layerEntitySet.featureIds[0]
               continue

            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, f.id())
            if dimEntity is None:
               entity.set(layer, f.id())
               if qad_array_fun.arrayPathEntity(self.plugIn, entity, self.basePt, self.pathRows, self.pathItemsNumber, \
                                                self.distanceBetweenRows, self.distanceBetweenCols, self.pathTangentDirection, self.itemsRotation, \
                                                self.pathLinearObjectList, self.distanceFromStartPt, \
                                                False, self.__highlight) == False:
                  return
               del layerEntitySet.featureIds[0] # la rimuovo da entitySet
            else:
               if qad_array_fun.arrayPathEntity(self.plugIn, dimEntity, self.basePt, self.pathRows, self.pathItemsNumber, \
                                                self.distanceBetweenRows, self.distanceBetweenCols, self.pathTangentDirection, self.itemsRotation, \
                                                self.pathLinearObjectList, self.distanceFromStartPt, \
                                                False, self.__highlight) == False:
                  return
               dimEntitySet = dimEntity.getEntitySet()
               entitySet.subtract(dimEntitySet) # la rimuovo da entitySet


   #============================================================================
   # doPolarArray
   #============================================================================
   def doPolarArray(self):
      self.__highlight.reset()

      entity = QadEntity()
      # copio entitySet
      entitySet = QadEntitySet(self.entitySet)
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         
         while len(layerEntitySet.featureIds) > 0:
            featureId = layerEntitySet.featureIds[0]
            
            f = layerEntitySet.getFeature(featureId)
            if f is None:
               del layerEntitySet.featureIds[0]
               continue

            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, f.id())
            if dimEntity is None:
               entity.set(layer, f.id())
               if qad_array_fun.arrayPolarEntity(self.plugIn, entity, self.basePt, self.centerPt, self.polarItemsNumber, \
                                                 self.polarAngleBetween, self.polarRows, self.distanceBetweenRows, self.itemsRotation, \
                                                 False, self.__highlight) == False:
                  return
               del layerEntitySet.featureIds[0] # la rimuovo da entitySet
            else:
               if qad_array_fun.arrayPolarEntity(self.plugIn, dimEntity, self.basePt, self.centerPt, self.polarItemsNumber, \
                                                 self.polarAngleBetween, self.polarRows, self.distanceBetweenRows, self.itemsRotation, \
                                                 False, self.__highlight) == False:
                  return
               dimEntitySet = dimEntity.getEntitySet()
               entitySet.subtract(dimEntitySet) # la rimuovo da entitySet


   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
#       # noto il punto base si richiede il secondo punto
#       if self.mode == Qad_array_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_COPY_PT:
#          self.setCopiedGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # non si richiede niente
      if self.mode == Qad_array_maptool_ModeEnum.NONE:
         self.setSelectionMode(QadGetPointSelectionModeEnum.NONE)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # si richiede il punto base
      elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_BASE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # si richiede il primo punto per la distanza tra colonne
      elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_COLUMN_SPACE_FIRST_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # si richiede il primo punto per la dimensione della cella
      elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_1PT_CELL:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # si richiede il psecondo punto per la dimensione della cella
      elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_2PT_CELL:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE)
         self.setStartPoint(self.firstPt)
      # si richiede il primo punto per la distanza tra righe
      elif self.mode == Qad_array_maptool_ModeEnum.ASK_FOR_ROW_SPACE_FIRST_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.entitySet = QadEntitySet()
        self.__highlight = QadHighlight(self.canvas)
Esempio n. 37
0
 def __init__(self, plugIn):
    QadGetPoint.__init__(self, plugIn)
                      
    self.basePt = None
    self.SSGeomList = [] # lista di entità da stirare con geom di selezione
    self.__highlight = QadHighlight(self.canvas)
class Qad_gripChangeArcRadius_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.entity = None
        self.arc = None
        self.coordTransform = None
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    def setEntity(self, entity):
        self.entity = QadEntity(entity)
        self.arc = self.entity.getQadGeom()  # arco in map coordinate
        self.basePt = self.arc.center
        self.coordTransform = QgsCoordinateTransform(
            self.canvas.mapSettings().destinationCrs(), entity.layer.crs())

    #============================================================================
    # stretch
    #============================================================================
    def changeRadius(self, radius):
        self.__highlight.reset()
        # radius = nuovo raggio dell'arco
        # tolerance2ApproxCurve = tolleranza per ricreare le curve
        self.arc.radius = radius
        points = self.arc.asPolyline()
        if points is None:
            return False

        g = QgsGeometry.fromPolyline(points)
        # trasformo la geometria nel crs del layer
        g.transform(self.coordTransform)
        self.__highlight.addGeometry(g, self.entity.layer)

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        # noto il punto base si richiede il secondo punto per il raggio
        if self.mode == Qad_gripChangeArcRadius_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_RADIUS_PT:
            radius = qad_utils.getDistance(self.basePt, self.tmpPoint)
            self.changeRadius(radius)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode
        # noto niente si richiede il punto base
        if self.mode == Qad_gripChangeArcRadius_maptool_ModeEnum.ASK_FOR_BASE_PT:
            self.clear()
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
            self.__highlight.reset()
        # noto il punto base si richiede il secondo punto per il raggio
        elif self.mode == Qad_gripChangeArcRadius_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_RADIUS_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.basePt)
Esempio n. 39
0
class Qad_stretch_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.SSGeomList = [] # lista di entità da stirare con geom di selezione
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    
   
   
   #============================================================================
   # stretch
   #============================================================================
   def stretch(self, entity, containerGeom, offSetX, offSetY, tolerance2ApproxCurve):
      # entity = entità da stirare
      # ptList = lista dei punti da stirare
      # offSetX, offSetY = spostamento da fare
      # tolerance2ApproxCurve = tolleranza per ricreare le curve
      # verifico se l'entità appartiene ad uno stile di quotatura
      if entity.whatIs() == "ENTITY":
         stretchedGeom = entity.getGeometry()
         # controllo inserito perchè con le quote, questa viene cancellata e ricreata quindi alcuni oggetti potrebbero non esistere più
         if stretchedGeom is None: # se non c'è lo salto senza errore
            return True
         # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
         coordTransform = QgsCoordinateTransform(entity.layer.crs(), self.canvas.mapSettings().destinationCrs())
         stretchedGeom.transform(coordTransform)           
         # stiro la feature
         stretchedGeom = qad_stretch_fun.stretchQgsGeometry(stretchedGeom, containerGeom, \
                                                            offSetX, offSetY, \
                                                            tolerance2ApproxCurve)
         
         if stretchedGeom is not None:
            # trasformo la geometria nel crs del layer
            coordTransform = QgsCoordinateTransform(self.canvas.mapSettings().destinationCrs(), entity.layer.crs())
            stretchedGeom.transform(coordTransform)
            self.__highlight.addGeometry(stretchedGeom, entity.layer)

      elif entity.whatIs() == "DIMENTITY":
         newDimEntity = QadDimEntity(entity) # la copio
         # stiro la quota
         newDimEntity.stretch(containerGeom, offSetX, offSetY)
         self.__highlight.addGeometry(newDimEntity.textualFeature.geometry(), newDimEntity.getTextualLayer())
         self.__highlight.addGeometries(newDimEntity.getLinearGeometryCollection(), newDimEntity.getLinearLayer())
         self.__highlight.addGeometries(newDimEntity.getSymbolGeometryCollection(), newDimEntity.getSymbolLayer())
            
      return True


   #============================================================================
   # addStretchedGeometries
   #============================================================================
   def addStretchedGeometries(self, newPt):
      self.__highlight.reset()            

      dimElaboratedList = [] # lista delle quotature già elaborate

      tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
      offSetX = newPt.x() - self.basePt.x()
      offSetY = newPt.y() - self.basePt.y()

      entity = QadEntity()
      for SSGeom in self.SSGeomList:
         # copio entitySet
         entitySet = QadEntitySet(SSGeom[0])
         geomSel = SSGeom[1]

         for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer

            for featureId in layerEntitySet.featureIds:
               entity.set(layer, featureId)

               # verifico se l'entità appartiene ad uno stile di quotatura
               dimEntity = QadDimStyles.getDimEntity(entity)
               if dimEntity is None:                        
                  self.stretch(entity, geomSel, offSetX, offSetY, tolerance2ApproxCurve)
               else:
                  found = False
                  for dimElaborated in dimElaboratedList:
                     if dimElaborated == dimEntity:
                        found = True
                  
                  if found == False: # quota non ancora elaborata
                     dimElaboratedList.append(dimEntity)
                     self.stretch(dimEntity, geomSel, offSetX, offSetY, tolerance2ApproxCurve)

      
   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_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
         self.addStretchedGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
   
      # si richiede la selezione del primo punto del rettangolo per selezionare gli oggetti
      if self.mode == Qad_stretch_maptool_ModeEnum.ASK_FOR_FIRST_PT_RECTANGLE:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)         
      # noto niente il primo punto del rettangolo si richiede il secondo punto
      elif self.mode == Qad_stretch_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_RECTANGLE:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_RECTANGLE)                
      # noto niente si richiede il punto base
      elif self.mode == Qad_stretch_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # noto il punto base si richiede il secondo punto
      elif self.mode == Qad_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
Esempio n. 40
0
class Qad_rotate_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.Pt1ReferenceAng = None
      self.ReferenceAng = 0
      self.Pt1NewAng = None
      self.entitySet = QadEntitySet()
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    
   
   
   #============================================================================
   # rotate
   #============================================================================
   def rotate(self, entity, basePt, angle):
      # verifico se l'entità appartiene ad uno stile di quotatura
      if entity.whatIs() == "ENTITY":
         # ruoto l'entità
         rotatedGeom = qad_utils.rotateQgsGeometry(entity.getGeometry(), basePt, angle)
         if rotatedGeom is not None:
            self.__highlight.addGeometry(rotatedGeom, entity.layer)
      else:
         # ruoto la quota
         entity.rotate(basePt, angle)
         self.__highlight.addGeometry(entity.textualFeature.geometry(), entity.getTextualLayer())
         self.__highlight.addGeometries(entity.getLinearGeometryCollection(), entity.getLinearLayer())
         self.__highlight.addGeometries(entity.getSymbolGeometryCollection(), entity.getSymbolLayer())
   
   
   #============================================================================
   # addRotatedGeometries
   #============================================================================
   def addRotatedGeometries(self, angle):
      self.__highlight.reset()            
      
      dimElaboratedList = [] # lista delle quotature già elaborate
      entity = QadEntity()
      
      for layerEntitySet in self.entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         
         transformedBasePt = self.canvas.mapSettings().mapToLayerCoordinates(layer, self.basePt)

         for featureId in layerEntitySet.featureIds:
            # verifico se l'entità appartiene ad uno stile di quotatura
            dimEntity = QadDimStyles.getDimEntity(layer, featureId)  
            if dimEntity is None:
               entity.set(layer, featureId)
               self.rotate(entity, transformedBasePt, angle)
            else:            
               found = False
               for dimElaborated in dimElaboratedList:
                  if dimElaborated == dimEntity:
                     found = True
               if found == False: # quota non ancora elaborata
                  dimElaboratedList.append(dimEntity)
                  self.rotate(dimEntity, transformedBasePt, angle)


   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)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il punto base
      if self.mode == Qad_rotate_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il punto base si richiede il secondo punto per l'angolo di rotazione
      elif self.mode == Qad_rotate_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_ROTATION_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
      # si richiede il primo punto per l'angolo di riferimento
      elif self.mode == Qad_rotate_maptool_ModeEnum.ASK_FOR_FIRST_PT_REFERENCE_ANG:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()            
      # noto il primo punto si richiede il secondo punto per l'angolo di riferimento
      elif self.mode == Qad_rotate_maptool_ModeEnum.FIRST_PT_KNOWN_ASK_FOR_SECOND_PT_REFERENCE_ANG:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.Pt1ReferenceAng)
      # 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:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
      # si richiede il primo punto per il nuovo angolo
      elif self.mode == Qad_rotate_maptool_ModeEnum.ASK_FOR_FIRST_NEW_ROTATION_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
      # 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:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.Pt1NewAng)
Esempio n. 41
0
class Qad_gripChangeArcRadius_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.entity = None
      self.arc = None 
      self.coordTransform = None
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None

   def setEntity(self, entity):
      self.entity = QadEntity(entity)
      self.arc = self.entity.getQadGeom() # arco in map coordinate
      self.basePt = self.arc.center
      self.coordTransform = QgsCoordinateTransform(self.canvas.mapRenderer().destinationCrs(), entity.layer.crs())


   #============================================================================
   # stretch
   #============================================================================
   def changeRadius(self, radius):
      self.__highlight.reset()
      # radius = nuovo raggio dell'arco
      # tolerance2ApproxCurve = tolleranza per ricreare le curve
      self.arc.radius = radius
      points = self.arc.asPolyline()
      if points is None:
         return False
      
      g = QgsGeometry.fromPolyline(points)
      # trasformo la geometria nel crs del layer
      g.transform(self.coordTransform)      
      self.__highlight.addGeometry(g, self.entity.layer)
            
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)

      # noto il punto base si richiede il secondo punto per il raggio
      if self.mode == Qad_gripChangeArcRadius_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_RADIUS_PT:
         radius = qad_utils.getDistance(self.basePt, self.tmpPoint)
         self.changeRadius(radius)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass
      
      
   def setMode(self, mode):
      self.mode = mode
      # noto niente si richiede il punto base
      if self.mode == Qad_gripChangeArcRadius_maptool_ModeEnum.ASK_FOR_BASE_PT:
         self.clear()
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()
      # noto il punto base si richiede il secondo punto per il raggio
      elif self.mode == Qad_gripChangeArcRadius_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_RADIUS_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)
Esempio n. 42
0
class Qad_copy_maptool(QadGetPoint):
    def __init__(self, plugIn):
        QadGetPoint.__init__(self, plugIn)

        self.basePt = None
        self.entitySet = QadEntitySet()
        self.seriesLen = 0
        self.adjust = False
        self.__highlight = QadHighlight(self.canvas)

    def hidePointMapToolMarkers(self):
        QadGetPoint.hidePointMapToolMarkers(self)
        self.__highlight.hide()

    def showPointMapToolMarkers(self):
        QadGetPoint.showPointMapToolMarkers(self)
        self.__highlight.show()

    def clear(self):
        QadGetPoint.clear(self)
        self.__highlight.reset()
        self.mode = None

    #============================================================================
    # move
    #============================================================================
    def move(self, f, offSetX, offSetY, layerEntitySet, entitySet, dimEntity):
        if dimEntity is None:
            # sposto la feature
            f.setGeometry(
                qad_utils.moveQgsGeometry(f.geometry(), offSetX, offSetY))
            self.__highlight.addGeometry(f.geometry(), layerEntitySet.layer)
        else:
            # sposto la quota
            dimEntity.move(offSetX, offSetY)
            self.__highlight.addGeometry(dimEntity.textualFeature.geometry(),
                                         dimEntity.getTextualLayer())
            self.__highlight.addGeometries(
                dimEntity.getLinearGeometryCollection(),
                dimEntity.getLinearLayer())
            self.__highlight.addGeometries(
                dimEntity.getSymbolGeometryCollection(),
                dimEntity.getSymbolLayer())

    def setCopiedGeometries(self, newPt):
        self.__highlight.reset()

        # copio entitySet
        entitySet = QadEntitySet(self.entitySet)

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer

            transformedBasePt = self.canvas.mapRenderer(
            ).mapToLayerCoordinates(layer, self.basePt)
            transformedNewPt = self.canvas.mapRenderer().mapToLayerCoordinates(
                layer, newPt)
            offSetX = transformedNewPt.x() - transformedBasePt.x()
            offSetY = transformedNewPt.y() - transformedBasePt.y()
            entity = QadEntity()

            while len(layerEntitySet.featureIds) > 0:
                featureId = layerEntitySet.featureIds[0]
                f = layerEntitySet.getFeature(featureId)
                if f is None:
                    del layerEntitySet.featureIds[0]
                    continue

                # verifico se l'entità appartiene ad uno stile di quotatura
                dimEntity = QadDimStyles.getDimEntity(layer, f.id())

                if self.seriesLen > 0:  # devo fare una serie
                    if self.adjust == True:
                        offSetX = offSetX / (self.seriesLen - 1)
                        offSetY = offSetY / (self.seriesLen - 1)

                    deltaX = offSetX
                    deltaY = offSetY

                    for i in xrange(1, self.seriesLen, 1):
                        self.move(f, deltaX, deltaY, layerEntitySet, entitySet,
                                  dimEntity)
                        deltaX = deltaX + offSetX
                        deltaY = deltaY + offSetY
                else:
                    self.move(f, offSetX, offSetY, layerEntitySet, entitySet,
                              dimEntity)

                # la rimuovo da entitySet
                if dimEntity is None:
                    del layerEntitySet.featureIds[0]
                else:
                    dimEntitySet = dimEntity.getEntitySet()
                    entitySet.subtract(dimEntitySet)

    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        # noto il punto base si richiede il secondo punto
        if self.mode == Qad_copy_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_COPY_PT:
            self.setCopiedGeometries(self.tmpPoint)

    def activate(self):
        QadGetPoint.activate(self)
        self.__highlight.show()

    def deactivate(self):
        try:  # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
            QadGetPoint.deactivate(self)
            self.__highlight.hide()
        except:
            pass

    def setMode(self, mode):
        self.mode = mode
        # noto niente si richiede il punto base
        if self.mode == Qad_copy_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.NONE)
        # noto il punto base si richiede il secondo punto per l'angolo di rotazione
        elif self.mode == Qad_copy_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_COPY_PT:
            self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
            self.setStartPoint(self.basePt)
Esempio n. 43
0
class Qad_offset_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.firstPt = None
      self.layer = None
      self.subGeom = None
      self.offSet = 0
      self.lastOffSetOnLeftSide = 0
      self.lastOffSetOnRightSide = 0
      self.gapType = 0     
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None    
   
   def addOffSetGeometries(self, newPt):
      self.__highlight.reset()            
      
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(newPt, self.subGeom)
      if self.offSet < 0:
         afterVertex = dummy[2]
         pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \
                                                            self.subGeom.vertexAt(afterVertex), \
                                                            newPt)
         offSetDistance = qad_utils.getDistance(newPt, pt)
      else:           
         offSetDistance = self.offSet

         if dummy[3] < 0: # alla sinistra
            offSetDistance = offSetDistance + self.lastOffSetOnLeftSide
         else: # alla destra
            offSetDistance = offSetDistance + self.lastOffSetOnRightSide         
      
      tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
      # uso il crs del canvas per lavorare con coordinate piane xy
      epsg = self.canvas.mapSettings().destinationCrs().authid()
      lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \
                                       offSetDistance, \
                                       "left" if dummy[3] < 0 else "right", \
                                       self.gapType, \
                                       tolerance2ApproxCurve)

      for line in lines:
         if self.layer.geometryType() == QGis.Polygon:
            if line[0] == line[-1]: # se é una linea chiusa
               offsetGeom = QgsGeometry.fromPolygon([line])
            else:
               offsetGeom = QgsGeometry.fromPolyline(line)
         else:
            offsetGeom = QgsGeometry.fromPolyline(line)

         self.__highlight.addGeometry(self.mapToLayerCoordinates(self.layer, offsetGeom), self.layer)
            
      
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      # nota la distanza di offset si richiede il punto per stabilire da che parte
      if self.mode == Qad_offset_maptool_ModeEnum.OFFSET_KNOWN_ASK_FOR_SIDE_PT:
         self.addOffSetGeometries(self.tmpPoint)                           
      # si richiede il punto di passaggio per stabilire da che parte e a quale offset
      elif self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_PASSAGE_PT:
         self.addOffSetGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()          

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.clear()
      self.mode = mode
      # si richiede il primo punto per calcolo offset
      if self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_FIRST_OFFSET_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.onlyEditableLayers = False
      # noto il primo punto per calcolo offset si richiede il secondo punto
      if self.mode == Qad_offset_maptool_ModeEnum.FIRST_OFFSET_PT_KNOWN_ASK_FOR_SECOND_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.firstPt)
         self.onlyEditableLayers = False
      # nota la distanza di offset si richiede il punto per stabilire da che parte
      elif self.mode == Qad_offset_maptool_ModeEnum.OFFSET_KNOWN_ASK_FOR_SIDE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.onlyEditableLayers = False
      # si richiede il punto di passaggio per stabilire da che parte e a quale offset
      elif self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_PASSAGE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.onlyEditableLayers = False
      # si richiede la selezione di un oggetto
      elif self.mode == Qad_offset_maptool_ModeEnum.ASK_FOR_ENTITY_SELECTION:
         self.setSelectionMode(QadGetPointSelectionModeEnum.ENTITY_SELECTION)
         # solo layer lineari o poligono editabili che non appartengano a quote
         layerList = []
         for layer in qad_utils.getVisibleVectorLayers(self.plugIn.canvas): # Tutti i layer vettoriali visibili
            if (layer.geometryType() == QGis.Line or layer.geometryType() == QGis.Polygon) and \
               layer.isEditable():
               if len(QadDimStyles.getDimListByLayer(layer)) == 0:
                  layerList.append(layer)
         
         self.layersToCheck = layerList
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.onlyEditableLayers = True
Esempio n. 44
0
class Qad_gripStretch_maptool(QadGetPoint):
    
   def __init__(self, plugIn):
      QadGetPoint.__init__(self, plugIn)
                        
      self.basePt = None
      self.selectedEntityGripPoints = [] # lista in cui ogni elemento è una entità + una lista di punti da stirare
      self.__highlight = QadHighlight(self.canvas)

   def hidePointMapToolMarkers(self):
      QadGetPoint.hidePointMapToolMarkers(self)
      self.__highlight.hide()

   def showPointMapToolMarkers(self):
      QadGetPoint.showPointMapToolMarkers(self)
      self.__highlight.show()
                             
   def clear(self):
      QadGetPoint.clear(self)
      self.__highlight.reset()
      self.mode = None


   #============================================================================
   # getSelectedEntityGripPointNdx
   #============================================================================
   def getSelectedEntityGripPointNdx(self, entity):
      # lista delle entityGripPoint con dei grip point selezionati
      # cerca la posizione di un'entità nella lista in cui ogni elemento è una entità + una lista di punti da stirare
      i = 0
      tot = len(self.selectedEntityGripPoints)
      while i < tot:
         selectedEntityGripPoint = self.selectedEntityGripPoints[i]
         if selectedEntityGripPoint[0] == entity:
            return i
         i = i + 1
      return -1
   
   
   #============================================================================
   # stretch
   #============================================================================
   def stretch(self, entity, ptList, offSetX, offSetY, tolerance2ApproxCurve):
      # entity = entità da stirare
      # ptList = lista dei punti da stirare
      # offSetX, offSetY = spostamento da fare
      # tolerance2ApproxCurve = tolleranza per ricreare le curve
      # entitySet = gruppo di selezione delle entità da stirare
      # verifico se l'entità appartiene ad uno stile di quotatura
      if entity.whatIs() == "ENTITY":
         stretchedGeom = entity.gripGeomStretch(self.basePt, ptList, offSetX, offSetY, tolerance2ApproxCurve)

         if stretchedGeom is not None:
            self.__highlight.addGeometry(stretchedGeom, entity.layer)
      elif entity.whatIs() == "DIMENTITY":
         # stiro la quota
         entity.stretch(ptList, offSetX, offSetY)
         self.__highlight.addGeometry(entity.textualFeature.geometry(), entity.getTextualLayer())
         self.__highlight.addGeometries(entity.getLinearGeometryCollection(), entity.getLinearLayer())
         self.__highlight.addGeometries(entity.getSymbolGeometryCollection(), entity.getSymbolLayer())

   
   #============================================================================
   # addStretchedGeometries
   #============================================================================
   def addStretchedGeometries(self, newPt):
      self.__highlight.reset()

      dimElaboratedList = [] # lista delle quotature già elaborate

      for selectedEntity in self.selectedEntityGripPoints:
         entity = selectedEntity[0]
         ptList = selectedEntity[1]
         layer = entity.layer

         tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
         offSetX = newPt.x() - self.basePt.x()
         offSetY = newPt.y() - self.basePt.y()

         # verifico se l'entità appartiene ad uno stile di quotatura
         if entity.isDimensionComponent() == False:
            self.stretch(entity, ptList, offSetX, offSetY, tolerance2ApproxCurve)
         else:
            dimEntity = QadDimEntity()
            if dimEntity.initByDimId(entity.dimStyle, entity.dimId):
               found = False
               for dimElaborated in dimElaboratedList:
                  if dimElaborated == dimEntity:
                     found = True
               if found == False: # quota non ancora elaborata
                  dimEntitySet = dimEntity.getEntitySet()
                  # creo un'unica lista contenente i grip points di tutti i componenti della quota
                  dimPtlist = []
                  for layerEntitySet in dimEntitySet.layerEntitySetList:
                     for featureId in layerEntitySet.featureIds:
                        componentDim = QadEntity()
                        componentDim.set(layerEntitySet.layer, featureId)
                        i = self.getSelectedEntityGripPointNdx(componentDim)
                        if i >= 0:
                           dimPtlist.extend(self.selectedEntityGripPoints[i][1])
   
                  dimElaboratedList.append(dimEntity)
                  self.stretch(dimEntity, dimPtlist, offSetX, offSetY, tolerance2ApproxCurve)
            
      
   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_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
         self.addStretchedGeometries(self.tmpPoint)                           
         
    
   def activate(self):
      QadGetPoint.activate(self)            
      self.__highlight.show()

   def deactivate(self):
      try: # necessario perché se si chiude QGIS parte questo evento nonostante non ci sia più l'oggetto maptool !
         QadGetPoint.deactivate(self)
         self.__highlight.hide()
      except:
         pass

   def setMode(self, mode):
      self.mode = mode
   
      # noto niente si richiede il punto base
      if self.mode == Qad_stretch_maptool_ModeEnum.NONE_KNOWN_ASK_FOR_BASE_PT:
         self.setSelectionMode(QadGetPointSelectionModeEnum.POINT_SELECTION)
         self.setDrawMode(QadGetPointDrawModeEnum.NONE)
         self.__highlight.reset()         
      # noto il punto base si richiede il secondo punto
      elif self.mode == Qad_stretch_maptool_ModeEnum.BASE_PT_KNOWN_ASK_FOR_MOVE_PT:
         self.setDrawMode(QadGetPointDrawModeEnum.ELASTIC_LINE)
         self.setStartPoint(self.basePt)