2019-04-09 12:43:15 +02:00
|
|
|
#include "RicfCreateSaturationPressurePlots.h"
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// 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 "RicfCreateSaturationPressurePlots.h"
|
|
|
|
|
|
|
|
|
|
#include "RiaLogging.h"
|
|
|
|
|
|
2026-09-16 17:24:23 +02:00
|
|
|
#include "RicfCommandForwarding.h"
|
|
|
|
|
|
2019-04-09 12:43:15 +02:00
|
|
|
#include "RimEclipseResultCase.h"
|
|
|
|
|
#include "RimProject.h"
|
2026-09-16 17:24:23 +02:00
|
|
|
#include "RimcEclipseCase.h"
|
2019-04-09 12:43:15 +02:00
|
|
|
|
2020-08-21 11:13:07 +02:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
2020-03-10 14:11:22 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
CAF_PDM_SOURCE_INIT( RicfCreateSaturationPressurePlots, "createSaturationPressurePlots" );
|
2019-04-09 12:43:15 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RicfCreateSaturationPressurePlots::RicfCreateSaturationPressurePlots()
|
|
|
|
|
{
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitScriptableField( &m_caseIds, "caseIds", std::vector<int>(), "Case IDs" );
|
2019-04-09 12:43:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-03-10 14:11:22 +01:00
|
|
|
caf::PdmScriptResponse RicfCreateSaturationPressurePlots::execute()
|
2019-04-09 12:43:15 +02:00
|
|
|
{
|
2026-09-16 17:24:23 +02:00
|
|
|
const QString commandName = classKeyword();
|
|
|
|
|
|
|
|
|
|
RimProject* project = RimProject::current();
|
|
|
|
|
if ( !project ) return RicfForwarding::errorResponse( "No project loaded", commandName );
|
|
|
|
|
|
|
|
|
|
// Collect the result cases. No ids means all Eclipse result cases in the project.
|
|
|
|
|
std::vector<RimEclipseResultCase*> resultCases;
|
|
|
|
|
if ( m_caseIds().empty() )
|
2019-04-09 12:43:15 +02:00
|
|
|
{
|
2026-09-16 17:24:23 +02:00
|
|
|
for ( RimEclipseCase* c : project->eclipseCases() )
|
2019-04-09 12:43:15 +02:00
|
|
|
{
|
2026-09-16 17:24:23 +02:00
|
|
|
if ( auto* resultCase = dynamic_cast<RimEclipseResultCase*>( c ) ) resultCases.push_back( resultCase );
|
2019-04-09 12:43:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
2026-09-16 17:24:23 +02:00
|
|
|
else
|
2019-05-23 13:59:19 +02:00
|
|
|
{
|
2026-09-16 17:24:23 +02:00
|
|
|
for ( int caseId : m_caseIds() )
|
|
|
|
|
{
|
|
|
|
|
auto rimCase = RicfForwarding::findCase( caseId );
|
|
|
|
|
if ( !rimCase ) return RicfForwarding::errorResponse( rimCase.error(), commandName );
|
2019-05-23 13:59:19 +02:00
|
|
|
|
2026-09-16 17:24:23 +02:00
|
|
|
if ( auto* resultCase = dynamic_cast<RimEclipseResultCase*>( rimCase.value() ) ) resultCases.push_back( resultCase );
|
|
|
|
|
}
|
2019-05-23 13:59:19 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-16 17:24:23 +02:00
|
|
|
if ( resultCases.empty() ) return RicfForwarding::errorResponse( "No cases found", commandName );
|
|
|
|
|
|
|
|
|
|
caf::PdmScriptResponse response;
|
|
|
|
|
for ( RimEclipseResultCase* resultCase : resultCases )
|
2019-05-23 13:59:19 +02:00
|
|
|
{
|
2026-09-16 17:24:23 +02:00
|
|
|
RimEclipseResultCase_createSaturationPressurePlots method( resultCase );
|
|
|
|
|
method.setTimeStep( 0 );
|
2019-04-09 12:43:15 +02:00
|
|
|
|
2026-09-16 17:24:23 +02:00
|
|
|
auto result = method.execute();
|
|
|
|
|
if ( !result )
|
2019-05-23 13:59:19 +02:00
|
|
|
{
|
2026-09-16 17:24:23 +02:00
|
|
|
// Legacy behavior: a case without the required data is skipped, not an error
|
|
|
|
|
QString warning = QString( "%1: %2" ).arg( commandName ).arg( result.error() );
|
|
|
|
|
RiaLogging::warning( warning.toStdString() );
|
|
|
|
|
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, warning );
|
2019-04-09 12:43:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-16 17:24:23 +02:00
|
|
|
return response;
|
2019-04-09 12:43:15 +02:00
|
|
|
}
|