GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 85.0% 68 / 0 / 80
Functions: 33.3% 2 / 0 / 6
Branches: 89.0% 121 / 0 / 136

src/model/FloorplanJSForwardTranslator.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 "FloorplanJSForwardTranslator.hpp"
7
8 #include "RenderingColor.hpp"
9 #include "ConstructionBase.hpp"
10 #include "ConstructionBase_Impl.hpp"
11 #include "ThermalZone.hpp"
12 #include "ThermalZone_Impl.hpp"
13 #include "SpaceType.hpp"
14 #include "SpaceType_Impl.hpp"
15 #include "BuildingStory.hpp"
16 #include "BuildingStory_Impl.hpp"
17 #include "BuildingUnit.hpp"
18 #include "BuildingUnit_Impl.hpp"
19 #include "Surface.hpp"
20 #include "Surface_Impl.hpp"
21 #include "SubSurface.hpp"
22 #include "SubSurface_Impl.hpp"
23 #include "ShadingSurface.hpp"
24 #include "ShadingSurface_Impl.hpp"
25 #include "InteriorPartitionSurface.hpp"
26 #include "InteriorPartitionSurface_Impl.hpp"
27 #include "PlanarSurfaceGroup.hpp"
28 #include "PlanarSurfaceGroup_Impl.hpp"
29 #include "Space.hpp"
30 #include "Space_Impl.hpp"
31 #include "DefaultConstructionSet.hpp"
32 #include "DefaultConstructionSet_Impl.hpp"
33 #include "ShadingSurfaceGroup.hpp"
34 #include "InteriorPartitionSurfaceGroup.hpp"
35
36 #include "../utilities/core/Assert.hpp"
37 #include "../utilities/core/Compare.hpp"
38 #include "../utilities/geometry/Point3d.hpp"
39 #include "../utilities/geometry/Plane.hpp"
40 #include "../utilities/geometry/BoundingBox.hpp"
41 #include "../utilities/geometry/Transformation.hpp"
42 #include "../utilities/geometry/Geometry.hpp"
43
44 #include <thread>
45
46 #include <cmath>
47
48 namespace openstudio {
49 namespace model {
50
51 3 FloorplanJSForwardTranslator::FloorplanJSForwardTranslator() {
52
1/1
✓ Branch 1 taken 3 times.
3 m_logSink.setLogLevel(Warn);
53 //m_logSink.setChannelRegex(boost::regex("openstudio\\.model\\.FloorplanJSForwardTranslator"));
54
1/1
✓ Branch 2 taken 3 times.
3 m_logSink.setThreadId(std::this_thread::get_id());
55 3 }
56
57 ✗ std::vector<LogMessage> FloorplanJSForwardTranslator::warnings() const {
58 ✗ std::vector<LogMessage> result = m_logSink.logMessages();
59 ✗ result.erase(std::remove_if(result.begin(), result.end(), [](const auto& logMessage) { return logMessage.logLevel() != Warn; }), result.end());
60 ✗ return result;
61 ✗ }
62
63 ✗ std::vector<LogMessage> FloorplanJSForwardTranslator::errors() const {
64 ✗ std::vector<LogMessage> result = m_logSink.logMessages();
65 ✗ result.erase(std::remove_if(result.begin(), result.end(), [](const auto& logMessage) { return logMessage.logLevel() <= Warn; }), result.end());
66 ✗ return result;
67 ✗ }
68
69 5 FloorplanJS FloorplanJSForwardTranslator::updateFloorplanJS(const FloorplanJS& floorplan, const Model& model, bool removeMissingObjects) {
70
1/1
✓ Branch 2 taken 5 times.
5 m_logSink.setThreadId(std::this_thread::get_id());
71
1/1
✓ Branch 1 taken 5 times.
5 m_logSink.resetStringStream();
72
73
2/2
✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
5 FloorplanJS result(floorplan.toJSON());
74
75 // first have to update all the names
76
77 // update resources first since these will have references to them
78 5 std::vector<FloorplanObject> unitObjects;
79
3/3
✓ Branch 1 taken 5 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 5 times.
7 for (const auto& unit : model.getConcreteModelObjects<BuildingUnit>()) {
80
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 FloorplanObject unitObject("", unit.nameString(), unit.handle());
81
1/1
✓ Branch 1 taken 2 times.
2 unitObjects.push_back(unitObject);
82 7 }
83
1/1
✓ Branch 1 taken 5 times.
5 result.updateBuildingUnits(unitObjects, removeMissingObjects);
84
85 5 std::vector<FloorplanObject> zoneObjects;
86
3/3
✓ Branch 1 taken 5 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 5 times.
7 for (const auto& zone : model.getConcreteModelObjects<ThermalZone>()) {
87
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 FloorplanObject zoneObject("", zone.nameString(), zone.handle());
88
89
1/1
✓ Branch 1 taken 2 times.
2 boost::optional<RenderingColor> color = zone.renderingColor();
90
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (color) {
91 ✗ zoneObject.setDataString("color", color->colorString());
92 }
93
94
1/1
✓ Branch 1 taken 2 times.
2 zoneObjects.push_back(zoneObject);
95 7 }
96
1/1
✓ Branch 1 taken 5 times.
5 result.updateThermalZones(zoneObjects, removeMissingObjects);
97
98 5 std::vector<FloorplanObject> spaceTypeObjects;
99
3/3
✓ Branch 1 taken 5 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 5 times.
9 for (const auto& spaceType : model.getConcreteModelObjects<SpaceType>()) {
100
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
12 FloorplanObject spaceTypeObject("", spaceType.nameString(), spaceType.handle());
101
102
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<RenderingColor> color = spaceType.renderingColor();
103
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (color) {
104
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 spaceTypeObject.setDataString("color", color->colorString());
105 }
106
107
1/1
✓ Branch 1 taken 4 times.
4 spaceTypeObjects.push_back(spaceTypeObject);
108 9 }
109
1/1
✓ Branch 1 taken 5 times.
5 result.updateSpaceTypes(spaceTypeObjects, removeMissingObjects);
110
111 5 std::vector<FloorplanObject> setObjects;
112
3/3
✓ Branch 1 taken 5 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 5 times.
7 for (const auto& set : model.getConcreteModelObjects<DefaultConstructionSet>()) {
113
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
6 FloorplanObject setObject("", set.nameString(), set.handle());
114
115 //boost::optional<RenderingColor> color = set.renderingColor();
116 //if (color){
117 // setObject.setDataString("color", color->colorString());
118 //}
119
120
1/1
✓ Branch 1 taken 2 times.
2 setObjects.push_back(setObject);
121 7 }
122
1/1
✓ Branch 1 taken 5 times.
5 result.updateConstructionSets(setObjects, removeMissingObjects);
123
124 // do stories and spaces after resources
125 5 std::vector<FloorplanObject> storyObjects;
126
3/3
✓ Branch 1 taken 5 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 5 times.
9 for (const auto& story : model.getConcreteModelObjects<BuildingStory>()) {
127
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
12 FloorplanObject storyObject("", story.nameString(), story.handle());
128
129
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<RenderingColor> color = story.renderingColor();
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (color) {
131 ✗ storyObject.setDataString("color", color->colorString());
132 }
133
134 // DLM: TODO "below_floor_plenum_height","floor_to_ceiling_height","above_ceiling_plenum_height","multiplier"
135
136
1/1
✓ Branch 1 taken 4 times.
4 storyObjects.push_back(storyObject);
137 9 }
138
1/1
✓ Branch 1 taken 5 times.
5 result.updateStories(storyObjects, removeMissingObjects);
139
140 5 std::vector<FloorplanObject> spaceObjects;
141
3/3
✓ Branch 1 taken 5 times.
✓ Branch 8 taken 4 times.
✓ Branch 9 taken 5 times.
9 for (const auto& space : model.getConcreteModelObjects<Space>()) {
142
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
12 FloorplanObject spaceObject("", space.nameString(), space.handle());
143
144 // DLM: Should we even continue if the story is empty?
145
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<BuildingStory> story = space.buildingStory();
146
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (story) {
147
4/4
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
✓ Branch 10 taken 4 times.
4 spaceObject.setParentHandleString(toString(story->handle()));
148 }
149
150
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<BuildingUnit> unit = space.buildingUnit();
151
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
4 if (unit) {
152
8/8
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
5 spaceObject.setDataReference("building_unit_id", FloorplanObject("", unit->nameString(), unit->handle()));
153 }
154
155
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<ThermalZone> zone = space.thermalZone();
156
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
4 if (zone) {
157
8/8
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
5 spaceObject.setDataReference("thermal_zone_id", FloorplanObject("", zone->nameString(), zone->handle()));
158 }
159
160
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<SpaceType> spaceType = space.spaceType();
161
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
4 if (spaceType) {
162
8/8
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
5 spaceObject.setDataReference("space_type_id", FloorplanObject("", spaceType->nameString(), spaceType->handle()));
163 }
164
165
1/1
✓ Branch 1 taken 4 times.
4 boost::optional<DefaultConstructionSet> set = space.defaultConstructionSet();
166
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
4 if (set) {
167
8/8
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 16 taken 1 time.
✓ Branch 19 taken 1 time.
✓ Branch 22 taken 1 time.
5 spaceObject.setDataReference("construction_set_id", FloorplanObject("", set->nameString(), set->handle()));
168 }
169
170
1/1
✓ Branch 1 taken 4 times.
4 spaceObjects.push_back(spaceObject);
171 9 }
172
1/1
✓ Branch 1 taken 5 times.
5 result.updateSpaces(spaceObjects, removeMissingObjects);
173
174 10 return result;
175 5 }
176
177 } // namespace model
178 } // namespace openstudio
179