2017-07-27 03:49:28 -05:00
|
|
|
#include "RicfRunOctaveScript.h"
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-07-27 03:49:28 -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:49:28 -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:49:28 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicfRunOctaveScript.h"
|
|
|
|
|
|
|
|
#include "RiaApplication.h"
|
2017-07-27 07:26:59 -05:00
|
|
|
#include "RiaLogging.h"
|
2017-07-27 03:49:28 -05:00
|
|
|
|
2019-04-04 14:37:22 -05:00
|
|
|
#include "RimCalcScript.h"
|
2019-04-05 02:34:02 -05:00
|
|
|
#include "RimEclipseCase.h"
|
|
|
|
#include "RimProject.h"
|
2019-04-04 14:37:22 -05:00
|
|
|
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
2020-03-10 08:11:22 -05:00
|
|
|
|
2017-07-27 03:49:28 -05:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RicfRunOctaveScript, "runOctaveScript" );
|
2017-07-27 03:49:28 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-07-27 03:49:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicfRunOctaveScript::RicfRunOctaveScript()
|
|
|
|
{
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitScriptableField( &m_path, "path", QString(), "Path" );
|
|
|
|
CAF_PDM_InitScriptableField( &m_caseIds, "caseIds", std::vector<int>(), "Case IDs" );
|
2017-07-27 03:49:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-07-27 03:49:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-03-10 08:11:22 -05:00
|
|
|
caf::PdmScriptResponse RicfRunOctaveScript::execute()
|
2017-07-27 03:49:28 -05:00
|
|
|
{
|
|
|
|
QString octavePath = RiaApplication::instance()->octavePath();
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QStringList processArguments = RimCalcScript::createCommandLineArguments( m_path() );
|
2017-07-27 03:49:28 -05:00
|
|
|
|
2019-04-05 02:34:02 -05:00
|
|
|
std::vector<int> caseIds = m_caseIds();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( caseIds.empty() )
|
2019-04-05 02:34:02 -05:00
|
|
|
{
|
2020-05-12 02:50:38 -05:00
|
|
|
RimProject* project = RimProject::current();
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( project )
|
2019-04-05 02:34:02 -05:00
|
|
|
{
|
|
|
|
auto eclipeCases = project->eclipseCases();
|
2019-09-06 03:40:57 -05:00
|
|
|
for ( auto c : eclipeCases )
|
2019-04-05 02:34:02 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
caseIds.push_back( c->caseId() );
|
2019-04-05 02:34:02 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 07:26:59 -05:00
|
|
|
bool ok;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( caseIds.empty() )
|
2017-07-27 03:49:28 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
ok = RiaApplication::instance()->launchProcess( octavePath,
|
|
|
|
processArguments,
|
|
|
|
RiaApplication::instance()->octaveProcessEnvironment() );
|
2017-07-27 03:49:28 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-12 04:43:15 -06:00
|
|
|
ok = RiaApplication::instance()->launchProcessForMultipleCases( octavePath,
|
|
|
|
processArguments,
|
|
|
|
caseIds,
|
|
|
|
RiaApplication::instance()->octaveProcessEnvironment() );
|
2017-07-27 07:26:59 -05:00
|
|
|
}
|
2019-05-23 06:59:19 -05:00
|
|
|
|
2020-03-10 08:11:22 -05:00
|
|
|
caf::PdmScriptResponse response;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !ok )
|
2017-07-27 07:26:59 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString error = QString( "runOctaveScript: Could not execute script %1" ).arg( m_path() );
|
|
|
|
RiaLogging::error( error );
|
2020-03-10 08:11:22 -05:00
|
|
|
response.updateStatus( caf::PdmScriptResponse::COMMAND_ERROR, error );
|
2017-07-27 03:49:28 -05:00
|
|
|
}
|
2017-07-31 04:10:22 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
RiaApplication::instance()->waitForProcess();
|
|
|
|
}
|
2019-05-23 06:59:19 -05:00
|
|
|
return response;
|
2017-07-27 03:49:28 -05:00
|
|
|
}
|