From fb18e9b170a840b67f7dc215a58a621fa2a197ea Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 9 Nov 2018 08:13:39 +0100 Subject: [PATCH] Temporary LGR : Hide context menu items, remove invalid assert --- ...portCompletionsForTemporaryLgrsFeature.cpp | 56 +++++++++++-------- .../RicDeleteTemporaryLgrsFeature.cpp | 7 ++- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/ApplicationCode/Commands/CompletionExportCommands/RicExportCompletionsForTemporaryLgrsFeature.cpp b/ApplicationCode/Commands/CompletionExportCommands/RicExportCompletionsForTemporaryLgrsFeature.cpp index ba4fe56082..ab370f9f85 100644 --- a/ApplicationCode/Commands/CompletionExportCommands/RicExportCompletionsForTemporaryLgrsFeature.cpp +++ b/ApplicationCode/Commands/CompletionExportCommands/RicExportCompletionsForTemporaryLgrsFeature.cpp @@ -26,11 +26,11 @@ #include "RiuPlotMainWindow.h" -#include "RimGridCollection.h" -#include "RimWellPath.h" -#include "RimProject.h" -#include "RimWellPathCollection.h" #include "RimEclipseCase.h" +#include "RimGridCollection.h" +#include "RimProject.h" +#include "RimWellPath.h" +#include "RimWellPathCollection.h" #include "cafSelectionManagerTools.h" @@ -43,6 +43,11 @@ CAF_CMD_SOURCE_INIT(RicExportCompletionsForTemporaryLgrsFeature, "RicExportCompl //-------------------------------------------------------------------------------------------------- bool RicExportCompletionsForTemporaryLgrsFeature::isCommandEnabled() { + if (wellPathsAssociatedWithLgrs().empty()) + { + return false; + } + std::vector selGridInfos = caf::selectedObjectsByTypeStrict(); return selGridInfos.size() == 1 && selGridInfos.front()->uiName() == RimGridCollection::temporaryGridUiName(); } @@ -53,7 +58,10 @@ bool RicExportCompletionsForTemporaryLgrsFeature::isCommandEnabled() void RicExportCompletionsForTemporaryLgrsFeature::onActionTriggered(bool isChecked) { std::vector wellPaths = wellPathsAssociatedWithLgrs(); - CVF_ASSERT(wellPaths.size() > 0); + if (wellPaths.empty()) + { + return; + } std::vector simWells; QString dialogTitle = "Export Completion Data for Temporary LGRs"; @@ -77,28 +85,32 @@ std::vector RicExportCompletionsForTemporaryLgrsFeature::wellPaths std::vector wellPaths; auto selectedEclipseCase = caf::firstAncestorOfTypeFromSelectedObject(); - auto mainGrid = selectedEclipseCase->mainGrid(); - - std::set wellPathNames; - - for (size_t i = 0; i < mainGrid->gridCount(); i++) + if (selectedEclipseCase) { - const RigGridBase* grid = mainGrid->gridByIndex(i); + auto mainGrid = selectedEclipseCase->mainGrid(); - if (!grid->associatedWellPathName().empty()) + std::set wellPathNames; + + for (size_t i = 0; i < mainGrid->gridCount(); i++) { - wellPathNames.insert(QString::fromStdString(grid->associatedWellPathName())); + const RigGridBase* grid = mainGrid->gridByIndex(i); + + if (!grid->associatedWellPathName().empty()) + { + wellPathNames.insert(QString::fromStdString(grid->associatedWellPathName())); + } + } + + auto project = RiaApplication::instance()->project(); + for (const auto& wellPathName : wellPathNames) + { + auto wellPath = project->wellPathByName(wellPathName); + if (wellPath) + { + wellPaths.push_back(wellPath); + } } } - auto project = RiaApplication::instance()->project(); - for (const auto& wellPathName : wellPathNames) - { - auto wellPath = project->wellPathByName(wellPathName); - if (wellPath) - { - wellPaths.push_back(wellPath); - } - } return wellPaths; } diff --git a/ApplicationCode/Commands/RicDeleteTemporaryLgrsFeature.cpp b/ApplicationCode/Commands/RicDeleteTemporaryLgrsFeature.cpp index cad79563ad..93c4c0bfa3 100644 --- a/ApplicationCode/Commands/RicDeleteTemporaryLgrsFeature.cpp +++ b/ApplicationCode/Commands/RicDeleteTemporaryLgrsFeature.cpp @@ -47,7 +47,12 @@ void RicDeleteTemporaryLgrsFeature::deleteAllTemporaryLgrs(RimEclipseCase* eclip bool RicDeleteTemporaryLgrsFeature::isCommandEnabled() { std::vector selGridInfos = caf::selectedObjectsByTypeStrict(); - return selGridInfos.size() == 1 && selGridInfos.front()->uiName() == RimGridCollection::temporaryGridUiName(); + if (selGridInfos.size() == 1 && selGridInfos.front()->uiName() == RimGridCollection::temporaryGridUiName()) + { + return !selGridInfos[0]->gridInfos().empty(); + } + + return false; } //--------------------------------------------------------------------------------------------------