From 6ac40b4ab368135c9ee978cd3da490f572fbe3d1 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 25 Sep 2024 10:24:55 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/bim/module/geometry/operator.py | 12 ++++++++---- src/bonsai/bonsai/tool/geometry.py | 14 +++++++++----- src/ifcopenshell-python/ifcopenshell/sql.py | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/geometry/operator.py b/src/bonsai/bonsai/bim/module/geometry/operator.py index 4cefd1969b..6f7a400cb1 100644 --- a/src/bonsai/bonsai/bim/module/geometry/operator.py +++ b/src/bonsai/bonsai/bim/module/geometry/operator.py @@ -1456,6 +1456,9 @@ class OverrideJoin(bpy.types.Operator, tool.Ifc.Operator): bl_label = "IFC Join" bl_options = {"REGISTER", "UNDO"} + target: bpy.types.Object + target_element: ifcopenshell.entity_instance + def invoke(self, context, event): if not tool.Ifc.get(): return bpy.ops.object.join() @@ -1469,12 +1472,12 @@ class OverrideJoin(bpy.types.Operator, tool.Ifc.Operator): return self.target = context.active_object - self.target_element = tool.Ifc.get_entity(self.target) - if self.target_element: + if target_element := tool.Ifc.get_entity(self.target): + self.target_element = target_element return self.join_ifc_obj() return self.join_blender_obj() - def join_ifc_obj(self): + def join_ifc_obj(self) -> None: ifc_file = tool.Ifc.get() builder = ShapeBuilder(ifc_file) si_conversion = ifcopenshell.util.unit.calculate_unit_scale(ifc_file) @@ -1539,7 +1542,7 @@ class OverrideJoin(bpy.types.Operator, tool.Ifc.Operator): apply_openings=True, ) - def join_blender_obj(self): + def join_blender_obj(self) -> None: for obj in bpy.context.selected_objects: if obj == self.target: continue @@ -2289,6 +2292,7 @@ class ImportRepresentationItems(bpy.types.Operator, tool.Ifc.Operator): def _execute(self, context): obj = context.active_object + assert obj props = context.scene.BIMGeometryProperties if previous_obj := props.representation_obj: previous_obj.hide_set(False) diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 731cc9929f..d319435335 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -29,9 +29,11 @@ import ifcopenshell.api.grid import ifcopenshell.geom import ifcopenshell.guid import ifcopenshell.util.element -import ifcopenshell.util.representation -import ifcopenshell.util.system import ifcopenshell.util.placement +import ifcopenshell.util.representation +import ifcopenshell.util.shape_builder +import ifcopenshell.util.system +import ifcopenshell.util.unit import bonsai.core.tool import bonsai.core.drawing import bonsai.core.geometry @@ -1409,11 +1411,13 @@ class Geometry(bonsai.core.tool.Geometry): return use_immediate_repr @classmethod - def get_elements_by_representation(cls, representation): + def get_elements_by_representation( + cls, representation: ifcopenshell.entity_instance + ) -> set[ifcopenshell.entity_instance]: return ifcopenshell.util.element.get_elements_by_representation(tool.Ifc.get(), representation) @classmethod - def sync_item_positions(cls): + def sync_item_positions(cls) -> None: props = bpy.context.scene.BIMGeometryProperties if not props.representation_obj: return @@ -1499,7 +1503,7 @@ class Geometry(bonsai.core.tool.Geometry): cls.record_object_position(obj) @classmethod - def disable_item_mode(cls): + def disable_item_mode(cls) -> None: props = bpy.context.scene.BIMGeometryProperties if props.representation_obj: props.representation_obj.hide_set(False) diff --git a/src/ifcopenshell-python/ifcopenshell/sql.py b/src/ifcopenshell-python/ifcopenshell/sql.py index d40a1c78b4..a77b5a85af 100644 --- a/src/ifcopenshell-python/ifcopenshell/sql.py +++ b/src/ifcopenshell-python/ifcopenshell/sql.py @@ -19,6 +19,7 @@ from __future__ import annotations import re import json import ifcopenshell +import ifcopenshell.util.attribute import ifcopenshell.util.schema from pathlib import Path from typing import Any, NoReturn, Union, Optional, TYPE_CHECKING