Ejemplo n.º 1
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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def doMoveAndRotateGeom(plugIn, f, g, layer, offSetX, offSetY, angle, rotFldName, basePt, coordTransform, addToLayer, highlightObj):
   # funzione di ausilio
   newGeom = qad_utils.moveQgsGeometry(g, offSetX, offSetY)
   if angle is not None:
      newGeom = qad_utils.rotateQgsGeometry(newGeom, basePt, angle)

   newGeom.transform(coordTransform)

   if addToLayer:
      newF = QgsFeature(f) # la copio perchè altrimenti qgis si incarta
      newF.setGeometry(newGeom)
      
      if len(rotFldName) > 0:
         rotValue = newF.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
         newF.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))               
      
      # plugIn, layer, feature, coordTransform, refresh, check_validity
      if qad_layer.addFeatureToLayer(plugIn, layer, newF, None, False, False) == False:
         return False

   if highlightObj is not None:
      highlightObj.addGeometry(newGeom, layer)
   
   del newGeom
   
   return True
Ejemplo n.º 4
0
 def addFeature(self, layer):
    transformedPoint = self.mapToLayerCoordinates(layer, self.insPt)
    g = QgsGeometry.fromPoint(transformedPoint)
    f = QgsFeature()
    f.setGeometry(g)
    # Add attribute fields to feature.
    fields = layer.pendingFields()
    f.setFields(fields)
    
    # assegno i valori di default
    provider = layer.dataProvider()
    for field in fields.toList():
       i = fields.indexFromName(field.name())
       f[field.name()] = provider.defaultValue(i)
    
    # se la scala dipende da un campo 
    scaleFldName = qad_layer.get_symbolScaleFieldName(layer)
    if len(scaleFldName) > 0:
       f.setAttribute(scaleFldName, self.scale)
    
    # se la rotazione dipende da un campo
    rotFldName = qad_layer.get_symbolRotationFieldName(layer)
    if len(rotFldName) > 0:
       f.setAttribute(rotFldName, qad_utils.toDegrees(self.rot))
    
    return qad_layer.addFeatureToLayer(self.plugIn, layer, f)               
Ejemplo n.º 5
0
 def addFeature(self, layer):
    transformedPoint = self.mapToLayerCoordinates(layer, self.insPt)
    g = QgsGeometry.fromPoint(transformedPoint)
    f = QgsFeature()
    f.setGeometry(g)
    # Add attribute fields to feature.
    fields = layer.pendingFields()
    f.setFields(fields)
    
    # assegno i valori di default
    provider = layer.dataProvider()
    for field in fields.toList():
       i = fields.indexFromName(field.name())
       f[field.name()] = provider.defaultValue(i)
    
    # se l'altezza testo dipende da un solo campo 
    sizeFldNames = qad_label.get_labelSizeFieldNames(layer)
    if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0:
       f.setAttribute(sizeFldNames[0], self.hText)
    
    # se la rotazione dipende da un solo campo
    rotFldNames = qad_label.get_labelRotationFieldNames(layer)
    if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0:
       f.setAttribute(rotFldNames[0], qad_utils.toDegrees(self.rot))
       
    # setto i valori degli attributi che compongono l'etichetta
    i = 0
    tot = len(self.labelFields)
    while i < tot:
       f.setAttribute(self.labelFields[i].name(), self.labelFieldValues[i])
       i = i + 1
    
    return qad_layer.addFeatureToLayer(self.plugIn, layer, f)       
Ejemplo n.º 6
0
    def addFeature(self, layer, insPt, rot):
        transformedPoint = self.mapToLayerCoordinates(layer, insPt)
        g = QgsGeometry.fromPoint(transformedPoint)
        f = QgsFeature()
        f.setGeometry(g)
        # Add attribute fields to feature.
        fields = layer.pendingFields()
        f.setFields(fields)

        # assegno i valori di default
        provider = layer.dataProvider()
        for field in fields.toList():
            i = fields.indexFromName(field.name())
            f[field.name()] = provider.defaultValue(i)

        # se la scala dipende da un campo
        scaleFldName = qad_layer.get_symbolScaleFieldName(layer)
        if len(scaleFldName) > 0:
            f.setAttribute(scaleFldName, 1.0)

        # se la rotazione dipende da un campo
        rotFldName = qad_layer.get_symbolRotationFieldName(layer)
        if len(rotFldName) > 0:
            f.setAttribute(rotFldName, qad_utils.toDegrees(rot))

        return qad_layer.addFeatureToLayer(self.plugIn, layer, f)
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
    def addFeature(self, layer):
        transformedPoint = self.mapToLayerCoordinates(layer, self.insPt)
        g = QgsGeometry.fromPoint(transformedPoint)
        f = QgsFeature()
        f.setGeometry(g)
        # Add attribute fields to feature.
        fields = layer.pendingFields()
        f.setFields(fields)

        # assegno i valori di default
        provider = layer.dataProvider()
        for field in fields.toList():
            i = fields.indexFromName(field.name())
            f[field.name()] = provider.defaultValue(i)

        # se l'altezza testo dipende da un solo campo
        sizeFldNames = qad_label.get_labelSizeFieldNames(layer)
        if len(sizeFldNames) == 1 and len(sizeFldNames[0]) > 0:
            f.setAttribute(sizeFldNames[0], self.hText)

        # se la rotazione dipende da un solo campo
        rotFldNames = qad_label.get_labelRotationFieldNames(layer)
        if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0:
            f.setAttribute(rotFldNames[0], qad_utils.toDegrees(self.rot))

        # setto i valori degli attributi che compongono l'etichetta
        i = 0
        tot = len(self.labelFields)
        while i < tot:
            f.setAttribute(self.labelFields[i].name(),
                           self.labelFieldValues[i])
            i = i + 1

        return qad_layer.addFeatureToLayer(self.plugIn, layer, f)
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
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
Ejemplo n.º 11
0
 def move(self, f, offSetX, offSetY, layerEntitySet, entitySet, dimEntity):
    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, coordTransform, refresh, check_validity
       if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:  
          return False
    else:
       # sposto la quota
       dimEntity.move(offSetX, offSetY)                               
       if dimEntity.addToLayers(self.plugIn) == False:
          return False             
          
    return True
Ejemplo n.º 12
0
    def mirror(self, f, pt1, pt2, rotFldName, layerEntitySet, entitySet,
               dimEntity):

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

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

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

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

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

        return True
Ejemplo n.º 17
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)
                # 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
Ejemplo n.º 18
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)
Ejemplo n.º 19
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, coordTransform, refresh, check_validity
       if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:  
          return False
       del layerEntitySet.featureIds[0]
    else:
       # sposto la quota e la rimuovo da entitySet
       dimEntitySet = dimEntity.getEntitySet()
       dimEntity.move(offSetX, offSetY)                               
       if dimEntity.addToLayers(self.plugIn) == False:
          return False             
       entitySet.subtract(dimEntitySet)
          
    return True
Ejemplo n.º 20
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)
                # 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
Ejemplo n.º 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
Ejemplo n.º 22
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
Ejemplo n.º 23
0
   def mirror(self, f, pt1, pt2, rotFldName, layerEntitySet, entitySet, dimEntity):
      
      if dimEntity is None:
         # scalo la feature e la rimuovo da entitySet (é la prima)
         f.setGeometry(qad_utils.mirrorQgsGeometry(f.geometry(), pt1, pt2))
         if len(rotFldName) > 0:
            rotValue = f.attribute(rotFldName)
            # a volte vale None e a volte null (vai a capire...)
            rotValue = 0 if rotValue is None or isinstance(rotValue, QPyNullVariant) else qad_utils.toRadians(rotValue) # la rotazione é in gradi nel campo della feature
            ptDummy = qad_utils.getPolarPointByPtAngle(pt1, rotValue, 1)
            mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
            ptDummy = qad_utils.mirrorPoint(ptDummy, pt1, mirrorAngle)
            rotValue = qad_utils.getAngleBy2Pts(pt1, ptDummy)
            f.setAttribute(rotFldName, qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))               
                  
         if self.copyFeatures == False:
            # plugIn, layer, feature, refresh, check_validity
            if qad_layer.updateFeatureToLayer(self.plugIn, layerEntitySet.layer, f, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False
         else:             
            # plugIn, layer, features, coordTransform, refresh, check_validity
            if qad_layer.addFeatureToLayer(self.plugIn, layerEntitySet.layer, f, None, False, False) == False:
               self.plugIn.destroyEditCommand()
               return False

         del layerEntitySet.featureIds[0]
      else:
         # scalo la quota e la rimuovo da entitySet
         mirrorAngle = qad_utils.getAngleBy2Pts(pt1, pt2)
         dimEntitySet = dimEntity.getEntitySet()
         if self.copyFeatures == False:
            if dimEntity.deleteToLayers(self.plugIn) == False:
               return False
         newDimEntity = QadDimEntity(dimEntity) # la copio
         newDimEntity.mirror(pt1, mirrorAngle)
         if newDimEntity.addToLayers(self.plugIn) == False:
            return False             
         entitySet.subtract(dimEntitySet)
Ejemplo n.º 24
0
   def 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)
Ejemplo n.º 25
0
def doMoveAndRotateGeom(plugIn, f, g, layer, offSetX, offSetY, angle,
                        rotFldName, basePt, coordTransform, addToLayer,
                        highlightObj):
    # funzione di ausilio
    newGeom = qad_utils.moveQgsGeometry(g, offSetX, offSetY)
    if angle is not None:
        newGeom = qad_utils.rotateQgsGeometry(newGeom, basePt, angle)

    newGeom.transform(coordTransform)

    if addToLayer:
        newF = QgsFeature(f)  # la copio perchè altrimenti qgis si incarta
        newF.setGeometry(newGeom)

        if len(rotFldName) > 0:
            rotValue = newF.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
            newF.setAttribute(
                rotFldName,
                qad_utils.toDegrees(qad_utils.normalizeAngle(rotValue)))

        # plugIn, layer, feature, coordTransform, refresh, check_validity
        if qad_layer.addFeatureToLayer(plugIn, layer, newF, None, False,
                                       False) == False:
            return False

    if highlightObj is not None:
        highlightObj.addGeometry(newGeom, layer)

    del newGeom

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

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

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

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