Potentially risky refactor of add_representation in preparation of stabilisation and optimization of geometric operators.

This commit is contained in:
Dion Moult
2021-10-18 19:23:40 +11:00
parent 33f4461a87
commit 4577b7bf60
16 changed files with 561 additions and 97 deletions
+7
View File
@@ -49,6 +49,13 @@ def context():
prophet.verify()
@pytest.fixture
def geometry():
prophet = Prophecy(blenderbim.core.tool.Geometry)
yield prophet
prophet.verify()
@pytest.fixture
def material():
prophet = Prophecy(blenderbim.core.tool.Material)
+152 -2
View File
@@ -17,12 +17,162 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.geometry as subject
from test.core.bootstrap import ifc, surveyor
import test.core.test_style
from test.core.bootstrap import ifc, surveyor, geometry, style
class TestEditObjectPlacement:
def test_run(self, ifc, surveyor):
def predict(self, ifc, surveyor):
ifc.get_entity("obj").should_be_called().will_return("element")
surveyor.get_absolute_matrix("obj").should_be_called().will_return("matrix")
ifc.run("geometry.edit_object_placement", product="element", matrix="matrix").should_be_called()
def test_run(self, ifc, surveyor):
self.predict(ifc, surveyor)
subject.edit_object_placement(ifc, surveyor, obj="obj")
class TestAddRepresentation:
def test_run(self, ifc, geometry, style, surveyor):
TestEditObjectPlacement.predict(self, ifc, surveyor)
# Add representation
geometry.get_object_data("obj").should_be_called().will_return("data")
geometry.get_cartesian_point_coordinate_offset("obj").should_be_called().will_return("coordinate_offset")
geometry.get_total_representation_items("obj").should_be_called().will_return(1)
geometry.should_force_faceted_brep().should_be_called().will_return(False)
geometry.should_force_triangulation().should_be_called().will_return(True)
ifc.run(
"geometry.add_representation",
context="context",
blender_object="obj",
geometry="data",
coordinate_offset="coordinate_offset",
total_items=1,
should_force_faceted_brep=False,
should_force_triangulation=True,
ifc_representation_class="ifc_representation_class",
profile_set_usage="profile_set_usage",
).should_be_called().will_return("representation")
# Styles are relevant for meshes with faces only
geometry.does_object_have_mesh_with_faces("obj").should_be_called().will_return(True)
# Add styles
geometry.get_object_materials_without_styles("obj").should_be_called().will_return(["material"])
test.core.test_style.TestAddStyle.predict(self, ifc, style, obj="material")
# Link style to representation items
geometry.should_use_presentation_style_assignment().should_be_called().will_return(False)
ifc.run(
"style.assign_representation_styles",
shape_representation="representation",
styles=["style"],
should_use_presentation_style_assignment=False,
).should_be_called()
# Assign representation to product
ifc.run("geometry.assign_representation", product="element", representation="representation").should_be_called()
# Update mesh
geometry.duplicate_object_data("obj").should_be_called().will_return("data")
geometry.get_representation_name("context", "representation").should_be_called().will_return("name")
geometry.rename_object_data("data", "name").should_be_called()
geometry.link("representation", "data").should_be_called()
assert (
subject.add_representation(
ifc,
geometry,
style,
surveyor,
obj="obj",
context="context",
ifc_representation_class="ifc_representation_class",
profile_set_usage="profile_set_usage",
)
== "representation"
)
def test_not_handling_styles_if_representation_has_no_faces(self, ifc, geometry, style, surveyor):
TestEditObjectPlacement.predict(self, ifc, surveyor)
# Add representation
geometry.get_object_data("obj").should_be_called().will_return("data")
geometry.get_cartesian_point_coordinate_offset("obj").should_be_called().will_return("coordinate_offset")
geometry.get_total_representation_items("obj").should_be_called().will_return(1)
geometry.should_force_faceted_brep().should_be_called().will_return(False)
geometry.should_force_triangulation().should_be_called().will_return(True)
ifc.run(
"geometry.add_representation",
context="context",
blender_object="obj",
geometry="data",
coordinate_offset="coordinate_offset",
total_items=1,
should_force_faceted_brep=False,
should_force_triangulation=True,
ifc_representation_class="ifc_representation_class",
profile_set_usage="profile_set_usage",
).should_be_called().will_return("representation")
# Styles are relevant for meshes with faces only
geometry.does_object_have_mesh_with_faces("obj").should_be_called().will_return(False)
# Assign representation to product
ifc.run("geometry.assign_representation", product="element", representation="representation").should_be_called()
# Update mesh
geometry.duplicate_object_data("obj").should_be_called().will_return("data")
geometry.get_representation_name("context", "representation").should_be_called().will_return("name")
geometry.rename_object_data("data", "name").should_be_called()
geometry.link("representation", "data").should_be_called()
assert (
subject.add_representation(
ifc,
geometry,
style,
surveyor,
obj="obj",
context="context",
ifc_representation_class="ifc_representation_class",
profile_set_usage="profile_set_usage",
)
== "representation"
)
def test_only_updating_the_placement_if_there_is_no_object_data(self, ifc, geometry, style, surveyor):
TestEditObjectPlacement.predict(self, ifc, surveyor)
# Add representation
geometry.get_object_data("obj").should_be_called().will_return(None)
assert (
subject.add_representation(
ifc,
geometry,
style,
surveyor,
obj="obj",
context="context",
ifc_representation_class="ifc_representation_class",
profile_set_usage="profile_set_usage",
)
is None
)
def test_doing_nothing_if_not_an_ifc_element(self, ifc, geometry, style, surveyor):
ifc.get_entity("obj").should_be_called().will_return(None)
assert (
subject.add_representation(
ifc,
geometry,
style,
surveyor,
obj="obj",
context="context",
ifc_representation_class="ifc_representation_class",
profile_set_usage="profile_set_usage",
)
is None
)
+8 -5
View File
@@ -21,15 +21,18 @@ from test.core.bootstrap import ifc, style
class TestAddStyle:
def test_it_adds_a_style_with_rendering_attributes(self, ifc, style):
style.get_name("obj").should_be_called().will_return("name")
def predict(self, ifc, style, obj="obj"):
style.get_name(obj).should_be_called().will_return("name")
ifc.run("style.add_style", name="name").should_be_called().will_return("style")
style.link("style", "obj").should_be_called()
style.get_surface_rendering_attributes("obj").should_be_called().will_return("attributes")
style.link("style", obj).should_be_called()
style.get_surface_rendering_attributes(obj).should_be_called().will_return("attributes")
ifc.run(
"style.add_surface_style", style="style", ifc_class="IfcSurfaceStyleRendering", attributes="attributes"
).should_be_called()
ifc.get_entity("obj").should_be_called().will_return(None)
ifc.get_entity(obj).should_be_called().will_return(None)
def test_it_adds_a_style_with_rendering_attributes(self, ifc, style):
self.predict(ifc, style)
assert subject.add_style(ifc, style, obj="obj") == "style"
def test_adding_a_style_linked_to_a_material(self, ifc, style):