From ceaa930aad6256056fc2fa66a6351c7f832b4a39 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 11 Feb 2023 11:03:35 +1100 Subject: [PATCH] Fix #2756. Bug where reassigning classes with a enum didn't work. --- src/blenderbim/test/bim/feature/root.feature | 3 ++- src/ifcopenshell-python/ifcopenshell/util/schema.py | 7 ++++++- src/ifcopenshell-python/ifcopenshell/util/shape.py | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/blenderbim/test/bim/feature/root.feature b/src/blenderbim/test/bim/feature/root.feature index 91acc14204..9b80a2419a 100644 --- a/src/blenderbim/test/bim/feature/root.feature +++ b/src/blenderbim/test/bim/feature/root.feature @@ -6,11 +6,12 @@ Scenario: Reassign class And I add a cube And the object "Cube" is selected And I set "scene.BIMRootProperties.ifc_class" to "IfcWall" - And I press "bim.assign_class" + And I press "bim.assign_class(ifc_class='IfcWall', predefined_type='SOLIDWALL')" And I press "object.duplicate_move" When the object "IfcWall/Cube.001" is selected And I press "bim.enable_reassign_class" And I set "scene.BIMRootProperties.ifc_class" to "IfcSlab" + And I set "scene.BIMRootProperties.ifc_predefined_type" to "BASESLAB" And I press "bim.reassign_class" Then the object "IfcSlab/Cube" is an "IfcSlab" diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index e3f3fdc3e1..41c717ebe2 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -20,6 +20,7 @@ import os import json import time import ifcopenshell +import ifcopenshell.util.attribute # This is highly experimental and incomplete, however, it may work for simple datasets. # In this simple implementation, we only support 2X3<->4 right now @@ -76,7 +77,11 @@ def reassign_class(ifc_file, element, new_class): name = attribute.name() old_attribute = info.get(name, None) if old_attribute: - new_attributes[name] = old_attribute + if ifcopenshell.util.attribute.get_primitive_type(attribute) == "enum": + if old_attribute in ifcopenshell.util.attribute.get_enum_items(attribute): + new_attributes[name] = old_attribute + else: + new_attributes[name] = old_attribute inverse_pairs = ifc_file.get_inverse(element, allow_duplicate=True, with_attribute_indices=True) ifc_file.remove(element) diff --git a/src/ifcopenshell-python/ifcopenshell/util/shape.py b/src/ifcopenshell-python/ifcopenshell/util/shape.py index 9baf5a0464..27da278034 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/shape.py +++ b/src/ifcopenshell-python/ifcopenshell/util/shape.py @@ -26,6 +26,7 @@ def is_x(value, x): def get_volume(geometry): + # https://stackoverflow.com/questions/1406029/how-to-calculate-the-volume-of-a-3d-mesh-object-the-surface-of-which-is-made-up def signed_triangle_volume(p1, p2, p3): v321 = p3[0] * p2[1] * p1[2] v231 = p2[0] * p3[1] * p1[2]