Example #1
0
 def action(self, arg):  #re-defintition of the method of parent
     "scene event handler"
     if arg["Type"] == "SoKeyboardEvent" and arg["State"] == 'DOWN':
         # key detection
         if arg["Key"] == "ESCAPE":
             self.finish()
         elif arg["ShiftDown"] and arg["CtrlDown"]:
             if arg["Key"] in ('M', 'm'):
                 if self.hackedUI.cb1.isChecked():
                     self.hackedUI.cb1.setChecked(False)
                 else:
                     self.hackedUI.cb1.setChecked(True)
             elif arg["Key"] in ('O', 'o'):
                 self.offsetWP()
             elif arg["Key"] in ('R', 'r'):
                 self.rotateWP()
     elif arg["Type"] == "SoLocation2Event":
         # mouse movement detection
         self.point, ctrlPoint, info = DraftTools.getPoint(self, arg)
     elif arg["Type"] == "SoMouseButtonEvent":
         # mouse button detection
         if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
             if (arg["Position"] == self.pos):
                 self.finish(False, cont=True)
             else:
                 if (not self.node) and (not self.support):
                     DraftTools.getSupport(arg)
                     self.point, ctrlPoint, info = DraftTools.getPoint(
                         self, arg)
                 if self.point:
                     self.ui.redraw()
                     self.pos = arg["Position"]
                     self.node.append(self.point)
                     self.drawSegment(self.point)
                     if self.hackedUI.cb1.isChecked():
                         rot = FreeCAD.DraftWorkingPlane.getPlacement(
                         ).Rotation
                         normal = rot.multVec(FreeCAD.Vector(0, 0, 1))
                         FreeCAD.DraftWorkingPlane.alignToPointAndAxis(
                             self.point, normal)
                         FreeCADGui.Snapper.setGrid()
                     if (not self.isWire and len(self.node) == 2):
                         self.finish(False, cont=True)
                     if (len(self.node) > 2):
                         if ((self.point - self.node[0]).Length <
                                 Draft.tolerance()):
                             self.undolast()
                             self.finish(True, cont=True)
    def action(self, arg):
        '''
        Event handling for alignment drawing
        '''

        #trap the escape key to quit
        if arg['Type'] == 'SoKeyboardEvent':
            if arg['Key'] == 'ESCAPE':
                self.finish()
                return

        #trap mouse movement
        if arg['Type'] == 'SoLocation2Event':

            self.point, ctrl_point, info = DraftTools.getPoint(self, arg, noTracker=False)

            self.alignment_tracker.update(self.node + [self.point], degree=self.degree)

            redraw3DView()

            return

        #trap button clicks
        if arg['Type'] == 'SoMouseButtonEvent':

            if (arg['State'] == 'DOWN') and (arg['Button'] == 'BUTTON1'):

                if arg['Position'] == self.pos:
                    self.finish(False, cont=True)
                    return

                #first point
                if not (self.node or self.support):

                    getSupport(arg)
                    self.point, ctrl_point, info = DraftTools.getPoint(self, arg, noTracker=True)

                if self.point:

                    self.ui.redraw()
                    self.node.append(self.point)
                    self.draw_update(self.point)

                    if not self.isWire and len(self.node) == 2:
                        self.finish(False, cont = True)
Example #3
0
 def action(self,arg): #re-defintition of the method of parent
     "scene event handler"
     if arg["Type"] == "SoKeyboardEvent" and arg["State"]=='DOWN':
         # key detection
         if arg["Key"] == "ESCAPE":
             self.finish()
         elif arg["ShiftDown"] and arg["CtrlDown"]:
           if arg["Key"] in ('M','m'):
             if self.hackedUI.cb1.isChecked():
               self.hackedUI.cb1.setChecked(False)
             else:
               self.hackedUI.cb1.setChecked(True)
           elif arg["Key"] in ('O','o'):
             self.offsetWP()
           elif arg["Key"] in ('R','r'):
             self.rotateWP()
     elif arg["Type"] == "SoLocation2Event":
         # mouse movement detection
         self.point,ctrlPoint,info = DraftTools.getPoint(self,arg)
     elif arg["Type"] == "SoMouseButtonEvent":
         # mouse button detection
         if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
             if (arg["Position"] == self.pos):
                 self.finish(False,cont=True)
             else:
                 if (not self.node) and (not self.support):
                     DraftTools.getSupport(arg)
                     self.point,ctrlPoint,info = DraftTools.getPoint(self,arg)
                 if self.point:
                     self.ui.redraw()
                     self.pos = arg["Position"]
                     self.node.append(self.point)
                     self.drawSegment(self.point)
                     if self.hackedUI.cb1.isChecked():
                       rot=FreeCAD.DraftWorkingPlane.getPlacement().Rotation
                       normal=rot.multVec(FreeCAD.Vector(0,0,1))
                       FreeCAD.DraftWorkingPlane.alignToPointAndAxis(self.point,normal)
                       FreeCADGui.Snapper.setGrid()
                     if (not self.isWire and len(self.node) == 2):
                         self.finish(False,cont=True)
                     if (len(self.node) > 2):
                         if ((self.point-self.node[0]).Length < Draft.tolerance()):
                             self.undolast()
                             self.finish(True,cont=True)
Example #4
0
    def action(self, arg):
        """Scene event handler. CURRENTLY NOT USED.

        Here the displaying of the trackers (previews)
        should be implemented by considering the current value of the
        `ui.radiusValue`.
        """
        if arg["Type"] == "SoKeyboardEvent":
            if arg["Key"] == "ESCAPE":
                self.finish()
        elif arg["Type"] == "SoLocation2Event":
            self.point, ctrlPoint, info = DraftTools.getPoint(self, arg)
            DraftTools.redraw3DView()
Example #5
0
 def action(self, arg):
     """scene event handler"""
     if arg["Type"] == "SoKeyboardEvent":
         if arg["Key"] == "ESCAPE":
             self.reject()
     elif arg["Type"] == "SoLocation2Event":  # mouse movement detection
         self.point, ctrlPoint, info = DraftTools.getPoint(self.sourceCmd,
                                                           arg,
                                                           noTracker=True)
         if not self.pointPicked:
             self.setPoint(self.point)
     elif arg["Type"] == "SoMouseButtonEvent":
         if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
             self.setPoint(self.point)
             self.pointPicked = True
Example #6
0
 def action(self, arg):
     "scene event handler"
     if arg["Type"] == "SoKeyboardEvent":
         if arg["Key"] == "ESCAPE":
             self.finish()
     elif arg["Type"] == "SoLocation2Event":  #mouse movement detection
         self.point, ctrlPoint, info = DraftTools.getPoint(self,
                                                           arg,
                                                           mobile=True,
                                                           noTracker=True)
         self.rect.update(self.point)
         DraftTools.redraw3DView()
     elif arg["Type"] == "SoMouseButtonEvent":
         if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"):
             if (arg["Position"] == self.pos):
                 self.finish()
             else:
                 if (not self.node) and (not self.support):
                     DraftTools.getSupport(arg)
                     self.point, ctrlPoint, info = DraftTools.getPoint(
                         self, arg, mobile=True, noTracker=True)
                 if self.point:
                     self.ui.redraw()
                     self.appendPoint(self.point)
Example #7
0
    def action(self,arg):
        "scene event handler"

        if arg["Type"] == "SoKeyboardEvent" and arg["State"] == "DOWN":
            if arg["Key"] == "ESCAPE":
                self.finish()
            elif arg["Key"] == "a":
                self.finish()
            elif arg["Key"] == "o":
                self.finish(closed=True)
            elif arg["Key"] == "i":
                if Draft.getType(self.obj) == "Circle": self.arcInvert()

        elif arg["Type"] == "SoLocation2Event": #mouse movement detection
            self.point,ctrlPoint,info = DraftTools.getPoint(self,arg)# causes problems when mouseover bezcurves
            if self.editing != None:
                self.trackers[self.editing].set(self.point)
                #FreeCAD.Console.PrintMessage(self.ghost)
                self.updateGhost(obj=self.obj,idx=self.editing,pt=self.point)

            if hasattr(self.obj.ViewObject,"Selectable"):
                if self.ui.addButton.isChecked():
                    self.obj.ViewObject.Selectable = True
                else:
                    self.obj.ViewObject.Selectable = False
            DraftTools.redraw3DView()

        elif arg["Type"] == "SoMouseButtonEvent" and arg["State"] == "DOWN":

            if arg["Button"] == "BUTTON1":
                self.ui.redraw()

                if self.editing == None:
                    # USECASE: User click on one of the editpoints or another object
                    ep = None
                    selobjs = self.getSelection()
                    if selobjs == None: return

                    if self.ui.addButton.isChecked():# still quite raw
                        # USECASE: User add a new point to the object
                        for info in selobjs:
                            if Draft.getType(self.obj) == "Wire" and 'Edge' in info["Component"]:
                                pt = FreeCAD.Vector(info["x"],info["y"],info["z"])
                                self.addPointToWire(pt, int(info["Component"][4:]))
                            elif self.point:
                                pt = self.point
                                if "x" in info:# prefer "real" 3D location over working-plane-driven one if possible
                                    pt = FreeCAD.Vector(info["x"],info["y"],info["z"])
                                self.addPointToCurve(pt,info)
                        self.removeTrackers()
                        self.editpoints = []
                        self.setEditPoints(self.obj)
                        self.resetTrackers()
                        return

                    ep = self.lookForClickedNode(selobjs,tolerance=20)
                    if ep == None: return

                    if self.ui.delButton.isChecked(): # still quite raw
                        # USECASE: User delete a point of the object
                        self.delPoint(ep)
                        # don't do tan/sym on DWire/BSpline!
                        self.removeTrackers()
                        self.editpoints = []
                        self.setEditPoints(self.obj)
                        self.resetTrackers()
                        return

                    if Draft.getType(self.obj) == "BezCurve":
                        # USECASE: User change the continuity of a Bezcurve point
                        if self.ui.sharpButton.isChecked():
                            return self.smoothBezPoint(ep, 'Sharp')
                        elif self.ui.tangentButton.isChecked():
                            return self.smoothBezPoint(ep, 'Tangent')
                        elif self.ui.symmetricButton.isChecked():
                            return self.smoothBezPoint(ep, 'Symmetric')

                    if self.ui.arc3PtButton.isChecked():
                        self.arc3Pt = False
                    else:
                        self.arc3Pt = True
                    self.ui.pointUi()
                    self.ui.isRelative.show()
                    self.editing = ep
                    self.trackers[self.editing].off()
                    self.finalizeGhost()
                    self.ghost = self.initGhost(self.obj)
                    '''if hasattr(self.obj.ViewObject,"Selectable"):
                        self.obj.ViewObject.Selectable = False'''
                    self.node.append(self.trackers[self.editing].get())
                    FreeCADGui.Snapper.setSelectMode(False)

                else: #if self.editing != None:
                    # USECASE: Destination point of editing is clicked
                    self.finalizeGhost()
                    self.trackers[self.editing].on()
                    #if hasattr(self.obj.ViewObject,"Selectable"):
                    #    self.obj.ViewObject.Selectable = True
                    FreeCADGui.Snapper.setSelectMode(True)
                    self.numericInput(self.trackers[self.editing].get())