mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
fix core.style tests #4843
This commit is contained in:
@@ -34,13 +34,10 @@ def add_style(ifc: tool.Ifc, style: tool.Style, obj: bpy.types.Material) -> ifco
|
||||
else:
|
||||
attributes = style.get_surface_shading_attributes(obj)
|
||||
ifc.run("style.add_surface_style", style=element, ifc_class="IfcSurfaceStyleShading", attributes=attributes)
|
||||
|
||||
material = ifc.get_entity(obj)
|
||||
if material:
|
||||
ifc.run("style.assign_material_style", material=material, style=element, context=style.get_context())
|
||||
return element
|
||||
|
||||
|
||||
# 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)
|
||||
ifc.run(
|
||||
@@ -124,13 +121,14 @@ def update_style_textures(
|
||||
ifc.run("style.remove_surface_style", style=texture_style)
|
||||
|
||||
|
||||
# TODO: outdated.
|
||||
def unlink_style(ifc: tool.Ifc, style: ifcopenshell.entity_instance) -> None:
|
||||
ifc.unlink(element=style)
|
||||
|
||||
|
||||
def enable_editing_style(style: tool.Style, style_: ifcopenshell.entity_instance) -> None:
|
||||
style.enable_editing(style_)
|
||||
style.import_surface_attributes(style_)
|
||||
def enable_editing_style(style_tool: tool.Style, style: ifcopenshell.entity_instance) -> None:
|
||||
style_tool.enable_editing(style)
|
||||
style_tool.import_surface_attributes(style)
|
||||
|
||||
|
||||
def disable_editing_style(style: tool.Style) -> None:
|
||||
@@ -143,9 +141,9 @@ 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_ = style.get_style(obj)
|
||||
style_element = style.get_style(obj)
|
||||
attributes = style.export_surface_attributes()
|
||||
ifc.run("style.edit_presentation_style", style=style_, attributes=attributes)
|
||||
ifc.run("style.edit_presentation_style", style=style_element, attributes=attributes)
|
||||
style.disable_editing()
|
||||
load_styles(style, style.get_active_style_type())
|
||||
|
||||
|
||||
@@ -929,14 +929,16 @@ class Structural:
|
||||
@interface
|
||||
class Style:
|
||||
def can_support_rendering_style(cls, obj): pass
|
||||
def disable_editing(cls, obj): pass
|
||||
def delete_object(cls, obj): pass
|
||||
def disable_editing(cls): pass
|
||||
def disable_editing_styles(cls): pass
|
||||
def enable_editing(cls, obj): pass
|
||||
def enable_editing(cls, style): pass
|
||||
def enable_editing_styles(cls): pass
|
||||
def export_surface_attributes(cls, obj): pass
|
||||
def export_surface_attributes(cls): pass
|
||||
def get_active_style_type(cls): pass
|
||||
def get_context(cls, obj): pass
|
||||
def get_elements_by_style(cls, style): pass
|
||||
def get_currently_edited_material(cls): pass
|
||||
def get_name(cls, obj): pass
|
||||
def get_style(cls, obj): pass
|
||||
def get_style_elements(cls, blender_material): pass
|
||||
@@ -949,8 +951,9 @@ class Style:
|
||||
def get_surface_texture_style(cls, obj): pass
|
||||
def get_uv_maps(cls, representation): pass
|
||||
def import_presentation_styles(cls, style_type): pass
|
||||
def import_surface_attributes(cls, style, obj): pass
|
||||
def import_surface_attributes(cls, style): pass
|
||||
def is_editing_styles(cls): pass
|
||||
def reload_material_from_ifc(cls, obj): pass
|
||||
|
||||
|
||||
@interface
|
||||
|
||||
@@ -51,7 +51,7 @@ class Style(blenderbim.core.tool.Style):
|
||||
|
||||
@classmethod
|
||||
def delete_object(cls, obj: bpy.types.Material) -> None:
|
||||
bpy.data.materials.remove(obj)
|
||||
tool.Blender.remove_data_block(obj)
|
||||
|
||||
@classmethod
|
||||
def disable_editing(cls) -> None:
|
||||
|
||||
@@ -21,51 +21,47 @@ from test.core.bootstrap import ifc, material, style, spatial
|
||||
|
||||
|
||||
class TestAddStyle:
|
||||
def test_it_adds_a_style_with_rendering_attributes(self, ifc, style):
|
||||
def add_style_common(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")
|
||||
ifc.link("style", "obj").should_be_called()
|
||||
ifc.run("style.add_style", name="name").should_be_called().will_return("element")
|
||||
ifc.link("element", "obj").should_be_called()
|
||||
|
||||
def test_it_adds_a_style_with_rendering_attributes(self, ifc, style):
|
||||
self.add_style_common(ifc, style)
|
||||
|
||||
style.can_support_rendering_style("obj").should_be_called().will_return(True)
|
||||
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"
|
||||
"style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleRendering", attributes="attributes"
|
||||
).should_be_called()
|
||||
|
||||
ifc.get_entity("obj").should_be_called().will_return(None)
|
||||
assert subject.add_style(ifc, style, obj="obj") == "style"
|
||||
assert subject.add_style(ifc, style, obj="obj") == "element"
|
||||
|
||||
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")
|
||||
ifc.link("style", "obj").should_be_called()
|
||||
def test_it_adds_a_style_with_shading_attributes(self, ifc, style):
|
||||
self.add_style_common(ifc, style)
|
||||
|
||||
style.can_support_rendering_style("obj").should_be_called().will_return(False)
|
||||
style.get_surface_shading_attributes("obj").should_be_called().will_return("attributes")
|
||||
ifc.run(
|
||||
"style.add_surface_style", style="style", ifc_class="IfcSurfaceStyleShading", attributes="attributes"
|
||||
"style.add_surface_style", style="element", ifc_class="IfcSurfaceStyleShading", attributes="attributes"
|
||||
).should_be_called()
|
||||
|
||||
ifc.get_entity("obj").should_be_called().will_return("material")
|
||||
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()
|
||||
assert subject.add_style(ifc, style, obj="obj") == "style"
|
||||
assert subject.add_style(ifc, style, obj="obj") == "element"
|
||||
|
||||
|
||||
class TestRemoveStyle:
|
||||
def test_removing_a_style(self, ifc, style):
|
||||
def remove_a_style_common(self, ifc, style):
|
||||
ifc.get_object("style").should_be_called().will_return("obj")
|
||||
ifc.unlink(element="style").should_be_called()
|
||||
ifc.run("style.remove_style", style="style").should_be_called()
|
||||
style.delete_object("obj").should_be_called()
|
||||
|
||||
def test_removing_a_style(self, ifc, style):
|
||||
self.remove_a_style_common(ifc, style)
|
||||
style.is_editing_styles().should_be_called().will_return(False)
|
||||
subject.remove_style(ifc, style, style="style")
|
||||
|
||||
def test_removing_a_style_and_reloading_imported_styles(self, ifc, style):
|
||||
ifc.get_object("style").should_be_called().will_return("obj")
|
||||
ifc.unlink(element="style").should_be_called()
|
||||
ifc.run("style.remove_style", style="style").should_be_called()
|
||||
style.delete_object("obj").should_be_called()
|
||||
self.remove_a_style_common(ifc, style)
|
||||
style.is_editing_styles().should_be_called().will_return(True)
|
||||
style.get_active_style_type().should_be_called().will_return("style_type")
|
||||
style.import_presentation_styles("style_type").should_be_called()
|
||||
@@ -83,7 +79,9 @@ class TestUpdateStyleColours:
|
||||
ifc.run("style.edit_surface_style", style="rendering_style", attributes="attributes").should_be_called()
|
||||
|
||||
ifc.run("style.add_surface_textures", material="obj").should_be_called().will_return("textures")
|
||||
ifc.run("style.edit_surface_style", style="texture_style", attributes={"Textures": "textures"}).should_be_called().will_return("textures")
|
||||
ifc.run(
|
||||
"style.edit_surface_style", style="texture_style", attributes={"Textures": "textures"}
|
||||
).should_be_called().will_return("textures")
|
||||
|
||||
subject.update_style_colours(ifc, style, obj="obj", verbose="verbose")
|
||||
|
||||
@@ -176,33 +174,41 @@ class TestUpdateStyleTextures:
|
||||
|
||||
|
||||
class TestUnlinkStyle:
|
||||
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")
|
||||
def test_run(self, ifc):
|
||||
ifc.unlink(element="style").should_be_called()
|
||||
subject.unlink_style(ifc, style="style")
|
||||
|
||||
|
||||
class TestEnableEditingStyle:
|
||||
def test_run(self, style):
|
||||
style.enable_editing("obj").should_be_called()
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
style.import_surface_attributes("style", "obj").should_be_called()
|
||||
subject.enable_editing_style(style, obj="obj")
|
||||
style.enable_editing("style_element").should_be_called()
|
||||
style.import_surface_attributes("style_element").should_be_called()
|
||||
subject.enable_editing_style(style, style="style_element")
|
||||
|
||||
|
||||
class TestDisableEditingStyle:
|
||||
def test_run(self, style):
|
||||
style.disable_editing("obj").should_be_called()
|
||||
subject.disable_editing_style(style, obj="obj")
|
||||
style.get_currently_edited_material().should_be_called().will_return("obj")
|
||||
style.reload_material_from_ifc("obj").should_be_called()
|
||||
style.disable_editing().should_be_called()
|
||||
style.reload_material_from_ifc("obj").should_be_called()
|
||||
subject.disable_editing_style(style)
|
||||
|
||||
|
||||
class TestEditStyle:
|
||||
def test_run(self, ifc, style):
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
style.export_surface_attributes("obj").should_be_called().will_return("attributes")
|
||||
ifc.run("style.edit_presentation_style", style="style", attributes="attributes").should_be_called()
|
||||
style.disable_editing("obj").should_be_called()
|
||||
subject.edit_style(ifc, style, obj="obj")
|
||||
style.get_currently_edited_material().should_be_called().will_return("obj")
|
||||
style.get_style("obj").should_be_called().will_return("style_element")
|
||||
style.export_surface_attributes().should_be_called().will_return("attributes")
|
||||
ifc.run("style.edit_presentation_style", style="style_element", attributes="attributes").should_be_called()
|
||||
style.disable_editing().should_be_called()
|
||||
style.get_active_style_type().should_be_called().will_return("style_type")
|
||||
|
||||
# Calling core.load_styles.
|
||||
style.import_presentation_styles("style_type").should_be_called()
|
||||
style.enable_editing_styles().should_be_called()
|
||||
|
||||
subject.edit_style(ifc, style)
|
||||
|
||||
|
||||
class TestLoadStyles:
|
||||
|
||||
Reference in New Issue
Block a user