Changes are now synchronised prior to switching representations.

This commit is contained in:
Dion Moult
2021-11-09 20:49:25 +11:00
parent cbf7b0a77a
commit 66fa3f0096
13 changed files with 185 additions and 26 deletions
@@ -73,6 +73,37 @@ Scenario: Switch representation
And I press "bim.switch_representation(obj='IfcWall/Cube', ifc_definition_id={representation})"
Then nothing happens
Scenario: Switch representation - current edited representation is updated prior to switch
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
And the variable "context" is "{ifc}.by_type('IfcGeometricRepresentationSubContext')[-1].id()"
And I set "scene.BIMProperties.contexts" to "{context}"
And I press "bim.add_representation"
When the object "IfcWall/Cube" is scaled to "2"
And the variable "representation" is "{ifc}.by_type('IfcShapeRepresentation')[0].id()"
And I press "bim.switch_representation(obj='IfcWall/Cube', ifc_definition_id={representation}, should_reload=True)"
And the variable "representation" is "{ifc}.by_type('IfcShapeRepresentation')[-1].id()"
And I press "bim.switch_representation(obj='IfcWall/Cube', ifc_definition_id={representation}, should_reload=True)"
When I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc')"
Then the object "IfcWall/Cube" dimensions are "4,4,0"
Scenario: Switch representation - current edited representation is discarded if switching to a box
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
When the object "IfcWall/Cube" is scaled to "2"
And the variable "representation" is "{ifc}.by_type('IfcShapeRepresentation')[-1].id()"
And I press "bim.switch_representation(obj='IfcWall/Cube', ifc_definition_id={representation}, should_reload=True)"
And the variable "representation" is "{ifc}.by_type('IfcShapeRepresentation')[0].id()"
And I press "bim.switch_representation(obj='IfcWall/Cube', ifc_definition_id={representation}, should_reload=True)"
When I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc')"
Then the object "IfcWall/Cube" dimensions are "2,2,2"
Scenario: Switch representation - existing Blender modifiers must be purged
Given an empty IFC project
And I add a cube
@@ -210,6 +241,16 @@ Scenario: Update representation - updating a profiled extrusion
When I press "bim.update_representation(obj='IfcWall/Cube')"
Then the object "IfcWall/Cube" has a "SweptSolid" representation of "Model/Body/MODEL_VIEW"
Scenario: Get representation IFC parameters
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
And I press "bim.assign_class"
And I press "bim.update_representation(ifc_representation_class='IfcExtrudedAreaSolid/IfcRectangleProfileDef')"
When I press "bim.get_representation_ifc_parameters"
Then nothing happens
Scenario: Copy representation
Given an empty IFC project
And I add a cube
+33
View File
@@ -182,6 +182,7 @@ class TestAddRepresentation:
class TestSwitchRepresentation:
def test_switching_to_a_freshly_loaded_representation(self, geometry):
geometry.is_edited("obj").should_be_called().will_return(False)
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return(None)
geometry.import_representation(
@@ -201,9 +202,11 @@ class TestSwitchRepresentation:
should_reload=True,
enable_dynamic_voids=True,
is_global=True,
should_sync_changes_first=True,
)
def test_switching_to_a_reloaded_representation_and_deleting_the_existing_data(self, geometry):
geometry.is_edited("obj").should_be_called().will_return(False)
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("existing_data")
geometry.import_representation(
@@ -224,9 +227,11 @@ class TestSwitchRepresentation:
should_reload=True,
enable_dynamic_voids=True,
is_global=True,
should_sync_changes_first=True,
)
def test_switching_to_an_existing_representation(self, geometry):
geometry.is_edited("obj").should_be_called().will_return(False)
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.change_object_data("obj", "data", is_global=True).should_be_called()
@@ -240,9 +245,11 @@ class TestSwitchRepresentation:
should_reload=False,
enable_dynamic_voids=True,
is_global=True,
should_sync_changes_first=True,
)
def test_switching_to_non_dynamic_baked_voids(self, geometry):
geometry.is_edited("obj").should_be_called().will_return(False)
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.change_object_data("obj", "data", is_global=False).should_be_called()
@@ -254,8 +261,34 @@ class TestSwitchRepresentation:
should_reload=False,
enable_dynamic_voids=False,
is_global=False,
should_sync_changes_first=True,
)
def test_updating_a_representation_if_the_blender_object_has_been_edited_prior_to_switching(self, geometry):
geometry.is_edited("obj").should_be_called().will_return(True)
geometry.is_box_representation("mapped_rep").should_be_called().will_return(False)
geometry.run_geometry_update_representation(obj="obj").should_be_called()
geometry.resolve_mapped_representation("mapped_rep").should_be_called().will_return("representation")
geometry.get_representation_data("representation").should_be_called().will_return("data")
geometry.change_object_data("obj", "data", is_global=False).should_be_called()
geometry.clear_modifiers("obj").should_be_called()
subject.switch_representation(
geometry,
obj="obj",
representation="mapped_rep",
should_reload=False,
enable_dynamic_voids=False,
is_global=False,
should_sync_changes_first=True,
)
class TestGetRepresentationIfcParameters:
def test_run(self, geometry):
geometry.get_object_data("obj").should_be_called().will_return("data")
geometry.import_representation_parameters("data").should_be_called()
subject.get_representation_ifc_parameters(geometry, obj="obj", should_sync_changes_first=False)
class TestRemoveRepresentation:
def test_removing_an_actively_used_mapped_representation_by_remapping_usages_to_an_empty(self, ifc, geometry):
+47
View File
@@ -248,6 +248,24 @@ class TestImportRepresentation(NewFile):
assert len(mesh.edges) == 4
class TestImportRepresentationParameters(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
tool.Ifc.set(ifc)
swept_area = ifc.createIfcCircleProfileDef(Radius=1)
item = ifc.createIfcExtrudedAreaSolid(SweptArea=swept_area, Depth=2)
representation = ifc.createIfcShapeRepresentation(Items=[item])
data = bpy.data.meshes.new("Mesh")
data.BIMMeshProperties.ifc_definition_id = representation.id()
subject.import_representation_parameters(data)
assert data.BIMMeshProperties.ifc_parameters[0].name == "IfcExtrudedAreaSolid/Depth"
assert data.BIMMeshProperties.ifc_parameters[0].step_id == item.id()
assert data.BIMMeshProperties.ifc_parameters[0].index == 3
assert data.BIMMeshProperties.ifc_parameters[1].name == "IfcCircleProfileDef/Radius"
assert data.BIMMeshProperties.ifc_parameters[1].step_id == swept_area.id()
assert data.BIMMeshProperties.ifc_parameters[1].index == 3
class TestIsBodyRepresentation(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -260,6 +278,30 @@ class TestIsBodyRepresentation(NewFile):
assert subject.is_body_representation(representation) is False
class TestIsBoxRepresentation(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
context = ifc.createIfcGeometricRepresentationContext()
representation = ifc.createIfcShapeRepresentation()
representation.ContextOfItems = context
context.ContextIdentifier = "Box"
assert subject.is_box_representation(representation) is True
context.ContextIdentifier = "Clearance"
assert subject.is_box_representation(representation) is False
class TestIsEdited(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", bpy.data.meshes.new("Mesh"))
assert subject.is_edited(obj) is False
obj.scale[0] = 2
assert subject.is_edited(obj) is True
obj.scale[0] = 1
assert subject.is_edited(obj) is False
IfcStore.edited_objs.add(obj)
assert subject.is_edited(obj) is True
class TestIsMappedRepresentation(NewFile):
def test_run(self):
ifc = ifcopenshell.file()
@@ -327,6 +369,11 @@ class TestResolveMappedRepresentation(NewFile):
assert subject.resolve_mapped_representation(representation) == representation
class TestRunGeometryUpdateRepresentation(NewFile):
def test_nothing(self):
pass
class TestShouldForceFacetedBrep(NewFile):
def test_run(self):
result = bpy.context.scene.BIMGeometryProperties.should_force_faceted_brep