fix Cost schedule of rates UI bug where linked types dont't refresh correctly (and black formatting)

This commit is contained in:
Sigma Dimensions (Yass)
2023-08-11 14:57:18 +01:00
parent 66fbbeff54
commit 6263766202
2 changed files with 17 additions and 9 deletions
-1
View File
@@ -183,7 +183,6 @@ class Cost:
def get_cost_value_unit_component(cls): pass def get_cost_value_unit_component(cls): pass
def get_direct_cost_item_products(cls): pass def get_direct_cost_item_products(cls): pass
def get_highlighted_cost_item(cls): pass def get_highlighted_cost_item(cls): pass
def get_highlighted_cost_item(cls): pass
def get_products(cls, related_object_type): pass def get_products(cls, related_object_type): pass
def get_schedule_cost_items(cls, cost_schedule): pass def get_schedule_cost_items(cls, cost_schedule): pass
def get_units(cls): pass def get_units(cls): pass
+13 -4
View File
@@ -156,12 +156,16 @@ class Cost(blenderbim.core.tool.Cost):
@classmethod @classmethod
def get_highlighted_cost_item(cls): def get_highlighted_cost_item(cls):
props = bpy.context.scene.BIMCostProperties props = bpy.context.scene.BIMCostProperties
if not props.active_cost_schedule_id:
return
if props.active_cost_item_index < len(props.cost_items): if props.active_cost_item_index < len(props.cost_items):
return tool.Ifc.get().by_id(props.cost_items[props.active_cost_item_index].ifc_definition_id) return tool.Ifc.get().by_id(props.cost_items[props.active_cost_item_index].ifc_definition_id)
return None return
@classmethod @classmethod
def load_cost_item_types(cls, cost_item=None): def load_cost_item_types(cls, cost_item=None):
if not cost_item:
cost_item = cls.get_highlighted_cost_item()
if not cost_item: if not cost_item:
return return
props = bpy.context.scene.BIMCostProperties props = bpy.context.scene.BIMCostProperties
@@ -220,7 +224,7 @@ class Cost(blenderbim.core.tool.Cost):
selected_quantitites = [] selected_quantitites = []
unit = "" unit = ""
for quantities in ifcopenshell.util.element.get_psets(product, qtos_only=True).values(): for quantities in ifcopenshell.util.element.get_psets(product, qtos_only=True).values():
for qto in (tool.Ifc.get().by_id(quantities["id"]).Quantities or []): for qto in tool.Ifc.get().by_id(quantities["id"]).Quantities or []:
for quantity in cost_item.CostQuantities: for quantity in cost_item.CostQuantities:
if quantity == qto: if quantity == qto:
selected_quantitites.append(quantity) selected_quantitites.append(quantity)
@@ -509,6 +513,7 @@ class Cost(blenderbim.core.tool.Cost):
import subprocess import subprocess
import os import os
import sys import sys
if filepath: if filepath:
path = filepath path = filepath
else: else:
@@ -518,6 +523,7 @@ class Cost(blenderbim.core.tool.Cost):
os.makedirs(path) os.makedirs(path)
if format == "CSV": if format == "CSV":
from ifc5d.ifc5Dspreadsheet import Ifc5DCsvWriter from ifc5d.ifc5Dspreadsheet import Ifc5DCsvWriter
writer = Ifc5DCsvWriter(file=tool.Ifc.get(), output=path, cost_schedule=cost_schedule) writer = Ifc5DCsvWriter(file=tool.Ifc.get(), output=path, cost_schedule=cost_schedule)
writer.write() writer.write()
elif format == "ODS": elif format == "ODS":
@@ -539,7 +545,7 @@ class Cost(blenderbim.core.tool.Cost):
elif sys.platform == "linux": elif sys.platform == "linux":
subprocess.call(["xdg-open", path]) subprocess.call(["xdg-open", path])
except: except:
return 'Could not open file location' return "Could not open file location"
@classmethod @classmethod
def get_units(cls): def get_units(cls):
@@ -566,7 +572,6 @@ class Cost(blenderbim.core.tool.Cost):
name = f"{unit.Prefix} {name}" name = f"{unit.Prefix} {name}"
return f"{unit.UnitType} / {name}" return f"{unit.UnitType} / {name}"
@classmethod @classmethod
def get_cost_schedule(cls, cost_item): def get_cost_schedule(cls, cost_item):
for rel in cost_item.HasAssignments or []: for rel in cost_item.HasAssignments or []:
@@ -649,6 +654,8 @@ class Cost(blenderbim.core.tool.Cost):
@classmethod @classmethod
def toggle_cost_item_parent_change(cls, cost_item=None): def toggle_cost_item_parent_change(cls, cost_item=None):
if not cost_item:
return
props = bpy.context.scene.BIMCostProperties props = bpy.context.scene.BIMCostProperties
if props.change_cost_item_parent: if props.change_cost_item_parent:
props.active_cost_item_id = cost_item.id() props.active_cost_item_id = cost_item.id()
@@ -681,12 +688,14 @@ class Cost(blenderbim.core.tool.Cost):
if product: if product:
cost_items = ifcopenshell.util.cost.get_cost_items_for_product(product) cost_items = ifcopenshell.util.cost.get_cost_items_for_product(product)
if pset: if pset:
def get_products_from_pset(pset): def get_products_from_pset(pset):
products = [] products = []
for rel in pset.DefinesOccurrence or []: for rel in pset.DefinesOccurrence or []:
if rel.is_a("IfcRelDefinesByProperties"): if rel.is_a("IfcRelDefinesByProperties"):
products.extend(rel.RelatedObjects) products.extend(rel.RelatedObjects)
return products return products
products = get_products_from_pset(pset) products = get_products_from_pset(pset)
for product in products or []: for product in products or []:
cost_items.extend(ifcopenshell.util.cost.get_cost_items_for_product(product)) cost_items.extend(ifcopenshell.util.cost.get_cost_items_for_product(product))