diff --git a/src/Mod/Part/BOPTools/SplitFeatures.py b/src/Mod/Part/BOPTools/SplitFeatures.py index c7bcc41433..ace3463e56 100644 --- a/src/Mod/Part/BOPTools/SplitFeatures.py +++ b/src/Mod/Part/BOPTools/SplitFeatures.py @@ -33,9 +33,9 @@ if FreeCAD.GuiUp: import FreeCADGui from PySide import QtCore, QtGui -#-------------------------- translation-related code ---------------------------------------- -#(see forum thread "A new Part tool is being born... JoinFeatures!" -#http://forum.freecadweb.org/viewtopic.php?f=22&t=11112&start=30#p90239 ) +# -------------------------- translation-related code ------------------------- +# See forum thread "A new Part tool is being born... JoinFeatures!" +# http://forum.freecadweb.org/viewtopic.php?f=22&t=11112&start=30#p90239 try: _fromUtf8 = QtCore.QString.fromUtf8 except Exception: @@ -48,30 +48,38 @@ if FreeCAD.GuiUp: except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) -#--------------------------/translation-related code ---------------------------------------- +#--------------------------/translation-related code -------------------------- + def getIconPath(icon_dot_svg): return icon_dot_svg -# -------------------------- /common stuff -------------------------------------------------- +# -------------------------- /common stuff ------------------------------------ -# -------------------------- BooleanFragments -------------------------------------------------- +# -------------------------- BooleanFragments --------------------------------- def makeBooleanFragments(name): '''makeBooleanFragments(name): makes an BooleanFragments object.''' - obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) + obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name) FeatureBooleanFragments(obj) if FreeCAD.GuiUp: ViewProviderBooleanFragments(obj.ViewObject) return obj + class FeatureBooleanFragments: - "The BooleanFragments feature object" + """The BooleanFragments feature object.""" + def __init__(self,obj): obj.addProperty("App::PropertyLinkList","Objects","BooleanFragments","Object to compute intersections between.") - obj.addProperty("App::PropertyEnumeration","Mode","BooleanFragments","Standard: wires, shells, compsolids remain in one piece. Split: wires, shells, compsolids are split. CompSolid: make compsolid from solid fragments.") + obj.addProperty("App::PropertyEnumeration","Mode","BooleanFragments", + "- Standard: wires, shells, compsolids remain in one piece.\n" + "- Split: wires, shells, compsolids are split.\n" + "- CompSolid: make compsolid from solid fragments.") obj.Mode = ["Standard", "Split", "CompSolid"] - obj.addProperty("App::PropertyLength","Tolerance","BooleanFragments","Tolerance when intersecting (fuzzy value). In addition to tolerances of the shapes.") + obj.addProperty("App::PropertyLength","Tolerance","BooleanFragments", + "Tolerance when intersecting (fuzzy value). " + "In addition to tolerances of the shapes.") obj.Proxy = self self.Type = "FeatureBooleanFragments" @@ -81,12 +89,12 @@ class FeatureBooleanFragments: if len(shapes) == 1 and shapes[0].ShapeType == "Compound": shapes = shapes[0].childShapes() if len(shapes) < 2: - raise ValueError("At least two shapes are needed for computing boolean fragments. Got only {num}.".format(num= len(shapes))) + raise ValueError("At least two shapes are needed for computing boolean fragments. Got only {num}.".format(num=len(shapes))) selfobj.Shape = SplitAPI.booleanFragments(shapes, selfobj.Mode, selfobj.Tolerance) class ViewProviderBooleanFragments: - "A View Provider for the Part BooleanFragments feature" + """A View Provider for the Part BooleanFragments feature.""" def __init__(self,vobj): vobj.Proxy = self @@ -130,13 +138,14 @@ class ViewProviderBooleanFragments: def dropObject(self, selfvp, incoming_object): self.Object.Objects = self.Object.Objects + [incoming_object] + def cmdCreateBooleanFragmentsFeature(name, mode): """cmdCreateBooleanFragmentsFeature(name, mode): implementation of GUI command to create BooleanFragments feature (GFA). Mode can be "Standard", "Split", or "CompSolid".""" sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create Boolean Fragments") FreeCADGui.addModule("BOPTools.SplitFeatures") - FreeCADGui.doCommand("j = BOPTools.SplitFeatures.makeBooleanFragments(name= '{name}')".format(name= name)) + FreeCADGui.doCommand("j = BOPTools.SplitFeatures.makeBooleanFragments(name='{name}')".format(name=name)) FreeCADGui.doCommand("j.Objects = {sel}".format( sel= "[" + ", ".join(["App.ActiveDocument."+so.Object.Name for so in sel]) + "]" )) @@ -148,11 +157,15 @@ def cmdCreateBooleanFragmentsFeature(name, mode): except Exception as err: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(_translate("Part_SplitFeatures","Computing the result failed with an error: \n\n{err}\n\nClick 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) - .format(err= str(err))) + mb.setText(_translate("Part_SplitFeatures", + "Computing the result failed with an error:\n\n" + "{err}\n\n" + "Click 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) + .format(err=str(err))) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) - btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) + btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), + QtGui.QMessageBox.ButtonRole.ActionRole) mb.setDefaultButton(btnOK) mb.exec_() @@ -166,21 +179,31 @@ def cmdCreateBooleanFragmentsFeature(name, mode): FreeCAD.ActiveDocument.commitTransaction() + class CommandBooleanFragments: - "Command to create BooleanFragments feature" + """Command to create BooleanFragments feature.""" + def GetResources(self): - return {'Pixmap' : getIconPath("Part_BooleanFragments.svg"), - 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Boolean Fragments"), + return {'Pixmap': getIconPath("Part_BooleanFragments.svg"), + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Boolean fragments"), 'Accel': "", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Split objects where they intersect")} + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures", + "Create a 'Boolean Fragments' object from two or more selected objects,\n" + "or from the shapes inside a compound.\n" + "This is a boolean union which is then sliced at the intersections\n" + "of the original shapes.\n" + "A 'Compound Filter' can be used to extract the individual slices.")} def Activated(self): - if len(FreeCADGui.Selection.getSelectionEx()) >= 1 : - cmdCreateBooleanFragmentsFeature(name= "BooleanFragments", mode= "Standard") + if len(FreeCADGui.Selection.getSelectionEx()) >= 1: + cmdCreateBooleanFragmentsFeature(name="BooleanFragments", mode="Standard") else: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(_translate("Part_SplitFeatures", "Select at least two objects, or one or more compounds, first! If only one compound is selected, the compounded shapes will be intersected between each other (otherwise, compounds with self-intersections are invalid).", None)) + mb.setText(_translate("Part_SplitFeatures", + "Select at least two objects, or one or more compounds. " + "If only one compound is selected, the compounded shapes will be intersected between each other " + "(otherwise, compounds with self-intersections are invalid).", None)) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) mb.exec_() @@ -190,9 +213,9 @@ class CommandBooleanFragments: else: return False -# -------------------------- /BooleanFragments -------------------------------------------------- +# -------------------------- /BooleanFragments -------------------------------- -# -------------------------- Slice -------------------------------------------------- +# -------------------------- Slice -------------------------------------------- def makeSlice(name): '''makeSlice(name): makes an Slice object.''' @@ -202,14 +225,21 @@ def makeSlice(name): ViewProviderSlice(obj.ViewObject) return obj + class FeatureSlice: - "The Slice feature object" + """The Slice feature object.""" + def __init__(self,obj): obj.addProperty("App::PropertyLink","Base","Slice","Object to be sliced.") obj.addProperty("App::PropertyLinkList","Tools","Slice","Objects that slice.") - obj.addProperty("App::PropertyEnumeration","Mode","Slice","Standard: wires, shells, compsolids remain in one piece. Split: wires, shells, compsolids are split. CompSolid: make compsolid from solid fragments.") + obj.addProperty("App::PropertyEnumeration","Mode","Slice", + "- Standard: wires, shells, compsolids remain in one piece.\n" + "- Split: wires, shells, compsolids are split.\n" + "- CompSolid: make compsolid from solid fragments.") obj.Mode = ["Standard", "Split", "CompSolid"] - obj.addProperty("App::PropertyLength","Tolerance","Slice","Tolerance when intersecting (fuzzy value). In addition to tolerances of the shapes.") + obj.addProperty("App::PropertyLength","Tolerance","Slice", + "Tolerance when intersecting (fuzzy value). " + "In addition to tolerances of the shapes.") obj.Proxy = self self.Type = "FeatureSlice" @@ -217,11 +247,14 @@ class FeatureSlice: def execute(self,selfobj): if len(selfobj.Tools) < 1: raise ValueError("No slicing objects supplied!") - selfobj.Shape = SplitAPI.slice(selfobj.Base.Shape, [obj.Shape for obj in selfobj.Tools], selfobj.Mode, selfobj.Tolerance) + selfobj.Shape = SplitAPI.slice(selfobj.Base.Shape, + [obj.Shape for obj in selfobj.Tools], + selfobj.Mode, + selfobj.Tolerance) class ViewProviderSlice: - "A View Provider for the Part Slice feature" + """A View Provider for the Part Slice feature.""" def __init__(self,vobj): vobj.Proxy = self @@ -250,13 +283,13 @@ class ViewProviderSlice: FreeCAD.Console.PrintError("Error in onDelete: " + str(err)) return True -def cmdCreateSliceFeature(name, mode, transaction= True): +def cmdCreateSliceFeature(name, mode, transaction=True): """cmdCreateSliceFeature(name, mode): implementation of GUI command to create Slice feature. Mode can be "Standard", "Split", or "CompSolid".""" sel = FreeCADGui.Selection.getSelectionEx() if transaction: FreeCAD.ActiveDocument.openTransaction("Create Slice") FreeCADGui.addModule("BOPTools.SplitFeatures") - FreeCADGui.doCommand("f = BOPTools.SplitFeatures.makeSlice(name= '{name}')".format(name= name)) + FreeCADGui.doCommand("f = BOPTools.SplitFeatures.makeSlice(name='{name}')".format(name=name)) FreeCADGui.doCommand("f.Base = {sel}[0]\n" "f.Tools = {sel}[1:]".format( sel= "[" + ", ".join(["App.ActiveDocument."+so.Object.Name for so in sel]) + "]" @@ -269,11 +302,15 @@ def cmdCreateSliceFeature(name, mode, transaction= True): except Exception as err: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(_translate("Part_SplitFeatures","Computing the result failed with an error: \n\n{err}\n\nClick 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) - .format(err= str(err))) + mb.setText(_translate("Part_SplitFeatures", + "Computing the result failed with an error:\n\n" + "{err}\n\n" + "Click 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) + .format(err=str(err))) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) - btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) + btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), + QtGui.QMessageBox.ButtonRole.ActionRole) mb.setDefaultButton(btnOK) mb.exec_() @@ -290,7 +327,7 @@ def cmdCreateSliceFeature(name, mode, transaction= True): def cmdSliceApart(): FreeCAD.ActiveDocument.openTransaction("Slice apart") - made = cmdCreateSliceFeature(name= "Slice", mode= "Split", transaction= False) + made = cmdCreateSliceFeature(name="Slice", mode="Split", transaction=False) if made: FreeCADGui.addModule("CompoundTools.Explode") @@ -300,23 +337,30 @@ def cmdSliceApart(): FreeCADGui.doCommand("App.ActiveDocument.recompute()") else: FreeCAD.ActiveDocument.abortTransaction() - + class CommandSlice: - "Command to create Slice feature" + """Command to create Slice feature.""" + def GetResources(self): - return {'Pixmap' : getIconPath("Part_Slice.svg"), + return {'Pixmap': getIconPath("Part_Slice.svg"), 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Slice to compound"), 'Accel': "", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Split object by intersections with other objects, and pack the pieces into a compound.")} + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures", + "Slice a selected object by using other objects as cutting tools.\n" + "The resulting pieces will be stored in a compound.\n" + "A 'Compound Filter' can be used to extract the individual slices.")} def Activated(self): - if len(FreeCADGui.Selection.getSelectionEx()) > 1 : - cmdCreateSliceFeature(name= "Slice", mode= "Split") + if len(FreeCADGui.Selection.getSelectionEx()) > 1: + cmdCreateSliceFeature(name="Slice", mode="Split") else: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(_translate("Part_SplitFeatures", "Select at least two objects, first! First one is the object to be sliced; the rest are objects to slice with.", None)) + mb.setText(_translate("Part_SplitFeatures", + "Select at least two objects. " + "The first one is the object to be sliced; " + "the rest are objects to slice with.", None)) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) mb.exec_() @@ -326,21 +370,28 @@ class CommandSlice: else: return False + class CommandSliceApart: - "Command to create exploded Slice feature" + """Command to create exploded Slice feature.""" + def GetResources(self): - return {'Pixmap' : getIconPath("Part_SliceApart.svg"), + return {'Pixmap': getIconPath("Part_SliceApart.svg"), 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Slice apart"), 'Accel': "", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Split object by intersections with other objects.")} + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures", + "Slice a selected object by other objects, and split it apart.\n" + "It will create a 'Compound Filter' for each slice.")} def Activated(self): - if len(FreeCADGui.Selection.getSelectionEx()) > 1 : + if len(FreeCADGui.Selection.getSelectionEx()) > 1: cmdSliceApart() else: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(_translate("Part_SplitFeatures", "Select at least two objects, first! First one is the object to be sliced; the rest are objects to slice with.", None)) + mb.setText(_translate("Part_SplitFeatures", + "Select at least two objects. " + "The first one is the object to be sliced; " + "the rest are objects to slice with.", None)) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) mb.exec_() @@ -350,9 +401,9 @@ class CommandSliceApart: else: return False -# -------------------------- /Slice -------------------------------------------------- +# -------------------------- /Slice ------------------------------------------- -# -------------------------- XOR -------------------------------------------------- +# -------------------------- XOR ---------------------------------------------- def makeXOR(name): '''makeXOR(name): makes an XOR object.''' @@ -362,11 +413,15 @@ def makeXOR(name): ViewProviderXOR(obj.ViewObject) return obj + class FeatureXOR: - "The XOR feature object" + """The XOR feature object.""" + def __init__(self,obj): obj.addProperty("App::PropertyLinkList","Objects","XOR","Object to compute intersections between.") - obj.addProperty("App::PropertyLength","Tolerance","XOR","Tolerance when intersecting (fuzzy value). In addition to tolerances of the shapes.") + obj.addProperty("App::PropertyLength","Tolerance","XOR", + "Tolerance when intersecting (fuzzy value). " + "In addition to tolerances of the shapes.") obj.Proxy = self self.Type = "FeatureXOR" @@ -376,12 +431,12 @@ class FeatureXOR: if len(shapes) == 1 and shapes[0].ShapeType == "Compound": shapes = shapes[0].childShapes() if len(shapes) < 2: - raise ValueError("At least two shapes are needed for computing XOR. Got only {num}.".format(num= len(shapes))) + raise ValueError("At least two shapes are needed for computing XOR. Got only {num}.".format(num=len(shapes))) selfobj.Shape = SplitAPI.xor(shapes, selfobj.Tolerance) class ViewProviderXOR: - "A View Provider for the Part XOR feature" + """A View Provider for the Part XOR feature.""" def __init__(self,vobj): vobj.Proxy = self @@ -425,13 +480,14 @@ class ViewProviderXOR: def dropObject(self, selfvp, incoming_object): self.Object.Objects = self.Object.Objects + [incoming_object] + def cmdCreateXORFeature(name): """cmdCreateXORFeature(name): implementation of GUI command to create XOR feature (GFA). Mode can be "Standard", "Split", or "CompSolid".""" sel = FreeCADGui.Selection.getSelectionEx() FreeCAD.ActiveDocument.openTransaction("Create Boolean XOR") FreeCADGui.addModule("BOPTools.SplitFeatures") - FreeCADGui.doCommand("j = BOPTools.SplitFeatures.makeXOR(name= '{name}')".format(name= name)) + FreeCADGui.doCommand("j = BOPTools.SplitFeatures.makeXOR(name='{name}')".format(name=name)) FreeCADGui.doCommand("j.Objects = {sel}".format( sel= "[" + ", ".join(["App.ActiveDocument."+so.Object.Name for so in sel]) + "]" )) @@ -442,11 +498,15 @@ def cmdCreateXORFeature(name): except Exception as err: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(_translate("Part_SplitFeatures","Computing the result failed with an error: \n\n{err}\n\nClick 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) - .format(err= str(err))) + mb.setText(_translate("Part_SplitFeatures", + "Computing the result failed with an error:\n\n" + "{err}\n\n" + "Click 'Continue' to create the feature anyway, or 'Abort' to cancel.", None) + .format(err=str(err))) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) - btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) + btnOK = mb.addButton(_translate("Part_SplitFeatures","Continue",None), + QtGui.QMessageBox.ButtonRole.ActionRole) mb.setDefaultButton(btnOK) mb.exec_() @@ -460,21 +520,30 @@ def cmdCreateXORFeature(name): FreeCAD.ActiveDocument.commitTransaction() + class CommandXOR: - "Command to create XOR feature" + """Command to create XOR feature.""" + def GetResources(self): - return {'Pixmap' : getIconPath("Part_XOR.svg"), + return {'Pixmap': getIconPath("Part_XOR.svg"), 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Boolean XOR"), 'Accel': "", - 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures","Remove intersection fragments")} + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_SplitFeatures", + "Perform an 'exclusive OR' boolean operation with two or more selected objects,\n" + "or with the shapes inside a compound.\n" + "This means the overlapping volumes of the shapes will be removed.\n" + "A 'Compound Filter' can be used to extract the remaining pieces.")} def Activated(self): - if len(FreeCADGui.Selection.getSelectionEx()) >= 1 : - cmdCreateXORFeature(name= "XOR") + if len(FreeCADGui.Selection.getSelectionEx()) >= 1: + cmdCreateXORFeature(name="XOR") else: mb = QtGui.QMessageBox() mb.setIcon(mb.Icon.Warning) - mb.setText(_translate("Part_SplitFeatures", "Select at least two objects, or one or more compounds, first! If only one compound is selected, the compounded shapes will be intersected between each other (otherwise, compounds with self-intersections are invalid).", None)) + mb.setText(_translate("Part_SplitFeatures", + "Select at least two objects, or one or more compounds. " + "If only one compound is selected, the compounded shapes will be intersected between each other " + "(otherwise, compounds with self-intersections are invalid).", None)) mb.setWindowTitle(_translate("Part_SplitFeatures","Bad selection", None)) mb.exec_() @@ -484,7 +553,7 @@ class CommandXOR: else: return False -# -------------------------- /XOR -------------------------------------------------- +# -------------------------- /XOR --------------------------------------------- def addCommands(): FreeCADGui.addCommand('Part_BooleanFragments',CommandBooleanFragments())