From 8678f74dc63cb5977829d25ca080841666486b8c Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 23 Oct 2018 12:47:11 +0200 Subject: [PATCH] allow to access NaviCube of 3d viewer --- src/Gui/CommandView.cpp | 7 +++- src/Gui/NaviCube.h | 2 +- src/Gui/View3DInventorViewer.cpp | 61 ++++++++++++++++++++++++-------- src/Gui/View3DInventorViewer.h | 1 + 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index 856bd24072..dc168b9984 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -2003,7 +2003,12 @@ protected: { Gui::View3DInventor* view = qobject_cast(Gui::getMainWindow()->activeWindow()); if (view) { - SoGroup* group = static_cast(view->getViewer()->getSceneGraph()); + Gui::View3DInventorViewer* viewer = view->getViewer(); + if (!viewer) + return false; // no active viewer + SoGroup* group = dynamic_cast(viewer->getSceneGraph()); + if (!group) + return false; // empty scene graph bool hasaxis = group->findChild(axisGroup) != -1; if (_pcAction->isChecked() != hasaxis) _pcAction->setChecked(hasaxis); diff --git a/src/Gui/NaviCube.h b/src/Gui/NaviCube.h index 3af12fc0f1..3f75c1b1b0 100644 --- a/src/Gui/NaviCube.h +++ b/src/Gui/NaviCube.h @@ -33,7 +33,7 @@ class View3DInventorViewer; class NaviCubeImplementation; -class NaviCube { +class GuiExport NaviCube { public: enum Corner { TopLeftCorner, diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 04d0e716df..f55e49e1a9 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -85,6 +85,8 @@ # include #endif +#include + #include #include #include @@ -876,6 +878,11 @@ void View3DInventorViewer::setNaviCubeCorner(int c) naviCube->setCorner(static_cast(c)); } +NaviCube* View3DInventorViewer::getNavigationCube() const +{ + return naviCube; +} + void View3DInventorViewer::setAxisCross(bool on) { SoNode* scene = getSceneGraph(); @@ -2158,28 +2165,52 @@ void View3DInventorViewer::setCameraType(SoType t) } } +namespace Gui { + class CameraAnimation : public QVariantAnimation + { + SoCamera* camera; + SbRotation startRot, endRot; + SbVec3f startPos, endPos; + + public: + CameraAnimation(SoCamera* camera, const SbRotation& rot, const SbVec3f& pos) + : camera(camera), endRot(rot), endPos(pos) + { + startPos = camera->position.getValue(); + startRot = camera->orientation.getValue(); + } + virtual ~CameraAnimation() + { + } + protected: + void updateCurrentValue(const QVariant & value) + { + int steps = endValue().toInt(); + int curr = value.toInt(); + + float s = static_cast(curr)/static_cast(steps); + SbVec3f curpos = startPos * (1.0f-s) + endPos * s; + SbRotation currot = SbRotation::slerp(startRot, endRot, s); + camera->orientation.setValue(currot); + camera->position.setValue(curpos); + } + }; +} + void View3DInventorViewer::moveCameraTo(const SbRotation& rot, const SbVec3f& pos, int steps, int ms) { SoCamera* cam = this->getSoRenderManager()->getCamera(); if (cam == 0) return; - SbVec3f campos = cam->position.getValue(); - SbRotation camrot = cam->orientation.getValue(); + CameraAnimation anim(cam, rot, pos); + anim.setDuration(Base::clamp(ms,0,5000)); + anim.setStartValue(static_cast(0)); + anim.setEndValue(steps); QEventLoop loop; - QTimer timer; - timer.setSingleShot(true); - QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - - for (int i=0; iorientation.setValue(currot); - cam->position.setValue(curpos); - timer.start(Base::clamp(ms,0,5000)); - loop.exec(QEventLoop::ExcludeUserInputEvents); - } + QObject::connect(&anim, SIGNAL(finished()), &loop, SLOT(quit())); + anim.start(); + loop.exec(QEventLoop::ExcludeUserInputEvents); cam->orientation.setValue(rot); cam->position.setValue(pos); diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index c8809e83fc..278ec84c27 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -349,6 +349,7 @@ public: void setEnabledNaviCube(bool b); bool isEnabledNaviCube(void) const; void setNaviCubeCorner(int); + NaviCube* getNavigationCube() const; void setEnabledVBO(bool b); bool isEnabledVBO() const;