From 188b6a03a847039c7e23a5897f945f900f519839 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 8 Jul 2025 10:29:29 +0500 Subject: [PATCH] Attribute.is_uri - move to Attribute.special_type --- src/bonsai/bonsai/bim/helper.py | 7 ++++--- src/bonsai/bonsai/bim/module/pset/ui.py | 2 +- src/bonsai/bonsai/bim/module/style/prop.py | 1 - src/bonsai/bonsai/bim/prop.py | 4 +--- src/bonsai/bonsai/tool/pset.py | 9 ++++++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/bonsai/bonsai/bim/helper.py b/src/bonsai/bonsai/bim/helper.py index 32ee842ae3..fc24a80e36 100644 --- a/src/bonsai/bonsai/bim/helper.py +++ b/src/bonsai/bonsai/bim/helper.py @@ -103,7 +103,7 @@ def draw_attribute( text=attribute.display_name, ) - if attribute.is_uri: + if attribute.special_type == "URI": op = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER") op.data_path = attribute.path_from_id("string_value") elif attribute.special_type in ("DATE", "DATETIME"): @@ -186,8 +186,9 @@ def import_attribute( props.remove(len(props) - 1) elif data_type == "string": new.string_value = "" if new.is_null else str(data[attribute.name()]).replace("\n", "\\n") - if attribute.type_of_attribute().declared_type().name() == "IfcURIReference": - new.is_uri = True + attribute_type = attribute.type_of_attribute() + if attribute_type._is("IfcURIReference"): + new.special_type = "URI" elif attribute.type_of_attribute()._is("IfcDate"): new.special_type = "DATE" elif attribute.type_of_attribute()._is("IfcDateTime"): diff --git a/src/bonsai/bonsai/bim/module/pset/ui.py b/src/bonsai/bonsai/bim/module/pset/ui.py index 0f40e05c77..f63f9e3189 100644 --- a/src/bonsai/bonsai/bim/module/pset/ui.py +++ b/src/bonsai/bonsai/bim/module/pset/ui.py @@ -60,7 +60,7 @@ def draw_single_property(prop: IfcProperty, layout: bpy.types.UILayout, copy_ope value_name, text=prop.metadata.display_name, ) - if prop.metadata.is_uri: + if prop.metadata.special_type == "URI": op = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER") op.data_path = prop.metadata.path_from_id("string_value") if prop.metadata.is_optional: diff --git a/src/bonsai/bonsai/bim/module/style/prop.py b/src/bonsai/bonsai/bim/module/style/prop.py index 11dcf72f92..158d29994d 100644 --- a/src/bonsai/bonsai/bim/module/style/prop.py +++ b/src/bonsai/bonsai/bim/module/style/prop.py @@ -167,7 +167,6 @@ class ColourRgb(PropertyGroup): } # to fit blender.bim.helper.draw_attribute - is_uri = False is_optional = False special_type = "" diff --git a/src/bonsai/bonsai/bim/prop.py b/src/bonsai/bonsai/bim/prop.py index 552e127116..22444ad3d2 100644 --- a/src/bonsai/bonsai/bim/prop.py +++ b/src/bonsai/bonsai/bim/prop.py @@ -287,7 +287,7 @@ def get_display_name(self: "Attribute") -> str: AttributeDataType = Literal["string", "integer", "float", "boolean", "enum", "file"] -AttributeSpecialType = Literal["", "DATE", "DATETIME", "LENGTH", "AREA", "VOLUME", "FORCE", "LOGICAL"] +AttributeSpecialType = Literal["", "DATE", "DATETIME", "LENGTH", "AREA", "VOLUME", "FORCE", "LOGICAL", "URI"] class Attribute(PropertyGroup): @@ -331,7 +331,6 @@ class Attribute(PropertyGroup): filter_glob: StringProperty() is_null: BoolProperty(name="Is Null", update=update_is_null) is_optional: BoolProperty(name="Is Optional") - is_uri: BoolProperty(name="Is Uri", default=False) is_selected: BoolProperty(name="Is Selected", default=False) value_min: FloatProperty(description="This is used to validate int_value and float_value") value_min_constraint: BoolProperty(default=False, description="True if the numerical value has a lower bound") @@ -361,7 +360,6 @@ class Attribute(PropertyGroup): filter_glob: str is_null: bool is_optional: bool - is_uri: bool is_selected: bool value_min: float value_min_constraint: bool diff --git a/src/bonsai/bonsai/tool/pset.py b/src/bonsai/bonsai/tool/pset.py index 11c2478a59..cb7d7216eb 100644 --- a/src/bonsai/bonsai/tool/pset.py +++ b/src/bonsai/bonsai/tool/pset.py @@ -108,7 +108,9 @@ class Pset(bonsai.core.tool.Pset): ) @classmethod - def get_special_type_for_prop(cls, prop_or_prop_template: ifcopenshell.entity_instance) -> str: + def get_special_type_for_prop( + cls, prop_or_prop_template: ifcopenshell.entity_instance + ) -> Literal["LENGTH"] | Literal["AREA"] | Literal["VOLUME"] | Literal["URI"] | Literal[""]: special_type = "" if prop_or_prop_template.is_a("IfcPropertyTemplate"): primary_measure_type = prop_or_prop_template.PrimaryMeasureType @@ -119,6 +121,8 @@ class Pset(bonsai.core.tool.Pset): special_type = "AREA" elif primary_measure_type == "IfcVolumeMeasure" or template_type == "Q_VOLUME": special_type = "VOLUME" + elif primary_measure_type == "IfcURIReference": + special_type = "URI" else: if prop_or_prop_template.is_a("IfcPropertySingleValue"): value = prop_or_prop_template.NominalValue @@ -246,7 +250,7 @@ class Pset(bonsai.core.tool.Pset): metadata.name = prop_template.Name metadata.is_null = data.get(prop_template.Name, None) is None metadata.is_optional = True - metadata.is_uri = prop_template.PrimaryMeasureType == "IfcURIReference" + metadata.special_type = "URI" if prop_template.PrimaryMeasureType == "IfcURIReference" else "" # Cute hack to abuse the metadata to find the Blender data_type metadata.set_value(enum_items[0]) @@ -272,7 +276,6 @@ class Pset(bonsai.core.tool.Pset): metadata.name = prop_template.Name metadata.is_null = data.get(prop_template.Name, None) is None metadata.is_optional = True - metadata.is_uri = prop_template.PrimaryMeasureType == "IfcURIReference" metadata.data_type = cls.get_prop_template_primitive_type(prop_template) metadata.special_type = cls.get_special_type_for_prop(prop_template)