2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include "COM_MuteNode.h"
24
#include "COM_SocketConnection.h"
25
#include "COM_SetValueOperation.h"
26
#include "COM_SetVectorOperation.h"
27
#include "COM_SetColorOperation.h"
30
#include "BLI_listbase.h"
33
MuteNode::MuteNode(bNode *editorNode) : Node(editorNode)
38
void MuteNode::reconnect(ExecutionSystem *graph, OutputSocket *output)
40
vector<InputSocket *> &inputsockets = this->getInputSockets();
41
for (unsigned int index = 0; index < inputsockets.size(); index++) {
42
InputSocket *input = inputsockets[index];
43
if (input->getDataType() == output->getDataType()) {
44
if (input->isConnected()) {
45
output->relinkConnections(input->getConnection()->getFromSocket(), false);
46
/* output connections have been redirected,
47
* remove the input connection to completely unlink the node.
49
input->unlinkConnections(graph);
55
createDefaultOutput(graph, output);
58
void MuteNode::createDefaultOutput(ExecutionSystem *graph, OutputSocket *output)
60
NodeOperation *operation = NULL;
61
switch (output->getDataType()) {
64
SetValueOperation *valueoperation = new SetValueOperation();
65
valueoperation->setValue(0.0f);
66
operation = valueoperation;
71
SetVectorOperation *vectoroperation = new SetVectorOperation();
72
vectoroperation->setX(0.0f);
73
vectoroperation->setY(0.0f);
74
vectoroperation->setW(0.0f);
75
operation = vectoroperation;
80
SetColorOperation *coloroperation = new SetColorOperation();
81
coloroperation->setChannel1(0.0f);
82
coloroperation->setChannel2(0.0f);
83
coloroperation->setChannel3(0.0f);
84
coloroperation->setChannel4(0.0f);
85
operation = coloroperation;
91
output->relinkConnections(operation->getOutputSocket(), false);
92
graph->addOperation(operation);
95
output->clearConnections();
98
template<class SocketType> void MuteNode::fillSocketMap(vector<SocketType *> &sockets, SocketMap &socketMap)
100
for (typename vector<SocketType *>::iterator it = sockets.begin(); it != sockets.end(); it++) {
101
Socket *socket = (Socket *) *it;
103
socketMap.insert(std::pair<bNodeSocket *, Socket *>(socket->getbNodeSocket(), socket));
107
void MuteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
109
bNode *editorNode = this->getbNode();
110
vector<OutputSocket *> &outputsockets = this->getOutputSockets();
112
/* mute node is also used for unknown nodes and couple of nodes in fast mode
113
* can't use generic routines in that case
115
if (editorNode->flag & NODE_MUTED) {
116
vector<InputSocket *> &inputsockets = this->getInputSockets();
117
vector<OutputSocket *> relinkedsockets;
121
this->fillSocketMap<OutputSocket>(outputsockets, socketMap);
122
this->fillSocketMap<InputSocket>(inputsockets, socketMap);
124
for (link = (bNodeLink *) editorNode->internal_links.first; link; link = link->next) {
125
if (link->fromnode == editorNode) {
126
InputSocket *fromSocket = (InputSocket *) socketMap.find(link->fromsock)->second;
127
OutputSocket *toSocket = (OutputSocket *) socketMap.find(link->tosock)->second;
129
if (toSocket->isConnected()) {
130
if (fromSocket->isConnected()) {
131
toSocket->relinkConnections(fromSocket->getConnection()->getFromSocket(), false);
134
createDefaultOutput(graph, toSocket);
137
relinkedsockets.push_back(toSocket);
142
/* in some cases node could be marked as muted, but it wouldn't have internal connections
143
* this happens in such cases as muted render layer node
145
* to deal with such cases create default operation for not-relinked output sockets
148
for (unsigned int index = 0; index < outputsockets.size(); index++) {
149
OutputSocket *output = outputsockets[index];
151
if (output->isConnected()) {
152
bool relinked = false;
153
vector<OutputSocket *>::iterator it;
155
for (it = relinkedsockets.begin(); it != relinkedsockets.end(); it++) {
163
createDefaultOutput(graph, output);
168
for (unsigned int index = 0; index < outputsockets.size(); index++) {
169
OutputSocket *output = outputsockets[index];
170
if (output->isConnected()) {
171
reconnect(graph, output);