From 2237f578c897f594485ab69cc6575afec358a2a9 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 7 Aug 2026 16:29:19 +0200 Subject: [PATCH] #14486 Contour Map: Always use an available cell result as data source A new contour map created from the right-click menu on a case used a hardcoded SOIL result, resulting in an empty view when SOIL was not present in the case. Use the cell result of an existing view for the same case if one is available, and otherwise fall back to RigCaseCellResultsData::defaultResult(), which verifies that the result exists before selecting it. Completion Type is a category result and is now excluded as a default result for both 3d views and contour maps. --- .../Commands/RicNewContourMapViewFeature.cpp | 45 +++++++++++++++---- .../Commands/RicNewContourMapViewFeature.h | 1 + .../RigCaseCellResultsData.cpp | 16 ++++--- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/ApplicationLibCode/Commands/RicNewContourMapViewFeature.cpp b/ApplicationLibCode/Commands/RicNewContourMapViewFeature.cpp index c451776604..1afe5f23c7 100644 --- a/ApplicationLibCode/Commands/RicNewContourMapViewFeature.cpp +++ b/ApplicationLibCode/Commands/RicNewContourMapViewFeature.cpp @@ -19,6 +19,7 @@ #include "RicNewContourMapViewFeature.h" #include "RigActiveCellInfo.h" +#include "RigCaseCellResultsData.h" #include "RigEclipseCaseData.h" #include "RigFemPartCollection.h" @@ -51,7 +52,7 @@ #include "RiaColorTools.h" #include "RiaLogging.h" -#include "RiaPreferencesGrid.h" +#include "RiaResultNames.h" #include "cafPdmDocument.h" #include "cafSelectionManager.h" @@ -311,7 +312,11 @@ RimEclipseContourMapView* RicNewContourMapViewFeature::createEclipseContourMap( contourMap->setEclipseCase( eclipseCase ); contourMap->resetDockWindowId(); - assignDefaultResultAndLegend( contourMap ); + // Prefer the cell result of an existing view for this case, fall back to the default result of the case + if ( !assignResultFromExistingView( contourMap ) ) + { + assignDefaultResultAndLegend( contourMap ); + } caf::PdmDocument::updateUiIconStateRecursively( contourMap ); @@ -415,13 +420,35 @@ RimGeoMechContourMapView* RicNewContourMapViewFeature::createGeoMechContourMap( //-------------------------------------------------------------------------------------------------- void RicNewContourMapViewFeature::assignDefaultResultAndLegend( RimEclipseContourMapView* contourMap ) { - if ( contourMap->cellResult() ) - { - contourMap->cellResult()->setResultType( RiaDefines::ResultCatType::DYNAMIC_NATIVE ); + if ( !contourMap->cellResult() ) return; - if ( RiaPreferencesGrid::current()->loadAndShowSoil() ) - { - contourMap->cellResult()->setResultVariable( "SOIL" ); - } + // Use the default result of the case, as this result is guaranteed to be available. See issue #14486. + if ( auto cellResultsData = contourMap->currentGridCellResults() ) + { + contourMap->cellResult()->setFromEclipseResultAddress( cellResultsData->defaultResult() ); } } + +//-------------------------------------------------------------------------------------------------- +/// Use the cell result of an existing view for the same case, if this result is available +//-------------------------------------------------------------------------------------------------- +bool RicNewContourMapViewFeature::assignResultFromExistingView( RimEclipseContourMapView* contourMap ) +{ + if ( !contourMap->cellResult() || !contourMap->eclipseCase() ) return false; + + for ( auto view : contourMap->eclipseCase()->reservoirViews() ) + { + if ( !view || view == contourMap ) continue; + + auto sourceCellResult = view->cellResult(); + if ( !sourceCellResult || sourceCellResult->isTernarySaturationSelected() || !sourceCellResult->hasResult() ) continue; + + // Completion Type is a category result, and is not useful as a contour map data source + if ( sourceCellResult->resultVariable() == RiaResultNames::completionTypeResultName() ) continue; + + contourMap->cellResult()->setFromEclipseResultAddress( sourceCellResult->eclipseResultAddress() ); + return true; + } + + return false; +} diff --git a/ApplicationLibCode/Commands/RicNewContourMapViewFeature.h b/ApplicationLibCode/Commands/RicNewContourMapViewFeature.h index 696f2f3455..a9f673053b 100644 --- a/ApplicationLibCode/Commands/RicNewContourMapViewFeature.h +++ b/ApplicationLibCode/Commands/RicNewContourMapViewFeature.h @@ -51,4 +51,5 @@ protected: static RimGeoMechContourMapView* createGeoMechContourMap( RimGeoMechCase* geoMechCase ); static void assignDefaultResultAndLegend( RimEclipseContourMapView* contourMap ); + static bool assignResultFromExistingView( RimEclipseContourMapView* contourMap ); }; diff --git a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp index 15eff8bc15..65d0d22de3 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -830,6 +830,10 @@ RigEclipseResultAddress RigCaseCellResultsData::defaultResult() const { auto allResults = existingResults(); + // Completion Type is a category result, and is not useful as a default result. See issue #14486. + auto isCandidateResult = []( const RigEclipseResultAddress& adr, RiaDefines::ResultCatType category ) + { return adr.resultCatType() == category && adr.resultName() != RiaResultNames::completionTypeResultName(); }; + if ( maxTimeStepCount() > 0 ) { auto prefs = RiaPreferencesGrid::current(); @@ -860,8 +864,8 @@ RigEclipseResultAddress RigCaseCellResultsData::defaultResult() const auto dynamicResult = std::find_if( allResults.begin(), allResults.end(), - []( const RigEclipseResultAddress& adr ) - { return adr.resultCatType() == RiaDefines::ResultCatType::DYNAMIC_NATIVE; } ); + [&isCandidateResult]( const RigEclipseResultAddress& adr ) + { return isCandidateResult( adr, RiaDefines::ResultCatType::DYNAMIC_NATIVE ); } ); if ( dynamicResult != allResults.end() ) return *dynamicResult; } @@ -869,16 +873,16 @@ RigEclipseResultAddress RigCaseCellResultsData::defaultResult() const // If any input property exists, use that auto inputProperty = std::find_if( allResults.begin(), allResults.end(), - []( const RigEclipseResultAddress& adr ) - { return adr.resultCatType() == RiaDefines::ResultCatType::INPUT_PROPERTY; } ); + [&isCandidateResult]( const RigEclipseResultAddress& adr ) + { return isCandidateResult( adr, RiaDefines::ResultCatType::INPUT_PROPERTY ); } ); if ( inputProperty != allResults.end() ) return *inputProperty; // If any static property exists, use that auto staticResult = std::find_if( allResults.begin(), allResults.end(), - []( const RigEclipseResultAddress& adr ) - { return adr.resultCatType() == RiaDefines::ResultCatType::STATIC_NATIVE; } ); + [&isCandidateResult]( const RigEclipseResultAddress& adr ) + { return isCandidateResult( adr, RiaDefines::ResultCatType::STATIC_NATIVE ); } ); if ( staticResult != allResults.end() ) return *staticResult;