From e70bc049150c29904e9711252ec752089c3ed828 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Wed, 6 Nov 2024 09:16:41 +0100 Subject: [PATCH] Update draw.py with provisionary access to arrange_spaces --- src/ifcopenshell-python/ifcopenshell/draw.py | 37 +++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/ifcopenshell-python/ifcopenshell/draw.py b/src/ifcopenshell-python/ifcopenshell/draw.py index 1e32e29570..1c35c9f14e 100644 --- a/src/ifcopenshell-python/ifcopenshell/draw.py +++ b/src/ifcopenshell-python/ifcopenshell/draw.py @@ -72,6 +72,7 @@ class draw_settings: prefilter: bool = True include_curves: bool = False unify_inputs: bool = True + arrange_spaces: bool = False def main( @@ -414,7 +415,41 @@ def main( # This generally shouldn't happen g1.appendChild(g2) - data = dom1.toxml() + if settings.arrange_spaces: + root_groups = [g for g in yield_groups(svg1) if g.parentNode.tagName == "svg"] + ref_node = root_groups[-1].nextSibling + parent = root_groups[0].parentNode + zone_groups = [] + + for i in range(len(root_groups)): + for j in range(len(root_groups)): + if i != j: + parent.removeChild(root_groups[j]) + polies = W.svg_to_polygons(svg1.toxml(), "IfcSpace") + + def min_bound_extent(p): + arr = numpy.array(p.boundary) + return (arr.max(axis=0) - arr.min(axis=0)).min() > 0.5 + + polies = type(polies)(filter(min_bound_extent, polies)) + arranged = W.arrange_polygons(polies) + svg_data_3 = W.polygons_to_svg(arranged, False) + dom3 = parseString(svg_data_3) + svg3 = dom3.childNodes[0] + g3 = next(yield_groups(svg3)) + for p in g3.getElementsByTagName("path"): + p.setAttribute("style", "fill: none; stroke: black; stroke-width: 0.2") + zone_groups.append(g3) + parent.removeChild(root_groups[i]) + for j in range(len(root_groups)): + parent.insertBefore(root_groups[j], ref_node) + + for rg, zg in zip(root_groups, zone_groups): + for p in rg.getElementsByTagName("path"): + p.setAttribute("style", "fill: none; stroke: black; stroke-width: 0.05") + rg.appendChild(zg) + + data = dom1.toprettyxml() data = data.encode("ascii", "xmlcharrefreplace") return data