mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
#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.
This commit is contained in:
1 parent
739f3744f6
commit
6548c4f4db
4 files changed
+96
-42
No files matched your search
@@ -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 <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QStringList>
|
||||
|
||||
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<RimIdenticalGridCaseGroup*>( 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;
|
||||
}
|
||||
@@ -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<QString>(), "Case Paths", "", "", "Paths to the grid files" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimProject_createGridCaseGroup::setCasePaths( const std::vector<QString>& casePaths )
|
||||
{
|
||||
m_casePaths = casePaths;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimProject_createGridCaseGroup::execute()
|
||||
{
|
||||
auto* project = self<RimProject>();
|
||||
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();
|
||||
}
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <memory>
|
||||
|
||||
class Rim3dView;
|
||||
class RimIdenticalGridCaseGroup;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -227,3 +228,22 @@ private:
|
||||
caf::PdmField<QString> m_path;
|
||||
caf::PdmField<bool> 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<QString>& casePaths );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
QString classKeywordReturnedType() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<std::vector<QString>> m_casePaths;
|
||||
};
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user