From 4bb112ce7151ee7e35c516a38c1a08f9df5e92b4 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 1 Dec 2024 11:21:38 +0100 Subject: [PATCH] Manually parse SVG polygons for space arrangement --- src/ifcopenshell-python/ifcopenshell/draw.py | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/draw.py b/src/ifcopenshell-python/ifcopenshell/draw.py index 200da97bb9..efecf33993 100644 --- a/src/ifcopenshell-python/ifcopenshell/draw.py +++ b/src/ifcopenshell-python/ifcopenshell/draw.py @@ -21,6 +21,8 @@ import math import json import functools +import re +import warnings import ifcopenshell import ifcopenshell.geom @@ -213,11 +215,11 @@ def main( if not settings.cells: return svg_data_1.encode("ascii", "xmlcharrefreplace") - def yield_groups(n): - if n.nodeType == n.ELEMENT_NODE and n.tagName == "g": + def yield_groups(n, tag='g'): + if n.nodeType == n.ELEMENT_NODE and n.tagName == tag: yield n for c in n.childNodes: - yield from yield_groups(c) + yield from yield_groups(c, tag=tag) dom1 = parseString(svg_data_1) svg1 = dom1.childNodes[0] @@ -427,7 +429,18 @@ def main( for j in range(len(root_groups)): if i != j: parent.removeChild(root_groups[j]) - polies = W.svg_to_polygons(svg1.toxml(), "IfcSpace") + + # wasteful and looses data for unknown reasons + # svg_contents = svg1.toxml() + # polies = W.svg_to_polygons(svg_contents, "IfcSpace") + + polies = [p.getAttribute('d') for p in yield_groups(svg1, "path") if 'IfcSpace' in p.parentNode.getAttribute('class')] + polies = [[[*map(float, s[1:].split(','))] for s in d.split(' ')] for d in polies] + def create_poly(b): + p = ifcopenshell.ifcopenshell_wrapper.polygon_2() + p.boundary = b + return p + polies = [create_poly(p) for p in polies] def min_bound_extent(p): arr = numpy.array(p.boundary)