Blender  V2.93
COM_NodeConverter.cc
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 2013, Blender Foundation.
17  */
18 
19 #include "BLI_utildefines.h"
20 
21 #include "COM_Debug.h"
22 
23 #include "COM_NodeOperation.h"
25 #include "COM_SetColorOperation.h"
26 #include "COM_SetValueOperation.h"
27 #include "COM_SetVectorOperation.h"
29 
30 #include "COM_NodeConverter.h" /* own include */
31 
32 namespace blender::compositor {
33 
34 NodeConverter::NodeConverter(NodeOperationBuilder *builder) : m_builder(builder)
35 {
36 }
37 
39 {
40  m_builder->addOperation(operation);
41 }
42 
43 void NodeConverter::mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
44 {
45  m_builder->mapInputSocket(node_socket, operation_socket);
46 }
47 
48 void NodeConverter::mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
49 {
50  m_builder->mapOutputSocket(node_socket, operation_socket);
51 }
52 
54 {
55  m_builder->addLink(from, to);
56 }
57 
59 {
60  m_builder->addPreview(output);
61 }
62 
64 {
65  m_builder->addNodeInputPreview(input);
66 }
67 
69 {
70  /* this is a really bad situation - bring on the pink! - so artists know this is bad */
71  const float warning_color[4] = {1.0f, 0.0f, 1.0f, 1.0f};
72 
73  SetColorOperation *operation = new SetColorOperation();
74  operation->setChannels(warning_color);
75 
76  m_builder->addOperation(operation);
77  m_builder->mapOutputSocket(output, operation->getOutputSocket());
78 
79  return operation;
80 }
81 
83 {
84  SocketProxyOperation *proxy = new SocketProxyOperation(input->getDataType(), use_conversion);
85  m_builder->addOperation(proxy);
86 
87  m_builder->mapInputSocket(input, proxy->getInputSocket(0));
88 
89  return proxy->getOutputSocket();
90 }
91 
93 {
94  SocketProxyOperation *proxy = new SocketProxyOperation(output->getDataType(), use_conversion);
95  m_builder->addOperation(proxy);
96 
97  m_builder->mapOutputSocket(output, proxy->getOutputSocket());
98 
99  return proxy->getInputSocket(0);
100 }
101 
103 {
104  SetValueOperation *operation = new SetValueOperation();
105  operation->setValue(value);
106 
107  m_builder->addOperation(operation);
108  m_builder->addLink(operation->getOutputSocket(), input);
109 }
110 
111 void NodeConverter::addInputColor(NodeOperationInput *input, const float value[4])
112 {
113  SetColorOperation *operation = new SetColorOperation();
114  operation->setChannels(value);
115 
116  m_builder->addOperation(operation);
117  m_builder->addLink(operation->getOutputSocket(), input);
118 }
119 
120 void NodeConverter::addInputVector(NodeOperationInput *input, const float value[3])
121 {
122  SetVectorOperation *operation = new SetVectorOperation();
123  operation->setVector(value);
124 
125  m_builder->addOperation(operation);
126  m_builder->addLink(operation->getOutputSocket(), input);
127 }
128 
130 {
131  SetValueOperation *operation = new SetValueOperation();
132  operation->setValue(value);
133 
134  m_builder->addOperation(operation);
135  m_builder->mapOutputSocket(output, operation->getOutputSocket());
136 }
137 
138 void NodeConverter::addOutputColor(NodeOutput *output, const float value[4])
139 {
140  SetColorOperation *operation = new SetColorOperation();
141  operation->setChannels(value);
142 
143  m_builder->addOperation(operation);
144  m_builder->mapOutputSocket(output, operation->getOutputSocket());
145 }
146 
148 {
149  SetVectorOperation *operation = new SetVectorOperation();
150  operation->setVector(value);
151 
152  m_builder->addOperation(operation);
153  m_builder->mapOutputSocket(output, operation->getOutputSocket());
154 }
155 
157 {
158  m_builder->registerViewer(viewer);
159 }
160 
162 {
163  return m_builder->active_viewer();
164 }
165 
166 } // namespace blender::compositor
#define output
NodeOperation * setInvalidOutput(NodeOutput *output)
void addOutputVector(NodeOutput *output, const float value[3])
void addOutputValue(NodeOutput *output, float value)
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addPreview(NodeOperationOutput *output)
void addNodeInputPreview(NodeInput *input)
void addInputValue(NodeOperationInput *input, float value)
void addOutputColor(NodeOutput *output, const float value[4])
void addOperation(NodeOperation *operation)
void addInputVector(NodeOperationInput *input, const float value[3])
NodeOperationOutput * addInputProxy(NodeInput *input, bool use_conversion)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void addInputColor(NodeOperationInput *input, const float value[4])
NodeConverter(NodeOperationBuilder *builder)
void registerViewer(ViewerOperation *viewer)
NodeOperationInput * addOutputProxy(NodeOutput *output, bool use_conversion)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
ViewerOperation * active_viewer() const
NodeInput are sockets that can receive data/input.
Definition: COM_Node.h:210
DataType getDataType() const
Definition: COM_Node.h:230
void addPreview(NodeOperationOutput *output)
void mapOutputSocket(NodeOutput *node_socket, NodeOperationOutput *operation_socket)
void mapInputSocket(NodeInput *node_socket, NodeOperationInput *operation_socket)
void addLink(NodeOperationOutput *from, NodeOperationInput *to)
NodeOperation contains calculation logic.
NodeOperationInput * getInputSocket(unsigned int index)
NodeOperationOutput * getOutputSocket(unsigned int index=0)
NodeOutput are sockets that can send data/input.
Definition: COM_Node.h:258
StackEntry * from