def canvasMoveEvent(self,event):
        if self.featId != None and self.clicked == True:
            ## Try to snap to active or background layer first.
            x = event.pos().x()
            y = event.pos().y()
            startingPoint = QPoint(x,y)            
            snapper = QgsMapCanvasSnapper(self.canvas)
            (retval,result) = snapper.snapToCurrentLayer (startingPoint,QgsSnapper.SnapToVertex)   
            if result <> []:
                newPoint = result[0].snappedVertex
            else:
                (retval,result) = snapper.snapToBackgroundLayers(startingPoint)
                if result <> []:
                    newPoint = result[0].snappedVertex
                else:
                    newPoint = self.toLayerCoordinates( self.layer, event.pos() )

            ## Create the new geometry (circular arc) for the moving rubberband and 
            ## the final feature.
            settings = QSettings("CatAIS","cadtools")
            value = settings.value("arcs/rubberangle",  5)
            if self.movingVertex == "arc":
                g = CircularArc.getInterpolatedArc(self.ptStart,  newPoint,  self.ptEnd,  "angle",   value.toDouble()[0])                
            elif self.movingVertex == "start":
                g = CircularArc.getInterpolatedArc(newPoint,  self.ptArc,  self.ptEnd,  "angle",   value.toDouble()[0])
            elif self.movingVertex == "end":
                g = CircularArc.getInterpolatedArc(self.ptStart,  self.ptArc,  newPoint,  "angle",   value.toDouble()[0])                
                
            self.rb2.setToGeometry( g, self.layer );
            
#            print str(self.ptStart.toString())
#            print str(newPoint.toString())
#            print str(self.ptEnd.toString())
            
        pass
 def canvasReleaseEvent(self,event):
     if self.rb2 <> None:
         ## Reset the rubberband.
         self.rb2.reset()
         self.rb2 = None
         
         ## What happens to newPoint???? Even as self.newPoint it 
         ## does not work....
         ## We just snap again....
         x = event.pos().x()
         y = event.pos().y()
         startingPoint = QPoint(x,y)            
         snapper = QgsMapCanvasSnapper(self.canvas)
         (retval,result) = snapper.snapToCurrentLayer (startingPoint,QgsSnapper.SnapToVertex)   
         if result <> []:
             newPoint = result[0].snappedVertex
         else:
             (retval,result) = snapper.snapToBackgroundLayers(startingPoint)
             if result <> []:
                 newPoint = result[0].snappedVertex
             else:
                 newPoint = self.toLayerCoordinates( self.layer, event.pos() )
     
         ## Modify the feature.
         settings = QSettings("CatAIS","cadtools")
         method = settings.value("arcs/featuremethod",  "pitch")
         if method == "pitch":
             value = settings.value("arcs/featurepitch",  2)
         else:
             value = settings.value("arcs/featureangle",  1)
         if self.movingVertex == "arc":
             g = CircularArc.getInterpolatedArc(self.ptStart,  newPoint,  self.ptEnd,  method,   value.toDouble()[0])                
         elif self.movingVertex == "start":
             g = CircularArc.getInterpolatedArc(newPoint,  self.ptArc,  self.ptEnd,  method, value.toDouble()[0])
         elif self.movingVertex == "end":
             g = CircularArc.getInterpolatedArc(self.ptStart,  self.ptArc,  newPoint,  method, value.toDouble()[0])    
             
         ## On the Fly reprojection of the geometry (only if needed)
         layerEPSG = self.layer.srs().epsg()
         projectEPSG = self.canvas.mapRenderer().destinationSrs().epsg()
         if layerEPSG != projectEPSG:
             layerSRS = self.layer.srs()
             projectSRS = self.canvas.mapRenderer().destinationSrs()
             coordtrans = QgsCoordinateTransform(layerSRS,  projectSRS)
             g.transform(coordtrans)
     
         self.layer.beginEditCommand("Geometry modified.")
         self.layer.changeGeometry(self.featId,  g)
         self.layer.endEditCommand()
         self.layer.setModified(True,  True)
         self.layer.reload()
         self.canvas.refresh()
         
     ## Reset some stuff.
     self.clicked = False
     self.featId = None
     
     pass
    def canvasMoveEvent(self, event):
        if self.featId != None and self.clicked == True:
            ## Try to snap to active or background layer first.
            x = event.pos().x()
            y = event.pos().y()
            startingPoint = QPoint(x, y)
            snapper = QgsMapCanvasSnapper(self.canvas)
            (retval,
             result) = snapper.snapToCurrentLayer(startingPoint,
                                                  QgsSnapper.SnapToVertex)
            if result <> []:
                newPoint = result[0].snappedVertex
            else:
                (retval,
                 result) = snapper.snapToBackgroundLayers(startingPoint)
                if result <> []:
                    newPoint = result[0].snappedVertex
                else:
                    newPoint = self.toLayerCoordinates(self.layer, event.pos())

            ## Create the new geometry (circular arc) for the moving rubberband and
            ## the final feature.
            settings = QSettings("CatAIS", "cadtools")
            value = settings.value("arcs/rubberangle", 5)
            if self.movingVertex == "arc":
                g = CircularArc.getInterpolatedArc(self.ptStart, newPoint,
                                                   self.ptEnd, "angle",
                                                   value.toDouble()[0])
            elif self.movingVertex == "start":
                g = CircularArc.getInterpolatedArc(newPoint, self.ptArc,
                                                   self.ptEnd, "angle",
                                                   value.toDouble()[0])
            elif self.movingVertex == "end":
                g = CircularArc.getInterpolatedArc(self.ptStart, self.ptArc,
                                                   newPoint, "angle",
                                                   value.toDouble()[0])

            self.rb2.setToGeometry(g, self.layer)

#            print str(self.ptStart.toString())
#            print str(newPoint.toString())
#            print str(self.ptEnd.toString())

        pass
예제 #4
0
        def createCircularArc(self):
            settings = QSettings("CatAIS","cadtools")
            method = settings.value("arcs/featuremethod",  "pitch")
            if method == "pitch":
                value = settings.value("arcs/featurepitch",  2, type=float)
            else:
                value = settings.value("arcs/featureangle",  1, type=float)

            if self.p1 == None or self.p2 == None or self.p3 == None:
                QMessageBox.information(None, QCoreApplication.translate("ctools", "Cancel"), QCoreApplication.translate("ctools", "Not enough points selected."))
            else:
                g = CircularArc.getInterpolatedArc(self.p1,  self.p2,  self.p3,  method,  value)
                cadutils.addGeometryToCadLayer(g)     
                self.canvas.refresh()
                
                self.unsetTool()
        def createCircularArc(self):
            settings = QSettings("CatAIS","cadtools")
            method = settings.value("arcs/featuremethod",  "pitch")
            if method == "pitch":
                value = settings.value("arcs/featurepitch",  2)
            else:
                value = settings.value("arcs/featureangle",  1)

            if self.p1 == None or self.p2 == None or self.p3 == None:
                QMessageBox.information(None,  "Cancel",  "Not enough points selected.")
            else:
                g = CircularArc.getInterpolatedArc(self.p1,  self.p2,  self.p3,  method.toString(),  value.toDouble()[0])
                cadutils.addGeometryToCadLayer(g)     
                self.canvas.refresh()
                
                self.unsetTool()
예제 #6
0
    def createCircularArc(self):
        settings = QSettings("CatAIS", "cadtools")
        method = settings.value("arcs/featuremethod", "pitch")
        if method == "pitch":
            value = settings.value("arcs/featurepitch", 2)
        else:
            value = settings.value("arcs/featureangle", 1)

        if self.p1 == None or self.p2 == None or self.p3 == None:
            QMessageBox.information(None, "Cancel",
                                    "Not enough points selected.")
        else:
            g = CircularArc.getInterpolatedArc(self.p1, self.p2, self.p3,
                                               method.toString(),
                                               value.toDouble()[0])
            cadutils.addGeometryToCadLayer(g)
            self.canvas.refresh()

            self.unsetTool()
예제 #7
0
    def canvasPressEvent(self, event):
        color = QColor(255, 0, 0, 100)
        self.rb.setColor(color)
        self.rb.setWidth(1)

        x = event.pos().x()
        y = event.pos().y()

        if event.button() == Qt.LeftButton:

            ## This is the same as in the canvasMoveEvent.
            ## Is there an easier way??? Or  more logical way?
            startingPoint = QPoint(x, y)
            snapper = QgsMapCanvasSnapper(self.canvas)

            (retval,
             result) = snapper.snapToCurrentLayer(startingPoint,
                                                  QgsSnapper.SnapToVertex)
            if result <> []:
                point = result[0].snappedVertex
            else:
                (retval,
                 result) = snapper.snapToBackgroundLayers(startingPoint)
                if result <> []:
                    point = result[0].snappedVertex
                else:
                    point = self.canvas.getCoordinateTransform(
                    ).toMapCoordinates(event.pos().x(),
                                       event.pos().y())

            self.rb.addPoint(point)

            if self.mCtrl == True:
                if self.count == 0:
                    self.ptStart = QgsPoint(point.x(), point.y())
                    print str(self.ptStart.toString())
                    print "******************** NUmmer EINS...."
                elif self.count == 1:
                    self.ptArc = QgsPoint(point.x(), point.y())
                    print "******************** NUmmer ZWEI...."
                elif self.count == 2:

                    print "******************** NUmmer drei...."
                    print str(self.ptStart.toString())

                    self.ptEnd = QgsPoint(point.x(), point.y())
                    self.count = -1

                    ## Remove the last three points
                    ## and create the circular arc.
                    self.rb.removeLastPoint()
                    self.rb.removeLastPoint()
                    self.rb.removeLastPoint()

                    settings = QSettings("CatAIS", "cadtools")
                    method = settings.value("arcs/featuremethod", "pitch")
                    if method == "pitch":
                        value = settings.value("arcs/featurepitch",
                                               2,
                                               type=float)
                    else:
                        value = settings.value("arcs/featureangle",
                                               1,
                                               type=float)

                    g = CircularArc.getInterpolatedArc(self.ptStart,
                                                       self.ptArc, self.ptEnd,
                                                       method, value)
                    ptList = g.asPolyline()

                    ## Add the segmentation points to the rubberband.
                    for i in ptList:
                        self.rb.addPoint(i)

                    self.mCtrl == False
                self.count = self.count + 1

        else:
            self.createFeature()
예제 #8
0
    def canvasReleaseEvent(self, event):
        if self.rb2 <> None:
            ## Reset the rubberband.
            self.rb2.reset()
            self.rb2 = None

            ## What happens to newPoint???? Even as self.newPoint it
            ## does not work....
            ## We just snap again....
            x = event.pos().x()
            y = event.pos().y()
            startingPoint = QPoint(x, y)
            snapper = QgsMapCanvasSnapper(self.canvas)
            (retval,
             result) = snapper.snapToCurrentLayer(startingPoint,
                                                  QgsSnapper.SnapToVertex)
            if result <> []:
                newPoint = result[0].snappedVertex
            else:
                (retval,
                 result) = snapper.snapToBackgroundLayers(startingPoint)
                if result <> []:
                    newPoint = result[0].snappedVertex
                else:
                    newPoint = self.toLayerCoordinates(self.layer, event.pos())

            ## Modify the feature.
            settings = QSettings("CatAIS", "cadtools")
            method = settings.value("arcs/featuremethod", "pitch")
            if method == "pitch":
                value = settings.value("arcs/featurepitch", 2, type=float)
            else:
                value = settings.value("arcs/featureangle", 1, type=float)
            if self.movingVertex == "arc":
                g = CircularArc.getInterpolatedArc(self.ptStart, newPoint,
                                                   self.ptEnd, method, value)
            elif self.movingVertex == "start":
                g = CircularArc.getInterpolatedArc(newPoint, self.ptArc,
                                                   self.ptEnd, method, value)
            elif self.movingVertex == "end":
                g = CircularArc.getInterpolatedArc(self.ptStart, self.ptArc,
                                                   newPoint, method, value)

            ## On the Fly reprojection of the geometry (only if needed)
            layerEPSG = cadutils.authidToCrs(self.layer.crs().authid())
            projectEPSG = cadutils.authidToCrs(
                self.canvas.mapRenderer().destinationCrs().authid())
            if layerEPSG != projectEPSG:
                layerCrs = self.layer.crs()
                projectCrs = self.canvas.mapRenderer().destinationCrs()
                coordtrans = QgsCoordinateTransform(layerCrs, projectCrs)
                g.transform(coordtrans)

            self.layer.beginEditCommand("Geometry modified.")
            self.layer.changeGeometry(self.featId, g)
            self.layer.endEditCommand()
            self.layer.reload()
            self.canvas.refresh()

        ## Reset some stuff.
        self.clicked = False
        self.featId = None

        pass
    def canvasPressEvent(self,event):
        color = QColor(255,0,0)
        self.rb.setColor(color) 
        self.rb.setWidth(1)      
        
        x = event.pos().x()
        y = event.pos().y()
        
        if event.button() == Qt.LeftButton:
            
            ## This is the same as in the canvasMoveEvent.
            ## Is there an easier way??? Or  more logical way?
            startingPoint = QPoint(x,y)
            snapper = QgsMapCanvasSnapper(self.canvas)
            
            (retval,result) = snapper.snapToCurrentLayer (startingPoint, QgsSnapper.SnapToVertex)   
            if result <> []:
                point = result[0].snappedVertex
            else:
                (retval,result) = snapper.snapToBackgroundLayers(startingPoint)
                if result <> []:
                    point = result[0].snappedVertex
                else:
                    point = self.canvas.getCoordinateTransform().toMapCoordinates( event.pos().x(), event.pos().y() );
            
            self.rb.addPoint(point)
            
            if self.mCtrl == True:
                if self.count == 0:
                    self.ptStart = QgsPoint( point.x(),  point.y() )
                    print str(self.ptStart.toString())
                    print "******************** NUmmer EINS...."
                elif self.count == 1:
                    self.ptArc = QgsPoint( point.x(),  point.y() )
                    print "******************** NUmmer ZWEI...."
                elif self.count == 2:
                    
                    print "******************** NUmmer drei...."
                    print str(self.ptStart.toString())
                    
                    self.ptEnd = QgsPoint( point.x(),  point.y() )
                    self.count = -1
                    
                    ## Remove the last three points 
                    ## and create the circular arc.
                    self.rb.removeLastPoint( )
                    self.rb.removeLastPoint( )
                    self.rb.removeLastPoint( )
                    
                    settings = QSettings("CatAIS","cadtools")
                    method = settings.value("arcs/featuremethod",  "pitch")
                    if method == "pitch":
                        value = settings.value("arcs/featurepitch",  2)
                    else:
                        value = settings.value("arcs/featureangle",  1)

                    g = CircularArc.getInterpolatedArc(self.ptStart,  self.ptArc,  self.ptEnd,  method.toString(),  value.toDouble()[0])
                    ptList = g.asPolyline()
                    
                    ## Add the segmentation points to the rubberband.
                    for i in ptList:
                        self.rb.addPoint(i)
                    
                    self.mCtrl == False
                self.count = self.count + 1
            
        else:
            self.createFeature()