Files
ResInsight/ApplicationLibCode/CommandFileInterface/RicfExportProperty.cpp
T
Kristian Bendiksen d2078613a8 #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.
2026-09-22 14:19:23 +02:00

82 lines
3.5 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfExportProperty.h"
#include "RicfCommandFileExecutor.h"
#include "RicfCommandForwarding.h"
#include "RimEclipseCase.h"
#include "RimcEclipseCase.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafUtils.h"
#include <QDir>
CAF_PDM_SOURCE_INIT( RicfExportProperty, "exportProperty" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfExportProperty::RicfExportProperty()
{
CAF_PDM_InitScriptableField( &m_caseId, "caseId", -1, "Case ID" );
CAF_PDM_InitScriptableField( &m_timeStepIndex, "timeStep", -1, "Time Step Index" );
CAF_PDM_InitScriptableField( &m_propertyName, "property", QString(), "Property Name" );
CAF_PDM_InitScriptableField( &m_eclipseKeyword, "eclipseKeyword", QString(), "Eclipse Keyword" );
CAF_PDM_InitScriptableField( &m_undefinedValue, "undefinedValue", 0.0, "Undefined Value" );
CAF_PDM_InitScriptableField( &m_exportFileName, "exportFile", QString(), "Export FileName" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
caf::PdmScriptResponse RicfExportProperty::execute()
{
const QString commandName = classKeyword();
auto rimCase = RicfForwarding::findCase( m_caseId() );
if ( !rimCase ) return RicfForwarding::errorResponse( rimCase.error(), commandName );
auto* eclipseCase = dynamic_cast<RimEclipseCase*>( rimCase.value() );
if ( !eclipseCase )
{
return RicfForwarding::errorResponse( QString( "Case with ID %1 is not an Eclipse case" ).arg( m_caseId() ), commandName );
}
// Resolve the default export file from the command file executor state. The Rimc method requires an explicit file.
QString filePath = m_exportFileName();
if ( filePath.isNull() )
{
QDir propertiesDir( RicfCommandFileExecutor::instance()->getExportPath( RicfCommandFileExecutor::ExportType::PROPERTIES ) );
QString fileName = QString( "%1-%2" ).arg( eclipseCase->caseUserDescription() ).arg( m_propertyName() );
fileName = caf::Utils::makeValidFileBasename( fileName );
filePath = propertiesDir.filePath( fileName );
}
RimEclipseCase_exportProperty method( eclipseCase );
method.setTimeStep( m_timeStepIndex() );
method.setPropertyName( m_propertyName() );
method.setEclipseKeyword( m_eclipseKeyword() );
method.setUndefinedValue( m_undefinedValue() );
method.setExportFile( filePath );
return RicfForwarding::toScriptResponse( method.execute(), commandName );
}