Skip to content

Commit

Permalink
Part: JoinFeatures UI improvements
Browse files Browse the repository at this point in the history
* display originals in tree under the features (like Part Fuse does)
* unhide originals upon delete
* display message box when computing the feature fails on creation
  • Loading branch information
DeepSOIC authored and wwmayer committed Mar 8, 2016
1 parent 2879ee2 commit 3df9df6
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions src/Mod/Part/JoinFeatures.py
Expand Up @@ -147,17 +147,48 @@ def __getstate__(self):

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()
self.Object.Tool.ViewObject.show()
except Exception as err:
FreeCAD.Console.PrintError("Error in onDelete: " + err.message)
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 = FreeCADGui.Selection.getSelection()[0]")
FreeCADGui.doCommand("j.Tool = FreeCADGui.Selection.getSelection()[1]")
FreeCADGui.doCommand("j.Proxy.execute(j)")
FreeCADGui.doCommand("j.purgeTouched()")
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= err.message))
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):
Expand All @@ -176,7 +207,7 @@ def GetResources(self):
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_ConnectFeature","Fuses objects, taking care to preserve voids.")}

def Activated(self):
if len(FreeCADGui.Selection.getSelection()) == 2 :
if len(FreeCADGui.Selection.getSelectionEx()) == 2 :
CreateJoinFeature(name = "Connect", mode = "Connect")
else:
mb = QtGui.QMessageBox()
Expand Down

0 comments on commit 3df9df6

Please sign in to comment.