2019-10-09 09:21:28 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
// 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 "RicfImportFormationNames.h"
|
|
|
|
|
|
2026-09-16 17:42:27 +02:00
|
|
|
#include "RicfCommandForwarding.h"
|
2019-10-09 09:21:28 +02:00
|
|
|
|
2025-01-29 01:36:29 +01:00
|
|
|
#include "Formations/RimFormationNames.h"
|
2019-10-09 09:21:28 +02:00
|
|
|
#include "RimCase.h"
|
|
|
|
|
#include "RimProject.h"
|
2026-09-16 17:42:27 +02:00
|
|
|
#include "RimcCase.h"
|
|
|
|
|
#include "RimcProject.h"
|
2019-10-09 09:21:28 +02:00
|
|
|
|
2020-08-21 11:13:07 +02:00
|
|
|
#include "cafPdmFieldScriptingCapability.h"
|
2020-03-10 14:11:22 +01:00
|
|
|
|
2019-10-09 09:21:28 +02:00
|
|
|
CAF_PDM_SOURCE_INIT( RicfImportFormationNames, "importFormationNames" );
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
RicfImportFormationNames::RicfImportFormationNames()
|
|
|
|
|
{
|
2021-11-14 14:15:12 +01:00
|
|
|
CAF_PDM_InitScriptableFieldNoDefault( &m_formationFiles, "formationFiles", "" );
|
|
|
|
|
CAF_PDM_InitScriptableField( &m_applyToCaseId, "applyToCaseId", -1, "" );
|
2019-10-09 09:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-03-10 14:11:22 +01:00
|
|
|
caf::PdmScriptResponse RicfImportFormationNames::execute()
|
2019-10-09 09:21:28 +02:00
|
|
|
{
|
2026-09-16 17:42:27 +02:00
|
|
|
const QString commandName = classKeyword();
|
2019-10-09 09:21:28 +02:00
|
|
|
|
2026-09-16 17:42:27 +02:00
|
|
|
RimProject_importFormationNames importMethod( RimProject::current() );
|
|
|
|
|
importMethod.setFormationFiles( m_formationFiles() );
|
2019-10-09 09:21:28 +02:00
|
|
|
|
2026-09-16 17:42:27 +02:00
|
|
|
auto importResult = importMethod.execute();
|
|
|
|
|
if ( !importResult ) return RicfForwarding::errorResponse( importResult.error(), commandName );
|
|
|
|
|
|
|
|
|
|
auto* formationNames = dynamic_cast<RimFormationNames*>( importResult.value() );
|
|
|
|
|
if ( !formationNames ) return RicfForwarding::errorResponse( "Imported object is not a formation names object", commandName );
|
|
|
|
|
|
|
|
|
|
// Apply to the given case, or to all grid cases when applyToCaseId is -1
|
|
|
|
|
std::vector<RimCase*> cases;
|
|
|
|
|
if ( m_applyToCaseId() == -1 )
|
|
|
|
|
{
|
|
|
|
|
cases = RimProject::current()->allGridCases();
|
2019-10-09 09:21:28 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-09-16 17:42:27 +02:00
|
|
|
auto rimCase = RicfForwarding::findCase( m_applyToCaseId() );
|
|
|
|
|
if ( !rimCase )
|
|
|
|
|
{
|
|
|
|
|
caf::PdmScriptResponse response;
|
|
|
|
|
response.updateStatus( caf::PdmScriptResponse::COMMAND_WARNING, "Could not find the case to apply the formations to" );
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
cases.push_back( rimCase.value() );
|
2019-10-09 09:21:28 +02:00
|
|
|
}
|
|
|
|
|
|
2026-09-16 17:42:27 +02:00
|
|
|
for ( RimCase* rimCase : cases )
|
2019-10-09 09:21:28 +02:00
|
|
|
{
|
2026-09-16 17:42:27 +02:00
|
|
|
RimCase_setFormationNames setMethod( rimCase );
|
|
|
|
|
setMethod.setFormationNames( formationNames );
|
|
|
|
|
|
|
|
|
|
auto result = setMethod.execute();
|
|
|
|
|
if ( !result ) return RicfForwarding::errorResponse( result.error(), commandName );
|
2019-10-09 09:21:28 +02:00
|
|
|
}
|
2026-09-16 17:42:27 +02:00
|
|
|
|
|
|
|
|
return caf::PdmScriptResponse();
|
2019-10-09 09:21:28 +02:00
|
|
|
}
|