[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32714] branches/particles-2010/source/ blender: Added an enum property for the socket type to node RNA.

Lukas Toenne lukas.toenne at googlemail.com
Tue Oct 26 17:44:53 CEST 2010


Revision: 32714
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32714
Author:   lukastoenne
Date:     2010-10-26 17:44:53 +0200 (Tue, 26 Oct 2010)

Log Message:
-----------
Added an enum property for the socket type to node RNA. This is not editable by default, even though in some cases the socket type may change.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/makesdna/DNA_node_types.h
    branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
    branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c
    branches/particles-2010/source/blender/nodes/intern/simulation/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-10-26 12:48:07 UTC (rev 32713)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-10-26 15:44:53 UTC (rev 32714)
@@ -595,17 +595,19 @@
 /* XXX having these here is ugly, should be in nodes directory */
 void sim_getdata_add_property_socket(struct bNode *node, const char *prop);
 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));
+const char *sim_getdata_path_get(struct bNode *node);
 void sim_getdata_path_set(struct bNodeTree *ntree, struct bNode *node, const char *path);
-const char *sim_getdata_path_get(struct bNode *node);
 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_property_types(struct bNodeSocket *sock, int **types, int *num_types);
 
 void sim_setdata_add_property_socket(struct bNode *node, const char *prop);
 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));
+const char *sim_setdata_path_get(struct bNode *node);
 void sim_setdata_path_set(struct bNodeTree *ntree, struct bNode *node, const char *path);
-const char *sim_setdata_path_get(struct bNode *node);
 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_property_types(struct bNodeSocket *sock, int **types, int *num_types);
 
 /**/
 

Modified: branches/particles-2010/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-10-26 12:48:07 UTC (rev 32713)
+++ branches/particles-2010/source/blender/makesdna/DNA_node_types.h	2010-10-26 15:44:53 UTC (rev 32714)
@@ -389,9 +389,15 @@
 
 /* stores associated properties for GetData/SetData node sockets */
 typedef struct SimDataNodeSocket {
-	char identifier[64];
+	int type;						/* type of property */
+	int pad;
+	char identifier[64];			/* identifier string */
 } SimDataNodeSocket;
 
+#define SIM_DATA_RNA		1
+#define SIM_DATA_IDPROP		2
+#define SIM_DATA_PARPROP	3
+
 typedef struct SimDataNode {
 	struct StructRNA *type;			/* context type of the properties */
 	/* only used during read/write file! */

Modified: branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c	2010-10-26 12:48:07 UTC (rev 32713)
+++ branches/particles-2010/source/blender/makesrna/intern/rna_nodetree.c	2010-10-26 15:44:53 UTC (rev 32714)
@@ -2344,9 +2344,25 @@
 
 /* -------------------------------------------------------------------------- */
 
+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,		"",				""}
+};
+
 static void rna_def_node_socket(BlenderRNA *brna)
 {
 	StructRNA *srna;
+	PropertyRNA *prop;
 
 	srna = RNA_def_struct(brna, "NodeSocket", NULL);
 	RNA_def_struct_ui_text(srna, "Node Socket", "Input or output socket of a node");
@@ -2355,6 +2371,11 @@
 	RNA_def_struct_ui_icon(srna, ICON_PLUG);
 	RNA_def_struct_path_func(srna, "rna_NodeSocket_path");
 
+	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_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_ui_text(prop, "Type", "Socket data type");
 }
 
 static void rna_def_node_socket_value(BlenderRNA *brna)

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c	2010-10-26 12:48:07 UTC (rev 32713)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_get_data.c	2010-10-26 15:44:53 UTC (rev 32714)
@@ -121,6 +121,8 @@
 
 void sim_getdata_add_property_socket(bNode *node, const char *identifier)
 {
+	SimDataNode *data= (SimDataNode*)node->storage;
+	SimDataNodeSocket *sockdata;
 	bNodeSocket *sock;
 	float defaults[4]= { 0.0f, 0.0f, 0.0f, 0.0f };
 	float min= 0.0f, max= 0.0f;
@@ -131,15 +133,28 @@
 		/* disable context adaptation (context is set explicitly) */
 		sock->flag &= ~SOCK_ADAPT_CONTEXT;
 		/* associate with the property */
-		strcpy(((SimDataNodeSocket*)sock->storage)->identifier, identifier);
+		sockdata = (SimDataNodeSocket*)sock->storage;
+		sockdata->type = SIM_DATA_RNA;
+		strcpy(sockdata->identifier, identifier);
 	}
-	else {
+	else if (data->type && RNA_struct_is_ID(data->type)) {
 		sock = nodeAddOutputSocket(node, identifier, SOCK_ANY, defaults, min, max);
 		/* disable context adaptation (context is set explicitly) */
 		sock->flag &= ~SOCK_ADAPT_CONTEXT;
 		/* associate with the property */
-		strcpy(((SimDataNodeSocket*)sock->storage)->identifier, identifier);
+		sockdata = (SimDataNodeSocket*)sock->storage;
+		sockdata->type = SIM_DATA_IDPROP;
+		strcpy(sockdata->identifier, identifier);
 	}
+	else if (data->type && RNA_struct_is_a(data->type, &RNA_NParticle)) {
+		sock = nodeAddOutputSocket(node, identifier, SOCK_ANY, defaults, min, max);
+		/* disable context adaptation (context is set explicitly) */
+		sock->flag &= ~SOCK_ADAPT_CONTEXT;
+		/* associate with the property */
+		sockdata = (SimDataNodeSocket*)sock->storage;
+		sockdata->type = SIM_DATA_PARPROP;
+		strcpy(sockdata->identifier, identifier);
+	}
 }
 
 void sim_getdata_path_set(bNodeTree *ntree, bNode *node, const char *path)
@@ -197,6 +212,27 @@
 	data->type = type;
 }
 
+void sim_getdata_property_types(bNodeSocket *sock, int **types, int *num_types)
+{
+	static int idprop_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_BOOL, SOCK_VECTOR, SOCK_RGBA, SOCK_QUAT, SOCK_MATRIX, SOCK_STRING };
+	static int parprop_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_BOOL, SOCK_VECTOR, SOCK_RGBA, SOCK_QUAT, SOCK_MATRIX, SOCK_STRING };
+	SimDataNodeSocket *data= (SimDataNodeSocket*)sock->storage;
+	switch (data->type) {
+	case SIM_DATA_IDPROP:
+		*types = idprop_types;
+		*num_types = 8;
+		break;
+	case SIM_DATA_PARPROP:
+		*types = parprop_types;
+		*num_types = 8;
+		break;
+	case SIM_DATA_RNA:
+	default:
+		*types = NULL;
+		*num_types = 0;
+	}
+}
+
 static void update(bNodeTree *ntree, bNode *node)
 {
 }

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c	2010-10-26 12:48:07 UTC (rev 32713)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/nodes/SIM_set_data.c	2010-10-26 15:44:53 UTC (rev 32714)
@@ -116,6 +116,8 @@
 
 void sim_setdata_add_property_socket(bNode *node, const char *identifier)
 {
+	SimDataNode *data= (SimDataNode*)node->storage;
+	SimDataNodeSocket *sockdata;
 	bNodeSocket *sock;
 	float defaults[4]= { 0.0f, 0.0f, 0.0f, 0.0f };
 	float min= 0.0f, max= 0.0f;
@@ -127,15 +129,28 @@
 		/* disable context adaptation (context is set explicitly) */
 		sock->flag &= ~SOCK_ADAPT_CONTEXT;
 		/* associate with the property */
-		strcpy(((SimDataNodeSocket*)sock->storage)->identifier, identifier);
+		sockdata = (SimDataNodeSocket*)sock->storage;
+		sockdata->type = SIM_DATA_RNA;
+		strcpy(sockdata->identifier, identifier);
 	}
-	else {
+	else if (data->type && RNA_struct_is_ID(data->type)) {
 		sock = nodeAddInputSocket(node, identifier, SOCK_ANY, defaults, min, max);
 		/* disable context adaptation (context is set explicitly) */
 		sock->flag &= ~SOCK_ADAPT_CONTEXT;
 		/* associate with the property */
-		strcpy(((SimDataNodeSocket*)sock->storage)->identifier, identifier);
+		sockdata = (SimDataNodeSocket*)sock->storage;
+		sockdata->type = SIM_DATA_IDPROP;
+		strcpy(sockdata->identifier, identifier);
 	}
+	else if (data->type && RNA_struct_is_a(data->type, &RNA_NParticle)) {
+		sock = nodeAddInputSocket(node, identifier, SOCK_ANY, defaults, min, max);
+		/* disable context adaptation (context is set explicitly) */
+		sock->flag &= ~SOCK_ADAPT_CONTEXT;
+		/* associate with the property */
+		sockdata = (SimDataNodeSocket*)sock->storage;
+		sockdata->type = SIM_DATA_PARPROP;
+		strcpy(sockdata->identifier, identifier);
+	}
 }
 
 const char *sim_setdata_path_get(bNode *node)
@@ -185,6 +200,27 @@
 	data->type = type;
 }
 
+void sim_setdata_property_types(bNodeSocket *sock, int **types, int *num_types)
+{
+	static int idprop_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_BOOL, SOCK_VECTOR, SOCK_RGBA, SOCK_QUAT, SOCK_MATRIX, SOCK_STRING };
+	static int parprop_types[] = { SOCK_FLOAT, SOCK_INT, SOCK_BOOL, SOCK_VECTOR, SOCK_RGBA, SOCK_QUAT, SOCK_MATRIX, SOCK_STRING };
+	SimDataNodeSocket *data= (SimDataNodeSocket*)sock->storage;
+	switch (data->type) {
+	case SIM_DATA_IDPROP:
+		*types = idprop_types;
+		*num_types = 8;
+		break;
+	case SIM_DATA_PARPROP:
+		*types = parprop_types;
+		*num_types = 8;
+		break;
+	case SIM_DATA_RNA:
+	default:
+		*types = NULL;
+		*num_types = 0;
+	}
+}
+
 static void init(bNode *node)
 {
 	SimDataNode *data = MEM_callocN(sizeof(SimDataNode), "SimDataNode");





More information about the Bf-blender-cvs mailing list