Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_node/node_relationships.c
| Show First 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | static void pick_link(const bContext *C, | ||||
| RNA_boolean_set(op->ptr, "has_link_picked", true); | RNA_boolean_set(op->ptr, "has_link_picked", true); | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| LinkData *linkdata = create_drag_link( | LinkData *linkdata = create_drag_link( | ||||
| bmain, snode, link_to_pick->fromnode, link_to_pick->fromsock); | bmain, snode, link_to_pick->fromnode, link_to_pick->fromsock); | ||||
| BLI_addtail(&nldrag->links, linkdata); | BLI_addtail(&nldrag->links, linkdata); | ||||
| nodeRemLink(snode->edittree, link_to_pick); | nodeRemLink(snode->edittree, link_to_pick); | ||||
| BLI_assert(nldrag->last_node_hovered_while_dragging_a_link != NULL); | |||||
| sort_multi_input_socket_links( | |||||
| snode, nldrag->last_node_hovered_while_dragging_a_link, NULL, NULL); | |||||
| /* Send changed event to original link->tonode. */ | /* Send changed event to original link->tonode. */ | ||||
| if (node) { | if (node) { | ||||
| snode_update(snode, node); | snode_update(snode, node); | ||||
| } | } | ||||
| } | } | ||||
| static void pick_input_link_by_link_intersect(const bContext *C, | static void pick_input_link_by_link_intersect(const bContext *C, | ||||
| wmOperator *op, | wmOperator *op, | ||||
| ▲ Show 20 Lines • Show All 655 Lines • ▼ Show 20 Lines | if (node_find_indicated_socket(snode, &tnode, &tsock, cursor, SOCK_IN)) { | ||||
| link->tonode = tnode; | link->tonode = tnode; | ||||
| link->tosock = tsock; | link->tosock = tsock; | ||||
| nldrag->last_node_hovered_while_dragging_a_link = tnode; | nldrag->last_node_hovered_while_dragging_a_link = tnode; | ||||
| if (existing_link_connected_to_fromsock) { | if (existing_link_connected_to_fromsock) { | ||||
| link->multi_input_socket_index = | link->multi_input_socket_index = | ||||
| existing_link_connected_to_fromsock->multi_input_socket_index; | existing_link_connected_to_fromsock->multi_input_socket_index; | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (link->tosock && link->tosock->flag & SOCK_MULTI_INPUT) { | |||||
| sort_multi_input_socket_links(snode, tnode, link, cursor); | sort_multi_input_socket_links(snode, tnode, link, cursor); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| else { | else { | ||||
| LISTBASE_FOREACH (LinkData *, linkdata, &nldrag->links) { | LISTBASE_FOREACH (LinkData *, linkdata, &nldrag->links) { | ||||
| bNodeLink *link = linkdata->data; | bNodeLink *link = linkdata->data; | ||||
| if (nldrag->last_node_hovered_while_dragging_a_link) { | if (nldrag->last_node_hovered_while_dragging_a_link) { | ||||
| sort_multi_input_socket_links( | sort_multi_input_socket_links( | ||||
| snode, nldrag->last_node_hovered_while_dragging_a_link, NULL, cursor); | snode, nldrag->last_node_hovered_while_dragging_a_link, NULL, cursor); | ||||
| } | } | ||||
| link->tonode = NULL; | link->tonode = NULL; | ||||
| ▲ Show 20 Lines • Show All 124 Lines • ▼ Show 20 Lines | else { | ||||
| LinkData *linkdata = create_drag_link(bmain, snode, node, sock); | LinkData *linkdata = create_drag_link(bmain, snode, node, sock); | ||||
| BLI_addtail(&nldrag->links, linkdata); | BLI_addtail(&nldrag->links, linkdata); | ||||
| } | } | ||||
| } | } | ||||
| /* or an input? */ | /* or an input? */ | ||||
| else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { | else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { | ||||
| nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); | nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata"); | ||||
| nldrag->last_node_hovered_while_dragging_a_link = node; | |||||
| const int num_links = nodeCountSocketLinks(snode->edittree, sock); | const int num_links = nodeCountSocketLinks(snode->edittree, sock); | ||||
| if (num_links > 0) { | if (num_links > 0) { | ||||
| /* dragged links are fixed on output side */ | /* dragged links are fixed on output side */ | ||||
| nldrag->in_out = SOCK_OUT; | nldrag->in_out = SOCK_OUT; | ||||
| /* detach current links and store them in the operator data */ | /* detach current links and store them in the operator data */ | ||||
| bNodeLink *link_to_pick; | bNodeLink *link_to_pick; | ||||
| LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode->edittree->links) { | LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode->edittree->links) { | ||||
| ▲ Show 20 Lines • Show All 1,197 Lines • ▼ Show 20 Lines | if (best_input && best_output) { | ||||
| bNode *node = link->tonode; | bNode *node = link->tonode; | ||||
| bNodeSocket *sockto = link->tosock; | bNodeSocket *sockto = link->tosock; | ||||
| link->tonode = select; | link->tonode = select; | ||||
| link->tosock = best_input; | link->tosock = best_input; | ||||
| node_remove_extra_links(snode, link); | node_remove_extra_links(snode, link); | ||||
| link->flag &= ~NODE_LINKFLAG_HILITE; | link->flag &= ~NODE_LINKFLAG_HILITE; | ||||
| nodeAddLink(snode->edittree, select, best_output, node, sockto); | bNodeLink *new_link = nodeAddLink(snode->edittree, select, best_output, node, sockto); | ||||
| /* Copy the socket index for the new link, and reset it for the old link. This way the | |||||
| * relative order of links is preserved, and the links get drawn in the right place. */ | |||||
| new_link->multi_input_socket_index = link->multi_input_socket_index; | |||||
| link->multi_input_socket_index = 0; | |||||
| /* set up insert offset data, it needs stuff from here */ | /* set up insert offset data, it needs stuff from here */ | ||||
| if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) { | if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) { | ||||
| NodeInsertOfsData *iofsd = MEM_callocN(sizeof(NodeInsertOfsData), __func__); | NodeInsertOfsData *iofsd = MEM_callocN(sizeof(NodeInsertOfsData), __func__); | ||||
| iofsd->insert = select; | iofsd->insert = select; | ||||
| iofsd->prev = link->fromnode; | iofsd->prev = link->fromnode; | ||||
| iofsd->next = node; | iofsd->next = node; | ||||
| snode->runtime->iofsd = iofsd; | snode->runtime->iofsd = iofsd; | ||||
| } | } | ||||
| ntreeUpdateTree(bmain, snode->edittree); /* needed for pointers */ | ntreeUpdateTree(bmain, snode->edittree); /* needed for pointers */ | ||||
| snode_update(snode, select); | snode_update(snode, select); | ||||
| ED_node_tag_update_id((ID *)snode->edittree); | ED_node_tag_update_id((ID *)snode->edittree); | ||||
| ED_node_tag_update_id(snode->id); | ED_node_tag_update_id(snode->id); | ||||
| sort_multi_input_socket_links(snode, node, NULL, NULL); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||