Skip to content

Commit

Permalink
Fix firstAncestorOfType usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
kriben committed Mar 22, 2024
1 parent 353febb commit 0f703b6
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "RicPasteFeatureImpl.h"

#include "Rim3dView.h"
#include "RimCase.h"
#include "RimCellFilter.h"
#include "RimCellFilterCollection.h"
Expand All @@ -42,17 +43,9 @@ bool RicPasteCellFiltersFeature::isCommandEnabled() const

std::vector<caf::PdmPointer<RimCellFilter>> typedObjects;
objectGroup.objectsByType( &typedObjects );
if ( typedObjects.empty() )
{
return false;
}

if ( dynamic_cast<RimCellFilterCollection*>( caf::SelectionManager::instance()->selectedItem() ) )
{
return true;
}
if ( typedObjects.empty() ) return false;

return false;
return dynamic_cast<RimCellFilterCollection*>( caf::SelectionManager::instance()->selectedItem() ) != nullptr;
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -63,7 +56,11 @@ void RicPasteCellFiltersFeature::onActionTriggered( bool isChecked )
auto cellFilterCollection = dynamic_cast<RimCellFilterCollection*>( caf::SelectionManager::instance()->selectedItem() );
if ( !cellFilterCollection ) return;

auto eclipseCase = cellFilterCollection->firstAncestorOfType<RimCase>();
auto view = cellFilterCollection->firstAncestorOfType<Rim3dView>();
if ( !view ) return;

auto eclipseCase = view->ownerCase();
if ( !eclipseCase ) return;

caf::PdmObjectGroup objectGroup;
RicPasteFeatureImpl::findObjectsFromClipboardRefs( &objectGroup );
Expand Down
5 changes: 2 additions & 3 deletions ApplicationLibCode/Commands/RicVec3dPickEventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ bool RicVec3dPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eventObj

cvf::Vec3d pickedPosition = eventObject.m_pickItemInfos.front().globalPickedPoint();

RimCase* ownerCase = rimView->firstAncestorOrThisOfType<RimCase>();
if ( ownerCase )
if ( rimView->ownerCase() )
{
double zPickOffset = ownerCase->characteristicCellSize() * m_zOffsetFactor;
double zPickOffset = rimView->ownerCase()->characteristicCellSize() * m_zOffsetFactor;
pickedPosition.z() += zPickOffset;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ void RivWellPathPartMgr::appendPerforationsToModel( cvf::ModelBasicList*
QDateTime currentTimeStamp;
if ( m_rimView )
{
auto rimCase = m_rimView->firstAncestorOrThisOfType<RimCase>();
auto rimCase = m_rimView->ownerCase();

if ( rimCase )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,13 @@ void RivSurfacePartMgr::generatePartGeometry()
void RivSurfacePartMgr::generateNativePartGeometry()
{
cvf::Vec3d displayModOffset( 0, 0, 0 );
auto ownerCase = m_surfaceInView->firstAncestorOrThisOfType<RimCase>();
if ( ownerCase ) displayModOffset = ownerCase->displayModelOffset();

auto view = m_surfaceInView->firstAncestorOrThisOfType<Rim3dView>();
if ( view )
{
auto ownerCase = view->ownerCase();
if ( ownerCase ) displayModOffset = ownerCase->displayModelOffset();
}

m_usedSurfaceData = m_surfaceInView->surface()->surfaceData();
if ( m_usedSurfaceData.isNull() ) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,19 @@ void RimAnnotationInViewCollection::defineEditorAttribute( const caf::PdmFieldHa

if ( attr )
{
auto rimCase = firstAncestorOrThisOfType<RimCase>();
if ( rimCase )
if ( auto view = firstAncestorOrThisOfType<Rim3dView>() )
{
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;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RimCase>();
auto rimView = firstAncestorOrThisOfType<Rim3dView>();
if ( rimView == nullptr ) return;

auto rimCase = rimView->ownerCase();
if ( rimCase == nullptr ) return;

for ( const auto& filter : m_cellFilters )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ void RimIntersectionResultsDefinitionCollection::appendIntersectionResultDefinit

if ( interResDef->activeCase() == nullptr )
{
auto ownerCase = firstAncestorOrThisOfType<RimCase>();
interResDef->setActiveCase( ownerCase );
if ( auto gridView = firstAncestorOrThisOfType<Rim3dView>() )
{
if ( auto ownerCase = gridView->ownerCase() )
{
interResDef->setActiveCase( ownerCase );
}
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions ApplicationLibCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,12 +1013,14 @@ void Rim3dOverlayInfoConfig::updateSeismicInfo( RimSeismicView* seisView )
//--------------------------------------------------------------------------------------------------
void Rim3dOverlayInfoConfig::update3DInfoIn2dViews() const
{
RimCase* rimCase = firstAncestorOrThisOfType<RimCase>();
if ( rimCase )
if ( auto rimView = firstAncestorOrThisOfType<Rim3dView>() )
{
for ( Rim2dIntersectionView* view : rimCase->intersectionViewCollection()->views() )
if ( RimCase* rimCase = rimView->ownerCase() )
{
view->update3dInfo();
for ( Rim2dIntersectionView* view : rimCase->intersectionViewCollection()->views() )
{
view->update3dInfo();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void RiuAdvancedSnapshotExportWidget::addSnapshotItemFromActiveView()
multiSnapshot->timeStepStart = activeView->currentTimeStep();
multiSnapshot->timeStepEnd = activeView->currentTimeStep();

auto sourceCase = activeView->firstAncestorOrThisOfType<RimCase>();
auto sourceCase = activeView->ownerCase();
if ( sourceCase )
{
multiSnapshot->additionalCases().push_back( sourceCase );
Expand Down

0 comments on commit 0f703b6

Please sign in to comment.