deprecate Style.get_style

In favor of Ifc.get_entity
This commit is contained in:
Andrej730
2024-10-23 11:38:55 +05:00
parent 863633f2dc
commit b61927b460
5 changed files with 17 additions and 25 deletions
@@ -272,7 +272,7 @@ class UnlinkObject(bpy.types.Operator, tool.Ifc.Operator):
material_replacement = replacements[material]
# no need to copy non-ifc materials as unlinking won't do anything to them
elif tool.Ifc.get_entity(material) is None and tool.Style.get_style(material) is None:
elif tool.Ifc.get_entity(material) is None:
replacements[material] = material
continue
+4 -4
View File
@@ -39,7 +39,7 @@ def add_style(ifc: tool.Ifc, style: tool.Style, obj: bpy.types.Material) -> ifco
# TODO: outdated.
def add_external_style(ifc: tool.Ifc, style: tool.Style, obj: bpy.types.Material, attributes: dict[str, Any]) -> None:
element = style.get_style(obj)
element = ifc.get_entity(obj)
ifc.run(
"style.add_surface_style", style=element, ifc_class="IfcExternallyDefinedSurfaceStyle", attributes=attributes
)
@@ -77,7 +77,7 @@ def remove_style(
def update_style_colours(ifc: tool.Ifc, style: tool.Style, obj: bpy.types.Material, verbose: bool = False) -> None:
element = style.get_style(obj)
element = ifc.get_entity(obj)
if style.can_support_rendering_style(obj):
rendering_style = style.get_surface_rendering_style(obj)
@@ -114,7 +114,7 @@ def update_style_colours(ifc: tool.Ifc, style: tool.Style, obj: bpy.types.Materi
def update_style_textures(
ifc: tool.Ifc, style: tool.Style, obj: ifcopenshell.entity_instance, representation: ifcopenshell.entity_instance
) -> None:
element = style.get_style(obj)
element = ifc.get_entity(obj)
uv_maps = style.get_uv_maps(representation)
textures = ifc.run("style.add_surface_textures", material=obj, uv_maps=uv_maps)
@@ -151,7 +151,7 @@ def disable_editing_style(style: tool.Style) -> None:
def edit_style(ifc: tool.Ifc, style: tool.Style) -> None:
obj = style.get_currently_edited_material()
style_element = style.get_style(obj)
style_element = ifc.get_entity(obj)
assert style_element
attributes = style.export_surface_attributes()
is_style_side_attribute_edited = style.is_style_side_attribute_edited(style_element, attributes)
+2 -2
View File
@@ -583,7 +583,7 @@ class Geometry(bonsai.core.tool.Geometry):
def get_styles(
cls, obj: bpy.types.Object, only_assigned_to_faces: bool = False
) -> list[Union[ifcopenshell.entity_instance, None]]:
styles = [tool.Style.get_style(s.material) for s in obj.material_slots if s.material]
styles = [tool.Ifc.get_entity(s.material) for s in obj.material_slots if s.material]
if not only_assigned_to_faces:
return styles
@@ -1632,7 +1632,7 @@ class Geometry(bonsai.core.tool.Geometry):
material_index = mesh.polygons[0].material_index
if materials := list(mesh.materials):
material = materials[material_index]
if not (style := tool.Style.get_style(material)):
if not (style := tool.Ifc.get_entity(material)):
style = ifcopenshell.api.run("style.add_style", tool.Ifc.get(), name=material.name)
if material.use_nodes:
ifc_class = "IfcSurfaceStyleRendering"
-8
View File
@@ -143,14 +143,6 @@ class Style(bonsai.core.tool.Style):
assert isinstance(obj, bpy.types.Material)
return obj
@classmethod
def get_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]:
"""Get linked IFC style based on material's BIMStyleProperties.ifc_definition_id.
Return None if material is not linked to IFC or it's linked to non-existent element.
"""
return tool.Ifc.get_entity(obj)
@classmethod
def get_style_elements(
cls, blender_material_or_style: Union[bpy.types.Material, ifcopenshell.entity_instance]
+10 -10
View File
@@ -69,7 +69,7 @@ class TestRemoveStyle:
class TestUpdateStyleColours:
def test_updating_rendering_style_if_available(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.can_support_rendering_style("obj").should_be_called().will_return(True)
style.get_surface_rendering_style("obj").should_be_called().will_return("rendering_style")
@@ -85,7 +85,7 @@ class TestUpdateStyleColours:
subject.update_style_colours(ifc, style, obj="obj", verbose="verbose")
def test_adding_a_rendering_style_if_not_available(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.can_support_rendering_style("obj").should_be_called().will_return(True)
style.get_surface_rendering_style("obj").should_be_called().will_return(None)
@@ -106,7 +106,7 @@ class TestUpdateStyleColours:
subject.update_style_colours(ifc, style, obj="obj", verbose="verbose")
def test_updating_shading_style_as_a_fallback_if_available(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.can_support_rendering_style("obj").should_be_called().will_return(False)
style.get_surface_shading_style("obj").should_be_called().will_return("style")
style.get_surface_shading_attributes("obj").should_be_called().will_return("attributes")
@@ -114,7 +114,7 @@ class TestUpdateStyleColours:
subject.update_style_colours(ifc, style, obj="obj")
def test_adding_a_shading_style_as_a_fallback_if_not_available(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.can_support_rendering_style("obj").should_be_called().will_return(False)
style.get_surface_shading_style("obj").should_be_called().will_return(None)
style.get_surface_shading_attributes("obj").should_be_called().will_return("attributes")
@@ -126,7 +126,7 @@ class TestUpdateStyleColours:
class TestUpdateStyleTextures:
def test_updating_an_existing_texture_style(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.get_uv_maps("representation").should_be_called().will_return("uv_maps")
ifc.run("style.add_surface_textures", material="obj", uv_maps="uv_maps").should_be_called().will_return(
"textures"
@@ -142,7 +142,7 @@ class TestUpdateStyleTextures:
subject.update_style_textures(ifc, style, obj="obj", representation="representation")
def test_adding_a_fresh_texture_style(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.get_uv_maps("representation").should_be_called().will_return("uv_maps")
ifc.run("style.add_surface_textures", material="obj", uv_maps="uv_maps").should_be_called().will_return(
"textures"
@@ -157,7 +157,7 @@ class TestUpdateStyleTextures:
subject.update_style_textures(ifc, style, obj="obj", representation="representation")
def test_removing_an_texture_if_no_textures_can_be_added(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.get_uv_maps("representation").should_be_called().will_return("uv_maps")
ifc.run("style.add_surface_textures", material="obj", uv_maps="uv_maps").should_be_called().will_return(None)
style.get_surface_texture_style("obj").should_be_called().will_return("style")
@@ -165,7 +165,7 @@ class TestUpdateStyleTextures:
subject.update_style_textures(ifc, style, obj="obj", representation="representation")
def test_doing_nothing_if_no_existing_texture_and_we_cannot_add_a_new_texture(self, ifc, style):
style.get_style("obj").should_be_called().will_return("element")
ifc.get_entity("obj").should_be_called().will_return("element")
style.get_uv_maps("representation").should_be_called().will_return("uv_maps")
ifc.run("style.add_surface_textures", material="obj", uv_maps="uv_maps").should_be_called().will_return(None)
style.get_surface_texture_style("obj").should_be_called().will_return(None)
@@ -197,7 +197,7 @@ class TestDisableEditingStyle:
class TestEditStyle:
def test_run_side_attr_updated(self, ifc, style):
style.get_currently_edited_material().should_be_called().will_return("obj")
style.get_style("obj").should_be_called().will_return("style_element")
ifc.get_entity("obj").should_be_called().will_return("style_element")
style.export_surface_attributes().should_be_called().will_return("attributes")
style.is_style_side_attribute_edited("style_element", "attributes").should_be_called().will_return(True)
ifc.run("style.edit_presentation_style", style="style_element", attributes="attributes").should_be_called()
@@ -214,7 +214,7 @@ class TestEditStyle:
def test_run_side_attr_unchanged(self, ifc, style):
style.get_currently_edited_material().should_be_called().will_return("obj")
style.get_style("obj").should_be_called().will_return("style_element")
ifc.get_entity("obj").should_be_called().will_return("style_element")
style.export_surface_attributes().should_be_called().will_return("attributes")
style.is_style_side_attribute_edited("style_element", "attributes").should_be_called().will_return(False)
ifc.run("style.edit_presentation_style", style="style_element", attributes="attributes").should_be_called()