#5269 Cycle cell selection when clicking an NNC

This commit is contained in:
Jacob Støren 2020-01-02 12:39:14 +01:00
parent bbb5e89fe7
commit f1cee7ab36

View File

@ -22,6 +22,7 @@
#include "Rim2dIntersectionView.h" #include "Rim2dIntersectionView.h"
#include "RimBoxIntersection.h" #include "RimBoxIntersection.h"
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h" #include "RimEclipseCellColors.h"
#include "RimEclipseView.h" #include "RimEclipseView.h"
#include "RimExtrudedCurveIntersection.h" #include "RimExtrudedCurveIntersection.h"
@ -38,6 +39,10 @@
#include "RivFemPickSourceInfo.h" #include "RivFemPickSourceInfo.h"
#include "RivSourceInfo.h" #include "RivSourceInfo.h"
#include "RigEclipseCaseData.h"
#include "RigMainGrid.h"
#include "RigNNCData.h"
#include "cafPdmObjectHandle.h" #include "cafPdmObjectHandle.h"
#include "cvfPart.h" #include "cvfPart.h"
@ -113,26 +118,25 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
if ( !firstHitPart ) return false; if ( !firstHitPart ) return false;
size_t gridIndex = cvf::UNDEFINED_SIZE_T; size_t gridIndex = cvf::UNDEFINED_SIZE_T;
size_t cellIndex = cvf::UNDEFINED_SIZE_T; size_t gridLocalCellIndex = cvf::UNDEFINED_SIZE_T;
cvf::StructGridInterface::FaceType face = cvf::StructGridInterface::NO_FACE; cvf::StructGridInterface::FaceType face = cvf::StructGridInterface::NO_FACE;
int gmFace = -1; int gmFace = -1;
bool intersectionHit = false; bool intersectionHit = false;
std::array<cvf::Vec3f, 3> intersectionTriangleHit; std::array<cvf::Vec3f, 3> intersectionTriangleHit;
RimGeoMechResultDefinition* geomResDef = nullptr; RimGeoMechResultDefinition* geomResDef = nullptr;
RimEclipseResultDefinition* eclResDef = nullptr; RimEclipseResultDefinition* eclResDef = nullptr;
size_t timestepIndex = -1; size_t timestepIndex = -1;
// clang-format off // clang-format off
if ( const RivSourceInfo* rivSourceInfo = if ( const RivSourceInfo* rivSourceInfo = dynamic_cast<const RivSourceInfo*>( firstHitPart->sourceInfo() ) )
dynamic_cast<const RivSourceInfo*>( firstHitPart->sourceInfo() ) )
{ {
gridIndex = rivSourceInfo->gridIndex(); gridIndex = rivSourceInfo->gridIndex();
if ( rivSourceInfo->hasCellFaceMapping() ) if ( rivSourceInfo->hasCellFaceMapping() )
{ {
CVF_ASSERT( rivSourceInfo->m_cellFaceFromTriangleMapper.notNull() ); CVF_ASSERT( rivSourceInfo->m_cellFaceFromTriangleMapper.notNull() );
cellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex( firstPartTriangleIndex ); gridLocalCellIndex = rivSourceInfo->m_cellFaceFromTriangleMapper->cellIndex( firstPartTriangleIndex );
face = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace( firstPartTriangleIndex ); face = rivSourceInfo->m_cellFaceFromTriangleMapper->cellFace( firstPartTriangleIndex );
} }
} }
@ -140,17 +144,17 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
dynamic_cast<const RivFemPickSourceInfo*>( firstHitPart->sourceInfo() ) ) dynamic_cast<const RivFemPickSourceInfo*>( firstHitPart->sourceInfo() ) )
{ {
gridIndex = femSourceInfo->femPartIndex(); gridIndex = femSourceInfo->femPartIndex();
cellIndex = femSourceInfo->triangleToElmMapper()->elementIndex( firstPartTriangleIndex ); gridLocalCellIndex = femSourceInfo->triangleToElmMapper()->elementIndex( firstPartTriangleIndex );
gmFace = femSourceInfo->triangleToElmMapper()->elementFace( firstPartTriangleIndex ); gmFace = femSourceInfo->triangleToElmMapper()->elementFace( firstPartTriangleIndex );
} }
else if ( const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo = else if ( const RivExtrudedCurveIntersectionSourceInfo* intersectionSourceInfo =
dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) ) dynamic_cast<const RivExtrudedCurveIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{ {
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView, RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionSourceInfo, intersectionSourceInfo,
firstPartTriangleIndex, firstPartTriangleIndex,
&cellIndex, &gridLocalCellIndex,
&gridIndex ); &gridIndex );
intersectionHit = true; intersectionHit = true;
intersectionTriangleHit = intersectionSourceInfo->triangle( firstPartTriangleIndex ); intersectionTriangleHit = intersectionSourceInfo->triangle( firstPartTriangleIndex );
@ -173,10 +177,10 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
dynamic_cast<const RivBoxIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) ) dynamic_cast<const RivBoxIntersectionSourceInfo*>( firstHitPart->sourceInfo() ) )
{ {
RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView, RiuViewerCommands::findCellAndGridIndex( mainOrComparisonView,
intersectionBoxSourceInfo, intersectionBoxSourceInfo,
firstPartTriangleIndex, firstPartTriangleIndex,
&cellIndex, &gridLocalCellIndex,
&gridIndex ); &gridIndex );
intersectionHit = true; intersectionHit = true;
intersectionTriangleHit = intersectionBoxSourceInfo->triangle( firstPartTriangleIndex ); intersectionTriangleHit = intersectionBoxSourceInfo->triangle( firstPartTriangleIndex );
@ -197,7 +201,7 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
} }
// clang-format on // clang-format on
if ( cellIndex == cvf::UNDEFINED_SIZE_T ) if ( gridLocalCellIndex == cvf::UNDEFINED_SIZE_T )
{ {
Riu3dSelectionManager::instance()->deleteAllItems(); Riu3dSelectionManager::instance()->deleteAllItems();
return false; return false;
@ -253,11 +257,55 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
if ( eclResDef ) if ( eclResDef )
{ {
// Select the other cell if we are about to select the same cell at an nnc.
// To make consecutive clicks toggle between closest and furthest cell
// clang-format off
if ( nncIndex != cvf::UNDEFINED_SIZE_T )
{
auto selectedItem = dynamic_cast<RiuEclipseSelectionItem*>( Riu3dSelectionManager::instance()->selectedItem() );
if ( selectedItem &&
selectedItem->m_gridIndex == gridIndex &&
selectedItem->m_gridLocalCellIndex == gridLocalCellIndex &&
selectedItem->m_nncIndex == nncIndex )
{
RigMainGrid* mainGrid = eclipseView->eclipseCase()->eclipseCaseData()->mainGrid();
const RigConnection& nncConn = mainGrid->nncData()->connections()[nncIndex];
size_t c1LocalIdx = cvf::UNDEFINED_SIZE_T;
const RigGridBase* grid1 = mainGrid->gridAndGridLocalIdxFromGlobalCellIdx(nncConn.m_c1GlobIdx, &c1LocalIdx);
size_t c1GridIdx = grid1->gridIndex();
size_t c2LocalIdx = cvf::UNDEFINED_SIZE_T;
const RigGridBase* grid2 = mainGrid->gridAndGridLocalIdxFromGlobalCellIdx(nncConn.m_c2GlobIdx, &c2LocalIdx);
size_t c2GridIdx = grid2->gridIndex();
if (gridLocalCellIndex == c1LocalIdx && gridIndex == c1GridIdx)
{
gridLocalCellIndex = c2LocalIdx;
gridIndex = c2GridIdx;
face = cvf::StructGridInterface::oppositeFace(face);
}
else if (gridLocalCellIndex == c2LocalIdx && gridIndex == c2GridIdx)
{
gridLocalCellIndex = c1LocalIdx;
gridIndex = c1GridIdx;
face = cvf::StructGridInterface::oppositeFace(face);
}
else
{
// None really matched, error in nnc data.
}
}
}
// clang-format on
selItem = new RiuEclipseSelectionItem( associatedGridView, selItem = new RiuEclipseSelectionItem( associatedGridView,
eclResDef, eclResDef,
timestepIndex, timestepIndex,
gridIndex, gridIndex,
cellIndex, gridLocalCellIndex,
nncIndex, nncIndex,
curveColor, curveColor,
face, face,
@ -271,7 +319,7 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
geomResDef, geomResDef,
timestepIndex, timestepIndex,
gridIndex, gridIndex,
cellIndex, gridLocalCellIndex,
curveColor, curveColor,
gmFace, gmFace,
localIntersectionPoint, localIntersectionPoint,
@ -281,7 +329,7 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve
geomResDef, geomResDef,
timestepIndex, timestepIndex,
gridIndex, gridIndex,
cellIndex, gridLocalCellIndex,
curveColor, curveColor,
gmFace, gmFace,
localIntersectionPoint ); localIntersectionPoint );