Skip to content

Commit

Permalink
add method to get view that contains a given node
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 14, 2016
1 parent 9ad3025 commit 549236f
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Gui/Document.cpp
Expand Up @@ -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<MDIView*> mdis = getMDIViewsOfType(View3DInventor::getClassTypeId());
for (std::list<MDIView*>::const_iterator it = mdis.begin(); it != mdis.end(); ++it) {
View3DInventor* view = static_cast<View3DInventor*>(*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<MDIView*> mdis = getMDIViewsOfType(View3DInventor::getClassTypeId());
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/Document.h
Expand Up @@ -35,6 +35,7 @@

#include "Tree.h"

class SoNode;
class SoPath;

namespace Base {
Expand Down Expand Up @@ -156,6 +157,7 @@ class GuiExport Document : public Base::Persistence
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
Expand Down
10 changes: 10 additions & 0 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/Gui/View3DInventorViewer.h
Expand Up @@ -138,6 +138,7 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi
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;
Expand Down
7 changes: 7 additions & 0 deletions src/Gui/ViewProviderDocumentObject.cpp
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/Gui/ViewProviderDocumentObject.h
Expand Up @@ -31,6 +31,7 @@

class SoMaterial;
class SoDrawStyle;
class SoNode;
class SoType;

namespace App
Expand Down Expand Up @@ -116,6 +117,9 @@ class GuiExport ViewProviderDocumentObject : public ViewProvider
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
Expand Down

0 comments on commit 549236f

Please sign in to comment.