Fix bug where an added default material was not linked and auto synced.

This commit is contained in:
Dion Moult
2021-11-10 18:01:10 +11:00
parent a7b3b5261f
commit 28e5af853d
11 changed files with 55 additions and 42 deletions
@@ -6,7 +6,24 @@ Scenario: Add default material
When I press "bim.add_default_material"
Then the material "Default" exists
Scenario: Unlink object
Scenario: Add material
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I add a material
When I press "bim.add_material"
Then the material "Material" is an IFC material
Scenario: Remove material
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
And I add a material
And I press "bim.add_material"
When I press "bim.remove_material"
Then the material "Material" is not an IFC material
Scenario: Unlink material
Given an empty IFC project
And I add a cube
And the object "Cube" is selected
+6
View File
@@ -367,6 +367,12 @@ def the_object_name_is_not_an_ifc_element(name):
assert id != 0, f"The ID is {id}"
@then(parsers.parse('the material "{name}" is an IFC material'))
def the_material_name_is_not_an_ifc_material(name):
id = the_material_name_exists(name).BIMObjectProperties.ifc_definition_id
assert id != 0, f"The ID is {id}"
@then(parsers.parse('the material "{name}" is not an IFC material'))
def the_material_name_is_not_an_ifc_material(name):
id = the_material_name_exists(name).BIMObjectProperties.ifc_definition_id
+4 -4
View File
@@ -21,14 +21,14 @@ from test.core.bootstrap import ifc, material
class TestUnlinkMaterial:
def test_run(self, material):
material.unlink("obj").should_be_called()
subject.unlink_material(material, obj="obj")
def test_run(self, ifc):
ifc.unlink(obj="obj").should_be_called()
subject.unlink_material(ifc, obj="obj")
class TestAddDefaultMaterial:
def test_run(self, ifc, material):
material.add_default_material_object().should_be_called().will_return("obj")
ifc.run("material.add_material", name="Default").should_be_called().will_return("material")
material.link("material", "obj").should_be_called()
ifc.link("material", "obj").should_be_called()
assert subject.add_default_material(ifc, material) == "obj"
+21 -2
View File
@@ -101,7 +101,7 @@ class TestGetObject(test.bim.bootstrap.NewFile):
class TestLink(test.bim.bootstrap.NewFile):
def test_run(self):
def test_link_an_object(self):
ifc = ifcopenshell.file()
subject.set(ifc)
element = ifc.createIfcWall()
@@ -110,9 +110,18 @@ class TestLink(test.bim.bootstrap.NewFile):
assert subject.get_entity(obj) == element
assert subject.get_object(element) == obj
def test_link_a_material(self):
ifc = ifcopenshell.file()
subject.set(ifc)
element = ifc.createIfcMaterial()
obj = bpy.data.materials.new("Material")
subject.link(element, obj)
assert subject.get_entity(obj) == element
assert subject.get_object(element) == obj
class TestUnlink(test.bim.bootstrap.NewFile):
def test_run(self):
def test_unlink_an_object(self):
ifc = ifcopenshell.file()
subject.set(ifc)
element = ifc.createIfcWall()
@@ -122,6 +131,16 @@ class TestUnlink(test.bim.bootstrap.NewFile):
assert subject.get_entity(obj) is None
assert subject.get_object(element) is None
def test_unlink_a_material(self):
ifc = ifcopenshell.file()
subject.set(ifc)
element = ifc.createIfcMaterial()
obj = bpy.data.materials.new("Material")
subject.link(element, obj)
subject.unlink(element, obj)
assert subject.get_entity(obj) is None
assert subject.get_object(element) is None
def test_unlinking_using_an_object(self):
ifc = ifcopenshell.file()
subject.set(ifc)
-19
View File
@@ -34,22 +34,3 @@ class TestAddDefaultMaterialObject(NewFile):
material = subject.add_default_material_object()
assert isinstance(material, bpy.types.Material)
assert material.name == "Default"
class TestLink(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
ifc = ifcopenshell.file()
material = ifc.createIfcMaterial()
subject.link(material, obj)
assert obj.BIMObjectProperties.ifc_definition_id == material.id()
class TestUnlink(NewFile):
def test_run(self):
obj = bpy.data.materials.new("Material")
ifc = ifcopenshell.file()
material = ifc.createIfcMaterial()
subject.link(material, obj)
subject.unlink(obj)
assert obj.BIMObjectProperties.ifc_definition_id == 0