Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-09-04 07:22:12 +0300
committerHans Goudey <h.goudey@me.com>2022-09-04 07:25:06 +0300
commit0ff920b777791d6dcc002257f437f86e2d14df01 (patch)
tree7f39d83bb7930b2c343120c472be71b3574e1885 /source/blender/editors/space_node/node_relationships.cc
parentb978c1bc65434c5818d84a61f7446a4957dcd211 (diff)
Cleanup: Clarify multi-socket input sorting
The multi-socket input sorting was used for two purposes: moving links to the proper positions when dragging a new link, and resetting the multi-input indices on the links when removing a link. They are now separated into two functions, and the sorting when making a group node that didn't accomplish anything is removed (in that case a proper implementation would copy the indices from the original exterior sockets).
Diffstat (limited to 'source/blender/editors/space_node/node_relationships.cc')
-rw-r--r--source/blender/editors/space_node/node_relationships.cc47
1 files changed, 31 insertions, 16 deletions
diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc
index e95de7b8e85..067c01dcc58 100644
--- a/source/blender/editors/space_node/node_relationships.cc
+++ b/source/blender/editors/space_node/node_relationships.cc
@@ -73,6 +73,8 @@ static void clear_picking_highlight(ListBase *links)
namespace blender::ed::space_node {
+void update_multi_input_indices_for_removed_links(bNode &node);
+
/* -------------------------------------------------------------------- */
/** \name Add Node
* \{ */
@@ -103,11 +105,9 @@ static void pick_link(
nldrag.links.append(link);
nodeRemLink(snode.edittree, &link_to_pick);
-
- BLI_assert(nldrag.last_node_hovered_while_dragging_a_link != nullptr);
-
snode.edittree->ensure_topology_cache();
- sort_multi_input_socket_links(*nldrag.last_node_hovered_while_dragging_a_link, nullptr, nullptr);
+ BLI_assert(nldrag.last_node_hovered_while_dragging_a_link != nullptr);
+ update_multi_input_indices_for_removed_links(*nldrag.last_node_hovered_while_dragging_a_link);
/* Send changed event to original link->tonode. */
if (node) {
@@ -292,7 +292,9 @@ struct LinkAndPosition {
float2 multi_socket_position;
};
-void sort_multi_input_socket_links(bNode &node, bNodeLink *drag_link, const float2 *cursor)
+static void sort_multi_input_socket_links_with_drag(bNode &node,
+ bNodeLink &drag_link,
+ const float2 &cursor)
{
for (bNodeSocket *socket : node.input_sockets()) {
if (!socket->is_multi_input()) {
@@ -307,10 +309,7 @@ void sort_multi_input_socket_links(bNode &node, bNodeLink *drag_link, const floa
links.append({link, location});
};
- if (drag_link) {
- BLI_assert(cursor != nullptr);
- links.append({drag_link, *cursor});
- }
+ links.append({&drag_link, cursor});
std::sort(links.begin(), links.end(), [](const LinkAndPosition a, const LinkAndPosition b) {
return a.multi_socket_position.y < b.multi_socket_position.y;
@@ -322,6 +321,23 @@ void sort_multi_input_socket_links(bNode &node, bNodeLink *drag_link, const floa
}
}
+void update_multi_input_indices_for_removed_links(bNode &node)
+{
+ for (bNodeSocket *socket : node.input_sockets()) {
+ if (!socket->is_multi_input()) {
+ continue;
+ }
+ Vector<bNodeLink *, 8> links = socket->directly_linked_links();
+ std::sort(links.begin(), links.end(), [](const bNodeLink *a, const bNodeLink *b) {
+ return a->multi_input_socket_index < b->multi_input_socket_index;
+ });
+
+ for (const int i : links.index_range()) {
+ links[i]->multi_input_socket_index = i;
+ }
+ }
+}
+
static void snode_autoconnect(SpaceNode &snode, const bool allow_multiple, const bool replace)
{
bNodeTree *ntree = snode.edittree;
@@ -944,19 +960,19 @@ static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cur
continue;
}
if (link->tosock && link->tosock->flag & SOCK_MULTI_INPUT) {
- sort_multi_input_socket_links(*tnode, link, &cursor);
+ sort_multi_input_socket_links_with_drag(*tnode, *link, cursor);
}
}
}
else {
for (bNodeLink *link : nldrag->links) {
- if (nldrag->last_node_hovered_while_dragging_a_link) {
- sort_multi_input_socket_links(
- *nldrag->last_node_hovered_while_dragging_a_link, nullptr, nullptr);
- }
link->tonode = nullptr;
link->tosock = nullptr;
}
+ if (nldrag->last_node_hovered_while_dragging_a_link) {
+ update_multi_input_indices_for_removed_links(
+ *nldrag->last_node_hovered_while_dragging_a_link);
+ }
}
}
else {
@@ -1347,9 +1363,8 @@ static int cut_links_exec(bContext *C, wmOperator *op)
}
node_tree.ensure_topology_cache();
-
for (bNode *node : affected_nodes) {
- sort_multi_input_socket_links(*node, nullptr, nullptr);
+ update_multi_input_indices_for_removed_links(*node);
}
ED_node_tree_propagate_change(C, CTX_data_main(C), snode.edittree);