From 5f29379a6de42772de4b28e508283d1b43a3ffd4 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 12 Sep 2021 15:42:59 +1000 Subject: [PATCH] You can now unload a partially loaded project --- .../blenderbim/bim/module/project/__init__.py | 1 + .../blenderbim/bim/module/project/operator.py | 12 ++++++++++++ src/blenderbim/blenderbim/bim/module/project/ui.py | 3 ++- src/blenderbim/test/bim/bootstrap.py | 7 +++++++ .../test/bim/module/project/test_operator.py | 10 ++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/bim/module/project/__init__.py b/src/blenderbim/blenderbim/bim/module/project/__init__.py index 5fb2b055bf..d5401a8d2e 100644 --- a/src/blenderbim/blenderbim/bim/module/project/__init__.py +++ b/src/blenderbim/blenderbim/bim/module/project/__init__.py @@ -22,6 +22,7 @@ from . import ui, prop, operator classes = ( operator.CreateProject, operator.LoadProject, + operator.UnloadProject, operator.LoadProjectElements, operator.SelectLibraryFile, operator.ChangeLibraryElement, diff --git a/src/blenderbim/blenderbim/bim/module/project/operator.py b/src/blenderbim/blenderbim/bim/module/project/operator.py index a11f106cc4..6c47fd84e7 100644 --- a/src/blenderbim/blenderbim/bim/module/project/operator.py +++ b/src/blenderbim/blenderbim/bim/module/project/operator.py @@ -524,6 +524,18 @@ class LoadProject(bpy.types.Operator): return {"RUNNING_MODAL"} +class UnloadProject(bpy.types.Operator): + bl_idname = "bim.unload_project" + bl_label = "Unload Project" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + IfcStore.purge() + context.scene.BIMProperties.ifc_file = "" + context.scene.BIMProjectProperties.is_loading = False + return {"FINISHED"} + + class LoadProjectElements(bpy.types.Operator): bl_idname = "bim.load_project_elements" bl_label = "Load Project Elements" diff --git a/src/blenderbim/blenderbim/bim/module/project/ui.py b/src/blenderbim/blenderbim/bim/module/project/ui.py index 5592af5df1..f29ae76b4b 100644 --- a/src/blenderbim/blenderbim/bim/module/project/ui.py +++ b/src/blenderbim/blenderbim/bim/module/project/ui.py @@ -56,8 +56,9 @@ class BIM_PT_project(Panel): pprops, "active_filter_category_index", ) - row = self.layout.row() + row = self.layout.row(align=True) row.operator("bim.load_project_elements") + row.operator("bim.unload_project", text="", icon="CANCEL") def draw_project_ui(self, context): props = context.scene.BIMProperties diff --git a/src/blenderbim/test/bim/bootstrap.py b/src/blenderbim/test/bim/bootstrap.py index b385f25ce2..2177bbd9dc 100644 --- a/src/blenderbim/test/bim/bootstrap.py +++ b/src/blenderbim/test/bim/bootstrap.py @@ -129,6 +129,12 @@ def an_ifc_file_exists(): return ifc +def an_ifc_file_does_not_exist(): + ifc = IfcStore.get_file() + if ifc: + assert False, "An IFC is available" + + def the_object_name_does_not_exist(name): assert bpy.data.objects.get(name) is None, "Object exists" @@ -255,6 +261,7 @@ definitions = { 'the object "(.*)" is in the collection "(.*)"': the_object_name_is_in_the_collection_collection, 'the collection "(.*)" is in the collection "(.*)"': the_collection_name1_is_in_the_collection_name2, "an IFC file exists": an_ifc_file_exists, + "an IFC file does not exist": an_ifc_file_does_not_exist, 'the object "(.*)" has a "(.*)" representation of "(.*)"': the_object_name_has_a_type_representation_of_context, 'the object "(.*)" is placed in the collection "(.*)"': the_object_name_is_placed_in_the_collection_collection, 'the object "(.*)" is contained in "(.*)"': the_object_name_is_contained_in_container_name, diff --git a/src/blenderbim/test/bim/module/project/test_operator.py b/src/blenderbim/test/bim/module/project/test_operator.py index 187e32dbc9..d086df6197 100644 --- a/src/blenderbim/test/bim/module/project/test_operator.py +++ b/src/blenderbim/test/bim/module/project/test_operator.py @@ -94,3 +94,13 @@ class TestLoadProjectElements(test.bim.bootstrap.NewFile): And the object "IfcBuildingStorey/Level 1" does not exist And the object "IfcWall/Wall" does not exist """ + +class TestUnloadProject(test.bim.bootstrap.NewFile): + @test.bim.bootstrap.scenario + def test_unloading_a_project(self): + return """ + When I press "bim.load_project(filepath='{cwd}/test/files/basic.ifc')" + And I press "bim.unload_project" + Then an IFC file does not exist + And "scene.BIMProjectProperties.is_loading" is "False" + """