From 29bd89324a71f0b211f600b30f19f1804184fae5 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 23 May 2025 13:51:24 +0500 Subject: [PATCH] ifcopenshell.geom.tree.get_clash_type --- src/ifcclash/ifcclash/ifcclash.py | 7 ++----- src/ifcopenshell-python/ifcopenshell/geom/main.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ifcclash/ifcclash/ifcclash.py b/src/ifcclash/ifcclash/ifcclash.py index 5769a554b1..409fb914d7 100644 --- a/src/ifcclash/ifcclash/ifcclash.py +++ b/src/ifcclash/ifcclash/ifcclash.py @@ -40,9 +40,6 @@ class ClashSource(TypedDict): ifc: NotRequired[ifcopenshell.file] -ClashType = Literal["protrusion", "pierce", "collision", "clearance"] - - class ClashResult(TypedDict): a_global_id: str b_global_id: str @@ -50,7 +47,7 @@ class ClashResult(TypedDict): b_ifc_class: str a_name: str b_name: str - type: ClashType + type: ifcopenshell.geom.main.ClashType p1: list[float] p2: list[float] distance: float @@ -146,7 +143,7 @@ class Clasher: b_ifc_class=element2.is_a(), a_name=element1.get_argument(2), b_name=element2.get_argument(2), - type=("protrusion", "pierce", "collision", "clearance")[result.clash_type], + type=self.tree.get_clash_type(result.clash_type), p1=list(result.p1), p2=list(result.p2), distance=result.distance, diff --git a/src/ifcopenshell-python/ifcopenshell/geom/main.py b/src/ifcopenshell-python/ifcopenshell/geom/main.py index e467ae5bc0..edebc2c206 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/main.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/main.py @@ -343,6 +343,10 @@ class iterator(ifcopenshell_wrapper.Iterator): break +ClashType = Literal["protrusion", "pierce", "collision", "clearance"] +CLASH_TYPE_ITEMS = ("protrusion", "pierce", "collision", "clearance") + + class tree(ifcopenshell_wrapper.tree): def __init__(self, file: Optional[file] = None, settings: Optional[settings] = None): args = [self] @@ -429,6 +433,14 @@ class tree(ifcopenshell_wrapper.tree): args = [self, [e.wrapped_data for e in set_a], [e.wrapped_data for e in set_b], clearance, check_all] return ifcopenshell_wrapper.tree.clash_clearance_many(*args) + @staticmethod + def get_clash_type(clash_type_i: int) -> ClashType: + """Convert clash type index to a readable string format. + + :param clash_type_i: Type index that comes from ``clash.clash_type``. + """ + return CLASH_TYPE_ITEMS[clash_type_i] + def create_shape( settings: settings,