[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [18086] branches/blender2.5/blender/source /blender: RNA:
Brecht Van Lommel
brecht at blender.org
Fri Dec 26 21:38:52 CET 2008
Revision: 18086
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=18086
Author: blendix
Date: 2008-12-26 21:38:52 +0100 (Fri, 26 Dec 2008)
Log Message:
-----------
RNA:
* Added support for using pointers + collections as operator properties,
but with the restriction that they must point to other type derived from
ID property groups. The "add" function for these properties will allocate
a new ID property group and point to that.
* Added support for arrays with type IDP_GROUP in ID properties.
* Fix bug getting/setting float array values.
Example code for collections, note the "OperatorMousePath" type is defined
in rna_wm.c and has a float[2] property named "loc".
Defining the operator property:
prop= RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
Adding values:
PointerRNA itemptr;
float loc[2] = {1, 1},
RNA_collection_add(op->ptr, "path", &itemptr);
RNA_float_set_array(&itemptr, "loc", loc);
Iterating:
RNA_BEGIN(op->ptr, itemptr, "path") {
float loc[2];
RNA_float_get_array(&itemptr, "loc", loc);
printf("Location: %f %f\n", loc[0], loc[1]);
}
RNA_END;
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c
branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
branches/blender2.5/blender/source/blender/makesrna/RNA_types.h
branches/blender2.5/blender/source/blender/makesrna/intern/makesrna.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_ID.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_access.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_define.c
branches/blender2.5/blender/source/blender/makesrna/intern/rna_internal.h
branches/blender2.5/blender/source/blender/makesrna/intern/rna_wm.c
Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c 2008-12-26 20:25:02 UTC (rev 18085)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/idprop.c 2008-12-26 20:38:52 UTC (rev 18086)
@@ -61,6 +61,34 @@
/* ----------- Array Type ----------- */
+static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr)
+{
+ if(prop->subtype != IDP_GROUP)
+ return;
+
+ if(newlen >= prop->len) {
+ /* bigger */
+ IDProperty **array= newarr;
+ IDPropertyTemplate val;
+ int a;
+
+ for(a=prop->len; a<newlen; a++) {
+ val.i = 0; /* silence MSVC warning about uninitialized var when debugging */
+ array[a]= IDP_New(IDP_GROUP, val, "IDP_ResizeArray group");
+ }
+ }
+ else {
+ /* smaller */
+ IDProperty **array= prop->data.pointer;
+ int a;
+
+ for(a=newlen; a<prop->len; a++) {
+ IDP_FreeProperty(array[a]);
+ MEM_freeN(array[a]);
+ }
+ }
+}
+
/*this function works for strings too!*/
void IDP_ResizeArray(IDProperty *prop, int newlen)
{
@@ -70,6 +98,7 @@
/*first check if the array buffer size has room*/
/*if newlen is 200 chars less then totallen, reallocate anyway*/
if (newlen <= prop->totallen && prop->totallen - newlen < 200) {
+ idp_resize_group_array(prop, newlen, newarr);
prop->len = newlen;
return;
}
@@ -84,11 +113,17 @@
*/
newsize = (newsize >> 3) + (newsize < 9 ? 3 : 6) + newsize;
- newarr = MEM_callocN(idp_size_table[prop->type]*newsize, "idproperty array resized");
- /*newlen is bigger*/
- if (newlen >= prop->len) memcpy(newarr, prop->data.pointer, prop->len*idp_size_table[prop->type]);
- /*newlen is smaller*/
- else memcpy(newarr, prop->data.pointer, newlen*prop->len*idp_size_table[prop->type]);
+ newarr = MEM_callocN(idp_size_table[prop->subtype]*newsize, "idproperty array resized");
+ if (newlen >= prop->len) {
+ /* newlen is bigger*/
+ memcpy(newarr, prop->data.pointer, prop->len*idp_size_table[prop->subtype]);
+ idp_resize_group_array(prop, newlen, newarr);
+ }
+ else {
+ /* newlen is smaller*/
+ idp_resize_group_array(prop, newlen, newarr);
+ memcpy(newarr, prop->data.pointer, newlen*prop->len*idp_size_table[prop->subtype]);
+ }
MEM_freeN(prop->data.pointer);
prop->data.pointer = newarr;
@@ -96,10 +131,12 @@
prop->totallen = newsize;
}
- void IDP_FreeArray(IDProperty *prop)
+void IDP_FreeArray(IDProperty *prop)
{
- if (prop->data.pointer)
+ if (prop->data.pointer) {
+ idp_resize_group_array(prop, 0, NULL);
MEM_freeN(prop->data.pointer);
+ }
}
@@ -120,7 +157,17 @@
{
IDProperty *newp = idp_generic_copy(prop);
- if (prop->data.pointer) newp->data.pointer = MEM_dupallocN(prop->data.pointer);
+ if (prop->data.pointer) {
+ newp->data.pointer = MEM_dupallocN(prop->data.pointer);
+
+ if(prop->type == IDP_GROUP) {
+ IDProperty **array= newp->data.pointer;
+ int a;
+
+ for(a=0; a<prop->len; a++)
+ array[a]= IDP_CopyProperty(array[a]);
+ }
+ }
newp->len = prop->len;
newp->subtype = prop->subtype;
newp->totallen = prop->totallen;
@@ -381,11 +428,12 @@
case IDP_ARRAY:
{
/*for now, we only support float and int and double arrays*/
- if (val.array.type == IDP_FLOAT || val.array.type == IDP_INT || val.array.type == IDP_DOUBLE) {
+ if (val.array.type == IDP_FLOAT || val.array.type == IDP_INT || val.array.type == IDP_DOUBLE || val.array.type == IDP_GROUP) {
prop = MEM_callocN(sizeof(IDProperty), "IDProperty array");
- prop->len = prop->totallen = val.array.len;
prop->subtype = val.array.type;
prop->data.pointer = MEM_callocN(idp_size_table[val.array.type]*val.array.len, "id property array");
+ idp_resize_group_array(prop, val.array.len, prop->data.pointer);
+ prop->len = prop->totallen = val.array.len;
break;
} else {
return NULL;
Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c 2008-12-26 20:25:02 UTC (rev 18085)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c 2008-12-26 20:38:52 UTC (rev 18086)
@@ -1345,11 +1345,12 @@
/* ************ READ ID Properties *************** */
-void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, void *fd);
-void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, void *fd);
+void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
+void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd);
-static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, void *fd)
+static void IDP_DirectLinkArray(IDProperty *prop, int switch_endian, FileData *fd)
{
+ IDProperty **array;
int i;
/*since we didn't save the extra buffer, set totallen to len.*/
@@ -1357,26 +1358,33 @@
prop->data.pointer = newdataadr(fd, prop->data.pointer);
if (switch_endian) {
- if (prop->subtype != IDP_DOUBLE) {
+ if(prop->subtype == IDP_GROUP) {
+ test_pointer_array(fd, prop->data.pointer);
+ array= prop->data.pointer;
+
+ for(i=0; i<prop->len; i++)
+ IDP_DirectLinkProperty(array[i], switch_endian, fd);
+ }
+ else if(prop->subtype == IDP_DOUBLE) {
for (i=0; i<prop->len; i++) {
- SWITCH_INT(((int*)prop->data.pointer)[i]);
+ SWITCH_LONGINT(((double*)prop->data.pointer)[i]);
}
} else {
for (i=0; i<prop->len; i++) {
- SWITCH_LONGINT(((double*)prop->data.pointer)[i]);
+ SWITCH_INT(((int*)prop->data.pointer)[i]);
}
}
}
}
-static void IDP_DirectLinkString(IDProperty *prop, int switch_endian, void *fd)
+static void IDP_DirectLinkString(IDProperty *prop, int switch_endian, FileData *fd)
{
/*since we didn't save the extra string buffer, set totallen to len.*/
prop->totallen = prop->len;
prop->data.pointer = newdataadr(fd, prop->data.pointer);
}
-static void IDP_DirectLinkGroup(IDProperty *prop, int switch_endian, void *fd)
+static void IDP_DirectLinkGroup(IDProperty *prop, int switch_endian, FileData *fd)
{
ListBase *lb = &prop->data.group;
IDProperty *loop;
@@ -1389,7 +1397,7 @@
}
}
-void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, void *fd)
+void IDP_DirectLinkProperty(IDProperty *prop, int switch_endian, FileData *fd)
{
switch (prop->type) {
case IDP_GROUP:
@@ -1423,7 +1431,7 @@
}
/*stub function*/
-void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, void *fd)
+void IDP_LibLinkProperty(IDProperty *prop, int switch_endian, FileData *fd)
{
}
Modified: branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c 2008-12-26 20:25:02 UTC (rev 18085)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/writefile.c 2008-12-26 20:38:52 UTC (rev 18086)
@@ -390,6 +390,14 @@
/*REMEMBER to set totalen to len in the linking code!!*/
if (prop->data.pointer) {
writedata(wd, DATA, MEM_allocN_len(prop->data.pointer), prop->data.pointer);
+
+ if(prop->type == IDP_GROUP) {
+ IDProperty **array= prop->data.pointer;
+ int a;
+
+ for(a=0; a<prop->len; a++)
+ IDP_WriteProperty(array[a], wd);
+ }
}
}
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_access.h 2008-12-26 20:25:02 UTC (rev 18085)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_access.h 2008-12-26 20:38:52 UTC (rev 18086)
@@ -50,7 +50,6 @@
extern StructRNA RNA_CollisionSensor;
extern StructRNA RNA_ColorSequence;
extern StructRNA RNA_Constraint;
-// ... constraint types...
extern StructRNA RNA_Controller;
extern StructRNA RNA_Curve;
extern StructRNA RNA_CurveMap;
@@ -119,6 +118,7 @@
extern StructRNA RNA_NorController;
extern StructRNA RNA_Object;
extern StructRNA RNA_Operator;
+extern StructRNA RNA_OperatorMousePath;
extern StructRNA RNA_OperatorProperties;
extern StructRNA RNA_OrController;
extern StructRNA RNA_PackedFile;
@@ -266,6 +266,11 @@
int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr);
int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr);
+/* to create ID property groups */
+void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop);
+void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr);
+void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop);
+
/* Path
*
* Experimental method to refer to structs and properties with a string,
@@ -329,6 +334,25 @@
int RNA_string_length(PointerRNA *ptr, const char *name);
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value);
+void RNA_pointer_get(PointerRNA *ptr, const char *name, PointerRNA *r_value);
+void RNA_pointer_add(PointerRNA *ptr, const char *name);
+
+void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter);
+int RNA_collection_length(PointerRNA *ptr, const char *name);
+void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value);
+void RNA_collection_clear(PointerRNA *ptr, const char *name);
+
+#define RNA_BEGIN(sptr, itemptr, propname) \
+ { \
+ CollectionPropertyIterator rna_macro_iter; \
+ for(RNA_collection_begin(sptr, propname, &rna_macro_iter); rna_macro_iter.valid; RNA_property_collection_next(&rna_macro_iter)) { \
+ PointerRNA itemptr= rna_macro_iter.ptr;
+
+#define RNA_END \
+ } \
+ RNA_property_collection_end(&rna_macro_iter); \
+ }
+
/* check if the idproperty exists, for operators */
int RNA_property_is_set(PointerRNA *ptr, const char *name);
Modified: branches/blender2.5/blender/source/blender/makesrna/RNA_define.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/RNA_define.h 2008-12-26 20:25:02 UTC (rev 18085)
+++ branches/blender2.5/blender/source/blender/makesrna/RNA_define.h 2008-12-26 20:38:52 UTC (rev 18086)
@@ -69,6 +69,7 @@
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item);
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list