mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 10:06:47 +00:00
Fix bug where assigning a spatial container didn't work with non local placements
This commit is contained in:
@@ -248,7 +248,11 @@ class IfcStore:
|
||||
operator, rollback=lambda d: IfcStore.get_file().undo(), commit=lambda d: IfcStore.get_file().redo()
|
||||
)
|
||||
IfcStore.end_transaction(operator)
|
||||
context.view_layer.objects.active = active_object
|
||||
try:
|
||||
active_object.name
|
||||
context.view_layer.objects.active = active_object
|
||||
except:
|
||||
pass
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -242,7 +242,6 @@ class AssignClass(bpy.types.Operator):
|
||||
tool.Ifc,
|
||||
tool.Collector,
|
||||
tool.Container,
|
||||
tool.Surveyor,
|
||||
structure_obj=spatial_obj,
|
||||
element_obj=obj,
|
||||
)
|
||||
|
||||
@@ -46,7 +46,6 @@ class AssignContainer(bpy.types.Operator, Operator):
|
||||
tool.Ifc,
|
||||
tool.Collector,
|
||||
tool.Container,
|
||||
tool.Surveyor,
|
||||
structure_obj=structure_obj,
|
||||
element_obj=element_obj,
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import blenderbim.core
|
||||
|
||||
|
||||
def assign_container(ifc, collector, container, surveyor, structure_obj=None, element_obj=None):
|
||||
def assign_container(ifc, collector, container, structure_obj=None, element_obj=None):
|
||||
if not container.can_contain(structure_obj, element_obj):
|
||||
return
|
||||
rel = ifc.run(
|
||||
@@ -27,7 +27,6 @@ def assign_container(ifc, collector, container, surveyor, structure_obj=None, el
|
||||
product=ifc.get_entity(element_obj),
|
||||
relating_structure=ifc.get_entity(structure_obj),
|
||||
)
|
||||
blenderbim.core.geometry.edit_object_placement(ifc, surveyor, obj=element_obj)
|
||||
container.disable_editing(element_obj)
|
||||
collector.assign(element_obj)
|
||||
return rel
|
||||
|
||||
@@ -17,24 +17,22 @@
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import blenderbim.core.spatial as subject
|
||||
from test.core.bootstrap import ifc, collector, container, surveyor
|
||||
from test.core.bootstrap import ifc, collector, container
|
||||
|
||||
|
||||
class TestAssignContainer:
|
||||
def test_run(self, ifc, collector, container, surveyor):
|
||||
def test_run(self, ifc, collector, container):
|
||||
container.can_contain("structure_obj", "element_obj").should_be_called().will_return(True)
|
||||
ifc.get_entity("structure_obj").should_be_called().will_return("structure")
|
||||
ifc.get_entity("element_obj").should_be_called().will_return("element")
|
||||
ifc.run(
|
||||
"spatial.assign_container", product="element", relating_structure="structure"
|
||||
).should_be_called().will_return("rel")
|
||||
surveyor.get_absolute_matrix("element_obj").should_be_called().will_return("matrix")
|
||||
ifc.run("geometry.edit_object_placement", product="element", matrix="matrix").should_be_called()
|
||||
container.disable_editing("element_obj").should_be_called()
|
||||
collector.assign("element_obj").should_be_called()
|
||||
assert (
|
||||
subject.assign_container(
|
||||
ifc, collector, container, surveyor, structure_obj="structure_obj", element_obj="element_obj"
|
||||
ifc, collector, container, structure_obj="structure_obj", element_obj="element_obj"
|
||||
)
|
||||
== "rel"
|
||||
)
|
||||
|
||||
@@ -45,7 +45,8 @@ class Usecase:
|
||||
}
|
||||
)
|
||||
|
||||
if getattr(self.settings["product"], "ObjectPlacement", None):
|
||||
placement = getattr(self.settings["product"], "ObjectPlacement", None)
|
||||
if placement and placement.is_a("IfcLocalPlacement"):
|
||||
ifcopenshell.api.run(
|
||||
"geometry.edit_object_placement",
|
||||
self.file,
|
||||
|
||||
@@ -76,4 +76,15 @@ class TestEditObjectPlacement(test.bootstrap.IFC4):
|
||||
"geometry.edit_object_placement", self.file, product=subelement, matrix=matrix1.copy(), is_si=False
|
||||
)
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element2)
|
||||
assert subelement.ObjectPlacement.PlacementRelTo.PlacesObject[0] == element2
|
||||
assert numpy.array_equal(ifcopenshell.util.placement.get_local_placement(subelement.ObjectPlacement), matrix1)
|
||||
|
||||
def test_not_updating_placement_if_placement_is_not_relative(self):
|
||||
ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcProject")
|
||||
ifcopenshell.api.run("unit.assign_unit", self.file)
|
||||
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcBuilding")
|
||||
subelement = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
|
||||
placement = self.file.createIfcGridPlacement()
|
||||
subelement.ObjectPlacement = placement
|
||||
ifcopenshell.api.run("spatial.assign_container", self.file, product=subelement, relating_structure=element)
|
||||
assert subelement.ObjectPlacement == placement
|
||||
|
||||
Reference in New Issue
Block a user