コード例 #1
0
   def setInfo(self, entity, point):
      # setta: self.layer, self.tmpLinearObjectList e self.move_startPt

      if self.tmpLinearObjectList is not None:
         del self.tmpLinearObjectList
         self.tmpLinearObjectList = None
      
      if entity.isInitialized() == False:
         return False
         
      self.layer = entity.layer
      transformedPt = self.canvas.mapSettings().mapToLayerCoordinates(self.layer, point)
      geom = entity.getGeometry()
                  
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(transformedPt, geom)
      if dummy[2] is None:
         return False
      # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
      subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])               
      self.tmpLinearObjectList = qad_utils.QadLinearObjectList()               
      self.tmpLinearObjectList.fromPolyline(subGeom.asPolyline())
      
      if qad_utils.getDistance(self.tmpLinearObjectList.getStartPt(), transformedPt) <= \
         qad_utils.getDistance(self.tmpLinearObjectList.getEndPt(), transformedPt):
         # si allunga/accorcia dal punto iniziale                 
         self.move_startPt = True
      else:
         # si allunga dal punto finale
         self.move_startPt = False
      return True
コード例 #2
0
ファイル: qad_joindisjoin_cmd.py プロジェクト: geosim/QAD
   def setCurrentSubGeom(self, entSelClass):
      """
      Setta la sottogeometria corrente
      """
      self.currSubGeom = None
      self.currAtSubGeom = None

      # verifico che sia stata selezionata un'entità
      if entSelClass.entity.isInitialized() == False:
         self.showMsg(QadMsg.translate("QAD", "No geometries in this position."))
         return False
      # verifico che sia stata selezionata attraverso un punto
      # (per capire quale sottogeometria è stata selezionata)
      if entSelClass.point is None: return False

      self.entity.set(entSelClass.entity)
      
      geom = self.layerToMapCoordinates(entSelClass.entity.layer, entSelClass.entity.getGeometry())
      
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(entSelClass.point, geom)
      if dummy[2] is None:
         return False
      # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
      self.currSubGeom, self.currAtSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])
      if self.currSubGeom is None or self.currAtSubGeom is None:
         self.currSubGeom = None
         self.currAtSubGeom = None
         return False
      
      return True
コード例 #3
0
ファイル: qad_offset_cmd.py プロジェクト: ermati/QAD
   def addFeatureCache(self, newPt):
      featureCacheLen = len(self.featureCache)
      layer = self.entity.layer
      f = self.entity.getFeature()
      transformedPt = self.mapToLayerCoordinates(layer, newPt)

      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom)
      if self.offSet < 0:
         afterVertex = dummy[2]
         pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \
                                                            self.subGeom.vertexAt(afterVertex), \
                                                            transformedPt)
         offSetDistance = qad_utils.getDistance(transformedPt, pt)
      else:        
         offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \
                                                              self.plugIn.canvas,\
                                                              layer)                     
         if self.multi == True:
            if dummy[3] < 0: # alla sinistra
               offSetDistance = offSetDistance + self.lastOffSetOnLeftSide
               self.lastOffSetOnLeftSide = offSetDistance
               self.getPointMapTool().lastOffSetOnLeftSide = self.lastOffSetOnLeftSide                     
            else: # alla destra
               offSetDistance = offSetDistance + self.lastOffSetOnRightSide
               self.lastOffSetOnRightSide = offSetDistance            
               self.getPointMapTool().lastOffSetOnRightSide = self.lastOffSetOnRightSide

      tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \
                                                                  self.plugIn.canvas,\
                                                                  layer)
      epsg = layer.crs().authid()      
      lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \
                                       offSetDistance, \
                                       "left" if dummy[3] < 0 else "right", \
                                       self.gapType, \
                                       tolerance2ApproxCurve)
      added = False
      for line in lines:        
         if layer.geometryType() == QGis.Polygon:
            if line[0] == line[-1]: # se é una linea chiusa
               offsetGeom = QgsGeometry.fromPolygon([line])
            else:
               offsetGeom = QgsGeometry.fromPolyline(line)
         else:
            offsetGeom = QgsGeometry.fromPolyline(line)

         if offsetGeom.type() == QGis.Line or offsetGeom.type() == QGis.Polygon:           
            offsetFeature = QgsFeature(f)                              
            offsetFeature.setGeometry(offsetGeom)
            self.featureCache.append([layer, offsetFeature])
            self.addFeatureToRubberBand(layer, offsetFeature)            
            added = True           

      if added:      
         self.undoFeatureCacheIndexes.append(featureCacheLen)
コード例 #4
0
   def addFeatureCache(self, newPt):
      featureCacheLen = len(self.featureCache)
      layer = self.entity.layer
      f = self.entity.getFeature()

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

      tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
      # uso il crs del canvas per lavorare con coordinate piane xy
      epsg = self.plugIn.canvas.mapSettings().destinationCrs().authid()
      lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \
                                       offSetDistance, \
                                       "left" if dummy[3] < 0 else "right", \
                                       self.gapType, \
                                       tolerance2ApproxCurve)
      added = False
      for line in lines:        
         if layer.geometryType() == QGis.Polygon:
            if line[0] == line[-1]: # se é una linea chiusa
               offsetGeom = QgsGeometry.fromPolygon([line])
            else:
               offsetGeom = QgsGeometry.fromPolyline(line)
         else:
            offsetGeom = QgsGeometry.fromPolyline(line)

         if offsetGeom.type() == QGis.Line or offsetGeom.type() == QGis.Polygon:           
            offsetFeature = QgsFeature(f)
            # trasformo la geometria nel crs del layer
            offsetFeature.setGeometry(self.mapToLayerCoordinates(layer, offsetGeom))
            self.featureCache.append([layer, offsetFeature])
            self.addFeatureToRubberBand(layer, offsetFeature)            
            added = True           

      if added:      
         self.undoFeatureCacheIndexes.append(featureCacheLen)
コード例 #5
0
   def setSelectedEntityGripPoints(self, entitySetGripPoints):
      # lista delle entityGripPoint con dei grip point selezionati
      # setta la prima entità con un grip selezionato
      self.entity = None
      for entityGripPoints in entitySetGripPoints.entityGripPoints:
         for gripPoint in entityGripPoints.gripPoints:
            # grip point selezionato
            if gripPoint.getStatus() == qad_grip.QadGripStatusEnum.SELECTED:
               # verifico se l'entità appartiene ad uno stile di quotatura
               if entityGripPoints.entity.isDimensionComponent():
                  return False
               if entityGripPoints.entity.getEntityType() != QadEntityGeomTypeEnum.ARC and \
                  entityGripPoints.entity.getEntityType() != QadEntityGeomTypeEnum.LINESTRING:
                  return False
               
               # setta: self.entity, self.linearObjectList, self.atSubGeom e self.move_startPt
               self.entity = entityGripPoints.entity
               
               if self.linearObjectList is not None:
                  del self.linearObjectList
                  self.linearObjectList = None

               # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
               geom = self.layerToMapCoordinates(self.entity.layer, self.entity.getGeometry())
               
               # ritorna una tupla (<The squared cartesian distance>,
               #                    <minDistPoint>
               #                    <afterVertex>
               #                    <leftOf>)
               res = False
               dummy = qad_utils.closestSegmentWithContext(gripPoint.getPoint(), geom)
               if dummy[2] is None:
                  return False
               # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
               subGeom, self.atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])               
               self.linearObjectList = qad_utils.QadLinearObjectList()

               self.linearObjectList.fromPolyline(subGeom.asPolyline())
               
               if qad_utils.getDistance(self.linearObjectList.getStartPt(), gripPoint.getPoint()) <= \
                  qad_utils.getDistance(self.linearObjectList.getEndPt(), gripPoint.getPoint()):
                  # si allunga dal punto iniziale
                  self.move_startPt = True
               else:
                  # si allunga dal punto finale
                  self.move_startPt = False

               # imposto il map tool
               if self.getPointMapTool().setInfo(self.entity, gripPoint.getPoint()) == False:
                  return False
               
               return True
      return False
コード例 #6
0
ファイル: qad_lengthen_cmd.py プロジェクト: resistor4u/QAD
   def setSelectedEntityGripPoints(self, entitySetGripPoints):
      # lista delle entityGripPoint con dei grip point selezionati
      # setta la prima entità con un grip selezionato
      self.entity = None
      for entityGripPoints in entitySetGripPoints.entityGripPoints:
         for gripPoint in entityGripPoints.gripPoints:
            # grip point selezionato
            if gripPoint.getStatus() == qad_grip.QadGripStatusEnum.SELECTED:
               # verifico se l'entità appartiene ad uno stile di quotatura
               if entityGripPoints.entity.isDimensionComponent():
                  return False
               if entityGripPoints.entity.getEntityType() != QadEntityGeomTypeEnum.ARC and \
                  entityGripPoints.entity.getEntityType() != QadEntityGeomTypeEnum.LINESTRING:
                  return False
               
               # setta: self.entity, self.linearObjectList, self.atSubGeom e self.move_startPt
               self.entity = entityGripPoints.entity
               
               if self.linearObjectList is not None:
                  del self.linearObjectList
                  self.linearObjectList = None

               # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
               geom = self.layerToMapCoordinates(self.entity.layer, self.entity.getGeometry())
               
               # ritorna una tupla (<The squared cartesian distance>,
               #                    <minDistPoint>
               #                    <afterVertex>
               #                    <leftOf>)
               res = False
               dummy = qad_utils.closestSegmentWithContext(gripPoint.getPoint(), geom)
               if dummy[2] is None:
                  return False
               # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
               subGeom, self.atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])               
               self.linearObjectList = qad_utils.QadLinearObjectList()

               self.linearObjectList.fromPolyline(subGeom.asPolyline())
               
               if qad_utils.getDistance(self.linearObjectList.getStartPt(), gripPoint.getPoint()) <= \
                  qad_utils.getDistance(self.linearObjectList.getEndPt(), gripPoint.getPoint()):
                  # si allunga dal punto iniziale
                  self.move_startPt = True
               else:
                  # si allunga dal punto finale
                  self.move_startPt = False

               # imposto il map tool
               if self.getPointMapTool().setInfo(self.entity, gripPoint.getPoint()) == False:
                  return False
               
               return True
      return False
コード例 #7
0
    def setEntityInfo(self, firstObj, layer, featureId, point):
        """
      Setta self.entity, self.atSubGeom, self.linearObjectList, self.partAt, self.pointAt
      di primo o del secondo oggetto da raccordare (vedi <firstObj>)
      """
        if firstObj:
            e = self.entity1
            l = self.linearObjectList1
        else:
            e = self.entity2
            l = self.linearObjectList2

        e.set(layer, featureId)
        # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
        geom = self.layerToMapCoordinates(layer, e.getGeometry())
        # ritorna una tupla (<The squared cartesian distance>,
        #                    <minDistPoint>
        #                    <afterVertex>
        #                    <leftOf>)
        dummy = qad_utils.closestSegmentWithContext(point, geom)
        if dummy[2] is not None:
            # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
            if firstObj:
                subGeom, self.atSubGeom1 = qad_utils.getSubGeomAtVertex(
                    geom, dummy[2])
            else:
                subGeom, self.atSubGeom2 = qad_utils.getSubGeomAtVertex(
                    geom, dummy[2])

            l.fromPolyline(subGeom.asPolyline())
            e.selectOnLayer(False)  # non incrementale

            # la funzione ritorna una lista con (<minima distanza al quadrato>,
            #                                    <punto più vicino>
            #                                    <indice della parte più vicina>
            #                                    <"a sinistra di">)
            dummy = l.closestPartWithContext(point)

            if firstObj:
                self.partAt1 = dummy[2]
                self.pointAt1 = dummy[1]
            else:
                self.partAt2 = dummy[2]
                self.pointAt2 = dummy[1]

            return True
        else:
            e.deselectOnLayer()
            return False
コード例 #8
0
ファイル: qad_fillet_cmd.py プロジェクト: tudorbarascu/QAD
   def setEntityInfo(self, firstObj, layer, featureId, point):
      """
      Setta self.entity, self.atSubGeom, self.linearObjectList, self.partAt, self.pointAt
      di primo o del secondo oggetto da raccordare (vedi <firstObj>)
      """
      transformedPt = self.mapToLayerCoordinates(layer, point)
      
      if firstObj:
         e = self.entity1
         l = self.linearObjectList1
      else:
         e = self.entity2
         l = self.linearObjectList2
         
      e.set(layer, featureId)
      geom = e.getGeometry()
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(transformedPt, geom)
      if dummy[2] is not None:
         # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
         if firstObj:
            subGeom, self.atSubGeom1 = qad_utils.getSubGeomAtVertex(geom, dummy[2])
         else:
            subGeom, self.atSubGeom2 = qad_utils.getSubGeomAtVertex(geom, dummy[2])
             
         l.fromPolyline(subGeom.asPolyline())
         e.selectOnLayer(False) # non incrementale        
         
         # la funzione ritorna una lista con (<minima distanza al quadrato>,
         #                                    <punto più vicino>
         #                                    <indice della parte più vicina>       
         #                                    <"a sinistra di">)
         dummy = l.closestPartWithContext(transformedPt)
         
         if firstObj:           
            self.partAt1 = dummy[2]
            self.pointAt1 = dummy[1]
         else:
            self.partAt2 = dummy[2]
            self.pointAt2 = dummy[1]

         return True
      else:
         e.deselectOnLayer()
         return False
コード例 #9
0
ファイル: qad_offset_maptool.py プロジェクト: ermati/QAD
   def addOffSetGeometries(self, newPt):
      self.__rubberBand.reset()            
            
      transformedPt = self.plugIn.canvas.mapRenderer().mapToLayerCoordinates(self.layer, newPt)
      
      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(transformedPt, self.subGeom)
      if self.offSet < 0:
         afterVertex = dummy[2]
         pt = qad_utils.getPerpendicularPointOnInfinityLine(self.subGeom.vertexAt(afterVertex - 1), \
                                                            self.subGeom.vertexAt(afterVertex), \
                                                            transformedPt)
         offSetDistance = qad_utils.getDistance(transformedPt, pt)
      else:           
         offSetDistance = qad_utils.distMapToLayerCoordinates(self.offSet, \
                                                              self.plugIn.canvas,\
                                                              self.layer)
         if dummy[3] < 0: # alla sinistra
            offSetDistance = offSetDistance + self.lastOffSetOnLeftSide
         else: # alla destra
            offSetDistance = offSetDistance + self.lastOffSetOnRightSide         
      
      tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \
                                                                  self.plugIn.canvas,\
                                                                  self.layer)
      epsg = self.layer.crs().authid()      
      lines = qad_utils.offSetPolyline(self.subGeom.asPolyline(), epsg, \
                                       offSetDistance, \
                                       "left" if dummy[3] < 0 else "right", \
                                       self.gapType, \
                                       tolerance2ApproxCurve)

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

         self.__rubberBand.addGeometry(offsetGeom, self.layer)
コード例 #10
0
    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)
コード例 #11
0
    def setCurrentSubGeom(self, entSelClass):
        """
      Setta la sottogeometria corrente
      """
        self.currSubGeom = None
        self.currAtSubGeom = None

        # verifico che sia stata selezionata un'entità
        if entSelClass.entity.isInitialized() == False:
            self.showMsg(
                QadMsg.translate("QAD", "No geometries in this position."))
            return False
        # verifico che sia stata selezionata attraverso un punto
        # (per capire quale sottogeometria è stata selezionata)
        if entSelClass.point is None: return False
        # verifico che sia stato selezionato lo stesso polygono che è da modificare
        if self.poligonEntity != entSelClass.entity:
            self.showMsg(
                QadMsg.translate(
                    "Command_MAPMPEDIT",
                    "The boundary doesn't belong to the selected polygon."))
            return False

        # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
        geom = self.layerToMapCoordinates(entSelClass.entity.layer,
                                          entSelClass.entity.getGeometry())

        # ritorna una tupla (<The squared cartesian distance>,
        #                    <minDistPoint>
        #                    <afterVertex>
        #                    <leftOf>)
        dummy = qad_utils.closestSegmentWithContext(entSelClass.point, geom)
        if dummy[2] is None:
            return False
        # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
        self.currSubGeom, self.currAtSubGeom = qad_utils.getSubGeomAtVertex(
            geom, dummy[2])
        if self.currSubGeom is None or self.currAtSubGeom is None:
            self.currSubGeom = None
            self.currAtSubGeom = None
            return False

        return True
コード例 #12
0
    def doDivide(self, dstLayer):
        f = self.entSelClass.entity.getFeature()
        if f is None:
            return

        layer = self.entSelClass.entity.layer

        # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
        geom = self.layerToMapCoordinates(layer, f.geometry())

        # ritorna una tupla (<The squared cartesian distance>,
        #                    <minDistPoint>
        #                    <afterVertex>
        #                    <leftOf>)
        dummy = qad_utils.closestSegmentWithContext(self.entSelClass.point,
                                                    geom)
        if dummy[2] is None:
            return False

        # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
        subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])
        pathLinearObjectList = qad_utils.QadLinearObjectList()
        geomType = subGeom.type()
        pathLinearObjectList.fromPolyline(subGeom.asPolyline())
        distance = pathLinearObjectList.length() / self.nSegments

        self.plugIn.beginEditCommand("Feature divided", dstLayer)

        i = 1
        distanceFromStart = distance
        while i < self.nSegments:
            pt, rot = pathLinearObjectList.getPointFromStart(distanceFromStart)
            if self.addFeature(dstLayer, pt,
                               rot if self.objectAlignment else 0) == False:
                self.plugIn.destroyEditCommand()
                return False
            i = i + 1
            distanceFromStart = distanceFromStart + distance

        self.plugIn.endEditCommand()
        return True
コード例 #13
0
ファイル: qad_offset_maptool.py プロジェクト: gam17/QAD
   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)
コード例 #14
0
ファイル: qad_lengthen_cmd.py プロジェクト: gam17/QAD
   def showLength(self, entity, pt):
      # visualizza la lunghezza dell'entità in unità di mappa
      geom = entity.getGeometry()
      if geom is None:         
         errMsg = QadMsg.translate("QAD", "Invalid object.")
         self.showErr("\n" + errMsg)
         return None
   
      # Trasformo il punto nel sistema di coordinate del layer
      convPt = self.mapToLayerCoordinates(entity.layer, pt)

      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(pt, geom)
      if dummy[2] is None:
         errMsg = QadMsg.translate("QAD", "Invalid object.")
         self.showErr("\n" + errMsg)
         return None
      # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
      subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])
      
      LinearObjectListToMisure = qad_utils.QadLinearObjectList()
      pointList = subGeom.asPolyline()
      LinearObjectListToMisure.fromPolyline(pointList)
      # la trasformo in unità di mappa
      LinearObjectListToMisure.transformFromCRSToCRS(entity.layer.crs(), self.plugIn.canvas.mapSettings().destinationCrs())      
      
      msg = QadMsg.translate("Command_LENGTHEN", "\nCurrent length: {0}")
      msg = msg.format(str(LinearObjectListToMisure.length()))

      arc = QadArc()
      startEndVertices = arc.fromPolyline(pointList, 0)
      # se la polilinea è composta solo da un arco
      if startEndVertices and startEndVertices[0] == 0 and startEndVertices[1] == len(pointList)-1:
         msg = msg + QadMsg.translate("Command_LENGTHEN", ", included angle: {0}")
         msg = msg.format(str(qad_utils.toDegrees(arc.totalAngle())))
         
      self.showMsg(msg)
コード例 #15
0
   def showLength(self, entity, pt):
      # visualizza la lunghezza dell'entità in unità di mappa
      geom = entity.getGeometry()
      if geom is None:         
         errMsg = QadMsg.translate("QAD", "Invalid object.")
         self.showErr("\n" + errMsg)
         return None
   
      # Trasformo il punto nel sistema di coordinate del layer
      convPt = self.mapToLayerCoordinates(entity.layer, pt)

      # ritorna una tupla (<The squared cartesian distance>,
      #                    <minDistPoint>
      #                    <afterVertex>
      #                    <leftOf>)
      dummy = qad_utils.closestSegmentWithContext(pt, geom)
      if dummy[2] is None:
         errMsg = QadMsg.translate("QAD", "Invalid object.")
         self.showErr("\n" + errMsg)
         return None
      # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
      subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])
      
      LinearObjectListToMisure = qad_utils.QadLinearObjectList()
      pointList = subGeom.asPolyline()
      LinearObjectListToMisure.fromPolyline(pointList)
      # la trasformo in unità di mappa
      LinearObjectListToMisure.transformFromCRSToCRS(entity.layer.crs(), self.plugIn.canvas.mapRenderer().destinationCrs())      
      
      msg = QadMsg.translate("Command_LENGTHEN", "\nCurrent length: {0}")
      msg = msg.format(str(LinearObjectListToMisure.length()))

      arc = QadArc()
      startEndVertices = arc.fromPolyline(pointList, 0)
      # se la polilinea è composta solo da un arco
      if startEndVertices and startEndVertices[0] == 0 and startEndVertices[1] == len(pointList)-1:
         msg = msg + QadMsg.translate("Command_LENGTHEN", ", included angle: {0}")
         msg = msg.format(str(qad_utils.toDegrees(arc.totalAngle())))
         
      self.showMsg(msg)
コード例 #16
0
ファイル: qad_divide_cmd.py プロジェクト: gam17/QAD
    def doDivide(self, dstLayer):
        f = self.entSelClass.entity.getFeature()
        if f is None:
            return

        layer = self.entSelClass.entity.layer

        # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
        geom = self.layerToMapCoordinates(layer, f.geometry())

        # ritorna una tupla (<The squared cartesian distance>,
        #                    <minDistPoint>
        #                    <afterVertex>
        #                    <leftOf>)
        dummy = qad_utils.closestSegmentWithContext(self.entSelClass.point, geom)
        if dummy[2] is None:
            return False

        # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
        subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])
        pathLinearObjectList = qad_utils.QadLinearObjectList()
        geomType = subGeom.type()
        pathLinearObjectList.fromPolyline(subGeom.asPolyline())
        distance = pathLinearObjectList.length() / self.nSegments

        self.plugIn.beginEditCommand("Feature divided", dstLayer)

        i = 1
        distanceFromStart = distance
        while i < self.nSegments:
            pt, rot = pathLinearObjectList.getPointFromStart(distanceFromStart)
            if self.addFeature(dstLayer, pt, rot if self.objectAlignment else 0) == False:
                self.plugIn.destroyEditCommand()
                return False
            i = i + 1
            distanceFromStart = distanceFromStart + distance

        self.plugIn.endEditCommand()
        return True
コード例 #17
0
ファイル: qad_mapmpedit_cmd.py プロジェクト: gam17/QAD
    def setCurrentSubGeom(self, entSelClass):
        """
      Setta la sottogeometria corrente
      """
        self.currSubGeom = None
        self.currAtSubGeom = None

        # verifico che sia stata selezionata un'entità
        if entSelClass.entity.isInitialized() == False:
            self.showMsg(QadMsg.translate("QAD", "No geometries in this position."))
            return False
        # verifico che sia stata selezionata attraverso un punto
        # (per capire quale sottogeometria è stata selezionata)
        if entSelClass.point is None:
            return False
        # verifico che sia stato selezionato lo stesso polygono che è da modificare
        if self.poligonEntity != entSelClass.entity:
            self.showMsg(QadMsg.translate("Command_MAPMPEDIT", "The boundary doesn't belong to the selected polygon."))
            return False

        # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
        geom = self.layerToMapCoordinates(entSelClass.entity.layer, entSelClass.entity.getGeometry())

        # ritorna una tupla (<The squared cartesian distance>,
        #                    <minDistPoint>
        #                    <afterVertex>
        #                    <leftOf>)
        dummy = qad_utils.closestSegmentWithContext(entSelClass.point, geom)
        if dummy[2] is None:
            return False
        # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
        self.currSubGeom, self.currAtSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])
        if self.currSubGeom is None or self.currAtSubGeom is None:
            self.currSubGeom = None
            self.currAtSubGeom = None
            return False

        return True
コード例 #18
0
ファイル: qad_joindisjoin_cmd.py プロジェクト: omnilink/QAD
    def setCurrentSubGeom(self, entSelClass):
        """
      Setta la sottogeometria corrente
      """
        self.currSubGeom = None
        self.currAtSubGeom = None

        # verifico che sia stata selezionata un'entità
        if entSelClass.entity.isInitialized() == False:
            self.showMsg(
                QadMsg.translate("QAD", "No geometries in this position."))
            return False
        # verifico che sia stata selezionata attraverso un punto
        # (per capire quale sottogeometria è stata selezionata)
        if entSelClass.point is None: return False

        self.entity.set(entSelClass.entity)

        geom = self.layerToMapCoordinates(entSelClass.entity.layer,
                                          entSelClass.entity.getGeometry())

        # ritorna una tupla (<The squared cartesian distance>,
        #                    <minDistPoint>
        #                    <afterVertex>
        #                    <leftOf>)
        dummy = qad_utils.closestSegmentWithContext(entSelClass.point, geom)
        if dummy[2] is None:
            return False
        # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
        self.currSubGeom, self.currAtSubGeom = qad_utils.getSubGeomAtVertex(
            geom, dummy[2])
        if self.currSubGeom is None or self.currAtSubGeom is None:
            self.currSubGeom = None
            self.currAtSubGeom = None
            return False

        return True
コード例 #19
0
   def trimFeatures(self, geom, toExtend):
      # geom è in map coordinates
      tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
      LineTempLayer = None
      self.plugIn.beginEditCommand("Feature extended" if toExtend else "Feature trimmed", \
                                   self.entitySet.getLayerList())
      
      for layerEntitySet in self.entitySet.layerEntitySetList:
         layer = layerEntitySet.layer

         for featureId in layerEntitySet.featureIds:
            f = qad_utils.getFeatureById(layer, featureId)
            if f is None:
               continue
            # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
            f_geom = self.layerToMapCoordinates(layer, f.geometry())
            
            if geom.type() == QGis.Point:
               # ritorna una tupla (<The squared cartesian distance>,
               #                    <minDistPoint>
               #                    <afterVertex>
               #                    <leftOf>)
               dummy = qad_utils.closestSegmentWithContext(geom.asPoint(), f_geom)
               if dummy[1] is not None:
                  intPts = [dummy[1]]
            else:
               intPts = qad_utils.getIntersectionPoints(geom, f_geom)
               
            for intPt in intPts:               
               if toExtend:
                  newGeom = qad_utils.extendQgsGeometry(self.plugIn.canvas.mapRenderer().destinationCrs(), f_geom, intPt, \
                                                        self.limitEntitySet, self.edgeMode, \
                                                        tolerance2ApproxCurve)
                  if newGeom is not None:
                     # aggiorno la feature con la geometria estesa
                     extendedFeature = QgsFeature(f)
                     # trasformo la geometria nel crs del layer
                     extendedFeature.setGeometry(self.mapToLayerCoordinates(layer, newGeom))
                     # plugIn, layer, feature, refresh, check_validity
                     if qad_layer.updateFeatureToLayer(self.plugIn, layer, extendedFeature, False, False) == False:
                        self.plugIn.destroyEditCommand()
                        return
               else: # trim
                  result = qad_utils.trimQgsGeometry(self.plugIn.canvas.mapRenderer().destinationCrs(), f_geom, intPt, \
                                                     self.limitEntitySet, self.edgeMode, \
                                                     tolerance2ApproxCurve)                  
                  if result is not None:
                     line1 = result[0]
                     line2 = result[1]
                     atSubGeom = result[2]
                     if layer.geometryType() == QGis.Line:
                        updGeom = qad_utils.setSubGeom(f_geom, line1, atSubGeom)
                        if updGeom is None:
                           self.plugIn.destroyEditCommand()
                           return
                        trimmedFeature1 = QgsFeature(f)
                        # trasformo la geometria nel crs del layer
                        trimmedFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
                        # plugIn, layer, feature, refresh, check_validity
                        if qad_layer.updateFeatureToLayer(self.plugIn, layer, trimmedFeature1, False, False) == False:
                           self.plugIn.destroyEditCommand()
                           return
                        if line2 is not None:
                           trimmedFeature2 = QgsFeature(f)      
                           # trasformo la geometria nel crs del layer
                           trimmedFeature2.setGeometry(self.mapToLayerCoordinates(layer, line2))
                           # plugIn, layer, feature, coordTransform, refresh, check_validity
                           if qad_layer.addFeatureToLayer(self.plugIn, layer, trimmedFeature2, None, False, False) == False:
                              self.plugIn.destroyEditCommand()
                              return                        
                     else:
                        # aggiungo le linee nei layer temporanei di QAD
                        if LineTempLayer is None:
                           LineTempLayer = qad_layer.createQADTempLayer(self.plugIn, QGis.Line)
                           self.plugIn.addLayerToLastEditCommand("Feature trimmed", LineTempLayer)
                        
                        lineGeoms = [line1]
                        if line2 is not None:
                           lineGeoms.append(line2)

                        # trasformo la geometria in quella dei layer temporanei
                        # plugIn, pointGeoms, lineGeoms, polygonGeoms, coord, refresh
                        if qad_layer.addGeometriesToQADTempLayers(self.plugIn, None, lineGeoms, None, None, False) == False:
                           self.plugIn.destroyEditCommand()
                           return
                                                      
                        updGeom = qad_utils.delSubGeom(f_geom, atSubGeom)
                        
                        if updGeom is None or updGeom.isGeosEmpty(): # da cancellare
                           # plugIn, layer, feature id, refresh
                           if qad_layer.deleteFeatureToLayer(self.plugIn, layer, f.id(), False) == False:
                              self.plugIn.destroyEditCommand()
                              return
                        else:
                           trimmedFeature1 = QgsFeature(f)
                           # trasformo la geometria nel crs del layer
                           trimmedFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
                           # plugIn, layer, feature, refresh, check_validity
                           if qad_layer.updateFeatureToLayer(self.plugIn, layer, trimmedFeature1, False, False) == False:
                              self.plugIn.destroyEditCommand()
                              return

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
コード例 #20
0
   def run(self, msgMapTool = False, msg = None):
      if self.plugIn.canvas.mapSettings().destinationCrs().geographicFlag():
         self.showMsg(QadMsg.translate("QAD", "\nThe coordinate reference system of the project must be a projected coordinate system.\n"))
         return True # fine comando

      # il layer corrente deve essere editabile e di tipo linea o poligono
      currLayer, errMsg = qad_layer.getCurrLayerEditable(self.plugIn.canvas, [QGis.Line, QGis.Polygon])
      if currLayer is None:
         self.showErr(errMsg)
         return True # fine comando

      #=========================================================================
      # RICHIESTA DISTANZA DI OFFSET
      if self.step == 0: # inizio del comando
         CurrSettingsMsg = QadMsg.translate("QAD", "\nCurrent settings: ")
         CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", "OFFSETGAPTYPE = ") + str(self.gapType)                        
         if self.gapType == 0:
            CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", " (extends the segments)")
         elif self.gapType == 1:
            CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", " (fillets the segments)")
         elif self.gapType == 2:
            CurrSettingsMsg = CurrSettingsMsg + QadMsg.translate("Command_OFFSET", " (chamfers the segments)")
         
         self.showMsg(CurrSettingsMsg)         

         self.waitForDistance()
            
      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DELLA DISTANZA DI OFFSET (da step = 0)
      elif self.step == 1: # dopo aver atteso un punto o un numero reale si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  if self.offSet < 0:
                     value = QadMsg.translate("Command_OFFSET", "Through")
                  else:
                     value = self.offSet
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False
            else:
               value = self.getPointMapTool().point
         else: # il punto arriva come parametro della funzione
            value = msg
         
         if type(value) == unicode:
            if value == QadMsg.translate("Command_OFFSET", "Through") or value == "Through":
               self.offSet = -1
               self.getPointMapTool().offSet = self.offSet
               QadVariables.set(QadMsg.translate("Environment variables", "OFFSETDIST"), self.offSet)
               QadVariables.save()               
               # si appresta ad attendere la selezione di un oggetto
               self.waitForObjectSel()
            elif value == QadMsg.translate("Command_OFFSET", "Erase") or value == "Erase":
               keyWords = QadMsg.translate("QAD", "Yes") + "/" + \
                          QadMsg.translate("QAD", "No")
              
               if self.eraseEntity == True:
                  default = QadMsg.translate("QAD", "Yes")
               else: 
                  default = QadMsg.translate("QAD", "No")
               prompt = QadMsg.translate("Command_OFFSET", "Erase source object after offsetting ? [{0}] <{1}>: ").format(keyWords, default)
                   
               englishKeyWords = "Yes" + "/" + "No"
               keyWords += "_" + englishKeyWords
               # si appresta ad attendere enter o una parola chiave
               # msg, inputType, default, keyWords, nessun controllo
               self.waitFor(prompt, \
                            QadInputTypeEnum.KEYWORDS, \
                            default, \
                            keyWords, QadInputModeEnum.NONE)
               self.step = 5
            elif value == QadMsg.translate("Command_OFFSET", "Multiple") or value == "Multiple":
               self.multi = True
               self.waitForBasePt()                         
         elif type(value) == QgsPoint: # se é stato inserito il primo punto per il calcolo della distanza
            self.firstPt.set(value.x(), value.y())
            # imposto il map tool
            self.getPointMapTool().firstPt = self.firstPt           
            self.getPointMapTool().setMode(Qad_offset_maptool_ModeEnum.FIRST_OFFSET_PT_KNOWN_ASK_FOR_SECOND_PT)
            # si appresta ad attendere un punto
            self.waitForPoint(QadMsg.translate("Command_OFFSET", "Specify second point: "))
            self.step = 6
         elif type(value) == float:
            self.offSet = value
            self.getPointMapTool().offSet = self.offSet
            QadVariables.set(QadMsg.translate("Environment variables", "OFFSETDIST"), self.offSet)
            QadVariables.save()
            # si appresta ad attendere la selezione di un oggetto
            self.waitForObjectSel()
         
         return False 

      #=========================================================================
      # RISPOSTA ALLA SELEZIONE DI UN OGGETTO
      elif self.step == 2:
         entity = None
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  value = QadMsg.translate("Command_OFFSET", "Exit")
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False
            else:
               entity = self.getPointMapTool().entity
               value = self.getPointMapTool().point
         else: # il punto arriva come parametro della funzione
            value = msg
         
         if type(value) == unicode:
            if value == QadMsg.translate("Command_OFFSET", "Exit") or value == "Exit":
               self.offsetGeoms(currLayer)
               return True
            elif value == QadMsg.translate("Command_OFFSET", "Undo") or value == "Undo":
               self.undoGeomsInCache()
               # si appresta ad attendere la selezione di un oggetto
               self.waitForObjectSel()
         elif type(value) == QgsPoint: # se é stato selezionato un punto
            if entity is not None and entity.isInitialized(): # se é stata selezionata una entità
               self.entity.set(entity.layer, entity.featureId)
               self.getPointMapTool().layer = self.entity.layer
               # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
               geom = self.layerToMapCoordinates(entity.layer, entity.getGeometry())

               # ritorna una tupla (<The squared cartesian distance>,
               #                    <minDistPoint>
               #                    <afterVertex>
               #                    <leftOf>)
               dummy = qad_utils.closestSegmentWithContext(value, geom)
               if dummy[2] is not None:
                  # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
                  # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>])
                  self.subGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])[0]
                  self.subGeomSelectedPt = QgsPoint(value)
                  
                  self.getPointMapTool().subGeom = self.subGeom
                  if self.offSet < 0: # richiesta di punto di passaggio
                     self.waitForPassagePt()
                  else:  # richiesta la parte dell'oggetto
                     self.waitForSidePt()
            else:
               # si appresta ad attendere la selezione di un oggetto
               self.waitForObjectSel()

         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DI UN PUNTO PER STABILIRE LA PARTE DI OFFSET  (da step = 2)
      elif self.step == 3:
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  if self.multi == False: # default = esci                     
                     self.offsetGeoms(currLayer)
                     return True # fine comando
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False

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

         if value is None: # oggetto successivo
            # si appresta ad attendere la selezione di un oggetto
            self.waitForObjectSel()
         else:
            if type(value) == unicode:
               if value == QadMsg.translate("Command_OFFSET", "Exit") or value == "Exit":
                  self.offsetGeoms(currLayer)
                  return True # fine comando
               elif value == QadMsg.translate("Command_OFFSET", "Multiple") or value == "Multiple":
                  self.multi = True
                  self.waitForSidePt()               
               elif value == QadMsg.translate("Command_OFFSET", "Undo") or value == "Undo":
                  self.undoGeomsInCache()               
                  # si appresta ad attendere la selezione di un oggetto
                  self.waitForObjectSel()
               elif value == QadMsg.translate("Command_OFFSET", "Segment") or value == "Segment":
                  self.OnlySegment = True   
                  linearObject = qad_utils.QadLinearObject()
                  if linearObject.setByClosestSegmentOfGeom(self.subGeomSelectedPt, self.subGeom) == True:
                     self.subGeom = QgsGeometry.fromPolyline(linearObject.asPolyline())
                     self.getPointMapTool().subGeom = self.subGeom
                  
                  self.waitForSidePt()                  
            elif type(value) == QgsPoint: # se é stato selezionato un punto            
               self.addFeatureCache(value) 
               if self.multi == False:
                  # si appresta ad attendere la selezione di un oggetto
                  self.waitForObjectSel()
               else:
                  # richiesta la parte dell'oggetto
                  self.waitForSidePt()

         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DI UN PUNTO DI PASSAGGIO DI OFFSET  (da step = 2)
      elif self.step == 4:
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  if self.multi == False: # default = esci                     
                     self.offsetGeoms(currLayer)
                     return True # fine comando
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False

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

         if value is None: # oggetto successivo
            # si appresta ad attendere la selezione di un oggetto
            self.waitForObjectSel()
         else:
            if type(value) == unicode:
               if value == QadMsg.translate("Command_OFFSET", "Exit") or value == "Exit":
                  self.offsetGeoms(currLayer)
                  return True # fine comando
               elif value == QadMsg.translate("Command_OFFSET", "Multiple") or value == "Multiple":
                  self.multi = True
                  self.waitForPassagePt()     
               elif value == QadMsg.translate("Command_OFFSET", "Undo") or value == "Undo":
                  self.undoGeomsInCache()               
                  # si appresta ad attendere la selezione di un oggetto
                  self.waitForObjectSel()
               elif value == QadMsg.translate("Command_OFFSET", "Segment") or value == "Segment":
                  self.OnlySegment = True                  
                  linearObject = qad_utils.QadLinearObject()
                  if linearObject.setByClosestSegmentOfGeom(self.subGeomSelectedPt, self.subGeom) == True:
                     self.subGeom = QgsGeometry.fromPolyline(linearObject.asPolyline())
                     self.getPointMapTool().subGeom = self.subGeom
                  
                  self.waitForPassagePt()     
            elif type(value) == QgsPoint: # se é stato selezionato un punto            
               self.addFeatureCache(value)       
               if self.multi == False:
                  # si appresta ad attendere la selezione di un oggetto
                  self.waitForObjectSel()
               else:
                  # richiesta di punto di passaggio
                  self.waitForPassagePt()

         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA DI CANCELLAZIONE OGGETTO SORGENTE (da step = 1)
      elif self.step == 5: # dopo aver atteso un punto o un numero reale si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
               value = QadMsg.translate("QAD", "No")   
            else:
               self.setMapTool(self.getPointMapTool()) # riattivo il maptool
               return False
         else: # il valore arriva come parametro della funzione
            value = msg

         if type(value) == unicode:
            if value == QadMsg.translate("QAD", "Yes") or value == "Yes":
               self.eraseEntity = True
               self.waitForDistance()
            elif value == QadMsg.translate("QAD", "No") or value == "No":
               self.eraseEntity = False
               self.waitForDistance()
         
         return False

      #=========================================================================
      # RISPOSTA ALLA RICHIESTA SECONDO PUNTO PER LUNGHEZZA OFFSET (da step = 1)
      elif self.step == 6: # dopo aver atteso un punto o un numero reale si riavvia il comando
         if msgMapTool == True: # il punto arriva da una selezione grafica
            # la condizione seguente si verifica se durante la selezione di un punto
            # é stato attivato un altro plugin che ha disattivato Qad
            # quindi stato riattivato il comando che torna qui senza che il maptool
            # abbia selezionato un punto            
            if self.getPointMapTool().point is None: # il maptool é stato attivato senza un punto
               if self.getPointMapTool().rightButton == True: # se usato il tasto destro del mouse
                  return True # fine comando
               else:
                  self.setMapTool(self.getPointMapTool()) # riattivo il maptool
                  return False

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

         if value == self.firstPt:
            self.showMsg(QadMsg.translate("QAD", "\nThe value must be positive and not zero."))
            # si appresta ad attendere un punto
            self.waitForPoint(QadMsg.translate("Command_OFFSET", "Specify second point: "))
            return False
               
         self.offSet = qad_utils.getDistance(self.firstPt, value)
         self.getPointMapTool().offSet = self.offSet
         QadVariables.set(QadMsg.translate("Environment variables", "OFFSETDIST"), self.offSet)
         QadVariables.save()
         # si appresta ad attendere la selezione di un oggetto
         self.waitForObjectSel()

         return False
                  
               
コード例 #21
0
ファイル: qad_fillet_maptool.py プロジェクト: resistor4u/QAD
   def canvasMoveEvent(self, event):
      QadGetPoint.canvasMoveEvent(self, event)
      
      self.__rubberBand.reset()
      tmpLinearObjectList = None
       
      # si richiede la selezione del secondo oggetto
      if self.mode == Qad_fillet_maptool_ModeEnum.ASK_FOR_SECOND_LINESTRING:
         if self.tmpEntity.isInitialized():                                                         
            # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
            geom = self.layerToMapCoordinates(self.tmpEntity.layer, self.tmpEntity.getGeometry())
            
            # ritorna una tupla (<The squared cartesian distance>,
            #                    <minDistPoint>
            #                    <afterVertex>
            #                    <leftOf>)
            dummy = qad_utils.closestSegmentWithContext(self.tmpPoint, geom)
            if dummy[2] is not None:
               # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
               subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])               
               tmpLinearObjectList = qad_utils.QadLinearObjectList()               
               tmpLinearObjectList.fromPolyline(subGeom.asPolyline())
               
               # la funzione ritorna una lista con (<minima distanza al quadrato>,
               #                                    <punto più vicino>
               #                                    <indice della parte più vicina>       
               #                                    <"a sinistra di">)
               dummy = tmpLinearObjectList.closestPartWithContext(self.tmpPoint)
               tmpPartAt = dummy[2]
               tmpPointAt = dummy[1]
               
               # stessa entità e stessa parte
               if self.layer.id() == self.tmpEntity.layer.id() and \
                  self.featureId == self.tmpEntity.featureId and \
                  self.partAt == tmpPartAt:
                  return

               # uso il crs del canvas per lavorare con coordinate piane xy
               epsg = self.canvas.mapRenderer().destinationCrs().authid()
               
               if self.tmpShiftKey == True: # tasto shift premuto durante il movimento del mouse
                  # filletMode = 1 # modalità di raccordo; 1=Taglia-estendi
                  # raggio = 0
                  res = qad_utils.getFilletLinearObjectList(self.linearObjectList, self.partAt, self.pointAt, \
                                                            tmpLinearObjectList, tmpPartAt, tmpPointAt,\
                                                            1, 0, epsg)
               else:               
                  res = qad_utils.getFilletLinearObjectList(self.linearObjectList, self.partAt, self.pointAt, \
                                                            tmpLinearObjectList, tmpPartAt, tmpPointAt,\
                                                            self.filletMode, self.radius, epsg)
               if res is None: # raccordo non possibile
                  return
               tmpLinearObjectList = res[0]
                        
      # si richiede la selezione della polilinea
      elif self.mode == Qad_fillet_maptool_ModeEnum.ASK_FOR_POLYLINE:
         if self.tmpEntity.isInitialized():
            # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
            geom = self.layerToMapCoordinates(self.tmpEntity.layer, self.tmpEntity.getGeometry())
            # ritorna una tupla (<The squared cartesian distance>,
            #                    <minDistPoint>
            #                    <afterVertex>
            #                    <leftOf>)
            dummy = qad_utils.closestSegmentWithContext(self.tmpPoint, geom)
            if dummy[2] is not None:
               # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
               subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(geom, dummy[2])               
               tmpLinearObjectList = qad_utils.QadLinearObjectList()
               tmpLinearObjectList.fromPolyline(subGeom.asPolyline())
               tmpLinearObjectList.fillet(self.radius)
      
      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 canvas per lavorare con coordinate piane xy
         geom = self.layerToMapCoordinates(self.layer, geom)            
         self.__rubberBand.addGeometry(geom, self.layer)
コード例 #22
0
    def canvasMoveEvent(self, event):
        QadGetPoint.canvasMoveEvent(self, event)

        self.__rubberBand.reset()
        tmpLinearObjectList = None

        # si richiede la selezione del secondo oggetto
        if self.mode == Qad_fillet_maptool_ModeEnum.ASK_FOR_SECOND_LINESTRING:
            if self.tmpEntity.isInitialized():
                # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
                geom = self.layerToMapCoordinates(self.tmpEntity.layer,
                                                  self.tmpEntity.getGeometry())

                # ritorna una tupla (<The squared cartesian distance>,
                #                    <minDistPoint>
                #                    <afterVertex>
                #                    <leftOf>)
                dummy = qad_utils.closestSegmentWithContext(
                    self.tmpPoint, geom)
                if dummy[2] is not None:
                    # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
                    subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(
                        geom, dummy[2])
                    tmpLinearObjectList = qad_utils.QadLinearObjectList()
                    tmpLinearObjectList.fromPolyline(subGeom.asPolyline())

                    # la funzione ritorna una lista con (<minima distanza al quadrato>,
                    #                                    <punto più vicino>
                    #                                    <indice della parte più vicina>
                    #                                    <"a sinistra di">)
                    dummy = tmpLinearObjectList.closestPartWithContext(
                        self.tmpPoint)
                    tmpPartAt = dummy[2]
                    tmpPointAt = dummy[1]

                    # stessa entità e stessa parte
                    if self.layer.id() == self.tmpEntity.layer.id() and \
                       self.featureId == self.tmpEntity.featureId and \
                       self.partAt == tmpPartAt:
                        return

                    # uso il crs del canvas per lavorare con coordinate piane xy
                    epsg = self.canvas.mapRenderer().destinationCrs().authid()

                    if self.tmpShiftKey == True:  # tasto shift premuto durante il movimento del mouse
                        # filletMode = 1 # modalità di raccordo; 1=Taglia-estendi
                        # raggio = 0
                        res = qad_utils.getFilletLinearObjectList(self.linearObjectList, self.partAt, self.pointAt, \
                                                                  tmpLinearObjectList, tmpPartAt, tmpPointAt,\
                                                                  1, 0, epsg)
                    else:
                        res = qad_utils.getFilletLinearObjectList(self.linearObjectList, self.partAt, self.pointAt, \
                                                                  tmpLinearObjectList, tmpPartAt, tmpPointAt,\
                                                                  self.filletMode, self.radius, epsg)
                    if res is None:  # raccordo non possibile
                        return
                    tmpLinearObjectList = res[0]

        # si richiede la selezione della polilinea
        elif self.mode == Qad_fillet_maptool_ModeEnum.ASK_FOR_POLYLINE:
            if self.tmpEntity.isInitialized():
                # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
                geom = self.layerToMapCoordinates(self.tmpEntity.layer,
                                                  self.tmpEntity.getGeometry())
                # ritorna una tupla (<The squared cartesian distance>,
                #                    <minDistPoint>
                #                    <afterVertex>
                #                    <leftOf>)
                dummy = qad_utils.closestSegmentWithContext(
                    self.tmpPoint, geom)
                if dummy[2] is not None:
                    # ritorna la sotto-geometria al vertice <atVertex> e la sua posizione nella geometria (0-based)
                    subGeom, atSubGeom = qad_utils.getSubGeomAtVertex(
                        geom, dummy[2])
                    tmpLinearObjectList = qad_utils.QadLinearObjectList()
                    tmpLinearObjectList.fromPolyline(subGeom.asPolyline())
                    tmpLinearObjectList.fillet(self.radius)

        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 canvas per lavorare con coordinate piane xy
            geom = self.layerToMapCoordinates(self.layer, geom)
            self.__rubberBand.addGeometry(geom, self.layer)