mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
Manually parse SVG polygons for space arrangement
This commit is contained in:
@@ -21,6 +21,8 @@
|
|||||||
import math
|
import math
|
||||||
import json
|
import json
|
||||||
import functools
|
import functools
|
||||||
|
import re
|
||||||
|
import warnings
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
@@ -213,11 +215,11 @@ def main(
|
|||||||
if not settings.cells:
|
if not settings.cells:
|
||||||
return svg_data_1.encode("ascii", "xmlcharrefreplace")
|
return svg_data_1.encode("ascii", "xmlcharrefreplace")
|
||||||
|
|
||||||
def yield_groups(n):
|
def yield_groups(n, tag='g'):
|
||||||
if n.nodeType == n.ELEMENT_NODE and n.tagName == "g":
|
if n.nodeType == n.ELEMENT_NODE and n.tagName == tag:
|
||||||
yield n
|
yield n
|
||||||
for c in n.childNodes:
|
for c in n.childNodes:
|
||||||
yield from yield_groups(c)
|
yield from yield_groups(c, tag=tag)
|
||||||
|
|
||||||
dom1 = parseString(svg_data_1)
|
dom1 = parseString(svg_data_1)
|
||||||
svg1 = dom1.childNodes[0]
|
svg1 = dom1.childNodes[0]
|
||||||
@@ -427,7 +429,18 @@ def main(
|
|||||||
for j in range(len(root_groups)):
|
for j in range(len(root_groups)):
|
||||||
if i != j:
|
if i != j:
|
||||||
parent.removeChild(root_groups[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):
|
def min_bound_extent(p):
|
||||||
arr = numpy.array(p.boundary)
|
arr = numpy.array(p.boundary)
|
||||||
|
|||||||
Reference in New Issue
Block a user