From db56dd4bc95d04e037c4602f276ae4b0b32588c3 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 10 Mar 2017 13:13:26 +0100 Subject: [PATCH] #1288 Show view selection dialog also from 3D view --- .../RicShowContributingWellsFeature.cpp | 19 +++- .../RicShowContributingWellsFeatureImpl.cpp | 103 +++++++++++++++++- .../RicShowContributingWellsFeatureImpl.h | 9 +- ...icShowContributingWellsFromPlotFeature.cpp | 98 +---------------- 4 files changed, 126 insertions(+), 103 deletions(-) diff --git a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeature.cpp b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeature.cpp index 38b69304ad..f61933d827 100644 --- a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeature.cpp +++ b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeature.cpp @@ -20,13 +20,15 @@ #include "RicShowContributingWellsFeatureImpl.h" +#include "RimEclipseResultCase.h" #include "RimEclipseView.h" #include "RimEclipseWell.h" +#include "RimViewManipulator.h" #include "RiuMainWindow.h" -#include "cafSelectionManager.h" #include "cafCmdFeatureManager.h" +#include "cafSelectionManager.h" #include @@ -59,10 +61,19 @@ void RicShowContributingWellsFeature::onActionTriggered(bool isChecked) RimEclipseView* eclipseView = nullptr; well->firstAncestorOrThisOfTypeAsserted(eclipseView); - RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(eclipseView, well->name(), eclipseView->currentTimeStep()); + RimEclipseResultCase* eclipseResultCase = nullptr; + well->firstAncestorOrThisOfTypeAsserted(eclipseResultCase); + + RimEclipseView* modifiedView = RicShowContributingWellsFeatureImpl::showViewSelection(eclipseResultCase, well->name(), eclipseView->currentTimeStep()); + if (modifiedView) + { + modifiedView->createDisplayModelAndRedraw(); + + std::vector viewsToUpdate; + viewsToUpdate.push_back(modifiedView); - RiuMainWindow::instance()->setExpanded(eclipseView, true); - RiuMainWindow::instance()->selectAsCurrentItem(eclipseView); + RimViewManipulator::applySourceViewCameraOnDestinationViews(eclipseView, viewsToUpdate); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.cpp b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.cpp index c7e7ee36f5..431b0ba5a3 100644 --- a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.cpp +++ b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.cpp @@ -18,6 +18,10 @@ #include "RicShowContributingWellsFeatureImpl.h" +#include "RiaApplication.h" + +#include "RicSelectViewUI.h" + #include "RigFlowDiagResultAddress.h" #include "RigSingleWellResultsData.h" @@ -28,14 +32,111 @@ #include "RimEclipseView.h" #include "RimEclipseWell.h" #include "RimEclipseWellCollection.h" -#include "RimFlowDiagSolution.h" #include "RimFaultCollection.h" +#include "RimFlowDiagSolution.h" +#include "RimProject.h" +#include "RimViewManipulator.h" #include "RiuMainWindow.h" #include "cafAssert.h" #include "cafCmdFeature.h" #include "cafCmdFeatureManager.h" +#include "cafPdmUiPropertyViewDialog.h" + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseView* RicShowContributingWellsFeatureImpl::showViewSelection(RimEclipseResultCase* wellAllocationResultCase, QString wellName, int timeStep) +{ + const QString lastUsedViewKey("lastUsedViewKey"); + + RimEclipseView* defaultSelectedView = nullptr; + { + QString lastUsedViewRef = RiaApplication::instance()->cacheDataObject(lastUsedViewKey).toString(); + RimEclipseView* lastUsedView = dynamic_cast(caf::PdmReferenceHelper::objectFromReference(RiaApplication::instance()->project(), lastUsedViewRef)); + if (lastUsedView) + { + RimEclipseResultCase* lastUsedViewResultCase = nullptr; + lastUsedView->firstAncestorOrThisOfTypeAsserted(lastUsedViewResultCase); + + if (lastUsedViewResultCase == wellAllocationResultCase) + { + defaultSelectedView = lastUsedView; + } + } + + if (!defaultSelectedView) + { + RimEclipseView* activeView = dynamic_cast(RiaApplication::instance()->activeReservoirView()); + if (activeView) + { + RimEclipseResultCase* activeViewResultCase = nullptr; + activeView->firstAncestorOrThisOfTypeAsserted(activeViewResultCase); + + if (activeViewResultCase == wellAllocationResultCase) + { + defaultSelectedView = activeView; + } + else + { + if (wellAllocationResultCase->views().size() > 0) + { + defaultSelectedView = dynamic_cast(wellAllocationResultCase->views()[0]); + } + } + } + } + } + + RicSelectViewUI featureUi; + if (defaultSelectedView) + { + featureUi.setView(defaultSelectedView); + } + else + { + featureUi.setCase(wellAllocationResultCase); + } + + caf::PdmUiPropertyViewDialog propertyDialog(NULL, &featureUi, "Show Contributing Wells in View", ""); + propertyDialog.resize(QSize(400, 200)); + + if (propertyDialog.exec() != QDialog::Accepted) return nullptr; + + RimEclipseView* viewToManipulate = nullptr; + if (featureUi.createNewView()) + { + RimEclipseView* createdView = wellAllocationResultCase->createAndAddReservoirView(); + createdView->name = featureUi.newViewName(); + + // Must be run before buildViewItems, as wells are created in this function + createdView->loadDataAndUpdate(); + wellAllocationResultCase->updateConnectedEditors(); + + viewToManipulate = createdView; + } + else + { + viewToManipulate = featureUi.selectedView(); + } + + CAF_ASSERT(viewToManipulate); + + + RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(viewToManipulate, wellName, timeStep); + + auto* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicShowMainWindowFeature"); + feature->actionTriggered(false); + + RiuMainWindow::instance()->setExpanded(viewToManipulate, true); + RiuMainWindow::instance()->selectAsCurrentItem(viewToManipulate); + + QString refFromProjectToView = caf::PdmReferenceHelper::referenceFromRootToObject(RiaApplication::instance()->project(), viewToManipulate); + RiaApplication::instance()->setCacheDataObject(lastUsedViewKey, refFromProjectToView); + + return viewToManipulate; +} //-------------------------------------------------------------------------------------------------- /// diff --git a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.h b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.h index 09f3f12c1d..dbc3beebe8 100644 --- a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.h +++ b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFeatureImpl.h @@ -22,10 +22,11 @@ #include -class RimEclipseWell; +class RigSingleWellResultsData; +class RimEclipseResultCase; class RimEclipseView; +class RimEclipseWell; class RimFlowDiagSolution; -class RigSingleWellResultsData; //================================================================================================== /// @@ -33,9 +34,11 @@ class RigSingleWellResultsData; class RicShowContributingWellsFeatureImpl { public: - static void modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName, int timeStep); + static RimEclipseView* showViewSelection(RimEclipseResultCase* wellAllocationResultCase, QString wellName, int timeStep); private: + static void modifyViewToShowContributingWells(RimEclipseView* viewToModify, const QString& wellName, int timeStep); + static std::vector findContributingTracerNames( const RimFlowDiagSolution* flowDiagSolution, const RigSingleWellResultsData* wellResults, diff --git a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFromPlotFeature.cpp b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFromPlotFeature.cpp index 1efac5ef37..43df03c87b 100644 --- a/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFromPlotFeature.cpp +++ b/ApplicationCode/Commands/FlowCommands/RicShowContributingWellsFromPlotFeature.cpp @@ -20,20 +20,12 @@ #include "RiaApplication.h" -#include "RicSelectViewUI.h" #include "RicShowContributingWellsFeatureImpl.h" #include "RimEclipseResultCase.h" -#include "RimEclipseView.h" #include "RimFlowDiagSolution.h" -#include "RimProject.h" #include "RimWellAllocationPlot.h" -#include "RiuMainWindow.h" - -#include "cafCmdFeatureManager.h" -#include "cafPdmUiPropertyViewDialog.h" - #include CAF_CMD_SOURCE_INIT(RicShowContributingWellsFromPlotFeature, "RicShowContributingWellsFromPlotFeature"); @@ -51,100 +43,16 @@ bool RicShowContributingWellsFromPlotFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicShowContributingWellsFromPlotFeature::onActionTriggered(bool isChecked) { - const QString lastUsedViewKey("lastUsedViewKey"); - RimWellAllocationPlot* wellAllocationPlot = RiaApplication::instance()->activeWellAllocationPlot(); if (!wellAllocationPlot) return; - RimEclipseResultCase* wellAllocationResultCase = nullptr; - wellAllocationPlot->flowDiagSolution()->firstAncestorOrThisOfTypeAsserted(wellAllocationResultCase); - - RimEclipseView* defaultSelectedView = nullptr; - - { - QString lastUsedViewRef = RiaApplication::instance()->cacheDataObject(lastUsedViewKey).toString(); - RimEclipseView* lastUsedView = dynamic_cast(caf::PdmReferenceHelper::objectFromReference(RiaApplication::instance()->project(), lastUsedViewRef)); - if (lastUsedView) - { - RimEclipseResultCase* lastUsedViewResultCase = nullptr; - lastUsedView->firstAncestorOrThisOfTypeAsserted(lastUsedViewResultCase); - - if (lastUsedViewResultCase == wellAllocationResultCase) - { - defaultSelectedView = lastUsedView; - } - } - - if (!defaultSelectedView) - { - RimEclipseView* activeView = dynamic_cast(RiaApplication::instance()->activeReservoirView()); - if (activeView) - { - RimEclipseResultCase* activeViewResultCase = nullptr; - activeView->firstAncestorOrThisOfTypeAsserted(activeViewResultCase); - - if (activeViewResultCase == wellAllocationResultCase) - { - defaultSelectedView = activeView; - } - else - { - if (wellAllocationResultCase->views().size() > 0) - { - defaultSelectedView = dynamic_cast(wellAllocationResultCase->views()[0]); - } - } - } - } - } - - RicSelectViewUI featureUi; - if (defaultSelectedView) - { - featureUi.setView(defaultSelectedView); - } - else - { - featureUi.setCase(wellAllocationResultCase); - } - - caf::PdmUiPropertyViewDialog propertyDialog(NULL, &featureUi, "Show Contributing Wells in View", ""); - propertyDialog.resize(QSize(400, 200)); - - if (propertyDialog.exec() != QDialog::Accepted) return; - - RimEclipseView* viewToManipulate = nullptr; - if (featureUi.createNewView()) - { - RimEclipseView* createdView = wellAllocationResultCase->createAndAddReservoirView(); - createdView->name = featureUi.newViewName(); - - // Must be run before buildViewItems, as wells are created in this function - createdView->loadDataAndUpdate(); - wellAllocationResultCase->updateConnectedEditors(); - - viewToManipulate = createdView; - } - else - { - viewToManipulate = featureUi.selectedView(); - } - - CAF_ASSERT(viewToManipulate); - int timeStep = wellAllocationPlot->timeStep(); QString wellName = wellAllocationPlot->wellName(); - RicShowContributingWellsFeatureImpl::modifyViewToShowContributingWells(viewToManipulate, wellName, timeStep); - - auto* feature = caf::CmdFeatureManager::instance()->getCommandFeature("RicShowMainWindowFeature"); - feature->actionTriggered(false); - - RiuMainWindow::instance()->setExpanded(viewToManipulate, true); - RiuMainWindow::instance()->selectAsCurrentItem(viewToManipulate); + RimEclipseResultCase* wellAllocationResultCase = nullptr; + wellAllocationPlot->flowDiagSolution()->firstAncestorOrThisOfTypeAsserted(wellAllocationResultCase); - QString refFromProjectToView = caf::PdmReferenceHelper::referenceFromRootToObject(RiaApplication::instance()->project(), viewToManipulate); - RiaApplication::instance()->setCacheDataObject(lastUsedViewKey, refFromProjectToView); + RicShowContributingWellsFeatureImpl::showViewSelection(wellAllocationResultCase, wellName, timeStep); } //--------------------------------------------------------------------------------------------------