From ffa3aae132301cd32b216b315be1f9f208ef1cb7 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 2 Sep 2022 15:21:21 +1000 Subject: [PATCH] Fix UI bug where changing classification levels sometimes didn't display --- .../bim/module/classification/operator.py | 1 + .../bim/module/classification/ui.py | 9 +- .../test/bim/feature/classification.feature | 187 ++++++++++++++++++ .../test/bim/feature/project.feature | 14 ++ src/blenderbim/test/bim/test_feature.py | 18 +- src/blenderbim/test/files/classification.ifc | 18 ++ 6 files changed, 242 insertions(+), 5 deletions(-) create mode 100644 src/blenderbim/test/bim/feature/classification.feature create mode 100644 src/blenderbim/test/files/classification.ifc diff --git a/src/blenderbim/blenderbim/bim/module/classification/operator.py b/src/blenderbim/blenderbim/bim/module/classification/operator.py index 021078842c..b0617b7370 100644 --- a/src/blenderbim/blenderbim/bim/module/classification/operator.py +++ b/src/blenderbim/blenderbim/bim/module/classification/operator.py @@ -258,3 +258,4 @@ class DisableEditingClassificationReferences(bpy.types.Operator): def execute(self, context): props = context.scene.BIMClassificationProperties props.available_library_references.clear() + return {"FINISHED"} diff --git a/src/blenderbim/blenderbim/bim/module/classification/ui.py b/src/blenderbim/blenderbim/bim/module/classification/ui.py index 5c1ae86b7d..77c7ed2764 100644 --- a/src/blenderbim/blenderbim/bim/module/classification/ui.py +++ b/src/blenderbim/blenderbim/bim/module/classification/ui.py @@ -123,10 +123,11 @@ class BIM_PT_classification_references(Panel): if self.sprops.active_library_referenced_source: op = row.operator("bim.change_classification_level", text="", icon="FRAME_PREV") op.parent_id = self.sprops.active_library_referenced_source - op = row.operator("bim.add_classification_reference", text="", icon="ADD") - op.reference = self.sprops.available_library_references[ - self.sprops.active_library_reference_index - ].ifc_definition_id + if self.sprops.active_library_reference_index < len(self.sprops.available_library_references): + op = row.operator("bim.add_classification_reference", text="", icon="ADD") + op.reference = self.sprops.available_library_references[ + self.sprops.active_library_reference_index + ].ifc_definition_id row.operator("bim.disable_editing_classification_references", text="", icon="CANCEL") self.layout.template_list( "BIM_UL_classifications", diff --git a/src/blenderbim/test/bim/feature/classification.feature b/src/blenderbim/test/bim/feature/classification.feature new file mode 100644 index 0000000000..d77d87184a --- /dev/null +++ b/src/blenderbim/test/bim/feature/classification.feature @@ -0,0 +1,187 @@ +@classification +Feature: Classification + +Scenario: Load classification library + Given an empty IFC project + When I press "bim.load_classification_library(filepath='{cwd}/test/files/classification.ifc')" + Then nothing happens + +Scenario: Add classification + 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}" + When I press "bim.add_classification" + Then nothing happens + +Scenario: Add classification - IFC2X3 + Given an empty IFC2X3 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}" + When I press "bim.add_classification" + Then nothing happens + +Scenario: Enable editing classification + 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 the variable "classification" is "{ifc}.by_type('IfcClassification')[0].id()" + When I press "bim.enable_editing_classification(classification={classification})" + Then nothing happens + +Scenario: Disable editing classification + 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 the variable "classification" is "{ifc}.by_type('IfcClassification')[0].id()" + And I press "bim.enable_editing_classification(classification={classification})" + When I press "bim.disable_editing_classification" + Then nothing happens + +Scenario: Remove classification + 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 the variable "classification" is "{ifc}.by_type('IfcClassification')[0].id()" + When I press "bim.remove_classification(classification={classification})" + Then nothing happens + +Scenario: Edit classification + 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 the variable "classification" is "{ifc}.by_type('IfcClassification')[0].id()" + And I press "bim.enable_editing_classification(classification={classification})" + When I press "bim.edit_classification" + Then nothing happens + +Scenario: Add classification reference + 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 add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + 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})" + Then nothing happens + +Scenario: Change classification level + 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 add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + 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.change_classification_level(parent_id={reference})" + Then nothing happens + +Scenario: Disable editing classification references + 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 add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + And I press "bim.change_classification_level(parent_id={classification})" + When I press "bim.disable_editing_classification_references" + Then nothing happens + +Scenario: Enable editing classification reference + 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 add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + 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})" + And the variable "reference" is "{ifc}.by_type('IfcClassificationReference')[0].id()" + When I press "bim.enable_editing_classification_reference(reference={reference})" + Then nothing happens + +Scenario: Disable editing classification reference + 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 add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + 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})" + And the variable "reference" is "{ifc}.by_type('IfcClassificationReference')[0].id()" + And I press "bim.enable_editing_classification_reference(reference={reference})" + When I press "bim.disable_editing_classification_reference" + Then nothing happens + +Scenario: Remove classification reference + 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 add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + 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})" + And the variable "reference" is "{ifc}.by_type('IfcClassificationReference')[0].id()" + And I press "bim.enable_editing_classification_reference(reference={reference})" + When I press "bim.remove_classification_reference(reference={reference})" + Then nothing happens + +Scenario: Edit classification reference + 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 add a cube + And the object "Cube" is selected + And I set "scene.BIMRootProperties.ifc_product" to "IfcElementType" + And I set "scene.BIMRootProperties.ifc_class" to "IfcWallType" + And I press "bim.assign_class" + 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})" + And the variable "reference" is "{ifc}.by_type('IfcClassificationReference')[0].id()" + And I press "bim.enable_editing_classification_reference(reference={reference})" + When I press "bim.edit_classification_reference" + Then nothing happens diff --git a/src/blenderbim/test/bim/feature/project.feature b/src/blenderbim/test/bim/feature/project.feature index c5c05672af..efe3a539e1 100644 --- a/src/blenderbim/test/bim/feature/project.feature +++ b/src/blenderbim/test/bim/feature/project.feature @@ -14,6 +14,20 @@ Scenario: Create project And the object "IfcBuilding/My Building" is in the collection "IfcBuilding/My Building" And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" +Scenario: Create project - IFC2X3 + Given an empty Blender session + And I set "scene.BIMProjectProperties.export_schema" to "IFC2X3" + When I press "bim.create_project" + Then an IFC file exists + And the object "IfcProject/My Project" is an "IfcProject" + And the object "IfcSite/My Site" is an "IfcSite" + And the object "IfcBuilding/My Building" is an "IfcBuilding" + And the object "IfcBuildingStorey/My Storey" is an "IfcBuildingStorey" + And the object "IfcProject/My Project" is in the collection "IfcProject/My Project" + And the object "IfcSite/My Site" is in the collection "IfcSite/My Site" + And the object "IfcBuilding/My Building" is in the collection "IfcBuilding/My Building" + And the object "IfcBuildingStorey/My Storey" is in the collection "IfcBuildingStorey/My Storey" + Scenario: Append library element Given an empty IFC project When I press "bim.select_library_file(filepath='{cwd}/test/files/basic.ifc')" diff --git a/src/blenderbim/test/bim/test_feature.py b/src/blenderbim/test/bim/test_feature.py index edd1046a7e..0050024908 100644 --- a/src/blenderbim/test/bim/test_feature.py +++ b/src/blenderbim/test/bim/test_feature.py @@ -29,7 +29,12 @@ from mathutils import Vector scenarios("feature") -variables = {"cwd": os.getcwd(), "ifc": "IfcStore.get_file()", "pset_ifc": "IfcStore.pset_template_file"} +variables = { + "cwd": os.getcwd(), + "ifc": "IfcStore.get_file()", + "pset_ifc": "IfcStore.pset_template_file", + "classification_ifc": "IfcStore.classification_file", +} # Monkey-patch webbrowser opening since we want to test headlessly webbrowser.open = lambda x: True @@ -68,6 +73,17 @@ def an_empty_ifc_project(): bpy.ops.bim.create_project() +@given("an empty IFC2X3 project") +def an_empty_ifc_project(): + IfcStore.purge() + bpy.ops.wm.read_homefile(app_template="") + if len(bpy.data.objects) > 0: + bpy.data.batch_remove(bpy.data.objects) + bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True) + bpy.context.scene.BIMProjectProperties.export_schema = "IFC2X3" + bpy.ops.bim.create_project() + + @when("I load a new pset template file") def i_load_a_new_pset_template_file(): IfcStore.pset_template_path = os.path.join( diff --git a/src/blenderbim/test/files/classification.ifc b/src/blenderbim/test/files/classification.ifc new file mode 100644 index 0000000000..c038dae910 --- /dev/null +++ b/src/blenderbim/test/files/classification.ifc @@ -0,0 +1,18 @@ +ISO-10303-21; +HEADER; +FILE_DESCRIPTION(('ViewDefinition [CoordinationView]'),'2;1'); +FILE_NAME('','2020-04-23T18:09:33',(),(),'IfcOpenShell 0.6.0b0','IfcOpenShell 0.6.0b0',''); +FILE_SCHEMA(('IFC4')); +ENDSEC; +DATA; +#1=IFCPROJECTLIBRARY($,$,'FoobarClass',$,$,$,$,$,$); +#2=IFCCLASSIFICATION('FoobarClass','(FBC)','2000-01-01','Foobar','The Foobar Classification System is a classification system for the construction industry.','http://www.example.org/',('_')); +#3=IFCRELASSOCIATESCLASSIFICATION('1qt9lErCr5hQsihRukSfaU',$,$,$,(#1),#2); +#4=IFCCLASSIFICATIONREFERENCE($,'Co','Complexes',#2,$,$); +#5=IFCCLASSIFICATIONREFERENCE($,'Co_20','Administrative, commercial and protective service complexes',#4,$,$); +#6=IFCCLASSIFICATIONREFERENCE($,'Co_20_10','Legislative complexes',#5,$,$); +#7=IFCCLASSIFICATIONREFERENCE($,'Pr','Products',#2,$,$); +#8=IFCCLASSIFICATIONREFERENCE($,'Pr_15','Preparatory products',#7,$,$); +#9=IFCCLASSIFICATIONREFERENCE($,'Pr_15_31','Formless preparatory products',#8,$,$); +ENDSEC; +END-ISO-10303-21;