Implement support for managing nest hosts and components.

This commit is contained in:
Dion Moult
2023-12-07 13:18:33 +11:00
parent 302dc8eb9f
commit 401db55c55
19 changed files with 704 additions and 22 deletions
+7
View File
@@ -126,6 +126,13 @@ def misc():
prophet.verify()
@pytest.fixture
def nest():
prophet = Prophecy(blenderbim.core.tool.Nest)
yield prophet
prophet.verify()
@pytest.fixture
def owner():
prophet = Prophecy(blenderbim.core.tool.Owner)
+59
View File
@@ -0,0 +1,59 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.nest as subject
from test.core.bootstrap import ifc, nest, collector
class TestEnableEditingNeset:
def test_run(self, nest):
nest.enable_editing("obj").should_be_called()
subject.enable_editing_nest(nest, obj="obj")
class TestDisableEditingNest:
def test_run(self, nest):
nest.disable_editing("obj").should_be_called()
subject.disable_editing_nest(nest, obj="obj")
class TestAssignObject:
def test_run(self, ifc, nest, collector):
nest.can_nest("relating_obj", "related_obj").should_be_called().will_return(True)
ifc.get_entity("relating_obj").should_be_called().will_return("relating_object")
ifc.get_entity("related_obj").should_be_called().will_return("related_object")
ifc.run(
"nest.assign_object", related_object="related_object", relating_object="relating_object"
).should_be_called().will_return("rel")
nest.disable_editing("related_obj").should_be_called()
collector.assign("relating_obj").should_be_called()
collector.assign("related_obj").should_be_called()
assert (
subject.assign_object(ifc, nest, collector, relating_obj="relating_obj", related_obj="related_obj") == "rel"
)
class TestUnassignObject:
def test_run(self, ifc, nest, collector):
ifc.get_entity("related_obj").should_be_called().will_return("element")
nest.get_container("element").should_be_called().will_return("container")
ifc.run("spatial.assign_container", product="element", relating_structure="container").should_be_called()
ifc.run("nest.unassign_object", related_object="element").should_be_called().will_return("rel")
collector.assign("relating_obj").should_be_called()
collector.assign("related_obj").should_be_called()
subject.unassign_object(ifc, nest, collector, relating_obj="relating_obj", related_obj="related_obj")
+1 -4
View File
@@ -29,10 +29,6 @@ class TestImplementsTool(NewFile):
assert isinstance(subject(), blenderbim.core.tool.Aggregate)
class TestCanAggregate(NewFile):
def test_elements_can_aggregate(self):
ifc = ifcopenshell.file()
@@ -107,6 +103,7 @@ class TestCanAggregate(NewFile):
tool.Ifc.link(subelement, subelement_obj)
assert subject.can_aggregate(element_obj, subelement_obj) is False
class TestDisableEditing(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
+74
View File
@@ -0,0 +1,74 @@
# BlenderBIM Add-on - OpenBIM Blender Add-on
# Copyright (C) 2021 Dion Moult <dion@thinkmoult.com>
#
# This file is part of BlenderBIM Add-on.
#
# BlenderBIM Add-on is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BlenderBIM Add-on is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import bpy
import ifcopenshell
import blenderbim.core.tool
import blenderbim.tool as tool
from test.bim.bootstrap import NewFile
from blenderbim.tool.nest import Nest as subject
class TestImplementsTool(NewFile):
def test_run(self):
assert isinstance(subject(), blenderbim.core.tool.Nest)
class TestCanNest(NewFile):
def test_elements_can_nest(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcElementAssembly()
element_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(element, element_obj)
subelement = ifc.createIfcBeam()
subelement_obj = bpy.data.objects.new("Object", None)
tool.Ifc.link(subelement, subelement_obj)
assert subject.can_nest(element_obj, subelement_obj) is True
def test_unlinked_elements_cannot_nest(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element_obj = bpy.data.objects.new("Object", None)
subelement_obj = bpy.data.objects.new("Object", None)
assert subject.can_nest(element_obj, subelement_obj) is False
class TestDisableEditing(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
subject.enable_editing(obj)
subject.disable_editing(obj)
assert obj.BIMObjectNestProperties.is_editing is False
class TestEnableEditing(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
subject.enable_editing(obj)
assert obj.BIMObjectNestProperties.is_editing is True
class TestGetContainer(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
element = ifc.createIfcWall()
container = ifc.createIfcBuildingStorey()
ifcopenshell.api.run("spatial.assign_container", ifc, product=element, relating_structure=container)
assert subject.get_container(element) == container