src/gltf/GltfModelObjectMetaData.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 "GltfModelObjectMetaData.hpp" | ||
| 7 | |||
| 8 | #include "../model/AirLoopHVAC.hpp" | ||
| 9 | #include "../model/BuildingUnit.hpp" | ||
| 10 | #include "../model/SpaceType.hpp" | ||
| 11 | #include "../model/BuildingStory.hpp" | ||
| 12 | #include "../model/ThermalZone.hpp" | ||
| 13 | #include "../model/DefaultConstructionSet.hpp" | ||
| 14 | #include "../model/Space.hpp" | ||
| 15 | #include "../model/RenderingColor.hpp" | ||
| 16 | |||
| 17 | #include "../utilities/core/UUID.hpp" | ||
| 18 | |||
| 19 | #include <tiny_gltf.h> | ||
| 20 | |||
| 21 | #include <string> | ||
| 22 | #include <map> | ||
| 23 | |||
| 24 | namespace openstudio { | ||
| 25 | namespace gltf { | ||
| 26 | |||
| 27 | ✗ | GltfModelObjectMetaData::GltfModelObjectMetaData() = default; | |
| 28 | |||
| 29 | 6 | GltfModelObjectMetaData::GltfModelObjectMetaData(const model::AirLoopHVAC& airLoopHVAC) | |
| 30 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | : m_handle(openstudio::removeBraces(airLoopHVAC.handle())), |
| 31 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | m_iddObjectType(model::AirLoopHVAC::iddObjectType().valueDescription()), |
| 32 |
1/1✓ Branch 2 taken 6 times.
|
12 | m_name(airLoopHVAC.nameString()) {} |
| 33 | |||
| 34 | ✗ | GltfModelObjectMetaData::GltfModelObjectMetaData(const model::BuildingUnit& buildingUnit) | |
| 35 | ✗ | : m_handle(openstudio::removeBraces(buildingUnit.handle())), | |
| 36 | ✗ | m_iddObjectType(model::BuildingUnit::iddObjectType().valueDescription()), | |
| 37 | ✗ | m_name(buildingUnit.nameString()) { | |
| 38 | |||
| 39 | ✗ | if (buildingUnit.renderingColor()) { | |
| 40 | ✗ | m_color = buildingUnit.renderingColor()->colorString(); | |
| 41 | } | ||
| 42 | ✗ | } | |
| 43 | |||
| 44 | 405 | GltfModelObjectMetaData::GltfModelObjectMetaData(const model::SpaceType& spaceType) | |
| 45 |
2/2✓ Branch 1 taken 405 times.
✓ Branch 4 taken 405 times.
|
405 | : m_handle(openstudio::removeBraces(spaceType.handle())), |
| 46 |
2/2✓ Branch 1 taken 405 times.
✓ Branch 4 taken 405 times.
|
405 | m_iddObjectType(model::SpaceType::iddObjectType().valueDescription()), |
| 47 |
1/1✓ Branch 2 taken 405 times.
|
810 | m_name(spaceType.nameString()) { |
| 48 | |||
| 49 |
2/3✓ Branch 1 taken 405 times.
✓ Branch 4 taken 405 times.
✗ Branch 5 not taken.
|
810 | if (spaceType.renderingColor()) { |
| 50 |
3/3✓ Branch 1 taken 405 times.
✓ Branch 4 taken 405 times.
✓ Branch 7 taken 405 times.
|
405 | m_color = spaceType.renderingColor()->colorString(); |
| 51 | } | ||
| 52 | 405 | } | |
| 53 | |||
| 54 | 85 | GltfModelObjectMetaData::GltfModelObjectMetaData(const model::BuildingStory& buildingStory) | |
| 55 |
2/2✓ Branch 1 taken 85 times.
✓ Branch 4 taken 85 times.
|
85 | : m_handle(openstudio::removeBraces(buildingStory.handle())), |
| 56 |
2/2✓ Branch 1 taken 85 times.
✓ Branch 4 taken 85 times.
|
85 | m_iddObjectType(model::BuildingStory::iddObjectType().valueDescription()), |
| 57 |
1/1✓ Branch 2 taken 85 times.
|
170 | m_name(buildingStory.nameString()) { |
| 58 | |||
| 59 |
2/3✓ Branch 1 taken 85 times.
✓ Branch 4 taken 85 times.
✗ Branch 5 not taken.
|
170 | if (buildingStory.renderingColor()) { |
| 60 |
3/3✓ Branch 1 taken 85 times.
✓ Branch 4 taken 85 times.
✓ Branch 7 taken 85 times.
|
85 | m_color = buildingStory.renderingColor()->colorString(); |
| 61 | } | ||
| 62 |
2/3✓ Branch 1 taken 85 times.
✓ Branch 3 taken 85 times.
✗ Branch 4 not taken.
|
170 | if (buildingStory.nominalZCoordinate()) { |
| 63 |
2/2✓ Branch 1 taken 85 times.
✓ Branch 4 taken 85 times.
|
85 | m_nominalZCoordinate = buildingStory.nominalZCoordinate().get(); |
| 64 | } | ||
| 65 | // TBD: Do we have to include this ? | ||
| 66 |
3/3✓ Branch 1 taken 85 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 79 times.
|
170 | if (buildingStory.nominalFloortoCeilingHeight()) { |
| 67 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
|
6 | m_nominalFloortoCeilingHeight = buildingStory.nominalFloortoCeilingHeight().get(); |
| 68 | } | ||
| 69 | |||
| 70 | // TODO: How to calculate this ? | ||
| 71 | 85 | m_opentoBelow = false; | |
| 72 | |||
| 73 |
1/1✓ Branch 1 taken 85 times.
|
170 | if (buildingStory.nominalFloortoFloorHeight()) { |
| 74 | // TODO: DLM how to translate this? | ||
| 75 | } | ||
| 76 | 85 | } | |
| 77 | |||
| 78 | 795 | GltfModelObjectMetaData::GltfModelObjectMetaData(const model::ThermalZone& thermalZone) | |
| 79 |
2/2✓ Branch 1 taken 795 times.
✓ Branch 4 taken 795 times.
|
795 | : m_handle(openstudio::removeBraces(thermalZone.handle())), |
| 80 |
2/2✓ Branch 1 taken 795 times.
✓ Branch 4 taken 795 times.
|
795 | m_iddObjectType(model::ThermalZone::iddObjectType().valueDescription()), |
| 81 |
1/1✓ Branch 2 taken 795 times.
|
1590 | m_name(thermalZone.nameString()) { |
| 82 | |||
| 83 |
2/3✓ Branch 1 taken 795 times.
✓ Branch 4 taken 795 times.
✗ Branch 5 not taken.
|
1590 | if (thermalZone.renderingColor()) { |
| 84 |
3/3✓ Branch 1 taken 795 times.
✓ Branch 4 taken 795 times.
✓ Branch 7 taken 795 times.
|
795 | m_color = thermalZone.renderingColor()->colorString(); |
| 85 | } | ||
| 86 | |||
| 87 | // TODO: How to calculate this ? | ||
| 88 | 795 | m_opentoBelow = false; | |
| 89 | |||
| 90 |
1/1✓ Branch 1 taken 795 times.
|
795 | m_multiplier = thermalZone.multiplier(); |
| 91 | 795 | } | |
| 92 | 22 | GltfModelObjectMetaData::GltfModelObjectMetaData(const model::DefaultConstructionSet& defaultConstructionSet) | |
| 93 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
22 | : m_handle(openstudio::removeBraces(defaultConstructionSet.handle())), |
| 94 |
2/2✓ Branch 1 taken 22 times.
✓ Branch 4 taken 22 times.
|
22 | m_iddObjectType(model::DefaultConstructionSet::iddObjectType().valueDescription()), |
| 95 |
1/1✓ Branch 2 taken 22 times.
|
44 | m_name(defaultConstructionSet.nameString()) {} |
| 96 | |||
| 97 | 757 | GltfModelObjectMetaData::GltfModelObjectMetaData(const model::Space& space) | |
| 98 |
2/2✓ Branch 1 taken 757 times.
✓ Branch 4 taken 757 times.
|
757 | : m_handle(openstudio::removeBraces(space.handle())), |
| 99 |
2/2✓ Branch 1 taken 757 times.
✓ Branch 4 taken 757 times.
|
757 | m_iddObjectType(model::Space::iddObjectType().valueDescription()), |
| 100 |
1/1✓ Branch 2 taken 757 times.
|
1514 | m_name(space.nameString()) { |
| 101 | |||
| 102 | // TODO: the original implementation doesn't use the space multiplier (well: it does come from the attached thermal Zone so...) | ||
| 103 | 757 | } | |
| 104 | |||
| 105 | ✗ | std::string GltfModelObjectMetaData::color() const { | |
| 106 | ✗ | return m_color; | |
| 107 | } | ||
| 108 | ✗ | void GltfModelObjectMetaData::setColor(const std::string& color) { | |
| 109 | ✗ | m_color = color; | |
| 110 | ✗ | }; | |
| 111 | |||
| 112 | ✗ | std::string GltfModelObjectMetaData::handle() const { | |
| 113 | ✗ | return m_handle; | |
| 114 | } | ||
| 115 | ✗ | void GltfModelObjectMetaData::setHandle(const std::string& handle) { | |
| 116 | ✗ | m_handle = handle; | |
| 117 | ✗ | }; | |
| 118 | |||
| 119 | 9 | std::string GltfModelObjectMetaData::iddObjectType() const { | |
| 120 | 9 | return m_iddObjectType; | |
| 121 | } | ||
| 122 | ✗ | void GltfModelObjectMetaData::setIddObjectType(const std::string& iddObjectType) { | |
| 123 | ✗ | m_iddObjectType = iddObjectType; | |
| 124 | ✗ | }; | |
| 125 | |||
| 126 | 2 | std::string GltfModelObjectMetaData::name() const { | |
| 127 | 2 | return m_name; | |
| 128 | } | ||
| 129 | ✗ | void GltfModelObjectMetaData::setName(const std::string& name) { | |
| 130 | ✗ | m_name = name; | |
| 131 | ✗ | }; | |
| 132 | |||
| 133 | ✗ | bool GltfModelObjectMetaData::isOpentoBelow() const { | |
| 134 | ✗ | return m_opentoBelow; | |
| 135 | } | ||
| 136 | ✗ | void GltfModelObjectMetaData::setOpentoBelow(bool opentoBelow) { | |
| 137 | ✗ | m_opentoBelow = opentoBelow; | |
| 138 | ✗ | }; | |
| 139 | |||
| 140 | ✗ | double GltfModelObjectMetaData::nominalZCoordinate() const { | |
| 141 | ✗ | return m_nominalZCoordinate; | |
| 142 | } | ||
| 143 | ✗ | void GltfModelObjectMetaData::setNominalZCoordinate(double nominalZCoordinate) { | |
| 144 | ✗ | m_nominalZCoordinate = nominalZCoordinate; | |
| 145 | ✗ | }; | |
| 146 | |||
| 147 | ✗ | double GltfModelObjectMetaData::nominalFloortoCeilingHeight() const { | |
| 148 | ✗ | return m_nominalFloortoCeilingHeight; | |
| 149 | } | ||
| 150 | ✗ | void GltfModelObjectMetaData::setNominalFloortoCeilingHeight(double nominalFloortoCeilingHeight) { | |
| 151 | ✗ | m_nominalFloortoCeilingHeight = nominalFloortoCeilingHeight; | |
| 152 | ✗ | }; | |
| 153 | |||
| 154 | ✗ | int GltfModelObjectMetaData::multiplier() const { | |
| 155 | ✗ | return m_multiplier; | |
| 156 | } | ||
| 157 | ✗ | void GltfModelObjectMetaData::setMultiplier(int multiplier) { | |
| 158 | ✗ | m_multiplier = multiplier; | |
| 159 | ✗ | }; | |
| 160 | |||
| 161 | 2070 | std::map<std::string, tinygltf::Value> GltfModelObjectMetaData::toExtras() const { | |
| 162 | return { | ||
| 163 | ✗ | {"color", tinygltf::Value(m_color)}, | |
| 164 | 2070 | {"handle", tinygltf::Value(m_handle)}, | |
| 165 | 2070 | {"iddObjectType", tinygltf::Value(m_iddObjectType)}, | |
| 166 | 2070 | {"name", tinygltf::Value(m_name)}, | |
| 167 | 2070 | {"open_to_below", tinygltf::Value(m_opentoBelow)}, | |
| 168 | 2070 | {"nominal_z_coordinate", tinygltf::Value(m_nominalZCoordinate)}, | |
| 169 | 2070 | {"nominal_floorCeiling_Height", tinygltf::Value(m_nominalFloortoCeilingHeight)}, | |
| 170 | 2070 | {"multiplier", tinygltf::Value(m_multiplier)}, | |
| 171 |
3/5✓ Branch 1 taken 2070 times.
✓ Branch 3 taken 16560 times.
✓ Branch 4 taken 2070 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
22770 | }; |
| 172 | 2070 | } | |
| 173 | |||
| 174 | 9 | GltfModelObjectMetaData::GltfModelObjectMetaData(const tinygltf::Value& modelObjectMetaDataObj) { | |
| 175 | |||
| 176 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
18 | if (modelObjectMetaDataObj.Has("color")) { |
| 177 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | auto val = modelObjectMetaDataObj.Get("color"); |
| 178 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | if (val.IsString()) { |
| 179 |
1/1✓ Branch 2 taken 9 times.
|
9 | m_color = val.Get<std::string>(); |
| 180 | } else { | ||
| 181 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'color' but it is not a std::string"); | |
| 182 | } | ||
| 183 | 9 | } else { | |
| 184 | ✗ | LOG(Debug, "modelObjectMetaDataObj is missing the key 'color'"); | |
| 185 | } | ||
| 186 | |||
| 187 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
18 | if (modelObjectMetaDataObj.Has("handle")) { |
| 188 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | auto val = modelObjectMetaDataObj.Get("handle"); |
| 189 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | if (val.IsString()) { |
| 190 |
1/1✓ Branch 2 taken 9 times.
|
9 | m_handle = val.Get<std::string>(); |
| 191 | } else { | ||
| 192 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'handle' but it is not a std::string"); | |
| 193 | } | ||
| 194 | 9 | } else { | |
| 195 | ✗ | LOG(Debug, "modelObjectMetaDataObj is missing the key 'handle'"); | |
| 196 | } | ||
| 197 | |||
| 198 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
18 | if (modelObjectMetaDataObj.Has("iddObjectType")) { |
| 199 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | auto val = modelObjectMetaDataObj.Get("iddObjectType"); |
| 200 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | if (val.IsString()) { |
| 201 |
1/1✓ Branch 2 taken 9 times.
|
9 | m_iddObjectType = val.Get<std::string>(); |
| 202 | } else { | ||
| 203 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'iddObjectType' but it is not a std::string"); | |
| 204 | } | ||
| 205 | 9 | } else { | |
| 206 | ✗ | LOG(Debug, "modelObjectMetaDataObj is missing the key 'iddObjectType'"); | |
| 207 | } | ||
| 208 | |||
| 209 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
18 | if (modelObjectMetaDataObj.Has("name")) { |
| 210 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | auto val = modelObjectMetaDataObj.Get("name"); |
| 211 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | if (val.IsString()) { |
| 212 |
1/1✓ Branch 2 taken 9 times.
|
9 | m_name = val.Get<std::string>(); |
| 213 | } else { | ||
| 214 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'name' but it is not a std::string"); | |
| 215 | } | ||
| 216 | 9 | } else { | |
| 217 | ✗ | LOG(Debug, "modelObjectMetaDataObj is missing the key 'name'"); | |
| 218 | } | ||
| 219 | |||
| 220 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
|
18 | if (modelObjectMetaDataObj.Has("opentoBelow")) { |
| 221 | ✗ | auto val = modelObjectMetaDataObj.Get("opentoBelow"); | |
| 222 | ✗ | if (val.IsBool()) { | |
| 223 | ✗ | m_opentoBelow = val.Get<bool>(); | |
| 224 | } else { | ||
| 225 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'opentoBelow' but it is not a bool"); | |
| 226 | } | ||
| 227 | ✗ | } else { | |
| 228 |
5/5✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
|
9 | LOG(Debug, "modelObjectMetaDataObj is missing the key 'opentoBelow'"); |
| 229 | } | ||
| 230 | |||
| 231 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
|
18 | if (modelObjectMetaDataObj.Has("nominalZCoordinate")) { |
| 232 | ✗ | auto val = modelObjectMetaDataObj.Get("nominalZCoordinate"); | |
| 233 | ✗ | if (val.IsReal()) { | |
| 234 | ✗ | m_nominalZCoordinate = val.Get<double>(); | |
| 235 | } else { | ||
| 236 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'nominalZCoordinate' but it is not a double"); | |
| 237 | } | ||
| 238 | ✗ | } else { | |
| 239 |
5/5✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
|
9 | LOG(Debug, "modelObjectMetaDataObj is missing the key 'nominalZCoordinate'"); |
| 240 | } | ||
| 241 | |||
| 242 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 9 times.
|
18 | if (modelObjectMetaDataObj.Has("nominalFloortoCeilingHeight")) { |
| 243 | ✗ | auto val = modelObjectMetaDataObj.Get("nominalFloortoCeilingHeight"); | |
| 244 | ✗ | if (val.IsReal()) { | |
| 245 | ✗ | m_nominalFloortoCeilingHeight = val.Get<double>(); | |
| 246 | } else { | ||
| 247 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'nominalFloortoCeilingHeight' but it is not a double"); | |
| 248 | } | ||
| 249 | ✗ | } else { | |
| 250 |
5/5✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
✓ Branch 13 taken 9 times.
|
9 | LOG(Debug, "modelObjectMetaDataObj is missing the key 'nominalFloortoCeilingHeight'"); |
| 251 | } | ||
| 252 | |||
| 253 |
3/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✗ Branch 8 not taken.
|
18 | if (modelObjectMetaDataObj.Has("multiplier")) { |
| 254 |
3/3✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
|
9 | auto val = modelObjectMetaDataObj.Get("multiplier"); |
| 255 |
1/2✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
|
9 | if (val.IsInt()) { |
| 256 | 9 | m_multiplier = val.Get<int>(); | |
| 257 | } else { | ||
| 258 | ✗ | LOG(Warn, "modelObjectMetaDataObj has the key 'multiplier' but it is not a int"); | |
| 259 | } | ||
| 260 | 9 | } else { | |
| 261 | ✗ | LOG(Debug, "modelObjectMetaDataObj is missing the key 'multiplier'"); | |
| 262 | } | ||
| 263 | 9 | } | |
| 264 | |||
| 265 | } // namespace gltf | ||
| 266 | } // namespace openstudio | ||
| 267 |