diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 6cd5153fe1..aa595e88b9 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -59,7 +59,15 @@ using namespace Attacher; namespace PartDesignGui { -PartDesign::Body *getBody(bool messageIfNot) +/*! + * \brief Return active body or show a warning message. + * If \a autoActivate is true (the default) then if there is + * only single body in the document it will be activated. + * \param messageIfNot + * \param autoActivate + * \return Body + */ +PartDesign::Body *getBody(bool messageIfNot, bool autoActivate) { PartDesign::Body * activeBody = nullptr; Gui::MDIView *activeView = Gui::Application::Instance->activeView(); @@ -70,7 +78,7 @@ PartDesign::Body *getBody(bool messageIfNot) if ( PartDesignGui::assureModernWorkflow ( activeView->getAppDocument() ) ) { activeBody = activeView->getActiveObject(PDBODYKEY); - if (!activeBody && singleBodyDocument) { + if (!activeBody && singleBodyDocument && autoActivate) { Gui::Command::doCommand( Gui::Command::Gui, "Gui.activeView().setActiveObject('pdbody',App.ActiveDocument.findObjects('PartDesign::Body')[0])"); activeBody = activeView->getActiveObject(PDBODYKEY); @@ -114,13 +122,13 @@ PartDesign::Body * makeBody(App::Document *doc) return activeView->getActiveObject(PDBODYKEY); } -PartDesign::Body *getBodyFor(const App::DocumentObject* obj, bool messageIfNot) +PartDesign::Body *getBodyFor(const App::DocumentObject* obj, bool messageIfNot, bool autoActivate) { if(!obj) return nullptr; - PartDesign::Body * rv = getBody( /*messageIfNot =*/ false); - if(rv && rv->hasObject(obj)) + PartDesign::Body * rv = getBody(/*messageIfNot =*/false, autoActivate); + if (rv && rv->hasObject(obj)) return rv; rv = PartDesign::Body::findBodyOf(obj); diff --git a/src/Mod/PartDesign/Gui/Utils.h b/src/Mod/PartDesign/Gui/Utils.h index b0b428d460..5e4e6a7422 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); +PartDesign::Body *getBody(bool messageIfNot, bool autoActivate=true); /// Display error when there are existing Body objects, but none are active void needActiveBodyError(void); @@ -56,7 +56,7 @@ 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); +PartDesign::Body *getBodyFor(const App::DocumentObject*, bool messageIfNot, bool autoActivate=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 8be2e6ad67..3ab2966d93 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -163,7 +163,7 @@ 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 ); + PartDesign::Body *body = PartDesignGui::getBodyFor (feature, false, false); // lote of assertion so feature should be marked as a tip if ( selection.size () == 1 && feature && ( feature->isDerivedFrom ( PartDesign::Body::getClassTypeId () ) ||