add method to get view that contains a given node

This commit is contained in:
wmayer 2016-08-14 18:01:10 +02:00
parent 9ad302526b
commit 549236f517
6 changed files with 31 additions and 7 deletions

View File

@ -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());

View File

@ -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

View File

@ -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();

View File

@ -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;

View File

@ -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

View File

@ -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