src/gbxml/ReverseTranslator.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 "ReverseTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../model/Model.hpp" | ||
| 9 | #include "../model/ModelObject.hpp" | ||
| 10 | #include "../model/ModelObject_Impl.hpp" | ||
| 11 | #include "../model/Facility.hpp" | ||
| 12 | #include "../model/Facility_Impl.hpp" | ||
| 13 | #include "../model/Building.hpp" | ||
| 14 | #include "../model/Building_Impl.hpp" | ||
| 15 | #include "../model/BuildingStory.hpp" | ||
| 16 | #include "../model/BuildingStory_Impl.hpp" | ||
| 17 | #include "../model/ThermalZone.hpp" | ||
| 18 | #include "../model/ThermalZone_Impl.hpp" | ||
| 19 | #include "../model/Space.hpp" | ||
| 20 | #include "../model/Space_Impl.hpp" | ||
| 21 | #include "../model/SpaceType.hpp" | ||
| 22 | #include "../model/SpaceType_Impl.hpp" | ||
| 23 | #include "../model/Surface.hpp" | ||
| 24 | #include "../model/Surface_Impl.hpp" | ||
| 25 | #include "../model/SubSurface.hpp" | ||
| 26 | #include "../model/SubSurface_Impl.hpp" | ||
| 27 | #include "../model/ShadingSurface.hpp" | ||
| 28 | #include "../model/ShadingSurface_Impl.hpp" | ||
| 29 | #include "../model/ShadingSurfaceGroup.hpp" | ||
| 30 | #include "../model/ShadingSurfaceGroup_Impl.hpp" | ||
| 31 | #include "../model/ConstructionBase.hpp" | ||
| 32 | #include "../model/ConstructionBase_Impl.hpp" | ||
| 33 | #include "../model/Construction.hpp" | ||
| 34 | #include "../model/Construction_Impl.hpp" | ||
| 35 | #include "../model/ConstructionAirBoundary.hpp" | ||
| 36 | #include "../model/ConstructionAirBoundary_Impl.hpp" | ||
| 37 | #include "../model/AdditionalProperties.hpp" | ||
| 38 | |||
| 39 | #include "../utilities/core/Assert.hpp" | ||
| 40 | #include "../utilities/core/Compare.hpp" | ||
| 41 | #include "../utilities/core/FilesystemHelpers.hpp" | ||
| 42 | #include "../utilities/units/Quantity.hpp" | ||
| 43 | #include "../utilities/units/UnitFactory.hpp" | ||
| 44 | #include "../utilities/units/QuantityConverter.hpp" | ||
| 45 | #include "../utilities/plot/ProgressBar.hpp" | ||
| 46 | #include "../utilities/geometry/BoundingBox.hpp" | ||
| 47 | #include "../utilities/xml/XMLValidator.hpp" | ||
| 48 | |||
| 49 | #include <utilities/idd/IddEnums.hxx> | ||
| 50 | #include <resources.hxx> | ||
| 51 | |||
| 52 | #include <thread> | ||
| 53 | |||
| 54 | #include <pugixml.hpp> | ||
| 55 | #include <algorithm> | ||
| 56 | #include <locale> | ||
| 57 | |||
| 58 | namespace openstudio { | ||
| 59 | namespace gbxml { | ||
| 60 | |||
| 61 | ✗ | std::ostream& operator<<(std::ostream& os, const pugi::xml_node& element) { | |
| 62 | ✗ | pugi::xml_document doc; | |
| 63 | ✗ | doc.append_copy(element); | |
| 64 | ✗ | doc.save(os, " "); | |
| 65 | ✗ | return os; | |
| 66 | ✗ | } | |
| 67 | |||
| 68 |
9/9✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 8 taken 26 times.
✓ Branch 11 taken 26 times.
✓ Branch 15 taken 26 times.
✓ Branch 18 taken 26 times.
✓ Branch 22 taken 26 times.
✓ Branch 25 taken 26 times.
✓ Branch 30 taken 26 times.
|
234 | ReverseTranslator::ReverseTranslator() : m_nonBaseMultiplier(1.0), m_lengthMultiplier(1.0) { |
| 69 |
1/1✓ Branch 1 taken 26 times.
|
26 | m_logSink.setLogLevel(Warn); |
| 70 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
26 | m_logSink.setChannelRegex(boost::regex("openstudio\\.gbxml\\.ReverseTranslator")); |
| 71 |
1/1✓ Branch 2 taken 26 times.
|
26 | m_logSink.setThreadId(std::this_thread::get_id()); |
| 72 | 26 | } | |
| 73 | |||
| 74 | 26 | ReverseTranslator::~ReverseTranslator() = default; | |
| 75 | |||
| 76 | 28 | boost::optional<openstudio::model::Model> ReverseTranslator::loadModel(const openstudio::path& path, ProgressBar* progressBar) { | |
| 77 | 28 | m_progressBar = progressBar; | |
| 78 | |||
| 79 |
1/1✓ Branch 2 taken 28 times.
|
28 | m_logSink.setThreadId(std::this_thread::get_id()); |
| 80 | |||
| 81 |
1/1✓ Branch 1 taken 28 times.
|
28 | m_logSink.resetStringStream(); |
| 82 | |||
| 83 | 28 | m_idToObjectMap.clear(); | |
| 84 | |||
| 85 | 28 | boost::optional<openstudio::model::Model> result; | |
| 86 | |||
| 87 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (openstudio::filesystem::exists(path)) { |
| 88 | |||
| 89 |
1/1✓ Branch 1 taken 28 times.
|
28 | openstudio::filesystem::ifstream file(path, std::ios_base::binary); |
| 90 |
1/2✓ Branch 1 taken 28 times.
✗ Branch 2 not taken.
|
28 | if (file.is_open()) { |
| 91 |
1/1✓ Branch 1 taken 28 times.
|
28 | pugi::xml_document doc; |
| 92 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto load_result = doc.load(file); |
| 93 |
2/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 28 times.
✗ Branch 4 not taken.
|
28 | if (load_result) { |
| 94 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto root = doc.document_element(); |
| 95 |
2/3✓ Branch 2 taken 28 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
|
28 | if (std::string_view{root.name()} != "gbXML") { |
| 96 | ✗ | LOG(Error, "Expected the root element to be <gbXML>"); | |
| 97 | ✗ | return boost::none; | |
| 98 | } | ||
| 99 | // Scan version of gbxml schema | ||
| 100 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | std::string version = root.attribute("version").value(); |
| 101 |
1/1✓ Branch 1 taken 28 times.
|
28 | VersionString schemaVersion(7, 3); |
| 102 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 25 times.
|
28 | if (version.empty()) { |
| 103 |
5/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
|
3 | LOG(Warn, "gbXML has no `version` attribute for the schema version, assuming 7.03."); |
| 104 | } else { | ||
| 105 | try { | ||
| 106 |
1/1✓ Branch 1 taken 25 times.
|
25 | schemaVersion = VersionString(version); |
| 107 | ✗ | } catch (...) { | |
| 108 | ✗ | LOG(Warn, "gbXML has `version` '" << version << "' which was not understood, assuming 7.03."); | |
| 109 | ✗ | } | |
| 110 | } | ||
| 111 |
4/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 13 times.
✓ Branch 8 taken 15 times.
|
28 | if (schemaVersion == VersionString(7, 3)) { |
| 112 | // validate the gbxml prior to reverse translation | ||
| 113 |
1/1✓ Branch 1 taken 13 times.
|
13 | auto gbxmlValidator = XMLValidator::gbxmlValidator(schemaVersion); |
| 114 |
1/1✓ Branch 1 taken 13 times.
|
13 | gbxmlValidator.validate(path); |
| 115 | 13 | } else { | |
| 116 |
7/7✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
✓ Branch 10 taken 15 times.
✓ Branch 13 taken 15 times.
✓ Branch 16 taken 15 times.
✓ Branch 19 taken 15 times.
|
15 | LOG(Error, |
| 117 | "Version of schema specified: " << version | ||
| 118 | << ", expected 7.03. gbXML Schema Validation skipped. Note that ReverseTranslator rules are built " | ||
| 119 | "for 7.03 and older versions are not officially supported, check resulting model with care."); | ||
| 120 | }; | ||
| 121 | |||
| 122 |
2/2✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
|
28 | result = this->convert(root); |
| 123 | 28 | } | |
| 124 |
1/1✓ Branch 1 taken 28 times.
|
28 | file.close(); |
| 125 | 28 | } | |
| 126 | // JWD: Would be nice to add some error handling here | ||
| 127 | 28 | } | |
| 128 | |||
| 129 |
1/1✓ Branch 1 taken 28 times.
|
28 | return result; |
| 130 | 28 | } | |
| 131 | |||
| 132 | ✗ | std::vector<LogMessage> ReverseTranslator::warnings() const { | |
| 133 | ✗ | std::vector<LogMessage> result; | |
| 134 | ✗ | std::vector<LogMessage> allMessages = m_logSink.logMessages(); | |
| 135 | ✗ | std::copy_if(allMessages.cbegin(), allMessages.cend(), std::back_inserter(result), | |
| 136 | ✗ | [](const auto& logMessage) { return logMessage.logLevel() == Warn; }); | |
| 137 | ✗ | return result; | |
| 138 | ✗ | } | |
| 139 | |||
| 140 | ✗ | std::vector<LogMessage> ReverseTranslator::errors() const { | |
| 141 | ✗ | std::vector<LogMessage> result; | |
| 142 | ✗ | std::vector<LogMessage> allMessages = m_logSink.logMessages(); | |
| 143 | ✗ | std::copy_if(allMessages.cbegin(), allMessages.cend(), std::back_inserter(result), | |
| 144 | ✗ | [](const auto& logMessage) { return logMessage.logLevel() > Warn; }); | |
| 145 | ✗ | return result; | |
| 146 | ✗ | } | |
| 147 | |||
| 148 | 223 | std::string ReverseTranslator::escapeName(const std::string& id, const std::string& name) { | |
| 149 | 223 | std::string value = id; | |
| 150 |
2/2✓ Branch 1 taken 125 times.
✓ Branch 2 taken 98 times.
|
223 | if (!name.empty()) { |
| 151 |
1/1✓ Branch 1 taken 125 times.
|
125 | value = name; |
| 152 | } | ||
| 153 | 223 | std::replace(value.begin(), value.end(), ',', '-'); | |
| 154 | 223 | std::replace(value.begin(), value.end(), ';', '-'); | |
| 155 | 223 | return value; | |
| 156 | ✗ | } | |
| 157 | |||
| 158 | 28 | boost::optional<model::Model> ReverseTranslator::convert(const pugi::xml_node& root) { | |
| 159 | 28 | return translateGBXML(root); | |
| 160 | } | ||
| 161 | |||
| 162 | 28 | boost::optional<model::Model> ReverseTranslator::translateGBXML(const pugi::xml_node& root) { | |
| 163 |
1/1✓ Branch 1 taken 28 times.
|
28 | openstudio::model::Model model; |
| 164 |
1/1✓ Branch 1 taken 28 times.
|
28 | model.setFastNaming(true); |
| 165 | |||
| 166 | // gbXML attributes not mapped directly to IDF, but needed to map | ||
| 167 | |||
| 168 | // {F, C, K, R} | ||
| 169 | // JWD: the previous check was not great, this one is better and more true to the schema | ||
| 170 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
56 | std::string temperatureUnit{root.attribute("temperatureUnit").value()}; |
| 171 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 19 times.
|
28 | if (temperatureUnit == "F") { |
| 172 |
5/5✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
|
27 | m_temperatureUnit = UnitFactory::instance().createUnit("F").get(); |
| 173 |
2/3✓ Branch 1 taken 19 times.
✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
|
19 | } else if (temperatureUnit == "C") { |
| 174 |
5/5✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
✓ Branch 7 taken 19 times.
✓ Branch 10 taken 19 times.
✓ Branch 13 taken 19 times.
|
57 | m_temperatureUnit = UnitFactory::instance().createUnit("C").get(); |
| 175 | ✗ | } else if (temperatureUnit == "K") { | |
| 176 | ✗ | m_temperatureUnit = UnitFactory::instance().createUnit("K").get(); | |
| 177 | ✗ | } else if (temperatureUnit == "R") { | |
| 178 | ✗ | m_temperatureUnit = UnitFactory::instance().createUnit("R").get(); | |
| 179 | } else { | ||
| 180 | ✗ | LOG(Warn, "No recognized temperature unit specified, using C"); | |
| 181 | ✗ | m_temperatureUnit = UnitFactory::instance().createUnit("C").get(); | |
| 182 | } | ||
| 183 | |||
| 184 | // {Kilometers, Centimeters, Millimeters, Meters, Miles, Yards, Feet, Inches} | ||
| 185 | // JWD: the previous check was not great, this one is better, though still not exactly true to the schema | ||
| 186 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
84 | std::string lengthUnit{root.attribute("lengthUnit").value()}; |
| 187 |
3/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 28 times.
|
56 | if (istringEqual(lengthUnit, "Kilometers")) { |
| 188 | ✗ | m_nonBaseMultiplier = 1000.0; | |
| 189 | ✗ | m_lengthUnit = UnitFactory::instance().createUnit("m").get(); | |
| 190 |
3/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 28 times.
|
56 | } else if (istringEqual(lengthUnit, "Centimeters")) { |
| 191 | ✗ | m_nonBaseMultiplier = 1.0e-2; | |
| 192 | ✗ | m_lengthUnit = UnitFactory::instance().createUnit("m").get(); | |
| 193 |
3/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 28 times.
|
56 | } else if (istringEqual(lengthUnit, "Millimeters")) { |
| 194 | ✗ | m_nonBaseMultiplier = 1.0e-3; | |
| 195 | ✗ | m_lengthUnit = UnitFactory::instance().createUnit("K").get(); | |
| 196 |
4/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 18 times.
✓ Branch 8 taken 10 times.
|
56 | } else if (istringEqual(lengthUnit, "Meters")) { |
| 197 |
5/5✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 7 taken 18 times.
✓ Branch 10 taken 18 times.
✓ Branch 13 taken 18 times.
|
54 | m_lengthUnit = UnitFactory::instance().createUnit("m").get(); |
| 198 |
3/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 10 times.
|
20 | } else if (istringEqual(lengthUnit, "Miles")) { |
| 199 | ✗ | m_lengthUnit = UnitFactory::instance().createUnit("mi").get(); | |
| 200 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 9 times.
|
20 | } else if (istringEqual(lengthUnit, "Yards")) { |
| 201 | 1 | m_nonBaseMultiplier = 3.0; | |
| 202 |
5/5✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
|
3 | m_lengthUnit = UnitFactory::instance().createUnit("ft").get(); |
| 203 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
18 | } else if (istringEqual(lengthUnit, "Feet")) { |
| 204 |
5/5✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
|
27 | m_lengthUnit = UnitFactory::instance().createUnit("ft").get(); |
| 205 | ✗ | } else if (istringEqual(lengthUnit, "Inches")) { | |
| 206 | ✗ | m_lengthUnit = UnitFactory::instance().createUnit("in").get(); | |
| 207 | } else { | ||
| 208 | ✗ | LOG(Warn, "No length unit specified, using Meters"); | |
| 209 | ✗ | m_lengthUnit = UnitFactory::instance().createUnit("m").get(); | |
| 210 | } | ||
| 211 | |||
| 212 |
1/1✓ Branch 1 taken 28 times.
|
28 | Quantity unitLength(m_nonBaseMultiplier, m_lengthUnit); |
| 213 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
56 | Unit targetUnit = UnitFactory::instance().createUnit("m").get(); |
| 214 |
4/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
|
28 | m_lengthMultiplier = QuantityConverter::instance().convert(unitLength, targetUnit)->value(); |
| 215 | |||
| 216 | // {SquareKilometers, SquareMeters, SquareCentimeters, SquareMillimeters, SquareMiles, SquareYards, SquareFeet, SquareInches} | ||
| 217 | // TODO: still need some help with some units | ||
| 218 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | std::string areaUnit = root.attribute("areaUnit").value(); |
| 219 | |||
| 220 | // {CubicKilometers, CubicMeters, CubicCentimeters, CubicMillimeters, CubicMiles, CubicYards, CubicFeet, CubicInches} | ||
| 221 | // TODO: still need some help with some units | ||
| 222 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | std::string volumeUnit = root.attribute("volumeUnit").value(); |
| 223 | |||
| 224 | // {true, false} | ||
| 225 | 28 | m_useSIUnitsForResults = true; | |
| 226 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
84 | std::string useSIUnitsForResults{root.attribute("useSIUnitsForResults").value()}; |
| 227 |
4/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 22 times.
|
56 | if (istringEqual(useSIUnitsForResults, "False")) { |
| 228 | 6 | m_useSIUnitsForResults = false; | |
| 229 | } | ||
| 230 | |||
| 231 | // do materials before constructions | ||
| 232 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto materialElements = root.children("Material"); |
| 233 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 234 | ✗ | m_progressBar->setWindowTitle(toString("Translating Materials")); | |
| 235 | ✗ | m_progressBar->setMinimum(0); | |
| 236 | ✗ | m_progressBar->setMaximum((int)std::distance(materialElements.begin(), materialElements.end())); | |
| 237 | ✗ | m_progressBar->setValue(0); | |
| 238 | } | ||
| 239 | |||
| 240 |
5/5✓ Branch 3 taken 210 times.
✓ Branch 6 taken 210 times.
✓ Branch 9 taken 238 times.
✓ Branch 11 taken 210 times.
✓ Branch 12 taken 28 times.
|
238 | for (auto& materialElement : materialElements) { |
| 241 |
1/1✓ Branch 1 taken 210 times.
|
210 | boost::optional<model::ModelObject> material = translateMaterial(materialElement, model); |
| 242 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 210 times.
✗ Branch 4 not taken.
|
210 | OS_ASSERT(material); // Krishnan, what type of error handling do you want? |
| 243 | |||
| 244 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 210 times.
|
210 | if (m_progressBar) { |
| 245 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 246 | } | ||
| 247 | 210 | } | |
| 248 | |||
| 249 | // do constructions before surfaces | ||
| 250 | 28 | std::unordered_map<std::string, pugi::xml_node> layerElements; | |
| 251 |
6/6✓ Branch 1 taken 28 times.
✓ Branch 6 taken 201 times.
✓ Branch 9 taken 201 times.
✓ Branch 12 taken 229 times.
✓ Branch 14 taken 201 times.
✓ Branch 15 taken 28 times.
|
229 | for (auto& layerEl : root.children("Layer")) { |
| 252 |
3/3✓ Branch 1 taken 201 times.
✓ Branch 4 taken 201 times.
✓ Branch 7 taken 201 times.
|
201 | std::string layerId = layerEl.attribute("id").value(); |
| 253 | // Could maybe use some error checking here for empty IDs | ||
| 254 |
1/1✓ Branch 1 taken 201 times.
|
201 | layerElements[layerId] = layerEl; |
| 255 | 201 | } | |
| 256 | |||
| 257 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto constructionElements = root.children("Construction"); |
| 258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 259 | ✗ | m_progressBar->setWindowTitle(toString("Translating Constructions")); | |
| 260 | ✗ | m_progressBar->setMinimum(0); | |
| 261 | ✗ | m_progressBar->setMaximum((int)std::distance(constructionElements.begin(), constructionElements.end())); | |
| 262 | ✗ | m_progressBar->setValue(0); | |
| 263 | } | ||
| 264 | |||
| 265 |
5/5✓ Branch 3 taken 159 times.
✓ Branch 6 taken 159 times.
✓ Branch 9 taken 187 times.
✓ Branch 11 taken 159 times.
✓ Branch 12 taken 28 times.
|
187 | for (auto& constructionElement : constructionElements) { |
| 266 |
1/1✓ Branch 1 taken 159 times.
|
159 | boost::optional<model::ModelObject> construction = translateConstruction(constructionElement, layerElements, model); |
| 267 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 159 times.
✗ Branch 4 not taken.
|
159 | OS_ASSERT(construction); // Krishnan, what type of error handling do you want? |
| 268 | |||
| 269 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 159 times.
|
159 | if (m_progressBar) { |
| 270 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 271 | } | ||
| 272 | 159 | } | |
| 273 | |||
| 274 | // do window type before sub surfaces | ||
| 275 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto windowTypeElements = root.children("WindowType"); |
| 276 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 277 | ✗ | m_progressBar->setWindowTitle(toString("Translating Window Types")); | |
| 278 | ✗ | m_progressBar->setMinimum(0); | |
| 279 | ✗ | m_progressBar->setMaximum((int)std::distance(windowTypeElements.begin(), windowTypeElements.end())); | |
| 280 | ✗ | m_progressBar->setValue(0); | |
| 281 | } | ||
| 282 | |||
| 283 |
5/5✓ Branch 3 taken 38 times.
✓ Branch 6 taken 38 times.
✓ Branch 9 taken 66 times.
✓ Branch 11 taken 38 times.
✓ Branch 12 taken 28 times.
|
66 | for (auto& windowTypeElement : windowTypeElements) { |
| 284 |
1/1✓ Branch 1 taken 38 times.
|
38 | boost::optional<model::ModelObject> construction = translateWindowType(windowTypeElement, model); |
| 285 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 38 times.
✗ Branch 4 not taken.
|
38 | OS_ASSERT(construction); // Krishnan, what type of error handling do you want? |
| 286 | |||
| 287 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
|
38 | if (m_progressBar) { |
| 288 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 289 | } | ||
| 290 | 38 | } | |
| 291 | |||
| 292 | // do schedules before loads | ||
| 293 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto scheduleElements = root.children("Schedule"); |
| 294 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 295 | ✗ | m_progressBar->setWindowTitle(toString("Translating Schedules")); | |
| 296 | ✗ | m_progressBar->setMinimum(0); | |
| 297 | ✗ | m_progressBar->setMaximum((int)std::distance(scheduleElements.begin(), scheduleElements.end())); | |
| 298 | ✗ | m_progressBar->setValue(0); | |
| 299 | } | ||
| 300 | |||
| 301 |
5/5✓ Branch 3 taken 46 times.
✓ Branch 6 taken 46 times.
✓ Branch 9 taken 74 times.
✓ Branch 11 taken 46 times.
✓ Branch 12 taken 28 times.
|
74 | for (auto& scheduleElement : scheduleElements) { |
| 302 |
1/1✓ Branch 1 taken 46 times.
|
46 | boost::optional<model::ModelObject> schedule = translateSchedule(scheduleElement, root, model); |
| 303 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 4 not taken.
|
46 | OS_ASSERT(schedule); // Krishnan, what type of error handling do you want? |
| 304 | |||
| 305 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
|
46 | if (m_progressBar) { |
| 306 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 307 | } | ||
| 308 | 46 | } | |
| 309 | |||
| 310 | // do thermal zones before spaces | ||
| 311 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto zoneElements = root.children("Zone"); |
| 312 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 313 | ✗ | m_progressBar->setWindowTitle(toString("Translating Zones")); | |
| 314 | ✗ | m_progressBar->setMinimum(0); | |
| 315 | ✗ | m_progressBar->setMaximum((int)std::distance(zoneElements.begin(), zoneElements.end())); | |
| 316 | ✗ | m_progressBar->setValue(0); | |
| 317 | } | ||
| 318 | |||
| 319 |
5/5✓ Branch 3 taken 66 times.
✓ Branch 6 taken 66 times.
✓ Branch 9 taken 94 times.
✓ Branch 11 taken 66 times.
✓ Branch 12 taken 28 times.
|
94 | for (auto& zoneElement : zoneElements) { |
| 320 |
1/1✓ Branch 1 taken 66 times.
|
66 | boost::optional<model::ModelObject> zone = translateThermalZone(zoneElement, model); |
| 321 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 66 times.
✗ Branch 4 not taken.
|
66 | OS_ASSERT(zone); // Krishnan, what type of error handling do you want? |
| 322 | |||
| 323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
|
66 | if (m_progressBar) { |
| 324 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 325 | } | ||
| 326 | 66 | } | |
| 327 | |||
| 328 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto campusElement = root.child("Campus"); |
| 329 |
3/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 9 not taken.
|
28 | OS_ASSERT(campusElement.next_sibling("Campus").empty()); |
| 330 |
1/1✓ Branch 1 taken 28 times.
|
28 | boost::optional<model::ModelObject> facility = translateCampus(campusElement, model); |
| 331 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 4 not taken.
|
28 | OS_ASSERT(facility); // Krishnan, what type of error handling do you want? |
| 332 | |||
| 333 |
1/1✓ Branch 1 taken 28 times.
|
28 | model.setFastNaming(false); |
| 334 | |||
| 335 |
1/1✓ Branch 1 taken 28 times.
|
56 | return model; |
| 336 | 28 | } | |
| 337 | |||
| 338 | // A 'quick and dirty' method to find and correct surfaces that have incorrect orientations | ||
| 339 | // Checks the surface against the space bounding box | ||
| 340 | // If the surface is at or near the upper bound of the bounding box it should be a Roof/Ceiling | ||
| 341 | // If the surface is at or near the lower bound of the bounding box it should be a Floor | ||
| 342 | // Works only for spaces with 3D shapes that are prisms in the sense that they have only two | ||
| 343 | // levels where there are horizontal surfaces. | ||
| 344 | 28 | void ReverseTranslator::validateSpaceSurfaces(openstudio::model::Model& model) { | |
| 345 | |||
| 346 | 28 | double tol = 0.001; | |
| 347 | |||
| 348 |
1/1✓ Branch 1 taken 28 times.
|
28 | const auto& spaces = model.getConcreteModelObjects<openstudio::model::Space>(); |
| 349 |
2/2✓ Branch 5 taken 267 times.
✓ Branch 6 taken 28 times.
|
295 | for (const auto& space : spaces) { |
| 350 |
2/2✓ Branch 1 taken 267 times.
✓ Branch 4 taken 267 times.
|
267 | std::string spaceName = space.name().value(); |
| 351 | |||
| 352 |
1/1✓ Branch 1 taken 267 times.
|
267 | const auto& bounds = space.boundingBox(); |
| 353 |
1/1✓ Branch 1 taken 267 times.
|
267 | auto surfaces = space.surfaces(); |
| 354 |
2/2✓ Branch 5 taken 2838 times.
✓ Branch 6 taken 267 times.
|
3105 | for (auto& surface : surfaces) { |
| 355 |
1/1✓ Branch 1 taken 2838 times.
|
2838 | std::string surfType = surface.surfaceType(); |
| 356 |
2/2✓ Branch 1 taken 2838 times.
✓ Branch 4 taken 2838 times.
|
2838 | std::string surfName = surface.name().value(); |
| 357 | |||
| 358 | // Look for Roof or Floor surfaces that have adjacent surface (if there's no adjacwent surface | ||
| 359 | // then the spaces cannot be in the wrong order and the orientation would have already been fixed) | ||
| 360 |
1/1✓ Branch 1 taken 2838 times.
|
2838 | boost::optional<openstudio::model::Surface> adjacentSurf = surface.adjacentSurface(); |
| 361 |
10/10✓ Branch 1 taken 2838 times.
✓ Branch 3 taken 2408 times.
✓ Branch 4 taken 430 times.
✓ Branch 6 taken 2408 times.
✓ Branch 8 taken 392 times.
✓ Branch 9 taken 2016 times.
✓ Branch 10 taken 368 times.
✓ Branch 11 taken 454 times.
✓ Branch 12 taken 368 times.
✓ Branch 13 taken 2470 times.
|
3660 | if ((surfType == "RoofCeiling" || surfType == "Floor") && adjacentSurf) { |
| 362 |
1/1✓ Branch 1 taken 368 times.
|
368 | auto vertices = surface.vertices(); |
| 363 | |||
| 364 |
12/12✓ Branch 2 taken 368 times.
✓ Branch 5 taken 368 times.
✓ Branch 8 taken 368 times.
✓ Branch 11 taken 218 times.
✓ Branch 12 taken 150 times.
✓ Branch 15 taken 218 times.
✓ Branch 18 taken 218 times.
✓ Branch 21 taken 218 times.
✓ Branch 24 taken 54 times.
✓ Branch 25 taken 164 times.
✓ Branch 26 taken 54 times.
✓ Branch 27 taken 314 times.
|
368 | if (std::abs(vertices[0].z() - bounds.maxZ().value()) > tol && std::abs(vertices[0].z() - bounds.minZ().value()) > tol) { |
| 365 | |||
| 366 | // Log this because we cant do a face orientation check because the space | ||
| 367 | // isnt a prism (it has > 2 levels of horizontal surfaces) | ||
| 368 |
9/9✓ Branch 1 taken 54 times.
✓ Branch 4 taken 54 times.
✓ Branch 7 taken 54 times.
✓ Branch 10 taken 54 times.
✓ Branch 13 taken 54 times.
✓ Branch 16 taken 54 times.
✓ Branch 19 taken 54 times.
✓ Branch 22 taken 54 times.
✓ Branch 25 taken 54 times.
|
54 | LOG(Warn, "Skipping surface " << surfName << " of type " << surfType << " because it is not a prism"); |
| 369 | 54 | continue; | |
| 370 | 54 | } | |
| 371 | |||
| 372 |
5/5✓ Branch 2 taken 314 times.
✓ Branch 5 taken 314 times.
✓ Branch 8 taken 314 times.
✓ Branch 11 taken 150 times.
✓ Branch 12 taken 164 times.
|
314 | if (std::abs(vertices[0].z() - bounds.maxZ().value()) <= tol) { |
| 373 | |||
| 374 | // Surface is at the top of the space bounding box so it should be a roof/ceiling | ||
| 375 | // and the normal should be up (z should be > 0) | ||
| 376 |
1/1✓ Branch 1 taken 150 times.
|
150 | auto surfType = surface.surfaceType(); |
| 377 |
3/3✓ Branch 1 taken 150 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 93 times.
|
150 | if (surfType != "RoofCeiling") { |
| 378 | // Log changing surface type | ||
| 379 |
7/7✓ Branch 1 taken 57 times.
✓ Branch 4 taken 57 times.
✓ Branch 7 taken 57 times.
✓ Branch 10 taken 57 times.
✓ Branch 13 taken 57 times.
✓ Branch 16 taken 57 times.
✓ Branch 19 taken 57 times.
|
57 | LOG(Warn, "Changing surface type from " << surfType << " to RoofCeiling. Surface vertices elevation is above the space."); |
| 380 |
2/2✓ Branch 1 taken 57 times.
✓ Branch 4 taken 57 times.
|
114 | surface.setSurfaceType("RoofCeiling"); |
| 381 | } | ||
| 382 |
1/1✓ Branch 1 taken 150 times.
|
150 | const auto& normal = surface.outwardNormal(); |
| 383 |
3/3✓ Branch 1 taken 150 times.
✓ Branch 3 taken 57 times.
✓ Branch 4 taken 93 times.
|
150 | if (normal.z() < 0) { |
| 384 | // Log reversing surface | ||
| 385 |
5/5✓ Branch 1 taken 57 times.
✓ Branch 4 taken 57 times.
✓ Branch 7 taken 57 times.
✓ Branch 10 taken 57 times.
✓ Branch 13 taken 57 times.
|
57 | LOG(Warn, "Reversing surface orientation because surface is a RoofCeiling but the surface is oriented down."); |
| 386 |
1/1✓ Branch 3 taken 57 times.
|
57 | std::reverse(vertices.begin(), vertices.end()); |
| 387 |
1/1✓ Branch 1 taken 57 times.
|
57 | surface.setVertices(vertices); |
| 388 | } | ||
| 389 |
4/5✓ Branch 4 taken 164 times.
✓ Branch 7 taken 164 times.
✓ Branch 10 taken 164 times.
✓ Branch 13 taken 164 times.
✗ Branch 14 not taken.
|
314 | } else if (std::abs(vertices[0].z() - bounds.minZ().value()) <= tol) { |
| 390 | |||
| 391 | // Surface is at the bottom of the space's bounding box and so should be a floor | ||
| 392 | // and the normal shuld be down (z < 0) | ||
| 393 |
1/1✓ Branch 1 taken 164 times.
|
164 | auto surfType = surface.surfaceType(); |
| 394 |
3/3✓ Branch 1 taken 164 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 95 times.
|
164 | if (surfType != "Floor") { |
| 395 | // Log changing surface type | ||
| 396 |
2/2✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
|
138 | surface.setSurfaceType("Floor"); |
| 397 | } | ||
| 398 |
1/1✓ Branch 1 taken 164 times.
|
164 | const auto& normal = surface.outwardNormal(); |
| 399 |
3/3✓ Branch 1 taken 164 times.
✓ Branch 3 taken 69 times.
✓ Branch 4 taken 95 times.
|
164 | if (normal.z() > 0) { |
| 400 | // Log reversing surface | ||
| 401 |
5/5✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
✓ Branch 7 taken 69 times.
✓ Branch 10 taken 69 times.
✓ Branch 13 taken 69 times.
|
69 | LOG(Warn, "Reversing surface orientation because surface is a Floor but the surface is oriented up."); |
| 402 |
1/1✓ Branch 3 taken 69 times.
|
69 | std::reverse(vertices.begin(), vertices.end()); |
| 403 |
1/1✓ Branch 1 taken 69 times.
|
69 | surface.setVertices(vertices); |
| 404 | } | ||
| 405 | 164 | } | |
| 406 | 368 | } | |
| 407 | 2946 | } | |
| 408 | 267 | } | |
| 409 | 28 | } | |
| 410 | |||
| 411 | 28 | boost::optional<model::ModelObject> ReverseTranslator::translateCampus(const pugi::xml_node& element, openstudio::model::Model& model) { | |
| 412 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto facility = model.getUniqueModelObject<openstudio::model::Facility>(); |
| 413 | |||
| 414 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto buildingElement = element.child("Building"); |
| 415 |
3/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 9 not taken.
|
28 | OS_ASSERT(buildingElement.next_sibling("Building").empty()); |
| 416 | |||
| 417 |
1/1✓ Branch 1 taken 28 times.
|
28 | boost::optional<model::ModelObject> building = translateBuilding(buildingElement, model); |
| 418 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 4 not taken.
|
28 | OS_ASSERT(building); |
| 419 | |||
| 420 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto surfaceElements = element.children("Surface"); |
| 421 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 422 | ✗ | m_progressBar->setWindowTitle(toString("Translating Surfaces")); | |
| 423 | ✗ | m_progressBar->setMinimum(0); | |
| 424 | ✗ | m_progressBar->setMaximum((int)std::distance(surfaceElements.begin(), surfaceElements.end())); | |
| 425 | ✗ | m_progressBar->setValue(0); | |
| 426 | } | ||
| 427 | |||
| 428 |
5/5✓ Branch 3 taken 2923 times.
✓ Branch 6 taken 2923 times.
✓ Branch 9 taken 2951 times.
✓ Branch 11 taken 2923 times.
✓ Branch 12 taken 28 times.
|
2951 | for (auto& surfEl : surfaceElements) { |
| 429 | try { | ||
| 430 |
1/1✓ Branch 1 taken 2923 times.
|
2923 | boost::optional<model::ModelObject> surface = translateSurface(surfEl, model); |
| 431 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
2923 | } catch (const std::exception&) { |
| 432 | ✗ | LOG(Error, "Could not translate surface " << surfEl); | |
| 433 | ✗ | } | |
| 434 | |||
| 435 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2923 times.
|
2923 | if (m_progressBar) { |
| 436 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 437 | } | ||
| 438 | } | ||
| 439 | |||
| 440 |
1/1✓ Branch 1 taken 28 times.
|
28 | validateSpaceSurfaces(model); |
| 441 |
1/1✓ Branch 1 taken 28 times.
|
56 | return facility; |
| 442 | 28 | } | |
| 443 | |||
| 444 | 28 | boost::optional<model::ModelObject> ReverseTranslator::translateBuilding(const pugi::xml_node& element, openstudio::model::Model& model) { | |
| 445 |
1/1✓ Branch 1 taken 28 times.
|
28 | openstudio::model::Building building = model.getUniqueModelObject<openstudio::model::Building>(); |
| 446 | |||
| 447 |
1/1✓ Branch 1 taken 28 times.
|
28 | translateId(element, building); |
| 448 |
1/1✓ Branch 1 taken 28 times.
|
28 | translateName(element, building); |
| 449 | |||
| 450 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto storyElements = element.children("BuildingStorey"); |
| 451 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 452 | ✗ | m_progressBar->setWindowTitle(toString("Translating Building Stories")); | |
| 453 | ✗ | m_progressBar->setMinimum(0); | |
| 454 | ✗ | m_progressBar->setMaximum((int)std::distance(storyElements.begin(), storyElements.end())); | |
| 455 | ✗ | m_progressBar->setValue(0); | |
| 456 | } | ||
| 457 | |||
| 458 |
5/5✓ Branch 3 taken 43 times.
✓ Branch 6 taken 43 times.
✓ Branch 9 taken 71 times.
✓ Branch 11 taken 43 times.
✓ Branch 12 taken 28 times.
|
71 | for (auto& storyEl : storyElements) { |
| 459 |
1/1✓ Branch 1 taken 43 times.
|
43 | boost::optional<model::ModelObject> story = translateBuildingStory(storyEl, model); |
| 460 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 43 times.
✗ Branch 4 not taken.
|
43 | OS_ASSERT(story); |
| 461 | |||
| 462 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
|
43 | if (m_progressBar) { |
| 463 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 464 | } | ||
| 465 | 43 | } | |
| 466 | |||
| 467 |
1/1✓ Branch 1 taken 28 times.
|
28 | auto spaceElements = element.children("Space"); |
| 468 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | if (m_progressBar) { |
| 469 | ✗ | m_progressBar->setWindowTitle(toString("Translating Spaces")); | |
| 470 | ✗ | m_progressBar->setMinimum(0); | |
| 471 | ✗ | m_progressBar->setMaximum((int)std::distance(spaceElements.begin(), spaceElements.end())); | |
| 472 | ✗ | m_progressBar->setValue(0); | |
| 473 | } | ||
| 474 | |||
| 475 |
5/5✓ Branch 3 taken 267 times.
✓ Branch 6 taken 267 times.
✓ Branch 9 taken 295 times.
✓ Branch 11 taken 267 times.
✓ Branch 12 taken 28 times.
|
295 | for (auto& spaceEl : spaceElements) { |
| 476 |
1/1✓ Branch 1 taken 267 times.
|
267 | boost::optional<model::ModelObject> space = translateSpace(spaceEl, model); |
| 477 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 267 times.
✗ Branch 4 not taken.
|
267 | OS_ASSERT(space); |
| 478 | |||
| 479 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 267 times.
|
267 | if (m_progressBar) { |
| 480 | ✗ | m_progressBar->setValue(m_progressBar->value() + 1); | |
| 481 | } | ||
| 482 | 267 | } | |
| 483 | |||
| 484 |
1/1✓ Branch 1 taken 28 times.
|
56 | return building; |
| 485 | 28 | } | |
| 486 | |||
| 487 | 43 | boost::optional<model::ModelObject> ReverseTranslator::translateBuildingStory(const pugi::xml_node& element, openstudio::model::Model& model) { | |
| 488 |
1/1✓ Branch 1 taken 43 times.
|
43 | openstudio::model::BuildingStory story(model); |
| 489 | |||
| 490 |
1/1✓ Branch 1 taken 43 times.
|
43 | translateId(element, story); |
| 491 |
1/1✓ Branch 1 taken 43 times.
|
43 | translateName(element, story); |
| 492 | |||
| 493 | // DLM: we need to better support separate name from id in this translator | ||
| 494 | |||
| 495 | // DLM: todo, translate Level | ||
| 496 | |||
| 497 |
1/1✓ Branch 1 taken 43 times.
|
86 | return story; |
| 498 | 43 | } | |
| 499 | |||
| 500 | 66 | boost::optional<model::ModelObject> ReverseTranslator::translateThermalZone(const pugi::xml_node& element, openstudio::model::Model& model) { | |
| 501 |
1/1✓ Branch 1 taken 66 times.
|
66 | openstudio::model::ThermalZone zone(model); |
| 502 | |||
| 503 |
1/1✓ Branch 1 taken 66 times.
|
66 | translateId(element, zone); |
| 504 |
1/1✓ Branch 1 taken 66 times.
|
66 | translateName(element, zone); |
| 505 | |||
| 506 | // DLM: todo, translate setpoints | ||
| 507 | |||
| 508 | // import CADObjectId | ||
| 509 |
5/5✓ Branch 1 taken 66 times.
✓ Branch 6 taken 51 times.
✓ Branch 9 taken 66 times.
✓ Branch 11 taken 51 times.
✓ Branch 12 taken 15 times.
|
66 | for (auto& cadObjectId : element.children("CADObjectId")) { |
| 510 | // TODO: import multiple CADObjectIds | ||
| 511 |
1/1✓ Branch 1 taken 51 times.
|
51 | translateCADObjectId(cadObjectId, zone); |
| 512 | |||
| 513 | 51 | break; // TODO: import multiple CADObjectIds | |
| 514 | } | ||
| 515 | |||
| 516 |
1/1✓ Branch 1 taken 66 times.
|
132 | return zone; |
| 517 | 66 | } | |
| 518 | |||
| 519 | 267 | boost::optional<model::ModelObject> ReverseTranslator::translateSpace(const pugi::xml_node& element, openstudio::model::Model& model) { | |
| 520 |
1/1✓ Branch 1 taken 267 times.
|
267 | openstudio::model::Space space(model); |
| 521 | |||
| 522 |
1/1✓ Branch 1 taken 267 times.
|
267 | translateId(element, space); |
| 523 |
1/1✓ Branch 1 taken 267 times.
|
267 | translateName(element, space); |
| 524 | |||
| 525 | //DLM: we should be using a map of id to model object to get this, not relying on name | ||
| 526 |
3/3✓ Branch 1 taken 267 times.
✓ Branch 4 taken 267 times.
✓ Branch 7 taken 267 times.
|
267 | std::string storyId = element.attribute("buildingStoreyIdRef").value(); |
| 527 |
1/1✓ Branch 1 taken 267 times.
|
267 | auto storyIt = m_idToObjectMap.find(storyId); |
| 528 |
2/2✓ Branch 2 taken 211 times.
✓ Branch 3 taken 56 times.
|
267 | if (storyIt != m_idToObjectMap.end()) { |
| 529 |
1/1✓ Branch 2 taken 211 times.
|
211 | boost::optional<model::BuildingStory> story = storyIt->second.optionalCast<model::BuildingStory>(); |
| 530 |
1/2✓ Branch 0 taken 211 times.
✗ Branch 1 not taken.
|
211 | if (story) { |
| 531 |
2/2✓ Branch 1 taken 211 times.
✓ Branch 4 taken 211 times.
|
211 | space.setBuildingStory(*story); |
| 532 | } | ||
| 533 | 211 | } | |
| 534 | |||
| 535 | // if space doesn't have story assigned should we warn the user? | ||
| 536 | |||
| 537 |
3/3✓ Branch 1 taken 267 times.
✓ Branch 4 taken 267 times.
✓ Branch 7 taken 267 times.
|
267 | std::string zoneId = element.attribute("zoneIdRef").value(); |
| 538 |
1/1✓ Branch 1 taken 267 times.
|
267 | auto zoneIt = m_idToObjectMap.find(zoneId); |
| 539 |
2/2✓ Branch 2 taken 215 times.
✓ Branch 3 taken 52 times.
|
267 | if (zoneIt != m_idToObjectMap.end()) { |
| 540 |
1/1✓ Branch 2 taken 215 times.
|
215 | boost::optional<model::ThermalZone> thermalZone = zoneIt->second.optionalCast<model::ThermalZone>(); |
| 541 |
1/2✓ Branch 0 taken 215 times.
✗ Branch 1 not taken.
|
215 | if (thermalZone) { |
| 542 |
2/2✓ Branch 1 taken 215 times.
✓ Branch 4 taken 215 times.
|
215 | space.setThermalZone(*thermalZone); |
| 543 | } | ||
| 544 | 215 | } | |
| 545 | |||
| 546 |
3/3✓ Branch 1 taken 267 times.
✓ Branch 5 taken 52 times.
✓ Branch 6 taken 215 times.
|
267 | if (!space.thermalZone()) { |
| 547 | // DLM: may want to revisit this | ||
| 548 | // create a new thermal zone if none assigned | ||
| 549 |
1/1✓ Branch 1 taken 52 times.
|
52 | openstudio::model::ThermalZone thermalZone(model); |
| 550 |
3/3✓ Branch 1 taken 52 times.
✓ Branch 4 taken 52 times.
✓ Branch 7 taken 52 times.
|
52 | std::string id = element.attribute("id").value(); |
| 551 |
4/4✓ Branch 1 taken 52 times.
✓ Branch 4 taken 52 times.
✓ Branch 7 taken 52 times.
✓ Branch 10 taken 52 times.
|
52 | std::string name = element.child("Name").text().as_string(); |
| 552 |
2/2✓ Branch 1 taken 52 times.
✓ Branch 4 taken 52 times.
|
52 | thermalZone.setName(id + " ThermalZone"); |
| 553 |
4/4✓ Branch 1 taken 52 times.
✓ Branch 4 taken 52 times.
✓ Branch 7 taken 52 times.
✓ Branch 10 taken 52 times.
|
156 | thermalZone.additionalProperties().setFeature("gbXMLId", id + " Thermal Zone"); |
| 554 |
4/4✓ Branch 1 taken 52 times.
✓ Branch 4 taken 52 times.
✓ Branch 7 taken 52 times.
✓ Branch 10 taken 52 times.
|
156 | thermalZone.additionalProperties().setFeature("displayName", name + " Thermal Zone"); |
| 555 |
1/1✓ Branch 1 taken 52 times.
|
52 | space.setThermalZone(thermalZone); |
| 556 | 52 | } | |
| 557 | |||
| 558 | // create a stub space type | ||
| 559 | // DLM: is this better than nothing? | ||
| 560 |
3/3✓ Branch 1 taken 267 times.
✓ Branch 4 taken 267 times.
✓ Branch 7 taken 267 times.
|
267 | std::string spaceTypeId = element.attribute("spaceType").value(); |
| 561 |
2/2✓ Branch 1 taken 41 times.
✓ Branch 2 taken 226 times.
|
267 | if (!spaceTypeId.empty()) { |
| 562 |
1/1✓ Branch 1 taken 41 times.
|
41 | auto spaceTypeIt = m_idToObjectMap.find(spaceTypeId); |
| 563 | |||
| 564 |
2/2✓ Branch 2 taken 12 times.
✓ Branch 3 taken 29 times.
|
41 | if (spaceTypeIt == m_idToObjectMap.end()) { |
| 565 |
1/1✓ Branch 1 taken 12 times.
|
12 | model::SpaceType spaceType(model); |
| 566 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | spaceType.setName(escapeName(spaceTypeId, spaceTypeId)); |
| 567 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 6 taken 12 times.
|
12 | spaceTypeIt = m_idToObjectMap.insert(m_idToObjectMap.end(), std::make_pair(spaceTypeId, spaceType)); |
| 568 | 12 | } | |
| 569 | |||
| 570 |
1/1✓ Branch 2 taken 41 times.
|
41 | boost::optional<model::SpaceType> spaceType = spaceTypeIt->second.optionalCast<model::SpaceType>(); |
| 571 |
1/2✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
|
41 | if (spaceType) { |
| 572 |
2/2✓ Branch 1 taken 41 times.
✓ Branch 4 taken 41 times.
|
41 | space.setSpaceType(*spaceType); |
| 573 | } | ||
| 574 | 41 | } | |
| 575 | |||
| 576 | // import CADObjectId | ||
| 577 |
5/5✓ Branch 1 taken 267 times.
✓ Branch 6 taken 202 times.
✓ Branch 9 taken 267 times.
✓ Branch 11 taken 202 times.
✓ Branch 12 taken 65 times.
|
267 | for (auto& cadObjectId : element.children("CADObjectId")) { |
| 578 | // TODO: import multiple CADObjectIds | ||
| 579 |
1/1✓ Branch 1 taken 202 times.
|
202 | translateCADObjectId(cadObjectId, space); |
| 580 | |||
| 581 | 202 | break; // TODO: import multiple CADObjectIds | |
| 582 | } | ||
| 583 | |||
| 584 | // import Volume | ||
| 585 |
2/2✓ Branch 1 taken 267 times.
✓ Branch 4 taken 267 times.
|
267 | auto volume = element.child("Volume").text(); |
| 586 |
3/3✓ Branch 1 taken 267 times.
✓ Branch 3 taken 255 times.
✓ Branch 4 taken 12 times.
|
267 | if (!volume.empty()) { |
| 587 |
2/2✓ Branch 1 taken 255 times.
✓ Branch 4 taken 255 times.
|
255 | space.setVolume(volume.as_double()); |
| 588 | } | ||
| 589 | |||
| 590 |
1/1✓ Branch 1 taken 267 times.
|
534 | return space; |
| 591 | 267 | } | |
| 592 | |||
| 593 | 2923 | boost::optional<model::ModelObject> ReverseTranslator::translateSurface(const pugi::xml_node& element, openstudio::model::Model& model) { | |
| 594 | 2923 | boost::optional<model::ModelObject> result; | |
| 595 | 2923 | std::vector<openstudio::Point3d> vertices; | |
| 596 | |||
| 597 |
1/1✓ Branch 1 taken 2923 times.
|
2923 | auto planarGeometryElement = element.child("PlanarGeometry"); |
| 598 |
1/1✓ Branch 1 taken 2923 times.
|
2923 | auto polyLoopElement = planarGeometryElement.child("PolyLoop"); |
| 599 |
1/1✓ Branch 1 taken 2923 times.
|
2923 | auto cartesianPointElements = polyLoopElement.children("CartesianPoint"); |
| 600 | |||
| 601 |
5/5✓ Branch 3 taken 13193 times.
✓ Branch 6 taken 13193 times.
✓ Branch 9 taken 16116 times.
✓ Branch 11 taken 13193 times.
✓ Branch 12 taken 2923 times.
|
16116 | for (auto& cart_el : cartesianPointElements) { |
| 602 |
1/1✓ Branch 1 taken 13193 times.
|
13193 | auto coordinateElements = cart_el.children("Coordinate"); |
| 603 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 13193 times.
✗ Branch 5 not taken.
|
26386 | OS_ASSERT(std::distance(coordinateElements.begin(), coordinateElements.end()) == 3); |
| 604 | |||
| 605 | /* Calling these conversions every time is unnecessarily slow | ||
| 606 | |||
| 607 | Unit targetUnit = UnitFactory::instance().createUnit("m").get(); | ||
| 608 | Quantity xQuantity(coordinateElements.at(0).toElement().text().toDouble(), m_lengthUnit); | ||
| 609 | Quantity yQuantity(coordinateElements.at(1).toElement().text().toDouble(), m_lengthUnit); | ||
| 610 | Quantity zQuantity(coordinateElements.at(2).toElement().text().toDouble(), m_lengthUnit); | ||
| 611 | |||
| 612 | double x = QuantityConverter::instance().convert(xQuantity, targetUnit)->value(); | ||
| 613 | double y = QuantityConverter::instance().convert(yQuantity, targetUnit)->value(); | ||
| 614 | double z = QuantityConverter::instance().convert(zQuantity, targetUnit)->value(); | ||
| 615 | */ | ||
| 616 | |||
| 617 | 13193 | std::array<double, 3> coords{{0.0, 0.0, 0.0}}; | |
| 618 | 13193 | size_t i{0}; | |
| 619 |
4/5✓ Branch 3 taken 39579 times.
✓ Branch 6 taken 26386 times.
✓ Branch 9 taken 39579 times.
✓ Branch 11 taken 39579 times.
✗ Branch 12 not taken.
|
39579 | for (auto& el : coordinateElements) { |
| 620 |
2/2✓ Branch 1 taken 39579 times.
✓ Branch 4 taken 39579 times.
|
39579 | coords[i] = m_lengthMultiplier * el.text().as_double(); |
| 621 | 39579 | ++i; | |
| 622 |
2/2✓ Branch 0 taken 13193 times.
✓ Branch 1 taken 26386 times.
|
39579 | if (i == 3) { |
| 623 | 13193 | break; | |
| 624 | } | ||
| 625 | } | ||
| 626 | |||
| 627 |
1/1✓ Branch 4 taken 13193 times.
|
13193 | vertices.emplace_back(coords[0], coords[1], coords[2]); |
| 628 | } | ||
| 629 | |||
| 630 |
3/3✓ Branch 1 taken 2923 times.
✓ Branch 4 taken 2923 times.
✓ Branch 7 taken 2923 times.
|
2923 | std::string surfaceType = element.attribute("surfaceType").value(); |
| 631 |
2/2✓ Branch 1 taken 553 times.
✓ Branch 2 taken 2370 times.
|
2923 | if (surfaceType.find("Shade") != std::string::npos) { |
| 632 | |||
| 633 |
1/1✓ Branch 1 taken 553 times.
|
553 | openstudio::model::ShadingSurface shadingSurface(vertices, model); |
| 634 | |||
| 635 |
1/1✓ Branch 1 taken 553 times.
|
553 | translateId(element, shadingSurface); |
| 636 |
1/1✓ Branch 1 taken 553 times.
|
553 | translateName(element, shadingSurface); |
| 637 | |||
| 638 |
1/1✓ Branch 1 taken 553 times.
|
553 | openstudio::model::Building building = model.getUniqueModelObject<openstudio::model::Building>(); |
| 639 | |||
| 640 |
1/1✓ Branch 1 taken 553 times.
|
553 | std::vector<openstudio::model::ShadingSurfaceGroup> shadingSurfaceGroups = building.shadingSurfaceGroups(); |
| 641 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 2 taken 537 times.
|
553 | if (shadingSurfaceGroups.empty()) { |
| 642 |
1/1✓ Branch 1 taken 16 times.
|
16 | openstudio::model::ShadingSurfaceGroup shadingSurfaceGroup(model); |
| 643 |
1/1✓ Branch 1 taken 16 times.
|
16 | shadingSurface.setShadingSurfaceGroup(shadingSurfaceGroup); |
| 644 | 16 | } else { | |
| 645 |
1/1✓ Branch 2 taken 537 times.
|
537 | shadingSurface.setShadingSurfaceGroup(shadingSurfaceGroups[0]); |
| 646 | } | ||
| 647 | |||
| 648 |
1/1✓ Branch 1 taken 553 times.
|
553 | result = shadingSurface; |
| 649 | |||
| 650 |
3/6✓ Branch 4 taken 2370 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2370 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2370 times.
|
2923 | } else if ((surfaceType.find("FreestandingColumn") != std::string::npos) || (surfaceType.find("EmbeddedColumn") != std::string::npos)) { |
| 651 | |||
| 652 | // do not handle these | ||
| 653 | ✗ | return boost::none; | |
| 654 | |||
| 655 | } else { | ||
| 656 | |||
| 657 | // The rest of the function wants array-type access to the elements, so create that | ||
| 658 | 2370 | std::vector<pugi::xml_node> adjacentSpaceElements; | |
| 659 |
6/6✓ Branch 1 taken 2370 times.
✓ Branch 6 taken 3446 times.
✓ Branch 9 taken 3446 times.
✓ Branch 12 taken 5816 times.
✓ Branch 14 taken 3446 times.
✓ Branch 15 taken 2370 times.
|
5816 | for (auto& adj : element.children("AdjacentSpaceId")) { |
| 660 |
1/1✓ Branch 1 taken 3446 times.
|
3446 | adjacentSpaceElements.push_back(adj); |
| 661 | } | ||
| 662 | |||
| 663 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 2370 times.
|
2370 | if (adjacentSpaceElements.empty()) { |
| 664 | ✗ | LOG(Warn, "Surface has no adjacent spaces, will not be translated."); | |
| 665 | ✗ | return boost::none; | |
| 666 |
2/2✓ Branch 1 taken 1076 times.
✓ Branch 2 taken 1294 times.
|
2370 | } else if (adjacentSpaceElements.size() == 2) { |
| 667 |
4/4✓ Branch 1 taken 1076 times.
✓ Branch 4 taken 1076 times.
✓ Branch 7 taken 1076 times.
✓ Branch 10 taken 1076 times.
|
1076 | std::string spaceId1 = adjacentSpaceElements.at(0).attribute("spaceIdRef").value(); |
| 668 |
4/4✓ Branch 1 taken 1076 times.
✓ Branch 4 taken 1076 times.
✓ Branch 7 taken 1076 times.
✓ Branch 10 taken 1076 times.
|
1076 | std::string spaceId2 = adjacentSpaceElements.at(1).attribute("spaceIdRef").value(); |
| 669 |
2/2✓ Branch 1 taken 300 times.
✓ Branch 2 taken 776 times.
|
1076 | if (spaceId1 == spaceId2) { |
| 670 |
7/7✓ Branch 1 taken 300 times.
✓ Branch 4 taken 300 times.
✓ Branch 7 taken 300 times.
✓ Branch 10 taken 300 times.
✓ Branch 13 taken 300 times.
✓ Branch 16 taken 300 times.
✓ Branch 19 taken 300 times.
|
300 | LOG(Warn, "Surface has two adjacent spaces which are the same space '" << spaceId2 << "', will not be translated."); |
| 671 | 300 | return boost::none; | |
| 672 | } | ||
| 673 |
5/6✓ Branch 1 taken 776 times.
✓ Branch 2 taken 300 times.
✓ Branch 4 taken 776 times.
✓ Branch 5 taken 300 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1294 times.
|
2670 | } else if (adjacentSpaceElements.size() > 2) { |
| 674 | ✗ | LOG(Error, "Surface has more than 2 adjacent surfaces, will not be translated."); | |
| 675 | ✗ | return boost::none; | |
| 676 | } | ||
| 677 | |||
| 678 |
1/1✓ Branch 1 taken 2070 times.
|
2070 | openstudio::model::Surface surface(vertices, model); |
| 679 | |||
| 680 |
1/1✓ Branch 1 taken 2070 times.
|
2070 | translateId(element, surface); |
| 681 |
1/1✓ Branch 1 taken 2070 times.
|
2070 | translateName(element, surface); |
| 682 | |||
| 683 |
3/3✓ Branch 1 taken 2070 times.
✓ Branch 4 taken 2070 times.
✓ Branch 7 taken 2070 times.
|
2070 | std::string exposedToSun = element.attribute("exposedToSun").value(); |
| 684 | |||
| 685 | // set surface type | ||
| 686 | // wall types | ||
| 687 |
2/2✓ Branch 1 taken 780 times.
✓ Branch 2 taken 1290 times.
|
2070 | if (surfaceType.find("ExteriorWall") != std::string::npos) { |
| 688 |
2/2✓ Branch 1 taken 780 times.
✓ Branch 4 taken 780 times.
|
1560 | surface.setSurfaceType("Wall"); |
| 689 |
2/2✓ Branch 1 taken 562 times.
✓ Branch 2 taken 728 times.
|
1290 | } else if (surfaceType.find("InteriorWall") != std::string::npos) { |
| 690 |
2/2✓ Branch 1 taken 562 times.
✓ Branch 4 taken 562 times.
|
1124 | surface.setSurfaceType("Wall"); |
| 691 |
2/2✓ Branch 1 taken 57 times.
✓ Branch 2 taken 671 times.
|
728 | } else if (surfaceType.find("UndergroundWall") != std::string::npos) { |
| 692 |
2/2✓ Branch 1 taken 57 times.
✓ Branch 4 taken 57 times.
|
114 | surface.setSurfaceType("Wall"); |
| 693 | // roof types | ||
| 694 |
2/2✓ Branch 1 taken 246 times.
✓ Branch 2 taken 425 times.
|
671 | } else if (surfaceType.find("Roof") != std::string::npos) { |
| 695 |
2/2✓ Branch 1 taken 246 times.
✓ Branch 4 taken 246 times.
|
492 | surface.setSurfaceType("RoofCeiling"); |
| 696 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 2 taken 403 times.
|
425 | } else if (surfaceType.find("Ceiling") != std::string::npos) { |
| 697 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
44 | surface.setSurfaceType("RoofCeiling"); |
| 698 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 403 times.
|
403 | } else if (surfaceType.find("UndergroundCeiling") != std::string::npos) { |
| 699 | ✗ | surface.setSurfaceType("RoofCeiling"); | |
| 700 | // floor types | ||
| 701 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 2 taken 364 times.
|
403 | } else if (surfaceType.find("UndergroundSlab") != std::string::npos) { |
| 702 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
78 | surface.setSurfaceType("Floor"); |
| 703 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 2 taken 313 times.
|
364 | } else if (surfaceType.find("SlabOnGrade") != std::string::npos) { |
| 704 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
|
102 | surface.setSurfaceType("Floor"); |
| 705 |
2/2✓ Branch 1 taken 152 times.
✓ Branch 2 taken 161 times.
|
313 | } else if (surfaceType.find("InteriorFloor") != std::string::npos) { |
| 706 |
2/2✓ Branch 1 taken 152 times.
✓ Branch 4 taken 152 times.
|
304 | surface.setSurfaceType("Floor"); |
| 707 |
2/2✓ Branch 1 taken 119 times.
✓ Branch 2 taken 42 times.
|
161 | } else if (surfaceType.find("RaisedFloor") != std::string::npos) { |
| 708 |
2/2✓ Branch 1 taken 119 times.
✓ Branch 4 taken 119 times.
|
238 | surface.setSurfaceType("Floor"); |
| 709 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
|
42 | } else if (surfaceType.find("ExposedFloor") != std::string::npos) { |
| 710 | ✗ | surface.setSurfaceType("Floor"); | |
| 711 | 42 | } else if (surfaceType.find("Air") != std::string::npos) { | |
| 712 | // this type can be wall, roof, or floor. just use default surface type based on vertices. | ||
| 713 | } | ||
| 714 | |||
| 715 | // set boundary conditions | ||
| 716 |
2/2✓ Branch 1 taken 736 times.
✓ Branch 2 taken 1334 times.
|
2070 | if (exposedToSun.find("true") != std::string::npos) { |
| 717 |
2/2✓ Branch 1 taken 736 times.
✓ Branch 4 taken 736 times.
|
1472 | surface.setOutsideBoundaryCondition("Outdoors"); |
| 718 |
2/2✓ Branch 1 taken 736 times.
✓ Branch 4 taken 736 times.
|
1472 | surface.setSunExposure("SunExposed"); |
| 719 |
2/2✓ Branch 1 taken 736 times.
✓ Branch 4 taken 736 times.
|
1472 | surface.setWindExposure("WindExposed"); |
| 720 |
2/2✓ Branch 1 taken 714 times.
✓ Branch 2 taken 620 times.
|
1334 | } else if (surfaceType.find("Interior") != std::string::npos) { |
| 721 |
2/2✓ Branch 1 taken 714 times.
✓ Branch 4 taken 714 times.
|
1428 | surface.setOutsideBoundaryCondition("Adiabatic"); |
| 722 |
2/2✓ Branch 1 taken 714 times.
✓ Branch 4 taken 714 times.
|
1428 | surface.setSunExposure("NoSun"); |
| 723 |
2/2✓ Branch 1 taken 714 times.
✓ Branch 4 taken 714 times.
|
1428 | surface.setWindExposure("NoWind"); |
| 724 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 2 taken 598 times.
|
620 | } else if (surfaceType.find("Ceiling") != std::string::npos) { |
| 725 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
44 | surface.setOutsideBoundaryCondition("Adiabatic"); |
| 726 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
44 | surface.setSunExposure("NoSun"); |
| 727 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
44 | surface.setWindExposure("NoWind"); |
| 728 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 2 taken 547 times.
|
598 | } else if (surfaceType.find("SlabOnGrade") != std::string::npos) { |
| 729 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
|
102 | surface.setOutsideBoundaryCondition("Ground"); |
| 730 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
|
102 | surface.setSunExposure("NoSun"); |
| 731 |
2/2✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
|
102 | surface.setWindExposure("NoWind"); |
| 732 |
2/2✓ Branch 1 taken 96 times.
✓ Branch 2 taken 451 times.
|
547 | } else if (surfaceType.find("Underground") != std::string::npos) { |
| 733 |
2/2✓ Branch 1 taken 96 times.
✓ Branch 4 taken 96 times.
|
192 | surface.setOutsideBoundaryCondition("Ground"); |
| 734 |
2/2✓ Branch 1 taken 96 times.
✓ Branch 4 taken 96 times.
|
192 | surface.setSunExposure("NoSun"); |
| 735 |
2/2✓ Branch 1 taken 96 times.
✓ Branch 4 taken 96 times.
|
192 | surface.setWindExposure("NoWind"); |
| 736 | } | ||
| 737 | |||
| 738 |
1/1✓ Branch 1 taken 2070 times.
|
2070 | result = surface; |
| 739 | |||
| 740 | // if air wall | ||
| 741 |
2/2✓ Branch 1 taken 42 times.
✓ Branch 2 taken 2028 times.
|
2070 | if (surfaceType.find("Air") != std::string::npos) { |
| 742 | 42 | boost::optional<model::ConstructionAirBoundary> airWall; | |
| 743 | |||
| 744 |
3/3✓ Branch 1 taken 42 times.
✓ Branch 7 taken 33 times.
✓ Branch 8 taken 9 times.
|
42 | for (const auto& construction : model.getConcreteModelObjects<model::ConstructionAirBoundary>()) { |
| 745 |
1/1✓ Branch 1 taken 33 times.
|
33 | airWall = construction; |
| 746 | 33 | break; | |
| 747 | 42 | } | |
| 748 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 2 taken 33 times.
|
42 | if (!airWall) { |
| 749 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | airWall = model::ConstructionAirBoundary(model); |
| 750 | } | ||
| 751 |
2/2✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
|
42 | surface.setConstruction(*airWall); |
| 752 | |||
| 753 | // don't translate subsurfaces of air walls? | ||
| 754 | |||
| 755 | 42 | } else { | |
| 756 | // not air wall | ||
| 757 | |||
| 758 | // translate construction | ||
| 759 |
3/3✓ Branch 1 taken 2028 times.
✓ Branch 4 taken 2028 times.
✓ Branch 7 taken 2028 times.
|
2028 | std::string constructionIdRef = element.attribute("constructionIdRef").value(); |
| 760 |
1/1✓ Branch 1 taken 2028 times.
|
2028 | auto constructionIt = m_idToObjectMap.find(constructionIdRef); |
| 761 |
2/2✓ Branch 2 taken 1633 times.
✓ Branch 3 taken 395 times.
|
2028 | if (constructionIt != m_idToObjectMap.end()) { |
| 762 |
1/1✓ Branch 2 taken 1633 times.
|
1633 | boost::optional<model::ConstructionBase> construction = constructionIt->second.optionalCast<model::ConstructionBase>(); |
| 763 |
1/2✓ Branch 0 taken 1633 times.
✗ Branch 1 not taken.
|
1633 | if (construction) { |
| 764 |
2/2✓ Branch 1 taken 1633 times.
✓ Branch 4 taken 1633 times.
|
1633 | surface.setConstruction(*construction); |
| 765 | } | ||
| 766 | 1633 | } | |
| 767 | |||
| 768 | // translate subSurfaces | ||
| 769 |
6/6✓ Branch 1 taken 2028 times.
✓ Branch 6 taken 461 times.
✓ Branch 9 taken 461 times.
✓ Branch 12 taken 2489 times.
✓ Branch 14 taken 461 times.
✓ Branch 15 taken 2028 times.
|
2489 | for (auto& subsurf : element.children("Opening")) { |
| 770 | try { | ||
| 771 |
1/1✓ Branch 1 taken 461 times.
|
461 | boost::optional<model::ModelObject> subSurface = translateSubSurface(subsurf, surface); |
| 772 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
461 | } catch (const std::exception&) { |
| 773 | ✗ | LOG(Error, "Could not translate sub surface " << subsurf); | |
| 774 | ✗ | } | |
| 775 | } | ||
| 776 | 2028 | } | |
| 777 | |||
| 778 | // adjacent surfaces | ||
| 779 |
4/4✓ Branch 1 taken 2070 times.
✓ Branch 4 taken 2070 times.
✓ Branch 7 taken 2070 times.
✓ Branch 10 taken 2070 times.
|
2070 | std::string spaceId = adjacentSpaceElements.at(0).attribute("spaceIdRef").value(); |
| 780 |
1/1✓ Branch 1 taken 2070 times.
|
2070 | auto spaceIt = m_idToObjectMap.find(spaceId); |
| 781 |
2/2✓ Branch 2 taken 2064 times.
✓ Branch 3 taken 6 times.
|
2070 | if (spaceIt != m_idToObjectMap.end()) { |
| 782 |
1/1✓ Branch 2 taken 2064 times.
|
2064 | boost::optional<model::Space> space = spaceIt->second.optionalCast<openstudio::model::Space>(); |
| 783 |
1/2✓ Branch 0 taken 2064 times.
✗ Branch 1 not taken.
|
2064 | if (space) { |
| 784 |
2/2✓ Branch 1 taken 2064 times.
✓ Branch 4 taken 2064 times.
|
2064 | surface.setSpace(*space); |
| 785 | } | ||
| 786 | 2064 | } | |
| 787 | |||
| 788 |
1/1✓ Branch 1 taken 2070 times.
|
2070 | boost::optional<openstudio::model::Space> space = surface.space(); |
| 789 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2064 times.
|
2070 | if (!space) { |
| 790 |
9/9✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 20 taken 6 times.
✓ Branch 23 taken 6 times.
✓ Branch 26 taken 6 times.
|
6 | LOG(Error, "Surface '" << surface.name().get() << "' is not assigned to a space"); |
| 791 | } | ||
| 792 | |||
| 793 |
6/6✓ Branch 0 taken 2064 times.
✓ Branch 1 taken 6 times.
✓ Branch 3 taken 774 times.
✓ Branch 4 taken 1290 times.
✓ Branch 5 taken 774 times.
✓ Branch 6 taken 1296 times.
|
2070 | if (space && adjacentSpaceElements.size() == 2) { |
| 794 | |||
| 795 | // From the GbXML Schema (v6.01): | ||
| 796 | // | ||
| 797 | // First AdjacentSpaceId entered will determine how the referenced construction layers are ordered with the first construction layer | ||
| 798 | // being in contact with the outside or 2nd space listed and the last layer in contact with the first space listed. | ||
| 799 | // | ||
| 800 | // References the ID of a Space that is bounded by this surface. First AdjacentSpaceId entered will determine how the referenced construction | ||
| 801 | // layers are ordered with the first construction layer being in contact with the outside or 2nd space listed and the last layer in contact with | ||
| 802 | // the first space listed. The outward normal of the surface, as defined by the right hand rule of the coordinates in the planar geometry element, | ||
| 803 | // is always pointing away from the first AdjacentSpaceID listed. | ||
| 804 | // | ||
| 805 | // With interior horizontal surfaces, this attribute can distinguish between ceiling and floor surfaces to avoid double-counting of floor areas, etc. | ||
| 806 | // If not present, the surface type can be assumed based on the description of the surface type enums. When the surfaceTypeEnum is provided and the | ||
| 807 | // surface attributes (i.e. adjacency, tilt angle) do not match the enumeration's description, the enumeration should have precedence. | ||
| 808 | |||
| 809 |
4/4✓ Branch 1 taken 774 times.
✓ Branch 4 taken 774 times.
✓ Branch 7 taken 774 times.
✓ Branch 10 taken 774 times.
|
774 | std::string adjacentSpaceId = adjacentSpaceElements.at(1).attribute("spaceIdRef").value(); |
| 810 |
1/1✓ Branch 1 taken 774 times.
|
774 | auto adjacentSpaceIt = m_idToObjectMap.find(adjacentSpaceId); |
| 811 |
1/2✓ Branch 2 taken 774 times.
✗ Branch 3 not taken.
|
774 | if (adjacentSpaceIt != m_idToObjectMap.end()) { |
| 812 |
1/1✓ Branch 2 taken 774 times.
|
774 | boost::optional<model::Space> adjacentSpace = adjacentSpaceIt->second.optionalCast<openstudio::model::Space>(); |
| 813 |
1/2✓ Branch 0 taken 774 times.
✗ Branch 1 not taken.
|
774 | if (adjacentSpace) { |
| 814 | |||
| 815 | // DLM: we have issues if interior ceilings/floors are mislabeled, override surface type for adjacent surfaces | ||
| 816 | // http://code.google.com/p/cbecc/issues/detail?id=471 | ||
| 817 | |||
| 818 | // the surfaceType at this point has been set based on the surfaceType attribute of the surface | ||
| 819 | // if there are two spaces, we do not know which copy of the surface should go into which space | ||
| 820 | // in the case of a floor/ceiling pair, this can lead to putting the floor in the bottom space and the ceiling in the top space rather than vice versa | ||
| 821 | // in the case of interior walls, this can lead to incorrect surface normals (e.g. wall with right-pointing normal placed in the right space instead of left) | ||
| 822 | // we can try to use the adjacent space attribute surfaceType to put floors and ceilings in the right space | ||
| 823 | // we cannot ensure that wall normals are handled correctly, that will require a convention that vertices are not reversed in the first space listed or additional attribute | ||
| 824 |
1/1✓ Branch 1 taken 774 times.
|
774 | std::string gbXMLSurfaceType = surface.surfaceType(); |
| 825 | |||
| 826 | // we now assign the default surface type based on outward normal | ||
| 827 | // this is needed in case floor vertices (i.e. normal down) are provided for a surface labeled ceiling | ||
| 828 |
1/1✓ Branch 1 taken 774 times.
|
774 | surface.assignDefaultSurfaceType(); |
| 829 | |||
| 830 | // currentSurfaceType is the surface type assigned by vertices | ||
| 831 |
1/1✓ Branch 1 taken 774 times.
|
774 | std::string currentSurfaceType = surface.surfaceType(); |
| 832 | |||
| 833 | // spaceSurfaceType is the surfaceType that should be in the first space | ||
| 834 |
4/4✓ Branch 1 taken 774 times.
✓ Branch 4 taken 774 times.
✓ Branch 7 taken 774 times.
✓ Branch 10 taken 774 times.
|
774 | std::string spaceSurfaceType = adjacentSpaceElements.at(0).attribute("surfaceType").value(); |
| 835 | |||
| 836 | // spaceSurfaceType is the surfaceType that should be in the second space | ||
| 837 |
4/4✓ Branch 1 taken 774 times.
✓ Branch 4 taken 774 times.
✓ Branch 7 taken 774 times.
✓ Branch 10 taken 774 times.
|
774 | std::string adjacentSpaceSurfaceType = adjacentSpaceElements.at(1).attribute("surfaceType").value(); |
| 838 | |||
| 839 | // we will mark figuredOut as true if we are sure of our assignment, otherwise we will log a warning | ||
| 840 | 774 | bool figuredOut = false; | |
| 841 | |||
| 842 | // set reverseConstruction if construction should be applied to the surface created in adjacent space | ||
| 843 | 774 | bool reverseConstruction = false; | |
| 844 | |||
| 845 |
5/6✓ Branch 1 taken 571 times.
✓ Branch 2 taken 203 times.
✓ Branch 4 taken 571 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 203 times.
✓ Branch 7 taken 571 times.
|
774 | if (spaceSurfaceType.empty() && adjacentSpaceSurfaceType.empty()) { |
| 846 | |||
| 847 | // this is ok but gives us no new information, no warning issued | ||
| 848 | |||
| 849 |
2/6✗ Branch 1 not taken.
✓ Branch 2 taken 203 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 203 times.
|
203 | } else if (spaceSurfaceType.empty() && !adjacentSpaceSurfaceType.empty()) { |
| 850 | |||
| 851 | // if one adjacent space surfaceType is given then the other should be too | ||
| 852 | ✗ | LOG(Warn, "Only one adjacent surfaceType listed for '" << surface.name().get() << "'"); | |
| 853 | |||
| 854 |
3/6✓ Branch 1 taken 203 times.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 203 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 203 times.
|
203 | } else if (!spaceSurfaceType.empty() && adjacentSpaceSurfaceType.empty()) { |
| 855 | |||
| 856 | // if one adjacent surfaceType is given then the other should be too | ||
| 857 | ✗ | LOG(Warn, "Only one adjacent surfaceType listed for '" << surface.name().get() << "'"); | |
| 858 | |||
| 859 | } else { | ||
| 860 | |||
| 861 | // have both spaceSurfaceType and adjacentSpaceSurfaceType | ||
| 862 | |||
| 863 |
8/8✓ Branch 1 taken 203 times.
✓ Branch 3 taken 186 times.
✓ Branch 4 taken 17 times.
✓ Branch 6 taken 186 times.
✓ Branch 8 taken 64 times.
✓ Branch 9 taken 122 times.
✓ Branch 10 taken 81 times.
✓ Branch 11 taken 122 times.
|
203 | if (currentSurfaceType == "RoofCeiling" || currentSurfaceType == "Floor") { |
| 864 | |||
| 865 | // both the spaceSurfaceType and adjacentSpaceSurfaceType should be either Ceiling or InteriorFloor | ||
| 866 |
6/8✓ Branch 1 taken 81 times.
✓ Branch 3 taken 75 times.
✓ Branch 4 taken 6 times.
✓ Branch 6 taken 75 times.
✓ Branch 8 taken 75 times.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 81 times.
|
162 | if (!((spaceSurfaceType == "InteriorFloor" || spaceSurfaceType == "Ceiling") |
| 867 |
5/6✓ Branch 1 taken 81 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 75 times.
✓ Branch 6 taken 6 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6 times.
|
81 | && (adjacentSpaceSurfaceType == "InteriorFloor" || adjacentSpaceSurfaceType == "Ceiling"))) { |
| 868 | |||
| 869 | // one of the spaces lists this as a wall or some other surfaceType | ||
| 870 | // we could try to reapply the surfaceType from the gbXML back here, but then we would be in the same problem as before | ||
| 871 | // at least now we have a surface type that matches the vertex outward normal | ||
| 872 | ✗ | LOG(Warn, "Adjacent surfaceTypes '" << spaceSurfaceType << "' and '" << adjacentSpaceSurfaceType << "' listed for '" | |
| 873 | << surface.name().get() << "' do not match vertices"); | ||
| 874 | |||
| 875 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 81 times.
|
81 | } else if (spaceSurfaceType == adjacentSpaceSurfaceType) { |
| 876 | |||
| 877 | // both spaceSurfaceType and adjacentSpaceSurfaceType are either InteriorFloor or Ceiling, not allowed | ||
| 878 | ✗ | LOG(Warn, "Duplicate surfaceType '" << spaceSurfaceType << "' listed for '" << surface.name().get() << "'"); | |
| 879 | |||
| 880 | } else { | ||
| 881 | |||
| 882 |
3/3✓ Branch 1 taken 81 times.
✓ Branch 3 taken 64 times.
✓ Branch 4 taken 17 times.
|
81 | if (currentSurfaceType == "Floor") { |
| 883 | // vertices indicate floor, outward normal is down | ||
| 884 |
3/3✓ Branch 1 taken 64 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 58 times.
|
64 | if (spaceSurfaceType == "InteriorFloor") { |
| 885 | // No changes, floor should go into first space | ||
| 886 | 6 | figuredOut = true; | |
| 887 |
2/3✓ Branch 1 taken 58 times.
✓ Branch 3 taken 58 times.
✗ Branch 4 not taken.
|
58 | } else if (spaceSurfaceType == "Ceiling") { |
| 888 | // Swap roles of space and adjacentSpace, floor should go into second space | ||
| 889 |
2/2✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
|
58 | surface.setSpace(*adjacentSpace); |
| 890 |
1/1✓ Branch 1 taken 58 times.
|
58 | auto temp = space; |
| 891 |
1/1✓ Branch 1 taken 58 times.
|
58 | space = adjacentSpace; |
| 892 |
1/1✓ Branch 1 taken 58 times.
|
58 | adjacentSpace = temp; |
| 893 | 58 | figuredOut = true; | |
| 894 | |||
| 895 | // Schema says, "The outward normal of the surface, as defined by the right hand rule of the coordinates in the planar geometry element, | ||
| 896 | // is always pointing away from the first AdjacentSpaceID listed." but this does not match surfaceType in the first AdjacentSpaceID | ||
| 897 |
11/11✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
✓ Branch 7 taken 58 times.
✓ Branch 10 taken 58 times.
✓ Branch 13 taken 58 times.
✓ Branch 16 taken 58 times.
✓ Branch 19 taken 58 times.
✓ Branch 22 taken 58 times.
✓ Branch 26 taken 58 times.
✓ Branch 29 taken 58 times.
✓ Branch 32 taken 58 times.
|
58 | LOG(Warn, "Outward normal for '" << surface.name().get() << "' does not match surfaceType '" << spaceSurfaceType |
| 898 | << "' attribute of first AdjacentSpaceID"); | ||
| 899 | |||
| 900 | // construction listed in order for first space which is now the adjacent space | ||
| 901 | 58 | reverseConstruction = true; | |
| 902 | 58 | } | |
| 903 |
2/3✓ Branch 1 taken 17 times.
✓ Branch 3 taken 17 times.
✗ Branch 4 not taken.
|
17 | } else if (currentSurfaceType == "RoofCeiling") { |
| 904 | // vertices indicate ceiling, outward normal is up | ||
| 905 |
2/3✓ Branch 1 taken 17 times.
✓ Branch 3 taken 17 times.
✗ Branch 4 not taken.
|
17 | if (spaceSurfaceType == "Ceiling") { |
| 906 | // No changes, ceiling should go into first space | ||
| 907 | 17 | figuredOut = true; | |
| 908 | ✗ | } else if (spaceSurfaceType == "InteriorFloor") { | |
| 909 | // Swap roles of space and adjacentSpace, ceiling should go into second space | ||
| 910 | ✗ | surface.setSpace(*adjacentSpace); | |
| 911 | ✗ | auto temp = space; | |
| 912 | ✗ | space = adjacentSpace; | |
| 913 | ✗ | adjacentSpace = temp; | |
| 914 | ✗ | figuredOut = true; | |
| 915 | |||
| 916 | // Schema says, "The outward normal of the surface, as defined by the right hand rule of the coordinates in the planar geometry element, | ||
| 917 | // is always pointing away from the first AdjacentSpaceID listed." but this does not match surfaceType in the first AdjacentSpaceID | ||
| 918 | ✗ | LOG(Warn, "Outward normal for '" << surface.name().get() << "' does not match surfaceType attribute '" << spaceSurfaceType | |
| 919 | << "' of first AdjacentSpaceID"); | ||
| 920 | |||
| 921 | // construction listed in order for first space which is now the adjacent space | ||
| 922 | ✗ | reverseConstruction = true; | |
| 923 | ✗ | } | |
| 924 | } | ||
| 925 | } | ||
| 926 | } else { | ||
| 927 | |||
| 928 | // currentSurfaceType is Wall, we can't be sure it is in correct space (with normal pointing out) but don't issue warning | ||
| 929 | // need to have either 1) convention that vertices are not reversed in first space, 2) some new attribute (e.g. 'reversed=true/false'), or 3) heuristic checking outward normal | ||
| 930 | // if doing a hueristic, best to run at the end after all other geometry is created so you can tell which way is out of the space (all surfaces should point out of the space) | ||
| 931 | } | ||
| 932 | } | ||
| 933 | |||
| 934 | // if we changed surface type and didn't figure out if that is ok, issue warning | ||
| 935 |
2/2✓ Branch 0 taken 693 times.
✓ Branch 1 taken 81 times.
|
774 | if (!figuredOut) { |
| 936 |
2/2✓ Branch 1 taken 19 times.
✓ Branch 2 taken 674 times.
|
693 | if (currentSurfaceType != gbXMLSurfaceType) { |
| 937 |
13/13✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
✓ Branch 7 taken 19 times.
✓ Branch 10 taken 19 times.
✓ Branch 13 taken 19 times.
✓ Branch 16 taken 19 times.
✓ Branch 19 taken 19 times.
✓ Branch 22 taken 19 times.
✓ Branch 25 taken 19 times.
✓ Branch 28 taken 19 times.
✓ Branch 32 taken 19 times.
✓ Branch 35 taken 19 times.
✓ Branch 38 taken 19 times.
|
19 | LOG(Warn, "Changing surface type from '" << gbXMLSurfaceType << "' to '" << currentSurfaceType << "' for surface '" |
| 938 | << surface.name().get() << "'"); | ||
| 939 | } | ||
| 940 | } | ||
| 941 | |||
| 942 | // clone the surface and sub surfaces and reverse vertices | ||
| 943 |
2/2✓ Branch 1 taken 774 times.
✓ Branch 4 taken 774 times.
|
774 | boost::optional<openstudio::model::Surface> otherSurface = surface.createAdjacentSurface(*adjacentSpace); |
| 944 |
1/2✓ Branch 0 taken 774 times.
✗ Branch 1 not taken.
|
774 | if (otherSurface) { |
| 945 |
2/2✓ Branch 0 taken 58 times.
✓ Branch 1 taken 716 times.
|
774 | if (reverseConstruction) { |
| 946 |
1/1✓ Branch 1 taken 58 times.
|
58 | boost::optional<openstudio::model::ConstructionBase> construction = surface.construction(); |
| 947 |
1/2✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
|
58 | if (construction) { |
| 948 |
3/3✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
✓ Branch 7 taken 58 times.
|
58 | otherSurface->setConstruction(*construction); |
| 949 |
1/1✓ Branch 1 taken 58 times.
|
58 | surface.resetConstruction(); // will be inherited from the adjacent surface |
| 950 | } | ||
| 951 | 58 | } | |
| 952 | } else { | ||
| 953 | ✗ | LOG(Error, "Could not create adjacent surface in adjacent space '" << adjacentSpace->name().get() << "' for surface '" | |
| 954 | << surface.name().get() << "' in space '" << space->name().get() | ||
| 955 | << "'"); | ||
| 956 | } | ||
| 957 | 774 | } | |
| 958 | 774 | } else { | |
| 959 | ✗ | LOG(Error, "Could not find adjacent space '" << adjacentSpaceId << "' for surface '" << surface.name().get() << "'"); | |
| 960 | } | ||
| 961 | 774 | } | |
| 962 | 2370 | } | |
| 963 | |||
| 964 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2623 times.
✗ Branch 4 not taken.
|
2623 | OS_ASSERT(result); |
| 965 | |||
| 966 | // import CADObjectId | ||
| 967 |
6/6✓ Branch 1 taken 2623 times.
✓ Branch 6 taken 2331 times.
✓ Branch 9 taken 2331 times.
✓ Branch 12 taken 4954 times.
✓ Branch 14 taken 2331 times.
✓ Branch 15 taken 2623 times.
|
4954 | for (auto& cadObjectId : element.children("CADObjectId")) { |
| 968 |
2/2✓ Branch 1 taken 2331 times.
✓ Branch 4 taken 2331 times.
|
2331 | translateCADObjectId(cadObjectId, *result); |
| 969 | } | ||
| 970 | |||
| 971 | // merge additional properties for reversed surfaces and sub surfaces | ||
| 972 |
4/4✓ Branch 1 taken 2623 times.
✓ Branch 4 taken 2623 times.
✓ Branch 6 taken 2070 times.
✓ Branch 7 taken 553 times.
|
5246 | if (boost::optional<model::Surface> _surface = result->optionalCast<model::Surface>()) { |
| 973 | |||
| 974 |
2/2✓ Branch 1 taken 2070 times.
✓ Branch 4 taken 2070 times.
|
2070 | boost::optional<openstudio::model::Surface> otherSurface = _surface->adjacentSurface(); |
| 975 |
2/2✓ Branch 0 taken 774 times.
✓ Branch 1 taken 1296 times.
|
2070 | if (otherSurface) { |
| 976 |
5/5✓ Branch 1 taken 774 times.
✓ Branch 4 taken 774 times.
✓ Branch 7 taken 774 times.
✓ Branch 10 taken 774 times.
✓ Branch 13 taken 774 times.
|
774 | otherSurface->additionalProperties().merge(result->additionalProperties(), true); |
| 977 |
4/4✓ Branch 1 taken 774 times.
✓ Branch 4 taken 774 times.
✓ Branch 7 taken 774 times.
✓ Branch 10 taken 774 times.
|
2322 | otherSurface->additionalProperties().setFeature("gbXMLReversed", true); |
| 978 | } | ||
| 979 | |||
| 980 |
4/4✓ Branch 1 taken 2070 times.
✓ Branch 4 taken 2070 times.
✓ Branch 11 taken 461 times.
✓ Branch 12 taken 2070 times.
|
2531 | for (const auto& subSurface : _surface->subSurfaces()) { |
| 981 |
1/1✓ Branch 1 taken 461 times.
|
461 | boost::optional<openstudio::model::SubSurface> otherSubSurface = subSurface.adjacentSubSurface(); |
| 982 |
2/2✓ Branch 0 taken 102 times.
✓ Branch 1 taken 359 times.
|
461 | if (otherSubSurface) { |
| 983 |
4/4✓ Branch 1 taken 102 times.
✓ Branch 4 taken 102 times.
✓ Branch 7 taken 102 times.
✓ Branch 10 taken 102 times.
|
102 | otherSubSurface->additionalProperties().merge(subSurface.additionalProperties(), true); |
| 984 |
4/4✓ Branch 1 taken 102 times.
✓ Branch 4 taken 102 times.
✓ Branch 7 taken 102 times.
✓ Branch 10 taken 102 times.
|
306 | otherSubSurface->additionalProperties().setFeature("gbXMLReversed", true); |
| 985 | } | ||
| 986 | |||
| 987 |
3/3✓ Branch 1 taken 461 times.
✓ Branch 4 taken 461 times.
✓ Branch 7 taken 461 times.
|
1383 | subSurface.additionalProperties().setFeature("gbXMLReversed", false); |
| 988 | 2531 | } | |
| 989 | |||
| 990 |
4/4✓ Branch 1 taken 2070 times.
✓ Branch 4 taken 2070 times.
✓ Branch 7 taken 2070 times.
✓ Branch 10 taken 2070 times.
|
6210 | _surface->additionalProperties().setFeature("gbXMLReversed", false); |
| 991 | 4693 | } | |
| 992 | |||
| 993 | 2623 | return result; | |
| 994 | 2923 | } | |
| 995 | |||
| 996 | 461 | boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateSubSurface(const pugi::xml_node& element, | |
| 997 | openstudio::model::Surface& surface) { | ||
| 998 |
1/1✓ Branch 1 taken 461 times.
|
461 | openstudio::model::Model model = surface.model(); |
| 999 | |||
| 1000 | 461 | boost::optional<model::ModelObject> result; | |
| 1001 | |||
| 1002 | 461 | std::vector<openstudio::Point3d> vertices; | |
| 1003 | |||
| 1004 |
1/1✓ Branch 1 taken 461 times.
|
461 | auto planarGeometryElement = element.child("PlanarGeometry"); |
| 1005 |
1/1✓ Branch 1 taken 461 times.
|
461 | auto polyLoopElement = planarGeometryElement.child("PolyLoop"); |
| 1006 |
1/1✓ Branch 1 taken 461 times.
|
461 | auto cartesianPointElements = polyLoopElement.children("CartesianPoint"); |
| 1007 | |||
| 1008 |
5/5✓ Branch 3 taken 1868 times.
✓ Branch 6 taken 1868 times.
✓ Branch 9 taken 2329 times.
✓ Branch 11 taken 1868 times.
✓ Branch 12 taken 461 times.
|
2329 | for (auto& cart_el : cartesianPointElements) { |
| 1009 |
1/1✓ Branch 1 taken 1868 times.
|
1868 | auto coordinateElements = cart_el.children("Coordinate"); |
| 1010 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1868 times.
✗ Branch 5 not taken.
|
3736 | OS_ASSERT(std::distance(coordinateElements.begin(), coordinateElements.end()) == 3); |
| 1011 | |||
| 1012 | /* Calling these conversions every time is unnecessarily slow | ||
| 1013 | |||
| 1014 | Unit targetUnit = UnitFactory::instance().createUnit("m").get(); | ||
| 1015 | Quantity xQuantity(coordinateElements.at(0).toElement().text().toDouble(), m_lengthUnit); | ||
| 1016 | Quantity yQuantity(coordinateElements.at(1).toElement().text().toDouble(), m_lengthUnit); | ||
| 1017 | Quantity zQuantity(coordinateElements.at(2).toElement().text().toDouble(), m_lengthUnit); | ||
| 1018 | |||
| 1019 | double x = QuantityConverter::instance().convert(xQuantity, targetUnit)->value(); | ||
| 1020 | double y = QuantityConverter::instance().convert(yQuantity, targetUnit)->value(); | ||
| 1021 | double z = QuantityConverter::instance().convert(zQuantity, targetUnit)->value(); | ||
| 1022 | */ | ||
| 1023 | 1868 | std::array<double, 3> coords{{0.0, 0.0, 0.0}}; | |
| 1024 | 1868 | size_t i{0}; | |
| 1025 |
4/5✓ Branch 3 taken 5604 times.
✓ Branch 6 taken 3736 times.
✓ Branch 9 taken 5604 times.
✓ Branch 11 taken 5604 times.
✗ Branch 12 not taken.
|
5604 | for (auto& el : coordinateElements) { |
| 1026 |
2/2✓ Branch 1 taken 5604 times.
✓ Branch 4 taken 5604 times.
|
5604 | coords[i] = m_lengthMultiplier * el.text().as_double(); |
| 1027 | 5604 | ++i; | |
| 1028 |
2/2✓ Branch 0 taken 1868 times.
✓ Branch 1 taken 3736 times.
|
5604 | if (i == 3) { |
| 1029 | 1868 | break; | |
| 1030 | } | ||
| 1031 | } | ||
| 1032 | |||
| 1033 |
1/1✓ Branch 4 taken 1868 times.
|
1868 | vertices.emplace_back(coords[0], coords[1], coords[2]); |
| 1034 | } | ||
| 1035 | |||
| 1036 |
1/1✓ Branch 1 taken 461 times.
|
461 | openstudio::model::SubSurface subSurface(vertices, model); |
| 1037 |
1/1✓ Branch 1 taken 461 times.
|
461 | subSurface.setSurface(surface); |
| 1038 | |||
| 1039 |
1/1✓ Branch 1 taken 461 times.
|
461 | translateId(element, subSurface); |
| 1040 |
1/1✓ Branch 1 taken 461 times.
|
461 | translateName(element, subSurface); |
| 1041 | |||
| 1042 |
1/1✓ Branch 1 taken 461 times.
|
461 | result = subSurface; |
| 1043 | |||
| 1044 | // translate openingType | ||
| 1045 |
3/3✓ Branch 1 taken 461 times.
✓ Branch 4 taken 461 times.
✓ Branch 7 taken 461 times.
|
461 | std::string openingType = element.attribute("openingType").value(); |
| 1046 |
2/2✓ Branch 1 taken 134 times.
✓ Branch 2 taken 327 times.
|
461 | if (openingType.find("FixedWindow") != std::string::npos) { |
| 1047 |
2/2✓ Branch 1 taken 134 times.
✓ Branch 4 taken 134 times.
|
268 | subSurface.setSubSurfaceType("FixedWindow"); |
| 1048 |
2/2✓ Branch 1 taken 202 times.
✓ Branch 2 taken 125 times.
|
327 | } else if (openingType.find("OperableWindow") != std::string::npos) { |
| 1049 |
2/2✓ Branch 1 taken 202 times.
✓ Branch 4 taken 202 times.
|
404 | subSurface.setSubSurfaceType("OperableWindow"); |
| 1050 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 125 times.
|
125 | } else if (openingType.find("FixedSkylight") != std::string::npos) { |
| 1051 | ✗ | subSurface.setSubSurfaceType("Skylight"); | |
| 1052 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 121 times.
|
125 | } else if (openingType.find("OperableSkylight") != std::string::npos) { |
| 1053 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
8 | subSurface.setSubSurfaceType("Skylight"); |
| 1054 |
2/2✓ Branch 1 taken 111 times.
✓ Branch 2 taken 10 times.
|
121 | } else if (openingType.find("NonSlidingDoor") != std::string::npos) { // do before testing contains door |
| 1055 |
2/2✓ Branch 1 taken 111 times.
✓ Branch 4 taken 111 times.
|
222 | subSurface.setSubSurfaceType("Door"); |
| 1056 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | } else if (openingType.find("SlidingDoor") != std::string::npos) { |
| 1057 | ✗ | subSurface.setSubSurfaceType("GlassDoor"); | |
| 1058 | 10 | } else if (openingType.find("Air") != std::string::npos) { | |
| 1059 | // use default sub surface type? | ||
| 1060 | } | ||
| 1061 | |||
| 1062 | // if air wall | ||
| 1063 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 451 times.
|
461 | if (openingType.find("Air") != std::string::npos) { |
| 1064 | 10 | boost::optional<model::ConstructionAirBoundary> airWall; | |
| 1065 | |||
| 1066 |
3/3✓ Branch 1 taken 10 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 3 times.
|
10 | for (const auto& construction : model.getConcreteModelObjects<model::ConstructionAirBoundary>()) { |
| 1067 |
1/1✓ Branch 1 taken 7 times.
|
7 | airWall = construction; |
| 1068 | 7 | break; | |
| 1069 | 10 | } | |
| 1070 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 2 taken 7 times.
|
10 | if (!airWall) { |
| 1071 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | airWall = model::ConstructionAirBoundary(model); |
| 1072 | } | ||
| 1073 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | subSurface.setConstruction(*airWall); |
| 1074 | |||
| 1075 | 10 | } else { | |
| 1076 | |||
| 1077 | // translate construction | ||
| 1078 |
3/3✓ Branch 1 taken 451 times.
✓ Branch 4 taken 451 times.
✓ Branch 7 taken 451 times.
|
451 | std::string constructionIdRef = element.attribute("constructionIdRef").value(); |
| 1079 |
2/2✓ Branch 1 taken 373 times.
✓ Branch 2 taken 78 times.
|
451 | if (constructionIdRef.empty()) { |
| 1080 |
3/3✓ Branch 1 taken 373 times.
✓ Branch 4 taken 373 times.
✓ Branch 7 taken 373 times.
|
373 | constructionIdRef = element.attribute("windowTypeIdRef").value(); |
| 1081 | } | ||
| 1082 |
1/1✓ Branch 1 taken 451 times.
|
451 | auto constructionIt = m_idToObjectMap.find(constructionIdRef); |
| 1083 |
2/2✓ Branch 2 taken 338 times.
✓ Branch 3 taken 113 times.
|
451 | if (constructionIt != m_idToObjectMap.end()) { |
| 1084 |
1/1✓ Branch 2 taken 338 times.
|
338 | boost::optional<model::ConstructionBase> construction = constructionIt->second.optionalCast<model::ConstructionBase>(); |
| 1085 |
1/2✓ Branch 0 taken 338 times.
✗ Branch 1 not taken.
|
338 | if (construction) { |
| 1086 |
2/2✓ Branch 1 taken 338 times.
✓ Branch 4 taken 338 times.
|
338 | subSurface.setConstruction(*construction); |
| 1087 | } | ||
| 1088 | 338 | } | |
| 1089 | 451 | } | |
| 1090 | |||
| 1091 | // todo: translate "interiorShadeType", "exteriorShadeType", and other properties of the opening | ||
| 1092 | |||
| 1093 | // import CADObjectId | ||
| 1094 |
6/6✓ Branch 1 taken 461 times.
✓ Branch 6 taken 281 times.
✓ Branch 9 taken 281 times.
✓ Branch 12 taken 742 times.
✓ Branch 14 taken 281 times.
✓ Branch 15 taken 461 times.
|
742 | for (auto& cadObjectId : element.children("CADObjectId")) { |
| 1095 |
1/1✓ Branch 1 taken 281 times.
|
281 | translateCADObjectId(cadObjectId, subSurface); |
| 1096 | } | ||
| 1097 | |||
| 1098 | 922 | return result; | |
| 1099 | 461 | } | |
| 1100 | |||
| 1101 | 3895 | void ReverseTranslator::translateId(const pugi::xml_node& element, openstudio::model::ModelObject& modelObject) { | |
| 1102 |
3/3✓ Branch 1 taken 3895 times.
✓ Branch 4 taken 3895 times.
✓ Branch 7 taken 3895 times.
|
3895 | std::string id = element.attribute("id").value(); |
| 1103 |
2/2✓ Branch 1 taken 3895 times.
✓ Branch 4 taken 3895 times.
|
3895 | m_idToObjectMap.insert(std::make_pair(id, modelObject)); |
| 1104 |
1/1✓ Branch 1 taken 3895 times.
|
3895 | modelObject.setName(id); |
| 1105 |
1/1✓ Branch 1 taken 3895 times.
|
3895 | modelObject.setGBXMLId(id); |
| 1106 | 3895 | } | |
| 1107 | |||
| 1108 | 3895 | void ReverseTranslator::translateName(const pugi::xml_node& element, openstudio::model::ModelObject& modelObject) { | |
| 1109 | |||
| 1110 |
2/2✓ Branch 1 taken 3895 times.
✓ Branch 4 taken 3895 times.
|
3895 | auto name = element.child("Name").text(); |
| 1111 |
3/3✓ Branch 1 taken 3895 times.
✓ Branch 3 taken 3553 times.
✓ Branch 4 taken 342 times.
|
3895 | if (!name.empty()) { |
| 1112 |
3/3✓ Branch 1 taken 3553 times.
✓ Branch 4 taken 3553 times.
✓ Branch 7 taken 3553 times.
|
7106 | modelObject.setDisplayName(name.as_string()); |
| 1113 | } | ||
| 1114 | 3895 | } | |
| 1115 | |||
| 1116 | 2865 | void ReverseTranslator::translateCADObjectId(const pugi::xml_node& element, openstudio::model::ModelObject& modelObject) { | |
| 1117 | |||
| 1118 |
1/1✓ Branch 1 taken 2865 times.
|
2865 | auto cadObjectId = element.text(); |
| 1119 |
2/3✓ Branch 1 taken 2865 times.
✓ Branch 3 taken 2865 times.
✗ Branch 4 not taken.
|
2865 | if (!cadObjectId.empty()) { |
| 1120 |
3/3✓ Branch 1 taken 2865 times.
✓ Branch 4 taken 2865 times.
✓ Branch 7 taken 2865 times.
|
2865 | modelObject.setCADObjectId(cadObjectId.as_string()); |
| 1121 | |||
| 1122 |
1/1✓ Branch 1 taken 2865 times.
|
2865 | auto programIdRef = element.attribute("programIdRef"); |
| 1123 |
2/3✓ Branch 1 taken 2865 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2865 times.
|
2865 | if (programIdRef) { |
| 1124 | ✗ | model::AdditionalProperties result = modelObject.additionalProperties(); | |
| 1125 | ✗ | result.setFeature("programIdRef", programIdRef.value()); | |
| 1126 | ✗ | } | |
| 1127 | } | ||
| 1128 | 2865 | } | |
| 1129 | |||
| 1130 | } // namespace gbxml | ||
| 1131 | } // namespace openstudio | ||
| 1132 |