Skip to content

Commit

Permalink
Fix conversion into new cross plot structure
Browse files Browse the repository at this point in the history
* Fix conversion into new cross plot structure
* Guard null pointer
* Create one multi plot per cross plot
  • Loading branch information
magnesj authored Sep 25, 2023
1 parent 8e5788b commit 55687c4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
33 changes: 15 additions & 18 deletions ApplicationLibCode/ProjectDataModel/RimMainPlotCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,34 +196,31 @@ void RimMainPlotCollection::initAfterRead()

// Move cross plots into summary plot collection
auto crossPlots = m_summaryCrossPlotCollection_OBSOLETE->plots();
if ( !crossPlots.empty() )
for ( auto crossPlot : crossPlots )
{
m_summaryCrossPlotCollection_OBSOLETE->removePlot( crossPlot );

auto* summaryMultiPlot = new RimSummaryMultiPlot;
summaryMultiPlot->setMultiPlotTitle( QString( "Multi Plot %1" ).arg( m_summaryMultiPlotCollection->multiPlots().size() + 1 ) );
summaryMultiPlot->setAsPlotMdiWindow();
m_summaryMultiPlotCollection->addSummaryMultiPlot( summaryMultiPlot );

for ( auto crossPlot : crossPlots )
{
m_summaryCrossPlotCollection_OBSOLETE->removePlot( crossPlot );
summaryMultiPlot->addPlot( crossPlot );

// We want to convert RimSummaryCrossPlot into a RimSummaryPlot. The cross plot is derived from RimSummaryPlot, but we need to
// create a new RimSummaryPlot to be able to store the PDM object as a RimSummaryPlot instead of RimSummaryCrossPlot
auto summaryPlot = new RimSummaryPlot;
summaryMultiPlot->addPlot( summaryPlot );

for ( auto curve : crossPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS ) )
{
crossPlot->removeCurve( curve );
// We want to convert RimSummaryCrossPlot into a RimSummaryPlot. The cross plot is derived from RimSummaryPlot, but we need to
// create a new RimSummaryPlot to be able to store the PDM object as a RimSummaryPlot instead of RimSummaryCrossPlot
auto summaryPlot = new RimSummaryPlot;
summaryMultiPlot->addPlot( summaryPlot );

if ( curve->summaryCaseX() != nullptr ) curve->setAxisTypeX( RiaDefines::HorizontalAxisType::SUMMARY_VECTOR );
for ( auto curve : crossPlot->allCurves( RimSummaryDataSourceStepping::Axis::Y_AXIS ) )
{
crossPlot->removeCurve( curve );

summaryPlot->insertCurve( curve, std::numeric_limits<size_t>::max() );
}
if ( curve->summaryCaseX() != nullptr ) curve->setAxisTypeX( RiaDefines::HorizontalAxisType::SUMMARY_VECTOR );

delete crossPlot;
summaryPlot->insertCurve( curve, std::numeric_limits<size_t>::max() );
summaryPlot->findOrAssignPlotAxisX( curve );
}

delete crossPlot;
}
}

Expand Down
45 changes: 34 additions & 11 deletions ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,11 @@ void RimSummaryPlot::copyAxisPropertiesFromOther( RiaDefines::PlotAxis plotAxisT

QString data = ap->writeObjectToXmlString();

axisPropertiesForPlotAxis( ap->plotAxis() )->readObjectFromXmlString( data, caf::PdmDefaultObjectFactory::instance() );
auto axisProperty = axisPropertiesForPlotAxis( ap->plotAxis() );
if ( axisProperty )
{
axisProperty->readObjectFromXmlString( data, caf::PdmDefaultObjectFactory::instance() );
}
}
}

Expand Down Expand Up @@ -1237,20 +1241,39 @@ void RimSummaryPlot::findOrAssignPlotAxisX( RimSummaryCurve* curve )
}
}

if ( curve->summaryCaseX() != nullptr && plotWidget() && plotWidget()->isMultiAxisSupported() )
if ( curve->summaryCaseX() != nullptr )
{
QString axisObjectName = "New Axis";
if ( !curve->summaryAddressX().uiText().empty() ) axisObjectName = QString::fromStdString( curve->summaryAddressX().uiText() );

RiuPlotAxis newPlotAxis = plotWidget()->createNextPlotAxis( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM );
addNewAxisProperties( newPlotAxis, axisObjectName );
if ( plotWidget() )
if ( !plotWidget() )
{
plotWidget()->ensureAxisIsCreated( newPlotAxis );
// Assign a default bottom axis if no plot widget is present. This can happens during project load and transformation to new
// cross plot structure in RimMainPlotCollection::initAfterRead()

QString axisObjectName = "New Axis";
if ( !curve->summaryAddressX().uiText().empty() ) axisObjectName = QString::fromStdString( curve->summaryAddressX().uiText() );

RiuPlotAxis newPlotAxis = RiuPlotAxis::defaultBottomForSummaryVectors();
addNewAxisProperties( newPlotAxis, axisObjectName );

curve->setTopOrBottomAxisX( newPlotAxis );

return;
}

updateAxes();
curve->setTopOrBottomAxisX( newPlotAxis );
if ( plotWidget()->isMultiAxisSupported() )
{
QString axisObjectName = "New Axis";
if ( !curve->summaryAddressX().uiText().empty() ) axisObjectName = QString::fromStdString( curve->summaryAddressX().uiText() );

RiuPlotAxis newPlotAxis = plotWidget()->createNextPlotAxis( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM );
addNewAxisProperties( newPlotAxis, axisObjectName );
if ( plotWidget() )
{
plotWidget()->ensureAxisIsCreated( newPlotAxis );
}

updateAxes();
curve->setTopOrBottomAxisX( newPlotAxis );
}
}
}

Expand Down

0 comments on commit 55687c4

Please sign in to comment.