src/utilities/geometry/FloorplanJS.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 "FloorplanJS.hpp" | ||
| 7 | #include "ThreeJS.hpp" | ||
| 8 | #include "Vector3d.hpp" | ||
| 9 | #include "Geometry.hpp" | ||
| 10 | #include "Intersection.hpp" | ||
| 11 | |||
| 12 | #include "../core/Assert.hpp" | ||
| 13 | //#include "../core/Path.hpp" | ||
| 14 | #include "../core/Json.hpp" | ||
| 15 | |||
| 16 | namespace openstudio { | ||
| 17 | |||
| 18 | static constexpr auto BELOWFLOORPLENUMPOSTFIX(" Floor Plenum"); | ||
| 19 | static constexpr auto ABOVECEILINGPLENUMPOSTFIX(" Plenum"); | ||
| 20 | static constexpr auto PLENUMSPACETYPENAME("Plenum Space Type"); // DLM: needs to be coordinated with name in Model_Impl::plenumSpaceType() | ||
| 21 | static constexpr auto PLENUMCOLOR("#C0C0C0"); // DLM: needs to be coordinated with plenum colors in makeStandardThreeMaterials | ||
| 22 | |||
| 23 | ✗ | FloorplanObject::FloorplanObject(const std::string& id, const std::string& name, const std::string& handleString) | |
| 24 | ✗ | : m_id(id), m_name(name), m_handle(toUUID(handleString)), m_handleString(handleString) {} | |
| 25 | |||
| 26 | 22 | FloorplanObject::FloorplanObject(const std::string& id, const std::string& name, const UUID& handle) | |
| 27 |
3/3✓ Branch 2 taken 22 times.
✓ Branch 5 taken 22 times.
✓ Branch 9 taken 22 times.
|
22 | : m_id(id), m_name(name), m_handle(handle), m_handleString(toString(handle)) {} |
| 28 | |||
| 29 | ✗ | FloorplanObject::FloorplanObject(const Json::Value& value) : m_data(value) { | |
| 30 | ✗ | m_id = m_data.get("id", "").asString(); | |
| 31 | ✗ | m_data.removeMember("id"); | |
| 32 | |||
| 33 | ✗ | m_name = m_data.get("name", "").asString(); | |
| 34 | ✗ | m_data.removeMember("name"); | |
| 35 | |||
| 36 | ✗ | m_handleString = m_data.get("handle", "").asString(); | |
| 37 | ✗ | m_handle = toUUID(m_handleString); | |
| 38 | ✗ | m_data.removeMember("handle"); | |
| 39 | |||
| 40 | // look for different references | ||
| 41 | ✗ | std::string building_unit_id = m_data.get("building_unit_id", "").asString(); | |
| 42 | ✗ | if (!building_unit_id.empty()) { | |
| 43 | ✗ | m_objectReferenceMap.insert(std::make_pair("building_unit_id", FloorplanObject(building_unit_id, "", ""))); | |
| 44 | } | ||
| 45 | ✗ | m_data.removeMember("building_unit_id"); | |
| 46 | |||
| 47 | ✗ | std::string thermal_zone_id = m_data.get("thermal_zone_id", "").asString(); | |
| 48 | ✗ | if (!thermal_zone_id.empty()) { | |
| 49 | ✗ | m_objectReferenceMap.insert(std::make_pair("thermal_zone_id", FloorplanObject(thermal_zone_id, "", ""))); | |
| 50 | } | ||
| 51 | ✗ | m_data.removeMember("thermal_zone_id"); | |
| 52 | |||
| 53 | ✗ | std::string space_type_id = m_data.get("space_type_id", "").asString(); | |
| 54 | ✗ | if (!space_type_id.empty()) { | |
| 55 | ✗ | m_objectReferenceMap.insert(std::make_pair("space_type_id", FloorplanObject(space_type_id, "", ""))); | |
| 56 | } | ||
| 57 | ✗ | m_data.removeMember("space_type_id"); | |
| 58 | |||
| 59 | ✗ | std::string construction_set_id = m_data.get("construction_set_id", "").asString(); | |
| 60 | ✗ | if (!construction_set_id.empty()) { | |
| 61 | ✗ | m_objectReferenceMap.insert(std::make_pair("construction_set_id", FloorplanObject(construction_set_id, "", ""))); | |
| 62 | } | ||
| 63 | ✗ | m_data.removeMember("construction_set_id"); | |
| 64 | |||
| 65 | //windows::window_definition_id | ||
| 66 | |||
| 67 | //daylighting_controls::daylighting_control_definition_id | ||
| 68 | |||
| 69 | //doors::door_definition_id | ||
| 70 | ✗ | } | |
| 71 | |||
| 72 | 4 | std::string FloorplanObject::id() const { | |
| 73 | 4 | return m_id; | |
| 74 | } | ||
| 75 | |||
| 76 | 28 | std::string FloorplanObject::name() const { | |
| 77 | 28 | return m_name; | |
| 78 | } | ||
| 79 | |||
| 80 | ✗ | UUID FloorplanObject::handle() const { | |
| 81 | ✗ | return m_handle; | |
| 82 | } | ||
| 83 | |||
| 84 | 36 | std::string FloorplanObject::handleString() const { | |
| 85 | 36 | return m_handleString; | |
| 86 | } | ||
| 87 | |||
| 88 | 4 | boost::optional<std::string> FloorplanObject::parentHandleString() const { | |
| 89 | 4 | return m_parentHandleString; | |
| 90 | } | ||
| 91 | |||
| 92 | 4 | void FloorplanObject::setParentHandleString(const std::string& parentHandleString) { | |
| 93 | 4 | m_parentHandleString = parentHandleString; | |
| 94 | 4 | } | |
| 95 | |||
| 96 | ✗ | void FloorplanObject::resetParentHandleString() { | |
| 97 | ✗ | m_parentHandleString.reset(); | |
| 98 | ✗ | } | |
| 99 | |||
| 100 | ✗ | boost::optional<double> FloorplanObject::getDataDouble(const std::string& key) const { | |
| 101 | ✗ | Json::Value value = m_data.get(key, Json::nullValue); | |
| 102 | ✗ | if (!value.isNull() && value.isNumeric()) { | |
| 103 | ✗ | return value.asDouble(); | |
| 104 | } | ||
| 105 | ✗ | return boost::none; | |
| 106 | ✗ | } | |
| 107 | |||
| 108 | ✗ | boost::optional<int> FloorplanObject::getDataInt(const std::string& key) const { | |
| 109 | ✗ | Json::Value value = m_data.get(key, Json::nullValue); | |
| 110 | ✗ | if (!value.isNull() && value.isNumeric()) { | |
| 111 | ✗ | return value.asInt(); | |
| 112 | } | ||
| 113 | ✗ | return boost::none; | |
| 114 | ✗ | } | |
| 115 | |||
| 116 | ✗ | boost::optional<bool> FloorplanObject::getDataBool(const std::string& key) const { | |
| 117 | ✗ | Json::Value value = m_data.get(key, Json::nullValue); | |
| 118 | ✗ | if (!value.isNull() && value.isBool()) { | |
| 119 | ✗ | return value.asBool(); | |
| 120 | } | ||
| 121 | ✗ | return boost::none; | |
| 122 | ✗ | } | |
| 123 | |||
| 124 | ✗ | boost::optional<std::string> FloorplanObject::getDataString(const std::string& key) const { | |
| 125 | ✗ | Json::Value value = m_data.get(key, Json::nullValue); | |
| 126 | ✗ | if (!value.isNull() && value.isString()) { | |
| 127 | ✗ | return value.asString(); | |
| 128 | } | ||
| 129 | ✗ | return boost::none; | |
| 130 | ✗ | } | |
| 131 | |||
| 132 | ✗ | boost::optional<FloorplanObject> FloorplanObject::getDataReference(const std::string& key) const { | |
| 133 | ✗ | const auto& it = m_objectReferenceMap.find(key); | |
| 134 | ✗ | if (it != m_objectReferenceMap.end()) { | |
| 135 | ✗ | return it->second; | |
| 136 | } | ||
| 137 | ✗ | return boost::none; | |
| 138 | } | ||
| 139 | |||
| 140 | ✗ | void FloorplanObject::setDataDouble(const std::string& key, double value) { | |
| 141 | ✗ | m_data[key] = value; | |
| 142 | ✗ | } | |
| 143 | |||
| 144 | ✗ | void FloorplanObject::setDataInt(const std::string& key, int value) { | |
| 145 | ✗ | m_data[key] = value; | |
| 146 | ✗ | } | |
| 147 | |||
| 148 | ✗ | void FloorplanObject::setDataBool(const std::string& key, bool value) { | |
| 149 | ✗ | m_data[key] = value; | |
| 150 | ✗ | } | |
| 151 | |||
| 152 | 2 | void FloorplanObject::setDataString(const std::string& key, const std::string& value) { | |
| 153 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | m_data[key] = value; |
| 154 | 2 | } | |
| 155 | |||
| 156 | 4 | void FloorplanObject::setDataReference(const std::string& key, const FloorplanObject& value) { | |
| 157 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | m_objectReferenceMap.insert(std::make_pair(key, value)); |
| 158 | 4 | } | |
| 159 | |||
| 160 | 18 | Json::Value FloorplanObject::data() const { | |
| 161 | 18 | return m_data; | |
| 162 | } | ||
| 163 | |||
| 164 | 18 | std::map<std::string, FloorplanObject> FloorplanObject::objectReferenceMap() const { | |
| 165 | 18 | return m_objectReferenceMap; | |
| 166 | } | ||
| 167 | |||
| 168 | 1 | FloorplanJS::FloorplanJS() : m_value(Json::Value(Json::objectValue)), m_lastId(0) {} | |
| 169 | |||
| 170 | // cppcheck-suppress funcArgNamesDifferent | ||
| 171 | 46 | FloorplanJS::FloorplanJS(const std::string& s) : m_lastId(0) { | |
| 172 |
1/1✓ Branch 1 taken 46 times.
|
46 | Json::CharReaderBuilder rbuilder; |
| 173 |
1/1✓ Branch 1 taken 46 times.
|
46 | std::istringstream ss(s); |
| 174 | 46 | std::string formattedErrors; | |
| 175 |
1/1✓ Branch 1 taken 46 times.
|
46 | bool parsingSuccessful = Json::parseFromStream(rbuilder, ss, &m_value, &formattedErrors); |
| 176 | |||
| 177 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 13 times.
|
46 | if (!parsingSuccessful) { |
| 178 | |||
| 179 | // see if this is a path | ||
| 180 |
1/1✓ Branch 1 taken 33 times.
|
33 | openstudio::path p = toPath(s); |
| 181 |
5/8✓ Branch 1 taken 33 times.
✓ Branch 3 taken 33 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 33 times.
✓ Branch 8 taken 33 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 33 times.
✗ Branch 11 not taken.
|
33 | if (boost::filesystem::exists(p) && boost::filesystem::is_regular_file(p)) { |
| 182 | // open file | ||
| 183 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
|
33 | std::ifstream ifs(openstudio::toSystemFilename(p)); |
| 184 |
1/1✓ Branch 1 taken 33 times.
|
33 | m_value.clear(); |
| 185 | 33 | formattedErrors.clear(); | |
| 186 |
1/1✓ Branch 1 taken 33 times.
|
33 | parsingSuccessful = Json::parseFromStream(rbuilder, ifs, &m_value, &formattedErrors); |
| 187 | 33 | } | |
| 188 | |||
| 189 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 33 times.
|
33 | if (!parsingSuccessful) { |
| 190 | ✗ | LOG_AND_THROW("ThreeJS JSON cannot be processed, " << formattedErrors); | |
| 191 | } | ||
| 192 | 33 | } | |
| 193 | |||
| 194 | // DLM: should update value to current schema | ||
| 195 | // Code in FloorspaceJS, importFloorplan.js, importState | ||
| 196 | // Code in FloorspaceJS, export.js, exportData | ||
| 197 | |||
| 198 |
1/1✓ Branch 1 taken 46 times.
|
46 | setLastId(m_value); |
| 199 | 46 | } | |
| 200 | |||
| 201 | ✗ | FloorplanJS::FloorplanJS(const Json::Value& value) : m_value(value), m_lastId(0) { | |
| 202 | // DLM: should update value to current schema | ||
| 203 | // Code in FloorspaceJS, importFloorplan.js, importState | ||
| 204 | // Code in FloorspaceJS, export.js, exportData | ||
| 205 | // past files for testing: floorspace.js/test/e2e/fixtures/ | ||
| 206 | |||
| 207 | ✗ | setLastId(m_value); | |
| 208 | ✗ | } | |
| 209 | |||
| 210 | 40 | boost::optional<FloorplanJS> FloorplanJS::load(const std::string& json) { | |
| 211 | try { | ||
| 212 |
1/1✓ Branch 1 taken 40 times.
|
40 | FloorplanJS result(json); |
| 213 |
1/1✓ Branch 1 taken 40 times.
|
40 | return result; |
| 214 | 40 | } catch (...) { | |
| 215 | ✗ | LOG(Error, "Could not parse JSON input"); | |
| 216 | ✗ | } | |
| 217 | ✗ | return boost::none; | |
| 218 | } | ||
| 219 | |||
| 220 | 11 | std::string FloorplanJS::toJSON(bool prettyPrint) const { | |
| 221 | // Write to string | ||
| 222 |
1/1✓ Branch 1 taken 11 times.
|
11 | Json::StreamWriterBuilder wbuilder; |
| 223 | |||
| 224 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
|
11 | if (prettyPrint) { |
| 225 | // mimic the old StyledWriter behavior: | ||
| 226 | ✗ | wbuilder["commentStyle"] = "All"; | |
| 227 | // From source, it seems indentation was set to 3 spaces, rather than the new default of '\t' | ||
| 228 | ✗ | wbuilder["indentation"] = " "; | |
| 229 | } else { | ||
| 230 | // mimic the old FastWriter behavior: | ||
| 231 |
3/3✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
|
33 | wbuilder["commentStyle"] = "None"; |
| 232 |
3/3✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
|
33 | wbuilder["indentation"] = ""; |
| 233 | } | ||
| 234 | |||
| 235 |
1/1✓ Branch 1 taken 11 times.
|
11 | std::string result = Json::writeString(wbuilder, m_value); |
| 236 | |||
| 237 | 22 | return result; | |
| 238 | 11 | } | |
| 239 | |||
| 240 | 38512 | size_t getVertexIndex(const Point3d& point3d, std::vector<Point3d>& allPoints, double tol = 0.001) { | |
| 241 | 38512 | size_t n = allPoints.size(); | |
| 242 |
2/2✓ Branch 0 taken 82562 times.
✓ Branch 1 taken 38428 times.
|
120990 | for (size_t i = 0; i < n; ++i) { |
| 243 | 82562 | if (std::sqrt(std::pow(point3d.x() - allPoints[i].x(), 2) + std::pow(point3d.y() - allPoints[i].y(), 2) | |
| 244 | 82562 | + std::pow(point3d.z() - allPoints[i].z(), 2)) | |
| 245 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 82478 times.
|
82562 | < tol) { |
| 246 | 84 | return i; | |
| 247 | } | ||
| 248 | } | ||
| 249 | 38428 | allPoints.push_back(point3d); | |
| 250 | 38428 | return (allPoints.size() - 1); | |
| 251 | } | ||
| 252 | |||
| 253 | 8452 | std::string FloorplanJS::makeSurface(const Json::Value& story, const Json::Value& spaceOrShading, const std::string& parentSurfaceName, | |
| 254 | const std::string& parentSubSurfaceName, bool belowFloorPlenum, bool aboveCeilingPlenum, | ||
| 255 | const std::string& surfaceType, const Point3dVectorVector& finalFaceVertices, size_t faceFormat, | ||
| 256 | std::vector<ThreeGeometry>& geometries, std::vector<ThreeSceneChild>& sceneChildren, double illuminanceSetpoint, | ||
| 257 | bool airWall) const { | ||
| 258 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | std::string finalSurfaceType = surfaceType; |
| 259 | |||
| 260 | 8452 | bool isShading = false; | |
| 261 | 8452 | bool isSpace = false; | |
| 262 |
2/2✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
|
16904 | assertKeyAndType(spaceOrShading, "type", Json::stringValue); |
| 263 |
3/3✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 8452 times.
|
8452 | std::string type = spaceOrShading.get("type", "").asString(); |
| 264 |
4/4✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 8008 times.
✓ Branch 8 taken 444 times.
|
16904 | if (istringEqual(type, "space")) { |
| 265 | 8008 | isSpace = true; | |
| 266 |
3/4✓ Branch 1 taken 444 times.
✓ Branch 4 taken 444 times.
✓ Branch 7 taken 444 times.
✗ Branch 8 not taken.
|
888 | } else if (istringEqual(type, "shading")) { |
| 267 | 444 | isShading = true; | |
| 268 | // DLM: TODO add key to distinguish site and building shading | ||
| 269 |
1/1✓ Branch 1 taken 444 times.
|
444 | finalSurfaceType = "SiteShading"; |
| 270 | } else { | ||
| 271 | ✗ | LOG(Error, "Unknown type '" << type << "'"); | |
| 272 | } | ||
| 273 | |||
| 274 | 8452 | bool plenum = false; | |
| 275 | 8452 | std::string spaceOrShadingNamePostFix; | |
| 276 |
2/2✓ Branch 0 taken 86 times.
✓ Branch 1 taken 8366 times.
|
8452 | if (belowFloorPlenum) { |
| 277 | 86 | plenum = true; | |
| 278 |
1/1✓ Branch 1 taken 86 times.
|
86 | spaceOrShadingNamePostFix = BELOWFLOORPLENUMPOSTFIX; |
| 279 |
2/2✓ Branch 0 taken 92 times.
✓ Branch 1 taken 8274 times.
|
8366 | } else if (aboveCeilingPlenum) { |
| 280 | 92 | plenum = true; | |
| 281 |
1/1✓ Branch 1 taken 92 times.
|
92 | spaceOrShadingNamePostFix = ABOVECEILINGPLENUMPOSTFIX; |
| 282 | } | ||
| 283 | |||
| 284 |
3/3✓ Branch 2 taken 8452 times.
✓ Branch 5 taken 8452 times.
✓ Branch 8 taken 8452 times.
|
25356 | std::string geometryId = std::string("Geometry ") + std::to_string(geometries.size()); |
| 285 |
3/3✓ Branch 2 taken 8452 times.
✓ Branch 5 taken 8452 times.
✓ Branch 8 taken 8452 times.
|
25356 | std::string faceId = std::string("Face ") + std::to_string(geometries.size()); |
| 286 | |||
| 287 | 8452 | Point3dVector allVertices; | |
| 288 | 8452 | std::vector<size_t> faceIndices; | |
| 289 |
2/2✓ Branch 5 taken 8494 times.
✓ Branch 6 taken 8452 times.
|
16946 | for (const auto& finalFaceVerts : finalFaceVertices) { |
| 290 |
1/1✓ Branch 1 taken 8494 times.
|
8494 | faceIndices.push_back(faceFormat); |
| 291 |
2/2✓ Branch 4 taken 38512 times.
✓ Branch 5 taken 8494 times.
|
47006 | for (const auto& vert : finalFaceVerts) { |
| 292 |
2/2✓ Branch 1 taken 38512 times.
✓ Branch 4 taken 38512 times.
|
38512 | faceIndices.push_back(getVertexIndex(vert, allVertices)); |
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 296 | { | ||
| 297 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | std::string uuid = geometryId; |
| 298 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | type = "Geometry"; |
| 299 |
2/2✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
|
8452 | ThreeGeometryData data(toThreeVector(allVertices), faceIndices); |
| 300 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | ThreeGeometry geometry(uuid, type, data); |
| 301 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | geometries.push_back(geometry); |
| 302 | 8452 | } | |
| 303 | |||
| 304 | { | ||
| 305 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | std::string uuid = faceId; |
| 306 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | std::string name = faceId; |
| 307 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | type = "Mesh"; |
| 308 | 8452 | std::string materialId; | |
| 309 | |||
| 310 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | ThreeUserData userData; |
| 311 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | userData.setName(faceId); |
| 312 | |||
| 313 | 8452 | std::string s; | |
| 314 | 8452 | std::string id; | |
| 315 | |||
| 316 | // story | ||
| 317 |
2/2✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
|
16904 | assertKeyAndType(story, "name", Json::stringValue); |
| 318 |
3/3✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 8452 times.
|
8452 | s = story.get("name", "").asString(); |
| 319 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | userData.setBuildingStoryName(s); |
| 320 |
3/3✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 8452 times.
|
8452 | userData.setBuildingStoryMaterialName(getObjectThreeMaterialName("OS:BuildingStory", s)); |
| 321 | |||
| 322 |
4/4✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 806 times.
✓ Branch 8 taken 7646 times.
|
25356 | if (checkKeyAndType(story, "handle", Json::stringValue)) { |
| 323 |
3/3✓ Branch 1 taken 806 times.
✓ Branch 4 taken 806 times.
✓ Branch 7 taken 806 times.
|
806 | s = story.get("handle", "").asString(); |
| 324 |
1/1✓ Branch 1 taken 806 times.
|
806 | userData.setBuildingStoryHandle(s); |
| 325 | } | ||
| 326 | |||
| 327 | // space or shading | ||
| 328 |
2/2✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
|
16904 | assertKeyAndType(spaceOrShading, "name", Json::stringValue); |
| 329 |
3/3✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 8452 times.
|
8452 | s = spaceOrShading.get("name", "").asString(); |
| 330 |
2/2✓ Branch 0 taken 8008 times.
✓ Branch 1 taken 444 times.
|
8452 | if (isSpace) { |
| 331 |
2/2✓ Branch 1 taken 8008 times.
✓ Branch 4 taken 8008 times.
|
8008 | userData.setSpaceName(s + spaceOrShadingNamePostFix); |
| 332 |
1/2✓ Branch 0 taken 444 times.
✗ Branch 1 not taken.
|
444 | } else if (isShading) { |
| 333 |
2/2✓ Branch 1 taken 444 times.
✓ Branch 4 taken 444 times.
|
444 | userData.setShadingName(s + spaceOrShadingNamePostFix); |
| 334 | } | ||
| 335 | |||
| 336 |
4/4✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 784 times.
✓ Branch 8 taken 7668 times.
|
25356 | if (checkKeyAndType(spaceOrShading, "handle", Json::stringValue)) { |
| 337 |
3/3✓ Branch 1 taken 784 times.
✓ Branch 4 taken 784 times.
✓ Branch 7 taken 784 times.
|
784 | s = spaceOrShading.get("handle", "").asString(); |
| 338 |
1/2✓ Branch 0 taken 784 times.
✗ Branch 1 not taken.
|
784 | if (isSpace) { |
| 339 |
1/1✓ Branch 1 taken 784 times.
|
784 | userData.setSpaceHandle(s); |
| 340 | ✗ | } else if (isShading) { | |
| 341 | ✗ | userData.setShadingHandle(s); | |
| 342 | } | ||
| 343 | } | ||
| 344 | |||
| 345 | // parent surface | ||
| 346 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | userData.setSurfaceName(parentSurfaceName); |
| 347 | |||
| 348 | // parent sub surface | ||
| 349 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | userData.setSubSurfaceName(parentSubSurfaceName); |
| 350 | |||
| 351 | // building unit | ||
| 352 |
4/4✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 542 times.
✓ Branch 8 taken 7910 times.
|
25356 | if (checkKeyAndType(spaceOrShading, "building_unit_id", Json::stringValue)) { |
| 353 |
3/3✓ Branch 1 taken 542 times.
✓ Branch 4 taken 542 times.
✓ Branch 7 taken 542 times.
|
542 | id = spaceOrShading.get("building_unit_id", "").asString(); |
| 354 |
4/4✓ Branch 1 taken 542 times.
✓ Branch 4 taken 542 times.
✓ Branch 6 taken 466 times.
✓ Branch 7 taken 76 times.
|
542 | if (const Json::Value* buildingUnit = findById(m_value["building_units"], id)) { |
| 355 |
2/2✓ Branch 1 taken 466 times.
✓ Branch 4 taken 466 times.
|
932 | assertKeyAndType(*buildingUnit, "name", Json::stringValue); |
| 356 |
3/3✓ Branch 1 taken 466 times.
✓ Branch 4 taken 466 times.
✓ Branch 7 taken 466 times.
|
466 | s = buildingUnit->get("name", "").asString(); |
| 357 |
1/1✓ Branch 1 taken 466 times.
|
466 | userData.setBuildingUnitName(s); |
| 358 |
3/3✓ Branch 1 taken 466 times.
✓ Branch 4 taken 466 times.
✓ Branch 7 taken 466 times.
|
466 | userData.setBuildingUnitMaterialName(getObjectThreeMaterialName("OS:BuildingUnit", s)); |
| 359 | |||
| 360 |
4/4✓ Branch 1 taken 466 times.
✓ Branch 4 taken 466 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 460 times.
|
1398 | if (checkKeyAndType(*buildingUnit, "handle", Json::stringValue)) { |
| 361 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | s = buildingUnit->get("handle", "").asString(); |
| 362 |
1/1✓ Branch 1 taken 6 times.
|
6 | userData.setBuildingUnitHandle(s); |
| 363 | } | ||
| 364 | } else { | ||
| 365 |
7/7✓ Branch 1 taken 76 times.
✓ Branch 4 taken 76 times.
✓ Branch 7 taken 76 times.
✓ Branch 10 taken 76 times.
✓ Branch 13 taken 76 times.
✓ Branch 16 taken 76 times.
✓ Branch 19 taken 76 times.
|
76 | LOG(Error, "Cannot find BuildingUnit '" << id << "'"); |
| 366 | } | ||
| 367 | } | ||
| 368 | |||
| 369 | // thermal zone | ||
| 370 |
4/4✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 6999 times.
✓ Branch 8 taken 1453 times.
|
25356 | if (checkKeyAndType(spaceOrShading, "thermal_zone_id", Json::stringValue)) { |
| 371 |
3/3✓ Branch 1 taken 6999 times.
✓ Branch 4 taken 6999 times.
✓ Branch 7 taken 6999 times.
|
6999 | id = spaceOrShading.get("thermal_zone_id", "").asString(); |
| 372 |
3/4✓ Branch 1 taken 6999 times.
✓ Branch 4 taken 6999 times.
✓ Branch 6 taken 6999 times.
✗ Branch 7 not taken.
|
6999 | if (const Json::Value* thermalZone = findById(m_value["thermal_zones"], id)) { |
| 373 |
2/2✓ Branch 1 taken 6999 times.
✓ Branch 4 taken 6999 times.
|
13998 | assertKeyAndType(*thermalZone, "name", Json::stringValue); |
| 374 |
3/3✓ Branch 1 taken 6999 times.
✓ Branch 4 taken 6999 times.
✓ Branch 7 taken 6999 times.
|
6999 | s = thermalZone->get("name", "").asString(); |
| 375 |
1/1✓ Branch 1 taken 6999 times.
|
6999 | std::string thermalZoneName = s + spaceOrShadingNamePostFix; |
| 376 |
1/1✓ Branch 1 taken 6999 times.
|
6999 | userData.setThermalZoneName(thermalZoneName); |
| 377 |
3/3✓ Branch 1 taken 6999 times.
✓ Branch 4 taken 6999 times.
✓ Branch 7 taken 6999 times.
|
6999 | userData.setThermalZoneMaterialName(getObjectThreeMaterialName("OS:ThermalZone", s)); |
| 378 | |||
| 379 |
2/2✓ Branch 0 taken 112 times.
✓ Branch 1 taken 6887 times.
|
6999 | if (plenum) { |
| 380 | // DLM: we do not have this plenum thermal zone in the floorplan so user can't edit its properties | ||
| 381 |
1/1✓ Branch 1 taken 112 times.
|
112 | m_plenumThermalZoneNames.insert(thermalZoneName); |
| 382 | |||
| 383 | // reset to ThermalZone_Plenum in makeStandardThreeMaterials | ||
| 384 |
4/4✓ Branch 1 taken 112 times.
✓ Branch 4 taken 112 times.
✓ Branch 7 taken 112 times.
✓ Branch 10 taken 112 times.
|
448 | userData.setThermalZoneMaterialName(getObjectThreeMaterialName("OS:ThermalZone", "Plenum")); |
| 385 | } else { | ||
| 386 |
4/4✓ Branch 1 taken 6887 times.
✓ Branch 4 taken 6887 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 6881 times.
|
20661 | if (checkKeyAndType(*thermalZone, "handle", Json::stringValue)) { |
| 387 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | s = thermalZone->get("handle", "").asString(); |
| 388 |
1/1✓ Branch 1 taken 6 times.
|
6 | userData.setThermalZoneHandle(s); |
| 389 | } | ||
| 390 | } | ||
| 391 | 6999 | } else { | |
| 392 | ✗ | LOG(Error, "Cannot find ThermalZone '" << id << "'"); | |
| 393 | } | ||
| 394 | } | ||
| 395 | |||
| 396 | // space type | ||
| 397 |
2/2✓ Branch 0 taken 178 times.
✓ Branch 1 taken 8274 times.
|
8452 | if (plenum) { |
| 398 |
2/2✓ Branch 1 taken 178 times.
✓ Branch 4 taken 178 times.
|
356 | userData.setSpaceTypeName(PLENUMSPACETYPENAME); |
| 399 |
4/4✓ Branch 1 taken 178 times.
✓ Branch 4 taken 178 times.
✓ Branch 7 taken 178 times.
✓ Branch 10 taken 178 times.
|
712 | userData.setSpaceTypeMaterialName(getObjectThreeMaterialName("OS:SpaceType", "Plenum")); |
| 400 | } else { | ||
| 401 |
4/4✓ Branch 1 taken 8274 times.
✓ Branch 4 taken 8274 times.
✓ Branch 7 taken 7501 times.
✓ Branch 8 taken 773 times.
|
24822 | if (checkKeyAndType(spaceOrShading, "space_type_id", Json::stringValue)) { |
| 402 |
3/3✓ Branch 1 taken 7501 times.
✓ Branch 4 taken 7501 times.
✓ Branch 7 taken 7501 times.
|
7501 | id = spaceOrShading.get("space_type_id", "").asString(); |
| 403 |
4/4✓ Branch 1 taken 7501 times.
✓ Branch 4 taken 7501 times.
✓ Branch 6 taken 7425 times.
✓ Branch 7 taken 76 times.
|
7501 | if (const Json::Value* spaceType = findById(m_value["space_types"], id)) { |
| 404 |
2/2✓ Branch 1 taken 7425 times.
✓ Branch 4 taken 7425 times.
|
14850 | assertKeyAndType(*spaceType, "name", Json::stringValue); |
| 405 |
3/3✓ Branch 1 taken 7425 times.
✓ Branch 4 taken 7425 times.
✓ Branch 7 taken 7425 times.
|
7425 | s = spaceType->get("name", "").asString(); |
| 406 |
1/1✓ Branch 1 taken 7425 times.
|
7425 | userData.setSpaceTypeName(s); |
| 407 |
3/3✓ Branch 1 taken 7425 times.
✓ Branch 4 taken 7425 times.
✓ Branch 7 taken 7425 times.
|
7425 | userData.setSpaceTypeMaterialName(getObjectThreeMaterialName("OS:SpaceType", s)); |
| 408 | |||
| 409 |
4/4✓ Branch 1 taken 7425 times.
✓ Branch 4 taken 7425 times.
✓ Branch 7 taken 772 times.
✓ Branch 8 taken 6653 times.
|
22275 | if (checkKeyAndType(*spaceType, "handle", Json::stringValue)) { |
| 410 |
3/3✓ Branch 1 taken 772 times.
✓ Branch 4 taken 772 times.
✓ Branch 7 taken 772 times.
|
772 | s = spaceType->get("handle", "").asString(); |
| 411 |
1/1✓ Branch 1 taken 772 times.
|
772 | userData.setSpaceTypeHandle(s); |
| 412 | } | ||
| 413 | } else { | ||
| 414 |
7/7✓ Branch 1 taken 76 times.
✓ Branch 4 taken 76 times.
✓ Branch 7 taken 76 times.
✓ Branch 10 taken 76 times.
✓ Branch 13 taken 76 times.
✓ Branch 16 taken 76 times.
✓ Branch 19 taken 76 times.
|
76 | LOG(Error, "Cannot find SpaceType '" << id << "'"); |
| 415 | } | ||
| 416 | } | ||
| 417 | } | ||
| 418 | |||
| 419 | // construction set | ||
| 420 |
4/4✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
✓ Branch 7 taken 548 times.
✓ Branch 8 taken 7904 times.
|
25356 | if (checkKeyAndType(spaceOrShading, "construction_set_id", Json::stringValue)) { |
| 421 |
3/3✓ Branch 1 taken 548 times.
✓ Branch 4 taken 548 times.
✓ Branch 7 taken 548 times.
|
548 | id = spaceOrShading.get("construction_set_id", "").asString(); |
| 422 |
4/4✓ Branch 1 taken 548 times.
✓ Branch 4 taken 548 times.
✓ Branch 6 taken 472 times.
✓ Branch 7 taken 76 times.
|
548 | if (const Json::Value* constructionSet = findById(m_value["construction_sets"], id)) { |
| 423 |
2/2✓ Branch 1 taken 472 times.
✓ Branch 4 taken 472 times.
|
944 | assertKeyAndType(*constructionSet, "name", Json::stringValue); |
| 424 |
3/3✓ Branch 1 taken 472 times.
✓ Branch 4 taken 472 times.
✓ Branch 7 taken 472 times.
|
472 | s = constructionSet->get("name", "").asString(); |
| 425 |
1/1✓ Branch 1 taken 472 times.
|
472 | userData.setConstructionSetName(s); |
| 426 | //userData.setConstructionSetNameMaterialName(getObjectThreeMaterialName("OS:DefaultConstructionSet", s)); | ||
| 427 | |||
| 428 |
4/4✓ Branch 1 taken 472 times.
✓ Branch 4 taken 472 times.
✓ Branch 7 taken 6 times.
✓ Branch 8 taken 466 times.
|
1416 | if (checkKeyAndType(*constructionSet, "handle", Json::stringValue)) { |
| 429 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | s = constructionSet->get("handle", "").asString(); |
| 430 |
1/1✓ Branch 1 taken 6 times.
|
6 | userData.setConstructionSetHandle(s); |
| 431 | } | ||
| 432 | } else { | ||
| 433 |
7/7✓ Branch 1 taken 76 times.
✓ Branch 4 taken 76 times.
✓ Branch 7 taken 76 times.
✓ Branch 10 taken 76 times.
✓ Branch 13 taken 76 times.
✓ Branch 16 taken 76 times.
✓ Branch 19 taken 76 times.
|
76 | LOG(Error, "Cannot find ConstructionSet '" << id << "'"); |
| 434 | } | ||
| 435 | } | ||
| 436 | |||
| 437 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | userData.setSurfaceType(finalSurfaceType); |
| 438 |
2/2✓ Branch 1 taken 8452 times.
✓ Branch 4 taken 8452 times.
|
8452 | userData.setSurfaceTypeMaterialName(getSurfaceTypeThreeMaterialName(finalSurfaceType)); |
| 439 | //userData.setAboveCeilingPlenum(aboveCeilingPlenum); | ||
| 440 | //userData.setBelowFloorPlenum(belowFloorPlenum); | ||
| 441 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | userData.setIlluminanceSetpoint(illuminanceSetpoint); |
| 442 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | userData.setAirWall(airWall); |
| 443 | |||
| 444 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | ThreeSceneChild sceneChild(uuid, name, type, geometryId, materialId, userData); |
| 445 |
1/1✓ Branch 1 taken 8452 times.
|
8452 | sceneChildren.push_back(sceneChild); |
| 446 | 8452 | } | |
| 447 | |||
| 448 | 16904 | return faceId; | |
| 449 | 8452 | } | |
| 450 | |||
| 451 | 864 | void FloorplanJS::makeGeometries(const Json::Value& story, const Json::Value& spaceOrShading, bool belowFloorPlenum, bool aboveCeilingPlenum, | |
| 452 | double lengthToMeters, double minZ, double maxZ, const Json::Value& vertices, const Json::Value& edges, | ||
| 453 | const Json::Value& faces, const std::string& faceId, bool openstudioFormat, std::vector<ThreeGeometry>& geometries, | ||
| 454 | std::vector<ThreeSceneChild>& sceneChildren, bool openToBelow) const { | ||
| 455 | 864 | std::vector<Point3d> faceVertices; | |
| 456 | 864 | std::vector<Point3d> windowCenterVertices; | |
| 457 | 864 | std::vector<std::string> windowDefinitionIds; | |
| 458 | // TODO? std::vector<Point3d> daylightingControlVertices; | ||
| 459 | 864 | std::vector<Point3d> doorCenterVertices; | |
| 460 | 864 | std::vector<std::string> doorDefinitionIds; | |
| 461 | |||
| 462 |
2/2✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
|
864 | const Json::Value windowDefinitions = m_value.get("window_definitions", Json::arrayValue); |
| 463 |
2/2✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
|
864 | const Json::Value daylightingControlDefinitions = m_value.get("daylighting_control_definitions", Json::arrayValue); |
| 464 |
2/2✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
|
864 | const Json::Value doorDefinitions = m_value.get("door_definitions", Json::arrayValue); |
| 465 | |||
| 466 | // get all the windows on this story unless this is a plenum | ||
| 467 | 864 | std::map<std::string, std::vector<Json::Value>> edgeIdToWindowsMap; | |
| 468 |
4/4✓ Branch 0 taken 850 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 835 times.
✓ Branch 3 taken 15 times.
|
864 | if (!belowFloorPlenum && !aboveCeilingPlenum) { |
| 469 |
9/9✓ Branch 1 taken 835 times.
✓ Branch 4 taken 835 times.
✓ Branch 8 taken 835 times.
✓ Branch 11 taken 835 times.
✓ Branch 14 taken 13750 times.
✓ Branch 17 taken 13750 times.
✓ Branch 20 taken 14585 times.
✓ Branch 22 taken 13750 times.
✓ Branch 23 taken 835 times.
|
14585 | for (const auto& window : story.get("windows", Json::arrayValue)) { |
| 470 |
2/2✓ Branch 1 taken 13750 times.
✓ Branch 4 taken 13750 times.
|
27500 | assertKeyAndType(window, "edge_id", Json::stringValue); |
| 471 | |||
| 472 |
3/3✓ Branch 1 taken 13750 times.
✓ Branch 4 taken 13750 times.
✓ Branch 7 taken 13750 times.
|
13750 | std::string edgeId = window.get("edge_id", "").asString(); |
| 473 |
3/3✓ Branch 2 taken 13750 times.
✓ Branch 5 taken 8520 times.
✓ Branch 6 taken 5230 times.
|
13750 | if (edgeIdToWindowsMap.find(edgeId) == edgeIdToWindowsMap.end()) { |
| 474 | // cppcheck-suppress stlFindInsert | ||
| 475 |
1/1✓ Branch 2 taken 8520 times.
|
8520 | edgeIdToWindowsMap[edgeId] = std::vector<Json::Value>(); |
| 476 | } | ||
| 477 |
2/2✓ Branch 1 taken 13750 times.
✓ Branch 4 taken 13750 times.
|
13750 | edgeIdToWindowsMap[edgeId].push_back(window); |
| 478 | 14585 | } | |
| 479 | } | ||
| 480 | |||
| 481 | // get all the doors on this story unless this is a plenum | ||
| 482 | 864 | std::map<std::string, std::vector<Json::Value>> edgeIdToDoorsMap; | |
| 483 |
4/4✓ Branch 0 taken 850 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 835 times.
✓ Branch 3 taken 15 times.
|
864 | if (!belowFloorPlenum && !aboveCeilingPlenum) { |
| 484 |
9/9✓ Branch 1 taken 835 times.
✓ Branch 4 taken 835 times.
✓ Branch 8 taken 835 times.
✓ Branch 11 taken 835 times.
✓ Branch 14 taken 46 times.
✓ Branch 17 taken 46 times.
✓ Branch 20 taken 881 times.
✓ Branch 22 taken 46 times.
✓ Branch 23 taken 835 times.
|
881 | for (const auto& door : story.get("doors", Json::arrayValue)) { |
| 485 |
2/2✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
|
92 | assertKeyAndType(door, "edge_id", Json::stringValue); |
| 486 | |||
| 487 |
3/3✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
✓ Branch 7 taken 46 times.
|
46 | std::string edgeId = door.get("edge_id", "").asString(); |
| 488 |
3/3✓ Branch 2 taken 46 times.
✓ Branch 5 taken 29 times.
✓ Branch 6 taken 17 times.
|
46 | if (edgeIdToDoorsMap.find(edgeId) == edgeIdToDoorsMap.end()) { |
| 489 | // cppcheck-suppress stlFindInsert | ||
| 490 |
1/1✓ Branch 2 taken 29 times.
|
29 | edgeIdToDoorsMap[edgeId] = std::vector<Json::Value>(); |
| 491 | } | ||
| 492 |
2/2✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
|
46 | edgeIdToDoorsMap[edgeId].push_back(door); |
| 493 | 881 | } | |
| 494 | } | ||
| 495 | |||
| 496 | // get the face | ||
| 497 |
1/1✓ Branch 1 taken 864 times.
|
864 | const Json::Value* face = findById(faces, faceId); |
| 498 |
1/2✓ Branch 0 taken 864 times.
✗ Branch 1 not taken.
|
864 | if (face) { |
| 499 | |||
| 500 | // get the edges | ||
| 501 |
2/2✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
|
864 | Json::Value edgeIds = face->get("edge_ids", Json::arrayValue); |
| 502 |
2/2✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
|
864 | Json::Value edgeOrders = face->get("edge_order", Json::arrayValue); |
| 503 |
1/1✓ Branch 1 taken 864 times.
|
864 | Json::ArrayIndex edgeN = edgeIds.size(); |
| 504 |
2/4✓ Branch 1 taken 864 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 864 times.
✗ Branch 6 not taken.
|
864 | OS_ASSERT(edgeN == edgeOrders.size()); |
| 505 | |||
| 506 | // loop over edges | ||
| 507 |
2/2✓ Branch 0 taken 5771 times.
✓ Branch 1 taken 864 times.
|
6635 | for (Json::ArrayIndex edgeIdx = 0; edgeIdx < edgeN; ++edgeIdx) { |
| 508 |
2/2✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
|
5771 | std::string edgeId = edgeIds[edgeIdx].asString(); |
| 509 |
2/2✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
|
5771 | unsigned edgeOrder = edgeOrders[edgeIdx].asUInt(); |
| 510 | |||
| 511 | // get the edge | ||
| 512 |
1/1✓ Branch 1 taken 5771 times.
|
5771 | const Json::Value* edge = findById(edges, edgeId); |
| 513 |
1/2✓ Branch 0 taken 5771 times.
✗ Branch 1 not taken.
|
5771 | if (edge) { |
| 514 |
2/2✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
|
5771 | Json::Value vertexIds = edge->get("vertex_ids", Json::arrayValue); |
| 515 |
2/4✓ Branch 1 taken 5771 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5771 times.
✗ Branch 6 not taken.
|
5771 | OS_ASSERT(2u == vertexIds.size()); |
| 516 | |||
| 517 | // get the vertices | ||
| 518 | const Json::Value* nextVertex; | ||
| 519 |
3/3✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
✓ Branch 7 taken 5771 times.
|
5771 | const Json::Value* vertex1 = findById(vertices, vertexIds[0].asString()); |
| 520 |
3/3✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
✓ Branch 7 taken 5771 times.
|
5771 | const Json::Value* vertex2 = findById(vertices, vertexIds[1].asString()); |
| 521 | |||
| 522 |
2/2✓ Branch 0 taken 4022 times.
✓ Branch 1 taken 1749 times.
|
5771 | if (edgeOrder == 1) { |
| 523 | 4022 | nextVertex = vertex1; | |
| 524 | } else { | ||
| 525 | 1749 | nextVertex = vertex2; | |
| 526 | } | ||
| 527 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 5771 times.
✗ Branch 3 not taken.
|
5771 | OS_ASSERT(nextVertex); |
| 528 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 5771 times.
✗ Branch 3 not taken.
|
5771 | OS_ASSERT(vertex1); |
| 529 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 5771 times.
✗ Branch 3 not taken.
|
5771 | OS_ASSERT(vertex2); |
| 530 | |||
| 531 |
2/2✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
|
11542 | assertKeyAndType(*nextVertex, "x", Json::realValue); |
| 532 |
2/2✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
|
11542 | assertKeyAndType(*nextVertex, "y", Json::realValue); |
| 533 |
1/1✓ Branch 1 taken 5771 times.
|
5771 | faceVertices.push_back( |
| 534 |
7/7✓ Branch 1 taken 5771 times.
✓ Branch 4 taken 5771 times.
✓ Branch 7 taken 5771 times.
✓ Branch 10 taken 5771 times.
✓ Branch 13 taken 5771 times.
✓ Branch 16 taken 5771 times.
✓ Branch 19 taken 5771 times.
|
11542 | Point3d(lengthToMeters * nextVertex->get("x", 0.0).asDouble(), lengthToMeters * nextVertex->get("y", 0.0).asDouble(), 0.0)); |
| 535 | |||
| 536 | // check if there are windows on this edge | ||
| 537 |
3/3✓ Branch 2 taken 5771 times.
✓ Branch 5 taken 565 times.
✓ Branch 6 taken 5206 times.
|
5771 | if (edgeIdToWindowsMap.find(edgeId) != edgeIdToWindowsMap.end()) { |
| 538 |
2/2✓ Branch 1 taken 565 times.
✓ Branch 4 taken 565 times.
|
565 | std::vector<Json::Value> windows = edgeIdToWindowsMap[edgeId]; |
| 539 |
2/2✓ Branch 5 taken 830 times.
✓ Branch 6 taken 565 times.
|
1395 | for (const auto& window : windows) { |
| 540 |
2/2✓ Branch 1 taken 830 times.
✓ Branch 4 taken 830 times.
|
1660 | assertKeyAndType(window, "window_definition_id", Json::stringValue); |
| 541 |
3/3✓ Branch 1 taken 830 times.
✓ Branch 4 taken 830 times.
✓ Branch 7 taken 830 times.
|
830 | std::string windowDefinitionId = window.get("window_definition_id", "").asString(); |
| 542 | |||
| 543 | 830 | std::vector<double> alphas; | |
| 544 | // do an extra check here to avoid a warning message | ||
| 545 |
8/9✓ Branch 1 taken 830 times.
✓ Branch 3 taken 830 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 830 times.
✓ Branch 9 taken 830 times.
✓ Branch 11 taken 829 times.
✓ Branch 12 taken 1 time.
✓ Branch 13 taken 829 times.
✓ Branch 14 taken 1 time.
|
830 | if (window.isMember("alpha") && window["alpha"].isConvertibleTo(Json::realValue)) { |
| 546 |
3/4✓ Branch 1 taken 829 times.
✓ Branch 4 taken 829 times.
✓ Branch 7 taken 829 times.
✗ Branch 8 not taken.
|
2487 | if (checkKeyAndType(window, "alpha", Json::realValue)) { |
| 547 |
4/4✓ Branch 1 taken 829 times.
✓ Branch 4 taken 829 times.
✓ Branch 7 taken 829 times.
✓ Branch 10 taken 829 times.
|
829 | alphas.push_back(window.get("alpha", 0.0).asDouble()); |
| 548 | } | ||
| 549 | } else { | ||
| 550 |
3/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
3 | if (checkKeyAndType(window, "alpha", Json::arrayValue)) { |
| 551 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | Json::Value temp = window.get("alpha", Json::arrayValue); |
| 552 |
1/1✓ Branch 1 taken 1 time.
|
1 | Json::ArrayIndex tempN = temp.size(); |
| 553 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 1 time.
|
18 | for (Json::ArrayIndex tempIdx = 0; tempIdx < tempN; ++tempIdx) { |
| 554 |
3/3✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
|
17 | alphas.push_back(temp[tempIdx].asDouble()); |
| 555 | } | ||
| 556 | 1 | } | |
| 557 | } | ||
| 558 | |||
| 559 |
2/2✓ Branch 4 taken 846 times.
✓ Branch 5 taken 830 times.
|
1676 | for (const auto& alpha : alphas) { |
| 560 |
6/6✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
✓ Branch 7 taken 846 times.
✓ Branch 10 taken 846 times.
✓ Branch 13 taken 846 times.
✓ Branch 16 taken 846 times.
|
846 | double x = (1.0 - alpha) * vertex1->get("x", 0.0).asDouble() + alpha * vertex2->get("x", 0.0).asDouble(); |
| 561 |
6/6✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
✓ Branch 7 taken 846 times.
✓ Branch 10 taken 846 times.
✓ Branch 13 taken 846 times.
✓ Branch 16 taken 846 times.
|
846 | double y = (1.0 - alpha) * vertex1->get("y", 0.0).asDouble() + alpha * vertex2->get("y", 0.0).asDouble(); |
| 562 | |||
| 563 |
1/1✓ Branch 1 taken 846 times.
|
846 | windowDefinitionIds.push_back(windowDefinitionId); |
| 564 |
2/2✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
|
846 | windowCenterVertices.push_back(Point3d(lengthToMeters * x, lengthToMeters * y, 0.0)); |
| 565 | } | ||
| 566 | 830 | } | |
| 567 | 565 | } | |
| 568 | |||
| 569 | // check if there are doors on this edge | ||
| 570 |
3/3✓ Branch 2 taken 5771 times.
✓ Branch 5 taken 15 times.
✓ Branch 6 taken 5756 times.
|
5771 | if (edgeIdToDoorsMap.find(edgeId) != edgeIdToDoorsMap.end()) { |
| 571 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
|
15 | std::vector<Json::Value> doors = edgeIdToDoorsMap[edgeId]; |
| 572 |
2/2✓ Branch 5 taken 26 times.
✓ Branch 6 taken 15 times.
|
41 | for (const auto& door : doors) { |
| 573 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
52 | assertKeyAndType(door, "door_definition_id", Json::stringValue); |
| 574 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
|
26 | std::string doorDefinitionId = door.get("door_definition_id", "").asString(); |
| 575 | |||
| 576 | 26 | std::vector<double> alphas; | |
| 577 |
3/4✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
|
78 | if (checkKeyAndType(door, "alpha", Json::realValue)) { |
| 578 |
4/4✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
✓ Branch 10 taken 26 times.
|
26 | alphas.push_back(door.get("alpha", 0.0).asDouble()); |
| 579 | ✗ | } else if (checkKeyAndType(door, "alpha", Json::arrayValue)) { | |
| 580 | ✗ | Json::Value temp = door.get("alpha", Json::arrayValue); | |
| 581 | ✗ | Json::ArrayIndex tempN = temp.size(); | |
| 582 | ✗ | for (Json::ArrayIndex tempIdx = 0; tempIdx < tempN; ++tempIdx) { | |
| 583 | ✗ | alphas.push_back(temp[tempIdx].asDouble()); | |
| 584 | } | ||
| 585 | ✗ | } | |
| 586 | |||
| 587 |
2/2✓ Branch 4 taken 26 times.
✓ Branch 5 taken 26 times.
|
52 | for (const auto& alpha : alphas) { |
| 588 |
6/6✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
✓ Branch 10 taken 26 times.
✓ Branch 13 taken 26 times.
✓ Branch 16 taken 26 times.
|
26 | double x = (1.0 - alpha) * vertex1->get("x", 0.0).asDouble() + alpha * vertex2->get("x", 0.0).asDouble(); |
| 589 |
6/6✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
✓ Branch 10 taken 26 times.
✓ Branch 13 taken 26 times.
✓ Branch 16 taken 26 times.
|
26 | double y = (1.0 - alpha) * vertex1->get("y", 0.0).asDouble() + alpha * vertex2->get("y", 0.0).asDouble(); |
| 590 | |||
| 591 |
1/1✓ Branch 1 taken 26 times.
|
26 | doorDefinitionIds.push_back(doorDefinitionId); |
| 592 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
26 | doorCenterVertices.push_back(Point3d(lengthToMeters * x, lengthToMeters * y, 0.0)); |
| 593 | } | ||
| 594 | 26 | } | |
| 595 | 15 | } | |
| 596 | 5771 | } | |
| 597 | 5771 | } | |
| 598 | 864 | } | |
| 599 | |||
| 600 | // correct the floor vertices | ||
| 601 | |||
| 602 | // simplify the vertices to remove potential duplicate, colinear points | ||
| 603 | 864 | double tol = 0.001; | |
| 604 | //std::vector<Point3d> testFaceVertices(faceVertices); | ||
| 605 |
1/1✓ Branch 1 taken 864 times.
|
864 | faceVertices = simplify(faceVertices, false, tol); |
| 606 | |||
| 607 | 864 | size_t numPoints = faceVertices.size(); | |
| 608 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 864 times.
|
864 | if (numPoints < 3) { |
| 609 | //LOG(Error, "Cannot create a space for floorPrint of size " << faceVertices.size() << "."); | ||
| 610 | ✗ | return; | |
| 611 | } | ||
| 612 | |||
| 613 |
1/1✓ Branch 1 taken 864 times.
|
864 | boost::optional<Vector3d> outwardNormal = getOutwardNormal(faceVertices); |
| 614 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 864 times.
|
864 | if (!outwardNormal) { |
| 615 | //LOG(Error, "Cannot compute outwardNormal for floorPrint."); | ||
| 616 | ✗ | return; | |
| 617 | } | ||
| 618 | |||
| 619 |
4/4✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
✓ Branch 6 taken 517 times.
✓ Branch 7 taken 347 times.
|
864 | if (outwardNormal->z() > 0) { |
| 620 |
1/1✓ Branch 1 taken 517 times.
|
517 | faceVertices = reverse(faceVertices); |
| 621 | } | ||
| 622 | |||
| 623 | 864 | Point3dVectorVector allFinalFaceVertices; | |
| 624 |
1/1✓ Branch 1 taken 864 times.
|
864 | unsigned roofCeilingFaceFormat = openstudioFaceFormatId(); |
| 625 |
1/1✓ Branch 1 taken 864 times.
|
864 | unsigned wallFaceFormat = openstudioFaceFormatId(); |
| 626 |
2/2✓ Branch 0 taken 851 times.
✓ Branch 1 taken 13 times.
|
864 | if (openstudioFormat) { |
| 627 |
1/1✓ Branch 1 taken 851 times.
|
851 | allFinalFaceVertices.push_back(faceVertices); |
| 628 | } else { | ||
| 629 | 13 | roofCeilingFaceFormat = 0; // triangle | |
| 630 | 13 | wallFaceFormat = 1; // quad | |
| 631 | //std::ostringstream ss; | ||
| 632 | //ss << testFaceVertices; | ||
| 633 | //std::string testStr = ss.str(); | ||
| 634 |
1/1✓ Branch 2 taken 13 times.
|
13 | allFinalFaceVertices = computeTriangulation(faceVertices, Point3dVectorVector()); |
| 635 | } | ||
| 636 | |||
| 637 | // create floor and ceiling | ||
| 638 | 864 | Point3dVectorVector allFinalfloorVertices; | |
| 639 | 864 | Point3dVectorVector allFinalRoofCeilingVertices; | |
| 640 |
2/2✓ Branch 5 taken 885 times.
✓ Branch 6 taken 864 times.
|
1749 | for (const auto& finalFaceVertices : allFinalFaceVertices) { |
| 641 | 885 | Point3dVector finalfloorVertices; | |
| 642 | 885 | Point3dVector finalRoofCeilingVertices; | |
| 643 |
2/2✓ Branch 5 taken 5808 times.
✓ Branch 6 taken 885 times.
|
6693 | for (const auto& v : finalFaceVertices) { |
| 644 |
3/3✓ Branch 1 taken 5808 times.
✓ Branch 4 taken 5808 times.
✓ Branch 7 taken 5808 times.
|
5808 | Point3d floorVert(v.x(), v.y(), minZ); |
| 645 |
3/3✓ Branch 1 taken 5808 times.
✓ Branch 4 taken 5808 times.
✓ Branch 7 taken 5808 times.
|
5808 | Point3d ceilVert(v.x(), v.y(), maxZ); |
| 646 |
1/1✓ Branch 1 taken 5808 times.
|
5808 | finalfloorVertices.push_back(floorVert); |
| 647 |
1/1✓ Branch 1 taken 5808 times.
|
5808 | finalRoofCeilingVertices.push_back(ceilVert); |
| 648 |
1/1✓ Branch 1 taken 5808 times.
|
5808 | m_boundingBox.addPoint(floorVert); |
| 649 |
1/1✓ Branch 1 taken 5808 times.
|
5808 | m_boundingBox.addPoint(ceilVert); |
| 650 | 5808 | } | |
| 651 |
1/1✓ Branch 3 taken 885 times.
|
885 | std::reverse(finalRoofCeilingVertices.begin(), finalRoofCeilingVertices.end()); |
| 652 |
1/1✓ Branch 1 taken 885 times.
|
885 | allFinalfloorVertices.push_back(finalfloorVertices); |
| 653 |
1/1✓ Branch 1 taken 885 times.
|
885 | allFinalRoofCeilingVertices.push_back(finalRoofCeilingVertices); |
| 654 | 885 | } | |
| 655 |
4/4✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
✓ Branch 7 taken 864 times.
✓ Branch 10 taken 864 times.
|
5184 | makeSurface(story, spaceOrShading, "", "", belowFloorPlenum, aboveCeilingPlenum, "Floor", allFinalfloorVertices, roofCeilingFaceFormat, geometries, |
| 656 | sceneChildren, 0, openToBelow); | ||
| 657 |
4/4✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
✓ Branch 7 taken 864 times.
✓ Branch 10 taken 864 times.
|
5184 | makeSurface(story, spaceOrShading, "", "", belowFloorPlenum, aboveCeilingPlenum, "RoofCeiling", allFinalRoofCeilingVertices, roofCeilingFaceFormat, |
| 658 | geometries, sceneChildren, 0, false); | ||
| 659 | |||
| 660 | // create each wall | ||
| 661 | 864 | std::set<unsigned> mappedWindows; | |
| 662 | 864 | std::set<unsigned> mappedDoors; | |
| 663 |
2/2✓ Branch 0 taken 5766 times.
✓ Branch 1 taken 864 times.
|
6630 | for (unsigned i = 1; i <= numPoints; ++i) { |
| 664 | Point3dVector wallVertices{ | ||
| 665 | 11532 | {faceVertices[i - 1].x(), faceVertices[i - 1].y(), maxZ}, | |
| 666 | 11532 | {faceVertices[i % numPoints].x(), faceVertices[i % numPoints].y(), maxZ}, | |
| 667 | 11532 | {faceVertices[i % numPoints].x(), faceVertices[i % numPoints].y(), minZ}, | |
| 668 | 11532 | {faceVertices[i - 1].x(), faceVertices[i - 1].y(), minZ}, | |
| 669 |
3/5✓ Branch 1 taken 5766 times.
✓ Branch 3 taken 23064 times.
✓ Branch 4 taken 5766 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
34596 | }; |
| 670 | |||
| 671 | // find windows that appear on this edge, can't use edge ids after simplify algorithm | ||
| 672 | std::vector<Point3d> testSegment{ | ||
| 673 | 11532 | {faceVertices[i - 1].x(), faceVertices[i - 1].y(), 0.0}, | |
| 674 | 11532 | {faceVertices[i % numPoints].x(), faceVertices[i % numPoints].y(), 0.0}, | |
| 675 |
3/5✓ Branch 1 taken 5766 times.
✓ Branch 3 taken 11532 times.
✓ Branch 4 taken 5766 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
23064 | }; |
| 676 | |||
| 677 |
1/1✓ Branch 3 taken 5766 times.
|
5766 | Vector3d edgeVector = testSegment[1] - testSegment[0]; |
| 678 |
1/1✓ Branch 1 taken 5766 times.
|
5766 | edgeVector.setLength(1.0); |
| 679 |
1/1✓ Branch 1 taken 5766 times.
|
5766 | Vector3d upVector(0, 0, 1); |
| 680 |
1/1✓ Branch 1 taken 5766 times.
|
5766 | Vector3d crossVector = upVector.cross(edgeVector); |
| 681 | |||
| 682 | 5766 | Point3dVectorVector allFinalWindowVertices; | |
| 683 | 5766 | std::vector<std::string> allFinalWindowTypes; | |
| 684 | 5766 | Point3dVectorVector allFinalShadeVertices; | |
| 685 | 5766 | std::vector<unsigned> allFinalShadeParentSubSurfaceIndices; | |
| 686 | |||
| 687 | 5766 | size_t windowN = windowCenterVertices.size(); | |
| 688 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5766 times.
✗ Branch 4 not taken.
|
5766 | OS_ASSERT(windowN == windowDefinitionIds.size()); |
| 689 |
2/2✓ Branch 0 taken 6637 times.
✓ Branch 1 taken 5766 times.
|
12403 | for (unsigned windowIdx = 0; windowIdx < windowN; ++windowIdx) { |
| 690 |
3/3✓ Branch 2 taken 6637 times.
✓ Branch 5 taken 3732 times.
✓ Branch 6 taken 2905 times.
|
6637 | if (mappedWindows.find(windowIdx) == mappedWindows.end()) { |
| 691 |
3/3✓ Branch 2 taken 3732 times.
✓ Branch 4 taken 846 times.
✓ Branch 5 taken 2886 times.
|
3732 | if (getDistancePointToLineSegment(windowCenterVertices[windowIdx], testSegment) < tol) { |
| 692 | |||
| 693 | // get window definition | ||
| 694 | |||
| 695 |
1/1✓ Branch 2 taken 846 times.
|
846 | const Json::Value* windowDefinition = findById(windowDefinitions, windowDefinitionIds[windowIdx]); |
| 696 |
1/2✓ Branch 0 taken 846 times.
✗ Branch 1 not taken.
|
846 | if (windowDefinition) { |
| 697 | 846 | std::string windowDefinitionMode; | |
| 698 |
4/4✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
✓ Branch 7 taken 58 times.
✓ Branch 8 taken 788 times.
|
2538 | if (checkKeyAndType(*windowDefinition, "window_definition_type", Json::stringValue)) { |
| 699 |
3/3✓ Branch 1 taken 58 times.
✓ Branch 4 taken 58 times.
✓ Branch 7 taken 58 times.
|
58 | windowDefinitionMode = windowDefinition->get("window_definition_type", "").asString(); |
| 700 | } else { | ||
| 701 |
2/2✓ Branch 1 taken 788 times.
✓ Branch 4 taken 788 times.
|
1576 | assertKeyAndType(*windowDefinition, "window_definition_mode", Json::stringValue); |
| 702 |
3/3✓ Branch 1 taken 788 times.
✓ Branch 4 taken 788 times.
✓ Branch 7 taken 788 times.
|
788 | windowDefinitionMode = windowDefinition->get("window_definition_mode", "").asString(); |
| 703 | } | ||
| 704 | |||
| 705 | // "Fixed","Operable" | ||
| 706 |
1/1✓ Branch 1 taken 846 times.
|
846 | std::string windowType = "FixedWindow"; |
| 707 |
4/4✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
✓ Branch 7 taken 788 times.
✓ Branch 8 taken 58 times.
|
2538 | if (checkKeyAndType(*windowDefinition, "window_type", Json::stringValue)) { |
| 708 |
3/3✓ Branch 1 taken 788 times.
✓ Branch 4 taken 788 times.
✓ Branch 7 taken 788 times.
|
788 | windowType = windowDefinition->get("window_type", windowType).asString(); |
| 709 | } | ||
| 710 |
4/4✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
✓ Branch 7 taken 785 times.
✓ Branch 8 taken 61 times.
|
1692 | if (istringEqual(windowType, "Fixed")) { |
| 711 |
1/1✓ Branch 1 taken 785 times.
|
785 | windowType = "FixedWindow"; |
| 712 |
4/4✓ Branch 1 taken 61 times.
✓ Branch 4 taken 61 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 58 times.
|
122 | } else if (istringEqual(windowType, "Operable")) { |
| 713 |
1/1✓ Branch 1 taken 3 times.
|
3 | windowType = "OperableWindow"; |
| 714 | } | ||
| 715 |
1/1✓ Branch 1 taken 846 times.
|
846 | allFinalWindowTypes.push_back(windowType); |
| 716 | |||
| 717 |
16/26✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
✓ Branch 6 taken 59 times.
✓ Branch 7 taken 787 times.
✓ Branch 9 taken 59 times.
✓ Branch 12 taken 59 times.
✓ Branch 14 taken 17 times.
✓ Branch 15 taken 42 times.
✓ Branch 16 taken 59 times.
✓ Branch 17 taken 787 times.
✓ Branch 19 taken 59 times.
✓ Branch 20 taken 787 times.
✓ Branch 21 taken 846 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 846 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 804 times.
✓ Branch 27 taken 42 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
|
2656 | if (istringEqual("Single Window", windowDefinitionMode) || istringEqual("Repeating Windows", windowDefinitionMode)) { |
| 718 |
2/2✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
|
1608 | assertKeyAndType(*windowDefinition, "sill_height", Json::realValue); |
| 719 |
2/2✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
|
1608 | assertKeyAndType(*windowDefinition, "height", Json::realValue); |
| 720 |
2/2✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
|
1608 | assertKeyAndType(*windowDefinition, "width", Json::realValue); |
| 721 | |||
| 722 |
3/3✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
✓ Branch 7 taken 804 times.
|
804 | double sillHeight = lengthToMeters * windowDefinition->get("sill_height", 0.0).asDouble(); |
| 723 |
3/3✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
✓ Branch 7 taken 804 times.
|
804 | double height = lengthToMeters * windowDefinition->get("height", 0.0).asDouble(); |
| 724 |
3/3✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
✓ Branch 7 taken 804 times.
|
804 | double width = lengthToMeters * windowDefinition->get("width", 0.0).asDouble(); |
| 725 | |||
| 726 |
1/1✓ Branch 1 taken 804 times.
|
804 | Vector3d widthVector = edgeVector; |
| 727 |
1/1✓ Branch 1 taken 804 times.
|
804 | widthVector.setLength(0.5 * width); |
| 728 |
1/1✓ Branch 2 taken 804 times.
|
804 | Point3d window1 = windowCenterVertices[windowIdx] + widthVector; |
| 729 |
1/1✓ Branch 1 taken 804 times.
|
804 | widthVector.setLength(-0.5 * width); |
| 730 |
1/1✓ Branch 2 taken 804 times.
|
804 | Point3d window2 = windowCenterVertices[windowIdx] + widthVector; |
| 731 | |||
| 732 | Point3dVector windowVertices{ | ||
| 733 | 804 | {window1.x(), window1.y(), minZ + sillHeight + height}, | |
| 734 | {window1.x(), window1.y(), minZ + sillHeight}, | ||
| 735 | {window2.x(), window2.y(), minZ + sillHeight}, | ||
| 736 | 804 | {window2.x(), window2.y(), minZ + sillHeight + height}, | |
| 737 |
3/5✓ Branch 1 taken 804 times.
✓ Branch 3 taken 3216 times.
✓ Branch 4 taken 804 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
4824 | }; |
| 738 | |||
| 739 | 804 | size_t parentSubSurfaceIndex = allFinalWindowVertices.size(); | |
| 740 |
1/1✓ Branch 1 taken 804 times.
|
804 | allFinalWindowVertices.push_back(windowVertices); |
| 741 | |||
| 742 |
4/9✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 788 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
2412 | if (checkKeyAndType(*windowDefinition, "overhang_projection_factor", Json::realValue) |
| 743 |
11/17✓ Branch 1 taken 804 times.
✓ Branch 3 taken 788 times.
✓ Branch 4 taken 16 times.
✓ Branch 6 taken 788 times.
✓ Branch 9 taken 788 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 788 times.
✓ Branch 13 taken 788 times.
✓ Branch 14 taken 16 times.
✓ Branch 16 taken 788 times.
✓ Branch 17 taken 16 times.
✓ Branch 18 taken 804 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
3184 | || checkKeyAndType(*windowDefinition, "overhang_projection_factor", Json::intValue)) { |
| 744 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
|
16 | double projectionFactor = windowDefinition->get("overhang_projection_factor", 0.0).asDouble(); |
| 745 | |||
| 746 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (projectionFactor > 0) { |
| 747 |
1/1✓ Branch 1 taken 16 times.
|
16 | Vector3d outVector = crossVector; |
| 748 |
1/1✓ Branch 1 taken 16 times.
|
16 | outVector.setLength(projectionFactor * height); |
| 749 | |||
| 750 |
1/1✓ Branch 1 taken 16 times.
|
16 | Point3d window3 = window1 + outVector; |
| 751 |
1/1✓ Branch 1 taken 16 times.
|
16 | Point3d window4 = window2 + outVector; |
| 752 | |||
| 753 | Point3dVector shadeVertices{ | ||
| 754 | 16 | {window1.x(), window1.y(), minZ + sillHeight + height}, | |
| 755 | 16 | {window3.x(), window3.y(), minZ + sillHeight + height}, | |
| 756 | 16 | {window4.x(), window4.y(), minZ + sillHeight + height}, | |
| 757 | 16 | {window2.x(), window2.y(), minZ + sillHeight + height}, | |
| 758 |
3/5✓ Branch 1 taken 16 times.
✓ Branch 3 taken 64 times.
✓ Branch 4 taken 16 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
96 | }; |
| 759 | |||
| 760 |
1/1✓ Branch 1 taken 16 times.
|
16 | allFinalShadeVertices.push_back(shadeVertices); |
| 761 |
1/1✓ Branch 1 taken 16 times.
|
16 | allFinalShadeParentSubSurfaceIndices.push_back(parentSubSurfaceIndex); |
| 762 | 16 | } | |
| 763 | } | ||
| 764 | |||
| 765 |
4/9✓ Branch 1 taken 804 times.
✓ Branch 4 taken 804 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✓ Branch 7 taken 788 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
2412 | if (checkKeyAndType(*windowDefinition, "fin_projection_factor", Json::realValue) |
| 766 |
11/17✓ Branch 1 taken 804 times.
✓ Branch 3 taken 788 times.
✓ Branch 4 taken 16 times.
✓ Branch 6 taken 788 times.
✓ Branch 9 taken 788 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 788 times.
✓ Branch 13 taken 788 times.
✓ Branch 14 taken 16 times.
✓ Branch 16 taken 788 times.
✓ Branch 17 taken 16 times.
✓ Branch 18 taken 804 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
3184 | || checkKeyAndType(*windowDefinition, "fin_projection_factor", Json::intValue)) { |
| 767 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
|
16 | double projectionFactor = windowDefinition->get("fin_projection_factor", 0.0).asDouble(); |
| 768 | |||
| 769 |
1/2✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 | if (projectionFactor > 0) { |
| 770 |
1/1✓ Branch 1 taken 16 times.
|
16 | Vector3d outVector = crossVector; |
| 771 |
1/1✓ Branch 1 taken 16 times.
|
16 | outVector.setLength(projectionFactor * height); |
| 772 | |||
| 773 |
1/1✓ Branch 1 taken 16 times.
|
16 | Point3d window3 = window1 + outVector; |
| 774 |
1/1✓ Branch 1 taken 16 times.
|
16 | Point3d window4 = window2 + outVector; |
| 775 | |||
| 776 | Point3dVector shadeVertices{ | ||
| 777 | 16 | {window1.x(), window1.y(), minZ + sillHeight + height}, | |
| 778 | {window1.x(), window1.y(), minZ + sillHeight}, | ||
| 779 | {window3.x(), window3.y(), minZ + sillHeight}, | ||
| 780 | 16 | {window3.x(), window3.y(), minZ + sillHeight + height}, | |
| 781 |
3/5✓ Branch 1 taken 16 times.
✓ Branch 3 taken 64 times.
✓ Branch 4 taken 16 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
96 | }; |
| 782 | |||
| 783 |
1/1✓ Branch 1 taken 16 times.
|
16 | allFinalShadeVertices.push_back(shadeVertices); |
| 784 |
1/1✓ Branch 1 taken 16 times.
|
16 | allFinalShadeParentSubSurfaceIndices.push_back(parentSubSurfaceIndex); |
| 785 | |||
| 786 |
2/4✓ Branch 0 taken 64 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
80 | shadeVertices = { |
| 787 | 16 | {window4.x(), window4.y(), minZ + sillHeight + height}, | |
| 788 | {window4.x(), window4.y(), minZ + sillHeight}, | ||
| 789 | {window2.x(), window2.y(), minZ + sillHeight}, | ||
| 790 | 16 | {window2.x(), window2.y(), minZ + sillHeight + height}, | |
| 791 | 80 | }; | |
| 792 | |||
| 793 |
1/1✓ Branch 1 taken 16 times.
|
16 | allFinalShadeVertices.push_back(shadeVertices); |
| 794 |
1/1✓ Branch 1 taken 16 times.
|
16 | allFinalShadeParentSubSurfaceIndices.push_back(parentSubSurfaceIndex); |
| 795 | 16 | } | |
| 796 | } | ||
| 797 | |||
| 798 |
3/4✓ Branch 5 taken 42 times.
✓ Branch 8 taken 42 times.
✓ Branch 11 taken 42 times.
✗ Branch 12 not taken.
|
888 | } else if (istringEqual("Window to Wall Ratio", windowDefinitionMode)) { |
| 799 |
2/2✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
|
84 | assertKeyAndType(*windowDefinition, "sill_height", Json::realValue); |
| 800 |
2/2✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
|
84 | assertKeyAndType(*windowDefinition, "wwr", Json::realValue); |
| 801 | |||
| 802 |
3/3✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
✓ Branch 7 taken 42 times.
|
42 | double sillHeight = lengthToMeters * windowDefinition->get("sill_height", 0.0).asDouble(); |
| 803 |
3/3✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
✓ Branch 7 taken 42 times.
|
42 | double wwr = windowDefinition->get("wwr", 0.0).asDouble(); |
| 804 | |||
| 805 | 42 | double projectionFactor = 0.0; | |
| 806 |
4/9✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 21 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
126 | if (checkKeyAndType(*windowDefinition, "overhang_projection_factor", Json::realValue) |
| 807 |
11/17✓ Branch 1 taken 42 times.
✓ Branch 3 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 6 taken 21 times.
✓ Branch 9 taken 21 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 21 times.
✓ Branch 13 taken 21 times.
✓ Branch 14 taken 21 times.
✓ Branch 16 taken 21 times.
✓ Branch 17 taken 21 times.
✓ Branch 18 taken 42 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
126 | || checkKeyAndType(*windowDefinition, "overhang_projection_factor", Json::intValue)) { |
| 808 |
3/3✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 7 taken 21 times.
|
21 | projectionFactor = windowDefinition->get("overhang_projection_factor", 0.0).asDouble(); |
| 809 | } | ||
| 810 | |||
| 811 | // applyViewAndDaylightingGlassRatios does not currently take argument for fins | ||
| 812 | |||
| 813 | 42 | Point3dVector viewVertices; | |
| 814 | 42 | Point3dVector daylightingVertices; // not populated | |
| 815 | 42 | Point3dVector exteriorShadingVertices; | |
| 816 | 42 | Point3dVector interiorShelfVertices; // not populated | |
| 817 | |||
| 818 |
1/1✓ Branch 1 taken 42 times.
|
42 | bool test = applyViewAndDaylightingGlassRatios(wwr, 0.0, sillHeight, 0.0, projectionFactor, 0.0, wallVertices, viewVertices, |
| 819 | daylightingVertices, exteriorShadingVertices, interiorShelfVertices); | ||
| 820 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | if (test) { |
| 821 |
1/2✓ Branch 1 taken 42 times.
✗ Branch 2 not taken.
|
42 | if (!viewVertices.empty()) { |
| 822 | 42 | size_t parentSubSurfaceIndex = allFinalWindowVertices.size(); | |
| 823 |
1/1✓ Branch 1 taken 42 times.
|
42 | allFinalWindowVertices.push_back(viewVertices); |
| 824 | |||
| 825 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
|
42 | if (!exteriorShadingVertices.empty()) { |
| 826 |
1/1✓ Branch 1 taken 21 times.
|
21 | allFinalShadeVertices.push_back(exteriorShadingVertices); |
| 827 |
1/1✓ Branch 1 taken 21 times.
|
21 | allFinalShadeParentSubSurfaceIndices.push_back(parentSubSurfaceIndex); |
| 828 | } | ||
| 829 | } | ||
| 830 | } | ||
| 831 | 42 | } | |
| 832 | 846 | } | |
| 833 | |||
| 834 |
1/1✓ Branch 1 taken 846 times.
|
846 | mappedWindows.insert(windowIdx); |
| 835 | } | ||
| 836 | } | ||
| 837 | } | ||
| 838 | |||
| 839 | 5766 | Point3dVectorVector allFinalDoorVertices; | |
| 840 | 5766 | std::vector<std::string> allFinalDoorTypes; | |
| 841 | |||
| 842 | 5766 | size_t doorN = doorCenterVertices.size(); | |
| 843 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5766 times.
✗ Branch 4 not taken.
|
5766 | OS_ASSERT(doorN == doorDefinitionIds.size()); |
| 844 |
2/2✓ Branch 0 taken 105 times.
✓ Branch 1 taken 5766 times.
|
5871 | for (unsigned doorIdx = 0; doorIdx < doorN; ++doorIdx) { |
| 845 |
3/3✓ Branch 2 taken 105 times.
✓ Branch 5 taken 57 times.
✓ Branch 6 taken 48 times.
|
105 | if (mappedDoors.find(doorIdx) == mappedDoors.end()) { |
| 846 |
3/3✓ Branch 2 taken 57 times.
✓ Branch 4 taken 26 times.
✓ Branch 5 taken 31 times.
|
57 | if (getDistancePointToLineSegment(doorCenterVertices[doorIdx], testSegment) < tol) { |
| 847 | |||
| 848 | // get door definition | ||
| 849 | |||
| 850 |
1/1✓ Branch 2 taken 26 times.
|
26 | const Json::Value* doorDefinition = findById(doorDefinitions, doorDefinitionIds[doorIdx]); |
| 851 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (doorDefinition) { |
| 852 | |||
| 853 | // "Door","Glass Door","Overhead Door" | ||
| 854 |
1/1✓ Branch 1 taken 26 times.
|
26 | std::string doorType = "Door"; |
| 855 |
3/4✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
✗ Branch 8 not taken.
|
78 | if (checkKeyAndType(*doorDefinition, "door_type", Json::stringValue)) { |
| 856 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
|
26 | doorType = doorDefinition->get("door_type", doorType).asString(); |
| 857 | } | ||
| 858 |
4/4✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 3 times.
✓ Branch 8 taken 23 times.
|
52 | if (istringEqual(doorType, "Glass Door")) { |
| 859 |
1/1✓ Branch 1 taken 3 times.
|
3 | doorType = "GlassDoor"; |
| 860 |
4/4✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 21 times.
|
46 | } else if (istringEqual(doorType, "Overhead Door")) { |
| 861 |
1/1✓ Branch 1 taken 2 times.
|
2 | doorType = "OverheadDoor"; |
| 862 | } | ||
| 863 |
1/1✓ Branch 1 taken 26 times.
|
26 | allFinalDoorTypes.push_back(doorType); |
| 864 | |||
| 865 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
52 | assertKeyAndType(*doorDefinition, "height", Json::realValue); |
| 866 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
52 | assertKeyAndType(*doorDefinition, "width", Json::realValue); |
| 867 | |||
| 868 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
|
26 | double height = lengthToMeters * doorDefinition->get("height", 0.0).asDouble(); |
| 869 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
✓ Branch 7 taken 26 times.
|
26 | double width = lengthToMeters * doorDefinition->get("width", 0.0).asDouble(); |
| 870 | |||
| 871 |
1/1✓ Branch 1 taken 26 times.
|
26 | Vector3d widthVector = edgeVector; |
| 872 |
1/1✓ Branch 1 taken 26 times.
|
26 | widthVector.setLength(0.5 * width); |
| 873 |
1/1✓ Branch 2 taken 26 times.
|
26 | Point3d door1 = doorCenterVertices[doorIdx] + widthVector; |
| 874 |
1/1✓ Branch 1 taken 26 times.
|
26 | widthVector.setLength(-0.5 * width); |
| 875 |
1/1✓ Branch 2 taken 26 times.
|
26 | Point3d doorw2 = doorCenterVertices[doorIdx] + widthVector; |
| 876 | |||
| 877 | Point3dVector doorVertices{ | ||
| 878 | {door1.x(), door1.y(), minZ + height}, | ||
| 879 | {door1.x(), door1.y(), minZ + 0.0}, | ||
| 880 | {doorw2.x(), doorw2.y(), minZ + 0.0}, | ||
| 881 | {doorw2.x(), doorw2.y(), minZ + height}, | ||
| 882 |
3/5✓ Branch 1 taken 26 times.
✓ Branch 3 taken 104 times.
✓ Branch 4 taken 26 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
156 | }; |
| 883 | |||
| 884 | // size_t parentSubSurfaceIndex = allFinalDoorVertices.size(); | ||
| 885 |
1/1✓ Branch 1 taken 26 times.
|
26 | allFinalDoorVertices.push_back(doorVertices); |
| 886 | 26 | } | |
| 887 | |||
| 888 |
1/1✓ Branch 1 taken 26 times.
|
26 | mappedDoors.insert(doorIdx); |
| 889 | } | ||
| 890 | } | ||
| 891 | } | ||
| 892 | |||
| 893 | 5766 | Point3dVectorVector allFinalWallVertices; | |
| 894 | 5766 | unsigned finalWallFaceFormat = wallFaceFormat; | |
| 895 |
2/2✓ Branch 0 taken 5706 times.
✓ Branch 1 taken 60 times.
|
5766 | if (openstudioFormat) { |
| 896 |
1/1✓ Branch 1 taken 5706 times.
|
5706 | allFinalWallVertices.push_back(wallVertices); |
| 897 |
3/6✓ Branch 1 taken 60 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 60 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 60 times.
✗ Branch 7 not taken.
|
60 | } else if (allFinalWindowVertices.empty() && allFinalDoorVertices.empty()) { |
| 898 |
1/1✓ Branch 1 taken 60 times.
|
60 | allFinalWallVertices.push_back(wallVertices); |
| 899 | } else { | ||
| 900 | ✗ | finalWallFaceFormat = 0; // triangle | |
| 901 | |||
| 902 | ✗ | Transformation t = Transformation::alignFace(wallVertices); | |
| 903 | //Transformation r = t.rotationMatrix(); | ||
| 904 | ✗ | Transformation tInv = t.inverse(); | |
| 905 | ✗ | wallVertices = reverse(tInv * wallVertices); | |
| 906 | // get vertices of all sub surfaces | ||
| 907 | ✗ | Point3dVectorVector wallSubVertices; | |
| 908 | ✗ | for (const auto& finalWindowVertices : allFinalWindowVertices) { | |
| 909 | ✗ | wallSubVertices.push_back(reverse(tInv * finalWindowVertices)); | |
| 910 | } | ||
| 911 | ✗ | for (const auto& finalDoorVertices : allFinalDoorVertices) { | |
| 912 | ✗ | wallSubVertices.push_back(reverse(tInv * finalDoorVertices)); | |
| 913 | } | ||
| 914 | |||
| 915 | ✗ | Point3dVectorVector finalWallVertices = computeTriangulation(wallVertices, wallSubVertices, tol); | |
| 916 | ✗ | for (const auto& finalWallVerts : finalWallVertices) { | |
| 917 | ✗ | Point3dVector finalVerts = t * finalWallVerts; | |
| 918 | ✗ | allFinalWallVertices.push_back(reverse(finalVerts)); | |
| 919 | ✗ | } | |
| 920 | ✗ | } | |
| 921 | |||
| 922 | 5766 | std::string parentSurfaceName; | |
| 923 |
4/4✓ Branch 1 taken 5766 times.
✓ Branch 4 taken 5766 times.
✓ Branch 7 taken 5766 times.
✓ Branch 10 taken 5766 times.
|
40362 | parentSurfaceName = makeSurface(story, spaceOrShading, "", "", belowFloorPlenum, aboveCeilingPlenum, "Wall", allFinalWallVertices, |
| 924 | 5766 | finalWallFaceFormat, geometries, sceneChildren, 0, false); | |
| 925 | |||
| 926 | 5766 | std::vector<std::string> parentSubSurfaceNames; | |
| 927 | 5766 | size_t finalWindowN = allFinalWindowVertices.size(); | |
| 928 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5766 times.
✗ Branch 4 not taken.
|
5766 | OS_ASSERT(finalWindowN == allFinalWindowTypes.size()); |
| 929 |
2/2✓ Branch 0 taken 846 times.
✓ Branch 1 taken 5766 times.
|
6612 | for (size_t finalWindowIdx = 0; finalWindowIdx < finalWindowN; ++finalWindowIdx) { |
| 930 | 846 | const auto& finalWindowVertices = allFinalWindowVertices[finalWindowIdx]; | |
| 931 | std::string parentSubSurfaceName = | ||
| 932 |
1/1✓ Branch 2 taken 846 times.
|
1692 | makeSurface(story, spaceOrShading, parentSurfaceName, "", belowFloorPlenum, aboveCeilingPlenum, allFinalWindowTypes[finalWindowIdx], |
| 933 |
2/2✓ Branch 1 taken 846 times.
✓ Branch 4 taken 846 times.
|
4230 | Point3dVectorVector(1, finalWindowVertices), wallFaceFormat, geometries, sceneChildren, 0, false); |
| 934 |
1/1✓ Branch 1 taken 846 times.
|
846 | parentSubSurfaceNames.push_back(parentSubSurfaceName); |
| 935 | 846 | } | |
| 936 | |||
| 937 | 5766 | size_t finalDoorN = allFinalDoorVertices.size(); | |
| 938 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5766 times.
✗ Branch 4 not taken.
|
5766 | OS_ASSERT(finalDoorN == allFinalDoorTypes.size()); |
| 939 |
2/2✓ Branch 0 taken 26 times.
✓ Branch 1 taken 5766 times.
|
5792 | for (size_t finalDoorIdx = 0; finalDoorIdx < finalDoorN; ++finalDoorIdx) { |
| 940 | 26 | const auto& finalDoorVertices = allFinalDoorVertices[finalDoorIdx]; | |
| 941 | std::string parentSubSurfaceName = | ||
| 942 |
1/1✓ Branch 2 taken 26 times.
|
52 | makeSurface(story, spaceOrShading, parentSurfaceName, "", belowFloorPlenum, aboveCeilingPlenum, allFinalDoorTypes[finalDoorIdx], |
| 943 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
130 | Point3dVectorVector(1, finalDoorVertices), wallFaceFormat, geometries, sceneChildren, 0, false); |
| 944 |
1/1✓ Branch 1 taken 26 times.
|
26 | parentSubSurfaceNames.push_back(parentSubSurfaceName); |
| 945 | 26 | } | |
| 946 | |||
| 947 | 5766 | size_t shadeN = allFinalShadeVertices.size(); | |
| 948 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 5766 times.
✗ Branch 4 not taken.
|
5766 | OS_ASSERT(shadeN == allFinalShadeParentSubSurfaceIndices.size()); |
| 949 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 5766 times.
|
5835 | for (size_t shadeIdx = 0; shadeIdx < shadeN; ++shadeIdx) { |
| 950 |
1/1✓ Branch 3 taken 69 times.
|
69 | std::string parentSubSurfaceName = parentSubSurfaceNames[allFinalShadeParentSubSurfaceIndices[shadeIdx]]; |
| 951 |
3/3✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
✓ Branch 7 taken 69 times.
|
276 | makeSurface(story, spaceOrShading, "", parentSubSurfaceName, belowFloorPlenum, aboveCeilingPlenum, "SpaceShading", |
| 952 |
1/1✓ Branch 2 taken 69 times.
|
138 | Point3dVectorVector(1, allFinalShadeVertices[shadeIdx]), wallFaceFormat, geometries, sceneChildren, 0, false); |
| 953 | 69 | } | |
| 954 | 5766 | } | |
| 955 | |||
| 956 | // get daylighting controls | ||
| 957 |
9/9✓ Branch 1 taken 864 times.
✓ Branch 4 taken 864 times.
✓ Branch 8 taken 864 times.
✓ Branch 11 taken 864 times.
✓ Branch 14 taken 17 times.
✓ Branch 17 taken 17 times.
✓ Branch 20 taken 881 times.
✓ Branch 22 taken 17 times.
✓ Branch 23 taken 864 times.
|
881 | for (const auto& daylightingControl : spaceOrShading.get("daylighting_controls", Json::arrayValue)) { |
| 958 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
34 | assertKeyAndType(daylightingControl, "vertex_id", Json::stringValue); |
| 959 |
3/3✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
|
17 | std::string vertexId = daylightingControl.get("vertex_id", "").asString(); |
| 960 | |||
| 961 |
1/1✓ Branch 1 taken 17 times.
|
17 | const Json::Value* vertex = findById(vertices, vertexId); |
| 962 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | if (vertex) { |
| 963 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
34 | assertKeyAndType(daylightingControl, "daylighting_control_definition_id", Json::stringValue); |
| 964 |
3/3✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
|
17 | std::string daylightingControlDefinitionId = daylightingControl.get("daylighting_control_definition_id", "").asString(); |
| 965 | |||
| 966 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
34 | assertKeyAndType(*vertex, "x", Json::realValue); |
| 967 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
34 | assertKeyAndType(*vertex, "y", Json::realValue); |
| 968 | |||
| 969 |
1/1✓ Branch 1 taken 17 times.
|
17 | const Json::Value* daylightingControlDefinition = findById(daylightingControlDefinitions, daylightingControlDefinitionId); |
| 970 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | if (daylightingControlDefinition) { |
| 971 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
34 | assertKey(*daylightingControlDefinition, "height"); |
| 972 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
|
17 | assertKey(*daylightingControlDefinition, "illuminance_setpoint"); |
| 973 | |||
| 974 |
3/3✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
|
17 | double height = lengthToMeters * daylightingControlDefinition->get("height", 0.0).asDouble(); |
| 975 |
3/3✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
|
17 | double illuminanceSetpoint = daylightingControlDefinition->get("illuminance_setpoint", 0.0).asDouble(); // DLM: TODO put in unit conversion |
| 976 | |||
| 977 | 17 | Point3dVector dcVertices; | |
| 978 |
1/1✓ Branch 1 taken 17 times.
|
17 | dcVertices.push_back( |
| 979 |
7/7✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
✓ Branch 10 taken 17 times.
✓ Branch 13 taken 17 times.
✓ Branch 16 taken 17 times.
✓ Branch 19 taken 17 times.
|
34 | Point3d(lengthToMeters * vertex->get("x", 0.0).asDouble() - 0.1, lengthToMeters * vertex->get("y", 0.0).asDouble() + 0.1, minZ + height)); |
| 980 |
1/1✓ Branch 1 taken 17 times.
|
17 | dcVertices.push_back( |
| 981 |
7/7✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
✓ Branch 10 taken 17 times.
✓ Branch 13 taken 17 times.
✓ Branch 16 taken 17 times.
✓ Branch 19 taken 17 times.
|
34 | Point3d(lengthToMeters * vertex->get("x", 0.0).asDouble() + 0.1, lengthToMeters * vertex->get("y", 0.0).asDouble() + 0.1, minZ + height)); |
| 982 |
1/1✓ Branch 1 taken 17 times.
|
17 | dcVertices.push_back( |
| 983 |
7/7✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
✓ Branch 10 taken 17 times.
✓ Branch 13 taken 17 times.
✓ Branch 16 taken 17 times.
✓ Branch 19 taken 17 times.
|
34 | Point3d(lengthToMeters * vertex->get("x", 0.0).asDouble() + 0.1, lengthToMeters * vertex->get("y", 0.0).asDouble() - 0.1, minZ + height)); |
| 984 |
1/1✓ Branch 1 taken 17 times.
|
17 | dcVertices.push_back( |
| 985 |
7/7✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
✓ Branch 10 taken 17 times.
✓ Branch 13 taken 17 times.
✓ Branch 16 taken 17 times.
✓ Branch 19 taken 17 times.
|
34 | Point3d(lengthToMeters * vertex->get("x", 0.0).asDouble() - 0.1, lengthToMeters * vertex->get("y", 0.0).asDouble() - 0.1, minZ + height)); |
| 986 | |||
| 987 |
5/5✓ Branch 1 taken 17 times.
✓ Branch 4 taken 17 times.
✓ Branch 7 taken 17 times.
✓ Branch 10 taken 17 times.
✓ Branch 13 taken 17 times.
|
136 | makeSurface(story, spaceOrShading, "", "", belowFloorPlenum, aboveCeilingPlenum, "DaylightingControl", Point3dVectorVector(1, dcVertices), |
| 988 | wallFaceFormat, geometries, sceneChildren, illuminanceSetpoint, false); | ||
| 989 | 17 | } | |
| 990 | 17 | } | |
| 991 | 881 | } | |
| 992 | 13274 | } | |
| 993 | |||
| 994 | 910 | void FloorplanJS::makeMaterial(const Json::Value& object, const std::string& iddObjectType, std::vector<ThreeMaterial>& materials, | |
| 995 | std::map<std::string, std::string>& materialMap) { | ||
| 996 |
2/2✓ Branch 1 taken 910 times.
✓ Branch 4 taken 910 times.
|
1820 | assertKeyAndType(object, "name", Json::stringValue); |
| 997 |
3/3✓ Branch 1 taken 910 times.
✓ Branch 4 taken 910 times.
✓ Branch 7 taken 910 times.
|
910 | std::string name = object.get("name", "").asString(); |
| 998 | |||
| 999 |
4/4✓ Branch 1 taken 910 times.
✓ Branch 4 taken 910 times.
✓ Branch 7 taken 811 times.
✓ Branch 8 taken 99 times.
|
2730 | if (checkKeyAndType(object, "color", Json::stringValue)) { |
| 1000 |
3/3✓ Branch 1 taken 811 times.
✓ Branch 4 taken 811 times.
✓ Branch 7 taken 811 times.
|
811 | std::string color = object.get("color", "").asString(); |
| 1001 | |||
| 1002 |
1/1✓ Branch 1 taken 811 times.
|
811 | std::string materialName = getObjectThreeMaterialName(iddObjectType, name); |
| 1003 |
3/3✓ Branch 1 taken 811 times.
✓ Branch 4 taken 811 times.
✓ Branch 7 taken 811 times.
|
811 | ThreeMaterial material = makeThreeMaterial(materialName, toThreeColor(color), 1, ThreeSide::DoubleSide); |
| 1004 |
1/1✓ Branch 1 taken 811 times.
|
811 | addThreeMaterial(materials, materialMap, material); |
| 1005 | 811 | } | |
| 1006 | 910 | } | |
| 1007 | |||
| 1008 | 1763 | ThreeModelObjectMetadata FloorplanJS::makeModelObjectMetadata(const std::string& iddObjectType, const Json::Value& object) { | |
| 1009 | 1763 | std::string handle; | |
| 1010 |
4/4✓ Branch 1 taken 1763 times.
✓ Branch 4 taken 1763 times.
✓ Branch 7 taken 167 times.
✓ Branch 8 taken 1596 times.
|
5289 | if (checkKeyAndType(object, "handle", Json::stringValue)) { |
| 1011 |
3/3✓ Branch 1 taken 167 times.
✓ Branch 4 taken 167 times.
✓ Branch 7 taken 167 times.
|
167 | handle = object.get("handle", "").asString(); |
| 1012 | } | ||
| 1013 | |||
| 1014 | 1763 | std::string name; | |
| 1015 |
3/4✓ Branch 1 taken 1763 times.
✓ Branch 4 taken 1763 times.
✓ Branch 7 taken 1763 times.
✗ Branch 8 not taken.
|
5289 | if (checkKeyAndType(object, "name", Json::stringValue)) { |
| 1016 |
3/3✓ Branch 1 taken 1763 times.
✓ Branch 4 taken 1763 times.
✓ Branch 7 taken 1763 times.
|
1763 | name = object.get("name", "").asString(); |
| 1017 | } | ||
| 1018 | |||
| 1019 |
1/1✓ Branch 1 taken 1763 times.
|
1763 | ThreeModelObjectMetadata result(iddObjectType, handle, name); |
| 1020 | |||
| 1021 |
4/4✓ Branch 1 taken 1763 times.
✓ Branch 4 taken 1763 times.
✓ Branch 7 taken 1649 times.
✓ Branch 8 taken 114 times.
|
5289 | if (checkKeyAndType(object, "color", Json::stringValue)) { |
| 1022 |
3/3✓ Branch 1 taken 1649 times.
✓ Branch 4 taken 1649 times.
✓ Branch 7 taken 1649 times.
|
1649 | std::string color = object.get("color", "").asString(); |
| 1023 |
1/1✓ Branch 1 taken 1649 times.
|
1649 | result.setColor(color); |
| 1024 | 1649 | } | |
| 1025 | |||
| 1026 | 3526 | return result; | |
| 1027 | 1763 | } | |
| 1028 | |||
| 1029 | 44 | ThreeScene FloorplanJS::toThreeScene(bool openstudioFormat) const { | |
| 1030 | 44 | m_plenumThermalZoneNames.clear(); | |
| 1031 | 44 | m_boundingBox = BoundingBox(); | |
| 1032 | |||
| 1033 | 44 | std::vector<ThreeGeometry> geometries; | |
| 1034 | 44 | std::vector<ThreeSceneChild> children; | |
| 1035 | 44 | std::vector<std::string> buildingStoryNames; | |
| 1036 | 44 | std::vector<ThreeModelObjectMetadata> modelObjectMetadata; | |
| 1037 | |||
| 1038 | 44 | std::vector<ThreeMaterial> materials; | |
| 1039 | 44 | std::map<std::string, std::string> materialMap; | |
| 1040 | |||
| 1041 | // DLM: always add the standard materials | ||
| 1042 | // add standard materials if we will be rendering | ||
| 1043 | //if (!openstudioFormat){ | ||
| 1044 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 8 taken 2464 times.
✓ Branch 9 taken 44 times.
|
2508 | for (const auto& material : makeStandardThreeMaterials()) { |
| 1045 |
1/1✓ Branch 1 taken 2464 times.
|
2464 | addThreeMaterial(materials, materialMap, material); |
| 1046 | 44 | } | |
| 1047 | //} | ||
| 1048 | // add model specific materials in loop with makeMaterial | ||
| 1049 | |||
| 1050 | 44 | double currentStoryZ = 0; | |
| 1051 | |||
| 1052 | // read project config | ||
| 1053 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value project = m_value.get("project", Json::objectValue); |
| 1054 |
2/3✓ Branch 1 taken 44 times.
✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
|
44 | if (!project.isNull()) { |
| 1055 | // DLM: TODO move this to a function | ||
| 1056 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value ground = project.get("ground", Json::objectValue); |
| 1057 |
2/3✓ Branch 1 taken 44 times.
✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
|
44 | if (!ground.isNull()) { |
| 1058 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 32 times.
✓ Branch 8 taken 12 times.
|
132 | if (checkKeyAndType(ground, "floor_offset", Json::realValue)) { |
| 1059 |
3/3✓ Branch 1 taken 32 times.
✓ Branch 4 taken 32 times.
✓ Branch 7 taken 32 times.
|
32 | currentStoryZ = ground.get("floor_offset", 0.0).asDouble(); |
| 1060 | } | ||
| 1061 | } | ||
| 1062 | 44 | } | |
| 1063 | |||
| 1064 | // DLM: geometry in ThreeJS output is always in meters in building coordinates | ||
| 1065 | // north angle is applied directly to osm, does not impact this translation | ||
| 1066 | |||
| 1067 | 44 | double lengthToMeters = 1; | |
| 1068 |
5/5✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 11 taken 35 times.
✓ Branch 12 taken 9 times.
|
88 | if (istringEqual(units(), "ip")) { |
| 1069 | 35 | lengthToMeters = 0.3048; // don't use openstudio convert to keep dependencies low | |
| 1070 | } | ||
| 1071 | |||
| 1072 | // are there any plenums in the entire model | ||
| 1073 | 44 | bool anyPlenums = false; | |
| 1074 | |||
| 1075 | // loop over stories | ||
| 1076 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value stories = m_value.get("stories", Json::arrayValue); |
| 1077 |
1/1✓ Branch 1 taken 44 times.
|
44 | Json::ArrayIndex storyN = stories.size(); |
| 1078 |
2/2✓ Branch 0 taken 101 times.
✓ Branch 1 taken 44 times.
|
145 | for (Json::ArrayIndex storyIdx = 0; storyIdx < storyN; ++storyIdx) { |
| 1079 | |||
| 1080 |
4/5✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
✗ Branch 11 not taken.
|
303 | if (checkKeyAndType(stories[storyIdx], "name", Json::stringValue)) { |
| 1081 |
5/5✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
✓ Branch 13 taken 101 times.
|
101 | buildingStoryNames.push_back(stories[storyIdx].get("name", "").asString()); |
| 1082 | } | ||
| 1083 | |||
| 1084 | 101 | std::string storyColor; | |
| 1085 |
5/5✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 80 times.
✓ Branch 11 taken 21 times.
|
303 | if (checkKeyAndType(stories[storyIdx], "color", Json::stringValue)) { |
| 1086 |
4/4✓ Branch 1 taken 80 times.
✓ Branch 4 taken 80 times.
✓ Branch 7 taken 80 times.
✓ Branch 10 taken 80 times.
|
80 | storyColor = stories[storyIdx].get("color", storyColor).asString(); |
| 1087 | } | ||
| 1088 | |||
| 1089 | 101 | unsigned storyMultiplier = 1; | |
| 1090 |
4/5✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
✗ Branch 11 not taken.
|
303 | if (checkKeyAndType(stories[storyIdx], "multiplier", Json::uintValue)) { |
| 1091 |
4/4✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
|
101 | storyMultiplier = stories[storyIdx].get("multiplier", storyMultiplier).asUInt(); |
| 1092 | } | ||
| 1093 | |||
| 1094 | 101 | double storyBelowFloorPlenumHeight = 0; | |
| 1095 |
4/5✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
✗ Branch 11 not taken.
|
303 | if (checkKeyAndType(stories[storyIdx], "below_floor_plenum_height", Json::realValue)) { |
| 1096 |
4/4✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
|
101 | storyBelowFloorPlenumHeight = lengthToMeters * stories[storyIdx].get("below_floor_plenum_height", storyBelowFloorPlenumHeight).asDouble(); |
| 1097 | } | ||
| 1098 | |||
| 1099 | 101 | double storyFloorToCeilingHeight = 3; // default is 3 m | |
| 1100 |
4/5✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
✗ Branch 11 not taken.
|
303 | if (checkKeyAndType(stories[storyIdx], "floor_to_ceiling_height", Json::realValue)) { |
| 1101 |
4/4✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 101 times.
|
101 | storyFloorToCeilingHeight = lengthToMeters * stories[storyIdx].get("floor_to_ceiling_height", storyFloorToCeilingHeight).asDouble(); |
| 1102 | } | ||
| 1103 | |||
| 1104 | 101 | double storyAboveCeilingPlenumHeight = 0; | |
| 1105 |
5/5✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
✓ Branch 10 taken 94 times.
✓ Branch 11 taken 7 times.
|
303 | if (checkKeyAndType(stories[storyIdx], "above_ceiling_plenum_height", Json::realValue)) { |
| 1106 |
4/4✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
✓ Branch 7 taken 94 times.
✓ Branch 10 taken 94 times.
|
94 | storyAboveCeilingPlenumHeight = lengthToMeters * stories[storyIdx].get("above_ceiling_plenum_height", storyAboveCeilingPlenumHeight).asDouble(); |
| 1107 | } | ||
| 1108 | |||
| 1109 | // DLM: temp code | ||
| 1110 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 94 times.
|
101 | if (storyFloorToCeilingHeight < 0.1) { |
| 1111 | //belowFloorPlenumHeight = 1; | ||
| 1112 | 7 | storyFloorToCeilingHeight = 3; | |
| 1113 | //aboveCeilingPlenumHeight = 1; | ||
| 1114 | } | ||
| 1115 |
2/2✓ Branch 0 taken 17 times.
✓ Branch 1 taken 84 times.
|
101 | if (storyMultiplier == 0) { |
| 1116 | 17 | storyMultiplier = 1; | |
| 1117 | } else if (storyMultiplier > 1) { | ||
| 1118 | //LOG(Warn, "Multiplier translation not yet implemented"); | ||
| 1119 | //storyMultiplier = 1; | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | // get story properties | ||
| 1123 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
202 | ThreeModelObjectMetadata storyMetadata = makeModelObjectMetadata("OS:BuildingStory", stories[storyIdx]); |
| 1124 |
1/1✓ Branch 1 taken 101 times.
|
101 | storyMetadata.setColor(storyColor); |
| 1125 |
1/1✓ Branch 1 taken 101 times.
|
101 | storyMetadata.setMultiplier(storyMultiplier); |
| 1126 |
1/1✓ Branch 1 taken 101 times.
|
101 | storyMetadata.setNominalZCoordinate(currentStoryZ); |
| 1127 |
1/1✓ Branch 1 taken 101 times.
|
101 | storyMetadata.setBelowFloorPlenumHeight(storyBelowFloorPlenumHeight); |
| 1128 |
1/1✓ Branch 1 taken 101 times.
|
101 | storyMetadata.setFloorToCeilingHeight(storyFloorToCeilingHeight); |
| 1129 |
1/1✓ Branch 1 taken 101 times.
|
101 | storyMetadata.setAboveCeilingPlenumHeight(storyAboveCeilingPlenumHeight); |
| 1130 |
1/1✓ Branch 1 taken 101 times.
|
101 | modelObjectMetadata.push_back(storyMetadata); |
| 1131 | |||
| 1132 | // make story material | ||
| 1133 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | makeMaterial(stories[storyIdx], "OS:BuildingStory", materials, materialMap); |
| 1134 | |||
| 1135 | // increment currentStoryZ, will be zero for multiplier == 1 | ||
| 1136 | // DLM: TODO need to get the intersection and matching code in utilities, move stories after intersecting and matching | ||
| 1137 | //currentStoryZ += 0.5*(storyMultiplier - 1)*(storyBelowFloorPlenumHeight + storyFloorToCeilingHeight + storyAboveCeilingPlenumHeight); | ||
| 1138 | |||
| 1139 | // get the geometry | ||
| 1140 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
202 | assertKeyAndType(stories[storyIdx], "geometry", Json::objectValue); |
| 1141 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | Json::Value geometry = stories[storyIdx].get("geometry", Json::arrayValue); |
| 1142 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
|
101 | Json::Value vertices = geometry.get("vertices", Json::arrayValue); |
| 1143 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
|
101 | Json::Value edges = geometry.get("edges", Json::arrayValue); |
| 1144 |
2/2✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
|
101 | Json::Value faces = geometry.get("faces", Json::arrayValue); |
| 1145 | |||
| 1146 | // loop over spaces | ||
| 1147 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | Json::Value spaces = stories[storyIdx].get("spaces", Json::arrayValue); |
| 1148 |
1/1✓ Branch 1 taken 101 times.
|
101 | Json::ArrayIndex spaceN = spaces.size(); |
| 1149 |
2/2✓ Branch 0 taken 791 times.
✓ Branch 1 taken 101 times.
|
892 | for (Json::ArrayIndex spaceIdx = 0; spaceIdx < spaceN; ++spaceIdx) { |
| 1150 | |||
| 1151 | // each space should have one face | ||
| 1152 |
4/5✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 791 times.
✗ Branch 11 not taken.
|
2373 | if (checkKeyAndType(spaces[spaceIdx], "face_id", Json::stringValue)) { |
| 1153 |
4/4✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 791 times.
|
791 | std::string faceId = spaces[spaceIdx].get("face_id", "").asString(); |
| 1154 | |||
| 1155 |
3/3✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
|
1582 | assertKeyAndType(spaces[spaceIdx], "name", Json::stringValue); |
| 1156 |
4/4✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 791 times.
|
791 | std::string spaceName = spaces[spaceIdx].get("name", "").asString(); |
| 1157 | |||
| 1158 | // translate space properties, default to story values | ||
| 1159 | 791 | unsigned spaceMultiplier = storyMultiplier; | |
| 1160 |
4/5✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 791 times.
|
2373 | if (checkKeyAndType(spaces[spaceIdx], "multiplier", Json::uintValue)) { |
| 1161 | ✗ | spaceMultiplier = spaces[spaceIdx].get("multiplier", spaceMultiplier).asUInt(); | |
| 1162 | } | ||
| 1163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 791 times.
|
791 | if (spaceMultiplier == 0) { |
| 1164 | ✗ | spaceMultiplier = 1; | |
| 1165 | } else if (spaceMultiplier > 1) { | ||
| 1166 | //LOG(Warn, "Multiplier translation not yet implemented"); | ||
| 1167 | //spaceMultiplier = 1; | ||
| 1168 | } | ||
| 1169 | |||
| 1170 | 791 | double spaceBelowFloorPlenumHeight = storyBelowFloorPlenumHeight; | |
| 1171 |
5/5✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 7 times.
✓ Branch 11 taken 784 times.
|
2373 | if (checkKeyAndType(spaces[spaceIdx], "below_floor_plenum_height", Json::realValue)) { |
| 1172 |
4/4✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
|
7 | spaceBelowFloorPlenumHeight = lengthToMeters * spaces[spaceIdx].get("below_floor_plenum_height", spaceBelowFloorPlenumHeight).asDouble(); |
| 1173 | } | ||
| 1174 | |||
| 1175 | 791 | double spaceFloorToCeilingHeight = storyFloorToCeilingHeight; | |
| 1176 |
5/5✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 7 times.
✓ Branch 11 taken 784 times.
|
2373 | if (checkKeyAndType(spaces[spaceIdx], "floor_to_ceiling_height", Json::realValue)) { |
| 1177 |
4/4✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
|
7 | spaceFloorToCeilingHeight = lengthToMeters * spaces[spaceIdx].get("floor_to_ceiling_height", spaceFloorToCeilingHeight).asDouble(); |
| 1178 | } | ||
| 1179 | |||
| 1180 | 791 | double spaceAboveCeilingPlenumHeight = storyAboveCeilingPlenumHeight; | |
| 1181 |
5/5✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 7 times.
✓ Branch 11 taken 784 times.
|
2373 | if (checkKeyAndType(spaces[spaceIdx], "above_ceiling_plenum_height", Json::realValue)) { |
| 1182 | 7 | spaceAboveCeilingPlenumHeight = | |
| 1183 |
4/4✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
✓ Branch 10 taken 7 times.
|
7 | lengthToMeters * spaces[spaceIdx].get("above_ceiling_plenum_height", spaceAboveCeilingPlenumHeight).asDouble(); |
| 1184 | } | ||
| 1185 | |||
| 1186 | 791 | double spaceFloorOffset = 0; | |
| 1187 |
5/5✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 789 times.
|
2373 | if (checkKeyAndType(spaces[spaceIdx], "floor_offset", Json::realValue)) { |
| 1188 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | spaceFloorOffset = lengthToMeters * spaces[spaceIdx].get("floor_offset", spaceFloorOffset).asDouble(); |
| 1189 | } | ||
| 1190 | |||
| 1191 | 791 | [[maybe_unused]] bool openToBelow = false; | |
| 1192 |
5/5✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 790 times.
|
2373 | if (checkKeyAndType(spaces[spaceIdx], "open_to_below", Json::booleanValue)) { |
| 1193 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | openToBelow = spaces[spaceIdx].get("open_to_below", openToBelow).asBool(); |
| 1194 | } | ||
| 1195 | |||
| 1196 | // create geometry | ||
| 1197 | 791 | double minZ = currentStoryZ + spaceFloorOffset; | |
| 1198 | 791 | double maxZ = currentStoryZ + spaceFloorOffset + spaceBelowFloorPlenumHeight; | |
| 1199 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 781 times.
|
791 | if (spaceBelowFloorPlenumHeight > 0) { |
| 1200 | 10 | anyPlenums = true; | |
| 1201 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 10 taken 10 times.
|
50 | ThreeModelObjectMetadata spaceMetadata("OS:Space", "", spaceName + BELOWFLOORPLENUMPOSTFIX); |
| 1202 |
1/1✓ Branch 1 taken 10 times.
|
10 | spaceMetadata.setMultiplier(spaceMultiplier); |
| 1203 |
1/1✓ Branch 1 taken 10 times.
|
10 | spaceMetadata.setOpenToBelow(openToBelow); |
| 1204 |
1/1✓ Branch 1 taken 10 times.
|
10 | modelObjectMetadata.push_back(spaceMetadata); |
| 1205 |
3/3✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
|
10 | makeGeometries(stories[storyIdx], spaces[spaceIdx], true, false, lengthToMeters, minZ, maxZ, vertices, edges, faces, faceId, |
| 1206 | openstudioFormat, geometries, children, openToBelow); | ||
| 1207 | 10 | openToBelow = false; // no longer open | |
| 1208 | 10 | } | |
| 1209 | |||
| 1210 | 791 | minZ = maxZ; | |
| 1211 | 791 | maxZ += spaceFloorToCeilingHeight; | |
| 1212 |
1/2✓ Branch 0 taken 791 times.
✗ Branch 1 not taken.
|
791 | if (spaceFloorToCeilingHeight > 0) { |
| 1213 |
3/3✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
|
1582 | ThreeModelObjectMetadata spaceMetadata = makeModelObjectMetadata("OS:Space", spaces[spaceIdx]); |
| 1214 |
1/1✓ Branch 1 taken 791 times.
|
791 | spaceMetadata.setMultiplier(spaceMultiplier); |
| 1215 |
1/1✓ Branch 1 taken 791 times.
|
791 | spaceMetadata.setOpenToBelow(openToBelow); |
| 1216 |
1/1✓ Branch 1 taken 791 times.
|
791 | modelObjectMetadata.push_back(spaceMetadata); |
| 1217 |
3/3✓ Branch 1 taken 791 times.
✓ Branch 4 taken 791 times.
✓ Branch 7 taken 791 times.
|
791 | makeGeometries(stories[storyIdx], spaces[spaceIdx], false, false, lengthToMeters, minZ, maxZ, vertices, edges, faces, faceId, |
| 1218 | openstudioFormat, geometries, children, openToBelow); | ||
| 1219 | 791 | openToBelow = false; // no longer open | |
| 1220 | 791 | } | |
| 1221 | |||
| 1222 | 791 | minZ = maxZ; | |
| 1223 | 791 | maxZ += spaceAboveCeilingPlenumHeight; | |
| 1224 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 781 times.
|
791 | if (spaceAboveCeilingPlenumHeight > 0) { |
| 1225 | 10 | anyPlenums = true; | |
| 1226 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✓ Branch 10 taken 10 times.
|
50 | ThreeModelObjectMetadata spaceMetadata("OS:Space", "", spaceName + ABOVECEILINGPLENUMPOSTFIX); |
| 1227 |
1/1✓ Branch 1 taken 10 times.
|
10 | spaceMetadata.setMultiplier(spaceMultiplier); |
| 1228 |
1/1✓ Branch 1 taken 10 times.
|
10 | spaceMetadata.setOpenToBelow(openToBelow); |
| 1229 |
1/1✓ Branch 1 taken 10 times.
|
10 | modelObjectMetadata.push_back(spaceMetadata); |
| 1230 |
3/3✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
|
10 | makeGeometries(stories[storyIdx], spaces[spaceIdx], false, true, lengthToMeters, minZ, maxZ, vertices, edges, faces, faceId, |
| 1231 | openstudioFormat, geometries, children, openToBelow); | ||
| 1232 | 10 | openToBelow = false; // no longer open | |
| 1233 | 10 | } | |
| 1234 | 791 | } | |
| 1235 | |||
| 1236 | } // spaces | ||
| 1237 | |||
| 1238 | // loop over shading | ||
| 1239 |
3/3✓ Branch 1 taken 101 times.
✓ Branch 4 taken 101 times.
✓ Branch 7 taken 101 times.
|
101 | Json::Value shading = stories[storyIdx].get("shading", Json::arrayValue); |
| 1240 |
1/1✓ Branch 1 taken 101 times.
|
101 | Json::ArrayIndex shadingN = shading.size(); |
| 1241 |
2/2✓ Branch 0 taken 69 times.
✓ Branch 1 taken 101 times.
|
170 | for (Json::ArrayIndex shadingdx = 0; shadingdx < shadingN; ++shadingdx) { |
| 1242 | |||
| 1243 | // each shading should have one face | ||
| 1244 |
5/5✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
✓ Branch 7 taken 69 times.
✓ Branch 10 taken 44 times.
✓ Branch 11 taken 25 times.
|
207 | if (checkKeyAndType(shading[shadingdx], "face_id", Json::stringValue)) { |
| 1245 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 10 taken 44 times.
|
44 | std::string faceId = shading[shadingdx].get("face_id", "").asString(); |
| 1246 | |||
| 1247 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
|
88 | assertKeyAndType(shading[shadingdx], "name", Json::stringValue); |
| 1248 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 10 taken 44 times.
|
44 | std::string shadingName = shading[shadingdx].get("name", "").asString(); |
| 1249 | |||
| 1250 | // translate shading properties, default to story values | ||
| 1251 | 44 | unsigned shadingMultiplier = storyMultiplier; | |
| 1252 |
4/5✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 44 times.
|
132 | if (checkKeyAndType(shading[shadingdx], "multiplier", Json::uintValue)) { |
| 1253 | ✗ | shadingMultiplier = shading[shadingdx].get("multiplier", shadingMultiplier).asUInt(); | |
| 1254 | } | ||
| 1255 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44 times.
|
44 | if (shadingMultiplier == 0) { |
| 1256 | ✗ | shadingMultiplier = 1; | |
| 1257 | } else if (shadingMultiplier > 1) { | ||
| 1258 | //LOG(Warn, "Multiplier translation not yet implemented"); | ||
| 1259 | //shadingMultiplier = 1; | ||
| 1260 | } | ||
| 1261 | |||
| 1262 | 44 | double shadingBelowFloorPlenumHeight = storyBelowFloorPlenumHeight; | |
| 1263 |
5/5✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 43 times.
|
132 | if (checkKeyAndType(shading[shadingdx], "below_floor_plenum_height", Json::realValue)) { |
| 1264 | 1 | shadingBelowFloorPlenumHeight = | |
| 1265 |
4/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
|
1 | lengthToMeters * shading[shadingdx].get("below_floor_plenum_height", shadingBelowFloorPlenumHeight).asDouble(); |
| 1266 | } | ||
| 1267 | |||
| 1268 | 44 | double shadingFloorToCeilingHeight = storyFloorToCeilingHeight; | |
| 1269 |
5/5✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 10 taken 38 times.
✓ Branch 11 taken 6 times.
|
132 | if (checkKeyAndType(shading[shadingdx], "floor_to_ceiling_height", Json::realValue)) { |
| 1270 |
4/4✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
✓ Branch 10 taken 38 times.
|
38 | shadingFloorToCeilingHeight = lengthToMeters * shading[shadingdx].get("floor_to_ceiling_height", shadingFloorToCeilingHeight).asDouble(); |
| 1271 | } | ||
| 1272 | |||
| 1273 | 44 | double shadingAboveCeilingPlenumHeight = storyAboveCeilingPlenumHeight; | |
| 1274 |
5/5✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 10 taken 2 times.
✓ Branch 11 taken 42 times.
|
132 | if (checkKeyAndType(shading[shadingdx], "above_ceiling_plenum_height", Json::realValue)) { |
| 1275 | 2 | shadingAboveCeilingPlenumHeight = | |
| 1276 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | lengthToMeters * shading[shadingdx].get("above_ceiling_plenum_height", shadingAboveCeilingPlenumHeight).asDouble(); |
| 1277 | } | ||
| 1278 | |||
| 1279 | 44 | double shadingFloorOffset = 0; | |
| 1280 |
4/5✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 44 times.
|
132 | if (checkKeyAndType(shading[shadingdx], "floor_offset", Json::realValue)) { |
| 1281 | ✗ | shadingFloorOffset = lengthToMeters * shading[shadingdx].get("floor_offset", shadingFloorOffset).asDouble(); | |
| 1282 | } | ||
| 1283 | |||
| 1284 | 44 | [[maybe_unused]] bool openToBelow = false; | |
| 1285 |
4/5✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 44 times.
|
132 | if (checkKeyAndType(shading[shadingdx], "open_to_below", Json::booleanValue)) { |
| 1286 | ✗ | openToBelow = shading[shadingdx].get("open_to_below", openToBelow).asBool(); | |
| 1287 | } | ||
| 1288 | |||
| 1289 | // create geometry | ||
| 1290 | 44 | double minZ = currentStoryZ + shadingFloorOffset; | |
| 1291 | 44 | double maxZ = currentStoryZ + shadingFloorOffset + shadingBelowFloorPlenumHeight; | |
| 1292 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 40 times.
|
44 | if (shadingBelowFloorPlenumHeight > 0) { |
| 1293 | 4 | anyPlenums = true; | |
| 1294 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
|
20 | ThreeModelObjectMetadata shadingMetadata("OS:ShadingSurfaceGroup", "", shadingName + BELOWFLOORPLENUMPOSTFIX); |
| 1295 |
1/1✓ Branch 1 taken 4 times.
|
4 | shadingMetadata.setMultiplier(shadingMultiplier); |
| 1296 |
1/1✓ Branch 1 taken 4 times.
|
4 | shadingMetadata.setOpenToBelow(openToBelow); |
| 1297 |
1/1✓ Branch 1 taken 4 times.
|
4 | modelObjectMetadata.push_back(shadingMetadata); |
| 1298 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | makeGeometries(stories[storyIdx], shading[shadingdx], true, false, lengthToMeters, minZ, maxZ, vertices, edges, faces, faceId, |
| 1299 | openstudioFormat, geometries, children, openToBelow); | ||
| 1300 | 4 | openToBelow = false; // no longer open | |
| 1301 | 4 | } | |
| 1302 | |||
| 1303 | 44 | minZ = maxZ; | |
| 1304 | 44 | maxZ += shadingFloorToCeilingHeight; | |
| 1305 |
1/2✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 | if (shadingFloorToCeilingHeight > 0) { |
| 1306 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
|
88 | ThreeModelObjectMetadata shadingMetadata = makeModelObjectMetadata("OS:ShadingSurfaceGroup", shading[shadingdx]); |
| 1307 |
1/1✓ Branch 1 taken 44 times.
|
44 | shadingMetadata.setMultiplier(shadingMultiplier); |
| 1308 |
1/1✓ Branch 1 taken 44 times.
|
44 | shadingMetadata.setOpenToBelow(openToBelow); |
| 1309 |
1/1✓ Branch 1 taken 44 times.
|
44 | modelObjectMetadata.push_back(shadingMetadata); |
| 1310 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
|
44 | makeGeometries(stories[storyIdx], shading[shadingdx], false, false, lengthToMeters, minZ, maxZ, vertices, edges, faces, faceId, |
| 1311 | openstudioFormat, geometries, children, openToBelow); | ||
| 1312 | 44 | openToBelow = false; // no longer open | |
| 1313 | 44 | } | |
| 1314 | |||
| 1315 | 44 | minZ = maxZ; | |
| 1316 | 44 | maxZ += shadingAboveCeilingPlenumHeight; | |
| 1317 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 39 times.
|
44 | if (shadingAboveCeilingPlenumHeight > 0) { |
| 1318 | 5 | anyPlenums = true; | |
| 1319 |
4/4✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
|
25 | ThreeModelObjectMetadata shadingMetadata("OS:ShadingSurfaceGroup", "", shadingName + ABOVECEILINGPLENUMPOSTFIX); |
| 1320 |
1/1✓ Branch 1 taken 5 times.
|
5 | shadingMetadata.setMultiplier(shadingMultiplier); |
| 1321 |
1/1✓ Branch 1 taken 5 times.
|
5 | shadingMetadata.setOpenToBelow(openToBelow); |
| 1322 |
1/1✓ Branch 1 taken 5 times.
|
5 | modelObjectMetadata.push_back(shadingMetadata); |
| 1323 |
3/3✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
|
5 | makeGeometries(stories[storyIdx], shading[shadingdx], false, true, lengthToMeters, minZ, maxZ, vertices, edges, faces, faceId, |
| 1324 | openstudioFormat, geometries, children, openToBelow); | ||
| 1325 | 5 | openToBelow = false; // no longer open | |
| 1326 | 5 | } | |
| 1327 | 44 | } | |
| 1328 | |||
| 1329 | } // shading | ||
| 1330 | |||
| 1331 | // increment height for next story, will be (storyBelowFloorPlenumHeight + storyFloorToCeilingHeight + storyAboveCeilingPlenumHeight) for multiplier == 1 | ||
| 1332 | // DLM: TODO need to get the intersection and matching code in utilities, move stories after intersecting and matching | ||
| 1333 | //currentStoryZ += 0.5*(storyMultiplier + 1)*(storyBelowFloorPlenumHeight + storyFloorToCeilingHeight + storyAboveCeilingPlenumHeight); | ||
| 1334 | 101 | currentStoryZ += storyBelowFloorPlenumHeight + storyFloorToCeilingHeight + storyAboveCeilingPlenumHeight; | |
| 1335 | |||
| 1336 | 101 | } // stories | |
| 1337 | |||
| 1338 | // loop over building_units | ||
| 1339 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value buildingUnits = m_value.get("building_units", Json::arrayValue); |
| 1340 |
1/1✓ Branch 1 taken 44 times.
|
44 | Json::ArrayIndex n = buildingUnits.size(); |
| 1341 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 44 times.
|
64 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1342 |
4/4✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
✓ Branch 10 taken 20 times.
|
60 | modelObjectMetadata.push_back(makeModelObjectMetadata("OS:BuildingUnit", buildingUnits[i])); |
| 1343 |
3/3✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
✓ Branch 7 taken 20 times.
|
40 | makeMaterial(buildingUnits[i], "OS:BuildingUnit", materials, materialMap); |
| 1344 | } | ||
| 1345 | |||
| 1346 | // loop over thermal_zones | ||
| 1347 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value thermalZones = m_value.get("thermal_zones", Json::arrayValue); |
| 1348 |
1/1✓ Branch 1 taken 44 times.
|
44 | n = thermalZones.size(); |
| 1349 |
2/2✓ Branch 0 taken 644 times.
✓ Branch 1 taken 44 times.
|
688 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1350 |
4/4✓ Branch 1 taken 644 times.
✓ Branch 4 taken 644 times.
✓ Branch 7 taken 644 times.
✓ Branch 10 taken 644 times.
|
1932 | modelObjectMetadata.push_back(makeModelObjectMetadata("OS:ThermalZone", thermalZones[i])); |
| 1351 |
3/3✓ Branch 1 taken 644 times.
✓ Branch 4 taken 644 times.
✓ Branch 7 taken 644 times.
|
1288 | makeMaterial(thermalZones[i], "OS:ThermalZone", materials, materialMap); |
| 1352 | } | ||
| 1353 | |||
| 1354 | // DLM: how will we merge this plenum zone with existing plenum zones? | ||
| 1355 |
2/2✓ Branch 5 taken 16 times.
✓ Branch 6 taken 44 times.
|
60 | for (const auto& thermalZoneName : m_plenumThermalZoneNames) { |
| 1356 |
3/3✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
✓ Branch 7 taken 16 times.
|
48 | ThreeModelObjectMetadata thermalZoneMetadata("OS:ThermalZone", "", thermalZoneName); |
| 1357 |
1/1✓ Branch 1 taken 16 times.
|
16 | modelObjectMetadata.push_back(thermalZoneMetadata); |
| 1358 |
2/2✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
|
16 | thermalZoneMetadata.setColor(PLENUMCOLOR); // already made in makeStandardThreeMaterials |
| 1359 | 16 | } | |
| 1360 | |||
| 1361 | // loop over space_types | ||
| 1362 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value spaceTypes = m_value.get("space_types", Json::arrayValue); |
| 1363 |
1/1✓ Branch 1 taken 44 times.
|
44 | n = spaceTypes.size(); |
| 1364 |
2/2✓ Branch 0 taken 145 times.
✓ Branch 1 taken 44 times.
|
189 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1365 |
4/4✓ Branch 1 taken 145 times.
✓ Branch 4 taken 145 times.
✓ Branch 7 taken 145 times.
✓ Branch 10 taken 145 times.
|
435 | modelObjectMetadata.push_back(makeModelObjectMetadata("OS:SpaceType", spaceTypes[i])); |
| 1366 |
3/3✓ Branch 1 taken 145 times.
✓ Branch 4 taken 145 times.
✓ Branch 7 taken 145 times.
|
290 | makeMaterial(spaceTypes[i], "OS:SpaceType", materials, materialMap); |
| 1367 | } | ||
| 1368 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 39 times.
|
44 | if (anyPlenums) { |
| 1369 |
4/4✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
|
25 | ThreeModelObjectMetadata spaceTypeMetadata("OS:SpaceType", "", PLENUMSPACETYPENAME); |
| 1370 |
1/1✓ Branch 1 taken 5 times.
|
5 | modelObjectMetadata.push_back(spaceTypeMetadata); |
| 1371 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | spaceTypeMetadata.setColor(PLENUMCOLOR); // already made in makeStandardThreeMaterials |
| 1372 | 5 | } | |
| 1373 | |||
| 1374 | // loop over construction_sets | ||
| 1375 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value constructionSets = m_value.get("construction_sets", Json::arrayValue); |
| 1376 |
1/1✓ Branch 1 taken 44 times.
|
44 | n = constructionSets.size(); |
| 1377 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 44 times.
|
62 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1378 |
4/4✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 7 taken 18 times.
✓ Branch 10 taken 18 times.
|
54 | modelObjectMetadata.push_back(makeModelObjectMetadata("OS:DefaultConstructionSet", constructionSets[i])); |
| 1379 | //makeMaterial(constructionSets[i], "OS:DefaultConstructionSet", materials, materialMap); | ||
| 1380 | } | ||
| 1381 | |||
| 1382 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | m_boundingBox.addPoint(Point3d(0, 0, 0)); |
| 1383 | |||
| 1384 | 44 | double lookAtX = 0; // (boundingBox.minX().get() + boundingBox.maxX().get()) / 2.0 | |
| 1385 | 44 | double lookAtY = 0; // (boundingBox.minY().get() + boundingBox.maxY().get()) / 2.0 | |
| 1386 | 44 | double lookAtZ = 0; // (boundingBox.minZ().get() + boundingBox.maxZ().get()) / 2.0 | |
| 1387 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
44 | double lookAtR = sqrt(std::pow(m_boundingBox.maxX().get() / 2.0, 2) + std::pow(m_boundingBox.maxY().get() / 2.0, 2) |
| 1388 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.maxZ().get() / 2.0, 2)); |
| 1389 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
88 | lookAtR = std::max(lookAtR, sqrt(std::pow(m_boundingBox.minX().get() / 2.0, 2) + std::pow(m_boundingBox.maxY().get() / 2.0, 2) |
| 1390 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.maxZ().get() / 2.0, 2))); |
| 1391 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
88 | lookAtR = std::max(lookAtR, sqrt(std::pow(m_boundingBox.maxX().get() / 2.0, 2) + std::pow(m_boundingBox.minY().get() / 2.0, 2) |
| 1392 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.maxZ().get() / 2.0, 2))); |
| 1393 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
88 | lookAtR = std::max(lookAtR, sqrt(std::pow(m_boundingBox.maxX().get() / 2.0, 2) + std::pow(m_boundingBox.maxY().get() / 2.0, 2) |
| 1394 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.minZ().get() / 2.0, 2))); |
| 1395 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
88 | lookAtR = std::max(lookAtR, sqrt(std::pow(m_boundingBox.minX().get() / 2.0, 2) + std::pow(m_boundingBox.minY().get() / 2.0, 2) |
| 1396 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.maxZ().get() / 2.0, 2))); |
| 1397 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
88 | lookAtR = std::max(lookAtR, sqrt(std::pow(m_boundingBox.minX().get() / 2.0, 2) + std::pow(m_boundingBox.maxY().get() / 2.0, 2) |
| 1398 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.minZ().get() / 2.0, 2))); |
| 1399 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
88 | lookAtR = std::max(lookAtR, sqrt(std::pow(m_boundingBox.maxX().get() / 2.0, 2) + std::pow(m_boundingBox.minY().get() / 2.0, 2) |
| 1400 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.minZ().get() / 2.0, 2))); |
| 1401 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 8 taken 44 times.
✓ Branch 11 taken 44 times.
|
88 | lookAtR = std::max(lookAtR, sqrt(std::pow(m_boundingBox.minX().get() / 2.0, 2) + std::pow(m_boundingBox.minY().get() / 2.0, 2) |
| 1402 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | + std::pow(m_boundingBox.minZ().get() / 2.0, 2))); |
| 1403 | |||
| 1404 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 10 taken 44 times.
|
176 | ThreeBoundingBox boundingBox(m_boundingBox.minX().get(), m_boundingBox.minY().get(), m_boundingBox.minZ().get(), m_boundingBox.maxX().get(), |
| 1405 |
9/9✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
✓ Branch 10 taken 44 times.
✓ Branch 13 taken 44 times.
✓ Branch 16 taken 44 times.
✓ Branch 19 taken 44 times.
✓ Branch 22 taken 44 times.
✓ Branch 25 taken 44 times.
|
220 | m_boundingBox.maxY().get(), m_boundingBox.maxZ().get(), lookAtX, lookAtY, lookAtZ, lookAtR); |
| 1406 | |||
| 1407 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | ThreeSceneMetadata metadata(buildingStoryNames, boundingBox, northAxis(), modelObjectMetadata); |
| 1408 | |||
| 1409 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | ThreeSceneObject sceneObject("", children); |
| 1410 | |||
| 1411 |
1/1✓ Branch 1 taken 44 times.
|
44 | ThreeScene result(metadata, geometries, materials, sceneObject); |
| 1412 | |||
| 1413 | 88 | return result; | |
| 1414 | 44 | } | |
| 1415 | |||
| 1416 | 44 | std::string FloorplanJS::units() const { | |
| 1417 |
1/1✓ Branch 1 taken 44 times.
|
44 | std::string units = "ip"; |
| 1418 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value project = m_value.get("project", Json::objectValue); |
| 1419 |
2/3✓ Branch 1 taken 44 times.
✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
|
44 | if (!project.isNull()) { |
| 1420 |
2/2✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
|
44 | Json::Value config = project.get("config", Json::objectValue); |
| 1421 |
2/3✓ Branch 1 taken 44 times.
✓ Branch 3 taken 44 times.
✗ Branch 4 not taken.
|
44 | if (!config.isNull()) { |
| 1422 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 44 times.
|
44 | units = config.get("units", units).asString(); |
| 1423 | } | ||
| 1424 | 44 | } | |
| 1425 |
4/4✓ Branch 1 taken 44 times.
✓ Branch 4 taken 44 times.
✓ Branch 7 taken 17 times.
✓ Branch 8 taken 27 times.
|
88 | if (istringEqual(units, "ft")) { |
| 1426 |
1/1✓ Branch 1 taken 17 times.
|
17 | units = "ip"; |
| 1427 | } | ||
| 1428 | 88 | return units; | |
| 1429 | 44 | } | |
| 1430 | |||
| 1431 | ✗ | bool FloorplanJS::setUnits(const std::string& units) { | |
| 1432 | ✗ | if (!(istringEqual(units, "ip") || istringEqual(units, "si"))) { | |
| 1433 | ✗ | return false; | |
| 1434 | } | ||
| 1435 | |||
| 1436 | ✗ | if (!checkKeyAndType(m_value, "project", Json::objectValue)) { | |
| 1437 | ✗ | m_value["project"] = Json::Value(Json::objectValue); | |
| 1438 | } | ||
| 1439 | ✗ | Json::Value& project = m_value["project"]; | |
| 1440 | |||
| 1441 | ✗ | if (!checkKeyAndType(project, "config", Json::objectValue)) { | |
| 1442 | ✗ | project["config"] = Json::Value(Json::objectValue); | |
| 1443 | } | ||
| 1444 | ✗ | Json::Value& config = project["config"]; | |
| 1445 | |||
| 1446 | ✗ | config["units"] = units; | |
| 1447 | |||
| 1448 | ✗ | return true; | |
| 1449 | } | ||
| 1450 | |||
| 1451 | ✗ | void FloorplanJS::resetUnits() { | |
| 1452 | ✗ | setUnits("ip"); | |
| 1453 | ✗ | } | |
| 1454 | |||
| 1455 | 46 | double FloorplanJS::northAxis() const { | |
| 1456 | 46 | double result = 0; | |
| 1457 |
2/2✓ Branch 1 taken 46 times.
✓ Branch 4 taken 46 times.
|
46 | Json::Value project = m_value.get("project", Json::objectValue); |
| 1458 |
2/3✓ Branch 1 taken 46 times.
✓ Branch 3 taken 46 times.
✗ Branch 4 not taken.
|
46 | if (!project.isNull()) { |
| 1459 |
3/3✓ Branch 1 taken 46 times.
✓ Branch 3 taken 32 times.
✓ Branch 4 taken 14 times.
|
46 | if (project.isMember("north_axis")) { |
| 1460 | // current location | ||
| 1461 |
3/3✓ Branch 1 taken 32 times.
✓ Branch 4 taken 32 times.
✓ Branch 7 taken 32 times.
|
32 | result = project.get("north_axis", result).asDouble(); |
| 1462 | } else { | ||
| 1463 | // previous location | ||
| 1464 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | Json::Value config = project.get("config", Json::objectValue); |
| 1465 |
2/3✓ Branch 1 taken 14 times.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
|
14 | if (!config.isNull()) { |
| 1466 |
3/3✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
|
14 | result = config.get("north_axis", result).asDouble(); |
| 1467 | } | ||
| 1468 | 14 | } | |
| 1469 | } | ||
| 1470 | 46 | return result; | |
| 1471 | 46 | } | |
| 1472 | |||
| 1473 | ✗ | bool FloorplanJS::setNorthAxis(double northAxis) { | |
| 1474 | ✗ | if (!checkKeyAndType(m_value, "project", Json::objectValue)) { | |
| 1475 | ✗ | m_value["project"] = Json::Value(Json::objectValue); | |
| 1476 | } | ||
| 1477 | ✗ | Json::Value& project = m_value["project"]; | |
| 1478 | |||
| 1479 | ✗ | project["north_axis"] = northAxis; | |
| 1480 | |||
| 1481 | ✗ | if (!checkKeyAndType(project, "map", Json::objectValue)) { | |
| 1482 | ✗ | project["map"] = Json::Value(Json::objectValue); | |
| 1483 | } | ||
| 1484 | ✗ | Json::Value& map = project["map"]; | |
| 1485 | |||
| 1486 | ✗ | map["rotation"] = degToRad(northAxis); | |
| 1487 | |||
| 1488 | ✗ | return true; | |
| 1489 | } | ||
| 1490 | |||
| 1491 | ✗ | void FloorplanJS::resetNorthAxis() { | |
| 1492 | ✗ | setNorthAxis(0); | |
| 1493 | ✗ | } | |
| 1494 | |||
| 1495 | 2 | double FloorplanJS::latitude() const { | |
| 1496 | 2 | double result = 0; | |
| 1497 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | Json::Value project = m_value.get("project", Json::objectValue); |
| 1498 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if (!project.isNull()) { |
| 1499 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | Json::Value map = project.get("map", Json::objectValue); |
| 1500 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if (!map.isNull()) { |
| 1501 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | result = map.get("latitude", result).asDouble(); |
| 1502 | } | ||
| 1503 | 2 | } | |
| 1504 | 2 | return result; | |
| 1505 | 2 | } | |
| 1506 | |||
| 1507 | ✗ | bool FloorplanJS::setLatitude(double latitude) { | |
| 1508 | ✗ | if (!checkKeyAndType(m_value, "project", Json::objectValue)) { | |
| 1509 | ✗ | m_value["project"] = Json::Value(Json::objectValue); | |
| 1510 | } | ||
| 1511 | ✗ | Json::Value& project = m_value["project"]; | |
| 1512 | |||
| 1513 | ✗ | if (!checkKeyAndType(project, "map", Json::objectValue)) { | |
| 1514 | ✗ | project["map"] = Json::Value(Json::objectValue); | |
| 1515 | } | ||
| 1516 | ✗ | Json::Value& map = project["map"]; | |
| 1517 | |||
| 1518 | ✗ | map["latitude"] = latitude; | |
| 1519 | |||
| 1520 | ✗ | return true; | |
| 1521 | } | ||
| 1522 | |||
| 1523 | ✗ | void FloorplanJS::resetLatitude() { | |
| 1524 | ✗ | setLatitude(0); | |
| 1525 | ✗ | } | |
| 1526 | |||
| 1527 | 2 | double FloorplanJS::longitude() const { | |
| 1528 | 2 | double result = 0; | |
| 1529 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | Json::Value project = m_value.get("project", Json::objectValue); |
| 1530 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if (!project.isNull()) { |
| 1531 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | Json::Value map = project.get("map", Json::objectValue); |
| 1532 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if (!map.isNull()) { |
| 1533 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | result = map.get("longitude", result).asDouble(); |
| 1534 | } | ||
| 1535 | 2 | } | |
| 1536 | 2 | return result; | |
| 1537 | 2 | } | |
| 1538 | |||
| 1539 | ✗ | bool FloorplanJS::setLongitude(double longitude) { | |
| 1540 | ✗ | if (!checkKeyAndType(m_value, "project", Json::objectValue)) { | |
| 1541 | ✗ | m_value["project"] = Json::Value(Json::objectValue); | |
| 1542 | } | ||
| 1543 | ✗ | Json::Value& project = m_value["project"]; | |
| 1544 | |||
| 1545 | ✗ | if (!checkKeyAndType(project, "map", Json::objectValue)) { | |
| 1546 | ✗ | project["map"] = Json::Value(Json::objectValue); | |
| 1547 | } | ||
| 1548 | ✗ | Json::Value& map = project["map"]; | |
| 1549 | |||
| 1550 | ✗ | map["longitude"] = longitude; | |
| 1551 | |||
| 1552 | ✗ | return true; | |
| 1553 | } | ||
| 1554 | |||
| 1555 | ✗ | void FloorplanJS::resetLongitude() { | |
| 1556 | ✗ | setLongitude(0); | |
| 1557 | ✗ | } | |
| 1558 | |||
| 1559 | 2 | double FloorplanJS::elevation() const { | |
| 1560 | 2 | double result = 0; | |
| 1561 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | Json::Value project = m_value.get("project", Json::objectValue); |
| 1562 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if (!project.isNull()) { |
| 1563 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | Json::Value map = project.get("map", Json::objectValue); |
| 1564 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2 | if (!map.isNull()) { |
| 1565 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | result = map.get("elevation", result).asDouble(); |
| 1566 | } | ||
| 1567 | 2 | } | |
| 1568 | 2 | return result; | |
| 1569 | 2 | } | |
| 1570 | |||
| 1571 | ✗ | bool FloorplanJS::setElevation(double elevation) { | |
| 1572 | ✗ | if (!checkKeyAndType(m_value, "project", Json::objectValue)) { | |
| 1573 | ✗ | m_value["project"] = Json::Value(Json::objectValue); | |
| 1574 | } | ||
| 1575 | ✗ | Json::Value& project = m_value["project"]; | |
| 1576 | |||
| 1577 | ✗ | if (!checkKeyAndType(project, "map", Json::objectValue)) { | |
| 1578 | ✗ | project["map"] = Json::Value(Json::objectValue); | |
| 1579 | } | ||
| 1580 | ✗ | Json::Value& map = project["map"]; | |
| 1581 | |||
| 1582 | ✗ | map["elevation"] = elevation; | |
| 1583 | |||
| 1584 | ✗ | return true; | |
| 1585 | } | ||
| 1586 | |||
| 1587 | ✗ | void FloorplanJS::resetElevation() { | |
| 1588 | ✗ | setElevation(0); | |
| 1589 | ✗ | } | |
| 1590 | |||
| 1591 | 5 | void FloorplanJS::updateStories(const std::vector<FloorplanObject>& objects, bool removeMissingObjects) { | |
| 1592 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
10 | updateObjects(m_value, "stories", objects, removeMissingObjects); |
| 1593 | 5 | } | |
| 1594 | |||
| 1595 | 5 | void FloorplanJS::updateSpaces(const std::vector<FloorplanObject>& objects, bool removeMissingObjects) { | |
| 1596 | 5 | std::map<std::string, std::vector<FloorplanObject>> storyHandleToSpaceObejctIds; | |
| 1597 | |||
| 1598 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 6 taken 5 times.
|
9 | for (const auto& object : objects) { |
| 1599 |
1/1✓ Branch 1 taken 4 times.
|
4 | boost::optional<std::string> parentHandleString = object.parentHandleString(); |
| 1600 | |||
| 1601 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (!parentHandleString) { |
| 1602 | ✗ | continue; | |
| 1603 | } | ||
| 1604 | |||
| 1605 |
3/4✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✗ Branch 9 not taken.
|
4 | if (storyHandleToSpaceObejctIds.find(*parentHandleString) == storyHandleToSpaceObejctIds.end()) { |
| 1606 | // cppcheck-suppress stlFindInsert | ||
| 1607 |
2/2✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
|
4 | storyHandleToSpaceObejctIds[*parentHandleString] = std::vector<FloorplanObject>(); |
| 1608 | } | ||
| 1609 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | storyHandleToSpaceObejctIds[*parentHandleString].push_back(object); |
| 1610 | 4 | } | |
| 1611 | |||
| 1612 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 6 taken 5 times.
|
9 | for (const auto& keyValue : storyHandleToSpaceObejctIds) { |
| 1613 | // no need to check by name, assume stories have been updated | ||
| 1614 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
8 | Json::Value* story = findByHandleString(m_value, "stories", keyValue.first); |
| 1615 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (story) { |
| 1616 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
12 | updateObjects(*story, "spaces", keyValue.second, removeMissingObjects); |
| 1617 | } | ||
| 1618 | } | ||
| 1619 | 5 | } | |
| 1620 | |||
| 1621 | 5 | void FloorplanJS::updateBuildingUnits(const std::vector<FloorplanObject>& objects, bool removeMissingObjects) { | |
| 1622 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
10 | updateObjects(m_value, "building_units", objects, removeMissingObjects); |
| 1623 | 5 | } | |
| 1624 | |||
| 1625 | 5 | void FloorplanJS::updateThermalZones(const std::vector<FloorplanObject>& objects, bool removeMissingObjects) { | |
| 1626 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
10 | updateObjects(m_value, "thermal_zones", objects, removeMissingObjects); |
| 1627 | 5 | } | |
| 1628 | |||
| 1629 | 5 | void FloorplanJS::updateSpaceTypes(const std::vector<FloorplanObject>& objects, bool removeMissingObjects) { | |
| 1630 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
10 | updateObjects(m_value, "space_types", objects, removeMissingObjects); |
| 1631 | 5 | } | |
| 1632 | |||
| 1633 | 5 | void FloorplanJS::updateConstructionSets(const std::vector<FloorplanObject>& objects, bool removeMissingObjects) { | |
| 1634 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
10 | updateObjects(m_value, "construction_sets", objects, removeMissingObjects); |
| 1635 | 5 | } | |
| 1636 | |||
| 1637 | 33 | std::string FloorplanJS::getHandleString(const Json::Value& value) { | |
| 1638 |
3/3✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
✓ Branch 7 taken 33 times.
|
33 | return value.get("handle", "").asString(); |
| 1639 | } | ||
| 1640 | |||
| 1641 | 9 | std::string FloorplanJS::getName(const Json::Value& value) { | |
| 1642 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | return value.get("name", "").asString(); |
| 1643 | } | ||
| 1644 | |||
| 1645 | 911872 | std::string FloorplanJS::getId(const Json::Value& value) { | |
| 1646 |
3/3✓ Branch 1 taken 911872 times.
✓ Branch 4 taken 911872 times.
✓ Branch 7 taken 911872 times.
|
911872 | return value.get("id", "").asString(); |
| 1647 | } | ||
| 1648 | |||
| 1649 | 4 | std::string FloorplanJS::getFaceId(const Json::Value& value) { | |
| 1650 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | return value.get("face_id", "").asString(); |
| 1651 | } | ||
| 1652 | |||
| 1653 | 6 | std::string FloorplanJS::getNextId() { | |
| 1654 | 6 | ++m_lastId; | |
| 1655 | 6 | return std::to_string(m_lastId); | |
| 1656 | } | ||
| 1657 | |||
| 1658 | 46194 | void FloorplanJS::setLastId(const Json::Value& value) { | |
| 1659 |
2/2✓ Branch 1 taken 13127 times.
✓ Branch 2 taken 33067 times.
|
46194 | if (value.isObject()) { |
| 1660 |
3/3✓ Branch 1 taken 13127 times.
✓ Branch 8 taken 66292 times.
✓ Branch 9 taken 13127 times.
|
79419 | for (const auto& key : value.getMemberNames()) { |
| 1661 |
1/1✓ Branch 1 taken 66292 times.
|
66292 | const auto& value2 = value[key]; |
| 1662 |
3/3✓ Branch 1 taken 66292 times.
✓ Branch 3 taken 14617 times.
✓ Branch 4 taken 51675 times.
|
66292 | if (value2.isArray()) { |
| 1663 |
1/1✓ Branch 1 taken 14617 times.
|
14617 | Json::ArrayIndex n = value2.size(); |
| 1664 |
2/2✓ Branch 0 taken 44751 times.
✓ Branch 1 taken 14617 times.
|
59368 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1665 |
2/2✓ Branch 1 taken 44751 times.
✓ Branch 4 taken 44751 times.
|
44751 | setLastId(value2[i]); |
| 1666 | } | ||
| 1667 |
3/3✓ Branch 1 taken 51675 times.
✓ Branch 3 taken 1397 times.
✓ Branch 4 taken 50278 times.
|
51675 | } else if (value2.isObject()) { |
| 1668 |
1/1✓ Branch 1 taken 1397 times.
|
1397 | setLastId(value2); |
| 1669 |
3/3✓ Branch 1 taken 50278 times.
✓ Branch 3 taken 11806 times.
✓ Branch 4 taken 38472 times.
|
50278 | } else if (key == "id") { |
| 1670 |
3/3✓ Branch 1 taken 11806 times.
✓ Branch 3 taken 10312 times.
✓ Branch 4 taken 1494 times.
|
11806 | if (value2.isString()) { |
| 1671 |
1/1✓ Branch 1 taken 10312 times.
|
10312 | std::string s = value2.asString(); |
| 1672 | 10312 | unsigned id = strtoul(s.c_str(), nullptr, 0); | |
| 1673 | //if (id > 100){ | ||
| 1674 | //// DLM: TODO test code, remove | ||
| 1675 | //bool test= false; | ||
| 1676 | //} | ||
| 1677 | 10312 | m_lastId = std::max(m_lastId, id); | |
| 1678 |
2/3✓ Branch 2 taken 1494 times.
✓ Branch 4 taken 1494 times.
✗ Branch 5 not taken.
|
11806 | } else if (value2.isConvertibleTo(Json::ValueType::uintValue)) { |
| 1679 |
1/1✓ Branch 1 taken 1494 times.
|
1494 | unsigned id = value2.asUInt(); |
| 1680 | //if (id > 100){ | ||
| 1681 | //// DLM: TODO test code, remove | ||
| 1682 | //bool test = false; | ||
| 1683 | //} | ||
| 1684 | 1494 | m_lastId = std::max(m_lastId, id); | |
| 1685 | } | ||
| 1686 | } | ||
| 1687 | 13127 | } | |
| 1688 | } | ||
| 1689 | 46194 | } | |
| 1690 | |||
| 1691 | 26 | Json::Value* FloorplanJS::findByHandleString(Json::Value& value, const std::string& key, const std::string& handleString) { | |
| 1692 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 26 times.
|
26 | if (handleString.empty()) { |
| 1693 | ✗ | return nullptr; | |
| 1694 | } | ||
| 1695 | |||
| 1696 | 26 | Json::Value& values = value[key]; | |
| 1697 | 26 | Json::ArrayIndex n = values.size(); | |
| 1698 |
2/2✓ Branch 0 taken 21 times.
✓ Branch 1 taken 10 times.
|
31 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1699 |
4/4✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 8 taken 16 times.
✓ Branch 9 taken 5 times.
|
21 | if (getHandleString(values[i]) == handleString) { |
| 1700 | 16 | return &values[i]; | |
| 1701 | } | ||
| 1702 | } | ||
| 1703 | |||
| 1704 | 10 | return nullptr; | |
| 1705 | } | ||
| 1706 | |||
| 1707 | 10 | Json::Value* FloorplanJS::findByName(Json::Value& value, const std::string& key, const std::string& name, bool requireEmptyHandle) { | |
| 1708 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (name.empty()) { |
| 1709 | ✗ | return nullptr; | |
| 1710 | } | ||
| 1711 | |||
| 1712 | 10 | Json::Value& values = value[key]; | |
| 1713 | 10 | Json::ArrayIndex n = values.size(); | |
| 1714 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 6 times.
|
11 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1715 |
4/4✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 1 time.
|
5 | if (getName(values[i]) == name) { |
| 1716 | // TODO: Both branches do the same! | ||
| 1717 | // cppcheck-suppress duplicateBranch | ||
| 1718 |
6/12✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 6 taken 4 times.
✓ Branch 9 taken 4 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 4 times.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
4 | if (requireEmptyHandle && getHandleString(values[i]).empty()) { |
| 1719 | 4 | return &values[i]; | |
| 1720 | } else { | ||
| 1721 | ✗ | return &values[i]; | |
| 1722 | } | ||
| 1723 | } | ||
| 1724 | } | ||
| 1725 | |||
| 1726 | 6 | return nullptr; | |
| 1727 | } | ||
| 1728 | |||
| 1729 | ✗ | Json::Value* FloorplanJS::findById(Json::Value& value, const std::string& key, const std::string& id) { | |
| 1730 | ✗ | if (id.empty()) { | |
| 1731 | ✗ | return nullptr; | |
| 1732 | } | ||
| 1733 | |||
| 1734 | ✗ | Json::Value& values = value[key]; | |
| 1735 | ✗ | Json::ArrayIndex n = values.size(); | |
| 1736 | ✗ | for (Json::ArrayIndex i = 0; i < n; ++i) { | |
| 1737 | ✗ | if (getId(values[i]) == id) { | |
| 1738 | ✗ | return &values[i]; | |
| 1739 | } | ||
| 1740 | } | ||
| 1741 | |||
| 1742 | ✗ | return nullptr; | |
| 1743 | } | ||
| 1744 | |||
| 1745 | 34673 | const Json::Value* FloorplanJS::findById(const Json::Value& values, const std::string& id) const { | |
| 1746 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 34673 times.
|
34673 | if (id.empty()) { |
| 1747 | ✗ | return nullptr; | |
| 1748 | } | ||
| 1749 | |||
| 1750 | 34673 | Json::ArrayIndex n = values.size(); | |
| 1751 |
2/2✓ Branch 0 taken 911872 times.
✓ Branch 1 taken 228 times.
|
912100 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1752 |
4/4✓ Branch 1 taken 911872 times.
✓ Branch 4 taken 911872 times.
✓ Branch 8 taken 34445 times.
✓ Branch 9 taken 877427 times.
|
911872 | if (getId(values[i]) == id) { |
| 1753 | 34445 | return &values[i]; | |
| 1754 | } | ||
| 1755 | } | ||
| 1756 | |||
| 1757 | 228 | return nullptr; | |
| 1758 | } | ||
| 1759 | |||
| 1760 | 29 | void FloorplanJS::updateObjects(Json::Value& value, const std::string& key, const std::vector<FloorplanObject>& objects, bool removeMissingObjects) { | |
| 1761 | // ensure key exists | ||
| 1762 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 24 times.
|
29 | if (!value.isMember(key)) { |
| 1763 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
|
5 | value[key] = Json::Value(Json::arrayValue); |
| 1764 | } | ||
| 1765 | |||
| 1766 | // remove all objects that aren't found by handle or name | ||
| 1767 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 17 times.
|
29 | if (removeMissingObjects) { |
| 1768 | 12 | std::set<std::string> ids; | |
| 1769 | 12 | std::set<std::string> names; | |
| 1770 | 12 | std::set<std::string> handleStrings; | |
| 1771 |
2/2✓ Branch 4 taken 4 times.
✓ Branch 5 taken 12 times.
|
16 | for (const auto& object : objects) { |
| 1772 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | ids.insert(object.id()); |
| 1773 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | names.insert(object.name()); |
| 1774 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | handleStrings.insert(object.handleString()); |
| 1775 | } | ||
| 1776 | |||
| 1777 | 12 | std::vector<Json::ArrayIndex> indicesToRemove; | |
| 1778 | 12 | std::set<std::string> faceIdsToRemove; | |
| 1779 |
1/1✓ Branch 1 taken 12 times.
|
12 | Json::Value& values = value[key]; |
| 1780 |
1/1✓ Branch 1 taken 12 times.
|
12 | Json::ArrayIndex n = values.size(); |
| 1781 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 12 times.
|
20 | for (Json::ArrayIndex i = 0; i < n; ++i) { |
| 1782 |
2/2✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
|
8 | std::string handle = getHandleString(values[i]); |
| 1783 | // empty handle indicates that object has not been synched with the osm yet | ||
| 1784 |
7/7✓ Branch 1 taken 6 times.
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 6 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 4 times.
|
8 | if (!handle.empty() && (handleStrings.find(handle) == handleStrings.end())) { |
| 1785 | |||
| 1786 | // no object in floorplan should have an empty name | ||
| 1787 |
4/5✓ Branch 2 taken 4 times.
✓ Branch 5 taken 4 times.
✓ Branch 8 taken 4 times.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
|
4 | if (names.find(getName(values[i])) == names.end()) { |
| 1788 |
1/1✓ Branch 1 taken 4 times.
|
4 | indicesToRemove.push_back(i); |
| 1789 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | std::string faceId = getFaceId(values[i]); |
| 1790 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (!faceId.empty()) { |
| 1791 | ✗ | faceIdsToRemove.insert(faceId); | |
| 1792 | } | ||
| 1793 | 4 | } | |
| 1794 | } | ||
| 1795 | 8 | } | |
| 1796 |
1/1✓ Branch 3 taken 12 times.
|
12 | std::reverse(indicesToRemove.begin(), indicesToRemove.end()); |
| 1797 | |||
| 1798 |
2/2✓ Branch 5 taken 4 times.
✓ Branch 6 taken 12 times.
|
16 | for (const auto& i : indicesToRemove) { |
| 1799 |
1/1✓ Branch 1 taken 4 times.
|
4 | Json::Value removed; |
| 1800 |
1/1✓ Branch 1 taken 4 times.
|
4 | values.removeIndex(i, &removed); |
| 1801 | 4 | } | |
| 1802 | |||
| 1803 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
|
12 | if (!faceIdsToRemove.empty()) { |
| 1804 | ✗ | if (checkKeyAndType(value, "geometry", Json::objectValue)) { | |
| 1805 | ✗ | removeFaces(value["geometry"], faceIdsToRemove); | |
| 1806 | } | ||
| 1807 | } | ||
| 1808 | 12 | } | |
| 1809 | |||
| 1810 | // now update names and data | ||
| 1811 |
2/2✓ Branch 5 taken 18 times.
✓ Branch 6 taken 29 times.
|
47 | for (const auto& object : objects) { |
| 1812 | |||
| 1813 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
|
18 | Json::Value* v = findByHandleString(value, key, object.handleString()); |
| 1814 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 10 times.
|
18 | if (v) { |
| 1815 | // ensure name is the same | ||
| 1816 |
3/3✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
✓ Branch 7 taken 8 times.
|
8 | (*v)["name"] = object.name(); |
| 1817 | } else { | ||
| 1818 | // find object by name only if handle is empty | ||
| 1819 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | v = findByName(value, key, object.name(), true); |
| 1820 | |||
| 1821 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 6 times.
|
10 | if (v) { |
| 1822 | // set handle | ||
| 1823 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | (*v)["handle"] = object.handleString(); |
| 1824 | } else { | ||
| 1825 | // create new object | ||
| 1826 |
1/1✓ Branch 1 taken 6 times.
|
6 | Json::Value newObject(Json::objectValue); |
| 1827 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | newObject["id"] = getNextId(); |
| 1828 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | newObject["name"] = object.name(); |
| 1829 |
3/3✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
|
6 | newObject["handle"] = object.handleString(); |
| 1830 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | v = &(value[key].append(newObject)); |
| 1831 | 6 | } | |
| 1832 | } | ||
| 1833 | |||
| 1834 |
1/2✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 | if (v) { |
| 1835 | // update properties | ||
| 1836 |
1/1✓ Branch 1 taken 18 times.
|
18 | Json::Value data = object.data(); |
| 1837 |
3/3✓ Branch 1 taken 18 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 18 times.
|
20 | for (const auto& k : data.getMemberNames()) { |
| 1838 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | (*v)[k] = data[k]; |
| 1839 | 18 | } | |
| 1840 | |||
| 1841 | // update references | ||
| 1842 |
3/3✓ Branch 1 taken 18 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 18 times.
|
22 | for (const auto& p : object.objectReferenceMap()) { |
| 1843 |
1/1✓ Branch 1 taken 4 times.
|
4 | updateObjectReference(*v, p.first, p.second, removeMissingObjects); |
| 1844 | 18 | } | |
| 1845 | 18 | } | |
| 1846 | } | ||
| 1847 | 29 | } | |
| 1848 | |||
| 1849 | 4 | void FloorplanJS::updateObjectReference(Json::Value& value, const std::string& key, const FloorplanObject& objectReference, | |
| 1850 | bool /*removeMissingObjects*/) { | ||
| 1851 | 4 | std::string searchKey; | |
| 1852 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 3 times.
|
4 | if (key == "thermal_zone_id") { |
| 1853 |
1/1✓ Branch 1 taken 1 time.
|
1 | searchKey = "thermal_zones"; |
| 1854 |
3/3✓ Branch 1 taken 3 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 2 times.
|
3 | } else if (key == "space_type_id") { |
| 1855 |
1/1✓ Branch 1 taken 1 time.
|
1 | searchKey = "space_types"; |
| 1856 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
|
2 | } else if (key == "building_unit_id") { |
| 1857 |
1/1✓ Branch 1 taken 1 time.
|
1 | searchKey = "building_units"; |
| 1858 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
1 | } else if (key == "construction_set_id") { |
| 1859 |
1/1✓ Branch 1 taken 1 time.
|
1 | searchKey = "construction_sets"; |
| 1860 | } | ||
| 1861 | |||
| 1862 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (searchKey.empty()) { |
| 1863 | ✗ | LOG(Error, "Could not find objects to search for key '" << key << "'"); | |
| 1864 | ✗ | return; | |
| 1865 | } | ||
| 1866 | |||
| 1867 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
|
4 | Json::Value* v = findByHandleString(m_value, searchKey, objectReference.handleString()); |
| 1868 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (v) { |
| 1869 |
5/5✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
✓ Branch 13 taken 4 times.
|
4 | value[key] = v->get("id", "").asString(); |
| 1870 | 4 | return; | |
| 1871 | } | ||
| 1872 | |||
| 1873 | ✗ | v = findById(m_value, searchKey, objectReference.id()); | |
| 1874 | ✗ | if (v) { | |
| 1875 | ✗ | value[key] = v->get("id", "").asString(); | |
| 1876 | ✗ | return; | |
| 1877 | } | ||
| 1878 | |||
| 1879 | ✗ | v = findByName(m_value, searchKey, objectReference.name(), true); | |
| 1880 | ✗ | if (v) { | |
| 1881 | ✗ | value[key] = v->get("id", "").asString(); | |
| 1882 | ✗ | return; | |
| 1883 | } | ||
| 1884 | |||
| 1885 | ✗ | value[key] = ""; | |
| 1886 | 4 | } | |
| 1887 | |||
| 1888 | ✗ | void FloorplanJS::removeFaces(Json::Value& value, const std::set<std::string>& faceIdsToRemove) { | |
| 1889 | ✗ | if (!checkKeyAndType(value, "faces", Json::arrayValue)) { | |
| 1890 | ✗ | return; | |
| 1891 | } | ||
| 1892 | |||
| 1893 | ✗ | std::map<std::string, unsigned> edgeRefCount; | |
| 1894 | ✗ | std::set<std::string> edgeIdsToRemove; | |
| 1895 | |||
| 1896 | ✗ | std::vector<Json::ArrayIndex> indicesToRemove; | |
| 1897 | ✗ | Json::Value& faces = value["faces"]; | |
| 1898 | ✗ | Json::ArrayIndex n = faces.size(); | |
| 1899 | ✗ | for (Json::ArrayIndex i = 0; i < n; ++i) { | |
| 1900 | ✗ | bool removeFace = false; | |
| 1901 | ✗ | if (faceIdsToRemove.find(getId(faces[i])) != faceIdsToRemove.end()) { | |
| 1902 | ✗ | removeFace = true; | |
| 1903 | ✗ | indicesToRemove.push_back(i); | |
| 1904 | } | ||
| 1905 | ✗ | if (checkKeyAndType(faces[i], "edge_ids", Json::arrayValue)) { | |
| 1906 | ✗ | Json::Value& edgeIds = faces[i]["edge_ids"]; | |
| 1907 | ✗ | Json::ArrayIndex n2 = edgeIds.size(); | |
| 1908 | ✗ | for (Json::ArrayIndex i2 = 0; i2 < n2; ++i2) { | |
| 1909 | ✗ | std::string edgeId = edgeIds[i2].asString(); | |
| 1910 | |||
| 1911 | ✗ | if (removeFace) { | |
| 1912 | ✗ | edgeIdsToRemove.insert(edgeId); | |
| 1913 | } | ||
| 1914 | |||
| 1915 | ✗ | if (edgeRefCount.find(edgeId) == edgeRefCount.end()) { | |
| 1916 | ✗ | edgeRefCount[edgeId] = 1; | |
| 1917 | } else { | ||
| 1918 | ✗ | edgeRefCount[edgeId] = edgeRefCount[edgeId] + 1; | |
| 1919 | } | ||
| 1920 | ✗ | } | |
| 1921 | } | ||
| 1922 | } | ||
| 1923 | ✗ | std::reverse(indicesToRemove.begin(), indicesToRemove.end()); | |
| 1924 | |||
| 1925 | // remove the faces | ||
| 1926 | ✗ | for (const auto& i : indicesToRemove) { | |
| 1927 | ✗ | Json::Value removed; | |
| 1928 | ✗ | faces.removeIndex(i, &removed); | |
| 1929 | ✗ | } | |
| 1930 | |||
| 1931 | // don't remove edges with ref count > 1 | ||
| 1932 | ✗ | for (const auto& pair : edgeRefCount) { | |
| 1933 | ✗ | if (pair.second > 1) { | |
| 1934 | ✗ | edgeIdsToRemove.erase(pair.first); | |
| 1935 | } | ||
| 1936 | } | ||
| 1937 | ✗ | removeEdges(value, edgeIdsToRemove); | |
| 1938 | ✗ | } | |
| 1939 | |||
| 1940 | ✗ | void FloorplanJS::removeEdges(Json::Value& value, const std::set<std::string>& edgeIdsToRemove) { | |
| 1941 | ✗ | if (!checkKeyAndType(value, "edges", Json::arrayValue)) { | |
| 1942 | ✗ | return; | |
| 1943 | } | ||
| 1944 | |||
| 1945 | ✗ | std::map<std::string, unsigned> vertexRefCount; | |
| 1946 | ✗ | std::set<std::string> vertexIdsToRemove; | |
| 1947 | |||
| 1948 | ✗ | std::vector<Json::ArrayIndex> indicesToRemove; | |
| 1949 | ✗ | Json::Value& edges = value["edges"]; | |
| 1950 | ✗ | Json::ArrayIndex n = edges.size(); | |
| 1951 | ✗ | for (Json::ArrayIndex i = 0; i < n; ++i) { | |
| 1952 | ✗ | bool removeEdge = false; | |
| 1953 | ✗ | if (edgeIdsToRemove.find(getId(edges[i])) != edgeIdsToRemove.end()) { | |
| 1954 | ✗ | removeEdge = true; | |
| 1955 | ✗ | indicesToRemove.push_back(i); | |
| 1956 | } | ||
| 1957 | ✗ | if (checkKeyAndType(edges[i], "vertex_ids", Json::arrayValue)) { | |
| 1958 | ✗ | Json::Value& vertexIds = edges[i]["vertex_ids"]; | |
| 1959 | ✗ | Json::ArrayIndex n2 = vertexIds.size(); | |
| 1960 | ✗ | for (Json::ArrayIndex i2 = 0; i2 < n2; ++i2) { | |
| 1961 | ✗ | std::string vertexId = vertexIds[i2].asString(); | |
| 1962 | |||
| 1963 | ✗ | if (removeEdge) { | |
| 1964 | ✗ | vertexIdsToRemove.insert(vertexId); | |
| 1965 | } | ||
| 1966 | |||
| 1967 | ✗ | if (vertexRefCount.find(vertexId) == vertexRefCount.end()) { | |
| 1968 | ✗ | vertexRefCount[vertexId] = 1; | |
| 1969 | } else { | ||
| 1970 | ✗ | vertexRefCount[vertexId] = vertexRefCount[vertexId] + 1; | |
| 1971 | } | ||
| 1972 | ✗ | } | |
| 1973 | } | ||
| 1974 | } | ||
| 1975 | ✗ | std::reverse(indicesToRemove.begin(), indicesToRemove.end()); | |
| 1976 | |||
| 1977 | // remove the edges | ||
| 1978 | ✗ | for (const auto& i : indicesToRemove) { | |
| 1979 | ✗ | Json::Value removed; | |
| 1980 | ✗ | edges.removeIndex(i, &removed); | |
| 1981 | ✗ | } | |
| 1982 | |||
| 1983 | // don't remove vertices with ref count > 1 | ||
| 1984 | ✗ | for (const auto& pair : vertexRefCount) { | |
| 1985 | ✗ | if (pair.second > 2) { | |
| 1986 | ✗ | vertexIdsToRemove.erase(pair.first); | |
| 1987 | } | ||
| 1988 | } | ||
| 1989 | ✗ | removeVertices(value, vertexIdsToRemove); | |
| 1990 | ✗ | } | |
| 1991 | |||
| 1992 | // cppcheck-suppress functionConst | ||
| 1993 | ✗ | void FloorplanJS::removeVertices(Json::Value& value, const std::set<std::string>& vertexIdsToRemove) { | |
| 1994 | ✗ | if (!checkKeyAndType(value, "vertices", Json::arrayValue)) { | |
| 1995 | ✗ | return; | |
| 1996 | } | ||
| 1997 | |||
| 1998 | ✗ | std::vector<Json::ArrayIndex> indicesToRemove; | |
| 1999 | ✗ | Json::Value& vertices = value["vertices"]; | |
| 2000 | ✗ | Json::ArrayIndex n = vertices.size(); | |
| 2001 | ✗ | for (Json::ArrayIndex i = 0; i < n; ++i) { | |
| 2002 | ✗ | if (vertexIdsToRemove.find(getId(vertices[i])) != vertexIdsToRemove.end()) { | |
| 2003 | ✗ | indicesToRemove.push_back(i); | |
| 2004 | } | ||
| 2005 | } | ||
| 2006 | ✗ | std::reverse(indicesToRemove.begin(), indicesToRemove.end()); | |
| 2007 | |||
| 2008 | // remove the vertices | ||
| 2009 | ✗ | for (const auto& i : indicesToRemove) { | |
| 2010 | ✗ | Json::Value removed; | |
| 2011 | ✗ | vertices.removeIndex(i, &removed); | |
| 2012 | ✗ | } | |
| 2013 | ✗ | } | |
| 2014 | |||
| 2015 | ✗ | std::string floorplanToThreeJS(const std::string& json, bool openstudioFormat) { | |
| 2016 | ✗ | boost::optional<FloorplanJS> floorplan = FloorplanJS::load(json); | |
| 2017 | ✗ | if (floorplan) { | |
| 2018 | ✗ | ThreeScene scene = floorplan->toThreeScene(openstudioFormat); | |
| 2019 | ✗ | return scene.toJSON(false); | |
| 2020 | ✗ | } | |
| 2021 | |||
| 2022 | ✗ | return "{}"; | |
| 2023 | ✗ | } | |
| 2024 | |||
| 2025 | } // namespace openstudio | ||
| 2026 |