From ee712eecf85115f9934bb1a3259d8039936feaf5 Mon Sep 17 00:00:00 2001 From: jriegel Date: Sat, 5 May 2012 17:10:52 +0200 Subject: [PATCH] Automatic WB switching and Active PartDesign body --- src/Mod/Assembly/App/AppAssemblyPy.cpp | 4 ++-- src/Mod/Assembly/Gui/ViewProviderAssembly.cpp | 1 + src/Mod/PartDesign/App/Body.cpp | 10 ++++++++++ src/Mod/PartDesign/App/Body.h | 9 ++++++--- src/Mod/PartDesign/Gui/AppPartDesignGui.cpp | 2 ++ src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 8 ++++---- src/Mod/PartDesign/Gui/Workbench.cpp | 3 +++ 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp b/src/Mod/Assembly/App/AppAssemblyPy.cpp index 7be456d55b..30ff96e618 100644 --- a/src/Mod/Assembly/App/AppAssemblyPy.cpp +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp @@ -61,10 +61,10 @@ static PyObject * setActivePart(PyObject *self, PyObject *args) ActivePartObject = Item; ActiveGuiDoc = Gui::Application::Instance->getDocument(Item->getDocument()); ActiveVp = dynamic_cast (ActiveGuiDoc->getViewProvider(Item)) ; - ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,true); + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Underlined,true); }else{ - ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Blue,false); + ActiveGuiDoc->signalHighlightObject(*ActiveVp,Gui::Underlined,false); ActivePartObject = 0; } diff --git a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp index 23af658abf..49fe6fa71c 100644 --- a/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp +++ b/src/Mod/Assembly/Gui/ViewProviderAssembly.cpp @@ -47,6 +47,7 @@ ViewProviderItemAssembly::~ViewProviderItemAssembly() bool ViewProviderItemAssembly::doubleClicked(void) { + Gui::Command::assureWorkbench("AssemblyWorkbench"); Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.setActiveAssembly(App.activeDocument().%s)",this->getObject()->getNameInDocument()); return true; } diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index f435afc0e1..7110e04a08 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -28,6 +28,7 @@ #include #include "Body.h" +#include "BodyPy.h" using namespace PartDesign; @@ -56,4 +57,13 @@ App::DocumentObjectExecReturn *Body::execute(void) return App::DocumentObject::StdReturn; } +PyObject *Body::getPyObject(void) +{ + if (PythonObject.is(Py::_None())){ + // ref counter is set to 1 + PythonObject = Py::Object(new BodyPy(this),true); + } + return Py::new_reference_to(PythonObject); +} + } \ No newline at end of file diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index b66fc752d4..ecf001f84b 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -44,10 +44,13 @@ public: App::DocumentObjectExecReturn *execute(void); short mustExecute() const; /// returns the type name of the view provider - //const char* getViewProviderName(void) const { - // return "PartDesignGui::ViewProviderBody"; - //} + const char* getViewProviderName(void) const { + return "PartDesignGui::ViewProviderBody"; + } //@} + + PyObject *getPyObject(void); + }; } //namespace PartDesign diff --git a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp index af202d08c2..af942d95f4 100644 --- a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp +++ b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp @@ -36,6 +36,7 @@ #include "Workbench.h" #include "ViewProviderPocket.h" +#include "ViewProviderBody.h" #include "ViewProviderPad.h" #include "ViewProviderChamfer.h" #include "ViewProviderFillet.h" @@ -105,6 +106,7 @@ PyMODINIT_FUNC initPartDesignGui() PartDesignGui::Workbench ::init(); PartDesignGui::ViewProvider ::init(); + PartDesignGui::ViewProviderBody ::init(); PartDesignGui::ViewProviderPocket ::init(); PartDesignGui::ViewProviderPad ::init(); PartDesignGui::ViewProviderRevolution ::init(); diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index 08472d0ca8..7d4b19c1ff 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -44,10 +44,10 @@ ViewProviderBody::~ViewProviderBody() bool ViewProviderBody::doubleClicked(void) { - std::string Msg("Change "); - Msg += this->pcObject->getNameInDocument(); - Gui::Command::openCommand(Msg.c_str()); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s',0)",this->pcObject->getNameInDocument()); + // assure the PartDesign workbench + Gui::Command::assureWorkbench("PartDesignWorkbench"); + Gui::Command::addModule(Gui::Command::Gui,"PartDesignGui"); + Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setActivePart(App.activeDocument().%s)",this->getObject()->getNameInDocument()); return true; } diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 07eb72ebbe..e327a071e0 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -34,6 +34,7 @@ #include #include #include +#include using namespace PartDesignGui; @@ -155,6 +156,8 @@ void Workbench::activated() void Workbench::deactivated() { + Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setActivePart(None)"); + Gui::Workbench::deactivated(); removeTaskWatcher();