def getPrincipalAx(self, ax='Z'): self.deleteArrow() from Part import Edge, Line O = FreeCAD.Vector() l = Line(O, FreeCAD.Vector(0, 0, 1000)) if ax == 'X': l = Line(O, FreeCAD.Vector(1000, 0, 0)) elif ax == 'Y': l = Line(O, FreeCAD.Vector(0, 1000, 0)) self.Axis = Edge(l) self.form.lab1.setText("Principal: " + ax)
def selectAction(self): edged = [ objex for objex in FreeCADGui.Selection.getSelectionEx() if frameCmd.edges([objex]) ] if edged: self.Axis = frameCmd.edges([edged[0]])[0] self.deleteArrow() from polarUtilsCmd import arrow where = FreeCAD.Placement() where.Base = self.Axis.valueAt(self.Axis.LastParameter) where.Rotation = FreeCAD.Rotation( FreeCAD.Vector(0, 0, 1), self.Axis.tangentAt(self.Axis.LastParameter)) size = [ self.Axis.Length / 20.0, self.Axis.Length / 10.0, self.Axis.Length / 20.0 ] self.arrow = arrow(pl=where, scale=size, offset=self.Axis.Length / 10.0) if self.Axis.curvatureAt(0): O = self.Axis.centerOfCurvatureAt(0) n = self.Axis.tangentAt(0).cross(self.Axis.normalAt(0)) from Part import Edge, Line self.Axis = (Edge( Line(FreeCAD.Vector(O), FreeCAD.Vector(O + n)))) self.form.lab1.setText(edged[0].Object.Label + ": edge")
def selectAction(self): edged = [ objex for objex in FreeCADGui.Selection.getSelectionEx() if fCmd.edges([objex]) ] if edged: self.Axis = fCmd.edges([edged[0]])[0] self.deleteArrow() from uCmd import arrow where = FreeCAD.Placement() where.Base = self.Axis.valueAt(self.Axis.LastParameter) where.Rotation = FreeCAD.Rotation( FreeCAD.Vector(0, 0, 1), self.Axis.tangentAt(self.Axis.LastParameter)) obj = edged[ 0].Object #TARGET [solved]: make "where" deal with App::Parts if fCmd.isPartOfPart(obj): part = fCmd.isPartOfPart(obj) where = part.Placement.multiply(where) size = [ self.Axis.Length / 20.0, self.Axis.Length / 10.0, self.Axis.Length / 20.0 ] self.arrow = arrow(pl=where, scale=size, offset=self.Axis.Length / 10.0) if self.Axis.curvatureAt(0): O = self.Axis.centerOfCurvatureAt(0) n = self.Axis.tangentAt(0).cross(self.Axis.normalAt(0)) from Part import Edge, Line self.Axis = (Edge( Line(FreeCAD.Vector(O), FreeCAD.Vector(O + n)))) self.form.lab1.setText(edged[0].Object.Label + ": edge")
def getPrincipalAx(self, ax='Z'): self.deleteArrow() from Part import Edge,Line O=FreeCAD.Vector() l=Line(O,FreeCAD.Vector(0,0,1000)) if ax=='X': l=Line(O,FreeCAD.Vector(1000,0,0)) elif ax=='Y': l=Line(O,FreeCAD.Vector(0,1000,0)) self.Axis=Edge(l) self.form.lab1.setText("Principal: "+ax)
class rotateAroundForm(prototypeDialog): ''' Dialog for rotateTheBeamAround(). It allows to rotate one object around one edge or the axis of a circular edge (or one principal axis.) ''' def __init__(self): super(rotateAroundForm, self).__init__('rotAround.ui') self.form.edit1.setValidator(QDoubleValidator()) self.form.btn1.clicked.connect(self.selectAction) self.form.btn2.clicked.connect(self.reverse) self.form.btnX.clicked.connect(lambda: self.getPrincipalAx('X')) self.form.btnY.clicked.connect(lambda: self.getPrincipalAx('Y')) self.form.btnZ.clicked.connect(lambda: self.getPrincipalAx('Z')) self.form.dial.valueChanged.connect( lambda: self.form.edit1.setText(str(self.form.dial.value()))) self.form.edit1.editingFinished.connect( lambda: self.form.dial.setValue(int(self.form.edit1.text()))) self.Axis = None self.arrow = None self.selectAction() def accept(self, ang=None): if not ang: ang = float(self.form.edit1.text()) self.deleteArrow() objects = FreeCADGui.Selection.getSelection() if objects and self.Axis: FreeCAD.ActiveDocument.openTransaction('rotateTheBeamAround') for o in objects: if self.form.copyCB.isChecked(): FreeCAD.activeDocument().copyObject(o, True) frameCmd.rotateTheBeamAround(o, self.Axis, ang) FreeCAD.ActiveDocument.commitTransaction() def reverse(self): ang = float(self.form.edit1.text()) * -1 self.form.edit1.setText('%.0f' % ang) self.form.dial.setValue(int(self.form.edit1.text())) self.accept(ang * 2) def getPrincipalAx(self, ax='Z'): self.deleteArrow() from Part import Edge, Line O = FreeCAD.Vector() l = Line(O, FreeCAD.Vector(0, 0, 1000)) if ax == 'X': l = Line(O, FreeCAD.Vector(1000, 0, 0)) elif ax == 'Y': l = Line(O, FreeCAD.Vector(0, 1000, 0)) self.Axis = Edge(l) self.form.lab1.setText("Principal: " + ax) def selectAction(self): edged = [ objex for objex in FreeCADGui.Selection.getSelectionEx() if frameCmd.edges([objex]) ] if edged: self.Axis = frameCmd.edges([edged[0]])[0] self.deleteArrow() from polarUtilsCmd import arrow where = FreeCAD.Placement() where.Base = self.Axis.valueAt(self.Axis.LastParameter) where.Rotation = FreeCAD.Rotation( FreeCAD.Vector(0, 0, 1), self.Axis.tangentAt(self.Axis.LastParameter)) size = [ self.Axis.Length / 20.0, self.Axis.Length / 10.0, self.Axis.Length / 20.0 ] self.arrow = arrow(pl=where, scale=size, offset=self.Axis.Length / 10.0) if self.Axis.curvatureAt(0): O = self.Axis.centerOfCurvatureAt(0) n = self.Axis.tangentAt(0).cross(self.Axis.normalAt(0)) from Part import Edge, Line self.Axis = (Edge( Line(FreeCAD.Vector(O), FreeCAD.Vector(O + n)))) self.form.lab1.setText(edged[0].Object.Label + ": edge") def deleteArrow(self): if self.arrow: self.arrow.closeArrow() self.arrow = None def reject(self): # redefined to remove arrow from scene try: self.view.removeEventCallback('SoEvent', self.call) except: pass self.deleteArrow() FreeCADGui.Control.closeDialog()
class rotateAroundForm(prototypeDialog): ''' Dialog for rotateTheBeamAround(). It allows to rotate one object around one edge or the axis of a circular edge (or one principal axis.) ''' def __init__(self): super(rotateAroundForm,self).__init__('rotAround.ui') self.form.edit1.setValidator(QDoubleValidator()) self.form.btn1.clicked.connect(self.selectAction) self.form.btn2.clicked.connect(self.reverse) self.form.btnX.clicked.connect(lambda: self.getPrincipalAx('X')) self.form.btnY.clicked.connect(lambda: self.getPrincipalAx('Y')) self.form.btnZ.clicked.connect(lambda: self.getPrincipalAx('Z')) self.form.dial.valueChanged.connect(lambda: self.form.edit1.setText(str(self.form.dial.value()))) self.form.edit1.editingFinished.connect(lambda: self.form.dial.setValue(int(self.form.edit1.text()))) self.Axis=None self.arrow=None self.selectAction() def accept(self, ang=None): if not ang: ang=float(self.form.edit1.text()) self.deleteArrow() objects=FreeCADGui.Selection.getSelection() if objects and self.Axis: FreeCAD.ActiveDocument.openTransaction('rotateTheBeamAround') for o in objects: if self.form.copyCB.isChecked(): FreeCAD.activeDocument().copyObject(o,True) frameCmd.rotateTheBeamAround(o,self.Axis,ang) FreeCAD.ActiveDocument.commitTransaction() def reverse(self): ang=float(self.form.edit1.text())*-1 self.form.edit1.setText('%.0f'%ang) self.form.dial.setValue(int(self.form.edit1.text())) self.accept(ang*2) def getPrincipalAx(self, ax='Z'): self.deleteArrow() from Part import Edge,Line O=FreeCAD.Vector() l=Line(O,FreeCAD.Vector(0,0,1000)) if ax=='X': l=Line(O,FreeCAD.Vector(1000,0,0)) elif ax=='Y': l=Line(O,FreeCAD.Vector(0,1000,0)) self.Axis=Edge(l) self.form.lab1.setText("Principal: "+ax) def selectAction(self): edged = [objex for objex in FreeCADGui.Selection.getSelectionEx() if frameCmd.edges([objex])] if edged: self.Axis=frameCmd.edges([edged[0]])[0] self.deleteArrow() from polarUtilsCmd import arrow where=FreeCAD.Placement() where.Base=self.Axis.valueAt(self.Axis.LastParameter) where.Rotation=FreeCAD.Rotation(FreeCAD.Vector(0,0,1),self.Axis.tangentAt(self.Axis.LastParameter)) size=[self.Axis.Length/20.0,self.Axis.Length/10.0,self.Axis.Length/20.0] self.arrow=arrow(pl=where,scale=size,offset=self.Axis.Length/10.0) if self.Axis.curvatureAt(0): O=self.Axis.centerOfCurvatureAt(0) n=self.Axis.tangentAt(0).cross(self.Axis.normalAt(0)) from Part import Edge, Line self.Axis=(Edge(Line(FreeCAD.Vector(O),FreeCAD.Vector(O+n)))) self.form.lab1.setText(edged[0].Object.Label+": edge") def deleteArrow(self): if self.arrow: self.arrow.closeArrow() self.arrow=None def reject(self): # redefined to remove arrow from scene self.deleteArrow() #try: self.view.removeEventCallback('SoEvent',self.call) #except: pass #if FreeCAD.ActiveDocument: FreeCAD.ActiveDocument.recompute() #FreeCADGui.Control.closeDialog() super(rotateAroundForm,self).reject()