From 5273ace5e68ea0d9b647102ee24ad1942dbd3a0b Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Thu, 25 Jan 2018 17:04:20 +0100 Subject: [PATCH] #2301 Rel.perm Plot: Add tooltip for cell value --- .../RiuRelativePermeabilityPlotPanel.cpp | 94 +++++++++++++++--- .../RiuRelativePermeabilityPlotPanel.h | 99 ++++++++++++------- 2 files changed, 145 insertions(+), 48 deletions(-) diff --git a/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.cpp b/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.cpp index 0e5ef06448..4ed965093d 100644 --- a/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.cpp +++ b/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.cpp @@ -169,7 +169,12 @@ void RiuRelativePermeabilityPlotPanel::setPlotDefaults(QwtPlot* plot) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuRelativePermeabilityPlotPanel::setPlotData(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector& relPermCurves, double swat, double sgas, QString caseName, QString cellReferenceText) +void RiuRelativePermeabilityPlotPanel::setPlotData(RiaEclipseUnitTools::UnitSystem unitSystem, + const std::vector& relPermCurves, + double swat, + double sgas, + QString caseName, + QString cellReferenceText) { //cvf::Trace::show("Set RelPerm plot data"); @@ -224,10 +229,59 @@ void RiuRelativePermeabilityPlotPanel::plotUiSelectedCurves() plotCurvesInQwt(m_unitSystem, selectedCurves, m_swat, m_sgas, m_cellReferenceText, useLogScale, m_qwtPlot, &m_myPlotMarkers); } +//-------------------------------------------------------------------------------------------------- +/// Add a transparent curve to make tooltip available on given points. +//-------------------------------------------------------------------------------------------------- +void RiuRelativePermeabilityPlotPanel::addTransparentCurve(QwtPlot* plot, const std::vector& points, const std::vector& axes) +{ + QwtPlotCurve* curveLeftAxis = new QwtPlotCurve(); + QwtPlotCurve* curveRightAxis = new QwtPlotCurve(); + + QVector pointsOnLeftAxis; + QVector pointsOnRightAxis; + + // Each point is defined by either left or right axis + CVF_ASSERT(points.size() == axes.size()); + + for (size_t i = 0; i < points.size(); i++) + { + if (axes[i] == LEFT_YAXIS) + { + pointsOnLeftAxis.push_back(points[i]); + } + else + { + pointsOnRightAxis.push_back(points[i]); + } + } + + curveLeftAxis->setSamples(pointsOnLeftAxis); + curveRightAxis->setSamples(pointsOnRightAxis); + + curveLeftAxis->setYAxis(QwtPlot::yLeft); + curveRightAxis->setYAxis(QwtPlot::yRight); + + curveLeftAxis->setStyle(QwtPlotCurve::NoCurve); + curveRightAxis->setStyle(QwtPlotCurve::NoCurve); + + curveLeftAxis->setLegendAttribute(QwtPlotCurve::LegendNoAttribute); + curveRightAxis->setLegendAttribute(QwtPlotCurve::LegendNoAttribute); + + curveLeftAxis->attach(plot); + curveRightAxis->attach(plot); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector& curveArr, double swat, double sgas, QString cellReferenceText, bool logScaleLeftAxis, QwtPlot* plot, std::vector* myPlotMarkers) +void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::UnitSystem unitSystem, + const std::vector& curveArr, + double swat, + double sgas, + QString cellReferenceText, + bool logScaleLeftAxis, + QwtPlot* plot, + std::vector* myPlotMarkers) { plot->detachItems(QwtPlotItem::Rtti_PlotCurve); @@ -240,7 +294,9 @@ void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::Unit delete marker; } myPlotMarkers->clear(); - + + std::vector points; + std::vector axes; bool shouldEnableRightYAxis = false; @@ -255,7 +311,6 @@ void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::Unit plotOnWhichYAxis = RIGHT_YAXIS; } - //QwtPlotCurve* qwtCurve = new QwtPlotCurve(curve.name.c_str()); RiuLineSegmentQwtPlotCurve* qwtCurve = new RiuLineSegmentQwtPlotCurve(curve.name.c_str()); @@ -303,7 +358,6 @@ void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::Unit qwtCurve->attach(plot); - // Add markers to indicate where SWAT and/or SGAS saturation intersects the respective curves // Note that if we're using log scale we must guard against non-positive values if (swat != HUGE_VAL) @@ -312,7 +366,7 @@ void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::Unit curve.ident == RigFlowDiagSolverInterface::RelPermCurve::KROW || curve.ident == RigFlowDiagSolverInterface::RelPermCurve::PCOW) { - addCurveConstSaturationIntersectionMarker(curve, swat, Qt::blue, plotOnWhichYAxis, plot, myPlotMarkers); + addCurveConstSaturationIntersectionMarker(curve, swat, Qt::blue, plotOnWhichYAxis, plot, myPlotMarkers, &points, &axes); } } if (sgas != HUGE_VAL) @@ -321,11 +375,14 @@ void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::Unit curve.ident == RigFlowDiagSolverInterface::RelPermCurve::KROG || curve.ident == RigFlowDiagSolverInterface::RelPermCurve::PCOG) { - addCurveConstSaturationIntersectionMarker(curve, sgas, Qt::red, plotOnWhichYAxis, plot, myPlotMarkers); + addCurveConstSaturationIntersectionMarker(curve, sgas, Qt::red, plotOnWhichYAxis, plot, myPlotMarkers, &points, &axes); } } } + plot->enableAxis(QwtPlot::yRight, shouldEnableRightYAxis); + + addTransparentCurve(plot, points, axes); // Add vertical marker lines to indicate cell SWAT and/or SGAS saturations if (swat != HUGE_VAL) @@ -367,8 +424,6 @@ void RiuRelativePermeabilityPlotPanel::plotCurvesInQwt(RiaEclipseUnitTools::Unit plot->setAxisTitle(QwtPlot::yLeft, "Kr"); plot->setAxisTitle(QwtPlot::yRight, QString("Pc [%1]").arg(RiaEclipseUnitTools::unitStringPressure(unitSystem))); - plot->enableAxis(QwtPlot::yRight, shouldEnableRightYAxis); - plot->replot(); } @@ -408,7 +463,11 @@ QString RiuRelativePermeabilityPlotPanel::determineXAxisTitleFromCurveCollection //-------------------------------------------------------------------------------------------------- /// Add a vertical labeled marker line at the specified saturation value //-------------------------------------------------------------------------------------------------- -void RiuRelativePermeabilityPlotPanel::addVerticalSaturationMarkerLine(double saturationValue, QString label, QColor color, QwtPlot* plot, std::vector* myPlotMarkers) +void RiuRelativePermeabilityPlotPanel::addVerticalSaturationMarkerLine(double saturationValue, + QString label, + QColor color, + QwtPlot* plot, + std::vector* myPlotMarkers) { QwtPlotMarker* lineMarker = new QwtPlotMarker; lineMarker->setXValue(saturationValue); @@ -425,7 +484,14 @@ void RiuRelativePermeabilityPlotPanel::addVerticalSaturationMarkerLine(double sa //-------------------------------------------------------------------------------------------------- /// Add a marker at the intersection of the passed curve and the constant saturation value //-------------------------------------------------------------------------------------------------- -void RiuRelativePermeabilityPlotPanel::addCurveConstSaturationIntersectionMarker(const RigFlowDiagSolverInterface::RelPermCurve& curve, double saturationValue, QColor markerColor, WhichYAxis whichYAxis, QwtPlot* plot, std::vector* myPlotMarkers) +void RiuRelativePermeabilityPlotPanel::addCurveConstSaturationIntersectionMarker(const RigFlowDiagSolverInterface::RelPermCurve& curve, + double saturationValue, + QColor markerColor, + WhichYAxis whichYAxis, + QwtPlot* plot, + std::vector* myPlotMarkers, + std::vector* points, + std::vector* axes) { const double yVal = interpolatedCurveYValue(curve.saturationVals, curve.yVals, saturationValue); if (yVal != HUGE_VAL) @@ -446,6 +512,8 @@ void RiuRelativePermeabilityPlotPanel::addCurveConstSaturationIntersectionMarker } myPlotMarkers->push_back(pointMarker); + axes->push_back(whichYAxis); + points->push_back(QPointF(saturationValue, yVal)); } } @@ -497,7 +565,9 @@ std::vector RiuRelativePermeabilityPlo std::vector selectedCurves; // Determine which curves to actually plot based on selection in GUI - const RigFlowDiagSolverInterface::RelPermCurve::EpsMode epsModeToShow = m_showUnscaledCheckBox->isChecked() ? RigFlowDiagSolverInterface::RelPermCurve::EPS_OFF : RigFlowDiagSolverInterface::RelPermCurve::EPS_ON; + const RigFlowDiagSolverInterface::RelPermCurve::EpsMode epsModeToShow = m_showUnscaledCheckBox->isChecked() ? + RigFlowDiagSolverInterface::RelPermCurve::EPS_OFF : + RigFlowDiagSolverInterface::RelPermCurve::EPS_ON; for (size_t i = 0; i < m_allCurvesArr.size(); i++) { diff --git a/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.h b/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.h index 6dd085b499..b3bbd6e759 100644 --- a/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.h +++ b/ApplicationCode/UserInterface/RiuRelativePermeabilityPlotPanel.h @@ -1,25 +1,25 @@ ///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 Statoil 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 +// +// See the GNU General Public License at // for more details. // ///////////////////////////////////////////////////////////////////////////////// #pragma once -#include "RigFlowDiagSolverInterface.h" #include "RiaEclipseUnitTools.h" +#include "RigFlowDiagSolverInterface.h" #include @@ -31,8 +31,7 @@ class QButtonGroup; class QCheckBox; class QwtPlot; class QwtPlotMarker; - - +class QPointF; //================================================================================================== // @@ -46,8 +45,13 @@ class RiuRelativePermeabilityPlotPanel : public QWidget public: RiuRelativePermeabilityPlotPanel(QDockWidget* parent); virtual ~RiuRelativePermeabilityPlotPanel(); - - void setPlotData(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector& relPermCurves, double swat, double sgas, QString caseName, QString cellReferenceText); + + void setPlotData(RiaEclipseUnitTools::UnitSystem unitSystem, + const std::vector& relPermCurves, + double swat, + double sgas, + QString caseName, + QString cellReferenceText); void clearPlot(); RiuRelativePermeabilityPlotUpdater* plotUpdater(); @@ -69,38 +73,61 @@ private: double max; }; - void plotUiSelectedCurves(); - static void setPlotDefaults(QwtPlot* plot); - static void plotCurvesInQwt(RiaEclipseUnitTools::UnitSystem unitSystem, const std::vector& curveArr, double swat, double sgas, QString cellReferenceText, bool logScaleLeftAxis, QwtPlot* plot, std::vector* myPlotMarkers); - static QString determineXAxisTitleFromCurveCollection(const std::vector& curveArr); - static void addVerticalSaturationMarkerLine(double saturationValue, QString label, QColor color, QwtPlot* plot, std::vector* myPlotMarkers); - static void addCurveConstSaturationIntersectionMarker(const RigFlowDiagSolverInterface::RelPermCurve& curve, double saturationValue, QColor markerColor, WhichYAxis whichYAxis, QwtPlot* plot, std::vector* myPlotMarkers); - static double interpolatedCurveYValue(const std::vector& xVals, const std::vector& yVals, double x); - - std::vector gatherUiSelectedCurves() const; - QString asciiDataForUiSelectedCurves() const; + void plotUiSelectedCurves(); + static void setPlotDefaults(QwtPlot* plot); + static void plotCurvesInQwt(RiaEclipseUnitTools::UnitSystem unitSystem, + const std::vector& curveArr, + double swat, + double sgas, + QString cellReferenceText, + bool logScaleLeftAxis, + QwtPlot* plot, + std::vector* myPlotMarkers); - virtual void contextMenuEvent(QContextMenuEvent* event) override; + static QString determineXAxisTitleFromCurveCollection(const std::vector& curveArr); + + static void addVerticalSaturationMarkerLine(double saturationValue, + QString label, + QColor color, + QwtPlot* plot, + std::vector* myPlotMarkers); + + static void addCurveConstSaturationIntersectionMarker(const RigFlowDiagSolverInterface::RelPermCurve& curve, + double saturationValue, + QColor markerColor, + WhichYAxis whichYAxis, + QwtPlot* plot, + std::vector* myPlotMarkers, + std::vector* points, + std::vector* axes); + + static double interpolatedCurveYValue(const std::vector& xVals, const std::vector& yVals, double x); + + static void addTransparentCurve(QwtPlot* plot, const std::vector& points, const std::vector& axes); + + std::vector gatherUiSelectedCurves() const; + QString asciiDataForUiSelectedCurves() const; + + virtual void contextMenuEvent(QContextMenuEvent* event) override; private slots: - void slotButtonInButtonGroupClicked(int); - void slotSomeCheckBoxStateChanged(int); - void slotCurrentPlotDataInTextDialog(); + void slotButtonInButtonGroupClicked(int); + void slotSomeCheckBoxStateChanged(int); + void slotCurrentPlotDataInTextDialog(); private: - RiaEclipseUnitTools::UnitSystem m_unitSystem; - std::vector m_allCurvesArr; - double m_swat; - double m_sgas; - QString m_caseName; - QString m_cellReferenceText; - QwtPlot* m_qwtPlot; - std::vector m_myPlotMarkers; + RiaEclipseUnitTools::UnitSystem m_unitSystem; + std::vector m_allCurvesArr; + double m_swat; + double m_sgas; + QString m_caseName; + QString m_cellReferenceText; + QwtPlot* m_qwtPlot; + std::vector m_myPlotMarkers; - QButtonGroup* m_selectedCurvesButtonGroup; - QCheckBox* m_showUnscaledCheckBox; - QCheckBox* m_logarithmicScaleKrAxisCheckBox; + QButtonGroup* m_selectedCurvesButtonGroup; + QCheckBox* m_showUnscaledCheckBox; + QCheckBox* m_logarithmicScaleKrAxisCheckBox; - std::unique_ptr m_plotUpdater; + std::unique_ptr m_plotUpdater; }; -