Skip to content

Commit

Permalink
Fix version translation and backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
macumber committed Jul 6, 2016
1 parent 706b58d commit 42a7787
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 9 deletions.
24 changes: 24 additions & 0 deletions openstudiocore/ruby/openstudio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,32 @@

# "typedefs" for backwards compatibility
module OpenStudio

# support for deprecated names
class IdfObject
def to_Meter
return to_OutputMeter
end
end

module Model

# support for deprecated names
class Model
def getMeter(handle)
return getOutputMeter(handle)
end
def getMeters
return getOutputMeters
end
def getMeterByName(name)
return getOutputMeterByName(name)
end
def getMetersByName(name)
return getOutputMetersByName(name)
end
end

# support for name deprecated as of 1.12.1
class Meter < OutputMeter
end
Expand Down
25 changes: 24 additions & 1 deletion openstudiocore/ruby/openstudio_dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
require 'openstudiomodeleditor'
require 'openstudioanalysis'
require 'openstudiolib'
require 'openstudioosversion'
require 'openstudioisomodel'
require 'openstudiosdd'

Expand Down Expand Up @@ -182,8 +181,32 @@

# "typedefs" for backwards compatibility
module OpenStudio

# support for deprecated names
class IdfObject
def to_Meter
return to_OutputMeter
end
end

module Model

# support for deprecated names
class Model
def getMeter(handle)
return getOutputMeter(handle)
end
def getMeters
return getOutputMeters
end
def getMeterByName(name)
return getOutputMeterByName(name)
end
def getMetersByName(name)
return getOutputMetersByName(name)
end
end

# support for name deprecated as of 1.12.1
class Meter < OutputMeter
end
Expand Down
12 changes: 12 additions & 0 deletions openstudiocore/src/openstudio_app/OpenStudioApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,24 @@ void OpenStudioApp::buildCompLibraries()
path p = resourcesPath() / toPath("MinimalTemplate.osm");
OS_ASSERT(exists(p));
boost::optional<Model> temp = versionTranslator.loadModel(p);
if (!temp){
LOG_FREE(Error, "OpenStudioApp", "Failed to load MinimalTemplate");
for (const auto& error : versionTranslator.errors()){
LOG_FREE(Error, "OpenStudioApp", error.logMessage());
}
}
OS_ASSERT(temp);
m_compLibrary = temp.get();

p = resourcesPath() / toPath("hvaclibrary/hvac_library.osm");
OS_ASSERT(exists(p));
temp = versionTranslator.loadModel(p);
if (!temp){
LOG_FREE(Error, "OpenStudioApp", "Failed to load hvaclibrary");
for (const auto& error : versionTranslator.errors()){
LOG_FREE(Error, "OpenStudioApp", error.logMessage());
}
}
OS_ASSERT(temp);
m_hvacCompLibrary = temp.get();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

OS:Version,
{d39ef75f-e352-424a-af0f-2c00d6612a2b}, !- Handle
1.12.0; !- Version Identifier
1.12.1; !- Version Identifier

OS:Schedule:Constant,
{9f54092d-a4a8-41b8-a381-c4c332ecb843}, !- Handle
Expand Down
12 changes: 6 additions & 6 deletions openstudiocore/src/osversion/VersionTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ VersionTranslator::VersionTranslator()
m_updateMethods[VersionString("1.10.6")] = &VersionTranslator::update_1_10_5_to_1_10_6;
m_updateMethods[VersionString("1.11.4")] = &VersionTranslator::update_1_11_3_to_1_11_4;
m_updateMethods[VersionString("1.11.5")] = &VersionTranslator::update_1_11_4_to_1_11_5;
m_updateMethods[VersionString("1.12.1")] = &VersionTranslator::update_1_12_1_to_1_12_2;
m_updateMethods[VersionString("1.12.1")] = &VersionTranslator::update_1_12_0_to_1_12_1;
m_updateMethods[VersionString("1.12.2")] = &VersionTranslator::defaultUpdate;


Expand Down Expand Up @@ -3279,20 +3279,20 @@ std::string VersionTranslator::update_1_11_4_to_1_11_5(const IdfFile& idf_1_11_4
return ss.str();
}

std::string VersionTranslator::update_1_12_1_to_1_12_2(const IdfFile& idf_1_12_1, const IddFileAndFactoryWrapper& idd_1_12_2) {
std::string VersionTranslator::update_1_12_0_to_1_12_1(const IdfFile& idf_1_12_0, const IddFileAndFactoryWrapper& idd_1_12_1) {
std::stringstream ss;

ss << idf_1_12_1.header() << std::endl << std::endl;
ss << idf_1_12_0.header() << std::endl << std::endl;

// new version object
IdfFile targetIdf(idd_1_12_2.iddFile());
IdfFile targetIdf(idd_1_12_1.iddFile());
ss << targetIdf.versionObject().get();

for (const IdfObject& object : idf_1_12_1.objects()) {
for (const IdfObject& object : idf_1_12_0.objects()) {
auto iddname = object.iddObject().name();

if (iddname == "OS:Meter") {
auto iddObject = idd_1_12_2.getObject("OS:OutputMeter");
auto iddObject = idd_1_12_1.getObject("OS:Output:Meter");
IdfObject newObject(iddObject.get());

size_t newi = 0;
Expand Down
2 changes: 1 addition & 1 deletion openstudiocore/src/osversion/VersionTranslator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class OSVERSION_API VersionTranslator {
std::string update_1_10_5_to_1_10_6(const IdfFile& idf_1_10_5, const IddFileAndFactoryWrapper& idd_1_10_6);
std::string update_1_11_3_to_1_11_4(const IdfFile& idf_1_11_3, const IddFileAndFactoryWrapper& idd_1_11_4);
std::string update_1_11_4_to_1_11_5(const IdfFile& idf_1_11_4, const IddFileAndFactoryWrapper& idd_1_11_5);
std::string update_1_12_1_to_1_12_2(const IdfFile& idf_1_12_1, const IddFileAndFactoryWrapper& idd_1_12_2);
std::string update_1_12_0_to_1_12_1(const IdfFile& idf_1_12_0, const IddFileAndFactoryWrapper& idd_1_12_1);

IdfObject updateUrlField_0_7_1_to_0_7_2(const IdfObject& object, unsigned index);

Expand Down

1 comment on commit 42a7787

@nrel-bot-3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jmarrec_merge (macumber) - x86_64-MacOS-10.10-clang: OK (2405 of 2447 tests passed, 0 test warnings)

Build Badge Test Badge

Please sign in to comment.