Blender V5.3
main_invariants.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
11
12#include "DEG_depsgraph.hh"
13
14#include "DNA_node_types.h"
15
16#include "WM_api.hh"
17#include "WM_types.hh"
18#include <optional>
19
20namespace blender {
21
23{
25
26 if (ntree->type == NTREE_SHADER && id != nullptr) {
27 if (GS(id->name) == ID_MA) {
29 }
30 else if (GS(id->name) == ID_LA) {
32 }
33 else if (GS(id->name) == ID_WO) {
35 }
36 }
37 else if (ntree->type == NTREE_COMPOSIT) {
38 /* The notifier category `NC_SCENE` has some special handling in #wm_event_do_notifiers. When
39 * the id that is passed as the reference is not a scene or not the active scene/sequencer
40 * scene, then the notifier is dropped. So we need to pass `nullptr` here to make sure the
41 * notifier is sent. */
44 }
45 else if (ntree->type == NTREE_TEXTURE) {
47 }
48 else if (ntree->type == NTREE_GEOMETRY) {
50 if (ntree->geometry_node_asset_traits) {
52 /* Notifier to re-register node group operators. */
54 }
55 }
56 }
57}
58
59static void propagate_node_tree_changes(Main &bmain, const std::optional<Span<ID *>> modified_ids)
60{
62 params.tree_changed_fn = [](bNodeTree &ntree, ID &owner_id) {
65 };
66 params.tree_output_changed_fn = [](bNodeTree &ntree, ID & /*owner_id*/) {
68 };
69
70 std::optional<Vector<bNodeTree *>> modified_trees;
71 if (modified_ids.has_value()) {
72 modified_trees.emplace();
73 for (ID *id : *modified_ids) {
74 if (GS(id->name) == ID_NT) {
75 modified_trees->append(reinterpret_cast<bNodeTree *>(id));
76 }
77 }
78 }
79
80 BKE_ntree_update(bmain, modified_trees, params);
81}
82
83void BKE_main_ensure_invariants(Main &bmain, const std::optional<Span<ID *>> modified_ids)
84{
85 propagate_node_tree_changes(bmain, modified_ids);
86}
87
88void BKE_main_ensure_invariants(Main &bmain, ID &modified_id)
89{
90 BKE_main_ensure_invariants(bmain, {{&modified_id}});
91}
92
93} // namespace blender
#define NC_WORLD
Definition WM_types.hh:400
#define ND_SHADING
Definition WM_types.hh:520
#define ND_WORLD
Definition WM_types.hh:471
#define NC_NODE
Definition WM_types.hh:407
#define ND_COMPO_RESULT
Definition WM_types.hh:466
#define NC_SCENE
Definition WM_types.hh:391
#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_LAMP
Definition WM_types.hh:395
#define NC_TEXTURE
Definition WM_types.hh:394
#define ND_LIGHTING
Definition WM_types.hh:526
#define NC_OBJECT
Definition WM_types.hh:392
#define ND_NODE_ASSET_DATA
Definition WM_types.hh:558
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void BKE_ntree_update(Main &bmain, std::optional< Span< bNodeTree * > > modified_trees=std::nullopt, const NodeTreeUpdateExtraParams &params={})
static void send_notifiers_after_node_tree_change(ID *id, bNodeTree *ntree)
@ GEO_NODE_ASSET_TOOL
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
static void propagate_node_tree_changes(Main &bmain, const std::optional< Span< ID * > > modified_ids)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_NTREE_OUTPUT
Definition DNA_ID.h:1155
ID_Type GS(const char *name)
Definition DNA_ID.h:410
std::function< void(bNodeTree &, ID &owner)> tree_changed_fn
std::function< void(bNodeTree &, ID &owner)> tree_output_changed_fn
struct GeometryNodeAssetTraits * geometry_node_asset_traits
eNodeTree_Type type