diff --git a/src/blenderbim/blenderbim/bim/import_ifc.py b/src/blenderbim/blenderbim/bim/import_ifc.py index 5e427aae3e..cbbb8e7731 100644 --- a/src/blenderbim/blenderbim/bim/import_ifc.py +++ b/src/blenderbim/blenderbim/bim/import_ifc.py @@ -1703,18 +1703,18 @@ class IfcImporter: self.type_collection.children.link(aggregate["collection"]) continue - def create_materials(self): + def create_materials(self) -> None: for material in self.file.by_type("IfcMaterial"): self.create_material(material) - def create_material(self, material): + def create_material(self, material: ifcopenshell.entity_instance) -> bpy.types.Material: blender_material = bpy.data.materials.new(material.Name) self.link_element(material, blender_material) self.material_creator.materials[material.id()] = blender_material blender_material.use_fake_user = True return blender_material - def create_styles(self): + def create_styles(self) -> None: parsed_styles = set() for material_definition_representation in self.file.by_type("IfcMaterialDefinitionRepresentation"): diff --git a/src/blenderbim/blenderbim/bim/module/geometry/operator.py b/src/blenderbim/blenderbim/bim/module/geometry/operator.py index 2fecf1b793..7537a04067 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/operator.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/operator.py @@ -40,6 +40,7 @@ from mathutils import Vector, Matrix from time import time from blenderbim.bim.ifc import IfcStore from ifcopenshell.util.shape_builder import ShapeBuilder +from typing import Any class Operator: @@ -729,7 +730,7 @@ class OverrideOutlinerDelete(bpy.types.Operator): IfcStore.add_transaction_operation(self) return {"FINISHED"} - def get_collection_objects_and_children(self, collection): + def get_collection_objects_and_children(self, collection: bpy.types.Collection) -> dict[str, Any]: objects = set() children = set() queue = [collection] diff --git a/src/blenderbim/blenderbim/tool/blender.py b/src/blenderbim/blenderbim/tool/blender.py index a58392b16c..46a435eccb 100644 --- a/src/blenderbim/blenderbim/tool/blender.py +++ b/src/blenderbim/blenderbim/tool/blender.py @@ -21,6 +21,7 @@ import bmesh import json import ifcopenshell.api import ifcopenshell.util.element +import blenderbim.core.tool import blenderbim.tool as tool import blenderbim.bim import addon_utils diff --git a/src/ifcopenshell-python/ifcopenshell/file.py b/src/ifcopenshell-python/ifcopenshell/file.py index cf8e5491a2..000b249c5d 100644 --- a/src/ifcopenshell-python/ifcopenshell/file.py +++ b/src/ifcopenshell-python/ifcopenshell/file.py @@ -24,7 +24,7 @@ import zipfile import functools import ifcopenshell from pathlib import Path -from typing import Optional, Any, Union, Callable +from typing import Optional, Any, Union, Callable, Generator from . import ifcopenshell_wrapper from .entity_instance import entity_instance @@ -59,13 +59,13 @@ class Transaction: value, ) - def batch(self): + def batch(self) -> None: self.is_batched = True self.batch_delete_index = len(self.operations) self.batch_delete_ids = set() self.batch_inverses = [] - def unbatch(self): + def unbatch(self) -> None: for inverses in self.batch_inverses: if inverses: self.operations.insert(self.batch_delete_index, {"action": "batch_delete", "inverses": inverses}) @@ -74,11 +74,11 @@ class Transaction: self.batch_delete_ids = set() self.batch_inverses = [] - def store_create(self, element): + def store_create(self, element: ifcopenshell.entity_instance) -> None: if element.id(): self.operations.append({"action": "create", "value": self.serialise_entity_instance(element)}) - def store_edit(self, element, index, value): + def store_edit(self, element: ifcopenshell.entity_instance, index: int, value: Any) -> None: if element.id(): self.operations.append( { @@ -120,7 +120,7 @@ class Transaction: return False return value == element - def rollback(self): + def rollback(self) -> None: for operation in self.operations[::-1]: if operation["action"] == "create": element = self.file.by_id(operation["value"]["id"]) @@ -153,7 +153,7 @@ class Transaction: for index, value in data: inverse[index] = self.unserialise_value(inverse, value) - def commit(self): + def commit(self) -> None: for operation in self.operations: if operation["action"] == "create": e = self.file.create_entity(operation["value"]["type"], id=operation["value"]["id"]) @@ -260,19 +260,19 @@ class file: file_dict[self.file_pointer()] = weakref.ref(self) - def __del__(self): + def __del__(self) -> None: del file_dict[self.file_pointer()] - def set_history_size(self, size): + def set_history_size(self, size: int) -> None: self.history_size = size while len(self.history) > self.history_size: self.history.pop(0) - def begin_transaction(self): + def begin_transaction(self) -> None: if self.history_size: self.transaction = Transaction(self) - def end_transaction(self): + def end_transaction(self) -> None: if self.transaction: self.history.append(self.transaction) if len(self.history) > self.history_size: @@ -280,19 +280,19 @@ class file: self.future = [] self.transaction = None - def discard_transaction(self): + def discard_transaction(self) -> None: if self.transaction: self.transaction.rollback() self.transaction = None - def undo(self): + def undo(self) -> None: if not self.history: return transaction = self.history.pop() transaction.rollback() self.future.append(transaction) - def redo(self): + def redo(self) -> None: if not self.future: return transaction = self.future.pop() @@ -405,7 +405,7 @@ class file: else: return getattr(self.wrapped_data, attr) - def __getitem__(self, key): + def __getitem__(self, key: Union[numbers.Integral, str, bytes]) -> entity_instance: if isinstance(key, numbers.Integral): return entity_instance(self.wrapped_data.by_id(key), self) elif isinstance(key, (str, bytes)): @@ -501,7 +501,7 @@ class file: return [entity_instance(e, self) for e in fn(inst.wrapped_data, max_levels)] def get_inverse( - self, inst: ifcopenshell.entity_instance, allow_duplicate=False, with_attribute_indices=False + self, inst: ifcopenshell.entity_instance, allow_duplicate: bool = False, with_attribute_indices: bool = False ) -> list[ifcopenshell.entity_instance]: """Return a list of entities that reference this entity @@ -572,7 +572,7 @@ class file: self.transaction.unbatch() return self.wrapped_data.unbatch() - def __iter__(self): + def __iter__(self) -> Generator[ifcopenshell.entity_instance, None, None]: return iter(self[id] for id in self.wrapped_data.entity_names()) def write(self, path: "os.PathLike | str", format: Optional[str] = None, zipped: bool = False) -> None: diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index 6bba052bf2..77cbbb1ee1 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -22,9 +22,9 @@ import time import ifcopenshell import ifcopenshell.util.attribute import ifcopenshell.ifcopenshell_wrapper as ifcopenshell_wrapper +from typing import Union, Any # This is highly experimental and incomplete, however, it may work for simple datasets. -# In this simple implementation, we only support 2X3<->4 right now cwd = os.path.dirname(os.path.realpath(__file__)) @@ -223,7 +223,9 @@ class Migrator: "User": None, } - def migrate(self, element: ifcopenshell.entity_instance, new_file: ifcopenshell.file) -> ifcopenshell.entity_instance: + def migrate( + self, element: ifcopenshell.entity_instance, new_file: ifcopenshell.file + ) -> ifcopenshell.entity_instance: if element.id() == 0: return new_file.create_entity(element.is_a(), element.wrappedValue) try: @@ -241,7 +243,9 @@ class Migrator: self.migrated_ids[element.id()] = new_element.id() return new_element - def migrate_class(self, element, new_file): + def migrate_class( + self, element: ifcopenshell.entity_instance, new_file: ifcopenshell.file + ) -> ifcopenshell.entity_instance: try: new_element = new_file.create_entity(element.is_a()) except: @@ -260,7 +264,14 @@ class Migrator: self.migrate_attribute(attribute, element, new_file, new_element, new_element_schema) return new_element - def find_equivalent_attribute(self, new_element, attribute, element, attributes_mapping, reverse_mapping=False): + def find_equivalent_attribute( + self, + new_element: ifcopenshell.entity_instance, + attribute: ifcopenshell_wrapper.attribute, + element: ifcopenshell.entity_instance, + attributes_mapping: dict[str, dict[str, str]], + reverse_mapping: bool = False, + ) -> Union[Any, None]: # print("Searching for an equivalent", element, new_element, attribute.name()) try: if reverse_mapping: @@ -281,7 +292,14 @@ class Migrator: ) raise e - def migrate_attribute(self, attribute, element, new_file: ifcopenshell.file, new_element, new_element_schema): + def migrate_attribute( + self, + attribute: ifcopenshell_wrapper.attribute, + element: ifcopenshell.entity_instance, + new_file: ifcopenshell.file, + new_element: ifcopenshell.entity_instance, + new_element_schema: ifcopenshell_wrapper.declaration, + ) -> None: # NOTE: `attribute` is an attribute in new file schema # print("Migrating attribute", element, new_element, attribute.name()) old_file = element.wrapped_data.file @@ -349,7 +367,7 @@ class Migrator: if value is not None: setattr(new_element, attribute.name(), value) - def generate_default_value(self, attribute, new_file): + def generate_default_value(self, attribute: ifcopenshell_wrapper.attribute, new_file: ifcopenshell.file) -> Any: if attribute.name() in self.default_values: return self.default_values[attribute.name()] elif attribute.name() == "OwnerHistory":