Blender V5.3
node_group.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 <cstdlib>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_node_types.h"
14
15#include "BLI_math_vector_c.hh"
17#include "BLI_string.hh"
18#include "BLI_string_utf8.hh"
19#include "BLI_vector.hh"
20
21#include "BLT_translation.hh"
22
23#include "BKE_action.hh"
24#include "BKE_animsys.hh"
25#include "BKE_context.hh"
26#include "BKE_lib_id.hh"
27#include "BKE_library.hh"
28#include "BKE_main.hh"
30#include "BKE_node_runtime.hh"
32#include "BKE_report.hh"
33
34#include "ANIM_action.hh"
35
37
38#include "ED_node.hh"
39#include "ED_node_preview.hh"
40#include "ED_render.hh"
41#include "ED_screen.hh"
42
43#include "RNA_access.hh"
44#include "RNA_define.hh"
45#include "RNA_prototypes.hh"
46
47#include "WM_api.hh"
48#include "WM_types.hh"
49
50#include "UI_resources.hh"
51
52#include "NOD_common.hh"
53#include "NOD_composite.hh"
54#include "NOD_geometry.hh"
56#include "NOD_shader.h"
57#include "NOD_socket.hh"
58#include "NOD_texture.h"
59
60#include "node_intern.hh" /* own include */
61
63
64/* -------------------------------------------------------------------- */
67
69{
72
73 /* Group operators only defined for standard node tree types.
74 * Disabled otherwise to allow python-nodes define their own operators
75 * with same key-map. */
76 if (STR_ELEM(snode->tree_idname,
77 "ShaderNodeTree",
78 "CompositorNodeTree",
79 "TextureNodeTree",
80 "GeometryNodeTree"))
81 {
82 return true;
83 }
84 }
85 return false;
86}
87
89{
92
93 /* Group operators only defined for standard node tree types.
94 * Disabled otherwise to allow python-nodes define their own operators
95 * with same key-map. */
96 if (ED_node_is_shader(snode) || ED_node_is_compositor(snode) || ED_node_is_texture(snode) ||
98 {
99 return true;
100 }
101 }
102 return false;
103}
104
106{
107 SpaceNode *snode = CTX_wm_space_node(C);
108 return snode->tree_idname;
109}
110
112{
113 SpaceNode *snode = CTX_wm_space_node(C);
114
115 if (ED_node_is_shader(snode)) {
117 }
118 if (ED_node_is_compositor(snode)) {
120 }
121 if (ED_node_is_texture(snode)) {
123 }
124 if (ED_node_is_geometry(snode)) {
126 }
127
128 return ""_ustr;
129}
130
131static bNode *node_group_get_active(bContext *C, const UString node_idname)
132{
133 SpaceNode *snode = CTX_wm_space_node(C);
135
136 if (node && node->idname == node_idname) {
137 return node;
138 }
139 return nullptr;
140}
141
143
144/* -------------------------------------------------------------------- */
147
149{
150 SpaceNode *snode = CTX_wm_space_node(C);
151 ARegion *region = CTX_wm_region(C);
152 const UString node_idname = node_group_idname(C);
153 const bool exit = RNA_boolean_get(op->ptr, "exit");
154
156
157 bNode *gnode = node_group_get_active(C, node_idname);
158
159 if (gnode && !exit) {
160 bNodeTree *ngroup = id_cast<bNodeTree *>(gnode->id);
161
162 if (ngroup) {
163 ED_node_tree_push(region, snode, ngroup, gnode);
164 }
165 }
166 else {
167 ED_node_tree_pop(region, snode);
168 }
169
172
173 return OPERATOR_FINISHED;
174}
175
177{
178 /* identifiers */
179 ot->name = "Edit Group";
180 ot->description = "Edit node group";
181 ot->idname = "NODE_OT_group_edit";
182
183 /* API callbacks. */
186
187 /* flags */
189
190 PropertyRNA *prop = RNA_def_boolean(ot->srna, "exit", false, "Exit", "");
192}
193
195
196/* -------------------------------------------------------------------- */
199
201 wmOperator * /*op*/,
202 const wmEvent *event)
203{
204 SpaceNode &snode = *CTX_wm_space_node(C);
205 ARegion &region = *CTX_wm_region(C);
206
207 /* Don't interfere when the mouse is interacting with some button. See #147282. */
208 if (ISMOUSE_BUTTON(event->type) && ui::but_find_mouse_over(&region, event)) {
210 }
211
212 float2 cursor;
213 ui::view2d_region_to_view(&region.v2d, event->mval[0], event->mval[1], &cursor.x, &cursor.y);
214 bNode *node = node_under_mouse_get(snode, cursor);
215
216 if (!node || node->is_frame()) {
217 ED_node_tree_pop(&region, &snode);
218 return OPERATOR_FINISHED;
219 }
220 if (!node->is_group()) {
222 }
223 if (node->is_custom_group()) {
225 }
226 bNodeTree *group = id_cast<bNodeTree *>(node->id);
227 if (!group || ID_MISSING(group)) {
229 }
230 ED_node_tree_push(&region, &snode, group, node);
231 return OPERATOR_FINISHED;
232}
233
235{
236 ot->name = "Enter/Exit Group";
237 ot->description = "Enter or exit node group based on cursor location";
238 ot->idname = "NODE_OT_group_enter_exit";
239
242
243 ot->flag = OPTYPE_REGISTER;
244}
245
247
248/* -------------------------------------------------------------------- */
251
255static void node_group_ungroup(bContext &C, bNodeTree &ntree, bNode &group_node)
256{
257 Main &bmain = *CTX_data_main(&C);
259 params.skip_hidden = false;
260
261 const bNodeTree &ngroup = *reinterpret_cast<const bNodeTree *>(group_node.id);
262 const NodeTreeInterfaceMapping io_mapping = map_group_node_interface(params, ntree, group_node);
263
264 const NodeSetCopy copied_nodes = NodeSetCopy::from_predicate(
265 bmain,
266 ngroup,
267 [&](const bNode &node) {
268 if (node.is_group_input() || node.is_group_output()) {
269 return false;
270 }
271 return true;
272 },
273 ntree);
275 C, ngroup, copied_nodes, io_mapping, &group_node);
276
277 /* Center nodes on the bounds of the original group node. */
278 if (const std::optional<Bounds<float2>> bounds = node_location_bounds(Span{&group_node})) {
279 const float2 center = bounds->center();
280 for (bNode *node : copied_nodes.node_map().values()) {
281 node->location[0] += center[0];
282 node->location[1] += center[1];
283 }
284 for (bNode *node : proxy_nodes.values()) {
285 node->location[0] += center[0];
286 node->location[1] += center[1];
287 }
288 }
289 /* Attach to the same parent as the group node. */
290 if (group_node.parent) {
291 for (bNode *node : copied_nodes.node_map().values()) {
292 node->parent = group_node.parent;
293 }
294 for (bNode *node : proxy_nodes.values()) {
295 node->parent = group_node.parent;
296 }
297 }
298
299 update_nested_node_refs_after_ungroup(ntree, group_node, copied_nodes);
300
301 /* Delete the original group instance. */
302 bke::node_remove_node(&bmain, ntree, group_node, true);
303
304 /* Select ungrouped nodes. */
305 for (bNode *node : copied_nodes.node_map().values()) {
307 }
308 for (bNode *node : proxy_nodes.values()) {
310 }
311}
312
314{
315 Main *bmain = CTX_data_main(C);
316 SpaceNode *snode = CTX_wm_space_node(C);
317 const UString node_idname = node_group_idname(C);
318
320
321 Vector<bNode *> nodes_to_ungroup;
322 for (bNode *node : snode->edittree->all_nodes()) {
323 if (node->is_selected()) {
324 if (node->idname == node_idname) {
325 if (node->id != nullptr) {
326 nodes_to_ungroup.append(node);
327 }
328 }
329 }
330 }
331 if (nodes_to_ungroup.is_empty()) {
332 return OPERATOR_CANCELLED;
333 }
334
336 for (bNode *node : nodes_to_ungroup) {
337 node_group_ungroup(*C, *snode->edittree, *node);
338 }
341 return OPERATOR_FINISHED;
342}
343
345{
346 /* identifiers */
347 ot->name = "Ungroup";
348 ot->description = "Ungroup selected nodes";
349 ot->idname = "NODE_OT_group_ungroup";
350
351 /* API callbacks. */
354
355 /* flags */
357}
358
360
361/* -------------------------------------------------------------------- */
364
369 Main &bmain, bNodeTree &ntree, bNodeTree &ngroup, const float2 &offset, const bool make_copy)
370{
371 node_deselect_all(ntree);
372
373 /* Add selected nodes into the ntree, ignoring interface nodes. */
374 VectorSet<bNode *> nodes_to_move = get_selected_nodes(ngroup);
375 nodes_to_move.remove_if(
376 [](const bNode *node) { return node->is_group_input() || node->is_group_output(); });
377
379 bmain, ngroup, nodes_to_move.as_span(), ntree);
380 for (bNode *node : copied_nodes.node_map().values()) {
381 node->location[0] += offset[0];
382 node->location[1] += offset[1];
383 }
384
385 if (!make_copy) {
386 for (bNode *node : nodes_to_move) {
387 bke::node_remove_node(&bmain, ngroup, *node, true);
388 }
389 }
390
391 return true;
392}
393
398
399/* Operator Property */
401 {NODE_GS_COPY, "COPY", 0, "Copy", "Copy to parent node tree, keep group intact"},
402 {NODE_GS_MOVE, "MOVE", 0, "Move", "Move to parent node tree, remove from group"},
403 {0, nullptr, 0, nullptr, nullptr},
404};
405
407{
408 Main *bmain = CTX_data_main(C);
409 ARegion *region = CTX_wm_region(C);
410 SpaceNode *snode = CTX_wm_space_node(C);
411 int type = RNA_enum_get(op->ptr, "type");
412
414
415 /* are we inside of a group? */
416 bNodeTree *ngroup = snode->edittree;
417 bNodeTree *nparent = ED_node_tree_get(snode, 1);
418 if (!nparent) {
419 BKE_report(op->reports, RPT_WARNING, "Not inside node group");
420 return OPERATOR_CANCELLED;
421 }
422 /* get node tree offset */
423 const float2 offset = space_node_group_offset(*snode);
424
425 switch (type) {
426 case NODE_GS_COPY:
427 if (!node_group_separate_selected(*bmain, *nparent, *ngroup, offset, true)) {
428 BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes");
429 return OPERATOR_CANCELLED;
430 }
431 break;
432 case NODE_GS_MOVE:
433 if (!node_group_separate_selected(*bmain, *nparent, *ngroup, offset, false)) {
434 BKE_report(op->reports, RPT_WARNING, "Cannot separate nodes");
435 return OPERATOR_CANCELLED;
436 }
437 break;
438 }
439
440 /* switch to parent tree */
441 ED_node_tree_pop(region, snode);
442
444
445 return OPERATOR_FINISHED;
446}
447
449 wmOperator * /*op*/,
450 const wmEvent * /*event*/)
451{
453 C, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Separate"), ICON_NONE);
454 ui::Layout *layout = popup_menu_layout(pup);
455
457 PointerRNA op_ptr = layout->op("NODE_OT_group_separate", IFACE_("Copy"), ICON_NONE);
458 RNA_enum_set(&op_ptr, "type", NODE_GS_COPY);
459 op_ptr = layout->op("NODE_OT_group_separate", IFACE_("Move"), ICON_NONE);
460 RNA_enum_set(&op_ptr, "type", NODE_GS_MOVE);
461
462 popup_menu_end(C, pup);
463
464 return OPERATOR_INTERFACE;
465}
466
468{
469 /* identifiers */
470 ot->name = "Separate";
471 ot->description = "Separate selected nodes from the node group";
472 ot->idname = "NODE_OT_group_separate";
473
474 /* API callbacks. */
478
479 /* flags */
481
482 RNA_def_enum(ot->srna, "type", node_group_separate_types, NODE_GS_COPY, "Type", "");
483}
484
486
487/* -------------------------------------------------------------------- */
490
492{
493 VectorSet<bNode *> nodes_to_group = get_selected_nodes(node_tree);
494 nodes_to_group.remove_if(
495 [](bNode *node) { return node->is_group_input() || node->is_group_output(); });
496 nodes_to_group.remove(group_node);
497 return nodes_to_group;
498}
499
501 const VectorSet<bNode *> &nodes_to_group,
502 const StringRef ntree_idname,
503 ReportList &reports)
504{
505 if (nodes_to_group.is_empty()) {
506 return false;
507 }
508 /* make a local pseudo node tree to pass to the node poll functions */
509 bNodeTree *ngroup = bke::node_tree_add_tree(nullptr, "Pseudo Node Group", ntree_idname);
510 BLI_SCOPED_DEFER([&]() {
512 MEM_delete(ngroup);
513 });
514
515 /* check poll functions for selected nodes */
516 for (bNode *node : nodes_to_group) {
517 const char *disabled_hint = nullptr;
518 if (node->typeinfo->poll_instance &&
519 !node->typeinfo->poll_instance(node, ngroup, &disabled_hint))
520 {
521 if (disabled_hint) {
522 BKE_reportf(&reports,
524 "Cannot add node '%s' in a group:\n %s",
525 node->name,
526 disabled_hint);
527 }
528 else {
529 BKE_reportf(&reports, RPT_WARNING, "Cannot add node '%s' in a group", node->name);
530 }
531 return false;
532 }
533 }
534
535 /* check if all connections are OK, no unselected node has both
536 * inputs and outputs to a selection */
537 ntree.ensure_topology_cache();
538 for (bNode *node : ntree.all_nodes()) {
539 if (nodes_to_group.contains(node)) {
540 continue;
541 }
542 auto sockets_connected_to_group = [&](const Span<bNodeSocket *> sockets) {
543 for (const bNodeSocket *socket : sockets) {
544 for (const bNodeSocket *other_socket : socket->directly_linked_sockets()) {
545 if (nodes_to_group.contains(const_cast<bNode *>(&other_socket->owner_node()))) {
546 return true;
547 }
548 }
549 }
550 return false;
551 };
552 if (sockets_connected_to_group(node->input_sockets()) &&
553 sockets_connected_to_group(node->output_sockets()))
554 {
555 return false;
556 }
557 }
558 /* Check if zone pairs are fully selected.
559 * Zone input or output nodes can only be grouped together with the paired node. */
560 for (const bke::bNodeZoneType *zone_type : bke::all_zone_types()) {
561 for (bNode *input_node : ntree.nodes_by_type(zone_type->input_idname)) {
562 if (bNode *output_node = zone_type->get_corresponding_output(ntree, *input_node)) {
563 const bool input_selected = nodes_to_group.contains(input_node);
564 const bool output_selected = nodes_to_group.contains(output_node);
565 if (input_selected && !output_selected) {
566 BKE_reportf(&reports,
568 "Cannot add zone input node '%s' to a group without its paired output '%s'",
569 input_node->name,
570 output_node->name);
571 return false;
572 }
573 if (output_selected && !input_selected) {
574 BKE_reportf(&reports,
576 "Cannot add zone output node '%s' to a group without its paired input '%s'",
577 output_node->name,
578 input_node->name);
579 return false;
580 }
581 }
582 }
583 }
584
585 return true;
586}
587
589 bNodeTree &ntree,
590 bNode *gnode,
591 const Span<bNode *> nodes)
592{
593 Main &bmain = *CTX_data_main(&C);
594 bNodeTree &group = *reinterpret_cast<bNodeTree *>(gnode->id);
595
597 /* TODO This is inconsistent with the single-node wrapper case, which does expose hidden
598 * sockets and only hides them on the group node instance. */
599 params.skip_hidden = true;
600 /* Expose only connected sockets if there is more than one node. */
601 params.skip_unconnected = (nodes.size() > 1);
602 /* Share external connections if a socket has multiple links. */
603 params.use_unique_input = false;
604 params.use_unique_output = false;
606 params, ntree, nodes, group);
607
608 /* Copy nodes into the group. */
609 node_deselect_all(group);
610 const NodeSetCopy copied_nodes = NodeSetCopy::from_nodes(bmain, ntree, nodes, group);
611 /* Connect exposed sockets to group input/output nodes. */
612 connect_copied_nodes_to_interface(C, copied_nodes, io_mapping);
613
616
617 /* Connect the group node to external sockets. */
618 connect_group_node_to_external_sockets(*gnode, io_mapping);
619
620 /* Remove original nodes from the tree, everything has been copied to the group. */
621 for (bNode *node : nodes) {
622 bke::node_remove_node(&bmain, ntree, *node, true);
623 }
624
626}
627
629 bNodeTree &ntree,
630 const Span<bNode *> nodes_to_group,
631 const UString ntype,
632 const StringRef ntreetype)
633{
634 Main *bmain = CTX_data_main(&C);
635
636 /* New node-tree. */
637 bNodeTree *ngroup = bke::node_tree_add_tree(bmain, "NodeGroup", ntreetype);
638 BKE_id_move_to_same_lib(*bmain, ngroup->id, ntree.id);
639
640 /* make group node */
641 bNode *gnode = bke::node_add_node(&C, ntree, ntype);
642 gnode->id = id_cast<ID *>(ngroup);
643
644 if (const std::optional<Bounds<float2>> bounds = node_location_bounds(nodes_to_group)) {
645 gnode->location[0] = nearest_node_grid_coord(bounds->center()[0]);
646 gnode->location[1] = nearest_node_grid_coord(bounds->center()[1]);
647 }
648 if (bNode *parent = ed::space_node::find_common_parent_node(nodes_to_group)) {
649 gnode->parent = parent;
650 }
651
652 node_group_make_insert_selected(C, ntree, gnode, nodes_to_group);
653
654 return gnode;
655}
656
658 bNodeTree &ntree,
659 bNode &src_node,
660 const UString node_idname)
661{
662 Main &bmain = *CTX_data_main(&C);
663
664 bNodeTree *wrapper_group = bke::node_tree_add_tree(
665 &bmain, bke::node_label(ntree, src_node), ntree.idname);
666 wrapper_group->color_tag = int(bke::node_color_tag(src_node));
667 if (!src_node.is_reroute()) {
668 wrapper_group->default_group_node_width = src_node.width;
669 }
670
672 /* Hidden sockets are exposed but hidden on the group node instance. */
673 params.skip_hidden = false;
674 /* Expose all sockets even if unconnected. */
675 params.skip_unconnected = false;
677 params, src_node, *wrapper_group);
678
679 const NodeSetCopy copied_nodes = NodeSetCopy::from_nodes(
680 bmain, ntree, {&src_node}, *wrapper_group);
681 connect_copied_nodes_to_interface(C, copied_nodes, io_mapping);
682
683 BKE_main_ensure_invariants(bmain, wrapper_group->id);
684
685 /* Create a group node. */
686 bNode *gnode = bke::node_add_node(&C, ntree, node_idname);
687 STRNCPY_UTF8(gnode->name, BKE_id_name(wrapper_group->id));
688 bke::node_unique_name(ntree, *gnode);
689
690 /* Assign the newly created wrapper group to the new group node. */
691 gnode->id = &wrapper_group->id;
692
693 /* Position node exactly where the old node was. */
694 gnode->parent = src_node.parent;
695
696 if (!src_node.is_reroute()) {
697 gnode->width = std::max<float>(src_node.width, bke::NodeWidth::GroupMin);
698 }
699 copy_v2_v2(gnode->location, src_node.location);
700
702 ntree.ensure_topology_cache();
703
704 connect_group_node_to_external_sockets(*gnode, io_mapping);
705
706 /* Remove the old node because it has been replaced. Use the name of the removed node for the
707 * new group node. This also keeps animation data working. */
708 std::string old_node_name = src_node.name;
709 bke::node_remove_node(&bmain, ntree, src_node, true, false);
710 STRNCPY(gnode->name, old_node_name.c_str());
711
712 /* Clear already created nested node refs to create new stable ones below. */
713 MEM_SAFE_DELETE(wrapper_group->nested_node_refs);
714 wrapper_group->nested_node_refs_num = 0;
716
719 return gnode;
720}
721
723{
724 ARegion &region = *CTX_wm_region(C);
725 SpaceNode &snode = *CTX_wm_space_node(C);
726 bNodeTree &ntree = *snode.edittree;
727 const StringRef ntree_idname = group_ntree_idname(C);
728 const UString node_idname = node_group_idname(C);
729 Main *bmain = CTX_data_main(C);
730
732
733 VectorSet<bNode *> nodes_to_group = get_nodes_to_group(ntree, nullptr);
734 if (!node_group_make_test_selected(ntree, nodes_to_group, ntree_idname, *op->reports)) {
735 return OPERATOR_CANCELLED;
736 }
737
738 bNode *gnode = nullptr;
739 if (nodes_to_group.size() == 1 && nodes_to_group[0]->declaration()) {
740 gnode = node_group_make_from_node_declaration(*C, ntree, *nodes_to_group[0], node_idname);
741 }
742 else {
744 *C, ntree, std::move(nodes_to_group), node_idname, ntree_idname);
745 }
746
747 if (gnode) {
748 bNodeTree *ngroup = id_cast<bNodeTree *>(gnode->id);
749
750 bke::node_set_active(ntree, *gnode);
751 if (ngroup) {
752 ED_node_tree_push(&region, &snode, ngroup, gnode);
753 }
754 }
755
758 /* We broke relations in node tree, need to rebuild them in the graphs. */
760
761 return OPERATOR_FINISHED;
762}
763
765{
766 /* identifiers */
767 ot->name = "Make Group";
768 ot->description = "Make group from selected nodes";
769 ot->idname = "NODE_OT_group_make";
770
771 /* API callbacks. */
774
775 /* flags */
777}
778
780
781/* -------------------------------------------------------------------- */
784
786{
787 SpaceNode *snode = CTX_wm_space_node(C);
788 ARegion *region = CTX_wm_region(C);
789 bNodeTree *ntree = snode->edittree;
790 const UString node_idname = node_group_idname(C);
791
793
794 bNode *gnode = node_group_get_active(C, node_idname);
795 if (!gnode || !gnode->id) {
796 return OPERATOR_CANCELLED;
797 }
798
799 bNodeTree *ngroup = reinterpret_cast<bNodeTree *>(gnode->id);
800 VectorSet<bNode *> nodes_to_group = get_nodes_to_group(*ntree, gnode);
801
802 /* Make sure that there won't be a node group containing itself afterwards. */
803 for (const bNode *group : nodes_to_group) {
804 if (!group->is_group() || group->id == nullptr) {
805 continue;
806 }
807 if (bke::node_tree_contains_tree(*reinterpret_cast<bNodeTree *>(group->id), *ngroup)) {
809 op->reports, RPT_WARNING, "Cannot insert group '%s' in '%s'", group->name, gnode->name);
810 return OPERATOR_CANCELLED;
811 }
812 }
813
814 if (!node_group_make_test_selected(*ntree, nodes_to_group, ngroup->idname, *op->reports)) {
815 return OPERATOR_CANCELLED;
816 }
817
818 node_group_make_insert_selected(*C, *ntree, gnode, nodes_to_group);
819
820 bke::node_set_active(*ntree, *gnode);
821 ED_node_tree_push(region, snode, ngroup, gnode);
822
823 return OPERATOR_FINISHED;
824}
825
827{
828 /* identifiers */
829 ot->name = "Group Insert";
830 ot->description = "Insert selected nodes into a node group";
831 ot->idname = "NODE_OT_group_insert";
832
833 /* API callbacks. */
836
837 /* flags */
839}
840
842
843/* -------------------------------------------------------------------- */
846
848{
849 SpaceNode *snode = CTX_wm_space_node(C);
850 if (!snode) {
851 return false;
852 }
853 bNodeTree *ntree = snode->edittree;
854 if (!ntree) {
855 return false;
856 }
857 if (!ID_IS_EDITABLE(ntree)) {
858 return false;
859 }
860 if (snode->nodetree == snode->edittree) {
861 /* Top-level node group does not have enough context to set the node width. */
862 CTX_wm_operator_poll_msg_set(C, "There is no parent group node in this context");
863 return false;
864 }
865 return true;
866}
867
869{
870 SpaceNode *snode = CTX_wm_space_node(C);
871 bNodeTree *ntree = snode->edittree;
872
873 bNodeTreePath *last_path_item = snode->treepath.last();
874 bNodeTreePath *parent_path_item = last_path_item->prev;
875 if (!parent_path_item) {
876 return OPERATOR_CANCELLED;
877 }
878 bNodeTree *parent_ntree = parent_path_item->nodetree;
879 if (!parent_ntree) {
880 return OPERATOR_CANCELLED;
881 }
882 parent_ntree->ensure_topology_cache();
883 bNode *parent_node = bke::node_find_node_by_name(*parent_ntree, last_path_item->node_name);
884 if (!parent_node) {
885 return OPERATOR_CANCELLED;
886 }
887 ntree->default_group_node_width = parent_node->width;
889 return OPERATOR_CANCELLED;
890}
891
893{
894 /* identifiers */
895 ot->name = "Set Default Group Node Width";
896 ot->description = "Set the width based on the parent group node in the current context";
897 ot->idname = "NODE_OT_default_group_width_set";
898
899 /* API callbacks. */
902
903 /* flags */
905}
906
908
909} // namespace blender::ed::space_node
Functions and classes to work with Actions.
Blender kernel action and pose functionality.
#define BLI_SCOPED_DEFER(function_to_defer)
#define STR_ELEM(...)
#define STRNCPY_UTF8(dst, src)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_MISSING(_id)
Definition DNA_ID.h:695
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_NODE
Definition WM_types.hh:407
#define NC_SCENE
Definition WM_types.hh:391
#define NA_ADDED
Definition WM_types.hh:636
#define ND_NODES
Definition WM_types.hh:455
#define NA_EDITED
Definition WM_types.hh:634
#define ND_NODE_GIZMO
Definition WM_types.hh:559
bool remove(const Key &key)
int64_t size() const
bool contains(const Key &key) const
int64_t remove_if(Predicate &&predicate)
Span< Key > as_span() const
void append(const T &value)
bool is_empty() const
static NodeSetCopy from_predicate(Main &bmain, const bNodeTree &src_tree, FunctionRef< bool(const bNode &node)> node_predicate, bNodeTree &dst_tree)
static NodeSetCopy from_nodes(Main &bmain, const bNodeTree &src_tree, const Span< const bNode * > src_nodes, bNodeTree &dst_tree)
const Map< const bNode *, bNode * > & node_map() const
bNode * node_find_node_by_name(bNodeTree &ntree, StringRefNull name)
Definition node.cc:4047
NodeColorTag node_color_tag(const bNode &node)
Definition node.cc:5788
std::string node_label(const bNodeTree &ntree, const bNode &node)
Definition node.cc:5732
void node_tree_free_tree(bNodeTree &ntree)
Definition node.cc:5224
void node_remove_node(Main *bmain, bNodeTree &ntree, bNode &node, bool do_id_user, bool remove_animation=true)
Definition node.cc:5155
bNode * node_get_active(bNodeTree &ntree)
Definition node.cc:5445
bNode * node_add_node(const bContext *C, bNodeTree &ntree, UString idname, std::optional< int > unique_identifier=std::nullopt)
Definition node.cc:4260
Span< const bNodeZoneType * > all_zone_types()
bool node_set_selected(bNode &node, bool select)
Definition node.cc:5455
bool node_tree_contains_tree(const bNodeTree &tree_to_search_in, const bNodeTree &tree_to_search_for)
Definition node.cc:5423
bNodeTree * node_tree_add_tree(Main *bmain, StringRef name, StringRef idname)
Definition node.cc:4992
void node_set_active(bNodeTree &ntree, bNode &node)
Definition node.cc:5484
void node_unique_name(bNodeTree &ntree, bNode &node)
Definition node.cc:4238
static bool node_default_group_width_set_poll(bContext *C)
static bool node_group_operator_active_poll(bContext *C)
Definition node_group.cc:68
static bNode * node_group_make_from_node_declaration(bContext &C, bNodeTree &ntree, bNode &src_node, const UString node_idname)
static VectorSet< bNode * > get_nodes_to_group(bNodeTree &node_tree, bNode *group_node)
static wmOperatorStatus node_group_insert_exec(bContext *C, wmOperator *op)
static void node_group_make_insert_selected(const bContext &C, bNodeTree &ntree, bNode *gnode, const Span< bNode * > nodes)
static wmOperatorStatus node_default_group_width_set_exec(bContext *C, wmOperator *)
static void node_group_ungroup(bContext &C, bNodeTree &ntree, bNode &group_node)
bool node_deselect_all(bNodeTree &node_tree)
static wmOperatorStatus node_group_separate_invoke(bContext *C, wmOperator *, const wmEvent *)
static bool node_group_make_test_selected(bNodeTree &ntree, const VectorSet< bNode * > &nodes_to_group, const StringRef ntree_idname, ReportList &reports)
void NODE_OT_group_make(wmOperatorType *ot)
static const EnumPropertyItem node_group_separate_types[]
GroupInputOutputNodes connect_copied_nodes_to_interface(const bContext &C, const NodeSetCopy &copied_nodes, const NodeTreeInterfaceMapping &io_mapping)
void NODE_OT_group_insert(wmOperatorType *ot)
static bool node_group_separate_selected(Main &bmain, bNodeTree &ntree, bNodeTree &ngroup, const float2 &offset, const bool make_copy)
Map< std::string, bNode * > InterfaceProxyNodes
NodeTreeInterfaceMapping build_node_set_interface(const NodeSetInterfaceParams &params, const bNodeTree &src_tree, const Span< bNode * > src_nodes, bNodeTree &dst_tree)
static wmOperatorStatus node_group_ungroup_exec(bContext *C, wmOperator *)
NodeTreeInterfaceMapping build_node_declaration_interface(const NodeSetInterfaceParams &params, const bNode &src_node, bNodeTree &dst_tree)
static wmOperatorStatus node_group_separate_exec(bContext *C, wmOperator *op)
bNode * node_under_mouse_get(const SpaceNode &snode, const float2 mouse)
static wmOperatorStatus node_group_edit_exec(bContext *C, wmOperator *op)
UString node_group_idname(const bContext *C)
void update_nested_node_refs_after_ungroup(bNodeTree &dst_tree, const bNode &group_node, const NodeSetCopy &node_set_copy)
VectorSet< bNode * > get_selected_nodes(bNodeTree &node_tree)
static bNode * node_group_make_from_nodes(const bContext &C, bNodeTree &ntree, const Span< bNode * > nodes_to_group, const UString ntype, const StringRef ntreetype)
static bool node_group_operator_editable(bContext *C)
Definition node_group.cc:88
float2 space_node_group_offset(const SpaceNode &snode)
static wmOperatorStatus node_group_make_exec(bContext *C, wmOperator *op)
void connect_group_node_to_external_sockets(bNode &group_node, const NodeTreeInterfaceMapping &io_mapping)
void NODE_OT_group_edit(wmOperatorType *ot)
void NODE_OT_group_separate(wmOperatorType *ot)
bNode * find_common_parent_node(Span< bNode * > nodes)
NodeTreeInterfaceMapping map_group_node_interface(const NodeSetInterfaceParams &params, const bNodeTree &tree, const bNode &group_node)
void NODE_OT_group_enter_exit(wmOperatorType *ot)
void NODE_OT_default_group_width_set(wmOperatorType *ot)
std::optional< Bounds< float2 > > node_location_bounds(Span< const bNode * > nodes)
static wmOperatorStatus node_group_enter_exit_invoke(bContext *C, wmOperator *, const wmEvent *event)
void NODE_OT_group_ungroup(wmOperatorType *ot)
void update_nested_node_refs_after_moving_nodes_into_group(bNodeTree &src_tree, const bNode &group_node, const NodeSetCopy &node_set_copy)
static StringRef group_ntree_idname(bContext *C)
float nearest_node_grid_coord(float co)
Definition node_edit.cc:516
InterfaceProxyNodes connect_copied_nodes_to_external_sockets(bContext &C, const bNodeTree &src_tree, const NodeSetCopy &copied_nodes, const NodeTreeInterfaceMapping &io_mapping, const bNode *group_node)
static bNode * node_group_get_active(bContext *C, const UString node_idname)
Button * but_find_mouse_over(const ARegion *region, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
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
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:135
bool ED_operator_node_active(bContext *C)
void ED_node_tree_push(ARegion *region, SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
bool ED_node_is_geometry(const SpaceNode *snode)
Definition node_edit.cc:150
@ RPT_WARNING
Definition BKE_report.hh:40
void ED_node_tree_pop(ARegion *region, SpaceNode *snode)
MINLINE void copy_v2_v2(float r[2], const float a[2])
bke::bNodeTreeType * ntreeType_Geometry
bke::bNodeTreeType * ntreeType_Composite
bool ED_node_is_shader(SpaceNode *snode)
Definition node_edit.cc:140
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
bool ED_operator_node_editable(bContext *C)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
const char * BKE_id_name(const ID &id)
struct bke::bNodeTreeType * ntreeType_Texture
void ED_preview_kill_jobs(wmWindowManager *wm, Main *bmain)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
VecBase< float, 2 > float2
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
bool ED_node_is_texture(SpaceNode *snode)
Definition node_edit.cc:145
wmWindowManager * CTX_wm_manager(const bContext *C)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
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)
struct bke::bNodeTreeType * ntreeType_Shader
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void WM_event_handling_break(const bContext &C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
void BKE_ntree_update_tag_node_property(bNodeTree *ntree, bNode *node)
Main * CTX_data_main(const bContext *C)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
void BKE_id_move_to_same_lib(Main &bmain, ID &id, const ID &owner_id)
Definition lib_id.cc:953
void DEG_relations_tag_update(Main *bmain)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
bNodeTree * ED_node_tree_get(SpaceNode *snode, int level)
ARegion * CTX_wm_region(const bContext *C)
struct bNodeTree * edittree
struct bNodeTree * nodetree
ListBaseT< bNodeTreePath > treepath
struct bNodeTree * nodetree
struct bNodeTreePath * prev
bNestedNodeRef * nested_node_refs
struct bNode * parent
static constexpr int GroupMin
Definition BKE_node.hh:256
void operator_context_set(wm::OpCallContext opcontext)
PointerRNA op(wmOperatorType *ot, std::optional< StringRef > name, int icon, wm::OpCallContext context, eUI_Item_Flag flag)
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
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
struct ReportList * reports
#define ISMOUSE_BUTTON(event_type)