36b62f5030b1450a1e1dac71320bd454c16692e5
[blender.git] / source / blender / makesrna / intern / rna_define.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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.
10  *
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.
15  *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Blender Foundation (2008).
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <float.h>
26 #include <limits.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <ctype.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "DNA_genfile.h"
35 #include "DNA_sdna_types.h"
36
37 #include "RNA_access.h"
38 #include "RNA_define.h"
39 #include "RNA_types.h"
40
41 #include "rna_internal.h"
42
43 /* Global used during defining */
44
45 BlenderDefRNA DefRNA = {0, {0, 0}, {0, 0}, 0, 0, 0};
46
47 /* Duplicated code since we can't link in blenkernel or blenlib */
48
49 #ifndef MIN2
50 #define MIN2(x,y) ((x)<(y)? (x): (y))
51 #define MAX2(x,y) ((x)>(y)? (x): (y))
52 #endif
53
54 void rna_addtail(ListBase *listbase, void *vlink)
55 {
56         Link *link= vlink;
57
58         link->next = NULL;
59         link->prev = listbase->last;
60
61         if (listbase->last) ((Link *)listbase->last)->next = link;
62         if (listbase->first == 0) listbase->first = link;
63         listbase->last = link;
64 }
65
66 void rna_remlink(ListBase *listbase, void *vlink)
67 {
68         Link *link= vlink;
69
70         if (link->next) link->next->prev = link->prev;
71         if (link->prev) link->prev->next = link->next;
72
73         if (listbase->last == link) listbase->last = link->prev;
74         if (listbase->first == link) listbase->first = link->next;
75 }
76
77 void rna_freelinkN(ListBase *listbase, void *vlink)
78 {
79         rna_remlink(listbase, vlink);
80         MEM_freeN(vlink);
81 }
82
83 void rna_freelistN(ListBase *listbase)
84 {
85         Link *link, *next;
86         
87         for(link=listbase->first; link; link=next) {
88                 next= link->next;
89                 MEM_freeN(link);
90         }
91         
92         listbase->first= listbase->last= NULL;
93 }
94
95 /* DNA utility function for looking up members */
96
97 typedef struct DNAStructMember {
98         char *type;
99         char *name;
100         int arraylength;
101         int pointerlevel;
102 } DNAStructMember;
103
104 static int rna_member_cmp(const char *name, const char *oname)
105 {
106         int a=0;
107         
108         /* compare without pointer or array part */
109         while(name[0]=='*')
110                 name++;
111         while(oname[0]=='*')
112                 oname++;
113         
114         while(1) {
115                 if(name[a]=='[' && oname[a]==0) return 1;
116                 if(name[a]==0) break;
117                 if(name[a] != oname[a]) return 0;
118                 a++;
119         }
120         if(name[a]==0 && oname[a] == '.') return 2;
121         if(name[a]==0 && oname[a] == '-' && oname[a+1] == '>') return 3;
122
123         return (name[a] == oname[a]);
124 }
125
126 static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *membername, DNAStructMember *smember)
127 {
128         char *dnaname;
129         short *sp;
130         int a, b, structnr, totmember, cmp;
131
132         structnr= DNA_struct_find_nr(sdna, structname);
133         if(structnr == -1)
134                 return 0;
135
136         sp= sdna->structs[structnr];
137         totmember= sp[1];
138         sp+= 2;
139
140         for(a=0; a<totmember; a++, sp+=2) {
141                 dnaname= sdna->names[sp[1]];
142
143                 cmp= rna_member_cmp(dnaname, membername);
144
145                 if(cmp == 1) {
146                         smember->type= sdna->types[sp[0]];
147                         smember->name= dnaname;
148                         smember->arraylength= DNA_elem_array_size(smember->name, strlen(smember->name));
149
150                         smember->pointerlevel= 0;
151                         for(b=0; dnaname[b] == '*'; b++)
152                                 smember->pointerlevel++;
153
154                         return 1;
155                 }
156                 else if(cmp == 2) {
157                         membername= strstr(membername, ".") + strlen(".");
158                         return rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
159                 }
160                 else if(cmp == 3) {
161                         membername= strstr(membername, "->") + strlen("->");
162                         return rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
163                 }
164         }
165
166         return 0;
167 }
168
169 static int rna_validate_identifier(const char *identifier, char *error)
170 {
171         int a=0;
172         
173         /*  list from http://docs.python.org/reference/lexical_analysis.html#id5 */
174         static char *kwlist[] = {
175                 "and", "as", "assert", "break",
176                 "class", "continue", "def", "del",
177                 "elif", "else", "except", "exec",
178                 "finally", "for", "from", "global",
179                 "if", "import", "in", "is",
180                 "lambda", "not", "or", "pass",
181                 "print", "raise", "return", "try",
182                 "while", "with", "yield", NULL
183         };
184         
185         
186         if (!isalpha(identifier[0])) {
187                 strcpy(error, "first character failed isalpha() check");
188                 return 0;
189         }
190         
191         for(a=1; identifier[a] != '\0'; a++) {
192                 if (identifier[a]=='_') {
193                         continue;
194                 }
195                 
196                 if (isalnum(identifier[a])==0) {
197                         strcpy(error, "one of the characters failed an isalnum() check and is not an underscore");
198                         return 0;
199                 }
200         }
201         
202         for(a=0; kwlist[a]; a++) {
203                 if (strcmp(identifier, kwlist[a]) == 0) {
204                         strcpy(error, "this keyword is reserved by python");
205                         return 0;
206                 }
207         }
208         
209         return 1;
210 }
211
212 /* Blender Data Definition */
213
214 BlenderRNA *RNA_create()
215 {
216         BlenderRNA *brna;
217
218         brna= MEM_callocN(sizeof(BlenderRNA), "BlenderRNA");
219
220         DefRNA.sdna= DNA_sdna_from_data(DNAstr,  DNAlen, 0);
221         DefRNA.structs.first= DefRNA.structs.last= NULL;
222         DefRNA.error= 0;
223         DefRNA.preprocess= 1;
224
225         return brna;
226 }
227
228 void RNA_define_free(BlenderRNA *brna)
229 {
230         StructDefRNA *srna;
231         AllocDefRNA *alloc;
232
233         for(alloc=DefRNA.allocs.first; alloc; alloc=alloc->next)
234                 MEM_freeN(alloc->mem);
235         rna_freelistN(&DefRNA.allocs);
236
237         for(srna=DefRNA.structs.first; srna; srna=srna->next)
238                 rna_freelistN(&srna->properties);
239
240         rna_freelistN(&DefRNA.structs);
241
242         if(DefRNA.sdna) {
243                 DNA_sdna_free(DefRNA.sdna);
244                 DefRNA.sdna= NULL;
245         }
246
247         DefRNA.error= 0;
248 }
249
250 void RNA_free(BlenderRNA *brna)
251 {
252         StructRNA *srna, *nextsrna;
253         PropertyRNA *prop, *nextprop;
254
255         if(DefRNA.preprocess) {
256                 RNA_define_free(brna);
257
258                 for(srna=brna->structs.first; srna; srna=srna->next)
259                         rna_freelistN(&srna->properties);
260
261                 rna_freelistN(&brna->structs);
262                 
263                 MEM_freeN(brna);
264         }
265         else {
266                 for(srna=brna->structs.first; srna; srna=nextsrna) {
267                         nextsrna= srna->next;
268
269                         for(prop=srna->properties.first; prop; prop=nextprop) {
270                                 nextprop= prop->next;
271
272                                 if(prop->flag & PROP_RUNTIME)
273                                         rna_freelinkN(&srna->properties, prop);
274                         }
275
276                         if(srna->flag & STRUCT_RUNTIME)
277                                 rna_freelinkN(&brna->structs, srna);
278                 }
279         }
280 }
281
282 static size_t rna_property_type_sizeof(PropertyType type)
283 {
284         switch(type) {
285                 case PROP_BOOLEAN: return sizeof(BooleanPropertyRNA);
286                 case PROP_INT: return sizeof(IntPropertyRNA);
287                 case PROP_FLOAT: return sizeof(FloatPropertyRNA);
288                 case PROP_STRING: return sizeof(StringPropertyRNA);
289                 case PROP_ENUM: return sizeof(EnumPropertyRNA);
290                 case PROP_POINTER: return sizeof(PointerPropertyRNA);
291                 case PROP_COLLECTION: return sizeof(CollectionPropertyRNA);
292                 default: return 0;
293         }
294 }
295
296 static StructDefRNA *rna_find_def_struct(StructRNA *srna)
297 {
298         StructDefRNA *ds;
299
300         for(ds=DefRNA.structs.first; ds; ds=ds->next)
301                 if(ds->srna == srna)
302                         return ds;
303
304         return NULL;
305 }
306
307 static PropertyDefRNA *rna_find_def_property(StructRNA *srna, PropertyRNA *prop)
308 {
309         StructDefRNA *ds= rna_find_def_struct(srna);
310         PropertyDefRNA *dp;
311
312         if(ds)
313                 for(dp=ds->properties.first; dp; dp=dp->next)
314                         if(dp->prop == prop)
315                                 return dp;
316         
317         return NULL;
318 }
319
320 /* Struct Definition */
321
322 StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
323 {
324         StructRNA *srna, *srnafrom= NULL;
325         StructDefRNA *ds= NULL, *dsfrom= NULL;
326         PropertyRNA *prop, *propfrom;
327         
328         if(DefRNA.preprocess) {
329                 char error[512];
330                 if (rna_validate_identifier(identifier, error) == 0) {
331                         fprintf(stderr, "RNA_def_struct: struct identifier \"%s\" error - %s\n", identifier, error);
332                         DefRNA.error= 1;
333                 }
334         }
335         
336         if(from) {
337                 /* find struct to derive from */
338                 for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->next)
339                         if(strcmp(srnafrom->identifier, from) == 0)
340                                 break;
341
342                 if(!srnafrom) {
343                         fprintf(stderr, "RNA_def_struct: struct %s not found to define %s.\n", from, identifier);
344                         DefRNA.error= 1;
345                 }
346         }
347
348         srna= MEM_callocN(sizeof(StructRNA), "StructRNA");
349         DefRNA.laststruct= srna;
350
351         if(srnafrom) {
352                 /* copy from struct to derive stuff, a bit clumsy since we can't
353                  * use MEM_dupallocN, data structs may not be alloced but builtin */
354                 memcpy(srna, srnafrom, sizeof(StructRNA));
355                 srna->properties.first= srna->properties.last= NULL;
356
357                 if(DefRNA.preprocess) {
358                         srna->from= (StructRNA*)from;
359                         dsfrom= rna_find_def_struct(srnafrom);
360                 }
361                 else
362                         srna->from= srnafrom;
363         }
364
365         srna->identifier= identifier;
366         srna->name= identifier; /* may be overwritten later RNA_def_struct_ui_text */
367         srna->description= "";
368
369         rna_addtail(&brna->structs, srna);
370
371         if(DefRNA.preprocess) {
372                 ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
373                 ds->srna= srna;
374                 rna_addtail(&DefRNA.structs, ds);
375
376                 if(dsfrom)
377                         ds->dnafromname= dsfrom->dnaname;
378         }
379
380         /* in preprocess, try to find sdna */
381         if(DefRNA.preprocess)
382                 RNA_def_struct_sdna(srna, srna->identifier);
383         else
384                 srna->flag |= STRUCT_RUNTIME;
385
386         if(srnafrom) {
387                 /* copy from struct to derive stuff, a bit clumsy since we can't
388                  * use MEM_dupallocN, data structs may not be alloced but builtin */
389
390                 for(propfrom= srnafrom->properties.first; propfrom; propfrom=propfrom->next) {
391                         prop= RNA_def_property(srna, propfrom->identifier, propfrom->type, propfrom->subtype);
392
393                         rna_remlink(&srna->properties, prop);
394                         memcpy(prop, propfrom, rna_property_type_sizeof(propfrom->type));
395
396                         if(!DefRNA.preprocess)
397                                 prop->flag |= PROP_RUNTIME;
398
399                         prop->next= prop->prev= NULL;
400                         rna_addtail(&srna->properties, prop);
401
402                         if(propfrom == srnafrom->nameproperty)
403                                 srna->nameproperty= prop;
404                         if(propfrom == srnafrom->iteratorproperty)
405                                 srna->iteratorproperty= prop;
406
407                         if(DefRNA.preprocess) {
408                                 PropertyDefRNA *dp, *dpfrom;
409                                 
410                                 dp= ds->properties.last;
411                                 dpfrom= rna_find_def_property(srnafrom, propfrom);
412
413                                 rna_remlink(&ds->properties, dp);
414                                 memcpy(dp, dpfrom, sizeof(*dp));
415                                 dp->srna= srna;
416                                 dp->prop= prop;
417                                 dp->next= dp->prev= NULL;
418                                 rna_addtail(&ds->properties, dp);
419                         }
420                 }
421         }
422         else {
423                 /* define some builtin properties */
424                 prop= RNA_def_property(srna, "rna_properties", PROP_COLLECTION, PROP_NONE);
425                 RNA_def_property_flag(prop, PROP_BUILTIN);
426                 RNA_def_property_ui_text(prop, "Properties", "RNA property collection.");
427
428                 if(DefRNA.preprocess) {
429                         RNA_def_property_struct_type(prop, "Property");
430                         RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", 0, 0, 0, 0);
431                 }
432                 else {
433 #ifdef RNA_RUNTIME
434                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
435                         cprop->begin= rna_builtin_properties_begin;
436                         cprop->next= rna_builtin_properties_next;
437                         cprop->next= rna_iterator_listbase_end;
438                         cprop->get= rna_builtin_properties_get;
439                         cprop->structtype= &RNA_Property;
440 #endif
441                 }
442
443                 prop= RNA_def_property(srna, "rna_type", PROP_POINTER, PROP_NONE);
444                 RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
445                 RNA_def_property_ui_text(prop, "RNA", "RNA type definition.");
446
447                 if(DefRNA.preprocess) {
448                         RNA_def_property_struct_type(prop, "Struct");
449                         RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL);
450                 }
451                 else {
452 #ifdef RNA_RUNTIME
453                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
454                         pprop->get= rna_builtin_type_get;
455                         pprop->structtype= &RNA_Struct;
456 #endif
457                 }
458         }
459
460         return srna;
461 }
462
463 void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
464 {
465         StructDefRNA *ds= DefRNA.structs.last;
466
467         if(!DefRNA.preprocess) {
468                 fprintf(stderr, "RNA_def_struct_sdna: only during preprocessing.\n");
469                 return;
470         }
471
472         if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
473                 if(!DefRNA.silent) {
474                         fprintf(stderr, "RNA_def_struct_sdna: %s not found.\n", structname);
475                         DefRNA.error= 1;
476                 }
477                 return;
478         }
479
480         ds->dnaname= structname;
481 }
482
483 void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
484 {
485         StructDefRNA *ds= DefRNA.structs.last;
486
487         if(!DefRNA.preprocess) {
488                 fprintf(stderr, "RNA_def_struct_sdna_from: only during preprocessing.\n");
489                 return;
490         }
491
492         if(!ds->dnaname) {
493                 fprintf(stderr, "RNA_def_struct_sdna_from: %s base struct must know DNA already.\n", structname);
494                 return;
495         }
496
497         if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
498                 if(!DefRNA.silent) {
499                         fprintf(stderr, "RNA_def_struct_sdna_from: %s not found.\n", structname);
500                         DefRNA.error= 1;
501                 }
502                 return;
503         }
504
505         ds->dnafromprop= propname;
506         ds->dnaname= structname;
507 }
508
509 void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
510 {
511         if(prop->type != PROP_STRING) {
512                 fprintf(stderr, "RNA_def_struct_name_property: %s.%s, must be a string property.\n", srna->identifier, prop->identifier);
513                 DefRNA.error= 1;
514         }
515         else
516                 srna->nameproperty= prop;
517 }
518
519 void RNA_def_struct_parent(StructRNA *srna, StructRNA *parent)
520 {
521
522         if(DefRNA.preprocess)
523                 srna->parent= (StructRNA*)parent->identifier;
524         else
525                 srna->parent= parent;
526 }
527
528 void RNA_def_struct_flag(StructRNA *srna, int flag)
529 {
530         srna->flag= flag;
531 }
532
533 void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
534 {
535         if(!DefRNA.preprocess) {
536                 fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
537                 return;
538         }
539
540         if(refine) srna->refine= (StructRefineFunc)refine;
541 }
542
543 void RNA_def_struct_identifier(StructRNA *srna, const char *identifier)
544 {
545         if(DefRNA.preprocess) {
546                 fprintf(stderr, "RNA_def_struct_name_runtime: only at runtime.\n");
547                 return;
548         }
549
550         srna->identifier= identifier;
551 }
552
553 void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
554 {
555         srna->name= name;
556         srna->description= description;
557 }
558
559 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
560 {
561         rna_freelistN(&srna->properties);
562         rna_freelinkN(&brna->structs, srna);
563 }
564
565 /* Property Definition */
566
567 PropertyRNA *RNA_def_property(StructRNA *srna, const char *identifier, int type, int subtype)
568 {
569         StructDefRNA *ds;
570         PropertyDefRNA *dp= NULL;
571         PropertyRNA *prop;
572
573         if(DefRNA.preprocess) {
574                 char error[512];
575                 
576                 if (rna_validate_identifier(identifier, error) == 0) {
577                         fprintf(stderr, "RNA_def_property: property identifier \"%s\" - %s\n", identifier, error);
578                         DefRNA.error= 1;
579                 }
580                 
581                 ds= DefRNA.structs.last;
582                 dp= MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA");
583                 rna_addtail(&ds->properties, dp);
584         }
585
586         prop= MEM_callocN(rna_property_type_sizeof(type), "PropertyRNA");
587
588         switch(type) {
589                 case PROP_BOOLEAN:
590                         break;
591                 case PROP_INT: {
592                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
593
594                         iprop->hardmin= (subtype == PROP_UNSIGNED)? 0: INT_MIN;
595                         iprop->hardmax= INT_MAX;
596
597                         iprop->softmin= (subtype == PROP_UNSIGNED)? 0: -10000; /* rather arbitrary .. */
598                         iprop->softmax= 10000;
599                         iprop->step= 1;
600                         break;
601                 }
602                 case PROP_FLOAT: {
603                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
604
605                         fprop->hardmin= (subtype == PROP_UNSIGNED)? 0.0f: -FLT_MAX;
606                         fprop->hardmax= FLT_MAX;
607
608                         if(subtype == PROP_COLOR) {
609                                 fprop->softmin= 0.0f;
610                                 fprop->softmax= 1.0f;
611                         }
612                         else {
613                                 fprop->softmin= (subtype == PROP_UNSIGNED)? 0.0f: -10000.0f; /* rather arbitrary .. */
614                                 fprop->softmax= 10000.0f;
615                         }
616                         fprop->step= 10;
617                         fprop->precision= 3;
618                         break;
619                 }
620                 case PROP_STRING: {
621                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
622
623                         sprop->defaultvalue= "";
624                         sprop->maxlength= 0;
625                         break;
626                 }
627                 case PROP_ENUM:
628                 case PROP_POINTER:
629                 case PROP_COLLECTION:
630                         break;
631                 default:
632                         fprintf(stderr, "RNA_def_property: %s.%s, invalid property type.\n", srna->identifier, identifier);
633                         DefRNA.error= 1;
634                         return NULL;
635         }
636
637         if(DefRNA.preprocess) {
638                 dp->srna= srna;
639                 dp->prop= prop;
640         }
641
642         prop->magic= RNA_MAGIC;
643         prop->identifier= identifier;
644         prop->type= type;
645         prop->subtype= subtype;
646         prop->name= identifier;
647         prop->description= "";
648
649         if(type == PROP_COLLECTION || type == PROP_POINTER)
650                 prop->flag= PROP_NOT_EDITABLE|PROP_NOT_DRIVEABLE;
651
652         if(DefRNA.preprocess) {
653                 switch(type) {
654                         case PROP_BOOLEAN:
655                                 DefRNA.silent= 1;
656                                 RNA_def_property_boolean_sdna(prop, NULL, identifier, 0);
657                                 DefRNA.silent= 0;
658                                 break;
659                         case PROP_INT: {
660                                 DefRNA.silent= 1;
661                                 RNA_def_property_int_sdna(prop, NULL, identifier);
662                                 DefRNA.silent= 0;
663                                 break;
664                         }
665                         case PROP_FLOAT: {
666                                 DefRNA.silent= 1;
667                                 RNA_def_property_float_sdna(prop, NULL, identifier);
668                                 DefRNA.silent= 0;
669                                 break;
670                         }
671                         case PROP_STRING: {
672                                 DefRNA.silent= 1;
673                                 RNA_def_property_string_sdna(prop, NULL, identifier);
674                                 DefRNA.silent= 0;
675                                 break;
676                         }
677                         case PROP_ENUM:
678                                 DefRNA.silent= 1;
679                                 RNA_def_property_enum_sdna(prop, NULL, identifier);
680                                 DefRNA.silent= 0;
681                                 break;
682                         case PROP_POINTER:
683                                 DefRNA.silent= 1;
684                                 RNA_def_property_pointer_sdna(prop, NULL, identifier);
685                                 DefRNA.silent= 0;
686                                 break;
687                         case PROP_COLLECTION:
688                                 DefRNA.silent= 1;
689                                 RNA_def_property_collection_sdna(prop, NULL, identifier, NULL);
690                                 DefRNA.silent= 0;
691                                 break;
692                 }
693         }
694         else
695                 prop->flag |= PROP_IDPROPERTY|PROP_RUNTIME;
696
697         rna_addtail(&srna->properties, prop);
698
699         return prop;
700 }
701
702 void RNA_def_property_flag(PropertyRNA *prop, int flag)
703 {
704 #if 0
705         StructRNA *srna;
706 #endif
707
708         prop->flag |= flag;
709
710 #if 0
711         if(prop->type != PROP_POINTER && prop->type != PROP_COLLECTION) {
712                 if(flag & (PROP_EVALUATE_DEPENDENCY|PROP_INVERSE_EVALUATE_DEPENDENCY|PROP_RENDER_DEPENDENCY|PROP_INVERSE_RENDER_DEPENDENCY)) {
713                         fprintf(stderr, "RNA_def_property_flag: %s.%s, only pointer and collection types can create dependencies.\n", ds->srna->identifier, prop->identifier);
714                         DefRNA.error= 1;
715                 }
716         }
717 #endif
718 }
719
720 void RNA_def_property_array(PropertyRNA *prop, int arraylength)
721 {
722         StructRNA *srna= DefRNA.laststruct;
723
724         switch(prop->type) {
725                 case PROP_BOOLEAN:
726                 case PROP_INT:
727                 case PROP_FLOAT:
728                         prop->arraylength= arraylength;
729                         break;
730                 default:
731                         fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
732                         DefRNA.error= 1;
733                         break;
734         }
735 }
736
737 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
738 {
739         prop->name= name;
740         prop->description= description;
741 }
742
743 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
744 {
745         StructRNA *srna= DefRNA.laststruct;
746
747         switch(prop->type) {
748                 case PROP_INT: {
749                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
750                         iprop->softmin= (int)min;
751                         iprop->softmax= (int)max;
752                         iprop->step= (int)step;
753                         break;
754                 }
755                 case PROP_FLOAT: {
756                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
757                         fprop->softmin= (float)min;
758                         fprop->softmax= (float)max;
759                         fprop->step= (float)step;
760                         fprop->precision= (int)precision;
761                         break;
762                 }
763                 default:
764                         fprintf(stderr, "RNA_def_property_ui_range: %s.%s, invalid type for ui range.\n", srna->identifier, prop->identifier);
765                         DefRNA.error= 1;
766                         break;
767         }
768 }
769
770 void RNA_def_property_range(PropertyRNA *prop, double min, double max)
771 {
772         StructRNA *srna= DefRNA.laststruct;
773
774         switch(prop->type) {
775                 case PROP_INT: {
776                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
777                         iprop->hardmin= (int)min;
778                         iprop->hardmax= (int)max;
779                         iprop->softmin= MAX2((int)min, iprop->hardmin);
780                         iprop->softmax= MIN2((int)max, iprop->hardmax);
781                         break;
782                 }
783                 case PROP_FLOAT: {
784                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
785                         fprop->hardmin= (float)min;
786                         fprop->hardmax= (float)max;
787                         fprop->softmin= MAX2((float)min, fprop->hardmin);
788                         fprop->softmax= MIN2((float)max, fprop->hardmax);
789                         break;
790                 }
791                 default:
792                         fprintf(stderr, "RNA_def_property_range: %s.%s, invalid type for range.\n", srna->identifier, prop->identifier);
793                         DefRNA.error= 1;
794                         break;
795         }
796 }
797
798 void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
799 {
800         StructRNA *srna= DefRNA.laststruct;
801
802         if(!DefRNA.preprocess) {
803                 fprintf(stderr, "RNA_def_property_struct_type: only during preprocessing.\n");
804                 return;
805         }
806
807         switch(prop->type) {
808                 case PROP_POINTER: {
809                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
810                         pprop->structtype = (StructRNA*)type;
811                         break;
812                 }
813                 case PROP_COLLECTION: {
814                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
815                         cprop->structtype = (StructRNA*)type;
816                         break;
817                 }
818                 default:
819                         fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
820                         DefRNA.error= 1;
821                         break;
822         }
823 }
824
825 void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type)
826 {
827         StructRNA *srna= DefRNA.laststruct;
828
829         if(DefRNA.preprocess) {
830                 fprintf(stderr, "RNA_def_property_struct_runtime: only at runtime.\n");
831                 return;
832         }
833
834         switch(prop->type) {
835                 case PROP_POINTER: {
836                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
837                         pprop->structtype = type;
838                         break;
839                 }
840                 case PROP_COLLECTION: {
841                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
842                         cprop->structtype = type;
843                         break;
844                 }
845                 default:
846                         fprintf(stderr, "RNA_def_property_struct_runtime: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
847                         DefRNA.error= 1;
848                         break;
849         }
850 }
851
852 void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
853 {
854         StructRNA *srna= DefRNA.laststruct;
855         int i;
856
857         switch(prop->type) {
858                 case PROP_ENUM: {
859                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
860                         eprop->item= item;
861                         eprop->totitem= 0;
862                         for(i=0; item[i].identifier; i++)
863                                 eprop->totitem++;
864
865                         break;
866                 }
867                 default:
868                         fprintf(stderr, "RNA_def_property_enum_items: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
869                         DefRNA.error= 1;
870                         break;
871         }
872 }
873
874 void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
875 {
876         StructRNA *srna= DefRNA.laststruct;
877
878         switch(prop->type) {
879                 case PROP_STRING: {
880                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
881                         sprop->maxlength= maxlength;
882                         break;
883                 }
884                 default:
885                         fprintf(stderr, "RNA_def_property_string_maxlength: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
886                         DefRNA.error= 1;
887                         break;
888         }
889 }
890
891 void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
892 {
893         StructRNA *srna= DefRNA.laststruct;
894
895         switch(prop->type) {
896                 case PROP_BOOLEAN: {
897                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
898                         bprop->defaultvalue= value;
899                         break;
900                 }
901                 default:
902                         fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
903                         DefRNA.error= 1;
904                         break;
905         }
906 }
907
908 void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
909 {
910         StructRNA *srna= DefRNA.laststruct;
911
912         switch(prop->type) {
913                 case PROP_BOOLEAN: {
914                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
915                         bprop->defaultarray= array;
916                         break;
917                 }
918                 default:
919                         fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
920                         DefRNA.error= 1;
921                         break;
922         }
923 }
924
925 void RNA_def_property_int_default(PropertyRNA *prop, int value)
926 {
927         StructRNA *srna= DefRNA.laststruct;
928
929         switch(prop->type) {
930                 case PROP_INT: {
931                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
932                         iprop->defaultvalue= value;
933                         break;
934                 }
935                 default:
936                         fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
937                         DefRNA.error= 1;
938                         break;
939         }
940 }
941
942 void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
943 {
944         StructRNA *srna= DefRNA.laststruct;
945
946         switch(prop->type) {
947                 case PROP_INT: {
948                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
949                         iprop->defaultarray= array;
950                         break;
951                 }
952                 default:
953                         fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
954                         DefRNA.error= 1;
955                         break;
956         }
957 }
958
959 void RNA_def_property_float_default(PropertyRNA *prop, float value)
960 {
961         StructRNA *srna= DefRNA.laststruct;
962
963         switch(prop->type) {
964                 case PROP_FLOAT: {
965                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
966                         fprop->defaultvalue= value;
967                         break;
968                 }
969                 default:
970                         fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
971                         DefRNA.error= 1;
972                         break;
973         }
974 }
975
976 void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
977 {
978         StructRNA *srna= DefRNA.laststruct;
979
980         switch(prop->type) {
981                 case PROP_FLOAT: {
982                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
983                         fprop->defaultarray= array;
984                         break;
985                 }
986                 default:
987                         fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
988                         DefRNA.error= 1;
989                         break;
990         }
991 }
992
993 void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
994 {
995         StructRNA *srna= DefRNA.laststruct;
996
997         switch(prop->type) {
998                 case PROP_STRING: {
999                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1000                         sprop->defaultvalue= value;
1001                         break;
1002                 }
1003                 default:
1004                         fprintf(stderr, "RNA_def_property_string_default: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1005                         DefRNA.error= 1;
1006                         break;
1007         }
1008 }
1009
1010 void RNA_def_property_enum_default(PropertyRNA *prop, int value)
1011 {
1012         StructRNA *srna= DefRNA.laststruct;
1013
1014         switch(prop->type) {
1015                 case PROP_ENUM: {
1016                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1017                         eprop->defaultvalue= value;
1018                         break;
1019                 }
1020                 default:
1021                         fprintf(stderr, "RNA_def_property_enum_default: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1022                         DefRNA.error= 1;
1023                         break;
1024         }
1025 }
1026
1027 /* SDNA */
1028
1029 static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1030 {
1031         DNAStructMember smember;
1032         StructDefRNA *ds= DefRNA.structs.last;
1033         PropertyDefRNA *dp= ds->properties.last;
1034
1035         if(!structname)
1036                 structname= ds->dnaname;
1037         if(!propname)
1038                 propname= prop->identifier;
1039
1040         if(!rna_find_sdna_member(DefRNA.sdna, structname, propname, &smember)) {
1041                 if(!DefRNA.silent) {
1042                         fprintf(stderr, "rna_def_property_sdna: %s.%s not found.\n", structname, propname);
1043                         DefRNA.error= 1;
1044                 }
1045                 return NULL;
1046         }
1047
1048         if(smember.arraylength > 1)
1049                 prop->arraylength= smember.arraylength;
1050         else
1051                 prop->arraylength= 0;
1052         
1053         dp->dnastructname= structname;
1054         dp->dnastructfromname= ds->dnafromname;
1055         dp->dnastructfromprop= ds->dnafromprop;
1056         dp->dnaname= propname;
1057         dp->dnatype= smember.type;
1058         dp->dnaarraylength= smember.arraylength;
1059         dp->dnapointerlevel= smember.pointerlevel;
1060
1061         return dp;
1062 }
1063
1064 void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int bit)
1065 {
1066         PropertyDefRNA *dp;
1067         StructRNA *srna= DefRNA.laststruct;
1068         
1069         if(!DefRNA.preprocess) {
1070                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1071                 return;
1072         }
1073
1074         if(prop->type != PROP_BOOLEAN) {
1075                 fprintf(stderr, "RNA_def_property_boolean_sdna: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
1076                 DefRNA.error= 1;
1077                 return;
1078         }
1079
1080         if((dp=rna_def_property_sdna(prop, structname, propname)))
1081                 dp->booleanbit= bit;
1082 }
1083
1084 void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int booleanbit)
1085 {
1086         StructDefRNA *ds;
1087         PropertyDefRNA *dp;
1088
1089         RNA_def_property_boolean_sdna(prop, structname, propname, booleanbit);
1090
1091         if((ds=DefRNA.structs.last) && (dp=ds->properties.last))
1092                 dp->booleannegative= 1;
1093 }
1094
1095 void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1096 {
1097         PropertyDefRNA *dp;
1098         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1099         StructRNA *srna= DefRNA.laststruct;
1100         
1101         if(!DefRNA.preprocess) {
1102                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1103                 return;
1104         }
1105
1106         if(prop->type != PROP_INT) {
1107                 fprintf(stderr, "RNA_def_property_int_sdna: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
1108                 DefRNA.error= 1;
1109                 return;
1110         }
1111
1112         if((dp= rna_def_property_sdna(prop, structname, propname))) {
1113                 /* SDNA doesn't pass us unsigned unfortunately .. */
1114                 if(strcmp(dp->dnatype, "char") == 0) {
1115                         iprop->hardmin= iprop->softmin= CHAR_MIN;
1116                         iprop->hardmax= iprop->softmax= CHAR_MAX;
1117                 }
1118                 else if(strcmp(dp->dnatype, "short") == 0) {
1119                         iprop->hardmin= iprop->softmin= SHRT_MIN;
1120                         iprop->hardmax= iprop->softmax= SHRT_MAX;
1121                 }
1122                 else if(strcmp(dp->dnatype, "int") == 0) {
1123                         iprop->hardmin= INT_MIN;
1124                         iprop->hardmax= INT_MAX;
1125
1126                         iprop->softmin= -10000; /* rather arbitrary .. */
1127                         iprop->softmax= 10000;
1128                 }
1129
1130                 if(prop->subtype == PROP_UNSIGNED)
1131                         iprop->hardmin= iprop->softmin= 0;
1132         }
1133 }
1134
1135 void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1136 {
1137         StructRNA *srna= DefRNA.laststruct;
1138
1139         if(!DefRNA.preprocess) {
1140                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1141                 return;
1142         }
1143
1144         if(prop->type != PROP_FLOAT) {
1145                 fprintf(stderr, "RNA_def_property_float_sdna: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1146                 DefRNA.error= 1;
1147                 return;
1148         }
1149
1150         rna_def_property_sdna(prop, structname, propname);
1151 }
1152
1153 void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1154 {
1155         PropertyDefRNA *dp;
1156         StructRNA *srna= DefRNA.laststruct;
1157         
1158         if(!DefRNA.preprocess) {
1159                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1160                 return;
1161         }
1162
1163         if(prop->type != PROP_ENUM) {
1164                 fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1165                 DefRNA.error= 1;
1166                 return;
1167         }
1168
1169         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1170                 if(prop->arraylength) {
1171                         prop->arraylength= 0;
1172                         if(!DefRNA.silent) {
1173                                 fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, array not supported for enum type.\n", structname, propname);
1174                                 DefRNA.error= 1;
1175                         }
1176                 }
1177         }
1178 }
1179
1180 void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1181 {
1182         StructDefRNA *ds;
1183         PropertyDefRNA *dp;
1184
1185         RNA_def_property_enum_sdna(prop, structname, propname);
1186
1187         if((ds=DefRNA.structs.last) && (dp=ds->properties.last))
1188                 dp->enumbitflags= 1;
1189 }
1190
1191 void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1192 {
1193         PropertyDefRNA *dp;
1194         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1195         StructRNA *srna= DefRNA.laststruct;
1196
1197         if(!DefRNA.preprocess) {
1198                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1199                 return;
1200         }
1201
1202         if(prop->type != PROP_STRING) {
1203                 fprintf(stderr, "RNA_def_property_string_sdna: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1204                 DefRNA.error= 1;
1205                 return;
1206         }
1207
1208         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1209                 if(prop->arraylength) {
1210                         sprop->maxlength= prop->arraylength;
1211                         prop->arraylength= 0;
1212                 }
1213         }
1214 }
1215
1216 void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1217 {
1218         PropertyDefRNA *dp;
1219         StructRNA *srna= DefRNA.laststruct;
1220         
1221         if(!DefRNA.preprocess) {
1222                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1223                 return;
1224         }
1225
1226         if(prop->type != PROP_POINTER) {
1227                 fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, type is not pointer.\n", srna->identifier, prop->identifier);
1228                 DefRNA.error= 1;
1229                 return;
1230         }
1231
1232         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1233                 if(prop->arraylength) {
1234                         prop->arraylength= 0;
1235                         if(!DefRNA.silent) {
1236                                 fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, array not supported for pointer type.\n", structname, propname);
1237                                 DefRNA.error= 1;
1238                         }
1239                 }
1240         }
1241 }
1242
1243 void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
1244 {
1245         PropertyDefRNA *dp;
1246         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1247         StructRNA *srna= DefRNA.laststruct;
1248
1249         if(!DefRNA.preprocess) {
1250                 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1251                 return;
1252         }
1253
1254         if(prop->type != PROP_COLLECTION) {
1255                 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, type is not collection.\n", srna->identifier, prop->identifier);
1256                 DefRNA.error= 1;
1257                 return;
1258         }
1259
1260         if((dp=rna_def_property_sdna(prop, structname, propname))) {
1261                 if(prop->arraylength && !lengthpropname) {
1262                         prop->arraylength= 0;
1263
1264                         if(!DefRNA.silent) {
1265                                 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, array of collections not supported.\n", structname, propname);
1266                                 DefRNA.error= 1;
1267                         }
1268                 }
1269
1270                 if(strcmp(dp->dnatype, "ListBase") == 0) {
1271                         cprop->next= (PropCollectionNextFunc)"rna_iterator_listbase_next";
1272                         cprop->get= (PropCollectionGetFunc)"rna_iterator_listbase_get";
1273                         cprop->end= (PropCollectionEndFunc)"rna_iterator_listbase_end";
1274                 }
1275         }
1276
1277         if(dp && lengthpropname) {
1278                 DNAStructMember smember;
1279                 StructDefRNA *ds= DefRNA.structs.last;
1280
1281                 if(!structname)
1282                         structname= ds->dnaname;
1283
1284                 if(lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
1285                         if(lengthpropname[0] == 0) {
1286                                 dp->dnalengthfixed= prop->arraylength;
1287                                 prop->arraylength= 0;
1288                         }
1289                         else {
1290                                 dp->dnalengthstructname= structname;
1291                                 dp->dnalengthname= lengthpropname;
1292                         }
1293
1294                         cprop->next= (PropCollectionNextFunc)"rna_iterator_array_next";
1295                         cprop->end= (PropCollectionEndFunc)"rna_iterator_array_end";
1296
1297                         if(dp->dnapointerlevel >= 2) 
1298                                 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_dereference_get";
1299                         else
1300                                 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
1301                 }
1302                 else {
1303                         if(!DefRNA.silent) {
1304                                 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s not found.\n", structname, lengthpropname);
1305                                 DefRNA.error= 1;
1306                         }
1307                 }
1308         }
1309 }
1310
1311 /* Functions */
1312
1313 void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
1314 {
1315         if(!DefRNA.preprocess) {
1316                 fprintf(stderr, "RNA_def_property_editable_func: only during preprocessing.\n");
1317                 return;
1318         }
1319
1320         if(editable) prop->editable= (EditableFunc)editable;
1321 }
1322
1323 void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
1324 {
1325         if(!DefRNA.preprocess) {
1326                 fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
1327                 return;
1328         }
1329
1330         prop->noteflag= noteflag;
1331         prop->update= (UpdateFunc)func;
1332 }
1333
1334 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
1335 {
1336         StructRNA *srna= DefRNA.laststruct;
1337
1338         if(!DefRNA.preprocess) {
1339                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1340                 return;
1341         }
1342
1343         switch(prop->type) {
1344                 case PROP_BOOLEAN: {
1345                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1346
1347                         if(prop->arraylength) {
1348                                 if(get) bprop->getarray= (PropBooleanArrayGetFunc)get;
1349                                 if(set) bprop->setarray= (PropBooleanArraySetFunc)set;
1350                         }
1351                         else {
1352                                 if(get) bprop->get= (PropBooleanGetFunc)get;
1353                                 if(set) bprop->set= (PropBooleanSetFunc)set;
1354                         }
1355                         break;
1356                 }
1357                 default:
1358                         fprintf(stderr, "RNA_def_property_boolean_funcs: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
1359                         DefRNA.error= 1;
1360                         break;
1361         }
1362 }
1363
1364 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1365 {
1366         StructRNA *srna= DefRNA.laststruct;
1367
1368         if(!DefRNA.preprocess) {
1369                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1370                 return;
1371         }
1372
1373         switch(prop->type) {
1374                 case PROP_INT: {
1375                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1376
1377                         if(prop->arraylength) {
1378                                 if(get) iprop->getarray= (PropIntArrayGetFunc)get;
1379                                 if(set) iprop->setarray= (PropIntArraySetFunc)set;
1380                         }
1381                         else {
1382                                 if(get) iprop->get= (PropIntGetFunc)get;
1383                                 if(set) iprop->set= (PropIntSetFunc)set;
1384                         }
1385                         if(range) iprop->range= (PropIntRangeFunc)range;
1386                         break;
1387                 }
1388                 default:
1389                         fprintf(stderr, "RNA_def_property_int_funcs: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
1390                         DefRNA.error= 1;
1391                         break;
1392         }
1393 }
1394
1395 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1396 {
1397         StructRNA *srna= DefRNA.laststruct;
1398
1399         if(!DefRNA.preprocess) {
1400                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1401                 return;
1402         }
1403
1404         switch(prop->type) {
1405                 case PROP_FLOAT: {
1406                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1407
1408                         if(prop->arraylength) {
1409                                 if(get) fprop->getarray= (PropFloatArrayGetFunc)get;
1410                                 if(set) fprop->setarray= (PropFloatArraySetFunc)set;
1411                         }
1412                         else {
1413                                 if(get) fprop->get= (PropFloatGetFunc)get;
1414                                 if(set) fprop->set= (PropFloatSetFunc)set;
1415                         }
1416                         if(range) fprop->range= (PropFloatRangeFunc)range;
1417                         break;
1418                 }
1419                 default:
1420                         fprintf(stderr, "RNA_def_property_float_funcs: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1421                         DefRNA.error= 1;
1422                         break;
1423         }
1424 }
1425
1426 void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set)
1427 {
1428         StructRNA *srna= DefRNA.laststruct;
1429
1430         if(!DefRNA.preprocess) {
1431                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1432                 return;
1433         }
1434
1435         switch(prop->type) {
1436                 case PROP_ENUM: {
1437                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1438
1439                         if(get) eprop->get= (PropEnumGetFunc)get;
1440                         if(set) eprop->set= (PropEnumSetFunc)set;
1441                         break;
1442                 }
1443                 default:
1444                         fprintf(stderr, "RNA_def_property_enum_funcs: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1445                         DefRNA.error= 1;
1446                         break;
1447         }
1448 }
1449
1450 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
1451 {
1452         StructRNA *srna= DefRNA.laststruct;
1453
1454         if(!DefRNA.preprocess) {
1455                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1456                 return;
1457         }
1458
1459         switch(prop->type) {
1460                 case PROP_STRING: {
1461                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1462
1463                         if(get) sprop->get= (PropStringGetFunc)get;
1464                         if(length) sprop->length= (PropStringLengthFunc)length;
1465                         if(set) sprop->set= (PropStringSetFunc)set;
1466                         break;
1467                 }
1468                 default:
1469                         fprintf(stderr, "RNA_def_property_string_funcs: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1470                         DefRNA.error= 1;
1471                         break;
1472         }
1473 }
1474
1475 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *type, const char *set)
1476 {
1477         StructRNA *srna= DefRNA.laststruct;
1478
1479         if(!DefRNA.preprocess) {
1480                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1481                 return;
1482         }
1483
1484         switch(prop->type) {
1485                 case PROP_POINTER: {
1486                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1487
1488                         if(get) pprop->get= (PropPointerGetFunc)get;
1489                         if(type) pprop->type= (PropPointerTypeFunc)type;
1490                         if(set) pprop->set= (PropPointerSetFunc)set;
1491                         break;
1492                 }
1493                 default:
1494                         fprintf(stderr, "RNA_def_property_pointer_funcs: %s.%s, type is not pointer.\n", srna->identifier, prop->identifier);
1495                         DefRNA.error= 1;
1496                         break;
1497         }
1498 }
1499
1500 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *type, const char *length, const char *lookupint, const char *lookupstring)
1501 {
1502         StructRNA *srna= DefRNA.laststruct;
1503
1504         if(!DefRNA.preprocess) {
1505                 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1506                 return;
1507         }
1508
1509         switch(prop->type) {
1510                 case PROP_COLLECTION: {
1511                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1512
1513                         if(begin) cprop->begin= (PropCollectionBeginFunc)begin;
1514                         if(next) cprop->next= (PropCollectionNextFunc)next;
1515                         if(end) cprop->end= (PropCollectionEndFunc)end;
1516                         if(get) cprop->get= (PropCollectionGetFunc)get;
1517                         if(type) cprop->type= (PropCollectionTypeFunc)type;
1518                         if(length) cprop->length= (PropCollectionLengthFunc)length;
1519                         if(lookupint) cprop->lookupint= (PropCollectionLookupIntFunc)lookupint;
1520                         if(lookupstring) cprop->lookupstring= (PropCollectionLookupStringFunc)lookupstring;
1521                         break;
1522                 }
1523                 default:
1524                         fprintf(stderr, "RNA_def_property_collection_funcs: %s.%s, type is not collection.\n", srna->identifier, prop->identifier);
1525                         DefRNA.error= 1;
1526                         break;
1527         }
1528 }
1529