Files
ResInsight/ApplicationLibCode/CommandFileInterface/RicfLoadCase.cpp
T

72 lines
2.7 KiB
C++
Raw Normal View History

/////////////////////////////////////////////////////////////////////////////////
//
2019-07-18 10:53:59 +02:00
// Copyright (C) 2017-2019 Statoil ASA
// Copyright (C) 2019- Equinor 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.
2019-07-18 10:53:59 +02: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-07-18 10:53:59 +02:00
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicfLoadCase.h"
#include "RicfCommandForwarding.h"
2024-07-04 12:38:41 +02:00
#include "RimCase.h"
#include "RimProject.h"
#include "RimcProject.h"
2024-07-04 12:38:41 +02:00
2020-08-21 11:13:07 +02:00
#include "cafPdmFieldScriptingCapability.h"
2020-03-10 14:11:22 +01:00
CAF_PDM_SOURCE_INIT( RicfLoadCaseResult, "loadCaseResult" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfLoadCaseResult::RicfLoadCaseResult( int caseId )
{
CAF_PDM_InitObject( "case_result" );
CAF_PDM_InitField( &this->caseId, "id", caseId, "" );
}
CAF_PDM_SOURCE_INIT( RicfLoadCase, "loadCase" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfLoadCase::RicfLoadCase()
{
CAF_PDM_InitScriptableField( &m_path, "path", QString(), "Path to Case File" );
CAF_PDM_InitScriptableField( &m_gridOnly, "gridOnly", false, "Load Grid Data Only" );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2020-03-10 14:11:22 +01:00
caf::PdmScriptResponse RicfLoadCase::execute()
{
const QString commandName = classKeyword();
2019-06-05 14:30:10 +02:00
RimProject_loadCase method( RimProject::current() );
method.setPath( m_path() );
method.setGridOnly( m_gridOnly() );
auto result = method.execute();
if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName );
auto* rimCase = dynamic_cast<RimCase*>( result.value() );
if ( !rimCase ) return RicfForwarding::errorResponse( "Loaded object is not a case", commandName );
2020-03-10 14:11:22 +01:00
caf::PdmScriptResponse response;
response.setResult( new RicfLoadCaseResult( rimCase->caseId() ) );
return response;
}