#1842 RFT Plot. Command enabling criteria. Minor refactoring

This commit is contained in:
Bjørn Erik Jensen 2017-10-05 16:25:04 +02:00
parent d283e3aa8c
commit b6c74ee559
7 changed files with 123 additions and 136 deletions

View File

@ -35,6 +35,7 @@
#include "RimWellPath.h" #include "RimWellPath.h"
#include "RimRftPlotCollection.h" #include "RimRftPlotCollection.h"
#include "RimMainPlotCollection.h" #include "RimMainPlotCollection.h"
#include "RimEclipseResultCase.h"
#include "RiuMainPlotWindow.h" #include "RiuMainPlotWindow.h"
@ -55,9 +56,30 @@ CAF_CMD_SOURCE_INIT(RicNewRftPlotFeature, "RicNewRftPlotFeature");
bool RicNewRftPlotFeature::isCommandEnabled() bool RicNewRftPlotFeature::isCommandEnabled()
{ {
if (RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot()) return false; if (RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot()) return false;
return true;
int branchIndex; //int branchIndex;
return (selectedWellLogPlotTrack() != nullptr || selectedWellPath() != nullptr || selectedSimulationWell(&branchIndex) != nullptr) && caseAvailable();
auto eclWell = selectedPdmObject<RimEclipseWell*>();
auto rimWellPath = eclWell == nullptr ? selectedPdmObject<RimWellPath*>() : nullptr;
bool enable = true;
if (eclWell != nullptr)
{
auto eclCase = selectedPdmObject<RimEclipseResultCase*>();
if (eclWell != nullptr)
{
enable &= RimWellRftPlot::hasPressureData(eclCase);
}
}
else if (rimWellPath)
{
auto wellLogFile = rimWellPath->wellLogFile();
if (wellLogFile != nullptr)
{
enable &= RimWellRftPlot::hasPressureData(wellLogFile);
}
}
return enable;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -65,29 +87,26 @@ bool RicNewRftPlotFeature::isCommandEnabled()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RicNewRftPlotFeature::onActionTriggered(bool isChecked) void RicNewRftPlotFeature::onActionTriggered(bool isChecked)
{ {
if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return; //if (RicWellLogPlotCurveFeatureImpl::parentWellRftPlot()) return;
RimProject* proj = RiaApplication::instance()->project(); RimProject* proj = RiaApplication::instance()->project();
auto rftPlotColl = proj->mainPlotCollection()->rftPlotCollection(); auto rftPlotColl = proj->mainPlotCollection()->rftPlotCollection();
if (rftPlotColl) if (rftPlotColl)
{ {
std::vector<caf::PdmUiItem*> selectedItems; QString wellName;
caf::SelectionManager::instance()->selectedItems(selectedItems);
QString wellName = "(unknown well name)";
RimWellPath* wellPath = nullptr; RimWellPath* wellPath = nullptr;
RimEclipseWell* eclipseWell = nullptr; RimEclipseWell* eclipseWell = nullptr;
if ((wellPath = dynamic_cast<RimWellPath*>(selectedItems.front())) != nullptr) if ((wellPath = selectedPdmObject<RimWellPath*>()) != nullptr)
{ {
wellName = wellPath->name(); wellName = wellPath->name();
} }
else if ((eclipseWell = dynamic_cast<RimEclipseWell*>(selectedItems.front())) != nullptr) else if ((eclipseWell = selectedPdmObject<RimEclipseWell*>()) != nullptr)
{ {
wellName = eclipseWell->name(); wellName = eclipseWell->name();
} }
QString plotName = QString("RFT: %1").arg(wellName); QString plotName = QString(RimWellRftPlot::plotNameFormatString()).arg(wellName);
auto rftPlot = new RimWellRftPlot(); auto rftPlot = new RimWellRftPlot();
rftPlot->setCurrentWellName(wellName); rftPlot->setCurrentWellName(wellName);
@ -171,3 +190,4 @@ bool RicNewRftPlotFeature::caseAvailable() const
return cases.size() > 0; return cases.size() > 0;
} }

View File

@ -47,4 +47,26 @@ private:
RimWellPath* selectedWellPath() const; RimWellPath* selectedWellPath() const;
RimEclipseWell* selectedSimulationWell(int * branchIndex) const; RimEclipseWell* selectedSimulationWell(int * branchIndex) const;
bool caseAvailable() const; bool caseAvailable() const;
template<typename T>
T selectedPdmObject() const;
}; };
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename T>
T RicNewRftPlotFeature::selectedPdmObject() const
{
T objToFind = nullptr;
caf::PdmUiItem* pdmUiItem = caf::SelectionManager::instance()->selectedItem();
caf::PdmObjectHandle* objHandle = dynamic_cast<caf::PdmObjectHandle*>(pdmUiItem);
if (objHandle)
{
objHandle->firstAncestorOrThisOfType(objToFind);
}
return objToFind;
}

View File

@ -71,6 +71,7 @@ CAF_PDM_SOURCE_INIT(RimWellRftPlot, "WellRftPlot");
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
const char RimWellRftPlot::PRESSURE_DATA_NAME[] = "PRESSURE"; const char RimWellRftPlot::PRESSURE_DATA_NAME[] = "PRESSURE";
const char RimWellRftPlot::PLOT_NAME_QFORMAT_STRING[] = "RFT: %1";
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -171,7 +172,7 @@ void RimWellRftPlot::updateWidgetTitleWindowTitle()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RimWellRftPlot::loadDataAndUpdatePlot() void RimWellRftPlot::syncCurvesFromUiSelection()
{ {
auto plotTrack = m_wellLogPlot->trackByIndex(0); auto plotTrack = m_wellLogPlot->trackByIndex(0);
const auto& allCurveDefs = selectedCurveDefs(); const auto& allCurveDefs = selectedCurveDefs();
@ -204,26 +205,6 @@ void RimWellRftPlot::loadDataAndUpdatePlot()
updateCurvesInPlot(allCurveDefs, newCurveDefs, curvesToDelete); updateCurvesInPlot(allCurveDefs, newCurveDefs, curvesToDelete);
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellRftPlot::hasPressureData(RimWellLogFileChannel* channel)
{
// Todo: read pressure channel names from config/defines
return QString::compare(channel->name(), PRESSURE_DATA_NAME) == 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellRftPlot::hasPressureData(RimEclipseResultCase* gridCase)
{
auto eclipseCaseData = gridCase->eclipseCaseData();
size_t resultIndex = eclipseCaseData->results(RiaDefines::MATRIX_MODEL)->
findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, PRESSURE_DATA_NAME);
return resultIndex != cvf::UNDEFINED_SIZE_T;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -239,19 +220,10 @@ std::vector<RimWellPath*> RimWellRftPlot::wellPathsContainingPressure(const QStr
{ {
bool hasPressure = false; bool hasPressure = false;
const auto& wellLogFile = wellPath->wellLogFile(); const auto& wellLogFile = wellPath->wellLogFile();
const auto& wellLogChannels = wellLogFile->wellLogChannelNames();
if (QString::compare(wellLogFile->wellName(), wellName) != 0) continue; if (QString::compare(wellLogFile->wellName(), wellName) != 0) continue;
for (const auto& wellLogChannel : *wellLogChannels) if (hasPressureData(wellLogFile))
{
if (hasPressureData(wellLogChannel))
{
hasPressure = true;
break;
}
}
if (hasPressure)
wellPaths.push_back(wellPath); wellPaths.push_back(wellPath);
} }
} }
@ -510,7 +482,7 @@ void RimWellRftPlot::updateCurvesInPlot(const std::set<std::pair<RimWellRftAddre
} }
} }
} }
m_wellLogPlot->loadDataAndUpdate(); loadDataAndUpdate();
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -553,6 +525,47 @@ QString RimWellRftPlot::currentWellName() const
return m_wellName; return m_wellName;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellRftPlot::hasPressureData(RimWellLogFile* wellLogFile)
{
const auto& wellLogChannels = wellLogFile->wellLogChannelNames();
for (const auto& wellLogChannel : *wellLogChannels)
{
if (hasPressureData(wellLogChannel)) return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellRftPlot::hasPressureData(RimWellLogFileChannel* channel)
{
// Todo: read pressure channel names from config/defines
return QString::compare(channel->name(), PRESSURE_DATA_NAME) == 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimWellRftPlot::hasPressureData(RimEclipseResultCase* gridCase)
{
auto eclipseCaseData = gridCase->eclipseCaseData();
size_t resultIndex = eclipseCaseData->results(RiaDefines::MATRIX_MODEL)->
findScalarResultIndex(RiaDefines::DYNAMIC_NATIVE, PRESSURE_DATA_NAME);
return resultIndex != cvf::UNDEFINED_SIZE_T;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const char* RimWellRftPlot::plotNameFormatString()
{
return PLOT_NAME_QFORMAT_STRING;
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -605,13 +618,21 @@ void RimWellRftPlot::fieldChangedByUi(const caf::PdmFieldHandle* changedField, c
{ {
RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue); RimViewWindow::fieldChangedByUi(changedField, oldValue, newValue);
if (changedField == &m_selectedSources) if (changedField == &m_wellName)
{ {
loadDataAndUpdatePlot(); setDescription(QString(plotNameFormatString()).arg(m_wellName));
}
else if (changedField == &m_selectedSources)
{
syncCurvesFromUiSelection();
} }
else if (changedField == &m_selectedTimeSteps) else if (changedField == &m_selectedTimeSteps)
{ {
loadDataAndUpdatePlot(); syncCurvesFromUiSelection();
}
else if (changedField == &m_showPlotTitle)
{
//m_wellLogPlot->setShowDescription(m_showPlotTitle);
} }
} }
@ -646,7 +667,7 @@ void RimWellRftPlot::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering&
caf::PdmUiGroup* timeStepsGroup = uiOrdering.addNewGroupWithKeyword("Time Steps", "TimeSteps"); caf::PdmUiGroup* timeStepsGroup = uiOrdering.addNewGroupWithKeyword("Time Steps", "TimeSteps");
timeStepsGroup->add(&m_selectedTimeSteps); timeStepsGroup->add(&m_selectedTimeSteps);
uiOrdering.add(&m_showPlotTitle); //uiOrdering.add(&m_showPlotTitle);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -774,14 +795,3 @@ QWidget* RimWellRftPlot::createViewWidget(QWidget* mainWindowParent)
return m_wellLogPlotWidget; return m_wellLogPlotWidget;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::Color3f RimWellRftPlot::getTracerColor(const QString& tracerName)
{
if (tracerName == RIG_FLOW_OIL_NAME) return cvf::Color3f::DARK_GREEN;
if (tracerName == RIG_FLOW_GAS_NAME) return cvf::Color3f::DARK_RED;
if (tracerName == RIG_FLOW_WATER_NAME) return cvf::Color3f::BLUE;
return cvf::Color3f::DARK_GRAY;
}

View File

@ -61,9 +61,7 @@ class RimWellRftPlot : public RimViewWindow
CAF_PDM_HEADER_INIT; CAF_PDM_HEADER_INIT;
static const char PRESSURE_DATA_NAME[]; static const char PRESSURE_DATA_NAME[];
static const char PLOT_NAME_QFORMAT_STRING[];
public:
enum FlowType { ACCUMULATED, INFLOW};
public: public:
RimWellRftPlot(); RimWellRftPlot();
@ -82,6 +80,11 @@ public:
void setCurrentWellName(const QString& currWellName); void setCurrentWellName(const QString& currWellName);
QString currentWellName() const; QString currentWellName() const;
static bool hasPressureData(RimWellLogFile* wellLogFile);
static bool hasPressureData(RimWellLogFileChannel* channel);
static bool hasPressureData(RimEclipseResultCase* gridCase);
static const char* plotNameFormatString();
protected: protected:
// Overridden PDM methods // Overridden PDM methods
virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; }
@ -101,10 +104,8 @@ private:
void updateEditorsFromCurves(); void updateEditorsFromCurves();
void updateWidgetTitleWindowTitle(); void updateWidgetTitleWindowTitle();
void loadDataAndUpdatePlot(); void syncCurvesFromUiSelection();
static bool hasPressureData(RimWellLogFileChannel* channel);
static bool hasPressureData(RimEclipseResultCase* gridCase);
std::vector<RimWellPath*> wellPathsContainingPressure(const QString& wellName) const; std::vector<RimWellPath*> wellPathsContainingPressure(const QString& wellName) const;
std::vector<RimWellLogFileChannel*> getPressureChannelsFromWellPath(const RimWellPath* wellPath) const; std::vector<RimWellLogFileChannel*> getPressureChannelsFromWellPath(const RimWellPath* wellPath) const;
RimEclipseResultCase* gridCaseFromCaseId(int caseId); RimEclipseResultCase* gridCaseFromCaseId(int caseId);
@ -125,14 +126,12 @@ private:
virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual QWidget* createViewWidget(QWidget* mainWindowParent) override;
virtual void deleteViewWidget() override; virtual void deleteViewWidget() override;
cvf::Color3f getTracerColor(const QString& tracerName);
private: private:
caf::PdmField<bool> m_showPlotTitle; caf::PdmField<bool> m_showPlotTitle;
caf::PdmField<QString> m_userName; caf::PdmField<QString> m_userName;
caf::PdmField<QString> m_wellName; caf::PdmField<QString> m_wellName;
caf::PdmField<int> m_branchIndex; // Temp field caf::PdmField<int> m_branchIndex;
caf::PdmField<std::vector<RimWellRftAddress>> m_selectedSources; caf::PdmField<std::vector<RimWellRftAddress>> m_selectedSources;
caf::PdmField<std::vector<QDateTime>> m_selectedTimeSteps; caf::PdmField<std::vector<QDateTime>> m_selectedTimeSteps;

View File

@ -89,6 +89,7 @@
#include <vector> #include <vector>
#include <QMenu> #include <QMenu>
#include "RimRftPlotCollection.h"
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -264,6 +265,10 @@ QStringList RimContextCommandBuilder::commandsFromSelection()
commandIds << "Separator"; commandIds << "Separator";
commandIds << "RicNewWellLogPlotFeature"; commandIds << "RicNewWellLogPlotFeature";
} }
else if (dynamic_cast<RimRftPlotCollection*>(uiItem))
{
commandIds << "RicNewRftPlotFeature";
}
else if (dynamic_cast<RimSummaryPlotCollection*>(uiItem)) else if (dynamic_cast<RimSummaryPlotCollection*>(uiItem))
{ {
commandIds << "RicPasteSummaryPlotFeature"; commandIds << "RicPasteSummaryPlotFeature";

View File

@ -76,24 +76,6 @@ RiuWellRftPlot::RiuWellRftPlot(RimWellRftPlot* plotDefinition, QWidget* parent)
mainLayout->addLayout(plotWidgetsLayout); mainLayout->addLayout(plotWidgetsLayout);
plotWidgetsLayout->addLayout(rightColumnLayout); plotWidgetsLayout->addLayout(rightColumnLayout);
//m_legendWidget = new RiuNightchartsWidget(this);
//new RiuPlotObjectPicker(m_legendWidget, m_plotDefinition->plotLegend());
//QStringList commandIds;
//commandIds << "RicShowTotalAllocationDataFeature";
//new RiuContextMenuLauncher(m_legendWidget, commandIds);
//rightColumnLayout->addWidget(m_legendWidget);
//m_legendWidget->showPie(false);
//QWidget* totalFlowAllocationWidget = m_plotDefinition->totalWellFlowPlot()->createViewWidget(this);
//new RiuPlotObjectPicker(totalFlowAllocationWidget, m_plotDefinition->totalWellFlowPlot());
//new RiuContextMenuLauncher(totalFlowAllocationWidget, commandIds);
//rightColumnLayout->addWidget(totalFlowAllocationWidget, Qt::AlignTop);
//rightColumnLayout->addWidget(m_plotDefinition->tofAccumulatedPhaseFractionsPlot()->createViewWidget(this), Qt::AlignTop);
//rightColumnLayout->addStretch();
QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createViewWidget(this); QWidget* wellFlowWidget = m_plotDefinition->wellLogPlot()->createViewWidget(this);
plotWidgetsLayout->addWidget(wellFlowWidget); plotWidgetsLayout->addWidget(wellFlowWidget);
@ -144,41 +126,6 @@ void RiuWellRftPlot::hideTitle()
m_titleLabel->hide(); m_titleLabel->hide();
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
//void RiuWellRftPlot::showLegend(bool doShow)
//{
// if (doShow)
// m_legendWidget->show();
// else
// m_legendWidget->hide();
//}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
//void RiuWellRftPlot::addLegendItem(const QString& name, const cvf::Color3f& color, float value)
//{
// QColor sliceColor(color.rByte(), color.gByte(), color.bByte());
//
// m_legendWidget->addItem(name, sliceColor, value);
// m_legendWidget->updateGeometry();
// m_legendWidget->update();
//}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
//void RiuWellRftPlot::clearLegend()
//{
// m_legendWidget->clear();
//}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -192,17 +139,6 @@ QSize RiuWellRftPlot::minimumSizeHint() const
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RiuWellRftPlot::contextMenuEvent(QContextMenuEvent* event) void RiuWellRftPlot::contextMenuEvent(QContextMenuEvent* event)
{ {
//QMenu menu;
//QStringList commandIds;
//commandIds << "RicShowContributingWellsFromPlotFeature";
//RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu);
//if (menu.actions().size() > 0)
//{
// menu.exec(event->globalPos());
//}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -219,4 +155,3 @@ QSize RiuWellRftPlot::sizeHint() const
void RiuWellRftPlot::setDefaults() void RiuWellRftPlot::setDefaults()
{ {
} }

View File

@ -53,10 +53,6 @@ public:
void showTitle(const QString& title); void showTitle(const QString& title);
void hideTitle(); void hideTitle();
// void showLegend(bool doShow);
// void addLegendItem(const QString& name, const cvf::Color3f& color, float value);
// void clearLegend();
protected: protected:
virtual QSize sizeHint() const override; virtual QSize sizeHint() const override;