Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AirLoopHVAC to ThreeJS user data #4407

Merged
2 changes: 1 addition & 1 deletion resources/utilities/Geometry/threejs.json

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion src/model/ThreeJSForwardTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "ConstructionBase_Impl.hpp"
#include "ConstructionAirBoundary.hpp"
#include "ConstructionAirBoundary_Impl.hpp"
#include "AirLoopHVAC.hpp"
#include "AirLoopHVAC_Impl.hpp"
#include "ThermalZone.hpp"
#include "ThermalZone_Impl.hpp"
#include "SpaceType.hpp"
Expand Down Expand Up @@ -149,6 +151,15 @@ namespace model {
makeThreeMaterial(name, toThreeColor(color->renderingRedValue(), color->renderingBlueValue(), color->renderingGreenValue()), 1,
ThreeSide::DoubleSide));
}

// make air loop HVAC materials
for (auto& airLoopHVAC : model.getConcreteModelObjects<AirLoopHVAC>()) {
std::string name = getObjectThreeMaterialName(airLoopHVAC);
boost::optional<RenderingColor> color = RenderingColor(model);
addThreeMaterial(materials, materialMap,
makeThreeMaterial(name, toThreeColor(color->renderingRedValue(), color->renderingBlueValue(), color->renderingGreenValue()), 1,
ThreeSide::DoubleSide));
}
}

size_t getVertexIndex(const Point3d& point3d, std::vector<Point3d>& allPoints, double tol = 0.001) {
Expand Down Expand Up @@ -284,6 +295,11 @@ namespace model {
if (thermalZone) {
userData.setThermalZoneName(thermalZone->nameString());
userData.setThermalZoneMaterialName(getObjectThreeMaterialName(*thermalZone));
std::vector<AirLoopHVAC> airLoopHVACs = thermalZone->airLoopHVACs();
for (const auto& airLoopHVAC : airLoopHVACs) {
userData.addAirLoopHVACName(airLoopHVAC.nameString());
userData.addAirLoopHVACMaterialName(getObjectThreeMaterialName(airLoopHVAC));
}
}

boost::optional<SpaceType> spaceType = space->spaceType();
Expand Down Expand Up @@ -471,11 +487,13 @@ namespace model {
std::vector<BuildingStory> buildingStories = model.getConcreteModelObjects<BuildingStory>();
std::vector<BuildingUnit> buildingUnits = model.getConcreteModelObjects<BuildingUnit>();
std::vector<ThermalZone> thermalZones = model.getConcreteModelObjects<ThermalZone>();
std::vector<AirLoopHVAC> airLoopHVACs = model.getConcreteModelObjects<AirLoopHVAC>();
std::vector<SpaceType> spaceTypes = model.getConcreteModelObjects<SpaceType>();
std::vector<DefaultConstructionSet> defaultConstructionSets = model.getConcreteModelObjects<DefaultConstructionSet>();
double n = 0;
std::vector<PlanarSurface>::size_type N = planarSurfaces.size() + planarSurfaceGroups.size() + buildingStories.size() + buildingUnits.size()
+ thermalZones.size() + spaceTypes.size() + defaultConstructionSets.size() + 1;
+ thermalZones.size() + spaceTypes.size() + defaultConstructionSets.size() + airLoopHVACs.size()
+ 1;

// loop over all surfaces
for (const auto& planarSurface : planarSurfaces) {
Expand Down Expand Up @@ -612,6 +630,14 @@ namespace model {
updatePercentage(100.0 * n / N);
}

for (const auto& airLoopHVAC : airLoopHVACs) {
ThreeModelObjectMetadata airLoopMetaData(airLoopHVAC.iddObjectType().valueDescription(), toString(airLoopHVAC.handle()), airLoopHVAC.nameString());
modelObjectMetadata.push_back(airLoopMetaData);

n += 1;
updatePercentage(100.0 * n / N);
}

double northAxis = 0.0;
boost::optional<Building> building = model.getOptionalUniqueModelObject<Building>();
if (building) {
Expand Down
13 changes: 13 additions & 0 deletions src/utilities/geometry/Test/ThreeJS_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ TEST_F(GeometryFixture, ThreeJS) {
boost::optional<ThreeScene> scene = ThreeScene::load(contents);
ASSERT_TRUE(scene);

// checking user data
std::vector<ThreeSceneChild> sceneChildren = scene->object().children();
for (const ThreeSceneChild& sceneChild : sceneChildren) {
EXPECT_DOUBLE_EQ(1, double(sceneChild.userData().airLoopHVACNames().size()));
jmarrec marked this conversation as resolved.
Show resolved Hide resolved
}

// checking metadata
std::vector<ThreeModelObjectMetadata> metadatas = scene->metadata().modelObjectMetadata();
EXPECT_TRUE(std::any_of(metadatas.cbegin(), metadatas.cend(), [](const auto& metadata) {
return istringEqual("OS:AirLoopHVAC", metadata.iddObjectType()) && istringEqual("Air Loop HVAC 1", metadata.name());
})
);

scene = ThreeScene::load(toString(p));
ASSERT_TRUE(scene);

Expand Down
58 changes: 58 additions & 0 deletions src/utilities/geometry/ThreeJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ std::string getObjectThreeMaterialName(const std::string& iddObjectType, const s
result = "Construction_" + name;
} else if (istringEqual(iddObjectType, "OS:ThermalZone")) {
result = "ThermalZone_" + name;
} else if (istringEqual(iddObjectType, "OS:AirLoopHVAC")) {
result = "AirLoopHVAC_" + name;
} else if (istringEqual(iddObjectType, "OS:SpaceType")) {
result = "SpaceType_" + name;
} else if (istringEqual(iddObjectType, "OS:BuildingStory")) {
Expand Down Expand Up @@ -712,6 +714,9 @@ ThreeUserData::ThreeUserData(const Json::Value& value) {
assertType(value, "windExposure", Json::stringValue);
assertType(value, "illuminanceSetpoint", Json::realValue);
assertType(value, "airWall", Json::booleanValue);
assertType(value, "airLoopHVACNames", Json::arrayValue);
assertType(value, "airLoopHVACHandles", Json::arrayValue);
assertType(value, "airLoopHVACMaterialNames", Json::arrayValue);
//assertType(value, "belowFloorPlenum", Json::booleanValue);
//assertType(value, "aboveCeilingPlenum", Json::booleanValue);

Expand Down Expand Up @@ -754,6 +759,16 @@ ThreeUserData::ThreeUserData(const Json::Value& value) {
m_windExposure = value.get("windExposure", "").asString();
m_illuminanceSetpoint = value.get("illuminanceSetpoint", 0.0).asDouble();
m_airWall = value.get("airWall", false).asBool();
Json::Value airLoopNames = value.get("airLoopHVACNames", Json::arrayValue);
Json::Value airLoopHandles = value.get("airLoopHVACHandles", Json::arrayValue);
Json::Value airLoopMaterialNames = value.get("airLoopHVACMaterialNames", Json::arrayValue);
// OS_ASSERT(airLoopNames.size() == airLoopHandles.size());
// OS_ASSERT(airLoopNames.size() == airLoopMaterialNames.size());
for (Json::ArrayIndex loopIdx = 0; loopIdx < airLoopNames.size(); ++loopIdx) {
m_airLoopHVACNames.push_back(airLoopNames[loopIdx].asString());
m_airLoopHVACHandles.push_back(airLoopHandles[loopIdx].asString());
m_airLoopHVACMaterialNames.push_back(airLoopMaterialNames[loopIdx].asString());
}
//m_belowFloorPlenum = value.get("belowFloorPlenum", "").asBool();
//m_aboveCeilingPlenum = value.get("aboveCeilingPlenum", "").asBool();
}
Expand Down Expand Up @@ -799,6 +814,25 @@ Json::Value ThreeUserData::toJsonValue() const {
result["windExposure"] = m_windExposure;
result["illuminanceSetpoint"] = m_illuminanceSetpoint;
result["airWall"] = m_airWall;

Json::Value airLoopHVACNames(Json::arrayValue);
for (const auto& airLoopName : m_airLoopHVACNames) {
airLoopHVACNames.append(airLoopName);
}
result["airLoopHVACNames"] = airLoopHVACNames;

Json::Value airLoopHVACHandles(Json::arrayValue);
for (const auto& airLoopHandle : m_airLoopHVACHandles) {
airLoopHVACHandles.append(airLoopHandle);
}
result["airLoopHVACHandles"] = airLoopHVACHandles;

Json::Value airLoopHVACMaterialNames(Json::arrayValue);
for (const auto& airLoopHVACMaterialName : m_airLoopHVACMaterialNames) {
airLoopHVACMaterialNames.append(airLoopHVACMaterialName);
}
result["airLoopHVACMaterialNames"] = airLoopHVACMaterialNames;

//result["belowFloorPlenum"] = m_belowFloorPlenum;
//result["aboveCeilingPlenum"] = m_aboveCeilingPlenum;

Expand Down Expand Up @@ -961,6 +995,18 @@ bool ThreeUserData::airWall() const {
return m_airWall;
}

std::vector<std::string> ThreeUserData::airLoopHVACNames() const {
return m_airLoopHVACNames;
}

std::vector<std::string> ThreeUserData::airLoopHVACHandles() const {
return m_airLoopHVACHandles;
}

std::vector<std::string> ThreeUserData::airLoopHVACMaterialNames() const {
return m_airLoopHVACMaterialNames;
}

//bool ThreeUserData::plenum() const
//{
// return (m_belowFloorPlenum || m_aboveCeilingPlenum);
Expand Down Expand Up @@ -1132,6 +1178,18 @@ void ThreeUserData::setAirWall(bool b) {
m_airWall = b;
}

void ThreeUserData::addAirLoopHVACName(const std::string& s) {
m_airLoopHVACNames.push_back(s);
}

void ThreeUserData::addAirLoopHVACHandle(const std::string& s) {
m_airLoopHVACHandles.push_back(s);
}

void ThreeUserData::addAirLoopHVACMaterialName(const std::string& s) {
m_airLoopHVACMaterialNames.push_back(s);
}

//void ThreeUserData::setBelowFloorPlenum(bool v)
//{
// m_belowFloorPlenum = v;
Expand Down
11 changes: 11 additions & 0 deletions src/utilities/geometry/ThreeJS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ class UTILITIES_API ThreeUserData
std::string windExposure() const;
double illuminanceSetpoint() const;
bool airWall() const;

std::vector<std::string> airLoopHVACNames() const;
std::vector<std::string> airLoopHVACHandles() const;
std::vector<std::string> airLoopHVACMaterialNames() const;

//bool plenum() const;
//bool belowFloorPlenum() const;
//bool aboveCeilingPlenum() const;
Expand Down Expand Up @@ -305,6 +310,9 @@ class UTILITIES_API ThreeUserData
void setWindExposure(const std::string& s);
void setIlluminanceSetpoint(double d);
void setAirWall(bool b);
void addAirLoopHVACName(const std::string& s);
void addAirLoopHVACHandle(const std::string& s);
void addAirLoopHVACMaterialName(const std::string& s);
//void setBelowFloorPlenum(bool v);
//void setAboveCeilingPlenum(bool v);

Expand Down Expand Up @@ -353,6 +361,9 @@ class UTILITIES_API ThreeUserData
std::string m_windExposure;
double m_illuminanceSetpoint;
bool m_airWall;
std::vector<std::string> m_airLoopHVACNames;
std::vector<std::string> m_airLoopHVACHandles;
std::vector<std::string> m_airLoopHVACMaterialNames;
//bool m_belowFloorPlenum;
//bool m_aboveCeilingPlenum;
};
Expand Down