mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
#2094. Removing styles now also purges Blender material object if possible.
This commit is contained in:
@@ -59,9 +59,10 @@ class RemoveStyle(bpy.types.Operator, Operator):
|
||||
bl_idname = "bim.remove_style"
|
||||
bl_label = "Remove Style"
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
style: bpy.props.IntProperty()
|
||||
|
||||
def _execute(self, context):
|
||||
core.remove_style(tool.Ifc, tool.Style, obj=context.active_object.active_material)
|
||||
core.remove_style(tool.Ifc, tool.Material, tool.Style, style=tool.Ifc.get().by_id(self.style))
|
||||
|
||||
|
||||
class AddStyle(bpy.types.Operator, Operator):
|
||||
|
||||
@@ -51,15 +51,15 @@ class BIM_PT_styles(Panel):
|
||||
row.operator("bim.load_styles", text="", icon="IMPORT").style_type = self.props.style_type
|
||||
return
|
||||
|
||||
#row = self.layout.row(align=True)
|
||||
#row.alignment = "RIGHT"
|
||||
row = self.layout.row(align=True)
|
||||
row.alignment = "RIGHT"
|
||||
|
||||
#row.operator("bim.add_presentation_style", text="", icon="ADD")
|
||||
#if self.props.styles and self.props.active_style_index < len(self.props.styles):
|
||||
# style = self.props.styles[self.props.active_style_index]
|
||||
if self.props.styles and self.props.active_style_index < len(self.props.styles):
|
||||
style = self.props.styles[self.props.active_style_index]
|
||||
# op = row.operator("bim.select_by_style", text="", icon="RESTRICT_SELECT_OFF")
|
||||
# op.style = style.ifc_definition_id
|
||||
# row.operator("bim.remove_style", text="", icon="X").style = style.ifc_definition_id
|
||||
row.operator("bim.remove_style", text="", icon="X").style = style.ifc_definition_id
|
||||
|
||||
self.layout.template_list("BIM_UL_styles", "", self.props, "styles", self.props, "active_style_index")
|
||||
|
||||
@@ -86,7 +86,7 @@ class BIM_PT_style(Panel):
|
||||
row.operator("bim.update_style_colours", icon="GREASEPENCIL")
|
||||
row.operator("bim.update_style_textures", icon="TEXTURE", text="")
|
||||
row.operator("bim.unlink_style", icon="UNLINKED", text="")
|
||||
row.operator("bim.remove_style", icon="X", text="")
|
||||
row.operator("bim.remove_style", icon="X", text="").style = props.ifc_style_id
|
||||
else:
|
||||
row.operator("bim.add_style", icon="ADD")
|
||||
|
||||
|
||||
@@ -33,10 +33,14 @@ def add_style(ifc, style, obj=None):
|
||||
return element
|
||||
|
||||
|
||||
def remove_style(ifc, style, obj=None):
|
||||
element = style.get_style(obj)
|
||||
ifc.unlink(obj=obj, element=element)
|
||||
ifc.run("style.remove_style", style=element)
|
||||
def remove_style(ifc, material, style_tool, style=None):
|
||||
obj = ifc.get_object(style)
|
||||
ifc.unlink(obj=obj, element=style)
|
||||
ifc.run("style.remove_style", style=style)
|
||||
if obj and not ifc.get_entity(obj):
|
||||
material.delete_object(obj)
|
||||
if style_tool.is_editing_styles():
|
||||
style_tool.import_presentation_styles(style_tool.get_active_style_type())
|
||||
|
||||
|
||||
def update_style_colours(ifc, style, obj=None):
|
||||
|
||||
@@ -436,6 +436,7 @@ class Style:
|
||||
def enable_editing(cls, obj): pass
|
||||
def enable_editing_styles(cls): pass
|
||||
def export_surface_attributes(cls, obj): pass
|
||||
def get_active_style_type(cls): pass
|
||||
def get_context(cls, obj): pass
|
||||
def get_name(cls, obj): pass
|
||||
def get_style(cls, obj): pass
|
||||
@@ -447,6 +448,7 @@ class Style:
|
||||
def get_uv_maps(cls, representation): pass
|
||||
def import_presentation_styles(cls, style_type): pass
|
||||
def import_surface_attributes(cls, style, obj): pass
|
||||
def is_editing_styles(cls): pass
|
||||
|
||||
|
||||
@interface
|
||||
|
||||
@@ -48,6 +48,10 @@ class Style(blenderbim.core.tool.Style):
|
||||
def export_surface_attributes(cls, obj):
|
||||
return blenderbim.bim.helper.export_attributes(obj.BIMStyleProperties.attributes)
|
||||
|
||||
@classmethod
|
||||
def get_active_style_type(cls):
|
||||
return bpy.context.scene.BIMStylesProperties.style_type
|
||||
|
||||
@classmethod
|
||||
def get_context(cls, obj):
|
||||
return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
|
||||
@@ -188,3 +192,7 @@ class Style(blenderbim.core.tool.Style):
|
||||
def import_surface_attributes(cls, style, obj):
|
||||
obj.BIMStyleProperties.attributes.clear()
|
||||
blenderbim.bim.helper.import_attributes2(style, obj.BIMStyleProperties.attributes)
|
||||
|
||||
@classmethod
|
||||
def is_editing_styles(cls):
|
||||
return bpy.context.scene.BIMStylesProperties.is_editing
|
||||
|
||||
@@ -112,7 +112,6 @@ Scenario: Assign material - Assign a material profile set
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Select by material
|
||||
Scenario: Load materials - then add material
|
||||
Given an empty IFC project
|
||||
And I press "bim.load_materials"
|
||||
And I press "bim.add_material(obj='')"
|
||||
|
||||
@@ -14,7 +14,8 @@ Scenario: Remove style
|
||||
And I add a cube
|
||||
And I add a material
|
||||
And I press "bim.add_style"
|
||||
When I press "bim.remove_style"
|
||||
And the variable "style" is "{ifc}.by_type('IfcSurfaceStyle')[0].id()"
|
||||
When I press "bim.remove_style(style={style})"
|
||||
Then nothing happens
|
||||
|
||||
Scenario: Add style
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import blenderbim.core.style as subject
|
||||
from test.core.bootstrap import ifc, style
|
||||
from test.core.bootstrap import ifc, material, style
|
||||
|
||||
|
||||
class TestAddStyle:
|
||||
@@ -53,11 +53,32 @@ class TestAddStyle:
|
||||
|
||||
|
||||
class TestRemoveStyle:
|
||||
def test_run(self, ifc, style):
|
||||
style.get_style("obj").should_be_called().will_return("style")
|
||||
def test_removing_a_style(self, ifc, material, style):
|
||||
ifc.get_object("style").should_be_called().will_return("obj")
|
||||
ifc.unlink(obj="obj", element="style").should_be_called()
|
||||
ifc.run("style.remove_style", style="style").should_be_called()
|
||||
subject.remove_style(ifc, style, obj="obj")
|
||||
ifc.get_entity("obj").should_be_called().will_return("material")
|
||||
style.is_editing_styles().should_be_called().will_return(False)
|
||||
subject.remove_style(ifc, material, style, style="style")
|
||||
|
||||
def test_removing_a_style_and_reloading_imported_styles(self, ifc, material, style):
|
||||
ifc.get_object("style").should_be_called().will_return("obj")
|
||||
ifc.unlink(obj="obj", element="style").should_be_called()
|
||||
ifc.run("style.remove_style", style="style").should_be_called()
|
||||
ifc.get_entity("obj").should_be_called().will_return("material")
|
||||
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()
|
||||
subject.remove_style(ifc, material, style, style="style")
|
||||
|
||||
def test_removing_an_object_if_it_is_not_still_used_for_a_material(self, ifc, material, style):
|
||||
ifc.get_object("style").should_be_called().will_return("obj")
|
||||
ifc.unlink(obj="obj", element="style").should_be_called()
|
||||
ifc.run("style.remove_style", style="style").should_be_called()
|
||||
ifc.get_entity("obj").should_be_called().will_return(None)
|
||||
material.delete_object("obj").should_be_called()
|
||||
style.is_editing_styles().should_be_called().will_return(False)
|
||||
subject.remove_style(ifc, material, style, style="style")
|
||||
|
||||
|
||||
class TestUpdateStyleColours:
|
||||
|
||||
@@ -78,6 +78,16 @@ class TestExportSurfaceAttributes(NewFile):
|
||||
assert subject.export_surface_attributes(obj) == {"Name": "Name", "Side": "BOTH"}
|
||||
|
||||
|
||||
class TestGetActiveStyleType(NewFile):
|
||||
def test_run(self):
|
||||
ifc = ifcopenshell.file()
|
||||
tool.Ifc.set(ifc)
|
||||
bpy.context.scene.BIMStylesProperties.style_type = "IfcSurfaceStyle"
|
||||
assert subject.get_active_style_type() == "IfcSurfaceStyle"
|
||||
bpy.context.scene.BIMStylesProperties.style_type = "IfcCurveStyle"
|
||||
assert subject.get_active_style_type() == "IfcCurveStyle"
|
||||
|
||||
|
||||
class TestGetContext(NewFile):
|
||||
def test_run(self):
|
||||
bpy.ops.bim.create_project()
|
||||
@@ -408,3 +418,11 @@ class TestImportPresentationStyles(NewFile):
|
||||
assert props.styles[0].ifc_definition_id == style.id()
|
||||
assert props.styles[0].name == "Name"
|
||||
assert props.styles[0].total_elements == 0
|
||||
|
||||
|
||||
class TestIsEditingStyles(NewFile):
|
||||
def test_run(self):
|
||||
bpy.context.scene.BIMStylesProperties.is_editing = False
|
||||
subject.is_editing_styles() is False
|
||||
bpy.context.scene.BIMStylesProperties.is_editing = True
|
||||
subject.is_editing_styles() is True
|
||||
|
||||
Reference in New Issue
Block a user