Skip to content

Commit

Permalink
Gui: add virtual method containsViewProvider to MDIView and re-implem…
Browse files Browse the repository at this point in the history
…ent it in some sub-classes

Improve Document::setActiveView to not always switch to the first 3D view but check the currently active view before
  • Loading branch information
wwmayer committed Dec 29, 2019
1 parent ad95219 commit eb4e2d2
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 18 deletions.
46 changes: 29 additions & 17 deletions src/Gui/Document.cpp
Expand Up @@ -1956,44 +1956,56 @@ MDIView* Document::getActiveView(void) const
return 0;
}

MDIView *Document::setActiveView(ViewProviderDocumentObject *vp, Base::Type typeId) {
MDIView *view = 0;
if(!vp)
MDIView *Document::setActiveView(ViewProviderDocumentObject *vp, Base::Type typeId)
{
MDIView *view = nullptr;
if (!vp) {
view = getActiveView();
else{
}
else {
view = vp->getMDIView();
if(!view) {
if (!view) {
auto obj = vp->getObject();
if(!obj)
if (!obj) {
view = getActiveView();
}
else {
auto linked = obj->getLinkedObject(true);
if(linked!=obj) {
if (linked!=obj) {
auto vpLinked = dynamic_cast<ViewProviderDocumentObject*>(
Application::Instance->getViewProvider(linked));
if(vpLinked)
if (vpLinked)
view = vpLinked->getMDIView();
}
if(!view && typeId.isBad())
typeId = View3DInventor::getClassTypeId();

if (!view && typeId.isBad()) {
MDIView* active = getActiveView();
if (active && active->containsViewProvider(vp))
view = active;
else
typeId = View3DInventor::getClassTypeId();
}
}
}
}
if(!view || (!typeId.isBad() && !view->isDerivedFrom(typeId))) {
view = 0;

if (!view || (!typeId.isBad() && !view->isDerivedFrom(typeId))) {
view = nullptr;
for (auto *v : d->baseViews) {
if(v->isDerivedFrom(MDIView::getClassTypeId()) &&
(typeId.isBad() || v->isDerivedFrom(typeId)))
{
if (v->isDerivedFrom(MDIView::getClassTypeId()) &&
(typeId.isBad() || v->isDerivedFrom(typeId))) {
view = static_cast<MDIView*>(v);
break;
}
}
}
if(!view && !typeId.isBad())

if (!view && !typeId.isBad())
view = createView(typeId);
if(view)

if (view)
getMainWindow()->setActiveWindow(view);

return view;
}

Expand Down
11 changes: 11 additions & 0 deletions src/Gui/MDIView.h
Expand Up @@ -35,6 +35,7 @@ QT_END_NAMESPACE
namespace Gui
{
class Document;
class ViewProvider;
class ViewProviderDocumentObject;

/** Base class of all windows belonging to a document.
Expand Down Expand Up @@ -131,6 +132,16 @@ public Q_SLOTS:
return ActiveObjects.hasObject(o,n,subname);
}

/*!
* \brief containsViewProvider
* Checks if the given view provider is part of this view. The default implementation
* returns false.
* \return bool
*/
virtual bool containsViewProvider(const ViewProvider*) const {
return false;
}

public Q_SLOTS:
virtual void setOverrideCursor(const QCursor&);
virtual void restoreOverrideCursor();
Expand Down
10 changes: 10 additions & 0 deletions src/Gui/SplitView3DInventor.cpp
Expand Up @@ -72,6 +72,16 @@ void AbstractSplitView::deleteSelf()
MDIView::deleteSelf();
}

bool AbstractSplitView::containsViewProvider(const ViewProvider* vp) const
{
for (auto it = _viewer.begin(); it != _viewer.end(); ++it) {
if ((*it)->containsViewProvider(vp))
return true;
}

return false;
}

void AbstractSplitView::setupSettings()
{
// attach Parameter Observer
Expand Down
1 change: 1 addition & 0 deletions src/Gui/SplitView3DInventor.h
Expand Up @@ -56,6 +56,7 @@ class GuiExport AbstractSplitView : public MDIView, public ParameterGrp::Observe

View3DInventorViewer *getViewer(unsigned int) const;
void setOverrideCursor(const QCursor&);
virtual bool containsViewProvider(const ViewProvider*) const;

PyObject *getPyObject(void);
void setPyObject(PyObject *);
Expand Down
6 changes: 6 additions & 0 deletions src/Gui/View3DInventor.cpp
Expand Up @@ -84,6 +84,7 @@
#include <Inventor/nodes/SoOrthographicCamera.h>

#include "View3DInventorExamples.h"
#include "ViewProviderDocumentObject.h"
#include "SoFCSelectionAction.h"
#include "View3DPy.h"
#include "SoFCDB.h"
Expand Down Expand Up @@ -516,6 +517,11 @@ void View3DInventor::print(QPrinter* printer)
p.end();
}

bool View3DInventor::containsViewProvider(const ViewProvider* vp) const
{
return _viewer->containsViewProvider(vp);
}

// **********************************************************************************

bool View3DInventor::onMsg(const char* pMsg, const char** ppReturn)
Expand Down
3 changes: 2 additions & 1 deletion src/Gui/View3DInventor.h
Expand Up @@ -106,7 +106,8 @@ class GuiExport View3DInventor : public MDIView, public ParameterGrp::ObserverTy
void removeOverlayWidget();

View3DInventorViewer *getViewer(void) const {return _viewer;}

virtual bool containsViewProvider(const ViewProvider*) const;

public Q_SLOTS:
/// override the cursor in this view
void setOverrideCursor(const QCursor&);
Expand Down
9 changes: 9 additions & 0 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -968,6 +968,15 @@ SbBool View3DInventorViewer::hasViewProvider(ViewProvider* pcProvider) const
return _ViewProviderSet.find(pcProvider) != _ViewProviderSet.end();
}

SbBool View3DInventorViewer::containsViewProvider(const ViewProvider* vp) const

This comment has been minimized.

Copy link
@realthunder

realthunder Feb 17, 2020

Collaborator

@wwmayer Any reason to use SoSearchAction instead of just call hasViewProvider() function above? I am asking because for larger scene this causes noticeable slow down.

This comment has been minimized.

Copy link
@wwmayer

wwmayer Feb 17, 2020

Author Contributor

Because hasViewProvider only works for top-level view providers but it fails for all view providers that are claimed as children of another view provider because in this case they are removed from the set and map.

This comment has been minimized.

Copy link
@realthunder

realthunder Feb 17, 2020

Collaborator

I see. I forgot that my changes are still pending. After this commit, _ViewProviderSet will contain all view providers regardless of whether they are claimed or not.

{
SoSearchAction sa;
sa.setNode(const_cast<ViewProvider*>(vp)->getRoot());
sa.setSearchingAll(true);
sa.apply(getSoRenderManager()->getSceneGraph());
return sa.getPath() != nullptr;
}

/// adds an ViewProvider to the view, e.g. from a feature
void View3DInventorViewer::addViewProvider(ViewProvider* pcProvider)
{
Expand Down
5 changes: 5 additions & 0 deletions src/Gui/View3DInventorViewer.h
Expand Up @@ -181,7 +181,12 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi

/** @name Handling of view providers */
//@{
/// Checks if the view provider is a top-level object of the scene
SbBool hasViewProvider(ViewProvider*) const;
/// Checks if the view provider is part of the scene.
/// In contrast to hasViewProvider() this method also checks if the view
/// provider is a child of another view provider
SbBool containsViewProvider(const ViewProvider*) const;
/// adds an ViewProvider to the view, e.g. from a feature
void addViewProvider(ViewProvider*);
/// remove a ViewProvider
Expand Down

0 comments on commit eb4e2d2

Please sign in to comment.