From 8cc21947648c3dec128f4700e2bf5612817d3f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Mon, 25 Nov 2019 18:36:05 +0100 Subject: [PATCH] (#5112) Move cell and nnc picking code to a separate pick event handler --- .../Commands/RicPickEventHandler.h | 4 +- .../UserInterface/CMakeLists_files.cmake | 2 + .../UserInterface/Riu3dSelectionManager.cpp | 26 +- .../UserInterface/Riu3dSelectionManager.h | 54 ++-- .../RiuCellAndNncPickEventHandler.cpp | 247 ++++++++++++++++++ .../RiuCellAndNncPickEventHandler.h | 33 +++ .../UserInterface/RiuViewerCommands.cpp | 183 ++----------- .../UserInterface/RiuViewerCommands.h | 32 +-- 8 files changed, 369 insertions(+), 212 deletions(-) create mode 100644 ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp create mode 100644 ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.h diff --git a/ApplicationCode/Commands/RicPickEventHandler.h b/ApplicationCode/Commands/RicPickEventHandler.h index 00b42d40cb..ec66242477 100644 --- a/ApplicationCode/Commands/RicPickEventHandler.h +++ b/ApplicationCode/Commands/RicPickEventHandler.h @@ -41,14 +41,16 @@ class Rim3dView; class Ric3dPickEvent : public caf::PickEvent { public: - Ric3dPickEvent( const std::vector& pickItemInfos, Rim3dView* view ) + Ric3dPickEvent( const std::vector& pickItemInfos, Rim3dView* view, Qt::KeyboardModifiers keyboardModifiers) : m_pickItemInfos( pickItemInfos ) , m_view( view ) + , m_keyboardModifiers( keyboardModifiers ) { } std::vector m_pickItemInfos; Rim3dView* m_view; + Qt::KeyboardModifiers m_keyboardModifiers; }; //================================================================================================== diff --git a/ApplicationCode/UserInterface/CMakeLists_files.cmake b/ApplicationCode/UserInterface/CMakeLists_files.cmake index 658feae907..8e162070a7 100644 --- a/ApplicationCode/UserInterface/CMakeLists_files.cmake +++ b/ApplicationCode/UserInterface/CMakeLists_files.cmake @@ -48,6 +48,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuTreeViewEventFilter.h ${CMAKE_CURRENT_LIST_DIR}/RiuViewer.h ${CMAKE_CURRENT_LIST_DIR}/RiuViewerToViewInterface.h ${CMAKE_CURRENT_LIST_DIR}/RiuViewerCommands.h +${CMAKE_CURRENT_LIST_DIR}/RiuCellAndNncPickEventHandler.h ${CMAKE_CURRENT_LIST_DIR}/RiuPickItemInfo.h ${CMAKE_CURRENT_LIST_DIR}/RiuWellLogPlot.h ${CMAKE_CURRENT_LIST_DIR}/RiuWellLogTrack.h @@ -136,6 +137,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiuToolTipMenu.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuTreeViewEventFilter.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuViewer.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuViewerCommands.cpp +${CMAKE_CURRENT_LIST_DIR}/RiuCellAndNncPickEventHandler.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuPickItemInfo.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuWellLogTrack.cpp ${CMAKE_CURRENT_LIST_DIR}/RiuWellLogPlot.cpp diff --git a/ApplicationCode/UserInterface/Riu3dSelectionManager.cpp b/ApplicationCode/UserInterface/Riu3dSelectionManager.cpp index d35a162049..306a222c44 100644 --- a/ApplicationCode/UserInterface/Riu3dSelectionManager.cpp +++ b/ApplicationCode/UserInterface/Riu3dSelectionManager.cpp @@ -25,6 +25,8 @@ #include "RimGridView.h" #include "RimSimWellInView.h" #include "RimWellPath.h" +#include "RimEclipseResultDefinition.h" +#include "RimGeoMechResultDefinition.h" #include "RivSimWellPipeSourceInfo.h" #include "RivWellPathSourceInfo.h" @@ -156,6 +158,8 @@ void Riu3dSelectionManager::deleteAllItemsFromSelection( int role ) /// //-------------------------------------------------------------------------------------------------- RiuEclipseSelectionItem::RiuEclipseSelectionItem( RimEclipseView* view, + RimEclipseResultDefinition* resultDefinition, + size_t timestepIdx, size_t gridIndex, size_t cellIndex, size_t nncIndex, @@ -163,6 +167,8 @@ RiuEclipseSelectionItem::RiuEclipseSelectionItem( RimEclipseView* cvf::StructGridInterface::FaceType face, const cvf::Vec3d& localIntersectionPointInDisplay ) : m_view( view ) + , m_resultDefinition( resultDefinition ) + , m_timestepIdx( timestepIdx ) , m_gridIndex( gridIndex ) , m_gridLocalCellIndex( cellIndex ) , m_nncIndex( nncIndex ) @@ -175,13 +181,17 @@ RiuEclipseSelectionItem::RiuEclipseSelectionItem( RimEclipseView* //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RiuGeoMechSelectionItem::RiuGeoMechSelectionItem( RimGeoMechView* view, - size_t gridIndex, - size_t cellIndex, - cvf::Color3f color, - int elementFace, - const cvf::Vec3d& localIntersectionPointInDisplay ) +RiuGeoMechSelectionItem::RiuGeoMechSelectionItem( RimGeoMechView* view, + RimGeoMechResultDefinition* resultDefinition, + size_t timestepIdx, + size_t gridIndex, + size_t cellIndex, + cvf::Color3f color, + int elementFace, + const cvf::Vec3d& localIntersectionPointInDisplay ) : m_view( view ) + , m_resultDefinition( resultDefinition ) + , m_timestepIdx( timestepIdx ) , m_gridIndex( gridIndex ) , m_cellIndex( cellIndex ) , m_color( color ) @@ -195,6 +205,8 @@ RiuGeoMechSelectionItem::RiuGeoMechSelectionItem( RimGeoMechView* view, /// //-------------------------------------------------------------------------------------------------- RiuGeoMechSelectionItem::RiuGeoMechSelectionItem( RimGeoMechView* view, + RimGeoMechResultDefinition* resultDefinition, + size_t timestepIdx, size_t gridIndex, size_t cellIndex, cvf::Color3f color, @@ -202,6 +214,8 @@ RiuGeoMechSelectionItem::RiuGeoMechSelectionItem( RimGeoMechView* const cvf::Vec3d& localIntersectionPointInDisplay, const std::array& intersectionTriangle ) : m_view( view ) + , m_resultDefinition( resultDefinition ) + , m_timestepIdx( timestepIdx ) , m_gridIndex( gridIndex ) , m_cellIndex( cellIndex ) , m_color( color ) diff --git a/ApplicationCode/UserInterface/Riu3dSelectionManager.h b/ApplicationCode/UserInterface/Riu3dSelectionManager.h index 4dcc22416e..a9c80b01ac 100644 --- a/ApplicationCode/UserInterface/Riu3dSelectionManager.h +++ b/ApplicationCode/UserInterface/Riu3dSelectionManager.h @@ -42,6 +42,8 @@ class RiuSelectionChangedHandler; class RiuSelectionItem; class RivSimWellPipeSourceInfo; class RivWellPathSourceInfo; +class RimEclipseResultDefinition; +class RimGeoMechResultDefinition; //================================================================================================== // @@ -131,6 +133,8 @@ class RiuEclipseSelectionItem : public RiuSelectionItem { public: explicit RiuEclipseSelectionItem( RimEclipseView* view, + RimEclipseResultDefinition* resultDefinition, + size_t timestepIdx, size_t gridIndex, size_t cellIndex, size_t nncIndex, @@ -146,13 +150,15 @@ public: } public: - caf::PdmPointer m_view; - size_t m_gridIndex; - size_t m_gridLocalCellIndex; - size_t m_nncIndex; - cvf::Color3f m_color; - cvf::StructGridInterface::FaceType m_face; - cvf::Vec3d m_localIntersectionPointInDisplay; + caf::PdmPointer m_view; + caf::PdmPointer m_resultDefinition; + size_t m_timestepIdx; + size_t m_gridIndex; + size_t m_gridLocalCellIndex; + size_t m_nncIndex; + cvf::Color3f m_color; + cvf::StructGridInterface::FaceType m_face; + cvf::Vec3d m_localIntersectionPointInDisplay; }; //================================================================================================== @@ -163,14 +169,18 @@ public: class RiuGeoMechSelectionItem : public RiuSelectionItem { public: - explicit RiuGeoMechSelectionItem( RimGeoMechView* view, - size_t gridIndex, - size_t cellIndex, - cvf::Color3f color, - int elementFace, - const cvf::Vec3d& localIntersectionPointInDisplay ); + explicit RiuGeoMechSelectionItem( RimGeoMechView* view, + RimGeoMechResultDefinition* resultDefinition, + size_t timestepIdx, + size_t gridIndex, + size_t cellIndex, + cvf::Color3f color, + int elementFace, + const cvf::Vec3d& localIntersectionPointInDisplay ); explicit RiuGeoMechSelectionItem( RimGeoMechView* view, + RimGeoMechResultDefinition* resultDefinition, + size_t timestepIdx, size_t gridIndex, size_t cellIndex, cvf::Color3f color, @@ -185,14 +195,16 @@ public: } public: - caf::PdmPointer m_view; - size_t m_gridIndex; - size_t m_cellIndex; - cvf::Color3f m_color; - int m_elementFace; - bool m_hasIntersectionTriangle; - std::array m_intersectionTriangle; - cvf::Vec3d m_localIntersectionPointInDisplay; + caf::PdmPointer m_view; + caf::PdmPointer m_resultDefinition; + size_t m_timestepIdx; + size_t m_gridIndex; + size_t m_cellIndex; + cvf::Color3f m_color; + int m_elementFace; + bool m_hasIntersectionTriangle; + std::array m_intersectionTriangle; + cvf::Vec3d m_localIntersectionPointInDisplay; }; //================================================================================================== diff --git a/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp b/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp new file mode 100644 index 0000000000..6c0caf3489 --- /dev/null +++ b/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp @@ -0,0 +1,247 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor ASA +// +// 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 "RiuCellAndNncPickEventHandler.h" + +#include "RiaColorTables.h" + +#include "Rim2dIntersectionView.h" +#include "RimEclipseView.h" +#include "RimExtrudedCurveIntersection.h" +#include "RimGeoMechView.h" + +#include "Riu3dSelectionManager.h" +#include "RiuViewerCommands.h" + +#include "RivBoxIntersectionSourceInfo.h" +#include "RivExtrudedCurveIntersectionSourceInfo.h" +#include "RivFemPartGeometryGenerator.h" +#include "RivFemPickSourceInfo.h" +#include "RivSourceInfo.h" + +#include "cafPdmObjectHandle.h" + +#include "cvfPart.h" + +#include + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuCellAndNncPickEventHandler* RiuCellAndNncPickEventHandler::instance() +{ + static RiuCellAndNncPickEventHandler* singleton = new RiuCellAndNncPickEventHandler; + return singleton; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eventObject ) +{ + const std::vector& pickItemInfos = eventObject.m_pickItemInfos; + Rim3dView* mainOrComparisonView = eventObject.m_view; + Qt::KeyboardModifiers keyboardModifiers = eventObject.m_keyboardModifiers; + + const cvf::Part* firstHitPart = nullptr; + uint firstPartTriangleIndex = cvf::UNDEFINED_UINT; + + cvf::Vec3d localIntersectionPoint( cvf::Vec3d::ZERO ); + cvf::Vec3d globalIntersectionPoint( cvf::Vec3d::ZERO ); + size_t nncIndex = cvf::UNDEFINED_SIZE_T; + + { + const cvf::Part* firstNncHitPart = nullptr; + uint nncPartTriangleIndex = cvf::UNDEFINED_UINT; + + if ( pickItemInfos.size() ) + { + size_t indexToFirstNoneNncItem = cvf::UNDEFINED_SIZE_T; + size_t indexToNncItemNearFirstItem = cvf::UNDEFINED_SIZE_T; + + RiuViewerCommands::findFirstItems( mainOrComparisonView, + pickItemInfos, + &indexToFirstNoneNncItem, + &indexToNncItemNearFirstItem ); + + if ( indexToFirstNoneNncItem != cvf::UNDEFINED_SIZE_T ) + { + localIntersectionPoint = pickItemInfos[indexToFirstNoneNncItem].localPickedPoint(); + globalIntersectionPoint = pickItemInfos[indexToFirstNoneNncItem].globalPickedPoint(); + firstHitPart = pickItemInfos[indexToFirstNoneNncItem].pickedPart(); + firstPartTriangleIndex = pickItemInfos[indexToFirstNoneNncItem].faceIdx(); + } + + if ( indexToNncItemNearFirstItem != cvf::UNDEFINED_SIZE_T ) + { + firstNncHitPart = pickItemInfos[indexToNncItemNearFirstItem].pickedPart(); + nncPartTriangleIndex = pickItemInfos[indexToNncItemNearFirstItem].faceIdx(); + } + } + + if ( firstNncHitPart && firstNncHitPart->sourceInfo() ) + { + const RivSourceInfo* rivSourceInfo = dynamic_cast( firstNncHitPart->sourceInfo() ); + if ( rivSourceInfo ) + { + if ( nncPartTriangleIndex < rivSourceInfo->m_NNCIndices->size() ) + { + nncIndex = rivSourceInfo->m_NNCIndices->get( nncPartTriangleIndex ); + } + } + } + } + + if ( !firstHitPart ) return false; + + size_t gridIndex = cvf::UNDEFINED_SIZE_T; + size_t cellIndex = cvf::UNDEFINED_SIZE_T; + cvf::StructGridInterface::FaceType face = cvf::StructGridInterface::NO_FACE; + int gmFace = -1; + bool intersectionHit = false; + std::array intersectionTriangleHit; + + // clang-format off + if ( const RivSourceInfo* rivSourceInfo = dynamic_cast( firstHitPart->sourceInfo() ) ) + { + gridIndex = rivSourceInfo->gridIndex(); + if ( rivSourceInfo->hasCellFaceMapping() ) + { + CVF_ASSERT( rivSourceInfo->m_cellFaceFromTriangleMapper.notNull() ); + + cellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex( firstPartTriangleIndex ); + face = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace( firstPartTriangleIndex ); + } + } + else if ( const RivFemPickSourceInfo* femSourceInfo = + dynamic_cast( firstHitPart->sourceInfo() ) ) + { + gridIndex = femSourceInfo->femPartIndex(); + cellIndex = femSourceInfo->triangleToElmMapper()->elementIndex( firstPartTriangleIndex ); + gmFace = femSourceInfo->triangleToElmMapper()->elementFace( firstPartTriangleIndex ); + } + else if ( const RivExtrudedCurveIntersectionSourceInfo* crossSectionSourceInfo = + dynamic_cast( firstHitPart->sourceInfo() ) ) + { + RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView, + crossSectionSourceInfo, + firstPartTriangleIndex, + &cellIndex, + &gridIndex ); + intersectionHit = true; + intersectionTriangleHit = crossSectionSourceInfo->triangle( firstPartTriangleIndex ); + } + else if ( const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo = + dynamic_cast( firstHitPart->sourceInfo() ) ) + { + RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView, + intersectionBoxSourceInfo, + firstPartTriangleIndex, + &cellIndex, + &gridIndex ); + intersectionHit = true; + intersectionTriangleHit = intersectionBoxSourceInfo->triangle( firstPartTriangleIndex ); + } + // clang-format on + + if ( cellIndex == cvf::UNDEFINED_SIZE_T ) + { + Riu3dSelectionManager::instance()->deleteAllItems(); + return false; + } + + bool appendToSelection = false; + if ( keyboardModifiers & Qt::ControlModifier ) + { + appendToSelection = true; + } + + std::vector items; + Riu3dSelectionManager::instance()->selectedItems( items ); + + const caf::ColorTable& colorTable = RiaColorTables::selectionPaletteColors(); + + cvf::Color3f curveColor = colorTable.cycledColor3f( items.size() ); + + if ( !appendToSelection ) + { + curveColor = colorTable.cycledColor3f( 0 ); + } + + RiuSelectionItem* selItem = nullptr; + { + Rim2dIntersectionView* intersectionView = dynamic_cast( mainOrComparisonView ); + RimEclipseView* eclipseView = dynamic_cast( mainOrComparisonView ); + RimGeoMechView* geomView = dynamic_cast( mainOrComparisonView ); + + if ( intersectionView ) + { + intersectionView->intersection()->firstAncestorOrThisOfType( eclipseView ); + intersectionView->intersection()->firstAncestorOrThisOfType( geomView ); + } + + if ( eclipseView ) + { + selItem = new RiuEclipseSelectionItem( eclipseView, + nullptr, + -1, + gridIndex, + cellIndex, + nncIndex, + curveColor, + face, + localIntersectionPoint ); + } + + if ( geomView ) + { + if ( intersectionHit ) + selItem = new RiuGeoMechSelectionItem( geomView, + nullptr, + -1, + gridIndex, + cellIndex, + curveColor, + gmFace, + localIntersectionPoint, + intersectionTriangleHit ); + else + selItem = new RiuGeoMechSelectionItem( geomView, + nullptr, + -1, + gridIndex, + cellIndex, + curveColor, + gmFace, + localIntersectionPoint ); + } + + if ( intersectionView ) selItem = new Riu2dIntersectionSelectionItem( intersectionView, selItem ); + } + + if ( appendToSelection ) + { + Riu3dSelectionManager::instance()->appendItemToSelection( selItem ); + } + else if ( selItem ) + { + Riu3dSelectionManager::instance()->setSelectedItem( selItem ); + } + + return false; +} diff --git a/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.h b/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.h new file mode 100644 index 0000000000..5d03adbc76 --- /dev/null +++ b/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.h @@ -0,0 +1,33 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor ASA +// +// 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 "RicPickEventHandler.h" + +//================================================================================================== +/// +//================================================================================================== +class RiuCellAndNncPickEventHandler : public RicDefaultPickEventHandler +{ +public: + static RiuCellAndNncPickEventHandler* instance(); + +protected: + bool handle3dPickEvent( const Ric3dPickEvent& eventObject ) override; +}; diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 3de6a3a02e..391da1f930 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -28,6 +28,7 @@ #include "RicEclipsePropertyFilterNewExec.h" #include "RicGeoMechPropertyFilterNewExec.h" #include "RicPickEventHandler.h" +#include "RiuCellAndNncPickEventHandler.h" #include "WellLogCommands/Ric3dWellLogCurvePickEventHandler.h" #include "WellPathCommands/RicIntersectionPickEventHandler.h" #include "WellPathCommands/RicWellPathPickEventHandler.h" @@ -137,6 +138,7 @@ RiuViewerCommands::RiuViewerCommands( RiuViewer* ownerViewer ) addDefaultPickEventHandler( Ric3dWellLogCurvePickEventHandler::instance() ); addDefaultPickEventHandler( RicWellPathPickEventHandler::instance() ); addDefaultPickEventHandler( RicContourMapPickEventHandler::instance() ); + addDefaultPickEventHandler( RiuCellAndNncPickEventHandler::instance() ); } } @@ -643,7 +645,7 @@ void RiuViewerCommands::handlePickAction( int winPosX, int winPosY, Qt::Keyboard if ( pickItemInfos.size() ) { - Ric3dPickEvent viewerEventObject( pickItemInfos, mainOrComparisonView ); + Ric3dPickEvent viewerEventObject( pickItemInfos, mainOrComparisonView, keyboardModifiers ); if ( sm_overridingPickHandler && sm_overridingPickHandler->handle3dPickEvent( viewerEventObject ) ) { @@ -660,77 +662,33 @@ void RiuViewerCommands::handlePickAction( int winPosX, int winPosY, Qt::Keyboard } // Old pick handling. Todo: Encapsulate in pickEventHandlers - - size_t gridIndex = cvf::UNDEFINED_SIZE_T; - size_t cellIndex = cvf::UNDEFINED_SIZE_T; - size_t nncIndex = cvf::UNDEFINED_SIZE_T; - cvf::StructGridInterface::FaceType face = cvf::StructGridInterface::NO_FACE; - int gmFace = -1; - bool intersectionHit = false; - std::array intersectionTriangleHit; - - cvf::Vec3d localIntersectionPoint( cvf::Vec3d::ZERO ); - cvf::Vec3d globalIntersectionPoint( cvf::Vec3d::ZERO ); - - // Extract all the above information from the pick { const cvf::Part* firstHitPart = nullptr; uint firstPartTriangleIndex = cvf::UNDEFINED_UINT; - - const cvf::Part* firstNncHitPart = nullptr; - uint nncPartTriangleIndex = cvf::UNDEFINED_UINT; + cvf::Vec3d globalIntersectionPoint( cvf::Vec3d::ZERO ); if ( pickItemInfos.size() ) { - size_t indexToFirstNoneNncItem = cvf::UNDEFINED_SIZE_T; - ; + size_t indexToFirstNoneNncItem = cvf::UNDEFINED_SIZE_T; size_t indexToNncItemNearFirstItem = cvf::UNDEFINED_SIZE_T; - ; findFirstItems( mainOrComparisonView, pickItemInfos, &indexToFirstNoneNncItem, &indexToNncItemNearFirstItem ); if ( indexToFirstNoneNncItem != cvf::UNDEFINED_SIZE_T ) { - localIntersectionPoint = pickItemInfos[indexToFirstNoneNncItem].localPickedPoint(); - globalIntersectionPoint = pickItemInfos[indexToFirstNoneNncItem].globalPickedPoint(); firstHitPart = pickItemInfos[indexToFirstNoneNncItem].pickedPart(); firstPartTriangleIndex = pickItemInfos[indexToFirstNoneNncItem].faceIdx(); - } - - if ( indexToNncItemNearFirstItem != cvf::UNDEFINED_SIZE_T ) - { - firstNncHitPart = pickItemInfos[indexToNncItemNearFirstItem].pickedPart(); - nncPartTriangleIndex = pickItemInfos[indexToNncItemNearFirstItem].faceIdx(); - } - } - - if ( firstNncHitPart && firstNncHitPart->sourceInfo() ) - { - const RivSourceInfo* rivSourceInfo = dynamic_cast( firstNncHitPart->sourceInfo() ); - if ( rivSourceInfo ) - { - if ( nncPartTriangleIndex < rivSourceInfo->m_NNCIndices->size() ) - { - nncIndex = rivSourceInfo->m_NNCIndices->get( nncPartTriangleIndex ); - } + globalIntersectionPoint = pickItemInfos[indexToFirstNoneNncItem].globalPickedPoint(); } } if ( firstHitPart && firstHitPart->sourceInfo() ) { - const RivObjectSourceInfo* rivObjectSourceInfo = dynamic_cast( - firstHitPart->sourceInfo() ); - const RivSourceInfo* rivSourceInfo = dynamic_cast( firstHitPart->sourceInfo() ); - const RivFemPickSourceInfo* femSourceInfo = dynamic_cast( - firstHitPart->sourceInfo() ); - const RivExtrudedCurveIntersectionSourceInfo* crossSectionSourceInfo = - dynamic_cast( firstHitPart->sourceInfo() ); - const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo = - dynamic_cast( firstHitPart->sourceInfo() ); - const RivSimWellPipeSourceInfo* eclipseWellSourceInfo = dynamic_cast( - firstHitPart->sourceInfo() ); - const RivWellConnectionSourceInfo* wellConnectionSourceInfo = dynamic_cast( - firstHitPart->sourceInfo() ); + // clang-format off + const RivObjectSourceInfo* rivObjectSourceInfo = dynamic_cast( firstHitPart->sourceInfo() ); + const RivSimWellPipeSourceInfo* eclipseWellSourceInfo = dynamic_cast( firstHitPart->sourceInfo() ); + const RivWellConnectionSourceInfo* wellConnectionSourceInfo = dynamic_cast( firstHitPart->sourceInfo() ); + // clang-format on if ( rivObjectSourceInfo ) { @@ -800,50 +758,18 @@ void RiuViewerCommands::handlePickAction( int winPosX, int winPosY, Qt::Keyboard RiuMainWindow::instance()->selectAsCurrentItem( textAnnot, true ); } } - - if ( rivSourceInfo ) + else if ( const RivExtrudedCurveIntersectionSourceInfo* crossSectionSourceInfo = + dynamic_cast( firstHitPart->sourceInfo() ) ) { - gridIndex = rivSourceInfo->gridIndex(); - if ( rivSourceInfo->hasCellFaceMapping() ) - { - CVF_ASSERT( rivSourceInfo->m_cellFaceFromTriangleMapper.notNull() ); - - cellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex( firstPartTriangleIndex ); - face = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace( firstPartTriangleIndex ); - } - } - else if ( femSourceInfo ) - { - gridIndex = femSourceInfo->femPartIndex(); - cellIndex = femSourceInfo->triangleToElmMapper()->elementIndex( firstPartTriangleIndex ); - gmFace = femSourceInfo->triangleToElmMapper()->elementFace( firstPartTriangleIndex ); - } - else if ( crossSectionSourceInfo ) - { - findCellAndGridIndex( mainOrComparisonView, - crossSectionSourceInfo, - firstPartTriangleIndex, - &cellIndex, - &gridIndex ); - intersectionHit = true; - intersectionTriangleHit = crossSectionSourceInfo->triangle( firstPartTriangleIndex ); - bool allowActiveViewChange = dynamic_cast( m_viewer->ownerViewWindow() ) == nullptr; RiuMainWindow::instance()->selectAsCurrentItem( crossSectionSourceInfo->intersection(), allowActiveViewChange ); } - else if ( intersectionBoxSourceInfo ) + else if ( const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo = + dynamic_cast( firstHitPart->sourceInfo() ) ) { - findCellAndGridIndex( mainOrComparisonView, - intersectionBoxSourceInfo, - firstPartTriangleIndex, - &cellIndex, - &gridIndex ); - intersectionHit = true; - intersectionTriangleHit = intersectionBoxSourceInfo->triangle( firstPartTriangleIndex ); - RiuMainWindow::instance()->selectAsCurrentItem( intersectionBoxSourceInfo->intersectionBox() ); } else if ( eclipseWellSourceInfo ) @@ -987,85 +913,6 @@ void RiuViewerCommands::handlePickAction( int winPosX, int winPosY, Qt::Keyboard } } } - - if ( cellIndex == cvf::UNDEFINED_SIZE_T ) - { - Riu3dSelectionManager::instance()->deleteAllItems(); - } - else - { - bool appendToSelection = false; - if ( keyboardModifiers & Qt::ControlModifier ) - { - appendToSelection = true; - } - - std::vector items; - Riu3dSelectionManager::instance()->selectedItems( items ); - - const caf::ColorTable& colorTable = RiaColorTables::selectionPaletteColors(); - - cvf::Color3f curveColor = colorTable.cycledColor3f( items.size() ); - - if ( !appendToSelection ) - { - curveColor = colorTable.cycledColor3f( 0 ); - } - - RiuSelectionItem* selItem = nullptr; - { - Rim2dIntersectionView* intersectionView = dynamic_cast( mainOrComparisonView ); - RimEclipseView* eclipseView = dynamic_cast( mainOrComparisonView ); - RimGeoMechView* geomView = dynamic_cast( mainOrComparisonView ); - - if ( intersectionView ) - { - intersectionView->intersection()->firstAncestorOrThisOfType( eclipseView ); - intersectionView->intersection()->firstAncestorOrThisOfType( geomView ); - } - - if ( eclipseView ) - { - selItem = new RiuEclipseSelectionItem( eclipseView, - gridIndex, - cellIndex, - nncIndex, - curveColor, - face, - localIntersectionPoint ); - } - - if ( geomView ) - { - if ( intersectionHit ) - selItem = new RiuGeoMechSelectionItem( geomView, - gridIndex, - cellIndex, - curveColor, - gmFace, - localIntersectionPoint, - intersectionTriangleHit ); - else - selItem = new RiuGeoMechSelectionItem( geomView, - gridIndex, - cellIndex, - curveColor, - gmFace, - localIntersectionPoint ); - } - - if ( intersectionView ) selItem = new Riu2dIntersectionSelectionItem( intersectionView, selItem ); - } - - if ( appendToSelection ) - { - Riu3dSelectionManager::instance()->appendItemToSelection( selItem ); - } - else if ( selItem ) - { - Riu3dSelectionManager::instance()->setSelectedItem( selItem ); - } - } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.h b/ApplicationCode/UserInterface/RiuViewerCommands.h index 9141d803d8..1685a75343 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.h +++ b/ApplicationCode/UserInterface/RiuViewerCommands.h @@ -69,17 +69,22 @@ public: cvf::Vec3d lastPickPositionInDomainCoords() const; bool isCurrentPickInComparisonView() const; + static void findFirstItems( Rim3dView* mainOrComparisonView, + const std::vector& pickItemInfos, + size_t* indexToFirstNoneNncItem, + size_t* indexToNncItemNearFirsItem ); + static void findCellAndGridIndex( Rim3dView* mainOrComparisonView, + const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo, + cvf::uint firstPartTriangleIndex, + size_t* cellIndex, + size_t* gridIndex ); + static void findCellAndGridIndex( Rim3dView* mainOrComparisonView, + const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo, + cvf::uint firstPartTriangleIndex, + size_t* cellIndex, + size_t* gridIndex ); + private: - void findCellAndGridIndex( Rim3dView* mainOrComparisonView, - const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo, - cvf::uint firstPartTriangleIndex, - size_t* cellIndex, - size_t* gridIndex ); - void findCellAndGridIndex( Rim3dView* mainOrComparisonView, - const RivBoxIntersectionSourceInfo* intersectionBoxSourceInfo, - cvf::uint firstPartTriangleIndex, - size_t* cellIndex, - size_t* gridIndex ); void ijkFromCellIndex( Rim3dView* mainOrComparisonView, size_t gridIdx, size_t cellIndex, @@ -87,12 +92,8 @@ private: size_t* j, size_t* k ); - void findFirstItems( Rim3dView* mainOrComparisonView, - const std::vector& pickItemInfos, - size_t* indexToFirstNoneNncItem, - size_t* indexToNncItemNearFirsItem ); - bool handleOverlayItemPicking( int winPosX, int winPosY ); + void handleTextPicking( int winPosX, int winPosY, cvf::HitItemCollection* hitItems ); void addCompareToViewMenu( caf::CmdFeatureMenuBuilder* menuBuilder ); @@ -110,5 +111,4 @@ private: static Ric3dViewPickEventHandler* sm_overridingPickHandler; static std::vector sm_defaultPickEventHandlers; - void handleTextPicking( int winPosX, int winPosY, cvf::HitItemCollection* hitItems ); };