common method for setting up Blender listeners for objects

This commit is contained in:
Andrej730
2024-10-23 14:30:01 +05:00
parent 86edd52894
commit fa29c42887
2 changed files with 12 additions and 16 deletions
+2 -11
View File
@@ -274,12 +274,7 @@ class IfcStore:
else:
obj.BIMObjectProperties.ifc_definition_id = element.id()
bonsai.bim.handler.subscribe_to(obj, "name", bonsai.bim.handler.name_callback)
if isinstance(obj, bpy.types.Object):
bonsai.bim.handler.subscribe_to(
obj, "active_material_index", bonsai.bim.handler.active_material_index_callback
)
tool.Ifc.setup_listeners(obj)
if IfcStore.history:
data = OperationData(id=element.id(), guid=getattr(element, "GlobalId", None), obj=obj.name)
@@ -301,11 +296,7 @@ class IfcStore:
IfcStore.id_map[data["id"]] = obj
if "guid" in data:
IfcStore.guid_map[data["guid"]] = obj
bonsai.bim.handler.subscribe_to(obj, "name", bonsai.bim.handler.name_callback)
if isinstance(obj, bpy.types.Object):
bonsai.bim.handler.subscribe_to(
obj, "active_material_index", bonsai.bim.handler.active_material_index_callback
)
tool.Ifc.setup_listeners(obj)
# TODO Listeners are not re-registered. Does this cause nasty problems to debug later on?
# TODO We're handling id_map and guid_map, but what about edited_objs? This might cause big problems.
+10 -5
View File
@@ -161,10 +161,7 @@ class Ifc(bonsai.core.tool.Ifc):
if global_id:
IfcStore.guid_map[global_id] = obj
bonsai.bim.handler.subscribe_to(obj, "name", bonsai.bim.handler.name_callback)
bonsai.bim.handler.subscribe_to(
obj, "active_material_index", bonsai.bim.handler.active_material_index_callback
)
cls.setup_listeners(obj)
for obj in bpy.data.materials:
if obj.library:
@@ -177,7 +174,15 @@ class Ifc(bonsai.core.tool.Ifc):
continue
IfcStore.id_map[style.id()] = obj
bonsai.bim.handler.subscribe_to(obj, "name", bonsai.bim.handler.name_callback)
cls.setup_listeners(obj)
@classmethod
def setup_listeners(cls, obj: IFC_CONNECTED_TYPE) -> None:
if isinstance(obj, bpy.types.Object):
bonsai.bim.handler.subscribe_to(
obj, "active_material_index", bonsai.bim.handler.active_material_index_callback
)
bonsai.bim.handler.subscribe_to(obj, "name", bonsai.bim.handler.name_callback)
@classmethod
def link(