From 7bfe4f4bfe5758c4155c0b0f71361087ab18d849 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Wed, 21 Aug 2019 15:11:29 +0200 Subject: [PATCH] #4603 Python: add case Id to exportSnapshots (#4604) * #4603 Python: add case Id to exportSnapshots * Fixup after review --- .../CommandFileInterface/RicfExportSnapshots.cpp | 3 ++- ApplicationCode/CommandFileInterface/RicfExportSnapshots.h | 1 + .../ExportCommands/RicSnapshotAllViewsToFileFeature.cpp | 7 +++++-- .../ExportCommands/RicSnapshotAllViewsToFileFeature.h | 2 +- ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto | 1 + ApplicationCode/GrpcInterface/Python/rips/Commands.py | 6 ++++-- .../Python/rips/PythonExamples/ExportSnapshots.py | 4 ++-- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp index 97bd0b507d..ee272ec0a1 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp +++ b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.cpp @@ -51,6 +51,7 @@ RicfExportSnapshots::RicfExportSnapshots() { RICF_InitField(&m_type, "type", RicfExportSnapshots::SnapshotsTypeEnum(), "Type", "", "", ""); RICF_InitField(&m_prefix, "prefix", QString(), "Prefix", "", "", ""); + RICF_InitField(&m_caseId, "caseId", -1, "Case Id", "", "", ""); } //-------------------------------------------------------------------------------------------------- @@ -77,7 +78,7 @@ RicfCommandResponse RicfExportSnapshots::execute() } if (m_type == RicfExportSnapshots::VIEWS || m_type == RicfExportSnapshots::ALL) { - RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(absolutePathToSnapshotDir, m_prefix); + RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(absolutePathToSnapshotDir, m_prefix, m_caseId()); } if (m_type == RicfExportSnapshots::PLOTS || m_type == RicfExportSnapshots::ALL) { diff --git a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h index 2d2a706043..47aa2123fa 100644 --- a/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h +++ b/ApplicationCode/CommandFileInterface/RicfExportSnapshots.h @@ -50,4 +50,5 @@ public: private: caf::PdmField m_type; caf::PdmField m_prefix; + caf::PdmField m_caseId; }; diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp index ceac51fa33..6fe37816fd 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.cpp @@ -68,9 +68,9 @@ void RicSnapshotAllViewsToFileFeature::saveAllViews() } //-------------------------------------------------------------------------------------------------- -/// +/// Export all snapshots of a given case (or caseId == -1 for all cases) //-------------------------------------------------------------------------------------------------- -void RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(const QString& snapshotFolderName, const QString& prefix) +void RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(const QString& snapshotFolderName, const QString& prefix /*= ""*/, int caseId /*= -1*/) { RimProject* project = RiaApplication::instance()->project(); @@ -94,6 +94,9 @@ void RicSnapshotAllViewsToFileFeature::exportSnapshotOfAllViewsIntoFolder(const RimCase* cas = projectCases[i]; if (!cas) continue; + bool matchingCaseId = caseId == -1 || caseId == cas->caseId(); + if (!matchingCaseId) continue; + std::vector views = cas->views(); for (size_t j = 0; j < views.size(); j++) diff --git a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h index e8d664f36b..705566be1f 100644 --- a/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h +++ b/ApplicationCode/Commands/ExportCommands/RicSnapshotAllViewsToFileFeature.h @@ -32,7 +32,7 @@ class RicSnapshotAllViewsToFileFeature : public caf::CmdFeature public: static void saveAllViews(); - static void exportSnapshotOfAllViewsIntoFolder(const QString& snapshotFolderName, const QString& prefix = ""); + static void exportSnapshotOfAllViewsIntoFolder(const QString& snapshotFolderName, const QString& prefix = "", int caseId = -1); protected: // Overrides diff --git a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto index d5b531101d..970139eefe 100644 --- a/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto +++ b/ApplicationCode/GrpcInterface/GrpcProtos/Commands.proto @@ -52,6 +52,7 @@ message ExportSnapshotsRequest { SnapshotType type = 1; string prefix = 2; + int32 caseId = 3; } message ExportPropertyRequest diff --git a/ApplicationCode/GrpcInterface/Python/rips/Commands.py b/ApplicationCode/GrpcInterface/Python/rips/Commands.py index 063b92f081..d07ba51327 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/Commands.py +++ b/ApplicationCode/GrpcInterface/Python/rips/Commands.py @@ -118,16 +118,18 @@ class Commands: """ return self.__execute(exportMultiCaseSnapshot=Cmd.ExportMultiCaseRequest(gridListFile=gridListFile)) - def exportSnapshots(self, type = 'ALL', prefix=''): + def exportSnapshots(self, type = 'ALL', prefix='', caseId = -1): """ Export snapshots of a given type Arguments: type (str): Enum string ('ALL', 'VIEWS' or 'PLOTS') prefix (str): Exported file name prefix + caseId (int): the case Id to export for. The default of -1 will export all cases """ return self.__execute(exportSnapshots=Cmd.ExportSnapshotsRequest(type=type, - prefix=prefix)) + prefix=prefix, + caseId=caseId)) def exportProperty(self, caseId, timeStep, property, eclipseKeyword=property, undefinedValue=0.0, exportFile=property): """ Export an Eclipse property diff --git a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ExportSnapshots.py b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ExportSnapshots.py index 8a5ef4cbc7..69f71f80cc 100644 --- a/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ExportSnapshots.py +++ b/ApplicationCode/GrpcInterface/Python/rips/PythonExamples/ExportSnapshots.py @@ -35,9 +35,9 @@ for case in cases: print(case.name, case.id, 'Number of timesteps: ' + str(len(timeSteps))) print('Number of timesteps for snapshoting: ' + str(len(tss_snapshot))) - view = case.view(id = 0) + view = case.views()[0] for property in property_list: view.applyCellResult(resultType='DYNAMIC_NATIVE', resultVariable=property) for ts_snapshot in tss_snapshot: resInsight.commands.setTimeStep(caseId = case.id, timeStep = ts_snapshot) - resInsight.commands.exportSnapshots('VIEWS') # ‘ALL’, ‘VIEWS’ or ‘PLOTS’ default is 'ALL' + resInsight.commands.exportSnapshots(type='VIEWS', caseId=case.id) # ‘ALL’, ‘VIEWS’ or ‘PLOTS’ default is 'ALL'