src/energyplus/ReverseTranslator/ReverseTranslateEnergyManagementSystemTrendVariable.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/EnergyManagementSystemTrendVariable.hpp" | ||
| 9 | #include "../../model/EnergyManagementSystemTrendVariable_Impl.hpp" | ||
| 10 | #include "../../model/EnergyManagementSystemGlobalVariable.hpp" | ||
| 11 | #include "../../model/EnergyManagementSystemGlobalVariable_Impl.hpp" | ||
| 12 | |||
| 13 | #include <utilities/idd/EnergyManagementSystem_TrendVariable_FieldEnums.hxx> | ||
| 14 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 15 | #include <utilities/idd/IddEnums.hxx> | ||
| 16 | |||
| 17 | using namespace openstudio::model; | ||
| 18 | |||
| 19 | namespace openstudio { | ||
| 20 | |||
| 21 | namespace energyplus { | ||
| 22 | |||
| 23 | 3 | OptionalModelObject ReverseTranslator::translateEnergyManagementSystemTrendVariable(const WorkspaceObject& workspaceObject) { | |
| 24 |
4/5✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 3 times.
|
3 | if (workspaceObject.iddObject().type() != IddObjectType::EnergyManagementSystem_TrendVariable) { |
| 25 | ✗ | LOG(Error, "WorkspaceObject is not IddObjectType: EnergyManagementSystem_TrendVariable"); | |
| 26 | ✗ | return boost::none; | |
| 27 | } | ||
| 28 | |||
| 29 |
1/1✓ Branch 1 taken 3 times.
|
3 | OptionalString s = workspaceObject.getString(EnergyManagementSystem_TrendVariableFields::Name); |
| 30 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (!s) { |
| 31 | ✗ | LOG(Error, "WorkspaceObject EnergyManagementSystem_TrendVariable has no Name"); | |
| 32 | ✗ | return boost::none; | |
| 33 | } | ||
| 34 | |||
| 35 |
1/1✓ Branch 1 taken 3 times.
|
3 | openstudio::model::EnergyManagementSystemTrendVariable emsTrendVariable(m_model); |
| 36 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | emsTrendVariable.setName(*s); |
| 37 | |||
| 38 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<int> i = workspaceObject.getInt(EnergyManagementSystem_TrendVariableFields::NumberofTimestepstobeLogged); |
| 39 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (!i) { |
| 40 | ✗ | LOG(Error, emsTrendVariable.nameString() + ": NumberofTimestepstobeLogged not set"); | |
| 41 | ✗ | return boost::none; | |
| 42 | } else { | ||
| 43 |
2/2✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
|
3 | emsTrendVariable.setNumberOfTimestepsToBeLogged(*i); |
| 44 | } | ||
| 45 | |||
| 46 |
1/1✓ Branch 1 taken 3 times.
|
3 | s = workspaceObject.getString(EnergyManagementSystem_TrendVariableFields::EMSVariableName); |
| 47 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
|
3 | if (!s) { |
| 48 | ✗ | LOG(Error, emsTrendVariable.nameString() + ": EMSVariableName not set"); | |
| 49 | ✗ | return boost::none; | |
| 50 | } else { | ||
| 51 | 3 | bool result = false; | |
| 52 |
1/1✓ Branch 1 taken 3 times.
|
3 | Workspace workspace = workspaceObject.workspace(); |
| 53 | //look for GlobalVariables, translate and check if there is a name match since GV's dont have name field. | ||
| 54 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 11 taken 3 times.
✓ Branch 12 taken 1 time.
|
4 | for (WorkspaceObject& wsObject : workspace.getObjectsByType(IddObjectType::EnergyManagementSystem_GlobalVariable)) { |
| 55 |
1/1✓ Branch 1 taken 3 times.
|
3 | boost::optional<model::ModelObject> modelObject = translateAndMapWorkspaceObject(wsObject); |
| 56 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (modelObject) { |
| 57 |
6/6✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 14 taken 2 times.
✓ Branch 15 taken 1 time.
|
3 | if (modelObject.get().cast<EnergyManagementSystemGlobalVariable>().name() == s) { |
| 58 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
2 | result = emsTrendVariable.setEMSVariableName(*s); |
| 59 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (result) { |
| 60 |
1/1✓ Branch 1 taken 2 times.
|
2 | return emsTrendVariable; |
| 61 | } else { | ||
| 62 | ✗ | return boost::none; | |
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | 6 | } | |
| 67 | //look for name match on other (EMS) objects. | ||
| 68 |
3/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 11 taken 1 time.
✗ Branch 12 not taken.
|
1 | for (WorkspaceObject& wsObject : workspace.getObjectsByName(*s)) { |
| 69 |
1/1✓ Branch 1 taken 1 time.
|
1 | boost::optional<model::ModelObject> modelObject = translateAndMapWorkspaceObject(wsObject); |
| 70 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (modelObject) { |
| 71 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | result = emsTrendVariable.setEMSVariableName(*s); |
| 72 |
1/2✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
|
1 | if (result) { |
| 73 |
1/1✓ Branch 1 taken 1 time.
|
1 | return emsTrendVariable; |
| 74 | } else { | ||
| 75 | ✗ | return boost::none; | |
| 76 | } | ||
| 77 | } | ||
| 78 | 2 | } | |
| 79 | 3 | } | |
| 80 | |||
| 81 | ✗ | return emsTrendVariable; | |
| 82 | 3 | } | |
| 83 | |||
| 84 | } // namespace energyplus | ||
| 85 | |||
| 86 | } // namespace openstudio | ||
| 87 |