[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44633] trunk/blender/source/blender/ editors/space_node/node_edit.c: Small feature for the viewer linking operator: When no viewer node is present in the tree, it automatically adds a new one next to the output socket.

Lukas Toenne lukas.toenne at googlemail.com
Sun Mar 4 11:49:26 CET 2012


Revision: 44633
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44633
Author:   lukastoenne
Date:     2012-03-04 10:49:13 +0000 (Sun, 04 Mar 2012)
Log Message:
-----------
Small feature for the viewer linking operator: When no viewer node is present in the tree, it automatically adds a new one next to the output socket.

Also changed the poll function of that operator to make sure it actually only works on compositor trees (others don't have viewer nodes).

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_node/node_edit.c

Modified: trunk/blender/source/blender/editors/space_node/node_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_edit.c	2012-03-04 04:35:12 UTC (rev 44632)
+++ trunk/blender/source/blender/editors/space_node/node_edit.c	2012-03-04 10:49:13 UTC (rev 44633)
@@ -1639,15 +1639,18 @@
 	}
 }
 
-static void node_link_viewer(SpaceNode *snode, bNode *tonode)
+static int node_link_viewer(const bContext *C, bNode *tonode)
 {
+	SpaceNode *snode = CTX_wm_space_node(C);
 	bNode *node;
+	bNodeLink *link;
+	bNodeSocket *sock;
 
 	/* context check */
 	if(tonode==NULL || tonode->outputs.first==NULL)
-		return;
+		return OPERATOR_CANCELLED;
 	if( ELEM(tonode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) 
-		return;
+		return OPERATOR_CANCELLED;
 	
 	/* get viewer */
 	for(node= snode->edittree->nodes.first; node; node= node->next)
@@ -1663,52 +1666,69 @@
 			}
 		}
 	}
-		
-	if(node) {
-		bNodeLink *link;
-		bNodeSocket *sock= NULL;
-
-		/* try to find an already connected socket to cycle to the next */
+	
+	sock = NULL;
+	
+	/* try to find an already connected socket to cycle to the next */
+	if (node) {
+		link = NULL;
 		for(link= snode->edittree->links.first; link; link= link->next)
 			if(link->tonode==node && link->fromnode==tonode)
 				if(link->tosock==node->inputs.first)
 					break;
-
 		if(link) {
 			/* unlink existing connection */
 			sock= link->fromsock;
 			nodeRemLink(snode->edittree, link);
-
+			
 			/* find a socket after the previously connected socket */
 			for(sock=sock->next; sock; sock= sock->next)
 				if(!nodeSocketIsHidden(sock))
 					break;
 		}
-
-		/* find a socket starting from the first socket */
-		if(!sock) {
-			for(sock= tonode->outputs.first; sock; sock= sock->next)
-				if(!nodeSocketIsHidden(sock))
-					break;
+	}
+	
+	/* find a socket starting from the first socket */
+	if(!sock) {
+		for(sock= tonode->outputs.first; sock; sock= sock->next)
+			if(!nodeSocketIsHidden(sock))
+				break;
+	}
+	
+	if(sock) {
+		/* add a new viewer if none exists yet */
+		if(!node) {
+			Main *bmain = CTX_data_main(C);
+			Scene *scene = CTX_data_scene(C);
+			bNodeTemplate ntemp;
+			
+			ntemp.type = CMP_NODE_VIEWER;
+			/* XXX location is a quick hack, just place it next to the linked socket */
+			node = node_add_node(snode, bmain, scene, &ntemp, sock->locx + 100, sock->locy);
+			if (!node)
+				return OPERATOR_CANCELLED;
+			
+			link = NULL;
 		}
-		
-		if(sock) {
+		else {
 			/* get link to viewer */
 			for(link= snode->edittree->links.first; link; link= link->next)
 				if(link->tonode==node && link->tosock==node->inputs.first)
 					break;
-			
-			if(link==NULL) {
-				nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first);
-			}
-			else {
-				link->fromnode= tonode;
-				link->fromsock= sock;
-			}
-			ntreeUpdateTree(snode->edittree);
-			snode_update(snode, node);
 		}
+		
+		if(link==NULL) {
+			nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first);
+		}
+		else {
+			link->fromnode= tonode;
+			link->fromsock= sock;
+		}
+		ntreeUpdateTree(snode->edittree);
+		snode_update(snode, node);
 	}
+	
+	return OPERATOR_FINISHED;
 }
 
 
@@ -1724,7 +1744,9 @@
 
 	ED_preview_kill_jobs(C);
 
-	node_link_viewer(snode, node);
+	if (node_link_viewer(C, node) == OPERATOR_CANCELLED)
+		return OPERATOR_CANCELLED;
+
 	snode_notify(C, snode);
 
 	return OPERATOR_FINISHED;
@@ -1741,7 +1763,7 @@
 	
 	/* api callbacks */
 	ot->exec= node_active_link_viewer;
-	ot->poll= ED_operator_node_active;
+	ot->poll= composite_node_active;
 	
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;




More information about the Bf-blender-cvs mailing list