Make RigWellPathFormations a value type

The object is immutable after construction and small, so reference
counting via cvf::Object adds nothing. Store it by value and use
std::optional where it may be absent.
This commit is contained in:
Magne Sjaastad committed 2026-10-07 13:37:23 +02:00
1 parent 07d8153852
commit 91e2e4d575
10 files changed
+47 -53

No files matched your search

@@ -36,9 +36,9 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<QString, cvf::ref<RigWellPathFormations>> RifWellPathFormationReader::readWellFormationsToGeometry( const QString& filePath )
std::map<QString, RigWellPathFormations> RifWellPathFormationReader::readWellFormationsToGeometry( const QString& filePath )
{
std::map<QString, cvf::ref<RigWellPathFormations>> result;
std::map<QString, RigWellPathFormations> result;
std::vector<QString> wellNames;
std::vector<QString> formationNames;
@@ -112,8 +112,7 @@ std::map<QString, cvf::ref<RigWellPathFormations>> RifWellPathFormationReader::r
for ( const std::pair<const QString, std::vector<RigWellPathFormation>>& formation : formations )
{
cvf::ref<RigWellPathFormations> wellPathFormations = new RigWellPathFormations( formation.second, filePath, formation.first );
result[formation.first] = wellPathFormations;
result.emplace( formation.first, RigWellPathFormations( formation.second, filePath, formation.first ) );
}
return result;
@@ -24,8 +24,6 @@
#include <utility>
#include <vector>
#include "cvfObject.h"
#include <QString>
//==================================================================================================
@@ -34,7 +32,7 @@
class RifWellPathFormationReader
{
public:
static std::map<QString, cvf::ref<RigWellPathFormations>> readWellFormationsToGeometry( const QString& filePath );
static std::map<QString, RigWellPathFormations> readWellFormationsToGeometry( const QString& filePath );
private:
static void readFile( const QString& filePath,
@@ -22,24 +22,25 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigWellPathFormations> RifWellPathFormationsImporter::readWellPathFormations( const QString& formationFilePath, const QString& wellName )
std::optional<RigWellPathFormations> RifWellPathFormationsImporter::readWellPathFormations( const QString& formationFilePath,
const QString& wellName )
{
readAllWellPathFormations( formationFilePath );
if ( m_fileNameToWellPathFormationMap[formationFilePath].find( wellName ) != m_fileNameToWellPathFormationMap[formationFilePath].end() )
const auto& wellFormations = m_fileNameToWellPathFormationMap[formationFilePath];
if ( auto it = wellFormations.find( wellName ); it != wellFormations.end() )
{
return m_fileNameToWellPathFormationMap[formationFilePath][wellName];
}
else
{
return nullptr;
return it->second;
}
return std::nullopt;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigWellPathFormations> RifWellPathFormationsImporter::reloadWellPathFormations( const QString& formationFilePath,
const QString& wellName )
std::optional<RigWellPathFormations> RifWellPathFormationsImporter::reloadWellPathFormations( const QString& formationFilePath,
const QString& wellName )
{
m_fileNameToWellPathFormationMap.erase( formationFilePath );
@@ -49,7 +50,7 @@ cvf::ref<RigWellPathFormations> RifWellPathFormationsImporter::reloadWellPathFor
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<QString, cvf::ref<RigWellPathFormations>> RifWellPathFormationsImporter::readWellPathFormationsFromPath( const QString& filePath )
std::map<QString, RigWellPathFormations> RifWellPathFormationsImporter::readWellPathFormationsFromPath( const QString& filePath )
{
// If we have the file in the map, assume it is already read.
if ( m_fileNameToWellPathFormationMap.find( filePath ) != m_fileNameToWellPathFormationMap.end() )
@@ -57,8 +58,7 @@ std::map<QString, cvf::ref<RigWellPathFormations>> RifWellPathFormationsImporter
return m_fileNameToWellPathFormationMap[filePath];
}
std::map<QString, cvf::ref<RigWellPathFormations>> wellPathToFormationMap =
RifWellPathFormationReader::readWellFormationsToGeometry( filePath );
std::map<QString, RigWellPathFormations> wellPathToFormationMap = RifWellPathFormationReader::readWellFormationsToGeometry( filePath );
m_fileNameToWellPathFormationMap[filePath] = wellPathToFormationMap;
@@ -95,8 +95,7 @@ void RifWellPathFormationsImporter::readAllWellPathFormations( const QString& fi
return;
}
std::map<QString, cvf::ref<RigWellPathFormations>> wellPathToFormationMap =
RifWellPathFormationReader::readWellFormationsToGeometry( filePath );
std::map<QString, RigWellPathFormations> wellPathToFormationMap = RifWellPathFormationReader::readWellFormationsToGeometry( filePath );
m_fileNameToWellPathFormationMap[filePath] = wellPathToFormationMap;
}
@@ -20,12 +20,11 @@
#include "Well/RigWellPathFormations.h"
#include "cvfObject.h"
#include <QDateTime>
#include <QString>
#include <map>
#include <optional>
#include <vector>
//==================================================================================================
@@ -35,15 +34,15 @@
class RifWellPathFormationsImporter
{
public:
cvf::ref<RigWellPathFormations> readWellPathFormations( const QString& formationFilePath, const QString& wellName );
cvf::ref<RigWellPathFormations> reloadWellPathFormations( const QString& formationFilePath, const QString& wellName );
std::optional<RigWellPathFormations> readWellPathFormations( const QString& formationFilePath, const QString& wellName );
std::optional<RigWellPathFormations> reloadWellPathFormations( const QString& formationFilePath, const QString& wellName );
std::map<QString, cvf::ref<RigWellPathFormations>> readWellPathFormationsFromPath( const QString& filePath );
std::map<QString, RigWellPathFormations> readWellPathFormationsFromPath( const QString& filePath );
void reloadAllWellPathFormations();
private:
void readAllWellPathFormations( const QString& filePath );
std::map<QString /*filename*/, std::map<QString /*wellName*/, cvf::ref<RigWellPathFormations>>> m_fileNameToWellPathFormationMap;
std::map<QString /*filename*/, std::map<QString /*wellName*/, RigWellPathFormations>> m_fileNameToWellPathFormationMap;
};
@@ -749,7 +749,7 @@ void RimEnsembleWellLogCurveSet::updateEnsembleCurves( const std::vector<RimWell
if ( m_statistics->hideEnsembleCurves() ) return;
std::shared_ptr<RigWellLogIndexDepthOffset> offsets;
cvf::ref<RigWellPathFormations> wellPathFormations;
std::optional<RigWellPathFormations> wellPathFormations;
if ( m_depthEqualization() == RimEnsembleWellLogStatistics::DepthEqualization::K_LAYER )
{
@@ -792,7 +792,7 @@ void RimEnsembleWellLogCurveSet::updateEnsembleCurves( const std::vector<RimWell
}
RimWellPath* wellPath = RimProject::current()->wellPathByName( wellLogFile->wellName() );
if ( wellPathFormations.notNull() ) wellPath->setFormationsGeometry( wellPathFormations );
if ( wellPathFormations ) wellPath->setFormationsGeometry( *wellPathFormations );
curve->setWellPath( wellPath );
curve->setWellLogChannelName( wellLogChannelName );
@@ -1232,18 +1232,18 @@ void RimEnsembleWellLogCurveSet::setWellLogChannelName( const QString& wellLogCh
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigWellPathFormations> RimEnsembleWellLogCurveSet::createWellPathFormations( std::shared_ptr<RigWellLogIndexDepthOffset> offsets )
std::optional<RigWellPathFormations> RimEnsembleWellLogCurveSet::createWellPathFormations( std::shared_ptr<RigWellLogIndexDepthOffset> offsets )
{
RimFormationNamesCollection* formationNamesCollection = RimProject::current()->activeOilField()->formationNamesCollection.v();
if ( !formationNamesCollection ) return nullptr;
if ( !formationNamesCollection ) return std::nullopt;
if ( formationNamesCollection->formationNamesList().empty() ) return nullptr;
if ( formationNamesCollection->formationNamesList().empty() ) return std::nullopt;
RimFormationNames* rimFormationNames = formationNamesCollection->formationNamesList()[0];
if ( !rimFormationNames ) return nullptr;
if ( !rimFormationNames ) return std::nullopt;
auto formationNames = rimFormationNames->formationNamesData();
if ( !formationNames ) return nullptr;
if ( !formationNames ) return std::nullopt;
std::vector<RigWellPathFormation> wellPathFormationItems;
for ( int kLayer : offsets->sortedIndexes() )
@@ -1255,10 +1255,8 @@ cvf::ref<RigWellPathFormations> RimEnsembleWellLogCurveSet::createWellPathFormat
wellPathFormationItems.push_back( wellPathFormation );
}
QString unusedFilePath = "";
cvf::ref<RigWellPathFormations> wellPathFormations =
new RigWellPathFormations( wellPathFormationItems, unusedFilePath, "Ensemble formation" );
return wellPathFormations;
QString unusedFilePath = "";
return RigWellPathFormations( wellPathFormationItems, unusedFilePath, "Ensemble formation" );
}
//--------------------------------------------------------------------------------------------------
@@ -35,6 +35,8 @@
#include <QPointer>
#include <optional>
class RimEnsembleWellLogs;
class RimEnsembleWellLogsCollection;
class RimEnsembleCurveFilterCollection;
@@ -156,7 +158,7 @@ private:
void onEnsembleCurvesAppearanceChanged( const caf::SignalEmitter* emitter );
void setLogScaleFromSelectedResult( const QString resVar );
cvf::ref<RigWellPathFormations> createWellPathFormations( std::shared_ptr<RigWellLogIndexDepthOffset> offsets );
std::optional<RigWellPathFormations> createWellPathFormations( std::shared_ptr<RigWellLogIndexDepthOffset> offsets );
private:
caf::PdmField<bool> m_showCurves;
@@ -987,11 +987,11 @@ void RimWellPath::detachWellLog( RimWellLog* wellLog )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellPath::setFormationsGeometry( cvf::ref<RigWellPathFormations> wellPathFormations )
void RimWellPath::setFormationsGeometry( const RigWellPathFormations& wellPathFormations )
{
m_wellPathFormations = wellPathFormations;
m_wellPathFormationFilePath = wellPathFormations->filePath();
m_formationKeyInFile = wellPathFormations->keyInFile();
m_wellPathFormationFilePath = wellPathFormations.filePath();
m_formationKeyInFile = wellPathFormations.keyInFile();
updateConnectedEditors();
}
@@ -1051,7 +1051,7 @@ bool RimWellPath::reloadWellPathFormationsFile( QString* errorMessage, RifWellPa
//--------------------------------------------------------------------------------------------------
bool RimWellPath::hasFormations() const
{
return !m_wellPathFormations.isNull();
return m_wellPathFormations.has_value();
}
//--------------------------------------------------------------------------------------------------
@@ -1059,7 +1059,7 @@ bool RimWellPath::hasFormations() const
//--------------------------------------------------------------------------------------------------
const RigWellPathFormations* RimWellPath::formationsGeometry() const
{
return m_wellPathFormations.p();
return m_wellPathFormations ? &m_wellPathFormations.value() : nullptr;
}
//--------------------------------------------------------------------------------------------------
@@ -24,6 +24,8 @@
#include "RimWellPathComponentInterface.h"
#include "Well/RigWellPathFormations.h"
#include "cafAppEnum.h"
#include "cafFilePath.h"
#include "cafPdmChildField.h"
@@ -43,7 +45,6 @@
class RifWellPathImporter;
class RifWellPathFormationsImporter;
class RigWellPath;
class RigWellPathFormations;
class RimProject;
class RimWellLogFile;
@@ -115,7 +116,7 @@ public:
RimWellLogFile* firstWellLogFileMatchingChannelName( const QString& channelName ) const;
void setFormationsGeometry( cvf::ref<RigWellPathFormations> wellPathFormations );
void setFormationsGeometry( const RigWellPathFormations& wellPathFormations );
bool readWellPathFormationsFile( QString* errorMessage, RifWellPathFormationsImporter* wellPathFormationsImporter );
bool reloadWellPathFormationsFile( QString* errorMessage, RifWellPathFormationsImporter* wellPathFormationsImporter );
bool hasFormations() const;
@@ -230,6 +231,6 @@ private:
private:
// Geometry and data
cvf::ref<RigWellPath> m_wellPathGeometry;
cvf::ref<RigWellPathFormations> m_wellPathFormations;
cvf::ref<RigWellPath> m_wellPathGeometry;
std::optional<RigWellPathFormations> m_wellPathFormations;
};
@@ -533,8 +533,7 @@ void RimWellPathCollection::addWellPathFormations( const QStringList& filePaths
for ( const QString& filePath : filePaths )
{
std::map<QString, cvf::ref<RigWellPathFormations>> newFormations =
m_wellPathFormationsImporter->readWellPathFormationsFromPath( filePath );
std::map<QString, RigWellPathFormations> newFormations = m_wellPathFormationsImporter->readWellPathFormationsFromPath( filePath );
for ( const auto& newFormation : newFormations )
{
@@ -550,7 +549,7 @@ void RimWellPathCollection::addWellPathFormations( const QStringList& filePaths
}
wellPath->setFormationsGeometry( newFormation.second );
QString wellFormationsCount = QString( "%1" ).arg( newFormation.second->formationNamesCount() );
QString wellFormationsCount = QString( "%1" ).arg( newFormation.second.formationNamesCount() );
m_mostRecentlyUpdatedWellPath = wellPath;
@@ -22,7 +22,6 @@
#include "RiaWellLogTrackDefines.h"
#include "cvfMath.h"
#include "cvfObject.h"
#include <map>
#include <utility>
@@ -42,7 +41,7 @@ struct RigWellPathFormation
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RigWellPathFormations : public cvf::Object
class RigWellPathFormations
{
public:
using FormationLevel = RiaDefines::WellLogTrackFormationLevel;