mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
typing
This commit is contained in:
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user