From cf7aa0e2f02fc9c9ddfa93eb654104b782f50be9 Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Tue, 4 Jul 2023 17:38:00 +0200 Subject: [PATCH 1/3] #4692 - Add a GTest for Model::load --- resources/CMakeLists.txt | 2 ++ resources/model/empty361.osm | 5 +++++ resources/model/empty361/workflow.osw | 6 ++++++ src/model/test/Model_GTest.cpp | 29 ++++++++++++++++++++++++++- 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 resources/model/empty361.osm create mode 100644 resources/model/empty361/workflow.osw diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 9c47de51d50..d97a7620cde 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -175,6 +175,8 @@ set(model_resources_src model/ASHRAECourthouse.osm model/A205ExampleChiller.RS0001.a205.cbor model/4837_SpaceVolume.osm + model/empty361.osm + model/empty361/workflow.osw ) diff --git a/resources/model/empty361.osm b/resources/model/empty361.osm new file mode 100644 index 00000000000..9e538acfe7f --- /dev/null +++ b/resources/model/empty361.osm @@ -0,0 +1,5 @@ + +OS:Version, + {e2190a61-e3f3-4d4b-8c0b-7a9c2342180e}, !- Handle + 3.6.1; !- Version Identifier + diff --git a/resources/model/empty361/workflow.osw b/resources/model/empty361/workflow.osw new file mode 100644 index 00000000000..147ae7382be --- /dev/null +++ b/resources/model/empty361/workflow.osw @@ -0,0 +1,6 @@ +{ + "created_at" : "20230704T152451Z", + "seed_file" : "../empty361.osm", + "steps" : [], + "updated_at" : "20230704T152548Z" +} \ No newline at end of file diff --git a/src/model/test/Model_GTest.cpp b/src/model/test/Model_GTest.cpp index 8ad9498582f..b000740e612 100644 --- a/src/model/test/Model_GTest.cpp +++ b/src/model/test/Model_GTest.cpp @@ -129,16 +129,18 @@ #include "../ExternalInterface.hpp" #include "../ExternalInterface_Impl.hpp" -#include "../../utilities/sql/SqlFile.hpp" +#include "../../utilities/core/PathHelpers.hpp" #include "../../utilities/data/TimeSeries.hpp" #include "../../utilities/idf/IdfFile.hpp" #include "../../utilities/idf/Workspace.hpp" #include "../../utilities/idf/WorkspaceObject.hpp" #include "../../utilities/idf/ValidityReport.hpp" +#include "../../utilities/sql/SqlFile.hpp" #include "../../osversion/VersionTranslator.hpp" #include +#include #include @@ -1160,3 +1162,28 @@ TEST_F(ModelFixture, UniqueModelObjectCachedGetters) { EXPECT_TRUE(m.getOptionalUniqueModelObject()); EXPECT_EQ(++i, m.getModelObjects().size()); } + +TEST_F(ModelFixture, Model_load) { + + openstudio::path modelPath = resourcesPath() / "model" / toPath("empty361.osm"); + ASSERT_TRUE(openstudio::filesystem::exists(modelPath)); + + const openstudio::path workflowJSONPath = getCompanionFolder(modelPath) / toPath("workflow.osw"); + ASSERT_TRUE(openstudio::filesystem::exists(workflowJSONPath)); + + // Check that the versionObject is indeed translated to the current version + boost::optional model_ = Model::load(modelPath); + ASSERT_TRUE(model_); + auto versionObject_ = model_->versionObject(); + ASSERT_TRUE(versionObject_); + EXPECT_EQ(openStudioVersion(), versionObject_->getString(1).get()); + + // Check that the workflowJSON in the companion folder is correctly loaded + auto workflowJSON = model_->workflowJSON(); + auto p_ = workflowJSON.oswPath(); + ASSERT_TRUE(p_); + EXPECT_EQ(workflowJSONPath, *p_); + + ASSERT_TRUE(workflowJSON.seedFile()); + EXPECT_EQ(workflowJSON.seedFile().get(), openstudio::toPath("../empty361.osm")); +} From e26f1727c6eec6f133c48cd882699277a0d514bd Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Tue, 4 Jul 2023 15:26:27 +0200 Subject: [PATCH 2/3] Fix #4692 - Modify Model::load to use the VersionTranslator --- src/model/Model.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/model/Model.cpp b/src/model/Model.cpp index 06dbe153e22..18caded3bf1 100644 --- a/src/model/Model.cpp +++ b/src/model/Model.cpp @@ -21,8 +21,11 @@ #include #include +#include "../osversion/VersionTranslator.hpp" + #include "../utilities/core/Assert.hpp" #include "../utilities/core/ContainersMove.hpp" +#include "../utilities/core/Filesystem.hpp" #include "../utilities/core/PathHelpers.hpp" #include "../utilities/idd/IddEnums.hpp" @@ -1840,27 +1843,26 @@ namespace model { } boost::optional Model::load(const path& osmPath) { - OptionalModel result; - OptionalIdfFile oIdfFile = IdfFile::load(osmPath, IddFileType::OpenStudio); - if (oIdfFile) { - try { - result = Model(*oIdfFile); - } catch (...) { - } - } - if (result) { - // Load the workflow.osw in the model's companion folder - path workflowJSONPath = getCompanionFolder(osmPath) / toPath("workflow.osw"); - if (exists(workflowJSONPath)) { - boost::optional workflowJSON = WorkflowJSON::load(workflowJSONPath); - if (workflowJSON) { - result->setWorkflowJSON(*workflowJSON); - } + if (!openstudio::filesystem::is_regular_file(osmPath)) { + LOG(Warn, "Path is not a valid file: " << osmPath); + return boost::none; + } + openstudio::osversion::VersionTranslator vt; + boost::optional model_ = vt.loadModel(osmPath); + if (!model_) { + LOG(Warn, "Failed to load model at " << osmPath); + return boost::none; + } + // Load the workflow.osw in the model's companion folder + const openstudio::path workflowJSONPath = getCompanionFolder(osmPath) / toPath("workflow.osw"); + if (exists(workflowJSONPath)) { + if (boost::optional workflowJSON_ = WorkflowJSON::load(workflowJSONPath)) { + model_->setWorkflowJSON(*workflowJSON_); } } - return result; + return model_; } boost::optional Model::load(const path& osmPath, const path& workflowJSONPath) { From 0e36453119a29230ec58da7ffa4238cf8cef3598 Mon Sep 17 00:00:00 2001 From: Julien Marrec Date: Tue, 4 Jul 2023 15:29:29 +0200 Subject: [PATCH 3/3] Add to TDB release notes --- developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md | 1 + 1 file changed, 1 insertion(+) diff --git a/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md b/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md index d705a28aab8..67990451e91 100644 --- a/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md +++ b/developer/doc/ReleaseNotes/OpenStudio_Release_Notes_3_7_0_TDB.md @@ -74,6 +74,7 @@ You can also refer to the [OpenStudio SDK Python Binding Version Compatibility M ## New Features, Major Fixes and API-breaking changes * [#4827](https://github.com/NREL/OpenStudio/pull/4827) - #4748 #4817 - Validate BCLXML with schema when loading + make sorting of files in measure.xml consistent when saving +* [#4923](https://github.com/NREL/OpenStudio/pull/4923) - Fix #4692 - Modify `Model::load` to use the VersionTranslator instead of loading it assuming the version of the loaded OSM is the same as the current SDK version being used. ## Minor changes and bug fixes