Blender  V3.3
COM_Node.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #pragma once
5 
6 #include "BLI_vector.hh"
7 
8 #include "DNA_node_types.h"
9 
10 /* common node includes
11  * added here so node files don't have to include themselves
12  */
13 #include "COM_CompositorContext.h"
14 #include "COM_NodeConverter.h"
15 
16 namespace blender::compositor {
17 
18 class NodeOperation;
19 class NodeConverter;
20 
24 class Node {
25  private:
29  bNodeTree *editor_node_tree_;
30 
34  bNode *editor_node_;
35 
39  bool in_active_group_;
40 
44  bNodeInstanceKey instance_key_;
45 
46  protected:
51 
56 
57  public:
58  Node(bNode *editor_node, bool create_sockets = true);
59  virtual ~Node();
60 
64  bNode *get_bnode() const
65  {
66  return editor_node_;
67  }
68 
73  {
74  return editor_node_tree_;
75  }
76 
84  {
85  editor_node_ = node;
86  }
87 
92  void set_bnodetree(bNodeTree *nodetree)
93  {
94  editor_node_tree_ = nodetree;
95  }
96 
101  {
102  return inputs_;
103  }
104 
109  {
110  return outputs_;
111  }
112 
117  NodeOutput *get_output_socket(unsigned int index = 0) const;
118 
123  NodeInput *get_input_socket(unsigned int index) const;
124 
129  void set_is_in_active_group(bool value)
130  {
131  in_active_group_ = value;
132  }
133 
140  inline bool is_in_active_group() const
141  {
142  return in_active_group_;
143  }
144 
153  virtual void convert_to_operations(NodeConverter &converter,
154  const CompositorContext &context) const = 0;
155 
157  {
158  instance_key_ = instance_key;
159  }
161  {
162  return instance_key_;
163  }
164 
165  protected:
171  void add_input_socket(DataType datatype);
172  void add_input_socket(DataType datatype, bNodeSocket *socket);
173 
179  void add_output_socket(DataType datatype);
180  void add_output_socket(DataType datatype, bNodeSocket *socket);
181 
182  bNodeSocket *get_editor_input_socket(int editor_node_input_socket_index);
183  bNodeSocket *get_editor_output_socket(int editor_node_output_socket_index);
184 };
185 
190 class NodeInput {
191  private:
192  Node *node_;
193  bNodeSocket *editor_socket_;
194 
195  DataType datatype_;
196 
201  NodeOutput *link_;
202 
203  public:
204  NodeInput(Node *node, bNodeSocket *b_socket, DataType datatype);
205 
206  Node *get_node() const
207  {
208  return node_;
209  }
211  {
212  return datatype_;
213  }
215  {
216  return editor_socket_;
217  }
218 
219  void set_link(NodeOutput *link);
220  bool is_linked() const
221  {
222  return link_;
223  }
225  {
226  return link_;
227  }
228 
229  float get_editor_value_float() const;
230  void get_editor_value_color(float *value) const;
231  void get_editor_value_vector(float *value) const;
232 };
233 
238 class NodeOutput {
239  private:
240  Node *node_;
241  bNodeSocket *editor_socket_;
242 
243  DataType datatype_;
244 
245  public:
246  NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype);
247 
248  Node *get_node() const
249  {
250  return node_;
251  }
253  {
254  return datatype_;
255  }
257  {
258  return editor_socket_;
259  }
260 
261  float get_editor_value_float();
262  void get_editor_value_color(float *value);
263  void get_editor_value_vector(float *value);
264 };
265 
266 } // namespace blender::compositor
Overall context of the compositor.
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:190
NodeInput(Node *node, bNodeSocket *b_socket, DataType datatype)
Definition: COM_Node.cc:125
void get_editor_value_color(float *value) const
Definition: COM_Node.cc:142
bNodeSocket * get_bnode_socket() const
Definition: COM_Node.h:214
DataType get_data_type() const
Definition: COM_Node.h:210
float get_editor_value_float() const
Definition: COM_Node.cc:135
void set_link(NodeOutput *link)
Definition: COM_Node.cc:130
void get_editor_value_vector(float *value) const
Definition: COM_Node.cc:149
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:238
void get_editor_value_vector(float *value)
Definition: COM_Node.cc:179
NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype)
Definition: COM_Node.cc:160
bNodeSocket * get_bnode_socket() const
Definition: COM_Node.h:256
void get_editor_value_color(float *value)
Definition: COM_Node.cc:172
DataType get_data_type() const
Definition: COM_Node.h:252
NodeOutput * get_output_socket(unsigned int index=0) const
Definition: COM_Node.cc:84
void add_output_socket(DataType datatype)
add an NodeOutput to the collection of output-sockets
Definition: COM_Node.cc:74
void set_instance_key(bNodeInstanceKey instance_key)
Definition: COM_Node.h:156
bNodeTree * get_bnodetree() const
get the reference to the SDNA bNodeTree struct
Definition: COM_Node.h:72
bNodeInstanceKey get_instance_key() const
Definition: COM_Node.h:160
void set_bnode(bNode *node)
set the reference to the bNode
Definition: COM_Node.h:83
const Vector< NodeInput * > & get_input_sockets() const
get access to the vector of input sockets
Definition: COM_Node.h:100
bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:64
NodeInput * get_input_socket(unsigned int index) const
Definition: COM_Node.cc:89
void add_input_socket(DataType datatype)
add an NodeInput to the collection of input-sockets
Definition: COM_Node.cc:63
bool is_in_active_group() const
Is this node part of the active group the active group is the group that is currently being edited....
Definition: COM_Node.h:140
const Vector< NodeOutput * > & get_output_sockets() const
get access to the vector of input sockets
Definition: COM_Node.h:108
void set_bnodetree(bNodeTree *nodetree)
set the reference to the bNodeTree
Definition: COM_Node.h:92
bNodeSocket * get_editor_output_socket(int editor_node_output_socket_index)
Definition: COM_Node.cc:107
Vector< NodeInput * > inputs_
the list of actual input-sockets
Definition: COM_Node.h:50
Node(bNode *editor_node, bool create_sockets=true)
Definition: COM_Node.cc:17
Vector< NodeOutput * > outputs_
the list of actual output-sockets
Definition: COM_Node.h:55
void set_is_in_active_group(bool value)
Is this node in the active group (the group that is being edited)
Definition: COM_Node.h:129
bNodeSocket * get_editor_input_socket(int editor_node_input_socket_index)
Definition: COM_Node.cc:94
virtual void convert_to_operations(NodeConverter &converter, const CompositorContext &context) const =0
convert node to operation
OperationNode * node
DataType
possible data types for sockets
Definition: COM_defines.h:30