2012-05-18 02:45:23 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2011-2012 Statoil ASA, Ceetron AS
|
2018-11-05 07:28:07 -06:00
|
|
|
//
|
2012-05-18 02:45:23 -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.
|
2018-11-05 07:28:07 -06:00
|
|
|
//
|
2012-05-18 02:45:23 -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.
|
2018-11-05 07:28:07 -06:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2012-05-18 02:45:23 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RimCalcScript.h"
|
2018-11-05 07:28:07 -06:00
|
|
|
|
2019-04-04 14:37:22 -05:00
|
|
|
#include "RiaApplication.h"
|
2018-11-05 07:28:07 -06:00
|
|
|
#include "RiaFieldHandleTools.h"
|
2019-04-05 12:12:19 -05:00
|
|
|
#include "RiaLogging.h"
|
2018-11-05 07:28:07 -06:00
|
|
|
|
|
|
|
#include "cafPdmField.h"
|
2012-06-26 09:10:41 -05:00
|
|
|
#include "cafPdmUiFilePathEditor.h"
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2019-04-04 14:37:22 -05:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_SOURCE_INIT( RimCalcScript, "CalcScript" );
|
2012-05-18 02:45:23 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-05 07:28:07 -06:00
|
|
|
///
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimCalcScript::RimCalcScript()
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_PDM_InitObject( "CalcScript", ":/OctaveScriptFile16x16.png", "Calc Script", "" );
|
2012-05-18 02:45:23 -05:00
|
|
|
|
2021-11-14 07:15:12 -06:00
|
|
|
CAF_PDM_InitField( &absoluteFileName, "AbsolutePath", QString(), "Location" );
|
2019-09-06 03:40:57 -05:00
|
|
|
|
|
|
|
absoluteFileName.uiCapability()->setUiEditorTypeName( caf::PdmUiFilePathEditor::uiEditorTypeName() );
|
2012-05-18 02:45:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-11-05 07:28:07 -06:00
|
|
|
///
|
2012-05-18 02:45:23 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 04:13:38 -06:00
|
|
|
RimCalcScript::~RimCalcScript()
|
|
|
|
{
|
|
|
|
}
|
2019-04-04 14:37:22 -05:00
|
|
|
|
2019-07-26 07:54:54 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
RimCalcScript::ScriptType RimCalcScript::scriptType( const QString& absoluteFileNameScript )
|
2019-07-26 07:54:54 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QFileInfo fileInfo( absoluteFileNameScript );
|
|
|
|
if ( fileInfo.suffix() == "py" )
|
2019-07-26 07:54:54 -05:00
|
|
|
{
|
|
|
|
return PYTHON;
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( fileInfo.suffix() == "m" )
|
2019-07-26 07:54:54 -05:00
|
|
|
{
|
|
|
|
return OCTAVE;
|
|
|
|
}
|
|
|
|
return UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RimCalcScript::ScriptType RimCalcScript::scriptType() const
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
return scriptType( absoluteFileName() );
|
2019-07-26 07:54:54 -05:00
|
|
|
}
|
|
|
|
|
2019-04-04 14:37:22 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
QStringList RimCalcScript::createCommandLineArguments( const QString& absoluteFileNameScript )
|
2019-04-04 14:37:22 -05:00
|
|
|
{
|
2019-04-05 12:09:41 -05:00
|
|
|
QStringList arguments;
|
2019-04-04 14:37:22 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( scriptType( absoluteFileNameScript ) == PYTHON )
|
2019-04-05 12:09:41 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
arguments.append( absoluteFileNameScript );
|
2019-04-05 12:09:41 -05:00
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( scriptType( absoluteFileNameScript ) == OCTAVE )
|
2019-04-05 12:09:41 -05:00
|
|
|
{
|
2019-07-26 07:54:54 -05:00
|
|
|
{
|
|
|
|
auto app = RiaApplication::instance();
|
2019-04-05 12:09:41 -05:00
|
|
|
|
2019-07-26 07:54:54 -05:00
|
|
|
arguments = app->octaveArguments();
|
2019-09-06 03:40:57 -05:00
|
|
|
arguments.append( "--path" );
|
2019-07-26 07:54:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QFileInfo fi( absoluteFileNameScript );
|
2019-07-26 07:54:54 -05:00
|
|
|
QString octaveFunctionSearchPath = fi.absolutePath();
|
2019-09-06 03:40:57 -05:00
|
|
|
QString absFilePath = fi.absoluteFilePath();
|
2019-07-26 07:54:54 -05:00
|
|
|
|
|
|
|
arguments << octaveFunctionSearchPath;
|
|
|
|
arguments << absFilePath;
|
|
|
|
}
|
2019-04-05 12:09:41 -05:00
|
|
|
}
|
2019-04-04 14:37:22 -05:00
|
|
|
|
2019-04-08 00:57:49 -05:00
|
|
|
bool debugPrintArgumentText = false;
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( debugPrintArgumentText )
|
2019-04-05 12:12:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString argumentString = arguments.join( " " );
|
2019-04-05 12:12:19 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
RiaLogging::info( "Scriptarguments : " + argumentString );
|
2019-04-05 12:12:19 -05:00
|
|
|
}
|
|
|
|
|
2019-04-04 14:37:22 -05:00
|
|
|
return arguments;
|
|
|
|
}
|
2019-07-26 07:54:54 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RimCalcScript::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= ""*/ )
|
2019-07-26 07:54:54 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( scriptType() == PYTHON )
|
2019-07-26 07:54:54 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
uiCapability()->setUiIconFromResourceString( ":/PythonScriptFile16x16.png" );
|
2019-07-26 07:54:54 -05:00
|
|
|
}
|
|
|
|
}
|