mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Use .Name instead of .Description if IFC2X3 for sheets #4576
As Description was added only in IFC4
This commit is contained in:
@@ -1241,12 +1241,14 @@ class AddDrawingToSheet(bpy.types.Operator, Operator):
|
||||
return
|
||||
|
||||
reference = tool.Ifc.run("document.add_reference", information=sheet)
|
||||
id_attr = "ItemReference" if tool.Ifc.get_schema() == "IFC2X3" else "Identification"
|
||||
attributes = {
|
||||
id_attr: str(len([r for r in references if r.Description in ("DRAWING", "SCHEDULE")]) + 1),
|
||||
"Location": drawing_reference.Location,
|
||||
"Description": "DRAWING",
|
||||
}
|
||||
attributes = tool.Drawing.generate_reference_attributes(
|
||||
reference,
|
||||
Identification=str(
|
||||
len([r for r in references if tool.Drawing.get_reference_description(r) in ("DRAWING", "SCHEDULE")]) + 1
|
||||
),
|
||||
Location=drawing_reference.Location,
|
||||
Description="DRAWING",
|
||||
)
|
||||
tool.Ifc.run("document.edit_reference", reference=reference, attributes=attributes)
|
||||
sheet_builder = sheeter.SheetBuilder()
|
||||
sheet_builder.data_dir = context.scene.BIMProperties.data_dir
|
||||
@@ -1314,9 +1316,10 @@ class CreateSheets(bpy.types.Operator, Operator):
|
||||
|
||||
has_sheet_reference = False
|
||||
for reference in tool.Drawing.get_document_references(sheet):
|
||||
if reference.Description == "SHEET":
|
||||
reference_description = tool.Drawing.get_reference_description(reference)
|
||||
if reference == "SHEET":
|
||||
has_sheet_reference = True
|
||||
elif reference.Description == "RASTER":
|
||||
elif reference == "RASTER":
|
||||
if reference.Location in raster_references:
|
||||
raster_references.remove(reference.Location)
|
||||
else:
|
||||
@@ -1327,7 +1330,9 @@ class CreateSheets(bpy.types.Operator, Operator):
|
||||
tool.Ifc.run(
|
||||
"document.edit_reference",
|
||||
reference=reference,
|
||||
attributes={"Location": tool.Ifc.get_relative_uri(svg), "Description": "SHEET"},
|
||||
attributes=tool.Drawing.generate_reference_attributes(
|
||||
reference, Location=tool.Ifc.get_relative_uri(svg), Description="SHEET"
|
||||
),
|
||||
)
|
||||
|
||||
for raster_reference in raster_references:
|
||||
@@ -1335,7 +1340,9 @@ class CreateSheets(bpy.types.Operator, Operator):
|
||||
tool.Ifc.run(
|
||||
"document.edit_reference",
|
||||
reference=reference,
|
||||
attributes={"Location": tool.Ifc.get_relative_uri(raster_reference), "Description": "RASTER"},
|
||||
attributes=tool.Drawing.generate_reference_attributes(
|
||||
reference, Location=tool.Ifc.get_relative_uri(raster_reference), Description="RASTER"
|
||||
),
|
||||
)
|
||||
|
||||
svg2pdf_command = context.preferences.addons["blenderbim"].preferences.svg2pdf_command
|
||||
@@ -1988,12 +1995,14 @@ class AddScheduleToSheet(bpy.types.Operator, Operator):
|
||||
return
|
||||
|
||||
reference = tool.Ifc.run("document.add_reference", information=sheet)
|
||||
id_attr = "ItemReference" if tool.Ifc.get_schema() == "IFC2X3" else "Identification"
|
||||
attributes = {
|
||||
id_attr: str(len([r for r in references if r.Description in ("DRAWING", "SCHEDULE")]) + 1),
|
||||
"Location": schedule_location,
|
||||
"Description": "SCHEDULE",
|
||||
}
|
||||
attributes = tool.Drawing.generate_reference_attributes(
|
||||
reference,
|
||||
Identification=str(
|
||||
len([r for r in references if tool.Drawing.get_reference_description(r) in ("DRAWING", "SCHEDULE")]) + 1
|
||||
),
|
||||
Location=schedule_location,
|
||||
Description="SCHEDULE",
|
||||
)
|
||||
tool.Ifc.run("document.edit_reference", reference=reference, attributes=attributes)
|
||||
|
||||
sheet_builder = sheeter.SheetBuilder()
|
||||
@@ -2042,12 +2051,15 @@ class AddReferenceToSheet(bpy.types.Operator, Operator):
|
||||
return
|
||||
|
||||
reference = tool.Ifc.run("document.add_reference", information=sheet)
|
||||
id_attr = "ItemReference" if tool.Ifc.get_schema() == "IFC2X3" else "Identification"
|
||||
attributes = {
|
||||
id_attr: str(len([r for r in references if r.Description in ("DRAWING", "REFERENCE")]) + 1),
|
||||
"Location": extref_location,
|
||||
"Description": "REFERENCE",
|
||||
}
|
||||
attributes = tool.Drawing.generate_reference_attributes(
|
||||
reference,
|
||||
Identification=str(
|
||||
len([r for r in references if tool.Drawing.get_reference_description(r) in ("DRAWING", "REFERENCE")])
|
||||
+ 1
|
||||
),
|
||||
Location=extref_location,
|
||||
Description="REFERENCE",
|
||||
)
|
||||
tool.Ifc.run("document.edit_reference", reference=reference, attributes=attributes)
|
||||
|
||||
sheet_builder = sheeter.SheetBuilder()
|
||||
@@ -2393,7 +2405,7 @@ class EditSheet(bpy.types.Operator, Operator):
|
||||
self.document_type = "SHEET"
|
||||
self.name = sheet.Name
|
||||
self.identification = sheet.Identification
|
||||
elif sheet.is_a("IfcDocumentReference") and sheet.Description == "TITLEBLOCK":
|
||||
elif sheet.is_a("IfcDocumentReference") and tool.Drawing.get_reference_description(sheet) == "TITLEBLOCK":
|
||||
self.document_type = "TITLEBLOCK"
|
||||
else:
|
||||
self.document_type = "EMBEDDED"
|
||||
@@ -2419,7 +2431,7 @@ class EditSheet(bpy.types.Operator, Operator):
|
||||
if self.document_type == "SHEET":
|
||||
core.rename_sheet(tool.Ifc, tool.Drawing, sheet=sheet, identification=self.identification, name=self.name)
|
||||
elif self.document_type == "EMBEDDED":
|
||||
core.rename_reference(tool.Ifc, reference=sheet, identification=self.identification)
|
||||
core.rename_reference(tool.Ifc, tool.Drawing, reference=sheet, identification=self.identification)
|
||||
elif self.document_type == "TITLEBLOCK":
|
||||
titleblock = self.props.titleblock
|
||||
reference = sheet
|
||||
|
||||
@@ -726,7 +726,8 @@ class SvgWriter:
|
||||
reference = tool.Drawing.get_drawing_reference(drawing)
|
||||
if reference:
|
||||
for sheet_reference in tool.Ifc.get().by_type("IfcDocumentReference"):
|
||||
if sheet_reference.Description != "DRAWING" or sheet_reference.Location != reference.Location:
|
||||
reference_description = tool.Drawing.get_reference_description(reference)
|
||||
if reference_description != "DRAWING" or sheet_reference.Location != reference.Location:
|
||||
continue
|
||||
sheet = tool.Drawing.get_reference_document(sheet_reference)
|
||||
if sheet:
|
||||
|
||||
@@ -77,16 +77,17 @@ def add_sheet(ifc, drawing, titleblock=None):
|
||||
else:
|
||||
attributes = {"Identification": identification, "Name": "UNTITLED", "Scope": "SHEET"}
|
||||
ifc.run("document.edit_information", information=sheet, attributes=attributes)
|
||||
ifc.run(
|
||||
"document.edit_reference",
|
||||
reference=layout,
|
||||
attributes={"Location": drawing.get_default_layout_path(identification, "UNTITLED"), "Description": "LAYOUT"},
|
||||
|
||||
attributes = drawing.generate_reference_attributes(
|
||||
layout, Location=drawing.get_default_layout_path(identification, "UNTITLED"), Description="LAYOUT"
|
||||
)
|
||||
ifc.run(
|
||||
"document.edit_reference",
|
||||
reference=titleblock_reference,
|
||||
attributes={"Location": drawing.get_default_titleblock_path(titleblock), "Description": "TITLEBLOCK"},
|
||||
ifc.run("document.edit_reference", reference=layout, attributes=attributes)
|
||||
|
||||
attributes = drawing.generate_reference_attributes(
|
||||
layout, Location=drawing.get_default_titleblock_path(titleblock), Description="TITLEBLOCK"
|
||||
)
|
||||
ifc.run("document.edit_reference", reference=titleblock_reference, attributes=attributes)
|
||||
|
||||
drawing.create_svg_sheet(sheet, titleblock)
|
||||
drawing.import_sheets()
|
||||
|
||||
@@ -138,8 +139,9 @@ def rename_sheet(ifc, drawing, sheet=None, identification=None, name=None):
|
||||
drawing.move_file(old_location, ifc.resolve_uri(new_location))
|
||||
|
||||
|
||||
def rename_reference(ifc, reference=None, identification=None):
|
||||
ifc.run("document.edit_reference", reference=reference, attributes={"Identification": identification})
|
||||
def rename_reference(ifc, drawing, reference=None, identification=None):
|
||||
attributes = drawing.generate_reference_attributes(reference, Identifiaction=identification)
|
||||
ifc.run("document.edit_reference", reference=reference, attributes=attributes)
|
||||
|
||||
|
||||
def load_schedules(drawing):
|
||||
|
||||
@@ -329,6 +329,7 @@ class Drawing:
|
||||
def get_name(cls, element): pass
|
||||
def get_path_filename(cls, uri): pass
|
||||
def get_reference_description(cls, reference): pass
|
||||
def generate_reference_attributes(cls, reference, **attributes): pass
|
||||
def get_reference_document(cls, reference): pass
|
||||
def get_reference_location(cls, reference): pass
|
||||
def get_references_with_location(cls, location): pass
|
||||
|
||||
@@ -254,9 +254,10 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
sheet_reference = None
|
||||
drawing_names = []
|
||||
for reference in cls.get_document_references(sheet):
|
||||
if reference.Description == "LAYOUT":
|
||||
reference_description = cls.get_reference_description(reference)
|
||||
if reference_description == "LAYOUT":
|
||||
sheet_reference = reference
|
||||
elif reference.Description == "DRAWING":
|
||||
elif reference_description == "DRAWING":
|
||||
drawing_names.append(Path(reference.Location).stem)
|
||||
for annotation in [e for e in tool.Ifc.get().by_type("IfcAnnotation") if e.ObjectType == "DRAWING"]:
|
||||
if annotation.Name in drawing_names:
|
||||
@@ -421,7 +422,7 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
else:
|
||||
references = document.HasDocumentReferences
|
||||
for reference in references:
|
||||
if description and reference.Description != description:
|
||||
if description and cls.get_reference_description(reference) != description:
|
||||
continue
|
||||
location = cls.get_document_uri(reference)
|
||||
if location:
|
||||
@@ -823,7 +824,8 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
continue
|
||||
|
||||
for reference in cls.get_document_references(sheet):
|
||||
if reference.Description in ("SHEET", "LAYOUT", "RASTER"):
|
||||
reference_description = cls.get_reference_description(reference)
|
||||
if reference_description in ("SHEET", "LAYOUT", "RASTER"):
|
||||
# These references are an internal detail and should not be visible to users
|
||||
continue
|
||||
new = props.sheets.add()
|
||||
@@ -836,7 +838,7 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
new.identification = reference.Identification or ""
|
||||
|
||||
new.name = os.path.basename(reference.Location)
|
||||
new.reference_type = reference.Description
|
||||
new.reference_type = reference_description
|
||||
|
||||
@classmethod
|
||||
def get_active_sheet(cls, context):
|
||||
@@ -1568,9 +1570,28 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
tree.write(uri, pretty_print=True, xml_declaration=True, encoding="utf-8")
|
||||
|
||||
@classmethod
|
||||
def get_reference_description(cls, reference):
|
||||
def get_reference_description(cls, reference: ifcopenshell.entity_instance) -> Union[str, None]:
|
||||
if reference.file.schema == "IFC2X3":
|
||||
return reference.Name
|
||||
return reference.Description
|
||||
|
||||
@classmethod
|
||||
def generate_reference_attributes(cls, reference: ifcopenshell.entity_instance, **attributes: Any) -> dict[str, Any]:
|
||||
"""will automatically convert attributes below for IFC2X3 compatibility:
|
||||
|
||||
- Identification -> ItemReference
|
||||
|
||||
- Description -> Name
|
||||
"""
|
||||
if reference.file.schema == "IFC2X3":
|
||||
if "Description" in attributes:
|
||||
attributes["Name"] = attributes["Description"]
|
||||
del attributes["Description"]
|
||||
if "Identification" in attributes:
|
||||
attributes["ItemReference"] = attributes["Identification"]
|
||||
del attributes["Identification"]
|
||||
return attributes
|
||||
|
||||
@classmethod
|
||||
def get_reference_location(cls, reference):
|
||||
return reference.Location
|
||||
|
||||
@@ -95,15 +95,21 @@ class TestAddSheet:
|
||||
information="sheet",
|
||||
attributes={"Identification": "u_identification", "Name": "UNTITLED", "Scope": "SHEET"},
|
||||
).should_be_called()
|
||||
drawing.generate_reference_attributes(
|
||||
"reference", Location="layout_path", Description="LAYOUT"
|
||||
).should_be_called().will_return("attributes")
|
||||
ifc.run(
|
||||
"document.edit_reference",
|
||||
reference="reference",
|
||||
attributes={"Location": "layout_path", "Description": "LAYOUT"},
|
||||
attributes="attributes",
|
||||
).should_be_called()
|
||||
drawing.generate_reference_attributes(
|
||||
"reference", Location="titleblock_path", Description="TITLEBLOCK"
|
||||
).should_be_called().will_return("attributes2")
|
||||
ifc.run(
|
||||
"document.edit_reference",
|
||||
reference="reference",
|
||||
attributes={"Location": "titleblock_path", "Description": "TITLEBLOCK"},
|
||||
attributes="attributes2",
|
||||
).should_be_called()
|
||||
drawing.create_svg_sheet("sheet", "titleblock").should_be_called()
|
||||
drawing.import_sheets().should_be_called()
|
||||
@@ -122,15 +128,21 @@ class TestAddSheet:
|
||||
information="sheet",
|
||||
attributes={"DocumentId": "u_identification", "Name": "UNTITLED", "Scope": "SHEET"},
|
||||
).should_be_called()
|
||||
drawing.generate_reference_attributes(
|
||||
"reference", Location="layout_path", Description="LAYOUT"
|
||||
).should_be_called().will_return("attributes")
|
||||
ifc.run(
|
||||
"document.edit_reference",
|
||||
reference="reference",
|
||||
attributes={"Location": "layout_path", "Description": "LAYOUT"},
|
||||
attributes="attributes",
|
||||
).should_be_called()
|
||||
drawing.generate_reference_attributes(
|
||||
"reference", Location="titleblock_path", Description="TITLEBLOCK"
|
||||
).should_be_called().will_return("attributes2")
|
||||
ifc.run(
|
||||
"document.edit_reference",
|
||||
reference="reference",
|
||||
attributes={"Location": "titleblock_path", "Description": "TITLEBLOCK"},
|
||||
attributes="attributes2",
|
||||
).should_be_called()
|
||||
drawing.create_svg_sheet("sheet", "titleblock").should_be_called()
|
||||
drawing.import_sheets().should_be_called()
|
||||
@@ -490,7 +502,9 @@ class TestUpdateDrawingName:
|
||||
)
|
||||
ifc.resolve_uri("relative_layout_uri").should_be_called().will_return("absolute_layout_uri")
|
||||
drawing.does_file_exist("absolute_layout_uri").should_be_called().will_return(True)
|
||||
drawing.update_embedded_svg_location("absolute_layout_uri", "reference_with_old_location", "new_uri").should_be_called()
|
||||
drawing.update_embedded_svg_location(
|
||||
"absolute_layout_uri", "reference_with_old_location", "new_uri"
|
||||
).should_be_called()
|
||||
|
||||
drawing.is_editing_sheets().should_be_called().will_return(True)
|
||||
drawing.import_sheets().should_be_called()
|
||||
|
||||
Reference in New Issue
Block a user