mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
You can now assign resource-based parametric quantities to cost items
This commit is contained in:
@@ -324,6 +324,14 @@ class AssignCostItemQuantity(bpy.types.Operator):
|
||||
].ifc_definition_id
|
||||
)
|
||||
]
|
||||
elif self.related_object_type == "RESOURCE":
|
||||
products = [
|
||||
self.file.by_id(
|
||||
context.scene.BIMResourceTreeProperties.resources[
|
||||
context.scene.BIMResourceProperties.active_resource_index
|
||||
].ifc_definition_id
|
||||
)
|
||||
]
|
||||
ifcopenshell.api.run(
|
||||
"cost.assign_cost_item_quantity",
|
||||
self.file,
|
||||
@@ -717,6 +725,8 @@ class LoadCostItemQuantities(bpy.types.Operator):
|
||||
self.props.cost_item_products.remove(0)
|
||||
while len(self.props.cost_item_processes) > 0:
|
||||
self.props.cost_item_processes.remove(0)
|
||||
while len(self.props.cost_item_resources) > 0:
|
||||
self.props.cost_item_resources.remove(0)
|
||||
ifc_definition_id = self.props.cost_items[self.props.active_cost_item_index].ifc_definition_id
|
||||
for control_id, quantity_ids in Data.cost_items[ifc_definition_id]["Controls"].items():
|
||||
related_object = self.file.by_id(control_id)
|
||||
@@ -725,7 +735,7 @@ class LoadCostItemQuantities(bpy.types.Operator):
|
||||
elif related_object.is_a("IfcProcess"):
|
||||
new = self.props.cost_item_processes.add()
|
||||
elif related_object.is_a("IfcResource"):
|
||||
pass
|
||||
new = self.props.cost_item_resources.add()
|
||||
new.ifc_definition_id = control_id
|
||||
new.name = related_object.Name or "Unnamed"
|
||||
total_quantity = 0
|
||||
|
||||
@@ -22,6 +22,8 @@ productquantitynames_enum = []
|
||||
productquantitynames_count = []
|
||||
processquantitynames_enum = []
|
||||
processquantitynames_id = 0
|
||||
resourcequantitynames_enum = []
|
||||
resourcequantitynames_id = 0
|
||||
|
||||
|
||||
def purge():
|
||||
@@ -30,11 +32,15 @@ def purge():
|
||||
global productquantitynames_count
|
||||
global processquantitynames_enum
|
||||
global processquantitynames_id
|
||||
global resourcequantitynames_enum
|
||||
global resourcequantitynames_id
|
||||
quantitytypes_enum = []
|
||||
productquantitynames_enum = []
|
||||
productquantitynames_count = []
|
||||
processquantitynames_enum = []
|
||||
processquantitynames_id = 0
|
||||
resourcequantitynames_enum = []
|
||||
resourcequantitynames_id = 0
|
||||
|
||||
|
||||
def getQuantityTypes(self, context):
|
||||
@@ -79,12 +85,10 @@ def getProcessQuantityNames(self, context):
|
||||
global processquantitynames_id
|
||||
ifc_file = IfcStore.get_file()
|
||||
active_task_index = context.scene.BIMWorkScheduleProperties.active_task_index
|
||||
if not active_task_index:
|
||||
return []
|
||||
try:
|
||||
ifc_definition_id = context.scene.BIMTaskTreeProperties.tasks[active_task_index].ifc_definition_id
|
||||
except:
|
||||
total_tasks = len(context.scene.BIMTaskTreeProperties.tasks)
|
||||
if not total_tasks or active_task_index >= total_tasks:
|
||||
return []
|
||||
ifc_definition_id = context.scene.BIMTaskTreeProperties.tasks[active_task_index].ifc_definition_id
|
||||
if processquantitynames_id != ifc_definition_id:
|
||||
processquantitynames_enum = []
|
||||
processquantitynames_id = ifc_definition_id
|
||||
@@ -98,6 +102,28 @@ def getProcessQuantityNames(self, context):
|
||||
return processquantitynames_enum
|
||||
|
||||
|
||||
def getResourceQuantityNames(self, context):
|
||||
global resourcequantitynames_enum
|
||||
global resourcequantitynames_id
|
||||
ifc_file = IfcStore.get_file()
|
||||
active_resource_index = context.scene.BIMResourceProperties.active_resource_index
|
||||
total_resources = len(context.scene.BIMResourceTreeProperties.resources)
|
||||
if not total_resources or active_resource_index >= total_resources:
|
||||
return []
|
||||
ifc_definition_id = context.scene.BIMResourceTreeProperties.resources[active_resource_index].ifc_definition_id
|
||||
if resourcequantitynames_id != ifc_definition_id:
|
||||
resourcequantitynames_enum = []
|
||||
resourcequantitynames_id = ifc_definition_id
|
||||
names = set()
|
||||
if ifc_definition_id not in PsetData.products:
|
||||
PsetData.load(ifc_file, ifc_definition_id)
|
||||
for qto_id in PsetData.products[ifc_definition_id]["qtos"]:
|
||||
qto = PsetData.qtos[qto_id]
|
||||
[names.add(PsetData.properties[p]["Name"]) for p in qto["Properties"]]
|
||||
resourcequantitynames_enum.extend([(n, n, "") for n in names])
|
||||
return resourcequantitynames_enum
|
||||
|
||||
|
||||
def update_cost_item_index(self, context):
|
||||
bpy.ops.bim.load_cost_item_quantities()
|
||||
|
||||
@@ -145,6 +171,7 @@ class BIMCostProperties(PropertyGroup):
|
||||
quantity_types: EnumProperty(items=getQuantityTypes, name="Quantity Types")
|
||||
product_quantity_names: EnumProperty(items=getProductQuantityNames, name="Product Quantity Names")
|
||||
process_quantity_names: EnumProperty(items=getProcessQuantityNames, name="Process Quantity Names")
|
||||
resource_quantity_names: EnumProperty(items=getResourceQuantityNames, name="Resource Quantity Names")
|
||||
active_cost_item_quantity_id: IntProperty(name="Active Cost Item Quantity Id")
|
||||
quantity_attributes: CollectionProperty(name="Quantity Attributes", type=Attribute)
|
||||
cost_types: EnumProperty(
|
||||
@@ -166,3 +193,5 @@ class BIMCostProperties(PropertyGroup):
|
||||
active_cost_item_product_index: IntProperty(name="Active Cost Item Product Index")
|
||||
cost_item_processes: CollectionProperty(name="Cost Item Processes", type=CostItemQuantity)
|
||||
active_cost_item_process_index: IntProperty(name="Active Cost Item Process Index")
|
||||
cost_item_resources: CollectionProperty(name="Cost Item Resources", type=CostItemQuantity)
|
||||
active_cost_item_resource_index: IntProperty(name="Active Cost Item Resource Index")
|
||||
|
||||
@@ -301,8 +301,6 @@ class BIM_PT_cost_item_quantities(Panel):
|
||||
|
||||
row2 = col.row(align=True)
|
||||
row2.label(text="Tasks")
|
||||
op = row2.operator("bim.select_cost_item_products", icon="RESTRICT_SELECT_OFF", text="")
|
||||
op.cost_item = cost_item.ifc_definition_id
|
||||
|
||||
row2 = col.row()
|
||||
row2.template_list(
|
||||
@@ -327,22 +325,24 @@ class BIM_PT_cost_item_quantities(Panel):
|
||||
|
||||
row2 = col.row(align=True)
|
||||
row2.label(text="Resources")
|
||||
op = row2.operator("bim.select_cost_item_products", icon="RESTRICT_SELECT_OFF", text="")
|
||||
op.cost_item = cost_item.ifc_definition_id
|
||||
|
||||
row2 = col.row()
|
||||
row2.template_list(
|
||||
"BIM_UL_cost_item_quantities",
|
||||
"",
|
||||
self.props,
|
||||
"cost_item_products",
|
||||
"cost_item_resources",
|
||||
self.props,
|
||||
"active_cost_item_product_index",
|
||||
"active_cost_item_resource_index",
|
||||
)
|
||||
|
||||
row2 = col.row(align=True)
|
||||
row2.prop(self.props, "process_quantity_names", text="")
|
||||
op = row2.operator("bim.assign_cost_item_quantity", text="", icon="ADD")
|
||||
row2.prop(self.props, "resource_quantity_names", text="")
|
||||
if CostProp.resourcequantitynames_enum:
|
||||
op = row2.operator("bim.assign_cost_item_quantity", text="", icon="ADD")
|
||||
op.related_object_type = "RESOURCE"
|
||||
op.cost_item = cost_item.ifc_definition_id
|
||||
op.prop_name = self.props.resource_quantity_names
|
||||
|
||||
|
||||
class BIM_UL_cost_items(UIList):
|
||||
|
||||
Reference in New Issue
Block a user