From c3763479da0e78cb8334da3f18eea939a199a23b Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 5 Jul 2019 18:53:35 +0200 Subject: [PATCH] activate/create 3d view when setting or getting active objects --- src/Gui/CommandStructure.cpp | 3 ++- src/Gui/ViewProviderPart.cpp | 2 ++ src/Mod/PartDesign/Gui/CommandBody.cpp | 3 ++- src/Mod/PartDesign/Gui/Utils.cpp | 1 + src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 3 +++ src/Mod/PartDesign/Gui/ViewProviderDatum.cpp | 1 + src/Mod/PartDesign/TestPartDesignGui.py | 2 ++ 7 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Gui/CommandStructure.cpp b/src/Gui/CommandStructure.cpp index d54428d218..b9e8b02ec2 100644 --- a/src/Gui/CommandStructure.cpp +++ b/src/Gui/CommandStructure.cpp @@ -69,7 +69,8 @@ void StdCmdPart::activated(int iMsg) // TODO We really must set label ourselves? (2015-08-17, Fat-Zer) doCommand(Doc,"App.activeDocument().%s.Label = '%s'", PartName.c_str(), QObject::tr(PartName.c_str()).toUtf8().data()); - doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", + doCommand(Gui::Command::Gui, "Gui.activateView('Gui::View3DInventor', True)\n" + "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PARTKEY, PartName.c_str()); updateActive(); diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index d59f10b494..5f7fc088c2 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -94,12 +94,14 @@ bool ViewProviderPart::doubleClicked(void) if (activePart == this->getObject()){ //active part double-clicked. Deactivate. Gui::Command::doCommand(Gui::Command::Gui, + "Gui.activateView('Gui::View3DInventor', True)\n" "Gui.getDocument('%s').ActiveView.setActiveObject('%s', None)", this->getObject()->getDocument()->getName(), PARTKEY); } else { //set new active part Gui::Command::doCommand(Gui::Command::Gui, + "Gui.activateView('Gui::View3DInventor', True)\n" "Gui.getDocument('%s').ActiveView.setActiveObject('%s', App.getDocument('%s').getObject('%s'))", this->getObject()->getDocument()->getName(), PARTKEY, diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index b295dbd964..c432e48cd0 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -218,7 +218,8 @@ void CmdPartDesignBody::activated(int iMsg) } } addModule(Gui,"PartDesignGui"); // import the Gui module only once a session - doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", + doCommand(Gui::Command::Gui, "Gui.activateView('Gui::View3DInventor', True)\n" + "Gui.activeView().setActiveObject('%s', App.activeDocument().%s)", PDBODYKEY, bodyName.c_str()); // Make the "Create sketch" prompt appear in the task panel diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 8072ecccb7..8f0cec62c9 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -80,6 +80,7 @@ PartDesign::Body *getBody(bool messageIfNot, bool autoActivate, bool assertModer if (!activeBody && singleBodyDocument && autoActivate) { Gui::Command::doCommand( Gui::Command::Gui, + "Gui.activateView('Gui::View3DInventor', True)\n" "Gui.activeView().setActiveObject('pdbody',App.ActiveDocument.findObjects('PartDesign::Body')[0])"); activeBody = activeView->getActiveObject(PDBODYKEY); return activeBody; diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index 4b450ce3f5..82541f4761 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -152,6 +152,7 @@ bool ViewProviderBody::doubleClicked(void) if (activeBody == this->getObject()){ //active body double-clicked. Deactivate. Gui::Command::doCommand(Gui::Command::Gui, + "Gui.activateView('Gui::View3DInventor', True)\n" "Gui.getDocument('%s').ActiveView.setActiveObject('%s', None)", this->getObject()->getDocument()->getName(), PDBODYKEY); @@ -164,6 +165,7 @@ bool ViewProviderBody::doubleClicked(void) auto* part = App::Part::getPartOfObject ( getObject() ); if ( part && part != getActiveView()->getActiveObject ( PARTKEY ) ) { Gui::Command::doCommand(Gui::Command::Gui, + "Gui.activateView('Gui::View3DInventor', True)\n" "Gui.getDocument('%s').ActiveView.setActiveObject('%s', App.getDocument('%s').getObject('%s'))", part->getDocument()->getName(), PARTKEY, @@ -172,6 +174,7 @@ bool ViewProviderBody::doubleClicked(void) } Gui::Command::doCommand(Gui::Command::Gui, + "Gui.activateView('Gui::View3DInventor', True)\n" "Gui.getDocument('%s').ActiveView.setActiveObject('%s', App.getDocument('%s').getObject('%s'))", this->getObject()->getDocument()->getName(), PDBODYKEY, diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp index 4c0475b0f0..1d807538cf 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp @@ -294,6 +294,7 @@ bool ViewProviderDatum::doubleClicked(void) if (datumBody != NULL) { if (datumBody != activeBody) { Gui::Command::doCommand(Gui::Command::Gui, + "Gui.activateView('Gui::View3DInventor', True)\n" "Gui.getDocument('%s').ActiveView.setActiveObject('%s', App.getDocument('%s').getObject('%s'))", datumBody->getDocument()->getName(), PDBODYKEY, diff --git a/src/Mod/PartDesign/TestPartDesignGui.py b/src/Mod/PartDesign/TestPartDesignGui.py index aaee07ed77..9174dcceea 100644 --- a/src/Mod/PartDesign/TestPartDesignGui.py +++ b/src/Mod/PartDesign/TestPartDesignGui.py @@ -87,6 +87,7 @@ class PartDesignGuiTestCases(unittest.TestCase): def testRefuseToMoveSingleFeature(self): FreeCAD.Console.PrintMessage('Testing refuse to move the feature with dependencies from one body to another\n') self.BodySource = self.Doc.addObject('PartDesign::Body','Body') + Gui.activateView('Gui::View3DInventor', True) Gui.activeView().setActiveObject('pdbody', self.BodySource) self.BoxObj = self.Doc.addObject('PartDesign::AdditiveBox','Box') @@ -147,6 +148,7 @@ class PartDesignGuiTestCases(unittest.TestCase): def testMoveSingleFeature(self): FreeCAD.Console.PrintMessage('Testing moving one feature from one body to another\n') self.BodySource = self.Doc.addObject('PartDesign::Body','Body') + Gui.activateView('Gui::View3DInventor', True) Gui.activeView().setActiveObject('pdbody', self.BodySource) self.Sketch = self.Doc.addObject('Sketcher::SketchObject','Sketch')