diff --git a/src/blenderbim/blenderbim/bim/module/root/data.py b/src/blenderbim/blenderbim/bim/module/root/data.py index 6b91e18ab8..3ee83bb6db 100644 --- a/src/blenderbim/blenderbim/bim/module/root/data.py +++ b/src/blenderbim/blenderbim/bim/module/root/data.py @@ -42,6 +42,7 @@ class IfcClassData: cls.data["contexts"] = cls.contexts() cls.data["has_entity"] = cls.has_entity() cls.data["name"] = cls.name() + cls.data["has_inherited_predefined_type"] = cls.has_inherited_predefined_type() cls.data["ifc_class"] = cls.ifc_class() cls.data["ifc_predefined_types"] = cls.ifc_predefined_types() cls.data["can_reassign_class"] = cls.can_reassign_class() @@ -162,6 +163,15 @@ class IfcClassData: name += f"[{predefined_type}]" return name + @classmethod + def has_inherited_predefined_type(cls): + element = tool.Ifc.get_entity(bpy.context.view_layer.objects.active) + if not element: + return + if element_type := ifcopenshell.util.element.get_type(element): + return ifcopenshell.util.element.get_predefined_type(element_type) != "NOTDEFINED" + return False + @classmethod def ifc_class(cls): element = tool.Ifc.get_entity(bpy.context.view_layer.objects.active) diff --git a/src/blenderbim/blenderbim/bim/module/root/ui.py b/src/blenderbim/blenderbim/bim/module/root/ui.py index b80c733ee5..a57bec2e40 100644 --- a/src/blenderbim/blenderbim/bim/module/root/ui.py +++ b/src/blenderbim/blenderbim/bim/module/root/ui.py @@ -61,7 +61,10 @@ class BIM_PT_class(Panel): self.layout.prop(context.scene.BIMRootProperties, "relating_class_object", icon="COPYDOWN") else: row = self.layout.row(align=True) - row.label(text=IfcClassData.data["name"]) + row.label( + text=IfcClassData.data["name"], + icon="CON_CHILDOF" if IfcClassData.data["has_inherited_predefined_type"] else "NONE", + ) row.operator("bim.select_ifc_class", text="", icon="RESTRICT_SELECT_OFF") row.operator("bim.unlink_object", icon="UNLINKED", text="") if IfcClassData.data["can_reassign_class"]: diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 6c084b57ad..f5c788a8aa 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -26,10 +26,10 @@ def get_pset( element: ifcopenshell.entity_instance, name: str, prop: Optional[str] = None, - psets_only=False, - qtos_only=False, - should_inherit=True, - verbose=False, + psets_only: bool = False, + qtos_only: bool = False, + should_inherit: bool = True, + verbose: bool = False, ) -> Union[Any, dict[str, Any]]: """Retrieve a single property set or single property @@ -429,8 +429,7 @@ def get_predefined_type(element: ifcopenshell.entity_instance) -> str: element = ifcopenshell.by_type("IfcWall")[0] predefined_type = ifcopenshell.util.element.get_predefined_type(element) """ - element_type = get_type(element) - if element_type: + if element_type := get_type(element): predefined_type = getattr(element_type, "PredefinedType", None) if predefined_type == "USERDEFINED" or not predefined_type: predefined_type = getattr(element_type, "ElementType", ...) @@ -563,7 +562,9 @@ def get_material( return get_material(relating_type, should_skip_usage) -def get_materials(element: ifcopenshell.entity_instance, should_inherit=True) -> list[ifcopenshell.entity_instance]: +def get_materials( + element: ifcopenshell.entity_instance, should_inherit: bool = True +) -> list[ifcopenshell.entity_instance]: """Gets individual materials of an element If the element has a material set, the individual materials of that set are @@ -826,7 +827,7 @@ def get_layers( def get_container( - element: ifcopenshell.entity_instance, should_get_direct=False, ifc_class: Optional[str] = None + element: ifcopenshell.entity_instance, should_get_direct: bool = False, ifc_class: Optional[str] = None ) -> ifcopenshell.entity_instance: """ Retrieves the spatial structure container of an element. diff --git a/src/ifcopenshell-python/test/util/test_element.py b/src/ifcopenshell-python/test/util/test_element.py index c8a63e299d..9a038b044b 100644 --- a/src/ifcopenshell-python/test/util/test_element.py +++ b/src/ifcopenshell-python/test/util/test_element.py @@ -291,6 +291,16 @@ class TestGetPredefinedTypeIFC4(test.bootstrap.IFC4): element_type.ProcessType = "FOOBAR" assert subject.get_predefined_type(element) == "FOOBAR" + def test_getting_an_element_type_predefined_type(self): + element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + element_type.PredefinedType = "PARTITIONING" + assert subject.get_predefined_type(element_type) == "PARTITIONING" + + def test_getting_an_element_type_null_predefined_type(self): + element_type = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType") + element_type.PredefinedType = "NOTDEFINED" + assert subject.get_predefined_type(element_type) == "NOTDEFINED" + class TestGetTypeIFC4(test.bootstrap.IFC4): def test_getting_the_type_of_a_product(self):