| 341 | } |
| 342 | |
| 343 | bool saveModel(openstudio::model::Model model, const openstudio::path& osmPath, const openstudio::path& modelTempDir) { |
| 344 | // set the workflow's path |
| 345 | openstudio::path oswPath = modelTempDir / openstudio::toPath("resources/workflow.osw"); |
| 346 | boost::optional<openstudio::path> currentOswPath = model.workflowJSON().oswPath(); |
| 347 | if (!currentOswPath || (oswPath != currentOswPath.get())) { |
| 348 | model.workflowJSON().setOswPath(oswPath); |
| 349 | } |
| 350 | |
| 351 | // set the seed name |
| 352 | openstudio::path seedFile = toPath("..") / osmPath.filename(); |
| 353 | boost::optional<openstudio::path> currentSeedFile = model.workflowJSON().seedFile(); |
| 354 | if (!currentSeedFile || (seedFile != currentSeedFile.get())) { |
| 355 | model.workflowJSON().setSeedFile(seedFile); |
| 356 | } |
| 357 | |
| 358 | // save the osw, do before temp dirs get copied |
| 359 | model.workflowJSON().save(); |
| 360 | |
| 361 | // save osm to temp directory, saveModelTempDir will copy to real location |
| 362 | openstudio::path tempModelPath = modelTempDir / osmPath.filename(); |
| 363 | bool modelSaved = model.save(tempModelPath, true); |
| 364 | |
| 365 | if (modelSaved) { |
| 366 | LOG_FREE(Debug, "saveModel", "Saved model to '" << toString(tempModelPath) << "'"); |
| 367 | } else { |
| 368 | LOG_FREE(Error, "saveModel", "Failed to save model to '" << toString(tempModelPath) << "'"); |
| 369 | } |
| 370 | |
| 371 | bool tempDirSaved = saveModelTempDir(modelTempDir, osmPath); |
| 372 | |
| 373 | return (modelSaved && tempDirSaved); |
| 374 | } |
| 375 | |
| 376 | void removeModelTempDir(const openstudio::path& modelTempDir) { |
| 377 | removeDir(modelTempDir); |
nothing calls this directly
no test coverage detected