mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Fix UI bugs for settings predefined types / assign_type to prevent invalid ifc (#7011)
This commit is contained in:
@@ -188,10 +188,7 @@ class Usecase:
|
||||
if not related_objects:
|
||||
return
|
||||
|
||||
related_objects_set = set(related_objects)
|
||||
|
||||
ifc2x3 = self.file.schema == "IFC2X3"
|
||||
|
||||
related_objects_set = set(related_objects)
|
||||
if ifc2x3:
|
||||
types = next(iter(relating_type.ObjectTypeOf), None)
|
||||
@@ -257,6 +254,14 @@ class Usecase:
|
||||
relating_type=relating_type,
|
||||
)
|
||||
self.map_material_usages(objects_to_change, relating_type)
|
||||
|
||||
# Remove PredefinedType / ObjectType if existing to forbid double typing(See #7006)
|
||||
predefined_type = ifcopenshell.util.element.get_predefined_type(relating_type)
|
||||
if predefined_type != "NOTDEFINED" and predefined_type is not None:
|
||||
for obj in related_objects_set:
|
||||
obj.ObjectType = None
|
||||
if hasattr(obj, "PredefinedType"):
|
||||
obj.PredefinedType = None
|
||||
return types
|
||||
|
||||
def map_material_usages(
|
||||
|
||||
@@ -139,6 +139,37 @@ class TestAssignType(test.bootstrap.IFC4):
|
||||
assert (material := ifcopenshell.util.element.get_material(element1))
|
||||
assert material.id() == material_id
|
||||
|
||||
def test_remove_predefined_type_if_type_assignment(self):
|
||||
"""
|
||||
if an element has a PredefinedType, it should be removed when assigning a type.
|
||||
This is because the type will have its own PredefinedType, and the element's PredefinedType
|
||||
will conflict with it. (See #7006)
|
||||
"""
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element_type.PredefinedType = "MOVABLE"
|
||||
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.PredefinedType = "USERDEFINED"
|
||||
element.ObjectType = "Test"
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert element.PredefinedType is None
|
||||
assert element.ObjectType is None
|
||||
|
||||
def test_keep_predefined_type_if_type_assignment_is_notdefined(self):
|
||||
"""
|
||||
if an element has a PredefinedType, it will be removed when assigning a type.(See #7006)
|
||||
This behavior needs to be blocked if the PredefinedType of the typing Entity is set to "NOTDEFINED". (See #7011)
|
||||
"""
|
||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||
element_type.PredefinedType = "NOTDEFINED"
|
||||
|
||||
element = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWall")
|
||||
element.PredefinedType = "USERDEFINED"
|
||||
element.ObjectType = "Test"
|
||||
ifcopenshell.api.type.assign_type(self.file, related_objects=[element], relating_type=element_type)
|
||||
assert element.PredefinedType == "USERDEFINED"
|
||||
assert element.ObjectType == "Test"
|
||||
|
||||
|
||||
class TestAssignTypeIFC2X3(test.bootstrap.IFC2X3, TestAssignType):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user