mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
Refactor BBIM costing code, and re-use shared IOS utilies code
This commit is contained in:
@@ -198,8 +198,9 @@ def edit_cost_value(ifc, cost, cost_value):
|
|||||||
def copy_cost_item_values(ifc, cost, source, destination):
|
def copy_cost_item_values(ifc, cost, source, destination):
|
||||||
ifc.run("cost.copy_cost_item_values", source=source, destination=destination)
|
ifc.run("cost.copy_cost_item_values", source=source, destination=destination)
|
||||||
|
|
||||||
def select_cost_item_products(cost, spatial, cost_item, include_nested):
|
def select_cost_item_products(cost, spatial, cost_item):
|
||||||
products = cost.get_cost_item_products(cost_item, include_nested)
|
is_deep = cost.show_nested_cost_item_elements()
|
||||||
|
products = cost.get_cost_item_products(cost_item, is_deep)
|
||||||
spatial.select_products(products)
|
spatial.select_products(products)
|
||||||
|
|
||||||
def select_cost_schedule_products(cost, spatial, cost_schedule):
|
def select_cost_schedule_products(cost, spatial, cost_schedule):
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ class Cost(blenderbim.core.tool.Cost):
|
|||||||
if props.active_cost_item_index in cls.contracted_cost_items:
|
if props.active_cost_item_index in cls.contracted_cost_items:
|
||||||
cls.contracted_cost_items.remove(props.active_cost_item_index)
|
cls.contracted_cost_items.remove(props.active_cost_item_index)
|
||||||
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
||||||
bpy.ops.bim.enable_editing_cost_items(cost_schedule=props.active_cost_schedule_id)
|
cls.enable_editing_cost_items(cost_schedule=tool.Ifc.get().by_id(props.active_cost_schedule_id))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enable_editing_cost_item_attributes(cls, cost_item):
|
def enable_editing_cost_item_attributes(cls, cost_item):
|
||||||
@@ -148,7 +148,7 @@ class Cost(blenderbim.core.tool.Cost):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_active_cost_item(cls):
|
def get_active_cost_item(cls):
|
||||||
props = bpy.context.scene.BIMCostProperties
|
props = bpy.context.scene.BIMCostProperties
|
||||||
if props.active_cost_item_id == 0:
|
if not props.active_cost_item_id:
|
||||||
return None
|
return None
|
||||||
return tool.Ifc.get().by_id(bpy.context.scene.BIMCostProperties.active_cost_item_id)
|
return tool.Ifc.get().by_id(bpy.context.scene.BIMCostProperties.active_cost_item_id)
|
||||||
|
|
||||||
@@ -394,47 +394,30 @@ class Cost(blenderbim.core.tool.Cost):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cost_item_products(cls, cost_item, include_nested=False):
|
def show_nested_cost_item_elements(cls):
|
||||||
if not include_nested:
|
return bpy.context.scene.BIMCostProperties.show_nested_elements
|
||||||
return cls.get_direct_cost_item_products(cost_item)
|
|
||||||
else:
|
|
||||||
return [
|
|
||||||
product
|
|
||||||
for nested_cost_item in cls.get_all_nested_cost_items(cost_item)
|
|
||||||
for product in cls.get_direct_cost_item_products(nested_cost_item)
|
|
||||||
]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_all_nested_cost_items(cls, cost_item):
|
def get_cost_item_products(cls, cost_item, is_deep=False):
|
||||||
for cost_item in cls.get_nested_cost_items(cost_item):
|
return cls.get_cost_item_assignments(cost_item, filter_by_type="PRODUCT", is_deep=is_deep)
|
||||||
yield cost_item
|
|
||||||
yield from cls.get_all_nested_cost_items(cost_item)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_nested_cost_items(cls, cost_item):
|
def get_cost_item_resources(cls, cost_item, is_deep=False):
|
||||||
return [obj for rel in cost_item.IsNestedBy for obj in rel.RelatedObjects]
|
return cls.get_cost_item_assignments(cost_item, filter_by_type="RESOURCE", is_deep=is_deep)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_cost_item_processes(cls, cost_item, is_deep=False):
|
||||||
|
return cls.get_cost_item_assignments(cost_item, filter_by_type="PROCESS", is_deep=is_deep)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_schedule_cost_items(cls, cost_schedule):
|
def get_schedule_cost_items(cls, cost_schedule):
|
||||||
for cost_item in cls.get_root_cost_items(cost_schedule):
|
return ifcopenshell.util.cost.get_schedule_cost_items(cost_schedule)
|
||||||
yield cost_item
|
|
||||||
yield from cls.get_all_nested_cost_items(cost_item)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_root_cost_items(cls, cost_schedule):
|
|
||||||
return [
|
|
||||||
related_object
|
|
||||||
for rel in cost_schedule.Controls or []
|
|
||||||
for related_object in rel.RelatedObjects
|
|
||||||
if related_object.is_a("IfcCostItem")
|
|
||||||
]
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_cost_schedule_products(cls, cost_schedule):
|
def get_cost_schedule_products(cls, cost_schedule):
|
||||||
products = []
|
products = []
|
||||||
for cost_item in cls.get_root_cost_items(cost_schedule):
|
for cost_item in ifcopenshell.util.cost.get_schedule_cost_items(cost_schedule):
|
||||||
products.extend(cls.get_cost_item_products(cost_item, include_nested=True))
|
products.extend(cls.get_cost_item_products(cost_item))
|
||||||
return products
|
return products
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user