mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 03:05:33 +00:00
remove some props from Material.BIMStyleProperties as deprecated #4843
This commit is contained in:
@@ -165,13 +165,7 @@ class EnableEditingStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
style: bpy.props.IntProperty(default=0)
|
style: bpy.props.IntProperty(default=0)
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = bpy.context.scene.BIMStylesProperties
|
core.enable_editing_style(tool.Style, tool.Ifc.get().by_id(self.style))
|
||||||
style = tool.Ifc.get().by_id(self.style)
|
|
||||||
props.is_editing_style = style.id()
|
|
||||||
props.is_editing_class = "IfcSurfaceStyle"
|
|
||||||
attributes = props.attributes
|
|
||||||
attributes.clear()
|
|
||||||
blenderbim.bim.helper.import_attributes2(style, attributes)
|
|
||||||
|
|
||||||
|
|
||||||
class DisableEditingStyle(bpy.types.Operator, tool.Ifc.Operator):
|
class DisableEditingStyle(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -180,16 +174,7 @@ class DisableEditingStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_label = "Disable Editing Style"
|
bl_label = "Disable Editing Style"
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = bpy.context.scene.BIMStylesProperties
|
core.disable_editing_style(tool.Style)
|
||||||
|
|
||||||
style = tool.Ifc.get().by_id(props.is_editing_style)
|
|
||||||
material = tool.Ifc.get_object(style)
|
|
||||||
tool.Style.reload_material_from_ifc(material)
|
|
||||||
props.is_editing_style = 0
|
|
||||||
|
|
||||||
# restore selected style type
|
|
||||||
material = tool.Ifc.get_object(style)
|
|
||||||
material.BIMStyleProperties.active_style_type = material.BIMStyleProperties.active_style_type
|
|
||||||
|
|
||||||
|
|
||||||
class EditStyle(bpy.types.Operator, tool.Ifc.Operator):
|
class EditStyle(bpy.types.Operator, tool.Ifc.Operator):
|
||||||
@@ -198,12 +183,7 @@ class EditStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def _execute(self, context):
|
def _execute(self, context):
|
||||||
props = bpy.context.scene.BIMStylesProperties
|
core.edit_style(tool.Ifc, tool.Style)
|
||||||
style = tool.Ifc.get().by_id(props.is_editing_style)
|
|
||||||
attributes = blenderbim.bim.helper.export_attributes(props.attributes)
|
|
||||||
ifcopenshell.api.run("style.edit_presentation_style", tool.Ifc.get(), style=style, attributes=attributes)
|
|
||||||
props.is_editing_style = 0
|
|
||||||
core.load_styles(tool.Style, style_type=props.style_type)
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateCurrentStyle(bpy.types.Operator):
|
class UpdateCurrentStyle(bpy.types.Operator):
|
||||||
|
|||||||
@@ -291,12 +291,6 @@ def update_shading_style(self, context):
|
|||||||
|
|
||||||
class BIMStyleProperties(PropertyGroup):
|
class BIMStyleProperties(PropertyGroup):
|
||||||
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
ifc_definition_id: IntProperty(name="IFC Definition ID")
|
||||||
# TODO: remove, as attributes already moved to styles ui
|
|
||||||
attributes: CollectionProperty(name="Attributes", type=Attribute)
|
|
||||||
is_editing: BoolProperty(name="Is Editing")
|
|
||||||
external_style_attributes: CollectionProperty(name="External Style Attributes", type=Attribute)
|
|
||||||
is_editing_external_style: BoolProperty(name="Is Editing External Style")
|
|
||||||
|
|
||||||
active_style_type: EnumProperty(
|
active_style_type: EnumProperty(
|
||||||
name="Active Style Type",
|
name="Active Style Type",
|
||||||
description="Update current blender material to match style type",
|
description="Update current blender material to match style type",
|
||||||
|
|||||||
@@ -58,9 +58,7 @@ def update_external_style(
|
|||||||
ifc.run("style.edit_surface_style", style=external_style, attributes=attributes)
|
ifc.run("style.edit_surface_style", style=external_style, attributes=attributes)
|
||||||
|
|
||||||
|
|
||||||
def remove_style(
|
def remove_style(ifc: tool.Ifc, style_tool: tool.Style, style: ifcopenshell.entity_instance) -> None:
|
||||||
ifc: tool.Ifc, style_tool: tool.Style, style: ifcopenshell.entity_instance
|
|
||||||
) -> None:
|
|
||||||
obj = ifc.get_object(style)
|
obj = ifc.get_object(style)
|
||||||
ifc.unlink(element=style)
|
ifc.unlink(element=style)
|
||||||
ifc.run("style.remove_style", style=style)
|
ifc.run("style.remove_style", style=style)
|
||||||
@@ -130,19 +128,26 @@ def unlink_style(ifc: tool.Ifc, style: ifcopenshell.entity_instance) -> None:
|
|||||||
ifc.unlink(element=style)
|
ifc.unlink(element=style)
|
||||||
|
|
||||||
|
|
||||||
def enable_editing_style(style: tool.Style, obj: bpy.types.Material) -> None:
|
def enable_editing_style(style: tool.Style, style_: ifcopenshell.entity_instance) -> None:
|
||||||
style.enable_editing(obj)
|
style.enable_editing(style_)
|
||||||
style.import_surface_attributes(style.get_style(obj), obj)
|
style.import_surface_attributes(style_)
|
||||||
|
|
||||||
|
|
||||||
def disable_editing_style(style: tool.Style, obj: bpy.types.Material) -> None:
|
def disable_editing_style(style: tool.Style) -> None:
|
||||||
style.disable_editing(obj)
|
obj = style.get_currently_edited_material()
|
||||||
|
# TODO: is reloading twice necessary?
|
||||||
|
style.reload_material_from_ifc(obj)
|
||||||
|
style.disable_editing()
|
||||||
|
style.reload_material_from_ifc(obj)
|
||||||
|
|
||||||
|
|
||||||
def edit_style(ifc: tool.Ifc, style: tool.Style, obj: bpy.types.Material) -> None:
|
def edit_style(ifc: tool.Ifc, style: tool.Style) -> None:
|
||||||
attributes = style.export_surface_attributes(obj)
|
obj = style.get_currently_edited_material()
|
||||||
ifc.run("style.edit_presentation_style", style=style.get_style(obj), attributes=attributes)
|
style_ = style.get_style(obj)
|
||||||
style.disable_editing(obj)
|
attributes = style.export_surface_attributes()
|
||||||
|
ifc.run("style.edit_presentation_style", style=style_, attributes=attributes)
|
||||||
|
style.disable_editing()
|
||||||
|
load_styles(style, style.get_active_style_type())
|
||||||
|
|
||||||
|
|
||||||
def load_styles(style: tool.Style, style_type: str) -> None:
|
def load_styles(style: tool.Style, style_type: str) -> None:
|
||||||
|
|||||||
@@ -54,12 +54,8 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
bpy.data.materials.remove(obj)
|
bpy.data.materials.remove(obj)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def disable_editing(cls, obj: bpy.types.Material) -> None:
|
def disable_editing(cls) -> None:
|
||||||
obj.BIMStyleProperties.is_editing = False
|
bpy.context.scene.BIMStylesProperties.is_editing_style = 0
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def disable_editing_external_style(cls, obj: bpy.types.Material) -> None:
|
|
||||||
obj.BIMStyleProperties.is_editing_external_style = False
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def disable_editing_styles(cls) -> None:
|
def disable_editing_styles(cls) -> None:
|
||||||
@@ -72,24 +68,19 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
return new_style
|
return new_style
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enable_editing(cls, obj: bpy.types.Material) -> None:
|
def enable_editing(cls, style: ifcopenshell.entity_instance) -> None:
|
||||||
obj.BIMStyleProperties.is_editing = True
|
props = bpy.context.scene.BIMStylesProperties
|
||||||
|
props.is_editing_style = style.id()
|
||||||
@classmethod
|
props.is_editing_class = "IfcSurfaceStyle"
|
||||||
def enable_editing_external_style(cls, obj: bpy.types.Material) -> None:
|
|
||||||
obj.BIMStyleProperties.is_editing_external_style = True
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def enable_editing_styles(cls) -> None:
|
def enable_editing_styles(cls) -> None:
|
||||||
bpy.context.scene.BIMStylesProperties.is_editing = True
|
bpy.context.scene.BIMStylesProperties.is_editing = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def export_surface_attributes(cls, obj: bpy.types.Material) -> dict[str, Any]:
|
def export_surface_attributes(cls) -> dict[str, Any]:
|
||||||
return blenderbim.bim.helper.export_attributes(obj.BIMStyleProperties.attributes)
|
props = bpy.context.scene.BIMStylesProperties
|
||||||
|
return blenderbim.bim.helper.export_attributes(props.attributes)
|
||||||
@classmethod
|
|
||||||
def export_external_style_attributes(cls, obj: bpy.types.Material) -> dict[str, Any]:
|
|
||||||
return blenderbim.bim.helper.export_attributes(obj.BIMStyleProperties.external_style_attributes)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_active_style_type(cls) -> str:
|
def get_active_style_type(cls) -> str:
|
||||||
@@ -107,6 +98,14 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
def get_name(cls, obj: bpy.types.Material) -> str:
|
def get_name(cls, obj: bpy.types.Material) -> str:
|
||||||
return obj.name
|
return obj.name
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_currently_edited_material(cls) -> bpy.types.Material:
|
||||||
|
props = bpy.context.scene.BIMStylesProperties
|
||||||
|
style = tool.Ifc.get().by_id(props.is_editing_style)
|
||||||
|
obj = tool.Ifc.get_object(style)
|
||||||
|
assert isinstance(obj, bpy.types.Material)
|
||||||
|
return obj
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]:
|
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.
|
"""Get linked IFC style based on material's BIMStyleProperties.ifc_definition_id.
|
||||||
@@ -506,14 +505,8 @@ class Style(blenderbim.core.tool.Style):
|
|||||||
new.total_elements = len(ifcopenshell.util.element.get_elements_by_style(tool.Ifc.get(), style))
|
new.total_elements = len(ifcopenshell.util.element.get_elements_by_style(tool.Ifc.get(), style))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def import_surface_attributes(cls, style: ifcopenshell.entity_instance, obj: bpy.types.Material) -> None:
|
def import_surface_attributes(cls, style: ifcopenshell.entity_instance) -> None:
|
||||||
attributes = obj.BIMStyleProperties.attributes
|
attributes = bpy.context.scene.BIMStylesProperties.attributes
|
||||||
attributes.clear()
|
|
||||||
blenderbim.bim.helper.import_attributes2(style, attributes)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def import_external_style_attributes(cls, style: ifcopenshell.entity_instance, obj: bpy.types.Material) -> None:
|
|
||||||
attributes = obj.BIMStyleProperties.external_style_attributes
|
|
||||||
attributes.clear()
|
attributes.clear()
|
||||||
blenderbim.bim.helper.import_attributes2(style, attributes)
|
blenderbim.bim.helper.import_attributes2(style, attributes)
|
||||||
|
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ class TestCanSupportRenderingStyle(NewFile):
|
|||||||
|
|
||||||
class TestDisableEditing(NewFile):
|
class TestDisableEditing(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
obj = bpy.data.materials.new("Material")
|
props = bpy.context.scene.BIMStylesProperties
|
||||||
obj.BIMStyleProperties.is_editing = True
|
props.is_editing_style = 1
|
||||||
subject.disable_editing(obj)
|
subject.disable_editing()
|
||||||
assert obj.BIMStyleProperties.is_editing is False
|
assert props.is_editing_style == 0
|
||||||
|
|
||||||
|
|
||||||
class TestDisableEditingStyles(NewFile):
|
class TestDisableEditingStyles(NewFile):
|
||||||
@@ -62,9 +62,10 @@ class TestDisableEditingStyles(NewFile):
|
|||||||
|
|
||||||
class TestEnableEditing(NewFile):
|
class TestEnableEditing(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
obj = bpy.data.materials.new("Material")
|
props = bpy.context.scene.BIMStylesProperties
|
||||||
subject.enable_editing(obj)
|
style = ifcopenshell.file().create_entity("IfcSurfaceStyle")
|
||||||
assert obj.BIMStyleProperties.is_editing is True
|
subject.enable_editing(style)
|
||||||
|
assert props.is_editing_style is style.id()
|
||||||
|
|
||||||
|
|
||||||
class TestEnableEditingStyles(NewFile):
|
class TestEnableEditingStyles(NewFile):
|
||||||
@@ -77,8 +78,7 @@ class TestEnableEditingStyles(NewFile):
|
|||||||
class TestExportSurfaceAttributes(NewFile):
|
class TestExportSurfaceAttributes(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
TestImportSurfaceAttributes().test_run()
|
TestImportSurfaceAttributes().test_run()
|
||||||
obj = bpy.data.materials.get("Material")
|
assert subject.export_surface_attributes() == {"Name": "Name", "Side": "BOTH"}
|
||||||
assert subject.export_surface_attributes(obj) == {"Name": "Name", "Side": "BOTH"}
|
|
||||||
|
|
||||||
|
|
||||||
class TestGetActiveStyleType(NewFile):
|
class TestGetActiveStyleType(NewFile):
|
||||||
@@ -395,24 +395,24 @@ class TestGetUVMaps(NewFile):
|
|||||||
class TestImportSurfaceAttributes(NewFile):
|
class TestImportSurfaceAttributes(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
tool.Ifc.set(ifc := ifcopenshell.file())
|
tool.Ifc.set(ifc := ifcopenshell.file())
|
||||||
style = ifc.createIfcSurfaceStyle("Name", "BOTH")
|
props = bpy.context.scene.BIMStylesProperties
|
||||||
obj = bpy.data.materials.new("Material")
|
style = ifc.create_entity("IfcSurfaceStyle", "Name", "BOTH")
|
||||||
subject.import_surface_attributes(style, obj)
|
subject.import_surface_attributes(style)
|
||||||
assert obj.BIMStyleProperties.attributes.get("Name").string_value == "Name"
|
assert props.attributes.get("Name").string_value == "Name"
|
||||||
assert obj.BIMStyleProperties.attributes.get("Side").enum_value == "BOTH"
|
assert props.attributes.get("Side").enum_value == "BOTH"
|
||||||
|
|
||||||
def test_importing_surface_attributes_twice(self):
|
def test_importing_surface_attributes_twice(self):
|
||||||
tool.Ifc.set(ifc := ifcopenshell.file())
|
tool.Ifc.set(ifc := ifcopenshell.file())
|
||||||
style = ifc.createIfcSurfaceStyle("Name", "BOTH")
|
style = ifc.create_entity("IfcSurfaceStyle", "Name", "BOTH")
|
||||||
obj = bpy.data.materials.new("Material")
|
props = bpy.context.scene.BIMStylesProperties
|
||||||
subject.import_surface_attributes(style, obj)
|
subject.import_surface_attributes(style)
|
||||||
assert len(obj.BIMStyleProperties.attributes) == 2
|
assert len(props.attributes) == 2
|
||||||
assert obj.BIMStyleProperties.attributes.get("Name").string_value == "Name"
|
assert props.attributes.get("Name").string_value == "Name"
|
||||||
assert obj.BIMStyleProperties.attributes.get("Side").enum_value == "BOTH"
|
assert props.attributes.get("Side").enum_value == "BOTH"
|
||||||
subject.import_surface_attributes(style, obj)
|
subject.import_surface_attributes(style)
|
||||||
assert len(obj.BIMStyleProperties.attributes) == 2
|
assert len(props.attributes) == 2
|
||||||
assert obj.BIMStyleProperties.attributes.get("Name").string_value == "Name"
|
assert props.attributes.get("Name").string_value == "Name"
|
||||||
assert obj.BIMStyleProperties.attributes.get("Side").enum_value == "BOTH"
|
assert props.attributes.get("Side").enum_value == "BOTH"
|
||||||
|
|
||||||
|
|
||||||
class TestImportPresentationStyles(NewFile):
|
class TestImportPresentationStyles(NewFile):
|
||||||
|
|||||||
Reference in New Issue
Block a user