mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
bim.edit_style to update representations if Side was edited
Mentioned in #5604. Since IfcSurfaceStyle.Side is used during representation generation, we need to regenerate them if the value was changed. Previously it would require manual update / project reload.
This commit is contained in:
@@ -152,10 +152,14 @@ 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)
|
||||
assert style_element
|
||||
attributes = style.export_surface_attributes()
|
||||
is_style_side_attribute_edited = style.is_style_side_attribute_edited(style_element, attributes)
|
||||
ifc.run("style.edit_presentation_style", style=style_element, attributes=attributes)
|
||||
style.disable_editing()
|
||||
load_styles(style, style.get_active_style_type())
|
||||
if is_style_side_attribute_edited:
|
||||
style.reload_repersentations(style_element)
|
||||
|
||||
|
||||
def load_styles(style: tool.Style, style_type: str) -> None:
|
||||
|
||||
@@ -1015,6 +1015,8 @@ class Style:
|
||||
def import_surface_attributes(cls, style): pass
|
||||
def is_editing_styles(cls): pass
|
||||
def reload_material_from_ifc(cls, obj): pass
|
||||
def is_style_side_attribute_edited(cls, style, new_attributes): pass
|
||||
def reload_repersentations(cls, style): pass
|
||||
|
||||
|
||||
@interface
|
||||
|
||||
@@ -675,3 +675,17 @@ class Style(bonsai.core.tool.Style):
|
||||
bonsai.core.style.remove_style(tool.Ifc, tool.Style, element, reload_styles_ui=False)
|
||||
i += 1
|
||||
return i
|
||||
|
||||
@classmethod
|
||||
def is_style_side_attribute_edited(
|
||||
cls, style: ifcopenshell.entity_instance, new_attributes: dict[str, Any]
|
||||
) -> bool:
|
||||
old_value, new_value = style.Side, new_attributes["Side"]
|
||||
# Only need to reload if there it was change from/become NEGATIVE.
|
||||
return old_value != new_value and "NEGATIVE" in (old_value, new_value)
|
||||
|
||||
@classmethod
|
||||
def reload_repersentations(cls, style: ifcopenshell.entity_instance) -> None:
|
||||
elements = ifcopenshell.util.element.get_elements_by_style(tool.Ifc.get(), style)
|
||||
objects = [tool.Ifc.get_object(e) for e in elements]
|
||||
tool.Geometry.reload_representation(objects)
|
||||
|
||||
@@ -195,10 +195,28 @@ class TestDisableEditingStyle:
|
||||
|
||||
|
||||
class TestEditStyle:
|
||||
def test_run(self, ifc, style):
|
||||
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")
|
||||
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()
|
||||
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()
|
||||
|
||||
style.reload_repersentations("style_element").should_be_called()
|
||||
|
||||
subject.edit_style(ifc, style)
|
||||
|
||||
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")
|
||||
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()
|
||||
style.disable_editing().should_be_called()
|
||||
style.get_active_style_type().should_be_called().will_return("style_type")
|
||||
|
||||
Reference in New Issue
Block a user