4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
32 #include "MEM_guardedalloc.h"
34 #include "DNA_genfile.h"
35 #include "DNA_sdna_types.h"
37 #include "RNA_define.h"
39 #include "BLI_ghash.h"
40 #include "BLI_string.h"
42 #include "rna_internal.h"
44 /* Global used during defining */
46 BlenderDefRNA DefRNA = {0, {0, 0}, {0, 0}, 0, 0, 0, 0, 1};
48 /* Duplicated code since we can't link in blenkernel or blenlib */
51 #define MIN2(x,y) ((x)<(y)? (x): (y))
52 #define MAX2(x,y) ((x)>(y)? (x): (y))
55 void rna_addtail(ListBase *listbase, void *vlink)
60 link->prev = listbase->last;
62 if (listbase->last) ((Link *)listbase->last)->next = link;
63 if (listbase->first == 0) listbase->first = link;
64 listbase->last = link;
67 static void rna_remlink(ListBase *listbase, void *vlink)
71 if (link->next) link->next->prev = link->prev;
72 if (link->prev) link->prev->next = link->next;
74 if (listbase->last == link) listbase->last = link->prev;
75 if (listbase->first == link) listbase->first = link->next;
78 PropertyDefRNA *rna_findlink(ListBase *listbase, const char *identifier)
82 for(link=listbase->first; link; link=link->next) {
83 PropertyRNA *prop= ((PropertyDefRNA *)link)->prop;
84 if(prop && (strcmp(prop->identifier, identifier)==0)) {
85 return (PropertyDefRNA *)link;
92 void rna_freelinkN(ListBase *listbase, void *vlink)
94 rna_remlink(listbase, vlink);
98 void rna_freelistN(ListBase *listbase)
102 for(link=listbase->first; link; link=next) {
107 listbase->first= listbase->last= NULL;
110 StructDefRNA *rna_find_struct_def(StructRNA *srna)
114 if(!DefRNA.preprocess) {
115 /* we should never get here */
116 fprintf(stderr, "rna_find_struct_def: only at preprocess time.\n");
120 dsrna= DefRNA.structs.last;
121 for (; dsrna; dsrna= dsrna->cont.prev)
122 if (dsrna->srna==srna)
128 PropertyDefRNA *rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop)
131 PropertyDefRNA *dprop;
133 if(!DefRNA.preprocess) {
134 /* we should never get here */
135 fprintf(stderr, "rna_find_struct_property_def: only at preprocess time.\n");
139 dsrna= rna_find_struct_def(srna);
140 dprop= dsrna->cont.properties.last;
141 for (; dprop; dprop= dprop->prev)
142 if (dprop->prop==prop)
145 dsrna= DefRNA.structs.last;
146 for (; dsrna; dsrna= dsrna->cont.prev) {
147 dprop= dsrna->cont.properties.last;
148 for (; dprop; dprop= dprop->prev)
149 if (dprop->prop==prop)
157 static PropertyDefRNA *rna_find_property_def(PropertyRNA *prop)
159 PropertyDefRNA *dprop;
161 if(!DefRNA.preprocess) {
162 /* we should never get here */
163 fprintf(stderr, "rna_find_property_def: only at preprocess time.\n");
167 dprop= rna_find_struct_property_def(DefRNA.laststruct, prop);
171 dprop= rna_find_parameter_def(prop);
179 FunctionDefRNA *rna_find_function_def(FunctionRNA *func)
182 FunctionDefRNA *dfunc;
184 if(!DefRNA.preprocess) {
185 /* we should never get here */
186 fprintf(stderr, "rna_find_function_def: only at preprocess time.\n");
190 dsrna= rna_find_struct_def(DefRNA.laststruct);
191 dfunc= dsrna->functions.last;
192 for (; dfunc; dfunc= dfunc->cont.prev)
193 if (dfunc->func==func)
196 dsrna= DefRNA.structs.last;
197 for (; dsrna; dsrna= dsrna->cont.prev) {
198 dfunc= dsrna->functions.last;
199 for (; dfunc; dfunc= dfunc->cont.prev)
200 if (dfunc->func==func)
207 PropertyDefRNA *rna_find_parameter_def(PropertyRNA *parm)
210 FunctionDefRNA *dfunc;
211 PropertyDefRNA *dparm;
213 if(!DefRNA.preprocess) {
214 /* we should never get here */
215 fprintf(stderr, "rna_find_parameter_def: only at preprocess time.\n");
219 dsrna= rna_find_struct_def(DefRNA.laststruct);
220 dfunc= dsrna->functions.last;
221 for (; dfunc; dfunc= dfunc->cont.prev) {
222 dparm= dfunc->cont.properties.last;
223 for (; dparm; dparm= dparm->prev)
224 if (dparm->prop==parm)
228 dsrna= DefRNA.structs.last;
229 for (; dsrna; dsrna= dsrna->cont.prev) {
230 dfunc= dsrna->functions.last;
231 for (; dfunc; dfunc= dfunc->cont.prev) {
232 dparm= dfunc->cont.properties.last;
233 for (; dparm; dparm= dparm->prev)
234 if (dparm->prop==parm)
242 static ContainerDefRNA *rna_find_container_def(ContainerRNA *cont)
245 FunctionDefRNA *dfunc;
247 if(!DefRNA.preprocess) {
248 /* we should never get here */
249 fprintf(stderr, "rna_find_container_def: only at preprocess time.\n");
253 ds= rna_find_struct_def((StructRNA*)cont);
257 dfunc= rna_find_function_def((FunctionRNA*)cont);
264 /* DNA utility function for looking up members */
266 typedef struct DNAStructMember {
273 static int rna_member_cmp(const char *name, const char *oname)
277 /* compare without pointer or array part */
284 if(name[a]=='[' && oname[a]==0) return 1;
285 if(name[a]=='[' && oname[a]=='[') return 1;
286 if(name[a]==0) break;
287 if(name[a] != oname[a]) return 0;
290 if(name[a]==0 && oname[a] == '.') return 2;
291 if(name[a]==0 && oname[a] == '-' && oname[a+1] == '>') return 3;
293 return (name[a] == oname[a]);
296 static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *membername, DNAStructMember *smember)
300 int a, b, structnr, totmember, cmp;
302 structnr= DNA_struct_find_nr(sdna, structname);
306 sp= sdna->structs[structnr];
310 for(a=0; a<totmember; a++, sp+=2) {
311 dnaname= sdna->names[sp[1]];
313 cmp= rna_member_cmp(dnaname, membername);
316 smember->type= sdna->types[sp[0]];
317 smember->name= dnaname;
319 if(strstr(membername, "["))
320 smember->arraylength= 0;
322 smember->arraylength= DNA_elem_array_size(smember->name, strlen(smember->name));
324 smember->pointerlevel= 0;
325 for(b=0; dnaname[b] == '*'; b++)
326 smember->pointerlevel++;
332 smember->name= dnaname;
333 smember->pointerlevel= 0;
334 smember->arraylength= 0;
336 membername= strstr(membername, ".") + strlen(".");
337 rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
343 smember->name= dnaname;
344 smember->pointerlevel= 0;
345 smember->arraylength= 0;
347 membername= strstr(membername, "->") + strlen("->");
348 rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
357 static int rna_validate_identifier(const char *identifier, char *error, int property)
361 /* list from http://docs.python.org/reference/lexical_analysis.html#id5 */
362 static char *kwlist[] = {
363 "and", "as", "assert", "break",
364 "class", "continue", "def", "del",
365 "elif", "else", "except", "exec",
366 "finally", "for", "from", "global",
367 "if", "import", "in", "is",
368 "lambda", "not", "or", "pass",
369 "print", "raise", "return", "try",
370 "while", "with", "yield", NULL
374 if (!isalpha(identifier[0])) {
375 strcpy(error, "first character failed isalpha() check");
379 for(a=0; identifier[a]; a++) {
380 if(DefRNA.preprocess && property) {
381 if(isalpha(identifier[a]) && isupper(identifier[a])) {
382 strcpy(error, "property names must contain lower case characters only");
387 if (identifier[a]=='_') {
391 if (identifier[a]==' ') {
392 strcpy(error, "spaces are not ok in identifier names");
396 if (isalnum(identifier[a])==0) {
397 strcpy(error, "one of the characters failed an isalnum() check and is not an underscore");
402 for(a=0; kwlist[a]; a++) {
403 if (strcmp(identifier, kwlist[a]) == 0) {
404 strcpy(error, "this keyword is reserved by python");
412 /* Blender Data Definition */
414 BlenderRNA *RNA_create()
418 brna= MEM_callocN(sizeof(BlenderRNA), "BlenderRNA");
420 DefRNA.sdna= DNA_sdna_from_data(DNAstr, DNAlen, 0);
421 DefRNA.structs.first= DefRNA.structs.last= NULL;
423 DefRNA.preprocess= 1;
428 void RNA_define_free(BlenderRNA *brna)
431 FunctionDefRNA *dfunc;
434 for(alloc=DefRNA.allocs.first; alloc; alloc=alloc->next)
435 MEM_freeN(alloc->mem);
436 rna_freelistN(&DefRNA.allocs);
438 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
439 for (dfunc= ds->functions.first; dfunc; dfunc= dfunc->cont.next)
440 rna_freelistN(&dfunc->cont.properties);
442 rna_freelistN(&ds->cont.properties);
443 rna_freelistN(&ds->functions);
446 rna_freelistN(&DefRNA.structs);
449 DNA_sdna_free(DefRNA.sdna);
456 void RNA_define_verify_sdna(int verify)
458 DefRNA.verify= verify;
461 void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *ext)
464 ext->free(ext->data); /* decref's the PyObject that the srna owns */
465 RNA_struct_blender_type_set(srna, NULL); /* this gets accessed again - XXX fixme */
466 RNA_struct_py_type_set(srna, NULL); /* NULL the srna's value so RNA_struct_free wont complain of a leak */
470 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
473 FunctionRNA *func, *nextfunc;
474 PropertyRNA *prop, *nextprop;
475 PropertyRNA *parm, *nextparm;
477 if(srna->flag & STRUCT_RUNTIME) {
478 if(RNA_struct_py_type_get(srna)) {
479 fprintf(stderr, "RNA_struct_free '%s' freed while holding a python reference\n", srna->identifier);
483 for(prop=srna->cont.properties.first; prop; prop=nextprop) {
484 nextprop= prop->next;
486 RNA_def_property_free_pointers(prop);
488 if(prop->flag & PROP_RUNTIME)
489 rna_freelinkN(&srna->cont.properties, prop);
492 for(func=srna->functions.first; func; func=nextfunc) {
493 nextfunc= func->cont.next;
495 for(parm=func->cont.properties.first; parm; parm=nextparm) {
496 nextparm= parm->next;
498 RNA_def_property_free_pointers(parm);
500 if(parm->flag & PROP_RUNTIME)
501 rna_freelinkN(&func->cont.properties, parm);
504 RNA_def_func_free_pointers(func);
506 if(func->flag & FUNC_RUNTIME)
507 rna_freelinkN(&srna->functions, func);
510 RNA_def_struct_free_pointers(srna);
512 if(srna->flag & STRUCT_RUNTIME)
513 rna_freelinkN(&brna->structs, srna);
518 void RNA_free(BlenderRNA *brna)
520 StructRNA *srna, *nextsrna;
523 if(DefRNA.preprocess) {
524 RNA_define_free(brna);
526 for(srna=brna->structs.first; srna; srna=srna->cont.next) {
527 for (func= srna->functions.first; func; func= func->cont.next)
528 rna_freelistN(&func->cont.properties);
530 rna_freelistN(&srna->cont.properties);
531 rna_freelistN(&srna->functions);
534 rna_freelistN(&brna->structs);
539 for(srna=brna->structs.first; srna; srna=nextsrna) {
540 nextsrna= srna->cont.next;
541 RNA_struct_free(brna, srna);
546 static size_t rna_property_type_sizeof(PropertyType type)
549 case PROP_BOOLEAN: return sizeof(BooleanPropertyRNA);
550 case PROP_INT: return sizeof(IntPropertyRNA);
551 case PROP_FLOAT: return sizeof(FloatPropertyRNA);
552 case PROP_STRING: return sizeof(StringPropertyRNA);
553 case PROP_ENUM: return sizeof(EnumPropertyRNA);
554 case PROP_POINTER: return sizeof(PointerPropertyRNA);
555 case PROP_COLLECTION: return sizeof(CollectionPropertyRNA);
560 static StructDefRNA *rna_find_def_struct(StructRNA *srna)
564 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
571 /* Struct Definition */
573 StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
575 StructRNA *srna, *srnafrom= NULL;
576 StructDefRNA *ds= NULL, *dsfrom= NULL;
579 if(DefRNA.preprocess) {
582 if (rna_validate_identifier(identifier, error, 0) == 0) {
583 fprintf(stderr, "RNA_def_struct: struct identifier \"%s\" error - %s\n", identifier, error);
589 /* find struct to derive from */
590 for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->cont.next)
591 if(strcmp(srnafrom->identifier, from) == 0)
595 fprintf(stderr, "RNA_def_struct: struct %s not found to define %s.\n", from, identifier);
600 srna= MEM_callocN(sizeof(StructRNA), "StructRNA");
601 DefRNA.laststruct= srna;
604 /* copy from struct to derive stuff, a bit clumsy since we can't
605 * use MEM_dupallocN, data structs may not be alloced but builtin */
606 memcpy(srna, srnafrom, sizeof(StructRNA));
607 srna->cont.prophash= NULL;
608 srna->cont.properties.first= srna->cont.properties.last= NULL;
609 srna->functions.first= srna->functions.last= NULL;
612 if(DefRNA.preprocess) {
613 srna->base= srnafrom;
614 dsfrom= rna_find_def_struct(srnafrom);
617 srna->base= srnafrom;
620 srna->identifier= identifier;
621 srna->name= identifier; /* may be overwritten later RNA_def_struct_ui_text */
622 srna->description= "";
624 srna->icon= ICON_DOT;
626 rna_addtail(&brna->structs, srna);
628 if(DefRNA.preprocess) {
629 ds= MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
631 rna_addtail(&DefRNA.structs, ds);
634 ds->dnafromname= dsfrom->dnaname;
637 /* in preprocess, try to find sdna */
638 if(DefRNA.preprocess)
639 RNA_def_struct_sdna(srna, srna->identifier);
641 srna->flag |= STRUCT_RUNTIME;
644 srna->nameproperty= srnafrom->nameproperty;
645 srna->iteratorproperty= srnafrom->iteratorproperty;
648 /* define some builtin properties */
649 prop= RNA_def_property(&srna->cont, "rna_properties", PROP_COLLECTION, PROP_NONE);
650 RNA_def_property_flag(prop, PROP_BUILTIN);
651 RNA_def_property_ui_text(prop, "Properties", "RNA property collection");
653 if(DefRNA.preprocess) {
654 RNA_def_property_struct_type(prop, "Property");
655 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");
659 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
660 cprop->begin= rna_builtin_properties_begin;
661 cprop->next= rna_builtin_properties_next;
662 cprop->get= rna_builtin_properties_get;
663 cprop->item_type= &RNA_Property;
667 prop= RNA_def_property(&srna->cont, "rna_type", PROP_POINTER, PROP_NONE);
668 RNA_def_property_flag(prop, PROP_HIDDEN);
669 RNA_def_property_ui_text(prop, "RNA", "RNA type definition");
671 if(DefRNA.preprocess) {
672 RNA_def_property_struct_type(prop, "Struct");
673 RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL, NULL);
677 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
678 pprop->get= rna_builtin_type_get;
679 pprop->type= &RNA_Struct;
687 void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
691 if(!DefRNA.preprocess) {
692 fprintf(stderr, "RNA_def_struct_sdna: only during preprocessing.\n");
696 ds= rna_find_def_struct(srna);
698 if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
700 fprintf(stderr, "RNA_def_struct_sdna: %s not found.\n", structname);
706 ds->dnaname= structname;
709 void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
713 if(!DefRNA.preprocess) {
714 fprintf(stderr, "RNA_def_struct_sdna_from: only during preprocessing.\n");
718 ds= rna_find_def_struct(srna);
721 fprintf(stderr, "RNA_def_struct_sdna_from: %s base struct must know DNA already.\n", structname);
725 if(!DNA_struct_find_nr(DefRNA.sdna, structname)) {
727 fprintf(stderr, "RNA_def_struct_sdna_from: %s not found.\n", structname);
733 ds->dnafromprop= propname;
734 ds->dnaname= structname;
737 void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
739 if(prop->type != PROP_STRING) {
740 fprintf(stderr, "RNA_def_struct_name_property: \"%s.%s\", must be a string property.\n", srna->identifier, prop->identifier);
744 srna->nameproperty= prop;
747 void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
751 /* find struct to derive from */
752 for(srnafrom= brna->structs.first; srnafrom; srnafrom=srnafrom->cont.next)
753 if(strcmp(srnafrom->identifier, structname) == 0)
757 fprintf(stderr, "RNA_def_struct_nested: struct %s not found for %s.\n", structname, srna->identifier);
761 srna->nested= srnafrom;
764 void RNA_def_struct_flag(StructRNA *srna, int flag)
769 void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
774 void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
776 if(!DefRNA.preprocess) {
777 fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
781 if(refine) srna->refine= (StructRefineFunc)refine;
784 void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
786 if(!DefRNA.preprocess) {
787 fprintf(stderr, "RNA_def_struct_idprops_func: only during preprocessing.\n");
791 if(idproperties) srna->idproperties= (IDPropertiesFunc)idproperties;
794 void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg)
796 if(!DefRNA.preprocess) {
797 fprintf(stderr, "RNA_def_struct_register_funcs: only during preprocessing.\n");
801 if(reg) srna->reg= (StructRegisterFunc)reg;
802 if(unreg) srna->unreg= (StructUnregisterFunc)unreg;
805 void RNA_def_struct_path_func(StructRNA *srna, const char *path)
807 if(!DefRNA.preprocess) {
808 fprintf(stderr, "RNA_def_struct_path_func: only during preprocessing.\n");
812 if(path) srna->path= (StructPathFunc)path;
815 void RNA_def_struct_identifier(StructRNA *srna, const char *identifier)
817 if(DefRNA.preprocess) {
818 fprintf(stderr, "RNA_def_struct_name_runtime: only at runtime.\n");
822 srna->identifier= identifier;
825 void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
828 srna->description= description;
831 void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
836 /* Property Definition */
838 PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
840 StructRNA *srna= DefRNA.laststruct;
841 ContainerRNA *cont= cont_;
842 ContainerDefRNA *dcont;
843 PropertyDefRNA *dprop= NULL;
846 if(DefRNA.preprocess) {
849 if (rna_validate_identifier(identifier, error, 1) == 0) {
850 fprintf(stderr, "RNA_def_property: property identifier \"%s.%s\" - %s\n", srna->identifier, identifier, error);
854 dcont= rna_find_container_def(cont);
856 /* XXX - toto, detect supertype collisions */
857 if(rna_findlink(&dcont->properties, identifier)) {
858 fprintf(stderr, "RNA_def_property: duplicate identifier \"%s.%s\"\n", srna->identifier, identifier);
862 dprop= MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA");
863 rna_addtail(&dcont->properties, dprop);
866 prop= MEM_callocN(rna_property_type_sizeof(type), "PropertyRNA");
872 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
874 iprop->hardmin= (subtype == PROP_UNSIGNED)? 0: INT_MIN;
875 iprop->hardmax= INT_MAX;
877 iprop->softmin= (subtype == PROP_UNSIGNED)? 0: -10000; /* rather arbitrary .. */
878 iprop->softmax= 10000;
883 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
885 fprop->hardmin= (subtype == PROP_UNSIGNED)? 0.0f: -FLT_MAX;
886 fprop->hardmax= FLT_MAX;
888 if(ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
889 fprop->softmin= 0.0f;
890 fprop->softmax= 1.0f;
892 else if(subtype == PROP_FACTOR) {
893 fprop->softmin= fprop->hardmin= 0.0f;
894 fprop->softmax= fprop->hardmax= 1.0f;
897 fprop->softmin= (subtype == PROP_UNSIGNED)? 0.0f: -10000.0f; /* rather arbitrary .. */
898 fprop->softmax= 10000.0f;
905 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
907 sprop->defaultvalue= "";
913 case PROP_COLLECTION:
916 fprintf(stderr, "RNA_def_property: \"%s.%s\", invalid property type.\n", srna->identifier, identifier);
921 if(DefRNA.preprocess) {
926 prop->magic= RNA_MAGIC;
927 prop->identifier= identifier;
929 prop->subtype= subtype;
930 prop->name= identifier;
931 prop->description= "";
932 /* a priori not raw editable */
935 if(type != PROP_COLLECTION && type != PROP_POINTER) {
936 prop->flag= PROP_EDITABLE;
938 if(type != PROP_STRING)
939 prop->flag |= PROP_ANIMATABLE;
942 if(DefRNA.preprocess) {
946 RNA_def_property_boolean_sdna(prop, NULL, identifier, 0);
951 RNA_def_property_int_sdna(prop, NULL, identifier);
957 RNA_def_property_float_sdna(prop, NULL, identifier);
963 RNA_def_property_string_sdna(prop, NULL, identifier);
969 RNA_def_property_enum_sdna(prop, NULL, identifier);
974 RNA_def_property_pointer_sdna(prop, NULL, identifier);
977 case PROP_COLLECTION:
979 RNA_def_property_collection_sdna(prop, NULL, identifier, NULL);
985 prop->flag |= PROP_IDPROPERTY|PROP_RUNTIME;
988 BLI_ghash_insert(cont->prophash, (void*)prop->identifier, prop);
992 rna_addtail(&cont->properties, prop);
997 void RNA_def_property_flag(PropertyRNA *prop, int flag)
1002 void RNA_def_property_clear_flag(PropertyRNA *prop, int flag)
1004 prop->flag &= ~flag;
1007 void RNA_def_property_array(PropertyRNA *prop, int length)
1009 StructRNA *srna= DefRNA.laststruct;
1012 fprintf(stderr, "RNA_def_property_array: \"%s.%s\", array length must be zero of greater.\n", srna->identifier, prop->identifier);
1017 if(length>RNA_MAX_ARRAY_LENGTH) {
1018 fprintf(stderr, "RNA_def_property_array: \"%s.%s\", array length must be smaller than %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY_LENGTH);
1023 switch(prop->type) {
1027 prop->arraylength[0]= length;
1028 prop->totarraylength= length;
1029 prop->arraydimension= 1;
1032 fprintf(stderr, "RNA_def_property_array: \"%s.%s\", only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
1038 void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, int length[])
1040 StructRNA *srna= DefRNA.laststruct;
1043 if (dimension < 1 || dimension > RNA_MAX_ARRAY_DIMENSION) {
1044 fprintf(stderr, "RNA_def_property_multi_array: \"%s.%s\", array dimension must be between 1 and %d.\n", srna->identifier, prop->identifier, RNA_MAX_ARRAY_DIMENSION);
1049 switch(prop->type) {
1055 fprintf(stderr, "RNA_def_property_multi_array: \"%s.%s\", only boolean/int/float can be array.\n", srna->identifier, prop->identifier);
1060 prop->arraydimension= dimension;
1061 prop->totarraylength= 0;
1064 memcpy(prop->arraylength, length, sizeof(int)*dimension);
1066 prop->totarraylength= length[0];
1067 for(i=1; i<dimension; i++)
1068 prop->totarraylength *= length[i];
1071 memset(prop->arraylength, 0, sizeof(prop->arraylength));
1073 /* TODO make sure arraylength values are sane */
1076 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
1079 prop->description= description;
1082 void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
1086 prop->flag |= PROP_ICONS_CONSECUTIVE;
1089 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
1091 StructRNA *srna= DefRNA.laststruct;
1093 switch(prop->type) {
1095 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1096 iprop->softmin= (int)min;
1097 iprop->softmax= (int)max;
1098 iprop->step= (int)step;
1102 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1103 fprop->softmin= (float)min;
1104 fprop->softmax= (float)max;
1105 fprop->step= (float)step;
1106 fprop->precision= (int)precision;
1110 fprintf(stderr, "RNA_def_property_ui_range: \"%s.%s\", invalid type for ui range.\n", srna->identifier, prop->identifier);
1116 void RNA_def_property_range(PropertyRNA *prop, double min, double max)
1118 StructRNA *srna= DefRNA.laststruct;
1120 switch(prop->type) {
1122 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1123 iprop->hardmin= (int)min;
1124 iprop->hardmax= (int)max;
1125 iprop->softmin= MAX2((int)min, iprop->hardmin);
1126 iprop->softmax= MIN2((int)max, iprop->hardmax);
1130 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1131 fprop->hardmin= (float)min;
1132 fprop->hardmax= (float)max;
1133 fprop->softmin= MAX2((float)min, fprop->hardmin);
1134 fprop->softmax= MIN2((float)max, fprop->hardmax);
1138 fprintf(stderr, "RNA_def_property_range: \"%s.%s\", invalid type for range.\n", srna->identifier, prop->identifier);
1144 void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
1146 StructRNA *srna= DefRNA.laststruct;
1148 if(!DefRNA.preprocess) {
1149 fprintf(stderr, "RNA_def_property_struct_type \"%s.%s\": only during preprocessing.\n", srna->identifier, prop->identifier);
1153 switch(prop->type) {
1154 case PROP_POINTER: {
1155 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1156 pprop->type = (StructRNA*)type;
1159 case PROP_COLLECTION: {
1160 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1161 cprop->item_type = (StructRNA*)type;
1165 fprintf(stderr, "RNA_def_property_struct_type: \"%s.%s\", invalid type for struct type.\n", srna->identifier, prop->identifier);
1171 void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type)
1173 StructRNA *srna= DefRNA.laststruct;
1175 if(DefRNA.preprocess) {
1176 fprintf(stderr, "RNA_def_property_struct_runtime: only at runtime.\n");
1180 switch(prop->type) {
1181 case PROP_POINTER: {
1182 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1185 if(type && (type->flag & STRUCT_ID_REFCOUNT))
1186 prop->flag |= PROP_ID_REFCOUNT;
1190 case PROP_COLLECTION: {
1191 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1192 cprop->item_type = type;
1196 fprintf(stderr, "RNA_def_property_struct_runtime: \"%s.%s\", invalid type for struct type.\n", srna->identifier, prop->identifier);
1202 void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
1204 StructRNA *srna= DefRNA.laststruct;
1205 int i, defaultfound= 0;
1207 switch(prop->type) {
1209 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1210 eprop->item= (EnumPropertyItem*)item;
1212 for(i=0; item[i].identifier; i++) {
1215 if(item[i].identifier[0] && item[i].value == eprop->defaultvalue)
1220 for(i=0; item[i].identifier; i++) {
1221 if(item[i].identifier[0]) {
1222 eprop->defaultvalue= item[i].value;
1231 fprintf(stderr, "RNA_def_property_enum_items: \"%s.%s\", invalid type for struct type.\n", srna->identifier, prop->identifier);
1237 void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
1239 StructRNA *srna= DefRNA.laststruct;
1241 switch(prop->type) {
1243 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1244 sprop->maxlength= maxlength;
1248 fprintf(stderr, "RNA_def_property_string_maxlength: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
1254 void RNA_def_property_boolean_default(PropertyRNA *prop, int value)
1256 StructRNA *srna= DefRNA.laststruct;
1258 switch(prop->type) {
1259 case PROP_BOOLEAN: {
1260 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1261 bprop->defaultvalue= value;
1265 fprintf(stderr, "RNA_def_property_boolean_default: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
1271 void RNA_def_property_boolean_array_default(PropertyRNA *prop, const int *array)
1273 StructRNA *srna= DefRNA.laststruct;
1275 switch(prop->type) {
1276 case PROP_BOOLEAN: {
1277 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1278 bprop->defaultarray= array;
1282 fprintf(stderr, "RNA_def_property_boolean_default: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
1288 void RNA_def_property_int_default(PropertyRNA *prop, int value)
1290 StructRNA *srna= DefRNA.laststruct;
1292 switch(prop->type) {
1294 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1295 iprop->defaultvalue= value;
1299 fprintf(stderr, "RNA_def_property_int_default: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
1305 void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
1307 StructRNA *srna= DefRNA.laststruct;
1309 switch(prop->type) {
1311 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1312 iprop->defaultarray= array;
1316 fprintf(stderr, "RNA_def_property_int_default: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
1322 void RNA_def_property_float_default(PropertyRNA *prop, float value)
1324 StructRNA *srna= DefRNA.laststruct;
1326 switch(prop->type) {
1328 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1329 fprop->defaultvalue= value;
1333 fprintf(stderr, "RNA_def_property_float_default: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
1338 /* array must remain valid after this function finishes */
1339 void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
1341 StructRNA *srna= DefRNA.laststruct;
1343 switch(prop->type) {
1345 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1346 fprop->defaultarray= array; /* WARNING, this array must not come from the stack and lost */
1350 fprintf(stderr, "RNA_def_property_float_default: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
1356 void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
1358 StructRNA *srna= DefRNA.laststruct;
1360 switch(prop->type) {
1362 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1363 sprop->defaultvalue= value;
1367 fprintf(stderr, "RNA_def_property_string_default: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
1373 void RNA_def_property_enum_default(PropertyRNA *prop, int value)
1375 StructRNA *srna= DefRNA.laststruct;
1376 int i, defaultfound= 0;
1378 switch(prop->type) {
1380 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1381 eprop->defaultvalue= value;
1383 for(i=0; i<eprop->totitem; i++) {
1384 if(eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue)
1388 if(!defaultfound && eprop->totitem) {
1390 eprop->defaultvalue= eprop->item[0].value;
1393 fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", default is not in items.\n", srna->identifier, prop->identifier);
1401 fprintf(stderr, "RNA_def_property_enum_default: \"%s.%s\", type is not enum.\n", srna->identifier, prop->identifier);
1409 static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1411 DNAStructMember smember;
1415 dp= rna_find_struct_property_def(DefRNA.laststruct, prop);
1416 if (dp==NULL) return NULL;
1418 ds= rna_find_struct_def((StructRNA*)dp->cont);
1421 structname= ds->dnaname;
1423 propname= prop->identifier;
1425 if(!rna_find_sdna_member(DefRNA.sdna, structname, propname, &smember)) {
1429 else if(!DefRNA.verify) {
1430 /* some basic values to survive even with sdna info */
1431 dp->dnastructname= structname;
1432 dp->dnaname= propname;
1433 if(prop->type == PROP_BOOLEAN)
1434 dp->dnaarraylength= 1;
1435 if(prop->type == PROP_POINTER)
1436 dp->dnapointerlevel= 1;
1440 fprintf(stderr, "rna_def_property_sdna: \"%s.%s\" not found.\n", structname, propname);
1446 if(smember.arraylength > 1) {
1447 prop->arraylength[0]= smember.arraylength;
1448 prop->totarraylength= smember.arraylength;
1449 prop->arraydimension= 1;
1452 prop->arraydimension= 0;
1453 prop->totarraylength= 0;
1456 dp->dnastructname= structname;
1457 dp->dnastructfromname= ds->dnafromname;
1458 dp->dnastructfromprop= ds->dnafromprop;
1459 dp->dnaname= propname;
1460 dp->dnatype= smember.type;
1461 dp->dnaarraylength= smember.arraylength;
1462 dp->dnapointerlevel= smember.pointerlevel;
1467 void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int bit)
1470 StructRNA *srna= DefRNA.laststruct;
1472 if(!DefRNA.preprocess) {
1473 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1477 if(prop->type != PROP_BOOLEAN) {
1478 fprintf(stderr, "RNA_def_property_boolean_sdna: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
1483 if((dp=rna_def_property_sdna(prop, structname, propname)))
1484 dp->booleanbit= bit;
1487 void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int booleanbit)
1491 RNA_def_property_boolean_sdna(prop, structname, propname, booleanbit);
1493 dp= rna_find_struct_property_def(DefRNA.laststruct, prop);
1496 dp->booleannegative= 1;
1499 void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1502 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1503 StructRNA *srna= DefRNA.laststruct;
1505 if(!DefRNA.preprocess) {
1506 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1510 if(prop->type != PROP_INT) {
1511 fprintf(stderr, "RNA_def_property_int_sdna: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
1516 if((dp= rna_def_property_sdna(prop, structname, propname))) {
1517 /* SDNA doesn't pass us unsigned unfortunately .. */
1518 if(dp->dnatype && strcmp(dp->dnatype, "char") == 0) {
1519 iprop->hardmin= iprop->softmin= CHAR_MIN;
1520 iprop->hardmax= iprop->softmax= CHAR_MAX;
1522 else if(dp->dnatype && strcmp(dp->dnatype, "short") == 0) {
1523 iprop->hardmin= iprop->softmin= SHRT_MIN;
1524 iprop->hardmax= iprop->softmax= SHRT_MAX;
1526 else if(dp->dnatype && strcmp(dp->dnatype, "int") == 0) {
1527 iprop->hardmin= INT_MIN;
1528 iprop->hardmax= INT_MAX;
1530 iprop->softmin= -10000; /* rather arbitrary .. */
1531 iprop->softmax= 10000;
1534 if(prop->subtype == PROP_UNSIGNED || prop->subtype == PROP_PERCENTAGE || prop->subtype == PROP_FACTOR)
1535 iprop->hardmin= iprop->softmin= 0;
1539 void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1541 StructRNA *srna= DefRNA.laststruct;
1543 if(!DefRNA.preprocess) {
1544 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1548 if(prop->type != PROP_FLOAT) {
1549 fprintf(stderr, "RNA_def_property_float_sdna: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
1554 rna_def_property_sdna(prop, structname, propname);
1557 void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1560 StructRNA *srna= DefRNA.laststruct;
1562 if(!DefRNA.preprocess) {
1563 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1567 if(prop->type != PROP_ENUM) {
1568 fprintf(stderr, "RNA_def_property_enum_sdna: \"%s.%s\", type is not enum.\n", srna->identifier, prop->identifier);
1573 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1574 if(prop->arraydimension) {
1575 prop->arraydimension= 0;
1576 prop->totarraylength= 0;
1578 if(!DefRNA.silent) {
1579 fprintf(stderr, "RNA_def_property_enum_sdna: \"%s.%s\", array not supported for enum type.\n", structname, propname);
1586 void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1590 RNA_def_property_enum_sdna(prop, structname, propname);
1592 dp= rna_find_struct_property_def(DefRNA.laststruct, prop);
1595 dp->enumbitflags= 1;
1598 void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1601 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1602 StructRNA *srna= DefRNA.laststruct;
1604 if(!DefRNA.preprocess) {
1605 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1609 if(prop->type != PROP_STRING) {
1610 fprintf(stderr, "RNA_def_property_string_sdna: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
1615 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1616 if(prop->arraydimension) {
1617 sprop->maxlength= prop->totarraylength;
1618 prop->arraydimension= 0;
1619 prop->totarraylength= 0;
1624 void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1627 StructRNA *srna= DefRNA.laststruct;
1629 if(!DefRNA.preprocess) {
1630 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1634 if(prop->type != PROP_POINTER) {
1635 fprintf(stderr, "RNA_def_property_pointer_sdna: \"%s.%s\", type is not pointer.\n", srna->identifier, prop->identifier);
1640 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1641 if(prop->arraydimension) {
1642 prop->arraydimension= 0;
1643 prop->totarraylength= 0;
1645 if(!DefRNA.silent) {
1646 fprintf(stderr, "RNA_def_property_pointer_sdna: \"%s.%s\", array not supported for pointer type.\n", structname, propname);
1653 void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
1656 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1657 StructRNA *srna= DefRNA.laststruct;
1659 if(!DefRNA.preprocess) {
1660 fprintf(stderr, "RNA_def_property_*_sdna: only during preprocessing.\n");
1664 if(prop->type != PROP_COLLECTION) {
1665 fprintf(stderr, "RNA_def_property_collection_sdna: \"%s.%s\", type is not collection.\n", srna->identifier, prop->identifier);
1670 if((dp=rna_def_property_sdna(prop, structname, propname))) {
1671 if(prop->arraydimension && !lengthpropname) {
1672 prop->arraydimension= 0;
1673 prop->totarraylength= 0;
1675 if(!DefRNA.silent) {
1676 fprintf(stderr, "RNA_def_property_collection_sdna: \"%s.%s\", array of collections not supported.\n", structname, propname);
1681 if(dp->dnatype && strcmp(dp->dnatype, "ListBase") == 0) {
1682 cprop->next= (PropCollectionNextFunc)"rna_iterator_listbase_next";
1683 cprop->get= (PropCollectionGetFunc)"rna_iterator_listbase_get";
1684 cprop->end= (PropCollectionEndFunc)"rna_iterator_listbase_end";
1688 if(dp && lengthpropname) {
1689 DNAStructMember smember;
1690 StructDefRNA *ds= rna_find_struct_def((StructRNA*)dp->cont);
1693 structname= ds->dnaname;
1695 if(lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
1696 if(lengthpropname[0] == 0) {
1697 dp->dnalengthfixed= prop->totarraylength;
1698 prop->arraydimension= 0;
1699 prop->totarraylength= 0;
1702 dp->dnalengthstructname= structname;
1703 dp->dnalengthname= lengthpropname;
1704 prop->totarraylength= 0;
1707 cprop->next= (PropCollectionNextFunc)"rna_iterator_array_next";
1708 cprop->end= (PropCollectionEndFunc)"rna_iterator_array_end";
1710 if(dp->dnapointerlevel >= 2)
1711 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_dereference_get";
1713 cprop->get= (PropCollectionGetFunc)"rna_iterator_array_get";
1716 if(!DefRNA.silent) {
1717 fprintf(stderr, "RNA_def_property_collection_sdna: \"%s.%s\" not found.\n", structname, lengthpropname);
1726 void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
1728 if(!DefRNA.preprocess) {
1729 fprintf(stderr, "RNA_def_property_editable_func: only during preprocessing.\n");
1733 if(editable) prop->editable= (EditableFunc)editable;
1736 void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable)
1738 if(!DefRNA.preprocess) {
1739 fprintf(stderr, "RNA_def_property_editable_array_func: only during preprocessing.\n");
1743 if(editable) prop->itemeditable= (ItemEditableFunc)editable;
1746 void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
1748 if(!DefRNA.preprocess) {
1749 fprintf(stderr, "RNA_def_struct_refine_func: only during preprocessing.\n");
1753 prop->noteflag= noteflag;
1754 prop->update= (UpdateFunc)func;
1757 void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
1759 if(!DefRNA.preprocess) {
1760 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1764 if (!(prop->flag & PROP_DYNAMIC)) {
1765 fprintf(stderr, "RNA_def_property_dynamic_array_funcs: property is a not dynamic array.\n");
1770 if(getlength) prop->getlength= (PropArrayLengthGetFunc)getlength;
1773 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
1775 StructRNA *srna= DefRNA.laststruct;
1777 if(!DefRNA.preprocess) {
1778 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1782 switch(prop->type) {
1783 case PROP_BOOLEAN: {
1784 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1786 if(prop->arraydimension) {
1787 if(get) bprop->getarray= (PropBooleanArrayGetFunc)get;
1788 if(set) bprop->setarray= (PropBooleanArraySetFunc)set;
1791 if(get) bprop->get= (PropBooleanGetFunc)get;
1792 if(set) bprop->set= (PropBooleanSetFunc)set;
1797 fprintf(stderr, "RNA_def_property_boolean_funcs: \"%s.%s\", type is not boolean.\n", srna->identifier, prop->identifier);
1803 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1805 StructRNA *srna= DefRNA.laststruct;
1807 if(!DefRNA.preprocess) {
1808 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1812 switch(prop->type) {
1814 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1816 if(prop->arraydimension) {
1817 if(get) iprop->getarray= (PropIntArrayGetFunc)get;
1818 if(set) iprop->setarray= (PropIntArraySetFunc)set;
1821 if(get) iprop->get= (PropIntGetFunc)get;
1822 if(set) iprop->set= (PropIntSetFunc)set;
1824 if(range) iprop->range= (PropIntRangeFunc)range;
1828 fprintf(stderr, "RNA_def_property_int_funcs: \"%s.%s\", type is not int.\n", srna->identifier, prop->identifier);
1834 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
1836 StructRNA *srna= DefRNA.laststruct;
1838 if(!DefRNA.preprocess) {
1839 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1843 switch(prop->type) {
1845 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1847 if(prop->arraydimension) {
1848 if(get) fprop->getarray= (PropFloatArrayGetFunc)get;
1849 if(set) fprop->setarray= (PropFloatArraySetFunc)set;
1852 if(get) fprop->get= (PropFloatGetFunc)get;
1853 if(set) fprop->set= (PropFloatSetFunc)set;
1855 if(range) fprop->range= (PropFloatRangeFunc)range;
1859 fprintf(stderr, "RNA_def_property_float_funcs: \"%s.%s\", type is not float.\n", srna->identifier, prop->identifier);
1865 void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
1867 StructRNA *srna= DefRNA.laststruct;
1869 if(!DefRNA.preprocess) {
1870 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1874 switch(prop->type) {
1876 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1878 if(get) eprop->get= (PropEnumGetFunc)get;
1879 if(set) eprop->set= (PropEnumSetFunc)set;
1880 if(item) eprop->itemf= (PropEnumItemFunc)item;
1884 fprintf(stderr, "RNA_def_property_enum_funcs: \"%s.%s\", type is not enum.\n", srna->identifier, prop->identifier);
1890 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
1892 StructRNA *srna= DefRNA.laststruct;
1894 if(!DefRNA.preprocess) {
1895 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1899 switch(prop->type) {
1901 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1903 if(get) sprop->get= (PropStringGetFunc)get;
1904 if(length) sprop->length= (PropStringLengthFunc)length;
1905 if(set) sprop->set= (PropStringSetFunc)set;
1909 fprintf(stderr, "RNA_def_property_string_funcs: \"%s.%s\", type is not string.\n", srna->identifier, prop->identifier);
1915 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *typef, const char *poll)
1917 StructRNA *srna= DefRNA.laststruct;
1919 if(!DefRNA.preprocess) {
1920 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1924 switch(prop->type) {
1925 case PROP_POINTER: {
1926 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1928 if(get) pprop->get= (PropPointerGetFunc)get;
1929 if(set) pprop->set= (PropPointerSetFunc)set;
1930 if(typef) pprop->typef= (PropPointerTypeFunc)typef;
1931 if(poll) pprop->poll= (PropPointerPollFunc)poll;
1935 fprintf(stderr, "RNA_def_property_pointer_funcs: \"%s.%s\", type is not pointer.\n", srna->identifier, prop->identifier);
1941 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)
1943 StructRNA *srna= DefRNA.laststruct;
1945 if(!DefRNA.preprocess) {
1946 fprintf(stderr, "RNA_def_property_*_funcs: only during preprocessing.\n");
1950 switch(prop->type) {
1951 case PROP_COLLECTION: {
1952 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1954 if(begin) cprop->begin= (PropCollectionBeginFunc)begin;
1955 if(next) cprop->next= (PropCollectionNextFunc)next;
1956 if(end) cprop->end= (PropCollectionEndFunc)end;
1957 if(get) cprop->get= (PropCollectionGetFunc)get;
1958 if(length) cprop->length= (PropCollectionLengthFunc)length;
1959 if(lookupint) cprop->lookupint= (PropCollectionLookupIntFunc)lookupint;
1960 if(lookupstring) cprop->lookupstring= (PropCollectionLookupStringFunc)lookupstring;
1964 fprintf(stderr, "RNA_def_property_collection_funcs: \"%s.%s\", type is not collection.\n", srna->identifier, prop->identifier);
1970 void RNA_def_property_srna(PropertyRNA *prop, const char *type)
1972 prop->srna= (StructRNA*)type;
1975 /* Compact definitions */
1977 PropertyRNA *RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, int default_value, const char *ui_name, const char *ui_description)
1979 ContainerRNA *cont= cont_;
1982 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
1983 RNA_def_property_boolean_default(prop, default_value);
1984 RNA_def_property_ui_text(prop, ui_name, ui_description);
1989 PropertyRNA *RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
1990 const char *ui_name, const char *ui_description)
1992 ContainerRNA *cont= cont_;
1995 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
1996 if(len != 0) RNA_def_property_array(prop, len);
1997 if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
1998 RNA_def_property_ui_text(prop, ui_name, ui_description);
2003 PropertyRNA *RNA_def_boolean_layer(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
2004 const char *ui_name, const char *ui_description)
2006 ContainerRNA *cont= cont_;
2009 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER);
2010 if(len != 0) RNA_def_property_array(prop, len);
2011 if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
2012 RNA_def_property_ui_text(prop, ui_name, ui_description);
2017 PropertyRNA *RNA_def_boolean_layer_member(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
2018 const char *ui_name, const char *ui_description)
2020 ContainerRNA *cont= cont_;
2023 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER_MEMBER);
2024 if(len != 0) RNA_def_property_array(prop, len);
2025 if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
2026 RNA_def_property_ui_text(prop, ui_name, ui_description);
2031 PropertyRNA *RNA_def_boolean_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, int *default_value,
2032 const char *ui_name, const char *ui_description)
2034 ContainerRNA *cont= cont_;
2037 prop= RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_XYZ); // XXX
2038 if(len != 0) RNA_def_property_array(prop, len);
2039 if(default_value) RNA_def_property_boolean_array_default(prop, default_value);
2040 RNA_def_property_ui_text(prop, ui_name, ui_description);
2045 PropertyRNA *RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value, int hardmin, int hardmax,
2046 const char *ui_name, const char *ui_description, int softmin, int softmax)
2048 ContainerRNA *cont= cont_;
2051 prop= RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
2052 RNA_def_property_int_default(prop, default_value);
2053 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2054 RNA_def_property_ui_text(prop, ui_name, ui_description);
2055 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2060 PropertyRNA *RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value,
2061 int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
2063 ContainerRNA *cont= cont_;
2066 prop= RNA_def_property(cont, identifier, PROP_INT, PROP_XYZ); // XXX
2067 if(len != 0) RNA_def_property_array(prop, len);
2068 if(default_value) RNA_def_property_int_array_default(prop, default_value);
2069 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2070 RNA_def_property_ui_text(prop, ui_name, ui_description);
2071 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2076 PropertyRNA *RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value,
2077 int hardmin, int hardmax, const char *ui_name, const char *ui_description, int softmin, int softmax)
2079 ContainerRNA *cont= cont_;
2082 prop= RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
2083 if(len != 0) RNA_def_property_array(prop, len);
2084 if(default_value) RNA_def_property_int_array_default(prop, default_value);
2085 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2086 RNA_def_property_ui_text(prop, ui_name, ui_description);
2087 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2092 PropertyRNA *RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
2093 const char *ui_name, const char *ui_description)
2095 ContainerRNA *cont= cont_;
2098 prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_NONE);
2099 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2100 if(default_value) RNA_def_property_string_default(prop, default_value);
2101 RNA_def_property_ui_text(prop, ui_name, ui_description);
2106 PropertyRNA *RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
2107 const char *ui_name, const char *ui_description)
2109 ContainerRNA *cont= cont_;
2112 prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_FILEPATH);
2113 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2114 if(default_value) RNA_def_property_string_default(prop, default_value);
2115 RNA_def_property_ui_text(prop, ui_name, ui_description);
2120 PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
2121 const char *ui_name, const char *ui_description)
2123 ContainerRNA *cont= cont_;
2126 prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_DIRPATH);
2127 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2128 if(default_value) RNA_def_property_string_default(prop, default_value);
2129 RNA_def_property_ui_text(prop, ui_name, ui_description);
2134 PropertyRNA *RNA_def_string_file_name(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
2135 const char *ui_name, const char *ui_description)
2137 ContainerRNA *cont= cont_;
2140 prop= RNA_def_property(cont, identifier, PROP_STRING, PROP_FILENAME);
2141 if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2142 if(default_value) RNA_def_property_string_default(prop, default_value);
2143 RNA_def_property_ui_text(prop, ui_name, ui_description);
2148 PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, int default_value,
2149 const char *ui_name, const char *ui_description)
2151 ContainerRNA *cont= cont_;
2155 printf("RNA_def_enum: items not allowed to be NULL.\n");
2159 prop= RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
2160 if(items) RNA_def_property_enum_items(prop, items);
2161 RNA_def_property_enum_default(prop, default_value);
2162 RNA_def_property_ui_text(prop, ui_name, ui_description);
2167 void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
2169 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2170 eprop->itemf= itemfunc;
2173 PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
2174 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2176 ContainerRNA *cont= cont_;
2179 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
2180 RNA_def_property_float_default(prop, default_value);
2181 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2182 RNA_def_property_ui_text(prop, ui_name, ui_description);
2183 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2188 PropertyRNA *RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2189 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2191 ContainerRNA *cont= cont_;
2194 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_XYZ);
2195 if(len != 0) RNA_def_property_array(prop, len);
2196 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2197 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2198 RNA_def_property_ui_text(prop, ui_name, ui_description);
2199 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2204 PropertyRNA *RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2205 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2209 prop= RNA_def_float_vector(cont_, identifier, len, default_value, hardmin, hardmax, ui_name, ui_description, softmin, softmax);
2210 prop->subtype = PROP_XYZ_LENGTH;
2215 PropertyRNA *RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2216 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2218 ContainerRNA *cont= cont_;
2221 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_COLOR);
2222 if(len != 0) RNA_def_property_array(prop, len);
2223 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2224 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2225 RNA_def_property_ui_text(prop, ui_name, ui_description);
2226 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2232 PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int rows, int columns, const float *default_value,
2233 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2235 ContainerRNA *cont= cont_;
2237 int length[2]= {rows, columns};
2239 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_MATRIX);
2240 RNA_def_property_multi_array(prop, 2, length);
2241 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2242 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2243 RNA_def_property_ui_text(prop, ui_name, ui_description);
2244 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2249 PropertyRNA *RNA_def_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2250 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2252 ContainerRNA *cont= cont_;
2255 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_EULER); // XXX
2256 if(len != 0) RNA_def_property_array(prop, len);
2257 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2258 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2259 RNA_def_property_ui_text(prop, ui_name, ui_description);
2260 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2265 PropertyRNA *RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value,
2266 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2268 ContainerRNA *cont= cont_;
2271 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
2272 if(len != 0) RNA_def_property_array(prop, len);
2273 if(default_value) RNA_def_property_float_array_default(prop, default_value);
2274 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2275 RNA_def_property_ui_text(prop, ui_name, ui_description);
2276 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2281 PropertyRNA *RNA_def_float_percentage(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
2282 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2284 ContainerRNA *cont= cont_;
2287 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_PERCENTAGE);
2288 RNA_def_property_float_default(prop, default_value);
2289 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2290 RNA_def_property_ui_text(prop, ui_name, ui_description);
2291 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2296 PropertyRNA *RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
2297 float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
2299 ContainerRNA *cont= cont_;
2302 prop= RNA_def_property(cont, identifier, PROP_FLOAT, PROP_FACTOR);
2303 RNA_def_property_float_default(prop, default_value);
2304 if(hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2305 RNA_def_property_ui_text(prop, ui_name, ui_description);
2306 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2311 PropertyRNA *RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
2312 const char *ui_name, const char *ui_description)
2314 ContainerRNA *cont= cont_;
2317 prop= RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
2318 RNA_def_property_struct_type(prop, type);
2319 RNA_def_property_ui_text(prop, ui_name, ui_description);
2324 PropertyRNA *RNA_def_pointer_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
2325 const char *ui_name, const char *ui_description)
2327 ContainerRNA *cont= cont_;
2330 prop= RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
2331 RNA_def_property_struct_runtime(prop, type);
2332 RNA_def_property_ui_text(prop, ui_name, ui_description);
2337 PropertyRNA *RNA_def_collection(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
2338 const char *ui_name, const char *ui_description)
2340 ContainerRNA *cont= cont_;
2343 prop= RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
2344 RNA_def_property_struct_type(prop, type);
2345 RNA_def_property_ui_text(prop, ui_name, ui_description);
2350 PropertyRNA *RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
2351 const char *ui_name, const char *ui_description)
2353 ContainerRNA *cont= cont_;
2356 prop= RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
2357 RNA_def_property_struct_runtime(prop, type);
2358 RNA_def_property_ui_text(prop, ui_name, ui_description);
2365 static FunctionRNA *rna_def_function(StructRNA *srna, const char *identifier)
2368 StructDefRNA *dsrna;
2369 FunctionDefRNA *dfunc;
2371 if(DefRNA.preprocess) {
2374 if (rna_validate_identifier(identifier, error, 0) == 0) {
2375 fprintf(stderr, "RNA_def_function: function identifier \"%s\" - %s\n", identifier, error);
2380 func= MEM_callocN(sizeof(FunctionRNA), "FunctionRNA");
2381 func->identifier= identifier;
2382 func->description= identifier;
2384 rna_addtail(&srna->functions, func);
2386 if(DefRNA.preprocess) {
2387 dsrna= rna_find_struct_def(srna);
2388 dfunc= MEM_callocN(sizeof(FunctionDefRNA), "FunctionDefRNA");
2389 rna_addtail(&dsrna->functions, dfunc);
2393 func->flag|= FUNC_RUNTIME;
2398 FunctionRNA *RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
2401 FunctionDefRNA *dfunc;
2403 func= rna_def_function(srna, identifier);
2405 if(!DefRNA.preprocess) {
2406 fprintf(stderr, "RNA_def_function: only at preprocess time.\n");
2410 dfunc= rna_find_function_def(func);
2416 FunctionRNA *RNA_def_function_runtime(StructRNA *srna, const char *identifier, CallFunc call)
2420 func= rna_def_function(srna, identifier);
2422 if(DefRNA.preprocess) {
2423 fprintf(stderr, "RNA_def_function_call_runtime: only at runtime.\n");
2433 /* C return value only!, multiple RNA returns can be done with RNA_def_function_output */
2434 void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
2436 if (ret->flag & PROP_DYNAMIC) {
2437 fprintf(stderr, "RNA_def_function_return: \"%s.%s\", dynamic values are not allowed as strict returns, use RNA_def_function_output instead.\n", func->identifier, ret->identifier);
2440 else if (ret->arraydimension) {
2441 fprintf(stderr, "RNA_def_function_return: \"%s.%s\", arrays are not allowed as strict returns, use RNA_def_function_output instead.\n", func->identifier, ret->identifier);
2447 RNA_def_function_output(func, ret);
2450 void RNA_def_function_output(FunctionRNA *func, PropertyRNA *ret)
2452 ret->flag|= PROP_OUTPUT;
2455 void RNA_def_function_flag(FunctionRNA *func, int flag)
2460 void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
2462 func->description= description;
2465 int rna_parameter_size(PropertyRNA *parm)
2467 PropertyType ptype= parm->type;
2468 int len= parm->totarraylength; /* only supports fixed length at the moment */
2471 /* XXX in other parts is mentioned that strings can be dynamic as well */
2472 if (parm->flag & PROP_DYNAMIC)
2473 return sizeof(void *);
2478 return sizeof(int)*len;
2480 return sizeof(float)*len;
2492 return sizeof(float);
2494 /* return valyes dont store a pointer to the original */
2495 if(parm->flag & PROP_THICK_WRAP) {
2496 StringPropertyRNA *sparm= (StringPropertyRNA*)parm;
2497 return sizeof(char) * sparm->maxlength;
2499 return sizeof(char *);
2500 case PROP_POINTER: {
2502 if(parm->flag & PROP_RNAPTR)
2503 return sizeof(PointerRNA);
2505 return sizeof(void *);
2507 if(parm->flag & PROP_RNAPTR)
2508 return sizeof(PointerRNA);
2510 return sizeof(void *);
2513 case PROP_COLLECTION:
2514 return sizeof(ListBase);
2518 return sizeof(void *);
2521 /* this function returns the size of the memory allocated for the parameter,
2522 useful for instance for memory alignment or for storing additional information */
2523 int rna_parameter_size_alloc(PropertyRNA *parm)
2525 int size = rna_parameter_size(parm);
2527 if (parm->flag & PROP_DYNAMIC)
2528 size+= sizeof(((ParameterDynAlloc *)NULL)->array_tot);
2535 void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item)
2537 EnumPropertyItem *newitems;
2541 *items= MEM_callocN(sizeof(EnumPropertyItem)*8, "RNA_enum_items_add");
2543 else if(tot >= 8 && (tot&(tot-1)) == 0){
2544 /* power of two > 8 */
2545 newitems= MEM_callocN(sizeof(EnumPropertyItem)*tot*2, "RNA_enum_items_add");
2546 memcpy(newitems, *items, sizeof(EnumPropertyItem)*tot);
2551 (*items)[tot]= *item;
2555 void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem)
2557 static EnumPropertyItem sepr = {0, "", 0, NULL, NULL};
2558 RNA_enum_item_add(items, totitem, &sepr);
2561 void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item)
2563 for(; item->identifier; item++)
2564 RNA_enum_item_add(items, totitem, item);
2567 void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, EnumPropertyItem *item, int value)
2569 for(; item->identifier; item++) {
2570 if(item->value == value) {
2571 RNA_enum_item_add(items, totitem, item);
2572 break; // break on first match - does this break anything? (is quick hack to get object->parent_type working ok for armature/lattice)
2577 void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
2579 static EnumPropertyItem empty = {0, NULL, 0, NULL, NULL};
2580 RNA_enum_item_add(items, totitem, &empty);
2583 /* Memory management */
2586 void RNA_def_struct_duplicate_pointers(StructRNA *srna)
2588 if(srna->identifier) srna->identifier= BLI_strdup(srna->identifier);
2589 if(srna->name) srna->name= BLI_strdup(srna->name);
2590 if(srna->description) srna->description= BLI_strdup(srna->description);
2592 srna->flag |= STRUCT_FREE_POINTERS;
2595 void RNA_def_struct_free_pointers(StructRNA *srna)
2597 if(srna->flag & STRUCT_FREE_POINTERS) {
2598 if(srna->identifier) MEM_freeN((void*)srna->identifier);
2599 if(srna->name) MEM_freeN((void*)srna->name);
2600 if(srna->description) MEM_freeN((void*)srna->description);
2604 void RNA_def_func_duplicate_pointers(FunctionRNA *func)
2606 if(func->identifier) func->identifier= BLI_strdup(func->identifier);
2607 if(func->description) func->description= BLI_strdup(func->description);
2609 func->flag |= FUNC_FREE_POINTERS;
2612 void RNA_def_func_free_pointers(FunctionRNA *func)
2614 if(func->flag & FUNC_FREE_POINTERS) {
2615 if(func->identifier) MEM_freeN((void*)func->identifier);
2616 if(func->description) MEM_freeN((void*)func->description);
2620 void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop)
2622 ContainerRNA *cont= cont_;
2623 EnumPropertyItem *earray;
2628 /* annoying since we just added this to a hash, could make this add the correct key to the hash in the first place */
2629 if(prop->identifier) {
2630 if(cont->prophash) {
2631 BLI_ghash_remove(cont->prophash, (void*)prop->identifier, NULL, NULL);
2632 prop->identifier= BLI_strdup(prop->identifier);
2633 BLI_ghash_insert(cont->prophash, (void*)prop->identifier, prop);
2636 prop->identifier= BLI_strdup(prop->identifier);
2640 if(prop->name) prop->name= BLI_strdup(prop->name);
2641 if(prop->description) prop->description= BLI_strdup(prop->description);
2643 switch(prop->type) {
2644 case PROP_BOOLEAN: {
2645 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
2647 if(bprop->defaultarray) {
2648 iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
2649 memcpy(iarray, bprop->defaultarray, sizeof(int)*prop->totarraylength);
2650 bprop->defaultarray= iarray;
2655 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2657 if(iprop->defaultarray) {
2658 iarray= MEM_callocN(sizeof(int)*prop->totarraylength, "RNA_def_property_store");
2659 memcpy(iarray, iprop->defaultarray, sizeof(int)*prop->totarraylength);
2660 iprop->defaultarray= iarray;
2665 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2668 earray= MEM_callocN(sizeof(EnumPropertyItem)*(eprop->totitem+1), "RNA_def_property_store"),
2669 memcpy(earray, eprop->item, sizeof(EnumPropertyItem)*(eprop->totitem+1));
2670 eprop->item= earray;
2672 for(a=0; a<eprop->totitem; a++) {
2673 if(eprop->item[a].identifier) eprop->item[a].identifier= BLI_strdup(eprop->item[a].identifier);
2674 if(eprop->item[a].name) eprop->item[a].name= BLI_strdup(eprop->item[a].name);
2675 if(eprop->item[a].description) eprop->item[a].description= BLI_strdup(eprop->item[a].description);
2681 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2683 if(fprop->defaultarray) {
2684 farray= MEM_callocN(sizeof(float)*prop->totarraylength, "RNA_def_property_store");
2685 memcpy(farray, fprop->defaultarray, sizeof(float)*prop->totarraylength);
2686 fprop->defaultarray= farray;
2691 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
2692 if(sprop->defaultvalue) sprop->defaultvalue= BLI_strdup(sprop->defaultvalue);
2699 prop->flag |= PROP_FREE_POINTERS;
2702 void RNA_def_property_free_pointers(PropertyRNA *prop)
2704 if(prop->flag & PROP_FREE_POINTERS) {
2707 if(prop->identifier) MEM_freeN((void*)prop->identifier);
2708 if(prop->name) MEM_freeN((void*)prop->name);
2709 if(prop->description) MEM_freeN((void*)prop->description);
2711 switch(prop->type) {
2712 case PROP_BOOLEAN: {
2713 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
2714 if(bprop->defaultarray) MEM_freeN((void*)bprop->defaultarray);
2718 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2719 if(iprop->defaultarray) MEM_freeN((void*)iprop->defaultarray);
2723 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2724 if(fprop->defaultarray) MEM_freeN((void*)fprop->defaultarray);
2728 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2730 for(a=0; a<eprop->totitem; a++) {
2731 if(eprop->item[a].identifier) MEM_freeN((void*)eprop->item[a].identifier);
2732 if(eprop->item[a].name) MEM_freeN((void*)eprop->item[a].name);
2733 if(eprop->item[a].description) MEM_freeN((void*)eprop->item[a].description);
2736 if(eprop->item) MEM_freeN((void*)eprop->item);
2740 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
2741 if(sprop->defaultvalue) MEM_freeN((void*)sprop->defaultvalue);
2750 void RNA_def_property_free(StructOrFunctionRNA *cont_, PropertyRNA *prop)
2752 ContainerRNA *cont= cont_;
2754 if(prop->flag & PROP_RUNTIME) {
2756 BLI_ghash_remove(cont->prophash, (void*)prop->identifier, NULL, NULL);
2758 RNA_def_property_free_pointers(prop);
2759 rna_freelinkN(&cont->properties, prop);
2762 RNA_def_property_free_pointers(prop);
2766 /* note: only intended for removing dynamic props */
2767 int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier)
2769 ContainerRNA *cont= cont_;
2772 for(prop= cont->properties.first; prop; prop= prop->next) {
2773 if(strcmp(prop->identifier, identifier)==0) {
2774 if(prop->flag & PROP_RUNTIME) {
2775 RNA_def_property_free(cont_, prop);