MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / loadModel

Method loadModel

src/gbxml/ReverseTranslator.cpp:76–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74 ReverseTranslator::~ReverseTranslator() = default;
75
76 boost::optional<openstudio::model::Model> ReverseTranslator::loadModel(const openstudio::path& path, ProgressBar* progressBar) {
77 m_progressBar = progressBar;
78
79 m_logSink.setThreadId(std::this_thread::get_id());
80
81 m_logSink.resetStringStream();
82
83 m_idToObjectMap.clear();
84
85 boost::optional<openstudio::model::Model> result;
86
87 if (openstudio::filesystem::exists(path)) {
88
89 openstudio::filesystem::ifstream file(path, std::ios_base::binary);
90 if (file.is_open()) {
91 pugi::xml_document doc;
92 auto load_result = doc.load(file);
93 if (load_result) {
94 auto root = doc.document_element();
95 if (std::string_view{root.name()} != "gbXML") {
96 LOG(Error, "Expected the root element to be <gbXML>");
97 return boost::none;
98 }
99 // Scan version of gbxml schema
100 std::string version = root.attribute("version").value();
101 VersionString schemaVersion(7, 3);
102 if (version.empty()) {
103 LOG(Warn, "gbXML has no `version` attribute for the schema version, assuming 7.03.");
104 } else {
105 try {
106 schemaVersion = VersionString(version);
107 } catch (...) {
108 LOG(Warn, "gbXML has `version` '" << version << "' which was not understood, assuming 7.03.");
109 }
110 }
111 if (schemaVersion == VersionString(7, 3)) {
112 // validate the gbxml prior to reverse translation
113 auto gbxmlValidator = XMLValidator::gbxmlValidator(schemaVersion);
114 gbxmlValidator.validate(path);
115 } else {
116 LOG(Error,
117 "Version of schema specified: " << version
118 << ", expected 7.03. gbXML Schema Validation skipped. Note that ReverseTranslator rules are built "
119 "for 7.03 and older versions are not officially supported, check resulting model with care.");
120 };
121
122 result = this->convert(root);
123 }
124 file.close();
125 }
126 // JWD: Would be nice to add some error handling here
127 }
128
129 return result;
130 }
131
132 std::vector<LogMessage> ReverseTranslator::warnings() const {
133 std::vector<LogMessage> result;

Callers 5

TEST_FFunction · 0.45
mainFunction · 0.45
TEST_FFunction · 0.45
TEST_PFunction · 0.45
TEST_FFunction · 0.45

Calls 12

convertMethod · 0.95
setThreadIdMethod · 0.80
resetStringStreamMethod · 0.80
validateMethod · 0.80
VersionStringClass · 0.50
clearMethod · 0.45
loadMethod · 0.45
nameMethod · 0.45
valueMethod · 0.45
attributeMethod · 0.45
emptyMethod · 0.45
closeMethod · 0.45

Tested by 4

TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_PFunction · 0.36
TEST_FFunction · 0.36