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