From c02c39d59d9e931e7efdab94125a195da9fe91e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rnar=20Grip=20Fj=C3=A6r?= Date: Fri, 28 Jul 2017 11:28:55 +0200 Subject: [PATCH] #1665 Add replaceCase command to command file interface --- ApplicationCode/Application/RiaApplication.h | 17 ++--- .../CMakeLists_files.cmake | 2 + .../RicfCommandFileExecutor.cpp | 18 ++++- .../RicfCommandFileExecutor.h | 5 +- .../CommandFileInterface/RicfOpenProject.cpp | 5 ++ .../CommandFileInterface/RicfReplaceCase.cpp | 68 +++++++++++++++++++ .../CommandFileInterface/RicfReplaceCase.h | 36 ++++++++++ .../CommandFileInterface/RicfSetTimeStep.cpp | 1 - 8 files changed, 141 insertions(+), 11 deletions(-) create mode 100644 ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp create mode 100644 ApplicationCode/CommandFileInterface/RicfReplaceCase.h diff --git a/ApplicationCode/Application/RiaApplication.h b/ApplicationCode/Application/RiaApplication.h index 2653c03e19..f0bb87bfc6 100644 --- a/ApplicationCode/Application/RiaApplication.h +++ b/ApplicationCode/Application/RiaApplication.h @@ -82,6 +82,12 @@ public: NAVIGATION_POLICY_RMS }; + enum ProjectLoadAction + { + PLA_NONE = 0, + PLA_CALCULATE_STATISTICS = 1 + }; + public: RiaApplication(int& argc, char** argv); ~RiaApplication(); @@ -123,6 +129,7 @@ public: QString currentProjectPath() const; QString createAbsolutePathFromProjectRelativePath(QString projectRelativePath); bool loadProject(const QString& projectFileName); + bool loadProject(const QString& projectFileName, ProjectLoadAction loadAction, RiaProjectModifier* projectModifier); bool saveProject(); bool saveProjectAs(const QString& fileName); bool saveProjectPromptForFileName(); @@ -196,17 +203,11 @@ public: void setStartDir(const QString& startDir); -private: - enum ProjectLoadAction - { - PLA_NONE = 0, - PLA_CALCULATE_STATISTICS = 1 - }; + static std::vector readFileListFromTextFile(QString listFileName); - bool loadProject(const QString& projectFileName, ProjectLoadAction loadAction, RiaProjectModifier* projectModifier); +private: void onProjectOpenedOrClosed(); - std::vector readFileListFromTextFile(QString listFileName); void setWindowCaptionFromAppState(); void clearViewsScheduledForUpdate(); diff --git a/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake b/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake index 7ee248aa95..adc50aad95 100644 --- a/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake +++ b/ApplicationCode/CommandFileInterface/CMakeLists_files.cmake @@ -9,6 +9,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportSnapshots.h ${CMAKE_CURRENT_LIST_DIR}/RicfExportWellPathCompletions.h ${CMAKE_CURRENT_LIST_DIR}/RicfLoadCase.h ${CMAKE_CURRENT_LIST_DIR}/RicfOpenProject.h +${CMAKE_CURRENT_LIST_DIR}/RicfReplaceCase.h ${CMAKE_CURRENT_LIST_DIR}/RicfRunOctaveScript.h ${CMAKE_CURRENT_LIST_DIR}/RicfSetExportFolder.h ${CMAKE_CURRENT_LIST_DIR}/RicfSetMainWindowSize.h @@ -26,6 +27,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RicfExportSnapshots.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfExportWellPathCompletions.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfLoadCase.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfOpenProject.cpp +${CMAKE_CURRENT_LIST_DIR}/RicfReplaceCase.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfRunOctaveScript.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfSetExportFolder.cpp ${CMAKE_CURRENT_LIST_DIR}/RicfSetMainWindowSize.cpp diff --git a/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.cpp b/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.cpp index f505fe9ba3..2d3035a1a8 100644 --- a/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.cpp +++ b/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.cpp @@ -84,7 +84,7 @@ void RicfCommandFileExecutor::setExportPath(ExportType type, QString path) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -QString RicfCommandFileExecutor::getExportPath(ExportType type) +QString RicfCommandFileExecutor::getExportPath(ExportType type) const { auto it = m_exportPaths.find(type); QString path; @@ -95,6 +95,22 @@ QString RicfCommandFileExecutor::getExportPath(ExportType type) return path; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicfCommandFileExecutor::setLastProjectPath(const QString& path) +{ + m_lastProjectPath = path; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RicfCommandFileExecutor::getLastProjectPath() const +{ + return m_lastProjectPath; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.h b/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.h index 5775acdb89..938d24861d 100644 --- a/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.h +++ b/ApplicationCode/CommandFileInterface/RicfCommandFileExecutor.h @@ -39,7 +39,9 @@ public: void executeCommands(QTextStream& stream); void setExportPath(ExportType type, QString path); - QString getExportPath(ExportType type); + QString getExportPath(ExportType type) const; + void setLastProjectPath(const QString& path); + QString getLastProjectPath() const; static RicfCommandFileExecutor* instance(); @@ -47,4 +49,5 @@ private: RicfMessages m_messages; std::map m_exportPaths; + QString m_lastProjectPath; }; diff --git a/ApplicationCode/CommandFileInterface/RicfOpenProject.cpp b/ApplicationCode/CommandFileInterface/RicfOpenProject.cpp index 24f119535e..166963a44b 100644 --- a/ApplicationCode/CommandFileInterface/RicfOpenProject.cpp +++ b/ApplicationCode/CommandFileInterface/RicfOpenProject.cpp @@ -18,6 +18,8 @@ #include "RicfOpenProject.h" +#include "RicfCommandFileExecutor.h" + #include "RiaApplication.h" #include "RiaLogging.h" @@ -40,5 +42,8 @@ void RicfOpenProject::execute() if (!ok) { RiaLogging::error(QString("openProject: Unable to open project at %1").arg(m_path())); + return; } + + RicfCommandFileExecutor::instance()->setLastProjectPath(m_path); } diff --git a/ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp b/ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp new file mode 100644 index 0000000000..3364dfddc2 --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfReplaceCase.cpp @@ -0,0 +1,68 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicfReplaceCase.h" + +#include "RicfCommandFileExecutor.h" + +#include "RiaApplication.h" +#include "RiaLogging.h" +#include "RiaProjectModifier.h" + +CAF_PDM_SOURCE_INIT(RicfReplaceCase, "replaceCase"); + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RicfReplaceCase::RicfReplaceCase() +{ + RICF_InitField(&m_caseId, "case", -1, "Case ID", "", "", ""); + RICF_InitField(&m_newGridFile, "newGridFile", QString(), "New Grid File", "", "", ""); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RicfReplaceCase::execute() +{ + if (m_newGridFile().isNull()) + { + RiaLogging::error("replaceCase: Required parameter newGridFile."); + return; + } + + QString lastProjectPath = RicfCommandFileExecutor::instance()->getLastProjectPath(); + if (lastProjectPath.isNull()) + { + RiaLogging::error("replaceCase: 'openProject' must be called before 'replaceCase' to specify project file to replace case in."); + return; + } + + + cvf::ref projectModifier; + if (m_caseId() == -1) + { + projectModifier->setReplaceCaseFirstOccurrence(m_newGridFile()); + } + else + { + projectModifier->setReplaceCase(m_caseId(), m_newGridFile()); + } + + RiaApplication::instance()->loadProject(lastProjectPath, RiaApplication::PLA_NONE, projectModifier.p()); +} diff --git a/ApplicationCode/CommandFileInterface/RicfReplaceCase.h b/ApplicationCode/CommandFileInterface/RicfReplaceCase.h new file mode 100644 index 0000000000..d853480290 --- /dev/null +++ b/ApplicationCode/CommandFileInterface/RicfReplaceCase.h @@ -0,0 +1,36 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// 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 "RicfCommandObject.h" + +#include "cafPdmField.h" + +class RicfReplaceCase : public RicfCommandObject +{ + CAF_PDM_HEADER_INIT; + +public: + RicfReplaceCase(); + + virtual void execute() override; + +private: + caf::PdmField m_newGridFile; + caf::PdmField m_caseId; +}; diff --git a/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp b/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp index 82bacbc682..f487b37352 100644 --- a/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp +++ b/ApplicationCode/CommandFileInterface/RicfSetTimeStep.cpp @@ -1,4 +1,3 @@ -#include "RicfSetTimeStep.h" ///////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2017 Statoil ASA