Skip to content

Commit

Permalink
Merge pull request #4513 from NREL/issue-4457
Browse files Browse the repository at this point in the history
Addresses #4457, support gbXML translation where user-input <Name> is different from the id
  • Loading branch information
joseph-robertson authored Feb 19, 2022
2 parents 2f385d4 + f67050a commit d75af8b
Show file tree
Hide file tree
Showing 12 changed files with 39,866 additions and 218 deletions.
1 change: 1 addition & 0 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ SET(gbxml_resources_src
gbxml/3951_Geometry_bug.xml
gbxml/3997_WindowScaling_bug.xml
gbxml/TestSchedules.xml
gbxml/gbXMLStandard_Single_Family_Residential_2016.xml
gbxml/TropicBird_BEM_4_2018.xml
gbxml/TropicBird.xml
)
Expand Down
39,017 changes: 39,017 additions & 0 deletions resources/gbxml/gbXMLStandard_Single_Family_Residential_2016.xml

Large diffs are not rendered by default.

87 changes: 40 additions & 47 deletions src/gbxml/ForwardTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,8 @@ namespace gbxml {
auto result = parent.append_child("Space");
m_translatedObjects[space.handle()] = result;

// id
std::string name = space.name().get();
result.append_attribute("id") = escapeName(name).c_str();
translateId(space, result);
translateName(space, result);

// space type
//boost::optional<model::SpaceType> spaceType = space.spaceType();
Expand All @@ -651,10 +650,6 @@ namespace gbxml {
result.append_attribute("buildingStoreyIdRef") = escapeName(storyName).c_str();
}

// name
auto nameElement = result.append_child("Name");
nameElement.text() = name.c_str();

// append floor area
double area = space.floorArea();
auto areaElement = result.append_child("Area");
Expand Down Expand Up @@ -718,13 +713,8 @@ namespace gbxml {
auto result = parent.append_child("Space");
m_translatedObjects[shadingSurfaceGroup.handle()] = result;

// id
std::string name = shadingSurfaceGroup.name().get();
result.append_attribute("id") = escapeName(name).c_str();

// name
auto nameElement = result.append_child("Name");
nameElement.text() = name.c_str();
translateId(shadingSurfaceGroup, result);
translateName(shadingSurfaceGroup, result);

return result;
}
Expand Down Expand Up @@ -755,13 +745,8 @@ namespace gbxml {
auto result = parent.append_child("BuildingStorey");
m_translatedObjects[story.handle()] = result;

// id
std::string name = story.name().get();
result.append_attribute("id") = escapeName(name).c_str();

// name
auto nameElement = result.append_child("Name");
nameElement.text() = name.c_str();
translateId(story, result);
translateName(story, result);

// append level
auto levelElement = result.append_child("Level");
Expand All @@ -779,9 +764,8 @@ namespace gbxml {
auto result = parent.append_child("Surface");
m_translatedObjects[surface.handle()] = result;

// id
std::string name = surface.name().get();
result.append_attribute("id") = escapeName(name).c_str();
translateId(surface, result);
translateName(surface, result);

// DLM: currently unhandled
//FreestandingColumn
Expand Down Expand Up @@ -995,9 +979,8 @@ namespace gbxml {
auto result = parent.append_child("Opening");
m_translatedObjects[subSurface.handle()] = result;

// id
std::string name = subSurface.name().get();
result.append_attribute("id") = escapeName(name).c_str();
translateId(subSurface, result);
translateName(subSurface, result);

// construction
boost::optional<model::ConstructionBase> construction = subSurface.construction();
Expand Down Expand Up @@ -1149,9 +1132,8 @@ namespace gbxml {
auto result = parent.append_child("Surface");
m_translatedObjects[shadingSurface.handle()] = result;

// id
std::string name = shadingSurface.name().get();
result.append_attribute("id") = escapeName(name).c_str();
translateId(shadingSurface, result);
translateName(shadingSurface, result);

result.append_attribute("surfaceType") = "Shade";

Expand Down Expand Up @@ -1292,13 +1274,8 @@ namespace gbxml {
auto result = parent.append_child("Zone");
m_translatedObjects[thermalZone.handle()] = result;

// id
std::string name = thermalZone.name().get();
result.append_attribute("id") = escapeName(name).c_str();

// name
auto nameElement = result.append_child("Name");
nameElement.text() = name.c_str();
translateId(thermalZone, result);
translateName(thermalZone, result);

// heating setpoint
boost::optional<double> designHeatT;
Expand Down Expand Up @@ -1350,22 +1327,38 @@ namespace gbxml {
return result;
}

void ForwardTranslator::translateId(const openstudio::model::ModelObject& modelObject, pugi::xml_node& parentElement) {

std::string id = modelObject.name().get();
if (modelObject.gbXMLId()) {
id = modelObject.gbXMLId().get();
}
parentElement.append_attribute("id") = escapeName(id).c_str();
}

void ForwardTranslator::translateName(const openstudio::model::ModelObject& modelObject, pugi::xml_node& parentElement) {

std::string name = modelObject.name().get();
if (modelObject.displayName()) {
name = modelObject.displayName().get();
}
parentElement.append_child("Name").text() = name.c_str();
}

boost::optional<pugi::xml_node> ForwardTranslator::translateCADObjectId(const openstudio::model::ModelObject& modelObject,
pugi::xml_node& parentElement) {
boost::optional<pugi::xml_node> result;

if (modelObject.hasAdditionalProperties()) {
model::AdditionalProperties additionalProperties = modelObject.additionalProperties();
if (additionalProperties.hasFeature("CADObjectId")) {
boost::optional<std::string> cadObjectId = additionalProperties.getFeatureAsString("CADObjectId");
if (cadObjectId) {
if (additionalProperties.hasFeature("programIdRef")) {
boost::optional<std::string> programIdRef = additionalProperties.getFeatureAsString("programIdRef");
if (programIdRef) {
auto cadObjectIdElement = parentElement.append_child("CADObjectId");
cadObjectIdElement.append_attribute("programIdRef") = (*programIdRef).c_str();
result = cadObjectIdElement;
}
if (boost::optional<std::string> cadObjectId = modelObject.cadObjectId()) {
auto cadObjectIdElement = parentElement.append_child("CADObjectId");
cadObjectIdElement.text() = (*cadObjectId).c_str();
result = cadObjectIdElement;
if (additionalProperties.hasFeature("programIdRef")) {
boost::optional<std::string> programIdRef = additionalProperties.getFeatureAsString("programIdRef");
if (programIdRef) {
cadObjectIdElement.append_attribute("programIdRef") = (*programIdRef).c_str();
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/gbxml/ForwardTranslator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ namespace gbxml {
boost::optional<pugi::xml_node> translateLayer(const openstudio::model::Material& material, pugi::xml_node& parent);
boost::optional<pugi::xml_node> translateMaterial(const openstudio::model::Material& material, pugi::xml_node& parent);
boost::optional<pugi::xml_node> translateConstructionBase(const openstudio::model::ConstructionBase& constructionBase, pugi::xml_node& parent);

/** Set id as the model object name, otherwise use the gbXMLId additional property if it exists. */
void translateId(const openstudio::model::ModelObject& modelObject, pugi::xml_node& parentElement);

/** Set the Name as the model object name, otherwise use the displayName additional property if it exists. */
void translateName(const openstudio::model::ModelObject& modelObject, pugi::xml_node& parentElement);

/** Set the CADObjectId as the CADObjectId additional property if it exists. */
boost::optional<pugi::xml_node> translateCADObjectId(const openstudio::model::ModelObject& modelObject, pugi::xml_node& parentElement);

std::map<openstudio::Handle, pugi::xml_node> m_translatedObjects;
Expand Down
59 changes: 14 additions & 45 deletions src/gbxml/MapEnvelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ namespace gbxml {
//openstudio::model::Construction construction = model.getUniqueModelObject<openstudio::model::Construction>();

openstudio::model::Construction construction(model);
std::string constructionId = element.attribute("id").value();
m_idToObjectMap.insert(std::make_pair(constructionId, construction));

std::string constructionName = element.child("Name").text().as_string();
construction.setName(escapeName(constructionId, constructionName));
translateId(element, construction);
translateName(element, construction);

// auto layerIdList = element.children("LayerId");
// Construction::LayerId (layerIdList) -> Layer (layerElements), Layer::MaterialId -> Material
Expand Down Expand Up @@ -118,12 +116,9 @@ namespace gbxml {
boost::optional<openstudio::model::ModelObject> ReverseTranslator::translateWindowType(const pugi::xml_node& element,
openstudio::model::Model& model) {
openstudio::model::Construction construction(model);
std::string windowTypeId = element.attribute("id").value();
m_idToObjectMap.insert(std::make_pair(windowTypeId, construction));
construction.additionalProperties().setFeature("gbXMLId", windowTypeId);

std::string windowTypeName = element.child("Name").text().as_string();
construction.setName(escapeName(windowTypeId, windowTypeName));
translateId(element, construction);
translateName(element, construction);

boost::optional<double> uValue;
boost::optional<double> shgc;
Expand Down Expand Up @@ -190,12 +185,8 @@ namespace gbxml {
openstudio::model::StandardOpaqueMaterial material(model);
result = material;

std::string id = element.attribute("id").value();
m_idToObjectMap.insert(std::make_pair(id, material));
material.additionalProperties().setFeature("gbXMLId", id);

std::string name = element.child("Name").text().as_string();
material.setName(escapeName(id, name));
translateId(element, material);
translateName(element, material);

material.setDensity(density);
material.setThermalConductivity(conductivity);
Expand All @@ -216,12 +207,8 @@ namespace gbxml {
openstudio::model::MasslessOpaqueMaterial material(model);
result = material;

std::string id = element.attribute("id").value();
m_idToObjectMap.insert(std::make_pair(id, material));
material.additionalProperties().setFeature("gbXMLId", id);

std::string name = element.child("Name").text().as_string();
material.setName(escapeName(id, name));
translateId(element, material);
translateName(element, material);

material.setThermalResistance(rvalue);

Expand All @@ -231,14 +218,8 @@ namespace gbxml {
openstudio::model::MasslessOpaqueMaterial material(model);
result = material;

std::string id = element.attribute("id").value();
m_idToObjectMap.insert(std::make_pair(id, material));
material.additionalProperties().setFeature("gbXMLId", id);

std::string name = element.child("Name").text().as_string();
material.setName(escapeName(id, name));

LOG(Warn, "Creating stub material '" << name << "'");
translateId(element, material);
translateName(element, material);

material.setThermalResistance(.001);
}
Expand All @@ -260,14 +241,8 @@ namespace gbxml {
m_translatedObjects[constructionBase.handle()] = *result;
}

std::string name = constructionBase.name().get();

// id
result->append_attribute("id") = escapeName(name).c_str();

// name
auto nameElement = result->append_child("Name");
nameElement.text() = name.c_str();
translateId(constructionBase, *result);
translateName(constructionBase, *result);

if (isOpaque) {
if (constructionBase.optionalCast<model::LayeredConstruction>()) {
Expand Down Expand Up @@ -351,14 +326,8 @@ namespace gbxml {
boost::optional<pugi::xml_node> ForwardTranslator::translateMaterial(const openstudio::model::Material& material, pugi::xml_node& root) {
auto result = root.append_child("Material");

std::string name = material.name().get();

// id
result.append_attribute("id") = escapeName(name).c_str();

// name
auto nameElement = result.append_child("Name");
nameElement.text() = name.c_str();
translateId(material, result);
translateName(material, result);

boost::optional<double> thermalReflectance;
boost::optional<double> solarReflectance;
Expand Down
Loading

0 comments on commit d75af8b

Please sign in to comment.