[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43219] trunk/blender/source/blender: Improved auto-hiding of unused sockets for collapsed nodes.

Lukas Toenne lukas.toenne at googlemail.com
Sun Jan 8 11:23:31 CET 2012


Revision: 43219
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43219
Author:   lukastoenne
Date:     2012-01-08 10:23:19 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
Improved auto-hiding of unused sockets for collapsed nodes.

Instead of generally hiding all unused sockets in collapsed mode, the sockets now have a new explicit flag SOCK_AUTO_HIDDEN, which is only toggled when the hide_toggle operator is called. This way the auto-hidden sockets stay as they are when nodes are duplicated etc. The new flag is necessary to distinguish between manually hidden sockets (via hide_sockets_toggle operator) and automatically hidden sockets and restore the node state when unhiding a node.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_blender.h
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/space_node/node_draw.c
    trunk/blender/source/blender/editors/space_node/node_edit.c
    trunk/blender/source/blender/editors/space_node/node_intern.h
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/nodes/intern/node_common.c
    trunk/blender/source/blender/nodes/shader/node_shader_util.c

Modified: trunk/blender/source/blender/blenkernel/BKE_blender.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_blender.h	2012-01-08 05:10:52 UTC (rev 43218)
+++ trunk/blender/source/blender/blenkernel/BKE_blender.h	2012-01-08 10:23:19 UTC (rev 43219)
@@ -42,7 +42,7 @@
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION			261
-#define BLENDER_SUBVERSION		0
+#define BLENDER_SUBVERSION		1
 
 #define BLENDER_MINVERSION		250
 #define BLENDER_MINSUBVERSION	0

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2012-01-08 05:10:52 UTC (rev 43218)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2012-01-08 10:23:19 UTC (rev 43219)
@@ -374,6 +374,8 @@
 
 void			nodeFreePreview(struct bNode *node);
 
+int				nodeSocketIsHidden(struct bNodeSocket *sock);
+
 /* ************** NODE TYPE ACCESS *************** */
 
 struct bNodeTemplate nodeMakeTemplate(struct bNode *node);

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2012-01-08 05:10:52 UTC (rev 43218)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2012-01-08 10:23:19 UTC (rev 43219)
@@ -1325,6 +1325,11 @@
 		node->flag |= NODE_ACTIVE_TEXTURE;
 }
 
+int nodeSocketIsHidden(bNodeSocket *sock)
+{
+	return ((sock->flag & (SOCK_HIDDEN | SOCK_AUTO_HIDDEN | SOCK_UNAVAIL)) != 0);
+}
+
 /* ************** dependency stuff *********** */
 
 /* node is guaranteed to be not checked before */

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2012-01-08 05:10:52 UTC (rev 43218)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2012-01-08 10:23:19 UTC (rev 43219)
@@ -7547,6 +7547,32 @@
 	}
 }
 
+/* set the SOCK_AUTO_HIDDEN flag on collapsed nodes */
+static void do_versions_nodetree_socket_auto_hidden_flags_2_62(bNodeTree *ntree)
+{
+	bNode *node;
+	bNodeSocket *sock;
+	
+	for (node=ntree->nodes.first; node; node=node->next) {
+		if (node->flag & NODE_HIDDEN) {
+			for (sock=node->inputs.first; sock; sock=sock->next) {
+				if (sock->link==NULL)
+					sock->flag |= SOCK_AUTO_HIDDEN;
+			}
+			for(sock=node->outputs.first; sock; sock= sock->next) {
+				if(nodeCountSocketLinks(ntree, sock)==0)
+					sock->flag |= SOCK_AUTO_HIDDEN;
+			}
+		}
+		else {
+			for(sock=node->inputs.first; sock; sock= sock->next)
+				sock->flag &= ~SOCK_AUTO_HIDDEN;
+			for(sock=node->outputs.first; sock; sock= sock->next)
+				sock->flag &= ~SOCK_AUTO_HIDDEN;
+		}
+	}
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
 	/* WATCH IT!!!: pointers from libdata have not been converted */
@@ -12779,7 +12805,7 @@
 		}
 	}
 
-	/* put compatibility code here until next subversion bump */
+	if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 1))
 	{
 		{
 			/* update use flags for node sockets (was only temporary before) */
@@ -12879,8 +12905,45 @@
 				}
 			}
 		}
+		{
+			/* set the SOCK_AUTO_HIDDEN flag on collapsed nodes */
+			Scene *sce;
+			Material *mat;
+			Tex *tex;
+			Lamp *lamp;
+			World *world;
+			bNodeTree *ntree;
+
+			for (sce=main->scene.first; sce; sce=sce->id.next)
+				if (sce->nodetree)
+					do_versions_nodetree_socket_auto_hidden_flags_2_62(sce->nodetree);
+
+			for (mat=main->mat.first; mat; mat=mat->id.next)
+				if (mat->nodetree)
+					do_versions_nodetree_socket_auto_hidden_flags_2_62(mat->nodetree);
+
+			for (tex=main->tex.first; tex; tex=tex->id.next)
+				if (tex->nodetree)
+					do_versions_nodetree_socket_auto_hidden_flags_2_62(tex->nodetree);
+
+			for (lamp=main->lamp.first; lamp; lamp=lamp->id.next)
+				if (lamp->nodetree)
+					do_versions_nodetree_socket_auto_hidden_flags_2_62(lamp->nodetree);
+
+			for (world=main->world.first; world; world=world->id.next)
+				if (world->nodetree)
+					do_versions_nodetree_socket_auto_hidden_flags_2_62(world->nodetree);
+
+			for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
+				do_versions_nodetree_socket_auto_hidden_flags_2_62(ntree);
+		}
 	}
 
+	/* put compatibility code here until next subversion bump */
+	{
+		
+	}
+
 	/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
 	/* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 

Modified: trunk/blender/source/blender/editors/space_node/node_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_draw.c	2012-01-08 05:10:52 UTC (rev 43218)
+++ trunk/blender/source/blender/editors/space_node/node_draw.c	2012-01-08 10:23:19 UTC (rev 43219)
@@ -233,7 +233,7 @@
 
 	/* output sockets */
 	for(nsock= node->outputs.first; nsock; nsock= nsock->next) {
-		if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
+		if(!nodeSocketIsHidden(nsock)) {
 			nsock->locx= locx + node->width;
 			nsock->locy= dy - NODE_DYS;
 			dy-= NODE_DY;
@@ -312,7 +312,7 @@
 
 	/* input sockets */
 	for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
-		if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
+		if(!nodeSocketIsHidden(nsock)) {
 			nsock->locx= locx;
 			nsock->locy= dy - NODE_DYS;
 			dy-= NODE_DY;
@@ -351,10 +351,10 @@
 
 	/* calculate minimal radius */
 	for(nsock= node->inputs.first; nsock; nsock= nsock->next)
-		if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE))
+		if(!nodeSocketIsHidden(nsock))
 			totin++;
 	for(nsock= node->outputs.first; nsock; nsock= nsock->next)
-		if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE))
+		if(!nodeSocketIsHidden(nsock))
 			totout++;
 	
 	tot= MAX2(totin, totout);
@@ -371,7 +371,7 @@
 	rad=drad= (float)M_PI/(1.0f + (float)totout);
 	
 	for(nsock= node->outputs.first; nsock; nsock= nsock->next) {
-		if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE)) {
+		if(!nodeSocketIsHidden(nsock)) {
 			nsock->locx= node->totr.xmax - hiddenrad + (float)sin(rad)*hiddenrad;
 			nsock->locy= node->totr.ymin + hiddenrad + (float)cos(rad)*hiddenrad;
 			rad+= drad;
@@ -382,7 +382,7 @@
 	rad=drad= - (float)M_PI/(1.0f + (float)totin);
 	
 	for(nsock= node->inputs.first; nsock; nsock= nsock->next) {
-		if(!(nsock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (nsock->flag & SOCK_IN_USE)) {
+		if(!nodeSocketIsHidden(nsock)) {
 			nsock->locx= node->totr.xmin + hiddenrad + (float)sin(rad)*hiddenrad;
 			nsock->locy= node->totr.ymin + hiddenrad + (float)cos(rad)*hiddenrad;
 			rad+= drad;
@@ -713,7 +713,7 @@
 	for(sock= node->inputs.first; sock; sock= sock->next) {
 		bNodeSocketType *stype= ntreeGetSocketType(sock->type);
 		
-		if(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))
+		if(nodeSocketIsHidden(sock))
 			continue;
 		
 		node_socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
@@ -736,7 +736,7 @@
 		
 		RNA_pointer_create((ID*)ntree, &RNA_NodeSocket, sock, &sockptr);
 		
-		if(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))
+		if(nodeSocketIsHidden(sock))
 			continue;
 		
 		node_socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
@@ -854,12 +854,12 @@
 	
 	/* sockets */
 	for(sock= node->inputs.first; sock; sock= sock->next) {
-		if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (sock->flag & SOCK_IN_USE))
+		if(!nodeSocketIsHidden(sock))
 			node_socket_circle_draw(snode->nodetree, sock, socket_size);
 	}
 	
 	for(sock= node->outputs.first; sock; sock= sock->next) {
-		if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)) && (sock->flag & SOCK_IN_USE))
+		if(!nodeSocketIsHidden(sock))
 			node_socket_circle_draw(snode->nodetree, sock, socket_size);
 	}
 	

Modified: trunk/blender/source/blender/editors/space_node/node_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_edit.c	2012-01-08 05:10:52 UTC (rev 43218)
+++ trunk/blender/source/blender/editors/space_node/node_edit.c	2012-01-08 10:23:19 UTC (rev 43219)
@@ -1600,40 +1600,38 @@
 
 /* ********************** hidden sockets ******************** */
 
-int node_has_hidden_sockets(bNode *node)
+int node_has_hidden_sockets(bNode *node, short flag)
 {
 	bNodeSocket *sock;
 	
 	for(sock= node->inputs.first; sock; sock= sock->next)
-		if(sock->flag & SOCK_HIDDEN)
+		if(sock->flag & flag)
 			return 1;
 	for(sock= node->outputs.first; sock; sock= sock->next)
-		if(sock->flag & SOCK_HIDDEN)
+		if(sock->flag & flag)
 			return 1;
 	return 0;
 }
 
-/* note: call node_tree_verify_groups(snode->nodetree) after this
- */
-void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
+void node_set_hidden_sockets(SpaceNode *snode, bNode *node, short flag, int set)
 {	
 	bNodeSocket *sock;
 
 	if(set==0) {
 		for(sock= node->inputs.first; sock; sock= sock->next)
-			sock->flag &= ~SOCK_HIDDEN;
+			sock->flag &= ~flag;
 		for(sock= node->outputs.first; sock; sock= sock->next)
-			sock->flag &= ~SOCK_HIDDEN;
+			sock->flag &= ~flag;
 	}
 	else {
 		/* hide unused sockets */
 		for(sock= node->inputs.first; sock; sock= sock->next) {
 			if(sock->link==NULL)
-				sock->flag |= SOCK_HIDDEN;
+				sock->flag |= flag;
 		}
 		for(sock= node->outputs.first; sock; sock= sock->next) {
 			if(nodeCountSocketLinks(snode->edittree, sock)==0)
-				sock->flag |= SOCK_HIDDEN;
+				sock->flag |= flag;
 		}
 	}
 }
@@ -1680,14 +1678,14 @@
 
 			/* find a socket after the previously connected socket */
 			for(sock=sock->next; sock; sock= sock->next)
-				if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
+				if(!nodeSocketIsHidden(sock))
 					break;
 		}
 
 		/* find a socket starting from the first socket */
 		if(!sock) {
 			for(sock= tonode->outputs.first; sock; sock= sock->next)
-				if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
+				if(!nodeSocketIsHidden(sock))
 					break;
 		}
 		
@@ -1805,7 +1803,7 @@
 		
 		if(in_out & SOCK_IN) {
 			for(sock= node->inputs.first; sock; sock= sock->next) {
-				if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL))) {
+				if(!nodeSocketIsHidden(sock)) {
 					if(BLI_in_rctf(&rect, sock->locx, sock->locy)) {
 						if(node == visible_node(snode, &rect)) {
 							*nodep= node;
@@ -1818,7 +1816,7 @@
 		}
 		if(in_out & SOCK_OUT) {

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list