mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 17:59:55 +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()
|
operator, rollback=lambda d: IfcStore.get_file().undo(), commit=lambda d: IfcStore.get_file().redo()
|
||||||
)
|
)
|
||||||
IfcStore.end_transaction(operator)
|
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
|
return result
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,6 @@ class AssignClass(bpy.types.Operator):
|
|||||||
tool.Ifc,
|
tool.Ifc,
|
||||||
tool.Collector,
|
tool.Collector,
|
||||||
tool.Container,
|
tool.Container,
|
||||||
tool.Surveyor,
|
|
||||||
structure_obj=spatial_obj,
|
structure_obj=spatial_obj,
|
||||||
element_obj=obj,
|
element_obj=obj,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ class AssignContainer(bpy.types.Operator, Operator):
|
|||||||
tool.Ifc,
|
tool.Ifc,
|
||||||
tool.Collector,
|
tool.Collector,
|
||||||
tool.Container,
|
tool.Container,
|
||||||
tool.Surveyor,
|
|
||||||
structure_obj=structure_obj,
|
structure_obj=structure_obj,
|
||||||
element_obj=element_obj,
|
element_obj=element_obj,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
import blenderbim.core
|
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):
|
if not container.can_contain(structure_obj, element_obj):
|
||||||
return
|
return
|
||||||
rel = ifc.run(
|
rel = ifc.run(
|
||||||
@@ -27,7 +27,6 @@ def assign_container(ifc, collector, container, surveyor, structure_obj=None, el
|
|||||||
product=ifc.get_entity(element_obj),
|
product=ifc.get_entity(element_obj),
|
||||||
relating_structure=ifc.get_entity(structure_obj),
|
relating_structure=ifc.get_entity(structure_obj),
|
||||||
)
|
)
|
||||||
blenderbim.core.geometry.edit_object_placement(ifc, surveyor, obj=element_obj)
|
|
||||||
container.disable_editing(element_obj)
|
container.disable_editing(element_obj)
|
||||||
collector.assign(element_obj)
|
collector.assign(element_obj)
|
||||||
return rel
|
return rel
|
||||||
|
|||||||
@@ -17,24 +17,22 @@
|
|||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import blenderbim.core.spatial as subject
|
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:
|
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)
|
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("structure_obj").should_be_called().will_return("structure")
|
||||||
ifc.get_entity("element_obj").should_be_called().will_return("element")
|
ifc.get_entity("element_obj").should_be_called().will_return("element")
|
||||||
ifc.run(
|
ifc.run(
|
||||||
"spatial.assign_container", product="element", relating_structure="structure"
|
"spatial.assign_container", product="element", relating_structure="structure"
|
||||||
).should_be_called().will_return("rel")
|
).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()
|
container.disable_editing("element_obj").should_be_called()
|
||||||
collector.assign("element_obj").should_be_called()
|
collector.assign("element_obj").should_be_called()
|
||||||
assert (
|
assert (
|
||||||
subject.assign_container(
|
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"
|
== "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(
|
ifcopenshell.api.run(
|
||||||
"geometry.edit_object_placement",
|
"geometry.edit_object_placement",
|
||||||
self.file,
|
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
|
"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)
|
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)
|
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