Files
ResInsight/ApplicationLibCode/ProjectDataModel/StimPlanModel/RimStimPlanModelTemplateCollection.cpp
T
Kristian Bendiksen 5e880ffc26 Refactor: migrate fourteen more collections to caf::PdmObjectCollection<T>
Migrated to the templated base, preserving each collection's existing XML
field keyword for project-file backward compatibility:

- RimEnsembleFractureStatisticsCollection
- RimEclipseInputPropertyCollection
- RimPlotDataFilterCollection
- RimGeoMechContourMapViewCollection
- RimIntersectionResultsDefinitionCollection
- RimCustomObjectiveFunctionCollection
- RimStimPlanModelTemplateCollection
- RimEnsembleWellLogsCollection
- RimEclipseContourMapViewCollection
- RimSeismicViewCollection
- RimGridInfoCollection
- RimEclipseStatisticsCaseCollection
- RimWellIASettingsCollection
- RimVfpDataCollection

External callers that accessed the old public/named array fields directly
(RimEclipseInputPropertyCollection::inputProperties,
RimEclipseStatisticsCaseCollection::cases) now use addItem/items() from
the base. RimCustomObjectiveFunction.h replaced its include of the
collection header with a forward declaration to break the new include
cycle introduced by the migration.
2026-05-11 13:42:13 +02:00

140 lines
5.1 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2020- 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 "RimStimPlanModelTemplateCollection.h"
#include "RimCase.h"
#include "RimEclipseCase.h"
#include "RimEclipseView.h"
#include "RimProject.h"
#include "RimStimPlanModelTemplate.h"
#include "cafPdmFieldScriptingCapability.h"
#include "cafPdmObject.h"
#include "cafPdmObjectScriptingCapability.h"
#include <algorithm>
CAF_PDM_SOURCE_INIT( RimStimPlanModelTemplateCollection, "StimPlanModelTemplateCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStimPlanModelTemplateCollection::RimStimPlanModelTemplateCollection()
{
CAF_PDM_InitScriptableObject( "StimPlan Model Templates", ":/FractureTemplates16x16.png" );
CAF_PDM_InitScriptableFieldNoDefault( &m_items, "StimPlanModelTemplates", "StimPlan Model Templates" );
CAF_PDM_InitField( &m_nextValidId_OBSOLETE, "NextValidId", 0, "" );
m_nextValidId_OBSOLETE.xmlCapability()->setIOWritable( false );
m_nextValidId_OBSOLETE.uiCapability()->setUiHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimStimPlanModelTemplate* RimStimPlanModelTemplateCollection::stimPlanModelTemplate( int id ) const
{
for ( const auto& templ : m_items )
{
if ( templ->id() == id ) return templ;
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimStimPlanModelTemplate*> RimStimPlanModelTemplateCollection::stimPlanModelTemplates() const
{
std::vector<RimStimPlanModelTemplate*> templates;
for ( auto& templ : m_items )
{
templates.push_back( templ );
}
return templates;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStimPlanModelTemplateCollection::addStimPlanModelTemplate( RimStimPlanModelTemplate* templ )
{
templ->setId( nextFractureTemplateId() );
addItem( templ );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStimPlanModelTemplateCollection::loadAndUpdateData()
{
for ( RimStimPlanModelTemplate* f : m_items() )
{
f->loadDataAndUpdate();
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStimPlanModelTemplateCollection::initAfterRead()
{
// Assign template id if not already assigned
for ( auto& templ : m_items )
{
if ( templ->id() < 0 ) templ->setId( nextFractureTemplateId() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimStimPlanModelTemplateCollection::nextFractureTemplateId()
{
int nextValidId = 0;
for ( const auto& templ : m_items )
{
nextValidId = std::max( nextValidId, templ->id() + 1 );
}
return nextValidId;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimStimPlanModelTemplateCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects )
{
RimProject* proj = RimProject::current();
if ( proj )
{
proj->scheduleCreateDisplayModelAndRedrawAllViews();
}
std::vector<Rim3dView*> views = proj->allVisibleViews();
for ( Rim3dView* visibleView : views )
{
if ( dynamic_cast<RimEclipseView*>( visibleView ) )
{
visibleView->updateConnectedEditors();
}
}
}