From 8fe81e38e03f9379e2845c1c71267e4b2a4ae832 Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 26 Jan 2020 22:18:52 -0500 Subject: [PATCH] feat(door): Allow Shades to be assigned to Doors We recently decided that it was weird that people could not assign shades to Doors but they could to all other geometry objects as noted by [this change in the schema](https://github.com/ladybug-tools-in2/honeybee-schema/pull/24). This commit updates the measure to support this new feature and I also put the code that creates shade groups into a function so that we have less copy/pasted code. --- lib/from_honeybee/geometry/face.rb | 1 - lib/from_honeybee/geometry/room.rb | 55 ++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/from_honeybee/geometry/face.rb b/lib/from_honeybee/geometry/face.rb index 3f65dabd..2a0df81c 100644 --- a/lib/from_honeybee/geometry/face.rb +++ b/lib/from_honeybee/geometry/face.rb @@ -32,7 +32,6 @@ require 'from_honeybee/model_object' require 'from_honeybee/geometry/aperture' require 'from_honeybee/geometry/door' -require 'from_honeybee/geometry/shade' require 'openstudio' diff --git a/lib/from_honeybee/geometry/room.rb b/lib/from_honeybee/geometry/room.rb index 3066af35..4ae93f99 100644 --- a/lib/from_honeybee/geometry/room.rb +++ b/lib/from_honeybee/geometry/room.rb @@ -103,18 +103,13 @@ def to_openstudio(openstudio_model) openstudio_surface = ladybug_face.to_openstudio(openstudio_model) openstudio_surface.setSpace(os_space) - # TODO: process all air walls between Roooms + # TODO: process all air walls between Rooms # assign face-level shades if they exist if face[:outdoor_shades] - os_shd_group = OpenStudio::Model::ShadingSurfaceGroup.new(openstudio_model) - os_shd_group.setShadedSurface(openstudio_surface) - os_shd_group.setSpace(os_space) - os_shd_group.setShadingSurfaceType("Space") + os_shd_group = make_shade_group(openstudio_model, openstudio_surface, os_space) face[:outdoor_shades].each do |outdoor_shade| - hb_outdoor_shade = Shade.new(outdoor_shade) - os_outdoor_shade = hb_outdoor_shade.to_openstudio(openstudio_model) - os_outdoor_shade.setShadingSurfaceGroup(os_shd_group) + add_shade_to_group(openstudio_model, os_shd_group, outdoor_shade) end end @@ -123,15 +118,24 @@ def to_openstudio(openstudio_model) face[:apertures].each do |aperture| if aperture[:outdoor_shades] unless os_shd_group - os_shd_group = OpenStudio::Model::ShadingSurfaceGroup.new(openstudio_model) - os_shd_group.setShadedSurface(openstudio_surface) - os_shd_group.setSpace(os_space) - os_shd_group.setShadingSurfaceType("Space") + os_shd_group = make_shade_group(openstudio_model, openstudio_surface, os_space) end aperture[:outdoor_shades].each do |outdoor_shade| - hb_outdoor_shade = Shade.new(outdoor_shade) - os_outdoor_shade = hb_outdoor_shade.to_openstudio(openstudio_model) - os_outdoor_shade.setShadingSurfaceGroup(os_shd_group) + add_shade_to_group(openstudio_model, os_shd_group, outdoor_shade) + end + end + end + end + + # assign door-level shades if they exist + if face[:doors] + face[:doors].each do |door| + if door[:outdoor_shades] + unless os_shd_group + os_shd_group = make_shade_group(openstudio_model, openstudio_surface, os_space) + end + door[:outdoor_shades].each do |outdoor_shade| + add_shade_to_group(openstudio_model, os_shd_group, outdoor_shade) end end end @@ -154,9 +158,7 @@ def to_openstudio(openstudio_model) os_shd_group.setSpace(os_space) os_shd_group.setShadingSurfaceType("Space") @hash[:outdoor_shades].each do |outdoor_shade| - outdoor_shade = Shade.new(outdoor_shade) - os_outdoor_shade = outdoor_shade.to_openstudio(openstudio_model) - os_outdoor_shade.setShadingSurfaceGroup(os_shd_group) + add_shade_to_group(openstudio_model, os_shd_group, outdoor_shade) end end @@ -255,6 +257,23 @@ def to_openstudio(openstudio_model) os_space end + + # method to make a space-assigned Shade group for shades assigned to parent objects + def make_shade_group(openstudio_model, openstudio_surface, os_space) + os_shd_group = OpenStudio::Model::ShadingSurfaceGroup.new(openstudio_model) + os_shd_group.setShadedSurface(openstudio_surface) + os_shd_group.setSpace(os_space) + os_shd_group.setShadingSurfaceType("Space") + + os_shd_group + end + + # method to create a Shade and add it to a shade group + def add_shade_to_group(openstudio_model, os_shd_group, outdoor_shade) + hb_outdoor_shade = Shade.new(outdoor_shade) + os_outdoor_shade = hb_outdoor_shade.to_openstudio(openstudio_model) + os_outdoor_shade.setShadingSurfaceGroup(os_shd_group) + end # method to check for the closest-assigned interior ceiling or floor construction def closest_interior_construction(openstudio_model, os_space, surface_type)