GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 74.8% 450 / 0 / 602
Functions: 81.8% 18 / 0 / 22
Branches: 62.3% 590 / 0 / 947

src/model/ModelMerger.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 "ModelMerger.hpp"
7
8 #include "RenderingColor.hpp"
9 #include "ConstructionBase.hpp"
10 #include "ConstructionBase_Impl.hpp"
11 #include "Site.hpp"
12 #include "Site_Impl.hpp"
13 #include "Facility.hpp"
14 #include "Facility_Impl.hpp"
15 #include "Building.hpp"
16 #include "Building_Impl.hpp"
17 #include "ThermalZone.hpp"
18 #include "ThermalZone_Impl.hpp"
19 #include "SpaceType.hpp"
20 #include "SpaceType_Impl.hpp"
21 #include "BuildingStory.hpp"
22 #include "BuildingStory_Impl.hpp"
23 #include "BuildingUnit.hpp"
24 #include "BuildingUnit_Impl.hpp"
25 #include "Surface.hpp"
26 #include "Surface_Impl.hpp"
27 #include "SubSurface.hpp"
28 #include "SubSurface_Impl.hpp"
29 #include "ShadingSurface.hpp"
30 #include "ShadingSurface_Impl.hpp"
31 #include "InteriorPartitionSurface.hpp"
32 #include "InteriorPartitionSurface_Impl.hpp"
33 #include "PlanarSurfaceGroup.hpp"
34 #include "PlanarSurfaceGroup_Impl.hpp"
35 #include "ShadingSurfaceGroup.hpp"
36 #include "ShadingSurfaceGroup_Impl.hpp"
37 #include "Space.hpp"
38 #include "Space_Impl.hpp"
39 #include "DefaultConstructionSet.hpp"
40 #include "DefaultConstructionSet_Impl.hpp"
41 #include "DefaultScheduleSet.hpp"
42 #include "DefaultScheduleSet_Impl.hpp"
43 #include "InteriorPartitionSurfaceGroup.hpp"
44 #include "DaylightingControl.hpp"
45 #include "DaylightingControl_Impl.hpp"
46 #include "AdditionalProperties.hpp"
47
48 #include "../utilities/core/Assert.hpp"
49 #include "../utilities/core/Compare.hpp"
50 #include "../utilities/geometry/Point3d.hpp"
51 #include "../utilities/geometry/Plane.hpp"
52 #include "../utilities/geometry/BoundingBox.hpp"
53 #include "../utilities/geometry/Transformation.hpp"
54 #include "../utilities/geometry/Geometry.hpp"
55
56 #include <utilities/idd/IddFactory.hxx>
57
58 #include <thread>
59
60 #include <cmath>
61 #include <tuple>
62
63 namespace openstudio {
64 namespace model {
65
66
2/2
✓ Branch 2 taken 21 times.
✓ Branch 5 taken 21 times.
21 ModelMerger::ModelMerger() {
67 // DLM: TODO expose this to user to give more control over merging?
68
69 // Unique Objects
70
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_Site);
71
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_Facility);
72
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_Building);
73
74 // Non unique Objects
75
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_Space);
76
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_ShadingSurfaceGroup);
77
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_ThermalZone);
78
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_SpaceType);
79
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_BuildingStory);
80
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_BuildingUnit);
81
2/2
✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
21 m_iddObjectTypesToMerge.push_back(IddObjectType::OS_DefaultConstructionSet);
82
83
1/1
✓ Branch 1 taken 21 times.
21 m_logSink.setLogLevel(Warn);
84 //m_logSink.setChannelRegex(boost::regex("openstudio\\.model\\.ThreeJSReverseTranslator"));
85
1/1
✓ Branch 2 taken 21 times.
21 m_logSink.setThreadId(std::this_thread::get_id());
86 21 }
87
88 4 std::map<UUID, UUID> ModelMerger::suggestHandleMapping(const Model& currentModel, const Model& newModel) const {
89 4 std::map<UUID, UUID> result;
90
91 using HandleSet = std::set<UUID>;
92 using StringHandleMap = std::map<std::string, UUID>;
93 using ObjectLookup = std::tuple<HandleSet, StringHandleMap, StringHandleMap>; // 0 - handle, 1 - CADObjectId, 2 - Name
94 using IddToObjectLookupMap = std::map<IddObjectType, ObjectLookup>;
95
96 4 IddToObjectLookupMap currentIddToObjectLookupMap;
97
2/2
✓ Branch 5 taken 40 times.
✓ Branch 6 taken 4 times.
44 for (const auto& iddObjectType : m_iddObjectTypesToMerge) {
98 40 ObjectLookup currentLookup;
99
3/3
✓ Branch 1 taken 40 times.
✓ Branch 8 taken 58 times.
✓ Branch 9 taken 40 times.
98 for (const auto& object : currentModel.getObjectsByType(iddObjectType)) {
100
1/1
✓ Branch 1 taken 58 times.
58 Handle handle = object.handle();
101
1/1
✓ Branch 2 taken 58 times.
58 std::get<0>(currentLookup).insert(handle);
102
103
1/1
✓ Branch 1 taken 58 times.
58 auto modelObject = object.cast<ModelObject>();
104
3/3
✓ Branch 1 taken 58 times.
✓ Branch 3 taken 25 times.
✓ Branch 4 taken 33 times.
58 if (modelObject.hasAdditionalProperties()) {
105
1/1
✓ Branch 1 taken 25 times.
25 model::AdditionalProperties additionalProperties = modelObject.additionalProperties();
106
4/4
✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
✓ Branch 7 taken 12 times.
✓ Branch 8 taken 13 times.
50 if (additionalProperties.hasFeature("CADObjectId")) {
107
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
24 boost::optional<std::string> cadObjectId = additionalProperties.getFeatureAsString("CADObjectId");
108
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (cadObjectId) {
109
3/3
✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
✓ Branch 8 taken 12 times.
12 std::get<1>(currentLookup).insert(std::make_pair(*cadObjectId, handle));
110 }
111 12 }
112 25 }
113
114
2/2
✓ Branch 2 taken 58 times.
✓ Branch 6 taken 58 times.
58 std::get<2>(currentLookup).insert(std::make_pair(object.nameString(), handle));
115 98 }
116
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 currentIddToObjectLookupMap.insert(std::make_pair(iddObjectType, currentLookup));
117 40 }
118
119
2/2
✓ Branch 5 taken 40 times.
✓ Branch 6 taken 4 times.
44 for (const auto& iddObjectType : m_iddObjectTypesToMerge) {
120
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 ObjectLookup currentLookup = currentIddToObjectLookupMap[iddObjectType];
121
3/3
✓ Branch 1 taken 40 times.
✓ Branch 8 taken 62 times.
✓ Branch 9 taken 40 times.
102 for (const auto& object : newModel.getObjectsByType(iddObjectType)) {
122
1/1
✓ Branch 1 taken 62 times.
62 Handle handle = object.handle();
123
3/3
✓ Branch 2 taken 62 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 48 times.
62 if (std::get<0>(currentLookup).count(handle) > 0) {
124 // handle is in both models
125
1/1
✓ Branch 1 taken 14 times.
14 result[handle] = handle;
126 57 continue;
127 }
128
129
4/4
✓ Branch 1 taken 48 times.
✓ Branch 5 taken 46 times.
✓ Branch 8 taken 43 times.
✓ Branch 9 taken 3 times.
94 if ((iddObjectType == IddObjectType::OS_Site) || (iddObjectType == IddObjectType::OS_Facility)
130
7/7
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 2 times.
✓ Branch 3 taken 43 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 40 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 40 times.
94 || (iddObjectType == IddObjectType::OS_Building)) {
131 // this is a unique object
132
1/2
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 if (std::get<0>(currentLookup).size() == 1) {
133 8 Handle currentHandle = *(std::get<0>(currentLookup).begin());
134
1/1
✓ Branch 1 taken 8 times.
8 result[currentHandle] = handle;
135 8 continue;
136 8 }
137 }
138
139
1/1
✓ Branch 1 taken 40 times.
40 auto modelObject = object.cast<ModelObject>();
140
3/3
✓ Branch 1 taken 40 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 16 times.
40 if (modelObject.hasAdditionalProperties()) {
141
1/1
✓ Branch 1 taken 24 times.
24 model::AdditionalProperties additionalProperties = modelObject.additionalProperties();
142
4/4
✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
✓ Branch 7 taken 12 times.
✓ Branch 8 taken 12 times.
48 if (additionalProperties.hasFeature("CADObjectId")) {
143
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
24 boost::optional<std::string> cadObjectId = additionalProperties.getFeatureAsString("CADObjectId");
144
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (cadObjectId) {
145
3/4
✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
✓ Branch 7 taken 12 times.
✗ Branch 8 not taken.
12 if (std::get<1>(currentLookup).count(*cadObjectId) > 0) {
146 // cadObjectId is in both models
147
2/2
✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
12 Handle currentHandle = std::get<1>(currentLookup)[*cadObjectId];
148
1/1
✓ Branch 1 taken 12 times.
12 result[currentHandle] = handle;
149 12 continue;
150 12 }
151 }
152 12 }
153 24 }
154
155
4/4
✓ Branch 2 taken 28 times.
✓ Branch 5 taken 28 times.
✓ Branch 8 taken 23 times.
✓ Branch 9 taken 5 times.
28 if (std::get<2>(currentLookup).count(object.nameString()) > 0) {
156 // name is in both models
157
2/2
✓ Branch 2 taken 23 times.
✓ Branch 5 taken 23 times.
23 Handle currentHandle = std::get<2>(currentLookup)[object.nameString()];
158
1/1
✓ Branch 1 taken 23 times.
23 result[currentHandle] = handle;
159 23 continue;
160 23 }
161 80 }
162 40 }
163
164 8 return result;
165 4 }
166
167 4 std::vector<LogMessage> ModelMerger::warnings() const {
168 4 std::vector<LogMessage> result = m_logSink.logMessages();
169
2/2
✓ Branch 6 taken 4 times.
✓ Branch 10 taken 4 times.
4 result.erase(std::remove_if(result.begin(), result.end(), [](const auto& logMessage) { return logMessage.logLevel() != Warn; }), result.end());
170 4 return result;
171 ✗ }
172
173 4 std::vector<LogMessage> ModelMerger::errors() const {
174 4 std::vector<LogMessage> result = m_logSink.logMessages();
175
2/2
✓ Branch 6 taken 4 times.
✓ Branch 10 taken 4 times.
4 result.erase(std::remove_if(result.begin(), result.end(), [](const auto& logMessage) { return logMessage.logLevel() <= Warn; }), result.end());
176 4 return result;
177 ✗ }
178
179 ✗ boost::optional<UUID> ModelMerger::getNewModelHandle(const UUID& currentHandle) {
180 ✗ auto it = m_currentToNewHandleMapping.find(currentHandle);
181 ✗ if (it != m_currentToNewHandleMapping.end()) {
182 ✗ return it->second;
183 }
184 ✗ return boost::none;
185 }
186
187 492 boost::optional<UUID> ModelMerger::getCurrentModelHandle(const UUID& newHandle) {
188
1/1
✓ Branch 1 taken 492 times.
492 auto it = m_newToCurrentHandleMapping.find(newHandle);
189
2/2
✓ Branch 2 taken 249 times.
✓ Branch 3 taken 243 times.
492 if (it != m_newToCurrentHandleMapping.end()) {
190
1/1
✓ Branch 2 taken 249 times.
249 return it->second;
191 }
192 243 return boost::none;
193 }
194
195 11 void ModelMerger::mergeSite(Site& currentSite, const Site& newSite) {
196
3/4
✓ Branch 2 taken 11 times.
✓ Branch 5 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 11 times.
11 if (m_newMergedHandles.find(newSite.handle()) != m_newMergedHandles.end()) {
197 // already merged
198 ✗ return;
199 }
200
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 m_newMergedHandles.insert(newSite.handle());
201
202
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 currentSite.setName(newSite.nameString());
203
204
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9 times.
11 if (!newSite.isLatitudeDefaulted()) {
205 2 currentSite.setLatitude(newSite.latitude());
206 }
207
208
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9 times.
11 if (!newSite.isLongitudeDefaulted()) {
209 2 currentSite.setLongitude(newSite.longitude());
210 }
211
212
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (!newSite.isTimeZoneDefaulted()) {
213 ✗ currentSite.setTimeZone(newSite.timeZone());
214 }
215
216
2/2
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 9 times.
11 if (!newSite.isElevationDefaulted()) {
217 2 currentSite.setElevation(newSite.elevation());
218 }
219
220
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
11 if (!newSite.isTerrainDefaulted()) {
221 ✗ currentSite.setTerrain(newSite.terrain());
222 }
223 }
224
225 13 void ModelMerger::mergeFacility(Facility& currentFacility, const Facility& newFacility) {
226
3/4
✓ Branch 2 taken 13 times.
✓ Branch 5 taken 13 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 13 times.
13 if (m_newMergedHandles.find(newFacility.handle()) != m_newMergedHandles.end()) {
227 // already merged
228 ✗ return;
229 }
230
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 m_newMergedHandles.insert(newFacility.handle());
231
232
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 currentFacility.setName(newFacility.nameString());
233 }
234
235 13 void ModelMerger::mergeBuilding(Building& currentBuilding, const Building& newBuilding) {
236
3/4
✓ Branch 2 taken 13 times.
✓ Branch 5 taken 13 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 13 times.
13 if (m_newMergedHandles.find(newBuilding.handle()) != m_newMergedHandles.end()) {
237 // already merged
238 ✗ return;
239 }
240
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 m_newMergedHandles.insert(newBuilding.handle());
241
242
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 currentBuilding.setName(newBuilding.nameString());
243
244
2/2
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 2 times.
13 if (!newBuilding.isNorthAxisDefaulted()) {
245 11 currentBuilding.setNorthAxis(newBuilding.northAxis());
246 }
247
248
2/3
✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
26 if (newBuilding.nominalFloortoFloorHeight()) {
249 ✗ currentBuilding.setNominalFloortoFloorHeight(newBuilding.nominalFloortoFloorHeight().get());
250 }
251
252
2/3
✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
26 if (newBuilding.nominalFloortoCeilingHeight()) {
253 ✗ currentBuilding.setNominalFloortoCeilingHeight(newBuilding.nominalFloortoCeilingHeight().get());
254 }
255
256
2/3
✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
26 if (newBuilding.standardsNumberOfStories()) {
257 ✗ currentBuilding.setStandardsNumberOfStories(newBuilding.standardsNumberOfStories().get());
258 }
259
260
2/3
✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
26 if (newBuilding.standardsNumberOfAboveGroundStories()) {
261 ✗ currentBuilding.setStandardsNumberOfAboveGroundStories(newBuilding.standardsNumberOfAboveGroundStories().get());
262 }
263
264
2/3
✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
26 if (newBuilding.standardsNumberOfLivingUnits()) {
265 ✗ currentBuilding.setStandardsNumberOfLivingUnits(newBuilding.standardsNumberOfLivingUnits().get());
266 }
267
268
2/3
✓ Branch 1 taken 13 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
26 if (newBuilding.standardsTemplate()) {
269 ✗ currentBuilding.setStandardsTemplate(newBuilding.standardsTemplate().get());
270 }
271
272
2/3
✓ Branch 1 taken 13 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 13 times.
26 if (newBuilding.standardsBuildingType()) {
273 ✗ currentBuilding.setStandardsBuildingType(newBuilding.standardsBuildingType().get());
274 }
275
276
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
13 if (!newBuilding.isRelocatableDefaulted()) {
277 ✗ currentBuilding.setRelocatable(newBuilding.relocatable());
278 }
279
280 // default construction set
281
2/3
✓ Branch 1 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
26 if (boost::optional<DefaultConstructionSet> newDefaultConstructionSet = newBuilding.defaultConstructionSet()) {
282 ✗ boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newDefaultConstructionSet);
283 ✗ if (currentObject) {
284 ✗ auto currentDefaultConstructionSet = currentObject->cast<DefaultConstructionSet>();
285 ✗ currentBuilding.setDefaultConstructionSet(currentDefaultConstructionSet);
286 ✗ } else {
287 ✗ currentBuilding.resetDefaultConstructionSet();
288 }
289 ✗ } else {
290
1/1
✓ Branch 1 taken 13 times.
13 currentBuilding.resetDefaultConstructionSet();
291 13 }
292
293 // TODO: default schedule sets
294 }
295
296 56 void ModelMerger::mergeSpace(Space& currentSpace, const Space& newSpace) {
297
3/4
✓ Branch 2 taken 56 times.
✓ Branch 5 taken 56 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 56 times.
56 if (m_newMergedHandles.find(newSpace.handle()) != m_newMergedHandles.end()) {
298 // already merged
299 ✗ return;
300 }
301
2/2
✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
56 m_newMergedHandles.insert(newSpace.handle());
302
303
2/2
✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
56 currentSpace.setName(newSpace.nameString());
304
305
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 if (newSpace.isDirectionofRelativeNorthDefaulted()) {
306 56 currentSpace.resetDirectionofRelativeNorth();
307 } else {
308 ✗ currentSpace.setDirectionofRelativeNorth(newSpace.directionofRelativeNorth());
309 }
310
311
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 if (newSpace.isXOriginDefaulted()) {
312 56 currentSpace.resetXOrigin();
313 } else {
314 ✗ currentSpace.setXOrigin(newSpace.xOrigin());
315 }
316
317
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 if (newSpace.isYOriginDefaulted()) {
318 56 currentSpace.resetYOrigin();
319 } else {
320 ✗ currentSpace.setYOrigin(newSpace.yOrigin());
321 }
322
323
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 if (newSpace.isZOriginDefaulted()) {
324 56 currentSpace.resetZOrigin();
325 } else {
326 ✗ currentSpace.setZOrigin(newSpace.zOrigin());
327 }
328
329 // remove current surfaces
330
3/3
✓ Branch 1 taken 56 times.
✓ Branch 7 taken 175 times.
✓ Branch 8 taken 56 times.
231 for (auto& currentSurface : currentSpace.surfaces()) {
331
1/1
✓ Branch 1 taken 175 times.
175 currentSurface.remove();
332 56 }
333
334 // remove current shadingSurfaceGroups
335
2/3
✓ Branch 1 taken 56 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 56 times.
56 for (auto& shadingSurfaceGroup : currentSpace.shadingSurfaceGroups()) {
336 ✗ shadingSurfaceGroup.remove();
337 56 }
338
339 // add new surfaces
340
3/3
✓ Branch 1 taken 56 times.
✓ Branch 8 taken 502 times.
✓ Branch 9 taken 56 times.
558 for (const auto& newSurface : newSpace.surfaces()) {
341 // DLM: this should probably be moved to a mergeSurface method
342
3/3
✓ Branch 1 taken 502 times.
✓ Branch 4 taken 502 times.
✓ Branch 7 taken 502 times.
502 auto clone = newSurface.clone(m_currentModel).cast<Surface>();
343
1/1
✓ Branch 1 taken 502 times.
502 clone.setSpace(currentSpace);
344
345
2/2
✓ Branch 1 taken 502 times.
✓ Branch 4 taken 502 times.
502 m_newMergedHandles.insert(newSurface.handle());
346
3/3
✓ Branch 1 taken 502 times.
✓ Branch 4 taken 502 times.
✓ Branch 7 taken 502 times.
502 m_currentToNewHandleMapping[clone.handle()] = newSurface.handle();
347
3/3
✓ Branch 1 taken 502 times.
✓ Branch 4 taken 502 times.
✓ Branch 7 taken 502 times.
502 m_newToCurrentHandleMapping[newSurface.handle()] = clone.handle();
348
349
1/1
✓ Branch 1 taken 502 times.
502 boost::optional<Surface> newAdjacentSurface = newSurface.adjacentSurface();
350
2/2
✓ Branch 0 taken 198 times.
✓ Branch 1 taken 304 times.
502 if (newAdjacentSurface) {
351
3/3
✓ Branch 1 taken 198 times.
✓ Branch 4 taken 198 times.
✓ Branch 7 taken 198 times.
198 boost::optional<UUID> currentAdjacentSurfaceHandle = getCurrentModelHandle(newAdjacentSurface->handle());
352
2/2
✓ Branch 0 taken 99 times.
✓ Branch 1 taken 99 times.
198 if (currentAdjacentSurfaceHandle) {
353
2/2
✓ Branch 1 taken 99 times.
✓ Branch 4 taken 99 times.
99 boost::optional<Surface> currentAdjacentSurface = m_currentModel.getModelObject<Surface>(*currentAdjacentSurfaceHandle);
354
1/2
✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
99 if (currentAdjacentSurface) {
355
2/2
✓ Branch 1 taken 99 times.
✓ Branch 4 taken 99 times.
99 clone.setAdjacentSurface(*currentAdjacentSurface);
356 }
357 99 }
358 198 }
359
360 // setAdjacentSurface resets the AdjacentSubSurface on all child subsurfaces
361
3/3
✓ Branch 1 taken 502 times.
✓ Branch 8 taken 146 times.
✓ Branch 9 taken 502 times.
648 for (const auto& newSubSurface : newSurface.subSurfaces()) {
362 // for performance reasons, only find matching subsurfaces if there is an AdjacentSubSurface
363
1/1
✓ Branch 1 taken 146 times.
146 boost::optional<SubSurface> newAdjacentSubSurface = newSubSurface.adjacentSubSurface();
364
2/2
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 108 times.
146 if (newAdjacentSubSurface) {
365
2/3
✓ Branch 1 taken 38 times.
✓ Branch 8 taken 38 times.
✗ Branch 9 not taken.
38 for (auto& cloneSubSurface : clone.subSurfaces()) {
366
4/5
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
✓ Branch 11 taken 38 times.
✗ Branch 12 not taken.
38 if (circularEqual(newSubSurface.vertices(), cloneSubSurface.vertices(), 0.01)) {
367 // only subsurfaces with an AdjacentSubSurface will be added to the handle mapping
368
3/3
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
38 m_currentToNewHandleMapping[cloneSubSurface.handle()] = newSubSurface.handle();
369
3/3
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
38 m_newToCurrentHandleMapping[newSubSurface.handle()] = cloneSubSurface.handle();
370
3/3
✓ Branch 1 taken 38 times.
✓ Branch 4 taken 38 times.
✓ Branch 7 taken 38 times.
38 boost::optional<UUID> currentAdjacentSubSurfaceHandle = getCurrentModelHandle(newAdjacentSubSurface->handle());
371
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 19 times.
38 if (currentAdjacentSubSurfaceHandle) {
372
2/2
✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
19 boost::optional<SubSurface> currentAdjacentSubSurface = m_currentModel.getModelObject<SubSurface>(*currentAdjacentSubSurfaceHandle);
373
1/2
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
19 if (currentAdjacentSubSurface) {
374
2/2
✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
19 cloneSubSurface.setAdjacentSubSurface(*currentAdjacentSubSurface);
375 }
376 19 }
377 38 break;
378 38 }
379 38 }
380 }
381 648 }
382 558 }
383
384 // add new shadingSurfaceGroups
385
2/3
✓ Branch 1 taken 56 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 56 times.
56 for (const auto& newShadingSurfaceGroup : newSpace.shadingSurfaceGroups()) {
386
387 // check if this already merged via a window clone
388 ✗ if (m_newMergedHandles.find(newShadingSurfaceGroup.handle()) != m_newMergedHandles.end()) {
389 ✗ continue;
390 }
391
392 ✗ auto clone = newShadingSurfaceGroup.clone(m_currentModel).cast<ShadingSurfaceGroup>();
393 ✗ clone.setSpace(currentSpace);
394
395 ✗ m_newMergedHandles.insert(newShadingSurfaceGroup.handle());
396 ✗ m_currentToNewHandleMapping[clone.handle()] = newShadingSurfaceGroup.handle();
397 ✗ m_newToCurrentHandleMapping[newShadingSurfaceGroup.handle()] = clone.handle();
398
399 ✗ boost::optional<SubSurface> newShadedSubSurface = newShadingSurfaceGroup.shadedSubSurface();
400 ✗ if (newShadedSubSurface) {
401 ✗ boost::optional<UUID> currentSubSurfaceHandle = getCurrentModelHandle(newShadedSubSurface->handle());
402 ✗ if (currentSubSurfaceHandle) {
403 ✗ boost::optional<SubSurface> currentSubSurface = m_currentModel.getModelObject<SubSurface>(*currentSubSurfaceHandle);
404 ✗ if (currentSubSurface) {
405 ✗ clone.setShadedSubSurface(*currentSubSurface);
406 }
407 ✗ }
408 ✗ }
409
410 ✗ boost::optional<Surface> newShadedSurface = newShadingSurfaceGroup.shadedSurface();
411 ✗ if (newShadedSurface) {
412 ✗ boost::optional<UUID> currentSurfaceHandle = getCurrentModelHandle(newShadedSurface->handle());
413 ✗ if (currentSurfaceHandle) {
414 ✗ boost::optional<Surface> currentSurface = m_currentModel.getModelObject<Surface>(*currentSurfaceHandle);
415 ✗ if (currentSurface) {
416 ✗ clone.setShadedSurface(*currentSurface);
417 }
418 ✗ }
419 ✗ }
420 56 }
421
422 // DLM: TODO remove current and bring over new hard assigned loads, optional
423
424 // DLM: TODO interiorPartitionSurfaceGroups
425
426 // thermal zone
427
3/3
✓ Branch 1 taken 56 times.
✓ Branch 3 taken 42 times.
✓ Branch 4 taken 14 times.
112 if (boost::optional<ThermalZone> newThermalZone = newSpace.thermalZone()) {
428
2/2
✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
42 boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newThermalZone);
429
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 if (currentObject) {
430
2/2
✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
42 auto currentThermalZone = currentObject->cast<ThermalZone>();
431
1/1
✓ Branch 1 taken 42 times.
42 currentSpace.setThermalZone(currentThermalZone);
432 42 } else {
433 ✗ currentSpace.resetThermalZone();
434 }
435 42 } else {
436
1/1
✓ Branch 1 taken 14 times.
14 currentSpace.resetThermalZone();
437 56 }
438
439 // space type
440
3/3
✓ Branch 1 taken 56 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 48 times.
112 if (boost::optional<SpaceType> newSpaceType = newSpace.spaceType()) {
441
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newSpaceType);
442
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (currentObject) {
443
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 auto currentSpaceType = currentObject->cast<SpaceType>();
444
1/1
✓ Branch 1 taken 8 times.
8 currentSpace.setSpaceType(currentSpaceType);
445 8 } else {
446 ✗ currentSpace.resetSpaceType();
447 }
448 8 } else {
449
1/1
✓ Branch 1 taken 48 times.
48 currentSpace.resetSpaceType();
450 56 }
451
452 // building story
453
3/3
✓ Branch 1 taken 56 times.
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 36 times.
112 if (boost::optional<BuildingStory> newBuildingStory = newSpace.buildingStory()) {
454
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newBuildingStory);
455
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (currentObject) {
456
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 auto currentBuildingStory = currentObject->cast<BuildingStory>();
457
1/1
✓ Branch 1 taken 20 times.
20 currentSpace.setBuildingStory(currentBuildingStory);
458 20 } else {
459 ✗ currentSpace.resetBuildingStory();
460 }
461 20 } else {
462
1/1
✓ Branch 1 taken 36 times.
36 currentSpace.resetBuildingStory();
463 56 }
464
465 // building unit
466
3/3
✓ Branch 1 taken 56 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 48 times.
112 if (boost::optional<BuildingUnit> newBuildingUnit = newSpace.buildingUnit()) {
467
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newBuildingUnit);
468
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (currentObject) {
469
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 auto currentBuildingUnit = currentObject->cast<BuildingUnit>();
470
1/1
✓ Branch 1 taken 8 times.
8 currentSpace.setBuildingUnit(currentBuildingUnit);
471 8 } else {
472 ✗ currentSpace.resetBuildingUnit();
473 }
474 8 } else {
475
1/1
✓ Branch 1 taken 48 times.
48 currentSpace.resetBuildingUnit();
476 56 }
477
478 // default construction set
479
3/3
✓ Branch 1 taken 56 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 48 times.
112 if (boost::optional<DefaultConstructionSet> newDefaultConstructionSet = newSpace.defaultConstructionSet()) {
480
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newDefaultConstructionSet);
481
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (currentObject) {
482
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 auto currentDefaultConstructionSet = currentObject->cast<DefaultConstructionSet>();
483
1/1
✓ Branch 1 taken 8 times.
8 currentSpace.setDefaultConstructionSet(currentDefaultConstructionSet);
484 8 } else {
485 ✗ currentSpace.resetDefaultConstructionSet();
486 }
487 8 } else {
488
1/1
✓ Branch 1 taken 48 times.
48 currentSpace.resetDefaultConstructionSet();
489 56 }
490
491 // remove current daylightingControls
492
2/3
✓ Branch 1 taken 56 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 56 times.
56 for (auto& daylightingControl : currentSpace.daylightingControls()) {
493 ✗ daylightingControl.remove();
494 56 }
495
496 // add new daylightingControls
497
2/3
✓ Branch 1 taken 56 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 56 times.
56 for (const auto& newDaylightingControl : newSpace.daylightingControls()) {
498
499 ✗ auto clone = newDaylightingControl.clone(m_currentModel).cast<DaylightingControl>();
500 ✗ clone.setSpace(currentSpace);
501
502 ✗ m_newMergedHandles.insert(newDaylightingControl.handle());
503 ✗ m_currentToNewHandleMapping[clone.handle()] = newDaylightingControl.handle();
504 ✗ m_newToCurrentHandleMapping[newDaylightingControl.handle()] = clone.handle();
505
506 // hook up daylighting control to thermal zone
507 ✗ for (const auto& newThermalZone : newDaylightingControl.getModelObjectSources<ThermalZone>()) {
508 ✗ boost::optional<DaylightingControl> primaryDaylightingControl = newThermalZone.primaryDaylightingControl();
509 ✗ boost::optional<DaylightingControl> secondaryDaylightingControl = newThermalZone.secondaryDaylightingControl();
510
511 ✗ if (primaryDaylightingControl && (primaryDaylightingControl->handle() == newDaylightingControl.handle())) {
512 ✗ boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(newThermalZone);
513 ✗ if (currentObject) {
514 ✗ auto currentThermalZone = currentObject->cast<ThermalZone>();
515 ✗ currentThermalZone.setPrimaryDaylightingControl(clone);
516 ✗ currentThermalZone.setFractionofZoneControlledbyPrimaryDaylightingControl(
517 newThermalZone.fractionofZoneControlledbyPrimaryDaylightingControl());
518 ✗ }
519
520 ✗ } else if (secondaryDaylightingControl && (secondaryDaylightingControl->handle() == newDaylightingControl.handle())) {
521 ✗ boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(newThermalZone);
522 ✗ if (currentObject) {
523 ✗ auto currentThermalZone = currentObject->cast<ThermalZone>();
524 ✗ currentThermalZone.setSecondaryDaylightingControl(clone);
525 ✗ currentThermalZone.setFractionofZoneControlledbySecondaryDaylightingControl(
526 newThermalZone.fractionofZoneControlledbySecondaryDaylightingControl());
527 ✗ }
528 ✗ }
529 ✗ }
530 56 }
531 }
532
533 2 void ModelMerger::mergeShadingSurfaceGroup(ShadingSurfaceGroup& currentGroup, const ShadingSurfaceGroup& newGroup) {
534
3/4
✓ Branch 2 taken 2 times.
✓ Branch 5 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
2 if (m_newMergedHandles.find(newGroup.handle()) != m_newMergedHandles.end()) {
535 // already merged
536 ✗ return;
537 }
538
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 m_newMergedHandles.insert(newGroup.handle());
539
540
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 currentGroup.setName(newGroup.nameString());
541
542
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (newGroup.isDirectionofRelativeNorthDefaulted()) {
543 2 currentGroup.resetDirectionofRelativeNorth();
544 } else {
545 ✗ currentGroup.setDirectionofRelativeNorth(newGroup.directionofRelativeNorth());
546 }
547
548
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (newGroup.isXOriginDefaulted()) {
549 2 currentGroup.resetXOrigin();
550 } else {
551 ✗ currentGroup.setXOrigin(newGroup.xOrigin());
552 }
553
554
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (newGroup.isYOriginDefaulted()) {
555 2 currentGroup.resetYOrigin();
556 } else {
557 ✗ currentGroup.setYOrigin(newGroup.yOrigin());
558 }
559
560
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (newGroup.isZOriginDefaulted()) {
561 2 currentGroup.resetZOrigin();
562 } else {
563 ✗ currentGroup.setZOrigin(newGroup.zOrigin());
564 }
565
566 // remove current shading surfaces
567
2/3
✓ Branch 1 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
2 for (auto& currentSurface : currentGroup.shadingSurfaces()) {
568 ✗ currentSurface.remove();
569 2 }
570
571 // change shading surface group type
572
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 currentGroup.setShadingSurfaceType(newGroup.shadingSurfaceType());
573
574 // add new shading surfaces
575
3/3
✓ Branch 1 taken 2 times.
✓ Branch 8 taken 136 times.
✓ Branch 9 taken 2 times.
138 for (const auto& newSurface : newGroup.shadingSurfaces()) {
576 // DLM: this should probably be moved to a mergeSurface method
577
3/3
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
✓ Branch 7 taken 136 times.
136 auto clone = newSurface.clone(m_currentModel).cast<ShadingSurface>();
578
1/1
✓ Branch 1 taken 136 times.
136 clone.setShadingSurfaceGroup(currentGroup);
579
580
2/2
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
136 m_newMergedHandles.insert(newSurface.handle());
581
3/3
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
✓ Branch 7 taken 136 times.
136 m_currentToNewHandleMapping[clone.handle()] = newSurface.handle();
582
3/3
✓ Branch 1 taken 136 times.
✓ Branch 4 taken 136 times.
✓ Branch 7 taken 136 times.
136 m_newToCurrentHandleMapping[newSurface.handle()] = clone.handle();
583 138 }
584 }
585
586 84 void ModelMerger::mergeThermalZone(ThermalZone& currentThermalZone, const ThermalZone& newThermalZone) {
587
4/4
✓ Branch 2 taken 84 times.
✓ Branch 5 taken 84 times.
✓ Branch 8 taken 42 times.
✓ Branch 9 taken 42 times.
84 if (m_newMergedHandles.find(newThermalZone.handle()) != m_newMergedHandles.end()) {
588 // already merged
589 42 return;
590 }
591
2/2
✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
42 m_newMergedHandles.insert(newThermalZone.handle());
592
593
2/2
✓ Branch 1 taken 42 times.
✓ Branch 4 taken 42 times.
42 currentThermalZone.setName(newThermalZone.nameString());
594
595 // rendering color
596
1/1
✓ Branch 1 taken 42 times.
42 boost::optional<RenderingColor> newColor = newThermalZone.renderingColor();
597
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 40 times.
42 if (newColor) {
598
1/1
✓ Branch 1 taken 2 times.
2 boost::optional<RenderingColor> currentColor = currentThermalZone.renderingColor();
599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (currentColor) {
600 ✗ currentColor->setRenderingRedValue(newColor->renderingRedValue());
601 ✗ currentColor->setRenderingGreenValue(newColor->renderingGreenValue());
602 ✗ currentColor->setRenderingBlueValue(newColor->renderingBlueValue());
603 ✗ currentColor->setRenderingAlphaValue(newColor->renderingAlphaValue());
604 } else {
605
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 currentColor = RenderingColor::fromColorString(newColor->colorString(), currentThermalZone.model());
606
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(currentColor);
607
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 currentThermalZone.setRenderingColor(*currentColor);
608 }
609 2 }
610
611 // multiplier
612
3/3
✓ Branch 1 taken 42 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 34 times.
42 if (newThermalZone.isMultiplierDefaulted()) {
613 // DLM: TODO: add option as this might have been intentionally reset on other model
614 //currentThermalZone.resetMultiplier();
615 } else {
616
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 currentThermalZone.setMultiplier(newThermalZone.multiplier());
617 }
618
619 // ceilingHeight
620
3/8
✓ Branch 1 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 42 times.
42 if (newThermalZone.isCeilingHeightDefaulted() || newThermalZone.isCeilingHeightAutocalculated()) {
621 // DLM: TODO: add option as this might have been intentionally reset on other model
622 //currentThermalZone.resetCeilingHeight();
623 } else {
624 ✗ currentThermalZone.setCeilingHeight(newThermalZone.ceilingHeight());
625 }
626
627 // volume
628
3/8
✓ Branch 1 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 42 times.
42 if (newThermalZone.isVolumeDefaulted() || newThermalZone.isVolumeAutocalculated()) {
629 // DLM: TODO: add option as this might have been intentionally reset on other model
630 //currentThermalZone.resetVolume();
631 } else {
632 ✗ currentThermalZone.setVolume(newThermalZone.volume());
633 }
634
635 // DLM: TODO zoneInsideConvectionAlgorithm
636 // DLM: TODO zoneOutsideConvectionAlgorithm
637 // DLM: TODO zoneConditioningEquipmentListName ?
638 // DLM: TODO thermostat
639 // DLM: TODO zoneControlHumidistat
640 // DLM: TODO zoneControlContaminantController
641 // DLM: TODO sizingZone
642 42 }
643
644 19 void ModelMerger::mergeSpaceType(SpaceType& currentSpaceType, const SpaceType& newSpaceType) {
645
4/4
✓ Branch 2 taken 19 times.
✓ Branch 5 taken 19 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 11 times.
19 if (m_newMergedHandles.find(newSpaceType.handle()) != m_newMergedHandles.end()) {
646 // already merged
647 8 return;
648 }
649
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 m_newMergedHandles.insert(newSpaceType.handle());
650
651
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 currentSpaceType.setName(newSpaceType.nameString());
652
653 //default construction set.
654
2/3
✓ Branch 1 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
22 if (boost::optional<DefaultConstructionSet> newDefaultConstructionSet = newSpaceType.defaultConstructionSet()) {
655 ✗ boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newDefaultConstructionSet);
656 ✗ if (currentObject) {
657 ✗ auto currentDefaultConstructionSet = currentObject->cast<DefaultConstructionSet>();
658 ✗ currentSpaceType.setDefaultConstructionSet(currentDefaultConstructionSet);
659 ✗ } else {
660 // DLM: this is an error
661 //currentSpaceType.resetDefaultConstructionSet();
662 }
663 ✗ } else {
664 // DLM: TODO: add option as this might have been intentionally reset on other model
665 //currentSpaceType.resetDefaultConstructionSet();
666 11 }
667
668 // default schedule set
669
2/3
✓ Branch 1 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
22 if (boost::optional<DefaultScheduleSet> newDefaultScheduleSet = newSpaceType.defaultScheduleSet()) {
670 ✗ boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newDefaultScheduleSet);
671 ✗ if (currentObject) {
672 ✗ auto currentDefaultScheduleSet = currentObject->cast<DefaultScheduleSet>();
673 ✗ currentSpaceType.setDefaultScheduleSet(currentDefaultScheduleSet);
674 ✗ } else {
675 // DLM: this is an error
676 //currentSpaceType.resetDefaultScheduleSet();
677 }
678 ✗ } else {
679 // DLM: TODO: add option as this might have been intentionally reset on other model
680 //currentSpaceType.resetDefaultScheduleSet();
681 11 }
682
683 // rendering color
684
1/1
✓ Branch 1 taken 11 times.
11 boost::optional<RenderingColor> newColor = newSpaceType.renderingColor();
685
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 8 times.
11 if (newColor) {
686
1/1
✓ Branch 1 taken 3 times.
3 boost::optional<RenderingColor> currentColor = currentSpaceType.renderingColor();
687
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
3 if (currentColor) {
688
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 currentColor->setRenderingRedValue(newColor->renderingRedValue());
689
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 currentColor->setRenderingGreenValue(newColor->renderingGreenValue());
690
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 currentColor->setRenderingBlueValue(newColor->renderingBlueValue());
691
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 currentColor->setRenderingAlphaValue(newColor->renderingAlphaValue());
692 } else {
693
4/4
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
1 currentColor = RenderingColor::fromColorString(newColor->colorString(), currentSpaceType.model());
694
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 4 not taken.
1 OS_ASSERT(currentColor);
695
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 currentSpaceType.setRenderingColor(*currentColor);
696 }
697 3 }
698
699 // standardsBuildingType
700
1/1
✓ Branch 1 taken 11 times.
11 boost::optional<std::string> newStandardsBuildingType = newSpaceType.standardsBuildingType();
701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (newStandardsBuildingType) {
702 ✗ currentSpaceType.setStandardsBuildingType(*newStandardsBuildingType);
703 } else {
704 // DLM: TODO: add option as this might have been intentionally reset on other model
705 //currentSpaceType.resetStandardsBuildingType();
706 }
707
708 // standardsSpaceType
709
1/1
✓ Branch 1 taken 11 times.
11 boost::optional<std::string> newStandardsSpaceType = newSpaceType.standardsSpaceType();
710
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
11 if (newStandardsSpaceType) {
711 ✗ currentSpaceType.setStandardsSpaceType(*newStandardsSpaceType);
712 } else {
713 // DLM: TODO: add option as this might have been intentionally reset on other model
714 //currentSpaceType.resetStandardsSpaceType();
715 }
716
717 // bring over child loads
718 // DLM: should only do this if new model can have loads, if doing this should also remove current loads
719 //for (const auto& newChild : newSpaceType.children()){
720 // ModelObject currentChild = newChild.clone(m_currentModel).cast<ModelObject>();
721 // currentChild.setParent(currentSpaceType);
722 //}
723 11 }
724
725 32 void ModelMerger::mergeBuildingStory(BuildingStory& currentBuildingStory, const BuildingStory& newBuildingStory) {
726
4/4
✓ Branch 2 taken 32 times.
✓ Branch 5 taken 32 times.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 12 times.
32 if (m_newMergedHandles.find(newBuildingStory.handle()) != m_newMergedHandles.end()) {
727 // already merged
728 20 return;
729 }
730
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 m_newMergedHandles.insert(newBuildingStory.handle());
731
732
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 currentBuildingStory.setName(newBuildingStory.nameString());
733
734 // rendering color
735
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<RenderingColor> newColor = newBuildingStory.renderingColor();
736
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 10 times.
12 if (newColor) {
737
1/1
✓ Branch 1 taken 2 times.
2 boost::optional<RenderingColor> currentColor = currentBuildingStory.renderingColor();
738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (currentColor) {
739 ✗ currentColor->setRenderingRedValue(newColor->renderingRedValue());
740 ✗ currentColor->setRenderingGreenValue(newColor->renderingGreenValue());
741 ✗ currentColor->setRenderingBlueValue(newColor->renderingBlueValue());
742 ✗ currentColor->setRenderingAlphaValue(newColor->renderingAlphaValue());
743 } else {
744
4/4
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
2 currentColor = RenderingColor::fromColorString(newColor->colorString(), currentBuildingStory.model());
745
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(currentColor);
746
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 currentBuildingStory.setRenderingColor(*currentColor);
747 }
748 2 }
749
750 // nominalZCoordinate
751
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<double> newNominalZCoordinate = newBuildingStory.nominalZCoordinate();
752
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (newNominalZCoordinate) {
753
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 currentBuildingStory.setNominalZCoordinate(*newNominalZCoordinate);
754 } else {
755 ✗ currentBuildingStory.resetNominalZCoordinate();
756 }
757
758 // nominalFloortoFloorHeight
759
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<double> newNominalFloortoFloorHeight = newBuildingStory.nominalFloortoFloorHeight();
760
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (newNominalFloortoFloorHeight) {
761
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 currentBuildingStory.setNominalFloortoFloorHeight(*newNominalFloortoFloorHeight);
762 } else {
763 ✗ currentBuildingStory.resetNominalFloortoFloorHeight();
764 }
765
766 // nominalFloortoCeilingHeight
767
1/1
✓ Branch 1 taken 12 times.
12 boost::optional<double> newNominalFloortoCeilingHeight = newBuildingStory.nominalFloortoCeilingHeight();
768
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if (newNominalFloortoCeilingHeight) {
769
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 currentBuildingStory.setNominalFloortoCeilingHeight(*newNominalFloortoCeilingHeight);
770 } else {
771 ✗ currentBuildingStory.resetNominalFloortoCeilingHeight();
772 }
773
774 //default construction set.
775
2/3
✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
24 if (boost::optional<DefaultConstructionSet> newDefaultConstructionSet = newBuildingStory.defaultConstructionSet()) {
776 ✗ boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newDefaultConstructionSet);
777 ✗ if (currentObject) {
778 ✗ auto currentDefaultConstructionSet = currentObject->cast<DefaultConstructionSet>();
779 ✗ currentBuildingStory.setDefaultConstructionSet(currentDefaultConstructionSet);
780 ✗ } else {
781 // DLM: this is an error
782 //currentBuildingStory.resetDefaultConstructionSet();
783 }
784 ✗ } else {
785 // DLM: TODO: add option as this might have been intentionally reset on other model
786 //currentBuildingStory.resetDefaultConstructionSet();
787 12 }
788
789 // default schedule set
790
2/3
✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
24 if (boost::optional<DefaultScheduleSet> newDefaultScheduleSet = newBuildingStory.defaultScheduleSet()) {
791 ✗ boost::optional<WorkspaceObject> currentObject = getCurrentModelObject(*newDefaultScheduleSet);
792 ✗ if (currentObject) {
793 ✗ auto currentDefaultScheduleSet = currentObject->cast<DefaultScheduleSet>();
794 ✗ currentBuildingStory.setDefaultScheduleSet(currentDefaultScheduleSet);
795 ✗ } else {
796 // DLM: this is an error
797 //currentBuildingStory.resetDefaultScheduleSet();
798 }
799 ✗ } else {
800 // DLM: TODO: add option as this might have been intentionally reset on other model
801 //currentBuildingStory.resetDefaultScheduleSet();
802 12 }
803 12 }
804
805 14 void ModelMerger::mergeBuildingUnit(BuildingUnit& currentBuildingUnit, const BuildingUnit& newBuildingUnit) {
806
4/4
✓ Branch 2 taken 14 times.
✓ Branch 5 taken 14 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 6 times.
14 if (m_newMergedHandles.find(newBuildingUnit.handle()) != m_newMergedHandles.end()) {
807 // already merged
808 8 return;
809 }
810
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 m_newMergedHandles.insert(newBuildingUnit.handle());
811
812
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 currentBuildingUnit.setName(newBuildingUnit.nameString());
813
814 // rendering color
815
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<RenderingColor> newColor = newBuildingUnit.renderingColor();
816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (newColor) {
817 ✗ boost::optional<RenderingColor> currentColor = currentBuildingUnit.renderingColor();
818 ✗ if (currentColor) {
819 ✗ currentColor->setRenderingRedValue(newColor->renderingRedValue());
820 ✗ currentColor->setRenderingGreenValue(newColor->renderingGreenValue());
821 ✗ currentColor->setRenderingBlueValue(newColor->renderingBlueValue());
822 ✗ currentColor->setRenderingAlphaValue(newColor->renderingAlphaValue());
823 } else {
824 ✗ currentColor = RenderingColor::fromColorString(newColor->colorString(), currentBuildingUnit.model());
825 ✗ OS_ASSERT(currentColor);
826 ✗ currentBuildingUnit.setRenderingColor(*currentColor);
827 }
828 ✗ }
829
830 // buildingUnitType
831 // DLM: TODO need to check if other buildingUnitType is defaulted and optionally set
832 //currentBuildingUnit.setBuildingUnitType(newBuildingUnit.buildingUnitType());
833
834 // DLM: TODO featureNames() const;
835 6 }
836
837 12 void ModelMerger::mergeDefaultConstructionSet(DefaultConstructionSet& currentDefaultConstructionSet,
838 const DefaultConstructionSet& newDefaultConstructionSet) {
839
4/4
✓ Branch 2 taken 12 times.
✓ Branch 5 taken 12 times.
✓ Branch 8 taken 8 times.
✓ Branch 9 taken 4 times.
12 if (m_newMergedHandles.find(newDefaultConstructionSet.handle()) != m_newMergedHandles.end()) {
840 // already merged
841 8 return;
842 }
843
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 m_newMergedHandles.insert(newDefaultConstructionSet.handle());
844
845
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 currentDefaultConstructionSet.setName(newDefaultConstructionSet.nameString());
846
847 // DLM: TODO defaultExteriorSurfaceConstructions() const;
848
849 // DLM: TODO defaultInteriorSurfaceConstructions() const;
850
851 // DLM: TODO defaultGroundContactSurfaceConstructions() const;
852
853 // DLM: TODO defaultExteriorSubSurfaceConstructions() const;
854
855 // DLM: TODO defaultInteriorSubSurfaceConstructions() const;
856
857 // DLM: TODO interiorPartitionConstruction() const;
858
859 // DLM: TODO spaceShadingConstruction() const;
860
861 // DLM: TODO buildingShadingConstruction() const;
862
863 // DLM: TODO siteShadingConstruction() const;
864 }
865
866 256 boost::optional<WorkspaceObject> ModelMerger::getCurrentModelObject(const WorkspaceObject& newObject) {
867 // find object in current model
868
2/2
✓ Branch 1 taken 256 times.
✓ Branch 4 taken 256 times.
256 IddObjectType iddObjectType = newObject.iddObject().type();
869
2/2
✓ Branch 1 taken 256 times.
✓ Branch 4 taken 256 times.
256 boost::optional<UUID> currentHandle = getCurrentModelHandle(newObject.handle());
870 256 boost::optional<WorkspaceObject> currentObject;
871
2/2
✓ Branch 0 taken 131 times.
✓ Branch 1 taken 125 times.
256 if (currentHandle) {
872
2/2
✓ Branch 1 taken 131 times.
✓ Branch 4 taken 131 times.
131 currentObject = m_currentModel.getObject(*currentHandle);
873
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 131 times.
131 if (!currentObject) {
874 ✗ LOG(Error, "Could not find object in current model for handle " << *currentHandle << " of type " << iddObjectType.valueName());
875 }
876 }
877
878 // create object in current model if needed
879
2/2
✓ Branch 1 taken 125 times.
✓ Branch 2 taken 131 times.
256 if (!currentObject) {
880
11/12
✓ Branch 1 taken 125 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 9 times.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 27 times.
✓ Branch 9 taken 9 times.
✓ Branch 10 taken 11 times.
✓ Branch 11 taken 6 times.
✓ Branch 12 taken 4 times.
✗ Branch 13 not taken.
125 switch (iddObjectType.value()) {
881 8 case IddObjectType::OS_Site:
882
2/2
✓ Branch 1 taken 8 times.
✓ Branch 4 taken 8 times.
8 currentObject = m_currentModel.getUniqueModelObject<Site>();
883 8 break;
884 9 case IddObjectType::OS_Facility:
885
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 currentObject = m_currentModel.getUniqueModelObject<Facility>();
886 9 break;
887 9 case IddObjectType::OS_Building:
888
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 currentObject = m_currentModel.getUniqueModelObject<Building>();
889 9 break;
890 40 case IddObjectType::OS_Space:
891
2/2
✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
40 currentObject = model::Space(m_currentModel);
892 40 break;
893 2 case IddObjectType::OS_ShadingSurfaceGroup:
894
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 currentObject = model::ShadingSurfaceGroup(m_currentModel);
895 2 break;
896 27 case IddObjectType::OS_ThermalZone:
897
2/2
✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
27 currentObject = model::ThermalZone(m_currentModel);
898 27 break;
899 9 case IddObjectType::OS_SpaceType:
900
2/2
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
9 currentObject = model::SpaceType(m_currentModel);
901 9 break;
902 11 case IddObjectType::OS_BuildingStory:
903
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 currentObject = model::BuildingStory(m_currentModel);
904 11 break;
905 6 case IddObjectType::OS_BuildingUnit:
906
2/2
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
6 currentObject = model::BuildingUnit(m_currentModel);
907 6 break;
908 4 case IddObjectType::OS_DefaultConstructionSet:
909
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 currentObject = model::DefaultConstructionSet(m_currentModel);
910 4 break;
911 ✗ default:
912 ✗ LOG(Error, "No constructor registered for IddObjectType " << iddObjectType.valueName());
913 }
914
915
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 125 times.
✗ Branch 4 not taken.
125 OS_ASSERT(currentObject);
916
4/4
✓ Branch 1 taken 125 times.
✓ Branch 4 taken 125 times.
✓ Branch 7 taken 125 times.
✓ Branch 10 taken 125 times.
125 m_currentToNewHandleMapping[currentObject->handle()] = newObject.handle();
917
4/4
✓ Branch 1 taken 125 times.
✓ Branch 4 taken 125 times.
✓ Branch 7 taken 125 times.
✓ Branch 10 taken 125 times.
125 m_newToCurrentHandleMapping[newObject.handle()] = currentObject->handle();
918 }
919
920 // merge objects
921
11/12
✓ Branch 1 taken 256 times.
✓ Branch 3 taken 11 times.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 13 times.
✓ Branch 6 taken 56 times.
✓ Branch 7 taken 2 times.
✓ Branch 8 taken 84 times.
✓ Branch 9 taken 19 times.
✓ Branch 10 taken 32 times.
✓ Branch 11 taken 14 times.
✓ Branch 12 taken 12 times.
✗ Branch 13 not taken.
256 switch (iddObjectType.value()) {
922 11 case IddObjectType::OS_Site: {
923
2/2
✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
11 Site currentSite = currentObject->cast<Site>();
924
1/1
✓ Branch 1 taken 11 times.
11 Site newSite = newObject.cast<Site>();
925
1/1
✓ Branch 1 taken 11 times.
11 mergeSite(currentSite, newSite);
926 11 } break;
927 13 case IddObjectType::OS_Facility: {
928
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 auto currentFacility = currentObject->cast<Facility>();
929
1/1
✓ Branch 1 taken 13 times.
13 auto newFacility = newObject.cast<Facility>();
930
1/1
✓ Branch 1 taken 13 times.
13 mergeFacility(currentFacility, newFacility);
931 13 } break;
932 13 case IddObjectType::OS_Building: {
933
2/2
✓ Branch 1 taken 13 times.
✓ Branch 4 taken 13 times.
13 auto currentBuilding = currentObject->cast<Building>();
934
1/1
✓ Branch 1 taken 13 times.
13 auto newBuilding = newObject.cast<Building>();
935
1/1
✓ Branch 1 taken 13 times.
13 mergeBuilding(currentBuilding, newBuilding);
936 13 } break;
937 56 case IddObjectType::OS_Space: {
938
2/2
✓ Branch 1 taken 56 times.
✓ Branch 4 taken 56 times.
56 auto currentSpace = currentObject->cast<Space>();
939
1/1
✓ Branch 1 taken 56 times.
56 auto newSpace = newObject.cast<Space>();
940
1/1
✓ Branch 1 taken 56 times.
56 mergeSpace(currentSpace, newSpace);
941 56 } break;
942 2 case IddObjectType::OS_ShadingSurfaceGroup: {
943
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 auto currentGroup = currentObject->cast<ShadingSurfaceGroup>();
944
1/1
✓ Branch 1 taken 2 times.
2 auto newGroup = newObject.cast<ShadingSurfaceGroup>();
945
946 // if the new group has a space it will be added under that space
947
2/3
✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
2 if (!newGroup.space()) {
948
1/1
✓ Branch 1 taken 2 times.
2 mergeShadingSurfaceGroup(currentGroup, newGroup);
949 }
950 2 } break;
951 84 case IddObjectType::OS_ThermalZone: {
952
2/2
✓ Branch 1 taken 84 times.
✓ Branch 4 taken 84 times.
84 auto currentThermalZone = currentObject->cast<ThermalZone>();
953
1/1
✓ Branch 1 taken 84 times.
84 auto newThermalZone = newObject.cast<ThermalZone>();
954
1/1
✓ Branch 1 taken 84 times.
84 mergeThermalZone(currentThermalZone, newThermalZone);
955 84 } break;
956 19 case IddObjectType::OS_SpaceType: {
957
2/2
✓ Branch 1 taken 19 times.
✓ Branch 4 taken 19 times.
19 auto currentSpaceType = currentObject->cast<SpaceType>();
958
1/1
✓ Branch 1 taken 19 times.
19 auto newSpaceType = newObject.cast<SpaceType>();
959
1/1
✓ Branch 1 taken 19 times.
19 mergeSpaceType(currentSpaceType, newSpaceType);
960 19 } break;
961 32 case IddObjectType::OS_BuildingStory: {
962
2/2
✓ Branch 1 taken 32 times.
✓ Branch 4 taken 32 times.
32 auto currentBuildingStory = currentObject->cast<BuildingStory>();
963
1/1
✓ Branch 1 taken 32 times.
32 auto newBuildingStory = newObject.cast<BuildingStory>();
964
1/1
✓ Branch 1 taken 32 times.
32 mergeBuildingStory(currentBuildingStory, newBuildingStory);
965 32 } break;
966 14 case IddObjectType::OS_BuildingUnit: {
967
2/2
✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
14 auto currentBuildingUnit = currentObject->cast<BuildingUnit>();
968
1/1
✓ Branch 1 taken 14 times.
14 auto newBuildingUnit = newObject.cast<BuildingUnit>();
969
1/1
✓ Branch 1 taken 14 times.
14 mergeBuildingUnit(currentBuildingUnit, newBuildingUnit);
970 14 } break;
971 12 case IddObjectType::OS_DefaultConstructionSet: {
972
2/2
✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
12 auto currentDefaultConstructionSet = currentObject->cast<DefaultConstructionSet>();
973
1/1
✓ Branch 1 taken 12 times.
12 auto newDefaultConstructionSet = newObject.cast<DefaultConstructionSet>();
974
1/1
✓ Branch 1 taken 12 times.
12 mergeDefaultConstructionSet(currentDefaultConstructionSet, newDefaultConstructionSet);
975 12 } break;
976 ✗ default:
977 ✗ LOG(Error, "No merge function registered for IddObjectType " << iddObjectType.valueName());
978 }
979
980
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 256 times.
✗ Branch 4 not taken.
256 OS_ASSERT(currentObject);
981
3/5
✓ Branch 1 taken 256 times.
✓ Branch 4 taken 256 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 256 times.
✗ Branch 10 not taken.
256 OS_ASSERT(!currentObject->handle().isNull());
982
2/2
✓ Branch 1 taken 256 times.
✓ Branch 4 taken 256 times.
512 return *currentObject;
983 256 }
984
985 21 void ModelMerger::mergeModels(Model& currentModel, const Model& newModel, const std::map<UUID, UUID>& handleMapping) {
986 21 m_logSink.setThreadId(std::this_thread::get_id());
987 21 m_logSink.resetStringStream();
988
989 21 m_currentModel = currentModel;
990 21 m_newModel = newModel;
991
992 21 m_newMergedHandles.clear();
993 21 m_currentToNewHandleMapping = handleMapping;
994 21 m_newToCurrentHandleMapping.clear();
995
2/2
✓ Branch 4 taken 45 times.
✓ Branch 5 taken 21 times.
66 for (const auto& it : handleMapping) {
996
2/3
✓ Branch 2 taken 45 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 45 times.
45 if (m_newToCurrentHandleMapping.find(it.second) != m_newToCurrentHandleMapping.end()) {
997 ✗ LOG(Error, "Multiple entries in current model refer to handle '" << toString(it.second) << "' in new model");
998 }
999
1/1
✓ Branch 1 taken 45 times.
45 m_newToCurrentHandleMapping[it.second] = it.first;
1000 }
1001
1002 //** Remove objects from current model that are not in new model **//
1003
3/3
✓ Branch 1 taken 21 times.
✓ Branch 8 taken 210 times.
✓ Branch 9 taken 21 times.
231 for (const auto& iddObjectType : iddObjectTypesToMerge()) {
1004
3/3
✓ Branch 1 taken 210 times.
✓ Branch 8 taken 88 times.
✓ Branch 9 taken 210 times.
298 for (auto& currenObject : currentModel.getObjectsByType(iddObjectType)) {
1005
4/4
✓ Branch 2 taken 88 times.
✓ Branch 5 taken 88 times.
✓ Branch 8 taken 43 times.
✓ Branch 9 taken 45 times.
88 if (m_currentToNewHandleMapping.find(currenObject.handle()) == m_currentToNewHandleMapping.end()) {
1006
4/4
✓ Branch 1 taken 43 times.
✓ Branch 5 taken 40 times.
✓ Branch 8 taken 39 times.
✓ Branch 9 taken 1 time.
83 if ((iddObjectType == IddObjectType::OS_Site) || (iddObjectType == IddObjectType::OS_Facility)
1007
7/7
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 3 times.
✓ Branch 3 taken 39 times.
✓ Branch 6 taken 3 times.
✓ Branch 7 taken 36 times.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 36 times.
83 || (iddObjectType == IddObjectType::OS_Building)) {
1008 // These are unique objects, so no need to delete them
1009 7 continue;
1010 } else {
1011
1/1
✓ Branch 1 taken 36 times.
36 currenObject.remove();
1012 }
1013 }
1014 210 }
1015 21 }
1016
1017 //** Merge objects from new model into current model **//
1018
3/3
✓ Branch 1 taken 21 times.
✓ Branch 8 taken 210 times.
✓ Branch 9 taken 21 times.
231 for (const auto& iddObjectType : iddObjectTypesToMerge()) {
1019
3/3
✓ Branch 1 taken 210 times.
✓ Branch 7 taken 170 times.
✓ Branch 8 taken 210 times.
380 for (auto& newObject : newModel.getObjectsByType(iddObjectType)) {
1020
1/1
✓ Branch 1 taken 170 times.
170 getCurrentModelObject(newObject);
1021 210 }
1022 21 }
1023 21 }
1024
1025 42 std::vector<IddObjectType> ModelMerger::iddObjectTypesToMerge() const {
1026 42 return m_iddObjectTypesToMerge;
1027 }
1028
1029 ✗ bool ModelMerger::setIddObjectTypesToMerge(const std::vector<IddObjectType>& /*iddObjectTypesToMerge*/) {
1030 ✗ LOG(Error, "setIddObjectTypesToMerge is not yet implemented");
1031 ✗ return false;
1032 }
1033
1034 } // namespace model
1035 } // namespace openstudio
1036