mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
This commit is contained in:
@@ -20,26 +20,35 @@
|
||||
#include "RiuCadNavigation.h"
|
||||
#include "cafViewer.h"
|
||||
#include "cvfCamera.h"
|
||||
#include "cvfScene.h"
|
||||
#include "cvfModel.h"
|
||||
#include "cvfViewport.h"
|
||||
#include "cvfHitItemCollection.h"
|
||||
#include "cvfRay.h"
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
|
||||
#include <QInputEvent>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
using cvf::ManipulatorTrackball;
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuCadNavigation::RiuCadNavigation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RiuCadNavigation::~RiuCadNavigation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuCadNavigation::init()
|
||||
{
|
||||
m_trackball = new cvf::ManipulatorTrackball;
|
||||
m_trackball->setCamera(m_viewer->mainCamera());
|
||||
m_isRotCenterInitialized = false;
|
||||
m_isRotating = false;
|
||||
caf::TrackBallBasedNavigation::init();
|
||||
m_navigationUpdated = false;
|
||||
}
|
||||
|
||||
@@ -62,7 +71,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
if (me->button() == Qt::LeftButton)
|
||||
{
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
||||
m_isRotating = true;
|
||||
m_isNavigating = true;
|
||||
isEventHandled = true;
|
||||
}
|
||||
else if (me->button() == Qt::MidButton)
|
||||
@@ -70,7 +79,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
if (me->modifiers() & Qt::ShiftModifier)
|
||||
{
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
||||
m_isRotating = true;
|
||||
m_isNavigating = true;
|
||||
isEventHandled = true;
|
||||
}
|
||||
else if (me->modifiers() == Qt::NoModifier)
|
||||
@@ -90,7 +99,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
|
||||
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
||||
//m_viewer->setCursor(RiuCursors::get(RiuCursors::ROTATE));
|
||||
m_isRotating = true;
|
||||
m_isNavigating = true;
|
||||
isEventHandled = true;
|
||||
}
|
||||
}
|
||||
@@ -103,14 +112,14 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
if (m_isRotating)
|
||||
if (m_isNavigating)
|
||||
{
|
||||
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
||||
if (me->button() == Qt::MidButton || me->button() == Qt::LeftButton)
|
||||
{
|
||||
m_trackball->endNavigation();
|
||||
//m_viewer->setCursor(RiuCursors::get(RiuCursors::PICK));
|
||||
m_isRotating = false;
|
||||
m_isNavigating = false;
|
||||
|
||||
isEventHandled = m_navigationUpdated;
|
||||
m_navigationUpdated = false;
|
||||
@@ -127,7 +136,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
int translatedMousePosX = me->x();
|
||||
int translatedMousePosY = m_viewer->height() - me->y();
|
||||
|
||||
if (m_isRotating)
|
||||
if (m_isNavigating)
|
||||
{
|
||||
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
||||
if (needRedraw)
|
||||
@@ -182,65 +191,3 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
return isEventHandled;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuCadNavigation::initializeRotationCenter()
|
||||
{
|
||||
if (m_isRotCenterInitialized
|
||||
|| m_trackball.isNull()
|
||||
|| !m_viewer->currentScene()->boundingBox().isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
cvf::Vec3d pointOfInterest = m_viewer->currentScene()->boundingBox().center();
|
||||
|
||||
this->setPointOfInterest(pointOfInterest);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Repositions and orients the camera to view the rotation point along the
|
||||
/// direction "alongDirection". The distance to the rotation point is maintained.
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuCadNavigation::setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection )
|
||||
{
|
||||
m_trackball->setView(alongDirection, upDirection);
|
||||
/*
|
||||
if (m_camera.isNull()) return;
|
||||
|
||||
Vec3d dir = alongDirection;
|
||||
if (!dir.normalize()) return;
|
||||
Vec3d up = upDirection;
|
||||
if(!up.normalize()) up = Vec3d::Z_AXIS;
|
||||
|
||||
if((up * dir) < 1e-2) up = dir.perpendicularVector();
|
||||
|
||||
Vec3d cToE = m_camera->position() - m_rotationPoint;
|
||||
Vec3d newEye = m_rotationPoint - cToE.length() * dir;
|
||||
|
||||
m_camera->setFromLookAt(newEye, m_rotationPoint, upDirection);
|
||||
*/
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
cvf::Vec3d RiuCadNavigation::pointOfInterest()
|
||||
{
|
||||
initializeRotationCenter();
|
||||
return m_pointOfInterest;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuCadNavigation::setPointOfInterest(cvf::Vec3d poi)
|
||||
{
|
||||
m_pointOfInterest = poi;
|
||||
m_trackball->setRotationPoint(poi);
|
||||
m_isRotCenterInitialized = true;
|
||||
m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user