mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-26 07:00:17 -05:00
#14772 Python: Add EclipseView.export_current_property and forward exportPropertyInViews to it
RimEclipseView_exportCurrentProperty exports the cell result shown in the view at its current time step to a GRDECL style text file, and requires an explicit export file. RicfExportPropertyInViews selects the views by id/name, resolves the default file names from the command file executor's PROPERTIES export folder, and forwards to it for each view. The method is named exportCurrentProperty rather than exportProperty to avoid shadowing the legacy View.export_property() wrapper (different signature) in the generated Python class hierarchy. The legacy wrapper is kept and emits a DeprecationWarning.
This commit is contained in:
1 parent
d2078613a8
commit
1f06f02b39
5 files changed
+188
-88
No files matched your search
@@ -18,6 +18,13 @@
|
||||
|
||||
#include "RimcEclipseView.h"
|
||||
|
||||
#include "ExportCommands/RicEclipseCellResultToFileImpl.h"
|
||||
|
||||
#include "RigResultAccessor.h"
|
||||
#include "RigResultAccessorFactory.h"
|
||||
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseCellColors.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimFaultDistance.h"
|
||||
#include "RimFaultDistanceCollection.h"
|
||||
@@ -26,6 +33,7 @@
|
||||
|
||||
#include "cafPdmAbstractFieldScriptingCapability.h"
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
#include "cafUtils.h"
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseView, RimcEclipseView_addFaultDistance, "add_fault_distance" );
|
||||
|
||||
@@ -82,3 +90,94 @@ QString RimcEclipseView_addFaultDistance::classKeywordReturnedType() const
|
||||
{
|
||||
return RimFaultDistance::classKeywordStatic();
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( RimEclipseView, RimEclipseView_exportCurrentProperty, "exportCurrentProperty" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimEclipseView_exportCurrentProperty::RimEclipseView_exportCurrentProperty( caf::PdmObjectHandle* self )
|
||||
: caf::PdmVoidObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Export Current Property", "", "", "Export the cell result currently shown in the view to a GRDECL style text file" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_exportFile, "ExportFile", QString(), "Export File", "", "", "Full path of the file to write" );
|
||||
CAF_PDM_InitScriptableField( &m_undefinedValue, "UndefinedValue", 0.0, "Undefined Value", "", "", "Value written for undefined cells" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEclipseView_exportCurrentProperty::setExportFile( const QString& exportFile )
|
||||
{
|
||||
m_exportFile = exportFile;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimEclipseView_exportCurrentProperty::setUndefinedValue( double undefinedValue )
|
||||
{
|
||||
m_undefinedValue = undefinedValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> RimEclipseView_exportCurrentProperty::execute()
|
||||
{
|
||||
auto* view = self<RimEclipseView>();
|
||||
if ( !view ) return std::unexpected( "No view is available." );
|
||||
|
||||
if ( m_exportFile().isEmpty() ) return std::unexpected( "No export file specified." );
|
||||
|
||||
RimEclipseCase* eclipseCase = view->eclipseCase();
|
||||
if ( !eclipseCase || !eclipseCase->eclipseCaseData() ) return std::unexpected( "The view has no case data." );
|
||||
|
||||
const int mainGridIndex = 0;
|
||||
|
||||
cvf::ref<RigResultAccessor> resultAccessor = RigResultAccessorFactory::createFromResultDefinition( eclipseCase->eclipseCaseData(),
|
||||
mainGridIndex,
|
||||
view->currentTimeStep(),
|
||||
view->cellResult() );
|
||||
|
||||
const QString propertyName = view->cellResult()->resultVariableUiShortName();
|
||||
|
||||
if ( resultAccessor.isNull() )
|
||||
{
|
||||
return std::unexpected( QString( "Could not find property '%1' at time step %2 in view '%3'" )
|
||||
.arg( propertyName )
|
||||
.arg( view->currentTimeStep() )
|
||||
.arg( view->name() ) );
|
||||
}
|
||||
|
||||
const bool writeEchoKeywords = false;
|
||||
QString errorMessage;
|
||||
if ( !RicEclipseCellResultToFileImpl::writeResultToTextFile( m_exportFile(),
|
||||
eclipseCase->eclipseCaseData(),
|
||||
resultAccessor.p(),
|
||||
propertyName,
|
||||
m_undefinedValue(),
|
||||
"exportProperty",
|
||||
writeEchoKeywords,
|
||||
&errorMessage ) )
|
||||
{
|
||||
return std::unexpected( errorMessage );
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimEclipseView_exportCurrentProperty::defaultFileBaseName( const RimEclipseView* view )
|
||||
{
|
||||
if ( !view || !view->eclipseCase() ) return {};
|
||||
|
||||
const QString propertyName = view->cellResult()->resultVariableUiShortName();
|
||||
const QString fileName =
|
||||
QString( "%1-%2-T%3-%4" ).arg( view->eclipseCase()->caseUserDescription() ).arg( view->name() ).arg( view->currentTimeStep() ).arg( propertyName );
|
||||
|
||||
return caf::Utils::makeValidFileBasename( fileName );
|
||||
}
|
||||
Reference in new issue
Block a user