#14772 Forward createStatisticsCase to RimcIdenticalGridCaseGroup_createStatisticsCase

Add a PopulateResultSelection parameter to the existing object method.
The legacy command selects all available properties (via
createAndAppendStatisticsCase) while the object method created an
empty selection; the default (false) keeps the object method behavior
and the Ricf forwarder passes true. The created case now gets a case id
assigned in both paths.

Add RicfForwarding::findCaseGroup() and findStatisticsCase().
This commit is contained in:
Kristian Bendiksen committed 2026-09-22 14:19:23 +02:00
1 parent 0416bd041e
commit 111741b365
6 files changed
+138 -25

No files matched your search

@@ -22,8 +22,13 @@
#include "Rim3dView.h"
#include "RimCase.h"
#include "RimEclipseCaseCollection.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseStatisticsCase.h"
#include "RimEclipseStatisticsCaseCollection.h"
#include "RimFractureTemplate.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimOilField.h"
#include "RimProject.h"
#include "cafPdmObjectHandle.h"
@@ -86,6 +91,55 @@ std::expected<Rim3dView*, QString> RicfForwarding::findView( int viewId )
return std::unexpected( QString( "Could not find view with ID %1" ).arg( viewId ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<RimIdenticalGridCaseGroup*, QString> RicfForwarding::findCaseGroup( int groupId )
{
RimProject* project = RimProject::current();
if ( !project ) return std::unexpected( "No project is available." );
std::vector<RimIdenticalGridCaseGroup*> caseGroups;
for ( RimOilField* oilField : project->oilFields() )
{
RimEclipseCaseCollection* analysisModels = oilField ? oilField->analysisModels() : nullptr;
if ( !analysisModels ) continue;
for ( RimIdenticalGridCaseGroup* caseGroup : analysisModels->caseGroups )
{
if ( caseGroup ) caseGroups.push_back( caseGroup );
}
}
if ( groupId < 0 )
{
if ( caseGroups.empty() ) return std::unexpected( "No grid case groups found in project." );
return caseGroups.front();
}
for ( RimIdenticalGridCaseGroup* caseGroup : caseGroups )
{
if ( caseGroup->groupId() == groupId ) return caseGroup;
}
return std::unexpected( QString( "Could not find grid case group with ID %1" ).arg( groupId ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<RimEclipseStatisticsCase*, QString> RicfForwarding::findStatisticsCase( int caseId )
{
RimProject* project = RimProject::current();
if ( !project ) return std::unexpected( "No project is available." );
for ( RimEclipseStatisticsCase* statsCase : project->descendantsIncludingThisOfType<RimEclipseStatisticsCase>() )
{
if ( statsCase && statsCase->caseId() == caseId ) return statsCase;
}
return std::unexpected( QString( "Could not find statistics case with ID %1" ).arg( caseId ) );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -27,6 +27,8 @@
class RimCase;
class Rim3dView;
class RimFractureTemplate;
class RimIdenticalGridCaseGroup;
class RimEclipseStatisticsCase;
namespace caf
{
@@ -49,6 +51,12 @@ 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.
std::expected<RimIdenticalGridCaseGroup*, QString> findCaseGroup( int groupId );
/// Find a statistics case by case id in any grid case group.
std::expected<RimEclipseStatisticsCase*, QString> findStatisticsCase( int caseId );
/// Find a fracture template by id.
std::expected<RimFractureTemplate*, QString> findFractureTemplate( int templateId );
@@ -18,18 +18,13 @@
#include "RicfCreateStatisticsCase.h"
#include "RimCaseCollection.h"
#include "RimEclipseStatisticsCase.h"
#include "RimEclipseStatisticsCaseCollection.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimProject.h"
#include "RicfCommandForwarding.h"
#include "Riu3DMainWindowTools.h"
#include "RimEclipseStatisticsCase.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimcIdenticalGridCaseGroup.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafSelectionManager.h"
#include <QAction>
CAF_PDM_SOURCE_INIT( RicfCreateStatisticsCaseResult, "createStatisticsCaseResult" );
@@ -57,20 +52,21 @@ RicfCreateStatisticsCase::RicfCreateStatisticsCase()
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicfCreateStatisticsCase::execute()
{
RimProject* project = RimProject::current();
const QString commandName = classKeyword();
std::vector<RimIdenticalGridCaseGroup*> gridCaseGroups = project->descendantsIncludingThisOfType<RimIdenticalGridCaseGroup>();
for ( auto gridCaseGroup : gridCaseGroups )
{
if ( gridCaseGroup->groupId() == m_caseGroupId() )
{
RimEclipseStatisticsCase* createdObject = gridCaseGroup->createAndAppendStatisticsCase();
project->assignCaseIdToCase( createdObject );
gridCaseGroup->updateConnectedEditors();
caf::PdmScriptResponse response;
response.setResult( new RicfCreateStatisticsCaseResult( createdObject->caseId() ) );
return response;
}
}
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, "Could not find grid case group" );
auto caseGroup = RicfForwarding::findCaseGroup( m_caseGroupId() );
if ( !caseGroup ) return RicfForwarding::errorResponse( caseGroup.error(), commandName );
RimcIdenticalGridCaseGroup_createStatisticsCase method( caseGroup.value() );
method.setPopulateResultSelection( true );
auto result = method.execute();
if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName );
auto* statsCase = dynamic_cast<RimEclipseStatisticsCase*>( result.value() );
if ( !statsCase ) return RicfForwarding::errorResponse( "Created object is not a statistics case", commandName );
caf::PdmScriptResponse response;
response.setResult( new RicfCreateStatisticsCaseResult( statsCase->caseId() ) );
return response;
}
@@ -20,6 +20,7 @@
#include "RimEclipseStatisticsCase.h"
#include "RimIdenticalGridCaseGroup.h"
#include "RimProject.h"
#include "cafPdmFieldScriptingCapability.h"
@@ -32,6 +33,24 @@ RimcIdenticalGridCaseGroup_createStatisticsCase::RimcIdenticalGridCaseGroup_crea
: caf::PdmObjectCreationMethod( self )
{
CAF_PDM_InitObject( "Create Statistics Case", "", "", "Create a new statistics case in the grid case group" );
CAF_PDM_InitScriptableField( &m_populateResultSelection,
"PopulateResultSelection",
false,
"Populate Result Selection",
"",
"",
"Select all available source properties for statistics. When false, no properties are selected "
"and set_source_properties() must be called before compute_statistics()." );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimcIdenticalGridCaseGroup_createStatisticsCase::setPopulateResultSelection( bool populate )
{
m_populateResultSelection = populate;
}
//--------------------------------------------------------------------------------------------------
@@ -40,8 +59,13 @@ RimcIdenticalGridCaseGroup_createStatisticsCase::RimcIdenticalGridCaseGroup_crea
std::expected<caf::PdmObjectHandle*, QString> RimcIdenticalGridCaseGroup_createStatisticsCase::execute()
{
auto gridCaseGroup = self<RimIdenticalGridCaseGroup>();
auto statCase = gridCaseGroup->createAndAppendEmptyStatisticsCase();
if ( !gridCaseGroup ) return std::unexpected( "No grid case group is available." );
RimEclipseStatisticsCase* statCase = m_populateResultSelection() ? gridCaseGroup->createAndAppendStatisticsCase()
: gridCaseGroup->createAndAppendEmptyStatisticsCase();
if ( !statCase ) return std::unexpected( "Could not create statistics case." );
RimProject::current()->assignCaseIdToCase( statCase );
gridCaseGroup->updateConnectedEditors();
return statCase;
@@ -36,6 +36,11 @@ class RimcIdenticalGridCaseGroup_createStatisticsCase : public caf::PdmObjectCre
public:
RimcIdenticalGridCaseGroup_createStatisticsCase( caf::PdmObjectHandle* self );
void setPopulateResultSelection( bool populate );
std::expected<caf::PdmObjectHandle*, QString> execute() override;
QString classKeywordReturnedType() const override;
private:
caf::PdmField<bool> m_populateResultSelection;
};