mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
#14772 Python: Add Project.load_case as object method and forward loadCase to it
RimProject_loadCase loads a grid case from file and returns the case object. RicfLoadCase forwards to it and wraps the case id in the legacy loadCaseResult. The hand-written Python Project.load_case() wrapper is removed since the generated method has the same signature and returns the most-derived case class.
This commit is contained in:
1 parent
cc1f09b665
commit
739f3744f6
4 files changed
+117
-45
No files matched your search
@@ -19,20 +19,14 @@
|
||||
|
||||
#include "RicfLoadCase.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferencesGrid.h"
|
||||
#include "RicfCommandForwarding.h"
|
||||
|
||||
#include "RicImportGeneralDataFeature.h"
|
||||
|
||||
#include "RifReaderSettings.h"
|
||||
#include "RimCase.h"
|
||||
#include "RimProject.h"
|
||||
#include "RimcProject.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QStringList>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RicfLoadCaseResult, "loadCaseResult" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -60,30 +54,19 @@ RicfLoadCase::RicfLoadCase()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmScriptResponse RicfLoadCase::execute()
|
||||
{
|
||||
QString absolutePath = m_path;
|
||||
QFileInfo projectPathInfo( absolutePath );
|
||||
if ( !projectPathInfo.exists() )
|
||||
{
|
||||
QDir startDir( RiaApplication::instance()->startDir() );
|
||||
absolutePath = startDir.absoluteFilePath( m_path );
|
||||
}
|
||||
const QString commandName = classKeyword();
|
||||
|
||||
RifReaderSettings readerSettings = m_gridOnly ? RiaPreferencesGrid::gridOnlyReaderSettings()
|
||||
: RiaPreferencesGrid::current()->readerSettings();
|
||||
RimProject_loadCase method( RimProject::current() );
|
||||
method.setPath( m_path() );
|
||||
method.setGridOnly( m_gridOnly() );
|
||||
|
||||
bool createPlot = false;
|
||||
bool createView = false;
|
||||
auto fileOpenMetaData =
|
||||
RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{ absolutePath }, createPlot, createView, readerSettings );
|
||||
auto result = method.execute();
|
||||
if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName );
|
||||
|
||||
if ( fileOpenMetaData.createdCaseIds.empty() )
|
||||
{
|
||||
QString error = QString( "loadCase: Unable to load case from %1" ).arg( absolutePath );
|
||||
RiaLogging::error( error.toStdString() );
|
||||
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
||||
}
|
||||
auto* rimCase = dynamic_cast<RimCase*>( result.value() );
|
||||
if ( !rimCase ) return RicfForwarding::errorResponse( "Loaded object is not a case", commandName );
|
||||
|
||||
caf::PdmScriptResponse response;
|
||||
response.setResult( new RicfLoadCaseResult( fileOpenMetaData.createdCaseIds.front() ) );
|
||||
response.setResult( new RicfLoadCaseResult( rimCase->caseId() ) );
|
||||
return response;
|
||||
}
|
||||
@@ -24,17 +24,22 @@
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaPreferencesGrid.h"
|
||||
#include "RiaQStringFormatter.h"
|
||||
#include "RiaRegressionTestRunner.h"
|
||||
#include "RiaResultNames.h"
|
||||
|
||||
#include "ExportCommands/RicSnapshotAllPlotsToFileFeature.h"
|
||||
#include "ExportCommands/RicSnapshotAllViewsToFileFeature.h"
|
||||
#include "RicImportGeneralDataFeature.h"
|
||||
#include "RicImportSummaryCasesFeature.h"
|
||||
#include "ViewLink/RicLinkVisibleViewsFeature.h"
|
||||
#include "ViewLink/RicUnLinkViewFeature.h"
|
||||
|
||||
#include "RifReaderSettings.h"
|
||||
|
||||
#include "Rim3dView.h"
|
||||
#include "RimCase.h"
|
||||
#include "RimCornerPointCase.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimEclipseCellColors.h"
|
||||
@@ -595,3 +600,81 @@ std::expected<caf::PdmObjectHandle*, QString> RimProject_exportSnapshots::execut
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimProject, RimProject_loadCase, "loadCase" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimProject_loadCase::RimProject_loadCase( caf::PdmObjectHandle* self )
|
||||
: caf::PdmObjectCreationMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Load Case", "", "", "Load a grid case from file and add it to the project" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_path, "Path", QString(), "Path", "", "", "Path to the grid file (EGRID, GRID, GRDECL or ROFF)" );
|
||||
CAF_PDM_InitScriptableField( &m_gridOnly, "GridOnly", false, "Grid Only", "", "", "Load the grid geometry only, without results" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimProject_loadCase::setPath( const QString& path )
|
||||
{
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimProject_loadCase::setGridOnly( bool gridOnly )
|
||||
{
|
||||
m_gridOnly = gridOnly;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimProject_loadCase::execute()
|
||||
{
|
||||
auto* project = self<RimProject>();
|
||||
if ( !project ) return std::unexpected( "No project is available." );
|
||||
|
||||
if ( m_path().isEmpty() ) return std::unexpected( "No path specified." );
|
||||
|
||||
QString absolutePath = m_path();
|
||||
QFileInfo pathInfo( absolutePath );
|
||||
if ( !pathInfo.exists() )
|
||||
{
|
||||
QDir startDir( RiaApplication::instance()->startDir() );
|
||||
absolutePath = startDir.absoluteFilePath( m_path() );
|
||||
}
|
||||
|
||||
RifReaderSettings readerSettings = m_gridOnly() ? RiaPreferencesGrid::gridOnlyReaderSettings()
|
||||
: RiaPreferencesGrid::current()->readerSettings();
|
||||
|
||||
const bool createPlot = false;
|
||||
const bool createView = false;
|
||||
auto fileOpenMetaData =
|
||||
RicImportGeneralDataFeature::openEclipseFilesFromFileNames( QStringList{ absolutePath }, createPlot, createView, readerSettings );
|
||||
|
||||
if ( fileOpenMetaData.createdCaseIds.empty() )
|
||||
{
|
||||
return std::unexpected( QString( "Unable to load case from %1" ).arg( absolutePath ) );
|
||||
}
|
||||
|
||||
const int caseId = fileOpenMetaData.createdCaseIds.front();
|
||||
for ( RimCase* rimCase : project->allGridCases() )
|
||||
{
|
||||
if ( rimCase && rimCase->caseId() == caseId ) return rimCase;
|
||||
}
|
||||
|
||||
return std::unexpected( QString( "Case loaded from %1 was not found in the project" ).arg( absolutePath ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimProject_loadCase::classKeywordReturnedType() const
|
||||
{
|
||||
return RimCase::classKeywordStatic();
|
||||
}
|
||||
@@ -206,3 +206,24 @@ private:
|
||||
caf::PdmField<int> m_height;
|
||||
caf::PdmField<caf::AppEnum<RiaDefines::SnapshotFileFormat>> m_plotFileFormat;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// Load a grid case (EGRID, GRID, GRDECL, ROFF) from file and add it to the project.
|
||||
//==================================================================================================
|
||||
class RimProject_loadCase : public caf::PdmObjectCreationMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimProject_loadCase( caf::PdmObjectHandle* self );
|
||||
|
||||
void setPath( const QString& path );
|
||||
void setGridOnly( bool gridOnly );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
QString classKeywordReturnedType() const override;
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_path;
|
||||
caf::PdmField<bool> m_gridOnly;
|
||||
};
|
||||
Reference in new issue
Block a user