Skip to content

Commit

Permalink
Part: CompoundFilter, changes:
Browse files Browse the repository at this point in the history
- add CompoundTools menue enty
- add command to FreeCAD GUI
  • Loading branch information
berndhahnebach committed Feb 16, 2017
1 parent de8face commit 515d0c4
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/Mod/Part/App/AppPart.cpp
Expand Up @@ -380,6 +380,19 @@ PyMODINIT_FUNC initPart()
err.ReportException();
}

try {
//import all submodules of CompoundTools, to make them easy to browse in Py console.
//It's done in this weird manner instead of bt.caMemberFunction("importAll"),
//because the latter crashed when importAll failed with exception.
Base::Interpreter().runString("__import__('CompoundTools').importAll()");

Py::Object bt = Base::Interpreter().runStringObject("__import__('CompoundTools')");
module.setAttr(std::string("CompoundTools"),bt);
} catch (Base::PyException &err){
Base::Console().Error("Failed to import CompoundTools package:\n");
err.ReportException();
}

Part::TopoShape ::init();
Part::PropertyPartShape ::init();
Part::PropertyGeometryList ::init();
Expand Down
30 changes: 30 additions & 0 deletions src/Mod/Part/CompoundTools/CompoundFilter.py
Expand Up @@ -32,6 +32,7 @@
if FreeCAD.GuiUp:
import FreeCADGui
from PySide import QtGui
from PySide import QtCore


#-------------------------- translation-related code ----------------------------------------
Expand Down Expand Up @@ -271,9 +272,38 @@ def cmdCreateCompoundFilter(name):
FreeCADGui.doCommand("f = None")

FreeCAD.ActiveDocument.commitTransaction()


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
# -------------------------- /GUI command --------------------------------------------------


def addCommands():
FreeCADGui.addCommand('Part_CompoundFilter', _CommandCompoundFilter())


# helper
def getNullShapeShape(scale=1.0):
"""obtains a shape intended ad a placeholder in case null shape was produced by an operation"""
Expand Down
83 changes: 83 additions & 0 deletions src/Mod/Part/Gui/Command.cpp
Expand Up @@ -755,6 +755,88 @@ bool CmdPartCompSplitFeatures::isActive(void)
return false;
}

//===========================================================================
// Part_CompoundFilter (dropdown toolbar button for CompoundTools, CompoundFilter)
//===========================================================================

DEF_STD_CMD_ACL(CmdPartCompFilterFeatures);

CmdPartCompFilterFeatures::CmdPartCompFilterFeatures()
: Command("Part_CompoundFilter")
{
sAppModule = "Part";
sGroup = QT_TR_NOOP("Part");
sMenuText = QT_TR_NOOP("Compound Filter");
sToolTipText = QT_TR_NOOP("Compound Filter: remove some childs from a compound");
sWhatsThis = "Part_CompoundFilter";
sStatusTip = sToolTipText;
}

void CmdPartCompFilterFeatures::activated(int iMsg)
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
if (iMsg==0)
rcCmdMgr.runCommandByName("Part_CompoundFilter");
else
return;

// Since the default icon is reset when enabing/disabling the command we have
// to explicitly set the icon of the used command.
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
QList<QAction*> a = pcAction->actions();

assert(iMsg < a.size());
pcAction->setIcon(a[iMsg]->icon());
}

Gui::Action * CmdPartCompFilterFeatures::createAction(void)
{
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true);
applyCommandData(this->className(), pcAction);

QAction* cmd0 = pcAction->addAction(QString());
cmd0->setIcon(Gui::BitmapFactory().pixmap("Part_CompoundFilter"));

_pcAction = pcAction;
languageChange();

pcAction->setIcon(cmd0->icon());
int defaultId = 0;
pcAction->setProperty("defaultAction", QVariant(defaultId));

return pcAction;
}

void CmdPartCompFilterFeatures::languageChange()
{
Command::languageChange();

if (!_pcAction)
return;

Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();

Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
QList<QAction*> a = pcAction->actions();

Gui::Command* makeCompoundFilter = rcCmdMgr.getCommandByName("Part_CompoundFilter");
if (makeCompoundFilter) {
QAction* cmd0 = a[0];
cmd0->setText(QApplication::translate("Part_CompoundFilter", makeCompoundFilter->getMenuText()));
cmd0->setToolTip(QApplication::translate("Part_CompoundFilter", makeCompoundFilter->getToolTipText()));
cmd0->setStatusTip(QApplication::translate("Part_CompoundFilter", makeCompoundFilter->getStatusTip()));
}
}

bool CmdPartCompFilterFeatures::isActive(void)
{
if (getActiveGuiDocument())
return true;
else
return false;
}

//===========================================================================
// Part_Compound
//===========================================================================
Expand Down Expand Up @@ -2238,6 +2320,7 @@ void CreatePartCommands(void)
rcCmdMgr.addCommand(new CmdPartFuse());
rcCmdMgr.addCommand(new CmdPartCompJoinFeatures());
rcCmdMgr.addCommand(new CmdPartCompSplitFeatures());
rcCmdMgr.addCommand(new CmdPartCompFilterFeatures());
rcCmdMgr.addCommand(new CmdPartCompound());
rcCmdMgr.addCommand(new CmdPartSection());
//rcCmdMgr.addCommand(new CmdPartBox2());
Expand Down
10 changes: 7 additions & 3 deletions src/Mod/Part/Gui/Workbench.cpp
Expand Up @@ -75,15 +75,19 @@ 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");
*part << "Part_Import" << "Part_Export" << "Separator";
*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";
Expand Down Expand Up @@ -129,7 +133,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
*boolop << "Part_Boolean" << "Part_Cut" << "Part_Fuse" << "Part_Common"
<< "Part_CompJoinFeatures" << "Part_CompSplitFeatures" << "Part_CheckGeometry" << "Part_Section"
<< "Part_CrossSections";

Gui::ToolBarItem* measure = new Gui::ToolBarItem(root);
measure->setCommand("Measure");
*measure << "Part_Measure_Linear" << "Part_Measure_Angular" << "Separator" << "Part_Measure_Clear_All" << "Part_Measure_Toggle_All"
Expand Down
8 changes: 6 additions & 2 deletions src/Mod/Part/InitGui.py
@@ -1,4 +1,4 @@
# Part gui init module
# Part gui init module
# (c) 2003 Juergen Riegel
#
# Gathering all the information to start FreeCAD
Expand Down Expand Up @@ -45,7 +45,11 @@ def Initialize(self):
try:
Part.BOPTools.addCommands()
except Exception as err:
FreeCAD.Console.PrintError("Features from BOPTools package cannot be loaded. {err}\n".format(err= err.message))
FreeCAD.Console.PrintError("Features from BOPTools package cannot be loaded. {err}\n".format(err= err.message))
try:
Part.CompoundTools.addCommands()
except Exception as err:
FreeCAD.Console.PrintError("Features from CompoundTools package cannot be loaded. {err}\n".format(err= err.message))

def GetClassName(self):
return "PartGui::Workbench"
Expand Down

0 comments on commit 515d0c4

Please sign in to comment.