From 4afed8f2f338771f862f453cc285558b06ee69d6 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 28 Mar 2025 12:00:33 +0500 Subject: [PATCH] typing --- src/bonsai/bonsai/tool/geometry.py | 2 +- src/bonsai/bonsai/tool/project.py | 34 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index a386132cbb..d959504065 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -1952,7 +1952,7 @@ class Geometry(bonsai.core.tool.Geometry): if not material: continue if not (style := tool.Ifc.get_entity(material)): - style = ifcopenshell.api.run("style.add_style", tool.Ifc.get(), name=material.name) + style = ifcopenshell.api.style.add_style(ifc_file, name=material.name) if material.use_nodes: ifc_class = "IfcSurfaceStyleRendering" attributes = tool.Style.get_surface_rendering_attributes(material) diff --git a/src/bonsai/bonsai/tool/project.py b/src/bonsai/bonsai/tool/project.py index 9e5e646da7..ed24d2fd7c 100644 --- a/src/bonsai/bonsai/tool/project.py +++ b/src/bonsai/bonsai/tool/project.py @@ -59,16 +59,16 @@ class Project(bonsai.core.tool.Project): bpy.ops.bim.append_library_element(definition=element.id()) @classmethod - def create_empty(cls, name): + def create_empty(cls, name: str) -> bpy.types.Object: return bpy.data.objects.new(name, None) @classmethod - def load_default_thumbnails(cls): + def load_default_thumbnails(cls) -> None: if tool.Ifc.get().by_type("IfcElementType"): bpy.ops.bim.load_type_thumbnails() @classmethod - def load_pset_templates(cls): + def load_pset_templates(cls) -> None: props = tool.Blender.get_bim_props() pset_dir = tool.Ifc.resolve_uri(props.pset_dir) if os.path.isdir(pset_dir): @@ -76,13 +76,21 @@ class Project(bonsai.core.tool.Project): bonsai.bim.schema.ifc.psetqto.templates.append(ifcopenshell.open(path)) @classmethod - def run_aggregate_assign_object(cls, relating_obj=None, related_obj=None): + def run_aggregate_assign_object( + cls, relating_obj: Optional[bpy.types.Object] = None, related_obj: Optional[bpy.types.Object] = None + ): return bonsai.core.aggregate.assign_object( tool.Ifc, tool.Aggregate, tool.Collector, relating_obj=relating_obj, related_obj=related_obj ) @classmethod - def run_context_add_context(cls, context_type=None, context_identifier=None, target_view=None, parent=None): + def run_context_add_context( + cls, + context_type: Optional[str] = None, + context_identifier: Optional[str] = None, + target_view: Optional[str] = None, + parent: Optional[str] = None, + ): return bonsai.core.context.add_context( tool.Ifc, context_type=context_type, @@ -100,11 +108,13 @@ class Project(bonsai.core.tool.Project): return bonsai.core.owner.add_person(tool.Ifc) @classmethod - def run_owner_add_person_and_organisation(cls, person=None, organisation=None): + def run_owner_add_person_and_organisation( + cls, person: ifcopenshell.entity_instance, organisation: ifcopenshell.entity_instance + ): return bonsai.core.owner.add_person_and_organisation(tool.Ifc, person=person, organisation=organisation) @classmethod - def run_owner_set_user(cls, user=None): + def run_owner_set_user(cls, user: ifcopenshell.entity_instance): return bonsai.core.owner.set_user(tool.Owner, user=user) @classmethod @@ -116,7 +126,7 @@ class Project(bonsai.core.tool.Project): should_add_representation: bool = True, context: Optional[ifcopenshell.entity_instance] = None, ifc_representation_class: Optional[str] = None, - ) -> ifcopenshell.entity_instance: + ): return bonsai.core.root.assign_class( tool.Ifc, tool.Collector, @@ -134,20 +144,20 @@ class Project(bonsai.core.tool.Project): return bonsai.core.unit.assign_scene_units(tool.Ifc, tool.Unit) @classmethod - def set_context(cls, context): + def set_context(cls, context: ifcopenshell.entity_instance) -> None: bonsai.bim.handler.refresh_ui_data() rprops = tool.Root.get_root_props() rprops.contexts = str(context.id()) @classmethod - def set_default_context(cls): + def set_default_context(cls) -> None: context = ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW") if context: rprops = tool.Root.get_root_props() rprops.contexts = str(context.id()) @classmethod - def set_default_modeling_dimensions(cls): + def set_default_modeling_dimensions(cls) -> None: props = tool.Model.get_model_props() unit_scale = ifcopenshell.util.unit.calculate_unit_scale(tool.Ifc.get()) props.extrusion_depth = 3 @@ -323,7 +333,7 @@ class Project(bonsai.core.tool.Project): return any(rel in project_library_rels for rel in has_context) @classmethod - def update_current_library_page(cls): + def update_current_library_page(cls) -> None: props = cls.get_project_props() active_library_breadcrumb = props.get_active_library_breadcrumb() change_back = False