[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46175] trunk/blender/source/blender: A number of changes to node RNA and the file output node, to simplify socket types and make node code more robust for future nodes with extra socket data .

Lukas Toenne lukas.toenne at googlemail.com
Wed May 2 09:18:52 CEST 2012


Revision: 46175
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46175
Author:   lukastoenne
Date:     2012-05-02 07:18:51 +0000 (Wed, 02 May 2012)
Log Message:
-----------
A number of changes to node RNA and the file output node, to simplify socket types and make node code more robust for future nodes with extra socket data.

* Removed the struct_type identifier from sockets completely. Any specialization of socket types can be done by using separate collections in RNA and customized socket draw callbacks in node type. Sockets themselves are pure data inputs/outputs now. Possibly the sock->storage data could also be removed, but this will change anyway with id properties in custom nodes.

* Replaced the direct socket button draw calls by extra callbacks in node types. This allows nodes to draw sockets in specialized ways without referring to the additional struct_type identifier. Default is simply drawing the socket default_value button, only file output node overrides this atm.

* File output node slots now use a separate file sub-path in their storage data, instead of using the socket name. That way the path is an actual PROP_FILEPATH property and it works better with the UI list template (name property is local to the data struct).

* Node draw contexts for options on the node itself and detail buttons in the sidebar now have an extra context pointer "node" (uiLayoutSetContextPointer). This can be used to bind operator buttons to a specific node, instead of having to rely on the active/selected node(s) or making weak links via node name. Compare to modifiers and logic bricks, they use the same feature.

* Added another operator for reordering custom input slots in the file output node.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_node/node_buttons.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/editors/space_node/node_ops.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/nodes/composite/nodes/node_composite_outputFile.c

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2012-05-01 23:22:58 UTC (rev 46174)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2012-05-02 07:18:51 UTC (rev 46175)
@@ -145,6 +145,9 @@
 	void (*uifunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
 	/// Additional parameters in the side panel.
 	void (*uifuncbut)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
+	/// Draw a node socket. Default draws the input value button.
+	NodeSocketButtonFunction drawinputfunc;
+	NodeSocketButtonFunction drawoutputfunc;
 	/// Optional custom label function for the node header.
 	const char *(*labelfunc)(struct bNode *);
 	/// Optional custom resize handle polling.

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2012-05-01 23:22:58 UTC (rev 46174)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2012-05-02 07:18:51 UTC (rev 46175)
@@ -7786,6 +7786,23 @@
 	}
 }
 
+static void do_versions_nodetree_multi_file_output_path_2_64_0(bNodeTree *ntree)
+{
+	bNode *node;
+	
+	for (node=ntree->nodes.first; node; node=node->next) {
+		if (node->type==CMP_NODE_OUTPUT_FILE) {
+			bNodeSocket *sock;
+			for (sock=node->inputs.first; sock; sock=sock->next) {
+				NodeImageMultiFileSocket *input = sock->storage;
+				/* input file path is stored in dedicated struct now instead socket name */
+				BLI_strncpy(input->path, sock->name, sizeof(input->path));
+				sock->name[0] = '\0';	/* unused */
+			}
+		}
+	}
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
 	/* WATCH IT!!!: pointers from libdata have not been converted */
@@ -13282,10 +13299,23 @@
 
 
 	if (main->versionfile < 263) {
-		/* Default for old files is to save particle rotations to pointcache */
-		ParticleSettings *part;
-		for (part = main->particle.first; part; part = part->id.next)
-			part->flag |= PART_ROTATIONS;
+		{
+			/* Default for old files is to save particle rotations to pointcache */
+			ParticleSettings *part;
+			for (part = main->particle.first; part; part = part->id.next)
+				part->flag |= PART_ROTATIONS;
+		}
+		{
+			/* file output node paths are now stored in the file info struct instead socket name */
+			Scene *sce;
+			bNodeTree *ntree;
+			
+			for (sce = main->scene.first; sce; sce=sce->id.next)
+				if (sce->nodetree)
+					do_versions_nodetree_multi_file_output_path_2_64_0(sce->nodetree);
+			for (ntree = main->nodetree.first; ntree; ntree=ntree->id.next)
+				do_versions_nodetree_multi_file_output_path_2_64_0(ntree);
+		}
 	}
 
 	if (main->versionfile <= 263 && main->subversionfile == 0) {

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2012-05-01 23:22:58 UTC (rev 46174)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2012-05-02 07:18:51 UTC (rev 46175)
@@ -98,72 +98,24 @@
 	uiDefBut(block, LABEL, 0, sock->name, x, y, width, NODE_DY, NULL, 0, 0, 0, 0, "");
 }
 
-/* draw function for file output node sockets.
- * XXX a bit ugly use atm, called from datatype button functions,
- * since all node types and callbacks only use data type without struct_type.
- */
-static void node_socket_button_output_file(const bContext *C, uiBlock *block,
-                                           bNodeTree *ntree, bNode *node, bNodeSocket *sock,
-                                           const char *UNUSED(name), int x, int y, int width)
-{
-	uiLayout *layout, *row;
-	PointerRNA nodeptr, sockptr, imfptr;
-	int imtype;
-	int rx, ry;
-	RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);
-	RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &sockptr);
-	
-	layout = uiBlockLayout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, x, y+NODE_DY, width, 20, UI_GetStyle());
-	row = uiLayoutRow(layout, 0);		
-	
-	uiItemL(row, sock->name, 0);
-	
-	imfptr = RNA_pointer_get(&nodeptr, "format");
-	imtype = RNA_enum_get(&imfptr, "file_format");
-	/* in multilayer format all socket format details are ignored */
-	if (imtype != R_IMF_IMTYPE_MULTILAYER) {
-		PropertyRNA *imtype_prop;
-		const char *imtype_name;
-		
-		if (!RNA_boolean_get(&sockptr, "use_node_format"))
-			imfptr = RNA_pointer_get(&sockptr, "format");
-		
-		imtype_prop = RNA_struct_find_property(&imfptr, "file_format");
-		RNA_property_enum_name((bContext*)C, &imfptr, imtype_prop, RNA_property_enum_get(&imfptr, imtype_prop), &imtype_name);
-		uiBlockSetEmboss(block, UI_EMBOSSP);
-		uiItemL(row, imtype_name, 0);
-		uiBlockSetEmboss(block, UI_EMBOSSN);
-	}
-	
-	uiBlockLayoutResolve(block, &rx, &ry);
-}
-
 static void node_socket_button_default(const bContext *C, uiBlock *block,
 								bNodeTree *ntree, bNode *node, bNodeSocket *sock,
 								const char *name, int x, int y, int width)
 {
-	switch (sock->struct_type) {
-	case SOCK_STRUCT_NONE: {
-		if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
-			node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
-		else {
-			PointerRNA ptr;
-			uiBut *bt;
-			
-			RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
-			
-			bt = uiDefButR(block, NUM, B_NODE_EXEC, name,
-						   x, y+1, width, NODE_DY-2, 
-						   &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
-			if (node)
-				uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
-		}
-		break;
+	if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
+		node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
+	else {
+		PointerRNA ptr;
+		uiBut *bt;
+		
+		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
+		
+		bt = uiDefButR(block, NUM, B_NODE_EXEC, name,
+					   x, y+1, width, NODE_DY-2, 
+					   &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
+		if (node)
+			uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
 	}
-	case SOCK_STRUCT_OUTPUT_FILE:
-		node_socket_button_output_file(C, block, ntree, node, sock, name, x, y, width);
-		break;
-	}
 }
 
 typedef struct SocketComponentMenuArgs {
@@ -192,69 +144,78 @@
 								   bNodeTree *ntree, bNode *node, bNodeSocket *sock,
 								   const char *name, int x, int y, int width)
 {
-	switch (sock->struct_type) {
-	case SOCK_STRUCT_NONE: {
-		if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
-			node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
-		else {
-			PointerRNA ptr;
-			SocketComponentMenuArgs *args;
-			
-			RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
-			
-			args= MEM_callocN(sizeof(SocketComponentMenuArgs), "SocketComponentMenuArgs");
-			
-			args->ptr = ptr;
-			args->x = x;
-			args->y = y;
-			args->width = width;
-			args->cb = node_sync_cb;
-			args->arg1 = CTX_wm_space_node(C);
-			args->arg2 = node;
-			
-			uiDefBlockButN(block, socket_component_menu, args, name, x, y+1, width, NODE_DY-2, "");
-		}
-		break;
+	if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
+		node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
+	else {
+		PointerRNA ptr;
+		SocketComponentMenuArgs *args;
+		
+		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
+		
+		args= MEM_callocN(sizeof(SocketComponentMenuArgs), "SocketComponentMenuArgs");
+		
+		args->ptr = ptr;
+		args->x = x;
+		args->y = y;
+		args->width = width;
+		args->cb = node_sync_cb;
+		args->arg1 = CTX_wm_space_node(C);
+		args->arg2 = node;
+		
+		uiDefBlockButN(block, socket_component_menu, args, name, x, y+1, width, NODE_DY-2, "");
 	}
-	case SOCK_STRUCT_OUTPUT_FILE:
-		node_socket_button_output_file(C, block, ntree, node, sock, name, x, y, width);
-		break;
-	}
 }
 
 static void node_socket_button_color(const bContext *C, uiBlock *block,
 							  bNodeTree *ntree, bNode *node, bNodeSocket *sock,
 							  const char *name, int x, int y, int width)
 {
-	/* XXX would be nicer to have draw function based on sock->struct_type as well,
-	 * but currently socket types are completely identified by data type only.
-	 */
-	
-	switch (sock->struct_type) {
-	case SOCK_STRUCT_NONE: {
-		if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
-			node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
-		else {
-			PointerRNA ptr;
-			uiBut *bt;
-			int labelw= width - 40;
-			RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
-			
-			bt=uiDefButR(block, COL, B_NODE_EXEC, "",
-						 x, y+2, (labelw>0 ? 40 : width), NODE_DY-2, 
-						 &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
-			if (node)
-				uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
-			
-			if (name[0]!='\0' && labelw>0)
-				uiDefBut(block, LABEL, 0, name, x + 40, y+2, labelw, NODE_DY-2, NULL, 0, 0, 0, 0, "");
-		}
-		break;
+	if (sock->link || (sock->flag & SOCK_HIDE_VALUE))
+		node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
+	else {
+		PointerRNA ptr;
+		uiBut *bt;
+		int labelw= width - 40;
+		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, sock, &ptr);
+		
+		bt=uiDefButR(block, COL, B_NODE_EXEC, "",
+					 x, y+2, (labelw>0 ? 40 : width), NODE_DY-2, 
+					 &ptr, "default_value", 0, 0, 0, -1, -1, NULL);
+		if (node)
+			uiButSetFunc(bt, node_sync_cb, CTX_wm_space_node(C), node);
+		
+		if (name[0]!='\0' && labelw>0)
+			uiDefBut(block, LABEL, 0, name, x + 40, y+2, labelw, NODE_DY-2, NULL, 0, 0, 0, 0, "");
 	}
-	case SOCK_STRUCT_OUTPUT_FILE:
-		node_socket_button_output_file(C, block, ntree, node, sock, name, x, y, width);
-		break;
+}
+
+/* standard draw function, display the default input value */
+static void node_draw_input_default(const bContext *C, uiBlock *block,
+                                     bNodeTree *ntree, bNode *node, bNodeSocket *sock,
+                                     const char *name, int x, int y, int width)
+{
+	bNodeSocketType *stype = ntreeGetSocketType(sock->type);
+	if (stype->buttonfunc)
+		stype->buttonfunc(C, block, ntree, node, sock, name, x, y, width);
+	else
+		node_socket_button_label(C, block, ntree, node, sock, name, x, y, width);
+}
+
+static void node_draw_output_default(const bContext *C, uiBlock *block,
+                                     bNodeTree *UNUSED(ntree), bNode *node, bNodeSocket *sock,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list