2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation (2008).
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/makesrna.c
35 #include "MEM_guardedalloc.h"
37 #include "RNA_access.h"
38 #include "RNA_define.h"
39 #include "RNA_types.h"
41 #include "rna_internal.h"
43 #define RNA_VERSION_DATE "FIXME-RNA_VERSION_DATE"
47 #define snprintf _snprintf
51 /* Replace if different */
52 #define TMP_EXT ".tmp"
55 /* copied from BLI_file_older */
57 static int file_older(const char *file1, const char *file2)
60 // printf("compare: %s %s\n", file1, file2);
62 if(stat(file1, &st1)) return 0;
63 if(stat(file2, &st2)) return 0;
65 return (st1.st_mtime < st2.st_mtime);
67 static const char *makesrna_path= NULL;
69 static int replace_if_different(char *tmpfile, const char *dep_files[])
71 // return 0; // use for testing had edited rna
75 FILE *file_test= fopen(orgfile, "rb"); \
78 if(fp_org) fclose(fp_org); \
79 if(fp_new) fclose(fp_new); \
80 if(remove(orgfile) != 0) { \
81 fprintf(stderr, "%s:%d, Remove Error (%s): \"%s\"\n", __FILE__, __LINE__, strerror(errno), orgfile); \
86 if(rename(tmpfile, orgfile) != 0) { \
87 fprintf(stderr, "%s:%d, Rename Error (%s): \"%s\" -> \"%s\"\n", __FILE__, __LINE__, strerror(errno), tmpfile, orgfile); \
95 FILE *fp_new= NULL, *fp_org= NULL;
97 char *arr_new, *arr_org;
102 strcpy(orgfile, tmpfile);
103 orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* strip '.tmp' */
105 fp_org= fopen(orgfile, "rb");
112 /* XXX, trick to work around dependancy problem
113 * assumes dep_files is in the same dir as makesrna.c, which is true for now. */
116 /* first check if makesrna.c is newer then generated files
117 * for development on makesrna.c you may want to disable this */
118 if(file_older(orgfile, __FILE__)) {
122 if(file_older(orgfile, makesrna_path)) {
126 /* now check if any files we depend on are newer then any generated files */
129 for(pass=0; dep_files[pass]; pass++) {
130 char from_path[4096]= __FILE__;
134 p1= strrchr(from_path, '/');
135 p2= strrchr(from_path, '\\');
136 strcpy((p1 > p2 ? p1 : p2)+1, dep_files[pass]);
137 /* account for build deps, if makesrna.c (this file) is newer */
138 if(file_older(orgfile, from_path)) {
144 /* XXX end dep trick */
147 fp_new= fopen(tmpfile, "rb");
150 /* shouldn't happen, just to be safe */
151 fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
156 fseek(fp_new, 0L, SEEK_END); len_new = ftell(fp_new); fseek(fp_new, 0L, SEEK_SET);
157 fseek(fp_org, 0L, SEEK_END); len_org = ftell(fp_org); fseek(fp_org, 0L, SEEK_SET);
160 if(len_new != len_org) {
166 /* now compare the files... */
167 arr_new= MEM_mallocN(sizeof(char)*len_new, "rna_cmp_file_new");
168 arr_org= MEM_mallocN(sizeof(char)*len_org, "rna_cmp_file_org");
170 if(fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
171 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
172 if(fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
173 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
178 cmp= memcmp(arr_new, arr_org, len_new);
194 /* Helper to solve keyword problems with C/C++ */
196 static const char *rna_safe_id(const char *id)
198 if(strcmp(id, "default") == 0)
199 return "default_value";
200 else if(strcmp(id, "operator") == 0)
201 return "operator_value";
208 static int cmp_struct(const void *a, const void *b)
210 const StructRNA *structa= *(const StructRNA**)a;
211 const StructRNA *structb= *(const StructRNA**)b;
213 return strcmp(structa->identifier, structb->identifier);
216 static int cmp_property(const void *a, const void *b)
218 const PropertyRNA *propa= *(const PropertyRNA**)a;
219 const PropertyRNA *propb= *(const PropertyRNA**)b;
221 if(strcmp(propa->identifier, "rna_type") == 0) return -1;
222 else if(strcmp(propb->identifier, "rna_type") == 0) return 1;
224 if(strcmp(propa->identifier, "name") == 0) return -1;
225 else if(strcmp(propb->identifier, "name") == 0) return 1;
227 return strcmp(propa->name, propb->name);
230 static int cmp_def_struct(const void *a, const void *b)
232 const StructDefRNA *dsa= *(const StructDefRNA**)a;
233 const StructDefRNA *dsb= *(const StructDefRNA**)b;
235 return cmp_struct(&dsa->srna, &dsb->srna);
238 static int cmp_def_property(const void *a, const void *b)
240 const PropertyDefRNA *dpa= *(const PropertyDefRNA**)a;
241 const PropertyDefRNA *dpb= *(const PropertyDefRNA**)b;
243 return cmp_property(&dpa->prop, &dpb->prop);
246 static void rna_sortlist(ListBase *listbase, int(*cmp)(const void*, const void*))
252 if(listbase->first == listbase->last)
255 for(size=0, link=listbase->first; link; link=link->next)
258 array= MEM_mallocN(sizeof(void*)*size, "rna_sortlist");
259 for(a=0, link=listbase->first; link; link=link->next, a++)
262 qsort(array, size, sizeof(void*), cmp);
264 listbase->first= listbase->last= NULL;
265 for(a=0; a<size; a++) {
267 link->next= link->prev= NULL;
268 rna_addtail(listbase, link);
276 static void rna_print_c_string(FILE *f, const char *str)
278 static const char *escape[] = {"\''", "\"\"", "\??", "\\\\","\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", NULL};
287 for(i=0; str[i]; i++) {
288 for(j=0; escape[j]; j++)
289 if(str[i] == escape[j][0])
292 if(escape[j]) fprintf(f, "\\%c", escape[j][1]);
293 else fprintf(f, "%c", str[i]);
298 static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
300 if(dp->dnastructfromname && dp->dnastructfromprop)
301 fprintf(f, " %s *data= (%s*)(((%s*)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname, dp->dnastructfromname, dp->dnastructfromprop);
303 fprintf(f, " %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
306 static void rna_print_id_get(FILE *f, PropertyDefRNA *dp)
308 fprintf(f, " ID *id= ptr->id.data;\n");
311 static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
317 snprintf(buffer, sizeof(buffer), "%s_%s_%s", structname, propname, type);
318 result= MEM_callocN(sizeof(char)*strlen(buffer)+1, "rna_alloc_function_name");
319 strcpy(result, buffer);
321 alloc= MEM_callocN(sizeof(AllocDefRNA), "AllocDefRNA");
323 rna_addtail(&DefRNA.allocs, alloc);
328 static StructRNA *rna_find_struct(const char *identifier)
332 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
333 if(strcmp(ds->srna->identifier, identifier)==0)
339 static const char *rna_find_type(const char *type)
343 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
344 if(ds->dnaname && strcmp(ds->dnaname, type)==0)
345 return ds->srna->identifier;
350 static const char *rna_find_dna_type(const char *type)
354 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
355 if(strcmp(ds->srna->identifier, type)==0)
361 static const char *rna_type_type_name(PropertyRNA *prop)
371 if(prop->flag & PROP_THICK_WRAP) {
375 return "const char*";
382 static const char *rna_type_type(PropertyRNA *prop)
386 type= rna_type_type_name(prop);
394 static const char *rna_type_struct(PropertyRNA *prop)
398 type= rna_type_type_name(prop);
406 static const char *rna_parameter_type_name(PropertyRNA *parm)
410 type= rna_type_type_name(parm);
417 PointerPropertyRNA *pparm= (PointerPropertyRNA*)parm;
419 if(parm->flag & PROP_RNAPTR)
422 return rna_find_dna_type((const char *)pparm->type);
424 case PROP_COLLECTION: {
428 return "<error, no type specified>";
432 static int rna_enum_bitmask(PropertyRNA *prop)
434 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
438 for(a=0; a<eprop->totitem; a++)
439 if(eprop->item[a].identifier[0])
440 mask |= eprop->item[a].value;
446 static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
448 if(prop->type == PROP_FLOAT && (prop->subtype==PROP_COLOR || prop->subtype==PROP_COLOR_GAMMA))
449 if(strcmp(dp->dnatype, "float") != 0 && strcmp(dp->dnatype, "double") != 0)
455 static const char *rna_function_string(void *func)
457 return (func)? (const char*)func: "NULL";
460 static void rna_float_print(FILE *f, float num)
462 if(num == -FLT_MAX) fprintf(f, "-FLT_MAX");
463 else if(num == FLT_MAX) fprintf(f, "FLT_MAX");
464 else if((int)num == num) fprintf(f, "%.1ff", num);
465 else fprintf(f, "%.10ff", num);
468 static void rna_int_print(FILE *f, int num)
470 if(num == INT_MIN) fprintf(f, "INT_MIN");
471 else if(num == INT_MAX) fprintf(f, "INT_MAX");
472 else fprintf(f, "%d", num);
475 static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
479 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
483 if(!dp->dnastructname || !dp->dnaname) {
484 fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
490 if(dp->dnatype && *dp->dnatype) {
492 if(prop->type == PROP_FLOAT) {
493 if(IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
494 if(prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */
495 fprintf(stderr, "rna_def_property_get_func1: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type));
501 else if(prop->type == PROP_INT || prop->type == PROP_BOOLEAN || prop->type == PROP_ENUM) {
502 if(IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
503 fprintf(stderr, "rna_def_property_get_func2: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type));
512 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
516 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
517 fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
520 fprintf(f, " %s(ptr, value);\n", manualfunc);
523 const PropertySubType subtype= prop->subtype;
524 const char *string_copy_func= (subtype==PROP_FILEPATH || subtype==PROP_DIRPATH || subtype==PROP_FILENAME) ? "BLI_strncpy" : "BLI_strncpy_utf8";
526 rna_print_data_get(f, dp);
528 fprintf(f, " %s(value, data->%s, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
530 fprintf(f, " %s(value, data->%s, sizeof(data->%s));\n", string_copy_func, dp->dnaname, dp->dnaname);
536 fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func);
539 fprintf(f, " return %s(ptr);\n", manualfunc);
542 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
543 rna_print_data_get(f, dp);
544 if(dp->dnapointerlevel == 0)
545 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, &data->%s);\n", (const char*)pprop->type, dp->dnaname);
547 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, data->%s);\n", (const char*)pprop->type, dp->dnaname);
552 case PROP_COLLECTION: {
553 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
555 fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
558 if(strcmp(manualfunc, "rna_iterator_listbase_get") == 0 ||
559 strcmp(manualfunc, "rna_iterator_array_get") == 0 ||
560 strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0)
561 fprintf(f, " return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", (cprop->item_type)? (const char*)cprop->item_type: "UnknownType", manualfunc);
563 fprintf(f, " return %s(iter);\n", manualfunc);
569 if(prop->arraydimension) {
570 if(prop->flag & PROP_DYNAMIC)
571 fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
573 fprintf(f, "void %s(PointerRNA *ptr, %s values[%u])\n", func, rna_type_type(prop), prop->totarraylength);
577 fprintf(f, " %s(ptr, values);\n", manualfunc);
580 rna_print_data_get(f, dp);
582 if(prop->flag & PROP_DYNAMIC) {
583 char *lenfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get_length");
584 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
585 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
586 fprintf(f, " for(i=0; i<len; i++) {\n");
590 fprintf(f, " int i;\n\n");
591 fprintf(f, " for(i=0; i<%u; i++) {\n", prop->totarraylength);
594 if(dp->dnaarraylength == 1) {
595 if(prop->type == PROP_BOOLEAN && dp->booleanbit)
596 fprintf(f, " values[i]= %s((data->%s & (%d<<i)) != 0);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
598 fprintf(f, " values[i]= (%s)%s((&data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
601 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
602 fprintf(f, " values[i]= %s((data->%s[i] & ", (dp->booleannegative)? "!": "", dp->dnaname);
603 rna_int_print(f, dp->booleanbit);
604 fprintf(f, ") != 0);\n");
606 else if(rna_color_quantize(prop, dp))
607 fprintf(f, " values[i]= (%s)(data->%s[i]*(1.0f/255.0f));\n", rna_type_type(prop), dp->dnaname);
609 fprintf(f, " values[i]= (%s)%s(((%s*)data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname);
611 fprintf(f, " values[i]= (%s)%s((data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
618 fprintf(f, "%s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
622 fprintf(f, " return %s(ptr);\n", manualfunc);
625 rna_print_data_get(f, dp);
626 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
627 fprintf(f, " return %s(((data->%s) & ", (dp->booleannegative)? "!": "", dp->dnaname);
628 rna_int_print(f, dp->booleanbit);
629 fprintf(f, ") != 0);\n");
631 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
632 fprintf(f, " return ((data->%s) & ", dp->dnaname);
633 rna_int_print(f, rna_enum_bitmask(prop));
637 fprintf(f, " return (%s)%s(data->%s);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
648 /* defined min/max variables to be used by rna_clamp_value() */
649 static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
651 if(prop->type == PROP_FLOAT) {
652 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
654 fprintf(f, " float prop_clamp_min, prop_clamp_max;\n");
655 fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max);\n", rna_function_string(fprop->range));
658 else if(prop->type == PROP_INT) {
659 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
661 fprintf(f, " int prop_clamp_min, prop_clamp_max;\n");
662 fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max);\n", rna_function_string(iprop->range));
667 static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
669 if(prop->type == PROP_INT) {
670 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
672 if(iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
673 if(array) fprintf(f, "CLAMPIS(values[i], ");
674 else fprintf(f, "CLAMPIS(value, ");
676 fprintf(f, "prop_clamp_min, prop_clamp_max);");
679 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
680 rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
685 else if(prop->type == PROP_FLOAT) {
686 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
688 if(fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
689 if(array) fprintf(f, "CLAMPIS(values[i], ");
690 else fprintf(f, "CLAMPIS(value, ");
692 fprintf(f, "prop_clamp_min, prop_clamp_max);");
695 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
696 rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
703 fprintf(f, "values[i];\n");
705 fprintf(f, "value;\n");
708 static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
712 if(!(prop->flag & PROP_EDITABLE))
714 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
718 if(!dp->dnastructname || !dp->dnaname) {
719 if(prop->flag & PROP_EDITABLE) {
720 fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
727 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set");
731 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
732 fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func);
735 fprintf(f, " %s(ptr, value);\n", manualfunc);
738 const PropertySubType subtype= prop->subtype;
739 const char *string_copy_func= (subtype==PROP_FILEPATH || subtype==PROP_DIRPATH || subtype==PROP_FILENAME) ? "BLI_strncpy" : "BLI_strncpy_utf8";
741 rna_print_data_get(f, dp);
743 fprintf(f, " %s(data->%s, value, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
745 fprintf(f, " %s(data->%s, value, sizeof(data->%s));\n", string_copy_func, dp->dnaname, dp->dnaname);
751 fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func);
754 fprintf(f, " %s(ptr, value);\n", manualfunc);
757 rna_print_data_get(f, dp);
759 if(prop->flag & PROP_ID_SELF_CHECK) {
760 rna_print_id_get(f, dp);
761 fprintf(f, " if(id==value.data) return;\n\n");
764 if(prop->flag & PROP_ID_REFCOUNT) {
765 fprintf(f, "\n if(data->%s)\n", dp->dnaname);
766 fprintf(f, " id_us_min((ID*)data->%s);\n", dp->dnaname);
767 fprintf(f, " if(value.data)\n");
768 fprintf(f, " id_us_plus((ID*)value.data);\n\n");
771 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
772 StructRNA *type= rna_find_struct((const char*)pprop->type);
773 if(type && (type->flag & STRUCT_ID)) {
774 fprintf(f, " if(value.data)\n");
775 fprintf(f, " id_lib_extern((ID*)value.data);\n\n");
779 fprintf(f, " data->%s= value.data;\n", dp->dnaname);
786 if(prop->arraydimension) {
787 if(prop->flag & PROP_DYNAMIC)
788 fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
790 fprintf(f, "void %s(PointerRNA *ptr, const %s values[%u])\n", func, rna_type_type(prop), prop->totarraylength);
794 fprintf(f, " %s(ptr, values);\n", manualfunc);
797 rna_print_data_get(f, dp);
799 if(prop->flag & PROP_DYNAMIC) {
800 char *lenfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set_length");
801 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
802 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
803 rna_clamp_value_range(f, prop);
804 fprintf(f, " for(i=0; i<len; i++) {\n");
808 fprintf(f, " int i;\n\n");
809 rna_clamp_value_range(f, prop);
810 fprintf(f, " for(i=0; i<%u; i++) {\n", prop->totarraylength);
813 if(dp->dnaarraylength == 1) {
814 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
815 fprintf(f, " if(%svalues[i]) data->%s |= (%d<<i);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
816 fprintf(f, " else data->%s &= ~(%d<<i);\n", dp->dnaname, dp->booleanbit);
819 fprintf(f, " (&data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
820 rna_clamp_value(f, prop, 1);
824 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
825 fprintf(f, " if(%svalues[i]) data->%s[i] |= ", (dp->booleannegative)? "!": "", dp->dnaname);
826 rna_int_print(f, dp->booleanbit);
828 fprintf(f, " else data->%s[i] &= ~", dp->dnaname);
829 rna_int_print(f, dp->booleanbit);
832 else if(rna_color_quantize(prop, dp)) {
833 fprintf(f, " data->%s[i]= FTOCHAR(values[i]);\n", dp->dnaname);
837 fprintf(f, " ((%s*)data->%s)[i]= %s", dp->dnatype, dp->dnaname, (dp->booleannegative)? "!": "");
839 fprintf(f, " (data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
840 rna_clamp_value(f, prop, 1);
848 fprintf(f, "void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
852 fprintf(f, " %s(ptr, value);\n", manualfunc);
855 rna_print_data_get(f, dp);
856 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
857 fprintf(f, " if(%svalue) data->%s |= ", (dp->booleannegative)? "!": "", dp->dnaname);
858 rna_int_print(f, dp->booleanbit);
860 fprintf(f, " else data->%s &= ~", dp->dnaname);
861 rna_int_print(f, dp->booleanbit);
864 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
865 fprintf(f, " data->%s &= ~", dp->dnaname);
866 rna_int_print(f, rna_enum_bitmask(prop));
868 fprintf(f, " data->%s |= value;\n", dp->dnaname);
871 rna_clamp_value_range(f, prop);
872 fprintf(f, " data->%s= %s", dp->dnaname, (dp->booleannegative)? "!": "");
873 rna_clamp_value(f, prop, 0);
884 static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
888 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
891 if(prop->type == PROP_STRING) {
893 if(!dp->dnastructname || !dp->dnaname) {
894 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
900 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
902 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
905 fprintf(f, " return %s(ptr);\n", manualfunc);
908 rna_print_data_get(f, dp);
909 fprintf(f, " return strlen(data->%s);\n", dp->dnaname);
913 else if(prop->type == PROP_COLLECTION) {
915 if(prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed)|| !dp->dnaname)) {
916 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
922 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
924 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
927 fprintf(f, " return %s(ptr);\n", manualfunc);
930 rna_print_data_get(f, dp);
931 if(dp->dnalengthname)
932 fprintf(f, " return (data->%s == NULL)? 0: data->%s;\n", dp->dnaname, dp->dnalengthname);
934 fprintf(f, " return (data->%s == NULL)? 0: %d;\n", dp->dnaname, dp->dnalengthfixed);
942 static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
944 char *func, *getfunc;
946 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
950 if(!dp->dnastructname || !dp->dnaname) {
951 fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
957 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "begin");
959 fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
963 rna_print_data_get(f, dp);
965 fprintf(f, "\n memset(iter, 0, sizeof(*iter));\n");
966 fprintf(f, " iter->parent= *ptr;\n");
967 fprintf(f, " iter->prop= (PropertyRNA*)&rna_%s_%s;\n", srna->identifier, prop->identifier);
969 if(dp->dnalengthname || dp->dnalengthfixed) {
971 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
974 if(dp->dnalengthname)
975 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);
977 fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed);
982 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
983 else if(dp->dnapointerlevel == 0)
984 fprintf(f, "\n rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname);
986 fprintf(f, "\n rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname);
989 getfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
991 fprintf(f, "\n if(iter->valid)\n");
992 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
1000 static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc, const char *nextfunc)
1002 /* note on indices, this is for external functions and ignores skipped values.
1003 * so the the index can only be checked against the length when there is no 'skip' funcion. */
1006 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
1010 if(!dp->dnastructname || !dp->dnaname)
1013 /* only supported in case of standard next functions */
1014 if(strcmp(nextfunc, "rna_iterator_array_next") == 0);
1015 else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0);
1019 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_int");
1021 fprintf(f, "int %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func);
1025 fprintf(f, "\n return %s(ptr, index, r_ptr);\n", manualfunc);
1026 fprintf(f, "}\n\n");
1030 fprintf(f, " int found= 0;\n");
1031 fprintf(f, " CollectionPropertyIterator iter;\n\n");
1033 fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1034 fprintf(f, " if(iter.valid){\n");
1036 if(strcmp(nextfunc, "rna_iterator_array_next") == 0) {
1037 fprintf(f, " ArrayIterator *internal= iter.internal;\n");
1038 fprintf(f, " if(index < 0 || index >= internal->length) {\n");
1039 fprintf(f, "#ifdef __GNUC__\n");
1040 fprintf(f, " printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, index);\n");
1041 fprintf(f, "#else\n");
1042 fprintf(f, " printf(\"Array iterator out of range: (index %%d)\\n\", index);\n");
1043 fprintf(f, "#endif\n");
1045 fprintf(f, " else if(internal->skip) {\n");
1046 fprintf(f, " while(index-- > 0 && iter.valid) {\n");
1047 fprintf(f, " rna_iterator_array_next(&iter);\n");
1049 fprintf(f, " found= (index == -1 && iter.valid);\n");
1051 fprintf(f, " else {\n");
1052 fprintf(f, " internal->ptr += internal->itemsize*index;\n");
1053 fprintf(f, " found= 1;\n");
1056 else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
1057 fprintf(f, " ListBaseIterator *internal= iter.internal;\n");
1058 fprintf(f, " if(internal->skip) {\n");
1059 fprintf(f, " while(index-- > 0 && iter.valid) {\n");
1060 fprintf(f, " rna_iterator_listbase_next(&iter);\n");
1062 fprintf(f, " found= (index == -1 && iter.valid);\n");
1064 fprintf(f, " else {\n");
1065 fprintf(f, " while(index-- > 0 && internal->link)\n");
1066 fprintf(f, " internal->link= internal->link->next;\n");
1067 fprintf(f, " found= (index == -1 && internal->link);\n");
1071 fprintf(f, " if(found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, rna_safe_id(prop->identifier));
1072 fprintf(f, " }\n\n");
1073 fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1075 fprintf(f, " return found;\n");
1078 rna_print_data_get(f, dp);
1079 item_type= (cprop->item_type)? (const char*)cprop->item_type: "UnknownType";
1081 if(dp->dnalengthname || dp->dnalengthfixed) {
1082 if(dp->dnalengthname)
1083 fprintf(f, "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), data->%s, index);\n", item_type, dp->dnaname, dp->dnaname, dp->dnalengthname);
1085 fprintf(f, "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), %d, index);\n", item_type, dp->dnaname, dp->dnaname, dp->dnalengthfixed);
1088 if(dp->dnapointerlevel == 0)
1089 fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, &data->%s, index);\n", item_type, dp->dnaname);
1091 fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, data->%s, index);\n", item_type, dp->dnaname);
1095 fprintf(f, "}\n\n");
1100 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1102 char *func, *getfunc;
1104 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
1110 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "next");
1112 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1114 fprintf(f, " %s(iter);\n", manualfunc);
1116 getfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
1118 fprintf(f, "\n if(iter->valid)\n");
1119 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
1121 fprintf(f, "}\n\n");
1126 static char *rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1130 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
1133 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "end");
1135 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1138 fprintf(f, " %s(iter);\n", manualfunc);
1139 fprintf(f, "}\n\n");
1144 static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
1146 if(dp->dnapointerlevel != 0)
1148 if(!dp->dnatype || !dp->dnaname || !dp->dnastructname)
1151 if(strcmp(dp->dnatype, "char") == 0) {
1152 prop->rawtype= PROP_RAW_CHAR;
1153 prop->flag |= PROP_RAW_ACCESS;
1155 else if(strcmp(dp->dnatype, "short") == 0) {
1156 prop->rawtype= PROP_RAW_SHORT;
1157 prop->flag |= PROP_RAW_ACCESS;
1159 else if(strcmp(dp->dnatype, "int") == 0) {
1160 prop->rawtype= PROP_RAW_INT;
1161 prop->flag |= PROP_RAW_ACCESS;
1163 else if(strcmp(dp->dnatype, "float") == 0) {
1164 prop->rawtype= PROP_RAW_FLOAT;
1165 prop->flag |= PROP_RAW_ACCESS;
1167 else if(strcmp(dp->dnatype, "double") == 0) {
1168 prop->rawtype= PROP_RAW_DOUBLE;
1169 prop->flag |= PROP_RAW_ACCESS;
1173 static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
1175 PropertyDefRNA *dp= rna_find_struct_property_def(srna, prop);
1177 fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype);
1180 static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1186 switch(prop->type) {
1187 case PROP_BOOLEAN: {
1188 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1190 if(!prop->arraydimension) {
1191 if(!bprop->get && !bprop->set && !dp->booleanbit)
1192 rna_set_raw_property(dp, prop);
1194 bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)bprop->get);
1195 bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)bprop->set);
1198 bprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)bprop->getarray);
1199 bprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)bprop->setarray);
1204 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1206 if(!prop->arraydimension) {
1207 if(!iprop->get && !iprop->set)
1208 rna_set_raw_property(dp, prop);
1210 iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)iprop->get);
1211 iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)iprop->set);
1214 if(!iprop->getarray && !iprop->setarray)
1215 rna_set_raw_property(dp, prop);
1217 iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)iprop->getarray);
1218 iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)iprop->setarray);
1223 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1225 if(!prop->arraydimension) {
1226 if(!fprop->get && !fprop->set)
1227 rna_set_raw_property(dp, prop);
1229 fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)fprop->get);
1230 fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)fprop->set);
1233 if(!fprop->getarray && !fprop->setarray)
1234 rna_set_raw_property(dp, prop);
1236 fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)fprop->getarray);
1237 fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)fprop->setarray);
1242 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1244 eprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)eprop->get);
1245 eprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)eprop->set);
1249 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1251 sprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)sprop->get);
1252 sprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (const char*)sprop->length);
1253 sprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)sprop->set);
1256 case PROP_POINTER: {
1257 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1259 pprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)pprop->get);
1260 pprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)pprop->set);
1262 fprintf(stderr, "rna_def_property_funcs: %s.%s, pointer must have a struct type.\n", srna->identifier, prop->identifier);
1267 case PROP_COLLECTION: {
1268 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1269 const char *nextfunc= (const char*)cprop->next;
1271 if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0);
1272 else if(dp->dnalengthname || dp->dnalengthfixed)
1273 cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (const char*)cprop->length);
1275 /* test if we can allow raw array access, if it is using our standard
1276 * array get/next function, we can be sure it is an actual array */
1277 if(cprop->next && cprop->get)
1278 if(strcmp((const char*)cprop->next, "rna_iterator_array_next") == 0 &&
1279 strcmp((const char*)cprop->get, "rna_iterator_array_get") == 0)
1280 prop->flag |= PROP_RAW_ARRAY;
1282 cprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)cprop->get);
1283 cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp, (const char*)cprop->begin);
1284 cprop->next= (void*)rna_def_property_next_func(f, srna, prop, dp, (const char*)cprop->next);
1285 cprop->end= (void*)rna_def_property_end_func(f, srna, prop, dp, (const char*)cprop->end);
1286 cprop->lookupint= (void*)rna_def_property_lookup_int_func(f, srna, prop, dp, (const char*)cprop->lookupint, nextfunc);
1288 if(!(prop->flag & PROP_IDPROPERTY)) {
1290 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a begin function.\n", srna->identifier, prop->identifier);
1294 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a next function.\n", srna->identifier, prop->identifier);
1298 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a get function.\n", srna->identifier, prop->identifier);
1302 if(!cprop->item_type) {
1303 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a struct type.\n", srna->identifier, prop->identifier);
1311 static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1318 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1321 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "");
1323 switch(prop->type) {
1326 if(!prop->arraydimension) {
1327 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1328 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1330 else if(prop->arraydimension && prop->totarraylength) {
1331 fprintf(f, "void %sget(PointerRNA *ptr, int values[%u]);\n", func, prop->totarraylength);
1332 //fprintf(f, "void %sset(PointerRNA *ptr, const int values[%d]);\n", func, prop->arraylength);
1335 fprintf(f, "void %sget(PointerRNA *ptr, int values[]);\n", func);
1336 //fprintf(f, "void %sset(PointerRNA *ptr, const int values[]);\n", func);
1341 if(!prop->arraydimension) {
1342 fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
1343 //fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
1345 else if(prop->arraydimension && prop->totarraylength) {
1346 fprintf(f, "void %sget(PointerRNA *ptr, float values[%u]);\n", func, prop->totarraylength);
1347 //fprintf(f, "void %sset(PointerRNA *ptr, const float values[%d]);\n", func, prop->arraylength);
1350 fprintf(f, "void %sget(PointerRNA *ptr, float values[]);\n", func);
1351 //fprintf(f, "void %sset(PointerRNA *ptr, const float values[]);\n", func);
1356 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1360 fprintf(f, "enum {\n");
1362 for(i=0; i<eprop->totitem; i++)
1363 if(eprop->item[i].identifier[0])
1364 fprintf(f, "\t%s_%s_%s = %d,\n", srna->identifier, prop->identifier, eprop->item[i].identifier, eprop->item[i].value);
1366 fprintf(f, "};\n\n");
1369 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1370 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1375 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1377 if(sprop->maxlength) {
1378 fprintf(f, "#define %s_%s_MAX %d\n\n", srna->identifier, prop->identifier, sprop->maxlength);
1381 fprintf(f, "void %sget(PointerRNA *ptr, char *value);\n", func);
1382 fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1383 //fprintf(f, "void %sset(PointerRNA *ptr, const char *value);\n", func);
1387 case PROP_POINTER: {
1388 fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func);
1389 //fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func);
1392 case PROP_COLLECTION: {
1393 fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
1394 fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
1395 fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
1396 //fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1397 //fprintf(f, "void %slookup_int(PointerRNA *ptr, int key, StructRNA **type);\n", func);
1398 //fprintf(f, "void %slookup_string(PointerRNA *ptr, const char *key, StructRNA **type);\n", func);
1406 static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1412 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1415 if(prop->name && prop->description && prop->description[0] != '\0')
1416 fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
1418 fprintf(f, "\t/* %s */\n", prop->name);
1420 fprintf(f, "\t/* */\n");
1422 switch(prop->type) {
1423 case PROP_BOOLEAN: {
1424 if(!prop->arraydimension)
1425 fprintf(f, "\tinline bool %s(void);", rna_safe_id(prop->identifier));
1427 fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier));
1431 if(!prop->arraydimension)
1432 fprintf(f, "\tinline int %s(void);", rna_safe_id(prop->identifier));
1434 fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier));
1438 if(!prop->arraydimension)
1439 fprintf(f, "\tinline float %s(void);", rna_safe_id(prop->identifier));
1441 fprintf(f, "\tinline Array<float, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier));
1445 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1449 fprintf(f, "\tenum %s_enum {\n", rna_safe_id(prop->identifier));
1451 for(i=0; i<eprop->totitem; i++)
1452 if(eprop->item[i].identifier[0])
1453 fprintf(f, "\t\t%s_%s = %d,\n", rna_safe_id(prop->identifier), eprop->item[i].identifier, eprop->item[i].value);
1455 fprintf(f, "\t};\n");
1458 fprintf(f, "\tinline %s_enum %s(void);", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier));
1462 fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier));
1465 case PROP_POINTER: {
1466 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1469 fprintf(f, "\tinline %s %s(void);", (const char*)pprop->type, rna_safe_id(prop->identifier));
1471 fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier));
1474 case PROP_COLLECTION: {
1475 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1477 if(cprop->item_type)
1478 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char*)cprop->item_type, srna->identifier, rna_safe_id(prop->identifier));
1480 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, rna_safe_id(prop->identifier));
1488 static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1494 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1497 switch(prop->type) {
1498 case PROP_BOOLEAN: {
1499 if(!prop->arraydimension)
1500 fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1502 fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength, rna_safe_id(prop->identifier));
1506 if(!prop->arraydimension)
1507 fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1509 fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength, rna_safe_id(prop->identifier));
1513 if(!prop->arraydimension)
1514 fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1516 fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength, rna_safe_id(prop->identifier));
1520 fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", rna_safe_id(prop->identifier), srna->identifier, rna_safe_id(prop->identifier));
1525 fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1528 case PROP_POINTER: {
1529 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1532 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", (const char*)pprop->type, srna->identifier, rna_safe_id(prop->identifier));
1534 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, rna_safe_id(prop->identifier));
1537 case PROP_COLLECTION: {
1538 /*CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1541 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char*)cprop->type, srna->identifier, prop->identifier);
1543 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);*/
1551 static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
1555 PropertyDefRNA *dparm;
1557 const char *funcname, *valstr;
1559 const short has_data= (dfunc->cont.properties.first != NULL);
1560 int flag, pout, cptr, first;
1568 funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call");
1570 /* function definition */
1571 fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname);
1572 fprintf(f, "\n{\n");
1574 /* variable definitions */
1576 if(func->flag & FUNC_USE_SELF_ID) {
1577 fprintf(f, "\tstruct ID *_selfid;\n");
1580 if((func->flag & FUNC_NO_SELF)==0) {
1581 if(dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
1582 else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
1585 dparm= dfunc->cont.properties.first;
1586 for(; dparm; dparm= dparm->next) {
1587 type = dparm->prop->type;
1588 flag = dparm->prop->flag;
1589 pout = (flag & PROP_OUTPUT);
1590 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1592 if(dparm->prop==func->c_ret)
1593 ptrstr= cptr || dparm->prop->arraydimension ? "*" : "";
1594 /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
1595 else if (cptr || (flag & PROP_DYNAMIC))
1596 ptrstr= pout ? "**" : "*";
1597 /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
1598 else if (type == PROP_POINTER || dparm->prop->arraydimension)
1600 /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack, but type name for string props is already char*, so leave empty */
1601 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
1604 ptrstr= pout ? "*" : "";
1606 /* for dynamic parameters we pass an additional int for the length of the parameter */
1607 if (flag & PROP_DYNAMIC)
1608 fprintf(f, "\tint %s%s_len;\n", pout ? "*" : "", dparm->prop->identifier);
1610 fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
1614 fprintf(f, "\tchar *_data");
1615 if(func->c_ret) fprintf(f, ", *_retdata");
1621 if(func->flag & FUNC_USE_SELF_ID) {
1622 fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
1625 if((func->flag & FUNC_NO_SELF)==0) {
1626 if(dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
1627 else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
1631 fprintf(f, "\t_data= (char *)_parms->data;\n");
1634 dparm= dfunc->cont.properties.first;
1635 for(; dparm; dparm= dparm->next) {
1636 type = dparm->prop->type;
1637 flag = dparm->prop->flag;
1638 pout = (flag & PROP_OUTPUT);
1639 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1641 if(dparm->prop==func->c_ret)
1642 fprintf(f, "\t_retdata= _data;\n");
1644 const char *data_str;
1645 if (cptr || (flag & PROP_DYNAMIC)) {
1649 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
1653 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
1662 /* this must be kept in sync with RNA_parameter_length_get_data, we could just call the function directly, but this is faster */
1663 if (flag & PROP_DYNAMIC) {
1664 fprintf(f, "\t%s_len= %s((int *)_data);\n", dparm->prop->identifier, pout ? "" : "*");
1665 data_str= "(&(((char *)_data)[sizeof(void *)]))";
1670 fprintf(f, "\t%s= ", dparm->prop->identifier);
1673 fprintf(f, "%s", valstr);
1675 fprintf(f, "((%s%s%s)%s);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, data_str);
1679 fprintf(f, "\t_data+= %d;\n", rna_parameter_size_alloc(dparm->prop));
1685 if(func->c_ret) fprintf(f, "%s= ", func->c_ret->identifier);
1686 fprintf(f, "%s(", dfunc->call);
1690 if(func->flag & FUNC_USE_SELF_ID) {
1691 fprintf(f, "_selfid");
1695 if((func->flag & FUNC_NO_SELF)==0) {
1696 if(!first) fprintf(f, ", ");
1697 fprintf(f, "_self");
1701 if(func->flag & FUNC_USE_CONTEXT) {
1702 if(!first) fprintf(f, ", ");
1707 if(func->flag & FUNC_USE_REPORTS) {
1708 if(!first) fprintf(f, ", ");
1710 fprintf(f, "reports");
1713 dparm= dfunc->cont.properties.first;
1714 for(; dparm; dparm= dparm->next) {
1715 if(dparm->prop==func->c_ret)
1718 if(!first) fprintf(f, ", ");
1721 if (dparm->prop->flag & PROP_DYNAMIC)
1722 fprintf(f, "%s_len, %s", dparm->prop->identifier, dparm->prop->identifier);
1724 fprintf(f, "%s", dparm->prop->identifier);
1730 dparm= rna_find_parameter_def(func->c_ret);
1731 ptrstr= (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) || (dparm->prop->arraydimension))? "*": "";
1732 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);
1736 fprintf(f, "}\n\n");
1738 dfunc->gencall= funcname;
1741 static void rna_auto_types(void)
1746 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
1747 /* DNA name for Screen is patched in 2.5, we do the reverse here .. */
1748 if(ds->dnaname && strcmp(ds->dnaname, "Screen") == 0)
1749 ds->dnaname= "bScreen";
1751 for(dp=ds->cont.properties.first; dp; dp=dp->next) {
1752 if(dp->dnastructname && strcmp(dp->dnastructname, "Screen") == 0)
1753 dp->dnastructname= "bScreen";
1756 if(dp->prop->type == PROP_POINTER) {
1757 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1760 if(!pprop->type && !pprop->get)
1761 pprop->type= (StructRNA*)rna_find_type(dp->dnatype);
1764 type= rna_find_struct((const char*)pprop->type);
1765 if(type && (type->flag & STRUCT_ID_REFCOUNT))
1766 pprop->property.flag |= PROP_ID_REFCOUNT;
1769 else if(dp->prop->type== PROP_COLLECTION) {
1770 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1772 if(!cprop->item_type && !cprop->get && strcmp(dp->dnatype, "ListBase")==0)
1773 cprop->item_type= (StructRNA*)rna_find_type(dp->dnatype);
1780 static void rna_sort(BlenderRNA *brna)
1785 rna_sortlist(&brna->structs, cmp_struct);
1786 rna_sortlist(&DefRNA.structs, cmp_def_struct);
1788 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1789 rna_sortlist(&srna->cont.properties, cmp_property);
1791 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
1792 rna_sortlist(&ds->cont.properties, cmp_def_property);
1795 static const char *rna_property_structname(PropertyType type)
1798 case PROP_BOOLEAN: return "BooleanPropertyRNA";
1799 case PROP_INT: return "IntPropertyRNA";
1800 case PROP_FLOAT: return "FloatPropertyRNA";
1801 case PROP_STRING: return "StringPropertyRNA";
1802 case PROP_ENUM: return "EnumPropertyRNA";
1803 case PROP_POINTER: return "PointerPropertyRNA";
1804 case PROP_COLLECTION: return "CollectionPropertyRNA";
1805 default: return "UnknownPropertyRNA";
1809 static const char *rna_property_subtypename(PropertySubType type)
1812 case PROP_NONE: return "PROP_NONE";
1813 case PROP_FILEPATH: return "PROP_FILEPATH";
1814 case PROP_FILENAME: return "PROP_FILENAME";
1815 case PROP_DIRPATH: return "PROP_DIRPATH";
1816 case PROP_TRANSLATE: return "PROP_TRANSLATE";
1817 case PROP_UNSIGNED: return "PROP_UNSIGNED";
1818 case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
1819 case PROP_FACTOR: return "PROP_FACTOR";
1820 case PROP_ANGLE: return "PROP_ANGLE";
1821 case PROP_TIME: return "PROP_TIME";
1822 case PROP_DISTANCE: return "PROP_DISTANCE";
1823 case PROP_COLOR: return "PROP_COLOR";
1824 case PROP_TRANSLATION: return "PROP_TRANSLATION";
1825 case PROP_DIRECTION: return "PROP_DIRECTION";
1826 case PROP_MATRIX: return "PROP_MATRIX";
1827 case PROP_EULER: return "PROP_EULER";
1828 case PROP_QUATERNION: return "PROP_QUATERNION";
1829 case PROP_AXISANGLE: return "PROP_AXISANGLE";
1830 case PROP_VELOCITY: return "PROP_VELOCITY";
1831 case PROP_ACCELERATION: return "PROP_ACCELERATION";
1832 case PROP_XYZ: return "PROP_XYZ";
1833 case PROP_COLOR_GAMMA: return "PROP_COLOR_GAMMA";
1834 case PROP_COORDS: return "PROP_COORDS";
1835 case PROP_LAYER: return "PROP_LAYER";
1836 case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
1838 /* incase we dont have a type preset that includes the subtype */
1839 if(RNA_SUBTYPE_UNIT(type)) {
1840 return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
1843 return "PROP_SUBTYPE_UNKNOWN";
1849 static const char *rna_property_subtype_unit(PropertySubType type)
1851 switch(RNA_SUBTYPE_UNIT(type)) {
1852 case PROP_UNIT_NONE: return "PROP_UNIT_NONE";
1853 case PROP_UNIT_LENGTH: return "PROP_UNIT_LENGTH";
1854 case PROP_UNIT_AREA: return "PROP_UNIT_AREA";
1855 case PROP_UNIT_VOLUME: return "PROP_UNIT_VOLUME";
1856 case PROP_UNIT_MASS: return "PROP_UNIT_MASS";
1857 case PROP_UNIT_ROTATION: return "PROP_UNIT_ROTATION";
1858 case PROP_UNIT_TIME: return "PROP_UNIT_TIME";
1859 case PROP_UNIT_VELOCITY: return "PROP_UNIT_VELOCITY";
1860 case PROP_UNIT_ACCELERATION:return "PROP_UNIT_ACCELERATION";
1861 default: return "PROP_UNIT_UNKNOWN";
1865 static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
1869 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1870 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
1874 static void rna_generate_blender(BlenderRNA *brna, FILE *f)
1878 fprintf(f, "BlenderRNA BLENDER_RNA = {");
1880 srna= brna->structs.first;
1881 if(srna) fprintf(f, "{&RNA_%s, ", srna->identifier);
1882 else fprintf(f, "{NULL, ");
1884 srna= brna->structs.last;
1885 if(srna) fprintf(f, "&RNA_%s}", srna->identifier);
1886 else fprintf(f, "NULL}");
1888 fprintf(f, "};\n\n");
1891 static void rna_generate_property_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1899 for(prop=base->cont.properties.first; prop; prop=prop->next)
1900 fprintf(f, "%s%s rna_%s_%s;\n", "extern ", rna_property_structname(prop->type), base->identifier, prop->identifier);
1904 if(srna->cont.properties.first)
1907 for(prop=srna->cont.properties.first; prop; prop=prop->next)
1908 fprintf(f, "%s%s rna_%s_%s;\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, prop->identifier);
1912 static void rna_generate_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionRNA *func, FILE *f)
1916 for(parm= func->cont.properties.first; parm; parm= parm->next)
1917 fprintf(f, "%s%s rna_%s_%s_%s;\n", "extern ", rna_property_structname(parm->type), srna->identifier, func->identifier, parm->identifier);
1919 if(func->cont.properties.first)
1923 static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1930 for(func= base->functions.first; func; func= func->cont.next) {
1931 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", base->identifier, func->identifier);
1932 rna_generate_parameter_prototypes(brna, base, func, f);
1935 if(base->functions.first)
1941 for(func= srna->functions.first; func; func= func->cont.next) {
1942 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier);
1943 rna_generate_parameter_prototypes(brna, srna, func, f);
1946 if(srna->functions.first)
1950 static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionDefRNA *dfunc, FILE *f)
1953 PropertyDefRNA *dparm;
1954 StructDefRNA *dsrna;
1956 int flag, pout, cptr, first;
1959 dsrna= rna_find_struct_def(srna);
1963 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
1964 if(dparm->prop==func->c_ret) {
1965 if(dparm->prop->arraydimension)
1966 fprintf(f, "XXX no array return types yet"); /* XXX not supported */
1967 else if(dparm->prop->type == PROP_POINTER && !(dparm->prop->flag & PROP_RNAPTR))
1968 fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1970 fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1976 /* void if nothing to return */
1978 fprintf(f, "void ");
1981 fprintf(f, "%s(", dfunc->call);
1985 /* self, context and reports parameters */
1986 if(func->flag & FUNC_USE_SELF_ID) {
1987 fprintf(f, "struct ID *_selfid");
1991 if((func->flag & FUNC_NO_SELF)==0) {
1992 if(!first) fprintf(f, ", ");
1993 if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
1994 else fprintf(f, "struct %s *_self", srna->identifier);
1998 if(func->flag & FUNC_USE_CONTEXT) {
1999 if(!first) fprintf(f, ", ");
2001 fprintf(f, "bContext *C");
2004 if(func->flag & FUNC_USE_REPORTS) {
2005 if(!first) fprintf(f, ", ");
2007 fprintf(f, "ReportList *reports");
2010 /* defined parameters */
2011 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
2012 type = dparm->prop->type;
2013 flag = dparm->prop->flag;
2014 pout = (flag & PROP_OUTPUT);
2015 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
2017 if(dparm->prop==func->c_ret)
2020 if (cptr || (flag & PROP_DYNAMIC))
2021 ptrstr= pout ? "**" : "*";
2022 else if (type == PROP_POINTER || dparm->prop->arraydimension)
2024 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
2027 ptrstr= pout ? "*" : "";
2029 if(!first) fprintf(f, ", ");
2032 if (flag & PROP_DYNAMIC)
2033 fprintf(f, "int %s%s_len, ", pout ? "*" : "", dparm->prop->identifier);
2035 if(!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension)
2036 fprintf(f, "%s%s %s[%u]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->totarraylength);
2038 fprintf(f, "%s%s %s%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
2045 static void rna_generate_static_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
2048 FunctionDefRNA *dfunc;
2051 for(func= srna->functions.first; func; func= func->cont.next) {
2052 dfunc= rna_find_function_def(func);
2056 fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
2060 rna_generate_static_parameter_prototypes(brna, srna, dfunc, f);
2067 static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
2069 char *strnest= "", *errnest= "";
2070 int len, freenest= 0;
2075 strnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> strnest");
2076 errnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> errnest");
2078 strcpy(strnest, "_"); strcat(strnest, nest);
2079 strcpy(errnest, "."); strcat(errnest, nest);
2084 switch(prop->type) {
2086 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2087 int i, defaultfound= 0, totflag= 0;
2090 fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
2092 for(i=0; i<eprop->totitem; i++) {
2093 fprintf(f, "{%d, ", eprop->item[i].value);
2094 rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
2095 fprintf(f, "%d, ", eprop->item[i].icon);
2096 rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
2097 rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
2099 if(eprop->item[i].identifier[0]) {
2100 if(prop->flag & PROP_ENUM_FLAG) {
2101 totflag |= eprop->item[i].value;
2104 if(eprop->defaultvalue == eprop->item[i].value) {
2111 fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
2113 if(prop->flag & PROP_ENUM_FLAG) {
2114 if(eprop->defaultvalue & ~totflag) {
2115 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default includes unused bits (%d).\n", srna->identifier, errnest, prop->identifier, eprop->defaultvalue & ~totflag);
2121 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
2127 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum must have items defined.\n", srna->identifier, errnest, prop->identifier);
2132 case PROP_BOOLEAN: {
2133 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
2136 if(prop->arraydimension && prop->totarraylength) {
2137 fprintf(f, "static int rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
2139 for(i=0; i<prop->totarraylength; i++) {
2140 if(bprop->defaultarray)
2141 fprintf(f, "%d", bprop->defaultarray[i]);
2143 fprintf(f, "%d", bprop->defaultvalue);
2144 if(i != prop->totarraylength-1)
2145 fprintf(f, ",\n\t");
2148 fprintf(f, "\n};\n\n");
2153 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2156 if(prop->arraydimension && prop->totarraylength) {
2157 fprintf(f, "static int rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
2159 for(i=0; i<prop->totarraylength; i++) {
2160 if(iprop->defaultarray)
2161 fprintf(f, "%d", iprop->defaultarray[i]);
2163 fprintf(f, "%d", iprop->defaultvalue);
2164 if(i != prop->totarraylength-1)
2165 fprintf(f, ",\n\t");
2168 fprintf(f, "\n};\n\n");
2173 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2176 if(prop->arraydimension && prop->totarraylength) {
2177 fprintf(f, "static float rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
2179 for(i=0; i<prop->totarraylength; i++) {
2180 if(fprop->defaultarray)
2181 rna_float_print(f, fprop->defaultarray[i]);
2183 rna_float_print(f, fprop->defaultvalue);
2184 if(i != prop->totarraylength-1)
2185 fprintf(f, ",\n\t");
2188 fprintf(f, "\n};\n\n");
2196 fprintf(f, "%s%s rna_%s%s_%s = {\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, strnest, prop->identifier);
2198 if(prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
2199 else fprintf(f, "\t{NULL, ");
2200 if(prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
2201 else fprintf(f, "NULL,\n");
2202 fprintf(f, "\t%d, ", prop->magic);
2203 rna_print_c_string(f, prop->identifier);
2204 fprintf(f, ", %d, ", prop->flag);
2205 rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
2206 rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
2207 fprintf(f, "%d,\n", prop->icon);
2208 fprintf(f, "\t%s, %s|%s, %s, %u, {%u, %u, %u}, %u,\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);
2209 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));
2211 if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
2212 else fprintf(f, "\t0, -1");
2214 /* our own type - collections/arrays only */
2215 if(prop->srna) fprintf(f, ", &RNA_%s", (const char*)prop->srna);
2216 else fprintf(f, ", NULL");
2220 switch(prop->type) {
2221 case PROP_BOOLEAN: {
2222 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
2223 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);
2224 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2225 else fprintf(f, "NULL\n");
2229 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2230 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));
2231 rna_int_print(f, iprop->softmin); fprintf(f, ", ");
2232 rna_int_print(f, iprop->softmax); fprintf(f, ", ");
2233 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
2234 rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
2235 rna_int_print(f, iprop->step); fprintf(f, ", ");
2236 rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
2237 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2238 else fprintf(f, "NULL\n");
2242 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2243 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));
2244 rna_float_print(f, fprop->softmin); fprintf(f, ", ");
2245 rna_float_print(f, fprop->softmax); fprintf(f, ", ");
2246 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
2247 rna_float_print(f, fprop->hardmax); fprintf(f, ", ");
2248 rna_float_print(f, fprop->step); fprintf(f, ", ");
2249 rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
2250 rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
2251 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2252 else fprintf(f, "NULL\n");
2256 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
2257 fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength);
2258 rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
2262 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2263 fprintf(f, "\t%s, %s, %s, NULL, ", rna_function_string(eprop->get), rna_function_string(eprop->set), rna_function_string(eprop->itemf));
2265 fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
2267 fprintf(f, "NULL, ");
2268 fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
2271 case PROP_POINTER: {
2272 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
2273 fprintf(f, "\t%s, %s, %s, %s,", rna_function_string(pprop->get), rna_function_string(pprop->set), rna_function_string(pprop->typef), rna_function_string(pprop->poll));
2274 if(pprop->type) fprintf(f, "&RNA_%s\n", (const char*)pprop->type);
2275 else fprintf(f, "NULL\n");
2278 case PROP_COLLECTION: {
2279 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2280 fprintf(f, "\t%s, %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), rna_function_string(cprop->assignint));
2281 if(cprop->item_type) fprintf(f, "&RNA_%s\n", (const char*)cprop->item_type);
2282 else fprintf(f, "NULL\n");
2287 fprintf(f, "};\n\n");
2295 static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
2298 FunctionDefRNA *dfunc;
2299 PropertyRNA *prop, *parm;
2302 fprintf(f, "/* %s */\n", srna->name);
2304 for(prop= srna->cont.properties.first; prop; prop= prop->next)
2305 rna_generate_property(f, srna, NULL, prop);
2307 for(func= srna->functions.first; func; func= func->cont.next) {
2308 for(parm= func->cont.properties.first; parm; parm= parm->next)
2309 rna_generate_property(f, srna, func->identifier, parm);
2311 fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
2313 if(func->cont.next) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, ((FunctionRNA*)func->cont.next)->identifier);
2314 else fprintf(f, "\t{NULL, ");
2315 if(func->cont.prev) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier, ((FunctionRNA*)func->cont.prev)->identifier);
2316 else fprintf(f, "NULL,\n");
2318 fprintf(f, "\tNULL,\n");
2320 parm= func->cont.properties.first;
2321 if(parm) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
2322 else fprintf(f, "\t{NULL, ");
2324 parm= func->cont.properties.last;
2325 if(parm) fprintf(f, "(PropertyRNA*)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
2326 else fprintf(f, "NULL}},\n");
2329 rna_print_c_string(f, func->identifier);
2330 fprintf(f, ", %d, ", func->flag);
2331 rna_print_c_string(f, func->description); fprintf(f, ",\n");
2333 dfunc= rna_find_function_def(func);
2334 if(dfunc->gencall) fprintf(f, "\t%s,\n", dfunc->gencall);
2335 else fprintf(f, "\tNULL,\n");
2337 if(func->c_ret) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
2338 else fprintf(f, "\tNULL\n");
2344 fprintf(f, "StructRNA RNA_%s = {\n", srna->identifier);
2346 if(srna->cont.next) fprintf(f, "\t{(ContainerRNA *)&RNA_%s, ", ((StructRNA*)srna->cont.next)->identifier);
2347 else fprintf(f, "\t{NULL, ");
2348 if(srna->cont.prev) fprintf(f, "(ContainerRNA *)&RNA_%s,\n", ((StructRNA*)srna->cont.prev)->identifier);
2349 else fprintf(f, "NULL,\n");
2351 fprintf(f, "\tNULL,\n");
2353 prop= srna->cont.properties.first;
2354 if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
2355 else fprintf(f, "\t{NULL, ");
2357 prop= srna->cont.properties.last;
2358 if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
2359 else fprintf(f, "NULL}},\n");
2361 rna_print_c_string(f, srna->identifier);
2362 fprintf(f, "\t, NULL,NULL\n"); /* PyType - Cant initialize here */
2363 fprintf(f, ", %d, ", srna->flag);
2364 rna_print_c_string(f, srna->name);
2366 rna_print_c_string(f, srna->description);
2367 fprintf(f, ",\n\t%d,\n", srna->icon);
2369 prop= srna->nameproperty;
2372 while (base->base && base->base->nameproperty==prop)
2375 fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", base->identifier, prop->identifier);
2377 else fprintf(f, "\tNULL, ");
2379 prop= srna->iteratorproperty;
2381 while (base->base && base->base->iteratorproperty==prop)
2383 fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", base->identifier);
2385 if(srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
2386 else fprintf(f, "\tNULL,\n");
2388 if(srna->nested) fprintf(f, "\t&RNA_%s,\n", srna->nested->identifier);
2389 else fprintf(f, "\tNULL,\n");
2391 fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
2392 fprintf(f, "\t%s,\n", rna_function_string(srna->path));
2393 fprintf(f, "\t%s,\n", rna_function_string(srna->reg));
2394 fprintf(f, "\t%s,\n", rna_function_string(srna->unreg));
2395 fprintf(f, "\t%s,\n", rna_function_string(srna->instance));
2396 fprintf(f, "\t%s,\n", rna_function_string(srna->idproperties));
2398 if(srna->reg && !srna->refine) {
2399 fprintf(stderr, "rna_generate_struct: %s has a register function, must also have refine function.\n", srna->identifier);
2403 func= srna->functions.first;
2404 if(func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, func->identifier);
2405 else fprintf(f, "\t{NULL, ");
2407 func= srna->functions.last;
2408 if(func) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
2409 else fprintf(f, "NULL}\n");
2416 typedef struct RNAProcessItem {
2417 const char *filename;
2418 const char *api_filename;
2419 void (*define)(BlenderRNA *brna);
2422 static RNAProcessItem PROCESS_ITEMS[]= {
2423 {"rna_rna.c", NULL, RNA_def_rna},
2424 {"rna_ID.c", NULL, RNA_def_ID},
2425 {"rna_texture.c", "rna_texture_api.c", RNA_def_texture},
2426 {"rna_action.c", "rna_action_api.c", RNA_def_action},
2427 {"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
2428 {"rna_animviz.c", NULL, RNA_def_animviz},
2429 {"rna_actuator.c", "rna_actuator_api.c", RNA_def_actuator},
2430 {"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
2431 {"rna_boid.c", NULL, RNA_def_boid},
2432 {"rna_brush.c", NULL, RNA_def_brush},
2433 {"rna_camera.c", "rna_camera_api.c", RNA_def_camera},
2434 {"rna_cloth.c", NULL, RNA_def_cloth},
2435 {"rna_color.c", NULL, RNA_def_color},
2436 {"rna_constraint.c", NULL, RNA_def_constraint},
2437 {"rna_context.c", NULL, RNA_def_context},
2438 {"rna_controller.c", "rna_controller_api.c", RNA_def_controller},
2439 {"rna_curve.c", NULL, RNA_def_curve},
2440 {"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
2441 {"rna_fluidsim.c", NULL, RNA_def_fluidsim},
2442 {"rna_gpencil.c", NULL, RNA_def_gpencil},
2443 {"rna_group.c", NULL, RNA_def_group},
2444 {"rna_image.c", "rna_image_api.c", RNA_def_image},
2445 {"rna_key.c", NULL, RNA_def_key},
2446 {"rna_lamp.c", NULL, RNA_def_lamp},
2447 {"rna_lattice.c", NULL, RNA_def_lattice},
2448 {"rna_main.c", "rna_main_api.c", RNA_def_main},
2449 {"rna_material.c", "rna_material_api.c", RNA_def_material},
2450 {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
2451 {"rna_meta.c", NULL, RNA_def_meta},
2452 {"rna_modifier.c", NULL, RNA_def_modifier},
2453 {"rna_nla.c", NULL, RNA_def_nla},
2454 {"rna_nodetree.c", NULL, RNA_def_nodetree},
2455 {"rna_object.c", "rna_object_api.c", RNA_def_object},
2456 {"rna_object_force.c", NULL, RNA_def_object_force},
2457 {"rna_packedfile.c", NULL, RNA_def_packedfile},
2458 {"rna_particle.c", NULL, RNA_def_particle},
2459 {"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
2460 {"rna_property.c", NULL, RNA_def_gameproperty},
2461 {"rna_render.c", NULL, RNA_def_render},
2462 {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
2463 {"rna_screen.c", NULL, RNA_def_screen},
2464 {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
2465 {"rna_sensor.c", "rna_sensor_api.c", RNA_def_sensor},
2466 {"rna_sequencer.c", "rna_sequencer_api.c", RNA_def_sequencer},
2467 {"rna_smoke.c", NULL, RNA_def_smoke},
2468 {"rna_space.c", NULL, RNA_def_space},
2469 {"rna_speaker.c", NULL, RNA_def_speaker},
2470 {"rna_test.c", NULL, RNA_def_test},
2471 {"rna_text.c", NULL, RNA_def_text},
2472 {"rna_timeline.c", NULL, RNA_def_timeline_marker},
2473 {"rna_sound.c", NULL, RNA_def_sound},
2474 {"rna_ui.c", "rna_ui_api.c", RNA_def_ui},
2475 {"rna_userdef.c", NULL, RNA_def_userdef},
2476 {"rna_vfont.c", NULL, RNA_def_vfont},
2477 {"rna_wm.c", "rna_wm_api.c", RNA_def_wm},
2478 {"rna_world.c", NULL, RNA_def_world},
2481 static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename)
2485 FunctionDefRNA *dfunc;
2487 fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
2488 " Do not edit manually, changes will be overwritten. */\n\n"
2489 "#define RNA_RUNTIME\n\n");
2491 fprintf(f, "#include <float.h>\n");
2492 fprintf(f, "#include <stdio.h>\n");
2493 fprintf(f, "#include <limits.h>\n");
2494 fprintf(f, "#include <string.h>\n\n");
2495 fprintf(f, "#include <stddef.h>\n\n");
2497 fprintf(f, "#include \"DNA_ID.h\"\n");
2498 fprintf(f, "#include \"DNA_scene_types.h\"\n");
2500 fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
2501 fprintf(f, "#include \"BLI_utildefines.h\"\n\n");
2503 fprintf(f, "#include \"BKE_context.h\"\n");
2504 fprintf(f, "#include \"BKE_library.h\"\n");
2505 fprintf(f, "#include \"BKE_main.h\"\n");
2506 fprintf(f, "#include \"BKE_report.h\"\n");
2508 fprintf(f, "#include \"RNA_define.h\"\n");
2509 fprintf(f, "#include \"RNA_types.h\"\n");
2510 fprintf(f, "#include \"rna_internal.h\"\n\n");
2512 rna_generate_prototypes(brna, f);
2514 fprintf(f, "#include \"%s\"\n", filename);
2516 fprintf(f, "#include \"%s\"\n", api_filename);
2519 fprintf(f, "/* Autogenerated Functions */\n\n");
2521 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2522 if(!filename || ds->filename == filename) {
2523 rna_generate_property_prototypes(brna, ds->srna, f);
2524 rna_generate_function_prototypes(brna, ds->srna, f);
2528 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2529 if(!filename || ds->filename == filename)
2530 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2531 rna_def_property_funcs(f, ds->srna, dp);
2533 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2534 if(!filename || ds->filename == filename) {
2535 for(dfunc=ds->functions.first; dfunc; dfunc= dfunc->cont.next)
2536 rna_def_function_funcs(f, ds, dfunc);
2538 rna_generate_static_function_prototypes(brna, ds->srna, f);
2542 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2543 if(!filename || ds->filename == filename)
2544 rna_generate_struct(brna, ds->srna, f);
2546 if(strcmp(filename, "rna_ID.c") == 0) {
2547 /* this is ugly, but we cannot have c files compiled for both
2548 * makesrna and blender with some build systems at the moment */
2549 fprintf(f, "#include \"rna_define.c\"\n\n");
2551 rna_generate_blender(brna, f);
2555 static void rna_generate_header(BlenderRNA *brna, FILE *f)
2561 fprintf(f, "\n#ifndef __RNA_BLENDER_H__\n");
2562 fprintf(f, "#define __RNA_BLENDER_H__\n\n");
2564 fprintf(f, "/* Automatically generated function declarations for the Data API.\n"
2565 " Do not edit manually, changes will be overwritten. */\n\n");
2567 fprintf(f, "#include \"RNA_types.h\"\n\n");
2569 fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
2571 fprintf(f, "#define FOREACH_BEGIN(property, sptr, itemptr) \\\n");
2572 fprintf(f, " { \\\n");
2573 fprintf(f, " CollectionPropertyIterator rna_macro_iter; \\\n");
2574 fprintf(f, " for(property##_begin(&rna_macro_iter, sptr); rna_macro_iter.valid; property##_next(&rna_macro_iter)) { \\\n");
2575 fprintf(f, " itemptr= rna_macro_iter.ptr;\n\n");
2577 fprintf(f, "#define FOREACH_END(property) \\\n");
2578 fprintf(f, " } \\\n");
2579 fprintf(f, " property##_end(&rna_macro_iter); \\\n");
2580 fprintf(f, " }\n\n");
2582 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2585 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2588 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
2593 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2594 rna_def_property_funcs_header(f, ds->srna, dp);
2597 fprintf(f, "#ifdef __cplusplus\n}\n#endif\n\n");
2599 fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n\n");
2602 static const char *cpp_classes = ""
2604 "#include <string>\n"
2608 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
2609 " inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr)? true: false; }\n"
2611 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2612 " inline Array<int,size> sname::identifier(void) \\\n"
2613 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2615 "#define INT_PROPERTY(sname, identifier) \\\n"
2616 " inline int sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2618 "#define INT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2619 " inline Array<int,size> sname::identifier(void) \\\n"
2620 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2622 "#define FLOAT_PROPERTY(sname, identifier) \\\n"
2623 " inline float sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2625 "#define FLOAT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2626 " inline Array<float,size> sname::identifier(void) \\\n"
2627 " { Array<float, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2629 "#define ENUM_PROPERTY(type, sname, identifier) \\\n"
2630 " inline sname::type sname::identifier(void) { return (type)sname##_##identifier##_get(&ptr); }\n"
2632 "#define STRING_PROPERTY(sname, identifier) \\\n"
2633 " inline std::string sname::identifier(void) { \\\n"
2634 " int len= sname##_##identifier##_length(&ptr); \\\n"
2635 " std::string str; str.resize(len); \\\n"
2636 " sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
2638 "#define POINTER_PROPERTY(type, sname, identifier) \\\n"
2639 " inline type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
2641 "#define COLLECTION_PROPERTY(type, sname, identifier) \\\n"
2642 " typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
2643 " sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
2644 " Collection<sname, type, sname##_##identifier##_begin, \\\n"
2645 " sname##_##identifier##_next, sname##_##identifier##_end> identifier;\n"
2649 " Pointer(const PointerRNA& p) : ptr(p) { }\n"
2650 " operator const PointerRNA&() { return ptr; }\n"
2651 " bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type)? true: false; }\n"
2652 " operator void*() { return ptr.data; }\n"
2653 " operator bool() { return ptr.data != NULL; }\n"
2655 " PointerRNA ptr;\n"
2659 "template<typename T, int Tsize>\n"
2665 " Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); }\n"
2666 " const Array<T, Tsize>& operator=(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); return *this; }\n"
2668 " operator T*() { return data; }\n"
2671 "typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
2672 "typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
2673 "typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
2675 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2676 "class CollectionIterator {\n"
2678 " CollectionIterator() : t(iter.ptr), init(false) { iter.valid= false; }\n"
2679 " ~CollectionIterator(void) { if(init) Tend(&iter); };\n"
2681 " operator bool(void)\n"
2682 " { return iter.valid != 0; }\n"
2683 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator++() { Tnext(&iter); t = T(iter.ptr); return *this; }\n"
2685 " T& operator*(void) { return t; }\n"
2686 " T* operator->(void) { return &t; }\n"
2687 " bool operator==(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid == other.iter.valid; }\n"
2688 " bool operator!=(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid != other.iter.valid; }\n"
2690 " void begin(const Pointer& ptr)\n"
2691 " { if(init) Tend(&iter); Tbegin(&iter, (PointerRNA*)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
2694 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator=(const CollectionIterator<T, Tbegin, Tnext, Tend>& copy) {}\n"
2696 " CollectionPropertyIterator iter;\n"
2701 "template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2702 "class Collection {\n"
2704 " Collection(const PointerRNA& p) : ptr(p) {}\n"
2706 " void begin(CollectionIterator<T, Tbegin, Tnext, Tend>& iter)\n"
2707 " { iter.begin(ptr); }\n"
2708 " CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
2709 " { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
2712 " PointerRNA ptr;\n"
2716 static void rna_generate_header_cpp(BlenderRNA *brna, FILE *f)
2722 fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
2723 fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
2725 fprintf(f, "/* Automatically generated classes for the Data API.\n"
2726 " Do not edit manually, changes will be overwritten. */\n\n");
2728 fprintf(f, "#include \"RNA_blender.h\"\n");
2729 fprintf(f, "#include \"RNA_types.h\"\n");
2731 fprintf(f, "%s", cpp_classes);
2733 fprintf(f, "/**************** Declarations ****************/\n\n");
2735 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2736 fprintf(f, "class %s;\n", ds->srna->identifier);
2739 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2742 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2744 fprintf(f, "class %s : public %s {\n", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2745 fprintf(f, "public:\n");
2746 fprintf(f, "\t%s(const PointerRNA& ptr) :\n\t\t%s(ptr)", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2747 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2748 if(!(dp->prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN)))
2749 if(dp->prop->type == PROP_COLLECTION)
2750 fprintf(f, ",\n\t\t%s(ptr)", dp->prop->identifier);
2751 fprintf(f, "\n\t\t{}\n\n");
2753 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2754 rna_def_property_funcs_header_cpp(f, ds->srna, dp);
2755 fprintf(f, "};\n\n");
2759 fprintf(f, "/**************** Implementation ****************/\n");
2761 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2762 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2763 rna_def_property_funcs_impl_cpp(f, ds->srna, dp);
2768 fprintf(f, "}\n\n#endif /* __RNA_BLENDER_CPP_H__ */\n\n");
2771 static void make_bad_file(const char *file, int line)
2773 FILE *fp= fopen(file, "w");
2774 fprintf(fp, "#error \"Error! can't make correct RNA file from %s:%d, STUPID!\"\n", __FILE__, line);
2778 static int rna_preprocess(const char *outfile)
2785 const char *deps[3]; /* expand as needed */
2790 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2791 if(PROCESS_ITEMS[i].define) {
2792 PROCESS_ITEMS[i].define(brna);
2794 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2796 ds->filename= PROCESS_ITEMS[i].filename;
2803 /* create RNA_blender_cpp.h */
2804 strcpy(deffile, outfile);
2805 strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
2807 status= (DefRNA.error != 0);
2810 make_bad_file(deffile, __LINE__);
2813 file = fopen(deffile, "w");
2816 printf ("Unable to open file: %s\n", deffile);
2820 rna_generate_header_cpp(brna, file);
2822 status= (DefRNA.error != 0);
2826 replace_if_different(deffile, NULL);
2830 /* create rna_gen_*.c files */
2831 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2832 strcpy(deffile, outfile);
2833 strcat(deffile, PROCESS_ITEMS[i].filename);
2834 deffile[strlen(deffile)-2] = '\0';
2835 strcat(deffile, "_gen.c" TMP_EXT);
2838 make_bad_file(deffile, __LINE__);
2841 file = fopen(deffile, "w");
2844 printf ("Unable to open file: %s\n", deffile);
2848 rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
2850 status= (DefRNA.error != 0);
2854 /* avoid unneeded rebuilds */
2855 deps[0]= PROCESS_ITEMS[i].filename;
2856 deps[1]= PROCESS_ITEMS[i].api_filename;
2859 replace_if_different(deffile, deps);
2862 /* create RNA_blender.h */
2863 strcpy(deffile, outfile);
2864 strcat(deffile, "RNA_blender.h" TMP_EXT);
2867 make_bad_file(deffile, __LINE__);
2870 file = fopen(deffile, "w");
2873 printf ("Unable to open file: %s\n", deffile);
2877 rna_generate_header(brna, file);
2879 status= (DefRNA.error != 0);
2883 replace_if_different(deffile, NULL);
2886 RNA_define_free(brna);
2892 static void mem_error_cb(const char *errorStr)
2894 fprintf(stderr, "%s", errorStr);
2898 int main(int argc, char **argv)
2900 int totblock, return_status = 0;
2903 printf("Usage: %s outdirectory/\n", argv[0]);
2907 printf("Running makesrna, program versions %s\n", RNA_VERSION_DATE);
2908 makesrna_path= argv[0];
2909 return_status= rna_preprocess(argv[1]);
2912 totblock= MEM_get_memory_blocks_in_use();
2914 printf("Error Totblock: %d\n",totblock);
2915 MEM_set_error_callback(mem_error_cb);
2919 return return_status;