src/model/ModelObject.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 "ModelObject.hpp" | ||
| 7 | #include "ModelObject_Impl.hpp" | ||
| 8 | #include "Model_Impl.hpp" | ||
| 9 | #include "Component.hpp" | ||
| 10 | #include "LifeCycleCost.hpp" | ||
| 11 | #include "LifeCycleCost_Impl.hpp" | ||
| 12 | #include "ParentObject.hpp" | ||
| 13 | #include "ResourceObject.hpp" | ||
| 14 | #include "ResourceObject_Impl.hpp" | ||
| 15 | #include "Connection.hpp" | ||
| 16 | #include "Connection_Impl.hpp" | ||
| 17 | #include "CoilCoolingDXTwoStageWithHumidityControlMode.hpp" | ||
| 18 | #include "CoilCoolingDXTwoStageWithHumidityControlMode_Impl.hpp" | ||
| 19 | #include "CoilPerformanceDXCooling.hpp" | ||
| 20 | #include "CoilPerformanceDXCooling_Impl.hpp" | ||
| 21 | #include "AdditionalProperties.hpp" | ||
| 22 | #include "AdditionalProperties_Impl.hpp" | ||
| 23 | |||
| 24 | #include "ScheduleTypeRegistry.hpp" | ||
| 25 | #include "Schedule.hpp" | ||
| 26 | #include "Schedule_Impl.hpp" | ||
| 27 | #include "ScheduleTypeLimits.hpp" | ||
| 28 | |||
| 29 | #include "OutputVariable.hpp" | ||
| 30 | #include "OutputVariable_Impl.hpp" | ||
| 31 | |||
| 32 | #include "../utilities/core/Assert.hpp" | ||
| 33 | #include "../utilities/core/ContainersMove.hpp" | ||
| 34 | #include "../utilities/sql/SqlFileEnums.hpp" | ||
| 35 | #include "../utilities/sql/SqlFileTimeSeriesQuery.hpp" | ||
| 36 | #include "../utilities/sql/SqlFile.hpp" | ||
| 37 | #include "../utilities/idf/ValidityReport.hpp" | ||
| 38 | |||
| 39 | #include <utilities/idd/OS_Output_Variable_FieldEnums.hxx> | ||
| 40 | #include "../utilities/data/TimeSeries.hpp" | ||
| 41 | |||
| 42 | #include <boost/algorithm/string.hpp> | ||
| 43 | #include <fmt/core.h> | ||
| 44 | |||
| 45 | using openstudio::Handle; | ||
| 46 | using openstudio::HandleVector; | ||
| 47 | using openstudio::WorkspaceObject; | ||
| 48 | using openstudio::OptionalWorkspaceObject; | ||
| 49 | using openstudio::WorkspaceObjectVector; | ||
| 50 | using openstudio::Workspace; | ||
| 51 | |||
| 52 | using std::vector; | ||
| 53 | |||
| 54 | namespace openstudio { | ||
| 55 | namespace model { | ||
| 56 | namespace detail { | ||
| 57 | |||
| 58 | 69669 | ModelObject_Impl::ModelObject_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 59 | 69669 | : WorkspaceObject_Impl(other, model, keepHandle) {} | |
| 60 | |||
| 61 | 99870 | ModelObject_Impl::ModelObject_Impl(const ModelObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 62 | 99870 | : WorkspaceObject_Impl(other, model, keepHandle) {} | |
| 63 | |||
| 64 | // GETTERS | ||
| 65 | |||
| 66 | 368043 | Model ModelObject_Impl::model() const { | |
| 67 |
2/2✓ Branch 1 taken 368043 times.
✓ Branch 4 taken 368043 times.
|
368043 | return workspace().cast<Model>(); |
| 68 | } | ||
| 69 | |||
| 70 | 22781 | std::vector<LifeCycleCost> ModelObject_Impl::lifeCycleCosts() const { | |
| 71 |
2/2✓ Branch 1 taken 22781 times.
✓ Branch 4 taken 22781 times.
|
22781 | return getObject<ModelObject>().getModelObjectSources<LifeCycleCost>(); |
| 72 | } | ||
| 73 | |||
| 74 | 5227 | std::vector<IdfObject> ModelObject_Impl::removeLifeCycleCosts() { | |
| 75 | 5227 | std::vector<IdfObject> removedCosts; | |
| 76 |
1/1✓ Branch 1 taken 5227 times.
|
5227 | std::vector<LifeCycleCost> lifeCycleCosts = this->lifeCycleCosts(); |
| 77 |
1/2✗ Branch 4 not taken.
✓ Branch 5 taken 5227 times.
|
5227 | for (LifeCycleCost& lifeCycleCost : lifeCycleCosts) { |
| 78 | ✗ | openstudio::detail::concat_helper(removedCosts, lifeCycleCost.remove()); | |
| 79 | } | ||
| 80 | 10454 | return removedCosts; | |
| 81 | 5227 | } | |
| 82 | |||
| 83 | 10430 | std::vector<ResourceObject> ModelObject_Impl::resources() const { | |
| 84 | // resources are ResourceObjects pointed to ... | ||
| 85 |
2/2✓ Branch 1 taken 10430 times.
✓ Branch 4 taken 10430 times.
|
10430 | ResourceObjectVector resourceObjects = getObject<ModelObject>().getModelObjectTargets<ResourceObject>(); |
| 86 | |||
| 87 | // create vector of unique resource objects except for a ResourceObject that is this object's parent | ||
| 88 |
1/1✓ Branch 1 taken 10430 times.
|
10430 | OptionalParentObject opo = parent(); |
| 89 | 10430 | std::set<Handle> uniqueResourceHandles; | |
| 90 | 10430 | ResourceObjectVector result; | |
| 91 |
2/2✓ Branch 5 taken 3058 times.
✓ Branch 6 taken 10430 times.
|
13488 | for (const ResourceObject& resourceObject : resourceObjects) { |
| 92 | |||
| 93 |
1/1✓ Branch 1 taken 3058 times.
|
3058 | Handle handle = resourceObject.handle(); |
| 94 |
9/9✓ Branch 0 taken 379 times.
✓ Branch 1 taken 2679 times.
✓ Branch 3 taken 379 times.
✓ Branch 6 taken 379 times.
✓ Branch 9 taken 379 times.
✓ Branch 11 taken 165 times.
✓ Branch 12 taken 214 times.
✓ Branch 13 taken 165 times.
✓ Branch 14 taken 2893 times.
|
3058 | if (opo && (opo->handle() == handle)) { |
| 95 | 245 | continue; | |
| 96 | } | ||
| 97 | |||
| 98 |
1/1✓ Branch 1 taken 2893 times.
|
2893 | auto it = uniqueResourceHandles.find(handle); |
| 99 |
2/2✓ Branch 2 taken 80 times.
✓ Branch 3 taken 2813 times.
|
2893 | if (it != uniqueResourceHandles.end()) { |
| 100 | 80 | continue; | |
| 101 | } | ||
| 102 | |||
| 103 |
1/1✓ Branch 1 taken 2813 times.
|
2813 | uniqueResourceHandles.insert(handle); |
| 104 |
1/1✓ Branch 1 taken 2813 times.
|
2813 | result.push_back(resourceObject); |
| 105 | } | ||
| 106 | |||
| 107 | 20860 | return result; | |
| 108 | 10430 | } | |
| 109 | |||
| 110 | /** Get all output variables associated with this object, must run simulation to generate associate data. */ | ||
| 111 | 10 | OutputVariableVector ModelObject_Impl::outputVariables() const { | |
| 112 | 10 | OutputVariableVector variables; | |
| 113 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | std::vector<std::string> variableNames = this->outputVariableNames(); |
| 114 |
1/1✓ Branch 1 taken 10 times.
|
10 | OptionalString name = this->name(); |
| 115 | |||
| 116 |
4/4✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
✓ Branch 12 taken 12 times.
✓ Branch 13 taken 10 times.
|
22 | for (OutputVariable& variable : this->model().getConcreteModelObjects<OutputVariable>()) { |
| 117 |
1/1✓ Branch 1 taken 12 times.
|
12 | std::string keyValue = variable.keyValue(); |
| 118 |
1/1✓ Branch 1 taken 12 times.
|
12 | std::string variableName = variable.variableName(); |
| 119 | |||
| 120 |
1/2✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 | if (name) { |
| 121 |
9/9✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
✓ Branch 6 taken 8 times.
✓ Branch 7 taken 4 times.
✓ Branch 9 taken 8 times.
✓ Branch 11 taken 6 times.
✓ Branch 12 taken 2 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 10 times.
|
12 | if (istringEqual(*name, keyValue) || (keyValue == "*")) { |
| 122 | // match | ||
| 123 | } else { | ||
| 124 | 2 | continue; // no match | |
| 125 | } | ||
| 126 | } else { | ||
| 127 | // match | ||
| 128 | } | ||
| 129 | |||
| 130 |
2/3✓ Branch 4 taken 10 times.
✓ Branch 7 taken 10 times.
✗ Branch 8 not taken.
|
10 | if (std::find(variableNames.begin(), variableNames.end(), variableName) != variableNames.end()) { |
| 131 |
1/1✓ Branch 2 taken 10 times.
|
10 | variables.emplace_back(std::move(variable)); |
| 132 | } | ||
| 133 | 24 | } | |
| 134 | 20 | return variables; | |
| 135 | 10 | } | |
| 136 | |||
| 137 | /** Get data associated with this output variable and this object. */ | ||
| 138 | ✗ | openstudio::OptionalTimeSeries ModelObject_Impl::getData(const OutputVariable& variable, const std::string& envPeriod) const { | |
| 139 | ✗ | openstudio::OptionalTimeSeries result; | |
| 140 | ✗ | OptionalSqlFile sqlFile = this->model().sqlFile(); | |
| 141 | |||
| 142 | ✗ | if (sqlFile) { | |
| 143 | ✗ | OptionalString variableName = variable.getString(OS_Output_VariableFields::VariableName); | |
| 144 | ✗ | OptionalString keyValue = variable.getString(OS_Output_VariableFields::KeyValue); | |
| 145 | ✗ | OptionalString reportingFrequency = variable.getString(OS_Output_VariableFields::ReportingFrequency, true); | |
| 146 | |||
| 147 | // solve any issues if key value is '*' | ||
| 148 | ✗ | keyValue = getSpecificKeyValue(keyValue); | |
| 149 | |||
| 150 | ✗ | if (variableName && keyValue) { | |
| 151 | ✗ | if (!reportingFrequency) { | |
| 152 | // default to hourly frequency | ||
| 153 | ✗ | LOG(Warn, "Variable does not specify reporting frequency, defaulting to hourly."); | |
| 154 | ✗ | reportingFrequency = ReportingFrequency(ReportingFrequency::Hourly).valueName(); | |
| 155 | } | ||
| 156 | // use query interface because replaces requested strings with exact strings in database | ||
| 157 | ✗ | ReportingFrequency rf(ReportingFrequency::Hourly); | |
| 158 | try { | ||
| 159 | ✗ | ReportingFrequency rf(boost::trim_copy(*reportingFrequency)); | |
| 160 | ✗ | } catch (...) { | |
| 161 | ✗ | LOG(Warn, "Unrecognized reporting frequency string. Defaulting to hourly."); | |
| 162 | ✗ | } | |
| 163 | ✗ | SqlFileTimeSeriesQuery q(envPeriod, rf, *variableName, *keyValue); | |
| 164 | ✗ | TimeSeriesVector tsVec = sqlFile->timeSeries(q); | |
| 165 | ✗ | if (tsVec.size() == 1) { | |
| 166 | ✗ | result = tsVec[0]; | |
| 167 | } | ||
| 168 | ✗ | } | |
| 169 | ✗ | } | |
| 170 | |||
| 171 | ✗ | return result; | |
| 172 | ✗ | } | |
| 173 | |||
| 174 | // set name from optional string | ||
| 175 | ✗ | bool ModelObject_Impl::mf_setName(const boost::optional<std::string>& name) { | |
| 176 | ✗ | bool result = false; | |
| 177 | ✗ | if (name) { | |
| 178 | ✗ | result = this->setName(*name).has_value(); | |
| 179 | } | ||
| 180 | ✗ | return result; | |
| 181 | } | ||
| 182 | |||
| 183 | // get specific key value from optional key value which might be '*' | ||
| 184 | ✗ | OptionalString ModelObject_Impl::getSpecificKeyValue(OptionalString keyValue) const { | |
| 185 | ✗ | OptionalString name = this->name(); | |
| 186 | ✗ | if (keyValue && name) { | |
| 187 | ✗ | if (*keyValue == "*") { | |
| 188 | ✗ | keyValue = name; | |
| 189 | } | ||
| 190 | ✗ | } else if (keyValue) { | |
| 191 | ✗ | if (*keyValue == "*") { | |
| 192 | ✗ | LOG(Error, "Variable specifies '*' for key value and object has no name."); | |
| 193 | ✗ | return {}; | |
| 194 | } | ||
| 195 | ✗ | } else if (name) { | |
| 196 | ✗ | LOG(Warn, "Variable does not specify key value, using object name."); | |
| 197 | ✗ | keyValue = name; | |
| 198 | } else { | ||
| 199 | ✗ | LOG(Error, "Variable does not specify key value and object has no name."); | |
| 200 | ✗ | return {}; | |
| 201 | } | ||
| 202 | ✗ | return keyValue; | |
| 203 | ✗ | } | |
| 204 | |||
| 205 | ✗ | boost::optional<double> ModelObject_Impl::getAutosizedValueFromInitializationSummary(const std::string& valueName, | |
| 206 | const std::string& units) const { | ||
| 207 | |||
| 208 | // Get the object name | ||
| 209 | ✗ | if (!name()) { | |
| 210 | ✗ | LOG(Warn, "This object does not have a name, cannot retrieve the autosized value '" + valueName + "'."); | |
| 211 | ✗ | return boost::none; | |
| 212 | } | ||
| 213 | |||
| 214 | // Check that the model has a sql file | ||
| 215 | ✗ | if (!model().sqlFile()) { | |
| 216 | ✗ | LOG(Warn, "This model has no sql file, cannot retrieve the autosized value '" + valueName + "'."); | |
| 217 | ✗ | return boost::none; | |
| 218 | } | ||
| 219 | |||
| 220 | // Get the object name and transform to the way it is recorded | ||
| 221 | // in the sql file | ||
| 222 | ✗ | std::string sqlName = name().get(); | |
| 223 | ✗ | boost::to_upper(sqlName); | |
| 224 | |||
| 225 | // Query the InitializationSummary -> Component Sizing table to get | ||
| 226 | // the row names that contains information for this component. | ||
| 227 | ✗ | const std::string rowsQuery = R"( | |
| 228 | SELECT RowName FROM TabularDataWithStrings | ||
| 229 | WHERE ReportName = 'InitializationSummary' | ||
| 230 | AND ReportForString = 'Entire Facility' | ||
| 231 | AND TableName = 'Component Sizing Information' | ||
| 232 | AND Value = ?;)"; | ||
| 233 | |||
| 234 | ✗ | boost::optional<std::vector<std::string>> rowNames = model().sqlFile().get().execAndReturnVectorOfString(rowsQuery, | |
| 235 | // bindArgs | ||
| 236 | ✗ | sqlName); | |
| 237 | |||
| 238 | // Warn if the query failed | ||
| 239 | ✗ | if (!rowNames) { | |
| 240 | ✗ | LOG(Warn, "Could not find a component called '" + sqlName + "' in any rows of the InitializationSummary Component Sizing table."); | |
| 241 | ✗ | return boost::none; | |
| 242 | } | ||
| 243 | |||
| 244 | // Query each row of the InitializationSummary -> Component Sizing table | ||
| 245 | // that contains this component to get the desired value. | ||
| 246 | ✗ | std::string valueNameAndUnits = valueName + std::string(" [") + units + std::string("]"); | |
| 247 | ✗ | if (units.empty()) { | |
| 248 | ✗ | valueNameAndUnits = valueName; | |
| 249 | ✗ | } else if (units == "typo_in_energyplus") { | |
| 250 | ✗ | valueNameAndUnits = valueName + std::string(" []"); | |
| 251 | } | ||
| 252 | |||
| 253 | ✗ | for (const std::string& rowName : rowNames.get()) { | |
| 254 | ✗ | const std::string rowCheckQuery = R"( | |
| 255 | SELECT Value FROM TabularDataWithStrings | ||
| 256 | WHERE ReportName = 'InitializationSummary' | ||
| 257 | AND ReportForString = 'Entire Facility' | ||
| 258 | AND TableName = 'Component Sizing Information' | ||
| 259 | AND RowName = ? | ||
| 260 | AND Value = ?;)"; | ||
| 261 | ✗ | const boost::optional<std::string> rowValueName = model().sqlFile().get().execAndReturnFirstString(rowCheckQuery, | |
| 262 | // bindArgs | ||
| 263 | ✗ | rowName, valueNameAndUnits); | |
| 264 | // Check if the query succeeded | ||
| 265 | ✗ | if (!rowValueName) { | |
| 266 | ✗ | continue; | |
| 267 | } | ||
| 268 | // This is the right row | ||
| 269 | ✗ | const std::string valQuery = R"( | |
| 270 | SELECT Value FROM TabularDataWithStrings | ||
| 271 | WHERE ReportName = 'InitializationSummary' | ||
| 272 | AND ReportForString = 'Entire Facility' | ||
| 273 | AND TableName = 'Component Sizing Information' | ||
| 274 | AND ColumnName='Value' | ||
| 275 | AND RowName = ?;)"; | ||
| 276 | ✗ | boost::optional<double> val = model().sqlFile().get().execAndReturnFirstDouble(valQuery, | |
| 277 | // bindArgs | ||
| 278 | rowName); | ||
| 279 | // Check if the query succeeded and return if so | ||
| 280 | ✗ | if (val) { | |
| 281 | ✗ | return val; | |
| 282 | } | ||
| 283 | ✗ | } | |
| 284 | |||
| 285 | ✗ | LOG(Debug, "The autosized value query for " + valueNameAndUnits + " of " + sqlName + " returned no value."); | |
| 286 | ✗ | return boost::none; | |
| 287 | ✗ | } | |
| 288 | |||
| 289 | /** Gets the autosized component value from the sql file **/ | ||
| 290 | 21 | boost::optional<double> ModelObject_Impl::getAutosizedValue(const std::string& valueName, const std::string& units, | |
| 291 | std::string overrideCompType) const { | ||
| 292 | |||
| 293 | // Get the object name | ||
| 294 |
2/3✓ Branch 1 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 21 times.
|
21 | if (!name()) { |
| 295 | ✗ | LOG(Warn, "This object does not have a name, cannot retrieve the autosized value '" + valueName + "'."); | |
| 296 | ✗ | return boost::none; | |
| 297 | } | ||
| 298 | |||
| 299 | // Check that the model has a sql file | ||
| 300 |
3/4✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 9 taken 21 times.
✗ Branch 10 not taken.
|
21 | if (!model().sqlFile()) { |
| 301 |
7/7✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✓ Branch 7 taken 21 times.
✓ Branch 10 taken 21 times.
✓ Branch 15 taken 21 times.
✓ Branch 18 taken 21 times.
✓ Branch 21 taken 21 times.
|
21 | LOG(Warn, "This model has no sql file, cannot retrieve the autosized value '" + valueName + "'."); |
| 302 | 21 | return boost::none; | |
| 303 | } | ||
| 304 | |||
| 305 | // Get the object name and transform to the way it is recorded | ||
| 306 | // in the sql file | ||
| 307 | ✗ | std::string sqlName = name().get(); | |
| 308 | ✗ | boost::to_upper(sqlName); | |
| 309 | |||
| 310 | // Get the object type and transform to the way it is recorded in the sql file | ||
| 311 | ✗ | if (overrideCompType.empty()) { | |
| 312 | ✗ | overrideCompType = iddObject().type().valueDescription(); | |
| 313 | ✗ | boost::replace_all(overrideCompType, "OS:", ""); | |
| 314 | } | ||
| 315 | |||
| 316 | ✗ | const std::string directQuery = R"sql( | |
| 317 | SELECT Value FROM ComponentSizes | ||
| 318 | WHERE CompType = ? | ||
| 319 | AND CompName = ? | ||
| 320 | AND Description = ? | ||
| 321 | AND Units = ?; | ||
| 322 | )sql"; | ||
| 323 | ✗ | boost::optional<double> val = model().sqlFile().get().execAndReturnFirstDouble(directQuery, | |
| 324 | // bindArgs | ||
| 325 | overrideCompType, sqlName, valueName, units); | ||
| 326 | ✗ | if (!val) { | |
| 327 | ✗ | LOG(Debug, fmt::format(R"sql(The direct query failed: | |
| 328 | SELECT Value FROM ComponentSizes | ||
| 329 | WHERE CompType = '{}' | ||
| 330 | AND CompName = '{}' | ||
| 331 | AND Description = '{}' | ||
| 332 | AND Units = '{}';)sql", | ||
| 333 | overrideCompType, sqlName, valueName, units)); | ||
| 334 | } | ||
| 335 | |||
| 336 | ✗ | return val; | |
| 337 | ✗ | } | |
| 338 | |||
| 339 | //void ModelObject_Impl::connect(unsigned outletPort, ModelObject target, unsigned inletPort) | ||
| 340 | //{ | ||
| 341 | // OptionalConnection connection = getOutletConnection(outletPort); | ||
| 342 | // connection->targetModelObject(target); | ||
| 343 | // connection->inletPort(inletPort); | ||
| 344 | // target.setInletConnection(connection.get()); | ||
| 345 | //} | ||
| 346 | |||
| 347 | //OptionalConnection ModelObject_Impl::getOutletConnection(unsigned portID) | ||
| 348 | //{ | ||
| 349 | // ConnectionVector connectionVector; | ||
| 350 | // connectionVector = Connection::getConnection(model()); | ||
| 351 | // OptionalConnection connection; | ||
| 352 | // | ||
| 353 | // for (connection : connectionVector) | ||
| 354 | // { | ||
| 355 | // if(connection->getSourceModelObject()) | ||
| 356 | // { | ||
| 357 | // if(connection->getSourceModelObject()->handle() == handle()) | ||
| 358 | // { | ||
| 359 | // if(connection->getOutletPort() == portID) | ||
| 360 | // { | ||
| 361 | // return connection; | ||
| 362 | // } | ||
| 363 | // } | ||
| 364 | // } | ||
| 365 | // } | ||
| 366 | // connection = Connection(model()); | ||
| 367 | // openstudio::Handle h = this->handle(); | ||
| 368 | // ModelObject modelObject = model().getModelObject(h).get(); | ||
| 369 | // connection->sourceModelObject(modelObject); | ||
| 370 | // connection->outletPort(portID); | ||
| 371 | // return connection; | ||
| 372 | //} | ||
| 373 | |||
| 374 | //void ModelObject_Impl::setOutletConnection(Connection _connection) | ||
| 375 | //{ | ||
| 376 | // ConnectionVector connectionVector; | ||
| 377 | // connectionVector = Connection::getConnection(model()); | ||
| 378 | // OptionalConnection connection; | ||
| 379 | // | ||
| 380 | // for (connection : connectionVector) | ||
| 381 | // { | ||
| 382 | // if(connection->getSourceModelObject()) | ||
| 383 | // { | ||
| 384 | // if(connection->getSourceModelObject()->handle() == handle()) | ||
| 385 | // { | ||
| 386 | // if(connection->getOutletPort() == _connection.getOutletPort()) | ||
| 387 | // { | ||
| 388 | // connection = _connection; | ||
| 389 | // return; | ||
| 390 | // } | ||
| 391 | // } | ||
| 392 | // } | ||
| 393 | // } | ||
| 394 | //} | ||
| 395 | |||
| 396 | //OptionalConnection ModelObject_Impl::getInletConnection(unsigned portID) | ||
| 397 | //{ | ||
| 398 | // ConnectionVector connectionVector; | ||
| 399 | // connectionVector = Connection::getConnection(model()); | ||
| 400 | // OptionalConnection connection; | ||
| 401 | // | ||
| 402 | // for (connection : connectionVector) | ||
| 403 | // { | ||
| 404 | // if(connection->getTargetModelObject()) | ||
| 405 | // { | ||
| 406 | // if(connection->getTargetModelObject()->handle() == handle()) | ||
| 407 | // { | ||
| 408 | // if(connection->getInletPort() == portID) | ||
| 409 | // { | ||
| 410 | // return connection; | ||
| 411 | // } | ||
| 412 | // } | ||
| 413 | // } | ||
| 414 | // } | ||
| 415 | // connection = Connection(model()); | ||
| 416 | // openstudio::Handle h = this->handle(); | ||
| 417 | // ModelObject modelObject = model().getModelObject(h).get(); | ||
| 418 | // connection->targetModelObject(modelObject); | ||
| 419 | // connection->inletPort(portID); | ||
| 420 | // return connection; | ||
| 421 | //} | ||
| 422 | |||
| 423 | //void ModelObject_Impl::setInletConnection(Connection _connection) | ||
| 424 | //{ | ||
| 425 | // ConnectionVector connectionVector; | ||
| 426 | // connectionVector = Connection::getConnection(model()); | ||
| 427 | // OptionalConnection connection; | ||
| 428 | // | ||
| 429 | // for (connection : connectionVector) | ||
| 430 | // { | ||
| 431 | // if(connection->getTargetModelObject()) | ||
| 432 | // { | ||
| 433 | // if(connection->getTargetModelObject()->handle() == handle()) | ||
| 434 | // { | ||
| 435 | // if(connection->getInletPort() == _connection.getInletPort()) | ||
| 436 | // { | ||
| 437 | // connection = _connection; | ||
| 438 | // return; | ||
| 439 | // } | ||
| 440 | // } | ||
| 441 | // } | ||
| 442 | // } | ||
| 443 | //} | ||
| 444 | |||
| 445 | //boost::optional<ModelObject> ModelObject_Impl::getOutletModelObject(unsigned outletPortID) | ||
| 446 | //{ | ||
| 447 | // boost::optional<ModelObject> obj; | ||
| 448 | // OptionalConnection connection; | ||
| 449 | // connection = getOutletConnection(outletPortID); | ||
| 450 | // if(connection) | ||
| 451 | // { | ||
| 452 | // obj = connection->getTargetModelObject(); | ||
| 453 | // } | ||
| 454 | // return obj; | ||
| 455 | //} | ||
| 456 | |||
| 457 | //boost::optional<ModelObject> ModelObject_Impl::getInletModelObject(unsigned inletPortID) | ||
| 458 | //{ | ||
| 459 | // OptionalConnection connection; | ||
| 460 | // OptionalModelObject obj; | ||
| 461 | // if(connection = getInletConnection(inletPortID)) | ||
| 462 | // { | ||
| 463 | // obj = connection->getSourceModelObject(); | ||
| 464 | // } | ||
| 465 | // return obj; | ||
| 466 | //} | ||
| 467 | |||
| 468 | 499829 | boost::optional<ModelObject> ModelObject_Impl::connectedObject(unsigned port) const { | |
| 469 |
1/1✓ Branch 1 taken 499829 times.
|
499829 | OptionalWorkspaceObject wo = this->getTarget(port); |
| 470 |
2/2✓ Branch 0 taken 394943 times.
✓ Branch 1 taken 104886 times.
|
499829 | if (wo) { |
| 471 | |||
| 472 |
2/2✓ Branch 1 taken 394943 times.
✓ Branch 4 taken 394943 times.
|
394943 | auto connection = wo->cast<Connection>(); |
| 473 | |||
| 474 |
1/1✓ Branch 1 taken 394943 times.
|
394943 | boost::optional<ModelObject> targetObject = connection.targetObject(); |
| 475 |
1/1✓ Branch 1 taken 394943 times.
|
394943 | boost::optional<ModelObject> sourceObject = connection.sourceObject(); |
| 476 |
5/6✓ Branch 0 taken 394943 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 394942 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 394942 times.
✓ Branch 5 taken 1 time.
|
789886 | if (sourceObject && targetObject) { |
| 477 |
6/6✓ Branch 1 taken 394942 times.
✓ Branch 4 taken 394942 times.
✓ Branch 7 taken 394942 times.
✓ Branch 10 taken 394942 times.
✓ Branch 12 taken 315750 times.
✓ Branch 13 taken 79192 times.
|
394942 | if (sourceObject->handle() == this->handle()) { |
| 478 | 315750 | return targetObject; | |
| 479 | } | ||
| 480 |
6/6✓ Branch 1 taken 79192 times.
✓ Branch 4 taken 79192 times.
✓ Branch 7 taken 79192 times.
✓ Branch 10 taken 79192 times.
✓ Branch 12 taken 79186 times.
✓ Branch 13 taken 6 times.
|
79192 | if (targetObject->handle() == this->handle()) { |
| 481 | 79186 | return sourceObject; | |
| 482 | } | ||
| 483 | } | ||
| 484 | 1184815 | } | |
| 485 | 104893 | return {}; | |
| 486 | 499829 | } | |
| 487 | |||
| 488 | 3340 | boost::optional<unsigned> ModelObject_Impl::connectedObjectPort(unsigned port) const { | |
| 489 |
1/1✓ Branch 1 taken 3340 times.
|
3340 | OptionalWorkspaceObject wo = this->getTarget(port); |
| 490 |
2/2✓ Branch 0 taken 3336 times.
✓ Branch 1 taken 4 times.
|
3340 | if (wo) { |
| 491 |
2/2✓ Branch 1 taken 3336 times.
✓ Branch 4 taken 3336 times.
|
3336 | auto connection = wo->cast<Connection>(); |
| 492 | |||
| 493 |
2/3✓ Branch 1 taken 3336 times.
✓ Branch 3 taken 3336 times.
✗ Branch 4 not taken.
|
6672 | if (boost::optional<ModelObject> sourceObject = connection.sourceObject()) { |
| 494 |
6/6✓ Branch 1 taken 3336 times.
✓ Branch 4 taken 3336 times.
✓ Branch 7 taken 3336 times.
✓ Branch 10 taken 3336 times.
✓ Branch 12 taken 2135 times.
✓ Branch 13 taken 1201 times.
|
3336 | if (sourceObject->handle() == this->handle()) { |
| 495 |
1/1✓ Branch 1 taken 2135 times.
|
2135 | return connection.targetObjectPort(); |
| 496 | } | ||
| 497 | 3336 | } | |
| 498 |
2/3✓ Branch 1 taken 1201 times.
✓ Branch 3 taken 1201 times.
✗ Branch 4 not taken.
|
2402 | if (boost::optional<ModelObject> targetObject = connection.targetObject()) { |
| 499 |
5/6✓ Branch 1 taken 1201 times.
✓ Branch 4 taken 1201 times.
✓ Branch 7 taken 1201 times.
✓ Branch 10 taken 1201 times.
✓ Branch 12 taken 1201 times.
✗ Branch 13 not taken.
|
1201 | if (targetObject->handle() == this->handle()) { |
| 500 |
1/1✓ Branch 1 taken 1201 times.
|
1201 | return connection.sourceObjectPort(); |
| 501 | } | ||
| 502 | 1201 | } | |
| 503 | 3336 | } | |
| 504 | 4 | return {}; | |
| 505 | 3340 | } | |
| 506 | |||
| 507 | 9648 | ModelObject ModelObject_Impl::clone(Model model) const { | |
| 508 | // UniqueModelObject. | ||
| 509 |
4/4✓ Branch 1 taken 9648 times.
✓ Branch 4 taken 9648 times.
✓ Branch 7 taken 129 times.
✓ Branch 8 taken 9519 times.
|
9648 | if (this->iddObject().properties().unique) { |
| 510 |
1/1✓ Branch 1 taken 129 times.
|
129 | Model m = this->model(); |
| 511 |
3/3✓ Branch 1 taken 129 times.
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 81 times.
|
129 | if (model == m) { |
| 512 | // Return self | ||
| 513 |
7/7✓ Branch 1 taken 48 times.
✓ Branch 4 taken 48 times.
✓ Branch 7 taken 48 times.
✓ Branch 10 taken 48 times.
✓ Branch 14 taken 48 times.
✓ Branch 17 taken 48 times.
✓ Branch 20 taken 48 times.
|
48 | LOG(Info, "Cannot clone a UniqueModelObject into the same model, returning self, for " << briefDescription()); |
| 514 |
1/1✓ Branch 1 taken 48 times.
|
48 | return getObject<ModelObject>(); |
| 515 | } else { | ||
| 516 | // Remove any existing objects (there should really be only one) | ||
| 517 |
3/4✓ Branch 1 taken 81 times.
✓ Branch 4 taken 81 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 81 times.
|
81 | for (auto& wo : model.getObjectsByType(this->iddObject())) { |
| 518 | ✗ | LOG(Info, "Removing existing UniqueModelObject in the target model: " << wo.briefDescription()); | |
| 519 | ✗ | wo.remove(); | |
| 520 | 81 | } | |
| 521 | } | ||
| 522 | 129 | } | |
| 523 | |||
| 524 | // Business as usual... | ||
| 525 | |||
| 526 | 9600 | WorkspaceObjectVector result; | |
| 527 | |||
| 528 | // No children because ModelObject. | ||
| 529 | // Can have resources and costs. | ||
| 530 |
2/2✓ Branch 1 taken 9600 times.
✓ Branch 4 taken 9600 times.
|
9600 | WorkspaceObjectVector toAdd(1u, getObject<WorkspaceObject>()); |
| 531 | |||
| 532 | // add costs | ||
| 533 |
1/1✓ Branch 1 taken 9600 times.
|
9600 | std::vector<LifeCycleCost> lifeCycleCosts = this->lifeCycleCosts(); |
| 534 |
1/1✓ Branch 5 taken 9600 times.
|
9600 | toAdd.insert(toAdd.end(), lifeCycleCosts.begin(), lifeCycleCosts.end()); |
| 535 | |||
| 536 | // add additional properties | ||
| 537 |
2/2✓ Branch 1 taken 9600 times.
✓ Branch 4 taken 9600 times.
|
9600 | AdditionalPropertiesVector props = getObject<ModelObject>().getModelObjectSources<AdditionalProperties>(); |
| 538 |
1/1✓ Branch 5 taken 9600 times.
|
9600 | toAdd.insert(toAdd.end(), props.begin(), props.end()); |
| 539 | |||
| 540 |
2/2✓ Branch 1 taken 9600 times.
✓ Branch 4 taken 9600 times.
|
9600 | std::string s = toString(this->handle()); |
| 541 | |||
| 542 | // If same model, non-recursive insert of resources should be sufficient. | ||
| 543 |
1/1✓ Branch 1 taken 9600 times.
|
9600 | Model m = this->model(); |
| 544 |
3/3✓ Branch 1 taken 9600 times.
✓ Branch 3 taken 8101 times.
✓ Branch 4 taken 1499 times.
|
9600 | if (model == m) { |
| 545 |
1/1✓ Branch 1 taken 8101 times.
|
8101 | ResourceObjectVector resources = this->resources(); |
| 546 |
1/1✓ Branch 1 taken 8101 times.
|
8101 | WorkspaceObjectVector toInsert = castVector<WorkspaceObject>(resources); |
| 547 |
1/1✓ Branch 1 taken 8101 times.
|
8101 | result = m.addAndInsertObjects(toAdd, toInsert); |
| 548 | // adding this better have worked | ||
| 549 |
1/3✗ Branch 4 not taken.
✓ Branch 5 taken 8101 times.
✗ Branch 7 not taken.
|
8101 | OS_ASSERT(result.size() == 1u + lifeCycleCosts.size() + props.size() + resources.size()); |
| 550 | // inserting resources better have worked | ||
| 551 | 8101 | unsigned i = 1 + lifeCycleCosts.size() + props.size(); | |
| 552 |
2/2✓ Branch 4 taken 1840 times.
✓ Branch 5 taken 8101 times.
|
9941 | for (const ResourceObject& resource : resources) { |
| 553 |
2/4✓ Branch 2 taken 1840 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1840 times.
✗ Branch 7 not taken.
|
1840 | OS_ASSERT(result[i] == resource); |
| 554 | 1840 | ++i; | |
| 555 | } | ||
| 556 |
1/1✓ Branch 2 taken 8101 times.
|
8101 | return result[0].cast<ModelObject>(); |
| 557 | 8101 | } | |
| 558 | |||
| 559 | // Not the same model. Resource handling is more complicated. | ||
| 560 |
4/4✓ Branch 1 taken 1499 times.
✓ Branch 4 taken 1499 times.
✓ Branch 7 taken 1499 times.
✓ Branch 10 taken 1499 times.
|
1499 | result = model.addAndInsertObjects(toAdd, castArray<WorkspaceObject>(getRecursiveResourceSubTrees(getObject<ModelObject>(), true))); |
| 561 | // Operation should work. | ||
| 562 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 1499 times.
✗ Branch 4 not taken.
|
1499 | OS_ASSERT(!result.empty()); |
| 563 |
1/1✓ Branch 2 taken 1499 times.
|
1499 | return result[0].cast<ModelObject>(); |
| 564 | 9600 | } | |
| 565 | |||
| 566 | /// remove the object from the model, also removes any cost objects associated with this object | ||
| 567 | /// return std::vector<IdfObject> containing any removed object(s) | ||
| 568 | 5227 | std::vector<IdfObject> ModelObject_Impl::remove() { | |
| 569 | // We need to **guarantee** that WorkspaceObject_Impl::remove() is called last. C++ does not guarantee the order in which function parameters | ||
| 570 | // are evaluated, so I can't pass the three remove to concat<IdfObject>(Args&&...) (on GCC it was calling Workspace_Impl::remove first) | ||
| 571 |
3/3✓ Branch 1 taken 5227 times.
✓ Branch 4 taken 5227 times.
✓ Branch 7 taken 5227 times.
|
5227 | auto result = concat<IdfObject>(this->removeLifeCycleCosts(), this->removeAdditionalProperties()); |
| 572 |
2/2✓ Branch 1 taken 5227 times.
✓ Branch 4 taken 5227 times.
|
5227 | openstudio::detail::concat_helper(result, WorkspaceObject_Impl::remove()); |
| 573 | 5227 | return result; | |
| 574 | ✗ | } | |
| 575 | |||
| 576 | 129 | Component ModelObject_Impl::createComponent() const { | |
| 577 | // component contents is defined by clone | ||
| 578 |
1/1✓ Branch 1 taken 129 times.
|
129 | Model temp; |
| 579 |
2/2✓ Branch 1 taken 129 times.
✓ Branch 4 taken 129 times.
|
129 | ModelObject cloneOfThis = this->clone(temp); |
| 580 | // ensure that the first object in contents is cloneOfThis (the primary object). | ||
| 581 |
2/2✓ Branch 1 taken 129 times.
✓ Branch 4 taken 129 times.
|
129 | ModelObjectVector contents = castVector<ModelObject>(temp.objects(true)); |
| 582 |
2/4✓ Branch 2 taken 129 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 129 times.
✗ Branch 7 not taken.
|
129 | OS_ASSERT(contents[0] == cloneOfThis); |
| 583 |
1/1✓ Branch 1 taken 129 times.
|
258 | return Component(contents); |
| 584 | 129 | } | |
| 585 | |||
| 586 | 1284 | boost::optional<ParentObject> ModelObject_Impl::parent() const { | |
| 587 | 1284 | return {}; | |
| 588 | } | ||
| 589 | |||
| 590 | 12 | bool ModelObject_Impl::setParent(ParentObject& /*newParent*/) { | |
| 591 | 12 | return false; | |
| 592 | } | ||
| 593 | |||
| 594 | 243735 | ModelObject_Impl::ModelObject_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 595 | 243735 | : WorkspaceObject_Impl(idfObject, model, keepHandle) {} | |
| 596 | |||
| 597 | ✗ | ModelObject_Impl::ModelObject_Impl(IddObjectType type, Model_Impl* model) : WorkspaceObject_Impl(IdfObject(type), model) {} | |
| 598 | |||
| 599 | 2823 | bool ModelObject_Impl::getBooleanFieldValue(unsigned index) const { | |
| 600 |
1/1✓ Branch 1 taken 2823 times.
|
2823 | OptionalString oStr = getString(index, true); |
| 601 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 2823 times.
✗ Branch 4 not taken.
|
2823 | OS_ASSERT(oStr); |
| 602 |
2/2✓ Branch 1 taken 2823 times.
✓ Branch 4 taken 2823 times.
|
2823 | std::string temp = *oStr; |
| 603 |
1/1✓ Branch 2 taken 2823 times.
|
2823 | boost::to_lower(temp); |
| 604 |
3/3✓ Branch 1 taken 2823 times.
✓ Branch 3 taken 369 times.
✓ Branch 4 taken 2454 times.
|
2823 | if (temp == "yes") { |
| 605 | 369 | return true; | |
| 606 | } | ||
| 607 |
2/3✓ Branch 1 taken 2454 times.
✓ Branch 3 taken 2454 times.
✗ Branch 4 not taken.
|
2454 | if (temp == "no") { |
| 608 | 2454 | return false; | |
| 609 | } | ||
| 610 | ✗ | LOG_AND_THROW("Unable to deduce a value for boolean field " << index << " in " << briefDescription() << "."); | |
| 611 | return false; | ||
| 612 | 2823 | } | |
| 613 | |||
| 614 | 7830 | bool ModelObject_Impl::setBooleanFieldValue(unsigned index, bool value) { | |
| 615 | 7830 | bool ok(true); | |
| 616 |
2/2✓ Branch 0 taken 1977 times.
✓ Branch 1 taken 5853 times.
|
7830 | if (value) { |
| 617 |
2/2✓ Branch 1 taken 1977 times.
✓ Branch 4 taken 1977 times.
|
5931 | ok = setString(index, "Yes"); |
| 618 | } else { | ||
| 619 |
2/2✓ Branch 1 taken 5853 times.
✓ Branch 4 taken 5853 times.
|
17559 | ok = setString(index, "No"); |
| 620 | } | ||
| 621 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7830 times.
|
7830 | if (!ok) { |
| 622 | ✗ | LOG_AND_THROW("Unable to set boolean field " << index << " in " << briefDescription() << "."); | |
| 623 | } | ||
| 624 | 7830 | return true; | |
| 625 | } | ||
| 626 | |||
| 627 | 6806 | bool ModelObject_Impl::setSchedule(unsigned index, const std::string& className, const std::string& scheduleDisplayName, Schedule& schedule) { | |
| 628 |
4/5✓ Branch 1 taken 6806 times.
✓ Branch 4 taken 6806 times.
✓ Branch 7 taken 6806 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 6806 times.
|
6806 | if (schedule.model() != model()) { |
| 629 | ✗ | return false; | |
| 630 | } | ||
| 631 | 6806 | bool result = checkOrAssignScheduleTypeLimits(className, scheduleDisplayName, schedule); | |
| 632 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 6795 times.
|
6806 | if (!result) { |
| 633 |
2/3✓ Branch 1 taken 11 times.
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
|
22 | if (boost::optional<ScheduleTypeLimits> scheduleTypeLimits = schedule.scheduleTypeLimits()) { |
| 634 |
13/13✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✓ Branch 10 taken 11 times.
✓ Branch 13 taken 11 times.
✓ Branch 16 taken 11 times.
✓ Branch 19 taken 11 times.
✓ Branch 22 taken 11 times.
✓ Branch 25 taken 11 times.
✓ Branch 28 taken 11 times.
✓ Branch 33 taken 11 times.
✓ Branch 36 taken 11 times.
✓ Branch 39 taken 11 times.
|
11 | LOG(Warn, "For " << briefDescription() << " cannot set Schedule " << scheduleDisplayName << "=" << schedule.nameString() |
| 635 | << " because it has an incompatible ScheduleTypeLimits"); | ||
| 636 | 11 | } | |
| 637 | 11 | return result; | |
| 638 | } | ||
| 639 |
2/2✓ Branch 1 taken 6795 times.
✓ Branch 4 taken 6795 times.
|
6795 | return setPointer(index, schedule.handle()); |
| 640 | } | ||
| 641 | |||
| 642 | ✗ | boost::optional<ModelObject> ModelObject_Impl::parentAsModelObject() const { | |
| 643 | ✗ | boost::optional<ModelObject> result; | |
| 644 | ✗ | OptionalParentObject intermediate = parent(); | |
| 645 | ✗ | if (intermediate) { | |
| 646 | ✗ | result = *intermediate; | |
| 647 | } | ||
| 648 | ✗ | return result; | |
| 649 | ✗ | } | |
| 650 | |||
| 651 | ✗ | std::vector<ModelObject> ModelObject_Impl::resourcesAsModelObjects() const { | |
| 652 | ✗ | ModelObjectVector result = castVector<ModelObject>(resources()); | |
| 653 | ✗ | return result; | |
| 654 | } | ||
| 655 | |||
| 656 | ✗ | bool ModelObject_Impl::setParentAsModelObject(boost::optional<ModelObject> modelObject) { | |
| 657 | ✗ | if (modelObject) { | |
| 658 | ✗ | OptionalParentObject intermediate = modelObject->optionalCast<ParentObject>(); | |
| 659 | ✗ | if (intermediate) { | |
| 660 | ✗ | return setParent(*intermediate); | |
| 661 | } | ||
| 662 | ✗ | } | |
| 663 | ✗ | return false; | |
| 664 | } | ||
| 665 | |||
| 666 | 2065 | std::vector<ScheduleTypeKey> ModelObject_Impl::getScheduleTypeKeys(const Schedule& /*schedule*/) const { | |
| 667 | 2065 | return {}; | |
| 668 | } | ||
| 669 | |||
| 670 | ✗ | std::vector<EMSActuatorNames> ModelObject_Impl::emsActuatorNames() const { | |
| 671 | ✗ | return {}; | |
| 672 | } | ||
| 673 | |||
| 674 | ✗ | std::vector<std::string> ModelObject_Impl::emsInternalVariableNames() const { | |
| 675 | ✗ | return {}; | |
| 676 | } | ||
| 677 | |||
| 678 | 28087 | AdditionalProperties ModelObject_Impl::additionalProperties() const { | |
| 679 |
2/2✓ Branch 1 taken 28087 times.
✓ Branch 4 taken 28087 times.
|
28087 | AdditionalPropertiesVector candidates = getObject<ModelObject>().getModelObjectSources<AdditionalProperties>(); |
| 680 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 28086 times.
|
28087 | if (candidates.size() > 1) { |
| 681 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
|
2 | for (unsigned i = 1, n = candidates.size(); i < n; ++i) { |
| 682 | // do a merge before removing | ||
| 683 |
1/1✓ Branch 3 taken 1 time.
|
1 | candidates[0].merge(candidates[i]); |
| 684 |
1/1✓ Branch 2 taken 1 time.
|
1 | candidates[i].remove(); |
| 685 | } | ||
| 686 |
8/8✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 17 taken 1 time.
✓ Branch 20 taken 1 time.
✓ Branch 23 taken 1 time.
|
1 | LOG(Warn, "Removed extraneous ModelObjectAdditionalProperties objects pointing to " << briefDescription() << "."); |
| 687 | } | ||
| 688 |
2/2✓ Branch 1 taken 23020 times.
✓ Branch 2 taken 5067 times.
|
28087 | if (!candidates.empty()) { |
| 689 |
1/1✓ Branch 2 taken 23020 times.
|
23020 | return candidates[0]; |
| 690 | } | ||
| 691 |
2/2✓ Branch 1 taken 5067 times.
✓ Branch 4 taken 5066 times.
|
5068 | return AdditionalProperties(getObject<ModelObject>()); |
| 692 | 28087 | } | |
| 693 | |||
| 694 | 5227 | std::vector<IdfObject> ModelObject_Impl::removeAdditionalProperties() { | |
| 695 | 5227 | std::vector<IdfObject> removed; | |
| 696 |
2/2✓ Branch 1 taken 5227 times.
✓ Branch 4 taken 5227 times.
|
5227 | AdditionalPropertiesVector candidates = getObject<ModelObject>().getModelObjectSources<AdditionalProperties>(); |
| 697 |
2/2✓ Branch 5 taken 2 times.
✓ Branch 6 taken 5227 times.
|
5229 | for (AdditionalProperties& candidate : candidates) { |
| 698 |
1/1✓ Branch 1 taken 2 times.
|
2 | std::vector<IdfObject> tmp = candidate.remove(); |
| 699 |
1/1✓ Branch 2 taken 2 times.
|
2 | openstudio::detail::concat_helper(removed, std::move(tmp)); |
| 700 | 2 | } | |
| 701 | 10454 | return removed; | |
| 702 | 5227 | } | |
| 703 | |||
| 704 | 16160 | bool ModelObject_Impl::hasAdditionalProperties() const { | |
| 705 |
2/2✓ Branch 1 taken 16160 times.
✓ Branch 4 taken 16160 times.
|
16160 | AdditionalPropertiesVector candidates = getObject<ModelObject>().getModelObjectSources<AdditionalProperties>(); |
| 706 | 32320 | return !candidates.empty(); | |
| 707 | 16160 | } | |
| 708 | |||
| 709 | 1518 | boost::optional<std::string> ModelObject_Impl::cadObjectId() const { | |
| 710 | 1518 | boost::optional<std::string> result; | |
| 711 |
2/3✓ Branch 1 taken 1518 times.
✓ Branch 3 taken 1518 times.
✗ Branch 4 not taken.
|
1518 | if (hasAdditionalProperties()) { |
| 712 |
1/1✓ Branch 1 taken 1518 times.
|
1518 | AdditionalProperties additionalProperties = this->additionalProperties(); |
| 713 |
4/4✓ Branch 1 taken 1518 times.
✓ Branch 4 taken 1518 times.
✓ Branch 7 taken 1332 times.
✓ Branch 8 taken 186 times.
|
3036 | if (additionalProperties.hasFeature("CADObjectId")) { |
| 714 |
2/2✓ Branch 1 taken 1332 times.
✓ Branch 4 taken 1332 times.
|
2664 | result = additionalProperties.getFeatureAsString("CADObjectId"); |
| 715 | } | ||
| 716 | 1518 | } | |
| 717 | 1518 | return result; | |
| 718 | ✗ | } | |
| 719 | |||
| 720 | 2873 | bool ModelObject_Impl::setCADObjectId(const std::string& cadObjectId) { | |
| 721 |
3/3✓ Branch 1 taken 2873 times.
✓ Branch 4 taken 2873 times.
✓ Branch 7 taken 2873 times.
|
8619 | return this->additionalProperties().setFeature("CADObjectId", cadObjectId); |
| 722 | } | ||
| 723 | |||
| 724 | 3851 | boost::optional<std::string> ModelObject_Impl::gbXMLId() const { | |
| 725 | 3851 | boost::optional<std::string> result; | |
| 726 |
3/3✓ Branch 1 taken 3851 times.
✓ Branch 3 taken 3152 times.
✓ Branch 4 taken 699 times.
|
3851 | if (hasAdditionalProperties()) { |
| 727 |
1/1✓ Branch 1 taken 3152 times.
|
3152 | AdditionalProperties additionalProperties = this->additionalProperties(); |
| 728 |
3/4✓ Branch 1 taken 3152 times.
✓ Branch 4 taken 3152 times.
✓ Branch 7 taken 3152 times.
✗ Branch 8 not taken.
|
6304 | if (additionalProperties.hasFeature("gbXMLId")) { |
| 729 |
2/2✓ Branch 1 taken 3152 times.
✓ Branch 4 taken 3152 times.
|
6304 | result = additionalProperties.getFeatureAsString("gbXMLId"); |
| 730 | } | ||
| 731 | 3152 | } | |
| 732 | 3851 | return result; | |
| 733 | ✗ | } | |
| 734 | |||
| 735 | 3903 | bool ModelObject_Impl::setGBXMLId(const std::string& gbXMLId) { | |
| 736 |
3/3✓ Branch 1 taken 3903 times.
✓ Branch 4 taken 3903 times.
✓ Branch 7 taken 3903 times.
|
11709 | return this->additionalProperties().setFeature("gbXMLId", gbXMLId); |
| 737 | } | ||
| 738 | |||
| 739 | 3755 | boost::optional<std::string> ModelObject_Impl::displayName() const { | |
| 740 | 3755 | boost::optional<std::string> result; | |
| 741 |
3/3✓ Branch 1 taken 3755 times.
✓ Branch 3 taken 3052 times.
✓ Branch 4 taken 703 times.
|
3755 | if (hasAdditionalProperties()) { |
| 742 |
1/1✓ Branch 1 taken 3052 times.
|
3052 | AdditionalProperties additionalProperties = this->additionalProperties(); |
| 743 |
4/4✓ Branch 1 taken 3052 times.
✓ Branch 4 taken 3052 times.
✓ Branch 7 taken 2932 times.
✓ Branch 8 taken 120 times.
|
6104 | if (additionalProperties.hasFeature("displayName")) { |
| 744 |
2/2✓ Branch 1 taken 2932 times.
✓ Branch 4 taken 2932 times.
|
5864 | result = additionalProperties.getFeatureAsString("displayName"); |
| 745 | } | ||
| 746 | 3052 | } | |
| 747 | 3755 | return result; | |
| 748 | ✗ | } | |
| 749 | |||
| 750 | 3567 | bool ModelObject_Impl::setDisplayName(const std::string& displayName) { | |
| 751 |
3/3✓ Branch 1 taken 3567 times.
✓ Branch 4 taken 3567 times.
✓ Branch 7 taken 3567 times.
|
10701 | return this->additionalProperties().setFeature("displayName", displayName); |
| 752 | } | ||
| 753 | |||
| 754 | } // namespace detail | ||
| 755 | |||
| 756 | 21425 | bool ModelObject::operator<(const ModelObject& right) const { | |
| 757 | 21425 | return (getImpl<detail::ModelObject_Impl>()) < (right.getImpl<detail::ModelObject_Impl>()); | |
| 758 | } | ||
| 759 | |||
| 760 | // GETTERS | ||
| 761 | |||
| 762 | // DLM@20101011: todo, fix later | ||
| 763 | 86646 | Model ModelObject::model() const { | |
| 764 |
1/1✓ Branch 3 taken 86646 times.
|
86646 | return getImpl<detail::ModelObject_Impl>()->model(); |
| 765 | } | ||
| 766 | |||
| 767 | 7954 | std::vector<LifeCycleCost> ModelObject::lifeCycleCosts() const { | |
| 768 |
1/1✓ Branch 3 taken 7954 times.
|
7954 | return getImpl<detail::ModelObject_Impl>()->lifeCycleCosts(); |
| 769 | } | ||
| 770 | |||
| 771 | ✗ | std::vector<IdfObject> ModelObject::removeLifeCycleCosts() { | |
| 772 | ✗ | return getImpl<detail::ModelObject_Impl>()->removeLifeCycleCosts(); | |
| 773 | } | ||
| 774 | |||
| 775 | 106975 | IddObjectType ModelObject::iddObjectType() const { | |
| 776 |
1/1✓ Branch 3 taken 106975 times.
|
106975 | return getImpl<detail::ModelObject_Impl>()->iddObjectType(); |
| 777 | } | ||
| 778 | |||
| 779 | 2332 | std::vector<ResourceObject> ModelObject::resources() const { | |
| 780 |
1/1✓ Branch 3 taken 2332 times.
|
2332 | return getImpl<detail::ModelObject_Impl>()->resources(); |
| 781 | } | ||
| 782 | |||
| 783 | /** Get all output variables names that could be associated with this object. | ||
| 784 | * Each concrete class should override this.*/ | ||
| 785 | 607 | const std::vector<std::string>& ModelObject::outputVariableNames() const { | |
| 786 |
1/1✓ Branch 3 taken 607 times.
|
607 | return getImpl<detail::ModelObject_Impl>()->outputVariableNames(); |
| 787 | } | ||
| 788 | |||
| 789 | /** Get all output variables associated with this object, must run simulation to generate associate data. */ | ||
| 790 | 10 | OutputVariableVector ModelObject::outputVariables() const { | |
| 791 |
1/1✓ Branch 3 taken 10 times.
|
10 | return getImpl<detail::ModelObject_Impl>()->outputVariables(); |
| 792 | } | ||
| 793 | |||
| 794 | /** Get data associated with this output variable and this object. */ | ||
| 795 | ✗ | openstudio::OptionalTimeSeries ModelObject::getData(const OutputVariable& variable, const std::string& envPeriod) const { | |
| 796 | ✗ | return getImpl<detail::ModelObject_Impl>()->getData(variable, envPeriod); | |
| 797 | } | ||
| 798 | |||
| 799 | /// equality test | ||
| 800 | 2716194 | bool ModelObject::operator==(const ModelObject& other) const { | |
| 801 |
3/3✓ Branch 1 taken 2716194 times.
✓ Branch 4 taken 2716194 times.
✓ Branch 7 taken 2716194 times.
|
2716194 | return (handle() == other.handle()); |
| 802 | } | ||
| 803 | |||
| 804 | /// in-equality test | ||
| 805 | 975 | bool ModelObject::operator!=(const ModelObject& other) const { | |
| 806 |
3/3✓ Branch 1 taken 975 times.
✓ Branch 4 taken 975 times.
✓ Branch 7 taken 975 times.
|
975 | return (handle() != other.handle()); |
| 807 | } | ||
| 808 | |||
| 809 | 2074 | std::vector<ScheduleTypeKey> ModelObject::getScheduleTypeKeys(const Schedule& schedule) const { | |
| 810 |
1/1✓ Branch 3 taken 2074 times.
|
2074 | return getImpl<detail::ModelObject_Impl>()->getScheduleTypeKeys(schedule); |
| 811 | } | ||
| 812 | |||
| 813 | 1939 | boost::optional<ModelObject> ModelObject::connectedObject(unsigned port) const { | |
| 814 |
1/1✓ Branch 3 taken 1939 times.
|
1939 | return getImpl<detail::ModelObject_Impl>()->connectedObject(port); |
| 815 | } | ||
| 816 | |||
| 817 | 2900 | boost::optional<unsigned> ModelObject::connectedObjectPort(unsigned port) const { | |
| 818 |
1/1✓ Branch 3 taken 2900 times.
|
2900 | return getImpl<detail::ModelObject_Impl>()->connectedObjectPort(port); |
| 819 | } | ||
| 820 | |||
| 821 | 2461 | ModelObject ModelObject::clone() const { | |
| 822 |
2/2✓ Branch 3 taken 2461 times.
✓ Branch 6 taken 2461 times.
|
2461 | return getImpl<detail::ModelObject_Impl>()->clone(model()); |
| 823 | } | ||
| 824 | |||
| 825 | 6896 | ModelObject ModelObject::clone(Model model) const { | |
| 826 |
2/2✓ Branch 3 taken 6896 times.
✓ Branch 6 taken 6893 times.
|
6899 | return getImpl<detail::ModelObject_Impl>()->clone(model); |
| 827 | } | ||
| 828 | |||
| 829 | 129 | Component ModelObject::createComponent() const { | |
| 830 |
1/1✓ Branch 3 taken 129 times.
|
129 | return getImpl<detail::ModelObject_Impl>()->createComponent(); |
| 831 | } | ||
| 832 | |||
| 833 | 107 | OptionalParentObject ModelObject::parent() const { | |
| 834 |
1/1✓ Branch 3 taken 107 times.
|
107 | return getImpl<detail::ModelObject_Impl>()->parent(); |
| 835 | } | ||
| 836 | |||
| 837 | 4191 | bool ModelObject::setParent(ParentObject& newParent) { | |
| 838 |
1/1✓ Branch 3 taken 4191 times.
|
4191 | return getImpl<detail::ModelObject_Impl>()->setParent(newParent); |
| 839 | } | ||
| 840 | |||
| 841 | 9996 | AdditionalProperties ModelObject::additionalProperties() const { | |
| 842 |
1/1✓ Branch 3 taken 9995 times.
|
9996 | return getImpl<detail::ModelObject_Impl>()->additionalProperties(); |
| 843 | } | ||
| 844 | |||
| 845 | 7036 | bool ModelObject::hasAdditionalProperties() const { | |
| 846 |
1/1✓ Branch 3 taken 7036 times.
|
7036 | return getImpl<detail::ModelObject_Impl>()->hasAdditionalProperties(); |
| 847 | } | ||
| 848 | |||
| 849 | ✗ | std::vector<IdfObject> ModelObject::removeAdditionalProperties() { | |
| 850 | ✗ | return getImpl<detail::ModelObject_Impl>()->removeAdditionalProperties(); | |
| 851 | } | ||
| 852 | |||
| 853 | 1518 | boost::optional<std::string> ModelObject::cadObjectId() const { | |
| 854 |
1/1✓ Branch 3 taken 1518 times.
|
1518 | return getImpl<detail::ModelObject_Impl>()->cadObjectId(); |
| 855 | } | ||
| 856 | |||
| 857 | 2873 | bool ModelObject::setCADObjectId(const std::string& cadObjectId) { | |
| 858 |
1/1✓ Branch 3 taken 2873 times.
|
2873 | return getImpl<detail::ModelObject_Impl>()->setCADObjectId(cadObjectId); |
| 859 | } | ||
| 860 | |||
| 861 | 3851 | boost::optional<std::string> ModelObject::gbXMLId() const { | |
| 862 |
1/1✓ Branch 3 taken 3851 times.
|
3851 | return getImpl<detail::ModelObject_Impl>()->gbXMLId(); |
| 863 | } | ||
| 864 | |||
| 865 | 3903 | bool ModelObject::setGBXMLId(const std::string& gbXMLId) { | |
| 866 |
1/1✓ Branch 3 taken 3903 times.
|
3903 | return getImpl<detail::ModelObject_Impl>()->setGBXMLId(gbXMLId); |
| 867 | } | ||
| 868 | |||
| 869 | 3755 | boost::optional<std::string> ModelObject::displayName() const { | |
| 870 |
1/1✓ Branch 3 taken 3755 times.
|
3755 | return getImpl<detail::ModelObject_Impl>()->displayName(); |
| 871 | } | ||
| 872 | |||
| 873 | 3567 | bool ModelObject::setDisplayName(const std::string& displayName) { | |
| 874 |
1/1✓ Branch 3 taken 3567 times.
|
3567 | return getImpl<detail::ModelObject_Impl>()->setDisplayName(displayName); |
| 875 | } | ||
| 876 | |||
| 877 | 173617 | ModelObject::ModelObject(IddObjectType type, const Model& model, bool fastName) | |
| 878 |
3/3✓ Branch 3 taken 173617 times.
✓ Branch 6 taken 173617 times.
✓ Branch 9 taken 173617 times.
|
173617 | : WorkspaceObject(model.getImpl<detail::Model_Impl>()->createObject(IdfObject(type, fastName), false)) { |
| 879 | // create object of correct type | ||
| 880 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 173617 times.
✗ Branch 5 not taken.
|
173617 | OS_ASSERT(getImpl<detail::ModelObject_Impl>()); |
| 881 |
2/4✓ Branch 3 taken 173617 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 173617 times.
✗ Branch 8 not taken.
|
173617 | OS_ASSERT(!getImpl<detail::ModelObject_Impl>()->initialized()); |
| 882 | // add to Workspace | ||
| 883 | 173617 | openstudio::detail::WorkspaceObject_ImplPtrVector impls; | |
| 884 |
1/1✓ Branch 2 taken 173617 times.
|
173617 | impls.push_back(getImpl<openstudio::detail::WorkspaceObject_Impl>()); |
| 885 |
1/1✓ Branch 3 taken 173617 times.
|
173617 | model.getImpl<detail::Model_Impl>()->addObjects(impls, false); |
| 886 | // object should be initialized and ready to go | ||
| 887 |
2/3✓ Branch 3 taken 173617 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 173617 times.
|
173617 | if (!getImpl<detail::ModelObject_Impl>()->initialized()) { |
| 888 | ✗ | LOG_AND_THROW("ModelObject not initialized: " << '\n' << getImpl<openstudio::detail::WorkspaceObject_Impl>()->idfObject()); | |
| 889 | } | ||
| 890 | 173617 | } | |
| 891 | |||
| 892 |
1/1✓ Branch 3 taken 11565540 times.
|
11565540 | ModelObject::ModelObject(std::shared_ptr<detail::ModelObject_Impl> p) : WorkspaceObject(std::move(p)) {} |
| 893 | |||
| 894 | /** Gets the autosized component value from the sql file **/ | ||
| 895 | ✗ | boost::optional<double> ModelObject::getAutosizedValue(const std::string& valueName, const std::string& units) const { | |
| 896 | ✗ | return getImpl<detail::ModelObject_Impl>()->getAutosizedValue(valueName, units); | |
| 897 | } | ||
| 898 | |||
| 899 | ✗ | std::vector<EMSActuatorNames> ModelObject::emsActuatorNames() const { | |
| 900 | ✗ | return getImpl<detail::ModelObject_Impl>()->emsActuatorNames(); | |
| 901 | } | ||
| 902 | |||
| 903 | ✗ | std::vector<std::string> ModelObject::emsInternalVariableNames() const { | |
| 904 | ✗ | return getImpl<detail::ModelObject_Impl>()->emsInternalVariableNames(); | |
| 905 | } | ||
| 906 | |||
| 907 | ✗ | EMSActuatorNames::EMSActuatorNames(const std::string& componentTypeName, const std::string& controlTypeName) | |
| 908 | ✗ | : m_componentTypeName(componentTypeName), m_controlTypeName(controlTypeName) {} | |
| 909 | |||
| 910 | ✗ | std::string EMSActuatorNames::controlTypeName() const { | |
| 911 | ✗ | return m_controlTypeName; | |
| 912 | } | ||
| 913 | |||
| 914 | ✗ | std::string EMSActuatorNames::componentTypeName() const { | |
| 915 | ✗ | return m_componentTypeName; | |
| 916 | } | ||
| 917 | |||
| 918 | 1 | ScheduleTypeKey::ScheduleTypeKey(const std::string& className, const std::string& scheduleDisplayName) | |
| 919 |
1/1✓ Branch 2 taken 1 time.
|
1 | : m_className(className), m_scheduleDisplayName(scheduleDisplayName) {} |
| 920 | ✗ | std::string ScheduleTypeKey::className() const { | |
| 921 | ✗ | return m_className; | |
| 922 | } | ||
| 923 | ✗ | std::string ScheduleTypeKey::scheduleDisplayName() const { | |
| 924 | ✗ | return m_scheduleDisplayName; | |
| 925 | } | ||
| 926 | |||
| 927 | } // namespace model | ||
| 928 | } // namespace openstudio | ||
| 929 |