diff --git a/ApplicationCode/Commands/CMakeLists_files.cmake b/ApplicationCode/Commands/CMakeLists_files.cmake index 212c5fbc31..4000ddb2a6 100644 --- a/ApplicationCode/Commands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CMakeLists_files.cmake @@ -7,6 +7,7 @@ endif() set (SOURCE_GROUP_HEADER_FILES ${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.h ${CEE_CURRENT_LIST_DIR}RicCloseSummaryCaseFeature.h +${CEE_CURRENT_LIST_DIR}RicCloseSummaryCaseCollectionFeature.h ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterFeatureImpl.h ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertFeature.h ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertExec.h @@ -70,6 +71,7 @@ endif() set (SOURCE_GROUP_SOURCE_FILES ${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.cpp ${CEE_CURRENT_LIST_DIR}RicCloseSummaryCaseFeature.cpp +${CEE_CURRENT_LIST_DIR}RicCloseSummaryCaseCollectionFeature.cpp ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterFeatureImpl.cpp ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertFeature.cpp ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertExec.cpp diff --git a/ApplicationCode/Commands/RicCloseSummaryCaseCollectionFeature.cpp b/ApplicationCode/Commands/RicCloseSummaryCaseCollectionFeature.cpp new file mode 100644 index 0000000000..4235a6c8d6 --- /dev/null +++ b/ApplicationCode/Commands/RicCloseSummaryCaseCollectionFeature.cpp @@ -0,0 +1,82 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RicCloseSummaryCaseCollectionFeature.h" + +#include "RiaApplication.h" + +#include "RicCloseSummaryCaseFeature.h" + +#include "RimMainPlotCollection.h" +#include "RimProject.h" +#include "RimSummaryCase.h" +#include "RimSummaryCaseCollection.h" +#include "RimSummaryPlot.h" +#include "RimSummaryPlotCollection.h" + +#include "cafSelectionManager.h" + +#include "cvfAssert.h" + +#include +#include + + +CAF_CMD_SOURCE_INIT(RicCloseSummaryCaseCollectionFeature, "RicCloseSummaryCaseCollectionFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCloseSummaryCaseCollectionFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Close Sub Items"); + actionToSetup->setIcon(QIcon(":/Erase.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicCloseSummaryCaseCollectionFeature::isCommandEnabled() +{ + std::vector summaryCaseCollections; + caf::SelectionManager::instance()->objectsByType(&summaryCaseCollections); + return (summaryCaseCollections.size() > 0); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCloseSummaryCaseCollectionFeature::onActionTriggered(bool isChecked) +{ + std::vector summaryCaseCollections; + caf::SelectionManager::instance()->objectsByType(&summaryCaseCollections); + + for (RimSummaryCaseCollection* summaryCaseCollection : summaryCaseCollections) + { + std::vector summaryCasesFromCollection; + + for (int i = 0; i < summaryCaseCollection->summaryCaseCount(); i++) + { + summaryCasesFromCollection.push_back(summaryCaseCollection->summaryCase(i)); + } + + RicCloseSummaryCaseFeature::deleteSummaryCases(summaryCasesFromCollection); + } +} + diff --git a/ApplicationCode/Commands/RicCloseSummaryCaseCollectionFeature.h b/ApplicationCode/Commands/RicCloseSummaryCaseCollectionFeature.h new file mode 100644 index 0000000000..60b9ae43d6 --- /dev/null +++ b/ApplicationCode/Commands/RicCloseSummaryCaseCollectionFeature.h @@ -0,0 +1,35 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cafCmdFeature.h" + +//================================================================================================== +/// +//================================================================================================== +class RicCloseSummaryCaseCollectionFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + virtual bool isCommandEnabled() override; + virtual void onActionTriggered(bool isChecked) override; + virtual void setupActionLook(QAction* actionToSetup) override; +}; diff --git a/ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp index 122b33c84f..df3e256167 100644 --- a/ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp +++ b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp @@ -34,6 +34,7 @@ #include + CAF_CMD_SOURCE_INIT(RicCloseSummaryCaseFeature, "RicCloseSummaryCaseFeature"); @@ -46,6 +47,37 @@ void RicCloseSummaryCaseFeature::setupActionLook(QAction* actionToSetup) actionToSetup->setIcon(QIcon(":/Erase.png")); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCloseSummaryCaseFeature::deleteSummaryCases(const std::vector& cases) +{ + RimProject* project = RiaApplication::instance()->project(); + CVF_ASSERT(project); + + RimMainPlotCollection* mainPlotColl = project->mainPlotCollection(); + CVF_ASSERT(mainPlotColl); + + RimSummaryPlotCollection* summaryPlotColl = mainPlotColl->summaryPlotCollection(); + CVF_ASSERT(summaryPlotColl); + + for (RimSummaryCase* summaryCase : cases) + { + for (RimSummaryPlot* summaryPlot : summaryPlotColl->summaryPlots) + { + summaryPlot->removeCurveAssosiatedWithCase(summaryCase); + } + summaryPlotColl->updateConnectedEditors(); + + RimSummaryCaseCollection* summaryCaseCollection = nullptr; + summaryCase->firstAncestorOrThisOfTypeAsserted(summaryCaseCollection); + + summaryCaseCollection->deleteCase(summaryCase); + delete summaryCase; + summaryCaseCollection->updateConnectedEditors(); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -53,6 +85,7 @@ bool RicCloseSummaryCaseFeature::isCommandEnabled() { std::vector selection; caf::SelectionManager::instance()->objectsByType(&selection); + return (selection.size() > 0); } @@ -64,29 +97,6 @@ void RicCloseSummaryCaseFeature::onActionTriggered(bool isChecked) std::vector selection; caf::SelectionManager::instance()->objectsByType(&selection); CVF_ASSERT(selection.size() > 0); - - RimProject* project = RiaApplication::instance()->project(); - CVF_ASSERT(project); - - RimMainPlotCollection* mainPlotColl = project->mainPlotCollection(); - CVF_ASSERT(mainPlotColl); - - RimSummaryPlotCollection* summaryPlotColl = mainPlotColl->summaryPlotCollection(); - CVF_ASSERT(summaryPlotColl); - - for (RimSummaryCase* summaryCase : selection) - { - for (RimSummaryPlot* summaryPlot : summaryPlotColl->summaryPlots) - { - summaryPlot->removeCurveAssosiatedWithCase(summaryCase); - } - summaryPlotColl->updateConnectedEditors(); - - RimSummaryCaseCollection* summaryCaseCollection = nullptr; - summaryCase->firstAncestorOrThisOfTypeAsserted(summaryCaseCollection); - - summaryCaseCollection->deleteCase(summaryCase); - delete summaryCase; - summaryCaseCollection->updateConnectedEditors(); - } + + RicCloseSummaryCaseFeature::deleteSummaryCases(selection); } diff --git a/ApplicationCode/Commands/RicCloseSummaryCaseFeature.h b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.h index be08e7afc8..d987aba447 100644 --- a/ApplicationCode/Commands/RicCloseSummaryCaseFeature.h +++ b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.h @@ -32,13 +32,11 @@ class RicCloseSummaryCaseFeature : public caf::CmdFeature { CAF_CMD_HEADER_INIT; public: + static void deleteSummaryCases(const std::vector& cases); protected: // Overrides virtual bool isCommandEnabled() override; virtual void onActionTriggered(bool isChecked) override; virtual void setupActionLook(QAction* actionToSetup) override; - -private: - RimSummaryCase* selectedSummaryCase() const; }; diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 7b60cd02e9..43e152ab9a 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -444,6 +444,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() commandIds << "RicFlyToObjectFeature"; commandIds << "RicExportCarfin"; commandIds << "RicCloseSummaryCaseFeature"; + commandIds << "RicCloseSummaryCaseCollectionFeature"; // Fracture commands