[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32967] branches/particles-2010/source/ blender: Added sub-menus for GetData and SetData nodes.
Lukas Toenne
lukas.toenne at googlemail.com
Tue Nov 9 16:03:09 CET 2010
Revision: 32967
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32967
Author: lukastoenne
Date: 2010-11-09 16:03:09 +0100 (Tue, 09 Nov 2010)
Log Message:
-----------
Added sub-menus for GetData and SetData nodes. These contain shortcuts to commonly used data types, so the user does not have to type the RNA struct name each time when adding a data node. (defined in node_header.c, could be moved)
Modified Paths:
--------------
branches/particles-2010/source/blender/blenkernel/BKE_node.h
branches/particles-2010/source/blender/editors/space_node/node_header.c
Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-11-09 14:54:59 UTC (rev 32966)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h 2010-11-09 15:03:09 UTC (rev 32967)
@@ -597,6 +597,8 @@
/* TO BE REMOVED: debugging stuff, testing, etc. */
#define SIM_NODE_DEBUGPRINT 900
+/* XXX NODE_GROUP_MENU is 1000, this is getting dangerously close if more categories are added this way ... */
+
/* API */
void ntreeSimulationCompileProgram(struct bNodeTree *ntree, int force);
void ntreeSimulationReleaseProgram(struct bNodeTree *ntree);
Modified: branches/particles-2010/source/blender/editors/space_node/node_header.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/node_header.c 2010-11-09 14:54:59 UTC (rev 32966)
+++ branches/particles-2010/source/blender/editors/space_node/node_header.c 2010-11-09 15:03:09 UTC (rev 32967)
@@ -43,6 +43,7 @@
#include "BKE_node.h"
#include "BKE_main.h"
+#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -83,6 +84,70 @@
snode_notify(C, snode);
}
+static struct StructRNA *data_node_types[] = {
+ &RNA_Object,
+ &RNA_Lamp,
+ &RNA_NParticle,
+ NULL /* terminator */
+};
+
+static void do_data_node_add(bContext *C, void *arg_type, int event)
+{
+ SpaceNode *snode= CTX_wm_space_node(C);
+ int type= GET_INT_FROM_POINTER(arg_type);
+ /* here the event is not the node type, but the data type */
+ struct StructRNA *datatype= data_node_types[event];
+ bNode *node;
+
+ /* store selection in temp test flag */
+ for(node= snode->edittree->nodes.first; node; node= node->next) {
+ if(node->flag & NODE_SELECT) node->flag |= NODE_TEST;
+ else node->flag &= ~NODE_TEST;
+ }
+
+ node= node_add_node(snode, CTX_data_scene(C), type, snode->mx, snode->my);
+ /* set the data type for this item */
+ if (datatype) {
+ if (type == SIM_NODE_GETDATA)
+ sim_getdata_type_set(snode->edittree, node, datatype);
+ else if (type == SIM_NODE_SETDATA)
+ sim_setdata_type_set(snode->edittree, node, datatype);
+ }
+
+ /* select previous selection before autoconnect */
+ for(node= snode->edittree->nodes.first; node; node= node->next) {
+ if(node->flag & NODE_TEST) node->flag |= NODE_SELECT;
+ }
+
+ snode_autoconnect(snode, 1, 0);
+
+ /* deselect after autoconnection */
+ for(node= snode->edittree->nodes.first; node; node= node->next) {
+ if(node->flag & NODE_TEST) node->flag &= ~NODE_SELECT;
+ }
+
+ snode_notify(C, snode);
+}
+
+static void data_node_add_menu(bContext *C, uiLayout *layout, void *arg_type)
+{
+ SpaceNode *snode= CTX_wm_space_node(C);
+ bNodeTree *ntree= snode->nodetree;
+ int i;
+
+ if(!ntree) {
+ uiItemS(layout);
+ return;
+ }
+
+ uiLayoutSetFunc(layout, do_data_node_add, arg_type);
+
+ for (i=0; data_node_types[i] != NULL; ++i) {
+ uiItemV(layout, (char*)RNA_struct_ui_name(data_node_types[i]), RNA_struct_ui_icon(data_node_types[i]), i);
+ }
+ uiItemV(layout, "custom", 0, i);
+}
+
static void node_auto_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass)
{
Main *bmain= CTX_data_main(C);
@@ -141,6 +206,12 @@
uiItemV(layout, type->name, 0, NODE_DYNAMIC_MENU+script);
script++;
}
+ else if(type->type == SIM_NODE_GETDATA) {
+ uiItemMenuF(layout, "Get Data", 0, data_node_add_menu, SET_INT_IN_POINTER(SIM_NODE_GETDATA));
+ }
+ else if(type->type == SIM_NODE_SETDATA) {
+ uiItemMenuF(layout, "Set Data", 0, data_node_add_menu, SET_INT_IN_POINTER(SIM_NODE_SETDATA));
+ }
else
uiItemV(layout, type->name, 0, type->type);
More information about the Bf-blender-cvs
mailing list