| 419 | } |
| 420 | |
| 421 | std::vector<std::string> SpaceType_Impl::suggestedStandardsSpaceTypes() const { |
| 422 | std::vector<std::string> result; |
| 423 | |
| 424 | boost::optional<std::string> standardsTemplate = this->standardsTemplate(); |
| 425 | boost::optional<std::string> standardsBuildingType = this->standardsBuildingType(); |
| 426 | boost::optional<std::string> standardsSpaceType = this->standardsSpaceType(); |
| 427 | |
| 428 | // include values from json if template and building_type are set |
| 429 | if (standardsTemplate && standardsBuildingType) { |
| 430 | // Find the possible space_type names that have the right template and building_type name |
| 431 | // standardsJSON is an array of hashes (no nested levels) |
| 432 | for (const auto& v : getStandardsJSON()) { |
| 433 | auto thisTemplate = v["template"].asString(); |
| 434 | auto thisBuildingType = v["building_type"].asString(); |
| 435 | if ((thisTemplate == standardsTemplate.get()) && (thisBuildingType == standardsBuildingType.get())) { |
| 436 | const Json::Value _spaceType = v["space_type"]; |
| 437 | if (_spaceType.isString()) { |
| 438 | result.emplace_back(_spaceType.asString()); |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | // always add these hard coded types |
| 445 | result.emplace_back("Attic"); |
| 446 | result.emplace_back("Plenum"); |
| 447 | |
| 448 | // include values from model |
| 449 | for (const SpaceType& other : this->model().getConcreteModelObjects<SpaceType>()) { |
| 450 | if (other.handle() == this->handle()) { |
| 451 | continue; |
| 452 | } |
| 453 | |
| 454 | boost::optional<std::string> otherBuildingType = other.standardsBuildingType(); |
| 455 | if (standardsBuildingType && otherBuildingType) { |
| 456 | // need to be the same |
| 457 | if (standardsBuildingType.get() != otherBuildingType.get()) { |
| 458 | continue; |
| 459 | } |
| 460 | } else if (!standardsBuildingType && !otherBuildingType) { |
| 461 | // both empty |
| 462 | } else { |
| 463 | // different |
| 464 | continue; |
| 465 | } |
| 466 | |
| 467 | boost::optional<std::string> otherSpaceType = other.standardsSpaceType(); |
| 468 | if (otherSpaceType) { |
| 469 | result.emplace_back(*otherSpaceType); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | // remove buildingStandardsBuildingType and standardsBuildingType |
| 474 | IstringFind finder; |
| 475 | if (standardsSpaceType) { |
| 476 | finder.addTarget(*standardsSpaceType); |
| 477 | } |
| 478 | auto it = std::remove_if(result.begin(), result.end(), finder); |