This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/compositor/intern/COM_InputSocket.cpp
Jeroen Bakker 044e818cf8 ____
`````|````` | |        |                        ..'''' 
     |      | |        |______               .''       
     |      | |        |                  ..'          
     |      | |_______ |___________ ....''             
               merge to TRUNK!

 * The old compositor is still available (Debug Menu: 200)

This commit was brought to you by:

Developers:
 * Monique Dewanchand
 * Jeroen Bakker
 * Dalai Felinto
 * Lukas Tönne

Review:
 * Brecht van Lommel

Testers:
 * Nate Wiebe
 * Wolfgang Faehnle
 * Carlo Andreacchio
 * Daniel Salazar
 * Artur Mag
 * Christian Krupa
 * Francesco Siddi
 * Dan McGrath
 * Bassam Kurdali

But mostly by the community:
Gold:

    Joshua Faulkner
    Michael Tiemann
    Francesco Paglia
    Blender Guru
    Blender Developers Fund

Silver:

    Pablo Vazquez
    Joel Heethaar
    Amrein Olivier
    Ilias Karasavvidis
    Thomas Kumlehn
    Sebastian Koenig
    Hannu Hoffrén
    Benjamin Dansie
    Fred M'ule
    Michel Vilain
    Bradley Cathey
    Gianmichele Mariani
    Gottfried Hofmann
    Bjørnar Frøyse
    Valentijn Bruning
    Paul Holmes
    Clemens Rudolph
    Juris Graphix
    David Strebel
    Ronan Zeegers
    François Tarlier
    Felipe Andres Esquivel Reed
    Olaf Beckman
    Jesus Alberto Olmos Linares
    Kajimba
    Maria Figueiredo
    Alexandr Galperin
    Francesco Siddi
    Julio Iglesias Lopez
    Kjartan Tysdal
    Thomas Torfs
    Film Works
    Teruyuki Nakamura
    Roger Luethi
    Benoit Bolsee
    Stefan Abrahamsen
    Andreas Mattijat
    Xavier Bouchoux
    Blender 3D Graphics and Animation
    Henk Vostermans
    Daniel Blanco Delgado
    BlenderDay/2011
    Bradley Cathey
    Matthieu Dupont de Dinechin
    Gianmichele Mariani
    Jérôme Scaillet

Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó, 
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli, 
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein, 
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio, 
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel, 
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey, 
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter, 
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini, 
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch, 
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson, 
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song, 
Dylan Urquidi )
2012-05-17 12:49:33 +00:00

218 lines
6.9 KiB
C++

/*
* 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->connection = NULL;
this->resizeMode = COM_SC_CENTER;
}
InputSocket::InputSocket(DataType datatype, InputSocketResizeMode resizeMode) :Socket(datatype) {
this->connection = NULL;
this->resizeMode = resizeMode;
}
InputSocket::InputSocket(InputSocket* from) :Socket(from->getDataType()) {
this->connection = NULL;
this->resizeMode = from->getResizeMode();
}
int InputSocket::isInputSocket() const { return true; }
const int InputSocket::isConnected() const { return this->connection != NULL; }
void InputSocket::setConnection(SocketConnection *connection) {
this->connection = connection;
}
SocketConnection* InputSocket::getConnection() {return this->connection;}
void InputSocket::determineResolution(unsigned int resolution[],unsigned int preferredResolution[]) {
if (this->isConnected()){
this->connection->getFromSocket()->determineResolution(resolution, preferredResolution);
} else {
return;
}
}
DataType InputSocket::convertToSupportedDataType(DataType datatype) {
int supportedDataTypes = getDataType();
if (supportedDataTypes&datatype) {
return datatype;
}
bool candoValue = supportedDataTypes&COM_DT_VALUE;
bool candoVector = supportedDataTypes&COM_DT_VECTOR;
bool candoColor = supportedDataTypes&COM_DT_COLOR;
if (datatype == COM_DT_VALUE) {
if (candoColor) {
return COM_DT_COLOR;
} else if (candoVector) {
return COM_DT_VECTOR;
}
} else if (datatype == COM_DT_VECTOR) {
if (candoColor) {
return COM_DT_COLOR;
} else if (candoValue) {
return COM_DT_VALUE;
}
} else if (datatype == COM_DT_COLOR) {
if (candoVector) {
return COM_DT_VECTOR;
} else if (candoValue) {
return COM_DT_VALUE;
}
}
return this->getDataType();
}
void InputSocket::determineActualDataType() {
/// @note: this method is only called for inputsocket that are not connected.
/// @note: passes COM_DT_COLOR, the convertToSupportedDataType converts this to a capable DataType
this->setActualDataType(this->convertToSupportedDataType(COM_DT_COLOR));
#if 0 // XXX TODO check for proxy node and use output data type?
if (this->getGroupOutputSocket()) {
if (!this->isInsideOfGroupNode()) {
this->getGroupOutputSocket()->determineActualDataType();
}
}
#endif
}
void InputSocket::notifyActualInputType(DataType datatype) {
DataType supportedDataType = convertToSupportedDataType(datatype);
this->setActualDataType(supportedDataType);
this->fireActualDataTypeSet();
}
void InputSocket::fireActualDataTypeSet() {
this->getNode()->notifyActualDataTypeSet(this, this->getActualDataType());
}
void InputSocket::relinkConnections(InputSocket *relinkToSocket) {
this->relinkConnections(relinkToSocket, false, -1, NULL);
}
void InputSocket::relinkConnections(InputSocket *relinkToSocket, bool autoconnect, int editorNodeInputSocketIndex, bool duplicate, ExecutionSystem* graph) {
if (!duplicate) {
this->relinkConnections(relinkToSocket, autoconnect, editorNodeInputSocketIndex, graph);
} else {
if (!this->isConnected() && autoconnect) {
Node* node = (Node*)this->getNode();
switch (this->getActualDataType()) {
case COM_DT_UNKNOWN:
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, bool autoconnect, int editorNodeInputSocketIndex, ExecutionSystem* graph) {
if (!isConnected()) {
if (autoconnect) {
Node* node = (Node*)this->getNode();
switch (this->getActualDataType()) {
case COM_DT_UNKNOWN:
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 *connection = this->getConnection();
connection->setToSocket(relinkToSocket);
relinkToSocket->setConnection(connection);
this->setConnection(NULL);
}
const ChannelInfo* InputSocket::getChannelInfo(const int channelnumber) {
if (this->isConnected() && this->connection->getFromSocket()) {
return this->connection->getFromSocket()->getChannelInfo(channelnumber);
} else {
return NULL;
}
}
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->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;
}
}