From 9907651d4a764639efdb56b7d33ddd1fe22fe620 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 21 Oct 2021 11:28:49 +1100 Subject: [PATCH] Fix bug where you could reassign class to another product type and create invalid relationships --- .../blenderbim/bim/module/root/ui.py | 11 +++++--- .../test/api/root/test_reassign_class.py | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/ifcopenshell-python/test/api/root/test_reassign_class.py diff --git a/src/blenderbim/blenderbim/bim/module/root/ui.py b/src/blenderbim/blenderbim/bim/module/root/ui.py index c0329862f0..10f28fd70f 100644 --- a/src/blenderbim/blenderbim/bim/module/root/ui.py +++ b/src/blenderbim/blenderbim/bim/module/root/ui.py @@ -52,7 +52,9 @@ class BIM_PT_class(Panel): row.operator("bim.reassign_class", icon="CHECKMARK") row.operator("bim.disable_reassign_class", icon="CANCEL", text="") self.draw_class_dropdowns( - context, root_prop.getIfcPredefinedTypes(context.scene.BIMRootProperties, context) + context, + root_prop.getIfcPredefinedTypes(context.scene.BIMRootProperties, context), + should_draw_product=False, ) else: data = Data.products[props.ifc_definition_id] @@ -84,10 +86,11 @@ class BIM_PT_class(Panel): op.predefined_type = context.scene.BIMRootProperties.ifc_predefined_type if ifc_predefined_types else "" op.userdefined_type = context.scene.BIMRootProperties.ifc_userdefined_type - def draw_class_dropdowns(self, context, ifc_predefined_types): + def draw_class_dropdowns(self, context, ifc_predefined_types, should_draw_product=True): props = context.scene.BIMRootProperties - row = self.layout.row() - row.prop(props, "ifc_product") + if should_draw_product: + row = self.layout.row() + row.prop(props, "ifc_product") row = self.layout.row() row.prop(props, "ifc_class") if ifc_predefined_types: diff --git a/src/ifcopenshell-python/test/api/root/test_reassign_class.py b/src/ifcopenshell-python/test/api/root/test_reassign_class.py new file mode 100644 index 0000000000..0073b18079 --- /dev/null +++ b/src/ifcopenshell-python/test/api/root/test_reassign_class.py @@ -0,0 +1,26 @@ +import test.bootstrap +import ifcopenshell.api + + +class TestReassignClass(test.bootstrap.IFC4): + def test_reassigning_a_simple_class(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + new = ifcopenshell.api.run("root.reassign_class", self.file, product=element, ifc_class="IfcSlab") + assert len([e for e in self.file]) == 1 + assert new.id() == 2 + assert new.is_a("IfcSlab") + + def test_reassigning_a_predefined_type(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + new = ifcopenshell.api.run( + "root.reassign_class", self.file, product=element, ifc_class="IfcSlab", predefined_type="FLOOR" + ) + assert new.PredefinedType == "FLOOR" + + def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned(self): + element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall") + new = ifcopenshell.api.run( + "root.reassign_class", self.file, product=element, ifc_class="IfcSlab", predefined_type="FOO" + ) + assert new.PredefinedType == "USERDEFINED" + assert new.ObjectType == "FOO"