src/model/EnergyManagementSystemSensor.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 "EnergyManagementSystemSensor.hpp" | ||
| 7 | #include "EnergyManagementSystemSensor_Impl.hpp" | ||
| 8 | |||
| 9 | #include "OutputVariable.hpp" | ||
| 10 | #include "OutputVariable_Impl.hpp" | ||
| 11 | #include "OutputMeter.hpp" | ||
| 12 | #include "OutputMeter_Impl.hpp" | ||
| 13 | |||
| 14 | #include "Model.hpp" | ||
| 15 | |||
| 16 | #include <utilities/idd/IddEnums.hxx> | ||
| 17 | #include <utilities/idd/OS_EnergyManagementSystem_Sensor_FieldEnums.hxx> | ||
| 18 | |||
| 19 | #include "../utilities/core/Assert.hpp" | ||
| 20 | #include "../utilities/core/UUID.hpp" | ||
| 21 | |||
| 22 | namespace openstudio { | ||
| 23 | namespace model { | ||
| 24 | |||
| 25 | namespace detail { | ||
| 26 | |||
| 27 | 70 | EnergyManagementSystemSensor_Impl::EnergyManagementSystemSensor_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 28 | 70 | : ModelObject_Impl(idfObject, model, keepHandle) { | |
| 29 |
4/6✓ Branch 1 taken 70 times.
✓ Branch 4 taken 70 times.
✓ Branch 7 taken 70 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 70 times.
✗ Branch 13 not taken.
|
70 | OS_ASSERT(idfObject.iddObject().type() == EnergyManagementSystemSensor::iddObjectType()); |
| 30 | 70 | } | |
| 31 | |||
| 32 | 28 | EnergyManagementSystemSensor_Impl::EnergyManagementSystemSensor_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, | |
| 33 | 28 | bool keepHandle) | |
| 34 | 28 | : ModelObject_Impl(other, model, keepHandle) { | |
| 35 |
4/6✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 13 not taken.
|
28 | OS_ASSERT(other.iddObject().type() == EnergyManagementSystemSensor::iddObjectType()); |
| 36 | 28 | } | |
| 37 | |||
| 38 | 18 | EnergyManagementSystemSensor_Impl::EnergyManagementSystemSensor_Impl(const EnergyManagementSystemSensor_Impl& other, Model_Impl* model, | |
| 39 | 18 | bool keepHandle) | |
| 40 | 18 | : ModelObject_Impl(other, model, keepHandle) {} | |
| 41 | |||
| 42 | ✗ | const std::vector<std::string>& EnergyManagementSystemSensor_Impl::outputVariableNames() const { | |
| 43 | ✗ | static const std::vector<std::string> result; | |
| 44 | ✗ | return result; | |
| 45 | } | ||
| 46 | |||
| 47 | 7 | IddObjectType EnergyManagementSystemSensor_Impl::iddObjectType() const { | |
| 48 | 7 | return EnergyManagementSystemSensor::iddObjectType(); | |
| 49 | } | ||
| 50 | |||
| 51 | 26 | std::string EnergyManagementSystemSensor_Impl::keyName() const { | |
| 52 |
1/1✓ Branch 1 taken 26 times.
|
26 | OptionalString results = getString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterIndexKeyName, true); |
| 53 |
1/2✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 | if (results) { |
| 54 |
2/2✓ Branch 1 taken 26 times.
✓ Branch 4 taken 26 times.
|
26 | return results.get(); |
| 55 | } | ||
| 56 | ✗ | return ""; | |
| 57 | 26 | } | |
| 58 | |||
| 59 | 35 | boost::optional<OutputVariable> EnergyManagementSystemSensor_Impl::outputVariable() const { | |
| 60 |
1/1✓ Branch 1 taken 35 times.
|
35 | boost::optional<OutputVariable> value = optionalOutputVariable(); |
| 61 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 29 times.
|
35 | if (!value.is_initialized()) { |
| 62 |
5/5✓ 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.
|
6 | LOG(Info, " does not have an Output Variable attached."); |
| 63 | 6 | return value; | |
| 64 | } | ||
| 65 |
2/2✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
|
29 | return value.get(); |
| 66 | 35 | } | |
| 67 | |||
| 68 | 12 | boost::optional<OutputMeter> EnergyManagementSystemSensor_Impl::outputMeter() const { | |
| 69 |
1/1✓ Branch 1 taken 12 times.
|
12 | boost::optional<OutputMeter> value = optionalOutputMeter(); |
| 70 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 7 times.
|
12 | if (!value.is_initialized()) { |
| 71 |
5/5✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
|
5 | LOG(Info, " does not have an Output Meter attached."); |
| 72 | 5 | return value; | |
| 73 | } | ||
| 74 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
|
7 | return value.get(); |
| 75 | 12 | } | |
| 76 | |||
| 77 | 3 | std::string EnergyManagementSystemSensor_Impl::outputVariableOrMeterName() const { | |
| 78 |
1/1✓ Branch 1 taken 3 times.
|
3 | OptionalString results = getString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, true); |
| 79 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (results) { |
| 80 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | return results.get(); |
| 81 | } | ||
| 82 | ✗ | return ""; | |
| 83 | 3 | } | |
| 84 | |||
| 85 | 17 | bool EnergyManagementSystemSensor_Impl::setKeyName(const std::string& keyName) { | |
| 86 | 17 | bool result = setString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterIndexKeyName, keyName); | |
| 87 | 17 | return result; | |
| 88 | } | ||
| 89 | |||
| 90 | 34 | bool EnergyManagementSystemSensor_Impl::setOutputVariable(const OutputVariable& outputVariable) { | |
| 91 | //bool result = setPointer(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, outputVariable.handle()); | ||
| 92 |
3/3✓ Branch 1 taken 34 times.
✓ Branch 4 taken 34 times.
✓ Branch 7 taken 34 times.
|
34 | bool result = setString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, toString(outputVariable.handle())); |
| 93 | 34 | return result; | |
| 94 | } | ||
| 95 | |||
| 96 | 4 | bool EnergyManagementSystemSensor_Impl::setOutputMeter(const OutputMeter& outputMeter) { | |
| 97 | //bool result = setPointer(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, outputMeter.handle()); | ||
| 98 |
3/3✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
|
4 | bool result = setString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, toString(outputMeter.handle())); |
| 99 | 4 | return result; | |
| 100 | } | ||
| 101 | |||
| 102 | ✗ | bool EnergyManagementSystemSensor_Impl::setOutputVariableOrMeterName(const std::string& outputVariableOrMeterName) { | |
| 103 | //bool result = setPointer(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, outputMeter.handle()); | ||
| 104 | ✗ | bool result = setString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, outputVariableOrMeterName); | |
| 105 | ✗ | return result; | |
| 106 | } | ||
| 107 | |||
| 108 | 35 | boost::optional<OutputVariable> EnergyManagementSystemSensor_Impl::optionalOutputVariable() const { | |
| 109 | //Note: Cant do /object-list implementation since Auto Naming of Objects causes issues. | ||
| 110 | // Instead, doing an /alpha getString implementation | ||
| 111 | //return getObject<ModelObject>().getModelObjectTarget<OutputVariable>(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName); | ||
| 112 |
1/1✓ Branch 1 taken 35 times.
|
35 | boost::optional<std::string> handle = getString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName); |
| 113 |
1/1✓ Branch 1 taken 35 times.
|
35 | const Model m = this->model(); |
| 114 |
1/2✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
|
35 | if (handle) { |
| 115 |
2/2✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
|
35 | UUID uid = toUUID(handle.get()); |
| 116 |
1/1✓ Branch 1 taken 35 times.
|
35 | boost::optional<ModelObject> object = m.getModelObject<model::ModelObject>(uid); |
| 117 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 2 times.
|
35 | if (object) { |
| 118 |
4/4✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
✓ Branch 7 taken 29 times.
✓ Branch 8 taken 4 times.
|
66 | if (object->optionalCast<OutputVariable>()) { |
| 119 |
3/3✓ Branch 1 taken 29 times.
✓ Branch 4 taken 29 times.
✓ Branch 7 taken 29 times.
|
29 | return object->cast<OutputVariable>(); |
| 120 | } | ||
| 121 | } | ||
| 122 | 35 | } | |
| 123 | 6 | return boost::none; | |
| 124 | 35 | } | |
| 125 | |||
| 126 | 12 | boost::optional<OutputMeter> EnergyManagementSystemSensor_Impl::optionalOutputMeter() const { | |
| 127 | //Note: Cant do /object-list implementation since Auto Naming of Objects causes issues. | ||
| 128 | // Instead, doing an /alpha getString implementation | ||
| 129 | //return getObject<ModelObject>().getModelObjectTarget<OutputMeter>(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName); | ||
| 130 |
1/1✓ Branch 1 taken 12 times.
|
12 | boost::optional<std::string> handle = getString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName); |
| 131 |
1/1✓ Branch 1 taken 12 times.
|
12 | const Model m = this->model(); |
| 132 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (handle) { |
| 133 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | UUID uid = toUUID(handle.get()); |
| 134 |
1/1✓ Branch 1 taken 12 times.
|
12 | boost::optional<ModelObject> object = m.getModelObject<model::ModelObject>(uid); |
| 135 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | if (object) { |
| 136 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 7 taken 7 times.
✓ Branch 8 taken 3 times.
|
20 | if (object->optionalCast<OutputMeter>()) { |
| 137 |
3/3✓ Branch 1 taken 7 times.
✓ Branch 4 taken 7 times.
✓ Branch 7 taken 7 times.
|
7 | return object->cast<OutputMeter>(); |
| 138 | } | ||
| 139 | } | ||
| 140 | 12 | } | |
| 141 | 5 | return boost::none; | |
| 142 | 12 | } | |
| 143 | |||
| 144 | } // namespace detail | ||
| 145 | |||
| 146 | 26 | EnergyManagementSystemSensor::EnergyManagementSystemSensor(const Model& model, const OutputVariable& outvar) | |
| 147 | 26 | : ModelObject(EnergyManagementSystemSensor::iddObjectType(), model) { | |
| 148 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 26 times.
✗ Branch 5 not taken.
|
26 | OS_ASSERT(getImpl<detail::EnergyManagementSystemSensor_Impl>()); |
| 149 |
1/1✓ Branch 1 taken 26 times.
|
26 | bool ok = setOutputVariable(outvar); |
| 150 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 26 times.
|
26 | if (!ok) { |
| 151 | ✗ | remove(); | |
| 152 | ✗ | LOG_AND_THROW("Unable to set " << briefDescription() << "'s OutputVariable to " << outvar.briefDescription() << "."); | |
| 153 | } | ||
| 154 |
3/3✓ Branch 1 taken 26 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 25 times.
|
26 | if (!outvar.isKeyValueDefaulted()) { |
| 155 |
1/1✓ Branch 1 taken 1 time.
|
1 | std::string key = outvar.keyValue(); |
| 156 |
1/1✓ Branch 1 taken 1 time.
|
1 | setKeyName(key); |
| 157 | 1 | } | |
| 158 | 26 | } | |
| 159 | |||
| 160 | 3 | EnergyManagementSystemSensor::EnergyManagementSystemSensor(const Model& model, const OutputMeter& outvar) | |
| 161 | 3 | : ModelObject(EnergyManagementSystemSensor::iddObjectType(), model) { | |
| 162 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 5 not taken.
|
3 | OS_ASSERT(getImpl<detail::EnergyManagementSystemSensor_Impl>()); |
| 163 |
1/1✓ Branch 1 taken 3 times.
|
3 | bool ok = setOutputMeter(outvar); |
| 164 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!ok) { |
| 165 | ✗ | remove(); | |
| 166 | ✗ | LOG_AND_THROW("Unable to set " << briefDescription() << "'s OutputVariable to " << outvar.briefDescription() << "."); | |
| 167 | } | ||
| 168 | 3 | } | |
| 169 | |||
| 170 | 4 | EnergyManagementSystemSensor::EnergyManagementSystemSensor(const Model& model, const std::string& outputVariableOrMeterName) | |
| 171 | 4 | : ModelObject(EnergyManagementSystemSensor::iddObjectType(), model) { | |
| 172 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 5 not taken.
|
4 | OS_ASSERT(getImpl<detail::EnergyManagementSystemSensor_Impl>()); |
| 173 |
1/1✓ Branch 1 taken 4 times.
|
4 | bool ok = setString(OS_EnergyManagementSystem_SensorFields::OutputVariableorOutputMeterName, outputVariableOrMeterName); |
| 174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!ok) { |
| 175 | ✗ | remove(); | |
| 176 | ✗ | LOG_AND_THROW("Unable to set " << briefDescription() << "'s OutputVariableOrMeterName to " << outputVariableOrMeterName << "."); | |
| 177 | } | ||
| 178 | 4 | } | |
| 179 | |||
| 180 | 9 | EnergyManagementSystemSensor::EnergyManagementSystemSensor(const Model& model) : ModelObject(EnergyManagementSystemSensor::iddObjectType(), model) { | |
| 181 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✗ Branch 5 not taken.
|
9 | OS_ASSERT(getImpl<detail::EnergyManagementSystemSensor_Impl>()); |
| 182 | //TODO setOutputVariable() on a default OutputVariable | ||
| 183 | 9 | } | |
| 184 | |||
| 185 | 7885 | IddObjectType EnergyManagementSystemSensor::iddObjectType() { | |
| 186 |
1/1✓ Branch 1 taken 7885 times.
|
7885 | return {IddObjectType::OS_EnergyManagementSystem_Sensor}; |
| 187 | } | ||
| 188 | |||
| 189 | 26 | std::string EnergyManagementSystemSensor::keyName() const { | |
| 190 |
1/1✓ Branch 3 taken 26 times.
|
26 | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->keyName(); |
| 191 | } | ||
| 192 | |||
| 193 | 35 | boost::optional<OutputVariable> EnergyManagementSystemSensor::outputVariable() const { | |
| 194 |
1/1✓ Branch 3 taken 35 times.
|
35 | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->outputVariable(); |
| 195 | } | ||
| 196 | |||
| 197 | 12 | boost::optional<OutputMeter> EnergyManagementSystemSensor::outputMeter() const { | |
| 198 |
1/1✓ Branch 3 taken 12 times.
|
12 | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->outputMeter(); |
| 199 | } | ||
| 200 | |||
| 201 | 3 | std::string EnergyManagementSystemSensor::outputVariableOrMeterName() const { | |
| 202 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->outputVariableOrMeterName(); |
| 203 | } | ||
| 204 | |||
| 205 | 17 | bool EnergyManagementSystemSensor::setKeyName(const std::string& keyName) { | |
| 206 |
1/1✓ Branch 3 taken 17 times.
|
17 | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->setKeyName(keyName); |
| 207 | } | ||
| 208 | |||
| 209 | 34 | bool EnergyManagementSystemSensor::setOutputVariable(const OutputVariable& outputVariable) { | |
| 210 |
1/1✓ Branch 3 taken 34 times.
|
34 | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->setOutputVariable(outputVariable); |
| 211 | } | ||
| 212 | |||
| 213 | 4 | bool EnergyManagementSystemSensor::setOutputMeter(const OutputMeter& outputMeter) { | |
| 214 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->setOutputMeter(outputMeter); |
| 215 | } | ||
| 216 | |||
| 217 | ✗ | bool EnergyManagementSystemSensor::setOutputVariableOrMeterName(const std::string& outputVariableOrMeterName) { | |
| 218 | ✗ | return getImpl<detail::EnergyManagementSystemSensor_Impl>()->setOutputVariableOrMeterName(outputVariableOrMeterName); | |
| 219 | } | ||
| 220 | |||
| 221 | /// @cond | ||
| 222 | 37 | EnergyManagementSystemSensor::EnergyManagementSystemSensor(std::shared_ptr<detail::EnergyManagementSystemSensor_Impl> impl) | |
| 223 |
1/1✓ Branch 3 taken 37 times.
|
37 | : ModelObject(std::move(impl)) {} |
| 224 | /// @endcond | ||
| 225 | |||
| 226 | } // namespace model | ||
| 227 | } // namespace openstudio | ||
| 228 |