| 49 | namespace sdd { |
| 50 | |
| 51 | boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateConstructAssembly(const pugi::xml_node& element, |
| 52 | openstudio::model::Model& model) { |
| 53 | boost::optional<openstudio::model::ModelObject> result; |
| 54 | |
| 55 | pugi::xml_node nameElement = element.child("Name"); |
| 56 | std::string name; |
| 57 | if (!nameElement) { |
| 58 | LOG(Error, "ConsAssm element 'Name' is empty.") |
| 59 | } else { |
| 60 | name = escapeName(nameElement.text().as_string()); |
| 61 | } |
| 62 | |
| 63 | pugi::xml_node specificationElement = element.child("SpecMthd"); |
| 64 | if (!specificationElement) { |
| 65 | LOG(Error, "ConsAssm element 'SpecMthd' is empty for construction named '" << name << "'. Construction will not be created"); |
| 66 | return boost::none; |
| 67 | } |
| 68 | |
| 69 | if (openstudio::istringEqual(specificationElement.text().as_string(), "Layers")) { |
| 70 | |
| 71 | openstudio::model::Construction construction(model); |
| 72 | construction.setName(name); |
| 73 | |
| 74 | std::vector<model::Material> materials; |
| 75 | for (const pugi::xml_node& materialElement : element.children("MatRef")) { |
| 76 | std::string materialName = escapeName(materialElement.text().as_string()); |
| 77 | boost::optional<model::Material> material = model.getModelObjectByName<model::Material>(materialName); |
| 78 | if (!material) { |
| 79 | LOG(Error, "Construction: " << construction.name().get() << " references material: " << materialName << " that is not defined."); |
| 80 | |
| 81 | // DLM: what to do? Remove the construction? |
| 82 | } else { |
| 83 | materials.push_back(*material); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | bool test = construction.setLayers(materials); |
| 88 | if (!test) { |
| 89 | LOG(Error, "Failed to set material layers for Construction: " << construction.name().get() << "."); |
| 90 | |
| 91 | // DLM: what to do? Remove the construction? |
| 92 | } |
| 93 | |
| 94 | bool wasFastNaming = model.fastNaming(); |
| 95 | model.setFastNaming(false); |
| 96 | |
| 97 | auto n = (unsigned)materials.size(); |
| 98 | construction.ensureUniqueLayers(); |
| 99 | materials = construction.layers(); // DLM: get materials again in case new ones were cloned |
| 100 | |
| 101 | OS_ASSERT(n == materials.size()); |
| 102 | |
| 103 | model.setFastNaming(wasFastNaming); |
| 104 | |
| 105 | if (n > 0) { |
| 106 | |
| 107 | // DLM: are these fields only on layered constructions? |
| 108 | pugi::xml_node extRoughnessElement = element.child("ExtRoughness"); // enumerated value |
nothing calls this directly
no test coverage detected