From 119752bf04356f99ba30cdfcff7e21c2b4eb2e4f Mon Sep 17 00:00:00 2001 From: Rebecca Cox Date: Mon, 19 Feb 2018 14:15:42 +0100 Subject: [PATCH] #2501 Result Plot: Add "Show Plot Data" to context menu --- .../ProjectDataModel/Summary/RimSummaryPlot.h | 4 +- .../UserInterface/CMakeLists_files.cmake | 1 + .../UserInterface/RiuResultQwtPlot.cpp | 84 +++++++++++++++++-- .../UserInterface/RiuResultQwtPlot.h | 23 ++++- .../RiuSelectionChangedHandler.cpp | 6 +- 5 files changed, 104 insertions(+), 14 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h index fe43619508..b3393077f0 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h @@ -129,11 +129,11 @@ class RimSummaryPlot : public RimViewWindow protected: // Overridden PDM methods - virtual caf::PdmFieldHandle* userDescriptionField(); + virtual caf::PdmFieldHandle* userDescriptionField() override; virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override; virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; virtual void defineUiTreeOrdering(caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "") override; - virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); + virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute) override; virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; virtual void onLoadDataAndUpdate() override; diff --git a/ApplicationCode/UserInterface/CMakeLists_files.cmake b/ApplicationCode/UserInterface/CMakeLists_files.cmake index f6219706d6..58e825d702 100644 --- a/ApplicationCode/UserInterface/CMakeLists_files.cmake +++ b/ApplicationCode/UserInterface/CMakeLists_files.cmake @@ -149,6 +149,7 @@ ${CEE_CURRENT_LIST_DIR}RiuMainPlotWindow.h ${CEE_CURRENT_LIST_DIR}RiuPvtPlotPanel.h ${CEE_CURRENT_LIST_DIR}RiuRelativePermeabilityPlotPanel.h ${CEE_CURRENT_LIST_DIR}RiuResultInfoPanel.h +${CEE_CURRENT_LIST_DIR}RiuResultQwtPlot.h ${CEE_CURRENT_LIST_DIR}RiuTextDialog.h ${CEE_CURRENT_LIST_DIR}RiuViewer.h ${CEE_CURRENT_LIST_DIR}RiuProcessMonitor.h diff --git a/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp b/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp index f6bec832ac..ae65202248 100644 --- a/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuResultQwtPlot.cpp @@ -22,8 +22,11 @@ #include "RigCurveDataTools.h" #include "RimContextCommandBuilder.h" +#include "RimCase.h" #include "RiuLineSegmentQwtPlotCurve.h" +#include "RiuSummaryQwtPlot.h" +#include "RiuTextDialog.h" #include "cafCmdFeatureMenuBuilder.h" @@ -41,7 +44,6 @@ #include #include -#include "RiuSummaryQwtPlot.h" //-------------------------------------------------------------------------------------------------- @@ -64,7 +66,7 @@ RiuResultQwtPlot::~RiuResultQwtPlot() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuResultQwtPlot::addCurve(const QString& curveName, const cvf::Color3f& curveColor, const std::vector& dateTimes, const std::vector& timeHistoryValues) +void RiuResultQwtPlot::addCurve(const RimCase* rimCase, const QString& curveName, const cvf::Color3f& curveColor, const std::vector& dateTimes, const std::vector& timeHistoryValues) { if (dateTimes.empty() || timeHistoryValues.empty()) { @@ -84,21 +86,28 @@ void RiuResultQwtPlot::addCurve(const QString& curveName, const cvf::Color3f& cu this->setAxisScale( QwtPlot::xTop, QwtDate::toDouble(dateTimes.front()), QwtDate::toDouble(dateTimes.back())); this->replot(); + + int caseId = rimCase->caseId; + + m_caseNames[caseId] = rimCase->caseUserDescription; + m_curveNames[caseId].push_back(curveName); + m_curveData[caseId].push_back(timeHistoryValues); + m_timeSteps[caseId] = dateTimes; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuResultQwtPlot::addCurve(const QString& curveName, const cvf::Color3f& curveColor, const std::vector& frameTimes, const std::vector& timeHistoryValues) +void RiuResultQwtPlot::addCurve(const RimCase* rimCase, const QString& curveName, const cvf::Color3f& curveColor, const std::vector& frameTimes, const std::vector& timeHistoryValues) { std::vector dateTimes; - for (size_t i = 0; i < frameTimes.size(); i++) + for (double frameTime : frameTimes) { - dateTimes.push_back(QwtDate::toDateTime(frameTimes[i])); + dateTimes.push_back(QwtDate::toDateTime(frameTime)); } - addCurve(curveName, curveColor, dateTimes, timeHistoryValues); + addCurve(rimCase, curveName, curveColor, dateTimes, timeHistoryValues); } //-------------------------------------------------------------------------------------------------- @@ -113,6 +122,11 @@ void RiuResultQwtPlot::deleteAllCurves() } m_plotCurves.clear(); + + m_caseNames.clear(); + m_curveNames.clear(); + m_curveData.clear(); + m_timeSteps.clear(); } //-------------------------------------------------------------------------------------------------- @@ -141,9 +155,14 @@ void RiuResultQwtPlot::contextMenuEvent(QContextMenuEvent* event) menuBuilder << "RicNewGridTimeHistoryCurveFeature"; + const int curveCount = this->itemList(QwtPlotItem::Rtti_PlotCurve).count(); + + QAction* act = menu.addAction("Show Plot Data", this, SLOT(slotCurrentPlotDataInTextDialog())); + act->setEnabled(curveCount > 0); + menuBuilder.appendToMenu(&menu); - if (menu.actions().size() > 0) + if (!menu.actions().empty()) { menu.exec(event->globalPos()); } @@ -171,3 +190,54 @@ void RiuResultQwtPlot::setDefaults() QwtLegend* legend = new QwtLegend(this); this->insertLegend(legend, BottomLegend); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiuResultQwtPlot::asciiDataForUiSelectedCurves() const +{ + QString out; + + for (std::pair caseIdAndName : m_caseNames) + { + int caseId = caseIdAndName.first; + out += "Case: " + caseIdAndName.second; + out += "\n"; + + for (size_t i = 0; i < m_timeSteps.at(caseId).size(); i++) //time steps & data points + { + if (i == 0) + { + out += "Date and time"; + for (QString curveName : m_curveNames.at(caseId)) + { + out += "\t" + curveName; + } + } + out += "\n"; + out += m_timeSteps.at(caseId)[i].toString("yyyy-MM-dd hh:mm:ss "); + + for (size_t j = 0; j < m_curveData.at(caseId).size(); j++) // curves + { + out += "\t" + QString::number(m_curveData.at(caseId)[j][i], 'g', 6); + } + } + out += "\n\n"; + } + + return out; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuResultQwtPlot::slotCurrentPlotDataInTextDialog() +{ + QString outTxt = asciiDataForUiSelectedCurves(); + + RiuTextDialog* textDialog = new RiuTextDialog(this); + textDialog->setMinimumSize(400, 600); + textDialog->setWindowTitle("Result Plot Data"); + textDialog->setText(outTxt); + textDialog->show(); +} diff --git a/ApplicationCode/UserInterface/RiuResultQwtPlot.h b/ApplicationCode/UserInterface/RiuResultQwtPlot.h index c08250accc..53e792c4f6 100644 --- a/ApplicationCode/UserInterface/RiuResultQwtPlot.h +++ b/ApplicationCode/UserInterface/RiuResultQwtPlot.h @@ -21,6 +21,11 @@ #include "qwt_plot.h" +#include +#include +#include + +class RimCase; class QwtPlotCurve; class QwtPlotGrid; @@ -36,15 +41,19 @@ namespace cvf //================================================================================================== class RiuResultQwtPlot : public QwtPlot { + Q_OBJECT + public: explicit RiuResultQwtPlot(QWidget* parent = NULL); virtual ~RiuResultQwtPlot(); - void addCurve(const QString& curveName, + void addCurve(const RimCase* rimCase, + const QString& curveName, const cvf::Color3f& curveColor, const std::vector& dateTimes, const std::vector& timeHistoryValues); - void addCurve(const QString& curveName, + void addCurve(const RimCase* rimCase, + const QString& curveName, const cvf::Color3f& curveColor, const std::vector& frameTimes, const std::vector& timeHistoryValues); @@ -59,7 +68,17 @@ class RiuResultQwtPlot : public QwtPlot private: void setDefaults(); + QString asciiDataForUiSelectedCurves() const; + +private slots: + void slotCurrentPlotDataInTextDialog(); + private: std::vector m_plotCurves; + + std::map m_caseNames; + std::map > m_timeSteps; + std::map >> m_curveData; + std::map > m_curveNames; }; diff --git a/ApplicationCode/UserInterface/RiuSelectionChangedHandler.cpp b/ApplicationCode/UserInterface/RiuSelectionChangedHandler.cpp index d75604513f..aec9a19a0c 100644 --- a/ApplicationCode/UserInterface/RiuSelectionChangedHandler.cpp +++ b/ApplicationCode/UserInterface/RiuSelectionChangedHandler.cpp @@ -154,7 +154,7 @@ void RiuSelectionChangedHandler::addCurveFromSelectionItem(const RiuEclipseSelec std::vector timeHistoryValues = RigTimeHistoryResultAccessor::timeHistoryValues(eclipseView->eclipseCase()->eclipseCaseData(), eclipseView->cellResult(), eclipseSelectionItem->m_gridIndex, eclipseSelectionItem->m_gridLocalCellIndex, timeStepDates.size()); CVF_ASSERT(timeStepDates.size() == timeHistoryValues.size()); - RiuMainWindow::instance()->resultPlot()->addCurve(curveName, eclipseSelectionItem->m_color, timeStepDates, timeHistoryValues); + RiuMainWindow::instance()->resultPlot()->addCurve(eclipseView->eclipseCase(), curveName, eclipseSelectionItem->m_color, timeStepDates, timeHistoryValues); } } @@ -223,7 +223,7 @@ void RiuSelectionChangedHandler::addCurveFromSelectionItem(const RiuGeoMechSelec std::vector dates = geoMechView->geoMechCase()->timeStepDates(); if (dates.size() == timeHistoryValues.size()) { - RiuMainWindow::instance()->resultPlot()->addCurve(curveName, geomSelectionItem->m_color, dates, timeHistoryValues); + RiuMainWindow::instance()->resultPlot()->addCurve(geoMechView->geoMechCase(), curveName, geomSelectionItem->m_color, dates, timeHistoryValues); } else { @@ -233,7 +233,7 @@ void RiuSelectionChangedHandler::addCurveFromSelectionItem(const RiuGeoMechSelec dummyStepTimes.push_back(i); } - RiuMainWindow::instance()->resultPlot()->addCurve(curveName, geomSelectionItem->m_color, dummyStepTimes, timeHistoryValues); + RiuMainWindow::instance()->resultPlot()->addCurve(geoMechView->geoMechCase(), curveName, geomSelectionItem->m_color, dummyStepTimes, timeHistoryValues); } } }