rename remaining class members with m_ prefix.
[blender.git] / source / blender / compositor / intern / COM_OutputSocket.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_Socket.h"
24 #include "COM_Node.h"
25 #include "COM_SocketConnection.h"
26 #include "COM_NodeOperation.h"
27
28 OutputSocket::OutputSocket(DataType datatype) : Socket(datatype)
29 {
30         /* pass */
31 }
32
33 int OutputSocket::isOutputSocket() const { return true; }
34 const int OutputSocket::isConnected() const { return this->m_connections.size() != 0; }
35
36 void OutputSocket::determineResolution(unsigned int resolution[], unsigned int preferredResolution[])
37 {
38         NodeBase *node = this->getNode();
39         if (node->isOperation()) {
40                 NodeOperation *operation = (NodeOperation *)node;
41                 if (operation->isResolutionSet()) {
42                         resolution[0] = operation->getWidth();
43                         resolution[1] = operation->getHeight();
44                 }
45                 else {
46                         operation->determineResolution(resolution, preferredResolution);
47                         operation->setResolution(resolution);
48                 }
49         }
50 }
51
52 void OutputSocket::addConnection(SocketConnection *connection)
53 {
54         this->m_connections.push_back(connection);
55 }
56
57 void OutputSocket::relinkConnections(OutputSocket *relinkToSocket, bool single)
58 {
59         if (isConnected()) {
60                 if (single) {
61                         SocketConnection *connection = this->m_connections[0];
62                         connection->setFromSocket(relinkToSocket);
63                         relinkToSocket->addConnection(connection);
64                         this->m_connections.erase(this->m_connections.begin());
65                 }
66                 else {
67                         unsigned int index;
68                         for (index = 0; index < this->m_connections.size(); index++) {
69                                 SocketConnection *connection = this->m_connections[index];
70                                 connection->setFromSocket(relinkToSocket);
71                                 relinkToSocket->addConnection(connection);
72                         }
73                         this->m_connections.clear();
74                 }
75         }
76 }
77 void OutputSocket::removeFirstConnection()
78 {
79         SocketConnection *connection = this->m_connections[0];
80         InputSocket *inputSocket = connection->getToSocket();
81         if (inputSocket != NULL) {
82                 inputSocket->setConnection(NULL);
83         }
84         this->m_connections.erase(this->m_connections.begin());
85 }
86
87 void OutputSocket::clearConnections()
88 {
89         while (this->isConnected()) {
90                 removeFirstConnection();
91         }
92 }
93
94 WriteBufferOperation *OutputSocket::findAttachedWriteBufferOperation() const
95 {
96         unsigned int index;
97         for (index = 0; index < this->m_connections.size(); index++) {
98                 SocketConnection *connection = this->m_connections[index];
99                 NodeBase *node = connection->getToNode();
100                 if (node->isOperation()) {
101                         NodeOperation *operation = (NodeOperation *)node;
102                         if (operation->isWriteBufferOperation()) {
103                                 return (WriteBufferOperation *)operation;
104                         }
105                 }
106         }
107         return NULL;
108 }
109