From acd88878afb11d8d738c751b648d7c62bb7f9709 Mon Sep 17 00:00:00 2001 From: jrheinlaender Date: Sun, 31 Mar 2013 16:03:13 +0430 Subject: [PATCH] When switching to the PartDesign workbench, activate the Body feature that was active when the document was last saved, and move the selection to its Tip feature so that the user can start creating new features right away --- src/Mod/Assembly/App/AppAssemblyPy.cpp | 2 ++ src/Mod/PartDesign/App/Body.cpp | 2 +- src/Mod/PartDesign/App/Body.h | 4 ++++ src/Mod/PartDesign/App/FeaturePad.cpp | 2 +- src/Mod/PartDesign/Gui/Workbench.cpp | 24 +++++++++++++++++++++--- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp b/src/Mod/Assembly/App/AppAssemblyPy.cpp index 133c8fdd5..e048646e9 100644 --- a/src/Mod/Assembly/App/AppAssemblyPy.cpp +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp @@ -55,6 +55,7 @@ static PyObject * setActivePart(PyObject *self, PyObject *args) break; } + ActivePartObject->IsActive.setValue(false); ActivePartObject = 0; ActiveGuiDoc =0; ActiveAppDoc =0; @@ -67,6 +68,7 @@ static PyObject * setActivePart(PyObject *self, PyObject *args) // Should be set! assert(Item); + Item->IsActive.setValue(true); ActivePartObject = Item; ActiveAppDoc = Item->getDocument(); ActiveGuiDoc = Gui::Application::Instance->getDocument(ActiveAppDoc); diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 27af6aada..40e33035d 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -43,7 +43,7 @@ PROPERTY_SOURCE(PartDesign::Body, Part::BodyBase) Body::Body() { - + ADD_PROPERTY(IsActive,(0)); } short Body::mustExecute() const diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index 074bb0e73..b72a183cc 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -38,6 +38,10 @@ class Body : public Part::BodyBase PROPERTY_HEADER(PartDesign::Body); public: + + /// True if this body feature is active or was active when the document was last closed + App::PropertyBool IsActive; + Body(); /** @name methods override feature */ diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index c8df8364b..0a1e262b9 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -96,7 +96,7 @@ App::DocumentObjectExecReturn *Pad::execute(void) return new App::DocumentObjectExecReturn(e.what()); } - // Find active Body feature and get the shape of the feature preceding this one for fusing + // Find Body feature which owns this Pad and get the shape of the feature preceding this one for fusing PartDesign::Body* body = getBody(); if (body == NULL) { return new App::DocumentObjectExecReturn( diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 20bbfff1c..3738605ba 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -151,9 +151,26 @@ void Workbench::activated() "PartDesign_MultiTransform" )); - // set the previous used active Body - if(oldActive != "") - Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setActivePart(App.activeDocument().%s)",oldActive.c_str()); + // make the previously used active Body active again + PartDesign::Body* activeBody = NULL; + std::vector bodies = App::GetApplication().getActiveDocument()->getObjectsOfType(PartDesign::Body::getClassTypeId()); + for (std::vector::const_iterator b = bodies.begin(); b != bodies.end(); b++) { + PartDesign::Body* body = static_cast(*b); + if (body->IsActive.getValue()) { + activeBody = body; + break; + } + } + // If there is only one body, make it active + if ((activeBody == NULL) && (bodies.size() == 1)) + activeBody = static_cast(bodies.front()); + + if (activeBody != NULL) { + Gui::Command::doCommand(Gui::Command::Doc,"import PartDesignGui"); + Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActivePart(App.activeDocument().%s)", activeBody->getNameInDocument()); + // Move selection to the Tip feature so that the user can start creating new features right away + Gui::Command::doCommand(Gui::Command::Gui,"Gui.Selection.addSelection(App.ActiveDocument.%s.Tip)", activeBody->getNameInDocument()); + } addTaskWatcher(Watcher); Gui::Control().showTaskView(); @@ -165,6 +182,7 @@ void Workbench::deactivated() { removeTaskWatcher(); // remember the body for later activation + // TODO: Remove this if the IsActive Property of Body works OK if(ActivePartObject) oldActive = ActivePartObject->getNameInDocument(); else