Convenience fix: Exposing internal sockets now copies the default input value to...
authorLukas Toenne <lukas.toenne@googlemail.com>
Tue, 22 Feb 2011 20:49:34 +0000 (20:49 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Tue, 22 Feb 2011 20:49:34 +0000 (20:49 +0000)
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/editors/space_node/node_edit.c
source/blender/makesrna/intern/rna_nodetree.c

index 8bf2f4bb84940c91577f177f9230d277a5ef3300..41e41eab78f7fe1b889f4f60c3babc79fb069f8d 100644 (file)
@@ -212,6 +212,7 @@ void                        nodeGroupSocketUseFlags(struct bNodeTree *ngroup);
 void                   nodeGroupCopy(struct bNode *gnode);
 
 struct bNodeSocket *nodeGroupAddSocket(struct bNodeTree *ngroup, const char *name, int type, int in_out);
+struct bNodeSocket *nodeGroupExposeSocket(struct bNodeTree *ngroup, struct bNodeSocket *sock, int in_out);
 void                   nodeGroupExposeAllSockets(struct bNodeTree *ngroup);
 void                   nodeGroupRemoveSocket(struct bNodeTree *ngroup, struct bNodeSocket *gsock, int in_out);
 
index 93d0a45ae94f17b803ac47bb8c6770c692cb3320..d645bcd832961a767679b7b1f76f16aa66fc97aa 100644 (file)
@@ -476,7 +476,7 @@ bNode *nodeMakeGroupFromSelected(bNodeTree *ntree)
                        BLI_addtail(&ngroup->links, link);
                }
                else if(link->tonode && (link->tonode->flag & NODE_SELECT)) {
-                       gsock = nodeGroupAddSocket(ngroup, link->tosock->name, link->tosock->type, SOCK_IN);
+                       gsock = nodeGroupExposeSocket(ngroup, link->tosock, SOCK_IN);
                        link->tosock->link = nodeAddLink(ngroup, NULL, gsock, link->tonode, link->tosock);
                        link->tosock = node_add_group_socket(&gnode->inputs, gsock);
                        link->tonode = gnode;
@@ -487,7 +487,7 @@ bNode *nodeMakeGroupFromSelected(bNodeTree *ntree)
                                if (gsock->link && gsock->link->fromsock==link->fromsock)
                                        break;
                        if (!gsock) {
-                               gsock = nodeGroupAddSocket(ngroup, link->fromsock->name, link->fromsock->type, SOCK_OUT);
+                               gsock = nodeGroupExposeSocket(ngroup, link->fromsock, SOCK_OUT);
                                gsock->link = nodeAddLink(ngroup, link->fromnode, link->fromsock, NULL, gsock);
                                link->fromsock = node_add_group_socket(&gnode->outputs, gsock);
                        }
@@ -836,6 +836,7 @@ bNodeSocket *nodeGroupAddSocket(bNodeTree *ngroup, const char *name, int type, i
        
        strncpy(gsock->name, name, sizeof(gsock->name));
        gsock->type = type;
+       gsock->ns.sockettype = type;
        gsock->ns.min = INT_MIN;
        gsock->ns.max = INT_MAX;
        zero_v4(gsock->ns.vec);
@@ -855,6 +856,14 @@ bNodeSocket *nodeGroupAddSocket(bNodeTree *ngroup, const char *name, int type, i
        return gsock;
 }
 
+bNodeSocket *nodeGroupExposeSocket(bNodeTree *ngroup, bNodeSocket *sock, int in_out)
+{
+       bNodeSocket *gsock= nodeGroupAddSocket(ngroup, sock->name, sock->type, in_out);
+       /* initialize the default socket value */
+       QUATCOPY(gsock->ns.vec, sock->ns.vec);
+       return gsock;
+}
+
 void nodeGroupExposeAllSockets(bNodeTree *ngroup)
 {
        bNode *node;
@@ -864,13 +873,16 @@ void nodeGroupExposeAllSockets(bNodeTree *ngroup)
                for (sock=node->inputs.first; sock; sock=sock->next) {
                        if (!sock->link && !(sock->flag & SOCK_HIDDEN)) {
                                gsock = nodeGroupAddSocket(ngroup, sock->name, sock->type, SOCK_IN);
+                               /* initialize the default socket value */
+                               QUATCOPY(gsock->ns.vec, sock->ns.vec);
                                sock->link = nodeAddLink(ngroup, NULL, gsock, node, sock);
                        }
                }
                for (sock=node->outputs.first; sock; sock=sock->next) {
-                       printf("\t\tOutput '%s': #links=%d, hidden=%d\n", sock->name, nodeCountSocketLinks(ngroup, sock), (sock->flag & SOCK_HIDDEN));
                        if (nodeCountSocketLinks(ngroup, sock)==0 && !(sock->flag & SOCK_HIDDEN)) {
                                gsock = nodeGroupAddSocket(ngroup, sock->name, sock->type, SOCK_OUT);
+                               /* initialize the default socket value */
+                               QUATCOPY(gsock->ns.vec, sock->ns.vec);
                                gsock->link = nodeAddLink(ngroup, node, sock, NULL, gsock);
                        }
                }
index ed13198e129bc169d34379dfa622a8d708715c8e..bd3c36a05c322f096713210602fa27fe7d395a56 100644 (file)
@@ -2141,11 +2141,11 @@ static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event)
                        else if (outside_group_rect(snode) && (link->tonode || link->fromnode)) {
                                /* automatically add new group socket */
                                if (link->tonode && link->tosock) {
-                                       link->fromsock = nodeGroupAddSocket(snode->edittree, link->tosock->name, link->tosock->type, SOCK_IN);
+                                       link->fromsock = nodeGroupExposeSocket(snode->edittree, link->tosock, SOCK_IN);
                                        link->fromnode = NULL;
                                }
                                else if (link->fromnode && link->fromsock) {
-                                       link->tosock = nodeGroupAddSocket(snode->edittree, link->fromsock->name, link->fromsock->type, SOCK_OUT);
+                                       link->tosock = nodeGroupExposeSocket(snode->edittree, link->fromsock, SOCK_OUT);
                                        link->tonode = NULL;
                                }
                        }
index a20ced776e55b973eed5106488a3e984e645a60a..b8ff41a7948b0415fa46a30ee6bdbf5a793baf2f 100644 (file)
@@ -659,7 +659,7 @@ static bNodeSocket *rna_NodeTree_output_new(bNodeTree *ntree, ReportList *UNUSED
        return gsock;
 }
 
-static bNodeSocket *rna_NodeTree_input_expose(bNodeTree *ntree, ReportList *reports, bNodeSocket *sock)
+static bNodeSocket *rna_NodeTree_input_expose(bNodeTree *ntree, ReportList *reports, bNodeSocket *sock, int add_link)
 {
        bNode *node;
        bNodeSocket *gsock;
@@ -672,7 +672,8 @@ static bNodeSocket *rna_NodeTree_input_expose(bNodeTree *ntree, ReportList *repo
        else {
                /* XXX should check if tree is a group here! no good way to do this currently. */
                gsock = nodeGroupAddSocket(ntree, sock->name, sock->type, SOCK_IN);
-               nodeAddLink(ntree, NULL, gsock, node, sock);
+               if (add_link)
+                       nodeAddLink(ntree, NULL, gsock, node, sock);
                
                nodeGroupVerify(ntree); /* update group node socket links*/
                WM_main_add_notifier(NC_NODE|NA_EDITED, ntree);
@@ -681,7 +682,7 @@ static bNodeSocket *rna_NodeTree_input_expose(bNodeTree *ntree, ReportList *repo
        return NULL;
 }
 
-static bNodeSocket *rna_NodeTree_output_expose(bNodeTree *ntree, ReportList *reports, bNodeSocket *sock)
+static bNodeSocket *rna_NodeTree_output_expose(bNodeTree *ntree, ReportList *reports, bNodeSocket *sock, int add_link)
 {
        bNode *node;
        bNodeSocket *gsock;
@@ -694,7 +695,8 @@ static bNodeSocket *rna_NodeTree_output_expose(bNodeTree *ntree, ReportList *rep
        else {
                /* XXX should check if tree is a group here! no good way to do this currently. */
                gsock = nodeGroupAddSocket(ntree, sock->name, sock->type, SOCK_OUT);
-               nodeAddLink(ntree, node, sock, NULL, gsock);
+               if (add_link)
+                       nodeAddLink(ntree, node, sock, NULL, gsock);
                
                nodeGroupVerify(ntree); /* update group node socket links*/
                WM_main_add_notifier(NC_NODE|NA_EDITED, ntree);
@@ -2749,6 +2751,8 @@ static void rna_def_group_sockets_api(BlenderRNA *brna, PropertyRNA *cprop, int
        RNA_def_function_ui_description(func, "Expose an internal socket in the group tree.");
        RNA_def_function_flag(func, FUNC_USE_REPORTS);
        RNA_def_pointer(func, "sock", "NodeSocket", "Socket", "Internal node socket to expose");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       RNA_def_boolean(func, "add_link", TRUE, "Add Link", "If TRUE, adds a link to the internal socket");
        /* return value */
        parm= RNA_def_pointer(func, "socket", "NodeSocket", "", "New socket.");
        RNA_def_function_return(func, parm);