4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
31 #include "MEM_guardedalloc.h"
33 #include "RNA_access.h"
34 #include "RNA_define.h"
35 #include "RNA_types.h"
37 #include "rna_internal.h"
39 #define RNA_VERSION_DATE "$Id$"
43 #define snprintf _snprintf
47 /* Replace if different */
48 #define TMP_EXT ".tmp"
50 static int replace_if_different(char *tmpfile)
55 if(rename(tmpfile, orgfile) != 0) { \
56 fprintf(stderr, "%s:%d, rename error: \"%s\" -> \"%s\"\n", __FILE__, __LINE__, tmpfile, orgfile); \
64 FILE *fp_new, *fp_org;
66 char *arr_new, *arr_org;
71 strcpy(orgfile, tmpfile);
72 orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* strip '.tmp' */
74 fp_org= fopen(orgfile, "rb");
80 fp_new= fopen(tmpfile, "rb");
83 /* shouldn't happen, just to be safe */
84 fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
88 fseek(fp_new, 0L, SEEK_END); len_new = ftell(fp_new); fseek(fp_new, 0L, SEEK_SET);
89 fseek(fp_org, 0L, SEEK_END); len_org = ftell(fp_org); fseek(fp_org, 0L, SEEK_SET);
92 if(len_new != len_org) {
98 /* now compare the files... */
99 arr_new= MEM_mallocN(sizeof(char)*len_new, "rna_cmp_file_new");
100 arr_org= MEM_mallocN(sizeof(char)*len_org, "rna_cmp_file_org");
102 if(fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
103 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
104 if(fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
105 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
110 cmp= memcmp(arr_new, arr_org, len_new);
130 static int cmp_struct(const void *a, const void *b)
132 const StructRNA *structa= *(const StructRNA**)a;
133 const StructRNA *structb= *(const StructRNA**)b;
135 return strcmp(structa->identifier, structb->identifier);
138 static int cmp_property(const void *a, const void *b)
140 const PropertyRNA *propa= *(const PropertyRNA**)a;
141 const PropertyRNA *propb= *(const PropertyRNA**)b;
143 if(strcmp(propa->identifier, "rna_type") == 0) return -1;
144 else if(strcmp(propb->identifier, "rna_type") == 0) return 1;
146 if(strcmp(propa->identifier, "name") == 0) return -1;
147 else if(strcmp(propb->identifier, "name") == 0) return 1;
149 return strcmp(propa->name, propb->name);
152 static int cmp_def_struct(const void *a, const void *b)
154 const StructDefRNA *dsa= *(const StructDefRNA**)a;
155 const StructDefRNA *dsb= *(const StructDefRNA**)b;
157 return cmp_struct(&dsa->srna, &dsb->srna);
160 static int cmp_def_property(const void *a, const void *b)
162 const PropertyDefRNA *dpa= *(const PropertyDefRNA**)a;
163 const PropertyDefRNA *dpb= *(const PropertyDefRNA**)b;
165 return cmp_property(&dpa->prop, &dpb->prop);
168 static void rna_sortlist(ListBase *listbase, int(*cmp)(const void*, const void*))
174 if(listbase->first == listbase->last)
177 for(size=0, link=listbase->first; link; link=link->next)
180 array= MEM_mallocN(sizeof(void*)*size, "rna_sortlist");
181 for(a=0, link=listbase->first; link; link=link->next, a++)
184 qsort(array, size, sizeof(void*), cmp);
186 listbase->first= listbase->last= NULL;
187 for(a=0; a<size; a++) {
189 link->next= link->prev= NULL;
190 rna_addtail(listbase, link);
198 static void rna_print_c_string(FILE *f, const char *str)
200 static char *escape[] = {"\''", "\"\"", "\??", "\\\\","\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", NULL};
209 for(i=0; str[i]; i++) {
210 for(j=0; escape[j]; j++)
211 if(str[i] == escape[j][0])
214 if(escape[j]) fprintf(f, "\\%c", escape[j][1]);
215 else fprintf(f, "%c", str[i]);
220 static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
222 if(dp->dnastructfromname && dp->dnastructfromprop)
223 fprintf(f, " %s *data= (%s*)(((%s*)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname, dp->dnastructfromname, dp->dnastructfromprop);
225 fprintf(f, " %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
228 static void rna_print_id_get(FILE *f, PropertyDefRNA *dp)
230 fprintf(f, " ID *id= ptr->id.data;\n");
233 static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
239 snprintf(buffer, sizeof(buffer), "%s_%s_%s", structname, propname, type);
240 result= MEM_callocN(sizeof(char)*strlen(buffer)+1, "rna_alloc_function_name");
241 strcpy(result, buffer);
243 alloc= MEM_callocN(sizeof(AllocDefRNA), "AllocDefRNA");
245 rna_addtail(&DefRNA.allocs, alloc);
250 static StructRNA *rna_find_struct(const char *identifier)
254 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
255 if(strcmp(ds->srna->identifier, identifier)==0)
261 static const char *rna_find_type(const char *type)
265 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
266 if(ds->dnaname && strcmp(ds->dnaname, type)==0)
267 return ds->srna->identifier;
272 static const char *rna_find_dna_type(const char *type)
276 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
277 if(strcmp(ds->srna->identifier, type)==0)
283 static const char *rna_type_type_name(PropertyRNA *prop)
299 static const char *rna_type_type(PropertyRNA *prop)
303 type= rna_type_type_name(prop);
311 static const char *rna_type_struct(PropertyRNA *prop)
315 type= rna_type_type_name(prop);
323 static const char *rna_parameter_type_name(PropertyRNA *parm)
327 type= rna_type_type_name(parm);
334 PointerPropertyRNA *pparm= (PointerPropertyRNA*)parm;
336 if(parm->flag & PROP_RNAPTR)
339 return rna_find_dna_type((const char *)pparm->type);
341 case PROP_COLLECTION: {
345 return "<error, no type specified>";
349 static int rna_enum_bitmask(PropertyRNA *prop)
351 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
355 for(a=0; a<eprop->totitem; a++)
356 if(eprop->item[a].identifier[0])
357 mask |= eprop->item[a].value;
363 static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
365 if(prop->type == PROP_FLOAT && prop->subtype == PROP_COLOR)
366 if(strcmp(dp->dnatype, "float") != 0 && strcmp(dp->dnatype, "double") != 0)
372 static const char *rna_function_string(void *func)
374 return (func)? (const char*)func: "NULL";
377 static void rna_float_print(FILE *f, float num)
379 if(num == -FLT_MAX) fprintf(f, "-FLT_MAX");
380 else if(num == FLT_MAX) fprintf(f, "FLT_MAX");
381 else if((int)num == num) fprintf(f, "%.1ff", num);
382 else fprintf(f, "%.10ff", num);
385 static void rna_int_print(FILE *f, int num)
387 if(num == INT_MIN) fprintf(f, "INT_MIN");
388 else if(num == INT_MAX) fprintf(f, "INT_MAX");
389 else fprintf(f, "%d", num);
392 static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
396 if(prop->flag & PROP_IDPROPERTY)
400 if(!dp->dnastructname || !dp->dnaname) {
401 fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
407 func= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
411 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
412 fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
415 fprintf(f, " %s(ptr, value);\n", manualfunc);
418 rna_print_data_get(f, dp);
420 fprintf(f, " BLI_strncpy(value, data->%s, %d);\n", dp->dnaname, sprop->maxlength);
422 fprintf(f, " BLI_strncpy(value, data->%s, sizeof(data->%s));\n", dp->dnaname, dp->dnaname);
428 fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func);
431 fprintf(f, " return %s(ptr);\n", manualfunc);
434 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
435 rna_print_data_get(f, dp);
436 if(dp->dnapointerlevel == 0)
437 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, &data->%s);\n", (char*)pprop->type, dp->dnaname);
439 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, data->%s);\n", (char*)pprop->type, dp->dnaname);
444 case PROP_COLLECTION: {
445 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
447 fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
450 if(strcmp(manualfunc, "rna_iterator_listbase_get") == 0 ||
451 strcmp(manualfunc, "rna_iterator_array_get") == 0 ||
452 strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0)
453 fprintf(f, " return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", (cprop->item_type)? (char*)cprop->item_type: "UnknownType", manualfunc);
455 fprintf(f, " return %s(iter);\n", manualfunc);
461 if(prop->arraydimension) {
462 if(prop->flag & PROP_DYNAMIC)
463 fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
465 fprintf(f, "void %s(PointerRNA *ptr, %s values[%d])\n", func, rna_type_type(prop), prop->totarraylength);
469 fprintf(f, " %s(ptr, values);\n", manualfunc);
472 rna_print_data_get(f, dp);
474 if(prop->flag & PROP_DYNAMIC) {
475 char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get_length");
476 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
477 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
478 fprintf(f, " for(i=0; i<len; i++) {\n");
482 fprintf(f, " int i;\n\n");
483 fprintf(f, " for(i=0; i<%d; i++) {\n", prop->totarraylength);
486 if(dp->dnaarraylength == 1) {
487 if(prop->type == PROP_BOOLEAN && dp->booleanbit)
488 fprintf(f, " values[i]= (%s(data->%s & (%d<<i)) != 0);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
490 fprintf(f, " values[i]= (%s)%s((&data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
493 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
494 fprintf(f, " values[i]= (%s(data->%s[i] & ", (dp->booleannegative)? "!": "", dp->dnaname);
495 rna_int_print(f, dp->booleanbit);
496 fprintf(f, ") != 0);\n");
498 else if(rna_color_quantize(prop, dp))
499 fprintf(f, " values[i]= (%s)(data->%s[i]*(1.0f/255.0f));\n", rna_type_type(prop), dp->dnaname);
501 fprintf(f, " values[i]= (%s)%s(((%s*)data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname);
503 fprintf(f, " values[i]= (%s)%s((data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
510 fprintf(f, "%s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
514 fprintf(f, " return %s(ptr);\n", manualfunc);
517 rna_print_data_get(f, dp);
518 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
519 fprintf(f, " return (%s((data->%s) & ", (dp->booleannegative)? "!": "", dp->dnaname);
520 rna_int_print(f, dp->booleanbit);
521 fprintf(f, ") != 0);\n");
523 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
524 fprintf(f, " return ((data->%s) & ", dp->dnaname);
525 rna_int_print(f, rna_enum_bitmask(prop));
529 fprintf(f, " return (%s)%s(data->%s);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
540 static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
542 if(prop->type == PROP_INT) {
543 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
545 if(iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
546 if(array) fprintf(f, "CLAMPIS(values[i], ");
547 else fprintf(f, "CLAMPIS(value, ");
548 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
549 rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
553 else if(prop->type == PROP_FLOAT) {
554 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
556 if(fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
557 if(array) fprintf(f, "CLAMPIS(values[i], ");
558 else fprintf(f, "CLAMPIS(value, ");
559 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
560 rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
566 fprintf(f, "values[i];\n");
568 fprintf(f, "value;\n");
571 static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
575 if(!(prop->flag & PROP_EDITABLE))
577 if(prop->flag & PROP_IDPROPERTY)
581 if(!dp->dnastructname || !dp->dnaname) {
582 if(prop->flag & PROP_EDITABLE) {
583 fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
590 func= rna_alloc_function_name(srna->identifier, prop->identifier, "set");
594 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
595 fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func);
598 fprintf(f, " %s(ptr, value);\n", manualfunc);
601 rna_print_data_get(f, dp);
603 fprintf(f, " BLI_strncpy(data->%s, value, %d);\n", dp->dnaname, sprop->maxlength);
605 fprintf(f, " BLI_strncpy(data->%s, value, sizeof(data->%s));\n", dp->dnaname, dp->dnaname);
611 fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func);
614 fprintf(f, " %s(ptr, value);\n", manualfunc);
617 rna_print_data_get(f, dp);
619 if(prop->flag & PROP_ID_SELF_CHECK) {
620 rna_print_id_get(f, dp);
621 fprintf(f, " if(id==value.data) return;\n\n");
624 if(prop->flag & PROP_ID_REFCOUNT) {
625 fprintf(f, "\n if(data->%s)\n", dp->dnaname);
626 fprintf(f, " id_us_min((ID*)data->%s);\n", dp->dnaname);
627 fprintf(f, " if(value.data)\n");
628 fprintf(f, " id_us_plus((ID*)value.data);\n\n");
631 fprintf(f, " data->%s= value.data;\n", dp->dnaname);
638 if(prop->arraydimension) {
639 if(prop->flag & PROP_DYNAMIC)
640 fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
642 fprintf(f, "void %s(PointerRNA *ptr, const %s values[%d])\n", func, rna_type_type(prop), prop->totarraylength);
646 fprintf(f, " %s(ptr, values);\n", manualfunc);
649 rna_print_data_get(f, dp);
651 if(prop->flag & PROP_DYNAMIC) {
652 char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "set_length");
653 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
654 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
655 fprintf(f, " for(i=0; i<len; i++) {\n");
659 fprintf(f, " int i;\n\n");
660 fprintf(f, " for(i=0; i<%d; i++) {\n", prop->totarraylength);
663 if(dp->dnaarraylength == 1) {
664 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
665 fprintf(f, " if(%svalues[i]) data->%s |= (%d<<i);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
666 fprintf(f, " else data->%s &= ~(%d<<i);\n", dp->dnaname, dp->booleanbit);
669 fprintf(f, " (&data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
670 rna_clamp_value(f, prop, 1);
674 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
675 fprintf(f, " if(%svalues[i]) data->%s[i] |= ", (dp->booleannegative)? "!": "", dp->dnaname);
676 rna_int_print(f, dp->booleanbit);
678 fprintf(f, " else data->%s[i] &= ~", dp->dnaname);
679 rna_int_print(f, dp->booleanbit);
682 else if(rna_color_quantize(prop, dp)) {
683 fprintf(f, " data->%s[i]= FTOCHAR(values[i]);\n", dp->dnaname);
687 fprintf(f, " ((%s*)data->%s)[i]= %s", dp->dnatype, dp->dnaname, (dp->booleannegative)? "!": "");
689 fprintf(f, " (data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
690 rna_clamp_value(f, prop, 1);
698 fprintf(f, "void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
702 fprintf(f, " %s(ptr, value);\n", manualfunc);
705 rna_print_data_get(f, dp);
706 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
707 fprintf(f, " if(%svalue) data->%s |= ", (dp->booleannegative)? "!": "", dp->dnaname);
708 rna_int_print(f, dp->booleanbit);
710 fprintf(f, " else data->%s &= ~", dp->dnaname);
711 rna_int_print(f, dp->booleanbit);
714 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
715 fprintf(f, " data->%s &= ~", dp->dnaname);
716 rna_int_print(f, rna_enum_bitmask(prop));
718 fprintf(f, " data->%s |= value;\n", dp->dnaname);
721 fprintf(f, " data->%s= %s", dp->dnaname, (dp->booleannegative)? "!": "");
722 rna_clamp_value(f, prop, 0);
733 static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
737 if(prop->flag & PROP_IDPROPERTY)
740 if(prop->type == PROP_STRING) {
742 if(!dp->dnastructname || !dp->dnaname) {
743 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
749 func= rna_alloc_function_name(srna->identifier, prop->identifier, "length");
751 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
754 fprintf(f, " return %s(ptr);\n", manualfunc);
757 rna_print_data_get(f, dp);
758 fprintf(f, " return strlen(data->%s);\n", dp->dnaname);
762 else if(prop->type == PROP_COLLECTION) {
764 if(prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed)|| !dp->dnaname)) {
765 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
771 func= rna_alloc_function_name(srna->identifier, prop->identifier, "length");
773 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
776 fprintf(f, " return %s(ptr);\n", manualfunc);
779 rna_print_data_get(f, dp);
780 if(dp->dnalengthname)
781 fprintf(f, " return (data->%s == NULL)? 0: data->%s;\n", dp->dnaname, dp->dnalengthname);
783 fprintf(f, " return (data->%s == NULL)? 0: %d;\n", dp->dnaname, dp->dnalengthfixed);
791 static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
793 char *func, *getfunc;
795 if(prop->flag & PROP_IDPROPERTY)
799 if(!dp->dnastructname || !dp->dnaname) {
800 fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
806 func= rna_alloc_function_name(srna->identifier, prop->identifier, "begin");
808 fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
812 rna_print_data_get(f, dp);
814 fprintf(f, "\n memset(iter, 0, sizeof(*iter));\n");
815 fprintf(f, " iter->parent= *ptr;\n");
816 fprintf(f, " iter->prop= (PropertyRNA*)&rna_%s_%s;\n", srna->identifier, prop->identifier);
818 if(dp->dnalengthname || dp->dnalengthfixed) {
820 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
823 if(dp->dnalengthname)
824 fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthname);
826 fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed);
831 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
832 else if(dp->dnapointerlevel == 0)
833 fprintf(f, "\n rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname);
835 fprintf(f, "\n rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname);
838 getfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
840 fprintf(f, "\n if(iter->valid)\n");
841 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
849 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
851 char *func, *getfunc;
853 if(prop->flag & PROP_IDPROPERTY)
859 func= rna_alloc_function_name(srna->identifier, prop->identifier, "next");
861 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
863 fprintf(f, " %s(iter);\n", manualfunc);
865 getfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
867 fprintf(f, "\n if(iter->valid)\n");
868 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
875 static char *rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
879 if(prop->flag & PROP_IDPROPERTY)
882 func= rna_alloc_function_name(srna->identifier, prop->identifier, "end");
884 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
887 fprintf(f, " %s(iter);\n", manualfunc);
893 static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
895 if(dp->dnapointerlevel != 0)
897 if(!dp->dnatype || !dp->dnaname || !dp->dnastructname)
900 if(strcmp(dp->dnatype, "char") == 0) {
901 prop->rawtype= PROP_RAW_CHAR;
902 prop->flag |= PROP_RAW_ACCESS;
904 else if(strcmp(dp->dnatype, "short") == 0) {
905 prop->rawtype= PROP_RAW_SHORT;
906 prop->flag |= PROP_RAW_ACCESS;
908 else if(strcmp(dp->dnatype, "int") == 0) {
909 prop->rawtype= PROP_RAW_INT;
910 prop->flag |= PROP_RAW_ACCESS;
912 else if(strcmp(dp->dnatype, "float") == 0) {
913 prop->rawtype= PROP_RAW_FLOAT;
914 prop->flag |= PROP_RAW_ACCESS;
916 else if(strcmp(dp->dnatype, "double") == 0) {
917 prop->rawtype= PROP_RAW_DOUBLE;
918 prop->flag |= PROP_RAW_ACCESS;
922 static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
924 PropertyDefRNA *dp= rna_find_struct_property_def(srna, prop);
926 fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype);
929 static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
937 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
939 if(!prop->arraydimension) {
940 if(!bprop->get && !bprop->set && !dp->booleanbit)
941 rna_set_raw_property(dp, prop);
943 bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)bprop->get);
944 bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)bprop->set);
947 bprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)bprop->getarray);
948 bprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)bprop->setarray);
953 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
955 if(!prop->arraydimension) {
956 if(!iprop->get && !iprop->set)
957 rna_set_raw_property(dp, prop);
959 iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->get);
960 iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->set);
963 if(!iprop->getarray && !iprop->setarray)
964 rna_set_raw_property(dp, prop);
966 iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->getarray);
967 iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->setarray);
972 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
974 if(!prop->arraydimension) {
975 if(!fprop->get && !fprop->set)
976 rna_set_raw_property(dp, prop);
978 fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->get);
979 fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->set);
982 if(!fprop->getarray && !fprop->setarray)
983 rna_set_raw_property(dp, prop);
985 fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->getarray);
986 fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->setarray);
991 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
993 eprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)eprop->get);
994 eprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)eprop->set);
998 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1000 sprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)sprop->get);
1001 sprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (char*)sprop->length);
1002 sprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)sprop->set);
1005 case PROP_POINTER: {
1006 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1008 pprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)pprop->get);
1009 pprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)pprop->set);
1011 fprintf(stderr, "rna_def_property_funcs: %s.%s, pointer must have a struct type.\n", srna->identifier, prop->identifier);
1016 case PROP_COLLECTION: {
1017 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1019 if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0);
1020 else if(dp->dnalengthname || dp->dnalengthfixed)
1021 cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (char*)cprop->length);
1023 /* test if we can allow raw array access, if it is using our standard
1024 * array get/next function, we can be sure it is an actual array */
1025 if(cprop->next && cprop->get)
1026 if(strcmp((char*)cprop->next, "rna_iterator_array_next") == 0 &&
1027 strcmp((char*)cprop->get, "rna_iterator_array_get") == 0)
1028 prop->flag |= PROP_RAW_ARRAY;
1030 cprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)cprop->get);
1031 cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp, (char*)cprop->begin);
1032 cprop->next= (void*)rna_def_property_next_func(f, srna, prop, dp, (char*)cprop->next);
1033 cprop->end= (void*)rna_def_property_end_func(f, srna, prop, dp, (char*)cprop->end);
1035 if(!(prop->flag & PROP_IDPROPERTY)) {
1037 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a begin function.\n", srna->identifier, prop->identifier);
1041 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a next function.\n", srna->identifier, prop->identifier);
1045 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a get function.\n", srna->identifier, prop->identifier);
1049 if(!cprop->item_type) {
1050 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a struct type.\n", srna->identifier, prop->identifier);
1058 static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1065 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1068 func= rna_alloc_function_name(srna->identifier, prop->identifier, "");
1070 switch(prop->type) {
1073 if(!prop->arraydimension) {
1074 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1075 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1078 fprintf(f, "void %sget(PointerRNA *ptr, int values[%d]);\n", func, prop->totarraylength);
1079 //fprintf(f, "void %sset(PointerRNA *ptr, const int values[%d]);\n", func, prop->arraylength);
1084 if(!prop->arraydimension) {
1085 fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
1086 //fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
1089 fprintf(f, "void %sget(PointerRNA *ptr, float values[%d]);\n", func, prop->totarraylength);
1090 //fprintf(f, "void %sset(PointerRNA *ptr, const float values[%d]);\n", func, prop->arraylength);
1095 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1099 fprintf(f, "enum {\n");
1101 for(i=0; i<eprop->totitem; i++)
1102 if(eprop->item[i].identifier[0])
1103 fprintf(f, "\t%s_%s_%s = %d,\n", srna->identifier, prop->identifier, eprop->item[i].identifier, eprop->item[i].value);
1105 fprintf(f, "};\n\n");
1108 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1109 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1114 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1116 if(sprop->maxlength) {
1117 fprintf(f, "#define %s_%s_MAX %d\n\n", srna->identifier, prop->identifier, sprop->maxlength);
1120 fprintf(f, "void %sget(PointerRNA *ptr, char *value);\n", func);
1121 fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1122 //fprintf(f, "void %sset(PointerRNA *ptr, const char *value);\n", func);
1126 case PROP_POINTER: {
1127 fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func);
1128 //fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func);
1131 case PROP_COLLECTION: {
1132 fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
1133 fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
1134 fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
1135 //fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1136 //fprintf(f, "void %slookup_int(PointerRNA *ptr, int key, StructRNA **type);\n", func);
1137 //fprintf(f, "void %slookup_string(PointerRNA *ptr, const char *key, StructRNA **type);\n", func);
1145 static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1151 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1154 if(prop->name && prop->description && strcmp(prop->description, "") != 0)
1155 fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
1157 fprintf(f, "\t/* %s */\n", prop->name);
1159 fprintf(f, "\t/* */\n");
1161 switch(prop->type) {
1162 case PROP_BOOLEAN: {
1163 if(!prop->arraydimension)
1164 fprintf(f, "\tbool %s(void);", prop->identifier);
1166 fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier);
1170 if(!prop->arraydimension)
1171 fprintf(f, "\tint %s(void);", prop->identifier);
1173 fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier);
1177 if(!prop->arraydimension)
1178 fprintf(f, "\tfloat %s(void);", prop->identifier);
1180 fprintf(f, "\tArray<float, %d> %s(void);", prop->totarraylength, prop->identifier);
1184 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1188 fprintf(f, "\tenum %s_enum {\n", prop->identifier);
1190 for(i=0; i<eprop->totitem; i++)
1191 if(eprop->item[i].identifier[0])
1192 fprintf(f, "\t\t%s_%s = %d,\n", prop->identifier, eprop->item[i].identifier, eprop->item[i].value);
1194 fprintf(f, "\t};\n");
1197 fprintf(f, "\t%s_enum %s(void);", prop->identifier, prop->identifier);
1201 fprintf(f, "\tstd::string %s(void);", prop->identifier);
1204 case PROP_POINTER: {
1205 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1208 fprintf(f, "\t%s %s(void);", (char*)pprop->type, prop->identifier);
1210 fprintf(f, "\t%s %s(void);", "UnknownType", prop->identifier);
1213 case PROP_COLLECTION: {
1214 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1216 if(cprop->item_type)
1217 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->item_type, srna->identifier, prop->identifier);
1219 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
1227 static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1233 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1236 switch(prop->type) {
1237 case PROP_BOOLEAN: {
1238 if(!prop->arraydimension)
1239 fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1241 fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
1245 if(!prop->arraydimension)
1246 fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1248 fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
1252 if(!prop->arraydimension)
1253 fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1255 fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
1259 fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", prop->identifier, srna->identifier, prop->identifier);
1264 fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1267 case PROP_POINTER: {
1268 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1271 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", (char*)pprop->type, srna->identifier, prop->identifier);
1273 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
1276 case PROP_COLLECTION: {
1277 /*CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1280 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->type, srna->identifier, prop->identifier);
1282 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);*/
1290 static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
1294 PropertyDefRNA *dparm;
1296 char *funcname, *ptrstr, *valstr;
1297 int flag, pout, cptr, first;
1305 funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call");
1307 /* function definition */
1308 fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname);
1309 fprintf(f, "\n{\n");
1311 /* variable definitions */
1312 if((func->flag & FUNC_NO_SELF)==0) {
1313 if(func->flag & FUNC_USE_SELF_ID)
1314 fprintf(f, "\tstruct ID *_selfid;\n");
1316 if(dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
1317 else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
1320 dparm= dfunc->cont.properties.first;
1321 for(; dparm; dparm= dparm->next) {
1322 type = dparm->prop->type;
1323 flag = dparm->prop->flag;
1324 pout = (flag & PROP_OUTPUT);
1325 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1327 if(dparm->prop==func->c_ret)
1328 ptrstr= cptr || dparm->prop->arraydimension ? "*" : "";
1329 /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
1330 else if (cptr || (flag & PROP_DYNAMIC))
1331 ptrstr= pout ? "**" : "*";
1332 /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
1333 else if (type == PROP_POINTER || dparm->prop->arraydimension)
1335 /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack, but type name for string props is already char*, so leave empty */
1336 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
1339 ptrstr= pout ? "*" : "";
1341 fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
1343 /* for dynamic parameters we pass an additional int for the length of the parameter */
1344 if (flag & PROP_DYNAMIC)
1345 fprintf(f, "\tint %s%s_len;\n", pout ? "*" : "", dparm->prop->identifier);
1348 fprintf(f, "\tchar *_data");
1349 if(func->c_ret) fprintf(f, ", *_retdata");
1354 if((func->flag & FUNC_NO_SELF)==0) {
1355 if(func->flag & FUNC_USE_SELF_ID)
1356 fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
1358 if(dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
1359 else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
1362 fprintf(f, "\t_data= (char *)_parms->data;\n");
1364 dparm= dfunc->cont.properties.first;
1365 for(; dparm; dparm= dparm->next) {
1366 type = dparm->prop->type;
1367 flag = dparm->prop->flag;
1368 pout = (flag & PROP_OUTPUT);
1369 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1371 if(dparm->prop==func->c_ret)
1372 fprintf(f, "\t_retdata= _data;\n");
1374 if (cptr || (flag & PROP_DYNAMIC)) {
1378 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
1382 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
1391 fprintf(f, "\t%s= ", dparm->prop->identifier);
1394 fprintf(f, "%s", valstr);
1396 fprintf(f, "((%s%s%s)_data);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr);
1398 /* this must be kept in sync with RNA_parameter_length_get_data, we could just call the function directly, but this is faster */
1399 if (flag & PROP_DYNAMIC)
1400 fprintf(f, "\t%s_len= %s((int *)(_data+%d));\n", dparm->prop->identifier, pout ? "" : "*", rna_parameter_size(dparm->prop));
1404 fprintf(f, "\t_data+= %d;\n", rna_parameter_size_alloc(dparm->prop));
1410 if(func->c_ret) fprintf(f, "%s= ", func->c_ret->identifier);
1411 fprintf(f, "%s(", dfunc->call);
1415 if((func->flag & FUNC_NO_SELF)==0) {
1416 if(func->flag & FUNC_USE_SELF_ID)
1417 fprintf(f, "_selfid, ");
1419 fprintf(f, "_self");
1423 if(func->flag & FUNC_USE_CONTEXT) {
1424 if(!first) fprintf(f, ", ");
1429 if(func->flag & FUNC_USE_REPORTS) {
1430 if(!first) fprintf(f, ", ");
1432 fprintf(f, "reports");
1435 dparm= dfunc->cont.properties.first;
1436 for(; dparm; dparm= dparm->next) {
1437 if(dparm->prop==func->c_ret)
1440 if(!first) fprintf(f, ", ");
1443 fprintf(f, "%s", dparm->prop->identifier);
1445 if (dparm->prop->flag & PROP_DYNAMIC)
1446 fprintf(f, ", %s_len", dparm->prop->identifier);
1452 dparm= rna_find_parameter_def(func->c_ret);
1453 ptrstr= (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) || (dparm->prop->arraydimension))? "*": "";
1454 fprintf(f, "\t*((%s%s%s*)_retdata)= %s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, func->c_ret->identifier);
1458 fprintf(f, "}\n\n");
1460 dfunc->gencall= funcname;
1463 static void rna_auto_types()
1468 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
1469 /* DNA name for Screen is patched in 2.5, we do the reverse here .. */
1470 if(ds->dnaname && strcmp(ds->dnaname, "Screen") == 0)
1471 ds->dnaname= "bScreen";
1473 for(dp=ds->cont.properties.first; dp; dp=dp->next) {
1474 if(dp->dnastructname && strcmp(dp->dnastructname, "Screen") == 0)
1475 dp->dnastructname= "bScreen";
1478 if(dp->prop->type == PROP_POINTER) {
1479 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1482 if(!pprop->type && !pprop->get)
1483 pprop->type= (StructRNA*)rna_find_type(dp->dnatype);
1486 type= rna_find_struct((char*)pprop->type);
1487 if(type && (type->flag & STRUCT_ID_REFCOUNT))
1488 pprop->property.flag |= PROP_ID_REFCOUNT;
1491 else if(dp->prop->type== PROP_COLLECTION) {
1492 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1494 if(!cprop->item_type && !cprop->get && strcmp(dp->dnatype, "ListBase")==0)
1495 cprop->item_type= (StructRNA*)rna_find_type(dp->dnatype);
1502 static void rna_sort(BlenderRNA *brna)
1507 rna_sortlist(&brna->structs, cmp_struct);
1508 rna_sortlist(&DefRNA.structs, cmp_def_struct);
1510 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1511 rna_sortlist(&srna->cont.properties, cmp_property);
1513 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
1514 rna_sortlist(&ds->cont.properties, cmp_def_property);
1517 static const char *rna_property_structname(PropertyType type)
1520 case PROP_BOOLEAN: return "BooleanPropertyRNA";
1521 case PROP_INT: return "IntPropertyRNA";
1522 case PROP_FLOAT: return "FloatPropertyRNA";
1523 case PROP_STRING: return "StringPropertyRNA";
1524 case PROP_ENUM: return "EnumPropertyRNA";
1525 case PROP_POINTER: return "PointerPropertyRNA";
1526 case PROP_COLLECTION: return "CollectionPropertyRNA";
1527 default: return "UnknownPropertyRNA";
1531 static const char *rna_property_typename(PropertyType type)
1534 case PROP_BOOLEAN: return "PROP_BOOLEAN";
1535 case PROP_INT: return "PROP_INT";
1536 case PROP_FLOAT: return "PROP_FLOAT";
1537 case PROP_STRING: return "PROP_STRING";
1538 case PROP_ENUM: return "PROP_ENUM";
1539 case PROP_POINTER: return "PROP_POINTER";
1540 case PROP_COLLECTION: return "PROP_COLLECTION";
1541 default: return "PROP_UNKNOWN";
1545 static const char *rna_property_subtypename(PropertyType type)
1548 case PROP_NONE: return "PROP_NONE";
1549 case PROP_FILEPATH: return "PROP_FILEPATH";
1550 case PROP_DIRPATH: return "PROP_DIRPATH";
1551 case PROP_UNSIGNED: return "PROP_UNSIGNED";
1552 case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
1553 case PROP_FACTOR: return "PROP_FACTOR";
1554 case PROP_ANGLE: return "PROP_ANGLE";
1555 case PROP_TIME: return "PROP_TIME";
1556 case PROP_DISTANCE: return "PROP_DISTANCE";
1557 case PROP_COLOR: return "PROP_COLOR";
1558 case PROP_TRANSLATION: return "PROP_TRANSLATION";
1559 case PROP_DIRECTION: return "PROP_DIRECTION";
1560 case PROP_MATRIX: return "PROP_MATRIX";
1561 case PROP_EULER: return "PROP_EULER";
1562 case PROP_QUATERNION: return "PROP_QUATERNION";
1563 case PROP_AXISANGLE: return "PROP_AXISANGLE";
1564 case PROP_VELOCITY: return "PROP_VELOCITY";
1565 case PROP_ACCELERATION: return "PROP_ACCELERATION";
1566 case PROP_XYZ: return "PROP_XYZ";
1567 case PROP_COLOR_GAMMA: return "PROP_COLOR_GAMMA";
1568 case PROP_LAYER: return "PROP_LAYER";
1569 case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
1571 /* incase we dont have a type preset that includes the subtype */
1572 if(RNA_SUBTYPE_UNIT(type)) {
1573 return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
1576 return "PROP_SUBTYPE_UNKNOWN";
1582 static const char *rna_property_subtype_unit(PropertyType type)
1584 switch(RNA_SUBTYPE_UNIT(type)) {
1585 case PROP_UNIT_NONE: return "PROP_UNIT_NONE";
1586 case PROP_UNIT_LENGTH: return "PROP_UNIT_LENGTH";
1587 case PROP_UNIT_AREA: return "PROP_UNIT_AREA";
1588 case PROP_UNIT_VOLUME: return "PROP_UNIT_VOLUME";
1589 case PROP_UNIT_MASS: return "PROP_UNIT_MASS";
1590 case PROP_UNIT_ROTATION: return "PROP_UNIT_ROTATION";
1591 case PROP_UNIT_TIME: return "PROP_UNIT_TIME";
1592 case PROP_UNIT_VELOCITY: return "PROP_UNIT_VELOCITY";
1593 case PROP_UNIT_ACCELERATION:return "PROP_UNIT_ACCELERATION";
1594 default: return "PROP_UNKNOWN";
1598 static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
1602 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1603 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
1607 static void rna_generate_blender(BlenderRNA *brna, FILE *f)
1611 fprintf(f, "BlenderRNA BLENDER_RNA = {");
1613 srna= brna->structs.first;
1614 if(srna) fprintf(f, "{&RNA_%s, ", srna->identifier);
1615 else fprintf(f, "{NULL, ");
1617 srna= brna->structs.last;
1618 if(srna) fprintf(f, "&RNA_%s}", srna->identifier);
1619 else fprintf(f, "NULL}");
1621 fprintf(f, "};\n\n");
1624 static void rna_generate_property_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1632 for(prop=base->cont.properties.first; prop; prop=prop->next)
1633 fprintf(f, "%s%s rna_%s_%s;\n", "extern ", rna_property_structname(prop->type), base->identifier, prop->identifier);
1637 if(srna->cont.properties.first)
1640 for(prop=srna->cont.properties.first; prop; prop=prop->next)
1641 fprintf(f, "%s%s rna_%s_%s;\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, prop->identifier);
1645 static void rna_generate_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionRNA *func, FILE *f)
1649 for(parm= func->cont.properties.first; parm; parm= parm->next)
1650 fprintf(f, "%s%s rna_%s_%s_%s;\n", "extern ", rna_property_structname(parm->type), srna->identifier, func->identifier, parm->identifier);
1652 if(func->cont.properties.first)
1656 static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1663 for(func= base->functions.first; func; func= func->cont.next) {
1664 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", base->identifier, func->identifier);
1665 rna_generate_parameter_prototypes(brna, base, func, f);
1668 if(base->functions.first)
1674 for(func= srna->functions.first; func; func= func->cont.next) {
1675 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier);
1676 rna_generate_parameter_prototypes(brna, srna, func, f);
1679 if(srna->functions.first)
1683 static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionDefRNA *dfunc, FILE *f)
1686 PropertyDefRNA *dparm;
1687 StructDefRNA *dsrna;
1689 int flag, pout, cptr, first;
1692 dsrna= rna_find_struct_def(srna);
1696 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
1697 if(dparm->prop==func->c_ret) {
1698 if(dparm->prop->arraydimension)
1699 fprintf(f, "XXX no array return types yet"); /* XXX not supported */
1700 else if(dparm->prop->type == PROP_POINTER && !(dparm->prop->flag & PROP_RNAPTR))
1701 fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1703 fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1709 /* void if nothing to return */
1711 fprintf(f, "void ");
1714 fprintf(f, "%s(", dfunc->call);
1718 /* self, context and reports parameters */
1719 if((func->flag & FUNC_NO_SELF)==0) {
1720 if(func->flag & FUNC_USE_SELF_ID)
1721 fprintf(f, "struct ID *_selfid, ");
1723 if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
1724 else fprintf(f, "struct %s *_self", srna->identifier);
1728 if(func->flag & FUNC_USE_CONTEXT) {
1729 if(!first) fprintf(f, ", ");
1731 fprintf(f, "bContext *C");
1734 if(func->flag & FUNC_USE_REPORTS) {
1735 if(!first) fprintf(f, ", ");
1737 fprintf(f, "ReportList *reports");
1740 /* defined parameters */
1741 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
1742 type = dparm->prop->type;
1743 flag = dparm->prop->flag;
1744 pout = (flag & PROP_OUTPUT);
1745 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1747 if(dparm->prop==func->c_ret)
1750 if (cptr || (flag & PROP_DYNAMIC))
1751 ptrstr= pout ? "**" : "*";
1752 else if (type == PROP_POINTER || dparm->prop->arraydimension)
1754 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
1757 ptrstr= pout ? "*" : "";
1759 if(!first) fprintf(f, ", ");
1762 if(!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension)
1763 fprintf(f, "%s%s %s[%d]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->totarraylength);
1765 fprintf(f, "%s%s %s%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
1767 if (flag & PROP_DYNAMIC)
1768 fprintf(f, ", int %s%s_len", pout ? "*" : "", dparm->prop->identifier);
1774 static void rna_generate_static_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1777 FunctionDefRNA *dfunc;
1780 for(func= srna->functions.first; func; func= func->cont.next) {
1781 dfunc= rna_find_function_def(func);
1785 fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
1789 rna_generate_static_parameter_prototypes(brna, srna, dfunc, f);
1796 static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
1798 char *strnest= "", *errnest= "";
1799 int len, freenest= 0;
1804 strnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> strnest");
1805 errnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> errnest");
1807 strcpy(strnest, "_"); strcat(strnest, nest);
1808 strcpy(errnest, "."); strcat(errnest, nest);
1813 switch(prop->type) {
1815 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1816 int i, defaultfound= 0;
1819 fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
1821 for(i=0; i<eprop->totitem; i++) {
1822 fprintf(f, "{%d, ", eprop->item[i].value);
1823 rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
1824 fprintf(f, "%d, ", eprop->item[i].icon);
1825 rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
1826 rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
1828 if(eprop->item[i].identifier[0])
1829 if(eprop->defaultvalue == eprop->item[i].value)
1833 fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
1836 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
1841 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum must have items defined.\n", srna->identifier, errnest, prop->identifier);
1846 case PROP_BOOLEAN: {
1847 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1850 if(prop->arraydimension && prop->totarraylength) {
1851 fprintf(f, "static int rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
1853 for(i=0; i<prop->totarraylength; i++) {
1854 if(bprop->defaultarray)
1855 fprintf(f, "%d", bprop->defaultarray[i]);
1857 fprintf(f, "%d", bprop->defaultvalue);
1858 if(i != prop->totarraylength-1)
1859 fprintf(f, ",\n\t");
1862 fprintf(f, "\n};\n\n");
1867 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1870 if(prop->arraydimension && prop->totarraylength) {
1871 fprintf(f, "static int rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
1873 for(i=0; i<prop->totarraylength; i++) {
1874 if(iprop->defaultarray)
1875 fprintf(f, "%d", iprop->defaultarray[i]);
1877 fprintf(f, "%d", iprop->defaultvalue);
1878 if(i != prop->totarraylength-1)
1879 fprintf(f, ",\n\t");
1882 fprintf(f, "\n};\n\n");
1887 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1890 if(prop->arraydimension && prop->totarraylength) {
1891 fprintf(f, "static float rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
1893 for(i=0; i<prop->totarraylength; i++) {
1894 if(fprop->defaultarray)
1895 rna_float_print(f, fprop->defaultarray[i]);
1897 rna_float_print(f, fprop->defaultvalue);
1898 if(i != prop->totarraylength-1)
1899 fprintf(f, ",\n\t");
1902 fprintf(f, "\n};\n\n");
1910 fprintf(f, "%s%s rna_%s%s_%s = {\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, strnest, prop->identifier);
1912 if(prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
1913 else fprintf(f, "\t{NULL, ");
1914 if(prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
1915 else fprintf(f, "NULL,\n");
1916 fprintf(f, "\t%d, ", prop->magic);
1917 rna_print_c_string(f, prop->identifier);
1918 fprintf(f, ", %d, ", prop->flag);
1919 rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
1920 rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
1921 fprintf(f, "%d,\n", prop->icon);
1922 fprintf(f, "\t%s, %s|%s, %s, %d, {%d, %d, %d}, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength);
1923 fprintf(f, "\t%s%s, %d, %s, %s,\n", (prop->flag & PROP_CONTEXT_UPDATE)? "(UpdateFunc)": "", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable));
1925 if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
1926 else fprintf(f, "\t0, -1");
1928 /* our own type - collections/arrays only */
1929 if(prop->srna) fprintf(f, ", &RNA_%s", (char*)prop->srna);
1930 else fprintf(f, ", NULL");
1934 switch(prop->type) {
1935 case PROP_BOOLEAN: {
1936 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1937 fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), rna_function_string(bprop->set), rna_function_string(bprop->getarray), rna_function_string(bprop->setarray), bprop->defaultvalue);
1938 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
1939 else fprintf(f, "NULL\n");
1943 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1944 fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range));
1945 rna_int_print(f, iprop->softmin); fprintf(f, ", ");
1946 rna_int_print(f, iprop->softmax); fprintf(f, ", ");
1947 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
1948 rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
1949 rna_int_print(f, iprop->step); fprintf(f, ", ");
1950 rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
1951 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
1952 else fprintf(f, "NULL\n");
1956 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1957 fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), rna_function_string(fprop->set), rna_function_string(fprop->getarray), rna_function_string(fprop->setarray), rna_function_string(fprop->range));
1958 rna_float_print(f, fprop->softmin); fprintf(f, ", ");
1959 rna_float_print(f, fprop->softmax); fprintf(f, ", ");
1960 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
1961 rna_float_print(f, fprop->hardmax); fprintf(f, ", ");
1962 rna_float_print(f, fprop->step); fprintf(f, ", ");
1963 rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
1964 rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
1965 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
1966 else fprintf(f, "NULL\n");
1970 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1971 fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength);
1972 rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
1976 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1977 fprintf(f, "\t%s, %s, %s, ", rna_function_string(eprop->get), rna_function_string(eprop->set), rna_function_string(eprop->itemf));
1979 fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
1981 fprintf(f, "NULL, ");
1982 fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
1985 case PROP_POINTER: {
1986 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1987 fprintf(f, "\t%s, %s, %s, ", rna_function_string(pprop->get), rna_function_string(pprop->set), rna_function_string(pprop->typef));
1988 if(pprop->type) fprintf(f, "&RNA_%s\n", (char*)pprop->type);
1989 else fprintf(f, "NULL\n");
1992 case PROP_COLLECTION: {
1993 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1994 fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), rna_function_string(cprop->next), rna_function_string(cprop->end), rna_function_string(cprop->get), rna_function_string(cprop->length), rna_function_string(cprop->lookupint), rna_function_string(cprop->lookupstring));
1995 if(cprop->item_type) fprintf(f, "&RNA_%s\n", (char*)cprop->item_type);
1996 else fprintf(f, "NULL\n");
2001 fprintf(f, "};\n\n");
2009 static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
2012 FunctionDefRNA *dfunc;
2013 PropertyRNA *prop, *parm;
2016 fprintf(f, "/* %s */\n", srna->name);
2018 for(prop= srna->cont.properties.first; prop; prop= prop->next)
2019 rna_generate_property(f, srna, NULL, prop);
2021 for(func= srna->functions.first; func; func= func->cont.next) {
2022 for(parm= func->cont.properties.first; parm; parm= parm->next)
2023 rna_generate_property(f, srna, func->identifier, parm);
2025 fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
2027 if(func->cont.next) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, ((FunctionRNA*)func->cont.next)->identifier);
2028 else fprintf(f, "\t{NULL, ");
2029 if(func->cont.prev) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier, ((FunctionRNA*)func->cont.prev)->identifier);
2030 else fprintf(f, "NULL,\n");
2032 fprintf(f, "\tNULL,\n");
2034 parm= func->cont.properties.first;
2035 if(parm) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
2036 else fprintf(f, "\t{NULL, ");
2038 parm= func->cont.properties.last;
2039 if(parm) fprintf(f, "(PropertyRNA*)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
2040 else fprintf(f, "NULL}},\n");
2043 rna_print_c_string(f, func->identifier);
2044 fprintf(f, ", %d, ", func->flag);
2045 rna_print_c_string(f, func->description); fprintf(f, ",\n");
2047 dfunc= rna_find_function_def(func);
2048 if(dfunc->gencall) fprintf(f, "\t%s,\n", dfunc->gencall);
2049 else fprintf(f, "\tNULL,\n");
2051 if(func->c_ret) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
2052 else fprintf(f, "\tNULL\n");
2058 fprintf(f, "StructRNA RNA_%s = {\n", srna->identifier);
2060 if(srna->cont.next) fprintf(f, "\t{(ContainerRNA *)&RNA_%s, ", ((StructRNA*)srna->cont.next)->identifier);
2061 else fprintf(f, "\t{NULL, ");
2062 if(srna->cont.prev) fprintf(f, "(ContainerRNA *)&RNA_%s,\n", ((StructRNA*)srna->cont.prev)->identifier);
2063 else fprintf(f, "NULL,\n");
2065 fprintf(f, "\tNULL,\n");
2067 prop= srna->cont.properties.first;
2068 if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
2069 else fprintf(f, "\t{NULL, ");
2071 prop= srna->cont.properties.last;
2072 if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
2073 else fprintf(f, "NULL}},\n");
2075 fprintf(f, "\tNULL,NULL,\n"); /* PyType - Cant initialize here */
2078 rna_print_c_string(f, srna->identifier);
2079 fprintf(f, ", %d, ", srna->flag);
2080 rna_print_c_string(f, srna->name);
2082 rna_print_c_string(f, srna->description);
2083 fprintf(f, ",\n\t%d,\n", srna->icon);
2085 prop= srna->nameproperty;
2088 while (base->base && base->base->nameproperty==prop)
2091 fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", base->identifier, prop->identifier);
2093 else fprintf(f, "\tNULL, ");
2095 prop= srna->iteratorproperty;
2097 while (base->base && base->base->iteratorproperty==prop)
2099 fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", base->identifier);
2101 if(srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
2102 else fprintf(f, "\tNULL,\n");
2104 if(srna->nested) fprintf(f, "\t&RNA_%s,\n", srna->nested->identifier);
2105 else fprintf(f, "\tNULL,\n");
2107 fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
2108 fprintf(f, "\t%s,\n", rna_function_string(srna->path));
2109 fprintf(f, "\t%s,\n", rna_function_string(srna->reg));
2110 fprintf(f, "\t%s,\n", rna_function_string(srna->unreg));
2111 fprintf(f, "\t%s,\n", rna_function_string(srna->idproperties));
2113 if(srna->reg && !srna->refine) {
2114 fprintf(stderr, "rna_generate_struct: %s has a register function, must also have refine function.\n", srna->identifier);
2118 func= srna->functions.first;
2119 if(func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, func->identifier);
2120 else fprintf(f, "\t{NULL, ");
2122 func= srna->functions.last;
2123 if(func) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
2124 else fprintf(f, "NULL}\n");
2131 typedef struct RNAProcessItem {
2134 void (*define)(BlenderRNA *brna);
2137 RNAProcessItem PROCESS_ITEMS[]= {
2138 {"rna_rna.c", NULL, RNA_def_rna},
2139 {"rna_ID.c", NULL, RNA_def_ID},
2140 {"rna_texture.c", NULL, RNA_def_texture},
2141 {"rna_action.c", "rna_action_api.c", RNA_def_action},
2142 {"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
2143 {"rna_animviz.c", NULL, RNA_def_animviz},
2144 {"rna_actuator.c", NULL, RNA_def_actuator},
2145 {"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
2146 {"rna_boid.c", NULL, RNA_def_boid},
2147 {"rna_brush.c", NULL, RNA_def_brush},
2148 {"rna_camera.c", NULL, RNA_def_camera},
2149 {"rna_cloth.c", NULL, RNA_def_cloth},
2150 {"rna_color.c", NULL, RNA_def_color},
2151 {"rna_constraint.c", NULL, RNA_def_constraint},
2152 {"rna_context.c", NULL, RNA_def_context},
2153 {"rna_controller.c", NULL, RNA_def_controller},
2154 {"rna_curve.c", NULL, RNA_def_curve},
2155 {"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
2156 {"rna_fluidsim.c", NULL, RNA_def_fluidsim},
2157 {"rna_gpencil.c", NULL, RNA_def_gpencil},
2158 {"rna_group.c", NULL, RNA_def_group},
2159 {"rna_image.c", "rna_image_api.c", RNA_def_image},
2160 {"rna_key.c", NULL, RNA_def_key},
2161 {"rna_lamp.c", NULL, RNA_def_lamp},
2162 {"rna_lattice.c", NULL, RNA_def_lattice},
2163 {"rna_main.c", "rna_main_api.c", RNA_def_main},
2164 {"rna_material.c", "rna_material_api.c", RNA_def_material},
2165 {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
2166 {"rna_meta.c", NULL, RNA_def_meta},
2167 {"rna_modifier.c", NULL, RNA_def_modifier},
2168 {"rna_nla.c", NULL, RNA_def_nla},
2169 {"rna_nodetree.c", NULL, RNA_def_nodetree},
2170 {"rna_object.c", "rna_object_api.c", RNA_def_object},
2171 {"rna_object_force.c", NULL, RNA_def_object_force},
2172 {"rna_packedfile.c", NULL, RNA_def_packedfile},
2173 {"rna_particle.c", NULL, RNA_def_particle},
2174 {"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
2175 {"rna_property.c", NULL, RNA_def_gameproperty},
2176 {"rna_render.c", NULL, RNA_def_render},
2177 {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
2178 {"rna_screen.c", NULL, RNA_def_screen},
2179 {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
2180 {"rna_sensor.c", NULL, RNA_def_sensor},
2181 {"rna_sequencer.c", NULL, RNA_def_sequencer},
2182 {"rna_smoke.c", NULL, RNA_def_smoke},
2183 {"rna_space.c", NULL, RNA_def_space},
2184 {"rna_test.c", NULL, RNA_def_test},
2185 {"rna_text.c", NULL, RNA_def_text},
2186 {"rna_timeline.c", NULL, RNA_def_timeline_marker},
2187 {"rna_sound.c", NULL, RNA_def_sound},
2188 {"rna_ui.c", "rna_ui_api.c", RNA_def_ui},
2189 {"rna_userdef.c", NULL, RNA_def_userdef},
2190 {"rna_vfont.c", NULL, RNA_def_vfont},
2191 {"rna_wm.c", "rna_wm_api.c", RNA_def_wm},
2192 {"rna_world.c", NULL, RNA_def_world},
2195 static void rna_generate(BlenderRNA *brna, FILE *f, char *filename, char *api_filename)
2199 FunctionDefRNA *dfunc;
2201 fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
2202 " Do not edit manually, changes will be overwritten. */\n\n"
2203 "#define RNA_RUNTIME\n\n");
2205 fprintf(f, "#include <float.h>\n");
2206 fprintf(f, "#include <limits.h>\n");
2207 fprintf(f, "#include <string.h>\n\n");
2208 fprintf(f, "#include <stddef.h>\n\n");
2210 fprintf(f, "#include \"DNA_ID.h\"\n");
2211 fprintf(f, "#include \"DNA_scene_types.h\"\n");
2213 fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
2215 fprintf(f, "#include \"BKE_context.h\"\n");
2216 fprintf(f, "#include \"BKE_library.h\"\n");
2217 fprintf(f, "#include \"BKE_main.h\"\n");
2218 fprintf(f, "#include \"BKE_report.h\"\n");
2219 fprintf(f, "#include \"BKE_utildefines.h\"\n\n");
2221 fprintf(f, "#include \"RNA_define.h\"\n");
2222 fprintf(f, "#include \"RNA_types.h\"\n");
2223 fprintf(f, "#include \"rna_internal.h\"\n\n");
2225 rna_generate_prototypes(brna, f);
2227 fprintf(f, "#include \"%s\"\n", filename);
2229 fprintf(f, "#include \"%s\"\n", api_filename);
2232 fprintf(f, "/* Autogenerated Functions */\n\n");
2234 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2235 if(!filename || ds->filename == filename) {
2236 rna_generate_property_prototypes(brna, ds->srna, f);
2237 rna_generate_function_prototypes(brna, ds->srna, f);
2241 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2242 if(!filename || ds->filename == filename)
2243 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2244 rna_def_property_funcs(f, ds->srna, dp);
2246 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2247 if(!filename || ds->filename == filename) {
2248 for(dfunc=ds->functions.first; dfunc; dfunc= dfunc->cont.next)
2249 rna_def_function_funcs(f, ds, dfunc);
2251 rna_generate_static_function_prototypes(brna, ds->srna, f);
2255 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2256 if(!filename || ds->filename == filename)
2257 rna_generate_struct(brna, ds->srna, f);
2259 if(strcmp(filename, "rna_ID.c") == 0) {
2260 /* this is ugly, but we cannot have c files compiled for both
2261 * makesrna and blender with some build systems at the moment */
2262 fprintf(f, "#include \"rna_define.c\"\n\n");
2264 rna_generate_blender(brna, f);
2268 static void rna_generate_header(BlenderRNA *brna, FILE *f)
2274 fprintf(f, "\n#ifndef __RNA_BLENDER_H__\n");
2275 fprintf(f, "#define __RNA_BLENDER_H__\n\n");
2277 fprintf(f, "/* Automatically generated function declarations for the Data API.\n"
2278 " Do not edit manually, changes will be overwritten. */\n\n");
2280 fprintf(f, "#include \"RNA_types.h\"\n\n");
2282 fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
2284 fprintf(f, "#define FOREACH_BEGIN(property, sptr, itemptr) \\\n");
2285 fprintf(f, " { \\\n");
2286 fprintf(f, " CollectionPropertyIterator rna_macro_iter; \\\n");
2287 fprintf(f, " for(property##_begin(&rna_macro_iter, sptr); rna_macro_iter.valid; property##_next(&rna_macro_iter)) { \\\n");
2288 fprintf(f, " itemptr= rna_macro_iter.ptr;\n\n");
2290 fprintf(f, "#define FOREACH_END(property) \\\n");
2291 fprintf(f, " } \\\n");
2292 fprintf(f, " property##_end(&rna_macro_iter); \\\n");
2293 fprintf(f, " }\n\n");
2295 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2298 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2301 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
2306 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2307 rna_def_property_funcs_header(f, ds->srna, dp);
2310 fprintf(f, "#ifdef __cplusplus\n}\n#endif\n\n");
2312 fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n\n");
2315 static const char *cpp_classes = ""
2317 "#include <string>\n"
2321 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
2322 " bool sname::identifier(void) { return (bool)sname##_##identifier##_get(&ptr); }\n"
2324 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2325 " Array<int,size> sname::identifier(void) \\\n"
2326 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2328 "#define INT_PROPERTY(sname, identifier) \\\n"
2329 " int sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2331 "#define INT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2332 " Array<int,size> sname::identifier(void) \\\n"
2333 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2335 "#define FLOAT_PROPERTY(sname, identifier) \\\n"
2336 " float sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2338 "#define FLOAT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2339 " Array<float,size> sname::identifier(void) \\\n"
2340 " { Array<float, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2342 "#define ENUM_PROPERTY(type, sname, identifier) \\\n"
2343 " sname::type sname::identifier(void) { return (type)sname##_##identifier##_get(&ptr); }\n"
2345 "#define STRING_PROPERTY(sname, identifier) \\\n"
2346 " std::string sname::identifier(void) { \\\n"
2347 " int len= sname##_##identifier##_length(&ptr); \\\n"
2348 " std::string str; str.resize(len); \\\n"
2349 " sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
2351 "#define POINTER_PROPERTY(type, sname, identifier) \\\n"
2352 " type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
2354 "#define COLLECTION_PROPERTY(type, sname, identifier) \\\n"
2355 " typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
2356 " sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
2357 " Collection<sname, type, sname##_##identifier##_begin, \\\n"
2358 " sname##_##identifier##_next, sname##_##identifier##_end> identifier;\n"
2362 " Pointer(const PointerRNA& p) : ptr(p) { }\n"
2363 " operator const PointerRNA&() { return ptr; }\n"
2364 " bool is_a(StructRNA *type) { return RNA_struct_is_a(&ptr, type); }\n"
2365 " operator void*() { return ptr.data; }\n"
2366 " operator bool() { return ptr.data != NULL; }\n"
2368 " PointerRNA ptr;\n"
2372 "template<typename T, int Tsize>\n"
2376 " operator T*() { return data; }\n"
2379 "typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
2380 "typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
2381 "typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
2383 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2384 "class CollectionIterator {\n"
2386 " CollectionIterator() : t(iter.ptr), init(false) { iter.valid= false; }\n"
2387 " ~CollectionIterator(void) { if(init) Tend(&iter); };\n"
2388 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator=(const CollectionIterator<T, Tbegin, Tnext, Tend>& copy)\n"
2389 " { if(init) Tend(&iter); iter= copy.iter; if(iter.internal) iter.internal= MEM_dupallocN(iter.internal); t= copy.t; init= copy.init; return *this; }\n"
2391 " operator bool(void)\n"
2392 " { return iter.valid != 0; }\n"
2393 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator++() { Tnext(&iter); t = T(iter.ptr); return *this; }\n"
2394 " T& operator*(void) { return t; }\n"
2395 " T* operator->(void) { return &t; }\n"
2396 " bool operator==(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid == other.iter.valid; }\n"
2397 " bool operator!=(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid != other.iter.valid; }\n"
2399 " void begin(const Pointer& ptr)\n"
2400 " { if(init) Tend(&iter); Tbegin(&iter, (PointerRNA*)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
2403 " CollectionPropertyIterator iter;\n"
2408 "template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2409 "class Collection {\n"
2411 " Collection(const PointerRNA& p) : ptr(p) {}\n"
2413 " CollectionIterator<T, Tbegin, Tnext, Tend> begin()\n"
2414 " { CollectionIterator<T, Tbegin, Tnext, Tend> iter; iter.begin(ptr); return iter; }\n"
2415 " CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
2416 " { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
2419 " PointerRNA ptr;\n"
2423 static void rna_generate_header_cpp(BlenderRNA *brna, FILE *f)
2429 fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
2430 fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
2432 fprintf(f, "/* Automatically generated classes for the Data API.\n"
2433 " Do not edit manually, changes will be overwritten. */\n\n");
2435 fprintf(f, "#include \"RNA_blender.h\"\n");
2436 fprintf(f, "#include \"RNA_types.h\"\n");
2438 fprintf(f, "%s", cpp_classes);
2440 fprintf(f, "/**************** Declarations ****************/\n\n");
2442 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2443 fprintf(f, "class %s;\n", ds->srna->identifier);
2446 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2449 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2451 fprintf(f, "class %s : public %s {\n", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2452 fprintf(f, "public:\n");
2453 fprintf(f, "\t%s(const PointerRNA& ptr) :\n\t\t%s(ptr)", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2454 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2455 if(!(dp->prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN)))
2456 if(dp->prop->type == PROP_COLLECTION)
2457 fprintf(f, ",\n\t\t%s(ptr)", dp->prop->identifier);
2458 fprintf(f, "\n\t\t{}\n\n");
2460 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2461 rna_def_property_funcs_header_cpp(f, ds->srna, dp);
2462 fprintf(f, "};\n\n");
2466 fprintf(f, "/**************** Implementation ****************/\n");
2468 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2469 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2470 rna_def_property_funcs_impl_cpp(f, ds->srna, dp);
2475 fprintf(f, "}\n\n#endif /* __RNA_BLENDER_CPP_H__ */\n\n");
2478 static void make_bad_file(char *file, int line)
2480 FILE *fp= fopen(file, "w");
2481 fprintf(fp, "#error \"Error! can't make correct RNA file from %s:%d, STUPID!\"\n", __FILE__, line);
2485 static int rna_preprocess(char *outfile)
2496 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2497 if(PROCESS_ITEMS[i].define) {
2498 PROCESS_ITEMS[i].define(brna);
2500 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2502 ds->filename= PROCESS_ITEMS[i].filename;
2509 /* create RNA_blender_cpp.h */
2510 strcpy(deffile, outfile);
2511 strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
2513 status= (DefRNA.error != 0);
2516 make_bad_file(deffile, __LINE__);
2519 file = fopen(deffile, "w");
2522 printf ("Unable to open file: %s\n", deffile);
2526 rna_generate_header_cpp(brna, file);
2528 status= (DefRNA.error != 0);
2532 replace_if_different(deffile);
2536 /* create rna_gen_*.c files */
2537 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2538 strcpy(deffile, outfile);
2539 strcat(deffile, PROCESS_ITEMS[i].filename);
2540 deffile[strlen(deffile)-2] = '\0';
2541 strcat(deffile, "_gen.c" TMP_EXT);
2544 make_bad_file(deffile, __LINE__);
2547 file = fopen(deffile, "w");
2550 printf ("Unable to open file: %s\n", deffile);
2554 rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
2556 status= (DefRNA.error != 0);
2560 replace_if_different(deffile);
2563 /* create RNA_blender.h */
2564 strcpy(deffile, outfile);
2565 strcat(deffile, "RNA_blender.h" TMP_EXT);
2568 make_bad_file(deffile, __LINE__);
2571 file = fopen(deffile, "w");
2574 printf ("Unable to open file: %s\n", deffile);
2578 rna_generate_header(brna, file);
2580 status= (DefRNA.error != 0);
2584 replace_if_different(deffile);
2587 RNA_define_free(brna);
2593 static void mem_error_cb(const char *errorStr)
2595 fprintf(stderr, "%s", errorStr);
2599 int main(int argc, char **argv)
2601 int totblock, return_status = 0;
2604 printf("Usage: %s outdirectory/\n", argv[0]);
2608 printf("Running makesrna, program versions %s\n", RNA_VERSION_DATE);
2609 return_status= rna_preprocess(argv[1]);
2612 totblock= MEM_get_memory_blocks_in_use();
2614 printf("Error Totblock: %d\n",totblock);
2615 MEM_set_error_callback(mem_error_cb);
2619 return return_status;