#14772 Python: Add Reservoir.export_property as object method and forward exportProperty to it

RimEclipseCase_exportProperty writes a cell property to a GRDECL style
text file and requires an explicit export file. RicfExportProperty
resolves the default file name from the command file executor's
PROPERTIES export folder and forwards to it.

The hand-written Case.export_property() wrapper is removed. The
generated Reservoir.export_property() has the same argument names and
shadows the base class wrapper anyway, so a deprecation shim would
never be reached.
This commit is contained in:
Kristian Bendiksen committed 2026-09-22 14:19:23 +02:00
1 parent 77c32a3fa5
commit d2078613a8
5 files changed
+185 -95

No files matched your search

@@ -22,6 +22,8 @@
#include "RiaGuiApplication.h"
#include "RiaKeyValueStoreUtil.h"
#include "ExportCommands/RicEclipseCellResultToFileImpl.h"
#include "RifInputPropertyLoader.h"
#include "RigActiveCellInfo.h"
@@ -450,3 +452,110 @@ std::expected<RiaDefines::ResultDataType, QString> RimcEclipseCase_propertyDataT
return std::unexpected( QString( "Property not found: %1" ).arg( m_propertyName() ) );
}
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseCase, RimEclipseCase_exportProperty, "exportProperty" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseCase_exportProperty::RimEclipseCase_exportProperty( caf::PdmObjectHandle* self )
: caf::PdmVoidObjectMethod( self )
{
CAF_PDM_InitObject( "Export Property", "", "", "Export a cell property of the case to a GRDECL style text file" );
CAF_PDM_InitScriptableField( &m_timeStep, "TimeStep", -1, "Time Step", "", "", "Zero-based time step index. Ignored for static properties." );
CAF_PDM_InitScriptableField( &m_propertyName, "PropertyName", QString(), "Property Name", "", "", "Name of the property to export" );
CAF_PDM_InitScriptableField( &m_eclipseKeyword,
"EclipseKeyword",
QString(),
"Eclipse Keyword",
"",
"",
"Keyword written to the file header. Defaults to the property name." );
CAF_PDM_InitScriptableField( &m_undefinedValue, "UndefinedValue", 0.0, "Undefined Value", "", "", "Value written for undefined cells" );
CAF_PDM_InitScriptableField( &m_exportFile, "ExportFile", QString(), "Export File", "", "", "Full path of the file to write" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCase_exportProperty::setTimeStep( int timeStep )
{
m_timeStep = timeStep;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCase_exportProperty::setPropertyName( const QString& propertyName )
{
m_propertyName = propertyName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCase_exportProperty::setEclipseKeyword( const QString& eclipseKeyword )
{
m_eclipseKeyword = eclipseKeyword;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCase_exportProperty::setUndefinedValue( double undefinedValue )
{
m_undefinedValue = undefinedValue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEclipseCase_exportProperty::setExportFile( const QString& exportFile )
{
m_exportFile = exportFile;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::expected<caf::PdmObjectHandle*, QString> RimEclipseCase_exportProperty::execute()
{
auto* eclipseCase = self<RimEclipseCase>();
if ( !eclipseCase ) return std::unexpected( "No case is available." );
if ( m_propertyName().isEmpty() ) return std::unexpected( "No property name specified." );
if ( m_exportFile().isEmpty() ) return std::unexpected( "No export file specified." );
if ( !eclipseCase->eclipseCaseData() && !eclipseCase->openReservoirCase() )
{
return std::unexpected( QString( "Could not open case '%1'" ).arg( eclipseCase->caseUserDescription() ) );
}
RigEclipseCaseData* eclipseCaseData = eclipseCase->eclipseCaseData();
RigCaseCellResultsData* cellResultsData = eclipseCaseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL );
if ( !cellResultsData->ensureKnownResultLoaded( RigEclipseResultAddress( m_propertyName() ) ) )
{
return std::unexpected( QString( "Could not find result property '%1'" ).arg( m_propertyName() ) );
}
QString eclipseKeyword = m_eclipseKeyword();
if ( eclipseKeyword.isEmpty() ) eclipseKeyword = m_propertyName();
const bool writeEchoKeywords = false;
QString errorMessage;
if ( !RicEclipseCellResultToFileImpl::writePropertyToTextFile( m_exportFile(),
eclipseCaseData,
m_timeStep(),
m_propertyName(),
eclipseKeyword,
m_undefinedValue(),
writeEchoKeywords,
&errorMessage ) )
{
return std::unexpected( errorMessage );
}
return nullptr;
}
@@ -161,3 +161,29 @@ private:
caf::PdmField<int> m_timeStep;
caf::PdmField<int> m_gridIndex;
};
//==================================================================================================
/// Export a cell property (static or dynamic, matrix model) of the case to a GRDECL style text file.
//==================================================================================================
class RimEclipseCase_exportProperty : public caf::PdmVoidObjectMethod
{
CAF_PDM_HEADER_INIT;
public:
RimEclipseCase_exportProperty( caf::PdmObjectHandle* self );
void setTimeStep( int timeStep );
void setPropertyName( const QString& propertyName );
void setEclipseKeyword( const QString& eclipseKeyword );
void setUndefinedValue( double undefinedValue );
void setExportFile( const QString& exportFile );
std::expected<caf::PdmObjectHandle*, QString> execute() override;
private:
caf::PdmField<int> m_timeStep;
caf::PdmField<QString> m_propertyName;
caf::PdmField<QString> m_eclipseKeyword;
caf::PdmField<double> m_undefinedValue;
caf::PdmField<QString> m_exportFile;
};