2015-07-02 05:31:35 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2015- Statoil ASA
|
|
|
|
// Copyright (C) 2015- Ceetron Solutions AS
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RiuCadNavigation.h"
|
|
|
|
#include "cafViewer.h"
|
|
|
|
#include "cvfCamera.h"
|
|
|
|
#include "cvfViewport.h"
|
|
|
|
#include "cvfHitItemCollection.h"
|
|
|
|
#include "cvfRay.h"
|
2015-12-09 08:51:38 -06:00
|
|
|
#include "cvfManipulatorTrackball.h"
|
2015-07-02 05:31:35 -05:00
|
|
|
|
|
|
|
#include <QInputEvent>
|
|
|
|
|
2015-12-09 08:51:38 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuCadNavigation::RiuCadNavigation()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RiuCadNavigation::~RiuCadNavigation()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2015-07-02 05:31:35 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RiuCadNavigation::init()
|
|
|
|
{
|
2015-12-09 08:51:38 -06:00
|
|
|
caf::TrackBallBasedNavigation::init();
|
2015-07-02 07:21:24 -05:00
|
|
|
m_navigationUpdated = false;
|
2015-07-02 05:31:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|
|
|
{
|
|
|
|
if (! inputEvent) return false;
|
|
|
|
bool isEventHandled = false;
|
|
|
|
|
|
|
|
switch (inputEvent->type())
|
|
|
|
{
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
{
|
|
|
|
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
|
|
|
int translatedMousePosX = me->x();
|
|
|
|
int translatedMousePosY = m_viewer->height() - me->y();
|
|
|
|
|
2015-07-02 07:21:24 -05:00
|
|
|
if (me->button() == Qt::LeftButton)
|
|
|
|
{
|
|
|
|
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
2015-12-09 08:51:38 -06:00
|
|
|
m_isNavigating = true;
|
2015-07-02 07:21:24 -05:00
|
|
|
isEventHandled = true;
|
|
|
|
}
|
|
|
|
else if (me->button() == Qt::MidButton)
|
2015-07-02 05:31:35 -05:00
|
|
|
{
|
|
|
|
if (me->modifiers() & Qt::ShiftModifier)
|
|
|
|
{
|
|
|
|
m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY);
|
2015-12-09 08:51:38 -06:00
|
|
|
m_isNavigating = true;
|
2015-07-02 05:31:35 -05:00
|
|
|
isEventHandled = true;
|
|
|
|
}
|
|
|
|
else if (me->modifiers() == Qt::NoModifier)
|
|
|
|
{
|
|
|
|
cvf::HitItemCollection hic;
|
|
|
|
bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic);
|
|
|
|
|
|
|
|
if (hitSomething)
|
|
|
|
{
|
|
|
|
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
|
2015-12-07 08:54:44 -06:00
|
|
|
this->setPointOfInterest(pointOfInterest);
|
2015-07-02 05:31:35 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
initializeRotationCenter();
|
|
|
|
}
|
|
|
|
|
|
|
|
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
|
|
|
|
//m_viewer->setCursor(RiuCursors::get(RiuCursors::ROTATE));
|
2015-12-09 08:51:38 -06:00
|
|
|
m_isNavigating = true;
|
2015-07-02 05:31:35 -05:00
|
|
|
isEventHandled = true;
|
|
|
|
}
|
|
|
|
}
|
2015-07-02 07:21:24 -05:00
|
|
|
|
|
|
|
if (isEventHandled)
|
2015-07-02 05:31:35 -05:00
|
|
|
{
|
2015-07-02 07:21:24 -05:00
|
|
|
m_navigationUpdated = false;
|
2015-07-02 05:31:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
{
|
2015-12-09 08:51:38 -06:00
|
|
|
if (m_isNavigating)
|
2015-07-02 05:31:35 -05:00
|
|
|
{
|
|
|
|
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
2015-07-02 07:21:24 -05:00
|
|
|
if (me->button() == Qt::MidButton || me->button() == Qt::LeftButton)
|
2015-07-02 05:31:35 -05:00
|
|
|
{
|
|
|
|
m_trackball->endNavigation();
|
|
|
|
//m_viewer->setCursor(RiuCursors::get(RiuCursors::PICK));
|
2015-12-09 08:51:38 -06:00
|
|
|
m_isNavigating = false;
|
2015-07-02 07:21:24 -05:00
|
|
|
|
|
|
|
isEventHandled = m_navigationUpdated;
|
|
|
|
m_navigationUpdated = false;
|
2015-07-02 05:31:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
{
|
|
|
|
initializeRotationCenter();
|
|
|
|
if (m_isRotCenterInitialized)
|
|
|
|
{
|
|
|
|
QMouseEvent * me = static_cast<QMouseEvent*>( inputEvent);
|
|
|
|
int translatedMousePosX = me->x();
|
|
|
|
int translatedMousePosY = m_viewer->height() - me->y();
|
|
|
|
|
2015-12-09 08:51:38 -06:00
|
|
|
if (m_isNavigating)
|
2015-07-02 05:31:35 -05:00
|
|
|
{
|
|
|
|
bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY);
|
|
|
|
if (needRedraw)
|
|
|
|
{
|
2015-09-01 11:04:35 -05:00
|
|
|
m_viewer->navigationPolicyUpdate();
|
2015-07-02 07:21:24 -05:00
|
|
|
m_navigationUpdated = true;
|
2015-07-02 05:31:35 -05:00
|
|
|
}
|
|
|
|
isEventHandled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QEvent::Wheel:
|
|
|
|
{
|
|
|
|
if (inputEvent->modifiers() == Qt::NoModifier)
|
|
|
|
{
|
|
|
|
initializeRotationCenter();
|
|
|
|
if (m_isRotCenterInitialized)
|
|
|
|
{
|
|
|
|
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
|
|
|
int translatedMousePosX = we->x();
|
|
|
|
int translatedMousePosY = m_viewer->height() - we->y();
|
|
|
|
|
|
|
|
cvf::ref<cvf::Ray> ray;
|
|
|
|
if (we->delta() > 0)
|
|
|
|
ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY);
|
|
|
|
else
|
|
|
|
ray = m_viewer->mainCamera()->rayFromWindowCoordinates((int)(1.0*translatedMousePosX), (int)(1.0*translatedMousePosY));
|
|
|
|
|
|
|
|
if (ray.notNull() && abs(we->delta()) > 0)
|
|
|
|
{
|
|
|
|
cvf::Vec3d pos, vrp, up;
|
|
|
|
m_viewer->mainCamera()->toLookAt(&pos, &vrp, &up);
|
|
|
|
|
|
|
|
double scale = -we->delta()/8.0 * 1.0/150 * (pos - m_pointOfInterest).length();
|
|
|
|
cvf::Vec3d trans = scale * ray->direction();
|
|
|
|
cvf::Vec3d newPos = pos + trans;
|
|
|
|
cvf::Vec3d newVrp = vrp + trans;
|
|
|
|
|
|
|
|
m_viewer->mainCamera()->setFromLookAt(newPos,newVrp, up );
|
2015-12-04 17:56:14 -06:00
|
|
|
|
2015-12-07 08:54:44 -06:00
|
|
|
m_viewer->updateParallelProjectionHeightFromMoveZoom(m_pointOfInterest);
|
2015-09-01 11:04:35 -05:00
|
|
|
m_viewer->navigationPolicyUpdate();
|
2015-07-02 05:31:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
isEventHandled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isEventHandled;
|
|
|
|
}
|
|
|
|
|