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 *****
25 /** \file blender/makesrna/intern/makesrna.c
37 #include "MEM_guardedalloc.h"
39 #include "RNA_access.h"
40 #include "RNA_define.h"
41 #include "RNA_types.h"
43 #include "rna_internal.h"
45 #define RNA_VERSION_DATE "$Id$"
49 #define snprintf _snprintf
53 /* Replace if different */
54 #define TMP_EXT ".tmp"
57 /* copied from BLI_file_older */
59 static int file_older(const char *file1, const char *file2)
62 // printf("compare: %s %s\n", file1, file2);
64 if(stat(file1, &st1)) return 0;
65 if(stat(file2, &st2)) return 0;
67 return (st1.st_mtime < st2.st_mtime);
69 static const char *makesrna_path= NULL;
71 static int replace_if_different(char *tmpfile, const char *dep_files[])
73 // return 0; // use for testing had edited rna
77 FILE *file_test= fopen(orgfile, "rb"); \
80 if(fp_org) fclose(fp_org); \
81 if(fp_new) fclose(fp_new); \
82 if(remove(orgfile) != 0) { \
83 fprintf(stderr, "%s:%d, Remove Error (%s): \"%s\"\n", __FILE__, __LINE__, strerror(errno), orgfile); \
88 if(rename(tmpfile, orgfile) != 0) { \
89 fprintf(stderr, "%s:%d, Rename Error (%s): \"%s\" -> \"%s\"\n", __FILE__, __LINE__, strerror(errno), tmpfile, orgfile); \
97 FILE *fp_new= NULL, *fp_org= NULL;
99 char *arr_new, *arr_org;
104 strcpy(orgfile, tmpfile);
105 orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* strip '.tmp' */
107 fp_org= fopen(orgfile, "rb");
114 /* XXX, trick to work around dependancy problem
115 * assumes dep_files is in the same dir as makesrna.c, which is true for now. */
118 /* first check if makesrna.c is newer then generated files
119 * for development on makesrna.c you may want to disable this */
120 if(file_older(orgfile, __FILE__)) {
124 if(file_older(orgfile, makesrna_path)) {
128 /* now check if any files we depend on are newer then any generated files */
131 for(pass=0; dep_files[pass]; pass++) {
132 char from_path[4096]= __FILE__;
136 p1= strrchr(from_path, '/');
137 p2= strrchr(from_path, '\\');
138 strcpy((p1 > p2 ? p1 : p2)+1, dep_files[pass]);
139 /* account for build deps, if makesrna.c (this file) is newer */
140 if(file_older(orgfile, from_path)) {
146 /* XXX end dep trick */
149 fp_new= fopen(tmpfile, "rb");
152 /* shouldn't happen, just to be safe */
153 fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
158 fseek(fp_new, 0L, SEEK_END); len_new = ftell(fp_new); fseek(fp_new, 0L, SEEK_SET);
159 fseek(fp_org, 0L, SEEK_END); len_org = ftell(fp_org); fseek(fp_org, 0L, SEEK_SET);
162 if(len_new != len_org) {
168 /* now compare the files... */
169 arr_new= MEM_mallocN(sizeof(char)*len_new, "rna_cmp_file_new");
170 arr_org= MEM_mallocN(sizeof(char)*len_org, "rna_cmp_file_org");
172 if(fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
173 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
174 if(fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
175 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
180 cmp= memcmp(arr_new, arr_org, len_new);
196 /* Helper to solve keyword problems with C/C++ */
198 static const char *rna_safe_id(const char *id)
200 if(strcmp(id, "default") == 0)
201 return "default_value";
202 else if(strcmp(id, "operator") == 0)
203 return "operator_value";
210 static int cmp_struct(const void *a, const void *b)
212 const StructRNA *structa= *(const StructRNA**)a;
213 const StructRNA *structb= *(const StructRNA**)b;
215 return strcmp(structa->identifier, structb->identifier);
218 static int cmp_property(const void *a, const void *b)
220 const PropertyRNA *propa= *(const PropertyRNA**)a;
221 const PropertyRNA *propb= *(const PropertyRNA**)b;
223 if(strcmp(propa->identifier, "rna_type") == 0) return -1;
224 else if(strcmp(propb->identifier, "rna_type") == 0) return 1;
226 if(strcmp(propa->identifier, "name") == 0) return -1;
227 else if(strcmp(propb->identifier, "name") == 0) return 1;
229 return strcmp(propa->name, propb->name);
232 static int cmp_def_struct(const void *a, const void *b)
234 const StructDefRNA *dsa= *(const StructDefRNA**)a;
235 const StructDefRNA *dsb= *(const StructDefRNA**)b;
237 return cmp_struct(&dsa->srna, &dsb->srna);
240 static int cmp_def_property(const void *a, const void *b)
242 const PropertyDefRNA *dpa= *(const PropertyDefRNA**)a;
243 const PropertyDefRNA *dpb= *(const PropertyDefRNA**)b;
245 return cmp_property(&dpa->prop, &dpb->prop);
248 static void rna_sortlist(ListBase *listbase, int(*cmp)(const void*, const void*))
254 if(listbase->first == listbase->last)
257 for(size=0, link=listbase->first; link; link=link->next)
260 array= MEM_mallocN(sizeof(void*)*size, "rna_sortlist");
261 for(a=0, link=listbase->first; link; link=link->next, a++)
264 qsort(array, size, sizeof(void*), cmp);
266 listbase->first= listbase->last= NULL;
267 for(a=0; a<size; a++) {
269 link->next= link->prev= NULL;
270 rna_addtail(listbase, link);
278 static void rna_print_c_string(FILE *f, const char *str)
280 static const char *escape[] = {"\''", "\"\"", "\??", "\\\\","\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", NULL};
289 for(i=0; str[i]; i++) {
290 for(j=0; escape[j]; j++)
291 if(str[i] == escape[j][0])
294 if(escape[j]) fprintf(f, "\\%c", escape[j][1]);
295 else fprintf(f, "%c", str[i]);
300 static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
302 if(dp->dnastructfromname && dp->dnastructfromprop)
303 fprintf(f, " %s *data= (%s*)(((%s*)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname, dp->dnastructfromname, dp->dnastructfromprop);
305 fprintf(f, " %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
308 static void rna_print_id_get(FILE *f, PropertyDefRNA *dp)
310 fprintf(f, " ID *id= ptr->id.data;\n");
313 static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
319 snprintf(buffer, sizeof(buffer), "%s_%s_%s", structname, propname, type);
320 result= MEM_callocN(sizeof(char)*strlen(buffer)+1, "rna_alloc_function_name");
321 strcpy(result, buffer);
323 alloc= MEM_callocN(sizeof(AllocDefRNA), "AllocDefRNA");
325 rna_addtail(&DefRNA.allocs, alloc);
330 static StructRNA *rna_find_struct(const char *identifier)
334 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
335 if(strcmp(ds->srna->identifier, identifier)==0)
341 static const char *rna_find_type(const char *type)
345 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
346 if(ds->dnaname && strcmp(ds->dnaname, type)==0)
347 return ds->srna->identifier;
352 static const char *rna_find_dna_type(const char *type)
356 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
357 if(strcmp(ds->srna->identifier, type)==0)
363 static const char *rna_type_type_name(PropertyRNA *prop)
373 if(prop->flag & PROP_THICK_WRAP) {
377 return "const char*";
384 static const char *rna_type_type(PropertyRNA *prop)
388 type= rna_type_type_name(prop);
396 static const char *rna_type_struct(PropertyRNA *prop)
400 type= rna_type_type_name(prop);
408 static const char *rna_parameter_type_name(PropertyRNA *parm)
412 type= rna_type_type_name(parm);
419 PointerPropertyRNA *pparm= (PointerPropertyRNA*)parm;
421 if(parm->flag & PROP_RNAPTR)
424 return rna_find_dna_type((const char *)pparm->type);
426 case PROP_COLLECTION: {
430 return "<error, no type specified>";
434 static int rna_enum_bitmask(PropertyRNA *prop)
436 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
440 for(a=0; a<eprop->totitem; a++)
441 if(eprop->item[a].identifier[0])
442 mask |= eprop->item[a].value;
448 static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
450 if(prop->type == PROP_FLOAT && (prop->subtype==PROP_COLOR || prop->subtype==PROP_COLOR_GAMMA))
451 if(strcmp(dp->dnatype, "float") != 0 && strcmp(dp->dnatype, "double") != 0)
457 static const char *rna_function_string(void *func)
459 return (func)? (const char*)func: "NULL";
462 static void rna_float_print(FILE *f, float num)
464 if(num == -FLT_MAX) fprintf(f, "-FLT_MAX");
465 else if(num == FLT_MAX) fprintf(f, "FLT_MAX");
466 else if((int)num == num) fprintf(f, "%.1ff", num);
467 else fprintf(f, "%.10ff", num);
470 static void rna_int_print(FILE *f, int num)
472 if(num == INT_MIN) fprintf(f, "INT_MIN");
473 else if(num == INT_MAX) fprintf(f, "INT_MAX");
474 else fprintf(f, "%d", num);
477 static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
481 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
485 if(!dp->dnastructname || !dp->dnaname) {
486 fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
492 if(dp->dnatype && *dp->dnatype) {
494 if(prop->type == PROP_FLOAT) {
495 if(IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
496 if(prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */
497 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));
503 else if(prop->type == PROP_INT || prop->type == PROP_BOOLEAN || prop->type == PROP_ENUM) {
504 if(IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
505 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));
514 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
518 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
519 fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
522 fprintf(f, " %s(ptr, value);\n", manualfunc);
525 const PropertySubType subtype= prop->subtype;
526 const char *string_copy_func= (subtype==PROP_FILEPATH || subtype==PROP_DIRPATH || subtype==PROP_FILENAME) ? "BLI_strncpy" : "BLI_strncpy_utf8";
528 rna_print_data_get(f, dp);
530 fprintf(f, " %s(value, data->%s, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
532 fprintf(f, " %s(value, data->%s, sizeof(data->%s));\n", string_copy_func, dp->dnaname, dp->dnaname);
538 fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func);
541 fprintf(f, " return %s(ptr);\n", manualfunc);
544 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
545 rna_print_data_get(f, dp);
546 if(dp->dnapointerlevel == 0)
547 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, &data->%s);\n", (const char*)pprop->type, dp->dnaname);
549 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, data->%s);\n", (const char*)pprop->type, dp->dnaname);
554 case PROP_COLLECTION: {
555 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
557 fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
560 if(strcmp(manualfunc, "rna_iterator_listbase_get") == 0 ||
561 strcmp(manualfunc, "rna_iterator_array_get") == 0 ||
562 strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0)
563 fprintf(f, " return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", (cprop->item_type)? (const char*)cprop->item_type: "UnknownType", manualfunc);
565 fprintf(f, " return %s(iter);\n", manualfunc);
571 if(prop->arraydimension) {
572 if(prop->flag & PROP_DYNAMIC)
573 fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
575 fprintf(f, "void %s(PointerRNA *ptr, %s values[%u])\n", func, rna_type_type(prop), prop->totarraylength);
579 fprintf(f, " %s(ptr, values);\n", manualfunc);
582 rna_print_data_get(f, dp);
584 if(prop->flag & PROP_DYNAMIC) {
585 char *lenfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get_length");
586 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
587 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
588 fprintf(f, " for(i=0; i<len; i++) {\n");
592 fprintf(f, " int i;\n\n");
593 fprintf(f, " for(i=0; i<%u; i++) {\n", prop->totarraylength);
596 if(dp->dnaarraylength == 1) {
597 if(prop->type == PROP_BOOLEAN && dp->booleanbit)
598 fprintf(f, " values[i]= %s((data->%s & (%d<<i)) != 0);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
600 fprintf(f, " values[i]= (%s)%s((&data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
603 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
604 fprintf(f, " values[i]= %s((data->%s[i] & ", (dp->booleannegative)? "!": "", dp->dnaname);
605 rna_int_print(f, dp->booleanbit);
606 fprintf(f, ") != 0);\n");
608 else if(rna_color_quantize(prop, dp))
609 fprintf(f, " values[i]= (%s)(data->%s[i]*(1.0f/255.0f));\n", rna_type_type(prop), dp->dnaname);
611 fprintf(f, " values[i]= (%s)%s(((%s*)data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname);
613 fprintf(f, " values[i]= (%s)%s((data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
620 fprintf(f, "%s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
624 fprintf(f, " return %s(ptr);\n", manualfunc);
627 rna_print_data_get(f, dp);
628 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
629 fprintf(f, " return %s(((data->%s) & ", (dp->booleannegative)? "!": "", dp->dnaname);
630 rna_int_print(f, dp->booleanbit);
631 fprintf(f, ") != 0);\n");
633 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
634 fprintf(f, " return ((data->%s) & ", dp->dnaname);
635 rna_int_print(f, rna_enum_bitmask(prop));
639 fprintf(f, " return (%s)%s(data->%s);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
650 /* defined min/max variables to be used by rna_clamp_value() */
651 static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
653 if(prop->type == PROP_FLOAT) {
654 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
656 fprintf(f, " float prop_clamp_min, prop_clamp_max;\n");
657 fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max);\n", rna_function_string(fprop->range));
660 else if(prop->type == PROP_INT) {
661 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
663 fprintf(f, " int prop_clamp_min, prop_clamp_max;\n");
664 fprintf(f, " %s(ptr, &prop_clamp_min, &prop_clamp_max);\n", rna_function_string(iprop->range));
669 static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
671 if(prop->type == PROP_INT) {
672 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
674 if(iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
675 if(array) fprintf(f, "CLAMPIS(values[i], ");
676 else fprintf(f, "CLAMPIS(value, ");
678 fprintf(f, "prop_clamp_min, prop_clamp_max);");
681 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
682 rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
687 else if(prop->type == PROP_FLOAT) {
688 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
690 if(fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
691 if(array) fprintf(f, "CLAMPIS(values[i], ");
692 else fprintf(f, "CLAMPIS(value, ");
694 fprintf(f, "prop_clamp_min, prop_clamp_max);");
697 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
698 rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
705 fprintf(f, "values[i];\n");
707 fprintf(f, "value;\n");
710 static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
714 if(!(prop->flag & PROP_EDITABLE))
716 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
720 if(!dp->dnastructname || !dp->dnaname) {
721 if(prop->flag & PROP_EDITABLE) {
722 fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
729 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set");
733 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
734 fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func);
737 fprintf(f, " %s(ptr, value);\n", manualfunc);
740 const PropertySubType subtype= prop->subtype;
741 const char *string_copy_func= (subtype==PROP_FILEPATH || subtype==PROP_DIRPATH || subtype==PROP_FILENAME) ? "BLI_strncpy" : "BLI_strncpy_utf8";
743 rna_print_data_get(f, dp);
745 fprintf(f, " %s(data->%s, value, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
747 fprintf(f, " %s(data->%s, value, sizeof(data->%s));\n", string_copy_func, dp->dnaname, dp->dnaname);
753 fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func);
756 fprintf(f, " %s(ptr, value);\n", manualfunc);
759 rna_print_data_get(f, dp);
761 if(prop->flag & PROP_ID_SELF_CHECK) {
762 rna_print_id_get(f, dp);
763 fprintf(f, " if(id==value.data) return;\n\n");
766 if(prop->flag & PROP_ID_REFCOUNT) {
767 fprintf(f, "\n if(data->%s)\n", dp->dnaname);
768 fprintf(f, " id_us_min((ID*)data->%s);\n", dp->dnaname);
769 fprintf(f, " if(value.data)\n");
770 fprintf(f, " id_us_plus((ID*)value.data);\n\n");
773 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
774 StructRNA *type= rna_find_struct((const char*)pprop->type);
775 if(type && (type->flag & STRUCT_ID)) {
776 fprintf(f, " if(value.data)\n");
777 fprintf(f, " id_lib_extern((ID*)value.data);\n\n");
781 fprintf(f, " data->%s= value.data;\n", dp->dnaname);
788 if(prop->arraydimension) {
789 if(prop->flag & PROP_DYNAMIC)
790 fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
792 fprintf(f, "void %s(PointerRNA *ptr, const %s values[%u])\n", func, rna_type_type(prop), prop->totarraylength);
796 fprintf(f, " %s(ptr, values);\n", manualfunc);
799 rna_print_data_get(f, dp);
801 if(prop->flag & PROP_DYNAMIC) {
802 char *lenfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set_length");
803 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
804 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
805 rna_clamp_value_range(f, prop);
806 fprintf(f, " for(i=0; i<len; i++) {\n");
810 fprintf(f, " int i;\n\n");
811 rna_clamp_value_range(f, prop);
812 fprintf(f, " for(i=0; i<%u; i++) {\n", prop->totarraylength);
815 if(dp->dnaarraylength == 1) {
816 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
817 fprintf(f, " if(%svalues[i]) data->%s |= (%d<<i);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
818 fprintf(f, " else data->%s &= ~(%d<<i);\n", dp->dnaname, dp->booleanbit);
821 fprintf(f, " (&data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
822 rna_clamp_value(f, prop, 1);
826 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
827 fprintf(f, " if(%svalues[i]) data->%s[i] |= ", (dp->booleannegative)? "!": "", dp->dnaname);
828 rna_int_print(f, dp->booleanbit);
830 fprintf(f, " else data->%s[i] &= ~", dp->dnaname);
831 rna_int_print(f, dp->booleanbit);
834 else if(rna_color_quantize(prop, dp)) {
835 fprintf(f, " data->%s[i]= FTOCHAR(values[i]);\n", dp->dnaname);
839 fprintf(f, " ((%s*)data->%s)[i]= %s", dp->dnatype, dp->dnaname, (dp->booleannegative)? "!": "");
841 fprintf(f, " (data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
842 rna_clamp_value(f, prop, 1);
850 fprintf(f, "void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
854 fprintf(f, " %s(ptr, value);\n", manualfunc);
857 rna_print_data_get(f, dp);
858 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
859 fprintf(f, " if(%svalue) data->%s |= ", (dp->booleannegative)? "!": "", dp->dnaname);
860 rna_int_print(f, dp->booleanbit);
862 fprintf(f, " else data->%s &= ~", dp->dnaname);
863 rna_int_print(f, dp->booleanbit);
866 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
867 fprintf(f, " data->%s &= ~", dp->dnaname);
868 rna_int_print(f, rna_enum_bitmask(prop));
870 fprintf(f, " data->%s |= value;\n", dp->dnaname);
873 rna_clamp_value_range(f, prop);
874 fprintf(f, " data->%s= %s", dp->dnaname, (dp->booleannegative)? "!": "");
875 rna_clamp_value(f, prop, 0);
886 static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
890 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
893 if(prop->type == PROP_STRING) {
895 if(!dp->dnastructname || !dp->dnaname) {
896 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
902 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
904 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
907 fprintf(f, " return %s(ptr);\n", manualfunc);
910 rna_print_data_get(f, dp);
911 fprintf(f, " return strlen(data->%s);\n", dp->dnaname);
915 else if(prop->type == PROP_COLLECTION) {
917 if(prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed)|| !dp->dnaname)) {
918 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
924 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
926 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
929 fprintf(f, " return %s(ptr);\n", manualfunc);
932 rna_print_data_get(f, dp);
933 if(dp->dnalengthname)
934 fprintf(f, " return (data->%s == NULL)? 0: data->%s;\n", dp->dnaname, dp->dnalengthname);
936 fprintf(f, " return (data->%s == NULL)? 0: %d;\n", dp->dnaname, dp->dnalengthfixed);
944 static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
946 char *func, *getfunc;
948 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
952 if(!dp->dnastructname || !dp->dnaname) {
953 fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
959 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "begin");
961 fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
965 rna_print_data_get(f, dp);
967 fprintf(f, "\n memset(iter, 0, sizeof(*iter));\n");
968 fprintf(f, " iter->parent= *ptr;\n");
969 fprintf(f, " iter->prop= (PropertyRNA*)&rna_%s_%s;\n", srna->identifier, prop->identifier);
971 if(dp->dnalengthname || dp->dnalengthfixed) {
973 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
976 if(dp->dnalengthname)
977 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);
979 fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed);
984 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
985 else if(dp->dnapointerlevel == 0)
986 fprintf(f, "\n rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname);
988 fprintf(f, "\n rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname);
991 getfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
993 fprintf(f, "\n if(iter->valid)\n");
994 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
1002 static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc, const char *nextfunc)
1004 /* note on indices, this is for external functions and ignores skipped values.
1005 * so the the index can only be checked against the length when there is no 'skip' funcion. */
1008 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
1012 if(!dp->dnastructname || !dp->dnaname)
1015 /* only supported in case of standard next functions */
1016 if(strcmp(nextfunc, "rna_iterator_array_next") == 0);
1017 else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0);
1021 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_int");
1023 fprintf(f, "int %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func);
1027 fprintf(f, "\n return %s(ptr, index, r_ptr);\n", manualfunc);
1028 fprintf(f, "}\n\n");
1032 fprintf(f, " int found= 0;\n");
1033 fprintf(f, " CollectionPropertyIterator iter;\n\n");
1035 fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1036 fprintf(f, " if(iter.valid){\n");
1038 if(strcmp(nextfunc, "rna_iterator_array_next") == 0) {
1039 fprintf(f, " ArrayIterator *internal= iter.internal;\n");
1040 fprintf(f, " if(index < 0 || index >= internal->length) {\n");
1041 fprintf(f, "#ifdef __GNUC__\n");
1042 fprintf(f, " printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, index);\n");
1043 fprintf(f, "#else\n");
1044 fprintf(f, " printf(\"Array iterator out of range: (index %%d)\\n\", index);\n");
1045 fprintf(f, "#endif\n");
1047 fprintf(f, " else if(internal->skip) {\n");
1048 fprintf(f, " while(index-- > 0 && iter.valid) {\n");
1049 fprintf(f, " rna_iterator_array_next(&iter);\n");
1051 fprintf(f, " found= (index == -1 && iter.valid);\n");
1053 fprintf(f, " else {\n");
1054 fprintf(f, " internal->ptr += internal->itemsize*index;\n");
1055 fprintf(f, " found= 1;\n");
1058 else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
1059 fprintf(f, " ListBaseIterator *internal= iter.internal;\n");
1060 fprintf(f, " if(internal->skip) {\n");
1061 fprintf(f, " while(index-- > 0 && iter.valid) {\n");
1062 fprintf(f, " rna_iterator_listbase_next(&iter);\n");
1064 fprintf(f, " found= (index == -1 && iter.valid);\n");
1066 fprintf(f, " else {\n");
1067 fprintf(f, " while(index-- > 0 && internal->link)\n");
1068 fprintf(f, " internal->link= internal->link->next;\n");
1069 fprintf(f, " found= (index == -1 && internal->link);\n");
1073 fprintf(f, " if(found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, rna_safe_id(prop->identifier));
1074 fprintf(f, " }\n\n");
1075 fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1077 fprintf(f, " return found;\n");
1080 rna_print_data_get(f, dp);
1081 item_type= (cprop->item_type)? (const char*)cprop->item_type: "UnknownType";
1083 if(dp->dnalengthname || dp->dnalengthfixed) {
1084 if(dp->dnalengthname)
1085 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);
1087 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);
1090 if(dp->dnapointerlevel == 0)
1091 fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, &data->%s, index);\n", item_type, dp->dnaname);
1093 fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, data->%s, index);\n", item_type, dp->dnaname);
1097 fprintf(f, "}\n\n");
1102 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1104 char *func, *getfunc;
1106 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
1112 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "next");
1114 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1116 fprintf(f, " %s(iter);\n", manualfunc);
1118 getfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
1120 fprintf(f, "\n if(iter->valid)\n");
1121 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
1123 fprintf(f, "}\n\n");
1128 static char *rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1132 if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL)
1135 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "end");
1137 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1140 fprintf(f, " %s(iter);\n", manualfunc);
1141 fprintf(f, "}\n\n");
1146 static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
1148 if(dp->dnapointerlevel != 0)
1150 if(!dp->dnatype || !dp->dnaname || !dp->dnastructname)
1153 if(strcmp(dp->dnatype, "char") == 0) {
1154 prop->rawtype= PROP_RAW_CHAR;
1155 prop->flag |= PROP_RAW_ACCESS;
1157 else if(strcmp(dp->dnatype, "short") == 0) {
1158 prop->rawtype= PROP_RAW_SHORT;
1159 prop->flag |= PROP_RAW_ACCESS;
1161 else if(strcmp(dp->dnatype, "int") == 0) {
1162 prop->rawtype= PROP_RAW_INT;
1163 prop->flag |= PROP_RAW_ACCESS;
1165 else if(strcmp(dp->dnatype, "float") == 0) {
1166 prop->rawtype= PROP_RAW_FLOAT;
1167 prop->flag |= PROP_RAW_ACCESS;
1169 else if(strcmp(dp->dnatype, "double") == 0) {
1170 prop->rawtype= PROP_RAW_DOUBLE;
1171 prop->flag |= PROP_RAW_ACCESS;
1175 static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
1177 PropertyDefRNA *dp= rna_find_struct_property_def(srna, prop);
1179 fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype);
1182 static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1188 switch(prop->type) {
1189 case PROP_BOOLEAN: {
1190 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1192 if(!prop->arraydimension) {
1193 if(!bprop->get && !bprop->set && !dp->booleanbit)
1194 rna_set_raw_property(dp, prop);
1196 bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)bprop->get);
1197 bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)bprop->set);
1200 bprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)bprop->getarray);
1201 bprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)bprop->setarray);
1206 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1208 if(!prop->arraydimension) {
1209 if(!iprop->get && !iprop->set)
1210 rna_set_raw_property(dp, prop);
1212 iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)iprop->get);
1213 iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)iprop->set);
1216 if(!iprop->getarray && !iprop->setarray)
1217 rna_set_raw_property(dp, prop);
1219 iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)iprop->getarray);
1220 iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)iprop->setarray);
1225 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1227 if(!prop->arraydimension) {
1228 if(!fprop->get && !fprop->set)
1229 rna_set_raw_property(dp, prop);
1231 fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)fprop->get);
1232 fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)fprop->set);
1235 if(!fprop->getarray && !fprop->setarray)
1236 rna_set_raw_property(dp, prop);
1238 fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)fprop->getarray);
1239 fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)fprop->setarray);
1244 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1246 eprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)eprop->get);
1247 eprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)eprop->set);
1251 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1253 sprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)sprop->get);
1254 sprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (const char*)sprop->length);
1255 sprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)sprop->set);
1258 case PROP_POINTER: {
1259 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1261 pprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)pprop->get);
1262 pprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (const char*)pprop->set);
1264 fprintf(stderr, "rna_def_property_funcs: %s.%s, pointer must have a struct type.\n", srna->identifier, prop->identifier);
1269 case PROP_COLLECTION: {
1270 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1271 const char *nextfunc= (const char*)cprop->next;
1273 if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0);
1274 else if(dp->dnalengthname || dp->dnalengthfixed)
1275 cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (const char*)cprop->length);
1277 /* test if we can allow raw array access, if it is using our standard
1278 * array get/next function, we can be sure it is an actual array */
1279 if(cprop->next && cprop->get)
1280 if(strcmp((const char*)cprop->next, "rna_iterator_array_next") == 0 &&
1281 strcmp((const char*)cprop->get, "rna_iterator_array_get") == 0)
1282 prop->flag |= PROP_RAW_ARRAY;
1284 cprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (const char*)cprop->get);
1285 cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp, (const char*)cprop->begin);
1286 cprop->next= (void*)rna_def_property_next_func(f, srna, prop, dp, (const char*)cprop->next);
1287 cprop->end= (void*)rna_def_property_end_func(f, srna, prop, dp, (const char*)cprop->end);
1288 cprop->lookupint= (void*)rna_def_property_lookup_int_func(f, srna, prop, dp, (const char*)cprop->lookupint, nextfunc);
1290 if(!(prop->flag & PROP_IDPROPERTY)) {
1292 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a begin function.\n", srna->identifier, prop->identifier);
1296 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a next function.\n", srna->identifier, prop->identifier);
1300 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a get function.\n", srna->identifier, prop->identifier);
1304 if(!cprop->item_type) {
1305 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a struct type.\n", srna->identifier, prop->identifier);
1313 static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1320 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1323 func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "");
1325 switch(prop->type) {
1328 if(!prop->arraydimension) {
1329 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1330 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1332 else if(prop->arraydimension && prop->totarraylength) {
1333 fprintf(f, "void %sget(PointerRNA *ptr, int values[%u]);\n", func, prop->totarraylength);
1334 //fprintf(f, "void %sset(PointerRNA *ptr, const int values[%d]);\n", func, prop->arraylength);
1337 fprintf(f, "void %sget(PointerRNA *ptr, int values[]);\n", func);
1338 //fprintf(f, "void %sset(PointerRNA *ptr, const int values[]);\n", func);
1343 if(!prop->arraydimension) {
1344 fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
1345 //fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
1347 else if(prop->arraydimension && prop->totarraylength) {
1348 fprintf(f, "void %sget(PointerRNA *ptr, float values[%u]);\n", func, prop->totarraylength);
1349 //fprintf(f, "void %sset(PointerRNA *ptr, const float values[%d]);\n", func, prop->arraylength);
1352 fprintf(f, "void %sget(PointerRNA *ptr, float values[]);\n", func);
1353 //fprintf(f, "void %sset(PointerRNA *ptr, const float values[]);\n", func);
1358 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1362 fprintf(f, "enum {\n");
1364 for(i=0; i<eprop->totitem; i++)
1365 if(eprop->item[i].identifier[0])
1366 fprintf(f, "\t%s_%s_%s = %d,\n", srna->identifier, prop->identifier, eprop->item[i].identifier, eprop->item[i].value);
1368 fprintf(f, "};\n\n");
1371 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1372 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1377 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1379 if(sprop->maxlength) {
1380 fprintf(f, "#define %s_%s_MAX %d\n\n", srna->identifier, prop->identifier, sprop->maxlength);
1383 fprintf(f, "void %sget(PointerRNA *ptr, char *value);\n", func);
1384 fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1385 //fprintf(f, "void %sset(PointerRNA *ptr, const char *value);\n", func);
1389 case PROP_POINTER: {
1390 fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func);
1391 //fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func);
1394 case PROP_COLLECTION: {
1395 fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
1396 fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
1397 fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
1398 //fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1399 //fprintf(f, "void %slookup_int(PointerRNA *ptr, int key, StructRNA **type);\n", func);
1400 //fprintf(f, "void %slookup_string(PointerRNA *ptr, const char *key, StructRNA **type);\n", func);
1408 static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1414 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1417 if(prop->name && prop->description && prop->description[0] != '\0')
1418 fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
1420 fprintf(f, "\t/* %s */\n", prop->name);
1422 fprintf(f, "\t/* */\n");
1424 switch(prop->type) {
1425 case PROP_BOOLEAN: {
1426 if(!prop->arraydimension)
1427 fprintf(f, "\tinline bool %s(void);", rna_safe_id(prop->identifier));
1429 fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier));
1433 if(!prop->arraydimension)
1434 fprintf(f, "\tinline int %s(void);", rna_safe_id(prop->identifier));
1436 fprintf(f, "\tinline Array<int, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier));
1440 if(!prop->arraydimension)
1441 fprintf(f, "\tinline float %s(void);", rna_safe_id(prop->identifier));
1443 fprintf(f, "\tinline Array<float, %u> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier));
1447 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1451 fprintf(f, "\tenum %s_enum {\n", rna_safe_id(prop->identifier));
1453 for(i=0; i<eprop->totitem; i++)
1454 if(eprop->item[i].identifier[0])
1455 fprintf(f, "\t\t%s_%s = %d,\n", rna_safe_id(prop->identifier), eprop->item[i].identifier, eprop->item[i].value);
1457 fprintf(f, "\t};\n");
1460 fprintf(f, "\tinline %s_enum %s(void);", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier));
1464 fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier));
1467 case PROP_POINTER: {
1468 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1471 fprintf(f, "\tinline %s %s(void);", (const char*)pprop->type, rna_safe_id(prop->identifier));
1473 fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier));
1476 case PROP_COLLECTION: {
1477 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1479 if(cprop->item_type)
1480 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char*)cprop->item_type, srna->identifier, rna_safe_id(prop->identifier));
1482 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, rna_safe_id(prop->identifier));
1490 static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1496 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1499 switch(prop->type) {
1500 case PROP_BOOLEAN: {
1501 if(!prop->arraydimension)
1502 fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1504 fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength, rna_safe_id(prop->identifier));
1508 if(!prop->arraydimension)
1509 fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1511 fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength, rna_safe_id(prop->identifier));
1515 if(!prop->arraydimension)
1516 fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1518 fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength, rna_safe_id(prop->identifier));
1522 fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", rna_safe_id(prop->identifier), srna->identifier, rna_safe_id(prop->identifier));
1527 fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1530 case PROP_POINTER: {
1531 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1534 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", (const char*)pprop->type, srna->identifier, rna_safe_id(prop->identifier));
1536 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, rna_safe_id(prop->identifier));
1539 case PROP_COLLECTION: {
1540 /*CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1543 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char*)cprop->type, srna->identifier, prop->identifier);
1545 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);*/
1553 static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
1557 PropertyDefRNA *dparm;
1559 const char *funcname, *valstr;
1561 const short has_data= (dfunc->cont.properties.first != NULL);
1562 int flag, pout, cptr, first;
1570 funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call");
1572 /* function definition */
1573 fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname);
1574 fprintf(f, "\n{\n");
1576 /* variable definitions */
1578 if(func->flag & FUNC_USE_SELF_ID) {
1579 fprintf(f, "\tstruct ID *_selfid;\n");
1582 if((func->flag & FUNC_NO_SELF)==0) {
1583 if(dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
1584 else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
1587 dparm= dfunc->cont.properties.first;
1588 for(; dparm; dparm= dparm->next) {
1589 type = dparm->prop->type;
1590 flag = dparm->prop->flag;
1591 pout = (flag & PROP_OUTPUT);
1592 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1594 if(dparm->prop==func->c_ret)
1595 ptrstr= cptr || dparm->prop->arraydimension ? "*" : "";
1596 /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
1597 else if (cptr || (flag & PROP_DYNAMIC))
1598 ptrstr= pout ? "**" : "*";
1599 /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
1600 else if (type == PROP_POINTER || dparm->prop->arraydimension)
1602 /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack, but type name for string props is already char*, so leave empty */
1603 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
1606 ptrstr= pout ? "*" : "";
1608 /* for dynamic parameters we pass an additional int for the length of the parameter */
1609 if (flag & PROP_DYNAMIC)
1610 fprintf(f, "\tint %s%s_len;\n", pout ? "*" : "", dparm->prop->identifier);
1612 fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
1616 fprintf(f, "\tchar *_data");
1617 if(func->c_ret) fprintf(f, ", *_retdata");
1623 if(func->flag & FUNC_USE_SELF_ID) {
1624 fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
1627 if((func->flag & FUNC_NO_SELF)==0) {
1628 if(dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
1629 else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
1633 fprintf(f, "\t_data= (char *)_parms->data;\n");
1636 dparm= dfunc->cont.properties.first;
1637 for(; dparm; dparm= dparm->next) {
1638 type = dparm->prop->type;
1639 flag = dparm->prop->flag;
1640 pout = (flag & PROP_OUTPUT);
1641 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1643 if(dparm->prop==func->c_ret)
1644 fprintf(f, "\t_retdata= _data;\n");
1646 const char *data_str;
1647 if (cptr || (flag & PROP_DYNAMIC)) {
1651 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
1655 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
1664 /* this must be kept in sync with RNA_parameter_length_get_data, we could just call the function directly, but this is faster */
1665 if (flag & PROP_DYNAMIC) {
1666 fprintf(f, "\t%s_len= %s((int *)_data);\n", dparm->prop->identifier, pout ? "" : "*");
1667 data_str= "(&(((char *)_data)[sizeof(void *)]))";
1672 fprintf(f, "\t%s= ", dparm->prop->identifier);
1675 fprintf(f, "%s", valstr);
1677 fprintf(f, "((%s%s%s)%s);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, data_str);
1681 fprintf(f, "\t_data+= %d;\n", rna_parameter_size_alloc(dparm->prop));
1687 if(func->c_ret) fprintf(f, "%s= ", func->c_ret->identifier);
1688 fprintf(f, "%s(", dfunc->call);
1692 if(func->flag & FUNC_USE_SELF_ID) {
1693 fprintf(f, "_selfid");
1697 if((func->flag & FUNC_NO_SELF)==0) {
1698 if(!first) fprintf(f, ", ");
1699 fprintf(f, "_self");
1703 if(func->flag & FUNC_USE_CONTEXT) {
1704 if(!first) fprintf(f, ", ");
1709 if(func->flag & FUNC_USE_REPORTS) {
1710 if(!first) fprintf(f, ", ");
1712 fprintf(f, "reports");
1715 dparm= dfunc->cont.properties.first;
1716 for(; dparm; dparm= dparm->next) {
1717 if(dparm->prop==func->c_ret)
1720 if(!first) fprintf(f, ", ");
1723 if (dparm->prop->flag & PROP_DYNAMIC)
1724 fprintf(f, "%s_len, %s", dparm->prop->identifier, dparm->prop->identifier);
1726 fprintf(f, "%s", dparm->prop->identifier);
1732 dparm= rna_find_parameter_def(func->c_ret);
1733 ptrstr= (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) || (dparm->prop->arraydimension))? "*": "";
1734 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);
1738 fprintf(f, "}\n\n");
1740 dfunc->gencall= funcname;
1743 static void rna_auto_types(void)
1748 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
1749 /* DNA name for Screen is patched in 2.5, we do the reverse here .. */
1750 if(ds->dnaname && strcmp(ds->dnaname, "Screen") == 0)
1751 ds->dnaname= "bScreen";
1753 for(dp=ds->cont.properties.first; dp; dp=dp->next) {
1754 if(dp->dnastructname && strcmp(dp->dnastructname, "Screen") == 0)
1755 dp->dnastructname= "bScreen";
1758 if(dp->prop->type == PROP_POINTER) {
1759 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1762 if(!pprop->type && !pprop->get)
1763 pprop->type= (StructRNA*)rna_find_type(dp->dnatype);
1766 type= rna_find_struct((const char*)pprop->type);
1767 if(type && (type->flag & STRUCT_ID_REFCOUNT))
1768 pprop->property.flag |= PROP_ID_REFCOUNT;
1771 else if(dp->prop->type== PROP_COLLECTION) {
1772 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1774 if(!cprop->item_type && !cprop->get && strcmp(dp->dnatype, "ListBase")==0)
1775 cprop->item_type= (StructRNA*)rna_find_type(dp->dnatype);
1782 static void rna_sort(BlenderRNA *brna)
1787 rna_sortlist(&brna->structs, cmp_struct);
1788 rna_sortlist(&DefRNA.structs, cmp_def_struct);
1790 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1791 rna_sortlist(&srna->cont.properties, cmp_property);
1793 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
1794 rna_sortlist(&ds->cont.properties, cmp_def_property);
1797 static const char *rna_property_structname(PropertyType type)
1800 case PROP_BOOLEAN: return "BooleanPropertyRNA";
1801 case PROP_INT: return "IntPropertyRNA";
1802 case PROP_FLOAT: return "FloatPropertyRNA";
1803 case PROP_STRING: return "StringPropertyRNA";
1804 case PROP_ENUM: return "EnumPropertyRNA";
1805 case PROP_POINTER: return "PointerPropertyRNA";
1806 case PROP_COLLECTION: return "CollectionPropertyRNA";
1807 default: return "UnknownPropertyRNA";
1811 static const char *rna_property_subtypename(PropertySubType type)
1814 case PROP_NONE: return "PROP_NONE";
1815 case PROP_FILEPATH: return "PROP_FILEPATH";
1816 case PROP_FILENAME: return "PROP_FILENAME";
1817 case PROP_DIRPATH: return "PROP_DIRPATH";
1818 case PROP_TRANSLATE: return "PROP_TRANSLATE";
1819 case PROP_UNSIGNED: return "PROP_UNSIGNED";
1820 case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
1821 case PROP_FACTOR: return "PROP_FACTOR";
1822 case PROP_ANGLE: return "PROP_ANGLE";
1823 case PROP_TIME: return "PROP_TIME";
1824 case PROP_DISTANCE: return "PROP_DISTANCE";
1825 case PROP_COLOR: return "PROP_COLOR";
1826 case PROP_TRANSLATION: return "PROP_TRANSLATION";
1827 case PROP_DIRECTION: return "PROP_DIRECTION";
1828 case PROP_MATRIX: return "PROP_MATRIX";
1829 case PROP_EULER: return "PROP_EULER";
1830 case PROP_QUATERNION: return "PROP_QUATERNION";
1831 case PROP_AXISANGLE: return "PROP_AXISANGLE";
1832 case PROP_VELOCITY: return "PROP_VELOCITY";
1833 case PROP_ACCELERATION: return "PROP_ACCELERATION";
1834 case PROP_XYZ: return "PROP_XYZ";
1835 case PROP_COLOR_GAMMA: return "PROP_COLOR_GAMMA";
1836 case PROP_COORDS: return "PROP_COORDS";
1837 case PROP_LAYER: return "PROP_LAYER";
1838 case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
1840 /* incase we dont have a type preset that includes the subtype */
1841 if(RNA_SUBTYPE_UNIT(type)) {
1842 return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
1845 return "PROP_SUBTYPE_UNKNOWN";
1851 static const char *rna_property_subtype_unit(PropertySubType type)
1853 switch(RNA_SUBTYPE_UNIT(type)) {
1854 case PROP_UNIT_NONE: return "PROP_UNIT_NONE";
1855 case PROP_UNIT_LENGTH: return "PROP_UNIT_LENGTH";
1856 case PROP_UNIT_AREA: return "PROP_UNIT_AREA";
1857 case PROP_UNIT_VOLUME: return "PROP_UNIT_VOLUME";
1858 case PROP_UNIT_MASS: return "PROP_UNIT_MASS";
1859 case PROP_UNIT_ROTATION: return "PROP_UNIT_ROTATION";
1860 case PROP_UNIT_TIME: return "PROP_UNIT_TIME";
1861 case PROP_UNIT_VELOCITY: return "PROP_UNIT_VELOCITY";
1862 case PROP_UNIT_ACCELERATION:return "PROP_UNIT_ACCELERATION";
1863 default: return "PROP_UNIT_UNKNOWN";
1867 static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
1871 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1872 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
1876 static void rna_generate_blender(BlenderRNA *brna, FILE *f)
1880 fprintf(f, "BlenderRNA BLENDER_RNA = {");
1882 srna= brna->structs.first;
1883 if(srna) fprintf(f, "{&RNA_%s, ", srna->identifier);
1884 else fprintf(f, "{NULL, ");
1886 srna= brna->structs.last;
1887 if(srna) fprintf(f, "&RNA_%s}", srna->identifier);
1888 else fprintf(f, "NULL}");
1890 fprintf(f, "};\n\n");
1893 static void rna_generate_property_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1901 for(prop=base->cont.properties.first; prop; prop=prop->next)
1902 fprintf(f, "%s%s rna_%s_%s;\n", "extern ", rna_property_structname(prop->type), base->identifier, prop->identifier);
1906 if(srna->cont.properties.first)
1909 for(prop=srna->cont.properties.first; prop; prop=prop->next)
1910 fprintf(f, "%s%s rna_%s_%s;\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, prop->identifier);
1914 static void rna_generate_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionRNA *func, FILE *f)
1918 for(parm= func->cont.properties.first; parm; parm= parm->next)
1919 fprintf(f, "%s%s rna_%s_%s_%s;\n", "extern ", rna_property_structname(parm->type), srna->identifier, func->identifier, parm->identifier);
1921 if(func->cont.properties.first)
1925 static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1932 for(func= base->functions.first; func; func= func->cont.next) {
1933 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", base->identifier, func->identifier);
1934 rna_generate_parameter_prototypes(brna, base, func, f);
1937 if(base->functions.first)
1943 for(func= srna->functions.first; func; func= func->cont.next) {
1944 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier);
1945 rna_generate_parameter_prototypes(brna, srna, func, f);
1948 if(srna->functions.first)
1952 static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionDefRNA *dfunc, FILE *f)
1955 PropertyDefRNA *dparm;
1956 StructDefRNA *dsrna;
1958 int flag, pout, cptr, first;
1961 dsrna= rna_find_struct_def(srna);
1965 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
1966 if(dparm->prop==func->c_ret) {
1967 if(dparm->prop->arraydimension)
1968 fprintf(f, "XXX no array return types yet"); /* XXX not supported */
1969 else if(dparm->prop->type == PROP_POINTER && !(dparm->prop->flag & PROP_RNAPTR))
1970 fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1972 fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1978 /* void if nothing to return */
1980 fprintf(f, "void ");
1983 fprintf(f, "%s(", dfunc->call);
1987 /* self, context and reports parameters */
1988 if(func->flag & FUNC_USE_SELF_ID) {
1989 fprintf(f, "struct ID *_selfid");
1993 if((func->flag & FUNC_NO_SELF)==0) {
1994 if(!first) fprintf(f, ", ");
1995 if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
1996 else fprintf(f, "struct %s *_self", srna->identifier);
2000 if(func->flag & FUNC_USE_CONTEXT) {
2001 if(!first) fprintf(f, ", ");
2003 fprintf(f, "bContext *C");
2006 if(func->flag & FUNC_USE_REPORTS) {
2007 if(!first) fprintf(f, ", ");
2009 fprintf(f, "ReportList *reports");
2012 /* defined parameters */
2013 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
2014 type = dparm->prop->type;
2015 flag = dparm->prop->flag;
2016 pout = (flag & PROP_OUTPUT);
2017 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
2019 if(dparm->prop==func->c_ret)
2022 if (cptr || (flag & PROP_DYNAMIC))
2023 ptrstr= pout ? "**" : "*";
2024 else if (type == PROP_POINTER || dparm->prop->arraydimension)
2026 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
2029 ptrstr= pout ? "*" : "";
2031 if(!first) fprintf(f, ", ");
2034 if (flag & PROP_DYNAMIC)
2035 fprintf(f, "int %s%s_len, ", pout ? "*" : "", dparm->prop->identifier);
2037 if(!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension)
2038 fprintf(f, "%s%s %s[%u]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->totarraylength);
2040 fprintf(f, "%s%s %s%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
2047 static void rna_generate_static_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
2050 FunctionDefRNA *dfunc;
2053 for(func= srna->functions.first; func; func= func->cont.next) {
2054 dfunc= rna_find_function_def(func);
2058 fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
2062 rna_generate_static_parameter_prototypes(brna, srna, dfunc, f);
2069 static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
2071 char *strnest= "", *errnest= "";
2072 int len, freenest= 0;
2077 strnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> strnest");
2078 errnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> errnest");
2080 strcpy(strnest, "_"); strcat(strnest, nest);
2081 strcpy(errnest, "."); strcat(errnest, nest);
2086 switch(prop->type) {
2088 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2089 int i, defaultfound= 0, totflag= 0;
2092 fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
2094 for(i=0; i<eprop->totitem; i++) {
2095 fprintf(f, "{%d, ", eprop->item[i].value);
2096 rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
2097 fprintf(f, "%d, ", eprop->item[i].icon);
2098 rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
2099 rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
2101 if(eprop->item[i].identifier[0]) {
2102 if(prop->flag & PROP_ENUM_FLAG) {
2103 totflag |= eprop->item[i].value;
2106 if(eprop->defaultvalue == eprop->item[i].value) {
2113 fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
2115 if(prop->flag & PROP_ENUM_FLAG) {
2116 if(eprop->defaultvalue & ~totflag) {
2117 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default includes unused bits (%d).\n", srna->identifier, errnest, prop->identifier, eprop->defaultvalue & ~totflag);
2123 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
2129 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum must have items defined.\n", srna->identifier, errnest, prop->identifier);
2134 case PROP_BOOLEAN: {
2135 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
2138 if(prop->arraydimension && prop->totarraylength) {
2139 fprintf(f, "static int rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
2141 for(i=0; i<prop->totarraylength; i++) {
2142 if(bprop->defaultarray)
2143 fprintf(f, "%d", bprop->defaultarray[i]);
2145 fprintf(f, "%d", bprop->defaultvalue);
2146 if(i != prop->totarraylength-1)
2147 fprintf(f, ",\n\t");
2150 fprintf(f, "\n};\n\n");
2155 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2158 if(prop->arraydimension && prop->totarraylength) {
2159 fprintf(f, "static int rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
2161 for(i=0; i<prop->totarraylength; i++) {
2162 if(iprop->defaultarray)
2163 fprintf(f, "%d", iprop->defaultarray[i]);
2165 fprintf(f, "%d", iprop->defaultvalue);
2166 if(i != prop->totarraylength-1)
2167 fprintf(f, ",\n\t");
2170 fprintf(f, "\n};\n\n");
2175 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2178 if(prop->arraydimension && prop->totarraylength) {
2179 fprintf(f, "static float rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
2181 for(i=0; i<prop->totarraylength; i++) {
2182 if(fprop->defaultarray)
2183 rna_float_print(f, fprop->defaultarray[i]);
2185 rna_float_print(f, fprop->defaultvalue);
2186 if(i != prop->totarraylength-1)
2187 fprintf(f, ",\n\t");
2190 fprintf(f, "\n};\n\n");
2198 fprintf(f, "%s%s rna_%s%s_%s = {\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, strnest, prop->identifier);
2200 if(prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
2201 else fprintf(f, "\t{NULL, ");
2202 if(prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
2203 else fprintf(f, "NULL,\n");
2204 fprintf(f, "\t%d, ", prop->magic);
2205 rna_print_c_string(f, prop->identifier);
2206 fprintf(f, ", %d, ", prop->flag);
2207 rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
2208 rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
2209 fprintf(f, "%d,\n", prop->icon);
2210 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);
2211 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));
2213 if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
2214 else fprintf(f, "\t0, -1");
2216 /* our own type - collections/arrays only */
2217 if(prop->srna) fprintf(f, ", &RNA_%s", (const char*)prop->srna);
2218 else fprintf(f, ", NULL");
2222 switch(prop->type) {
2223 case PROP_BOOLEAN: {
2224 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
2225 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);
2226 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2227 else fprintf(f, "NULL\n");
2231 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2232 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));
2233 rna_int_print(f, iprop->softmin); fprintf(f, ", ");
2234 rna_int_print(f, iprop->softmax); fprintf(f, ", ");
2235 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
2236 rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
2237 rna_int_print(f, iprop->step); fprintf(f, ", ");
2238 rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
2239 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2240 else fprintf(f, "NULL\n");
2244 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2245 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));
2246 rna_float_print(f, fprop->softmin); fprintf(f, ", ");
2247 rna_float_print(f, fprop->softmax); fprintf(f, ", ");
2248 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
2249 rna_float_print(f, fprop->hardmax); fprintf(f, ", ");
2250 rna_float_print(f, fprop->step); fprintf(f, ", ");
2251 rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
2252 rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
2253 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2254 else fprintf(f, "NULL\n");
2258 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
2259 fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength);
2260 rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
2264 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2265 fprintf(f, "\t%s, %s, %s, NULL, ", rna_function_string(eprop->get), rna_function_string(eprop->set), rna_function_string(eprop->itemf));
2267 fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
2269 fprintf(f, "NULL, ");
2270 fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
2273 case PROP_POINTER: {
2274 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
2275 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));
2276 if(pprop->type) fprintf(f, "&RNA_%s\n", (const char*)pprop->type);
2277 else fprintf(f, "NULL\n");
2280 case PROP_COLLECTION: {
2281 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2282 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));
2283 if(cprop->item_type) fprintf(f, "&RNA_%s\n", (const char*)cprop->item_type);
2284 else fprintf(f, "NULL\n");
2289 fprintf(f, "};\n\n");
2297 static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
2300 FunctionDefRNA *dfunc;
2301 PropertyRNA *prop, *parm;
2304 fprintf(f, "/* %s */\n", srna->name);
2306 for(prop= srna->cont.properties.first; prop; prop= prop->next)
2307 rna_generate_property(f, srna, NULL, prop);
2309 for(func= srna->functions.first; func; func= func->cont.next) {
2310 for(parm= func->cont.properties.first; parm; parm= parm->next)
2311 rna_generate_property(f, srna, func->identifier, parm);
2313 fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
2315 if(func->cont.next) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, ((FunctionRNA*)func->cont.next)->identifier);
2316 else fprintf(f, "\t{NULL, ");
2317 if(func->cont.prev) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier, ((FunctionRNA*)func->cont.prev)->identifier);
2318 else fprintf(f, "NULL,\n");
2320 fprintf(f, "\tNULL,\n");
2322 parm= func->cont.properties.first;
2323 if(parm) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
2324 else fprintf(f, "\t{NULL, ");
2326 parm= func->cont.properties.last;
2327 if(parm) fprintf(f, "(PropertyRNA*)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
2328 else fprintf(f, "NULL}},\n");
2331 rna_print_c_string(f, func->identifier);
2332 fprintf(f, ", %d, ", func->flag);
2333 rna_print_c_string(f, func->description); fprintf(f, ",\n");
2335 dfunc= rna_find_function_def(func);
2336 if(dfunc->gencall) fprintf(f, "\t%s,\n", dfunc->gencall);
2337 else fprintf(f, "\tNULL,\n");
2339 if(func->c_ret) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
2340 else fprintf(f, "\tNULL\n");
2346 fprintf(f, "StructRNA RNA_%s = {\n", srna->identifier);
2348 if(srna->cont.next) fprintf(f, "\t{(ContainerRNA *)&RNA_%s, ", ((StructRNA*)srna->cont.next)->identifier);
2349 else fprintf(f, "\t{NULL, ");
2350 if(srna->cont.prev) fprintf(f, "(ContainerRNA *)&RNA_%s,\n", ((StructRNA*)srna->cont.prev)->identifier);
2351 else fprintf(f, "NULL,\n");
2353 fprintf(f, "\tNULL,\n");
2355 prop= srna->cont.properties.first;
2356 if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
2357 else fprintf(f, "\t{NULL, ");
2359 prop= srna->cont.properties.last;
2360 if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
2361 else fprintf(f, "NULL}},\n");
2363 rna_print_c_string(f, srna->identifier);
2364 fprintf(f, "\t, NULL,NULL\n"); /* PyType - Cant initialize here */
2365 fprintf(f, ", %d, ", srna->flag);
2366 rna_print_c_string(f, srna->name);
2368 rna_print_c_string(f, srna->description);
2369 fprintf(f, ",\n\t%d,\n", srna->icon);
2371 prop= srna->nameproperty;
2374 while (base->base && base->base->nameproperty==prop)
2377 fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", base->identifier, prop->identifier);
2379 else fprintf(f, "\tNULL, ");
2381 prop= srna->iteratorproperty;
2383 while (base->base && base->base->iteratorproperty==prop)
2385 fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", base->identifier);
2387 if(srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
2388 else fprintf(f, "\tNULL,\n");
2390 if(srna->nested) fprintf(f, "\t&RNA_%s,\n", srna->nested->identifier);
2391 else fprintf(f, "\tNULL,\n");
2393 fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
2394 fprintf(f, "\t%s,\n", rna_function_string(srna->path));
2395 fprintf(f, "\t%s,\n", rna_function_string(srna->reg));
2396 fprintf(f, "\t%s,\n", rna_function_string(srna->unreg));
2397 fprintf(f, "\t%s,\n", rna_function_string(srna->instance));
2398 fprintf(f, "\t%s,\n", rna_function_string(srna->idproperties));
2400 if(srna->reg && !srna->refine) {
2401 fprintf(stderr, "rna_generate_struct: %s has a register function, must also have refine function.\n", srna->identifier);
2405 func= srna->functions.first;
2406 if(func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, func->identifier);
2407 else fprintf(f, "\t{NULL, ");
2409 func= srna->functions.last;
2410 if(func) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
2411 else fprintf(f, "NULL}\n");
2418 typedef struct RNAProcessItem {
2419 const char *filename;
2420 const char *api_filename;
2421 void (*define)(BlenderRNA *brna);
2424 static RNAProcessItem PROCESS_ITEMS[]= {
2425 {"rna_rna.c", NULL, RNA_def_rna},
2426 {"rna_ID.c", NULL, RNA_def_ID},
2427 {"rna_texture.c", "rna_texture_api.c", RNA_def_texture},
2428 {"rna_action.c", "rna_action_api.c", RNA_def_action},
2429 {"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
2430 {"rna_animviz.c", NULL, RNA_def_animviz},
2431 {"rna_actuator.c", "rna_actuator_api.c", RNA_def_actuator},
2432 {"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
2433 {"rna_boid.c", NULL, RNA_def_boid},
2434 {"rna_brush.c", NULL, RNA_def_brush},
2435 {"rna_camera.c", "rna_camera_api.c", RNA_def_camera},
2436 {"rna_cloth.c", NULL, RNA_def_cloth},
2437 {"rna_color.c", NULL, RNA_def_color},
2438 {"rna_constraint.c", NULL, RNA_def_constraint},
2439 {"rna_context.c", NULL, RNA_def_context},
2440 {"rna_controller.c", "rna_controller_api.c", RNA_def_controller},
2441 {"rna_curve.c", NULL, RNA_def_curve},
2442 {"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
2443 {"rna_fluidsim.c", NULL, RNA_def_fluidsim},
2444 {"rna_gpencil.c", NULL, RNA_def_gpencil},
2445 {"rna_group.c", NULL, RNA_def_group},
2446 {"rna_image.c", "rna_image_api.c", RNA_def_image},
2447 {"rna_key.c", NULL, RNA_def_key},
2448 {"rna_lamp.c", NULL, RNA_def_lamp},
2449 {"rna_lattice.c", NULL, RNA_def_lattice},
2450 {"rna_main.c", "rna_main_api.c", RNA_def_main},
2451 {"rna_material.c", "rna_material_api.c", RNA_def_material},
2452 {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
2453 {"rna_meta.c", NULL, RNA_def_meta},
2454 {"rna_modifier.c", NULL, RNA_def_modifier},
2455 {"rna_nla.c", NULL, RNA_def_nla},
2456 {"rna_nodetree.c", NULL, RNA_def_nodetree},
2457 {"rna_object.c", "rna_object_api.c", RNA_def_object},
2458 {"rna_object_force.c", NULL, RNA_def_object_force},
2459 {"rna_packedfile.c", NULL, RNA_def_packedfile},
2460 {"rna_particle.c", NULL, RNA_def_particle},
2461 {"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
2462 {"rna_property.c", NULL, RNA_def_gameproperty},
2463 {"rna_render.c", NULL, RNA_def_render},
2464 {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
2465 {"rna_screen.c", NULL, RNA_def_screen},
2466 {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
2467 {"rna_sensor.c", "rna_sensor_api.c", RNA_def_sensor},
2468 {"rna_sequencer.c", "rna_sequencer_api.c", RNA_def_sequencer},
2469 {"rna_smoke.c", NULL, RNA_def_smoke},
2470 {"rna_space.c", NULL, RNA_def_space},
2471 {"rna_speaker.c", NULL, RNA_def_speaker},
2472 {"rna_test.c", NULL, RNA_def_test},
2473 {"rna_text.c", NULL, RNA_def_text},
2474 {"rna_timeline.c", NULL, RNA_def_timeline_marker},
2475 {"rna_sound.c", NULL, RNA_def_sound},
2476 {"rna_ui.c", "rna_ui_api.c", RNA_def_ui},
2477 {"rna_userdef.c", NULL, RNA_def_userdef},
2478 {"rna_vfont.c", NULL, RNA_def_vfont},
2479 {"rna_wm.c", "rna_wm_api.c", RNA_def_wm},
2480 {"rna_world.c", NULL, RNA_def_world},
2483 static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename)
2487 FunctionDefRNA *dfunc;
2489 fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
2490 " Do not edit manually, changes will be overwritten. */\n\n"
2491 "#define RNA_RUNTIME\n\n");
2493 fprintf(f, "#include <float.h>\n");
2494 fprintf(f, "#include <stdio.h>\n");
2495 fprintf(f, "#include <limits.h>\n");
2496 fprintf(f, "#include <string.h>\n\n");
2497 fprintf(f, "#include <stddef.h>\n\n");
2499 fprintf(f, "#include \"DNA_ID.h\"\n");
2500 fprintf(f, "#include \"DNA_scene_types.h\"\n");
2502 fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
2503 fprintf(f, "#include \"BLI_utildefines.h\"\n\n");
2505 fprintf(f, "#include \"BKE_context.h\"\n");
2506 fprintf(f, "#include \"BKE_library.h\"\n");
2507 fprintf(f, "#include \"BKE_main.h\"\n");
2508 fprintf(f, "#include \"BKE_report.h\"\n");
2510 fprintf(f, "#include \"RNA_define.h\"\n");
2511 fprintf(f, "#include \"RNA_types.h\"\n");
2512 fprintf(f, "#include \"rna_internal.h\"\n\n");
2514 rna_generate_prototypes(brna, f);
2516 fprintf(f, "#include \"%s\"\n", filename);
2518 fprintf(f, "#include \"%s\"\n", api_filename);
2521 fprintf(f, "/* Autogenerated Functions */\n\n");
2523 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2524 if(!filename || ds->filename == filename) {
2525 rna_generate_property_prototypes(brna, ds->srna, f);
2526 rna_generate_function_prototypes(brna, ds->srna, f);
2530 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2531 if(!filename || ds->filename == filename)
2532 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2533 rna_def_property_funcs(f, ds->srna, dp);
2535 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2536 if(!filename || ds->filename == filename) {
2537 for(dfunc=ds->functions.first; dfunc; dfunc= dfunc->cont.next)
2538 rna_def_function_funcs(f, ds, dfunc);
2540 rna_generate_static_function_prototypes(brna, ds->srna, f);
2544 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2545 if(!filename || ds->filename == filename)
2546 rna_generate_struct(brna, ds->srna, f);
2548 if(strcmp(filename, "rna_ID.c") == 0) {
2549 /* this is ugly, but we cannot have c files compiled for both
2550 * makesrna and blender with some build systems at the moment */
2551 fprintf(f, "#include \"rna_define.c\"\n\n");
2553 rna_generate_blender(brna, f);
2557 static void rna_generate_header(BlenderRNA *brna, FILE *f)
2563 fprintf(f, "\n#ifndef __RNA_BLENDER_H__\n");
2564 fprintf(f, "#define __RNA_BLENDER_H__\n\n");
2566 fprintf(f, "/* Automatically generated function declarations for the Data API.\n"
2567 " Do not edit manually, changes will be overwritten. */\n\n");
2569 fprintf(f, "#include \"RNA_types.h\"\n\n");
2571 fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
2573 fprintf(f, "#define FOREACH_BEGIN(property, sptr, itemptr) \\\n");
2574 fprintf(f, " { \\\n");
2575 fprintf(f, " CollectionPropertyIterator rna_macro_iter; \\\n");
2576 fprintf(f, " for(property##_begin(&rna_macro_iter, sptr); rna_macro_iter.valid; property##_next(&rna_macro_iter)) { \\\n");
2577 fprintf(f, " itemptr= rna_macro_iter.ptr;\n\n");
2579 fprintf(f, "#define FOREACH_END(property) \\\n");
2580 fprintf(f, " } \\\n");
2581 fprintf(f, " property##_end(&rna_macro_iter); \\\n");
2582 fprintf(f, " }\n\n");
2584 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2587 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2590 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
2595 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2596 rna_def_property_funcs_header(f, ds->srna, dp);
2599 fprintf(f, "#ifdef __cplusplus\n}\n#endif\n\n");
2601 fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n\n");
2604 static const char *cpp_classes = ""
2606 "#include <string>\n"
2610 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
2611 " inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr)? true: false; }\n"
2613 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2614 " inline Array<int,size> sname::identifier(void) \\\n"
2615 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2617 "#define INT_PROPERTY(sname, identifier) \\\n"
2618 " inline int sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2620 "#define INT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2621 " inline Array<int,size> sname::identifier(void) \\\n"
2622 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2624 "#define FLOAT_PROPERTY(sname, identifier) \\\n"
2625 " inline float sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2627 "#define FLOAT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2628 " inline Array<float,size> sname::identifier(void) \\\n"
2629 " { Array<float, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2631 "#define ENUM_PROPERTY(type, sname, identifier) \\\n"
2632 " inline sname::type sname::identifier(void) { return (type)sname##_##identifier##_get(&ptr); }\n"
2634 "#define STRING_PROPERTY(sname, identifier) \\\n"
2635 " inline std::string sname::identifier(void) { \\\n"
2636 " int len= sname##_##identifier##_length(&ptr); \\\n"
2637 " std::string str; str.resize(len); \\\n"
2638 " sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
2640 "#define POINTER_PROPERTY(type, sname, identifier) \\\n"
2641 " inline type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
2643 "#define COLLECTION_PROPERTY(type, sname, identifier) \\\n"
2644 " typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
2645 " sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
2646 " Collection<sname, type, sname##_##identifier##_begin, \\\n"
2647 " sname##_##identifier##_next, sname##_##identifier##_end> identifier;\n"
2651 " Pointer(const PointerRNA& p) : ptr(p) { }\n"
2652 " operator const PointerRNA&() { return ptr; }\n"
2653 " bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type)? true: false; }\n"
2654 " operator void*() { return ptr.data; }\n"
2655 " operator bool() { return ptr.data != NULL; }\n"
2657 " PointerRNA ptr;\n"
2661 "template<typename T, int Tsize>\n"
2667 " Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); }\n"
2668 " const Array<T, Tsize>& operator=(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T)*Tsize); return *this; }\n"
2670 " operator T*() { return data; }\n"
2673 "typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
2674 "typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
2675 "typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
2677 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2678 "class CollectionIterator {\n"
2680 " CollectionIterator() : t(iter.ptr), init(false) { iter.valid= false; }\n"
2681 " ~CollectionIterator(void) { if(init) Tend(&iter); };\n"
2683 " operator bool(void)\n"
2684 " { return iter.valid != 0; }\n"
2685 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator++() { Tnext(&iter); t = T(iter.ptr); return *this; }\n"
2687 " T& operator*(void) { return t; }\n"
2688 " T* operator->(void) { return &t; }\n"
2689 " bool operator==(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid == other.iter.valid; }\n"
2690 " bool operator!=(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid != other.iter.valid; }\n"
2692 " void begin(const Pointer& ptr)\n"
2693 " { if(init) Tend(&iter); Tbegin(&iter, (PointerRNA*)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
2696 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator=(const CollectionIterator<T, Tbegin, Tnext, Tend>& copy) {}\n"
2698 " CollectionPropertyIterator iter;\n"
2703 "template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2704 "class Collection {\n"
2706 " Collection(const PointerRNA& p) : ptr(p) {}\n"
2708 " void begin(CollectionIterator<T, Tbegin, Tnext, Tend>& iter)\n"
2709 " { iter.begin(ptr); }\n"
2710 " CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
2711 " { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
2714 " PointerRNA ptr;\n"
2718 static void rna_generate_header_cpp(BlenderRNA *brna, FILE *f)
2724 fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
2725 fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
2727 fprintf(f, "/* Automatically generated classes for the Data API.\n"
2728 " Do not edit manually, changes will be overwritten. */\n\n");
2730 fprintf(f, "#include \"RNA_blender.h\"\n");
2731 fprintf(f, "#include \"RNA_types.h\"\n");
2733 fprintf(f, "%s", cpp_classes);
2735 fprintf(f, "/**************** Declarations ****************/\n\n");
2737 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2738 fprintf(f, "class %s;\n", ds->srna->identifier);
2741 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2744 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2746 fprintf(f, "class %s : public %s {\n", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2747 fprintf(f, "public:\n");
2748 fprintf(f, "\t%s(const PointerRNA& ptr) :\n\t\t%s(ptr)", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2749 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2750 if(!(dp->prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN)))
2751 if(dp->prop->type == PROP_COLLECTION)
2752 fprintf(f, ",\n\t\t%s(ptr)", dp->prop->identifier);
2753 fprintf(f, "\n\t\t{}\n\n");
2755 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2756 rna_def_property_funcs_header_cpp(f, ds->srna, dp);
2757 fprintf(f, "};\n\n");
2761 fprintf(f, "/**************** Implementation ****************/\n");
2763 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2764 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2765 rna_def_property_funcs_impl_cpp(f, ds->srna, dp);
2770 fprintf(f, "}\n\n#endif /* __RNA_BLENDER_CPP_H__ */\n\n");
2773 static void make_bad_file(char *file, int line)
2775 FILE *fp= fopen(file, "w");
2776 fprintf(fp, "#error \"Error! can't make correct RNA file from %s:%d, STUPID!\"\n", __FILE__, line);
2780 static int rna_preprocess(char *outfile)
2787 const char *deps[3]; /* expand as needed */
2792 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2793 if(PROCESS_ITEMS[i].define) {
2794 PROCESS_ITEMS[i].define(brna);
2796 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2798 ds->filename= PROCESS_ITEMS[i].filename;
2805 /* create RNA_blender_cpp.h */
2806 strcpy(deffile, outfile);
2807 strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
2809 status= (DefRNA.error != 0);
2812 make_bad_file(deffile, __LINE__);
2815 file = fopen(deffile, "w");
2818 printf ("Unable to open file: %s\n", deffile);
2822 rna_generate_header_cpp(brna, file);
2824 status= (DefRNA.error != 0);
2828 replace_if_different(deffile, NULL);
2832 /* create rna_gen_*.c files */
2833 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2834 strcpy(deffile, outfile);
2835 strcat(deffile, PROCESS_ITEMS[i].filename);
2836 deffile[strlen(deffile)-2] = '\0';
2837 strcat(deffile, "_gen.c" TMP_EXT);
2840 make_bad_file(deffile, __LINE__);
2843 file = fopen(deffile, "w");
2846 printf ("Unable to open file: %s\n", deffile);
2850 rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
2852 status= (DefRNA.error != 0);
2856 /* avoid unneeded rebuilds */
2857 deps[0]= PROCESS_ITEMS[i].filename;
2858 deps[1]= PROCESS_ITEMS[i].api_filename;
2861 replace_if_different(deffile, deps);
2864 /* create RNA_blender.h */
2865 strcpy(deffile, outfile);
2866 strcat(deffile, "RNA_blender.h" TMP_EXT);
2869 make_bad_file(deffile, __LINE__);
2872 file = fopen(deffile, "w");
2875 printf ("Unable to open file: %s\n", deffile);
2879 rna_generate_header(brna, file);
2881 status= (DefRNA.error != 0);