Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / makesrna / intern / rna_define.c
index 8d05cbd..f22fd59 100644 (file)
@@ -1001,18 +1001,18 @@ void RNA_def_property_clear_flag(PropertyRNA *prop, int flag)
        prop->flag &= ~flag;
 }
 
-void RNA_def_property_array(PropertyRNA *prop, int length)
+void RNA_def_property_array(PropertyRNA *prop, int arraylength)
 {
        StructRNA *srna= DefRNA.laststruct;
 
-       if(length<0) {
+       if(arraylength<0) {
                fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be zero of greater.\n", srna->identifier, prop->identifier);
                DefRNA.error= 1;
                return;
        }
 
-       if(length>RNA_MAX_ARRAY_LENGTH) {
-               fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be smaller than %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY_LENGTH);
+       if(arraylength>RNA_MAX_ARRAY) {
+               fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be smaller than %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY);
                DefRNA.error= 1;
                return;
        }
@@ -1021,9 +1021,7 @@ void RNA_def_property_array(PropertyRNA *prop, int length)
                case PROP_BOOLEAN:
                case PROP_INT:
                case PROP_FLOAT:
-                       prop->arraylength[0]= length;
-                       prop->totarraylength= length;
-                       prop->arraydimension= 1;
+                       prop->arraylength= arraylength;
                        break;
                default:
                        fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
@@ -1032,44 +1030,6 @@ void RNA_def_property_array(PropertyRNA *prop, int length)
        }
 }
 
-void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, int length[])
-{
-       StructRNA *srna= DefRNA.laststruct;
-       int i;
-       
-       if (dimension < 1 || dimension > RNA_MAX_ARRAY_DIMENSION) {
-               fprintf(stderr, "RNA_def_property_multi_array: %s.%s, array dimension must be between 1 and %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY_DIMENSION);
-               DefRNA.error= 1;
-               return;
-       }
-
-       switch(prop->type) {
-               case PROP_BOOLEAN:
-               case PROP_INT:
-               case PROP_FLOAT:
-                       break;
-               default:
-                       fprintf(stderr, "RNA_def_property_multi_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
-                       DefRNA.error= 1;
-                       break;
-       }
-
-       prop->arraydimension= dimension;
-       prop->totarraylength= 0;
-
-       if(length) {
-               memcpy(prop->arraylength, length, sizeof(int)*dimension);
-
-               prop->totarraylength= length[0];
-               for(i=1; i<dimension; i++)
-                       prop->totarraylength *= length[i];
-       }
-       else
-               memset(prop->arraylength, 0, sizeof(prop->arraylength));
-
-       /* TODO make sure arraylength values are sane  */
-}
-
 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
 {
        prop->name= name;
@@ -1213,14 +1173,8 @@ void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item
                                        defaultfound= 1;
                        }
 
-                       if(!defaultfound) {
-                               for(i=0; item[i].identifier; i++) {
-                                       if(item[i].identifier[0]) {
-                                               eprop->defaultvalue= item[i].value;
-                                               break;
-                                       }
-                               }
-                       }
+                       if(!defaultfound)
+                               eprop->defaultvalue= item[0].value;
 
                        break;
                }
@@ -1440,15 +1394,10 @@ static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *stru
                }
        }
 
-       if(smember.arraylength > 1) {
-               prop->arraylength[0]= smember.arraylength;
-               prop->totarraylength= smember.arraylength;
-               prop->arraydimension= 1;
-       }
-       else {
-               prop->arraydimension= 0;
-               prop->totarraylength= 0;
-       }
+       if(smember.arraylength > 1)
+               prop->arraylength= smember.arraylength;
+       else
+               prop->arraylength= 0;
        
        dp->dnastructname= structname;
        dp->dnastructfromname= ds->dnafromname;
@@ -1568,10 +1517,8 @@ void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const
        }
 
        if((dp=rna_def_property_sdna(prop, structname, propname))) {
-               if(prop->arraydimension) {
-                       prop->arraydimension= 0;
-                       prop->totarraylength= 0;
-
+               if(prop->arraylength) {
+                       prop->arraylength= 0;
                        if(!DefRNA.silent) {
                                fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, array not supported for enum type.\n", structname, propname);
                                DefRNA.error= 1;
@@ -1610,10 +1557,9 @@ void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, con
        }
 
        if((dp=rna_def_property_sdna(prop, structname, propname))) {
-               if(prop->arraydimension) {
-                       sprop->maxlength= prop->totarraylength;
-                       prop->arraydimension= 0;
-                       prop->totarraylength= 0;
+               if(prop->arraylength) {
+                       sprop->maxlength= prop->arraylength;
+                       prop->arraylength= 0;
                }
        }
 }
@@ -1635,10 +1581,8 @@ void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, co
        }
 
        if((dp=rna_def_property_sdna(prop, structname, propname))) {
-               if(prop->arraydimension) {
-                       prop->arraydimension= 0;
-                       prop->totarraylength= 0;
-
+               if(prop->arraylength) {
+                       prop->arraylength= 0;
                        if(!DefRNA.silent) {
                                fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, array not supported for pointer type.\n", structname, propname);
                                DefRNA.error= 1;
@@ -1665,9 +1609,8 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname,
        }
 
        if((dp=rna_def_property_sdna(prop, structname, propname))) {
-               if(prop->arraydimension && !lengthpropname) {
-                       prop->arraydimension= 0;
-                       prop->totarraylength= 0;
+               if(prop->arraylength && !lengthpropname) {
+                       prop->arraylength= 0;
 
                        if(!DefRNA.silent) {
                                fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, array of collections not supported.\n", structname, propname);
@@ -1691,9 +1634,8 @@ void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname,
 
                if(lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
                        if(lengthpropname[0] == 0) {
-                               dp->dnalengthfixed= prop->totarraylength;
-                               prop->arraydimension= 0;
-                               prop->totarraylength= 0;
+                               dp->dnalengthfixed= prop->arraylength;
+                               prop->arraylength= 0;
                        }
                        else {
                                dp->dnalengthstructname= structname;
@@ -1740,22 +1682,6 @@ void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
        prop->update= (UpdateFunc)func;
 }
 
-void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
-{
-       if(!DefRNA.preprocess) {
-               fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
-               return;
-       }
-
-       if (!(prop->flag & PROP_DYNAMIC)) {
-               fprintf(stderr, "RNA_def_property_dynamic_array_funcs: property is a not dynamic array.\n");
-               DefRNA.error= 1;
-               return;
-       }
-
-       if(getlength) prop->getlength= (PropArrayLengthGetFunc)getlength;
-}
-
 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
 {
        StructRNA *srna= DefRNA.laststruct;
@@ -1769,7 +1695,7 @@ void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const ch
                case PROP_BOOLEAN: {
                        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
-                       if(prop->arraydimension) {
+                       if(prop->arraylength) {
                                if(get) bprop->getarray= (PropBooleanArrayGetFunc)get;
                                if(set) bprop->setarray= (PropBooleanArraySetFunc)set;
                        }
@@ -1799,7 +1725,7 @@ void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *
                case PROP_INT: {
                        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
-                       if(prop->arraydimension) {
+                       if(prop->arraylength) {
                                if(get) iprop->getarray= (PropIntArrayGetFunc)get;
                                if(set) iprop->setarray= (PropIntArraySetFunc)set;
                        }
@@ -1830,7 +1756,7 @@ void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char
                case PROP_FLOAT: {
                        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
-                       if(prop->arraydimension) {
+                       if(prop->arraylength) {
                                if(get) fprop->getarray= (PropFloatArrayGetFunc)get;
                                if(set) fprop->setarray= (PropFloatArraySetFunc)set;
                        }
@@ -1982,34 +1908,6 @@ PropertyRNA *RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *ident
        return prop;
 }
 
-PropertyRNA *RNA_def_boolean_layer(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value, 
-       const char *ui_name, const char *ui_description)
-{
-       ContainerRNA *cont= cont_;
-       PropertyRNA *prop;
-       
-       prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER);
-       if(len != 0) RNA_def_property_array(prop, len);
-       if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
-       RNA_def_property_ui_text(prop, ui_name, ui_description);
-
-       return prop;
-}
-
-PropertyRNA *RNA_def_boolean_layer_member(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value, 
-       const char *ui_name, const char *ui_description)
-{
-       ContainerRNA *cont= cont_;
-       PropertyRNA *prop;
-       
-       prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER_MEMBER);
-       if(len != 0) RNA_def_property_array(prop, len);
-       if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
-       RNA_def_property_ui_text(prop, ui_name, ui_description);
-
-       return prop;
-}
-
 PropertyRNA *RNA_def_boolean_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value, 
        const char *ui_name, const char *ui_description)
 {
@@ -2181,15 +2079,14 @@ PropertyRNA *RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identif
 }
 
 
-PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int rows, int columns, const float *default_value, 
+PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, 
        float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
 {
        ContainerRNA *cont= cont_;
        PropertyRNA *prop;
-       int length[2]= {rows, columns};
        
        prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_MATRIX);
-       RNA_def_property_multi_array(prop, 2, length);
+       if(len != 0) RNA_def_property_array(prop, len);
        if(default_value) RNA_def_property_float_array_default(prop, default_value);
        if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
        RNA_def_property_ui_text(prop, ui_name, ui_description);
@@ -2386,12 +2283,11 @@ void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
 int rna_parameter_size(PropertyRNA *parm)
 {
        PropertyType ptype= parm->type;
-       int len= parm->totarraylength; /* only supports fixed length at the moment */
+       int len= parm->arraylength;
 
-       if(len > 0) {
-               if (parm->flag & PROP_DYNAMIC)
-                       return sizeof(void *);
+       if (parm->flag & PROP_DYNAMIC_ARRAY) return sizeof(void*);
 
+       if(len > 0) {
                switch (ptype) {
                        case PROP_BOOLEAN:
                        case PROP_INT:
@@ -2536,8 +2432,8 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
                        BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
 
                        if(bprop->defaultarray) {
-                               iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
-                               memcpy(iarray, bprop->defaultarray, sizeof(int)*prop->totarraylength);
+                               iarray= MEM_callocN(sizeof(int)*prop->arraylength, "RNA_def_property_store");
+                               memcpy(iarray, bprop->defaultarray, sizeof(int)*prop->arraylength);
                                bprop->defaultarray= iarray;
                        }
                        break;
@@ -2546,8 +2442,8 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
                        IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
 
                        if(iprop->defaultarray) {
-                               iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
-                               memcpy(iarray, iprop->defaultarray, sizeof(int)*prop->totarraylength);
+                               iarray= MEM_callocN(sizeof(int)*prop->arraylength, "RNA_def_property_store");
+                               memcpy(iarray, iprop->defaultarray, sizeof(int)*prop->arraylength);
                                iprop->defaultarray= iarray;
                        }
                        break;
@@ -2572,8 +2468,8 @@ void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
                        FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
 
                        if(fprop->defaultarray) {
-                               farray= MEM_callocN(sizeof(float)*prop->totarraylength, "RNA_def_property_store");
-                               memcpy(farray, fprop->defaultarray, sizeof(float)*prop->totarraylength);
+                               farray= MEM_callocN(sizeof(float)*prop->arraylength, "RNA_def_property_store");
+                               memcpy(farray, fprop->defaultarray, sizeof(float)*prop->arraylength);
                                fprop->defaultarray= farray;
                        }
                        break;
@@ -2617,14 +2513,13 @@ void RNA_def_property_free_pointers(PropertyRNA *prop)
                        }
                        case PROP_ENUM: {
                                EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
+                               if(eprop->item) MEM_freeN((void*)eprop->item);
 
                                for(a=0; a<eprop->totitem; a++) {
                                        if(eprop->item[a].identifier) MEM_freeN((void*)eprop->item[a].identifier);
                                        if(eprop->item[a].name) MEM_freeN((void*)eprop->item[a].name);
                                        if(eprop->item[a].description) MEM_freeN((void*)eprop->item[a].description);
                                }
-
-                               if(eprop->item) MEM_freeN((void*)eprop->item);
                                break;
                        }
                        case PROP_STRING: {