[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32700] branches/particles-2010/source/ blender: Added a separate callback for buttons in the "N"-panel for nodes.

Lukas Toenne lukas.toenne at googlemail.com
Mon Oct 25 13:55:23 CEST 2010


Revision: 32700
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32700
Author:   lukastoenne
Date:     2010-10-25 13:55:23 +0200 (Mon, 25 Oct 2010)

Log Message:
-----------
Added a separate callback for buttons in the "N"-panel for nodes. In case this callback is not defined (default) the usual ui function for node options is used. This callback is currently defined for data nodes, which use it to provide additional buttons for adding and removing property sockets. This avoids cluttering up the node itself with lots of tiny, seldomly used buttons.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/editors/space_node/drawnode.c
    branches/particles-2010/source/blender/editors/space_node/node_buttons.c
    branches/particles-2010/source/blender/editors/space_node/node_edit.c
    branches/particles-2010/source/blender/editors/space_node/node_intern.h
    branches/particles-2010/source/blender/editors/space_node/node_ops.c
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-10-25 10:53:33 UTC (rev 32699)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-10-25 11:55:23 UTC (rev 32700)
@@ -100,6 +100,7 @@
 	void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **);
 	
 	/* this line is set on startup of blender */
+	/* node options ui */
 	void (*uifunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
 
 	void (*initfunc)(struct bNode *);
@@ -114,6 +115,9 @@
 	/* gpu */
 	int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out);
 
+	/* node buttons ui */
+	void (*buttonfunc)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr);
+
 	/* called when the node is updated (e.g. linked) in the editor. */
 	void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node);
 

Modified: branches/particles-2010/source/blender/editors/space_node/drawnode.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/drawnode.c	2010-10-25 10:53:33 UTC (rev 32699)
+++ branches/particles-2010/source/blender/editors/space_node/drawnode.c	2010-10-25 11:55:23 UTC (rev 32700)
@@ -1269,6 +1269,16 @@
 	}
 }
 
+static void node_simulation_buts_getdata(uiLayout *layout, bContext *C, PointerRNA *ptr)
+{
+	uiLayout *col;
+	
+	col= uiLayoutColumn(layout, 0);
+	uiLayoutSetContextPointer(col, "node", ptr);
+
+	uiItemR(col, ptr, "path", 0, NULL, 0);
+}
+
 static void getdata_add_property_exec_cb(bContext *C, void *arg1, void *arg2)
 {
 	SpaceNode *snode= CTX_wm_space_node(C);
@@ -1303,20 +1313,43 @@
 	but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X*6, UI_UNIT_Y, 0, 0, "");
 	uiButSetSearchFunc(but, getdata_add_property_search_cb, node, getdata_add_property_exec_cb, NULL);
 }
-static void node_simulation_buts_getdata(uiLayout *layout, bContext *C, PointerRNA *ptr)
+static void node_simulation_detailbuts_getdata(uiLayout *layout, bContext *C, PointerRNA *ptr)
 {
 	bNode *node= ptr->data;
-	uiLayout *col;
+	bNodeSocket *sock;
+	PointerRNA sockptr;
+	uiLayout *col, *row;
 	
 	col= uiLayoutColumn(layout, 0);
 	uiLayoutSetContextPointer(col, "node", ptr);
 
-	uiItemR(col, ptr, "typename", 0, NULL, 0);
 	uiItemR(col, ptr, "path", 0, NULL, 0);
 	
-	getdata_add_property_search(layout, node);
+	uiItemR(col, ptr, "typename", 0, NULL, 0);
+	getdata_add_property_search(col, node);
+	
+	uiItemS(col);
+	uiItemL(col, "Property Sockets", 0);
+	for (sock=node->outputs.first; sock; sock=sock->next) {
+		row= uiLayoutRow(col, 0);
+		RNA_pointer_create((ID*)ptr->id.data, &RNA_NodeSocket, sock, &sockptr);
+		uiLayoutSetContextPointer(row, "socket", &sockptr);
+		
+		uiItemR(row, &sockptr, "name", 0, "", 0);
+		uiItemO(row, "", ICON_X, "NODE_OT_property_socket_remove");
+	}
 }
 
+static void node_simulation_buts_setdata(uiLayout *layout, bContext *C, PointerRNA *ptr)
+{
+	uiLayout *col;
+	
+	col= uiLayoutColumn(layout, 0);
+	uiLayoutSetContextPointer(col, "node", ptr);
+
+	uiItemR(col, ptr, "path", 0, NULL, 0);
+}
+
 static void setdata_add_property_exec_cb(bContext *C, void *arg1, void *arg2)
 {
 	SpaceNode *snode= CTX_wm_space_node(C);
@@ -1351,18 +1384,31 @@
 	but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 0, 0, UI_UNIT_X*6, UI_UNIT_Y, 0, 0, "");
 	uiButSetSearchFunc(but, setdata_add_property_search_cb, node, setdata_add_property_exec_cb, NULL);
 }
-static void node_simulation_buts_setdata(uiLayout *layout, bContext *C, PointerRNA *ptr)
+static void node_simulation_detailbuts_setdata(uiLayout *layout, bContext *C, PointerRNA *ptr)
 {
 	bNode *node= ptr->data;
-	uiLayout *col;
+	bNodeSocket *sock;
+	PointerRNA sockptr;
+	uiLayout *col, *row;
 	
 	col= uiLayoutColumn(layout, 0);
 	uiLayoutSetContextPointer(col, "node", ptr);
 
+	uiItemR(col, ptr, "path", 0, NULL, 0);
+
 	uiItemR(col, ptr, "typename", 0, NULL, 0);
-	uiItemR(col, ptr, "path", 0, NULL, 0);
+	setdata_add_property_search(col, node);
 	
-	setdata_add_property_search(layout, node);
+	uiItemS(col);
+	uiItemL(col, "Property Sockets", 0);
+	for (sock=node->inputs.first; sock; sock=sock->next) {
+		row= uiLayoutRow(col, 0);
+		RNA_pointer_create((ID*)ptr->id.data, &RNA_NodeSocket, sock, &sockptr);
+		uiLayoutSetContextPointer(row, "socket", &sockptr);
+		
+		uiItemR(row, &sockptr, "name", 0, "", 0);
+		uiItemO(row, "", ICON_X, "NODE_OT_property_socket_remove");
+	}
 }
 
 static void node_simulation_buts_while(uiLayout *layout, bContext *C, PointerRNA *ptr)
@@ -1379,9 +1425,11 @@
 	switch(ntype->type) {
 	case SIM_NODE_GETDATA:
 		ntype->uifunc = node_simulation_buts_getdata;
+		ntype->buttonfunc = node_simulation_detailbuts_getdata;
 		break;
 	case SIM_NODE_SETDATA:
 		ntype->uifunc = node_simulation_buts_setdata;
+		ntype->buttonfunc = node_simulation_detailbuts_setdata;
 		break;
 	case SIM_NODE_WHILE:
 		ntype->uifunc = node_simulation_buts_while;

Modified: branches/particles-2010/source/blender/editors/space_node/node_buttons.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/node_buttons.c	2010-10-25 10:53:33 UTC (rev 32699)
+++ branches/particles-2010/source/blender/editors/space_node/node_buttons.c	2010-10-25 11:55:23 UTC (rev 32700)
@@ -111,7 +111,9 @@
 	// TODO: a separator would be nice...
 	
 	/* draw this node's settings */
-	if (node->typeinfo && node->typeinfo->uifunc)
+	if (node->typeinfo && node->typeinfo->buttonfunc)
+		node->typeinfo->buttonfunc(layout, (bContext *)C, &ptr);
+	else if (node->typeinfo && node->typeinfo->uifunc)
 		node->typeinfo->uifunc(layout, (bContext *)C, &ptr);
 }
 

Modified: branches/particles-2010/source/blender/editors/space_node/node_edit.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/node_edit.c	2010-10-25 10:53:33 UTC (rev 32699)
+++ branches/particles-2010/source/blender/editors/space_node/node_edit.c	2010-10-25 11:55:23 UTC (rev 32700)
@@ -2387,7 +2387,7 @@
 
 /* ****************** Add Property Socket Operator  ******************* */
 
-static int node_add_property_socket_exec(bContext *C, wmOperator *op)
+static int node_property_socket_add_exec(bContext *C, wmOperator *op)
 {
 	SpaceNode *snode= CTX_wm_space_node(C);
 	bNode *node= editnode_get_active(snode->edittree);
@@ -2415,15 +2415,15 @@
 	return OPERATOR_FINISHED;
 }
 
-void NODE_OT_add_property_socket(wmOperatorType *ot)
+void NODE_OT_property_socket_add(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name= "Add property socket";
 	ot->description= "Add a new property socket to a data node";
-	ot->idname= "NODE_OT_add_property_socket";
+	ot->idname= "NODE_OT_property_socket_add";
 	
 	/* callbacks */
-	ot->exec= node_add_property_socket_exec;
+	ot->exec= node_property_socket_add_exec;
 	ot->poll= ED_operator_node_active;
 	
 	/* flags */
@@ -2434,7 +2434,7 @@
 
 /* ****************** Remove Property Socket Operator  ******************* */
 
-static int node_remove_property_socket_exec(bContext *C, wmOperator *op)
+static int node_property_socket_remove_exec(bContext *C, wmOperator *op)
 {
 	SpaceNode *snode= CTX_wm_space_node(C);
 	bNode *node= editnode_get_active(snode->edittree);
@@ -2443,42 +2443,38 @@
 	ED_preview_kill_jobs(C);
 	
 	/* check input variables */
-	if (RNA_property_is_set(op->ptr, "socket"))
-		sock = (bNodeSocket*)RNA_pointer_get(op->ptr, "socket").data;
-	else
-		sock = NULL;
-
-	switch (node->type) {
-	case SIM_NODE_GETDATA:
-		nodeRemoveOutputSocket(snode->edittree, node, sock);
-		break;
-	case SIM_NODE_SETDATA:
-		nodeRemoveInputSocket(snode->edittree, node, sock);
-		break;
+	sock = CTX_data_pointer_get(C, "socket").data;
+	if (sock) {
+		switch (node->type) {
+		case SIM_NODE_GETDATA:
+			nodeRemoveOutputSocket(snode->edittree, node, sock);
+			break;
+		case SIM_NODE_SETDATA:
+			nodeRemoveInputSocket(snode->edittree, node, sock);
+			break;
+		}
+		
+		node_tree_verify_groups(snode->nodetree);
+		
+		snode_notify(C, snode);
 	}
 	
-	node_tree_verify_groups(snode->nodetree);
-	
-	snode_notify(C, snode);
-	
 	return OPERATOR_FINISHED;
 }
 
-void NODE_OT_remove_property_socket(wmOperatorType *ot)
+void NODE_OT_property_socket_remove(wmOperatorType *ot)
 {
 	/* identifiers */
 	ot->name= "Remove property socket";
 	ot->description= "Remove a new property socket from a data node";
-	ot->idname= "NODE_OT_remove_property_socket";
+	ot->idname= "NODE_OT_property_socket_remove";
 	
 	/* callbacks */
-	ot->exec= node_remove_property_socket_exec;
+	ot->exec= node_property_socket_remove_exec;
 	ot->poll= ED_operator_node_active;
 	
 	/* flags */
 	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
-	
-	RNA_def_pointer(ot->srna, "socket", "NodeSocket", "Socket", "Property socket to remove.");
 }
 
 /* ****************** Compile OpenCL Program Node Operator  ******************* */

Modified: branches/particles-2010/source/blender/editors/space_node/node_intern.h
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/node_intern.h	2010-10-25 10:53:33 UTC (rev 32699)
+++ branches/particles-2010/source/blender/editors/space_node/node_intern.h	2010-10-25 11:55:23 UTC (rev 32700)
@@ -122,8 +122,8 @@
 
 void NODE_OT_add_file(struct wmOperatorType *ot);
 
-void NODE_OT_add_property_socket(struct wmOperatorType *ot);
-void NODE_OT_remove_property_socket(struct wmOperatorType *ot);
+void NODE_OT_property_socket_add(struct wmOperatorType *ot);
+void NODE_OT_property_socket_remove(struct wmOperatorType *ot);
 
 void NODE_OT_compile_opencl_program(struct wmOperatorType *ot);
 

Modified: branches/particles-2010/source/blender/editors/space_node/node_ops.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/node_ops.c	2010-10-25 10:53:33 UTC (rev 32699)
+++ branches/particles-2010/source/blender/editors/space_node/node_ops.c	2010-10-25 11:55:23 UTC (rev 32700)
@@ -84,8 +84,8 @@
 	
 	WM_operatortype_append(NODE_OT_add_file);
 	
-	WM_operatortype_append(NODE_OT_add_property_socket);
-	WM_operatortype_append(NODE_OT_remove_property_socket);
+	WM_operatortype_append(NODE_OT_property_socket_add);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list