From 1a449905f44be92beebfdd57649d1bea9ce82a05 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 25 Mar 2024 13:57:29 +0500 Subject: [PATCH] fix linked ifc selectability toggle --- .../blenderbim/bim/module/project/operator.py | 12 ++++++------ src/blenderbim/test/bim/feature/project.feature | 10 ++++++++++ src/blenderbim/test/bim/test_feature.py | 12 ++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/project/operator.py b/src/blenderbim/blenderbim/bim/module/project/operator.py index 8dc58c4651..0681664800 100644 --- a/src/blenderbim/blenderbim/bim/module/project/operator.py +++ b/src/blenderbim/blenderbim/bim/module/project/operator.py @@ -1008,24 +1008,24 @@ class ToggleLinkSelectability(bpy.types.Operator): bl_label = "Toggle Link Selectability" bl_options = {"REGISTER", "UNDO"} bl_description = "Toggle selectability" - link: bpy.props.StringProperty() + link: bpy.props.StringProperty(name="Linked IFC Filepath") def execute(self, context): props = context.scene.BIMProjectProperties link = props.links.get(self.link) - self.filepath = self.link - if not os.path.isabs(self.filepath): - self.filepath = os.path.abspath(os.path.join(bpy.path.abspath("//"), self.filepath)).replace("\\", "/") + if not os.path.isabs(self.link): + self.link = os.path.abspath(os.path.join(bpy.path.abspath("//"), self.link)) + self.library_filepath = Path(self.link).with_suffix(".ifc.cache.blend") for collection in self.get_linked_collections(): collection.hide_select = not collection.hide_select link.is_selectable = not collection.hide_select return {"FINISHED"} - def get_linked_collections(self): + def get_linked_collections(self) -> list[bpy.types.Collection]: return [ c for c in bpy.data.collections - if "IfcProject" in c.name and c.library and c.library.filepath.replace("\\", "/") == self.filepath + if "IfcProject" in c.name and c.library and Path(c.library.filepath) == self.library_filepath ] diff --git a/src/blenderbim/test/bim/feature/project.feature b/src/blenderbim/test/bim/feature/project.feature index 0be34ba4fb..7433bcfd30 100644 --- a/src/blenderbim/test/bim/feature/project.feature +++ b/src/blenderbim/test/bim/feature/project.feature @@ -329,6 +329,16 @@ Scenario: Toggle link visibility - wireframe mode Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_wireframe" is "False" And the object "Chunk" should display as "TEXTURED" +Scenario: Toggle link selectability + Given an empty IFC project + And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')" + When I press "bim.toggle_link_selectability(link='{cwd}/test/files/basic.ifc')" + Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_selectable" is "False" + And the collection "IfcProject/basic.ifc" is unselectable + When I press "bim.toggle_link_selectability(link='{cwd}/test/files/basic.ifc')" + Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_selectable" is "True" + And the collection "IfcProject/basic.ifc" is selectable + Scenario: Toggle link visibility - visible mode Given an empty IFC project And I press "bim.link_ifc(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 e8ab73555c..07dbf89532 100644 --- a/src/blenderbim/test/bim/test_feature.py +++ b/src/blenderbim/test/bim/test_feature.py @@ -397,6 +397,18 @@ def the_collection_name_exists(name) -> bpy.types.Collection: return obj +@then(parsers.parse('the collection "{name}" is selectable')) +def the_collection_name_is_selectable(name: str) -> None: + col = the_collection_name_exists(name) + assert col.hide_select == False + + +@then(parsers.parse('the collection "{name}" is unselectable')) +def the_collection_name_is_unselectable(name: str) -> None: + col = the_collection_name_exists(name) + assert col.hide_select == True + + @then(parsers.parse('the collection "{name}" exists in viewlayer')) def the_collection_exists_in_viewlayer(name: str) -> bpy.types.LayerCollection: col = the_collection_name_exists(name)