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
@@ -336,8 +336,7 @@ void RimBoxIntersection::fieldChangedByUi( const caf::PdmFieldHandle* changedFie
{
m_boxManipulator = new RicBoxManipulatorEventHandler( viewer() );
Rim3dView* rimView = nullptr;
this->firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
for ( Rim3dView* mainView : rimView->viewsUsingThisAsComparisonView() )
{
m_boxManipulator->registerInAdditionalViewer( mainView->viewer() );
@@ -367,9 +366,7 @@ void RimBoxIntersection::fieldChangedByUi( const caf::PdmFieldHandle* changedFie
{
if ( m_boxManipulator )
{
Rim3dView* rimView = nullptr;
this->firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( rimView )
{
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
@@ -393,8 +390,7 @@ void RimBoxIntersection::updateBoxManipulatorGeometry()
{
if ( m_boxManipulator.isNull() ) return;
Rim3dView* rimView = nullptr;
this->firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( !rimView ) return;
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
@@ -522,8 +518,7 @@ void RimBoxIntersection::initAfterRead()
//--------------------------------------------------------------------------------------------------
void RimBoxIntersection::slotScheduleRedraw()
{
Rim3dView* rimView = nullptr;
this->firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( rimView )
{
rimView->scheduleCreateDisplayModelAndRedraw();
@@ -535,9 +530,7 @@ void RimBoxIntersection::slotScheduleRedraw()
//--------------------------------------------------------------------------------------------------
void RimBoxIntersection::slotUpdateGeometry( const cvf::Vec3d& origin, const cvf::Vec3d& size )
{
Rim3dView* rimView = nullptr;
this->firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( rimView )
{
cvf::ref<caf::DisplayCoordTransform> transForm = rimView->displayCoordTransform();
@@ -663,23 +656,8 @@ void RimBoxIntersection::switchSingelPlaneState()
//--------------------------------------------------------------------------------------------------
cvf::BoundingBox RimBoxIntersection::currentCellBoundingBox()
{
RimCase* rimCase = nullptr;
this->firstAncestorOrThisOfType( rimCase );
auto rimCase = firstAncestorOrThisOfTypeAsserted<RimCase>();
CVF_ASSERT( rimCase );
/*
RimEclipseView* eclView = nullptr;
this->firstAncestorOrThisOfType(eclView);
bool useAllCells = true;
if (eclView)
{
useAllCells = eclView->showInactiveCells();
}
if(false)//useAllCells) // For now, only use the active CellsBBox.
return rimCase->allCellsBoundingBox();
else */
return rimCase->activeCellsBoundingBox();
}
@@ -688,11 +666,8 @@ cvf::BoundingBox RimBoxIntersection::currentCellBoundingBox()
//--------------------------------------------------------------------------------------------------
RiuViewer* RimBoxIntersection::viewer()
{
Rim3dView* rimView = nullptr;
this->firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( rimView ) return rimView->viewer();
RiuViewer* riuViewer = nullptr;
if ( rimView ) riuViewer = rimView->viewer();
return riuViewer;
return nullptr;
}
@@ -708,8 +708,7 @@ std::vector<std::vector<cvf::Vec3d>> RimExtrudedCurveIntersection::polyLines( cv
if ( m_wellPath() && wellPath()->wellPathGeometry() )
{
lines.push_back( wellPath()->wellPathGeometry()->wellPathPoints() );
RimCase* ownerCase = nullptr;
this->firstAncestorOrThisOfType( ownerCase );
auto ownerCase = firstAncestorOrThisOfType<RimCase>();
if ( ownerCase && ownerCase->activeCellsBoundingBox().isValid() )
{
size_t dummy;
@@ -1041,8 +1040,7 @@ void RimExtrudedCurveIntersection::appendPointToPolyLine( const cvf::Vec3d& poin
//--------------------------------------------------------------------------------------------------
Rim2dIntersectionView* RimExtrudedCurveIntersection::correspondingIntersectionView() const
{
std::vector<Rim2dIntersectionView*> objects;
this->objectsWithReferringPtrFieldsOfType( objects );
std::vector<Rim2dIntersectionView*> objects = objectsWithReferringPtrFieldsOfType<Rim2dIntersectionView>();
for ( auto isectView : objects )
{
if ( isectView )
@@ -1237,8 +1235,7 @@ void RimExtrudedCurveIntersection::rebuildGeometryAndScheduleCreateDisplayModel(
{
m_crossSectionPartMgr = nullptr;
Rim3dView* rimView = nullptr;
this->firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( rimView )
{
rimView->scheduleCreateDisplayModelAndRedraw();
@@ -1314,7 +1311,5 @@ void RimExtrudedCurveIntersection::setPointsFromXYD( const std::vector<cvf::Vec3
//--------------------------------------------------------------------------------------------------
RimEclipseView* RimExtrudedCurveIntersection::eclipseView() const
{
RimEclipseView* eclipseView = nullptr;
firstAncestorOrThisOfType( eclipseView );
return eclipseView;
return firstAncestorOrThisOfType<RimEclipseView>();
}
@@ -128,8 +128,7 @@ QList<caf::PdmOptionItemInfo> RimIntersection::calculateValueOptions( const caf:
//--------------------------------------------------------------------------------------------------
RimIntersectionResultsDefinitionCollection* RimIntersection::findSeparateResultsCollection()
{
RimGridView* view;
this->firstAncestorOrThisOfTypeAsserted( view );
auto view = firstAncestorOrThisOfTypeAsserted<RimGridView>();
return view->separateIntersectionResultsCollection();
}
@@ -187,8 +186,7 @@ void RimIntersection::updateDefaultSeparateDataSource()
//--------------------------------------------------------------------------------------------------
cvf::ref<RivIntersectionHexGridInterface> RimIntersection::createHexGridInterface()
{
RimGeoMechView* geoView;
this->firstAncestorOrThisOfType( geoView );
auto geoView = firstAncestorOrThisOfType<RimGeoMechView>();
RimIntersectionResultDefinition* resDef = activeSeparateResultDefinition();
if ( resDef && resDef->activeCase() )
@@ -214,8 +212,7 @@ cvf::ref<RivIntersectionHexGridInterface> RimIntersection::createHexGridInterfac
}
}
RimEclipseView* eclipseView;
this->firstAncestorOrThisOfType( eclipseView );
auto eclipseView = firstAncestorOrThisOfType<RimEclipseView>();
if ( eclipseView && eclipseView->mainGrid() )
{
RigMainGrid* grid = eclipseView->mainGrid();
@@ -96,8 +96,7 @@ caf::PdmFieldHandle* RimIntersectionCollection::objectToggleField()
//--------------------------------------------------------------------------------------------------
void RimIntersectionCollection::defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName /*= "" */ )
{
RimGridView* gridView = nullptr;
this->firstAncestorOfType( gridView );
auto gridView = firstAncestorOfType<RimGridView>();
if ( gridView )
{
auto uiTree = gridView->separateIntersectionResultsCollection()->uiTreeOrdering();
@@ -251,7 +250,7 @@ void RimIntersectionCollection::rebuildGeometry()
//--------------------------------------------------------------------------------------------------
std::vector<RimExtrudedCurveIntersection*> RimIntersectionCollection::intersections() const
{
return m_intersections.children();
return m_intersections.childrenByType();
}
//--------------------------------------------------------------------------------------------------
@@ -259,7 +258,7 @@ std::vector<RimExtrudedCurveIntersection*> RimIntersectionCollection::intersecti
//--------------------------------------------------------------------------------------------------
std::vector<RimBoxIntersection*> RimIntersectionCollection::intersectionBoxes() const
{
return m_intersectionBoxes.children();
return m_intersectionBoxes.childrenByType();
}
//--------------------------------------------------------------------------------------------------
@@ -306,8 +305,7 @@ void RimIntersectionCollection::appendIntersectionNoUpdate( RimExtrudedCurveInte
//--------------------------------------------------------------------------------------------------
void RimIntersectionCollection::syncronize2dIntersectionViews()
{
RimCase* ownerCase = nullptr;
this->firstAncestorOrThisOfTypeAsserted( ownerCase );
auto ownerCase = firstAncestorOrThisOfTypeAsserted<RimCase>();
ownerCase->intersectionViewCollection()->syncFromExistingIntersections( true );
}
@@ -508,9 +506,7 @@ void RimIntersectionCollection::defineEditorAttribute( const caf::PdmFieldHandle
//--------------------------------------------------------------------------------------------------
RimEclipseView* RimIntersectionCollection::eclipseView() const
{
RimEclipseView* eclipseView = nullptr;
firstAncestorOrThisOfType( eclipseView );
return eclipseView;
return firstAncestorOrThisOfType<RimEclipseView>();
}
//--------------------------------------------------------------------------------------------------
@@ -518,8 +514,7 @@ RimEclipseView* RimIntersectionCollection::eclipseView() const
//--------------------------------------------------------------------------------------------------
void RimIntersectionCollection::rebuild3dView() const
{
Rim3dView* rimView = nullptr;
firstAncestorOrThisOfType( rimView );
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( rimView )
{
rimView->scheduleCreateDisplayModelAndRedraw();
@@ -104,8 +104,7 @@ void RimIntersectionResultDefinition::assignCaseIfMissing() const
{
if ( !m_case )
{
RimCase* ownerCase = nullptr;
this->firstAncestorOrThisOfType( ownerCase );
auto ownerCase = firstAncestorOrThisOfType<RimCase>();
const_cast<RimIntersectionResultDefinition*>( this )->setActiveCase( ownerCase );
}
}
@@ -331,14 +330,12 @@ void RimIntersectionResultDefinition::fieldChangedByUi( const caf::PdmFieldHandl
this->updateConnectedEditors();
RimIntersectionResultsDefinitionCollection* interResDefColl = nullptr;
this->firstAncestorOrThisOfType( interResDefColl );
bool isInAction = isActive() && interResDefColl && interResDefColl->isActive();
auto interResDefColl = firstAncestorOrThisOfType<RimIntersectionResultsDefinitionCollection>();
bool isInAction = isActive() && interResDefColl && interResDefColl->isActive();
if ( changedField == &m_isActive || ( changedField == &m_timeStep && isInAction ) )
{
std::vector<PdmObject*> referringObjects;
this->objectsWithReferringPtrFieldsOfType( referringObjects );
std::vector<PdmObject*> referringObjects = objectsWithReferringPtrFieldsOfType<PdmObject>();
for ( auto* obj : referringObjects )
{
obj->updateConnectedEditors();
@@ -349,8 +346,7 @@ void RimIntersectionResultDefinition::fieldChangedByUi( const caf::PdmFieldHandl
if ( reDraw )
{
RimGridView* gridView = nullptr;
this->firstAncestorOrThisOfType( gridView );
auto gridView = firstAncestorOrThisOfType<RimGridView>();
if ( gridView ) gridView->scheduleCreateDisplayModelAndRedraw();
update2dIntersectionViews();
@@ -367,9 +363,7 @@ void RimIntersectionResultDefinition::update2dIntersectionViews()
// Update 2D Intersection views
updateCaseInResultDefinitions();
std::vector<RimExtrudedCurveIntersection*> intersections;
this->objectsWithReferringPtrFieldsOfType( intersections );
auto intersections = objectsWithReferringPtrFieldsOfType<RimExtrudedCurveIntersection>();
for ( auto intersection : intersections )
{
if ( intersection && intersection->correspondingIntersectionView() )
@@ -494,8 +488,7 @@ void RimIntersectionResultDefinition::updateCaseInResultDefinitions()
//--------------------------------------------------------------------------------------------------
bool RimIntersectionResultDefinition::isInAction() const
{
RimIntersectionResultsDefinitionCollection* interResDefColl = nullptr;
this->firstAncestorOrThisOfType( interResDefColl );
auto interResDefColl = firstAncestorOrThisOfType<RimIntersectionResultsDefinitionCollection>();
return isActive() && interResDefColl && interResDefColl->isActive();
}
@@ -61,7 +61,7 @@ bool RimIntersectionResultsDefinitionCollection::isActive() const
//--------------------------------------------------------------------------------------------------
std::vector<RimIntersectionResultDefinition*> RimIntersectionResultsDefinitionCollection::intersectionResultsDefinitions() const
{
return m_intersectionResultsDefs.children();
return m_intersectionResultsDefs.childrenByType();
}
//--------------------------------------------------------------------------------------------------
@@ -73,8 +73,7 @@ void RimIntersectionResultsDefinitionCollection::appendIntersectionResultDefinit
if ( interResDef->activeCase() == nullptr )
{
RimCase* ownerCase = nullptr;
this->firstAncestorOrThisOfType( ownerCase );
auto ownerCase = firstAncestorOrThisOfType<RimCase>();
interResDef->setActiveCase( ownerCase );
}
}
@@ -96,8 +95,7 @@ void RimIntersectionResultsDefinitionCollection::fieldChangedByUi( const caf::Pd
{
this->updateUiIconFromToggleField();
RimGridView* gridView = nullptr;
this->firstAncestorOrThisOfType( gridView );
auto gridView = firstAncestorOrThisOfType<RimGridView>();
if ( gridView ) gridView->scheduleCreateDisplayModelAndRedraw();
if ( intersectionResultsDefinitions().size() > 0 ) intersectionResultsDefinitions()[0]->update2dIntersectionViews();
}
@@ -116,8 +114,7 @@ void RimIntersectionResultsDefinitionCollection::initAfterRead()
void RimIntersectionResultsDefinitionCollection::onChildDeleted( caf::PdmChildArrayFieldHandle* childArray,
std::vector<caf::PdmObjectHandle*>& referringObjects )
{
RimGridView* gridView = nullptr;
this->firstAncestorOrThisOfType( gridView );
auto gridView = firstAncestorOrThisOfType<RimGridView>();
if ( gridView )
{
gridView->scheduleCreateDisplayModelAndRedraw();