2017-07-27 03:39:59 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-07-27 03:39:59 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-07-27 03:39:59 -05:00
|
|
|
// 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.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-07-27 03:39:59 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicfSetTimeStep.h"
|
|
|
|
|
2018-01-09 03:11:28 -06:00
|
|
|
#include "Rim3dView.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimEclipseCaseCollection.h"
|
|
|
|
#include "RimOilField.h"
|
|
|
|
#include "RimProject.h"
|
2017-07-27 03:39:59 -05:00
|
|
|
|
2017-07-27 07:26:59 -05:00
|
|
|
#include "RiaLogging.h"
|
2017-07-27 03:39:59 -05:00
|
|
|
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
2020-03-10 08:11:22 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RicfSetTimeStep, "setTimeStep" );
|
2017-07-27 03:39:59 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-07-27 03:39:59 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicfSetTimeStep::RicfSetTimeStep()
|
|
|
|
{
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitScriptableField( &m_caseId, "caseId", -1, "Case ID" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_viewId, "viewId", -1, "View ID" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_timeStepIndex, "timeStep", -1, "Time Step Index" );
|
2017-07-27 03:39:59 -05:00
|
|
|
}
|
|
|
|
|
2019-05-20 06:21:02 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfSetTimeStep::setCaseId( int caseId )
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
m_caseId = caseId;
|
|
|
|
}
|
|
|
|
|
2019-09-23 04:50:33 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RicfSetTimeStep::setViewId( int viewId )
|
|
|
|
{
|
|
|
|
m_viewId = viewId;
|
|
|
|
}
|
|
|
|
|
2019-05-20 06:21:02 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfSetTimeStep::setTimeStepIndex( int timeStepIndex )
|
2019-05-20 06:21:02 -05:00
|
|
|
{
|
|
|
|
m_timeStepIndex = timeStepIndex;
|
|
|
|
}
|
|
|
|
|
2017-07-27 03:39:59 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-07-27 03:39:59 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-03-10 08:11:22 -05:00
|
|
|
caf::PdmScriptResponse RicfSetTimeStep::execute()
|
2017-07-27 03:39:59 -05:00
|
|
|
{
|
2023-09-11 08:12:18 -05:00
|
|
|
RimCase* rimCase = nullptr;
|
2017-07-27 03:39:59 -05:00
|
|
|
|
|
|
|
{
|
2023-09-11 08:12:18 -05:00
|
|
|
std::vector<RimCase*> allCases = RimProject::current()->allGridCases();
|
2020-01-21 01:48:44 -06:00
|
|
|
|
2017-07-27 07:26:59 -05:00
|
|
|
bool foundCase = false;
|
2020-01-21 01:48:44 -06:00
|
|
|
for ( RimCase* c : allCases )
|
2017-07-27 03:39:59 -05:00
|
|
|
{
|
2022-08-18 00:12:23 -05:00
|
|
|
if ( c->caseId() == m_caseId )
|
2017-07-27 07:26:59 -05:00
|
|
|
{
|
2020-01-21 01:48:44 -06:00
|
|
|
rimCase = c;
|
|
|
|
foundCase = true;
|
2017-07-27 07:26:59 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !foundCase )
|
2017-07-27 07:26:59 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString error = QString( "setTimeStep: Could not find case with ID %1" ).arg( m_caseId() );
|
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2017-07-27 03:39:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-21 01:48:44 -06:00
|
|
|
int maxTimeStep = rimCase->timeStepStrings().size() - 1;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( m_timeStepIndex() > maxTimeStep )
|
2019-05-23 06:59:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
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 );
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2019-05-23 06:59:19 -05:00
|
|
|
}
|
|
|
|
|
2020-01-21 01:48:44 -06:00
|
|
|
for ( Rim3dView* view : rimCase->views() )
|
2017-07-27 03:39:59 -05:00
|
|
|
{
|
2019-09-23 04:50:33 -05:00
|
|
|
if ( m_viewId() == -1 || view->id() == m_viewId() )
|
|
|
|
{
|
|
|
|
view->setCurrentTimeStepAndUpdate( m_timeStepIndex );
|
|
|
|
view->createDisplayModelAndRedraw();
|
|
|
|
}
|
2017-07-27 03:39:59 -05:00
|
|
|
}
|
2019-05-23 06:59:19 -05:00
|
|
|
|
2020-03-10 08:11:22 -05:00
|
|
|
return caf::PdmScriptResponse();
|
2017-07-27 03:39:59 -05:00
|
|
|
}
|