diff --git a/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp b/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp index a8bb45a610..463242a504 100644 --- a/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp +++ b/ApplicationCode/Commands/FlowCommands/RicShowWellAllocationPlotFeature.cpp @@ -33,6 +33,9 @@ #include "cafSelectionManager.h" #include +#include "RimWellPath.h" +#include "RimEclipseView.h" +#include "RimSimWellInViewCollection.h" CAF_CMD_SOURCE_INIT(RicShowWellAllocationPlotFeature, "RicShowWellAllocationPlotFeature"); @@ -41,10 +44,27 @@ CAF_CMD_SOURCE_INIT(RicShowWellAllocationPlotFeature, "RicShowWellAllocationPlot //-------------------------------------------------------------------------------------------------- bool RicShowWellAllocationPlotFeature::isCommandEnabled() { - std::vector collection; - caf::SelectionManager::instance()->objectsByType(&collection); + std::vector simWellCollection; + caf::SelectionManager::instance()->objectsByType(&simWellCollection); - if (collection.size() > 0) + if (simWellCollection.size() > 0) + { + return true; + } + + std::vector wellPathCollection; + caf::SelectionManager::instance()->objectsByType(&wellPathCollection); + + if (wellPathCollection.empty()) return false; + + RimView* view = RiaApplication::instance()->activeReservoirView(); + if (!view) return false; + RimEclipseView* eclView = dynamic_cast(view); + if (!eclView) return false; + + RimSimWellInView* simWellFromWellPath = eclView->wellCollection->findWell(wellPathCollection[0]->associatedSimulationWellName()); + + if (simWellFromWellPath) { return true; } @@ -60,22 +80,38 @@ void RicShowWellAllocationPlotFeature::onActionTriggered(bool isChecked) std::vector collection; caf::SelectionManager::instance()->objectsByType(&collection); + std::vector wellPathCollection; + caf::SelectionManager::instance()->objectsByType(&wellPathCollection); + + RimSimWellInView* simWell = nullptr; + if (collection.size() > 0) { - RimSimWellInView* simWell = collection[0]; + simWell = collection[0]; + } + else if (wellPathCollection.size() > 0) + { + RimView* view = RiaApplication::instance()->activeReservoirView(); + if (!view) return; + RimEclipseView* eclView = dynamic_cast(view); + if (!eclView) return; - if (RiaApplication::instance()->project()) + simWell = eclView->wellCollection->findWell(wellPathCollection[0]->associatedSimulationWellName()); + if (!simWell) return; + } + else return; + + if (RiaApplication::instance()->project()) + { + RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection(); + if (flowPlotColl) { - RimFlowPlotCollection* flowPlotColl = RiaApplication::instance()->project()->mainPlotCollection->flowPlotCollection(); - if (flowPlotColl) - { - flowPlotColl->defaultWellAllocPlot()->setFromSimulationWell(simWell); - flowPlotColl->defaultWellAllocPlot()->updateConnectedEditors(); + flowPlotColl->defaultWellAllocPlot()->setFromSimulationWell(simWell); + flowPlotColl->defaultWellAllocPlot()->updateConnectedEditors(); - // Make sure the summary plot window is created and visible - RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow(); - plotwindow->selectAsCurrentItem(flowPlotColl->defaultWellAllocPlot()); - } + // Make sure the summary plot window is created and visible + RiuMainPlotWindow* plotwindow = RiaApplication::instance()->getOrCreateAndShowMainPlotWindow(); + plotwindow->selectAsCurrentItem(flowPlotColl->defaultWellAllocPlot()); } } } diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 36b1b52223..8d7bcb6e70 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -242,6 +242,7 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "Separator"; menuBuilder << "RicNewRftPlotFeature"; menuBuilder << "RicNewPltPlotFeature"; + menuBuilder << "RicShowWellAllocationPlotFeature"; menuBuilder << "RicNewWellLogFileCurveFeature"; menuBuilder << "RicNewWellLogCurveExtractionFeature"; menuBuilder << "RicNewWellPathIntersectionFeature";