From 1c8ef176b1df1b197aaa06b4964fe7befd83d444 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 5 Mar 2025 14:56:29 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/bim/module/boundary/operator.py | 9 +++++---- src/bonsai/bonsai/bim/module/model/door.py | 1 + src/bonsai/bonsai/tool/model.py | 10 +++++++--- .../ifcopenshell/entity_instance.py | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/boundary/operator.py b/src/bonsai/bonsai/bim/module/boundary/operator.py index ac81aa2a65..ece7277275 100644 --- a/src/bonsai/bonsai/bim/module/boundary/operator.py +++ b/src/bonsai/bonsai/bim/module/boundary/operator.py @@ -41,6 +41,7 @@ from bonsai.bim.module.model.decorator import ProfileDecorator from bonsai.bim.module.boundary.decorator import BoundaryDecorator import bonsai.core import bonsai.core.geometry +from typing import Union, Optional def disable_editing_boundary_geometry(context): @@ -58,7 +59,7 @@ def disable_editing_boundary_geometry(context): class Loader: - def __init__(self, operator=None): + def __init__(self, operator: Optional[bpy.types.Operator] = None): self.operator = operator self.ifc_file = None self.logger = None @@ -67,7 +68,7 @@ class Loader: self.fallback_settings = self.load_fallback_settings() self.load_importer() - def create_mesh(self, boundary): + def create_mesh(self, boundary: ifcopenshell.entity_instance) -> Union[bpy.types.Mesh, None]: # ConnectionGeometry is optional in IFC schema for some reasons. if not boundary.ConnectionGeometry: return None @@ -131,7 +132,7 @@ class Loader: settings.set("dimensionality", ifcopenshell.ifcopenshell_wrapper.CURVES_SURFACES_AND_SOLIDS) return settings - def load_importer(self): + def load_importer(self) -> None: self.ifc_file = tool.Ifc.get() self.logger = logging.getLogger("ImportIFC") ifc_import_settings = import_ifc.IfcImportSettings.factory(bpy.context, IfcStore.path, self.logger) @@ -280,7 +281,7 @@ class SelectProjectBoundaries(bpy.types.Operator): return {"FINISHED"} -def get_colour(ifc_boundary): +def get_colour(ifc_boundary: ifcopenshell.entity_instance) -> tuple[float, float, float, float]: """Return a color depending on IfcClass given""" product_colors = { "IfcWall": (0.7, 0.3, 0, 1), diff --git a/src/bonsai/bonsai/bim/module/model/door.py b/src/bonsai/bonsai/bim/module/model/door.py index 1d53a2c279..3021d47f92 100644 --- a/src/bonsai/bonsai/bim/module/model/door.py +++ b/src/bonsai/bonsai/bim/module/model/door.py @@ -21,6 +21,7 @@ import bpy import bmesh import ifcopenshell import ifcopenshell.api +import ifcopenshell.api.material import ifcopenshell.util.element import ifcopenshell.util.representation import ifcopenshell.util.schema diff --git a/src/bonsai/bonsai/tool/model.py b/src/bonsai/bonsai/tool/model.py index 2a191bde76..31069b1d19 100644 --- a/src/bonsai/bonsai/tool/model.py +++ b/src/bonsai/bonsai/tool/model.py @@ -26,6 +26,7 @@ import collections.abc import numpy as np import ifcopenshell import ifcopenshell.api +import ifcopenshell.api.geometry import ifcopenshell.api.grid import ifcopenshell.api.pset import ifcopenshell.geom @@ -1555,12 +1556,14 @@ class Model(bonsai.core.tool.Model): def add_body_representation(cls, obj: bpy.types.Object) -> None: ifc_file = tool.Ifc.get() body = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW") - representation = ifcopenshell.api.run( - "geometry.add_representation", + assert body + mesh = obj.data + assert isinstance(mesh, bpy.types.Mesh) + representation = ifcopenshell.api.geometry.add_representation( ifc_file, context=body, blender_object=obj, - geometry=obj.data, + geometry=mesh, coordinate_offset=tool.Geometry.get_cartesian_point_offset(obj), total_items=tool.Geometry.get_total_representation_items(obj), should_force_faceted_brep=tool.Geometry.should_force_faceted_brep(), @@ -1569,6 +1572,7 @@ class Model(bonsai.core.tool.Model): ifc_representation_class=None, profile_set_usage=None, ) + assert representation tool.Model.replace_object_ifc_representation(body, obj, representation) @classmethod diff --git a/src/ifcopenshell-python/ifcopenshell/entity_instance.py b/src/ifcopenshell-python/ifcopenshell/entity_instance.py index 15e5980d41..d01c618d52 100644 --- a/src/ifcopenshell-python/ifcopenshell/entity_instance.py +++ b/src/ifcopenshell-python/ifcopenshell/entity_instance.py @@ -613,7 +613,7 @@ class entity_instance: include_identifier: bool = True, recursive: bool = False, return_type: type[dict] = dict, - ignore: Iterable[str] = (), + ignore: Sequence[str] = (), ) -> dict[str, Any]: """More perfomant version of `.get_info()` but with limited arguments values.\n Method has exactly the same signature as `.get_info()` but it doesn't support getting information non-recursively.