mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-24 21:59:59 +00:00
deprecate style.edit_presentation_style listener
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
from bonsai.bim.module.model import root, product, wall, slab, profile, opening, task
|
from bonsai.bim.module.model import product, wall, slab, profile, opening, task
|
||||||
from bonsai.bim.ifc import IfcStore
|
from bonsai.bim.ifc import IfcStore
|
||||||
from bpy.app.handlers import persistent
|
from bpy.app.handlers import persistent
|
||||||
|
|
||||||
@@ -29,8 +29,6 @@ def load_post(*args):
|
|||||||
# TODO: the goal is to slowly remove these API listeners. In hindsight it
|
# TODO: the goal is to slowly remove these API listeners. In hindsight it
|
||||||
# isn't a good idea because it leads to domino events being triggered. It's
|
# isn't a good idea because it leads to domino events being triggered. It's
|
||||||
# less buggy to explicitly code the logic in core.
|
# less buggy to explicitly code the logic in core.
|
||||||
ifcopenshell.api.add_pre_listener("style.edit_presentation_style", "Bonsai.Root.SyncStyleName", root.sync_name)
|
|
||||||
|
|
||||||
ifcopenshell.api.add_post_listener(
|
ifcopenshell.api.add_post_listener(
|
||||||
"geometry.add_representation", "Bonsai.Product.GenerateBox", product.generate_box
|
"geometry.add_representation", "Bonsai.Product.GenerateBox", product.generate_box
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
# Bonsai - OpenBIM Blender Add-on
|
|
||||||
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
|
|
||||||
#
|
|
||||||
# This file is part of Bonsai.
|
|
||||||
#
|
|
||||||
# Bonsai is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Bonsai is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
import bpy
|
|
||||||
import ifcopenshell.file
|
|
||||||
import bonsai.bim.handler
|
|
||||||
import bonsai.tool as tool
|
|
||||||
from bonsai.bim.ifc import IFC_CONNECTED_TYPE
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
|
|
||||||
def sync_name(usecase_path: str, ifc_file: ifcopenshell.file, settings: dict[str, Any]) -> None:
|
|
||||||
if usecase_path == "style.edit_presentation_style":
|
|
||||||
element = settings["style"]
|
|
||||||
else:
|
|
||||||
raise Exception(f"Unsupported usecase: '{usecase_path}'.")
|
|
||||||
|
|
||||||
element: ifcopenshell.entity_instance
|
|
||||||
if "Name" not in settings["attributes"]:
|
|
||||||
return
|
|
||||||
obj = tool.Ifc.get_object(element)
|
|
||||||
if not obj:
|
|
||||||
return
|
|
||||||
obj: IFC_CONNECTED_TYPE
|
|
||||||
if isinstance(obj, bpy.types.Object):
|
|
||||||
new_name = "{}/{}".format(element.is_a(), settings["attributes"]["Name"] or "Unnamed")
|
|
||||||
collection = obj.BIMObjectProperties.collection
|
|
||||||
if collection:
|
|
||||||
collection.name = new_name
|
|
||||||
elif isinstance(obj, bpy.types.Material):
|
|
||||||
new_name = settings["attributes"]["Name"] or "Unnamed"
|
|
||||||
obj.name = new_name
|
|
||||||
bonsai.bim.handler.refresh_ui_data()
|
|
||||||
@@ -840,9 +840,15 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
tool.Loader.create_surface_style_with_textures(material, self.rendering_style, texture_style)
|
tool.Loader.create_surface_style_with_textures(material, self.rendering_style, texture_style)
|
||||||
elif self.surface_style.is_a("IfcSurfaceStyle"):
|
elif self.surface_style.is_a("IfcSurfaceStyle"):
|
||||||
attributes = self.props.attributes
|
attributes = self.props.attributes
|
||||||
|
original_name = self.surface_style.Name
|
||||||
|
attributes_data = bonsai.bim.helper.export_attributes(attributes)
|
||||||
ifcopenshell.api.style.edit_presentation_style(
|
ifcopenshell.api.style.edit_presentation_style(
|
||||||
ifc_file, style=self.surface_style, attributes=bonsai.bim.helper.export_attributes(attributes)
|
ifc_file, style=self.surface_style, attributes=attributes_data
|
||||||
)
|
)
|
||||||
|
new_name = attributes_data["Name"]
|
||||||
|
if new_name != original_name:
|
||||||
|
material = tool.Ifc.get_object(self.surface_style)
|
||||||
|
material.name = new_name or "Unnamed"
|
||||||
else:
|
else:
|
||||||
attributes = tool.Style.get_style_ui_props_attributes(self.surface_style.is_a())
|
attributes = tool.Style.get_style_ui_props_attributes(self.surface_style.is_a())
|
||||||
assert attributes
|
assert attributes
|
||||||
|
|||||||
Reference in New Issue
Block a user