| 785 | } |
| 786 | |
| 787 | boost::optional<BCLMeasure> WorkflowJSON_Impl::addMeasure(const BCLMeasure& bclMeasure) { |
| 788 | boost::optional<BCLMeasure> existingMeasure = getBCLMeasureByUUID(bclMeasure.uuid()); |
| 789 | boost::optional<openstudio::path> existingMeasureDirName; |
| 790 | if (existingMeasure) { |
| 791 | // TODO: check that measure type has not changed? |
| 792 | |
| 793 | existingMeasureDirName = existingMeasure->directory(); |
| 794 | boost::filesystem::remove_all(*existingMeasureDirName); |
| 795 | } |
| 796 | |
| 797 | std::vector<openstudio::path> paths = absoluteMeasurePaths(); |
| 798 | OS_ASSERT(!paths.empty()); |
| 799 | |
| 800 | // Get the name of the directory (=last level directory name), eg: /path/to/measure_folder => measure_folder |
| 801 | openstudio::path lastLevelDirectoryName = getLastLevelDirectoryName(bclMeasure.directory()); |
| 802 | if (!toUUID(toString(lastLevelDirectoryName)).isNull()) { |
| 803 | // directory name is convertible to uuid, use the class name |
| 804 | lastLevelDirectoryName = toPath(bclMeasure.className()); |
| 805 | } |
| 806 | |
| 807 | int i = 1; |
| 808 | while (boost::filesystem::exists(paths[0] / lastLevelDirectoryName)) { |
| 809 | std::stringstream ss; |
| 810 | ss << toString(lastLevelDirectoryName) << " " << i; |
| 811 | lastLevelDirectoryName = toPath(ss.str()); |
| 812 | } |
| 813 | openstudio::path newMeasureDirName = paths[0] / lastLevelDirectoryName; |
| 814 | |
| 815 | // If we have an existing measure |
| 816 | if (existingMeasureDirName) { |
| 817 | openstudio::path lastLevelExistingDirectoryName = getLastLevelDirectoryName(*existingMeasureDirName); |
| 818 | // And the previous directory name isn't the same as the new one |
| 819 | if (lastLevelExistingDirectoryName != lastLevelDirectoryName) { |
| 820 | // update steps |
| 821 | for (auto& step : m_steps) { |
| 822 | if (auto measureStep = step.optionalCast<MeasureStep>()) { |
| 823 | if (measureStep->measureDirName() == toString(lastLevelExistingDirectoryName)) { |
| 824 | measureStep->setMeasureDirName(toString(lastLevelDirectoryName)); |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | onUpdate(); |
| 832 | |
| 833 | return bclMeasure.clone(newMeasureDirName); |
| 834 | } |
| 835 | |
| 836 | boost::optional<RunOptions> WorkflowJSON_Impl::runOptions() const { |
| 837 | return m_runOptions; |
nothing calls this directly
no test coverage detected