Fixing [#32210] "Character physics type colliding with sensor type" reported by Danie...
[blender.git] / source / blender / compositor / nodes / COM_MuteNode.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
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.
8  *
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.
13  *
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.
17  *
18  * Contributor: 
19  *              Jeroen Bakker 
20  *              Monique Dewanchand
21  */
22
23 #include <stdio.h>
24
25 #include "COM_MuteNode.h"
26 #include "COM_SocketConnection.h"
27 #include "COM_SetValueOperation.h"
28 #include "COM_SetVectorOperation.h"
29 #include "COM_SetColorOperation.h"
30
31 MuteNode::MuteNode(bNode *editorNode) : Node(editorNode)
32 {
33         /* pass */
34 }
35
36 void MuteNode::reconnect(ExecutionSystem *graph, OutputSocket *output)
37 {
38         vector<InputSocket *> &inputsockets = this->getInputSockets();
39         for (unsigned int index = 0; index < inputsockets.size(); index++) {
40                 InputSocket *input = inputsockets[index];
41                 if (input->getDataType() == output->getDataType()) {
42                         if (input->isConnected()) {
43                                 output->relinkConnections(input->getConnection()->getFromSocket(), false);
44                                 return;
45                         }
46                 }
47         }
48         
49         NodeOperation *operation = NULL;
50         switch (output->getDataType()) {
51                 case COM_DT_VALUE:
52                 {
53                         SetValueOperation *valueoperation = new SetValueOperation();
54                         valueoperation->setValue(0.0f);
55                         operation = valueoperation;
56                         break;
57                 }
58                 case COM_DT_VECTOR:
59                 {
60                         SetVectorOperation *vectoroperation = new SetVectorOperation();
61                         vectoroperation->setX(0.0f);
62                         vectoroperation->setY(0.0f);
63                         vectoroperation->setW(0.0f);
64                         operation = vectoroperation;
65                         break;
66                 }
67                 case COM_DT_COLOR:
68                 {
69                         SetColorOperation *coloroperation = new SetColorOperation();
70                         coloroperation->setChannel1(0.0f);
71                         coloroperation->setChannel2(0.0f);
72                         coloroperation->setChannel3(0.0f);
73                         coloroperation->setChannel4(0.0f);
74                         operation = coloroperation;
75                         break;
76                 }
77         }
78
79         if (operation) {
80                 output->relinkConnections(operation->getOutputSocket(), false);
81                 graph->addOperation(operation);
82         }
83
84         output->clearConnections();
85 }
86
87 void MuteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
88 {
89         vector<OutputSocket *> &outputsockets = this->getOutputSockets();
90
91         for (unsigned int index = 0; index < outputsockets.size(); index++) {
92                 OutputSocket *output = outputsockets[index];
93                 if (output->isConnected()) {
94                         reconnect(graph, output);
95                 }
96         }
97 }