GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 4 / 1 / 5
Functions: 100.0% 4 / 1 / 5
Branches: 100.0% 3 / 1 / 4

src/osversion/VersionTranslator.hpp
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 #ifndef OSVERSION_VERSIONTRANSLATOR_HPP
7 #define OSVERSION_VERSIONTRANSLATOR_HPP
8
9 #include "OSVersionAPI.hpp"
10
11 #include "../model/Schedule.hpp"
12
13 #include "../utilities/idf/IdfFile.hpp"
14 #include "../utilities/idd/IddFile.hpp"
15 #include "../utilities/idd/IddFileAndFactoryWrapper.hpp"
16
17 #include "../utilities/idf/IdfObject.hpp"
18 #include "../utilities/idd/IddObject.hpp"
19
20 #include "../utilities/core/Compare.hpp"
21 #include "../utilities/core/Logger.hpp"
22 #include "../utilities/core/StringStreamLogSink.hpp"
23
24 #include <boost/functional.hpp>
25
26 #include <map>
27 #include <istream>
28 #include <string>
29 #include <set>
30
31 namespace openstudio {
32 class ProgressBar;
33 namespace model {
34 class Model;
35 class Component;
36 } // namespace model
37 namespace osversion {
38
39 /** Helper class meant to replace std::pair<IdfObject, IdfObject> that maps objects that have been significantly refactor (old, new) */
40 class OSVERSION_API RefactoredObjectData
41 {
42 public:
43 RefactoredObjectData(const IdfObject& old, const IdfObject& newObject);
44 RefactoredObjectData(IdfObject&& old, IdfObject&& newObject);
45
46 IdfObject oldObject() const;
47 IdfObject newObject() const;
48
49 private:
50 IdfObject m_oldObject;
51 IdfObject m_newObject;
52 };
53
54 /** This class updates OpenStudio Models and Components to the latest version of OpenStudio. It
55 * must be maintained to keep everything working. The developer who is wrapping up the current
56 * release and starting the next one should:
57 *
58 * <ol>
59 * <li> Run openstudio_osversion_tests.exe and verify that all the tests pass. </li>
60 * <li> Create the release branch. </li>
61 * <li> Copy the latest resources/osversion folder from the build directory to the source
62 * directory, add those files to the resources/CMakeLists.txt, and commit to trunk. </li>
63 * <li> Increment the OpenStudio version in CMakeLists.txt </li>
64 * <li> Increment the OpenStudio version in openstudiocore/resources/model/OpenStudio.idd (at the
65 * top and in the \\default of OS:Version's Version Identifier field). </li>
66 * <li> Register a trivial update method for the new version in the constructor. Further
67 * instructions are provided in the cpp code for VersionTranslator::VersionTranslator. </li>
68 * <li> Add the just-branched-for-release version number to m_startVersions, also in the
69 * constructor. </li>
70 * </ol>
71 *
72 * To support the current iteration, developers should:
73 *
74 * <ol>
75 * <li> Create a non-trivial update method upon the first IDD or other change that should result
76 * in data changes to models of the earlier vintages. </li>
77 * <li> Add to this non-trivial update method should any other such changes occur during the
78 * iteration. </li>
79 * <li> Feel free to just log warnings and errors if the desirable changes cannot be reliably
80 * completed at the data (IDF) level. Such messages could prompt the user to take specific
81 * actions in the OpenStudio Application once they have a nominally valid (updated) model. </li>
82 * </ol>
83 * */
84 class OSVERSION_API VersionTranslator
85 {
86 public:
87 /** @name Constructors and Destructors */
88 //@{
89
90 VersionTranslator();
91
92 //@}
93 /** @name Actions
94 *
95 * Update files on disk to the current version of OpenStudio. */
96 //@{
97
98 /** Returns a current-version OpenStudio Model, if possible. The file at pathToOldOsm must
99 * be an osm of version 0.7.0 or later. */
100 boost::optional<model::Model> loadModel(const openstudio::path& pathToOldOsm, ProgressBar* progressBar = nullptr);
101
102 /** \overload */
103 boost::optional<model::Model> loadModel(std::istream& is, ProgressBar* progressBar = nullptr);
104
105 /** Load a model from string. Not overloading loadModel so paths passed as strings in bindings will work.*/
106 boost::optional<model::Model> loadModelFromString(const std::string& str, ProgressBar* progressBar = nullptr);
107
108 /** Returns a current-version OpenStudio Component, if possible. The file at pathToOldOsc
109 * must be an osc of version 0.7.0 or later. */
110 boost::optional<model::Component> loadComponent(const openstudio::path& pathToOldOsc, ProgressBar* progressBar = nullptr);
111
112 /** \overload */
113 boost::optional<model::Component> loadComponent(std::istream& is, ProgressBar* progressBar = nullptr);
114
115 //@}
116 /** @name Queries
117 *
118 * Access warnings, errors, and other information about the last translation process. All this
119 * data is cleared by subsequent calls to loadModel or loadComponent. */
120 //@{
121
122 /** Get the version of the loaded file. Is 0.0.0 before loadModel or loadComponent is called.
123 * 0.7.0 is the default if no Version object is found in the file. */
124 VersionString originalVersion() const;
125
126 /** Get warning messages generated by the last translation. */
127 std::vector<LogMessage> warnings() const;
128
129 /** Get error messages generated by the last translation. */
130 std::vector<LogMessage> errors() const;
131
132 /** Returns objects that were removed from the model because the object type or particular use
133 * has been deprecated. */
134 std::vector<IdfObject> deprecatedObjects() const;
135
136 /** Returns objects that were removed from the model because there is not a straightforward,
137 * unique way to upgrade them. */
138 std::vector<IdfObject> untranslatedObjects() const;
139
140 /** Returns objects that were added to the model to make it work properly in the latest
141 * version of OpenStudio. */
142 std::vector<IdfObject> newObjects() const;
143
144 /** Returns an (original object, new object) pair for objects that have been significantly
145 * refactored. */
146 std::vector<RefactoredObjectData> refactoredObjects() const;
147
148 /** Returns true if loading newer versions is allowable. Defaults to true. */
149 bool allowNewerVersions() const;
150
151 /** Set whether or not loading newer versions is allowed. */
152 void setAllowNewerVersions(bool allowNewerVersions);
153
154 //@}
155 private:
156 − REGISTER_LOGGER("openstudio.osversion.VersionTranslator");
157
158 using OSVersionUpdater = boost::function<std::string(VersionTranslator*, const IdfFile&, const IddFileAndFactoryWrapper&)>;
159 std::map<VersionString, OSVersionUpdater> m_updateMethods;
160 std::vector<VersionString> m_startVersions;
161
162 VersionString m_originalVersion;
163 bool m_allowNewerVersions;
164 std::map<VersionString, IdfFile> m_map;
165 StringStreamLogSink m_logSink;
166 std::vector<IdfObject> m_deprecated, m_untranslated, m_new;
167 std::vector<RefactoredObjectData> m_refactored;
168 int m_nObjectsStart;
169 int m_nObjectsFinalIdf;
170 int m_nObjectsFinalModel;
171 bool m_isComponent;
172 std::vector<IdfObject> m_cbeccSizingObjects;
173
174 boost::optional<model::Model> updateVersion(std::istream& is, bool isComponent, ProgressBar* progressBar = nullptr);
175
176 void initializeMap(std::istream& is);
177
178 IddFileAndFactoryWrapper getIddFile(const VersionString& version);
179
180 void update(const VersionString& startVersion);
181
182 /** Deletes handles from m_untranslated and m_deprecated, and adds handles from m_new */
183 void updateComponentData(IdfFile& idfFile);
184
185 std::string defaultUpdate(const IdfFile& idf, const IddFileAndFactoryWrapper& targetIdd);
186 std::string update_0_7_1_to_0_7_2(const IdfFile& idf_0_7_1, const IddFileAndFactoryWrapper& idd_0_7_2);
187 std::string update_0_7_2_to_0_7_3(const IdfFile& idf_0_7_2, const IddFileAndFactoryWrapper& idd_0_7_3);
188 std::string update_0_7_3_to_0_7_4(const IdfFile& idf_0_7_3, const IddFileAndFactoryWrapper& idd_0_7_4);
189 std::string update_0_9_1_to_0_9_2(const IdfFile& idf_0_9_1, const IddFileAndFactoryWrapper& idd_0_9_2);
190 std::string update_0_9_5_to_0_9_6(const IdfFile& idf_0_9_5, const IddFileAndFactoryWrapper& idd_0_9_6);
191 std::string update_0_9_6_to_0_10_0(const IdfFile& idf_0_9_6, const IddFileAndFactoryWrapper& idd_0_10_0);
192 std::string update_0_11_0_to_0_11_1(const IdfFile& idf_0_11_0, const IddFileAndFactoryWrapper& idd_0_11_1);
193 std::string update_0_11_1_to_0_11_2(const IdfFile& idf_0_11_1, const IddFileAndFactoryWrapper& idd_0_11_2);
194 std::string update_0_11_4_to_0_11_5(const IdfFile& idf_0_11_4, const IddFileAndFactoryWrapper& idd_0_11_5);
195 std::string update_0_11_5_to_0_11_6(const IdfFile& idf_0_11_5, const IddFileAndFactoryWrapper& idd_0_11_6);
196 std::string update_1_0_1_to_1_0_2(const IdfFile& idf_1_0_1, const IddFileAndFactoryWrapper& idd_1_0_2);
197 std::string update_1_0_2_to_1_0_3(const IdfFile& idf_1_0_2, const IddFileAndFactoryWrapper& idd_1_0_3);
198 std::string update_1_2_2_to_1_2_3(const IdfFile& idf_1_2_2, const IddFileAndFactoryWrapper& idd_1_2_3);
199 std::string update_1_3_4_to_1_3_5(const IdfFile& idf_1_3_4, const IddFileAndFactoryWrapper& idd_1_3_5);
200 std::string update_1_5_3_to_1_5_4(const IdfFile& idf_1_5_3, const IddFileAndFactoryWrapper& idd_1_5_4);
201 std::string update_1_7_1_to_1_7_2(const IdfFile& idf_1_7_1, const IddFileAndFactoryWrapper& idd_1_7_2);
202 std::string update_1_7_4_to_1_7_5(const IdfFile& idf_1_7_4, const IddFileAndFactoryWrapper& idd_1_7_5);
203 std::string update_1_8_3_to_1_8_4(const IdfFile& idf_1_8_3, const IddFileAndFactoryWrapper& idd_1_8_4);
204 std::string update_1_8_4_to_1_8_5(const IdfFile& idf_1_8_4, const IddFileAndFactoryWrapper& idd_1_8_5);
205 std::string update_1_8_5_to_1_9_0(const IdfFile& idf_1_8_5, const IddFileAndFactoryWrapper& idd_1_9_0);
206 std::string update_1_9_2_to_1_9_3(const IdfFile& idf_1_9_2, const IddFileAndFactoryWrapper& idd_1_9_3);
207 std::string update_1_9_4_to_1_9_5(const IdfFile& idf_1_9_4, const IddFileAndFactoryWrapper& idd_1_9_5);
208 std::string update_1_9_5_to_1_10_0(const IdfFile& idf_1_9_5, const IddFileAndFactoryWrapper& idd_1_10_0);
209 std::string update_1_10_1_to_1_10_2(const IdfFile& idf_1_10_1, const IddFileAndFactoryWrapper& idd_1_10_2);
210 std::string update_1_10_5_to_1_10_6(const IdfFile& idf_1_10_5, const IddFileAndFactoryWrapper& idd_1_10_6);
211 std::string update_1_11_3_to_1_11_4(const IdfFile& idf_1_11_3, const IddFileAndFactoryWrapper& idd_1_11_4);
212 std::string update_1_11_4_to_1_11_5(const IdfFile& idf_1_11_4, const IddFileAndFactoryWrapper& idd_1_11_5);
213 std::string update_1_12_0_to_1_12_1(const IdfFile& idf_1_12_0, const IddFileAndFactoryWrapper& idd_1_12_1);
214 std::string update_1_12_3_to_1_12_4(const IdfFile& idf_1_12_3, const IddFileAndFactoryWrapper& idd_1_12_4);
215 std::string update_2_1_0_to_2_1_1(const IdfFile& idf_2_1_0, const IddFileAndFactoryWrapper& idd_2_1_1);
216 std::string update_2_1_1_to_2_1_2(const IdfFile& idf_2_1_1, const IddFileAndFactoryWrapper& idd_2_1_2);
217 std::string update_2_3_0_to_2_3_1(const IdfFile& idf_2_3_0, const IddFileAndFactoryWrapper& idd_2_3_1);
218 std::string update_2_4_1_to_2_4_2(const IdfFile& idf_2_4_1, const IddFileAndFactoryWrapper& idd_2_4_2);
219 std::string update_2_4_3_to_2_5_0(const IdfFile& idf_2_4_3, const IddFileAndFactoryWrapper& idd_2_5_0);
220 std::string update_2_6_0_to_2_6_1(const IdfFile& idf_2_6_0, const IddFileAndFactoryWrapper& idd_2_6_1);
221 std::string update_2_6_1_to_2_6_2(const IdfFile& idf_2_6_1, const IddFileAndFactoryWrapper& idd_2_6_2);
222 std::string update_2_6_2_to_2_7_0(const IdfFile& idf_2_6_2, const IddFileAndFactoryWrapper& idd_2_7_0);
223 std::string update_2_7_0_to_2_7_1(const IdfFile& idf_2_7_0, const IddFileAndFactoryWrapper& idd_2_7_1);
224 std::string update_2_7_1_to_2_7_2(const IdfFile& idf_2_7_1, const IddFileAndFactoryWrapper& idd_2_7_2);
225 std::string update_2_8_1_to_2_9_0(const IdfFile& idf_2_8_1, const IddFileAndFactoryWrapper& idd_2_9_0);
226 std::string update_2_9_0_to_2_9_1(const IdfFile& idf_2_9_0, const IddFileAndFactoryWrapper& idd_2_9_1);
227 std::string update_2_9_1_to_3_0_0(const IdfFile& idf_2_9_1, const IddFileAndFactoryWrapper& idd_3_0_0);
228 std::string update_3_0_0_to_3_0_1(const IdfFile& idf_3_0_0, const IddFileAndFactoryWrapper& idd_3_0_1);
229 std::string update_3_0_1_to_3_1_0(const IdfFile& idf_3_0_1, const IddFileAndFactoryWrapper& idd_3_1_0);
230 std::string update_3_1_0_to_3_2_0(const IdfFile& idf_3_1_0, const IddFileAndFactoryWrapper& idd_3_2_0);
231 std::string update_3_2_0_to_3_2_1(const IdfFile& idf_3_2_0, const IddFileAndFactoryWrapper& idd_3_2_1);
232 std::string update_3_2_1_to_3_3_0(const IdfFile& idf_3_2_1, const IddFileAndFactoryWrapper& idd_3_3_0);
233 std::string update_3_3_0_to_3_4_0(const IdfFile& idf_3_3_0, const IddFileAndFactoryWrapper& idd_3_4_0);
234 std::string update_3_4_0_to_3_5_0(const IdfFile& idf_3_4_0, const IddFileAndFactoryWrapper& idd_3_5_0);
235 std::string update_3_5_0_to_3_5_1(const IdfFile& idf_3_5_0, const IddFileAndFactoryWrapper& idd_3_5_1);
236 std::string update_3_5_1_to_3_6_0(const IdfFile& idf_3_5_1, const IddFileAndFactoryWrapper& idd_3_6_0);
237 std::string update_3_6_1_to_3_7_0(const IdfFile& idf_3_6_1, const IddFileAndFactoryWrapper& idd_3_7_0);
238 std::string update_3_7_0_to_3_8_0(const IdfFile& idf_3_7_0, const IddFileAndFactoryWrapper& idd_3_8_0);
239 std::string update_3_8_0_to_3_9_0(const IdfFile& idf_3_8_0, const IddFileAndFactoryWrapper& idd_3_9_0);
240 std::string update_3_9_0_to_3_10_0(const IdfFile& idf_3_9_0, const IddFileAndFactoryWrapper& idd_3_10_0);
241 std::string update_3_10_0_to_3_11_0(const IdfFile& idf_3_10_0, const IddFileAndFactoryWrapper& idd_3_11_0);
242 std::string update_3_11_0_to_3_12_0(const IdfFile& idf_3_11_0, const IddFileAndFactoryWrapper& idd_3_12_0);
243
244 IdfObject updateUrlField_0_7_1_to_0_7_2(const IdfObject& object, unsigned index);
245
246 struct InterobjectIssueInformation
247 {
248 VersionString endVersion;
249 1 InterobjectIssueInformation(const VersionString& t_endVersion) : endVersion(t_endVersion) {}
250 1 virtual ~InterobjectIssueInformation() = default;
251 };
252
253 std::vector<std::shared_ptr<InterobjectIssueInformation>> fixInterobjectIssuesStage1(model::Model& model, const VersionString& startVersion);
254
255 void fixInterobjectIssuesStage2(model::Model& model, std::vector<std::shared_ptr<InterobjectIssueInformation>>& stage1Information);
256
257 struct InterobjectIssueInformation_0_8_3_to_0_8_4 : public InterobjectIssueInformation
258 {
259 std::vector<model::Schedule> schedules;
260 std::vector<std::vector<model::ModelObject>> users;
261 std::vector<std::vector<std::vector<unsigned>>> indices;
262 std::vector<std::vector<std::vector<model::ScheduleTypeKey>>> keys;
263 std::vector<std::vector<IdfObject>> componentDataObjects;
264 std::vector<IdfObject> originalUsers;
265 std::set<model::ModelObject> refactoredUsers;
266
267
3/3
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
3 InterobjectIssueInformation_0_8_3_to_0_8_4() : InterobjectIssueInformation(VersionString("0.8.4")) {}
268 1 virtual ~InterobjectIssueInformation_0_8_3_to_0_8_4() = default;
269 };
270
271 std::shared_ptr<InterobjectIssueInformation> fixInterobjectIssuesStage1_0_8_3_to_0_8_4(model::Model& model);
272
273 void fixInterobjectIssuesStage2_0_8_3_to_0_8_4(model::Model& model, std::shared_ptr<InterobjectIssueInformation>& info);
274 };
275
276 } // namespace osversion
277 } // namespace openstudio
278
279 #endif // OSVERSION_VERSIONTRANSLATOR_HPP
280