From 57732f74414a036a4689fffe4038aa65bdeb0bc8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 3 Jan 2018 21:35:03 +0100 Subject: [PATCH] add option to getBodyFor to suppress dialog to set workflow style to modern --- src/Mod/PartDesign/Gui/Utils.cpp | 9 +++++---- src/Mod/PartDesign/Gui/Utils.h | 5 +++-- src/Mod/PartDesign/Gui/Workbench.cpp | 11 ++++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index ba51ed0491..a71fdbdaa7 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -67,7 +67,7 @@ namespace PartDesignGui { * \param autoActivate * \return Body */ -PartDesign::Body *getBody(bool messageIfNot, bool autoActivate) +PartDesign::Body *getBody(bool messageIfNot, bool autoActivate, bool assertModern) { PartDesign::Body * activeBody = nullptr; Gui::MDIView *activeView = Gui::Application::Instance->activeView(); @@ -75,7 +75,7 @@ PartDesign::Body *getBody(bool messageIfNot, bool autoActivate) if (activeView) { bool singleBodyDocument = activeView->getAppDocument()-> countObjectsOfType(PartDesign::Body::getClassTypeId()) == 1; - if ( PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { + if (assertModern && PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { activeBody = activeView->getActiveObject(PDBODYKEY); if (!activeBody && singleBodyDocument && autoActivate) { @@ -122,12 +122,13 @@ PartDesign::Body * makeBody(App::Document *doc) return activeView->getActiveObject(PDBODYKEY); } -PartDesign::Body *getBodyFor(const App::DocumentObject* obj, bool messageIfNot, bool autoActivate) +PartDesign::Body *getBodyFor(const App::DocumentObject* obj, bool messageIfNot, + bool autoActivate, bool assertModern) { if(!obj) return nullptr; - PartDesign::Body * rv = getBody(/*messageIfNot =*/false, autoActivate); + PartDesign::Body * rv = getBody(/*messageIfNot =*/false, autoActivate, assertModern); if (rv && rv->hasObject(obj)) return rv; diff --git a/src/Mod/PartDesign/Gui/Utils.h b/src/Mod/PartDesign/Gui/Utils.h index 0c3e6d911c..446a8ed011 100644 --- a/src/Mod/PartDesign/Gui/Utils.h +++ b/src/Mod/PartDesign/Gui/Utils.h @@ -44,7 +44,7 @@ namespace Sketcher { namespace PartDesignGui { /// Return active body or show a warning message -PartDesign::Body *getBody(bool messageIfNot, bool autoActivate=true); +PartDesign::Body *getBody(bool messageIfNot, bool autoActivate=true, bool assertModern=true); /// Display error when there are existing Body objects, but none are active void needActiveBodyError(void); @@ -56,7 +56,8 @@ PartDesign::Body * makeBody(App::Document *doc); * Finds a body for the given feature. And shows a message if not found * Also unlike Body::findBodyFor it checks if the active body has the feature first. */ -PartDesign::Body *getBodyFor(const App::DocumentObject*, bool messageIfNot, bool autoActivate=true); +PartDesign::Body *getBodyFor(const App::DocumentObject*, bool messageIfNot, + bool autoActivate=true, bool assertModern=true); App::Part *getPartFor(const App::DocumentObject*, bool messageIfNot); App::Part *getActivePart(); diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 380a566fab..346f66d3df 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -163,7 +163,16 @@ void Workbench::setupContextMenu(const char* recipient, Gui::MenuItem* item) con // Add move Tip Command if ( selection.size () >= 1 ) { App::DocumentObject *feature = selection.front().pObject; - PartDesign::Body *body = PartDesignGui::getBodyFor (feature, false, false); + PartDesign::Body *body = nullptr; + + // if PD workflow is not new-style then add a command to the context-menu + bool assertModern = true; + if (feature && !isModernWorkflow(feature->getDocument())) { + assertModern = false; + *item << "PartDesign_Migrate"; + } + + body = PartDesignGui::getBodyFor (feature, false, false, assertModern); // lote of assertion so feature should be marked as a tip if ( selection.size () == 1 && feature && ( feature->isDerivedFrom ( PartDesign::Body::getClassTypeId () ) ||