diff --git a/src/bonsai/bonsai/bim/module/root/operator.py b/src/bonsai/bonsai/bim/module/root/operator.py index ae636f4037..5ad4aeae3e 100644 --- a/src/bonsai/bonsai/bim/module/root/operator.py +++ b/src/bonsai/bonsai/bim/module/root/operator.py @@ -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 diff --git a/src/bonsai/bonsai/core/style.py b/src/bonsai/bonsai/core/style.py index b36c9fe565..685cc2cf88 100644 --- a/src/bonsai/bonsai/core/style.py +++ b/src/bonsai/bonsai/core/style.py @@ -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) diff --git a/src/bonsai/bonsai/tool/geometry.py b/src/bonsai/bonsai/tool/geometry.py index 16ad8e006c..0e40bf3238 100644 --- a/src/bonsai/bonsai/tool/geometry.py +++ b/src/bonsai/bonsai/tool/geometry.py @@ -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" diff --git a/src/bonsai/bonsai/tool/style.py b/src/bonsai/bonsai/tool/style.py index a9b37d4678..d4beeff489 100644 --- a/src/bonsai/bonsai/tool/style.py +++ b/src/bonsai/bonsai/tool/style.py @@ -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] diff --git a/src/bonsai/test/core/test_style.py b/src/bonsai/test/core/test_style.py index 0275414084..4f7353bffe 100644 --- a/src/bonsai/test/core/test_style.py +++ b/src/bonsai/test/core/test_style.py @@ -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()