src/energyplus/ReverseTranslator/ReverseTranslateWindowShadingControl.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 "../ReverseTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/ShadingControl.hpp" | ||
| 9 | #include "../../model/ShadingControl_Impl.hpp" | ||
| 10 | #include "../../model/Construction.hpp" | ||
| 11 | #include "../../model/Construction_Impl.hpp" | ||
| 12 | #include "../../model/Schedule.hpp" | ||
| 13 | #include "../../model/Schedule_Impl.hpp" | ||
| 14 | #include "../../model/ShadingMaterial.hpp" | ||
| 15 | #include "../../model/ShadingMaterial_Impl.hpp" | ||
| 16 | #include "../../model/SubSurface.hpp" | ||
| 17 | #include "../../model/SubSurface_Impl.hpp" | ||
| 18 | |||
| 19 | #include "../../utilities/idf/WorkspaceExtensibleGroup.hpp" | ||
| 20 | |||
| 21 | #include <utilities/idd/WindowShadingControl_FieldEnums.hxx> | ||
| 22 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 23 | #include <utilities/idd/IddEnums.hxx> | ||
| 24 | |||
| 25 | #include "../../utilities/core/Assert.hpp" | ||
| 26 | |||
| 27 | using namespace openstudio::model; | ||
| 28 | |||
| 29 | namespace openstudio { | ||
| 30 | namespace energyplus { | ||
| 31 | |||
| 32 | 2 | boost::optional<ModelObject> ReverseTranslator::translateWindowShadingControl(const WorkspaceObject& workspaceObject) { | |
| 33 |
4/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 2 times.
|
2 | if (workspaceObject.iddObject().type() != IddObjectType::WindowShadingControl) { |
| 34 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: WindowShadingControl"); | |
| 35 | ✗ | return boost::none; | |
| 36 | } | ||
| 37 | |||
| 38 | 2 | OptionalWorkspaceObject target; | |
| 39 | |||
| 40 | 2 | boost::optional<Construction> construction; | |
| 41 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
4 | if ((target = workspaceObject.getTarget(WindowShadingControlFields::ConstructionwithShadingName))) { |
| 42 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target); |
| 43 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (modelObject) { |
| 44 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
4 | if (modelObject->optionalCast<Construction>()) { |
| 45 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | construction = modelObject->cast<Construction>(); |
| 46 | } | ||
| 47 | } | ||
| 48 | 2 | } | |
| 49 | |||
| 50 | 2 | boost::optional<ShadingMaterial> shadingMaterial; | |
| 51 |
2/3✓ Branch 1 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
|
4 | if ((target = workspaceObject.getTarget(WindowShadingControlFields::ShadingDeviceMaterialName))) { |
| 52 | ✗ | OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target); | |
| 53 | ✗ | if (modelObject) { | |
| 54 | ✗ | if (modelObject->optionalCast<ShadingMaterial>()) { | |
| 55 | ✗ | shadingMaterial = modelObject->cast<ShadingMaterial>(); | |
| 56 | } | ||
| 57 | } | ||
| 58 | ✗ | } | |
| 59 | |||
| 60 | 2 | boost::optional<ShadingControl> shadingControl; | |
| 61 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (construction) { |
| 62 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | shadingControl = openstudio::model::ShadingControl(*construction); |
| 63 | ✗ | } else if (shadingMaterial) { | |
| 64 | ✗ | shadingControl = openstudio::model::ShadingControl(*shadingMaterial); | |
| 65 | } else { | ||
| 66 | ✗ | LOG(Error, workspaceObject.briefDescription() << " does not appear to have a valid Construction or Shading Material Name attached to it"); | |
| 67 | ✗ | return boost::none; | |
| 68 | } | ||
| 69 | |||
| 70 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (shadingControl) { |
| 71 | |||
| 72 | 2 | OptionalString s; | |
| 73 | 2 | OptionalDouble d; | |
| 74 | |||
| 75 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.name(); |
| 76 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 77 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | shadingControl->setName(*s); |
| 78 | } | ||
| 79 | |||
| 80 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(WindowShadingControlFields::ShadingType); |
| 81 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 82 |
4/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
|
6 | if (istringEqual("InteriorBlind", *s)) { |
| 83 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
6 | shadingControl->setShadingType("InteriorDaylightRedirectionDevice"); |
| 84 | } else { | ||
| 85 | ✗ | shadingControl->setShadingType(*s); | |
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(WindowShadingControlFields::ShadingControlType); |
| 90 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 91 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | shadingControl->setShadingControlType(*s); |
| 92 | } | ||
| 93 | |||
| 94 |
2/3✓ Branch 1 taken 2 times.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
4 | if ((target = workspaceObject.getTarget(WindowShadingControlFields::ScheduleName))) { |
| 95 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target); |
| 96 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (modelObject) { |
| 97 |
3/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
4 | if (modelObject->optionalCast<Schedule>()) { |
| 98 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | shadingControl->setSchedule(modelObject->cast<Schedule>()); |
| 99 | } | ||
| 100 | } | ||
| 101 | 2 | } | |
| 102 | |||
| 103 |
1/1✓ Branch 1 taken 2 times.
|
2 | d = workspaceObject.getDouble(WindowShadingControlFields::Setpoint); |
| 104 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 105 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | shadingControl->setSetpoint(*d); |
| 106 | } | ||
| 107 | |||
| 108 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(WindowShadingControlFields::GlareControlIsActive); |
| 109 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 110 |
4/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
|
4 | if (istringEqual(*s, "Yes")) { |
| 111 | ✗ | shadingControl->setGlareControlIsActive(true); | |
| 112 |
4/5✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
|
4 | } else if (istringEqual(*s, "No")) { |
| 113 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | shadingControl->setGlareControlIsActive(false); |
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(WindowShadingControlFields::TypeofSlatAngleControlforBlinds); |
| 118 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 119 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | shadingControl->setTypeofSlatAngleControlforBlinds(*s); |
| 120 | } | ||
| 121 | |||
| 122 |
2/3✓ Branch 1 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
|
4 | if ((target = workspaceObject.getTarget(WindowShadingControlFields::SlatAngleScheduleName))) { |
| 123 | ✗ | OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target); | |
| 124 | ✗ | if (modelObject) { | |
| 125 | ✗ | if (modelObject->optionalCast<Schedule>()) { | |
| 126 | ✗ | shadingControl->setSlatAngleSchedule(modelObject->cast<Schedule>()); | |
| 127 | } | ||
| 128 | } | ||
| 129 | ✗ | } | |
| 130 | |||
| 131 |
1/1✓ Branch 1 taken 2 times.
|
2 | d = workspaceObject.getDouble(WindowShadingControlFields::Setpoint2); |
| 132 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 133 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | shadingControl->setSetpoint2(*d); |
| 134 | } | ||
| 135 | |||
| 136 |
1/1✓ Branch 1 taken 2 times.
|
2 | s = workspaceObject.getString(WindowShadingControlFields::MultipleSurfaceControlType); |
| 137 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (s) { |
| 138 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | shadingControl->setMultipleSurfaceControlType(*s); |
| 139 | } | ||
| 140 | |||
| 141 | // get extensible groups for sub surfaces | ||
| 142 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 2 times.
|
4 | for (const IdfExtensibleGroup& idfGroup : workspaceObject.extensibleGroups()) { |
| 143 |
1/1✓ Branch 1 taken 2 times.
|
2 | auto workspaceGroup = idfGroup.cast<WorkspaceExtensibleGroup>(); |
| 144 |
1/1✓ Branch 1 taken 2 times.
|
2 | OptionalWorkspaceObject target = workspaceGroup.getTarget(WindowShadingControlExtensibleFields::FenestrationSurfaceName); |
| 145 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | OptionalModelObject modelObject = translateAndMapWorkspaceObject(*target); |
| 146 | |||
| 147 | // add the sub surface | ||
| 148 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
✓ Branch 10 taken 2 times.
|
2 | shadingControl->addSubSurface(modelObject->cast<SubSurface>()); |
| 149 | 4 | } | |
| 150 | |||
| 151 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | return shadingControl.get(); |
| 152 | 2 | } else { | |
| 153 | ✗ | LOG(Error, "Unknown error translating " << workspaceObject.briefDescription()); | |
| 154 | |||
| 155 | ✗ | return boost::none; | |
| 156 | } | ||
| 157 | 2 | } | |
| 158 | |||
| 159 | } // namespace energyplus | ||
| 160 | } // namespace openstudio | ||
| 161 |