Blender V5.3
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
12#include "BLI_listbase.hh"
13#include "BLI_math_vector_c.hh"
14#include "BLI_stack.hh"
15#include "BLI_string.hh"
16#include "BLI_string_utf8.hh"
17
18#include "DNA_ID.h"
20#include "DNA_material_types.h"
21#include "DNA_modifier_types.h"
22#include "DNA_node_types.h"
23#include "DNA_object_types.h"
24#include "DNA_screen_types.h"
25#include "DNA_space_types.h"
27
28#include "MEM_guardedalloc.h"
29
30#include "BKE_annotations.h"
31#include "BKE_asset.hh"
32#include "BKE_compositor.hh"
35#include "BKE_context.hh"
36#include "BKE_idprop.hh"
37#include "BKE_lib_id.hh"
38#include "BKE_lib_query.hh"
39#include "BKE_lib_remap.hh"
41#include "BKE_node_runtime.hh"
43#include "BKE_screen.hh"
44
45#include "BLT_translation.hh"
46
47#include "ED_asset_shelf.hh"
48#include "ED_image.hh"
49#include "ED_node.hh"
50#include "ED_node_preview.hh"
51#include "ED_screen.hh"
52#include "ED_space_api.hh"
53
54#include "UI_view2d.hh"
55
56#include "DEG_depsgraph.hh"
58
59#include "BLO_read_write.hh"
60
61#include "RNA_access.hh"
62#include "RNA_define.hh"
63#include "RNA_enum_types.hh"
64#include "RNA_prototypes.hh"
65
66#include "WM_api.hh"
67#include "WM_types.hh"
68
69#include "NOD_trace_values.hh"
70
71#include "io_utils.hh"
72
73#include "node_intern.hh" /* own include */
74
75namespace blender {
76
77/* ******************** tree path ********************* */
78
79void ED_node_tree_start(ARegion *region, SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from)
80{
81 for (bNodeTreePath &path : snode->treepath.items_mutable()) {
82 MEM_delete(&path);
83 }
84 snode->treepath.clear_no_delete();
85
86 if (ntree) {
87 bNodeTreePath *path = MEM_new<bNodeTreePath>("node tree path");
88 path->nodetree = ntree;
90
91 /* Set initial view center from node tree. */
92 copy_v2_v2(path->view_center, ntree->view_center);
93 path->view_width = ntree->view_width;
94
95 if (region) {
96 /* Leave the zoom level unchanged if it hasn't been set before. */
97 if (ntree->view_width != 0.0f) {
98 ui::view2d_size_x_set(&region->v2d, ntree->view_width);
99 }
100 ui::view2d_center_set(&region->v2d, ntree->view_center[0], ntree->view_center[1]);
101 }
102
103 if (id) {
104 STRNCPY_UTF8(path->display_name, id->name + 2);
105 }
106
107 BLI_addtail(&snode->treepath, path);
108
109 if (ntree->type != NTREE_GEOMETRY) {
110 /* This can probably be removed for all node tree types. It mainly exists because it was not
111 * possible to store id references in custom properties. Also see #36024. I don't want to
112 * remove it for all tree types in bcon3 though. */
113 id_us_ensure_real(&ntree->id);
114 }
115 }
116
117 /* update current tree */
118 snode->nodetree = snode->edittree = ntree;
119 snode->id = id;
120 snode->from = from;
121
124
126}
127
128void ED_node_tree_push(ARegion *region, SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
129{
130 bNodeTreePath *path = MEM_new<bNodeTreePath>("node tree path");
131 bNodeTreePath *prev_path = snode->treepath.last();
132 path->nodetree = ntree;
133 if (gnode) {
134 if (prev_path) {
135 path->parent_key = bke::node_instance_key(prev_path->parent_key, prev_path->nodetree, gnode);
136 }
137 else {
139 }
140
141 STRNCPY_UTF8(path->node_name, gnode->name);
142 STRNCPY_UTF8(path->display_name, gnode->name);
143 }
144 else {
146 }
147
148 /* Set initial view center from node tree. */
149 copy_v2_v2(path->view_center, ntree->view_center);
150 path->view_width = ntree->view_width;
151 if (region) {
152 if (ntree->view_width != 0.0f) {
153 ui::view2d_size_x_set(&region->v2d, ntree->view_width);
154 }
155 ui::view2d_center_set(&region->v2d, ntree->view_center[0], ntree->view_center[1]);
156 }
157
158 BLI_addtail(&snode->treepath, path);
159
160 id_us_ensure_real(&ntree->id);
161
162 /* update current tree */
163 snode->edittree = ntree;
164
167
169}
170
171void ED_node_tree_pop(ARegion *region, SpaceNode *snode)
172{
173 bNodeTreePath *path = snode->treepath.last();
174
175 /* don't remove root */
176 if (path == snode->treepath.first_) {
177 return;
178 }
179
180 BLI_remlink(&snode->treepath, path);
181 MEM_delete(path);
182
183 /* update current tree */
184 path = snode->treepath.last();
185 snode->edittree = path->nodetree;
186
187 /* Set view center and zoom from node tree path. */
188 if (region) {
189 if (path->view_width != 0.0f) {
190 ui::view2d_size_x_set(&region->v2d, path->view_width);
191 }
192 ui::view2d_center_set(&region->v2d, path->view_center[0], path->view_center[1]);
193 }
194
197
199}
200
202{
203 return snode->treepath.count();
204}
205
207{
208 bNodeTreePath *path;
209 int i;
210 for (path = snode->treepath.last(), i = 0; path; path = path->prev, i++) {
211 if (i == level) {
212 return path->nodetree;
213 }
214 }
215 return nullptr;
216}
217
219{
220 int length = 0;
221
222 for (const auto [i, path] : snode->treepath.enumerate()) {
223 length += strlen(path.display_name);
224 if (i > 0) {
225 length += 1; /* for separator char */
226 }
227 }
228 return length;
229}
230
231void ED_node_tree_path_get(SpaceNode *snode, char *value)
232{
233
234#ifndef NDEBUG
235 const char *value_orig = value;
236#endif
237 /* Note that the caller ensures there is enough space available. */
238 for (const auto [i, path] : snode->treepath.enumerate()) {
239 const int len = strlen(path.display_name);
240 if (i != 0) {
241 *value++ = '/';
242 }
243 memcpy(value, path.display_name, len);
244 value += len;
245 }
246 *value = '\0';
247 BLI_assert(ptrdiff_t(ED_node_tree_path_length(snode)) == ptrdiff_t(value - value_orig));
248}
249
251{
252 bNodeTreePath *path = snode->treepath.last();
253 if (snode->nodetree && path) {
254 /* A change in active viewer may result in the change of the output node used by the
255 * compositor, so we need to get notified about such changes. */
256 if (snode->nodetree->active_viewer_key.value != path->parent_key.value &&
257 snode->nodetree->type == NTREE_COMPOSIT)
258 {
261 }
262
263 snode->nodetree->active_viewer_key = path->parent_key;
264 }
265}
266
267void ED_node_cursor_location_get(const SpaceNode *snode, float value[2])
268{
269 copy_v2_v2(value, snode->runtime->cursor);
270}
271
272void ED_node_cursor_location_set(SpaceNode *snode, const float value[2])
273{
274 copy_v2_v2(snode->runtime->cursor, value);
275}
276
277namespace ed::space_node {
278
280{
281 const bNodeTreePath *path = snode.treepath.last();
282
283 if (path && path->prev) {
284 return float2(path->view_center) - float2(path->prev->view_center);
285 }
286 return float2(0);
287}
288
289std::optional<nodes::FoundNestedNodeID> find_nested_node_id_in_root(const SpaceNode &snode,
290 const bNode &query_node)
291{
292 BLI_assert(snode.edittree->runtime->nodes_by_id.contains(const_cast<bNode *>(&query_node)));
293 bke::ComputeContextCache compute_context_cache;
294 const ComputeContext *compute_context = compute_context_for_edittree_node(
295 snode, compute_context_cache, query_node);
296 if (!compute_context) {
297 return {};
298 }
299 return find_nested_node_id_in_root(*snode.nodetree, compute_context, query_node.identifier);
300}
301
302std::optional<nodes::FoundNestedNodeID> find_nested_node_id_in_root(
303 const bNodeTree &root_tree, const ComputeContext *compute_context, const int node_id)
304{
306 Vector<int> node_ids;
307 for (const ComputeContext *context = compute_context; context != nullptr;
308 context = context->parent())
309 {
310 if (const auto *node_context = dynamic_cast<const bke::GroupNodeComputeContext *>(context)) {
311 node_ids.append(node_context->node_id());
312 }
313 else if (dynamic_cast<const bke::RepeatZoneComputeContext *>(context) != nullptr) {
314 found.is_in_loop = true;
315 }
316 else if (dynamic_cast<const bke::SimulationZoneComputeContext *>(context) != nullptr) {
317 found.is_in_simulation = true;
318 }
319 else if (dynamic_cast<const bke::ForeachGeometryElementZoneComputeContext *>(context) !=
320 nullptr)
321 {
322 found.is_in_loop = true;
323 }
324 else if (dynamic_cast<const bke::EvaluateClosureComputeContext *>(context) != nullptr) {
325 found.is_in_closure = true;
326 }
327 }
328 std::reverse(node_ids.begin(), node_ids.end());
329 node_ids.append(node_id);
330 const bNestedNodeRef *nested_node_ref = root_tree.nested_node_ref_from_node_id_path(node_ids);
331 if (nested_node_ref == nullptr) {
332 return std::nullopt;
333 }
334 found.id = nested_node_ref->id;
335 return found;
336}
337
339{
340 SpaceNode *snode = CTX_wm_space_node(C);
341
342 if (snode && snode->from) {
343 if (snode->from->id_type() == ID_OB) {
344 return id_cast<Object *>(snode->from);
345 }
346 }
347
348 return static_cast<Object *>(CTX_data_pointer_get(C, "object").data);
349}
350
351std::optional<ObjectAndModifier> get_geometry_nodes_modifier_for_node_editor(
352 const SpaceNode &snode)
353{
355 return std::nullopt;
356 }
357 if (snode.id == nullptr) {
358 return std::nullopt;
359 }
360 if (GS(snode.id->name) != ID_OB) {
361 return std::nullopt;
362 }
363 const Object *object = reinterpret_cast<Object *>(snode.id);
364 const NodesModifierData *used_modifier = nullptr;
365 if (snode.flag & SNODE_PIN) {
366 for (const ModifierData &md : object->modifiers) {
367 if (md.type == eModifierType_Nodes) {
368 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(&md);
369 /* Would be good to store the name of the pinned modifier in the node editor. */
370 if (nmd->node_group == snode.nodetree) {
371 used_modifier = nmd;
372 break;
373 }
374 }
375 }
376 }
377 else {
378 for (const ModifierData &md : object->modifiers) {
379 if (md.type == eModifierType_Nodes) {
380 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(&md);
381 if (nmd->node_group == snode.nodetree) {
382 if (md.flag & eModifierFlag_Active) {
383 used_modifier = nmd;
384 break;
385 }
386 }
387 }
388 }
389 }
390 if (used_modifier == nullptr) {
391 return std::nullopt;
392 }
393 return ObjectAndModifier{object, used_modifier};
394}
395
397 const Object &object,
398 const NodesModifierData &nmd)
399{
400 const std::optional<ObjectAndModifier> object_and_modifier =
402 if (!object_and_modifier) {
403 return false;
404 }
405 const Object *object_orig = DEG_is_original(&object) ? &object : DEG_get_original(&object);
406 if (object_and_modifier->object != object_orig) {
407 return false;
408 }
409 return object_and_modifier->nmd->modifier.persistent_uid == nmd.modifier.persistent_uid;
410}
411
413 const Scene *scene = nullptr;
415};
416
417static std::optional<SceneAndCompositorEffect> get_scene_compositor_effect_for_node_editor(
418 const SpaceNode &space_node)
419{
420 if (space_node.node_tree_sub_type != SNODE_COMPOSITOR_SCENE) {
421 return std::nullopt;
422 }
423
424 if (!space_node.id) {
425 return std::nullopt;
426 }
427
428 if (GS(space_node.id->name) != ID_SCE) {
429 return std::nullopt;
430 }
431
432 const Scene *scene = id_cast<Scene *>(space_node.id);
433 if (space_node.flag & SNODE_PIN) {
434 for (const SceneCompositorEffect &effect : scene->compositor_effects) {
435 if (effect.node_group == space_node.nodetree) {
436 return SceneAndCompositorEffect(scene, &effect);
437 }
438 }
439 return std::nullopt;
440 }
441
442 const SceneCompositorEffect *active_effect = bke::compositor::get_active_effect(*scene);
443 if (!active_effect) {
444 return std::nullopt;
445 }
446 return SceneAndCompositorEffect(scene, active_effect);
447}
448
450 bke::ComputeContextCache &compute_context_cache,
451 const ComputeContext *parent_compute_context)
452{
453 const bNode *output_node_ptr = zone.output_node();
454 if (!output_node_ptr) {
455 return nullptr;
456 }
457 const bNode &output_node = *output_node_ptr;
458 switch (output_node.type_legacy) {
460 return &compute_context_cache.for_simulation_zone(parent_compute_context, output_node);
461 }
463 const auto &storage = *static_cast<const NodeGeometryRepeatOutput *>(output_node.storage);
464 return &compute_context_cache.for_repeat_zone(
465 parent_compute_context, output_node, storage.inspection_index);
466 }
468 const auto &storage = *static_cast<const NodeGeometryForeachGeometryElementOutput *>(
469 output_node.storage);
470 return &compute_context_cache.for_foreach_geometry_element_zone(
471 parent_compute_context, output_node, storage.inspection_index);
472 }
473 case NODE_CLOSURE_OUTPUT: {
474 nodes::ClosureSourceLocation source_location{};
475 const bNodeTree &tree = output_node.owner_tree();
476 source_location.tree = &tree;
477 source_location.closure_output_node_id = output_node.identifier;
478 source_location.compute_context_hash = parent_compute_context ?
479 parent_compute_context->hash() :
481 source_location.compute_context = parent_compute_context;
482 return compute_context_for_closure_evaluation(parent_compute_context,
483 output_node.output_socket(0),
484 compute_context_cache,
485 source_location);
486 }
487 }
488 return nullptr;
489}
490
492 bke::ComputeContextCache &compute_context_cache,
493 const ComputeContext *parent_compute_context)
494{
495 const ComputeContext *current = parent_compute_context;
496 for (const bke::bNodeTreeZone *zone : zones) {
497 current = compute_context_for_zone(*zone, compute_context_cache, current);
498 if (!current) {
499 return nullptr;
500 }
501 }
502 return current;
503}
504
505static std::optional<const ComputeContext *> compute_context_for_tree_path(
506 const SpaceNode &snode,
507 bke::ComputeContextCache &compute_context_cache,
508 const ComputeContext *parent_compute_context)
509{
510 const ComputeContext *current = parent_compute_context;
512 for (const bNodeTreePath &item : snode.treepath) {
513 tree_path.append(&item);
514 }
515 if (tree_path.is_empty()) {
516 return current;
517 }
518
519 for (const int i : tree_path.index_range().drop_back(1)) {
520 bNodeTree *tree = tree_path[i]->nodetree;
521 const char *group_node_name = tree_path[i + 1]->node_name;
522 const bNode *group_node = bke::node_find_node_by_name(*tree, group_node_name);
523 if (group_node == nullptr) {
524 return std::nullopt;
525 }
526 const bke::bNodeTreeZones *tree_zones = tree->zones();
527 if (tree_zones == nullptr) {
528 return std::nullopt;
529 }
531 tree_zones->get_zone_by_node(group_node->identifier));
532 current = compute_context_for_zones(zone_stack, compute_context_cache, current);
533 if (!current) {
534 return std::nullopt;
535 }
536 current = &compute_context_cache.for_group_node(current, group_node->identifier, tree);
537 }
538 return current;
539}
540
542 const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
543{
544 if (snode.nodetree->type == NTREE_GEOMETRY) {
547 std::optional<ed::space_node::ObjectAndModifier> object_and_modifier =
549 if (!object_and_modifier) {
550 return nullptr;
551 }
552 const bke::DataBlockComputeContext &object_context = compute_context_cache.for_data_block(
553 nullptr, object_and_modifier->object->id);
554 return &compute_context_cache.for_geometry_nodes_modifier(&object_context,
555 *object_and_modifier->nmd);
556 }
557 case SNODE_GEOMETRY_TOOL: {
558 return &compute_context_cache.for_operator(nullptr);
559 }
560 }
561 return nullptr;
562 }
563 if (snode.nodetree->type == NTREE_COMPOSIT) {
566 std::optional<SceneAndCompositorEffect> scene_and_effect =
568 if (!scene_and_effect) {
569 return nullptr;
570 }
571 const bke::DataBlockComputeContext &scene_context = compute_context_cache.for_data_block(
572 nullptr, scene_and_effect->scene->id);
573 return &compute_context_cache.for_scene_compositor_effect(&scene_context,
574 *scene_and_effect->effect);
575 }
577 return nullptr;
578 }
579 }
580 return nullptr;
581 }
582 if (snode.nodetree->type == NTREE_SHADER) {
583 return &compute_context_cache.for_shader(nullptr, snode.nodetree);
584 }
585 return nullptr;
586}
587
589 const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache)
590{
591 if (!snode.edittree) {
592 return nullptr;
593 }
595 return nullptr;
596 }
597 const ComputeContext *root_context = get_node_editor_root_compute_context(snode,
598 compute_context_cache);
599 if (!root_context) {
600 return nullptr;
601 }
602 const ComputeContext *edittree_context =
603 compute_context_for_tree_path(snode, compute_context_cache, root_context).value_or(nullptr);
604 return edittree_context;
605}
606
608 const SpaceNode &snode,
609 bke::ComputeContextCache &compute_context_cache,
610 const bNodeSocket &socket)
611{
612 const ComputeContext *context = compute_context_for_edittree(snode, compute_context_cache);
613 if (!context) {
614 return nullptr;
615 }
616 const bke::bNodeTreeZones *zones = snode.edittree->zones();
617 if (!zones) {
618 return nullptr;
619 }
620 const bke::bNodeTreeZone *zone = zones->get_zone_by_socket(socket);
622 return compute_context_for_zones(zone_stack, compute_context_cache, context);
623}
624
626 const SpaceNode &snode, bke::ComputeContextCache &compute_context_cache, const bNode &node)
627{
628 const ComputeContext *context = compute_context_for_edittree(snode, compute_context_cache);
629 if (!context) {
630 return nullptr;
631 }
632 const bke::bNodeTreeZones *zones = snode.edittree->zones();
633 if (!zones) {
634 return nullptr;
635 }
636 const bke::bNodeTreeZone *zone = zones->get_zone_by_node(node.identifier);
638 return compute_context_for_zones(zone_stack, compute_context_cache, context);
639}
640
641/* ******************** default callbacks for node space ***************** */
642
643static SpaceLink *node_create(const ScrArea * /*area*/, const Scene * /*scene*/)
644{
645 SpaceNode *snode = MEM_new<SpaceNode>(__func__);
646 snode->runtime = MEM_new<SpaceNode_Runtime>(__func__);
647 snode->spacetype = SPACE_NODE;
648
653
654 /* backdrop */
655 snode->zoom = 1.0f;
656 snode->overlay.passepartout_alpha = 0.5f;
657
658 /* select the first tree type for valid type */
659 for (const bke::bNodeTreeType *treetype : bke::node_tree_types_get()) {
660 STRNCPY_UTF8(snode->tree_idname, treetype->idname.c_str());
661 break;
662 }
663
664 /* header */
665 ARegion *region = BKE_area_region_new();
666
667 BLI_addtail(&snode->regionbase, region);
668 region->regiontype = RGN_TYPE_HEADER;
670
671 /* asset shelf */
672 region = BKE_area_region_new();
673
674 BLI_addtail(&snode->regionbase, region);
676 region->alignment = RGN_ALIGN_BOTTOM;
677 region->flag |= RGN_FLAG_HIDDEN;
678
679 /* asset shelf header */
680 region = BKE_area_region_new();
681
682 BLI_addtail(&snode->regionbase, region);
685
686 /* buttons/list view */
687 region = BKE_area_region_new();
688
689 BLI_addtail(&snode->regionbase, region);
690 region->regiontype = RGN_TYPE_UI;
691 region->alignment = RGN_ALIGN_RIGHT;
692
693 /* toolbar */
694 region = BKE_area_region_new();
695
696 BLI_addtail(&snode->regionbase, region);
697 region->regiontype = RGN_TYPE_TOOLS;
698 region->alignment = RGN_ALIGN_LEFT;
699
700 region->flag = RGN_FLAG_HIDDEN;
701
702 /* main region */
703 region = BKE_area_region_new();
704
705 BLI_addtail(&snode->regionbase, region);
706 region->regiontype = RGN_TYPE_WINDOW;
707
708 region->v2d.tot.xmin = -12.8f * U.widget_unit;
709 region->v2d.tot.ymin = -12.8f * U.widget_unit;
710 region->v2d.tot.xmax = 38.4f * U.widget_unit;
711 region->v2d.tot.ymax = 38.4f * U.widget_unit;
712
713 region->v2d.cur = region->v2d.tot;
714
715 region->v2d.min[0] = 1.0f;
716 region->v2d.min[1] = 1.0f;
717
718 region->v2d.max[0] = 32000.0f;
719 region->v2d.max[1] = 32000.0f;
720
721 region->v2d.minzoom = 0.05f;
722 region->v2d.maxzoom = 2.31f;
723
726 region->v2d.keeptot = eView2D_KeepTot{};
727
728 return reinterpret_cast<SpaceLink *>(snode);
729}
730
731static void node_free(SpaceLink *sl)
732{
733 SpaceNode *snode = reinterpret_cast<SpaceNode *>(sl);
734 snode->treepath.free_no_destruct();
735 MEM_delete(snode->runtime);
736}
737
738/* spacetype; init callback */
739static void node_init(wmWindowManager * /*wm*/, ScrArea * /*area*/) {}
740
742{
743 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
744 free_previews(*wm, *snode);
745}
746
747static bool any_node_uses_id(const bNodeTree *ntree, const ID *id)
748{
749 if (ELEM(nullptr, ntree, id)) {
750 return false;
751 }
752 for (const bNode *node : ntree->all_nodes()) {
753 if (node->id == id) {
754 return true;
755 }
756 }
757 return false;
758}
759
766static void node_area_tag_tree_recalc(SpaceNode * /*snode*/, ScrArea *area)
767{
769}
770
772{
773 ScrArea *area = params->area;
774 const wmNotifier *wmn = params->notifier;
775
776 /* NOTE: #ED_area_tag_refresh will re-execute compositor. */
777 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
778 /* shaderfrom is only used for new shading nodes, otherwise all shaders are from objects */
779 short shader_type = snode->shaderfrom;
780
781 /* preview renders */
782 switch (wmn->category) {
783 case NC_SCENE:
784 switch (wmn->data) {
785 case ND_NODES: {
786 node_area_tag_tree_recalc(snode, area);
787 break;
788 }
789 case ND_FRAME:
790 node_area_tag_tree_recalc(snode, area);
791 break;
792 case ND_COMPO_RESULT: {
793 ED_area_tag_redraw(area);
794 /* Backdrop image offset is calculated during compositing so gizmos need to be updated
795 * afterwards. */
798 break;
799 }
800 }
801 break;
802
803 /* future: add ID checks? */
804 case NC_MATERIAL:
805 if (ED_node_is_shader(snode)) {
806 if (wmn->data == ND_SHADING) {
807 node_area_tag_tree_recalc(snode, area);
808 }
809 else if (wmn->data == ND_SHADING_DRAW) {
810 node_area_tag_tree_recalc(snode, area);
811 }
812 else if (wmn->data == ND_SHADING_LINKS) {
813 node_area_tag_tree_recalc(snode, area);
814 }
815 }
816 break;
817 case NC_TEXTURE:
818 if (ED_node_is_shader(snode) || ED_node_is_texture(snode)) {
819 if (wmn->data == ND_NODES) {
820 node_area_tag_tree_recalc(snode, area);
821 }
822 }
823 break;
824 case NC_WORLD:
825 if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_WORLD) {
826 node_area_tag_tree_recalc(snode, area);
827 }
828 break;
829 case NC_OBJECT:
830 if (ED_node_is_shader(snode)) {
831 if (wmn->data == ND_OB_SHADING) {
832 node_area_tag_tree_recalc(snode, area);
833 }
834 }
835 else if (ED_node_is_geometry(snode)) {
836 if (wmn->data == ND_MODIFIER) {
837 /* Rather strict check: only redraw when the reference matches current editor's ID, */
838 if (wmn->reference == snode->id || snode->id == nullptr) {
839 node_area_tag_tree_recalc(snode, area);
840 }
841 /* Redraw context path or modifier dependent information. */
842 ED_area_tag_redraw(area);
843 }
844 }
845 break;
846 case NC_SPACE:
847 if (wmn->data == ND_SPACE_NODE) {
848 node_area_tag_tree_recalc(snode, area);
849 }
850 else if (wmn->data == ND_SPACE_NODE_VIEW) {
851 ED_area_tag_redraw(area);
852 }
853 break;
854 case NC_NODE:
855 if (wmn->action == NA_EDITED) {
856 if (ELEM(wmn->reference, snode->nodetree, snode->id, nullptr) || snode->id == nullptr) {
857 node_area_tag_tree_recalc(snode, area);
858 }
859 }
860 else if (wmn->action == NA_SELECTED) {
861 ED_area_tag_redraw(area);
862 }
863 break;
864 case NC_SCREEN:
865 switch (wmn->data) {
866 case ND_ANIMPLAY:
868 node_area_tag_tree_recalc(snode, area);
869 break;
870 }
871 break;
872 case NC_MASK:
873 if (wmn->action == NA_EDITED) {
874 if (snode->nodetree && snode->nodetree->type == NTREE_COMPOSIT) {
875 node_area_tag_tree_recalc(snode, area);
876 }
877 }
878 break;
879
880 case NC_IMAGE:
881 if (wmn->action == NA_EDITED) {
882 if (ED_node_is_compositor(snode)) {
883 /* Without this check drawing on an image could become very slow when the compositor is
884 * open. */
885 if (any_node_uses_id(snode->nodetree, static_cast<ID *>(wmn->reference))) {
886 node_area_tag_tree_recalc(snode, area);
887 }
888 }
889
890 ED_area_tag_redraw(area);
891 }
892 break;
893
894 case NC_MOVIECLIP:
895 if (wmn->action == NA_EDITED) {
896 if (ED_node_is_compositor(snode)) {
897 if (any_node_uses_id(snode->nodetree, static_cast<ID *>(wmn->reference))) {
898 node_area_tag_tree_recalc(snode, area);
899 }
900 }
901 }
902 break;
903
904 case NC_LINESTYLE:
905 if (ED_node_is_shader(snode) && shader_type == SNODE_SHADER_LINESTYLE) {
906 node_area_tag_tree_recalc(snode, area);
907 }
908 break;
909 case NC_WM:
910 if (wmn->data == ND_UNDO) {
911 node_area_tag_tree_recalc(snode, area);
912 }
913 break;
914 case NC_GPENCIL:
915 if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
916 ED_area_tag_redraw(area);
917 }
918 break;
919 }
920}
921
922static void node_area_refresh(const bContext *C, ScrArea * /*area*/)
923{
925}
926
928{
929 SpaceNode *snode = reinterpret_cast<SpaceNode *>(sl);
930 SpaceNode *snoden = MEM_dupalloc(snode);
931
932 BLI_duplicatelist(&snoden->treepath, &snode->treepath);
933
934 snoden->runtime = MEM_new<SpaceNode_Runtime>(__func__);
935
936 /* NOTE: no need to set node tree user counts,
937 * the editor only keeps at least 1 (id_us_ensure_real),
938 * which is already done by the original SpaceNode.
939 */
940
941 return reinterpret_cast<SpaceLink *>(snoden);
942}
943
944/* add handlers, stuff you only do once or on area/region changes */
946{
947 wmKeyMap *keymap;
948
949 ED_region_panels_init(wm, region);
950
951 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Node Generic", SPACE_NODE, RGN_TYPE_WINDOW);
953}
954
955static void node_buttons_region_draw(const bContext *C, ARegion *region)
956{
957 ED_region_panels(C, region);
958}
959
960/* add handlers, stuff you only do once or on area/region changes */
962{
963 wmKeyMap *keymap;
964
965 ED_region_panels_init(wm, region);
966
967 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Node Generic", SPACE_NODE, RGN_TYPE_WINDOW);
969}
970
971static void node_toolbar_region_draw(const bContext *C, ARegion *region)
972{
973 ED_region_panels(C, region);
974}
975
976static void node_cursor(wmWindow *win, ScrArea *area, ARegion *region)
977{
978 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
979
980 /* convert mouse coordinates to v2d space */
982 win->runtime->eventstate->xy[0] - region->winrct.xmin,
983 win->runtime->eventstate->xy[1] - region->winrct.ymin,
984 &snode->runtime->cursor[0],
985 &snode->runtime->cursor[1]);
986
987 /* here snode->runtime->cursor is used to detect the node edge for sizing */
988 node_set_cursor(*win, *region, *snode, snode->runtime->cursor);
989
990 /* XXX snode->runtime->cursor is in placing new nodes space */
991 snode->runtime->cursor[0] /= UI_SCALE_FAC;
992 snode->runtime->cursor[1] /= UI_SCALE_FAC;
993}
994
995/* Initialize main region, setting handlers. */
997{
998 wmKeyMap *keymap;
999 ListBaseT<wmDropBox> *lb;
1000
1001 view2d_region_reinit(&region->v2d, ui::V2D_COMMONVIEW_CUSTOM, region->winx, region->winy);
1002
1003 /* own keymaps */
1004 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Node Generic", SPACE_NODE, RGN_TYPE_WINDOW);
1005 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
1006
1007 keymap = WM_keymap_ensure(wm->runtime->defaultconf, "Node Editor", SPACE_NODE, RGN_TYPE_WINDOW);
1009
1010 /* add drop boxes */
1011 lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW);
1012
1014
1015 /* The backdrop image gizmo needs to change together with the view. So always refresh gizmos on
1016 * region size changes. */
1018}
1019
1020static void node_main_region_draw(const bContext *C, ARegion *region)
1021{
1022 node_draw_space(*C, *region);
1023}
1024
1025/* ************* dropboxes ************* */
1026
1027static bool node_group_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1028{
1029 SpaceNode *snode = CTX_wm_space_node(C);
1030
1031 if (snode == nullptr) {
1032 return false;
1033 }
1034
1035 if (snode->edittree == nullptr) {
1036 return false;
1037 }
1038
1039 if (!WM_drag_is_ID_type(drag, ID_NT)) {
1040 return false;
1041 }
1042
1043 if (drag->type == WM_DRAG_ID) {
1044 const bNodeTree *node_tree = reinterpret_cast<const bNodeTree *>(
1046 if (!node_tree) {
1047 return false;
1048 }
1049 return node_tree->type == snode->edittree->type;
1050 }
1051
1052 if (drag->type == WM_DRAG_ASSET) {
1053 const wmDragAsset *asset_data = WM_drag_get_asset_data(drag, ID_NT);
1054 if (!asset_data) {
1055 return false;
1056 }
1057 const AssetMetaData *metadata = &asset_data->asset->get_metadata();
1058 const IDProperty *tree_type = BKE_asset_metadata_idprop_find(metadata, "type");
1059 if (!tree_type || IDP_int_get(tree_type) != snode->edittree->type) {
1060 return false;
1061 }
1062 }
1063
1064 return true;
1065}
1066
1067static bool node_object_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1068{
1070}
1071
1072static bool node_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1073{
1075}
1076
1077static bool node_id_im_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
1078{
1079 return WM_drag_is_ID_type(drag, ID_IM);
1080}
1081
1082static bool node_mask_drop_poll(bContext * /*C*/, wmDrag *drag, const wmEvent * /*event*/)
1083{
1084 return WM_drag_is_ID_type(drag, ID_MSK);
1085}
1086
1087static bool node_material_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1088{
1090}
1091
1092static bool node_color_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1093{
1094 return (drag->type == WM_DRAG_COLOR) && !ui::button_active_drop_color(C);
1095}
1096
1097static bool node_import_file_drop_poll(bContext *C, wmDrag *drag, const wmEvent * /*event*/)
1098{
1099 SpaceNode *snode = CTX_wm_space_node(C);
1100 if (!snode) {
1101 return false;
1102 }
1103 if (!snode->edittree) {
1104 return false;
1105 }
1107 return false;
1108 }
1109 if (drag->type != WM_DRAG_PATH) {
1110 return false;
1111 }
1112 const bool is_geometry_tree = snode->edittree->type == NTREE_GEOMETRY;
1113 const Span<std::string> paths = WM_drag_get_paths(drag);
1114 for (const StringRef path : paths) {
1115 if (path.endswith(".txt")) {
1116 return true;
1117 }
1118 if (is_geometry_tree &&
1119 (path.endswith(".csv") || path.endswith(".obj") || path.endswith(".ply") ||
1120 path.endswith(".stl") || path.endswith(".vdb") || path.endswith(".spz")))
1121 {
1122 return true;
1123 }
1124 }
1125 return false;
1126}
1127
1129 wmDrag *drag,
1130 const wmEvent * /*event*/)
1131{
1132 if (drag->type != WM_DRAG_NODE_TREE_INTERFACE) {
1133 return false;
1134 }
1135 SpaceNode *snode = CTX_wm_space_node(C);
1136 if (!snode || !snode->edittree) {
1137 return false;
1138 }
1139 const bNodeTree *target_ntree = snode->edittree;
1140
1141 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1142 drag->poin);
1143
1144 /* Drag only onto node editors of the same node tree. */
1145 const bNodeTree *source_ntree = drag_data->tree;
1146 if (target_ntree != source_ntree) {
1147 return false;
1148 }
1149
1150 return true;
1151}
1152
1154{
1155 return !(event->modifier & KM_CTRL) && node_interface_item_drop_poll_base(C, drag, event);
1156}
1157
1159{
1160 return event->modifier & KM_CTRL && node_interface_item_drop_poll_base(C, drag, event);
1161}
1162
1164{
1166 if (id) {
1167 RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
1168 }
1169
1170 RNA_boolean_set(drop->ptr, "show_datablock_in_node", (drag->type != WM_DRAG_ASSET));
1171}
1172
1173static void node_id_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
1174{
1176 if (id) {
1177 RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
1178 }
1179}
1180
1182{
1184 if (id) {
1185 RNA_int_set(drop->ptr, "session_uid", int(id->session_uid));
1186 RNA_struct_property_unset(drop->ptr, "filepath");
1187 return;
1188 }
1189}
1190
1191static void node_import_file_drop_copy(bContext * /*C*/, wmDrag *drag, wmDropBox *drop)
1192{
1194}
1195
1197 wmDrag * /*drag*/,
1198 wmDropBox *drop)
1199{
1200 RNA_boolean_set(drop->ptr, "only_selected_sockets", true);
1201 RNA_boolean_set(drop->ptr, "all_panel_contents", false);
1202}
1203
1204static void node_interface_item_drop_copy_all(bContext * /*C*/, wmDrag * /*drag*/, wmDropBox *drop)
1205{
1206 RNA_boolean_set(drop->ptr, "only_selected_sockets", true);
1207 RNA_boolean_set(drop->ptr, "all_panel_contents", true);
1208}
1209
1211 wmDrag *drag,
1212 const int /*xy*/[2],
1213 wmDropBox * /*drop*/)
1214{
1215 auto *drag_data = static_cast<bke::node_interface::bNodeTreeInterfaceItemReference *>(
1216 drag->poin);
1217 bool has_selected_header_toggle = false;
1218
1219 for (int i = 0; i < drag_data->items_count; i++) {
1220 const bNodeTreeInterfaceItem *item = drag_data->items[i];
1221 if (const auto *panel = bke::node_interface::get_item_as<bNodeTreeInterfacePanel>(item)) {
1222 if (panel->header_toggle_socket()) {
1223 has_selected_header_toggle = true;
1224 break;
1225 }
1226 }
1227 }
1228
1229 if (has_selected_header_toggle) {
1230 return TIP_("Add Group Input (hold Ctrl to include sockets under panel toggle)");
1231 }
1232 return TIP_("Add Group Input");
1233}
1234
1236 wmDrag * /*drag*/,
1237 const int /*xy*/[2],
1238 wmDropBox * /*drop*/)
1239{
1240 return TIP_("Add Group Input");
1241}
1242
1243/* this region dropbox definition */
1244static void node_dropboxes()
1245{
1246 ListBaseT<wmDropBox> *lb = WM_dropboxmap_find("Node Editor", SPACE_NODE, RGN_TYPE_WINDOW);
1247
1248 WM_dropbox_add(lb,
1249 "NODE_OT_add_object",
1253 nullptr);
1254 WM_dropbox_add(lb,
1255 "NODE_OT_add_collection",
1259 nullptr);
1260 WM_dropbox_add(lb,
1261 "NODE_OT_add_group",
1265 nullptr);
1266 WM_dropbox_add(lb,
1267 "NODE_OT_add_image",
1271 nullptr);
1272 WM_dropbox_add(lb,
1273 "NODE_OT_add_mask",
1277 nullptr);
1278 WM_dropbox_add(lb,
1279 "NODE_OT_add_material",
1283 nullptr);
1285 lb, "NODE_OT_add_color", node_color_drop_poll, ui::drop_color_copy, nullptr, nullptr);
1286 WM_dropbox_add(lb,
1287 "NODE_OT_add_import_node",
1290 nullptr,
1291 nullptr);
1292 WM_dropbox_add(lb,
1293 "NODE_OT_add_group_input_node",
1296 nullptr,
1298 WM_dropbox_add(lb,
1299 "NODE_OT_add_group_input_node",
1302 nullptr,
1304}
1305
1306/* ************* end drop *********** */
1307
1308/* add handlers, stuff you only do once or on area/region changes */
1310{
1311 ED_region_header_init(region);
1312}
1313
1314static void node_header_region_draw(const bContext *C, ARegion *region)
1315{
1316 /* find and set the context */
1318
1319 ED_region_header(C, region);
1320}
1321
1322/* used for header + main region */
1324{
1325 ARegion *region = params->region;
1326 const wmNotifier *wmn = params->notifier;
1327 wmGizmoMap *gzmap = region->runtime->gizmo_map;
1328
1329 /* context changes */
1330 switch (wmn->category) {
1331 case NC_SPACE:
1332 switch (wmn->data) {
1333 case ND_SPACE_NODE:
1334 ED_region_tag_redraw(region);
1335 break;
1336 case ND_SPACE_NODE_VIEW:
1338 break;
1339 }
1340 break;
1341 case NC_ANIMATION:
1342 if (wmn->data == ND_NLA_ACTCHANGE) {
1343 ED_region_tag_redraw(region);
1344 }
1345 break;
1346 case NC_SCREEN:
1347 if (wmn->data == ND_LAYOUTSET || wmn->action == NA_EDITED) {
1349 }
1350 switch (wmn->data) {
1351 case ND_ANIMPLAY:
1352 case ND_LAYER:
1353 ED_region_tag_redraw(region);
1354 break;
1355 }
1356 break;
1357 case NC_WM:
1358 if (wmn->data == ND_JOB) {
1359 ED_region_tag_redraw(region);
1360 }
1361 break;
1362 case NC_SCENE:
1363 ED_region_tag_redraw(region);
1364 if (wmn->data == ND_RENDER_RESULT) {
1366 }
1367 break;
1368 case NC_NODE:
1369 ED_region_tag_redraw(region);
1370 if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
1372 }
1373 break;
1374 case NC_MATERIAL:
1375 case NC_TEXTURE:
1376 case NC_WORLD:
1377 case NC_LINESTYLE:
1378 ED_region_tag_redraw(region);
1379 break;
1380 case NC_OBJECT:
1381 if (ELEM(wmn->data, ND_OB_SHADING, ND_TRANSFORM)) {
1382 ED_region_tag_redraw(region);
1383 }
1384 break;
1385 case NC_ID:
1386 if (ELEM(wmn->action, NA_RENAME, NA_EDITED)) {
1387 ED_region_tag_redraw(region);
1388 }
1389 break;
1390 case NC_GPENCIL:
1391 if (wmn->action == NA_EDITED) {
1392 ED_region_tag_redraw(region);
1393 }
1394 else if (wmn->data & ND_GPENCIL_EDITMODE) {
1395 ED_region_tag_redraw(region);
1396 }
1397 break;
1398 case NC_VIEWER_PATH:
1399 ED_region_tag_redraw(region);
1400 break;
1401 }
1402}
1403
1404} // namespace ed::space_node
1405
1406/* Outside of blender namespace to avoid Python documentation build error with `ctypes`. */
1407extern "C" {
1408const char *node_context_dir[] = {
1409 "selected_nodes", "active_node", "light", "material", "world", nullptr};
1410};
1411
1412namespace ed::space_node {
1413
1414static int /*eContextResult*/ node_context(const bContext *C,
1415 const char *member,
1417{
1418 SpaceNode *snode = CTX_wm_space_node(C);
1419
1420 if (CTX_data_dir(member)) {
1422 return CTX_RESULT_OK;
1423 }
1424 if (CTX_data_equals(member, "selected_nodes")) {
1425 if (snode->edittree) {
1426 for (bNode *node : snode->edittree->all_nodes()) {
1427 if (node->is_selected()) {
1428 PointerRNA ptr = RNA_pointer_create_id_subdata(snode->edittree->id, RNA_Node, node);
1430 }
1431 }
1432 }
1434 return CTX_RESULT_OK;
1435 }
1436 if (CTX_data_equals(member, "active_node")) {
1437 if (snode->edittree) {
1439 PointerRNA ptr = RNA_pointer_create_id_subdata(snode->edittree->id, RNA_Node, node);
1441 }
1442
1444 return CTX_RESULT_OK;
1445 }
1446 if (CTX_data_equals(member, "material")) {
1447 if (snode->id && GS(snode->id->name) == ID_MA) {
1449 }
1450 return CTX_RESULT_OK;
1451 }
1452 if (CTX_data_equals(member, "light")) {
1453 if (snode->id && GS(snode->id->name) == ID_LA) {
1455 }
1456 return CTX_RESULT_OK;
1457 }
1458 if (CTX_data_equals(member, "world")) {
1459 if (snode->id && GS(snode->id->name) == ID_WO) {
1461 }
1462 return CTX_RESULT_OK;
1463 }
1464 if (CTX_data_equals(member, "edit_image")) {
1465 if (snode->edittree != nullptr) {
1466 if (bNode *node = bke::node_get_active(*snode->edittree)) {
1467 if (ELEM(node->type_legacy, SH_NODE_TEX_IMAGE, SH_NODE_TEX_ENVIRONMENT)) {
1468 if (Image *image = id_cast<Image *>(node->id)) {
1470 return CTX_RESULT_OK;
1471 }
1472 }
1473 }
1474 }
1475 }
1477}
1478
1496
1497static void node_id_remap(ID *old_id, ID *new_id, SpaceNode *snode)
1498{
1499 if (snode->id == old_id) {
1500 /* nasty DNA logic for SpaceNode:
1501 * ideally should be handled by editor code, but would be bad level call
1502 */
1503 snode->treepath.free_no_destruct();
1504
1505 /* XXX Untested in case new_id != nullptr... */
1506 snode->id = new_id;
1507 snode->from = nullptr;
1508 snode->nodetree = nullptr;
1509 snode->edittree = nullptr;
1510 }
1511 else if (GS(old_id->name) == ID_OB) {
1512 if (snode->from == old_id) {
1513 if (new_id == nullptr) {
1514 snode->flag &= ~SNODE_PIN;
1515 }
1516 snode->from = new_id;
1517 }
1518 }
1519 else if (GS(old_id->name) == ID_GD_LEGACY) {
1520 if (id_cast<ID *>(snode->gpd) == old_id) {
1521 snode->gpd = id_cast<bGPdata *>(new_id);
1522 id_us_min(old_id);
1523 id_us_plus(new_id);
1524 }
1525 }
1526 else if (GS(old_id->name) == ID_NT) {
1527
1528 if (snode->selected_node_group) {
1529 if (&snode->selected_node_group->id == old_id) {
1530 snode->selected_node_group = reinterpret_cast<bNodeTree *>(new_id);
1531 }
1532 }
1533
1534 bNodeTreePath *path, *path_next;
1535
1536 for (path = snode->treepath.first(); path; path = path->next) {
1537 if (id_cast<ID *>(path->nodetree) == old_id) {
1538 path->nodetree = id_cast<bNodeTree *>(new_id);
1539 id_us_ensure_real(new_id);
1540 }
1541 if (path == snode->treepath.first_) {
1542 /* first nodetree in path is same as snode->nodetree */
1543 snode->nodetree = path->nodetree;
1544 }
1545 if (path->nodetree == nullptr) {
1546 break;
1547 }
1548 }
1549
1550 /* remaining path entries are invalid, remove */
1551 for (; path; path = path_next) {
1552 path_next = path->next;
1553
1554 BLI_remlink(&snode->treepath, path);
1555 MEM_delete(path);
1556 }
1557
1558 /* edittree is just the last in the path,
1559 * set this directly since the path may have been shortened above */
1560 if (snode->treepath.last()) {
1561 path = snode->treepath.last();
1562 snode->edittree = path->nodetree;
1564 }
1565 else {
1566 snode->edittree = nullptr;
1567 }
1568 }
1569}
1570
1571static void node_id_remap(ScrArea * /*area*/,
1572 SpaceLink *slink,
1573 const bke::id::IDRemapper &mappings)
1574{
1575 /* Although we should be able to perform all the mappings in a single go this lead to issues when
1576 * running the python test cases. Somehow the nodetree/edittree weren't updated to the new
1577 * pointers that generated a SEGFAULT.
1578 *
1579 * To move forward we should perhaps remove snode->edittree and snode->nodetree as they are just
1580 * copies of pointers. All usages should be calling a function that will receive the appropriate
1581 * instance.
1582 *
1583 * We could also move a remap address at a time to use the IDRemapper as that should get closer
1584 * to cleaner code. See {D13615} for more information about this topic.
1585 */
1586 mappings.iter([&](ID *old_id, ID *new_id) {
1587 node_id_remap(old_id, new_id, reinterpret_cast<SpaceNode *>(slink));
1588 });
1589}
1590
1592{
1593 SpaceNode *snode = reinterpret_cast<SpaceNode *>(space_link);
1594 const int data_flags = BKE_lib_query_foreachid_process_flags_get(data);
1595 const bool is_readonly = (data_flags & IDWALK_READONLY) != 0;
1596 const bool allow_pointer_access = (data_flags & IDWALK_NO_ORIG_POINTERS_ACCESS) == 0;
1597 bool is_embedded_nodetree = snode->id != nullptr && allow_pointer_access &&
1598 bke::node_tree_from_id(snode->id) == snode->nodetree;
1599
1602
1603 bNodeTreePath *path = snode->treepath.first();
1604 BLI_assert(path == nullptr || path->nodetree == snode->nodetree);
1605
1606 if (is_embedded_nodetree) {
1608 if (path != nullptr) {
1610 }
1611
1612 /* Embedded ID pointers are not remapped (besides exceptions), ensure it still matches
1613 * actual data. Note that `snode->id` was already processed (and therefore potentially
1614 * remapped) above. */
1615 if (!is_readonly) {
1616 snode->nodetree = (snode->id == nullptr) ? nullptr : bke::node_tree_from_id(snode->id);
1617 if (path != nullptr) {
1618 path->nodetree = snode->nodetree;
1619 }
1620 }
1621 }
1622 else {
1625 if (path != nullptr) {
1628 }
1629 }
1630
1633
1634 /* Both `snode->id` and `snode->nodetree` have been remapped now, so their data can be
1635 * accessed. */
1636 BLI_assert(snode->id == nullptr || snode->nodetree == nullptr ||
1637 (snode->nodetree->id.flag & ID_FLAG_EMBEDDED_DATA) == 0 ||
1638 snode->nodetree == bke::node_tree_from_id(snode->id));
1639
1640 /* This is mainly here for readfile case ('lib_link' process), as in such case there is no access
1641 * to original data allowed, so no way to know whether the SpaceNode nodetree pointer is an
1642 * embedded one or not. */
1643 if (!is_readonly && snode->id && !snode->nodetree) {
1644 is_embedded_nodetree = true;
1645 snode->nodetree = bke::node_tree_from_id(snode->id);
1646 if (path != nullptr) {
1647 path->nodetree = snode->nodetree;
1648 }
1649 }
1650
1651 if (path != nullptr) {
1652 for (path = path->next; path != nullptr; path = path->next) {
1653 BLI_assert(path->nodetree != nullptr);
1654 if (allow_pointer_access) {
1656 }
1657
1660
1661 if (path->nodetree == nullptr) {
1662 BLI_assert(!is_readonly);
1663 /* Remaining path entries are invalid, remove them. */
1664 for (bNodeTreePath *path_next; path; path = path_next) {
1665 path_next = path->next;
1666 BLI_remlink(&snode->treepath, path);
1667 MEM_delete(path);
1668 }
1669 break;
1670 }
1671 }
1672 }
1673 BLI_assert(path == nullptr);
1674
1675 if (!is_readonly) {
1676 /* `edittree` is just the last in the path, set this directly since the path may have
1677 * been shortened above. */
1678 if (snode->treepath.last() != nullptr) {
1679 path = snode->treepath.last();
1680 snode->edittree = path->nodetree;
1681 }
1682 else {
1683 snode->edittree = nullptr;
1684 }
1685 }
1686 else {
1687 /* Only process this pointer in readonly case, otherwise could lead to a bad
1688 * double-remapping e.g. */
1689 if (is_embedded_nodetree && snode->edittree == snode->nodetree) {
1691 }
1692 else {
1694 }
1695 }
1696}
1697
1699{
1700 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
1702}
1703
1704static void node_space_subtype_set(ScrArea *area, int value)
1705{
1706 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
1708}
1709
1711{
1712 bool free;
1714 RNA_enum_items_add(item, totitem, item_src);
1715 if (free) {
1716 MEM_delete(item_src);
1717 }
1718}
1719
1721{
1722 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
1724 if (tree_type == nullptr) {
1725 return IFACE_("Node Editor");
1726 }
1727 return tree_type->ui_name;
1728}
1729
1730static int node_space_icon_get(const ScrArea *area)
1731{
1732 SpaceNode *snode = area->spacedata.first_as<SpaceNode>();
1734 if (tree_type == nullptr) {
1735 return ICON_NODETREE;
1736 }
1737 return tree_type->ui_icon;
1738}
1739
1741{
1742 SpaceNode *snode = reinterpret_cast<SpaceNode *>(sl);
1743
1744 if (snode->gpd) {
1745 BLO_read_struct(reader, bGPdata, &snode->gpd);
1746 BKE_annotations_blend_read_data(reader, snode->gpd);
1747 }
1748
1750 snode->edittree = nullptr;
1751 snode->runtime = MEM_new<SpaceNode_Runtime>(__func__);
1752}
1753
1755{
1756 SpaceNode *snode = reinterpret_cast<SpaceNode *>(sl);
1757 writer->write_struct_cast<SpaceNode>(snode, [](BlendStructWriter<SpaceNode> &struct_writer) {
1758 struct_writer.shallow_data.runtime = nullptr;
1759 });
1760
1761 for (bNodeTreePath &path : snode->treepath) {
1762 writer->write_struct(&path);
1763 }
1764}
1765
1767{
1768 using namespace blender::ed;
1769 wmKeyMap *keymap = WM_keymap_ensure(
1770 wm->runtime->defaultconf, "Node Generic", SPACE_NODE, RGN_TYPE_WINDOW);
1771 WM_event_add_keymap_handler(&region->runtime->handlers, keymap);
1772
1774}
1775
1776} // namespace ed::space_node
1777
1779{
1780 using namespace blender::ed;
1781 using namespace blender::ed::space_node;
1782
1783 std::unique_ptr<SpaceType> st = std::make_unique<SpaceType>();
1784 ARegionType *art;
1785
1786 st->spaceid = SPACE_NODE;
1787 STRNCPY_UTF8(st->name, "Node");
1788 st->struct_size = sizeof(SpaceNode);
1789
1790 st->create = node_create;
1791 st->free = node_free;
1792 st->init = node_init;
1793 st->exit = node_exit;
1794 st->duplicate = node_duplicate;
1795 st->operatortypes = node_operatortypes;
1796 st->keymap = node_keymap;
1797 st->listener = node_area_listener;
1798 st->refresh = node_area_refresh;
1799 st->context = node_context;
1800 st->dropboxes = node_dropboxes;
1801 st->gizmos = node_widgets;
1802 st->id_remap = node_id_remap;
1803 st->foreach_id = node_foreach_id;
1804 st->space_subtype_item_extend = node_space_subtype_item_extend;
1805 st->space_subtype_get = node_space_subtype_get;
1806 st->space_subtype_set = node_space_subtype_set;
1807 st->space_name_get = node_space_name_get;
1808 st->space_icon_get = node_space_icon_get;
1809 st->blend_read_data = node_space_blend_read_data;
1810 st->blend_read_after_liblink = nullptr;
1811 st->blend_write = node_space_blend_write;
1812
1813 /* regions: main window */
1814 art = MEM_new_zeroed<ARegionType>("spacetype node region");
1821 art->cursor = node_cursor;
1822 art->event_cursor = true;
1823 art->clip_gizmo_events_by_ui = true;
1825
1826 BLI_addhead(&st->regiontypes, art);
1827
1828 /* regions: header */
1829 art = MEM_new_zeroed<ARegionType>("spacetype node region");
1831 art->prefsizey = HEADERY;
1836
1837 BLI_addhead(&st->regiontypes, art);
1838
1839 /* regions: asset shelf */
1840 art = MEM_new_zeroed<ARegionType>("spacetype node asset shelf region");
1855 BLI_addhead(&st->regiontypes, art);
1856
1857 /* regions: asset shelf header */
1858 art = MEM_new_zeroed<ARegionType>("spacetype node asset shelf header region");
1866 BLI_addhead(&st->regiontypes, art);
1868
1869 /* regions: list-view/buttons */
1870 art = MEM_new_zeroed<ARegionType>("spacetype node region");
1871 art->regionid = RGN_TYPE_UI;
1880 BLI_addhead(&st->regiontypes, art);
1881
1883
1884 /* regions: toolbar */
1885 art = MEM_new_zeroed<ARegionType>("spacetype view3d tools region");
1886 art->regionid = RGN_TYPE_TOOLS;
1887 art->prefsizex = int(UI_TOOLBAR_WIDTH);
1888 art->prefsizey = 50; /* XXX */
1895 BLI_addhead(&st->regiontypes, art);
1896
1897 WM_menutype_add(MEM_new<MenuType>(__func__, catalog_assets_menu_type()));
1898 WM_menutype_add(MEM_new<MenuType>(__func__, unassigned_assets_menu_type()));
1899 WM_menutype_add(MEM_new<MenuType>(__func__, add_root_catalogs_menu_type()));
1900 WM_menutype_add(MEM_new<MenuType>(__func__, swap_root_catalogs_menu_type()));
1901
1902 BKE_spacetype_register(std::move(st));
1903}
1904
1905} // namespace blender
Main runtime representation of an asset.
#define IDP_int_get(prop)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
#define SH_NODE_TEX_IMAGE
#define SH_NODE_TEX_ENVIRONMENT
#define GEO_NODE_FOREACH_GEOMETRY_ELEMENT_OUTPUT
#define GEO_NODE_SIMULATION_OUTPUT
#define NODE_CLOSURE_OUTPUT
#define GEO_NODE_REPEAT_OUTPUT
#define STRNCPY_UTF8(dst, src)
#define BLO_read_struct_list(reader, struct_name, list)
#define BLO_read_struct(reader, struct_name, ptr_p)
#define TIP_(msgid)
#define IFACE_(msgid)
ID and Library types, which are fundamental for SDNA.
Object is a sort of wrapper for general info.
#define HEADERY
#define UI_SCALE_FAC
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_SIDEBAR_PANEL_WIDTH
#define UI_TOOLBAR_WIDTH
#define NC_WORLD
Definition WM_types.hh:400
#define ND_ANIMATION_PLAYBACK
Definition WM_types.hh:448
#define ND_SHADING
Definition WM_types.hh:520
#define NC_ID
Definition WM_types.hh:408
#define NC_NODE
Definition WM_types.hh:407
#define ND_NLA_ACTCHANGE
Definition WM_types.hh:541
#define ND_RENDER_RESULT
Definition WM_types.hh:465
#define ND_JOB
Definition WM_types.hh:432
#define NC_WM
Definition WM_types.hh:387
#define ND_GPENCIL_EDITMODE
Definition WM_types.hh:547
#define NC_LINESTYLE
Definition WM_types.hh:413
#define NC_ANIMATION
Definition WM_types.hh:401
#define NC_VIEWER_PATH
Definition WM_types.hh:419
#define ND_SPACE_NODE
Definition WM_types.hh:569
#define ND_COMPO_RESULT
Definition WM_types.hh:466
#define NC_SCREEN
Definition WM_types.hh:390
#define NC_MOVIECLIP
Definition WM_types.hh:410
#define ND_ANIMPLAY
Definition WM_types.hh:441
#define NC_SCENE
Definition WM_types.hh:391
#define ND_SPACE_NODE_VIEW
Definition WM_types.hh:579
#define ND_NODES
Definition WM_types.hh:455
#define ND_MODIFIER
Definition WM_types.hh:503
#define NA_EDITED
Definition WM_types.hh:634
#define NC_MATERIAL
Definition WM_types.hh:393
#define NC_IMAGE
Definition WM_types.hh:397
#define ND_UNDO
Definition WM_types.hh:433
#define ND_FRAME
Definition WM_types.hh:453
#define NC_GPENCIL
Definition WM_types.hh:412
#define NC_TEXTURE
Definition WM_types.hh:394
#define ND_TRANSFORM
Definition WM_types.hh:475
#define ND_LAYER
Definition WM_types.hh:469
#define NC_MASK
Definition WM_types.hh:411
#define NA_RENAME
Definition WM_types.hh:638
#define ND_OB_SHADING
Definition WM_types.hh:476
#define ND_LAYOUTSET
Definition WM_types.hh:443
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_SHADING_LINKS
Definition WM_types.hh:522
#define ND_SHADING_DRAW
Definition WM_types.hh:521
#define NC_SPACE
Definition WM_types.hh:405
#define NA_SELECTED
Definition WM_types.hh:639
#define ELEM(...)
const ComputeContextHash & hash() const
constexpr IndexRange drop_back(int64_t n) const
void clear()
Definition BLI_map.hh:1038
bool contains(const Key &key) const
void append(const T &value)
bool is_empty() const
IndexRange index_range() const
const GeometryNodesModifierComputeContext & for_geometry_nodes_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 DataBlockComputeContext & for_data_block(const ComputeContext *parent, const uint32_t orig_session_uid, const ID *id=nullptr)
const ShaderComputeContext & for_shader(const ComputeContext *parent, const bNodeTree *tree)
const OperatorComputeContext & for_operator(const ComputeContext *parent)
const SimulationZoneComputeContext & for_simulation_zone(const ComputeContext *parent, int output_node_id)
const SceneCompositorEffectComputeContext & for_scene_compositor_effect(const ComputeContext *parent, const SceneCompositorEffect &effect)
const bNode * output_node() const
Vector< const bNodeTreeZone * > get_zones_to_enter_from_root(const bNodeTreeZone *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
#define storage(slot, qualifiers)
float length(VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
SceneCompositorEffect * get_active_effect(const Scene &scene)
T & get_item_as(bNodeTreeInterfaceItem &item)
void free(Subdiv *subdiv)
Definition subdiv.cc:192
bNode * node_find_node_by_name(bNodeTree &ntree, StringRefNull name)
Definition node.cc:4047
bNodeTreeType * node_tree_type_find(StringRef idname)
Definition node.cc:2797
bNode * node_get_active(bNodeTree &ntree)
Definition node.cc:5445
const bNodeInstanceKey NODE_INSTANCE_KEY_BASE
Definition node.cc:5600
bNodeInstanceKey node_instance_key(bNodeInstanceKey parent_key, const bNodeTree *ntree, const bNode *node)
Definition node.cc:5621
Span< bNodeTreeType * > node_tree_types_get()
Definition node.cc:2878
bNodeTree * node_tree_from_id(ID *id)
Definition node.cc:5337
void header_region(const bContext *C, ARegion *region)
void region_init(wmWindowManager *wm, ARegion *region)
void types_register(ARegionType *region_type, const int space_type)
void region_listen(const wmRegionListenerParams *params)
void region_on_poll_success(const bContext *C, ARegion *region)
void header_region_listen(const wmRegionListenerParams *params)
void region_on_user_resize(const ARegion *region)
int context(const bContext *C, const char *member, bContextDataResult *result)
int region_snap(const ARegion *region, int size, int axis)
void * region_duplicate(void *regiondata)
bool regions_poll(const RegionPollParams *params)
void header_region_init(wmWindowManager *wm, ARegion *region)
void region_draw(const bContext *C, ARegion *region)
void region_message_subscribe(const wmRegionMessageSubscribeParams *params)
void region_layout(const bContext *C, ARegion *region)
void region_free(ARegion *region)
void paths_to_operator_properties(PointerRNA *ptr, const Span< std::string > paths)
Definition io_utils.cc:121
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 std::optional< SceneAndCompositorEffect > get_scene_compositor_effect_for_node_editor(const SpaceNode &space_node)
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 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 std::string node_interface_item_drop_tooltip_single(bContext *, wmDrag *drag, const int[2], wmDropBox *)
static void node_group_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
Object * get_space_editor_object(const bContext *C)
std::optional< ObjectAndModifier > get_geometry_nodes_modifier_for_node_editor(const SpaceNode &snode)
static void node_header_region_draw(const bContext *C, ARegion *region)
static void node_area_refresh(const bContext *C, ScrArea *)
static void node_asset_shelf_region_init(wmWindowManager *wm, ARegion *region)
MenuType swap_root_catalogs_menu_type()
static void node_foreach_id(SpaceLink *space_link, LibraryForeachIDData *data)
void free_previews(wmWindowManager &wm, SpaceNode &snode)
static StringRefNull node_space_name_get(const ScrArea *area)
static SpaceLink * node_duplicate(SpaceLink *sl)
static void node_main_region_init(wmWindowManager *wm, ARegion *region)
static void node_id_remap(ID *old_id, ID *new_id, SpaceNode *snode)
static bool node_interface_item_drop_poll_base(bContext *C, wmDrag *drag, const wmEvent *)
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)
void NODE_GGT_backdrop_split(wmGizmoGroupType *gzgt)
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)
void node_tree_interface_panel_register(ARegionType *art)
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 void node_interface_item_drop_copy_all(bContext *, wmDrag *, wmDropBox *drop)
static bool node_mask_drop_poll(bContext *, wmDrag *drag, const wmEvent *)
static std::string node_interface_item_drop_tooltip_all(bContext *, wmDrag *, const int[2], wmDropBox *)
static int node_space_subtype_get(ScrArea *area)
void NODE_GGT_backdrop_crop(wmGizmoGroupType *gzgt)
Definition node_gizmo.cc:65
static bool node_group_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
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)
Definition node_gizmo.cc:85
static void node_free(SpaceLink *sl)
static bool node_collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *)
static void node_interface_item_drop_copy_single(bContext *, wmDrag *, wmDropBox *drop)
static void node_dropboxes()
void NODE_GGT_backdrop_transform(wmGizmoGroupType *gzgt)
Definition node_gizmo.cc:46
void snode_set_context(const bContext &C)
Definition node_edit.cc:191
static void node_area_listener(const wmSpaceTypeListenerParams *params)
static void node_id_im_drop_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
void NODE_GGT_compositor_translate(wmGizmoGroupType *gzgt)
static bool node_interface_item_drop_poll_single(bContext *C, wmDrag *drag, const wmEvent *event)
void node_keymap(wmKeyConfig *keyconf)
Definition node_ops.cc:133
const ComputeContext * compute_context_for_zones(const Span< const bke::bNodeTreeZone * > zones, bke::ComputeContextCache &compute_context_cache, const ComputeContext *parent_compute_context)
void NODE_GGT_backdrop_ellipse_mask(wmGizmoGroupType *gzgt)
static void node_init(wmWindowManager *, ScrArea *)
static int node_context(const bContext *C, const char *member, bContextDataResult *result)
static void node_area_tag_tree_recalc(SpaceNode *, ScrArea *area)
void NODE_GGT_compositor_transform(wmGizmoGroupType *gzgt)
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_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)
void NODE_GGT_compositor_scale(wmGizmoGroupType *gzgt)
static bool any_node_uses_id(const bNodeTree *ntree, const ID *id)
void NODE_GGT_backdrop_glare(wmGizmoGroupType *gzgt)
static bool node_interface_item_drop_poll_all(bContext *C, wmDrag *drag, const wmEvent *event)
static void node_buttons_region_init(wmWindowManager *wm, ARegion *region)
static void node_space_blend_write(BlendWriter *writer, SpaceLink *sl)
static SpaceLink * node_create(const ScrArea *, const Scene *)
static void node_space_subtype_set(ScrArea *area, int value)
const ComputeContext * compute_context_for_closure_evaluation(const ComputeContext *closure_socket_context, const bNodeSocket &closure_socket, bke::ComputeContextCache &compute_context_cache, const std::optional< ClosureSourceLocation > &source_location)
bool button_active_drop_color(bContext *C)
void drop_color_copy(bContext *C, wmDrag *drag, wmDropBox *drop)
bool button_active_drop_name(const bContext *C)
void view2d_center_set(View2D *v2d, float x, float y)
Definition view2d.cc:1939
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
@ V2D_COMMONVIEW_CUSTOM
Definition UI_view2d.hh:56
void view2d_size_x_set(View2D *v2d, float size_x)
Definition view2d.cc:1947
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
bool ED_node_is_compositor(const SpaceNode *snode)
Definition node_edit.cc:135
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void ED_node_tree_push(ARegion *region, SpaceNode *snode, bNodeTree *ntree, bNode *gnode)
wmDropBox * WM_dropbox_add(ListBaseT< wmDropBox > *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)
@ SNODE_SHADER_LINESTYLE
bool ED_node_is_geometry(const SpaceNode *snode)
Definition node_edit.cc:150
const char * node_context_dir[]
void ED_region_generic_tools_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
Definition area_utils.cc:30
wmDragAsset * WM_drag_get_asset_data(const wmDrag *drag, int idcode)
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
void WM_drag_free_imported_drag_ID(Main *bmain, wmDrag *drag, wmDropBox *drop)
Free asset ID imported for canceled drop.
int rna_node_tree_idname_to_enum(const char *idname)
@ SNODE_GEOMETRY_MODIFIER
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:98
@ REGION_DRAW_LOCK_ALL
@ RGN_TYPE_ASSET_SHELF_HEADER
int ED_node_tree_path_length(SpaceNode *snode)
void id_us_plus(ID *id)
Definition lib_id.cc:433
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
Definition listbase.cc:834
void ED_node_tree_pop(ARegion *region, SpaceNode *snode)
MINLINE void copy_v2_v2(float r[2], const float a[2])
@ IDWALK_NO_ORIG_POINTERS_ACCESS
void ED_node_cursor_location_get(const SpaceNode *snode, float value[2])
bool ED_node_is_shader(SpaceNode *snode)
Definition node_edit.cc:140
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
@ WM_DRAG_NODE_TREE_INTERFACE
Definition WM_types.hh:1317
@ WM_DRAG_ASSET
Definition WM_types.hh:1294
@ WM_DRAG_PATH
Definition WM_types.hh:1302
@ WM_DRAG_COLOR
Definition WM_types.hh:1312
void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
ID * WM_drag_get_local_ID_or_import_from_asset(const bContext *C, const wmDrag *drag, int idcode)
void ED_node_tree_start(ARegion *region, SpaceNode *snode, bNodeTree *ntree, ID *id, ID *from)
Definition space_node.cc:79
bool CTX_data_equals(const char *member, const char *str)
void WM_gizmomap_tag_refresh(wmGizmoMap *gzmap)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
LibraryForeachIDFlag BKE_lib_query_foreachid_process_flags_get(const LibraryForeachIDData *data)
Definition lib_query.cc:133
bool WM_drag_is_ID_type(const wmDrag *drag, int idcode)
@ RGN_ALIGN_HIDE_WITH_PREV
bool DEG_is_original(const T *id)
void CTX_data_id_pointer_set(bContextDataResult *result, ID *id)
SpaceNodeCompositorNodesType
@ SNODE_COMPOSITOR_SEQUENCER
@ SNODE_COMPOSITOR_SCENE
wmEventHandler_Dropbox * WM_event_add_dropbox_handler(ListBaseT< wmEventHandler > *handlers, ListBaseT< wmDropBox > *dropboxes)
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
int ED_region_generic_panel_region_snap_size(const ARegion *region, int size, int axis)
Definition area_utils.cc:73
wmGizmoGroupTypeRef * WM_gizmogrouptype_append_and_link(wmGizmoMapType *gzmap_type, void(*wtfunc)(wmGizmoGroupType *))
void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
bke::bNodeTreeType * rna_node_tree_type_from_enum(int value)
void DEG_id_tag_update(ID *id, unsigned int flags)
void CTX_data_type_set(bContextDataResult *result, ContextDataType type)
BMesh const char void * data
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
bool ED_node_is_texture(SpaceNode *snode)
Definition node_edit.cc:145
wmEventHandler_Keymap * WM_event_add_keymap_handler_v2d_mask(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
void CTX_data_pointer_set_ptr(bContextDataResult *result, const PointerRNA *ptr)
void ED_region_panels(const bContext *C, ARegion *region)
Definition area.cc:3999
void BKE_annotations_blend_read_data(struct BlendDataReader *reader, struct bGPdata *gpd)
IDProperty * BKE_asset_metadata_idprop_find(const AssetMetaData *asset_data, const char *name) ATTR_WARN_UNUSED_RESULT
Definition asset.cc:183
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
SpaceNode * CTX_wm_space_node(const bContext *C)
void ED_area_do_mgs_subscribe_for_tool_ui(const wmRegionMessageSubscribeParams *params)
Definition area.cc:442
wmEventHandler_Keymap * WM_event_add_keymap_handler(ListBaseT< wmEventHandler > *handlers, wmKeyMap *keymap)
ARegion * BKE_area_region_new()
Definition screen.cc:522
int ED_region_generic_tools_region_snap_size(const ARegion *region, int size, int axis)
Definition area_utils.cc:42
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
bool CTX_data_dir(const char *member)
@ ED_KEYMAP_UI
Definition ED_screen.hh:852
@ ED_KEYMAP_FOOTER
Definition ED_screen.hh:859
@ ED_KEYMAP_HEADER
Definition ED_screen.hh:858
@ ED_KEYMAP_GPENCIL
Definition ED_screen.hh:860
@ ED_KEYMAP_TOOL
Definition ED_screen.hh:854
@ ED_KEYMAP_ASSET_SHELF
Definition ED_screen.hh:862
@ ED_KEYMAP_VIEW2D
Definition ED_screen.hh:855
@ ED_KEYMAP_FRAMES
Definition ED_screen.hh:857
@ ED_KEYMAP_GIZMO
Definition ED_screen.hh:853
void ED_node_cursor_location_set(SpaceNode *snode, const float value[2])
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
void id_us_ensure_real(ID *id)
Definition lib_id.cc:388
T * DEG_get_original(T *id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
bool WM_menutype_add(MenuType *mt)
void BKE_spacetype_register(std::unique_ptr< SpaceType > st)
Definition screen.cc:379
void ED_node_set_active_viewer_key(SpaceNode *snode)
@ ID_RECALC_NTREE_OUTPUT
Definition DNA_ID.h:1155
ID_Type GS(const char *name)
Definition DNA_ID.h:410
void ED_region_header_init(ARegion *region)
Definition area.cc:4406
Span< std::string > WM_drag_get_paths(const wmDrag *drag)
wmGizmoMapType * WM_gizmomaptype_ensure(const wmGizmoMapType_Params *gzmap_params)
const EnumPropertyItem * RNA_enum_node_tree_types_itemf_impl(bContext *C, bool *r_free)
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
void CTX_data_list_add_ptr(bContextDataResult *result, const PointerRNA *ptr)
void ED_node_set_tree_type(SpaceNode *snode, bke::bNodeTreeType *typeinfo)
Definition node_edit.cc:121
void ED_spacetype_node()
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
void ED_area_tag_refresh(ScrArea *area)
Definition area.cc:813
@ CTX_RESULT_MEMBER_NOT_FOUND
ID * WM_drag_get_local_ID(const wmDrag *drag, short idcode)
@ IDWALK_CB_DIRECT_WEAK_LINK
@ IDWALK_CB_EMBEDDED_NOT_OWNING
ListBaseT< wmDropBox > * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
int ED_node_tree_depth(SpaceNode *snode)
bNodeTree * ED_node_tree_get(SpaceNode *snode, int level)
void ED_region_header(const bContext *C, ARegion *region)
Definition area.cc:4391
void id_us_min(ID *id)
Definition lib_id.cc:441
void ED_region_panels_init(wmWindowManager *wm, ARegion *region)
Definition area.cc:4006
@ SN_OVERLAY_SHOW_OVERLAYS
@ SN_OVERLAY_SHOW_PREVIEWS
@ SN_OVERLAY_SHOW_WIRE_COLORS
@ SN_OVERLAY_SHOW_RENDER_REGION
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
void ED_node_tree_path_get(SpaceNode *snode, char *value)
void(*) on_user_resize(const ARegion *region)
void(*) cursor(wmWindow *win, ScrArea *area, ARegion *region)
ARegionTypeFlag flag
int(*) snap_size(const ARegion *region, int size, int axis)
void *(*) duplicate(void *poin)
void(*) on_poll_success(const bContext *C, ARegion *region)
void(*) message_subscribe(const wmRegionMessageSubscribeParams *params)
bContextDataCallback context
void(*) free(ARegion *)
void(*) draw(const bContext *C, ARegion *region)
void(*) listener(const wmRegionListenerParams *params)
void(*) layout(const bContext *C, ARegion *region)
bool(*) poll(const RegionPollParams *params)
void(*) init(wmWindowManager *wm, ARegion *region)
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
eRegion_Type regiontype
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
void write_struct_cast(const void *data, BlendStructWriterTypedFn< T > fn=nullptr)
void write_struct(const T *data, BlendStructWriterTypedFn< T > fn=nullptr)
char name[258]
Definition DNA_ID.h:433
short flag
Definition DNA_ID.h:439
ListBaseT< SceneCompositorEffect > compositor_effects
ListBaseT< SpaceLink > spacedata
eSpaceNodeOverlay_Flag flag
struct bGPdata * gpd
SpaceNodeOverlay overlay
struct bNodeTree * selected_node_group
eSpaceNode_ShaderFrom shaderfrom
struct bNodeTree * edittree
struct bNodeTree * nodetree
ListBaseT< bNodeTreePath > treepath
ed::space_node::SpaceNode_Runtime * runtime
ListBaseT< ARegion > regionbase
eSpaceNode_Flag flag
eView2D_KeepTot keeptot
eView2D_KeepZoom keepzoom
eView2D_Scroll scroll
struct bNodeTreePath * next
struct bNodeTree * nodetree
struct bNodeTreePath * prev
bNodeInstanceKey parent_key
eNodeTree_Type type
bke::bNodeTreeRuntime * runtime
bNodeInstanceKey active_viewer_key
ListBaseT< wmEventHandler > handlers
const asset_system::AssetRepresentation * asset
Definition WM_types.hh:1337
eWM_DragDataType type
Definition WM_types.hh:1424
PointerRNA * ptr
Definition WM_types.hh:1524
unsigned int action
Definition WM_types.hh:371
unsigned int category
Definition WM_types.hh:371
unsigned int data
Definition WM_types.hh:371
bke::WindowRuntime * runtime