def numericInput(self,numx,numy,numz): "this function gets called by the toolbar when a valid base point has been entered" self.point = Vector(numx,numy,numz) self.node.append(self.point) if not self.pickmode: self.ui.offUi() if self.call: self.view.removeEventCallback("SoEvent",self.call) self.task = DraftGui.ScaleTaskPanel() self.task.sourceCmd = self DraftGui.todo.delay(FreeCADGui.Control.showDialog,self.task) if self.ghost: self.ghost.on() elif len(self.node) == 2: msg(translate("draft", "Pick new distance from base point:")+"\n") elif len(self.node) == 3: if hasattr(FreeCADGui,"Snapper"): FreeCADGui.Snapper.off() if self.call: self.view.removeEventCallback("SoEvent",self.call) d1 = (self.node[1].sub(self.node[0])).Length d2 = (self.node[2].sub(self.node[0])).Length #print d2,"/",d1,"=",d2/d1 if hasattr(self,"task"): if self.task: self.task.lock.setChecked(True) self.task.setValue(d2/d1)
def Activated(self): self.name = translate("draft","Scale", utf8_decode=True) Modifier.Activated(self,self.name) self.ghost = None if self.ui: if not FreeCADGui.Selection.getSelection(): self.ui.selectUi() msg(translate("draft", "Select an object to scale")+"\n") self.call = self.view.addEventCallback("SoEvent",selectObject) else: self.proceed()
def Activated(self): self.name = translate("draft", "BaseTransform", utf8_decode=True) Modifier.Activated(self, self.name) if self.ui: if not FreeCADGui.Selection.getSelection(): self.ui.selectUi() msg(translate("draft", "Select an object to edit") + "\n") self.call_sel = \ self.view.addEventCallback("SoEvent", selectObject) ## TODO it should allow multiple selections ## TODO Ui should be more explanatory else: self.proceed()
def proceed(self): if self.call: self.view.removeEventCallback("SoEvent",self.call) self.sel = FreeCADGui.Selection.getSelection() self.sel = Draft.getGroupContents(self.sel) self.refs = [] self.ui.pointUi(self.name) self.ui.modUi() self.ui.xValue.setFocus() self.ui.xValue.selectAll() self.ghost = ghostTracker(self.sel) self.pickmode = False self.task = None self.call = self.view.addEventCallback("SoEvent",self.action) msg(translate("draft", "Pick base point:")+"\n")
def numericInput(self,numx,numy,numz): "this function gets called by the toolbar when valid x, y, and z \ have been entered there" self.center = Vector(numx,numy,numz) self.node = [self.center] self.arctrack.setCenter(self.center) if self.ghost: for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.center(self.center) self.ui.radiusUi() self.ui.hasFill.hide() self.ui.labelRadius.setText("Base angle") self.step = 1 msg(translate("draft", "Pick base angle:")+"\n")
def numericRadius(self,rad): "this function gets called by the toolbar when valid radius have been entered there" if (self.step == 1): self.ui.labelRadius.setText("Rotation") self.firstangle = math.radians(rad) self.arctrack.setStartAngle(self.firstangle) self.arctrack.on() if self.ghost: for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.on() self.step = 2 msg(translate("draft", "Pick rotation angle:")+"\n") else: self.rot(math.radians(rad),self.ui.isCopy.isChecked()) self.finish(cont=True)
def action(self,arg): "scene event handler" if arg["Type"] == "SoKeyboardEvent": if arg["Key"] == "ESCAPE": self.finish() elif arg["Type"] == "SoLocation2Event": #mouse movement detection #if self.ghost: # self.ghost.off() self.point,ctrlPoint,info = getPoint(self,arg) if (len(self.node) > 0): last = self.node[len(self.node)-1] delta = self.point.sub(last) if self.ghost: for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.move(delta) g.on() if self.extendedCopy: if not hasMod(arg,MODALT): self.finish() redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: self.ui.redraw() if (self.node == []): self.node.append(self.point) self.ui.isRelative.show() if self.ghost: for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.on() msg(translate("draft", "Pick end point:")+"\n") if self.planetrack: self.planetrack.set(self.point) else: last = self.node[0] if self.ui.isCopy.isChecked() or hasMod(arg,MODALT): self.move(self.point.sub(last),True) else: self.move(self.point.sub(last)) if hasMod(arg,MODALT): self.extendedCopy = True else: self.finish(cont=True)
def numericInput(self,numx,numy,numz): "this function gets called by the toolbar when valid x, y, and z \ have been entered there" self.point = Vector(numx,numy,numz) if not self.node: self.node.append(self.point) self.ui.isRelative.show() self.ui.isCopy.show() for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.on() msg(translate("draft", "Pick end point:")+"\n") else: last = self.node[-1] if self.ui.isCopy.isChecked(): self.move(self.point.sub(last),True) else: self.move(self.point.sub(last)) self.finish()
def Activated(self): from bimEdit import hideAttribute self.name = translate("draft","bimMove", utf8_decode=True) Modifier.Activated(self,self.name) self.ghost = {} for typ in self.sel_dict: if typ not in self.ghost: self.ghost.update({typ:[]}) for o in self.sel_dict[typ]: self.ghost[typ].append(o.ghost[typ]) ## Proceeding if self.call: self.view.removeEventCallback("SoEvent",self.call) self.ui.pointUi(self.name) self.ui.modUi() if self.copymode: self.ui.isCopy.setChecked(True) self.ui.xValue.setFocus() self.ui.xValue.selectAll() self.call = self.view.addEventCallback("SoEvent",self.action) msg(translate("draft", "Pick start point:")+"\n")
def Activated(self): from bimEdit import hideAttribute self.name = translate("draft","bimRotate", utf8_decode=True) Modifier.Activated(self,self.name) self.ghost = {} for typ in self.sel_dict: if typ not in self.ghost: self.ghost.update({typ:[]}) for o in self.sel_dict[typ]: self.ghost[typ].append(o.ghost[typ]) self.arctrack = None ## Proceeding if self.call: self.view.removeEventCallback("SoEvent",self.call) self.step = 0 self.center = None self.ui.arcUi() self.ui.modUi() self.ui.setTitle("Rotate") self.arctrack = arcTracker() self.call = self.view.addEventCallback("SoEvent",self.action) msg(translate("draft", "Pick rotation center:")+"\n")
def pickRef(self): self.pickmode = True if self.node: self.node = self.node[:1] # remove previous picks msg(translate("draft", "Pick reference distance from base point:")+"\n") self.call = self.view.addEventCallback("SoEvent",self.action)
def action(self,arg): "scene event handler" if arg["Type"] == "SoKeyboardEvent": if arg["Key"] == "ESCAPE": self.finish() elif arg["Type"] == "SoLocation2Event": #if self.ghost: # self.ghost.off() self.point,ctrlPoint,info = getPoint(self,arg) # this is to make sure radius is what you see on screen if self.center and DraftVecUtils.dist(self.point,self.center): viewdelta = DraftVecUtils.project(self.point.sub(self.center), plane.axis) if not DraftVecUtils.isNull(viewdelta): self.point = self.point.add(viewdelta.negative()) if self.extendedCopy: if not hasMod(arg,MODALT): self.step = 3 self.finish() if (self.step == 0): pass elif (self.step == 1): currentrad = DraftVecUtils.dist(self.point,self.center) if (currentrad != 0): angle = DraftVecUtils.angle(plane.u, self.point.sub(self.center), plane.axis) else: angle = 0 self.ui.setRadiusValue(math.degrees(angle),unit="Angle") self.firstangle = angle self.ui.radiusValue.setFocus() self.ui.radiusValue.selectAll() elif (self.step == 2): currentrad = DraftVecUtils.dist(self.point,self.center) if (currentrad != 0): angle = DraftVecUtils.angle(plane.u, self.point.sub(self.center), plane.axis) else: angle = 0 if (angle < self.firstangle): sweep = (2*math.pi-self.firstangle)+angle else: sweep = angle - self.firstangle self.arctrack.setApertureAngle(sweep) if self.ghost: for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.rotate(plane.axis,sweep) g.on() self.ui.setRadiusValue(math.degrees(sweep), 'Angle') self.ui.radiusValue.setFocus() self.ui.radiusValue.selectAll() redraw3DView() elif arg["Type"] == "SoMouseButtonEvent": if (arg["State"] == "DOWN") and (arg["Button"] == "BUTTON1"): if self.point: if (self.step == 0): self.center = self.point self.node = [self.point] self.ui.radiusUi() self.ui.radiusValue.setText(FreeCAD.Units.Quantity( 0,FreeCAD.Units.Angle).UserString) self.ui.hasFill.hide() self.ui.labelRadius.setText("Base angle") self.arctrack.setCenter(self.center) if self.ghost: for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.center(self.center) self.step = 1 msg(translate("draft", "Pick base angle:")+"\n") if self.planetrack: self.planetrack.set(self.point) elif (self.step == 1): self.ui.labelRadius.setText("Rotation") self.rad = DraftVecUtils.dist(self.point,self.center) self.arctrack.on() self.arctrack.setStartPoint(self.point) if self.ghost: for typ in self.ghost: if typ == 'toEdit' or typ == 'dirDeps': for g in [i for i in self.ghost[typ]]: g.on() self.step = 2 msg(translate("draft", "Pick rotation angle:")+"\n") else: currentrad = DraftVecUtils.dist(self.point,self.center) angle = self.point.sub(self.center).getAngle(plane.u) if DraftVecUtils.project(self.point.sub(self.center), plane.v).getAngle(plane.v) > 1: angle = -angle if (angle < self.firstangle): sweep = (2*math.pi-self.firstangle)+angle else: sweep = angle - self.firstangle if self.ui.isCopy.isChecked() or hasMod(arg,MODALT): self.rot(sweep,True) else: self.rot(sweep) if hasMod(arg,MODALT): self.extendedCopy = True else: self.finish(cont=True)