Blender  V2.59
rna_define.c
Go to the documentation of this file.
00001 /*
00002  * $Id: rna_define.c 37260 2011-06-06 17:50:20Z campbellbarton $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * Contributor(s): Blender Foundation (2008).
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include <float.h>
00031 #include <limits.h>
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <ctype.h>
00036 
00037 #include "MEM_guardedalloc.h"
00038 
00039 #include "DNA_genfile.h"
00040 #include "DNA_sdna_types.h"
00041 
00042 #include "BLI_string.h"
00043 #include "BLI_utildefines.h"
00044 #include "BLI_ghash.h"
00045 
00046 #include "RNA_define.h"
00047 
00048 #include "rna_internal.h"
00049 
00050 /* Global used during defining */
00051 
00052 BlenderDefRNA DefRNA = {NULL, {NULL, NULL}, {NULL, NULL}, NULL, 0, 0, 0, 1};
00053 
00054 /* Duplicated code since we can't link in blenkernel or blenlib */
00055 
00056 #ifndef MIN2
00057 #define MIN2(x,y) ((x)<(y)? (x): (y))
00058 #define MAX2(x,y) ((x)>(y)? (x): (y))
00059 #endif
00060 
00061 void rna_addtail(ListBase *listbase, void *vlink)
00062 {
00063         Link *link= vlink;
00064 
00065         link->next = NULL;
00066         link->prev = listbase->last;
00067 
00068         if (listbase->last) ((Link *)listbase->last)->next = link;
00069         if (listbase->first == NULL) listbase->first = link;
00070         listbase->last = link;
00071 }
00072 
00073 static void rna_remlink(ListBase *listbase, void *vlink)
00074 {
00075         Link *link= vlink;
00076 
00077         if (link->next) link->next->prev = link->prev;
00078         if (link->prev) link->prev->next = link->next;
00079 
00080         if (listbase->last == link) listbase->last = link->prev;
00081         if (listbase->first == link) listbase->first = link->next;
00082 }
00083 
00084 PropertyDefRNA *rna_findlink(ListBase *listbase, const char *identifier)
00085 {
00086         Link *link;
00087 
00088         for(link=listbase->first; link; link=link->next) {
00089                 PropertyRNA *prop= ((PropertyDefRNA *)link)->prop;
00090                 if(prop && (strcmp(prop->identifier, identifier)==0)) {
00091                         return (PropertyDefRNA *)link;
00092                 }
00093         }
00094 
00095         return NULL;
00096 }
00097 
00098 void rna_freelinkN(ListBase *listbase, void *vlink)
00099 {
00100         rna_remlink(listbase, vlink);
00101         MEM_freeN(vlink);
00102 }
00103 
00104 void rna_freelistN(ListBase *listbase)
00105 {
00106         Link *link, *next;
00107         
00108         for(link=listbase->first; link; link=next) {
00109                 next= link->next;
00110                 MEM_freeN(link);
00111         }
00112         
00113         listbase->first= listbase->last= NULL;
00114 }
00115 
00116 StructDefRNA *rna_find_struct_def(StructRNA *srna)
00117 {
00118         StructDefRNA *dsrna;
00119 
00120         if(!DefRNA.preprocess) {
00121                 /* we should never get here */
00122                 fprintf(stderr, "rna_find_struct_def: only at preprocess time.\n");
00123                 return NULL;
00124         }
00125 
00126         dsrna= DefRNA.structs.last;
00127         for (; dsrna; dsrna= dsrna->cont.prev)
00128                 if (dsrna->srna==srna)
00129                         return dsrna;
00130 
00131         return NULL;
00132 }
00133 
00134 PropertyDefRNA *rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop)
00135 {
00136         StructDefRNA *dsrna;
00137         PropertyDefRNA *dprop;
00138 
00139         if(!DefRNA.preprocess) {
00140                 /* we should never get here */
00141                 fprintf(stderr, "rna_find_struct_property_def: only at preprocess time.\n");
00142                 return NULL;
00143         }
00144 
00145         dsrna= rna_find_struct_def(srna);
00146         dprop= dsrna->cont.properties.last;
00147         for (; dprop; dprop= dprop->prev)
00148                 if (dprop->prop==prop)
00149                         return dprop;
00150 
00151         dsrna= DefRNA.structs.last;
00152         for (; dsrna; dsrna= dsrna->cont.prev) {
00153                 dprop= dsrna->cont.properties.last;
00154                 for (; dprop; dprop= dprop->prev)
00155                         if (dprop->prop==prop)
00156                                 return dprop;
00157         }
00158 
00159         return NULL;
00160 }
00161 
00162 #if 0
00163 static PropertyDefRNA *rna_find_property_def(PropertyRNA *prop)
00164 {
00165         PropertyDefRNA *dprop;
00166 
00167         if(!DefRNA.preprocess) {
00168                 /* we should never get here */
00169                 fprintf(stderr, "rna_find_property_def: only at preprocess time.\n");
00170                 return NULL;
00171         }
00172 
00173         dprop= rna_find_struct_property_def(DefRNA.laststruct, prop);
00174         if (dprop)
00175                 return dprop;
00176 
00177         dprop= rna_find_parameter_def(prop);
00178         if (dprop)
00179                 return dprop;
00180 
00181         return NULL;
00182 }
00183 #endif
00184 
00185 FunctionDefRNA *rna_find_function_def(FunctionRNA *func)
00186 {
00187         StructDefRNA *dsrna;
00188         FunctionDefRNA *dfunc;
00189 
00190         if(!DefRNA.preprocess) {
00191                 /* we should never get here */
00192                 fprintf(stderr, "rna_find_function_def: only at preprocess time.\n");
00193                 return NULL;
00194         }
00195 
00196         dsrna= rna_find_struct_def(DefRNA.laststruct);
00197         dfunc= dsrna->functions.last;
00198         for (; dfunc; dfunc= dfunc->cont.prev)
00199                 if (dfunc->func==func)
00200                         return dfunc;
00201 
00202         dsrna= DefRNA.structs.last;
00203         for (; dsrna; dsrna= dsrna->cont.prev) {
00204                 dfunc= dsrna->functions.last;
00205                 for (; dfunc; dfunc= dfunc->cont.prev)
00206                         if (dfunc->func==func)
00207                                 return dfunc;
00208         }
00209 
00210         return NULL;
00211 }
00212 
00213 PropertyDefRNA *rna_find_parameter_def(PropertyRNA *parm)
00214 {
00215         StructDefRNA *dsrna;
00216         FunctionDefRNA *dfunc;
00217         PropertyDefRNA *dparm;
00218 
00219         if(!DefRNA.preprocess) {
00220                 /* we should never get here */
00221                 fprintf(stderr, "rna_find_parameter_def: only at preprocess time.\n");
00222                 return NULL;
00223         }
00224 
00225         dsrna= rna_find_struct_def(DefRNA.laststruct);
00226         dfunc= dsrna->functions.last;
00227         for (; dfunc; dfunc= dfunc->cont.prev) {
00228                 dparm= dfunc->cont.properties.last;
00229                 for (; dparm; dparm= dparm->prev)
00230                         if (dparm->prop==parm)
00231                                 return dparm;
00232         }
00233 
00234         dsrna= DefRNA.structs.last;
00235         for (; dsrna; dsrna= dsrna->cont.prev) {
00236                 dfunc= dsrna->functions.last;
00237                 for (; dfunc; dfunc= dfunc->cont.prev) {
00238                         dparm= dfunc->cont.properties.last;
00239                         for (; dparm; dparm= dparm->prev)
00240                                 if (dparm->prop==parm)
00241                                         return dparm;
00242                 }
00243         }
00244 
00245         return NULL;
00246 }
00247 
00248 static ContainerDefRNA *rna_find_container_def(ContainerRNA *cont)
00249 {
00250         StructDefRNA *ds;
00251         FunctionDefRNA *dfunc;
00252 
00253         if(!DefRNA.preprocess) {
00254                 /* we should never get here */
00255                 fprintf(stderr, "rna_find_container_def: only at preprocess time.\n");
00256                 return NULL;
00257         }
00258 
00259         ds= rna_find_struct_def((StructRNA*)cont);
00260         if(ds)
00261                 return &ds->cont;
00262 
00263         dfunc= rna_find_function_def((FunctionRNA*)cont);
00264         if(dfunc)
00265                 return &dfunc->cont;
00266 
00267         return NULL;
00268 }
00269 
00270 /* DNA utility function for looking up members */
00271 
00272 typedef struct DNAStructMember {
00273         const char *type;
00274         const char *name;
00275         int arraylength;
00276         int pointerlevel;
00277 } DNAStructMember;
00278 
00279 static int rna_member_cmp(const char *name, const char *oname)
00280 {
00281         int a=0;
00282         
00283         /* compare without pointer or array part */
00284         while(name[0]=='*')
00285                 name++;
00286         while(oname[0]=='*')
00287                 oname++;
00288         
00289         while(1) {
00290                 if(name[a]=='[' && oname[a]==0) return 1;
00291                 if(name[a]=='[' && oname[a]=='[') return 1;
00292                 if(name[a]==0) break;
00293                 if(name[a] != oname[a]) return 0;
00294                 a++;
00295         }
00296         if(name[a]==0 && oname[a] == '.') return 2;
00297         if(name[a]==0 && oname[a] == '-' && oname[a+1] == '>') return 3;
00298 
00299         return (name[a] == oname[a]);
00300 }
00301 
00302 static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *membername, DNAStructMember *smember)
00303 {
00304         const char *dnaname;
00305         short *sp;
00306         int a, b, structnr, totmember, cmp;
00307 
00308         structnr= DNA_struct_find_nr(sdna, structname);
00309         if(structnr == -1)
00310                 return 0;
00311 
00312         sp= sdna->structs[structnr];
00313         totmember= sp[1];
00314         sp+= 2;
00315 
00316         for(a=0; a<totmember; a++, sp+=2) {
00317                 dnaname= sdna->names[sp[1]];
00318 
00319                 cmp= rna_member_cmp(dnaname, membername);
00320 
00321                 if(cmp == 1) {
00322                         smember->type= sdna->types[sp[0]];
00323                         smember->name= dnaname;
00324 
00325                         if(strstr(membername, "["))
00326                                 smember->arraylength= 0;
00327                         else
00328                                 smember->arraylength= DNA_elem_array_size(smember->name, strlen(smember->name));
00329 
00330                         smember->pointerlevel= 0;
00331                         for(b=0; dnaname[b] == '*'; b++)
00332                                 smember->pointerlevel++;
00333 
00334                         return 1;
00335                 }
00336                 else if(cmp == 2) {
00337                         smember->type= "";
00338                         smember->name= dnaname;
00339                         smember->pointerlevel= 0;
00340                         smember->arraylength= 0;
00341 
00342                         membername= strstr(membername, ".") + strlen(".");
00343                         rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
00344 
00345                         return 1;
00346                 }
00347                 else if(cmp == 3) {
00348                         smember->type= "";
00349                         smember->name= dnaname;
00350                         smember->pointerlevel= 0;
00351                         smember->arraylength= 0;
00352 
00353                         membername= strstr(membername, "->") + strlen("->");
00354                         rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
00355 
00356                         return 1;
00357                 }
00358         }
00359 
00360         return 0;
00361 }
00362 
00363 static int rna_validate_identifier(const char *identifier, char *error, int property)
00364 {
00365         int a=0;
00366         
00367         /*  list from http://docs.python.org/reference/lexical_analysis.html#id5 */
00368         static const char *kwlist[] = {
00369                 "and", "as", "assert", "break",
00370                 "class", "continue", "def", "del",
00371                 "elif", "else", "except", "exec",
00372                 "finally", "for", "from", "global",
00373                 "if", "import", "in", "is",
00374                 "lambda", "not", "or", "pass",
00375                 "print", "raise", "return", "try",
00376                 "while", "with", "yield", NULL
00377         };
00378         
00379         
00380         if (!isalpha(identifier[0])) {
00381                 strcpy(error, "first character failed isalpha() check");
00382                 return 0;
00383         }
00384         
00385         for(a=0; identifier[a]; a++) {
00386                 if(DefRNA.preprocess && property) {
00387                         if(isalpha(identifier[a]) && isupper(identifier[a])) {
00388                                 strcpy(error, "property names must contain lower case characters only");
00389                                 return 0;
00390                         }
00391                 }
00392                 
00393                 if (identifier[a]=='_') {
00394                         continue;
00395                 }
00396 
00397                 if (identifier[a]==' ') {
00398                         strcpy(error, "spaces are not okay in identifier names");
00399                         return 0;
00400                 }
00401 
00402                 if (isalnum(identifier[a])==0) {
00403                         strcpy(error, "one of the characters failed an isalnum() check and is not an underscore");
00404                         return 0;
00405                 }
00406         }
00407         
00408         for(a=0; kwlist[a]; a++) {
00409                 if (strcmp(identifier, kwlist[a]) == 0) {
00410                         strcpy(error, "this keyword is reserved by python");
00411                         return 0;
00412                 }
00413         }
00414 
00415         if(property) {
00416                 static const char *kwlist_prop[] = {
00417                         /* not keywords but reserved all the same because py uses */
00418                         "keys", "values", "items", "get",
00419                         NULL
00420                 };
00421 
00422                 for(a=0; kwlist_prop[a]; a++) {
00423                         if (strcmp(identifier, kwlist_prop[a]) == 0) {
00424                                 strcpy(error, "this keyword is reserved by python");
00425                                 return 0;
00426                         }
00427                 }
00428         }
00429         
00430         return 1;
00431 }
00432 
00433 /* Blender Data Definition */
00434 
00435 BlenderRNA *RNA_create(void)
00436 {
00437         BlenderRNA *brna;
00438 
00439         brna= MEM_callocN(sizeof(BlenderRNA), "BlenderRNA");
00440 
00441         DefRNA.sdna= DNA_sdna_from_data(DNAstr,  DNAlen, 0);
00442         DefRNA.structs.first= DefRNA.structs.last= NULL;
00443         DefRNA.error= 0;
00444         DefRNA.preprocess= 1;
00445 
00446         return brna;
00447 }
00448 
00449 void RNA_define_free(BlenderRNA *UNUSED(brna))
00450 {
00451         StructDefRNA *ds;
00452         FunctionDefRNA *dfunc;
00453         AllocDefRNA *alloc;
00454 
00455         for(alloc=DefRNA.allocs.first; alloc; alloc=alloc->next)
00456                 MEM_freeN(alloc->mem);
00457         rna_freelistN(&DefRNA.allocs);
00458 
00459         for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
00460                 for (dfunc= ds->functions.first; dfunc; dfunc= dfunc->cont.next)
00461                         rna_freelistN(&dfunc->cont.properties);
00462 
00463                 rna_freelistN(&ds->cont.properties);
00464                 rna_freelistN(&ds->functions);
00465         }
00466 
00467         rna_freelistN(&DefRNA.structs);
00468 
00469         if(DefRNA.sdna) {
00470                 DNA_sdna_free(DefRNA.sdna);
00471                 DefRNA.sdna= NULL;
00472         }
00473 
00474         DefRNA.error= 0;
00475 }
00476 
00477 void RNA_define_verify_sdna(int verify)
00478 {
00479         DefRNA.verify= verify;
00480 }
00481 
00482 void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *ext)
00483 {
00484 #ifdef RNA_RUNTIME
00485         ext->free(ext->data);                   /* decref's the PyObject that the srna owns */
00486         RNA_struct_blender_type_set(srna, NULL); /* this gets accessed again - XXX fixme */
00487         RNA_struct_py_type_set(srna, NULL);     /* NULL the srna's value so RNA_struct_free wont complain of a leak */
00488 #endif  
00489 }
00490 
00491 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
00492 {
00493 #ifdef RNA_RUNTIME
00494         FunctionRNA *func, *nextfunc;
00495         PropertyRNA *prop, *nextprop;
00496         PropertyRNA *parm, *nextparm;
00497 
00498         /*
00499         if(srna->flag & STRUCT_RUNTIME) {
00500                 if(RNA_struct_py_type_get(srna)) {
00501                         fprintf(stderr, "RNA_struct_free '%s' freed while holding a python reference\n", srna->identifier);
00502                 }
00503         } */
00504 
00505         for(prop=srna->cont.properties.first; prop; prop=nextprop) {
00506                 nextprop= prop->next;
00507 
00508                 RNA_def_property_free_pointers(prop);
00509 
00510                 if(prop->flag & PROP_RUNTIME)
00511                         rna_freelinkN(&srna->cont.properties, prop);
00512         }
00513 
00514         for(func=srna->functions.first; func; func=nextfunc) {
00515                 nextfunc= func->cont.next;
00516 
00517                 for(parm=func->cont.properties.first; parm; parm=nextparm) {
00518                         nextparm= parm->next;
00519 
00520                         RNA_def_property_free_pointers(parm);
00521 
00522                         if(parm->flag & PROP_RUNTIME)
00523                                 rna_freelinkN(&func->cont.properties, parm);
00524                 }
00525 
00526                 RNA_def_func_free_pointers(func);
00527 
00528                 if(func->flag & FUNC_RUNTIME)
00529                         rna_freelinkN(&srna->functions, func);
00530         }
00531 
00532         RNA_def_struct_free_pointers(srna);
00533 
00534         if(srna->flag & STRUCT_RUNTIME)
00535                 rna_freelinkN(&brna->structs, srna);
00536 
00537 #endif
00538 }
00539 
00540 void RNA_free(BlenderRNA *brna)
00541 {
00542         StructRNA *srna, *nextsrna;
00543         FunctionRNA *func;
00544 
00545         if(DefRNA.preprocess) {
00546                 RNA_define_free(brna);
00547 
00548                 for(srna=brna->structs.first; srna; srna=srna->cont.next) {
00549                         for (func= srna->functions.first; func; func= func->cont.next)
00550                                 rna_freelistN(&func->cont.properties);
00551 
00552                         rna_freelistN(&srna->cont.properties);
00553                         rna_freelistN(&srna->functions);
00554                 }
00555 
00556                 rna_freelistN(&brna->structs);
00557                 
00558                 MEM_freeN(brna);
00559         }
00560         else {
00561                 for(srna=brna->structs.first; srna; srna=nextsrna) {
00562                         nextsrna= srna->cont.next;
00563                         RNA_struct_free(brna, srna);
00564                 }
00565         }
00566 }
00567 
00568 static size_t rna_property_type_sizeof(PropertyType type)
00569 {
00570         switch(type) {
00571                 case PROP_BOOLEAN: return sizeof(BooleanPropertyRNA);
00572                 case PROP_INT: return sizeof(IntPropertyRNA);
00573                 case PROP_FLOAT: return sizeof(FloatPropertyRNA);
00574                 case PROP_STRING: return sizeof(StringPropertyRNA);
00575                 case PROP_ENUM: return sizeof(EnumPropertyRNA);
00576                 case PROP_POINTER: return sizeof(PointerPropertyRNA);
00577                 case PROP_COLLECTION: return sizeof(CollectionPropertyRNA);
00578                 default: return 0;
00579         }
00580 }
00581 
00582 static StructDefRNA *rna_find_def_struct(StructRNA *srna)
00583 {
00584         StructDefRNA *ds;
00585 
00586         for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
00587                 if(ds->srna == srna)
00588                         return ds;
00589 
00590         return NULL;
00591 }
00592 
00593 /* Struct Definition */
00594 
00595 StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
00596 {
00597         StructRNA *srna, *srnafrom= NULL;
00598         StructDefRNA *ds= NULL, *dsfrom= NULL;
00599         PropertyRNA *prop;
00600         
00601         if(DefRNA.preprocess) {
00602                 char error[512];
00603 
00604                 if (rna_validate_identifier(identifier, error, 0) == 0) {
00605                         fprintf(stderr, "RNA_def_struct: struct identifier \"%s\" error - %s\n", identifier, error);
00606                         DefRNA.error= 1;
00607                 }
00608         }
00609         
00610         if(from) {
00611                 /* find struct to derive from */
00612                 for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->cont.next)
00613                         if(strcmp(srnafrom->identifier, from) == 0)
00614                                 break;
00615 
00616                 if(!srnafrom) {
00617                         fprintf(stderr, "RNA_def_struct: struct %s not found to define %s.\n", from, identifier);
00618                         DefRNA.error= 1;
00619                 }
00620         }
00621 
00622         srna= MEM_callocN(sizeof(StructRNA), "StructRNA");
00623         DefRNA.laststruct= srna;
00624 
00625         if(srnafrom) {
00626                 /* copy from struct to derive stuff, a bit clumsy since we can't
00627                  * use MEM_dupallocN, data structs may not be alloced but builtin */
00628                 memcpy(srna, srnafrom, sizeof(StructRNA));
00629                 srna->cont.prophash= NULL;
00630                 srna->cont.properties.first= srna->cont.properties.last= NULL;
00631                 srna->functions.first= srna->functions.last= NULL;
00632                 srna->py_type= NULL;
00633 
00634                 if(DefRNA.preprocess) {
00635                         srna->base= srnafrom;
00636                         dsfrom= rna_find_def_struct(srnafrom);
00637                 }
00638                 else
00639                         srna->base= srnafrom;
00640         }
00641         
00642         srna->identifier= identifier;
00643         srna->name= identifier; /* may be overwritten later RNA_def_struct_ui_text */
00644         srna->description= "";
00645         if(!srnafrom)
00646                 srna->icon= ICON_DOT;
00647 
00648         rna_addtail(&brna->structs, srna);
00649 
00650         if(DefRNA.preprocess) {
00651                 ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
00652                 ds->srna= srna;
00653                 rna_addtail(&DefRNA.structs, ds);
00654 
00655                 if(dsfrom)
00656                         ds->dnafromname= dsfrom->dnaname;
00657         }
00658 
00659         /* in preprocess, try to find sdna */
00660         if(DefRNA.preprocess)
00661                 RNA_def_struct_sdna(srna, srna->identifier);
00662         else
00663                 srna->flag |= STRUCT_RUNTIME;
00664 
00665         if(srnafrom) {
00666                 srna->nameproperty= srnafrom->nameproperty;
00667                 srna->iteratorproperty= srnafrom->iteratorproperty;
00668         }
00669         else {
00670                 /* define some builtin properties */
00671                 prop= RNA_def_property(&srna->cont, "rna_properties", PROP_COLLECTION, PROP_NONE);
00672                 RNA_def_property_flag(prop, PROP_BUILTIN);
00673                 RNA_def_property_ui_text(prop, "Properties", "RNA property collection");
00674 
00675                 if(DefRNA.preprocess) {
00676                         RNA_def_property_struct_type(prop, "Property");
00677                         RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", NULL, NULL, "rna_builtin_properties_lookup_string");
00678                 }
00679                 else {
00680 #ifdef RNA_RUNTIME
00681                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
00682                         cprop->begin= rna_builtin_properties_begin;
00683                         cprop->next= rna_builtin_properties_next;
00684                         cprop->get= rna_builtin_properties_get;
00685                         cprop->item_type= &RNA_Property;
00686 #endif
00687                 }
00688 
00689                 prop= RNA_def_property(&srna->cont, "rna_type", PROP_POINTER, PROP_NONE);
00690                 RNA_def_property_flag(prop, PROP_HIDDEN);
00691                 RNA_def_property_ui_text(prop, "RNA", "RNA type definition");
00692 
00693                 if(DefRNA.preprocess) {
00694                         RNA_def_property_struct_type(prop, "Struct");
00695                         RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL, NULL);
00696                 }
00697                 else {
00698 #ifdef RNA_RUNTIME
00699                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
00700                         pprop->get= rna_builtin_type_get;
00701                         pprop->type= &RNA_Struct;
00702 #endif
00703                 }
00704         }
00705 
00706         return srna;
00707 }
00708 
00709 void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
00710 {
00711         StructDefRNA *ds;
00712 
00713         if(!DefRNA.preprocess) {
00714                 fprintf(stderr, "RNA_def_struct_sdna: only during preprocessing.\n");
00715                 return;
00716         }
00717 
00718         ds= rna_find_def_struct(srna);
00719 
00720         if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
00721                 if(!DefRNA.silent) {
00722                         fprintf(stderr, "RNA_def_struct_sdna: %s not found.\n", structname);
00723                         DefRNA.error= 1;
00724                 }
00725                 return;
00726         }
00727 
00728         ds->dnaname= structname;
00729 }
00730 
00731 void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
00732 {
00733         StructDefRNA *ds;
00734 
00735         if(!DefRNA.preprocess) {
00736                 fprintf(stderr, "RNA_def_struct_sdna_from: only during preprocessing.\n");
00737                 return;
00738         }
00739 
00740         ds= rna_find_def_struct(srna);
00741 
00742         if(!ds->dnaname) {
00743                 fprintf(stderr, "RNA_def_struct_sdna_from: %s base struct must know DNA already.\n", structname);
00744                 return;
00745         }
00746 
00747         if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
00748                 if(!DefRNA.silent) {
00749                         fprintf(stderr, "RNA_def_struct_sdna_from: %s not found.\n", structname);
00750                         DefRNA.error= 1;
00751                 }
00752                 return;
00753         }
00754 
00755         ds->dnafromprop= propname;
00756         ds->dnaname= structname;
00757 }
00758 
00759 void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
00760 {
00761         if(prop->type != PROP_STRING) {
00762                 fprintf(stderr, "RNA_def_struct_name_property: \"%s.%s\", must be a string property.\n", srna->identifier, prop->identifier);
00763                 DefRNA.error= 1;
00764         }
00765         else
00766                 srna->nameproperty= prop;
00767 }
00768 
00769 void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
00770 {
00771         StructRNA *srnafrom;
00772 
00773         /* find struct to derive from */
00774         for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->cont.next)
00775                 if(strcmp(srnafrom->identifier, structname) == 0)
00776                         break;
00777 
00778         if(!srnafrom) {
00779                 fprintf(stderr, "RNA_def_struct_nested: struct %s not found for %s.\n", structname, srna->identifier);
00780                 DefRNA.error= 1;
00781         }
00782 
00783         srna->nested= srnafrom;
00784 }
00785 
00786 void RNA_def_struct_flag(StructRNA *srna, int flag)
00787 {
00788         srna->flag |= flag;
00789 }
00790 
00791 void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
00792 {
00793         srna->flag &= ~flag;
00794 }
00795 
00796 void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
00797 {
00798         if(!DefRNA.preprocess) {
00799                 fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
00800                 return;
00801         }
00802 
00803         if(refine) srna->refine= (StructRefineFunc)refine;
00804 }
00805 
00806 void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
00807 {
00808         if(!DefRNA.preprocess) {
00809                 fprintf(stderr, "RNA_def_struct_idprops_func: only during preprocessing.\n");
00810                 return;
00811         }
00812 
00813         if(idproperties) srna->idproperties= (IDPropertiesFunc)idproperties;
00814 }
00815 
00816 void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance)
00817 {
00818         if(!DefRNA.preprocess) {
00819                 fprintf(stderr, "RNA_def_struct_register_funcs: only during preprocessing.\n");
00820                 return;
00821         }
00822 
00823         if(reg) srna->reg= (StructRegisterFunc)reg;
00824         if(unreg) srna->unreg= (StructUnregisterFunc)unreg;
00825         if(instance) srna->instance= (StructInstanceFunc)instance;
00826 }
00827 
00828 void RNA_def_struct_path_func(StructRNA *srna, const char *path)
00829 {
00830         if(!DefRNA.preprocess) {
00831                 fprintf(stderr, "RNA_def_struct_path_func: only during preprocessing.\n");
00832                 return;
00833         }
00834 
00835         if(path) srna->path= (StructPathFunc)path;
00836 }
00837 
00838 void RNA_def_struct_identifier(StructRNA *srna, const char *identifier)
00839 {
00840         if(DefRNA.preprocess) {
00841                 fprintf(stderr, "RNA_def_struct_name_runtime: only at runtime.\n");
00842                 return;
00843         }
00844 
00845         srna->identifier= identifier;
00846 }
00847 
00848 void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
00849 {
00850         srna->name= name;
00851         srna->description= description;
00852 }
00853 
00854 void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
00855 {
00856         srna->icon= icon;
00857 }
00858 
00859 /* Property Definition */
00860 
00861 PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
00862 {
00863         /*StructRNA *srna= DefRNA.laststruct;*/ /* invalid for python defined props */
00864         ContainerRNA *cont= cont_;
00865         ContainerDefRNA *dcont;
00866         PropertyDefRNA *dprop= NULL;
00867         PropertyRNA *prop;
00868 
00869         if(DefRNA.preprocess) {
00870                 char error[512];
00871                 
00872                 if (rna_validate_identifier(identifier, error, 1) == 0) {
00873                         fprintf(stderr, "RNA_def_property: property identifier \"%s.%s\" - %s\n", CONTAINER_RNA_ID(cont), identifier, error);
00874                         DefRNA.error= 1;
00875                 }
00876                 
00877                 dcont= rna_find_container_def(cont);
00878 
00879                 /* XXX - toto, detect supertype collisions */
00880                 if(rna_findlink(&dcont->properties, identifier)) {
00881                         fprintf(stderr, "RNA_def_property: duplicate identifier \"%s.%s\"\n", CONTAINER_RNA_ID(cont), identifier);
00882                         DefRNA.error= 1;
00883                 }
00884 
00885                 dprop= MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA");
00886                 rna_addtail(&dcont->properties, dprop);
00887         }
00888 
00889         prop= MEM_callocN(rna_property_type_sizeof(type), "PropertyRNA");
00890 
00891         switch(type) {
00892                 case PROP_BOOLEAN:
00893                         break;
00894                 case PROP_INT: {
00895                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
00896 
00897                         iprop->hardmin= (subtype == PROP_UNSIGNED)? 0: INT_MIN;
00898                         iprop->hardmax= INT_MAX;
00899 
00900                         iprop->softmin= (subtype == PROP_UNSIGNED)? 0: -10000; /* rather arbitrary .. */
00901                         iprop->softmax= 10000;
00902                         iprop->step= 1;
00903                         break;
00904                 }
00905                 case PROP_FLOAT: {
00906                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
00907 
00908                         fprop->hardmin= (subtype == PROP_UNSIGNED)? 0.0f: -FLT_MAX;
00909                         fprop->hardmax= FLT_MAX;
00910 
00911                         if(ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
00912                                 fprop->softmin= 0.0f;
00913                                 fprop->softmax= 1.0f;
00914                         }
00915                         else if(subtype == PROP_FACTOR) {
00916                                 fprop->softmin= fprop->hardmin= 0.0f;
00917                                 fprop->softmax= fprop->hardmax= 1.0f;
00918                         }
00919                         else {
00920                                 fprop->softmin= (subtype == PROP_UNSIGNED)? 0.0f: -10000.0f; /* rather arbitrary .. */
00921                                 fprop->softmax= 10000.0f;
00922                         }
00923                         fprop->step= 10;
00924                         fprop->precision= 3;
00925                         break;
00926                 }
00927                 case PROP_STRING: {
00928                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
00929 
00930                         sprop->defaultvalue= "";
00931                         sprop->maxlength= 0;
00932                         break;
00933                 }
00934                 case PROP_ENUM:
00935                 case PROP_POINTER:
00936                 case PROP_COLLECTION:
00937                         break;
00938                 default:
00939                         fprintf(stderr, "RNA_def_property: \"%s.%s\", invalid property type.\n", CONTAINER_RNA_ID(cont), identifier);
00940                         DefRNA.error= 1;
00941                         return NULL;
00942         }
00943 
00944         if(DefRNA.preprocess) {
00945                 dprop->cont= cont;
00946                 dprop->prop= prop;
00947         }
00948 
00949         prop->magic= RNA_MAGIC;
00950         prop->identifier= identifier;
00951         prop->type= type;
00952         prop->subtype= subtype;
00953         prop->name= identifier;
00954         prop->description= "";
00955         /* a priori not raw editable */
00956         prop->rawtype = -1;
00957 
00958         if(type != PROP_COLLECTION && type != PROP_POINTER) {
00959                 prop->flag= PROP_EDITABLE;
00960         
00961                 if(type != PROP_STRING)
00962                         prop->flag |= PROP_ANIMATABLE;
00963         }
00964 
00965         if(DefRNA.preprocess) {
00966                 switch(type) {
00967                         case PROP_BOOLEAN:
00968                                 DefRNA.silent= 1;
00969                                 RNA_def_property_boolean_sdna(prop, NULL, identifier, 0);
00970                                 DefRNA.silent= 0;
00971                                 break;
00972                         case PROP_INT: {
00973                                 DefRNA.silent= 1;
00974                                 RNA_def_property_int_sdna(prop, NULL, identifier);
00975                                 DefRNA.silent= 0;
00976                                 break;
00977                         }
00978                         case PROP_FLOAT: {
00979                                 DefRNA.silent= 1;
00980                                 RNA_def_property_float_sdna(prop, NULL, identifier);
00981                                 DefRNA.silent= 0;
00982                                 break;
00983                         }
00984                         case PROP_STRING: {
00985                                 DefRNA.silent= 1;
00986                                 RNA_def_property_string_sdna(prop, NULL, identifier);
00987                                 DefRNA.silent= 0;
00988                                 break;
00989                         }
00990                         case PROP_ENUM:
00991                                 DefRNA.silent= 1;
00992                                 RNA_def_property_enum_sdna(prop, NULL, identifier);
00993                                 DefRNA.silent= 0;
00994                                 break;
00995                         case PROP_POINTER:
00996                                 DefRNA.silent= 1;
00997                                 RNA_def_property_pointer_sdna(prop, NULL, identifier);
00998                                 DefRNA.silent= 0;
00999                                 break;
01000                         case PROP_COLLECTION:
01001                                 DefRNA.silent= 1;
01002                                 RNA_def_property_collection_sdna(prop, NULL, identifier, NULL);
01003                                 DefRNA.silent= 0;
01004                                 break;
01005                 }
01006         }
01007         else {
01008                 prop->flag |= PROP_IDPROPERTY|PROP_RUNTIME;
01009 #ifdef RNA_RUNTIME
01010                 if(cont->prophash)
01011                         BLI_ghash_insert(cont->prophash, (void*)prop->identifier, prop);
01012 #endif
01013         }
01014 
01015         rna_addtail(&cont->properties, prop);
01016 
01017         return prop;
01018 }
01019 
01020 void RNA_def_property_flag(PropertyRNA *prop, int flag)
01021 {
01022         prop->flag |= flag;
01023 }
01024 
01025 void RNA_def_property_clear_flag(PropertyRNA *prop, int flag)
01026 {
01027         prop->flag &= ~flag;
01028 }
01029 
01030 void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
01031 {
01032         prop->subtype= subtype;
01033 }
01034 
01035 void RNA_def_property_array(PropertyRNA *prop, int length)
01036 {
01037         StructRNA *srna= DefRNA.laststruct;
01038 
01039         if(length<0) {
01040                 fprintf(stderr, "RNA_def_property_array: \"%s.%s\", array length must be zero of greater.\n", srna->identifier, prop->identifier);
01041                 DefRNA.error= 1;
01042                 return;
01043         }
01044 
01045         if(length>RNA_MAX_ARRAY_LENGTH) {
01046                 fprintf(stderr, "RNA_def_property_array: \"%s.%s\", array length must be smaller than %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY_LENGTH);
01047                 DefRNA.error= 1;
01048                 return;
01049         }
01050 
01051         if(prop->arraydimension > 1) {
01052                 fprintf(stderr, "RNA_def_property_array: \"%s.%s\", array dimensions has been set to %d but would be overwritten as 1.\n", srna->identifier, prop->identifier, prop->arraydimension);
01053                 DefRNA.error= 1;
01054                 return;
01055         }
01056 
01057         switch(prop->type) {
01058                 case PROP_BOOLEAN:
01059                 case PROP_INT:
01060                 case PROP_FLOAT:
01061                         prop->arraylength[0]= length;
01062                         prop->totarraylength= length;
01063                         prop->arraydimension= 1;
01064                         break;
01065                 default:
01066                         fprintf(stderr, "RNA_def_property_array: \"%s.%s\", only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
01067                         DefRNA.error= 1;
01068                         break;
01069         }
01070 }
01071 
01072 void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
01073 {
01074         StructRNA *srna= DefRNA.laststruct;
01075         int i;
01076         
01077         if (dimension < 1 || dimension > RNA_MAX_ARRAY_DIMENSION) {
01078                 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);
01079                 DefRNA.error= 1;
01080                 return;
01081         }
01082 
01083         switch(prop->type) {
01084                 case PROP_BOOLEAN:
01085                 case PROP_INT:
01086                 case PROP_FLOAT:
01087                         break;
01088                 default:
01089                         fprintf(stderr, "RNA_def_property_multi_array: \"%s.%s\", only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
01090                         DefRNA.error= 1;
01091                         break;
01092         }
01093 
01094         prop->arraydimension= dimension;
01095         prop->totarraylength= 0;
01096 
01097         if(length) {
01098                 memcpy(prop->arraylength, length, sizeof(int)*dimension);
01099 
01100                 prop->totarraylength= length[0];
01101                 for(i=1; i<dimension; i++)
01102                         prop->totarraylength *= length[i];
01103         }
01104         else
01105                 memset(prop->arraylength, 0, sizeof(prop->arraylength));
01106 
01107         /* TODO make sure arraylength values are sane  */
01108 }
01109 
01110 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
01111 {
01112         prop->name= name;
01113         prop->description= description;
01114 }
01115 
01116 void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
01117 {
01118         prop->icon= icon;
01119         if(consecutive)
01120                 prop->flag |= PROP_ICONS_CONSECUTIVE;
01121 }
01122 
01123 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
01124 {
01125         StructRNA *srna= DefRNA.laststruct;
01126 
01127         switch(prop->type) {
01128                 case PROP_INT: {
01129                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
01130                         iprop->softmin= (int)min;
01131                         iprop->softmax= (int)max;
01132                         iprop->step= (int)step;
01133                         break;
01134                 }
01135                 case PROP_FLOAT: {
01136                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
01137                         fprop->softmin= (float)min;
01138                         fprop->softmax= (float)max;
01139                         fprop->step= (float)step;
01140                         fprop->precision= (int)precision;
01141                         break;
01142                 }
01143                 default:
01144                         fprintf(stderr, "RNA_def_property_ui_range: \"%s.%s\", invalid type for ui range.\n", srna->identifier, prop->identifier);
01145                         DefRNA.error= 1;
01146                         break;
01147         }
01148 }
01149 
01150 void RNA_def_property_range(PropertyRNA *prop, double min, double max)
01151 {
01152         StructRNA *srna= DefRNA.laststruct;
01153 
01154         switch(prop->type) {
01155                 case PROP_INT: {
01156                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
01157                         iprop->hardmin= (int)min;
01158                         iprop->hardmax= (int)max;
01159                         iprop->softmin= MAX2((int)min, iprop->hardmin);
01160                         iprop->softmax= MIN2((int)max, iprop->hardmax);
01161                         break;
01162                 }
01163                 case PROP_FLOAT: {
01164                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
01165                         fprop->hardmin= (float)min;
01166                         fprop->hardmax= (float)max;
01167                         fprop->softmin= MAX2((float)min, fprop->hardmin);
01168                         fprop->softmax= MIN2((float)max, fprop->hardmax);
01169                         break;
01170                 }
01171                 default:
01172                         fprintf(stderr, "RNA_def_property_range: \"%s.%s\", invalid type for range.\n", srna->identifier, prop->identifier);
01173                         DefRNA.error= 1;
01174                         break;
01175         }
01176 }
01177 
01178 void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
01179 {
01180         StructRNA *srna= DefRNA.laststruct;
01181 
01182         if(!DefRNA.preprocess) {
01183                 fprintf(stderr, "RNA_def_property_struct_type \"%s.%s\": only during preprocessing.\n", srna->identifier, prop->identifier);
01184                 return;
01185         }
01186 
01187         switch(prop->type) {
01188                 case PROP_POINTER: {
01189                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
01190                         pprop->type = (StructRNA*)type;
01191                         break;
01192                 }
01193                 case PROP_COLLECTION: {
01194                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
01195                         cprop->item_type = (StructRNA*)type;
01196                         break;
01197                 }
01198                 default:
01199                         fprintf(stderr, "RNA_def_property_struct_type: \"%s.%s\", invalid type for struct type.\n", srna->identifier, prop->identifier);
01200                         DefRNA.error= 1;
01201                         break;
01202         }
01203 }
01204 
01205 void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type)
01206 {
01207         StructRNA *srna= DefRNA.laststruct;
01208 
01209         if(DefRNA.preprocess) {
01210                 fprintf(stderr, "RNA_def_property_struct_runtime: only at runtime.\n");
01211                 return;
01212         }
01213 
01214         switch(prop->type) {
01215                 case PROP_POINTER: {
01216                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
01217                         pprop->type = type;
01218 
01219                         if(type && (type->flag & STRUCT_ID_REFCOUNT))
01220                                 prop->flag |= PROP_ID_REFCOUNT;
01221 
01222                         break;
01223                 }
01224                 case PROP_COLLECTION: {
01225                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
01226                         cprop->item_type = type;
01227                         break;
01228                 }
01229                 default:
01230                         fprintf(stderr, "RNA_def_property_struct_runtime: \"%s.%s\", invalid type for struct type.\n", srna->identifier, prop->identifier);
01231                         DefRNA.error= 1;
01232                         break;
01233         }
01234 }
01235 
01236 void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
01237 {
01238         StructRNA *srna= DefRNA.laststruct;
01239         int i, defaultfound= 0;
01240 
01241         switch(prop->type) {
01242                 case PROP_ENUM: {
01243                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
01244                         eprop->item= (EnumPropertyItem*)item;
01245                         eprop->totitem= 0;
01246                         for(i=0; item[i].identifier; i++) {
01247                                 eprop->totitem++;
01248 
01249                                 if(item[i].identifier[0] && item[i].value == eprop->defaultvalue)
01250                                         defaultfound= 1;
01251                         }
01252 
01253                         if(!defaultfound) {
01254                                 for(i=0; item[i].identifier; i++) {
01255                                         if(item[i].identifier[0]) {
01256                                                 eprop->defaultvalue= item[i].value;
01257                                                 break;
01258                                         }
01259                                 }
01260                         }
01261 
01262                         break;
01263                 }
01264                 default:
01265                         fprintf(stderr, "RNA_def_property_enum_items: \"%s.%s\", invalid type for struct type.\n", srna->identifier, prop->identifier);
01266                         DefRNA.error= 1;
01267                         break;
01268         }
01269 }
01270 
01271 void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
01272 {
01273         StructRNA *srna= DefRNA.laststruct;
01274 
01275         switch(prop->type) {
01276                 case PROP_STRING: {
01277                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
01278                         sprop->maxlength= maxlength;
01279                         break;
01280                 }
01281                 default:
01282                         fprintf(stderr, "RNA_def_property_string_maxlength: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
01283                         DefRNA.error= 1;
01284                         break;
01285         }
01286 }
01287 
01288 void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
01289 {
01290         StructRNA *srna= DefRNA.laststruct;
01291 
01292         switch(prop->type) {
01293                 case PROP_BOOLEAN: {
01294                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
01295                         bprop->defaultvalue= value;
01296                         break;
01297                 }
01298                 default:
01299                         fprintf(stderr, "RNA_def_property_boolean_default: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
01300                         DefRNA.error= 1;
01301                         break;
01302         }
01303 }
01304 
01305 void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
01306 {
01307         StructRNA *srna= DefRNA.laststruct;
01308 
01309         switch(prop->type) {
01310                 case PROP_BOOLEAN: {
01311                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
01312                         bprop->defaultarray= array;
01313                         break;
01314                 }
01315                 default:
01316                         fprintf(stderr, "RNA_def_property_boolean_default: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
01317                         DefRNA.error= 1;
01318                         break;
01319         }
01320 }
01321 
01322 void RNA_def_property_int_default(PropertyRNA *prop, int value)
01323 {
01324         StructRNA *srna= DefRNA.laststruct;
01325 
01326         switch(prop->type) {
01327                 case PROP_INT: {
01328                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
01329                         iprop->defaultvalue= value;
01330                         break;
01331                 }
01332                 default:
01333                         fprintf(stderr, "RNA_def_property_int_default: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
01334                         DefRNA.error= 1;
01335                         break;
01336         }
01337 }
01338 
01339 void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
01340 {
01341         StructRNA *srna= DefRNA.laststruct;
01342 
01343         switch(prop->type) {
01344                 case PROP_INT: {
01345                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
01346                         iprop->defaultarray= array;
01347                         break;
01348                 }
01349                 default:
01350                         fprintf(stderr, "RNA_def_property_int_default: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
01351                         DefRNA.error= 1;
01352                         break;
01353         }
01354 }
01355 
01356 void RNA_def_property_float_default(PropertyRNA *prop, float value)
01357 {
01358         StructRNA *srna= DefRNA.laststruct;
01359 
01360         switch(prop->type) {
01361                 case PROP_FLOAT: {
01362                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
01363                         fprop->defaultvalue= value;
01364                         break;
01365                 }
01366                 default:
01367                         fprintf(stderr, "RNA_def_property_float_default: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
01368                         DefRNA.error= 1;
01369                         break;
01370         }
01371 }
01372 /* array must remain valid after this function finishes */
01373 void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
01374 {
01375         StructRNA *srna= DefRNA.laststruct;
01376 
01377         switch(prop->type) {
01378                 case PROP_FLOAT: {
01379                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
01380                         fprop->defaultarray= array; /* WARNING, this array must not come from the stack and lost */
01381                         break;
01382                 }
01383                 default:
01384                         fprintf(stderr, "RNA_def_property_float_default: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
01385                         DefRNA.error= 1;
01386                         break;
01387         }
01388 }
01389 
01390 void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
01391 {
01392         StructRNA *srna= DefRNA.laststruct;
01393 
01394         switch(prop->type) {
01395                 case PROP_STRING: {
01396                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
01397                         sprop->defaultvalue= value;
01398                         break;
01399                 }
01400                 default:
01401                         fprintf(stderr, "RNA_def_property_string_default: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
01402                         DefRNA.error= 1;
01403                         break;
01404         }
01405 }
01406 
01407 void RNA_def_property_enum_default(PropertyRNA *prop, int value)
01408 {
01409         StructRNA *srna= DefRNA.laststruct;
01410         int i, defaultfound= 0;
01411 
01412         switch(prop->type) {
01413                 case PROP_ENUM: {
01414                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
01415                         eprop->defaultvalue= value;
01416 
01417                         if(prop->flag & PROP_ENUM_FLAG) {
01418                                 /* check all bits are accounted for */
01419                                 int totflag= 0;
01420                                 for(i=0; i<eprop->totitem; i++) {
01421                                         if(eprop->item[i].identifier[0]) {
01422                                                 totflag |= eprop->item[i].value;
01423                                         }
01424                                 }
01425 
01426                                 if(eprop->defaultvalue & ~totflag) {
01427                                         fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default includes unused bits (%d).\n", srna->identifier, prop->identifier, eprop->defaultvalue & ~totflag);
01428                                         DefRNA.error= 1;
01429                                 }
01430                         }
01431                         else {
01432                                 for(i=0; i<eprop->totitem; i++) {
01433                                         if(eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue)
01434                                                 defaultfound= 1;
01435                                 }
01436 
01437                                 if(!defaultfound && eprop->totitem) {
01438                                         if(value == 0) {
01439                                                 eprop->defaultvalue= eprop->item[0].value;
01440                                         }
01441                                         else {
01442                                                 fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default is not in items.\n", srna->identifier, prop->identifier);
01443                                                 DefRNA.error= 1;
01444                                         }
01445                                 }
01446                         }
01447 
01448                         break;
01449                 }
01450                 default:
01451                         fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", type is not enum.\n", srna->identifier, prop->identifier);
01452                         DefRNA.error= 1;
01453                         break;
01454         }
01455 }
01456 
01457 /* SDNA */
01458 
01459 static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *structname, const char *propname)
01460 {
01461         DNAStructMember smember;
01462         StructDefRNA *ds;
01463         PropertyDefRNA *dp;
01464 
01465         dp= rna_find_struct_property_def(DefRNA.laststruct, prop);
01466         if (dp==NULL) return NULL;
01467 
01468         ds= rna_find_struct_def((StructRNA*)dp->cont);
01469 
01470         if(!structname)
01471                 structname= ds->dnaname;
01472         if(!propname)
01473                 propname= prop->identifier;
01474 
01475         if(!rna_find_sdna_member(DefRNA.sdna, structname, propname, &smember)) {
01476                 if(DefRNA.silent) {
01477                         return NULL;
01478                 }
01479                 else if(!DefRNA.verify) {
01480                         /* some basic values to survive even with sdna info */
01481                         dp->dnastructname= structname;
01482                         dp->dnaname= propname;
01483                         if(prop->type == PROP_BOOLEAN)
01484                                 dp->dnaarraylength= 1;
01485                         if(prop->type == PROP_POINTER)
01486                                 dp->dnapointerlevel= 1;
01487                         return dp;
01488                 }
01489                 else {
01490                         fprintf(stderr, "rna_def_property_sdna: \"%s.%s\" not found.\n", structname, propname);
01491                         DefRNA.error= 1;
01492                         return NULL;
01493                 }
01494         }
01495 
01496         if(smember.arraylength > 1) {
01497                 prop->arraylength[0]= smember.arraylength;
01498                 prop->totarraylength= smember.arraylength;
01499                 prop->arraydimension= 1;
01500         }
01501         else {
01502                 prop->arraydimension= 0;
01503                 prop->totarraylength= 0;
01504         }
01505         
01506         dp->dnastructname= structname;
01507         dp->dnastructfromname= ds->dnafromname;
01508         dp->dnastructfromprop= ds->dnafromprop;
01509         dp->dnaname= propname;
01510         dp->dnatype= smember.type;
01511         dp->dnaarraylength= smember.arraylength;
01512         dp->dnapointerlevel= smember.pointerlevel;
01513 
01514         return dp;
01515 }
01516 
01517 void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int bit)
01518 {
01519         PropertyDefRNA *dp;
01520         StructRNA *srna= DefRNA.laststruct;
01521         
01522         if(!DefRNA.preprocess) {
01523                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
01524                 return;
01525         }
01526 
01527         if(prop->type != PROP_BOOLEAN) {
01528                 fprintf(stderr, "RNA_def_property_boolean_sdna: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
01529                 DefRNA.error= 1;
01530                 return;
01531         }
01532 
01533         if((dp=rna_def_property_sdna(prop, structname, propname))) {
01534 
01535                 if(DefRNA.silent == 0) {
01536                         /* error check to ensure floats are not wrapped as ints/bools */
01537                         if(dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
01538                                 fprintf(stderr, "RNA_def_property_boolean_sdna: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type));
01539                                 DefRNA.error= 1;
01540                                 return;
01541                         }
01542                 }
01543 
01544                 dp->booleanbit= bit;
01545         }
01546 }
01547 
01548 void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int booleanbit)
01549 {
01550         PropertyDefRNA *dp;
01551 
01552         RNA_def_property_boolean_sdna(prop, structname, propname, booleanbit);
01553 
01554         dp= rna_find_struct_property_def(DefRNA.laststruct, prop);
01555 
01556         if(dp)
01557                 dp->booleannegative= 1;
01558 }
01559 
01560 void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
01561 {
01562         PropertyDefRNA *dp;
01563         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
01564         StructRNA *srna= DefRNA.laststruct;
01565         
01566         if(!DefRNA.preprocess) {
01567                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
01568                 return;
01569         }
01570 
01571         if(prop->type != PROP_INT) {
01572                 fprintf(stderr, "RNA_def_property_int_sdna: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
01573                 DefRNA.error= 1;
01574                 return;
01575         }
01576 
01577         if((dp= rna_def_property_sdna(prop, structname, propname))) {
01578 
01579                 /* error check to ensure floats are not wrapped as ints/bools */
01580                 if(DefRNA.silent == 0) {
01581                         if(dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
01582                                 fprintf(stderr, "RNA_def_property_int_sdna: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type));
01583                                 DefRNA.error= 1;
01584                                 return;
01585                         }
01586                 }
01587 
01588                 /* SDNA doesn't pass us unsigned unfortunately .. */
01589                 if(dp->dnatype && strcmp(dp->dnatype, "char") == 0) {
01590                         iprop->hardmin= iprop->softmin= CHAR_MIN;
01591                         iprop->hardmax= iprop->softmax= CHAR_MAX;
01592                 }
01593                 else if(dp->dnatype && strcmp(dp->dnatype, "short") == 0) {
01594                         iprop->hardmin= iprop->softmin= SHRT_MIN;
01595                         iprop->hardmax= iprop->softmax= SHRT_MAX;
01596                 }
01597                 else if(dp->dnatype && strcmp(dp->dnatype, "int") == 0) {
01598                         iprop->hardmin= INT_MIN;
01599                         iprop->hardmax= INT_MAX;
01600 
01601                         iprop->softmin= -10000; /* rather arbitrary .. */
01602                         iprop->softmax= 10000;
01603                 }
01604 
01605                 if(prop->subtype == PROP_UNSIGNED || prop->subtype == PROP_PERCENTAGE || prop->subtype == PROP_FACTOR)
01606                         iprop->hardmin= iprop->softmin= 0;
01607         }
01608 }
01609 
01610 void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
01611 {
01612         PropertyDefRNA *dp;
01613         StructRNA *srna= DefRNA.laststruct;
01614 
01615         if(!DefRNA.preprocess) {
01616                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
01617                 return;
01618         }
01619 
01620         if(prop->type != PROP_FLOAT) {
01621                 fprintf(stderr, "RNA_def_property_float_sdna: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
01622                 DefRNA.error= 1;
01623                 return;
01624         }
01625 
01626         if((dp= rna_def_property_sdna(prop, structname, propname))) {
01627                 /* silent is for internal use */
01628                 if(DefRNA.silent == 0) {
01629                         if(dp->dnatype && *dp->dnatype && IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
01630                                 if(prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */
01631                                         fprintf(stderr, "RNA_def_property_float_sdna: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type));
01632                                         DefRNA.error= 1;
01633                                         return;
01634                                 }
01635                         }
01636                 }
01637         }
01638 
01639         rna_def_property_sdna(prop, structname, propname);
01640 }
01641 
01642 void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
01643 {
01644         /* PropertyDefRNA *dp; */
01645         StructRNA *srna= DefRNA.laststruct;
01646         
01647         if(!DefRNA.preprocess) {
01648                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
01649                 return;
01650         }
01651 
01652         if(prop->type != PROP_ENUM) {
01653                 fprintf(stderr, "RNA_def_property_enum_sdna: \"%s.%s\", type is not enum.\n", srna->identifier, prop->identifier);
01654                 DefRNA.error= 1;
01655                 return;
01656         }
01657 
01658         if(( /* dp= */ rna_def_property_sdna(prop, structname, propname))) {
01659                 if(prop->arraydimension) {
01660                         prop->arraydimension= 0;
01661                         prop->totarraylength= 0;
01662 
01663                         if(!DefRNA.silent) {
01664                                 fprintf(stderr, "RNA_def_property_enum_sdna: \"%s.%s\", array not supported for enum type.\n", structname, propname);
01665                                 DefRNA.error= 1;
01666                         }
01667                 }
01668         }
01669 }
01670 
01671 void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
01672 {
01673         PropertyDefRNA *dp;
01674 
01675         RNA_def_property_enum_sdna(prop, structname, propname);
01676 
01677         dp= rna_find_struct_property_def(DefRNA.laststruct, prop);
01678 
01679         if(dp)
01680                 dp->enumbitflags= 1;
01681 }
01682 
01683 void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
01684 {
01685         /* PropertyDefRNA *dp; */
01686         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
01687         StructRNA *srna= DefRNA.laststruct;
01688 
01689         if(!DefRNA.preprocess) {
01690                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
01691                 return;
01692         }
01693 
01694         if(prop->type != PROP_STRING) {
01695                 fprintf(stderr, "RNA_def_property_string_sdna: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
01696                 DefRNA.error= 1;
01697                 return;
01698         }
01699 
01700         if((/* dp= */ rna_def_property_sdna(prop, structname, propname))) {
01701                 if(prop->arraydimension) {
01702                         sprop->maxlength= prop->totarraylength;
01703                         prop->arraydimension= 0;
01704                         prop->totarraylength= 0;
01705                 }
01706         }
01707 }
01708 
01709 void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
01710 {
01711         /* PropertyDefRNA *dp; */
01712         StructRNA *srna= DefRNA.laststruct;
01713         
01714         if(!DefRNA.preprocess) {
01715                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
01716                 return;
01717         }
01718 
01719         if(prop->type != PROP_POINTER) {
01720                 fprintf(stderr, "RNA_def_property_pointer_sdna: \"%s.%s\", type is not pointer.\n", srna->identifier, prop->identifier);
01721                 DefRNA.error= 1;
01722                 return;
01723         }
01724 
01725         if((/* dp= */ rna_def_property_sdna(prop, structname, propname))) {
01726                 if(prop->arraydimension) {
01727                         prop->arraydimension= 0;
01728                         prop->totarraylength= 0;
01729 
01730                         if(!DefRNA.silent) {
01731                                 fprintf(stderr, "RNA_def_property_pointer_sdna: \"%s.%s\", array not supported for pointer type.\n", structname, propname);
01732                                 DefRNA.error= 1;
01733                         }
01734                 }
01735         }
01736 }
01737 
01738 void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
01739 {
01740         PropertyDefRNA *dp;
01741         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
01742         StructRNA *srna= DefRNA.laststruct;
01743 
01744         if(!DefRNA.preprocess) {
01745                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
01746                 return;
01747         }
01748 
01749         if(prop->type != PROP_COLLECTION) {
01750                 fprintf(stderr, "RNA_def_property_collection_sdna: \"%s.%s\", type is not collection.\n", srna->identifier, prop->identifier);
01751                 DefRNA.error= 1;
01752                 return;
01753         }
01754 
01755         if((dp=rna_def_property_sdna(prop, structname, propname))) {
01756                 if(prop->arraydimension && !lengthpropname) {
01757                         prop->arraydimension= 0;
01758                         prop->totarraylength= 0;
01759 
01760                         if(!DefRNA.silent) {
01761                                 fprintf(stderr, "RNA_def_property_collection_sdna: \"%s.%s\", array of collections not supported.\n", structname, propname);
01762                                 DefRNA.error= 1;
01763                         }
01764                 }
01765 
01766                 if(dp->dnatype && strcmp(dp->dnatype, "ListBase") == 0) {
01767                         cprop->next= (PropCollectionNextFunc)"rna_iterator_listbase_next";
01768                         cprop->get= (PropCollectionGetFunc)"rna_iterator_listbase_get";
01769                         cprop->end= (PropCollectionEndFunc)"rna_iterator_listbase_end";
01770                 }
01771         }
01772 
01773         if(dp && lengthpropname) {
01774                 DNAStructMember smember;
01775                 StructDefRNA *ds= rna_find_struct_def((StructRNA*)dp->cont);
01776 
01777                 if(!structname)
01778                         structname= ds->dnaname;
01779 
01780                 if(lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
01781                         if(lengthpropname[0] == 0) {
01782                                 dp->dnalengthfixed= prop->totarraylength;
01783                                 prop->arraydimension= 0;
01784                                 prop->totarraylength= 0;
01785                         }
01786                         else {
01787                                 dp->dnalengthstructname= structname;
01788                                 dp->dnalengthname= lengthpropname;
01789                                 prop->totarraylength= 0;
01790                         }
01791 
01792                         cprop->next= (PropCollectionNextFunc)"rna_iterator_array_next";
01793                         cprop->end= (PropCollectionEndFunc)"rna_iterator_array_end";
01794 
01795                         if(dp->dnapointerlevel >= 2) 
01796                                 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_dereference_get";
01797                         else
01798                                 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
01799                 }
01800                 else {
01801                         if(!DefRNA.silent) {
01802                                 fprintf(stderr, "RNA_def_property_collection_sdna: \"%s.%s\" not found.\n", structname, lengthpropname);
01803                                 DefRNA.error= 1;
01804                         }
01805                 }
01806         }
01807 }
01808 
01809 /* Functions */
01810 
01811 void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
01812 {
01813         if(!DefRNA.preprocess) {
01814                 fprintf(stderr, "RNA_def_property_editable_func: only during preprocessing.\n");
01815                 return;
01816         }
01817 
01818         if(editable) prop->editable= (EditableFunc)editable;
01819 }
01820 
01821 void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable)
01822 {
01823         if(!DefRNA.preprocess) {
01824                 fprintf(stderr, "RNA_def_property_editable_array_func: only during preprocessing.\n");
01825                 return;
01826         }
01827 
01828         if(editable) prop->itemeditable= (ItemEditableFunc)editable;
01829 }
01830 
01831 void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
01832 {
01833         if(!DefRNA.preprocess) {
01834                 fprintf(stderr, "RNA_def_property_update: only during preprocessing.\n");
01835                 return;
01836         }
01837 
01838         prop->noteflag= noteflag;
01839         prop->update= (UpdateFunc)func;
01840 }
01841 
01842 void RNA_def_property_update_runtime(PropertyRNA *prop, void *func)
01843 {
01844         prop->update= func;
01845 }
01846 
01847 void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
01848 {
01849         if(!DefRNA.preprocess) {
01850                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
01851                 return;
01852         }
01853 
01854         if (!(prop->flag & PROP_DYNAMIC)) {
01855                 fprintf(stderr, "RNA_def_property_dynamic_array_funcs: property is a not dynamic array.\n");
01856                 DefRNA.error= 1;
01857                 return;
01858         }
01859 
01860         if(getlength) prop->getlength= (PropArrayLengthGetFunc)getlength;
01861 }
01862 
01863 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
01864 {
01865         StructRNA *srna= DefRNA.laststruct;
01866 
01867         if(!DefRNA.preprocess) {
01868                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
01869                 return;
01870         }
01871 
01872         switch(prop->type) {
01873                 case PROP_BOOLEAN: {
01874                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
01875 
01876                         if(prop->arraydimension) {
01877                                 if(get) bprop->getarray= (PropBooleanArrayGetFunc)get;
01878                                 if(set) bprop->setarray= (PropBooleanArraySetFunc)set;
01879                         }
01880                         else {
01881                                 if(get) bprop->get= (PropBooleanGetFunc)get;
01882                                 if(set) bprop->set= (PropBooleanSetFunc)set;
01883                         }
01884                         break;
01885                 }
01886                 default:
01887                         fprintf(stderr, "RNA_def_property_boolean_funcs: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
01888                         DefRNA.error= 1;
01889                         break;
01890         }
01891 }
01892 
01893 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
01894 {
01895         StructRNA *srna= DefRNA.laststruct;
01896 
01897         if(!DefRNA.preprocess) {
01898                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
01899                 return;
01900         }
01901 
01902         switch(prop->type) {
01903                 case PROP_INT: {
01904                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
01905 
01906                         if(prop->arraydimension) {
01907                                 if(get) iprop->getarray= (PropIntArrayGetFunc)get;
01908                                 if(set) iprop->setarray= (PropIntArraySetFunc)set;
01909                         }
01910                         else {
01911                                 if(get) iprop->get= (PropIntGetFunc)get;
01912                                 if(set) iprop->set= (PropIntSetFunc)set;
01913                         }
01914                         if(range) iprop->range= (PropIntRangeFunc)range;
01915                         break;
01916                 }
01917                 default:
01918                         fprintf(stderr, "RNA_def_property_int_funcs: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
01919                         DefRNA.error= 1;
01920                         break;
01921         }
01922 }
01923 
01924 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
01925 {
01926         StructRNA *srna= DefRNA.laststruct;
01927 
01928         if(!DefRNA.preprocess) {
01929                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
01930                 return;
01931         }
01932 
01933         switch(prop->type) {
01934                 case PROP_FLOAT: {
01935                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
01936 
01937                         if(prop->arraydimension) {
01938                                 if(get) fprop->getarray= (PropFloatArrayGetFunc)get;
01939                                 if(set) fprop->setarray= (PropFloatArraySetFunc)set;
01940                         }
01941                         else {
01942                                 if(get) fprop->get= (PropFloatGetFunc)get;
01943                                 if(set) fprop->set= (PropFloatSetFunc)set;
01944                         }
01945                         if(range) fprop->range= (PropFloatRangeFunc)range;
01946                         break;
01947                 }
01948                 default:
01949                         fprintf(stderr, "RNA_def_property_float_funcs: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
01950                         DefRNA.error= 1;
01951                         break;
01952         }
01953 }
01954 
01955 void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
01956 {
01957         StructRNA *srna= DefRNA.laststruct;
01958 
01959         if(!DefRNA.preprocess) {
01960                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
01961                 return;
01962         }
01963 
01964         switch(prop->type) {
01965                 case PROP_ENUM: {
01966                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
01967 
01968                         if(get) eprop->get= (PropEnumGetFunc)get;
01969                         if(set) eprop->set= (PropEnumSetFunc)set;
01970                         if(item) eprop->itemf= (PropEnumItemFunc)item;
01971                         break;
01972                 }
01973                 default:
01974                         fprintf(stderr, "RNA_def_property_enum_funcs: \"%s.%s\", type is not enum.\n", srna->identifier, prop->identifier);
01975                         DefRNA.error= 1;
01976                         break;
01977         }
01978 }
01979 
01980 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
01981 {
01982         StructRNA *srna= DefRNA.laststruct;
01983 
01984         if(!DefRNA.preprocess) {
01985                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
01986                 return;
01987         }
01988 
01989         switch(prop->type) {
01990                 case PROP_STRING: {
01991                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
01992 
01993                         if(get) sprop->get= (PropStringGetFunc)get;
01994                         if(length) sprop->length= (PropStringLengthFunc)length;
01995                         if(set) sprop->set= (PropStringSetFunc)set;
01996                         break;
01997                 }
01998                 default:
01999                         fprintf(stderr, "RNA_def_property_string_funcs: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
02000                         DefRNA.error= 1;
02001                         break;
02002         }
02003 }
02004 
02005 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *typef, const char *poll)
02006 {
02007         StructRNA *srna= DefRNA.laststruct;
02008 
02009         if(!DefRNA.preprocess) {
02010                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
02011                 return;
02012         }
02013 
02014         switch(prop->type) {
02015                 case PROP_POINTER: {
02016                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
02017 
02018                         if(get) pprop->get= (PropPointerGetFunc)get;
02019                         if(set) pprop->set= (PropPointerSetFunc)set;
02020                         if(typef) pprop->typef= (PropPointerTypeFunc)typef;
02021                         if(poll) pprop->poll= (PropPointerPollFunc)poll;
02022                         break;
02023                 }
02024                 default:
02025                         fprintf(stderr, "RNA_def_property_pointer_funcs: \"%s.%s\", type is not pointer.\n", srna->identifier, prop->identifier);
02026                         DefRNA.error= 1;
02027                         break;
02028         }
02029 }
02030 
02031 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring)
02032 {
02033         StructRNA *srna= DefRNA.laststruct;
02034 
02035         if(!DefRNA.preprocess) {
02036                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
02037                 return;
02038         }
02039 
02040         switch(prop->type) {
02041                 case PROP_COLLECTION: {
02042                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
02043 
02044                         if(begin) cprop->begin= (PropCollectionBeginFunc)begin;
02045                         if(next) cprop->next= (PropCollectionNextFunc)next;
02046                         if(end) cprop->end= (PropCollectionEndFunc)end;
02047                         if(get) cprop->get= (PropCollectionGetFunc)get;
02048                         if(length) cprop->length= (PropCollectionLengthFunc)length;
02049                         if(lookupint) cprop->lookupint= (PropCollectionLookupIntFunc)lookupint;
02050                         if(lookupstring) cprop->lookupstring= (PropCollectionLookupStringFunc)lookupstring;
02051                         break;
02052                 }
02053                 default:
02054                         fprintf(stderr, "RNA_def_property_collection_funcs: \"%s.%s\", type is not collection.\n", srna->identifier, prop->identifier);
02055                         DefRNA.error= 1;
02056                         break;
02057         }
02058 }
02059 
02060 void RNA_def_property_srna(PropertyRNA *prop, const char *type)
02061 {
02062         prop->srna= (StructRNA*)type;
02063 }
02064 
02065 void RNA_def_py_data(PropertyRNA *prop, void *py_data)
02066 {
02067         prop->py_data= py_data;
02068 }
02069 
02070 /* Compact definitions */
02071 
02072 PropertyRNA *RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, int default_value, const char *ui_name, const char *ui_description)
02073 {
02074         ContainerRNA *cont= cont_;
02075         PropertyRNA *prop;
02076         
02077         prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
02078         RNA_def_property_boolean_default(prop, default_value);
02079         RNA_def_property_ui_text(prop, ui_name, ui_description);
02080 
02081         return prop;
02082 }
02083 
02084 PropertyRNA *RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value, 
02085         const char *ui_name, const char *ui_description)
02086 {
02087         ContainerRNA *cont= cont_;
02088         PropertyRNA *prop;
02089         
02090         prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
02091         if(len != 0) RNA_def_property_array(prop, len);
02092         if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
02093         RNA_def_property_ui_text(prop, ui_name, ui_description);
02094 
02095         return prop;
02096 }
02097 
02098 PropertyRNA *RNA_def_boolean_layer(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value, 
02099         const char *ui_name, const char *ui_description)
02100 {
02101         ContainerRNA *cont= cont_;
02102         PropertyRNA *prop;
02103         
02104         prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER);
02105         if(len != 0) RNA_def_property_array(prop, len);
02106         if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
02107         RNA_def_property_ui_text(prop, ui_name, ui_description);
02108 
02109         return prop;
02110 }
02111 
02112 PropertyRNA *RNA_def_boolean_layer_member(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value, 
02113         const char *ui_name, const char *ui_description)
02114 {
02115         ContainerRNA *cont= cont_;
02116         PropertyRNA *prop;
02117         
02118         prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER_MEMBER);
02119         if(len != 0) RNA_def_property_array(prop, len);
02120         if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
02121         RNA_def_property_ui_text(prop, ui_name, ui_description);
02122 
02123         return prop;
02124 }
02125 
02126 PropertyRNA *RNA_def_boolean_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value, 
02127         const char *ui_name, const char *ui_description)
02128 {
02129         ContainerRNA *cont= cont_;
02130         PropertyRNA *prop;
02131         
02132         prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_XYZ); // XXX
02133         if(len != 0) RNA_def_property_array(prop, len);
02134         if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
02135         RNA_def_property_ui_text(prop, ui_name, ui_description);
02136 
02137         return prop;
02138 }
02139 
02140 PropertyRNA *RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax, 
02141         const char *ui_name, const char *ui_description, int softmin, int softmax)
02142 {
02143         ContainerRNA *cont= cont_;
02144         PropertyRNA *prop;
02145         
02146         prop= RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
02147         RNA_def_property_int_default(prop, default_value);
02148         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02149         RNA_def_property_ui_text(prop, ui_name, ui_description);
02150         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02151 
02152         return prop;
02153 }
02154 
02155 PropertyRNA *RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, 
02156         int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
02157 {
02158         ContainerRNA *cont= cont_;
02159         PropertyRNA *prop;
02160         
02161         prop= RNA_def_property(cont, identifier, PROP_INT, PROP_XYZ); // XXX
02162         if(len != 0) RNA_def_property_array(prop, len);
02163         if(default_value) RNA_def_property_int_array_default(prop, default_value);
02164         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02165         RNA_def_property_ui_text(prop, ui_name, ui_description);
02166         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02167 
02168         return prop;
02169 }
02170 
02171 PropertyRNA *RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value, 
02172         int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
02173 {
02174         ContainerRNA *cont= cont_;
02175         PropertyRNA *prop;
02176         
02177         prop= RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
02178         if(len != 0) RNA_def_property_array(prop, len);
02179         if(default_value) RNA_def_property_int_array_default(prop, default_value);
02180         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02181         RNA_def_property_ui_text(prop, ui_name, ui_description);
02182         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02183 
02184         return prop;
02185 }
02186 
02187 PropertyRNA *RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, 
02188         const char *ui_name, const char *ui_description)
02189 {
02190         ContainerRNA *cont= cont_;
02191         PropertyRNA *prop;
02192         
02193         prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_NONE);
02194         if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
02195         if(default_value) RNA_def_property_string_default(prop, default_value);
02196         RNA_def_property_ui_text(prop, ui_name, ui_description);
02197 
02198         return prop;
02199 }
02200 
02201 PropertyRNA *RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, 
02202         const char *ui_name, const char *ui_description)
02203 {
02204         ContainerRNA *cont= cont_;
02205         PropertyRNA *prop;
02206         
02207         prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_FILEPATH);
02208         if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
02209         if(default_value) RNA_def_property_string_default(prop, default_value);
02210         RNA_def_property_ui_text(prop, ui_name, ui_description);
02211 
02212         return prop;
02213 }
02214 
02215 PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, 
02216         const char *ui_name, const char *ui_description)
02217 {
02218         ContainerRNA *cont= cont_;
02219         PropertyRNA *prop;
02220         
02221         prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_DIRPATH);
02222         if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
02223         if(default_value) RNA_def_property_string_default(prop, default_value);
02224         RNA_def_property_ui_text(prop, ui_name, ui_description);
02225 
02226         return prop;
02227 }
02228 
02229 PropertyRNA *RNA_def_string_file_name(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen, 
02230         const char *ui_name, const char *ui_description)
02231 {
02232         ContainerRNA *cont= cont_;
02233         PropertyRNA *prop;
02234         
02235         prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_FILENAME);
02236         if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
02237         if(default_value) RNA_def_property_string_default(prop, default_value);
02238         RNA_def_property_ui_text(prop, ui_name, ui_description);
02239 
02240         return prop;
02241 }
02242 
02243 PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value, 
02244         const char *ui_name, const char *ui_description)
02245 {
02246         ContainerRNA *cont= cont_;
02247         PropertyRNA *prop;
02248 
02249         if(!items) {
02250                 printf("RNA_def_enum: items not allowed to be NULL.\n");
02251                 return NULL;
02252         }
02253         
02254         prop= RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
02255         if(items) RNA_def_property_enum_items(prop, items);
02256         RNA_def_property_enum_default(prop, default_value);
02257         RNA_def_property_ui_text(prop, ui_name, ui_description);
02258 
02259         return prop;
02260 }
02261 
02262 /* same as above but sets 'PROP_ENUM_FLAG' before setting the default value */
02263 PropertyRNA *RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value,
02264         const char *ui_name, const char *ui_description)
02265 {
02266         ContainerRNA *cont= cont_;
02267         PropertyRNA *prop;
02268 
02269         if(!items) {
02270                 printf("RNA_def_enum_flag: items not allowed to be NULL.\n");
02271                 return NULL;
02272         }
02273 
02274         prop= RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
02275         RNA_def_property_flag(prop, PROP_ENUM_FLAG); /* important to run before default set */
02276         if(items) RNA_def_property_enum_items(prop, items);
02277         RNA_def_property_enum_default(prop, default_value);
02278         RNA_def_property_ui_text(prop, ui_name, ui_description);
02279 
02280         return prop;
02281 }
02282 
02283 void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
02284 {
02285         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
02286         eprop->itemf= itemfunc;
02287 }
02288 
02289 void RNA_def_enum_py_data(PropertyRNA *prop, void *py_data)
02290 {
02291         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
02292         eprop->py_data= py_data;
02293 }
02294 
02295 PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value, 
02296         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02297 {
02298         ContainerRNA *cont= cont_;
02299         PropertyRNA *prop;
02300         
02301         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
02302         RNA_def_property_float_default(prop, default_value);
02303         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02304         RNA_def_property_ui_text(prop, ui_name, ui_description);
02305         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02306 
02307         return prop;
02308 }
02309 
02310 PropertyRNA *RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, 
02311         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02312 {
02313         ContainerRNA *cont= cont_;
02314         PropertyRNA *prop;
02315         
02316         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_XYZ);
02317         if(len != 0) RNA_def_property_array(prop, len);
02318         if(default_value) RNA_def_property_float_array_default(prop, default_value);
02319         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02320         RNA_def_property_ui_text(prop, ui_name, ui_description);
02321         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02322 
02323         return prop;
02324 }
02325 
02326 PropertyRNA *RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, 
02327         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02328 {
02329         PropertyRNA *prop;
02330         
02331         prop= RNA_def_float_vector(cont_, identifier, len, default_value, hardmin, hardmax, ui_name, ui_description, softmin, softmax);
02332         prop->subtype = PROP_XYZ_LENGTH;
02333 
02334         return prop;
02335 }
02336 
02337 PropertyRNA *RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, 
02338         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02339 {
02340         ContainerRNA *cont= cont_;
02341         PropertyRNA *prop;
02342         
02343         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_COLOR);
02344         if(len != 0) RNA_def_property_array(prop, len);
02345         if(default_value) RNA_def_property_float_array_default(prop, default_value);
02346         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02347         RNA_def_property_ui_text(prop, ui_name, ui_description);
02348         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02349 
02350         return prop;
02351 }
02352 
02353 
02354 PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int rows, int columns, const float *default_value, 
02355         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02356 {
02357         ContainerRNA *cont= cont_;
02358         PropertyRNA *prop;
02359         int length[2];
02360 
02361         length[0]= rows;
02362         length[1]= columns;
02363 
02364         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_MATRIX);
02365         RNA_def_property_multi_array(prop, 2, length);
02366         if(default_value) RNA_def_property_float_array_default(prop, default_value);
02367         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02368         RNA_def_property_ui_text(prop, ui_name, ui_description);
02369         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02370 
02371         return prop;
02372 }
02373 
02374 PropertyRNA *RNA_def_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
02375         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02376 {
02377         ContainerRNA *cont= cont_;
02378         PropertyRNA *prop;
02379         
02380         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_EULER); // XXX
02381         if(len != 0) RNA_def_property_array(prop, len);
02382         if(default_value) RNA_def_property_float_array_default(prop, default_value);
02383         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02384         RNA_def_property_ui_text(prop, ui_name, ui_description);
02385         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02386 
02387         return prop;
02388 }
02389 
02390 PropertyRNA *RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
02391         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02392 {
02393         ContainerRNA *cont= cont_;
02394         PropertyRNA *prop;
02395         
02396         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
02397         if(len != 0) RNA_def_property_array(prop, len);
02398         if(default_value) RNA_def_property_float_array_default(prop, default_value);
02399         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02400         RNA_def_property_ui_text(prop, ui_name, ui_description);
02401         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02402 
02403         return prop;
02404 }
02405 
02406 PropertyRNA *RNA_def_float_percentage(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
02407         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02408 {
02409         ContainerRNA *cont= cont_;
02410         PropertyRNA *prop;
02411         
02412         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_PERCENTAGE);
02413         RNA_def_property_float_default(prop, default_value);
02414         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02415         RNA_def_property_ui_text(prop, ui_name, ui_description);
02416         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02417 
02418         return prop;
02419 }
02420 
02421 PropertyRNA *RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
02422         float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
02423 {
02424         ContainerRNA *cont= cont_;
02425         PropertyRNA *prop;
02426         
02427         prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_FACTOR);
02428         RNA_def_property_float_default(prop, default_value);
02429         if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
02430         RNA_def_property_ui_text(prop, ui_name, ui_description);
02431         RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
02432 
02433         return prop;
02434 }
02435 
02436 PropertyRNA *RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
02437         const char *ui_name, const char *ui_description)
02438 {
02439         ContainerRNA *cont= cont_;
02440         PropertyRNA *prop;
02441         
02442         prop= RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
02443         RNA_def_property_struct_type(prop, type);
02444         RNA_def_property_ui_text(prop, ui_name, ui_description);
02445 
02446         return prop;
02447 }
02448 
02449 PropertyRNA *RNA_def_pointer_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
02450         const char *ui_name, const char *ui_description)
02451 {
02452         ContainerRNA *cont= cont_;
02453         PropertyRNA *prop;
02454         
02455         prop= RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
02456         RNA_def_property_struct_runtime(prop, type);
02457         RNA_def_property_ui_text(prop, ui_name, ui_description);
02458 
02459         return prop;
02460 }
02461 
02462 PropertyRNA *RNA_def_collection(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
02463         const char *ui_name, const char *ui_description)
02464 {
02465         ContainerRNA *cont= cont_;
02466         PropertyRNA *prop;
02467         
02468         prop= RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
02469         RNA_def_property_struct_type(prop, type);
02470         RNA_def_property_ui_text(prop, ui_name, ui_description);
02471 
02472         return prop;
02473 }
02474 
02475 PropertyRNA *RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
02476         const char *ui_name, const char *ui_description)
02477 {
02478         ContainerRNA *cont= cont_;
02479         PropertyRNA *prop;
02480         
02481         prop= RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
02482         RNA_def_property_struct_runtime(prop, type);
02483         RNA_def_property_ui_text(prop, ui_name, ui_description);
02484 
02485         return prop;
02486 }
02487 
02488 /* Function */
02489 
02490 static FunctionRNA *rna_def_function(StructRNA *srna, const char *identifier)
02491 {
02492         FunctionRNA *func;
02493         StructDefRNA *dsrna;
02494         FunctionDefRNA *dfunc;
02495 
02496         if(DefRNA.preprocess) {
02497                 char error[512];
02498 
02499                 if (rna_validate_identifier(identifier, error, 0) == 0) {
02500                         fprintf(stderr, "RNA_def_function: function identifier \"%s\" - %s\n", identifier, error);
02501                         DefRNA.error= 1;
02502                 }
02503         }
02504 
02505         func= MEM_callocN(sizeof(FunctionRNA), "FunctionRNA");
02506         func->identifier= identifier;
02507         func->description= identifier;
02508 
02509         rna_addtail(&srna->functions, func);
02510 
02511         if(DefRNA.preprocess) {
02512                 dsrna= rna_find_struct_def(srna);
02513                 dfunc= MEM_callocN(sizeof(FunctionDefRNA), "FunctionDefRNA");
02514                 rna_addtail(&dsrna->functions, dfunc);
02515                 dfunc->func= func;
02516         }
02517         else
02518                 func->flag|= FUNC_RUNTIME;
02519 
02520         return func;
02521 }
02522 
02523 FunctionRNA *RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
02524 {
02525         FunctionRNA *func;
02526         FunctionDefRNA *dfunc;
02527 
02528         func= rna_def_function(srna, identifier);
02529 
02530         if(!DefRNA.preprocess) {
02531                 fprintf(stderr, "RNA_def_function: only at preprocess time.\n");
02532                 return func;
02533         }
02534 
02535         dfunc= rna_find_function_def(func);
02536         dfunc->call= call;
02537 
02538         return func;
02539 }
02540 
02541 FunctionRNA *RNA_def_function_runtime(StructRNA *srna, const char *identifier, CallFunc call)
02542 {
02543         FunctionRNA *func;
02544 
02545         func= rna_def_function(srna, identifier);
02546 
02547         if(DefRNA.preprocess) {
02548                 fprintf(stderr, "RNA_def_function_call_runtime: only at runtime.\n");
02549                 return func;
02550         }
02551 
02552         func->call= call;
02553 
02554 
02555         return func;
02556 }
02557 
02558 /* C return value only!, multiple RNA returns can be done with RNA_def_function_output */
02559 void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
02560 {
02561         if (ret->flag & PROP_DYNAMIC) {
02562                 fprintf(stderr, "RNA_def_function_return: \"%s.%s\", dynamic values are not allowed as strict returns, use RNA_def_function_output instead.\n", func->identifier, ret->identifier);
02563                 return;
02564         }
02565         else if (ret->arraydimension) {
02566                 fprintf(stderr, "RNA_def_function_return: \"%s.%s\", arrays are not allowed as strict returns, use RNA_def_function_output instead.\n", func->identifier, ret->identifier);
02567                 return;
02568         }
02569 
02570         func->c_ret= ret;
02571 
02572         RNA_def_function_output(func, ret);
02573 }
02574 
02575 void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
02576 {
02577         ret->flag|= PROP_OUTPUT;
02578 }
02579 
02580 void RNA_def_function_flag(FunctionRNA *func, int flag)
02581 {
02582         func->flag|= flag;
02583 }
02584 
02585 void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
02586 {
02587         func->description= description;
02588 }
02589 
02590 int rna_parameter_size(PropertyRNA *parm)
02591 {
02592         PropertyType ptype= parm->type;
02593         int len= parm->totarraylength; /* only supports fixed length at the moment */
02594 
02595         if(len > 0) {
02596                 /* XXX in other parts is mentioned that strings can be dynamic as well */
02597                 if (parm->flag & PROP_DYNAMIC)
02598                         return sizeof(void *);
02599 
02600                 switch (ptype) {
02601                         case PROP_BOOLEAN:
02602                         case PROP_INT:
02603                                 return sizeof(int)*len;
02604                         case PROP_FLOAT:
02605                                 return sizeof(float)*len;
02606                         default:
02607                                 break;
02608                 }
02609         }
02610         else {
02611                 switch (ptype) {
02612                         case PROP_BOOLEAN:
02613                         case PROP_INT:
02614                         case PROP_ENUM:
02615                                 return sizeof(int);
02616                         case PROP_FLOAT:
02617                                 return sizeof(float);
02618                         case PROP_STRING:
02619                                 /* return  valyes dont store a pointer to the original */
02620                                 if(parm->flag & PROP_THICK_WRAP) {
02621                                         StringPropertyRNA *sparm= (StringPropertyRNA*)parm;
02622                                         return sizeof(char) * sparm->maxlength;
02623                                 } else
02624                                         return sizeof(char *);
02625                         case PROP_POINTER: {
02626 #ifdef RNA_RUNTIME
02627                                 if(parm->flag & PROP_RNAPTR)
02628                                         return sizeof(PointerRNA);
02629                                 else
02630                                         return sizeof(void *);
02631 #else
02632                                 if(parm->flag & PROP_RNAPTR)
02633                                         return sizeof(PointerRNA);
02634                                 else
02635                                         return sizeof(void *);
02636 #endif
02637                         }
02638                         case PROP_COLLECTION:
02639                                 return sizeof(ListBase);
02640                 }
02641         }
02642 
02643         return sizeof(void *);
02644 }
02645 
02646 /* this function returns the size of the memory allocated for the parameter,
02647    useful for instance for memory alignment or for storing additional information */
02648 int rna_parameter_size_alloc(PropertyRNA *parm)
02649 {
02650         int size = rna_parameter_size(parm);
02651 
02652         if (parm->flag & PROP_DYNAMIC)
02653                 size+= sizeof(((ParameterDynAlloc *)NULL)->array_tot);
02654 
02655         return size;
02656 }
02657 
02658 /* Dynamic Enums */
02659 
02660 void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item)
02661 {
02662         EnumPropertyItem *newitems;
02663         int tot= *totitem;
02664 
02665         if(tot == 0) {
02666                 *items= MEM_callocN(sizeof(EnumPropertyItem)*8, "RNA_enum_items_add");
02667         }
02668         else if(tot >= 8 && (tot&(tot-1)) == 0){
02669                 /* power of two > 8 */
02670                 newitems= MEM_callocN(sizeof(EnumPropertyItem)*tot*2, "RNA_enum_items_add");
02671                 memcpy(newitems, *items, sizeof(EnumPropertyItem)*tot);
02672                 MEM_freeN(*items);
02673                 *items= newitems;
02674         }
02675 
02676         (*items)[tot]= *item;
02677         *totitem= tot+1;
02678 }
02679 
02680 void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem)
02681 {
02682         static EnumPropertyItem sepr = {0, "", 0, NULL, NULL};
02683         RNA_enum_item_add(items, totitem, &sepr);
02684 }
02685 
02686 void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item)
02687 {
02688         for(; item->identifier; item++)
02689                 RNA_enum_item_add(items, totitem, item);
02690 }
02691 
02692 void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item, int value)
02693 {
02694         for(; item->identifier; item++) {
02695                 if(item->value == value) {
02696                         RNA_enum_item_add(items, totitem, item);
02697                         break; // break on first match - does this break anything? (is quick hack to get object->parent_type working ok for armature/lattice)
02698                 }
02699         }
02700 }
02701 
02702 void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
02703 {
02704         static EnumPropertyItem empty = {0, NULL, 0, NULL, NULL};
02705         RNA_enum_item_add(items, totitem, &empty);
02706 }
02707 
02708 /* Memory management */
02709 
02710 #ifdef RNA_RUNTIME
02711 void RNA_def_struct_duplicate_pointers(StructRNA *srna)
02712 {
02713         if(srna->identifier) srna->identifier= BLI_strdup(srna->identifier);
02714         if(srna->name) srna->name= BLI_strdup(srna->name);
02715         if(srna->description) srna->description= BLI_strdup(srna->description);
02716 
02717         srna->flag |= STRUCT_FREE_POINTERS;
02718 }
02719 
02720 void RNA_def_struct_free_pointers(StructRNA *srna)
02721 {
02722         if(srna->flag & STRUCT_FREE_POINTERS) {
02723                 if(srna->identifier) MEM_freeN((void*)srna->identifier);
02724                 if(srna->name) MEM_freeN((void*)srna->name);
02725                 if(srna->description) MEM_freeN((void*)srna->description);
02726         }
02727 }
02728 
02729 void RNA_def_func_duplicate_pointers(FunctionRNA *func)
02730 {
02731         if(func->identifier) func->identifier= BLI_strdup(func->identifier);
02732         if(func->description) func->description= BLI_strdup(func->description);
02733 
02734         func->flag |= FUNC_FREE_POINTERS;
02735 }
02736 
02737 void RNA_def_func_free_pointers(FunctionRNA *func)
02738 {
02739         if(func->flag & FUNC_FREE_POINTERS) {
02740                 if(func->identifier) MEM_freeN((void*)func->identifier);
02741                 if(func->description) MEM_freeN((void*)func->description);
02742         }
02743 }
02744 
02745 void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop)
02746 {
02747         ContainerRNA *cont= cont_;
02748         EnumPropertyItem *earray;
02749         float *farray;
02750         int *iarray;
02751         int a;
02752 
02753         /* annoying since we just added this to a hash, could make this add the correct key to the hash in the first place */
02754         if(prop->identifier) {
02755                 if(cont->prophash) {
02756                         BLI_ghash_remove(cont->prophash, (void*)prop->identifier, NULL, NULL);
02757                         prop->identifier= BLI_strdup(prop->identifier);
02758                         BLI_ghash_insert(cont->prophash, (void*)prop->identifier, prop);
02759                 }
02760                 else {
02761                         prop->identifier= BLI_strdup(prop->identifier);
02762                 }
02763         }
02764 
02765         if(prop->name) prop->name= BLI_strdup(prop->name);
02766         if(prop->description) prop->description= BLI_strdup(prop->description);
02767 
02768         switch(prop->type) {
02769                 case PROP_BOOLEAN: {
02770                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
02771 
02772                         if(bprop->defaultarray) {
02773                                 iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
02774                                 memcpy(iarray, bprop->defaultarray, sizeof(int)*prop->totarraylength);
02775                                 bprop->defaultarray= iarray;
02776                         }
02777                         break;
02778                 }
02779                 case PROP_INT: {
02780                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
02781 
02782                         if(iprop->defaultarray) {
02783                                 iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
02784                                 memcpy(iarray, iprop->defaultarray, sizeof(int)*prop->totarraylength);
02785                                 iprop->defaultarray= iarray;
02786                         }
02787                         break;
02788                 }
02789                 case PROP_ENUM: {
02790                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
02791 
02792                         if(eprop->item) {
02793                                 earray= MEM_callocN(sizeof(EnumPropertyItem)*(eprop->totitem+1), "RNA_def_property_store"),
02794                                 memcpy(earray, eprop->item, sizeof(EnumPropertyItem)*(eprop->totitem+1));
02795                                 eprop->item= earray;
02796 
02797                                 for(a=0; a<eprop->totitem; a++) {
02798                                         if(eprop->item[a].identifier) eprop->item[a].identifier= BLI_strdup(eprop->item[a].identifier);
02799                                         if(eprop->item[a].name) eprop->item[a].name= BLI_strdup(eprop->item[a].name);
02800                                         if(eprop->item[a].description) eprop->item[a].description= BLI_strdup(eprop->item[a].description);
02801                                 }
02802                         }
02803                         break;
02804                 }
02805                 case PROP_FLOAT: {
02806                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
02807 
02808                         if(fprop->defaultarray) {
02809                                 farray= MEM_callocN(sizeof(float)*prop->totarraylength, "RNA_def_property_store");
02810                                 memcpy(farray, fprop->defaultarray, sizeof(float)*prop->totarraylength);
02811                                 fprop->defaultarray= farray;
02812                         }
02813                         break;
02814                 }
02815                 case PROP_STRING: {
02816                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
02817                         if(sprop->defaultvalue) sprop->defaultvalue= BLI_strdup(sprop->defaultvalue);
02818                         break;
02819                 }
02820                 default:
02821                         break;
02822         }
02823 
02824         prop->flag |= PROP_FREE_POINTERS;
02825 }
02826 
02827 void RNA_def_property_free_pointers(PropertyRNA *prop)
02828 {
02829         if(prop->flag & PROP_FREE_POINTERS) {
02830                 int a;
02831 
02832                 if(prop->identifier) MEM_freeN((void*)prop->identifier);
02833                 if(prop->name) MEM_freeN((void*)prop->name);
02834                 if(prop->description) MEM_freeN((void*)prop->description);
02835                 if(prop->py_data) MEM_freeN(prop->py_data);
02836 
02837                 switch(prop->type) {
02838                         case PROP_BOOLEAN: {
02839                                 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
02840                                 if(bprop->defaultarray) MEM_freeN((void*)bprop->defaultarray);
02841                                 break;
02842                         }
02843                         case PROP_INT: {
02844                                 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
02845                                 if(iprop->defaultarray) MEM_freeN((void*)iprop->defaultarray);
02846                                 break;
02847                         }
02848                         case PROP_FLOAT: {
02849                                 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
02850                                 if(fprop->defaultarray) MEM_freeN((void*)fprop->defaultarray);
02851                                 break;
02852                         }
02853                         case PROP_ENUM: {
02854                                 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
02855 
02856                                 for(a=0; a<eprop->totitem; a++) {
02857                                         if(eprop->item[a].identifier) MEM_freeN((void*)eprop->item[a].identifier);
02858                                         if(eprop->item[a].name) MEM_freeN((void*)eprop->item[a].name);
02859                                         if(eprop->item[a].description) MEM_freeN((void*)eprop->item[a].description);
02860                                 }
02861 
02862                                 if(eprop->item) MEM_freeN((void*)eprop->item);
02863                                 break;
02864                         }
02865                         case PROP_STRING: {
02866                                 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
02867                                 if(sprop->defaultvalue) MEM_freeN((void*)sprop->defaultvalue);
02868                                 break;
02869                         }
02870                         default:
02871                                 break;
02872                 }
02873         }
02874 }
02875 
02876 static void rna_def_property_free(StructOrFunctionRNA *cont_, PropertyRNA *prop)
02877 {
02878         ContainerRNA *cont= cont_;
02879         
02880         if(prop->flag & PROP_RUNTIME) {
02881                 if(cont->prophash)
02882                         BLI_ghash_remove(cont->prophash, (void*)prop->identifier, NULL, NULL);
02883 
02884                 RNA_def_property_free_pointers(prop);
02885                 rna_freelinkN(&cont->properties, prop);
02886         }
02887         else {
02888                 RNA_def_property_free_pointers(prop);
02889         }
02890 }
02891 
02892 /* note: only intended for removing dynamic props */
02893 int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier)
02894 {
02895         ContainerRNA *cont= cont_;
02896         PropertyRNA *prop;
02897         
02898         for(prop= cont->properties.first; prop; prop= prop->next) {
02899                 if(strcmp(prop->identifier, identifier)==0) {
02900                         if(prop->flag & PROP_RUNTIME) {
02901                                 rna_def_property_free(cont_, prop);
02902                                 return 1;
02903                         }
02904                         else {
02905                                 return -1;
02906                         }
02907                 }
02908         }
02909         return 0;
02910 }
02911 #endif
02912 
02913 const char *RNA_property_typename(PropertyType type)
02914 {
02915         switch(type) {
02916                 case PROP_BOOLEAN: return "PROP_BOOLEAN";
02917                 case PROP_INT: return "PROP_INT";
02918                 case PROP_FLOAT: return "PROP_FLOAT";
02919                 case PROP_STRING: return "PROP_STRING";
02920                 case PROP_ENUM: return "PROP_ENUM";
02921                 case PROP_POINTER: return "PROP_POINTER";
02922                 case PROP_COLLECTION: return "PROP_COLLECTION";
02923         }
02924 
02925         return "PROP_UNKNOWN";
02926 }