From 04e703b3ee2ce5dfb78025b9acd549ddd31a3be3 Mon Sep 17 00:00:00 2001 From: Durman Date: Thu, 5 May 2022 14:44:05 +0400 Subject: [PATCH] add list available sockets for group tree fix displaying property in GroupOutputNode fix showing default properties of generated Interface socket classes --- core/node_group.py | 20 +++++++++++++++----- core/sockets.py | 22 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/core/node_group.py b/core/node_group.py index 2007f8418e..e1c56270f9 100644 --- a/core/node_group.py +++ b/core/node_group.py @@ -17,6 +17,7 @@ from sverchok.data_structure import extend_blender_class from mathutils import Vector +from sverchok.core.sockets import socket_type_names from sverchok.core.group_handlers import MainHandler, NodeIdManager from sverchok.core.events import GroupEvent from sverchok.utils.tree_structure import Tree, Node @@ -125,11 +126,14 @@ def update_sockets(self): # todo it lets simplify sockets API n_in_s.use_prop = not t_in_s.hide_value if hasattr(t_in_s, 'default_type'): n_in_s.default_property_type = t_in_s.default_type - for node in (n for n in self.nodes if n.bl_idname == 'NodeGroupOutput'): - for n_in_s, t_out_s in zip(node.inputs, self.outputs): - n_in_s.use_prop = not t_out_s.hide_value - if hasattr(t_out_s, 'default_type'): - n_in_s.default_property_type = t_out_s.default_type + for out_node in (n for n in self.nodes if n.bl_idname == 'NodeGroupOutput'): + for n_in_s, t_out_s in zip(out_node.inputs, self.outputs): + if hasattr(n_in_s, 'default_property'): + n_in_s.use_prop = not t_out_s.hide_value + if hasattr(t_out_s, 'default_type'): + n_in_s.default_property_type = t_out_s.default_type + else: + n_in_s.use_prop = False def check_reroutes_sockets(self): """ @@ -258,6 +262,12 @@ def get_update_path(self) -> List['SvGroupTreeNode']: return group_nodes raise LookupError(f'Path the group tree: {self} was not found') + if bpy.app.version >= (3, 2): # in 3.1 this can lead to a crash + @classmethod + def valid_socket_type(cls, socket_type: str): + # https://docs.blender.org/api/master/bpy.types.NodeTree.html#bpy.types.NodeTree.valid_socket_type + return socket_type in socket_type_names() + class BaseNode: n_id: bpy.props.StringProperty(options={'SKIP_SAVE'}) diff --git a/core/sockets.py b/core/sockets.py index 5b0183c01c..a922695914 100644 --- a/core/sockets.py +++ b/core/sockets.py @@ -16,6 +16,9 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # ##### END GPL LICENSE BLOCK ##### +import inspect +import sys +from typing import Set from mathutils import Matrix, Quaternion import bpy @@ -73,6 +76,17 @@ def update_interface(self, context): if input_node: group_tree.update_nodes([input_node]) + +def socket_type_names() -> Set[str]: + names = set() + for name, member in inspect.getmembers(sys.modules[__name__]): + is_module_cls = inspect.isclass(member) and member.__module__ == __name__ + if is_module_cls: + if NodeSocket in member.__bases__: + names.add(member.bl_idname) + return names + + class SV_MT_AllSocketsOptionsMenu(bpy.types.Menu): bl_label = "Sockets Options" @@ -1481,13 +1495,17 @@ def socket_interface_classes(): prop_args['name'] = "Default value" prop_args['update'] = lambda s, c: s.id_data.update_sockets() socket_interface_attributes['__annotations__'] = {} - socket_interface_attributes['__annotations__']['default_value'] = (prop_func, prop_args) + socket_interface_attributes['__annotations__']['default_value'] = socket_cls.__annotations__['default_property'] def draw(self, context, layout): col = layout.column() col.prop(self, 'default_value') col.prop(self, 'hide_value') - socket_interface_attributes['draw'] = draw + else: + def draw(self, context, layout): + pass + + socket_interface_attributes['draw'] = draw yield type( f'{socket_cls.__name__}Interface', (bpy.types.NodeSocketInterface,), socket_interface_attributes)