Skip to content
Merged
58 changes: 46 additions & 12 deletions ApplicationLibCode/Commands/RicHistogramPlotTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#include "RiuPlotMainWindow.h"
#include "RiuPlotMainWindowTools.h"

#include "cafAssert.h"

namespace caf
{
template <>
Expand Down Expand Up @@ -68,6 +66,8 @@ std::vector<RicHistogramPlotTools::DataSourceType> RicHistogramPlotTools::allDat
//--------------------------------------------------------------------------------------------------
void RicHistogramPlotTools::createDefaultHistogramCurve( RimHistogramPlot* plot, RicHistogramPlotTools::DataSourceType dataSourceType )
{
if ( !plot ) return;

auto getDataSourceFromType = []( DataSourceType dataSourceType ) -> RimHistogramDataSource*
{
if ( dataSourceType == DataSourceType::ENSEMBLE_PARAMETER )
Expand All @@ -82,18 +82,27 @@ void RicHistogramPlotTools::createDefaultHistogramCurve( RimHistogramPlot* plot,
};

RimHistogramDataSource* dataSource = getDataSourceFromType( dataSourceType );
if ( !dataSource ) return;

dataSource->setDefaults();
return createHistogramCurve( plot, dataSource );
createHistogramCurve( plot, dataSource );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicHistogramPlotTools::createHistogramCurve( RimHistogramPlot* plot, RimHistogramDataSource* dataSource )
{
RiaGuiApplication* app = RiaGuiApplication::instance();
RimProject* project = app->project();
CAF_ASSERT( project );
if ( !plot || !dataSource ) return;

// RiaGuiApplication::instance() asserts internally if called when there is no running GUI
// application, so check isRunning() first instead of relying on a null check of instance().
if ( !RiaGuiApplication::isRunning() ) return;

RiaGuiApplication* app = RiaGuiApplication::instance();

RimProject* project = app->project();
if ( !project ) return;

RimHistogramCurve* newCurve = new RimHistogramCurve();

Expand All @@ -112,7 +121,10 @@ void RicHistogramPlotTools::createHistogramCurve( RimHistogramPlot* plot, RimHis
//--------------------------------------------------------------------------------------------------
RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot()
{
auto collection = RimMainPlotCollection::current()->histogramMultiPlotCollection();
auto mainPlotCollection = RimMainPlotCollection::current();
if ( !mainPlotCollection ) return nullptr;

auto collection = mainPlotCollection->histogramMultiPlotCollection();
if ( !collection ) return nullptr;

return addNewHistogramMultiplot( collection );
Expand All @@ -123,9 +135,10 @@ RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot()
//--------------------------------------------------------------------------------------------------
RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot( RimHistogramMultiPlotCollection* collection )
{
CAF_ASSERT( collection );
if ( !collection ) return nullptr;

RimHistogramMultiPlot* multiplot = collection->appendHistogramMultiPlot();
if ( !multiplot ) return nullptr;
multiplot->dockAsPlotWindow();
multiplot->setShowWindow( true );
multiplot->loadDataAndUpdate();
Expand All @@ -141,6 +154,8 @@ RimHistogramMultiPlot* RicHistogramPlotTools::addNewHistogramMultiplot( RimHisto
//--------------------------------------------------------------------------------------------------
RimHistogramPlot* RicHistogramPlotTools::addNewHistogramPlot( RimHistogramMultiPlot* histogramMultiPlot )
{
if ( !histogramMultiPlot ) return nullptr;

RimHistogramPlot* plot = new RimHistogramPlot();
plot->enableAutoPlotTitle( true );
histogramMultiPlot->addPlot( plot );
Expand All @@ -156,10 +171,16 @@ RimHistogramPlot* RicHistogramPlotTools::addNewHistogramPlot( RimHistogramMultiP
std::vector<RimHistogramDataSource*> RicHistogramPlotTools::existingDataSources( RimHistogramPlot* plot )
{
std::vector<RimHistogramDataSource*> sources;
if ( !plot ) return sources;

for ( auto curve : plot->histogramCurves() )
{
sources.push_back( curve->dataSource() );
if ( !curve ) continue;

if ( auto source = curve->dataSource() )
{
sources.push_back( source );
}
}

return sources;
Expand All @@ -170,6 +191,8 @@ std::vector<RimHistogramDataSource*> RicHistogramPlotTools::existingDataSources(
//--------------------------------------------------------------------------------------------------
void RicHistogramPlotTools::appendEnsembleParameterHistogramCurve( RimHistogramPlot* plot, RimEnsembleParameterHistogramDataSource* dataSource )
{
if ( !plot || !dataSource ) return;

for ( auto source : existingDataSources( plot ) )
{
if ( auto histSource = dynamic_cast<RimEnsembleParameterHistogramDataSource*>( source ) )
Expand All @@ -190,8 +213,15 @@ void RicHistogramPlotTools::appendEnsembleParameterHistogramCurve( RimHistogramP
//--------------------------------------------------------------------------------------------------
void RicHistogramPlotTools::addHistogramCurveToPlot( RimHistogramPlot* plot, RimHistogramCurve* curve, bool resolveRefs )
{
RiaGuiApplication* app = RiaGuiApplication::instance();
RimProject* project = app->project();
if ( !plot || !curve ) return;

// RiaGuiApplication::instance() asserts internally if called when there is no running GUI
// application, so check isRunning() first instead of relying on a null check of instance().
if ( !RiaGuiApplication::isRunning() ) return;

RiaGuiApplication* app = RiaGuiApplication::instance();

RimProject* project = app->project();
if ( project == nullptr ) return;

plot->addCurveNoUpdate( curve );
Expand All @@ -202,7 +232,7 @@ void RicHistogramPlotTools::addHistogramCurveToPlot( RimHistogramPlot* plot, Rim
plot->updateConnectedEditors();

RiuPlotMainWindow* mainPlotWindow = app->mainPlotWindow();
mainPlotWindow->updateMultiPlotToolBar();
if ( mainPlotWindow ) mainPlotWindow->updateMultiPlotToolBar();

RiuPlotMainWindowTools::onObjectAppended( curve, plot );
}
Expand All @@ -213,6 +243,7 @@ void RicHistogramPlotTools::addHistogramCurveToPlot( RimHistogramPlot* plot, Rim
std::set<QString> RicHistogramPlotTools::existingEnsembleParameters( RimHistogramPlot* plot )
{
std::set<QString> foundParameters;
if ( !plot ) return foundParameters;

for ( auto source : existingDataSources( plot ) )
{
Expand All @@ -231,6 +262,7 @@ std::set<QString> RicHistogramPlotTools::existingEnsembleParameters( RimHistogra
std::set<std::pair<RifEclipseSummaryAddress, QDateTime>> RicHistogramPlotTools::existingSummaryVectors( RimHistogramPlot* plot )
{
std::set<std::pair<RifEclipseSummaryAddress, QDateTime>> foundVectors;
if ( !plot ) return foundVectors;

for ( auto source : existingDataSources( plot ) )
{
Expand All @@ -248,6 +280,8 @@ std::set<std::pair<RifEclipseSummaryAddress, QDateTime>> RicHistogramPlotTools::
//--------------------------------------------------------------------------------------------------
void RicHistogramPlotTools::appendEnsembleToHistogram( RimHistogramPlot* plot, RimSummaryEnsemble* ensemble )
{
if ( !plot || !ensemble ) return;

auto currentParameters = existingEnsembleParameters( plot );
auto currentVectors = existingSummaryVectors( plot );

Expand Down
16 changes: 16 additions & 0 deletions ApplicationLibCode/FeatureTests/Tests/RiuQwtPlotWidget-Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,19 @@ TEST( RiuQwtPlotWidget, PruneAxesKeepsAxisMappingValid )

plotWidget.enableAxisNumberLabels( RiuPlotAxis::defaultLeft(), true );
}

//--------------------------------------------------------------------------------------------------
/// Reproduces the crash reported in RiuMultiPlotPage::setDefaultAxisProperties(): pruning all axes
/// (e.g. when an axis properties object is deleted) can drop the default left axis from the axis
/// mapping. setAxisLabelsAndTicksEnabled() is then called directly, without an enableAxis() call to
/// heal the mapping first, so it must not rely on the mapping already being valid.
//--------------------------------------------------------------------------------------------------
TEST( RiuQwtPlotWidget, SetAxisLabelsAndTicksEnabledAfterPruneAxesDoesNotCrash )
{
RiuQwtPlotWidget plotWidget( nullptr );

plotWidget.ensureAxisIsCreated( RiuPlotAxis( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, 1 ) );
plotWidget.pruneAxes( {} );

plotWidget.setAxisLabelsAndTicksEnabled( RiuPlotAxis::defaultLeft(), true, true );
}
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void RimHistogramCurve::loadAndUpdateDataAndPlot()
plot->updateConnectedEditors();

RiuPlotMainWindow* mainPlotWindow = RiaGuiApplication::instance()->mainPlotWindow();
mainPlotWindow->updateMultiPlotToolBar();
if ( mainPlotWindow ) mainPlotWindow->updateMultiPlotToolBar();

dataChanged.send();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,16 @@ void RimIntersectionCollection::appendIntersectionNoUpdate( RimExtrudedCurveInte
//--------------------------------------------------------------------------------------------------
void RimIntersectionCollection::synchronize2dIntersectionViews()
{
auto ownerCase = firstAncestorOrThisOfTypeAsserted<Rim3dView>()->ownerCase();
ownerCase->intersectionViewCollection()->syncFromExistingIntersections( true );
auto ownerView = firstAncestorOrThisOfType<Rim3dView>();
if ( !ownerView ) return;

auto ownerCase = ownerView->ownerCase();
if ( !ownerCase ) return;

auto intersectionViewCollection = ownerCase->intersectionViewCollection();
if ( !intersectionViewCollection ) return;

intersectionViewCollection->syncFromExistingIntersections( true );
}

//--------------------------------------------------------------------------------------------------
Expand Down
15 changes: 14 additions & 1 deletion ApplicationLibCode/ProjectDataModel/RimDockWindowController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ RimDockWindowController::~RimDockWindowController()
//--------------------------------------------------------------------------------------------------
void RimDockWindowController::handleViewerDeletion()
{
if ( !viewPdmObject() ) return;

viewPdmObject()->m_showWindow = false;
viewPdmObject()->updateConnectedEditors();
viewPdmObject()->updateUiIconFromToggleField();
Expand Down Expand Up @@ -130,8 +132,19 @@ void RimDockWindowController::updateViewerWidget()
{
if ( !viewWidget() )
{
// Create the view widget first: if it fails, nothing has been allocated yet. Creating the
// dock widget first and having view widget creation fail afterwards would otherwise leave a
// dock widget without a dock manager, which deleteDockWidget() cannot clean up.
QWidget* viewWidget = viewPdmObject()->createViewWidget();
if ( !viewWidget ) return;

ads::CDockWidget* dockWidget = viewPdmObject()->createDockWidget();
QWidget* viewWidget = viewPdmObject()->createViewWidget();
if ( !dockWidget )
{
viewPdmObject()->deleteViewWidget();
return;
}

dockWidget->setWidget( viewWidget );
dockWidget->setObjectName( viewPdmObject()->dockWindowName() );
viewWidget->setObjectName( viewPdmObject()->dockWindowName() );
Expand Down
45 changes: 34 additions & 11 deletions ApplicationLibCode/ProjectDataModel/RimViewController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ RimGeoMechView* RimViewController::managedGeoView() const
void RimViewController::updateOverrides()
{
RimViewLinker* viewLinker = ownerViewLinker();
if ( !viewLinker ) return;

auto masterView = viewLinker->masterView();

Expand Down Expand Up @@ -511,6 +512,7 @@ void RimViewController::updateDuplicatedPropertyFilters()
}

RimViewLinker* viewLinker = ownerViewLinker();
if ( !viewLinker ) return;

auto masterView = viewLinker->masterView();

Expand Down Expand Up @@ -555,9 +557,13 @@ void RimViewController::updateCameraLink()
if ( m_managedView )
{
RimViewLinker* viewLinker = ownerViewLinker();
if ( !viewLinker ) return;

viewLinker->updateScaleZ( viewLinker->masterView(), viewLinker->masterView()->scaleZ() );
viewLinker->updateCamera( viewLinker->masterView() );
Rim3dView* masterView = viewLinker->masterView();
if ( !masterView ) return;

viewLinker->updateScaleZ( masterView, masterView->scaleZ() );
viewLinker->updateCamera( masterView );
}
}

Expand All @@ -571,8 +577,12 @@ void RimViewController::updateTimeStepLink()
if ( m_managedView )
{
RimViewLinker* viewLinker = ownerViewLinker();
if ( !viewLinker ) return;

Rim3dView* masterView = viewLinker->masterView();
if ( !masterView ) return;

viewLinker->updateTimeStep( viewLinker->masterView(), viewLinker->masterView()->currentTimeStep() );
viewLinker->updateTimeStep( masterView, masterView->currentTimeStep() );
}
}

Expand All @@ -584,6 +594,7 @@ void RimViewController::updateResultColorsControl()
if ( !isResultColorControlled() ) return;

RimViewLinker* viewLinker = ownerViewLinker();
if ( !viewLinker ) return;
viewLinker->updateCellResult();
}

Expand All @@ -595,6 +606,7 @@ void RimViewController::updateLegendDefinitions()
if ( !isLegendDefinitionsControlled() ) return;

RimViewLinker* viewLinker = ownerViewLinker();
if ( !viewLinker ) return;
viewLinker->updateCellResult();
}

Expand Down Expand Up @@ -683,7 +695,10 @@ const RigCaseToCaseCellMapper* RimViewController::cellMapper()
//--------------------------------------------------------------------------------------------------
Rim3dView* RimViewController::masterView() const
{
return ownerViewLinker()->masterView();
RimViewLinker* viewLinker = ownerViewLinker();
if ( !viewLinker ) return nullptr;

return viewLinker->masterView();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -755,15 +770,17 @@ void RimViewController::scheduleGeometryRegenForDepViews( RivCellSetEnum geometr
//--------------------------------------------------------------------------------------------------
bool RimViewController::isActive() const
{
return ownerViewLinker()->isActive() && isChecked();
RimViewLinker* viewLinker = ownerViewLinker();
return viewLinker && viewLinker->isActive() && isChecked();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimViewController::isCameraLinked() const
{
if ( ownerViewLinker()->isActive() && isChecked() )
RimViewLinker* viewLinker = ownerViewLinker();
if ( viewLinker && viewLinker->isActive() && isChecked() )
{
return m_syncCamera;
}
Expand All @@ -784,7 +801,8 @@ bool RimViewController::showCursor() const
//--------------------------------------------------------------------------------------------------
bool RimViewController::isTimeStepLinked() const
{
if ( ownerViewLinker()->isActive() && isChecked() )
RimViewLinker* viewLinker = ownerViewLinker();
if ( viewLinker && viewLinker->isActive() && isChecked() )
{
return m_syncTimeStep;
}
Expand All @@ -797,7 +815,8 @@ bool RimViewController::isTimeStepLinked() const
//--------------------------------------------------------------------------------------------------
bool RimViewController::isResultColorControlled() const
{
if ( ownerViewLinker()->isActive() && isChecked() )
RimViewLinker* viewLinker = ownerViewLinker();
if ( viewLinker && viewLinker->isActive() && isChecked() )
{
return m_syncCellResult;
}
Expand All @@ -810,7 +829,8 @@ bool RimViewController::isResultColorControlled() const
//--------------------------------------------------------------------------------------------------
bool RimViewController::isLegendDefinitionsControlled() const
{
if ( ownerViewLinker()->isActive() && isChecked() )
RimViewLinker* viewLinker = ownerViewLinker();
if ( viewLinker && viewLinker->isActive() && isChecked() )
{
return m_syncLegendDefinitions;
}
Expand Down Expand Up @@ -939,7 +959,8 @@ bool RimViewController::isPropertyFilterOveridden() const
{
if ( !isPropertyFilterControlPossible() ) return false;

if ( ownerViewLinker()->isActive() && isChecked() )
RimViewLinker* viewLinker = ownerViewLinker();
if ( viewLinker && viewLinker->isActive() && isChecked() )
{
return m_syncPropertyFilters;
}
Expand Down Expand Up @@ -1093,7 +1114,9 @@ void RimViewController::applyCellFilterCollectionByUserChoice()
}

RimViewLinker* viewLinker = ownerViewLinker();
auto* masterView = dynamic_cast<RimGridView*>( viewLinker->masterView() );
if ( !viewLinker ) return;

auto* masterView = dynamic_cast<RimGridView*>( viewLinker->masterView() );

bool anyActiveCellFilter = false;

Expand Down
Loading