def execute(self,obj): if self.Changed: say("self changed") self.Changed=False return if not self.Lock: self.obj2=obj self.Lock=True try: self.update() except: sayexc('update') self.Lock=False
def execute(self, obj): if self.Changed: say("self changed") self.Changed = False return if not self.Lock: self.obj2 = obj self.Lock = True try: self.update() except: sayexc('update') self.Lock = False
def eventFilter(self, o, e): z = str(e.type()) try: # 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.HoverMove': self.pos = e.pos() if z == 'PySide.QtCore.QEvent.Type.KeyPress': # ignore editors if self.editmode: return QtGui.QWidget.eventFilter(self, o, e) # only first time key pressed if not self.keypressed: text = e.text() if 0 or text <> '': self.keypressed = True key = '' if e.modifiers() & QtCore.Qt.SHIFT: #FreeCAD.Console.PrintMessage("SHIFT ") key += "SHIFT+" if e.modifiers() & QtCore.Qt.CTRL: #FreeCAD.Console.PrintMessage("CTRL ") key += "CTRL+" if e.modifiers() & QtCore.Qt.ALT: #FreeCAD.Console.PrintMessage("ALT ") key += "ALT+" key += PySide.QtGui.QKeySequence(e.key()).toString() FreeCAD.Console.PrintMessage(" " + str(key) + " \n") pos = self.pos #if e.key()== QtCore.Qt.Key_F10: # key += "F10#" if pos: if self.debug: FreeCAD.Console.PrintMessage( key + " at mouse position: " + str(pos) + "\n") say(pos.x()) say(pos.y()) step = 1 if key == 'F': self.V.Placement.Base.x -= step elif key == 'G': self.V.Placement.Base.x += step elif key == 'T': self.V.Placement.Base.y += step elif key == 'V': self.V.Placement.Base.y -= step elif key == 'Z': self.V.Placement.Base.x += step self.V.Placement.Base.y += step elif key == 'R': self.V.Placement.Base.x -= step self.V.Placement.Base.y += step elif key == 'B': self.V.Placement.Base.x += step self.V.Placement.Base.y -= step elif key == 'C': self.V.Placement.Base.x -= step self.V.Placement.Base.y -= step elif key == 'H': s = Gui.Selection.getSelection() try: ll = Gui.Selection.getSelectionEx() pts = ll[0].PickedPoints V.Placement.Base.x = pts[0].x V.Placement.Base.y = pts[0].y except: try: say("error 11") self.V.Placement.Base.x = s[ 0].Placement.Base.x self.V.Placement.Base.y = s[ 0].Placement.Base.y except: say("error 2") pass self.ctl.Placement = self.V.Placement App.ActiveDocument.recompute() else: self.keypressed = False if z == 'PySide.QtCore.QEvent.Type.KeyRelease': if self.keypressed: pass self.keypressed = False except: sayexc() try: return QtGui.QWidget.eventFilter(self, o, e) except: return None
def eventFilter(self, o, e): z=str(e.type()) try: # 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.HoverMove' : self.pos=e.pos() if z == 'PySide.QtCore.QEvent.Type.KeyPress': # ignore editors if self.editmode: return QtGui.QWidget.eventFilter(self, o, e) # only first time key pressed if not self.keypressed: text=e.text() if 0 or text !='': self.keypressed=True key='' if e.modifiers() & QtCore.Qt.SHIFT: #FreeCAD.Console.PrintMessage("SHIFT ") key +="SHIFT+" if e.modifiers() & QtCore.Qt.CTRL: #FreeCAD.Console.PrintMessage("CTRL ") key +="CTRL+" if e.modifiers() & QtCore.Qt.ALT: #FreeCAD.Console.PrintMessage("ALT ") key +="ALT+" key +=PySide.QtGui.QKeySequence(e.key()).toString() FreeCAD.Console.PrintMessage(" "+str(key) +" \n" ) pos=self.pos #if e.key()== QtCore.Qt.Key_F10: # key += "F10#" if pos: if self.debug: FreeCAD.Console.PrintMessage( key + " at mouse position: " +str(pos) + "\n") say(pos.x()) say(pos.y()) step=1 if key == 'F': self.V.Placement.Base.x -= step elif key == 'G': self.V.Placement.Base.x += step elif key == 'T': self.V.Placement.Base.y += step elif key == 'V': self.V.Placement.Base.y -= step elif key == 'Z': self.V.Placement.Base.x += step self.V.Placement.Base.y += step elif key == 'R': self.V.Placement.Base.x -= step self.V.Placement.Base.y += step elif key == 'B': self.V.Placement.Base.x += step self.V.Placement.Base.y -= step elif key == 'C': self.V.Placement.Base.x -= step self.V.Placement.Base.y -= step elif key == 'H': s=Gui.Selection.getSelection() try: ll=Gui.Selection.getSelectionEx() pts=ll[0].PickedPoints V.Placement.Base.x=pts[0].x V.Placement.Base.y=pts[0].y except: try: say("error 11") self.V.Placement.Base.x=s[0].Placement.Base.x self.V.Placement.Base.y=s[0].Placement.Base.y except: say("error 2") pass self.ctl.Placement=self.V.Placement App.ActiveDocument.recompute() else: self.keypressed=False if z == 'PySide.QtCore.QEvent.Type.KeyRelease': if self.keypressed: pass self.keypressed=False except: sayexc() try: return QtGui.QWidget.eventFilter(self, o, e) except: return None
def velocity(self,ix,mytime): force=self.force damper=self.damper (x,y,z)=self.ptslix[ix] xy=ix%(self.obj2.dimU*self.obj2.dimV) # xp=xy//self.obj2.dimU # yp=xy%self.obj2.dimV xp=xy//self.obj2.dimV yp=xy%self.obj2.dimV # geschwindkeit anpassen -- kraft am ort x,y,z addieren # print "vor ",self.pvs[xp,yp] self.pvs[xp,yp] += force(x,y,z,self.pvs[xp,yp],mytime) print (ix,xy, xp,yp,force(x,y,z,self.pvs[xp,yp],mytime)) # print "nach ",self.pvs[xp,yp] tt=self.pvs[xp,yp] (dx,dy,dz) =damper(x,y,z,self.pvs[xp,yp],mytime) self.pvs[xp,yp] *= damper(x,y,z,self.pvs[xp,yp],mytime) xn,yn,zn=x+tt[0],y+tt[1],z+tt[2] ddx,ddy,ddz=self.obj2.damperWall.x,self.obj2.damperWall.y,self.obj2.damperWall.z if self.obj2.boundMode=='Bound Box': if zn<=0: if xn>self.xmax: xn=self.xmax -ddx*(xn-self.xmax) self.pvs[xp,yp][0] *= -1 if xn<self.xmin: xn=self.xmin -ddx*(xn-self.xmin) self.pvs[xp,yp][0] *= -1 if yn>self.ymax: yn=self.ymax -ddy*(yn-self.ymax) self.pvs[xp,yp][1] *= -1 if yn<self.ymin: yn=self.ymin -ddy*(yn-self.ymin) self.pvs[xp,yp][1] *= -1 if zn>self.zmax: zn=self.zmax -ddz*(zn-self.zmax) self.pvs[xp,yp][2] *= -1 if zn<self.zmin: zn=self.zmin -ddz*(zn-self.zmin) self.pvs[xp,yp][2] *= -1 elif self.obj2.boundMode=='Bound Cylinder': r=40 r=max(self.xmax,self.ymax) if xn**2+yn**2>r**2: try: (x2,y2)=lineCircleCommon(x,y,xn,yn,r) try: (x2,y2)=mirrorCircle(x,y,x2,y2) except: sayexc("") xn,yn=x2,y2 self.pvs[xp,yp][0] = -0.5*xn self.pvs[xp,yp][1] = -0.5*yn except: pass if zn<self.zmin: zn=self.zmin -ddz*(zn-self.zmin) self.pvs[xp,yp][2] *= -1 elif self.obj2.boundMode=='no Bounds': pass else: sayErr("nont implemented mode" + self.obj2.boundMode) rr=1 rr=self.obj2.noise if zn <-5: xn,yn,zn=xn+rr*(0.5-random.random()),yn+rr*(0.5-random.random()),zn+rr*(0.5-random.random()) self.ptslix[ix+self.obj2.dimU*self.obj2.dimV]=[xn,yn,zn] return self.ptslix[ix+self.obj2.dimU*self.obj2.dimV]
def velocity(self,ix,mytime): force=self.force damper=self.damper (x,y,z)=self.ptslix[ix] xy=ix%(self.obj2.dimU*self.obj2.dimV) # xp=xy//self.obj2.dimU # yp=xy%self.obj2.dimV xp=xy//self.obj2.dimV yp=xy%self.obj2.dimV # geschwindkeit anpassen -- kraft am ort x,y,z addieren # print "vor ",self.pvs[xp,yp] self.pvs[xp,yp] += force(x,y,z,self.pvs[xp,yp],mytime) print(ix,xy, xp,yp,force(x,y,z,self.pvs[xp,yp],mytime)) # print "nach ",self.pvs[xp,yp] tt=self.pvs[xp,yp] (dx,dy,dz) =damper(x,y,z,self.pvs[xp,yp],mytime) self.pvs[xp,yp] *= damper(x,y,z,self.pvs[xp,yp],mytime) xn,yn,zn=x+tt[0],y+tt[1],z+tt[2] ddx,ddy,ddz=self.obj2.damperWall.x,self.obj2.damperWall.y,self.obj2.damperWall.z if self.obj2.boundMode=='Bound Box': if zn<=0: if xn>self.xmax: xn=self.xmax -ddx*(xn-self.xmax) self.pvs[xp,yp][0] *= -1 if xn<self.xmin: xn=self.xmin -ddx*(xn-self.xmin) self.pvs[xp,yp][0] *= -1 if yn>self.ymax: yn=self.ymax -ddy*(yn-self.ymax) self.pvs[xp,yp][1] *= -1 if yn<self.ymin: yn=self.ymin -ddy*(yn-self.ymin) self.pvs[xp,yp][1] *= -1 if zn>self.zmax: zn=self.zmax -ddz*(zn-self.zmax) self.pvs[xp,yp][2] *= -1 if zn<self.zmin: zn=self.zmin -ddz*(zn-self.zmin) self.pvs[xp,yp][2] *= -1 elif self.obj2.boundMode=='Bound Cylinder': r=40 r=max(self.xmax,self.ymax) if xn**2+yn**2>r**2: try: (x2,y2)=lineCircleCommon(x,y,xn,yn,r) try: (x2,y2)=mirrorCircle(x,y,x2,y2) except: sayexc("") xn,yn=x2,y2 self.pvs[xp,yp][0] = -0.5*xn self.pvs[xp,yp][1] = -0.5*yn except: pass if zn<self.zmin: zn=self.zmin -ddz*(zn-self.zmin) self.pvs[xp,yp][2] *= -1 elif self.obj2.boundMode=='no Bounds': pass else: sayErr("nont implemented mode" + self.obj2.boundMode) rr=1 rr=self.obj2.noise if zn <-5: xn,yn,zn=xn+rr*(0.5-random.random()),yn+rr*(0.5-random.random()),zn+rr*(0.5-random.random()) self.ptslix[ix+self.obj2.dimU*self.obj2.dimV]=[xn,yn,zn] return self.ptslix[ix+self.obj2.dimU*self.obj2.dimV]