def eventFilter(self, o, e): ''' the eventfilter for the facedraw server''' z = str(e.type()) event = e if event.type() == QtCore.QEvent.ContextMenu: return True # not used events if z == 'PySide.QtCore.QEvent.Type.ChildAdded' or \ z == 'PySide.QtCore.QEvent.Type.ChildRemoved'or \ z == 'PySide.QtCore.QEvent.Type.User' or \ z == 'PySide.QtCore.QEvent.Type.Paint' or \ z == 'PySide.QtCore.QEvent.Type.LayoutRequest' or\ z == 'PySide.QtCore.QEvent.Type.UpdateRequest' : return QtGui.QWidget.eventFilter(self, o, e) if z == 'PySide.QtCore.QEvent.Type.KeyPress': # http://doc.qt.io/qt-4.8/qkeyevent.html print("key", e.key()) # ignore editors try: if self.editmode: return QtGui.QWidget.eventFilter(self, o, e) except: pass # only first time key pressed if not self.keyPressed2: self.keyPressed2 = True time2 = time.time() ee = e.text() if time2 - self.lasttime < 0.01 and len( ee) > 0 and ee[0] == self.lastkey: self.lasttime = time2 return False try: # only two function keys implemented, no modifieres if e.key() == QtCore.Qt.Key_F2: say("------------F2-- show mode and moddata---------------" ) return False elif e.key() == QtCore.Qt.Key_Escape: say("------------Escape = Stop-----------------") stop() elif e.key() == QtCore.Qt.Key_F3: say("------------F3 up x-----------------") self.dialog.modl.setText("Mode: add") self.mode = 'up' return False elif e.key() == QtCore.Qt.Key_F4: say("------------D down y-----------------") self.dialog.modl.setText("Mode: subtract") self.mode = 'down' return False elif e.key() == QtCore.Qt.Key_F5: say("------------F3 zero-----------------") self.dialog.modl.setText("Mode: reset to null") self.mode = 'zero' return False elif e.key() == QtCore.Qt.Key_F6: say("------------F6 none-----------------") self.dialog.modl.setText("Mode: none") self.mode = 'none' return False # some key bindings not used at the moment # elif e.key()== QtCore.Qt.Key_Return: # say("------------Enter-----------------") # self.update() elif e.key() == QtCore.Qt.Key_Right: print "Go right" return True elif e.key() == QtCore.Qt.Key_Left: print "Go Left" return True elif e.key() == QtCore.Qt.Key_Up: # self.mouseWheel += FreeCAD.ParamGet('User parameter:Plugins/nurbs').GetFloat("MoveCursorStep",10) print "go up" return True elif e.key() == QtCore.Qt.Key_Down: print "Go Down" return True elif e.key() == QtCore.Qt.Key_PageUp: self.mouseWheel += FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MovePageStep", 50) self.dialog.ef_action("up!", self, self.mouseWheel) return True elif e.key() == QtCore.Qt.Key_PageDown: self.mouseWheel -= FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MovePageStep", 50) self.dialog.ef_action("down!", self, self.mouseWheel) return True if e.key() == QtCore.Qt.Key_Enter or e.key( ) == QtCore.Qt.Key_Return: print "Enter Action-----------------------------" # enter creates a new point ... # vf=FreeCAD.Vector(self.x,self.y,self.z) print self.pos if self.mode == 'marker': createMarker(self) return True # self.colors += [self.colorA] # self.pts += [vf] # # if len(self.pts)>1: # self.wire.Shape=Part.makePolygon(self.pts) # drawColorpath(self.pts,self.colors,self.colorA) else: # letter key pressed ee = e.text() if len(ee) > 0: r = ee[0] else: r = "key:" + str(e.key()) self.lastkey = e.text() # zooming +-* if r == '+': Gui.activeDocument().ActiveView.zoomIn() return True if r == '-': Gui.activeDocument().ActiveView.zoomOut() return True if r == '*': Gui.activeDocument().ActiveView.fitAll() return True if r in ['a', 'b', 'c']: print("KEY pressed ----------------------", r) except: sayexc() if event.type() == QtCore.QEvent.MouseMove: (x, y) = Gui.ActiveDocument.ActiveView.getCursorPos() t = Gui.ActiveDocument.ActiveView.getObjectsInfo((x, y)) #--------------------- cursor = QtGui.QCursor() p = cursor.pos() # if p.x()<100 or p.y()<100: # print "jump cursor facedraw 92" # cursor.setPos(p.x()+100, p.y()+100) #----------------------------------- if t <> None: # if objects are under the mouse #pts=App.ActiveDocument.shoe_last_scanned.Points.Points # print "-----!" for tt in t: if tt['Object'] == "MyGrid_N": pp = FreeCAD.Vector(tt['x'], tt['y'], tt['z']) sp = App.ActiveDocument.getObject("Sphere") if sp == None: sp = App.ActiveDocument.addObject( "Part::Sphere", "Sphere") sp.Placement.Base = pp sf = self.nu.Shape.Face1.Surface print "Position on nurbs:", sf.parameter(pp) self.pos = pp sf.parameter(pp) if event.buttons() == QtCore.Qt.LeftButton: # print "LEFT BUTTON drawing" check(pp, self.mode, False, self) break for tt in t: if tt['Object'] == "MyGrid_M": # print (tt['Object'],tt['Component']) # print (tt['x']) # print (tt['y']) # print (tt['z']) pp = FreeCAD.Vector(tt['x'], tt['y'], tt['z']) sp = App.ActiveDocument.getObject("Sphere") if sp == None: sp = App.ActiveDocument.addObject( "Part::Sphere", "Sphere") sp.Placement.Base = pp # sf=App.ActiveDocument.Nurbs.Shape.Face1.Surface sf = self.nu.Shape.Face1.Surface # print "Position on nurbs:",sf.parameter(pp) sf.parameter(pp) if event.buttons() == QtCore.Qt.LeftButton: # print "LEFT BUTTON drawing" check(pp, self.mode, False, self) break return False # end of a single key pressed if z == 'PySide.QtCore.QEvent.Type.KeyRelease': self.lasttime = time.time() self.keyPressed2 = False # enter and leave a widget - editor widgets if z == 'PySide.QtCore.QEvent.Type.Enter' or z == 'PySide.QtCore.QEvent.Type.Leave': pass # deactivate keys in editors context if z == 'PySide.QtCore.QEvent.Type.Enter' and \ (o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit): self.editmode = True elif z == 'PySide.QtCore.QEvent.Type.Leave' and \ (o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit): self.editmode = False # mouse movement only leaves and enters if z == 'PySide.QtCore.QEvent.Type.HoverMove': pass return QtGui.QWidget.eventFilter(self, o, e)
def eventFilter(self, o, e): ''' the eventfilter for the facedraw server''' z = str(e.type()) event = e #ef=FreeCAD.eventfilter if event.type() == QtCore.QEvent.ContextMenu: return True # not used events if z == 'PySide.QtCore.QEvent.Type.ChildAdded' or \ z == 'PySide.QtCore.QEvent.Type.ChildRemoved'or \ z == 'PySide.QtCore.QEvent.Type.User' or \ z == 'PySide.QtCore.QEvent.Type.Paint' or \ z == 'PySide.QtCore.QEvent.Type.LayoutRequest' or\ z == 'PySide.QtCore.QEvent.Type.UpdateRequest' : return QtGui.QWidget.eventFilter(self, o, e) if event.type() == QtCore.QEvent.MouseMove: (x, y) = Gui.ActiveDocument.ActiveView.getCursorPos() t = Gui.ActiveDocument.ActiveView.getObjectsInfo((x, y)) #--------------------- cursor = QtGui.QCursor() p = cursor.pos() px = p.x() py = p.y() if p.x() < 100 or p.y() < 100: print "jump cursor facedraw 92" # cursor.setPos(p.x()+100, p.y()+100) #----------------------------------- if t <> None: # if objects are under the mouse for tix, tt in enumerate(t): print("objunder ", tix, tt, tt['Object'], tt['Component']) print self.fob.Label uxx = ef.xy2u(px, py) vxx = ef.xy2v(px, py) print(vxx, uxx) # if tt['Object']==self.objname and tt['Component']==self.subelement: # self.x,self.y,self.z=tt['x'],tt['y'],tt['z'] # break if event.buttons() == QtCore.Qt.LeftButton: #print "LEFT BUTTON drawing" vf = FreeCAD.Vector(self.x, self.y, self.z) bs = self.subobj.Surface (u, v) = bs.parameter(vf) #print (u,v) lu = 0.5 lv = 0.5 ba = bs.vIso(u) ky = ba.length(v, lv) if v < 0.5: ky = -ky bbc = bs.vIso(v) kx = bbc.length(lu, u) if u < 0.5: kx = -kx mf = FreeCAD.Vector(self.x, self.y, 0) mf = FreeCAD.Vector(-1 * ky, -1 * kx, 0) self.pts += [vf] self.ptsm += [mf] self.colors += [self.colorA] drawColorpath(self.pts, self.colors, self.colorA) self.wire.ViewObject.Visibility = False if len(self.pts) > 1: self.wire.Shape = Part.makePolygon(self.pts) self.wirem.Shape = Part.makePolygon(self.ptsm) return True if z == 'PySide.QtCore.QEvent.Type.KeyPress': # http://doc.qt.io/qt-4.8/qkeyevent.html # ignore editors try: if self.editmode: return QtGui.QWidget.eventFilter(self, o, e) except: pass # only first time key pressed if not self.keyPressed2: self.keyPressed2 = True time2 = time.time() ee = e.text() if time2 - self.lasttime < 0.01 and len( ee) > 0 and ee[0] == self.lastkey: self.lasttime = time2 return False try: # only two function keys implemented, no modifieres if e.key() == QtCore.Qt.Key_F2: say("------------F2-- show mode and moddata---------------" ) return False elif e.key() == QtCore.Qt.Key_Escape: say("------------Escape = Stop-----------------") stop() elif e.key() == QtCore.Qt.Key_F3: say("------------F3-----------------") stop() # some key bindings not used at teh moment # elif e.key()== QtCore.Qt.Key_Return: # say("------------Enter-----------------") # self.update() elif e.key() == QtCore.Qt.Key_Right: if self.dialog.dial.value( ) == self.dialog.dial.maximum(): val = 0 else: val = self.dialog.dial.value() + 1 self.dialog.dial.setValue(val) return True elif e.key() == QtCore.Qt.Key_Left: if self.dialog.dial.value() == 0: val = self.dialog.dial.maximum() else: val = self.dialog.dial.value() - 1 self.dialog.dial.setValue(val) return True elif e.key() == QtCore.Qt.Key_Up: self.mouseWheel += FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MoveCursorStep", 10) self.dialog.ef_action("up", self, self.mouseWheel) return True elif e.key() == QtCore.Qt.Key_Down: self.mouseWheel -= FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MoveCursorStep", 10) self.dialog.ef_action("down", self, self.mouseWheel) return True elif e.key() == QtCore.Qt.Key_PageUp: self.mouseWheel += FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MovePageStep", 50) self.dialog.ef_action("up!", self, self.mouseWheel) return True elif e.key() == QtCore.Qt.Key_PageDown: self.mouseWheel -= FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MovePageStep", 50) self.dialog.ef_action("down!", self, self.mouseWheel) return True if e.key() == QtCore.Qt.Key_Enter or e.key( ) == QtCore.Qt.Key_Return: # enter creates a new point ... vf = FreeCAD.Vector(self.x, self.y, self.z) self.colors += [self.colorA] self.pts += [vf] if len(self.pts) > 1: self.wire.Shape = Part.makePolygon(self.pts) drawColorpath(self.pts, self.colors, self.colorA) else: # letter key pressed ee = e.text() if len(ee) > 0: r = ee[0] else: r = "key:" + str(e.key()) self.lastkey = e.text() #color select for drawing if r == 'h': self.colorA = 0 return True if r == 'y': self.colorA = 1 return True if r == 'n': self.colorA = 2 return True if r == 'g': self.colorA = 3 return True if r == 'j': self.colorA = 4 return True if r == 'z': self.colorA = 6 return True if r == 'x': self.colorA = 5 return True if r == '#': self.colorA = 7 return True # zooming +-* if r == '+': Gui.activeDocument().ActiveView.zoomIn() return True if r == '-': Gui.activeDocument().ActiveView.zoomOut() return True if r == '*': Gui.activeDocument().ActiveView.fitAll() return True if r in ['a', 'b', 'c']: print("KEY pressed ----------------------", r) except: sayexc() # end of a single key pressed if z == 'PySide.QtCore.QEvent.Type.KeyRelease': self.lasttime = time.time() self.keyPressed2 = False # enter and leave a widget - editor widgets if z == 'PySide.QtCore.QEvent.Type.Enter' or z == 'PySide.QtCore.QEvent.Type.Leave': pass # deactive keys in editors context if z == 'PySide.QtCore.QEvent.Type.Enter' and \ (o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit): self.editmode = True elif z == 'PySide.QtCore.QEvent.Type.Leave' and \ (o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit): self.editmode = False # mouse movement only leaves and enters if z == 'PySide.QtCore.QEvent.Type.HoverMove': pass return QtGui.QWidget.eventFilter(self, o, e)
def eventFilter(self, o, e): z = str(e.type()) event = e if event.type() == QtCore.QEvent.ContextMenu: return True # not used events if z == 'PySide.QtCore.QEvent.Type.ChildAdded' or \ z == 'PySide.QtCore.QEvent.Type.ChildRemoved'or \ z == 'PySide.QtCore.QEvent.Type.User' or \ z == 'PySide.QtCore.QEvent.Type.Paint' or \ z == 'PySide.QtCore.QEvent.Type.LayoutRequest' or\ z == 'PySide.QtCore.QEvent.Type.UpdateRequest' : return QtGui.QWidget.eventFilter(self, o, e) if event.type() == QtCore.QEvent.MouseMove: if event.buttons() == QtCore.Qt.NoButton: pos = event.pos() x = pos.x() y = pos.y() # print ("mous pos ",x,y) if z == 'PySide.QtCore.QEvent.Type.KeyPress': # http://doc.qt.io/qt-4.8/qkeyevent.html # ignore editors try: if self.editmode: return QtGui.QWidget.eventFilter(self, o, e) except: pass # only first time key pressed if not self.keyPressed2: self.keyPressed2 = True time2 = time.time() ee = e.text() if time2 - self.lasttime < 0.01 and len( ee) > 0 and ee[0] == self.lastkey: self.lasttime = time2 return False try: # only two function keys implemented, no modifieres if e.key() == QtCore.Qt.Key_F2: say("------------F2-- show mode and moddata---------------" ) print self.mode return False elif e.key() == QtCore.Qt.Key_Escape: say("------------Escape-----------------") stop() elif e.key() == QtCore.Qt.Key_F3: say("------------F3-----------------") stop() elif e.key() == QtCore.Qt.Key_Enter or e.key( ) == QtCore.Qt.Key_Return: # say("------------Enter-----------------") self.update() elif e.key() == QtCore.Qt.Key_Right: if self.dialog.dial.value( ) == self.dialog.dial.maximum(): val = 0 else: val = self.dialog.dial.value() + 1 self.dialog.dial.setValue(val) return True elif e.key() == QtCore.Qt.Key_Left: if self.dialog.dial.value() == 0: val = self.dialog.dial.maximum() else: val = self.dialog.dial.value() - 1 self.dialog.dial.setValue(val) return True elif e.key() == QtCore.Qt.Key_Up: self.mouseWheel += FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MoveCursorStep", 10) self.dialog.ef_action("up", self, self.mouseWheel) return True elif e.key() == QtCore.Qt.Key_Down: self.mouseWheel -= FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MoveCursorStep", 10) self.dialog.ef_action("down", self, self.mouseWheel) return True elif e.key() == QtCore.Qt.Key_PageUp: self.mouseWheel += FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MovePageStep", 50) self.dialog.ef_action("up!", self, self.mouseWheel) return True elif e.key() == QtCore.Qt.Key_PageDown: self.mouseWheel -= FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').GetFloat( "MovePageStep", 50) self.dialog.ef_action("down!", self, self.mouseWheel) return True else: # letter key pressed ee = e.text() if len(ee) > 0: r = ee[0] else: r = "key:" + str(e.key()) #say("-------action for key ----!!------" + r) self.lastkey = e.text() if r == '+': Gui.activeDocument().ActiveView.zoomIn() return True if r == '-': Gui.activeDocument().ActiveView.zoomOut() return True if r == '*': Gui.activeDocument().ActiveView.fitAll() return True if r in ['l', 'r', 'h', 'x', 'y', 'z', 'n', 't', 'b']: self.key = str(r) self.mode = str(r) FreeCAD.ParamGet( 'User parameter:Plugins/nurbs').SetString( "editorKey", self.key) self.dialog.ef_action(r, self) self.dialog.modelab.setText("Direction: " + r) if r == '0': self.mouseWheel = 0 self.mode = '0' except: sayexc() # end of a single key pressed if z == 'PySide.QtCore.QEvent.Type.KeyRelease': self.lasttime = time.time() self.keyPressed2 = False # enter and leave a widget - editor widgets if z == 'PySide.QtCore.QEvent.Type.Enter' or z == 'PySide.QtCore.QEvent.Type.Leave': pass # deactive keys in editors context if z == 'PySide.QtCore.QEvent.Type.Enter' and \ (o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit): self.editmode = True elif z == 'PySide.QtCore.QEvent.Type.Leave' and \ (o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit): self.editmode = False # mouse movement only leaves and enters if z == 'PySide.QtCore.QEvent.Type.HoverMove': pass event = e try: if event.type( ) == QtCore.QEvent.ContextMenu: #and o.__class__ == QtGui.QWidget: # hier contextmenue rechte maus auschalten FreeCAD.Console.PrintMessage( '!! cancel -------------------------------------context-----------\n' ) return False pass # wheel rotation if event.type() == QtCore.QEvent.Type.Wheel: self.mouseWheel += e.delta() / 120 pos = e.pos() self.posx = pos.x() self.posy = pos.y() ##FreeCAD.Console.PrintMessage("wheel: " + str(self.mouseWheel) + " pos: " +str(e.pos())+ "\n") #self.modedat[self.mode]=self.mouseWheel self.dialog.ef_action("wheel", self, self.mouseWheel) noDefaultWheel = self.mode <> 'n' if noDefaultWheel: return True else: return False # mouse clicks if event.type() == QtCore.QEvent.MouseButtonPress or \ event.type() == QtCore.QEvent.MouseButtonRelease or\ event.type() == QtCore.QEvent.MouseButtonDblClick: # FreeCAD.Console.PrintMessage(str(event.type())+ " " + str(o) +'!!\n') if event.button() == QtCore.Qt.MidButton or event.button( ) == QtCore.Qt.MiddleButton: # FreeCAD.Console.PrintMessage('!-------------------------------------!! X middle \n') return False if event.button() == QtCore.Qt.LeftButton: # FreeCAD.Console.PrintMessage('!! X one left\n') return False elif event.button() == QtCore.Qt.RightButton: # FreeCAD.Console.PrintMessage('!! X one right\n') return False except: sayexc() return QtGui.QWidget.eventFilter(self, o, e)