Revision: 32730
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32730
Author:   lukastoenne
Date:     2010-10-27 10:48:10 +0200 (Wed, 27 Oct 2010)

Log Message:
-----------
Added type selection menu to property sockets in the n-panel.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/blenkernel/intern/node.c
    branches/particles-2010/source/blender/editors/space_node/drawnode.c
    branches/particles-2010/source/blender/editors/space_node/node_edit.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-27 06:41:48 UTC (rev 32729)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h        
2010-10-27 08:48:10 UTC (rev 32730)
@@ -196,6 +196,8 @@
 
 bNodeTreeTypeInfo      *ntreeGetTypeInfo(int type);
 
+void                   ntreeSocketTypeInfo(int type, const char **identifier, 
int *icon, const char **name);
+
 struct bNodeTree *ntreeAddTree(int type);
 void                   ntreeInitTypes(struct bNodeTree *ntree);
 void                   ntreeVerifyTypes(struct bNodeTree *ntree);

Modified: branches/particles-2010/source/blender/blenkernel/intern/node.c
===================================================================
--- branches/particles-2010/source/blender/blenkernel/intern/node.c     
2010-10-27 06:41:48 UTC (rev 32729)
+++ branches/particles-2010/source/blender/blenkernel/intern/node.c     
2010-10-27 08:48:10 UTC (rev 32730)
@@ -85,6 +85,23 @@
        }
 }
 
+void ntreeSocketTypeInfo(int type, const char **identifier, int *icon, const 
char **name)
+{
+       switch (type) {
+       case SOCK_VALUE:        if (identifier) *identifier = "SOCK_VALUE";     
        if (icon) *icon = 0;    if (name) *name = "Value";              break;
+       case SOCK_VECTOR:       if (identifier) *identifier = "SOCK_VECTOR";    
if (icon) *icon = 0;    if (name) *name = "Vector";             break;
+       case SOCK_RGBA:         if (identifier) *identifier = "SOCK_RGBA";      
        if (icon) *icon = 0;    if (name) *name = "Color";              break;
+       case SOCK_ANY:          if (identifier) *identifier = "SOCK_ANY";       
        if (icon) *icon = 0;    if (name) *name = "Any";                break;
+       case SOCK_OP:           if (identifier) *identifier = "SOCK_OP";        
        if (icon) *icon = 0;    if (name) *name = "Execute";    break;
+       case SOCK_FLOAT:        if (identifier) *identifier = "SOCK_FLOAT";     
        if (icon) *icon = 0;    if (name) *name = "Float";              break;
+       case SOCK_INT:          if (identifier) *identifier = "SOCK_INT";       
        if (icon) *icon = 0;    if (name) *name = "Integer";    break;
+       case SOCK_BOOL:         if (identifier) *identifier = "SOCK_BOOL";      
        if (icon) *icon = 0;    if (name) *name = "Boolean";    break;
+       case SOCK_QUAT:         if (identifier) *identifier = "SOCK_QUAT";      
        if (icon) *icon = 0;    if (name) *name = "Quaternion"; break;
+       case SOCK_MATRIX:       if (identifier) *identifier = "SOCK_MATRIX";    
if (icon) *icon = 0;    if (name) *name = "Matrix";             break;
+       case SOCK_STRING:       if (identifier) *identifier = "SOCK_STRING";    
if (icon) *icon = 0;    if (name) *name = "String";             break;
+       default:                        if (identifier) *identifier = "";       
                        if (icon) *icon = 0;    if (name) *name = "";
+       }
+}
 
 static bNodeType *node_get_type(bNodeTree *ntree, int type, bNodeTree *ngroup, 
ID *id)
 {

Modified: branches/particles-2010/source/blender/editors/space_node/drawnode.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/drawnode.c        
2010-10-27 06:41:48 UTC (rev 32729)
+++ branches/particles-2010/source/blender/editors/space_node/drawnode.c        
2010-10-27 08:48:10 UTC (rev 32730)
@@ -1279,6 +1279,18 @@
        uiItemR(col, ptr, "path", 0, NULL, 0);
 }
 
+static void do_property_socket_type(bContext *C, void *arg, int event)
+{
+       SpaceNode *snode= CTX_wm_space_node(C);
+       bNodeSocket *sock= (bNodeSocket*)arg;
+       
+       sock->type = event;
+       
+       node_tree_verify_groups(snode->nodetree);
+       
+       snode_notify(C, snode);
+}
+
 static void getdata_add_property_exec_cb(bContext *C, void *arg1, void *arg2)
 {
        SpaceNode *snode= CTX_wm_space_node(C);
@@ -1321,12 +1333,32 @@
        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);
 }
+static void node_getdata_property_socket_type_menu(bContext *C, uiLayout 
*layout, void *arg)
+{
+//     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;
+       
+       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]);
+       }
+}
 static void node_simulation_detailbuts_getdata(uiLayout *layout, bContext *C, 
PointerRNA *ptr)
 {
        bNode *node= ptr->data;
        bNodeSocket *sock;
        PointerRNA sockptr;
        uiLayout *col, *row;
+       const char *tname;
+       int ticon;
        
        col= uiLayoutColumn(layout, 0);
        uiLayoutSetContextPointer(col, "node", ptr);
@@ -1343,6 +1375,8 @@
                RNA_pointer_create((ID*)ptr->id.data, &RNA_NodeSocket, sock, 
&sockptr);
                uiLayoutSetContextPointer(row, "socket", &sockptr);
                
+               ntreeSocketTypeInfo(sock->type, NULL, &ticon, &tname);
+               uiItemMenuF(row, (char*)tname, ticon, 
node_getdata_property_socket_type_menu, sock);
                uiItemR(row, &sockptr, "name", 0, "", 0);
                uiItemO(row, "", ICON_X, "NODE_OT_property_socket_remove");
        }
@@ -1400,12 +1434,32 @@
        but= uiDefSearchBut(block, data->propsearch, 0, ICON_VIEWZOOM, 
sizeof(data->propsearch), 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_setdata_property_socket_type_menu(bContext *C, uiLayout 
*layout, void *arg)
+{
+//     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;
+       
+       sim_setdata_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]);
+       }
+}
 static void node_simulation_detailbuts_setdata(uiLayout *layout, bContext *C, 
PointerRNA *ptr)
 {
        bNode *node= ptr->data;
        bNodeSocket *sock;
        PointerRNA sockptr;
        uiLayout *col, *row;
+       const char *tname;
+       int ticon;
        
        col= uiLayoutColumn(layout, 0);
        uiLayoutSetContextPointer(col, "node", ptr);
@@ -1422,6 +1476,8 @@
                RNA_pointer_create((ID*)ptr->id.data, &RNA_NodeSocket, sock, 
&sockptr);
                uiLayoutSetContextPointer(row, "socket", &sockptr);
                
+               ntreeSocketTypeInfo(sock->type, NULL, &ticon, &tname);
+               uiItemMenuF(row, (char*)tname, ticon, 
node_setdata_property_socket_type_menu, sock);
                uiItemR(row, &sockptr, "name", 0, "", 0);
                uiItemO(row, "", ICON_X, "NODE_OT_property_socket_remove");
        }

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-27 06:41:48 UTC (rev 32729)
+++ branches/particles-2010/source/blender/editors/space_node/node_edit.c       
2010-10-27 08:48:10 UTC (rev 32730)
@@ -69,6 +69,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "WM_api.h"
 #include "WM_types.h"

Modified: branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c       
2010-10-27 06:41:48 UTC (rev 32729)
+++ branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c       
2010-10-27 08:48:10 UTC (rev 32730)
@@ -27,6 +27,7 @@
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "rna_internal.h"
 #include "rna_internal_types.h"
@@ -118,6 +119,33 @@
        return BLI_sprintfN("nodes[\"%s\"]", node->name);
 }
 
+static int rna_NodeSocket_type_get(struct PointerRNA *ptr)
+{
+       bNodeSocket *sock= (bNodeSocket*)ptr->data;
+       return sock->type;
+}
+
+EnumPropertyItem *rna_NodeSocket_type_itemf(bContext *C, PointerRNA *ptr, int 
*free)
+{
+       static EnumPropertyItem items[NUM_SOCKET_TYPES+1];
+       int i;
+
+       for (i=0; i < NUM_SOCKET_TYPES; ++i) {
+               items[i].value = i;
+               ntreeSocketTypeInfo(i, &items[i].identifier, &items[i].icon, 
&items[i].name);
+               items[i].description = "";
+       }
+       items[i].value = -1;
+       items[i].identifier = "";
+       items[i].icon = 0;
+       items[i].name = "";
+       items[i].description = "";
+       
+       *free= 0;
+       
+       return items;
+}
+
 static char *rna_NodeSocket_path(PointerRNA *ptr)
 {
        bNodeTree *ntree= (bNodeTree*)ptr->id.data;
@@ -2345,18 +2373,8 @@
 /* -------------------------------------------------------------------------- 
*/
 
 static EnumPropertyItem node_socket_type_items[] = {
-       {SOCK_VALUE,    "SOCK_VALUE",   0,              "Value",                
""},
-       {SOCK_VECTOR,   "SOCK_VECTOR",  0,              "Vector",               
""},
-       {SOCK_RGBA,             "SOCK_RGBA",    0,              "Color",        
        ""},
-       {SOCK_ANY,              "SOCK_ANY",             0,              "Any",  
                ""},
-       {SOCK_OP,               "SOCK_OP",              0,              
"Execute",              ""},
-       {SOCK_FLOAT,    "SOCK_FLOAT",   0,              "Float",                
""},
-       {SOCK_INT,              "SOCK_INT",             0,              
"Integer",              ""},
-       {SOCK_BOOL,             "SOCK_BOOL",    0,              "Boolean",      
        ""},
-       {SOCK_QUAT,             "SOCK_QUAT",    0,              "Quaternion",   
""},
-       {SOCK_MATRIX,   "SOCK_MATRIX",  0,              "Matrix",               
""},
-       {SOCK_STRING,   "SOCK_STRING",  0,              "String",               
""},
-       {-1,                    "",                             0,              
"",                             ""}
+       {0, "__SOCK_DUMMY_TYPE__", 0, "", ""},
+       {-1, "", 0, "", ""}
 };
 
 static void rna_def_node_socket(BlenderRNA *brna)
@@ -2374,6 +2392,8 @@
        prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "type");
        RNA_def_property_enum_items(prop, node_socket_type_items);
+       RNA_def_property_enum_default(prop, 0);
+       RNA_def_property_enum_funcs(prop, "rna_NodeSocket_type_get", NULL, 
"rna_NodeSocket_type_itemf");
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Type", "Socket data type");
 }


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to