mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 21:53:40 +00:00
Reimplement feature to reassign inherited containers if you select a child element
This reimplements @theoryshaw 's commit 9adbd4 but has a few upgrades: - Considers all parent / child relationships, not just aggregates - Puts business logic in core where it belongs and tool code in tool - Uses existing utils where possible like get_decomposition - Does not use name based collection checking which is fragile - Reuses tool.Collector - Makes container assignment handle the API's capability to do things in bulk instead of one by one in a loop, so it's faster - Tests
This commit is contained in:
@@ -38,16 +38,19 @@ class TestDereferenceStructure:
|
||||
|
||||
class TestAssignContainer:
|
||||
def test_run(self, ifc, collector, spatial):
|
||||
spatial.can_contain("container", "element_obj").should_be_called().will_return(True)
|
||||
ifc.get_entity("element_obj").should_be_called().will_return("element")
|
||||
ifc.run(
|
||||
"spatial.assign_container", products=["element"], relating_structure="container"
|
||||
).should_be_called().will_return("rel")
|
||||
spatial.disable_editing("element_obj").should_be_called()
|
||||
collector.assign("element_obj").should_be_called()
|
||||
assert (
|
||||
subject.assign_container(ifc, collector, spatial, container="container", element_obj="element_obj") == "rel"
|
||||
)
|
||||
ifc.get_entity("obj").should_be_called().will_return("element")
|
||||
spatial.get_root_element("element").should_be_called().will_return("aggregate")
|
||||
spatial.get_decomposition("aggregate").should_be_called().will_return(["element", "element2"])
|
||||
spatial.can_contain("container", "aggregate").should_be_called().will_return(True)
|
||||
ifc.run("spatial.assign_container", products=["aggregate"], relating_structure="container").should_be_called()
|
||||
spatial.disable_editing("obj").should_be_called()
|
||||
ifc.get_object("aggregate").should_be_called().will_return("aggregate_obj")
|
||||
ifc.get_object("element").should_be_called().will_return("obj")
|
||||
ifc.get_object("element2").should_be_called().will_return("obj2")
|
||||
collector.assign("aggregate_obj").should_be_called()
|
||||
collector.assign("obj").should_be_called()
|
||||
collector.assign("obj2").should_be_called()
|
||||
subject.assign_container(ifc, collector, spatial, container="container", objs=["obj"])
|
||||
|
||||
|
||||
class TestEnableEditingContainer:
|
||||
@@ -82,7 +85,7 @@ class TestCopyToContainer:
|
||||
spatial.duplicate_object_and_data("obj").should_be_called().will_return("new_obj")
|
||||
spatial.set_relative_object_matrix("new_obj", "to_container_obj", "matrix").should_be_called()
|
||||
spatial.run_root_copy_class(obj="new_obj").should_be_called()
|
||||
spatial.run_spatial_assign_container(container="to_container", element_obj="new_obj").should_be_called()
|
||||
spatial.run_spatial_assign_container(container="to_container", objs=["new_obj"]).should_be_called()
|
||||
|
||||
spatial.disable_editing("obj").should_be_called()
|
||||
|
||||
@@ -97,7 +100,7 @@ class TestCopyToContainer:
|
||||
spatial.duplicate_object_and_data("obj").should_be_called().will_return("new_obj")
|
||||
spatial.set_relative_object_matrix("new_obj", "to_container_obj", "matrix").should_be_called()
|
||||
spatial.run_root_copy_class(obj="new_obj").should_be_called()
|
||||
spatial.run_spatial_assign_container(container="to_container", element_obj="new_obj").should_be_called()
|
||||
spatial.run_spatial_assign_container(container="to_container", objs=["new_obj"]).should_be_called()
|
||||
|
||||
spatial.disable_editing("obj").should_be_called()
|
||||
|
||||
|
||||
@@ -43,9 +43,7 @@ class TestCanContain(NewFile):
|
||||
structure_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(structure, structure_obj)
|
||||
element = ifc.createIfcWall()
|
||||
element_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(element, element_obj)
|
||||
assert subject.can_contain(structure, element_obj) is True
|
||||
assert subject.can_contain(structure, element) is True
|
||||
|
||||
def test_a_spatial_structure_element_can_contain_an_element_ifc2x3(self):
|
||||
ifc = ifcopenshell.file(schema="IFC2X3")
|
||||
@@ -54,9 +52,7 @@ class TestCanContain(NewFile):
|
||||
structure_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(structure, structure_obj)
|
||||
element = ifc.createIfcWall()
|
||||
element_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(element, element_obj)
|
||||
assert subject.can_contain(structure, element_obj) is True
|
||||
assert subject.can_contain(structure, element) is True
|
||||
|
||||
def test_a_spatial_zone_element_cannot_contain_an_element(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -65,14 +61,7 @@ class TestCanContain(NewFile):
|
||||
structure_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(structure, structure_obj)
|
||||
element = ifc.createIfcWall()
|
||||
element_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(element, element_obj)
|
||||
assert subject.can_contain(structure, element_obj) is False
|
||||
|
||||
def test_unlinked_elements_cannot_contain_anything(self):
|
||||
structure_obj = bpy.data.objects.new("Object", None)
|
||||
element_obj = bpy.data.objects.new("Object", None)
|
||||
assert subject.can_contain(structure_obj, element_obj) is False
|
||||
assert subject.can_contain(structure, element) is False
|
||||
|
||||
def test_a_non_spatial_element_cannot_contain_anything(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -81,9 +70,7 @@ class TestCanContain(NewFile):
|
||||
structure_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(structure, structure_obj)
|
||||
element = ifc.createIfcWall()
|
||||
element_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(element, element_obj)
|
||||
assert subject.can_contain(structure, element_obj) is False
|
||||
assert subject.can_contain(structure, element) is False
|
||||
|
||||
def test_a_non_element_cannot_be_contained(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -92,9 +79,7 @@ class TestCanContain(NewFile):
|
||||
structure_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(structure, structure_obj)
|
||||
element = ifc.createIfcTask()
|
||||
element_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(element, element_obj)
|
||||
assert subject.can_contain(structure, element_obj) is False
|
||||
assert subject.can_contain(structure, element) is False
|
||||
|
||||
def test_other_non_elements_that_have_a_contained_in_structure_attribute_can_be_contained(self):
|
||||
ifc = ifcopenshell.file()
|
||||
@@ -103,9 +88,7 @@ class TestCanContain(NewFile):
|
||||
structure_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(structure, structure_obj)
|
||||
element = ifc.createIfcGrid()
|
||||
element_obj = bpy.data.objects.new("Object", None)
|
||||
tool.Ifc.link(element, element_obj)
|
||||
assert subject.can_contain(structure, element_obj) is True
|
||||
assert subject.can_contain(structure, element) is True
|
||||
|
||||
|
||||
class TestCanReference(NewFile):
|
||||
|
||||
Reference in New Issue
Block a user