Blender V5.3
node_relationships.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_array_utils.hh"
14#include "DNA_node_types.h"
15
16#include "BLI_easing.hh"
17#include "BLI_listbase.hh"
18#include "BLI_math_geom_c.hh"
19#include "BLI_stack.hh"
20#include "BLI_vector.hh"
21
22#include "BKE_context.hh"
24#include "BKE_node.hh"
26#include "BKE_node_runtime.hh"
28#include "BKE_screen.hh"
29
30#include "ED_node.hh" /* own include */
31#include "ED_render.hh"
32#include "ED_screen.hh"
33#include "ED_space_api.hh"
34#include "ED_viewer_path.hh"
35
36#include "RNA_access.hh"
37#include "RNA_define.hh"
38#include "RNA_prototypes.hh"
39
40#include "WM_api.hh"
41#include "WM_types.hh"
42
43#include "UI_interface_icons.hh"
44#include "UI_resources.hh"
45#include "UI_view2d.hh"
46
47#include "NOD_geo_viewer.hh"
49#include "NOD_socket.hh"
50#include "NOD_socket_items.hh"
51
52#include "node_intern.hh" /* own include */
53
54namespace blender {
55
56namespace ed::space_node {
57
58static void clear_picking_highlight(ListBaseT<bNodeLink> *links)
59{
60 for (bNodeLink &link : *links) {
61 link.flag &= ~NODE_LINK_TEMP_HIGHLIGHT;
62 }
63}
64
65/* -------------------------------------------------------------------- */
68
70{
71 bNodeLink oplink{};
72 if (socket.in_out == SOCK_OUT) {
73 oplink.fromnode = &node;
74 oplink.fromsock = &socket;
75 }
76 else {
77 oplink.tonode = &node;
78 oplink.tosock = &socket;
79 }
80 oplink.flag |= NODE_LINK_VALID;
81 return oplink;
82}
83
84static void pick_link(bNodeLinkDrag &nldrag,
85 SpaceNode &snode,
86 bNode *node,
87 bNodeLink &link_to_pick)
88{
90
91 bNodeLink link = create_drag_link(*link_to_pick.fromnode, *link_to_pick.fromsock);
92
93 bke::node_link_set_mute(*snode.edittree, link, (link_to_pick.flag & NODE_LINK_MUTED));
94
95 /* So we can restore order on cancel. */
96 if (link_to_pick.tosock->is_multi_input()) {
97 link.multi_input_sort_id = link_to_pick.multi_input_sort_id;
98 }
99
100 nldrag.links.append(link);
101 bke::node_remove_link(snode.edittree, link_to_pick);
102 snode.edittree->ensure_topology_cache();
105
106 /* Send changed event to original link->tonode. */
107 if (node) {
109 }
110}
111
113 wmOperator &op,
114 bNodeLinkDrag &nldrag,
115 const float2 &cursor)
116{
117 SpaceNode *snode = CTX_wm_space_node(&C);
118 ARegion *region = CTX_wm_region(&C);
119 bNodeTree &node_tree = *snode->edittree;
120
121 float2 drag_start;
122 RNA_float_get_array(op.ptr, "drag_start", drag_start);
123 bNodeSocket *socket = node_find_indicated_socket(*snode, *region, drag_start, SOCK_IN);
124 bNode &node = socket->owner_node();
125
126 /* Distance to test overlapping of cursor on link. */
127 const float cursor_link_touch_distance = 12.5f * UI_SCALE_FAC;
128
129 bNodeLink *link_to_pick = nullptr;
130 clear_picking_highlight(&node_tree.links);
131 for (bNodeLink *link : socket->directly_linked_links()) {
132 /* Test if the cursor is near a link. */
133 std::array<float2, NODE_LINK_RESOL + 1> coords;
135
136 for (const int i : IndexRange(coords.size() - 1)) {
137 const float distance = dist_squared_to_line_segment_v2(cursor, coords[i], coords[i + 1]);
138 if (distance < cursor_link_touch_distance) {
139 link_to_pick = link;
140 nldrag.last_picked_multi_input_socket_link = link_to_pick;
141 }
142 }
143 }
144
145 /* If no linked was picked in this call, try using the one picked in the previous call.
146 * Not essential for the basic behavior, but can make interaction feel a bit better if
147 * the mouse moves to the right and loses the "selection." */
148 if (!link_to_pick) {
149 bNodeLink *last_picked_link = nldrag.last_picked_multi_input_socket_link;
150 if (last_picked_link) {
151 link_to_pick = last_picked_link;
152 }
153 }
154
155 if (link_to_pick) {
156 /* Highlight is set here and cleared in the next iteration or if the operation finishes. */
157 link_to_pick->flag |= NODE_LINK_TEMP_HIGHLIGHT;
159
160 if (!node_find_indicated_socket(*snode, *region, cursor, SOCK_IN)) {
161 pick_link(nldrag, *snode, &node, *link_to_pick);
162 }
163 }
164}
165
166static bool socket_is_available(const bNodeTree *ntree, bNodeSocket *sock, const bool allow_used)
167{
168 ntree->ensure_topology_cache();
169 if (!sock->is_visible()) {
170 return false;
171 }
172
173 if (!allow_used && (sock->flag & SOCK_IS_LINKED)) {
174 /* Multi input sockets are available (even if used). */
175 if (!(sock->flag & SOCK_MULTI_INPUT)) {
176 return false;
177 }
178 }
179
180 return true;
181}
182
184 bNode *node,
185 bNodeSocket *sock_target,
186 const bool allow_multiple)
187{
188 /* First look for selected output. */
189 for (bNodeSocket &sock : node->outputs) {
190 if (!socket_is_available(ntree, &sock, allow_multiple)) {
191 continue;
192 }
193
194 if (sock.flag & SELECT) {
195 return &sock;
196 }
197 }
198
199 /* Try to find a socket with a matching name. */
200 for (bNodeSocket &sock : node->outputs) {
201 if (!socket_is_available(ntree, &sock, allow_multiple)) {
202 continue;
203 }
204
205 /* Check for same types. */
206 if (sock.type == sock_target->type) {
207 if (STREQ(sock.name, sock_target->name)) {
208 return &sock;
209 }
210 }
211 }
212
213 /* Otherwise settle for the first available socket of the right type. */
214 for (bNodeSocket &sock : node->outputs) {
215 if (!socket_is_available(ntree, &sock, allow_multiple)) {
216 continue;
217 }
218
219 /* Check for same types. */
220 if (sock.type == sock_target->type) {
221 return &sock;
222 }
223 }
224
225 /* If the target is an extend socket, then connect the first available socket that is not
226 * already linked to the target node. */
227 ntree->ensure_topology_cache();
228 if (STREQ(sock_target->idname, "NodeSocketVirtual")) {
229 for (bNodeSocket &output : node->outputs) {
230 if (!output.is_icon_visible()) {
231 continue;
232 }
233
234 /* Find out if the socket is already linked to the target node. */
235 const Span<bNodeSocket *> directly_linked_sockets = output.directly_linked_sockets();
236 bool is_output_linked_to_target_node = false;
237 for (bNodeSocket *socket : directly_linked_sockets) {
238 if (&socket->owner_node() == &sock_target->owner_node()) {
239 is_output_linked_to_target_node = true;
240 break;
241 }
242 }
243
244 /* Already linked, ignore it. */
245 if (is_output_linked_to_target_node) {
246 continue;
247 }
248
249 return &output;
250 }
251 }
252
253 /* Always allow linking to an reroute node. The socket type of the reroute sockets might change
254 * after the link has been created. */
255 if (node->is_reroute()) {
256 return node->outputs.first();
257 }
258
259 return nullptr;
260}
261
262/* Returns the list of available inputs sorted by their order of importance, where the order of
263 * importance is assumed to be the numerical value of the socket type, such that a higher value
264 * corresponds to a higher importance. If only_unlinked is true, only input sockets that are
265 * unlinked will be considered. */
267 const bNode *node,
268 const bool only_unlinked)
269{
271 for (bNodeSocket &input : node->inputs) {
272 if (socket_is_available(ntree, &input, !only_unlinked)) {
273 inputs.append(&input);
274 }
275 }
276
277 std::ranges::sort(inputs,
278 [](const bNodeSocket *a, const bNodeSocket *b) { return a->type > b->type; });
279
280 return inputs;
281}
282
284 SpaceNode &snode,
285 bNode *node_fr,
286 bNodeSocket *sock_fr,
287 bNode *node_to,
288 bNodeSocket *sock_to,
289 int replace)
290{
291 bNodeTree *ntree = snode.edittree;
292
293 if (replace) {
294 bke::node_remove_socket_links(*ntree, *sock_to);
295 }
296
297 bNodeLink &link = bke::node_add_link(*ntree, *node_fr, *sock_fr, *node_to, *sock_to);
298
299 if (link.fromnode->typeinfo->insert_link) {
300 bke::NodeInsertLinkParams params{*ntree, *link.fromnode, link, &C};
301 if (!link.fromnode->typeinfo->insert_link(params)) {
302 bke::node_remove_link(ntree, link);
303 return false;
304 }
305 }
306 if (link.tonode->typeinfo->insert_link) {
307 bke::NodeInsertLinkParams params{*ntree, *link.tonode, link, &C};
308 if (!link.tonode->typeinfo->insert_link(params)) {
309 bke::node_remove_link(ntree, link);
310 return false;
311 }
312 }
313
314 return true;
315}
316
321
323 bNodeLink &drag_link,
324 const float2 &cursor)
325{
326 const float2 &socket_location = socket.runtime->location;
327
329 for (bNodeLink *link : socket.directly_linked_links()) {
331 socket_location, link->multi_input_sort_id, link->tosock->runtime->total_inputs);
332 links.append({link, location});
333 };
334
335 links.append({&drag_link, cursor});
336
337 std::ranges::sort(links, [](const LinkAndPosition a, const LinkAndPosition b) {
338 return a.multi_socket_position.y < b.multi_socket_position.y;
339 });
340
341 for (const int i : links.index_range()) {
342 links[i].link->multi_input_sort_id = i;
343 }
344}
345
347{
348 for (bNodeSocket *socket : node.input_sockets()) {
349 if (!socket->is_multi_input()) {
350 continue;
351 }
352 Vector<bNodeLink *, 8> links = socket->directly_linked_links();
353 std::ranges::sort(links, [](const bNodeLink *a, const bNodeLink *b) {
354 return a->multi_input_sort_id < b->multi_input_sort_id;
355 });
356
357 for (const int i : links.index_range()) {
358 links[i]->multi_input_sort_id = i;
359 }
360 }
361}
362
364 SpaceNode &snode,
365 const bool allow_multiple,
366 const bool replace)
367{
368 bNodeTree *ntree = snode.edittree;
369 Vector<bNode *> sorted_nodes = get_selected_nodes(*ntree).extract_vector();
370
371 /* Sort nodes left to right. */
372 std::ranges::sort(sorted_nodes, [](const bNode *a, const bNode *b) {
373 return a->location[0] < b->location[0];
374 });
375
376 // int numlinks = 0; /* UNUSED */
377 for (const int i : sorted_nodes.as_mutable_span().drop_back(1).index_range()) {
378 bool has_selected_inputs = false;
379
380 bNode *node_fr = sorted_nodes[i];
381 bNode *node_to = sorted_nodes[i + 1];
382 /* Corner case: input/output node aligned the wrong way around (#47729). */
383 if (node_to->inputs.is_empty() || node_fr->outputs.is_empty()) {
384 std::swap(node_fr, node_to);
385 }
386
387 /* If there are selected sockets, connect those. */
388 for (bNodeSocket &sock_to : node_to->inputs) {
389 if (sock_to.flag & SELECT) {
390 has_selected_inputs = true;
391
392 if (!socket_is_available(ntree, &sock_to, replace)) {
393 continue;
394 }
395
396 /* Check for an appropriate output socket to connect from. */
397 bNodeSocket *sock_fr = best_socket_output(ntree, node_fr, &sock_to, allow_multiple);
398 if (!sock_fr) {
399 continue;
400 }
401
402 if (snode_autoconnect_input(C, snode, node_fr, sock_fr, node_to, &sock_to, replace)) {
403 // numlinks++;
404 }
405 }
406 }
407
408 if (!has_selected_inputs) {
409 Vector<bNodeSocket *> inputs = get_available_sorted_inputs(ntree, node_to, !replace);
410 for (bNodeSocket *input : inputs) {
411 /* Check for an appropriate output socket to connect from. */
412 bNodeSocket *sock_fr = best_socket_output(ntree, node_fr, input, allow_multiple);
413 if (!sock_fr) {
414 continue;
415 }
416
417 if (snode_autoconnect_input(C, snode, node_fr, sock_fr, node_to, input, replace)) {
418 // numlinks++;
419 break;
420 }
421 }
422 }
423 }
424}
425
427
428namespace viewer_linking {
429
430/* -------------------------------------------------------------------- */
433
434/* Depending on the node tree type, different socket types are supported by viewer nodes. */
435static bool socket_can_be_viewed(const bNodeSocket &socket)
436{
437 if (!socket.is_icon_visible()) {
438 return false;
439 }
440 if (STREQ(socket.idname, "NodeSocketVirtual")) {
441 return false;
442 }
443
444 /* The compositor viewer can only view color sockets, so we make sure the socket can be converted
445 * into a color. */
446 if (socket.owner_tree().type == NTREE_COMPOSIT) {
447 return socket.owner_tree().typeinfo->validate_link(socket.type, SOCK_RGBA);
448 }
449
450 return true;
451}
452
454 bNode &viewer_node)
455{
456 const auto &storage = *static_cast<const NodeGeometryViewer *>(viewer_node.storage);
457 if (storage.items_num >= 1) {
458 const NodeGeometryViewerItem &first_item = storage.items[0];
459 if (first_item.socket_type == SOCK_GEOMETRY) {
460 return;
461 }
462 }
463 std::optional<int> existing_geometry_index;
464 for (const int i : IndexRange(storage.items_num)) {
465 const NodeGeometryViewerItem &item = storage.items[i];
466 if (item.socket_type == SOCK_GEOMETRY) {
467 existing_geometry_index = i;
468 break;
469 }
470 }
471 if (existing_geometry_index) {
472 BLI_assert(*existing_geometry_index >= 1);
473 dna::array::move_index(storage.items, storage.items_num, *existing_geometry_index, 0);
474 return;
475 }
477 tree, viewer_node, SOCK_GEOMETRY, "Geometry");
478 dna::array::move_index(storage.items, storage.items_num, storage.items_num - 1, 0);
479}
480
482 bNodeTree &ntree, bNode &viewer_node, const eNodeSocketDatatype socket_type)
483{
484 const auto &storage = *static_cast<const NodeGeometryViewer *>(viewer_node.storage);
485 if (storage.items_num == 0) {
487 ntree, viewer_node, socket_type, IFACE_("Value"));
488 return 0;
489 }
490 if (storage.items_num == 1 && storage.items[0].socket_type != SOCK_GEOMETRY) {
491 storage.items[0].socket_type = socket_type;
492 return 0;
493 }
494 if (storage.items_num == 1 && storage.items[0].socket_type == SOCK_GEOMETRY) {
496 ntree, viewer_node, socket_type, IFACE_("Value"));
497 return 1;
498 }
499 if (storage.items_num == 2 && storage.items[0].socket_type == SOCK_GEOMETRY &&
500 storage.items[1].socket_type != SOCK_GEOMETRY)
501 {
502 storage.items[1].socket_type = socket_type;
503 return 1;
504 }
505 std::optional<int> existing_geometry_index;
506 for (const int i : IndexRange(storage.items_num)) {
507 if (storage.items[i].socket_type == SOCK_GEOMETRY) {
508 existing_geometry_index = i;
509 break;
510 }
511 }
512 if (existing_geometry_index) {
513 dna::array::move_index(storage.items, storage.items_num, *existing_geometry_index, 0);
514 storage.items[1].socket_type = socket_type;
515 MEM_SAFE_DELETE(storage.items[1].name);
516 storage.items[1].name = BLI_strdup(IFACE_("Value"));
517 return 1;
518 }
519 storage.items[0].socket_type = socket_type;
520 MEM_SAFE_DELETE(storage.items[0].name);
521 storage.items[0].name = BLI_strdup(IFACE_("Value"));
522 return 0;
523}
524
525static std::string get_viewer_source_name(const bNodeSocket &socket)
526{
527 const bNode &node = socket.owner_node();
528 if (node.is_reroute()) {
529 const bNodeSocket &reroute_input = node.input_socket(0);
530 if (!reroute_input.is_logically_linked()) {
531 return IFACE_(socket.typeinfo->label);
532 }
533 return reroute_input.logically_linked_sockets()[0]->name;
534 }
535 return blender::bke::node_socket_label(socket);
536}
537
541 bNode &viewer_node,
542 bNodeSocket &src_socket)
543{
544 if (viewer_node.type_legacy != GEO_NODE_VIEWER) {
545 /* In viewer nodes in the compositor, only the first input should be linked to. */
546 return viewer_node.inputs.first();
547 }
549 {
550 return nullptr;
551 }
552
553 /* For the geometry nodes viewer, find the socket with the correct type. */
554 const std::string name = get_viewer_source_name(src_socket);
555
556 int item_index;
557 if (src_socket.type == SOCK_GEOMETRY) {
559 item_index = 0;
560 }
561 else {
563 ntree, viewer_node, src_socket.typeinfo->type);
564 }
565
566 auto &storage = *static_cast<NodeGeometryViewer *>(viewer_node.storage);
567 NodeGeometryViewerItem &item = storage.items[item_index];
569 viewer_node, item, name.c_str());
572 return static_cast<bNodeSocket *>(BLI_findlink(&viewer_node.inputs, item_index));
573}
574
575static bool is_viewer_node(const bNode &node)
576{
577 return ELEM(node.type_legacy, CMP_NODE_VIEWER, GEO_NODE_VIEWER);
578}
579
580static bool is_viewer_socket_in_viewer(const bNodeSocket &socket)
581{
582 const bNode &node = socket.owner_node();
584 if (node.typeinfo->type_legacy == GEO_NODE_VIEWER) {
585 return true;
586 }
587 return socket.index() == 0;
588}
589
590static bool is_viewer_socket(const bNodeSocket &socket)
591{
592 if (is_viewer_node(socket.owner_node())) {
593 return is_viewer_socket_in_viewer(socket);
594 }
595 return false;
596}
597
599{
600 SpaceNode *snode = CTX_wm_space_node(C);
602}
603
605{
606 for (bNodeLink &link : btree.links.items_mutable()) {
607 if (link.tonode == &viewer_node) {
608 if (link.tosock->flag & SOCK_UNAVAIL) {
609 bke::node_remove_link(&btree, link);
610 }
611 }
612 }
613}
614
616{
617 int last_linked_data_socket_index = -1;
618 bool has_linked_geometry_socket = false;
619 for (bNodeSocket *socket : node_to_view.output_sockets()) {
620 if (!socket_can_be_viewed(*socket)) {
621 continue;
622 }
623 for (bNodeLink *link : socket->directly_linked_links()) {
624 bNodeSocket &target_socket = *link->tosock;
625 bNode &target_node = *link->tonode;
626 if (is_viewer_socket(target_socket)) {
627 if (link->is_muted() || !(target_node.flag & NODE_DO_OUTPUT)) {
628 /* This socket is linked to a deactivated viewer, the viewer should be activated. */
629 return socket;
630 }
631 if (socket->type == SOCK_GEOMETRY) {
632 has_linked_geometry_socket = true;
633 }
634 else {
635 last_linked_data_socket_index = socket->index();
636 }
637 }
638 }
639 }
640
641 if (last_linked_data_socket_index == -1 && !has_linked_geometry_socket) {
642 /* Return the first socket that can be viewed. */
643 for (bNodeSocket *socket : node_to_view.output_sockets()) {
644 if (socket_can_be_viewed(*socket)) {
645 return socket;
646 }
647 }
648 return nullptr;
649 }
650
651 bNodeSocket *already_viewed_socket = nullptr;
652
653 /* Pick the next socket to be linked to the viewer. */
654 const int tot_outputs = node_to_view.output_sockets().size();
655 for (const int offset : IndexRange(1, tot_outputs)) {
656 const int index = (last_linked_data_socket_index + offset) % tot_outputs;
657 bNodeSocket &output_socket = node_to_view.output_socket(index);
658 if (!socket_can_be_viewed(output_socket)) {
659 continue;
660 }
661 if (has_linked_geometry_socket && output_socket.type == SOCK_GEOMETRY) {
662 /* Skip geometry sockets when cycling if one is already viewed. */
663 already_viewed_socket = &output_socket;
664 continue;
665 }
666
667 bool is_currently_viewed = false;
668 for (const bNodeLink *link : output_socket.directly_linked_links()) {
669 bNodeSocket &target_socket = *link->tosock;
670 bNode &target_node = *link->tonode;
671 if (!is_viewer_socket(target_socket)) {
672 continue;
673 }
674 if (link->is_muted()) {
675 continue;
676 }
677 if (!(target_node.flag & NODE_DO_OUTPUT)) {
678 continue;
679 }
680 is_currently_viewed = true;
681 break;
682 }
683 if (is_currently_viewed) {
684 already_viewed_socket = &output_socket;
685 continue;
686 }
687 return &output_socket;
688 }
689 return already_viewed_socket;
690}
691
692static void finalize_viewer_link(const bContext &C,
693 SpaceNode &snode,
694 bNode &viewer_node,
695 bNodeLink &viewer_link)
696{
697 Main *bmain = CTX_data_main(&C);
699 viewer_link.flag &= ~NODE_LINK_MUTED;
700 viewer_node.flag &= ~NODE_MUTED;
701 viewer_node.flag |= NODE_DO_OUTPUT;
702
703 if (snode.edittree->type == NTREE_GEOMETRY) {
704
705 std::optional<int> item_identifier;
706 const NodeGeometryViewerItem *item =
708 viewer_node, viewer_link.tosock->identifier);
709 BLI_assert(item);
710 if (item) {
711 item_identifier = item->identifier;
712 }
713
714 viewer_path::activate_geometry_node(*bmain, snode, viewer_node, item_identifier);
715 }
716 else if (snode.edittree->type == NTREE_COMPOSIT) {
717 for (bNode *node : snode.nodetree->all_nodes()) {
718 if (node->is_type("CompositorNodeViewer"_ustr) && node != &viewer_node) {
719 node->flag &= ~NODE_DO_OUTPUT;
720 }
721 }
722 }
724 BKE_main_ensure_invariants(*bmain, snode.edittree->id);
725}
726
727static const bNode *find_overlapping_node(const bNodeTree &tree,
728 const rctf &rect,
729 const Span<const bNode *> ignored_nodes)
730{
731 for (const bNode *node : tree.all_nodes()) {
732 if (node->is_frame()) {
733 continue;
734 }
735 if (ignored_nodes.contains(node)) {
736 continue;
737 }
738 if (BLI_rctf_isect(&rect, &node->runtime->draw_bounds, nullptr)) {
739 return node;
740 }
741 }
742 return nullptr;
743}
744
750 const float step_distance,
751 const float max_distance)
752{
753 /* Prefer moving viewer a bit further horizontally than vertically. */
754 const float y_scale = 0.5f;
755
756 Vector<float2> candidates;
757 candidates.append(initial);
758 for (float distance = step_distance; distance <= max_distance; distance += step_distance) {
759 const float arc_length = distance * M_PI;
760 const int checks = std::max<int>(2, ceilf(arc_length / step_distance));
761 for (const int i : IndexRange(checks)) {
762 const float angle = i / float(checks - 1) * M_PI;
763 const float candidate_x = initial.x + distance * std::sin(angle);
764 const float candidate_y = initial.y + distance * std::cos(angle) * y_scale;
765 candidates.append({candidate_x, candidate_y});
766 }
767 }
768 return candidates;
769}
770
776static void position_viewer_node(const bContext &C,
777 bNodeTree &tree,
778 bNode &viewer_node,
779 const bNode &node_to_view)
780{
781 ScrArea &area = *CTX_wm_area(&C);
782 ARegion &region = *CTX_wm_region(&C);
784
785 tree.ensure_topology_cache();
786
787 const View2D &v2d = region.v2d;
788 rctf region_rect;
789 region_rect.xmin = 0;
790 region_rect.xmax = region.winx;
791 region_rect.ymin = 0;
792 region_rect.ymax = region.winy;
793 if (U.uiflag2 & USER_REGION_OVERLAP) {
794 region_rect.xmax -= sidebar.winx;
795 }
796
797 rctf region_bounds;
798 ui::view2d_region_to_view_rctf(&v2d, &region_rect, &region_bounds);
799
800 viewer_node.ui_order = tree.all_nodes().size();
802
803 const bool is_new_viewer_node = BLI_rctf_size_x(&viewer_node.runtime->draw_bounds) == 0;
804 if (!is_new_viewer_node &&
805 BLI_rctf_inside_rctf(&region_bounds, &viewer_node.runtime->draw_bounds) &&
806 viewer_node.runtime->draw_bounds.xmin > node_to_view.runtime->draw_bounds.xmax)
807 {
808 /* Stay at the old viewer position when the viewer node is still in view and on the right side
809 * of the node-to-view. */
810 return;
811 }
812
813 const float default_padding_x = U.node_margin;
814 const float default_padding_y = 10;
815 const float viewer_width = is_new_viewer_node ?
816 viewer_node.width * UI_SCALE_FAC :
817 BLI_rctf_size_x(&viewer_node.runtime->draw_bounds);
818 const float viewer_height = is_new_viewer_node ?
819 100 * UI_SCALE_FAC :
820 BLI_rctf_size_y(&viewer_node.runtime->draw_bounds);
821
822 const float2 main_candidate{node_to_view.runtime->draw_bounds.xmax + default_padding_x,
823 node_to_view.runtime->draw_bounds.ymax + viewer_height +
824 default_padding_y};
825
826 std::optional<float2> new_viewer_position;
827
828 const Vector<float2> position_candidates = get_viewer_node_position_candidates(
829 main_candidate, 50 * UI_SCALE_FAC, 800 * UI_SCALE_FAC);
830 for (const float2 &candidate_pos : position_candidates) {
831 rctf candidate;
832 candidate.xmin = candidate_pos.x;
833 candidate.xmax = candidate_pos.x + viewer_width;
834 candidate.ymin = candidate_pos.y - viewer_height;
835 candidate.ymax = candidate_pos.y;
836
837 if (!BLI_rctf_inside_rctf(&region_bounds, &candidate)) {
838 /* Avoid moving viewer outside of visible region. */
839 continue;
840 }
841
842 rctf padded_candidate = candidate;
843 BLI_rctf_pad(&padded_candidate, default_padding_x - 1, default_padding_y - 1);
844
845 const bNode *overlapping_node = find_overlapping_node(
846 tree, padded_candidate, {&viewer_node, &node_to_view});
847 if (!overlapping_node) {
848 new_viewer_position = candidate_pos;
849 break;
850 }
851 }
852
853 if (!new_viewer_position) {
854 new_viewer_position = main_candidate;
855 }
856
857 viewer_node.location[0] = new_viewer_position->x / UI_SCALE_FAC;
858 viewer_node.location[1] = new_viewer_position->y / UI_SCALE_FAC;
859 viewer_node.parent = nullptr;
860}
861
862static int view_socket(const bContext &C,
863 SpaceNode &snode,
864 bNodeTree &btree,
865 bNode &bnode_to_view,
866 bNodeSocket &bsocket_to_view)
867{
868 bNode *viewer_node = nullptr;
869 /* Try to find a viewer that is already active. */
870 for (bNode *node : btree.all_nodes()) {
871 if (is_viewer_node(*node)) {
872 if (node->flag & NODE_DO_OUTPUT && node->custom1 == NODE_VIEWER_SHORTCUT_NONE) {
873 viewer_node = node;
874 break;
875 }
876 }
877 }
878
879 /* Try to reactivate existing viewer connection. */
880 for (bNodeLink *link : bsocket_to_view.directly_linked_links()) {
881 bNodeSocket &target_socket = *link->tosock;
882 bNode &target_node = *link->tonode;
883 if (is_viewer_socket(target_socket) && ELEM(viewer_node, nullptr, &target_node)) {
884 finalize_viewer_link(C, snode, target_node, *link);
885 position_viewer_node(C, btree, target_node, bnode_to_view);
886 return OPERATOR_FINISHED;
887 }
888 }
889
890 if (viewer_node == nullptr) {
891 for (bNode *node : btree.all_nodes()) {
892 if (is_viewer_node(*node) && node->custom1 == NODE_VIEWER_SHORTCUT_NONE) {
893 viewer_node = node;
894 break;
895 }
896 }
897 }
898 if (viewer_node == nullptr) {
899 const float2 socket_location = bsocket_to_view.runtime->location;
900 const int viewer_type = get_default_viewer_type(&C);
901 const float2 location{socket_location.x / UI_SCALE_FAC + 100,
902 socket_location.y / UI_SCALE_FAC};
903 viewer_node = add_static_node(C, viewer_type, location);
904 }
905
906 bNodeSocket *viewer_bsocket = node_link_viewer_get_socket(btree, *viewer_node, bsocket_to_view);
907 if (viewer_bsocket == nullptr) {
908 return OPERATOR_CANCELLED;
909 }
910 viewer_bsocket->flag &= ~SOCK_HIDDEN;
911
912 bNodeLink *viewer_link = nullptr;
913 for (bNodeLink &link : btree.links.items_mutable()) {
914 if (link.tosock == viewer_bsocket) {
915 viewer_link = &link;
916 break;
917 }
918 }
919 if (viewer_link == nullptr) {
920 viewer_link = &bke::node_add_link(
921 btree, bnode_to_view, bsocket_to_view, *viewer_node, *viewer_bsocket);
922 }
923 else {
924 viewer_link->fromnode = &bnode_to_view;
925 viewer_link->fromsock = &bsocket_to_view;
927 }
928 finalize_viewer_link(C, snode, *viewer_node, *viewer_link);
929 position_viewer_node(C, btree, *viewer_node, bnode_to_view);
930 return OPERATOR_CANCELLED;
931}
932
933static int node_link_viewer(const bContext &C, bNode &bnode_to_view, bNodeSocket *bsocket_to_view)
934{
935 SpaceNode &snode = *CTX_wm_space_node(&C);
936 bNodeTree *btree = snode.edittree;
937 btree->ensure_topology_cache();
938
939 if (bsocket_to_view == nullptr) {
940 bsocket_to_view = determine_socket_to_view(bnode_to_view);
941 }
942
943 if (bsocket_to_view == nullptr) {
944 return OPERATOR_CANCELLED;
945 }
946
947 if (!socket_can_be_viewed(*bsocket_to_view)) {
948 return OPERATOR_CANCELLED;
949 }
950
951 return view_socket(C, snode, *btree, bnode_to_view, *bsocket_to_view);
952}
953
955
956} // namespace viewer_linking
957
958/* -------------------------------------------------------------------- */
961
963{
964 SpaceNode &snode = *CTX_wm_space_node(C);
966
967 if (!node) {
968 return OPERATOR_CANCELLED;
969 }
970
972
973 bNodeSocket *socket_to_view = nullptr;
974 for (bNodeSocket &socket : node->outputs) {
975 if (socket.flag & SELECT) {
976 socket_to_view = &socket;
977 break;
978 }
979 }
980
981 if (viewer_linking::node_link_viewer(*C, *node, socket_to_view) == OPERATOR_CANCELLED) {
982 return OPERATOR_CANCELLED;
983 }
984
986
987 return OPERATOR_FINISHED;
988}
989
991{
993 return false;
994 }
995 SpaceNode *snode = CTX_wm_space_node(C);
996 if (ED_node_is_compositor(snode)) {
997 return true;
998 }
999 if (ED_node_is_geometry(snode)) {
1001 /* The viewer node is not supported in the "Tool" context. */
1002 return false;
1003 }
1004 return true;
1005 }
1006 return false;
1007}
1008
1010{
1011 /* identifiers */
1012 ot->name = "Link to Viewer Node";
1013 ot->description = "Link to viewer node";
1014 ot->idname = "NODE_OT_link_viewer";
1015
1016 /* API callbacks. */
1019
1020 /* flags */
1022}
1023
1025
1026/* -------------------------------------------------------------------- */
1029
1035{
1036 if (nldrag.in_out == SOCK_OUT) {
1037 for (const bNodeLink &link : nldrag.links) {
1038 if (link.tonode && link.tosock) {
1039 return false;
1040 }
1041 }
1042 }
1043 else {
1044 for (const bNodeLink &link : nldrag.links) {
1045 if (link.fromnode && link.fromsock) {
1046 return false;
1047 }
1048 }
1049 }
1050 return true;
1051}
1052
1054 const bNodeLinkDrag &nldrag)
1055{
1056 /* Custom node trees aren't supported yet. */
1057 if (node_tree.type == NTREE_CUSTOM) {
1058 return false;
1059 }
1060 /* Only create the search menu when the drag has not already connected the links to a socket. */
1061 if (!dragged_links_are_detached(nldrag)) {
1062 return false;
1063 }
1064 if (nldrag.swap_links) {
1065 return false;
1066 }
1067 /* Don't create the search menu if the drag is disconnecting a link from an input node. */
1068 if (nldrag.start_socket->in_out == SOCK_IN && nldrag.start_link_count > 0) {
1069 return false;
1070 }
1071 /* Don't allow a drag from the "new socket" (group input node or simulation nodes currently).
1072 * Handling these properly in node callbacks increases the complexity too much for now. */
1073 if (nldrag.start_socket->type == SOCK_CUSTOM) {
1074 return false;
1075 }
1076 if (nldrag.start_socket->type == SOCK_TEXTURE) {
1077 /* This socket types is not used anymore, but can currently still exists in files. */
1078 return false;
1079 }
1080 return true;
1081}
1082
1083static bool need_drag_link_tooltip(const bNodeTree &node_tree, const bNodeLinkDrag &nldrag)
1084{
1085 return nldrag.swap_links || should_create_drag_link_search_menu(node_tree, nldrag);
1086}
1087
1088static void draw_draglink_tooltip(const bContext * /*C*/, ARegion * /*region*/, void *arg)
1089{
1090 bNodeLinkDrag *nldrag = static_cast<bNodeLinkDrag *>(arg);
1091
1092 uchar text_col[4];
1094
1095 const int padding = 4 * UI_SCALE_FAC;
1096 const float x = nldrag->in_out == SOCK_IN ? nldrag->cursor[0] - 3.3f * padding :
1097 nldrag->cursor[0];
1098 const float y = nldrag->cursor[1] - 2.0f * UI_SCALE_FAC;
1099
1100 const bool new_link = nldrag->in_out == nldrag->start_socket->in_out;
1101 const bool swap_links = nldrag->swap_links;
1102
1103 const int icon = !swap_links ? ICON_ADD : (new_link ? ICON_ANIM : ICON_UV_SYNC_SELECT);
1104
1106 x, y, icon, UI_INV_SCALE_FAC, 1.0f, 0.0f, text_col, false, UI_NO_ICON_OVERLAY_TEXT);
1107}
1108
1109static void draw_draglink_tooltip_activate(const ARegion &region, bNodeLinkDrag &nldrag)
1110{
1111 if (nldrag.draw_handle == nullptr) {
1114 }
1115}
1116
1117static void draw_draglink_tooltip_deactivate(const ARegion &region, bNodeLinkDrag &nldrag)
1118{
1119 if (nldrag.draw_handle) {
1121 nldrag.draw_handle = nullptr;
1122 }
1123}
1124
1125static int node_socket_count_links(const bNodeTree &ntree, const bNodeSocket &socket)
1126{
1127 int count = 0;
1128 for (bNodeLink &link : ntree.links) {
1129 if (ELEM(&socket, link.fromsock, link.tosock)) {
1130 count++;
1131 }
1132 }
1133 return count;
1134}
1135
1137 const bNode *node,
1138 bNodeSocket *socket_to_match)
1139{
1140 bNodeSocket *first_socket = socket_to_match->in_out == SOCK_IN ? node->inputs.first() :
1141 node->outputs.first();
1142
1143 bNodeSocket *socket = socket_to_match->next ? socket_to_match->next : first_socket;
1144 while (socket != socket_to_match) {
1145 if (socket->is_visible()) {
1146 const bool sockets_are_compatible = socket->typeinfo == socket_to_match->typeinfo;
1147 if (sockets_are_compatible) {
1148 const int link_count = node_socket_count_links(ntree, *socket);
1149 const bool socket_has_capacity = link_count < bke::node_socket_link_limit(*socket);
1150 if (socket_has_capacity) {
1151 /* Found a valid free socket we can swap to. */
1152 return socket;
1153 }
1154 }
1155 }
1156 /* Wrap around the list end. */
1157 socket = socket->next ? socket->next : first_socket;
1158 }
1159
1160 return nullptr;
1161}
1162
1163static void displace_links(bNodeTree *ntree, const bNode *node, bNodeLink *inserted_link)
1164{
1165 bNodeSocket *linked_socket = node == inserted_link->tonode ? inserted_link->tosock :
1166 inserted_link->fromsock;
1167 bNodeSocket *replacement_socket = node_find_linkable_socket(*ntree, node, linked_socket);
1168
1169 if (linked_socket->is_input()) {
1170 BLI_assert(!linked_socket->is_multi_input());
1171 ntree->ensure_topology_cache();
1172
1173 if (linked_socket->directly_linked_links().is_empty()) {
1174 return;
1175 }
1176 bNodeLink *displaced_link = linked_socket->directly_linked_links().first();
1177
1178 if (!replacement_socket) {
1179 bke::node_remove_link(ntree, *displaced_link);
1180 return;
1181 }
1182
1183 displaced_link->tosock = replacement_socket;
1184
1185 if (replacement_socket->is_multi_input()) {
1186 /* Check for duplicate links when linking to multi input sockets. */
1187 for (bNodeLink *existing_link : replacement_socket->runtime->directly_linked_links) {
1188 if (existing_link->fromsock == displaced_link->fromsock) {
1189 bke::node_remove_link(ntree, *displaced_link);
1190 return;
1191 }
1192 }
1193 const int multi_input_sort_id = node_socket_count_links(*ntree, *replacement_socket) - 1;
1194 displaced_link->multi_input_sort_id = multi_input_sort_id;
1195 }
1196
1198 return;
1199 }
1200
1201 for (bNodeLink &link : ntree->links.items_mutable()) {
1202 if (link.fromsock == linked_socket) {
1203 if (replacement_socket) {
1204 link.fromsock = replacement_socket;
1206 }
1207 else {
1208 bke::node_remove_link(ntree, link);
1210 }
1211 }
1212 }
1213}
1214
1216{
1217 bNodeLink &link = nldrag.links.first();
1218 if (!link.fromsock || !link.tosock) {
1219 return;
1220 }
1221 if (nldrag.start_socket->is_input()) {
1222 displace_links(&ntree, link.fromnode, &link);
1223 }
1224 else {
1225 displace_links(&ntree, link.tonode, &link);
1226 }
1227}
1228
1229static void node_swap_links(bNodeLinkDrag &nldrag, bNodeTree &ntree)
1230{
1231 bNodeSocket &linked_socket = *nldrag.hovered_socket;
1232 bNodeSocket *start_socket = nldrag.start_socket;
1233 bNode *start_node = nldrag.start_node;
1234
1235 if (linked_socket.is_input()) {
1236 for (bNodeLink &link : ntree.links.items_mutable()) {
1237 if (link.tosock != &linked_socket) {
1238 continue;
1239 }
1240 if (link.fromnode == start_node) {
1241 /* Don't link a node to itself. */
1242 bke::node_remove_link(&ntree, link);
1243 continue;
1244 }
1245
1246 link.tosock = start_socket;
1247 link.tonode = start_node;
1248 }
1249 }
1250 else {
1251 for (bNodeLink &link : ntree.links.items_mutable()) {
1252 if (link.fromsock != &linked_socket) {
1253 continue;
1254 }
1255 if (link.tonode == start_node) {
1256 /* Don't link a node to itself. */
1257 bke::node_remove_link(&ntree, link);
1258 continue;
1259 }
1260 link.fromsock = start_socket;
1261 link.fromnode = start_node;
1262 }
1263 }
1264
1266}
1267
1269{
1270 bNodeSocket &linked_socket = *nldrag.hovered_socket;
1271
1272 int link_count = node_socket_count_links(ntree, linked_socket);
1273 const int link_limit = bke::node_socket_link_limit(linked_socket);
1274 Set<bNodeLink *> links_to_remove;
1275
1276 ntree.ensure_topology_cache();
1277
1278 /* Remove duplicate links first. */
1279 for (const bNodeLink dragged_link : nldrag.links) {
1280 if (linked_socket.is_input()) {
1281 for (bNodeLink *link : linked_socket.runtime->directly_linked_links) {
1282 const bool duplicate_link = link->fromsock == dragged_link.fromsock;
1283 if (duplicate_link) {
1284 links_to_remove.add(link);
1285 link_count--;
1286 }
1287 }
1288 }
1289 else {
1290 for (bNodeLink *link : linked_socket.runtime->directly_linked_links) {
1291 const bool duplicate_link = link->tosock == dragged_link.tosock;
1292 if (duplicate_link) {
1293 links_to_remove.add(link);
1294 link_count--;
1295 }
1296 }
1297 }
1298 }
1299
1300 for (bNodeLink *link : linked_socket.runtime->directly_linked_links) {
1301 const bool link_limit_exceeded = !(link_count < link_limit);
1302 if (link_limit_exceeded) {
1303 if (links_to_remove.add(link)) {
1304 link_count--;
1305 }
1306 }
1307 }
1308
1309 for (bNodeLink *link : links_to_remove) {
1310 bke::node_remove_link(&ntree, *link);
1311 }
1312}
1313
1315{
1316 Main *bmain = CTX_data_main(&C);
1317 ARegion &region = *CTX_wm_region(&C);
1318 SpaceNode &snode = *CTX_wm_space_node(&C);
1319 bNodeTree &ntree = *snode.edittree;
1320
1321 /* Handle node links already occupying the socket. */
1322 if (const bNodeSocket *linked_socket = nldrag.hovered_socket) {
1323 /* Swapping existing links out of multi input sockets is not supported. */
1324 const bool connecting_to_multi_input = linked_socket->is_multi_input() ||
1325 nldrag.start_socket->is_multi_input();
1326 if (nldrag.swap_links && !connecting_to_multi_input) {
1327 const bool is_new_link = nldrag.in_out == nldrag.start_socket->in_out;
1328 if (is_new_link) {
1329 node_displace_existing_links(nldrag, ntree);
1330 }
1331 else {
1332 node_swap_links(nldrag, ntree);
1333 }
1334 }
1335 else {
1337 }
1338 }
1339
1340 for (const bNodeLink &link : nldrag.links) {
1341 if (!link.tosock || !link.fromsock) {
1342 continue;
1343 }
1344
1345 /* Before actually adding the link let nodes perform special link insertion handling. */
1346
1347 bNodeLink *new_link = MEM_new<bNodeLink>(__func__, link);
1348 if (link.fromnode->typeinfo->insert_link) {
1349 bke::NodeInsertLinkParams params{ntree, *link.fromnode, *new_link, &C};
1350 if (!link.fromnode->typeinfo->insert_link(params)) {
1351 MEM_delete(new_link);
1352 continue;
1353 }
1354 }
1355 if (link.tonode->typeinfo->insert_link) {
1356 bke::NodeInsertLinkParams params{ntree, *link.tonode, *new_link, &C};
1357 if (!link.tonode->typeinfo->insert_link(params)) {
1358 MEM_delete(new_link);
1359 continue;
1360 }
1361 }
1362
1363 BLI_addtail(&ntree.links, new_link);
1364 BKE_ntree_update_tag_link_added(&ntree, new_link);
1365 }
1366
1367 BKE_main_ensure_invariants(*bmain, ntree.id);
1368
1369 /* Ensure drag-link tool-tip is disabled. */
1370 draw_draglink_tooltip_deactivate(region, nldrag);
1371
1372 ED_workspace_status_text(&C, nullptr);
1373 ED_region_tag_redraw(&region);
1375
1376 snode.runtime->linkdrag.reset();
1377}
1378
1380{
1381 SpaceNode *snode = CTX_wm_space_node(C);
1382 bNodeTree &ntree = *snode->edittree;
1383 bNodeLinkDrag *nldrag = static_cast<bNodeLinkDrag *>(op->customdata);
1384
1385 /* Restore pre-existing links. */
1386 for (bNodeLink &link : nldrag->links) {
1387 if (nldrag->start_socket->is_output() && nldrag->in_out == SOCK_OUT) {
1388 /* Dragged from output socket (to create a new link), nothing to restore. */
1389 continue;
1390 }
1391
1392 bNode *fromnode = nullptr, *tonode = nullptr;
1393 bNodeSocket *fromsock = nullptr, *tosock = nullptr;
1394
1395 if (nldrag->start_socket->is_output() && nldrag->in_out == SOCK_IN) {
1396 /* Existing, disconnected (from output socket) link, fixed on an input socket. */
1397 fromnode = nldrag->start_node;
1398 fromsock = nldrag->start_socket;
1399 tonode = link.tonode;
1400 tosock = link.tosock;
1401 }
1402 else if (nldrag->start_socket->is_input() && nldrag->in_out == SOCK_OUT) {
1403 /* Existing, disconnected (from input socket) link, fixed on an output socket. */
1404 fromnode = link.fromnode;
1405 fromsock = link.fromsock;
1406 tonode = nldrag->start_node;
1407 tosock = nldrag->start_socket;
1408 }
1409
1410 if (ELEM(nullptr, fromnode, fromsock, tonode, tosock)) {
1411 continue;
1412 }
1413
1414 bNodeLink &link_restored = bke::node_add_link(ntree, *fromnode, *fromsock, *tonode, *tosock);
1415
1416 bke::node_link_set_mute(ntree, link_restored, (link.flag & NODE_LINK_MUTED));
1417
1418 if ((tosock->flag & SOCK_MULTI_INPUT)) {
1419 ntree.ensure_topology_cache();
1420 link_restored.multi_input_sort_id = link.multi_input_sort_id;
1421 /* When drag-disconnected from input socket, order from other links will
1422 * have changed, so update sort IDs to prevent invalid cases later on. */
1423 if (nldrag->start_socket->is_input()) {
1424 for (bNodeLink *other_link : tosock->directly_linked_links()) {
1425 if (other_link == &link_restored) {
1426 continue;
1427 }
1428 if (other_link->multi_input_sort_id >= link_restored.multi_input_sort_id) {
1429 other_link->multi_input_sort_id += 1;
1430 }
1431 }
1432 }
1433 }
1434
1435 if (link_restored.fromnode->typeinfo->insert_link) {
1436 bke::NodeInsertLinkParams params{ntree, *link_restored.fromnode, link_restored, C};
1437 if (!link_restored.fromnode->typeinfo->insert_link(params)) {
1438 bke::node_remove_link(&ntree, link_restored);
1439 continue;
1440 }
1441 }
1442 if (link_restored.tonode->typeinfo->insert_link) {
1443 bke::NodeInsertLinkParams params{ntree, *link_restored.tonode, link_restored, C};
1444 if (!link_restored.tonode->typeinfo->insert_link(params)) {
1445 bke::node_remove_link(&ntree, link_restored);
1446 continue;
1447 }
1448 }
1449 }
1450
1452 view2d_edge_pan_cancel(C, &nldrag->pan_data);
1453 snode->runtime->linkdrag.reset();
1457}
1458
1459static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cursor)
1460{
1461 SpaceNode &snode = *CTX_wm_space_node(&C);
1462 ARegion &region = *CTX_wm_region(&C);
1463 bNodeLinkDrag &nldrag = *static_cast<bNodeLinkDrag *>(op.customdata);
1464
1465 if (nldrag.in_out == SOCK_OUT) {
1466 if (bNodeSocket *tsock = node_find_indicated_socket(snode, region, cursor, SOCK_IN)) {
1467 nldrag.hovered_socket = tsock;
1468 bNode &tnode = tsock->owner_node();
1469 for (bNodeLink &link : nldrag.links) {
1470 /* Skip if socket is on the same node as the fromsock. */
1471 if (link.fromnode == &tnode) {
1472 continue;
1473 }
1474
1475 /* Skip if tsock is already linked with this output. */
1476 bNodeLink *existing_link_connected_to_fromsock = nullptr;
1477 for (bNodeLink &existing_link : snode.edittree->links) {
1478 if (existing_link.fromsock == link.fromsock && existing_link.tosock == tsock) {
1479 existing_link_connected_to_fromsock = &existing_link;
1480 break;
1481 }
1482 }
1483
1484 /* Attach links to the socket. */
1485 link.tonode = &tnode;
1486 link.tosock = tsock;
1488 if (existing_link_connected_to_fromsock) {
1489 link.multi_input_sort_id = existing_link_connected_to_fromsock->multi_input_sort_id;
1490 continue;
1491 }
1492 if (tsock && tsock->is_multi_input()) {
1493 sort_multi_input_socket_links_with_drag(*tsock, link, cursor);
1494 }
1495 }
1496 }
1497 else {
1498 nldrag.hovered_socket = nullptr;
1499 for (bNodeLink &link : nldrag.links) {
1500 link.tonode = nullptr;
1501 link.tosock = nullptr;
1502 }
1506 }
1507 }
1508 }
1509 else {
1510 if (bNodeSocket *tsock = node_find_indicated_socket(snode, region, cursor, SOCK_OUT)) {
1511 nldrag.hovered_socket = tsock;
1512 bNode &node = tsock->owner_node();
1513 for (bNodeLink &link : nldrag.links) {
1514 /* Skip if this is already the target socket. */
1515 if (link.fromsock == tsock) {
1516 continue;
1517 }
1518 /* Skip if socket is on the same node as the `fromsock`. */
1519 if (link.tonode == &node) {
1520 continue;
1521 }
1522
1523 /* Attach links to the socket. */
1524 link.fromnode = &node;
1525 link.fromsock = tsock;
1526 }
1527 }
1528 else {
1529 nldrag.hovered_socket = nullptr;
1530 for (bNodeLink &link : nldrag.links) {
1531 link.fromnode = nullptr;
1532 link.fromsock = nullptr;
1533 }
1534 }
1535 }
1536}
1537
1538enum class NodeLinkAction : int {
1540 Cancel = 1,
1541 Swap = 2,
1542 Confirm = 3,
1543};
1544
1546{
1547 static const EnumPropertyItem modal_items[] = {
1548 {int(NodeLinkAction::Begin), "BEGIN", 0, "Drag Node-link", ""},
1549 {int(NodeLinkAction::Confirm), "CONFIRM", 0, "Confirm Link", ""},
1550 {int(NodeLinkAction::Cancel), "CANCEL", 0, "Cancel", ""},
1551 {int(NodeLinkAction::Swap), "SWAP", 0, "Swap Links", ""},
1552 {0, nullptr, 0, nullptr, nullptr},
1553 };
1554
1555 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Node Link Modal Map");
1556
1557 /* This function is called for each space-type, only needs to add map once. */
1558 if (keymap && keymap->modal_items) {
1559 return nullptr;
1560 }
1561
1562 keymap = WM_modalkeymap_ensure(keyconf, "Node Link Modal Map", modal_items);
1563
1564 WM_modalkeymap_assign(keymap, "NODE_OT_link");
1565
1566 return keymap;
1567}
1568
1570{
1571 bNodeLinkDrag &nldrag = *static_cast<bNodeLinkDrag *>(op->customdata);
1572 SpaceNode &snode = *CTX_wm_space_node(C);
1573 ARegion *region = CTX_wm_region(C);
1574
1575 view2d_edge_pan_apply_event(C, &nldrag.pan_data, event);
1576
1577 float2 cursor;
1578 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &cursor.x, &cursor.y);
1579 nldrag.cursor[0] = event->mval[0];
1580 nldrag.cursor[1] = event->mval[1];
1581
1582 if (event->type == EVT_MODAL_MAP) {
1583 switch (event->val) {
1584 case int(NodeLinkAction::Begin): {
1586 }
1587 case int(NodeLinkAction::Confirm): {
1588 /* Add a search menu for compatible sockets if the drag released on empty space. */
1589 if (should_create_drag_link_search_menu(*snode.edittree, nldrag)) {
1590 bNodeLink &link = nldrag.links.first();
1591 if (nldrag.in_out == SOCK_OUT) {
1592 invoke_node_link_drag_add_menu(*C, *link.fromnode, *link.fromsock, cursor);
1593 }
1594 else {
1595 invoke_node_link_drag_add_menu(*C, *link.tonode, *link.tosock, cursor);
1596 }
1597 }
1598 add_dragged_links_to_tree(*C, nldrag);
1599 return OPERATOR_FINISHED;
1600 }
1601 case int(NodeLinkAction::Cancel): {
1602 node_link_cancel(C, op);
1603 return OPERATOR_CANCELLED;
1604 }
1605 case int(NodeLinkAction::Swap):
1606 if (event->prev_val == KM_PRESS) {
1607 nldrag.swap_links = true;
1608 }
1609 else if (event->prev_val == KM_RELEASE) {
1610 nldrag.swap_links = false;
1611 }
1613 }
1614 }
1615 else if (event->type == MOUSEMOVE) {
1616 if (nldrag.start_socket->is_multi_input() && nldrag.links.is_empty()) {
1617 pick_input_link_by_link_intersect(*C, *op, nldrag, cursor);
1618 }
1619 else {
1620 node_link_find_socket(*C, *op, cursor);
1621 ED_region_tag_redraw(region);
1622 }
1623
1624 if (need_drag_link_tooltip(*snode.edittree, nldrag)) {
1625 draw_draglink_tooltip_activate(*region, nldrag);
1626 }
1627 else {
1628 draw_draglink_tooltip_deactivate(*region, nldrag);
1629 }
1630 }
1631
1633}
1634
1636{
1637 tree.ensure_topology_cache();
1638 Vector<bNodeLink *> links = socket.directly_linked_links();
1639 for (bNodeLink *link : links) {
1640 if (!link->is_available()) {
1641 bke::node_remove_link(&tree, *link);
1642 }
1643 }
1644}
1645
1646static std::unique_ptr<bNodeLinkDrag> node_link_init(ARegion &region,
1647 SpaceNode &snode,
1648 const float2 cursor,
1649 const bool detach)
1650{
1651 if (bNodeSocket *sock = node_find_indicated_socket(snode, region, cursor, SOCK_OUT)) {
1652 remove_unavailable_links(*snode.edittree, *sock);
1653 snode.edittree->ensure_topology_cache();
1654 bNode &node = sock->owner_node();
1655
1656 std::unique_ptr<bNodeLinkDrag> nldrag = std::make_unique<bNodeLinkDrag>();
1657 nldrag->start_node = &node;
1658 nldrag->start_socket = sock;
1659 nldrag->start_link_count = bke::node_count_socket_links(*snode.edittree, *sock);
1660 int link_limit = bke::node_socket_link_limit(*sock);
1661 if (nldrag->start_link_count > 0 && (nldrag->start_link_count >= link_limit || detach)) {
1662 /* Dragged links are fixed on input side. */
1663 nldrag->in_out = SOCK_IN;
1664 /* Detach current links and store them in the operator data. */
1665 for (bNodeLink &link : snode.edittree->links.items_mutable()) {
1666 if (link.fromsock == sock) {
1667 bNodeLink oplink = link;
1668 oplink.next = oplink.prev = nullptr;
1669 oplink.flag |= NODE_LINK_VALID;
1670
1671 nldrag->links.append(oplink);
1672 bke::node_remove_link(snode.edittree, link);
1673 }
1674 }
1675 }
1676 else {
1677 /* Dragged links are fixed on output side. */
1678 nldrag->in_out = SOCK_OUT;
1679 nldrag->links.append(create_drag_link(node, *sock));
1680 }
1681 return nldrag;
1682 }
1683
1684 if (bNodeSocket *sock = node_find_indicated_socket(snode, region, cursor, SOCK_IN)) {
1685 remove_unavailable_links(*snode.edittree, *sock);
1686 snode.edittree->ensure_topology_cache();
1687 bNode &node = sock->owner_node();
1688 std::unique_ptr<bNodeLinkDrag> nldrag = std::make_unique<bNodeLinkDrag>();
1689 nldrag->last_node_hovered_while_dragging_a_link = &node;
1690 nldrag->start_node = &node;
1691 nldrag->start_socket = sock;
1692
1693 nldrag->start_link_count = bke::node_count_socket_links(*snode.edittree, *sock);
1694 if (nldrag->start_link_count > 0) {
1695 /* Dragged links are fixed on output side. */
1696 nldrag->in_out = SOCK_OUT;
1697 /* Detach current links and store them in the operator data. */
1698 bNodeLink *link_to_pick;
1699 for (bNodeLink &link : snode.edittree->links.items_mutable()) {
1700 if (link.tosock == sock) {
1701 link_to_pick = &link;
1702 }
1703 }
1704
1705 if (link_to_pick != nullptr && !nldrag->start_socket->is_multi_input()) {
1706 bNodeLink oplink = *link_to_pick;
1707 oplink.next = oplink.prev = nullptr;
1708 oplink.flag |= NODE_LINK_VALID;
1709
1710 nldrag->links.append(oplink);
1711 bke::node_remove_link(snode.edittree, *link_to_pick);
1712
1713 /* Send changed event to original link->tonode. */
1715 }
1716 }
1717 else {
1718 /* Dragged links are fixed on input side. */
1719 nldrag->in_out = SOCK_IN;
1720 nldrag->links.append(create_drag_link(node, *sock));
1721 }
1722 return nldrag;
1723 }
1724
1725 return {};
1726}
1727
1729{
1730 Main &bmain = *CTX_data_main(C);
1731 SpaceNode &snode = *CTX_wm_space_node(C);
1732 ARegion &region = *CTX_wm_region(C);
1733
1734 bool detach = RNA_boolean_get(op->ptr, "detach");
1735
1736 int2 mval;
1737 WM_event_drag_start_mval(event, &region, mval);
1738
1739 float2 cursor;
1740 ui::view2d_region_to_view(&region.v2d, mval[0], mval[1], &cursor[0], &cursor[1]);
1741 RNA_float_set_array(op->ptr, "drag_start", cursor);
1742
1744
1745 std::unique_ptr<bNodeLinkDrag> nldrag = node_link_init(region, snode, cursor, detach);
1746 if (!nldrag) {
1748 }
1749
1750 view2d_edge_pan_operator_init(C, &nldrag->pan_data, op);
1751
1752 /* Add icons at the cursor when the link is dragged in empty space. */
1753 if (need_drag_link_tooltip(*snode.edittree, *nldrag)) {
1755 }
1756 snode.runtime->linkdrag = std::move(nldrag);
1757 op->customdata = snode.runtime->linkdrag.get();
1758
1760
1762}
1763
1765{
1766 /* identifiers */
1767 ot->name = "Link Nodes";
1768 ot->idname = "NODE_OT_link";
1769 ot->description = "Use the mouse to create a link between two nodes";
1770
1771 /* API callbacks. */
1773 ot->modal = node_link_modal;
1776
1777 /* flags */
1779
1780 RNA_def_boolean(ot->srna, "detach", false, "Detach", "Detach and redirect existing links");
1782 "drag_start",
1783 2,
1784 nullptr,
1787 "Drag Start",
1788 "The position of the mouse cursor at the start of the operation",
1791
1799}
1800
1802
1803/* -------------------------------------------------------------------- */
1806
1807/* Makes a link between selected output and input sockets. */
1809{
1810 Main &bmain = *CTX_data_main(C);
1811 SpaceNode &snode = *CTX_wm_space_node(C);
1812 bNodeTree &node_tree = *snode.edittree;
1813 const bool replace = RNA_boolean_get(op->ptr, "replace");
1814
1816
1817 snode_autoconnect(*C, snode, true, replace);
1818
1819 /* Deselect sockets after linking. */
1820 node_deselect_all_input_sockets(node_tree, false);
1821 node_deselect_all_output_sockets(node_tree, false);
1822
1823 BKE_main_ensure_invariants(bmain, node_tree.id);
1824
1825 return OPERATOR_FINISHED;
1826}
1827
1829{
1830 /* identifiers */
1831 ot->name = "Make Links";
1832 ot->description = "Make a link between selected output and input sockets";
1833 ot->idname = "NODE_OT_link_make";
1834
1835 /* callbacks */
1837 /* XXX we need a special poll which checks that there are selected input/output sockets. */
1839
1840 /* flags */
1842
1844 ot->srna, "replace", false, "Replace", "Replace socket connections with the new links");
1845}
1846
1848
1849/* -------------------------------------------------------------------- */
1852
1854{
1855 Main &bmain = *CTX_data_main(C);
1856 SpaceNode &snode = *CTX_wm_space_node(C);
1857 const ARegion &region = *CTX_wm_region(C);
1858
1859 Vector<float2> path;
1860 RNA_BEGIN (op->ptr, itemptr, "path") {
1861 float2 loc_region;
1862 RNA_float_get_array(&itemptr, "loc", loc_region);
1863 float2 loc_view;
1864 ui::view2d_region_to_view(&region.v2d, loc_region.x, loc_region.y, &loc_view.x, &loc_view.y);
1865 path.append(loc_view);
1866 if (path.size() >= 256) {
1867 break;
1868 }
1869 }
1870 RNA_END;
1871
1872 if (path.is_empty()) {
1874 }
1875
1876 bool found = false;
1877
1879
1880 bNodeTree &node_tree = *snode.edittree;
1881 node_tree.ensure_topology_cache();
1882
1883 Set<bNodeLink *> links_to_remove;
1884 for (bNodeLink &link : node_tree.links) {
1885 if (node_link_is_hidden_or_dimmed(region.v2d, link)) {
1886 continue;
1887 }
1888
1889 if (link_path_intersection(link, path)) {
1890
1891 if (!found) {
1892 /* TODO(sergey): Why did we kill jobs twice? */
1894 found = true;
1895 }
1896 links_to_remove.add(&link);
1897 }
1898 }
1899
1900 Set<bNode *> affected_nodes;
1901 for (bNodeLink *link : links_to_remove) {
1902 bNode *to_node = link->tonode;
1903 bke::node_remove_link(snode.edittree, *link);
1904 affected_nodes.add(to_node);
1905 }
1906
1907 node_tree.ensure_topology_cache();
1908 for (bNode *node : affected_nodes) {
1910 }
1911
1913 if (found) {
1914 return OPERATOR_FINISHED;
1915 }
1916
1917 return OPERATOR_CANCELLED;
1918}
1919
1921{
1922 ot->name = "Cut Links";
1923 ot->idname = "NODE_OT_links_cut";
1924 ot->description = "Use the mouse to cut (remove) some links";
1925
1928 ot->exec = cut_links_exec;
1930
1932
1933 /* flags */
1935
1936 /* properties */
1937 PropertyRNA *prop;
1938 prop = RNA_def_collection_runtime(ot->srna, "path", RNA_OperatorMousePath, "Path", "");
1940
1941 /* internal */
1942 RNA_def_int(ot->srna, "cursor", WM_CURSOR_KNIFE, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
1943}
1944
1946
1947/* -------------------------------------------------------------------- */
1950
1951bool all_links_muted(const bNodeSocket &socket)
1952{
1953 for (const bNodeLink *link : socket.directly_linked_links()) {
1954 if (!(link->flag & NODE_LINK_MUTED)) {
1955 return false;
1956 }
1957 }
1958 return true;
1959}
1960
1962{
1963 Main &bmain = *CTX_data_main(C);
1964 SpaceNode &snode = *CTX_wm_space_node(C);
1965 const ARegion &region = *CTX_wm_region(C);
1966 bNodeTree &ntree = *snode.edittree;
1967
1968 Vector<float2> path;
1969 RNA_BEGIN (op->ptr, itemptr, "path") {
1970 float2 loc_region;
1971 RNA_float_get_array(&itemptr, "loc", loc_region);
1972 float2 loc_view;
1973 ui::view2d_region_to_view(&region.v2d, loc_region.x, loc_region.y, &loc_view.x, &loc_view.y);
1974 path.append(loc_view);
1975 if (path.size() >= 256) {
1976 break;
1977 }
1978 }
1979 RNA_END;
1980
1981 if (path.is_empty()) {
1983 }
1984
1986
1987 ntree.ensure_topology_cache();
1988
1989 Set<bNodeLink *> affected_links;
1990 for (bNodeLink &link : ntree.links) {
1991 if (node_link_is_hidden_or_dimmed(region.v2d, link)) {
1992 continue;
1993 }
1994 if (!link_path_intersection(link, path)) {
1995 continue;
1996 }
1997 affected_links.add(&link);
1998 }
1999
2000 if (affected_links.is_empty()) {
2001 return OPERATOR_CANCELLED;
2002 }
2003
2004 bke::node_tree_runtime::AllowUsingOutdatedInfo allow_outdated_info{ntree};
2005
2006 for (bNodeLink *link : affected_links) {
2007 bke::node_link_set_mute(ntree, *link, !(link->flag & NODE_LINK_MUTED));
2008 const bool muted = link->flag & NODE_LINK_MUTED;
2009
2010 /* Propagate mute status downstream past reroute nodes. */
2011 if (link->tonode->is_reroute()) {
2012 Stack<bNodeLink *> links;
2013 links.push_multiple(link->tonode->output_socket(0).directly_linked_links());
2014 while (!links.is_empty()) {
2015 bNodeLink *link = links.pop();
2016 bke::node_link_set_mute(ntree, *link, muted);
2017 if (!link->tonode->is_reroute()) {
2018 continue;
2019 }
2020 links.push_multiple(link->tonode->output_socket(0).directly_linked_links());
2021 }
2022 }
2023 /* Propagate mute status upstream past reroutes, but only if all outputs are muted. */
2024 if (link->fromnode->is_reroute()) {
2025 if (!muted || all_links_muted(*link->fromsock)) {
2026 Stack<bNodeLink *> links;
2027 links.push_multiple(link->fromnode->input_socket(0).directly_linked_links());
2028 while (!links.is_empty()) {
2029 bNodeLink *link = links.pop();
2030 bke::node_link_set_mute(ntree, *link, muted);
2031 if (!link->fromnode->is_reroute()) {
2032 continue;
2033 }
2034 if (!muted || all_links_muted(*link->fromsock)) {
2035 links.push_multiple(link->fromnode->input_socket(0).directly_linked_links());
2036 }
2037 }
2038 }
2039 }
2040 }
2041
2043 return OPERATOR_FINISHED;
2044}
2045
2047{
2048 ot->name = "Mute Links";
2049 ot->idname = "NODE_OT_links_mute";
2050 ot->description = "Use the mouse to mute links";
2051
2054 ot->exec = mute_links_exec;
2056
2058
2059 /* flags */
2061
2062 /* properties */
2063 PropertyRNA *prop;
2064 prop = RNA_def_collection_runtime(ot->srna, "path", RNA_OperatorMousePath, "Path", "");
2066
2067 /* internal */
2068 RNA_def_int(ot->srna, "cursor", WM_CURSOR_MUTE, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
2069}
2070
2072
2073/* -------------------------------------------------------------------- */
2076
2078{
2079 SpaceNode &snode = *CTX_wm_space_node(C);
2080 bNodeTree &ntree = *snode.edittree;
2081
2083
2084 for (bNode *node : ntree.all_nodes()) {
2085 if (node->is_selected()) {
2087 }
2088 }
2089
2091 return OPERATOR_FINISHED;
2092}
2093
2095{
2096 ot->name = "Detach Links";
2097 ot->idname = "NODE_OT_links_detach";
2098 ot->description =
2099 "Remove all links to selected nodes, and try to connect neighbor nodes together";
2100
2101 ot->exec = detach_links_exec;
2103
2104 /* flags */
2106}
2107
2109
2110/* -------------------------------------------------------------------- */
2113
2115{
2116 SpaceNode &snode = *CTX_wm_space_node(C);
2117 bNodeTree &ntree = *snode.edittree;
2118 bNode *frame = bke::node_get_active(ntree);
2119 if (!frame || !frame->is_frame()) {
2120 return OPERATOR_CANCELLED;
2121 }
2122
2123 for (bNode *node : ntree.all_nodes()) {
2124 if (node == frame) {
2125 continue;
2126 }
2127 if (node->is_selected()) {
2128 bke::node_detach_node(ntree, *node);
2129 bke::node_attach_node(ntree, *node, *frame);
2130 }
2131 }
2132
2135
2136 return OPERATOR_FINISHED;
2137}
2138
2140{
2141 /* identifiers */
2142 ot->name = "Make Parent";
2143 ot->description = "Attach selected nodes";
2144 ot->idname = "NODE_OT_parent_set";
2145
2146 /* API callbacks. */
2149
2150 /* flags */
2152}
2153
2155
2156/* -------------------------------------------------------------------- */
2159
2161 bool done;
2163};
2164
2166 MutableSpan<NodeJoinState> join_states,
2167 bNode *node,
2168 bNode *frame,
2169 const VectorSet<bNode *> &selected_nodes)
2170{
2171 join_states[node->index()].done = true;
2172
2173 if (node == frame) {
2174 join_states[node->index()].descendent = true;
2175 }
2176 else if (node->parent) {
2177 /* call recursively */
2178 if (!join_states[node->parent->index()].done) {
2179 node_join_attach_recursive(ntree, join_states, node->parent, frame, selected_nodes);
2180 }
2181
2182 /* in any case: if the parent is a descendant, so is the child */
2183 if (join_states[node->parent->index()].descendent) {
2184 join_states[node->index()].descendent = true;
2185 }
2186 else if (selected_nodes.contains(node)) {
2187 /* if parent is not an descendant of the frame, reattach the node */
2188 bke::node_detach_node(ntree, *node);
2189 bke::node_attach_node(ntree, *node, *frame);
2190 join_states[node->index()].descendent = true;
2191 }
2192 }
2193 else if (selected_nodes.contains(node)) {
2194 bke::node_attach_node(ntree, *node, *frame);
2195 join_states[node->index()].descendent = true;
2196 }
2197}
2198
2200{
2201 Vector<bNode *> parents;
2202 for (bNode *parent = node.parent; parent; parent = parent->parent) {
2203 parents.append(parent);
2204 }
2205 /* Reverse so that the root frame is the first element (if there is any). */
2206 std::reverse(parents.begin(), parents.end());
2207 return parents;
2208}
2209
2211{
2212 if (nodes.is_empty()) {
2213 return nullptr;
2214 }
2215 /* The common parent node also has to be a parent of the first node. */
2217 for (const bNode *node : nodes.drop_front(1)) {
2219 /* Possibly shrink set of candidates so that it only contains the parents common with the
2220 * current node. */
2221 candidates.resize(std::min(candidates.size(), parents.size()));
2222 for (const int i : candidates.index_range()) {
2223 if (candidates[i] != parents[i]) {
2224 candidates.resize(i);
2225 break;
2226 }
2227 }
2228 if (candidates.is_empty()) {
2229 break;
2230 }
2231 }
2232 if (candidates.is_empty()) {
2233 return nullptr;
2234 }
2235 return candidates.last();
2236}
2237
2239{
2240 Main &bmain = *CTX_data_main(C);
2241 SpaceNode &snode = *CTX_wm_space_node(C);
2242 bNodeTree &ntree = *snode.edittree;
2243
2244 const VectorSet<bNode *> selected_nodes = get_selected_nodes(ntree);
2245
2246 bNode *frame_node = add_static_node(*C, NODE_FRAME, snode.runtime->cursor);
2247 bke::node_set_active(ntree, *frame_node);
2248 frame_node->parent = find_common_parent_node(selected_nodes.as_span());
2249
2250 ntree.ensure_topology_cache();
2251
2252 Array<NodeJoinState> join_states(ntree.all_nodes().size(), NodeJoinState{false, false});
2253
2254 for (bNode *node : ntree.all_nodes()) {
2255 if (!join_states[node->index()].done) {
2256 node_join_attach_recursive(ntree, join_states, node, frame_node, selected_nodes);
2257 }
2258 }
2259
2261 BKE_main_ensure_invariants(bmain, snode.edittree->id);
2263
2264 return OPERATOR_FINISHED;
2265}
2266
2268 wmOperator *op,
2269 const wmEvent *event)
2270{
2271 ARegion *region = CTX_wm_region(C);
2272 SpaceNode *snode = CTX_wm_space_node(C);
2273
2274 /* Convert mouse coordinates to v2d space. */
2276 event->mval[0],
2277 event->mval[1],
2278 &snode->runtime->cursor[0],
2279 &snode->runtime->cursor[1]);
2280
2281 snode->runtime->cursor[0] /= UI_SCALE_FAC;
2282 snode->runtime->cursor[1] /= UI_SCALE_FAC;
2283
2284 return node_join_in_frame_exec(C, op);
2285}
2286
2288{
2289 /* identifiers */
2290 ot->name = "Join Nodes in Frame";
2291 ot->description = "Attach selected nodes to a new common frame";
2292 ot->idname = "NODE_OT_join";
2293
2294 /* API callbacks. */
2298
2299 /* flags */
2301}
2302
2304
2305/* -------------------------------------------------------------------- */
2308
2309static void join_group_inputs(bNodeTree &tree, VectorSet<bNode *> group_inputs, bNode *active_node)
2310{
2311 bNode *main_node = nullptr;
2312 if (group_inputs.contains(active_node)) {
2313 main_node = active_node;
2314 }
2315 else {
2316 main_node = group_inputs[0];
2317 /* Move main node to average of all group inputs. */
2318 float2 location{};
2319 for (const bNode *node : group_inputs) {
2320 location += node->location;
2321 }
2322 location /= float(group_inputs.size());
2323 copy_v2_v2(main_node->location, location);
2324 }
2325 tree.ensure_topology_cache();
2327 for (bNode *node : group_inputs) {
2328 for (bNodeSocket *socket : node->output_sockets().drop_back(1)) {
2329 old_link_map.add_multiple(socket, socket->directly_linked_links());
2330 }
2331 }
2333 for (bNodeSocket *socket : main_node->output_sockets()) {
2334 used_link_targets.add_multiple(socket, socket->directly_linked_sockets());
2335 }
2336 for (bNode *node : group_inputs) {
2337 if (node == main_node) {
2338 continue;
2339 }
2340 bool keep_node = false;
2341
2342 /* Using runtime data directly because we know the parts that are used are still valid. */
2343 for (const int group_input_i : node->runtime->outputs.index_range().drop_back(1)) {
2344 bNodeSocket &new_socket = *main_node->runtime->outputs[group_input_i];
2345 bNodeSocket &old_socket = *node->runtime->outputs[group_input_i];
2346 bool keep_socket = (old_socket.flag & SOCK_HIDDEN) == 0;
2347 for (bNodeLink *link : old_link_map.lookup(&old_socket)) {
2348 bNodeSocket &to_socket = *link->tosock;
2349 if (used_link_targets.lookup(&new_socket).contains(&to_socket)) {
2350 keep_node = true;
2351 keep_socket = true;
2352 continue;
2353 }
2354 used_link_targets.add(&new_socket, &to_socket);
2355 link->fromsock = &new_socket;
2356 link->fromnode = main_node;
2357 keep_socket = true;
2359 }
2360 if (keep_socket) {
2361 new_socket.flag &= ~SOCK_HIDDEN;
2362 }
2363 else {
2364 old_socket.flag |= SOCK_HIDDEN;
2365 }
2366 }
2367 if (!keep_node) {
2368 bke::node_free_node(&tree, *node);
2369 }
2370 }
2371}
2372
2374{
2375 Main &bmain = *CTX_data_main(C);
2376 SpaceNode &snode = *CTX_wm_space_node(C);
2377 bNodeTree &ntree = *snode.edittree;
2378
2379 bNode *active_node = bke::node_get_active(ntree);
2380 VectorSet<bNode *> selected_nodes = get_selected_nodes(ntree);
2381 if (selected_nodes.size() <= 1) {
2382 return OPERATOR_CANCELLED;
2383 }
2384
2385 if (std::all_of(selected_nodes.begin(),
2386 selected_nodes.end(),
2387 [](const bNode *node) { return node->is_group_input(); }))
2388 {
2389 join_group_inputs(ntree, std::move(selected_nodes), active_node);
2390 }
2391 else {
2392 BKE_report(op->reports, RPT_ERROR, "Selected nodes can't be joined");
2393 return OPERATOR_CANCELLED;
2394 }
2395
2396 BKE_main_ensure_invariants(bmain, snode.edittree->id);
2398
2399 return OPERATOR_FINISHED;
2400}
2401
2403{
2404 ot->name = "Join Nodes";
2405 ot->description = "Merge selected group input nodes into one if possible";
2406 ot->idname = "NODE_OT_join_nodes";
2407
2410
2412}
2413
2415
2416/* -------------------------------------------------------------------- */
2419
2420static bNode *node_find_frame_to_attach(ARegion &region, bNodeTree &ntree, const int2 mouse_xy)
2421{
2422 /* convert mouse coordinates to v2d space */
2423 float2 cursor;
2424 ui::view2d_region_to_view(&region.v2d, mouse_xy.x, mouse_xy.y, &cursor.x, &cursor.y);
2425
2426 for (bNode *frame : tree_draw_order_calc_nodes_reversed(ntree)) {
2427 /* skip selected, those are the nodes we want to attach */
2428 if (!frame->is_frame() || frame->is_selected()) {
2429 continue;
2430 }
2431 if (BLI_rctf_isect_pt_v(&frame->runtime->draw_bounds, cursor)) {
2432 return frame;
2433 }
2434 }
2435
2436 return nullptr;
2437}
2438
2439static bool can_attach_node_to_frame(const bNode &node, const bNode &frame)
2440{
2441 /* Disallow moving a parent into its child. */
2442 if (node.is_frame() && bke::node_is_parent_and_child(node, frame)) {
2443 return false;
2444 }
2445 if (node.parent == nullptr) {
2446 return true;
2447 }
2448 if (node.parent == &frame) {
2449 return false;
2450 }
2451 /* Attach nodes which share parent with the frame. */
2452 const bool share_parent = bke::node_is_parent_and_child(*node.parent, frame);
2453 if (!share_parent) {
2454 return false;
2455 }
2456 return true;
2457}
2458
2460{
2461 ARegion &region = *CTX_wm_region(C);
2462 SpaceNode &snode = *CTX_wm_space_node(C);
2463 bNodeTree &ntree = *snode.edittree;
2464 bNode *frame = node_find_frame_to_attach(region, ntree, event->mval);
2465 if (frame == nullptr) {
2466 /* Return "finished" so that auto offset operator macros can work. */
2467 return OPERATOR_FINISHED;
2468 }
2469
2470 bool changed = false;
2471
2473 if (!node->is_selected()) {
2474 continue;
2475 }
2476 if (!can_attach_node_to_frame(*node, *frame)) {
2477 continue;
2478 }
2479 bke::node_detach_node(ntree, *node);
2480 bke::node_attach_node(ntree, *node, *frame);
2481 changed = true;
2482 }
2483
2484 if (changed) {
2487 }
2488
2489 return OPERATOR_FINISHED;
2490}
2491
2493{
2494 ot->name = "Attach Nodes";
2495 ot->description = "Attach active node to a frame";
2496 ot->idname = "NODE_OT_attach";
2497
2500
2502}
2503
2505
2506/* -------------------------------------------------------------------- */
2509
2511 bool done;
2513};
2514
2516 MutableSpan<NodeDetachstate> detach_states,
2517 bNode *node)
2518{
2519 detach_states[node->index()].done = true;
2520
2521 if (node->parent) {
2522 /* Call recursively. */
2523 if (!detach_states[node->parent->index()].done) {
2524 node_detach_recursive(ntree, detach_states, node->parent);
2525 }
2526
2527 /* In any case: if the parent is a descendant, so is the child. */
2528 if (detach_states[node->parent->index()].descendent) {
2529 detach_states[node->index()].descendent = true;
2530 }
2531 else if (node->is_selected()) {
2532 /* If parent is not a descendant of a selected node, detach. */
2533 bke::node_detach_node(ntree, *node);
2534 detach_states[node->index()].descendent = true;
2535 }
2536 }
2537 else if (node->is_selected()) {
2538 detach_states[node->index()].descendent = true;
2539 }
2540}
2541
2542/* Detach the root nodes in the current selection. */
2544{
2545 SpaceNode &snode = *CTX_wm_space_node(C);
2546 bNodeTree &ntree = *snode.edittree;
2547
2548 Array<NodeDetachstate> detach_states(ntree.all_nodes().size(), NodeDetachstate{false, false});
2549
2550 /* Detach nodes recursively. Relative order is preserved here. */
2551 for (bNode *node : ntree.all_nodes()) {
2552 if (!detach_states[node->index()].done) {
2553 node_detach_recursive(ntree, detach_states, node);
2554 }
2555 }
2556
2559
2560 return OPERATOR_FINISHED;
2561}
2562
2564{
2565 /* identifiers */
2566 ot->name = "Detach Nodes";
2567 ot->description = "Detach selected nodes from parents";
2568 ot->idname = "NODE_OT_detach";
2569
2570 /* API callbacks. */
2571 ot->exec = node_detach_exec;
2573
2574 /* flags */
2576}
2577
2579
2580/* -------------------------------------------------------------------- */
2583
2585{
2586 bNode *selected_node = nullptr;
2587 int selected_node_count = 0;
2588 for (bNode *node : node_tree.all_nodes()) {
2589 if (node->is_selected()) {
2590 selected_node = node;
2591 selected_node_count++;
2592 }
2593 if (selected_node_count > 1) {
2594 return nullptr;
2595 }
2596 }
2597 if (!selected_node) {
2598 return nullptr;
2599 }
2600 if (selected_node->input_sockets().is_empty() || selected_node->output_sockets().is_empty()) {
2601 return nullptr;
2602 }
2603 return selected_node;
2604}
2605
2607{
2608 const bNodeSocket *main_input = get_main_socket(tree, node, SOCK_IN);
2609 const bNodeSocket *main_output = get_main_socket(tree, node, SOCK_IN);
2610 if (ELEM(nullptr, main_input, main_output)) {
2611 return false;
2612 }
2613 if (node.is_reroute()) {
2614 return true;
2615 }
2616 if (!tree.typeinfo->validate_link) {
2617 return true;
2618 }
2619 if (!tree.typeinfo->validate_link(link.fromsock->type, main_input->type)) {
2620 return false;
2621 }
2622 if (!tree.typeinfo->validate_link(main_output->type, link.tosock->type)) {
2623 return false;
2624 }
2625 return true;
2626}
2627
2629 const ARegion &region,
2630 const bool attach_enabled,
2631 const bool is_new_node)
2632{
2633 bNodeTree &node_tree = *snode.edittree;
2634 node_tree.ensure_topology_cache();
2635
2637
2638 bNode *node_to_insert = get_selected_node_for_insertion(node_tree);
2639 if (!node_to_insert) {
2640 return;
2641 }
2642 Vector<bNodeSocket *> already_linked_sockets;
2643 for (bNodeSocket *socket : node_to_insert->input_sockets()) {
2644 already_linked_sockets.extend(socket->directly_linked_sockets());
2645 }
2646 for (bNodeSocket *socket : node_to_insert->output_sockets()) {
2647 already_linked_sockets.extend(socket->directly_linked_sockets());
2648 }
2649 if (!is_new_node && !already_linked_sockets.is_empty()) {
2650 return;
2651 }
2652
2653 /* Find link to select/highlight. */
2654 bNodeLink *selink = nullptr;
2655 float dist_best = FLT_MAX;
2656 for (bNodeLink &link : node_tree.links) {
2657 if (node_link_is_hidden_or_dimmed(region.v2d, link)) {
2658 continue;
2659 }
2660 if (ELEM(node_to_insert, link.fromnode, link.tonode)) {
2661 /* Don't insert on a link that is connected to the node already. */
2662 continue;
2663 }
2664 if (is_new_node && !already_linked_sockets.is_empty()) {
2665 /* Only allow links coming from or going to the already linked socket after
2666 * link-drag-search. */
2667 bool is_linked_to_linked = false;
2668 for (const bNodeSocket *socket : already_linked_sockets) {
2669 if (ELEM(socket, link.fromsock, link.tosock)) {
2670 is_linked_to_linked = true;
2671 break;
2672 }
2673 }
2674 if (!is_linked_to_linked) {
2675 continue;
2676 }
2677 }
2678
2679 std::array<float2, NODE_LINK_RESOL + 1> coords;
2681 float dist = FLT_MAX;
2682
2683 /* Loop over link coords to find shortest dist to upper left node edge of a intersected line
2684 * segment. */
2685 for (int i = 0; i < NODE_LINK_RESOL; i++) {
2686 /* Check if the node rectangle intersects the line from this point to next one. */
2687 if (BLI_rctf_isect_segment(&node_to_insert->runtime->draw_bounds, coords[i], coords[i + 1]))
2688 {
2689 /* Store the shortest distance to the upper left edge of all intersections found so far. */
2690 const float node_xy[] = {node_to_insert->runtime->draw_bounds.xmin,
2691 node_to_insert->runtime->draw_bounds.ymax};
2692
2693 /* To be precise coords should be clipped by `select->draw_bounds`, but not done since
2694 * there's no real noticeable difference. */
2695 dist = min_ff(dist_squared_to_line_segment_v2(node_xy, coords[i], coords[i + 1]), dist);
2696 }
2697 }
2698
2699 /* We want the link with the shortest distance to node center. */
2700 if (dist < dist_best) {
2701 dist_best = dist;
2702 selink = &link;
2703 }
2704 }
2705
2706 if (selink) {
2707 selink->flag |= NODE_LINK_INSERT_TARGET;
2708 if (!attach_enabled || !node_can_be_inserted_on_link(node_tree, *node_to_insert, *selink)) {
2710 }
2711 }
2712}
2713
2714void node_insert_on_frame_flag_set(SpaceNode &snode, ARegion &region, const int2 &cursor)
2715{
2717
2718 snode.edittree->ensure_topology_cache();
2719 const bNode *frame = node_find_frame_to_attach(region, *snode.edittree, cursor);
2720 if (!frame) {
2721 return;
2722 }
2723 for (const bNode *node : snode.edittree->all_nodes()) {
2724 if (!node->is_selected()) {
2725 continue;
2726 }
2727 if (!can_attach_node_to_frame(*node, *frame)) {
2728 continue;
2729 }
2730 /* We detected that a node can be attached to the frame, so highlight it. */
2732 return;
2733 }
2734}
2735
2740
2742{
2743 for (bNodeLink &link : node_tree.links) {
2745 }
2746}
2747
2748void node_insert_on_link_flags(Main &bmain, SpaceNode &snode, bool is_new_node)
2749{
2750 bNodeTree &ntree = *snode.edittree;
2751 ntree.ensure_topology_cache();
2752 bNode *node_to_insert = get_selected_node_for_insertion(ntree);
2753 if (!node_to_insert) {
2754 return;
2755 }
2756
2757 /* Find link to insert on. */
2758 bNodeLink *old_link = nullptr;
2759 for (bNodeLink &link : ntree.links) {
2760 if (link.flag & NODE_LINK_INSERT_TARGET) {
2761 if (!(link.flag & NODE_LINK_INSERT_TARGET_INVALID)) {
2762 old_link = &link;
2763 }
2764 break;
2765 }
2766 }
2768 if (old_link == nullptr) {
2769 return;
2770 }
2771
2772 bNodeSocket *best_input = nullptr;
2773 if (is_new_node) {
2774 for (bNodeSocket *socket : node_to_insert->input_sockets()) {
2775 if (!socket->directly_linked_sockets().is_empty()) {
2776 best_input = socket;
2777 break;
2778 }
2779 }
2780 }
2781 if (!best_input) {
2782 best_input = get_main_socket(ntree, *node_to_insert, SOCK_IN);
2783 }
2784 bNodeSocket *best_output = nullptr;
2785 if (is_new_node) {
2786 for (bNodeSocket *socket : node_to_insert->output_sockets()) {
2787 if (!socket->directly_linked_sockets().is_empty()) {
2788 best_output = socket;
2789 break;
2790 }
2791 }
2792 }
2793 if (!best_output) {
2794 best_output = get_main_socket(ntree, *node_to_insert, SOCK_OUT);
2795 }
2796
2797 if (!node_to_insert->is_reroute()) {
2798 /* Ignore main sockets when the types don't match. */
2799 if (best_input != nullptr && ntree.typeinfo->validate_link != nullptr &&
2800 !ntree.typeinfo->validate_link(old_link->fromsock->type, best_input->type))
2801 {
2802 best_input = nullptr;
2803 }
2804 if (best_output != nullptr && ntree.typeinfo->validate_link != nullptr &&
2805 !ntree.typeinfo->validate_link(best_output->type, old_link->tosock->type))
2806 {
2807 best_output = nullptr;
2808 }
2809 }
2810
2811 bNode *from_node = old_link->fromnode;
2812 bNodeSocket *from_socket = old_link->fromsock;
2813 bNode *to_node = old_link->tonode;
2814
2815 const bool best_input_is_linked = best_input && best_input->is_directly_linked();
2816 const bool old_link_muted = old_link->is_muted();
2817
2818 if (best_output != nullptr) {
2819 /* Relink the "start" of the existing link to the newly inserted node. */
2820 old_link->fromnode = node_to_insert;
2821 old_link->fromsock = best_output;
2823 }
2824 else {
2825 bke::node_remove_link(&ntree, *old_link);
2826 }
2827
2828 if (best_input != nullptr) {
2829 /* Don't change an existing link. */
2830 if (!best_input_is_linked) {
2831 /* Add a new link that connects the node on the left to the newly inserted node. */
2832 bNodeLink &link_from = bke::node_add_link(
2833 ntree, *from_node, *from_socket, *node_to_insert, *best_input);
2834 bke::node_link_set_mute(ntree, link_from, old_link_muted);
2835 }
2836 }
2837
2838 /* Set up insert offset data, it needs stuff from here. */
2839 if (U.uiflag & USER_NODE_AUTO_OFFSET) {
2840 BLI_assert(snode.runtime->iofsd == nullptr);
2841 auto iofsd = std::make_unique<NodeInsertOfsData>();
2842
2843 iofsd->insert = node_to_insert;
2844 iofsd->prev = from_node;
2845 iofsd->next = to_node;
2846
2847 snode.runtime->iofsd = std::move(iofsd);
2848 }
2849
2850 BKE_main_ensure_invariants(bmain, ntree.id);
2851}
2852
2854
2855/* -------------------------------------------------------------------- */
2858
2859static int get_main_socket_priority(const bNodeSocket *socket)
2860{
2861 switch (socket->type) {
2862 case SOCK_CUSTOM:
2863 return 0;
2864 case SOCK_MENU:
2865 return 1;
2866 case SOCK_BOOLEAN:
2867 return 2;
2868 case SOCK_INT:
2869 return 3;
2870 case SOCK_FLOAT:
2871 return 4;
2872 case SOCK_VECTOR:
2873 return 5;
2874 case SOCK_RGBA:
2875 return 6;
2876 case SOCK_INT_VECTOR:
2877 case SOCK_STRING:
2878 case SOCK_SHADER:
2879 case SOCK_OBJECT:
2880 case SOCK_IMAGE:
2881 case SOCK_ROTATION:
2882 case SOCK_MATRIX:
2883 case SOCK_GEOMETRY:
2884 case SOCK_COLLECTION:
2885 case SOCK_TEXTURE:
2886 case SOCK_MATERIAL:
2887 case SOCK_FONT:
2888 case SOCK_SCENE:
2889 case SOCK_TEXT_ID:
2890 case SOCK_MASK:
2891 case SOCK_SOUND:
2892 case SOCK_BUNDLE:
2893 case SOCK_CLOSURE:
2894 return 7;
2895 }
2896 return -1;
2897}
2898
2900{
2901 ListBaseT<bNodeSocket> *sockets = (in_out == SOCK_IN) ? &node.inputs : &node.outputs;
2902
2903 /* Try to get the main socket based on the socket declaration. */
2905 const nodes::NodeDeclaration *node_decl = node.declaration();
2906 if (node_decl != nullptr) {
2907 Span<nodes::SocketDeclaration *> socket_decls = (in_out == SOCK_IN) ? node_decl->inputs :
2908 node_decl->outputs;
2909 for (const nodes::SocketDeclaration *socket_decl : socket_decls) {
2910 if (!socket_decl->is_default_link_socket) {
2911 continue;
2912 }
2913 bNodeSocket *socket = static_cast<bNodeSocket *>(BLI_findlink(sockets, socket_decl->index));
2914 if (socket && socket->is_visible()) {
2915 return socket;
2916 }
2917 }
2918 }
2919
2920 /* Find priority range. */
2921 int maxpriority = -1;
2922 for (bNodeSocket &sock : *sockets) {
2923 if (sock.flag & SOCK_UNAVAIL) {
2924 continue;
2925 }
2926 maxpriority = max_ii(get_main_socket_priority(&sock), maxpriority);
2927 }
2928
2929 /* Try all priorities, starting from 'highest'. */
2930 for (int priority = maxpriority; priority >= 0; priority--) {
2931 for (bNodeSocket &sock : *sockets) {
2932 if (!!sock.is_visible() && priority == get_main_socket_priority(&sock)) {
2933 return &sock;
2934 }
2935 }
2936 }
2937
2938 return nullptr;
2939}
2940
2942 const bool left_to_right,
2943 MutableSpan<bool> mask_to_propagate)
2944{
2945 for (const bNode *node : nodes) {
2946 const Span<const bNodeSocket *> sockets = left_to_right ? node->input_sockets() :
2947 node->output_sockets();
2948 bool &node_value = mask_to_propagate[node->index()];
2949 for (const bNodeSocket *socket : sockets) {
2950 for (const bNodeLink *link : socket->directly_linked_links()) {
2951 if (!(link->tosock->is_visible() && link->fromsock->is_visible())) {
2952 continue;
2953 }
2954 if ((link->flag & NODE_LINK_VALID) == 0) {
2955 continue;
2956 }
2957
2958 const bNodeSocket *other_socket = left_to_right ? link->fromsock : link->tosock;
2959 const bNode &other_node = other_socket->owner_node();
2960 node_value |= mask_to_propagate[other_node.index()];
2961 if (node_value) {
2962 break;
2963 }
2964 }
2965 if (node_value) {
2966 break;
2967 }
2968 }
2969 }
2970}
2971
2972static void shift_nodes(bNodeTree &tree,
2973 const bNode &start_node,
2974 const bool left_to_right,
2975 const float value)
2976{
2977 const Span<bNode *> nodes = tree.all_nodes();
2978 Array<bool> shift_mask(nodes.size(), false);
2979
2980 const Span<const bNode *> sorted_nodes = left_to_right ? tree.toposort_left_to_right() :
2981 tree.toposort_right_to_left();
2982 shift_mask[start_node.index()] = true;
2984 sorted_nodes.drop_front(sorted_nodes.first_index(&start_node)), left_to_right, shift_mask);
2985
2986 for (const int index : nodes.index_range()) {
2987 if (shift_mask[index]) {
2988 nodes[index]->runtime->anim_ofsx = value;
2989 }
2990 }
2991}
2992
2993static bool node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, const bool right_alignment)
2994{
2995 bNodeTree &ntree = *iofsd->ntree;
2996 bNode &insert = *iofsd->insert;
2997 bNode &prev = *iofsd->prev;
2998 bNode &next = *iofsd->next;
2999
3000 ntree.ensure_topology_cache();
3001
3002 /* `insert.draw_bounds` isn't updated yet,
3003 * so `totr_insert` is used to get the correct world-space coords. */
3004 rctf totr_insert;
3005 node_to_updated_rect(insert, totr_insert);
3006
3007 const float gap_left = totr_insert.xmin - prev.runtime->draw_bounds.xmax;
3008 const float gap_right = next.runtime->draw_bounds.xmin - totr_insert.xmax;
3009 const float front_gap = right_alignment ? gap_right : gap_left;
3010 const float back_gap = right_alignment ? gap_left : gap_right;
3011 const float min_margin = U.node_margin * UI_SCALE_FAC;
3012
3013 const bool need_offset_side = (back_gap + front_gap) < min_margin * 2;
3014 const bool need_front_offset_insert = back_gap < min_margin;
3015 const bool need_back_offset_insert = !need_offset_side && front_gap < min_margin;
3016
3017 if (!(need_front_offset_insert || need_back_offset_insert || need_offset_side)) {
3018 return false;
3019 }
3020
3021 const float front_offset = (min_margin - back_gap) * float(need_front_offset_insert);
3022 const float back_offset = (front_gap - min_margin) * float(need_back_offset_insert);
3023 const float insert_node_offset = need_front_offset_insert ? front_offset : back_offset;
3024 const float side_offset = min_margin - front_gap + front_offset;
3025
3026 const float shift_sign = right_alignment ? 1.0f : -1.0f;
3027
3028 if (need_offset_side) {
3029 shift_nodes(ntree,
3030 right_alignment ? next : prev,
3031 right_alignment,
3032 shift_sign * side_offset / UI_SCALE_FAC);
3033 }
3034
3035 /* In case of the nodes cycle this node' offset might be overridden on propagation so set it
3036 * right after. */
3037 insert.runtime->anim_ofsx = shift_sign * insert_node_offset / UI_SCALE_FAC;
3038
3039 return true;
3040}
3041
3042#define NODE_INSOFS_ANIM_DURATION 0.25f
3043
3048{
3049 SpaceNode *snode = CTX_wm_space_node(C);
3050 NodeInsertOfsData *iofsd = static_cast<NodeInsertOfsData *>(op->customdata);
3051 bool redraw = false;
3052
3053 if (!snode || event->type != TIMER || iofsd == nullptr || iofsd->anim_timer != event->customdata)
3054 {
3055 return OPERATOR_PASS_THROUGH;
3056 }
3057
3058 const float duration = float(iofsd->anim_timer->time_duration);
3059
3060 /* handle animation - do this before possibly aborting due to duration, since
3061 * main thread might be so busy that node hasn't reached final position yet */
3062 for (bNode *node : snode->edittree->all_nodes()) {
3063 if (node->runtime->anim_ofsx) [[unlikely]] {
3064 const float prev_duration = duration - float(iofsd->anim_timer->time_delta);
3065 /* Clamp duration to not overshoot. */
3066 const float clamped_duration = math::min(duration, NODE_INSOFS_ANIM_DURATION);
3067 if (prev_duration < clamped_duration) {
3068 const float offset_step = node->runtime->anim_ofsx *
3070 clamped_duration, 0.0f, 1.0f, NODE_INSOFS_ANIM_DURATION) -
3072 prev_duration, 0.0f, 1.0f, NODE_INSOFS_ANIM_DURATION));
3073 node->location[0] += offset_step;
3074 redraw = true;
3075 }
3076 }
3077 }
3078 if (redraw) {
3080 }
3081
3082 /* end timer + free insert offset data */
3083 if (duration > NODE_INSOFS_ANIM_DURATION) {
3085
3086 for (bNode *node : snode->edittree->all_nodes()) {
3087 node->runtime->anim_ofsx = 0.0f;
3088 }
3089
3090 delete iofsd;
3091
3093 }
3094
3096}
3097
3098#undef NODE_INSOFS_ANIM_DURATION
3099
3101 wmOperator *op,
3102 const wmEvent * /*event*/)
3103{
3104 const SpaceNode *snode = CTX_wm_space_node(C);
3105 NodeInsertOfsData *iofsd = snode->runtime->iofsd.get();
3106 op->customdata = snode->runtime->iofsd.release();
3107
3108 if (!iofsd || !iofsd->insert) {
3109 return OPERATOR_CANCELLED;
3110 }
3111
3113
3114 iofsd->ntree = snode->edittree;
3115
3116 const bool offset_applied = node_link_insert_offset_ntree(
3117 iofsd, (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_RIGHT));
3118 if (!offset_applied) {
3119 delete iofsd;
3120 op->customdata = nullptr;
3121 return OPERATOR_CANCELLED;
3122 }
3123
3125
3126 /* add temp handler */
3128
3130}
3131
3133{
3134 /* identifiers */
3135 ot->name = "Insert Offset";
3136 ot->description = "Automatically offset nodes on insertion";
3137 ot->idname = "NODE_OT_insert_offset";
3138
3139 /* callbacks */
3143
3144 /* flags */
3146}
3147
3149
3150} // namespace ed::space_node
3151
3152} // namespace blender
#define SELECT
Definition BKE_mask.hh:19
#define NODE_FRAME
Definition BKE_node.hh:866
#define CMP_NODE_VIEWER
#define GEO_NODE_VIEWER
#define M_PI
#define IFACE_(msgid)
#define UI_SCALE_FAC
#define UI_INV_SCALE_FAC
#define NODE_EDGE_PAN_OUTSIDE_PAD
Definition ED_node_c.hh:34
#define NODE_EDGE_PAN_INSIDE_PAD
Definition ED_node_c.hh:33
#define NODE_EDGE_PAN_MAX_SPEED
Definition ED_node_c.hh:36
#define NODE_EDGE_PAN_DELAY
Definition ED_node_c.hh:37
#define NODE_EDGE_PAN_ZOOM_INFLUENCE
Definition ED_node_c.hh:38
#define NODE_EDGE_PAN_SPEED_RAMP
Definition ED_node_c.hh:35
#define REGION_DRAW_POST_PIXEL
Read Blender memory allocation and freeing.
#define RNA_BEGIN(sptr, itemptr, propname)
#define RNA_END
#define C
Definition RandGen.cpp:29
#define UI_PRECISION_FLOAT_MAX
#define UI_NO_ICON_OVERLAY_TEXT
#define NC_NODE
Definition WM_types.hh:407
#define ND_DISPLAY
Definition WM_types.hh:534
__forceinline const float4 insert(const float4 &a, const float b)
Definition binning.cpp:31
#define ELEM(...)
#define STREQ(a, b)
ccl_device_inline float arc_length(const float e2, const float gamma)
#define output
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
constexpr IndexRange()=default
Span< Value > lookup(const Key &key) const
void add_multiple(const Key &key, Span< Value > values)
void add(const Key &key, const Value &value)
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:614
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:175
constexpr int64_t first_index(const T &search_value) const
Definition BLI_span.hh:381
constexpr bool contains(const T &value) const
Definition BLI_span.hh:281
bool is_empty() const
Definition BLI_stack.hh:310
void push_multiple(Span< T > values)
Definition BLI_stack.hh:283
const Key * begin() const
int64_t size() const
const Key * end() const
bool contains(const Key &key) const
Span< Key > as_span() const
int64_t size() const
void append(const T &value)
const T & last(const int64_t n=0) const
bool is_empty() const
IndexRange index_range() const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void extend(Span< T > array)
Vector< bNodeSocket * > outputs
Vector< bNodeLink * > directly_linked_links
Vector< SocketDeclaration * > inputs
Vector< SocketDeclaration * > outputs
#define FLT_MAX
#define INT_MAX
#define storage(slot, qualifiers)
float distance(float, float) RET
bool node_is_parent_and_child(const bNode &parent, const bNode &child)
Definition node.cc:4115
void node_attach_node(bNodeTree &ntree, bNode &node, bNode &parent)
Definition node.cc:4883
bNode * node_get_active(bNodeTree &ntree)
Definition node.cc:5445
void node_remove_link(bNodeTree *ntree, bNodeLink &link)
Definition node.cc:4676
int node_count_socket_links(const bNodeTree &ntree, const bNodeSocket &sock)
Definition node.cc:5434
void node_internal_relink(bNodeTree &ntree, bNode &node)
Definition node.cc:4812
void node_free_node(bNodeTree *tree, bNode &node)
Definition node.cc:5073
void node_detach_node(bNodeTree &ntree, bNode &node)
Definition node.cc:4891
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
Definition node.cc:4638
void node_link_set_mute(bNodeTree &ntree, bNodeLink &link, const bool muted)
Definition node.cc:4693
void node_remove_socket_links(bNodeTree &ntree, bNodeSocket &sock)
Definition node.cc:4702
bool node_declaration_ensure(bNodeTree &ntree, bNode &node)
Definition node.cc:5578
void node_set_active(bNodeTree &ntree, bNode &node)
Definition node.cc:5484
int node_socket_link_limit(const bNodeSocket &sock)
Definition node.cc:5513
StringRefNull node_socket_label(const bNodeSocket &sock)
Definition node.cc:5758
void move_index(T *items, const int items_num, const int from_index, const int to_index)
static int view_socket(const bContext &C, SpaceNode &snode, bNodeTree &btree, bNode &bnode_to_view, bNodeSocket &bsocket_to_view)
static const bNode * find_overlapping_node(const bNodeTree &tree, const rctf &rect, const Span< const bNode * > ignored_nodes)
static int node_link_viewer(const bContext &C, bNode &bnode_to_view, bNodeSocket *bsocket_to_view)
static bNodeSocket * determine_socket_to_view(bNode &node_to_view)
static void finalize_viewer_link(const bContext &C, SpaceNode &snode, bNode &viewer_node, bNodeLink &viewer_link)
static std::string get_viewer_source_name(const bNodeSocket &socket)
static bNodeSocket * node_link_viewer_get_socket(bNodeTree &ntree, bNode &viewer_node, bNodeSocket &src_socket)
static void remove_links_to_unavailable_viewer_sockets(bNodeTree &btree, bNode &viewer_node)
static bool is_viewer_socket(const bNodeSocket &socket)
static bool is_viewer_node(const bNode &node)
static bool socket_can_be_viewed(const bNodeSocket &socket)
static bool is_viewer_socket_in_viewer(const bNodeSocket &socket)
static int ensure_geometry_nodes_viewer_has_non_geometry_socket(bNodeTree &ntree, bNode &viewer_node, const eNodeSocketDatatype socket_type)
static Vector< float2 > get_viewer_node_position_candidates(const float2 initial, const float step_distance, const float max_distance)
static int get_default_viewer_type(const bContext *C)
static void position_viewer_node(const bContext &C, bNodeTree &tree, bNode &viewer_node, const bNode &node_to_view)
static void ensure_geometry_nodes_viewer_starts_with_geometry_socket(bNodeTree &tree, bNode &viewer_node)
void NODE_OT_parent_set(wmOperatorType *ot)
static void join_group_inputs(bNodeTree &tree, VectorSet< bNode * > group_inputs, bNode *active_node)
static wmOperatorStatus node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void draw_draglink_tooltip_activate(const ARegion &region, bNodeLinkDrag &nldrag)
void node_deselect_all_input_sockets(bNodeTree &node_tree, bool deselect_nodes)
void node_insert_on_link_flags_set(SpaceNode &snode, const ARegion &region, bool attach_enabled, bool is_new_node)
static wmOperatorStatus mute_links_exec(bContext *C, wmOperator *op)
static void node_swap_links(bNodeLinkDrag &nldrag, bNodeTree &ntree)
void tree_draw_order_update(bNodeTree &ntree)
Definition node_draw.cc:265
static bool need_drag_link_tooltip(const bNodeTree &node_tree, const bNodeLinkDrag &nldrag)
static wmOperatorStatus node_join_in_frame_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void shift_nodes(bNodeTree &tree, const bNode &start_node, const bool left_to_right, const float value)
static bNodeLink create_drag_link(bNode &node, bNodeSocket &socket)
static void sort_multi_input_socket_links_with_drag(bNodeSocket &socket, bNodeLink &drag_link, const float2 &cursor)
bNode * add_static_node(const bContext &C, int type, const float2 &location)
Definition node_add.cc:107
static std::unique_ptr< bNodeLinkDrag > node_link_init(ARegion &region, SpaceNode &snode, const float2 cursor, const bool detach)
void invoke_node_link_drag_add_menu(bContext &C, bNode &node, bNodeSocket &socket, const float2 &cursor)
static wmOperatorStatus node_active_link_viewer_exec(bContext *C, wmOperator *)
void NODE_OT_detach(wmOperatorType *ot)
bool all_links_muted(const bNodeSocket &socket)
static bool can_attach_node_to_frame(const bNode &node, const bNode &frame)
bNodeSocket * node_find_indicated_socket(SpaceNode &snode, ARegion &region, const float2 &cursor, const eNodeSocketInOut in_out)
Definition node_edit.cc:793
static bool node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, const bool right_alignment)
static bNodeSocket * node_find_linkable_socket(const bNodeTree &ntree, const bNode *node, bNodeSocket *socket_to_match)
static wmOperatorStatus node_insert_offset_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus node_insert_offset_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus node_link_modal(bContext *C, wmOperator *op, const wmEvent *event)
void NODE_OT_insert_offset(wmOperatorType *ot)
Array< bNode * > tree_draw_order_calc_nodes_reversed(bNodeTree &ntree)
Definition node_draw.cc:286
static int get_main_socket_priority(const bNodeSocket *socket)
static bool snode_autoconnect_input(bContext &C, SpaceNode &snode, bNode *node_fr, bNodeSocket *sock_fr, bNode *node_to, bNodeSocket *sock_to, int replace)
static void expand_nodes_mask_in_direction(const Span< const bNode * > nodes, const bool left_to_right, MutableSpan< bool > mask_to_propagate)
static Vector< bNodeSocket * > get_available_sorted_inputs(const bNodeTree *ntree, const bNode *node, const bool only_unlinked)
float2 node_link_calculate_multi_input_position(const float2 &socket_position, const int index, const int total_inputs)
Definition node_edit.cc:763
void node_insert_on_frame_flag_set(SpaceNode &snode, ARegion &region, const int2 &cursor)
void NODE_OT_links_detach(wmOperatorType *ot)
static bool dragged_links_are_detached(const bNodeLinkDrag &nldrag)
void NODE_OT_links_cut(wmOperatorType *ot)
static void clear_picking_highlight(ListBaseT< bNodeLink > *links)
static void pick_input_link_by_link_intersect(const bContext &C, wmOperator &op, bNodeLinkDrag &nldrag, const float2 &cursor)
static wmOperatorStatus node_attach_invoke(bContext *C, wmOperator *, const wmEvent *event)
static void node_detach_recursive(bNodeTree &ntree, MutableSpan< NodeDetachstate > detach_states, bNode *node)
static void node_displace_existing_links(bNodeLinkDrag &nldrag, bNodeTree &ntree)
static void node_link_cancel(bContext *C, wmOperator *op)
static void pick_link(bNodeLinkDrag &nldrag, SpaceNode &snode, bNode *node, bNodeLink &link_to_pick)
static void displace_links(bNodeTree *ntree, const bNode *node, bNodeLink *inserted_link)
static wmOperatorStatus node_join_nodes_exec(bContext *C, wmOperator *op)
static wmOperatorStatus node_join_in_frame_exec(bContext *C, wmOperator *)
void NODE_OT_join(wmOperatorType *ot)
static void snode_autoconnect(bContext &C, SpaceNode &snode, const bool allow_multiple, const bool replace)
static bNode * node_find_frame_to_attach(ARegion &region, bNodeTree &ntree, const int2 mouse_xy)
static bool node_active_link_viewer_poll(bContext *C)
static wmOperatorStatus node_detach_exec(bContext *C, wmOperator *)
static bool socket_is_available(const bNodeTree *ntree, bNodeSocket *sock, const bool allow_used)
static wmOperatorStatus detach_links_exec(bContext *C, wmOperator *)
static Vector< bNode * > get_sorted_node_parents(const bNode &node)
static bool node_can_be_inserted_on_link(bNodeTree &tree, bNode &node, const bNodeLink &link)
void NODE_OT_attach(wmOperatorType *ot)
bool node_link_is_hidden_or_dimmed(const View2D &v2d, const bNodeLink &link)
Definition node_edit.cc:914
static void draw_draglink_tooltip_deactivate(const ARegion &region, bNodeLinkDrag &nldrag)
std::optional< float2 > link_path_intersection(const bNodeLink &link, const Span< float2 > path)
Definition node_add.cc:166
void NODE_OT_link_viewer(wmOperatorType *ot)
VectorSet< bNode * > get_selected_nodes(bNodeTree &node_tree)
void node_deselect_all_output_sockets(bNodeTree &node_tree, bool deselect_nodes)
float2 node_to_view(const float2 &co)
Definition node_draw.cc:318
void node_insert_on_link_flags_clear(bNodeTree &node_tree)
static void add_dragged_links_to_tree(bContext &C, bNodeLinkDrag &nldrag)
static void remove_unavailable_links(bNodeTree &tree, bNodeSocket &socket)
static wmOperatorStatus node_parent_set_exec(bContext *C, wmOperator *)
void NODE_OT_link_make(wmOperatorType *ot)
void node_link_bezier_points_evaluated(const bNodeLink &link, std::array< float2, NODE_LINK_RESOL+1 > &coords)
Definition drawnode.cc:1864
wmKeyMap * node_link_modal_keymap(wmKeyConfig *keyconf)
static wmOperatorStatus node_make_link_exec(bContext *C, wmOperator *op)
void NODE_OT_join_nodes(wmOperatorType *ot)
static bNodeSocket * best_socket_output(bNodeTree *ntree, bNode *node, bNodeSocket *sock_target, const bool allow_multiple)
bNode * find_common_parent_node(Span< bNode * > nodes)
static int node_socket_count_links(const bNodeTree &ntree, const bNodeSocket &socket)
void node_to_updated_rect(const bNode &node, rctf &r_rect)
Definition node_draw.cc:333
static bool should_create_drag_link_search_menu(const bNodeTree &node_tree, const bNodeLinkDrag &nldrag)
static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cursor)
void NODE_OT_link(wmOperatorType *ot)
void NODE_OT_links_mute(wmOperatorType *ot)
void node_insert_on_frame_flag_clear(SpaceNode &snode)
bNodeSocket * get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_out)
static void node_join_attach_recursive(bNodeTree &ntree, MutableSpan< NodeJoinState > join_states, bNode *node, bNode *frame, const VectorSet< bNode * > &selected_nodes)
void update_multi_input_indices_for_removed_links(bNode &node)
void node_insert_on_link_flags(Main &bmain, SpaceNode &snode, bool is_new_node)
static void node_remove_existing_links_if_needed(bNodeLinkDrag &nldrag, bNodeTree &ntree)
static wmOperatorStatus cut_links_exec(bContext *C, wmOperator *op)
static bNode * get_selected_node_for_insertion(bNodeTree &node_tree)
static void draw_draglink_tooltip(const bContext *, ARegion *, void *arg)
void activate_geometry_node(Main &bmain, SpaceNode &snode, bNode &node, std::optional< int > item_identifier=std::nullopt)
T min(const T &a, const T &b)
void set_item_name_and_make_unique(bNode &node, typename Accessor::ItemT &item, const char *value)
Accessor::ItemT * find_item_by_identifier(bNode &node, const StringRef identifier)
Accessor::ItemT * add_item_with_socket_type_and_name(bNodeTree &ntree, bNode &node, const eNodeSocketDatatype socket_type, const char *name, std::optional< int > dimensions=std::nullopt)
void update_node_declaration_and_sockets(bNodeTree &ntree, bNode &node, Main *bmain)
void get_color_4ubv(int colorid, unsigned char col[4])
void view2d_edge_pan_operator_properties_ex(wmOperatorType *ot, float inside_pad, float outside_pad, float speed_ramp, float max_speed, float delay, float zoom_influence)
void icon_draw_ex(float x, float y, int icon_id, float aspect, float alpha, float desaturate, const uchar mono_color[4], bool mono_border, const IconTextOverlay *text_overlay, const bool inverted=false, float scale=1.0f)
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst) ATTR_NONNULL()
Definition view2d.cc:1657
BMesh Iterators.
MINLINE float min_ff(float a, float b)
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:135
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ NODE_GEO_VIEWER_ITEM_FLAG_AUTO_REMOVE
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
ScrArea * CTX_wm_area(const bContext *C)
uint padding(uint offset, uint alignment)
bool ED_node_is_geometry(const SpaceNode *snode)
Definition node_edit.cc:150
void BKE_ntree_update_tag_link_added(bNodeTree *ntree, bNodeLink *link)
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
void BKE_ntree_update_tag_link_changed(bNodeTree *ntree)
PropertyRNA * RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
MINLINE void copy_v2_v2(float r[2], const float a[2])
bool ED_operator_node_editable(bContext *C)
float BLI_easing_cubic_ease_in_out(float time, float begin, float change, float duration)
Definition easing.cc:110
wmWindow * CTX_wm_window(const bContext *C)
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
MINLINE int max_ii(int a, int b)
void BKE_ntree_update_tag_link_removed(bNodeTree *ntree)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:307
void WM_gesture_lines_cancel(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_lines_modal(bContext *C, wmOperator *op, const wmEvent *event)
void ED_preview_kill_jobs(wmWindowManager *wm, Main *bmain)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
wmOperatorStatus WM_gesture_lines_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void * ED_region_draw_cb_activate(ARegionType *art, void(*draw)(const bContext *, ARegion *, void *), void *customdata, int type)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
unsigned char uchar
Definition BKE_text.h:58
bool ED_region_draw_cb_exit(ARegionType *art, void *handle)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
bool BLI_rctf_inside_rctf(const rctf *rct_a, const rctf *rct_b)
Definition rct.cc:195
SpaceNode * CTX_wm_space_node(const bContext *C)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
@ WM_CURSOR_MUTE
Definition wm_cursors.hh:62
@ WM_CURSOR_KNIFE
Definition wm_cursors.hh:33
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
Main * CTX_data_main(const bContext *C)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
@ NODE_VIEWER_SHORTCUT_NONE
bool BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest)
void BKE_ntree_update_tag_active_output_changed(bNodeTree *ntree)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
@ KM_RELEASE
Definition WM_types.hh:325
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
@ SNODE_INSERTOFS_DIR_RIGHT
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_DEPENDS_ON_CURSOR
Definition WM_types.hh:228
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
@ NODE_LINK_INSERT_TARGET
@ NODE_LINK_INSERT_TARGET_INVALID
@ NODE_LINK_TEMP_HIGHLIGHT
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2])
void BLI_rctf_pad(struct rctf *rect, float pad_x, float pad_y)
Definition rct.cc:651
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
#define NODE_LINK_RESOL
#define NODE_INSOFS_ANIM_DURATION
#define ceilf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
struct bNodeTree * edittree
eSpaceNode_InsertOffsetDir insert_ofs_dir
struct bNodeTree * nodetree
ed::space_node::SpaceNode_Runtime * runtime
bke::bNodeSocketType * typeinfo
eNodeSocketDatatype type
bke::bNodeSocketRuntime * runtime
eNodeSocketInOut in_out
struct bNodeSocket * next
ListBaseT< bNodeLink > links
bke::bNodeTreeType * typeinfo
eNodeTree_Type type
struct bNode * parent
ListBaseT< bNodeSocket > outputs
bke::bNodeRuntime * runtime
ListBaseT< bNodeSocket > inputs
bke::bNodeType * typeinfo
struct bNode * prev
struct bNode * next
struct ARegionType * type
eNodeSocketDatatype type
Definition BKE_node.hh:198
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:566
bool(*) insert_link(NodeInsertLinkParams &params)
Definition BKE_node.hh:364
std::optional< int > frame_identifier_to_highlight
std::unique_ptr< bNodeLinkDrag > linkdrag
std::unique_ptr< NodeInsertOfsData > iofsd
static bool supports_socket_type(const eNodeSocketDatatype socket_type, const int ntree_type)
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports