Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_InputSocket.cpp « intern « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a9c280e03675713969efcfad5ca6da85271f0792 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * Copyright 2011, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor: 
 *		Jeroen Bakker 
 *		Monique Dewanchand
 */

#include "COM_Socket.h"
#include "COM_Node.h"
#include "COM_SocketConnection.h"
#include "COM_ExecutionSystem.h"

InputSocket::InputSocket(DataType datatype) : Socket(datatype)
{
	this->m_connection = NULL;
	this->m_resizeMode = COM_SC_CENTER;
}
InputSocket::InputSocket(DataType datatype, InputSocketResizeMode resizeMode) : Socket(datatype)
{
	this->m_connection = NULL;
	this->m_resizeMode = resizeMode;
}

InputSocket::InputSocket(InputSocket *from) : Socket(from->getDataType())
{
	this->m_connection = NULL;
	this->m_resizeMode = from->getResizeMode();
}

int InputSocket::isInputSocket() const { return true; }
const int InputSocket::isConnected() const { return this->m_connection != NULL; }

void InputSocket::setConnection(SocketConnection *connection)
{
	this->m_connection = connection;
}
SocketConnection *InputSocket::getConnection()
{
	return this->m_connection;
}

void InputSocket::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
{
	if (this->isConnected()) {
		this->m_connection->getFromSocket()->determineResolution(resolution, preferredResolution);
	}
	else {
		return;
	}
}

void InputSocket::relinkConnections(InputSocket *relinkToSocket)
{
	if (!isConnected()) {
		return;
	}
	SocketConnection *connection = this->getConnection();
	connection->setToSocket(relinkToSocket);
	relinkToSocket->setConnection(connection);
	this->setConnection(NULL);
}

void InputSocket::relinkConnectionsDuplicate(InputSocket *relinkToSocket, int editorNodeInputSocketIndex, ExecutionSystem *graph)
{
	if (!this->isConnected()) {
		Node *node = (Node *)this->getNode();
		switch (this->getDataType()) {
			case COM_DT_COLOR:
				node->addSetColorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
				break;
			case COM_DT_VECTOR:
				node->addSetVectorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
				break;
			case COM_DT_VALUE:
				node->addSetValueOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
				break;
		}
		return;
	}
	SocketConnection *newConnection = new SocketConnection();
	OutputSocket *fromSocket = this->getConnection()->getFromSocket();
	newConnection->setToSocket(relinkToSocket);
	newConnection->setFromSocket(fromSocket);
	relinkToSocket->setConnection(newConnection);
	fromSocket->addConnection(newConnection);
	graph->addSocketConnection(newConnection);
}

void InputSocket::relinkConnections(InputSocket *relinkToSocket,  int editorNodeInputSocketIndex, ExecutionSystem *graph)
{
	if (isConnected()) {
		relinkConnections(relinkToSocket);
	}
	else {
		Node *node = (Node *)this->getNode();
		switch (this->getDataType()) {
			case COM_DT_COLOR:
				node->addSetColorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
				break;
			case COM_DT_VECTOR:
				node->addSetVectorOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
				break;
			case COM_DT_VALUE:
				node->addSetValueOperation(graph, relinkToSocket, editorNodeInputSocketIndex);
				break;
		}
	}
}

bool InputSocket::isStatic()
{
	if (isConnected()) {
		NodeBase *node = this->getConnection()->getFromNode();
		if (node) {
			return node->isStatic();
		}
	}
	return true;
}
SocketReader *InputSocket::getReader()
{
	return this->getOperation();
}

NodeOperation *InputSocket::getOperation() const
{
	if (isConnected()) {
		return (NodeOperation *)this->m_connection->getFromSocket()->getNode();
	}
	else {
		return NULL;
	}
}

float *InputSocket::getStaticValues()
{
	/* XXX only works for socket types with actual float input values.
	 * currently all compositor socket types (value, rgba, vector) support this.
	 */
	bNodeSocket *b_socket = this->getbNodeSocket();
	static float default_null = 0.0f;
	
	switch (this->getDataType()) {
		case COM_DT_VALUE:
			return &((bNodeSocketValueFloat *)b_socket->default_value)->value;
		case COM_DT_COLOR:
			return ((bNodeSocketValueRGBA *)b_socket->default_value)->value;
		case COM_DT_VECTOR:
			return ((bNodeSocketValueVector *)b_socket->default_value)->value;
		default:
			/* XXX this should never happen, just added to please the compiler */
			return &default_null;
	}
}