Blender  V3.3
COM_Node.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2011 Blender Foundation. */
3 
4 #include "BKE_node.h"
5 
6 #include "RNA_access.h"
7 #include "RNA_prototypes.h"
8 
9 #include "COM_Node.h" /* own include */
10 
11 namespace blender::compositor {
12 
13 /**************
14  **** Node ****
15  **************/
16 
17 Node::Node(bNode *editor_node, bool create_sockets)
18  : editor_node_tree_(nullptr),
19  editor_node_(editor_node),
20  in_active_group_(false),
21  instance_key_(NODE_INSTANCE_KEY_NONE)
22 {
23  if (create_sockets) {
24  bNodeSocket *input = (bNodeSocket *)editor_node->inputs.first;
25  while (input != nullptr) {
27  if (input->type == SOCK_RGBA) {
28  dt = DataType::Color;
29  }
30  if (input->type == SOCK_VECTOR) {
31  dt = DataType::Vector;
32  }
33 
34  this->add_input_socket(dt, input);
35  input = input->next;
36  }
37  bNodeSocket *output = (bNodeSocket *)editor_node->outputs.first;
38  while (output != nullptr) {
40  if (output->type == SOCK_RGBA) {
41  dt = DataType::Color;
42  }
43  if (output->type == SOCK_VECTOR) {
44  dt = DataType::Vector;
45  }
46 
47  this->add_output_socket(dt, output);
48  output = output->next;
49  }
50  }
51 }
52 
54 {
55  while (!outputs_.is_empty()) {
56  delete (outputs_.pop_last());
57  }
58  while (!inputs_.is_empty()) {
59  delete (inputs_.pop_last());
60  }
61 }
62 
64 {
65  this->add_input_socket(datatype, nullptr);
66 }
67 
69 {
70  NodeInput *socket = new NodeInput(this, bSocket, datatype);
71  inputs_.append(socket);
72 }
73 
75 {
76  this->add_output_socket(datatype, nullptr);
77 }
79 {
80  NodeOutput *socket = new NodeOutput(this, bSocket, datatype);
81  outputs_.append(socket);
82 }
83 
84 NodeOutput *Node::get_output_socket(unsigned int index) const
85 {
86  return outputs_[index];
87 }
88 
89 NodeInput *Node::get_input_socket(unsigned int index) const
90 {
91  return inputs_[index];
92 }
93 
94 bNodeSocket *Node::get_editor_input_socket(int editor_node_input_socket_index)
95 {
96  bNodeSocket *bSock = (bNodeSocket *)this->get_bnode()->inputs.first;
97  int index = 0;
98  while (bSock != nullptr) {
99  if (index == editor_node_input_socket_index) {
100  return bSock;
101  }
102  index++;
103  bSock = bSock->next;
104  }
105  return nullptr;
106 }
107 bNodeSocket *Node::get_editor_output_socket(int editor_node_output_socket_index)
108 {
109  bNodeSocket *bSock = (bNodeSocket *)this->get_bnode()->outputs.first;
110  int index = 0;
111  while (bSock != nullptr) {
112  if (index == editor_node_output_socket_index) {
113  return bSock;
114  }
115  index++;
116  bSock = bSock->next;
117  }
118  return nullptr;
119 }
120 
121 /*******************
122  **** NodeInput ****
123  *******************/
124 
126  : node_(node), editor_socket_(b_socket), datatype_(datatype), link_(nullptr)
127 {
128 }
129 
131 {
132  link_ = link;
133 }
134 
136 {
137  PointerRNA ptr;
138  RNA_pointer_create((ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket(), &ptr);
139  return RNA_float_get(&ptr, "default_value");
140 }
141 
142 void NodeInput::get_editor_value_color(float *value) const
143 {
144  PointerRNA ptr;
145  RNA_pointer_create((ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket(), &ptr);
146  return RNA_float_get_array(&ptr, "default_value", value);
147 }
148 
149 void NodeInput::get_editor_value_vector(float *value) const
150 {
151  PointerRNA ptr;
152  RNA_pointer_create((ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket(), &ptr);
153  return RNA_float_get_array(&ptr, "default_value", value);
154 }
155 
156 /********************
157  **** NodeOutput ****
158  ********************/
159 
161  : node_(node), editor_socket_(b_socket), datatype_(datatype)
162 {
163 }
164 
166 {
167  PointerRNA ptr;
168  RNA_pointer_create((ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket(), &ptr);
169  return RNA_float_get(&ptr, "default_value");
170 }
171 
173 {
174  PointerRNA ptr;
175  RNA_pointer_create((ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket(), &ptr);
176  return RNA_float_get_array(&ptr, "default_value", value);
177 }
178 
180 {
181  PointerRNA ptr;
182  RNA_pointer_create((ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket(), &ptr);
183  return RNA_float_get_array(&ptr, "default_value", value);
184 }
185 
186 } // namespace blender::compositor
const bNodeInstanceKey NODE_INSTANCE_KEY_NONE
Definition: node.cc:3897
@ SOCK_VECTOR
@ SOCK_RGBA
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
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
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
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
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
bNodeSocket * get_editor_input_socket(int editor_node_input_socket_index)
Definition: COM_Node.cc:94
OperationNode * node
DataType
possible data types for sockets
Definition: COM_defines.h:30
@ Vector
Vector data type.
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:4980
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4957
Definition: DNA_ID.h:368
void * first
Definition: DNA_listBase.h:31
struct bNodeSocket * next
ListBase inputs
ListBase outputs
PointerRNA * ptr
Definition: wm_files.c:3480