Blender  V2.93
COM_Node.h
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  * Copyright 2011, Blender Foundation.
17  */
18 
19 #pragma once
20 
21 #include "BLI_vector.hh"
22 
23 #include "DNA_node_types.h"
24 
25 #include <algorithm>
26 #include <string>
27 
28 /* common node includes
29  * added here so node files don't have to include themselves
30  */
31 #include "COM_CompositorContext.h"
32 #include "COM_NodeConverter.h"
33 
34 namespace blender::compositor {
35 
36 class NodeOperation;
37 class NodeConverter;
38 
42 class Node {
43  private:
47  bNodeTree *m_editorNodeTree;
48 
52  bNode *m_editorNode;
53 
57  bool m_inActiveGroup;
58 
62  bNodeInstanceKey m_instanceKey;
63 
64  protected:
69 
74 
75  public:
76  Node(bNode *editorNode, bool create_sockets = true);
77  virtual ~Node();
78 
82  bNode *getbNode() const
83  {
84  return m_editorNode;
85  }
86 
91  {
92  return m_editorNodeTree;
93  }
94 
102  {
103  this->m_editorNode = node;
104  }
105 
110  void setbNodeTree(bNodeTree *nodetree)
111  {
112  this->m_editorNodeTree = nodetree;
113  }
114 
119  {
120  return this->inputs;
121  }
122 
127  {
128  return this->outputs;
129  }
130 
136  NodeOutput *getOutputSocket(const unsigned int index = 0) const;
137 
143  NodeInput *getInputSocket(const unsigned int index) const;
144 
149  void setIsInActiveGroup(bool value)
150  {
151  this->m_inActiveGroup = value;
152  }
153 
160  inline bool isInActiveGroup() const
161  {
162  return this->m_inActiveGroup;
163  }
164 
173  virtual void convertToOperations(NodeConverter &converter,
174  const CompositorContext &context) const = 0;
175 
176  void setInstanceKey(bNodeInstanceKey instance_key)
177  {
178  m_instanceKey = instance_key;
179  }
181  {
182  return m_instanceKey;
183  }
184 
185  protected:
191  void addInputSocket(DataType datatype);
192  void addInputSocket(DataType datatype, bNodeSocket *socket);
193 
199  void addOutputSocket(DataType datatype);
200  void addOutputSocket(DataType datatype, bNodeSocket *socket);
201 
202  bNodeSocket *getEditorInputSocket(int editorNodeInputSocketIndex);
203  bNodeSocket *getEditorOutputSocket(int editorNodeOutputSocketIndex);
204 };
205 
210 class NodeInput {
211  private:
212  Node *m_node;
213  bNodeSocket *m_editorSocket;
214 
215  DataType m_datatype;
216 
221  NodeOutput *m_link;
222 
223  public:
224  NodeInput(Node *node, bNodeSocket *b_socket, DataType datatype);
225 
226  Node *getNode() const
227  {
228  return this->m_node;
229  }
231  {
232  return m_datatype;
233  }
235  {
236  return this->m_editorSocket;
237  }
238 
239  void setLink(NodeOutput *link);
240  bool isLinked() const
241  {
242  return m_link;
243  }
245  {
246  return m_link;
247  }
248 
249  float getEditorValueFloat() const;
250  void getEditorValueColor(float *value) const;
251  void getEditorValueVector(float *value) const;
252 };
253 
258 class NodeOutput {
259  private:
260  Node *m_node;
261  bNodeSocket *m_editorSocket;
262 
263  DataType m_datatype;
264 
265  public:
266  NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype);
267 
268  Node *getNode() const
269  {
270  return this->m_node;
271  }
273  {
274  return m_datatype;
275  }
277  {
278  return this->m_editorSocket;
279  }
280 
281  float getEditorValueFloat();
282  void getEditorValueColor(float *value);
283  void getEditorValueVector(float *value);
284 };
285 
286 } // namespace blender::compositor
Overall context of the compositor.
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
NodeInput(Node *node, bNodeSocket *b_socket, DataType datatype)
Definition: COM_Node.cc:149
DataType getDataType() const
Definition: COM_Node.h:230
void getEditorValueColor(float *value) const
Definition: COM_Node.cc:166
void getEditorValueVector(float *value) const
Definition: COM_Node.cc:173
void setLink(NodeOutput *link)
Definition: COM_Node.cc:154
bNodeSocket * getbNodeSocket() const
Definition: COM_Node.h:234
float getEditorValueFloat() const
Definition: COM_Node.cc:159
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
bNodeSocket * getbNodeSocket() const
Definition: COM_Node.h:276
void getEditorValueColor(float *value)
Definition: COM_Node.cc:196
NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype)
Definition: COM_Node.cc:184
void getEditorValueVector(float *value)
Definition: COM_Node.cc:203
DataType getDataType() const
Definition: COM_Node.h:272
Vector< NodeInput * > inputs
the list of actual input-sockets
Definition: COM_Node.h:68
Vector< NodeOutput * > outputs
the list of actual output-sockets
Definition: COM_Node.h:73
NodeOutput * getOutputSocket(const unsigned int index=0) const
Definition: COM_Node.cc:108
bNodeSocket * getEditorInputSocket(int editorNodeInputSocketIndex)
Definition: COM_Node.cc:118
bNode * getbNode() const
get the reference to the SDNA bNode struct
Definition: COM_Node.h:82
bNodeInstanceKey getInstanceKey() const
Definition: COM_Node.h:180
Node(bNode *editorNode, bool create_sockets=true)
Definition: COM_Node.cc:41
NodeInput * getInputSocket(const unsigned int index) const
Definition: COM_Node.cc:113
void setbNode(bNode *node)
set the reference to the bNode
Definition: COM_Node.h:101
void setbNodeTree(bNodeTree *nodetree)
set the reference to the bNodeTree
Definition: COM_Node.h:110
void setInstanceKey(bNodeInstanceKey instance_key)
Definition: COM_Node.h:176
virtual void convertToOperations(NodeConverter &converter, const CompositorContext &context) const =0
convert node to operation
bNodeSocket * getEditorOutputSocket(int editorNodeOutputSocketIndex)
Definition: COM_Node.cc:131
const Vector< NodeOutput * > & getOutputSockets() const
get access to the vector of input sockets
Definition: COM_Node.h:126
const Vector< NodeInput * > & getInputSockets() const
get access to the vector of input sockets
Definition: COM_Node.h:118
void addOutputSocket(DataType datatype)
add an NodeOutput to the collection of output-sockets
Definition: COM_Node.cc:98
bNodeTree * getbNodeTree() const
get the reference to the SDNA bNodeTree struct
Definition: COM_Node.h:90
bool isInActiveGroup() const
Is this node part of the active group the active group is the group that is currently being edited....
Definition: COM_Node.h:160
void setIsInActiveGroup(bool value)
Is this node in the active group (the group that is being edited)
Definition: COM_Node.h:149
void addInputSocket(DataType datatype)
add an NodeInput to the collection of input-sockets
Definition: COM_Node.cc:87
OperationNode * node
DataType
possible data types for sockets
Definition: COM_defines.h:27