From d1493b4234b9bc27d552a5814d025756d44debcc Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 19 Apr 2025 16:53:14 +1000 Subject: [PATCH] Fix #5571. No longer create "RASTER" document references. Process all images at sheet creation time. I think this was overengineered and a bad decision. RASTER is a technical detail, not a semantic label (in contrast with whether it's a title or a drawing). --- .../bonsai/bim/module/drawing/operator.py | 18 ----------- .../bonsai/bim/module/drawing/sheeter.py | 32 ++++++------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/operator.py b/src/bonsai/bonsai/bim/module/drawing/operator.py index 9cbc774a5b..fc43909d0e 100644 --- a/src/bonsai/bonsai/bim/module/drawing/operator.py +++ b/src/bonsai/bonsai/bim/module/drawing/operator.py @@ -1924,7 +1924,6 @@ class CreateSheets(bpy.types.Operator, tool.Ifc.Operator): sheet_builder = sheeter.SheetBuilder() references = sheet_builder.build(sheet) - raster_references = [tool.Ifc.get_uri(r, use_relative_path=True) for r in references["RASTER"]] # These variables will be made available to the evaluated commands svg = references["SHEET"] @@ -1943,11 +1942,6 @@ class CreateSheets(bpy.types.Operator, tool.Ifc.Operator): reference_description = tool.Drawing.get_reference_description(reference) if reference_description == "SHEET": has_sheet_reference = True - elif reference_description == "RASTER": - if reference.Location in raster_references: - raster_references.remove(reference.Location) - else: - tool.Ifc.run("document.remove_reference", reference=reference) if not has_sheet_reference: reference = tool.Ifc.run("document.add_reference", information=sheet) @@ -1959,18 +1953,6 @@ class CreateSheets(bpy.types.Operator, tool.Ifc.Operator): ), ) - for raster_reference in raster_references: - reference = tool.Ifc.run("document.add_reference", information=sheet) - tool.Ifc.run( - "document.edit_reference", - reference=reference, - attributes=tool.Drawing.generate_reference_attributes( - reference, - Location=tool.Ifc.get_uri(raster_reference, use_relative_path=True), - Description="RASTER", - ), - ) - if svg2pdf_command: # With great power comes great responsibility. Example: # [["inkscape", "svg", "-o", "pdf"]] diff --git a/src/bonsai/bonsai/bim/module/drawing/sheeter.py b/src/bonsai/bonsai/bim/module/drawing/sheeter.py index 93c42bbae5..916b795b50 100644 --- a/src/bonsai/bonsai/bim/module/drawing/sheeter.py +++ b/src/bonsai/bonsai/bim/module/drawing/sheeter.py @@ -90,7 +90,6 @@ class SheetBuilder: layout_dir = os.path.dirname(layout_path) drawing_path = tool.Drawing.get_document_uri(tool.Drawing.get_drawing_reference(drawing)) - underlay_path = os.path.splitext(drawing_path)[0] + "-underlay.png" if not os.path.exists(layout_path) or not os.path.exists(drawing_path): raise FileNotFoundError @@ -116,16 +115,6 @@ class SheetBuilder: x, y = self.next_drawing_location(layout_root, view_width) - # add background - if os.path.isfile(underlay_path): - background = ET.SubElement(view, "image") - background.attrib["data-type"] = "background" - background.attrib["xlink:href"] = os.path.relpath(underlay_path, layout_dir) - background.attrib["x"] = str(x) - background.attrib["y"] = str(y) - background.attrib["width"] = str(view_width) - background.attrib["height"] = str(view_height) - # add foreground if os.path.isfile(drawing_path): foreground = ET.SubElement(view, "image") @@ -406,14 +395,11 @@ class SheetBuilder: images = view.findall("{http://www.w3.org/2000/svg}image") - background = None foreground = None view_title = None for image in images: - if image.attrib["data-type"] == "background": - background = image - elif image.attrib["data-type"] == "foreground": + if image.attrib["data-type"] == "foreground": foreground = image elif image.attrib["data-type"] == "view-title": view_title = image @@ -423,12 +409,6 @@ class SheetBuilder: svg = self.ensure_drawing_unique_styles(svg, drawing_id) view.append(svg) - if background is not None: - background_path = os.path.join(self.layout_dir, self.get_href(background)) - raster_path = os.path.join(self.sheets_dir, os.path.basename(background_path)) - shutil.copy(background_path, raster_path) - self.references["RASTER"].append(raster_path) - if view_title is not None: foreground_path = self.get_href(foreground) data = reference.get_info() @@ -521,8 +501,14 @@ class SheetBuilder: self.scale = embedded.attrib.get("data-scale") images = embedded.findall("{http://www.w3.org/2000/svg}image") for image in images: - new_href = ntpath.basename(image.attrib.get("{http://www.w3.org/1999/xlink}href")) - image.attrib["{http://www.w3.org/1999/xlink}href"] = new_href + old_href = Path(image.attrib.get("{http://www.w3.org/1999/xlink}href")) + if not os.path.isabs(old_href): + template_dir = Path(os.path.join(self.layout_dir, svg_path)).resolve().parent + old_href = Path(os.path.join(template_dir, old_href)) + old_href = old_href.absolute().resolve().as_posix() + new_href = Path(os.path.join(self.sheets_dir, Path(old_href).name)).absolute().resolve().as_posix() + shutil.copy(old_href, new_href) + image.attrib["{http://www.w3.org/1999/xlink}href"] = Path(old_href).name for child in embedded: if "namedview" in child.tag: continue