#1288 Added RicSelectViewUI and harmonized features

This commit is contained in:
Magne Sjaastad 2017-03-09 23:01:45 +01:00
parent 40a5f8dc02
commit 2ed5ff7fb7
8 changed files with 285 additions and 131 deletions

View File

@ -11,6 +11,7 @@ ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.h
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.h
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeatureImpl.h
${CEE_CURRENT_LIST_DIR}RicPlotProductionRateFeature.h
${CEE_CURRENT_LIST_DIR}RicSelectViewUI.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -20,8 +21,10 @@ ${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFromPlotFeature.cpp
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeature.cpp
${CEE_CURRENT_LIST_DIR}RicShowContributingWellsFeatureImpl.cpp
${CEE_CURRENT_LIST_DIR}RicPlotProductionRateFeature.cpp
${CEE_CURRENT_LIST_DIR}RicSelectViewUI.cpp
)
list(APPEND CODE_HEADER_FILES
${SOURCE_GROUP_HEADER_FILES}
)

View File

@ -0,0 +1,132 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicSelectViewUI.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
CAF_PDM_SOURCE_INIT(RicSelectViewUI, "RicSelectViewUI");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RicSelectViewUI::RicSelectViewUI()
{
CAF_PDM_InitObject("RicSelectViewUI", "", "", "");
CAF_PDM_InitFieldNoDefault(&m_selectedView, "MasterView", "Select view", "", "", "");
CAF_PDM_InitField(&m_createNewView, "CreateNewView", false, "Create New View", "", "", "");
CAF_PDM_InitField(&m_newViewName, "NewViewName", QString("ShowContributingWells"), "New View Name", "", "", "");
m_currentView = nullptr;
m_currentCase = nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectViewUI::setView(RimEclipseView* currentView)
{
m_currentView = currentView;
m_currentView->firstAncestorOrThisOfTypeAsserted(m_currentCase);
m_selectedView = m_currentView;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectViewUI::setCase(RimEclipseResultCase* currentCase)
{
m_currentCase = currentCase;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimEclipseView* RicSelectViewUI::selectedView() const
{
return m_selectedView();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicSelectViewUI::createNewView() const
{
return m_createNewView;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RicSelectViewUI::newViewName() const
{
return m_newViewName;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RicSelectViewUI::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly)
{
QList<caf::PdmOptionItemInfo> options;
if (fieldNeedingOptions == &m_selectedView)
{
QIcon icon;
if (m_currentCase)
{
icon = m_currentCase->uiCapability()->uiIcon();
for (RimView* v : m_currentCase->views())
{
QString displayName = m_currentCase->caseUserDescription() + ": " + v->name;
options.push_back(caf::PdmOptionItemInfo(displayName, v, false, icon));
}
}
}
return options;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicSelectViewUI::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering)
{
if (m_currentCase && m_currentCase->views().size() == 0)
{
m_createNewView = true;
}
if (m_createNewView)
{
m_newViewName.uiCapability()->setUiReadOnly(false);
m_selectedView.uiCapability()->setUiReadOnly(true);
}
else
{
m_newViewName.uiCapability()->setUiReadOnly(true);
m_selectedView.uiCapability()->setUiReadOnly(false);
}
}

View File

@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "cafPdmField.h"
#include "cafPdmObject.h"
#include "cafPdmPtrField.h"
class RimEclipseView;
class RimEclipseResultCase;
//==================================================================================================
///
//==================================================================================================
class RicSelectViewUI : public caf::PdmObject
{
CAF_PDM_HEADER_INIT;
public:
RicSelectViewUI();
void setView(RimEclipseView* currentView);
void setCase(RimEclipseResultCase* currentCase);
RimEclipseView* selectedView() const;
bool createNewView() const;
QString newViewName() const;
virtual QList<caf::PdmOptionItemInfo> calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override;
protected:
virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override;
private:
caf::PdmPtrField<RimEclipseView*> m_selectedView;
caf::PdmField<bool> m_createNewView;
caf::PdmField<QString> m_newViewName;
RimEclipseView* m_currentView;
RimEclipseResultCase* m_currentCase;
};

View File

@ -20,9 +20,13 @@
#include "RicShowContributingWellsFeatureImpl.h"
#include "RimEclipseView.h"
#include "RimEclipseWell.h"
#include "RiuMainWindow.h"
#include "cafSelectionManager.h"
#include "cafCmdFeatureManager.h"
#include <QAction>
@ -55,7 +59,10 @@ void RicShowContributingWellsFeature::onActionTriggered(bool isChecked)
RimEclipseView* eclipseView = nullptr;
well->firstAncestorOrThisOfTypeAsserted(eclipseView);
RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(eclipseView, well->name());
RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(eclipseView, well->name(), eclipseView->currentTimeStep());
RiuMainWindow::instance()->setExpanded(eclipseView, true);
RiuMainWindow::instance()->selectAsCurrentItem(eclipseView);
}
//--------------------------------------------------------------------------------------------------

View File

@ -20,7 +20,6 @@
#include "cafCmdFeature.h"
//==================================================================================================
///
//==================================================================================================

View File

@ -40,15 +40,13 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName)
void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName, int timeStep)
{
CAF_ASSERT(selectedWell);
RimEclipseView* eclipseView = viewToModify;
CAF_ASSERT(viewToModify);
RimEclipseWell* selectedWell = nullptr;
for (RimEclipseWell* w : eclipseView->wellCollection()->wells())
for (RimEclipseWell* w : viewToModify->wellCollection()->wells())
{
if (w->name() == wellName)
{
@ -62,34 +60,32 @@ void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(RimE
selectedWell->firstAncestorOrThisOfTypeAsserted(eclipseResultCase);
// Use the active flow diag solutions, or the first one as default
RimFlowDiagSolution* flowDiagSolution = eclipseView->cellResult()->flowDiagSolution();
RimFlowDiagSolution* flowDiagSolution = viewToModify->cellResult()->flowDiagSolution();
if (!flowDiagSolution)
{
std::vector<RimFlowDiagSolution*> flowSolutions = eclipseResultCase->flowDiagSolutions();
if (flowSolutions.size()) flowDiagSolution = flowSolutions.front();
flowDiagSolution = eclipseResultCase->defaultFlowDiagSolution();
}
CAF_ASSERT(flowDiagSolution);
int timeStep = eclipseView->currentTimeStep();
RimFlowDiagSolution::TracerStatusType tracerStatus = flowDiagSolution->tracerStatusInTimeStep(selectedWell->name(), timeStep);
if (!(tracerStatus == RimFlowDiagSolution::INJECTOR || tracerStatus == RimFlowDiagSolution::PRODUCER))
{
return;
}
eclipseView->cellResult()->setResultType(RimDefines::FLOW_DIAGNOSTICS);
eclipseView->cellResult()->setResultVariable("MaxFractionTracer");
viewToModify->setCurrentTimeStep(timeStep);
viewToModify->cellResult()->setResultType(RimDefines::FLOW_DIAGNOSTICS);
viewToModify->cellResult()->setResultVariable("MaxFractionTracer");
viewToModify->cellResult()->setFlowSolution(flowDiagSolution);
switch (tracerStatus)
{
case RimFlowDiagSolution::PRODUCER:
eclipseView->cellResult()->setFlowDiagTracerSelectionType(RimEclipseResultDefinition::FLOW_TR_INJECTORS);
viewToModify->cellResult()->setFlowDiagTracerSelectionType(RimEclipseResultDefinition::FLOW_TR_INJECTORS);
break;
case RimFlowDiagSolution::INJECTOR:
eclipseView->cellResult()->setFlowDiagTracerSelectionType(RimEclipseResultDefinition::FLOW_TR_PRODUCERS);
viewToModify->cellResult()->setFlowDiagTracerSelectionType(RimEclipseResultDefinition::FLOW_TR_PRODUCERS);
break;
default:
@ -97,12 +93,12 @@ void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(RimE
break;
}
eclipseView->cellResult()->loadDataAndUpdate();
eclipseView->cellResult()->updateConnectedEditors();
viewToModify->cellResult()->loadDataAndUpdate();
viewToModify->cellResult()->updateConnectedEditors();
std::vector<QString> tracerNames = findContributingTracerNames(flowDiagSolution, selectedWell->wellResults(), timeStep);
for (RimEclipseWell* w : eclipseView->wellCollection()->wells())
for (RimEclipseWell* w : viewToModify->wellCollection()->wells())
{
if (std::find(tracerNames.begin(), tracerNames.end(), w->name()) != tracerNames.end()
|| selectedWell->name() == w->name())
@ -118,7 +114,7 @@ void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(RimE
// Disable all existing property filters, and
// create a new property filter based on TOF for current well
RimEclipsePropertyFilterCollection* propertyFilterCollection = eclipseView->eclipsePropertyFilterCollection();
RimEclipsePropertyFilterCollection* propertyFilterCollection = viewToModify->eclipsePropertyFilterCollection();
for (RimEclipsePropertyFilter* f : propertyFilterCollection->propertyFilters())
{
@ -128,7 +124,7 @@ void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(RimE
RimEclipsePropertyFilter* propertyFilter = new RimEclipsePropertyFilter();
propertyFilterCollection->propertyFilters().push_back(propertyFilter);
propertyFilter->resultDefinition()->setEclipseCase(eclipseView->eclipseCase());
propertyFilter->resultDefinition()->setEclipseCase(viewToModify->eclipseCase());
propertyFilter->resultDefinition()->setTofAndSelectTracer(selectedWell->name());
propertyFilter->resultDefinition()->loadDataAndUpdate();
@ -136,41 +132,11 @@ void RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(RimE
RiuMainWindow::instance()->setExpanded(propertyFilterCollection, true);
eclipseView->faultCollection()->showFaultCollection = false;
eclipseView->faultCollection()->updateConnectedEditors();
viewToModify->faultCollection()->showFaultCollection = false;
viewToModify->faultCollection()->updateConnectedEditors();
eclipseView->scheduleCreateDisplayModelAndRedraw();
auto* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicShowMainWindowFeature");
feature->actionTriggered(false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QString> RicShowContributingWellsFeatureImpl::contributingTracers(RimEclipseWell* well)
{
CAF_ASSERT(well);
RimEclipseView* eclipseView = nullptr;
well->firstAncestorOrThisOfTypeAsserted(eclipseView);
RimEclipseResultCase* eclipseResultCase = nullptr;
well->firstAncestorOrThisOfTypeAsserted(eclipseResultCase);
// Use the active flow diag solutions, or the first one as default
RimFlowDiagSolution* flowDiagSolution = eclipseView->cellResult()->flowDiagSolution();
if (!flowDiagSolution)
{
std::vector<RimFlowDiagSolution*> flowSolutions = eclipseResultCase->flowDiagSolutions();
if (flowSolutions.size()) flowDiagSolution = flowSolutions.front();
}
CAF_ASSERT(flowDiagSolution);
int timeStep = eclipseView->currentTimeStep();
return findContributingTracerNames(flowDiagSolution, well->wellResults(), timeStep);
viewToModify->updateCurrentTimeStepAndRedraw();
viewToModify->scheduleCreateDisplayModelAndRedraw();
}
//--------------------------------------------------------------------------------------------------

View File

@ -33,10 +33,9 @@ class RigSingleWellResultsData;
class RicShowContributingWellsFeatureImpl
{
public:
static void modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName);
static void modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName, int timeStep);
private:
static std::vector<QString> contributingTracers(RimEclipseWell* well);
static std::vector<QString> findContributingTracerNames(
const RimFlowDiagSolution* flowDiagSolution,
const RigSingleWellResultsData* wellResults,

View File

@ -20,20 +20,20 @@
#include "RiaApplication.h"
#include "RimDefines.h"
#include "RimEclipseCellColors.h"
#include "RimEclipsePropertyFilter.h"
#include "RimEclipsePropertyFilterCollection.h"
#include "RicSelectViewUI.h"
#include "RicShowContributingWellsFeatureImpl.h"
#include "RimEclipseResultCase.h"
#include "RimEclipseView.h"
#include "RimEclipseWell.h"
#include "RimEclipseWellCollection.h"
#include "RimFlowDiagSolution.h"
#include "RimWellAllocationPlot.h"
#include "RiuMainWindow.h"
#include <QAction>
#include "cafCmdFeatureManager.h"
#include "RimFlowDiagSolution.h"
#include "cafPdmUiPropertyViewDialog.h"
#include <QAction>
CAF_CMD_SOURCE_INIT(RicShowContributingWellsFromPlotFeature, "RicShowContributingWellsFromPlotFeature");
@ -42,12 +42,6 @@ CAF_CMD_SOURCE_INIT(RicShowContributingWellsFromPlotFeature, "RicShowContributin
//--------------------------------------------------------------------------------------------------
bool RicShowContributingWellsFromPlotFeature::isCommandEnabled()
{
RimWellAllocationPlot* wellAllocationPlot = RiaApplication::instance()->activeWellAllocationPlot();
if (!wellAllocationPlot) return false;
RimEclipseView* activeView = dynamic_cast<RimEclipseView*>(RiaApplication::instance()->activeReservoirView());
if (!activeView) return false;
return true;
}
@ -59,81 +53,77 @@ void RicShowContributingWellsFromPlotFeature::onActionTriggered(bool isChecked)
RimWellAllocationPlot* wellAllocationPlot = RiaApplication::instance()->activeWellAllocationPlot();
if (!wellAllocationPlot) return;
RimEclipseView* activeView = dynamic_cast<RimEclipseView*>(RiaApplication::instance()->activeReservoirView());
if (!activeView) return;
RimEclipseResultCase* parentEclipseCase = nullptr;
wellAllocationPlot->flowDiagSolution()->firstAncestorOrThisOfTypeAsserted(parentEclipseCase);
int timeStep = wellAllocationPlot->timeStep();
QString wellName = wellAllocationPlot->wellName();
const std::vector<QString> contributingTracers = wellAllocationPlot->contributingTracerNames();
RimFlowDiagSolution* flowSolution = wellAllocationPlot->flowDiagSolution();
RimEclipseView* viewToManipulate = nullptr;
if ( !flowSolution ) return;
RimFlowDiagSolution::TracerStatusType tracerStatus = flowSolution->tracerStatusInTimeStep(wellName, timeStep);
if (!(tracerStatus == RimFlowDiagSolution::INJECTOR || tracerStatus == RimFlowDiagSolution::PRODUCER) ) return;
activeView->cellResult()->setResultType(RimDefines::FLOW_DIAGNOSTICS);
activeView->cellResult()->setResultVariable("MaxFractionTracer");
switch (tracerStatus)
{
case RimFlowDiagSolution::PRODUCER:
activeView->cellResult()->setFlowDiagTracerSelectionType(RimEclipseResultDefinition::FLOW_TR_INJECTORS);
break;
case RimFlowDiagSolution::INJECTOR:
activeView->cellResult()->setFlowDiagTracerSelectionType(RimEclipseResultDefinition::FLOW_TR_PRODUCERS);
break;
RimEclipseView* viewForSameResultCase = nullptr;
default:
CVF_ASSERT(false);
break;
}
activeView->setCurrentTimeStep(timeStep);
activeView->cellResult()->loadDataAndUpdate();
activeView->cellResult()->updateConnectedEditors();
for ( RimEclipseWell* well : activeView->wellCollection()->wells() )
{
if ( std::find(contributingTracers.begin(), contributingTracers.end(), well->name()) != contributingTracers.end()
|| wellAllocationPlot->wellName() == well->name() )
RimEclipseView* activeView = dynamic_cast<RimEclipseView*>(RiaApplication::instance()->activeReservoirView());
if (activeView)
{
well->showWell = true;
RimEclipseResultCase* activeViewParent = nullptr;
activeView->firstAncestorOrThisOfTypeAsserted(activeViewParent);
if (activeViewParent == parentEclipseCase)
{
viewForSameResultCase = activeView;
}
else
{
if (parentEclipseCase->views().size() > 0)
{
viewForSameResultCase = dynamic_cast<RimEclipseView*>(parentEclipseCase->views()[0]);
}
}
}
RicSelectViewUI featureUi;
if (viewForSameResultCase)
{
featureUi.setView(viewForSameResultCase);
}
else
{
well->showWell = false;
featureUi.setCase(parentEclipseCase);
}
caf::PdmUiPropertyViewDialog propertyDialog(NULL, &featureUi, "Show Contributing Wells in View", "");
propertyDialog.resize(QSize(400, 200));
if (propertyDialog.exec() != QDialog::Accepted) return;
if (featureUi.createNewView())
{
RimEclipseView* createdView = parentEclipseCase->createAndAddReservoirView();
createdView->name = featureUi.newViewName();
// Must be run before buildViewItems, as wells are created in this function
createdView->loadDataAndUpdate();
parentEclipseCase->updateConnectedEditors();
viewToManipulate = createdView;
}
else
{
viewToManipulate = featureUi.selectedView();
}
}
// Disable all existing property filters, and
// create a new property filter based on TOF for current well
CAF_ASSERT(viewToManipulate);
RimEclipsePropertyFilterCollection* propertyFilterCollection = activeView->eclipsePropertyFilterCollection();
int timeStep = wellAllocationPlot->timeStep();
QString wellName = wellAllocationPlot->wellName();
for ( RimEclipsePropertyFilter* f : propertyFilterCollection->propertyFilters() )
{
f->isActive = false;
}
RimEclipsePropertyFilter* propertyFilter = new RimEclipsePropertyFilter();
propertyFilterCollection->propertyFilters().push_back(propertyFilter);
propertyFilter->resultDefinition()->setEclipseCase(activeView->eclipseCase());
propertyFilter->resultDefinition()->setTofAndSelectTracer(wellAllocationPlot->wellName());
propertyFilter->resultDefinition()->loadDataAndUpdate();
propertyFilterCollection->updateConnectedEditors();
RiuMainWindow::instance()->setExpanded(propertyFilterCollection, true);
activeView->scheduleCreateDisplayModelAndRedraw();
RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(viewToManipulate, wellName, timeStep);
auto* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicShowMainWindowFeature");
feature->actionTriggered(false);
RiuMainWindow::instance()->setExpanded(viewToManipulate, true);
RiuMainWindow::instance()->selectAsCurrentItem(viewToManipulate);
}
//--------------------------------------------------------------------------------------------------