diff --git a/src/bonsai/bonsai/bim/module/model/product.py b/src/bonsai/bonsai/bim/module/model/product.py index 49f0bde998..5bfa2e66f6 100644 --- a/src/bonsai/bonsai/bim/module/model/product.py +++ b/src/bonsai/bonsai/bim/module/model/product.py @@ -19,7 +19,6 @@ import bpy import mathutils import numpy as np -from functools import reduce import ifcopenshell import ifcopenshell.api import ifcopenshell.util.system diff --git a/src/bonsai/bonsai/core/drawing.py b/src/bonsai/bonsai/core/drawing.py index 4afb45c4e9..57ab21dbe7 100644 --- a/src/bonsai/bonsai/core/drawing.py +++ b/src/bonsai/bonsai/core/drawing.py @@ -76,7 +76,7 @@ def disable_editing_sheets(drawing: tool.Drawing) -> None: drawing.disable_editing_sheets() -def add_sheet(ifc: tool.Ifc, drawing, titleblock: ifcopenshell.entity_instance) -> None: +def add_sheet(ifc: tool.Ifc, drawing: tool.Drawing, titleblock: ifcopenshell.entity_instance) -> None: sheet = ifc.run("document.add_information") layout = ifc.run("document.add_reference", information=sheet) titleblock_reference = ifc.run("document.add_reference", information=sheet) @@ -127,7 +127,9 @@ def remove_sheet(ifc: tool.Ifc, drawing: tool.Drawing, sheet: ifcopenshell.entit drawing.import_sheets() -def rename_sheet(ifc: tool.Ifc, drawing, sheet: ifcopenshell.entity_instance, identification: str, name: str) -> None: +def rename_sheet( + ifc: tool.Ifc, drawing: tool.Drawing, sheet: ifcopenshell.entity_instance, identification: str, name: str +) -> None: if ifc.get_schema() == "IFC2X3": attributes = {"DocumentId": identification, "Name": name} else: diff --git a/src/bonsai/bonsai/tool/ifc.py b/src/bonsai/bonsai/tool/ifc.py index 3efad2bfa6..57c81b84cf 100644 --- a/src/bonsai/bonsai/tool/ifc.py +++ b/src/bonsai/bonsai/tool/ifc.py @@ -22,6 +22,7 @@ import numpy as np import ifcopenshell.api import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper import ifcopenshell.util.element +import ifcopenshell.util.schema import bonsai.core.tool import bonsai.bim.handler import bonsai.tool as tool @@ -60,7 +61,7 @@ class Ifc(bonsai.core.tool.Ifc): return IfcStore.path @classmethod - def get_schema(cls) -> str: + def get_schema(cls) -> ifcopenshell.util.schema.IFC_SCHEMA: if IfcStore.get_file(): return IfcStore.get_file().schema diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index addca6a3be..0a6bbc8594 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -24,11 +24,14 @@ import zipfile import functools import ifcopenshell from pathlib import Path -from typing import Optional, Any, Union, Callable, Generator, Literal +from typing import Optional, Any, Union, Callable, Generator, Literal, TYPE_CHECKING from . import ifcopenshell_wrapper from .entity_instance import entity_instance +if TYPE_CHECKING: + import ifcopenshell.util.schema + class Transaction: def __init__(self, ifc_file): @@ -406,7 +409,7 @@ class file: return e @property - def schema(self) -> Literal["IFC2X3", "IFC4", "IFC4X3"]: + def schema(self) -> ifcopenshell.util.schema.IFC_SCHEMA: """General IFC schema version: IFC2X3, IFC4, IFC4X3.""" prefixes = ("IFC", "X", "_ADD", "_TC") reg = "".join(f"(?P<{s}>{s}\\d+)?" for s in prefixes) diff --git a/src/ifcopenshell-python/ifcopenshell/util/doc.py b/src/ifcopenshell-python/ifcopenshell/util/doc.py index 2753d7d63b..b444966068 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/doc.py +++ b/src/ifcopenshell-python/ifcopenshell/util/doc.py @@ -60,7 +60,7 @@ IFC4x3_SPEC_URL_TEMPLATE = "https://ifc43-docs.standards.buildingsmart.org/IFC/R # child -> description # note: in IFC4x3 there is no children[] for properties -SUPPORTED_SCHEMA = Literal["IFC2X3", "IFC4", "IFC4X3"] +SUPPORTED_SCHEMA = ifcopenshell.util.schema.IFC_SCHEMA SCHEMA_FILES: dict[SUPPORTED_SCHEMA, dict] = { "IFC2X3": { "entities": BASE_MODULE_PATH / "schema/ifc2x3_entities.json", diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index fe08240d07..3a2021b8ef 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -22,11 +22,12 @@ import time import ifcopenshell import ifcopenshell.util.attribute import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper -from typing import Union, Any +from typing import Union, Any, Literal # This is highly experimental and incomplete, however, it may work for simple datasets. cwd = os.path.dirname(os.path.realpath(__file__)) +IFC_SCHEMA = Literal["IFC2X3", "IFC4", "IFC4X3"] def get_fallback_schema(version: str) -> str: diff --git a/src/ifcopenshell-python/ifcopenshell/util/type.py b/src/ifcopenshell-python/ifcopenshell/util/type.py index 3cd2750d2b..bfb0f40bc0 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/type.py +++ b/src/ifcopenshell-python/ifcopenshell/util/type.py @@ -23,8 +23,8 @@ from typing import List cwd = os.path.dirname(os.path.realpath(__file__)) -entity_to_type_map = {} -type_to_entity_map = {} +entity_to_type_map: dict[ifcopenshell.util.schema.IFC_SCHEMA, dict[str, list[str]]] = {} +type_to_entity_map: dict[ifcopenshell.util.schema.IFC_SCHEMA, dict[str, list[str]]] = {} mapped_schemas = { "IFC2X3": "entity_to_type_map_2x3.json", diff --git a/src/ifcpatch/ifcpatch/recipes/Migrate.py b/src/ifcpatch/ifcpatch/recipes/Migrate.py index 4b3a1cf8c9..9938ddd754 100644 --- a/src/ifcpatch/ifcpatch/recipes/Migrate.py +++ b/src/ifcpatch/ifcpatch/recipes/Migrate.py @@ -28,7 +28,7 @@ class Patcher: src: str, file: ifcopenshell.file, logger: Logger, - schema: typing.Literal["IFC2X3", "IFC4", "IFC4X3"] = "IFC4", + schema: ifcopenshell.util.schema.IFC_SCHEMA = "IFC4", ): """Migrate from one IFC version to another