src/gbxml/ForwardTranslator.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "ForwardTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../model/Model.hpp" | ||
| 9 | #include "../model/ModelObject.hpp" | ||
| 10 | #include "../model/ModelObject_Impl.hpp" | ||
| 11 | #include "../model/Material.hpp" | ||
| 12 | #include "../model/Material_Impl.hpp" | ||
| 13 | #include "../model/ConstructionBase.hpp" | ||
| 14 | #include "../model/ConstructionBase_Impl.hpp" | ||
| 15 | #include "../model/Construction.hpp" | ||
| 16 | #include "../model/Construction_Impl.hpp" | ||
| 17 | #include "../model/Facility.hpp" | ||
| 18 | #include "../model/Facility_Impl.hpp" | ||
| 19 | #include "../model/Building.hpp" | ||
| 20 | #include "../model/Building_Impl.hpp" | ||
| 21 | #include "../model/Space.hpp" | ||
| 22 | #include "../model/Space_Impl.hpp" | ||
| 23 | #include "../model/ShadingSurfaceGroup.hpp" | ||
| 24 | #include "../model/ShadingSurfaceGroup_Impl.hpp" | ||
| 25 | #include "../model/BuildingStory.hpp" | ||
| 26 | #include "../model/BuildingStory_Impl.hpp" | ||
| 27 | #include "../model/SpaceType.hpp" | ||
| 28 | #include "../model/SpaceType_Impl.hpp" | ||
| 29 | #include "../model/Surface.hpp" | ||
| 30 | #include "../model/Surface_Impl.hpp" | ||
| 31 | #include "../model/SubSurface.hpp" | ||
| 32 | #include "../model/SubSurface_Impl.hpp" | ||
| 33 | #include "../model/ShadingSurface.hpp" | ||
| 34 | #include "../model/ShadingSurface_Impl.hpp" | ||
| 35 | #include "../model/StandardOpaqueMaterial.hpp" | ||
| 36 | #include "../model/StandardOpaqueMaterial_Impl.hpp" | ||
| 37 | #include "../model/ThermalZone.hpp" | ||
| 38 | #include "../model/ThermalZone_Impl.hpp" | ||
| 39 | #include "../model/ThermostatSetpointDualSetpoint.hpp" | ||
| 40 | #include "../model/ThermostatSetpointDualSetpoint_Impl.hpp" | ||
| 41 | #include "../model/ScheduleRuleset.hpp" | ||
| 42 | #include "../model/ScheduleRuleset_Impl.hpp" | ||
| 43 | #include "../model/ScheduleConstant.hpp" | ||
| 44 | #include "../model/ScheduleConstant_Impl.hpp" | ||
| 45 | #include "../model/ScheduleDay.hpp" | ||
| 46 | #include "../model/ScheduleDay_Impl.hpp" | ||
| 47 | #include "../model/AdditionalProperties.hpp" | ||
| 48 | |||
| 49 | #include "../utilities/geometry/Transformation.hpp" | ||
| 50 | #include "../utilities/geometry/EulerAngles.hpp" | ||
| 51 | #include "../utilities/geometry/BoundingBox.hpp" | ||
| 52 | #include "../utilities/geometry/Geometry.hpp" | ||
| 53 | #include "../utilities/plot/ProgressBar.hpp" | ||
| 54 | #include "../utilities/time/DateTime.hpp" | ||
| 55 | #include "../utilities/time/Date.hpp" | ||
| 56 | #include "../utilities/sql/SqlFile.hpp" | ||
| 57 | #include "../utilities/core/Assert.hpp" | ||
| 58 | #include "../utilities/core/FilesystemHelpers.hpp" | ||
| 59 | #include "../utilities/core/StringHelpers.hpp" | ||
| 60 | #include "../utilities/xml/XMLValidator.hpp" | ||
| 61 | |||
| 62 | #include <OpenStudio.hxx> | ||
| 63 | #include <resources.hxx> | ||
| 64 | |||
| 65 | #include <boost/math/constants/constants.hpp> | ||
| 66 | |||
| 67 | #include <pugixml.hpp> | ||
| 68 | |||
| 69 | #include <regex> | ||
| 70 | #include <string_view> | ||
| 71 | |||
| 72 | namespace openstudio { | ||
| 73 | namespace gbxml { | ||
| 74 | |||
| 75 | static constexpr std::string_view shadingSurfaceWithoutConstructionName = "Shading_Surface_Without_Construction"; | ||
| 76 | |||
| 77 |
1/1✓ Branch 3 taken 18 times.
|
18 | ForwardTranslator::ForwardTranslator() { |
| 78 |
1/1✓ Branch 1 taken 18 times.
|
18 | m_logSink.setLogLevel(Warn); |
| 79 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
|
18 | m_logSink.setChannelRegex(boost::regex("openstudio\\.gbxml\\.ForwardTranslator")); |
| 80 |
1/1✓ Branch 2 taken 18 times.
|
18 | m_logSink.setThreadId(std::this_thread::get_id()); |
| 81 | 18 | } | |
| 82 | |||
| 83 | 18 | ForwardTranslator::~ForwardTranslator() = default; | |
| 84 | |||
| 85 | 19 | bool ForwardTranslator::modelToGbXML(const openstudio::model::Model& model, const openstudio::path& path, ProgressBar* progressBar) { | |
| 86 | 19 | m_progressBar = progressBar; | |
| 87 | |||
| 88 |
1/1✓ Branch 2 taken 19 times.
|
19 | m_logSink.setThreadId(std::this_thread::get_id()); |
| 89 | |||
| 90 |
1/1✓ Branch 1 taken 19 times.
|
19 | m_logSink.resetStringStream(); |
| 91 | |||
| 92 |
1/1✓ Branch 1 taken 19 times.
|
19 | pugi::xml_document doc; |
| 93 | //doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\""); | ||
| 94 |
1/1✓ Branch 1 taken 19 times.
|
19 | bool result = this->translateModel(model, doc); |
| 95 | |||
| 96 |
1/1✓ Branch 1 taken 19 times.
|
19 | openstudio::filesystem::ofstream file(path, std::ios_base::binary); |
| 97 |
1/2✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
|
19 | if (file.is_open()) { |
| 98 |
1/1✓ Branch 1 taken 19 times.
|
19 | doc.save(file, " "); |
| 99 |
1/1✓ Branch 1 taken 19 times.
|
19 | file.close(); |
| 100 | |||
| 101 | // validate the gbxml after forward translation | ||
| 102 |
2/2✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
|
19 | auto gbxmlValidator = XMLValidator::gbxmlValidator(); |
| 103 |
1/1✓ Branch 1 taken 19 times.
|
19 | gbxmlValidator.validate(path); |
| 104 | |||
| 105 | 19 | return result; | |
| 106 | 19 | } | |
| 107 | |||
| 108 | ✗ | return false; | |
| 109 | 19 | } | |
| 110 | |||
| 111 | 2 | std::string ForwardTranslator::modelToGbXMLString(const openstudio::model::Model& model, ProgressBar* progressBar) { | |
| 112 | 2 | std::string gbXML_str; | |
| 113 | |||
| 114 | 2 | m_progressBar = progressBar; | |
| 115 | |||
| 116 |
1/1✓ Branch 2 taken 2 times.
|
2 | m_logSink.setThreadId(std::this_thread::get_id()); |
| 117 | |||
| 118 |
1/1✓ Branch 1 taken 2 times.
|
2 | m_logSink.resetStringStream(); |
| 119 | |||
| 120 |
1/1✓ Branch 1 taken 2 times.
|
2 | pugi::xml_document doc; |
| 121 | //doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"utf-8\""); | ||
| 122 |
1/1✓ Branch 1 taken 2 times.
|
2 | bool result = this->translateModel(model, doc); |
| 123 | |||
| 124 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (result) { |
| 125 | // doc.save allows any ostream, so use a stringstream | ||
| 126 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::stringstream ss; |
| 127 |
1/1✓ Branch 1 taken 2 times.
|
2 | doc.save(ss, " "); |
| 128 |
1/1✓ Branch 1 taken 2 times.
|
2 | gbXML_str = ss.str(); |
| 129 | 2 | } | |
| 130 | |||
| 131 | 4 | return gbXML_str; | |
| 132 | 2 | } | |
| 133 | |||
| 134 | ✗ | std::vector<LogMessage> ForwardTranslator::warnings() const { | |
| 135 | ✗ | std::vector<LogMessage> result; | |
| 136 | ✗ | std::vector<LogMessage> allMessages = m_logSink.logMessages(); | |
| 137 | ✗ | std::copy_if(allMessages.cbegin(), allMessages.cend(), std::back_inserter(result), | |
| 138 | ✗ | [](const auto& logMessage) { return logMessage.logLevel() == Warn; }); | |
| 139 | ✗ | return result; | |
| 140 | ✗ | } | |
| 141 | |||
| 142 | ✗ | std::vector<LogMessage> ForwardTranslator::errors() const { | |
| 143 | ✗ | std::vector<LogMessage> result; | |
| 144 | ✗ | std::vector<LogMessage> allMessages = m_logSink.logMessages(); | |
| 145 | ✗ | std::copy_if(allMessages.cbegin(), allMessages.cend(), std::back_inserter(result), | |
| 146 | ✗ | [](const auto& logMessage) { return logMessage.logLevel() > Warn; }); | |
| 147 | ✗ | return result; | |
| 148 | ✗ | } | |
| 149 | |||
| 150 | 6110 | std::string ForwardTranslator::escapeName(const std::string& name) { | |
| 151 | 6110 | std::string result; | |
| 152 |
3/4✓ Branch 1 taken 6110 times.
✓ Branch 4 taken 6110 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6110 times.
|
6110 | if (std::regex_match(name, std::regex("^\\d.*"))) { |
| 153 | ✗ | result = "id_" + name; | |
| 154 | } else { | ||
| 155 |
1/1✓ Branch 1 taken 6110 times.
|
6110 | result = name; |
| 156 | } | ||
| 157 | 6110 | std::replace(result.begin(), result.end(), ' ', '_'); | |
| 158 | 6110 | std::replace(result.begin(), result.end(), '(', '_'); | |
| 159 | 6110 | std::replace(result.begin(), result.end(), ')', '_'); | |
| 160 | 6110 | std::replace(result.begin(), result.end(), '[', '_'); | |
| 161 | 6110 | std::replace(result.begin(), result.end(), ']', '_'); | |
| 162 | 6110 | std::replace(result.begin(), result.end(), '{', '_'); | |
| 163 | 6110 | std::replace(result.begin(), result.end(), '}', '_'); | |
| 164 | 6110 | std::replace(result.begin(), result.end(), '/', '_'); | |
| 165 | 6110 | std::replace(result.begin(), result.end(), '\\', '_'); | |
| 166 | //std::replace(result.begin(), result.end(),'-', '_'); // ok | ||
| 167 | //std::replace(result.begin(), result.end(),'.', '_'); // ok | ||
| 168 | 6110 | std::replace(result.begin(), result.end(), ':', '_'); | |
| 169 | 6110 | std::replace(result.begin(), result.end(), ';', '_'); | |
| 170 | 6110 | return result; | |
| 171 | ✗ | } | |
| 172 | |||
| 173 | 21 | bool ForwardTranslator::translateModel(const openstudio::model::Model& model, pugi::xml_document& document) { | |
| 174 | |||
| 175 | // Clear the map & set | ||
| 176 | 21 | m_translatedObjects.clear(); | |
| 177 | 21 | m_materials.clear(); | |
| 178 | 21 | m_placeholderShadingSurfaceConstructionAlreadyCreated = false; | |
| 179 | |||
| 180 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto gbXMLElement = document.append_child("gbXML"); |
| 181 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("xmlns") = "http://www.gbxml.org/schema"; |
| 182 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("xmlns:xhtml") = "http://www.w3.org/1999/xhtml"; |
| 183 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("xmlns:xsi") = "http://www.w3.org/2001/XMLSchema-instance"; |
| 184 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("xmlns:xsd") = "http://www.w3.org/2001/XMLSchema"; |
| 185 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("xsi:schemaLocation") = "http://www.gbxml.org/schema http://gbxml.org/schema/7-03/GreenBuildingXML_Ver7.03.xsd"; |
| 186 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("temperatureUnit") = "C"; |
| 187 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("lengthUnit") = "Meters"; |
| 188 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("areaUnit") = "SquareMeters"; |
| 189 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("volumeUnit") = "CubicMeters"; |
| 190 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("useSIUnitsForResults") = "true"; |
| 191 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("version") = "7.03"; |
| 192 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | gbXMLElement.append_attribute("SurfaceReferenceLocation") = "Centerline"; |
| 193 | |||
| 194 | // translateFacility is responsible to translate Surfaces, and calls translateBuilding, which is responsible to translate spaces | ||
| 195 | // so we do need to call it anyways. | ||
| 196 |
1/1✓ Branch 1 taken 21 times.
|
21 | translateFacility(model, gbXMLElement); |
| 197 | |||
| 198 | // do constructions | ||
| 199 |
1/1✓ Branch 1 taken 21 times.
|
21 | std::vector<model::ConstructionBase> constructionBases = model.getModelObjects<model::ConstructionBase>(); |
| 200 | |||
| 201 | // sort by is opaque so we get constructions before window types | ||
| 202 |
1/1✓ Branch 3 taken 21 times.
|
21 | std::sort(constructionBases.begin(), constructionBases.end(), |
| 203 |
4/4✓ Branch 1 taken 415 times.
✓ Branch 2 taken 78 times.
✓ Branch 4 taken 217 times.
✓ Branch 5 taken 198 times.
|
493 | [](const model::ConstructionBase& a, const model::ConstructionBase& b) { return a.isOpaque() && !b.isOpaque(); }); |
| 204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 205 | ✗ | m_progressBar->setWindowTitle(toString("Translating Constructions")); | |
| 206 | ✗ | m_progressBar->setMinimum(0); | |
| 207 | ✗ | m_progressBar->setMaximum((int)constructionBases.size()); | |
| 208 | ✗ | m_progressBar->setValue(0); | |
| 209 | } | ||
| 210 | |||
| 211 |
2/2✓ Branch 5 taken 159 times.
✓ Branch 6 taken 21 times.
|
180 | for (const model::ConstructionBase& constructionBase : constructionBases) { |
| 212 |
1/1✓ Branch 1 taken 159 times.
|
159 | translateConstructionBase(constructionBase, gbXMLElement); |
| 213 | |||
| 214 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 159 times.
|
159 | if (m_progressBar) { |
| 215 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | // do materials | ||
| 220 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 221 | ✗ | m_progressBar->setWindowTitle(toString("Translating Materials")); | |
| 222 | ✗ | m_progressBar->setMinimum(0); | |
| 223 | ✗ | m_progressBar->setMaximum((int)2 * m_materials.size()); | |
| 224 | ✗ | m_progressBar->setValue(0); | |
| 225 | } | ||
| 226 | |||
| 227 |
1/1✓ Branch 3 taken 21 times.
|
21 | std::vector<model::Material> materials(m_materials.begin(), m_materials.end()); |
| 228 |
1/1✓ Branch 3 taken 21 times.
|
21 | std::sort(materials.begin(), materials.end(), WorkspaceObjectNameLess()); |
| 229 | |||
| 230 |
2/2✓ Branch 5 taken 201 times.
✓ Branch 6 taken 21 times.
|
222 | for (const model::Material& material : materials) { |
| 231 |
1/1✓ Branch 1 taken 201 times.
|
201 | translateLayer(material, gbXMLElement); |
| 232 | |||
| 233 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 201 times.
|
201 | if (m_progressBar) { |
| 234 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 235 | } | ||
| 236 | } | ||
| 237 |
2/2✓ Branch 5 taken 201 times.
✓ Branch 6 taken 21 times.
|
222 | for (const model::Material& material : materials) { |
| 238 |
1/1✓ Branch 1 taken 201 times.
|
201 | translateMaterial(material, gbXMLElement); |
| 239 | |||
| 240 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 201 times.
|
201 | if (m_progressBar) { |
| 241 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | // do thermal zones | ||
| 246 |
1/1✓ Branch 1 taken 21 times.
|
21 | std::vector<model::ThermalZone> thermalZones = model.getConcreteModelObjects<model::ThermalZone>(); |
| 247 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 248 | ✗ | m_progressBar->setWindowTitle(toString("Translating Thermal Zones")); | |
| 249 | ✗ | m_progressBar->setMinimum(0); | |
| 250 | ✗ | m_progressBar->setMaximum((int)thermalZones.size()); | |
| 251 | ✗ | m_progressBar->setValue(0); | |
| 252 | } | ||
| 253 | |||
| 254 |
2/2✓ Branch 5 taken 59 times.
✓ Branch 6 taken 21 times.
|
80 | for (const model::ThermalZone& thermalZone : thermalZones) { |
| 255 |
1/1✓ Branch 1 taken 59 times.
|
59 | translateThermalZone(thermalZone, gbXMLElement); |
| 256 | |||
| 257 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 59 times.
|
59 | if (m_progressBar) { |
| 258 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | // Document History | ||
| 263 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto documentHistoryElement = gbXMLElement.append_child("DocumentHistory"); |
| 264 | |||
| 265 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto createdByElement = documentHistoryElement.append_child("CreatedBy"); |
| 266 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | createdByElement.append_attribute("programId") = "openstudio"; |
| 267 |
4/4✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 21 times.
✓ Branch 11 taken 21 times.
|
21 | createdByElement.append_attribute("date") = DateTime::now().toXsdDateTime().c_str(); |
| 268 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | createdByElement.append_attribute("personId") = "unknown"; |
| 269 | |||
| 270 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto programInfoElement = documentHistoryElement.append_child("ProgramInfo"); |
| 271 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | programInfoElement.append_attribute("id") = "openstudio"; |
| 272 | |||
| 273 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto productNameElement = programInfoElement.append_child("ProductName"); |
| 274 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | productNameElement.text() = "OpenStudio"; |
| 275 | |||
| 276 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto versionElement = programInfoElement.append_child("Version"); |
| 277 |
3/3✓ Branch 1 taken 21 times.
✓ Branch 5 taken 21 times.
✓ Branch 8 taken 21 times.
|
21 | versionElement.text() = openStudioVersion().c_str(); |
| 278 | |||
| 279 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto platformElement = programInfoElement.append_child("Platform"); |
| 280 | #if _WIN32 || _MSC_VER | ||
| 281 | platformElement.text() = "Windows"; | ||
| 282 | #elif __APPLE__ | ||
| 283 | platformElement.text() = "Apple"; | ||
| 284 | #else | ||
| 285 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | platformElement.text() = "Linux"; |
| 286 | #endif | ||
| 287 | |||
| 288 | // TODO: not used | ||
| 289 | // auto projectEntityElement = programInfoElement.append_child("ProjectEntity"); | ||
| 290 | |||
| 291 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto personInfoElement = documentHistoryElement.append_child("PersonInfo"); |
| 292 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | personInfoElement.append_attribute("id") = "unknown"; |
| 293 | |||
| 294 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto firstNameElement = personInfoElement.append_child("FirstName"); |
| 295 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | firstNameElement.text() = "Unknown"; |
| 296 | |||
| 297 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto lastNameElement = personInfoElement.append_child("LastName"); |
| 298 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | lastNameElement.text() = "Unknown"; |
| 299 | |||
| 300 | // translate results | ||
| 301 |
1/1✓ Branch 1 taken 21 times.
|
21 | boost::optional<SqlFile> sqlFile = model.sqlFile(); |
| 302 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (sqlFile) { |
| 303 | |||
| 304 | // thermal zone results | ||
| 305 | ✗ | if (m_progressBar) { | |
| 306 | ✗ | m_progressBar->setWindowTitle(toString("Translating Thermal Zone Results")); | |
| 307 | ✗ | m_progressBar->setMinimum(0); | |
| 308 | ✗ | m_progressBar->setMaximum((int)thermalZones.size()); | |
| 309 | ✗ | m_progressBar->setValue(0); | |
| 310 | } | ||
| 311 | |||
| 312 | ✗ | for (const model::ThermalZone& thermalZone : thermalZones) { | |
| 313 | ✗ | std::string query; | |
| 314 | ✗ | boost::optional<double> heatLoad; | |
| 315 | ✗ | boost::optional<double> coolingLoad; | |
| 316 | ✗ | boost::optional<double> flow; | |
| 317 | ✗ | std::string thermalZoneId = escapeName(thermalZone.name().get()); | |
| 318 | |||
| 319 | // DLM: these queries are taken from the OpenStudio standards, should be ported to Model | ||
| 320 | ✗ | query = "SELECT Value "; | |
| 321 | ✗ | query += "FROM tabulardatawithstrings "; | |
| 322 | ✗ | query += "WHERE ReportName='HVACSizingSummary' "; | |
| 323 | ✗ | query += "AND ReportForString='Entire Facility' "; | |
| 324 | ✗ | query += "AND TableName='Zone Sensible Heating' "; | |
| 325 | ✗ | query += "AND ColumnName='User Design Load' "; | |
| 326 | ✗ | query += "AND RowName='" + boost::to_upper_copy(thermalZone.name().get()) + "' "; | |
| 327 | ✗ | query += "AND Units='W'"; | |
| 328 | ✗ | heatLoad = sqlFile->execAndReturnFirstDouble(query); | |
| 329 | |||
| 330 | ✗ | query = "SELECT Value "; | |
| 331 | ✗ | query += "FROM tabulardatawithstrings "; | |
| 332 | ✗ | query += "WHERE ReportName='HVACSizingSummary' "; | |
| 333 | ✗ | query += "AND ReportForString='Entire Facility' "; | |
| 334 | ✗ | query += "AND TableName='Zone Sensible Cooling' "; | |
| 335 | ✗ | query += "AND ColumnName='User Design Load' "; | |
| 336 | ✗ | query += "AND RowName='" + boost::to_upper_copy(thermalZone.name().get()) + "' "; | |
| 337 | ✗ | query += "AND Units='W'"; | |
| 338 | ✗ | coolingLoad = sqlFile->execAndReturnFirstDouble(query); | |
| 339 | |||
| 340 | ✗ | query = "SELECT Value "; | |
| 341 | ✗ | query += "FROM tabulardatawithstrings "; | |
| 342 | ✗ | query += "WHERE ReportName='HVACSizingSummary' "; | |
| 343 | ✗ | query += "AND ReportForString='Entire Facility' "; | |
| 344 | ✗ | query += "AND TableName='Zone Sensible Cooling' "; | |
| 345 | ✗ | query += "AND ColumnName='User Design Air Flow' "; | |
| 346 | ✗ | query += "AND RowName='" + boost::to_upper_copy(thermalZone.name().get()) + "' "; | |
| 347 | ✗ | query += "AND Units='m3/s'"; | |
| 348 | ✗ | boost::optional<double> coolingFlow = sqlFile->execAndReturnFirstDouble(query); | |
| 349 | |||
| 350 | ✗ | query = "SELECT Value "; | |
| 351 | ✗ | query += "FROM tabulardatawithstrings "; | |
| 352 | ✗ | query += "WHERE ReportName='HVACSizingSummary' "; | |
| 353 | ✗ | query += "AND ReportForString='Entire Facility' "; | |
| 354 | ✗ | query += "AND TableName='Zone Sensible Heating' "; | |
| 355 | ✗ | query += "AND ColumnName='User Design Air Flow' "; | |
| 356 | ✗ | query += "AND RowName='" + boost::to_upper_copy(thermalZone.name().get()) + "' "; | |
| 357 | ✗ | query += "AND Units='m3/s'"; | |
| 358 | ✗ | boost::optional<double> heatingFlow = sqlFile->execAndReturnFirstDouble(query); | |
| 359 | |||
| 360 | ✗ | if (heatingFlow && coolingFlow) { | |
| 361 | ✗ | flow = std::max(*heatingFlow, *coolingFlow); | |
| 362 | ✗ | } else if (heatingFlow) { | |
| 363 | ✗ | flow = heatingFlow; | |
| 364 | ✗ | } else if (coolingFlow) { | |
| 365 | ✗ | flow = coolingFlow; | |
| 366 | } | ||
| 367 | |||
| 368 | ✗ | if (heatLoad) { | |
| 369 | ✗ | auto resultsElement = gbXMLElement.append_child("Results"); | |
| 370 | ✗ | resultsElement.append_attribute("id") = (thermalZoneId + "HeatLoad").c_str(); | |
| 371 | ✗ | resultsElement.append_attribute("resultsType") = "HeatLoad"; | |
| 372 | ✗ | resultsElement.append_attribute("unit") = "Kilowatt"; | |
| 373 | |||
| 374 | ✗ | auto objectIdElement = resultsElement.append_child("ObjectId"); | |
| 375 | ✗ | objectIdElement.text() = thermalZoneId.c_str(); | |
| 376 | |||
| 377 | ✗ | auto valueElement = resultsElement.append_child("Value"); | |
| 378 | ✗ | valueElement.text() = openstudio::string_conversions::number(*heatLoad / 1000.0, FloatFormat::fixed).c_str(); | |
| 379 | } | ||
| 380 | |||
| 381 | ✗ | if (coolingLoad) { | |
| 382 | ✗ | auto resultsElement = gbXMLElement.append_child("Results"); | |
| 383 | ✗ | resultsElement.append_attribute("id") = (thermalZoneId + "CoolingLoad").c_str(); | |
| 384 | ✗ | resultsElement.append_attribute("resultsType") = "CoolingLoad"; | |
| 385 | ✗ | resultsElement.append_attribute("unit") = "Kilowatt"; | |
| 386 | |||
| 387 | ✗ | auto objectIdElement = resultsElement.append_child("ObjectId"); | |
| 388 | ✗ | objectIdElement.text() = thermalZoneId.c_str(); | |
| 389 | |||
| 390 | ✗ | auto valueElement = resultsElement.append_child("Value"); | |
| 391 | ✗ | valueElement.text() = openstudio::string_conversions::number(*coolingLoad / 1000.0, FloatFormat::fixed).c_str(); | |
| 392 | } | ||
| 393 | |||
| 394 | ✗ | if (flow) { | |
| 395 | ✗ | auto resultsElement = gbXMLElement.append_child("Results"); | |
| 396 | ✗ | resultsElement.append_attribute("id") = (thermalZoneId + "Flow").c_str(); | |
| 397 | ✗ | resultsElement.append_attribute("resultsType") = "Flow"; | |
| 398 | ✗ | resultsElement.append_attribute("unit") = "CubicMPerHr"; | |
| 399 | |||
| 400 | ✗ | auto objectIdElement = resultsElement.append_child("ObjectId"); | |
| 401 | ✗ | objectIdElement.text() = thermalZoneId.c_str(); | |
| 402 | |||
| 403 | ✗ | auto valueElement = resultsElement.append_child("Value"); | |
| 404 | ✗ | valueElement.text() = openstudio::string_conversions::number(*flow * 3600, FloatFormat::fixed).c_str(); | |
| 405 | } | ||
| 406 | |||
| 407 | ✗ | if (m_progressBar) { | |
| 408 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 409 | } | ||
| 410 | ✗ | } | |
| 411 | } | ||
| 412 | |||
| 413 | 21 | return true; | |
| 414 | 21 | } | |
| 415 | |||
| 416 | 21 | boost::optional<pugi::xml_node> ForwardTranslator::translateFacility(const openstudio::model::Model& model, pugi::xml_node& parent) { | |
| 417 | |||
| 418 | // `model` is `const`, so we shouldn't call getUniqueModelObject<model::Facility> which will **create** a new object in there. | ||
| 419 |
1/1✓ Branch 1 taken 21 times.
|
21 | boost::optional<model::Facility> _facility = model.getOptionalUniqueModelObject<model::Facility>(); |
| 420 | |||
| 421 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto result = parent.append_child("Campus"); |
| 422 |
1/1✓ Branch 1 taken 21 times.
|
42 | std::string name = "Facility"; |
| 423 | |||
| 424 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 3 times.
|
21 | if (_facility) { |
| 425 |
3/3✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 7 taken 18 times.
|
18 | m_translatedObjects[_facility->handle()] = result; |
| 426 |
3/4✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 18 times.
|
36 | if (auto _s = _facility->name()) { |
| 427 | ✗ | name = _s.get(); | |
| 428 | 18 | } | |
| 429 | } | ||
| 430 | |||
| 431 | // id | ||
| 432 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | result.append_attribute("id") = "Facility"; |
| 433 | |||
| 434 | // name | ||
| 435 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto nameElement = result.append_child("Name"); |
| 436 |
2/2✓ Branch 2 taken 21 times.
✓ Branch 5 taken 21 times.
|
21 | nameElement.text() = name.c_str(); |
| 437 | |||
| 438 | // todo: translate location | ||
| 439 | |||
| 440 | // translate building: needs to be done even if not explicitly instantiated since that's what translates Spaces in particular. | ||
| 441 |
1/1✓ Branch 1 taken 21 times.
|
21 | translateBuilding(model, result); |
| 442 | |||
| 443 | // translate surfaces | ||
| 444 | // TODO: JM 2020-06-18 Why is translateSpace not responsible to call this one? | ||
| 445 |
1/1✓ Branch 1 taken 21 times.
|
21 | std::vector<model::Surface> surfaces = model.getConcreteModelObjects<model::Surface>(); |
| 446 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 447 | ✗ | m_progressBar->setWindowTitle(toString("Translating Surfaces")); | |
| 448 | ✗ | m_progressBar->setMinimum(0); | |
| 449 | ✗ | m_progressBar->setMaximum((int)surfaces.size()); | |
| 450 | ✗ | m_progressBar->setValue(0); | |
| 451 | } | ||
| 452 | |||
| 453 |
1/1✓ Branch 1 taken 21 times.
|
21 | std::vector<model::Space> spaces = model.getConcreteModelObjects<model::Space>(); |
| 454 |
1/1✓ Branch 3 taken 21 times.
|
21 | std::sort(spaces.begin(), spaces.end(), WorkspaceObjectNameLess()); |
| 455 |
2/2✓ Branch 5 taken 132 times.
✓ Branch 6 taken 21 times.
|
153 | for (const model::Space& space : spaces) { |
| 456 |
1/1✓ Branch 1 taken 132 times.
|
132 | std::vector<model::Surface> spaceSurfaces = space.surfaces(); |
| 457 |
1/1✓ Branch 3 taken 132 times.
|
132 | std::sort(spaceSurfaces.begin(), spaceSurfaces.end(), WorkspaceObjectNameLess()); |
| 458 | |||
| 459 |
2/2✓ Branch 5 taken 1467 times.
✓ Branch 6 taken 132 times.
|
1599 | for (const model::Surface& surface : spaceSurfaces) { |
| 460 |
2/2✓ Branch 1 taken 1467 times.
✓ Branch 4 taken 1467 times.
|
1467 | std::string name = surface.name().value(); |
| 461 |
1/1✓ Branch 1 taken 1467 times.
|
1467 | translateSurface(surface, result); |
| 462 | |||
| 463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1467 times.
|
1467 | if (m_progressBar) { |
| 464 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 465 | } | ||
| 466 | 1467 | } | |
| 467 | 132 | } | |
| 468 | |||
| 469 | // translate shading surfaces | ||
| 470 |
1/1✓ Branch 1 taken 21 times.
|
21 | std::vector<model::ShadingSurface> shadingSurfaces = model.getConcreteModelObjects<model::ShadingSurface>(); |
| 471 |
1/1✓ Branch 3 taken 21 times.
|
21 | std::sort(shadingSurfaces.begin(), shadingSurfaces.end(), WorkspaceObjectNameLess()); |
| 472 | |||
| 473 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 474 | ✗ | m_progressBar->setWindowTitle(toString("Translating Shading Surfaces")); | |
| 475 | ✗ | m_progressBar->setMinimum(0); | |
| 476 | ✗ | m_progressBar->setMaximum((int)shadingSurfaces.size()); | |
| 477 | ✗ | m_progressBar->setValue(0); | |
| 478 | } | ||
| 479 | |||
| 480 |
2/2✓ Branch 5 taken 300 times.
✓ Branch 6 taken 21 times.
|
321 | for (const model::ShadingSurface& shadingSurface : shadingSurfaces) { |
| 481 |
1/1✓ Branch 1 taken 300 times.
|
300 | translateShadingSurface(shadingSurface, result); |
| 482 | |||
| 483 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 300 times.
|
300 | if (m_progressBar) { |
| 484 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 485 | } | ||
| 486 | } | ||
| 487 | |||
| 488 |
1/1✓ Branch 1 taken 21 times.
|
42 | return result; |
| 489 | 21 | } | |
| 490 | |||
| 491 | 21 | 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 |
1/1✓ Branch 1 taken 21 times.
|
21 | boost::optional<model::Building> _building = model.getOptionalUniqueModelObject<model::Building>(); |
| 495 | |||
| 496 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto result = parent.append_child("Building"); |
| 497 |
1/1✓ Branch 1 taken 21 times.
|
42 | std::string bName = "Building"; |
| 498 |
1/1✓ Branch 1 taken 21 times.
|
42 | std::string bType = "Unknown"; |
| 499 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 1 time.
|
21 | if (_building) { |
| 500 |
3/3✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
|
20 | m_translatedObjects[_building->handle()] = result; |
| 501 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
|
20 | bName = _building->nameString(); |
| 502 | |||
| 503 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
|
40 | if (boost::optional<std::string> _standardsBuildingType = _building->standardsBuildingType()) { |
| 504 | // TODO: map to gbXML types | ||
| 505 | // bType = escapeName(_standardsBuildingType.get()).c_str(); | ||
| 506 | 20 | } | |
| 507 | |||
| 508 | // space type | ||
| 509 |
2/2✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
|
40 | 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 | 20 | } | |
| 514 | } | ||
| 515 | |||
| 516 | // id | ||
| 517 |
3/3✓ Branch 1 taken 21 times.
✓ Branch 5 taken 21 times.
✓ Branch 8 taken 21 times.
|
21 | result.append_attribute("id") = escapeName(bName).c_str(); |
| 518 | |||
| 519 | // building type | ||
| 520 |
2/2✓ Branch 2 taken 21 times.
✓ Branch 5 taken 21 times.
|
21 | result.append_attribute("buildingType") = bType.c_str(); |
| 521 | |||
| 522 | 21 | if (_building) { | |
| 523 | } | ||
| 524 | |||
| 525 | // name | ||
| 526 |
1/1✓ Branch 1 taken 21 times.
|
21 | auto nameElement = result.append_child("Name"); |
| 527 |
2/2✓ Branch 2 taken 21 times.
✓ Branch 5 taken 21 times.
|
21 | nameElement.text() = bName.c_str(); |
| 528 | |||
| 529 | // area | ||
| 530 |
1/1✓ Branch 1 taken 21 times.
|
21 | 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 |
1/1✓ Branch 1 taken 21 times.
|
21 | std::vector<model::Space> spaces = model.getConcreteModelObjects<model::Space>(); |
| 536 | |||
| 537 | 21 | double floorArea = 0; | |
| 538 |
2/2✓ Branch 5 taken 132 times.
✓ Branch 6 taken 21 times.
|
153 | for (const model::Space& space : spaces) { |
| 539 |
1/1✓ Branch 1 taken 132 times.
|
132 | double numberOfPeople = space.numberOfPeople(); |
| 540 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 88 times.
|
132 | if (numberOfPeople > 0.0) { |
| 541 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | floorArea += space.multiplier() * space.floorArea(); |
| 542 | } | ||
| 543 | } | ||
| 544 | |||
| 545 |
3/3✓ Branch 1 taken 21 times.
✓ Branch 5 taken 21 times.
✓ Branch 8 taken 21 times.
|
21 | areaElement.text() = openstudio::string_conversions::number(floorArea, FloatFormat::fixed).c_str(); |
| 546 | |||
| 547 | // translate spaces | ||
| 548 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 549 | ✗ | m_progressBar->setWindowTitle(toString("Translating Spaces")); | |
| 550 | ✗ | m_progressBar->setMinimum(0); | |
| 551 | ✗ | m_progressBar->setMaximum((int)spaces.size()); | |
| 552 | ✗ | m_progressBar->setValue(0); | |
| 553 | } | ||
| 554 | |||
| 555 |
1/1✓ Branch 3 taken 21 times.
|
21 | std::sort(spaces.begin(), spaces.end(), WorkspaceObjectNameLess()); |
| 556 | |||
| 557 |
2/2✓ Branch 5 taken 132 times.
✓ Branch 6 taken 21 times.
|
153 | for (const model::Space& space : spaces) { |
| 558 |
1/1✓ Branch 1 taken 132 times.
|
132 | translateSpace(space, result); |
| 559 | |||
| 560 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 132 times.
|
132 | if (m_progressBar) { |
| 561 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 562 | } | ||
| 563 | } | ||
| 564 | |||
| 565 | // translate shading surface groups | ||
| 566 |
1/1✓ Branch 1 taken 21 times.
|
21 | model::ShadingSurfaceGroupVector shadingSurfaceGroups = model.getConcreteModelObjects<model::ShadingSurfaceGroup>(); |
| 567 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 568 | ✗ | m_progressBar->setWindowTitle(toString("Translating Shading Surface Groups")); | |
| 569 | ✗ | m_progressBar->setMinimum(0); | |
| 570 | ✗ | m_progressBar->setMaximum((int)shadingSurfaceGroups.size()); | |
| 571 | ✗ | m_progressBar->setValue(0); | |
| 572 | } | ||
| 573 | |||
| 574 |
1/1✓ Branch 3 taken 21 times.
|
21 | std::sort(shadingSurfaceGroups.begin(), shadingSurfaceGroups.end(), WorkspaceObjectNameLess()); |
| 575 |
2/2✓ Branch 5 taken 37 times.
✓ Branch 6 taken 21 times.
|
58 | for (const model::ShadingSurfaceGroup& shadingSurfaceGroup : shadingSurfaceGroups) { |
| 576 |
1/1✓ Branch 1 taken 37 times.
|
37 | translateShadingSurfaceGroup(shadingSurfaceGroup, result); |
| 577 | |||
| 578 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37 times.
|
37 | if (m_progressBar) { |
| 579 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 580 | } | ||
| 581 | } | ||
| 582 | |||
| 583 | // translate stories | ||
| 584 |
1/1✓ Branch 1 taken 21 times.
|
21 | model::BuildingStoryVector stories = model.getConcreteModelObjects<model::BuildingStory>(); |
| 585 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (m_progressBar) { |
| 586 | ✗ | m_progressBar->setWindowTitle(toString("Translating Stories")); | |
| 587 | ✗ | m_progressBar->setMinimum(0); | |
| 588 | ✗ | m_progressBar->setMaximum((int)stories.size()); | |
| 589 | ✗ | m_progressBar->setValue(0); | |
| 590 | } | ||
| 591 | |||
| 592 |
2/2✓ Branch 5 taken 23 times.
✓ Branch 6 taken 21 times.
|
44 | for (const model::BuildingStory& story : stories) { |
| 593 |
1/1✓ Branch 1 taken 23 times.
|
23 | translateBuildingStory(story, result); |
| 594 | |||
| 595 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23 times.
|
23 | if (m_progressBar) { |
| 596 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 597 | } | ||
| 598 | } | ||
| 599 | |||
| 600 |
1/1✓ Branch 1 taken 21 times.
|
42 | return result; |
| 601 | 21 | } | |
| 602 | |||
| 603 | 132 | boost::optional<pugi::xml_node> ForwardTranslator::translateSpace(const openstudio::model::Space& space, pugi::xml_node& parent) { | |
| 604 |
1/1✓ Branch 1 taken 132 times.
|
132 | auto result = parent.append_child("Space"); |
| 605 |
2/2✓ Branch 1 taken 132 times.
✓ Branch 4 taken 132 times.
|
132 | m_translatedObjects[space.handle()] = result; |
| 606 | |||
| 607 |
1/1✓ Branch 1 taken 132 times.
|
132 | translateId(space, result); |
| 608 |
1/1✓ Branch 1 taken 132 times.
|
132 | translateName(space, result); |
| 609 | |||
| 610 | // space type | ||
| 611 | //boost::optional<model::SpaceType> spaceType = space.spaceType(); | ||
| 612 | //if (spaceType) { | ||
| 613 | //std::string spaceTypeName = spaceType->name().get(); | ||
| 614 | // todo: map to gbXML types | ||
| 615 | //result.setAttribute("spaceType", escapeName(spaceTypeName)); | ||
| 616 | //} | ||
| 617 | |||
| 618 | // thermal zone | ||
| 619 |
1/1✓ Branch 1 taken 132 times.
|
132 | boost::optional<model::ThermalZone> thermalZone = space.thermalZone(); |
| 620 |
1/2✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
|
132 | if (thermalZone) { |
| 621 |
4/4✓ Branch 1 taken 132 times.
✓ Branch 4 taken 132 times.
✓ Branch 7 taken 132 times.
✓ Branch 10 taken 132 times.
|
132 | std::string thermalZoneName = thermalZone->name().get(); |
| 622 |
3/3✓ Branch 1 taken 132 times.
✓ Branch 5 taken 132 times.
✓ Branch 8 taken 132 times.
|
132 | result.append_attribute("zoneIdRef") = escapeName(thermalZoneName).c_str(); |
| 623 | 132 | } | |
| 624 | |||
| 625 | // building story | ||
| 626 |
1/1✓ Branch 1 taken 132 times.
|
132 | boost::optional<model::BuildingStory> story = space.buildingStory(); |
| 627 |
2/2✓ Branch 0 taken 116 times.
✓ Branch 1 taken 16 times.
|
132 | if (story) { |
| 628 |
4/4✓ Branch 1 taken 116 times.
✓ Branch 4 taken 116 times.
✓ Branch 7 taken 116 times.
✓ Branch 10 taken 116 times.
|
116 | std::string storyName = story->name().get(); |
| 629 |
3/3✓ Branch 1 taken 116 times.
✓ Branch 5 taken 116 times.
✓ Branch 8 taken 116 times.
|
116 | result.append_attribute("buildingStoreyIdRef") = escapeName(storyName).c_str(); |
| 630 | 116 | } | |
| 631 | |||
| 632 | // append floor area | ||
| 633 |
1/1✓ Branch 1 taken 132 times.
|
132 | double area = space.floorArea(); |
| 634 |
1/1✓ Branch 1 taken 132 times.
|
132 | auto areaElement = result.append_child("Area"); |
| 635 |
3/3✓ Branch 1 taken 132 times.
✓ Branch 5 taken 132 times.
✓ Branch 8 taken 132 times.
|
132 | areaElement.text() = openstudio::string_conversions::number(area, FloatFormat::fixed).c_str(); |
| 636 | |||
| 637 | // append volume | ||
| 638 |
1/1✓ Branch 1 taken 132 times.
|
132 | double volume = space.volume(); |
| 639 |
1/1✓ Branch 1 taken 132 times.
|
132 | auto volumeElement = result.append_child("Volume"); |
| 640 |
3/3✓ Branch 1 taken 132 times.
✓ Branch 5 taken 132 times.
✓ Branch 8 taken 132 times.
|
132 | volumeElement.text() = openstudio::string_conversions::number(volume, FloatFormat::fixed).c_str(); |
| 641 | |||
| 642 | // Lighting | ||
| 643 | |||
| 644 | // LightingControl | ||
| 645 | |||
| 646 | // InfiltrationFlow | ||
| 647 | |||
| 648 | // PeopleNumber | ||
| 649 |
1/1✓ Branch 1 taken 132 times.
|
132 | double numberOfPeople = space.numberOfPeople(); |
| 650 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 88 times.
|
132 | if (numberOfPeople > 0) { |
| 651 |
1/1✓ Branch 1 taken 44 times.
|
44 | double floorAreaPerPerson = space.floorAreaPerPerson(); |
| 652 |
1/1✓ Branch 1 taken 44 times.
|
44 | auto peopleNumberElement = result.append_child("PeopleNumber"); |
| 653 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | peopleNumberElement.append_attribute("unit") = "SquareMPerPerson"; |
| 654 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 5 taken 44 times.
✓ Branch 8 taken 44 times.
|
44 | peopleNumberElement.text() = openstudio::string_conversions::number(floorAreaPerPerson, FloatFormat::fixed).c_str(); |
| 655 | } | ||
| 656 | |||
| 657 | // PeopleHeatGain | ||
| 658 | // unit "WattPerPerson", BtuPerHourPerson" | ||
| 659 | // heatGainType "Total", "Sensible", "Latent" | ||
| 660 | |||
| 661 | // LightPowerPerArea | ||
| 662 |
1/1✓ Branch 1 taken 132 times.
|
132 | double lightingPowerPerFloorArea = space.lightingPowerPerFloorArea(); |
| 663 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 88 times.
|
132 | if (lightingPowerPerFloorArea > 0) { |
| 664 |
1/1✓ Branch 1 taken 44 times.
|
44 | auto lightPowerPerAreaElement = result.append_child("LightPowerPerArea"); |
| 665 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | lightPowerPerAreaElement.append_attribute("unit") = "WattPerSquareMeter"; |
| 666 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 5 taken 44 times.
✓ Branch 8 taken 44 times.
|
44 | lightPowerPerAreaElement.text() = openstudio::string_conversions::number(lightingPowerPerFloorArea, FloatFormat::fixed).c_str(); |
| 667 | } | ||
| 668 | |||
| 669 | // EquipPowerPerArea | ||
| 670 |
1/1✓ Branch 1 taken 132 times.
|
132 | double electricEquipmentPowerPerFloorArea = space.electricEquipmentPowerPerFloorArea(); |
| 671 |
2/2✓ Branch 0 taken 44 times.
✓ Branch 1 taken 88 times.
|
132 | if (electricEquipmentPowerPerFloorArea > 0) { |
| 672 |
1/1✓ Branch 1 taken 44 times.
|
44 | auto equipPowerPerAreaElement = result.append_child("EquipPowerPerArea"); |
| 673 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | equipPowerPerAreaElement.append_attribute("unit") = "WattPerSquareMeter"; |
| 674 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 5 taken 44 times.
✓ Branch 8 taken 44 times.
|
44 | equipPowerPerAreaElement.text() = openstudio::string_conversions::number(electricEquipmentPowerPerFloorArea, FloatFormat::fixed).c_str(); |
| 675 | } | ||
| 676 | |||
| 677 | // Temperature | ||
| 678 | // unit "F", "C", "K", "R" | ||
| 679 | |||
| 680 | // export CADObjectId if present | ||
| 681 |
1/1✓ Branch 1 taken 132 times.
|
132 | translateCADObjectId(space, result); |
| 682 | |||
| 683 |
1/1✓ Branch 1 taken 132 times.
|
264 | return result; |
| 684 | 132 | } | |
| 685 | |||
| 686 | 37 | boost::optional<pugi::xml_node> ForwardTranslator::translateShadingSurfaceGroup(const openstudio::model::ShadingSurfaceGroup& shadingSurfaceGroup, | |
| 687 | pugi::xml_node& parent) { | ||
| 688 |
3/3✓ Branch 1 taken 37 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 26 times.
|
74 | if (shadingSurfaceGroup.space()) { |
| 689 | 11 | return boost::none; | |
| 690 | } | ||
| 691 | |||
| 692 |
1/1✓ Branch 1 taken 26 times.
|
26 | auto result = parent.append_child("Space"); |
| 693 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
26 | m_translatedObjects[shadingSurfaceGroup.handle()] = result; |
| 694 | |||
| 695 |
1/1✓ Branch 1 taken 26 times.
|
26 | translateId(shadingSurfaceGroup, result); |
| 696 |
1/1✓ Branch 1 taken 26 times.
|
26 | translateName(shadingSurfaceGroup, result); |
| 697 | |||
| 698 |
1/1✓ Branch 1 taken 26 times.
|
26 | return result; |
| 699 | } | ||
| 700 | |||
| 701 | 23 | boost::optional<pugi::xml_node> ForwardTranslator::translateBuildingStory(const openstudio::model::BuildingStory& story, pugi::xml_node& parent) { | |
| 702 |
1/1✓ Branch 1 taken 23 times.
|
23 | boost::optional<double> zLevel = story.nominalZCoordinate(); |
| 703 | |||
| 704 | // z-level not set, attempt to find it | ||
| 705 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 13 times.
|
23 | if (!zLevel) { |
| 706 |
3/3✓ Branch 1 taken 10 times.
✓ Branch 8 taken 64 times.
✓ Branch 9 taken 10 times.
|
74 | for (const auto& space : story.spaces()) { |
| 707 |
1/1✓ Branch 1 taken 64 times.
|
64 | Transformation t = space.buildingTransformation(); |
| 708 |
3/3✓ Branch 1 taken 64 times.
✓ Branch 8 taken 968 times.
✓ Branch 9 taken 64 times.
|
1032 | for (const auto& surface : space.surfaces()) { |
| 709 |
3/3✓ Branch 1 taken 968 times.
✓ Branch 8 taken 4508 times.
✓ Branch 9 taken 968 times.
|
5476 | for (const auto& vertex : surface.vertices()) { |
| 710 |
2/2✓ Branch 0 taken 4498 times.
✓ Branch 1 taken 10 times.
|
4508 | if (zLevel) { |
| 711 |
3/3✓ Branch 1 taken 4498 times.
✓ Branch 4 taken 4498 times.
✓ Branch 8 taken 4498 times.
|
4498 | zLevel = std::min(*zLevel, vertex.z()); |
| 712 | } else { | ||
| 713 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | zLevel = vertex.z(); |
| 714 | } | ||
| 715 | 968 | } | |
| 716 | 64 | } | |
| 717 | 74 | } | |
| 718 | } | ||
| 719 | |||
| 720 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
|
23 | if (!zLevel) { |
| 721 | ✗ | zLevel = 0; | |
| 722 | } | ||
| 723 | |||
| 724 |
1/1✓ Branch 1 taken 23 times.
|
23 | auto result = parent.append_child("BuildingStorey"); |
| 725 |
2/2✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
|
23 | m_translatedObjects[story.handle()] = result; |
| 726 | |||
| 727 |
1/1✓ Branch 1 taken 23 times.
|
23 | translateId(story, result); |
| 728 |
1/1✓ Branch 1 taken 23 times.
|
23 | translateName(story, result); |
| 729 | |||
| 730 | // append level | ||
| 731 |
1/1✓ Branch 1 taken 23 times.
|
23 | auto levelElement = result.append_child("Level"); |
| 732 |
4/4✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
✓ Branch 8 taken 23 times.
✓ Branch 11 taken 23 times.
|
23 | levelElement.text() = openstudio::string_conversions::number(*zLevel, FloatFormat::fixed).c_str(); |
| 733 | |||
| 734 |
1/1✓ Branch 1 taken 23 times.
|
46 | return result; |
| 735 | } | ||
| 736 | |||
| 737 | 1467 | boost::optional<pugi::xml_node> ForwardTranslator::translateSurface(const openstudio::model::Surface& surface, pugi::xml_node& parent) { | |
| 738 | // return if already translated | ||
| 739 |
4/4✓ Branch 2 taken 1467 times.
✓ Branch 5 taken 1467 times.
✓ Branch 8 taken 395 times.
✓ Branch 9 taken 1072 times.
|
1467 | if (m_translatedObjects.find(surface.handle()) != m_translatedObjects.end()) { |
| 740 | 395 | return boost::none; | |
| 741 | } | ||
| 742 | |||
| 743 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto result = parent.append_child("Surface"); |
| 744 |
2/2✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
|
1072 | m_translatedObjects[surface.handle()] = result; |
| 745 | |||
| 746 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | translateId(surface, result); |
| 747 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | translateName(surface, result); |
| 748 | |||
| 749 | // DLM: currently unhandled | ||
| 750 | //FreestandingColumn | ||
| 751 | //EmbeddedColumn | ||
| 752 | |||
| 753 | 1072 | bool checkSlabOnGrade = false; | |
| 754 | |||
| 755 |
3/3✓ Branch 1 taken 1072 times.
✓ Branch 3 taken 58 times.
✓ Branch 4 taken 1014 times.
|
1072 | if (surface.isAirWall()) { |
| 756 |
2/2✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
|
58 | result.append_attribute("surfaceType") = "Air"; |
| 757 | } else { | ||
| 758 |
1/1✓ Branch 1 taken 1014 times.
|
1014 | std::string surfaceType = surface.surfaceType(); |
| 759 |
1/1✓ Branch 1 taken 1014 times.
|
1014 | std::string outsideBoundaryCondition = surface.outsideBoundaryCondition(); |
| 760 |
4/4✓ Branch 1 taken 1014 times.
✓ Branch 4 taken 1014 times.
✓ Branch 7 taken 682 times.
✓ Branch 8 taken 332 times.
|
2028 | if (istringEqual("Wall", surfaceType)) { |
| 761 |
4/4✓ Branch 1 taken 682 times.
✓ Branch 4 taken 682 times.
✓ Branch 7 taken 379 times.
✓ Branch 8 taken 303 times.
|
1364 | if (istringEqual("Outdoors", outsideBoundaryCondition)) { |
| 762 |
2/2✓ Branch 1 taken 379 times.
✓ Branch 4 taken 379 times.
|
379 | result.append_attribute("surfaceType") = "ExteriorWall"; |
| 763 |
4/4✓ Branch 1 taken 303 times.
✓ Branch 4 taken 303 times.
✓ Branch 7 taken 287 times.
✓ Branch 8 taken 16 times.
|
606 | } else if (istringEqual("Surface", outsideBoundaryCondition)) { |
| 764 |
2/2✓ Branch 1 taken 287 times.
✓ Branch 4 taken 287 times.
|
287 | result.append_attribute("surfaceType") = "InteriorWall"; |
| 765 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 1 time.
|
16 | } else if (surface.isGroundSurface()) { |
| 766 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
|
15 | result.append_attribute("surfaceType") = "UndergroundWall"; |
| 767 |
3/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
2 | } else if (istringEqual("Adiabatic", outsideBoundaryCondition)) { |
| 768 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | result.append_attribute("surfaceType") = "InteriorWall"; |
| 769 | } | ||
| 770 |
4/4✓ Branch 1 taken 332 times.
✓ Branch 4 taken 332 times.
✓ Branch 7 taken 218 times.
✓ Branch 8 taken 114 times.
|
664 | } else if (istringEqual("RoofCeiling", surfaceType)) { |
| 771 |
4/4✓ Branch 1 taken 218 times.
✓ Branch 4 taken 218 times.
✓ Branch 7 taken 149 times.
✓ Branch 8 taken 69 times.
|
436 | if (istringEqual("Outdoors", outsideBoundaryCondition)) { |
| 772 |
2/2✓ Branch 1 taken 149 times.
✓ Branch 4 taken 149 times.
|
149 | result.append_attribute("surfaceType") = "Roof"; |
| 773 |
4/4✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
✓ Branch 7 taken 36 times.
✓ Branch 8 taken 33 times.
|
138 | } else if (istringEqual("Surface", outsideBoundaryCondition)) { |
| 774 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
|
36 | result.append_attribute("surfaceType") = "Ceiling"; |
| 775 |
2/3✓ Branch 1 taken 33 times.
✓ Branch 3 taken 33 times.
✗ Branch 4 not taken.
|
33 | } else if (surface.isGroundSurface()) { |
| 776 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
|
33 | result.append_attribute("surfaceType") = "UndergroundCeiling"; |
| 777 | ✗ | } else if (istringEqual("Adiabatic", outsideBoundaryCondition)) { | |
| 778 | ✗ | result.append_attribute("surfaceType") = "InteriorWall"; | |
| 779 | } | ||
| 780 |
3/4✓ Branch 1 taken 114 times.
✓ Branch 4 taken 114 times.
✓ Branch 7 taken 114 times.
✗ Branch 8 not taken.
|
228 | } else if (istringEqual("Floor", surfaceType)) { |
| 781 |
4/4✓ Branch 1 taken 114 times.
✓ Branch 4 taken 114 times.
✓ Branch 7 taken 25 times.
✓ Branch 8 taken 89 times.
|
228 | if (istringEqual("Outdoors", outsideBoundaryCondition)) { |
| 782 |
2/2✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
|
25 | result.append_attribute("surfaceType") = "RaisedFloor"; |
| 783 |
3/3✓ Branch 1 taken 89 times.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 14 times.
|
89 | } else if (surface.isGroundSurface()) { |
| 784 | 75 | checkSlabOnGrade = true; | |
| 785 | // Can be either UndergroundSlab or SlabOnGrade, check vertices later | ||
| 786 |
3/4✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
|
28 | } else if (istringEqual("Surface", outsideBoundaryCondition)) { |
| 787 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | result.append_attribute("surfaceType") = "InteriorFloor"; |
| 788 | ✗ | } else if (istringEqual("Adiabatic", outsideBoundaryCondition)) { | |
| 789 | ✗ | result.append_attribute("surfaceType") = "InteriorWall"; | |
| 790 | } | ||
| 791 | } | ||
| 792 | 1014 | } | |
| 793 | |||
| 794 | // construction | ||
| 795 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | boost::optional<model::ConstructionBase> construction = surface.construction(); |
| 796 |
2/2✓ Branch 0 taken 893 times.
✓ Branch 1 taken 179 times.
|
1072 | if (construction) { |
| 797 |
4/4✓ Branch 1 taken 893 times.
✓ Branch 4 taken 893 times.
✓ Branch 7 taken 893 times.
✓ Branch 10 taken 893 times.
|
893 | std::string constructionName = construction->name().get(); |
| 798 |
4/4✓ Branch 1 taken 893 times.
✓ Branch 4 taken 893 times.
✓ Branch 6 taken 835 times.
✓ Branch 7 taken 58 times.
|
893 | if (construction->isOpaque()) { |
| 799 |
3/3✓ Branch 1 taken 835 times.
✓ Branch 5 taken 835 times.
✓ Branch 8 taken 835 times.
|
835 | result.append_attribute("constructionIdRef") = escapeName(constructionName).c_str(); |
| 800 | } else { | ||
| 801 |
3/3✓ Branch 1 taken 58 times.
✓ Branch 5 taken 58 times.
✓ Branch 8 taken 58 times.
|
58 | result.append_attribute("constructionIdRef") = escapeName(constructionName).c_str(); // FIXME: windowTypeIdRef? |
| 802 | } | ||
| 803 | 893 | } | |
| 804 | |||
| 805 | // exposedToSun | ||
| 806 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | std::string exposedToSun = surface.sunExposure(); |
| 807 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 7 taken 519 times.
✓ Branch 8 taken 553 times.
|
2144 | if (istringEqual("NoSun", exposedToSun)) { |
| 808 |
2/2✓ Branch 1 taken 519 times.
✓ Branch 4 taken 519 times.
|
519 | result.append_attribute("exposedToSun") = "false"; |
| 809 |
3/4✓ Branch 1 taken 553 times.
✓ Branch 4 taken 553 times.
✓ Branch 7 taken 553 times.
✗ Branch 8 not taken.
|
1106 | } else if (istringEqual("SunExposed", exposedToSun)) { |
| 810 |
2/2✓ Branch 1 taken 553 times.
✓ Branch 4 taken 553 times.
|
553 | result.append_attribute("exposedToSun") = "true"; |
| 811 | } | ||
| 812 | |||
| 813 | // this space | ||
| 814 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | Transformation transformation; |
| 815 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | boost::optional<model::Space> space = surface.space(); |
| 816 |
1/2✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
|
1072 | if (space) { |
| 817 |
2/2✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
|
1072 | transformation = space->siteTransformation(); |
| 818 | |||
| 819 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 7 taken 1072 times.
✓ Branch 10 taken 1072 times.
|
1072 | std::string spaceName = space->name().get(); |
| 820 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto adjacentSpaceIdElement = result.append_child("AdjacentSpaceId"); |
| 821 |
3/3✓ Branch 1 taken 1072 times.
✓ Branch 5 taken 1072 times.
✓ Branch 8 taken 1072 times.
|
1072 | adjacentSpaceIdElement.append_attribute("spaceIdRef") = escapeName(spaceName).c_str(); |
| 822 | 1072 | } | |
| 823 | |||
| 824 | // adjacent surface | ||
| 825 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | boost::optional<model::Surface> adjacentSurface = surface.adjacentSurface(); |
| 826 |
2/2✓ Branch 0 taken 395 times.
✓ Branch 1 taken 677 times.
|
1072 | if (adjacentSurface) { |
| 827 |
2/2✓ Branch 1 taken 395 times.
✓ Branch 4 taken 395 times.
|
395 | boost::optional<model::Space> adjacentSpace = adjacentSurface->space(); |
| 828 |
1/2✓ Branch 0 taken 395 times.
✗ Branch 1 not taken.
|
395 | if (adjacentSpace) { |
| 829 |
4/4✓ Branch 1 taken 395 times.
✓ Branch 4 taken 395 times.
✓ Branch 7 taken 395 times.
✓ Branch 10 taken 395 times.
|
395 | std::string adjacentSpaceName = adjacentSpace->name().get(); |
| 830 |
1/1✓ Branch 1 taken 395 times.
|
395 | auto adjacentSpaceIdElement = result.append_child("AdjacentSpaceId"); |
| 831 |
3/3✓ Branch 1 taken 395 times.
✓ Branch 5 taken 395 times.
✓ Branch 8 taken 395 times.
|
395 | adjacentSpaceIdElement.append_attribute("spaceIdRef") = escapeName(adjacentSpaceName).c_str(); |
| 832 | |||
| 833 | // count adjacent surface as translated | ||
| 834 |
3/3✓ Branch 1 taken 395 times.
✓ Branch 4 taken 395 times.
✓ Branch 7 taken 395 times.
|
395 | m_translatedObjects[adjacentSurface->handle()] = result; |
| 835 | 395 | } | |
| 836 | 395 | } | |
| 837 | |||
| 838 | // transform vertices to world coordinates | ||
| 839 |
2/2✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
|
1072 | Point3dVector vertices = transformation * surface.vertices(); |
| 840 | |||
| 841 |
2/2✓ Branch 0 taken 75 times.
✓ Branch 1 taken 997 times.
|
1072 | if (checkSlabOnGrade) { |
| 842 | 75 | double minZ = std::numeric_limits<double>::max(); | |
| 843 | 75 | double maxZ = std::numeric_limits<double>::min(); | |
| 844 |
2/2✓ Branch 4 taken 361 times.
✓ Branch 5 taken 75 times.
|
436 | for (const auto& vertex : vertices) { |
| 845 |
1/1✓ Branch 1 taken 361 times.
|
361 | minZ = std::min(minZ, vertex.z()); |
| 846 |
1/1✓ Branch 1 taken 361 times.
|
361 | maxZ = std::max(maxZ, vertex.z()); |
| 847 | } | ||
| 848 |
4/4✓ Branch 0 taken 65 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 58 times.
✓ Branch 3 taken 7 times.
|
75 | if ((maxZ <= 0.01) && (minZ >= -0.01)) { |
| 849 |
2/2✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
|
58 | result.append_attribute("surfaceType") = "SlabOnGrade"; |
| 850 | } else { | ||
| 851 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
17 | result.append_attribute("surfaceType") = "UndergroundSlab"; |
| 852 | } | ||
| 853 | } | ||
| 854 | |||
| 855 | // check if we can make rectangular geometry | ||
| 856 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | OptionalVector3d outwardNormal = getOutwardNormal(vertices); |
| 857 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | double area = surface.grossArea(); |
| 858 |
3/6✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1072 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1072 times.
✗ Branch 5 not taken.
|
1072 | if (outwardNormal && area > 0) { |
| 859 | |||
| 860 | // get tilt, duplicate code in planar surface | ||
| 861 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | Vector3d up(0.0, 0.0, 1.0); |
| 862 |
2/2✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
|
1072 | double tiltRadians = getAngle(*outwardNormal, up); |
| 863 | |||
| 864 | // get azimuth, duplicate code in planar surface | ||
| 865 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | Vector3d north(0.0, 1.0, 0.0); |
| 866 |
2/2✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
|
1072 | double azimuthRadians = getAngle(*outwardNormal, north); |
| 867 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 6 taken 205 times.
✓ Branch 7 taken 867 times.
|
1072 | if (outwardNormal->x() < 0.0) { |
| 868 | 205 | azimuthRadians = -azimuthRadians + 2.0 * boost::math::constants::pi<double>(); | |
| 869 | } | ||
| 870 | |||
| 871 | // transform vertices to face coordinates | ||
| 872 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | Transformation faceTransformation = Transformation::alignFace(vertices); |
| 873 |
2/2✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
|
1072 | Point3dVector faceVertices = faceTransformation.inverse() * vertices; |
| 874 | 1072 | BoundingBox faceBoundingBox; | |
| 875 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | faceBoundingBox.addPoints(faceVertices); |
| 876 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 7 taken 1072 times.
✓ Branch 10 taken 1072 times.
|
1072 | double width = faceBoundingBox.maxX().get() - faceBoundingBox.minX().get(); |
| 877 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 7 taken 1072 times.
✓ Branch 10 taken 1072 times.
|
1072 | double height = faceBoundingBox.maxY().get() - faceBoundingBox.minY().get(); |
| 878 | 1072 | double areaCorrection = 1.0; | |
| 879 |
2/4✓ Branch 0 taken 1072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1072 times.
✗ Branch 3 not taken.
|
1072 | if (width > 0 && height > 0) { |
| 880 | 1072 | areaCorrection = std::sqrt(area / (width * height)); | |
| 881 | } | ||
| 882 | |||
| 883 | // pick lower left corner vertex in face coordinates | ||
| 884 | 1072 | double minY = std::numeric_limits<double>::max(); | |
| 885 | 1072 | double minX = std::numeric_limits<double>::max(); | |
| 886 | 1072 | size_t llcIndex = 0; | |
| 887 | 1072 | size_t N = vertices.size(); | |
| 888 |
2/2✓ Branch 0 taken 4865 times.
✓ Branch 1 taken 1072 times.
|
5937 | for (size_t i = 0; i < N; ++i) { |
| 889 |
1/1✓ Branch 2 taken 4865 times.
|
4865 | double z = faceVertices[i].z(); |
| 890 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 4865 times.
✗ Branch 4 not taken.
|
4865 | OS_ASSERT(std::abs(z) < 0.001); |
| 891 |
11/11✓ Branch 2 taken 4865 times.
✓ Branch 4 taken 3265 times.
✓ Branch 5 taken 1600 times.
✓ Branch 8 taken 3265 times.
✓ Branch 10 taken 1285 times.
✓ Branch 11 taken 1980 times.
✓ Branch 14 taken 1285 times.
✓ Branch 16 taken 630 times.
✓ Branch 17 taken 655 times.
✓ Branch 18 taken 2230 times.
✓ Branch 19 taken 2635 times.
|
4865 | if ((minY > faceVertices[i].y()) || ((minY > faceVertices[i].y() - 0.00001) && (minX > faceVertices[i].x()))) { |
| 892 | 2230 | llcIndex = i; | |
| 893 |
1/1✓ Branch 2 taken 2230 times.
|
2230 | minY = faceVertices[i].y(); |
| 894 |
1/1✓ Branch 2 taken 2230 times.
|
2230 | minX = faceVertices[i].x(); |
| 895 | } | ||
| 896 | } | ||
| 897 |
1/1✓ Branch 2 taken 1072 times.
|
1072 | Point3d vertex = vertices[llcIndex]; |
| 898 | |||
| 899 | // rectangular geometry | ||
| 900 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto rectangularGeometryElement = result.append_child("RectangularGeometry"); |
| 901 | |||
| 902 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto azimuthElement = rectangularGeometryElement.append_child("Azimuth"); |
| 903 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 8 taken 1072 times.
✓ Branch 11 taken 1072 times.
|
1072 | azimuthElement.text() = openstudio::string_conversions::number(radToDeg(azimuthRadians), FloatFormat::general).c_str(); |
| 904 | |||
| 905 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto cartesianPointElement = rectangularGeometryElement.append_child("CartesianPoint"); |
| 906 | |||
| 907 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto coordinateXElement = cartesianPointElement.append_child("Coordinate"); |
| 908 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 8 taken 1072 times.
✓ Branch 11 taken 1072 times.
|
1072 | coordinateXElement.text() = openstudio::string_conversions::number(vertex.x(), FloatFormat::fixed).c_str(); |
| 909 | |||
| 910 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto coordinateYElement = cartesianPointElement.append_child("Coordinate"); |
| 911 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 8 taken 1072 times.
✓ Branch 11 taken 1072 times.
|
1072 | coordinateYElement.text() = openstudio::string_conversions::number(vertex.y(), FloatFormat::fixed).c_str(); |
| 912 | |||
| 913 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto coordinateZElement = cartesianPointElement.append_child("Coordinate"); |
| 914 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 8 taken 1072 times.
✓ Branch 11 taken 1072 times.
|
1072 | coordinateZElement.text() = openstudio::string_conversions::number(vertex.z(), FloatFormat::fixed).c_str(); |
| 915 | |||
| 916 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto tiltElement = rectangularGeometryElement.append_child("Tilt"); |
| 917 |
4/4✓ Branch 1 taken 1072 times.
✓ Branch 4 taken 1072 times.
✓ Branch 8 taken 1072 times.
✓ Branch 11 taken 1072 times.
|
1072 | tiltElement.text() = openstudio::string_conversions::number(radToDeg(tiltRadians), FloatFormat::general).c_str(); |
| 918 | |||
| 919 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto widthElement = rectangularGeometryElement.append_child("Width"); |
| 920 |
3/3✓ Branch 1 taken 1072 times.
✓ Branch 5 taken 1072 times.
✓ Branch 8 taken 1072 times.
|
1072 | widthElement.text() = openstudio::string_conversions::number(areaCorrection * width, FloatFormat::fixed).c_str(); |
| 921 | |||
| 922 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto heightElement = rectangularGeometryElement.append_child("Height"); |
| 923 |
3/3✓ Branch 1 taken 1072 times.
✓ Branch 5 taken 1072 times.
✓ Branch 8 taken 1072 times.
|
1072 | heightElement.text() = openstudio::string_conversions::number(areaCorrection * height, FloatFormat::fixed).c_str(); |
| 924 | 1072 | } | |
| 925 | |||
| 926 | // planar geometry | ||
| 927 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto planarGeometryElement = result.append_child("PlanarGeometry"); |
| 928 | |||
| 929 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | auto polyLoopElement = planarGeometryElement.append_child("PolyLoop"); |
| 930 |
2/2✓ Branch 4 taken 4865 times.
✓ Branch 5 taken 1072 times.
|
5937 | for (const Point3d& vertex : vertices) { |
| 931 |
1/1✓ Branch 1 taken 4865 times.
|
4865 | auto cartesianPointElement = polyLoopElement.append_child("CartesianPoint"); |
| 932 | |||
| 933 |
1/1✓ Branch 1 taken 4865 times.
|
4865 | auto coordinateXElement = cartesianPointElement.append_child("Coordinate"); |
| 934 |
4/4✓ Branch 1 taken 4865 times.
✓ Branch 4 taken 4865 times.
✓ Branch 8 taken 4865 times.
✓ Branch 11 taken 4865 times.
|
4865 | coordinateXElement.text() = openstudio::string_conversions::number(vertex.x(), FloatFormat::fixed).c_str(); |
| 935 | |||
| 936 |
1/1✓ Branch 1 taken 4865 times.
|
4865 | auto coordinateYElement = cartesianPointElement.append_child("Coordinate"); |
| 937 |
4/4✓ Branch 1 taken 4865 times.
✓ Branch 4 taken 4865 times.
✓ Branch 8 taken 4865 times.
✓ Branch 11 taken 4865 times.
|
4865 | coordinateYElement.text() = openstudio::string_conversions::number(vertex.y(), FloatFormat::fixed).c_str(); |
| 938 | |||
| 939 |
1/1✓ Branch 1 taken 4865 times.
|
4865 | auto coordinateZElement = cartesianPointElement.append_child("Coordinate"); |
| 940 |
4/4✓ Branch 1 taken 4865 times.
✓ Branch 4 taken 4865 times.
✓ Branch 8 taken 4865 times.
✓ Branch 11 taken 4865 times.
|
4865 | coordinateZElement.text() = openstudio::string_conversions::number(vertex.z(), FloatFormat::fixed).c_str(); |
| 941 | } | ||
| 942 | |||
| 943 | // export CADObjectId if present | ||
| 944 |
3/3✓ Branch 1 taken 1072 times.
✓ Branch 5 taken 298 times.
✓ Branch 6 taken 774 times.
|
1072 | if (!translateCADObjectId(surface, result)) { |
| 945 |
1/1✓ Branch 1 taken 298 times.
|
298 | boost::optional<model::Surface> otherSurface = surface.adjacentSurface(); |
| 946 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 229 times.
|
298 | if (otherSurface) { |
| 947 |
2/2✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
|
69 | translateCADObjectId(*otherSurface, result); |
| 948 | } | ||
| 949 | 298 | } | |
| 950 | |||
| 951 | // translate sub surfaces | ||
| 952 |
3/3✓ Branch 1 taken 1072 times.
✓ Branch 7 taken 275 times.
✓ Branch 8 taken 1072 times.
|
1347 | for (const model::SubSurface& subSurface : surface.subSurfaces()) { |
| 953 |
1/1✓ Branch 1 taken 275 times.
|
275 | translateSubSurface(subSurface, transformation, result); |
| 954 | 1072 | } | |
| 955 | |||
| 956 |
1/1✓ Branch 1 taken 1072 times.
|
1072 | return result; |
| 957 | 1072 | } | |
| 958 | |||
| 959 | 275 | boost::optional<pugi::xml_node> ForwardTranslator::translateSubSurface(const openstudio::model::SubSurface& subSurface, | |
| 960 | const openstudio::Transformation& transformation, pugi::xml_node& parent) { | ||
| 961 | // return if already translated | ||
| 962 |
3/4✓ Branch 2 taken 275 times.
✓ Branch 5 taken 275 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 275 times.
|
275 | if (m_translatedObjects.find(subSurface.handle()) != m_translatedObjects.end()) { |
| 963 | ✗ | return boost::none; | |
| 964 | } | ||
| 965 | |||
| 966 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto result = parent.append_child("Opening"); |
| 967 |
2/2✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
|
275 | m_translatedObjects[subSurface.handle()] = result; |
| 968 | |||
| 969 |
1/1✓ Branch 1 taken 275 times.
|
275 | translateId(subSurface, result); |
| 970 |
1/1✓ Branch 1 taken 275 times.
|
275 | translateName(subSurface, result); |
| 971 | |||
| 972 | // construction | ||
| 973 |
1/1✓ Branch 1 taken 275 times.
|
275 | boost::optional<model::ConstructionBase> construction = subSurface.construction(); |
| 974 |
2/2✓ Branch 0 taken 231 times.
✓ Branch 1 taken 44 times.
|
275 | if (construction) { |
| 975 |
4/4✓ Branch 1 taken 231 times.
✓ Branch 4 taken 231 times.
✓ Branch 7 taken 231 times.
✓ Branch 10 taken 231 times.
|
231 | std::string constructionName = construction->name().get(); |
| 976 |
4/4✓ Branch 1 taken 231 times.
✓ Branch 4 taken 231 times.
✓ Branch 6 taken 70 times.
✓ Branch 7 taken 161 times.
|
231 | if (construction->isOpaque()) { |
| 977 |
3/3✓ Branch 1 taken 70 times.
✓ Branch 5 taken 70 times.
✓ Branch 8 taken 70 times.
|
70 | result.append_attribute("constructionIdRef") = escapeName(constructionName).c_str(); |
| 978 | } else { | ||
| 979 |
3/3✓ Branch 1 taken 161 times.
✓ Branch 5 taken 161 times.
✓ Branch 8 taken 161 times.
|
161 | result.append_attribute("windowTypeIdRef") = escapeName(constructionName).c_str(); |
| 980 | } | ||
| 981 | 231 | } | |
| 982 | |||
| 983 | // DLM: currently unhandled, nothing in os maps to these | ||
| 984 | // OperableSkylight | ||
| 985 | // SlidingDoor | ||
| 986 | |||
| 987 |
3/3✓ Branch 1 taken 275 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 266 times.
|
275 | if (subSurface.isAirWall()) { |
| 988 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | result.append_attribute("openingType") = "Air"; |
| 989 | } else { | ||
| 990 |
1/1✓ Branch 1 taken 266 times.
|
266 | std::string subSurfaceType = subSurface.subSurfaceType(); |
| 991 |
4/4✓ Branch 1 taken 266 times.
✓ Branch 4 taken 266 times.
✓ Branch 7 taken 74 times.
✓ Branch 8 taken 192 times.
|
532 | if (istringEqual("FixedWindow", subSurfaceType)) { |
| 992 |
2/2✓ Branch 1 taken 74 times.
✓ Branch 4 taken 74 times.
|
74 | result.append_attribute("openingType") = "FixedWindow"; |
| 993 |
4/4✓ Branch 1 taken 192 times.
✓ Branch 4 taken 192 times.
✓ Branch 7 taken 107 times.
✓ Branch 8 taken 85 times.
|
384 | } else if (istringEqual("OperableWindow", subSurfaceType)) { |
| 994 |
2/2✓ Branch 1 taken 107 times.
✓ Branch 4 taken 107 times.
|
107 | result.append_attribute("openingType") = "OperableWindow"; |
| 995 |
4/4✓ Branch 1 taken 85 times.
✓ Branch 4 taken 85 times.
✓ Branch 7 taken 83 times.
✓ Branch 8 taken 2 times.
|
170 | } else if (istringEqual("Door", subSurfaceType)) { |
| 996 |
2/2✓ Branch 1 taken 83 times.
✓ Branch 4 taken 83 times.
|
83 | result.append_attribute("openingType") = "NonSlidingDoor"; |
| 997 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
|
4 | } else if (istringEqual("GlassDoor", subSurfaceType)) { |
| 998 | ✗ | result.append_attribute("openingType") = "SlidingDoor"; | |
| 999 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
|
4 | } else if (istringEqual("OverheadDoor", subSurfaceType)) { |
| 1000 | ✗ | result.append_attribute("openingType") = "NonSlidingDoor"; | |
| 1001 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
4 | } else if (istringEqual("Skylight", subSurfaceType)) { |
| 1002 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | result.append_attribute("openingType") = "FixedSkylight"; |
| 1003 | ✗ | } else if (istringEqual("TubularDaylightDome", subSurfaceType)) { | |
| 1004 | ✗ | result.append_attribute("openingType") = "FixedSkylight"; | |
| 1005 | ✗ | } else if (istringEqual("TubularDaylightDiffuser", subSurfaceType)) { | |
| 1006 | ✗ | result.append_attribute("openingType") = "FixedSkylight"; | |
| 1007 | } | ||
| 1008 | 266 | } | |
| 1009 | |||
| 1010 | // transform vertices to world coordinates | ||
| 1011 |
2/2✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
|
275 | Point3dVector vertices = transformation * subSurface.vertices(); |
| 1012 | |||
| 1013 | // check if we can make rectangular geometry | ||
| 1014 |
1/1✓ Branch 1 taken 275 times.
|
275 | OptionalVector3d outwardNormal = getOutwardNormal(vertices); |
| 1015 |
1/1✓ Branch 1 taken 275 times.
|
275 | double area = subSurface.grossArea(); |
| 1016 |
3/6✓ Branch 0 taken 275 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 275 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 275 times.
✗ Branch 5 not taken.
|
275 | if (outwardNormal && area > 0) { |
| 1017 | |||
| 1018 | // get tilt, duplicate code in planar surface | ||
| 1019 |
1/1✓ Branch 1 taken 275 times.
|
275 | Vector3d up(0.0, 0.0, 1.0); |
| 1020 |
2/2✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
|
275 | double tiltRadians = getAngle(*outwardNormal, up); |
| 1021 | |||
| 1022 | // get azimuth, duplicate code in planar surface | ||
| 1023 |
1/1✓ Branch 1 taken 275 times.
|
275 | Vector3d north(0.0, 1.0, 0.0); |
| 1024 |
2/2✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
|
275 | double azimuthRadians = getAngle(*outwardNormal, north); |
| 1025 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 6 taken 83 times.
✓ Branch 7 taken 192 times.
|
275 | if (outwardNormal->x() < 0.0) { |
| 1026 | 83 | azimuthRadians = -azimuthRadians + 2.0 * boost::math::constants::pi<double>(); | |
| 1027 | } | ||
| 1028 | |||
| 1029 | // transform vertices to face coordinates | ||
| 1030 |
1/1✓ Branch 1 taken 275 times.
|
275 | Transformation faceTransformation = Transformation::alignFace(vertices); |
| 1031 |
2/2✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
|
275 | Point3dVector faceVertices = faceTransformation.inverse() * vertices; |
| 1032 | 275 | BoundingBox faceBoundingBox; | |
| 1033 |
1/1✓ Branch 1 taken 275 times.
|
275 | faceBoundingBox.addPoints(faceVertices); |
| 1034 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 7 taken 275 times.
✓ Branch 10 taken 275 times.
|
275 | double width = faceBoundingBox.maxX().get() - faceBoundingBox.minX().get(); |
| 1035 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 7 taken 275 times.
✓ Branch 10 taken 275 times.
|
275 | double height = faceBoundingBox.maxY().get() - faceBoundingBox.minY().get(); |
| 1036 | 275 | double areaCorrection = 1.0; | |
| 1037 |
2/4✓ Branch 0 taken 275 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 275 times.
✗ Branch 3 not taken.
|
275 | if (width > 0 && height > 0) { |
| 1038 | 275 | areaCorrection = std::sqrt(area / (width * height)); | |
| 1039 | } | ||
| 1040 | |||
| 1041 | // pick lower left corner vertex in face coordinates | ||
| 1042 | 275 | double minY = std::numeric_limits<double>::max(); | |
| 1043 | 275 | double minX = std::numeric_limits<double>::max(); | |
| 1044 | 275 | size_t llcIndex = 0; | |
| 1045 | 275 | size_t N = vertices.size(); | |
| 1046 |
2/2✓ Branch 0 taken 1119 times.
✓ Branch 1 taken 275 times.
|
1394 | for (size_t i = 0; i < N; ++i) { |
| 1047 |
1/1✓ Branch 2 taken 1119 times.
|
1119 | double z = faceVertices[i].z(); |
| 1048 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 1119 times.
✗ Branch 4 not taken.
|
1119 | OS_ASSERT(std::abs(z) < 0.001); |
| 1049 |
11/11✓ Branch 2 taken 1119 times.
✓ Branch 4 taken 803 times.
✓ Branch 5 taken 316 times.
✓ Branch 8 taken 803 times.
✓ Branch 10 taken 281 times.
✓ Branch 11 taken 522 times.
✓ Branch 14 taken 281 times.
✓ Branch 16 taken 139 times.
✓ Branch 17 taken 142 times.
✓ Branch 18 taken 455 times.
✓ Branch 19 taken 664 times.
|
1119 | if ((minY > faceVertices[i].y()) || ((minY > faceVertices[i].y() - 0.00001) && (minX > faceVertices[i].x()))) { |
| 1050 | 455 | llcIndex = i; | |
| 1051 |
1/1✓ Branch 2 taken 455 times.
|
455 | minY = faceVertices[i].y(); |
| 1052 |
1/1✓ Branch 2 taken 455 times.
|
455 | minX = faceVertices[i].x(); |
| 1053 | } | ||
| 1054 | } | ||
| 1055 |
1/1✓ Branch 2 taken 275 times.
|
275 | Point3d vertex = vertices[llcIndex]; |
| 1056 | |||
| 1057 | // rectangular geometry | ||
| 1058 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto rectangularGeometryElement = result.append_child("RectangularGeometry"); |
| 1059 | |||
| 1060 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto azimuthElement = rectangularGeometryElement.append_child("Azimuth"); |
| 1061 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 8 taken 275 times.
✓ Branch 11 taken 275 times.
|
275 | azimuthElement.text() = openstudio::string_conversions::number(radToDeg(azimuthRadians), FloatFormat::general).c_str(); |
| 1062 | |||
| 1063 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto cartesianPointElement = rectangularGeometryElement.append_child("CartesianPoint"); |
| 1064 | |||
| 1065 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto coordinateXElement = cartesianPointElement.append_child("Coordinate"); |
| 1066 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 8 taken 275 times.
✓ Branch 11 taken 275 times.
|
275 | coordinateXElement.text() = openstudio::string_conversions::number(vertex.x(), FloatFormat::fixed).c_str(); |
| 1067 | |||
| 1068 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto coordinateYElement = cartesianPointElement.append_child("Coordinate"); |
| 1069 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 8 taken 275 times.
✓ Branch 11 taken 275 times.
|
275 | coordinateYElement.text() = openstudio::string_conversions::number(vertex.y(), FloatFormat::fixed).c_str(); |
| 1070 | |||
| 1071 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto coordinateZElement = cartesianPointElement.append_child("Coordinate"); |
| 1072 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 8 taken 275 times.
✓ Branch 11 taken 275 times.
|
275 | coordinateZElement.text() = openstudio::string_conversions::number(vertex.z(), FloatFormat::fixed).c_str(); |
| 1073 | |||
| 1074 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto tiltElement = rectangularGeometryElement.append_child("Tilt"); |
| 1075 |
4/4✓ Branch 1 taken 275 times.
✓ Branch 4 taken 275 times.
✓ Branch 8 taken 275 times.
✓ Branch 11 taken 275 times.
|
275 | tiltElement.text() = openstudio::string_conversions::number(radToDeg(tiltRadians), FloatFormat::general).c_str(); |
| 1076 | |||
| 1077 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto widthElement = rectangularGeometryElement.append_child("Width"); |
| 1078 |
3/3✓ Branch 1 taken 275 times.
✓ Branch 5 taken 275 times.
✓ Branch 8 taken 275 times.
|
275 | widthElement.text() = openstudio::string_conversions::number(areaCorrection * width, FloatFormat::fixed).c_str(); |
| 1079 | |||
| 1080 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto heightElement = rectangularGeometryElement.append_child("Height"); |
| 1081 |
3/3✓ Branch 1 taken 275 times.
✓ Branch 5 taken 275 times.
✓ Branch 8 taken 275 times.
|
275 | heightElement.text() = openstudio::string_conversions::number(areaCorrection * height, FloatFormat::fixed).c_str(); |
| 1082 | 275 | } | |
| 1083 | |||
| 1084 | // planar geometry | ||
| 1085 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto planarGeometryElement = result.append_child("PlanarGeometry"); |
| 1086 | |||
| 1087 | // translate vertices | ||
| 1088 |
1/1✓ Branch 1 taken 275 times.
|
275 | auto polyLoopElement = planarGeometryElement.append_child("PolyLoop"); |
| 1089 |
2/2✓ Branch 4 taken 1119 times.
✓ Branch 5 taken 275 times.
|
1394 | for (const Point3d& vertex : vertices) { |
| 1090 |
1/1✓ Branch 1 taken 1119 times.
|
1119 | auto cartesianPointElement = polyLoopElement.append_child("CartesianPoint"); |
| 1091 | |||
| 1092 |
1/1✓ Branch 1 taken 1119 times.
|
1119 | auto coordinateXElement = cartesianPointElement.append_child("Coordinate"); |
| 1093 |
4/4✓ Branch 1 taken 1119 times.
✓ Branch 4 taken 1119 times.
✓ Branch 8 taken 1119 times.
✓ Branch 11 taken 1119 times.
|
1119 | coordinateXElement.text() = openstudio::string_conversions::number(vertex.x(), FloatFormat::fixed).c_str(); |
| 1094 | |||
| 1095 |
1/1✓ Branch 1 taken 1119 times.
|
1119 | auto coordinateYElement = cartesianPointElement.append_child("Coordinate"); |
| 1096 |
4/4✓ Branch 1 taken 1119 times.
✓ Branch 4 taken 1119 times.
✓ Branch 8 taken 1119 times.
✓ Branch 11 taken 1119 times.
|
1119 | coordinateYElement.text() = openstudio::string_conversions::number(vertex.y(), FloatFormat::fixed).c_str(); |
| 1097 | |||
| 1098 |
1/1✓ Branch 1 taken 1119 times.
|
1119 | auto coordinateZElement = cartesianPointElement.append_child("Coordinate"); |
| 1099 |
4/4✓ Branch 1 taken 1119 times.
✓ Branch 4 taken 1119 times.
✓ Branch 8 taken 1119 times.
✓ Branch 11 taken 1119 times.
|
1119 | coordinateZElement.text() = openstudio::string_conversions::number(vertex.z(), FloatFormat::fixed).c_str(); |
| 1100 | } | ||
| 1101 | |||
| 1102 | // export CADObjectId if present | ||
| 1103 |
3/3✓ Branch 1 taken 275 times.
✓ Branch 5 taken 103 times.
✓ Branch 6 taken 172 times.
|
275 | if (!translateCADObjectId(subSurface, result)) { |
| 1104 |
1/1✓ Branch 1 taken 103 times.
|
103 | boost::optional<model::SubSurface> otherSubSurface = subSurface.adjacentSubSurface(); |
| 1105 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 89 times.
|
103 | if (otherSubSurface) { |
| 1106 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | translateCADObjectId(*otherSubSurface, result); |
| 1107 | } | ||
| 1108 | 103 | } | |
| 1109 |
1/1✓ Branch 1 taken 275 times.
|
275 | return result; |
| 1110 | 275 | } | |
| 1111 | |||
| 1112 | 300 | boost::optional<pugi::xml_node> ForwardTranslator::translateShadingSurface(const openstudio::model::ShadingSurface& shadingSurface, | |
| 1113 | pugi::xml_node& parent) { | ||
| 1114 | // return if already translated | ||
| 1115 |
3/4✓ Branch 2 taken 300 times.
✓ Branch 5 taken 300 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 300 times.
|
300 | if (m_translatedObjects.find(shadingSurface.handle()) != m_translatedObjects.end()) { |
| 1116 | ✗ | return boost::none; | |
| 1117 | } | ||
| 1118 | |||
| 1119 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto result = parent.append_child("Surface"); |
| 1120 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
|
300 | m_translatedObjects[shadingSurface.handle()] = result; |
| 1121 | |||
| 1122 |
1/1✓ Branch 1 taken 300 times.
|
300 | translateId(shadingSurface, result); |
| 1123 |
1/1✓ Branch 1 taken 300 times.
|
300 | translateName(shadingSurface, result); |
| 1124 | |||
| 1125 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
|
300 | result.append_attribute("surfaceType") = "Shade"; |
| 1126 | |||
| 1127 | // construction | ||
| 1128 |
1/1✓ Branch 1 taken 300 times.
|
300 | boost::optional<model::ConstructionBase> construction = shadingSurface.construction(); |
| 1129 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 300 times.
|
300 | if (construction) { |
| 1130 | ✗ | std::string constructionName = construction->name().get(); | |
| 1131 | ✗ | if (construction->isOpaque()) { | |
| 1132 | ✗ | result.append_attribute("constructionIdRef") = escapeName(constructionName).c_str(); | |
| 1133 | } else { | ||
| 1134 | ✗ | result.append_attribute("windowTypeIdRef") = escapeName(constructionName).c_str(); | |
| 1135 | } | ||
| 1136 | ✗ | } else { | |
| 1137 | // no construction is relevant here, but we don't want to fail validation | ||
| 1138 |
1/1✓ Branch 1 taken 300 times.
|
300 | std::string name{shadingSurfaceWithoutConstructionName}; |
| 1139 | |||
| 1140 |
2/2✓ Branch 2 taken 300 times.
✓ Branch 5 taken 300 times.
|
300 | result.append_attribute("constructionIdRef") = name.c_str(); |
| 1141 | |||
| 1142 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 285 times.
|
300 | if (!m_placeholderShadingSurfaceConstructionAlreadyCreated) { |
| 1143 | // parent is Facility, and its parent is the gbXML element | ||
| 1144 |
1/1✓ Branch 1 taken 15 times.
|
15 | auto gbXMLElement = parent.parent(); |
| 1145 |
1/1✓ Branch 1 taken 15 times.
|
15 | auto node = gbXMLElement.append_child("Construction"); |
| 1146 |
2/2✓ Branch 2 taken 15 times.
✓ Branch 5 taken 15 times.
|
15 | node.append_attribute("id") = name.c_str(); |
| 1147 |
3/3✓ Branch 2 taken 15 times.
✓ Branch 5 taken 15 times.
✓ Branch 8 taken 15 times.
|
15 | node.append_child("Name").text() = name.c_str(); |
| 1148 | // Switch bool off | ||
| 1149 | 15 | m_placeholderShadingSurfaceConstructionAlreadyCreated = true; | |
| 1150 | } | ||
| 1151 | 300 | } | |
| 1152 | |||
| 1153 | // this space | ||
| 1154 |
1/1✓ Branch 1 taken 300 times.
|
300 | Transformation transformation; |
| 1155 |
1/1✓ Branch 1 taken 300 times.
|
300 | boost::optional<model::Space> space = shadingSurface.space(); |
| 1156 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 289 times.
|
300 | if (space) { |
| 1157 |
1/1✓ Branch 1 taken 11 times.
|
11 | boost::optional<model::ShadingSurfaceGroup> shadingSurfaceGroup = shadingSurface.shadingSurfaceGroup(); |
| 1158 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | if (shadingSurfaceGroup) { |
| 1159 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
11 | transformation = shadingSurfaceGroup->siteTransformation(); |
| 1160 | } else { | ||
| 1161 | ✗ | transformation = space->siteTransformation(); | |
| 1162 | } | ||
| 1163 | |||
| 1164 |
4/4✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✓ Branch 10 taken 11 times.
|
11 | std::string spaceName = space->name().get(); |
| 1165 |
1/1✓ Branch 1 taken 11 times.
|
11 | auto adjacentSpaceIdElement = result.append_child("AdjacentSpaceId"); |
| 1166 |
3/3✓ Branch 1 taken 11 times.
✓ Branch 5 taken 11 times.
✓ Branch 8 taken 11 times.
|
11 | adjacentSpaceIdElement.append_attribute("spaceIdRef") = escapeName(spaceName).c_str(); |
| 1167 | 11 | } else { | |
| 1168 |
1/1✓ Branch 1 taken 289 times.
|
289 | boost::optional<model::ShadingSurfaceGroup> shadingSurfaceGroup = shadingSurface.shadingSurfaceGroup(); |
| 1169 |
1/2✓ Branch 0 taken 289 times.
✗ Branch 1 not taken.
|
289 | if (shadingSurfaceGroup) { |
| 1170 |
2/2✓ Branch 1 taken 289 times.
✓ Branch 4 taken 289 times.
|
289 | transformation = shadingSurfaceGroup->siteTransformation(); |
| 1171 | |||
| 1172 |
4/4✓ Branch 1 taken 289 times.
✓ Branch 4 taken 289 times.
✓ Branch 7 taken 289 times.
✓ Branch 10 taken 289 times.
|
289 | std::string spaceName = shadingSurfaceGroup->name().get(); |
| 1173 |
1/1✓ Branch 1 taken 289 times.
|
289 | auto adjacentSpaceIdElement = result.append_child("AdjacentSpaceId"); |
| 1174 |
3/3✓ Branch 1 taken 289 times.
✓ Branch 5 taken 289 times.
✓ Branch 8 taken 289 times.
|
289 | adjacentSpaceIdElement.append_attribute("spaceIdRef") = escapeName(spaceName).c_str(); |
| 1175 | 289 | } | |
| 1176 | 289 | } | |
| 1177 | |||
| 1178 | // transform vertices to world coordinates | ||
| 1179 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
|
300 | Point3dVector vertices = transformation * shadingSurface.vertices(); |
| 1180 | |||
| 1181 | // check if we can make rectangular geometry | ||
| 1182 |
1/1✓ Branch 1 taken 300 times.
|
300 | OptionalVector3d outwardNormal = getOutwardNormal(vertices); |
| 1183 |
1/1✓ Branch 1 taken 300 times.
|
300 | double area = shadingSurface.grossArea(); |
| 1184 |
3/6✓ Branch 0 taken 300 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 300 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 300 times.
✗ Branch 5 not taken.
|
300 | if (outwardNormal && area > 0) { |
| 1185 | |||
| 1186 | // get tilt, duplicate code in planar surface | ||
| 1187 |
1/1✓ Branch 1 taken 300 times.
|
300 | Vector3d up(0.0, 0.0, 1.0); |
| 1188 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
|
300 | double tiltRadians = getAngle(*outwardNormal, up); |
| 1189 | |||
| 1190 | // get azimuth, duplicate code in planar surface | ||
| 1191 |
1/1✓ Branch 1 taken 300 times.
|
300 | Vector3d north(0.0, 1.0, 0.0); |
| 1192 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
|
300 | double azimuthRadians = getAngle(*outwardNormal, north); |
| 1193 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 6 taken 56 times.
✓ Branch 7 taken 244 times.
|
300 | if (outwardNormal->x() < 0.0) { |
| 1194 | 56 | azimuthRadians = -azimuthRadians + 2.0 * boost::math::constants::pi<double>(); | |
| 1195 | } | ||
| 1196 | |||
| 1197 | // transform vertices to face coordinates | ||
| 1198 |
1/1✓ Branch 1 taken 300 times.
|
300 | Transformation faceTransformation = Transformation::alignFace(vertices); |
| 1199 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
|
300 | Point3dVector faceVertices = faceTransformation.inverse() * vertices; |
| 1200 | 300 | BoundingBox faceBoundingBox; | |
| 1201 |
1/1✓ Branch 1 taken 300 times.
|
300 | faceBoundingBox.addPoints(faceVertices); |
| 1202 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 7 taken 300 times.
✓ Branch 10 taken 300 times.
|
300 | double width = faceBoundingBox.maxX().get() - faceBoundingBox.minX().get(); |
| 1203 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 7 taken 300 times.
✓ Branch 10 taken 300 times.
|
300 | double height = faceBoundingBox.maxY().get() - faceBoundingBox.minY().get(); |
| 1204 | 300 | double areaCorrection = 1.0; | |
| 1205 |
2/4✓ Branch 0 taken 300 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 300 times.
✗ Branch 3 not taken.
|
300 | if (width > 0 && height > 0) { |
| 1206 | 300 | areaCorrection = std::sqrt(area / (width * height)); | |
| 1207 | } | ||
| 1208 | |||
| 1209 | // pick lower left corner vertex in face coordinates | ||
| 1210 | 300 | double minY = std::numeric_limits<double>::max(); | |
| 1211 | 300 | double minX = std::numeric_limits<double>::max(); | |
| 1212 | 300 | size_t llcIndex = 0; | |
| 1213 | 300 | size_t N = vertices.size(); | |
| 1214 |
2/2✓ Branch 0 taken 1188 times.
✓ Branch 1 taken 300 times.
|
1488 | for (size_t i = 0; i < N; ++i) { |
| 1215 |
1/1✓ Branch 2 taken 1188 times.
|
1188 | double z = faceVertices[i].z(); |
| 1216 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 1188 times.
✗ Branch 4 not taken.
|
1188 | OS_ASSERT(std::abs(z) < 0.001); |
| 1217 |
11/11✓ Branch 2 taken 1188 times.
✓ Branch 4 taken 715 times.
✓ Branch 5 taken 473 times.
✓ Branch 8 taken 715 times.
✓ Branch 10 taken 238 times.
✓ Branch 11 taken 477 times.
✓ Branch 14 taken 238 times.
✓ Branch 16 taken 121 times.
✓ Branch 17 taken 117 times.
✓ Branch 18 taken 594 times.
✓ Branch 19 taken 594 times.
|
1188 | if ((minY > faceVertices[i].y()) || ((minY > faceVertices[i].y() - 0.00001) && (minX > faceVertices[i].x()))) { |
| 1218 | 594 | llcIndex = i; | |
| 1219 |
1/1✓ Branch 2 taken 594 times.
|
594 | minY = faceVertices[i].y(); |
| 1220 |
1/1✓ Branch 2 taken 594 times.
|
594 | minX = faceVertices[i].x(); |
| 1221 | } | ||
| 1222 | } | ||
| 1223 |
1/1✓ Branch 2 taken 300 times.
|
300 | Point3d vertex = vertices[llcIndex]; |
| 1224 | |||
| 1225 | // rectangular geometry | ||
| 1226 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto rectangularGeometryElement = result.append_child("RectangularGeometry"); |
| 1227 | |||
| 1228 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto azimuthElement = rectangularGeometryElement.append_child("Azimuth"); |
| 1229 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 8 taken 300 times.
✓ Branch 11 taken 300 times.
|
300 | azimuthElement.text() = openstudio::string_conversions::number(radToDeg(azimuthRadians), FloatFormat::general).c_str(); |
| 1230 | |||
| 1231 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto cartesianPointElement = rectangularGeometryElement.append_child("CartesianPoint"); |
| 1232 | |||
| 1233 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto coordinateXElement = cartesianPointElement.append_child("Coordinate"); |
| 1234 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 8 taken 300 times.
✓ Branch 11 taken 300 times.
|
300 | coordinateXElement.text() = openstudio::string_conversions::number(vertex.x(), FloatFormat::fixed).c_str(); |
| 1235 | |||
| 1236 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto coordinateYElement = cartesianPointElement.append_child("Coordinate"); |
| 1237 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 8 taken 300 times.
✓ Branch 11 taken 300 times.
|
300 | coordinateYElement.text() = openstudio::string_conversions::number(vertex.y(), FloatFormat::fixed).c_str(); |
| 1238 | |||
| 1239 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto coordinateZElement = cartesianPointElement.append_child("Coordinate"); |
| 1240 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 8 taken 300 times.
✓ Branch 11 taken 300 times.
|
300 | coordinateZElement.text() = openstudio::string_conversions::number(vertex.z(), FloatFormat::fixed).c_str(); |
| 1241 | |||
| 1242 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto tiltElement = rectangularGeometryElement.append_child("Tilt"); |
| 1243 |
4/4✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 8 taken 300 times.
✓ Branch 11 taken 300 times.
|
300 | tiltElement.text() = openstudio::string_conversions::number(radToDeg(tiltRadians), FloatFormat::general).c_str(); |
| 1244 | |||
| 1245 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto widthElement = rectangularGeometryElement.append_child("Width"); |
| 1246 |
3/3✓ Branch 1 taken 300 times.
✓ Branch 5 taken 300 times.
✓ Branch 8 taken 300 times.
|
300 | widthElement.text() = openstudio::string_conversions::number(areaCorrection * width, FloatFormat::fixed).c_str(); |
| 1247 | |||
| 1248 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto heightElement = rectangularGeometryElement.append_child("Height"); |
| 1249 |
3/3✓ Branch 1 taken 300 times.
✓ Branch 5 taken 300 times.
✓ Branch 8 taken 300 times.
|
300 | heightElement.text() = openstudio::string_conversions::number(areaCorrection * height, FloatFormat::fixed).c_str(); |
| 1250 | 300 | } | |
| 1251 | |||
| 1252 | // planar geometry | ||
| 1253 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto planarGeometryElement = result.append_child("PlanarGeometry"); |
| 1254 | |||
| 1255 |
1/1✓ Branch 1 taken 300 times.
|
300 | auto polyLoopElement = planarGeometryElement.append_child("PolyLoop"); |
| 1256 |
2/2✓ Branch 4 taken 1188 times.
✓ Branch 5 taken 300 times.
|
1488 | for (const Point3d& vertex : vertices) { |
| 1257 |
1/1✓ Branch 1 taken 1188 times.
|
1188 | auto cartesianPointElement = polyLoopElement.append_child("CartesianPoint"); |
| 1258 | |||
| 1259 |
1/1✓ Branch 1 taken 1188 times.
|
1188 | auto coordinateXElement = cartesianPointElement.append_child("Coordinate"); |
| 1260 |
4/4✓ Branch 1 taken 1188 times.
✓ Branch 4 taken 1188 times.
✓ Branch 8 taken 1188 times.
✓ Branch 11 taken 1188 times.
|
1188 | coordinateXElement.text() = openstudio::string_conversions::number(vertex.x(), FloatFormat::fixed).c_str(); |
| 1261 | |||
| 1262 |
1/1✓ Branch 1 taken 1188 times.
|
1188 | auto coordinateYElement = cartesianPointElement.append_child("Coordinate"); |
| 1263 |
4/4✓ Branch 1 taken 1188 times.
✓ Branch 4 taken 1188 times.
✓ Branch 8 taken 1188 times.
✓ Branch 11 taken 1188 times.
|
1188 | coordinateYElement.text() = openstudio::string_conversions::number(vertex.y(), FloatFormat::fixed).c_str(); |
| 1264 | |||
| 1265 |
1/1✓ Branch 1 taken 1188 times.
|
1188 | auto coordinateZElement = cartesianPointElement.append_child("Coordinate"); |
| 1266 |
4/4✓ Branch 1 taken 1188 times.
✓ Branch 4 taken 1188 times.
✓ Branch 8 taken 1188 times.
✓ Branch 11 taken 1188 times.
|
1188 | coordinateZElement.text() = openstudio::string_conversions::number(vertex.z(), FloatFormat::fixed).c_str(); |
| 1267 | } | ||
| 1268 | |||
| 1269 | // export CADObjectId if present | ||
| 1270 |
1/1✓ Branch 1 taken 300 times.
|
300 | translateCADObjectId(shadingSurface, result); |
| 1271 | |||
| 1272 |
1/1✓ Branch 1 taken 300 times.
|
300 | return result; |
| 1273 | 300 | } | |
| 1274 | |||
| 1275 | 59 | boost::optional<pugi::xml_node> ForwardTranslator::translateThermalZone(const openstudio::model::ThermalZone& thermalZone, pugi::xml_node& parent) { | |
| 1276 |
1/1✓ Branch 1 taken 59 times.
|
59 | auto result = parent.append_child("Zone"); |
| 1277 |
2/2✓ Branch 1 taken 59 times.
✓ Branch 4 taken 59 times.
|
59 | m_translatedObjects[thermalZone.handle()] = result; |
| 1278 | |||
| 1279 |
1/1✓ Branch 1 taken 59 times.
|
59 | translateId(thermalZone, result); |
| 1280 |
1/1✓ Branch 1 taken 59 times.
|
59 | translateName(thermalZone, result); |
| 1281 | |||
| 1282 | // heating setpoint | ||
| 1283 | 59 | boost::optional<double> designHeatT; | |
| 1284 | 59 | boost::optional<double> designCoolT; | |
| 1285 |
1/1✓ Branch 1 taken 59 times.
|
59 | boost::optional<model::Thermostat> thermostat = thermalZone.thermostat(); |
| 1286 |
9/12✓ Branch 1 taken 11 times.
✓ Branch 2 taken 48 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✓ Branch 10 taken 11 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 11 times.
✓ Branch 13 taken 48 times.
✓ Branch 15 taken 11 times.
✓ Branch 16 taken 48 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
|
129 | if (thermostat && thermostat->optionalCast<model::ThermostatSetpointDualSetpoint>()) { |
| 1287 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
11 | auto thermostatDualSetpoint = thermostat->cast<model::ThermostatSetpointDualSetpoint>(); |
| 1288 | |||
| 1289 |
1/1✓ Branch 1 taken 11 times.
|
11 | boost::optional<model::Schedule> heatingSchedule = thermostatDualSetpoint.heatingSetpointTemperatureSchedule(); |
| 1290 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | if (heatingSchedule) { |
| 1291 |
3/4✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
|
22 | if (heatingSchedule->optionalCast<model::ScheduleRuleset>()) { |
| 1292 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
11 | auto scheduleRuleset = heatingSchedule->cast<model::ScheduleRuleset>(); |
| 1293 |
1/1✓ Branch 1 taken 11 times.
|
11 | model::ScheduleDay winterDesignDaySchedule = scheduleRuleset.winterDesignDaySchedule(); |
| 1294 |
1/1✓ Branch 1 taken 11 times.
|
11 | std::vector<double> values = winterDesignDaySchedule.values(); |
| 1295 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | if (!values.empty()) { |
| 1296 |
2/2✓ Branch 3 taken 11 times.
✓ Branch 7 taken 11 times.
|
11 | designHeatT = *std::max_element(values.begin(), values.end()); |
| 1297 | } | ||
| 1298 | 11 | } | |
| 1299 | } | ||
| 1300 | |||
| 1301 |
1/1✓ Branch 1 taken 11 times.
|
11 | boost::optional<model::Schedule> coolingSchedule = thermostatDualSetpoint.coolingSetpointTemperatureSchedule(); |
| 1302 |
1/2✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
|
11 | if (coolingSchedule) { |
| 1303 |
3/4✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
|
22 | if (coolingSchedule->optionalCast<model::ScheduleRuleset>()) { |
| 1304 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
11 | auto scheduleRuleset = coolingSchedule->cast<model::ScheduleRuleset>(); |
| 1305 |
1/1✓ Branch 1 taken 11 times.
|
11 | model::ScheduleDay summerDesignDaySchedule = scheduleRuleset.summerDesignDaySchedule(); |
| 1306 |
1/1✓ Branch 1 taken 11 times.
|
11 | std::vector<double> values = summerDesignDaySchedule.values(); |
| 1307 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | if (!values.empty()) { |
| 1308 |
2/2✓ Branch 3 taken 11 times.
✓ Branch 7 taken 11 times.
|
11 | designCoolT = *std::min_element(values.begin(), values.end()); |
| 1309 | } | ||
| 1310 | 11 | } | |
| 1311 | } | ||
| 1312 | 11 | } | |
| 1313 | |||
| 1314 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 48 times.
|
59 | if (designHeatT) { |
| 1315 |
1/1✓ Branch 1 taken 11 times.
|
11 | auto designHeatTElement = result.append_child("DesignHeatT"); |
| 1316 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
11 | designHeatTElement.append_attribute("unit") = "C"; |
| 1317 |
4/4✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 8 taken 11 times.
✓ Branch 11 taken 11 times.
|
11 | designHeatTElement.text() = openstudio::string_conversions::number(*designHeatT, FloatFormat::fixed).c_str(); |
| 1318 | } | ||
| 1319 | |||
| 1320 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 48 times.
|
59 | if (designCoolT) { |
| 1321 |
1/1✓ Branch 1 taken 11 times.
|
11 | auto designCoolTElement = result.append_child("DesignCoolT"); |
| 1322 |
2/2✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
|
11 | designCoolTElement.append_attribute("unit") = "C"; |
| 1323 |
4/4✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 8 taken 11 times.
✓ Branch 11 taken 11 times.
|
11 | designCoolTElement.text() = openstudio::string_conversions::number(*designCoolT, FloatFormat::fixed).c_str(); |
| 1324 | } | ||
| 1325 | |||
| 1326 | // export CADObjectId if present | ||
| 1327 |
1/1✓ Branch 1 taken 59 times.
|
59 | translateCADObjectId(thermalZone, result); |
| 1328 | |||
| 1329 |
1/1✓ Branch 1 taken 59 times.
|
118 | return result; |
| 1330 | 59 | } | |
| 1331 | |||
| 1332 | 2247 | void ForwardTranslator::translateId(const openstudio::model::ModelObject& modelObject, pugi::xml_node& parentElement) { | |
| 1333 | |||
| 1334 |
3/3✓ Branch 1 taken 2247 times.
✓ Branch 4 taken 2247 times.
✓ Branch 7 taken 2247 times.
|
2247 | std::string id = modelObject.name().get(); |
| 1335 |
3/3✓ Branch 1 taken 2247 times.
✓ Branch 4 taken 1548 times.
✓ Branch 5 taken 699 times.
|
4494 | if (modelObject.gbXMLId()) { |
| 1336 |
3/3✓ Branch 1 taken 1548 times.
✓ Branch 4 taken 1548 times.
✓ Branch 7 taken 1548 times.
|
1548 | id = modelObject.gbXMLId().get(); |
| 1337 | } | ||
| 1338 |
3/3✓ Branch 1 taken 2247 times.
✓ Branch 5 taken 2247 times.
✓ Branch 8 taken 2247 times.
|
2247 | parentElement.append_attribute("id") = escapeName(id).c_str(); |
| 1339 | 2247 | } | |
| 1340 | |||
| 1341 | 2247 | void ForwardTranslator::translateName(const openstudio::model::ModelObject& modelObject, pugi::xml_node& parentElement) { | |
| 1342 | |||
| 1343 |
3/3✓ Branch 1 taken 2247 times.
✓ Branch 4 taken 2247 times.
✓ Branch 7 taken 2247 times.
|
2247 | std::string name = modelObject.name().get(); |
| 1344 |
3/3✓ Branch 1 taken 2247 times.
✓ Branch 4 taken 1429 times.
✓ Branch 5 taken 818 times.
|
4494 | if (modelObject.displayName()) { |
| 1345 |
3/3✓ Branch 1 taken 1429 times.
✓ Branch 4 taken 1429 times.
✓ Branch 7 taken 1429 times.
|
1429 | name = modelObject.displayName().get(); |
| 1346 | } | ||
| 1347 |
3/3✓ Branch 2 taken 2247 times.
✓ Branch 5 taken 2247 times.
✓ Branch 8 taken 2247 times.
|
2247 | parentElement.append_child("Name").text() = name.c_str(); |
| 1348 | 2247 | } | |
| 1349 | |||
| 1350 | 1921 | boost::optional<pugi::xml_node> ForwardTranslator::translateCADObjectId(const openstudio::model::ModelObject& modelObject, | |
| 1351 | pugi::xml_node& parentElement) { | ||
| 1352 | 1921 | boost::optional<pugi::xml_node> result; | |
| 1353 | |||
| 1354 |
3/3✓ Branch 1 taken 1921 times.
✓ Branch 3 taken 1483 times.
✓ Branch 4 taken 438 times.
|
1921 | if (modelObject.hasAdditionalProperties()) { |
| 1355 |
1/1✓ Branch 1 taken 1483 times.
|
1483 | model::AdditionalProperties additionalProperties = modelObject.additionalProperties(); |
| 1356 |
3/3✓ Branch 1 taken 1483 times.
✓ Branch 3 taken 1314 times.
✓ Branch 4 taken 169 times.
|
2966 | if (boost::optional<std::string> cadObjectId = modelObject.cadObjectId()) { |
| 1357 |
1/1✓ Branch 1 taken 1314 times.
|
1314 | auto cadObjectIdElement = parentElement.append_child("CADObjectId"); |
| 1358 |
3/3✓ Branch 1 taken 1314 times.
✓ Branch 5 taken 1314 times.
✓ Branch 8 taken 1314 times.
|
1314 | cadObjectIdElement.text() = (*cadObjectId).c_str(); |
| 1359 |
1/1✓ Branch 1 taken 1314 times.
|
1314 | result = cadObjectIdElement; |
| 1360 |
3/4✓ Branch 1 taken 1314 times.
✓ Branch 4 taken 1314 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1314 times.
|
2628 | if (additionalProperties.hasFeature("programIdRef")) { |
| 1361 | ✗ | boost::optional<std::string> programIdRef = additionalProperties.getFeatureAsString("programIdRef"); | |
| 1362 | ✗ | if (programIdRef) { | |
| 1363 | ✗ | cadObjectIdElement.append_attribute("programIdRef") = (*programIdRef).c_str(); | |
| 1364 | } | ||
| 1365 | ✗ | } | |
| 1366 | 1483 | } | |
| 1367 | 1483 | } | |
| 1368 | 1921 | return result; | |
| 1369 | ✗ | } | |
| 1370 | |||
| 1371 | } // namespace gbxml | ||
| 1372 | } // namespace openstudio | ||
| 1373 |