Blender V4.5
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
9
10#include "BLI_listbase.h"
11#include "BLI_vector.hh"
12
13#include "DNA_node_types.h"
14
15#include "BKE_context.hh"
16#include "BKE_material.hh"
17#include "BKE_object.hh"
18
19#include "RNA_prototypes.hh"
20
21#include "ED_screen.hh"
22
23#include "UI_interface.hh"
24#include "UI_resources.hh"
25
26#include "node_intern.hh"
27
28struct Material;
29
31
33{
34 if (!object.data) {
35 return;
36 }
37 if (object.type == OB_MESH) {
38 ui::context_path_add_generic(path, RNA_Mesh, object.data);
39 }
40 else if (object.type == OB_CURVES) {
41 ui::context_path_add_generic(path, RNA_Curves, object.data);
42 }
43 else if (object.type == OB_LAMP) {
44 ui::context_path_add_generic(path, RNA_Light, object.data);
45 }
46 else if (ELEM(object.type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
47 ui::context_path_add_generic(path, RNA_Curve, object.data);
48 }
49}
50
53 const bool skip_base = false)
54{
55 LISTBASE_FOREACH (const bNodeTreePath *, path_item, &snode.treepath) {
56 if (!(skip_base && path_item == snode.treepath.first)) {
57 ui::context_path_add_generic(path, RNA_NodeTree, path_item->nodetree, ICON_NODETREE);
58 }
59 }
60}
61
63 SpaceNode &snode,
65{
66 if (snode.flag & SNODE_PIN) {
67 if (snode.shaderfrom == SNODE_SHADER_WORLD) {
68 Scene *scene = CTX_data_scene(&C);
69 ui::context_path_add_generic(path, RNA_Scene, scene);
70 if (scene != nullptr) {
71 ui::context_path_add_generic(path, RNA_World, scene->world);
72 }
73 /* Skip the base node tree here, because the world contains a node tree already. */
75 }
76 else {
78 }
79 }
80 else {
82 if (snode.shaderfrom == SNODE_SHADER_OBJECT && object != nullptr) {
83 ui::context_path_add_generic(path, RNA_Object, object);
84 if (!(object->matbits && object->matbits[object->actcol - 1])) {
85 context_path_add_object_data(path, *object);
86 }
87 Material *material = BKE_object_material_get(object, object->actcol);
88 ui::context_path_add_generic(path, RNA_Material, material);
89 }
90 else if (snode.shaderfrom == SNODE_SHADER_WORLD) {
91 Scene *scene = CTX_data_scene(&C);
92 ui::context_path_add_generic(path, RNA_Scene, scene);
93 if (scene != nullptr) {
94 ui::context_path_add_generic(path, RNA_World, scene->world);
95 }
96 }
97#ifdef WITH_FREESTYLE
98 else if (snode.shaderfrom == SNODE_SHADER_LINESTYLE) {
99 ViewLayer *viewlayer = CTX_data_view_layer(&C);
101 ui::context_path_add_generic(path, RNA_ViewLayer, viewlayer);
102 Material *mat = BKE_object_material_get(object, object->actcol);
103 ui::context_path_add_generic(path, RNA_Material, mat);
104 }
105#endif
107 }
108}
109
111 SpaceNode &snode,
113{
114 if (snode.flag & SNODE_PIN) {
116 }
117 else {
118 Scene *scene = CTX_data_scene(&C);
119 ui::context_path_add_generic(path, RNA_Scene, scene);
121 }
122}
123
125 SpaceNode &snode,
127{
128 if (snode.flag & SNODE_PIN || snode.geometry_nodes_type == SNODE_GEOMETRY_TOOL) {
130 }
131 else {
132 Object *object = CTX_data_active_object(&C);
133 ui::context_path_add_generic(path, RNA_Object, object);
135 ui::context_path_add_generic(path, RNA_Modifier, modifier, ICON_GEOMETRY_NODES);
137 }
138}
139
141{
142 SpaceNode *snode = CTX_wm_space_node(&C);
143 if (snode == nullptr) {
144 return {};
145 }
146
147 Vector<ui::ContextPathItem> context_path;
148
149 if (snode->edittree->type == NTREE_GEOMETRY) {
150 get_context_path_node_geometry(C, *snode, context_path);
151 }
152 else if (snode->edittree->type == NTREE_SHADER) {
153 get_context_path_node_shader(C, *snode, context_path);
154 }
155 else if (snode->edittree->type == NTREE_COMPOSIT) {
156 get_context_path_node_compositor(C, *snode, context_path);
157 }
158
159 return context_path;
160}
161
162} // 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:704
General operations, lookup, etc. for materials.
Material * BKE_object_material_get(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
#define C
Definition RandGen.cpp:29
BMesh const char void * data
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
struct World * world
ListBase treepath
struct bNodeTree * edittree
char geometry_nodes_type