Files
ResInsight/ApplicationLibCode/ProjectDataModel/EnsembleFileSet/RimEnsembleFileSetCollection.cpp
T
Kristian Bendiksen 2fa7520b3a Refactor: forward-declare element type in collection headers
Move the element-type include from each migrated collection header into
its .cpp, leaving only a forward declaration in the header. Follows the
pattern from 9e4d79159 for RimJobCollection, made possible by the
constructor-time PdmObject base check.
2026-05-11 13:42:13 +02:00

158 lines
5.7 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2025 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 "RimEnsembleFileSetCollection.h"
#include "RimEnsembleFileSet.h"
#include "RimTools.h"
#include "cafCmdFeatureMenuBuilder.h"
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiLineEditor.h"
CAF_PDM_SOURCE_INIT( RimEnsembleFileSetCollection, "EnsembleFileSetCollection" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEnsembleFileSetCollection::RimEnsembleFileSetCollection()
{
CAF_PDM_InitObject( "Disc Data", ":/SummaryEnsemble.svg", "", "" );
CAF_PDM_InitFieldNoDefault( &m_items, "FileSets", "File Sets", "", "", "" );
m_items.uiCapability()->setUiHidden( true );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFileSetCollection::addFileSet( RimEnsembleFileSet* fileSet )
{
addItem( fileSet );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimEnsembleFileSet*> RimEnsembleFileSetCollection::fileSets() const
{
return items();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFileSetCollection::deleteAllFileSets()
{
deleteAllItems();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFileSetCollection::deleteFileSetIfPossible( RimEnsembleFileSet* fileSet )
{
if ( fileSet )
{
// Check if the file set is connected to any objects. If not, remove it from the collection and delete it
auto connectedObjects = fileSet->objectsWithReferringPtrFields();
if ( connectedObjects.empty() )
{
deleteItem( fileSet );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFileSetCollection::updateFilePathsFromProjectPath( const QString& newProjectPath, const QString& oldProjectPath )
{
for ( auto fileSet : fileSets() )
{
auto pattern = fileSet->pathPattern();
auto updatedPattern = RimTools::relocatePathPattern( pattern, newProjectPath, oldProjectPath );
if ( updatedPattern != pattern )
{
fileSet->setPathPattern( updatedPattern );
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimEnsembleFileSetCollection::ensembleFileSetOptions() const
{
QList<caf::PdmOptionItemInfo> options;
for ( const auto& fileset : m_items )
{
options.push_back( caf::PdmOptionItemInfo( fileset->name(), fileset, false, fileset->uiIconProvider() ) );
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFileSetCollection::updateFileSetNames()
{
std::set<std::string> key1;
std::set<std::string> key2;
for ( const auto& fileSet : fileSets() )
{
const auto keys = fileSet->nameKeys();
key1.insert( keys.first );
key2.insert( keys.second );
}
bool useKey1 = key1.size() > 1;
bool useKey2 = key2.size() > 1;
if ( !useKey1 && !useKey2 )
{
useKey2 = true;
}
std::set<QString> existingNames;
for ( auto fileSet : fileSets() )
{
fileSet->setUsePathKey1( useKey1 );
fileSet->setUsePathKey2( useKey2 );
fileSet->updateName( existingNames );
existingNames.insert( fileSet->name() );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFileSetCollection::appendMenuItems( caf::CmdFeatureMenuBuilder& menuBuilder ) const
{
menuBuilder << "RicImportEnsembleFileSetFeature";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimEnsembleFileSetCollection::initAfterRead()
{
updateFileSetNames();
}