Fix #2286. Classifications can now be added for cost items.

This commit is contained in:
Dion Moult
2022-09-03 17:11:14 +10:00
parent b9cb1ab012
commit 5d4512033d
8 changed files with 111 additions and 0 deletions
+4
View File
@@ -148,6 +148,10 @@ def get_obj_ifc_definition_id(context, obj, obj_type):
return context.scene.BIMTaskTreeProperties.tasks[ return context.scene.BIMTaskTreeProperties.tasks[
context.scene.BIMWorkScheduleProperties.active_task_index context.scene.BIMWorkScheduleProperties.active_task_index
].ifc_definition_id ].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": elif obj_type == "Resource":
return context.scene.BIMResourceTreeProperties.resources[ return context.scene.BIMResourceTreeProperties.resources[
context.scene.BIMResourceProperties.active_resource_index context.scene.BIMResourceProperties.active_resource_index
@@ -39,6 +39,7 @@ classes = (
ui.BIM_PT_classifications, ui.BIM_PT_classifications,
ui.BIM_PT_classification_references, ui.BIM_PT_classification_references,
ui.BIM_PT_material_classifications, ui.BIM_PT_material_classifications,
ui.BIM_PT_cost_classifications,
ui.BIM_UL_classifications, ui.BIM_UL_classifications,
) )
@@ -28,6 +28,7 @@ def refresh():
ClassificationsData.is_loaded = False ClassificationsData.is_loaded = False
ClassificationReferencesData.is_loaded = False ClassificationReferencesData.is_loaded = False
MaterialClassificationsData.is_loaded = False MaterialClassificationsData.is_loaded = False
CostClassificationsData.is_loaded = False
class ClassificationsData: class ClassificationsData:
@@ -114,3 +115,27 @@ class MaterialClassificationsData(ReferencesData):
del data["ReferencedSource"] del data["ReferencedSource"]
results.append(data) results.append(data)
return results 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
@@ -25,6 +25,7 @@ from blenderbim.bim.module.classification.data import (
ClassificationsData, ClassificationsData,
ClassificationReferencesData, ClassificationReferencesData,
MaterialClassificationsData, MaterialClassificationsData,
CostClassificationsData,
) )
@@ -200,6 +201,30 @@ class BIM_PT_material_classifications(Panel, ReferenceUI):
self.draw_ui(context) 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): class BIM_UL_classifications(UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname): def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
if item: if item:
@@ -19,6 +19,7 @@
import bpy import bpy
import ifcopenshell.api import ifcopenshell.api
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.classification.data import CostClassificationsData
from ifcopenshell.api.cost.data import Data from ifcopenshell.api.cost.data import Data
from ifcopenshell.api.pset.data import Data as PsetData from ifcopenshell.api.pset.data import Data as PsetData
from blenderbim.bim.prop import StrProperty, Attribute 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() bpy.ops.bim.load_cost_item_types()
else: else:
bpy.ops.bim.load_cost_item_quantities() bpy.ops.bim.load_cost_item_quantities()
CostClassificationsData.load()
def update_cost_item_identification(self, context): def update_cost_item_identification(self, context):
+1
View File
@@ -6,6 +6,7 @@ markers =
brick brick
classification classification
context context
cost
debug debug
demo demo
document document
@@ -216,3 +216,34 @@ Scenario: Remove classification reference - material
And I press "bim.add_classification_reference(reference={reference}, obj='Material', obj_type='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')" When I press "bim.remove_classification_reference(reference={reference}, obj='Material', obj_type='Material')"
Then nothing happens 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
@@ -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