diff --git a/src/blenderbim/blenderbim/bim/helper.py b/src/blenderbim/blenderbim/bim/helper.py index 557aca2eb9..4aa5231c1c 100644 --- a/src/blenderbim/blenderbim/bim/helper.py +++ b/src/blenderbim/blenderbim/bim/helper.py @@ -148,6 +148,10 @@ def get_obj_ifc_definition_id(context, obj, obj_type): return context.scene.BIMTaskTreeProperties.tasks[ context.scene.BIMWorkScheduleProperties.active_task_index ].ifc_definition_id + elif obj_type == "Cost": + return context.scene.BIMCostProperties.cost_items[ + context.scene.BIMCostProperties.active_cost_item_index + ].ifc_definition_id elif obj_type == "Resource": return context.scene.BIMResourceTreeProperties.resources[ context.scene.BIMResourceProperties.active_resource_index diff --git a/src/blenderbim/blenderbim/bim/module/classification/__init__.py b/src/blenderbim/blenderbim/bim/module/classification/__init__.py index db05b1e1a8..f5fdcaaaed 100644 --- a/src/blenderbim/blenderbim/bim/module/classification/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/classification/__init__.py @@ -39,6 +39,7 @@ classes = ( ui.BIM_PT_classifications, ui.BIM_PT_classification_references, ui.BIM_PT_material_classifications, + ui.BIM_PT_cost_classifications, ui.BIM_UL_classifications, ) diff --git a/src/blenderbim/blenderbim/bim/module/classification/data.py b/src/blenderbim/blenderbim/bim/module/classification/data.py index d9422109bf..6e12ecc83f 100644 --- a/src/blenderbim/blenderbim/bim/module/classification/data.py +++ b/src/blenderbim/blenderbim/bim/module/classification/data.py @@ -28,6 +28,7 @@ def refresh(): ClassificationsData.is_loaded = False ClassificationReferencesData.is_loaded = False MaterialClassificationsData.is_loaded = False + CostClassificationsData.is_loaded = False class ClassificationsData: @@ -114,3 +115,27 @@ class MaterialClassificationsData(ReferencesData): del data["ReferencedSource"] results.append(data) return results + + +class CostClassificationsData(ReferencesData): + data = {} + is_loaded = False + + @classmethod + def load(cls): + cls.is_loaded = True + cls.data["references"] = cls.references() + cls.data["is_available_classification_added"] = cls.is_available_classification_added() + + @classmethod + def references(cls): + results = [] + element = tool.Ifc.get().by_id(bpy.context.scene.BIMCostProperties.cost_items[ + bpy.context.scene.BIMCostProperties.active_cost_item_index + ].ifc_definition_id) + if element: + for reference in ifcopenshell.util.classification.get_references(element): + data = reference.get_info() + del data["ReferencedSource"] + results.append(data) + return results diff --git a/src/blenderbim/blenderbim/bim/module/classification/ui.py b/src/blenderbim/blenderbim/bim/module/classification/ui.py index d54867e012..b0c3cf5d18 100644 --- a/src/blenderbim/blenderbim/bim/module/classification/ui.py +++ b/src/blenderbim/blenderbim/bim/module/classification/ui.py @@ -25,6 +25,7 @@ from blenderbim.bim.module.classification.data import ( ClassificationsData, ClassificationReferencesData, MaterialClassificationsData, + CostClassificationsData, ) @@ -200,6 +201,30 @@ class BIM_PT_material_classifications(Panel, ReferenceUI): self.draw_ui(context) +class BIM_PT_cost_classifications(Panel, ReferenceUI): + bl_label = "IFC Cost Classifications" + bl_idname = "BIM_PT_cost_classifications" + bl_options = {"DEFAULT_CLOSED"} + bl_space_type = "PROPERTIES" + bl_region_type = "WINDOW" + bl_context = "scene" + bl_parent_id = "BIM_PT_cost_schedules" + + @classmethod + def poll(cls, context): + if not tool.Ifc.get(): + return False + return bool(context.scene.BIMCostProperties.cost_items) + + def draw(self, context): + if not CostClassificationsData.is_loaded: + CostClassificationsData.load() + self.data = CostClassificationsData + self.obj = "" + self.obj_type = "Cost" + self.draw_ui(context) + + class BIM_UL_classifications(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname): if item: diff --git a/src/blenderbim/blenderbim/bim/module/cost/prop.py b/src/blenderbim/blenderbim/bim/module/cost/prop.py index 69ac4f825f..9ed9dc65de 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/prop.py +++ b/src/blenderbim/blenderbim/bim/module/cost/prop.py @@ -19,6 +19,7 @@ import bpy import ifcopenshell.api from blenderbim.bim.ifc import IfcStore +from blenderbim.bim.module.classification.data import CostClassificationsData from ifcopenshell.api.cost.data import Data from ifcopenshell.api.pset.data import Data as PsetData from blenderbim.bim.prop import StrProperty, Attribute @@ -164,6 +165,7 @@ def update_active_cost_item_index(self, context): bpy.ops.bim.load_cost_item_types() else: bpy.ops.bim.load_cost_item_quantities() + CostClassificationsData.load() def update_cost_item_identification(self, context): diff --git a/src/blenderbim/pytest.ini b/src/blenderbim/pytest.ini index 7c45fa340d..dc9d7f02f6 100644 --- a/src/blenderbim/pytest.ini +++ b/src/blenderbim/pytest.ini @@ -6,6 +6,7 @@ markers = brick classification context + cost debug demo document diff --git a/src/blenderbim/test/bim/feature/classification.feature b/src/blenderbim/test/bim/feature/classification.feature index 16a270d987..48b5ae0dc0 100644 --- a/src/blenderbim/test/bim/feature/classification.feature +++ b/src/blenderbim/test/bim/feature/classification.feature @@ -216,3 +216,34 @@ Scenario: Remove classification reference - material And I press "bim.add_classification_reference(reference={reference}, obj='Material', obj_type='Material')" When I press "bim.remove_classification_reference(reference={reference}, obj='Material', obj_type='Material')" Then nothing happens + +Scenario: Add classification reference - cost + Given an empty IFC project + And I press "bim.load_classification_library(filepath='{cwd}/test/files/classification.ifc')" + And the variable "classification" is "{classification_ifc}.by_type('IfcClassification')[0].id()" + And I set "scene.BIMClassificationProperties.available_classifications" to "{classification}" + And I press "bim.add_classification" + And I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + And I press "bim.add_summary_cost_item(cost_schedule={cost_schedule})" + And I press "bim.change_classification_level(parent_id={classification})" + And the variable "reference" is "{classification_ifc}.by_type('IfcClassificationReference')[0].id()" + When I press "bim.add_classification_reference(reference={reference}, obj='', obj_type='Cost')" + Then nothing happens + +Scenario: Remove classification reference - cost + Given an empty IFC project + And I press "bim.load_classification_library(filepath='{cwd}/test/files/classification.ifc')" + And the variable "classification" is "{classification_ifc}.by_type('IfcClassification')[0].id()" + And I set "scene.BIMClassificationProperties.available_classifications" to "{classification}" + And I press "bim.add_classification" + And I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + And I press "bim.add_summary_cost_item(cost_schedule={cost_schedule})" + And I press "bim.change_classification_level(parent_id={classification})" + And the variable "reference" is "{classification_ifc}.by_type('IfcClassificationReference')[0].id()" + And I press "bim.add_classification_reference(reference={reference}, obj='', obj_type='Cost')" + When I press "bim.remove_classification_reference(reference={reference}, obj='', obj_type='Cost')" + Then nothing happens diff --git a/src/blenderbim/test/bim/feature/cost.feature b/src/blenderbim/test/bim/feature/cost.feature new file mode 100644 index 0000000000..c41d8157d1 --- /dev/null +++ b/src/blenderbim/test/bim/feature/cost.feature @@ -0,0 +1,22 @@ +@cost +Feature: Cost + +Scenario: Add cost schedule + Given an empty IFC project + When I press "bim.add_cost_schedule" + Then nothing happens + +Scenario: Enable editing cost items + Given an empty IFC project + When I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + Then nothing happens + +Scenario: Add summary cost item + Given an empty IFC project + When I press "bim.add_cost_schedule" + And the variable "cost_schedule" is "{ifc}.by_type('IfcCostSchedule')[0].id()" + And I press "bim.enable_editing_cost_items(cost_schedule={cost_schedule})" + And I press "bim.add_summary_cost_item(cost_schedule={cost_schedule})" + Then nothing happens