mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-18 11:20:21 +00:00
typing
This commit is contained in:
@@ -25,8 +25,6 @@ from typing import Union
|
||||
def copy_cost_item(
|
||||
file: ifcopenshell.file, cost_item: ifcopenshell.entity_instance
|
||||
) -> Union[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance]]:
|
||||
# TODO: currently it never returns list of duplicated cost items
|
||||
# though it is stated in the docs
|
||||
"""Copies all cost items and related relationships
|
||||
|
||||
The following relationships are also duplicated:
|
||||
@@ -36,9 +34,7 @@ def copy_cost_item(
|
||||
* The copy will have duplicated nested cost items
|
||||
|
||||
:param cost_item: The cost item to be duplicated
|
||||
:type cost_item: ifcopenshell.entity_instance
|
||||
:return: The duplicated cost item or the list of duplicated cost items if the latter has children
|
||||
:rtype: ifcopenshell.entity_instance or list[ifcopenshell.entity_instance]
|
||||
|
||||
Example:
|
||||
.. code:: python
|
||||
@@ -53,22 +49,29 @@ def copy_cost_item(
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
usecase.settings = {"cost_item": cost_item}
|
||||
return usecase.execute()
|
||||
return usecase.execute(cost_item)
|
||||
|
||||
|
||||
class Usecase:
|
||||
def execute(self):
|
||||
self.new_cost_items = []
|
||||
return self.duplicate_cost_item(self.settings["cost_item"])
|
||||
file: ifcopenshell.file
|
||||
new_cost_items: list[ifcopenshell.entity_instance]
|
||||
|
||||
def duplicate_cost_item(self, cost_item):
|
||||
def execute(
|
||||
self, cost_item: ifcopenshell.entity_instance
|
||||
) -> Union[ifcopenshell.entity_instance, list[ifcopenshell.entity_instance]]:
|
||||
self.new_cost_items = []
|
||||
self.duplicate_cost_item(cost_item)
|
||||
return self.new_cost_items[0] if len(self.new_cost_items) == 1 else self.new_cost_items
|
||||
|
||||
def duplicate_cost_item(self, cost_item: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance:
|
||||
new_cost_item = ifcopenshell.util.element.copy_deep(self.file, cost_item)
|
||||
self.new_cost_items.append(new_cost_item)
|
||||
self.copy_indirect_attributes(cost_item, new_cost_item)
|
||||
return new_cost_item
|
||||
|
||||
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"):
|
||||
inverse = ifcopenshell.util.element.copy(self.file, inverse)
|
||||
|
||||
Reference in New Issue
Block a user