mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-07 00:11:36 +00:00
unassociate bim.add_material from blender materials #4843
This commit is contained in:
@@ -118,7 +118,6 @@ class AddMaterial(bpy.types.Operator, tool.Ifc.Operator):
|
||||
bl_idname = "bim.add_material"
|
||||
bl_label = "Add Material"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
obj: bpy.props.StringProperty(name="Material Name")
|
||||
name: bpy.props.StringProperty(default="Default")
|
||||
category: bpy.props.StringProperty(default="")
|
||||
description: bpy.props.StringProperty(default="")
|
||||
@@ -135,8 +134,7 @@ class AddMaterial(bpy.types.Operator, tool.Ifc.Operator):
|
||||
row.prop(self, "category", text="Category")
|
||||
|
||||
def _execute(self, context):
|
||||
obj = bpy.data.materials.get(self.obj) if self.obj else None
|
||||
core.add_material(tool.Ifc, tool.Material, tool.Style, obj=obj, name=self.name, category=self.category, description=self.description)
|
||||
core.add_material(tool.Ifc, tool.Material, name=self.name, category=self.category, description=self.description)
|
||||
material_prop_purge()
|
||||
|
||||
|
||||
|
||||
@@ -28,23 +28,11 @@ if TYPE_CHECKING:
|
||||
def add_material(
|
||||
ifc: tool.Ifc,
|
||||
material: tool.Material,
|
||||
style: tool.Style,
|
||||
obj: Optional[bpy.types.Material] = None,
|
||||
name: Optional[str] = None,
|
||||
name: str,
|
||||
category: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
) -> ifcopenshell.entity_instance:
|
||||
if not obj:
|
||||
obj = material.add_default_material_object(name)
|
||||
ifc_material = ifc.run(
|
||||
"material.add_material", name=material.get_name(obj), category=category, description=description
|
||||
)
|
||||
ifc.link(ifc_material, obj)
|
||||
ifc_style = style.get_style(obj)
|
||||
if ifc_style:
|
||||
context = style.get_context(obj)
|
||||
if context:
|
||||
ifc.run("style.assign_material_style", material=ifc_material, style=ifc_style, context=context)
|
||||
ifc_material = ifc.run("material.add_material", name=name, category=category, description=description)
|
||||
if material.is_editing_materials():
|
||||
material.import_material_definitions(material.get_active_material_type())
|
||||
return ifc_material
|
||||
@@ -57,9 +45,7 @@ def add_material_set(ifc: tool.Ifc, material: tool.Material, set_type: str) -> i
|
||||
return ifc_material
|
||||
|
||||
|
||||
def remove_material(
|
||||
ifc: tool.Ifc, material_tool: tool.Material, material: ifcopenshell.entity_instance
|
||||
) -> bool:
|
||||
def remove_material(ifc: tool.Ifc, material_tool: tool.Material, material: ifcopenshell.entity_instance) -> bool:
|
||||
"""Remove an IFC material.
|
||||
|
||||
Return True if deletion succeeded,\n
|
||||
|
||||
@@ -480,7 +480,6 @@ class Loader:
|
||||
|
||||
@interface
|
||||
class Material:
|
||||
def add_default_material_object(cls, name): pass
|
||||
def add_material_to_set(cls, material_set, material): pass
|
||||
def delete_object(cls, obj): pass
|
||||
def disable_editing_material(cls): pass
|
||||
|
||||
@@ -34,10 +34,6 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
class Material(blenderbim.core.tool.Material):
|
||||
@classmethod
|
||||
def add_default_material_object(cls, name: Union[str, None]) -> bpy.types.Material:
|
||||
return bpy.data.materials.new(name or "Default")
|
||||
|
||||
@classmethod
|
||||
def disable_editing_materials(cls) -> None:
|
||||
bpy.context.scene.BIMMaterialProperties.is_editing = False
|
||||
@@ -54,10 +50,6 @@ class Material(blenderbim.core.tool.Material):
|
||||
def get_elements_by_material(cls, material: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]:
|
||||
return ifcopenshell.util.element.get_elements_by_material(tool.Ifc.get(), material)
|
||||
|
||||
@classmethod
|
||||
def get_name(cls, obj: bpy.types.Material) -> str:
|
||||
return obj.name
|
||||
|
||||
@classmethod
|
||||
def get_active_material_item(cls) -> Union[MaterialItem, None]:
|
||||
"""Get active material props item if index is valid, otherwise, return None."""
|
||||
|
||||
@@ -21,51 +21,17 @@ from test.core.bootstrap import ifc, material, style, spatial
|
||||
|
||||
|
||||
class TestAddMaterial:
|
||||
def test_add_a_default_material(self, ifc, material, style):
|
||||
material.add_default_material_object("name").should_be_called().will_return("obj")
|
||||
material.get_name("obj").should_be_called().will_return("name")
|
||||
def test_add_a_material(self, ifc, material):
|
||||
ifc.run("material.add_material", name="name").should_be_called().will_return("material")
|
||||
ifc.link("material", "obj").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return(None)
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
assert subject.add_material(ifc, material, style, name="name") == "material"
|
||||
assert subject.add_material(ifc, material, name="name") == "material"
|
||||
|
||||
def test_add_a_material_to_a_blender_material_object(self, ifc, material, style):
|
||||
material.get_name("obj").should_be_called().will_return("name")
|
||||
def test_reloading_imported_materials_if_you_are_editing_scene_materials(self, ifc, material):
|
||||
ifc.run("material.add_material", name="name").should_be_called().will_return("material")
|
||||
ifc.link("material", "obj").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return(None)
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
assert subject.add_material(ifc, material, style, obj="obj") == "material"
|
||||
|
||||
def test_reloading_imported_materials_if_you_are_editing_scene_materials(self, ifc, material, style):
|
||||
material.get_name("obj").should_be_called().will_return("name")
|
||||
ifc.run("material.add_material", name="name").should_be_called().will_return("material")
|
||||
ifc.link("material", "obj").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return(None)
|
||||
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()
|
||||
assert subject.add_material(ifc, material, style, obj="obj") == "material"
|
||||
|
||||
def test_add_a_style_to_the_material_if_the_object_also_has_an_attached_style(self, ifc, material, style):
|
||||
material.get_name("obj").should_be_called().will_return("name")
|
||||
ifc.run("material.add_material", name="name").should_be_called().will_return("material")
|
||||
ifc.link("material", "obj").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
style.get_context("obj").should_be_called().will_return("context")
|
||||
ifc.run("style.assign_material_style", material="material", style="style", context="context").should_be_called()
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
assert subject.add_material(ifc, material, style, obj="obj") == "material"
|
||||
|
||||
def test_not_adding_a_style_if_there_is_no_style_context_available(self, ifc, material, style):
|
||||
material.get_name("obj").should_be_called().will_return("name")
|
||||
ifc.run("material.add_material", name="name").should_be_called().will_return("material")
|
||||
ifc.link("material", "obj").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
style.get_context("obj").should_be_called().will_return(None)
|
||||
material.is_editing_materials().should_be_called().will_return(False)
|
||||
assert subject.add_material(ifc, material, style, obj="obj") == "material"
|
||||
assert subject.add_material(ifc, material, name="name") == "material"
|
||||
|
||||
|
||||
class TestAddMaterialSet:
|
||||
|
||||
@@ -30,26 +30,6 @@ class TestImplementsTool(NewFile):
|
||||
assert isinstance(subject(), blenderbim.core.tool.Material)
|
||||
|
||||
|
||||
class TestAddDefaultMaterialObject(NewFile):
|
||||
def test_run(self):
|
||||
material = subject.add_default_material_object(None)
|
||||
assert isinstance(material, bpy.types.Material)
|
||||
assert material.name == "Default"
|
||||
|
||||
def test_specify_a_name(self):
|
||||
material = subject.add_default_material_object("Material")
|
||||
assert isinstance(material, bpy.types.Material)
|
||||
assert material.name == "Material"
|
||||
|
||||
|
||||
class TestDeleteObject(NewFile):
|
||||
def test_run(self):
|
||||
material = subject.add_default_material_object(None)
|
||||
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
|
||||
@@ -84,11 +64,6 @@ class TestGetElementsByMaterial(NewFile):
|
||||
assert subject.get_elements_by_material(material) == {element}
|
||||
|
||||
|
||||
class TestGetName(NewFile):
|
||||
def test_run(self):
|
||||
assert subject.get_name(bpy.data.materials.new("Material")) == "Material"
|
||||
|
||||
|
||||
class TestImportMaterialDefinitions(NewFile):
|
||||
def test_import_materials_grouped_by_categories(self):
|
||||
ifc = ifcopenshell.file()
|
||||
|
||||
Reference in New Issue
Block a user