diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index 7ca34d7a0..769355028 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -36,6 +36,8 @@ #include "Command.h" #include "ViewProviderPart.h" +#include "Application.h" +#include "MDIView.h" using namespace Gui; @@ -65,9 +67,29 @@ void ViewProviderPart::onChanged(const App::Property* prop) { bool ViewProviderPart::doubleClicked(void) { //make the part the active one - Gui::Command::doCommand(Gui::Command::Gui, - "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", - PARTKEY, this->getObject()->getNameInDocument()); + + //first, check if the part is already active. + App::DocumentObject* activePart = nullptr; + MDIView* activeView = this->getActiveView(); + if ( activeView ) { + activePart = activeView->getActiveObject (PARTKEY); + } + + if (activePart == this->getObject()){ + //active part double-clicked. Deactivate. + Gui::Command::doCommand(Gui::Command::Gui, + "Gui.getDocument('%s').ActiveView.setActiveObject('%s', None)", + this->getObject()->getDocument()->getName(), + PARTKEY); + } else { + //set new active part + Gui::Command::doCommand(Gui::Command::Gui, + "Gui.getDocument('%s').ActiveView.setActiveObject('%s', App.getDocument('%s').getObject('%s'))", + this->getObject()->getDocument()->getName(), + PARTKEY, + this->getObject()->getDocument()->getName(), + this->getObject()->getNameInDocument()); + } return true; } diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index cc678c5c7..723590020 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -53,6 +53,7 @@ #include "ViewProviderBody.h" #include "ViewProvider.h" +#include using namespace PartDesignGui; @@ -130,20 +131,42 @@ void ViewProviderBody::setOverrideMode(const std::string& mode) { bool ViewProviderBody::doubleClicked(void) { - // assure the PartDesign workbench - Gui::Command::assureWorkbench("PartDesignWorkbench"); - - // and set correct active objects - auto* part = App::Part::getPartOfObject ( getObject() ); - if ( part && part != getActiveView()->getActiveObject ( PARTKEY ) ) { - Gui::Command::doCommand ( Gui::Command::Gui, - "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", - PARTKEY, part->getNameInDocument() ); + //first, check if the body is already active. + App::DocumentObject* activeBody = nullptr; + Gui::MDIView* activeView = this->getActiveView(); + if ( activeView ) { + activeBody = activeView->getActiveObject (PDBODYKEY); } - Gui::Command::doCommand ( Gui::Command::Gui, - "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", - PDBODYKEY, this->getObject()->getNameInDocument() ); + if (activeBody == this->getObject()){ + //active body double-clicked. Deactivate. + Gui::Command::doCommand(Gui::Command::Gui, + "Gui.getDocument('%s').ActiveView.setActiveObject('%s', None)", + this->getObject()->getDocument()->getName(), + PDBODYKEY); + } else { + + // assure the PartDesign workbench + Gui::Command::assureWorkbench("PartDesignWorkbench"); + + // and set correct active objects + auto* part = App::Part::getPartOfObject ( getObject() ); + if ( part && part != getActiveView()->getActiveObject ( PARTKEY ) ) { + Gui::Command::doCommand(Gui::Command::Gui, + "Gui.getDocument('%s').ActiveView.setActiveObject('%s', App.getDocument('%s').getObject('%s'))", + part->getDocument()->getName(), + PARTKEY, + part->getDocument()->getName(), + part->getNameInDocument()); + } + + Gui::Command::doCommand(Gui::Command::Gui, + "Gui.getDocument('%s').ActiveView.setActiveObject('%s', App.getDocument('%s').getObject('%s'))", + this->getObject()->getDocument()->getName(), + PDBODYKEY, + this->getObject()->getDocument()->getName(), + this->getObject()->getNameInDocument()); + } return true; }