Пример #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
Пример #2
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
Пример #3
0
   def rotate(self, basePt, angle):
      # basePt = punto base espresso in map coordinate
      # restituisce una feature ruotata
      canvas = qgis.utils.iface.mapCanvas()
      destinationCrs = canvas.mapSettings().destinationCrs()

      f = self.getFeature()
      g = g.geometry()
      g.transform(QgsCoordinateTransform(self.crs(), destinationCrs))
      # ruoto la feature
      g = qad_utils.rotateQgsGeometry(g, basePt, angle)
      g.transform(QgsCoordinateTransform(destinationCrs, self.crs()))
      f.setGeometry(g)
      
      rotFldName = ""
      if self.getEntityType() == QadEntityGeomTypeEnum.TEXT:
         # se la rotazione dipende da un solo campo
         rotFldNames = qad_label.get_labelRotationFieldNames(self.layer)
         if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0:
            rotFldName = rotFldNames[0]         
      elif self.getEntityType() == QadEntityGeomTypeEnum.SYMBOL:
         rotFldName = qad_layer.get_symbolRotationFieldName(self.layer)
      
      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)))               

      return f
Пример #4
0
   def rotate(self, basePt, angle):
      # basePt = punto base espresso in map coordinate
      # restituisce una feature ruotata
      canvas = qad.mainWindow().mapCanvas()
      destinationCrs = canvas.mapSettings().destinationCrs()

      f = self.getFeature()
      g = g.geometry()
      g.transform(QgsCoordinateTransform(self.crs(), destinationCrs))
      # ruoto la feature
      g = qad_utils.rotateQgsGeometry(g, basePt, angle)
      g.transform(QgsCoordinateTransform(destinationCrs, self.crs()))
      f.setGeometry(g)
      
      rotFldName = ""
      if self.getEntityType() == QadEntityGeomTypeEnum.TEXT:
         # se la rotazione dipende da un solo campo
         rotFldNames = qad_label.get_labelRotationFieldNames(self.layer)
         if len(rotFldNames) == 1 and len(rotFldNames[0]) > 0:
            rotFldName = rotFldNames[0]         
      elif self.getEntityType() == QadEntityGeomTypeEnum.SYMBOL:
         rotFldName = qad_layer.get_symbolRotationFieldName(self.layer)
      
      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)))               

      return f
    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
Пример #6
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)
Пример #7
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
Пример #9
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
Пример #10
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)
Пример #11
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
Пример #12
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
Пример #13
0
 def getTanDirectionOnPt(self, pt):
     angle = qad_utils.getAngleBy2Pts(self.center, pt)
     return qad_utils.normalizeAngle(angle + math.pi / 2)
Пример #14
0
 def getTanDirectionOnPt(self, pt):
     angle = qad_utils.getAngleBy2Pts(self.center, pt)
     return qad_utils.normalizeAngle(angle + math.pi / 2)