From e58ae2b6164a48910f3929192dec3fd09ffeea68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Sat, 18 Jul 2015 19:36:44 +0200 Subject: [PATCH] Setup ShapeBinder Viewprovider and command --- src/Mod/PartDesign/App/ShapeBinder.cpp | 6 +- src/Mod/PartDesign/Gui/Command.cpp | 80 ++++++- .../PartDesign/Gui/Resources/PartDesign.qrc | 1 + .../icons/PartDesign_ShapeBinder.svg | 202 ++++++++++++++++++ .../Gui/ViewProviderShapeBinder.cpp | 18 ++ src/Mod/PartDesign/Gui/Workbench.cpp | 2 + 6 files changed, 304 insertions(+), 5 deletions(-) create mode 100644 src/Mod/PartDesign/Gui/Resources/icons/PartDesign_ShapeBinder.svg diff --git a/src/Mod/PartDesign/App/ShapeBinder.cpp b/src/Mod/PartDesign/App/ShapeBinder.cpp index fd9fd8144..03dd5a6d7 100644 --- a/src/Mod/PartDesign/App/ShapeBinder.cpp +++ b/src/Mod/PartDesign/App/ShapeBinder.cpp @@ -101,13 +101,13 @@ TopoShape ShapeBinder::buildShapeFromReferences(std::vector< App::DocumentObject if(objs[index] != obj) continue; - //in this mode the full shape is allowed, as we already started the subshape - //prcessing + //in this mode the full shape is not allowed, as we already started the subshape + //processing if(sub.empty()) continue; if(base.isNull()) - base = obj->Shape.getShape(); + base = obj->Shape.getShape().getSubShape(sub.c_str()); else operators.push_back(obj->Shape.getShape().getSubShape(sub.c_str())); } diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index c6e28e435..2193cf7ef 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include "TaskFeaturePick.h" #include "ReferenceSelection.h" @@ -214,6 +215,80 @@ bool CmdPartDesignPoint::isActive(void) return false; } +//=========================================================================== +// PartDesign_ShapeBinder +//=========================================================================== + +DEF_STD_CMD_A(CmdPartDesignShapeBinder); + +CmdPartDesignShapeBinder::CmdPartDesignShapeBinder() + :Command("PartDesign_ShapeBinder") +{ + sAppModule = "PartDesign"; + sGroup = QT_TR_NOOP("PartDesign"); + sMenuText = QT_TR_NOOP("Create a shape binder"); + sToolTipText = QT_TR_NOOP("Create a new shape binder"); + sWhatsThis = sToolTipText; + sStatusTip = sToolTipText; + sPixmap = "PartDesign_ShapeBinder"; +} + +void CmdPartDesignShapeBinder::activated(int iMsg) +{ + App::PropertyLinkSubList support; + getSelection().getAsPropertyLinkSubList(support); + + bool bEditSelected = false; + if (support.getSize() == 1 && support.getValue() ){ + if (support.getValue()->isDerivedFrom(PartDesign::ShapeBinder::getClassTypeId()) || + support.getValue()->isDerivedFrom(PartDesign::ShapeBinder2D::getClassTypeId())) + bEditSelected = true; + } + + if (bEditSelected) { + std::string tmp = std::string("Edit ShapeBinder"); + openCommand(tmp.c_str()); + doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s')", + support.getValue()->getNameInDocument()); + } else { + PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */true); + if (pcActiveBody == 0) + return; + + std::string FeatName = getUniqueObjectName("ShapeBinder"); + std::string tmp = std::string("Create ShapeBinder"); + + openCommand(tmp.c_str()); + + if(support.getValue()->isDerivedFrom(PartDesign::ShapeBinder2D::getClassTypeId()) || + support.getValue()->isDerivedFrom(Part::Part2DObject::getClassTypeId())) { + doCommand(Gui::Command::Doc,"App.activeDocument().addObject('%s','%s')", + "PartDesign::ShapeBinder2D",FeatName.c_str()); + } else { + doCommand(Gui::Command::Doc,"App.activeDocument().addObject('%s','%s')", + "PartDesign::ShapeBinder",FeatName.c_str()); + } + + //test if current selection fits a mode. + if (support.getSize() > 0) { + AttachableObject* pcDatum = static_cast( + getDocument()->getObject(FeatName.c_str())); + doCommand(Gui::Command::Doc,"App.activeDocument().%s.Support = %s", + FeatName.c_str(),support.getPyReprString().c_str()); + } + doCommand(Gui::Command::Doc,"App.activeDocument().%s.addFeature(App.activeDocument().%s)", + pcActiveBody->getNameInDocument(), FeatName.c_str()); + doCommand(Gui::Command::Doc,"App.activeDocument().recompute()"); // recompute the feature based on its references + doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str()); + } + // TODO do a proper error processing (2015-09-11, Fat-Zer) +} + +bool CmdPartDesignShapeBinder::isActive(void) +{ + return hasActiveDocument (); +} + //=========================================================================== // PartDesign_Sketch //=========================================================================== @@ -667,7 +742,7 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, // If there is more than one selection/possibility, show dialog and let user pick sketch if ((bNoSketchWasSelected && validSketches > 1) || (!bNoSketchWasSelected && sketches.size() > 1) || - (!bNoSketchWasSelected && ext) ) { + (!bNoSketchWasSelected && ext) ) { Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); PartDesignGui::TaskDlgFeaturePick *pickDlg = qobject_cast(dlg); @@ -689,7 +764,7 @@ void prepareSketchBased(Gui::Command* cmd, const std::string& which, Gui::Selection().clearSelection(); pickDlg = new PartDesignGui::TaskDlgFeaturePick(sketches, status, accepter, worker); - if(!bNoSketchWasSelected && ext) + if(!bNoSketchWasSelected && ext) pickDlg->showExternal(true); Gui::Control().showDialog(pickDlg); @@ -1741,6 +1816,7 @@ void CreatePartDesignCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + rcCmdMgr.addCommand(new CmdPartDesignShapeBinder()); rcCmdMgr.addCommand(new CmdPartDesignPlane()); rcCmdMgr.addCommand(new CmdPartDesignLine()); rcCmdMgr.addCommand(new CmdPartDesignPoint()); diff --git a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc index 2c5223a22..7a85866d3 100644 --- a/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc +++ b/src/Mod/PartDesign/Gui/Resources/PartDesign.qrc @@ -16,6 +16,7 @@ icons/PartDesign_Hole.svg icons/PartDesign_Body.svg icons/PartDesign_Boolean.svg + icons/PartDesign_ShapeBinder.svg icons/PartDesign_Plane.svg icons/PartDesign_Line.svg icons/PartDesign_Point.svg diff --git a/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_ShapeBinder.svg b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_ShapeBinder.svg new file mode 100644 index 000000000..29a70e920 --- /dev/null +++ b/src/Mod/PartDesign/Gui/Resources/icons/PartDesign_ShapeBinder.svg @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp b/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp index 3cf6b5a80..f10ba6db3 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderShapeBinder.cpp @@ -38,6 +38,24 @@ PROPERTY_SOURCE(PartDesignGui::ViewProviderShapeBinder,PartGui::ViewProviderPart ViewProviderShapeBinder::ViewProviderShapeBinder() { sPixmap = "PartDesign_ShapeBinder.svg"; + + //make the viewprovider more datum like + AngularDeflection.StatusBits.set(3, true); + Deviation.StatusBits.set(3, true); + DrawStyle.StatusBits.set(3, true); + Lighting.StatusBits.set(3, true); + LineColor.StatusBits.set(3, true); + LineWidth.StatusBits.set(3, true); + PointColor.StatusBits.set(3, true); + PointSize.StatusBits.set(3, true); + ShapeColor.StatusBits.set(3, true); + Transparency.StatusBits.set(3, true); + + //get the datum coloring sheme + ShapeColor.setValue(App::Color(0.9f, 0.9f, 0.13f, 0.5f)); + LineColor.setValue(App::Color(0.9f, 0.9f, 0.13f, 0.5f)); + PointColor.setValue(App::Color(0.9f, 0.9f, 0.13f, 0.5f)); + LineWidth.setValue(1); } ViewProviderShapeBinder::~ViewProviderShapeBinder() diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index bc51d2d16..b8ebf8417 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -462,6 +462,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "PartDesign_Point" << "PartDesign_Line" << "PartDesign_Plane" + << "PartDesign_ShapeBinder" << "Separator" << "PartDesign_Pad" << "PartDesign_Pocket" @@ -521,6 +522,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const << "PartDesign_Point" << "PartDesign_Line" << "PartDesign_Plane" + << "PartDesign_ShapeBinder" << "Separator" << "PartDesign_CompPrimitiveAdditive" << "PartDesign_CompPrimitiveSubtractive"