From 0b4deee73fae841e03a9afdf10b608c59e7fa2ed Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 17 Mar 2025 15:08:25 +0500 Subject: [PATCH] typing --- .../bonsai/bim/module/drawing/helper.py | 1 + src/bonsai/bonsai/bim/module/geometry/data.py | 4 +++- src/bonsai/bonsai/bim/module/geometry/prop.py | 7 +++---- src/bonsai/bonsai/bim/module/material/ui.py | 4 ++-- src/bonsai/bonsai/bim/module/pset/ui.py | 20 +++++++++++-------- src/bonsai/bonsai/tool/pset.py | 6 +++++- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/drawing/helper.py b/src/bonsai/bonsai/bim/module/drawing/helper.py index 8c26a17cad..cbd98cfe5a 100644 --- a/src/bonsai/bonsai/bim/module/drawing/helper.py +++ b/src/bonsai/bonsai/bim/module/drawing/helper.py @@ -20,6 +20,7 @@ import bpy import math import mathutils.geometry import ifcopenshell +import ifcopenshell.util.unit import bonsai.tool as tool from mathutils import Vector from typing import Union diff --git a/src/bonsai/bonsai/bim/module/geometry/data.py b/src/bonsai/bonsai/bim/module/geometry/data.py index 2ba25df702..2522615885 100644 --- a/src/bonsai/bonsai/bim/module/geometry/data.py +++ b/src/bonsai/bonsai/bim/module/geometry/data.py @@ -157,15 +157,17 @@ class RepresentationsData: if not cls.data["representations"]: return [] obj = tool.Geometry.get_active_or_representation_obj() + assert obj if not obj.data: return [] element = tool.Ifc.get_entity(obj) + assert element base_representation = tool.Geometry.get_active_representation(obj) if not base_representation: return [] # Maybe in profile editing mode # shape aspects matching context of the active representation - matching_shape_aspects = [] + matching_shape_aspects: list[ifcopenshell.entity_instance] = [] for shape_aspect in ifcopenshell.util.element.get_shape_aspects(element): matching_representation = tool.Geometry.get_shape_aspect_representation(shape_aspect, base_representation) if matching_representation: diff --git a/src/bonsai/bonsai/bim/module/geometry/prop.py b/src/bonsai/bonsai/bim/module/geometry/prop.py index 7b80e9b040..6e67aca973 100644 --- a/src/bonsai/bonsai/bim/module/geometry/prop.py +++ b/src/bonsai/bonsai/bim/module/geometry/prop.py @@ -121,7 +121,7 @@ def get_layers_no_active(self, context): return LayersData.data["layers_enum_no_active"] -def update_shape_aspect(self, context): +def update_shape_aspect(self: "BIMObjectGeometryProperties", context: bpy.types.Context) -> None: shape_aspect_id = self.representation_item_shape_aspect attrs = self.shape_aspect_attrs @@ -250,9 +250,8 @@ class BIMObjectGeometryProperties(PropertyGroup): representation_item_layer: EnumProperty(items=get_layers, name="Representation Item's Layer") @property - def active_item(self): - if 0 <= self.active_item_index < len(self.items): - return self.items[self.active_item_index] + def active_item(self) -> Union[RepresentationItem, None]: + return tool.Blender.get_active_uilist_element(self.items, self.active_item_index) if TYPE_CHECKING: contexts: str diff --git a/src/bonsai/bonsai/bim/module/material/ui.py b/src/bonsai/bonsai/bim/module/material/ui.py index 6ca1d659ed..1b49a4aeee 100644 --- a/src/bonsai/bonsai/bim/module/material/ui.py +++ b/src/bonsai/bonsai/bim/module/material/ui.py @@ -24,7 +24,7 @@ from bpy.types import Panel, UIList from bonsai.bim.helper import draw_attributes from bonsai.bim.helper import prop_with_search from bonsai.bim.module.material.data import MaterialsData, ObjectMaterialData -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Any if TYPE_CHECKING: from bonsai.bim.module.material.prop import Material, BIMMaterialProperties @@ -289,7 +289,7 @@ class BIM_PT_object_material(Panel): row = box.row() prop_with_search(row, self.mprops, "profiles", icon="ITALIC", text="Profile") - def draw_read_only_set_item_ui(self, box, set_item): + def draw_read_only_set_item_ui(self, box: bpy.types.UILayout, set_item: dict[str, Any]) -> None: if ObjectMaterialData.data["material_class"] == "IfcMaterialList": row = box.row(align=True) row.label(text="IfcMaterial", icon="LAYER_ACTIVE") diff --git a/src/bonsai/bonsai/bim/module/pset/ui.py b/src/bonsai/bonsai/bim/module/pset/ui.py index 5bc6de9b6f..62fd6366c9 100644 --- a/src/bonsai/bonsai/bim/module/pset/ui.py +++ b/src/bonsai/bonsai/bim/module/pset/ui.py @@ -237,7 +237,8 @@ class BIM_PT_object_psets(Panel): def draw_header(self, context): row = self.layout.row(align=True) row.label(text="") # empty text occupies the left of the row - row.prop(context.scene.GlobalPsetProperties, "pset_filter", text="", icon="VIEWZOOM") + global_props = tool.Pset.get_global_pset_props() + row.prop(global_props, "pset_filter", text="", icon="VIEWZOOM") @classmethod def poll(cls, context): @@ -261,6 +262,7 @@ class BIM_PT_object_psets(Panel): op.obj = context.active_object.name op.obj_type = "Object" + global_props = tool.Pset.get_global_pset_props() if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "PSET": draw_psetqto_ui( context, @@ -269,7 +271,7 @@ class BIM_PT_object_psets(Panel): props, self.layout, "Object", - filter_keyword=context.scene.GlobalPsetProperties.pset_filter, + filter_keyword=global_props.pset_filter, ) if ObjectPsetsData.data["psets"]: @@ -285,7 +287,7 @@ class BIM_PT_object_psets(Panel): props, self.layout, "Object", - filter_keyword=context.scene.GlobalPsetProperties.pset_filter, + filter_keyword=global_props.pset_filter, ) if ObjectPsetsData.data["inherited_psets"]: @@ -299,7 +301,7 @@ class BIM_PT_object_psets(Panel): self.layout, "Object", allow_removing=False, - filter_keyword=context.scene.GlobalPsetProperties.pset_filter, + filter_keyword=global_props.pset_filter, ) @@ -315,7 +317,8 @@ class BIM_PT_object_qtos(Panel): def draw_header(self, context): row = self.layout.row(align=True) row.label(text="") # empty text occupies the left of the row - row.prop(context.scene.GlobalPsetProperties, "qto_filter", text="", icon="VIEWZOOM") + global_props = tool.Pset.get_global_pset_props() + row.prop(global_props, "qto_filter", text="", icon="VIEWZOOM") @classmethod def poll(cls, context): @@ -339,6 +342,7 @@ class BIM_PT_object_qtos(Panel): op.obj = context.active_object.name op.obj_type = "Object" + global_props = tool.Pset.get_global_pset_props() if not props.active_pset_id and props.active_pset_name and props.active_pset_type == "QTO": draw_psetqto_ui( context, @@ -347,7 +351,7 @@ class BIM_PT_object_qtos(Panel): props, self.layout, "Object", - filter_keyword=context.scene.GlobalPsetProperties.qto_filter, + filter_keyword=global_props.qto_filter, ) if ObjectQtosData.data["qtos"]: @@ -363,7 +367,7 @@ class BIM_PT_object_qtos(Panel): props, self.layout, "Object", - filter_keyword=context.scene.GlobalPsetProperties.qto_filter, + filter_keyword=global_props.qto_filter, ) if ObjectQtosData.data["inherited_qsets"]: @@ -377,7 +381,7 @@ class BIM_PT_object_qtos(Panel): self.layout, "Object", allow_removing=False, - filter_keyword=context.scene.GlobalPsetProperties.qto_filter, + filter_keyword=global_props.qto_filter, ) layout = self.layout qtoprops = tool.Qto.get_qto_props() diff --git a/src/bonsai/bonsai/tool/pset.py b/src/bonsai/bonsai/tool/pset.py index 39e4b0d721..d979fdb1ac 100644 --- a/src/bonsai/bonsai/tool/pset.py +++ b/src/bonsai/bonsai/tool/pset.py @@ -31,12 +31,16 @@ from typing_extensions import assert_never if TYPE_CHECKING: - from bonsai.bim.module.pset.prop import PsetProperties + from bonsai.bim.module.pset.prop import PsetProperties, GlobalPsetProperties class Pset(bonsai.core.tool.Pset): PSET_TYPE = Literal["PSET", "QTO"] + @classmethod + def get_global_pset_props(cls) -> GlobalPsetProperties: + return bpy.context.scene.GlobalPsetProperties + @classmethod def get_element_pset( cls, element: ifcopenshell.entity_instance, pset_name: str