#14772 Ricf: Only fall back to the first case/group for replaceCase and replaceSourceCases

RicfForwarding::findCase() and findCaseGroup() resolved a negative id to the first
Eclipse result case / first case group for every legacy command. Only replaceCase and
replaceSourceCases had that behavior; all other commands rejected a missing id. Make the
lookups strict and add explicit findCaseOrFirstEclipseResultCase() / findCaseGroupOrFirst()
for the two replace commands.
This commit is contained in:
Kristian Bendiksen committed 2026-09-22 14:19:23 +02:00
1 parent d17930d2b3
commit 7cb5ee4363
4 files changed
+63 -25

No files matched your search

@@ -42,18 +42,9 @@ std::expected<RimCase*, QString> RicfForwarding::findCase( int caseId )
RimProject* project = RimProject::current();
if ( !project ) return std::unexpected( "No project is available." );
std::vector<RimCase*> allCases = project->allGridCases();
if ( caseId < 0 )
{
// Matches RiaProjectModifier::firstCaseId(): the first occurrence is the first Eclipse result case
for ( RimCase* rimCase : allCases )
{
if ( dynamic_cast<RimEclipseResultCase*>( rimCase ) ) return rimCase;
}
return std::unexpected( "No Eclipse result cases found in project." );
}
if ( caseId < 0 ) return std::unexpected( "No case id specified." );
for ( RimCase* rimCase : allCases )
for ( RimCase* rimCase : project->allGridCases() )
{
if ( rimCase && rimCase->caseId() == caseId ) return rimCase;
}
@@ -61,6 +52,24 @@ std::expected<RimCase*, QString> RicfForwarding::findCase( int caseId )
return std::unexpected( QString( "Could not find case with ID %1" ).arg( caseId ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<RimCase*, QString> RicfForwarding::findCaseOrFirstEclipseResultCase( int caseId )
{
if ( caseId >= 0 ) return findCase( caseId );
RimProject* project = RimProject::current();
if ( !project ) return std::unexpected( "No project is available." );
// Matches RiaProjectModifier::firstCaseId(): the first occurrence is the first Eclipse result case
for ( RimCase* rimCase : project->allGridCases() )
{
if ( dynamic_cast<RimEclipseResultCase*>( rimCase ) ) return rimCase;
}
return std::unexpected( "No Eclipse result cases found in project." );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -95,11 +104,10 @@ std::expected<Rim3dView*, QString> RicfForwarding::findView( int viewId )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<RimIdenticalGridCaseGroup*, QString> RicfForwarding::findCaseGroup( int groupId )
namespace
{
std::vector<RimIdenticalGridCaseGroup*> allCaseGroups( RimProject* project )
{
RimProject* project = RimProject::current();
if ( !project ) return std::unexpected( "No project is available." );
std::vector<RimIdenticalGridCaseGroup*> caseGroups;
for ( RimOilField* oilField : project->oilFields() )
{
@@ -110,14 +118,21 @@ std::expected<RimIdenticalGridCaseGroup*, QString> RicfForwarding::findCaseGroup
if ( caseGroup ) caseGroups.push_back( caseGroup );
}
}
return caseGroups;
}
} // namespace
if ( groupId < 0 )
{
if ( caseGroups.empty() ) return std::unexpected( "No grid case groups found in project." );
return caseGroups.front();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<RimIdenticalGridCaseGroup*, QString> RicfForwarding::findCaseGroup( int groupId )
{
RimProject* project = RimProject::current();
if ( !project ) return std::unexpected( "No project is available." );
for ( RimIdenticalGridCaseGroup* caseGroup : caseGroups )
if ( groupId < 0 ) return std::unexpected( "No grid case group id specified." );
for ( RimIdenticalGridCaseGroup* caseGroup : allCaseGroups( project ) )
{
if ( caseGroup->groupId() == groupId ) return caseGroup;
}
@@ -125,6 +140,21 @@ std::expected<RimIdenticalGridCaseGroup*, QString> RicfForwarding::findCaseGroup
return std::unexpected( QString( "Could not find grid case group with ID %1" ).arg( groupId ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<RimIdenticalGridCaseGroup*, QString> RicfForwarding::findCaseGroupOrFirst( int groupId )
{
if ( groupId >= 0 ) return findCaseGroup( groupId );
RimProject* project = RimProject::current();
if ( !project ) return std::unexpected( "No project is available." );
auto caseGroups = allCaseGroups( project );
if ( caseGroups.empty() ) return std::unexpected( "No grid case groups found in project." );
return caseGroups.front();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -43,18 +43,26 @@ class PdmObjectHandle;
//==================================================================================================
namespace RicfForwarding
{
/// Find a grid case by id. A negative id resolves to the first Eclipse result case in the project.
/// Find a grid case by id. A negative id is not accepted.
std::expected<RimCase*, QString> findCase( int caseId );
/// Find a grid case by id, or the first Eclipse result case in the project when the id is negative.
/// Only for legacy commands that documented this fallback (replaceCase).
std::expected<RimCase*, QString> findCaseOrFirstEclipseResultCase( int caseId );
/// Find a view by id in the given case. A negative id is not accepted.
std::expected<Rim3dView*, QString> findView( RimCase* rimCase, int viewId );
/// Find a 3D view by id anywhere in the project. A negative id is not accepted.
std::expected<Rim3dView*, QString> findView( int viewId );
/// Find a grid case group by id. A negative id resolves to the first case group in the project.
/// Find a grid case group by id. A negative id is not accepted.
std::expected<RimIdenticalGridCaseGroup*, QString> findCaseGroup( int groupId );
/// Find a grid case group by id, or the first case group in the project when the id is negative.
/// Only for legacy commands that documented this fallback (replaceSourceCases).
std::expected<RimIdenticalGridCaseGroup*, QString> findCaseGroupOrFirst( int groupId );
/// Find a statistics case by case id in any grid case group.
std::expected<RimEclipseStatisticsCase*, QString> findStatisticsCase( int caseId );
@@ -81,7 +81,7 @@ caf::PdmScriptResponse RicfSingleCaseReplace::execute()
projectPath = lastProjectPath;
}
auto rimCase = RicfForwarding::findCase( m_caseId() );
auto rimCase = RicfForwarding::findCaseOrFirstEclipseResultCase( m_caseId() );
if ( !rimCase ) return RicfForwarding::errorResponse( rimCase.error(), commandName );
RimCase_replaceGrid method( rimCase.value() );
@@ -57,7 +57,7 @@ caf::PdmScriptResponse RicfReplaceSourceCases::execute()
commandName );
}
auto caseGroup = RicfForwarding::findCaseGroup( m_caseGroupId() );
auto caseGroup = RicfForwarding::findCaseGroupOrFirst( m_caseGroupId() );
if ( !caseGroup ) return RicfForwarding::errorResponse( caseGroup.error(), commandName );
RimIdenticalGridCaseGroup_replaceSourceCases method( caseGroup.value() );