diff --git a/src/blenderbim/blenderbim/bim/export_ifc.py b/src/blenderbim/blenderbim/bim/export_ifc.py index 111da2be9c..8997d7f81e 100644 --- a/src/blenderbim/blenderbim/bim/export_ifc.py +++ b/src/blenderbim/blenderbim/bim/export_ifc.py @@ -35,6 +35,7 @@ import blenderbim.core.spatial import blenderbim.core.style from blenderbim.bim.ifc import IfcStore from mathutils import Vector +from typing import Union class IfcExporter: @@ -86,8 +87,8 @@ class IfcExporter: self.get_application_name(), tool.Blender.get_blenderbim_version() ) - def sync_all_objects(self): - results = [] + def sync_all_objects(self) -> list[ifcopenshell.entity_instance]: + results: list[ifcopenshell.entity_instance] = [] self.unit_scale = ifcopenshell.util.unit.calculate_unit_scale(self.file) for ifc_definition_id in list(IfcStore.id_map.keys()): obj = IfcStore.id_map[ifc_definition_id] @@ -107,8 +108,8 @@ class IfcExporter: pass # The object is likely deleted return results - def sync_edited_objects(self): - results = [] + def sync_edited_objects(self) -> list[ifcopenshell.entity_instance]: + results: list[ifcopenshell.entity_instance] = [] for obj in IfcStore.edited_objs.copy(): if not obj: continue @@ -126,7 +127,7 @@ class IfcExporter: IfcStore.edited_objs.clear() return results - def sync_object_material(self, obj): + def sync_object_material(self, obj: bpy.types.Object) -> None: if not obj.data or not isinstance(obj.data, bpy.types.Mesh): return if not self.has_changed_materials(obj): @@ -137,7 +138,7 @@ class IfcExporter: checksum = obj.data.BIMMeshProperties.material_checksum return checksum != str([s.id() for s in tool.Geometry.get_styles(obj) if s]) - def sync_object_placement(self, obj): + def sync_object_placement(self, obj: bpy.types.Object) -> Union[ifcopenshell.entity_instance, None]: element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) if not tool.Ifc.is_moved(obj): return @@ -152,7 +153,7 @@ class IfcExporter: blenderbim.core.geometry.edit_object_placement(tool.Ifc, tool.Geometry, tool.Surveyor, obj=obj) return element - def sync_grid_axis_object_placement(self, obj, element): + def sync_grid_axis_object_placement(self, obj: bpy.types.Object, element: ifcopenshell.entity_instance) -> None: grid = (element.PartOfU or element.PartOfV or element.PartOfW)[0] grid_obj = tool.Ifc.get_object(grid) if grid_obj: diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index 2849becbd4..ee3d3eeddb 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -44,7 +44,7 @@ import blenderbim.bim.module.drawing.helper as helper import blenderbim.bim.export_ifc from blenderbim.bim.module.drawing.decoration import CutDecorator from blenderbim.bim.module.drawing.data import DecoratorData, DrawingsData -from typing import NamedTuple, List, Union +from typing import NamedTuple, List, Union, Optional from lxml import etree from mathutils import Vector, Color, Matrix from timeit import default_timer as timer @@ -445,8 +445,14 @@ class CreateDrawing(bpy.types.Operator): return LineworkContexts(body_contexts, annotation_contexts) def serialize_contexts_elements( - self, ifc, tree: ifcopenshell.geom.tree, contexts: LineworkContexts, context_type, drawing_elements, target_view - ): + self, + ifc: ifcopenshell.file, + tree: ifcopenshell.geom.tree, + contexts: LineworkContexts, + context_type: str, + drawing_elements: set[ifcopenshell.entity_instance], + target_view: str, + ) -> None: drawing_elements = drawing_elements.copy() contexts = getattr(contexts, context_type) for context in contexts: @@ -472,7 +478,7 @@ class CreateDrawing(bpy.types.Operator): tree.add_element(elem) drawing_elements -= processed - def generate_linework(self, context): + def generate_linework(self, context: bpy.types.Context) -> Union[str, None]: if not ifcopenshell.util.element.get_pset(self.drawing, "EPset_Drawing", "HasLinework"): return svg_path = self.get_svg_path(cache_type="linework") @@ -1115,14 +1121,14 @@ class CreateDrawing(bpy.types.Operator): continue return space - def get_material_name(self, element): + def get_material_name(self, element: ifcopenshell.entity_instance) -> str: if hasattr(element, "Name") and element.Name: return element.Name elif hasattr(element, "LayerSetName") and element.LayerSetName: return element.LayerSetName return "mat-" + str(element.id()) - def get_svg_path(self, cache_type=None): + def get_svg_path(self, cache_type: Optional[str] = None) -> str: drawing_path = tool.Drawing.get_document_uri(self.camera_document) drawings_dir = os.path.dirname(drawing_path) diff --git a/src/blenderbim/blenderbim/core/geometry.py b/src/blenderbim/blenderbim/core/geometry.py index 8677152284..88a97eff6e 100644 --- a/src/blenderbim/blenderbim/core/geometry.py +++ b/src/blenderbim/blenderbim/core/geometry.py @@ -16,10 +16,18 @@ # You should have received a copy of the GNU General Public License # along with BlenderBIM Add-on. If not, see . +from __future__ import annotations import blenderbim.core.style +from typing import TYPE_CHECKING, Optional +import blenderbim.core.tool as tool + +if TYPE_CHECKING: + import bpy -def edit_object_placement(ifc, geometry, surveyor, obj=None): +def edit_object_placement( + ifc: tool.Ifc, geometry: tool.Geometry, surveyor: tool.Surveyor, obj: Optional[bpy.types.Object] = None +) -> None: element = ifc.get_entity(obj) if not element: return diff --git a/src/blenderbim/blenderbim/core/spatial.py b/src/blenderbim/blenderbim/core/spatial.py index 8121674193..8e37c5650d 100644 --- a/src/blenderbim/blenderbim/core/spatial.py +++ b/src/blenderbim/blenderbim/core/spatial.py @@ -16,18 +16,42 @@ # 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, Union +import blenderbim.core.tool as tool -def reference_structure(ifc, spatial, structure=None, element=None): +if TYPE_CHECKING: + import bpy + import ifcopenshell + + +def reference_structure( + ifc: tool.Ifc, + spatial: tool.Spatial, + structure: Optional[ifcopenshell.entity_instance] = None, + element: Optional[ifcopenshell.entity_instance] = None, +) -> Union[ifcopenshell.entity_instance, None]: if spatial.can_reference(structure, element): return ifc.run("spatial.reference_structure", product=element, relating_structure=structure) -def dereference_structure(ifc, spatial, structure=None, element=None): +def dereference_structure( + ifc: tool.Ifc, + spatial: tool.Spatial, + structure: Optional[ifcopenshell.entity_instance] = None, + element: Optional[ifcopenshell.entity_instance] = None, +) -> None: if spatial.can_reference(structure, element): return ifc.run("spatial.dereference_structure", product=element, relating_structure=structure) -def assign_container(ifc, collector, spatial, structure_obj=None, element_obj=None): +def assign_container( + ifc: tool.Ifc, + collector: tool.Collector, + spatial: tool.Spatial, + structure_obj: Optional[bpy.types.Object] = None, + element_obj: Optional[bpy.types.Object] = None, +) -> Union[ifcopenshell.entity_instance, None]: if not spatial.can_contain(structure_obj, element_obj): return rel = ifc.run( diff --git a/src/blenderbim/blenderbim/tool/collector.py b/src/blenderbim/blenderbim/tool/collector.py index ed4e9377f5..e834cbc492 100644 --- a/src/blenderbim/blenderbim/tool/collector.py +++ b/src/blenderbim/blenderbim/tool/collector.py @@ -20,6 +20,8 @@ import bpy import ifcopenshell.util.element import blenderbim.core.tool +import blenderbim.core.spatial +import blenderbim.core.aggregate import blenderbim.tool as tool from typing import Union diff --git a/src/blenderbim/blenderbim/tool/spatial.py b/src/blenderbim/blenderbim/tool/spatial.py index 2a9c3d1fd1..1f72007547 100644 --- a/src/blenderbim/blenderbim/tool/spatial.py +++ b/src/blenderbim/blenderbim/tool/spatial.py @@ -34,7 +34,7 @@ from shapely import Polygon, MultiPolygon class Spatial(blenderbim.core.tool.Spatial): @classmethod - def can_contain(cls, structure_obj, element_obj): + def can_contain(cls, structure_obj: bpy.types.Object, element_obj: bpy.types.Object) -> bool: structure = tool.Ifc.get_entity(structure_obj) element = tool.Ifc.get_entity(element_obj) if not structure or not element: @@ -52,7 +52,7 @@ class Spatial(blenderbim.core.tool.Spatial): return True @classmethod - def can_reference(cls, structure, element): + def can_reference(cls, structure: ifcopenshell.entity_instance, element: ifcopenshell.entity_instance) -> bool: if not structure or not element: return False if tool.Ifc.get_schema() == "IFC2X3":