From 6548c4f4dbbd51cac98f82ca462661a245f72753 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Wed, 16 Sep 2026 17:34:39 +0200 Subject: [PATCH] #14772 Python: Add Project.create_grid_case_group as object method and forward createGridCaseGroup to it RimProject_createGridCaseGroup returns the created group object. RicfCreateGridCaseGroup forwards to it and wraps the group id and name in the legacy createGridCaseGroupResult. The hand-written Python wrapper is removed since the generated method has the same signature. --- .../RicfCreateGridCaseGroup.cpp | 39 +++++------- .../ProjectDataModelCommands/RimcProject.cpp | 62 +++++++++++++++++++ .../ProjectDataModelCommands/RimcProject.h | 20 ++++++ GrpcInterface/Python/rips/project.py | 17 ----- 4 files changed, 96 insertions(+), 42 deletions(-) diff --git a/ApplicationLibCode/CommandFileInterface/RicfCreateGridCaseGroup.cpp b/ApplicationLibCode/CommandFileInterface/RicfCreateGridCaseGroup.cpp index 203dd603d6..15eaffd967 100644 --- a/ApplicationLibCode/CommandFileInterface/RicfCreateGridCaseGroup.cpp +++ b/ApplicationLibCode/CommandFileInterface/RicfCreateGridCaseGroup.cpp @@ -18,17 +18,14 @@ #include "RicfCreateGridCaseGroup.h" -#include "RiaApplication.h" -#include "RiaImportEclipseCaseTools.h" +#include "RicfCommandForwarding.h" #include "RimIdenticalGridCaseGroup.h" +#include "RimProject.h" +#include "RimcProject.h" #include "cafPdmFieldScriptingCapability.h" -#include -#include -#include - CAF_PDM_SOURCE_INIT( RicfCreateGridCaseGroupResult, "createGridCaseGroupResult" ); //-------------------------------------------------------------------------------------------------- @@ -56,26 +53,18 @@ RicfCreateGridCaseGroup::RicfCreateGridCaseGroup() //-------------------------------------------------------------------------------------------------- caf::PdmScriptResponse RicfCreateGridCaseGroup::execute() { - QStringList casePaths; - for ( QString casePath : m_casePaths() ) - { - QFileInfo casePathInfo( casePath ); - if ( !casePathInfo.exists() ) - { - QDir startDir( RiaApplication::instance()->startDir() ); - casePath = startDir.absoluteFilePath( casePath ); - } - casePaths.push_back( casePath ); - } + const QString commandName = classKeyword(); - RimIdenticalGridCaseGroup* caseGroup = nullptr; + RimProject_createGridCaseGroup method( RimProject::current() ); + method.setCasePaths( m_casePaths() ); - if ( RiaImportEclipseCaseTools::addEclipseCases( casePaths, &caseGroup ) && caseGroup ) - { - caf::PdmScriptResponse response; - response.setResult( new RicfCreateGridCaseGroupResult( caseGroup->groupId(), caseGroup->name() ) ); - return response; - } + auto result = method.execute(); + if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName ); - return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, "Could not load grid case group" ); + auto* caseGroup = dynamic_cast( result.value() ); + if ( !caseGroup ) return RicfForwarding::errorResponse( "Created object is not a grid case group", commandName ); + + caf::PdmScriptResponse response; + response.setResult( new RicfCreateGridCaseGroupResult( caseGroup->groupId(), caseGroup->name() ) ); + return response; } diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcProject.cpp b/ApplicationLibCode/ProjectDataModelCommands/RimcProject.cpp index da064f14ff..6627f4fd1d 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcProject.cpp +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcProject.cpp @@ -23,6 +23,7 @@ #include "KeyValueStore/RiaKeyValueStoreUtil.h" #include "RiaApplication.h" #include "RiaGuiApplication.h" +#include "RiaImportEclipseCaseTools.h" #include "RiaLogging.h" #include "RiaPreferencesGrid.h" #include "RiaQStringFormatter.h" @@ -45,6 +46,7 @@ #include "RimEclipseCellColors.h" #include "RimEclipseView.h" #include "RimFileSummaryCase.h" +#include "RimIdenticalGridCaseGroup.h" #include "RimMainPlotCollection.h" #include "RimOilField.h" #include "RimProject.h" @@ -678,3 +680,63 @@ QString RimProject_loadCase::classKeywordReturnedType() const { return RimCase::classKeywordStatic(); } + +CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_createGridCaseGroup, "createGridCaseGroup" ); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimProject_createGridCaseGroup::RimProject_createGridCaseGroup( caf::PdmObjectHandle* self ) + : caf::PdmObjectCreationMethod( self ) +{ + CAF_PDM_InitObject( "Create Grid Case Group", "", "", "Create a grid case group from a list of grid files with identical grids" ); + + CAF_PDM_InitScriptableField( &m_casePaths, "CasePaths", std::vector(), "Case Paths", "", "", "Paths to the grid files" ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimProject_createGridCaseGroup::setCasePaths( const std::vector& casePaths ) +{ + m_casePaths = casePaths; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::expected RimProject_createGridCaseGroup::execute() +{ + auto* project = self(); + if ( !project ) return std::unexpected( "No project is available." ); + + if ( m_casePaths().empty() ) return std::unexpected( "No case paths specified." ); + + QStringList casePaths; + for ( QString casePath : m_casePaths() ) + { + QFileInfo casePathInfo( casePath ); + if ( !casePathInfo.exists() ) + { + QDir startDir( RiaApplication::instance()->startDir() ); + casePath = startDir.absoluteFilePath( casePath ); + } + casePaths.push_back( casePath ); + } + + RimIdenticalGridCaseGroup* caseGroup = nullptr; + if ( !RiaImportEclipseCaseTools::addEclipseCases( casePaths, &caseGroup ) || !caseGroup ) + { + return std::unexpected( "Could not load grid case group" ); + } + + return caseGroup; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimProject_createGridCaseGroup::classKeywordReturnedType() const +{ + return RimIdenticalGridCaseGroup::classKeywordStatic(); +} diff --git a/ApplicationLibCode/ProjectDataModelCommands/RimcProject.h b/ApplicationLibCode/ProjectDataModelCommands/RimcProject.h index 00e5e67e45..13fc6724fc 100644 --- a/ApplicationLibCode/ProjectDataModelCommands/RimcProject.h +++ b/ApplicationLibCode/ProjectDataModelCommands/RimcProject.h @@ -31,6 +31,7 @@ #include class Rim3dView; +class RimIdenticalGridCaseGroup; //================================================================================================== /// @@ -227,3 +228,22 @@ private: caf::PdmField m_path; caf::PdmField m_gridOnly; }; + +//================================================================================================== +/// Create a grid case group (for statistics) from a list of grid files with identical grids. +//================================================================================================== +class RimProject_createGridCaseGroup : public caf::PdmObjectCreationMethod +{ + CAF_PDM_HEADER_INIT; + +public: + RimProject_createGridCaseGroup( caf::PdmObjectHandle* self ); + + void setCasePaths( const std::vector& casePaths ); + + std::expected execute() override; + QString classKeywordReturnedType() const override; + +private: + caf::PdmField> m_casePaths; +}; diff --git a/GrpcInterface/Python/rips/project.py b/GrpcInterface/Python/rips/project.py index 47d9493cd3..6a8d1fee36 100644 --- a/GrpcInterface/Python/rips/project.py +++ b/GrpcInterface/Python/rips/project.py @@ -146,23 +146,6 @@ def replace_source_cases(self, grid_list_file, case_group_id=0): ) -@add_method(Project) -def create_grid_case_group(self, case_paths): - """Create a Grid Case Group from a list of cases - - Arguments: - case_paths (list): list of file path strings - Returns: - :class:`rips.generated.resinsight_classes.GridCaseGroup` - """ - command_reply = self._execute_command( - createGridCaseGroup=Commands_pb2.CreateGridCaseGroupRequest( - casePaths=case_paths - ) - ) - return self.grid_case_group(command_reply.createGridCaseGroupResult.groupId) - - @add_method(Project) def summary_cases(self): """Get a list of all summary cases in the Project