This commit is contained in:
Andrej730
2025-02-24 11:37:19 +05:00
parent 0783f8082e
commit 6eda4e389c
34 changed files with 336 additions and 245 deletions
@@ -28,11 +28,8 @@ def remove_cost_item_quantity(
removed.
:param cost_item: The IfcCostItem that the quantity is assigned to
:type cost_item: ifcopenshell.entity_instance
:param physical_quantity: The IfcPhysicalQuantity to remove
:type physical_quantity: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -46,11 +43,9 @@ def remove_cost_item_quantity(
ifcopenshell.api.cost.remove_cost_item(model,
cost_item=item, physical_quantity=quantity)
"""
settings = {"cost_item": cost_item, "physical_quantity": physical_quantity}
if len(file.get_inverse(settings["physical_quantity"])) == 1:
file.remove(settings["physical_quantity"])
if len(file.get_inverse(physical_quantity)) == 1:
file.remove(physical_quantity)
return
quantities = list(settings["cost_item"].CostQuantities or [])
quantities.remove(settings["physical_quantity"])
settings["cost_item"].CostQuantities = quantities
quantities = list(cost_item.CostQuantities or [])
quantities.remove(physical_quantity)
cost_item.CostQuantities = quantities
@@ -28,11 +28,8 @@ def remove_cost_value(
:param parent: The IfcCostItem, IfcConstructionResource, or IfcCostValue
that the IfcCostValue is assigned to.
:type parent: ifcopenshell.entity_instance
:param cost_value: The IfcCostValue that you want to remove
:type parent: ifcopenshell.entity_instance
:return: None
:rtype: None
Example:
@@ -48,20 +45,18 @@ def remove_cost_value(
ifcopenshell.api.cost.remove_cost_value(model, parent=item, cost_value=value)
"""
settings = {"parent": parent, "cost_value": cost_value}
if len(file.get_inverse(settings["cost_value"])) == 1:
file.remove(settings["cost_value"])
if len(file.get_inverse(cost_value)) == 1:
file.remove(cost_value)
# TODO deep purge
elif settings["parent"].is_a("IfcCostItem"):
values = list(settings["parent"].CostValues)
values.remove(settings["cost_value"])
settings["parent"].CostValues = values if values else None
elif settings["parent"].is_a("IfcConstructionResource"):
values = list(settings["parent"].BaseCosts)
values.remove(settings["cost_value"])
settings["parent"].BaseCosts = values if values else None
elif settings["parent"].is_a("IfcCostValue"):
components = list(settings["parent"].Components)
components.remove(settings["cost_value"])
settings["parent"].Components = components if components else None
elif parent.is_a("IfcCostItem"):
values = list(parent.CostValues)
values.remove(cost_value)
parent.CostValues = values if values else None
elif parent.is_a("IfcConstructionResource"):
values = list(parent.BaseCosts)
values.remove(cost_value)
parent.BaseCosts = values if values else None
elif parent.is_a("IfcCostValue"):
components = list(parent.Components)
components.remove(cost_value)
parent.Components = components if components else None