Blender V2.61 - r43446

rna_define.c

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