Skip to content

Commit

Permalink
fix(shade): Fixe Shading builder to support IP units
Browse files Browse the repository at this point in the history
- Fix shade_create_bldg_shd so it works with IP Rhino units
- Fix win_set_inst_depth so it works with IP Rhino units
- Update installer versions
  • Loading branch information
ed-p-may committed Apr 26, 2023
1 parent 49aafb2 commit f5e870d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
Binary file modified hbph_installer.gh
Binary file not shown.
2 changes: 1 addition & 1 deletion honeybee_ph_rhino/_component_info_.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
These are called when the component is instantiated within the Grasshopper canvas.
"""

RELEASE_VERSION = "Honeybee-PH v1.0.37"
RELEASE_VERSION = "Honeybee-PH v1.0.38"
CATEGORY = "HB-PH"
SUB_CATEGORIES = {
0: "00 | Utils",
Expand Down
32 changes: 24 additions & 8 deletions honeybee_ph_rhino/gh_compo_io/shade_create_bldg_shd.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
except ImportError as e:
raise ImportError('\nFailed to import honeybee_ph_rhino:\n\t{}'.format(e))

try:
from ph_units.converter import convert
except ImportError as e:
raise ImportError('\nFailed to import ph_units:\n\t{}'.format(e))


def create_punched_geometry(_hb_rooms):
# type: (Collection[room.Room]) -> List[rg.Brep]
"""Return a list of all of the 'punched' surfaces from the HB-Model."""
Expand Down Expand Up @@ -82,28 +88,37 @@ def create_inset_aperture_surfaces(_hb_rooms):
return inset_window_surfaces


def create_window_reveal(_hb_aperture):
# type: (aperture.Aperture) -> List[rg.Brep]
def create_window_reveal(_hb_aperture, _rh_units_name):
# type: (aperture.Aperture, str) -> List[rg.Brep]
"""Return a list of the Aperture 'reveal' surfaces."""
ap_prop_ph = _hb_aperture.properties.ph # type: AperturePhProperties

# -- Convert the Aperture's install depth to Rhino units
try:
ap_prop_ph = _hb_aperture.properties.ph # type: AperturePhProperties
ap_install_depth_in_m = ap_prop_ph.install_depth
ap_install_depth_in_r_units = convert(ap_install_depth_in_m, "M", _rh_units_name)
except Exception as e:
msg = "Error converting Aperture's install depth to Rhino units: {}?\t{}".format(_rh_units_name, e)
raise Exception(msg)

extrusion_vector = _hb_aperture.normal.reverse(
) * ap_prop_ph.install_depth
) * ap_install_depth_in_r_units
return [
from_face3d(Face3D.from_extrusion(seg, extrusion_vector))
for seg in _hb_aperture.geometry.boundary_segments
if extrusion_vector.magnitude != 0
]


def create_window_reveals(_hb_rooms):
# type: (Collection[room.Room]) -> List[rg.Brep]
def create_window_reveals(_hb_rooms, _rh_units_name):
# type: (Collection[room.Room], str) -> List[rg.Brep]
"""Return a list of all the aperture 'reveals' in the Honeybee-Model"""

reveals = []
for room in _hb_rooms:
for face in room.faces:
for aperture in face.apertures:
reveals.extend(create_window_reveal(aperture))
reveals.extend(create_window_reveal(aperture, _rh_units_name))
return reveals


Expand All @@ -116,9 +131,10 @@ def __init__(self, _IGH, _hb_rooms):
def run(self):
# type: () -> Tuple[List[rg.Brep], List[rg.Brep], List[room.Room]]

rh_units_name = self.IGH.get_rhino_unit_system_name()
shading_surfaces_ = []
shading_surfaces_.extend(create_punched_geometry(self.hb_rooms))
shading_surfaces_.extend(create_window_reveals(self.hb_rooms))
shading_surfaces_.extend(create_window_reveals(self.hb_rooms, rh_units_name))

window_surfaces_ = create_inset_aperture_surfaces(self.hb_rooms)
hb_rooms_ = self.hb_rooms
Expand Down
33 changes: 31 additions & 2 deletions honeybee_ph_rhino/gh_compo_io/win_set_inst_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
except ImportError as e:
raise ImportError('\nFailed to import honeybee_ph_rhino:\n\t{}'.format(e))

try:
from ph_units.converter import convert
from ph_units.parser import parse_input
except ImportError as e:
raise ImportError('\nFailed to import ph_units:\n\t{}'.format(e))


class GHCompo_SetApertureInstallDepth(object):
"""Interface to collect and clean PhWindowGlazing user-inputs."""

Expand All @@ -33,13 +40,35 @@ def __init__(self, _IGH, _apertures, _install_depth):
# type: (gh_io.IGH, List[Aperture], Optional[str]) -> None
self.IGH = _IGH
self._apertures = _apertures
self._install_depth = _install_depth or 0.106
self._install_depth = self.calc_install_depth(_install_depth)

def calc_install_depth(self, _install_depth):
# type: (Optional[str]) -> float| int
"""Calculate the install depth of the window glazing, considering Rhino unit-types."""

if not _install_depth:
return 0.106

# -- If the user supplied an input unit, just use that
input_value, input_unit = parse_input(_install_depth)

# -- otherwise use the Rhino document unit system
if not input_unit:
input_unit = self.IGH.get_rhino_unit_system_name()

# -- convert the input value to Meters, always
install_depth = convert(input_value, input_unit, "M")

if not install_depth:
raise ValueError("Failed to parse install depth input {}?".format(_install_depth))
else:
return install_depth

def run(self):
# type: () -> List[Aperture]
apertures_ = []
for aperture in self._apertures:
dup_ap = aperture.duplicate()
dup_ap.properties.ph.install_depth = self._install_depth
dup_ap.properties.ph.install_depth = self._install_depth # type: ignore
apertures_.append(dup_ap)
return apertures_
10 changes: 10 additions & 0 deletions honeybee_ph_rhino/gh_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def ghc(self):
"""Convenience Attribute Alias."""
return self.ghpythonlib_components

@property
def sc(self):
"""Convenience Attribute Alias."""
return self.scriptcontext

def gh_compo_find_input_index_by_name(self, _input_name):
# type: (str) -> int
"""
Expand Down Expand Up @@ -439,6 +444,11 @@ def remark(self, _in):
level = self.Grasshopper.Kernel.GH_RuntimeMessageLevel.Remark
self.ghenv.Component.AddRuntimeMessage(level, _in)

def get_rhino_unit_system_name(self):
# type: () -> str
"""Returns the Rhino Unit System Name as a string."""
return self.sc.doc.ModelUnitSystem


class ComponentInput:
"""GH-Component Input Node data class."""
Expand Down
1 change: 1 addition & 0 deletions honeybee_ph_rhino/make_spaces/make_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ladybug_rhino.togeometry import to_point3d
except ImportError as e:
raise ImportError("\nFailed to import ladybug_rhino:\n\t{}".format(e))

try:
from ladybug_geometry import geometry3d
except ImportError as e:
Expand Down

0 comments on commit f5e870d

Please sign in to comment.