This commit is contained in:
Andrej730
2024-08-08 12:11:36 +05:00
parent 9671be1734
commit eca1d47d06
5 changed files with 73 additions and 54 deletions
@@ -259,7 +259,7 @@ class Usecase:
subelement_queue.extend(self.settings["library"].traverse(subelement, max_levels=1)[1:])
return new
def has_whitelisted_inverses(self, element):
def has_whitelisted_inverses(self, element: ifcopenshell.entity_instance) -> bool:
for source_class, attributes in self.whitelisted_inverse_attributes.items():
if not element.is_a(source_class):
continue
@@ -274,6 +274,7 @@ class Usecase:
return True
elif value:
return True
return False
def check_inverses(self, element: ifcopenshell.entity_instance) -> None:
for source_class, attributes in self.whitelisted_inverse_attributes.items():
@@ -318,7 +319,7 @@ class Usecase:
if new_attribute is not None:
new[i] = new_attribute
def is_another_asset(self, element):
def is_another_asset(self, element: ifcopenshell.entity_instance) -> bool:
if element == self.settings["element"]:
return False
elif element.is_a("IfcFeatureElement"):
@@ -332,7 +333,7 @@ class Usecase:
return True
return False
def reuse_existing_contexts(self):
def reuse_existing_contexts(self) -> None:
added_contexts = set([e for e in self.added_elements.values() if e.is_a("IfcGeometricRepresentationContext")])
added_contexts -= set(self.existing_contexts)
for added_context in added_contexts:
@@ -344,7 +345,9 @@ class Usecase:
for added_context in added_contexts:
ifcopenshell.util.element.remove_deep2(self.file, added_context)
def get_equivalent_existing_context(self, added_context):
def get_equivalent_existing_context(
self, added_context: ifcopenshell.entity_instance
) -> Union[ifcopenshell.entity_instance, None]:
for context in self.existing_contexts:
if context.is_a() != added_context.is_a():
continue
@@ -361,7 +364,7 @@ class Usecase:
):
return context
def create_equivalent_context(self, added_context):
def create_equivalent_context(self, added_context: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
if added_context.is_a("IfcGeometricRepresentationSubContext"):
parent = self.get_equivalent_existing_context(added_context.ParentContext)
if not parent:
@@ -18,13 +18,14 @@
import math
import numpy as np
import numpy.typing as npt
import ifcopenshell
import ifcopenshell.util.unit
import ifcopenshell.util.element
import ifcopenshell.util.placement
from typing import NamedTuple, Optional, Union
MatrixType = ifcopenshell.util.placement.MatrixType
class HelmertTransformation(NamedTuple):
e: float
@@ -159,7 +160,9 @@ def auto_xyz2enh(
return enh[0] / parameters.scale, enh[1] / parameters.scale, enh[2] / parameters.scale
def auto_enh2xyz(ifc_file, easting, northing, height, is_specified_in_map_units: bool = True):
def auto_enh2xyz(
ifc_file: ifcopenshell.file, easting: float, northing: float, height: float, is_specified_in_map_units: bool = True
) -> tuple[float, float, float]:
"""Convert from global map coordinate eastings, northings, and heights to local XYZ coordinates
The necessary georeferencing map conversion is automatically detected from
@@ -351,7 +354,7 @@ def enh2xyz(
def local2global(
matrix: npt.NDArray[np.float64],
matrix: MatrixType,
eastings: float = 0.0,
northings: float = 0.0,
orthogonal_height: float = 0.0,
@@ -361,7 +364,7 @@ def local2global(
factor_x: float = 1.0,
factor_y: float = 1.0,
factor_z: float = 1.0,
) -> npt.NDArray[np.float64]:
) -> MatrixType:
"""Manually convert a 4x4 matrix from local to global coordinates
This function is for advanced users as it allows you to specify your own
@@ -413,8 +416,8 @@ def local2global(
def auto_local2global(
ifc_file: ifcopenshell.file, matrix: npt.NDArray[np.float64], should_return_in_map_units: bool = True
) -> npt.NDArray[np.float64]:
ifc_file: ifcopenshell.file, matrix: MatrixType, should_return_in_map_units: bool = True
) -> MatrixType:
"""Convert a local matrix to a global map matrix
The necessary georeferencing map conversion is automatically detected from
@@ -443,7 +446,7 @@ def auto_local2global(
def global2local(
matrix: npt.NDArray[np.float64],
matrix: MatrixType,
eastings: float = 0.0,
northings: float = 0.0,
orthogonal_height: float = 0.0,
@@ -453,7 +456,7 @@ def global2local(
factor_x: float = 1.0,
factor_y: float = 1.0,
factor_z: float = 1.0,
) -> npt.NDArray[np.float64]:
) -> MatrixType:
"""Manually convert a 4x4 matrix from global to local coordinates
This function is for advanced users as it allows you to specify your own
@@ -504,8 +507,8 @@ def global2local(
def auto_global2local(
ifc_file: ifcopenshell.file, matrix: npt.NDArray[np.float64], is_specified_in_map_units: bool = True
) -> npt.NDArray[np.float64]:
ifc_file: ifcopenshell.file, matrix: MatrixType, is_specified_in_map_units: bool = True
) -> MatrixType:
"""Convert a global map matrix to a local matrix
The necessary georeferencing map conversion is automatically detected from
@@ -651,7 +654,7 @@ def angle2yaxis(angle: float) -> tuple[float, float]:
return x, y
def get_wcs(ifc_file: ifcopenshell.file) -> Optional[npt.NDArray[np.float64]]:
def get_wcs(ifc_file: ifcopenshell.file) -> Optional[MatrixType]:
"""Gets the WCS (prioritising 3D contexts) as a matrix
:param: The IFC file