Part: Reformat JoinDeatures by Black, delete some comments. Reformat commented code too.
Now it proper recognize by lupdate.
This commit is contained in:
committed by
Chris Hennes
parent
4d7e550d97
commit
176cf0d144
@@ -21,136 +21,136 @@
|
||||
|
||||
import FreeCAD, Part
|
||||
|
||||
#if FreeCAD.GuiUp:
|
||||
# import FreeCADGui
|
||||
# from PySide import QtCore, QtGui
|
||||
# if FreeCAD.GuiUp:
|
||||
# import FreeCADGui
|
||||
# from PySide import QtCore, QtGui
|
||||
|
||||
__title__="JoinFeatures module (legacy)"
|
||||
__title__ = "JoinFeatures module (legacy)"
|
||||
__author__ = "DeepSOIC"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
__doc__ = "Legacy JoinFeatures module provided for ability to load projects made with \
|
||||
FreeCAD v0.16. Do not use. Use BOPTools.JoinFeatures instead."
|
||||
|
||||
##-------------------------- translation-related code ----------------------------------------
|
||||
##Thanks, yorik! (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 AttributeError:
|
||||
# def _fromUtf8(s):
|
||||
# return s
|
||||
#try:
|
||||
# _encoding = QtGui.QApplication.UnicodeUTF8
|
||||
# def _translate(context, text, disambig):
|
||||
# return QtGui.QApplication.translate(context, text, disambig, _encoding)
|
||||
#except AttributeError:
|
||||
# def _translate(context, text, disambig):
|
||||
# return QtGui.QApplication.translate(context, text, disambig)
|
||||
##--------------------------/translation-related code ----------------------------------------
|
||||
|
||||
# -------------------------- common stuff --------------------------------------------------
|
||||
def getParamRefine():
|
||||
return FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Part/Boolean").GetBool("RefineModel")
|
||||
return FreeCAD.ParamGet(
|
||||
"User parameter:BaseApp/Preferences/Mod/Part/Boolean"
|
||||
).GetBool("RefineModel")
|
||||
|
||||
|
||||
def shapeOfMaxVol(compound):
|
||||
if compound.ShapeType == 'Compound':
|
||||
if compound.ShapeType == "Compound":
|
||||
maxVol = 0
|
||||
cntEq = 0
|
||||
shMax = None
|
||||
for sh in compound.childShapes():
|
||||
v = sh.Volume
|
||||
if v > maxVol + 1e-8 :
|
||||
if v > maxVol + 1e-8:
|
||||
maxVol = v
|
||||
shMax = sh
|
||||
cntEq = 1
|
||||
elif abs(v - maxVol) <= 1e-8 :
|
||||
elif abs(v - maxVol) <= 1e-8:
|
||||
cntEq = cntEq + 1
|
||||
if cntEq > 1 :
|
||||
if cntEq > 1:
|
||||
raise ValueError("Equal volumes, can't figure out what to cut off!")
|
||||
return shMax
|
||||
else:
|
||||
return compound
|
||||
|
||||
#def makePartJoinFeature(name, mode = 'bypass'):
|
||||
# '''makePartJoinFeature(name, mode = 'bypass'): makes an PartJoinFeature object.'''
|
||||
# obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
|
||||
# _PartJoinFeature(obj)
|
||||
# obj.Mode = mode
|
||||
# obj.Refine = getParamRefine()
|
||||
# _ViewProviderPartJoinFeature(obj.ViewObject)
|
||||
# return obj
|
||||
|
||||
#
|
||||
# def makePartJoinFeature(name, mode="bypass"):
|
||||
# """makePartJoinFeature(name, mode = 'bypass'): makes an PartJoinFeature object."""
|
||||
# obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython", name)
|
||||
# _PartJoinFeature(obj)
|
||||
# obj.Mode = mode
|
||||
# obj.Refine = getParamRefine()
|
||||
# _ViewProviderPartJoinFeature(obj.ViewObject)
|
||||
# return obj
|
||||
|
||||
|
||||
class _PartJoinFeature:
|
||||
"The PartJoinFeature object"
|
||||
def __init__(self,obj):
|
||||
self.Type = "PartJoinFeature"
|
||||
obj.addProperty("App::PropertyEnumeration","Mode","Join","The mode of operation. bypass = make compound (fast)")
|
||||
obj.Mode = ['bypass','Connect','Embed','Cutout']
|
||||
obj.addProperty("App::PropertyLink","Base","Join","First object")
|
||||
obj.addProperty("App::PropertyLink","Tool","Join","Second object")
|
||||
obj.addProperty("App::PropertyBool","Refine","Join","True = refine resulting shape. False = output as is.")
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
|
||||
def execute(self,obj):
|
||||
def __init__(self, obj):
|
||||
self.Type = "PartJoinFeature"
|
||||
obj.addProperty(
|
||||
"App::PropertyEnumeration",
|
||||
"Mode",
|
||||
"Join",
|
||||
"The mode of operation. bypass = make compound (fast)",
|
||||
)
|
||||
obj.Mode = ["bypass", "Connect", "Embed", "Cutout"]
|
||||
obj.addProperty("App::PropertyLink", "Base", "Join", "First object")
|
||||
obj.addProperty("App::PropertyLink", "Tool", "Join", "Second object")
|
||||
obj.addProperty(
|
||||
"App::PropertyBool",
|
||||
"Refine",
|
||||
"Join",
|
||||
"True = refine resulting shape. False = output as is.",
|
||||
)
|
||||
|
||||
obj.Proxy = self
|
||||
|
||||
def execute(self, obj):
|
||||
rst = None
|
||||
if obj.Mode == 'bypass':
|
||||
if obj.Mode == "bypass":
|
||||
rst = Part.makeCompound([obj.Base.Shape, obj.Tool.Shape])
|
||||
else:
|
||||
cut1 = obj.Base.Shape.cut(obj.Tool.Shape)
|
||||
cut1 = shapeOfMaxVol(cut1)
|
||||
if obj.Mode == 'Connect':
|
||||
if obj.Mode == "Connect":
|
||||
cut2 = obj.Tool.Shape.cut(obj.Base.Shape)
|
||||
cut2 = shapeOfMaxVol(cut2)
|
||||
rst = cut1.multiFuse([cut2, obj.Tool.Shape.common(obj.Base.Shape)])
|
||||
elif obj.Mode == 'Embed':
|
||||
elif obj.Mode == "Embed":
|
||||
rst = cut1.fuse(obj.Tool.Shape)
|
||||
elif obj.Mode == 'Cutout':
|
||||
elif obj.Mode == "Cutout":
|
||||
rst = cut1
|
||||
if obj.Refine:
|
||||
rst = rst.removeSplitter()
|
||||
obj.Shape = rst
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
||||
class _ViewProviderPartJoinFeature:
|
||||
"A View Provider for the PartJoinFeature object"
|
||||
|
||||
def __init__(self,vobj):
|
||||
def __init__(self, vobj):
|
||||
vobj.Proxy = self
|
||||
|
||||
|
||||
def getIcon(self):
|
||||
if self.Object is None:
|
||||
return getIconPath("Part_JoinConnect.svg")
|
||||
else:
|
||||
return getIconPath( {
|
||||
'bypass':"Part_JoinBypass.svg",
|
||||
'Connect':"Part_JoinConnect.svg",
|
||||
'Embed':"Part_JoinEmbed.svg",
|
||||
'Cutout':"Part_JoinCutout.svg",
|
||||
}[self.Object.Mode] )
|
||||
return getIconPath(
|
||||
{
|
||||
"bypass": "Part_JoinBypass.svg",
|
||||
"Connect": "Part_JoinConnect.svg",
|
||||
"Embed": "Part_JoinEmbed.svg",
|
||||
"Cutout": "Part_JoinCutout.svg",
|
||||
}[self.Object.Mode]
|
||||
)
|
||||
|
||||
def attach(self, vobj):
|
||||
self.ViewObject = vobj
|
||||
self.Object = vobj.Object
|
||||
|
||||
|
||||
def setEdit(self,vobj,mode):
|
||||
def setEdit(self, vobj, mode):
|
||||
return False
|
||||
|
||||
def unsetEdit(self,vobj,mode):
|
||||
|
||||
def unsetEdit(self, vobj, mode):
|
||||
return
|
||||
|
||||
def __getstate__(self):
|
||||
return None
|
||||
|
||||
def __setstate__(self,state):
|
||||
def __setstate__(self, state):
|
||||
return None
|
||||
|
||||
|
||||
def claimChildren(self):
|
||||
return [self.Object.Base, self.Object.Tool]
|
||||
|
||||
|
||||
def onDelete(self, feature, subelements):
|
||||
try:
|
||||
self.Object.Base.ViewObject.show()
|
||||
@@ -158,135 +158,174 @@ class _ViewProviderPartJoinFeature:
|
||||
except Exception as err:
|
||||
FreeCAD.Console.PrintError("Error in onDelete: " + str(err))
|
||||
return True
|
||||
|
||||
#
|
||||
#def CreateJoinFeature(name, mode):
|
||||
# sel = FreeCADGui.Selection.getSelectionEx()
|
||||
# FreeCAD.ActiveDocument.openTransaction("Create "+mode+"ObjectsFeature")
|
||||
# FreeCADGui.addModule("JoinFeatures")
|
||||
# FreeCADGui.doCommand("j = JoinFeatures.makePartJoinFeature(name = '"+name+"', mode = '"+mode+"' )")
|
||||
# FreeCADGui.doCommand("j.Base = App.ActiveDocument."+sel[0].Object.Name)
|
||||
# FreeCADGui.doCommand("j.Tool = App.ActiveDocument."+sel[1].Object.Name)
|
||||
# try:
|
||||
# FreeCADGui.doCommand("j.Proxy.execute(j)")
|
||||
# FreeCADGui.doCommand("j.purgeTouched()")
|
||||
# except Exception as err:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(_translate("Part_JoinFeatures","Computing the result failed with an error: {err}. Click 'Continue' to create the feature anyway, or 'Abort' to cancel.", None)
|
||||
# .format(err= str(err)))
|
||||
# mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
|
||||
# btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort)
|
||||
# btnOK = mb.addButton(_translate("Part_JoinFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole)
|
||||
# mb.setDefaultButton(btnOK)
|
||||
#
|
||||
# mb.exec_()
|
||||
#
|
||||
# if mb.clickedButton() is btnAbort:
|
||||
# FreeCAD.ActiveDocument.abortTransaction()
|
||||
# return
|
||||
#
|
||||
# FreeCADGui.doCommand("j.Base.ViewObject.hide()")
|
||||
# FreeCADGui.doCommand("j.Tool.ViewObject.hide()")
|
||||
#
|
||||
# FreeCAD.ActiveDocument.commitTransaction()
|
||||
|
||||
|
||||
# def CreateJoinFeature(name, mode):
|
||||
# sel = FreeCADGui.Selection.getSelectionEx()
|
||||
# FreeCAD.ActiveDocument.openTransaction("Create " + mode + "ObjectsFeature")
|
||||
# FreeCADGui.addModule("JoinFeatures")
|
||||
# FreeCADGui.doCommand(
|
||||
# "j = JoinFeatures.makePartJoinFeature(name = '"
|
||||
# + name
|
||||
# + "', mode = '"
|
||||
# + mode
|
||||
# + "' )"
|
||||
# )
|
||||
# FreeCADGui.doCommand("j.Base = App.ActiveDocument." + sel[0].Object.Name)
|
||||
# FreeCADGui.doCommand("j.Tool = App.ActiveDocument." + sel[1].Object.Name)
|
||||
# try:
|
||||
# FreeCADGui.doCommand("j.Proxy.execute(j)")
|
||||
# FreeCADGui.doCommand("j.purgeTouched()")
|
||||
# except Exception as err:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(
|
||||
# translate(
|
||||
# "Part_JoinFeatures",
|
||||
# "Computing the result failed with an error: {err}. Click 'Continue' to create the feature anyway, or 'Abort' to cancel.",
|
||||
# None,
|
||||
# ).format(err=str(err))
|
||||
# )
|
||||
# mb.setWindowTitle(translate("Part_JoinFeatures", "Bad selection", None))
|
||||
# btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort)
|
||||
# btnOK = mb.addButton(
|
||||
# translate("Part_JoinFeatures", "Continue", None),
|
||||
# QtGui.QMessageBox.ButtonRole.ActionRole,
|
||||
# )
|
||||
# mb.setDefaultButton(btnOK)
|
||||
|
||||
# mb.exec_()
|
||||
|
||||
# if mb.clickedButton() is btnAbort:
|
||||
# FreeCAD.ActiveDocument.abortTransaction()
|
||||
# return
|
||||
|
||||
# FreeCADGui.doCommand("j.Base.ViewObject.hide()")
|
||||
# FreeCADGui.doCommand("j.Tool.ViewObject.hide()")
|
||||
|
||||
# FreeCAD.ActiveDocument.commitTransaction()
|
||||
|
||||
|
||||
def getIconPath(icon_dot_svg):
|
||||
return ":/icons/" + icon_dot_svg
|
||||
|
||||
# -------------------------- /common stuff --------------------------------------------------
|
||||
|
||||
## -------------------------- ConnectObjectsFeature --------------------------------------------------
|
||||
#
|
||||
#class _CommandConnectFeature:
|
||||
# "Command to create PartJoinFeature in Connect mode"
|
||||
# def GetResources(self):
|
||||
# return {'Pixmap' : getIconPath("Part_JoinConnect.svg"),
|
||||
# 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_ConnectFeature","Connect objects"),
|
||||
# 'Accel': "",
|
||||
# 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_ConnectFeature","Fuses objects, taking care to preserve voids.")}
|
||||
#
|
||||
# def Activated(self):
|
||||
# if len(FreeCADGui.Selection.getSelectionEx()) == 2 :
|
||||
# CreateJoinFeature(name = "Connect", mode = "Connect")
|
||||
# else:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(_translate("Part_JoinFeatures", "Two solids need to be selected, first!", None))
|
||||
# mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
|
||||
# mb.exec_()
|
||||
#
|
||||
# def IsActive(self):
|
||||
# if FreeCAD.ActiveDocument:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
#
|
||||
#FreeCADGui.addCommand('Part_JoinConnect',_CommandConnectFeature())
|
||||
#
|
||||
## -------------------------- /ConnectObjectsFeature --------------------------------------------------
|
||||
#
|
||||
#
|
||||
## -------------------------- EmbedFeature --------------------------------------------------
|
||||
#
|
||||
#class _CommandEmbedFeature:
|
||||
# "Command to create PartJoinFeature in Embed mode"
|
||||
# def GetResources(self):
|
||||
# return {'Pixmap' : getIconPath("Part_JoinEmbed.svg"),
|
||||
# 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_EmbedFeature","Embed object"),
|
||||
# 'Accel': "",
|
||||
# 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_EmbedFeature","Fuses one object into another, taking care to preserve voids.")}
|
||||
#
|
||||
# def Activated(self):
|
||||
# if len(FreeCADGui.Selection.getSelection()) == 2 :
|
||||
# CreateJoinFeature(name = "Embed", mode = "Embed")
|
||||
# else:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(_translate("Part_JoinFeatures","Select base object, then the object to embed, and invoke this tool.", None))
|
||||
# mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
|
||||
# mb.exec_()
|
||||
#
|
||||
#
|
||||
# def IsActive(self):
|
||||
# if FreeCAD.ActiveDocument:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
#
|
||||
#FreeCADGui.addCommand('Part_JoinEmbed',_CommandEmbedFeature())
|
||||
#
|
||||
## -------------------------- /EmbedFeature --------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
## -------------------------- CutoutFeature --------------------------------------------------
|
||||
#
|
||||
#class _CommandCutoutFeature:
|
||||
# "Command to create PartJoinFeature in Cutout mode"
|
||||
# def GetResources(self):
|
||||
# return {'Pixmap' : getIconPath("Part_JoinCutout.svg"),
|
||||
# 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_CutoutFeature","Cutout for object"),
|
||||
# 'Accel': "",
|
||||
# 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_CutoutFeature","Makes a cutout in one object to fit another object.")}
|
||||
#
|
||||
# def Activated(self):
|
||||
# if len(FreeCADGui.Selection.getSelection()) == 2 :
|
||||
# CreateJoinFeature(name = "Cutout", mode = "Cutout")
|
||||
# else:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(_translate("Part_JoinFeatures","Select the object to make a cutout in, then the object that should fit into the cutout, and invoke this tool.", None))
|
||||
# mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
|
||||
# mb.exec_()
|
||||
#
|
||||
# def IsActive(self):
|
||||
# if FreeCAD.ActiveDocument:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
#
|
||||
#FreeCADGui.addCommand('Part_JoinCutout',_CommandCutoutFeature())
|
||||
#
|
||||
## -------------------------- /CutoutFeature --------------------------------------------------
|
||||
#
|
||||
# class _CommandConnectFeature:
|
||||
# "Command to create PartJoinFeature in Connect mode"
|
||||
|
||||
# def GetResources(self):
|
||||
# return {
|
||||
# "Pixmap": getIconPath("Part_JoinConnect.svg"),
|
||||
# "MenuText": QtCore.QT_TRANSLATE_NOOP(
|
||||
# "Part_ConnectFeature", "Connect objects"
|
||||
# ),
|
||||
# "Accel": "",
|
||||
# "ToolTip": QtCore.QT_TRANSLATE_NOOP(
|
||||
# "Part_ConnectFeature", "Fuses objects, taking care to preserve voids."
|
||||
# ),
|
||||
# }
|
||||
|
||||
# def Activated(self):
|
||||
# if len(FreeCADGui.Selection.getSelectionEx()) == 2:
|
||||
# CreateJoinFeature(name="Connect", mode="Connect")
|
||||
# else:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(
|
||||
# translate(
|
||||
# "Part_JoinFeatures", "Two solids need to be selected, first!", None
|
||||
# )
|
||||
# )
|
||||
# mb.setWindowTitle(translate("Part_JoinFeatures", "Bad selection", None))
|
||||
# mb.exec_()
|
||||
|
||||
# def IsActive(self):
|
||||
# if FreeCAD.ActiveDocument:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
|
||||
|
||||
# FreeCADGui.addCommand("Part_JoinConnect", _CommandConnectFeature())
|
||||
|
||||
|
||||
# class _CommandEmbedFeature:
|
||||
# "Command to create PartJoinFeature in Embed mode"
|
||||
|
||||
# def GetResources(self):
|
||||
# return {
|
||||
# "Pixmap": getIconPath("Part_JoinEmbed.svg"),
|
||||
# "MenuText": QtCore.QT_TRANSLATE_NOOP("Part_EmbedFeature", "Embed object"),
|
||||
# "Accel": "",
|
||||
# "ToolTip": QtCore.QT_TRANSLATE_NOOP(
|
||||
# "Part_EmbedFeature",
|
||||
# "Fuses one object into another, taking care to preserve voids.",
|
||||
# ),
|
||||
# }
|
||||
|
||||
# def Activated(self):
|
||||
# if len(FreeCADGui.Selection.getSelection()) == 2:
|
||||
# CreateJoinFeature(name="Embed", mode="Embed")
|
||||
# else:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(
|
||||
# translate(
|
||||
# "Part_JoinFeatures",
|
||||
# "Select base object, then the object to embed, and invoke this tool.",
|
||||
# None,
|
||||
# )
|
||||
# )
|
||||
# mb.setWindowTitle(translate("Part_JoinFeatures", "Bad selection", None))
|
||||
# mb.exec_()
|
||||
|
||||
# def IsActive(self):
|
||||
# if FreeCAD.ActiveDocument:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
|
||||
|
||||
# FreeCADGui.addCommand("Part_JoinEmbed", _CommandEmbedFeature())
|
||||
|
||||
|
||||
# class _CommandCutoutFeature:
|
||||
# "Command to create PartJoinFeature in Cutout mode"
|
||||
|
||||
# def GetResources(self):
|
||||
# return {
|
||||
# "Pixmap": getIconPath("Part_JoinCutout.svg"),
|
||||
# "MenuText": QtCore.QT_TRANSLATE_NOOP(
|
||||
# "Part_CutoutFeature", "Cutout for object"
|
||||
# ),
|
||||
# "Accel": "",
|
||||
# "ToolTip": QtCore.QT_TRANSLATE_NOOP(
|
||||
# "Part_CutoutFeature",
|
||||
# "Makes a cutout in one object to fit another object.",
|
||||
# ),
|
||||
# }
|
||||
|
||||
# def Activated(self):
|
||||
# if len(FreeCADGui.Selection.getSelection()) == 2:
|
||||
# CreateJoinFeature(name="Cutout", mode="Cutout")
|
||||
# else:
|
||||
# mb = QtGui.QMessageBox()
|
||||
# mb.setIcon(mb.Icon.Warning)
|
||||
# mb.setText(
|
||||
# translate(
|
||||
# "Part_JoinFeatures",
|
||||
# "Select the object to make a cutout in, then the object that should fit into the cutout, and invoke this tool.",
|
||||
# None,
|
||||
# )
|
||||
# )
|
||||
# mb.setWindowTitle(translate("Part_JoinFeatures", "Bad selection", None))
|
||||
# mb.exec_()
|
||||
|
||||
# def IsActive(self):
|
||||
# if FreeCAD.ActiveDocument:
|
||||
# return True
|
||||
# else:
|
||||
# return False
|
||||
|
||||
|
||||
# FreeCADGui.addCommand("Part_JoinCutout", _CommandCutoutFeature())
|
||||
|
||||
Reference in New Issue
Block a user