| 281 | } |
| 282 | |
| 283 | boost::optional<model::Model> VersionTranslator::updateVersion(std::istream& is, bool isComponent, ProgressBar* progressBar) { |
| 284 | m_originalVersion = VersionString("0.0.0"); |
| 285 | m_map.clear(); |
| 286 | m_logSink.setThreadId(std::this_thread::get_id()); |
| 287 | m_logSink.resetStringStream(); |
| 288 | m_deprecated.clear(); |
| 289 | m_untranslated.clear(); |
| 290 | m_new.clear(); |
| 291 | m_refactored.clear(); |
| 292 | m_nObjectsStart = 0; |
| 293 | m_nObjectsFinalIdf = 0; |
| 294 | m_nObjectsFinalModel = 0; |
| 295 | m_isComponent = isComponent; |
| 296 | |
| 297 | initializeMap(is); |
| 298 | OS_ASSERT(m_map.size() < 2u); |
| 299 | if (m_map.empty()) { |
| 300 | return boost::none; |
| 301 | } |
| 302 | |
| 303 | if (progressBar) { |
| 304 | progressBar->setMinimum(0); |
| 305 | progressBar->setMaximum(m_startVersions.size()); |
| 306 | } |
| 307 | for (const VersionString& startVersion : m_startVersions) { |
| 308 | if (progressBar) { |
| 309 | progressBar->setWindowTitle("Upgrading from " + startVersion.str()); |
| 310 | progressBar->setValue(progressBar->value() + 1); |
| 311 | } |
| 312 | update(startVersion); // does nothing if no map entry |
| 313 | } |
| 314 | if (progressBar) { |
| 315 | progressBar->setValue(m_startVersions.size()); |
| 316 | } |
| 317 | |
| 318 | model::OptionalModel result; |
| 319 | IdfFile finalModel = m_map[VersionString(openStudioVersion())]; |
| 320 | LOG(Debug, "Final model has " << finalModel.numObjects() << " objects in IDF form."); |
| 321 | m_nObjectsFinalIdf = finalModel.numObjects(); |
| 322 | int numExpectedObjects = m_nObjectsStart + newObjects().size() - deprecatedObjects().size() - untranslatedObjects().size(); |
| 323 | if (m_nObjectsFinalIdf != numExpectedObjects) { |
| 324 | LOG(Warn, "Expected final translated model to have " << numExpectedObjects << ", but it actually has " << m_nObjectsFinalIdf << " objects."); |
| 325 | if ((m_nObjectsStart > 0) && (m_nObjectsFinalIdf == 0)) { |
| 326 | LOG(Error, "Original model contained " << m_nObjectsStart << ", but final translated model is empty."); |
| 327 | return boost::none; |
| 328 | } |
| 329 | numExpectedObjects = m_nObjectsFinalIdf; |
| 330 | } |
| 331 | |
| 332 | // validity checking |
| 333 | Workspace finalWorkspace(finalModel); |
| 334 | model::Model tempModel(finalWorkspace); // None-level strictness! |
| 335 | OS_ASSERT(tempModel.strictnessLevel() == StrictnessLevel::Minimal); |
| 336 | std::vector<std::shared_ptr<InterobjectIssueInformation>> issueInfo = fixInterobjectIssuesStage1(tempModel, m_originalVersion); |
| 337 | if (!tempModel.isValid(StrictnessLevel::Draft)) { |
| 338 | LOG(Error, "Model with Version " << openStudioVersion() << " IDD is not valid to draft " << "strictness level."); |
| 339 | LOG(Error, tempModel.validityReport(StrictnessLevel::Draft)); |
| 340 | return boost::none; |
nothing calls this directly
no test coverage detected