mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 06:32:09 +00:00
Fix bug where copying to container might get the wrong coordinates if containers weren't synced.
This commit is contained in:
@@ -136,7 +136,7 @@ class CopyToContainer(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
old_to_new = {}
|
old_to_new = {}
|
||||||
containers = [tool.Ifc.get().by_id(c.ifc_definition_id) for c in sprops.containers if c.is_selected]
|
containers = [tool.Ifc.get().by_id(c.ifc_definition_id) for c in sprops.containers if c.is_selected]
|
||||||
for obj in context.selected_objects:
|
for obj in context.selected_objects:
|
||||||
result_objs = core.copy_to_container(tool.Ifc, tool.Spatial, obj=obj, containers=containers)
|
result_objs = core.copy_to_container(tool.Ifc, tool.Collector, tool.Spatial, obj=obj, containers=containers)
|
||||||
if result_objs:
|
if result_objs:
|
||||||
old_to_new[tool.Ifc.get_entity(obj)] = result_objs
|
old_to_new[tool.Ifc.get_entity(obj)] = result_objs
|
||||||
# Recreate decompositions
|
# Recreate decompositions
|
||||||
|
|||||||
@@ -60,10 +60,11 @@ def remove_container(ifc, collector, obj=None):
|
|||||||
collector.assign(obj)
|
collector.assign(obj)
|
||||||
|
|
||||||
|
|
||||||
def copy_to_container(ifc, spatial, obj=None, containers=None):
|
def copy_to_container(ifc, collector, spatial, obj=None, containers=None):
|
||||||
element = ifc.get_entity(obj)
|
element = ifc.get_entity(obj)
|
||||||
if not element:
|
if not element:
|
||||||
return
|
return
|
||||||
|
collector.sync(obj)
|
||||||
from_container = spatial.get_container(element)
|
from_container = spatial.get_container(element)
|
||||||
if from_container:
|
if from_container:
|
||||||
matrix = spatial.get_relative_object_matrix(obj, ifc.get_object(from_container))
|
matrix = spatial.get_relative_object_matrix(obj, ifc.get_object(from_container))
|
||||||
|
|||||||
@@ -29,7 +29,12 @@ class Collector(blenderbim.core.tool.Collector):
|
|||||||
# This is the reverse of assign. It reads the Blender collection and figures out its IFC hierarchy
|
# This is the reverse of assign. It reads the Blender collection and figures out its IFC hierarchy
|
||||||
element = tool.Ifc.get_entity(obj)
|
element = tool.Ifc.get_entity(obj)
|
||||||
|
|
||||||
if element.is_a("IfcProject") or element.is_a("IfcGridAxis") or element.is_a("IfcOpeningElement"):
|
if (
|
||||||
|
not element
|
||||||
|
or element.is_a("IfcProject")
|
||||||
|
or element.is_a("IfcGridAxis")
|
||||||
|
or element.is_a("IfcOpeningElement")
|
||||||
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not obj.users_collection:
|
if not obj.users_collection:
|
||||||
|
|||||||
@@ -78,8 +78,9 @@ class TestRemoveContainer:
|
|||||||
|
|
||||||
|
|
||||||
class TestCopyToContainer:
|
class TestCopyToContainer:
|
||||||
def test_run(self, ifc, spatial):
|
def test_run(self, ifc, collector, spatial):
|
||||||
ifc.get_entity("obj").should_be_called().will_return("element")
|
ifc.get_entity("obj").should_be_called().will_return("element")
|
||||||
|
collector.sync("obj").should_be_called()
|
||||||
spatial.get_container("element").should_be_called().will_return("container")
|
spatial.get_container("element").should_be_called().will_return("container")
|
||||||
ifc.get_object("container").should_be_called().will_return("container_obj")
|
ifc.get_object("container").should_be_called().will_return("container_obj")
|
||||||
spatial.get_relative_object_matrix("obj", "container_obj").should_be_called().will_return("matrix")
|
spatial.get_relative_object_matrix("obj", "container_obj").should_be_called().will_return("matrix")
|
||||||
@@ -92,10 +93,11 @@ class TestCopyToContainer:
|
|||||||
|
|
||||||
spatial.disable_editing("obj").should_be_called()
|
spatial.disable_editing("obj").should_be_called()
|
||||||
|
|
||||||
subject.copy_to_container(ifc, spatial, obj="obj", containers=["to_container"])
|
subject.copy_to_container(ifc, collector, spatial, obj="obj", containers=["to_container"])
|
||||||
|
|
||||||
def test_using_an_absolute_matrix_if_there_is_no_from_container(self, ifc, spatial):
|
def test_using_an_absolute_matrix_if_there_is_no_from_container(self, ifc, collector, spatial):
|
||||||
ifc.get_entity("obj").should_be_called().will_return("element")
|
ifc.get_entity("obj").should_be_called().will_return("element")
|
||||||
|
collector.sync("obj").should_be_called()
|
||||||
spatial.get_container("element").should_be_called().will_return(None)
|
spatial.get_container("element").should_be_called().will_return(None)
|
||||||
spatial.get_object_matrix("obj").should_be_called().will_return("matrix")
|
spatial.get_object_matrix("obj").should_be_called().will_return("matrix")
|
||||||
|
|
||||||
@@ -107,7 +109,7 @@ class TestCopyToContainer:
|
|||||||
|
|
||||||
spatial.disable_editing("obj").should_be_called()
|
spatial.disable_editing("obj").should_be_called()
|
||||||
|
|
||||||
subject.copy_to_container(ifc, spatial, obj="obj", containers=["to_container"])
|
subject.copy_to_container(ifc, collector, spatial, obj="obj", containers=["to_container"])
|
||||||
|
|
||||||
|
|
||||||
class TestSelectContainer:
|
class TestSelectContainer:
|
||||||
|
|||||||
Reference in New Issue
Block a user