From 6bfbcb8f92085f0f53476c593b6ebc9661473d24 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 21 Oct 2024 11:29:46 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/bim/module/root/operator.py | 1 + src/bonsai/bonsai/tool/geometry.py | 20 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index a9ddbd6a4d..ae636f4037 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -20,6 +20,7 @@ import bpy import bmesh import ifcopenshell import ifcopenshell.api +import ifcopenshell.api.geometry import ifcopenshell.util.schema import ifcopenshell.util.element import ifcopenshell.util.type diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 5463fa5982..873d4089b7 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -48,7 +48,7 @@ from collections import defaultdict from math import radians, pi from mathutils import Vector, Matrix from bonsai.bim.ifc import IfcStore -from typing import Union, Iterable, Optional, Literal, Iterator, List, TYPE_CHECKING +from typing import Union, Iterable, Optional, Literal, Iterator, List, TYPE_CHECKING, get_args from typing_extensions import TypeIs if TYPE_CHECKING: @@ -815,13 +815,9 @@ class Geometry(bonsai.core.tool.Geometry): ] @classmethod - def has_mesh_properties(cls, data: Union[bpy.types.ID, None]) -> TypeIs[TYPES_WITH_MESH_PROPERTIES]: - supported_types = ( - bpy.types.Mesh, - bpy.types.Curve, - bpy.types.Camera, - bpy.types.PointLight, - ) + def has_mesh_properties( + cls, data: Union[bpy.types.ID, None], supported_types=get_args(TYPES_WITH_MESH_PROPERTIES) + ) -> TypeIs[TYPES_WITH_MESH_PROPERTIES]: if not data: return False return isinstance(data, supported_types) @@ -888,10 +884,10 @@ class Geometry(bonsai.core.tool.Geometry): @classmethod def is_representation_item(cls, obj: bpy.types.Object) -> bool: - return ( - obj.data - and hasattr(obj.data, "BIMMeshProperties") - and (ifc_id := obj.data.BIMMeshProperties.ifc_definition_id) + return bool( + (data := obj.data) + and isinstance(data, Geometry.TYPES_WITH_MESH_PROPERTIES) + and (ifc_id := data.BIMMeshProperties.ifc_definition_id) and tool.Ifc.get().by_id(ifc_id).is_a("IfcRepresentationItem") )