From b45a995bb3aab1b69069ab1cd8b5f6498be63af6 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 8 Jul 2024 11:39:19 +0500 Subject: [PATCH] typing --- src/blenderbim/blenderbim/core/profile.py | 14 +++++++++++++- src/blenderbim/blenderbim/tool/blender.py | 11 +++++++++++ .../ifcopenshell/api/material/add_material_set.py | 13 +++++++++++-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/core/profile.py b/src/blenderbim/blenderbim/core/profile.py index 58029f1dc4..549120631f 100644 --- a/src/blenderbim/blenderbim/core/profile.py +++ b/src/blenderbim/blenderbim/core/profile.py @@ -16,8 +16,20 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . +from __future__ import annotations +from typing import TYPE_CHECKING, Optional -def purge_unused_profiles(ifc, profile): +if TYPE_CHECKING: + import bpy + import ifcopenshell + import blenderbim.tool as tool + + +def purge_unused_profiles(ifc: tool.Ifc, profile: tool.Profile) -> int: + """Purge profiles that have no invserses. + + :return: Number of removed profiles. + """ purged_profiles = 0 for element_profile in profile.get_model_profiles(): if ifc.get().get_total_inverses(element_profile) > 0: diff --git a/src/blenderbim/blenderbim/tool/blender.py b/src/blenderbim/blenderbim/tool/blender.py index 5641f6cf67..6f199abaf4 100644 --- a/src/blenderbim/blenderbim/tool/blender.py +++ b/src/blenderbim/blenderbim/tool/blender.py @@ -52,6 +52,17 @@ class Blender(blenderbim.core.tool.Blender): OBJECT_TYPES_THAT_SUPPORT_EDIT_GPENCIL_MODE = ("GPENCIL",) TYPE_MANAGER_ICON = "LIGHTPROBE_VOLUME" if bpy.app.version >= (4, 1, 0) else "LIGHTPROBE_GRID" + BLENDER_ENUM_ITEM = Union[tuple[str, str, str], tuple[str, str, str, str], tuple[str, str, str, str, str]] + """ + Options: + + - (identifier, name, description) + + - (identifier, name, description, number) + + - (identifier, name, description, icon, number) + """ + @classmethod def activate_camera(cls, obj: bpy.types.Object) -> None: diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/add_material_set.py b/src/ifcopenshell-python/ifcopenshell/api/material/add_material_set.py index 7795c73de2..72c090b1ae 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/add_material_set.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/add_material_set.py @@ -16,10 +16,19 @@ # You should have received a copy of the GNU Lesser General Public License # along with IfcOpenShell. If not, see . import ifcopenshell +from typing import Literal + + +MATERIAL_SET_TYPE = Literal[ + "IfcMaterialLayerSet", + "IfcMaterialProfileSet", + "IfcMaterialConstituentSet", + "IfcMaterialList", +] def add_material_set( - file: ifcopenshell.file, name: str = "Unnamed", set_type: str = "IfcMaterialConstituentSet" + file: ifcopenshell.file, name: str = "Unnamed", set_type: MATERIAL_SET_TYPE = "IfcMaterialConstituentSet" ) -> ifcopenshell.entity_instance: """Adds a new material set @@ -104,7 +113,7 @@ def add_material_set( # Great! Let's assign our material set to our wall type. ifcopenshell.api.material.assign_material(model, products=[wall_type], material=material_set) """ - settings = {"name": name or "Unnamed", "set_type": set_type or "IfcMaterialConstituentSet"} + settings = {"name": name or "Unnamed", "set_type": set_type} if settings["set_type"] == "IfcMaterialLayerSet": return file.create_entity("IfcMaterialLayerSet", LayerSetName=settings["name"] or "Unnamed")