src/energyplus/ForwardTranslator/ForwardTranslateEnergyManagementSystemProgram.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 "../ForwardTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/Model.hpp" | ||
| 9 | #include "../../model/OutputVariable.hpp" | ||
| 10 | #include "../../model/OutputVariable_Impl.hpp" | ||
| 11 | #include "../../model/OutputMeter.hpp" | ||
| 12 | #include "../../model/OutputMeter_Impl.hpp" | ||
| 13 | #include "../../model/Schedule.hpp" | ||
| 14 | #include "../../model/Schedule_Impl.hpp" | ||
| 15 | #include "../../model/EnergyManagementSystemProgram.hpp" | ||
| 16 | #include "../../model/EnergyManagementSystemProgram_Impl.hpp" | ||
| 17 | |||
| 18 | #include "../../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 19 | #include "../../utilities/core/UUID.hpp" | ||
| 20 | #include "../../utilities/core/StringHelpers.hpp" | ||
| 21 | |||
| 22 | #include <utilities/idd/OS_EnergyManagementSystem_Program_FieldEnums.hxx> | ||
| 23 | #include <utilities/idd/EnergyManagementSystem_Program_FieldEnums.hxx> | ||
| 24 | #include "../../utilities/idd/IddEnums.hpp" | ||
| 25 | #include <utilities/idd/IddEnums.hxx> | ||
| 26 | #include <utilities/idd/IddFactory.hxx> | ||
| 27 | |||
| 28 | using namespace openstudio::model; | ||
| 29 | |||
| 30 | using namespace std; | ||
| 31 | |||
| 32 | namespace openstudio { | ||
| 33 | |||
| 34 | namespace energyplus { | ||
| 35 | |||
| 36 | 21 | boost::optional<IdfObject> ForwardTranslator::translateEnergyManagementSystemProgram(EnergyManagementSystemProgram& modelObject) { | |
| 37 | 21 | boost::optional<std::string> s; | |
| 38 | 21 | const int subs[] = {1}; | |
| 39 | 21 | std::string possible_uid; | |
| 40 | size_t pos; | ||
| 41 | 21 | std::string newline; | |
| 42 | |||
| 43 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | IdfObject idfObject(openstudio::IddObjectType::EnergyManagementSystem_Program); |
| 44 |
1/1✓ Branch 1 taken 21 times.
|
21 | m_idfObjects.push_back(idfObject); |
| 45 | //m_map.insert(std::make_pair(modelObject.handle(), idfObject)); | ||
| 46 | //Name | ||
| 47 |
1/1✓ Branch 1 taken 21 times.
|
21 | s = modelObject.name(); |
| 48 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
21 | if (s) { |
| 49 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | idfObject.setName(*s); |
| 50 | } | ||
| 51 | |||
| 52 |
1/1✓ Branch 1 taken 21 times.
|
21 | const Model m = modelObject.model(); |
| 53 | 21 | boost::optional<ModelObject> mObject; | |
| 54 | |||
| 55 |
3/3✓ Branch 1 taken 21 times.
✓ Branch 8 taken 33 times.
✓ Branch 9 taken 21 times.
|
54 | for (const IdfExtensibleGroup& eg : modelObject.extensibleGroups()) { |
| 56 |
1/1✓ Branch 1 taken 33 times.
|
33 | OptionalString line = eg.getString(OS_EnergyManagementSystem_ProgramExtensibleFields::ProgramLine); |
| 57 | // If there is actually something in the line | ||
| 58 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | if (line) { |
| 59 | // Then, we push an extensible group (E+ fatals out if program line is empty) | ||
| 60 |
1/1✓ Branch 1 taken 33 times.
|
33 | IdfExtensibleGroup group = idfObject.pushExtensibleGroup(); |
| 61 | //find uids | ||
| 62 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
|
33 | newline = line.get(); |
| 63 |
4/4✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
✓ Branch 9 taken 33 times.
✓ Branch 14 taken 33 times.
|
33 | boost::sregex_token_iterator j(line.get().begin(), line.get().end(), uuidInString(), subs); |
| 64 | |||
| 65 |
3/3✓ Branch 2 taken 60 times.
✓ Branch 5 taken 27 times.
✓ Branch 6 taken 33 times.
|
60 | while (j != boost::sregex_token_iterator()) { |
| 66 |
3/3✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
|
27 | possible_uid = *j++; |
| 67 | //look to see if uid is in the model and return the object | ||
| 68 |
1/1✓ Branch 1 taken 27 times.
|
27 | UUID uid = toUUID(possible_uid); |
| 69 |
1/1✓ Branch 1 taken 27 times.
|
27 | mObject = m.getModelObject<model::ModelObject>(uid); |
| 70 |
1/2✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
|
27 | if (mObject) { |
| 71 | //replace uid with namestring | ||
| 72 | 27 | pos = newline.find(possible_uid); | |
| 73 |
1/2✓ Branch 1 taken 27 times.
✗ Branch 2 not taken.
|
27 | if (pos + 38 <= newline.length()) { |
| 74 |
3/3✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
|
27 | newline.replace(pos, 38, mObject.get().nameString()); |
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 |
1/1✓ Branch 1 taken 33 times.
|
33 | group.setString(EnergyManagementSystem_ProgramExtensibleFields::ProgramLine, newline); |
| 79 |
1/1✓ Branch 1 taken 33 times.
|
33 | OptionalString comment = eg.fieldComment(OS_EnergyManagementSystem_ProgramExtensibleFields::ProgramLine); |
| 80 |
1/2✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 | if (comment) { |
| 81 |
2/2✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
|
33 | group.setFieldComment(EnergyManagementSystem_ProgramExtensibleFields::ProgramLine, comment.get()); |
| 82 | } | ||
| 83 | 33 | } | |
| 84 | 54 | } | |
| 85 |
1/1✓ Branch 1 taken 21 times.
|
42 | return idfObject; |
| 86 | 21 | } | |
| 87 | |||
| 88 | } // namespace energyplus | ||
| 89 | |||
| 90 | } // namespace openstudio | ||
| 91 |