Skip to content

Commit

Permalink
Fix #4692 - Modify Model::load to use the VersionTranslator
Browse files Browse the repository at this point in the history
  • Loading branch information
jmarrec committed Jul 4, 2023
1 parent cf7aa0e commit e26f172
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/model/Model.cpp
Expand Up @@ -21,8 +21,11 @@
#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/OS_Version_FieldEnums.hxx>

#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"
Expand Down Expand Up @@ -1840,27 +1843,26 @@ namespace model {
}

boost::optional<Model> 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 = 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<openstudio::model::Model> 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_ = WorkflowJSON::load(workflowJSONPath)) {
model_->setWorkflowJSON(*workflowJSON_);
}
}

return result;
return model_;
}

boost::optional<Model> Model::load(const path& osmPath, const path& workflowJSONPath) {
Expand Down

0 comments on commit e26f172

Please sign in to comment.