mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
tool.cost - refactor expand/contract rates methods
So they will be more similar
This commit is contained in:
@@ -154,7 +154,7 @@ class ExpandCostItem(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
cost_item: int
|
cost_item: int
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.expand_cost_item(tool.Cost, cost_item=tool.Ifc.get().by_id(self.cost_item))
|
core.expand_cost_item(tool.Cost, cost_item_id=self.cost_item)
|
||||||
|
|
||||||
|
|
||||||
class ExpandCostItems(bpy.types.Operator, tool.Ifc.Operator):
|
class ExpandCostItems(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -179,7 +179,7 @@ class ContractCostItem(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
cost_item: int
|
cost_item: int
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
core.contract_cost_item(tool.Cost, cost_item=tool.Ifc.get().by_id(self.cost_item))
|
core.contract_cost_item(tool.Cost, cost_item_id=self.cost_item)
|
||||||
|
|
||||||
|
|
||||||
class ContractCostItems(bpy.types.Operator, tool.Ifc.Operator):
|
class ContractCostItems(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
|
|||||||
@@ -76,8 +76,8 @@ def add_cost_item(ifc: type[tool.Ifc], cost: type[tool.Cost], cost_item: ifcopen
|
|||||||
# cost.enable_editing_cost_schedule_attributes(cost_schedule)
|
# cost.enable_editing_cost_schedule_attributes(cost_schedule)
|
||||||
|
|
||||||
|
|
||||||
def expand_cost_item(cost: type[tool.Cost], cost_item: ifcopenshell.entity_instance) -> None:
|
def expand_cost_item(cost: type[tool.Cost], cost_item_id: int) -> None:
|
||||||
cost.expand_cost_item(cost_item)
|
cost.expand_cost_item(cost_item_id)
|
||||||
cost.load_cost_schedule_tree()
|
cost.load_cost_schedule_tree()
|
||||||
|
|
||||||
|
|
||||||
@@ -86,8 +86,8 @@ def expand_cost_items(cost: type[tool.Cost]) -> None:
|
|||||||
cost.load_cost_schedule_tree()
|
cost.load_cost_schedule_tree()
|
||||||
|
|
||||||
|
|
||||||
def contract_cost_item(cost: type[tool.Cost], cost_item: ifcopenshell.entity_instance) -> None:
|
def contract_cost_item(cost: type[tool.Cost], cost_item_id: int) -> None:
|
||||||
cost.contract_cost_item(cost_item)
|
cost.contract_cost_item(cost_item_id)
|
||||||
cost.load_cost_schedule_tree()
|
cost.load_cost_schedule_tree()
|
||||||
|
|
||||||
|
|
||||||
@@ -368,12 +368,18 @@ def remove_cost_column(cost: type[tool.Cost], name: str) -> None:
|
|||||||
cost.remove_cost_column(name)
|
cost.remove_cost_column(name)
|
||||||
|
|
||||||
|
|
||||||
def expand_cost_item_rate(cost: type[tool.Cost], cost_item: int) -> None:
|
def expand_cost_item_rate(cost: type[tool.Cost], cost_item_id: int) -> None:
|
||||||
cost.expand_cost_item_rate(cost_item)
|
cost.expand_cost_item_rate(cost_item_id)
|
||||||
|
schedule_of_rates = cost.get_active_schedule_of_rates()
|
||||||
|
assert schedule_of_rates
|
||||||
|
cost.load_schedule_of_rates_tree(schedule_of_rates)
|
||||||
|
|
||||||
|
|
||||||
def contract_cost_item_rate(cost: type[tool.Cost], cost_item: int) -> None:
|
def contract_cost_item_rate(cost: type[tool.Cost], cost_item_id: int) -> None:
|
||||||
cost.contract_cost_item_rate(cost_item)
|
cost.contract_cost_item_rate(cost_item_id)
|
||||||
|
schedule_of_rates = cost.get_active_schedule_of_rates()
|
||||||
|
assert schedule_of_rates
|
||||||
|
cost.load_schedule_of_rates_tree(schedule_of_rates)
|
||||||
|
|
||||||
|
|
||||||
def calculate_cost_item_resource_value(ifc: type[tool.Ifc], cost_item: ifcopenshell.entity_instance) -> None:
|
def calculate_cost_item_resource_value(ifc: type[tool.Ifc], cost_item: ifcopenshell.entity_instance) -> None:
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ class Cost:
|
|||||||
def change_parent_cost_item(cls, cost_item, new_parent): pass
|
def change_parent_cost_item(cls, cost_item, new_parent): pass
|
||||||
def clean_up_cost_item_tree(cls, cost_item): pass
|
def clean_up_cost_item_tree(cls, cost_item): pass
|
||||||
def contract_cost_item_rate(cls, cost_item): pass
|
def contract_cost_item_rate(cls, cost_item): pass
|
||||||
def contract_cost_item(cls, cost_item): pass
|
def contract_cost_item(cls, cost_item_id): pass
|
||||||
def contract_cost_items(cls): pass
|
def contract_cost_items(cls): pass
|
||||||
def create_new_cost_item_li(props_collection, cost_item, level_index, type): pass
|
def create_new_cost_item_li(props_collection, cost_item, level_index, type): pass
|
||||||
def disable_editing_cost_item_parent(cls): pass
|
def disable_editing_cost_item_parent(cls): pass
|
||||||
@@ -220,7 +220,7 @@ class Cost:
|
|||||||
def enable_editing_cost_items(cls, cost_schedule): pass
|
def enable_editing_cost_items(cls, cost_schedule): pass
|
||||||
def enable_editing_cost_schedule_attributes(cls, cost_schedule): pass
|
def enable_editing_cost_schedule_attributes(cls, cost_schedule): pass
|
||||||
def expand_cost_item_rate(cls, cost_item): pass
|
def expand_cost_item_rate(cls, cost_item): pass
|
||||||
def expand_cost_item(cls, cost_item): pass
|
def expand_cost_item(cls, cost_item_id): pass
|
||||||
def expand_cost_items(cls): pass
|
def expand_cost_items(cls): pass
|
||||||
def export_cost_schedules(cls, filepath, format, cost_schedule): pass
|
def export_cost_schedules(cls, filepath, format, cost_schedule): pass
|
||||||
def format_unit(cls, unit): pass
|
def format_unit(cls, unit): pass
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ if TYPE_CHECKING:
|
|||||||
class Cost(bonsai.core.tool.Cost):
|
class Cost(bonsai.core.tool.Cost):
|
||||||
|
|
||||||
RELATED_OBJECT_TYPE = Literal["PRODUCT", "PROCESS", "RESOURCE"]
|
RELATED_OBJECT_TYPE = Literal["PRODUCT", "PROCESS", "RESOURCE"]
|
||||||
|
|
||||||
|
# TODO: Do we really need them cached as class attributes?
|
||||||
contracted_cost_items: list[int]
|
contracted_cost_items: list[int]
|
||||||
"""List of contracted cost item ids."""
|
"""List of contracted cost item ids."""
|
||||||
|
|
||||||
@@ -169,12 +171,12 @@ class Cost(bonsai.core.tool.Cost):
|
|||||||
props.is_cost_update_enabled = True
|
props.is_cost_update_enabled = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def expand_cost_item(cls, cost_item: ifcopenshell.entity_instance) -> None:
|
def expand_cost_item(cls, cost_item_id: int) -> None:
|
||||||
props = cls.get_cost_props()
|
props = cls.get_cost_props()
|
||||||
if not hasattr(cls, "contracted_cost_items"):
|
if not hasattr(cls, "contracted_cost_items"):
|
||||||
cls.contracted_cost_items = json.loads(props.contracted_cost_items)
|
cls.contracted_cost_items = json.loads(props.contracted_cost_items)
|
||||||
if cost_item.id() in cls.contracted_cost_items:
|
if cost_item_id in cls.contracted_cost_items:
|
||||||
cls.contracted_cost_items.remove(cost_item.id())
|
cls.contracted_cost_items.remove(cost_item_id)
|
||||||
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -187,11 +189,11 @@ class Cost(bonsai.core.tool.Cost):
|
|||||||
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def contract_cost_item(cls, cost_item: ifcopenshell.entity_instance) -> None:
|
def contract_cost_item(cls, cost_item_id: int) -> None:
|
||||||
props = cls.get_cost_props()
|
props = cls.get_cost_props()
|
||||||
if not hasattr(cls, "contracted_cost_items"):
|
if not hasattr(cls, "contracted_cost_items"):
|
||||||
cls.contracted_cost_items = json.loads(props.contracted_cost_items)
|
cls.contracted_cost_items = json.loads(props.contracted_cost_items)
|
||||||
cls.contracted_cost_items.append(cost_item.id())
|
cls.contracted_cost_items.append(cost_item_id)
|
||||||
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
props.contracted_cost_items = json.dumps(cls.contracted_cost_items)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -669,18 +671,19 @@ class Cost(bonsai.core.tool.Cost):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def expand_cost_item_rate(cls, cost_item_id: int) -> None:
|
def expand_cost_item_rate(cls, cost_item_id: int) -> None:
|
||||||
props = cls.get_cost_props()
|
props = cls.get_cost_props()
|
||||||
contracted_cost_item_rates = json.loads(props.contracted_cost_item_rates)
|
if not hasattr(cls, "contracted_cost_item_rates"):
|
||||||
contracted_cost_item_rates.remove(cost_item_id)
|
cls.contracted_cost_item_rates = json.loads(props.contracted_cost_item_rates)
|
||||||
props.contracted_cost_item_rates = json.dumps(contracted_cost_item_rates)
|
if cost_item_id in cls.contracted_cost_item_rates:
|
||||||
cls.load_schedule_of_rates_tree(schedule_of_rates=tool.Ifc.get().by_id(int(props.schedule_of_rates)))
|
cls.contracted_cost_item_rates.remove(cost_item_id)
|
||||||
|
props.contracted_cost_item_rates = json.dumps(cls.contracted_cost_item_rates)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def contract_cost_item_rate(cls, cost_item_id: int) -> None:
|
def contract_cost_item_rate(cls, cost_item_id: int) -> None:
|
||||||
props = cls.get_cost_props()
|
props = cls.get_cost_props()
|
||||||
contracted_cost_item_rates = json.loads(props.contracted_cost_item_rates)
|
if not hasattr(cls, "contracted_cost_item_rates"):
|
||||||
contracted_cost_item_rates.append(cost_item_id)
|
cls.contracted_cost_item_rates = json.loads(props.contracted_cost_item_rates)
|
||||||
props.contracted_cost_item_rates = json.dumps(contracted_cost_item_rates)
|
cls.contracted_cost_item_rates.append(cost_item_id)
|
||||||
cls.load_schedule_of_rates_tree(schedule_of_rates=tool.Ifc.get().by_id(int(props.schedule_of_rates)))
|
props.contracted_cost_item_rates = json.dumps(cls.contracted_cost_item_rates)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_new_cost_item_li(
|
def create_new_cost_item_li(
|
||||||
|
|||||||
Reference in New Issue
Block a user