clean up from developer's feedback + black formatting

This commit is contained in:
falken10
2025-07-03 00:05:13 +02:00
committed by Massimo Fabbro
parent b59bdb585b
commit 3055dfa1a6
6 changed files with 13 additions and 35 deletions
+1 -1
View File
@@ -76,7 +76,7 @@ class CostSchedulesData:
filepaths[schedule_id] = reference.Location filepaths[schedule_id] = reference.Location
except ValueError: except ValueError:
pass pass
return filepaths return filepaths
@classmethod @classmethod
+7 -12
View File
@@ -25,7 +25,6 @@ import bonsai.tool as tool
from bpy_extras.io_utils import ImportHelper, ExportHelper from bpy_extras.io_utils import ImportHelper, ExportHelper
import bonsai.tool as tool import bonsai.tool as tool
import bonsai.core.cost as core import bonsai.core.cost as core
from bonsai.bim.module.cost.data import CostSchedulesData
from pathlib import Path from pathlib import Path
from typing import get_args, TYPE_CHECKING, Literal from typing import get_args, TYPE_CHECKING, Literal
@@ -103,7 +102,6 @@ class EnableEditingCostItems(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
core.enable_editing_cost_items(tool.Cost, cost_schedule=tool.Ifc.get().by_id(self.cost_schedule)) core.enable_editing_cost_items(tool.Cost, cost_schedule=tool.Ifc.get().by_id(self.cost_schedule))
CostSchedulesData.is_loaded = False
class DisableEditingCostSchedule(bpy.types.Operator, tool.Ifc.Operator): class DisableEditingCostSchedule(bpy.types.Operator, tool.Ifc.Operator):
@@ -569,30 +567,29 @@ class ImportCostScheduleCsv(bpy.types.Operator, ImportHelper, tool.Ifc.Operator)
return True return True
def _execute(self, context): def _execute(self, context):
store_path = self.filepath store_path = self.filepath
if self.use_relative_path: if self.use_relative_path:
store_path = tool.Ifc.get_uri(self.filepath, use_relative_path=True) store_path = tool.Ifc.get_uri(self.filepath, use_relative_path=True)
resolved_path = Path(tool.Ifc.resolve_uri(self.filepath)) resolved_path = Path(tool.Ifc.resolve_uri(self.filepath))
if not resolved_path.exists(): if not resolved_path.exists():
self.report({"ERROR"}, f"File does not exist: '{store_path}' (resolved to '{resolved_path}')") self.report({"ERROR"}, f"File does not exist: '{store_path}' (resolved to '{resolved_path}')")
return {"CANCELLED"} return {"CANCELLED"}
cost_schedule = core.import_cost_schedule_csv(tool.Cost, str(resolved_path), self.is_schedule_of_rates) cost_schedule = core.import_cost_schedule_csv(tool.Cost, str(resolved_path), self.is_schedule_of_rates)
if cost_schedule: if cost_schedule:
core.add_csv_filepath(tool.Cost, store_path, self.is_schedule_of_rates, cost_schedule) core.add_csv_filepath(tool.Cost, store_path, self.is_schedule_of_rates, cost_schedule)
CostSchedulesData.is_loaded = False
return {"FINISHED"} return {"FINISHED"}
return {"CANCELLED"} return {"CANCELLED"}
def draw(self, context): def draw(self, context):
row = self.layout.row() row = self.layout.row()
row.prop(self, "is_schedule_of_rates") row.prop(self, "is_schedule_of_rates")
row = self.layout.row() row = self.layout.row()
row.prop(self, "use_relative_path") row.prop(self, "use_relative_path")
class RefreshCostScheduleCsv(bpy.types.Operator, tool.Ifc.Operator): class RefreshCostScheduleCsv(bpy.types.Operator, tool.Ifc.Operator):
bl_idname = "bim.refresh_cost_schedule_csv" bl_idname = "bim.refresh_cost_schedule_csv"
bl_label = "Refresh Cost Schedule CSV" bl_label = "Refresh Cost Schedule CSV"
@@ -605,18 +602,16 @@ class RefreshCostScheduleCsv(bpy.types.Operator, tool.Ifc.Operator):
if not props.active_cost_schedule_id: if not props.active_cost_schedule_id:
cls.poll_message_set("No active cost schedule") cls.poll_message_set("No active cost schedule")
return False return False
file_path = tool.Cost.get_cost_schedule_csv_filepath(props.active_cost_schedule_id) file_path = tool.Cost.get_cost_schedule_csv_filepath(props.active_cost_schedule_id)
if not file_path: if not file_path:
cls.poll_message_set("No CSV file associated with this cost schedule") cls.poll_message_set("No CSV file associated with this cost schedule")
return False return False
return True return True
def _execute(self, context): def _execute(self, context):
core.refresh_cost_schedule_csv(tool.Cost) core.refresh_cost_schedule_csv(tool.Cost)
CostSchedulesData.is_loaded = False
return {"FINISHED"} return {"FINISHED"}
@@ -174,6 +174,7 @@ class CostItemQuantity(PropertyGroup):
unit_symbol: str unit_symbol: str
total_cost_quantity: float total_cost_quantity: float
class CostItemType(PropertyGroup): class CostItemType(PropertyGroup):
name: StringProperty(name="Name") name: StringProperty(name="Name")
ifc_definition_id: IntProperty(name="IFC Definition ID") ifc_definition_id: IntProperty(name="IFC Definition ID")
+2 -2
View File
@@ -76,10 +76,10 @@ class BIM_PT_cost_schedules(Panel):
col = row0.column() col = row0.column()
col.label(text="Linked CSV:") col.label(text="Linked CSV:")
row_1 = col.row(align=True) row_1 = col.row(align=True)
csv_filepaths = CostSchedulesData.data["csv_filepaths"] csv_filepaths = CostSchedulesData.data["csv_filepaths"]
file_path = csv_filepaths.get(self.props.active_cost_schedule_id) file_path = csv_filepaths.get(self.props.active_cost_schedule_id)
if file_path: if file_path:
row_1.label(text=file_path) row_1.label(text=file_path)
row_1.operator("bim.refresh_cost_schedule_csv", icon="FILE_REFRESH", text="") row_1.operator("bim.refresh_cost_schedule_csv", icon="FILE_REFRESH", text="")
-15
View File
@@ -18,8 +18,6 @@
from __future__ import annotations from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Union, Literal from typing import TYPE_CHECKING, Optional, Union, Literal
import os
from bonsai.bim.module.cost.data import CostSchedulesData
if TYPE_CHECKING: if TYPE_CHECKING:
import bpy import bpy
@@ -345,7 +343,6 @@ def import_cost_schedule_csv(
cost: type[tool.Cost], resolved_path: str, is_schedule_of_rates: bool cost: type[tool.Cost], resolved_path: str, is_schedule_of_rates: bool
) -> ifcopenshell.entity_instance: ) -> ifcopenshell.entity_instance:
cost_schedule = cost.import_cost_schedule_csv(resolved_path, is_schedule_of_rates) cost_schedule = cost.import_cost_schedule_csv(resolved_path, is_schedule_of_rates)
return cost_schedule return cost_schedule
@@ -359,16 +356,10 @@ def remove_csv_filepath(cost: type[tool.Cost], cost_schedule) -> None:
def refresh_cost_schedule_csv(cost: type[tool.Cost]) -> Optional[str]: def refresh_cost_schedule_csv(cost: type[tool.Cost]) -> Optional[str]:
cost.delete_all_cost_items() cost.delete_all_cost_items()
cost.refresh_cost_schedule_csv() cost.refresh_cost_schedule_csv()
cost.load_cost_schedule_tree() cost.load_cost_schedule_tree()
CostSchedulesData.is_loaded = False
return None
def add_cost_column(cost: type[tool.Cost], name: str) -> None: def add_cost_column(cost: type[tool.Cost], name: str) -> None:
cost.add_cost_column(name) cost.add_cost_column(name)
@@ -470,9 +461,3 @@ def add_currency(ifc: type[tool.Ifc], cost: type[tool.Cost]) -> ifcopenshell.ent
def generate_cost_schedule_browser(cost: type[tool.Cost], cost_schedule: ifcopenshell.entity_instance) -> None: def generate_cost_schedule_browser(cost: type[tool.Cost], cost_schedule: ifcopenshell.entity_instance) -> None:
return cost.generate_cost_schedule_browser(cost_schedule) return cost.generate_cost_schedule_browser(cost_schedule)
+2 -5
View File
@@ -603,12 +603,12 @@ class Cost(bonsai.core.tool.Cost):
), ),
None, None,
) )
if not cost_docs_document: if not cost_docs_document:
cost_docs_document = ifcopenshell.api.document.add_information(ifc_file) cost_docs_document = ifcopenshell.api.document.add_information(ifc_file)
cost_docs_document.Name = "BBIM_Cost_Documents" cost_docs_document.Name = "BBIM_Cost_Documents"
cost_docs_document.Description = "Bonsai internal document containing references to cost CSV files" cost_docs_document.Description = "Bonsai internal document containing references to cost CSV files"
return cost_docs_document return cost_docs_document
@classmethod @classmethod
@@ -1097,6 +1097,3 @@ class Cost(bonsai.core.tool.Cost):
if results["quantity_type"] == "IfcQuantityCount": if results["quantity_type"] == "IfcQuantityCount":
results["unit_symbol"] = "U" results["unit_symbol"] = "U"
return results return results