diff --git a/src/Gui/Document.cpp b/src/Gui/Document.cpp index de7c6c3a3..de05933ef 100644 --- a/src/Gui/Document.cpp +++ b/src/Gui/Document.cpp @@ -1321,23 +1321,23 @@ MDIView* Document::getActiveView(void) const return active; } -Gui::MDIView* Document::getViewOfViewProvider(Gui::ViewProvider* vp) const +Gui::MDIView* Document::getViewOfNode(SoNode* node) const { std::list mdis = getMDIViewsOfType(View3DInventor::getClassTypeId()); for (std::list::const_iterator it = mdis.begin(); it != mdis.end(); ++it) { View3DInventor* view = static_cast(*it); - SoSearchAction searchAction; - searchAction.setNode(vp->getRoot()); - searchAction.setInterest(SoSearchAction::FIRST); - searchAction.apply(view->getViewer()->getSceneGraph()); - SoPath* selectionPath = searchAction.getPath(); - if (selectionPath) + if (view->getViewer()->searchNode(node)) return *it; } return 0; } +Gui::MDIView* Document::getViewOfViewProvider(Gui::ViewProvider* vp) const +{ + return getViewOfNode(vp->getRoot()); +} + Gui::MDIView* Document::getEditingViewOfViewProvider(Gui::ViewProvider* vp) const { std::list mdis = getMDIViewsOfType(View3DInventor::getClassTypeId()); diff --git a/src/Gui/Document.h b/src/Gui/Document.h index 04b577885..6a3268dfd 100644 --- a/src/Gui/Document.h +++ b/src/Gui/Document.h @@ -35,6 +35,7 @@ #include "Tree.h" +class SoNode; class SoPath; namespace Base { @@ -156,6 +157,7 @@ public: Gui::MDIView* getActiveView(void) const; Gui::MDIView* getEditingViewOfViewProvider(Gui::ViewProvider*) const; Gui::MDIView* getViewOfViewProvider(Gui::ViewProvider*) const; + Gui::MDIView* getViewOfNode(SoNode*) const; /// Create a new view void createView(const Base::Type& typeId); /** send messages to the active view diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 7a37ddf28..ec0e5f6b5 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -600,6 +600,16 @@ void View3DInventorViewer::OnChange(Gui::SelectionSingleton::SubjectType& rCalle } /// @endcond +SbBool View3DInventorViewer::searchNode(SoNode* node) const +{ + SoSearchAction searchAction; + searchAction.setNode(node); + searchAction.setInterest(SoSearchAction::FIRST); + searchAction.apply(this->getSceneGraph()); + SoPath* selectionPath = searchAction.getPath(); + return selectionPath ? true : false; +} + SbBool View3DInventorViewer::hasViewProvider(ViewProvider* pcProvider) const { return _ViewProviderSet.find(pcProvider) != _ViewProviderSet.end(); diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 879c978c8..fb4ac5851 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -138,6 +138,7 @@ public: void setBacklight(SbBool on); SbBool isBacklight(void) const; void setSceneGraph (SoNode *root); + SbBool searchNode(SoNode*) const; void setAnimationEnabled(const SbBool enable); SbBool isAnimationEnabled(void) const; diff --git a/src/Gui/ViewProviderDocumentObject.cpp b/src/Gui/ViewProviderDocumentObject.cpp index afebf9dbb..41786889b 100644 --- a/src/Gui/ViewProviderDocumentObject.cpp +++ b/src/Gui/ViewProviderDocumentObject.cpp @@ -208,6 +208,13 @@ Gui::MDIView* ViewProviderDocumentObject::getInventorView() const return mdi; } +Gui::MDIView* ViewProviderDocumentObject::getViewOfNode(SoNode* node) const +{ + App::Document* pAppDoc = pcObject->getDocument(); + Gui::Document* pGuiDoc = Gui::Application::Instance->getDocument(pAppDoc); + return pGuiDoc->getViewOfNode(node); +} + SoNode* ViewProviderDocumentObject::findFrontRootOfType(const SoType& type) const { // first get the document this object is part of and get its GUI counterpart diff --git a/src/Gui/ViewProviderDocumentObject.h b/src/Gui/ViewProviderDocumentObject.h index 501018c7c..823ca98f3 100644 --- a/src/Gui/ViewProviderDocumentObject.h +++ b/src/Gui/ViewProviderDocumentObject.h @@ -31,6 +31,7 @@ class SoMaterial; class SoDrawStyle; +class SoNode; class SoType; namespace App @@ -116,6 +117,9 @@ protected: If a value different to 0 is returned it is guaranteed to be a 3d view. */ Gui::MDIView* getInventorView() const; + /*! Get the mdi view of the document that contains the given \a node. + */ + Gui::MDIView* getViewOfNode(SoNode* node) const; /// get called before the value is changed virtual void onBeforeChange(const App::Property* prop); /// Gets called by the container whenever a property has been changed