Change API for PdmObjectHandle and PdmFieldHandle

* Refactor interface to PdmObjectHandle and PdmFieldHandle
Return objects instead of passing in structures as parameters

* Add nodiscard to several functions
* Remove redundant this->
* Rename to ptrReferencedObjectsByType
This commit is contained in:
Magne Sjaastad
2023-05-12 21:41:34 +02:00
committed by GitHub
parent 37e29a0f68
commit 0c90f67dcc
510 changed files with 1651 additions and 3111 deletions

View File

@@ -82,9 +82,7 @@ void RimModeledWellPath::updateWellPathVisualization()
{
createWellPathGeometry();
std::vector<RimPlotCurve*> referringCurves;
objectsWithReferringPtrFieldsOfType( referringCurves );
std::vector<RimPlotCurve*> referringCurves = objectsWithReferringPtrFieldsOfType<RimPlotCurve>();
for ( auto curve : referringCurves )
{
curve->loadDataAndUpdate( false );
@@ -95,23 +93,20 @@ void RimModeledWellPath::updateWellPathVisualization()
fracture->loadDataAndUpdate();
}
std::vector<RimExtrudedCurveIntersection*> referringIntersections;
objectsWithReferringPtrFieldsOfType( referringIntersections );
std::vector<RimExtrudedCurveIntersection*> referringIntersections = objectsWithReferringPtrFieldsOfType<RimExtrudedCurveIntersection>();
for ( auto intersection : referringIntersections )
{
intersection->rebuildGeometryAndScheduleCreateDisplayModel();
}
std::vector<RimSeismicSection*> referringSeismic;
objectsWithReferringPtrFieldsOfType( referringSeismic );
std::vector<RimSeismicSection*> referringSeismic = objectsWithReferringPtrFieldsOfType<RimSeismicSection>();
for ( auto seisSec : referringSeismic )
{
seisSec->updateVisualization();
}
RimProject* proj;
firstAncestorOrThisOfTypeAsserted( proj );
RimProject* proj = RimProject::current();
proj->scheduleCreateDisplayModelAndRedrawAllViews();
}
@@ -222,8 +217,7 @@ void RimModeledWellPath::updateGeometry( bool fullUpdate )
{
updateWellPathVisualization();
std::vector<RimWellPathTieIn*> tieInObjects;
objectsWithReferringPtrFieldsOfType( tieInObjects );
std::vector<RimWellPathTieIn*> tieInObjects = objectsWithReferringPtrFieldsOfType<RimWellPathTieIn>();
for ( auto tieIn : tieInObjects )
{
if ( tieIn->parentWell() == this )

View File

@@ -168,8 +168,7 @@ QList<caf::PdmOptionItemInfo> RimWellIASettings::calculateValueOptions( const ca
//--------------------------------------------------------------------------------------------------
void RimWellIASettings::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
{
RimWellPath* wellPath;
firstAncestorOrThisOfType( wellPath );
auto wellPath = firstAncestorOrThisOfType<RimWellPath>();
if ( wellPath )
{
if ( wellPath->unitSystem() == RiaDefines::EclipseUnitSystem::UNITS_METRIC )
@@ -212,8 +211,7 @@ void RimWellIASettings::defineEditorAttribute( const caf::PdmFieldHandle* field,
if ( myAttr )
{
RimWellPath* wellPath = nullptr;
this->firstAncestorOrThisOfType( wellPath );
auto wellPath = firstAncestorOrThisOfType<RimWellPath>();
if ( !wellPath ) return;
myAttr->m_minimum = wellPath->uniqueStartMD();
@@ -569,9 +567,7 @@ void RimWellIASettings::resetModelData()
//--------------------------------------------------------------------------------------------------
RimWellPath* RimWellIASettings::wellPath() const
{
RimWellPath* wellpath = nullptr;
this->firstAncestorOrThisOfTypeAsserted( wellpath );
return wellpath;
return firstAncestorOrThisOfTypeAsserted<RimWellPath>();
}
//--------------------------------------------------------------------------------------------------

View File

@@ -89,7 +89,7 @@ RimWellIASettings* RimWellIASettingsCollection::startWellIntegrationAnalysis( QS
//--------------------------------------------------------------------------------------------------
std::vector<RimWellIASettings*> RimWellIASettingsCollection::settings() const
{
return m_wellIASettings.children();
return m_wellIASettings.childrenByType();
}
//--------------------------------------------------------------------------------------------------
@@ -114,8 +114,7 @@ bool RimWellIASettingsCollection::hasSettings() const
void RimWellIASettingsCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects )
{
RimWellPath* wellPath;
this->firstAncestorOrThisOfType( wellPath );
auto wellPath = firstAncestorOrThisOfType<RimWellPath>();
if ( wellPath ) wellPath->updateConnectedEditors();
RiaApplication::instance()->project()->scheduleCreateDisplayModelAndRedrawAllViews();
}

View File

@@ -187,8 +187,7 @@ double RimWellPath::wellPathRadius( double characteristicCellSize ) const
{
double radius = characteristicCellSize * m_wellPathRadiusScaleFactor();
RimWellPathCollection* coll = nullptr;
this->firstAncestorOrThisOfType( coll );
RimWellPathCollection* coll = RimTools::wellPathCollection();
if ( coll )
{
radius *= coll->wellPathRadiusScaleFactor();
@@ -466,8 +465,7 @@ double RimWellPath::uniqueEndMD() const
//--------------------------------------------------------------------------------------------------
void RimWellPath::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue )
{
RimProject* proj;
this->firstAncestorOrThisOfTypeAsserted( proj );
RimProject* proj = RimProject::current();
if ( changedField == &m_showWellPath )
{
proj->reloadCompletionTypeResultsInAllViews();
@@ -818,8 +816,7 @@ size_t RimWellPath::simulationWellBranchCount( const QString& simWellName )
//--------------------------------------------------------------------------------------------------
double RimWellPath::combinedScaleFactor() const
{
RimWellPathCollection* wellPathColl = nullptr;
this->firstAncestorOrThisOfTypeAsserted( wellPathColl );
RimWellPathCollection* wellPathColl = firstAncestorOrThisOfTypeAsserted<RimWellPathCollection>();
return this->m_wellPathRadiusScaleFactor() * wellPathColl->wellPathRadiusScaleFactor();
}
@@ -833,8 +830,7 @@ void RimWellPath::setUnitSystem( RiaDefines::EclipseUnitSystem unitSystem )
m_completions->setUnitSystemSpecificDefaults();
std::vector<RimMswCompletionParameters*> mswParameters;
descendantsOfType( mswParameters );
std::vector<RimMswCompletionParameters*> mswParameters = descendantsOfType<RimMswCompletionParameters>();
for ( auto mswParams : mswParameters )
{
mswParams->setUnitSystemSpecificDefaults();
@@ -1104,8 +1100,7 @@ bool RimWellPath::isMultiLateralWellPath() const
{
auto top = topLevelWellPath();
std::vector<RimWellPath*> wells;
top->descendantsIncludingThisOfType( wells );
std::vector<RimWellPath*> wells = top->descendantsIncludingThisOfType<RimWellPath>();
return wells.size() > 1;
}
@@ -1147,8 +1142,7 @@ void RimWellPath::wellPathLateralsRecursively( std::vector<RimWellPath*>& wellPa
{
wellPathLaterals.push_back( const_cast<RimWellPath*>( this ) );
std::vector<caf::PdmObjectHandle*> referringObjects;
this->objectsWithReferringPtrFields( referringObjects );
std::vector<caf::PdmObjectHandle*> referringObjects = objectsWithReferringPtrFields();
for ( auto obj : referringObjects )
{
if ( auto tieIn = dynamic_cast<RimWellPathTieIn*>( obj ) )
@@ -1184,8 +1178,7 @@ std::vector<RimWellPath*> RimWellPath::wellPathLaterals() const
{
std::vector<RimWellPath*> laterals;
std::vector<caf::PdmObjectHandle*> referringObjects;
this->objectsWithReferringPtrFields( referringObjects );
std::vector<caf::PdmObjectHandle*> referringObjects = objectsWithReferringPtrFields();
for ( auto obj : referringObjects )
{
if ( auto tieIn = dynamic_cast<RimWellPathTieIn*>( obj ) )

View File

@@ -95,8 +95,7 @@ void RimWellPathAttribute::setDepthsFromWellPath( gsl::not_null<const RimWellPat
//--------------------------------------------------------------------------------------------------
bool RimWellPathAttribute::isEnabled() const
{
RimWellPathAttributeCollection* collection = nullptr;
this->firstAncestorOrThisOfTypeAsserted( collection );
auto collection = firstAncestorOrThisOfTypeAsserted<RimWellPathAttributeCollection>();
return collection->isChecked();
}
@@ -260,9 +259,8 @@ void RimWellPathAttribute::fieldChangedByUi( const caf::PdmFieldHandle* changedF
{
if ( m_type() == RiaDefines::WellPathComponentType::CASING )
{
RimWellPath* wellPath = nullptr;
this->firstAncestorOrThisOfTypeAsserted( wellPath );
m_startMD = wellPath->startMD();
auto wellPath = firstAncestorOrThisOfTypeAsserted<RimWellPath>();
m_startMD = wellPath->startMD();
if ( !supportedDiameters( m_type() ).count( m_diameterInInches() ) )
{
@@ -290,13 +288,11 @@ void RimWellPathAttribute::fieldChangedByUi( const caf::PdmFieldHandle* changedF
}
{
RimWellPathAttributeCollection* collection = nullptr;
this->firstAncestorOrThisOfTypeAsserted( collection );
auto collection = firstAncestorOrThisOfTypeAsserted<RimWellPathAttributeCollection>();
collection->updateAllReferringTracks();
}
{
RimProject* proj;
this->firstAncestorOrThisOfTypeAsserted( proj );
RimProject* proj = RimProject::current();
proj->reloadCompletionTypeResultsInAllViews();
}
}

View File

@@ -53,9 +53,7 @@ RimWellPathAttributeCollection::~RimWellPathAttributeCollection()
//--------------------------------------------------------------------------------------------------
void RimWellPathAttributeCollection::updateAllReferringTracks()
{
std::vector<RimWellLogTrack*> wellLogTracks;
this->objectsWithReferringPtrFieldsOfType( wellLogTracks );
std::vector<RimWellLogTrack*> wellLogTracks = objectsWithReferringPtrFieldsOfType<RimWellLogTrack>();
for ( RimWellLogTrack* track : wellLogTracks )
{
track->loadDataAndUpdate();
@@ -167,8 +165,7 @@ void RimWellPathAttributeCollection::fieldChangedByUi( const caf::PdmFieldHandle
{
if ( changedField == this->objectToggleField() )
{
RimProject* proj;
this->firstAncestorOrThisOfTypeAsserted( proj );
RimProject* proj = RimProject::current();
proj->scheduleCreateDisplayModelAndRedrawAllViews();
this->updateAllReferringTracks();
}

View File

@@ -283,7 +283,7 @@ void RimWellPathCollection::addWellPath( gsl::not_null<RimWellPath*> wellPath )
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPath*> RimWellPathCollection::allWellPaths() const
{
return m_wellPaths.children();
return m_wellPaths.childrenByType();
}
//--------------------------------------------------------------------------------------------------
@@ -485,8 +485,7 @@ caf::PdmFieldHandle* RimWellPathCollection::objectToggleField()
//--------------------------------------------------------------------------------------------------
void RimWellPathCollection::scheduleRedrawAffectedViews()
{
RimProject* proj;
this->firstAncestorOrThisOfType( proj );
RimProject* proj = RimProject::current();
if ( proj ) proj->reloadCompletionTypeResultsInAllViews();
}
@@ -760,8 +759,7 @@ void RimWellPathCollection::sortWellsByName()
//--------------------------------------------------------------------------------------------------
caf::AppEnum<RiaDefines::EclipseUnitSystem> RimWellPathCollection::findUnitSystemForWellPath( const RimWellPath* wellPath )
{
RimProject* project;
firstAncestorOrThisOfTypeAsserted( project );
RimProject* project = RimProject::current();
if ( project->activeOilField()->analysisModels->cases.empty() )
{
return RiaDefines::EclipseUnitSystem::UNITS_UNKNOWN;
@@ -790,7 +788,7 @@ void RimWellPathCollection::rebuildWellPathNodes()
{
m_wellPathNodes.deleteChildren();
std::map<QString, std::vector<RimWellPath*>> rootWells = wellPathsForWellNameStem( m_wellPaths.children() );
std::map<QString, std::vector<RimWellPath*>> rootWells = wellPathsForWellNameStem( m_wellPaths.childrenByType() );
for ( auto [groupName, wellPathGroup] : rootWells )
{
if ( groupName == unGroupedText() )

View File

@@ -100,7 +100,7 @@ void RimWellPathGroup::addChildWellPath( RimWellPath* wellPath )
//--------------------------------------------------------------------------------------------------
std::vector<RimWellPath*> RimWellPathGroup::childWellPaths() const
{
return m_childWellPaths.children();
return m_childWellPaths.childrenByType();
}
//--------------------------------------------------------------------------------------------------
@@ -146,7 +146,7 @@ void RimWellPathGroup::removeChildWellPath( RimWellPath* wellPath )
//--------------------------------------------------------------------------------------------------
void RimWellPathGroup::removeAllChildWellPaths()
{
auto childWellPaths = m_childWellPaths.children();
auto childWellPaths = m_childWellPaths.childrenByType();
for ( auto wellPath : childWellPaths )
{
removeChildWellPath( wellPath );
@@ -269,8 +269,7 @@ std::vector<const RigWellPath*> RimWellPathGroup::wellPathGeometries() const
QString RimWellPathGroup::createGroupName() const
{
QStringList allNames;
std::vector<RimWellPath*> descendantWellPaths;
this->descendantsOfType( descendantWellPaths );
std::vector<RimWellPath*> descendantWellPaths = descendantsOfType<RimWellPath>();
for ( auto wellPath : descendantWellPaths )
{
if ( wellPath )
@@ -286,8 +285,7 @@ QString RimWellPathGroup::createGroupName() const
// if no imported well path is present, use all modeled well paths
if ( allNames.empty() )
{
std::vector<RimModeledWellPath*> descendantWellPaths;
this->descendantsOfType( descendantWellPaths );
std::vector<RimModeledWellPath*> descendantWellPaths = descendantsOfType<RimModeledWellPath>();
for ( auto wellPath : descendantWellPaths )
{
if ( wellPath )

View File

@@ -486,10 +486,8 @@ void RimWellPathTarget::setTargetPointFromDisplayCoord( const cvf::Vec3d& coordI
//--------------------------------------------------------------------------------------------------
double RimWellPathTarget::measuredDepth() const
{
RimWellPath* wellPath = nullptr;
this->firstAncestorOfType( wellPath );
auto geoDef = geometryDefinition();
auto wellPath = firstAncestorOfType<RimWellPath>();
auto geoDef = geometryDefinition();
if ( geoDef && wellPath && wellPath->wellPathGeometry() )
{
@@ -508,10 +506,7 @@ double RimWellPathTarget::measuredDepth() const
//--------------------------------------------------------------------------------------------------
RimWellPathGeometryDef* RimWellPathTarget::geometryDefinition() const
{
RimWellPathGeometryDef* geoDef = nullptr;
this->firstAncestorOfType( geoDef );
return geoDef;
return firstAncestorOfType<RimWellPathGeometryDef>();
}
//--------------------------------------------------------------------------------------------------