diff --git a/ApplicationCode/Commands/RicCloseCaseFeature.cpp b/ApplicationCode/Commands/RicCloseCaseFeature.cpp index 6f76b80e81..0fb3100b0c 100644 --- a/ApplicationCode/Commands/RicCloseCaseFeature.cpp +++ b/ApplicationCode/Commands/RicCloseCaseFeature.cpp @@ -52,7 +52,7 @@ CAF_CMD_SOURCE_INIT(RicCloseCaseFeature, "RicCloseCaseFeature"); //-------------------------------------------------------------------------------------------------- bool RicCloseCaseFeature::isCommandEnabled() { - return selectedEclipseCase() != nullptr || selectedGeoMechCase() != nullptr; + return !selectedCases().empty(); } //-------------------------------------------------------------------------------------------------- @@ -60,24 +60,44 @@ bool RicCloseCaseFeature::isCommandEnabled() //-------------------------------------------------------------------------------------------------- void RicCloseCaseFeature::onActionTriggered(bool isChecked) { - RimEclipseCase* eclipseCase = selectedEclipseCase(); - RimGeoMechCase* geoMechCase = selectedGeoMechCase(); - if (eclipseCase) + std::vector rimCases = selectedCases(); + std::vector eclipseCases; + std::vector geoMechCases; + for (RimCase* rimCase : selectedCases()) { - std::vector casesToBeDeleted; - casesToBeDeleted.push_back(eclipseCase); - - if (userConfirmedGridCaseGroupChange(casesToBeDeleted)) + RimEclipseCase* eclipseCase = dynamic_cast(rimCase); + if (eclipseCase) { - deleteEclipseCase(eclipseCase); + eclipseCases.push_back(eclipseCase); + } + else + { + RimGeoMechCase* geoMechCase = dynamic_cast(rimCase); + if (geoMechCase) + { + geoMechCases.push_back(geoMechCase); + } + } + } + if (!eclipseCases.empty()) + { + if (userConfirmedGridCaseGroupChange(eclipseCases)) + { + for (RimEclipseCase* eclipseCase : eclipseCases) + { + deleteEclipseCase(eclipseCase); + } RiuMainWindow::instance()->cleanupGuiCaseClose(); } } - else if (geoMechCase) + + if (!geoMechCases.empty()) { - deleteGeoMechCase(geoMechCase); - + for (RimGeoMechCase* geoMechCase : geoMechCases) + { + deleteGeoMechCase(geoMechCase); + } RiuMainWindow::instance()->cleanupGuiCaseClose(); } } @@ -95,33 +115,11 @@ void RicCloseCaseFeature::setupActionLook(QAction* actionToSetup) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RimEclipseCase* RicCloseCaseFeature::selectedEclipseCase() const +std::vector RicCloseCaseFeature::selectedCases() const { - std::vector selection; + std::vector selection; caf::SelectionManager::instance()->objectsByType(&selection); - - if (selection.size() > 0) - { - return selection[0]; - } - - return nullptr; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -RimGeoMechCase* RicCloseCaseFeature::selectedGeoMechCase() const -{ - std::vector selection; - caf::SelectionManager::instance()->objectsByType(&selection); - - if (selection.size() > 0) - { - return selection[0]; - } - - return nullptr; + return selection; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/Commands/RicCloseCaseFeature.h b/ApplicationCode/Commands/RicCloseCaseFeature.h index 7e6199f9b1..fd8224dcb9 100644 --- a/ApplicationCode/Commands/RicCloseCaseFeature.h +++ b/ApplicationCode/Commands/RicCloseCaseFeature.h @@ -25,6 +25,7 @@ class RimEclipseCase; class RimGeoMechCase; +class RimCase; class RimIdenticalGridCaseGroup; //================================================================================================== @@ -45,8 +46,7 @@ protected: virtual void setupActionLook( QAction* actionToSetup ); private: - RimEclipseCase* selectedEclipseCase() const; - RimGeoMechCase* selectedGeoMechCase() const; + std::vector selectedCases() const; void deleteGeoMechCase(RimGeoMechCase* geoMechCase);