From e65facd5902d39b0406ad65ab34b1601392d7494 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 4 Dec 2015 15:15:13 +0100 Subject: [PATCH] (#404) Added RicViewerEventInterface and moved well path text display into a separate class --- .../RicNewPolylineCrossSectionFeature.cpp | 4 +- .../RicNewPolylineCrossSectionFeature.h | 6 +- .../Commands/RicViewerEventInterface.h | 53 +++++++++++ .../WellPathCommands/CMakeLists_files.cmake | 2 + .../RicWellPathViewerEventHandler.cpp | 92 +++++++++++++++++++ .../RicWellPathViewerEventHandler.h} | 26 ++---- .../ProjectDataModel/RimCrossSection.cpp | 2 - .../UserInterface/RiuViewerCommands.cpp | 58 +++--------- .../UserInterface/RiuViewerCommands.h | 4 +- 9 files changed, 177 insertions(+), 70 deletions(-) create mode 100644 ApplicationCode/Commands/RicViewerEventInterface.h create mode 100644 ApplicationCode/Commands/WellPathCommands/RicWellPathViewerEventHandler.cpp rename ApplicationCode/Commands/{RicCommandFeature.h => WellPathCommands/RicWellPathViewerEventHandler.h} (65%) diff --git a/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.cpp b/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.cpp index a626f71209..502fc11703 100644 --- a/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.cpp +++ b/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.cpp @@ -78,14 +78,14 @@ void RicNewPolylineCrossSectionFeature::setupActionLook(QAction* actionToSetup) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RicNewPolylineCrossSectionFeature::handleUiEvent(cvf::Object* uiEventObject) +bool RicNewPolylineCrossSectionFeature::handleEvent(cvf::Object* eventObject) { std::vector selection; caf::SelectionManager::instance()->objectsByType(&selection); if (selection.size() == 1) { - RicLocalIntersectionUiEvent* polylineUiEvent = dynamic_cast(uiEventObject); + RicViewerEventObject* polylineUiEvent = dynamic_cast(eventObject); if (polylineUiEvent) { RimCrossSection* crossSection = selection[0]; diff --git a/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.h b/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.h index 6900672c4e..c6ae47e624 100644 --- a/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.h +++ b/ApplicationCode/Commands/CrossSectionCommands/RicNewPolylineCrossSectionFeature.h @@ -19,7 +19,7 @@ #pragma once -#include "RicCommandFeature.h" +#include "RicViewerEventInterface.h" #include "cafCmdExecuteCommand.h" #include "cafPdmPointer.h" @@ -53,7 +53,7 @@ private: //================================================================================================== /// //================================================================================================== -class RicNewPolylineCrossSectionFeature : public RicCommandFeature +class RicNewPolylineCrossSectionFeature : public caf::CmdFeature, public RicViewerEventInterface { CAF_CMD_HEADER_INIT; @@ -66,7 +66,7 @@ protected: virtual void onActionTriggered( bool isChecked ); virtual void setupActionLook( QAction* actionToSetup ); - virtual bool handleUiEvent(cvf::Object* uiEventObject); + virtual bool handleEvent(cvf::Object* eventObject); }; diff --git a/ApplicationCode/Commands/RicViewerEventInterface.h b/ApplicationCode/Commands/RicViewerEventInterface.h new file mode 100644 index 0000000000..837532136c --- /dev/null +++ b/ApplicationCode/Commands/RicViewerEventInterface.h @@ -0,0 +1,53 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +#include "cvfBase.h" +#include "cvfObject.h" +#include "cvfVector3.h" + +namespace cvf { + class Part; +} + +class RicViewerEventInterface +{ +public: + virtual bool handleEvent(cvf::Object* eventObject) = 0; +}; + + +class RicViewerEventObject : public cvf::Object +{ +public: + RicViewerEventObject(cvf::Vec3d localIntersectionPoint, cvf::Part* firstHitPart, cvf::uint firstPartTriangleIndex) + : localIntersectionPoint(localIntersectionPoint), + firstHitPart(firstHitPart), + firstPartTriangleIndex(firstPartTriangleIndex) + { + } + + cvf::Vec3d localIntersectionPoint; + cvf::Part* firstHitPart; + cvf::uint firstPartTriangleIndex; +}; + diff --git a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake index 41ab4db8f8..0deea938f8 100644 --- a/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/WellPathCommands/CMakeLists_files.cmake @@ -9,6 +9,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellPathDeleteFeature.h ${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.h ${CEE_CURRENT_LIST_DIR}RicWellPathsImportFileFeature.h ${CEE_CURRENT_LIST_DIR}RicWellPathsImportSsihubFeature.h +${CEE_CURRENT_LIST_DIR}RicWellPathViewerEventHandler.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -16,6 +17,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellPathDeleteFeature.cpp ${CEE_CURRENT_LIST_DIR}RicWellPathsDeleteAllFeature.cpp ${CEE_CURRENT_LIST_DIR}RicWellPathsImportFileFeature.cpp ${CEE_CURRENT_LIST_DIR}RicWellPathsImportSsihubFeature.cpp +${CEE_CURRENT_LIST_DIR}RicWellPathViewerEventHandler.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/Commands/WellPathCommands/RicWellPathViewerEventHandler.cpp b/ApplicationCode/Commands/WellPathCommands/RicWellPathViewerEventHandler.cpp new file mode 100644 index 0000000000..bd43abca7b --- /dev/null +++ b/ApplicationCode/Commands/WellPathCommands/RicWellPathViewerEventHandler.cpp @@ -0,0 +1,92 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicWellPathViewerEventHandler.h" + +#include "RiaApplication.h" + +#include "RimCase.h" +#include "RimView.h" +#include "RimWellPath.h" +#include "RiuMainWindow.h" + +#include "RivWellPathSourceInfo.h" + +#include "cvfPart.h" +#include "cvfVector3.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicWellPathViewerEventHandler* RicWellPathViewerEventHandler::instance() +{ + static RicWellPathViewerEventHandler* singleton = new RicWellPathViewerEventHandler; + return singleton; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicWellPathViewerEventHandler::handleEvent(cvf::Object* eventObject) +{ + RicViewerEventObject* uiEvent = dynamic_cast(eventObject); + if (!uiEvent) return false; + + if (uiEvent->firstHitPart && uiEvent->firstHitPart->sourceInfo()) + { + const RivWellPathSourceInfo* wellPathSourceInfo = dynamic_cast(uiEvent->firstHitPart->sourceInfo()); + if (wellPathSourceInfo) + { + cvf::Vec3d displayModelOffset = cvf::Vec3d::ZERO; + + RimView* activeView = RiaApplication::instance()->activeReservoirView(); + if (!activeView) return false; + + RimCase* rimCase = NULL; + activeView->firstAnchestorOrThisOfType(rimCase); + if (rimCase) + { + displayModelOffset = rimCase->displayModelOffset(); + } + + cvf::Vec3d unscaledIntersection = uiEvent->localIntersectionPoint; + unscaledIntersection.z() /= activeView->scaleZ; + + size_t wellSegmentIndex = wellPathSourceInfo->segmentIndex(uiEvent->firstPartTriangleIndex); + double measuredDepth = wellPathSourceInfo->measuredDepth(uiEvent->firstPartTriangleIndex, unscaledIntersection + displayModelOffset); + cvf::Vec3d trueVerticalDepth = wellPathSourceInfo->trueVerticalDepth(uiEvent->firstPartTriangleIndex, unscaledIntersection + displayModelOffset); + + QString wellPathText; + wellPathText += QString("Well path name : %1\n").arg(wellPathSourceInfo->wellPath()->name); + wellPathText += QString("Measured depth : %1\n").arg(measuredDepth); + + QString formattedText; + formattedText.sprintf("Intersection point : [E: %.2f, N: %.2f, Depth: %.2f]", trueVerticalDepth.x(), trueVerticalDepth.y(), -trueVerticalDepth.z()); + wellPathText += formattedText; + + RiuMainWindow::instance()->setResultInfo(wellPathText); + + return true; + } + } + + return false; +} + diff --git a/ApplicationCode/Commands/RicCommandFeature.h b/ApplicationCode/Commands/WellPathCommands/RicWellPathViewerEventHandler.h similarity index 65% rename from ApplicationCode/Commands/RicCommandFeature.h rename to ApplicationCode/Commands/WellPathCommands/RicWellPathViewerEventHandler.h index aed7624bf5..305e856ab8 100644 --- a/ApplicationCode/Commands/RicCommandFeature.h +++ b/ApplicationCode/Commands/WellPathCommands/RicWellPathViewerEventHandler.h @@ -19,27 +19,17 @@ #pragma once -#include "cafCmdFeature.h" - -#include "cvfBase.h" -#include "cvfObject.h" -#include "cvfVector3.h" +#include "RicViewerEventInterface.h" -class RicCommandFeature : public caf::CmdFeature +//================================================================================================== +/// +//================================================================================================== +class RicWellPathViewerEventHandler : public RicViewerEventInterface { public: - virtual bool handleUiEvent(cvf::Object* uiEventObject) = 0; -}; - -class RicLocalIntersectionUiEvent : public cvf::Object -{ -public: - RicLocalIntersectionUiEvent(cvf::Vec3d localIntersectionPoint) - : localIntersectionPoint(localIntersectionPoint) - { - } - - cvf::Vec3d localIntersectionPoint; + static RicWellPathViewerEventHandler* instance(); + + virtual bool handleEvent(cvf::Object* eventObject); }; diff --git a/ApplicationCode/ProjectDataModel/RimCrossSection.cpp b/ApplicationCode/ProjectDataModel/RimCrossSection.cpp index cea704e7a5..40f3ffcc77 100644 --- a/ApplicationCode/ProjectDataModel/RimCrossSection.cpp +++ b/ApplicationCode/ProjectDataModel/RimCrossSection.cpp @@ -21,8 +21,6 @@ #include "RiaApplication.h" -#include "RicCommandFeature.h" - #include "RigSimulationWellCenterLineCalculator.h" #include "RimCase.h" diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 0bb23d1ae2..057fb262c8 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -19,7 +19,7 @@ #include "RiuViewerCommands.h" -#include "RicCommandFeature.h" +#include "RicViewerEventInterface.h" #include "RicEclipsePropertyFilterNewExec.h" #include "RicGeoMechPropertyFilterNewExec.h" #include "RicRangeFilterNewExec.h" @@ -65,10 +65,13 @@ #include "cvfHitItemCollection.h" #include "cvfPart.h" +#include "WellPathCommands/RicWellPathViewerEventHandler.h" + #include #include #include + //================================================================================================== // // RiaViewerCommands @@ -84,13 +87,16 @@ RiuViewerCommands::RiuViewerCommands(RiuViewer* ownerViewer) m_currentGridIdx(-1), m_currentCellIndex(-1) { - caf::CmdFeature* cmdFeature = caf::CmdFeatureManager::instance()->getCommandFeature("RicNewPolylineCrossSectionFeature"); - CVF_ASSERT(cmdFeature); + { + caf::CmdFeature* cmdFeature = caf::CmdFeatureManager::instance()->getCommandFeature("RicNewPolylineCrossSectionFeature"); + CVF_ASSERT(cmdFeature); - RicCommandFeature* riCommandFeature = dynamic_cast(cmdFeature); - CVF_ASSERT(riCommandFeature); + m_viewerEventHandlers.push_back(dynamic_cast(cmdFeature)); + } - m_activeUiCommandFeature = riCommandFeature; + { + m_viewerEventHandlers.push_back(dynamic_cast(RicWellPathViewerEventHandler::instance())); + } } //-------------------------------------------------------------------------------------------------- @@ -109,7 +115,6 @@ void RiuViewerCommands::setOwnerView(RimView * owner) m_reservoirView = owner; } - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -434,11 +439,10 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM { extractIntersectionData(hitItems, &localIntersectionPoint, &firstHitPart, &firstPartTriangleIndex, &firstNncHitPart, &nncPartTriangleIndex); - if (!m_activeUiCommandFeature.isNull()) + cvf::ref eventObj = new RicViewerEventObject(localIntersectionPoint, firstHitPart, firstPartTriangleIndex); + for (size_t i = 0; i < m_viewerEventHandlers.size(); i++) { - cvf::ref uiEventObj = new RicLocalIntersectionUiEvent(localIntersectionPoint); - - if (m_activeUiCommandFeature->handleUiEvent(uiEventObj.p())) + if (m_viewerEventHandlers[i]->handleEvent(eventObj.p())) { return; } @@ -451,7 +455,6 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM { const RivSourceInfo* rivSourceInfo = dynamic_cast(firstHitPart->sourceInfo()); const RivFemPickSourceInfo* femSourceInfo = dynamic_cast(firstHitPart->sourceInfo()); - const RivWellPathSourceInfo* wellPathSourceInfo = dynamic_cast(firstHitPart->sourceInfo()); const RivCrossSectionSourceInfo* crossSectionSourceInfo = dynamic_cast(firstHitPart->sourceInfo()); if (rivSourceInfo) @@ -470,37 +473,6 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY, Qt::KeyboardM gridIndex = femSourceInfo->femPartIndex(); cellIndex = femSourceInfo->triangleToElmMapper()->elementIndex(firstPartTriangleIndex); } - else if (wellPathSourceInfo) - { - cvf::Vec3d displayModelOffset = cvf::Vec3d::ZERO; - - RimCase* rimCase = NULL; - m_reservoirView->firstAnchestorOrThisOfType(rimCase); - if (rimCase) - { - displayModelOffset = rimCase->displayModelOffset(); - } - - cvf::Vec3d unscaledIntersection = localIntersectionPoint; - unscaledIntersection.z() /= m_reservoirView->scaleZ; - - size_t wellSegmentIndex = wellPathSourceInfo->segmentIndex(firstPartTriangleIndex); - double measuredDepth = wellPathSourceInfo->measuredDepth(firstPartTriangleIndex, unscaledIntersection + displayModelOffset); - cvf::Vec3d trueVerticalDepth = wellPathSourceInfo->trueVerticalDepth(firstPartTriangleIndex, unscaledIntersection + displayModelOffset); - - QString wellPathText; - wellPathText += wellPathSourceInfo->wellPath()->name; - wellPathText += "\n"; - wellPathText += QString("Well path segment index : %1\n").arg(wellSegmentIndex); - wellPathText += QString("Measured depth : %1\n").arg(measuredDepth); - - QString formattedText; - formattedText.sprintf("Intersection point : [E: %.2f, N: %.2f, Depth: %.2f]", trueVerticalDepth.x(), trueVerticalDepth.y(), -trueVerticalDepth.z()); - wellPathText += formattedText; - - RiuMainWindow::instance()->setResultInfo(wellPathText); - - } else if (crossSectionSourceInfo) { findCellAndGridIndex(crossSectionSourceInfo, firstPartTriangleIndex, &cellIndex, &gridIndex); diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.h b/ApplicationCode/UserInterface/RiuViewerCommands.h index ab2e117266..e83e0236db 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.h +++ b/ApplicationCode/UserInterface/RiuViewerCommands.h @@ -31,7 +31,7 @@ class RimGeoMechView; class RimView; class RiuViewer; class RivCrossSectionSourceInfo; -class RicCommandFeature; +class RicViewerEventInterface; class QMouseEvent; @@ -79,7 +79,7 @@ private: QPointer m_viewer; - QPointer m_activeUiCommandFeature; + std::vector m_viewerEventHandlers; };