Blender V4.5
space_node.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "BLI_listbase.h"
12#include "BLI_math_vector.h"
13#include "BLI_stack.hh"
14#include "BLI_string.h"
15
16#include "DNA_ID.h"
18#include "DNA_material_types.h"
19#include "DNA_modifier_types.h"
20#include "DNA_node_types.h"
21#include "DNA_object_types.h"
22#include "DNA_screen_types.h"
23#include "DNA_space_types.h"
25
26#include "MEM_guardedalloc.h"
27
28#include "BKE_asset.hh"
31#include "BKE_context.hh"
32#include "BKE_gpencil_legacy.h"
33#include "BKE_idprop.hh"
34#include "BKE_lib_id.hh"
35#include "BKE_lib_query.hh"
36#include "BKE_lib_remap.hh"
38#include "BKE_node_runtime.hh"
40#include "BKE_screen.hh"
41
42#include "BLT_translation.hh"
43
44#include "ED_image.hh"
45#include "ED_node.hh"
46#include "ED_node_preview.hh"
47#include "ED_screen.hh"
48#include "ED_space_api.hh"
49
50#include "UI_view2d.hh"
51
52#include "DEG_depsgraph.hh"
54
55#include "BLO_read_write.hh"
56
57#include "RNA_access.hh"
58#include "RNA_define.hh"
59#include "RNA_enum_types.hh"
60#include "RNA_prototypes.hh"
61
62#include "WM_api.hh"
63#include "WM_types.hh"
64
67
68#include "io_utils.hh"
69
70#include "node_intern.hh" /* own include */
71
72using blender::float2;
73
74/* ******************** tree path ********************* */
75
76void ED_node_tree_start(ARegion *region, SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from)
77{
79 MEM_freeN(path);
80 }
82
83 if (ntree) {
84 bNodeTreePath *path = MEM_callocN<bNodeTreePath>("node tree path");
85 path->nodetree = ntree;
87
88 /* Set initial view center from node tree. */
89 copy_v2_v2(path->view_center, ntree->view_center);
90 if (region) {
91 UI_view2d_center_set(&region->v2d, ntree->view_center[0], ntree->view_center[1]);
92 }
93
94 if (id) {
95 STRNCPY(path->display_name, id->name + 2);
96 }
97
98 BLI_addtail(&snode->treepath, path);
99
100 if (ntree->type != NTREE_GEOMETRY) {
101 /* This can probably be removed for all node tree types. It mainly exists because it was not
102 * possible to store id references in custom properties. Also see #36024. I don't want to
103 * remove it for all tree types in bcon3 though. */
104 id_us_ensure_real(&ntree->id);
105 }
106 }
107
108 /* update current tree */
109 snode->nodetree = snode->edittree = ntree;
110 snode->id = id;
111 snode->from = from;
112
114
116}
117
118void ED_node_tree_push(ARegion *region, SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
119{
120 bNodeTreePath *path = MEM_callocN<bNodeTreePath>("node tree path");
121 bNodeTreePath *prev_path = (bNodeTreePath *)snode->treepath.last;
122 path->nodetree = ntree;
123 if (gnode) {
124 if (prev_path) {
126 prev_path->parent_key, prev_path->nodetree, gnode);
127 }
128 else {
130 }
131
132 STRNCPY(path->node_name, gnode->name);
133 STRNCPY(path->display_name, gnode->name);
134 }
135 else {
137 }
138
139 /* Set initial view center from node tree. */
140 copy_v2_v2(path->view_center, ntree->view_center);
141 if (region) {
142 UI_view2d_center_set(&region->v2d, ntree->view_center[0], ntree->view_center[1]);
143 }
144
145 BLI_addtail(&snode->treepath, path);
146
147 id_us_ensure_real(&ntree->id);
148
149 /* update current tree */
150 snode->edittree = ntree;
151
153
155}
156
157void ED_node_tree_pop(ARegion *region, SpaceNode *snode)
158{
159 bNodeTreePath *path = (bNodeTreePath *)snode->treepath.last;
160
161 /* don't remove root */
162 if (path == snode->treepath.first) {
163 return;
164 }
165
166 BLI_remlink(&snode->treepath, path);
167 MEM_freeN(path);
168
169 /* update current tree */
170 path = (bNodeTreePath *)snode->treepath.last;
171 snode->edittree = path->nodetree;
172
173 /* Set view center from node tree path. */
174 if (region) {
175 UI_view2d_center_set(&region->v2d, path->view_center[0], path->view_center[1]);
176 }
177
179
181}
182
184{
185 return BLI_listbase_count(&snode->treepath);
186}
187
189{
190 bNodeTreePath *path;
191 int i;
192 for (path = (bNodeTreePath *)snode->treepath.last, i = 0; path; path = path->prev, i++) {
193 if (i == level) {
194 return path->nodetree;
195 }
196 }
197 return nullptr;
198}
199
201{
202 int length = 0;
203 int i = 0;
204 LISTBASE_FOREACH_INDEX (bNodeTreePath *, path, &snode->treepath, i) {
205 length += strlen(path->display_name);
206 if (i > 0) {
207 length += 1; /* for separator char */
208 }
209 }
210 return length;
211}
212
213void ED_node_tree_path_get(SpaceNode *snode, char *value)
214{
215 int i = 0;
216#ifndef NDEBUG
217 const char *value_orig = value;
218#endif
219 /* Note that the caller ensures there is enough space available. */
220 LISTBASE_FOREACH_INDEX (bNodeTreePath *, path, &snode->treepath, i) {
221 const int len = strlen(path->display_name);
222 if (i != 0) {
223 *value++ = '/';
224 }
225 memcpy(value, path->display_name, len);
226 value += len;
227 }
228 *value = '\0';
229 BLI_assert(ptrdiff_t(ED_node_tree_path_length(snode)) == ptrdiff_t(value - value_orig));
230}
231
233{
234 bNodeTreePath *path = (bNodeTreePath *)snode->treepath.last;
235 if (snode->nodetree && path) {
236 /* A change in active viewer may result in the change of the output node used by the
237 * compositor, so we need to get notified about such changes. */
238 if (snode->nodetree->active_viewer_key.value != path->parent_key.value &&
239 snode->nodetree->type == NTREE_COMPOSIT)
240 {
243 }
244
245 snode->nodetree->active_viewer_key = path->parent_key;
246 }
247}
248
249void ED_node_cursor_location_get(const SpaceNode *snode, float value[2])
250{
251 copy_v2_v2(value, snode->runtime->cursor);
252}
253
254void ED_node_cursor_location_set(SpaceNode *snode, const float value[2])
255{
256 copy_v2_v2(snode->runtime->cursor, value);
257}
258
259namespace blender::ed::space_node {
260
262{
263 const bNodeTreePath *path = (bNodeTreePath *)snode.treepath.last;
264
265 if (path && path->prev) {
266 return float2(path->view_center) - float2(path->prev->view_center);
267 }
268 return float2(0);
269}
270
271std::optional<nodes::FoundNestedNodeID> find_nested_node_id_in_root(const SpaceNode &snode,
272 const bNode &query_node)
273{
274 BLI_assert(snode.edittree->runtime->nodes_by_id.contains(const_cast<bNode *>(&query_node)));
275 bke::ComputeContextCache compute_context_cache;
276 const ComputeContext *compute_context = compute_context_for_edittree_node(
277 snode, compute_context_cache, query_node);
278 if (!compute_context) {
279 return {};
280 }
281 return find_nested_node_id_in_root(*snode.nodetree, compute_context, query_node.identifier);
282}
283
284std::optional<nodes::FoundNestedNodeID> find_nested_node_id_in_root(
285 const bNodeTree &root_tree, const ComputeContext *compute_context, const int node_id)
286{
288 Vector<int> node_ids;
289 for (const ComputeContext *context = compute_context; context != nullptr;
290 context = context->parent())
291 {
292 if (const auto *node_context = dynamic_cast<const bke::GroupNodeComputeContext *>(context)) {
293 node_ids.append(node_context->node_id());
294 }
295 else if (dynamic_cast<const bke::RepeatZoneComputeContext *>(context) != nullptr) {
296 found.is_in_loop = true;
297 }
298 else if (dynamic_cast<const bke::SimulationZoneComputeContext *>(context) != nullptr) {
299 found.is_in_simulation = true;
300 }
301 else if (dynamic_cast<const bke::ForeachGeometryElementZoneComputeContext *>(context) !=
302 nullptr)
303 {
304 found.is_in_loop = true;
305 }
306 else if (dynamic_cast<const bke::EvaluateClosureComputeContext *>(context) != nullptr) {
307 found.is_in_closure = true;
308 }
309 }
310 std::reverse(node_ids.begin(), node_ids.end());
311 node_ids.append(node_id);
312 const bNestedNodeRef *nested_node_ref = root_tree.nested_node_ref_from_node_id_path(node_ids);
313 if (nested_node_ref == nullptr) {
314 return std::nullopt;
315 }
316 found.id = nested_node_ref->id;
317 return found;
318}
319
320std::optional<ObjectAndModifier> get_modifier_for_node_editor(const SpaceNode &snode)
321{
323 return std::nullopt;
324 }
325 if (snode.id == nullptr) {
326 return std::nullopt;
327 }
328 if (GS(snode.id->name) != ID_OB) {
329 return std::nullopt;
330 }
331 const Object *object = reinterpret_cast<Object *>(snode.id);
332 const NodesModifierData *used_modifier = nullptr;
333 if (snode.flag & SNODE_PIN) {
334 LISTBASE_FOREACH (const ModifierData *, md, &object->modifiers) {
335 if (md->type == eModifierType_Nodes) {
336 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
337 /* Would be good to store the name of the pinned modifier in the node editor. */
338 if (nmd->node_group == snode.nodetree) {
339 used_modifier = nmd;
340 break;
341 }
342 }
343 }
344 }
345 else {
346 LISTBASE_FOREACH (const ModifierData *, md, &object->modifiers) {
347 if (md->type == eModifierType_Nodes) {
348 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
349 if (nmd->node_group == snode.nodetree) {
350 if (md->flag & eModifierFlag_Active) {
351 used_modifier = nmd;
352 break;
353 }
354 }
355 }
356 }
357 }
358 if (used_modifier == nullptr) {
359 return std::nullopt;
360 }
361 return ObjectAndModifier{object, used_modifier};
362}
363
365 const Object &object,
366 const NodesModifierData &nmd)
367{
368 const std::optional<ObjectAndModifier> object_and_modifier = get_modifier_for_node_editor(snode);
369 if (!object_and_modifier) {
370 return false;
371 }
372 const Object *object_orig = DEG_is_original(&object) ? &object : DEG_get_original(&object);
373 if (object_and_modifier->object != object_orig) {
374 return false;
375 }
376 return object_and_modifier->nmd->modifier.persistent_uid == nmd.modifier.persistent_uid;
377}
378
380 bke::ComputeContextCache &compute_context_cache,
381 const ComputeContext *parent_compute_context)
382{
383 const bNode *output_node_ptr = zone.output_node();
384 if (!output_node_ptr) {
385 return nullptr;
386 }
387 const bNode &output_node = *output_node_ptr;
388 switch (output_node.type_legacy) {
390 return &compute_context_cache.for_simulation_zone(parent_compute_context, output_node);
391 }
393 const auto &storage = *static_cast<const NodeGeometryRepeatOutput *>(output_node.storage);
394 return &compute_context_cache.for_repeat_zone(
395 parent_compute_context, output_node, storage.inspection_index);
396 }
398 const auto &storage = *static_cast<const NodeGeometryForeachGeometryElementOutput *>(
399 output_node.storage);
400 return &compute_context_cache.for_foreach_geometry_element_zone(
401 parent_compute_context, output_node, storage.inspection_index);
402 }
404 nodes::ClosureSourceLocation source_location{};
405 const bNodeTree &tree = output_node.owner_tree();
406 source_location.tree = &tree;
407 source_location.closure_output_node_id = output_node.identifier;
408 source_location.compute_context_hash = parent_compute_context ?
409 parent_compute_context->hash() :
411 return compute_context_for_closure_evaluation(parent_compute_context,
412 output_node.output_socket(0),
413 compute_context_cache,
414 source_location);
415 }
416 }
417 return nullptr;
418}
419
422 bke::ComputeContextCache &compute_context_cache,
423 const ComputeContext *parent_compute_context)
424{
425 const ComputeContext *current = parent_compute_context;
426 for (const bke::bNodeTreeZone *zone : zones) {
427 current = compute_context_for_zone(*zone, compute_context_cache, current);
428 if (!current) {
429 return nullptr;
430 }
431 }
432 return current;
433}
434
435static std::optional<const ComputeContext *> compute_context_for_tree_path(
436 const SpaceNode &snode,
437 bke::ComputeContextCache &compute_context_cache,
438 const ComputeContext *parent_compute_context)
439{
440 const ComputeContext *current = parent_compute_context;
442 LISTBASE_FOREACH (const bNodeTreePath *, item, &snode.treepath) {
443 tree_path.append(item);
444 }
445 if (tree_path.is_empty()) {
446 return current;
447 }
448
449 for (const int i : tree_path.index_range().drop_back(1)) {
450 bNodeTree *tree = tree_path[i]->nodetree;
451 const char *group_node_name = tree_path[i + 1]->node_name;
452 const bNode *group_node = blender::bke::node_find_node_by_name(*tree, group_node_name);
453 if (group_node == nullptr) {
454 return std::nullopt;
455 }
456 const blender::bke::bNodeTreeZones *tree_zones = tree->zones();
457 if (tree_zones == nullptr) {
458 return std::nullopt;
459 }
462 tree_zones->get_zone_by_node(group_node->identifier));
463 current = compute_context_for_zones(zone_stack, compute_context_cache, current);
464 if (!current) {
465 return std::nullopt;
466 }
467 current = &compute_context_cache.for_group_node(current, group_node->identifier, tree);
468 }
469 return current;
470}
471
473 const ComputeContext *closure_socket_context,
474 const bNodeSocket &closure_socket,
475 bke::ComputeContextCache &compute_context_cache,
476 const std::optional<nodes::ClosureSourceLocation> &source_location)
477{
478 using BundlePath = Vector<nodes::SocketInterfaceKey, 0>;
479
480 struct SocketToCheck {
482 BundlePath bundle_path;
483 };
484
485 Stack<SocketToCheck> sockets_to_check;
486 Set<nodes::SocketInContext> added_sockets;
487
488 auto add_if_new = [&](const nodes::SocketInContext &socket, BundlePath bundle_path) {
489 if (added_sockets.add(socket)) {
490 sockets_to_check.push({socket, std::move(bundle_path)});
491 }
492 };
493
494 const nodes::SocketInContext start_socket{closure_socket_context, &closure_socket};
495 add_if_new(start_socket, {});
496
497 while (!sockets_to_check.is_empty()) {
498 const SocketToCheck socket_to_check = sockets_to_check.pop();
499 const nodes::SocketInContext socket = socket_to_check.socket;
500 const BundlePath &bundle_path = socket_to_check.bundle_path;
501 const nodes::NodeInContext &node = socket.owner_node();
502 if (socket->is_input()) {
503 if (node->is_muted()) {
504 for (const bNodeLink &link : node->internal_links()) {
505 if (link.fromsock == socket.socket) {
506 add_if_new({socket.context, link.tosock}, bundle_path);
507 }
508 }
509 continue;
510 }
511 if (node->is_type("GeometryNodeEvaluateClosure")) {
512 return &compute_context_cache.for_evaluate_closure(
513 socket.context, node->identifier, &node->owner_tree(), source_location);
514 }
515 if (node->is_group()) {
516 if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node->id)) {
517 group->ensure_topology_cache();
518 const ComputeContext &group_compute_context = compute_context_cache.for_group_node(
519 socket.context, node->identifier, &node->owner_tree());
520 for (const bNode *input_node : group->group_input_nodes()) {
521 const bNodeSocket &group_input_socket = input_node->output_socket(socket->index());
522 if (group_input_socket.is_directly_linked()) {
523 add_if_new({&group_compute_context, &group_input_socket}, bundle_path);
524 }
525 }
526 }
527 continue;
528 }
529 if (node->is_group_output()) {
530 if (const auto *group_context = dynamic_cast<const bke::GroupNodeComputeContext *>(
531 socket.context))
532 {
533 const bNodeTree *caller_group = group_context->tree();
534 const bNode *caller_group_node = group_context->node();
535 if (caller_group && caller_group_node) {
536 caller_group->ensure_topology_cache();
537 const bNodeSocket &output_socket = caller_group_node->output_socket(socket->index());
538 add_if_new({group_context->parent(), &output_socket}, bundle_path);
539 }
540 }
541 continue;
542 }
543 if (node->is_type("GeometryNodeCombineBundle")) {
544 const auto &storage = *static_cast<const NodeGeometryCombineBundle *>(node->storage);
545 BundlePath new_bundle_path = bundle_path;
546 new_bundle_path.append(nodes::SocketInterfaceKey{storage.items[socket->index()].name});
547 add_if_new(node.output_socket(0), std::move(new_bundle_path));
548 continue;
549 }
550 if (node->is_type("GeometryNodeSeparateBundle")) {
551 if (bundle_path.is_empty()) {
552 continue;
553 }
554 const nodes::SocketInterfaceKey &last_key = bundle_path.last();
555 const auto &storage = *static_cast<const NodeGeometrySeparateBundle *>(node->storage);
556 for (const int output_i : IndexRange(storage.items_num)) {
557 const nodes::SocketInterfaceKey key{storage.items[output_i].name};
558 if (last_key.matches(key)) {
559 add_if_new(node.output_socket(output_i), bundle_path.as_span().drop_back(1));
560 }
561 }
562 continue;
563 }
564 }
565 else {
566 const bke::bNodeTreeZones *zones = node->owner_tree().zones();
567 if (!zones) {
568 continue;
569 }
570 const bke::bNodeTreeZone *from_zone = zones->get_zone_by_socket(*socket.socket);
571 for (const bNodeLink *link : socket->directly_linked_links()) {
572 if (!link->is_used()) {
573 continue;
574 }
575 bNodeSocket *to_socket = link->tosock;
576 const bke::bNodeTreeZone *to_zone = zones->get_zone_by_socket(*to_socket);
577 if (!zones->link_between_zones_is_allowed(from_zone, to_zone)) {
578 continue;
579 }
580 const Vector<const bke::bNodeTreeZone *> zones_to_enter = zones->get_zones_to_enter(
581 from_zone, to_zone);
582 const ComputeContext *compute_context = compute_context_for_zones(
583 zones_to_enter, compute_context_cache, socket.context);
584 if (!compute_context) {
585 continue;
586 }
587 add_if_new({compute_context, to_socket}, bundle_path);
588 }
589 }
590 }
591 return nullptr;
592}
593
595 const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
596{
599 std::optional<ed::space_node::ObjectAndModifier> object_and_modifier =
601 if (!object_and_modifier) {
602 return nullptr;
603 }
604 return &compute_context_cache.for_modifier(nullptr, *object_and_modifier->nmd);
605 }
606 case SNODE_GEOMETRY_TOOL: {
607 return &compute_context_cache.for_operator(nullptr);
608 }
609 }
610 return nullptr;
611}
612
614 const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
615{
616 if (!snode.edittree) {
617 return nullptr;
618 }
619 if (snode.edittree->type != NTREE_GEOMETRY) {
620 return nullptr;
621 }
622 const ComputeContext *root_context = get_node_editor_root_compute_context(snode,
623 compute_context_cache);
624 if (!root_context) {
625 return nullptr;
626 }
627 const ComputeContext *edittree_context =
628 compute_context_for_tree_path(snode, compute_context_cache, root_context).value_or(nullptr);
629 return edittree_context;
630}
631
633 const SpaceNode &snode,
634 bke::ComputeContextCache &compute_context_cache,
635 const bNodeSocket &socket)
636{
637 const ComputeContext *context = compute_context_for_edittree(snode, compute_context_cache);
638 if (!context) {
639 return nullptr;
640 }
641 const bke::bNodeTreeZones *zones = snode.edittree->zones();
642 if (!zones) {
643 return nullptr;
644 }
645 const bke::bNodeTreeZone *zone = zones->get_zone_by_socket(socket);
647 return compute_context_for_zones(zone_stack, compute_context_cache, context);
648}
649
651 const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache, const bNode &node)
652{
653 const ComputeContext *context = compute_context_for_edittree(snode, compute_context_cache);
654 if (!context) {
655 return nullptr;
656 }
657 const bke::bNodeTreeZones *zones = snode.edittree->zones();
658 if (!zones) {
659 return nullptr;
660 }
661 const bke::bNodeTreeZone *zone = zones->get_zone_by_node(node.identifier);
663 return compute_context_for_zones(zone_stack, compute_context_cache, context);
664}
665
666/* ******************** default callbacks for node space ***************** */
667
668static SpaceLink *node_create(const ScrArea * /*area*/, const Scene * /*scene*/)
669{
670 SpaceNode *snode = MEM_callocN<SpaceNode>(__func__);
671 snode->spacetype = SPACE_NODE;
672
676
677 /* backdrop */
678 snode->zoom = 1.0f;
679
680 /* select the first tree type for valid type */
681 for (const bke::bNodeTreeType *treetype : bke::node_tree_types_get()) {
682 STRNCPY(snode->tree_idname, treetype->idname.c_str());
683 break;
684 }
685
686 /* header */
687 ARegion *region = BKE_area_region_new();
688
689 BLI_addtail(&snode->regionbase, region);
690 region->regiontype = RGN_TYPE_HEADER;
692
693 /* buttons/list view */
694 region = BKE_area_region_new();
695
696 BLI_addtail(&snode->regionbase, region);
697 region->regiontype = RGN_TYPE_UI;
698 region->alignment = RGN_ALIGN_RIGHT;
699
700 /* toolbar */
701 region = BKE_area_region_new();
702
703 BLI_addtail(&snode->regionbase, region);
704 region->regiontype = RGN_TYPE_TOOLS;
705 region->alignment = RGN_ALIGN_LEFT;
706
707 region->flag = RGN_FLAG_HIDDEN;
708
709 /* main region */
710 region = BKE_area_region_new();
711
712 BLI_addtail(&snode->regionbase, region);
713 region->regiontype = RGN_TYPE_WINDOW;
714
715 region->v2d.tot.xmin = -12.8f * U.widget_unit;
716 region->v2d.tot.ymin = -12.8f * U.widget_unit;
717 region->v2d.tot.xmax = 38.4f * U.widget_unit;
718 region->v2d.tot.ymax = 38.4f * U.widget_unit;
719
720 region->v2d.cur = region->v2d.tot;
721
722 region->v2d.min[0] = 1.0f;
723 region->v2d.min[1] = 1.0f;
724
725 region->v2d.max[0] = 32000.0f;
726 region->v2d.max[1] = 32000.0f;
727
728 region->v2d.minzoom = 0.05f;
729 region->v2d.maxzoom = 2.31f;
730
733 region->v2d.keeptot = 0;
734
735 return (SpaceLink *)snode;
736}
737
738static void node_free(SpaceLink *sl)
739{
740 SpaceNode *snode = (SpaceNode *)sl;
741 BLI_freelistN(&snode->treepath);
742 MEM_delete(snode->runtime);
743}
744
745/* spacetype; init callback */
746static void node_init(wmWindowManager * /*wm*/, ScrArea *area)
747{
748 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
749
750 if (snode->runtime == nullptr) {
751 snode->runtime = MEM_new<SpaceNode_Runtime>(__func__);
752 }
753}
754
756{
757 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
758
759 if (snode->runtime) {
760 free_previews(*wm, *snode);
761 }
762}
763
764static bool any_node_uses_id(const bNodeTree *ntree, const ID *id)
765{
766 if (ELEM(nullptr, ntree, id)) {
767 return false;
768 }
769 for (const bNode *node : ntree->all_nodes()) {
770 if (node->id == id) {
771 return true;
772 }
773 }
774 return false;
775}
776
786{
787 if (ED_node_is_compositor(snode)) {
788 snode->runtime->recalc_regular_compositing = true;
789 }
790
792}
793
795{
796 ScrArea *area = params->area;
797 const wmNotifier *wmn = params->notifier;
798
799 /* NOTE: #ED_area_tag_refresh will re-execute compositor. */
800 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
801 /* shaderfrom is only used for new shading nodes, otherwise all shaders are from objects */
802 short shader_type = snode->shaderfrom;
803
804 /* preview renders */
805 switch (wmn->category) {
806 case NC_SCENE:
807 switch (wmn->data) {
808 case ND_NODES: {
809 node_area_tag_tree_recalc(snode, area);
810 break;
811 }
812 case ND_FRAME:
813 node_area_tag_tree_recalc(snode, area);
814 break;
815 case ND_COMPO_RESULT: {
816 ED_area_tag_redraw(area);
817 /* Backdrop image offset is calculated during compositing so gizmos need to be updated
818 * afterwards. */
820 WM_gizmomap_tag_refresh(region->runtime->gizmo_map);
821 break;
822 }
823 }
824 break;
825
826 /* future: add ID checks? */
827 case NC_MATERIAL:
828 if (ED_node_is_shader(snode)) {
829 if (wmn->data == ND_SHADING) {
830 node_area_tag_tree_recalc(snode, area);
831 }
832 else if (wmn->data == ND_SHADING_DRAW) {
833 node_area_tag_tree_recalc(snode, area);
834 }
835 else if (wmn->data == ND_SHADING_LINKS) {
836 node_area_tag_tree_recalc(snode, area);
837 }
838 }
839 break;
840 case NC_TEXTURE:
841 if (ED_node_is_shader(snode) || ED_node_is_texture(snode)) {
842 if (wmn->data == ND_NODES) {
843 node_area_tag_tree_recalc(snode, area);
844 }
845 }
846 break;
847 case NC_WORLD:
848 if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_WORLD) {
849 node_area_tag_tree_recalc(snode, area);
850 }
851 break;
852 case NC_OBJECT:
853 if (ED_node_is_shader(snode)) {
854 if (wmn->data == ND_OB_SHADING) {
855 node_area_tag_tree_recalc(snode, area);
856 }
857 }
858 else if (ED_node_is_geometry(snode)) {
859 /* Rather strict check: only redraw when the reference matches the current editor's ID. */
860 if (wmn->data == ND_MODIFIER) {
861 if (wmn->reference == snode->id || snode->id == nullptr) {
862 node_area_tag_tree_recalc(snode, area);
863 }
864 }
865 }
866 break;
867 case NC_SPACE:
868 if (wmn->data == ND_SPACE_NODE) {
869 node_area_tag_tree_recalc(snode, area);
870 }
871 else if (wmn->data == ND_SPACE_NODE_VIEW) {
872 ED_area_tag_redraw(area);
873 }
874 break;
875 case NC_NODE:
876 if (wmn->action == NA_EDITED) {
877 if (ELEM(wmn->reference, snode->nodetree, snode->id, nullptr) || snode->id == nullptr) {
878 node_area_tag_tree_recalc(snode, area);
879 }
880 }
881 else if (wmn->action == NA_SELECTED) {
882 ED_area_tag_redraw(area);
883 }
884 break;
885 case NC_SCREEN:
886 switch (wmn->data) {
887 case ND_ANIMPLAY:
888 node_area_tag_tree_recalc(snode, area);
889 break;
890 }
891 break;
892 case NC_MASK:
893 if (wmn->action == NA_EDITED) {
894 if (snode->nodetree && snode->nodetree->type == NTREE_COMPOSIT) {
895 node_area_tag_tree_recalc(snode, area);
896 }
897 }
898 break;
899
900 case NC_IMAGE:
901 if (wmn->action == NA_EDITED) {
902 if (ED_node_is_compositor(snode)) {
903 /* Without this check drawing on an image could become very slow when the compositor is
904 * open. */
905 if (any_node_uses_id(snode->nodetree, (ID *)wmn->reference)) {
906 node_area_tag_tree_recalc(snode, area);
907 }
908 }
909 }
910 break;
911
912 case NC_MOVIECLIP:
913 if (wmn->action == NA_EDITED) {
914 if (ED_node_is_compositor(snode)) {
915 if (any_node_uses_id(snode->nodetree, (ID *)wmn->reference)) {
916 node_area_tag_tree_recalc(snode, area);
917 }
918 }
919 }
920 break;
921
922 case NC_LINESTYLE:
923 if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_LINESTYLE) {
924 node_area_tag_tree_recalc(snode, area);
925 }
926 break;
927 case NC_WM:
928 if (wmn->data == ND_UNDO) {
929 node_area_tag_tree_recalc(snode, area);
930 }
931 break;
932 case NC_GPENCIL:
933 if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
934 ED_area_tag_redraw(area);
935 }
936 break;
937 }
938}
939
940static void node_area_refresh(const bContext *C, ScrArea *area)
941{
942 /* default now: refresh node is starting preview */
943 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
944
946
947 if (snode->nodetree) {
948 if (snode->nodetree->type == NTREE_COMPOSIT) {
949 Scene *scene = (Scene *)snode->id;
950 if (scene->use_nodes) {
952 snode->runtime->recalc_regular_compositing = false;
953 ED_node_composite_job(C, snode->nodetree, scene);
954 }
955 }
956 }
957 }
958}
959
961{
962 SpaceNode *snode = (SpaceNode *)sl;
963 SpaceNode *snoden = (SpaceNode *)MEM_dupallocN(snode);
964
965 BLI_duplicatelist(&snoden->treepath, &snode->treepath);
966
967 snoden->runtime = MEM_new<SpaceNode_Runtime>(__func__);
968
969 /* NOTE: no need to set node tree user counts,
970 * the editor only keeps at least 1 (id_us_ensure_real),
971 * which is already done by the original SpaceNode.
972 */
973
974 return (SpaceLink *)snoden;
975}
976
977/* add handlers, stuff you only do once or on area/region changes */
979{
980 wmKeyMap *keymap;
981
982 ED_region_panels_init(wm, region);
983
984 keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, RGN_TYPE_WINDOW);
985 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
986}
987
988static void node_buttons_region_draw(const bContext *C, ARegion *region)
989{
990 ED_region_panels(C, region);
991}
992
993/* add handlers, stuff you only do once or on area/region changes */
995{
996 wmKeyMap *keymap;
997
998 ED_region_panels_init(wm, region);
999
1000 keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, RGN_TYPE_WINDOW);
1001 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
1002}
1003
1004static void node_toolbar_region_draw(const bContext *C, ARegion *region)
1005{
1006 ED_region_panels(C, region);
1007}
1008
1009static void node_cursor(wmWindow *win, ScrArea *area, ARegion *region)
1010{
1011 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
1012
1013 /* convert mouse coordinates to v2d space */
1015 win->eventstate->xy[0] - region->winrct.xmin,
1016 win->eventstate->xy[1] - region->winrct.ymin,
1017 &snode->runtime->cursor[0],
1018 &snode->runtime->cursor[1]);
1019
1020 /* here snode->runtime->cursor is used to detect the node edge for sizing */
1021 node_set_cursor(*win, *region, *snode, snode->runtime->cursor);
1022
1023 /* XXX snode->runtime->cursor is in placing new nodes space */
1024 snode->runtime->cursor[0] /= UI_SCALE_FAC;
1025 snode->runtime->cursor[1] /= UI_SCALE_FAC;
1026}
1027
1028/* Initialize main region, setting handlers. */
1030{
1031 wmKeyMap *keymap;
1032 ListBase *lb;
1033
1034 UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
1035
1036 /* own keymaps */
1037 keymap = WM_keymap_ensure(wm->defaultconf, "Node Generic", SPACE_NODE, RGN_TYPE_WINDOW);
1038 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
1039
1040 keymap = WM_keymap_ensure(wm->defaultconf, "Node Editor", SPACE_NODE, RGN_TYPE_WINDOW);
1041 WM_event_add_keymap_handler_v2d_mask(&region->runtime->handlers, keymap);
1042
1043 /* add drop boxes */
1044 lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW);
1045
1046 WM_event_add_dropbox_handler(&region->runtime->handlers, lb);
1047
1048 /* The backdrop image gizmo needs to change together with the view. So always refresh gizmos on
1049 * region size changes. */
1050 WM_gizmomap_tag_refresh(region->runtime->gizmo_map);
1051}
1052
1053static void node_main_region_draw(const bContext *C, ARegion *region)
1054{
1055 node_draw_space(*C, *region);
1056}
1057
1058/* ************* dropboxes ************* */
1059
1060static bool node_group_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1061{
1062 SpaceNode *snode = CTX_wm_space_node(C);
1063
1064 if (snode == nullptr) {
1065 return false;
1066 }
1067
1068 if (snode->edittree == nullptr) {
1069 return false;
1070 }
1071
1072 if (!WM_drag_is_ID_type(drag, ID_NT)) {
1073 return false;
1074 }
1075
1076 if (drag->type == WM_DRAG_ID) {
1077 const bNodeTree *node_tree = reinterpret_cast<const bNodeTree *>(
1079 if (!node_tree) {
1080 return false;
1081 }
1082 return node_tree->type == snode->edittree->type;
1083 }
1084
1085 if (drag->type == WM_DRAG_ASSET) {
1086 const wmDragAsset *asset_data = WM_drag_get_asset_data(drag, ID_NT);
1087 if (!asset_data) {
1088 return false;
1089 }
1090 const AssetMetaData *metadata = &asset_data->asset->get_metadata();
1091 const IDProperty *tree_type = BKE_asset_metadata_idprop_find(metadata, "type");
1092 if (!tree_type || IDP_Int(tree_type) != snode->edittree->type) {
1093 return false;
1094 }
1095 }
1096
1097 return true;
1098}
1099
1100static bool node_object_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1101{
1103}
1104
1105static bool node_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1106{
1108}
1109
1110static bool node_id_im_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
1111{
1112 return WM_drag_is_ID_type(drag, ID_IM);
1113}
1114
1115static bool node_mask_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
1116{
1117 return WM_drag_is_ID_type(drag, ID_MSK);
1118}
1119
1120static bool node_material_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1121{
1123}
1124
1125static bool node_color_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1126{
1127 return (drag->type == WM_DRAG_COLOR) && !UI_but_active_drop_color(C);
1128}
1129
1130static bool node_import_file_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1131{
1132 SpaceNode *snode = CTX_wm_space_node(C);
1133 if (!snode) {
1134 return false;
1135 }
1136 if (!snode->edittree) {
1137 return false;
1138 }
1139 if (snode->edittree->type != NTREE_GEOMETRY) {
1140 return false;
1141 }
1142 if (drag->type != WM_DRAG_PATH) {
1143 return false;
1144 }
1146 for (const StringRef path : paths) {
1147 if (path.endswith(".csv") || path.endswith(".obj") || path.endswith(".ply") ||
1148 path.endswith(".stl") || path.endswith(".txt") || path.endswith(".vdb"))
1149 {
1150 return true;
1151 }
1152 }
1153 return false;
1154}
1155
1156static bool node_socket_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
1157{
1158 if (drag->type != WM_DRAG_NODE_TREE_INTERFACE) {
1159 return false;
1160 }
1161 SpaceNode *snode = CTX_wm_space_node(C);
1162 if (!snode || !snode->edittree) {
1163 return false;
1164 }
1165 const bNodeTree *target_ntree = snode->edittree;
1166
1167 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1168 drag->poin);
1169
1170 /* Drag only onto node editors of the same node tree. */
1171 const bNodeTree *source_ntree = drag_data->tree;
1172 if (target_ntree != source_ntree) {
1173 return false;
1174 }
1175
1176 /* Accept only socket items. */
1177 const bNodeTreeInterfaceSocket *socket =
1179 if (socket) {
1180 /* The check to avoid dragging output sockets is deferred to the
1181 * operator's poll in order to display a hint tooltip. */
1182 return true;
1183 }
1184
1185 /* Unless Ctrl is held, prefer dragging the toggle socket alone from a panel with toggle. */
1186 if (!(event->modifier & KM_CTRL)) {
1187 const bNodeTreeInterfacePanel *panel =
1189 if (panel && panel->header_toggle_socket()) {
1190 return true;
1191 }
1192 }
1193 return false;
1194}
1195
1196static bool node_panel_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
1197{
1198 if (drag->type != WM_DRAG_NODE_TREE_INTERFACE) {
1199 return false;
1200 }
1201 SpaceNode *snode = CTX_wm_space_node(C);
1202 if (!snode || !snode->edittree) {
1203 return false;
1204 }
1205 const bNodeTree *target_ntree = snode->edittree;
1206
1207 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1208 drag->poin);
1209
1210 /* Drag only onto node editors of the same node. */
1211 const bNodeTree *source_ntree = drag_data->tree;
1212 if (target_ntree != source_ntree) {
1213 return false;
1214 }
1215
1216 /* Accept only panel items. */
1218 drag_data->item);
1219 if (panel) {
1220 /* Unless Ctrl is held, prefer dragging only the toggle socket of a panel with toggle. */
1221 if (!(event->modifier & KM_CTRL)) {
1222 if (panel->header_toggle_socket()) {
1223 return false;
1224 }
1225 }
1226
1227 /* The check for whether the panel contains at least one input socket is
1228 * deferred to the operator's poll in order to display a hint tooltip. */
1229 return true;
1230 }
1231 return false;
1232}
1233
1235{
1237
1238 RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
1239
1240 RNA_boolean_set(drop->ptr, "show_datablock_in_node", (drag->type != WM_DRAG_ASSET));
1241}
1242
1243static void node_id_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
1244{
1246
1247 RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
1248}
1249
1251{
1253 if (id) {
1254 RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
1255 RNA_struct_property_unset(drop->ptr, "filepath");
1256 return;
1257 }
1258}
1259
1260static void node_import_file_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
1261{
1263}
1264
1265static void node_socket_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
1266{
1267 if (drag->type != WM_DRAG_NODE_TREE_INTERFACE) {
1268 return;
1269 }
1270
1271 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1272 drag->poin);
1273 const bNodeTreeInterfaceSocket *socket =
1275 if (!socket) {
1276 const bNodeTreeInterfacePanel *panel =
1278 socket = panel->header_toggle_socket();
1279 }
1280
1281 BLI_assert(socket);
1282 PropertyRNA *prop = RNA_struct_find_property(drop->ptr, "panel_identifier");
1283 RNA_property_unset(drop->ptr, prop);
1284 RNA_string_set(drop->ptr, "socket_identifier", socket->identifier);
1285}
1286
1287static void node_panel_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
1288{
1289 if (drag->type != WM_DRAG_NODE_TREE_INTERFACE) {
1290 return;
1291 }
1292
1293 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1294 drag->poin);
1296 drag_data->item);
1297
1298 BLI_assert(panel);
1299 PropertyRNA *prop = RNA_struct_find_property(drop->ptr, "socket_identifier");
1300 RNA_property_unset(drop->ptr, prop);
1301 RNA_int_set(drop->ptr, "panel_identifier", panel->identifier);
1302}
1303
1304static std::string node_socket_drop_tooltip(bContext * /*C*/,
1305 wmDrag *drag,
1306 const int /*xy*/[2],
1307 wmDropBox * /*drop*/)
1308{
1309 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1310 drag->poin);
1311 const bNodeTreeInterfaceSocket *socket =
1313
1314 if (socket) {
1315 return BLI_sprintfN(TIP_("Add \"%s\" Input"), socket->name);
1316 }
1317 else {
1318 const bNodeTreeInterfacePanel *panel =
1320 socket = panel->header_toggle_socket();
1321
1322 /* Dragging a panel with toggle defaults to dragging the toggle socket.
1323 * Display a hint with the modifier required to drag the panel. */
1324 if (socket) {
1325 return BLI_sprintfN(TIP_("Add \"%s\" Input (Ctrl to add panel)"), socket->name);
1326 }
1327 }
1329 return "Error: Unsupported socket.";
1330}
1331
1332static std::string node_panel_drop_tooltip(bContext * /*C*/,
1333 wmDrag *drag,
1334 const int /*xy*/[2],
1335 wmDropBox * /*drop*/)
1336{
1337 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1338 drag->poin);
1340 drag_data->item);
1341 BLI_assert(panel);
1342 return BLI_sprintfN(TIP_("Add \"%s\" Panel"), panel->name);
1343}
1344
1345/* this region dropbox definition */
1346static void node_dropboxes()
1347{
1349
1350 WM_dropbox_add(lb,
1351 "NODE_OT_add_object",
1355 nullptr);
1356 WM_dropbox_add(lb,
1357 "NODE_OT_add_collection",
1361 nullptr);
1362 WM_dropbox_add(lb,
1363 "NODE_OT_add_group",
1367 nullptr);
1368 WM_dropbox_add(lb,
1369 "NODE_OT_add_image",
1373 nullptr);
1374 WM_dropbox_add(lb,
1375 "NODE_OT_add_mask",
1379 nullptr);
1380 WM_dropbox_add(lb,
1381 "NODE_OT_add_material",
1385 nullptr);
1387 lb, "NODE_OT_add_color", node_color_drop_poll, UI_drop_color_copy, nullptr, nullptr);
1388 WM_dropbox_add(lb,
1389 "NODE_OT_add_import_node",
1392 nullptr,
1393 nullptr);
1394 WM_dropbox_add(lb,
1395 "NODE_OT_add_group_input_node",
1398 nullptr,
1400 WM_dropbox_add(lb,
1401 "NODE_OT_add_group_input_node",
1404 nullptr,
1406}
1407
1408/* ************* end drop *********** */
1409
1410/* add handlers, stuff you only do once or on area/region changes */
1412{
1413 ED_region_header_init(region);
1414}
1415
1416static void node_header_region_draw(const bContext *C, ARegion *region)
1417{
1418 /* find and set the context */
1420
1421 ED_region_header(C, region);
1422}
1423
1424/* used for header + main region */
1426{
1427 ARegion *region = params->region;
1428 const wmNotifier *wmn = params->notifier;
1429 wmGizmoMap *gzmap = region->runtime->gizmo_map;
1430
1431 /* context changes */
1432 switch (wmn->category) {
1433 case NC_SPACE:
1434 switch (wmn->data) {
1435 case ND_SPACE_NODE:
1436 ED_region_tag_redraw(region);
1437 break;
1438 case ND_SPACE_NODE_VIEW:
1440 break;
1441 }
1442 break;
1443 case NC_ANIMATION:
1444 if (wmn->data == ND_NLA_ACTCHANGE) {
1445 ED_region_tag_redraw(region);
1446 }
1447 break;
1448 case NC_SCREEN:
1449 if (wmn->data == ND_LAYOUTSET || wmn->action == NA_EDITED) {
1451 }
1452 switch (wmn->data) {
1453 case ND_ANIMPLAY:
1454 case ND_LAYER:
1455 ED_region_tag_redraw(region);
1456 break;
1457 }
1458 break;
1459 case NC_WM:
1460 if (wmn->data == ND_JOB) {
1461 ED_region_tag_redraw(region);
1462 }
1463 break;
1464 case NC_SCENE:
1465 ED_region_tag_redraw(region);
1466 if (wmn->data == ND_RENDER_RESULT) {
1468 }
1469 break;
1470 case NC_NODE:
1471 ED_region_tag_redraw(region);
1472 if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
1474 }
1475 break;
1476 case NC_MATERIAL:
1477 case NC_TEXTURE:
1478 case NC_WORLD:
1479 case NC_LINESTYLE:
1480 ED_region_tag_redraw(region);
1481 break;
1482 case NC_OBJECT:
1483 if (wmn->data == ND_OB_SHADING) {
1484 ED_region_tag_redraw(region);
1485 }
1486 break;
1487 case NC_ID:
1488 if (ELEM(wmn->action, NA_RENAME, NA_EDITED)) {
1489 ED_region_tag_redraw(region);
1490 }
1491 break;
1492 case NC_GPENCIL:
1493 if (wmn->action == NA_EDITED) {
1494 ED_region_tag_redraw(region);
1495 }
1496 else if (wmn->data & ND_GPENCIL_EDITMODE) {
1497 ED_region_tag_redraw(region);
1498 }
1499 break;
1500 case NC_VIEWER_PATH:
1501 ED_region_tag_redraw(region);
1502 break;
1503 }
1504}
1505
1506} // namespace blender::ed::space_node
1507
1508/* Outside of blender namespace to avoid Python documentation build error with `ctypes`. */
1509extern "C" {
1510const char *node_context_dir[] = {
1511 "selected_nodes", "active_node", "light", "material", "world", nullptr};
1512};
1513
1514namespace blender::ed::space_node {
1515
1516static int /*eContextResult*/ node_context(const bContext *C,
1517 const char *member,
1519{
1520 SpaceNode *snode = CTX_wm_space_node(C);
1521
1522 if (CTX_data_dir(member)) {
1524 return CTX_RESULT_OK;
1525 }
1526 if (CTX_data_equals(member, "selected_nodes")) {
1527 if (snode->edittree) {
1528 for (bNode *node : snode->edittree->all_nodes()) {
1529 if (node->flag & NODE_SELECT) {
1530 CTX_data_list_add(result, &snode->edittree->id, &RNA_Node, node);
1531 }
1532 }
1533 }
1535 return CTX_RESULT_OK;
1536 }
1537 if (CTX_data_equals(member, "active_node")) {
1538 if (snode->edittree) {
1539 bNode *node = bke::node_get_active(*snode->edittree);
1540 CTX_data_pointer_set(result, &snode->edittree->id, &RNA_Node, node);
1541 }
1542
1544 return CTX_RESULT_OK;
1545 }
1546 if (CTX_data_equals(member, "node_previews")) {
1547 if (snode->nodetree) {
1549 &snode->nodetree->id,
1550 &RNA_NodeInstanceHash,
1551 &snode->nodetree->runtime->previews);
1552 }
1553
1555 return CTX_RESULT_OK;
1556 }
1557 if (CTX_data_equals(member, "material")) {
1558 if (snode->id && GS(snode->id->name) == ID_MA) {
1560 }
1561 return CTX_RESULT_OK;
1562 }
1563 if (CTX_data_equals(member, "light")) {
1564 if (snode->id && GS(snode->id->name) == ID_LA) {
1566 }
1567 return CTX_RESULT_OK;
1568 }
1569 if (CTX_data_equals(member, "world")) {
1570 if (snode->id && GS(snode->id->name) == ID_WO) {
1572 }
1573 return CTX_RESULT_OK;
1574 }
1575
1577}
1578
1592
1593static void node_id_remap(ID *old_id, ID *new_id, SpaceNode *snode)
1594{
1595 if (snode->id == old_id) {
1596 /* nasty DNA logic for SpaceNode:
1597 * ideally should be handled by editor code, but would be bad level call
1598 */
1599 BLI_freelistN(&snode->treepath);
1600
1601 /* XXX Untested in case new_id != nullptr... */
1602 snode->id = new_id;
1603 snode->from = nullptr;
1604 snode->nodetree = nullptr;
1605 snode->edittree = nullptr;
1606 }
1607 else if (GS(old_id->name) == ID_OB) {
1608 if (snode->from == old_id) {
1609 if (new_id == nullptr) {
1610 snode->flag &= ~SNODE_PIN;
1611 }
1612 snode->from = new_id;
1613 }
1614 }
1615 else if (GS(old_id->name) == ID_GD_LEGACY) {
1616 if ((ID *)snode->gpd == old_id) {
1617 snode->gpd = (bGPdata *)new_id;
1618 id_us_min(old_id);
1619 id_us_plus(new_id);
1620 }
1621 }
1622 else if (GS(old_id->name) == ID_NT) {
1623
1624 if (snode->geometry_nodes_tool_tree) {
1625 if (&snode->geometry_nodes_tool_tree->id == old_id) {
1626 snode->geometry_nodes_tool_tree = reinterpret_cast<bNodeTree *>(new_id);
1627 }
1628 }
1629
1630 bNodeTreePath *path, *path_next;
1631
1632 for (path = (bNodeTreePath *)snode->treepath.first; path; path = path->next) {
1633 if ((ID *)path->nodetree == old_id) {
1634 path->nodetree = (bNodeTree *)new_id;
1635 id_us_ensure_real(new_id);
1636 }
1637 if (path == snode->treepath.first) {
1638 /* first nodetree in path is same as snode->nodetree */
1639 snode->nodetree = path->nodetree;
1640 }
1641 if (path->nodetree == nullptr) {
1642 break;
1643 }
1644 }
1645
1646 /* remaining path entries are invalid, remove */
1647 for (; path; path = path_next) {
1648 path_next = path->next;
1649
1650 BLI_remlink(&snode->treepath, path);
1651 MEM_freeN(path);
1652 }
1653
1654 /* edittree is just the last in the path,
1655 * set this directly since the path may have been shortened above */
1656 if (snode->treepath.last) {
1657 path = (bNodeTreePath *)snode->treepath.last;
1658 snode->edittree = path->nodetree;
1660 }
1661 else {
1662 snode->edittree = nullptr;
1663 }
1664 }
1665}
1666
1667static void node_id_remap(ScrArea * /*area*/,
1668 SpaceLink *slink,
1669 const blender::bke::id::IDRemapper &mappings)
1670{
1671 /* Although we should be able to perform all the mappings in a single go this lead to issues when
1672 * running the python test cases. Somehow the nodetree/edittree weren't updated to the new
1673 * pointers that generated a SEGFAULT.
1674 *
1675 * To move forward we should perhaps remove snode->edittree and snode->nodetree as they are just
1676 * copies of pointers. All usages should be calling a function that will receive the appropriate
1677 * instance.
1678 *
1679 * We could also move a remap address at a time to use the IDRemapper as that should get closer
1680 * to cleaner code. See {D13615} for more information about this topic.
1681 */
1682 mappings.iter([&](ID *old_id, ID *new_id) {
1683 node_id_remap(old_id, new_id, reinterpret_cast<SpaceNode *>(slink));
1684 });
1685}
1686
1688{
1689 SpaceNode *snode = reinterpret_cast<SpaceNode *>(space_link);
1690 const int data_flags = BKE_lib_query_foreachid_process_flags_get(data);
1691 const bool is_readonly = (data_flags & IDWALK_READONLY) != 0;
1692 const bool allow_pointer_access = (data_flags & IDWALK_NO_ORIG_POINTERS_ACCESS) == 0;
1693 bool is_embedded_nodetree = snode->id != nullptr && allow_pointer_access &&
1694 bke::node_tree_from_id(snode->id) == snode->nodetree;
1695
1698
1699 bNodeTreePath *path = static_cast<bNodeTreePath *>(snode->treepath.first);
1700 BLI_assert(path == nullptr || path->nodetree == snode->nodetree);
1701
1702 if (is_embedded_nodetree) {
1704 if (path != nullptr) {
1706 }
1707
1708 /* Embedded ID pointers are not remapped (besides exceptions), ensure it still matches
1709 * actual data. Note that `snode->id` was already processed (and therefore potentially
1710 * remapped) above. */
1711 if (!is_readonly) {
1712 snode->nodetree = (snode->id == nullptr) ? nullptr : bke::node_tree_from_id(snode->id);
1713 if (path != nullptr) {
1714 path->nodetree = snode->nodetree;
1715 }
1716 }
1717 }
1718 else {
1721 if (path != nullptr) {
1724 }
1725 }
1726
1729
1730 /* Both `snode->id` and `snode->nodetree` have been remapped now, so their data can be
1731 * accessed. */
1732 BLI_assert(snode->id == nullptr || snode->nodetree == nullptr ||
1733 (snode->nodetree->id.flag & ID_FLAG_EMBEDDED_DATA) == 0 ||
1734 snode->nodetree == bke::node_tree_from_id(snode->id));
1735
1736 /* This is mainly here for readfile case ('lib_link' process), as in such case there is no access
1737 * to original data allowed, so no way to know whether the SpaceNode nodetree pointer is an
1738 * embedded one or not. */
1739 if (!is_readonly && snode->id && !snode->nodetree) {
1740 is_embedded_nodetree = true;
1741 snode->nodetree = bke::node_tree_from_id(snode->id);
1742 if (path != nullptr) {
1743 path->nodetree = snode->nodetree;
1744 }
1745 }
1746
1747 if (path != nullptr) {
1748 for (path = path->next; path != nullptr; path = path->next) {
1749 BLI_assert(path->nodetree != nullptr);
1750 if (allow_pointer_access) {
1752 }
1753
1756
1757 if (path->nodetree == nullptr) {
1758 BLI_assert(!is_readonly);
1759 /* Remaining path entries are invalid, remove them. */
1760 for (bNodeTreePath *path_next; path; path = path_next) {
1761 path_next = path->next;
1762 BLI_remlink(&snode->treepath, path);
1763 MEM_freeN(path);
1764 }
1765 break;
1766 }
1767 }
1768 }
1769 BLI_assert(path == nullptr);
1770
1771 if (!is_readonly) {
1772 /* `edittree` is just the last in the path, set this directly since the path may have
1773 * been shortened above. */
1774 if (snode->treepath.last != nullptr) {
1775 path = static_cast<bNodeTreePath *>(snode->treepath.last);
1776 snode->edittree = path->nodetree;
1777 }
1778 else {
1779 snode->edittree = nullptr;
1780 }
1781 }
1782 else {
1783 /* Only process this pointer in readonly case, otherwise could lead to a bad
1784 * double-remapping e.g. */
1785 if (is_embedded_nodetree && snode->edittree == snode->nodetree) {
1787 }
1788 else {
1790 }
1791 }
1792}
1793
1795{
1796 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
1798}
1799
1800static void node_space_subtype_set(ScrArea *area, int value)
1801{
1802 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
1804}
1805
1807{
1808 bool free;
1810 RNA_enum_items_add(item, totitem, item_src);
1811 if (free) {
1812 MEM_freeN(item_src);
1813 }
1814}
1815
1817{
1818 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
1820 if (tree_type == nullptr) {
1821 return IFACE_("Node Editor");
1822 }
1823 return tree_type->ui_name;
1824}
1825
1826static int node_space_icon_get(const ScrArea *area)
1827{
1828 SpaceNode *snode = static_cast<SpaceNode *>(area->spacedata.first);
1830 if (tree_type == nullptr) {
1831 return ICON_NODETREE;
1832 }
1833 return tree_type->ui_icon;
1834}
1835
1837{
1838 SpaceNode *snode = (SpaceNode *)sl;
1839
1840 if (snode->gpd) {
1841 BLO_read_struct(reader, bGPdata, &snode->gpd);
1842 BKE_gpencil_blend_read_data(reader, snode->gpd);
1843 }
1844
1846 snode->edittree = nullptr;
1847 snode->runtime = nullptr;
1848}
1849
1851{
1852 SpaceNode *snode = (SpaceNode *)sl;
1853 BLO_write_struct(writer, SpaceNode, snode);
1854
1855 LISTBASE_FOREACH (bNodeTreePath *, path, &snode->treepath) {
1856 BLO_write_struct(writer, bNodeTreePath, path);
1857 }
1858}
1859
1860} // namespace blender::ed::space_node
1861
1863{
1864 using namespace blender::ed::space_node;
1865
1866 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
1867 ARegionType *art;
1868
1869 st->spaceid = SPACE_NODE;
1870 STRNCPY(st->name, "Node");
1871
1872 st->create = node_create;
1873 st->free = node_free;
1874 st->init = node_init;
1875 st->exit = node_exit;
1876 st->duplicate = node_duplicate;
1877 st->operatortypes = node_operatortypes;
1878 st->keymap = node_keymap;
1879 st->listener = node_area_listener;
1880 st->refresh = node_area_refresh;
1881 st->context = node_context;
1882 st->dropboxes = node_dropboxes;
1883 st->gizmos = node_widgets;
1884 st->id_remap = node_id_remap;
1885 st->foreach_id = node_foreach_id;
1886 st->space_subtype_item_extend = node_space_subtype_item_extend;
1887 st->space_subtype_get = node_space_subtype_get;
1888 st->space_subtype_set = node_space_subtype_set;
1889 st->space_name_get = node_space_name_get;
1890 st->space_icon_get = node_space_icon_get;
1891 st->blend_read_data = node_space_blend_read_data;
1892 st->blend_read_after_liblink = nullptr;
1893 st->blend_write = node_space_blend_write;
1894
1895 /* regions: main window */
1896 art = MEM_callocN<ARegionType>("spacetype node region");
1903 art->cursor = node_cursor;
1904 art->event_cursor = true;
1905 art->clip_gizmo_events_by_ui = true;
1907
1908 BLI_addhead(&st->regiontypes, art);
1909
1910 /* regions: header */
1911 art = MEM_callocN<ARegionType>("spacetype node region");
1913 art->prefsizey = HEADERY;
1918
1919 BLI_addhead(&st->regiontypes, art);
1920
1921 /* regions: list-view/buttons */
1922 art = MEM_callocN<ARegionType>("spacetype node region");
1923 art->regionid = RGN_TYPE_UI;
1930 BLI_addhead(&st->regiontypes, art);
1931
1932 /* regions: toolbar */
1933 art = MEM_callocN<ARegionType>("spacetype view3d tools region");
1934 art->regionid = RGN_TYPE_TOOLS;
1935 art->prefsizex = int(UI_TOOLBAR_WIDTH);
1936 art->prefsizey = 50; /* XXX */
1943 BLI_addhead(&st->regiontypes, art);
1944
1948
1949 BKE_spacetype_register(std::move(st));
1950}
Main runtime representation of an asset.
IDProperty * BKE_asset_metadata_idprop_find(const AssetMetaData *asset_data, const char *name) ATTR_WARN_UNUSED_RESULT
Definition asset.cc:179
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
bool CTX_data_equals(const char *member, const char *str)
void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data)
bool CTX_data_dir(const char *member)
void CTX_data_id_pointer_set(bContextDataResult *result, ID *id)
SpaceNode * CTX_wm_space_node(const bContext *C)
@ CTX_RESULT_MEMBER_NOT_FOUND
@ CTX_RESULT_OK
void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data)
@ CTX_DATA_TYPE_POINTER
@ CTX_DATA_TYPE_COLLECTION
void CTX_data_type_set(bContextDataResult *result, short type)
void BKE_gpencil_blend_read_data(struct BlendDataReader *reader, struct bGPdata *gpd)
#define IDP_Int(prop)
void id_us_plus(ID *id)
Definition lib_id.cc:353
void id_us_ensure_real(ID *id)
Definition lib_id.cc:308
void id_us_min(ID *id)
Definition lib_id.cc:361
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
@ IDWALK_CB_USER_ONE
@ IDWALK_CB_EMBEDDED_NOT_OWNING
@ IDWALK_CB_DIRECT_WEAK_LINK
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
LibraryForeachIDFlag BKE_lib_query_foreachid_process_flags_get(const LibraryForeachIDData *data)
Definition lib_query.cc:129
@ IDWALK_READONLY
@ IDWALK_NO_ORIG_POINTERS_ACCESS
#define GEO_NODE_CLOSURE_OUTPUT
#define GEO_NODE_FOREACH_GEOMETRY_ELEMENT_OUTPUT
#define GEO_NODE_SIMULATION_OUTPUT
#define GEO_NODE_REPEAT_OUTPUT
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:276
ARegion * BKE_area_region_new()
Definition screen.cc:381
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:840
@ REGION_DRAW_LOCK_ALL
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define BLI_assert(a)
Definition BLI_assert.h:46
void BLI_kdtree_nd_ free(KDTree *tree)
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(ListBase *lb)
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:131
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:91
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
MINLINE void copy_v2_v2(float r[2], const float a[2])
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:688
#define ELEM(...)
#define BLO_write_struct(writer, struct_name, data_ptr)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define TIP_(msgid)
#define IFACE_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
bool DEG_is_original(const T *id)
T * DEG_get_original(T *id)
ID and Library types, which are fundamental for SDNA.
@ ID_RECALC_NTREE_OUTPUT
Definition DNA_ID.h:1063
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:687
@ ID_IM
@ ID_NT
@ ID_LA
@ ID_MSK
@ ID_WO
@ ID_MA
@ ID_GD_LEGACY
@ ID_GR
@ ID_OB
@ eModifierFlag_Active
@ eModifierType_Nodes
@ NTREE_GEOMETRY
@ NTREE_COMPOSIT
@ NODE_SELECT
Object is a sort of wrapper for general info.
#define HEADERY
@ RGN_TYPE_UI
@ RGN_TYPE_WINDOW
@ RGN_TYPE_HEADER
@ RGN_TYPE_TOOLS
@ RGN_FLAG_HIDDEN
@ RGN_ALIGN_BOTTOM
@ RGN_ALIGN_LEFT
@ RGN_ALIGN_TOP
@ RGN_ALIGN_RIGHT
@ SN_OVERLAY_SHOW_PATH
@ SN_OVERLAY_SHOW_PREVIEWS
@ SN_OVERLAY_SHOW_WIRE_COLORS
@ SN_OVERLAY_SHOW_OVERLAYS
@ SNODE_PIN
@ SNODE_USE_ALPHA
@ SNODE_SHOW_GPENCIL
@ SPACE_NODE
SpaceNodeGeometryNodesType
@ SNODE_GEOMETRY_MODIFIER
@ SNODE_GEOMETRY_TOOL
@ SNODE_SHADER_WORLD
@ SNODE_SHADER_LINESTYLE
#define UI_SCALE_FAC
@ USER_HEADER_BOTTOM
@ V2D_SCROLL_RIGHT
@ V2D_SCROLL_BOTTOM
@ V2D_LIMITZOOM
@ V2D_KEEPASPECT
void ED_node_set_tree_type(SpaceNode *snode, blender::bke::bNodeTreeType *typeinfo)
Definition node_edit.cc:538
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:548
void ED_node_set_active_viewer_key(SpaceNode *snode)
bool ED_node_is_shader(SpaceNode *snode)
Definition node_edit.cc:553
void ED_node_composite_job(const bContext *C, bNodeTree *nodetree, Scene *scene_owner)
Definition node_edit.cc:441
bool ED_node_is_geometry(SpaceNode *snode)
Definition node_edit.cc:563
bool ED_node_is_texture(SpaceNode *snode)
Definition node_edit.cc:558
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:714
void ED_area_do_mgs_subscribe_for_tool_ui(const wmRegionMessageSubscribeParams *params)
Definition area.cc:432
@ ED_KEYMAP_UI
Definition ED_screen.hh:740
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:746
@ ED_KEYMAP_TOOL
Definition ED_screen.hh:742
@ ED_KEYMAP_GPENCIL
Definition ED_screen.hh:748
@ ED_KEYMAP_GIZMO
Definition ED_screen.hh:741
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:743
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:745
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3466
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:3754
void ED_region_header_init(ARegion *region)
Definition area.cc:3769
int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, int axis)
Definition area_utils.cc:38
void ED_area_tag_refresh(ScrArea *area)
Definition area.cc:743
void ED_region_generic_tools_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
Definition area_utils.cc:26
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:3473
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:639
Read Guarded memory(de)allocation.
blender::bke::bNodeTreeType * rna_node_tree_type_from_enum(int value)
int rna_node_tree_idname_to_enum(const char *idname)
const EnumPropertyItem * RNA_enum_node_tree_types_itemf_impl(bContext *C, bool *r_free)
#define C
Definition RandGen.cpp:29
#define UI_SIDEBAR_PANEL_WIDTH
bool UI_but_active_drop_name(const bContext *C)
#define UI_TOOLBAR_WIDTH
void UI_drop_color_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
bool UI_but_active_drop_color(bContext *C)
void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
Definition view2d.cc:221
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1667
void UI_view2d_center_set(View2D *v2d, float x, float y)
Definition view2d.cc:1948
@ V2D_COMMONVIEW_CUSTOM
Definition UI_view2d.hh:31
#define NC_WORLD
Definition WM_types.hh:384
#define ND_SHADING
Definition WM_types.hh:474
#define NC_ID
Definition WM_types.hh:392
#define NC_NODE
Definition WM_types.hh:391
#define ND_NLA_ACTCHANGE
Definition WM_types.hh:495
@ KM_CTRL
Definition WM_types.hh:276
#define ND_RENDER_RESULT
Definition WM_types.hh:443
#define ND_JOB
Definition WM_types.hh:413
#define NC_WM
Definition WM_types.hh:371
#define ND_GPENCIL_EDITMODE
Definition WM_types.hh:501
#define NC_LINESTYLE
Definition WM_types.hh:397
#define NC_ANIMATION
Definition WM_types.hh:385
#define NC_VIEWER_PATH
Definition WM_types.hh:403
#define ND_SPACE_NODE
Definition WM_types.hh:523
#define ND_COMPO_RESULT
Definition WM_types.hh:444
#define NC_SCREEN
Definition WM_types.hh:374
#define NC_MOVIECLIP
Definition WM_types.hh:394
#define ND_ANIMPLAY
Definition WM_types.hh:421
#define NC_SCENE
Definition WM_types.hh:375
#define ND_SPACE_NODE_VIEW
Definition WM_types.hh:533
#define ND_NODES
Definition WM_types.hh:433
#define ND_MODIFIER
Definition WM_types.hh:459
#define NA_EDITED
Definition WM_types.hh:581
#define NC_MATERIAL
Definition WM_types.hh:377
#define NC_IMAGE
Definition WM_types.hh:381
#define ND_UNDO
Definition WM_types.hh:414
#define ND_FRAME
Definition WM_types.hh:431
#define NC_GPENCIL
Definition WM_types.hh:396
#define NC_TEXTURE
Definition WM_types.hh:378
#define ND_LAYER
Definition WM_types.hh:447
#define NC_MASK
Definition WM_types.hh:395
#define NA_RENAME
Definition WM_types.hh:585
@ WM_DRAG_PATH
Definition WM_types.hh:1205
@ WM_DRAG_COLOR
Definition WM_types.hh:1215
@ WM_DRAG_NODE_TREE_INTERFACE
Definition WM_types.hh:1220
@ WM_DRAG_ASSET
Definition WM_types.hh:1199
@ WM_DRAG_ID
Definition WM_types.hh:1198
#define ND_OB_SHADING
Definition WM_types.hh:454
#define ND_LAYOUTSET
Definition WM_types.hh:423
#define NC_OBJECT
Definition WM_types.hh:376
#define ND_SHADING_LINKS
Definition WM_types.hh:476
#define ND_SHADING_DRAW
Definition WM_types.hh:475
#define NC_SPACE
Definition WM_types.hh:389
#define NA_SELECTED
Definition WM_types.hh:586
#define U
BMesh const char void * data
const ComputeContextHash & hash() const
constexpr IndexRange drop_back(int64_t n) const
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_stack.hh:308
void push(const T &value)
Definition BLI_stack.hh:213
void append(const T &value)
bool is_empty() const
IndexRange index_range() const
const EvaluateClosureComputeContext & for_evaluate_closure(const ComputeContext *parent, int32_t node_id, const bNodeTree *tree=nullptr, const std::optional< nodes::ClosureSourceLocation > &closure_source_location=std::nullopt)
const ModifierComputeContext & for_modifier(const ComputeContext *parent, const NodesModifierData &nmd)
const GroupNodeComputeContext & for_group_node(const ComputeContext *parent, int32_t node_id, const bNodeTree *tree=nullptr)
const ForeachGeometryElementZoneComputeContext & for_foreach_geometry_element_zone(const ComputeContext *parent, int32_t output_node_id, int index)
const RepeatZoneComputeContext & for_repeat_zone(const ComputeContext *parent, int32_t output_node_id, int iteration)
const OperatorComputeContext & for_operator(const ComputeContext *parent)
const SimulationZoneComputeContext & for_simulation_zone(const ComputeContext *parent, int output_node_id)
const bNode * output_node() const
Vector< const bNodeTreeZone * > get_zones_to_enter_from_root(const bNodeTreeZone *zone) const
Vector< const bNodeTreeZone * > get_zones_to_enter(const bNodeTreeZone *outer_zone, const bNodeTreeZone *inner_zone) const
bool link_between_zones_is_allowed(const bNodeTreeZone *from_zone, const bNodeTreeZone *to_zone) const
const bNodeTreeZone * get_zone_by_node(const int32_t node_id) const
const bNodeTreeZone * get_zone_by_socket(const bNodeSocket &socket) const
void iter(FunctionRef< void(ID *old_id, ID *new_id)> func) const
bool matches(const SocketInterfaceKey &other) const
KDTree_3d * tree
float length(VecOp< float, D >) RET
#define GS(a)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
T & get_item_as(bNodeTreeInterfaceItem &item)
bNode * node_find_node_by_name(bNodeTree &ntree, StringRefNull name)
Definition node.cc:3607
bNodeTreeType * node_tree_type_find(StringRef idname)
Definition node.cc:2635
bNode * node_get_active(bNodeTree &ntree)
Definition node.cc:4957
const bNodeInstanceKey NODE_INSTANCE_KEY_BASE
Definition node.cc:5118
bNodeInstanceKey node_instance_key(bNodeInstanceKey parent_key, const bNodeTree *ntree, const bNode *node)
Definition node.cc:5139
Span< bNodeTreeType * > node_tree_types_get()
Definition node.cc:2706
bNodeTree * node_tree_from_id(ID *id)
Definition node.cc:4840
void paths_to_operator_properties(PointerRNA *ptr, const Span< std::string > paths)
Definition io_utils.cc:117
static const ComputeContext * get_node_editor_root_compute_context(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
const ComputeContext * compute_context_for_edittree_socket(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache, const bNodeSocket &socket)
static void node_header_region_init(wmWindowManager *, ARegion *region)
static void node_widgets()
static void node_space_subtype_item_extend(bContext *C, EnumPropertyItem **item, int *totitem)
static std::string node_panel_drop_tooltip(bContext *, wmDrag *drag, const int[2], wmDropBox *)
static const ComputeContext * compute_context_for_zones(const Span< const bke::bNodeTreeZone * > zones, bke::ComputeContextCache &compute_context_cache, const ComputeContext *parent_compute_context)
static bool node_import_file_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
static int node_space_icon_get(const ScrArea *area)
static void node_toolbar_region_draw(const bContext *C, ARegion *region)
static void node_space_blend_read_data(BlendDataReader *reader, SpaceLink *sl)
static void node_group_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
static bool node_panel_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
static void node_header_region_draw(const bContext *C, ARegion *region)
MenuType add_catalog_assets_menu_type()
static void node_foreach_id(SpaceLink *space_link, LibraryForeachIDData *data)
void free_previews(wmWindowManager &wm, SpaceNode &snode)
static SpaceLink * node_duplicate(SpaceLink *sl)
MenuType add_unassigned_assets_menu_type()
static void node_main_region_init(wmWindowManager *wm, ARegion *region)
static void node_id_remap(ID *old_id, ID *new_id, SpaceNode *snode)
void node_set_cursor(wmWindow &win, ARegion &region, SpaceNode &snode, const float2 &cursor)
static void node_import_file_drop_copy(bContext *, wmDrag *drag, wmDropBox *drop)
std::optional< nodes::FoundNestedNodeID > find_nested_node_id_in_root(const SpaceNode &snode, const bNode &node)
static void node_area_refresh(const bContext *C, ScrArea *area)
void NODE_GGT_backdrop_split(wmGizmoGroupType *gzgt)
static void node_panel_drop_copy(bContext *, wmDrag *drag, wmDropBox *drop)
static bool node_material_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
static std::optional< const ComputeContext * > compute_context_for_tree_path(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache, const ComputeContext *parent_compute_context)
void NODE_GGT_backdrop_corner_pin(wmGizmoGroupType *gzgt)
const ComputeContext * compute_context_for_edittree(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
static bool node_color_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
static bool node_mask_drop_poll(bContext *, wmDrag *drag, const wmEvent *)
static int node_space_subtype_get(ScrArea *area)
void NODE_GGT_backdrop_crop(wmGizmoGroupType *gzgt)
static bool node_group_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
static void node_init(wmWindowManager *, ScrArea *area)
const ComputeContext * compute_context_for_zone(const bke::bNodeTreeZone &zone, bke::ComputeContextCache &compute_context_cache, const ComputeContext *parent_compute_context)
static void node_region_listener(const wmRegionListenerParams *params)
static bool node_id_im_drop_poll(bContext *, wmDrag *drag, const wmEvent *)
float2 space_node_group_offset(const SpaceNode &snode)
void NODE_GGT_backdrop_box_mask(wmGizmoGroupType *gzgt)
static void node_free(SpaceLink *sl)
static bool node_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
std::optional< ObjectAndModifier > get_modifier_for_node_editor(const SpaceNode &snode)
static blender::StringRefNull node_space_name_get(const ScrArea *area)
static void node_dropboxes()
void NODE_GGT_backdrop_transform(wmGizmoGroupType *gzgt)
void snode_set_context(const bContext &C)
Definition node_edit.cc:726
void NODE_GGT_backdrop_sun_beams(wmGizmoGroupType *gzgt)
static void node_area_listener(const wmSpaceTypeListenerParams *params)
static void node_id_im_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
void node_keymap(wmKeyConfig *keyconf)
Definition node_ops.cc:121
static std::string node_socket_drop_tooltip(bContext *, wmDrag *drag, const int[2], wmDropBox *)
void NODE_GGT_backdrop_ellipse_mask(wmGizmoGroupType *gzgt)
static int node_context(const bContext *C, const char *member, bContextDataResult *result)
static bool node_object_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
void node_draw_space(const bContext &C, ARegion &region)
static void node_cursor(wmWindow *win, ScrArea *area, ARegion *region)
static void node_buttons_region_draw(const bContext *C, ARegion *region)
static void node_socket_drop_copy(bContext *, wmDrag *drag, wmDropBox *drop)
static void node_id_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
bool node_editor_is_for_geometry_nodes_modifier(const SpaceNode &snode, const Object &object, const NodesModifierData &nmd)
static void node_toolbar_region_init(wmWindowManager *wm, ARegion *region)
static void node_exit(wmWindowManager *wm, ScrArea *area)
const ComputeContext * compute_context_for_edittree_node(const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache, const bNode &node)
static void node_main_region_draw(const bContext *C, ARegion *region)
static bool any_node_uses_id(const bNodeTree *ntree, const ID *id)
const ComputeContext * compute_context_for_closure_evaluation(const ComputeContext *closure_socket_context, const bNodeSocket &closure_socket, bke::ComputeContextCache &compute_context_cache, const std::optional< nodes::ClosureSourceLocation > &source_location)
static void node_buttons_region_init(wmWindowManager *wm, ARegion *region)
static void node_space_blend_write(BlendWriter *writer, SpaceLink *sl)
static void node_area_tag_tree_recalc(SpaceNode *snode, ScrArea *area)
static bool node_socket_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
static SpaceLink * node_create(const ScrArea *, const Scene *)
static void node_space_subtype_set(ScrArea *area, int value)
VecBase< float, 2 > float2
const char * node_context_dir[]
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
void RNA_property_unset(PointerRNA *ptr, PropertyRNA *prop)
void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
bNodeTree * ED_node_tree_get(SpaceNode *snode, int level)
void ED_node_tree_start(ARegion *region, SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from)
Definition space_node.cc:76
void ED_node_cursor_location_set(SpaceNode *snode, const float value[2])
void ED_node_tree_pop(ARegion *region, SpaceNode *snode)
void ED_node_tree_path_get(SpaceNode *snode, char *value)
void ED_node_tree_push(ARegion *region, SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
int ED_node_tree_depth(SpaceNode *snode)
void ED_node_set_active_viewer_key(SpaceNode *snode)
int ED_node_tree_path_length(SpaceNode *snode)
void ED_node_cursor_location_get(const SpaceNode *snode, float value[2])
void ED_spacetype_node()
bool clip_gizmo_events_by_ui
void(* message_subscribe)(const wmRegionMessageSubscribeParams *params)
void(* cursor)(wmWindow *win, ScrArea *area, ARegion *region)
void(* listener)(const wmRegionListenerParams *params)
void(* draw)(const bContext *C, ARegion *region)
short event_cursor
int(* snap_size)(const ARegion *region, int size, int axis)
void(* init)(wmWindowManager *wm, ARegion *region)
ARegionRuntimeHandle * runtime
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
Definition DNA_ID.h:404
short flag
Definition DNA_ID.h:420
char name[66]
Definition DNA_ID.h:415
unsigned int session_uid
Definition DNA_ID.h:444
void * last
void * first
struct bNodeTree * node_group
ListBase spacedata
char tree_idname[64]
SpaceNode_Runtime * runtime
struct ID * from
ListBase regionbase
struct bGPdata * gpd
ListBase treepath
struct bNodeTree * edittree
struct ID * id
struct bNodeTree * geometry_nodes_tool_tree
SpaceNodeOverlay overlay
struct bNodeTree * nodetree
char geometry_nodes_type
float minzoom
short keeptot
float max[2]
short keepzoom
float min[2]
float maxzoom
unsigned int value
struct bNodeTree * nodetree
struct bNodeTreePath * next
struct bNodeTreePath * prev
bNodeInstanceKey parent_key
char display_name[64]
float view_center[2]
bNodeTreeRuntimeHandle * runtime
bNodeInstanceKey active_viewer_key
struct ID * id
char name[64]
int16_t type_legacy
void * storage
int32_t identifier
SocketInContext output_socket(int index) const
float xmax
float xmin
float ymax
float ymin
int ymin
int xmin
const AssetRepresentationHandle * asset
Definition WM_types.hh:1239
eWM_DragDataType type
Definition WM_types.hh:1327
void * poin
Definition WM_types.hh:1328
PointerRNA * ptr
Definition WM_types.hh:1415
wmEventModifierFlag modifier
Definition WM_types.hh:771
int xy[2]
Definition WM_types.hh:758
unsigned int data
Definition WM_types.hh:355
unsigned int action
Definition WM_types.hh:355
unsigned int category
Definition WM_types.hh:355
void * reference
Definition WM_types.hh:357
struct wmEvent * eventstate
i
Definition text_draw.cc:230
uint len
wmDropBox * WM_dropbox_add(ListBase *lb, const char *idname, bool(*poll)(bContext *C, wmDrag *drag, const wmEvent *event), void(*copy)(bContext *C, wmDrag *drag, wmDropBox *drop), void(*cancel)(Main *bmain, wmDrag *drag, wmDropBox *drop), WMDropboxTooltipFunc tooltip)
void WM_drag_free_imported_drag_ID(Main *bmain, wmDrag *drag, wmDropBox *drop)
blender::Span< std::string > WM_drag_get_paths(const wmDrag *drag)
bool WM_drag_is_ID_type(const wmDrag *drag, int idcode)
ID * WM_drag_get_local_ID_or_import_from_asset(const bContext *C, const wmDrag *drag, int idcode)
ListBase * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
wmDragAsset * WM_drag_get_asset_data(const wmDrag *drag, int idcode)
ID * WM_drag_get_local_ID(const wmDrag *drag, short idcode)
wmEventHandler_Dropbox * WM_event_add_dropbox_handler(ListBase *handlers, ListBase *dropboxes)
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
void WM_main_add_notifier(uint type, void *reference)
wmEventHandler_Keymap * WM_event_add_keymap_handler_v2d_mask(ListBase *handlers, wmKeyMap *keymap)
wmGizmoGroupTypeRef * WM_gizmogrouptype_append_and_link(wmGizmoMapType *gzmap_type, void(*wtfunc)(wmGizmoGroupType *))
void WM_gizmomap_tag_refresh(wmGizmoMap *gzmap)
wmGizmoMapType * WM_gizmomaptype_ensure(const wmGizmoMapType_Params *gzmap_params)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:893
bool WM_menutype_add(MenuType *mt)