Skip to content

Commit

Permalink
#2501 Result Plot: Add "Show Plot Data" to context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Cox committed Feb 19, 2018
1 parent 4d39136 commit 119752b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ApplicationCode/ProjectDataModel/Summary/RimSummaryPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ class RimSummaryPlot : public RimViewWindow

protected:
// Overridden PDM methods
virtual caf::PdmFieldHandle* userDescriptionField();
virtual caf::PdmFieldHandle* userDescriptionField() override;
virtual QList<caf::PdmOptionItemInfo> 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;

Expand Down
1 change: 1 addition & 0 deletions ApplicationCode/UserInterface/CMakeLists_files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 77 additions & 7 deletions ApplicationCode/UserInterface/RiuResultQwtPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -41,7 +44,6 @@

#include <QMenu>
#include <QContextMenuEvent>
#include "RiuSummaryQwtPlot.h"


//--------------------------------------------------------------------------------------------------
Expand All @@ -64,7 +66,7 @@ RiuResultQwtPlot::~RiuResultQwtPlot()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuResultQwtPlot::addCurve(const QString& curveName, const cvf::Color3f& curveColor, const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues)
void RiuResultQwtPlot::addCurve(const RimCase* rimCase, const QString& curveName, const cvf::Color3f& curveColor, const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues)
{
if (dateTimes.empty() || timeHistoryValues.empty())
{
Expand All @@ -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<double>& frameTimes, const std::vector<double>& timeHistoryValues)
void RiuResultQwtPlot::addCurve(const RimCase* rimCase, const QString& curveName, const cvf::Color3f& curveColor, const std::vector<double>& frameTimes, const std::vector<double>& timeHistoryValues)
{
std::vector<QDateTime> 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);
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -113,6 +122,11 @@ void RiuResultQwtPlot::deleteAllCurves()
}

m_plotCurves.clear();

m_caseNames.clear();
m_curveNames.clear();
m_curveData.clear();
m_timeSteps.clear();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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<int, QString> 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();
}
23 changes: 21 additions & 2 deletions ApplicationCode/UserInterface/RiuResultQwtPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@

#include "qwt_plot.h"

#include <map>
#include <vector>
#include <QString>

class RimCase;
class QwtPlotCurve;
class QwtPlotGrid;

Expand All @@ -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<QDateTime>& dateTimes,
const std::vector<double>& timeHistoryValues);
void addCurve(const QString& curveName,
void addCurve(const RimCase* rimCase,
const QString& curveName,
const cvf::Color3f& curveColor,
const std::vector<double>& frameTimes,
const std::vector<double>& timeHistoryValues);
Expand All @@ -59,7 +68,17 @@ class RiuResultQwtPlot : public QwtPlot
private:
void setDefaults();

QString asciiDataForUiSelectedCurves() const;

private slots:
void slotCurrentPlotDataInTextDialog();

private:
std::vector<QwtPlotCurve*> m_plotCurves;

std::map<int, QString > m_caseNames;
std::map<int, std::vector< QDateTime> > m_timeSteps;
std::map<int, std::vector< std::vector<double> >> m_curveData;
std::map<int, std::vector< QString> > m_curveNames;
};

6 changes: 3 additions & 3 deletions ApplicationCode/UserInterface/RiuSelectionChangedHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void RiuSelectionChangedHandler::addCurveFromSelectionItem(const RiuEclipseSelec
std::vector<double> 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);
}
}

Expand Down Expand Up @@ -223,7 +223,7 @@ void RiuSelectionChangedHandler::addCurveFromSelectionItem(const RiuGeoMechSelec
std::vector<QDateTime> 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
{
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 119752b

Please sign in to comment.