mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
fix linked ifc visibility toggle tests
This commit is contained in:
@@ -1063,17 +1063,9 @@ class ToggleLinkVisibility(bpy.types.Operator):
|
||||
|
||||
def toggle_visibility(self, link):
|
||||
linked_collections = self.get_linked_collections()
|
||||
queue = [bpy.context.view_layer.layer_collection]
|
||||
layer_collection = None
|
||||
|
||||
while queue:
|
||||
layer = queue.pop()
|
||||
if layer.collection in linked_collections:
|
||||
layer_collection = layer
|
||||
break
|
||||
queue.extend(list(layer.children))
|
||||
|
||||
if layer_collection:
|
||||
layer_collections = tool.Blender.get_layer_collections_mapping(linked_collections)
|
||||
for layer_collection in layer_collections.values():
|
||||
layer_collection.exclude = not layer_collection.exclude
|
||||
link.is_hidden = layer_collection.exclude
|
||||
|
||||
|
||||
@@ -648,6 +648,35 @@ class Blender(blenderbim.core.tool.Blender):
|
||||
open_file_or_folder(filepath.as_posix())
|
||||
return {"PASS_THROUGH"}
|
||||
|
||||
@classmethod
|
||||
def get_layer_collection(
|
||||
cls, collection: bpy.types.Collection, view_layer: Optional[bpy.types.ViewLayer] = None
|
||||
) -> Union[bpy.types.LayerCollection, None]:
|
||||
return cls.get_layer_collections_mapping([collection], view_layer).get(collection)
|
||||
|
||||
@classmethod
|
||||
def get_layer_collections_mapping(
|
||||
cls, collections: list[bpy.types.Collection], view_layer: Optional[bpy.types.ViewLayer] = None
|
||||
) -> dict[bpy.types.Collection, bpy.types.LayerCollection]:
|
||||
if view_layer is None:
|
||||
view_layer = bpy.context.view_layer
|
||||
|
||||
collections = list(collections) # copy to prevent mutation
|
||||
collections_mapping = dict()
|
||||
queue = [view_layer.layer_collection]
|
||||
|
||||
while queue:
|
||||
layer = queue.pop()
|
||||
collection = layer.collection
|
||||
if collection in collections:
|
||||
collections_mapping[collection] = layer
|
||||
collections.remove(collection)
|
||||
if not collections:
|
||||
break
|
||||
queue.extend(list(layer.children))
|
||||
|
||||
return collections_mapping
|
||||
|
||||
class Modifier:
|
||||
@classmethod
|
||||
def is_eligible_for_railing_modifier(cls, obj):
|
||||
|
||||
@@ -331,9 +331,13 @@ Scenario: Toggle link visibility - wireframe mode
|
||||
|
||||
Scenario: Toggle link visibility - visible mode
|
||||
Given an empty IFC project
|
||||
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.blend')"
|
||||
When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.blend', mode='VISIBLE')"
|
||||
Then nothing happens
|
||||
And I press "bim.link_ifc(filepath='{cwd}/test/files/basic.ifc')"
|
||||
When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='VISIBLE')"
|
||||
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_hidden" is "True"
|
||||
And the collection "IfcProject/basic.ifc" exclude status is "True"
|
||||
When I press "bim.toggle_link_visibility(link='{cwd}/test/files/basic.ifc', mode='VISIBLE')"
|
||||
Then "scene.BIMProjectProperties.links['{cwd}/test/files/basic.ifc'].is_hidden" is "False"
|
||||
And the collection "IfcProject/basic.ifc" exclude status is "False"
|
||||
|
||||
Scenario: Unload link
|
||||
Given an empty Blender session
|
||||
|
||||
@@ -397,6 +397,21 @@ def the_collection_name_exists(name) -> bpy.types.Collection:
|
||||
return obj
|
||||
|
||||
|
||||
@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)
|
||||
layer = tool.Blender.get_layer_collection(col)
|
||||
if not layer:
|
||||
assert False, f'The collection "{name}" is not present in the current viewlayer'
|
||||
return layer
|
||||
|
||||
|
||||
@then(parsers.parse('the collection "{name}" exclude status is "{exclude}"'))
|
||||
def the_collection_exclude_status_is(name: str, exclude: str) -> None:
|
||||
layer = the_collection_exists_in_viewlayer(name)
|
||||
assert layer.exclude == (exclude == "True")
|
||||
|
||||
|
||||
@then(parsers.parse('the object "{name1}" and "{name2}" are different elements'))
|
||||
def the_object_name1_and_name2_are_different_elements(name1, name2):
|
||||
ifc = an_ifc_file_exists()
|
||||
|
||||
Reference in New Issue
Block a user