#1321 Added a comand to show Flow Characteristics plot. Added timestp colors, zoom, mouse tracking, and titles

This commit is contained in:
Jacob Støren
2017-03-28 23:35:53 +02:00
parent 960e6833c4
commit ba60bf3c13
15 changed files with 398 additions and 80 deletions

View File

@@ -402,3 +402,30 @@ const caf::ColorTable& RiaColorTables::selectionPaletteColors()
return colorTable; return colorTable;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const caf::ColorTable& RiaColorTables::timestepsPaletteColors()
{
static std::vector<cvf::Color3ub> colors{
cvf::Color3ub( 56, 56, 255), // Vivid Blue
cvf::Color3ub( 0, 143, 239), // Dark Light Blue
cvf::Color3ub( 0, 112, 136), // Dark Green-Blue
cvf::Color3ub( 51, 204, 255), // Bluer Turquoise
cvf::Color3ub( 0, 221, 221), // Turquoise
cvf::Color3ub( 0, 205, 68), // Bluish Green
cvf::Color3ub( 78, 204, 0), // Clear Green
cvf::Color3ub(164, 193, 0), // Mid Yellowish Green
cvf::Color3ub(236, 188, 0), // Mid Yellow
cvf::Color3ub(236, 118, 0), // Orange
cvf::Color3ub(202, 0, 0), // Red
cvf::Color3ub(248, 0, 170), // Magenta
cvf::Color3ub(201, 168, 206), // Light Violet
cvf::Color3ub(169, 2, 240), // Purple
};
static caf::ColorTable colorTable = caf::ColorTable(colors);
return colorTable;
}

View File

@@ -48,4 +48,6 @@ public:
static const caf::ColorTable& summaryCurveNoneRedGreenBlueBrownPaletteColors(); static const caf::ColorTable& summaryCurveNoneRedGreenBlueBrownPaletteColors();
static const caf::ColorTable& wellLogPlotPaletteColors(); static const caf::ColorTable& wellLogPlotPaletteColors();
static const caf::ColorTable& selectionPaletteColors(); static const caf::ColorTable& selectionPaletteColors();
static const caf::ColorTable& timestepsPaletteColors();
}; };

View File

@@ -6,6 +6,7 @@ endif()
set (SOURCE_GROUP_HEADER_FILES set (SOURCE_GROUP_HEADER_FILES
${CEE_CURRENT_LIST_DIR}RicShowWellAllocationPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicShowWellAllocationPlotFeature.h
${CEE_CURRENT_LIST_DIR}RicShowFlowCharacteristicsPlotFeature.h
${CEE_CURRENT_LIST_DIR}RicAddStoredWellAllocationPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicAddStoredWellAllocationPlotFeature.h
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.h ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.h
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.h ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.h
@@ -16,6 +17,7 @@ ${CEE_CURRENT_LIST_DIR}RicSelectViewUI.h
set (SOURCE_GROUP_SOURCE_FILES set (SOURCE_GROUP_SOURCE_FILES
${CEE_CURRENT_LIST_DIR}RicShowWellAllocationPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicShowWellAllocationPlotFeature.cpp
${CEE_CURRENT_LIST_DIR}RicShowFlowCharacteristicsPlotFeature.cpp
${CEE_CURRENT_LIST_DIR}RicAddStoredWellAllocationPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicAddStoredWellAllocationPlotFeature.cpp
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.cpp ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.cpp
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.cpp ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.cpp

View File

@@ -47,7 +47,7 @@ bool RicAddStoredWellAllocationPlotFeature::isCommandEnabled()
{ {
RimWellAllocationPlot* wellAllocationPlot = dynamic_cast<RimWellAllocationPlot*>(caf::SelectionManager::instance()->selectedItem()); RimWellAllocationPlot* wellAllocationPlot = dynamic_cast<RimWellAllocationPlot*>(caf::SelectionManager::instance()->selectedItem());
if (flowPlotColl->defaultPlot() == wellAllocationPlot) if (flowPlotColl->defaultWellAllocPlot() == wellAllocationPlot)
{ {
return true; return true;
} }
@@ -72,7 +72,7 @@ void RicAddStoredWellAllocationPlotFeature::onActionTriggered(bool isChecked)
RimWellAllocationPlot* wellAllocationPlot = dynamic_cast<RimWellAllocationPlot*>(sourceObject->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance())); RimWellAllocationPlot* wellAllocationPlot = dynamic_cast<RimWellAllocationPlot*>(sourceObject->copyByXmlSerialization(caf::PdmDefaultObjectFactory::instance()));
CVF_ASSERT(wellAllocationPlot); CVF_ASSERT(wellAllocationPlot);
flowPlotColl->addPlot(wellAllocationPlot); flowPlotColl->addWellAllocPlotToStoredPlots(wellAllocationPlot);
wellAllocationPlot->resolveReferencesRecursively(); wellAllocationPlot->resolveReferencesRecursively();
wellAllocationPlot->loadDataAndUpdate(); wellAllocationPlot->loadDataAndUpdate();

View File

@@ -0,0 +1,98 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RicShowFlowCharacteristicsPlotFeature.h"
#include "RiaApplication.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "RimFlowCharacteristicsPlot.h"
#include "RimFlowPlotCollection.h"
#include "RimMainPlotCollection.h"
#include "RimProject.h"
#include "RimView.h"
#include "RiuMainPlotWindow.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicShowFlowCharacteristicsPlotFeature, "RicShowFlowCharacteristicsPlotFeature");
RimEclipseResultCase* activeEclipseResultCase()
{
RimView * activeView = RiaApplication::instance()->activeReservoirView();
auto eclView = dynamic_cast<RimEclipseView*>(activeView);
if (!eclView) return nullptr;
auto eclCase = dynamic_cast<RimEclipseResultCase*>(eclView->ownerCase());
return eclCase;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicShowFlowCharacteristicsPlotFeature::isCommandEnabled()
{
RimEclipseResultCase* eclCase = activeEclipseResultCase();
if (!eclCase) return false;
if (!eclCase->defaultFlowDiagSolution()) return false;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicShowFlowCharacteristicsPlotFeature::onActionTriggered(bool isChecked)
{
RimEclipseResultCase* eclCase = activeEclipseResultCase();
if (eclCase && eclCase->defaultFlowDiagSolution())
{
if (RiaApplication::instance()->project())
{
RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection();
if (flowPlotColl)
{
RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();
flowPlotColl->defaultFlowCharacteristicsPlot()->setFromFlowSolution(eclCase->defaultFlowDiagSolution());
flowPlotColl->defaultFlowCharacteristicsPlot()->updateConnectedEditors();
// Make sure the summary plot window is created and visible
plotwindow->selectAsCurrentItem(flowPlotColl->defaultFlowCharacteristicsPlot());
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicShowFlowCharacteristicsPlotFeature::setupActionLook(QAction* actionToSetup)
{
actionToSetup->setIcon(QIcon(":/WellAllocPlot16x16.png"));
actionToSetup->setText("Plot Flow Characteristics");
}

View File

@@ -0,0 +1,40 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cafCmdFeature.h"
class RimEclipseWell;
//==================================================================================================
///
//==================================================================================================
class RicShowFlowCharacteristicsPlotFeature : public caf::CmdFeature
{
CAF_CMD_HEADER_INIT;
protected:
// Overrides
virtual bool isCommandEnabled() override;
virtual void onActionTriggered( bool isChecked ) override;
virtual void setupActionLook( QAction* actionToSetup ) override;
};

View File

@@ -69,12 +69,12 @@ void RicShowWellAllocationPlotFeature::onActionTriggered(bool isChecked)
RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection(); RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection();
if (flowPlotColl) if (flowPlotColl)
{ {
flowPlotColl->defaultPlot()->setFromSimulationWell(eclWell); flowPlotColl->defaultWellAllocPlot()->setFromSimulationWell(eclWell);
flowPlotColl->defaultPlot()->updateConnectedEditors(); flowPlotColl->defaultWellAllocPlot()->updateConnectedEditors();
// Make sure the summary plot window is created and visible // Make sure the summary plot window is created and visible
RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow(); RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow();
plotwindow->selectAsCurrentItem(flowPlotColl->defaultPlot()); plotwindow->selectAsCurrentItem(flowPlotColl->defaultWellAllocPlot());
} }
} }
} }

View File

@@ -74,6 +74,7 @@ void RimFlowCharacteristicsPlot::setFromFlowSolution(RimFlowDiagSolution* flowSo
} }
m_flowDiagSolution = flowSolution; m_flowDiagSolution = flowSolution;
m_showWindow = true;
loadDataAndUpdate(); loadDataAndUpdate();
} }
@@ -143,6 +144,7 @@ QWidget* RimFlowCharacteristicsPlot::viewWidget()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimFlowCharacteristicsPlot::zoomAll() void RimFlowCharacteristicsPlot::zoomAll()
{ {
if (m_flowCharPlotWidget) m_flowCharPlotWidget->zoomAll();
} }
@@ -187,7 +189,7 @@ void RimFlowCharacteristicsPlot::loadDataAndUpdate()
{ {
updateMdiWindowVisibility(); updateMdiWindowVisibility();
if (m_flowDiagSolution) if (m_flowDiagSolution && m_flowCharPlotWidget)
{ {
RigFlowDiagResults* flowResult = m_flowDiagSolution->flowDiagResults(); RigFlowDiagResults* flowResult = m_flowDiagSolution->flowDiagResults();
std::vector<int> calculatedTimesteps = flowResult->calculatedTimeSteps(); std::vector<int> calculatedTimesteps = flowResult->calculatedTimeSteps();
@@ -195,23 +197,26 @@ void RimFlowCharacteristicsPlot::loadDataAndUpdate()
std::vector<QDateTime> timeStepDates = m_case->timeStepDates(); std::vector<QDateTime> timeStepDates = m_case->timeStepDates();
std::vector<double> lorenzVals(timeStepDates.size(), HUGE_VAL); std::vector<double> lorenzVals(timeStepDates.size(), HUGE_VAL);
for (int timeStepIdx: calculatedTimesteps) m_flowCharPlotWidget->removeAllCurves();
{
lorenzVals[timeStepIdx] = flowResult->flowCharacteristicsResults(timeStepIdx).m_lorenzCoefficient;
if ( m_flowCharPlotWidget) for ( int timeStepIdx: calculatedTimesteps )
{ {
const auto & flowCharResults = flowResult->flowCharacteristicsResults(timeStepIdx); lorenzVals[timeStepIdx] = flowResult->flowCharacteristicsResults(timeStepIdx).m_lorenzCoefficient;
m_flowCharPlotWidget->addFlowCapStorageCapCurve(timeStepDates[timeStepIdx], }
flowCharResults.m_flowCapStorageCapCurve.first, m_flowCharPlotWidget->setLorenzCurve(timeStepDates, lorenzVals);
flowCharResults.m_flowCapStorageCapCurve.second);
m_flowCharPlotWidget->addSweepEfficiencyCurve(timeStepDates[timeStepIdx], for ( int timeStepIdx: calculatedTimesteps )
flowCharResults.m_sweepEfficiencyCurve.first, {
flowCharResults.m_sweepEfficiencyCurve.second);
} const auto & flowCharResults = flowResult->flowCharacteristicsResults(timeStepIdx);
m_flowCharPlotWidget->addFlowCapStorageCapCurve(timeStepDates[timeStepIdx],
flowCharResults.m_flowCapStorageCapCurve.first,
flowCharResults.m_flowCapStorageCapCurve.second);
m_flowCharPlotWidget->addSweepEfficiencyCurve(timeStepDates[timeStepIdx],
flowCharResults.m_sweepEfficiencyCurve.first,
flowCharResults.m_sweepEfficiencyCurve.second);
} }
if ( m_flowCharPlotWidget) m_flowCharPlotWidget->setLorenzCurve(timeStepDates, lorenzVals);
} }
} }

View File

@@ -62,8 +62,6 @@ public:
virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual QWidget* createViewWidget(QWidget* mainWindowParent) override;
virtual void deleteViewWidget() override; virtual void deleteViewWidget() override;
protected: protected:
// RimViewWindow overrides // RimViewWindow overrides

View File

@@ -36,12 +36,11 @@ RimFlowPlotCollection::RimFlowPlotCollection()
CAF_PDM_InitFieldNoDefault(&m_flowCharacteristicsPlot, "FlowCharacteristicsPlot", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_flowCharacteristicsPlot, "FlowCharacteristicsPlot", "", "", "", "");
m_flowCharacteristicsPlot.uiCapability()->setUiHidden(true); m_flowCharacteristicsPlot.uiCapability()->setUiHidden(true);
m_flowCharacteristicsPlot = new RimFlowCharacteristicsPlot;
CAF_PDM_InitFieldNoDefault(&m_defaultPlot, "DefaultFlowPlot", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_defaultWellAllocPlot, "DefaultFlowPlot", "", "", "", "");
m_defaultPlot.uiCapability()->setUiHidden(true); m_defaultWellAllocPlot.uiCapability()->setUiHidden(true);
CAF_PDM_InitFieldNoDefault(&m_flowPlots, "FlowPlots", "Stored Plots", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_storedWellAllocPlots, "FlowPlots", "Stored Plots", "", "", "");
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -49,9 +48,9 @@ RimFlowPlotCollection::RimFlowPlotCollection()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimFlowPlotCollection::~RimFlowPlotCollection() RimFlowPlotCollection::~RimFlowPlotCollection()
{ {
delete m_defaultPlot(); delete m_defaultWellAllocPlot();
m_flowPlots.deleteAllChildObjects(); m_storedWellAllocPlots.deleteAllChildObjects();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -59,12 +58,12 @@ RimFlowPlotCollection::~RimFlowPlotCollection()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimFlowPlotCollection::closeDefaultPlotWindowAndDeletePlots() void RimFlowPlotCollection::closeDefaultPlotWindowAndDeletePlots()
{ {
if ( m_defaultPlot ) if ( m_defaultWellAllocPlot )
{ {
m_defaultPlot->removeFromMdiAreaAndDeleteViewWidget(); m_defaultWellAllocPlot->removeFromMdiAreaAndDeleteViewWidget();
delete m_defaultPlot(); delete m_defaultWellAllocPlot();
} }
m_flowPlots.deleteAllChildObjects(); m_storedWellAllocPlots.deleteAllChildObjects();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -72,12 +71,12 @@ void RimFlowPlotCollection::closeDefaultPlotWindowAndDeletePlots()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimFlowPlotCollection::loadDataAndUpdate() void RimFlowPlotCollection::loadDataAndUpdate()
{ {
caf::ProgressInfo plotProgress(m_flowPlots.size() + 1, ""); caf::ProgressInfo plotProgress(m_storedWellAllocPlots.size() + 1, "");
if (m_defaultPlot) m_defaultPlot->loadDataAndUpdate(); if (m_defaultWellAllocPlot) m_defaultWellAllocPlot->loadDataAndUpdate();
plotProgress.incrementProgress(); plotProgress.incrementProgress();
for (RimWellAllocationPlot* p : m_flowPlots) for (RimWellAllocationPlot* p : m_storedWellAllocPlots)
{ {
p->loadDataAndUpdate(); p->loadDataAndUpdate();
plotProgress.incrementProgress(); plotProgress.incrementProgress();
@@ -90,31 +89,46 @@ void RimFlowPlotCollection::loadDataAndUpdate()
size_t RimFlowPlotCollection::plotCount() const size_t RimFlowPlotCollection::plotCount() const
{ {
size_t plotCount = 0; size_t plotCount = 0;
if (m_defaultPlot) plotCount = 1; if (m_defaultWellAllocPlot) plotCount = 1;
plotCount += m_flowPlots.size(); plotCount += m_storedWellAllocPlots.size();
return plotCount; return plotCount;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimFlowPlotCollection::addPlot(RimWellAllocationPlot* plot) void RimFlowPlotCollection::addWellAllocPlotToStoredPlots(RimWellAllocationPlot* plot)
{ {
m_flowPlots.push_back(plot); m_storedWellAllocPlots.push_back(plot);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimWellAllocationPlot* RimFlowPlotCollection::defaultPlot() RimWellAllocationPlot* RimFlowPlotCollection::defaultWellAllocPlot()
{ {
if ( !m_defaultPlot() ) if ( !m_defaultWellAllocPlot() )
{ {
m_defaultPlot = new RimWellAllocationPlot; m_defaultWellAllocPlot = new RimWellAllocationPlot;
m_defaultPlot->setDescription("Default Flow Diagnostics Plot"); m_defaultWellAllocPlot->setDescription("Default Flow Diagnostics Plot");
} }
this->updateConnectedEditors(); this->updateConnectedEditors();
return m_defaultPlot(); return m_defaultWellAllocPlot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFlowCharacteristicsPlot* RimFlowPlotCollection::defaultFlowCharacteristicsPlot()
{
if ( !m_flowCharacteristicsPlot() )
{
m_flowCharacteristicsPlot = new RimFlowCharacteristicsPlot;
}
this->updateConnectedEditors();
return m_flowCharacteristicsPlot();
} }

View File

@@ -40,11 +40,12 @@ public:
void loadDataAndUpdate(); void loadDataAndUpdate();
size_t plotCount() const; size_t plotCount() const;
void addPlot(RimWellAllocationPlot* plot); void addWellAllocPlotToStoredPlots(RimWellAllocationPlot* plot);
RimWellAllocationPlot* defaultPlot(); RimWellAllocationPlot* defaultWellAllocPlot();
RimFlowCharacteristicsPlot* defaultFlowCharacteristicsPlot();
private: private:
caf::PdmChildField<RimFlowCharacteristicsPlot*> m_flowCharacteristicsPlot; caf::PdmChildField<RimFlowCharacteristicsPlot*> m_flowCharacteristicsPlot;
caf::PdmChildField<RimWellAllocationPlot*> m_defaultPlot; caf::PdmChildField<RimWellAllocationPlot*> m_defaultWellAllocPlot;
caf::PdmChildArrayField<RimWellAllocationPlot*> m_flowPlots; caf::PdmChildArrayField<RimWellAllocationPlot*> m_storedWellAllocPlots;
}; };

View File

@@ -34,6 +34,7 @@
#include "RimEclipseView.h" #include "RimEclipseView.h"
#include "RimEclipseWell.h" #include "RimEclipseWell.h"
#include "RimFault.h" #include "RimFault.h"
#include "RimFlowDiagSolution.h"
#include "RimFormationNames.h" #include "RimFormationNames.h"
#include "RimFormationNamesCollection.h" #include "RimFormationNamesCollection.h"
#include "RimGeoMechCase.h" #include "RimGeoMechCase.h"
@@ -137,6 +138,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
commandIds << "Separator"; commandIds << "Separator";
commandIds << "RicNewViewFeature"; commandIds << "RicNewViewFeature";
commandIds << "RicShowFlowCharacteristicsPlotFeature";
commandIds << "RicEclipseCaseNewGroupFeature"; commandIds << "RicEclipseCaseNewGroupFeature";
commandIds << "Separator"; commandIds << "Separator";
commandIds << "RicCopyReferencesToClipboardFeature"; commandIds << "RicCopyReferencesToClipboardFeature";
@@ -353,6 +355,10 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
{ {
commandIds << "RicAddStoredWellAllocationPlotFeature"; commandIds << "RicAddStoredWellAllocationPlotFeature";
} }
else if (dynamic_cast<RimFlowDiagSolution*>(uiItem))
{
commandIds << "RicShowFlowCharacteristicsPlotFeature";
}
if (dynamic_cast<RimView*>(uiItem)) if (dynamic_cast<RimView*>(uiItem))

View File

@@ -30,6 +30,12 @@
#include <QMenu> #include <QMenu>
#include "RiuLineSegmentQwtPlotCurve.h" #include "RiuLineSegmentQwtPlotCurve.h"
#include <QDateTime> #include <QDateTime>
#include "RiuSummaryQwtPlot.h"
#include "RiuQwtPlotWheelZoomer.h"
#include "qwt_plot_zoomer.h"
#include "RiaColorTables.h"
#include "qwt_plot_zoneitem.h"
#include "qwt_date.h"
@@ -42,10 +48,10 @@ RiuFlowCharacteristicsPlot::RiuFlowCharacteristicsPlot(RimFlowCharacteristicsPlo
{ {
Q_ASSERT(m_plotDefinition); Q_ASSERT(m_plotDefinition);
QVBoxLayout* mainLayout = new QVBoxLayout(); QGridLayout* mainLayout = new QGridLayout();
this->setLayout(mainLayout); this->setLayout(mainLayout);
this->layout()->setMargin(0); this->layout()->setMargin(3);
this->layout()->setSpacing(2); this->layout()->setSpacing(3);
// White background // White background
QPalette pal = this->palette(); QPalette pal = this->palette();
@@ -53,15 +59,39 @@ RiuFlowCharacteristicsPlot::RiuFlowCharacteristicsPlot(RimFlowCharacteristicsPlo
this->setAutoFillBackground(true); this->setAutoFillBackground(true);
this->setPalette(pal); this->setPalette(pal);
m_lorenzPlot = new RiuResultQwtPlot(this); m_lorenzPlot = new QwtPlot(this);
m_flowCapVsStorageCapPlot = new RiuResultQwtPlot(this); m_flowCapVsStorageCapPlot = new QwtPlot(this);
m_sweepEffPlot = new RiuResultQwtPlot(this); m_sweepEffPlot = new QwtPlot(this);
mainLayout->addWidget(m_lorenzPlot);
mainLayout->addWidget(m_flowCapVsStorageCapPlot); mainLayout->addWidget(m_lorenzPlot, 0 ,0, 1, 2);
mainLayout->addWidget(m_sweepEffPlot); mainLayout->addWidget(m_flowCapVsStorageCapPlot, 1, 0);
mainLayout->addWidget(m_sweepEffPlot, 1, 1);
RiuSummaryQwtPlot::setCommonPlotBehaviour(m_lorenzPlot);
new RiuQwtPlotWheelZoomer(m_lorenzPlot);
addWindowZoom(m_lorenzPlot);
RiuSummaryQwtPlot::enableDateBasedBottomXAxis(m_lorenzPlot);
m_lorenzPlot->setTitle("Lorenz Coefficient");
RiuSummaryQwtPlot::setCommonPlotBehaviour(m_sweepEffPlot);
new RiuQwtPlotWheelZoomer(m_sweepEffPlot);
addWindowZoom(m_sweepEffPlot);
m_sweepEffPlot->setTitle("Sweep Efficiency");
RiuSummaryQwtPlot::setCommonPlotBehaviour(m_flowCapVsStorageCapPlot);
new RiuQwtPlotWheelZoomer(m_flowCapVsStorageCapPlot);
addWindowZoom(m_flowCapVsStorageCapPlot);
m_flowCapVsStorageCapPlot->setTitle("Flow Capacity vs Storage Capacity");
} }
void RiuFlowCharacteristicsPlot::addWindowZoom(QwtPlot* plot)
{
auto zoomer = new QwtPlotZoomer(plot->canvas());
zoomer->setRubberBandPen(QColor(Qt::black));
zoomer->setTrackerMode(QwtPicker::AlwaysOff);
zoomer->setTrackerPen(QColor(Qt::black));
zoomer->initMousePattern(1);
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -78,8 +108,56 @@ RiuFlowCharacteristicsPlot::~RiuFlowCharacteristicsPlot()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::setLorenzCurve(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues) void RiuFlowCharacteristicsPlot::setLorenzCurve(const std::vector<QDateTime>& dateTimes, const std::vector<double>& timeHistoryValues)
{ {
m_lorenzPlot->deleteAllCurves(); initializeColors(dateTimes);
m_lorenzPlot->addCurve("Lorenz Coefficient", cvf::Color3f::BLUE, dateTimes, timeHistoryValues);
m_lorenzPlot->detachItems(QwtPlotItem::Rtti_PlotCurve, true);
auto curve = createEmptyCurve(m_lorenzPlot, "Lorenz Coefficient", QColor(0, 0, 0));
curve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
//curve->setSymbol(QwtSymbol )
//size_t tsIdx = 0;
//for ( const QDateTime& dateTime: dateTimes )
//{
// auto curve = createEmptyCurve(m_lorenzPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
// std::vector<QDateTime> timeStep;
// timeStep.push_back(dateTime);
// std::vector<double> lorCoeff;
// lorCoeff.push_back(timeHistoryValues[tsIdx]);
//
// curve->setSamplesFromDateAndValues(timeStep, lorCoeff, false);
//
// ++tsIdx;
//}
//double milliSecSinceEpoch = QwtDate::toDouble(filteredDateTimes[i]);
for ( size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx )
{
double currentTsValue = QwtDate::toDouble(dateTimes[tsIdx]);
double minTsValue = currentTsValue;
if ( tsIdx > 0 ) minTsValue = 0.5 * (currentTsValue + QwtDate::toDouble(dateTimes[tsIdx-1]));
double maxTsValue = currentTsValue;
if ( tsIdx < dateTimes.size()-1 ) maxTsValue = 0.5 * (currentTsValue + QwtDate::toDouble(dateTimes[tsIdx+1]));
auto plotZone = new QwtPlotZoneItem();
plotZone->setOrientation(Qt::Vertical);
plotZone->setInterval(minTsValue, maxTsValue);
plotZone->setBrush(QBrush(m_dateToColorMap[dateTimes[tsIdx]]));
plotZone->attach(m_lorenzPlot);
}
m_lorenzPlot->replot();
}
RiuLineSegmentQwtPlotCurve* RiuFlowCharacteristicsPlot::createEmptyCurve(QwtPlot* plot, const QString& curveName, const QColor& curveColor )
{
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve(curveName);
plotCurve->setTitle(curveName);
plotCurve->setPen(QPen(curveColor));
plotCurve->attach(plot);
return plotCurve;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -87,16 +165,10 @@ void RiuFlowCharacteristicsPlot::setLorenzCurve(const std::vector<QDateTime>& da
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::addFlowCapStorageCapCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals) void RiuFlowCharacteristicsPlot::addFlowCapStorageCapCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals)
{ {
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve(dateTime.toString()); CVF_ASSERT(!m_dateToColorMap.empty());
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_flowCapVsStorageCapPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false); plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false);
plotCurve->setTitle(dateTime.toString());
plotCurve->setPen(QPen(QColor(180, 0, 20)));
plotCurve->attach(m_flowCapVsStorageCapPlot);
m_flowCapVsStorageCapPlot->setAxisScale( QwtPlot::xBottom, 0.0, 1.0);
m_flowCapVsStorageCapPlot->replot(); m_flowCapVsStorageCapPlot->replot();
} }
@@ -105,19 +177,42 @@ void RiuFlowCharacteristicsPlot::addFlowCapStorageCapCurve(const QDateTime& date
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::addSweepEfficiencyCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals) void RiuFlowCharacteristicsPlot::addSweepEfficiencyCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals)
{ {
RiuLineSegmentQwtPlotCurve* plotCurve = new RiuLineSegmentQwtPlotCurve(dateTime.toString()); CVF_ASSERT(!m_dateToColorMap.empty());
RiuLineSegmentQwtPlotCurve* plotCurve = createEmptyCurve(m_sweepEffPlot, dateTime.toString(), m_dateToColorMap[dateTime]);
plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false); plotCurve->setSamplesFromTimeAndValues(xVals, yVals, false);
plotCurve->setTitle(dateTime.toString());
plotCurve->setPen(QPen(QColor(180, 0, 20)));
plotCurve->attach(m_sweepEffPlot);
//m_sweepEffPlot->setAxisScale( QwtPlot::xBottom, 0.0, 1.0);
m_sweepEffPlot->replot(); m_sweepEffPlot->replot();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::removeAllCurves()
{
m_lorenzPlot->detachItems(QwtPlotItem::Rtti_PlotCurve, true);
m_sweepEffPlot->detachItems(QwtPlotItem::Rtti_PlotCurve, true);
m_flowCapVsStorageCapPlot->detachItems(QwtPlotItem::Rtti_PlotCurve, true);
m_dateToColorMap.clear();
}
void zoomAllInPlot(QwtPlot * plot)
{
plot->setAxisAutoScale(QwtPlot::xBottom, true);
plot->setAxisAutoScale(QwtPlot::yLeft, true);
plot->replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::zoomAll()
{
zoomAllInPlot(m_lorenzPlot);
zoomAllInPlot(m_sweepEffPlot);
zoomAllInPlot(m_flowCapVsStorageCapPlot);
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -152,3 +247,19 @@ void RiuFlowCharacteristicsPlot::setDefaults()
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::initializeColors(const std::vector<QDateTime>& dateTimes)
{
CVF_ASSERT(m_dateToColorMap.empty());
const caf::ColorTable& palette = RiaColorTables::timestepsPaletteColors();
cvf::Color3ubArray colorArray = caf::ColorTable::interpolateColorArray(palette.color3ubArray(), dateTimes.size());
for (size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx)
{
m_dateToColorMap[dateTimes[tsIdx]] = QColor( colorArray[tsIdx].r(), colorArray[tsIdx].g(), colorArray[tsIdx].b());
}
}

View File

@@ -28,6 +28,7 @@
class RimFlowCharacteristicsPlot; class RimFlowCharacteristicsPlot;
class RiuNightchartsWidget; class RiuNightchartsWidget;
class RiuResultQwtPlot; class RiuResultQwtPlot;
class RiuLineSegmentQwtPlotCurve;
class QLabel; class QLabel;
@@ -51,8 +52,14 @@ public:
void addFlowCapStorageCapCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals); void addFlowCapStorageCapCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals);
void addSweepEfficiencyCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals); void addSweepEfficiencyCurve(const QDateTime& dateTime, const std::vector<double>& xVals, const std::vector<double>& yVals);
void removeAllCurves();
void zoomAll();
RimFlowCharacteristicsPlot* ownerPlotDefinition(); RimFlowCharacteristicsPlot* ownerPlotDefinition();
static void addWindowZoom(QwtPlot* plot);
static RiuLineSegmentQwtPlotCurve* createEmptyCurve(QwtPlot* plot, const QString& curveName, const QColor& curveColor);
protected: protected:
virtual QSize sizeHint() const override; virtual QSize sizeHint() const override;
virtual QSize minimumSizeHint() const override; virtual QSize minimumSizeHint() const override;
@@ -60,11 +67,16 @@ protected:
private: private:
void setDefaults(); void setDefaults();
void initializeColors(const std::vector<QDateTime>& dateTimes);
private: private:
caf::PdmPointer<RimFlowCharacteristicsPlot> m_plotDefinition; caf::PdmPointer<RimFlowCharacteristicsPlot> m_plotDefinition;
QPointer<RiuResultQwtPlot> m_lorenzPlot; QPointer<QwtPlot> m_lorenzPlot;
QPointer<RiuResultQwtPlot> m_flowCapVsStorageCapPlot; QPointer<QwtPlot> m_flowCapVsStorageCapPlot;
QPointer<RiuResultQwtPlot> m_sweepEffPlot; QPointer<QwtPlot> m_sweepEffPlot;
std::map<QDateTime, QColor> m_dateToColorMap;
}; };

View File

@@ -328,6 +328,8 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event)
commandIds << "Separator"; commandIds << "Separator";
commandIds << "RicNewGridTimeHistoryCurveFeature"; commandIds << "RicNewGridTimeHistoryCurveFeature";
commandIds << "RicShowFlowCharacteristicsPlotFeature";
RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu); RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu);