Files
ResInsight/ApplicationLibCode/CommandFileInterface/RicfCreateGridCaseGroup.cpp
T

82 lines
3.1 KiB
C++
Raw Normal View History

2019-07-18 10:53:59 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- 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 "RicfCreateGridCaseGroup.h"
#include "RiaApplication.h"
#include "RiaImportEclipseCaseTools.h"
#include "RimIdenticalGridCaseGroup.h"
2020-08-21 11:13:07 +02:00
#include "cafPdmFieldScriptingCapability.h"
2020-03-10 14:11:22 +01:00
2019-07-18 10:53:59 +02:00
#include <QDir>
#include <QFileInfo>
2019-07-18 10:53:59 +02:00
#include <QStringList>
CAF_PDM_SOURCE_INIT( RicfCreateGridCaseGroupResult, "createGridCaseGroupResult" );
2019-07-18 10:53:59 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2023-02-26 10:48:40 +01:00
RicfCreateGridCaseGroupResult::RicfCreateGridCaseGroupResult( int caseGroupId /*= -1*/, const QString& caseGroupName /*= ""*/ )
2019-07-18 10:53:59 +02:00
{
CAF_PDM_InitObject( "case_group_result" );
CAF_PDM_InitField( &this->caseGroupId, "groupId", caseGroupId, "" );
CAF_PDM_InitField( &this->caseGroupName, "groupName", caseGroupName, "" );
2019-07-18 10:53:59 +02:00
}
CAF_PDM_SOURCE_INIT( RicfCreateGridCaseGroup, "createGridCaseGroup" );
2019-07-18 10:53:59 +02:00
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicfCreateGridCaseGroup::RicfCreateGridCaseGroup()
{
CAF_PDM_InitScriptableFieldNoDefault( &m_casePaths, "casePaths", "List of Paths to Case Files" );
2019-07-18 10:53:59 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
2020-03-10 14:11:22 +01:00
caf::PdmScriptResponse RicfCreateGridCaseGroup::execute()
2019-07-18 10:53:59 +02:00
{
QStringList casePaths;
for ( QString casePath : m_casePaths() )
2019-07-18 10:53:59 +02:00
{
QFileInfo casePathInfo( casePath );
if ( !casePathInfo.exists() )
2019-07-18 10:53:59 +02:00
{
QDir startDir( RiaApplication::instance()->startDir() );
casePath = startDir.absoluteFilePath( casePath );
2019-07-18 10:53:59 +02:00
}
casePaths.push_back( casePath );
2019-07-18 10:53:59 +02:00
}
2019-07-18 10:53:59 +02:00
RimIdenticalGridCaseGroup* caseGroup = nullptr;
if ( RiaImportEclipseCaseTools::addEclipseCases( casePaths, &caseGroup ) && caseGroup )
2019-07-18 10:53:59 +02:00
{
2020-03-10 14:11:22 +01:00
caf::PdmScriptResponse response;
response.setResult( new RicfCreateGridCaseGroupResult( caseGroup->groupId(), caseGroup->name() ) );
2019-07-18 10:53:59 +02:00
return response;
}
2020-03-10 14:11:22 +01:00
return caf::PdmScriptResponse( caf::PdmScriptResponse::COMMAND_ERROR, "Could not load grid case group" );
2019-07-18 10:53:59 +02:00
}