diff --git a/ApplicationCode/Commands/CMakeLists_files.cmake b/ApplicationCode/Commands/CMakeLists_files.cmake index fee89b9d57..dd81978915 100644 --- a/ApplicationCode/Commands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/CMakeLists_files.cmake @@ -33,6 +33,7 @@ ${CEE_CURRENT_LIST_DIR}RicWellLogsImportFileFeature.h ${CEE_CURRENT_LIST_DIR}RicTogglePerspectiveViewFeature.h ${CEE_CURRENT_LIST_DIR}RicImportGeoMechCaseFeature.h ${CEE_CURRENT_LIST_DIR}RicImportSummaryCaseFeature.h +${CEE_CURRENT_LIST_DIR}RicImportObservedDataFeature.h ${CEE_CURRENT_LIST_DIR}RicExportFeatureImpl.h ${CEE_CURRENT_LIST_DIR}RicSelectOrCreateViewFeatureImpl.h @@ -97,6 +98,7 @@ ${CEE_CURRENT_LIST_DIR}RicReloadFormationNamesFeature.cpp ${CEE_CURRENT_LIST_DIR}RicTogglePerspectiveViewFeature.cpp ${CEE_CURRENT_LIST_DIR}RicImportGeoMechCaseFeature.cpp ${CEE_CURRENT_LIST_DIR}RicImportSummaryCaseFeature.cpp +${CEE_CURRENT_LIST_DIR}RicImportObservedDataFeature.cpp ${CEE_CURRENT_LIST_DIR}RicExportFeatureImpl.cpp ${CEE_CURRENT_LIST_DIR}RicSelectOrCreateViewFeatureImpl.cpp diff --git a/ApplicationCode/Commands/RicImportObservedDataFeature.cpp b/ApplicationCode/Commands/RicImportObservedDataFeature.cpp new file mode 100644 index 0000000000..1be433c396 --- /dev/null +++ b/ApplicationCode/Commands/RicImportObservedDataFeature.cpp @@ -0,0 +1,98 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicImportObservedDataFeature.h" + +#include "RiaApplication.h" + +#include "RimObservedDataCollection.h" +#include "RimOilField.h" +#include "RimProject.h" +#include "RimSummaryObservedDataFile.h" + +#include +#include + + +CAF_CMD_SOURCE_INIT(RicImportObservedDataFeature, "RicImportObservedDataFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicImportObservedDataFeature::RicImportObservedDataFeature() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicImportObservedDataFeature::isCommandEnabled() +{ + return true; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportObservedDataFeature::onActionTriggered(bool isChecked) +{ + RiaApplication* app = RiaApplication::instance(); + QString defaultDir = app->lastUsedDialogDirectory("INPUT_FILES"); + QStringList fileNames = QFileDialog::getOpenFileNames(NULL, "Import Observed Data", defaultDir, "Observed Data File;;All Files (*.*)"); + + if (fileNames.isEmpty()) return; + + // Remember the path to next time + app->setLastUsedDialogDirectory("INPUT_FILES", QFileInfo(fileNames.last()).absolutePath()); + + RimProject* proj = app->project(); + RimObservedDataCollection* observedDataCollection = proj->activeOilField() ? proj->activeOilField()->observedDataCollection() : nullptr; + if (!observedDataCollection) return; + + for (auto fileName : fileNames) + { + RicImportObservedDataFeature::createAndAddObservedDataFromFile(fileName); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicImportObservedDataFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setIcon(QIcon(":/Default.png")); + actionToSetup->setText("Import Observed Data"); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicImportObservedDataFeature::createAndAddObservedDataFromFile(const QString& fileName) +{ + RiaApplication* app = RiaApplication::instance(); + RimProject* proj = app->project(); + + RimObservedDataCollection* observedDataCollection = proj->activeOilField() ? proj->activeOilField()->observedDataCollection() : nullptr; + if (!observedDataCollection) return false; + + RimSummaryObservedDataFile* newObservedData = observedDataCollection->createAndAddObservedDataFromFileName(fileName); + newObservedData->loadCase(); + + return true; +} + diff --git a/ApplicationCode/Commands/RicImportObservedDataFeature.h b/ApplicationCode/Commands/RicImportObservedDataFeature.h new file mode 100644 index 0000000000..463a03c128 --- /dev/null +++ b/ApplicationCode/Commands/RicImportObservedDataFeature.h @@ -0,0 +1,42 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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" + +#include "cafPdmField.h" + +//================================================================================================== +// +// +// +//================================================================================================== +class RicImportObservedDataFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +public: + RicImportObservedDataFeature(); + +private: + virtual bool isCommandEnabled() override; + virtual void onActionTriggered(bool isChecked) override; + virtual void setupActionLook(QAction* actionToSetup) override; + bool createAndAddObservedDataFromFile(const QString& fileName); +};