From 946351c853ec4a2f1cd27acd99ddac2d87d9384b Mon Sep 17 00:00:00 2001 From: rebcox1 <31475085+rebcox1@users.noreply.github.com> Date: Mon, 4 Sep 2017 15:05:13 +0200 Subject: [PATCH] #1728 Add close summary command. Dependent curves yet not deleted --- .../Commands/CMakeLists_files.cmake | 2 + .../Commands/RicCloseSummaryCaseFeature.cpp | 83 +++++++++++++++++++ .../Commands/RicCloseSummaryCaseFeature.h | 20 +++++ .../RimContextCommandBuilder.cpp | 2 + .../Summary/RimSummaryCaseCollection.h | 2 +- .../Summary/RimSummaryCurve.cpp | 17 ++-- 6 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp create mode 100644 ApplicationCode/Commands/RicCloseSummaryCaseFeature.h diff --git a/ApplicationCode/Commands/CMakeLists_files.cmake b/ApplicationCode/Commands/CMakeLists_files.cmake index 0f0eb51e89..212c5fbc31 100644 --- a/ApplicationCode/Commands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CMakeLists_files.cmake @@ -6,6 +6,7 @@ endif() set (SOURCE_GROUP_HEADER_FILES ${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.h +${CEE_CURRENT_LIST_DIR}RicCloseSummaryCaseFeature.h ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterFeatureImpl.h ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertFeature.h ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertExec.h @@ -68,6 +69,7 @@ endif() set (SOURCE_GROUP_SOURCE_FILES ${CEE_CURRENT_LIST_DIR}RicCloseCaseFeature.cpp +${CEE_CURRENT_LIST_DIR}RicCloseSummaryCaseFeature.cpp ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterFeatureImpl.cpp ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertFeature.cpp ${CEE_CURRENT_LIST_DIR}RicGeoMechPropertyFilterInsertExec.cpp diff --git a/ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp new file mode 100644 index 0000000000..930bca5522 --- /dev/null +++ b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.cpp @@ -0,0 +1,83 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2016- 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 "RicCloseSummaryCaseFeature.h" +#include "RimSummaryCaseCollection.h" +#include "cafSelectionManager.h" +#include "RimMainPlotCollection.h" +#include "RimProject.h" +#include "RiaApplication.h" +#include "RimSummaryCase.h" +#include "cvfAssert.h" +#include + + +CAF_CMD_SOURCE_INIT(RicCloseSummaryCaseFeature, "RicCloseSummaryCaseFeature"); + + +void RicCloseSummaryCaseFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Close Summary Plot"); + actionToSetup->setIcon(QIcon(":/Erase.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicCloseSummaryCaseFeature::isCommandEnabled() +{ + return selectedSummaryCase() != NULL; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimSummaryCase* RicCloseSummaryCaseFeature::selectedSummaryCase() const +{ + std::vector selection; + caf::SelectionManager::instance()->objectsByType(&selection); + + if (selection.size() > 0) + { + return selection[0]; + } + + return NULL; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicCloseSummaryCaseFeature::onActionTriggered(bool isChecked) +{ + std::vector selection; + caf::SelectionManager::instance()->objectsByType(&selection); + assert(selection.size() > 0); + + for (RimSummaryCase* summaryCase : selection) + { + RimSummaryCaseCollection* summaryCaseCollection = NULL; + summaryCase->firstAncestorOrThisOfType(summaryCaseCollection); + CVF_ASSERT(summaryCaseCollection); + + summaryCaseCollection->deleteCase(summaryCase); + delete summaryCase; + summaryCaseCollection->updateConnectedEditors(); + } +} \ No newline at end of file diff --git a/ApplicationCode/Commands/RicCloseSummaryCaseFeature.h b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.h new file mode 100644 index 0000000000..9baa1e5137 --- /dev/null +++ b/ApplicationCode/Commands/RicCloseSummaryCaseFeature.h @@ -0,0 +1,20 @@ +#pragma once +#include "cafCmdFeature.h" +#include "vector" + +class RimSummaryCase; + +class RicCloseSummaryCaseFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; +public: + +protected: + // Overrides + virtual bool isCommandEnabled(); + virtual void onActionTriggered(bool isChecked); + virtual void setupActionLook(QAction* actionToSetup); +private: + RimSummaryCase* selectedSummaryCase() const; +}; + diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index edcb757c78..7b60cd02e9 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -443,6 +443,8 @@ QStringList RimContextCommandBuilder::commandsFromSelection() commandIds << "RicWellPathImportCompletionsFileFeature"; commandIds << "RicFlyToObjectFeature"; commandIds << "RicExportCarfin"; + commandIds << "RicCloseSummaryCaseFeature"; + // Fracture commands #ifdef USE_PROTOTYPE_FEATURE_FRACTURES diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h index 14db31be05..49feaf05e6 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCaseCollection.h @@ -32,7 +32,7 @@ public: RimSummaryCase* summaryCase(size_t idx); size_t summaryCaseCount(); - + void createSummaryCasesFromRelevantEclipseResultCases(); RimSummaryCase* createAndAddSummaryCaseFromEclipseResultCase(RimEclipseResultCase* eclResCase); RimSummaryCase* createAndAddSummaryCaseFromFileName(const QString& fileName); diff --git a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp index 71accadb81..afd9f14302 100644 --- a/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp +++ b/ApplicationCode/ProjectDataModel/Summary/RimSummaryCurve.cpp @@ -195,7 +195,7 @@ RimSummaryCurve::~RimSummaryCurve() //-------------------------------------------------------------------------------------------------- void RimSummaryCurve::setSummaryCase(RimSummaryCase* sumCase) { - m_summaryCase = sumCase; + m_summaryCase = sumCase; } //-------------------------------------------------------------------------------------------------- @@ -504,10 +504,17 @@ void RimSummaryCurve::fieldChangedByUi(const caf::PdmFieldHandle* changedField, if(changedField == &m_uiFilterResultSelection) { - if (0 <= m_uiFilterResultSelection() && static_cast(m_uiFilterResultSelection()) < summaryReader()->allResultAddresses().size()) - { - m_curveVariable->setAddress(summaryReader()->allResultAddresses()[m_uiFilterResultSelection()]); - } + if (summaryReader()) + { + if (0 <= m_uiFilterResultSelection() && static_cast(m_uiFilterResultSelection()) < summaryReader()->allResultAddresses().size()) + { + m_curveVariable->setAddress(summaryReader()->allResultAddresses()[m_uiFilterResultSelection()]); + } + else + { + m_curveVariable->setAddress(RifEclipseSummaryAddress()); + } + } else { m_curveVariable->setAddress(RifEclipseSummaryAddress());