Avoid creating multiple outputs connected to the same socket when creating a node group

This patch fixes the annoyance that when creating a node group where one of its nodes is connected
to several other nodes, a separate output will be created for each link, even though they're all
connected to the same socket in the group.
Now, before adding an output for an outgoing link, the existing outputs are checked to find whether
any output is already connected to the same socket. If such an output is found, it is reused instead of
creating a new one.

Reviewers: Severin

Subscribers: Blendify

Differential Revision: https://developer.blender.org/D1836
This commit is contained in:
Lukas Stockner 2016-07-27 15:53:32 +02:00 committed by Sergey Sharybin
parent d7bd64df5d
commit 25bd01f2f7
1 changed files with 30 additions and 15 deletions

View File

@ -794,22 +794,37 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
link->tosock = node_group_find_input_socket(gnode, iosock->identifier);
}
else if (fromselect) {
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link->fromnode, link->fromsock);
bNodeSocket *output_sock;
/* update the group node and interface node sockets,
* so the new interface socket can be linked.
*/
node_group_verify(ntree, gnode, (ID *)ngroup);
node_group_output_verify(ngroup, output_node, (ID *)ngroup);
/* First check whether the source of this link is already connected to an output.
* If yes, reuse that output instead of duplicating it. */
bool connected = false;
bNodeLink *olink;
for (olink = ngroup->links.first; olink; olink = olink->next) {
if (olink->fromsock == link->fromsock && olink->tonode == output_node) {
bNodeSocket *output_sock = node_group_find_output_socket(gnode, olink->tosock->identifier);
link->fromnode = gnode;
link->fromsock = output_sock;
connected = true;
}
}
/* create new internal link */
output_sock = node_group_output_find_socket(output_node, iosock->identifier);
nodeAddLink(ngroup, link->fromnode, link->fromsock, output_node, output_sock);
/* redirect external link */
link->fromnode = gnode;
link->fromsock = node_group_find_output_socket(gnode, iosock->identifier);
if (!connected) {
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link->fromnode, link->fromsock);
bNodeSocket *output_sock;
/* update the group node and interface node sockets,
* so the new interface socket can be linked.
*/
node_group_verify(ntree, gnode, (ID *)ngroup);
node_group_output_verify(ngroup, output_node, (ID *)ngroup);
/* create new internal link */
output_sock = node_group_output_find_socket(output_node, iosock->identifier);
nodeAddLink(ngroup, link->fromnode, link->fromsock, output_node, output_sock);
/* redirect external link */
link->fromnode = gnode;
link->fromsock = node_group_find_output_socket(gnode, iosock->identifier);
}
}
}