~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/compositor/nodes/COM_MuteNode.cpp

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "COM_MuteNode.h"
 
24
#include "COM_SocketConnection.h"
 
25
#include "COM_SetValueOperation.h"
 
26
#include "COM_SetVectorOperation.h"
 
27
#include "COM_SetColorOperation.h"
 
28
 
 
29
extern "C" {
 
30
        #include "BLI_listbase.h"
 
31
}
 
32
 
 
33
MuteNode::MuteNode(bNode *editorNode) : Node(editorNode)
 
34
{
 
35
        /* pass */
 
36
}
 
37
 
 
38
void MuteNode::reconnect(ExecutionSystem *graph, OutputSocket *output)
 
39
{
 
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.
 
48
                                 */
 
49
                                input->unlinkConnections(graph);
 
50
                                return;
 
51
                        }
 
52
                }
 
53
        }
 
54
 
 
55
        createDefaultOutput(graph, output);
 
56
}
 
57
 
 
58
void MuteNode::createDefaultOutput(ExecutionSystem *graph, OutputSocket *output)
 
59
{
 
60
        NodeOperation *operation = NULL;
 
61
        switch (output->getDataType()) {
 
62
                case COM_DT_VALUE:
 
63
                {
 
64
                        SetValueOperation *valueoperation = new SetValueOperation();
 
65
                        valueoperation->setValue(0.0f);
 
66
                        operation = valueoperation;
 
67
                        break;
 
68
                }
 
69
                case COM_DT_VECTOR:
 
70
                {
 
71
                        SetVectorOperation *vectoroperation = new SetVectorOperation();
 
72
                        vectoroperation->setX(0.0f);
 
73
                        vectoroperation->setY(0.0f);
 
74
                        vectoroperation->setW(0.0f);
 
75
                        operation = vectoroperation;
 
76
                        break;
 
77
                }
 
78
                case COM_DT_COLOR:
 
79
                {
 
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;
 
86
                        break;
 
87
                }
 
88
        }
 
89
 
 
90
        if (operation) {
 
91
                output->relinkConnections(operation->getOutputSocket(), false);
 
92
                graph->addOperation(operation);
 
93
        }
 
94
 
 
95
        output->clearConnections();
 
96
}
 
97
 
 
98
template<class SocketType> void MuteNode::fillSocketMap(vector<SocketType *> &sockets, SocketMap &socketMap)
 
99
{
 
100
        for (typename vector<SocketType *>::iterator it = sockets.begin(); it != sockets.end(); it++) {
 
101
                Socket *socket = (Socket *) *it;
 
102
 
 
103
                socketMap.insert(std::pair<bNodeSocket *, Socket *>(socket->getbNodeSocket(), socket));
 
104
        }
 
105
}
 
106
 
 
107
void MuteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
 
108
{
 
109
        bNode *editorNode = this->getbNode();
 
110
        vector<OutputSocket *> &outputsockets = this->getOutputSockets();
 
111
 
 
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
 
114
         */
 
115
        if (editorNode->flag & NODE_MUTED) {
 
116
                vector<InputSocket *> &inputsockets = this->getInputSockets();
 
117
                vector<OutputSocket *> relinkedsockets;
 
118
                SocketMap socketMap;
 
119
                bNodeLink *link;
 
120
 
 
121
                this->fillSocketMap<OutputSocket>(outputsockets, socketMap);
 
122
                this->fillSocketMap<InputSocket>(inputsockets, socketMap);
 
123
 
 
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;
 
128
 
 
129
                                if (toSocket->isConnected()) {
 
130
                                        if (fromSocket->isConnected()) {
 
131
                                                toSocket->relinkConnections(fromSocket->getConnection()->getFromSocket(), false);
 
132
                                        }
 
133
                                        else {
 
134
                                                createDefaultOutput(graph, toSocket);
 
135
                                        }
 
136
 
 
137
                                        relinkedsockets.push_back(toSocket);
 
138
                                }
 
139
                        }
 
140
                }
 
141
 
 
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
 
144
                 *
 
145
                 * to deal with such cases create default operation for not-relinked output sockets
 
146
                 */
 
147
 
 
148
                for (unsigned int index = 0; index < outputsockets.size(); index++) {
 
149
                        OutputSocket *output = outputsockets[index];
 
150
 
 
151
                        if (output->isConnected()) {
 
152
                                bool relinked = false;
 
153
                                vector<OutputSocket *>::iterator it;
 
154
 
 
155
                                for (it = relinkedsockets.begin(); it != relinkedsockets.end(); it++) {
 
156
                                        if (*it == output) {
 
157
                                                relinked = true;
 
158
                                                break;
 
159
                                        }
 
160
                                }
 
161
 
 
162
                                if (!relinked)
 
163
                                        createDefaultOutput(graph, output);
 
164
                        }
 
165
                }
 
166
        }
 
167
        else {
 
168
                for (unsigned int index = 0; index < outputsockets.size(); index++) {
 
169
                        OutputSocket *output = outputsockets[index];
 
170
                        if (output->isConnected()) {
 
171
                                reconnect(graph, output);
 
172
                        }
 
173
                }
 
174
        }
 
175
}