Skip to content

Commit 29bd893

Browse files
committed
ifcopenshell.geom.tree.get_clash_type
1 parent 087608a commit 29bd893

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/ifcclash/ifcclash/ifcclash.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,14 @@ class ClashSource(TypedDict):
4040
ifc: NotRequired[ifcopenshell.file]
4141

4242

43-
ClashType = Literal["protrusion", "pierce", "collision", "clearance"]
44-
45-
4643
class ClashResult(TypedDict):
4744
a_global_id: str
4845
b_global_id: str
4946
a_ifc_class: str
5047
b_ifc_class: str
5148
a_name: str
5249
b_name: str
53-
type: ClashType
50+
type: ifcopenshell.geom.main.ClashType
5451
p1: list[float]
5552
p2: list[float]
5653
distance: float
@@ -146,7 +143,7 @@ def process_clash_set(self, clash_set: ClashSet) -> None:
146143
b_ifc_class=element2.is_a(),
147144
a_name=element1.get_argument(2),
148145
b_name=element2.get_argument(2),
149-
type=("protrusion", "pierce", "collision", "clearance")[result.clash_type],
146+
type=self.tree.get_clash_type(result.clash_type),
150147
p1=list(result.p1),
151148
p2=list(result.p2),
152149
distance=result.distance,

src/ifcopenshell-python/ifcopenshell/geom/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ def __iter__(self) -> Generator[IteratorOutput, None, None]:
343343
break
344344

345345

346+
ClashType = Literal["protrusion", "pierce", "collision", "clearance"]
347+
CLASH_TYPE_ITEMS = ("protrusion", "pierce", "collision", "clearance")
348+
349+
346350
class tree(ifcopenshell_wrapper.tree):
347351
def __init__(self, file: Optional[file] = None, settings: Optional[settings] = None):
348352
args = [self]
@@ -429,6 +433,14 @@ def clash_clearance_many(
429433
args = [self, [e.wrapped_data for e in set_a], [e.wrapped_data for e in set_b], clearance, check_all]
430434
return ifcopenshell_wrapper.tree.clash_clearance_many(*args)
431435

436+
@staticmethod
437+
def get_clash_type(clash_type_i: int) -> ClashType:
438+
"""Convert clash type index to a readable string format.
439+
440+
:param clash_type_i: Type index that comes from ``clash.clash_type``.
441+
"""
442+
return CLASH_TYPE_ITEMS[clash_type_i]
443+
432444

433445
def create_shape(
434446
settings: settings,

0 commit comments

Comments
 (0)