Blender V4.3
COM_Node.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_node.hh"
6
7#include "RNA_access.hh"
8#include "RNA_prototypes.hh"
9
10#include "COM_Node.h" /* own include */
11
12namespace blender::compositor {
13
14/**************
15 **** Node ****
16 **************/
17
18Node::Node(bNode *editor_node, bool create_sockets)
19 : editor_node_tree_(nullptr),
20 editor_node_(editor_node),
21 in_active_group_(false),
22 instance_key_(bke::NODE_INSTANCE_KEY_NONE)
23{
24 if (create_sockets) {
25 bNodeSocket *input = (bNodeSocket *)editor_node->inputs.first;
26 while (input != nullptr) {
28 if (input->type == SOCK_RGBA) {
29 dt = DataType::Color;
30 }
31 if (input->type == SOCK_VECTOR) {
33 }
34
35 this->add_input_socket(dt, input);
36 input = input->next;
37 }
38 bNodeSocket *output = (bNodeSocket *)editor_node->outputs.first;
39 while (output != nullptr) {
41 if (output->type == SOCK_RGBA) {
42 dt = DataType::Color;
43 }
44 if (output->type == SOCK_VECTOR) {
46 }
47
48 this->add_output_socket(dt, output);
49 output = output->next;
50 }
51 }
52}
53
55{
56 while (!outputs_.is_empty()) {
57 delete outputs_.pop_last();
58 }
59 while (!inputs_.is_empty()) {
60 delete inputs_.pop_last();
61 }
62}
63
65{
66 this->add_input_socket(datatype, nullptr);
67}
68
70{
71 NodeInput *socket = new NodeInput(this, bSocket, datatype);
72 inputs_.append(socket);
73}
74
76{
77 this->add_output_socket(datatype, nullptr);
78}
80{
81 NodeOutput *socket = new NodeOutput(this, bSocket, datatype);
82 outputs_.append(socket);
83}
84
86{
87 return outputs_[index];
88}
89
91{
92 return inputs_[index];
93}
94
95bNodeSocket *Node::get_editor_input_socket(int editor_node_input_socket_index)
96{
97 bNodeSocket *bSock = (bNodeSocket *)this->get_bnode()->inputs.first;
98 int index = 0;
99 while (bSock != nullptr) {
100 if (index == editor_node_input_socket_index) {
101 return bSock;
102 }
103 index++;
104 bSock = bSock->next;
105 }
106 return nullptr;
107}
108bNodeSocket *Node::get_editor_output_socket(int editor_node_output_socket_index)
109{
110 bNodeSocket *bSock = (bNodeSocket *)this->get_bnode()->outputs.first;
111 int index = 0;
112 while (bSock != nullptr) {
113 if (index == editor_node_output_socket_index) {
114 return bSock;
115 }
116 index++;
117 bSock = bSock->next;
118 }
119 return nullptr;
120}
121
122/*******************
123 **** NodeInput ****
124 *******************/
125
127 : node_(node), editor_socket_(b_socket), datatype_(datatype), link_(nullptr)
128{
129}
130
132{
133 link_ = link;
134}
135
137{
139 (ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket());
140 return RNA_float_get(&ptr, "default_value");
141}
142
143void NodeInput::get_editor_value_color(float *value) const
144{
146 (ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket());
147 return RNA_float_get_array(&ptr, "default_value", value);
148}
149
151{
153 (ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket());
154 return RNA_float_get_array(&ptr, "default_value", value);
155}
156
157/********************
158 **** NodeOutput ****
159 ********************/
160
162 : node_(node), editor_socket_(b_socket), datatype_(datatype)
163{
164}
165
167{
169 (ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket());
170 return RNA_float_get(&ptr, "default_value");
171}
172
174{
176 (ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket());
177 return RNA_float_get_array(&ptr, "default_value", value);
178}
179
181{
183 (ID *)get_node()->get_bnodetree(), &RNA_NodeSocket, get_bnode_socket());
184 return RNA_float_get_array(&ptr, "default_value", value);
185}
186
187} // namespace blender::compositor
unsigned int uint
@ SOCK_VECTOR
@ SOCK_RGBA
NodeInput are sockets that can receive data/input.
Definition COM_Node.h:191
NodeInput(Node *node, bNodeSocket *b_socket, DataType datatype)
Definition COM_Node.cc:126
void get_editor_value_color(float *value) const
Definition COM_Node.cc:143
bNodeSocket * get_bnode_socket() const
Definition COM_Node.h:215
float get_editor_value_float() const
Definition COM_Node.cc:136
void set_link(NodeOutput *link)
Definition COM_Node.cc:131
void get_editor_value_vector(float *value) const
Definition COM_Node.cc:150
NodeOutput are sockets that can send data/input.
Definition COM_Node.h:239
bNodeSocket * get_bnode_socket() const
Definition COM_Node.h:257
void get_editor_value_vector(float *value)
Definition COM_Node.cc:180
NodeOutput(Node *node, bNodeSocket *b_socket, DataType datatype)
Definition COM_Node.cc:161
void get_editor_value_color(float *value)
Definition COM_Node.cc:173
NodeOutput * get_output_socket(unsigned int index=0) const
Definition COM_Node.cc:85
void add_output_socket(DataType datatype)
add an NodeOutput to the collection of output-sockets
Definition COM_Node.cc:75
NodeInput * get_input_socket(unsigned int index) const
Definition COM_Node.cc:90
void add_input_socket(DataType datatype)
add an NodeInput to the collection of input-sockets
Definition COM_Node.cc:64
bNodeSocket * get_editor_output_socket(int editor_node_output_socket_index)
Definition COM_Node.cc:108
Vector< NodeInput * > inputs_
the list of actual input-sockets
Definition COM_Node.h:51
const bNode * get_bnode() const
get the reference to the SDNA bNode struct
Definition COM_Node.h:65
Node(bNode *editor_node, bool create_sockets=true)
Definition COM_Node.cc:18
Vector< NodeOutput * > outputs_
the list of actual output-sockets
Definition COM_Node.h:56
bNodeSocket * get_editor_input_socket(int editor_node_input_socket_index)
Definition COM_Node.cc:95
DataType
possible data types for sockets
Definition COM_defines.h:21
@ Vector
Vector data type.
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
float RNA_float_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
Definition DNA_ID.h:413
void * first
struct bNodeSocket * next
ListBase inputs
ListBase outputs
PointerRNA * ptr
Definition wm_files.cc:4126