From 63bb85b9982fc7e79c7b44502842cac4fb1ef5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rnar=20Grip=20Fj=C3=A6r?= Date: Fri, 11 Aug 2017 15:37:46 +0200 Subject: [PATCH] #1387 Command to delete existing sour sim data from ResInsight --- .../Commands/CMakeLists_files.cmake | 4 ++ .../Commands/RicDeleteSourSimDataFeature.cpp | 67 +++++++++++++++++++ .../Commands/RicDeleteSourSimDataFeature.h | 40 +++++++++++ .../FileInterface/RifReaderEclipseOutput.cpp | 8 +++ .../RimContextCommandBuilder.cpp | 1 + 5 files changed, 120 insertions(+) create mode 100644 ApplicationCode/Commands/RicDeleteSourSimDataFeature.cpp create mode 100644 ApplicationCode/Commands/RicDeleteSourSimDataFeature.h diff --git a/ApplicationCode/Commands/CMakeLists_files.cmake b/ApplicationCode/Commands/CMakeLists_files.cmake index 806e5bc397..1e35d7a66f 100644 --- a/ApplicationCode/Commands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CMakeLists_files.cmake @@ -44,6 +44,8 @@ ${CEE_CURRENT_LIST_DIR}RicDeleteItemExecData.h ${CEE_CURRENT_LIST_DIR}RicDeleteItemFeature.h ${CEE_CURRENT_LIST_DIR}RicDeleteSubItemsFeature.h +${CEE_CURRENT_LIST_DIR}RicDeleteSourSimDataFeature.h + ${CEE_CURRENT_LIST_DIR}RicCommandFeature.h ${CEE_CURRENT_LIST_DIR}RicReloadCaseFeature.h @@ -86,6 +88,8 @@ ${CEE_CURRENT_LIST_DIR}RicDeleteItemFeature.cpp ${CEE_CURRENT_LIST_DIR}RicDeleteSubItemsFeature.cpp +${CEE_CURRENT_LIST_DIR}RicDeleteSourSimDataFeature.cpp + ${CEE_CURRENT_LIST_DIR}RicReloadCaseFeature.cpp ) diff --git a/ApplicationCode/Commands/RicDeleteSourSimDataFeature.cpp b/ApplicationCode/Commands/RicDeleteSourSimDataFeature.cpp new file mode 100644 index 0000000000..acf0191fae --- /dev/null +++ b/ApplicationCode/Commands/RicDeleteSourSimDataFeature.cpp @@ -0,0 +1,67 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicDeleteSourSimDataFeature.h" + +#include "RimEclipseResultCase.h" + +#include "cafSelectionManager.h" + +#include + + +CAF_CMD_SOURCE_INIT(RicDeleteSourSimDataFeature, "RicDeleteSourSimDataFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicDeleteSourSimDataFeature::isCommandEnabled() +{ + return getSelectedEclipseCase() != nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicDeleteSourSimDataFeature::onActionTriggered(bool isChecked) +{ + RimEclipseResultCase* eclipseCase = getSelectedEclipseCase(); + + if (eclipseCase == nullptr) return; + + eclipseCase->setSourSimFileName(QString()); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicDeleteSourSimDataFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Delete SourSim Data"); + actionToSetup->setIcon(QIcon(":/Erase.png")); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseResultCase* RicDeleteSourSimDataFeature::getSelectedEclipseCase() +{ + caf::PdmUiItem* selectedItem = caf::SelectionManager::instance()->selectedItem(); + RimEclipseResultCase* eclipseCase = dynamic_cast(selectedItem); + return eclipseCase; +} diff --git a/ApplicationCode/Commands/RicDeleteSourSimDataFeature.h b/ApplicationCode/Commands/RicDeleteSourSimDataFeature.h new file mode 100644 index 0000000000..c76ea20d01 --- /dev/null +++ b/ApplicationCode/Commands/RicDeleteSourSimDataFeature.h @@ -0,0 +1,40 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 RimEclipseResultCase; + +//================================================================================================== +/// +//================================================================================================== +class RicDeleteSourSimDataFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; +protected: + + // Overrides + virtual bool isCommandEnabled(); + virtual void onActionTriggered( bool isChecked ); + virtual void setupActionLook( QAction* actionToSetup ); + +private: + static RimEclipseResultCase* getSelectedEclipseCase(); +}; diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index c426148ac2..2b42f7e325 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -458,6 +458,14 @@ void RifReaderEclipseOutput::setHdf5FileName(const QString& fileName) RigCaseCellResultsData* matrixModelResults = m_eclipseCase->results(RifReaderInterface::MATRIX_RESULTS); CVF_ASSERT(matrixModelResults); + if (fileName.isEmpty()) + { + RiaLogging::info("HDF: Removing all existing Sour Sim data ..."); + matrixModelResults->eraseAllSourSimData(); + + return; + } + RiaLogging::info(QString("HDF: Start import of data from : ").arg(fileName)); RiaLogging::info("HDF: Removing all existing Sour Sim data ..."); diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 1ed541ec64..dab7048433 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -410,6 +410,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() { commandIds << "RicReloadCaseFeature"; commandIds << "RicExecuteScriptForCasesFeature"; + commandIds << "RicDeleteSourSimDataFeature"; } else if (dynamic_cast(uiItem)) {