Blender V4.3
rna_define.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cctype>
10#include <cfloat>
11#include <climits>
12#include <cstddef>
13#include <cstdio>
14#include <cstdlib>
15#include <cstring>
16
17#include "BLI_utildefines.h"
18#include "MEM_guardedalloc.h"
19
20#include "DNA_defaults.h"
21#include "DNA_genfile.h"
22#include "DNA_sdna_types.h"
23
24#include "BLI_ghash.h"
25#include "BLI_listbase.h"
26
27#include "BLT_translation.hh"
28
29#include "UI_interface.hh" /* For things like UI_PRECISION_FLOAT_MAX... */
30
31#include "RNA_define.hh"
32
33#include "rna_internal.hh"
34
35#include "CLG_log.h"
36
37static CLG_LogRef LOG = {"rna.define"};
38
39#ifndef NDEBUG
40# define ASSERT_SOFT_HARD_LIMITS \
41 if (softmin < hardmin || softmax > hardmax) { \
42 CLOG_ERROR(&LOG, "error with soft/hard limits: %s.%s", CONTAINER_RNA_ID(cont), identifier); \
43 BLI_assert_msg(0, "invalid soft/hard limits"); \
44 } \
45 (void)0
46#else
47# define ASSERT_SOFT_HARD_LIMITS (void)0
48#endif
49
50/* Global used during defining */
51
53 /*sdna*/ nullptr,
54 /*structs*/ {nullptr, nullptr},
55 /*allocs*/ {nullptr, nullptr},
56 /*laststruct*/ nullptr,
57 /*error*/ false,
58 /*silent*/ false,
59 /*preprocess*/ false,
60 /*verify*/ true,
61 /*animate*/ true,
62 /*make_overridable*/ false,
63};
64
65#ifndef RNA_RUNTIME
66static struct {
69#endif
70
71#ifndef RNA_RUNTIME
76static bool debugSRNA_defaults = false;
77
78static void print_default_info(const PropertyDefRNA *dp)
79{
80 fprintf(stderr,
81 "dna_type=%s, dna_offset=%d, dna_struct=%s, dna_name=%s, id=%s\n",
82 dp->dnatype,
83 dp->dnaoffset,
84 dp->dnastructname,
85 dp->dnaname,
86 dp->prop->identifier);
87}
88#endif /* !RNA_RUNTIME */
89
90void rna_addtail(ListBase *listbase, void *vlink)
91{
92 Link *link = static_cast<Link *>(vlink);
93
94 link->next = nullptr;
95 link->prev = static_cast<Link *>(listbase->last);
96
97 if (listbase->last) {
98 ((Link *)listbase->last)->next = link;
99 }
100 if (listbase->first == nullptr) {
101 listbase->first = link;
102 }
103 listbase->last = link;
104}
105
106static void rna_remlink(ListBase *listbase, void *vlink)
107{
108 Link *link = static_cast<Link *>(vlink);
109
110 if (link->next) {
111 link->next->prev = link->prev;
112 }
113 if (link->prev) {
114 link->prev->next = link->next;
115 }
116
117 if (listbase->last == link) {
118 listbase->last = link->prev;
119 }
120 if (listbase->first == link) {
121 listbase->first = link->next;
122 }
123}
124
125PropertyDefRNA *rna_findlink(ListBase *listbase, const char *identifier)
126{
127 LISTBASE_FOREACH (Link *, link, listbase) {
128 PropertyRNA *prop = ((PropertyDefRNA *)link)->prop;
129 if (prop && STREQ(prop->identifier, identifier)) {
130 return (PropertyDefRNA *)link;
131 }
132 }
133 return nullptr;
134}
135
136void rna_freelinkN(ListBase *listbase, void *vlink)
137{
138 rna_remlink(listbase, vlink);
139 MEM_freeN(vlink);
140}
141
142void rna_freelistN(ListBase *listbase)
143{
144 Link *link, *next;
145
146 for (link = static_cast<Link *>(listbase->first); link; link = next) {
147 next = link->next;
148 MEM_freeN(link);
149 }
150
151 listbase->first = listbase->last = nullptr;
152}
153
155{
156 rna_addtail(&brna->structs, srna);
157 brna->structs_len += 1;
158
159 /* This exception is only needed for pre-processing.
160 * otherwise we don't allow empty names. */
161 if ((srna->flag & STRUCT_PUBLIC_NAMESPACE) && (srna->identifier[0] != '\0')) {
162 BLI_ghash_insert(brna->structs_map, (void *)srna->identifier, srna);
163 }
164}
165
166#ifdef RNA_RUNTIME
167static void rna_brna_structs_remove_and_free(BlenderRNA *brna, StructRNA *srna)
168{
169 if ((srna->flag & STRUCT_PUBLIC_NAMESPACE) && brna->structs_map) {
170 if (srna->identifier[0] != '\0') {
171 BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, nullptr, nullptr);
172 }
173 }
174
175 RNA_def_struct_free_pointers(nullptr, srna);
176
177 if (srna->flag & STRUCT_RUNTIME) {
178 rna_freelinkN(&brna->structs, srna);
179 }
180 brna->structs_len -= 1;
181}
182#endif
183
184static int DNA_struct_find_index_wrapper(const SDNA *sdna, const char *type_name)
185{
187#ifdef RNA_RUNTIME
188 /* We may support this at some point but for now we don't. */
190#else
191 type_name = static_cast<const char *>(BLI_ghash_lookup_default(
192 g_version_data.type_map_static_from_alias, type_name, (void *)type_name));
193#endif
194 return DNA_struct_find_index_without_alias(sdna, type_name);
195}
196
198{
199 StructDefRNA *dsrna;
200
201 if (!DefRNA.preprocess) {
202 /* we should never get here */
203 CLOG_ERROR(&LOG, "only at preprocess time.");
204 return nullptr;
205 }
206
207 dsrna = static_cast<StructDefRNA *>(DefRNA.structs.last);
208 for (; dsrna; dsrna = static_cast<StructDefRNA *>(dsrna->cont.prev)) {
209 if (dsrna->srna == srna) {
210 return dsrna;
211 }
212 }
213
214 return nullptr;
215}
216
218{
219 StructDefRNA *dsrna;
220 PropertyDefRNA *dprop;
221
222 if (!DefRNA.preprocess) {
223 /* we should never get here */
224 CLOG_ERROR(&LOG, "only at preprocess time.");
225 return nullptr;
226 }
227
228 dsrna = rna_find_struct_def(srna);
229 dprop = static_cast<PropertyDefRNA *>(dsrna->cont.properties.last);
230 for (; dprop; dprop = dprop->prev) {
231 if (dprop->prop == prop) {
232 return dprop;
233 }
234 }
235
236 dsrna = static_cast<StructDefRNA *>(DefRNA.structs.last);
237 for (; dsrna; dsrna = static_cast<StructDefRNA *>(dsrna->cont.prev)) {
238 dprop = static_cast<PropertyDefRNA *>(dsrna->cont.properties.last);
239 for (; dprop; dprop = dprop->prev) {
240 if (dprop->prop == prop) {
241 return dprop;
242 }
243 }
244 }
245
246 return nullptr;
247}
248
249#if 0
250static PropertyDefRNA *rna_find_property_def(PropertyRNA *prop)
251{
252 PropertyDefRNA *dprop;
253
254 if (!DefRNA.preprocess) {
255 /* we should never get here */
256 CLOG_ERROR(&LOG, "only at preprocess time.");
257 return nullptr;
258 }
259
261 if (dprop) {
262 return dprop;
263 }
264
265 dprop = rna_find_parameter_def(prop);
266 if (dprop) {
267 return dprop;
268 }
269
270 return nullptr;
271}
272#endif
273
275{
276 StructDefRNA *dsrna;
277 FunctionDefRNA *dfunc;
278
279 if (!DefRNA.preprocess) {
280 /* we should never get here */
281 CLOG_ERROR(&LOG, "only at preprocess time.");
282 return nullptr;
283 }
284
286 dfunc = static_cast<FunctionDefRNA *>(dsrna->functions.last);
287 for (; dfunc; dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.prev)) {
288 if (dfunc->func == func) {
289 return dfunc;
290 }
291 }
292
293 dsrna = static_cast<StructDefRNA *>(DefRNA.structs.last);
294 for (; dsrna; dsrna = static_cast<StructDefRNA *>(dsrna->cont.prev)) {
295 dfunc = static_cast<FunctionDefRNA *>(dsrna->functions.last);
296 for (; dfunc; dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.prev)) {
297 if (dfunc->func == func) {
298 return dfunc;
299 }
300 }
301 }
302
303 return nullptr;
304}
305
307{
308 StructDefRNA *dsrna;
309 FunctionDefRNA *dfunc;
310 PropertyDefRNA *dparm;
311
312 if (!DefRNA.preprocess) {
313 /* we should never get here */
314 CLOG_ERROR(&LOG, "only at preprocess time.");
315 return nullptr;
316 }
317
319 dfunc = static_cast<FunctionDefRNA *>(dsrna->functions.last);
320 for (; dfunc; dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.prev)) {
321 dparm = static_cast<PropertyDefRNA *>(dfunc->cont.properties.last);
322 for (; dparm; dparm = dparm->prev) {
323 if (dparm->prop == parm) {
324 return dparm;
325 }
326 }
327 }
328
329 dsrna = static_cast<StructDefRNA *>(DefRNA.structs.last);
330 for (; dsrna; dsrna = static_cast<StructDefRNA *>(dsrna->cont.prev)) {
331 dfunc = static_cast<FunctionDefRNA *>(dsrna->functions.last);
332 for (; dfunc; dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.prev)) {
333 dparm = static_cast<PropertyDefRNA *>(dfunc->cont.properties.last);
334 for (; dparm; dparm = dparm->prev) {
335 if (dparm->prop == parm) {
336 return dparm;
337 }
338 }
339 }
340 }
341
342 return nullptr;
343}
344
346{
347 StructDefRNA *ds;
348 FunctionDefRNA *dfunc;
349
350 if (!DefRNA.preprocess) {
351 /* we should never get here */
352 CLOG_ERROR(&LOG, "only at preprocess time.");
353 return nullptr;
354 }
355
356 ds = rna_find_struct_def((StructRNA *)cont);
357 if (ds) {
358 return &ds->cont;
359 }
360
361 dfunc = rna_find_function_def((FunctionRNA *)cont);
362 if (dfunc) {
363 return &dfunc->cont;
364 }
365
366 return nullptr;
367}
368
369/* DNA utility function for looking up members */
370
372 const char *type;
373 const char *name;
377 int size;
378};
379
380static int rna_member_cmp(const char *name, const char *oname)
381{
382 int a = 0;
383
384 /* compare without pointer or array part */
385 while (name[0] == '*') {
386 name++;
387 }
388 while (oname[0] == '*') {
389 oname++;
390 }
391
392 while (true) {
393 if (name[a] == '[' && oname[a] == 0) {
394 return 1;
395 }
396 if (name[a] == '[' && oname[a] == '[') {
397 return 1;
398 }
399 if (name[a] == 0) {
400 break;
401 }
402 if (name[a] != oname[a]) {
403 return 0;
404 }
405 a++;
406 }
407 if (name[a] == 0 && oname[a] == '.') {
408 return 2;
409 }
410 if (name[a] == 0 && oname[a] == '-' && oname[a + 1] == '>') {
411 return 3;
412 }
413
414 return (name[a] == oname[a]);
415}
416
417static int rna_find_sdna_member(SDNA *sdna,
418 const char *structname,
419 const char *membername,
420 DNAStructMember *smember,
421 int *offset)
422{
423 const char *dnaname;
424 int b, structnr, cmp;
425
426 if (!DefRNA.preprocess) {
427 CLOG_ERROR(&LOG, "only during preprocessing.");
428 return 0;
429 }
430 structnr = DNA_struct_find_index_wrapper(sdna, structname);
431
432 smember->offset = -1;
433 if (structnr == -1) {
434 *offset = -1;
435 return 0;
436 }
437
438 const SDNA_Struct *struct_info = sdna->structs[structnr];
439 for (int a = 0; a < struct_info->members_num; a++) {
440 const SDNA_StructMember *member = &struct_info->members[a];
441 const int size = DNA_struct_member_size(sdna, member->type_index, member->member_index);
442 dnaname = sdna->alias.members[member->member_index];
443 cmp = rna_member_cmp(dnaname, membername);
444
445 if (cmp == 1) {
446 smember->type = sdna->alias.types[member->type_index];
447 smember->name = dnaname;
448 smember->offset = *offset;
449 smember->size = size;
450
451 if (strstr(membername, "[")) {
452 smember->arraylength = 0;
453 }
454 else {
455 smember->arraylength = DNA_member_array_num(smember->name);
456 }
457
458 smember->pointerlevel = 0;
459 for (b = 0; dnaname[b] == '*'; b++) {
460 smember->pointerlevel++;
461 }
462
463 return 1;
464 }
465 if (cmp == 2) {
466 smember->type = "";
467 smember->name = dnaname;
468 smember->offset = *offset;
469 smember->size = size;
470 smember->pointerlevel = 0;
471 smember->arraylength = 0;
472
473 membername = strstr(membername, ".") + strlen(".");
475 sdna, sdna->alias.types[member->type_index], membername, smember, offset);
476
477 return 1;
478 }
479 if (cmp == 3) {
480 smember->type = "";
481 smember->name = dnaname;
482 smember->offset = *offset;
483 smember->size = size;
484 smember->pointerlevel = 0;
485 smember->arraylength = 0;
486
487 *offset = -1;
488 membername = strstr(membername, "->") + strlen("->");
490 sdna, sdna->alias.types[member->type_index], membername, smember, offset);
491
492 return 1;
493 }
494
495 if (*offset != -1) {
496 *offset += size;
497 }
498 }
499
500 return 0;
501}
502
503static bool rna_validate_identifier(const char *identifier, bool property, const char **r_error)
504{
505 int a = 0;
506
516 static const char *kwlist[] = {
517 /* "False", "None", "True", */
518 "and", "as", "assert", "async", "await", "break", "class", "continue", "def",
519 "del", "elif", "else", "except", "finally", "for", "from", "global", "if",
520 "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass", "raise",
521 "return", "try", "while", "with", "yield", nullptr,
522 };
523
524 if (!isalpha(identifier[0])) {
525 *r_error = "first character failed isalpha() check";
526 return false;
527 }
528
529 for (a = 0; identifier[a]; a++) {
530 if (DefRNA.preprocess && property) {
531 if (isalpha(identifier[a]) && isupper(identifier[a])) {
532 *r_error = "property names must contain lower case characters only";
533 return false;
534 }
535 }
536
537 if (identifier[a] == '_') {
538 continue;
539 }
540
541 if (identifier[a] == ' ') {
542 *r_error = "spaces are not okay in identifier names";
543 return false;
544 }
545
546 if (isalnum(identifier[a]) == 0) {
547 *r_error = "one of the characters failed an isalnum() check and is not an underscore";
548 return false;
549 }
550 }
551
552 for (a = 0; kwlist[a]; a++) {
553 if (STREQ(identifier, kwlist[a])) {
554 *r_error = "this keyword is reserved by Python";
555 return false;
556 }
557 }
558
559 if (property) {
560 static const char *kwlist_prop[] = {
561 /* not keywords but reserved all the same because py uses */
562 "keys",
563 "values",
564 "items",
565 "get",
566 nullptr,
567 };
568
569 for (a = 0; kwlist_prop[a]; a++) {
570 if (STREQ(identifier, kwlist_prop[a])) {
571 *r_error = "this keyword is reserved by Python";
572 return false;
573 }
574 }
575 }
576
577 return true;
578}
579
580void RNA_identifier_sanitize(char *identifier, int property)
581{
582 int a = 0;
583
584 /* list from http://docs.python.org/py3k/reference/lexical_analysis.html#keywords */
585 static const char *kwlist[] = {
586 /* "False", "None", "True", */
587 "and", "as", "assert", "break", "class", "continue", "def", "del",
588 "elif", "else", "except", "finally", "for", "from", "global", "if",
589 "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass",
590 "raise", "return", "try", "while", "with", "yield", nullptr,
591 };
592
593 if (!isalpha(identifier[0])) {
594 /* first character failed isalpha() check */
595 identifier[0] = '_';
596 }
597
598 for (a = 0; identifier[a]; a++) {
599 if (DefRNA.preprocess && property) {
600 if (isalpha(identifier[a]) && isupper(identifier[a])) {
601 /* property names must contain lower case characters only */
602 identifier[a] = tolower(identifier[a]);
603 }
604 }
605
606 if (identifier[a] == '_') {
607 continue;
608 }
609
610 if (identifier[a] == ' ') {
611 /* spaces are not okay in identifier names */
612 identifier[a] = '_';
613 }
614
615 if (isalnum(identifier[a]) == 0) {
616 /* one of the characters failed an isalnum() check and is not an underscore */
617 identifier[a] = '_';
618 }
619 }
620
621 for (a = 0; kwlist[a]; a++) {
622 if (STREQ(identifier, kwlist[a])) {
623 /* this keyword is reserved by python.
624 * just replace the last character by '_' to keep it readable.
625 */
626 identifier[strlen(identifier) - 1] = '_';
627 break;
628 }
629 }
630
631 if (property) {
632 static const char *kwlist_prop[] = {
633 /* not keywords but reserved all the same because py uses */
634 "keys",
635 "values",
636 "items",
637 "get",
638 nullptr,
639 };
640
641 for (a = 0; kwlist_prop[a]; a++) {
642 if (STREQ(identifier, kwlist_prop[a])) {
643 /* this keyword is reserved by python.
644 * just replace the last character by '_' to keep it readable.
645 */
646 identifier[strlen(identifier) - 1] = '_';
647 break;
648 }
649 }
650 }
651}
652
653static bool rna_range_from_int_type(const char *dnatype, int r_range[2])
654{
655 /* Type `char` is unsigned too. */
656 if (STREQ(dnatype, "char") || STREQ(dnatype, "uchar")) {
657 r_range[0] = CHAR_MIN;
658 r_range[1] = CHAR_MAX;
659 return true;
660 }
661 if (STREQ(dnatype, "short")) {
662 r_range[0] = SHRT_MIN;
663 r_range[1] = SHRT_MAX;
664 return true;
665 }
666 if (STREQ(dnatype, "int")) {
667 r_range[0] = INT_MIN;
668 r_range[1] = INT_MAX;
669 return true;
670 }
671 if (STREQ(dnatype, "int8_t")) {
672 r_range[0] = INT8_MIN;
673 r_range[1] = INT8_MAX;
674 return true;
675 }
676 return false;
677}
678
679/* Blender Data Definition */
680
682{
683 BlenderRNA *brna;
684
685 brna = static_cast<BlenderRNA *>(MEM_callocN(sizeof(BlenderRNA), "BlenderRNA"));
686 const char *error_message = nullptr;
687
689 brna->structs_map = BLI_ghash_str_new_ex(__func__, 2048);
690
691 DefRNA.error = false;
692 DefRNA.preprocess = true;
693
694 /* We need both alias and static (on-disk) DNA names. */
695 const bool do_alias = true;
696
697 DefRNA.sdna = DNA_sdna_from_data(DNAstr, DNAlen, false, false, do_alias, &error_message);
698 if (DefRNA.sdna == nullptr) {
699 CLOG_ERROR(&LOG, "Failed to decode SDNA: %s.", error_message);
700 DefRNA.error = true;
701 }
702
703#ifndef RNA_RUNTIME
705 DNA_RENAME_STATIC_FROM_ALIAS, &g_version_data.type_map_static_from_alias, nullptr);
706#endif
707
708 return brna;
709}
710
712{
713 StructDefRNA *ds;
714 FunctionDefRNA *dfunc;
715
717 MEM_freeN(alloc->mem);
718 }
720
721 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
722 ds = static_cast<StructDefRNA *>(ds->cont.next))
723 {
724 for (dfunc = static_cast<FunctionDefRNA *>(ds->functions.first); dfunc;
725 dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.next))
726 {
728 }
729
732 }
733
735
736 if (DefRNA.sdna) {
738 DefRNA.sdna = nullptr;
739 }
740
741 DefRNA.error = false;
742}
743
744void RNA_define_verify_sdna(bool verify)
745{
746 DefRNA.verify = verify;
747}
748
749void RNA_define_lib_overridable(const bool make_overridable)
750{
751 DefRNA.make_overridable = make_overridable;
752}
753
754#ifndef RNA_RUNTIME
755void RNA_define_animate_sdna(bool animate)
756{
757 DefRNA.animate = animate;
758}
759#endif
760
761#ifndef RNA_RUNTIME
762void RNA_define_fallback_property_update(int noteflag, const char *updatefunc)
763{
766}
767#endif
768
770{
771#ifdef RNA_RUNTIME
772 rna_ext->free(rna_ext->data); /* Decrefs the PyObject that the `srna` owns. */
773 RNA_struct_blender_type_set(srna, nullptr); /* FIXME: this gets accessed again. */
774
775 /* nullptr the srna's value so RNA_struct_free won't complain of a leak */
776 RNA_struct_py_type_set(srna, nullptr);
777
778#else
779 (void)srna;
780 (void)rna_ext;
781#endif
782}
783
785{
786#ifdef RNA_RUNTIME
787 FunctionRNA *func, *nextfunc;
788 PropertyRNA *prop, *nextprop;
789 PropertyRNA *parm, *nextparm;
790
791# if 0
792 if (srna->flag & STRUCT_RUNTIME) {
793 if (RNA_struct_py_type_get(srna)) {
794 fprintf(stderr, "%s '%s' freed while holding a Python reference.", srna->identifier);
795 }
796 }
797# endif
798
799 for (prop = static_cast<PropertyRNA *>(srna->cont.properties.first); prop; prop = nextprop) {
800 nextprop = prop->next;
801
803
805 rna_freelinkN(&srna->cont.properties, prop);
806 }
807 }
808
809 for (func = static_cast<FunctionRNA *>(srna->functions.first); func; func = nextfunc) {
810 nextfunc = static_cast<FunctionRNA *>(func->cont.next);
811
812 for (parm = static_cast<PropertyRNA *>(func->cont.properties.first); parm; parm = nextparm) {
813 nextparm = parm->next;
814
816
818 rna_freelinkN(&func->cont.properties, parm);
819 }
820 }
821
823
824 if (func->flag & FUNC_RUNTIME) {
825 rna_freelinkN(&srna->functions, func);
826 }
827 }
828
829 rna_brna_structs_remove_and_free(brna, srna);
830#else
831 UNUSED_VARS(brna, srna);
832#endif
833}
834
836{
837 StructRNA *srna, *nextsrna;
838 FunctionRNA *func;
839
840 BLI_ghash_free(brna->structs_map, nullptr, nullptr);
841 brna->structs_map = nullptr;
842
843 if (DefRNA.preprocess) {
844 RNA_define_free(brna);
845
846 for (srna = static_cast<StructRNA *>(brna->structs.first); srna;
847 srna = static_cast<StructRNA *>(srna->cont.next))
848 {
849 for (func = static_cast<FunctionRNA *>(srna->functions.first); func;
850 func = static_cast<FunctionRNA *>(func->cont.next))
851 {
853 }
854
856 rna_freelistN(&srna->functions);
857 }
858
859 rna_freelistN(&brna->structs);
860
861 MEM_freeN(brna);
862 }
863 else {
864 for (srna = static_cast<StructRNA *>(brna->structs.first); srna; srna = nextsrna) {
865 nextsrna = static_cast<StructRNA *>(srna->cont.next);
866 RNA_struct_free(brna, srna);
867 }
868 }
869
870#ifndef RNA_RUNTIME
871 BLI_ghash_free(g_version_data.type_map_static_from_alias, nullptr, nullptr);
872 g_version_data.type_map_static_from_alias = nullptr;
873#endif
874}
875
877{
878 switch (type) {
879 case PROP_BOOLEAN:
880 return sizeof(BoolPropertyRNA);
881 case PROP_INT:
882 return sizeof(IntPropertyRNA);
883 case PROP_FLOAT:
884 return sizeof(FloatPropertyRNA);
885 case PROP_STRING:
886 return sizeof(StringPropertyRNA);
887 case PROP_ENUM:
888 return sizeof(EnumPropertyRNA);
889 case PROP_POINTER:
890 return sizeof(PointerPropertyRNA);
891 case PROP_COLLECTION:
892 return sizeof(CollectionPropertyRNA);
893 default:
894 return 0;
895 }
896}
897
899{
900 StructDefRNA *ds;
901
902 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
903 ds = static_cast<StructDefRNA *>(ds->cont.next))
904 {
905 if (ds->srna == srna) {
906 return ds;
907 }
908 }
909
910 return nullptr;
911}
912
913StructRNA *RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
914{
915 StructRNA *srna;
916 StructDefRNA *ds = nullptr, *dsfrom = nullptr;
917 PropertyRNA *prop;
918
919 if (DefRNA.preprocess) {
920 const char *error = nullptr;
921
922 if (!rna_validate_identifier(identifier, false, &error)) {
923 CLOG_ERROR(&LOG, "struct identifier \"%s\" error - %s", identifier, error);
924 DefRNA.error = true;
925 }
926 }
927
928 srna = static_cast<StructRNA *>(MEM_callocN(sizeof(StructRNA), "StructRNA"));
929 DefRNA.laststruct = srna;
930
931 if (srnafrom) {
932 /* Copy from struct to derive stuff, a bit clumsy since we can't
933 * use #MEM_dupallocN, data structs may not be allocated but builtin. */
934 memcpy(srna, srnafrom, sizeof(StructRNA));
935 srna->cont.prophash = nullptr;
938 srna->py_type = nullptr;
939
940 srna->base = srnafrom;
941
942 if (DefRNA.preprocess) {
943 dsfrom = rna_find_def_struct(srnafrom);
944 }
945 else {
946 if (srnafrom->flag & STRUCT_PUBLIC_NAMESPACE_INHERIT) {
948 }
949 else {
951 }
952 }
953 }
954
955 srna->identifier = identifier;
956 srna->name = identifier; /* may be overwritten later RNA_def_struct_ui_text */
957 srna->description = "";
958 /* may be overwritten later RNA_def_struct_translation_context */
960 if (!srnafrom) {
961 srna->icon = ICON_DOT;
963 }
964
965 if (DefRNA.preprocess) {
967 }
968
969 rna_brna_structs_add(brna, srna);
970
971 if (DefRNA.preprocess) {
972 ds = static_cast<StructDefRNA *>(MEM_callocN(sizeof(StructDefRNA), "StructDefRNA"));
973 ds->srna = srna;
975
976 if (dsfrom) {
977 ds->dnafromname = dsfrom->dnaname;
978 }
979 }
980
981 /* in preprocess, try to find sdna */
982 if (DefRNA.preprocess) {
983 RNA_def_struct_sdna(srna, srna->identifier);
984 }
985 else {
987 }
988
989 if (srnafrom) {
990 srna->nameproperty = srnafrom->nameproperty;
991 srna->iteratorproperty = srnafrom->iteratorproperty;
992 }
993 else {
994 /* define some builtin properties */
995 prop = RNA_def_property(&srna->cont, "rna_properties", PROP_COLLECTION, PROP_NONE);
997 RNA_def_property_ui_text(prop, "Properties", "RNA property collection");
998
999 if (DefRNA.preprocess) {
1000 RNA_def_property_struct_type(prop, "Property");
1002 "rna_builtin_properties_begin",
1003 "rna_builtin_properties_next",
1004 "rna_iterator_listbase_end",
1005 "rna_builtin_properties_get",
1006 nullptr,
1007 nullptr,
1008 "rna_builtin_properties_lookup_string",
1009 nullptr);
1010 }
1011 else {
1012#ifdef RNA_RUNTIME
1017 cprop->item_type = &RNA_Property;
1018#endif
1019 }
1020
1021 prop = RNA_def_property(&srna->cont, "rna_type", PROP_POINTER, PROP_NONE);
1023 RNA_def_property_ui_text(prop, "RNA", "RNA type definition");
1024
1025 if (DefRNA.preprocess) {
1026 RNA_def_property_struct_type(prop, "Struct");
1027 RNA_def_property_pointer_funcs(prop, "rna_builtin_type_get", nullptr, nullptr, nullptr);
1028 }
1029 else {
1030#ifdef RNA_RUNTIME
1031 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1032 pprop->get = rna_builtin_type_get;
1033 pprop->type = &RNA_Struct;
1034#endif
1035 }
1036 }
1037
1038 return srna;
1039}
1040
1041StructRNA *RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
1042{
1043 StructRNA *srnafrom = nullptr;
1044
1045 /* only use RNA_def_struct() while pre-processing, otherwise use RNA_def_struct_ptr() */
1047
1048 if (from) {
1049 /* find struct to derive from */
1050 /* Inline RNA_struct_find(...) because it won't link from here. */
1051 srnafrom = static_cast<StructRNA *>(BLI_ghash_lookup(brna->structs_map, from));
1052 if (!srnafrom) {
1053 CLOG_ERROR(&LOG, "struct %s not found to define %s.", from, identifier);
1054 DefRNA.error = true;
1055 }
1056 }
1057
1058 return RNA_def_struct_ptr(brna, identifier, srnafrom);
1059}
1060
1061void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
1062{
1063 StructDefRNA *ds;
1064
1065 if (!DefRNA.preprocess) {
1066 CLOG_ERROR(&LOG, "only during preprocessing.");
1067 return;
1068 }
1069
1070 ds = rna_find_def_struct(srna);
1071
1072/* NOTE(@ideasman42): There are far too many structs which initialize without valid DNA struct
1073 * names, this can't be checked without adding an option to disable
1074 * (tested this and it means changes all over). */
1075#if 0
1076 if (DNA_struct_find_index_wrapper(DefRNA.sdna, structname) == -1) {
1077 if (!DefRNA.silent) {
1078 CLOG_ERROR(&LOG, "%s not found.", structname);
1079 DefRNA.error = true;
1080 }
1081 return;
1082 }
1083#endif
1084
1085 ds->dnaname = structname;
1086}
1087
1088void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
1089{
1090 StructDefRNA *ds;
1091
1092 if (!DefRNA.preprocess) {
1093 CLOG_ERROR(&LOG, "only during preprocessing.");
1094 return;
1095 }
1096
1097 ds = rna_find_def_struct(srna);
1098
1099 if (!ds->dnaname) {
1100 CLOG_ERROR(&LOG, "%s base struct must know DNA already.", structname);
1101 return;
1102 }
1103
1104 if (DNA_struct_find_index_wrapper(DefRNA.sdna, structname) == -1) {
1105 if (!DefRNA.silent) {
1106 CLOG_ERROR(&LOG, "%s not found.", structname);
1107 DefRNA.error = true;
1108 }
1109 return;
1110 }
1111
1112 ds->dnafromprop = propname;
1113 ds->dnaname = structname;
1114}
1115
1117{
1118 if (prop->type != PROP_STRING) {
1119 CLOG_ERROR(&LOG, "\"%s.%s\", must be a string property.", srna->identifier, prop->identifier);
1120 DefRNA.error = true;
1121 }
1122 else if (srna->nameproperty != nullptr) {
1123 CLOG_ERROR(
1124 &LOG, "\"%s.%s\", name property is already set.", srna->identifier, prop->identifier);
1125 DefRNA.error = true;
1126 }
1127 else {
1128 srna->nameproperty = prop;
1129 }
1130}
1131
1132void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
1133{
1134 StructRNA *srnafrom;
1135
1136 /* find struct to derive from */
1137 srnafrom = static_cast<StructRNA *>(BLI_ghash_lookup(brna->structs_map, structname));
1138 if (!srnafrom) {
1139 CLOG_ERROR(&LOG, "struct %s not found for %s.", structname, srna->identifier);
1140 DefRNA.error = true;
1141 }
1142
1143 srna->nested = srnafrom;
1144}
1145
1147{
1148 srna->flag |= flag;
1149}
1150
1152{
1153 srna->flag &= ~flag;
1154}
1155
1156void RNA_def_struct_property_tags(StructRNA *srna, const EnumPropertyItem *prop_tag_defines)
1157{
1158 srna->prop_tag_defines = prop_tag_defines;
1159}
1160
1162{
1163 if (!DefRNA.preprocess) {
1164 CLOG_ERROR(&LOG, "only during preprocessing.");
1165 return;
1166 }
1167
1168 if (refine) {
1170 }
1171}
1172
1173void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
1174{
1175 if (!DefRNA.preprocess) {
1176 CLOG_ERROR(&LOG, "only during preprocessing.");
1177 return;
1178 }
1179
1180 if (idproperties) {
1181 srna->idproperties = (IDPropertiesFunc)idproperties;
1182 }
1183}
1184
1186 const char *reg,
1187 const char *unreg,
1188 const char *instance)
1189{
1190 if (!DefRNA.preprocess) {
1191 CLOG_ERROR(&LOG, "only during preprocessing.");
1192 return;
1193 }
1194
1195 if (reg) {
1196 srna->reg = (StructRegisterFunc)reg;
1197 }
1198 if (unreg) {
1199 srna->unreg = (StructUnregisterFunc)unreg;
1200 }
1201 if (instance) {
1202 srna->instance = (StructInstanceFunc)instance;
1203 }
1204}
1205
1206void RNA_def_struct_path_func(StructRNA *srna, const char *path)
1207{
1208 if (!DefRNA.preprocess) {
1209 CLOG_ERROR(&LOG, "only during preprocessing.");
1210 return;
1211 }
1212
1213 if (path) {
1214 srna->path = (StructPathFunc)path;
1215 }
1216}
1217
1218void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
1219{
1220 if (DefRNA.preprocess) {
1221 CLOG_ERROR(&LOG, "only at runtime.");
1222 return;
1223 }
1224
1225 /* Operator registration may set twice, see: operator_properties_init */
1226 if (srna->flag & STRUCT_PUBLIC_NAMESPACE) {
1227 if (identifier != srna->identifier) {
1228 if (srna->identifier[0] != '\0') {
1229 BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, nullptr, nullptr);
1230 }
1231 if (identifier[0] != '\0') {
1232 BLI_ghash_insert(brna->structs_map, (void *)identifier, srna);
1233 }
1234 }
1235 }
1236
1237 srna->identifier = identifier;
1238}
1239
1240void RNA_def_struct_identifier_no_struct_map(StructRNA *srna, const char *identifier)
1241{
1242 if (DefRNA.preprocess) {
1243 CLOG_ERROR(&LOG, "only at runtime.");
1244 return;
1245 }
1246
1247 srna->identifier = identifier;
1248}
1249
1250void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
1251{
1252 srna->name = name;
1253 srna->description = description;
1254}
1255
1257{
1258 srna->icon = icon;
1259}
1260
1261void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
1262{
1263 srna->translation_context = context ? context : BLT_I18NCONTEXT_DEFAULT_BPYRNA;
1264}
1265
1266/* Property Definition */
1267
1269 const char *identifier,
1270 int type,
1271 int subtype)
1272{
1273 // StructRNA *srna = DefRNA.laststruct; /* Invalid for Python defined props. */
1274 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
1275 ContainerDefRNA *dcont;
1276 PropertyDefRNA *dprop = nullptr;
1277 PropertyRNA *prop;
1278
1279 if (DefRNA.preprocess) {
1280 const char *error = nullptr;
1281
1282 if (!rna_validate_identifier(identifier, true, &error)) {
1283 CLOG_ERROR(
1284 &LOG, "property identifier \"%s.%s\" - %s", CONTAINER_RNA_ID(cont), identifier, error);
1285 DefRNA.error = true;
1286 }
1287
1288 dcont = rna_find_container_def(cont);
1289
1290 /* TODO: detect super-type collisions. */
1291 if (rna_findlink(&dcont->properties, identifier)) {
1292 CLOG_ERROR(&LOG, "duplicate identifier \"%s.%s\"", CONTAINER_RNA_ID(cont), identifier);
1293 DefRNA.error = true;
1294 }
1295
1296 dprop = static_cast<PropertyDefRNA *>(MEM_callocN(sizeof(PropertyDefRNA), "PropertyDefRNA"));
1297 rna_addtail(&dcont->properties, dprop);
1298 }
1299 else {
1300#ifndef NDEBUG
1301 const char *error = nullptr;
1302 if (!rna_validate_identifier(identifier, true, &error)) {
1303 CLOG_ERROR(&LOG,
1304 "runtime property identifier \"%s.%s\" - %s",
1305 CONTAINER_RNA_ID(cont),
1306 identifier,
1307 error);
1308 DefRNA.error = true;
1309 }
1310#endif
1311 }
1312
1313 prop = static_cast<PropertyRNA *>(
1314 MEM_callocN(rna_property_type_sizeof(PropertyType(type)), "PropertyRNA"));
1315
1316 switch (type) {
1317 case PROP_BOOLEAN:
1318 if (DefRNA.preprocess) {
1319 if ((subtype & ~PROP_LAYER_MEMBER) != PROP_NONE) {
1320 CLOG_ERROR(&LOG,
1321 "subtype does not apply to 'PROP_BOOLEAN' \"%s.%s\"",
1322 CONTAINER_RNA_ID(cont),
1323 identifier);
1324 DefRNA.error = true;
1325 }
1326 }
1327 break;
1328 case PROP_INT: {
1329 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1330
1331#ifndef RNA_RUNTIME
1332 if (subtype == PROP_DISTANCE) {
1333 CLOG_ERROR(&LOG,
1334 "subtype does not apply to 'PROP_INT' \"%s.%s\"",
1335 CONTAINER_RNA_ID(cont),
1336 identifier);
1337 DefRNA.error = true;
1338 }
1339#endif
1340
1341 iprop->hardmin = (subtype == PROP_UNSIGNED) ? 0 : INT_MIN;
1342 iprop->hardmax = INT_MAX;
1343
1344 iprop->softmin = (subtype == PROP_UNSIGNED) ? 0 : -10000; /* rather arbitrary. */
1345 iprop->softmax = 10000;
1346 iprop->step = 1;
1347 break;
1348 }
1349 case PROP_FLOAT: {
1350 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1351
1352 fprop->hardmin = (subtype == PROP_UNSIGNED) ? 0.0f : -FLT_MAX;
1353 fprop->hardmax = FLT_MAX;
1354
1355 if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1356 fprop->softmin = fprop->hardmin = 0.0f;
1357 fprop->softmax = 1.0f;
1358 }
1359 else if (subtype == PROP_FACTOR) {
1360 fprop->softmin = fprop->hardmin = 0.0f;
1361 fprop->softmax = fprop->hardmax = 1.0f;
1362 }
1363 else {
1364 fprop->softmin = (subtype == PROP_UNSIGNED) ? 0.0f : -10000.0f; /* rather arbitrary. */
1365 fprop->softmax = 10000.0f;
1366 }
1367 fprop->step = 10;
1368 fprop->precision = 3;
1369 break;
1370 }
1371 case PROP_STRING: {
1372 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1373 /* By default don't allow nullptr string args, callers may clear.
1374 * Used so generated 'get/length/set' functions skip a nullptr check
1375 * in some cases we want it */
1377 sprop->defaultvalue = "";
1378 break;
1379 }
1380 case PROP_POINTER:
1381 /* needed for default behavior when PARM_RNAPTR is set */
1383 break;
1384 case PROP_ENUM:
1385 case PROP_COLLECTION:
1386 break;
1387 default:
1388 CLOG_ERROR(&LOG, "\"%s.%s\", invalid property type.", CONTAINER_RNA_ID(cont), identifier);
1389 DefRNA.error = true;
1390 return nullptr;
1391 }
1392
1393 if (DefRNA.preprocess) {
1394 dprop->cont = cont;
1395 dprop->prop = prop;
1396 }
1397
1398 prop->magic = RNA_MAGIC;
1399 prop->identifier = identifier;
1400 prop->type = PropertyType(type);
1401 prop->subtype = PropertySubType(subtype);
1402 prop->name = identifier;
1403 prop->description = "";
1405 /* a priori not raw editable */
1406 prop->rawtype = RawPropertyType(-1);
1407
1408 if (!ELEM(type, PROP_COLLECTION, PROP_POINTER)) {
1410
1411 if (type != PROP_STRING) {
1412#ifdef RNA_RUNTIME
1414#else
1415 if (DefRNA.animate) {
1417 }
1418#endif
1419 }
1420 }
1421
1422#ifndef RNA_RUNTIME
1425 }
1426#endif
1427
1428 if (DefRNA.preprocess) {
1429 switch (type) {
1430 case PROP_BOOLEAN:
1431 DefRNA.silent = true;
1432 RNA_def_property_boolean_sdna(prop, nullptr, identifier, 0);
1433 DefRNA.silent = false;
1434 break;
1435 case PROP_INT: {
1436 DefRNA.silent = true;
1437 RNA_def_property_int_sdna(prop, nullptr, identifier);
1438 DefRNA.silent = false;
1439 break;
1440 }
1441 case PROP_FLOAT: {
1442 DefRNA.silent = true;
1443 RNA_def_property_float_sdna(prop, nullptr, identifier);
1444 DefRNA.silent = false;
1445 break;
1446 }
1447 case PROP_STRING: {
1448 DefRNA.silent = true;
1449 RNA_def_property_string_sdna(prop, nullptr, identifier);
1450 DefRNA.silent = false;
1451 break;
1452 }
1453 case PROP_ENUM:
1454 DefRNA.silent = true;
1455 RNA_def_property_enum_sdna(prop, nullptr, identifier);
1456 DefRNA.silent = false;
1457 break;
1458 case PROP_POINTER:
1459 DefRNA.silent = true;
1460 RNA_def_property_pointer_sdna(prop, nullptr, identifier);
1461 DefRNA.silent = false;
1462 break;
1463 case PROP_COLLECTION:
1464 DefRNA.silent = true;
1465 RNA_def_property_collection_sdna(prop, nullptr, identifier, nullptr);
1466 DefRNA.silent = false;
1467 break;
1468 }
1469 }
1470 else {
1473#ifdef RNA_RUNTIME
1474 if (cont->prophash) {
1475 BLI_ghash_insert(cont->prophash, (void *)prop->identifier, prop);
1476 }
1477#endif
1478 }
1479
1480#ifndef RNA_RUNTIME
1481 /* Both are typically cleared. */
1484#endif
1485
1486 rna_addtail(&cont->properties, prop);
1487
1488 return prop;
1489}
1490
1492{
1493 prop->flag |= flag;
1494}
1495
1497{
1498 prop->flag &= ~flag;
1501 }
1502}
1503
1508
1513
1515{
1516 prop->tags |= tags;
1517}
1518
1520 PropertyFlag flag_property,
1521 ParameterFlag flag_parameter)
1522{
1523 prop->flag |= flag_property;
1524 prop->flag_parameter |= flag_parameter;
1525}
1526
1528 PropertyFlag flag_property,
1529 ParameterFlag flag_parameter)
1530{
1531 prop->flag &= ~flag_property;
1532 prop->flag_parameter &= ~flag_parameter;
1533}
1534
1536{
1537 prop->subtype = subtype;
1538}
1539
1541{
1542 StructRNA *srna = DefRNA.laststruct;
1543
1544 if (length < 0) {
1545 CLOG_ERROR(&LOG,
1546 "\"%s.%s\", array length must be zero of greater.",
1547 srna->identifier,
1548 prop->identifier);
1549 DefRNA.error = true;
1550 return;
1551 }
1552
1553 if (length > RNA_MAX_ARRAY_LENGTH) {
1554 CLOG_ERROR(&LOG,
1555 "\"%s.%s\", array length must be smaller than %d.",
1556 srna->identifier,
1557 prop->identifier,
1559 DefRNA.error = true;
1560 return;
1561 }
1562
1563 if (prop->arraydimension > 1) {
1564 CLOG_ERROR(&LOG,
1565 "\"%s.%s\", array dimensions has been set to %u but would be overwritten as 1.",
1566 srna->identifier,
1567 prop->identifier,
1568 prop->arraydimension);
1569 DefRNA.error = true;
1570 return;
1571 }
1572
1573 switch (prop->type) {
1574 case PROP_BOOLEAN:
1575 case PROP_INT:
1576 case PROP_FLOAT:
1577 prop->arraylength[0] = length;
1578 prop->totarraylength = length;
1579 prop->arraydimension = 1;
1580 break;
1581 default:
1582 CLOG_ERROR(&LOG,
1583 "\"%s.%s\", only boolean/int/float can be array.",
1584 srna->identifier,
1585 prop->identifier);
1586 DefRNA.error = true;
1587 break;
1588 }
1589}
1590
1591const float rna_default_quaternion[4] = {1, 0, 0, 0};
1592const float rna_default_axis_angle[4] = {0, 0, 1, 0};
1593const float rna_default_scale_3d[3] = {1, 1, 1};
1594
1595const int rna_matrix_dimsize_3x3[] = {3, 3};
1596const int rna_matrix_dimsize_4x4[] = {4, 4};
1597const int rna_matrix_dimsize_4x2[] = {4, 2};
1598
1599void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
1600{
1601 StructRNA *srna = DefRNA.laststruct;
1602 int i;
1603
1604 if (dimension < 1 || dimension > RNA_MAX_ARRAY_DIMENSION) {
1605 CLOG_ERROR(&LOG,
1606 "\"%s.%s\", array dimension must be between 1 and %d.",
1607 srna->identifier,
1608 prop->identifier,
1610 DefRNA.error = true;
1611 return;
1612 }
1613
1614 switch (prop->type) {
1615 case PROP_BOOLEAN:
1616 case PROP_INT:
1617 case PROP_FLOAT:
1618 break;
1619 default:
1620 CLOG_ERROR(&LOG,
1621 "\"%s.%s\", only boolean/int/float can be array.",
1622 srna->identifier,
1623 prop->identifier);
1624 DefRNA.error = true;
1625 break;
1626 }
1627
1628 prop->arraydimension = dimension;
1629 prop->totarraylength = 0;
1630
1631 if (length) {
1632 memcpy(prop->arraylength, length, sizeof(int) * dimension);
1633
1634 prop->totarraylength = length[0];
1635 for (i = 1; i < dimension; i++) {
1636 prop->totarraylength *= length[i];
1637 }
1638 }
1639 else {
1640 memset(prop->arraylength, 0, sizeof(prop->arraylength));
1641 }
1642
1643 /* TODO: make sure `arraylength` values are sane. */
1644}
1645
1646void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
1647{
1648 prop->name = name;
1649 prop->description = description;
1650}
1651
1652void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
1653{
1654 prop->icon = icon;
1655 if (consecutive != 0) {
1657 }
1658 if (consecutive < 0) {
1660 }
1661}
1662
1664 PropertyRNA *prop, double min, double max, double step, int precision)
1665{
1666 StructRNA *srna = DefRNA.laststruct;
1667
1668#ifndef NDEBUG
1669 if (min > max) {
1670 CLOG_ERROR(&LOG, "\"%s.%s\", min > max.", srna->identifier, prop->identifier);
1671 DefRNA.error = true;
1672 }
1673
1674 if (step < 0 || step > 100) {
1675 CLOG_ERROR(&LOG, "\"%s.%s\", step outside range.", srna->identifier, prop->identifier);
1676 DefRNA.error = true;
1677 }
1678
1679 if (step == 0) {
1680 CLOG_ERROR(&LOG, "\"%s.%s\", step is zero.", srna->identifier, prop->identifier);
1681 DefRNA.error = true;
1682 }
1683
1684 if (precision < -1 || precision > UI_PRECISION_FLOAT_MAX) {
1685 CLOG_ERROR(&LOG, "\"%s.%s\", precision outside range.", srna->identifier, prop->identifier);
1686 DefRNA.error = true;
1687 }
1688#endif
1689
1690 switch (prop->type) {
1691 case PROP_INT: {
1692 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1693 iprop->softmin = int(min);
1694 iprop->softmax = int(max);
1695 iprop->step = int(step);
1696 break;
1697 }
1698 case PROP_FLOAT: {
1699 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1700 fprop->softmin = float(min);
1701 fprop->softmax = float(max);
1702 fprop->step = float(step);
1703 fprop->precision = int(precision);
1704 break;
1705 }
1706 default:
1707 CLOG_ERROR(
1708 &LOG, "\"%s.%s\", invalid type for ui range.", srna->identifier, prop->identifier);
1709 DefRNA.error = true;
1710 break;
1711 }
1712}
1713
1715{
1716 StructRNA *srna = DefRNA.laststruct;
1717
1718 switch (prop->type) {
1719 case PROP_INT: {
1720 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1721 iprop->ui_scale_type = ui_scale_type;
1722 break;
1723 }
1724 case PROP_FLOAT: {
1725 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1726 fprop->ui_scale_type = ui_scale_type;
1727 break;
1728 }
1729 default:
1730 CLOG_ERROR(&LOG, "\"%s.%s\", invalid type for scale.", srna->identifier, prop->identifier);
1731 DefRNA.error = true;
1732 break;
1733 }
1734}
1735
1736void RNA_def_property_range(PropertyRNA *prop, double min, double max)
1737{
1738 StructRNA *srna = DefRNA.laststruct;
1739
1740#ifndef NDEBUG
1741 if (min > max) {
1742 CLOG_ERROR(&LOG, "\"%s.%s\", min > max.", srna->identifier, prop->identifier);
1743 DefRNA.error = true;
1744 }
1745#endif
1746
1747 switch (prop->type) {
1748 case PROP_INT: {
1749 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1750 iprop->hardmin = int(min);
1751 iprop->hardmax = int(max);
1752 iprop->softmin = std::max(int(min), iprop->hardmin);
1753 iprop->softmax = std::min(int(max), iprop->hardmax);
1754 break;
1755 }
1756 case PROP_FLOAT: {
1757 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1758 fprop->hardmin = float(min);
1759 fprop->hardmax = float(max);
1760 fprop->softmin = std::max(float(min), fprop->hardmin);
1761 fprop->softmax = std::min(float(max), fprop->hardmax);
1762 break;
1763 }
1764 default:
1765 CLOG_ERROR(&LOG, "\"%s.%s\", invalid type for range.", srna->identifier, prop->identifier);
1766 DefRNA.error = true;
1767 break;
1768 }
1769}
1770
1771void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
1772{
1773 StructRNA *srna = DefRNA.laststruct;
1774
1775 if (!DefRNA.preprocess) {
1776 fprintf(stderr, "\"%s.%s\": only during preprocessing.", srna->identifier, prop->identifier);
1777 return;
1778 }
1779
1780 switch (prop->type) {
1781 case PROP_POINTER: {
1782 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1783 pprop->type = (StructRNA *)type;
1784 break;
1785 }
1786 case PROP_COLLECTION: {
1788 cprop->item_type = (StructRNA *)type;
1789 break;
1790 }
1791 default:
1792 CLOG_ERROR(
1793 &LOG, "\"%s.%s\", invalid type for struct type.", srna->identifier, prop->identifier);
1794 DefRNA.error = true;
1795 break;
1796 }
1797}
1798
1800{
1801 /* Never valid when defined from python. */
1802 StructRNA *srna = DefRNA.laststruct;
1803
1804 if (DefRNA.preprocess) {
1805 CLOG_ERROR(&LOG, "only at runtime.");
1806 return;
1807 }
1808
1809 const bool is_id_type = (type->flag & STRUCT_ID) != 0;
1810
1811 switch (prop->type) {
1812 case PROP_POINTER: {
1813 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1814 pprop->type = type;
1815
1816 /* Check between `cont` and `srna` is mandatory, since when defined from python
1817 * `DefRNA.laststruct` is not valid.
1818 * This is not an issue as bpy code already checks for this case on its own. */
1819 if (cont == srna && (srna->flag & STRUCT_NO_DATABLOCK_IDPROPERTIES) != 0 && is_id_type) {
1820 CLOG_ERROR(&LOG,
1821 "\"%s.%s\", this struct type (probably an Operator, Keymap or UserPreference) "
1822 "does not accept ID pointer properties.",
1823 CONTAINER_RNA_ID(cont),
1824 prop->identifier);
1825 DefRNA.error = true;
1826 return;
1827 }
1828
1829 if (type && (type->flag & STRUCT_ID_REFCOUNT)) {
1831 }
1832
1833 break;
1834 }
1835 case PROP_COLLECTION: {
1837 cprop->item_type = type;
1838 break;
1839 }
1840 default:
1841 CLOG_ERROR(&LOG,
1842 "\"%s.%s\", invalid type for struct type.",
1843 CONTAINER_RNA_ID(cont),
1844 prop->identifier);
1845 DefRNA.error = true;
1846 return;
1847 }
1848
1849 if (is_id_type) {
1851 }
1852}
1853
1854void RNA_def_property_enum_native_type(PropertyRNA *prop, const char *native_enum_type)
1855{
1856 StructRNA *srna = DefRNA.laststruct;
1857 switch (prop->type) {
1858 case PROP_ENUM: {
1859 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
1860 eprop->native_enum_type = native_enum_type;
1861 break;
1862 }
1863 default:
1864 CLOG_ERROR(
1865 &LOG, "\"%s.%s\", invalid type for struct type.", srna->identifier, prop->identifier);
1866 DefRNA.error = true;
1867 break;
1868 }
1869}
1870
1872{
1873 StructRNA *srna = DefRNA.laststruct;
1874 int i, defaultfound = 0;
1875
1876 switch (prop->type) {
1877 case PROP_ENUM: {
1878
1879 /* Access DNA size & range (for additional sanity checks). */
1880 int enum_dna_size = -1;
1881 int enum_dna_range[2];
1882 if (DefRNA.preprocess) {
1883 /* If this is larger, this is likely a string which can sometimes store enums. */
1884 if (PropertyDefRNA *dp = rna_find_struct_property_def(srna, prop)) {
1885 if (dp->dnatype == nullptr || dp->dnatype[0] == '\0') {
1886 /* Unfortunately this happens when #PropertyDefRNA::dnastructname is for e.g.
1887 * `type->region_type` there isn't a convenient way to access the int size. */
1888 }
1889 else if (dp->dnaarraylength > 1) {
1890 /* When an array this is likely a string using get/set functions for enum access. */
1891 }
1892 else if (dp->dnasize == 0) {
1893 /* Some cases function callbacks are used, the DNA size isn't known. */
1894 }
1895 else {
1896 enum_dna_size = dp->dnasize;
1897 if (!rna_range_from_int_type(dp->dnatype, enum_dna_range)) {
1898 CLOG_ERROR(&LOG,
1899 "\"%s.%s\", enum type \"%s\" size is not known.",
1900 srna->identifier,
1901 prop->identifier,
1902 dp->dnatype);
1903 }
1904 }
1905 }
1906 }
1907
1908 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
1909 eprop->item = (EnumPropertyItem *)item;
1910 eprop->totitem = 0;
1911 for (i = 0; item[i].identifier; i++) {
1912 eprop->totitem++;
1913
1914 if (item[i].identifier[0]) {
1915 /* Don't allow spaces in internal enum items (it's fine for Python ones). */
1916 if (DefRNA.preprocess && strstr(item[i].identifier, " ")) {
1917 CLOG_ERROR(&LOG,
1918 "\"%s.%s\", enum identifiers must not contain spaces.",
1919 srna->identifier,
1920 prop->identifier);
1921 DefRNA.error = true;
1922 break;
1923 }
1924
1925 /* When the integer size is known, check the flag wont fit. */
1926 if (enum_dna_size != -1) {
1927 if (prop->flag & PROP_ENUM_FLAG) {
1928 uint32_t enum_type_mask = 0;
1929 if (enum_dna_size == 1) {
1930 enum_type_mask = 0xff;
1931 }
1932 else if (enum_dna_size == 2) {
1933 enum_type_mask = 0xffff;
1934 }
1935 if (enum_type_mask != 0) {
1936 if (uint32_t(item[i].value) != (uint32_t(item[i].value) & enum_type_mask)) {
1937 CLOG_ERROR(&LOG,
1938 "\"%s.%s\", enum value for '%s' does not fit into %d byte(s).",
1939 srna->identifier,
1940 prop->identifier,
1941 item[i].identifier,
1942 enum_dna_size);
1943 DefRNA.error = true;
1944 break;
1945 }
1946 }
1947 }
1948 else {
1949 if (ELEM(enum_dna_size, 1, 2)) {
1950 if ((item[i].value < enum_dna_range[0]) || (item[i].value > enum_dna_range[1])) {
1951 CLOG_ERROR(&LOG,
1952 "\"%s.%s\", enum value for '%s' is outside of range [%d - %d].",
1953 srna->identifier,
1954 prop->identifier,
1955 item[i].identifier,
1956 enum_dna_range[0],
1957 enum_dna_range[1]);
1958 DefRNA.error = true;
1959 break;
1960 }
1961 }
1962 }
1963 }
1964
1965 if (item[i].value == eprop->defaultvalue) {
1966 defaultfound = 1;
1967 }
1968 }
1969 }
1970
1971 if (!defaultfound) {
1972 for (i = 0; item[i].identifier; i++) {
1973 if (item[i].identifier[0]) {
1974 eprop->defaultvalue = item[i].value;
1975 break;
1976 }
1977 }
1978 }
1979
1980 break;
1981 }
1982 default:
1983 CLOG_ERROR(
1984 &LOG, "\"%s.%s\", invalid type for struct type.", srna->identifier, prop->identifier);
1985 DefRNA.error = true;
1986 break;
1987 }
1988}
1989
1991{
1992 StructRNA *srna = DefRNA.laststruct;
1993
1994 switch (prop->type) {
1995 case PROP_STRING: {
1996 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1997 sprop->maxlength = maxlength;
1998 break;
1999 }
2000 default:
2001 CLOG_ERROR(&LOG, "\"%s.%s\", type is not string.", srna->identifier, prop->identifier);
2002 DefRNA.error = true;
2003 break;
2004 }
2005}
2006
2008{
2009 StructRNA *srna = DefRNA.laststruct;
2010
2011 switch (prop->type) {
2012 case PROP_BOOLEAN: {
2013 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2014 BLI_assert(ELEM(value, false, true));
2015#ifndef RNA_RUNTIME
2016 /* Default may be set from items. */
2017 if (bprop->defaultvalue) {
2018 CLOG_ERROR(&LOG, "\"%s.%s\", set from DNA.", srna->identifier, prop->identifier);
2019 }
2020#endif
2021 bprop->defaultvalue = value;
2022 break;
2023 }
2024 default:
2025 CLOG_ERROR(&LOG, "\"%s.%s\", type is not boolean.", srna->identifier, prop->identifier);
2026 DefRNA.error = true;
2027 break;
2028 }
2029}
2030
2032{
2033 StructRNA *srna = DefRNA.laststruct;
2034
2035 switch (prop->type) {
2036 case PROP_BOOLEAN: {
2037 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2038 bprop->defaultarray = array;
2039 break;
2040 }
2041 default:
2042 CLOG_ERROR(&LOG, "\"%s.%s\", type is not boolean.", srna->identifier, prop->identifier);
2043 DefRNA.error = true;
2044 break;
2045 }
2046}
2047
2049{
2050 StructRNA *srna = DefRNA.laststruct;
2051
2052 switch (prop->type) {
2053 case PROP_INT: {
2054 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2055#ifndef RNA_RUNTIME
2056 if (iprop->defaultvalue != 0) {
2057 CLOG_ERROR(&LOG, "\"%s.%s\", set from DNA.", srna->identifier, prop->identifier);
2058 }
2059#endif
2060 iprop->defaultvalue = value;
2061 break;
2062 }
2063 default:
2064 CLOG_ERROR(&LOG, "\"%s.%s\", type is not int.", srna->identifier, prop->identifier);
2065 DefRNA.error = true;
2066 break;
2067 }
2068}
2069
2071{
2072 StructRNA *srna = DefRNA.laststruct;
2073
2074 switch (prop->type) {
2075 case PROP_INT: {
2076 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2077#ifndef RNA_RUNTIME
2078 if (iprop->defaultarray != nullptr) {
2079 CLOG_ERROR(&LOG, "\"%s.%s\", set from DNA.", srna->identifier, prop->identifier);
2080 }
2081#endif
2082 iprop->defaultarray = array;
2083 break;
2084 }
2085 default:
2086 CLOG_ERROR(&LOG, "\"%s.%s\", type is not int.", srna->identifier, prop->identifier);
2087 DefRNA.error = true;
2088 break;
2089 }
2090}
2091
2093{
2094 StructRNA *srna = DefRNA.laststruct;
2095
2096 switch (prop->type) {
2097 case PROP_FLOAT: {
2098 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2099#ifndef RNA_RUNTIME
2100 if (fprop->defaultvalue != 0) {
2101 CLOG_ERROR(&LOG, "\"%s.%s\", set from DNA.", srna->identifier, prop->identifier);
2102 }
2103#endif
2104 fprop->defaultvalue = value;
2105 break;
2106 }
2107 default:
2108 CLOG_ERROR(&LOG, "\"%s.%s\", type is not float.", srna->identifier, prop->identifier);
2109 DefRNA.error = true;
2110 break;
2111 }
2112}
2114{
2115 StructRNA *srna = DefRNA.laststruct;
2116
2117 switch (prop->type) {
2118 case PROP_FLOAT: {
2119 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2120#ifndef RNA_RUNTIME
2121 if (fprop->defaultarray != nullptr) {
2122 CLOG_ERROR(&LOG, "\"%s.%s\", set from DNA.", srna->identifier, prop->identifier);
2123 }
2124#endif
2125 fprop->defaultarray = array; /* WARNING, this array must not come from the stack and lost */
2126 break;
2127 }
2128 default:
2129 CLOG_ERROR(&LOG, "\"%s.%s\", type is not float.", srna->identifier, prop->identifier);
2130 DefRNA.error = true;
2131 break;
2132 }
2133}
2134
2135void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
2136{
2137 StructRNA *srna = DefRNA.laststruct;
2138
2139 switch (prop->type) {
2140 case PROP_STRING: {
2141 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2142
2143 if (value == nullptr) {
2144 CLOG_ERROR(&LOG,
2145 "\"%s.%s\", nullptr string passed (don't call in this case).",
2146 srna->identifier,
2147 prop->identifier);
2148 DefRNA.error = true;
2149 break;
2150 }
2151
2152 if (!value[0]) {
2153 CLOG_ERROR(&LOG,
2154 "\"%s.%s\", empty string passed (don't call in this case).",
2155 srna->identifier,
2156 prop->identifier);
2157 DefRNA.error = true;
2158 // BLI_assert(0);
2159 break;
2160 }
2161#ifndef RNA_RUNTIME
2162 if (sprop->defaultvalue != nullptr && sprop->defaultvalue[0]) {
2163 CLOG_ERROR(&LOG, "\"%s.%s\", set from DNA.", srna->identifier, prop->identifier);
2164 }
2165#endif
2166 sprop->defaultvalue = value;
2167 break;
2168 }
2169 default:
2170 CLOG_ERROR(&LOG, "\"%s.%s\", type is not string.", srna->identifier, prop->identifier);
2171 DefRNA.error = true;
2172 break;
2173 }
2174}
2175
2177{
2178 StructRNA *srna = DefRNA.laststruct;
2179 int i, defaultfound = 0;
2180
2181 switch (prop->type) {
2182 case PROP_ENUM: {
2183 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2184 eprop->defaultvalue = value;
2185
2186 if (prop->flag & PROP_ENUM_FLAG) {
2187 /* check all bits are accounted for */
2188 int totflag = 0;
2189 for (i = 0; i < eprop->totitem; i++) {
2190 if (eprop->item[i].identifier[0]) {
2191 totflag |= eprop->item[i].value;
2192 }
2193 }
2194
2195 if (eprop->defaultvalue & ~totflag) {
2196 CLOG_ERROR(&LOG,
2197 "\"%s.%s\", default includes unused bits (%d).",
2198 srna->identifier,
2199 prop->identifier,
2200 eprop->defaultvalue & ~totflag);
2201 DefRNA.error = true;
2202 }
2203 }
2204 else {
2205 for (i = 0; i < eprop->totitem; i++) {
2206 if (eprop->item[i].identifier[0] && eprop->item[i].value == eprop->defaultvalue) {
2207 defaultfound = 1;
2208 }
2209 }
2210
2211 if (!defaultfound && eprop->totitem) {
2212 if (value == 0) {
2213 eprop->defaultvalue = eprop->item[0].value;
2214 }
2215 else {
2216 CLOG_ERROR(
2217 &LOG, "\"%s.%s\", default is not in items.", srna->identifier, prop->identifier);
2218 DefRNA.error = true;
2219 }
2220 }
2221 }
2222
2223 break;
2224 }
2225 default:
2226 CLOG_ERROR(&LOG, "\"%s.%s\", type is not enum.", srna->identifier, prop->identifier);
2227 DefRNA.error = true;
2228 break;
2229 }
2230}
2231
2232/* SDNA */
2233
2235 const char *structname,
2236 const char *propname)
2237{
2238 DNAStructMember smember;
2239 StructDefRNA *ds;
2240 PropertyDefRNA *dp;
2241
2243 if (dp == nullptr) {
2244 return nullptr;
2245 }
2246
2247 ds = rna_find_struct_def((StructRNA *)dp->cont);
2248
2249 if (!structname) {
2250 structname = ds->dnaname;
2251 }
2252 if (!propname) {
2253 propname = prop->identifier;
2254 }
2255
2256 int dnaoffset = 0;
2257 if (!rna_find_sdna_member(DefRNA.sdna, structname, propname, &smember, &dnaoffset)) {
2258 if (DefRNA.silent) {
2259 return nullptr;
2260 }
2261 if (!DefRNA.verify) {
2262 /* some basic values to survive even with sdna info */
2263 dp->dnastructname = structname;
2264 dp->dnaname = propname;
2265 if (prop->type == PROP_BOOLEAN) {
2266 dp->dnaarraylength = 1;
2267 }
2268 if (prop->type == PROP_POINTER) {
2269 dp->dnapointerlevel = 1;
2270 }
2271 dp->dnaoffset = smember.offset;
2272 return dp;
2273 }
2274 CLOG_ERROR(&LOG,
2275 "\"%s.%s\" (identifier \"%s\") not found. Struct must be in DNA.",
2276 structname,
2277 propname,
2278 prop->identifier);
2279 DefRNA.error = true;
2280 return nullptr;
2281 }
2282
2283 if (smember.arraylength > 1) {
2284 prop->arraylength[0] = smember.arraylength;
2285 prop->totarraylength = smember.arraylength;
2286 prop->arraydimension = 1;
2287 }
2288 else {
2289 prop->arraydimension = 0;
2290 prop->totarraylength = 0;
2291 }
2292
2293 dp->dnastructname = structname;
2296 dp->dnaname = propname;
2297 dp->dnatype = smember.type;
2298 dp->dnaarraylength = smember.arraylength;
2299 dp->dnapointerlevel = smember.pointerlevel;
2300 dp->dnaoffset = smember.offset;
2301 dp->dnasize = smember.size;
2302
2303 return dp;
2304}
2305
2307 const char *structname,
2308 const char *propname,
2309 int64_t bit)
2310{
2311 PropertyDefRNA *dp;
2312 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2313 StructRNA *srna = DefRNA.laststruct;
2314
2315 if (!DefRNA.preprocess) {
2316 CLOG_ERROR(&LOG, "only during preprocessing.");
2317 return;
2318 }
2319
2320 if (prop->type != PROP_BOOLEAN) {
2321 CLOG_ERROR(&LOG, "\"%s.%s\", type is not boolean.", srna->identifier, prop->identifier);
2322 DefRNA.error = true;
2323 return;
2324 }
2325
2326 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2327
2328 if (!DefRNA.silent) {
2329 /* Error check to ensure floats are not wrapped as integers/booleans. */
2330 if (dp->dnatype && *dp->dnatype && IS_DNATYPE_BOOLEAN_COMPAT(dp->dnatype) == 0) {
2331 CLOG_ERROR(&LOG,
2332 "%s.%s is a '%s' but wrapped as type '%s'.",
2333 srna->identifier,
2334 prop->identifier,
2335 dp->dnatype,
2337 DefRNA.error = true;
2338 return;
2339 }
2340 }
2341
2342 dp->booleanbit = bit;
2343
2344#ifndef RNA_RUNTIME
2345 /* Set the default if possible. */
2346 if (dp->dnaoffset != -1) {
2348 if (SDNAnr != -1) {
2349 const void *default_data = DNA_default_table[SDNAnr];
2350 if (default_data) {
2351 default_data = POINTER_OFFSET(default_data, dp->dnaoffset);
2352 bool has_default = true;
2353 if (prop->totarraylength > 0) {
2354 has_default = false;
2355 if (debugSRNA_defaults) {
2356 fprintf(stderr, "%s default: unsupported boolean array default\n", __func__);
2357 }
2358 }
2359 else {
2360 if (STREQ(dp->dnatype, "char")) {
2361 bprop->defaultvalue = *(const char *)default_data & bit;
2362 }
2363 else if (STREQ(dp->dnatype, "short")) {
2364 bprop->defaultvalue = *(const short *)default_data & bit;
2365 }
2366 else if (STREQ(dp->dnatype, "int")) {
2367 bprop->defaultvalue = *(const int *)default_data & bit;
2368 }
2369 else {
2370 has_default = false;
2371 if (debugSRNA_defaults) {
2372 fprintf(
2373 stderr, "%s default: unsupported boolean type (%s)\n", __func__, dp->dnatype);
2374 }
2375 }
2376
2377 if (has_default) {
2378 if (dp->booleannegative) {
2379 bprop->defaultvalue = !bprop->defaultvalue;
2380 }
2381
2382 if (debugSRNA_defaults) {
2383 fprintf(stderr, "value=%d, ", bprop->defaultvalue);
2385 }
2386 }
2387 }
2388 }
2389 }
2390 }
2391#else
2392 UNUSED_VARS(bprop);
2393#endif
2394 }
2395}
2396
2398 const char *structname,
2399 const char *propname,
2400 int64_t booleanbit)
2401{
2402 PropertyDefRNA *dp;
2403
2404 RNA_def_property_boolean_sdna(prop, structname, propname, booleanbit);
2405
2407
2408 if (dp) {
2409 dp->booleannegative = true;
2410 }
2411}
2412
2413void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2414{
2415 PropertyDefRNA *dp;
2416 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2417 StructRNA *srna = DefRNA.laststruct;
2418
2419 if (!DefRNA.preprocess) {
2420 CLOG_ERROR(&LOG, "only during preprocessing.");
2421 return;
2422 }
2423
2424 if (prop->type != PROP_INT) {
2425 CLOG_ERROR(&LOG, "\"%s.%s\", type is not int.", srna->identifier, prop->identifier);
2426 DefRNA.error = true;
2427 return;
2428 }
2429
2430 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2431
2432 /* Error check to ensure floats are not wrapped as integers/booleans. */
2433 if (!DefRNA.silent) {
2434 if (dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
2435 CLOG_ERROR(&LOG,
2436 "%s.%s is a '%s' but wrapped as type '%s'.",
2437 srna->identifier,
2438 prop->identifier,
2439 dp->dnatype,
2441 DefRNA.error = true;
2442 return;
2443 }
2444 }
2445
2446 /* SDNA doesn't pass us unsigned unfortunately. */
2447 if (dp->dnatype != nullptr && (dp->dnatype[0] != '\0')) {
2448 int range[2];
2449 if (rna_range_from_int_type(dp->dnatype, range)) {
2450 iprop->hardmin = iprop->softmin = range[0];
2451 iprop->hardmax = iprop->softmax = range[1];
2452 }
2453 else {
2454 CLOG_ERROR(&LOG,
2455 "\"%s.%s\", type \"%s\" range not known.",
2456 srna->identifier,
2457 prop->identifier,
2458 dp->dnatype);
2459 DefRNA.error = true;
2460 }
2461
2462 /* Rather arbitrary that this is only done for one type. */
2463 if (STREQ(dp->dnatype, "int")) {
2464 iprop->softmin = -10000;
2465 iprop->softmax = 10000;
2466 }
2467 }
2468
2470 iprop->hardmin = iprop->softmin = 0;
2471 }
2472
2473#ifndef RNA_RUNTIME
2474 /* Set the default if possible. */
2475 if (dp->dnaoffset != -1) {
2477 if (SDNAnr != -1) {
2478 const void *default_data = DNA_default_table[SDNAnr];
2479 if (default_data) {
2480 default_data = POINTER_OFFSET(default_data, dp->dnaoffset);
2481 /* NOTE: Currently doesn't store sign, assume chars are unsigned because
2482 * we build with this enabled, otherwise check 'PROP_UNSIGNED'. */
2483 bool has_default = true;
2484 if (prop->totarraylength > 0) {
2485 const void *default_data_end = POINTER_OFFSET(default_data, dp->dnasize);
2486 const int size_final = sizeof(int) * prop->totarraylength;
2487 if (STREQ(dp->dnatype, "char")) {
2488 int *defaultarray = static_cast<int *>(rna_calloc(size_final));
2489 for (int i = 0; i < prop->totarraylength && default_data < default_data_end; i++) {
2490 defaultarray[i] = *(const char *)default_data;
2491 default_data = POINTER_OFFSET(default_data, sizeof(char));
2492 }
2493 iprop->defaultarray = defaultarray;
2494 }
2495 else if (STREQ(dp->dnatype, "short")) {
2496
2497 int *defaultarray = static_cast<int *>(rna_calloc(size_final));
2498 for (int i = 0; i < prop->totarraylength && default_data < default_data_end; i++) {
2499 defaultarray[i] = (prop->subtype != PROP_UNSIGNED) ? *(const short *)default_data :
2500 *(const ushort *)default_data;
2501 default_data = POINTER_OFFSET(default_data, sizeof(short));
2502 }
2503 iprop->defaultarray = defaultarray;
2504 }
2505 else if (STREQ(dp->dnatype, "int")) {
2506 int *defaultarray = static_cast<int *>(rna_calloc(size_final));
2507 memcpy(defaultarray, default_data, std::min(size_final, dp->dnasize));
2508 iprop->defaultarray = defaultarray;
2509 }
2510 else {
2511 has_default = false;
2512 if (debugSRNA_defaults) {
2513 fprintf(stderr,
2514 "%s default: unsupported int array type (%s)\n",
2515 __func__,
2516 dp->dnatype);
2517 }
2518 }
2519
2520 if (has_default) {
2521 if (debugSRNA_defaults) {
2522 fprintf(stderr, "value=(");
2523 for (int i = 0; i < prop->totarraylength; i++) {
2524 fprintf(stderr, "%d, ", iprop->defaultarray[i]);
2525 }
2526 fprintf(stderr, "), ");
2528 }
2529 }
2530 }
2531 else {
2532 if (STREQ(dp->dnatype, "char")) {
2533 iprop->defaultvalue = *(const char *)default_data;
2534 }
2535 else if (STREQ(dp->dnatype, "short")) {
2536 iprop->defaultvalue = (prop->subtype != PROP_UNSIGNED) ?
2537 *(const short *)default_data :
2538 *(const ushort *)default_data;
2539 }
2540 else if (STREQ(dp->dnatype, "int")) {
2541 iprop->defaultvalue = (prop->subtype != PROP_UNSIGNED) ? *(const int *)default_data :
2542 *(const uint *)default_data;
2543 }
2544 else {
2545 has_default = false;
2546 if (debugSRNA_defaults) {
2547 fprintf(stderr, "%s default: unsupported int type (%s)\n", __func__, dp->dnatype);
2548 }
2549 }
2550
2551 if (has_default) {
2552 if (debugSRNA_defaults) {
2553 fprintf(stderr, "value=%d, ", iprop->defaultvalue);
2555 }
2556 }
2557 }
2558 }
2559 }
2560 }
2561#endif
2562 }
2563}
2564
2565void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2566{
2567 PropertyDefRNA *dp;
2568 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2569 StructRNA *srna = DefRNA.laststruct;
2570
2571 if (!DefRNA.preprocess) {
2572 CLOG_ERROR(&LOG, "only during preprocessing.");
2573 return;
2574 }
2575
2576 if (prop->type != PROP_FLOAT) {
2577 CLOG_ERROR(&LOG, "\"%s.%s\", type is not float.", srna->identifier, prop->identifier);
2578 DefRNA.error = true;
2579 return;
2580 }
2581
2582 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2583 /* silent is for internal use */
2584 if (!DefRNA.silent) {
2585 if (dp->dnatype && *dp->dnatype && IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
2586 /* Colors are an exception. these get translated. */
2587 if (prop->subtype != PROP_COLOR_GAMMA) {
2588 CLOG_ERROR(&LOG,
2589 "%s.%s is a '%s' but wrapped as type '%s'.",
2590 srna->identifier,
2591 prop->identifier,
2592 dp->dnatype,
2594 DefRNA.error = true;
2595 return;
2596 }
2597 }
2598 }
2599
2600 if (dp->dnatype && STREQ(dp->dnatype, "char")) {
2601 fprop->hardmin = fprop->softmin = 0.0f;
2602 fprop->hardmax = fprop->softmax = 1.0f;
2603 }
2604
2605#ifndef RNA_RUNTIME
2606 /* Set the default if possible. */
2607 if (dp->dnaoffset != -1) {
2609 if (SDNAnr != -1) {
2610 const void *default_data = DNA_default_table[SDNAnr];
2611 if (default_data) {
2612 default_data = POINTER_OFFSET(default_data, dp->dnaoffset);
2613 bool has_default = true;
2614 if (prop->totarraylength > 0) {
2615 if (STREQ(dp->dnatype, "float")) {
2616 const int size_final = sizeof(float) * prop->totarraylength;
2617 float *defaultarray = static_cast<float *>(rna_calloc(size_final));
2618 memcpy(defaultarray, default_data, std::min(size_final, dp->dnasize));
2619 fprop->defaultarray = defaultarray;
2620 }
2621 else {
2622 has_default = false;
2623 if (debugSRNA_defaults) {
2624 fprintf(stderr,
2625 "%s default: unsupported float array type (%s)\n",
2626 __func__,
2627 dp->dnatype);
2628 }
2629 }
2630
2631 if (has_default) {
2632 if (debugSRNA_defaults) {
2633 fprintf(stderr, "value=(");
2634 for (int i = 0; i < prop->totarraylength; i++) {
2635 fprintf(stderr, "%g, ", fprop->defaultarray[i]);
2636 }
2637 fprintf(stderr, "), ");
2639 }
2640 }
2641 }
2642 else {
2643 if (STREQ(dp->dnatype, "float")) {
2644 fprop->defaultvalue = *(const float *)default_data;
2645 }
2646 else if (STREQ(dp->dnatype, "char")) {
2647 fprop->defaultvalue = float(*(const char *)default_data) * (1.0f / 255.0f);
2648 }
2649 else {
2650 has_default = false;
2651 if (debugSRNA_defaults) {
2652 fprintf(
2653 stderr, "%s default: unsupported float type (%s)\n", __func__, dp->dnatype);
2654 }
2655 }
2656
2657 if (has_default) {
2658 if (debugSRNA_defaults) {
2659 fprintf(stderr, "value=%g, ", fprop->defaultvalue);
2661 }
2662 }
2663 }
2664 }
2665 }
2666 }
2667#endif
2668 }
2669
2670 rna_def_property_sdna(prop, structname, propname);
2671}
2672
2673void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2674{
2675 PropertyDefRNA *dp;
2676 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2677 StructRNA *srna = DefRNA.laststruct;
2678
2679 if (!DefRNA.preprocess) {
2680 CLOG_ERROR(&LOG, "only during preprocessing.");
2681 return;
2682 }
2683
2684 if (prop->type != PROP_ENUM) {
2685 CLOG_ERROR(&LOG, "\"%s.%s\", type is not enum.", srna->identifier, prop->identifier);
2686 DefRNA.error = true;
2687 return;
2688 }
2689
2690 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2691 if (prop->arraydimension) {
2692 prop->arraydimension = 0;
2693 prop->totarraylength = 0;
2694
2695 if (!DefRNA.silent) {
2696 CLOG_ERROR(&LOG, "\"%s.%s\", array not supported for enum type.", structname, propname);
2697 DefRNA.error = true;
2698 }
2699 }
2700
2701#ifndef RNA_RUNTIME
2702 /* Set the default if possible. */
2703 if (dp->dnaoffset != -1) {
2705 if (SDNAnr != -1) {
2706 const void *default_data = DNA_default_table[SDNAnr];
2707 if (default_data) {
2708 default_data = POINTER_OFFSET(default_data, dp->dnaoffset);
2709 bool has_default = true;
2710 if (STREQ(dp->dnatype, "char")) {
2711 eprop->defaultvalue = *(const char *)default_data;
2712 }
2713 else if (STREQ(dp->dnatype, "short")) {
2714 eprop->defaultvalue = *(const short *)default_data;
2715 }
2716 else if (STREQ(dp->dnatype, "int")) {
2717 eprop->defaultvalue = *(const int *)default_data;
2718 }
2719 else {
2720 has_default = false;
2721 if (debugSRNA_defaults) {
2722 fprintf(stderr, "%s default: unsupported enum type (%s)\n", __func__, dp->dnatype);
2723 }
2724 }
2725
2726 if (has_default) {
2727 if (debugSRNA_defaults) {
2728 fprintf(stderr, "value=%d, ", eprop->defaultvalue);
2730 }
2731 }
2732 }
2733 }
2734 }
2735#else
2736 UNUSED_VARS(eprop);
2737#endif
2738 }
2739}
2740
2742 const char *structname,
2743 const char *propname)
2744{
2745 PropertyDefRNA *dp;
2746
2747 RNA_def_property_enum_sdna(prop, structname, propname);
2748
2750
2751 if (dp) {
2752 dp->enumbitflags = 1;
2753
2754#ifndef RNA_RUNTIME
2755 int defaultvalue_mask = 0;
2756 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2757 for (int i = 0; i < eprop->totitem; i++) {
2758 if (eprop->item[i].identifier[0]) {
2759 defaultvalue_mask |= eprop->defaultvalue & eprop->item[i].value;
2760 }
2761 }
2762 eprop->defaultvalue = defaultvalue_mask;
2763#endif
2764 }
2765}
2766
2767void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2768{
2769 PropertyDefRNA *dp;
2770 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2771 StructRNA *srna = DefRNA.laststruct;
2772
2773 if (!DefRNA.preprocess) {
2774 CLOG_ERROR(&LOG, "only during preprocessing.");
2775 return;
2776 }
2777
2778 if (prop->type != PROP_STRING) {
2779 CLOG_ERROR(&LOG, "\"%s.%s\", type is not string.", srna->identifier, prop->identifier);
2780 DefRNA.error = true;
2781 return;
2782 }
2783
2784 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2785 if (prop->arraydimension) {
2786 sprop->maxlength = prop->totarraylength;
2787 prop->arraydimension = 0;
2788 prop->totarraylength = 0;
2789 }
2790
2791#ifndef RNA_RUNTIME
2792 /* Set the default if possible. */
2793 if ((dp->dnaoffset != -1) && (dp->dnapointerlevel != 0)) {
2795 if (SDNAnr != -1) {
2796 const void *default_data = DNA_default_table[SDNAnr];
2797 if (default_data) {
2798 default_data = POINTER_OFFSET(default_data, dp->dnaoffset);
2799 sprop->defaultvalue = static_cast<const char *>(default_data);
2800
2801 if (debugSRNA_defaults) {
2802 fprintf(stderr, "value=\"%s\", ", sprop->defaultvalue);
2804 }
2805 }
2806 }
2807 }
2808#endif
2809 }
2810}
2811
2812void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
2813{
2814 // PropertyDefRNA *dp;
2815 StructRNA *srna = DefRNA.laststruct;
2816
2817 if (!DefRNA.preprocess) {
2818 CLOG_ERROR(&LOG, "only during preprocessing.");
2819 return;
2820 }
2821
2822 if (prop->type != PROP_POINTER) {
2823 CLOG_ERROR(&LOG, "\"%s.%s\", type is not pointer.", srna->identifier, prop->identifier);
2824 DefRNA.error = true;
2825 return;
2826 }
2827
2828 if (/* dp= */ rna_def_property_sdna(prop, structname, propname)) {
2829 if (prop->arraydimension) {
2830 prop->arraydimension = 0;
2831 prop->totarraylength = 0;
2832
2833 if (!DefRNA.silent) {
2834 CLOG_ERROR(&LOG, "\"%s.%s\", array not supported for pointer type.", structname, propname);
2835 DefRNA.error = true;
2836 }
2837 }
2838 }
2839}
2840
2842 const char *structname,
2843 const char *propname,
2844 const char *lengthpropname)
2845{
2846 PropertyDefRNA *dp;
2848 StructRNA *srna = DefRNA.laststruct;
2849
2850 if (!DefRNA.preprocess) {
2851 CLOG_ERROR(&LOG, "only during preprocessing.");
2852 return;
2853 }
2854
2855 if (prop->type != PROP_COLLECTION) {
2856 CLOG_ERROR(&LOG, "\"%s.%s\", type is not collection.", srna->identifier, prop->identifier);
2857 DefRNA.error = true;
2858 return;
2859 }
2860
2861 if ((dp = rna_def_property_sdna(prop, structname, propname))) {
2862 if (prop->arraydimension && !lengthpropname) {
2863 prop->arraydimension = 0;
2864 prop->totarraylength = 0;
2865
2866 if (!DefRNA.silent) {
2867 CLOG_ERROR(&LOG, "\"%s.%s\", array of collections not supported.", structname, propname);
2868 DefRNA.error = true;
2869 }
2870 }
2871
2872 if (dp->dnatype && STREQ(dp->dnatype, "ListBase")) {
2873 cprop->next = (PropCollectionNextFunc)(void *)"rna_iterator_listbase_next";
2874 cprop->get = (PropCollectionGetFunc)(void *)"rna_iterator_listbase_get";
2875 cprop->end = (PropCollectionEndFunc)(void *)"rna_iterator_listbase_end";
2876 }
2877 }
2878
2879 if (dp && lengthpropname) {
2880 DNAStructMember smember;
2882
2883 if (!structname) {
2884 structname = ds->dnaname;
2885 }
2886
2887 int dnaoffset = 0;
2888 if (lengthpropname[0] == 0 ||
2889 rna_find_sdna_member(DefRNA.sdna, structname, lengthpropname, &smember, &dnaoffset))
2890 {
2891 if (lengthpropname[0] == 0) {
2892 dp->dnalengthfixed = prop->totarraylength;
2893 prop->arraydimension = 0;
2894 prop->totarraylength = 0;
2895 }
2896 else {
2897 dp->dnalengthstructname = structname;
2898 dp->dnalengthname = lengthpropname;
2899 prop->totarraylength = 0;
2900 }
2901
2902 cprop->next = (PropCollectionNextFunc)(void *)"rna_iterator_array_next";
2903 cprop->end = (PropCollectionEndFunc)(void *)"rna_iterator_array_end";
2904
2905 if (dp->dnapointerlevel >= 2) {
2906 cprop->get = (PropCollectionGetFunc)(void *)"rna_iterator_array_dereference_get";
2907 }
2908 else {
2909 cprop->get = (PropCollectionGetFunc)(void *)"rna_iterator_array_get";
2910 }
2911 }
2912 else {
2913 if (!DefRNA.silent) {
2914 CLOG_ERROR(&LOG, "\"%s.%s\" not found.", structname, lengthpropname);
2915 DefRNA.error = true;
2916 }
2917 }
2918 }
2919}
2920
2922{
2923 prop->translation_context = context ? context : BLT_I18NCONTEXT_DEFAULT_BPYRNA;
2924}
2925
2926/* Functions */
2927
2928void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
2929{
2930 if (!DefRNA.preprocess) {
2931 CLOG_ERROR(&LOG, "only during preprocessing.");
2932 return;
2933 }
2934
2935 if (editable) {
2936 prop->editable = (EditableFunc)editable;
2937 }
2938}
2939
2940void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable)
2941{
2942 if (!DefRNA.preprocess) {
2943 CLOG_ERROR(&LOG, "only during preprocessing.");
2944 return;
2945 }
2946
2947 if (editable) {
2948 prop->itemeditable = (ItemEditableFunc)editable;
2949 }
2950}
2951
2953 const char *diff,
2954 const char *store,
2955 const char *apply)
2956{
2957 if (!DefRNA.preprocess) {
2958 CLOG_ERROR(&LOG, "only during preprocessing.");
2959 return;
2960 }
2961
2962 if (diff) {
2964 }
2965 if (store) {
2966 prop->override_store = (RNAPropOverrideStore)store;
2967 }
2968 if (apply) {
2969 prop->override_apply = (RNAPropOverrideApply)apply;
2970 }
2971}
2972
2973void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
2974{
2975 if (!DefRNA.preprocess) {
2976 CLOG_ERROR(&LOG, "only during preprocessing.");
2977 return;
2978 }
2979
2980 prop->noteflag = noteflag;
2981 prop->update = (UpdateFunc)func;
2982}
2983
2988
2995
2996void RNA_def_property_update_notifier(PropertyRNA *prop, const int noteflag)
2997{
2998 prop->noteflag = noteflag;
2999}
3000
3001void RNA_def_property_poll_runtime(PropertyRNA *prop, const void *func)
3002{
3003 if (prop->type == PROP_POINTER) {
3004 ((PointerPropertyRNA *)prop)->poll = (PropPointerPollFunc)func;
3005 }
3006 else {
3007 CLOG_ERROR(&LOG, "%s is not a Pointer Property.", prop->identifier);
3008 }
3009}
3010
3011void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
3012{
3013 if (!DefRNA.preprocess) {
3014 CLOG_ERROR(&LOG, "only during preprocessing.");
3015 return;
3016 }
3017
3018 if (!(prop->flag & PROP_DYNAMIC)) {
3019 CLOG_ERROR(&LOG, "property is a not dynamic array.");
3020 DefRNA.error = true;
3021 return;
3022 }
3023
3024 if (getlength) {
3025 prop->getlength = (PropArrayLengthGetFunc)getlength;
3026 }
3027}
3028
3029void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
3030{
3031 StructRNA *srna = DefRNA.laststruct;
3032
3033 if (!DefRNA.preprocess) {
3034 CLOG_ERROR(&LOG, "only during preprocessing.");
3035 return;
3036 }
3037
3038 switch (prop->type) {
3039 case PROP_BOOLEAN: {
3040 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
3041
3042 if (prop->arraydimension) {
3043 if (get) {
3044 bprop->getarray = (PropBooleanArrayGetFunc)get;
3045 }
3046 if (set) {
3047 bprop->setarray = (PropBooleanArraySetFunc)set;
3048 }
3049 }
3050 else {
3051 if (get) {
3052 bprop->get = (PropBooleanGetFunc)get;
3053 }
3054 if (set) {
3055 bprop->set = (PropBooleanSetFunc)set;
3056 }
3057 }
3058 break;
3059 }
3060 default:
3061 CLOG_ERROR(&LOG, "\"%s.%s\", type is not boolean.", srna->identifier, prop->identifier);
3062 DefRNA.error = true;
3063 break;
3064 }
3065}
3066
3068 BooleanPropertyGetFunc getfunc,
3069 BooleanPropertySetFunc setfunc)
3070{
3071 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
3072
3073 if (getfunc) {
3074 bprop->get_ex = getfunc;
3075 }
3076 if (setfunc) {
3077 bprop->set_ex = setfunc;
3078 }
3079
3080 if (getfunc || setfunc) {
3081 /* don't save in id properties */
3083
3084 if (!setfunc) {
3086 }
3087 }
3088}
3089
3093{
3094 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
3095
3096 if (getfunc) {
3097 bprop->getarray_ex = getfunc;
3098 }
3099 if (setfunc) {
3100 bprop->setarray_ex = setfunc;
3101 }
3102
3103 if (getfunc || setfunc) {
3104 /* don't save in id properties */
3106
3107 if (!setfunc) {
3109 }
3110 }
3111}
3112
3114 const char *get,
3115 const char *set,
3116 const char *range)
3117{
3118 StructRNA *srna = DefRNA.laststruct;
3119
3120 if (!DefRNA.preprocess) {
3121 CLOG_ERROR(&LOG, "only during preprocessing.");
3122 return;
3123 }
3124
3125 switch (prop->type) {
3126 case PROP_INT: {
3127 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
3128
3129 if (prop->arraydimension) {
3130 if (get) {
3131 iprop->getarray = (PropIntArrayGetFunc)get;
3132 }
3133 if (set) {
3134 iprop->setarray = (PropIntArraySetFunc)set;
3135 }
3136 }
3137 else {
3138 if (get) {
3139 iprop->get = (PropIntGetFunc)get;
3140 }
3141 if (set) {
3142 iprop->set = (PropIntSetFunc)set;
3143 }
3144 }
3145 if (range) {
3146 iprop->range = (PropIntRangeFunc)range;
3147 }
3148 break;
3149 }
3150 default:
3151 CLOG_ERROR(&LOG, "\"%s.%s\", type is not int.", srna->identifier, prop->identifier);
3152 DefRNA.error = true;
3153 break;
3154 }
3155}
3156
3158 IntPropertyGetFunc getfunc,
3159 IntPropertySetFunc setfunc,
3160 IntPropertyRangeFunc rangefunc)
3161{
3162 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
3163
3164 if (getfunc) {
3165 iprop->get_ex = getfunc;
3166 }
3167 if (setfunc) {
3168 iprop->set_ex = setfunc;
3169 }
3170 if (rangefunc) {
3171 iprop->range_ex = rangefunc;
3172 }
3173
3174 if (getfunc || setfunc) {
3175 /* don't save in id properties */
3177
3178 if (!setfunc) {
3180 }
3181 }
3182}
3183
3187 IntPropertyRangeFunc rangefunc)
3188{
3189 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
3190
3191 if (getfunc) {
3192 iprop->getarray_ex = getfunc;
3193 }
3194 if (setfunc) {
3195 iprop->setarray_ex = setfunc;
3196 }
3197 if (rangefunc) {
3198 iprop->range_ex = rangefunc;
3199 }
3200
3201 if (getfunc || setfunc) {
3202 /* don't save in id properties */
3204
3205 if (!setfunc) {
3207 }
3208 }
3209}
3210
3212 const char *get,
3213 const char *set,
3214 const char *range)
3215{
3216 StructRNA *srna = DefRNA.laststruct;
3217
3218 if (!DefRNA.preprocess) {
3219 CLOG_ERROR(&LOG, "only during preprocessing.");
3220 return;
3221 }
3222
3223 switch (prop->type) {
3224 case PROP_FLOAT: {
3225 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
3226
3227 if (prop->arraydimension) {
3228 if (get) {
3229 fprop->getarray = (PropFloatArrayGetFunc)get;
3230 }
3231 if (set) {
3232 fprop->setarray = (PropFloatArraySetFunc)set;
3233 }
3234 }
3235 else {
3236 if (get) {
3237 fprop->get = (PropFloatGetFunc)get;
3238 }
3239 if (set) {
3240 fprop->set = (PropFloatSetFunc)set;
3241 }
3242 }
3243 if (range) {
3244 fprop->range = (PropFloatRangeFunc)range;
3245 }
3246 break;
3247 }
3248 default:
3249 CLOG_ERROR(&LOG, "\"%s.%s\", type is not float.", srna->identifier, prop->identifier);
3250 DefRNA.error = true;
3251 break;
3252 }
3253}
3254
3256 FloatPropertyGetFunc getfunc,
3257 FloatPropertySetFunc setfunc,
3258 FloatPropertyRangeFunc rangefunc)
3259{
3260 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
3261
3262 if (getfunc) {
3263 fprop->get_ex = getfunc;
3264 }
3265 if (setfunc) {
3266 fprop->set_ex = setfunc;
3267 }
3268 if (rangefunc) {
3269 fprop->range_ex = rangefunc;
3270 }
3271
3272 if (getfunc || setfunc) {
3273 /* don't save in id properties */
3275
3276 if (!setfunc) {
3278 }
3279 }
3280}
3281
3285 FloatPropertyRangeFunc rangefunc)
3286{
3287 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
3288
3289 if (getfunc) {
3290 fprop->getarray_ex = getfunc;
3291 }
3292 if (setfunc) {
3293 fprop->setarray_ex = setfunc;
3294 }
3295 if (rangefunc) {
3296 fprop->range_ex = rangefunc;
3297 }
3298
3299 if (getfunc || setfunc) {
3300 /* don't save in id properties */
3302
3303 if (!setfunc) {
3305 }
3306 }
3307}
3308
3310 const char *get,
3311 const char *set,
3312 const char *item)
3313{
3314 StructRNA *srna = DefRNA.laststruct;
3315
3316 if (!DefRNA.preprocess) {
3317 CLOG_ERROR(&LOG, "only during preprocessing.");
3318 return;
3319 }
3320
3321 switch (prop->type) {
3322 case PROP_ENUM: {
3323 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
3324
3325 if (get) {
3326 eprop->get = (PropEnumGetFunc)get;
3327 }
3328 if (set) {
3329 eprop->set = (PropEnumSetFunc)set;
3330 }
3331 if (item) {
3332 eprop->item_fn = (PropEnumItemFunc)item;
3333 }
3334 break;
3335 }
3336 default:
3337 CLOG_ERROR(&LOG, "\"%s.%s\", type is not enum.", srna->identifier, prop->identifier);
3338 DefRNA.error = true;
3339 break;
3340 }
3341}
3342
3344 EnumPropertyGetFunc getfunc,
3345 EnumPropertySetFunc setfunc,
3346 EnumPropertyItemFunc itemfunc)
3347{
3348 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
3349
3350 if (getfunc) {
3351 eprop->get_ex = getfunc;
3352 }
3353 if (setfunc) {
3354 eprop->set_ex = setfunc;
3355 }
3356 if (itemfunc) {
3357 eprop->item_fn = itemfunc;
3358 }
3359
3360 if (getfunc || setfunc) {
3361 /* don't save in id properties */
3363
3364 if (!setfunc) {
3366 }
3367 }
3368}
3369
3371 const char *get,
3372 const char *length,
3373 const char *set)
3374{
3375 StructRNA *srna = DefRNA.laststruct;
3376
3377 if (!DefRNA.preprocess) {
3378 CLOG_ERROR(&LOG, "only during preprocessing.");
3379 return;
3380 }
3381
3382 switch (prop->type) {
3383 case PROP_STRING: {
3384 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3385
3386 if (get) {
3387 sprop->get = (PropStringGetFunc)get;
3388 }
3389 if (length) {
3390 sprop->length = (PropStringLengthFunc)length;
3391 }
3392 if (set) {
3393 sprop->set = (PropStringSetFunc)set;
3394 }
3395 break;
3396 }
3397 default:
3398 CLOG_ERROR(&LOG, "\"%s.%s\", type is not string.", srna->identifier, prop->identifier);
3399 DefRNA.error = true;
3400 break;
3401 }
3402}
3403
3405 const char *search,
3406 const eStringPropertySearchFlag search_flag)
3407{
3408 StructRNA *srna = DefRNA.laststruct;
3409
3410 if (!DefRNA.preprocess) {
3411 CLOG_ERROR(&LOG, "only during preprocessing.");
3412 return;
3413 }
3414
3415 switch (prop->type) {
3416 case PROP_STRING: {
3417 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3418 sprop->search = (StringPropertySearchFunc)search;
3419 if (search != nullptr) {
3420 sprop->search_flag = search_flag | PROP_STRING_SEARCH_SUPPORTED;
3421 }
3422 break;
3423 }
3424 default:
3425 CLOG_ERROR(&LOG, "\"%s.%s\", type is not string.", srna->identifier, prop->identifier);
3426 DefRNA.error = true;
3427 break;
3428 }
3429}
3430
3432 StringPropertyGetFunc getfunc,
3433 StringPropertyLengthFunc lengthfunc,
3434 StringPropertySetFunc setfunc)
3435{
3436 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3437
3438 if (getfunc) {
3439 sprop->get_ex = getfunc;
3440 }
3441 if (lengthfunc) {
3442 sprop->length_ex = lengthfunc;
3443 }
3444 if (setfunc) {
3445 sprop->set_ex = setfunc;
3446 }
3447
3448 if (getfunc || setfunc) {
3449 /* don't save in id properties */
3451
3452 if (!setfunc) {
3454 }
3455 }
3456}
3457
3459 StringPropertySearchFunc search_fn,
3460 const eStringPropertySearchFlag search_flag)
3461{
3462 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
3463
3464 sprop->search = search_fn;
3465 if (search_fn != nullptr) {
3466 sprop->search_flag = search_flag | PROP_STRING_SEARCH_SUPPORTED;
3467 }
3468}
3469
3471 PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
3472{
3473 StructRNA *srna = DefRNA.laststruct;
3474
3475 if (!DefRNA.preprocess) {
3476 CLOG_ERROR(&LOG, "only during preprocessing.");
3477 return;
3478 }
3479
3480 switch (prop->type) {
3481 case PROP_POINTER: {
3482 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
3483
3484 if (get) {
3485 pprop->get = (PropPointerGetFunc)get;
3486 }
3487 if (set) {
3488 pprop->set = (PropPointerSetFunc)set;
3489 }
3490 if (type_fn) {
3491 pprop->type_fn = (PropPointerTypeFunc)type_fn;
3492 }
3493 if (poll) {
3494 pprop->poll = (PropPointerPollFunc)poll;
3495 }
3496 break;
3497 }
3498 default:
3499 CLOG_ERROR(&LOG, "\"%s.%s\", type is not pointer.", srna->identifier, prop->identifier);
3500 DefRNA.error = true;
3501 break;
3502 }
3503}
3504
3506 const char *begin,
3507 const char *next,
3508 const char *end,
3509 const char *get,
3510 const char *length,
3511 const char *lookupint,
3512 const char *lookupstring,
3513 const char *assignint)
3514{
3515 StructRNA *srna = DefRNA.laststruct;
3516
3517 if (!DefRNA.preprocess) {
3518 CLOG_ERROR(&LOG, "only during preprocessing.");
3519 return;
3520 }
3521
3522 switch (prop->type) {
3523 case PROP_COLLECTION: {
3525
3526 if (begin) {
3527 cprop->begin = (PropCollectionBeginFunc)begin;
3528 }
3529 if (next) {
3531 }
3532 if (end) {
3533 cprop->end = (PropCollectionEndFunc)end;
3534 }
3535 if (get) {
3536 cprop->get = (PropCollectionGetFunc)get;
3537 }
3538 if (length) {
3539 cprop->length = (PropCollectionLengthFunc)length;
3540 }
3541 if (lookupint) {
3542 cprop->lookupint = (PropCollectionLookupIntFunc)lookupint;
3543 }
3544 if (lookupstring) {
3545 cprop->lookupstring = (PropCollectionLookupStringFunc)lookupstring;
3546 }
3547 if (assignint) {
3548 cprop->assignint = (PropCollectionAssignIntFunc)assignint;
3549 }
3550 break;
3551 }
3552 default:
3553 CLOG_ERROR(&LOG, "\"%s.%s\", type is not collection.", srna->identifier, prop->identifier);
3554 DefRNA.error = true;
3555 break;
3556 }
3557}
3558
3559void RNA_def_property_float_default_func(PropertyRNA *prop, const char *get_default)
3560{
3561 StructRNA *srna = DefRNA.laststruct;
3562
3563 if (!DefRNA.preprocess) {
3564 CLOG_ERROR(&LOG, "only during preprocessing");
3565 return;
3566 }
3567 switch (prop->type) {
3568 case PROP_FLOAT: {
3569 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop);
3570 if (prop->arraydimension) {
3571 if (get_default) {
3572 fprop->get_default_array = (PropFloatArrayGetFuncEx)get_default;
3573 }
3574 }
3575 else {
3576 if (get_default) {
3577 fprop->get_default = (PropFloatGetFuncEx)get_default;
3578 }
3579 }
3580 break;
3581 }
3582 default: {
3583 CLOG_ERROR(&LOG, "\"%s.%s\", type is not float.", srna->identifier, prop->identifier);
3584 DefRNA.error = true;
3585 break;
3586 }
3587 }
3588}
3589
3590void RNA_def_property_int_default_func(PropertyRNA *prop, const char *get_default)
3591{
3592 StructRNA *srna = DefRNA.laststruct;
3593
3594 if (!DefRNA.preprocess) {
3595 CLOG_ERROR(&LOG, "only during preprocessing");
3596 return;
3597 }
3598 switch (prop->type) {
3599 case PROP_INT: {
3600 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop);
3601 if (prop->arraydimension) {
3602 if (get_default) {
3603 iprop->get_default_array = (PropIntArrayGetFuncEx)get_default;
3604 }
3605 }
3606 else {
3607 if (get_default) {
3608 iprop->get_default = (PropIntGetFuncEx)get_default;
3609 }
3610 }
3611 break;
3612 }
3613 default: {
3614 CLOG_ERROR(&LOG, "\"%s.%s\", type is not int.", srna->identifier, prop->identifier);
3615 DefRNA.error = true;
3616 break;
3617 }
3618 }
3619}
3620
3621void RNA_def_property_boolean_default_func(PropertyRNA *prop, const char *get_default)
3622{
3623 StructRNA *srna = DefRNA.laststruct;
3624
3625 if (!DefRNA.preprocess) {
3626 CLOG_ERROR(&LOG, "only during preprocessing");
3627 return;
3628 }
3629 switch (prop->type) {
3630 case PROP_BOOLEAN: {
3631 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop);
3632 if (prop->arraydimension) {
3633 if (get_default) {
3634 bprop->get_default_array = (PropBooleanArrayGetFuncEx)get_default;
3635 }
3636 }
3637 else {
3638 if (get_default) {
3639 bprop->get_default = (PropBooleanGetFuncEx)get_default;
3640 }
3641 }
3642 break;
3643 }
3644 default: {
3645 CLOG_ERROR(&LOG, "\"%s.%s\", type is not boolean.", srna->identifier, prop->identifier);
3646 DefRNA.error = true;
3647 break;
3648 }
3649 }
3650}
3651
3652void RNA_def_property_srna(PropertyRNA *prop, const char *type)
3653{
3654 const char *error = nullptr;
3655 if (!rna_validate_identifier(type, false, &error)) {
3656 CLOG_ERROR(&LOG, "struct identifier \"%s\" error - %s", type, error);
3657 DefRNA.error = true;
3658 return;
3659 }
3660
3661 prop->srna = (StructRNA *)type;
3662}
3663
3664void RNA_def_py_data(PropertyRNA *prop, void *py_data)
3665{
3666 prop->py_data = py_data;
3667}
3668
3669/* Compact definitions */
3670
3672 const char *identifier,
3673 const bool default_value,
3674 const char *ui_name,
3675 const char *ui_description)
3676{
3677 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3678 PropertyRNA *prop;
3679
3680 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
3681 RNA_def_property_boolean_default(prop, default_value);
3682 RNA_def_property_ui_text(prop, ui_name, ui_description);
3683
3684 return prop;
3685}
3686
3688 const char *identifier,
3689 const int len,
3690 const bool *default_value,
3691 const char *ui_name,
3692 const char *ui_description)
3693{
3694 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3695 PropertyRNA *prop;
3696
3697 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_NONE);
3698 if (len != 0) {
3700 }
3701 if (default_value) {
3702 RNA_def_property_boolean_array_default(prop, default_value);
3703 }
3704 RNA_def_property_ui_text(prop, ui_name, ui_description);
3705
3706 return prop;
3707}
3708
3710 const char *identifier,
3711 const int len,
3712 const bool *default_value,
3713 const char *ui_name,
3714 const char *ui_description)
3715{
3716 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3717 PropertyRNA *prop;
3718
3719 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER);
3720 if (len != 0) {
3722 }
3723 if (default_value) {
3724 RNA_def_property_boolean_array_default(prop, default_value);
3725 }
3726 RNA_def_property_ui_text(prop, ui_name, ui_description);
3727
3728 return prop;
3729}
3730
3732 const char *identifier,
3733 const int len,
3734 const bool *default_value,
3735 const char *ui_name,
3736 const char *ui_description)
3737{
3738 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3739 PropertyRNA *prop;
3740
3741 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_LAYER_MEMBER);
3742 if (len != 0) {
3744 }
3745 if (default_value) {
3746 RNA_def_property_boolean_array_default(prop, default_value);
3747 }
3748 RNA_def_property_ui_text(prop, ui_name, ui_description);
3749
3750 return prop;
3751}
3752
3754 const char *identifier,
3755 const int len,
3756 const bool *default_value,
3757 const char *ui_name,
3758 const char *ui_description)
3759{
3760 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3761 PropertyRNA *prop;
3762
3763 prop = RNA_def_property(cont, identifier, PROP_BOOLEAN, PROP_XYZ); /* XXX */
3764 if (len != 0) {
3766 }
3767 if (default_value) {
3768 RNA_def_property_boolean_array_default(prop, default_value);
3769 }
3770 RNA_def_property_ui_text(prop, ui_name, ui_description);
3771
3772 return prop;
3773}
3774
3776 const char *identifier,
3777 const int default_value,
3778 const int hardmin,
3779 const int hardmax,
3780 const char *ui_name,
3781 const char *ui_description,
3782 const int softmin,
3783 const int softmax)
3784{
3785 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3786 PropertyRNA *prop;
3787
3789
3790 prop = RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
3791 RNA_def_property_int_default(prop, default_value);
3792 if (hardmin != hardmax) {
3793 RNA_def_property_range(prop, hardmin, hardmax);
3794 }
3795 RNA_def_property_ui_text(prop, ui_name, ui_description);
3796 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
3797
3798 return prop;
3799}
3800
3802 const char *identifier,
3803 const int len,
3804 const int *default_value,
3805 const int hardmin,
3806 const int hardmax,
3807 const char *ui_name,
3808 const char *ui_description,
3809 const int softmin,
3810 const int softmax)
3811{
3812 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3813 PropertyRNA *prop;
3814
3816
3817 prop = RNA_def_property(cont, identifier, PROP_INT, PROP_XYZ); /* XXX */
3818 if (len != 0) {
3820 }
3821 if (default_value) {
3822 RNA_def_property_int_array_default(prop, default_value);
3823 }
3824 if (hardmin != hardmax) {
3825 RNA_def_property_range(prop, hardmin, hardmax);
3826 }
3827 RNA_def_property_ui_text(prop, ui_name, ui_description);
3828 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
3829
3830 return prop;
3831}
3832
3834 const char *identifier,
3835 const int len,
3836 const int *default_value,
3837 const int hardmin,
3838 const int hardmax,
3839 const char *ui_name,
3840 const char *ui_description,
3841 const int softmin,
3842 const int softmax)
3843{
3844 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3845 PropertyRNA *prop;
3846
3848
3849 prop = RNA_def_property(cont, identifier, PROP_INT, PROP_NONE);
3850 if (len != 0) {
3852 }
3853 if (default_value) {
3854 RNA_def_property_int_array_default(prop, default_value);
3855 }
3856 if (hardmin != hardmax) {
3857 RNA_def_property_range(prop, hardmin, hardmax);
3858 }
3859 RNA_def_property_ui_text(prop, ui_name, ui_description);
3860 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
3861
3862 return prop;
3863}
3864
3866 const char *identifier,
3867 const char *default_value,
3868 const int maxlen,
3869 const char *ui_name,
3870 const char *ui_description)
3871{
3872 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3873 PropertyRNA *prop;
3874
3875 BLI_assert(default_value == nullptr || default_value[0]);
3876
3877 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_NONE);
3878 if (maxlen != 0) {
3880 }
3881 if (default_value) {
3882 RNA_def_property_string_default(prop, default_value);
3883 }
3884 RNA_def_property_ui_text(prop, ui_name, ui_description);
3885
3886 return prop;
3887}
3888
3890 const char *identifier,
3891 const char *default_value,
3892 const int maxlen,
3893 const char *ui_name,
3894 const char *ui_description)
3895{
3896 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3897 PropertyRNA *prop;
3898
3899 BLI_assert(default_value == nullptr || default_value[0]);
3900
3901 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_FILEPATH);
3902 if (maxlen != 0) {
3904 }
3905 if (default_value) {
3906 RNA_def_property_string_default(prop, default_value);
3907 }
3908 RNA_def_property_ui_text(prop, ui_name, ui_description);
3909
3910 return prop;
3911}
3912
3914 const char *identifier,
3915 const char *default_value,
3916 const int maxlen,
3917 const char *ui_name,
3918 const char *ui_description)
3919{
3920 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3921 PropertyRNA *prop;
3922
3923 BLI_assert(default_value == nullptr || default_value[0]);
3924
3925 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_DIRPATH);
3926 if (maxlen != 0) {
3928 }
3929 if (default_value) {
3930 RNA_def_property_string_default(prop, default_value);
3931 }
3932 RNA_def_property_ui_text(prop, ui_name, ui_description);
3933
3934 return prop;
3935}
3936
3938 const char *identifier,
3939 const char *default_value,
3940 const int maxlen,
3941 const char *ui_name,
3942 const char *ui_description)
3943{
3944 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3945 PropertyRNA *prop;
3946
3947 BLI_assert(default_value == nullptr || default_value[0]);
3948
3949 prop = RNA_def_property(cont, identifier, PROP_STRING, PROP_FILENAME);
3950 if (maxlen != 0) {
3952 }
3953 if (default_value) {
3954 RNA_def_property_string_default(prop, default_value);
3955 }
3956 RNA_def_property_ui_text(prop, ui_name, ui_description);
3957
3958 return prop;
3959}
3960
3962 const char *identifier,
3963 const EnumPropertyItem *items,
3964 const int default_value,
3965 const char *ui_name,
3966 const char *ui_description)
3967{
3968 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3969 PropertyRNA *prop;
3970
3971 if (items == nullptr) {
3972 CLOG_ERROR(&LOG, "items not allowed to be nullptr.");
3973 return nullptr;
3974 }
3975
3976 prop = RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
3977 RNA_def_property_enum_items(prop, items);
3978 RNA_def_property_enum_default(prop, default_value);
3979 RNA_def_property_ui_text(prop, ui_name, ui_description);
3980
3981 return prop;
3982}
3983
3985 const char *identifier,
3986 const EnumPropertyItem *items,
3987 const int default_value,
3988 const char *ui_name,
3989 const char *ui_description)
3990{
3991 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
3992 PropertyRNA *prop;
3993
3994 if (items == nullptr) {
3995 CLOG_ERROR(&LOG, "items not allowed to be nullptr.");
3996 return nullptr;
3997 }
3998
3999 prop = RNA_def_property(cont, identifier, PROP_ENUM, PROP_NONE);
4000 RNA_def_property_flag(prop, PROP_ENUM_FLAG); /* important to run before default set */
4001 RNA_def_property_enum_items(prop, items);
4002 RNA_def_property_enum_default(prop, default_value);
4003 RNA_def_property_ui_text(prop, ui_name, ui_description);
4004
4005 return prop;
4006}
4007
4009{
4010 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
4011 eprop->item_fn = itemfunc;
4012}
4013
4015 const char *identifier,
4016 const float default_value,
4017 const float hardmin,
4018 const float hardmax,
4019 const char *ui_name,
4020 const char *ui_description,
4021 const float softmin,
4022 const float softmax)
4023{
4024 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4025 PropertyRNA *prop;
4026
4028
4029 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
4030 RNA_def_property_float_default(prop, default_value);
4031 if (hardmin != hardmax) {
4032 RNA_def_property_range(prop, hardmin, hardmax);
4033 }
4034 RNA_def_property_ui_text(prop, ui_name, ui_description);
4035 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
4036
4037 return prop;
4038}
4039
4041 const char *identifier,
4042 const int len,
4043 const float *default_value,
4044 const float hardmin,
4045 const float hardmax,
4046 const char *ui_name,
4047 const char *ui_description,
4048 const float softmin,
4049 const float softmax)
4050{
4051 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4052 PropertyRNA *prop;
4053
4055
4056 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_XYZ);
4057 if (len != 0) {
4059 }
4060 if (default_value) {
4061 RNA_def_property_float_array_default(prop, default_value);
4062 }
4063 if (hardmin != hardmax) {
4064 RNA_def_property_range(prop, hardmin, hardmax);
4065 }
4066 RNA_def_property_ui_text(prop, ui_name, ui_description);
4067 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
4068
4069 return prop;
4070}
4071
4073 const char *identifier,
4074 const int len,
4075 const float *default_value,
4076 const float hardmin,
4077 const float hardmax,
4078 const char *ui_name,
4079 const char *ui_description,
4080 const float softmin,
4081 const float softmax)
4082{
4083 PropertyRNA *prop;
4084
4085 prop = RNA_def_float_vector(cont_,
4086 identifier,
4087 len,
4088 default_value,
4089 hardmin,
4090 hardmax,
4091 ui_name,
4092 ui_description,
4093 softmin,
4094 softmax);
4095 prop->subtype = PROP_XYZ_LENGTH;
4096
4097 return prop;
4098}
4099
4101 const char *identifier,
4102 const int len,
4103 const float *default_value,
4104 const float hardmin,
4105 const float hardmax,
4106 const char *ui_name,
4107 const char *ui_description,
4108 const float softmin,
4109 const float softmax)
4110{
4111 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4112 PropertyRNA *prop;
4113
4115
4116 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_COLOR);
4117 if (len != 0) {
4119 }
4120 if (default_value) {
4121 RNA_def_property_float_array_default(prop, default_value);
4122 }
4123 if (hardmin != hardmax) {
4124 RNA_def_property_range(prop, hardmin, hardmax);
4125 }
4126 RNA_def_property_ui_text(prop, ui_name, ui_description);
4127 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
4128
4129 return prop;
4130}
4131
4133 const char *identifier,
4134 const int rows,
4135 const int columns,
4136 const float *default_value,
4137 const float hardmin,
4138 const float hardmax,
4139 const char *ui_name,
4140 const char *ui_description,
4141 const float softmin,
4142 const float softmax)
4143{
4144 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4145 PropertyRNA *prop;
4146 const int length[2] = {rows, columns};
4147
4149
4150 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_MATRIX);
4151 RNA_def_property_multi_array(prop, 2, length);
4152 if (default_value) {
4153 RNA_def_property_float_array_default(prop, default_value);
4154 }
4155 if (hardmin != hardmax) {
4156 RNA_def_property_range(prop, hardmin, hardmax);
4157 }
4158 RNA_def_property_ui_text(prop, ui_name, ui_description);
4159 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
4160
4161 return prop;
4162}
4163
4165 const char *identifier,
4166 const int len,
4167 const float *default_value,
4168 const float hardmin,
4169 const float hardmax,
4170 const char *ui_name,
4171 const char *ui_description,
4172 const float softmin,
4173 const float softmax)
4174{
4175 PropertyRNA *prop;
4176
4177 prop = RNA_def_float_vector(cont_,
4178 identifier,
4179 len,
4180 default_value,
4181 hardmin,
4182 hardmax,
4183 ui_name,
4184 ui_description,
4185 softmin,
4186 softmax);
4187 prop->subtype = PROP_TRANSLATION;
4188
4189 RNA_def_property_ui_range(prop, softmin, softmax, 1, RNA_TRANSLATION_PREC_DEFAULT);
4190
4191 return prop;
4192}
4193
4195 const char *identifier,
4196 const int len,
4197 const float *default_value,
4198 const float hardmin,
4199 const float hardmax,
4200 const char *ui_name,
4201 const char *ui_description,
4202 const float softmin,
4203 const float softmax)
4204{
4205 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4206 PropertyRNA *prop;
4207
4209
4210 prop = RNA_def_property(cont, identifier, PROP_FLOAT, (len >= 3) ? PROP_EULER : PROP_ANGLE);
4211 if (len != 0) {
4213 if (default_value) {
4214 RNA_def_property_float_array_default(prop, default_value);
4215 }
4216 }
4217 else {
4218 /* RNA_def_property_float_default must be called outside */
4219 BLI_assert(default_value == nullptr);
4220 }
4221 if (hardmin != hardmax) {
4222 RNA_def_property_range(prop, hardmin, hardmax);
4223 }
4224 RNA_def_property_ui_text(prop, ui_name, ui_description);
4225 RNA_def_property_ui_range(prop, softmin, softmax, 10, 3);
4226
4227 return prop;
4228}
4229
4231 const char *identifier,
4232 const float default_value,
4233 const float hardmin,
4234 const float hardmax,
4235 const char *ui_name,
4236 const char *ui_description,
4237 const float softmin,
4238 const float softmax)
4239{
4240 PropertyRNA *prop = RNA_def_float(cont_,
4241 identifier,
4242 default_value,
4243 hardmin,
4244 hardmax,
4245 ui_name,
4246 ui_description,
4247 softmin,
4248 softmax);
4250
4251 return prop;
4252}
4253
4255 const char *identifier,
4256 const int len,
4257 const float *default_value,
4258 const float hardmin,
4259 const float hardmax,
4260 const char *ui_name,
4261 const char *ui_description,
4262 const float softmin,
4263 const float softmax)
4264{
4265 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4266 PropertyRNA *prop;
4267
4269
4270 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_NONE);
4271 if (len != 0) {
4273 }
4274 if (default_value) {
4275 RNA_def_property_float_array_default(prop, default_value);
4276 }
4277 if (hardmin != hardmax) {
4278 RNA_def_property_range(prop, hardmin, hardmax);
4279 }
4280 RNA_def_property_ui_text(prop, ui_name, ui_description);
4281 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
4282
4283 return prop;
4284}
4285
4287 const char *identifier,
4288 const float default_value,
4289 const float hardmin,
4290 const float hardmax,
4291 const char *ui_name,
4292 const char *ui_description,
4293 const float softmin,
4294 const float softmax)
4295{
4296 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4297 PropertyRNA *prop;
4298
4300
4301#ifndef NDEBUG
4302 /* Properties with PROP_PERCENTAGE should use a range like 0 to 100, unlike PROP_FACTOR. */
4303 if (hardmax < 2.0f) {
4304 CLOG_WARN(&LOG,
4305 "Percentage property with incorrect range: %s.%s",
4306 CONTAINER_RNA_ID(cont),
4307 identifier);
4308 }
4309#endif
4310
4311 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_PERCENTAGE);
4312 RNA_def_property_float_default(prop, default_value);
4313 if (hardmin != hardmax) {
4314 RNA_def_property_range(prop, hardmin, hardmax);
4315 }
4316 RNA_def_property_ui_text(prop, ui_name, ui_description);
4317 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
4318
4319 return prop;
4320}
4321
4323 const char *identifier,
4324 const float default_value,
4325 const float hardmin,
4326 const float hardmax,
4327 const char *ui_name,
4328 const char *ui_description,
4329 const float softmin,
4330 const float softmax)
4331{
4332 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4333 PropertyRNA *prop;
4334
4336
4337 prop = RNA_def_property(cont, identifier, PROP_FLOAT, PROP_FACTOR);
4338 RNA_def_property_float_default(prop, default_value);
4339 if (hardmin != hardmax) {
4340 RNA_def_property_range(prop, hardmin, hardmax);
4341 }
4342 RNA_def_property_ui_text(prop, ui_name, ui_description);
4343 RNA_def_property_ui_range(prop, softmin, softmax, 1, 3);
4344
4345 return prop;
4346}
4347
4349 const char *identifier,
4350 const char *type,
4351 const char *ui_name,
4352 const char *ui_description)
4353{
4354 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4355 PropertyRNA *prop;
4356
4357 prop = RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
4358 RNA_def_property_struct_type(prop, type);
4359 RNA_def_property_ui_text(prop, ui_name, ui_description);
4360
4361 return prop;
4362}
4363
4365 const char *identifier,
4366 StructRNA *type,
4367 const char *ui_name,
4368 const char *ui_description)
4369{
4370 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4371 PropertyRNA *prop;
4372
4373 prop = RNA_def_property(cont, identifier, PROP_POINTER, PROP_NONE);
4374 RNA_def_property_struct_runtime(cont, prop, type);
4375 if ((type->flag & STRUCT_ID) != 0) {
4377 }
4378 RNA_def_property_ui_text(prop, ui_name, ui_description);
4379
4380 return prop;
4381}
4382
4384 const char *identifier,
4385 const char *type,
4386 const char *ui_name,
4387 const char *ui_description)
4388{
4389 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4390 PropertyRNA *prop;
4391
4392 prop = RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
4393 RNA_def_property_struct_type(prop, type);
4394 RNA_def_property_ui_text(prop, ui_name, ui_description);
4395
4396 return prop;
4397}
4398
4400 const char *identifier,
4401 StructRNA *type,
4402 const char *ui_name,
4403 const char *ui_description)
4404{
4405 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4406 PropertyRNA *prop;
4407
4408 prop = RNA_def_property(cont, identifier, PROP_COLLECTION, PROP_NONE);
4409 RNA_def_property_struct_runtime(cont, prop, type);
4410 RNA_def_property_ui_text(prop, ui_name, ui_description);
4411
4412 return prop;
4413}
4414
4415/* Function */
4416
4417static FunctionRNA *rna_def_function(StructRNA *srna, const char *identifier)
4418{
4419 FunctionRNA *func;
4420 StructDefRNA *dsrna;
4421 FunctionDefRNA *dfunc;
4422
4423 if (DefRNA.preprocess) {
4424 const char *error = nullptr;
4425 if (!rna_validate_identifier(identifier, false, &error)) {
4426 CLOG_ERROR(&LOG, "function identifier \"%s\" - %s", identifier, error);
4427 DefRNA.error = true;
4428 }
4429 }
4430
4431 func = static_cast<FunctionRNA *>(MEM_callocN(sizeof(FunctionRNA), "FunctionRNA"));
4432 func->identifier = identifier;
4433 func->description = identifier;
4434
4435 rna_addtail(&srna->functions, func);
4436
4437 if (DefRNA.preprocess) {
4438 dsrna = rna_find_struct_def(srna);
4439 dfunc = static_cast<FunctionDefRNA *>(MEM_callocN(sizeof(FunctionDefRNA), "FunctionDefRNA"));
4440 rna_addtail(&dsrna->functions, dfunc);
4441 dfunc->func = func;
4442 }
4443 else {
4445 }
4446
4447 return func;
4448}
4449
4450FunctionRNA *RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
4451{
4452 FunctionRNA *func;
4453 FunctionDefRNA *dfunc;
4454
4455 if (BLI_findstring_ptr(&srna->functions, identifier, offsetof(FunctionRNA, identifier))) {
4456 CLOG_ERROR(&LOG, "%s.%s already defined.", srna->identifier, identifier);
4457 return nullptr;
4458 }
4459
4460 func = rna_def_function(srna, identifier);
4461
4462 if (!DefRNA.preprocess) {
4463 CLOG_ERROR(&LOG, "only at preprocess time.");
4464 return func;
4465 }
4466
4467 dfunc = rna_find_function_def(func);
4468 dfunc->call = call;
4469
4470 return func;
4471}
4472
4473FunctionRNA *RNA_def_function_runtime(StructRNA *srna, const char *identifier, CallFunc call)
4474{
4475 FunctionRNA *func;
4476
4477 func = rna_def_function(srna, identifier);
4478
4479 if (DefRNA.preprocess) {
4480 CLOG_ERROR(&LOG, "only at runtime.");
4481 return func;
4482 }
4483
4484 func->call = call;
4485
4486 return func;
4487}
4488
4490{
4491 if (ret->flag & PROP_DYNAMIC) {
4492 CLOG_ERROR(&LOG,
4493 "\"%s.%s\", dynamic values are not allowed as strict returns, "
4494 "use RNA_def_function_output instead.",
4495 func->identifier,
4496 ret->identifier);
4497 return;
4498 }
4499 if (ret->arraydimension) {
4500 CLOG_ERROR(&LOG,
4501 "\"%s.%s\", arrays are not allowed as strict returns, "
4502 "use RNA_def_function_output instead.",
4503 func->identifier,
4504 ret->identifier);
4505 return;
4506 }
4507
4508 BLI_assert(func->c_ret == nullptr);
4509 func->c_ret = ret;
4510
4512}
4513
4515{
4516 ret->flag_parameter |= PARM_OUTPUT;
4517}
4518
4520{
4521 func->flag |= flag;
4522}
4523
4524void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
4525{
4526 func->description = description;
4527}
4528
4530{
4531 PropertyType ptype = parm->type;
4532 int len = parm->totarraylength;
4533
4534 /* XXX in other parts is mentioned that strings can be dynamic as well */
4535 if (parm->flag & PROP_DYNAMIC) {
4536 return sizeof(ParameterDynAlloc);
4537 }
4538
4539 if (len > 0) {
4540 switch (ptype) {
4541 case PROP_BOOLEAN:
4542 return sizeof(bool) * len;
4543 case PROP_INT:
4544 return sizeof(int) * len;
4545 case PROP_FLOAT:
4546 return sizeof(float) * len;
4547 default:
4548 break;
4549 }
4550 }
4551 else {
4552 switch (ptype) {
4553 case PROP_BOOLEAN:
4554 return sizeof(bool);
4555 case PROP_INT:
4556 case PROP_ENUM:
4557 return sizeof(int);
4558 case PROP_FLOAT:
4559 return sizeof(float);
4560 case PROP_STRING:
4561 /* return values don't store a pointer to the original */
4562 if (parm->flag & PROP_THICK_WRAP) {
4563 StringPropertyRNA *sparm = (StringPropertyRNA *)parm;
4564 return sizeof(char) * sparm->maxlength;
4565 }
4566 else {
4567 return sizeof(char *);
4568 }
4569 case PROP_POINTER: {
4570#ifdef RNA_RUNTIME
4571 if (parm->flag_parameter & PARM_RNAPTR) {
4572 if (parm->flag & PROP_THICK_WRAP) {
4573 return sizeof(PointerRNA);
4574 }
4575 else {
4576 return sizeof(PointerRNA *);
4577 }
4578 }
4579 else {
4580 return sizeof(void *);
4581 }
4582#else
4583 if (parm->flag_parameter & PARM_RNAPTR) {
4584 if (parm->flag & PROP_THICK_WRAP) {
4585 return sizeof(PointerRNA);
4586 }
4587 return sizeof(PointerRNA *);
4588 }
4589 return sizeof(void *);
4590
4591#endif
4592 }
4593 case PROP_COLLECTION:
4594 return sizeof(ListBase);
4595 }
4596 }
4597
4598 return sizeof(void *);
4599}
4600
4601int rna_parameter_size_pad(const int size)
4602{
4603 /* Pad parameters in memory so the next parameter is properly aligned.
4604 * This silences warnings in UBSAN. More complicated logic to pack parameters
4605 * more tightly in memory is unlikely to improve performance, and aligning
4606 * to the requirements for pointers is enough for all data types we use. */
4607 const int alignment = sizeof(void *);
4608 return (size + alignment - 1) & ~(alignment - 1);
4609}
4610
4611/* Dynamic Enums */
4612
4613void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
4614{
4615 int tot = *totitem;
4616
4617 if (tot == 0) {
4618 *items = static_cast<EnumPropertyItem *>(MEM_callocN(sizeof(EnumPropertyItem[8]), __func__));
4619/* Ensure we get crashes on missing calls to 'RNA_enum_item_end', see #74227. */
4620#ifndef NDEBUG
4621 memset(*items, 0xff, sizeof(EnumPropertyItem[8]));
4622#endif
4623 }
4624 else if (tot >= 8 && (tot & (tot - 1)) == 0) {
4625 /* Power of two > 8. */
4626 *items = static_cast<EnumPropertyItem *>(
4627 MEM_recallocN_id(*items, sizeof(EnumPropertyItem) * tot * 2, __func__));
4628#ifndef NDEBUG
4629 memset((*items) + tot, 0xff, sizeof(EnumPropertyItem) * tot);
4630#endif
4631 }
4632
4633 (*items)[tot] = *item;
4634 *totitem = tot + 1;
4635}
4636
4638{
4639 static const EnumPropertyItem sepr = RNA_ENUM_ITEM_SEPR;
4640 RNA_enum_item_add(items, totitem, &sepr);
4641}
4642
4643void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
4644{
4645 for (; item->identifier; item++) {
4646 RNA_enum_item_add(items, totitem, item);
4647 }
4648}
4649
4651 int *totitem,
4652 const EnumPropertyItem *item,
4653 int value)
4654{
4655 for (; item->identifier; item++) {
4656 if (item->value == value) {
4657 RNA_enum_item_add(items, totitem, item);
4658 /* Break on first match - does this break anything?
4659 * (is quick hack to get `object->parent_type` working ok for armature/lattice). */
4660 break;
4661 }
4662 }
4663}
4664
4665void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
4666{
4667 static const EnumPropertyItem empty = {0, nullptr, 0, nullptr, nullptr};
4668 RNA_enum_item_add(items, totitem, &empty);
4669}
4670
4671/* Memory management */
4672
4673#ifdef RNA_RUNTIME
4675{
4676 if (srna->identifier) {
4677 srna->identifier = BLI_strdup(srna->identifier);
4678 if (srna->flag & STRUCT_PUBLIC_NAMESPACE) {
4679 BLI_ghash_replace_key(brna->structs_map, (void *)srna->identifier);
4680 }
4681 }
4682 if (srna->name) {
4683 srna->name = BLI_strdup(srna->name);
4684 }
4685 if (srna->description) {
4686 srna->description = BLI_strdup(srna->description);
4687 }
4688
4690}
4691
4693{
4694 if (srna->flag & STRUCT_FREE_POINTERS) {
4695 if (srna->identifier) {
4696 if (srna->flag & STRUCT_PUBLIC_NAMESPACE) {
4697 if (brna != nullptr) {
4698 BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, nullptr, nullptr);
4699 }
4700 }
4701 MEM_freeN((void *)srna->identifier);
4702 }
4703 if (srna->name) {
4704 MEM_freeN((void *)srna->name);
4705 }
4706 if (srna->description) {
4707 MEM_freeN((void *)srna->description);
4708 }
4709 }
4710}
4711
4713{
4714 if (func->identifier) {
4715 func->identifier = BLI_strdup(func->identifier);
4716 }
4717 if (func->description) {
4718 func->description = BLI_strdup(func->description);
4719 }
4720
4722}
4723
4725{
4726 if (func->flag & FUNC_FREE_POINTERS) {
4727 if (func->identifier) {
4728 MEM_freeN((void *)func->identifier);
4729 }
4730 if (func->description) {
4731 MEM_freeN((void *)func->description);
4732 }
4733 }
4734}
4735
4737{
4738 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4739 int a;
4740
4741 /* annoying since we just added this to a hash, could make this add the correct key to the hash
4742 * in the first place */
4743 if (prop->identifier) {
4744 if (cont->prophash) {
4745 prop->identifier = BLI_strdup(prop->identifier);
4746 BLI_ghash_reinsert(cont->prophash, (void *)prop->identifier, prop, nullptr, nullptr);
4747 }
4748 else {
4749 prop->identifier = BLI_strdup(prop->identifier);
4750 }
4751 }
4752
4753 if (prop->name) {
4754 prop->name = BLI_strdup(prop->name);
4755 }
4756 if (prop->description) {
4757 prop->description = BLI_strdup(prop->description);
4758 }
4759
4760 switch (prop->type) {
4761 case PROP_BOOLEAN: {
4762 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
4763
4764 if (bprop->defaultarray) {
4765 bool *array = static_cast<bool *>(
4766 MEM_mallocN(sizeof(bool) * prop->totarraylength, "RNA_def_property_store"));
4767 memcpy(array, bprop->defaultarray, sizeof(bool) * prop->totarraylength);
4768 bprop->defaultarray = array;
4769 }
4770 break;
4771 }
4772 case PROP_INT: {
4773 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
4774
4775 if (iprop->defaultarray) {
4776 int *array = static_cast<int *>(
4777 MEM_mallocN(sizeof(int) * prop->totarraylength, "RNA_def_property_store"));
4778 memcpy(array, iprop->defaultarray, sizeof(int) * prop->totarraylength);
4779 iprop->defaultarray = array;
4780 }
4781 break;
4782 }
4783 case PROP_ENUM: {
4784 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
4785
4786 if (eprop->item) {
4788 sizeof(EnumPropertyItem) * (eprop->totitem + 1), "RNA_def_property_store"));
4789 memcpy(array, eprop->item, sizeof(EnumPropertyItem) * (eprop->totitem + 1));
4790 eprop->item = array;
4791
4792 for (a = 0; a < eprop->totitem; a++) {
4793 if (array[a].identifier) {
4794 array[a].identifier = BLI_strdup(array[a].identifier);
4795 }
4796 if (array[a].name) {
4797 array[a].name = BLI_strdup(array[a].name);
4798 }
4799 if (array[a].description) {
4800 array[a].description = BLI_strdup(array[a].description);
4801 }
4802 }
4803 }
4804 break;
4805 }
4806 case PROP_FLOAT: {
4807 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
4808
4809 if (fprop->defaultarray) {
4810 float *array = static_cast<float *>(
4811 MEM_mallocN(sizeof(float) * prop->totarraylength, "RNA_def_property_store"));
4812 memcpy(array, fprop->defaultarray, sizeof(float) * prop->totarraylength);
4813 fprop->defaultarray = array;
4814 }
4815 break;
4816 }
4817 case PROP_STRING: {
4818 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
4819 if (sprop->defaultvalue) {
4820 sprop->defaultvalue = BLI_strdup(sprop->defaultvalue);
4821 }
4822 break;
4823 }
4824 default:
4825 break;
4826 }
4827
4829}
4830
4831static void (*g_py_data_clear_fn)(PropertyRNA *prop) = nullptr;
4832
4839 void (*py_data_clear_fn)(PropertyRNA *prop))
4840{
4841 g_py_data_clear_fn = py_data_clear_fn;
4842}
4843
4845{
4847 int a;
4848
4849 if (g_py_data_clear_fn) {
4850 g_py_data_clear_fn(prop);
4851 }
4852
4853 if (prop->identifier) {
4854 MEM_freeN((void *)prop->identifier);
4855 }
4856 if (prop->name) {
4857 MEM_freeN((void *)prop->name);
4858 }
4859 if (prop->description) {
4860 MEM_freeN((void *)prop->description);
4861 }
4862 if (prop->py_data) {
4863 MEM_freeN(prop->py_data);
4864 }
4865
4866 switch (prop->type) {
4867 case PROP_BOOLEAN: {
4868 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
4869 if (bprop->defaultarray) {
4870 MEM_freeN((void *)bprop->defaultarray);
4871 }
4872 break;
4873 }
4874 case PROP_INT: {
4875 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
4876 if (iprop->defaultarray) {
4877 MEM_freeN((void *)iprop->defaultarray);
4878 }
4879 break;
4880 }
4881 case PROP_FLOAT: {
4882 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
4883 if (fprop->defaultarray) {
4884 MEM_freeN((void *)fprop->defaultarray);
4885 }
4886 break;
4887 }
4888 case PROP_ENUM: {
4889 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
4890
4891 for (a = 0; a < eprop->totitem; a++) {
4892 if (eprop->item[a].identifier) {
4893 MEM_freeN((void *)eprop->item[a].identifier);
4894 }
4895 if (eprop->item[a].name) {
4896 MEM_freeN((void *)eprop->item[a].name);
4897 }
4898 if (eprop->item[a].description) {
4899 MEM_freeN((void *)eprop->item[a].description);
4900 }
4901 }
4902
4903 if (eprop->item) {
4904 MEM_freeN((void *)eprop->item);
4905 }
4906 break;
4907 }
4908 case PROP_STRING: {
4909 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
4910 if (sprop->defaultvalue) {
4911 MEM_freeN((void *)sprop->defaultvalue);
4912 }
4913 break;
4914 }
4915 default:
4916 break;
4917 }
4918 }
4919}
4920
4921static void rna_def_property_free(StructOrFunctionRNA *cont_, PropertyRNA *prop)
4922{
4923 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4924
4925 if (prop->flag_internal & PROP_INTERN_RUNTIME) {
4926 if (cont->prophash) {
4927 BLI_ghash_remove(cont->prophash, prop->identifier, nullptr, nullptr);
4928 }
4929
4931 rna_freelinkN(&cont->properties, prop);
4932 }
4933 else {
4935 }
4936}
4937
4938static PropertyRNA *rna_def_property_find_py_id(ContainerRNA *cont, const char *identifier)
4939{
4940 for (PropertyRNA *prop = static_cast<PropertyRNA *>(cont->properties.first); prop;
4941 prop = prop->next)
4942 {
4943 if (STREQ(prop->identifier, identifier)) {
4944 return prop;
4945 }
4946 }
4947 return nullptr;
4948}
4949
4950/* NOTE: only intended for removing dynamic props. */
4951int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier)
4952{
4953 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4954 PropertyRNA *prop = rna_def_property_find_py_id(cont, identifier);
4955 if (prop != nullptr) {
4956 if (prop->flag_internal & PROP_INTERN_RUNTIME) {
4957 rna_def_property_free(cont, prop);
4958 return 1;
4959 }
4960 else {
4961 return -1;
4962 }
4963 }
4964 return 0;
4965}
4966
4968 const char *identifier,
4969 void **r_handle)
4970{
4971 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4972 PropertyRNA *prop = rna_def_property_find_py_id(cont, identifier);
4973 if (prop != nullptr) {
4974 if (prop->flag_internal & PROP_INTERN_RUNTIME) {
4975 *r_handle = prop;
4976 return 1;
4977 }
4978 else {
4979 return -1;
4980 }
4981 }
4982 return 0;
4983}
4984
4986{
4987 ContainerRNA *cont = static_cast<ContainerRNA *>(cont_);
4988 PropertyRNA *prop = static_cast<PropertyRNA *>(handle);
4989 BLI_assert(BLI_findindex(&cont->properties, prop) != -1);
4991 rna_def_property_free(cont, prop);
4992}
4993
4994#endif /* RNA_RUNTIME */
4995
4997{
4998 switch (type) {
4999 case PROP_BOOLEAN:
5000 return "PROP_BOOLEAN";
5001 case PROP_INT:
5002 return "PROP_INT";
5003 case PROP_FLOAT:
5004 return "PROP_FLOAT";
5005 case PROP_STRING:
5006 return "PROP_STRING";
5007 case PROP_ENUM:
5008 return "PROP_ENUM";
5009 case PROP_POINTER:
5010 return "PROP_POINTER";
5011 case PROP_COLLECTION:
5012 return "PROP_COLLECTION";
5013 }
5014
5015 return "PROP_UNKNOWN";
5016}
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define BLI_assert(a)
Definition BLI_assert.h:50
void * BLI_ghash_lookup_default(const GHash *gh, const void *key, void *val_default) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:738
bool BLI_ghash_reinsert(GHash *gh, void *key, void *val, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:712
GHash * BLI_ghash_str_new_ex(const char *info, unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:787
void * BLI_ghash_lookup(const GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition BLI_ghash.c:731
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition BLI_ghash.c:707
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition BLI_ghash.c:860
void * BLI_ghash_replace_key(GHash *gh, void *key)
Definition BLI_ghash.c:718
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_findstring_ptr(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.c:40
unsigned short ushort
unsigned int uint
#define UNUSED_VARS(...)
#define ELEM(...)
#define POINTER_OFFSET(v, ofs)
#define STREQ(a, b)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:182
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:181
const void * DNA_default_table[SDNA_TYPE_MAX]
blenloader genfile private function prototypes
void DNA_sdna_free(struct SDNA *sdna)
const unsigned char DNAstr[]
struct SDNA * DNA_sdna_from_data(const void *data, int data_len, bool do_endian_swap, bool data_alloc, bool do_alias, const char **r_error_message)
int DNA_struct_member_size(const struct SDNA *sdna, short type, short member_index)
const int DNAlen
int DNA_struct_find_index_without_alias(const struct SDNA *sdna, const char *str)
struct ListBase ListBase
Read Guarded memory(de)allocation.
int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier)
void(*)(Main *, Scene *, PointerRNA *) RNAPropertyUpdateFunc
void RNA_def_struct_free_pointers(BlenderRNA *brna, StructRNA *srna)
#define IS_DNATYPE_BOOLEAN_COMPAT(_str)
void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA *prop)
void RNA_def_property_free_pointers_set_py_data_callback(void(*py_data_clear_fn)(PropertyRNA *prop))
#define IS_DNATYPE_FLOAT_COMPAT(_str)
void RNA_def_property_free_identifier_deferred_finish(StructOrFunctionRNA *cont_, void *handle)
#define IS_DNATYPE_INT_COMPAT(_str)
void RNA_def_func_duplicate_pointers(FunctionRNA *func)
#define RNA_MAX_ARRAY_LENGTH
Definition RNA_define.hh:23
void RNA_def_struct_duplicate_pointers(BlenderRNA *brna, StructRNA *srna)
void RNA_def_property_free_pointers(PropertyRNA *prop)
void RNA_def_func_free_pointers(FunctionRNA *func)
void(*)(bContext *C, PointerRNA *ptr, PropertyRNA *prop) RNAPropertyUpdateFuncWithContextAndProperty
int RNA_def_property_free_identifier_deferred_prepare(StructOrFunctionRNA *cont_, const char *identifier, void **handle)
void StructOrFunctionRNA
#define RNA_MAX_ARRAY_DIMENSION
Definition RNA_define.hh:26
ParameterFlag
Definition RNA_types.hh:396
@ PARM_RNAPTR
Definition RNA_types.hh:399
@ PARM_OUTPUT
Definition RNA_types.hh:398
int(*)(PointerRNA *ptr, PropertyRNA *prop) EnumPropertyGetFunc
Definition RNA_types.hh:605
void(*)(PointerRNA *ptr, PropertyRNA *prop, char *value) StringPropertyGetFunc
Definition RNA_types.hh:557
void(*)(PointerRNA *ptr, PropertyRNA *prop, bool *values) BooleanArrayPropertyGetFunc
Definition RNA_types.hh:539
PropertyScaleType
Definition RNA_types.hh:106
void(*)(PointerRNA *ptr, PropertyRNA *prop, const bool *values) BooleanArrayPropertySetFunc
Definition RNA_types.hh:540
@ FUNC_FREE_POINTERS
Definition RNA_types.hh:708
@ FUNC_RUNTIME
Definition RNA_types.hh:703
int(*)(PointerRNA *ptr, PropertyRNA *prop) StringPropertyLengthFunc
Definition RNA_types.hh:558
@ STRUCT_ID_REFCOUNT
Definition RNA_types.hh:720
@ STRUCT_RUNTIME
Definition RNA_types.hh:725
@ STRUCT_FREE_POINTERS
Definition RNA_types.hh:727
@ STRUCT_PUBLIC_NAMESPACE
Definition RNA_types.hh:735
@ STRUCT_ID
Definition RNA_types.hh:719
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
Definition RNA_types.hh:731
@ STRUCT_PUBLIC_NAMESPACE_INHERIT
Definition RNA_types.hh:737
@ STRUCT_UNDO
Definition RNA_types.hh:722
void(*)(PointerRNA *ptr, PropertyRNA *prop, float *values) FloatArrayPropertyGetFunc
Definition RNA_types.hh:551
void(*)(PointerRNA *ptr, PropertyRNA *prop, const char *value) StringPropertySetFunc
Definition RNA_types.hh:559
eStringPropertySearchFlag
Definition RNA_types.hh:570
@ PROP_STRING_SEARCH_SUPPORTED
Definition RNA_types.hh:575
void(*)(PointerRNA *ptr, PropertyRNA *prop, int *values) IntArrayPropertyGetFunc
Definition RNA_types.hh:545
void(*)(PointerRNA *ptr, PropertyRNA *prop, int value) EnumPropertySetFunc
Definition RNA_types.hh:606
void(*)(PointerRNA *ptr, PropertyRNA *prop, const int *values) IntArrayPropertySetFunc
Definition RNA_types.hh:546
PropertyType
Definition RNA_types.hh:64
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_STRING
Definition RNA_types.hh:68
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
#define RNA_ENUM_ITEM_SEPR
Definition RNA_types.hh:528
void(*)(PointerRNA *ptr, PropertyRNA *prop, int *min, int *max, int *softmin, int *softmax) IntPropertyRangeFunc
Definition RNA_types.hh:547
bool(*)(Main *bmain, StructRNA *type) StructUnregisterFunc
Definition RNA_types.hh:760
void(*)(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *edit_text, blender::FunctionRef< void(StringPropertySearchVisitParams)> visit_fn) StringPropertySearchFunc
Definition RNA_types.hh:598
bool(*)(PointerRNA *ptr, PropertyRNA *prop) BooleanPropertyGetFunc
Definition RNA_types.hh:537
void **(*)(PointerRNA *ptr) StructInstanceFunc
Definition RNA_types.hh:761
StructRNA *(*)(Main *bmain, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) StructRegisterFunc
Definition RNA_types.hh:752
#define RNA_TRANSLATION_PREC_DEFAULT
Definition RNA_types.hh:127
float(*)(PointerRNA *ptr, PropertyRNA *prop) FloatPropertyGetFunc
Definition RNA_types.hh:549
int(*)(PointerRNA *ptr, PropertyRNA *prop) IntPropertyGetFunc
Definition RNA_types.hh:543
void(*)(PointerRNA *ptr, PropertyRNA *prop, float value) FloatPropertySetFunc
Definition RNA_types.hh:550
PropertyOverrideFlag
Definition RNA_types.hh:353
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:355
void(*)( PointerRNA *ptr, PropertyRNA *prop, float *min, float *max, float *softmin, float *softmax) FloatPropertyRangeFunc
Definition RNA_types.hh:555
void(*)(PointerRNA *ptr, PropertyRNA *prop, int value) IntPropertySetFunc
Definition RNA_types.hh:544
void(*)(bContext *C, ReportList *reports, PointerRNA *ptr, ParameterList *parms) CallFunc
Definition RNA_types.hh:711
RawPropertyType
Definition RNA_types.hh:471
PropertyFlag
Definition RNA_types.hh:201
@ PROP_THICK_WRAP
Definition RNA_types.hh:312
@ PROP_DYNAMIC
Definition RNA_types.hh:317
@ PROP_ANIMATABLE
Definition RNA_types.hh:220
@ PROP_EDITABLE
Definition RNA_types.hh:207
@ PROP_ENUM_FLAG
Definition RNA_types.hh:293
@ PROP_CONTEXT_PROPERTY_UPDATE
Definition RNA_types.hh:297
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_ICONS_CONSECUTIVE
Definition RNA_types.hh:230
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:284
@ PROP_ICONS_REVERSE
Definition RNA_types.hh:231
@ PROP_HIDDEN
Definition RNA_types.hh:239
@ PROP_ID_REFCOUNT
Definition RNA_types.hh:253
@ PROP_IDPROPERTY
Definition RNA_types.hh:315
const EnumPropertyItem *(*)(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free) EnumPropertyItemFunc
Definition RNA_types.hh:608
void(*)(PointerRNA *ptr, PropertyRNA *prop, bool value) BooleanPropertySetFunc
Definition RNA_types.hh:538
void(*)(PointerRNA *ptr, PropertyRNA *prop, const float *values) FloatArrayPropertySetFunc
Definition RNA_types.hh:552
PropertySubType
Definition RNA_types.hh:135
@ PROP_MATRIX
Definition RNA_types.hh:168
@ PROP_XYZ
Definition RNA_types.hh:172
@ PROP_DISTANCE
Definition RNA_types.hh:159
@ PROP_LAYER_MEMBER
Definition RNA_types.hh:181
@ PROP_FILENAME
Definition RNA_types.hh:141
@ PROP_COLOR
Definition RNA_types.hh:163
@ PROP_ANGLE
Definition RNA_types.hh:155
@ PROP_EULER
Definition RNA_types.hh:169
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_DIRPATH
Definition RNA_types.hh:140
@ PROP_PERCENTAGE
Definition RNA_types.hh:153
@ PROP_FACTOR
Definition RNA_types.hh:154
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:175
@ PROP_TRANSLATION
Definition RNA_types.hh:164
@ PROP_XYZ_LENGTH
Definition RNA_types.hh:173
@ PROP_UNSIGNED
Definition RNA_types.hh:152
@ PROP_LAYER
Definition RNA_types.hh:180
@ PROP_FILEPATH
Definition RNA_types.hh:139
#define UI_PRECISION_FLOAT_MAX
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
local_group_size(16, 16) .push_constant(Type b
#define offsetof(t, d)
const char * DNA_struct_rename_legacy_hack_static_from_alias(const char *name)
Definition dna_utils.cc:293
int DNA_member_array_num(const char *str)
Definition dna_utils.cc:29
void DNA_alias_maps(enum eDNA_RenameDir version_dir, GHash **r_type_map, GHash **r_member_map)
Definition dna_utils.cc:193
@ DNA_RENAME_STATIC_FROM_ALIAS
Definition dna_utils.h:88
int len
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
static void refine(OpenSubdiv_Evaluator *evaluator)
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
Definition frames.inl:1166
void * rna_calloc(int buffer_size)
Definition makesrna.cc:448
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
void *(* MEM_recallocN_id)(void *vmemh, size_t len, const char *str)
Definition mallocn.cc:41
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
static ulong * next
static void error(const char *str)
return ret
void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
void * RNA_struct_py_type_get(StructRNA *srna)
PropertyRNA * RNA_def_float_factor(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_enum_items_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
PropertyRNA * RNA_def_int_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
PropertyRNA * RNA_def_float_percentage(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_define_lib_overridable(const bool make_overridable)
void RNA_def_property_struct_runtime(StructOrFunctionRNA *cont, PropertyRNA *prop, StructRNA *type)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void RNA_define_animate_sdna(bool animate)
PropertyRNA * RNA_def_boolean_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const bool *default_value, const char *ui_name, const char *ui_description)
static int DNA_struct_find_index_wrapper(const SDNA *sdna, const char *type_name)
PropertyRNA * RNA_def_float_color(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void rna_freelinkN(ListBase *listbase, void *vlink)
void RNA_def_property_string_search_func_runtime(PropertyRNA *prop, StringPropertySearchFunc search_fn, const eStringPropertySearchFlag search_flag)
void RNA_def_struct_flag(StructRNA *srna, int flag)
PropertyRNA * RNA_def_pointer_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
FunctionRNA * RNA_def_function_runtime(StructRNA *srna, const char *identifier, CallFunc call)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
const char * RNA_property_typename(PropertyType type)
const float rna_default_quaternion[4]
void RNA_def_property_float_default(PropertyRNA *prop, float value)
static void rna_remlink(ListBase *listbase, void *vlink)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
static bool rna_validate_identifier(const char *identifier, bool property, const char **r_error)
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_define_verify_sdna(bool verify)
void rna_freelistN(ListBase *listbase)
void RNA_def_property_string_search_func(PropertyRNA *prop, const char *search, const eStringPropertySearchFlag search_flag)
void RNA_def_property_enum_native_type(PropertyRNA *prop, const char *native_enum_type)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
PropertyRNA * RNA_def_float_rotation(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_float_distance(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
const int rna_matrix_dimsize_4x2[]
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
void RNA_def_property_boolean_default_func(PropertyRNA *prop, const char *get_default)
void RNA_def_struct_property_tags(StructRNA *srna, const EnumPropertyItem *prop_tag_defines)
PropertyRNA * RNA_def_float_translation(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_boolean_layer(StructOrFunctionRNA *cont_, const char *identifier, const int len, const bool *default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
PropertyRNA * RNA_def_float_matrix(StructOrFunctionRNA *cont_, const char *identifier, const int rows, const int columns, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_int_funcs_runtime(PropertyRNA *prop, IntPropertyGetFunc getfunc, IntPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
static struct @1326 g_version_data
static PropertyDefRNA * rna_def_property_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
const float rna_default_scale_3d[3]
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
#define ASSERT_SOFT_HARD_LIMITS
Definition rna_define.cc:40
void RNA_def_property_boolean_default(PropertyRNA *prop, bool value)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance)
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
void RNA_identifier_sanitize(char *identifier, int property)
void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
void RNA_def_property_enum_funcs_runtime(PropertyRNA *prop, EnumPropertyGetFunc getfunc, EnumPropertySetFunc setfunc, EnumPropertyItemFunc itemfunc)
void RNA_def_property_boolean_array_funcs_runtime(PropertyRNA *prop, BooleanArrayPropertyGetFunc getfunc, BooleanArrayPropertySetFunc setfunc)
FunctionDefRNA * rna_find_function_def(FunctionRNA *func)
void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
static int rna_member_cmp(const char *name, const char *oname)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_int_default(PropertyRNA *prop, int value)
const float rna_default_axis_angle[4]
void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable)
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
PropertyRNA * RNA_def_boolean_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const bool *default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_property_update_notifier(PropertyRNA *prop, const int noteflag)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
PropertyRNA * RNA_def_float_vector_xyz(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_py_data(PropertyRNA *prop, void *py_data)
void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_float_default_func(PropertyRNA *prop, const char *get_default)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
PropertyRNA * RNA_def_string_file_name(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
static bool debugSRNA_defaults
Definition rna_define.cc:76
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_struct_identifier_no_struct_map(StructRNA *srna, const char *identifier)
void RNA_def_property_poll_runtime(PropertyRNA *prop, const void *func)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
void RNA_def_struct_sdna_from(StructRNA *srna, const char *structname, const char *propname)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
static FunctionRNA * rna_def_function(StructRNA *srna, const char *identifier)
void RNA_def_property_update_runtime_with_context_and_property(PropertyRNA *prop, RNAPropertyUpdateFuncWithContextAndProperty func)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
const int rna_matrix_dimsize_4x4[]
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
static size_t rna_property_type_sizeof(PropertyType type)
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable)
void RNA_def_property_float_funcs_runtime(PropertyRNA *prop, FloatPropertyGetFunc getfunc, FloatPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc)
PropertyRNA * RNA_def_boolean_layer_member(StructOrFunctionRNA *cont_, const char *identifier, const int len, const bool *default_value, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_def_collection_runtime(StructOrFunctionRNA *cont_, const char *identifier, StructRNA *type, const char *ui_name, const char *ui_description)
void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structname, const char *propname)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_int_array_default(PropertyRNA *prop, const int *array)
void RNA_free(BlenderRNA *brna)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_def_function_flag(FunctionRNA *func, int flag)
static bool rna_range_from_int_type(const char *dnatype, int r_range[2])
static int rna_find_sdna_member(SDNA *sdna, const char *structname, const char *membername, DNAStructMember *smember, int *offset)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
BlenderRNA * RNA_create()
void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *rna_ext)
GHash * type_map_static_from_alias
Definition rna_define.cc:67
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
PropertyRNA * RNA_def_float_array(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
PropertyDefRNA * rna_find_parameter_def(PropertyRNA *parm)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
const int rna_matrix_dimsize_3x3[]
int rna_parameter_size(PropertyRNA *parm)
PropertyRNA * RNA_def_string_file_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_property_int_array_funcs_runtime(PropertyRNA *prop, IntArrayPropertyGetFunc getfunc, IntArrayPropertySetFunc setfunc, IntPropertyRangeFunc rangefunc)
void RNA_def_property_float_array_funcs_runtime(PropertyRNA *prop, FloatArrayPropertyGetFunc getfunc, FloatArrayPropertySetFunc setfunc, FloatPropertyRangeFunc rangefunc)
void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
static void print_default_info(const PropertyDefRNA *dp)
Definition rna_define.cc:78
BlenderDefRNA DefRNA
Definition rna_define.cc:52
PropertyRNA * RNA_def_collection(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_struct_idprops_func(StructRNA *srna, const char *idproperties)
void RNA_def_property_override_funcs(PropertyRNA *prop, const char *diff, const char *store, const char *apply)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
static CLG_LogRef LOG
Definition rna_define.cc:37
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
void RNA_def_property_ui_scale_type(PropertyRNA *prop, PropertyScaleType ui_scale_type)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_override_clear_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void RNA_enum_item_add_separator(EnumPropertyItem **items, int *totitem)
PropertyDefRNA * rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
PropertyRNA * RNA_def_string_dir_path(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
static void rna_brna_structs_add(BlenderRNA *brna, StructRNA *srna)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_boolean_array_default(PropertyRNA *prop, const bool *array)
void RNA_def_property_boolean_funcs_runtime(PropertyRNA *prop, BooleanPropertyGetFunc getfunc, BooleanPropertySetFunc setfunc)
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
static ContainerDefRNA * rna_find_container_def(ContainerRNA *cont)
StructDefRNA * rna_find_struct_def(StructRNA *srna)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_define_free(BlenderRNA *)
void RNA_def_property_tags(PropertyRNA *prop, int tags)
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
PropertyDefRNA * rna_findlink(ListBase *listbase, const char *identifier)
void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
void RNA_def_property_int_default_func(PropertyRNA *prop, const char *get_default)
static StructDefRNA * rna_find_def_struct(StructRNA *srna)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
int rna_parameter_size_pad(const int size)
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_struct_nested(BlenderRNA *brna, StructRNA *srna, const char *structname)
void RNA_define_fallback_property_update(int noteflag, const char *updatefunc)
void RNA_def_property_string_funcs_runtime(PropertyRNA *prop, StringPropertyGetFunc getfunc, StringPropertyLengthFunc lengthfunc, StringPropertySetFunc setfunc)
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void rna_addtail(ListBase *listbase, void *vlink)
Definition rna_define.cc:90
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void rna_builtin_properties_next(CollectionPropertyIterator *iter)
void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
PointerRNA rna_builtin_properties_get(CollectionPropertyIterator *iter)
PointerRNA rna_builtin_type_get(PointerRNA *ptr)
#define RNA_MAGIC
bool(*)(Main *bmain, RNAPropertyOverrideApplyContext &rnaapply_ctx) RNAPropOverrideApply
const EnumPropertyItem *(*)(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free) PropEnumItemFunc
StructRNA *(*)(PointerRNA *ptr) StructRefineFunc
void(*)(PointerRNA *ptr, float *min, float *max, float *softmin, float *softmax) PropFloatRangeFunc
void(*)(PointerRNA *ptr, bool *values) PropBooleanArrayGetFunc
void(*)(CollectionPropertyIterator *iter) PropCollectionNextFunc
int(*)(PointerRNA *ptr) PropStringLengthFunc
void(*)(CollectionPropertyIterator *iter, PointerRNA *ptr) PropCollectionBeginFunc
bool(*)(PointerRNA *ptr, int key, PointerRNA *r_ptr) PropCollectionLookupIntFunc
PointerRNA(*)(CollectionPropertyIterator *iter) PropCollectionGetFunc
IDProperty **(*)(PointerRNA *ptr) IDPropertiesFunc
void(*)(PointerRNA *ptr, const PointerRNA value, ReportList *reports) PropPointerSetFunc
@ PROP_INTERN_BUILTIN
@ PROP_INTERN_PTR_OWNERSHIP_FORCED
@ PROP_INTERN_FREE_POINTERS
@ PROP_INTERN_RUNTIME
int(*)(const PointerRNA *ptr, int index) ItemEditableFunc
bool(*)(PointerRNA *ptr, PropertyRNA *prop) PropBooleanGetFuncEx
void(*)(PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax) PropIntRangeFunc
void(*)(PointerRNA *ptr, int value) PropEnumSetFunc
int(*)(PointerRNA *ptr) PropEnumGetFunc
void(*)(Main *bmain, Scene *active_scene, PointerRNA *ptr) UpdateFunc
int(*)(const PointerRNA *ptr, const char **r_info) EditableFunc
bool(*)(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) PropCollectionLookupStringFunc
void(*)(PointerRNA *ptr, int value) PropIntSetFunc
int(*)(const PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION]) PropArrayLengthGetFunc
PointerRNA(*)(PointerRNA *ptr) PropPointerGetFunc
bool(*)(PointerRNA *ptr, const PointerRNA value) PropPointerPollFunc
void(*)(PointerRNA *ptr, PropertyRNA *prop, float *values) PropFloatArrayGetFuncEx
void(*)(PointerRNA *ptr, const float *values) PropFloatArraySetFunc
StructRNA *(*)(PointerRNA *ptr) PropPointerTypeFunc
void(*)(Main *bmain, RNAPropertyOverrideDiffContext &rnadiff_ctx) RNAPropOverrideDiff
void(*)(PointerRNA *ptr, char *value) PropStringGetFunc
void(*)(PointerRNA *ptr, bool value) PropBooleanSetFunc
bool(*)(Main *bmain, PointerRNA *ptr_local, PointerRNA *ptr_reference, PointerRNA *ptr_storage, PropertyRNA *prop_local, PropertyRNA *prop_reference, PropertyRNA *prop_storage, int len_local, int len_reference, int len_storage, IDOverrideLibraryPropertyOperation *opop) RNAPropOverrideStore
std::optional< std::string >(*)(const PointerRNA *ptr) StructPathFunc
int(*)(PointerRNA *ptr) PropCollectionLengthFunc
#define CONTAINER_RNA_ID(cont)
void(*)(PointerRNA *ptr, PropertyRNA *prop, int *values) PropIntArrayGetFuncEx
void(*)(PointerRNA *ptr, PropertyRNA *prop, bool *values) PropBooleanArrayGetFuncEx
void(*)(PointerRNA *ptr, const bool *values) PropBooleanArraySetFunc
bool(*)(PointerRNA *ptr) PropBooleanGetFunc
bool(*)(PointerRNA *ptr, int key, const PointerRNA *assign_ptr) PropCollectionAssignIntFunc
void(*)(PointerRNA *ptr, int *values) PropIntArrayGetFunc
void(*)(PointerRNA *ptr, float value) PropFloatSetFunc
void(*)(PointerRNA *ptr, const int *values) PropIntArraySetFunc
int(*)(PointerRNA *ptr, PropertyRNA *prop) PropIntGetFuncEx
int(*)(PointerRNA *ptr) PropIntGetFunc
float(*)(PointerRNA *ptr, PropertyRNA *prop) PropFloatGetFuncEx
void(*)(PointerRNA *ptr, const char *value) PropStringSetFunc
float(*)(PointerRNA *ptr) PropFloatGetFunc
void(*)(PointerRNA *ptr, float *values) PropFloatArrayGetFunc
void(*)(CollectionPropertyIterator *iter) PropCollectionEndFunc
#define min(a, b)
Definition sort.c:32
#define FLT_MAX
Definition stdcycles.h:14
unsigned int uint32_t
Definition stdint.h:80
__int64 int64_t
Definition stdint.h:89
#define INT8_MIN
Definition stdint.h:132
#define INT8_MAX
Definition stdint.h:133
struct StructRNA * laststruct
struct SDNA * sdna
const char * updatefunc
struct BlenderDefRNA::@1327::@1328 property_update
struct BlenderDefRNA::@1327 fallback
unsigned int structs_len
PropBooleanGetFuncEx get_default
PropBooleanArraySetFuncEx setarray_ex
PropBooleanArrayGetFuncEx getarray_ex
PropBooleanArraySetFunc setarray
const bool * defaultarray
PropBooleanArrayGetFuncEx get_default_array
PropBooleanSetFunc set
PropBooleanGetFunc get
PropBooleanSetFuncEx set_ex
PropBooleanGetFuncEx get_ex
PropBooleanArrayGetFunc getarray
PropCollectionNextFunc next
PropCollectionLookupStringFunc lookupstring
PropCollectionLengthFunc length
PropCollectionLookupIntFunc lookupint
PropCollectionBeginFunc begin
PropCollectionAssignIntFunc assignint
PropCollectionEndFunc end
PropCollectionGetFunc get
ListBase properties
struct GHash * prophash
const char * type
const char * name
const char * identifier
Definition RNA_types.hh:506
const char * name
Definition RNA_types.hh:510
const char * description
Definition RNA_types.hh:512
const EnumPropertyItem * item
PropEnumSetFuncEx set_ex
PropEnumGetFunc get
const char * native_enum_type
PropEnumItemFunc item_fn
PropEnumGetFuncEx get_ex
PropEnumSetFunc set
StructFreeFunc free
Definition RNA_types.hh:782
PropFloatSetFuncEx set_ex
PropertyScaleType ui_scale_type
PropFloatGetFunc get
PropFloatRangeFuncEx range_ex
PropFloatArrayGetFuncEx getarray_ex
PropFloatArraySetFuncEx setarray_ex
PropFloatArrayGetFunc getarray
PropFloatGetFuncEx get_default
PropFloatSetFunc set
const float * defaultarray
PropFloatRangeFunc range
PropFloatArraySetFunc setarray
PropFloatGetFuncEx get_ex
PropFloatArrayGetFuncEx get_default_array
FunctionRNA * func
ContainerDefRNA cont
const char * call
const char * identifier
PropertyRNA * c_ret
ContainerRNA cont
const char * description
PropIntRangeFuncEx range_ex
PropIntArrayGetFunc getarray
PropIntArrayGetFuncEx getarray_ex
PropIntRangeFunc range
PropIntArraySetFunc setarray
PropIntGetFuncEx get_ex
PropIntArrayGetFuncEx get_default_array
PropIntArraySetFuncEx setarray_ex
PropertyScaleType ui_scale_type
PropIntGetFuncEx get_default
PropIntSetFuncEx set_ex
void * last
void * first
PropPointerTypeFunc type_fn
PropPointerGetFunc get
PropPointerPollFunc poll
PropPointerSetFunc set
ContainerRNA * cont
const char * dnatype
const char * dnaname
const char * dnastructfromprop
const char * dnastructname
const char * dnalengthstructname
const char * dnalengthname
const char * dnastructfromname
PropertyDefRNA * prev
PropertyRNA * prop
ItemEditableFunc itemeditable
PropArrayLengthGetFunc getlength
const char * translation_context
RNAPropOverrideApply override_apply
unsigned int arraydimension
EditableFunc editable
RNAPropOverrideStore override_store
PropertyRNA * next
RNAPropOverrideDiff override_diff
PropertySubType subtype
unsigned int arraylength[RNA_MAX_ARRAY_DIMENSION]
const char * description
const char * name
unsigned int totarraylength
const char * identifier
RawPropertyType rawtype
PropertyType type
SDNA_StructMember members[]
const char ** members
struct SDNA::@1177 alias
SDNA_Struct ** structs
const char ** types
PropStringSetFunc set
PropStringLengthFuncEx length_ex
PropStringLengthFunc length
PropStringGetFuncEx get_ex
PropStringSetFuncEx set_ex
PropStringGetFunc get
StringPropertySearchFunc search
eStringPropertySearchFlag search_flag
const char * dnaname
ContainerDefRNA cont
StructRNA * srna
ListBase functions
const char * dnafromprop
const char * dnafromname
StructRNA * nested
StructRegisterFunc reg
StructUnregisterFunc unreg
const char * name
const char * identifier
StructInstanceFunc instance
ContainerRNA cont
const char * translation_context
const EnumPropertyItem * prop_tag_defines
PropertyRNA * nameproperty
const char * description
IDPropertiesFunc idproperties
PropertyRNA * iteratorproperty
StructRNA * base
StructRefineFunc refine
StructPathFunc path
uint8_t flag
Definition wm_window.cc:138