mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
#2094. Deleting materials now also deletes Blender material if not used for a style
This commit is contained in:
@@ -46,8 +46,18 @@ Scenario: Remove material
|
||||
And the object "Cube" is selected
|
||||
And I add a material
|
||||
And I press "bim.add_material(obj='Material')"
|
||||
When I press "bim.remove_material"
|
||||
Then the material "Material" is not an IFC material
|
||||
And the variable "material" is "{ifc}.by_type('IfcMaterial')[0].id()"
|
||||
When I press "bim.remove_material(material={material})"
|
||||
Then the material "Material" does not exist
|
||||
|
||||
Scenario: Remove material set
|
||||
Given an empty IFC project
|
||||
And I set "scene.BIMMaterialProperties.material_type" to "IfcMaterialLayerSet"
|
||||
And I press "bim.load_materials"
|
||||
And I press "bim.add_material_set(set_type='IfcMaterialLayerSet')"
|
||||
And the variable "material" is "{ifc}.by_type('IfcMaterialLayerSet')[0].id()"
|
||||
When I press "bim.remove_material_set(material={material})"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Unlink material
|
||||
Given an empty IFC project
|
||||
|
||||
@@ -297,6 +297,11 @@ def the_material_name_exists(name) -> bpy.types.Material:
|
||||
return obj
|
||||
|
||||
|
||||
@then(parsers.parse('the material "{name}" does not exist'))
|
||||
def the_material_name_does_not_exist(name):
|
||||
assert bpy.data.materials.get(name) is None, "Material exists"
|
||||
|
||||
|
||||
@then("an IFC file does not exist")
|
||||
def an_ifc_file_does_not_exist():
|
||||
ifc = IfcStore.get_file()
|
||||
|
||||
@@ -92,6 +92,50 @@ class TestAddMaterialSet:
|
||||
assert subject.add_material_set(ifc, material, set_type="set_type") == "material"
|
||||
|
||||
|
||||
class TestRemoveMaterial:
|
||||
def test_removing_a_material(self, ifc, material, style):
|
||||
ifc.get_object("material").should_be_called().will_return(None)
|
||||
ifc.unlink(element="material").should_be_called()
|
||||
ifc.run("material.remove_material", material="material").should_be_called()
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
subject.remove_material(ifc, material, style, material="material")
|
||||
|
||||
def test_removing_a_material_and_reloading_imported_materials(self, ifc, material, style):
|
||||
ifc.get_object("material").should_be_called().will_return(None)
|
||||
ifc.unlink(element="material").should_be_called()
|
||||
ifc.run("material.remove_material", material="material").should_be_called()
|
||||
material.is_editing_materials().should_be_called().will_return(True)
|
||||
material.get_active_material_type().should_be_called().will_return("material_type")
|
||||
material.import_material_definitions("material_type").should_be_called()
|
||||
subject.remove_material(ifc, material, style, material="material")
|
||||
|
||||
def test_removing_a_material_object_if_it_has_no_style(self, ifc, material, style):
|
||||
ifc.get_object("material").should_be_called().will_return("obj")
|
||||
ifc.unlink(element="material").should_be_called()
|
||||
ifc.run("material.remove_material", material="material").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return(None)
|
||||
material.delete_object("obj").should_be_called()
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
subject.remove_material(ifc, material, style, material="material")
|
||||
|
||||
def test_preserving_a_material_object_if_it_is_still_used_as_a_style(self, ifc, material, style):
|
||||
ifc.get_object("material").should_be_called().will_return("obj")
|
||||
ifc.unlink(element="material").should_be_called()
|
||||
ifc.run("material.remove_material", material="material").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
subject.remove_material(ifc, material, style, material="material")
|
||||
|
||||
|
||||
class TestRemoveMaterialSet:
|
||||
def test_run(self, ifc, material):
|
||||
ifc.run("material.remove_material_set", material="material").should_be_called()
|
||||
material.is_editing_materials().should_be_called().will_return(True)
|
||||
material.get_active_material_type().should_be_called().will_return("material_type")
|
||||
material.import_material_definitions("material_type").should_be_called()
|
||||
subject.remove_material_set(ifc, material, material="material")
|
||||
|
||||
|
||||
class TestLoadMaterials:
|
||||
def test_run(self, material):
|
||||
material.import_material_definitions("material_type").should_be_called()
|
||||
|
||||
@@ -36,6 +36,14 @@ class TestAddDefaultMaterialObject(NewFile):
|
||||
assert material.name == "Default"
|
||||
|
||||
|
||||
class TestDeleteObject(NewFile):
|
||||
def test_run(self):
|
||||
material = subject.add_default_material_object()
|
||||
assert bpy.data.materials.get("Default")
|
||||
subject.delete_object(material)
|
||||
assert not bpy.data.materials.get("Default")
|
||||
|
||||
|
||||
class TestDisableEditingMaterials(NewFile):
|
||||
def test_run(self):
|
||||
bpy.context.scene.BIMMaterialProperties.is_editing = True
|
||||
|
||||
Reference in New Issue
Block a user