mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-13 06:53:36 +00:00
Fix bug where style colours were not auto synchronised.
This commit is contained in:
@@ -387,3 +387,17 @@ Scenario: Export IFC - with changed object scale synchronised
|
||||
And an empty Blender session is started
|
||||
And I press "bim.load_project(filepath='{cwd}/test/files/export.ifc')"
|
||||
Then the object "IfcWall/Cube" dimensions are "4,4,4"
|
||||
|
||||
Scenario: Export IFC - with changed style colour synchronised
|
||||
Given an empty IFC project
|
||||
And I add a cube
|
||||
And the object "Cube" is selected
|
||||
And I add a material
|
||||
And I set "scene.BIMRootProperties.ifc_class" to "IfcWall"
|
||||
And I press "bim.assign_class"
|
||||
And the object "IfcWall/Cube" is selected
|
||||
When the material "Material" colour is set to "1,0,0,1"
|
||||
And I press "export_ifc.bim(filepath='{cwd}/test/files/export.ifc')"
|
||||
And an empty Blender session is started
|
||||
And I press "bim.load_project(filepath='{cwd}/test/files/export.ifc')"
|
||||
Then the material "Material" colour is "1,0,0,1"
|
||||
|
||||
@@ -95,6 +95,14 @@ def i_add_a_material():
|
||||
bpy.context.active_object.active_material = bpy.data.materials.new("Material")
|
||||
|
||||
|
||||
@given(parsers.parse('the material "{name}" colour is set to "{colour}"'))
|
||||
@when(parsers.parse('the material "{name}" colour is set to "{colour}"'))
|
||||
def the_material_name_colour_is_set_to_colour(name, colour):
|
||||
obj = the_material_name_exists(name)
|
||||
obj.diffuse_color = [float(c) for c in colour.split(",")]
|
||||
blenderbim.bim.handler.color_callback(obj, None)
|
||||
|
||||
|
||||
@given("I add an array modifier")
|
||||
def i_add_a_cube():
|
||||
bpy.ops.object.modifier_add(type="ARRAY")
|
||||
@@ -385,6 +393,12 @@ def the_material_name_is_not_an_ifc_material(name):
|
||||
assert id == 0, f"The ID is {id}"
|
||||
|
||||
|
||||
@then(parsers.parse('the material "{name}" colour is "{colour}"'))
|
||||
def the_material_name_colour_is_set_to_colour(name, colour):
|
||||
diffuse_color = list(the_material_name_exists(name).diffuse_color)
|
||||
assert diffuse_color == [float(c) for c in colour.split(",")], f"The colour is {diffuse_color}"
|
||||
|
||||
|
||||
@then(parsers.parse('the object "{name}" has "{number}" vertices'))
|
||||
def the_object_name_has_number_vertices(name, number):
|
||||
total = len(the_object_name_exists(name).data.vertices)
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestAddStyle:
|
||||
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()
|
||||
ifc.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"
|
||||
@@ -38,7 +38,7 @@ class TestAddStyle:
|
||||
def test_adding_a_style_linked_to_a_material(self, ifc, style):
|
||||
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()
|
||||
ifc.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"
|
||||
@@ -52,8 +52,8 @@ class TestAddStyle:
|
||||
class TestRemoveStyle:
|
||||
def test_run(self, ifc, style):
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
ifc.unlink(obj="obj", element="style").should_be_called()
|
||||
ifc.run("style.remove_style", style="style").should_be_called()
|
||||
style.unlink(obj="obj").should_be_called()
|
||||
subject.remove_style(ifc, style, obj="obj")
|
||||
|
||||
|
||||
@@ -73,9 +73,10 @@ class TestUpdateStyleColours:
|
||||
|
||||
|
||||
class TestUnlinkStyle:
|
||||
def test_run(self, style):
|
||||
style.unlink("obj").should_be_called()
|
||||
subject.unlink_style(style, obj="obj")
|
||||
def test_run(self, ifc, style):
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
ifc.unlink(obj="obj", element="style").should_be_called()
|
||||
subject.unlink_style(ifc, style, obj="obj")
|
||||
|
||||
|
||||
class TestEnableEditingStyle:
|
||||
|
||||
@@ -119,6 +119,26 @@ class TestLink(test.bim.bootstrap.NewFile):
|
||||
assert subject.get_entity(obj) == element
|
||||
assert subject.get_object(element) == obj
|
||||
|
||||
def test_link_a_style(self):
|
||||
ifc = ifcopenshell.file()
|
||||
subject.set(ifc)
|
||||
element = ifc.createIfcSurfaceStyle()
|
||||
obj = bpy.data.materials.new("Material")
|
||||
subject.link(element, obj)
|
||||
assert subject.get_object(element) == obj
|
||||
|
||||
def test_link_a_material_and_style(self):
|
||||
ifc = ifcopenshell.file()
|
||||
subject.set(ifc)
|
||||
style = ifc.createIfcSurfaceStyle()
|
||||
material = ifc.createIfcMaterial()
|
||||
obj = bpy.data.materials.new("Material")
|
||||
subject.link(style, obj)
|
||||
subject.link(material, obj)
|
||||
assert subject.get_entity(obj) == material
|
||||
assert subject.get_object(style) == obj
|
||||
assert subject.get_object(material) == obj
|
||||
|
||||
|
||||
class TestUnlink(test.bim.bootstrap.NewFile):
|
||||
def test_unlink_an_object(self):
|
||||
@@ -141,6 +161,31 @@ class TestUnlink(test.bim.bootstrap.NewFile):
|
||||
assert subject.get_entity(obj) is None
|
||||
assert subject.get_object(element) is None
|
||||
|
||||
def test_unlink_a_style(self):
|
||||
ifc = ifcopenshell.file()
|
||||
subject.set(ifc)
|
||||
element = ifc.createIfcSurfaceStyle()
|
||||
obj = bpy.data.materials.new("Material")
|
||||
subject.link(element, obj)
|
||||
subject.unlink(element, obj)
|
||||
assert subject.get_object(element) is None
|
||||
|
||||
def test_unlink_a_style_and_material(self):
|
||||
ifc = ifcopenshell.file()
|
||||
subject.set(ifc)
|
||||
style = ifc.createIfcSurfaceStyle()
|
||||
material = ifc.createIfcMaterial()
|
||||
obj = bpy.data.materials.new("Material")
|
||||
subject.link(style, obj)
|
||||
subject.link(material, obj)
|
||||
subject.unlink(element=style, obj=obj)
|
||||
assert subject.get_entity(obj) == material
|
||||
assert subject.get_object(material) == obj
|
||||
assert subject.get_object(style) is None
|
||||
subject.unlink(element=material, obj=obj)
|
||||
assert subject.get_entity(obj) is None
|
||||
assert subject.get_object(material) is None
|
||||
|
||||
def test_unlinking_using_an_object(self):
|
||||
ifc = ifcopenshell.file()
|
||||
subject.set(ifc)
|
||||
|
||||
@@ -189,22 +189,3 @@ class TestImportSurfaceAttributes(NewFile):
|
||||
assert len(obj.BIMStyleProperties.attributes) == 2
|
||||
assert obj.BIMStyleProperties.attributes.get("Name").string_value == "Name"
|
||||
assert obj.BIMStyleProperties.attributes.get("Side").enum_value == "BOTH"
|
||||
|
||||
|
||||
class TestLink(NewFile):
|
||||
def test_run(self):
|
||||
obj = bpy.data.materials.new("Material")
|
||||
ifc = ifcopenshell.file()
|
||||
style = ifc.createIfcSurfaceStyle()
|
||||
subject.link(style, obj)
|
||||
assert obj.BIMMaterialProperties.ifc_style_id == style.id()
|
||||
|
||||
|
||||
class TestUnlink(NewFile):
|
||||
def test_run(self):
|
||||
obj = bpy.data.materials.new("Material")
|
||||
ifc = ifcopenshell.file()
|
||||
style = ifc.createIfcSurfaceStyle()
|
||||
subject.link(style, obj)
|
||||
subject.unlink(obj)
|
||||
assert obj.BIMMaterialProperties.ifc_style_id == 0
|
||||
|
||||
Reference in New Issue
Block a user