Python node operator for combined node collapsing and hiding unused sockets. Socket hide flag is added to RNA as well, but can only be set when the socket is not connected, to avoid dangling links in editor drawing. Currently this operator has no default hotkey, but can be called from the Node menu.

This commit is contained in:
Lukas Toenne
2012-08-14 17:56:33 +00:00
parent 3220ef9d95
commit e83ef85576
4 changed files with 58 additions and 1 deletions

View File

@@ -134,3 +134,34 @@ class NODE_OT_add_search(Operator):
context.window_manager.invoke_search_popup(self) context.window_manager.invoke_search_popup(self)
return {'CANCELLED'} return {'CANCELLED'}
class NODE_OT_collapse_hide_unused_toggle(Operator):
'''Toggle collapsed nodes and hide unused sockets'''
bl_idname = "node.collapse_hide_unused_toggle"
bl_label = "Collapse and Hide Unused Sockets"
bl_options = {'REGISTER', 'UNDO'}
@classmethod
def poll(cls, context):
space = context.space_data
# needs active node editor and a tree
return space.type == 'NODE_EDITOR' and space.edit_tree
def execute(self, context):
space = context.space_data
tree = space.edit_tree
for node in tree.nodes:
if node.select:
hide = not node.hide
node.hide = hide
# Note: connected sockets are ignored internally
for socket in node.inputs:
socket.hide = hide
for socket in node.outputs:
socket.hide = hide
return {'FINISHED'}

View File

@@ -182,6 +182,7 @@ class NODE_MT_node(Menu):
layout.operator("node.preview_toggle") layout.operator("node.preview_toggle")
layout.operator("node.hide_socket_toggle") layout.operator("node.hide_socket_toggle")
layout.operator("node.options_toggle") layout.operator("node.options_toggle")
layout.operator("node.collapse_hide_unused_toggle")
layout.separator() layout.separator()

View File

@@ -127,7 +127,7 @@ typedef struct bNodeSocket {
/* sock->flag, first bit is select */ /* sock->flag, first bit is select */
/* hidden is user defined, to hide unused */ /* hidden is user defined, to hide unused */
#define SOCK_HIDDEN 2 #define SOCK_HIDDEN 2
/* only used now for groups... */ /* for quick check if socket is linked */
#define SOCK_IN_USE 4 /* XXX deprecated */ #define SOCK_IN_USE 4 /* XXX deprecated */
/* unavailable is for dynamic sockets */ /* unavailable is for dynamic sockets */
#define SOCK_UNAVAIL 8 #define SOCK_UNAVAIL 8

View File

@@ -324,6 +324,20 @@ static char *rna_NodeSocket_path(PointerRNA *ptr)
return NULL; return NULL;
} }
static void rna_NodeSocket_hide_set(PointerRNA *ptr, int value)
{
bNodeSocket *sock = (bNodeSocket *)ptr->data;
/* don't hide linked sockets */
if (sock->flag & SOCK_IN_USE)
return;
if (value)
sock->flag |= SOCK_HIDDEN;
else
sock->flag &= ~SOCK_HIDDEN;
}
/* Button Set Funcs for Matte Nodes */ /* Button Set Funcs for Matte Nodes */
static void rna_Matte_t1_set(PointerRNA *ptr, float value) static void rna_Matte_t1_set(PointerRNA *ptr, float value)
{ {
@@ -4106,6 +4120,17 @@ static void rna_def_node_socket(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Group Socket", RNA_def_property_ui_text(prop, "Group Socket",
"For group nodes, the group input or output socket this corresponds to"); "For group nodes, the group input or output socket this corresponds to");
prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", SOCK_HIDDEN);
RNA_def_property_boolean_funcs(prop, NULL, "rna_NodeSocket_hide_set");
RNA_def_property_ui_text(prop, "Hide", "Hide the socket");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, NULL);
prop = RNA_def_property(srna, "is_linked", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", SOCK_IN_USE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Linked", "True if the socket is connected");
prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE); prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SOCK_COLLAPSED); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SOCK_COLLAPSED);
RNA_def_property_ui_text(prop, "Expanded", "Socket links are expanded in the user interface"); RNA_def_property_ui_text(prop, "Expanded", "Socket links are expanded in the user interface");