Fix incorrect connections for muted nodes in tile compositor
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 30 Jul 2012 09:46:14 +0000 (09:46 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 30 Jul 2012 09:46:14 +0000 (09:46 +0000)
Not tile compositor would use the same routines to detect which
links to add for muted node.

source/blender/compositor/nodes/COM_MuteNode.cpp
source/blender/compositor/nodes/COM_MuteNode.h

index f52b7216ccac3524289c84d6abe4222142a62707..7b9dcf686fcfa049fdb9f39685808e907e6fc4d9 100644 (file)
  *             Monique Dewanchand
  */
 
-#include <stdio.h>
-
 #include "COM_MuteNode.h"
 #include "COM_SocketConnection.h"
 #include "COM_SetValueOperation.h"
 #include "COM_SetVectorOperation.h"
 #include "COM_SetColorOperation.h"
 
+extern "C" {
+       #include "BLI_listbase.h"
+}
+
 MuteNode::MuteNode(bNode *editorNode) : Node(editorNode)
 {
        /* pass */
@@ -84,14 +86,49 @@ void MuteNode::reconnect(ExecutionSystem *graph, OutputSocket *output)
        output->clearConnections();
 }
 
+template<class SocketType> void MuteNode::fillSocketMap(vector<SocketType *> &sockets, SocketMap &socketMap)
+{
+       for (typename vector<SocketType *>::iterator it = sockets.begin(); it != sockets.end(); it++) {
+               Socket *socket = (Socket *) *it;
+
+               socketMap.insert(std::pair<bNodeSocket *, Socket *>(socket->getbNodeSocket(), socket));
+       }
+}
+
 void MuteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
 {
+       bNode *editorNode = this->getbNode();
        vector<OutputSocket *> &outputsockets = this->getOutputSockets();
 
-       for (unsigned int index = 0; index < outputsockets.size(); index++) {
-               OutputSocket *output = outputsockets[index];
-               if (output->isConnected()) {
-                       reconnect(graph, output);
+       if (editorNode->typeinfo->internal_connect) {
+               vector<InputSocket *> &inputsockets = this->getInputSockets();
+               bNodeTree *editorTree = (bNodeTree *) context->getbNodeTree();
+               SocketMap socketMap;
+               ListBase intlinks;
+               bNodeLink *link;
+
+               intlinks = editorNode->typeinfo->internal_connect(editorTree, editorNode);
+
+               this->fillSocketMap<OutputSocket>(outputsockets, socketMap);
+               this->fillSocketMap<InputSocket>(inputsockets, socketMap);
+
+               for (link = (bNodeLink *) intlinks.first; link; link = link->next) {
+                       if (link->fromnode == editorNode) {
+                               InputSocket *fromSocket = (InputSocket *) socketMap.find(link->fromsock)->second;
+                               OutputSocket *toSocket = (OutputSocket *) socketMap.find(link->tosock)->second;
+
+                               toSocket->relinkConnections(fromSocket->getConnection()->getFromSocket(), false);
+                       }
+               }
+
+               BLI_freelistN(&intlinks);
+       }
+       else {
+               for (unsigned int index = 0; index < outputsockets.size(); index++) {
+                       OutputSocket *output = outputsockets[index];
+                       if (output->isConnected()) {
+                               reconnect(graph, output);
+                       }
                }
        }
 }
index aab37e5f888225439fdadd0a81221d3085609d5d..44fbe6e80c6145ba3dda7c1b937f0cc2aba68ea7 100644 (file)
 #ifndef _COM_MuteNode_h_
 #define _COM_MuteNode_h_
 
+#include <map>
+
 #include "COM_Node.h"
 
+extern "C" {
+       #include "BKE_node.h"
+}
+
 /**
  * @brief MuteNode
  * @ingroup Node
@@ -34,7 +40,11 @@ public:
        MuteNode(bNode *editorNode);
        void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
 private:
+       typedef std::map<bNodeSocket *, Socket *> SocketMap;
+
        void reconnect(ExecutionSystem *graph, OutputSocket *output);
+
+       template<class SocketType> void fillSocketMap(vector<SocketType *> &sockets, SocketMap &socketMap);
 };
 
 #endif