____
[blender.git] / source / blender / compositor / nodes / COM_ZCombineNode.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 "COM_ZCombineNode.h"
24
25 #include "COM_ZCombineOperation.h"
26
27 #include "COM_ExecutionSystem.h"
28 #include "COM_SetValueOperation.h"
29 #include "COM_MathBaseOperation.h"
30
31 #include "DNA_material_types.h" // the ramp types
32
33 void ZCombineNode::convertToOperations(ExecutionSystem* system, CompositorContext * context) {
34         if (this->getOutputSocket(0)->isConnected()) {
35                 ZCombineOperation * operation = NULL;
36                 if (this->getbNode()->custom1) {
37                         operation = new ZCombineAlphaOperation();
38                 } else {
39                         operation = new ZCombineOperation();
40                 }
41
42                 this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), true, 0, system);
43                 this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), true, 1, system);
44                 this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), true, 2, system);
45                 this->getInputSocket(3)->relinkConnections(operation->getInputSocket(3), true, 3, system);
46                 this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
47                 system->addOperation(operation);
48                 if (this->getOutputSocket(1)->isConnected()) {
49                         MathMinimumOperation * zoperation = new MathMinimumOperation();
50                         addLink(system, operation->getInputSocket(1)->getConnection()->getFromSocket(), zoperation->getInputSocket(0));
51                         addLink(system, operation->getInputSocket(3)->getConnection()->getFromSocket(), zoperation->getInputSocket(1));
52                         this->getOutputSocket(1)->relinkConnections(zoperation->getOutputSocket());
53                         system->addOperation(zoperation);
54                 }
55         } else {
56                 if (this->getOutputSocket(1)->isConnected()) {
57                         MathMinimumOperation * zoperation = new MathMinimumOperation();
58                         this->getInputSocket(1)->relinkConnections(zoperation->getInputSocket(0), true, 1, system);
59                         this->getInputSocket(3)->relinkConnections(zoperation->getInputSocket(1), true, 3, system);
60                         this->getOutputSocket(1)->relinkConnections(zoperation->getOutputSocket());
61                         system->addOperation(zoperation);
62                 }
63         }
64 }