-
Notifications
You must be signed in to change notification settings - Fork 193
/
ShadingControl.cpp
853 lines (705 loc) · 35.9 KB
/
ShadingControl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) 2008-2023, Alliance for Sustainable Energy, LLC, and other contributors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
* derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works
* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior
* written permission from Alliance for Sustainable Energy, LLC.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************************************************************/
#include "ShadingControl.hpp"
#include "ShadingControl_Impl.hpp"
#include "Construction.hpp"
#include "Construction_Impl.hpp"
#include "ShadingMaterial.hpp"
#include "ShadingMaterial_Impl.hpp"
#include "Blind.hpp"
#include "Blind_Impl.hpp"
#include "DaylightRedirectionDevice.hpp"
#include "DaylightRedirectionDevice_Impl.hpp"
#include "Screen.hpp"
#include "Screen_Impl.hpp"
#include "Shade.hpp"
#include "Shade_Impl.hpp"
#include "Schedule.hpp"
#include "Schedule_Impl.hpp"
#include "SubSurface.hpp"
#include "SubSurface_Impl.hpp"
#include "Model.hpp"
#include "Model_Impl.hpp"
#include "ModelExtensibleGroup.hpp"
#include "../utilities/idf/WorkspaceExtensibleGroup.hpp"
#include <utilities/idd/IddFactory.hxx>
#include <utilities/idd/OS_ShadingControl_FieldEnums.hxx>
#include <utilities/idd/IddEnums.hxx>
#include "../utilities/core/Assert.hpp"
#include "utilities/core/Compare.hpp"
#include <algorithm>
#include <array>
#include <string_view>
namespace openstudio {
namespace model {
namespace detail {
ShadingControl_Impl::ShadingControl_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle)
: ResourceObject_Impl(idfObject, model, keepHandle) {
OS_ASSERT(idfObject.iddObject().type() == ShadingControl::iddObjectType());
}
ShadingControl_Impl::ShadingControl_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle)
: ResourceObject_Impl(other, model, keepHandle) {
OS_ASSERT(other.iddObject().type() == ShadingControl::iddObjectType());
}
ShadingControl_Impl::ShadingControl_Impl(const ShadingControl_Impl& other, Model_Impl* model, bool keepHandle)
: ResourceObject_Impl(other, model, keepHandle) {}
const std::vector<std::string>& ShadingControl_Impl::outputVariableNames() const {
static const std::vector<std::string> result;
return result;
}
bool ShadingControl_Impl::isControlTypeValueNeedingSetpoint1(const std::string& controlType) {
static constexpr std::array data{
//"AlwaysOn",
//"AlwaysOff",
//"OnIfScheduleAllows",
"OnIfHighSolarOnWindow", "OnIfHighHorizontalSolar", "OnIfHighOutdoorAirTemperature", "OnIfHighZoneAirTemperature", "OnIfHighZoneCooling",
//"OnIfHighGlare",
//"MeetDaylightIlluminanceSetpoint",
"OnNightIfLowOutdoorTempAndOffDay", "OnNightIfLowInsideTempAndOffDay", "OnNightIfHeatingAndOffDay",
"OnNightIfLowOutdoorTempAndOnDayIfCooling", "OnNightIfHeatingAndOnDayIfCooling", "OffNightAndOnDayIfCoolingAndHighSolarOnWindow",
"OnNightAndOnDayIfCoolingAndHighSolarOnWindow", "OnIfHighOutdoorAirTempAndHighSolarOnWindow", "OnIfHighOutdoorAirTempAndHighHorizontalSolar",
"OnIfHighZoneAirTempAndHighSolarOnWindow", "OnIfHighZoneAirTempAndHighHorizontalSolar"};
return std::find_if(data.begin(), data.end(), [&controlType](auto c) { return openstudio::istringEqual(controlType, c); }) != data.end();
}
bool ShadingControl_Impl::isControlTypeValueNeedingSetpoint2(const std::string& controlType) {
static constexpr std::array data{"OnIfHighOutdoorAirTempAndHighSolarOnWindow", "OnIfHighOutdoorAirTempAndHighHorizontalSolar",
"OnIfHighZoneAirTempAndHighSolarOnWindow", "OnIfHighZoneAirTempAndHighHorizontalSolar"};
return std::find_if(data.begin(), data.end(), [&controlType](auto c) { return openstudio::istringEqual(controlType, c); }) != data.end();
}
bool ShadingControl_Impl::isControlTypeValueAllowingSchedule(const std::string& controlType) {
static constexpr std::array data{//"AlwaysOn",
//"AlwaysOff",
"OnIfScheduleAllows", "OnIfHighSolarOnWindow", "OnIfHighHorizontalSolar", "OnIfHighOutdoorAirTemperature",
"OnIfHighZoneAirTemperature", "OnIfHighZoneCooling",
//"OnIfHighGlare",
//"MeetDaylightIlluminanceSetpoint",
"OnNightIfLowOutdoorTempAndOffDay", "OnNightIfLowInsideTempAndOffDay", "OnNightIfHeatingAndOffDay",
"OnNightIfLowOutdoorTempAndOnDayIfCooling", "OnNightIfHeatingAndOnDayIfCooling",
"OffNightAndOnDayIfCoolingAndHighSolarOnWindow", "OnNightAndOnDayIfCoolingAndHighSolarOnWindow",
"OnIfHighOutdoorAirTempAndHighSolarOnWindow", "OnIfHighOutdoorAirTempAndHighHorizontalSolar",
"OnIfHighZoneAirTempAndHighSolarOnWindow", "OnIfHighZoneAirTempAndHighHorizontalSolar"};
return std::find_if(data.begin(), data.end(), [&controlType](auto c) { return openstudio::istringEqual(controlType, c); }) != data.end();
}
bool ShadingControl_Impl::isControlTypeValueRequiringSchedule(const std::string& controlType) {
return openstudio::istringEqual("OnIfScheduleAllows", controlType);
}
bool ShadingControl_Impl::isTypeValueAllowingSlatAngleControl(const std::string& type) {
static constexpr std::array data{
//"InteriorShade",
//"ExteriorShade",
//"ExteriorScreen",
"InteriorBlind", "ExteriorBlind",
//"BetweenGlassShade",
"BetweenGlassBlind",
//"SwitchableGlazing",
//"InteriorDaylightRedirectionDevice"
};
return std::find_if(data.begin(), data.end(), [&type](auto c) { return openstudio::istringEqual(type, c); }) != data.end();
}
IddObjectType ShadingControl_Impl::iddObjectType() const {
return ShadingControl::iddObjectType();
}
ModelObject ShadingControl_Impl::clone(Model model) const {
auto scClone = ResourceObject_Impl::clone(model).cast<ShadingControl>();
if (model != this->model()) {
scClone.removeAllSubSurfaces();
}
return std::move(scClone);
}
std::string ShadingControl_Impl::shadingType() const {
boost::optional<std::string> result = getString(OS_ShadingControlFields::ShadingType, true);
OS_ASSERT(result);
return result.get();
}
boost::optional<Construction> ShadingControl_Impl::construction() const {
return getObject<ShadingControl>().getModelObjectTarget<Construction>(OS_ShadingControlFields::ConstructionwithShadingName);
}
boost::optional<ShadingMaterial> ShadingControl_Impl::shadingMaterial() const {
return getObject<ShadingControl>().getModelObjectTarget<ShadingMaterial>(OS_ShadingControlFields::ShadingDeviceMaterialName);
}
std::string ShadingControl_Impl::shadingControlType() const {
boost::optional<std::string> result = getString(OS_ShadingControlFields::ShadingControlType, true);
OS_ASSERT(result);
return result.get();
}
bool ShadingControl_Impl::isShadingControlTypeDefaulted() const {
return isEmpty(OS_ShadingControlFields::ShadingControlType);
}
boost::optional<Schedule> ShadingControl_Impl::schedule() const {
return getObject<ShadingControl>().getModelObjectTarget<Schedule>(OS_ShadingControlFields::ScheduleName);
}
boost::optional<double> ShadingControl_Impl::setpoint() const {
boost::optional<double> result = getDouble(OS_ShadingControlFields::Setpoint);
if (!result) {
std::string shadingControlType = this->shadingControlType();
if (istringEqual("OnIfHighSolarOnWindow", shadingControlType)) {
result = 27; // w/m^2
}
}
return result;
}
bool ShadingControl_Impl::isSetpointDefaulted() const {
return isEmpty(OS_ShadingControlFields::Setpoint);
}
bool ShadingControl_Impl::glareControlIsActive() const {
boost::optional<std::string> value = getString(OS_ShadingControlFields::GlareControlIsActive, true);
OS_ASSERT(value);
return openstudio::istringEqual(value.get(), "Yes");
}
std::string ShadingControl_Impl::typeofSlatAngleControlforBlinds() const {
boost::optional<std::string> result = getString(OS_ShadingControlFields::TypeofSlatAngleControlforBlinds, true);
OS_ASSERT(result);
return result.get();
}
bool ShadingControl_Impl::isTypeofSlatAngleControlforBlindsDefaulted() const {
return isEmpty(OS_ShadingControlFields::TypeofSlatAngleControlforBlinds);
}
boost::optional<Schedule> ShadingControl_Impl::slatAngleSchedule() const {
return getObject<ShadingControl>().getModelObjectTarget<Schedule>(OS_ShadingControlFields::SlatAngleScheduleName);
}
boost::optional<double> ShadingControl_Impl::setpoint2() const {
boost::optional<double> result = getDouble(OS_ShadingControlFields::Setpoint2);
if (!result) {
std::string shadingControlType = this->shadingControlType();
if (istringEqual("OnIfHighSolarOnWindow", shadingControlType)) {
result = 27; // w/m^2
}
}
return result;
}
std::string ShadingControl_Impl::multipleSurfaceControlType() const {
boost::optional<std::string> result = getString(OS_ShadingControlFields::MultipleSurfaceControlType, true);
OS_ASSERT(result);
return result.get();
}
bool ShadingControl_Impl::setShadingType(const std::string& shadingType) {
return setString(OS_ShadingControlFields::ShadingType, shadingType);
}
bool ShadingControl_Impl::setShadingControlType(const std::string& shadingControlType) {
std::string oldControlType = this->shadingControlType();
bool result = setString(OS_ShadingControlFields::ShadingControlType, shadingControlType);
if (result) {
if (!ShadingControl_Impl::isControlTypeValueNeedingSetpoint1(shadingControlType)) {
// Not calling reset to avoid double check on whether it's required
// resetSetpoint();
LOG(Info,
briefDescription() << " Shading Control Type was changed to '" << shadingControlType << " which does not require a Setpoint, reseting");
bool test = setString(OS_ShadingControlFields::Setpoint, "");
OS_ASSERT(test);
}
if (!ShadingControl_Impl::isControlTypeValueNeedingSetpoint2(shadingControlType)) {
// Not calling reset to avoid double check on whether it's required
// resetSetpoint2();
LOG(Info, briefDescription() << " Shading Control Type was changed to '" << shadingControlType
<< " which does not require a Setpoint2, reseting");
bool test = setString(OS_ShadingControlFields::Setpoint2, "");
OS_ASSERT(test);
}
if (!ShadingControl_Impl::isControlTypeValueAllowingSchedule(shadingControlType)) {
LOG(Info,
briefDescription() << " Shading Control Type was changed to '" << shadingControlType << " which does not allow a Schedule, reseting");
bool test = setString(OS_ShadingControlFields::ScheduleName, "");
OS_ASSERT(test);
test = setString(OS_ShadingControlFields::ShadingControlIsScheduled, "No");
OS_ASSERT(test);
}
// TODO: do we want to force remove this stuff like it did resetSetpoint before? Units/quantity might be oranges and apples when switching
// types, but they could be compatible, and it may be very confusing at least for interface users that are playing with a dropdown to see
// schedulesand setpoints disapear
if (!openstudio::istringEqual(oldControlType, shadingControlType)) {
resetSetpoint(); // For backward compatibility
// resetSetpoint2();
// resetSchedule();
}
}
return result;
}
void ShadingControl_Impl::resetShadingControlType() {
std::string oldControlType = this->shadingControlType();
bool test = setString(OS_ShadingControlFields::ShadingControlType, "");
OS_ASSERT(test);
if (!openstudio::istringEqual("OnIfHighSolarOnWindow", oldControlType)) {
resetSetpoint();
}
}
bool ShadingControl_Impl::setSchedule(const Schedule& schedule) {
bool result = false;
std::string shadingControlType = this->shadingControlType();
if (ShadingControl_Impl::isControlTypeValueAllowingSchedule(shadingControlType)) {
result = setPointer(OS_ShadingControlFields::ScheduleName, schedule.handle());
if (result) {
bool test = setString(OS_ShadingControlFields::ShadingControlIsScheduled, "Yes");
OS_ASSERT(test);
}
} else {
LOG(Warn, briefDescription() << " has a Shading Control Type '" << shadingControlType << "' which does not allow a Schedule");
}
return result;
}
void ShadingControl_Impl::resetSchedule() {
std::string shadingControlType = this->shadingControlType();
if (ShadingControl_Impl::isControlTypeValueRequiringSchedule(shadingControlType)) {
LOG(Warn, briefDescription() << " has a Shading Control Type '" << shadingControlType << "' which does require a Schedule, not resetting it");
} else {
bool test = setString(OS_ShadingControlFields::ScheduleName, "");
OS_ASSERT(test);
test = setString(OS_ShadingControlFields::ShadingControlIsScheduled, "No");
OS_ASSERT(test);
}
}
bool ShadingControl_Impl::setSetpoint(double setpoint) {
bool result = false;
std::string shadingControlType = this->shadingControlType();
if (ShadingControl_Impl::isControlTypeValueNeedingSetpoint1(shadingControlType)) {
result = setDouble(OS_ShadingControlFields::Setpoint, setpoint);
} else {
LOG(Warn, briefDescription() << " has a Shading Control Type '" << shadingControlType << "' which does not require a Setpoint");
}
return result;
}
void ShadingControl_Impl::resetSetpoint() {
std::string shadingControlType = this->shadingControlType();
if (ShadingControl_Impl::isControlTypeValueNeedingSetpoint1(shadingControlType)
&& !openstudio::istringEqual("OnIfHighSolarOnWindow", shadingControlType)) {
LOG(Warn, briefDescription() << " has a Shading Control Type '" << shadingControlType << "' which does require a Setpoint, not resetting it");
} else {
bool test = setString(OS_ShadingControlFields::Setpoint, "");
OS_ASSERT(test);
}
}
bool ShadingControl_Impl::setGlareControlIsActive(bool glareControlIsActive) {
bool result = false;
if (glareControlIsActive) {
result = setString(OS_ShadingControlFields::GlareControlIsActive, "Yes");
} else {
result = setString(OS_ShadingControlFields::GlareControlIsActive, "No");
}
OS_ASSERT(result);
return result;
}
void ShadingControl_Impl::resetGlareControlIsActive() {
bool result = setString(OS_ShadingControlFields::GlareControlIsActive, "");
OS_ASSERT(result);
}
bool ShadingControl_Impl::setTypeofSlatAngleControlforBlinds(const std::string& typeofSlatAngleControlforBlinds) {
bool result = false;
std::string shadingType = this->shadingType();
if (ShadingControl_Impl::isTypeValueAllowingSlatAngleControl(shadingType)) {
result = setString(OS_ShadingControlFields::TypeofSlatAngleControlforBlinds, typeofSlatAngleControlforBlinds);
}
return result;
}
void ShadingControl_Impl::resetTypeofSlatAngleControlforBlinds() {
bool result = setString(OS_ShadingControlFields::TypeofSlatAngleControlforBlinds, "");
OS_ASSERT(result);
}
bool ShadingControl_Impl::setSlatAngleSchedule(const Schedule& slatAngleSchedule) {
bool result = false;
std::string shadingType = this->shadingType();
if (ShadingControl_Impl::isTypeValueAllowingSlatAngleControl(shadingType)) {
result = setPointer(OS_ShadingControlFields::SlatAngleScheduleName, slatAngleSchedule.handle());
if (result) {
bool test = setString(OS_ShadingControlFields::TypeofSlatAngleControlforBlinds, "ScheduledSlatAngle");
OS_ASSERT(test);
}
} else {
LOG(Warn, briefDescription() << " has a Shading Type '" << shadingType << "' which does not allow a Slat Angle Schedule");
}
return result;
}
void ShadingControl_Impl::resetSlatAngleSchedule() {
bool result = false;
result = setString(OS_ShadingControlFields::SlatAngleScheduleName, "");
OS_ASSERT(result);
result = setString(OS_ShadingControlFields::TypeofSlatAngleControlforBlinds, "");
OS_ASSERT(result);
}
bool ShadingControl_Impl::setSetpoint2(double setpoint2) {
bool result = false;
std::string shadingControlType = this->shadingControlType();
if (ShadingControl_Impl::isControlTypeValueNeedingSetpoint2(shadingControlType)) {
result = setDouble(OS_ShadingControlFields::Setpoint2, setpoint2);
} else {
LOG(Warn, briefDescription() << " has a Shading Control Type '" << shadingControlType << "' which does not require a Setpoint2");
}
return result;
}
void ShadingControl_Impl::resetSetpoint2() {
std::string shadingControlType = this->shadingControlType();
if (ShadingControl_Impl::isControlTypeValueNeedingSetpoint1(shadingControlType)) {
LOG(Warn,
briefDescription() << " has a Shading Control Type '" << shadingControlType << "' which does require a Setpoint2, not resetting it");
} else {
bool test = setString(OS_ShadingControlFields::Setpoint2, "");
OS_ASSERT(test);
}
}
bool ShadingControl_Impl::setMultipleSurfaceControlType(const std::string& multipleSurfaceControlType) {
return setString(OS_ShadingControlFields::MultipleSurfaceControlType, multipleSurfaceControlType);
}
unsigned int ShadingControl_Impl::numberofSubSurfaces() const {
return numExtensibleGroups();
}
std::vector<SubSurface> ShadingControl_Impl::subSurfaces() const {
std::vector<SubSurface> result;
auto groups = extensibleGroups();
for (const auto& group : groups) {
boost::optional<WorkspaceObject> wo = group.cast<WorkspaceExtensibleGroup>().getTarget(OS_ShadingControlExtensibleFields::SubSurfaceName);
if (wo) {
if (auto subsurface = wo->optionalCast<SubSurface>()) {
result.push_back(subsurface.get());
}
}
}
return result;
}
boost::optional<unsigned> ShadingControl_Impl::subSurfaceIndex(const SubSurface& subSurface) const {
boost::optional<unsigned> result;
auto egs = castVector<WorkspaceExtensibleGroup>(extensibleGroups());
auto h = openstudio::toString(subSurface.handle());
auto it = std::find_if(egs.begin(), egs.end(), [&](const WorkspaceExtensibleGroup& eg) {
return (eg.getField(OS_ShadingControlExtensibleFields::SubSurfaceName).get() == h);
});
// If found, we compute the index by using std::distance between the start of vector and the iterator returned by std::find_if
if (it != egs.end()) {
result = std::distance(egs.begin(), it) + 1;
}
return result;
}
bool ShadingControl_Impl::addSubSurface(const SubSurface& subSurface) {
// Check if subSurface already exists
boost::optional<unsigned> _existingIndex = subSurfaceIndex(subSurface);
if (_existingIndex) {
LOG(Warn, "For " << briefDescription() << ", SubSurface already exists.");
return true;
}
bool result;
auto eg = getObject<ModelObject>().pushExtensibleGroup().cast<WorkspaceExtensibleGroup>();
bool subsurface = eg.setPointer(OS_ShadingControlExtensibleFields::SubSurfaceName, subSurface.handle());
if (subsurface) {
result = true;
} else {
// Something went wrong
// So erase the new extensible group
getObject<ModelObject>().eraseExtensibleGroup(eg.groupIndex());
result = false;
}
return result;
}
bool ShadingControl_Impl::setSubSurfaceIndex(const SubSurface& subSurface, unsigned index) {
boost::optional<unsigned> idx = subSurfaceIndex(subSurface);
if (!idx) {
LOG(Warn,
"For " << briefDescription() << " cannot set the index of SubSurface " << subSurface.nameString() << " since it is not part of it.");
return false;
}
// TODO: we could just set via string instead of doing a ton of typechecking below...
std::vector<SubSurface> subSurfaceVector = subSurfaces();
if (index > subSurfaceVector.size()) {
LOG(Warn, "Requested a subSurface index of " << index << " to be assigned to " << subSurface.nameString() << ", but " << briefDescription()
<< " only has " << subSurfaceVector.size() << " SubSurfaces, resetting to that.");
index = subSurfaceVector.size();
} else if (index < 1) {
LOG(Warn, "Requested a subSurface index of " << index << " < 1 to be assigned to " << subSurface.briefDescription() << ", resetting to 1");
index = 1;
}
subSurfaceVector.erase(subSurfaceVector.begin() + idx.get() - 1); // subSurfaceIndex is 1-indexed, and vector is 0-indexed
subSurfaceVector.insert(subSurfaceVector.begin() + (index - 1), subSurface);
return setSubSurfaces(subSurfaceVector);
}
bool ShadingControl_Impl::addSubSurface(const SubSurface& subSurface, unsigned index) {
bool ok = addSubSurface(subSurface);
if (!ok) {
return false;
}
ok = setSubSurfaceIndex(subSurface, index);
return ok;
}
bool ShadingControl_Impl::removeSubSurface(const SubSurface& subSurface) {
boost::optional<unsigned> idx = subSurfaceIndex(subSurface);
if (!idx) {
LOG(Warn, "For " << briefDescription() << " cannot remove SubSurface " << subSurface.nameString() << " since it is not part of it.");
return false;
}
return removeSubSurface(idx.get());
}
bool ShadingControl_Impl::removeSubSurface(unsigned index) {
bool result = false;
if ((index > 0) && (index <= numberofSubSurfaces())) {
getObject<ModelObject>().eraseExtensibleGroup(index - 1);
result = true;
}
return result;
}
bool ShadingControl_Impl::addSubSurfaces(const std::vector<SubSurface>& subSurfaces) {
bool ok = true;
for (const SubSurface& subSurface : subSurfaces) {
ok &= addSubSurface(subSurface);
}
return ok;
}
void ShadingControl_Impl::removeAllSubSurfaces() {
clearExtensibleGroups();
}
bool ShadingControl_Impl::setSubSurfaces(const std::vector<SubSurface>& subSurfaces) {
removeAllSubSurfaces();
return addSubSurfaces(subSurfaces);
}
} // namespace detail
ShadingControl::ShadingControl(const Construction& construction) : ResourceObject(ShadingControl::iddObjectType(), construction.model()) {
OS_ASSERT(getImpl<detail::ShadingControl_Impl>());
std::vector<Material> layers = construction.layers();
std::string type;
// check layers from inside out
int i = layers.size() - 1;
for (; i >= 0; --i) {
if (layers[i].optionalCast<Shade>()) {
type = "Shade";
LOG(Warn, "ShadingMaterial detected in shaded construction, prefer to use the ShadingControl constructor from ShadingMaterial.");
break;
} else if (layers[i].optionalCast<Blind>()) {
type = "Blind";
LOG(Warn, "ShadingMaterial detected in shaded construction, prefer to use the ShadingControl constructor from ShadingMaterial.");
break;
} else if (layers[i].optionalCast<Screen>()) {
type = "Screen";
setShadingControlType("AlwaysOn");
LOG(Warn, "ShadingMaterial detected in shaded construction, prefer to use the ShadingControl constructor from ShadingMaterial.");
break;
} else if (layers[i].optionalCast<DaylightRedirectionDevice>()) {
type = "DaylightRedirectionDevice";
setShadingControlType("AlwaysOn");
LOG(Warn, "ShadingMaterial detected in shaded construction, prefer to use the ShadingControl constructor from ShadingMaterial.");
break;
}
}
std::string position;
if (i == int(layers.size()) - 1) {
position = "Interior";
} else if (i == 0) {
position = "Exterior";
} else {
position = "BetweenGlass";
}
if (type.empty()) {
type = "SwitchableGlazing";
position = "";
}
if (type == "Screen" && position != "Exterior") {
this->remove();
LOG_AND_THROW(position << type << " is not an allowable configuration for ShadingControl");
}
if (type == "DaylightRedirectionDevice" && position != "Interior") {
this->remove();
LOG_AND_THROW(position << type << " is not an allowable configuration for ShadingControl");
}
bool test = this->setShadingType(position + type);
OS_ASSERT(test);
test = setMultipleSurfaceControlType("Sequential"); // E+ IDD Default
OS_ASSERT(test);
test = this->setPointer(OS_ShadingControlFields::ConstructionwithShadingName, construction.handle());
OS_ASSERT(test);
}
ShadingControl::ShadingControl(const ShadingMaterial& shadingMaterial) : ResourceObject(ShadingControl::iddObjectType(), shadingMaterial.model()) {
OS_ASSERT(getImpl<detail::ShadingControl_Impl>());
std::string type;
if (shadingMaterial.optionalCast<Shade>()) {
type = "InteriorShade";
} else if (shadingMaterial.optionalCast<Blind>()) {
type = "InteriorBlind";
} else if (shadingMaterial.optionalCast<Screen>()) {
type = "ExteriorScreen";
setShadingControlType("AlwaysOn");
} else if (shadingMaterial.optionalCast<DaylightRedirectionDevice>()) {
type = "InteriorDaylightRedirectionDevice";
setShadingControlType("AlwaysOn");
}
bool test = this->setShadingType(type);
OS_ASSERT(test);
test = setMultipleSurfaceControlType("Sequential"); // E+ IDD Default
OS_ASSERT(test);
test = this->setPointer(OS_ShadingControlFields::ShadingDeviceMaterialName, shadingMaterial.handle());
OS_ASSERT(test);
}
IddObjectType ShadingControl::iddObjectType() {
return {IddObjectType::OS_ShadingControl};
}
std::vector<std::string> ShadingControl::shadingTypeValues() {
return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_ShadingControlFields::ShadingType);
}
std::vector<std::string> ShadingControl::shadingControlTypeValues() {
return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_ShadingControlFields::ShadingControlType);
}
std::vector<std::string> ShadingControl::typeofSlatAngleControlforBlindsValues() {
return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_ShadingControlFields::TypeofSlatAngleControlforBlinds);
}
std::vector<std::string> ShadingControl::multipleSurfaceControlTypeValues() {
return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_ShadingControlFields::MultipleSurfaceControlType);
}
bool ShadingControl::isControlTypeValueNeedingSetpoint1() {
return getImpl<detail::ShadingControl_Impl>()->isControlTypeValueNeedingSetpoint1(this->shadingControlType());
}
bool ShadingControl::isControlTypeValueNeedingSetpoint2() {
return getImpl<detail::ShadingControl_Impl>()->isControlTypeValueNeedingSetpoint2(this->shadingControlType());
}
bool ShadingControl::isControlTypeValueAllowingSchedule() {
return getImpl<detail::ShadingControl_Impl>()->isControlTypeValueAllowingSchedule(this->shadingControlType());
}
bool ShadingControl::isControlTypeValueRequiringSchedule() {
return getImpl<detail::ShadingControl_Impl>()->isControlTypeValueRequiringSchedule(this->shadingControlType());
}
bool ShadingControl::isTypeValueAllowingSlatAngleControl() {
return getImpl<detail::ShadingControl_Impl>()->isTypeValueAllowingSlatAngleControl(this->shadingType());
}
std::string ShadingControl::shadingType() const {
return getImpl<detail::ShadingControl_Impl>()->shadingType();
}
boost::optional<Construction> ShadingControl::construction() const {
return getImpl<detail::ShadingControl_Impl>()->construction();
}
boost::optional<ShadingMaterial> ShadingControl::shadingMaterial() const {
return getImpl<detail::ShadingControl_Impl>()->shadingMaterial();
}
std::string ShadingControl::shadingControlType() const {
return getImpl<detail::ShadingControl_Impl>()->shadingControlType();
}
bool ShadingControl::isShadingControlTypeDefaulted() const {
return getImpl<detail::ShadingControl_Impl>()->isShadingControlTypeDefaulted();
}
boost::optional<Schedule> ShadingControl::schedule() const {
return getImpl<detail::ShadingControl_Impl>()->schedule();
}
boost::optional<double> ShadingControl::setpoint() const {
return getImpl<detail::ShadingControl_Impl>()->setpoint();
}
bool ShadingControl::isSetpointDefaulted() const {
return getImpl<detail::ShadingControl_Impl>()->isSetpointDefaulted();
}
bool ShadingControl::glareControlIsActive() const {
return getImpl<detail::ShadingControl_Impl>()->glareControlIsActive();
}
std::string ShadingControl::typeofSlatAngleControlforBlinds() const {
return getImpl<detail::ShadingControl_Impl>()->typeofSlatAngleControlforBlinds();
}
bool ShadingControl::isTypeofSlatAngleControlforBlindsDefaulted() const {
return getImpl<detail::ShadingControl_Impl>()->isTypeofSlatAngleControlforBlindsDefaulted();
}
boost::optional<Schedule> ShadingControl::slatAngleSchedule() const {
return getImpl<detail::ShadingControl_Impl>()->slatAngleSchedule();
}
boost::optional<double> ShadingControl::setpoint2() const {
return getImpl<detail::ShadingControl_Impl>()->setpoint2();
}
std::string ShadingControl::multipleSurfaceControlType() const {
return getImpl<detail::ShadingControl_Impl>()->multipleSurfaceControlType();
}
bool ShadingControl::setShadingType(const std::string& shadingType) {
return getImpl<detail::ShadingControl_Impl>()->setShadingType(shadingType);
}
bool ShadingControl::setShadingControlType(const std::string& shadingControlType) {
return getImpl<detail::ShadingControl_Impl>()->setShadingControlType(shadingControlType);
}
void ShadingControl::resetShadingControlType() {
return getImpl<detail::ShadingControl_Impl>()->resetShadingControlType();
}
bool ShadingControl::setSchedule(const Schedule& schedule) {
return getImpl<detail::ShadingControl_Impl>()->setSchedule(schedule);
}
void ShadingControl::resetSchedule() {
getImpl<detail::ShadingControl_Impl>()->resetSchedule();
}
bool ShadingControl::setSetpoint(double setpoint) {
return getImpl<detail::ShadingControl_Impl>()->setSetpoint(setpoint);
}
void ShadingControl::resetSetpoint() {
getImpl<detail::ShadingControl_Impl>()->resetSetpoint();
}
bool ShadingControl::setGlareControlIsActive(bool glareControlIsActive) {
return getImpl<detail::ShadingControl_Impl>()->setGlareControlIsActive(glareControlIsActive);
}
void ShadingControl::resetGlareControlIsActive() {
getImpl<detail::ShadingControl_Impl>()->resetGlareControlIsActive();
}
bool ShadingControl::setTypeofSlatAngleControlforBlinds(const std::string& typeofSlatAngleControlforBlinds) {
return getImpl<detail::ShadingControl_Impl>()->setTypeofSlatAngleControlforBlinds(typeofSlatAngleControlforBlinds);
}
void ShadingControl::resetTypeofSlatAngleControlforBlinds() {
getImpl<detail::ShadingControl_Impl>()->resetTypeofSlatAngleControlforBlinds();
}
bool ShadingControl::setSlatAngleSchedule(const Schedule& slatAngleSchedule) {
return getImpl<detail::ShadingControl_Impl>()->setSlatAngleSchedule(slatAngleSchedule);
}
void ShadingControl::resetSlatAngleSchedule() {
getImpl<detail::ShadingControl_Impl>()->resetSlatAngleSchedule();
}
bool ShadingControl::setSetpoint2(double setpoint2) {
return getImpl<detail::ShadingControl_Impl>()->setSetpoint2(setpoint2);
}
bool ShadingControl::setMultipleSurfaceControlType(const std::string& multipleSurfaceControlType) {
return getImpl<detail::ShadingControl_Impl>()->setMultipleSurfaceControlType(multipleSurfaceControlType);
}
// Extensible Fields
std::vector<SubSurface> ShadingControl::subSurfaces() const {
return getImpl<detail::ShadingControl_Impl>()->subSurfaces();
}
unsigned int ShadingControl::numberofSubSurfaces() const {
return getImpl<detail::ShadingControl_Impl>()->numberofSubSurfaces();
}
boost::optional<unsigned> ShadingControl::subSurfaceIndex(const SubSurface& subSurface) const {
return getImpl<detail::ShadingControl_Impl>()->subSurfaceIndex(subSurface);
}
bool ShadingControl::addSubSurface(const SubSurface& subSurface) {
return getImpl<detail::ShadingControl_Impl>()->addSubSurface(subSurface);
}
bool ShadingControl::addSubSurface(const SubSurface& subSurface, unsigned index) {
return getImpl<detail::ShadingControl_Impl>()->addSubSurface(subSurface, index);
}
bool ShadingControl::setSubSurfaceIndex(const SubSurface& subSurface, unsigned index) {
return getImpl<detail::ShadingControl_Impl>()->setSubSurfaceIndex(subSurface, index);
}
bool ShadingControl::removeSubSurface(unsigned index) {
return getImpl<detail::ShadingControl_Impl>()->removeSubSurface(index);
}
bool ShadingControl::removeSubSurface(const SubSurface& subSurface) {
return getImpl<detail::ShadingControl_Impl>()->removeSubSurface(subSurface);
}
bool ShadingControl::addSubSurfaces(const std::vector<SubSurface>& subSurfaces) {
return getImpl<detail::ShadingControl_Impl>()->addSubSurfaces(subSurfaces);
}
bool ShadingControl::setSubSurfaces(const std::vector<SubSurface>& subSurfaces) {
return getImpl<detail::ShadingControl_Impl>()->setSubSurfaces(subSurfaces);
}
void ShadingControl::removeAllSubSurfaces() {
getImpl<detail::ShadingControl_Impl>()->removeAllSubSurfaces();
}
/// @cond
ShadingControl::ShadingControl(std::shared_ptr<detail::ShadingControl_Impl> impl) : ResourceObject(std::move(impl)) {}
/// @endcond
} // namespace model
} // namespace openstudio