mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
typing
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api.pset
|
||||
import ifcopenshell.util.element
|
||||
from typing import Optional, Any
|
||||
|
||||
|
||||
|
||||
@@ -54,9 +54,7 @@ def copy_class(file: ifcopenshell.file, product: ifcopenshell.entity_instance) -
|
||||
connections are still valid.
|
||||
|
||||
:param product: The IfcProduct to copy.
|
||||
:type param: ifcopenshell.entity_instance
|
||||
:return: The copied product
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
|
||||
@@ -70,26 +68,26 @@ def copy_class(file: ifcopenshell.file, product: ifcopenshell.entity_instance) -
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
usecase.settings = {"product": product}
|
||||
return usecase.execute()
|
||||
return usecase.execute(product)
|
||||
|
||||
|
||||
class Usecase:
|
||||
file: ifcopenshell.file
|
||||
settings: dict[str, Any]
|
||||
|
||||
def execute(self):
|
||||
result = ifcopenshell.util.element.copy(self.file, self.settings["product"])
|
||||
def execute(self, product: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
||||
result = ifcopenshell.util.element.copy(self.file, product)
|
||||
self.copy_direct_attributes(result)
|
||||
self.copy_indirect_attributes(self.settings["product"], result)
|
||||
self.copy_indirect_attributes(product, result)
|
||||
return result
|
||||
|
||||
def copy_direct_attributes(self, to_element):
|
||||
def copy_direct_attributes(self, to_element: ifcopenshell.entity_instance) -> None:
|
||||
self.remove_representations(to_element)
|
||||
self.copy_object_placements(to_element)
|
||||
self.copy_psets(to_element)
|
||||
|
||||
def copy_indirect_attributes(self, from_element, to_element):
|
||||
def copy_indirect_attributes(
|
||||
self, from_element: ifcopenshell.entity_instance, to_element: ifcopenshell.entity_instance
|
||||
) -> None:
|
||||
for inverse in self.file.get_inverse(from_element):
|
||||
if inverse.is_a("IfcRelDefinesByProperties"):
|
||||
# Properties must not be shared between objects for convenience of authoring
|
||||
@@ -175,13 +173,13 @@ class Usecase:
|
||||
new_value.append(to_element)
|
||||
inverse[i] = new_value
|
||||
|
||||
def remove_representations(self, element):
|
||||
def remove_representations(self, element: ifcopenshell.entity_instance) -> None:
|
||||
if element.is_a("IfcProduct"):
|
||||
element.Representation = None
|
||||
elif element.is_a("IfcTypeProduct"):
|
||||
element.RepresentationMaps = None
|
||||
|
||||
def copy_object_placements(self, element):
|
||||
def copy_object_placements(self, element: ifcopenshell.entity_instance) -> None:
|
||||
if not element.is_a("IfcProduct") or not element.ObjectPlacement:
|
||||
return
|
||||
element.ObjectPlacement = ifcopenshell.util.element.copy(self.file, element.ObjectPlacement)
|
||||
@@ -189,7 +187,7 @@ class Usecase:
|
||||
self.file, element.ObjectPlacement.RelativePlacement
|
||||
)
|
||||
|
||||
def copy_psets(self, element):
|
||||
def copy_psets(self, element: ifcopenshell.entity_instance) -> None:
|
||||
if not element.is_a("IfcTypeObject") or not element.HasPropertySets:
|
||||
return
|
||||
element.HasPropertySets = [
|
||||
|
||||
@@ -20,7 +20,6 @@ from fractions import Fraction
|
||||
from math import pi
|
||||
from typing import Any
|
||||
from typing import Dict
|
||||
from typing import Iterable
|
||||
from typing import Literal
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
@@ -821,7 +820,8 @@ def iter_element_and_attributes_per_type(ifc_file: ifcopenshell.file, attr_type_
|
||||
for element in ifc_file:
|
||||
entity = schema.declaration_by_name(element.is_a())
|
||||
attrs = entity.all_attributes()
|
||||
for attr, val, is_derived in zip(attrs, list(element), entity.derived()):
|
||||
attrs_derived: tuple[bool, ...] = entity.derived()
|
||||
for attr, val, is_derived in zip(attrs, list(element), attrs_derived):
|
||||
if is_derived:
|
||||
continue
|
||||
|
||||
@@ -877,7 +877,7 @@ def convert_file_length_units(ifc_file: ifcopenshell.file, target_units: str = "
|
||||
new_length = ifcopenshell.api.unit.add_conversion_based_unit(file_patched, name=target_units)
|
||||
|
||||
# support tuple of tuples, as in IfcCartesianPointList3D.CoordList
|
||||
def convert_value(value):
|
||||
def convert_value(value: FloatOrSequenceOfFloats) -> FloatOrSequenceOfFloats:
|
||||
if not isinstance(value, tuple):
|
||||
return convert_unit(value, old_length, new_length)
|
||||
return tuple(convert_value(v) for v in value)
|
||||
|
||||
Reference in New Issue
Block a user