Part: deprecate old JoinFeatures code

Commented out all the code not essential for recomputing old
JoinFeatures. The rest is left to support opening old projects.
This commit is contained in:
DeepSOIC 2016-07-29 14:13:12 +03:00
parent 54c8828237
commit ea586e9880

View File

@ -23,30 +23,32 @@
import FreeCAD, Part import FreeCAD, Part
if FreeCAD.GuiUp: #if FreeCAD.GuiUp:
import FreeCADGui # import FreeCADGui
from PySide import QtCore, QtGui # from PySide import QtCore, QtGui
__title__="JoinFeatures module" __title__="JoinFeatures module (legacy)"
__author__ = "DeepSOIC" __author__ = "DeepSOIC"
__url__ = "http://www.freecadweb.org" __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 ---------------------------------------- ##-------------------------- translation-related code ----------------------------------------
#Thanks, yorik! (see forum thread "A new Part tool is being born... JoinFeatures!" ##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 ) ##http://forum.freecadweb.org/viewtopic.php?f=22&t=11112&start=30#p90239 )
try: #try:
_fromUtf8 = QtCore.QString.fromUtf8 # _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError: #except AttributeError:
def _fromUtf8(s): # def _fromUtf8(s):
return s # return s
try: #try:
_encoding = QtGui.QApplication.UnicodeUTF8 # _encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig): # def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding) # return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError: #except AttributeError:
def _translate(context, text, disambig): # def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig) # return QtGui.QApplication.translate(context, text, disambig)
#--------------------------/translation-related code ---------------------------------------- ##--------------------------/translation-related code ----------------------------------------
# -------------------------- common stuff -------------------------------------------------- # -------------------------- common stuff --------------------------------------------------
def getParamRefine(): def getParamRefine():
@ -71,14 +73,14 @@ def shapeOfMaxVol(compound):
else: else:
return compound return compound
def makePartJoinFeature(name, mode = 'bypass'): #def makePartJoinFeature(name, mode = 'bypass'):
'''makePartJoinFeature(name, mode = 'bypass'): makes an PartJoinFeature object.''' # '''makePartJoinFeature(name, mode = 'bypass'): makes an PartJoinFeature object.'''
obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name) # obj = FreeCAD.ActiveDocument.addObject("Part::FeaturePython",name)
_PartJoinFeature(obj) # _PartJoinFeature(obj)
obj.Mode = mode # obj.Mode = mode
obj.Refine = getParamRefine() # obj.Refine = getParamRefine()
_ViewProviderPartJoinFeature(obj.ViewObject) # _ViewProviderPartJoinFeature(obj.ViewObject)
return obj # return obj
class _PartJoinFeature: class _PartJoinFeature:
"The PartJoinFeature object" "The PartJoinFeature object"
@ -159,133 +161,134 @@ class _ViewProviderPartJoinFeature:
FreeCAD.Console.PrintError("Error in onDelete: " + err.message) FreeCAD.Console.PrintError("Error in onDelete: " + err.message)
return True return True
#
def CreateJoinFeature(name, mode): #def CreateJoinFeature(name, mode):
sel = FreeCADGui.Selection.getSelectionEx() # sel = FreeCADGui.Selection.getSelectionEx()
FreeCAD.ActiveDocument.openTransaction("Create "+mode+"ObjectsFeature") # FreeCAD.ActiveDocument.openTransaction("Create "+mode+"ObjectsFeature")
FreeCADGui.addModule("JoinFeatures") # FreeCADGui.addModule("JoinFeatures")
FreeCADGui.doCommand("j = JoinFeatures.makePartJoinFeature(name = '"+name+"', mode = '"+mode+"' )") # FreeCADGui.doCommand("j = JoinFeatures.makePartJoinFeature(name = '"+name+"', mode = '"+mode+"' )")
FreeCADGui.doCommand("j.Base = App.ActiveDocument."+sel[0].Object.Name) # FreeCADGui.doCommand("j.Base = App.ActiveDocument."+sel[0].Object.Name)
FreeCADGui.doCommand("j.Tool = App.ActiveDocument."+sel[1].Object.Name) # FreeCADGui.doCommand("j.Tool = App.ActiveDocument."+sel[1].Object.Name)
try: # try:
FreeCADGui.doCommand("j.Proxy.execute(j)") # FreeCADGui.doCommand("j.Proxy.execute(j)")
FreeCADGui.doCommand("j.purgeTouched()") # FreeCADGui.doCommand("j.purgeTouched()")
except Exception as err: # except Exception as err:
mb = QtGui.QMessageBox() # mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Warning) # 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) # 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= err.message)) # .format(err= err.message))
mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None)) # mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) # btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort)
btnOK = mb.addButton(_translate("Part_JoinFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole) # btnOK = mb.addButton(_translate("Part_JoinFeatures","Continue",None), QtGui.QMessageBox.ButtonRole.ActionRole)
mb.setDefaultButton(btnOK) # mb.setDefaultButton(btnOK)
#
mb.exec_() # mb.exec_()
#
if mb.clickedButton() is btnAbort: # if mb.clickedButton() is btnAbort:
FreeCAD.ActiveDocument.abortTransaction() # FreeCAD.ActiveDocument.abortTransaction()
return # return
#
FreeCADGui.doCommand("j.Base.ViewObject.hide()") # FreeCADGui.doCommand("j.Base.ViewObject.hide()")
FreeCADGui.doCommand("j.Tool.ViewObject.hide()") # FreeCADGui.doCommand("j.Tool.ViewObject.hide()")
#
FreeCAD.ActiveDocument.commitTransaction() # FreeCAD.ActiveDocument.commitTransaction()
def getIconPath(icon_dot_svg): def getIconPath(icon_dot_svg):
return ":/icons/" + icon_dot_svg return ":/icons/" + icon_dot_svg
# -------------------------- /common stuff -------------------------------------------------- # -------------------------- /common stuff --------------------------------------------------
# -------------------------- ConnectObjectsFeature -------------------------------------------------- ## -------------------------- ConnectObjectsFeature --------------------------------------------------
#
class _CommandConnectFeature: #class _CommandConnectFeature:
"Command to create PartJoinFeature in Connect mode" # "Command to create PartJoinFeature in Connect mode"
def GetResources(self): # def GetResources(self):
return {'Pixmap' : getIconPath("Part_JoinConnect.svg"), # return {'Pixmap' : getIconPath("Part_JoinConnect.svg"),
'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_ConnectFeature","Connect objects"), # 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_ConnectFeature","Connect objects"),
'Accel': "", # 'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_ConnectFeature","Fuses objects, taking care to preserve voids.")} # 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_ConnectFeature","Fuses objects, taking care to preserve voids.")}
#
def Activated(self): # def Activated(self):
if len(FreeCADGui.Selection.getSelectionEx()) == 2 : # if len(FreeCADGui.Selection.getSelectionEx()) == 2 :
CreateJoinFeature(name = "Connect", mode = "Connect") # CreateJoinFeature(name = "Connect", mode = "Connect")
else: # else:
mb = QtGui.QMessageBox() # mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Warning) # mb.setIcon(mb.Icon.Warning)
mb.setText(_translate("Part_JoinFeatures", "Two solids need to be selected, first!", None)) # mb.setText(_translate("Part_JoinFeatures", "Two solids need to be selected, first!", None))
mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None)) # mb.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
mb.exec_() # mb.exec_()
#
def IsActive(self): # def IsActive(self):
if FreeCAD.ActiveDocument: # if FreeCAD.ActiveDocument:
return True # return True
else: # else:
return False # return False
#
FreeCADGui.addCommand('Part_JoinConnect',_CommandConnectFeature()) #FreeCADGui.addCommand('Part_JoinConnect',_CommandConnectFeature())
#
# -------------------------- /ConnectObjectsFeature -------------------------------------------------- ## -------------------------- /ConnectObjectsFeature --------------------------------------------------
#
#
# -------------------------- EmbedFeature -------------------------------------------------- ## -------------------------- EmbedFeature --------------------------------------------------
#
class _CommandEmbedFeature: #class _CommandEmbedFeature:
"Command to create PartJoinFeature in Embed mode" # "Command to create PartJoinFeature in Embed mode"
def GetResources(self): # def GetResources(self):
return {'Pixmap' : getIconPath("Part_JoinEmbed.svg"), # return {'Pixmap' : getIconPath("Part_JoinEmbed.svg"),
'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_EmbedFeature","Embed object"), # 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_EmbedFeature","Embed object"),
'Accel': "", # 'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_EmbedFeature","Fuses one object into another, taking care to preserve voids.")} # 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_EmbedFeature","Fuses one object into another, taking care to preserve voids.")}
#
def Activated(self): # def Activated(self):
if len(FreeCADGui.Selection.getSelection()) == 2 : # if len(FreeCADGui.Selection.getSelection()) == 2 :
CreateJoinFeature(name = "Embed", mode = "Embed") # CreateJoinFeature(name = "Embed", mode = "Embed")
else: # else:
mb = QtGui.QMessageBox() # mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Warning) # mb.setIcon(mb.Icon.Warning)
mb.setText(_translate("Part_JoinFeatures","Select base object, then the object to embed, and invoke this tool.", None)) # 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.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
mb.exec_() # mb.exec_()
#
#
def IsActive(self): # def IsActive(self):
if FreeCAD.ActiveDocument: # if FreeCAD.ActiveDocument:
return True # return True
else: # else:
return False # return False
#
FreeCADGui.addCommand('Part_JoinEmbed',_CommandEmbedFeature()) #FreeCADGui.addCommand('Part_JoinEmbed',_CommandEmbedFeature())
#
# -------------------------- /EmbedFeature -------------------------------------------------- ## -------------------------- /EmbedFeature --------------------------------------------------
#
#
#
# -------------------------- CutoutFeature -------------------------------------------------- ## -------------------------- CutoutFeature --------------------------------------------------
#
class _CommandCutoutFeature: #class _CommandCutoutFeature:
"Command to create PartJoinFeature in Cutout mode" # "Command to create PartJoinFeature in Cutout mode"
def GetResources(self): # def GetResources(self):
return {'Pixmap' : getIconPath("Part_JoinCutout.svg"), # return {'Pixmap' : getIconPath("Part_JoinCutout.svg"),
'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_CutoutFeature","Cutout for object"), # 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_CutoutFeature","Cutout for object"),
'Accel': "", # 'Accel': "",
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_CutoutFeature","Makes a cutout in one object to fit another object.")} # 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_CutoutFeature","Makes a cutout in one object to fit another object.")}
#
def Activated(self): # def Activated(self):
if len(FreeCADGui.Selection.getSelection()) == 2 : # if len(FreeCADGui.Selection.getSelection()) == 2 :
CreateJoinFeature(name = "Cutout", mode = "Cutout") # CreateJoinFeature(name = "Cutout", mode = "Cutout")
else: # else:
mb = QtGui.QMessageBox() # mb = QtGui.QMessageBox()
mb.setIcon(mb.Icon.Warning) # 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.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.setWindowTitle(_translate("Part_JoinFeatures","Bad selection", None))
mb.exec_() # mb.exec_()
#
def IsActive(self): # def IsActive(self):
if FreeCAD.ActiveDocument: # if FreeCAD.ActiveDocument:
return True # return True
else: # else:
return False # return False
#
FreeCADGui.addCommand('Part_JoinCutout',_CommandCutoutFeature()) #FreeCADGui.addCommand('Part_JoinCutout',_CommandCutoutFeature())
#
# -------------------------- /CutoutFeature -------------------------------------------------- ## -------------------------- /CutoutFeature --------------------------------------------------
#