From 07f42b91268df5be79475be0fa594cc036960a3e Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 30 Apr 2025 18:14:28 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/tool/drawing.py | 18 +++++++++++++----- src/bonsai/bonsai/tool/geometry.py | 11 +++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/bonsai/bonsai/tool/drawing.py b/src/bonsai/bonsai/tool/drawing.py index a1a70ae7d8..096ec7b275 100644 --- a/src/bonsai/bonsai/tool/drawing.py +++ b/src/bonsai/bonsai/tool/drawing.py @@ -1531,20 +1531,23 @@ class Drawing(bonsai.core.tool.Drawing): drawing: ifcopenshell.entity_instance, reference_element: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance, - ) -> ifcopenshell.entity_instance: + ) -> Union[ifcopenshell.entity_instance, None]: import bonsai.bim.module.drawing.helper as helper target_view = tool.Drawing.get_drawing_target_view(drawing) camera = tool.Ifc.get_object(drawing) + assert isinstance(camera, bpy.types.Object) + assert isinstance(camera_data := camera.data, bpy.types.Camera) - is_ortho = camera.data.type == "ORTHO" - bounds = helper.ortho_view_frame(camera.data) if is_ortho else None + is_ortho = camera_data.type == "ORTHO" + bounds = helper.ortho_view_frame(camera_data) if is_ortho else None clipping = is_ortho and target_view in ("PLAN_VIEW", "REFLECTED_PLAN_VIEW") elevating = is_ortho and target_view in ("ELEVATION_VIEW", "SECTION_VIEW") def clone(src: bpy.types.Object) -> bpy.types.Object: dst = src.copy() + assert isinstance(dst.data, bpy.types.Mesh) dst.data = dst.data.copy() dst.name = dst.name.replace("IfcGridAxis/", "") tool.Blender.get_object_bim_props(dst).ifc_definition_id = 0 @@ -1552,19 +1555,23 @@ class Drawing(bonsai.core.tool.Drawing): return dst def disassemble(obj: bpy.types.Object) -> tuple[bpy.types.Object, bmesh.types.BMesh]: + assert isinstance(obj.data, bpy.types.Mesh) mesh = bmesh.new() mesh.verts.ensure_lookup_table() mesh.from_mesh(obj.data) return obj, mesh def assemble(obj: bpy.types.Object, mesh: bmesh.types.BMesh) -> bpy.types.Object: + assert isinstance(obj.data, bpy.types.Mesh) mesh.to_mesh(obj.data) return obj - def to_camera_coords(obj: bpy.types.Object, mesh: bpy.types.Mesh) -> tuple[bpy.types.Object, bpy.types.Mesh]: + def to_camera_coords( + obj: bpy.types.Object, mesh: bmesh.types.BMesh + ) -> tuple[bpy.types.Object, bmesh.types.BMesh]: mesh.transform(camera.matrix_world.inverted() @ obj.matrix_world) obj.matrix_world = camera.matrix_world - annotation_offset = mathutils.Vector((0, 0, -camera.data.clip_start - 0.05)) + annotation_offset = mathutils.Vector((0, 0, -camera_data.clip_start - 0.05)) annotation_offset = camera.matrix_world.to_quaternion() @ annotation_offset obj.matrix_world.translation += annotation_offset return obj, mesh @@ -1595,6 +1602,7 @@ class Drawing(bonsai.core.tool.Drawing): obj = tool.Ifc.get_object(reference_element) if not obj: return + assert isinstance(obj, bpy.types.Object) obj, mesh = to_camera_coords(*disassemble(clone(obj))) if clipping: diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index d57d901927..af456c4170 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -27,9 +27,11 @@ import numpy.typing as npt import multiprocessing import ifcopenshell import ifcopenshell.api +import ifcopenshell.api.boundary import ifcopenshell.api.geometry import ifcopenshell.api.grid import ifcopenshell.api.profile +import ifcopenshell.api.root import ifcopenshell.api.style import ifcopenshell.geom import ifcopenshell.guid @@ -223,13 +225,14 @@ class Geometry(bonsai.core.tool.Geometry): @classmethod def delete_ifc_object(cls, obj: bpy.types.Object) -> None: + ifc_file = tool.Ifc.get() element = tool.Ifc.get_entity(obj) if not element: return elif element.is_a("IfcAnnotation") and element.ObjectType == "DRAWING": return bonsai.core.drawing.remove_drawing(tool.Ifc, tool.Drawing, drawing=element) elif element.is_a("IfcRelSpaceBoundary"): - ifcopenshell.api.run("boundary.remove_boundary", tool.Ifc.get(), boundary=element) + ifcopenshell.api.boundary.remove_boundary(ifc_file, boundary=element) tool.Boundary.undecorate_boundary(obj) return bpy.data.objects.remove(obj) elif element.is_a("IfcGridAxis"): @@ -241,14 +244,14 @@ class Geometry(bonsai.core.tool.Geometry): is_last_axis = True if is_last_axis: return - ifcopenshell.api.run("grid.remove_grid_axis", tool.Ifc.get(), axis=element) + ifcopenshell.api.grid.remove_grid_axis(ifc_file, axis=element) return bpy.data.objects.remove(obj) elif element.is_a("IfcGrid"): axes = list(element.UAxes or []) + list(element.VAxes or []) + list(element.WAxes or []) for axis in axes: if axis_obj := tool.Ifc.get_object(axis): bpy.data.objects.remove(axis_obj) - ifcopenshell.api.grid.remove_grid_axis(tool.Ifc.get(), axis=axis) + ifcopenshell.api.grid.remove_grid_axis(ifc_file, axis=axis) collection = tool.Blender.get_object_bim_props(obj).collection if collection: @@ -286,7 +289,7 @@ class Geometry(bonsai.core.tool.Geometry): bpy.ops.bim.remove_opening(opening_id=rel.RelatedOpeningElement.id()) for port in ifcopenshell.util.system.get_ports(element): bonsai.core.system.remove_port(tool.Ifc, tool.System, port=port) - ifcopenshell.api.run("root.remove_product", tool.Ifc.get(), product=element) + ifcopenshell.api.root.remove_product(ifc_file, product=element) data = obj.data if (