From 70091aa28b14620d72d6d122fa627f68c745edb4 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 3 Jun 2024 16:48:14 +0500 Subject: [PATCH] typing --- .../blenderbim/bim/module/drawing/operator.py | 1 + src/blenderbim/blenderbim/tool/geometry.py | 4 ++-- .../ifcopenshell/util/element.py | 16 ++++++++++++++-- .../ifcopenshell/util/representation.py | 5 +++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/drawing/operator.py b/src/blenderbim/blenderbim/bim/module/drawing/operator.py index bf5256185f..9f9341f76f 100644 --- a/src/blenderbim/blenderbim/bim/module/drawing/operator.py +++ b/src/blenderbim/blenderbim/bim/module/drawing/operator.py @@ -29,6 +29,7 @@ import subprocess import numpy as np import multiprocessing import ifcopenshell +import ifcopenshell.api import ifcopenshell.ifcopenshell_wrapper import ifcopenshell.geom import ifcopenshell.util.selector diff --git a/src/blenderbim/blenderbim/tool/geometry.py b/src/blenderbim/blenderbim/tool/geometry.py index 64c99d1c67..8120b69185 100644 --- a/src/blenderbim/blenderbim/tool/geometry.py +++ b/src/blenderbim/blenderbim/tool/geometry.py @@ -725,11 +725,11 @@ class Geometry(blenderbim.core.tool.Geometry): return False @classmethod - def should_use_presentation_style_assignment(cls): + def should_use_presentation_style_assignment(cls) -> bool: return bpy.context.scene.BIMGeometryProperties.should_use_presentation_style_assignment @classmethod - def get_model_representations(cls): + def get_model_representations(cls) -> list[ifcopenshell.entity_instance]: return tool.Ifc.get().by_type("IfcShapeRepresentation") @classmethod diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 5fe96a2ff0..33f5643efe 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -648,6 +648,8 @@ def get_styles(element: ifcopenshell.entity_instance) -> list[ifcopenshell.entit return styles +# TODO: ifc_file argument is unnecessary for some methods now +# since we have entity_instance.file, so we can deprecate it. def get_elements_by_material( ifc_file: ifcopenshell.file, material: ifcopenshell.entity_instance ) -> list[ifcopenshell.entity_instance]: @@ -1041,7 +1043,9 @@ def get_parent(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.enti - Voiding: the opening voids another physical element, such as a hole in a wall :param element: Any physical or spatial element in the tree + :type element: ifcopenshell.entity_instance :return: Its parent. This must exist for any valid file, or None if we've reached the IfcProject. + :rtype: Union[ifcopenshell.entity_instance, None] Example: @@ -1065,7 +1069,9 @@ def get_filled_void(element: ifcopenshell.entity_instance) -> Union[ifcopenshell Examples include windows and doors which fill a opening inside a wall. :param element: The building element, typically a window or door + :type element: ifcopenshell.entity_instance :return: The IfcOpeningElement that it is filling + :rtype: Union[ifcopenshell.entity_instance, None] Example: @@ -1084,7 +1090,9 @@ def get_voided_element(element: ifcopenshell.entity_instance) -> Union[ifcopensh For all valid models, this should never return None. :param element: The IfcOpeningElement + :type element: ifcopenshell.entity_instance :return: The building element, such as a wall or slab + :rtype: Union[ifcopenshell.entity_instance, None] Example: @@ -1102,7 +1110,9 @@ def get_aggregate(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.e Retrieves the aggregate parent of an element. :param element: The IFC element + :type element: ifcopenshell.entity_instance :return: The aggregate of the element + :rtype: Union[ifcopenshell.entity_instance, None] Example: @@ -1116,14 +1126,14 @@ def get_aggregate(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.e return decomposes[0].RelatingObject -def get_nest(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance]: +def get_nest(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance, None]: """ Retrieves the nest parent of an element. :param element: The IFC element :type element: ifcopenshell.entity_instance :return: The nested whole of the element - :rtype: ifcopenshell.entity_instance + :rtype: Union[ifcopenshell.entity_instance, None] Example: @@ -1159,6 +1169,7 @@ def get_parts(element: ifcopenshell.entity_instance) -> list[ifcopenshell.entity if (is_decomposed_by := getattr(element, "IsDecomposedBy", None)) is not None and is_decomposed_by: if is_decomposed_by[0].is_a("IfcRelAggregates"): return is_decomposed_by[0].RelatedObjects + return [] def get_components(element: ifcopenshell.entity_instance, include_ports=False) -> list[ifcopenshell.entity_instance]: @@ -1188,6 +1199,7 @@ def get_components(element: ifcopenshell.entity_instance, include_ports=False) - elif (is_decomposed_by := getattr(element, "IsDecomposedBy", None)) is not None and is_decomposed_by: if is_decomposed_by[0].is_a("IfcRelNests"): return is_decomposed_by[0].RelatedObjects + return [] ReferenceData = namedtuple("ReferenceData", "inverse_attribute, rel_class, relating_element_attribute") diff --git a/src/ifcopenshell-python/ifcopenshell/util/representation.py b/src/ifcopenshell-python/ifcopenshell/util/representation.py index 9bbfc783c4..fa79605ed0 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/representation.py +++ b/src/ifcopenshell-python/ifcopenshell/util/representation.py @@ -17,6 +17,7 @@ # along with IfcOpenShell. If not, see . import numpy as np +import numpy.typing as npt import ifcopenshell import ifcopenshell.util.placement from typing import Optional, Union, TypedDict @@ -98,12 +99,12 @@ def resolve_representation(representation: ifcopenshell.entity_instance) -> ifco class ResolvedItemDict(TypedDict): - matrix: np.array + matrix: npt.NDArray[np.float64] item: ifcopenshell.entity_instance def resolve_items( - representation: ifcopenshell.entity_instance, matrix: Optional[np.array] = None + representation: ifcopenshell.entity_instance, matrix: Optional[npt.NDArray[np.float64]] = None ) -> list[ResolvedItemDict]: if matrix is None: matrix = np.eye(4)