mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 11:18:01 +00:00
Fix #5675. Bug where separate islands of polygons still merged CSS classes incorrectly.
This commit is contained in:
@@ -1480,11 +1480,10 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
joined_paths.setdefault(hash_keys, []).append(el)
|
joined_paths.setdefault(hash_keys, []).append(el)
|
||||||
|
|
||||||
for key, els in joined_paths.items():
|
for key, els in joined_paths.items():
|
||||||
polygons = []
|
queue = []
|
||||||
classes = set()
|
|
||||||
|
|
||||||
for el in els:
|
for el in els:
|
||||||
classes.update(el.attrib["class"].split())
|
classes = set(el.attrib["class"].split())
|
||||||
classes.add(el.attrib["{http://www.ifcopenshell.org/ns}guid"])
|
classes.add(el.attrib["{http://www.ifcopenshell.org/ns}guid"])
|
||||||
is_closed_polygon = False
|
is_closed_polygon = False
|
||||||
for path in el.findall("{http://www.w3.org/2000/svg}path"):
|
for path in el.findall("{http://www.w3.org/2000/svg}path"):
|
||||||
@@ -1499,31 +1498,30 @@ class CreateDrawing(bpy.types.Operator):
|
|||||||
coords.append(coords[0])
|
coords.append(coords[0])
|
||||||
if len(coords) > 2 and coords[0] == coords[-1]:
|
if len(coords) > 2 and coords[0] == coords[-1]:
|
||||||
is_closed_polygon = True
|
is_closed_polygon = True
|
||||||
polygons.append(shapely.Polygon(coords))
|
queue.append((shapely.Polygon(coords), classes))
|
||||||
if is_closed_polygon:
|
if is_closed_polygon:
|
||||||
el.getparent().remove(el)
|
el.getparent().remove(el)
|
||||||
|
|
||||||
try:
|
while queue:
|
||||||
merged_polygons = shapely.ops.unary_union(polygons)
|
polygon, polygon_classes = queue.pop()
|
||||||
except:
|
for polygon2, polygon2_classes in queue[:]:
|
||||||
print("Warning. Portions of the merge failed. Please report a bug!", polygons)
|
try:
|
||||||
merged_polygons = polygons
|
merged_polygon = shapely.union(polygon, polygon2)
|
||||||
|
except:
|
||||||
|
print("Warning. Portions of the merge failed. Please report a bug!", polygon, polygon2)
|
||||||
|
continue
|
||||||
|
if type(merged_polygon) == shapely.Polygon:
|
||||||
|
polygon = merged_polygon
|
||||||
|
polygon_classes.update(polygon2_classes)
|
||||||
|
queue.remove((polygon2, polygon2_classes))
|
||||||
|
|
||||||
if type(merged_polygons) == shapely.MultiPolygon:
|
|
||||||
merged_polygons = merged_polygons.geoms
|
|
||||||
elif type(merged_polygons) == shapely.Polygon:
|
|
||||||
merged_polygons = [merged_polygons]
|
|
||||||
else:
|
|
||||||
merged_polygons = []
|
|
||||||
|
|
||||||
for polygon in merged_polygons:
|
|
||||||
g = etree.Element("g")
|
g = etree.Element("g")
|
||||||
path = etree.SubElement(g, "path")
|
path = etree.SubElement(g, "path")
|
||||||
d = "M" + " L".join([",".join([str(o) for o in co]) for co in polygon.exterior.coords[0:-1]]) + " Z"
|
d = "M" + " L".join([",".join([str(o) for o in co]) for co in polygon.exterior.coords[0:-1]]) + " Z"
|
||||||
for interior in polygon.interiors:
|
for interior in polygon.interiors:
|
||||||
d += " M" + " L".join([",".join([str(o) for o in co]) for co in interior.coords[0:-1]]) + " Z"
|
d += " M" + " L".join([",".join([str(o) for o in co]) for co in interior.coords[0:-1]]) + " Z"
|
||||||
path.attrib["d"] = d
|
path.attrib["d"] = d
|
||||||
g.set("class", " ".join(list(classes)))
|
g.set("class", " ".join(list(polygon_classes)))
|
||||||
group.append(g)
|
group.append(g)
|
||||||
|
|
||||||
def drawing_to_model_co(self, x: float, y: float) -> Vector:
|
def drawing_to_model_co(self, x: float, y: float) -> Vector:
|
||||||
|
|||||||
Reference in New Issue
Block a user