diff --git a/ApplicationCode/Commands/RicPickEventHandler.h b/ApplicationCode/Commands/RicPickEventHandler.h index ebee37bf7a..34f828df79 100644 --- a/ApplicationCode/Commands/RicPickEventHandler.h +++ b/ApplicationCode/Commands/RicPickEventHandler.h @@ -51,11 +51,21 @@ public: //================================================================================================== -/// +/// A static always-on pick handler used in the RiuViewerCommand //================================================================================================== -class RicPickEventHandler +class RicDefaultPickEventHandler { public: virtual bool handlePickEvent(const Ric3DPickEvent& eventObject) = 0; }; +//================================================================================================== +/// A temporary, dynamic pick handler that overrides the default ones +//================================================================================================== +class RicPickEventHandler +{ +public: + virtual bool handlePickEvent(const Ric3DPickEvent& eventObject) = 0; + virtual void notifyUnregistered() = 0; +}; + diff --git a/ApplicationCode/Commands/WellLogCommands/Ric3dWellLogCurvePickEventHandler.h b/ApplicationCode/Commands/WellLogCommands/Ric3dWellLogCurvePickEventHandler.h index 78ee086c34..b7d5a3717c 100644 --- a/ApplicationCode/Commands/WellLogCommands/Ric3dWellLogCurvePickEventHandler.h +++ b/ApplicationCode/Commands/WellLogCommands/Ric3dWellLogCurvePickEventHandler.h @@ -24,7 +24,7 @@ //================================================================================================== /// //================================================================================================== -class Ric3dWellLogCurvePickEventHandler : public RicPickEventHandler +class Ric3dWellLogCurvePickEventHandler : public RicDefaultPickEventHandler { public: static Ric3dWellLogCurvePickEventHandler* instance(); diff --git a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp index 09bd52a9c2..18bbc8414a 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp +++ b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.cpp @@ -45,6 +45,14 @@ RicCreateWellTargetsPickEventHandler::~RicCreateWellTargetsPickEventHandler() } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCreateWellTargetsPickEventHandler::notifyUnregistered() +{ + m_geometryToAddTargetsTo->enableTargetPointPicking(false); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h index 10e2decc07..0085aadfb4 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h +++ b/ApplicationCode/Commands/WellPathCommands/RicCreateWellTargetsPickEventHandler.h @@ -37,5 +37,6 @@ protected: caf::PdmPointer m_geometryToAddTargetsTo; virtual bool handlePickEvent(const Ric3DPickEvent& eventObject) override; + virtual void notifyUnregistered() override; }; diff --git a/ApplicationCode/Commands/WellPathCommands/RicIntersectionPickEventHandler.h b/ApplicationCode/Commands/WellPathCommands/RicIntersectionPickEventHandler.h index b74b9341fb..d6fbd88fc3 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicIntersectionPickEventHandler.h +++ b/ApplicationCode/Commands/WellPathCommands/RicIntersectionPickEventHandler.h @@ -23,7 +23,7 @@ //================================================================================================== /// //================================================================================================== -class RicIntersectionPickEventHandler : public RicPickEventHandler +class RicIntersectionPickEventHandler : public RicDefaultPickEventHandler { public: static RicIntersectionPickEventHandler* instance(); diff --git a/ApplicationCode/Commands/WellPathCommands/RicWellPathPickEventHandler.h b/ApplicationCode/Commands/WellPathCommands/RicWellPathPickEventHandler.h index 9687bf206f..905aaf355d 100644 --- a/ApplicationCode/Commands/WellPathCommands/RicWellPathPickEventHandler.h +++ b/ApplicationCode/Commands/WellPathCommands/RicWellPathPickEventHandler.h @@ -25,7 +25,7 @@ //================================================================================================== /// //================================================================================================== -class RicWellPathPickEventHandler : public RicPickEventHandler +class RicWellPathPickEventHandler : public RicDefaultPickEventHandler { public: static RicWellPathPickEventHandler* instance(); diff --git a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp index b8875d5fd1..840b2841a3 100644 --- a/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellPathGeometryDef.cpp @@ -79,7 +79,7 @@ RimWellPathGeometryDef::RimWellPathGeometryDef() //-------------------------------------------------------------------------------------------------- RimWellPathGeometryDef::~RimWellPathGeometryDef() { - RiuViewerCommands::removePickEventHandler(m_pickTargetsEventHandler); + RiuViewerCommands::removePickEventHandlerIfActive(m_pickTargetsEventHandler); delete m_pickTargetsEventHandler; @@ -197,12 +197,12 @@ void RimWellPathGeometryDef::enableTargetPointPicking(bool isEnabling) if (isEnabling) { m_pickPointsEnabled = true; - RiuViewerCommands::addPickEventHandler(m_pickTargetsEventHandler); + RiuViewerCommands::setPickEventHandler(m_pickTargetsEventHandler); updateConnectedEditors(); } else { - RiuViewerCommands::removePickEventHandler(m_pickTargetsEventHandler); + RiuViewerCommands::removePickEventHandlerIfActive(m_pickTargetsEventHandler); m_pickPointsEnabled = false; updateConnectedEditors(); } diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 3fa1341dfa..cbf695edeb 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -107,8 +107,9 @@ // RiaViewerCommands // //================================================================================================== +RicPickEventHandler* RiuViewerCommands::sm_overridingPickHandler = nullptr; -std::vector RiuViewerCommands::sm_pickEventHandlers; +std::vector RiuViewerCommands::sm_defaultPickEventHandlers; //-------------------------------------------------------------------------------------------------- /// @@ -121,11 +122,11 @@ RiuViewerCommands::RiuViewerCommands(RiuViewer* ownerViewer) , m_currentPickPositionInDomainCoords(cvf::Vec3d::UNDEFINED) , m_viewer(ownerViewer) { - if ( sm_pickEventHandlers.empty() ) + if ( sm_defaultPickEventHandlers.empty() ) { - addPickEventHandler(RicIntersectionPickEventHandler::instance()); - addPickEventHandler(Ric3dWellLogCurvePickEventHandler::instance()); - addPickEventHandler(RicWellPathPickEventHandler::instance()); + addDefaultPickEventHandler(RicIntersectionPickEventHandler::instance()); + addDefaultPickEventHandler(Ric3dWellLogCurvePickEventHandler::instance()); + addDefaultPickEventHandler(RicWellPathPickEventHandler::instance()); } } @@ -530,9 +531,14 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM Ric3DPickEvent viewerEventObject(pickItemInfos, m_reservoirView); - for ( size_t i = 0; i < sm_pickEventHandlers.size(); i++ ) + if (sm_overridingPickHandler && sm_overridingPickHandler->handlePickEvent(viewerEventObject)) { - if ( sm_pickEventHandlers[i]->handlePickEvent(viewerEventObject) ) + return; + } + + for ( size_t i = 0; i < sm_defaultPickEventHandlers.size(); i++ ) + { + if ( sm_defaultPickEventHandlers[i]->handlePickEvent(viewerEventObject) ) { return; } @@ -877,6 +883,28 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuViewerCommands::setPickEventHandler(RicPickEventHandler* pickEventHandler) +{ + if (sm_overridingPickHandler) sm_overridingPickHandler->notifyUnregistered(); + + sm_overridingPickHandler = pickEventHandler; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuViewerCommands::removePickEventHandlerIfActive(RicPickEventHandler* pickEventHandler) +{ + if (sm_overridingPickHandler == pickEventHandler) + { + sm_overridingPickHandler = nullptr; + if (pickEventHandler) pickEventHandler->notifyUnregistered(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -888,25 +916,25 @@ cvf::Vec3d RiuViewerCommands::lastPickPositionInDomainCoords() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuViewerCommands::addPickEventHandler(RicPickEventHandler* pickEventHandler) +void RiuViewerCommands::addDefaultPickEventHandler(RicDefaultPickEventHandler* pickEventHandler) { - removePickEventHandler(pickEventHandler); + removeDefaultPickEventHandler(pickEventHandler); if (pickEventHandler) { - sm_pickEventHandlers.push_back(pickEventHandler); + sm_defaultPickEventHandlers.push_back(pickEventHandler); } } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuViewerCommands::removePickEventHandler(RicPickEventHandler* pickEventHandler) +void RiuViewerCommands::removeDefaultPickEventHandler(RicDefaultPickEventHandler* pickEventHandler) { - for ( auto it = sm_pickEventHandlers.begin(); it != sm_pickEventHandlers.end(); ++it ) + for ( auto it = sm_defaultPickEventHandlers.begin(); it != sm_defaultPickEventHandlers.end(); ++it ) { if ( *it == pickEventHandler ) { - sm_pickEventHandlers.erase(it); + sm_defaultPickEventHandlers.erase(it); break; } } diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.h b/ApplicationCode/UserInterface/RiuViewerCommands.h index afcd32f949..fc3648c214 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.h +++ b/ApplicationCode/UserInterface/RiuViewerCommands.h @@ -25,6 +25,7 @@ #include #include +class RicDefaultPickEventHandler; class RicPickEventHandler; class RimEclipseView; class RimGeoMechView; @@ -59,8 +60,8 @@ public: void displayContextMenu(QMouseEvent* event); void handlePickAction(int winPosX, int winPosY, Qt::KeyboardModifiers keyboardModifiers); - static void addPickEventHandler(RicPickEventHandler* pickEventHandler); - static void removePickEventHandler(RicPickEventHandler* pickEventHandler); + static void setPickEventHandler(RicPickEventHandler* pickEventHandler); + static void removePickEventHandlerIfActive(RicPickEventHandler* pickEventHandler); cvf::Vec3d lastPickPositionInDomainCoords() const; private: @@ -75,6 +76,9 @@ private: bool handleOverlayItemPicking(int winPosX, int winPosY); + static void addDefaultPickEventHandler(RicDefaultPickEventHandler* pickEventHandler); + static void removeDefaultPickEventHandler(RicDefaultPickEventHandler* pickEventHandler); + private: size_t m_currentGridIdx; size_t m_currentCellIndex; @@ -82,5 +86,7 @@ private: cvf::Vec3d m_currentPickPositionInDomainCoords; caf::PdmPointer m_reservoirView; QPointer m_viewer; - static std::vector sm_pickEventHandlers; + + static RicPickEventHandler* sm_overridingPickHandler; + static std::vector sm_defaultPickEventHandlers; };