Part: compound filter, GUI command
This commit is contained in:
parent
8369d68c8f
commit
54bbd79b03
|
@ -381,6 +381,7 @@ SET(Part_Scripts
|
|||
BOPTools/SplitFeatures.py
|
||||
BOPTools/Utils.py
|
||||
CompoundTools/__init__.py
|
||||
CompoundTools/_CommandCompoundFilter.py
|
||||
CompoundTools/CompoundFilter.py
|
||||
)
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ INSTALL(
|
|||
INSTALL(
|
||||
FILES
|
||||
CompoundTools/__init__.py
|
||||
CompoundTools/_CommandCompoundFilter.py
|
||||
CompoundTools/CompoundFilter.py
|
||||
DESTINATION
|
||||
Mod/Part/CompoundTools
|
||||
|
|
119
src/Mod/Part/CompoundTools/_CommandCompoundFilter.py
Normal file
119
src/Mod/Part/CompoundTools/_CommandCompoundFilter.py
Normal file
|
@ -0,0 +1,119 @@
|
|||
# ***************************************************************************
|
||||
# * *
|
||||
# * Copyright (c) 2016 - Victor Titov (DeepSOIC) <vv.titov@gmail.com> *
|
||||
# * *
|
||||
# * 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()
|
|
@ -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";
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue
Block a user