示例#1
0
   def filletPolyline(self):         
      layer = self.entity1.layer

      transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.plugIn.canvas, layer)
      tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \
                                                                  self.plugin.canvas, \
                                                                  layer)                              
      f = self.entity1.getFeature()
      geom = f.geometry() 

      self.linearObjectList1.fillet(transformedRadius)
               
      updSubGeom = QgsGeometry.fromPolyline(self.linearObjectList1.asPolyline(tolerance2ApproxCurve))
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1)
      if updGeom is None:
         return False
      f.setGeometry(updGeom)
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
示例#2
0
文件: qad_move_cmd.py 项目: gam17/QAD
 def move(self, entity, offSetX, offSetY):
    # entity = entità da spostare
    # 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":
       # sposto l'entità
       movedGeom = qad_utils.moveQgsGeometry(entity.getGeometry(), offSetX, offSetY)
       
       if movedGeom is not None:
          f = entity.getFeature()
          f.setGeometry(movedGeom)
          if self.copyEntities == False:
             # plugIn, layer, feature, refresh, check_validity
             if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
                return False
          else:
             # plugIn, layer, features, coordTransform, refresh, check_validity
             if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
                return False
             
    elif entity.whatIs() == "DIMENTITY":
       # stiro la quota
       if self.copyEntities == False:
          if entity.deleteToLayers(self.plugIn) == False:
             return False                      
       newDimEntity = QadDimEntity(entity) # la copio
       newDimEntity.move(offSetX, offSetY)
       if newDimEntity.addToLayers(self.plugIn) == False:
          return False             
          
    return True
示例#3
0
    def move(self, f, offSetX, offSetY, layerEntitySet, entitySet):
        # verifico se l'entità appartiene ad uno stile di quotatura
        dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())

        if dimEntity is None:
            # sposto la feature e la rimuovo da entitySet (é la prima)
            f.setGeometry(
                qad_utils.moveQgsGeometry(f.geometry(), offSetX, offSetY))
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn,
                                              layerEntitySet.layer, f, False,
                                              False) == False:
                return False
            del layerEntitySet.featureIds[0]
        else:
            # sposto la quota e la rimuovo da entitySet
            dimEntitySet = dimEntity.getEntitySet()
            if dimEntity.deleteToLayers(self.plugIn) == False:
                return False
            if dimEntity.move(offSetX, offSetY) == False:
                return False
            if dimEntity.addToLayers(self.plugIn) == False:
                return False
            entitySet.subtract(dimEntitySet)

        return True
示例#4
0
 def scale(self, entity, basePt, scale, sizeFldName):
    # entity = entità da scalare
    # basePt = punto base
    # scale = fattore di scala
    # sizeFldName = campo della tabella che memorizza la scala
    # verifico se l'entità appartiene ad uno stile di quotatura
    if entity.whatIs() == "ENTITY":
       f = entity.getFeature()
       # ruoto l'entità
       f.setGeometry(qad_utils.scaleQgsGeometry(entity.getGeometry(), basePt, scale))
       if len(sizeFldName) > 0:
          sizeValue = f.attribute(sizeFldName)
          if sizeValue is None:
             sizeValue = 1
          sizeValue = sizeValue * scale
          f.setAttribute(sizeFldName, sizeValue)                           
       
       if self.copyEntities == False:
          # plugIn, layer, feature, refresh, check_validity
          if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
             return False
       else:
          # plugIn, layer, features, coordTransform, refresh, check_validity
          if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
             return False
             
    elif entity.whatIs() == "DIMENTITY":
       # stiro la quota
       if self.copyEntities == False:
          if entity.deleteToLayers(self.plugIn) == False:
             return False           
       entity.scale(self.plugIn, basePt, scale)
       if entity.addToLayers(self.plugIn) == False:
          return False
示例#5
0
   def filletPolyline(self):         
      layer = self.entity1.layer

      tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
      f = self.entity1.getFeature()
      # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
      geom = self.layerToMapCoordinates(layer, f.getGeometry())

      self.linearObjectList1.fillet(self.radius)
               
      updSubGeom = QgsGeometry.fromPolyline(self.linearObjectList1.asPolyline(tolerance2ApproxCurve))
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1)
      if updGeom is None:
         return False
      # trasformo la geometria nel crs del layer
      f.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
示例#6
0
   def rotate(self, entity, basePt, angle, rotFldName):
      # entity = entità da ruotare
      # basePt = punto base
      # angle = angolo di rotazione in gradi
      # rotFldName = campo della tabella che memorizza la rotazione
      # verifico se l'entità appartiene ad uno stile di quotatura
      if entity.whatIs() == "ENTITY":
         f = entity.getFeature()
         # ruoto l'entità
         f.setGeometry(qad_utils.rotateQgsGeometry(entity.getGeometry(), basePt, angle))
         if len(rotFldName) > 0:
            rotValue = f.attribute(rotFldName)
            rotValue = 0 if rotValue is None else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
            rotValue = rotValue + angle
            f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))               
         
         if self.copyEntities == False:
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
               return False
         else:
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
               return False
               
      elif entity.whatIs() == "DIMENTITY":
         # stiro la quota
         if self.copyEntities == False:
            if entity.deleteToLayers(self.plugIn) == False:
               return False           
         entity.rotate(self.plugIn, basePt, angle)
         if entity.addToLayers(self.plugIn) == False:
            return False             

      return True
    def filletPolyline(self):
        layer = self.entity1.layer

        tolerance2ApproxCurve = QadVariables.get(
            QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))
        f = self.entity1.getFeature()
        # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
        geom = self.layerToMapCoordinates(layer, f.getGeometry())

        self.linearObjectList1.fillet(self.radius)

        updSubGeom = QgsGeometry.fromPolyline(
            self.linearObjectList1.asPolyline(tolerance2ApproxCurve))
        updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1)
        if updGeom is None:
            return False
        # trasformo la geometria nel crs del layer
        f.setGeometry(self.mapToLayerCoordinates(layer, updGeom))

        self.plugIn.beginEditCommand("Feature edited", layer)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False,
                                          False) == False:
            self.plugIn.destroyEditCommand()
            return False

        self.plugIn.endEditCommand()
        self.nOperationsToUndo = self.nOperationsToUndo + 1

        return True
示例#8
0
   def delCurrentSubGeomToPolygon(self):
      """
      Cancella la sotto-geometria corrente dal poligono da modificare
      """
      geom = self.poligonEntity.getGeometry()

       # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>])
      part = self.currAtSubGeom[0]
      if len(self.currAtSubGeom) == 2:
         ring = self.currAtSubGeom[1]
         if geom.deleteRing(ring + 1, part) == False: # cancello una isola (Ring 0 is outer ring and can't be deleted)
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False
      else:
         if geom.deletePart(part) == False: # cancello una parte
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

      f = self.poligonEntity.getFeature()
      f.setGeometry(geom)

      self.plugIn.beginEditCommand("Feature edited", self.poligonEntity.layer)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
示例#9
0
   def delCurrentSubGeomToPolygon(self):
      """
      Cancella la sotto-geometria corrente dal poligono da modificare
      """
      geom = self.poligonEntity.getGeometry()

       # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>])
      part = self.currAtSubGeom[0]
      if len(self.currAtSubGeom) == 2:
         ring = self.currAtSubGeom[1]
         if geom.deleteRing(ring + 1, part) == False: # cancello una isola (Ring 0 is outer ring and can't be deleted)
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False
      else:
         if geom.deletePart(part) == False: # cancello una parte
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

      f = self.poligonEntity.getFeature()
      f.setGeometry(geom)

      self.plugIn.beginEditCommand("Feature edited", self.poligonEntity.layer)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
 def move(self, entity, offSetX, offSetY):
    # entity = entità da spostare
    # 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":
       # sposto l'entità
       movedGeom = qad_utils.moveQgsGeometry(entity.getGeometry(), offSetX, offSetY)
       
       if movedGeom is not None:
          f = entity.getFeature()
          f.setGeometry(movedGeom)
          if self.copyEntities == False:
             # plugIn, layer, feature, refresh, check_validity
             if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
                return False
          else:
             # plugIn, layer, features, coordTransform, refresh, check_validity
             if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
                return False
             
    elif entity.whatIs() == "DIMENTITY":
       # stiro la quota
       if self.copyEntities == False:
          if entity.deleteToLayers(self.plugIn) == False:
             return False                      
       newDimEntity = QadDimEntity(entity) # la copio
       newDimEntity.move(offSetX, offSetY)
       if newDimEntity.addToLayers(self.plugIn) == False:
          return False             
          
    return True
示例#11
0
   def stretch(self, f, containerGeom, offSetX, offSetY, tolerance2ApproxCurve, layerEntitySet, entitySet):
      # verifico se l'entità appartiene ad uno stile di quotatura
      dimEntity = self.plugIn.dimStyles.getDimEntity(layerEntitySet.layer, f.id())

      if dimEntity is None:
         # stiro la feature e la rimuovo da entitySet (é la prima)
         stretchedGeom = qad_utils.stretchQgsGeometry(f.geometry(), containerGeom, \
                                                      offSetX, offSetY, \
                                                      tolerance2ApproxCurve)
         
         if stretchedGeom is not None:
            f.setGeometry(stretchedGeom)
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False
         del layerEntitySet.featureIds[0]
      else:
         # ruoto la quota e la rimuovo da entitySet
         dimEntitySet = dimEntity.getEntitySet()
         if dimEntity.deleteToLayers(self.plugIn) == False:
            return False                      
         dimEntity.stretch(self.plugIn, containerGeom, offSetX, offSetY)
         if dimEntity.addToLayers(self.plugIn) == False:
            return False             
         entitySet.subtract(dimEntitySet)
            
      return True
示例#12
0
   def addEntitySetToPolyline(self, entitySet, removeOriginals = True):
      """
      Aggiunge il set di entità alla polilinea da modificare
      """
      geom = self.entity.getGeometry()
      layerList = []
      layerList.append(self.entity.layer)
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         if layer.geometryType() != QGis.Polygon and layer.geometryType() != QGis.Line:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

         if removeOriginals: layerList.append(layer)
         coordTransform = QgsCoordinateTransform(layer.crs(), self.entity.layer.crs())

         for featureId in layerEntitySet.featureIds:
            # se la feature è quella di entity è errore 
            if layer.id() == self.entity.layerId() and featureId == self.entity.featureId:
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
            
            f = layerEntitySet.getFeature(featureId)
            # trasformo la geometria nel crs del layer dell'entità da modificare
            geomToAdd = f.geometry()
            geomToAdd.transform(coordTransform)
            
            # Riduco la geometria in point o polyline
            simplifiedGeoms = qad_utils.asPointOrPolyline(geomToAdd)
            for simplifiedGeom in simplifiedGeoms:
               points = simplifiedGeom.asPolyline() # vettore di punti                     
               # aggiungo una parte
               if geom.addPart(points) != 0: # 0 in case of success
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False

      f = self.entity.getFeature()
      f.setGeometry(geom)

      layerList = entitySet.getLayerList()
      layerList.append(self.entity.layer)

      self.plugIn.beginEditCommand("Feature edited", layerList)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.entity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      if removeOriginals:
         for layerEntitySet in entitySet.layerEntitySetList:            
            if qad_layer.deleteFeaturesToLayer(self.plugIn, layerEntitySet.layer, layerEntitySet.featureIds, False) == False:
               self.plugIn.destroyEditCommand()
               return 

      self.plugIn.endEditCommand()

      return True
示例#13
0
    def convexHullEntitySetToPolygon(self, entitySet, removeOriginals=False):
        """
      modifica il poligono corrente in modo che includa tutti i punti delle geometrie di entitySet
      """
        layerList = []
        layerList.append(self.poligonEntity.layer)
        pointsForConvexHull = []

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer
            coordTransform = QgsCoordinateTransform(layer.crs(), self.poligonEntity.layer.crs())

            for featureId in layerEntitySet.featureIds:
                f = layerEntitySet.getFeature(featureId)
                # trasformo la geometria nel crs del layer del poligono da modificare
                geom = f.geometry()
                geom.transform(coordTransform)

                # Riduco la geometria in point o polyline
                simplifiedGeoms = qad_utils.asPointOrPolyline(geom)
                for simplifiedGeom in simplifiedGeoms:
                    if simplifiedGeom.wkbType() == QGis.WKBLineString:
                        pointsForConvexHull.extend(simplifiedGeom.asPolyline())
                    else:
                        pointsForConvexHull.append(simplifiedGeom.asPoint())

                if removeOriginals and layer.id() != self.poligonEntity.layerId():
                    layerList.append(layer)

        geom = QgsGeometry.fromMultiPoint(pointsForConvexHull)
        geom = geom.convexHull()
        if geom is None:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

        f = self.poligonEntity.getFeature()
        f.setGeometry(geom)

        self.plugIn.beginEditCommand("Feature edited", layerList)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        if removeOriginals:
            for layerEntitySet in entitySet.layerEntitySetList:
                if (
                    qad_layer.deleteFeaturesToLayer(self.plugIn, layerEntitySet.layer, layerEntitySet.featureIds, False)
                    == False
                ):
                    self.plugIn.destroyEditCommand()
                    return

        self.plugIn.endEditCommand()
        self.nOperationsToUndo = self.nOperationsToUndo + 1

        return True
示例#14
0
    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
        # 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.plugIn.canvas.mapSettings().destinationCrs())
            stretchedGeom.transform(coordTransform)
            # stiro la feature
            stretchedGeom = qad_stretch_fun.gripStretchQgsGeometry(stretchedGeom, self.basePt, ptList, \
                                                                   offSetX, offSetY, \
                                                                   tolerance2ApproxCurve)

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

                f = entity.getFeature()
                f.setGeometry(stretchedGeom)
                if self.copyEntities == False:
                    # plugIn, layer, feature, refresh, check_validity
                    if qad_layer.updateFeatureToLayer(self.plugIn,
                                                      entity.layer, f, False,
                                                      False) == False:
                        return False
                else:
                    # plugIn, layer, features, coordTransform, refresh, check_validity
                    if qad_layer.addFeatureToLayer(self.plugIn, entity.layer,
                                                   f, None, False,
                                                   False) == False:
                        return False

        elif entity.whatIs() == "DIMENTITY":
            # stiro la quota
            if self.copyEntities == False:
                if entity.deleteToLayers(self.plugIn) == False:
                    return False
            newDimEntity = QadDimEntity(entity)  # la copio
            newDimEntity.stretch(ptList, offSetX, offSetY)
            if newDimEntity.addToLayers(self.plugIn) == False:
                return False
            # non so per quale motivo a volte non si aggiorna la mappa quindi forzo l'aggiornamento
            self.plugIn.canvas.refresh()

        return True
示例#15
0
    def splitPolygon(self, splitLine, createNewEntities):
        """
      divide il poligono corrente usando una polilinea con i vertci in <plineVertices> in modo da generare o meno nuove entità
      """
        layerList = []
        layerList.append(self.poligonEntity.layer)

        splitLineTransformed = self.mapToLayerCoordinates(
            self.poligonEntity.layer, splitLine)
        f = self.poligonEntity.getFeature()
        geom = f.geometry()
        result, newGeoms, topologyTestPts = geom.splitGeometry(
            splitLineTransformed, False)

        if result <> 0 or len(newGeoms) == 0:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

        newfeatures = []
        if createNewEntities:
            for newGeom in newGeoms:
                newfeature = QgsFeature(f)
                newfeature.setGeometry(newGeom)
                newfeatures.append(newfeature)
        else:
            for newGeom in newGeoms:
                # Riduco la geometria in point o polyline
                simplifiedGeoms = qad_utils.asPointOrPolyline(newGeom)
                for simplifiedGeom in simplifiedGeoms:
                    points = simplifiedGeom.asPolyline()  # vettore di punti
                    res = geom.addPart(points)

        f.setGeometry(geom)

        self.plugIn.beginEditCommand("Feature edited", layerList)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn,
                                          self.poligonEntity.layer, f, False,
                                          False) == False:
            self.plugIn.destroyEditCommand()
            return False

        if len(newfeatures) > 0:
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeaturesToLayer(self.plugIn,
                                            self.poligonEntity.layer,
                                            newfeatures, None, False,
                                            False) == False:
                self.plugIn.destroyEditCommand()
                return

        self.plugIn.endEditCommand()
        self.nOperationsToUndo = self.nOperationsToUndo + 1

        return True
示例#16
0
   def convexHullEntitySetToPolygon(self, entitySet, removeOriginals = False):
      """
      modifica il poligono corrente in modo che includa tutti i punti delle geometrie di entitySet
      """
      layerList = []
      layerList.append(self.poligonEntity.layer)
      pointsForConvexHull = []
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         coordTransform = QgsCoordinateTransform(layer.crs(), self.poligonEntity.layer.crs())
         
         for featureId in layerEntitySet.featureIds:
            f = layerEntitySet.getFeature(featureId)
            # trasformo la geometria nel crs del layer del poligono da modificare
            geom = f.geometry()
            geom.transform(coordTransform)

            # Riduco la geometria in point o polyline
            simplifiedGeoms = qad_utils.asPointOrPolyline(geom)
            for simplifiedGeom in simplifiedGeoms:
               if simplifiedGeom.wkbType() == QGis.WKBLineString:
                  pointsForConvexHull.extend(simplifiedGeom.asPolyline())
               else:
                  pointsForConvexHull.append(simplifiedGeom.asPoint())
               
            if removeOriginals and layer.id() != self.poligonEntity.layerId():
               layerList.append(layer)

      geom = QgsGeometry.fromMultiPoint(pointsForConvexHull)
      geom = geom.convexHull()
      if geom is None:
         self.showMsg(QadMsg.translate("QAD", "Invalid object."))
         return False
         
      f = self.poligonEntity.getFeature()
      f.setGeometry(geom)

      self.plugIn.beginEditCommand("Feature edited", layerList)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      if removeOriginals:
         for layerEntitySet in entitySet.layerEntitySetList:            
            if qad_layer.deleteFeaturesToLayer(self.plugIn, layerEntitySet.layer, layerEntitySet.featureIds, False) == False:
               self.plugIn.destroyEditCommand()
               return 

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1

      return True
示例#17
0
    def splitPolygon(self, splitLine, createNewEntities):
        """
      divide il poligono corrente usando una polilinea con i vertci in <plineVertices> in modo da generare o meno nuove entità
      """
        layerList = []
        layerList.append(self.poligonEntity.layer)

        splitLineTransformed = self.mapToLayerCoordinates(self.poligonEntity.layer, splitLine)
        f = self.poligonEntity.getFeature()
        geom = f.geometry()
        result, newGeoms, topologyTestPts = geom.splitGeometry(splitLineTransformed, False)

        if result <> 0 or len(newGeoms) == 0:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

        newfeatures = []
        if createNewEntities:
            for newGeom in newGeoms:
                newfeature = QgsFeature(f)
                newfeature.setGeometry(newGeom)
                newfeatures.append(newfeature)
        else:
            for newGeom in newGeoms:
                # Riduco la geometria in point o polyline
                simplifiedGeoms = qad_utils.asPointOrPolyline(newGeom)
                for simplifiedGeom in simplifiedGeoms:
                    points = simplifiedGeom.asPolyline()  # vettore di punti
                    res = geom.addPart(points)

        f.setGeometry(geom)

        self.plugIn.beginEditCommand("Feature edited", layerList)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        if len(newfeatures) > 0:
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if (
                qad_layer.addFeaturesToLayer(self.plugIn, self.poligonEntity.layer, newfeatures, None, False, False)
                == False
            ):
                self.plugIn.destroyEditCommand()
                return

        self.plugIn.endEditCommand()
        self.nOperationsToUndo = self.nOperationsToUndo + 1

        return True
示例#18
0
    def mirror(self, f, pt1, pt2, rotFldName, layerEntitySet, entitySet,
               dimEntity):

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

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

            del layerEntitySet.featureIds[0]
        else:
            # scalo la quota e la rimuovo da entitySet
            mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
            dimEntitySet = dimEntity.getEntitySet()
            if self.copyFeatures == False:
                if dimEntity.deleteToLayers(self.plugIn) == False:
                    return False
            newDimEntity = QadDimEntity(dimEntity)  # la copio
            newDimEntity.mirror(pt1, mirrorAngle)
            if newDimEntity.addToLayers(self.plugIn) == False:
                return False
            entitySet.subtract(dimEntitySet)
示例#19
0
   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
      # 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.plugIn.canvas.mapSettings().destinationCrs())
         stretchedGeom.transform(coordTransform)           
         # stiro la feature
         stretchedGeom = qad_stretch_fun.gripStretchQgsGeometry(stretchedGeom, self.basePt, ptList, \
                                                                offSetX, offSetY, \
                                                                tolerance2ApproxCurve)
         
         if stretchedGeom is not None:
            # trasformo la geometria nel crs del layer
            coordTransform = QgsCoordinateTransform(self.plugIn.canvas.mapSettings().destinationCrs(), entity.layer.crs())
            stretchedGeom.transform(coordTransform)
                       
            f = entity.getFeature()
            f.setGeometry(stretchedGeom)
            if self.copyEntities == False:
               # plugIn, layer, feature, refresh, check_validity
               if qad_layer.updateFeatureToLayer(self.plugIn, entity.layer, f, False, False) == False:
                  return False
            else:
               # plugIn, layer, features, coordTransform, refresh, check_validity
               if qad_layer.addFeatureToLayer(self.plugIn, entity.layer, f, None, False, False) == False:
                  return False
               
      elif entity.whatIs() == "DIMENTITY":
         # stiro la quota
         if self.copyEntities == False:
            if entity.deleteToLayers(self.plugIn) == False:
               return False                      
         newDimEntity = QadDimEntity(entity) # la copio
         newDimEntity.stretch(ptList, offSetX, offSetY)
         if newDimEntity.addToLayers(self.plugIn) == False:
            return False
         # non so per quale motivo a volte non si aggiorna la mappa quindi forzo l'aggiornamento
         self.plugIn.canvas.refresh()
            
      return True
    def rotate(self, f, basePt, angle, rotFldName, layerEntitySet, entitySet):
        # verifico se l'entità appartiene ad uno stile di quotatura
        dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())

        if dimEntity is None:
            # ruoto la feature e la rimuovo da entitySet (é la prima)
            f.setGeometry(
                qad_utils.rotateQgsGeometry(f.geometry(), basePt, angle))

            if len(rotFldName) > 0:
                rotValue = f.attribute(rotFldName)
                # a volte vale None e a volte null (vai a capire...)
                rotValue = 0 if rotValue is None or isinstance(
                    rotValue, QPyNullVariant) else qad_utils.toRadians(
                        rotValue
                    )  # la rotazione é in gradi nel campo della feature
                rotValue = rotValue + angle
                f.setAttribute(
                    rotFldName,
                    qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))

            if self.copyFeatures == False:
                # plugIn, layer, feature, refresh, check_validity
                if qad_layer.updateFeatureToLayer(self.plugIn,
                                                  layerEntitySet.layer, f,
                                                  False, False) == False:
                    self.plugIn.destroyEditCommand()
                    return False
            else:
                # plugIn, layer, features, coordTransform, refresh, check_validity
                if qad_layer.addFeatureToLayer(self.plugIn,
                                               layerEntitySet.layer, f, None,
                                               False, False) == False:
                    self.plugIn.destroyEditCommand()
                    return False
            del layerEntitySet.featureIds[0]
        else:
            # ruoto la quota e la rimuovo da entitySet
            dimEntitySet = dimEntity.getEntitySet()
            if self.copyFeatures == False:
                if dimEntity.deleteToLayers(self.plugIn) == False:
                    return False
            newDimEntity = QadDimEntity(dimEntity)  # la copio
            newDimEntity.rotate(basePt, angle)
            if newDimEntity.addToLayers(self.plugIn) == False:
                return False
            entitySet.subtract(dimEntitySet)

        return True
示例#21
0
    def mirror(self, entity, pt1, pt2, rotFldName):
        # entity = entità da specchiare
        # pt1 e pt2 = linea di simmetria
        # rotFldName = campo della tabella che memorizza la rotazione
        # verifico se l'entità appartiene ad uno stile di quotatura
        if entity.whatIs() == "ENTITY":
            f = entity.getFeature()
            # specchio l'entità
            f.setGeometry(
                qad_utils.mirrorQgsGeometry(entity.getGeometry(), pt1, pt2))
            if len(rotFldName) > 0:
                rotValue = f.attribute(rotFldName)
                # a volte vale None e a volte null (vai a capire...)
                rotValue = 0 if rotValue is None or isinstance(
                    rotValue, QPyNullVariant) else qad_utils.toRadians(
                        rotValue
                    )  # la rotazione é in gradi nel campo della feature
                ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
                mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
                ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
                rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
                f.setAttribute(
                    rotFldName,
                    qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))

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

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

        return True
    def rotate(self, entity, basePt, angle, rotFldName):
        # entity = entità da ruotare
        # basePt = punto base
        # angle = angolo di rotazione in gradi
        # rotFldName = campo della tabella che memorizza la rotazione
        # verifico se l'entità appartiene ad uno stile di quotatura
        if entity.whatIs() == "ENTITY":
            f = entity.getFeature()
            # ruoto l'entità
            f.setGeometry(
                qad_utils.rotateQgsGeometry(entity.getGeometry(), basePt,
                                            angle))
            if len(rotFldName) > 0:
                rotValue = f.attribute(rotFldName)
                # a volte vale None e a volte null (vai a capire...)
                rotValue = 0 if rotValue is None or isinstance(
                    rotValue, QPyNullVariant) else qad_utils.toRadians(
                        rotValue
                    )  # la rotazione é in gradi nel campo della feature
                rotValue = rotValue + angle
                f.setAttribute(
                    rotFldName,
                    qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))

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

        elif entity.whatIs() == "DIMENTITY":
            # stiro la quota
            if self.copyEntities == False:
                if entity.deleteToLayers(self.plugIn) == False:
                    return False
            newDimEntity = QadDimEntity(entity)  # la copio
            newDimEntity.rotate(basePt, angle)
            if newDimEntity.addToLayers(self.plugIn) == False:
                return False

        return True
    def scale(self, f, basePt, scale, sizeFldName, 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))
            if sizeFldName is not None:
                sizeValue = f.attribute(sizeFldName)
                # a volte vale None e a volte null (vai a capire...)
                if sizeValue is None or isinstance(sizeValue, QPyNullVariant):
                    sizeValue = 1
                sizeValue = sizeValue * scale
                f.setAttribute(sizeFldName, sizeValue)

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

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

      return True
    def scale(self, entity, basePt, scale, sizeFldName):
        # entity = entità da scalare
        # basePt = punto base
        # scale = fattore di scala
        # sizeFldName = campo della tabella che memorizza la scala
        # verifico se l'entità appartiene ad uno stile di quotatura
        if entity.whatIs() == "ENTITY":
            f = entity.getFeature()
            # ruoto l'entità
            f.setGeometry(
                qad_utils.scaleQgsGeometry(entity.getGeometry(), basePt,
                                           scale))
            if len(sizeFldName) > 0:
                sizeValue = f.attribute(sizeFldName)
                # a volte vale None e a volte null (vai a capire...)
                if sizeValue is None or isinstance(sizeValue, QPyNullVariant):
                    sizeValue = 1
                sizeValue = sizeValue * scale
                f.setAttribute(sizeFldName, sizeValue)

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

        elif entity.whatIs() == "DIMENTITY":
            # stiro la quota
            if self.copyEntities == False:
                if entity.deleteToLayers(self.plugIn) == False:
                    return False
            newDimEntity = QadDimEntity(entity)  # la copio
            newDimEntity.scale(basePt, scale)
            if newDimEntity.addToLayers(self.plugIn) == False:
                return False
示例#26
0
   def mirror(self, f, pt1, pt2, rotFldName, layerEntitySet, entitySet, dimEntity):
      
      if dimEntity is None:
         # scalo la feature e la rimuovo da entitySet (é la prima)
         f.setGeometry(qad_utils.mirrorQgsGeometry(f.geometry(), pt1, pt2))
         if len(rotFldName) > 0:
            rotValue = f.attribute(rotFldName)
            # a volte vale None e a volte null (vai a capire...)
            rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
            ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
            mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
            ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
            rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
            f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))               
                  
         if self.copyFeatures == False:
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False
         else:             
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False

         del layerEntitySet.featureIds[0]
      else:
         # scalo la quota e la rimuovo da entitySet
         mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
         dimEntitySet = dimEntity.getEntitySet()
         if self.copyFeatures == False:
            if dimEntity.deleteToLayers(self.plugIn) == False:
               return False
         newDimEntity = QadDimEntity(dimEntity) # la copio
         newDimEntity.mirror(pt1, mirrorAngle)
         if newDimEntity.addToLayers(self.plugIn) == False:
            return False             
         entitySet.subtract(dimEntitySet)
示例#27
0
   def rotate(self, f, basePt, angle, rotFldName, layerEntitySet, entitySet):
      # verifico se l'entità appartiene ad uno stile di quotatura
      dimEntity = QadDimStyles.getDimEntity(layerEntitySet.layer, f.id())
      
      if dimEntity is None:
         # ruoto la feature e la rimuovo da entitySet (é la prima)
         f.setGeometry(qad_utils.rotateQgsGeometry(f.geometry(), basePt, angle))

         if len(rotFldName) > 0:
            rotValue = f.attribute(rotFldName)
            # a volte vale None e a volte null (vai a capire...)
            rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
            rotValue = rotValue + angle
            f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))               

         if self.copyFeatures == False:
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False
         else:             
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False
         del layerEntitySet.featureIds[0]
      else:
         # ruoto la quota e la rimuovo da entitySet
         dimEntitySet = dimEntity.getEntitySet()
         if self.copyFeatures == False:
            if dimEntity.deleteToLayers(self.plugIn) == False:
               return False                      
         newDimEntity = QadDimEntity(dimEntity) # la copio
         newDimEntity.rotate(basePt, angle)
         if newDimEntity.addToLayers(self.plugIn) == False:
            return False             
         entitySet.subtract(dimEntitySet)
            
      return True
示例#28
0
   def scale(self, f, basePt, scale, sizeFldName, 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))
         if sizeFldName is not None:
            sizeValue = f.attribute(sizeFldName)
            # a volte vale None e a volte null (vai a capire...)
            if sizeValue is None or isinstance(sizeValue, QPyNullVariant):
               sizeValue = 1
            sizeValue = sizeValue * scale
            f.setAttribute(sizeFldName, sizeValue)                           
         
         if self.copyFeatures == False:
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False
         else:             
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False

         del layerEntitySet.featureIds[0]
      else:
         # scalo la quota e la rimuovo da entitySet
         dimEntitySet = dimEntity.getEntitySet()
         if self.copyFeatures == False:
            if dimEntity.deleteToLayers(self.plugIn) == False:
               return False                      
         newDimEntity = QadDimEntity(dimEntity) # la copio
         newDimEntity.scale(basePt, scale)
         if newDimEntity.addToLayers(self.plugIn) == False:
            return False             
         entitySet.subtract(dimEntitySet)
示例#29
0
 def move(self, f, offSetX, offSetY, layerEntitySet, entitySet):
    # verifico se l'entità appartiene ad uno stile di quotatura
    dimEntity = self.plugIn.dimStyles.getDimEntity(layerEntitySet.layer, f.id())
          
    if dimEntity is None:
       # sposto la feature e la rimuovo da entitySet (é la prima)
       f.setGeometry(qad_utils.moveQgsGeometry(f.geometry(), offSetX, offSetY))
       # plugIn, layer, feature, refresh, check_validity
       if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
          return False
       del layerEntitySet.featureIds[0]
    else:
       # sposto la quota e la rimuovo da entitySet
       dimEntitySet = dimEntity.getEntitySet()
       if dimEntity.deleteToLayers(self.plugIn) == False:
          return False                     
       if dimEntity.move(offSetX, offSetY) == False:
          return False             
       if dimEntity.addToLayers(self.plugIn) == False:
          return False             
       entitySet.subtract(dimEntitySet)
          
    return True
   def breakFeatures(self):
      f = self.entSelClass.entity.getFeature()
      if f is None:
         return
      
      layer = self.entSelClass.entity.layer
      LineTempLayer = None
      self.plugIn.beginEditCommand("Feature broken", layer)
      
      tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))                           

      # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
      g = self.layerToMapCoordinates(layer, f.geometry())         
      result = qad_utils.breakQgsGeometry(g, self.firstPt, self.secondPt, \
                                          tolerance2ApproxCurve)                  
      if result is not None:
         line1 = result[0]
         line2 = result[1]
         atSubGeom = result[2]
         if layer.geometryType() == QGis.Line:
            if line1 is not None:
               updGeom = qad_utils.setSubGeom(g, line1, atSubGeom)
               if updGeom is None:
                  self.plugIn.destroyEditCommand()
                  return
               brokenFeature1 = QgsFeature(f)
               # trasformo la geometria nel crs del layer
               brokenFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
               # plugIn, layer, feature, refresh, check_validity
               if qad_layer.updateFeatureToLayer(self.plugIn, layer, brokenFeature1, False, False) == False:
                  self.plugIn.destroyEditCommand()
                  return
            if line2 is not None:
               brokenFeature2 = QgsFeature(f)      
               # trasformo la geometria nel crs del layer
               brokenFeature2.setGeometry(self.mapToLayerCoordinates(layer, line2))
               # plugIn, layer, feature, coordTransform, refresh, check_validity
               if qad_layer.addFeatureToLayer(self.plugIn, layer, brokenFeature2, 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 broken", LineTempLayer)
            
            lineGeoms = []
            if line1 is not None:
               lineGeoms.append(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(g, 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:
               brokenFeature1 = QgsFeature(f)
               # trasformo la geometria nel crs del layer
               brokenFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
               # plugIn, layer, feature, refresh, check_validity
               if qad_layer.updateFeatureToLayer(self.plugIn, layer, brokenFeature1, False, False) == False:
                  self.plugIn.destroyEditCommand()
                  return

      self.plugIn.endEditCommand()
示例#31
0
    def breakFeatures(self):
        f = self.EntSelClass.entity.getFeature()
        if f is None:
            return

        layer = self.EntSelClass.entity.layer
        LineTempLayer = None
        self.plugIn.beginEditCommand("Feature broken", layer)

        tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))

        # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
        g = self.layerToMapCoordinates(layer, f.geometry())
        result = qad_utils.breakQgsGeometry(g, self.firstPt, self.secondPt, tolerance2ApproxCurve)
        if result is not None:
            line1 = result[0]
            line2 = result[1]
            atSubGeom = result[2]
            if layer.geometryType() == QGis.Line:
                if line1 is not None:
                    updGeom = qad_utils.setSubGeom(g, line1, atSubGeom)
                    if updGeom is None:
                        self.plugIn.destroyEditCommand()
                        return
                    brokenFeature1 = QgsFeature(f)
                    # trasformo la geometria nel crs del layer
                    brokenFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
                    # plugIn, layer, feature, refresh, check_validity
                    if qad_layer.updateFeatureToLayer(self.plugIn, layer, brokenFeature1, False, False) == False:
                        self.plugIn.destroyEditCommand()
                        return
                if line2 is not None:
                    brokenFeature2 = QgsFeature(f)
                    # trasformo la geometria nel crs del layer
                    brokenFeature2.setGeometry(self.mapToLayerCoordinates(layer, line2))
                    # plugIn, layer, feature, coordTransform, refresh, check_validity
                    if qad_layer.addFeatureToLayer(self.plugIn, layer, brokenFeature2, 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 broken", LineTempLayer)

                lineGeoms = []
                if line1 is not None:
                    lineGeoms.append(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(g, 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:
                    brokenFeature1 = QgsFeature(f)
                    # trasformo la geometria nel crs del layer
                    brokenFeature1.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
                    # plugIn, layer, feature, refresh, check_validity
                    if qad_layer.updateFeatureToLayer(self.plugIn, layer, brokenFeature1, False, False) == False:
                        self.plugIn.destroyEditCommand()
                        return

        self.plugIn.endEditCommand()
示例#32
0
   def breakFeatures(self):
      layer = self.EntSelClass.entity.layer
      LineTempLayer = None
      self.plugIn.beginEditCommand("Feature broken", layer)
      
      tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \
                                                                  self.plugIn.canvas,\
                                                                  layer)                              
                  
      f = self.EntSelClass.entity.getFeature()
      g = f.geometry()
      if self.plugIn.canvas.mapRenderer().destinationCrs() != layer.crs():         
         # Trasformo i punti di break nel sistema di coordinate del layer
         self.firstPt = self.mapToLayerCoordinates(layer, self.firstPt)
         self.secondPt = self.mapToLayerCoordinates(layer, self.secondPt)
         
      result = qad_utils.breakQgsGeometry(layer, f.geometry(), self.firstPt, self.secondPt, \
                                          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.geometry(), line1, atSubGeom)
            if updGeom is None:
               self.plugIn.destroyEditCommand()
               return
            brokenFeature1 = QgsFeature(f)
            brokenFeature1.setGeometry(updGeom)
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, layer, brokenFeature1, False, False) == False:
               self.plugIn.destroyEditCommand()
               return
            if line2 is not None:
               brokenFeature2 = QgsFeature(f)      
               brokenFeature2.setGeometry(line2)
               # plugIn, layer, feature, coordTransform, refresh, check_validity
               if qad_layer.addFeatureToLayer(self.plugIn, layer, brokenFeature2, 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 broken", 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, layer.crs(), False) == False:
               self.plugIn.destroyEditCommand()
               return
            
            updGeom = qad_utils.delSubGeom(f.geometry(), 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:
               brokenFeature1 = QgsFeature(f)
               brokenFeature1.setGeometry(updGeom)
               # plugIn, layer, feature, refresh, check_validity
               if qad_layer.updateFeatureToLayer(self.plugIn, layer, brokenFeature1, False, False) == False:
                  self.plugIn.destroyEditCommand()
                  return

      self.plugIn.endEditCommand()
示例#33
0
   def unionIntersSubtractEntitySetToPolygon(self, entitySet, opType, removeOriginals = False):
      """
      Unisce o interseca i poligoni di entitySet al poligono corrente
      """
      geom = self.poligonEntity.getGeometry()
      layerList = []
      layerList.append(self.poligonEntity.layer)
      
      geomList = []
      geomList.append(geom)
      for layerEntitySet in entitySet.layerEntitySetList:
         del geomList[:]
         layer = layerEntitySet.layer
         coordTransform = QgsCoordinateTransform(layer.crs(), self.poligonEntity.layer.crs())
         
         if layer.geometryType() == QGis.Polygon:
            for featureId in layerEntitySet.featureIds:
               # se la feature è quella di polygonEntity è errore 
               if layer.id() == self.poligonEntity.layerId() and featureId == self.poligonEntity.featureId:
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               f = layerEntitySet.getFeature(featureId)
               # trasformo la geometria nel crs del layer del poligono da modificare
               geomToAdd = f.geometry()

               geomToAdd.transform(coordTransform)

               if opType == QadMAPMPEDITCommandOpTypeEnum.UNION: geom = geom.combine(geomToAdd)
               elif opType == QadMAPMPEDITCommandOpTypeEnum.INTERSECTION: geom = geom.intersection(geomToAdd)
               elif opType == QadMAPMPEDITCommandOpTypeEnum.DIFFERENCE: geom = geom.difference(geomToAdd)
               
               if geom is None:
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               
               if removeOriginals and layer.id() != self.poligonEntity.layerId():
                  layerList.append(layer)

         elif layer.geometryType() == QGis.Line:
            for featureId in layerEntitySet.featureIds:
               f = layerEntitySet.getFeature(featureId)
               # trasformo la geometria nel crs del layer del poligono da modificare
               geomToAdd = f.geometry()
               geomToAdd.transform(coordTransform)
               # Riduco la geometria in point o polyline
               simplifiedGeoms = qad_utils.asPointOrPolyline(geomToAdd)
               for simplifiedGeom in simplifiedGeoms:
                  if simplifiedGeom.wkbType() != QGis.WKBLineString:
                     self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                     return False
                  points = simplifiedGeom.asPolyline() # vettore di punti
                  
                  if len(points) < 4 or points[0] != points[-1]: # polilinea chiusa con almeno 4 punti (primo e ultimo uguali)
                     self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                     return False
                  geomToAdd = QgsGeometry.fromPolygon([points])
                  
                  if opType == QadMAPMPEDITCommandOpTypeEnum.UNION: geom = geom.combine(geomToAdd)
                  elif opType == QadMAPMPEDITCommandOpTypeEnum.INTERSECTION: geom = geom.intersection(geomToAdd)
                  elif opType == QadMAPMPEDITCommandOpTypeEnum.DIFFERENCE: geom = geom.difference(geomToAdd)
                  
                  if geom is None or geom.type() != QGis.Polygon:
                     self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                     return False
                  
               if removeOriginals: layerList.append(layer)
         else:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

      f = self.poligonEntity.getFeature()
      f.setGeometry(geom)

      self.plugIn.beginEditCommand("Feature edited", layerList)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      if removeOriginals:
         for layerEntitySet in entitySet.layerEntitySetList:            
            if qad_layer.deleteFeaturesToLayer(self.plugIn, layerEntitySet.layer, layerEntitySet.featureIds, False) == False:
               self.plugIn.destroyEditCommand()
               return 

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1

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

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

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

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

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
示例#35
0
   def fillet(self):
      transformedRadius = qad_utils.distMapToLayerCoordinates(self.radius, self.plugIn.canvas, self.entity1.layer)
      tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \
                                                                  self.plugIn.canvas,\
                                                                  self.entity1.layer)                              
      
      if self.entity1.layer.crs() != self.entity2.layer.crs():
         coordTransform = QgsCoordinateTransform(self.entity1.layer.crs(),\
                                                 self.entity2.layer.crs()) # trasformo la geometria
         transformedLinearObjectList2 = self.linearObjectList2.transform(coordTransform)
         transformedPointAt2 = coordTransform.transform(self.pointAt2)         
      else:
         # stessa entità e stessa parte
         if self.entity1.layer.id() == self.entity2.layer.id() and \
            self.entity1.featureId == self.entity2.featureId and \
            self.partAt1 == self.partAt2:
            return False
         
         transformedLinearObjectList2 = qad_utils.QadLinearObjectList(self.linearObjectList2)
         transformedPointAt2 = self.pointAt2
   
      epsg = self.entity1.layer.crs().authid()      
      res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \
                                                transformedLinearObjectList2, self.partAt2, transformedPointAt2,\
                                                self.filletMode, transformedRadius, epsg)      
      if res is None: # raccordo non possibile
         msg = QadMsg.translate("Command_FILLET", "\nFillet with radius <{0}> impossible.")
         #showMsg
         self.showMsg(msg.format(str(self.radius)))
         return False
      
      filletLinearObjectList = res[0]
      whatToDoPoly1 = res[1]
      whatToDoPoly2 = res[2]

      self.plugIn.beginEditCommand("Feature edited", [self.entity1.layer, self.entity2.layer])

      if whatToDoPoly1 == 1: # 1=modificare       
         f = self.entity1.getFeature()
         geom = f.geometry() 
         updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
         updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1)
         if updGeom is None:
            self.plugIn.destroyEditCommand()
            return False
         f.setGeometry(updGeom)
         
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, self.entity1.layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      elif whatToDoPoly1 == 2: # 2=cancellare 
         # plugIn, layer, featureId, refresh
         if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity1.layer, \
                                           self.entity1.featureId, False) == False:
            self.plugIn.destroyEditCommand()
            return False

      if whatToDoPoly2 == 1: # 1=modificare
         
         if self.entity1.layer.crs() != self.entity2.layer.crs():
            coordTransform = QgsCoordinateTransform(self.entity2.layer.crs(),\
                                                    self.entity1.layer.crs()) # trasformo la geometria
            transformedLinearObjectList2 = self.filletLinearObjectList.transform(coordTransform)
         else:
            transformedLinearObjectList2 = filletLinearObjectList
         
         tolerance2ApproxCurve = qad_utils.distMapToLayerCoordinates(QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")), \
                                                                     self.plugIn.canvas,\
                                                                     self.entity2.layer)                              

         f = self.entity2.getFeature()
         geom = f.geometry() 
         updSubGeom = QgsGeometry.fromPolyline(transformedLinearObjectList2.asPolyline(tolerance2ApproxCurve))
         updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2)
         if updGeom is None:
            self.plugIn.destroyEditCommand()
            return False
         f.setGeometry(updGeom)
         
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, self.entity2.layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      elif whatToDoPoly2 == 2: # 2=cancellare 
         # plugIn, layer, featureId, refresh
         if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity2.layer, \
                                           self.entity2.featureId, False) == False:
            self.plugIn.destroyEditCommand()
            return False

      if whatToDoPoly1 == 0 and whatToDoPoly2 == 0: # 0=niente      
         geom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
         # plugIn, layer, geom, coordTransform, refresh, check_validity
         if qad_layer.addGeomToLayer(self.plugIn, self.entity1.layer, geom, None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1

      return True
示例#36
0
    def disjoinCurrentSubGeomToPolygon(self):
        """
      Sconnette la sotto-geometria corrente del poligono da modificare creando una nuova entità
      """
        layer = self.entity.layer
        # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>])
        part = self.currAtSubGeom[0]
        ring = self.currAtSubGeom[1] if len(self.currAtSubGeom) == 2 else None

        geom = self.entity.getGeometry()
        wkbType = geom.wkbType()
        if wkbType == QGis.WKBMultiPoint or wkbType == QGis.WKBMultiLineString:
            if geom.deletePart(part) == False:  # disgrego una parte
                self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                return False
            newGeom = self.mapToLayerCoordinates(layer, self.currSubGeom)
        elif wkbType == QGis.WKBPolygon or wkbType == QGis.WKBMultiPolygon:
            if ring is not None:  # disgrego un'isola
                if geom.deleteRing(
                        ring + 1, part
                ) == False:  # cancello una isola (Ring 0 is outer ring and can't be deleted)
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False
                newGeom = QgsGeometry.fromPolygon([
                    self.mapToLayerCoordinates(layer,
                                               self.currSubGeom).asPolyline()
                ])
            else:  # disgrego una parte
                if wkbType == QGis.WKBPolygon:
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False

                newGeom = QgsGeometry.fromPolygon([
                    self.mapToLayerCoordinates(layer,
                                               self.currSubGeom).asPolyline()
                ])
                ring = 0
                ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])
                # se la parte ha delle isole
                while ringGeom is not None:
                    # aggiungo un'isola
                    points = ringGeom.asPolyline()  # vettore di punti
                    if newGeom.addRing(points) != 0:  # 0 in case of success
                        self.showMsg(QadMsg.translate("QAD",
                                                      "Invalid object."))
                        return False
                    ring = ring + 1
                    ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])

                if geom.deletePart(part) == False:  # cancello una parte
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False
        else:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

        f = self.entity.getFeature()
        f.setGeometry(geom)

        self.plugIn.beginEditCommand("Feature edited", self.entity.layer)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn, self.entity.layer, f,
                                          False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        # Aggiungo nuova feature
        newF = QgsFeature(f)
        newF.setGeometry(newGeom)
        if qad_layer.addFeatureToLayer(self.plugIn, self.entity.layer, newF,
                                       None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        self.plugIn.endEditCommand()

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

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

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

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

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

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

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

      if res == False: # allungamento impossibile
         return False
               
      pts = newLinearObjectList.asPolyline() 
      updSubGeom = QgsGeometry.fromPolyline(pts)
               
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom)
      if updGeom is None:
         return False
      # trasformo la geometria nel crs del layer
      f.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      if self.copyEntities == False:
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      else:
         # plugIn, layer, features, coordTransform, refresh, check_validity
         if qad_layer.addFeatureToLayer(self.plugIn, layer, f, None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      
      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
示例#39
0
   def disjoinCurrentSubGeomToPolygon(self):
      """
      Sconnette la sotto-geometria corrente del poligono da modificare creando una nuova entità
      """
      layer = self.entity.layer
      # la posizione é espressa con una lista (<index ogg. princ> [<index ogg. sec.>])
      part = self.currAtSubGeom[0]
      ring = self.currAtSubGeom[1] if len(self.currAtSubGeom) == 2 else None
      
      geom = self.entity.getGeometry()
      wkbType = geom.wkbType()
      if wkbType == QGis.WKBMultiPoint or wkbType == QGis.WKBMultiLineString:
         if geom.deletePart(part) == False: # disgrego una parte
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False
         newGeom = self.mapToLayerCoordinates(layer, self.currSubGeom)
      elif wkbType == QGis.WKBPolygon or wkbType == QGis.WKBMultiPolygon:
         if ring is not None: # disgrego un'isola 
            if geom.deleteRing(ring + 1, part) == False: # cancello una isola (Ring 0 is outer ring and can't be deleted)
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
            newGeom = QgsGeometry.fromPolygon([self.mapToLayerCoordinates(layer, self.currSubGeom).asPolyline()])
         else: # disgrego una parte
            if wkbType == QGis.WKBPolygon:
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
            
            newGeom = QgsGeometry.fromPolygon([self.mapToLayerCoordinates(layer, self.currSubGeom).asPolyline()])
            ring = 0
            ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])
            # se la parte ha delle isole
            while ringGeom is not None:
               # aggiungo un'isola
               points = ringGeom.asPolyline() # vettore di punti
               if newGeom.addRing(points) != 0: # 0 in case of success
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               ring = ring + 1
               ringGeom = qad_utils.getSubGeomAt(geom, [part, ring])

            if geom.deletePart(part) == False: # cancello una parte
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
      else:
         self.showMsg(QadMsg.translate("QAD", "Invalid object."))
         return False

      f = self.entity.getFeature()
      f.setGeometry(geom)

      self.plugIn.beginEditCommand("Feature edited", self.entity.layer)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.entity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      # Aggiungo nuova feature
      newF = QgsFeature(f)
      newF.setGeometry(newGeom)
      if qad_layer.addFeatureToLayer(self.plugIn, self.entity.layer, newF, None, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False
         
      self.plugIn.endEditCommand()

      return True
示例#40
0
   def addEntitySetToPolygon(self, entitySet, removeOriginals = False):
      """
      Aggiunge il set di entità al poligono da modificare
      """
      geom = self.poligonEntity.getGeometry()
      layerList = []
      layerList.append(self.poligonEntity.layer)
      
      for layerEntitySet in entitySet.layerEntitySetList:
         layer = layerEntitySet.layer
         if layer.geometryType() != QGis.Polygon and layer.geometryType() != QGis.Line:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

         if removeOriginals: layerList.append(layer)
         coordTransform = QgsCoordinateTransform(layer.crs(), self.poligonEntity.layer.crs())

         for featureId in layerEntitySet.featureIds:
            # se la feature è quella di polygonEntity è errore 
            if layer.id() == self.poligonEntity.layerId() and featureId == self.poligonEntity.featureId:
               self.showMsg(QadMsg.translate("QAD", "Invalid object."))
               return False
            
            f = layerEntitySet.getFeature(featureId)
            # trasformo la geometria nel crs del layer del poligono da modificare
            geomToAdd = f.geometry()
            geomToAdd.transform(coordTransform)
            
            # se il poligono è contenuto nella geometria da aggiungere
            if geomToAdd.contains(geom):
               # Riduco la geometria in point o polyline
               simplifiedGeoms = qad_utils.asPointOrPolyline(geom)
               # deve essere un poligono senza ring
               if len(simplifiedGeoms) != 1 or simplifiedGeoms[0].wkbType() != QGis.WKBLineString:
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               points = simplifiedGeoms[0].asPolyline() # vettore di punti
               # aggiungo un'isola
               if geomToAdd.addRing(points) != 0: # 0 in case of success
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               del geom
               geom = QgsGeometry.fromPolygon(geomToAdd.asPolygon())
            else: # se il poligono non è contenuto nella geometria da aggiungere
               # Riduco la geometria in point o polyline
               simplifiedGeoms = qad_utils.asPointOrPolyline(geomToAdd)
               for simplifiedGeom in simplifiedGeoms:
                  points = simplifiedGeom.asPolyline() # vettore di punti                     
                  # se la geometria da aggiungere è contenuta nel poligono
                  if geom.contains(QgsGeometry.fromPolyline(points)):
                     # aggiungo un'isola
                     if geom.addRing(points) != 0: # 0 in case of success
                        self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                        return False
                  else:
                     # aggiungo una parte
                     if geom.addPart(points) != 0: # 0 in case of success
                        self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                        return False

      f = self.poligonEntity.getFeature()
      f.setGeometry(geom)

      layerList = entitySet.getLayerList()
      layerList.append(self.poligonEntity.layer)

      self.plugIn.beginEditCommand("Feature edited", layerList)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      if removeOriginals:
         for layerEntitySet in entitySet.layerEntitySetList:            
            if qad_layer.deleteFeaturesToLayer(self.plugIn, layerEntitySet.layer, layerEntitySet.featureIds, False) == False:
               self.plugIn.destroyEditCommand()
               return 

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1

      return True
    def fillet(self):
        tolerance2ApproxCurve = QadVariables.get(
            QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))

        # stessa entità e stessa parte
        if self.entity1.layer.id() == self.entity2.layer.id() and \
           self.entity1.featureId == self.entity2.featureId and \
           self.partAt1 == self.partAt2:
            return False

        # uso il crs del canvas per lavorare con coordinate piane xy
        epsg = self.plugIn.canvas.mapSettings().destinationCrs().authid()
        res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \
                                                  self.linearObjectList2, self.partAt2, self.pointAt2,\
                                                  self.filletMode, self.radius, epsg)
        if res is None:  # raccordo non possibile
            msg = QadMsg.translate("Command_FILLET",
                                   "\nFillet with radius <{0}> impossible.")
            #showMsg
            self.showMsg(msg.format(str(self.radius)))
            return False

        filletLinearObjectList = res[0]
        whatToDoPoly1 = res[1]
        whatToDoPoly2 = res[2]

        self.plugIn.beginEditCommand("Feature edited",
                                     [self.entity1.layer, self.entity2.layer])

        if whatToDoPoly1 == 1:  # 1=modificare
            f = self.entity1.getFeature()
            # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
            geom = self.layerToMapCoordinates(self.entity1.layer, f.geometry())
            updSubGeom = QgsGeometry.fromPolyline(
                filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
            updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1)
            if updGeom is None:
                self.plugIn.destroyEditCommand()
                return False
            # trasformo la geometria nel crs del layer
            f.setGeometry(
                self.mapToLayerCoordinates(self.entity1.layer, updGeom))

            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, self.entity1.layer,
                                              f, False, False) == False:
                self.plugIn.destroyEditCommand()
                return False
        elif whatToDoPoly1 == 2:  # 2=cancellare
            # se non si tratta della stessa entità
            if self.entity1 != self.entity2:
                # plugIn, layer, featureId, refresh
                if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity1.layer, \
                                                  self.entity1.featureId, False) == False:
                    self.plugIn.destroyEditCommand()
                    return False

        if whatToDoPoly2 == 1:  # 1=modificare
            tolerance2ApproxCurve = QadVariables.get(
                QadMsg.translate("Environment variables",
                                 "TOLERANCE2APPROXCURVE"))

            f = self.entity2.getFeature()
            # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
            geom = self.layerToMapCoordinates(self.entity2.layer, f.geometry())
            updSubGeom = QgsGeometry.fromPolyline(
                filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
            updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2)
            if updGeom is None:
                self.plugIn.destroyEditCommand()
                return False
            # trasformo la geometria nel crs del layer
            f.setGeometry(
                self.mapToLayerCoordinates(self.entity2.layer, updGeom))

            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, self.entity2.layer,
                                              f, False, False) == False:
                self.plugIn.destroyEditCommand()
                return False
        elif whatToDoPoly2 == 2:  # 2=cancellare
            # se non si tratta della stessa entità
            if self.entity1 != self.entity2:
                # plugIn, layer, featureId, refresh
                if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity2.layer, \
                                                  self.entity2.featureId, False) == False:
                    self.plugIn.destroyEditCommand()
                    return False

        if whatToDoPoly1 == 0 and whatToDoPoly2 == 0:  # 0=niente
            geom = QgsGeometry.fromPolyline(
                filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
            # trasformo la geometria nel crs del layer
            geom = self.mapToLayerCoordinates(self.entity1.layer, geom)

            # plugIn, layer, geom, coordTransform, refresh, check_validity
            if qad_layer.addGeomToLayer(self.plugIn, self.entity1.layer, geom,
                                        None, False, False) == False:
                self.plugIn.destroyEditCommand()
                return False

        self.plugIn.endEditCommand()
        self.nOperationsToUndo = self.nOperationsToUndo + 1

        return True
示例#42
0
    def addEntitySetToPoint(self, entitySet, removeOriginals=True):
        """
      Aggiunge il set di entità al punto da modificare
      """
        geom = self.entity.getGeometry()
        layerList = []
        layerList.append(self.entity.layer)

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer
            if layer.geometryType() != QGis.Point:
                self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                return False

            if removeOriginals: layerList.append(layer)
            coordTransform = QgsCoordinateTransform(layer.crs(),
                                                    self.entity.layer.crs())

            for featureId in layerEntitySet.featureIds:
                # se la feature è quella di entity è errore
                if layer.id() == self.entity.layerId(
                ) and featureId == self.entity.featureId:
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False

                f = layerEntitySet.getFeature(featureId)
                # trasformo la geometria nel crs del layer dell'entità da modificare
                geomToAdd = f.geometry()
                geomToAdd.transform(coordTransform)

                simplifiedGeoms = qad_utils.asPointOrPolyline(geomToAdd)
                for simplifiedGeom in simplifiedGeoms:
                    point = simplifiedGeom.asPoint()
                    # aggiungo una parte
                    if geom.addPart([point]) != 0:  # 0 in case of success
                        self.showMsg(QadMsg.translate("QAD",
                                                      "Invalid object."))
                        return False

        f = self.entity.getFeature()
        f.setGeometry(geom)

        layerList = entitySet.getLayerList()
        layerList.append(self.entity.layer)

        self.plugIn.beginEditCommand("Feature edited", layerList)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn, self.entity.layer, f,
                                          False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        if removeOriginals:
            for layerEntitySet in entitySet.layerEntitySetList:
                if qad_layer.deleteFeaturesToLayer(self.plugIn,
                                                   layerEntitySet.layer,
                                                   layerEntitySet.featureIds,
                                                   False) == False:
                    self.plugIn.destroyEditCommand()
                    return

        self.plugIn.endEditCommand()

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

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

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

      if res == False: # allungamento impossibile
         return False
               
      pts = newLinearObjectList.asPolyline() 
      updSubGeom = QgsGeometry.fromPolyline(pts)
               
      updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom)
      if updGeom is None:
         return False
      # trasformo la geometria nel crs del layer
      f.setGeometry(self.mapToLayerCoordinates(layer, updGeom))
         
      self.plugIn.beginEditCommand("Feature edited", layer)
      
      if self.copyEntities == False:
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      else:
         # plugIn, layer, features, coordTransform, refresh, check_validity
         if qad_layer.addFeatureToLayer(self.plugIn, layer, f, None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      
      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1
      
      return True
示例#44
0
    def addEntitySetToPolygon(self, entitySet, removeOriginals=True):
        """
      Aggiunge il set di entità al poligono da modificare
      """
        geom = self.entity.getGeometry()
        layerList = []
        layerList.append(self.entity.layer)

        for layerEntitySet in entitySet.layerEntitySetList:
            layer = layerEntitySet.layer
            if layer.geometryType() != QGis.Polygon and layer.geometryType(
            ) != QGis.Line:
                self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                return False

            if removeOriginals: layerList.append(layer)
            coordTransform = QgsCoordinateTransform(layer.crs(),
                                                    self.entity.layer.crs())

            for featureId in layerEntitySet.featureIds:
                # se la feature è quella di entity è errore
                if layer.id() == self.entity.layerId(
                ) and featureId == self.entity.featureId:
                    self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                    return False

                f = layerEntitySet.getFeature(featureId)
                # trasformo la geometria nel crs del layer del poligono da modificare
                geomToAdd = f.geometry()
                geomToAdd.transform(coordTransform)

                # se il poligono è contenuto nella geometria da aggiungere
                if geomToAdd.contains(geom):
                    # Riduco la geometria in point o polyline
                    simplifiedGeoms = qad_utils.asPointOrPolyline(geom)
                    # deve essere un poligono senza ring
                    if len(simplifiedGeoms) != 1 or simplifiedGeoms[0].wkbType(
                    ) != QGis.WKBLineString:
                        self.showMsg(QadMsg.translate("QAD",
                                                      "Invalid object."))
                        return False
                    points = simplifiedGeoms[0].asPolyline(
                    )  # vettore di punti
                    # aggiungo un'isola
                    if geomToAdd.addRing(points) != 0:  # 0 in case of success
                        self.showMsg(QadMsg.translate("QAD",
                                                      "Invalid object."))
                        return False
                    del geom
                    geom = QgsGeometry.fromPolygon(geomToAdd.asPolygon())
                else:  # se il poligono non è contenuto nella geometria da aggiungere
                    # Riduco la geometria in point o polyline
                    simplifiedGeoms = qad_utils.asPointOrPolyline(geomToAdd)
                    for simplifiedGeom in simplifiedGeoms:
                        points = simplifiedGeom.asPolyline(
                        )  # vettore di punti
                        # se la geometria da aggiungere è contenuta nel poligono
                        if geom.contains(QgsGeometry.fromPolyline(points)):
                            # aggiungo un'isola
                            if geom.addRing(
                                    points) != 0:  # 0 in case of success
                                self.showMsg(
                                    QadMsg.translate("QAD", "Invalid object."))
                                return False
                        else:
                            # aggiungo una parte
                            if geom.addPart(
                                    points) != 0:  # 0 in case of success
                                self.showMsg(
                                    QadMsg.translate("QAD", "Invalid object."))
                                return False

        f = self.entity.getFeature()
        f.setGeometry(geom)

        layerList = entitySet.getLayerList()
        layerList.append(self.entity.layer)

        self.plugIn.beginEditCommand("Feature edited", layerList)

        # plugIn, layer, feature, refresh, check_validity
        if qad_layer.updateFeatureToLayer(self.plugIn, self.entity.layer, f,
                                          False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

        if removeOriginals:
            for layerEntitySet in entitySet.layerEntitySetList:
                if qad_layer.deleteFeaturesToLayer(self.plugIn,
                                                   layerEntitySet.layer,
                                                   layerEntitySet.featureIds,
                                                   False) == False:
                    self.plugIn.destroyEditCommand()
                    return

        self.plugIn.endEditCommand()

        return True
示例#45
0
   def unionIntersSubtractEntitySetToPolygon(self, entitySet, opType, removeOriginals = False):
      """
      Unisce o interseca i poligoni di entitySet al poligono corrente
      """
      geom = self.poligonEntity.getGeometry()
      layerList = []
      layerList.append(self.poligonEntity.layer)
      
      geomList = []
      geomList.append(geom)
      for layerEntitySet in entitySet.layerEntitySetList:
         del geomList[:]
         layer = layerEntitySet.layer
         coordTransform = QgsCoordinateTransform(layer.crs(), self.poligonEntity.layer.crs())
         
         if layer.geometryType() == QGis.Polygon:
            for featureId in layerEntitySet.featureIds:
               # se la feature è quella di polygonEntity è errore 
               if layer.id() == self.poligonEntity.layerId() and featureId == self.poligonEntity.featureId:
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               f = layerEntitySet.getFeature(featureId)
               # trasformo la geometria nel crs del layer del poligono da modificare
               geomToAdd = f.geometry()

               geomToAdd.transform(coordTransform)

               if opType == QadMAPMPEDITCommandOpTypeEnum.UNION: geom = geom.combine(geomToAdd)
               elif opType == QadMAPMPEDITCommandOpTypeEnum.INTERSECTION: geom = geom.intersection(geomToAdd)
               elif opType == QadMAPMPEDITCommandOpTypeEnum.DIFFERENCE: geom = geom.difference(geomToAdd)
               
               if geom is None:
                  self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                  return False
               
               if removeOriginals and layer.id() != self.poligonEntity.layerId():
                  layerList.append(layer)

         elif layer.geometryType() == QGis.Line:
            for featureId in layerEntitySet.featureIds:
               f = layerEntitySet.getFeature(featureId)
               # trasformo la geometria nel crs del layer del poligono da modificare
               geomToAdd = f.geometry()
               geomToAdd.transform(coordTransform)
               # Riduco la geometria in point o polyline
               simplifiedGeoms = qad_utils.asPointOrPolyline(geomToAdd)
               for simplifiedGeom in simplifiedGeoms:
                  if simplifiedGeom.wkbType() != QGis.WKBLineString:
                     self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                     return False
                  points = simplifiedGeom.asPolyline() # vettore di punti
                  
                  if len(points) < 4 or points[0] != points[-1]: # polilinea chiusa con almeno 4 punti (primo e ultimo uguali)
                     self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                     return False
                  geomToAdd = QgsGeometry.fromPolygon([points])
                  
                  if opType == QadMAPMPEDITCommandOpTypeEnum.UNION: geom = geom.combine(geomToAdd)
                  elif opType == QadMAPMPEDITCommandOpTypeEnum.INTERSECTION: geom = geom.intersection(geomToAdd)
                  elif opType == QadMAPMPEDITCommandOpTypeEnum.DIFFERENCE: geom = geom.difference(geomToAdd)
                  
                  if geom is None or geom.type() != QGis.Polygon:
                     self.showMsg(QadMsg.translate("QAD", "Invalid object."))
                     return False
                  
               if removeOriginals: layerList.append(layer)
         else:
            self.showMsg(QadMsg.translate("QAD", "Invalid object."))
            return False

      f = self.poligonEntity.getFeature()
      f.setGeometry(geom)

      self.plugIn.beginEditCommand("Feature edited", layerList)
         
      # plugIn, layer, feature, refresh, check_validity
      if qad_layer.updateFeatureToLayer(self.plugIn, self.poligonEntity.layer, f, False, False) == False:
         self.plugIn.destroyEditCommand()
         return False

      if removeOriginals:
         for layerEntitySet in entitySet.layerEntitySetList:            
            if qad_layer.deleteFeaturesToLayer(self.plugIn, layerEntitySet.layer, layerEntitySet.featureIds, False) == False:
               self.plugIn.destroyEditCommand()
               return 

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1

      return True
示例#46
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
示例#47
0
   def fillet(self):
      tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE")) 
      
      # stessa entità e stessa parte
      if self.entity1.layer.id() == self.entity2.layer.id() and \
         self.entity1.featureId == self.entity2.featureId and \
         self.partAt1 == self.partAt2:
         return False
   
      # uso il crs del canvas per lavorare con coordinate piane xy
      epsg = self.plugIn.canvas.mapRenderer().destinationCrs().authid()
      res = qad_utils.getFilletLinearObjectList(self.linearObjectList1, self.partAt1, self.pointAt1, \
                                                self.linearObjectList2, self.partAt2, self.pointAt2,\
                                                self.filletMode, self.radius, epsg)
      if res is None: # raccordo non possibile
         msg = QadMsg.translate("Command_FILLET", "\nFillet with radius <{0}> impossible.")
         #showMsg
         self.showMsg(msg.format(str(self.radius)))
         return False
      
      filletLinearObjectList = res[0]
      whatToDoPoly1 = res[1]
      whatToDoPoly2 = res[2]

      self.plugIn.beginEditCommand("Feature edited", [self.entity1.layer, self.entity2.layer])

      if whatToDoPoly1 == 1: # 1=modificare       
         f = self.entity1.getFeature()
         # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
         geom = self.layerToMapCoordinates(self.entity1.layer, f.geometry())
         updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
         updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom1)
         if updGeom is None:
            self.plugIn.destroyEditCommand()
            return False
         # trasformo la geometria nel crs del layer
         f.setGeometry(self.mapToLayerCoordinates(self.entity1.layer, updGeom))
         
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, self.entity1.layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      elif whatToDoPoly1 == 2: # 2=cancellare
         # se non si tratta della stessa entità
         if self.entity1 != self.entity2:
            # plugIn, layer, featureId, refresh
            if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity1.layer, \
                                              self.entity1.featureId, False) == False:
               self.plugIn.destroyEditCommand()
               return False

      if whatToDoPoly2 == 1: # 1=modificare
         tolerance2ApproxCurve = QadVariables.get(QadMsg.translate("Environment variables", "TOLERANCE2APPROXCURVE"))

         f = self.entity2.getFeature()
         # trasformo la geometria nel crs del canvas per lavorare con coordinate piane xy
         geom = self.layerToMapCoordinates(self.entity2.layer, f.geometry())
         updSubGeom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
         updGeom = qad_utils.setSubGeom(geom, updSubGeom, self.atSubGeom2)
         if updGeom is None:
            self.plugIn.destroyEditCommand()
            return False
         # trasformo la geometria nel crs del layer
         f.setGeometry(self.mapToLayerCoordinates(self.entity2.layer, updGeom))
         
         # plugIn, layer, feature, refresh, check_validity
         if qad_layer.updateFeatureToLayer(self.plugIn, self.entity2.layer, f, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False
      elif whatToDoPoly2 == 2: # 2=cancellare 
         # se non si tratta della stessa entità
         if self.entity1 != self.entity2:
            # plugIn, layer, featureId, refresh
            if qad_layer.deleteFeatureToLayer(self.plugIn, self.entity2.layer, \
                                              self.entity2.featureId, False) == False:
               self.plugIn.destroyEditCommand()
               return False

      if whatToDoPoly1 == 0 and whatToDoPoly2 == 0: # 0=niente      
         geom = QgsGeometry.fromPolyline(filletLinearObjectList.asPolyline(tolerance2ApproxCurve))
         # trasformo la geometria nel crs del layer
         geom = self.mapToLayerCoordinates(self.entity1.layer, geom)

         # plugIn, layer, geom, coordTransform, refresh, check_validity
         if qad_layer.addGeomToLayer(self.plugIn, self.entity1.layer, geom, None, False, False) == False:
            self.plugIn.destroyEditCommand()
            return False

      self.plugIn.endEditCommand()
      self.nOperationsToUndo = self.nOperationsToUndo + 1

      return True