Attribute.is_uri - move to Attribute.special_type

This commit is contained in:
Andrej730
2025-07-08 10:29:29 +05:00
parent 7f3860b025
commit 188b6a03a8
5 changed files with 12 additions and 11 deletions
+4 -3
View File
@@ -103,7 +103,7 @@ def draw_attribute(
text=attribute.display_name, 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 = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER")
op.data_path = attribute.path_from_id("string_value") op.data_path = attribute.path_from_id("string_value")
elif attribute.special_type in ("DATE", "DATETIME"): elif attribute.special_type in ("DATE", "DATETIME"):
@@ -186,8 +186,9 @@ def import_attribute(
props.remove(len(props) - 1) props.remove(len(props) - 1)
elif data_type == "string": elif data_type == "string":
new.string_value = "" if new.is_null else str(data[attribute.name()]).replace("\n", "\\n") new.string_value = "" if new.is_null else str(data[attribute.name()]).replace("\n", "\\n")
if attribute.type_of_attribute().declared_type().name() == "IfcURIReference": attribute_type = attribute.type_of_attribute()
new.is_uri = True if attribute_type._is("IfcURIReference"):
new.special_type = "URI"
elif attribute.type_of_attribute()._is("IfcDate"): elif attribute.type_of_attribute()._is("IfcDate"):
new.special_type = "DATE" new.special_type = "DATE"
elif attribute.type_of_attribute()._is("IfcDateTime"): elif attribute.type_of_attribute()._is("IfcDateTime"):
+1 -1
View File
@@ -60,7 +60,7 @@ def draw_single_property(prop: IfcProperty, layout: bpy.types.UILayout, copy_ope
value_name, value_name,
text=prop.metadata.display_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 = layout.operator("bim.select_uri_attribute", text="", icon="FILE_FOLDER")
op.data_path = prop.metadata.path_from_id("string_value") op.data_path = prop.metadata.path_from_id("string_value")
if prop.metadata.is_optional: if prop.metadata.is_optional:
@@ -167,7 +167,6 @@ class ColourRgb(PropertyGroup):
} }
# to fit blender.bim.helper.draw_attribute # to fit blender.bim.helper.draw_attribute
is_uri = False
is_optional = False is_optional = False
special_type = "" special_type = ""
+1 -3
View File
@@ -287,7 +287,7 @@ def get_display_name(self: "Attribute") -> str:
AttributeDataType = Literal["string", "integer", "float", "boolean", "enum", "file"] 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): class Attribute(PropertyGroup):
@@ -331,7 +331,6 @@ class Attribute(PropertyGroup):
filter_glob: StringProperty() filter_glob: StringProperty()
is_null: BoolProperty(name="Is Null", update=update_is_null) is_null: BoolProperty(name="Is Null", update=update_is_null)
is_optional: BoolProperty(name="Is Optional") is_optional: BoolProperty(name="Is Optional")
is_uri: BoolProperty(name="Is Uri", default=False)
is_selected: BoolProperty(name="Is Selected", 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: 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") 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 filter_glob: str
is_null: bool is_null: bool
is_optional: bool is_optional: bool
is_uri: bool
is_selected: bool is_selected: bool
value_min: float value_min: float
value_min_constraint: bool value_min_constraint: bool
+6 -3
View File
@@ -108,7 +108,9 @@ class Pset(bonsai.core.tool.Pset):
) )
@classmethod @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 = "" special_type = ""
if prop_or_prop_template.is_a("IfcPropertyTemplate"): if prop_or_prop_template.is_a("IfcPropertyTemplate"):
primary_measure_type = prop_or_prop_template.PrimaryMeasureType primary_measure_type = prop_or_prop_template.PrimaryMeasureType
@@ -119,6 +121,8 @@ class Pset(bonsai.core.tool.Pset):
special_type = "AREA" special_type = "AREA"
elif primary_measure_type == "IfcVolumeMeasure" or template_type == "Q_VOLUME": elif primary_measure_type == "IfcVolumeMeasure" or template_type == "Q_VOLUME":
special_type = "VOLUME" special_type = "VOLUME"
elif primary_measure_type == "IfcURIReference":
special_type = "URI"
else: else:
if prop_or_prop_template.is_a("IfcPropertySingleValue"): if prop_or_prop_template.is_a("IfcPropertySingleValue"):
value = prop_or_prop_template.NominalValue value = prop_or_prop_template.NominalValue
@@ -246,7 +250,7 @@ class Pset(bonsai.core.tool.Pset):
metadata.name = prop_template.Name metadata.name = prop_template.Name
metadata.is_null = data.get(prop_template.Name, None) is None metadata.is_null = data.get(prop_template.Name, None) is None
metadata.is_optional = True 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 # Cute hack to abuse the metadata to find the Blender data_type
metadata.set_value(enum_items[0]) metadata.set_value(enum_items[0])
@@ -272,7 +276,6 @@ class Pset(bonsai.core.tool.Pset):
metadata.name = prop_template.Name metadata.name = prop_template.Name
metadata.is_null = data.get(prop_template.Name, None) is None metadata.is_null = data.get(prop_template.Name, None) is None
metadata.is_optional = True metadata.is_optional = True
metadata.is_uri = prop_template.PrimaryMeasureType == "IfcURIReference"
metadata.data_type = cls.get_prop_template_primitive_type(prop_template) metadata.data_type = cls.get_prop_template_primitive_type(prop_template)
metadata.special_type = cls.get_special_type_for_prop(prop_template) metadata.special_type = cls.get_special_type_for_prop(prop_template)