diff --git a/src/Gui/ActiveObjectList.cpp b/src/Gui/ActiveObjectList.cpp index c0c22c455..c9ab78b36 100644 --- a/src/Gui/ActiveObjectList.cpp +++ b/src/Gui/ActiveObjectList.cpp @@ -29,18 +29,28 @@ #endif #include "ActiveObjectList.h" +#include +#include +#include using namespace Gui; -void Gui::ActiveObjectList::setObject(App::DocumentObject* obj, const char* name) +void Gui::ActiveObjectList::setObject(App::DocumentObject* obj, const char* name, const Gui::HighlightMode& mode) { - _ObjectMap[name] = obj; + if (obj){ + if (hasObject(name)){ + Gui::Application::Instance->activeDocument()->signalHighlightObject(*dynamic_cast(Gui::Application::Instance->activeDocument()->getViewProvider(getObject(name))), mode, false); + } + _ObjectMap[name] = obj; + + Gui::Application::Instance->activeDocument()->signalHighlightObject(*dynamic_cast(Gui::Application::Instance->activeDocument()->getViewProvider(obj)), mode, true); + } } -bool Gui::ActiveObjectList::hasObject(const char*name) +bool Gui::ActiveObjectList::hasObject(const char*name)const { return _ObjectMap.find(name) != _ObjectMap.end(); } diff --git a/src/Gui/ActiveObjectList.h b/src/Gui/ActiveObjectList.h index 3174ff147..d145e9f2a 100644 --- a/src/Gui/ActiveObjectList.h +++ b/src/Gui/ActiveObjectList.h @@ -27,6 +27,7 @@ #define GUI_ActiveObjectList_H #include +#include "Tree.h" namespace App { class DocumentObject; } @@ -48,13 +49,13 @@ namespace Gui public: template - inline _T getObject(const char* name) + inline _T getObject(const char* name) const { std::map::const_iterator pos = _ObjectMap.find(name); return pos == _ObjectMap.end() ? 0 : dynamic_cast<_T>(pos->second); } - void setObject(App::DocumentObject*, const char*); - bool hasObject(const char*); + void setObject(App::DocumentObject*, const char*, const Gui::HighlightMode& m = Gui::LightBlue); + bool hasObject(const char*)const; protected: std::map _ObjectMap; diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 5df8be631..5ae746261 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -321,6 +321,15 @@ struct PyMethodDef FreeCADGui_methods[] = { {NULL, NULL} /* sentinel */ }; + +Gui::MDIView* Application::activeView(void) const +{ + if (activeDocument()) + return activeDocument()->getActiveView(); + else + return NULL; +} + } // namespace Gui Application::Application(bool GUIenabled) diff --git a/src/Gui/Application.h b/src/Gui/Application.h index ea9ed2f19..d5d8e71ee 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -147,7 +147,9 @@ public: * If no such document exists 0 is returned. */ Gui::Document* getDocument(const App::Document* pDoc) const; - /// Shows the associated view provider of the given object + /// Getter for the active view of the active document or null + Gui::MDIView* activeView(void) const; + /// Shows the associated view provider of the given object void showViewProvider(const App::DocumentObject*); /// Hides the associated view provider of the given object void hideViewProvider(const App::DocumentObject*); diff --git a/src/Gui/MDIView.cpp b/src/Gui/MDIView.cpp index e29bd3e4a..68098b7db 100644 --- a/src/Gui/MDIView.cpp +++ b/src/Gui/MDIView.cpp @@ -38,7 +38,6 @@ #include "Document.h" #include "Application.h" #include "MainWindow.h" -#include "ActiveObjectList.h" using namespace Gui; @@ -49,7 +48,6 @@ MDIView::MDIView(Gui::Document* pcDocument,QWidget* parent, Qt::WindowFlags wfla : QMainWindow(parent, wflags), BaseView(pcDocument),currentMode(Child), wstate(Qt::WindowNoState) { setAttribute(Qt::WA_DeleteOnClose); - pcActiveObjects = new ActiveObjectList(); } MDIView::~MDIView() @@ -73,7 +71,6 @@ MDIView::~MDIView() } } - delete pcActiveObjects; } void MDIView::deleteSelf() diff --git a/src/Gui/MDIView.h b/src/Gui/MDIView.h index 5fd6abcf2..29597c7bc 100644 --- a/src/Gui/MDIView.h +++ b/src/Gui/MDIView.h @@ -26,6 +26,7 @@ #include "View.h" #include +#include "ActiveObjectList.h" QT_BEGIN_NAMESPACE class QPrinter; @@ -34,7 +35,6 @@ QT_END_NAMESPACE namespace Gui { class Document; -class ActiveObjectList; /** Base class of all windows belonging to a document. * There are two ways of belonging to a document: @@ -109,7 +109,21 @@ public: virtual void setCurrentViewMode(ViewMode mode); ViewMode currentViewMode() const { return currentMode; } - ActiveObjectList *pcActiveObjects; + + /// access getter for the active object list + template + inline _T getActiveObject(const char* name) const + { + return ActiveObjects.getObject<_T>(name); + }; + void setActiveObject(App::DocumentObject*o, const char*n) + { + ActiveObjects.setObject(o, n); + }; + bool hasActiveObject(const char*n) const + { + return ActiveObjects.hasObject(n); + }; public Q_SLOTS: virtual void setOverrideCursor(const QCursor&); @@ -133,6 +147,8 @@ protected: private: ViewMode currentMode; Qt::WindowStates wstate; + // list of active objects of this view + ActiveObjectList ActiveObjects; }; } // namespace Gui diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index e9fffda82..67a67a56c 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -229,7 +229,7 @@ Py::Object View3DInventorPy::getattr(const char * attr) } else { // see if a active object has the same name - App::DocumentObject *docObj = _view->pcActiveObjects->getObject(attr); + App::DocumentObject *docObj = _view->getActiveObject(attr); if (docObj){ return Py::Object(docObj->getPyObject(),true); }else{ @@ -2181,7 +2181,7 @@ Py::Object View3DInventorPy::setActiveObject(const Py::Tuple& args) if (docObject){ App::DocumentObject* obj = static_cast(docObject)->getDocumentObjectPtr(); - _view->pcActiveObjects->setObject(obj, name); + _view->setActiveObject(obj, name); } return Py::None(); } diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp b/src/Mod/Assembly/App/AppAssemblyPy.cpp index fae9f9ce9..84afbbef0 100644 --- a/src/Mod/Assembly/App/AppAssemblyPy.cpp +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp @@ -43,53 +43,48 @@ namespace PartDesignGui { -// pointer to the active assembly object -PartDesign::Body *ActivePartObject =0; -Gui::Document *ActiveGuiDoc =0; -App::Document *ActiveAppDoc =0; -Gui::ViewProviderDocumentObject *ActiveVp =0; - // The names of the base planes. Note: The user-visible label is different from this const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"}; } -static PyObject * setActiveBody(PyObject *self, PyObject *args) -{ - PyObject *object=0; - if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) { - PartDesign::Body* Item = static_cast(object)->getBodyPtr(); - // Should be set! - assert(Item); - - // Set old body inactive if we are activating another body in the same document - if ((PartDesignGui::ActivePartObject != NULL) && - (PartDesignGui::ActivePartObject->getDocument() == Item->getDocument())) - PartDesignGui::ActivePartObject->IsActive.setValue(false); - PartDesignGui::ActivePartObject = Item; - PartDesignGui::ActiveAppDoc = Item->getDocument(); - PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc); - PartDesignGui::ActiveVp = dynamic_cast (PartDesignGui::ActiveGuiDoc->getViewProvider(Item)); - PartDesignGui::ActiveVp->show(); - Item->IsActive.setValue(true); - } else { - // This handles the case of deactivating the workbench - PartDesignGui::ActivePartObject=0; - PartDesignGui::ActiveGuiDoc =0; - PartDesignGui::ActiveAppDoc =0; - PartDesignGui::ActiveVp =0; - } - - Py_Return; -} -static PyObject * getActiveBody(PyObject *, PyObject *) -{ - if (PartDesignGui::ActivePartObject == NULL) { - return Py::_None(); - } - - return PartDesignGui::ActivePartObject->getPyObject(); -} +//static PyObject * setActiveBody(PyObject *self, PyObject *args) +//{ +// PyObject *object=0; +// if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) { +// PartDesign::Body* Item = static_cast(object)->getBodyPtr(); +// // Should be set! +// assert(Item); +// +// // Set old body inactive if we are activating another body in the same document +// if ((PartDesignGui::ActivePartObject != NULL) && +// (PartDesignGui::ActivePartObject->getDocument() == Item->getDocument())) +// PartDesignGui::ActivePartObject->IsActive.setValue(false); +// PartDesignGui::ActivePartObject = Item; +// PartDesignGui::ActiveAppDoc = Item->getDocument(); +// PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc); +// PartDesignGui::ActiveVp = dynamic_cast (PartDesignGui::ActiveGuiDoc->getViewProvider(Item)); +// PartDesignGui::ActiveVp->show(); +// Item->IsActive.setValue(true); +// } else { +// // This handles the case of deactivating the workbench +// PartDesignGui::ActivePartObject=0; +// PartDesignGui::ActiveGuiDoc =0; +// PartDesignGui::ActiveAppDoc =0; +// PartDesignGui::ActiveVp =0; +// } +// +// Py_Return; +//} +// +//static PyObject * getActiveBody(PyObject *, PyObject *) +//{ +// if (PartDesignGui::ActivePartObject == NULL) { +// return Py::_None(); +// } +// +// return PartDesignGui::ActivePartObject->getPyObject(); +//} void setUpPart(App::Part *part); @@ -112,11 +107,11 @@ static PyObject * setUpPart(PyObject *self, PyObject *args) /* registration table */ struct PyMethodDef Assembly_methods[] = { - {"setActiveBody" ,setActiveBody ,METH_VARARGS, - "setActiveBody(BodyObject) -- Set the PartBody object in work."}, + //{"setActiveBody" ,setActiveBody ,METH_VARARGS, + // "setActiveBody(BodyObject) -- Set the PartBody object in work."}, - {"getActiveBody" ,getActiveBody ,METH_NOARGS, - "getActiveBody() -- Get the PartBody object in work."}, + //{"getActiveBody" ,getActiveBody ,METH_NOARGS, + // "getActiveBody() -- Get the PartBody object in work."}, {"setUpPart" ,setUpPart ,METH_VARARGS, "setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."}, diff --git a/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig b/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig index 7b47311dd..7bc0f2455 100644 --- a/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig +++ b/src/Mod/Assembly/App/AppAssemblyPy.cpp.orig @@ -43,17 +43,12 @@ namespace PartDesignGui { -// pointer to the active assembly object -PartDesign::Body *ActivePartObject =0; -Gui::Document *ActiveGuiDoc =0; -App::Document *ActiveAppDoc =0; -Gui::ViewProviderDocumentObject *ActiveVp =0; - // The names of the base planes. Note: The user-visible label is different from this const char* BaseplaneNames[3] = {"BaseplaneXY", "BaseplaneXZ", "BaseplaneYZ"}; } +<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp static PyObject * setActiveBody(PyObject *self, PyObject *args) { PyObject *object=0; @@ -82,12 +77,7 @@ static PyObject * setActiveBody(PyObject *self, PyObject *args) Py_Return; } -<<<<<<< 394f4c51924312cf9cfcce09be5c3ba696a82cf4:src/Mod/Assembly/App/AppAssemblyPy.cpp -static PyObject * getActivePart(PyObject *, PyObject *) -======= - static PyObject * getActiveBody(PyObject *, PyObject *) ->>>>>>> Assembly: Rename to setActiveBody and make link indeipendant Part initialization:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp { if (PartDesignGui::ActivePartObject == NULL) { return Py::_None(); @@ -95,6 +85,45 @@ static PyObject * getActiveBody(PyObject *, PyObject *) return PartDesignGui::ActivePartObject->getPyObject(); } +======= +//static PyObject * setActiveBody(PyObject *self, PyObject *args) +//{ +// PyObject *object=0; +// if (PyArg_ParseTuple(args,"|O!",&(PartDesign::BodyPy::Type), &object)&& object) { +// PartDesign::Body* Item = static_cast(object)->getBodyPtr(); +// // Should be set! +// assert(Item); +// +// // Set old body inactive if we are activating another body in the same document +// if ((PartDesignGui::ActivePartObject != NULL) && +// (PartDesignGui::ActivePartObject->getDocument() == Item->getDocument())) +// PartDesignGui::ActivePartObject->IsActive.setValue(false); +// PartDesignGui::ActivePartObject = Item; +// PartDesignGui::ActiveAppDoc = Item->getDocument(); +// PartDesignGui::ActiveGuiDoc = Gui::Application::Instance->getDocument(PartDesignGui::ActiveAppDoc); +// PartDesignGui::ActiveVp = dynamic_cast (PartDesignGui::ActiveGuiDoc->getViewProvider(Item)); +// PartDesignGui::ActiveVp->show(); +// Item->IsActive.setValue(true); +// } else { +// // This handles the case of deactivating the workbench +// PartDesignGui::ActivePartObject=0; +// PartDesignGui::ActiveGuiDoc =0; +// PartDesignGui::ActiveAppDoc =0; +// PartDesignGui::ActiveVp =0; +// } +// +// Py_Return; +//} +// +//static PyObject * getActiveBody(PyObject *, PyObject *) +//{ +// if (PartDesignGui::ActivePartObject == NULL) { +// return Py::_None(); +// } +// +// return PartDesignGui::ActivePartObject->getPyObject(); +//} +>>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp void setUpPart(App::Part *part); @@ -116,18 +145,18 @@ static PyObject * setUpPart(PyObject *self, PyObject *args) /* registration table */ -<<<<<<< 394f4c51924312cf9cfcce09be5c3ba696a82cf4:src/Mod/Assembly/App/AppAssemblyPy.cpp +<<<<<<< 4db2e50e38d4a9c01764fa8dedb78231fc64faee:src/Mod/Assembly/App/AppAssemblyPy.cpp struct PyMethodDef Assembly_methods[] = { - {"setActivePart" ,setActivePart ,METH_VARARGS, - "setActivePart(BodyObject) -- Set the PartBody object in work."}, -======= -struct PyMethodDef PartDesignGui_Import_methods[] = { {"setActiveBody" ,setActiveBody ,METH_VARARGS, "setActiveBody(BodyObject) -- Set the PartBody object in work."}, +======= +struct PyMethodDef PartDesignGui_Import_methods[] = { + //{"setActiveBody" ,setActiveBody ,METH_VARARGS, + // "setActiveBody(BodyObject) -- Set the PartBody object in work."}, +>>>>>>> Changing active object handling in PartDesign:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp - {"setActiveBody" ,getActiveBody ,METH_NOARGS, - "setActiveBody() -- Get the PartBody object in work."}, ->>>>>>> Assembly: Rename to setActiveBody and make link indeipendant Part initialization:src/Mod/PartDesign/Gui/AppPartDesignGuiPy.cpp + //{"getActiveBody" ,getActiveBody ,METH_NOARGS, + // "getActiveBody() -- Get the PartBody object in work."}, {"setUpPart" ,setUpPart ,METH_VARARGS, "setUpPart(Part) -- Sets a empty part object up for usage in PartDesign."}, diff --git a/src/Mod/PartDesign/App/Body.cpp b/src/Mod/PartDesign/App/Body.cpp index 9a4fffeec..0075fc4c6 100644 --- a/src/Mod/PartDesign/App/Body.cpp +++ b/src/Mod/PartDesign/App/Body.cpp @@ -53,7 +53,7 @@ PROPERTY_SOURCE(PartDesign::Body, Part::BodyBase) Body::Body() { - ADD_PROPERTY(IsActive,(0)); + //ADD_PROPERTY(IsActive,(0)); } /* diff --git a/src/Mod/PartDesign/App/Body.h b/src/Mod/PartDesign/App/Body.h index 6d3c27f25..d5218b3bf 100644 --- a/src/Mod/PartDesign/App/Body.h +++ b/src/Mod/PartDesign/App/Body.h @@ -40,7 +40,7 @@ class PartDesignExport Body : public Part::BodyBase public: /// True if this body feature is active or was active when the document was last closed - App::PropertyBool IsActive; + //App::PropertyBool IsActive; Body(); diff --git a/src/Mod/PartDesign/Gui/Command.cpp b/src/Mod/PartDesign/Gui/Command.cpp index 38b2e82be..762883a4e 100644 --- a/src/Mod/PartDesign/Gui/Command.cpp +++ b/src/Mod/PartDesign/Gui/Command.cpp @@ -250,13 +250,13 @@ void CmdPartDesignDuplicateSelection::activated(int iMsg) return; } - std::vector beforeFeatures = PartDesignGui::ActiveAppDoc->getObjects(); + std::vector beforeFeatures = getDocument()->getObjects(); openCommand("Duplicate a PartDesign object"); doCommand(Doc,"FreeCADGui.runCommand('Std_DuplicateSelection')"); // Find the features that were added - std::vector afterFeatures = PartDesignGui::ActiveAppDoc->getObjects(); + std::vector afterFeatures = getDocument()->getObjects(); std::vector newFeatures; std::set_difference(afterFeatures.begin(), afterFeatures.end(), beforeFeatures.begin(), beforeFeatures.end(), std::back_inserter(newFeatures)); @@ -1868,8 +1868,9 @@ void CmdPartDesignBoolean::activated(int iMsg) openCommand("Create Boolean"); + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); // Make sure we are working on the selected body - if (body != PartDesignGui::ActivePartObject) { + if (body != activeBody) { Gui::Selection().clearSelection(); Gui::Selection().addSelection(body->getDocument()->getName(), body->Tip.getValue()->getNameInDocument()); Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')"); diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp index 10f01c2a9..702474121 100644 --- a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -31,6 +31,9 @@ #endif #include +#include +#include +#include #include #include #include @@ -48,6 +51,9 @@ using namespace Gui; bool ReferenceSelection::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) { + PartDesign::Body* ActivePartObject = Gui::Application::Instance->activeView()->getActiveObject("Body"); + App::Part* activePart = Gui::Application::Instance->activeView()->getActiveObject("Part"); + // Don't allow selection in other document if ((support != NULL) && (pDoc != support->getDocument())) return false; diff --git a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp index ef3a49f63..b2a2eca1b 100644 --- a/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDatumParameters.cpp @@ -435,7 +435,8 @@ void TaskDatumParameters::onCheckFlip(bool on) void TaskDatumParameters::onButtonRef(const bool pressed, const int idx) { // Note: Even if there is no solid, App::Plane and Part::Datum can still be selected - App::DocumentObject* solid = PartDesignGui::ActivePartObject->getPrevSolidFeature(); + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + App::DocumentObject* solid = activeBody->getPrevSolidFeature(); if (pressed) { Gui::Selection().clearSelection(); @@ -506,12 +507,13 @@ void TaskDatumParameters::onRefName(const QString& text, const int idx) if (obj == NULL) return; std::string subElement; + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { // everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree) subElement = ""; } else if (obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { - if (!PartDesignGui::ActivePartObject->hasFeature(obj)) + if (!activeBody->hasFeature(obj)) return; subElement = ""; } else { @@ -713,7 +715,8 @@ bool TaskDlgDatumParameters::accept() Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),parameter->getAngle()); //Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Checked = %i",name.c_str(),parameter->getCheckBox1()?1:0); - App::DocumentObject* solid = PartDesignGui::ActivePartObject->getPrevSolidFeature(); + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + App::DocumentObject* solid = activeBody->getPrevSolidFeature(); if (solid != NULL) { QString buf = QString::fromAscii("["); for (int r = 0; r < 3; r++) { @@ -746,11 +749,12 @@ bool TaskDlgDatumParameters::reject() Gui::Command::abortCommand(); Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); // Body housekeeping - if (ActivePartObject != NULL) { + if (activeBody != NULL) { // Make the new Tip and the previous solid feature visible again - App::DocumentObject* tip = ActivePartObject->Tip.getValue(); - App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature(); + App::DocumentObject* tip = activeBody->Tip.getValue(); + App::DocumentObject* prev = activeBody->getPrevSolidFeature(); if (tip != NULL) { Gui::Application::Instance->getViewProvider(tip)->show(); if ((tip != prev) && (prev != NULL)) diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index 09b2b2987..43dda43fa 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -240,10 +240,11 @@ bool TaskDlgDressUpParameters::reject() Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); // Body housekeeping - if (ActivePartObject != NULL) { + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + if (activeBody != NULL) { // Make the new Tip and the previous solid feature visible again - App::DocumentObject* tip = ActivePartObject->Tip.getValue(); - App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature(); + App::DocumentObject* tip = activeBody->Tip.getValue(); + App::DocumentObject* prev = activeBody->getPrevSolidFeature(); if (tip != NULL) { Gui::Application::Instance->getViewProvider(tip)->show(); if ((tip != prev) && (prev != NULL)) diff --git a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp b/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp index c3a7a530c..f2ddee2e2 100644 --- a/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskGrooveParameters.cpp @@ -408,21 +408,20 @@ bool TaskDlgGrooveParameters::reject() Gui::Application::Instance->getViewProvider(pcSketch)->show(); } - // Body housekeeping - if (ActivePartObject != NULL) { - // Make the new Tip and the previous solid feature visible again - App::DocumentObject* tip = ActivePartObject->Tip.getValue(); - App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature(); - if (tip != NULL) { - Gui::Application::Instance->getViewProvider(tip)->show(); - if ((tip != prev) && (prev != NULL)) - Gui::Application::Instance->getViewProvider(prev)->show(); - } - } +// // Body housekeeping +// if (ActivePartObject != NULL) { +// // Make the new Tip and the previous solid feature visible again +// App::DocumentObject* tip = ActivePartObject->Tip.getValue(); +// App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature(); +// if (tip != NULL) { +// Gui::Application::Instance->getViewProvider(tip)->show(); +// if ((tip != prev) && (prev != NULL)) +// Gui::Application::Instance->getViewProvider(prev)->show(); +// } +// } return true; } - #include "moc_TaskGrooveParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index 76203ad29..c32aa8a33 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -91,8 +91,9 @@ const QString TaskSketchBasedParameters::onAddSelection(const Gui::SelectionChan void TaskSketchBasedParameters::onSelectReference(const bool pressed, const bool edge, const bool face, const bool planar) { // Note: Even if there is no solid, App::Plane and Part::Datum can still be selected - App::DocumentObject* prevSolid = PartDesignGui::ActivePartObject->getPrevSolidFeature(vp->getObject(), false); - App::DocumentObject* curSolid = PartDesignGui::ActivePartObject->getPrevSolidFeature(); + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + App::DocumentObject* prevSolid = activeBody->getPrevSolidFeature(vp->getObject(), false); + App::DocumentObject* curSolid = activeBody->getPrevSolidFeature(); if (pressed) { Gui::Document* doc = Gui::Application::Instance->activeDocument(); @@ -135,11 +136,12 @@ const QByteArray TaskSketchBasedParameters::onFaceName(const QString& text) if (obj == NULL) return QByteArray(); + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) { // everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree) return QByteArray(); } else if (obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { - if (!PartDesignGui::ActivePartObject->hasFeature(obj)) + if (!activeBody->hasFeature(obj)) return QByteArray(); return QByteArray(); } else { @@ -243,10 +245,11 @@ bool TaskDlgSketchBasedParameters::reject() } // Body housekeeping - if (ActivePartObject != NULL) { + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + if (activeBody != NULL) { // Make the new Tip and the previous solid feature visible again - App::DocumentObject* tip = ActivePartObject->Tip.getValue(); - App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature(); + App::DocumentObject* tip = activeBody->Tip.getValue(); + App::DocumentObject* prev = activeBody->getPrevSolidFeature(); if (tip != NULL) { Gui::Application::Instance->getViewProvider(tip)->show(); if ((tip != prev) && (prev != NULL)) diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index 803266391..85c15b5ff 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -340,10 +340,11 @@ bool TaskDlgTransformedParameters::reject() Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); // Body housekeeping - if (ActivePartObject != NULL) { + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + if (activeBody != NULL) { // Make the new Tip and the previous solid feature visible again - App::DocumentObject* tip = ActivePartObject->Tip.getValue(); - App::DocumentObject* prev = ActivePartObject->getPrevSolidFeature(); + App::DocumentObject* tip = activeBody->Tip.getValue(); + App::DocumentObject* prev = activeBody->getPrevSolidFeature(); if (tip != NULL) { Gui::Application::Instance->getViewProvider(tip)->show(); if ((tip != prev) && (prev != NULL)) diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp index d63ccf808..6b76d3a37 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.cpp +++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -51,10 +52,11 @@ ViewProvider::~ViewProvider() bool ViewProvider::doubleClicked(void) { - if (PartDesignGui::ActivePartObject != NULL) { + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + if (activeBody != NULL) { // Drop into insert mode so that the user doesn't see all the geometry that comes later in the tree // Also, this way the user won't be tempted to use future geometry as external references for the sketch - oldTip = ActivePartObject->Tip.getValue(); + oldTip = activeBody->Tip.getValue(); if (oldTip != this->pcObject) Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')"); else @@ -83,8 +85,9 @@ void ViewProvider::unsetEdit(int ModNum) if (ModNum == ViewProvider::Default) { // when pressing ESC make sure to close the dialog + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); Gui::Control().closeDialog(); - if ((PartDesignGui::ActivePartObject != NULL) && (oldTip != NULL)) { + if ((activeBody != NULL) && (oldTip != NULL)) { Gui::Selection().clearSelection(); Gui::Selection().addSelection(oldTip->getDocument()->getName(), oldTip->getNameInDocument()); Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')"); diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index d9af01e3c..3ec58f731 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -104,8 +104,9 @@ bool ViewProviderBody::doubleClicked(void) { // assure the PartDesign workbench Gui::Command::assureWorkbench("PartDesignWorkbench"); - Gui::Command::addModule(Gui::Command::Gui,"PartDesignGui"); - Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)",this->getObject()->getNameInDocument()); + //Gui::Command::doCommand(Gui::Command::Gui,"PartDesignGui.setActiveBody(App.activeDocument().%s)",this->getObject()->getNameInDocument()); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeView.setActiveBody(App.activeDocument().%s)",this->getObject()->getNameInDocument()); + return true; } @@ -148,40 +149,40 @@ std::vector ViewProviderBody::claimChildren3D(void)const } -void ViewProviderBody::updateTree() -{ - if (ActiveGuiDoc == NULL) return; - - // Highlight active body and all its features - //Base::Console().Error("ViewProviderBody::updateTree()\n"); - PartDesign::Body* body = static_cast(getObject()); - bool active = body->IsActive.getValue(); - //Base::Console().Error("Body is %s\n", active ? "active" : "inactive"); - ActiveGuiDoc->signalHighlightObject(*this, Gui::Blue, active); - std::vector features = body->Model.getValues(); - bool highlight = true; - App::DocumentObject* tip = body->Tip.getValue(); - for (std::vector::const_iterator f = features.begin(); f != features.end(); f++) { - //Base::Console().Error("Highlighting %s: %s\n", (*f)->getNameInDocument(), highlight ? "true" : "false"); - Gui::ViewProviderDocumentObject* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*f)); - if (vp != NULL) - ActiveGuiDoc->signalHighlightObject(*vp, Gui::LightBlue, active ? highlight : false); - if (highlight && (tip == *f)) - highlight = false; - } -} +//void ViewProviderBody::updateTree() +//{ +// if (ActiveGuiDoc == NULL) return; +// +// // Highlight active body and all its features +// //Base::Console().Error("ViewProviderBody::updateTree()\n"); +// PartDesign::Body* body = static_cast(getObject()); +// bool active = body->IsActive.getValue(); +// //Base::Console().Error("Body is %s\n", active ? "active" : "inactive"); +// ActiveGuiDoc->signalHighlightObject(*this, Gui::Blue, active); +// std::vector features = body->Model.getValues(); +// bool highlight = true; +// App::DocumentObject* tip = body->Tip.getValue(); +// for (std::vector::const_iterator f = features.begin(); f != features.end(); f++) { +// //Base::Console().Error("Highlighting %s: %s\n", (*f)->getNameInDocument(), highlight ? "true" : "false"); +// Gui::ViewProviderDocumentObject* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*f)); +// if (vp != NULL) +// ActiveGuiDoc->signalHighlightObject(*vp, Gui::LightBlue, active ? highlight : false); +// if (highlight && (tip == *f)) +// highlight = false; +// } +//} void ViewProviderBody::updateData(const App::Property* prop) { //Base::Console().Error("ViewProviderBody::updateData for %s\n", getObject()->getNameInDocument()); - if (ActiveGuiDoc == NULL) - // PartDesign workbench not active - return PartGui::ViewProviderPart::updateData(prop); + //if (ActiveGuiDoc == NULL) + // // PartDesign workbench not active + // return PartGui::ViewProviderPart::updateData(prop); - if ((prop->getTypeId() == App::PropertyBool::getClassTypeId() && strcmp(prop->getName(),"IsActive") == 0) || - (prop->getTypeId() == App::PropertyLink::getClassTypeId() && strcmp(prop->getName(),"Tip") == 0) || - (prop->getTypeId() == App::PropertyLinkList::getClassTypeId() && strcmp(prop->getName(),"Model") == 0)) - updateTree(); + //if ((/*prop->getTypeId() == App::PropertyBool::getClassTypeId() && strcmp(prop->getName(),"IsActive") == 0) ||*/ + // (prop->getTypeId() == App::PropertyLink::getClassTypeId() && strcmp(prop->getName(),"Tip") == 0) || + // (prop->getTypeId() == App::PropertyLinkList::getClassTypeId() && strcmp(prop->getName(),"Model") == 0)) + // // updateTree(); // Update the visual size of datum lines and planes PartDesign::Body* body = static_cast(getObject()); diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.h b/src/Mod/PartDesign/Gui/ViewProviderBody.h index 6c2539a95..301028aa2 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.h +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.h @@ -67,7 +67,7 @@ private: SoGroup *pcBodyTip; /// Update the children's highlighting - void updateTree(); + //void updateTree(); }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp index 51dbddd66..31dc56a92 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatum.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include using namespace PartDesignGui; @@ -275,10 +276,11 @@ bool ViewProviderDatum::doubleClicked(void) std::string Msg("Edit "); Msg += this->pcObject->Label.getValue(); Gui::Command::openCommand(Msg.c_str()); - if (PartDesignGui::ActivePartObject != NULL) { + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + if (activeBody != NULL) { // Drop into insert mode so that the user doesn't see all the geometry that comes later in the tree // Also, this way the user won't be tempted to use future geometry as external references for the sketch - oldTip = ActivePartObject->Tip.getValue(); + oldTip = activeBody->Tip.getValue(); if (oldTip != this->pcObject) Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')"); else @@ -299,8 +301,9 @@ void ViewProviderDatum::unsetEdit(int ModNum) if (ModNum == ViewProvider::Default) { // when pressing ESC make sure to close the dialog Gui::Control().closeDialog(); + PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); - if ((PartDesignGui::ActivePartObject != NULL) && (oldTip != NULL)) { + if ((activeBody != NULL) && (oldTip != NULL)) { Gui::Selection().clearSelection(); Gui::Selection().addSelection(oldTip->getDocument()->getName(), oldTip->getNameInDocument()); Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')"); diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index f5efc1233..25ef5573d 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -75,15 +75,17 @@ namespace PartDesignGui { PartDesign::Body *getBody(void) { - if(!PartDesignGui::ActivePartObject){ + PartDesign::Body * activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + + if (activeBody){ QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No active Body"), QObject::tr("In order to use PartDesign you need an active Body object in the document. " - "Please make one active or create one. If you have a legacy document " + "Please make one active (double click) or create one. If you have a legacy document " "with PartDesign objects without Body, use the transfer function in " "PartDesign to put them into a Body." )); } - return PartDesignGui::ActivePartObject; + return activeBody; } @@ -182,14 +184,14 @@ void Workbench::_doMigration(const App::Document* doc) // Always create at least the first body, even if the document is empty // This adds both the base planes and the body Gui::Command::runCommand(Gui::Command::Doc, "FreeCADGui.runCommand('PartDesign_Body')"); - PartDesign::Body *activeBody = PartDesignGui::ActivePartObject; + PartDesign::Body *activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); // Create one Body for every root and put the appropriate features into it for (std::vector::iterator r = roots.begin(); r != roots.end(); r++) { if (r != roots.begin()) { Gui::Command::runCommand(Gui::Command::Doc, "FreeCADGui.runCommand('PartDesign_Body')"); - activeBody = PartDesignGui::ActivePartObject; + activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); } std::set inList; @@ -352,7 +354,7 @@ void Workbench::_switchToDocument(const App::Document* doc) Gui::Command::doCommand(Gui::Command::Doc, "PartDesignGui.setUpPart(App.activeDocument().%s)", PartName.c_str()); Gui::Command::doCommand(Gui::Command::Gui, "Gui.activeView().setActiveObject('Part',App.activeDocument().%s)", PartName.c_str()); - activeBody = Gui::Application::Instance->activeDocument()->getActiveView()->pcActiveObjects->getObject("Body"); + activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); // body have to be created assert(activeBody); @@ -363,8 +365,11 @@ void Workbench::_switchToDocument(const App::Document* doc) } else { - activeBody = Gui::Application::Instance->activeDocument()->getActiveView()->pcActiveObjects->getObject("Body"); - activePart = Gui::Application::Instance->activeDocument()->getActiveView()->pcActiveObjects->getObject("Part"); + activeBody = Gui::Application::Instance->activeView()->getActiveObject("Body"); + activePart = Gui::Application::Instance->activeView()->getActiveObject("Part"); + + // document change not implemented yet + assert(activePart->getDocument() == doc); //// Find active body //for (std::vector::const_iterator b = bodies.begin(); b != bodies.end(); b++) { @@ -441,10 +446,10 @@ void Workbench::slotFinishRestoreDocument(const App::Document& Doc) void Workbench::slotDeleteDocument(const App::Document&) { - ActivePartObject = 0; - ActiveGuiDoc = 0; - ActiveAppDoc = 0; - ActiveVp = 0; + //ActivePartObject = 0; + //ActiveGuiDoc = 0; + //ActiveAppDoc = 0; + //ActiveVp = 0; } /* This does not work for Std_DuplicateSelection: @@ -650,7 +655,7 @@ void Workbench::activated() )); // make the previously used active Body active again - PartDesignGui::ActivePartObject = NULL; + //PartDesignGui::ActivePartObject = NULL; _switchToDocument(App::GetApplication().getActiveDocument()); addTaskWatcher(Watcher); diff --git a/src/Mod/PartDesign/Gui/Workbench.h b/src/Mod/PartDesign/Gui/Workbench.h index 0de375b0d..5f3d574ac 100644 --- a/src/Mod/PartDesign/Gui/Workbench.h +++ b/src/Mod/PartDesign/Gui/Workbench.h @@ -45,10 +45,10 @@ namespace App { namespace PartDesignGui { // pointer to the active assembly object -extern PartDesign::Body *ActivePartObject; -extern Gui::Document *ActiveGuiDoc; -extern App::Document *ActiveAppDoc; -extern Gui::ViewProviderDocumentObject *ActiveVp; +//extern PartDesign::Body *ActivePartObject; +//extern Gui::Document *ActiveGuiDoc; +//extern App::Document *ActiveAppDoc; +//extern Gui::ViewProviderDocumentObject *ActiveVp; // The names of the base planes extern const char* BaseplaneNames[3];