Update draw.py with provisionary access to arrange_spaces

This commit is contained in:
Thomas Krijnen
2024-11-06 09:16:41 +01:00
parent 585821d763
commit e70bc04915
+36 -1
View File
@@ -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