2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Blender Foundation (2008).
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_define.c
36 #include "BLI_utildefines.h"
37 #include "MEM_guardedalloc.h"
39 #include "DNA_genfile.h"
40 #include "DNA_sdna_types.h"
42 #include "BLI_listbase.h"
43 #include "BLI_ghash.h"
45 #include "BLT_translation.h"
47 #include "UI_interface.h" /* For things like UI_PRECISION_FLOAT_MAX... */
49 #include "RNA_define.h"
51 #include "rna_internal.h"
55 # define ASSERT_SOFT_HARD_LIMITS \
56 if (softmin < hardmin || softmax > hardmax) { \
57 fprintf(stderr, "Error with soft/hard limits: %s.%s\n", CONTAINER_RNA_ID(cont), identifier); \
58 BLI_assert(!"invalid soft/hard limits"); \
61 # define ASSERT_SOFT_HARD_LIMITS (void)0
64 /* Global used during defining */
66 BlenderDefRNA DefRNA = {NULL, {NULL, NULL}, {NULL, NULL}, NULL, 0, 0, 0, 1, 1};
68 /* Duplicated code since we can't link in blenkernel or blenlib */
70 /* pedantic check for final '.', note '...' are allowed though. */
72 # define DESCR_CHECK(description, id1, id2) \
73 if (description && (description)[0]) { \
74 int i = strlen(description); \
75 if (i > 3 && (description)[i - 1] == '.' && (description)[i - 3] != '.') { \
76 fprintf(stderr, "%s: '%s' description from '%s' '%s' ends with a '.' !\n", \
77 __func__, description, id1 ? id1 : "", id2 ? id2 : ""); \
82 # define DESCR_CHECK(description, id1, id2)
85 void rna_addtail(ListBase *listbase, void *vlink)
90 link->prev = listbase->last;
92 if (listbase->last) ((Link *)listbase->last)->next = link;
93 if (listbase->first == NULL) listbase->first = link;
94 listbase->last = link;
97 static void rna_remlink(ListBase *listbase, void *vlink)
101 if (link->next) link->next->prev = link->prev;
102 if (link->prev) link->prev->next = link->next;
104 if (listbase->last == link) listbase->last = link->prev;
105 if (listbase->first == link) listbase->first = link->next;
108 PropertyDefRNA *rna_findlink(ListBase *listbase, const char *identifier)
112 for (link = listbase->first; link; link = link->next) {
113 PropertyRNA *prop = ((PropertyDefRNA *)link)->prop;
114 if (prop && (STREQ(prop->identifier, identifier))) {
115 return (PropertyDefRNA *)link;
122 void rna_freelinkN(ListBase *listbase, void *vlink)
124 rna_remlink(listbase, vlink);
128 void rna_freelistN(ListBase *listbase)
132 for (link = listbase->first; link; link = next) {
137 listbase->first = listbase->last = NULL;
140 static void rna_brna_structs_add(BlenderRNA *brna, StructRNA *srna)
142 rna_addtail(&brna->structs, srna);
143 brna->structs_len += 1;
145 /* This exception is only needed for pre-processing.
146 * otherwise we don't allow empty names. */
147 if ((srna->flag & STRUCT_PUBLIC_NAMESPACE) &&
148 (srna->identifier[0] != '\0'))
150 BLI_ghash_insert(brna->structs_map, (void *)srna->identifier, srna);
155 static void rna_brna_structs_remove_and_free(BlenderRNA *brna, StructRNA *srna)
157 if ((srna->flag & STRUCT_PUBLIC_NAMESPACE) && brna->structs_map) {
158 if (srna->identifier[0] != '\0') {
159 BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL);
163 RNA_def_struct_free_pointers(NULL, srna);
165 if (srna->flag & STRUCT_RUNTIME) {
166 rna_freelinkN(&brna->structs, srna);
168 brna->structs_len -= 1;
172 StructDefRNA *rna_find_struct_def(StructRNA *srna)
176 if (!DefRNA.preprocess) {
177 /* we should never get here */
178 fprintf(stderr, "%s: only at preprocess time.\n", __func__);
182 dsrna = DefRNA.structs.last;
183 for (; dsrna; dsrna = dsrna->cont.prev)
184 if (dsrna->srna == srna)
190 PropertyDefRNA *rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop)
193 PropertyDefRNA *dprop;
195 if (!DefRNA.preprocess) {
196 /* we should never get here */
197 fprintf(stderr, "%s: only at preprocess time.\n", __func__);
201 dsrna = rna_find_struct_def(srna);
202 dprop = dsrna->cont.properties.last;
203 for (; dprop; dprop = dprop->prev)
204 if (dprop->prop == prop)
207 dsrna = DefRNA.structs.last;
208 for (; dsrna; dsrna = dsrna->cont.prev) {
209 dprop = dsrna->cont.properties.last;
210 for (; dprop; dprop = dprop->prev)
211 if (dprop->prop == prop)
219 static PropertyDefRNA *rna_find_property_def(PropertyRNA *prop)
221 PropertyDefRNA *dprop;
223 if (!DefRNA.preprocess) {
224 /* we should never get here */
225 fprintf(stderr, "%s: only at preprocess time.\n", __func__);
229 dprop = rna_find_struct_property_def(DefRNA.laststruct, prop);
233 dprop = rna_find_parameter_def(prop);
241 FunctionDefRNA *rna_find_function_def(FunctionRNA *func)
244 FunctionDefRNA *dfunc;
246 if (!DefRNA.preprocess) {
247 /* we should never get here */
248 fprintf(stderr, "%s: only at preprocess time.\n", __func__);
252 dsrna = rna_find_struct_def(DefRNA.laststruct);
253 dfunc = dsrna->functions.last;
254 for (; dfunc; dfunc = dfunc->cont.prev)
255 if (dfunc->func == func)
258 dsrna = DefRNA.structs.last;
259 for (; dsrna; dsrna = dsrna->cont.prev) {
260 dfunc = dsrna->functions.last;
261 for (; dfunc; dfunc = dfunc->cont.prev)
262 if (dfunc->func == func)
269 PropertyDefRNA *rna_find_parameter_def(PropertyRNA *parm)
272 FunctionDefRNA *dfunc;
273 PropertyDefRNA *dparm;
275 if (!DefRNA.preprocess) {
276 /* we should never get here */
277 fprintf(stderr, "%s: only at preprocess time.\n", __func__);
281 dsrna = rna_find_struct_def(DefRNA.laststruct);
282 dfunc = dsrna->functions.last;
283 for (; dfunc; dfunc = dfunc->cont.prev) {
284 dparm = dfunc->cont.properties.last;
285 for (; dparm; dparm = dparm->prev)
286 if (dparm->prop == parm)
290 dsrna = DefRNA.structs.last;
291 for (; dsrna; dsrna = dsrna->cont.prev) {
292 dfunc = dsrna->functions.last;
293 for (; dfunc; dfunc = dfunc->cont.prev) {
294 dparm = dfunc->cont.properties.last;
295 for (; dparm; dparm = dparm->prev)
296 if (dparm->prop == parm)
304 static ContainerDefRNA *rna_find_container_def(ContainerRNA *cont)
307 FunctionDefRNA *dfunc;
309 if (!DefRNA.preprocess) {
310 /* we should never get here */
311 fprintf(stderr, "%s: only at preprocess time.\n", __func__);
315 ds = rna_find_struct_def((StructRNA *)cont);
319 dfunc = rna_find_function_def((FunctionRNA *)cont);
326 /* DNA utility function for looking up members */
328 typedef struct DNAStructMember {
335 static int rna_member_cmp(const char *name, const char *oname)
339 /* compare without pointer or array part */
340 while (name[0] == '*')
342 while (oname[0] == '*')
346 if (name[a] == '[' && oname[a] == 0) return 1;
347 if (name[a] == '[' && oname[a] == '[') return 1;
348 if (name[a] == 0) break;
349 if (name[a] != oname[a]) return 0;
352 if (name[a] == 0 && oname[a] == '.') return 2;
353 if (name[a] == 0 && oname[a] == '-' && oname[a + 1] == '>') return 3;
355 return (name[a] == oname[a]);
358 static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *membername, DNAStructMember *smember)
362 int a, b, structnr, totmember, cmp;
364 structnr = DNA_struct_find_nr(sdna, structname);
368 sp = sdna->structs[structnr];
372 for (a = 0; a < totmember; a++, sp += 2) {
373 dnaname = sdna->names[sp[1]];
375 cmp = rna_member_cmp(dnaname, membername);
378 smember->type = sdna->types[sp[0]];
379 smember->name = dnaname;
381 if (strstr(membername, "["))
382 smember->arraylength = 0;
384 smember->arraylength = DNA_elem_array_size(smember->name);
386 smember->pointerlevel = 0;
387 for (b = 0; dnaname[b] == '*'; b++)
388 smember->pointerlevel++;
394 smember->name = dnaname;
395 smember->pointerlevel = 0;
396 smember->arraylength = 0;
398 membername = strstr(membername, ".") + strlen(".");
399 rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
405 smember->name = dnaname;
406 smember->pointerlevel = 0;
407 smember->arraylength = 0;
409 membername = strstr(membername, "->") + strlen("->");
410 rna_find_sdna_member(sdna, sdna->types[sp[0]], membername, smember);
419 static int rna_validate_identifier(const char *identifier, char *error, bool property)
424 * ", ".join(['"%s"' % kw for kw in __import__("keyword").kwlist if kw not in {"False", "None", "True"}])
426 static const char *kwlist[] = {
427 /* "False", "None", "True", */
428 "and", "as", "assert", "break",
429 "class", "continue", "def", "del", "elif", "else", "except",
430 "finally", "for", "from", "global", "if", "import", "in",
431 "is", "lambda", "nonlocal", "not", "or", "pass", "raise",
432 "return", "try", "while", "with", "yield", NULL
436 if (!isalpha(identifier[0])) {
437 strcpy(error, "first character failed isalpha() check");
441 for (a = 0; identifier[a]; a++) {
442 if (DefRNA.preprocess && property) {
443 if (isalpha(identifier[a]) && isupper(identifier[a])) {
444 strcpy(error, "property names must contain lower case characters only");
449 if (identifier[a] == '_') {
453 if (identifier[a] == ' ') {
454 strcpy(error, "spaces are not okay in identifier names");
458 if (isalnum(identifier[a]) == 0) {
459 strcpy(error, "one of the characters failed an isalnum() check and is not an underscore");
464 for (a = 0; kwlist[a]; a++) {
465 if (STREQ(identifier, kwlist[a])) {
466 strcpy(error, "this keyword is reserved by python");
472 static const char *kwlist_prop[] = {
473 /* not keywords but reserved all the same because py uses */
474 "keys", "values", "items", "get",
478 for (a = 0; kwlist_prop[a]; a++) {
479 if (STREQ(identifier, kwlist_prop[a])) {
480 strcpy(error, "this keyword is reserved by python");
489 void RNA_identifier_sanitize(char *identifier, int property)
493 /* list from http://docs.python.org/py3k/reference/lexical_analysis.html#keywords */
494 static const char *kwlist[] = {
495 /* "False", "None", "True", */
496 "and", "as", "assert", "break",
497 "class", "continue", "def", "del", "elif", "else", "except",
498 "finally", "for", "from", "global", "if", "import", "in",
499 "is", "lambda", "nonlocal", "not", "or", "pass", "raise",
500 "return", "try", "while", "with", "yield", NULL
504 if (!isalpha(identifier[0])) {
505 /* first character failed isalpha() check */
509 for (a = 0; identifier[a]; a++) {
510 if (DefRNA.preprocess && property) {
511 if (isalpha(identifier[a]) && isupper(identifier[a])) {
512 /* property names must contain lower case characters only */
513 identifier[a] = tolower(identifier[a]);
517 if (identifier[a] == '_') {
521 if (identifier[a] == ' ') {
522 /* spaces are not okay in identifier names */
526 if (isalnum(identifier[a]) == 0) {
527 /* one of the characters failed an isalnum() check and is not an underscore */
532 for (a = 0; kwlist[a]; a++) {
533 if (STREQ(identifier, kwlist[a])) {
534 /* this keyword is reserved by python.
535 * just replace the last character by '_' to keep it readable.
537 identifier[strlen(identifier) - 1] = '_';
543 static const char *kwlist_prop[] = {
544 /* not keywords but reserved all the same because py uses */
545 "keys", "values", "items", "get",
549 for (a = 0; kwlist_prop[a]; a++) {
550 if (STREQ(identifier, kwlist_prop[a])) {
551 /* this keyword is reserved by python.
552 * just replace the last character by '_' to keep it readable.
554 identifier[strlen(identifier) - 1] = '_';
561 /* Blender Data Definition */
563 BlenderRNA *RNA_create(void)
567 brna = MEM_callocN(sizeof(BlenderRNA), "BlenderRNA");
568 const char *error_message = NULL;
570 BLI_listbase_clear(&DefRNA.structs);
571 brna->structs_map = BLI_ghash_str_new_ex(__func__, 2048);
574 DefRNA.preprocess = 1;
576 DefRNA.sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, &error_message);
577 if (DefRNA.sdna == NULL) {
578 fprintf(stderr, "Error decoding SDNA: %s\n", error_message);
585 void RNA_define_free(BlenderRNA *UNUSED(brna))
588 FunctionDefRNA *dfunc;
591 for (alloc = DefRNA.allocs.first; alloc; alloc = alloc->next)
592 MEM_freeN(alloc->mem);
593 rna_freelistN(&DefRNA.allocs);
595 for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
596 for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next)
597 rna_freelistN(&dfunc->cont.properties);
599 rna_freelistN(&ds->cont.properties);
600 rna_freelistN(&ds->functions);
603 rna_freelistN(&DefRNA.structs);
606 DNA_sdna_free(DefRNA.sdna);
613 void RNA_define_verify_sdna(bool verify)
615 DefRNA.verify = verify;
619 void RNA_define_animate_sdna(bool animate)
621 DefRNA.animate = animate;
625 void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *ext)
628 ext->free(ext->data); /* decref's the PyObject that the srna owns */
629 RNA_struct_blender_type_set(srna, NULL); /* this gets accessed again - XXX fixme */
630 RNA_struct_py_type_set(srna, NULL); /* NULL the srna's value so RNA_struct_free wont complain of a leak */
637 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
640 FunctionRNA *func, *nextfunc;
641 PropertyRNA *prop, *nextprop;
642 PropertyRNA *parm, *nextparm;
645 if (srna->flag & STRUCT_RUNTIME) {
646 if (RNA_struct_py_type_get(srna)) {
647 fprintf(stderr, "%s '%s' freed while holding a python reference\n", __func__, srna->identifier);
652 for (prop = srna->cont.properties.first; prop; prop = nextprop) {
653 nextprop = prop->next;
655 RNA_def_property_free_pointers(prop);
657 if (prop->flag_internal & PROP_INTERN_RUNTIME)
658 rna_freelinkN(&srna->cont.properties, prop);
661 for (func = srna->functions.first; func; func = nextfunc) {
662 nextfunc = func->cont.next;
664 for (parm = func->cont.properties.first; parm; parm = nextparm) {
665 nextparm = parm->next;
667 RNA_def_property_free_pointers(parm);
669 if (parm->flag_internal & PROP_INTERN_RUNTIME)
670 rna_freelinkN(&func->cont.properties, parm);
673 RNA_def_func_free_pointers(func);
675 if (func->flag & FUNC_RUNTIME)
676 rna_freelinkN(&srna->functions, func);
680 rna_brna_structs_remove_and_free(brna, srna);
682 UNUSED_VARS(brna, srna);
686 void RNA_free(BlenderRNA *brna)
688 StructRNA *srna, *nextsrna;
691 BLI_ghash_free(brna->structs_map, NULL, NULL);
692 brna->structs_map = NULL;
694 if (DefRNA.preprocess) {
695 RNA_define_free(brna);
697 for (srna = brna->structs.first; srna; srna = srna->cont.next) {
698 for (func = srna->functions.first; func; func = func->cont.next)
699 rna_freelistN(&func->cont.properties);
701 rna_freelistN(&srna->cont.properties);
702 rna_freelistN(&srna->functions);
705 rna_freelistN(&brna->structs);
710 for (srna = brna->structs.first; srna; srna = nextsrna) {
711 nextsrna = srna->cont.next;
712 RNA_struct_free(brna, srna);
717 static size_t rna_property_type_sizeof(PropertyType type)
720 case PROP_BOOLEAN: return sizeof(BoolPropertyRNA);
721 case PROP_INT: return sizeof(IntPropertyRNA);
722 case PROP_FLOAT: return sizeof(FloatPropertyRNA);
723 case PROP_STRING: return sizeof(StringPropertyRNA);
724 case PROP_ENUM: return sizeof(EnumPropertyRNA);
725 case PROP_POINTER: return sizeof(PointerPropertyRNA);
726 case PROP_COLLECTION: return sizeof(CollectionPropertyRNA);
731 static StructDefRNA *rna_find_def_struct(StructRNA *srna)
735 for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
736 if (ds->srna == srna)
742 /* Struct Definition */
743 StructRNA *RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
746 StructDefRNA *ds = NULL, *dsfrom = NULL;
749 if (DefRNA.preprocess) {
752 if (rna_validate_identifier(identifier, error, false) == 0) {
753 fprintf(stderr, "%s: struct identifier \"%s\" error - %s\n", __func__, identifier, error);
758 srna = MEM_callocN(sizeof(StructRNA), "StructRNA");
759 DefRNA.laststruct = srna;
762 /* copy from struct to derive stuff, a bit clumsy since we can't
763 * use MEM_dupallocN, data structs may not be alloced but builtin */
764 memcpy(srna, srnafrom, sizeof(StructRNA));
765 srna->cont.prophash = NULL;
766 BLI_listbase_clear(&srna->cont.properties);
767 BLI_listbase_clear(&srna->functions);
768 srna->py_type = NULL;
770 srna->base = srnafrom;
772 if (DefRNA.preprocess) {
773 dsfrom = rna_find_def_struct(srnafrom);
776 if (srnafrom->flag & STRUCT_PUBLIC_NAMESPACE_INHERIT) {
777 srna->flag |= STRUCT_PUBLIC_NAMESPACE | STRUCT_PUBLIC_NAMESPACE_INHERIT;
780 srna->flag &= ~(STRUCT_PUBLIC_NAMESPACE | STRUCT_PUBLIC_NAMESPACE_INHERIT);
785 srna->identifier = identifier;
786 srna->name = identifier; /* may be overwritten later RNA_def_struct_ui_text */
787 srna->description = "";
788 /* may be overwritten later RNA_def_struct_translation_context */
789 srna->translation_context = BLT_I18NCONTEXT_DEFAULT_BPYRNA;
790 srna->flag |= STRUCT_UNDO;
792 srna->icon = ICON_DOT;
794 if (DefRNA.preprocess) {
795 srna->flag |= STRUCT_PUBLIC_NAMESPACE;
798 rna_brna_structs_add(brna, srna);
800 if (DefRNA.preprocess) {
801 ds = MEM_callocN(sizeof(StructDefRNA), "StructDefRNA");
803 rna_addtail(&DefRNA.structs, ds);
806 ds->dnafromname = dsfrom->dnaname;
809 /* in preprocess, try to find sdna */
810 if (DefRNA.preprocess)
811 RNA_def_struct_sdna(srna, srna->identifier);
813 srna->flag |= STRUCT_RUNTIME;
816 srna->nameproperty = srnafrom->nameproperty;
817 srna->iteratorproperty = srnafrom->iteratorproperty;
820 /* define some builtin properties */
821 prop = RNA_def_property(&srna->cont, "rna_properties", PROP_COLLECTION, PROP_NONE);
822 prop->flag_internal |= PROP_INTERN_BUILTIN;
823 RNA_def_property_ui_text(prop, "Properties", "RNA property collection");
825 if (DefRNA.preprocess) {
826 RNA_def_property_struct_type(prop, "Property");
827 RNA_def_property_collection_funcs(prop, "rna_builtin_properties_begin", "rna_builtin_properties_next",
828 "rna_iterator_listbase_end", "rna_builtin_properties_get", NULL, NULL,
829 "rna_builtin_properties_lookup_string", NULL);
833 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
834 cprop->begin = rna_builtin_properties_begin;
835 cprop->next = rna_builtin_properties_next;
836 cprop->get = rna_builtin_properties_get;
837 cprop->item_type = &RNA_Property;
841 prop = RNA_def_property(&srna->cont, "rna_type", PROP_POINTER, PROP_NONE);
842 RNA_def_property_flag(prop, PROP_HIDDEN);
843 RNA_def_property_ui_text(prop, "RNA", "RNA type definition");
845 if (DefRNA.preprocess) {
846 RNA_def_property_struct_type(prop, "Struct");
847 RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", NULL, NULL, NULL);
851 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
852 pprop->get = rna_builtin_type_get;
853 pprop->type = &RNA_Struct;
861 StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
863 StructRNA *srnafrom = NULL;
865 /* only use RNA_def_struct() while pre-processing, otherwise use RNA_def_struct_ptr() */
866 BLI_assert(DefRNA.preprocess);
869 /* find struct to derive from */
870 /* Inline RNA_struct_find(...) because it wont link from here. */
871 srnafrom = BLI_ghash_lookup(brna->structs_map, from);
873 fprintf(stderr, "%s: struct %s not found to define %s.\n", __func__, from, identifier);
878 return RNA_def_struct_ptr(brna, identifier, srnafrom);
881 void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
885 if (!DefRNA.preprocess) {
886 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
890 ds = rna_find_def_struct(srna);
892 /* there are far too many structs which initialize without valid DNA struct names,
893 * this can't be checked without adding an option to disable (tested this and it means changes all over - Campbell) */
895 if (DNA_struct_find_nr(DefRNA.sdna, structname) == -1) {
896 if (!DefRNA.silent) {
897 fprintf(stderr, "%s: %s not found.\n", __func__, structname);
904 ds->dnaname = structname;
907 void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
911 if (!DefRNA.preprocess) {
912 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
916 ds = rna_find_def_struct(srna);
919 fprintf(stderr, "%s: %s base struct must know DNA already.\n", __func__, structname);
923 if (DNA_struct_find_nr(DefRNA.sdna, structname) == -1) {
924 if (!DefRNA.silent) {
925 fprintf(stderr, "%s: %s not found.\n", __func__, structname);
931 ds->dnafromprop = propname;
932 ds->dnaname = structname;
935 void RNA_def_struct_name_property(struct StructRNA *srna, struct PropertyRNA *prop)
937 if (prop->type != PROP_STRING) {
938 fprintf(stderr, "%s: \"%s.%s\", must be a string property.\n", __func__, srna->identifier, prop->identifier);
942 srna->nameproperty = prop;
945 void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
949 /* find struct to derive from */
950 srnafrom = BLI_ghash_lookup(brna->structs_map, structname);
952 fprintf(stderr, "%s: struct %s not found for %s.\n", __func__, structname, srna->identifier);
956 srna->nested = srnafrom;
959 void RNA_def_struct_flag(StructRNA *srna, int flag)
964 void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
969 void RNA_def_struct_property_tags(StructRNA *srna, const EnumPropertyItem *prop_tag_defines)
971 srna->prop_tag_defines = prop_tag_defines;
974 void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
976 if (!DefRNA.preprocess) {
977 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
981 if (refine) srna->refine = (StructRefineFunc)refine;
984 void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
986 if (!DefRNA.preprocess) {
987 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
991 if (idproperties) srna->idproperties = (IDPropertiesFunc)idproperties;
994 void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance)
996 if (!DefRNA.preprocess) {
997 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
1001 if (reg) srna->reg = (StructRegisterFunc)reg;
1002 if (unreg) srna->unreg = (StructUnregisterFunc)unreg;
1003 if (instance) srna->instance = (StructInstanceFunc)instance;
1006 void RNA_def_struct_path_func(StructRNA *srna, const char *path)
1008 if (!DefRNA.preprocess) {
1009 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
1013 if (path) srna->path = (StructPathFunc)path;
1016 void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
1018 if (DefRNA.preprocess) {
1019 fprintf(stderr, "%s: only at runtime.\n", __func__);
1023 /* Operator registration may set twice, see: operator_properties_init */
1024 if (srna->flag & STRUCT_PUBLIC_NAMESPACE) {
1025 if (identifier != srna->identifier) {
1026 if (srna->identifier[0] != '\0') {
1027 BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL);
1029 if (identifier[0] != '\0') {
1030 BLI_ghash_insert(brna->structs_map, (void *)identifier, srna);
1035 srna->identifier = identifier;
1039 * Only used in one case when we name the struct for the purpose of useful error messages.
1041 void RNA_def_struct_identifier_no_struct_map(StructRNA *srna, const char *identifier)
1043 if (DefRNA.preprocess) {
1044 fprintf(stderr, "%s: only at runtime.\n", __func__);
1048 srna->identifier = identifier;
1051 void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
1053 DESCR_CHECK(description, srna->identifier, NULL);
1056 srna->description = description;
1059 void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
1064 void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
1066 srna->translation_context = context ? context : BLT_I18NCONTEXT_DEFAULT_BPYRNA;
1069 /* Property Definition */
1071 PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
1073 /*StructRNA *srna = DefRNA.laststruct;*/ /* invalid for python defined props */
1074 ContainerRNA *cont = cont_;
1075 ContainerDefRNA *dcont;
1076 PropertyDefRNA *dprop = NULL;
1079 if (DefRNA.preprocess) {
1082 if (rna_validate_identifier(identifier, error, true) == 0) {
1083 fprintf(stderr, "%s: property identifier \"%s.%s\" - %s\n", __func__,
1084 CONTAINER_RNA_ID(cont), identifier, error);
1088 dcont = rna_find_container_def(cont);
1090 /* XXX - toto, detect supertype collisions */
1091 if (rna_findlink(&dcont->properties, identifier)) {
1092 fprintf(stderr, "%s: duplicate identifier \"%s.%s\"\n", __func__, CONTAINER_RNA_ID(cont), identifier);
1096 dprop = MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA");
1097 rna_addtail(&dcont->properties, dprop);
1102 if (rna_validate_identifier(identifier, error, true) == 0) {
1103 fprintf(stderr, "%s: runtime property identifier \"%s.%s\" - %s\n", __func__,
1104 CONTAINER_RNA_ID(cont), identifier, error);
1110 prop = MEM_callocN(rna_property_type_sizeof(type), "PropertyRNA");
1114 if (DefRNA.preprocess) {
1115 if ((subtype & ~(PROP_LAYER_MEMBER)) != PROP_NONE) {
1116 fprintf(stderr, "%s: subtype does not apply to 'PROP_BOOLEAN' \"%s.%s\"\n", __func__,
1117 CONTAINER_RNA_ID(cont), identifier);
1124 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1127 if (subtype == PROP_DISTANCE) {
1128 fprintf(stderr, "%s: subtype does not apply to 'PROP_INT' \"%s.%s\"\n", __func__,
1129 CONTAINER_RNA_ID(cont), identifier);
1134 iprop->hardmin = (subtype == PROP_UNSIGNED) ? 0 : INT_MIN;
1135 iprop->hardmax = INT_MAX;
1137 iprop->softmin = (subtype == PROP_UNSIGNED) ? 0 : -10000; /* rather arbitrary .. */
1138 iprop->softmax = 10000;
1144 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1146 fprop->hardmin = (subtype == PROP_UNSIGNED) ? 0.0f : -FLT_MAX;
1147 fprop->hardmax = FLT_MAX;
1149 if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1150 fprop->softmin = fprop->hardmin = 0.0f;
1151 fprop->softmax = 1.0f;
1153 else if (subtype == PROP_FACTOR) {
1154 fprop->softmin = fprop->hardmin = 0.0f;
1155 fprop->softmax = fprop->hardmax = 1.0f;
1158 fprop->softmin = (subtype == PROP_UNSIGNED) ? 0.0f : -10000.0f; /* rather arbitrary .. */
1159 fprop->softmax = 10000.0f;
1162 fprop->precision = 3;
1167 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1168 /* By default don't allow NULL string args, callers may clear. */
1169 RNA_def_property_flag(prop, PROP_NEVER_NULL);
1170 sprop->defaultvalue = "";
1174 prop->flag |= PROP_THICK_WRAP; /* needed for default behavior when PARM_RNAPTR is set */
1177 case PROP_COLLECTION:
1180 fprintf(stderr, "%s: \"%s.%s\", invalid property type.\n", __func__, CONTAINER_RNA_ID(cont), identifier);
1185 if (DefRNA.preprocess) {
1190 prop->magic = RNA_MAGIC;
1191 prop->identifier = identifier;
1193 prop->subtype = subtype;
1194 prop->name = identifier;
1195 prop->description = "";
1196 prop->translation_context = BLT_I18NCONTEXT_DEFAULT_BPYRNA;
1197 /* a priori not raw editable */
1200 if (type != PROP_COLLECTION && type != PROP_POINTER) {
1201 prop->flag = PROP_EDITABLE;
1203 if (type != PROP_STRING) {
1205 prop->flag |= PROP_ANIMATABLE;
1207 if (DefRNA.animate) {
1208 prop->flag |= PROP_ANIMATABLE;
1214 if (type == PROP_STRING) {
1215 /* used so generated 'get/length/set' functions skip a NULL check
1216 * in some cases we want it */
1217 RNA_def_property_flag(prop, PROP_NEVER_NULL);
1220 if (DefRNA.preprocess) {
1224 RNA_def_property_boolean_sdna(prop, NULL, identifier, 0);
1230 RNA_def_property_int_sdna(prop, NULL, identifier);
1237 RNA_def_property_float_sdna(prop, NULL, identifier);
1244 RNA_def_property_string_sdna(prop, NULL, identifier);
1250 RNA_def_property_enum_sdna(prop, NULL, identifier);
1255 RNA_def_property_pointer_sdna(prop, NULL, identifier);
1258 case PROP_COLLECTION:
1260 RNA_def_property_collection_sdna(prop, NULL, identifier, NULL);
1266 prop->flag |= PROP_IDPROPERTY;
1267 prop->flag_internal |= PROP_INTERN_RUNTIME;
1270 BLI_ghash_insert(cont->prophash, (void *)prop->identifier, prop);
1274 /* Override handling. */
1275 if (DefRNA.preprocess) {
1276 prop->override_diff = (RNAPropOverrideDiff)"rna_property_override_diff_default";
1277 prop->override_store = (RNAPropOverrideStore)"rna_property_override_store_default";
1278 prop->override_apply = (RNAPropOverrideApply)"rna_property_override_apply_default";
1280 /* TODO: do we want that for runtime-defined stuff too? I’d say no, but... maybe yes :/ */
1282 rna_addtail(&cont->properties, prop);
1287 void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
1292 void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
1294 prop->flag &= ~flag;
1297 void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
1299 prop->flag_override |= flag;
1302 void RNA_def_property_override_clear_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
1304 prop->flag_override &= ~flag;
1308 * Add the property-tags passed as \a tags to \a prop (if valid).
1310 * \note Multiple tags can be set by passing them within \a tags (using bitflags).
1311 * \note Doesn't do any type-checking with the tags defined in the parent StructRNA
1312 * of \a prop. This should be done before (e.g. see #WM_operatortype_prop_tag).
1314 void RNA_def_property_tags(PropertyRNA *prop, int tags)
1319 void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
1321 prop->flag |= flag_property;
1322 prop->flag_parameter |= flag_parameter;
1325 void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
1327 prop->flag &= ~flag_property;
1328 prop->flag_parameter &= ~flag_parameter;
1331 void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
1333 prop->subtype = subtype;
1336 void RNA_def_property_array(PropertyRNA *prop, int length)
1338 StructRNA *srna = DefRNA.laststruct;
1341 fprintf(stderr, "%s: \"%s.%s\", array length must be zero of greater.\n", __func__,
1342 srna->identifier, prop->identifier);
1347 if (length > RNA_MAX_ARRAY_LENGTH) {
1348 fprintf(stderr, "%s: \"%s.%s\", array length must be smaller than %d.\n", __func__,
1349 srna->identifier, prop->identifier, RNA_MAX_ARRAY_LENGTH);
1354 if (prop->arraydimension > 1) {
1355 fprintf(stderr, "%s: \"%s.%s\", array dimensions has been set to %u but would be overwritten as 1.\n",
1356 __func__, srna->identifier, prop->identifier, prop->arraydimension);
1361 switch (prop->type) {
1365 prop->arraylength[0] = length;
1366 prop->totarraylength = length;
1367 prop->arraydimension = 1;
1370 fprintf(stderr, "%s: \"%s.%s\", only boolean/int/float can be array.\n",
1371 __func__, srna->identifier, prop->identifier);
1377 /* common args for length */
1378 const int rna_matrix_dimsize_3x3[] = {3, 3};
1379 const int rna_matrix_dimsize_4x4[] = {4, 4};
1380 const int rna_matrix_dimsize_4x2[] = {4, 2};
1382 void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
1384 StructRNA *srna = DefRNA.laststruct;
1387 if (dimension < 1 || dimension > RNA_MAX_ARRAY_DIMENSION) {
1388 fprintf(stderr, "%s: \"%s.%s\", array dimension must be between 1 and %d.\n",
1389 __func__, srna->identifier, prop->identifier, RNA_MAX_ARRAY_DIMENSION);
1394 switch (prop->type) {
1400 fprintf(stderr, "%s: \"%s.%s\", only boolean/int/float can be array.\n",
1401 __func__, srna->identifier, prop->identifier);
1406 prop->arraydimension = dimension;
1407 prop->totarraylength = 0;
1410 memcpy(prop->arraylength, length, sizeof(int) * dimension);
1412 prop->totarraylength = length[0];
1413 for (i = 1; i < dimension; i++)
1414 prop->totarraylength *= length[i];
1417 memset(prop->arraylength, 0, sizeof(prop->arraylength));
1419 /* TODO make sure arraylength values are sane */
1422 void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
1424 DESCR_CHECK(description, prop->identifier, NULL);
1427 prop->description = description;
1430 void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
1433 if (consecutive != 0)
1434 prop->flag |= PROP_ICONS_CONSECUTIVE;
1435 if (consecutive < 0)
1436 prop->flag |= PROP_ICONS_REVERSE;
1440 * The values hare are a little confusing:
1442 * \param step: Used as the value to increase/decrease when clicking on number buttons,
1443 * as well as scaling mouse input for click-dragging number buttons.
1444 * For floats this is (step * UI_PRECISION_FLOAT_SCALE), why? - nobody knows.
1445 * For ints, whole values are used.
1447 * \param precision The number of zeros to show
1448 * (as a whole number - common range is 1 - 6), see UI_PRECISION_FLOAT_MAX
1450 void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
1452 StructRNA *srna = DefRNA.laststruct;
1456 fprintf(stderr, "%s: \"%s.%s\", min > max.\n",
1457 __func__, srna->identifier, prop->identifier);
1461 if (step < 0 || step > 100) {
1462 fprintf(stderr, "%s: \"%s.%s\", step outside range.\n",
1463 __func__, srna->identifier, prop->identifier);
1467 if (precision < -1 || precision > UI_PRECISION_FLOAT_MAX) {
1468 fprintf(stderr, "%s: \"%s.%s\", precision outside range.\n",
1469 __func__, srna->identifier, prop->identifier);
1474 switch (prop->type) {
1477 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1478 iprop->softmin = (int)min;
1479 iprop->softmax = (int)max;
1480 iprop->step = (int)step;
1485 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1486 fprop->softmin = (float)min;
1487 fprop->softmax = (float)max;
1488 fprop->step = (float)step;
1489 fprop->precision = (int)precision;
1493 fprintf(stderr, "%s: \"%s.%s\", invalid type for ui range.\n",
1494 __func__, srna->identifier, prop->identifier);
1500 void RNA_def_property_range(PropertyRNA *prop, double min, double max)
1502 StructRNA *srna = DefRNA.laststruct;
1506 fprintf(stderr, "%s: \"%s.%s\", min > max.\n",
1507 __func__, srna->identifier, prop->identifier);
1512 switch (prop->type) {
1515 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1516 iprop->hardmin = (int)min;
1517 iprop->hardmax = (int)max;
1518 iprop->softmin = MAX2((int)min, iprop->hardmin);
1519 iprop->softmax = MIN2((int)max, iprop->hardmax);
1524 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1525 fprop->hardmin = (float)min;
1526 fprop->hardmax = (float)max;
1527 fprop->softmin = MAX2((float)min, fprop->hardmin);
1528 fprop->softmax = MIN2((float)max, fprop->hardmax);
1532 fprintf(stderr, "%s: \"%s.%s\", invalid type for range.\n", __func__, srna->identifier, prop->identifier);
1538 void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
1540 StructRNA *srna = DefRNA.laststruct;
1542 if (!DefRNA.preprocess) {
1543 fprintf(stderr, "%s \"%s.%s\": only during preprocessing.\n", __func__, srna->identifier, prop->identifier);
1547 switch (prop->type) {
1550 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1551 pprop->type = (StructRNA *)type;
1554 case PROP_COLLECTION:
1556 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
1557 cprop->item_type = (StructRNA *)type;
1561 fprintf(stderr, "%s: \"%s.%s\", invalid type for struct type.\n",
1562 __func__, srna->identifier, prop->identifier);
1568 void RNA_def_property_struct_runtime(PropertyRNA *prop, StructRNA *type)
1570 StructRNA *srna = DefRNA.laststruct;
1572 if (DefRNA.preprocess) {
1573 fprintf(stderr, "%s: only at runtime.\n", __func__);
1577 switch (prop->type) {
1580 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1583 if (type && (type->flag & STRUCT_ID_REFCOUNT))
1584 prop->flag |= PROP_ID_REFCOUNT;
1588 case PROP_COLLECTION:
1590 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
1591 cprop->item_type = type;
1595 fprintf(stderr, "%s: \"%s.%s\", invalid type for struct type.\n",
1596 __func__, srna->identifier, prop->identifier);
1602 void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
1604 StructRNA *srna = DefRNA.laststruct;
1605 int i, defaultfound = 0;
1607 switch (prop->type) {
1610 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
1611 eprop->item = (EnumPropertyItem *)item;
1613 for (i = 0; item[i].identifier; i++) {
1616 if (item[i].identifier[0] && item[i].value == eprop->defaultvalue)
1620 if (!defaultfound) {
1621 for (i = 0; item[i].identifier; i++) {
1622 if (item[i].identifier[0]) {
1623 eprop->defaultvalue = item[i].value;
1632 fprintf(stderr, "%s: \"%s.%s\", invalid type for struct type.\n",
1633 __func__, srna->identifier, prop->identifier);
1639 void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
1641 StructRNA *srna = DefRNA.laststruct;
1643 switch (prop->type) {
1646 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1647 sprop->maxlength = maxlength;
1651 fprintf(stderr, "%s: \"%s.%s\", type is not string.\n", __func__, srna->identifier, prop->identifier);
1657 void RNA_def_property_boolean_default(PropertyRNA *prop, bool value)
1659 StructRNA *srna = DefRNA.laststruct;
1661 switch (prop->type) {
1664 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1665 BLI_assert(ELEM(value, false, true));
1666 bprop->defaultvalue = value;
1670 fprintf(stderr, "%s: \"%s.%s\", type is not boolean.\n", __func__, srna->identifier, prop->identifier);
1676 void RNA_def_property_boolean_array_default(PropertyRNA *prop, const bool *array)
1678 StructRNA *srna = DefRNA.laststruct;
1680 switch (prop->type) {
1683 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1684 bprop->defaultarray = array;
1688 fprintf(stderr, "%s: \"%s.%s\", type is not boolean.\n", __func__, srna->identifier, prop->identifier);
1694 void RNA_def_property_int_default(PropertyRNA *prop, int value)
1696 StructRNA *srna = DefRNA.laststruct;
1698 switch (prop->type) {
1701 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1702 iprop->defaultvalue = value;
1706 fprintf(stderr, "%s: \"%s.%s\", type is not int.\n", __func__, srna->identifier, prop->identifier);
1712 void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
1714 StructRNA *srna = DefRNA.laststruct;
1716 switch (prop->type) {
1719 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1720 iprop->defaultarray = array;
1724 fprintf(stderr, "%s: \"%s.%s\", type is not int.\n", __func__, srna->identifier, prop->identifier);
1730 void RNA_def_property_float_default(PropertyRNA *prop, float value)
1732 StructRNA *srna = DefRNA.laststruct;
1734 switch (prop->type) {
1737 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1738 fprop->defaultvalue = value;
1742 fprintf(stderr, "%s: \"%s.%s\", type is not float.\n", __func__, srna->identifier, prop->identifier);
1747 /* array must remain valid after this function finishes */
1748 void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
1750 StructRNA *srna = DefRNA.laststruct;
1752 switch (prop->type) {
1755 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1756 fprop->defaultarray = array; /* WARNING, this array must not come from the stack and lost */
1760 fprintf(stderr, "%s: \"%s.%s\", type is not float.\n", __func__, srna->identifier, prop->identifier);
1766 void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
1768 StructRNA *srna = DefRNA.laststruct;
1770 switch (prop->type) {
1773 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1775 if (value == NULL) {
1776 fprintf(stderr, "%s: \"%s.%s\", NULL string passed (dont call in this case).\n", __func__, srna->identifier, prop->identifier);
1782 fprintf(stderr, "%s: \"%s.%s\", empty string passed (dont call in this case).\n", __func__, srna->identifier, prop->identifier);
1788 sprop->defaultvalue = value;
1792 fprintf(stderr, "%s: \"%s.%s\", type is not string.\n", __func__, srna->identifier, prop->identifier);
1798 void RNA_def_property_enum_default(PropertyRNA *prop, int value)
1800 StructRNA *srna = DefRNA.laststruct;
1801 int i, defaultfound = 0;
1803 switch (prop->type) {
1806 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
1807 eprop->defaultvalue = value;
1809 if (prop->flag & PROP_ENUM_FLAG) {
1810 /* check all bits are accounted for */
1812 for (i = 0; i < eprop->totitem; i++) {
1813 if (eprop->item[i].identifier[0]) {
1814 totflag |= eprop->item[i].value;
1818 if (eprop->defaultvalue & ~totflag) {
1819 fprintf(stderr, "%s: \"%s.%s\", default includes unused bits (%d).\n",
1820 __func__, srna->identifier, prop->identifier, eprop->defaultvalue & ~totflag);
1825 for (i = 0; i < eprop->totitem; i++) {
1826 if (eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue)
1830 if (!defaultfound && eprop->totitem) {
1832 eprop->defaultvalue = eprop->item[0].value;
1835 fprintf(stderr, "%s: \"%s.%s\", default is not in items.\n",
1836 __func__, srna->identifier, prop->identifier);
1845 fprintf(stderr, "%s: \"%s.%s\", type is not enum.\n", __func__, srna->identifier, prop->identifier);
1853 static PropertyDefRNA *rna_def_property_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1855 DNAStructMember smember;
1859 dp = rna_find_struct_property_def(DefRNA.laststruct, prop);
1860 if (dp == NULL) return NULL;
1862 ds = rna_find_struct_def((StructRNA *)dp->cont);
1865 structname = ds->dnaname;
1867 propname = prop->identifier;
1869 if (!rna_find_sdna_member(DefRNA.sdna, structname, propname, &smember)) {
1870 if (DefRNA.silent) {
1873 else if (!DefRNA.verify) {
1874 /* some basic values to survive even with sdna info */
1875 dp->dnastructname = structname;
1876 dp->dnaname = propname;
1877 if (prop->type == PROP_BOOLEAN)
1878 dp->dnaarraylength = 1;
1879 if (prop->type == PROP_POINTER)
1880 dp->dnapointerlevel = 1;
1884 fprintf(stderr, "%s: \"%s.%s\" (identifier \"%s\") not found. Struct must be in DNA.\n",
1885 __func__, structname, propname, prop->identifier);
1891 if (smember.arraylength > 1) {
1892 prop->arraylength[0] = smember.arraylength;
1893 prop->totarraylength = smember.arraylength;
1894 prop->arraydimension = 1;
1897 prop->arraydimension = 0;
1898 prop->totarraylength = 0;
1901 dp->dnastructname = structname;
1902 dp->dnastructfromname = ds->dnafromname;
1903 dp->dnastructfromprop = ds->dnafromprop;
1904 dp->dnaname = propname;
1905 dp->dnatype = smember.type;
1906 dp->dnaarraylength = smember.arraylength;
1907 dp->dnapointerlevel = smember.pointerlevel;
1912 void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int bit)
1915 StructRNA *srna = DefRNA.laststruct;
1917 if (!DefRNA.preprocess) {
1918 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
1922 if (prop->type != PROP_BOOLEAN) {
1923 fprintf(stderr, "%s: \"%s.%s\", type is not boolean.\n", __func__, srna->identifier, prop->identifier);
1928 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
1930 if (DefRNA.silent == 0) {
1931 /* error check to ensure floats are not wrapped as ints/bools */
1932 if (dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
1933 fprintf(stderr, "%s: %s.%s is a '%s' but wrapped as type '%s'.\n",
1934 __func__, srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type));
1940 dp->booleanbit = bit;
1944 void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname,
1945 const char *propname, int booleanbit)
1949 RNA_def_property_boolean_sdna(prop, structname, propname, booleanbit);
1951 dp = rna_find_struct_property_def(DefRNA.laststruct, prop);
1954 dp->booleannegative = 1;
1957 void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
1960 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1961 StructRNA *srna = DefRNA.laststruct;
1963 if (!DefRNA.preprocess) {
1964 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
1968 if (prop->type != PROP_INT) {
1969 fprintf(stderr, "%s: \"%s.%s\", type is not int.\n", __func__, srna->identifier, prop->identifier);
1974 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
1976 /* error check to ensure floats are not wrapped as ints/bools */
1977 if (DefRNA.silent == 0) {
1978 if (dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
1979 fprintf(stderr, "%s: %s.%s is a '%s' but wrapped as type '%s'.\n",
1980 __func__, srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type));
1986 /* SDNA doesn't pass us unsigned unfortunately .. */
1987 if (dp->dnatype && STREQ(dp->dnatype, "char")) {
1988 iprop->hardmin = iprop->softmin = CHAR_MIN;
1989 iprop->hardmax = iprop->softmax = CHAR_MAX;
1991 else if (dp->dnatype && STREQ(dp->dnatype, "short")) {
1992 iprop->hardmin = iprop->softmin = SHRT_MIN;
1993 iprop->hardmax = iprop->softmax = SHRT_MAX;
1995 else if (dp->dnatype && STREQ(dp->dnatype, "int")) {
1996 iprop->hardmin = INT_MIN;
1997 iprop->hardmax = INT_MAX;
1999 iprop->softmin = -10000; /* rather arbitrary .. */
2000 iprop->softmax = 10000;
2003 if (prop->subtype == PROP_UNSIGNED || prop->subtype == PROP_PERCENTAGE || prop->subtype == PROP_FACTOR)
2004 iprop->hardmin = iprop->softmin = 0;
2008 void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2011 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2012 StructRNA *srna = DefRNA.laststruct;
2014 if (!DefRNA.preprocess) {
2015 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2019 if (prop->type != PROP_FLOAT) {
2020 fprintf(stderr, "%s: \"%s.%s\", type is not float.\n", __func__, srna->identifier, prop->identifier);
2025 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2026 /* silent is for internal use */
2027 if (DefRNA.silent == 0) {
2028 if (dp->dnatype && *dp->dnatype && IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
2029 if (prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */
2030 fprintf(stderr, "%s: %s.%s is a '%s' but wrapped as type '%s'.\n",
2031 __func__, srna->identifier, prop->identifier, dp->dnatype,
2032 RNA_property_typename(prop->type));
2039 if (dp->dnatype && STREQ(dp->dnatype, "char")) {
2040 fprop->hardmin = fprop->softmin = 0.0f;
2041 fprop->hardmax = fprop->softmax = 1.0f;
2045 rna_def_property_sdna(prop, structname, propname);
2048 void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2050 /* PropertyDefRNA *dp; */
2051 StructRNA *srna = DefRNA.laststruct;
2053 if (!DefRNA.preprocess) {
2054 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2058 if (prop->type != PROP_ENUM) {
2059 fprintf(stderr, "%s: \"%s.%s\", type is not enum.\n", __func__, srna->identifier, prop->identifier);
2064 if ((/* dp= */ rna_def_property_sdna(prop, structname, propname))) {
2065 if (prop->arraydimension) {
2066 prop->arraydimension = 0;
2067 prop->totarraylength = 0;
2069 if (!DefRNA.silent) {
2070 fprintf(stderr, "%s: \"%s.%s\", array not supported for enum type.\n",
2071 __func__, structname, propname);
2078 void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2082 RNA_def_property_enum_sdna(prop, structname, propname);
2084 dp = rna_find_struct_property_def(DefRNA.laststruct, prop);
2087 dp->enumbitflags = 1;
2090 void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2092 /* PropertyDefRNA *dp; */
2093 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2094 StructRNA *srna = DefRNA.laststruct;
2096 if (!DefRNA.preprocess) {
2097 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2101 if (prop->type != PROP_STRING) {
2102 fprintf(stderr, "%s: \"%s.%s\", type is not string.\n", __func__, srna->identifier, prop->identifier);
2107 if ((/* dp= */ rna_def_property_sdna(prop, structname, propname))) {
2108 if (prop->arraydimension) {
2109 sprop->maxlength = prop->totarraylength;
2110 prop->arraydimension = 0;
2111 prop->totarraylength = 0;
2116 void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2118 /* PropertyDefRNA *dp; */
2119 StructRNA *srna = DefRNA.laststruct;
2121 if (!DefRNA.preprocess) {
2122 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2126 if (prop->type != PROP_POINTER) {
2127 fprintf(stderr, "%s: \"%s.%s\", type is not pointer.\n", __func__, srna->identifier, prop->identifier);
2132 if ((/* dp= */ rna_def_property_sdna(prop, structname, propname))) {
2133 if (prop->arraydimension) {
2134 prop->arraydimension = 0;
2135 prop->totarraylength = 0;
2137 if (!DefRNA.silent) {
2138 fprintf(stderr, "%s: \"%s.%s\", array not supported for pointer type.\n",
2139 __func__, structname, propname);
2146 void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname,
2147 const char *lengthpropname)
2150 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
2151 StructRNA *srna = DefRNA.laststruct;
2153 if (!DefRNA.preprocess) {
2154 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2158 if (prop->type != PROP_COLLECTION) {
2159 fprintf(stderr, "%s: \"%s.%s\", type is not collection.\n", __func__, srna->identifier, prop->identifier);
2164 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2165 if (prop->arraydimension && !lengthpropname) {
2166 prop->arraydimension = 0;
2167 prop->totarraylength = 0;
2169 if (!DefRNA.silent) {
2170 fprintf(stderr, "%s: \"%s.%s\", array of collections not supported.\n",
2171 __func__, structname, propname);
2176 if (dp->dnatype && STREQ(dp->dnatype, "ListBase")) {
2177 cprop->next = (PropCollectionNextFunc)"rna_iterator_listbase_next";
2178 cprop->get = (PropCollectionGetFunc)"rna_iterator_listbase_get";
2179 cprop->end = (PropCollectionEndFunc)"rna_iterator_listbase_end";
2183 if (dp && lengthpropname) {
2184 DNAStructMember smember;
2185 StructDefRNA *ds = rna_find_struct_def((StructRNA *)dp->cont);
2188 structname = ds->dnaname;
2190 if (lengthpropname[0] == 0 || rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember)) {
2191 if (lengthpropname[0] == 0) {
2192 dp->dnalengthfixed = prop->totarraylength;
2193 prop->arraydimension = 0;
2194 prop->totarraylength = 0;
2197 dp->dnalengthstructname = structname;
2198 dp->dnalengthname = lengthpropname;
2199 prop->totarraylength = 0;
2202 cprop->next = (PropCollectionNextFunc)"rna_iterator_array_next";
2203 cprop->end = (PropCollectionEndFunc)"rna_iterator_array_end";
2205 if (dp->dnapointerlevel >= 2)
2206 cprop->get = (PropCollectionGetFunc)"rna_iterator_array_dereference_get";
2208 cprop->get = (PropCollectionGetFunc)"rna_iterator_array_get";
2211 if (!DefRNA.silent) {
2212 fprintf(stderr, "%s: \"%s.%s\" not found.\n", __func__, structname, lengthpropname);
2219 void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
2221 prop->translation_context = context ? context : BLT_I18NCONTEXT_DEFAULT_BPYRNA;
2226 void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
2228 if (!DefRNA.preprocess) {
2229 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2233 if (editable) prop->editable = (EditableFunc)editable;
2236 void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable)
2238 if (!DefRNA.preprocess) {
2239 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2243 if (editable) prop->itemeditable = (ItemEditableFunc)editable;
2247 * Set custom callbacks for override operations handling.
2249 * \note \a diff callback will also be used by RNA comparison/equality functions.
2251 void RNA_def_property_override_funcs(PropertyRNA *prop, const char *diff, const char *store, const char *apply)
2253 if (!DefRNA.preprocess) {
2254 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2259 prop->override_diff = (RNAPropOverrideDiff)diff;
2262 prop->override_store = (RNAPropOverrideStore)store;
2265 prop->override_apply = (RNAPropOverrideApply)apply;
2269 void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
2271 if (!DefRNA.preprocess) {
2272 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2276 prop->noteflag = noteflag;
2277 prop->update = (UpdateFunc)func;
2280 void RNA_def_property_update_runtime(PropertyRNA *prop, const void *func)
2282 prop->update = (void *)func;
2285 void RNA_def_property_poll_runtime(PropertyRNA *prop, const void *func)
2287 if (prop->type == PROP_POINTER) {
2288 ((PointerPropertyRNA *)prop)->poll = (void *)func;
2291 fprintf(stderr, "%s: %s is not a Pointer Property.\n", __func__, prop->identifier);
2295 void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
2297 if (!DefRNA.preprocess) {
2298 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2302 if (!(prop->flag & PROP_DYNAMIC)) {
2303 fprintf(stderr, "%s: property is a not dynamic array.\n", __func__);
2308 if (getlength) prop->getlength = (PropArrayLengthGetFunc)getlength;
2311 void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
2313 StructRNA *srna = DefRNA.laststruct;
2315 if (!DefRNA.preprocess) {
2316 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2320 switch (prop->type) {
2323 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2325 if (prop->arraydimension) {
2326 if (get) bprop->getarray = (PropBooleanArrayGetFunc)get;
2327 if (set) bprop->setarray = (PropBooleanArraySetFunc)set;
2330 if (get) bprop->get = (PropBooleanGetFunc)get;
2331 if (set) bprop->set = (PropBooleanSetFunc)set;
2336 fprintf(stderr, "%s: \"%s.%s\", type is not boolean.\n", __func__, srna->identifier, prop->identifier);
2342 void RNA_def_property_boolean_funcs_runtime(PropertyRNA *prop, BooleanPropertyGetFunc getfunc, BooleanPropertySetFunc setfunc)
2344 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2346 if (getfunc) bprop->get_ex = getfunc;
2347 if (setfunc) bprop->set_ex = setfunc;
2349 if (getfunc || setfunc) {
2350 /* don't save in id properties */
2351 prop->flag &= ~PROP_IDPROPERTY;
2354 prop->flag &= ~PROP_EDITABLE;
2358 void RNA_def_property_boolean_array_funcs_runtime(PropertyRNA *prop, BooleanArrayPropertyGetFunc getfunc, BooleanArrayPropertySetFunc setfunc)
2360 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2362 if (getfunc) bprop->getarray_ex = getfunc;
2363 if (setfunc) bprop->setarray_ex = setfunc;
2365 if (getfunc || setfunc) {
2366 /* don't save in id properties */
2367 prop->flag &= ~PROP_IDPROPERTY;
2370 prop->flag &= ~PROP_EDITABLE;
2374 void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
2376 StructRNA *srna = DefRNA.laststruct;
2378 if (!DefRNA.preprocess) {
2379 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2383 switch (prop->type) {
2386 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2388 if (prop->arraydimension) {
2389 if (get) iprop->getarray = (PropIntArrayGetFunc)get;
2390 if (set) iprop->setarray = (PropIntArraySetFunc)set;
2393 if (get) iprop->get = (PropIntGetFunc)get;
2394 if (set) iprop->set = (PropIntSetFunc)set;
2396 if (range) iprop->range = (PropIntRangeFunc)range;
2400 fprintf(stderr, "%s: \"%s.%s\", type is not int.\n", __func__, srna->identifier, prop->identifier);
2406 void RNA_def_property_int_funcs_runtime(PropertyRNA *prop, IntPropertyGetFunc getfunc, IntPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
2408 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2410 if (getfunc) iprop->get_ex = getfunc;
2411 if (setfunc) iprop->set_ex = setfunc;
2412 if (rangefunc) iprop->range_ex = rangefunc;
2414 if (getfunc || setfunc) {
2415 /* don't save in id properties */
2416 prop->flag &= ~PROP_IDPROPERTY;
2419 prop->flag &= ~PROP_EDITABLE;
2423 void RNA_def_property_int_array_funcs_runtime(PropertyRNA *prop, IntArrayPropertyGetFunc getfunc, IntArrayPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
2425 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2427 if (getfunc) iprop->getarray_ex = getfunc;
2428 if (setfunc) iprop->setarray_ex = setfunc;
2429 if (rangefunc) iprop->range_ex = rangefunc;
2431 if (getfunc || setfunc) {
2432 /* don't save in id properties */
2433 prop->flag &= ~PROP_IDPROPERTY;
2436 prop->flag &= ~PROP_EDITABLE;
2440 void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
2442 StructRNA *srna = DefRNA.laststruct;
2444 if (!DefRNA.preprocess) {
2445 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2449 switch (prop->type) {
2452 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2454 if (prop->arraydimension) {
2455 if (get) fprop->getarray = (PropFloatArrayGetFunc)get;
2456 if (set) fprop->setarray = (PropFloatArraySetFunc)set;
2459 if (get) fprop->get = (PropFloatGetFunc)get;
2460 if (set) fprop->set = (PropFloatSetFunc)set;
2462 if (range) fprop->range = (PropFloatRangeFunc)range;
2466 fprintf(stderr, "%s: \"%s.%s\", type is not float.\n", __func__, srna->identifier, prop->identifier);
2472 void RNA_def_property_float_funcs_runtime(PropertyRNA *prop, FloatPropertyGetFunc getfunc, FloatPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc)
2474 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2476 if (getfunc) fprop->get_ex = getfunc;
2477 if (setfunc) fprop->set_ex = setfunc;
2478 if (rangefunc) fprop->range_ex = rangefunc;
2480 if (getfunc || setfunc) {
2481 /* don't save in id properties */
2482 prop->flag &= ~PROP_IDPROPERTY;
2485 prop->flag &= ~PROP_EDITABLE;
2489 void RNA_def_property_float_array_funcs_runtime(PropertyRNA *prop, FloatArrayPropertyGetFunc getfunc, FloatArrayPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc)
2491 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2493 if (getfunc) fprop->getarray_ex = getfunc;
2494 if (setfunc) fprop->setarray_ex = setfunc;
2495 if (rangefunc) fprop->range_ex = rangefunc;
2497 if (getfunc || setfunc) {
2498 /* don't save in id properties */
2499 prop->flag &= ~PROP_IDPROPERTY;
2502 prop->flag &= ~PROP_EDITABLE;
2506 void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
2508 StructRNA *srna = DefRNA.laststruct;
2510 if (!DefRNA.preprocess) {
2511 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2515 switch (prop->type) {
2518 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2520 if (get) eprop->get = (PropEnumGetFunc)get;
2521 if (set) eprop->set = (PropEnumSetFunc)set;
2522 if (item) eprop->itemf = (PropEnumItemFunc)item;
2526 fprintf(stderr, "%s: \"%s.%s\", type is not enum.\n", __func__, srna->identifier, prop->identifier);
2532 void RNA_def_property_enum_funcs_runtime(PropertyRNA *prop, EnumPropertyGetFunc getfunc, EnumPropertySetFunc setfunc, EnumPropertyItemFunc itemfunc)
2534 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2536 if (getfunc) eprop->get_ex = getfunc;
2537 if (setfunc) eprop->set_ex = setfunc;
2538 if (itemfunc) eprop->itemf = itemfunc;
2540 if (getfunc || setfunc) {
2541 /* don't save in id properties */
2542 prop->flag &= ~PROP_IDPROPERTY;
2545 prop->flag &= ~PROP_EDITABLE;
2549 void RNA_def_property_enum_py_data(PropertyRNA *prop, void *py_data)
2551 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2552 eprop->py_data = py_data;
2555 void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
2557 StructRNA *srna = DefRNA.laststruct;
2559 if (!DefRNA.preprocess) {
2560 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2564 switch (prop->type) {
2567 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2569 if (get) sprop->get = (PropStringGetFunc)get;
2570 if (length) sprop->length = (PropStringLengthFunc)length;
2571 if (set) sprop->set = (PropStringSetFunc)set;
2575 fprintf(stderr, "%s: \"%s.%s\", type is not string.\n", __func__, srna->identifier, prop->identifier);
2581 void RNA_def_property_string_funcs_runtime(PropertyRNA *prop, StringPropertyGetFunc getfunc, StringPropertyLengthFunc lengthfunc, StringPropertySetFunc setfunc)
2583 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2585 if (getfunc) sprop->get_ex = getfunc;
2586 if (lengthfunc) sprop->length_ex = lengthfunc;
2587 if (setfunc) sprop->set_ex = setfunc;
2589 if (getfunc || setfunc) {
2590 /* don't save in id properties */
2591 prop->flag &= ~PROP_IDPROPERTY;
2594 prop->flag &= ~PROP_EDITABLE;
2598 void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set,
2599 const char *typef, const char *poll)
2601 StructRNA *srna = DefRNA.laststruct;
2603 if (!DefRNA.preprocess) {
2604 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2608 switch (prop->type) {
2611 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
2613 if (get) pprop->get = (PropPointerGetFunc)get;
2614 if (set) pprop->set = (PropPointerSetFunc)set;
2615 if (typef) pprop->typef = (PropPointerTypeFunc)typef;
2616 if (poll) pprop->poll = (PropPointerPollFunc)poll;
2620 fprintf(stderr, "%s: \"%s.%s\", type is not pointer.\n", __func__, srna->identifier, prop->identifier);
2626 void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end,
2627 const char *get, const char *length, const char *lookupint,
2628 const char *lookupstring, const char *assignint)
2630 StructRNA *srna = DefRNA.laststruct;
2632 if (!DefRNA.preprocess) {
2633 fprintf(stderr, "%s: only during preprocessing.\n", __func__);
2637 switch (prop->type) {
2638 case PROP_COLLECTION:
2640 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
2642 if (begin) cprop->begin = (PropCollectionBeginFunc)begin;
2643 if (next) cprop->next = (PropCollectionNextFunc)next;
2644 if (end) cprop->end = (PropCollectionEndFunc)end;
2645 if (get) cprop->get = (PropCollectionGetFunc)get;
2646 if (length) cprop->length = (PropCollectionLengthFunc)length;
2647 if (lookupint) cprop->lookupint = (PropCollectionLookupIntFunc)lookupint;
2648 if (lookupstring) cprop->lookupstring = (PropCollectionLookupStringFunc)lookupstring;
2649 if (assignint) cprop->assignint = (PropCollectionAssignIntFunc)assignint;
2653 fprintf(stderr, "%s: \"%s.%s\", type is not collection.\n", __func__, srna->identifier, prop->identifier);
2659 void RNA_def_property_srna(PropertyRNA *prop, const char *type)
2661 prop->srna = (StructRNA *)type;
2664 void RNA_def_py_data(PropertyRNA *prop, void *py_data)
2666 prop->py_data = py_data;
2669 /* Compact definitions */
2671 PropertyRNA *RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value,
2672 const char *ui_name, const char *ui_description)
2674 ContainerRNA *cont = cont_;
2677 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
2678 RNA_def_property_boolean_default(prop, default_value);
2679 RNA_def_property_ui_text(prop, ui_name, ui_description);
2684 PropertyRNA *RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *identifier, int len, bool *default_value,
2685 const char *ui_name, const char *ui_description)
2687 ContainerRNA *cont = cont_;
2690 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
2691 if (len != 0) RNA_def_property_array(prop, len);
2692 if (default_value) RNA_def_property_boolean_array_default(prop, default_value);
2693 RNA_def_property_ui_text(prop, ui_name, ui_description);
2698 PropertyRNA *RNA_def_boolean_layer(StructOrFunctionRNA *cont_, const char *identifier, int len, bool *default_value,
2699 const char *ui_name, const char *ui_description)
2701 ContainerRNA *cont = cont_;
2704 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER);
2705 if (len != 0) RNA_def_property_array(prop, len);
2706 if (default_value) RNA_def_property_boolean_array_default(prop, default_value);
2707 RNA_def_property_ui_text(prop, ui_name, ui_description);
2712 PropertyRNA *RNA_def_boolean_layer_member(StructOrFunctionRNA *cont_, const char *identifier, int len,
2713 bool *default_value, const char *ui_name, const char *ui_description)
2715 ContainerRNA *cont = cont_;
2718 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER_MEMBER);
2719 if (len != 0) RNA_def_property_array(prop, len);
2720 if (default_value) RNA_def_property_boolean_array_default(prop, default_value);
2721 RNA_def_property_ui_text(prop, ui_name, ui_description);
2726 PropertyRNA *RNA_def_boolean_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, bool *default_value,
2727 const char *ui_name, const char *ui_description)
2729 ContainerRNA *cont = cont_;
2732 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_XYZ); /* XXX */
2733 if (len != 0) RNA_def_property_array(prop, len);
2734 if (default_value) RNA_def_property_boolean_array_default(prop, default_value);
2735 RNA_def_property_ui_text(prop, ui_name, ui_description);
2740 PropertyRNA *RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, int default_value,
2741 int hardmin, int hardmax, const char *ui_name, const char *ui_description,
2742 int softmin, int softmax)
2744 ContainerRNA *cont = cont_;
2747 ASSERT_SOFT_HARD_LIMITS;
2749 prop = RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
2750 RNA_def_property_int_default(prop, default_value);
2751 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2752 RNA_def_property_ui_text(prop, ui_name, ui_description);
2753 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2758 PropertyRNA *RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value,
2759 int hardmin, int hardmax, const char *ui_name, const char *ui_description,
2760 int softmin, int softmax)
2762 ContainerRNA *cont = cont_;
2765 ASSERT_SOFT_HARD_LIMITS;
2767 prop = RNA_def_property(cont, identifier, PROP_INT, PROP_XYZ); /* XXX */
2768 if (len != 0) RNA_def_property_array(prop, len);
2769 if (default_value) RNA_def_property_int_array_default(prop, default_value);
2770 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2771 RNA_def_property_ui_text(prop, ui_name, ui_description);
2772 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2777 PropertyRNA *RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, int len, const int *default_value,
2778 int hardmin, int hardmax, const char *ui_name, const char *ui_description,
2779 int softmin, int softmax)
2781 ContainerRNA *cont = cont_;
2784 ASSERT_SOFT_HARD_LIMITS;
2786 prop = RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
2787 if (len != 0) RNA_def_property_array(prop, len);
2788 if (default_value) RNA_def_property_int_array_default(prop, default_value);
2789 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2790 RNA_def_property_ui_text(prop, ui_name, ui_description);
2791 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2796 PropertyRNA *RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, int maxlen,
2797 const char *ui_name, const char *ui_description)
2799 ContainerRNA *cont = cont_;
2802 BLI_assert(default_value == NULL || default_value[0]);
2804 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_NONE);
2805 if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2806 if (default_value) RNA_def_property_string_default(prop, default_value);
2807 RNA_def_property_ui_text(prop, ui_name, ui_description);
2812 PropertyRNA *RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value,
2813 int maxlen, const char *ui_name, const char *ui_description)
2815 ContainerRNA *cont = cont_;
2818 BLI_assert(default_value == NULL || default_value[0]);
2820 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_FILEPATH);
2821 if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2822 if (default_value) RNA_def_property_string_default(prop, default_value);
2823 RNA_def_property_ui_text(prop, ui_name, ui_description);
2828 PropertyRNA *RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value,
2829 int maxlen, const char *ui_name, const char *ui_description)
2831 ContainerRNA *cont = cont_;
2834 BLI_assert(default_value == NULL || default_value[0]);
2836 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_DIRPATH);
2837 if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2838 if (default_value) RNA_def_property_string_default(prop, default_value);
2839 RNA_def_property_ui_text(prop, ui_name, ui_description);
2844 PropertyRNA *RNA_def_string_file_name(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value,
2845 int maxlen, const char *ui_name, const char *ui_description)
2847 ContainerRNA *cont = cont_;
2850 BLI_assert(default_value == NULL || default_value[0]);
2852 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_FILENAME);
2853 if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
2854 if (default_value) RNA_def_property_string_default(prop, default_value);
2855 RNA_def_property_ui_text(prop, ui_name, ui_description);
2860 PropertyRNA *RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items,
2861 int default_value, const char *ui_name, const char *ui_description)
2863 ContainerRNA *cont = cont_;
2867 printf("%s: items not allowed to be NULL.\n", __func__);
2871 prop = RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
2872 if (items) RNA_def_property_enum_items(prop, items);
2873 RNA_def_property_enum_default(prop, default_value);
2874 RNA_def_property_ui_text(prop, ui_name, ui_description);
2879 /* same as above but sets 'PROP_ENUM_FLAG' before setting the default value */
2880 PropertyRNA *RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items,
2881 int default_value, const char *ui_name, const char *ui_description)
2883 ContainerRNA *cont = cont_;
2887 printf("%s: items not allowed to be NULL.\n", __func__);
2891 prop = RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
2892 RNA_def_property_flag(prop, PROP_ENUM_FLAG); /* important to run before default set */
2893 if (items) RNA_def_property_enum_items(prop, items);
2894 RNA_def_property_enum_default(prop, default_value);
2895 RNA_def_property_ui_text(prop, ui_name, ui_description);
2900 void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
2902 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2903 eprop->itemf = itemfunc;
2906 PropertyRNA *RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
2907 float hardmin, float hardmax, const char *ui_name, const char *ui_description,
2908 float softmin, float softmax)
2910 ContainerRNA *cont = cont_;
2913 ASSERT_SOFT_HARD_LIMITS;
2915 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
2916 RNA_def_property_float_default(prop, default_value);
2917 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2918 RNA_def_property_ui_text(prop, ui_name, ui_description);
2919 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2924 PropertyRNA *RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len,
2925 const float *default_value, float hardmin, float hardmax, const char *ui_name,
2926 const char *ui_description, float softmin, float softmax)
2928 ContainerRNA *cont = cont_;
2931 ASSERT_SOFT_HARD_LIMITS;
2933 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_XYZ);
2934 if (len != 0) RNA_def_property_array(prop, len);
2935 if (default_value) RNA_def_property_float_array_default(prop, default_value);
2936 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2937 RNA_def_property_ui_text(prop, ui_name, ui_description);
2938 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2943 PropertyRNA *RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, int len,
2944 const float *default_value, float hardmin, float hardmax, const char *ui_name,
2945 const char *ui_description, float softmin, float softmax)
2949 prop = RNA_def_float_vector(cont_, identifier, len, default_value, hardmin, hardmax, ui_name, ui_description,
2951 prop->subtype = PROP_XYZ_LENGTH;
2956 PropertyRNA *RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identifier, int len,
2957 const float *default_value, float hardmin, float hardmax, const char *ui_name,
2958 const char *ui_description, float softmin, float softmax)
2960 ContainerRNA *cont = cont_;
2963 ASSERT_SOFT_HARD_LIMITS;
2965 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_COLOR);
2966 if (len != 0) RNA_def_property_array(prop, len);
2967 if (default_value) RNA_def_property_float_array_default(prop, default_value);
2968 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2969 RNA_def_property_ui_text(prop, ui_name, ui_description);
2970 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2976 PropertyRNA *RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, int rows, int columns,
2977 const float *default_value, float hardmin, float hardmax, const char *ui_name,
2978 const char *ui_description, float softmin, float softmax)
2980 ContainerRNA *cont = cont_;
2982 const int length[2] = {rows, columns};
2984 ASSERT_SOFT_HARD_LIMITS;
2986 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_MATRIX);
2987 RNA_def_property_multi_array(prop, 2, length);
2988 if (default_value) RNA_def_property_float_array_default(prop, default_value);
2989 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
2990 RNA_def_property_ui_text(prop, ui_name, ui_description);
2991 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
2996 PropertyRNA *RNA_def_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, int len,
2997 const float *default_value, float hardmin, float hardmax, const char *ui_name,
2998 const char *ui_description, float softmin, float softmax)
3000 ContainerRNA *cont = cont_;
3003 ASSERT_SOFT_HARD_LIMITS;
3005 prop = RNA_def_property(cont, identifier, PROP_FLOAT, (len >= 3) ? PROP_EULER : PROP_ANGLE);
3007 RNA_def_property_array(prop, len);
3008 if (default_value) RNA_def_property_float_array_default(prop, default_value);
3011 /* RNA_def_property_float_default must be called outside */
3012 BLI_assert(default_value == NULL);
3014 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
3015 RNA_def_property_ui_text(prop, ui_name, ui_description);
3016 RNA_def_property_ui_range(prop, softmin, softmax, 10, 3);
3021 PropertyRNA *RNA_def_float_distance(StructOrFunctionRNA *cont_, const char *identifier,
3022 float default_value, float hardmin, float hardmax, const char *ui_name,
3023 const char *ui_description, float softmin, float softmax)
3025 PropertyRNA *prop = RNA_def_float(cont_, identifier, default_value,
3026 hardmin, hardmax, ui_name, ui_description,
3028 RNA_def_property_subtype(prop, PROP_DISTANCE);
3033 PropertyRNA *RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, int len,
3034 const float *default_value, float hardmin, float hardmax, const char *ui_name,
3035 const char *ui_description, float softmin, float softmax)
3037 ContainerRNA *cont = cont_;
3040 ASSERT_SOFT_HARD_LIMITS;
3042 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
3043 if (len != 0) RNA_def_property_array(prop, len);
3044 if (default_value) RNA_def_property_float_array_default(prop, default_value);
3045 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
3046 RNA_def_property_ui_text(prop, ui_name, ui_description);
3047 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
3052 PropertyRNA *RNA_def_float_percentage(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
3053 float hardmin, float hardmax, const char *ui_name, const char *ui_description,
3054 float softmin, float softmax)
3056 ContainerRNA *cont = cont_;
3059 ASSERT_SOFT_HARD_LIMITS;
3061 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_PERCENTAGE);
3062 RNA_def_property_float_default(prop, default_value);
3063 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
3064 RNA_def_property_ui_text(prop, ui_name, ui_description);
3065 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
3070 PropertyRNA *RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, float default_value,
3071 float hardmin, float hardmax, const char *ui_name, const char *ui_description,
3072 float softmin, float softmax)
3074 ContainerRNA *cont = cont_;
3077 ASSERT_SOFT_HARD_LIMITS;
3079 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_FACTOR);
3080 RNA_def_property_float_default(prop, default_value);
3081 if (hardmin != hardmax) RNA_def_property_range(prop, hardmin, hardmax);
3082 RNA_def_property_ui_text(prop, ui_name, ui_description);
3083 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
3088 PropertyRNA *RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
3089 const char *ui_name, const char *ui_description)
3091 ContainerRNA *cont = cont_;
3094 prop = RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
3095 RNA_def_property_struct_type(prop, type);
3096 RNA_def_property_ui_text(prop, ui_name, ui_description);
3101 PropertyRNA *RNA_def_pointer_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
3102 const char *ui_name, const char *ui_description)
3104 ContainerRNA *cont = cont_;
3107 prop = RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
3108 RNA_def_property_struct_runtime(prop, type);
3109 if ((type->flag & STRUCT_ID) != 0) {
3110 prop->flag |= PROP_EDITABLE;
3112 RNA_def_property_ui_text(prop, ui_name, ui_description);
3117 PropertyRNA *RNA_def_collection(StructOrFunctionRNA *cont_, const char *identifier, const char *type,
3118 const char *ui_name, const char *ui_description)
3120 ContainerRNA *cont = cont_;
3123 prop = RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
3124 RNA_def_property_struct_type(prop, type);
3125 RNA_def_property_ui_text(prop, ui_name, ui_description);
3130 PropertyRNA *RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type,
3131 const char *ui_name, const char *ui_description)
3133 ContainerRNA *cont = cont_;
3136 prop = RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
3137 RNA_def_property_struct_runtime(prop, type);
3138 RNA_def_property_ui_text(prop, ui_name, ui_description);
3145 static FunctionRNA *rna_def_function(StructRNA *srna, const char *identifier)
3148 StructDefRNA *dsrna;
3149 FunctionDefRNA *dfunc;
3151 if (DefRNA.preprocess) {
3154 if (rna_validate_identifier(identifier, error, false) == 0) {
3155 fprintf(stderr, "%s: function identifier \"%s\" - %s\n", __func__, identifier, error);
3160 func = MEM_callocN(sizeof(FunctionRNA), "FunctionRNA");
3161 func->identifier = identifier;
3162 func->description = identifier;
3164 rna_addtail(&srna->functions, func);
3166 if (DefRNA.preprocess) {
3167 dsrna = rna_find_struct_def(srna);
3168 dfunc = MEM_callocN(sizeof(FunctionDefRNA), "FunctionDefRNA");
3169 rna_addtail(&dsrna->functions, dfunc);
3173 func->flag |= FUNC_RUNTIME;
3178 FunctionRNA *RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
3181 FunctionDefRNA *dfunc;
3183 if (BLI_findstring_ptr(&srna->functions, identifier, offsetof(FunctionRNA, identifier))) {
3184 fprintf(stderr, "%s: %s.%s already defined.\n", __func__, srna->identifier, identifier);
3188 func = rna_def_function(srna, identifier);
3190 if (!DefRNA.preprocess) {
3191 fprintf(stderr, "%s: only at preprocess time.\n", __func__);
3195 dfunc = rna_find_function_def(func);
3201 FunctionRNA *RNA_def_function_runtime(StructRNA *srna, const char *identifier, CallFunc call)
3205 func = rna_def_function(srna, identifier);
3207 if (DefRNA.preprocess) {
3208 fprintf(stderr, "%s: only at runtime.\n", __func__);
3218 /* C return value only!, multiple RNA returns can be done with RNA_def_function_output */
3219 void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
3221 if (ret->flag & PROP_DYNAMIC) {
3222 fprintf(stderr, "%s: \"%s.%s\", dynamic values are not allowed as strict returns, "
3223 "use RNA_def_function_output instead.\n", __func__, func->identifier, ret->identifier);
3226 else if (ret->arraydimension) {
3227 fprintf(stderr, "%s: \"%s.%s\", arrays are not allowed as strict returns, "
3228 "use RNA_def_function_output instead.\n", __func__, func->identifier, ret->identifier);
3232 BLI_assert(func->c_ret == NULL);
3235 RNA_def_function_output(func, ret);
3238 void RNA_def_function_output(FunctionRNA *UNUSED(func), PropertyRNA *ret)
3240 ret->flag_parameter |= PARM_OUTPUT;
3243 void RNA_def_function_flag(FunctionRNA *func, int flag)
3248 void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
3250 func->description = description;
3253 int rna_parameter_size(PropertyRNA *parm)