| 489 | } |
| 490 | |
| 491 | boost::optional<pugi::xml_node> ForwardTranslator::translateBuilding(const openstudio::model::Model& model, pugi::xml_node& parent) { |
| 492 | // `model` is `const`, so we shouldn't call getUniqueModelObject<model::Building> which will **create** a new object in there. |
| 493 | // model::Building building = model.getUniqueModelObject<model::Building>(); |
| 494 | boost::optional<model::Building> _building = model.getOptionalUniqueModelObject<model::Building>(); |
| 495 | |
| 496 | auto result = parent.append_child("Building"); |
| 497 | std::string bName = "Building"; |
| 498 | std::string bType = "Unknown"; |
| 499 | if (_building) { |
| 500 | m_translatedObjects[_building->handle()] = result; |
| 501 | bName = _building->nameString(); |
| 502 | |
| 503 | if (boost::optional<std::string> _standardsBuildingType = _building->standardsBuildingType()) { |
| 504 | // TODO: map to gbXML types |
| 505 | // bType = escapeName(_standardsBuildingType.get()).c_str(); |
| 506 | } |
| 507 | |
| 508 | // space type |
| 509 | if (boost::optional<model::SpaceType> _spaceType = _building->spaceType()) { |
| 510 | //std::string spaceTypeName = _spaceType->nameString(); |
| 511 | // TODO: map to gbXML types |
| 512 | // bType = escapeName(spaceTypeName).c_str(); |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | // id |
| 517 | result.append_attribute("id") = escapeName(bName).c_str(); |
| 518 | |
| 519 | // building type |
| 520 | result.append_attribute("buildingType") = bType.c_str(); |
| 521 | |
| 522 | if (_building) { |
| 523 | } |
| 524 | |
| 525 | // name |
| 526 | auto nameElement = result.append_child("Name"); |
| 527 | nameElement.text() = bName.c_str(); |
| 528 | |
| 529 | // area |
| 530 | auto areaElement = result.append_child("Area"); |
| 531 | |
| 532 | // DLM: we want to use gbXML's definition of floor area which includes area from all spaces with people in them |
| 533 | //double floorArea = building.floorArea(); |
| 534 | |
| 535 | std::vector<model::Space> spaces = model.getConcreteModelObjects<model::Space>(); |
| 536 | |
| 537 | double floorArea = 0; |
| 538 | for (const model::Space& space : spaces) { |
| 539 | double numberOfPeople = space.numberOfPeople(); |
| 540 | if (numberOfPeople > 0.0) { |
| 541 | floorArea += space.multiplier() * space.floorArea(); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | areaElement.text() = openstudio::string_conversions::number(floorArea, FloatFormat::fixed).c_str(); |
| 546 | |
| 547 | // translate spaces |
| 548 | if (m_progressBar) { |
nothing calls this directly
no test coverage detected