Fix errors regarding added PredefinedType to IfcAnnotations in IFC4X3 #6200

In IFC4X3 IfcAnnotation now has PredefinedType and checking ObjectType isn't enough.
This commit is contained in:
Andrej730
2025-02-21 18:38:31 +05:00
parent ee2fa739bb
commit 92c2fc0b7f
8 changed files with 44 additions and 28 deletions
+1 -1
View File
@@ -967,7 +967,7 @@ class IfcImporter:
tool.Collector.assign(obj, should_clean_users_collection=False) tool.Collector.assign(obj, should_clean_users_collection=False)
def is_curve_annotation(self, element: ifcopenshell.entity_instance) -> bool: def is_curve_annotation(self, element: ifcopenshell.entity_instance) -> bool:
object_type = element.ObjectType object_type = ifcopenshell.util.element.get_predefined_type(element)
return ( return (
object_type in tool.Drawing.ANNOTATION_TYPES_DATA object_type in tool.Drawing.ANNOTATION_TYPES_DATA
and tool.Drawing.ANNOTATION_TYPES_DATA[object_type].data_type == "curve" and tool.Drawing.ANNOTATION_TYPES_DATA[object_type].data_type == "curve"
@@ -153,7 +153,11 @@ class Annotator:
if object_type != "ANGLE": if object_type != "ANGLE":
for obj in collection.objects: for obj in collection.objects:
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
if element and element.ObjectType == object_type and obj.type == object_type.upper(): if (
element
and ifcopenshell.util.element.get_predefined_type(element) == object_type
and obj.type == object_type.upper()
):
return obj return obj
if data_type == "mesh": if data_type == "mesh":
+5 -1
View File
@@ -364,7 +364,11 @@ class DecoratorData:
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
supported_object_types = ("DIMENSION", "DIAMETER", "SECTION_LEVEL", "PLAN_LEVEL", "RADIUS") supported_object_types = ("DIMENSION", "DIAMETER", "SECTION_LEVEL", "PLAN_LEVEL", "RADIUS")
if not element or not element.is_a("IfcAnnotation") or element.ObjectType not in supported_object_types: if (
not element
or not element.is_a("IfcAnnotation")
or ifcopenshell.util.element.get_predefined_type(element) not in supported_object_types
):
return None return None
dimension_style = "arrow" dimension_style = "arrow"
@@ -977,6 +977,7 @@ class FallDecorator(BaseDecorator):
# same function as in svgwriter.py # same function as in svgwriter.py
def get_label_text(): def get_label_text():
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
assert element
B, A = [v.co.xyz for v in spline_points[:2]] B, A = [v.co.xyz for v in spline_points[:2]]
rise = abs(A.z - B.z) rise = abs(A.z - B.z)
O = A.copy() O = A.copy()
@@ -989,13 +990,14 @@ class FallDecorator(BaseDecorator):
angle = 90 angle = 90
# ues SLOPE_ANGLE as default # ues SLOPE_ANGLE as default
if element.ObjectType in ("FALL", "SLOPE_ANGLE"): object_type = ifcopenshell.util.element.get_predefined_type(element)
if object_type in ("FALL", "SLOPE_ANGLE"):
return f"{angle}°" return f"{angle}°"
elif element.ObjectType == "SLOPE_FRACTION": elif object_type == "SLOPE_FRACTION":
if angle == 90: if angle == 90:
return "-" return "-"
return f"{self.format_value(context, rise)} / {self.format_value(context, run)}" return f"{self.format_value(context, rise)} / {self.format_value(context, run)}"
elif element.ObjectType == "SLOPE_PERCENT": elif object_type == "SLOPE_PERCENT":
if angle == 90: if angle == 90:
return "-" return "-"
return f"{round(angle_tg * 100)} %" return f"{round(angle_tg * 100)} %"
@@ -2047,7 +2049,7 @@ class DecorationsHandler:
if not element.is_a("IfcAnnotation"): if not element.is_a("IfcAnnotation"):
continue continue
object_type: Union[str, None] = element.ObjectType object_type: Union[str, None] = ifcopenshell.util.element.get_predefined_type(element)
if object_type == "DRAWING": if object_type == "DRAWING":
continue continue
@@ -1370,7 +1370,11 @@ class CreateDrawing(bpy.types.Operator):
elements = list(elements | filtered_drawing_annotations) elements = list(elements | filtered_drawing_annotations)
annotations = sorted( annotations = sorted(
elements, key=lambda a: (tool.Drawing.get_annotation_z_index(a), 1 if a.ObjectType == "TEXT" else 0) elements,
key=lambda a: (
tool.Drawing.get_annotation_z_index(a),
1 if ifcopenshell.util.element.get_predefined_type(a) == "TEXT" else 0,
),
) )
precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "MetricPrecision") precision = ifcopenshell.util.element.get_pset(self.camera_element, "EPset_Drawing", "MetricPrecision")
@@ -181,35 +181,35 @@ class SvgWriter:
self.decimal_places = decimal_places self.decimal_places = decimal_places
for element in annotations: for element in annotations:
obj = tool.Ifc.get_object(element) obj = tool.Ifc.get_object(element)
if not obj or element.ObjectType == "DRAWING": if not obj or (object_type := ifcopenshell.util.element.get_predefined_type(element)) == "DRAWING":
continue continue
elif element.ObjectType == "GRID": elif object_type == "GRID":
self.draw_grid_annotation(obj) self.draw_grid_annotation(obj)
elif element.ObjectType == "TEXT_LEADER": elif object_type == "TEXT_LEADER":
self.draw_leader_annotation(obj) self.draw_leader_annotation(obj)
elif element.ObjectType == "STAIR_ARROW": elif object_type == "STAIR_ARROW":
self.draw_stair_annotation(obj) self.draw_stair_annotation(obj)
elif element.ObjectType == "DIMENSION": elif object_type == "DIMENSION":
self.draw_dimension_annotations(obj) self.draw_dimension_annotations(obj)
elif element.ObjectType == "ANGLE": elif object_type == "ANGLE":
self.draw_angle_annotations(obj) self.draw_angle_annotations(obj)
elif element.ObjectType == "RADIUS": elif object_type == "RADIUS":
self.draw_radius_annotations(obj) self.draw_radius_annotations(obj)
elif element.ObjectType == "DIAMETER": elif object_type == "DIAMETER":
self.draw_diameter_annotations(obj) self.draw_diameter_annotations(obj)
elif element.ObjectType == "ELEVATION": elif object_type == "ELEVATION":
self.draw_elevation_annotation(obj) self.draw_elevation_annotation(obj)
elif element.ObjectType == "SECTION": elif object_type == "SECTION":
self.draw_section_annotation(obj) self.draw_section_annotation(obj)
elif element.ObjectType == "BREAKLINE": elif object_type == "BREAKLINE":
self.draw_break_annotations(obj) self.draw_break_annotations(obj)
elif element.ObjectType == "PLAN_LEVEL": elif object_type == "PLAN_LEVEL":
self.draw_plan_level_annotation(obj) self.draw_plan_level_annotation(obj)
elif element.ObjectType == "SECTION_LEVEL": elif object_type == "SECTION_LEVEL":
self.draw_section_level_annotation(obj) self.draw_section_level_annotation(obj)
elif element.ObjectType == "TEXT": elif object_type == "TEXT":
self.draw_text_annotation(obj, obj.location) self.draw_text_annotation(obj, obj.location)
elif element.ObjectType in ("FALL", "SLOPE_ANGLE", "SLOPE_FRACTION", "SLOPE_PERCENT"): elif object_type in ("FALL", "SLOPE_ANGLE", "SLOPE_FRACTION", "SLOPE_PERCENT"):
self.draw_fall_annotations(obj) self.draw_fall_annotations(obj)
else: else:
self.draw_misc_annotation(obj) self.draw_misc_annotation(obj)
@@ -1207,13 +1207,14 @@ class SvgWriter:
angle = 90 angle = 90
# ues SLOPE_ANGLE as default # ues SLOPE_ANGLE as default
if element.ObjectType in ("FALL", "SLOPE_ANGLE"): object_type = ifcopenshell.util.element.get_predefined_type(element)
if object_type in ("FALL", "SLOPE_ANGLE"):
return f"{angle}°" return f"{angle}°"
elif element.ObjectType == "SLOPE_FRACTION": elif object_type == "SLOPE_FRACTION":
if angle == 90: if angle == 90:
return "-" return "-"
return f"{helper.format_distance(rise, precision=self.precision, decimal_places=self.decimal_places)} / {helper.format_distance(run, precision=self.precision, decimal_places=self.decimal_places)}" return f"{helper.format_distance(rise, precision=self.precision, decimal_places=self.decimal_places)} / {helper.format_distance(run, precision=self.precision, decimal_places=self.decimal_places)}"
elif element.ObjectType == "SLOPE_PERCENT": elif object_type == "SLOPE_PERCENT":
if angle == 90: if angle == 90:
return "-" return "-"
return f"{round(angle_tg * 100)} %" return f"{round(angle_tg * 100)} %"
@@ -19,6 +19,7 @@
import os import os
import bpy import bpy
import ifcopenshell.util.element
import bonsai.core.type import bonsai.core.type
import bonsai.core.drawing as core import bonsai.core.drawing as core
import bonsai.tool as tool import bonsai.tool as tool
@@ -333,7 +334,7 @@ class Hotkey(bpy.types.Operator, tool.Ifc.Operator):
if not element or not element.is_a("IfcAnnotation"): if not element or not element.is_a("IfcAnnotation"):
continue continue
annotation_type = element.ObjectType annotation_type = ifcopenshell.util.element.get_predefined_type(element)
if annotation_type not in tool.Drawing.ANNOTATION_TYPES_SUPPORT_SETUP: if annotation_type not in tool.Drawing.ANNOTATION_TYPES_SUPPORT_SETUP:
self.report({"ERROR"}, f"Annotation type {annotation_type} is not supported for readjustment.") self.report({"ERROR"}, f"Annotation type {annotation_type} is not supported for readjustment.")
continue continue
+1 -1
View File
@@ -245,7 +245,7 @@ class Drawing(bonsai.core.tool.Drawing):
element_type = element.is_a() element_type = element.is_a()
if element_type == "IfcAnnotation" and element.ObjectType in object_types: if element_type == "IfcAnnotation" and ifcopenshell.util.element.get_predefined_type(element) in object_types:
return True return True
if element_type == "IfcTypeProduct" and ( if element_type == "IfcTypeProduct" and (