GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 39.2% 85 / 0 / 217
Functions: 38.8% 26 / 0 / 67
Branches: 32.0% 55 / 0 / 172

src/model/GlareSensor.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 "GlareSensor.hpp"
7 #include "GlareSensor_Impl.hpp"
8 #include "ThermalZone.hpp"
9 #include "ThermalZone_Impl.hpp"
10
11 #include <utilities/idd/IddFactory.hxx>
12
13 #include <utilities/idd/OS_Glare_Sensor_FieldEnums.hxx>
14 #include <utilities/idd/IddEnums.hxx>
15
16 #include "../utilities/geometry/Transformation.hpp"
17 #include "../utilities/geometry/EulerAngles.hpp"
18 #include "../utilities/geometry/Vector3d.hpp"
19 #include "../utilities/geometry/Point3d.hpp"
20 #include "../utilities/geometry/Geometry.hpp"
21 #include "../utilities/core/Assert.hpp"
22
23 namespace openstudio {
24 namespace model {
25
26 namespace detail {
27
28 195 GlareSensor_Impl::GlareSensor_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
29 195 : SpaceItem_Impl(idfObject, model, keepHandle) {
30
4/6
✓ Branch 1 taken 195 times.
✓ Branch 4 taken 195 times.
✓ Branch 7 taken 195 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 195 times.
✗ Branch 13 not taken.
195 OS_ASSERT(idfObject.iddObject().type() == GlareSensor::iddObjectType());
31 195 }
32
33 25 GlareSensor_Impl::GlareSensor_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
34 25 : SpaceItem_Impl(other, model, keepHandle) {
35
4/6
✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
✓ Branch 7 taken 25 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 25 times.
✗ Branch 13 not taken.
25 OS_ASSERT(other.iddObject().type() == GlareSensor::iddObjectType());
36 25 }
37
38 65 GlareSensor_Impl::GlareSensor_Impl(const GlareSensor_Impl& other, Model_Impl* model, bool keepHandle)
39 65 : SpaceItem_Impl(other, model, keepHandle) {}
40
41 1 const std::vector<std::string>& GlareSensor_Impl::outputVariableNames() const {
42
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
1 static const std::vector<std::string> result;
43 1 return result;
44 }
45
46 1 IddObjectType GlareSensor_Impl::iddObjectType() const {
47 1 return GlareSensor::iddObjectType();
48 }
49
50 182 double GlareSensor_Impl::positionXCoordinate() const {
51
1/1
✓ Branch 1 taken 182 times.
182 boost::optional<double> value = getDouble(OS_Glare_SensorFields::PositionXCoordinate, true);
52
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 182 times.
✗ Branch 4 not taken.
182 OS_ASSERT(value);
53
1/1
✓ Branch 1 taken 182 times.
364 return value.get();
54 }
55
56 182 double GlareSensor_Impl::positionYCoordinate() const {
57
1/1
✓ Branch 1 taken 182 times.
182 boost::optional<double> value = getDouble(OS_Glare_SensorFields::PositionYCoordinate, true);
58
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 182 times.
✗ Branch 4 not taken.
182 OS_ASSERT(value);
59
1/1
✓ Branch 1 taken 182 times.
364 return value.get();
60 }
61
62 182 double GlareSensor_Impl::positionZCoordinate() const {
63
1/1
✓ Branch 1 taken 182 times.
182 boost::optional<double> value = getDouble(OS_Glare_SensorFields::PositionZCoordinate, true);
64
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 182 times.
✗ Branch 4 not taken.
182 OS_ASSERT(value);
65
1/1
✓ Branch 1 taken 182 times.
364 return value.get();
66 }
67
68 6 double GlareSensor_Impl::psiRotationAroundXAxis() const {
69
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<double> value = getDouble(OS_Glare_SensorFields::PsiRotationAroundXAxis, true);
70
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 4 not taken.
6 OS_ASSERT(value);
71
1/1
✓ Branch 1 taken 6 times.
12 return value.get();
72 }
73
74 ✗ bool GlareSensor_Impl::isPsiRotationAroundXAxisDefaulted() const {
75 ✗ return isEmpty(OS_Glare_SensorFields::PsiRotationAroundXAxis);
76 }
77
78 6 double GlareSensor_Impl::thetaRotationAroundYAxis() const {
79
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<double> value = getDouble(OS_Glare_SensorFields::ThetaRotationAroundYAxis, true);
80
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 4 not taken.
6 OS_ASSERT(value);
81
1/1
✓ Branch 1 taken 6 times.
12 return value.get();
82 }
83
84 ✗ bool GlareSensor_Impl::isThetaRotationAroundYAxisDefaulted() const {
85 ✗ return isEmpty(OS_Glare_SensorFields::ThetaRotationAroundYAxis);
86 }
87
88 6 double GlareSensor_Impl::phiRotationAroundZAxis() const {
89
1/1
✓ Branch 1 taken 6 times.
6 boost::optional<double> value = getDouble(OS_Glare_SensorFields::PhiRotationAroundZAxis, true);
90
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 4 not taken.
6 OS_ASSERT(value);
91
1/1
✓ Branch 1 taken 6 times.
12 return value.get();
92 }
93
94 ✗ bool GlareSensor_Impl::isPhiRotationAroundZAxisDefaulted() const {
95 ✗ return isEmpty(OS_Glare_SensorFields::PhiRotationAroundZAxis);
96 }
97
98 2 int GlareSensor_Impl::numberofGlareViewVectors() const {
99
1/1
✓ Branch 1 taken 2 times.
2 boost::optional<int> value = getInt(OS_Glare_SensorFields::NumberofGlareViewVectors, true);
100
1/3
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
2 OS_ASSERT(value);
101
1/1
✓ Branch 1 taken 2 times.
4 return value.get();
102 }
103
104 ✗ boost::optional<double> GlareSensor_Impl::maximumAllowableDaylightGlareProbability() const {
105 ✗ return getDouble(OS_Glare_SensorFields::MaximumAllowableDaylightGlareProbability, true);
106 }
107
108 168 bool GlareSensor_Impl::setPositionXCoordinate(double positionXCoordinate) {
109 168 bool result = setDouble(OS_Glare_SensorFields::PositionXCoordinate, positionXCoordinate);
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 OS_ASSERT(result);
111 168 return result;
112 }
113
114 168 bool GlareSensor_Impl::setPositionYCoordinate(double positionYCoordinate) {
115 168 bool result = setDouble(OS_Glare_SensorFields::PositionYCoordinate, positionYCoordinate);
116
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 OS_ASSERT(result);
117 168 return result;
118 }
119
120 168 bool GlareSensor_Impl::setPositionZCoordinate(double positionZCoordinate) {
121 168 bool result = setDouble(OS_Glare_SensorFields::PositionZCoordinate, positionZCoordinate);
122
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 OS_ASSERT(result);
123 168 return result;
124 }
125
126 ✗ bool GlareSensor_Impl::setPsiRotationAroundXAxis(double psiRotationAroundXAxis) {
127 ✗ bool result = setDouble(OS_Glare_SensorFields::PsiRotationAroundXAxis, psiRotationAroundXAxis);
128 ✗ OS_ASSERT(result);
129 ✗ return result;
130 }
131
132 ✗ void GlareSensor_Impl::resetPsiRotationAroundXAxis() {
133 ✗ bool result = setString(OS_Glare_SensorFields::PsiRotationAroundXAxis, "");
134 ✗ OS_ASSERT(result);
135 ✗ }
136
137 ✗ bool GlareSensor_Impl::setThetaRotationAroundYAxis(double thetaRotationAroundYAxis) {
138 ✗ bool result = setDouble(OS_Glare_SensorFields::ThetaRotationAroundYAxis, thetaRotationAroundYAxis);
139 ✗ OS_ASSERT(result);
140 ✗ return result;
141 }
142
143 ✗ void GlareSensor_Impl::resetThetaRotationAroundYAxis() {
144 ✗ bool result = setString(OS_Glare_SensorFields::ThetaRotationAroundYAxis, "");
145 ✗ OS_ASSERT(result);
146 ✗ }
147
148 ✗ bool GlareSensor_Impl::setPhiRotationAroundZAxis(double phiRotationAroundZAxis) {
149 ✗ bool result = setDouble(OS_Glare_SensorFields::PhiRotationAroundZAxis, phiRotationAroundZAxis);
150 ✗ OS_ASSERT(result);
151 ✗ return result;
152 }
153
154 ✗ void GlareSensor_Impl::resetPhiRotationAroundZAxis() {
155 ✗ bool result = setString(OS_Glare_SensorFields::PhiRotationAroundZAxis, "");
156 ✗ OS_ASSERT(result);
157 ✗ }
158
159 ✗ bool GlareSensor_Impl::setNumberofGlareViewVectors(int numberofGlareViewVectors) {
160 ✗ bool result = setInt(OS_Glare_SensorFields::NumberofGlareViewVectors, numberofGlareViewVectors);
161 ✗ return result;
162 }
163
164 ✗ void GlareSensor_Impl::resetNumberofGlareViewVectors() {
165 ✗ bool result = setString(OS_Glare_SensorFields::NumberofGlareViewVectors, "");
166 ✗ OS_ASSERT(result);
167 ✗ }
168
169 ✗ bool GlareSensor_Impl::setMaximumAllowableDaylightGlareProbability(boost::optional<double> maximumAllowableDaylightGlareProbability) {
170 ✗ bool result = false;
171 ✗ if (maximumAllowableDaylightGlareProbability) {
172 ✗ result = setDouble(OS_Glare_SensorFields::MaximumAllowableDaylightGlareProbability, maximumAllowableDaylightGlareProbability.get());
173 } else {
174 ✗ result = setString(OS_Glare_SensorFields::MaximumAllowableDaylightGlareProbability, "");
175 }
176 ✗ return result;
177 }
178
179 ✗ void GlareSensor_Impl::resetMaximumAllowableDaylightGlareProbability() {
180 ✗ bool result = setString(OS_Glare_SensorFields::MaximumAllowableDaylightGlareProbability, "");
181 ✗ OS_ASSERT(result);
182 ✗ }
183
184 176 Point3d GlareSensor_Impl::position() const {
185 176 Point3d result(this->positionXCoordinate(), this->positionYCoordinate(), this->positionZCoordinate());
186 176 return result;
187 }
188
189 168 bool GlareSensor_Impl::setPosition(const Point3d& position) {
190 168 this->setPositionXCoordinate(position.x());
191 168 this->setPositionYCoordinate(position.y());
192 168 this->setPositionZCoordinate(position.z());
193 168 return true;
194 }
195
196 6 openstudio::Transformation GlareSensor_Impl::transformation() const {
197
4/4
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
6 Vector3d origin(this->positionXCoordinate(), this->positionYCoordinate(), this->positionZCoordinate());
198
199 EulerAngles angles(degToRad(this->psiRotationAroundXAxis()), degToRad(this->thetaRotationAroundYAxis()),
200
7/7
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 6 times.
✓ Branch 13 taken 6 times.
✓ Branch 16 taken 6 times.
✓ Branch 19 taken 6 times.
6 degToRad(this->phiRotationAroundZAxis()));
201
202
3/3
✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 6 times.
6 Transformation result = Transformation::translation(origin) * Transformation::rotation(angles);
203
204 12 return result;
205 6 }
206
207 ✗ bool GlareSensor_Impl::setTransformation(const openstudio::Transformation& transformation) {
208 ✗ Vector3d translation = transformation.translation();
209 ✗ this->setPositionXCoordinate(translation.x());
210 ✗ this->setPositionYCoordinate(translation.y());
211 ✗ this->setPositionZCoordinate(translation.z());
212
213 ✗ EulerAngles eulerAngles = transformation.eulerAngles();
214 ✗ setPsiRotationAroundXAxis(radToDeg(eulerAngles.psi()));
215 ✗ setThetaRotationAroundYAxis(radToDeg(eulerAngles.theta()));
216 ✗ setPhiRotationAroundZAxis(radToDeg(eulerAngles.phi()));
217
218 ✗ return true;
219 ✗ }
220
221 ✗ bool GlareSensor_Impl::aimAt(const Point3d& target) {
222 ✗ Point3d position = this->position();
223 ✗ Vector3d vector = target - position;
224
225 ✗ if (!vector.normalize()) {
226 ✗ return false;
227 }
228
229 ✗ Vector3d yAxis(0, 1, 0);
230 ✗ Vector3d rotationAxis = yAxis.cross(vector);
231
232 ✗ if (!rotationAxis.normalize()) {
233 ✗ return false;
234 }
235
236 ✗ double angle = getAngle(yAxis, vector);
237 ✗ Transformation transformation = Transformation::rotation(rotationAxis, angle);
238 ✗ EulerAngles eulerAngles = transformation.eulerAngles();
239
240 ✗ this->setPsiRotationAroundXAxis(eulerAngles.psi());
241 ✗ this->setThetaRotationAroundYAxis(eulerAngles.theta());
242 ✗ this->setPhiRotationAroundZAxis(eulerAngles.phi());
243
244 ✗ return true;
245 ✗ }
246
247 //bool GlareSensor_Impl::isPrimaryGlareSensor() const
248 //{
249 // bool result = false;
250 // std::vector<WorkspaceObject> workspaceObjects = this->getSources(IddObjectType::OS_ThermalZone);
251 // if (!workspaceObjects.empty()){
252 // OS_ASSERT(workspaceObjects.size() == 1);
253 // boost::optional<GlareSensor> control = workspaceObjects[0].cast<ThermalZone>().primaryGlareSensor();
254 // if (control){
255 // result = (this->handle() == control->handle());
256 // }
257 // }
258 // return result;
259 //}
260 //
261 //bool GlareSensor_Impl::isSecondaryGlareSensor() const
262 //{
263 // bool result = false;
264 // std::vector<WorkspaceObject> workspaceObjects = this->getSources(IddObjectType::OS_ThermalZone);
265 // if (!workspaceObjects.empty()){
266 // OS_ASSERT(workspaceObjects.size() == 1);
267 // boost::optional<GlareSensor> control = workspaceObjects[0].cast<ThermalZone>().secondaryGlareSensor();
268 // if (control){
269 // result = (this->handle() == control->handle());
270 // }
271 // }
272 // return result; }
273
274 184 int GlareSensor_Impl::spaceIndex() const {
275 184 return OS_Glare_SensorFields::SpaceName;
276 }
277
278 } // namespace detail
279
280 169 GlareSensor::GlareSensor(const Model& model) : SpaceItem(GlareSensor::iddObjectType(), model) {
281
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 169 times.
✗ Branch 5 not taken.
169 OS_ASSERT(getImpl<detail::GlareSensor_Impl>());
282 169 }
283
284 48707 IddObjectType GlareSensor::iddObjectType() {
285
1/1
✓ Branch 1 taken 48707 times.
48707 return {IddObjectType::OS_Glare_Sensor};
286 }
287
288 ✗ double GlareSensor::positionXCoordinate() const {
289 ✗ return getImpl<detail::GlareSensor_Impl>()->positionXCoordinate();
290 }
291
292 ✗ double GlareSensor::positionYCoordinate() const {
293 ✗ return getImpl<detail::GlareSensor_Impl>()->positionYCoordinate();
294 }
295
296 ✗ double GlareSensor::positionZCoordinate() const {
297 ✗ return getImpl<detail::GlareSensor_Impl>()->positionZCoordinate();
298 }
299
300 ✗ double GlareSensor::psiRotationAroundXAxis() const {
301 ✗ return getImpl<detail::GlareSensor_Impl>()->psiRotationAroundXAxis();
302 }
303
304 ✗ bool GlareSensor::isPsiRotationAroundXAxisDefaulted() const {
305 ✗ return getImpl<detail::GlareSensor_Impl>()->isPsiRotationAroundXAxisDefaulted();
306 }
307
308 ✗ double GlareSensor::thetaRotationAroundYAxis() const {
309 ✗ return getImpl<detail::GlareSensor_Impl>()->thetaRotationAroundYAxis();
310 }
311
312 ✗ bool GlareSensor::isThetaRotationAroundYAxisDefaulted() const {
313 ✗ return getImpl<detail::GlareSensor_Impl>()->isThetaRotationAroundYAxisDefaulted();
314 }
315
316 ✗ double GlareSensor::phiRotationAroundZAxis() const {
317 ✗ return getImpl<detail::GlareSensor_Impl>()->phiRotationAroundZAxis();
318 }
319
320 ✗ bool GlareSensor::isPhiRotationAroundZAxisDefaulted() const {
321 ✗ return getImpl<detail::GlareSensor_Impl>()->isPhiRotationAroundZAxisDefaulted();
322 }
323
324 2 int GlareSensor::numberofGlareViewVectors() const {
325
1/1
✓ Branch 3 taken 2 times.
2 return getImpl<detail::GlareSensor_Impl>()->numberofGlareViewVectors();
326 }
327
328 ✗ boost::optional<double> GlareSensor::maximumAllowableDaylightGlareProbability() const {
329 ✗ return getImpl<detail::GlareSensor_Impl>()->maximumAllowableDaylightGlareProbability();
330 }
331
332 ✗ bool GlareSensor::setPositionXCoordinate(double positionXCoordinate) {
333 ✗ return getImpl<detail::GlareSensor_Impl>()->setPositionXCoordinate(positionXCoordinate);
334 }
335
336 ✗ bool GlareSensor::setPositionYCoordinate(double positionYCoordinate) {
337 ✗ return getImpl<detail::GlareSensor_Impl>()->setPositionYCoordinate(positionYCoordinate);
338 }
339
340 ✗ bool GlareSensor::setPositionZCoordinate(double positionZCoordinate) {
341 ✗ return getImpl<detail::GlareSensor_Impl>()->setPositionZCoordinate(positionZCoordinate);
342 }
343
344 ✗ bool GlareSensor::setPsiRotationAroundXAxis(double psiRotationAroundXAxis) {
345 ✗ return getImpl<detail::GlareSensor_Impl>()->setPsiRotationAroundXAxis(psiRotationAroundXAxis);
346 }
347
348 ✗ void GlareSensor::resetPsiRotationAroundXAxis() {
349 ✗ getImpl<detail::GlareSensor_Impl>()->resetPsiRotationAroundXAxis();
350 ✗ }
351
352 ✗ bool GlareSensor::setThetaRotationAroundYAxis(double thetaRotationAroundYAxis) {
353 ✗ return getImpl<detail::GlareSensor_Impl>()->setThetaRotationAroundYAxis(thetaRotationAroundYAxis);
354 }
355
356 ✗ void GlareSensor::resetThetaRotationAroundYAxis() {
357 ✗ getImpl<detail::GlareSensor_Impl>()->resetThetaRotationAroundYAxis();
358 ✗ }
359
360 ✗ bool GlareSensor::setPhiRotationAroundZAxis(double phiRotationAroundZAxis) {
361 ✗ return getImpl<detail::GlareSensor_Impl>()->setPhiRotationAroundZAxis(phiRotationAroundZAxis);
362 }
363
364 ✗ void GlareSensor::resetPhiRotationAroundZAxis() {
365 ✗ getImpl<detail::GlareSensor_Impl>()->resetPhiRotationAroundZAxis();
366 ✗ }
367
368 ✗ bool GlareSensor::setNumberofGlareViewVectors(int numberofGlareViewVectors) {
369 ✗ return getImpl<detail::GlareSensor_Impl>()->setNumberofGlareViewVectors(numberofGlareViewVectors);
370 }
371
372 ✗ void GlareSensor::resetNumberofGlareViewVectors() {
373 ✗ getImpl<detail::GlareSensor_Impl>()->resetNumberofGlareViewVectors();
374 ✗ }
375
376 ✗ bool GlareSensor::setMaximumAllowableDaylightGlareProbability(double maximumAllowableDaylightGlareProbability) {
377 ✗ return getImpl<detail::GlareSensor_Impl>()->setMaximumAllowableDaylightGlareProbability(maximumAllowableDaylightGlareProbability);
378 }
379
380 ✗ void GlareSensor::resetMaximumAllowableDaylightGlareProbability() {
381 ✗ getImpl<detail::GlareSensor_Impl>()->resetMaximumAllowableDaylightGlareProbability();
382 ✗ }
383
384 176 Point3d GlareSensor::position() const {
385
1/1
✓ Branch 3 taken 176 times.
176 return getImpl<detail::GlareSensor_Impl>()->position();
386 }
387
388 168 bool GlareSensor::setPosition(const Point3d& position) {
389
1/1
✓ Branch 3 taken 168 times.
168 return getImpl<detail::GlareSensor_Impl>()->setPosition(position);
390 }
391
392 6 openstudio::Transformation GlareSensor::transformation() const {
393
1/1
✓ Branch 3 taken 6 times.
6 return getImpl<detail::GlareSensor_Impl>()->transformation();
394 }
395
396 ✗ bool GlareSensor::setTransformation(const openstudio::Transformation& transformation) {
397 ✗ return getImpl<detail::GlareSensor_Impl>()->setTransformation(transformation);
398 }
399
400 ✗ bool GlareSensor::aimAt(const Point3d& target) {
401 ✗ return getImpl<detail::GlareSensor_Impl>()->aimAt(target);
402 }
403
404 /// @cond
405
1/1
✓ Branch 3 taken 239 times.
239 GlareSensor::GlareSensor(std::shared_ptr<detail::GlareSensor_Impl> impl) : SpaceItem(std::move(impl)) {}
406 /// @endcond
407
408 } // namespace model
409 } // namespace openstudio
410