Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-12-26 23:38:52 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-12-26 23:38:52 +0300
commit82cf2aebba1c340c1c4fffde1e89fc80a4591fea (patch)
tree18d58c3ce61401b4fcd077f902e06235cab737be /source/blender/blenkernel/intern/idprop.c
parent254fc41b56e8c4f828e9721a045c8c5108044d0a (diff)
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;
Diffstat (limited to 'source/blender/blenkernel/intern/idprop.c')
-rw-r--r--source/blender/blenkernel/intern/idprop.c68
1 files changed, 58 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index 542a1dff651..bd6dc7d6ed5 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -61,6 +61,34 @@ static char idp_size_table[] = {
/* ----------- 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 @@ void IDP_ResizeArray(IDProperty *prop, int newlen)
/*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 @@ void IDP_ResizeArray(IDProperty *prop, int newlen)
*/
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 @@ void IDP_ResizeArray(IDProperty *prop, int newlen)
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 *IDP_CopyArray(IDProperty *prop)
{
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 @@ IDProperty *IDP_New(int type, IDPropertyTemplate val, char *name)
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;