From 1d9481f09b022c118dd0128434106023f167b936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 10 Dec 2015 09:27:43 +0100 Subject: [PATCH] (#695) Unintentional picking fixed. Fixed in viewer, keeping the concept of the navigation policies to not flag the the events as handled. Made this clearer by adding an interface to turn event consumption on or off on the navigation policies. --- .../UserInterface/RiuCadNavigation.cpp | 5 +- .../UserInterface/RiuGeoQuestNavigation.cpp | 5 +- .../UserInterface/RiuRmsNavigation.cpp | 5 +- ApplicationCode/UserInterface/RiuViewer.cpp | 9 + Fwk/AppFwk/cafViewer/cafCadNavigation.cpp | 5 +- .../cafViewer/cafCeetronPlusNavigation.cpp | 6 +- .../cafViewer/cafTrackBallBasedNavigation.cpp | 157 +----------------- .../cafViewer/cafTrackBallBasedNavigation.h | 14 ++ 8 files changed, 45 insertions(+), 161 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuCadNavigation.cpp b/ApplicationCode/UserInterface/RiuCadNavigation.cpp index ba38ba5c97..5f145436a6 100644 --- a/ApplicationCode/UserInterface/RiuCadNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuCadNavigation.cpp @@ -174,6 +174,9 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp index 3bb0ed1797..95ba63030e 100644 --- a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp @@ -166,5 +166,8 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return false;//isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp index e689ed92a2..75ddf0a614 100644 --- a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp @@ -190,6 +190,9 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return false;//isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 8b4086b7dc..f4f7e6a7eb 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -228,6 +228,13 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event) if (event->button() == Qt::LeftButton) { + QPoint diffPoint = event->pos() - m_lastMousePressPosition; + if (diffPoint.manhattanLength() > 3) + { + // We are possibly in navigation mode, only clean press event will launch + return; + } + if (!m_infoLabelOverlayArea.isNull()) { if (m_infoLabelOverlayArea.contains(event->x(), event->y())) @@ -239,7 +246,9 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event) } m_viewerCommands->handlePickAction(event->x(), event->y(), event->modifiers()); + return; + } else if (event->button() == Qt::RightButton) { diff --git a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp index 72a705b7d6..aa94ef46ec 100644 --- a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp @@ -185,5 +185,8 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp index 0ef728eef1..9e324806ef 100644 --- a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp @@ -43,6 +43,7 @@ #include "cvfManipulatorTrackball.h" #include +#include "cvfTrace.h" //-------------------------------------------------------------------------------------------------- /// @@ -208,5 +209,8 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return false;//isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp index 61cef22bda..9c4591c717 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp @@ -50,7 +50,7 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -caf::TrackBallBasedNavigation::TrackBallBasedNavigation() +caf::TrackBallBasedNavigation::TrackBallBasedNavigation() : m_consumeEvents(false) { } @@ -63,8 +63,6 @@ caf::TrackBallBasedNavigation::~TrackBallBasedNavigation() } - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -80,159 +78,6 @@ void caf::TrackBallBasedNavigation::init() m_lastPosY = 0; } -#if 0 -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool caf::TrackBallBasedNavigation::handleInputEvent(QInputEvent* inputEvent) -{ - if (! inputEvent) return false; - bool isEventHandled = false; - switch (inputEvent->type()) - { - case QEvent::MouseButtonPress: - { - QMouseEvent * me = static_cast( inputEvent); - int translatedMousePosX = me->x(); - int translatedMousePosY = m_viewer->height() - me->y(); - - if (me->button() == Qt::RightButton) - { - cvf::HitItemCollection hic; - bool hitSomething = m_viewer->rayPick(me->x(), me->y(), &hic); - - if (hitSomething) - { - cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint(); - this->setPointOfInterest(pointOfInterest); - } - else - { - initializeRotationCenter(); - } - - m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); - //m_viewer->setCursor(RICursors::get(RICursors::ROTATE)); - m_isNavigating = true; - m_hasMovedMouseDuringNavigation = false; - isEventHandled = true; - } - else if (me->button() == Qt::LeftButton) - { - if (me->modifiers() == Qt::NoModifier) - { - m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY); - m_isNavigating = true; - m_hasMovedMouseDuringNavigation = false; - isEventHandled = true; - } - } - else if (me->button() == Qt::MidButton) - { - if (me->modifiers() == Qt::NoModifier) - { - QMouseEvent* we = static_cast ( inputEvent); - m_lastPosX = we->x(); - m_lastPosY = we->y(); - - m_zoomRay = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY); - - m_isNavigating = true; - m_hasMovedMouseDuringNavigation = false; - isEventHandled = true; - m_isZooming = true; - } - } - } - break; - case QEvent::MouseButtonRelease: - { - if (m_isNavigating) - { - QMouseEvent * me = static_cast( inputEvent); - if (me->button() == Qt::RightButton || me->button() == Qt::LeftButton ) - { - m_trackball->endNavigation(); - - m_isNavigating = false; - if (m_hasMovedMouseDuringNavigation) isEventHandled = true; - m_hasMovedMouseDuringNavigation = false; - } - else if ( me->button() == Qt::MidButton ) - { - m_isZooming = false; - - m_isNavigating = false; - if (m_hasMovedMouseDuringNavigation) isEventHandled = true; - m_hasMovedMouseDuringNavigation = false; - } - } - } - break; - case QEvent::MouseMove: - { - initializeRotationCenter(); - if (m_isRotCenterInitialized) - { - QMouseEvent * me = static_cast( inputEvent); - int translatedMousePosX = me->x(); - int translatedMousePosY = m_viewer->height() - me->y(); - - if (m_isNavigating) - { - if (m_isZooming) - { - int delta = 3*(m_lastPosY - me->y()); - this->zoomAlongRay(m_zoomRay.p(), delta); - m_lastPosX = me->x(); - m_lastPosY = me->y(); - } - else - { - bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY); - if (needRedraw) - { - m_viewer->navigationPolicyUpdate(); - } - } - isEventHandled = true; - m_hasMovedMouseDuringNavigation = true; - } - } - } - break; - case QEvent::Wheel: - { - if (inputEvent->modifiers() == Qt::NoModifier) - { - initializeRotationCenter(); - if (m_isRotCenterInitialized) - { - QWheelEvent* we = static_cast ( inputEvent); - int translatedMousePosX = we->x(); - int translatedMousePosY = m_viewer->height() - we->y(); - int delta = we->delta(); - - cvf::ref ray; - if (delta < 0) - ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY); - else - ray = m_viewer->mainCamera()->rayFromWindowCoordinates((int)(1.0*translatedMousePosX), (int)(1.0*translatedMousePosY)); - - zoomAlongRay(ray.p(), delta); - - } - isEventHandled = true; - } - } - break; - } - - return false;//isEventHandled; -} - -#endif - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h index d4766276c7..0083512d89 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h @@ -44,12 +44,22 @@ namespace cvf { namespace caf { +//-------------------------------------------------------------------------------------------------- +/// This class is a work in progress to consolidate the different navigation policies that are similar. +/// It is not yet finished. We need to extract the Pan, Rotation, ... etc. codes from the +/// special input event handlers and invoke those general methods from the event handlers instead. +/// Some of the protected variables in this class is used by the +/// derived classes, and should rather be used from the general methods in this class and thus be private +/// +//-------------------------------------------------------------------------------------------------- class TrackBallBasedNavigation: public NavigationPolicy { public: TrackBallBasedNavigation(); virtual ~TrackBallBasedNavigation(); + void enableEventEating(bool enable) { m_consumeEvents = enable; } + protected: // General navigation policy overrides virtual void init(); @@ -74,6 +84,10 @@ protected: int m_lastPosX; /// Previous mouse position int m_lastPosY; + bool isSupposedToConsumeEvents() { return m_consumeEvents; } + +private: + bool m_consumeEvents; }; } // End namespace caf