4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
32 #include "MEM_guardedalloc.h"
34 #include "DNA_genfile.h"
35 #include "DNA_sdna_types.h"
37 #include "RNA_access.h"
38 #include "RNA_define.h"
39 #include "RNA_types.h"
41 #include "BLI_ghash.h"
43 #include "rna_internal.h"
45 /* Global used during defining */
47 BlenderDefRNA DefRNA = {0, {0, 0}, {0, 0}, 0, 0, 0};
49 /* Duplicated code since we can't link in blenkernel or blenlib */
52 #define MIN2(x,y) ((x)<(y)? (x): (y))
53 #define MAX2(x,y) ((x)>(y)? (x): (y))
56 void rna_addtail(ListBase *listbase, void *vlink)
61 link->prev = listbase->last;
63 if (listbase->last) ((Link *)listbase->last)->next = link;
64 if (listbase->first == 0) listbase->first = link;
65 listbase->last = link;
68 void rna_remlink(ListBase *listbase, void *vlink)
72 if (link->next) link->next->prev = link->prev;
73 if (link->prev) link->prev->next = link->next;
75 if (listbase->last == link) listbase->last = link->prev;
76 if (listbase->first == link) listbase->first = link->next;
79 void rna_freelinkN(ListBase *listbase, void *vlink)
81 rna_remlink(listbase, vlink);
85 void rna_freelistN(ListBase *listbase)
89 for(link=listbase->first; link; link=next) {
94 listbase->first= listbase->last= NULL;
97 StructDefRNA *rna_find_struct_def(StructRNA *srna)
101 if(!DefRNA.preprocess) {
102 /* we should never get here */
103 fprintf(stderr, "rna_find_struct_def: only at preprocess time.\n");
107 dsrna= DefRNA.structs.last;
108 for (; dsrna; dsrna= dsrna->cont.prev)
109 if (dsrna->srna==srna)
115 PropertyDefRNA *rna_find_struct_property_def(PropertyRNA *prop)
118 PropertyDefRNA *dprop;
120 if(!DefRNA.preprocess) {
121 /* we should never get here */
122 fprintf(stderr, "rna_find_property_def: only at preprocess time.\n");
126 dsrna= rna_find_struct_def(DefRNA.laststruct);
127 dprop= dsrna->cont.properties.last;
128 for (; dprop; dprop= dprop->prev)
129 if (dprop->prop==prop)
132 dsrna= DefRNA.structs.last;
133 for (; dsrna; dsrna= dsrna->cont.prev) {
134 dprop= dsrna->cont.properties.last;
135 for (; dprop; dprop= dprop->prev)
136 if (dprop->prop==prop)
143 PropertyDefRNA *rna_find_property_def(PropertyRNA *prop)
145 PropertyDefRNA *dprop;
147 if(!DefRNA.preprocess) {
148 /* we should never get here */
149 fprintf(stderr, "rna_find_property_def: only at preprocess time.\n");
153 dprop= rna_find_struct_property_def(prop);
157 dprop= rna_find_parameter_def(prop);
164 FunctionDefRNA *rna_find_function_def(FunctionRNA *func)
167 FunctionDefRNA *dfunc;
169 if(!DefRNA.preprocess) {
170 /* we should never get here */
171 fprintf(stderr, "rna_find_function_def: only at preprocess time.\n");
175 dsrna= rna_find_struct_def(DefRNA.laststruct);
176 dfunc= dsrna->functions.last;
177 for (; dfunc; dfunc= dfunc->cont.prev)
178 if (dfunc->func==func)
181 dsrna= DefRNA.structs.last;
182 for (; dsrna; dsrna= dsrna->cont.prev) {
183 dfunc= dsrna->functions.last;
184 for (; dfunc; dfunc= dfunc->cont.prev)
185 if (dfunc->func==func)
192 PropertyDefRNA *rna_find_parameter_def(PropertyRNA *parm)
195 FunctionDefRNA *dfunc;
196 PropertyDefRNA *dparm;
198 if(!DefRNA.preprocess) {
199 /* we should never get here */
200 fprintf(stderr, "rna_find_parameter_def: only at preprocess time.\n");
204 dsrna= rna_find_struct_def(DefRNA.laststruct);
205 dfunc= dsrna->functions.last;
206 for (; dfunc; dfunc= dfunc->cont.prev) {
207 dparm= dfunc->cont.properties.last;
208 for (; dparm; dparm= dparm->prev)
209 if (dparm->prop==parm)
213 dsrna= DefRNA.structs.last;
214 for (; dsrna; dsrna= dsrna->cont.prev) {
215 dfunc= dsrna->functions.last;
216 for (; dfunc; dfunc= dfunc->cont.prev) {
217 dparm= dfunc->cont.properties.last;
218 for (; dparm; dparm= dparm->prev)
219 if (dparm->prop==parm)
227 ContainerDefRNA *rna_find_container_def(ContainerRNA *cont)
230 FunctionDefRNA *dfunc;
232 if(!DefRNA.preprocess) {
233 /* we should never get here */
234 fprintf(stderr, "rna_find_container_def: only at preprocess time.\n");
238 ds= rna_find_struct_def((StructRNA*)cont);
242 dfunc= rna_find_function_def((FunctionRNA*)cont);
249 /* DNA utility function for looking up members */
251 typedef struct DNAStructMember {
258 static int rna_member_cmp(const char *name, const char *oname)
262 /* compare without pointer or array part */
269 if(name[a]=='[' && oname[a]==0) return 1;
270 if(name[a]=='[' && oname[a]=='[') return 1;
271 if(name[a]==0) break;
272 if(name[a] != oname[a]) return 0;
275 if(name[a]==0 && oname[a] == '.') return 2;
276 if(name[a]==0 && oname[a] == '-' && oname[a+1] == '>') return 3;
278 return (name[a] == oname[a]);
281 static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *membername, DNAStructMember *smember)
285 int a, b, structnr, totmember, cmp;
287 structnr= DNA_struct_find_nr(sdna, structname);
291 sp= sdna->structs[structnr];
295 for(a=0; a<totmember; a++, sp+=2) {
296 dnaname= sdna->names[sp[1]];
298 cmp= rna_member_cmp(dnaname, membername);
301 smember->type= sdna->types[sp[0]];
302 smember->name= dnaname;
304 if(strstr(membername, "["))
305 smember->arraylength= 0;
307 smember->arraylength= DNA_elem_array_size(smember->name, strlen(smember->name));
309 smember->pointerlevel= 0;
310 for(b=0; dnaname[b] == '*'; b++)
311 smember->pointerlevel++;
317 smember->name= dnaname;
318 smember->pointerlevel= 0;
319 smember->arraylength= 0;
321 membername= strstr(membername, ".") + strlen(".");
322 rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
328 smember->name= dnaname;
329 smember->pointerlevel= 0;
330 smember->arraylength= 0;
332 membername= strstr(membername, "->") + strlen("->");
333 rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
342 static int rna_validate_identifier(const char *identifier, char *error, int property)
346 /* list from http://docs.python.org/reference/lexical_analysis.html#id5 */
347 static char *kwlist[] = {
348 "and", "as", "assert", "break",
349 "class", "continue", "def", "del",
350 "elif", "else", "except", "exec",
351 "finally", "for", "from", "global",
352 "if", "import", "in", "is",
353 "lambda", "not", "or", "pass",
354 "print", "raise", "return", "try",
355 "while", "with", "yield", NULL
359 if (!isalpha(identifier[0])) {
360 strcpy(error, "first character failed isalpha() check");
364 for(a=0; identifier[a]; a++) {
365 if(DefRNA.preprocess && property) {
366 if(isalpha(identifier[a]) && isupper(identifier[a])) {
367 strcpy(error, "property names must contain lower case characters only");
372 if (identifier[a]=='_') {
376 if (identifier[a]==' ') {
377 strcpy(error, "spaces are not ok in identifier names");
381 if (isalnum(identifier[a])==0) {
382 strcpy(error, "one of the characters failed an isalnum() check and is not an underscore");
387 for(a=0; kwlist[a]; a++) {
388 if (strcmp(identifier, kwlist[a]) == 0) {
389 strcpy(error, "this keyword is reserved by python");
397 /* Blender Data Definition */
399 BlenderRNA *RNA_create()
403 brna= MEM_callocN(sizeof(BlenderRNA), "BlenderRNA");
405 DefRNA.sdna= DNA_sdna_from_data(DNAstr, DNAlen, 0);
406 DefRNA.structs.first= DefRNA.structs.last= NULL;
408 DefRNA.preprocess= 1;
413 void RNA_define_free(BlenderRNA *brna)
416 FunctionDefRNA *dfunc;
419 for(alloc=DefRNA.allocs.first; alloc; alloc=alloc->next)
420 MEM_freeN(alloc->mem);
421 rna_freelistN(&DefRNA.allocs);
423 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
424 for (dfunc= ds->functions.first; dfunc; dfunc= dfunc->cont.next)
425 rna_freelistN(&dfunc->cont.properties);
427 rna_freelistN(&ds->cont.properties);
428 rna_freelistN(&ds->functions);
431 rna_freelistN(&DefRNA.structs);
434 DNA_sdna_free(DefRNA.sdna);
441 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
443 FunctionRNA *func, *nextfunc;
444 PropertyRNA *prop, *nextprop;
445 PropertyRNA *parm, *nextparm;
447 for(prop=srna->cont.properties.first; prop; prop=nextprop) {
448 nextprop= prop->next;
450 if(prop->flag & PROP_RUNTIME)
451 rna_freelinkN(&srna->cont.properties, prop);
454 for(func=srna->functions.first; func; func=nextfunc) {
455 nextfunc= func->cont.next;
457 for(parm=func->cont.properties.first; parm; parm=nextparm) {
458 nextparm= parm->next;
460 if(parm->flag & PROP_RUNTIME)
461 rna_freelinkN(&func->cont.properties, parm);
464 if(func->flag & FUNC_RUNTIME) {
465 rna_freelinkN(&srna->functions, func);
469 if(srna->flag & STRUCT_RUNTIME)
470 rna_freelinkN(&brna->structs, srna);
473 void RNA_free(BlenderRNA *brna)
475 StructRNA *srna, *nextsrna;
478 if(DefRNA.preprocess) {
479 RNA_define_free(brna);
481 for(srna=brna->structs.first; srna; srna=srna->cont.next) {
482 for (func= srna->functions.first; func; func= func->cont.next)
483 rna_freelistN(&func->cont.properties);
485 rna_freelistN(&srna->cont.properties);
486 rna_freelistN(&srna->functions);
489 rna_freelistN(&brna->structs);
494 for(srna=brna->structs.first; srna; srna=nextsrna) {
495 nextsrna= srna->cont.next;
496 RNA_struct_free(brna, srna);
501 static size_t rna_property_type_sizeof(PropertyType type)
504 case PROP_BOOLEAN: return sizeof(BooleanPropertyRNA);
505 case PROP_INT: return sizeof(IntPropertyRNA);
506 case PROP_FLOAT: return sizeof(FloatPropertyRNA);
507 case PROP_STRING: return sizeof(StringPropertyRNA);
508 case PROP_ENUM: return sizeof(EnumPropertyRNA);
509 case PROP_POINTER: return sizeof(PointerPropertyRNA);
510 case PROP_COLLECTION: return sizeof(CollectionPropertyRNA);
515 static StructDefRNA *rna_find_def_struct(StructRNA *srna)
519 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
526 /* Struct Definition */
528 StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
530 StructRNA *srna, *srnafrom= NULL;
531 StructDefRNA *ds= NULL, *dsfrom= NULL;
534 if(DefRNA.preprocess) {
537 if (rna_validate_identifier(identifier, error, 0) == 0) {
538 fprintf(stderr, "RNA_def_struct: struct identifier \"%s\" error - %s\n", identifier, error);
544 /* find struct to derive from */
545 for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->cont.next)
546 if(strcmp(srnafrom->identifier, from) == 0)
550 fprintf(stderr, "RNA_def_struct: struct %s not found to define %s.\n", from, identifier);
555 srna= MEM_callocN(sizeof(StructRNA), "StructRNA");
556 DefRNA.laststruct= srna;
559 /* copy from struct to derive stuff, a bit clumsy since we can't
560 * use MEM_dupallocN, data structs may not be alloced but builtin */
561 memcpy(srna, srnafrom, sizeof(StructRNA));
562 srna->cont.prophash= NULL;
563 srna->cont.properties.first= srna->cont.properties.last= NULL;
564 srna->functions.first= srna->functions.last= NULL;
567 if(DefRNA.preprocess) {
568 srna->base= srnafrom;
569 dsfrom= rna_find_def_struct(srnafrom);
572 srna->base= srnafrom;
575 srna->identifier= identifier;
576 srna->name= identifier; /* may be overwritten later RNA_def_struct_ui_text */
577 srna->description= "";
579 srna->icon= ICON_DOT;
581 rna_addtail(&brna->structs, srna);
583 if(DefRNA.preprocess) {
584 ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
586 rna_addtail(&DefRNA.structs, ds);
589 ds->dnafromname= dsfrom->dnaname;
592 /* in preprocess, try to find sdna */
593 if(DefRNA.preprocess)
594 RNA_def_struct_sdna(srna, srna->identifier);
596 srna->flag |= STRUCT_RUNTIME;
599 srna->nameproperty= srnafrom->nameproperty;
600 srna->iteratorproperty= srnafrom->iteratorproperty;
603 /* define some builtin properties */
604 prop= RNA_def_property(&srna->cont, "rna_properties", PROP_COLLECTION, PROP_NONE);
605 RNA_def_property_flag(prop, PROP_BUILTIN);
606 RNA_def_property_ui_text(prop, "Properties", "RNA property collection.");
608 if(DefRNA.preprocess) {
609 RNA_def_property_struct_type(prop, "Property");
610 RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next", "rna_iterator_listbase_end", "rna_builtin_properties_get", 0, 0, "rna_builtin_properties_lookup_string", 0, 0);
614 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
615 cprop->begin= rna_builtin_properties_begin;
616 cprop->next= rna_builtin_properties_next;
617 cprop->get= rna_builtin_properties_get;
618 cprop->type= &RNA_Property;
622 prop= RNA_def_property(&srna->cont, "rna_type", PROP_POINTER, PROP_NONE);
623 RNA_def_property_ui_text(prop, "RNA", "RNA type definition.");
625 if(DefRNA.preprocess) {
626 RNA_def_property_struct_type(prop, "Struct");
627 RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL);
631 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
632 pprop->get= rna_builtin_type_get;
633 pprop->type= &RNA_Struct;
641 void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
645 if(!DefRNA.preprocess) {
646 fprintf(stderr, "RNA_def_struct_sdna: only during preprocessing.\n");
650 ds= rna_find_def_struct(srna);
652 if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
654 fprintf(stderr, "RNA_def_struct_sdna: %s not found.\n", structname);
660 ds->dnaname= structname;
663 void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
667 if(!DefRNA.preprocess) {
668 fprintf(stderr, "RNA_def_struct_sdna_from: only during preprocessing.\n");
672 ds= rna_find_def_struct(srna);
675 fprintf(stderr, "RNA_def_struct_sdna_from: %s base struct must know DNA already.\n", structname);
679 if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
681 fprintf(stderr, "RNA_def_struct_sdna_from: %s not found.\n", structname);
687 ds->dnafromprop= propname;
688 ds->dnaname= structname;
691 void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
693 if(prop->type != PROP_STRING) {
694 fprintf(stderr, "RNA_def_struct_name_property: %s.%s, must be a string property.\n", srna->identifier, prop->identifier);
698 srna->nameproperty= prop;
701 void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
705 /* find struct to derive from */
706 for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->cont.next)
707 if(strcmp(srnafrom->identifier, structname) == 0)
711 fprintf(stderr, "RNA_def_struct_nested: struct %s not found.\n", structname);
715 srna->nested= srnafrom;
718 void RNA_def_struct_flag(StructRNA *srna, int flag)
723 void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
728 void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
730 if(!DefRNA.preprocess) {
731 fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
735 if(refine) srna->refine= (StructRefineFunc)refine;
738 void RNA_def_struct_idproperties_func(StructRNA *srna, const char *idproperties)
740 if(!DefRNA.preprocess) {
741 fprintf(stderr, "RNA_def_struct_idproperties_func: only during preprocessing.\n");
745 if(idproperties) srna->idproperties= (IDPropertiesFunc)idproperties;
748 void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg)
750 if(!DefRNA.preprocess) {
751 fprintf(stderr, "RNA_def_struct_register_funcs: only during preprocessing.\n");
755 if(reg) srna->reg= (StructRegisterFunc)reg;
756 if(unreg) srna->unreg= (StructUnregisterFunc)unreg;
759 void RNA_def_struct_path_func(StructRNA *srna, const char *path)
761 if(!DefRNA.preprocess) {
762 fprintf(stderr, "RNA_def_struct_path_func: only during preprocessing.\n");
766 if(path) srna->path= (StructPathFunc)path;
769 void RNA_def_struct_identifier(StructRNA *srna, const char *identifier)
771 if(DefRNA.preprocess) {
772 fprintf(stderr, "RNA_def_struct_name_runtime: only at runtime.\n");
776 srna->identifier= identifier;
779 void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
782 srna->description= description;
785 void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
790 /* Property Definition */
792 PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
794 StructRNA *srna= DefRNA.laststruct;
795 ContainerRNA *cont= cont_;
796 ContainerDefRNA *dcont;
797 PropertyDefRNA *dprop= NULL;
800 if(DefRNA.preprocess) {
803 if (rna_validate_identifier(identifier, error, 1) == 0) {
804 fprintf(stderr, "RNA_def_property: property identifier \"%s\" - %s\n", identifier, error);
808 dcont= rna_find_container_def(cont);
809 dprop= MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA");
810 rna_addtail(&dcont->properties, dprop);
813 prop= MEM_callocN(rna_property_type_sizeof(type), "PropertyRNA");
819 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
821 iprop->hardmin= (subtype == PROP_UNSIGNED)? 0: INT_MIN;
822 iprop->hardmax= INT_MAX;
824 iprop->softmin= (subtype == PROP_UNSIGNED)? 0: -10000; /* rather arbitrary .. */
825 iprop->softmax= 10000;
830 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
832 fprop->hardmin= (subtype == PROP_UNSIGNED)? 0.0f: -FLT_MAX;
833 fprop->hardmax= FLT_MAX;
835 if(subtype == PROP_COLOR) {
836 fprop->softmin= 0.0f;
837 fprop->softmax= 1.0f;
839 else if(subtype == PROP_PERCENTAGE) {
840 fprop->softmin= fprop->hardmin= 0.0f;
841 fprop->softmax= fprop->hardmax= 1.0f;
844 fprop->softmin= (subtype == PROP_UNSIGNED)? 0.0f: -10000.0f; /* rather arbitrary .. */
845 fprop->softmax= 10000.0f;
852 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
854 sprop->defaultvalue= "";
860 case PROP_COLLECTION:
863 fprintf(stderr, "RNA_def_property: %s.%s, invalid property type.\n", srna->identifier, identifier);
868 if(DefRNA.preprocess) {
873 prop->magic= RNA_MAGIC;
874 prop->identifier= identifier;
876 prop->subtype= subtype;
877 prop->name= identifier;
878 prop->description= "";
880 if(type != PROP_COLLECTION && type != PROP_POINTER) {
881 prop->flag= PROP_EDITABLE;
883 if(type != PROP_STRING)
884 prop->flag |= PROP_ANIMATEABLE;
887 if(DefRNA.preprocess) {
891 RNA_def_property_boolean_sdna(prop, NULL, identifier, 0);
896 RNA_def_property_int_sdna(prop, NULL, identifier);
902 RNA_def_property_float_sdna(prop, NULL, identifier);
908 RNA_def_property_string_sdna(prop, NULL, identifier);
914 RNA_def_property_enum_sdna(prop, NULL, identifier);
919 RNA_def_property_pointer_sdna(prop, NULL, identifier);
922 case PROP_COLLECTION:
924 RNA_def_property_collection_sdna(prop, NULL, identifier, NULL);
930 prop->flag |= PROP_IDPROPERTY|PROP_RUNTIME;
933 BLI_ghash_insert(cont->prophash, (void*)prop->identifier, prop);
937 rna_addtail(&cont->properties, prop);
942 void RNA_def_property_flag(PropertyRNA *prop, int flag)
947 void RNA_def_property_clear_flag(PropertyRNA *prop, int flag)
952 void RNA_def_property_array(PropertyRNA *prop, int arraylength)
954 StructRNA *srna= DefRNA.laststruct;
957 fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be zero of greater.\n", srna->identifier, prop->identifier);
962 if(arraylength>RNA_MAX_ARRAY) {
963 fprintf(stderr, "RNA_def_property_array: %s.%s, array length must be smaller than %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY);
972 prop->arraylength= arraylength;
975 fprintf(stderr, "RNA_def_property_array: %s.%s, only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
981 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
984 prop->description= description;
987 void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
991 prop->flag |= PROP_ICONS_CONSECUTIVE;
994 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
996 StructRNA *srna= DefRNA.laststruct;
1000 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1001 iprop->softmin= (int)min;
1002 iprop->softmax= (int)max;
1003 iprop->step= (int)step;
1007 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1008 fprop->softmin= (float)min;
1009 fprop->softmax= (float)max;
1010 fprop->step= (float)step;
1011 fprop->precision= (int)precision;
1015 fprintf(stderr, "RNA_def_property_ui_range: %s.%s, invalid type for ui range.\n", srna->identifier, prop->identifier);
1021 void RNA_def_property_range(PropertyRNA *prop, double min, double max)
1023 StructRNA *srna= DefRNA.laststruct;
1025 switch(prop->type) {
1027 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1028 iprop->hardmin= (int)min;
1029 iprop->hardmax= (int)max;
1030 iprop->softmin= MAX2((int)min, iprop->hardmin);
1031 iprop->softmax= MIN2((int)max, iprop->hardmax);
1035 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1036 fprop->hardmin= (float)min;
1037 fprop->hardmax= (float)max;
1038 fprop->softmin= MAX2((float)min, fprop->hardmin);
1039 fprop->softmax= MIN2((float)max, fprop->hardmax);
1043 fprintf(stderr, "RNA_def_property_range: %s.%s, invalid type for range.\n", srna->identifier, prop->identifier);
1049 void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
1051 StructRNA *srna= DefRNA.laststruct;
1053 if(!DefRNA.preprocess) {
1054 fprintf(stderr, "RNA_def_property_struct_type: only during preprocessing.\n");
1058 switch(prop->type) {
1059 case PROP_POINTER: {
1060 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1061 pprop->type = (StructRNA*)type;
1064 case PROP_COLLECTION: {
1065 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1066 cprop->type = (StructRNA*)type;
1070 fprintf(stderr, "RNA_def_property_struct_type: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
1076 void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type)
1078 StructRNA *srna= DefRNA.laststruct;
1080 if(DefRNA.preprocess) {
1081 fprintf(stderr, "RNA_def_property_struct_runtime: only at runtime.\n");
1085 switch(prop->type) {
1086 case PROP_POINTER: {
1087 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1090 if(type && (type->flag & STRUCT_ID_REFCOUNT))
1091 prop->flag |= PROP_ID_REFCOUNT;
1095 case PROP_COLLECTION: {
1096 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1101 fprintf(stderr, "RNA_def_property_struct_runtime: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
1107 void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
1109 StructRNA *srna= DefRNA.laststruct;
1110 int i, defaultfound= 0;
1112 switch(prop->type) {
1114 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1117 for(i=0; item[i].identifier; i++) {
1120 if(item[i].value == eprop->defaultvalue)
1125 eprop->defaultvalue= item[0].value;
1130 fprintf(stderr, "RNA_def_property_enum_items: %s.%s, invalid type for struct type.\n", srna->identifier, prop->identifier);
1136 void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
1138 StructRNA *srna= DefRNA.laststruct;
1140 switch(prop->type) {
1142 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1143 sprop->maxlength= maxlength;
1147 fprintf(stderr, "RNA_def_property_string_maxlength: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1153 void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
1155 StructRNA *srna= DefRNA.laststruct;
1157 switch(prop->type) {
1158 case PROP_BOOLEAN: {
1159 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1160 bprop->defaultvalue= value;
1164 fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
1170 void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
1172 StructRNA *srna= DefRNA.laststruct;
1174 switch(prop->type) {
1175 case PROP_BOOLEAN: {
1176 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1177 bprop->defaultarray= array;
1181 fprintf(stderr, "RNA_def_property_boolean_default: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
1187 void RNA_def_property_int_default(PropertyRNA *prop, int value)
1189 StructRNA *srna= DefRNA.laststruct;
1191 switch(prop->type) {
1193 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1194 iprop->defaultvalue= value;
1198 fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
1204 void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
1206 StructRNA *srna= DefRNA.laststruct;
1208 switch(prop->type) {
1210 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1211 iprop->defaultarray= array;
1215 fprintf(stderr, "RNA_def_property_int_default: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
1221 void RNA_def_property_float_default(PropertyRNA *prop, float value)
1223 StructRNA *srna= DefRNA.laststruct;
1225 switch(prop->type) {
1227 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1228 fprop->defaultvalue= value;
1232 fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1237 /* array must remain valid after this function finishes */
1238 void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
1240 StructRNA *srna= DefRNA.laststruct;
1242 switch(prop->type) {
1244 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1245 fprop->defaultarray= array; /* WARNING, this array must not come from the stack and lost */
1249 fprintf(stderr, "RNA_def_property_float_default: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1255 void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
1257 StructRNA *srna= DefRNA.laststruct;
1259 switch(prop->type) {
1261 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1262 sprop->defaultvalue= value;
1266 fprintf(stderr, "RNA_def_property_string_default: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1272 void RNA_def_property_enum_default(PropertyRNA *prop, int value)
1274 StructRNA *srna= DefRNA.laststruct;
1275 int i, defaultfound= 0;
1277 switch(prop->type) {
1279 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1280 eprop->defaultvalue= value;
1282 for(i=0; i<eprop->totitem; i++) {
1283 if(eprop->item[i].value == eprop->defaultvalue)
1287 if(!defaultfound && eprop->totitem) {
1289 eprop->defaultvalue= eprop->item[0].value;
1292 fprintf(stderr, "RNA_def_property_enum_default: %s.%s, default is not in items.\n", srna->identifier, prop->identifier);
1300 fprintf(stderr, "RNA_def_property_enum_default: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1308 static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1310 DNAStructMember smember;
1314 dp= rna_find_struct_property_def(prop);
1315 if (dp==NULL) return NULL;
1317 ds= rna_find_struct_def((StructRNA*)dp->cont);
1320 structname= ds->dnaname;
1322 propname= prop->identifier;
1324 if(!rna_find_sdna_member(DefRNA.sdna, structname, propname, &smember)) {
1325 if(!DefRNA.silent) {
1326 fprintf(stderr, "rna_def_property_sdna: %s.%s not found.\n", structname, propname);
1332 if(smember.arraylength > 1)
1333 prop->arraylength= smember.arraylength;
1335 prop->arraylength= 0;
1337 dp->dnastructname= structname;
1338 dp->dnastructfromname= ds->dnafromname;
1339 dp->dnastructfromprop= ds->dnafromprop;
1340 dp->dnaname= propname;
1341 dp->dnatype= smember.type;
1342 dp->dnaarraylength= smember.arraylength;
1343 dp->dnapointerlevel= smember.pointerlevel;
1348 void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int bit)
1351 StructRNA *srna= DefRNA.laststruct;
1353 if(!DefRNA.preprocess) {
1354 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1358 if(prop->type != PROP_BOOLEAN) {
1359 fprintf(stderr, "RNA_def_property_boolean_sdna: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
1364 if((dp=rna_def_property_sdna(prop, structname, propname)))
1365 dp->booleanbit= bit;
1368 void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int booleanbit)
1372 RNA_def_property_boolean_sdna(prop, structname, propname, booleanbit);
1374 dp= rna_find_struct_property_def(prop);
1377 dp->booleannegative= 1;
1380 void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1383 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1384 StructRNA *srna= DefRNA.laststruct;
1386 if(!DefRNA.preprocess) {
1387 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1391 if(prop->type != PROP_INT) {
1392 fprintf(stderr, "RNA_def_property_int_sdna: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
1397 if((dp= rna_def_property_sdna(prop, structname, propname))) {
1398 /* SDNA doesn't pass us unsigned unfortunately .. */
1399 if(strcmp(dp->dnatype, "char") == 0) {
1400 iprop->hardmin= iprop->softmin= CHAR_MIN;
1401 iprop->hardmax= iprop->softmax= CHAR_MAX;
1403 else if(strcmp(dp->dnatype, "short") == 0) {
1404 iprop->hardmin= iprop->softmin= SHRT_MIN;
1405 iprop->hardmax= iprop->softmax= SHRT_MAX;
1407 else if(strcmp(dp->dnatype, "int") == 0) {
1408 iprop->hardmin= INT_MIN;
1409 iprop->hardmax= INT_MAX;
1411 iprop->softmin= -10000; /* rather arbitrary .. */
1412 iprop->softmax= 10000;
1415 if(prop->subtype == PROP_UNSIGNED || prop->subtype == PROP_PERCENTAGE)
1416 iprop->hardmin= iprop->softmin= 0;
1420 void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1422 StructRNA *srna= DefRNA.laststruct;
1424 if(!DefRNA.preprocess) {
1425 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1429 if(prop->type != PROP_FLOAT) {
1430 fprintf(stderr, "RNA_def_property_float_sdna: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1435 rna_def_property_sdna(prop, structname, propname);
1438 void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1441 StructRNA *srna= DefRNA.laststruct;
1443 if(!DefRNA.preprocess) {
1444 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1448 if(prop->type != PROP_ENUM) {
1449 fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1454 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1455 if(prop->arraylength) {
1456 prop->arraylength= 0;
1457 if(!DefRNA.silent) {
1458 fprintf(stderr, "RNA_def_property_enum_sdna: %s.%s, array not supported for enum type.\n", structname, propname);
1465 void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1469 RNA_def_property_enum_sdna(prop, structname, propname);
1471 dp= rna_find_struct_property_def(prop);
1474 dp->enumbitflags= 1;
1477 void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1480 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1481 StructRNA *srna= DefRNA.laststruct;
1483 if(!DefRNA.preprocess) {
1484 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1488 if(prop->type != PROP_STRING) {
1489 fprintf(stderr, "RNA_def_property_string_sdna: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1494 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1495 if(prop->arraylength) {
1496 sprop->maxlength= prop->arraylength;
1497 prop->arraylength= 0;
1502 void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1505 StructRNA *srna= DefRNA.laststruct;
1507 if(!DefRNA.preprocess) {
1508 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1512 if(prop->type != PROP_POINTER) {
1513 fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, type is not pointer.\n", srna->identifier, prop->identifier);
1518 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1519 if(prop->arraylength) {
1520 prop->arraylength= 0;
1521 if(!DefRNA.silent) {
1522 fprintf(stderr, "RNA_def_property_pointer_sdna: %s.%s, array not supported for pointer type.\n", structname, propname);
1529 void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
1532 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1533 StructRNA *srna= DefRNA.laststruct;
1535 if(!DefRNA.preprocess) {
1536 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1540 if(prop->type != PROP_COLLECTION) {
1541 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, type is not collection.\n", srna->identifier, prop->identifier);
1546 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1547 if(prop->arraylength && !lengthpropname) {
1548 prop->arraylength= 0;
1550 if(!DefRNA.silent) {
1551 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s, array of collections not supported.\n", structname, propname);
1556 if(strcmp(dp->dnatype, "ListBase") == 0) {
1557 cprop->next= (PropCollectionNextFunc)"rna_iterator_listbase_next";
1558 cprop->get= (PropCollectionGetFunc)"rna_iterator_listbase_get";
1559 cprop->end= (PropCollectionEndFunc)"rna_iterator_listbase_end";
1563 if(dp && lengthpropname) {
1564 DNAStructMember smember;
1565 StructDefRNA *ds= rna_find_struct_def((StructRNA*)dp->cont);
1568 structname= ds->dnaname;
1570 if(lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
1571 if(lengthpropname[0] == 0) {
1572 dp->dnalengthfixed= prop->arraylength;
1573 prop->arraylength= 0;
1576 dp->dnalengthstructname= structname;
1577 dp->dnalengthname= lengthpropname;
1580 cprop->next= (PropCollectionNextFunc)"rna_iterator_array_next";
1581 cprop->end= (PropCollectionEndFunc)"rna_iterator_array_end";
1583 if(dp->dnapointerlevel >= 2)
1584 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_dereference_get";
1586 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
1589 if(!DefRNA.silent) {
1590 fprintf(stderr, "RNA_def_property_collection_sdna: %s.%s not found.\n", structname, lengthpropname);
1599 void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
1601 if(!DefRNA.preprocess) {
1602 fprintf(stderr, "RNA_def_property_editable_func: only during preprocessing.\n");
1606 if(editable) prop->editable= (EditableFunc)editable;
1609 void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
1611 if(!DefRNA.preprocess) {
1612 fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
1616 prop->noteflag= noteflag;
1617 prop->update= (UpdateFunc)func;
1620 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
1622 StructRNA *srna= DefRNA.laststruct;
1624 if(!DefRNA.preprocess) {
1625 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1629 switch(prop->type) {
1630 case PROP_BOOLEAN: {
1631 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1633 if(prop->arraylength) {
1634 if(get) bprop->getarray= (PropBooleanArrayGetFunc)get;
1635 if(set) bprop->setarray= (PropBooleanArraySetFunc)set;
1638 if(get) bprop->get= (PropBooleanGetFunc)get;
1639 if(set) bprop->set= (PropBooleanSetFunc)set;
1644 fprintf(stderr, "RNA_def_property_boolean_funcs: %s.%s, type is not boolean.\n", srna->identifier, prop->identifier);
1650 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1652 StructRNA *srna= DefRNA.laststruct;
1654 if(!DefRNA.preprocess) {
1655 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1659 switch(prop->type) {
1661 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1663 if(prop->arraylength) {
1664 if(get) iprop->getarray= (PropIntArrayGetFunc)get;
1665 if(set) iprop->setarray= (PropIntArraySetFunc)set;
1668 if(get) iprop->get= (PropIntGetFunc)get;
1669 if(set) iprop->set= (PropIntSetFunc)set;
1671 if(range) iprop->range= (PropIntRangeFunc)range;
1675 fprintf(stderr, "RNA_def_property_int_funcs: %s.%s, type is not int.\n", srna->identifier, prop->identifier);
1681 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1683 StructRNA *srna= DefRNA.laststruct;
1685 if(!DefRNA.preprocess) {
1686 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1690 switch(prop->type) {
1692 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1694 if(prop->arraylength) {
1695 if(get) fprop->getarray= (PropFloatArrayGetFunc)get;
1696 if(set) fprop->setarray= (PropFloatArraySetFunc)set;
1699 if(get) fprop->get= (PropFloatGetFunc)get;
1700 if(set) fprop->set= (PropFloatSetFunc)set;
1702 if(range) fprop->range= (PropFloatRangeFunc)range;
1706 fprintf(stderr, "RNA_def_property_float_funcs: %s.%s, type is not float.\n", srna->identifier, prop->identifier);
1712 void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
1714 StructRNA *srna= DefRNA.laststruct;
1716 if(!DefRNA.preprocess) {
1717 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1721 switch(prop->type) {
1723 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1725 if(get) eprop->get= (PropEnumGetFunc)get;
1726 if(set) eprop->set= (PropEnumSetFunc)set;
1727 if(item) eprop->itemf= (PropEnumItemFunc)item;
1731 fprintf(stderr, "RNA_def_property_enum_funcs: %s.%s, type is not enum.\n", srna->identifier, prop->identifier);
1737 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
1739 StructRNA *srna= DefRNA.laststruct;
1741 if(!DefRNA.preprocess) {
1742 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1746 switch(prop->type) {
1748 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1750 if(get) sprop->get= (PropStringGetFunc)get;
1751 if(length) sprop->length= (PropStringLengthFunc)length;
1752 if(set) sprop->set= (PropStringSetFunc)set;
1756 fprintf(stderr, "RNA_def_property_string_funcs: %s.%s, type is not string.\n", srna->identifier, prop->identifier);
1762 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *typef)
1764 StructRNA *srna= DefRNA.laststruct;
1766 if(!DefRNA.preprocess) {
1767 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1771 switch(prop->type) {
1772 case PROP_POINTER: {
1773 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1775 if(get) pprop->get= (PropPointerGetFunc)get;
1776 if(set) pprop->set= (PropPointerSetFunc)set;
1777 if(typef) pprop->typef= (PropPointerTypeFunc)typef;
1781 fprintf(stderr, "RNA_def_property_pointer_funcs: %s.%s, type is not pointer.\n", srna->identifier, prop->identifier);
1787 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *add, const char *remove)
1789 StructRNA *srna= DefRNA.laststruct;
1791 if(!DefRNA.preprocess) {
1792 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1796 switch(prop->type) {
1797 case PROP_COLLECTION: {
1798 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1800 if(begin) cprop->begin= (PropCollectionBeginFunc)begin;
1801 if(next) cprop->next= (PropCollectionNextFunc)next;
1802 if(end) cprop->end= (PropCollectionEndFunc)end;
1803 if(get) cprop->get= (PropCollectionGetFunc)get;
1804 if(length) cprop->length= (PropCollectionLengthFunc)length;
1805 if(lookupint) cprop->lookupint= (PropCollectionLookupIntFunc)lookupint;
1806 if(lookupstring) cprop->lookupstring= (PropCollectionLookupStringFunc)lookupstring;
1807 if(add) cprop->add= (FunctionRNA*)add;
1808 if(remove) cprop->remove= (FunctionRNA*)remove;
1812 fprintf(stderr, "RNA_def_property_collection_funcs: %s.%s, type is not collection.\n", srna->identifier, prop->identifier);
1818 /* Compact definitions */
1820 PropertyRNA *RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, int default_value, const char *ui_name, const char *ui_description)
1822 ContainerRNA *cont= cont_;
1825 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
1826 RNA_def_property_boolean_default(prop, default_value);
1827 RNA_def_property_ui_text(prop, ui_name, ui_description);
1832 PropertyRNA *RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
1833 const char *ui_name, const char *ui_description)
1835 ContainerRNA *cont= cont_;
1838 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
1839 if(len != 0) RNA_def_property_array(prop, len);
1840 if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
1841 RNA_def_property_ui_text(prop, ui_name, ui_description);
1846 PropertyRNA *RNA_def_boolean_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
1847 const char *ui_name, const char *ui_description)
1849 ContainerRNA *cont= cont_;
1852 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_VECTOR);
1853 if(len != 0) RNA_def_property_array(prop, len);
1854 if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
1855 RNA_def_property_ui_text(prop, ui_name, ui_description);
1860 PropertyRNA *RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax,
1861 const char *ui_name, const char *ui_description, int softmin, int softmax)
1863 ContainerRNA *cont= cont_;
1866 prop= RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
1867 RNA_def_property_int_default(prop, default_value);
1868 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
1869 RNA_def_property_ui_text(prop, ui_name, ui_description);
1870 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
1875 PropertyRNA *RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value,
1876 int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
1878 ContainerRNA *cont= cont_;
1881 prop= RNA_def_property(cont, identifier, PROP_INT, PROP_VECTOR);
1882 if(len != 0) RNA_def_property_array(prop, len);
1883 if(default_value) RNA_def_property_int_array_default(prop, default_value);
1884 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
1885 RNA_def_property_ui_text(prop, ui_name, ui_description);
1886 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
1891 PropertyRNA *RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value,
1892 int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
1894 ContainerRNA *cont= cont_;
1897 prop= RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
1898 if(len != 0) RNA_def_property_array(prop, len);
1899 if(default_value) RNA_def_property_int_array_default(prop, default_value);
1900 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
1901 RNA_def_property_ui_text(prop, ui_name, ui_description);
1902 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
1907 PropertyRNA *RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
1908 const char *ui_name, const char *ui_description)
1910 ContainerRNA *cont= cont_;
1913 prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_NONE);
1914 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
1915 if(default_value) RNA_def_property_string_default(prop, default_value);
1916 RNA_def_property_ui_text(prop, ui_name, ui_description);
1921 PropertyRNA *RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
1922 const char *ui_name, const char *ui_description)
1924 ContainerRNA *cont= cont_;
1927 prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_FILEPATH);
1928 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
1929 if(default_value) RNA_def_property_string_default(prop, default_value);
1930 RNA_def_property_ui_text(prop, ui_name, ui_description);
1935 PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
1936 const char *ui_name, const char *ui_description)
1938 ContainerRNA *cont= cont_;
1941 prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_DIRPATH);
1942 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
1943 if(default_value) RNA_def_property_string_default(prop, default_value);
1944 RNA_def_property_ui_text(prop, ui_name, ui_description);
1949 PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value,
1950 const char *ui_name, const char *ui_description)
1952 ContainerRNA *cont= cont_;
1955 prop= RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
1956 if(items) RNA_def_property_enum_items(prop, items);
1957 RNA_def_property_enum_default(prop, default_value);
1958 RNA_def_property_ui_text(prop, ui_name, ui_description);
1963 PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
1964 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
1966 ContainerRNA *cont= cont_;
1969 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
1970 RNA_def_property_float_default(prop, default_value);
1971 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
1972 RNA_def_property_ui_text(prop, ui_name, ui_description);
1973 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
1978 PropertyRNA *RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
1979 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
1981 ContainerRNA *cont= cont_;
1984 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_VECTOR);
1985 if(len != 0) RNA_def_property_array(prop, len);
1986 if(default_value) RNA_def_property_float_array_default(prop, default_value);
1987 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
1988 RNA_def_property_ui_text(prop, ui_name, ui_description);
1989 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
1994 PropertyRNA *RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
1995 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
1997 ContainerRNA *cont= cont_;
2000 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_COLOR);
2001 if(len != 0) RNA_def_property_array(prop, len);
2002 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2003 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2004 RNA_def_property_ui_text(prop, ui_name, ui_description);
2005 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2011 PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2012 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2014 ContainerRNA *cont= cont_;
2017 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_MATRIX);
2018 if(len != 0) RNA_def_property_array(prop, len);
2019 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2020 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2021 RNA_def_property_ui_text(prop, ui_name, ui_description);
2022 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2027 PropertyRNA *RNA_def_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2028 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2030 ContainerRNA *cont= cont_;
2033 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_ROTATION);
2034 if(len != 0) RNA_def_property_array(prop, len);
2035 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2036 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2037 RNA_def_property_ui_text(prop, ui_name, ui_description);
2038 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2043 PropertyRNA *RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2044 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2046 ContainerRNA *cont= cont_;
2049 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
2050 if(len != 0) RNA_def_property_array(prop, len);
2051 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2052 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2053 RNA_def_property_ui_text(prop, ui_name, ui_description);
2054 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2059 PropertyRNA *RNA_def_float_percentage(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
2060 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2062 ContainerRNA *cont= cont_;
2065 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_PERCENTAGE);
2066 RNA_def_property_float_default(prop, default_value);
2067 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2068 RNA_def_property_ui_text(prop, ui_name, ui_description);
2069 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2074 PropertyRNA *RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
2075 const char *ui_name, const char *ui_description)
2077 ContainerRNA *cont= cont_;
2080 prop= RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
2081 RNA_def_property_struct_type(prop, type);
2082 RNA_def_property_ui_text(prop, ui_name, ui_description);
2087 PropertyRNA *RNA_def_pointer_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
2088 const char *ui_name, const char *ui_description)
2090 ContainerRNA *cont= cont_;
2093 prop= RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
2094 RNA_def_property_struct_runtime(prop, type);
2095 RNA_def_property_ui_text(prop, ui_name, ui_description);
2100 PropertyRNA *RNA_def_collection(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
2101 const char *ui_name, const char *ui_description)
2103 ContainerRNA *cont= cont_;
2106 prop= RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
2107 RNA_def_property_struct_type(prop, type);
2108 RNA_def_property_ui_text(prop, ui_name, ui_description);
2113 PropertyRNA *RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
2114 const char *ui_name, const char *ui_description)
2116 ContainerRNA *cont= cont_;
2119 prop= RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
2120 RNA_def_property_struct_runtime(prop, type);
2121 RNA_def_property_ui_text(prop, ui_name, ui_description);
2128 static FunctionRNA *rna_def_function(StructRNA *srna, const char *identifier)
2131 StructDefRNA *dsrna;
2132 FunctionDefRNA *dfunc;
2134 if(DefRNA.preprocess) {
2137 if (rna_validate_identifier(identifier, error, 0) == 0) {
2138 fprintf(stderr, "RNA_def_function: function identifier \"%s\" - %s\n", identifier, error);
2143 func= MEM_callocN(sizeof(FunctionRNA), "FunctionRNA");
2144 func->identifier= identifier;
2145 func->description= identifier;
2147 rna_addtail(&srna->functions, func);
2149 if(DefRNA.preprocess) {
2150 dsrna= rna_find_struct_def(srna);
2151 dfunc= MEM_callocN(sizeof(FunctionDefRNA), "FunctionDefRNA");
2152 rna_addtail(&dsrna->functions, dfunc);
2156 func->flag|= FUNC_RUNTIME;
2161 FunctionRNA *RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
2164 FunctionDefRNA *dfunc;
2166 func= rna_def_function(srna, identifier);
2168 if(!DefRNA.preprocess) {
2169 fprintf(stderr, "RNA_def_function: only at preprocess time.\n");
2173 dfunc= rna_find_function_def(func);
2179 FunctionRNA *RNA_def_function_runtime(StructRNA *srna, const char *identifier, CallFunc call)
2183 func= rna_def_function(srna, identifier);
2185 if(DefRNA.preprocess) {
2186 fprintf(stderr, "RNA_def_function_call_runtime: only at runtime.\n");
2196 void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
2199 ret->flag|=PROP_RETURN;
2202 void RNA_def_function_flag(FunctionRNA *func, int flag)
2207 void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
2209 func->description= description;
2212 int rna_parameter_size(PropertyRNA *parm)
2214 PropertyType ptype= parm->type;
2215 int len= parm->arraylength;
2221 return sizeof(int)*len;
2223 return sizeof(float)*len;
2235 return sizeof(float);
2237 return sizeof(char *);
2238 case PROP_POINTER: {
2240 if(parm->flag & PROP_RNAPTR)
2241 return sizeof(PointerRNA);
2243 return sizeof(void *);
2245 if(parm->flag & PROP_RNAPTR)
2246 return sizeof(PointerRNA);
2248 return sizeof(void *);
2251 case PROP_COLLECTION:
2252 /* XXX does not work yet */
2253 return sizeof(ListBase);
2257 return sizeof(void *);