black format

This commit is contained in:
Andrej730
2024-04-09 16:44:26 +05:00
parent 8df04091ff
commit 846ff3b9fd
@@ -23,36 +23,36 @@ import ifcopenshell.util.element
class Usecase: class Usecase:
def __init__(self, file, cost_item=None): def __init__(self, file, cost_item=None):
"""Copies all cost items and related relationships """Copies all cost items and related relationships
The following relationships are also duplicated: The following relationships are also duplicated:
* The copy will have the same attributes and property sets as the original cost item * The copy will have the same attributes and property sets as the original cost item
* The copy will be assigned to the parent cost schedule * The copy will be assigned to the parent cost schedule
* The copy will have duplicated nested cost items * The copy will have duplicated nested cost items
:param cost_item: The cost item to be duplicated :param cost_item: The cost item to be duplicated
:type cost_item: ifcopenshell.entity_instance.entity_instance :type cost_item: ifcopenshell.entity_instance.entity_instance
:return: The duplicated cost item or the list of duplicated cost items if the latter has children :return: The duplicated cost item or the list of duplicated cost items if the latter has children
:rtype: ifcopenshell.entity_instance.entity_instance or list of ifcopenshell.entity_instance.entity_instance :rtype: ifcopenshell.entity_instance.entity_instance or list of ifcopenshell.entity_instance.entity_instance
Example: Example:
.. code:: python .. code:: python
# We have a cost item # We have a cost item
cost_item = CostItem(name="Design new feature", deadline="2023-03-01") cost_item = CostItem(name="Design new feature", deadline="2023-03-01")
# And now we have two # And now we have two
duplicated_cost_item = project.duplicate_cost_item(cost_item) duplicated_cost_item = project.duplicate_cost_item(cost_item)
""" """
self.file = file self.file = file
self.settings = {"cost_item": cost_item} self.settings = {"cost_item": cost_item}
def execute(self): def execute(self):
self.new_cost_items = [] self.new_cost_items = []
self.duplicate_cost_item(self.settings["cost_item"]) self.duplicate_cost_item(self.settings["cost_item"])
def duplicate_cost_item(self, cost_item): def duplicate_cost_item(self, cost_item):
new_cost_item = ifcopenshell.util.element.copy_deep(self.file, cost_item) new_cost_item = ifcopenshell.util.element.copy_deep(self.file, cost_item)
self.new_cost_items.append(new_cost_item) self.new_cost_items.append(new_cost_item)
@@ -64,9 +64,7 @@ class Usecase:
if inverse.is_a("IfcRelDefinesByProperties"): if inverse.is_a("IfcRelDefinesByProperties"):
inverse = ifcopenshell.util.element.copy(self.file, inverse) inverse = ifcopenshell.util.element.copy(self.file, inverse)
inverse.RelatedObjects = [to_element] inverse.RelatedObjects = [to_element]
pset = ifcopenshell.util.element.copy_deep( pset = ifcopenshell.util.element.copy_deep(self.file, inverse.RelatingPropertyDefinition)
self.file, inverse.RelatingPropertyDefinition
)
inverse.RelatingPropertyDefinition = pset inverse.RelatingPropertyDefinition = pset
elif inverse.is_a("IfcRelNests") and inverse.RelatingObject == from_element: elif inverse.is_a("IfcRelNests") and inverse.RelatingObject == from_element:
nested_cost_items = [e for e in inverse.RelatedObjects] nested_cost_items = [e for e in inverse.RelatedObjects]
@@ -79,9 +77,7 @@ class Usecase:
inverse.RelatingObject = to_element inverse.RelatingObject = to_element
inverse.RelatedObjects = new_cost_items inverse.RelatedObjects = new_cost_items
for cost_item in new_cost_items: for cost_item in new_cost_items:
ifcopenshell.api.run( ifcopenshell.api.run("nest.unassign_object", self.file, related_object=cost_item)
"nest.unassign_object", self.file, related_object=cost_item
)
rel = ifcopenshell.api.run( rel = ifcopenshell.api.run(
"nest.assign_object", "nest.assign_object",
self.file, self.file,