Blender  V2.93
node_composite_switchview.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2006 Blender Foundation.
17  * All rights reserved.
18  * Dalai Felinto
19  */
20 
25 #include "BKE_context.h"
26 #include "BKE_lib_id.h"
27 
28 #include "../node_composite_util.h"
29 
30 /* **************** SWITCH VIEW ******************** */
32  {SOCK_RGBA, N_("Image"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
33  {-1, ""},
34 };
35 
37  bNode *node,
38  const char *name)
39 {
41  return sock;
42 }
43 
45 {
46  bNodeSocket *sock;
47 
48  if (!BLI_listbase_is_empty(&node->inputs)) {
49  return;
50  }
51 
52  sock = ntreeCompositSwitchViewAddSocket(ntree, node, "No View");
53  sock->flag |= SOCK_HIDDEN;
54 }
55 
57 {
58  bNodeSocket *sock;
59  SceneRenderView *srv;
60  Scene *scene = (Scene *)node->id;
61 
62  /* only update when called from the operator button */
63  if (node->update != NODE_UPDATE_OPERATOR) {
64  return;
65  }
66 
67  if (scene == NULL) {
69  /* make sure there is always one socket */
71  return;
72  }
73 
74  /* remove the views that were removed */
75  sock = node->inputs.last;
76  while (sock) {
77  srv = BLI_findstring(&scene->r.views, sock->name, offsetof(SceneRenderView, name));
78 
79  if (srv == NULL) {
80  bNodeSocket *sock_del = sock;
81  sock = sock->prev;
82  nodeRemoveSocket(ntree, node, sock_del);
83  }
84  else {
85  if (srv->viewflag & SCE_VIEW_DISABLE) {
86  sock->flag |= SOCK_HIDDEN;
87  }
88  else {
89  sock->flag &= ~SOCK_HIDDEN;
90  }
91 
92  sock = sock->prev;
93  }
94  }
95 
96  /* add the new views */
97  for (srv = scene->r.views.first; srv; srv = srv->next) {
98  sock = BLI_findstring(&node->inputs, srv->name, offsetof(bNodeSocket, name));
99 
100  if (sock == NULL) {
102  }
103 
104  if (srv->viewflag & SCE_VIEW_DISABLE) {
105  sock->flag |= SOCK_HIDDEN;
106  }
107  else {
108  sock->flag &= ~SOCK_HIDDEN;
109  }
110  }
111 
112  /* make sure there is always one socket */
114 }
115 
116 static void init_switch_view(const bContext *C, PointerRNA *ptr)
117 {
120  bNode *node = ptr->data;
121  SceneRenderView *srv;
122  bNodeSocket *sock;
123  int nr;
124 
125  /* store scene for updates */
126  node->id = (ID *)scene;
127  id_us_plus(node->id);
128 
129  if (scene) {
130  RenderData *rd = &scene->r;
131 
132  for (nr = 0, srv = rd->views.first; srv; srv = srv->next, nr++) {
133  sock = ntreeCompositSwitchViewAddSocket(ntree, node, srv->name);
134 
135  if ((srv->viewflag & SCE_VIEW_DISABLE)) {
136  sock->flag |= SOCK_HIDDEN;
137  }
138  }
139  }
140 
141  /* make sure there is always one socket */
143 }
144 
146 {
147  static bNodeType ntype;
148 
151 
153 
155 
156  nodeRegisterType(&ntype);
157 }
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
void id_us_plus(struct ID *id)
Definition: lib_id.c:288
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4623
void nodeRemoveAllSockets(struct bNodeTree *ntree, struct bNode *node)
Definition: node.cc:1793
#define NODE_CLASS_CONVERTOR
Definition: BKE_node.h:341
struct bNodeSocket * nodeAddStaticSocket(struct bNodeTree *ntree, struct bNode *node, eNodeSocketInOut in_out, int type, int subtype, const char *identifier, const char *name)
Definition: node.cc:1716
void nodeRemoveSocket(struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *sock)
Definition: node.cc:1775
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
void * BLI_findstring(const struct ListBase *listbase, const char *id, const int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define N_(msgid)
#define NODE_UPDATE_OPERATOR
@ SOCK_IN
@ SOCK_HIDDEN
@ SOCK_RGBA
#define SCE_VIEW_DISABLE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh CMP_NODE_SWITCH_VIEW
@ PROP_NONE
Definition: RNA_types.h:113
#define C
Definition: RandGen.cpp:39
OperationNode * node
Scene scene
bNodeTree * ntree
static void cmp_node_switch_view_sanitycheck(bNodeTree *ntree, bNode *node)
static bNodeSocketTemplate cmp_node_switch_view_out[]
static bNodeSocket * ntreeCompositSwitchViewAddSocket(bNodeTree *ntree, bNode *node, const char *name)
void register_node_type_cmp_switch_view(void)
static void init_switch_view(const bContext *C, PointerRNA *ptr)
static void cmp_node_switch_view_update(bNodeTree *ntree, bNode *node)
void cmp_node_type_base(bNodeType *ntype, int type, const char *name, short nclass, short flag)
Definition: DNA_ID.h:273
void * first
Definition: DNA_listBase.h:47
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
ListBase views
struct SceneRenderView * next
struct RenderData r
Compact definition of a node socket.
Definition: BKE_node.h:95
char name[64]
struct bNodeSocket * prev
Defines a node type.
Definition: BKE_node.h:221
void(* initfunc_api)(const struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:288
PointerRNA * ptr
Definition: wm_files.c:3157