mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Fix bug where you could reassign class to another product type and create invalid relationships
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user