Blender V4.3
node_context_path.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
10#include "BLI_vector.hh"
11
12#include "DNA_node_types.h"
13
14#include "BKE_context.hh"
15#include "BKE_material.h"
16#include "BKE_object.hh"
17
18#include "RNA_prototypes.hh"
19
20#include "ED_screen.hh"
21
22#include "UI_interface.hh"
23#include "UI_resources.hh"
24
25#include "node_intern.hh"
26
27struct Material;
28
30
32{
33 if (!object.data) {
34 return;
35 }
36 if (object.type == OB_MESH) {
37 ui::context_path_add_generic(path, RNA_Mesh, object.data);
38 }
39 else if (object.type == OB_CURVES) {
40 ui::context_path_add_generic(path, RNA_Curves, object.data);
41 }
42 else if (object.type == OB_LAMP) {
43 ui::context_path_add_generic(path, RNA_Light, object.data);
44 }
45 else if (ELEM(object.type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
46 ui::context_path_add_generic(path, RNA_Curve, object.data);
47 }
48}
49
52 const bool skip_base = false)
53{
54 LISTBASE_FOREACH (const bNodeTreePath *, path_item, &snode.treepath) {
55 if (!(skip_base && path_item == snode.treepath.first)) {
56 ui::context_path_add_generic(path, RNA_NodeTree, path_item->nodetree, ICON_NODETREE);
57 }
58 }
59}
60
62 SpaceNode &snode,
64{
65 if (snode.flag & SNODE_PIN) {
66 if (snode.shaderfrom == SNODE_SHADER_WORLD) {
67 Scene *scene = CTX_data_scene(&C);
68 ui::context_path_add_generic(path, RNA_Scene, scene);
69 if (scene != nullptr) {
70 ui::context_path_add_generic(path, RNA_World, scene->world);
71 }
72 /* Skip the base node tree here, because the world contains a node tree already. */
74 }
75 else {
77 }
78 }
79 else {
80 Object *object = CTX_data_active_object(&C);
81 if (snode.shaderfrom == SNODE_SHADER_OBJECT && object != nullptr) {
82 ui::context_path_add_generic(path, RNA_Object, object);
83 if (!(object->matbits && object->matbits[object->actcol - 1])) {
84 context_path_add_object_data(path, *object);
85 }
86 Material *material = BKE_object_material_get(object, object->actcol);
87 ui::context_path_add_generic(path, RNA_Material, material);
88 }
89 else if (snode.shaderfrom == SNODE_SHADER_WORLD) {
90 Scene *scene = CTX_data_scene(&C);
91 ui::context_path_add_generic(path, RNA_Scene, scene);
92 if (scene != nullptr) {
93 ui::context_path_add_generic(path, RNA_World, scene->world);
94 }
95 }
96#ifdef WITH_FREESTYLE
97 else if (snode.shaderfrom == SNODE_SHADER_LINESTYLE) {
98 ViewLayer *viewlayer = CTX_data_view_layer(&C);
100 ui::context_path_add_generic(path, RNA_ViewLayer, viewlayer);
101 Material *mat = BKE_object_material_get(object, object->actcol);
102 ui::context_path_add_generic(path, RNA_Material, mat);
103 }
104#endif
106 }
107}
108
110 SpaceNode &snode,
112{
113 if (snode.flag & SNODE_PIN) {
115 }
116 else {
117 Scene *scene = CTX_data_scene(&C);
118 ui::context_path_add_generic(path, RNA_Scene, scene);
120 }
121}
122
124 SpaceNode &snode,
126{
127 if (snode.flag & SNODE_PIN || snode.geometry_nodes_type == SNODE_GEOMETRY_TOOL) {
129 }
130 else {
131 Object *object = CTX_data_active_object(&C);
132 ui::context_path_add_generic(path, RNA_Object, object);
133 ModifierData *modifier = BKE_object_active_modifier(object);
134 ui::context_path_add_generic(path, RNA_Modifier, modifier, ICON_GEOMETRY_NODES);
136 }
137}
138
140{
141 SpaceNode *snode = CTX_wm_space_node(&C);
142 if (snode == nullptr) {
143 return {};
144 }
145
146 Vector<ui::ContextPathItem> context_path;
147
148 if (snode->edittree->type == NTREE_GEOMETRY) {
149 get_context_path_node_geometry(C, *snode, context_path);
150 }
151 else if (snode->edittree->type == NTREE_SHADER) {
152 get_context_path_node_shader(C, *snode, context_path);
153 }
154 else if (snode->edittree->type == NTREE_COMPOSIT) {
155 get_context_path_node_compositor(C, *snode, context_path);
156 }
157
158 return context_path;
159}
160
161} // namespace blender::ed::space_node
SpaceNode * CTX_wm_space_node(const bContext *C)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
FreestyleLineStyle * BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer)
Definition linestyle.cc:705
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
General operations, lookup, etc. for blender objects.
ModifierData * BKE_object_active_modifier(const Object *ob)
#define LISTBASE_FOREACH(type, var, list)
#define ELEM(...)
@ NTREE_SHADER
@ NTREE_GEOMETRY
@ NTREE_COMPOSIT
@ OB_SURF
@ OB_FONT
@ OB_LAMP
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_CURVES
@ SNODE_PIN
@ SNODE_GEOMETRY_TOOL
@ SNODE_SHADER_WORLD
@ SNODE_SHADER_LINESTYLE
@ SNODE_SHADER_OBJECT
FreestyleLineStyle linestyle
static void get_context_path_node_shader(const bContext &C, SpaceNode &snode, Vector< ui::ContextPathItem > &path)
static void get_context_path_node_geometry(const bContext &C, SpaceNode &snode, Vector< ui::ContextPathItem > &path)
static void context_path_add_object_data(Vector< ui::ContextPathItem > &path, Object &object)
static void get_context_path_node_compositor(const bContext &C, SpaceNode &snode, Vector< ui::ContextPathItem > &path)
Vector< ui::ContextPathItem > context_path_for_space_node(const bContext &C)
static void context_path_add_node_tree_and_node_groups(const SpaceNode &snode, Vector< ui::ContextPathItem > &path, const bool skip_base=false)
void context_path_add_generic(Vector< ContextPathItem > &path, StructRNA &rna_type, void *ptr, const BIFIconID icon_override=ICON_NONE)
void * first
ListBase treepath
struct bNodeTree * edittree
char geometry_nodes_type