Merge pull request #8754 from OPM/multiplot_improvements

Summary Multiplot: add new plot from a single curve in an ensemble plot and improve general plot performance
This commit is contained in:
jonjenssen 2022-03-31 12:34:07 +02:00 committed by GitHub
parent 2eb1713866
commit ebba37a623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 227 additions and 39 deletions

View File

@ -204,4 +204,24 @@ enum class RowCount
ROWS_4 = 4,
};
enum class MultiPlotPageUpdateType : uint32_t
{
NONE = 0b0000,
LEGEND = 0b0001,
PLOT = 0b0010,
ALL = 0b0011
};
constexpr enum MultiPlotPageUpdateType operator|( const enum MultiPlotPageUpdateType selfValue,
const enum MultiPlotPageUpdateType inValue )
{
return ( enum MultiPlotPageUpdateType )( uint32_t( selfValue ) | uint32_t( inValue ) );
}
constexpr enum MultiPlotPageUpdateType operator&( const enum MultiPlotPageUpdateType selfValue,
const enum MultiPlotPageUpdateType inValue )
{
return ( enum MultiPlotPageUpdateType )( uint32_t( selfValue ) & uint32_t( inValue ) );
}
}; // namespace RiaDefines

View File

@ -51,9 +51,17 @@ void RiaPlotWindowRedrawScheduler::scheduleMultiPlotWindowUpdate( RiuMultiPlotBo
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaPlotWindowRedrawScheduler::scheduleMultiPlotPageUpdate( RiuMultiPlotPage* plotPage )
void RiaPlotWindowRedrawScheduler::scheduleMultiPlotPageUpdate( RiuMultiPlotPage* plotPage,
RiaDefines::MultiPlotPageUpdateType updateType )
{
m_plotPagesToUpdate.push_back( plotPage );
if ( m_plotPagesToUpdate.count( plotPage ) == 0 )
{
m_plotPagesToUpdate[plotPage] = updateType;
}
else
{
m_plotPagesToUpdate[plotPage] = m_plotPagesToUpdate[plotPage] | updateType;
}
startTimer( 0 );
}
@ -90,17 +98,16 @@ void RiaPlotWindowRedrawScheduler::clearAllScheduledUpdates()
//--------------------------------------------------------------------------------------------------
void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots()
{
std::vector<QPointer<RiuMultiPlotBook>> plotWindowsToUpdate;
std::vector<QPointer<RiuMultiPlotPage>> plotPagesToUpdate;
std::vector<QPointer<RiuPlotWidget>> plotWidgetsToReplot;
std::vector<QPointer<RiuMultiPlotBook>> plotWindowsToUpdate;
std::vector<QPointer<RiuPlotWidget>> plotWidgetsToReplot;
std::map<QPointer<RiuMultiPlotPage>, RiaDefines::MultiPlotPageUpdateType> pagesToUpdate;
pagesToUpdate.swap( m_plotPagesToUpdate );
plotWindowsToUpdate.swap( m_plotWindowsToUpdate );
plotPagesToUpdate.swap( m_plotPagesToUpdate );
plotWidgetsToReplot.swap( m_plotWidgetsToReplot );
std::set<QPointer<RiuPlotWidget>> updatedPlots;
std::set<QPointer<RiuMultiPlotBook>> updatedPlotWindows;
std::set<QPointer<RiuMultiPlotPage>> updatedPlotPages;
for ( QPointer<RiuMultiPlotBook> plotWindow : plotWindowsToUpdate )
{
@ -108,8 +115,7 @@ void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots()
{
for ( RiuMultiPlotPage* page : plotWindow->pages() )
{
plotPagesToUpdate.erase( std::remove( plotPagesToUpdate.begin(), plotPagesToUpdate.end(), page ),
plotPagesToUpdate.end() );
if ( pagesToUpdate.count( page ) > 0 ) pagesToUpdate.erase( page );
}
plotWindow->performUpdate();
@ -117,16 +123,13 @@ void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots()
}
}
for ( QPointer<RiuMultiPlotPage> plotPage : plotPagesToUpdate )
for ( auto& [page, updateType] : pagesToUpdate )
{
if ( !plotPage.isNull() && !updatedPlotPages.count( plotPage ) )
{
plotPage->performUpdate();
updatedPlotPages.insert( plotPage );
}
if ( page.isNull() ) continue;
page->performUpdate( updateType );
}
// Perform update and replot. Make sure we handle legend update
for ( QPointer<RiuPlotWidget> plot : plotWidgetsToReplot )
{
if ( !plot.isNull() && !updatedPlots.count( plot ) )

View File

@ -19,11 +19,14 @@
#include "cafPdmPointer.h"
#include "RiaDefines.h"
#include <QObject>
#include <QPointer>
#include <QScopedPointer>
#include <QTimer>
#include <map>
#include <vector>
class RiuMultiPlotPage;
@ -36,11 +39,14 @@ class RiaPlotWindowRedrawScheduler : public QObject
public:
static RiaPlotWindowRedrawScheduler* instance();
void scheduleMultiPlotWindowUpdate( RiuMultiPlotBook* plotWindow );
void scheduleMultiPlotPageUpdate( RiuMultiPlotPage* plotWindow );
void schedulePlotWidgetReplot( RiuPlotWidget* plotWidget );
void clearAllScheduledUpdates();
void performScheduledUpdatesAndReplots();
void scheduleMultiPlotWindowUpdate( RiuMultiPlotBook* plotWindow );
void scheduleMultiPlotPageUpdate(
RiuMultiPlotPage* plotWindow,
RiaDefines::MultiPlotPageUpdateType updateType = RiaDefines::MultiPlotPageUpdateType::ALL );
void schedulePlotWidgetReplot( RiuPlotWidget* plotWidget );
void clearAllScheduledUpdates();
void performScheduledUpdatesAndReplots();
private slots:
void slotUpdateAndReplotScheduledItemsWhenReady();
@ -52,8 +58,10 @@ private:
void startTimer( int msecs );
private:
std::map<QPointer<RiuMultiPlotPage>, RiaDefines::MultiPlotPageUpdateType> m_plotPagesToUpdate;
std::vector<QPointer<RiuPlotWidget>> m_plotWidgetsToReplot;
std::vector<QPointer<RiuMultiPlotBook>> m_plotWindowsToUpdate;
std::vector<QPointer<RiuMultiPlotPage>> m_plotPagesToUpdate;
QScopedPointer<QTimer> m_plotWindowUpdateTimer;
QScopedPointer<QTimer> m_plotWindowUpdateTimer;
};

View File

@ -4,6 +4,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryMultiPlotFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromDataVectorFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryMultiPlotFromDataVectorFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromCurveFeature.h
)
set(SOURCE_GROUP_SOURCE_FILES
@ -12,6 +13,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryMultiPlotFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromDataVectorFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryMultiPlotFromDataVectorFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicNewSummaryPlotFromCurveFeature.cpp
)
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,67 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicNewSummaryPlotFromCurveFeature.h"
#include "RimSummaryCurve.h"
#include "RimSummaryPlot.h"
#include "RicSummaryPlotBuilder.h"
#include <QAction>
#include <QVariant>
CAF_CMD_SOURCE_INIT( RicNewSummaryPlotFromCurveFeature, "RicNewSummaryPlotFromCurveFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicNewSummaryPlotFromCurveFeature::isCommandEnabled()
{
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryPlotFromCurveFeature::onActionTriggered( bool isChecked )
{
QVariant userData = this->userData();
if ( !userData.isNull() && userData.canConvert<void*>() )
{
RimSummaryCurve* curve = static_cast<RimSummaryCurve*>( userData.value<void*>() );
auto curveCopy =
dynamic_cast<RimSummaryCurve*>( curve->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
RimSummaryPlot* plot = RicSummaryPlotBuilder::createPlot( { curveCopy } );
std::vector<RimSummaryPlot*> plots = { plot };
RicSummaryPlotBuilder::createAndAppendSummaryMultiPlot( plots );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicNewSummaryPlotFromCurveFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "New Summary Plot from Curve" );
actionToSetup->setIcon( QIcon( ":/SummaryPlotLight16x16.png" ) );
}

View File

@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RicfCommandObject.h"
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicNewSummaryPlotFromCurveFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;
};

View File

@ -30,7 +30,6 @@ class RicNewSummaryPlotFromDataVectorFeature : public caf::CmdFeature
CAF_CMD_HEADER_INIT;
protected:
// Overrides
bool isCommandEnabled() override;
void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override;

View File

@ -472,6 +472,24 @@ void RicSummaryPlotBuilder::appendPlotsToSummaryMultiPlot( RimSummaryMultiPlot*
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlot* RicSummaryPlotBuilder::createPlot( const std::vector<RimSummaryCurve*>& summaryCurves )
{
auto* plot = new RimSummaryPlot();
plot->enableAutoPlotTitle( true );
for ( auto& curve : summaryCurves )
{
plot->addCurveNoUpdate( curve );
}
plot->applyDefaultCurveAppearances();
return plot;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -83,6 +83,8 @@ public:
static RimSummaryMultiPlot* createAndAppendSummaryMultiPlot( const std::vector<caf::PdmObjectHandle*>& objects );
static void appendPlotsToSummaryMultiPlot( RimSummaryMultiPlot* multiPlot, const std::vector<RimSummaryPlot*>& plots );
static RimSummaryPlot* createPlot( const std::vector<RimSummaryCurve*>& summaryCurves );
static RimSummaryPlot* createPlot( const std::set<RifEclipseSummaryAddress>& addresses,
const std::vector<RimSummaryCase*>& summaryCases,
const std::vector<RimSummaryCaseCollection*>& ensembles );

View File

@ -562,7 +562,7 @@ void RiuMultiPlotBook::createPages()
}
CAF_ASSERT( plotWidgets[visibleIndex] );
page->addPlot( plotWidgets[visibleIndex] );
page->performUpdate();
page->performUpdate( RiaDefines::MultiPlotPageUpdateType::ALL );
}
// Set page numbers in title when there's more than one page

View File

@ -322,10 +322,10 @@ int RiuMultiPlotPage::indexOfPlotWidget( RiuPlotWidget* plotWidget )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotPage::scheduleUpdate()
void RiuMultiPlotPage::scheduleUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate )
{
CAF_ASSERT( m_plotDefinition );
RiaPlotWindowRedrawScheduler::instance()->scheduleMultiPlotPageUpdate( this );
RiaPlotWindowRedrawScheduler::instance()->scheduleMultiPlotPageUpdate( this, whatToUpdate );
}
//--------------------------------------------------------------------------------------------------
@ -444,7 +444,7 @@ QLabel* RiuMultiPlotPage::createTitleLabel() const
void RiuMultiPlotPage::showEvent( QShowEvent* event )
{
QWidget::showEvent( event );
performUpdate();
performUpdate( RiaDefines::MultiPlotPageUpdateType::ALL );
}
//--------------------------------------------------------------------------------------------------
@ -560,12 +560,24 @@ bool RiuMultiPlotPage::showYAxis( int row, int column ) const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotPage::performUpdate()
void RiuMultiPlotPage::performUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate )
{
applyLook();
updateMarginsFromPageLayout();
reinsertPlotWidgets();
alignCanvasTops();
if ( whatToUpdate == RiaDefines::MultiPlotPageUpdateType::ALL )
{
applyLook();
updateMarginsFromPageLayout();
reinsertPlotWidgets();
alignCanvasTops();
}
else
{
if ( ( whatToUpdate & RiaDefines::MultiPlotPageUpdateType::LEGEND ) == RiaDefines::MultiPlotPageUpdateType::LEGEND )
{
refreshLegends();
alignCanvasTops();
}
}
}
//--------------------------------------------------------------------------------------------------
@ -573,7 +585,15 @@ void RiuMultiPlotPage::performUpdate()
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotPage::onLegendUpdated()
{
scheduleUpdate();
scheduleUpdate( RiaDefines::MultiPlotPageUpdateType::LEGEND );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMultiPlotPage::refreshLegends()
{
// TODO - might need to do something here, but at the moment it looks like alignCanvasTops() is sufficient
}
//--------------------------------------------------------------------------------------------------

View File

@ -19,6 +19,8 @@
#include "RiuInterfaceToViewWindow.h"
#include "RiaDefines.h"
#include "cafPdmPointer.h"
#include "cafSelectionChangedReceiver.h"
@ -76,8 +78,8 @@ public:
bool previewModeEnabled() const;
void setPagePreviewModeEnabled( bool previewMode );
void scheduleUpdate();
void scheduleReplotOfAllPlots();
void scheduleUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate = RiaDefines::MultiPlotPageUpdateType::ALL );
void scheduleReplotOfAllPlots();
virtual void updateVerticalScrollBar( double visibleMin, double visibleMax, double totalMin, double totalMax ) {}
void updateSubTitles();
@ -103,6 +105,7 @@ protected:
virtual bool showYAxis( int row, int column ) const;
virtual void reinsertPlotWidgets();
virtual void refreshLegends();
void updateTitleFont();
@ -119,7 +122,7 @@ protected:
void applyLook();
private slots:
virtual void performUpdate();
virtual void performUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate );
void onLegendUpdated();
protected:

View File

@ -31,6 +31,7 @@
#include "cafCmdFeatureMenuBuilder.h"
#include <QMenu>
#include <QPointer>
#include <cmath>
@ -87,6 +88,14 @@ void RiuSummaryPlot::showContextMenu( QPoint pos )
if ( ensemble && ensemble->isEnsemble() )
{
clickedQuantityName = QString::fromStdString( clickedEnsembleCurveSet->summaryAddress().uiText() );
if ( curveClicked )
{
QVariant curveVariant( QVariant::fromValue( static_cast<void*>( summaryCurve ) ) );
menuBuilder.addCmdFeatureWithUserData( "RicNewSummaryPlotFromCurveFeature",
"Create New Plot from Curve",
curveVariant );
}
}
}

View File

@ -151,7 +151,7 @@ void RiuWellLogPlot::slotSetMinDepth( int value )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuWellLogPlot::performUpdate()
void RiuWellLogPlot::performUpdate( RiaDefines::MultiPlotPageUpdateType /* whatToUpdate */ )
{
m_horizontalTrackScrollBar->setVisible( false );
m_verticalTrackScrollBar->setVisible( false );

View File

@ -45,7 +45,7 @@ private:
private slots:
void slotSetMinDepth( int value );
void performUpdate() override;
void performUpdate( RiaDefines::MultiPlotPageUpdateType whatToUpdate ) override;
private:
QPointer<QVBoxLayout> m_verticalTrackScrollBarLayout;