| 195 | } |
| 196 | |
| 197 | boost::optional<OSMInfo> MeasureManager::getModel(const openstudio::path& osmPath, bool force_reload) { |
| 198 | |
| 199 | if (!openstudio::filesystem::is_regular_file(osmPath)) { |
| 200 | fmt::print("Model '{}' does not exist\n", osmPath.generic_string()); |
| 201 | m_osms.erase(osmPath); |
| 202 | clearMeasureInfoForOsmorIdfPath(osmPath); |
| 203 | return boost::none; |
| 204 | } |
| 205 | |
| 206 | OSMInfo current; |
| 207 | current.checksum = openstudio::checksum(osmPath); |
| 208 | |
| 209 | if (!force_reload) { |
| 210 | auto it = m_osms.find(osmPath); |
| 211 | if (it != m_osms.end()) { |
| 212 | auto& cached = it->second; |
| 213 | if (current.checksum == cached.checksum) { |
| 214 | fmt::print("Using cached model {}\n", osmPath.generic_string()); |
| 215 | return cached; |
| 216 | } else { |
| 217 | fmt::print("Checksum of cached model does not match current checksum for '{}'\n", osmPath.generic_string()); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | clearMeasureInfoForOsmorIdfPath(osmPath); |
| 223 | |
| 224 | fmt::print("Attempting to load model '{}'\n", osmPath.generic_string()); |
| 225 | openstudio::osversion::VersionTranslator vt; |
| 226 | if (auto model_ = vt.loadModel(osmPath)) { |
| 227 | fmt::print("Successfully loaded model '{}'\n", osmPath.generic_string()); |
| 228 | current.model = std::move(*model_); |
| 229 | openstudio::energyplus::ForwardTranslator ft; |
| 230 | current.workspace = ft.translateModel(current.model); |
| 231 | auto [it, ok] = m_osms.insert_or_assign(osmPath, std::move(current)); |
| 232 | return it->second; |
| 233 | } |
| 234 | |
| 235 | fmt::print("Failed to load model '{}'\n", osmPath.generic_string()); |
| 236 | m_osms.erase(osmPath); |
| 237 | |
| 238 | return boost::none; |
| 239 | } |
| 240 | |
| 241 | boost::optional<IDFInfo> MeasureManager::getIdf(const openstudio::path& idfPath, bool force_reload) { |
| 242 | |