Blender  V3.3
node_context_path.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
9 #include "BLI_vector.hh"
10 
11 #include "DNA_node_types.h"
12 
13 #include "BKE_context.h"
14 #include "BKE_material.h"
15 #include "BKE_modifier.h"
16 #include "BKE_object.h"
17 
18 #include "BKE_screen.h"
19 
20 #include "RNA_access.h"
21 #include "RNA_prototypes.h"
22 
23 #include "ED_screen.h"
24 
25 #include "UI_interface.h"
26 #include "UI_interface.hh"
27 #include "UI_resources.h"
28 
29 #include "node_intern.hh"
30 
31 struct Material;
32 
33 namespace blender::ed::space_node {
34 
36 {
37  if (!object.data) {
38  return;
39  }
40  if (object.type == OB_MESH) {
41  ui::context_path_add_generic(path, RNA_Mesh, object.data);
42  }
43  else if (object.type == OB_CURVES) {
44  ui::context_path_add_generic(path, RNA_Curves, object.data);
45  }
46  else if (object.type == OB_LAMP) {
47  ui::context_path_add_generic(path, RNA_Light, object.data);
48  }
49  else if (ELEM(object.type, OB_CURVES_LEGACY, OB_FONT, OB_SURF)) {
50  ui::context_path_add_generic(path, RNA_Curve, object.data);
51  }
52 }
53 
56  const bool skip_base = false)
57 {
58  Vector<const bNodeTreePath *> tree_path = snode.treepath;
59  for (const bNodeTreePath *path_item : tree_path.as_span().drop_front(int(skip_base))) {
60  ui::context_path_add_generic(path, RNA_NodeTree, path_item->nodetree, ICON_NODETREE);
61  }
62 }
63 
65  SpaceNode &snode,
67 {
68  if (snode.flag & SNODE_PIN) {
69  if (snode.shaderfrom == SNODE_SHADER_WORLD) {
71  ui::context_path_add_generic(path, RNA_Scene, scene);
72  if (scene != nullptr) {
73  ui::context_path_add_generic(path, RNA_World, scene->world);
74  }
75  /* Skip the base node tree here, because the world contains a node tree already. */
77  }
78  else {
80  }
81  }
82  else {
83  Object *object = CTX_data_active_object(&C);
84  if (snode.shaderfrom == SNODE_SHADER_OBJECT && object != nullptr) {
85  ui::context_path_add_generic(path, RNA_Object, object);
86  if (!(object->matbits && object->matbits[object->actcol - 1])) {
87  context_path_add_object_data(path, *object);
88  }
89  Material *material = BKE_object_material_get(object, object->actcol);
90  ui::context_path_add_generic(path, RNA_Material, material);
91  }
92  else if (snode.shaderfrom == SNODE_SHADER_WORLD) {
94  ui::context_path_add_generic(path, RNA_Scene, scene);
95  if (scene != nullptr) {
96  ui::context_path_add_generic(path, RNA_World, scene->world);
97  }
98  }
99 #ifdef WITH_FREESTYLE
100  else if (snode.shaderfrom == SNODE_SHADER_LINESTYLE) {
101  ViewLayer *viewlayer = CTX_data_view_layer(&C);
103  ui::context_path_add_generic(path, RNA_ViewLayer, viewlayer);
104  Material *mat = BKE_object_material_get(object, object->actcol);
105  ui::context_path_add_generic(path, RNA_Material, mat);
106  }
107 #endif
109  }
110 }
111 
113  SpaceNode &snode,
115 {
116  if (snode.flag & SNODE_PIN) {
118  }
119  else {
121  ui::context_path_add_generic(path, RNA_Scene, scene);
123  }
124 }
125 
127  SpaceNode &snode,
129 {
130  if (snode.flag & SNODE_PIN) {
132  }
133  else {
134  Object *object = CTX_data_active_object(&C);
135  ui::context_path_add_generic(path, RNA_Object, object);
136  ModifierData *modifier = BKE_object_active_modifier(object);
137  ui::context_path_add_generic(path, RNA_Modifier, modifier, ICON_GEOMETRY_NODES);
139  }
140 }
141 
143 {
144  SpaceNode *snode = CTX_wm_space_node(&C);
145  if (snode == nullptr) {
146  return {};
147  }
148 
149  Vector<ui::ContextPathItem> context_path;
150 
151  if (snode->edittree->type == NTREE_GEOMETRY) {
152  get_context_path_node_geometry(C, *snode, context_path);
153  }
154  else if (snode->edittree->type == NTREE_SHADER) {
155  get_context_path_node_shader(C, *snode, context_path);
156  }
157  else if (snode->edittree->type == NTREE_COMPOSIT) {
158  get_context_path_node_compositor(C, *snode, context_path);
159  }
160 
161  return context_path;
162 }
163 
164 } // namespace blender::ed::space_node
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct SpaceNode * CTX_wm_space_node(const bContext *C)
Definition: context.c:878
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1353
FreestyleLineStyle * BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer)
Definition: linestyle.c:806
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
General operations, lookup, etc. for blender objects.
struct ModifierData * BKE_object_active_modifier(const struct Object *ob)
#define ELEM(...)
#define NTREE_GEOMETRY
#define NTREE_COMPOSIT
#define NTREE_SHADER
@ OB_SURF
@ OB_FONT
@ OB_LAMP
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_CURVES
@ SNODE_PIN
@ SNODE_SHADER_WORLD
@ SNODE_SHADER_LINESTYLE
@ SNODE_SHADER_OBJECT
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
#define C
Definition: RandGen.cpp:25
Span< T > as_span() const
Definition: BLI_vector.hh:325
Scene scene
FreestyleLineStyle linestyle
Material material
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)
char * matbits
struct World * world
ListBase treepath
struct bNodeTree * edittree