Fix UI bugs for settings predefined types / assign_type to prevent invalid ifc (#7011)

This commit is contained in:
Christoph Mellüh
2025-08-12 08:11:55 +02:00
committed by GitHub
parent b5e977d7f3
commit 3e5a2e5eb2
4 changed files with 55 additions and 6 deletions
@@ -255,6 +255,8 @@ class IfcClassData:
if not element:
return False
if element_type := ifcopenshell.util.element.get_type(element):
if element_type == element:
return False
# Allow for None due to https://github.com/buildingSMART/IFC4.3.x-development/issues/818
return ifcopenshell.util.element.get_predefined_type(element_type) not in ("NOTDEFINED", None)
return False
+14 -3
View File
@@ -59,10 +59,14 @@ class BIM_PT_class(Panel):
row = self.layout.row(align=True)
row.operator("bim.reassign_class", icon="CHECKMARK")
row.operator("bim.disable_reassign_class", icon="CANCEL", text="")
# If Entity has inherited Predefined Type, disable PredefinedType / ObjectType dropdown to forbid double typing. See #7006)
enable_predef_types = not IfcClassData.data["has_inherited_predefined_type"]
self.draw_class_dropdowns(
context,
root_prop.get_ifc_predefined_types(rprops, context),
is_reassigning_class=True,
set_predefined_types_enabled=enable_predef_types,
)
self.layout.prop(rprops, "relating_class_object", icon="COPYDOWN")
else:
@@ -82,22 +86,29 @@ class BIM_PT_class(Panel):
return
ifc_predefined_types = root_prop.get_ifc_predefined_types(rprops, context)
self.draw_class_dropdowns(context, ifc_predefined_types)
# If Entity has inherited Predefined Type, disable PredefinedType / ObjectType dropdown to forbid double typing. See #7006)
enable_predef_types = not IfcClassData.data["has_inherited_predefined_type"]
self.draw_class_dropdowns(context, ifc_predefined_types, set_predefined_types_enabled=enable_predef_types)
row = self.layout.row(align=True)
op = row.operator("bim.assign_class")
op.ifc_class = rprops.ifc_class
op.predefined_type = rprops.ifc_predefined_type if ifc_predefined_types else ""
op.userdefined_type = rprops.ifc_userdefined_type
def draw_class_dropdowns(self, context, ifc_predefined_types, is_reassigning_class=False):
def draw_class_dropdowns(
self, context, ifc_predefined_types, is_reassigning_class=False, set_predefined_types_enabled=True
):
props = tool.Root.get_root_props()
layout = self.layout
prop_with_search(layout, props, "ifc_product")
prop_with_search(layout, props, "ifc_class")
if ifc_predefined_types:
prop_with_search(layout, props, "ifc_predefined_type")
row = prop_with_search(layout, props, "ifc_predefined_type")
row.enabled = set_predefined_types_enabled
if props.ifc_predefined_type == "USERDEFINED":
row = layout.row()
row.prop(props, "ifc_userdefined_type")
row.enabled = set_predefined_types_enabled
if not is_reassigning_class:
prop_with_search(layout, props, "contexts")