[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [33335] branches/particles-2010/source/ blender: Implemented a search button for the data node types, similar to the one already in use for the property add buttons.

Lukas Toenne lukas.toenne at googlemail.com
Fri Nov 26 17:30:43 CET 2010


Revision: 33335
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=33335
Author:   lukastoenne
Date:     2010-11-26 17:30:43 +0100 (Fri, 26 Nov 2010)

Log Message:
-----------
Implemented a search button for the data node types, similar to the one already in use for the property add buttons. Unified button functions for GetData/SetData.

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/makesrna/intern/rna_nodetree.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_get_data.c
    branches/particles-2010/source/blender/nodes/intern/SIM_nodes/SIM_set_data.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-11-26 15:37:08 UTC (rev 33334)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-11-26 16:30:43 UTC (rev 33335)
@@ -617,16 +617,20 @@
 
 /* node-specific functions for UI */
 /* XXX having these here is ugly, should be in nodes directory */
+typedef int (*SimSearchFunction)(void *items, const char *str, const char *name, void *poin, int icon);
+
 void sim_getdata_add_property_socket(struct bNode *node, const char *name);
-void sim_getdata_foreach_property(struct bNode *node, void *items, const char *str, int (*cb)(void *items, const char *str, const char *name, const char *identifier, int icon));
+void sim_getdata_foreach_property(struct bNodeTree *ntree, struct bNode *node, void *items, const char *str, SimSearchFunction cb);
 struct StructRNA *sim_getdata_type_get(struct bNode *node);
 void sim_getdata_type_set(struct bNodeTree *ntree, struct bNode *node, struct StructRNA *type);
+void sim_getdata_foreach_type(struct bNodeTree *ntree, struct bNode *node, void *items, const char *str, SimSearchFunction cb);
 void sim_getdata_property_types(struct bNodeSocket *sock, int **types, int *num_types);
 
 void sim_setdata_add_property_socket(struct bNode *node, const char *name);
-void sim_setdata_foreach_property(struct bNode *node, void *items, const char *str, int (*cb)(void *items, const char *str, const char *name, const char *identifier, int icon));
+void sim_setdata_foreach_property(struct bNodeTree *ntree, struct bNode *node, void *items, const char *str, SimSearchFunction cb);
 struct StructRNA *sim_setdata_type_get(struct bNode *node);
 void sim_setdata_type_set(struct bNodeTree *ntree, struct bNode *node, struct StructRNA *type);
+void sim_setdata_foreach_type(struct bNodeTree *ntree, struct bNode *node, void *items, const char *str, SimSearchFunction cb);
 void sim_setdata_property_types(struct bNodeSocket *sock, int **types, int *num_types);
 
 void sim_fromquaternion_update_rotation_mode(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-11-26 15:37:08 UTC (rev 33334)
+++ branches/particles-2010/source/blender/editors/space_node/drawnode.c	2010-11-26 16:30:43 UTC (rev 33335)
@@ -1302,20 +1302,18 @@
 	uiItemR(col, ptr, "path", 0, NULL, 0);
 }
 
-static void node_simulation_buts_getdata(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
-	uiLayout *col;
-	
-	col= uiLayoutColumn(layout, 0);
-	uiLayoutSetContextPointer(col, "node", ptr);
+/* Local struct for passing several pointers to the various button functions */
+typedef struct NodeDataArgs {
+	bNodeTree *ntree;
+	bNode *node;
+	bNodeSocket *sock;
+} NodeDataArgs;
 
-	uiItemR(col, ptr, "path", 0, NULL, 0);
-}
-
+/* Property socket type selection box */
 static void do_property_socket_type(bContext *C, void *arg, int event)
 {
 	SpaceNode *snode= CTX_wm_space_node(C);
-	bNodeSocket *sock= (bNodeSocket*)arg;
+	bNodeSocket *sock= ((NodeDataArgs*)arg)->sock;
 	
 	sock->type = event;
 	
@@ -1323,69 +1321,152 @@
 	
 	snode_notify(C, snode);
 }
+static void node_data_property_socket_type_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)
+{
+	bNode *node= ((NodeDataArgs*)arg)->node;
+	bNodeSocket *sock= ((NodeDataArgs*)arg)->sock;
+	int *types= NULL;
+	int num_types= 0, i;
+	const char *name;
+	int icon;
+	
+	switch (node->type) {
+	case SIM_NODE_GETDATA:	sim_getdata_property_types(sock, &types, &num_types);	break;
+	case SIM_NODE_SETDATA:	sim_setdata_property_types(sock, &types, &num_types);	break;
+	}
+	
+	uiLayoutSetFunc(layout, do_property_socket_type, sock);
+	
+	for (i=0; i < num_types; ++i) {
+		ntreeSocketTypeInfo(types[i], NULL, &icon, &name);
+		uiItemV(layout, (char*)name, icon, types[i]);
+	}
+}
 
-static void getdata_add_property_exec_cb(bContext *C, void *arg1, void *arg2)
+/* Search field for data node types */
+static void node_data_type_exec_cb(bContext *C, void *arg1, void *arg2)
 {
 	SpaceNode *snode= CTX_wm_space_node(C);
-	bNode *node= (bNode*)arg1;
+	bNodeTree *ntree= ((NodeDataArgs*)arg1)->ntree;
+	bNode *node= ((NodeDataArgs*)arg1)->node;
+	struct StructRNA *type= (struct StructRNA*)arg2;
+	
+	switch (node->type) {
+	case SIM_NODE_GETDATA:	sim_getdata_type_set(ntree, node, type);	break;
+	case SIM_NODE_SETDATA:	sim_setdata_type_set(ntree, node, type);	break;
+	}
+	
+	snode_notify(C, snode);
+}
+static int node_data_type_foreach_cb(void *items, const char *str, const char *name, void *poin, int icon)
+{
+	if (!BLI_strcasestr(name, str))
+		return 1;
+	else
+		return uiSearchItemAdd(items, name, poin, icon);
+}
+static void node_data_type_search_cb(const bContext *UNUSED(C), void *arg, const char *str, uiSearchItems *items)
+{
+	bNodeTree *ntree= ((NodeDataArgs*)arg)->ntree;
+	bNode *node= ((NodeDataArgs*)arg)->node;
+	switch (node->type) {
+	case SIM_NODE_GETDATA:	sim_getdata_foreach_type(ntree, node, items, str, node_data_type_foreach_cb);	break;
+	case SIM_NODE_SETDATA:	sim_setdata_foreach_type(ntree, node, items, str, node_data_type_foreach_cb);	break;
+	}
+}
+static void node_data_type_search(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{
+	/* XXX using static variables here is a hack, only reason is that these arguments must be persistent beyond this functions scope.
+	 * This should not be a problem as long as only one instance of these buttons is used at a time.
+	 */
+	static char search[256];
+	static NodeDataArgs args;
+	uiBlock *block;
+	uiBut *but;
+	
+	args.ntree = (bNodeTree*)ptr->id.data;
+	args.node = (bNode*)ptr->data;
+	args.sock = NULL;
+	
+	block= uiLayoutGetBlock(layout);
+	uiBlockSetCurLayout(block, layout);
+
+	but= uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, 256, 0, 0, UI_UNIT_X*25, UI_UNIT_Y, 0, 0, "Select the data node type");
+	uiButSetSearchFunc(but, node_data_type_search_cb, &args, node_data_type_exec_cb, NULL);
+}
+
+/* Search field for adding property sockets */
+static void node_data_add_property_exec_cb(bContext *C, void *arg1, void *arg2)
+{
+	SpaceNode *snode= CTX_wm_space_node(C);
+	bNode *node= ((NodeDataArgs*)arg1)->node;
 	SimDataNode *data= (SimDataNode*)node->storage;
 	const char *prop= (const char*)arg2;
 	
 	if (prop) {
-		sim_getdata_add_property_socket(node, prop);
+		switch (node->type) {
+		case SIM_NODE_GETDATA:	sim_getdata_add_property_socket(node, prop);	break;
+		case SIM_NODE_SETDATA:	sim_setdata_add_property_socket(node, prop);	break;
+		}
 	}
 	else {
 		/* add dynamic property */
-		sim_getdata_add_property_socket(node, data->propsearch);
+		switch (node->type) {
+		case SIM_NODE_GETDATA:	sim_getdata_add_property_socket(node, data->propsearch);	break;
+		case SIM_NODE_SETDATA:	sim_setdata_add_property_socket(node, data->propsearch);	break;
+		}
 	}
 	/* clear the search field */
 	data->propsearch[0] = '\0';
 	
 	snode_notify(C, snode);
 }
-static int getdata_add_property_foreach_cb(void *items, const char *str, const char *name, const char *UNUSED(identifier), int icon)
+static int node_data_add_property_foreach_cb(void *items, const char *str, const char *name, void *poin, int icon)
 {
 	if (!BLI_strcasestr(name, str))
 		return 1;
 	else
-		return uiSearchItemAdd(items, name, (void*)name, icon);
+		return uiSearchItemAdd(items, name, poin, icon);
 }
-static void getdata_add_property_search_cb(const bContext *UNUSED(C), void *arg, const char *str, uiSearchItems *items)
+static void node_data_add_property_search_cb(const bContext *UNUSED(C), void *arg, const char *str, uiSearchItems *items)
 {
-	sim_getdata_foreach_property((bNode*)arg, items, str, getdata_add_property_foreach_cb);
+	bNodeTree *ntree= ((NodeDataArgs*)arg)->ntree;
+	bNode *node= ((NodeDataArgs*)arg)->node;
+	switch (node->type) {
+	case SIM_NODE_GETDATA:	sim_getdata_foreach_property(ntree, node, items, str, node_data_add_property_foreach_cb);	break;
+	case SIM_NODE_SETDATA:	sim_setdata_foreach_property(ntree, node, items, str, node_data_add_property_foreach_cb);	break;
+	}
 }
-static void getdata_add_property_search(uiLayout *layout, bNode *node)
+static void node_data_add_property_search(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
+	static NodeDataArgs args;
+	bNode *node= (bNode*)ptr->data;
 	SimDataNode *data= (SimDataNode*)node->storage;
 	uiBlock *block;
 	uiBut *but;
-		
+	
+	args.ntree = (bNodeTree*)ptr->id.data;
+	args.node = (bNode*)ptr->data;
+	args.sock = NULL;
+	
 	block= uiLayoutGetBlock(layout);
 	uiBlockSetCurLayout(block, layout);
-
-	but= uiDefSearchBut(block, data->propsearch, 0, ICON_VIEWZOOM, sizeof(data->propsearch), 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);
+	
+	but= uiDefSearchBut(block, data->propsearch, 0, ICON_VIEWZOOM, sizeof(data->propsearch), 0, 0, UI_UNIT_X*25, UI_UNIT_Y, 0, 0, "Add a new property socket");
+	uiButSetSearchFunc(but, node_data_add_property_search_cb, &args, node_data_add_property_exec_cb, NULL);
 }
-static void node_getdata_property_socket_type_menu(bContext *UNUSED(C), uiLayout *layout, void *arg)
+static void node_simulation_buts_getdata(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
 {
-//	SpaceNode *snode= CTX_wm_space_node(C);
-//	bNode *node= editnode_get_active(snode->edittree);
-	bNodeSocket *sock= (bNodeSocket*)arg;
-	int *types= NULL;
-	int num_types= 0, i;
-	const char *name;
-	int icon;
+	uiLayout *col;
 	
-	sim_getdata_property_types(sock, &types, &num_types);
-	uiLayoutSetFunc(layout, do_property_socket_type, sock);
-	
-	for (i=0; i < num_types; ++i) {
-		ntreeSocketTypeInfo(types[i], NULL, &icon, &name);
-		uiItemV(layout, (char*)name, icon, types[i]);
-	}
+	col= uiLayoutColumn(layout, 0);
+	uiLayoutSetContextPointer(col, "node", ptr);
+
+	uiItemR(col, ptr, "path", 0, NULL, 0);
 }
-static void node_simulation_detailbuts_getdata(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void node_simulation_detailbuts_getdata(uiLayout *layout, bContext *C, PointerRNA *ptr)
 {
+	static NodeDataArgs args;
 	bNode *node= ptr->data;
 	bNodeSocket *sock;
 	PointerRNA sockptr;
@@ -1393,23 +1474,36 @@
 	const char *tname;
 	int ticon;
 	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list