mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 19:07:57 +00:00
Generate functions for all API usecases for better static code features. See #2693.
This commit is contained in:
@@ -17,95 +17,92 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
class Usecase:
|
||||
def __init__(self, file, parent=None):
|
||||
"""Adds a new value or subvalue to a cost item
|
||||
def add_cost_value(file, parent=None) -> None:
|
||||
"""Adds a new value or subvalue to a cost item
|
||||
|
||||
A cost item's subtotal can be specified in two ways.
|
||||
A cost item's subtotal can be specified in two ways.
|
||||
|
||||
Option 1 is by simply manually specifying the subtotal value, which
|
||||
represents the full cost of that cost item. This option occurs when a
|
||||
cost item has no quantities associated with it.
|
||||
Option 1 is by simply manually specifying the subtotal value, which
|
||||
represents the full cost of that cost item. This option occurs when a
|
||||
cost item has no quantities associated with it.
|
||||
|
||||
Option 2 is by specifying a unit cost value of the cost item, which is
|
||||
then multiplied by the associated quantity of the cost item, to give us
|
||||
the subtotal. This option occurs when a cost item has quantities
|
||||
associated with it.
|
||||
Option 2 is by specifying a unit cost value of the cost item, which is
|
||||
then multiplied by the associated quantity of the cost item, to give us
|
||||
the subtotal. This option occurs when a cost item has quantities
|
||||
associated with it.
|
||||
|
||||
For either option 1 (full cost value) or option 2 (unit cost value), the
|
||||
cost value may be specified as a single number, or as a sum of
|
||||
subcomponents or formulas (e.g. multiplication by wastage factor, or
|
||||
adding taxes or other adjustments).
|
||||
For either option 1 (full cost value) or option 2 (unit cost value), the
|
||||
cost value may be specified as a single number, or as a sum of
|
||||
subcomponents or formulas (e.g. multiplication by wastage factor, or
|
||||
adding taxes or other adjustments).
|
||||
|
||||
This function lets you add a single top level unit value to a cost item,
|
||||
or alternatively price subcomponents by using the "parent" parameter.
|
||||
This function lets you add a single top level unit value to a cost item,
|
||||
or alternatively price subcomponents by using the "parent" parameter.
|
||||
|
||||
More advanced usage, which involves summing, subcategory-filtered costs,
|
||||
and formulas are possible but not yet documented.
|
||||
More advanced usage, which involves summing, subcategory-filtered costs,
|
||||
and formulas are possible but not yet documented.
|
||||
|
||||
:param parent: A parent IfcCostItem, if specifying a price directly to a
|
||||
cost item, or a top-level price component. Alternatively, this can
|
||||
be set to a IfcCostValue, if specifying price subcomponents.
|
||||
:type parent: ifcopenshell.entity_instance
|
||||
:return: The newly created IfcCostValue
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
:param parent: A parent IfcCostItem, if specifying a price directly to a
|
||||
cost item, or a top-level price component. Alternatively, this can
|
||||
be set to a IfcCostValue, if specifying price subcomponents.
|
||||
:type parent: ifcopenshell.entity_instance
|
||||
:return: The newly created IfcCostValue
|
||||
:rtype: ifcopenshell.entity_instance
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
.. code:: python
|
||||
.. code:: python
|
||||
|
||||
# We always need a schedule first prior to adding any cost items
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
|
||||
# We always need a schedule first prior to adding any cost items
|
||||
schedule = ifcopenshell.api.run("cost.add_cost_schedule", model)
|
||||
|
||||
# Option 1: This cost item will have a full cost of 42.0
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
|
||||
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item1)
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
|
||||
attributes={"AppliedValue": 42.0})
|
||||
# Option 1: This cost item will have a full cost of 42.0
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
|
||||
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item1)
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
|
||||
attributes={"AppliedValue": 42.0})
|
||||
|
||||
# Option 2: This cost item will have a unit cost of 5.0 per unit
|
||||
# area, multiplied by the quantity of area specified explicitly as
|
||||
# 3.0, giving us a subtotal cost of 15.0.
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
|
||||
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item2)
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
|
||||
attributes={"AppliedValue": 5.0})
|
||||
quantity = ifcopenshell.api.run("cost.add_cost_item_quantity", model,
|
||||
cost_item=item2, ifc_class="IfcQuantityVolume")
|
||||
ifcopenshell.api.run("cost.edit_cost_item_quantity", model,
|
||||
physical_quantity=quantity, "attributes": {"VolumeValue": 3.0})
|
||||
# Option 2: This cost item will have a unit cost of 5.0 per unit
|
||||
# area, multiplied by the quantity of area specified explicitly as
|
||||
# 3.0, giving us a subtotal cost of 15.0.
|
||||
item2 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
|
||||
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item2)
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value,
|
||||
attributes={"AppliedValue": 5.0})
|
||||
quantity = ifcopenshell.api.run("cost.add_cost_item_quantity", model,
|
||||
cost_item=item2, ifc_class="IfcQuantityVolume")
|
||||
ifcopenshell.api.run("cost.edit_cost_item_quantity", model,
|
||||
physical_quantity=quantity, "attributes": {"VolumeValue": 3.0})
|
||||
|
||||
# A cost value may also be specified in terms of the sum of its
|
||||
# subcomponents. In this case, it's broken down into 2 subvalues.
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
|
||||
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item1)
|
||||
subvalue1 = ifcopenshell.api.run("cost.add_cost_value", model, parent=value)
|
||||
subvalue2 = ifcopenshell.api.run("cost.add_cost_value", model, parent=value)
|
||||
# A cost value may also be specified in terms of the sum of its
|
||||
# subcomponents. In this case, it's broken down into 2 subvalues.
|
||||
item1 = ifcopenshell.api.run("cost.add_cost_item", model, cost_schedule=schedule)
|
||||
value = ifcopenshell.api.run("cost.add_cost_value", model, parent=item1)
|
||||
subvalue1 = ifcopenshell.api.run("cost.add_cost_value", model, parent=value)
|
||||
subvalue2 = ifcopenshell.api.run("cost.add_cost_value", model, parent=value)
|
||||
|
||||
# This specifies that the value is the sum of all subitems
|
||||
# regardless of their cost category. The first subvalue is 2.0 and
|
||||
# the second is 3.0, giving a total value of 5.0.
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value, attributes={"Category": "*"})
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model,
|
||||
cost_value=subvalue1, attributes={"AppliedValue": 2.0})
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model,
|
||||
cost_value=subvalue2, attributes={"AppliedValue": 3.0})
|
||||
"""
|
||||
self.file = file
|
||||
self.settings = {"parent": parent}
|
||||
# This specifies that the value is the sum of all subitems
|
||||
# regardless of their cost category. The first subvalue is 2.0 and
|
||||
# the second is 3.0, giving a total value of 5.0.
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model, cost_value=value, attributes={"Category": "*"})
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model,
|
||||
cost_value=subvalue1, attributes={"AppliedValue": 2.0})
|
||||
ifcopenshell.api.run("cost.edit_cost_value", model,
|
||||
cost_value=subvalue2, attributes={"AppliedValue": 3.0})
|
||||
"""
|
||||
settings = {"parent": parent}
|
||||
|
||||
def execute(self):
|
||||
value = self.file.create_entity("IfcCostValue")
|
||||
if self.settings["parent"].is_a("IfcCostItem"):
|
||||
values = list(self.settings["parent"].CostValues or [])
|
||||
values.append(value)
|
||||
self.settings["parent"].CostValues = values
|
||||
elif self.settings["parent"].is_a("IfcConstructionResource"):
|
||||
values = list(self.settings["parent"].BaseCosts or [])
|
||||
values.append(value)
|
||||
self.settings["parent"].BaseCosts = values
|
||||
elif self.settings["parent"].is_a("IfcCostValue"):
|
||||
values = list(self.settings["parent"].Components or [])
|
||||
values.append(value)
|
||||
self.settings["parent"].Components = values
|
||||
return value
|
||||
value = file.create_entity("IfcCostValue")
|
||||
if settings["parent"].is_a("IfcCostItem"):
|
||||
values = list(settings["parent"].CostValues or [])
|
||||
values.append(value)
|
||||
settings["parent"].CostValues = values
|
||||
elif settings["parent"].is_a("IfcConstructionResource"):
|
||||
values = list(settings["parent"].BaseCosts or [])
|
||||
values.append(value)
|
||||
settings["parent"].BaseCosts = values
|
||||
elif settings["parent"].is_a("IfcCostValue"):
|
||||
values = list(settings["parent"].Components or [])
|
||||
values.append(value)
|
||||
settings["parent"].Components = values
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user