mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 11:53:44 +00:00
Fix set update in loop bug when trying to filter elements by spatial container
This commit is contained in:
@@ -281,9 +281,12 @@ class Spatial(bonsai.core.tool.Spatial):
|
|||||||
if props.should_include_children:
|
if props.should_include_children:
|
||||||
elements = ifcopenshell.util.element.get_decomposition(container, is_recursive=True)
|
elements = ifcopenshell.util.element.get_decomposition(container, is_recursive=True)
|
||||||
else:
|
else:
|
||||||
elements = set(ifcopenshell.util.element.get_contained(container))
|
queue = list(set(ifcopenshell.util.element.get_contained(container)))
|
||||||
for e in elements:
|
elements = set()
|
||||||
elements.update(ifcopenshell.util.element.get_decomposition(e))
|
while queue:
|
||||||
|
item = queue.pop()
|
||||||
|
elements.add(item)
|
||||||
|
queue.extend(ifcopenshell.util.element.get_decomposition(item))
|
||||||
for element in elements:
|
for element in elements:
|
||||||
if element.is_a("IfcOpeningElement") or tool.Root.is_spatial_element(element):
|
if element.is_a("IfcOpeningElement") or tool.Root.is_spatial_element(element):
|
||||||
continue
|
continue
|
||||||
@@ -1306,9 +1309,12 @@ class Spatial(bonsai.core.tool.Spatial):
|
|||||||
if props.should_include_children:
|
if props.should_include_children:
|
||||||
elements = ifcopenshell.util.element.get_decomposition(container, is_recursive=True)
|
elements = ifcopenshell.util.element.get_decomposition(container, is_recursive=True)
|
||||||
else:
|
else:
|
||||||
elements = set(ifcopenshell.util.element.get_contained(container))
|
queue = list(set(ifcopenshell.util.element.get_contained(container)))
|
||||||
for e in elements:
|
elements = set()
|
||||||
elements.update(ifcopenshell.util.element.get_decomposition(e))
|
while queue:
|
||||||
|
item = queue.pop()
|
||||||
|
elements.add(item)
|
||||||
|
queue.extend(ifcopenshell.util.element.get_decomposition(item))
|
||||||
if not element_filter:
|
if not element_filter:
|
||||||
return elements
|
return elements
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,45 @@
|
|||||||
Feature: Spatial
|
Feature: Spatial
|
||||||
Covers spatial containment management and spatial tool.
|
Covers spatial containment management and spatial tool.
|
||||||
|
|
||||||
|
Scenario: Set default container
|
||||||
|
Given an empty IFC project
|
||||||
|
When I look at the "Spatial Decomposition" panel
|
||||||
|
Then I see "My Site" in the "1st" list
|
||||||
|
And I see "Default: My Storey"
|
||||||
|
When I select the row where I see "My Building" in the "1st" list
|
||||||
|
And I click "Set Default"
|
||||||
|
Then I don't see "Default: My Storey"
|
||||||
|
And I see "Default: My Building"
|
||||||
|
|
||||||
|
Scenario: Select container
|
||||||
|
Given an empty IFC project
|
||||||
|
And I look at the "Spatial Decomposition" panel
|
||||||
|
When I select the row where I see "My Building" in the "1st" list
|
||||||
|
And I click "OBJECT_DATA"
|
||||||
|
Then the object "IfcBuilding/My Building" is selected
|
||||||
|
|
||||||
|
Scenario: View elements - view elements recursively in the project
|
||||||
|
Given an empty IFC project
|
||||||
|
And I load the demo construction library
|
||||||
|
And I set "scene.BIMModelProperties.ifc_class" to "IfcColumnType"
|
||||||
|
And I add the construction type
|
||||||
|
When I look at the "Spatial Decomposition" panel
|
||||||
|
And I select the row where I see "My Project" in the "1st" list
|
||||||
|
Then I see "IfcColumn" in the "2nd" list
|
||||||
|
|
||||||
|
Scenario: View elements - view elements non-recursively in their container
|
||||||
|
Given an empty IFC project
|
||||||
|
And I load the demo construction library
|
||||||
|
And I set "scene.BIMModelProperties.ifc_class" to "IfcColumnType"
|
||||||
|
And I add the construction type
|
||||||
|
When I look at the "Spatial Decomposition" panel
|
||||||
|
And I select the row where I see "My Project" in the "1st" list
|
||||||
|
And I click "OUTLINER"
|
||||||
|
Then there are "1" lists
|
||||||
|
And I see "No Elements"
|
||||||
|
And I select the row where I see "My Storey" in the "1st" list
|
||||||
|
Then I see "IfcColumn" in the "2nd" list
|
||||||
|
|
||||||
Scenario: Enable editing container
|
Scenario: Enable editing container
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I add a cube
|
And I add a cube
|
||||||
@@ -77,7 +116,7 @@ Scenario: Dereference structure
|
|||||||
And I press "bim.dereference_structure"
|
And I press "bim.dereference_structure"
|
||||||
Then nothing happens
|
Then nothing happens
|
||||||
|
|
||||||
Scenario: Select container
|
Scenario: Assign container
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I add a cube
|
And I add a cube
|
||||||
And the object "Cube" is selected
|
And the object "Cube" is selected
|
||||||
@@ -144,7 +183,7 @@ Scenario: Spatial decomposition - see panel
|
|||||||
Then the "BIM_UL_containers_manager" list has 4 items
|
Then the "BIM_UL_containers_manager" list has 4 items
|
||||||
And I don't see the "BIM_UL_elements" list
|
And I don't see the "BIM_UL_elements" list
|
||||||
|
|
||||||
Scenario: Isolate spatial container
|
Scenario: Set element visibility - Isolate spatial container
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I trigger "Add Element"
|
And I trigger "Add Element"
|
||||||
And I set the "Definition" property to "IfcElement"
|
And I set the "Definition" property to "IfcElement"
|
||||||
@@ -156,7 +195,7 @@ Scenario: Isolate spatial container
|
|||||||
And I click "FULLSCREEN_EXIT"
|
And I click "FULLSCREEN_EXIT"
|
||||||
Then nothing happens
|
Then nothing happens
|
||||||
|
|
||||||
Scenario: Show spatial container
|
Scenario: Set element visibility - Show spatial container
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I trigger "Add Element"
|
And I trigger "Add Element"
|
||||||
And I set the "Definition" property to "IfcElement"
|
And I set the "Definition" property to "IfcElement"
|
||||||
@@ -168,7 +207,7 @@ Scenario: Show spatial container
|
|||||||
And I click "HIDE_OFF"
|
And I click "HIDE_OFF"
|
||||||
Then nothing happens
|
Then nothing happens
|
||||||
|
|
||||||
Scenario: Hide spatial container
|
Scenario: Set element visibility - Hide spatial container
|
||||||
Given an empty IFC project
|
Given an empty IFC project
|
||||||
And I trigger "Add Element"
|
And I trigger "Add Element"
|
||||||
And I set the "Definition" property to "IfcElement"
|
And I set the "Definition" property to "IfcElement"
|
||||||
|
|||||||
@@ -355,6 +355,16 @@ def i_see_text(text):
|
|||||||
assert [l for l in panel_spy.spied_labels if text in l], f"Text {text} not found in {panel_spy.spied_labels}"
|
assert [l for l in panel_spy.spied_labels if text in l], f"Text {text} not found in {panel_spy.spied_labels}"
|
||||||
|
|
||||||
|
|
||||||
|
@given(parsers.parse('there are "{n}" lists'))
|
||||||
|
@when(parsers.parse('there are "{n}" lists'))
|
||||||
|
@then(parsers.parse('there are "{n}" lists'))
|
||||||
|
def there_are_n_lists(n):
|
||||||
|
assert panel_spy
|
||||||
|
panel_spy.refresh_spy()
|
||||||
|
if len(panel_spy.spied_lists) != int(n):
|
||||||
|
assert False, f"Actual number of lists {len(panel_spy.spied_lists)} not {n}"
|
||||||
|
|
||||||
|
|
||||||
@given(parsers.parse('I see "{text}" in the "{nth}" list'))
|
@given(parsers.parse('I see "{text}" in the "{nth}" list'))
|
||||||
@when(parsers.parse('I see "{text}" in the "{nth}" list'))
|
@when(parsers.parse('I see "{text}" in the "{nth}" list'))
|
||||||
@then(parsers.parse('I see "{text}" in the "{nth}" list'))
|
@then(parsers.parse('I see "{text}" in the "{nth}" list'))
|
||||||
@@ -369,6 +379,10 @@ def i_see_text_in_the_nth_list(text, nth):
|
|||||||
if i + 1 != nth:
|
if i + 1 != nth:
|
||||||
continue
|
continue
|
||||||
for row in template_list.rows:
|
for row in template_list.rows:
|
||||||
|
for p in row.spied_props:
|
||||||
|
debug.append(str(p))
|
||||||
|
if isinstance(p["value"], str) and text in p["value"]:
|
||||||
|
return True
|
||||||
for l in row.spied_labels:
|
for l in row.spied_labels:
|
||||||
debug.append(l)
|
debug.append(l)
|
||||||
if text in l:
|
if text in l:
|
||||||
@@ -446,12 +460,17 @@ def i_select_the_row_where_i_see_text_in_the_nth_list(text, nth):
|
|||||||
continue
|
continue
|
||||||
for i, row in enumerate(template_list.rows):
|
for i, row in enumerate(template_list.rows):
|
||||||
is_row = False
|
is_row = False
|
||||||
|
for p in row.spied_props:
|
||||||
|
debug.append(str(p))
|
||||||
|
if isinstance(p["value"], str) and text in p["value"]:
|
||||||
|
is_row = True
|
||||||
for l in row.spied_labels:
|
for l in row.spied_labels:
|
||||||
debug.append(l)
|
debug.append(l)
|
||||||
if text in l:
|
if text in l:
|
||||||
is_row = True
|
is_row = True
|
||||||
if is_row:
|
if is_row:
|
||||||
template_list.set_active_index(i)
|
template_list.set_active_index(i)
|
||||||
|
panel_spy.is_spy_dirty = True
|
||||||
return True
|
return True
|
||||||
debug = "\n".join(debug)
|
debug = "\n".join(debug)
|
||||||
assert False, f"Could not see '{text}' in any list. We saw:\n{debug}"
|
assert False, f"Could not see '{text}' in any list. We saw:\n{debug}"
|
||||||
@@ -745,12 +764,13 @@ def _i_click_button_on_panel(button, panel_spy):
|
|||||||
if button in (spied_prop["name"], spied_prop["text"], spied_prop["icon"]):
|
if button in (spied_prop["name"], spied_prop["text"], spied_prop["icon"]):
|
||||||
val = getattr(spied_prop["props"], spied_prop["name"])
|
val = getattr(spied_prop["props"], spied_prop["name"])
|
||||||
setattr(spied_prop["props"], spied_prop["name"], not bool(val))
|
setattr(spied_prop["props"], spied_prop["name"], not bool(val))
|
||||||
|
panel_spy.is_spy_dirty = True
|
||||||
return
|
return
|
||||||
if button == "OK" and panel_spy.panel.bl_rna.base.name == "Operator":
|
if button == "OK" and panel_spy.panel.bl_rna.base.name == "Operator":
|
||||||
# Clicked confirm on an operator's draw dialog
|
# Clicked confirm on an operator's draw dialog
|
||||||
return i_press_operator(panel_spy.panel.bl_idname)
|
return i_press_operator(panel_spy.panel.bl_idname)
|
||||||
debug = "\n".join([f"{i} {v}" for i, v in enumerate(panel_spy.spied_operators)])
|
debug = "\n".join([f"{i} {v}" for i, v in enumerate(panel_spy.spied_operators)])
|
||||||
debug += f"\nHere is the text we see: {panel_spy.spied_labels}"
|
debug += f"\nHere is the text we see:\n{panel_spy.spied_labels}\n... and props:\n {panel_spy.spied_props}"
|
||||||
assert False, f"Could not find {button}:\n{debug}"
|
assert False, f"Could not find {button}:\n{debug}"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user