From abc925b62e598b70c34cd3e6c525cd5d05b3ca14 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Mon, 17 Aug 2015 14:37:10 +0300 Subject: [PATCH] PartDesign/Gui: Make partDesign's add sketch command Workflow-aware --- src/Mod/PartDesign/Gui/Command.cpp | 16 +++++++++++----- src/Mod/PartDesign/Gui/Utils.cpp | 25 ++++++++++++++----------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 294e67f47..c478a306e 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -58,6 +58,7 @@ #include "TaskFeaturePick.h" #include "ReferenceSelection.h" #include "Utils.h" +#include "WorkflowManager.h" using namespace std; @@ -234,19 +235,24 @@ CmdPartDesignNewSketch::CmdPartDesignNewSketch() void CmdPartDesignNewSketch::activated(int iMsg) { - PartDesign::Body *pcActiveBody = PartDesignGui::getBody(/*messageIfNot = */false); + App::Document *doc = getDocument (); + PartDesign::Body *pcActiveBody = PartDesignGui::getBody( + /*messageIfNot = */ PartDesignGui::assureModernWorkflow ( doc ) ); // No PartDesign feature without Body past FreeCAD 0.13 - if(!pcActiveBody) { - Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); - rcCmdMgr.runCommandByName("Sketcher_NewSketch"); + if ( !pcActiveBody ) { + // Call normal sketch command for old workflow + if ( PartDesignGui::isLegacyWorkflow ( doc) ) { + Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); + rcCmdMgr.runCommandByName("Sketcher_NewSketch"); + } return; } Gui::SelectionFilter SketchFilter("SELECT Sketcher::SketchObject COUNT 1"); Gui::SelectionFilter FaceFilter ("SELECT Part::Feature SUBELEMENT Face COUNT 1"); Gui::SelectionFilter PlaneFilter ("SELECT App::Plane COUNT 1"); - Gui::SelectionFilter PlaneFilter2 ("SELECT PartDesign::Plane COUNT 1"); + Gui::SelectionFilter PlaneFilter2("SELECT PartDesign::Plane COUNT 1"); if (PlaneFilter2.match()) PlaneFilter = PlaneFilter2; diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 693e2b1f7..30b39f177 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -43,6 +43,7 @@ #include "ReferenceSelection.h" #include "Utils.h" +#include "WorkflowManager.h" //=========================================================================== // Helper for Body @@ -55,19 +56,21 @@ PartDesign::Body *getBody(bool messageIfNot) PartDesign::Body * activeBody = nullptr; Gui::MDIView *activeView = Gui::Application::Instance->activeView(); - if (activeView) { - activeBody = activeView->getActiveObject(PDBODYKEY); - } + if ( PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { - if (!activeBody && messageIfNot) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), - QObject::tr("In order to use PartDesign you need an active Body object in the document. " - "Please make one active (double click) or create one. If you have a legacy document " - "with PartDesign objects without Body, use the transfer function in " - "PartDesign to put them into a Body." - )); - } + if (activeView) { + activeBody = activeView->getActiveObject(PDBODYKEY); + } + if (!activeBody && messageIfNot) { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), + QObject::tr("In order to use PartDesign you need an active Body object in the document. " + "Please make one active (double click) or create one. If you have a legacy document " + "with PartDesign objects without Body, use the transfer function in " + "PartDesign to put them into a Body." + )); + } + } return activeBody; }