From 709ec7378e71793066cbc7ab0801fb3983fef6b5 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 14 Oct 2024 09:08:47 +0200 Subject: [PATCH] #11768 Show current time step in result plot --- .../RiuFlowCharacteristicsPlot.cpp | 1 - .../RiuFlowCharacteristicsPlot.h | 1 - .../UserInterface/RiuResultQwtPlot.cpp | 37 ++++++++++++++++--- .../UserInterface/RiuResultQwtPlot.h | 4 +- .../RiuSelectionChangedHandler.cpp | 5 +++ 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.cpp b/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.cpp index 4d0dc9efb4..a6a4c88f84 100644 --- a/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.cpp @@ -31,7 +31,6 @@ #include "RiuQwtPlotWheelZoomer.h" #include "RiuQwtPlotZoomer.h" #include "RiuQwtSymbol.h" -#include "RiuResultQwtPlot.h" #include "cvfColor3.h" diff --git a/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.h b/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.h index df1018b9ff..2bb56e5c25 100644 --- a/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.h +++ b/ApplicationLibCode/UserInterface/RiuFlowCharacteristicsPlot.h @@ -27,7 +27,6 @@ class RimFlowCharacteristicsPlot; class RiuNightchartsWidget; -class RiuResultQwtPlot; class RiuQwtPlotCurve; class QLabel; diff --git a/ApplicationLibCode/UserInterface/RiuResultQwtPlot.cpp b/ApplicationLibCode/UserInterface/RiuResultQwtPlot.cpp index aafd930867..36f8b78997 100644 --- a/ApplicationLibCode/UserInterface/RiuResultQwtPlot.cpp +++ b/ApplicationLibCode/UserInterface/RiuResultQwtPlot.cpp @@ -42,7 +42,9 @@ #include "qwt_plot_curve.h" #include "qwt_plot_grid.h" #include "qwt_plot_layout.h" +#include "qwt_plot_marker.h" #include "qwt_scale_engine.h" +#include "qwt_text.h" #include #include @@ -80,7 +82,7 @@ void RiuResultQwtPlot::addCurve( const RimCase* rimCase, return; } - RiuQwtPlotCurve* plotCurve = new RiuQwtPlotCurve( nullptr, "Curve 1" ); + auto plotCurve = new RiuQwtPlotCurve( nullptr, "Curve 1" ); plotCurve->setSamplesFromDatesAndYValues( dateTimes, timeHistoryValues, false ); plotCurve->setTitle( curveName ); @@ -88,7 +90,7 @@ void RiuResultQwtPlot::addCurve( const RimCase* rimCase, plotCurve->setPen( QPen( QColor( curveColor.rByte(), curveColor.gByte(), curveColor.bByte() ) ) ); plotCurve->attach( this ); - m_plotCurves.push_back( plotCurve ); + m_plotItems.push_back( plotCurve ); setAxisScale( QwtAxis::XTop, QwtDate::toDouble( dateTimes.front() ), QwtDate::toDouble( dateTimes.back() ) ); applyFontSizes( false ); @@ -124,18 +126,41 @@ void RiuResultQwtPlot::addCurve( const RimCase* rimCase, addCurve( rimCase, curveName, curveColor, dateTimes, timeHistoryValues ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuResultQwtPlot::showTimeStep( const QDateTime& dateTime ) +{ + if ( !dateTime.isValid() ) return; + + auto lineMarker = new QwtPlotMarker; + + QPen pen; + pen.setStyle( Qt::DashLine ); + lineMarker->setLinePen( pen ); + + lineMarker->setXValue( QwtDate::toDouble( dateTime ) ); + lineMarker->setLineStyle( QwtPlotMarker::VLine ); + lineMarker->setLabel( QString( "Time Step" ) ); + lineMarker->setLabelAlignment( Qt::AlignTop | Qt::AlignRight ); + lineMarker->setLabelOrientation( Qt::Vertical ); + lineMarker->attach( this ); + + m_plotItems.push_back( lineMarker ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuResultQwtPlot::deleteAllCurves() { - for ( size_t i = 0; i < m_plotCurves.size(); i++ ) + for ( size_t i = 0; i < m_plotItems.size(); i++ ) { - m_plotCurves[i]->detach(); - delete m_plotCurves[i]; + m_plotItems[i]->detach(); + delete m_plotItems[i]; } - m_plotCurves.clear(); + m_plotItems.clear(); m_caseNames.clear(); m_curveNames.clear(); diff --git a/ApplicationLibCode/UserInterface/RiuResultQwtPlot.h b/ApplicationLibCode/UserInterface/RiuResultQwtPlot.h index e6f346b9d2..9a9c4e241f 100644 --- a/ApplicationLibCode/UserInterface/RiuResultQwtPlot.h +++ b/ApplicationLibCode/UserInterface/RiuResultQwtPlot.h @@ -58,6 +58,8 @@ public: const std::vector& frameTimes, const std::vector& timeHistoryValues ); + void showTimeStep( const QDateTime& dateTime ); + void deleteAllCurves(); protected: @@ -74,7 +76,7 @@ private slots: void slotCurrentPlotDataInTextDialog(); private: - std::vector m_plotCurves; + std::vector m_plotItems; std::map m_caseNames; std::map> m_timeSteps; diff --git a/ApplicationLibCode/UserInterface/RiuSelectionChangedHandler.cpp b/ApplicationLibCode/UserInterface/RiuSelectionChangedHandler.cpp index baa220bac9..243e91b800 100644 --- a/ApplicationLibCode/UserInterface/RiuSelectionChangedHandler.cpp +++ b/ApplicationLibCode/UserInterface/RiuSelectionChangedHandler.cpp @@ -188,6 +188,11 @@ void RiuSelectionChangedHandler::addResultCurveFromSelectionItem( const RiuEclip eclipseSelectionItem->m_color, timeStepDates, timeHistoryValues ); + + if ( eclipseSelectionItem->m_timestepIdx < timeStepDates.size() ) + { + RiuMainWindow::instance()->resultPlot()->showTimeStep( timeStepDates[eclipseSelectionItem->m_timestepIdx] ); + } } }