def reCreateRevolveObj(self, angle): try: # Create the Revolution # remove totally the second face, not required anymore. startY = self.wheelObj.w_parent.w_lastEventXYZ.Qt_y startX = self.wheelObj.w_parent.w_lastEventXYZ.Qt_x self.newObject = App.ActiveDocument.addObject( "Part::Revolution", "ExtendRotate") App.ActiveDocument.removeObject(self.ExtractedFaces[1].Name) self.ExtractedFaces[1] = None # to allow the creation other wise you get OCCT error, angl<>0 self.newObject.Angle = angle self.newObject.Solid = True self.newObject.Symmetric = False self.newObject.Source = self.ExtractedFaces[0] nor = faced.getNormalized(self.ExtractedFaces[0]) bas = faced.getBase(self.ExtractedFaces[0]) self.newObject.Base = bas self.newObject.Axis = nor # Try this .. might be correct self.wheelObj.w_Rotation[0] = nor.x self.wheelObj.w_Rotation[1] = nor.y self.wheelObj.w_Rotation[2] = nor.z except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError("'create revolve -Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def __del__(self): """ class destructor Remove all objects from memory even fr_coinwindow """ faced.EnableAllToolbar(True) try: self.smartInd.hide() self.smartInd.__del__() # call destructor if self._mywin is not None: self._mywin.hide() del self._mywin self._mywin = None App.ActiveDocument.commitTransaction() # undo reg. self.extrudeLength = 0 self.OperationOption = 0 self.selectedObj = None self.targetFace = None self.newObject = None del self except Exception as err: App.Console.PrintError("'Design456_Extrude' __del__-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def callback_release(userData: fr_degreewheel_widget.userDataObject = None): """ Callback after releasing the left mouse button. This callback will finalize the Extrude operation. Deleting the original object will be done when the user press 'OK' button """ try: print("release callback") if (userData is None): print("userData is None") raise TypeError events = userData.events linktocaller = userData.callerObject # Avoid activating this part several times, if (linktocaller.startVector is None): return print("mouse release") userData.wheelObj.remove_focus() linktocaller.run_Once = False App.ActiveDocument.recompute() linktocaller.startVector = None App.ActiveDocument.commitTransaction() # undo reg. except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError( "'Design456_ExtrudeRotate' Callback Release Filed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def __del__(self): """ class destructor Remove all objects from memory even fr_coinwindow """ faced.EnableAllToolbar(True) try: self.wheelObj.hide() if (self.radioMerge.isChecked()): fusion = App.ActiveDocument.addObject("Part::MultiFuse", "Fusion") fusion.Shapes = [self.newObject, self.selectedObj.Object] fusion.Refine = True App.ActiveDocument.recompute() self.wheelObj.__del__() # call destructor if self._mywin is not None: self._mywin.hide() del self._mywin self._mywin = None self.editing = False App.ActiveDocument.recompute() App.ActiveDocument.commitTransaction() # undo reg. self.mw = None self.dialog = None self.tab = None self.wheelObj = None self._mywin = None self.b1 = None self.ExtrudeLBL = None self.run_Once = False self.endVector = None self.startVector = None self.extrudeLength = 0.0 # We will make two object, one for visual effect and the other is the original self.selectedObj = None self.selected = None self.direction = None self.setupRotation = [0, 0, 0, 0] # Used only with the center (cylinder) self.Rotation = [0, 0, 0, 0] # We use this to simplify the code - for both, 2D and 3D object, the face variable is this self.newObject = None self.mouseOffset = App.Vector(0, 0, 0) self.OperationOption = 0 # default is zero self.objChangedTransparency.clear() self.ExtractedFaces = [] self.FirstLocation = None self.isItRotation = False del self except Exception as err: App.Console.PrintError( "'Design456_ExtrudeRotate' ExtractFace-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def getArrowPosition(self): """" Find out the vector and rotation of the arrow to be drawn. """ # For now the arrow will be at the top try: rotation = [0.0, 0.0, 0.0, 0.0] face1 = None if (self.WasFaceFrom3DObject): # The whole object is selected sub1 = self.selectedObj face1 = sub1.SubObjects[0] print("face1 testme") else: face1 = self.selectedObj.Object.Shape.Faces[0] print("face2 testme") self.extrudeLength = 5 self._vector = self.calculateNewVector() self.extrudeLength = 0.0 if (face1.Surface.Rotation is None): plr = plDirection = App.Placement() # section direction. When the face doesn't have a Rotation yL = face1.CenterOfMass uv = face1.Surface.parameter(yL) nv = face1.normalAt(uv[0], uv[1]) direction = yL.sub(nv + yL) r = App.Rotation(App.Vector(0, 0, 1), direction) plDirection.Base = yL plDirection.Rotation.Q = r.Q plr = plDirection rotation = (plr.Rotation.Axis.x, plr.Rotation.Axis.y, plr.Rotation.Axis.z, math.degrees(plr.Rotation.Angle)) print("No rotation") else: rotation = (face1.Surface.Rotation.Axis.x, face1.Surface.Rotation.Axis.y, face1.Surface.Rotation.Axis.z, math.degrees(face1.Surface.Rotation.Angle)) # TODO: This if statement is not totally correct. # Cylinder or curved surfaces cause an error in the noramlAt, angle and direction # I leave it like that now and I must target this later. if rotation == (0, 0, 1, 180) or rotation == (0, 0, 1, 0): rotation = (0, 1.0, 0, 90) return rotation except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError( "'Design456_Extrude' getArrowPosition-Failed" "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def calculateNewVector(self): """[Calculate the new position that will be used for the arrow drawing] Returns: [App.Vector]: [Position where the arrow will be moved to] """ try: if (self.WasFaceFrom3DObject): ss = self.selectedObj.SubObjects[0] else: ss = self.selectedObj.Object.Shape if hasattr(ss, "CenterOfMass"): yL = ss.CenterOfMass uv = ss.Surface.parameter(yL) nv = ss.normalAt(uv[0], uv[1]) elif hasattr(ss.SubObjects[0], "CenterOfMass"): yL = ss.SubObjects[0].CenterOfMass uv = ss.SubObjects[0].Surface.parameter(yL) nv = ss.SubObjects[0].normalAt(uv[0], uv[1]) else: yL = self.selectedObj.Object.Shape.Faces[ 0].centerOfMass #TODO This is wrong. FIXME: Don't know when and why this happens uv = self.selectedObj.Object.Shape.Faces[0].Surface.parameter( yL) nv = self.selectedObj.Object.Shape.Faces[0].normalAt( uv[0], uv[1]) print("oh no it is wrong") self.normalVector = nv if (self.extrudeLength == 0): d = self.extrudeLength = 1 else: d = self.extrudeLength point = yL + d * nv return ([point, App.Vector(0, 0, 0)]) # Must be two vectors always except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError( "'Design456_Extrude' calculateNewVector-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def extractFaces(self): """[Extract a face from a 3D object as it cannot be extruded otherwise] Returns: [Face]: [Face created from the selected face of the 3D object] """ try: name = self.selectedObj.SubElementNames[0] print(name) # TODO: THIS PART MIGHT FAIL TAKE ALL KIND OF 3D OBJECT TOO SEE IF HASATTR Subobject and then fix that sh = self.selectedObj.Object.Shape.copy() o = App.ActiveDocument.addObject("Part::Feature", "BaseFace") o.Shape = sh.getElement(name) self.ExtractedFaces.append( Gui.ActiveDocument.getObject(o.Label).Object) o = App.ActiveDocument.addObject("Part::Feature", "MovableFace") o.Shape = sh.getElement(name) self.ExtractedFaces.append( Gui.ActiveDocument.getObject(o.Label).Object) if hasattr(self.selectedObj.Object, "getGlobalPlacement"): gpl = self.selectedObj.Object.getGlobalPlacement() self.ExtractedFaces[0].Placement = gpl self.ExtractedFaces[1].Placement = gpl else: pass # TODO: WHAT SHOULD WE DO HERE ? print("error") App.ActiveDocument.recompute() except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError( "'Design456_ExtrudeRotate' ExtractFace-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
def getMainWindow(self): """[Create the tab for the tool] Raises: Exception: [If no tabs were found] Exception: [If something unusual happen] Returns: [dialog]: [the new dialog which will be added as a tab to the tab section of FreeCAD] """ try: toplevel = QtGui.QApplication.topLevelWidgets() self.mw = None for i in toplevel: if i.metaObject().className() == "Gui::MainWindow": self.mw = i if self.mw is None: raise Exception("No main window found") dw = self.mw.findChildren(QtGui.QDockWidget) for i in dw: if str(i.objectName()) == "Combo View": self.tab = i.findChild(QtGui.QTabWidget) elif str(i.objectName()) == "Python Console": self.tab = i.findChild(QtGui.QTabWidget) if self.tab is None: raise Exception("No tab widget found") oldsize = self.tab.count() self.dialog = QtGui.QDialog() self.tab.addTab(self.dialog, "Smart Extrude Rotate") self.frmRotation = QtGui.QFrame(self.dialog) self.dialog.resize(200, 450) self.frmRotation.setGeometry(QtCore.QRect(10, 190, 231, 181)) self.frame_2 = QtGui.QFrame(self.dialog) self.frame_2.setGeometry(QtCore.QRect(10, 195, 231, 151)) self.frame_2.setFrameShape(QtGui.QFrame.StyledPanel) self.frame_2.setFrameShadow(QtGui.QFrame.Sunken) self.frame_2.setObjectName("frame_2") self.gridLayoutWidget_3 = QtGui.QWidget(self.frame_2) self.gridLayoutWidget_3.setGeometry(QtCore.QRect(10, 40, 211, 101)) self.gridLayoutWidget_3.setObjectName("gridLayoutWidget_3") self.gridExtrusionResult = QtGui.QGridLayout( self.gridLayoutWidget_3) self.gridExtrusionResult.setContentsMargins(0, 0, 0, 0) self.gridExtrusionResult.setObjectName("gridExtrusionResult") self.radioAsIs = QtGui.QRadioButton(self.gridLayoutWidget_3) self.radioAsIs.setObjectName("radioAsIs") self.gridExtrusionResult.addWidget(self.radioAsIs, 0, 0, 1, 1) self.radioMerge = QtGui.QRadioButton(self.gridLayoutWidget_3) self.radioMerge.setObjectName("radioMerge") self.gridExtrusionResult.addWidget(self.radioMerge, 1, 0, 1, 1) self.lblExtrusionResult = QtGui.QLabel(self.frame_2) self.lblExtrusionResult.setGeometry(QtCore.QRect(10, 0, 191, 61)) font = QtGui.QFont() font.setPointSize(10) self.lblExtrusionResult.setFont(font) self.lblExtrusionResult.setObjectName("lblExtrusionResult") self.btnOK = QtGui.QDialogButtonBox(self.dialog) self.btnOK.setGeometry(QtCore.QRect(270, 360, 111, 61)) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.btnOK.setFont(font) self.btnOK.setObjectName("btnOK") self.btnOK.setStandardButtons(QtGui.QDialogButtonBox.Ok) self.lblTitle = QtGui.QLabel(self.dialog) self.lblTitle.setGeometry(QtCore.QRect(10, 10, 281, 91)) font = QtGui.QFont() font.setFamily("Times New Roman") font.setPointSize(10) self.lblTitle.setFont(font) self.lblTitle.setObjectName("lblTitle") self.ExtrudeLBL = QtGui.QLabel(self.dialog) self.ExtrudeLBL.setGeometry(QtCore.QRect(10, 145, 321, 40)) font = QtGui.QFont() font.setPointSize(10) self.ExtrudeLBL.setFont(font) self.ExtrudeLBL.setObjectName("ExtrudeLBL") self.RotateLBL = QtGui.QLabel(self.dialog) self.RotateLBL.setGeometry(QtCore.QRect(10, 100, 281, 40)) font = QtGui.QFont() font.setPointSize(10) self.RotateLBL.setFont(font) self.RotateLBL.setObjectName("RotateLBL") _translate = QtCore.QCoreApplication.translate self.dialog.setWindowTitle( _translate("Dialog", "Smart Extrude Rotate")) self.radioAsIs.setText(_translate("Dialog", "As Is")) self.radioMerge.setText(_translate("Dialog", "Merge")) self.lblExtrusionResult.setText( _translate("Dialog", "Extrusion Result")) self.lblTitle.setText( _translate( "Dialog", "(Smart Extrude Rotate)\n" "For quicker applying Extrude")) self.ExtrudeLBL.setText(_translate("Dialog", "Extrusion Length=")) self.RotateLBL.setText(_translate("Dialog", "Extrusion Angle=")) self.radioAsIs.setChecked(True) # self.radioBottom.setChecked(True) self.radioAsIs.toggled.connect( lambda: self.btnState(self.radioAsIs)) self.radioMerge.toggled.connect( lambda: self.btnState(self.radioMerge)) QtCore.QObject.connect(self.btnOK, QtCore.SIGNAL("accepted()"), self.hide) QtCore.QMetaObject.connectSlotsByName(self.dialog) self.tab.setCurrentWidget(self.dialog) return self.dialog except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError( "'Design456_ExtrudeRotate' ExtractFace-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def Activated(self): """[ Executes when the tool is used ] """ import ThreeDWidgets.fr_coinwindow as win try: print("Smart ExtrudeRotate") self.selected = Gui.Selection.getSelectionEx() if len(self.selected) == 0: # An object must be selected errMessage = "Select an object, one face to Extrude" faced.errorDialog(errMessage) return self.selectedObj = self.selected[0] faced.EnableAllToolbar(False) self.faceDir = faced.getDirectionAxis( self.selected) # face direction # Undo App.ActiveDocument.openTransaction( translate("Design456", "SmartExtrudeRotate")) self.ExtractedFaces.clear() if self.isFaceOf3DObj( ): # We must know if the selection is a 2D face or a face from a 3D object # We have a 3D Object. Extract a face and start to Extrude self.extractFaces() else: # We have a 2D Face - Extract it directly sh = self.selectedObj.Object.Shape.copy() o = App.ActiveDocument.addObject("Part::Feature", "MovableFace") o.Shape = sh self.ExtractedFaces.append(self.selectedObj.Object) self.ExtractedFaces.append(App.ActiveDocument.getObject( o.Name)) facingdir = self.faceDir.upper() facingdir = facingdir[1:] print(facingdir, "facingdir") # Decide how the Degree Wheel be drawn self.setupRotation = self.calculateNewVector() if self.faceDir == "+z" or self.faceDir == "-z": self.wheelObj = Fr_DegreeWheel_Widget( [self.FirstLocation, App.Vector(0, 0, 0)], str(round(self.w_rotation[3], 2)) + "°", 1, FR_COLOR.FR_RED, [0, 0, 0, 0], self.setupRotation, [2.0, 2.0, 2.0], 2, facingdir) else: self.wheelObj = Fr_DegreeWheel_Widget( [self.FirstLocation, App.Vector(0, 0, 0)], str(round(self.w_rotation[3], 2)) + "°", 1, FR_COLOR.FR_RED, [0, 0, 0, 0], self.setupRotation, [2.0, 2.0, 2.0], 1, facingdir) # Define the callbacks. We have many callbacks here. # TODO: FIXME: # Different callbacks for each action. self.wheelObj.w_wheel_cb_ = callback_Rotate self.wheelObj.w_xAxis_cb_ = callback_moveX self.wheelObj.w_yAxis_cb_ = callback_moveY self.wheelObj.w_45Axis_cb_ = callback_move45 self.wheelObj.w_135Axis_cb_ = callback_move135 self.wheelObj.w_callback_ = callback_release self.wheelObj.w_userData.callerObject = self self.newObject = App.ActiveDocument.addObject( 'Part::Loft', 'ExtendFace') self.newObject.Sections = self.ExtractedFaces self.newObject.Solid = True self.newObject.Ruled = False # TODO: SHOULD THIS BE RULED? self.newObject.Closed = False # TODO: SHOULD THIS BE CLOSED? self.ExtractedFaces[0].Visibility = False self.ExtractedFaces[1].Visibility = False if self._mywin is None: self._mywin = win.Fr_CoinWindow() self._mywin.addWidget(self.wheelObj) mw = self.getMainWindow() self._mywin.show() # TODO: FIXME: # loft will be used . make some experementations. # But when should we use sweep???? don't know now App.ActiveDocument.recompute() except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError( "'Design456_ExtrudeRotate' ExtractFace-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def calculateNewVector(self): """[Calculate the new position that will be used for the Wheel drawing] Returns: [App.Vector]: [Position where the Wheel will be moved to] """ # For now the Wheel will be at the top rotAxis = App.Vector(0, 0, 0) # Axis of the rotation for face2 faceAngle = 0 # New angle due to the rotation of face2 # New location for Face2 due to the rotation of the face base = App.Vector(0, 0, 0) try: # TODO:FIXME pl = self.calculateRotatedNormal(self.direction) if (self.ExtractedFaces[1] is not None): self.ExtractedFaces[1].Placement = pl face2 = None if (self.isFaceOf3DObj()): # The whole object is selected sub1 = self.ExtractedFaces[1] face2 = sub1.Shape else: face2 = self.ExtractedFaces[1].Shape yL = face2.CenterOfMass uv = face2.Surface.parameter(yL) nv = face2.normalAt(uv[0], uv[1]) self.normalVector = nv # Setup calculation. if (face2.Surface.Rotation is None): calAn = math.degrees(nv.getAngle(App.Vector(1, 1, 0))) rotation = [0, 0, 1, calAn] else: rotation = [ face2.Surface.Rotation.Axis.x, face2.Surface.Rotation.Axis.y, face2.Surface.Rotation.Axis.z, math.degrees(face2.Surface.Rotation.Angle) ] if (self.extrudeLength == 0): d = self.extrudeLength = 1 else: d = self.extrudeLength # The face itself self.ExtractedFaces[ 1].Placement.Base = face2.Placement.Base + d * nv if (self.wheelObj is not None): self.wheelObj.w_vector[0] = yL + d * nv # the wheel self.FirstLocation = yL + d * nv # the wheel App.ActiveDocument.recompute() return rotation except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError("'ExtractFace getWheelPosition-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def getMainWindow(self): """[Create the tab for the tool] Raises: Exception: [If no tabs were found] Exception: [If something unusual happen] Returns: [dialog]: [the new dialog which will be added as a tab to the tab section of FreeCAD] """ try: toplevel = QtGui.QApplication.topLevelWidgets() self.mw = None for i in toplevel: if i.metaObject().className() == "Gui::MainWindow": self.mw = i if self.mw is None: raise Exception("No main window found") dw = self.mw.findChildren(QtGui.QDockWidget) for i in dw: if str(i.objectName()) == "Combo View": self.tab = i.findChild(QtGui.QTabWidget) elif str(i.objectName()) == "Python Console": self.tab = i.findChild(QtGui.QTabWidget) if self.tab is None: raise Exception("No tab widget found") self.dialog = QtGui.QDialog() oldsize = self.tab.count() self.tab.addTab(self.dialog, "Smart Extrude") self.tab.setCurrentWidget(self.dialog) self.dialog.resize(200, 450) self.dialog.setWindowTitle("Smart Extrude") self.la = QtGui.QVBoxLayout(self.dialog) self.e1 = QtGui.QLabel( "(Smart Extrude)\nFor quicker\nApplying Extrude") commentFont = QtGui.QFont("Times", 14, True) self.ExtrudeLBL = QtGui.QLabel("Extrude Length=") self.e1.setFont(commentFont) okbox = QtGui.QDialogButtonBox(self.dialog) okbox.setOrientation(QtCore.Qt.Horizontal) okbox.setStandardButtons(QtGui.QDialogButtonBox.Ok) self.lblExtrudeSize = QtGui.QLabel("Extrude Step Size = " + str(self.ExtrusionStepSize)) self.lblExtrudeSize.setObjectName("lblExtrudeSize") comboFont = QtGui.QFont("Times", 13, True) self.lblExtrudeSize.setFont(comboFont) self.combListExtrudeStep = QtGui.QComboBox(self.dialog) self.combListExtrudeStep.addItem("0.1mm") # 0.1 mm self.combListExtrudeStep.addItem("0.5mm") # 0.5 mm self.combListExtrudeStep.addItem("1.0mm") # 1.0 mm self.combListExtrudeStep.addItem("10mm") # 1 cm self.combListExtrudeStep.addItem("100mm") # 10 cm self.combListExtrudeStep.addItem("1000mm") # 100 cm self.combListExtrudeStep.addItem("10000mm") # 10 m self.combListExtrudeStep.addItem("100000mm") # 100 m self.combListExtrudeStep.setCurrentIndex(2) #self.combListExtrudeStep.move (10, 400) self.combListExtrudeStep.activated[str].connect(self.comboChanged) self.combListExtrudeStep.setObjectName("combListExtrudeStep") self.groupBox = QtGui.QGroupBox(self.dialog) self.groupBox.setGeometry(QtCore.QRect(60, 130, 120, 80)) self.groupBox.setObjectName("Extrusion Type") self.radAsIs = QtGui.QRadioButton(self.groupBox) self.radAsIs.setObjectName("radAsIs") self.radAsIs.setText("As Is") self.radMerge = QtGui.QRadioButton(self.groupBox) self.radMerge.setObjectName("radMerge") self.radMerge.setText("Merge") self.radSubtract = QtGui.QRadioButton(self.groupBox) self.radSubtract.setObjectName("radSubtract") self.radSubtract.setText("Subtract") self.la.addWidget(self.e1) self.la.addWidget(self.ExtrudeLBL) self.la.addWidget(self.lblExtrudeSize) self.la.addWidget(self.combListExtrudeStep) self.la.addWidget(okbox) # Adding checkbox for Merge, Subtract Or just leave it "As is" self.la.addWidget(self.radAsIs) self.la.addWidget(self.radMerge) self.la.addWidget(self.radSubtract) self.radAsIs.setChecked(True) self.radAsIs.toggled.connect(lambda: self.btnState(self.radAsIs)) self.radMerge.toggled.connect(lambda: self.btnState(self.radMerge)) self.radSubtract.toggled.connect( lambda: self.btnState(self.radSubtract)) QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.hide) QtCore.QMetaObject.connectSlotsByName(self.dialog) return self.dialog except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError("'Design456_Extrude' getMainWindow-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def Activated(self): """[Executes when the tool is used] """ import ThreeDWidgets.fr_coinwindow as win try: print("Smart Extrusion") sel = Gui.Selection.getSelectionEx() if len(sel) == 0: # An object must be selected errMessage = "Select a face to Extrude" faced.errorDialog(errMessage) return self.selectedObj = sel[0] # Whole object is selected TODO: FIXME: Check if this works always. if len(self.selectedObj.SubObjects) == 0: errMessage = "Select a face to Extrude" faced.errorDialog(errMessage) return faced.EnableAllToolbar(False) # Undo App.ActiveDocument.openTransaction( translate("Design456", "SmartExtrude")) self.WasFaceFrom3DObject = self.isFaceOf3DObj() if self.WasFaceFrom3DObject is True: # We must know if the selection is a 2D face or a face from a 3D object # We have a 3D Object. Extract a face and start to Extrude self.targetFace = self.extractFace() else: # We have a 2D Face - Extract it directly self.targetFace = self.selectedObj.Object rotation = self.getArrowPosition() self.smartInd = Fr_Arrow_Widget(self._vector, [ " Length 0.0", ], 1, FR_COLOR.FR_RED, FR_COLOR.FR_WHITE, rotation, [1.2, 1.2, 1.2], 3, 0.0) self.smartInd.w_callback_ = callback_release self.smartInd.w_move_callback_ = callback_move self.smartInd.w_userData.callerObject = self if self._mywin is None: self._mywin = win.Fr_CoinWindow() self._mywin.addWidget(self.smartInd) mw = self.getMainWindow() self._mywin.show() self.newObject = App.ActiveDocument.addObject( 'Part::Extrusion', 'Extrude') self.newObject.Base = self.targetFace self.newObject.DirMode = "Normal" # Don't use Custom as it causes a PROBLEM! # Above statement is not always correct. Some faces require 'custom' self.newObject.DirLink = None self.newObject.LengthFwd = self.extrudeLength # Must be negative self.newObject.LengthRev = 0.0 self.newObject.Solid = True self.newObject.Reversed = False self.newObject.Symmetric = False self.newObject.TaperAngle = 0.0 self.newObject.TaperAngleRev = 0.0 self.newObject.Dir = Gui.ActiveDocument.getObject( self.targetFace.Name).Object.Shape.Faces[0].normalAt(0, 0) if (self.newObject.Dir.x != 1 or self.newObject.Dir.y != 1 or self.newObject.Dir.z != 1): self.newObject.DirMode = "Custom" App.ActiveDocument.recompute() except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError("'Design456_Extrude' Activated-Failed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)
def callback_release(userData: fr_arrow_widget.userDataObject = None): """ Callback after releasing the left mouse button. This callback will finalize the Extrude operation. Deleting the original object will be done when the user press 'OK' button """ try: if (userData is None): print("userData is None") raise TypeError ArrowObject = userData.ArrowObj linktocaller = userData.callerObject # Avoid activating this part several times, if (linktocaller.startVector is None): return ArrowObject.remove_focus() linktocaller.run_Once = False linktocaller.endVector = App.Vector( ArrowObject.w_parent.w_lastEventXYZ.Coin_x, ArrowObject.w_parent.w_lastEventXYZ.Coin_y, ArrowObject.w_parent.w_lastEventXYZ.Coin_z) # Undo App.ActiveDocument.openTransaction( translate("Design456", "SmartExtrude")) App.ActiveDocument.recompute() linktocaller.startVector = None App.ActiveDocument.commitTransaction() # undo reg. newObjcut = [] # Do final operation. Either leave it as it is, merge or subtract if (linktocaller.OperationOption == 1): createFusionObjectBase(linktocaller) App.ActiveDocument.recompute() # subtraction will continue to work here elif linktocaller.OperationOption == 2: # Subtraction is complex. I have to cut from each object the same extruded part. if (linktocaller.objChangedTransparency != []): base = createFusionObjectBase(linktocaller) # Create a cut object for each transparency object if (linktocaller.WasFaceFrom3DObject is True): # It is a 3D drawing object tool = createFusionObjectTool(linktocaller) for i in range(0, len(linktocaller.objChangedTransparency)): newObjcut.append( App.ActiveDocument.addObject( "Part::Cut", "CUT" + str(i))) newObjcut[i].Base = base # Subtracted shape/object newObjcut[i].Tool = tool newObjcut[i].Refine = True tool.Visibility = False else: for i in range(0, len(linktocaller.objChangedTransparency)): newObjcut.append( App.ActiveDocument.addObject( "Part::Cut", "CUT" + str(i))) newObjcut[i].Base = base # Subtracted shape/object newObjcut[i].Tool = linktocaller.newObject newObjcut[i].Refine = True App.ActiveDocument.recompute() elif linktocaller.OperationOption == 0: # is here just to make the code more readable. pass # nothing to do . App.ActiveDocument.recompute() App.ActiveDocument.commitTransaction() # undo reg. except Exception as err: faced.EnableAllToolbar(True) App.Console.PrintError("'Design456_Extrude' Release Filed. " "{err}\n".format(err=str(err))) exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print(exc_type, fname, exc_tb.tb_lineno)