allow to access NaviCube of 3d viewer

This commit is contained in:
wmayer
2018-10-23 12:47:11 +02:00
parent 7c4ab45e31
commit 8678f74dc6
4 changed files with 54 additions and 17 deletions

View File

@@ -2003,7 +2003,12 @@ protected:
{
Gui::View3DInventor* view = qobject_cast<View3DInventor*>(Gui::getMainWindow()->activeWindow());
if (view) {
SoGroup* group = static_cast<SoGroup*>(view->getViewer()->getSceneGraph());
Gui::View3DInventorViewer* viewer = view->getViewer();
if (!viewer)
return false; // no active viewer
SoGroup* group = dynamic_cast<SoGroup*>(viewer->getSceneGraph());
if (!group)
return false; // empty scene graph
bool hasaxis = group->findChild(axisGroup) != -1;
if (_pcAction->isChecked() != hasaxis)
_pcAction->setChecked(hasaxis);

View File

@@ -33,7 +33,7 @@ class View3DInventorViewer;
class NaviCubeImplementation;
class NaviCube {
class GuiExport NaviCube {
public:
enum Corner {
TopLeftCorner,

View File

@@ -85,6 +85,8 @@
# include <QMimeData>
#endif
#include <QVariantAnimation>
#include <sstream>
#include <Base/Console.h>
#include <Base/Stream.h>
@@ -876,6 +878,11 @@ void View3DInventorViewer::setNaviCubeCorner(int c)
naviCube->setCorner(static_cast<NaviCube::Corner>(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<float>(curr)/static_cast<float>(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<int>(ms,0,5000));
anim.setStartValue(static_cast<int>(0));
anim.setEndValue(steps);
QEventLoop loop;
QTimer timer;
timer.setSingleShot(true);
QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
for (int i=0; i<steps; i++) {
float s = float(i)/float(steps);
SbVec3f curpos = campos * (1.0f-s) + pos * s;
SbRotation currot = SbRotation::slerp(camrot, rot, s);
cam->orientation.setValue(currot);
cam->position.setValue(curpos);
timer.start(Base::clamp<int>(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);

View File

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