From 0f703b63f5b50c96ff773cf022489ef43701e4c3 Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 22 Mar 2024 10:40:25 +0100 Subject: [PATCH] Fix firstAncestorOfType usage. --- .../RicPasteCellFiltersFeature.cpp | 19 +++++++--------- .../Commands/RicVec3dPickEventHandler.cpp | 5 ++--- .../ModelVisualization/RivWellPathPartMgr.cpp | 2 +- .../Surfaces/RivSurfacePartMgr.cpp | 9 ++++++-- .../RimAnnotationInViewCollection.cpp | 22 ++++++++++--------- .../CellFilters/RimCellFilterCollection.cpp | 5 ++++- ...ntersectionResultsDefinitionCollection.cpp | 9 ++++++-- .../Rim3dOverlayInfoConfig.cpp | 10 +++++---- .../RiuAdvancedSnapshotExportWidget.cpp | 2 +- 9 files changed, 48 insertions(+), 35 deletions(-) diff --git a/ApplicationLibCode/Commands/OperationsUsingObjReferences/RicPasteCellFiltersFeature.cpp b/ApplicationLibCode/Commands/OperationsUsingObjReferences/RicPasteCellFiltersFeature.cpp index c809985609c..d2b68bd0858 100644 --- a/ApplicationLibCode/Commands/OperationsUsingObjReferences/RicPasteCellFiltersFeature.cpp +++ b/ApplicationLibCode/Commands/OperationsUsingObjReferences/RicPasteCellFiltersFeature.cpp @@ -20,6 +20,7 @@ #include "RicPasteFeatureImpl.h" +#include "Rim3dView.h" #include "RimCase.h" #include "RimCellFilter.h" #include "RimCellFilterCollection.h" @@ -42,17 +43,9 @@ bool RicPasteCellFiltersFeature::isCommandEnabled() const std::vector> typedObjects; objectGroup.objectsByType( &typedObjects ); - if ( typedObjects.empty() ) - { - return false; - } - - if ( dynamic_cast( caf::SelectionManager::instance()->selectedItem() ) ) - { - return true; - } + if ( typedObjects.empty() ) return false; - return false; + return dynamic_cast( caf::SelectionManager::instance()->selectedItem() ) != nullptr; } //-------------------------------------------------------------------------------------------------- @@ -63,7 +56,11 @@ void RicPasteCellFiltersFeature::onActionTriggered( bool isChecked ) auto cellFilterCollection = dynamic_cast( caf::SelectionManager::instance()->selectedItem() ); if ( !cellFilterCollection ) return; - auto eclipseCase = cellFilterCollection->firstAncestorOfType(); + auto view = cellFilterCollection->firstAncestorOfType(); + if ( !view ) return; + + auto eclipseCase = view->ownerCase(); + if ( !eclipseCase ) return; caf::PdmObjectGroup objectGroup; RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup ); diff --git a/ApplicationLibCode/Commands/RicVec3dPickEventHandler.cpp b/ApplicationLibCode/Commands/RicVec3dPickEventHandler.cpp index 995f59c40ba..652a0e772fe 100644 --- a/ApplicationLibCode/Commands/RicVec3dPickEventHandler.cpp +++ b/ApplicationLibCode/Commands/RicVec3dPickEventHandler.cpp @@ -42,10 +42,9 @@ bool RicVec3dPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eventObj cvf::Vec3d pickedPosition = eventObject.m_pickItemInfos.front().globalPickedPoint(); - RimCase* ownerCase = rimView->firstAncestorOrThisOfType(); - if ( ownerCase ) + if ( rimView->ownerCase() ) { - double zPickOffset = ownerCase->characteristicCellSize() * m_zOffsetFactor; + double zPickOffset = rimView->ownerCase()->characteristicCellSize() * m_zOffsetFactor; pickedPosition.z() += zPickOffset; } diff --git a/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp index 8b84699cb00..97dfdaaf22d 100644 --- a/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivWellPathPartMgr.cpp @@ -388,7 +388,7 @@ void RivWellPathPartMgr::appendPerforationsToModel( cvf::ModelBasicList* QDateTime currentTimeStamp; if ( m_rimView ) { - auto rimCase = m_rimView->firstAncestorOrThisOfType(); + auto rimCase = m_rimView->ownerCase(); if ( rimCase ) { diff --git a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp index 36ab921eb7f..42d72709e2a 100644 --- a/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/Surfaces/RivSurfacePartMgr.cpp @@ -382,8 +382,13 @@ void RivSurfacePartMgr::generatePartGeometry() void RivSurfacePartMgr::generateNativePartGeometry() { cvf::Vec3d displayModOffset( 0, 0, 0 ); - auto ownerCase = m_surfaceInView->firstAncestorOrThisOfType(); - if ( ownerCase ) displayModOffset = ownerCase->displayModelOffset(); + + auto view = m_surfaceInView->firstAncestorOrThisOfType(); + if ( view ) + { + auto ownerCase = view->ownerCase(); + if ( ownerCase ) displayModOffset = ownerCase->displayModelOffset(); + } m_usedSurfaceData = m_surfaceInView->surface()->surfaceData(); if ( m_usedSurfaceData.isNull() ) return; diff --git a/ApplicationLibCode/ProjectDataModel/Annotations/RimAnnotationInViewCollection.cpp b/ApplicationLibCode/ProjectDataModel/Annotations/RimAnnotationInViewCollection.cpp index b8234e9da96..55d43e08cdf 100644 --- a/ApplicationLibCode/ProjectDataModel/Annotations/RimAnnotationInViewCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Annotations/RimAnnotationInViewCollection.cpp @@ -279,17 +279,19 @@ void RimAnnotationInViewCollection::defineEditorAttribute( const caf::PdmFieldHa if ( attr ) { - auto rimCase = firstAncestorOrThisOfType(); - if ( rimCase ) + if ( auto view = firstAncestorOrThisOfType() ) { - auto bb = rimCase->allCellsBoundingBox(); - attr->m_minimum = -bb.max().z(); - attr->m_maximum = -bb.min().z(); - } - else - { - attr->m_minimum = 0; - attr->m_maximum = 10000; + if ( auto rimCase = view->ownerCase() ) + { + auto bb = rimCase->allCellsBoundingBox(); + attr->m_minimum = -bb.max().z(); + attr->m_maximum = -bb.min().z(); + } + else + { + attr->m_minimum = 0; + attr->m_maximum = 10000; + } } } } diff --git a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp index 5fe2bb0774a..a2074e16a4f 100644 --- a/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/CellFilters/RimCellFilterCollection.cpp @@ -160,7 +160,10 @@ void RimCellFilterCollection::initAfterRead() // Copy by xml serialization does not give a RimCase parent the first time initAfterRead is called here when creating a new a contour // view from a 3d view. The second time we get called it is ok, so just skip setting up the filter connections if we have no case. - auto rimCase = firstAncestorOrThisOfType(); + auto rimView = firstAncestorOrThisOfType(); + if ( rimView == nullptr ) return; + + auto rimCase = rimView->ownerCase(); if ( rimCase == nullptr ) return; for ( const auto& filter : m_cellFilters ) diff --git a/ApplicationLibCode/ProjectDataModel/Intersections/RimIntersectionResultsDefinitionCollection.cpp b/ApplicationLibCode/ProjectDataModel/Intersections/RimIntersectionResultsDefinitionCollection.cpp index adaa8a426c0..2769f569bb2 100644 --- a/ApplicationLibCode/ProjectDataModel/Intersections/RimIntersectionResultsDefinitionCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Intersections/RimIntersectionResultsDefinitionCollection.cpp @@ -72,8 +72,13 @@ void RimIntersectionResultsDefinitionCollection::appendIntersectionResultDefinit if ( interResDef->activeCase() == nullptr ) { - auto ownerCase = firstAncestorOrThisOfType(); - interResDef->setActiveCase( ownerCase ); + if ( auto gridView = firstAncestorOrThisOfType() ) + { + if ( auto ownerCase = gridView->ownerCase() ) + { + interResDef->setActiveCase( ownerCase ); + } + } } } diff --git a/ApplicationLibCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp b/ApplicationLibCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp index d81b5199163..86f6ef7e2ec 100644 --- a/ApplicationLibCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp +++ b/ApplicationLibCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp @@ -1013,12 +1013,14 @@ void Rim3dOverlayInfoConfig::updateSeismicInfo( RimSeismicView* seisView ) //-------------------------------------------------------------------------------------------------- void Rim3dOverlayInfoConfig::update3DInfoIn2dViews() const { - RimCase* rimCase = firstAncestorOrThisOfType(); - if ( rimCase ) + if ( auto rimView = firstAncestorOrThisOfType() ) { - for ( Rim2dIntersectionView* view : rimCase->intersectionViewCollection()->views() ) + if ( RimCase* rimCase = rimView->ownerCase() ) { - view->update3dInfo(); + for ( Rim2dIntersectionView* view : rimCase->intersectionViewCollection()->views() ) + { + view->update3dInfo(); + } } } } diff --git a/ApplicationLibCode/UserInterface/RiuAdvancedSnapshotExportWidget.cpp b/ApplicationLibCode/UserInterface/RiuAdvancedSnapshotExportWidget.cpp index f4ea30066ee..98898040581 100644 --- a/ApplicationLibCode/UserInterface/RiuAdvancedSnapshotExportWidget.cpp +++ b/ApplicationLibCode/UserInterface/RiuAdvancedSnapshotExportWidget.cpp @@ -147,7 +147,7 @@ void RiuAdvancedSnapshotExportWidget::addSnapshotItemFromActiveView() multiSnapshot->timeStepStart = activeView->currentTimeStep(); multiSnapshot->timeStepEnd = activeView->currentTimeStep(); - auto sourceCase = activeView->firstAncestorOrThisOfType(); + auto sourceCase = activeView->ownerCase(); if ( sourceCase ) { multiSnapshot->additionalCases().push_back( sourceCase );