Refactor and re-use common spatial_tool.select_products

This commit is contained in:
Sigma Dimensions
2023-06-12 15:21:33 +01:00
parent a7faa3ec3e
commit 0959a7f6a3
16 changed files with 43 additions and 72 deletions
+3 -3
View File
@@ -17,7 +17,7 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.material as subject
from test.core.bootstrap import ifc, material, style
from test.core.bootstrap import ifc, material, style, spatial
class TestUnlinkMaterial:
@@ -158,7 +158,7 @@ class TestDisableEditingMaterials:
class TestSelectByMaterial:
def test_run(self, material):
def test_run(self, material, spatial):
material.get_elements_by_material("material").should_be_called().will_return("elements")
material.select_elements("elements").should_be_called()
spatial.select_products("elements").should_be_called()
subject.select_by_material(material, material="material")
+8 -1
View File
@@ -17,7 +17,7 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.style as subject
from test.core.bootstrap import ifc, material, style
from test.core.bootstrap import ifc, material, style, spatial
class TestAddStyle:
@@ -212,3 +212,10 @@ class TestDisableEditingStyles:
def test_run(self, style):
style.disable_editing_styles().should_be_called()
subject.disable_editing_styles(style)
class TestSelectByStyle:
def test_run(self, style, spatial):
style.get_elements_by_style("style").should_be_called().will_return("elements")
spatial.select_products("elements").should_be_called()
subject.select_by_style(style, style="style")
+7 -7
View File
@@ -18,7 +18,7 @@
import blenderbim.core.system as subject
from test.core.bootstrap import ifc, system
from test.core.bootstrap import ifc, system, spatial
class TestLoadSystems:
@@ -91,24 +91,24 @@ class TestSelectSystemProducts:
class TestShowPorts:
def test_run(self, ifc, system):
def test_run(self, ifc, system, spatial):
ifc.get_object("element").should_be_called().will_return("obj")
ifc.is_moved("obj").should_be_called().will_return(False)
system.get_ports("element").should_be_called().will_return(["port"])
system.load_ports("element", ["port"]).should_be_called()
system.select_elements(["port"]).should_be_called()
subject.show_ports(ifc, system, element="element")
spatial.select_products(["port"]).should_be_called()
subject.show_ports(ifc, system, spatial, element="element")
def test_syncing_locations_if_objects_moved_prior_to_showing_ports(self, ifc, system):
def test_syncing_locations_if_objects_moved_prior_to_showing_ports(self, ifc, system, spatial):
ifc.get_object("element").should_be_called().will_return("obj")
ifc.is_moved("obj").should_be_called().will_return(True)
system.run_geometry_edit_object_placement(obj="obj").should_be_called()
system.get_ports("element").should_be_called().will_return(["port"])
system.load_ports("element", ["port"]).should_be_called()
system.select_elements(["port"]).should_be_called()
subject.show_ports(ifc, system, element="element")
spatial.select_products(["port"]).should_be_called()
subject.show_ports(ifc, system, spatial, element="element")
class TestHidePorts:
-11
View File
@@ -170,14 +170,3 @@ class TestIsMaterialUsedInSets(NewFile):
material_set_item.Material = material
assert subject.is_material_used_in_sets(material) is True
class TestSelectElements(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(element, obj)
subject.select_elements([element])
assert obj in bpy.context.selected_objects
+12
View File
@@ -257,3 +257,15 @@ class TestSetRelativeObjectMatrix(NewFile):
matrix[0][3] = 1
subject.set_relative_object_matrix(obj, relative_obj, matrix)
assert obj.matrix_world[0][3] == 2
class TestSelectProducts(NewFile):
def test_select_products(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
product = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcWall")
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(product, obj)
subject.select_products([product])
assert obj in bpy.context.selected_objects
-12
View File
@@ -440,15 +440,3 @@ class TestIsEditingStyles(NewFile):
subject.is_editing_styles() is False
bpy.context.scene.BIMStylesProperties.is_editing = True
subject.is_editing_styles() is True
class TestSelectElements(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(element, obj)
subject.select_elements([element])
assert obj in bpy.context.selected_objects
-12
View File
@@ -196,18 +196,6 @@ class TestRunRootAssignClass(NewFile):
pass
class TestSelectElements(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc().set(ifc)
element = ifcopenshell.api.run("root.create_entity", ifc, ifc_class="IfcPump")
obj = bpy.data.objects.new("Object", None)
bpy.context.scene.collection.objects.link(obj)
tool.Ifc.link(element, obj)
subject.select_elements([element])
assert obj in bpy.context.selected_objects
class TestSelectSystemProducts(NewFile):
def test_run(self):
ifc = ifcopenshell.file()