mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-22 05:00:53 +00:00
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).
This commit is contained in:
@@ -1924,7 +1924,6 @@ class CreateSheets(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
sheet_builder = sheeter.SheetBuilder()
|
sheet_builder = sheeter.SheetBuilder()
|
||||||
|
|
||||||
references = sheet_builder.build(sheet)
|
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
|
# These variables will be made available to the evaluated commands
|
||||||
svg = references["SHEET"]
|
svg = references["SHEET"]
|
||||||
@@ -1943,11 +1942,6 @@ class CreateSheets(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
reference_description = tool.Drawing.get_reference_description(reference)
|
reference_description = tool.Drawing.get_reference_description(reference)
|
||||||
if reference_description == "SHEET":
|
if reference_description == "SHEET":
|
||||||
has_sheet_reference = True
|
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:
|
if not has_sheet_reference:
|
||||||
reference = tool.Ifc.run("document.add_reference", information=sheet)
|
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:
|
if svg2pdf_command:
|
||||||
# With great power comes great responsibility. Example:
|
# With great power comes great responsibility. Example:
|
||||||
# [["inkscape", "svg", "-o", "pdf"]]
|
# [["inkscape", "svg", "-o", "pdf"]]
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ class SheetBuilder:
|
|||||||
layout_dir = os.path.dirname(layout_path)
|
layout_dir = os.path.dirname(layout_path)
|
||||||
|
|
||||||
drawing_path = tool.Drawing.get_document_uri(tool.Drawing.get_drawing_reference(drawing))
|
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):
|
if not os.path.exists(layout_path) or not os.path.exists(drawing_path):
|
||||||
raise FileNotFoundError
|
raise FileNotFoundError
|
||||||
@@ -116,16 +115,6 @@ class SheetBuilder:
|
|||||||
|
|
||||||
x, y = self.next_drawing_location(layout_root, view_width)
|
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
|
# add foreground
|
||||||
if os.path.isfile(drawing_path):
|
if os.path.isfile(drawing_path):
|
||||||
foreground = ET.SubElement(view, "image")
|
foreground = ET.SubElement(view, "image")
|
||||||
@@ -406,14 +395,11 @@ class SheetBuilder:
|
|||||||
|
|
||||||
images = view.findall("{http://www.w3.org/2000/svg}image")
|
images = view.findall("{http://www.w3.org/2000/svg}image")
|
||||||
|
|
||||||
background = None
|
|
||||||
foreground = None
|
foreground = None
|
||||||
view_title = None
|
view_title = None
|
||||||
|
|
||||||
for image in images:
|
for image in images:
|
||||||
if image.attrib["data-type"] == "background":
|
if image.attrib["data-type"] == "foreground":
|
||||||
background = image
|
|
||||||
elif image.attrib["data-type"] == "foreground":
|
|
||||||
foreground = image
|
foreground = image
|
||||||
elif image.attrib["data-type"] == "view-title":
|
elif image.attrib["data-type"] == "view-title":
|
||||||
view_title = image
|
view_title = image
|
||||||
@@ -423,12 +409,6 @@ class SheetBuilder:
|
|||||||
svg = self.ensure_drawing_unique_styles(svg, drawing_id)
|
svg = self.ensure_drawing_unique_styles(svg, drawing_id)
|
||||||
view.append(svg)
|
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:
|
if view_title is not None:
|
||||||
foreground_path = self.get_href(foreground)
|
foreground_path = self.get_href(foreground)
|
||||||
data = reference.get_info()
|
data = reference.get_info()
|
||||||
@@ -521,8 +501,14 @@ class SheetBuilder:
|
|||||||
self.scale = embedded.attrib.get("data-scale")
|
self.scale = embedded.attrib.get("data-scale")
|
||||||
images = embedded.findall("{http://www.w3.org/2000/svg}image")
|
images = embedded.findall("{http://www.w3.org/2000/svg}image")
|
||||||
for image in images:
|
for image in images:
|
||||||
new_href = ntpath.basename(image.attrib.get("{http://www.w3.org/1999/xlink}href"))
|
old_href = Path(image.attrib.get("{http://www.w3.org/1999/xlink}href"))
|
||||||
image.attrib["{http://www.w3.org/1999/xlink}href"] = new_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:
|
for child in embedded:
|
||||||
if "namedview" in child.tag:
|
if "namedview" in child.tag:
|
||||||
continue
|
continue
|
||||||
|
|||||||
Reference in New Issue
Block a user