From 1c483c74207655d9990e64c1fc52e3beab9b76b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rnar=20Grip=20Fj=C3=A6r?= Date: Tue, 29 Aug 2017 14:29:45 +0200 Subject: [PATCH] #1697 Export of visible cells to FLUXNUM / MULTNUM .GRDECL file --- .../ExportCommands/CMakeLists_files.cmake | 4 + ...RicSaveEclipseInputVisibleCellsFeature.cpp | 126 ++++++++++++++++++ .../RicSaveEclipseInputVisibleCellsFeature.h | 42 ++++++ .../RicSaveEclipseInputVisibleCellsUi.cpp | 117 ++++++++++++++++ .../RicSaveEclipseInputVisibleCellsUi.h | 62 +++++++++ .../FileInterface/RifEclipseInputFileTools.h | 2 +- .../RimContextCommandBuilder.cpp | 1 + .../UserInterface/RiuViewerCommands.cpp | 1 + 8 files changed, 354 insertions(+), 1 deletion(-) create mode 100644 ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.cpp create mode 100644 ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.h create mode 100644 ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.cpp create mode 100644 ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.h diff --git a/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake b/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake index 9ede0c258a..e667c58d71 100644 --- a/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake +++ b/ApplicationCode/Commands/ExportCommands/CMakeLists_files.cmake @@ -13,6 +13,8 @@ ${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.h ${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.h ${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.h ${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.h +${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputVisibleCellsFeature.h +${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputVisibleCellsUi.h ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.h ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.h ${CEE_CURRENT_LIST_DIR}RicSnapshotAllPlotsToFileFeature.h @@ -31,6 +33,8 @@ ${CEE_CURRENT_LIST_DIR}RicExportMultipleSnapshotsFeature.cpp ${CEE_CURRENT_LIST_DIR}RicExportToLasFileFeature.cpp ${CEE_CURRENT_LIST_DIR}RicExportToLasFileResampleUi.cpp ${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputPropertyFeature.cpp +${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputVisibleCellsFeature.cpp +${CEE_CURRENT_LIST_DIR}RicSaveEclipseInputVisibleCellsUi.cpp ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyExec.cpp ${CEE_CURRENT_LIST_DIR}RicSaveEclipseResultAsInputPropertyFeature.cpp ${CEE_CURRENT_LIST_DIR}RicSnapshotAllPlotsToFileFeature.cpp diff --git a/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.cpp new file mode 100644 index 0000000000..d2982bc7bf --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.cpp @@ -0,0 +1,126 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicSaveEclipseInputVisibleCellsFeature.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" + +#include "RicExportFeatureImpl.h" + +#include "RicSaveEclipseInputVisibleCellsUi.h" + +#include "RifEclipseInputFileTools.h" + +#include "RimView.h" +#include "RimEclipseView.h" +#include "RimEclipseCase.h" + +#include "RigEclipseCaseData.h" +#include "RigActiveCellInfo.h" + +#include "RiuMainWindow.h" + +#include "cafPdmUiPropertyViewDialog.h" +#include "cafSelectionManager.h" + +#include +#include +#include + +CAF_CMD_SOURCE_INIT(RicSaveEclipseInputVisibleCellsFeature, "RicSaveEclipseInputVisibleCellsFeature"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RicSaveEclipseInputVisibleCellsFeature::isCommandEnabled() +{ + return getSelectedEclipseView() != nullptr; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSaveEclipseInputVisibleCellsFeature::onActionTriggered(bool isChecked) +{ + RimEclipseView* view = getEclipseActiveView(); + + RicSaveEclipseInputVisibleCellsUi exportSettings; + caf::PdmUiPropertyViewDialog propertyDialog(RiuMainWindow::instance(), &exportSettings, "Export FLUXNUM/MULTNUM", ""); + RicExportFeatureImpl::configureForExport(&propertyDialog); + + if (propertyDialog.exec() == QDialog::Accepted) + { + std::vector values; + cvf::UByteArray visibleCells; + view->calculateCurrentTotalCellVisibility(&visibleCells, view->currentTimeStep()); + RigActiveCellInfo* activeCellInfo = view->eclipseCase()->eclipseCaseData()->activeCellInfo(RiaDefines::MATRIX_MODEL); + values.resize(visibleCells.size()); + for (size_t i = 0; i < visibleCells.size(); ++i) + { + if (activeCellInfo->isActive(i)) + { + if (visibleCells[i]) + { + values[i] = static_cast(exportSettings.visibleActiveCellsValue); + } + else + { + values[i] = static_cast(exportSettings.hiddenActiveCellsValue); + } + } + else + { + values[i] = static_cast(exportSettings.inactiveCellsValue); + } + } + QFile exportFile(exportSettings.exportFilename); + if (!exportFile.open(QIODevice::WriteOnly | QIODevice::Text)) + { + RiaLogging::error(QString("saveEclipseInputVisibleCells: Unable to open file '%1' for writing.").arg(exportSettings.exportFilename)); + return; + } + RifEclipseInputFileTools::writeDataToTextFile(&exportFile, exportSettings.exportKeyword().text(), values); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSaveEclipseInputVisibleCellsFeature::setupActionLook(QAction* actionToSetup) +{ + actionToSetup->setText("Export Visible Cells as FLUXNUM/MULTNUM"); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseView* RicSaveEclipseInputVisibleCellsFeature::getEclipseActiveView() +{ + RimView* activeView = RiaApplication::instance()->activeReservoirView(); + + return dynamic_cast(activeView); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RimEclipseView * RicSaveEclipseInputVisibleCellsFeature::getSelectedEclipseView() +{ + return dynamic_cast(caf::SelectionManager::instance()->selectedItem()); +} diff --git a/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.h b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.h new file mode 100644 index 0000000000..6c7290359e --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsFeature.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" + +class RimEclipseInputProperty; +class RimEclipseView; + +//================================================================================================== +/// +//================================================================================================== +class RicSaveEclipseInputVisibleCellsFeature : public caf::CmdFeature +{ + CAF_CMD_HEADER_INIT; + +protected: + // Overrides + virtual bool isCommandEnabled(); + virtual void onActionTriggered( bool isChecked ); + virtual void setupActionLook( QAction* actionToSetup ); + +private: + RimEclipseView* getEclipseActiveView(); + RimEclipseView* getSelectedEclipseView(); +}; diff --git a/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.cpp b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.cpp new file mode 100644 index 0000000000..675cd5681e --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.cpp @@ -0,0 +1,117 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicSaveEclipseInputVisibleCellsUi.h" + +#include "RiaApplication.h" + +#include "cafPdmUiFilePathEditor.h" +#include "cafPdmUiOrdering.h" + +#include + +namespace caf { + + template<> + void RicSaveEclipseInputVisibleCellsUi::ExportKeywordEnum::setUp() + { + addItem(RicSaveEclipseInputVisibleCellsUi::FLUXNUM, "FLUXNUM", "FLUXNUM"); + addItem(RicSaveEclipseInputVisibleCellsUi::MULTNUM, "MULTNUM", "MULTNUM"); + setDefault(RicSaveEclipseInputVisibleCellsUi::FLUXNUM); + } +} + +CAF_PDM_SOURCE_INIT(RicSaveEclipseInputVisibleCellsUi, "RicSaveEclipseInputVisibleCellsUi"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicSaveEclipseInputVisibleCellsUi::RicSaveEclipseInputVisibleCellsUi(void) : exportFilenameManuallyChanged(false) +{ + CAF_PDM_InitObject("Export Visible Cells FLUXNUM/MULTNUM", "", "", ""); + + CAF_PDM_InitField(&exportFilename, "ExportFilename", QString(), "Export Filename", "", "", ""); + exportFilename.uiCapability()->setUiEditorTypeName(caf::PdmUiFilePathEditor::uiEditorTypeName()); + CAF_PDM_InitFieldNoDefault(&exportKeyword, "ExportKeyword", "Export Keyword", "", "", ""); + CAF_PDM_InitField(&visibleActiveCellsValue, "VisibleActiveCellsValue", 1, "Visible Active Cells Value", "", "", ""); + CAF_PDM_InitField(&hiddenActiveCellsValue, "HiddenActiveCellsValue", 0, "Hidden Active Cells Value", "", "", ""); + CAF_PDM_InitField(&inactiveCellsValue, "InactiveCellsValue", 0, "Inactive Cells Value", "", "", ""); + + exportFilename = getDefaultExportPath(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicSaveEclipseInputVisibleCellsUi::~RicSaveEclipseInputVisibleCellsUi() +{ +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSaveEclipseInputVisibleCellsUi::defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute * attribute) +{ + if (field == &exportFilename) + { + caf::PdmUiFilePathEditorAttribute* myAttr = dynamic_cast(attribute); + if (myAttr) + { + myAttr->m_selectSaveFileName = true; + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSaveEclipseInputVisibleCellsUi::defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) +{ + uiOrdering.add(&exportFilename); + uiOrdering.add(&exportKeyword); + uiOrdering.add(&visibleActiveCellsValue); + uiOrdering.add(&hiddenActiveCellsValue); + uiOrdering.add(&inactiveCellsValue); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicSaveEclipseInputVisibleCellsUi::fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) +{ + if (changedField == &exportFilename) + { + exportFilenameManuallyChanged = true; + } + else if (changedField == &exportKeyword) + { + if (!exportFilenameManuallyChanged) + { + exportFilename = getDefaultExportPath(); + } + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicSaveEclipseInputVisibleCellsUi::getDefaultExportPath() const +{ + QDir baseDir(RiaApplication::instance()->currentProjectPath()); + return baseDir.absoluteFilePath(QString("%1.grdecl").arg(exportKeyword().text())); +} diff --git a/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.h b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.h new file mode 100644 index 0000000000..fbcaf1adc4 --- /dev/null +++ b/ApplicationCode/Commands/ExportCommands/RicSaveEclipseInputVisibleCellsUi.h @@ -0,0 +1,62 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "cafPdmField.h" +#include "cafPdmObject.h" +#include "cafPdmChildArrayField.h" +#include "cafAppEnum.h" + +//================================================================================================== +/// +//================================================================================================== +class RicSaveEclipseInputVisibleCellsUi : public caf::PdmObject +{ + CAF_PDM_HEADER_INIT; + +public: + enum ExportKeyword + { + FLUXNUM, + MULTNUM, + }; + + typedef caf::AppEnum ExportKeywordEnum; + +public: + RicSaveEclipseInputVisibleCellsUi(void); + ~RicSaveEclipseInputVisibleCellsUi(); + + caf::PdmField exportFilename; + caf::PdmField exportKeyword; + caf::PdmField visibleActiveCellsValue; + caf::PdmField hiddenActiveCellsValue; + caf::PdmField inactiveCellsValue; + +protected: + virtual void defineEditorAttribute(const caf::PdmFieldHandle* field, QString uiConfigName, caf::PdmUiEditorAttribute* attribute); + virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; + +private: + QString getDefaultExportPath() const; + +private: + bool exportFilenameManuallyChanged; +}; diff --git a/ApplicationCode/FileInterface/RifEclipseInputFileTools.h b/ApplicationCode/FileInterface/RifEclipseInputFileTools.h index f1172c08b6..65741c08e8 100644 --- a/ApplicationCode/FileInterface/RifEclipseInputFileTools.h +++ b/ApplicationCode/FileInterface/RifEclipseInputFileTools.h @@ -88,10 +88,10 @@ public: const QString& faultIncludeFileAbsolutePathPrefix); static cvf::StructGridInterface::FaceEnum faceEnumFromText(const QString& faceString); + static void writeDataToTextFile(QFile* file, const QString& eclipseKeyWord, const std::vector& resultData); private: static bool readDataFromKeyword(ecl_kw_type* eclipseKeywordData, RigEclipseCaseData* caseData, const QString& resultName); - static void writeDataToTextFile(QFile* file, const QString& eclipseKeyWord, const std::vector& resultData); static void findGridKeywordPositions(const std::vector< RifKeywordAndFilePos >& keywords, qint64* coordPos, qint64* zcornPos, qint64* specgridPos, qint64* actnumPos, qint64* mapaxesPos); static size_t findFaultByName(const cvf::Collection& faults, const QString& name); diff --git a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp index 7e50d864c5..ead23b2b6c 100644 --- a/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -125,6 +125,7 @@ QStringList RimContextCommandBuilder::commandsFromSelection() commandIds << "RicNewViewFeature"; commandIds << "Separator"; commandIds << "RicCopyReferencesToClipboardFeature"; + commandIds << "RicSaveEclipseInputVisibleCellsFeature"; } else if (dynamic_cast(uiItem)) { diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index fbda17b2b6..1cf874f6be 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -353,6 +353,7 @@ void RiuViewerCommands::displayContextMenu(QMouseEvent* event) commandIds << "Separator"; commandIds << "RicNewGridTimeHistoryCurveFeature"; commandIds << "RicShowFlowCharacteristicsPlotFeature"; + commandIds << "RicSaveEclipseInputVisibleCellsFeature"; RimContextCommandBuilder::appendCommandsToMenu(commandIds, &menu);