Skip to content

Commit

Permalink
fix(writer): handle rooms with multi-line names
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Sep 23, 2022
1 parent fb09b09 commit 2301675
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 9 additions & 3 deletions honeybee_ies/writer.py
Expand Up @@ -76,8 +76,10 @@ def _shade_group_to_ies(shades: List[Shade]) -> str:
[shade.geometry for shade in shades], tolerance=0.001
)
first_shade = shades[0]
# remove new lines from the name
shade_name = ' '.join(first_shade.display_name.split())
return _shade_geometry_to_ies(
group_geometry, first_shade.display_name, first_shade.is_detached
group_geometry, shade_name, first_shade.is_detached
)


Expand All @@ -99,8 +101,10 @@ def _shade_to_ies(shade: Shade, thickness: float = 0.1) -> str:
move_vector = geometry.normal.reverse().normalize() * thickness / 2
base_geo = geometry.move(move_vector)
shade_geo = Polyface3D.from_offset_face(base_geo, thickness)
# remove new lines from the name
shade_name = ' '.join(shade.display_name.split())
return _shade_geometry_to_ies(
shade_geo, shade.display_name, is_detached=shade.is_detached
shade_geo, shade_name, is_detached=shade.is_detached
)


Expand Down Expand Up @@ -187,8 +191,10 @@ def room_to_ies(room: Room) -> str:
open_str = '\n' + '\n'.join(openings) if len(openings) != 0 else ''
faces.append('%s%d%s' % (face_str, open_count, open_str))

# remove new lines from the name
room_name = ' '.join(room.display_name.split())
space = SPACE_TEMPLATE.format(
space_name=room.display_name, vertices_count=len(unique_vertices),
space_name=room_name, vertices_count=len(unique_vertices),
face_count=len(room.faces) - air_boundary_count,
vertices=vertices, faces='\n'.join(faces)
)
Expand Down
1 change: 1 addition & 0 deletions tests/assets/multiline_name_test.hbjson

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions tests/writer_test.py
Expand Up @@ -36,3 +36,15 @@ def test_air_boundary():
' 0.000000 3.000000\n'

assert ab_str in outf.read_text()


def test_display_name_clean_up():
in_file = './tests/assets/multiline_name_test.hbjson'
out_folder = pathlib.Path('./tests/assets/temp')
out_folder.mkdir(parents=True, exist_ok=True)
model = Model.from_hbjson(in_file)
outf = model_to_ies(model, out_folder.as_posix(), name='multiline_name_test')
assert outf.exists()
ab_str = 'IES first line second line\n'

assert ab_str in outf.read_text()

0 comments on commit 2301675

Please sign in to comment.