mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 22:27:55 -05:00
#14772 Python: Add View.set_time_step as object method and forward setTimeStep to it
Rim3dView_setTimeStep validates the time step against the owner case and updates the view. RicfSetTimeStep forwards to it, looping over all views of the case when viewId is -1. The hand-written Python View.set_time_step() wrapper is removed since the generated method has the same name and signature. Also fix the argument description of the new Rimc methods: the whatsThis text is the third variadic argument of CAF_PDM_InitScriptableField.
This commit is contained in:
1 parent
e87e372c7b
commit
ee28576c48
5 files changed
+97
-53
No files matched your search
@@ -18,13 +18,11 @@
|
||||
|
||||
#include "RicfSetTimeStep.h"
|
||||
|
||||
#include "Rim3dView.h"
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseCaseCollection.h"
|
||||
#include "RimOilField.h"
|
||||
#include "RimProject.h"
|
||||
#include "RicfCommandForwarding.h"
|
||||
|
||||
#include "RiaLogging.h"
|
||||
#include "Rim3dView.h"
|
||||
#include "RimCase.h"
|
||||
#include "RimcGridView.h"
|
||||
|
||||
#include "cafPdmFieldScriptingCapability.h"
|
||||
|
||||
@@ -69,47 +67,31 @@ void RicfSetTimeStep::setTimeStepIndex( int timeStepIndex )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmScriptResponse RicfSetTimeStep::execute()
|
||||
{
|
||||
RimCase* rimCase = nullptr;
|
||||
const QString commandName = classKeyword();
|
||||
|
||||
auto rimCase = RicfForwarding::findCase( m_caseId() );
|
||||
if ( !rimCase ) return RicfForwarding::errorResponse( rimCase.error(), commandName );
|
||||
|
||||
// A view id of -1 applies the time step to all views of the case
|
||||
std::vector<Rim3dView*> views;
|
||||
if ( m_viewId() == -1 )
|
||||
{
|
||||
std::vector<RimCase*> allCases = RimProject::current()->allGridCases();
|
||||
|
||||
bool foundCase = false;
|
||||
for ( RimCase* c : allCases )
|
||||
{
|
||||
if ( c->caseId() == m_caseId )
|
||||
{
|
||||
rimCase = c;
|
||||
foundCase = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !foundCase )
|
||||
{
|
||||
QString error = QString( "setTimeStep: Could not find case with ID %1" ).arg( m_caseId() );
|
||||
RiaLogging::error( error.toStdString() );
|
||||
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
||||
}
|
||||
views = rimCase.value()->views();
|
||||
}
|
||||
else
|
||||
{
|
||||
auto view = RicfForwarding::findView( rimCase.value(), m_viewId() );
|
||||
if ( !view ) return RicfForwarding::errorResponse( view.error(), commandName );
|
||||
views.push_back( view.value() );
|
||||
}
|
||||
|
||||
int maxTimeStep = rimCase->timeStepStrings().size() - 1;
|
||||
if ( m_timeStepIndex() > maxTimeStep )
|
||||
for ( Rim3dView* view : views )
|
||||
{
|
||||
QString error = QString( "setTimeStep: Step %1 is larger than the maximum of %2 for case %3" )
|
||||
.arg( m_timeStepIndex() )
|
||||
.arg( maxTimeStep )
|
||||
.arg( m_caseId() );
|
||||
RiaLogging::error( error.toStdString() );
|
||||
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
||||
}
|
||||
Rim3dView_setTimeStep method( view );
|
||||
method.setTimeStep( m_timeStepIndex() );
|
||||
|
||||
for ( Rim3dView* view : rimCase->views() )
|
||||
{
|
||||
if ( m_viewId() == -1 || view->id() == m_viewId() )
|
||||
{
|
||||
view->setCurrentTimeStepAndUpdate( m_timeStepIndex );
|
||||
view->createDisplayModelAndRedraw();
|
||||
}
|
||||
auto result = method.execute();
|
||||
if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName );
|
||||
}
|
||||
|
||||
return caf::PdmScriptResponse();
|
||||
|
||||
@@ -46,12 +46,19 @@ RimCase_replaceGrid::RimCase_replaceGrid( caf::PdmObjectHandle* self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Replace Grid", "", "", "Replace the grid file of the case and reload the project" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_newGridFile, "NewGridFile", QString(), "New Grid File", "", "Path to the new grid file (EGRID, GRID, GRDECL or ODB)" );
|
||||
CAF_PDM_InitScriptableField( &m_newGridFile,
|
||||
"NewGridFile",
|
||||
QString(),
|
||||
"New Grid File",
|
||||
"",
|
||||
"",
|
||||
"Path to the new grid file (EGRID, GRID, GRDECL or ODB)" );
|
||||
CAF_PDM_InitScriptableField( &m_projectFile,
|
||||
"ProjectFile",
|
||||
QString(),
|
||||
"Project File",
|
||||
"",
|
||||
"",
|
||||
"Optional project file to reload. Defaults to the current project file." );
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "Polygons/RimPolygon.h"
|
||||
#include "Polygons/RimPolygonInViewCollection.h"
|
||||
#include "Rim3dView.h"
|
||||
#include "RimCase.h"
|
||||
#include "RimEclipseCase.h"
|
||||
#include "RimEclipseView.h"
|
||||
#include "RimGeoMechCase.h"
|
||||
@@ -264,3 +265,50 @@ QString Rim3dView_clone::classKeywordReturnedType() const
|
||||
{
|
||||
return Rim3dView::classKeywordStatic();
|
||||
}
|
||||
|
||||
CAF_PDM_OBJECT_METHOD_SOURCE_INIT( Rim3dView, Rim3dView_setTimeStep, "setTimeStep" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
Rim3dView_setTimeStep::Rim3dView_setTimeStep( caf::PdmObjectHandle* self )
|
||||
: caf::PdmVoidObjectMethod( self )
|
||||
{
|
||||
CAF_PDM_InitObject( "Set Time Step", "", "", "Set the current time step of the view" );
|
||||
|
||||
CAF_PDM_InitScriptableField( &m_timeStep, "TimeStep", 0, "Time Step", "", "", "Zero-based time step index" );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void Rim3dView_setTimeStep::setTimeStep( int timeStep )
|
||||
{
|
||||
m_timeStep = timeStep;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::expected<caf::PdmObjectHandle*, QString> Rim3dView_setTimeStep::execute()
|
||||
{
|
||||
auto* view = self<Rim3dView>();
|
||||
if ( !view ) return std::unexpected( "No view is available." );
|
||||
|
||||
RimCase* rimCase = view->ownerCase();
|
||||
if ( !rimCase ) return std::unexpected( "The view has no case." );
|
||||
|
||||
const int maxTimeStep = static_cast<int>( rimCase->timeStepStrings().size() ) - 1;
|
||||
if ( m_timeStep() < 0 || m_timeStep() > maxTimeStep )
|
||||
{
|
||||
return std::unexpected( QString( "Time step %1 is out of range [0, %2] for case '%3'" )
|
||||
.arg( m_timeStep() )
|
||||
.arg( maxTimeStep )
|
||||
.arg( rimCase->caseUserDescription() ) );
|
||||
}
|
||||
|
||||
view->setCurrentTimeStepAndUpdate( m_timeStep() );
|
||||
view->createDisplayModelAndRedraw();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -109,3 +109,21 @@ public:
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
QString classKeywordReturnedType() const override;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// Set the current time step of the view and redraw.
|
||||
//==================================================================================================
|
||||
class Rim3dView_setTimeStep : public caf::PdmVoidObjectMethod
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
Rim3dView_setTimeStep( caf::PdmObjectHandle* self );
|
||||
|
||||
void setTimeStep( int timeStep );
|
||||
|
||||
std::expected<caf::PdmObjectHandle*, QString> execute() override;
|
||||
|
||||
private:
|
||||
caf::PdmField<int> m_timeStep;
|
||||
};
|
||||
@@ -82,17 +82,6 @@ def apply_flow_diagnostics_cell_result(
|
||||
cell_result.update()
|
||||
|
||||
|
||||
@add_method(View)
|
||||
def set_time_step(self, time_step):
|
||||
"""Set the time step for current view"""
|
||||
case_id = self.case().id
|
||||
return self._execute_command(
|
||||
setTimeStep=Cmd.SetTimeStepParams(
|
||||
caseId=case_id, viewId=self.id, timeStep=time_step
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@add_method(View)
|
||||
def export_sim_well_fracture_completions(
|
||||
self, time_step, simulation_well_names, file_split, compdat_export
|
||||
|
||||
Reference in new issue
Block a user