diff --git a/ApplicationCode/Application/CMakeLists_files.cmake b/ApplicationCode/Application/CMakeLists_files.cmake index dd3a8ddcbc..08afb25286 100644 --- a/ApplicationCode/Application/CMakeLists_files.cmake +++ b/ApplicationCode/Application/CMakeLists_files.cmake @@ -12,6 +12,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaSummaryCurveDefinition.h ${CMAKE_CURRENT_LIST_DIR}/RiaCurveSetDefinition.h ${CMAKE_CURRENT_LIST_DIR}/RiaRftPltCurveDefinition.h ${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h +${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.h ${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.h ${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.h ${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.h @@ -32,6 +33,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaSummaryCurveDefinition.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaCurveSetDefinition.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaRftPltCurveDefinition.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.cpp +${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaMemoryCleanup.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaFontCache.cpp ${CMAKE_CURRENT_LIST_DIR}/RiaEclipseFileNameTools.cpp @@ -52,6 +54,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaConsoleApplication.h ${CMAKE_CURRENT_LIST_DIR}/RiaGuiApplication.h ${CMAKE_CURRENT_LIST_DIR}/RiaCompletionTypeCalculationScheduler.h ${CMAKE_CURRENT_LIST_DIR}/RiaViewRedrawScheduler.h +${CMAKE_CURRENT_LIST_DIR}/RiaPlotWindowRedrawScheduler.h ) diff --git a/ApplicationCode/Application/RiaPlotWindowRedrawScheduler.cpp b/ApplicationCode/Application/RiaPlotWindowRedrawScheduler.cpp new file mode 100644 index 0000000000..6c74ce30ee --- /dev/null +++ b/ApplicationCode/Application/RiaPlotWindowRedrawScheduler.cpp @@ -0,0 +1,140 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// +#include "RiaPlotWindowRedrawScheduler.h" + +#include "RiuGridPlotWindow.h" +#include "RiuQwtPlotWidget.h" + +#include +#include + +#include + +#include "cafProgressState.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaPlotWindowRedrawScheduler* RiaPlotWindowRedrawScheduler::instance() +{ + static RiaPlotWindowRedrawScheduler theInstance; + + return &theInstance; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::schedulePlotWindowUpdate( RiuGridPlotWindow* plotWindow ) +{ + m_plotWindowsToUpdate.push_back( plotWindow ); + + startTimer( 0 ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::schedulePlotWidgetReplot( RiuQwtPlotWidget* plotWidget ) +{ + m_plotWidgetsToReplot.push_back( plotWidget ); + + startTimer( 0 ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::clearAllScheduledUpdates() +{ + if ( m_plotWindowUpdateTimer ) + { + while ( m_plotWindowUpdateTimer->isActive() ) + { + QCoreApplication::processEvents(); + } + } + m_plotWidgetsToReplot.clear(); + m_plotWindowsToUpdate.clear(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::performScheduledUpdatesAndReplots() +{ + std::set updatedPlots; + std::set updatedPlotWindows; + + for ( RiuGridPlotWindow* plotWindow : m_plotWindowsToUpdate ) + { + if ( plotWindow && !updatedPlotWindows.count( plotWindow ) ) + { + plotWindow->performUpdate(); + updatedPlotWindows.insert( plotWindow ); + } + } + + // Perform update and replot. Make sure we handle legend update + for ( RiuQwtPlotWidget* plot : m_plotWidgetsToReplot ) + { + if ( plot && !updatedPlots.count( plot ) ) + { + plot->replot(); + updatedPlots.insert( plot ); + } + } + + m_plotWidgetsToReplot.clear(); + m_plotWindowsToUpdate.clear(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::slotUpdateAndReplotScheduledItemsWhenReady() +{ + if ( caf::ProgressState::isActive() ) + { + startTimer( 10 ); + return; + } + + performScheduledUpdatesAndReplots(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaPlotWindowRedrawScheduler::startTimer( int msecs ) +{ + if ( !m_plotWindowUpdateTimer ) + { + m_plotWindowUpdateTimer.reset( new QTimer( this ) ); + connect( m_plotWindowUpdateTimer.data(), + SIGNAL( timeout() ), + this, + SLOT( slotUpdateAndReplotScheduledItemsWhenReady() ) ); + } + + if ( !m_plotWindowUpdateTimer->isActive() ) + { + m_plotWindowUpdateTimer->setSingleShot( true ); + m_plotWindowUpdateTimer->start( msecs ); + } +} diff --git a/ApplicationCode/Application/RiaPlotWindowRedrawScheduler.h b/ApplicationCode/Application/RiaPlotWindowRedrawScheduler.h new file mode 100644 index 0000000000..170c52f72b --- /dev/null +++ b/ApplicationCode/Application/RiaPlotWindowRedrawScheduler.h @@ -0,0 +1,53 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// +#pragma once + +#include "cafPdmPointer.h" + +#include +#include +#include +#include + +#include + +class RiuGridPlotWindow; +class RiuQwtPlotWidget; + +class RiaPlotWindowRedrawScheduler : public QObject +{ + Q_OBJECT + +public: + static RiaPlotWindowRedrawScheduler* instance(); + void schedulePlotWindowUpdate( RiuGridPlotWindow* plotWindow ); + void schedulePlotWidgetReplot( RiuQwtPlotWidget* plotWidget ); + void clearAllScheduledUpdates(); + void performScheduledUpdatesAndReplots(); + +private slots: + void slotUpdateAndReplotScheduledItemsWhenReady(); + +private: + void startTimer( int msecs ); + +private: + std::vector> m_plotWidgetsToReplot; + std::vector> m_plotWindowsToUpdate; + QScopedPointer m_plotWindowUpdateTimer; +}; diff --git a/ApplicationCode/Application/RiaViewRedrawScheduler.cpp b/ApplicationCode/Application/RiaViewRedrawScheduler.cpp index d21a8cbd59..23a2f18c2c 100644 --- a/ApplicationCode/Application/RiaViewRedrawScheduler.cpp +++ b/ApplicationCode/Application/RiaViewRedrawScheduler.cpp @@ -35,21 +35,6 @@ RiaViewRedrawScheduler* RiaViewRedrawScheduler::instance() return &theInstance; } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RiaViewRedrawScheduler::clearViewsScheduledForUpdate() -{ - if ( m_resViewUpdateTimer ) - { - while ( m_resViewUpdateTimer->isActive() ) - { - QCoreApplication::processEvents(); - } - } - m_resViewsToUpdate.clear(); -} - //-------------------------------------------------------------------------------------------------- /// Schedule a creation of the Display model and redraw of the reservoir view /// The redraw will happen as soon as the event loop is entered @@ -64,19 +49,16 @@ void RiaViewRedrawScheduler::scheduleDisplayModelUpdateAndRedraw( Rim3dView* res //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaViewRedrawScheduler::startTimer( int msecs ) +void RiaViewRedrawScheduler::clearViewsScheduledForUpdate() { - if ( !m_resViewUpdateTimer ) + if ( m_resViewUpdateTimer ) { - m_resViewUpdateTimer = new QTimer( this ); - connect( m_resViewUpdateTimer, SIGNAL( timeout() ), this, SLOT( slotUpdateAndRedrawScheduledViewsWhenReady() ) ); - } - - if ( !m_resViewUpdateTimer->isActive() ) - { - m_resViewUpdateTimer->setSingleShot( true ); - m_resViewUpdateTimer->start( msecs ); + while ( m_resViewUpdateTimer->isActive() ) + { + QCoreApplication::processEvents(); + } } + m_resViewsToUpdate.clear(); } //-------------------------------------------------------------------------------------------------- @@ -135,6 +117,24 @@ void RiaViewRedrawScheduler::slotUpdateAndRedrawScheduledViewsWhenReady() updateAndRedrawScheduledViews(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiaViewRedrawScheduler::startTimer( int msecs ) +{ + if ( !m_resViewUpdateTimer ) + { + m_resViewUpdateTimer = new QTimer( this ); + connect( m_resViewUpdateTimer, SIGNAL( timeout() ), this, SLOT( slotUpdateAndRedrawScheduledViewsWhenReady() ) ); + } + + if ( !m_resViewUpdateTimer->isActive() ) + { + m_resViewUpdateTimer->setSingleShot( true ); + m_resViewUpdateTimer->start( msecs ); + } +} + //-------------------------------------------------------------------------------------------------- /// //--------------------------------------------------------------------------------------------------