bim.reassign_class - fix issue in ifc2x3 when selected product class would be ignored

E.g. you select IfcSlab and change it to IfcRoof - since there is not IfcRoofType in IFC2X3 it would figure the matching product type is IfcBeamType (which is confusing too but that's another subject) and change this slab's type object to IfcBeamType which consequently change IfcSlab to IfcBeam instead of IfcRoof that was selected originally.

Noticed investigating #5918
This commit is contained in:
Andrej730
2025-03-11 18:35:34 +05:00
parent 5b95bb37e6
commit 977d814d39
3 changed files with 43 additions and 5 deletions
@@ -198,4 +198,25 @@ class TestReassignClass(test.bootstrap.IFC4):
class TestReassignClassIFC2X3(test.bootstrap.IFC2X3, TestReassignClass):
pass
def test_providing_occurrence_class(self):
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
element1 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element1], relating_type=element_type)
element2 = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
ifcopenshell.api.type.assign_type(self.file, related_objects=[element2], relating_type=element_type)
new_element_type = ifcopenshell.api.root.reassign_class(
self.file,
product=element_type,
ifc_class="IfcBuildingElementProxyType",
occurrence_class="IfcRoof",
)
assert new_element_type.is_a("IfcBuildingElementProxyType")
occurrences = ifcopenshell.util.element.get_types(new_element_type)
assert len(occurrences) == 2
# Assign IfcRoof instead of IfcBuildingElementProxy.
assert all(o.is_a("IfcRoof") for o in occurrences)
# original clases are gone
assert len(self.file.by_type("IfcWall")) == 0
assert len(self.file.by_type("IfcWallType")) == 0