From 54bbd79b030838367e4c6b12ca4cc07fe0fd8915 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Fri, 17 Feb 2017 20:35:13 +0100 Subject: [PATCH] Part: compound filter, GUI command --- src/Mod/Part/App/CMakeLists.txt | 1 + src/Mod/Part/CMakeLists.txt | 1 + .../CompoundTools/_CommandCompoundFilter.py | 119 ++++++++++++++++++ src/Mod/Part/Gui/Workbench.cpp | 8 +- src/Mod/Part/InitGui.py | 3 + 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 src/Mod/Part/CompoundTools/_CommandCompoundFilter.py diff --git a/src/Mod/Part/App/CMakeLists.txt b/src/Mod/Part/App/CMakeLists.txt index 9f7be64a4..8d45956f3 100644 --- a/src/Mod/Part/App/CMakeLists.txt +++ b/src/Mod/Part/App/CMakeLists.txt @@ -381,6 +381,7 @@ SET(Part_Scripts BOPTools/SplitFeatures.py BOPTools/Utils.py CompoundTools/__init__.py + CompoundTools/_CommandCompoundFilter.py CompoundTools/CompoundFilter.py ) diff --git a/src/Mod/Part/CMakeLists.txt b/src/Mod/Part/CMakeLists.txt index 650712eb2..24f97bc71 100644 --- a/src/Mod/Part/CMakeLists.txt +++ b/src/Mod/Part/CMakeLists.txt @@ -44,6 +44,7 @@ INSTALL( INSTALL( FILES CompoundTools/__init__.py + CompoundTools/_CommandCompoundFilter.py CompoundTools/CompoundFilter.py DESTINATION Mod/Part/CompoundTools diff --git a/src/Mod/Part/CompoundTools/_CommandCompoundFilter.py b/src/Mod/Part/CompoundTools/_CommandCompoundFilter.py new file mode 100644 index 000000000..f85d1b867 --- /dev/null +++ b/src/Mod/Part/CompoundTools/_CommandCompoundFilter.py @@ -0,0 +1,119 @@ +# *************************************************************************** +# * * +# * Copyright (c) 2016 - Victor Titov (DeepSOIC) * +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the GNU Lesser General Public License (LGPL) * +# * as published by the Free Software Foundation; either version 2 of * +# * the License, or (at your option) any later version. * +# * for detail see the LICENCE text file. * +# * * +# * This program is distributed in the hope that it will be useful, * +# * but WITHOUT ANY WARRANTY; without even the implied warranty of * +# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +# * GNU Library General Public License for more details. * +# * * +# * You should have received a copy of the GNU Library General Public * +# * License along with this program; if not, write to the Free Software * +# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * +# * USA * +# * * +# *************************************************************************** + +__title__ = "CompoundTools._CommandCompoundFilter" +__author__ = "DeepSOIC, Bernd Hahnebach" +__url__ = "http://www.freecadweb.org" +__doc__ = "Compound Filter: remove some children from a compound (features)." + + +import FreeCAD +if FreeCAD.GuiUp: + import FreeCADGui + from PySide import QtGui + from PySide import QtCore + + +# 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: + 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) + + +# command class +class _CommandCompoundFilter: + "Command to create CompoundFilter feature" + def GetResources(self): + return {'Pixmap': ":/icons/Part_CompoundFilter.svg", + 'MenuText': QtCore.QT_TRANSLATE_NOOP("Part_CompoundFilter", "Compound Filter"), + 'Accel': "", + 'ToolTip': QtCore.QT_TRANSLATE_NOOP("Part_CompoundFilter", "Compound Filter: remove some childs from a compound")} + + def Activated(self): + if len(FreeCADGui.Selection.getSelection()) == 1 or len(FreeCADGui.Selection.getSelection()) == 2: + cmdCreateCompoundFilter(name="CompoundFilter") + else: + mb = QtGui.QMessageBox() + mb.setIcon(mb.Icon.Warning) + mb.setText(_translate("Part_CompoundFilter", "Select a shape that is a compound, first! Second selected item (optional) will be treated as a stencil.", None)) + mb.setWindowTitle(_translate("Part_CompoundFilter", "Bad selection", None)) + mb.exec_() + + def IsActive(self): + if FreeCAD.ActiveDocument: + return True + else: + return False + + +if FreeCAD.GuiUp: + FreeCADGui.addCommand('Part_CompoundFilter', _CommandCompoundFilter()) + + +# helper +def cmdCreateCompoundFilter(name): + sel = FreeCADGui.Selection.getSelection() + FreeCAD.ActiveDocument.openTransaction("Create CompoundFilter") + FreeCADGui.addModule("CompoundTools.CompoundFilter") + FreeCADGui.doCommand("f = CompoundTools.CompoundFilter.makeCompoundFilter(name = '" + name + "')") + FreeCADGui.doCommand("f.Base = App.ActiveDocument." + sel[0].Name) + if len(sel) == 2: + FreeCADGui.doCommand("f.Stencil = App.ActiveDocument." + sel[1].Name) + FreeCADGui.doCommand("f.Stencil.ViewObject.hide()") + FreeCADGui.doCommand("f.FilterType = 'collision-pass'") + else: + FreeCADGui.doCommand("f.FilterType = 'window-volume'") + + try: + FreeCADGui.doCommand("f.Proxy.execute(f)") + FreeCADGui.doCommand("f.purgeTouched()") + except Exception as err: + mb = QtGui.QMessageBox() + mb.setIcon(mb.Icon.Warning) + mb.setText(_translate("Part_CompoundFilter", "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=err.message)) + mb.setWindowTitle(_translate("Part_CompoundFilter", "Bad selection", None)) + btnAbort = mb.addButton(QtGui.QMessageBox.StandardButton.Abort) + btnOK = mb.addButton(_translate("Part_SplitFeatures", "Continue", None), QtGui.QMessageBox.ButtonRole.ActionRole) + mb.setDefaultButton(btnOK) + + mb.exec_() + + if mb.clickedButton() is btnAbort: + FreeCAD.ActiveDocument.abortTransaction() + return + + FreeCADGui.doCommand("f.Base.ViewObject.hide()") + FreeCADGui.doCommand("f = None") + + FreeCAD.ActiveDocument.commitTransaction() diff --git a/src/Mod/Part/Gui/Workbench.cpp b/src/Mod/Part/Gui/Workbench.cpp index 0e8969f69..769f69280 100644 --- a/src/Mod/Part/Gui/Workbench.cpp +++ b/src/Mod/Part/Gui/Workbench.cpp @@ -75,6 +75,10 @@ Gui::MenuItem* Workbench::setupMenuBar() const split->setCommand("Split"); *split << "Part_BooleanFragments" << "Part_Slice" << "Part_XOR"; + Gui::MenuItem* compound = new Gui::MenuItem; + compound->setCommand("Compound"); + *compound << "Part_Compound" << "Part_CompoundFilter"; + Gui::MenuItem* part = new Gui::MenuItem; root->insertItem(item, part); part->setCommand("&Part"); @@ -82,8 +86,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const *part << prim << "Part_Primitives" << "Part_Builder" << "Separator" << "Part_ShapeFromMesh" << "Part_MakeSolid" << "Part_ReverseShape" << "Part_SimpleCopy" << "Part_RefineShape" << "Part_CheckGeometry" - << "Separator" << bop << join << split << "Separator" - << "Part_CrossSections" << "Part_Compound" << "Part_MakeFace" << "Part_Extrude" + << "Separator" << bop << join << split << compound << "Separator" + << "Part_CrossSections" << "Part_MakeFace" << "Part_Extrude" << "Part_Revolve" << "Part_Mirror" << "Part_Fillet" << "Part_Chamfer" << "Part_RuledSurface" << "Part_Loft" << "Part_Sweep" << "Part_Offset" << "Part_Offset2D" << "Part_Thickness" << "Separator" << "Part_EditAttachment"; diff --git a/src/Mod/Part/InitGui.py b/src/Mod/Part/InitGui.py index 4a99040b6..6d1a54cf6 100644 --- a/src/Mod/Part/InitGui.py +++ b/src/Mod/Part/InitGui.py @@ -42,6 +42,9 @@ class PartWorkbench ( Workbench ): # load the module import PartGui import Part + + import CompoundTools._CommandCompoundFilter + try: Part.BOPTools.addCommands() except Exception as err: