Blender V5.3
rna_access.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
8
9#include <cstddef>
10#include <cstdint>
11#include <cstring>
12#include <limits>
13#include <sstream>
14
15#include <fmt/format.h>
16
17#include "MEM_guardedalloc.h"
18
19#include "DNA_ID.h"
20#include "DNA_anim_types.h"
21#include "DNA_scene_types.h"
23
24#include "BLI_dynstr.hh"
25#include "BLI_listbase.hh"
26#include "BLI_math_base_c.hh"
27#include "BLI_mutex.hh"
28#include "BLI_string.hh"
29#include "BLI_string_utf8.hh"
30#include "BLI_utildefines.hh"
31
32#include "BLT_translation.hh"
33
34#include "BKE_anim_data.hh"
35#include "BKE_collection.hh"
36#include "BKE_context.hh"
37#include "BKE_fcurve.hh"
38#include "BKE_global.hh"
39#include "BKE_idprop.hh"
40#include "BKE_idtype.hh"
41#include "BKE_lib_id.hh"
42#include "BKE_lib_override.hh"
43#include "BKE_library.hh"
44#include "BKE_main.hh"
45#include "BKE_node.hh"
46#include "BKE_report.hh"
47
48#include "CLG_log.h"
49
50#include "DEG_depsgraph.hh"
52
53#include "RNA_access.hh"
54#include "RNA_define.hh"
55#include "RNA_enum_types.hh"
56#include "RNA_path.hh"
57#include "RNA_prototypes.hh"
58#include "RNA_types.hh"
59
60#include "UI_resources.hh"
61
62#include "WM_api.hh"
63#include "WM_message.hh"
64
65/* flush updates */
66#include "WM_types.hh"
67
68#ifdef WITH_PYTHON
69# include "BPY_extern.hh"
70#endif
71
73#include "rna_internal.hh"
74
75namespace blender {
76
77static CLG_LogRef LOG = {"rna.access"};
78
84#define USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
85
86/* Init/Exit */
87
89{
91
92 brna.structs_map.reserve(2048);
93
94 for (std::unique_ptr<StructRNA> &srna : RNA_blender_rna_get().structs) {
95 if (!srna->cont.prop_lookup_set) {
96 srna->cont.prop_lookup_set =
97 MEM_new<CustomIDVectorSet<PropertyRNA *, PropertyRNAIdentifierGetter>>(__func__);
98
99 for (PropertyRNA &prop : srna->cont.properties) {
100 if (!(prop.flag_internal & PROP_INTERN_BUILTIN)) {
101 srna->cont.prop_lookup_set->add(&prop);
102 }
103 }
104 }
106 brna.structs_map.add(srna->identifier, srna.get());
107 }
108}
109
111{
112#ifdef WITH_PYTHON
113 for (std::unique_ptr<StructRNA> &srna : RNA_blender_rna_get().structs) {
114 /* NOTE(@ideasman42): each call locks the Python's GIL. Only locking/unlocking once
115 * is possible but gives barely measurable speedup (< ~1millisecond) so leave as-is. */
116 BPY_free_srna_pytype(srna.get());
117 }
118#endif
119}
120
122{
123 for (std::unique_ptr<StructRNA> &srna : RNA_blender_rna_get().structs) {
124 MEM_SAFE_DELETE(srna->cont.prop_lookup_set);
125 }
126
128}
129
130/* Pointer */
131
133{
134 while (r_ptr.type->refine) {
135 StructRNA *type = r_ptr.type->refine(&r_ptr);
136 if (type == r_ptr.type) {
137 break;
138 }
139 r_ptr.type = type;
140 }
141}
142
144 StructRNA *type,
145 void *data,
146 PointerRNA &r_ptr)
147{
148 if (data) {
149 if (type && type->flag & STRUCT_ID) {
150 /* Currently, assume that an ID PointerRNA never has an ancestor.
151 * NOTE: This may become an issue for embedded IDs in the future, see also
152 * #PointerRNA::ancestors docs. */
153 r_ptr = {static_cast<ID *>(data), type, data};
154 }
155 else {
156 r_ptr = {parent.owner_id, type, data, parent};
157 }
158 rna_pointer_refine(r_ptr);
159 }
160 else {
161 r_ptr = {};
162 }
163}
164
166{
167 return {nullptr, RNA_BlendData, main};
168}
169
171{
172 if (id) {
173 PointerRNA ptr{id, ID_code_to_RNA_type(id->id_type()), id};
175 return ptr;
176 }
177
178 return {};
179}
180
182{
183 PointerRNA ptr{id, type, data};
184
185 if (data) {
187 }
188
189 return ptr;
190}
191
193{
196 return result;
197}
198
206
207PointerRNA RNA_pointer_create_from_ancestor(const PointerRNA &ptr, const int ancestor_idx)
208{
209 if (ancestor_idx >= ptr.ancestors.size()) {
211 return {};
212 }
213
214 /* NOTE: No call to `rna_pointer_refine` should be needed here, as ancestors info should have
215 * been created from already refined PointerRNA data. */
216 PointerRNA ancestor_ptr{ptr.owner_id,
217 ptr.ancestors[ancestor_idx].type,
218 ptr.ancestors[ancestor_idx].data,
219 ptr.ancestors.as_span().slice(0, ancestor_idx)};
220#ifndef NDEBUG
221 StructRNA *type = ancestor_ptr.type;
222 rna_pointer_refine(ancestor_ptr);
223 BLI_assert(type == ancestor_ptr.type);
224#endif
225
226 return ancestor_ptr;
227}
228
230{
231 PointerRNA ptr = {};
232 ptr.owner_id = nullptr;
233 ptr.type = RNA_BlenderRNA;
234 ptr.data = &RNA_blender_rna_get();
235 return ptr;
236}
237
239{
240#if 0 /* works but this case if covered by more general code below. */
241 if (RNA_struct_is_ID(ptr->type)) {
242 /* simple case */
243 return RNA_id_pointer_create(ptr->owner_id);
244 }
245 else
246#endif
247 {
248 PointerRNA ptr_result{*ptr};
249 PointerRNA t_ptr{*ptr};
250 StructRNA *base;
251
252 for (base = ptr->type->base; base; base = base->base) {
253 t_ptr.type = base;
254 rna_pointer_refine(t_ptr);
255 if (t_ptr.has_type() && t_ptr.type != ptr->type) {
256 ptr_result = t_ptr;
257 }
258 }
259 return ptr_result;
260 }
261}
262
263/* ID Properties */
264
266{
267 /* so the property is seen as 'set' by rna */
268 idprop->flag &= ~IDP_FLAG_GHOST;
269}
270
272{
273 StructRNA *type = ptr->type;
274 if (type == nullptr) {
275 return nullptr;
276 }
277 if (type->idproperties == nullptr) {
278 return nullptr;
279 }
280
281 return type->idproperties(ptr);
282}
283
285{
286 IDProperty **property_ptr = RNA_struct_idprops_p(ptr);
287 if (property_ptr == nullptr) {
288 return nullptr;
289 }
290
291 if (create && *property_ptr == nullptr) {
292 *property_ptr = bke::idprop::create_group("user_properties", IDP_FLAG_STATIC_TYPE).release();
293 }
294
295 return *property_ptr;
296}
297
299{
300 return (srna && srna->idproperties);
301}
302
304{
305 IDProperty *group = RNA_struct_idprops(ptr, false);
306
307 if (!group) {
308 return nullptr;
309 }
310 if (group->type == IDP_GROUP) {
311 return IDP_GetPropertyFromGroup(group, name);
312 }
313
314 /* Not sure why that happens sometimes, with nested properties... */
315 /* Seems to be actually array prop, name is usually "0"... To be sorted out later. */
316#if 0
317 printf("Got unexpected IDProp container when trying to retrieve %s: %d\n", name, group->type);
318#endif
319
320 return nullptr;
321}
322
324{
325 StructRNA *type = ptr->type;
326 if (type == nullptr) {
327 return nullptr;
328 }
329 if (type->system_idproperties == nullptr) {
330 return nullptr;
331 }
332
333 return type->system_idproperties(ptr);
334}
335
337{
338 IDProperty **property_ptr = RNA_struct_system_idprops_p(ptr);
339 if (property_ptr == nullptr) {
340 return nullptr;
341 }
342
343 if (create && *property_ptr == nullptr) {
344 *property_ptr = bke::idprop::create_group("system_properties", IDP_FLAG_STATIC_TYPE).release();
345 }
346
347 return *property_ptr;
348}
349
351{
352 return (srna && srna->system_idproperties);
353}
354
356{
357 IDProperty *group = RNA_struct_system_idprops(ptr, false);
358
359 if (!group) {
360 return nullptr;
361 }
362
363 if (group->type == IDP_GROUP) {
364 return IDP_GetPropertyFromGroup(group, name);
365 }
366
367 /* Not sure why that happens sometimes, with nested properties... */
368 /* Seems to be actually array prop, name is usually "0"... To be sorted out later. */
369#if 0
370 printf("Got unexpected IDProp container when trying to retrieve %s: %d\n", name, group->type);
371#endif
372
373 return nullptr;
374}
375
376static void rna_system_idproperty_free(PointerRNA *ptr, const char *name)
377{
378 IDProperty *group = RNA_struct_system_idprops(ptr, false);
379
380 if (group) {
382 if (idprop) {
384 }
385 }
386}
387
389{
390 if (prop->magic == RNA_MAGIC) {
391 int arraylen[RNA_MAX_ARRAY_DIMENSION];
392 if (prop->getlength && *ptr) {
394 return prop->getlength(ptr, arraylen);
395 }
396 else {
397 return int(prop->totarraylength);
398 }
399 }
400
401 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
402 if (idprop->type == IDP_ARRAY) {
403 return idprop->len;
404 }
405 return 0;
406}
407
409{
410 if (prop->magic == RNA_MAGIC) {
411 return (prop->getlength || prop->totarraylength);
412 }
413 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
414
415 return (idprop->type == IDP_ARRAY);
416}
417
419 PropertyRNA *prop,
420 int length[])
421{
422 if (prop->magic == RNA_MAGIC) {
423 if (prop->getlength) {
425 prop->getlength(ptr, length);
426 }
427 else {
428 memcpy(length, prop->arraylength, prop->arraydimension * sizeof(int));
429 }
430 }
431 else {
432 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
433
434 if (idprop->type == IDP_ARRAY) {
435 length[0] = idprop->len;
436 }
437 else {
438 length[0] = 0;
439 }
440 }
441}
442
444{
445 /* this verifies if the idproperty actually matches the property
446 * description and otherwise removes it. this is to ensure that
447 * rna property access is type safe, e.g. if you defined the rna
448 * to have a certain array length you can count on that staying so */
449
450 switch (idprop->type) {
451 case IDP_IDPARRAY:
452 if (prop->type != PROP_COLLECTION) {
453 return false;
454 }
455 break;
456 case IDP_ARRAY:
457 if (rna_ensure_property_array_length(ptr, prop) != idprop->len) {
458 return false;
459 }
460
461 if (idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT) {
462 return false;
463 }
464 if (idprop->subtype == IDP_BOOLEAN && prop->type != PROP_BOOLEAN) {
465 return false;
466 }
467 if (idprop->subtype == IDP_INT && !ELEM(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM)) {
468 return false;
469 }
470
471 break;
472 case IDP_INT:
473 if (!ELEM(prop->type, PROP_BOOLEAN, PROP_INT, PROP_ENUM)) {
474 return false;
475 }
476 break;
477 case IDP_BOOLEAN:
478 if (prop->type != PROP_BOOLEAN) {
479 return false;
480 }
481 break;
482 case IDP_FLOAT:
483 case IDP_DOUBLE:
484 if (prop->type != PROP_FLOAT) {
485 return false;
486 }
487 break;
488 case IDP_STRING:
489 if (prop->type != PROP_STRING) {
490 return false;
491 }
492 break;
493 case IDP_GROUP:
494 case IDP_ID:
495 if (prop->type != PROP_POINTER) {
496 return false;
497 }
498 break;
499 default:
500 return false;
501 }
502
503 return true;
504}
505
507 &rna_PropertyGroupItem_string,
508 &rna_PropertyGroupItem_int,
509 &rna_PropertyGroupItem_float,
510 nullptr,
511 nullptr,
512 nullptr,
513 &rna_PropertyGroupItem_group,
514 &rna_PropertyGroupItem_id,
515 &rna_PropertyGroupItem_double,
516 &rna_PropertyGroupItem_idp_array,
517 &rna_PropertyGroupItem_bool,
518};
519
521 nullptr,
522 &rna_PropertyGroupItem_int_array,
523 &rna_PropertyGroupItem_float_array,
524 nullptr,
525 nullptr,
526 nullptr,
527 &rna_PropertyGroupItem_collection,
528 nullptr,
529 &rna_PropertyGroupItem_double_array,
530 nullptr,
531 &rna_PropertyGroupItem_bool_array,
532};
533
535{
536 const bool is_meta_type = ptr.type && (ptr.type->flag & STRUCT_RNA_DEFINITION) != 0;
537 const bool is_prop_of_meta_type = (prop.flag_internal & PROP_INTERN_RNA_DEFINITION) != 0;
538 const bool is_prop_builtin = (prop.flag_internal & PROP_INTERN_BUILTIN) != 0;
539 BLI_assert((prop.magic == RNA_MAGIC && (prop.flag & PROP_IDPROPERTY) == 0) || !is_meta_type);
540 /* Builtin props (`Struct::properties` only currently?) are always accessible.
541 * Any property should be accessible in a non-meta type PointerRNA, even the meta-type ones.
542 * Only properties of meta-types should be accessible in a meta-type. */
543 return is_prop_builtin || !is_meta_type || is_prop_of_meta_type;
544}
545
547 PointerRNA *ptr,
548 PropertyRNAOrID *r_prop_rna_or_id)
549{
550 /* This is quite a hack, but avoids some complexity in the API. we
551 * pass IDProperty structs as PropertyRNA pointers to the outside.
552 * We store some bytes in PropertyRNA structs that allows us to
553 * distinguish it from IDProperty structs. If it is an ID property,
554 * we look up an IDP PropertyRNA based on the type, and set the data
555 * pointer to the IDProperty. */
556 *r_prop_rna_or_id = {};
557
558 r_prop_rna_or_id->ptr = ptr;
559 r_prop_rna_or_id->rawprop = prop;
560
561 const bool is_ptr_data_usable = rna_property_can_access_pointer_data(*ptr, *prop);
562
563 if (prop->magic == RNA_MAGIC) {
564 r_prop_rna_or_id->rnaprop = prop;
565 r_prop_rna_or_id->identifier = prop->identifier;
566
567 r_prop_rna_or_id->is_array = prop->getlength || prop->totarraylength;
568 if (r_prop_rna_or_id->is_array) {
569 int arraylen[RNA_MAX_ARRAY_DIMENSION];
570 /* Do not call actual data callbacks on definition data (i.e. it `ptr` is a struct or
571 * property definition, and not the actual data type). See e.g. #161362. */
572 r_prop_rna_or_id->array_len = (prop->getlength && *ptr && is_ptr_data_usable) ?
573 uint(prop->getlength(ptr, arraylen)) :
574 prop->totarraylength;
575 }
576
577 if (prop->flag & PROP_IDPROPERTY) {
579
580 if (idprop != nullptr && !rna_idproperty_verify_valid(ptr, prop, idprop)) {
581 IDProperty *group = RNA_struct_system_idprops(ptr, false);
582
584 idprop = nullptr;
585 }
586
587 r_prop_rna_or_id->idprop = idprop;
588 r_prop_rna_or_id->is_rna_storage_idprop = true;
589 r_prop_rna_or_id->is_set = idprop != nullptr && (idprop->flag & IDP_FLAG_GHOST) == 0;
590 }
591 else {
592 /* Full static RNA properties are always set. */
593 r_prop_rna_or_id->is_set = true;
594 }
595 }
596 else {
597 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
598 /* Given prop may come from the custom properties of another data, ensure we get the one from
599 * given data ptr. */
600 IDProperty *idprop_evaluated = rna_idproperty_find(ptr, idprop->name);
601 if (idprop_evaluated != nullptr && idprop->type != idprop_evaluated->type) {
602 idprop_evaluated = nullptr;
603 }
604
605 r_prop_rna_or_id->idprop = idprop_evaluated;
606 r_prop_rna_or_id->is_idprop = true;
607 /* Full IDProperties are always set, if it exists. */
608 r_prop_rna_or_id->is_set = (idprop_evaluated != nullptr);
609
610 r_prop_rna_or_id->identifier = UString(idprop->name);
611 if (idprop->type == IDP_ARRAY) {
612 r_prop_rna_or_id->rnaprop = arraytypemap[int(idprop->subtype)];
613 r_prop_rna_or_id->is_array = true;
614 r_prop_rna_or_id->array_len = idprop_evaluated != nullptr ? uint(idprop_evaluated->len) : 0;
615 }
616 else {
617 /* Special case for int properties with enum items, these are displayed as a PROP_ENUM. */
618 if (idprop->type == IDP_INT) {
619 const IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(
620 idprop->ui_data);
621 if (ui_data_int && ui_data_int->enum_items_num > 0) {
622 r_prop_rna_or_id->rnaprop = &rna_PropertyGroupItem_enum;
623 return;
624 }
625 }
626 r_prop_rna_or_id->rnaprop = typemap[int(idprop->type)];
627 }
628 }
629}
630
632{
633 PropertyRNAOrID prop_rna_or_id;
634
635 rna_property_rna_or_id_get(*prop, ptr, &prop_rna_or_id);
636
637 *prop = prop_rna_or_id.rnaprop;
638 return prop_rna_or_id.idprop;
639}
640
642{
643 /* the quick version if we don't need the idproperty */
644
645 if (prop->magic == RNA_MAGIC) {
646 return prop;
647 }
648
649 {
650 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
651
652 if (idprop->type == IDP_ARRAY) {
653 return arraytypemap[int(idprop->subtype)];
654 }
655 /* Special case for int properties with enum items, these are displayed as a PROP_ENUM. */
656 if (idprop->type == IDP_INT) {
657 const IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(
658 idprop->ui_data);
659 if (ui_data_int && ui_data_int->enum_items_num > 0) {
660 return &rna_PropertyGroupItem_enum;
661 }
662 }
663 return typemap[int(idprop->type)];
664 }
665}
666
667static const char *rna_ensure_property_identifier(const PropertyRNA *prop)
668{
669 if (prop->magic == RNA_MAGIC) {
670 return prop->identifier.c_str();
671 }
672 return (reinterpret_cast<const IDProperty *>(prop))->name;
673}
674
675static const char *rna_ensure_property_description(const PropertyRNA *prop)
676{
677 if (prop->magic == RNA_MAGIC) {
678 return prop->description;
679 }
680
681 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
682 if (idprop->ui_data) {
683 const IDPropertyUIData *ui_data = idprop->ui_data;
684 return ui_data->description;
685 }
686
687 return "";
688}
689
690static const char *rna_ensure_property_name(const PropertyRNA *prop)
691{
692 const char *name;
693
694 if (prop->magic == RNA_MAGIC) {
695 name = prop->name;
696 }
697 else {
698 name = (reinterpret_cast<const IDProperty *>(prop))->name;
699 }
700
701 return name;
702}
703
704/* Structs */
705
706StructRNA *RNA_struct_find(const char *identifier)
707{
708 return RNA_blender_rna_get().structs_map.lookup_default(UString(identifier), nullptr);
709}
710
711const char *RNA_struct_identifier(const StructRNA *type)
712{
713 return type->identifier.c_str();
714}
715
716const char *RNA_struct_ui_name(const StructRNA *type)
717{
718 return CTX_IFACE_(type->translation_context, type->name);
719}
720
721const char *RNA_struct_ui_name_raw(const StructRNA *type)
722{
723 return type->name;
724}
725
727{
728 if (type) {
729 return type->icon;
730 }
731 return ICON_DOT;
732}
733
734const char *RNA_struct_ui_description(const StructRNA *type)
735{
736 return TIP_(type->description);
737}
738
740{
741 return type->description;
742}
743
745{
746 return type->translation_context;
747}
748
750{
751 return type->nameproperty;
752}
753
755{
756 return type->prop_tag_defines;
757}
758
763
764std::string RNA_struct_to_string(const StructRNA &type)
765{
766 fmt::memory_buffer buf;
767 fmt::appender dst{buf};
768 fmt::format_to(dst, "Type: {}\n", type.identifier);
769
770 for (const PropertyRNA &prop : type.cont.properties) {
771 fmt::format_to(dst, " {}\n", RNA_property_identifier(&prop));
772 }
773
774 return fmt::to_string(buf);
775}
776
778{
779 return type->base;
780}
781
782const StructRNA *RNA_struct_base_child_of(const StructRNA *type, const StructRNA *parent_type)
783{
784 while (type) {
785 if (type->base == parent_type) {
786 return type;
787 }
788 type = type->base;
789 }
790 return nullptr;
791}
792
794{
795 return (type->flag & STRUCT_ID) != 0;
796}
797
799{
800 return (type->flag & STRUCT_PUBLIC_NAMESPACE) != 0;
801}
802
807
812
814{
815 return (type->flag & STRUCT_NO_IDPROPERTIES) == 0 && type->system_idproperties != nullptr;
816}
817
818bool RNA_struct_system_idprops_unset(PointerRNA *ptr, const char *identifier)
819{
820 IDProperty *group = RNA_struct_system_idprops(ptr, false);
821
822 if (group) {
823 IDProperty *idp = IDP_GetPropertyFromGroup(group, identifier);
824 if (idp) {
825 IDP_FreeFromGroup(group, idp);
826
827 return true;
828 }
829 }
830 return false;
831}
832
833bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
834{
835 const StructRNA *base;
836
837 if (srna == RNA_AnyType) {
838 return true;
839 }
840
841 if (!type) {
842 return false;
843 }
844
845 /* ptr->type is always maximally refined */
846 for (base = type; base; base = base->base) {
847 if (base == srna) {
848 return true;
849 }
850 }
851
852 return false;
853}
854
855PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
856{
857 if (identifier[0] == '[' && identifier[1] == '"') {
858 /* id prop lookup, not so common */
859 PropertyRNA *prop_test = nullptr;
860 PointerRNA ptr_test; /* only support single level props */
861 if (RNA_path_resolve_property(ptr, identifier, &ptr_test, &prop_test) &&
862 (ptr_test.type == ptr->type) && (ptr_test.data == ptr->data))
863 {
864 return prop_test;
865 }
866 }
867 else {
868 return RNA_struct_find_property(ptr, UString(identifier));
869 }
870
871 return nullptr;
872}
873
875{
876 StructRNA *srna = ptr->type;
877 do {
878 if (srna->cont.prop_lookup_set) {
879 if (PropertyRNA *const *prop = srna->cont.prop_lookup_set->lookup_key_ptr_as(identifier)) {
880 return *prop;
881 }
882 }
883 else {
884 for (PropertyRNA &prop : srna->cont.properties) {
885 if (!(prop.flag_internal & PROP_INTERN_BUILTIN) && prop.identifier == identifier) {
886 return &prop;
887 }
888 }
889 }
890 } while ((srna = srna->base));
891
892 return nullptr;
893}
894
895static const char *rna_property_type_identifier(PropertyType prop_type)
896{
897 switch (prop_type) {
898 case PROP_BOOLEAN:
899 return RNA_struct_identifier(RNA_BoolProperty);
900 case PROP_INT:
901 return RNA_struct_identifier(RNA_IntProperty);
902 case PROP_FLOAT:
903 return RNA_struct_identifier(RNA_FloatProperty);
904 case PROP_STRING:
905 return RNA_struct_identifier(RNA_StringProperty);
906 case PROP_ENUM:
907 return RNA_struct_identifier(RNA_EnumProperty);
908 case PROP_POINTER:
909 return RNA_struct_identifier(RNA_PointerProperty);
910 case PROP_COLLECTION:
911 return RNA_struct_identifier(RNA_CollectionProperty);
912 default:
913 return RNA_struct_identifier(RNA_Property);
914 }
915}
916
918 const char *name,
919 const PropertyType property_type_check)
920{
921 PropertyRNA *prop = RNA_struct_find_property(&props, name);
922 if (!prop) {
923 return nullptr;
924 }
925 const PropertyType prop_type = RNA_property_type(prop);
926 if (prop_type == property_type_check) {
927 return prop;
928 }
929 CLOG_WARN(&LOG,
930 "'%s : %s()' expected, got '%s : %s()'",
931 name,
932 rna_property_type_identifier(property_type_check),
933 name,
935 return nullptr;
936}
937
939 const char *name,
940 const StructRNA *struct_type_check)
941{
942 PropertyRNA *prop = RNA_struct_find_property(&props, name);
943 if (!prop) {
944 return nullptr;
945 }
946
947 const PropertyType prop_type = RNA_property_type(prop);
948 const StructRNA *prop_struct_type = RNA_property_pointer_type(&props, prop);
949 if (prop_type == PROP_COLLECTION && prop_struct_type == struct_type_check) {
950 return prop;
951 }
952
953 if (prop_type != PROP_COLLECTION) {
954 CLOG_WARN(&LOG,
955 "'%s : %s(type = %s)' expected, got '%s : %s()'",
956 name,
958 RNA_struct_identifier(struct_type_check),
959 name,
961 return nullptr;
962 }
963
964 CLOG_WARN(&LOG,
965 "'%s : %s(type = %s)' expected, got '%s : %s(type = %s)'.",
966 name,
968 RNA_struct_identifier(struct_type_check),
969 name,
971 RNA_struct_identifier(prop_struct_type));
972 return nullptr;
973}
974
976{
977 PropertyRNA *prop = nullptr;
978
979 RNA_STRUCT_BEGIN (ptr, iprop) {
980 /* This assumes that there can only be one user of this nested struct */
981 if (RNA_property_pointer_type(ptr, iprop) == srna) {
982 prop = iprop;
983 break;
984 }
985 }
987
988 return prop;
989}
990
992{
993 /* NOTE: prop_test could be freed memory, only use for comparison. */
994
995 /* validate the RNA is ok */
996 PropertyRNA *iterprop;
997 bool found = false;
998
999 iterprop = RNA_struct_iterator_property(ptr->type);
1000
1001 RNA_PROP_BEGIN (ptr, itemptr, iterprop) {
1002 // PropertyRNA *prop = itemptr.data;
1003 if (prop_test == static_cast<PropertyRNA *>(itemptr.data)) {
1004 found = true;
1005 break;
1006 }
1007 }
1009
1010 return found;
1011}
1012
1014{
1015 uint counter = 0;
1016
1017 PointerRNA struct_ptr = RNA_pointer_create_discrete(nullptr, srna, nullptr);
1018
1019 RNA_STRUCT_BEGIN (&struct_ptr, prop) {
1020 counter++;
1021 UNUSED_VARS(prop);
1022 }
1024
1025 return counter;
1026}
1027
1028std::optional<AncestorPointerRNA> RNA_struct_search_closest_ancestor_by_type(const PointerRNA *ptr,
1029 const StructRNA *srna)
1030{
1031 if (RNA_struct_is_a(ptr->type, srna)) {
1032 return {{ptr->type, ptr->data}};
1033 }
1034 else {
1035 for (int i = ptr->ancestors.size() - 1; i >= 0; i--) {
1036 const AncestorPointerRNA &ancestor = ptr->ancestors[i];
1037 if (RNA_struct_is_a(ancestor.type, srna)) {
1038 return ancestor;
1039 }
1040 }
1041 }
1042
1043 return std::nullopt;
1044}
1045
1046const ListBaseT<PropertyRNA> *RNA_struct_type_properties(StructRNA *srna)
1047{
1048 return &srna->cont.properties;
1049}
1050
1052{
1053 for (PropertyRNA &prop : srna->cont.properties) {
1054 if (prop.identifier == identifier) {
1055 return &prop;
1056 }
1057 }
1058 return nullptr;
1059}
1060
1062{
1063 const UString identifier_ustr(identifier);
1064 for (; srna; srna = srna->base) {
1065 PropertyRNA *prop = RNA_struct_type_find_property_no_base(srna, identifier_ustr);
1066 if (prop != nullptr) {
1067 return prop;
1068 }
1069 }
1070 return nullptr;
1071}
1072
1073FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier_c_str)
1074{
1075#if 1
1076 const UString identifier(identifier_c_str);
1077 for (; srna; srna = srna->base) {
1078 std::unique_ptr<FunctionRNA> *func = std::find_if(
1079 srna->functions.begin(), srna->functions.end(), [&](const auto &func) {
1080 return func->identifier == identifier;
1081 });
1082 if (func != srna->functions.end()) {
1083 return func->get();
1084 }
1085 }
1086 return nullptr;
1087
1088 /* functional but slow */
1089#else
1090 PropertyRNA *iterprop;
1091 FunctionRNA *func;
1092
1093 PointerRNA tptr = RNA_pointer_create_discrete(nullptr, RNA_Struct, srna);
1094 iterprop = RNA_struct_find_property(&tptr, "functions");
1095
1096 func = nullptr;
1097
1098 RNA_PROP_BEGIN (&tptr, funcptr, iterprop) {
1099 if (identifier == RNA_function_identifier(funcptr.data)) {
1100 func = funcptr.data;
1101 break;
1102 }
1103 }
1105
1106 return func;
1107#endif
1108}
1109
1114
1116{
1117 return type->reg;
1118}
1119
1121{
1122 do {
1123 if (type->unreg) {
1124 return type->unreg;
1125 }
1126 } while ((type = type->base));
1127
1128 return nullptr;
1129}
1130
1132{
1133 StructRNA *type = ptr->type;
1134
1135 do {
1136 if (type->instance) {
1137 return type->instance(ptr);
1138 }
1139 } while ((type = type->base));
1140
1141 return nullptr;
1142}
1143
1145{
1146 return srna->py_type;
1147}
1148
1149void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
1150{
1151 srna->py_type = py_type;
1152}
1153
1155{
1156 return srna->blender_type;
1157}
1158
1159void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
1160{
1161 srna->blender_type = blender_type;
1162}
1163
1165 PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len, PropertyRNA **r_nameprop)
1166{
1167 if (*ptr) {
1168 if (PropertyRNA *nameprop = RNA_struct_name_property(ptr->type)) {
1169 *r_nameprop = nameprop;
1170 return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen, r_len);
1171 }
1172 }
1173 return nullptr;
1174}
1175
1176char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
1177{
1178 if (*ptr) {
1179 if (PropertyRNA *nameprop = RNA_struct_name_property(ptr->type)) {
1180 return RNA_property_string_get_alloc(ptr, nameprop, fixedbuf, fixedlen, r_len);
1181 }
1182 }
1183 return nullptr;
1184}
1185
1186bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
1187{
1188 const StructRNA *srna_exists = RNA_struct_find(identifier);
1189 if (srna_exists != nullptr) [[unlikely]] {
1190 /* Use comprehensive string construction since this is such a rare occurrence
1191 * and information here may cut down time troubleshooting. */
1192 DynStr *dynstr = BLI_dynstr_new();
1193 BLI_dynstr_appendf(dynstr, "Type identifier '%s' is already in use: '", identifier);
1194 BLI_dynstr_append(dynstr, srna_exists->identifier.c_str());
1195 int i = 0;
1196 if (srna_exists->base) {
1197 for (const StructRNA *base = srna_exists->base; base; base = base->base) {
1198 BLI_dynstr_append(dynstr, "(");
1199 BLI_dynstr_append(dynstr, base->identifier.c_str());
1200 i += 1;
1201 }
1202 while (i--) {
1203 BLI_dynstr_append(dynstr, ")");
1204 }
1205 }
1206 BLI_dynstr_append(dynstr, "'.");
1207 char *result = BLI_dynstr_get_cstring(dynstr);
1208 BLI_dynstr_free(dynstr);
1209 BKE_report(reports, RPT_ERROR, result);
1210 MEM_delete(result);
1211 return false;
1212 }
1213 return true;
1214}
1215
1217 const char *identifier,
1218 const char *sep)
1219{
1220 const int len_sep = strlen(sep);
1221 const int len_id = strlen(identifier);
1222 const char *p = strstr(identifier, sep);
1223 /* TODO: make error, for now warning until add-ons update. */
1224#if 1
1225 const int report_level = RPT_WARNING;
1226 const bool failure = true;
1227#else
1228 const int report_level = RPT_ERROR;
1229 const bool failure = false;
1230#endif
1231 if (p == nullptr || p == identifier || p + len_sep >= identifier + len_id) {
1232 BKE_reportf(reports,
1233 eReportType(report_level),
1234 "'%s' does not contain '%s' with prefix and suffix",
1235 identifier,
1236 sep);
1237 return failure;
1238 }
1239
1240 const char *c, *start, *end, *last;
1241 start = identifier;
1242 end = p;
1243 last = end - 1;
1244 for (c = start; c != end; c++) {
1245 if (((*c >= 'A' && *c <= 'Z') || ((c != start) && (*c >= '0' && *c <= '9')) ||
1246 ((c != start) && (c != last) && (*c == '_'))) == 0)
1247 {
1248 BKE_reportf(reports,
1249 eReportType(report_level),
1250 "'%s' does not have upper case alphanumeric prefix",
1251 identifier);
1252 return failure;
1253 }
1254 }
1255
1256 start = p + len_sep;
1257 end = identifier + len_id;
1258 last = end - 1;
1259 for (c = start; c != end; c++) {
1260 if (((*c >= 'A' && *c <= 'Z') || (*c >= 'a' && *c <= 'z') || (*c >= '0' && *c <= '9') ||
1261 ((c != start) && (c != last) && (*c == '_'))) == 0)
1262 {
1263 BKE_reportf(reports,
1264 eReportType(report_level),
1265 "'%s' does not have an alphanumeric suffix",
1266 identifier);
1267 return failure;
1268 }
1269 }
1270 return true;
1271}
1272
1273/* Property Information */
1274
1275const char *RNA_property_identifier(const PropertyRNA *prop)
1276{
1277 return rna_ensure_property_identifier(prop);
1278}
1279
1281{
1283}
1284
1286{
1287 if (prop->magic == RNA_MAGIC) {
1288 return prop->deprecated;
1289 }
1290 return nullptr;
1291}
1292
1297
1299{
1300 PropertyRNA *rna_prop = rna_ensure_property(prop);
1301
1302 /* For custom properties, find and parse the 'subtype' metadata field. */
1303 if (prop->magic != RNA_MAGIC) {
1304 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
1305
1306 if (idprop->type == IDP_STRING && idprop->subtype == IDP_STRING_SUB_BYTE) {
1307 return PROP_BYTESTRING;
1308 }
1309
1310 if (idprop->ui_data) {
1311 IDPropertyUIData *ui_data = idprop->ui_data;
1312 return PropertySubType(ui_data->rna_subtype);
1313 }
1314 }
1315
1316 return rna_prop->subtype;
1317}
1318
1323
1325{
1326 PropertyRNA *rna_prop = rna_ensure_property(prop);
1327
1328 switch (rna_prop->type) {
1329 case PROP_INT: {
1330 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(rna_prop);
1331 return iprop->ui_scale_type;
1332 }
1333 case PROP_FLOAT: {
1334 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(rna_prop);
1335 return fprop->ui_scale_type;
1336 }
1337 default:
1338 return PROP_SCALE_LINEAR;
1339 }
1340}
1341
1343{
1344 return rna_ensure_property(prop)->flag;
1345}
1346
1348{
1349 return rna_ensure_property(prop)->tags;
1350}
1351
1356
1358{
1359 return (rna_ensure_property(prop)->flag_internal & PROP_INTERN_BUILTIN) != 0;
1360}
1361
1363{
1364 /* This is only called in isolated situations (mainly by the Python API),
1365 * so skip check for ID properties. Callers must use #RNA_property_is_idprop
1366 * when it's not known if the property might be an ID Property. */
1367 BLI_assert(prop->magic == RNA_MAGIC);
1368 return prop->py_data;
1369}
1370
1372{
1373 return rna_ensure_property_array_length(ptr, prop);
1374}
1375
1380
1382{
1383 PropertyRNA *rprop = rna_ensure_property(prop);
1384
1385 if (length) {
1387 }
1388
1389 return rprop->arraydimension;
1390}
1391
1393{
1395
1397
1398 return len[dimension];
1399}
1400
1402{
1403 const char *vectoritem = "XYZW";
1404 const char *quatitem = "WXYZ";
1405 const char *coloritem = "RGBA";
1406 PropertySubType subtype = RNA_property_subtype(prop);
1407
1408 BLI_assert(index >= 0);
1409
1410 /* get string to use for array index */
1411 if ((index < 4) && ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
1412 return quatitem[index];
1413 }
1414 if ((index < 4) && ELEM(subtype,
1417 PROP_XYZ,
1419 PROP_EULER,
1423 PROP_PIXEL))
1424 {
1425 return vectoritem[index];
1426 }
1427 if ((index < 4) && ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1428 return coloritem[index];
1429 }
1430
1431 return '\0';
1432}
1433
1435{
1436 /* Don't use custom property sub-types in RNA path lookup. */
1438
1439 /* get index based on string name/alias */
1440 /* maybe a function to find char index in string would be better than all the switches */
1441 if (ELEM(subtype, PROP_QUATERNION, PROP_AXISANGLE)) {
1442 switch (name) {
1443 case 'w':
1444 return 0;
1445 case 'x':
1446 return 1;
1447 case 'y':
1448 return 2;
1449 case 'z':
1450 return 3;
1451 }
1452 }
1453 else if (ELEM(subtype,
1456 PROP_XYZ,
1458 PROP_EULER,
1461 PROP_PIXEL))
1462 {
1463 switch (name) {
1464 case 'x':
1465 return 0;
1466 case 'y':
1467 return 1;
1468 case 'z':
1469 return 2;
1470 case 'w':
1471 return 3;
1472 }
1473 }
1474 else if (ELEM(subtype, PROP_COLOR, PROP_COLOR_GAMMA)) {
1475 switch (name) {
1476 case 'r':
1477 return 0;
1478 case 'g':
1479 return 1;
1480 case 'b':
1481 return 2;
1482 case 'a':
1483 return 3;
1484 }
1485 }
1486
1487 return -1;
1488}
1489
1490void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
1491{
1492 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(rna_ensure_property(prop));
1493 int softmin, softmax;
1494
1495 if (prop->magic != RNA_MAGIC) {
1496 const IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
1497 if (idprop->ui_data) {
1498 IDPropertyUIDataInt *ui_data = reinterpret_cast<IDPropertyUIDataInt *>(idprop->ui_data);
1499 *hardmin = ui_data->min;
1500 *hardmax = ui_data->max;
1501 }
1502 else {
1503 *hardmin = INT_MIN;
1504 *hardmax = INT_MAX;
1505 }
1506 return;
1507 }
1508
1509 if (iprop->range) {
1510 *hardmin = INT_MIN;
1511 *hardmax = INT_MAX;
1512
1513 iprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
1514 }
1515 else if (iprop->range_ex) {
1516 *hardmin = INT_MIN;
1517 *hardmax = INT_MAX;
1518
1519 iprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
1520 }
1521 else {
1522 *hardmin = iprop->hardmin;
1523 *hardmax = iprop->hardmax;
1524 }
1525}
1526
1528 PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
1529{
1530 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(rna_ensure_property(prop));
1531 int hardmin, hardmax;
1532
1533 if (prop->magic != RNA_MAGIC) {
1534 const IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
1535 if (idprop->ui_data) {
1536 IDPropertyUIDataInt *ui_data_int = reinterpret_cast<IDPropertyUIDataInt *>(idprop->ui_data);
1537 *softmin = ui_data_int->soft_min;
1538 *softmax = ui_data_int->soft_max;
1539 *step = ui_data_int->step;
1540 }
1541 else {
1542 *softmin = INT_MIN;
1543 *softmax = INT_MAX;
1544 *step = 1;
1545 }
1546 return;
1547 }
1548
1549 *softmin = iprop->softmin;
1550 *softmax = iprop->softmax;
1551
1552 if (iprop->range) {
1553 hardmin = INT_MIN;
1554 hardmax = INT_MAX;
1555
1556 iprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1557
1558 *softmin = max_ii(*softmin, hardmin);
1559 *softmax = min_ii(*softmax, hardmax);
1560 }
1561 else if (iprop->range_ex) {
1562 hardmin = INT_MIN;
1563 hardmax = INT_MAX;
1564
1565 iprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
1566
1567 *softmin = max_ii(*softmin, hardmin);
1568 *softmax = min_ii(*softmax, hardmax);
1569 }
1570
1571 *step = iprop->step;
1572}
1573
1574void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
1575{
1576 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(rna_ensure_property(prop));
1577 float softmin, softmax;
1578
1579 if (prop->magic != RNA_MAGIC) {
1580 const IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
1581 if (idprop->ui_data) {
1582 IDPropertyUIDataFloat *ui_data = reinterpret_cast<IDPropertyUIDataFloat *>(idprop->ui_data);
1583 *hardmin = float(ui_data->min);
1584 *hardmax = float(ui_data->max);
1585 }
1586 else {
1587 *hardmin = -FLT_MAX;
1588 *hardmax = FLT_MAX;
1589 }
1590 return;
1591 }
1592
1593 if (fprop->range) {
1594 *hardmin = -FLT_MAX;
1595 *hardmax = FLT_MAX;
1596
1597 fprop->range(ptr, hardmin, hardmax, &softmin, &softmax);
1598 }
1599 else if (fprop->range_ex) {
1600 *hardmin = -FLT_MAX;
1601 *hardmax = FLT_MAX;
1602
1603 fprop->range_ex(ptr, prop, hardmin, hardmax, &softmin, &softmax);
1604 }
1605 else {
1606 *hardmin = fprop->hardmin;
1607 *hardmax = fprop->hardmax;
1608 }
1609}
1610
1612 PropertyRNA *prop,
1613 float *softmin,
1614 float *softmax,
1615 float *step,
1616 float *precision)
1617{
1618 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(rna_ensure_property(prop));
1619 float hardmin, hardmax;
1620
1621 if (prop->magic != RNA_MAGIC) {
1622 const IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
1623 if (idprop->ui_data) {
1624 IDPropertyUIDataFloat *ui_data = reinterpret_cast<IDPropertyUIDataFloat *>(idprop->ui_data);
1625 *softmin = float(ui_data->soft_min);
1626 *softmax = float(ui_data->soft_max);
1627 *step = ui_data->step;
1628 *precision = float(ui_data->precision);
1629 }
1630 else {
1631 *softmin = -FLT_MAX;
1632 *softmax = FLT_MAX;
1633 *step = 1.0f;
1634 *precision = 3.0f;
1635 }
1636 return;
1637 }
1638
1639 *softmin = fprop->softmin;
1640 *softmax = fprop->softmax;
1641
1642 if (fprop->range) {
1643 hardmin = -FLT_MAX;
1644 hardmax = FLT_MAX;
1645
1646 fprop->range(ptr, &hardmin, &hardmax, softmin, softmax);
1647
1648 *softmin = max_ff(*softmin, hardmin);
1649 *softmax = min_ff(*softmax, hardmax);
1650 }
1651 else if (fprop->range_ex) {
1652 hardmin = -FLT_MAX;
1653 hardmax = FLT_MAX;
1654
1655 fprop->range_ex(ptr, prop, &hardmin, &hardmax, softmin, softmax);
1656
1657 *softmin = max_ff(*softmin, hardmin);
1658 *softmax = min_ff(*softmax, hardmax);
1659 }
1660
1661 *step = fprop->step;
1662 *precision = float(fprop->precision);
1663}
1664
1666{
1667 float min, max;
1668
1669 RNA_property_float_range(ptr, prop, &min, &max);
1670
1671 if (*value < min) {
1672 *value = min;
1673 return -1;
1674 }
1675 if (*value > max) {
1676 *value = max;
1677 return 1;
1678 }
1679 return 0;
1680}
1681
1683{
1684 int min, max;
1685
1686 RNA_property_int_range(ptr, prop, &min, &max);
1687
1688 if (*value < min) {
1689 *value = min;
1690 return -1;
1691 }
1692 if (*value > max) {
1693 *value = max;
1694 return 1;
1695 }
1696 return 0;
1697}
1698
1700{
1701 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(rna_ensure_property(prop));
1702 return sprop->maxlength;
1703}
1704
1710
1712{
1713 if (prop->magic != RNA_MAGIC) {
1714 const IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
1715 if (idprop->type == IDP_ID) {
1716 const IDPropertyUIDataID *ui_data = reinterpret_cast<const IDPropertyUIDataID *>(
1717 idprop->ui_data);
1718 if (ui_data) {
1719 return ID_code_to_RNA_type(ui_data->id_type);
1720 }
1721 }
1722 }
1723
1724 prop = rna_ensure_property(prop);
1725
1726 if (prop->type == PROP_POINTER) {
1727 const bool is_ptr_data_usable = rna_property_can_access_pointer_data(*ptr, *prop);
1728 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
1729
1730 if (pprop->type_fn && is_ptr_data_usable) {
1731 return pprop->type_fn(ptr);
1732 }
1733 if (pprop->pointer_type) {
1734 return pprop->pointer_type;
1735 }
1736 }
1737 else if (prop->type == PROP_COLLECTION) {
1739 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
1740
1741 if (cprop->item_type) {
1742 return cprop->item_type;
1743 }
1744 }
1745 /* ignore other types, rna_struct_find_nested calls with unchecked props */
1746
1747 return RNA_UnknownType;
1748}
1749
1751{
1752 prop = rna_ensure_property(prop);
1753
1754 if (prop->type != PROP_POINTER) {
1755 printf("%s: %s is not a pointer property.\n", __func__, prop->identifier.c_str());
1756 return false;
1757 }
1758
1760 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
1761
1762 /* Can't point from linked to local datablock. */
1763 if (ptr->owner_id && value->owner_id && !BKE_id_can_use_id(*ptr->owner_id, *value->owner_id)) {
1764 return false;
1765 }
1766
1767 /* Check custom poll function. */
1768 if (!pprop->poll) {
1769 return true;
1770 }
1771
1772 if (rna_idproperty_check(&prop, ptr)) {
1773 return reinterpret_cast<PropPointerPollFuncPy>(reinterpret_cast<void *>(pprop->poll))(
1774 ptr, *value, prop);
1775 }
1776 return pprop->poll(ptr, *value);
1777}
1778
1780 PointerRNA *ptr,
1781 PropertyRNA *prop,
1782 const bool use_static,
1783 const EnumPropertyItem **r_item,
1784 int *r_totitem,
1785 bool *r_free)
1786{
1787 if (!use_static && prop->magic != RNA_MAGIC) {
1788 const IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
1789 if (idprop->type == IDP_INT) {
1790 IDPropertyUIDataInt *ui_data = reinterpret_cast<IDPropertyUIDataInt *>(idprop->ui_data);
1791
1792 int totitem = 0;
1793 EnumPropertyItem *result = nullptr;
1794 if (ui_data) {
1795 for (const IDPropertyUIDataEnumItem &idprop_item :
1796 Span(ui_data->enum_items, ui_data->enum_items_num))
1797 {
1798 BLI_assert(idprop_item.identifier != nullptr);
1799 BLI_assert(idprop_item.name != nullptr);
1800 const EnumPropertyItem item = {idprop_item.value,
1801 idprop_item.identifier,
1802 idprop_item.icon,
1803 idprop_item.name,
1804 idprop_item.description ? idprop_item.description : ""};
1805 RNA_enum_item_add(&result, &totitem, &item);
1806 }
1807 }
1808
1809 RNA_enum_item_end(&result, &totitem);
1810 *r_item = result;
1811 if (r_totitem) {
1812 /* Exclude the terminator item. */
1813 *r_totitem = totitem - 1;
1814 }
1815 *r_free = true;
1816 return;
1817 }
1818 }
1819
1820 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(rna_ensure_property(prop));
1821
1822 *r_free = false;
1823
1824 if (!use_static && (eprop->item_fn != nullptr)) {
1825 const bool no_context = (prop->flag & PROP_ENUM_NO_CONTEXT) ||
1827 (ptr->owner_id == nullptr));
1828 if (C != nullptr || no_context) {
1829 /* FIXME: Currently, the enum item_fn callback can be called in various situations, mixing
1830 * 'valid' regular PointerRNA data, and e.g. meta-data like Function PointerRNA (see e.g.
1831 * `brush_type` properties, using the same items callback in both actual data
1832 * (`WorkSpaceTool` struct) and function definition (`WorkSpaceTool::setup()`).
1833 *
1834 * This should probably be sanitized at some point, but for now, this code cannot assert on
1835 * `rna_property_can_access_pointer_data(*ptr, *eprop)`. */
1836 const EnumPropertyItem *item;
1837
1838 item = eprop->item_fn(no_context ? nullptr : C, ptr, prop, r_free);
1839
1840 /* any callbacks returning nullptr should be fixed */
1841 BLI_assert(item != nullptr);
1842
1843 if (r_totitem) {
1844 int tot;
1845 for (tot = 0; item[tot].identifier; tot++) {
1846 /* pass */
1847 }
1848 *r_totitem = tot;
1849 }
1850
1851 *r_item = item;
1852 return;
1853 }
1854 }
1855
1856 *r_item = eprop->item;
1857 if (r_totitem) {
1858 *r_totitem = eprop->totitem;
1859 }
1860}
1861
1863 PointerRNA *ptr,
1864 PropertyRNA *prop,
1865 const EnumPropertyItem **r_item,
1866 int *r_totitem,
1867 bool *r_free)
1868{
1869 RNA_property_enum_items_ex(C, ptr, prop, false, r_item, r_totitem, r_free);
1870}
1871
1872#ifdef WITH_INTERNATIONAL
1873static void property_enum_translate(PropertyRNA *prop,
1874 EnumPropertyItem **r_item,
1875 const int *totitem,
1876 bool *r_free)
1877{
1879 int i;
1880
1881 /* NOTE: Only do those tests once, and then use BLT_pgettext. */
1882 bool do_iface = BLT_translate_iface();
1883 bool do_tooltip = BLT_translate_tooltips();
1884 EnumPropertyItem *nitem;
1885
1886 if (!(do_iface || do_tooltip)) {
1887 return;
1888 }
1889
1890 if (*r_free) {
1891 nitem = *r_item;
1892 }
1893 else {
1894 const EnumPropertyItem *item = *r_item;
1895 int tot;
1896
1897 if (totitem) {
1898 tot = *totitem;
1899 }
1900 else {
1901 /* count */
1902 for (tot = 0; item[tot].identifier; tot++) {
1903 /* pass */
1904 }
1905 }
1906
1907 nitem = MEM_new_array_uninitialized<EnumPropertyItem>(size_t(tot) + 1, __func__);
1908 memcpy(nitem, item, sizeof(EnumPropertyItem) * (tot + 1));
1909
1910 *r_free = true;
1911 }
1912
1913 const char *translation_context = RNA_property_translation_context(prop);
1914
1915 for (i = 0; nitem[i].identifier; i++) {
1916 if (nitem[i].name && do_iface) {
1917 nitem[i].name = BLT_pgettext(translation_context, nitem[i].name);
1918 }
1919 if (nitem[i].description && do_tooltip) {
1920 nitem[i].description = BLT_pgettext(nullptr, nitem[i].description);
1921 }
1922 }
1923
1924 *r_item = nitem;
1925 }
1926}
1927#endif
1928
1930 PointerRNA *ptr,
1931 PropertyRNA *prop,
1932 const EnumPropertyItem **r_item,
1933 int *r_totitem,
1934 bool *r_free)
1935{
1936 RNA_property_enum_items(C, ptr, prop, r_item, r_totitem, r_free);
1937
1938#ifdef WITH_INTERNATIONAL
1939 /* Normally dropping 'const' is _not_ ok, in this case it's only modified if we own the memory
1940 * so allow the exception (callers are creating new arrays in this case). */
1941 property_enum_translate(prop, (EnumPropertyItem **)r_item, r_totitem, r_free);
1942#endif
1943}
1944
1946 PointerRNA *ptr,
1947 PropertyRNA *prop,
1948 const EnumPropertyItem **r_item,
1949 int *r_totitem,
1950 bool *r_free)
1951{
1952 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(rna_ensure_property(prop));
1953 size_t mem_size = sizeof(EnumPropertyItem) * (size_t(eprop->totitem) + 1);
1954 /* first return all items */
1956 size_t(eprop->totitem) + 1, "enum_gettext_all");
1957 *r_free = true;
1958 memcpy(item_array, eprop->item, mem_size);
1959
1960 if (r_totitem) {
1961 *r_totitem = eprop->totitem;
1962 }
1963
1964 if (eprop->item_fn != nullptr) {
1965 const bool no_context = (eprop->flag & PROP_ENUM_NO_CONTEXT) ||
1967 (ptr->owner_id == nullptr));
1968 if (C != nullptr || no_context) {
1969 /* FIXME: Currently, the enum item_fn callback can be called in various situations, mixing
1970 * 'valid' regular PointerRNA data, and e.g. meta-data like Function PointerRNA (see e.g.
1971 * `brush_type` properties, using the same items callback in both actual data
1972 * (`WorkSpaceTool` struct) and function definition (`WorkSpaceTool::setup()`).
1973 *
1974 * This should probably be sanitized at some point, but for now, this code cannot assert on
1975 * `rna_property_can_access_pointer_data(*ptr, *eprop)`. */
1976 const EnumPropertyItem *item;
1977 int i;
1978 bool free = false;
1979
1980 item = eprop->item_fn(no_context ? nullptr : nullptr, ptr, prop, &free);
1981
1982 /* any callbacks returning nullptr should be fixed */
1983 BLI_assert(item != nullptr);
1984
1985 for (i = 0; i < eprop->totitem; i++) {
1986 bool exists = false;
1987 int i_fixed;
1988
1989 /* Items that do not exist on list are returned,
1990 * but have their names/identifiers null'ed out. */
1991 for (i_fixed = 0; item[i_fixed].identifier; i_fixed++) {
1992 if (STREQ(item[i_fixed].identifier, item_array[i].identifier)) {
1993 exists = true;
1994 break;
1995 }
1996 }
1997
1998 if (!exists) {
1999 item_array[i].name = nullptr;
2000 item_array[i].identifier = "";
2001 }
2002 }
2003
2004 if (free) {
2005 MEM_delete(item);
2006 }
2007 }
2008 }
2009
2010#ifdef WITH_INTERNATIONAL
2011 property_enum_translate(prop, &item_array, r_totitem, r_free);
2012#endif
2013 *r_item = item_array;
2014}
2015
2017 bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
2018{
2019 const EnumPropertyItem *item;
2020 bool free;
2021 bool found;
2022
2023 RNA_property_enum_items(C, ptr, prop, &item, nullptr, &free);
2024
2025 if (item) {
2026 const int i = RNA_enum_from_identifier(item, identifier);
2027 if (i != -1) {
2028 *r_value = item[i].value;
2029 found = true;
2030 }
2031 else {
2032 found = false;
2033 }
2034
2035 if (free) {
2036 MEM_delete(item);
2037 }
2038 }
2039 else {
2040 found = false;
2041 }
2042 return found;
2043}
2044
2045bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
2046{
2047 const int i = RNA_enum_from_value(item, value);
2048 if (i != -1) {
2049 *r_identifier = item[i].identifier;
2050 return true;
2051 }
2052 return false;
2053}
2054
2056 const int value,
2057 const char **r_identifier)
2058{
2059 int index = 0;
2060 for (; item->identifier; item++) {
2061 if (item->identifier[0] && item->value & value) {
2062 r_identifier[index++] = item->identifier;
2063 }
2064 }
2065 r_identifier[index] = nullptr;
2066 return index;
2067}
2068
2069bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
2070{
2071 const int i = RNA_enum_from_value(item, value);
2072 if (i != -1) {
2073 *r_name = item[i].name;
2074 return true;
2075 }
2076 return false;
2077}
2078
2080 int value,
2081 const char *translation_context,
2082 const char **r_name)
2083{
2084 bool result;
2085
2086 result = RNA_enum_name(item, value, r_name);
2087
2088 if (result) {
2089 *r_name = BLT_translate_do_iface(translation_context, *r_name);
2090 }
2091
2092 return result;
2093};
2094
2096 const int value,
2097 const char **r_description)
2098{
2099 const int i = RNA_enum_from_value(item, value);
2100 if (i != -1) {
2101 *r_description = item[i].description;
2102 return true;
2103 }
2104 return false;
2105}
2106
2107int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier)
2108{
2109 int i = 0;
2110 for (; item->identifier; item++, i++) {
2111 if (item->identifier[0] && STREQ(item->identifier, identifier)) {
2112 return i;
2113 }
2114 }
2115 return -1;
2116}
2117
2119 const char *identifier,
2120 int *r_value)
2121{
2122 const int i = RNA_enum_from_identifier(item, identifier);
2123 if (i == -1) {
2124 return false;
2125 }
2126 *r_value = item[i].value;
2127 return true;
2128}
2129
2130int RNA_enum_from_name(const EnumPropertyItem *item, const char *name)
2131{
2132 int i = 0;
2133 for (; item->identifier; item++, i++) {
2134 if (item->identifier[0] && STREQ(item->name, name)) {
2135 return i;
2136 }
2137 }
2138 return -1;
2139}
2140
2141int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
2142{
2143 int i = 0;
2144 for (; item->identifier; item++, i++) {
2145 if (item->identifier[0] && item->value == value) {
2146 return i;
2147 }
2148 }
2149 return -1;
2150}
2151
2153{
2154 uint i = 0;
2155
2156 while (item->identifier) {
2157 item++;
2158 i++;
2159 }
2160
2161 return i;
2162}
2163
2165 bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_identifier)
2166{
2167 const EnumPropertyItem *item = nullptr;
2168 bool free;
2169
2170 RNA_property_enum_items(C, ptr, prop, &item, nullptr, &free);
2171 if (item) {
2172 bool result;
2173 result = RNA_enum_identifier(item, value, r_identifier);
2174 if (free) {
2175 MEM_delete(item);
2176 }
2177 return result;
2178 }
2179 return false;
2180}
2181
2183 bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
2184{
2185 const EnumPropertyItem *item = nullptr;
2186 bool free;
2187
2188 RNA_property_enum_items(C, ptr, prop, &item, nullptr, &free);
2189 if (item) {
2190 bool result;
2191 result = RNA_enum_name(item, value, r_name);
2192 if (free) {
2193 MEM_delete(item);
2194 }
2195
2196 return result;
2197 }
2198 return false;
2199}
2200
2202 bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
2203{
2204 bool result;
2205
2206 result = RNA_property_enum_name(C, ptr, prop, value, r_name);
2207
2208 if (result) {
2209 if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
2211 }
2212 }
2213
2214 return result;
2215}
2216
2218 bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
2219{
2220 const EnumPropertyItem *item = nullptr;
2221 bool free;
2222
2223 RNA_property_enum_items(C, ptr, prop, &item, nullptr, &free);
2224 if (item) {
2225 const int i = RNA_enum_from_value(item, value);
2226 bool result;
2227
2228 if (i != -1) {
2229 *r_item = item[i];
2230 result = true;
2231 }
2232 else {
2233 result = false;
2234 }
2235
2236 if (free) {
2237 MEM_delete(item);
2238 }
2239
2240 return result;
2241 }
2242 return false;
2243}
2244
2246 bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
2247{
2248 const bool result = RNA_property_enum_item_from_value(C, ptr, prop, value, r_item);
2249
2252 r_item->description = BLT_translate_do_tooltip(nullptr, r_item->description);
2253 }
2254
2255 return result;
2256}
2257
2259 bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_identifier)
2260{
2261 const EnumPropertyItem *item = nullptr;
2262 bool free;
2263
2264 RNA_property_enum_items(C, ptr, prop, &item, nullptr, &free);
2265 if (item) {
2266 int result;
2267 result = RNA_enum_bitflag_identifiers(item, value, r_identifier);
2268 if (free) {
2269 MEM_delete(item);
2270 }
2271
2272 return result;
2273 }
2274 return 0;
2275}
2276
2277const char *RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
2278{
2279 if (ptr && prop->magic == RNA_MAGIC && prop->ui_name_func) {
2280 if (const char *name = prop->ui_name_func(ptr, prop, true)) {
2281 return name;
2282 }
2283 }
2285}
2286
2287const char *RNA_property_ui_name_raw(const PropertyRNA *prop, const PointerRNA *ptr)
2288{
2289 if (ptr && prop->magic == RNA_MAGIC && prop->ui_name_func) {
2290 if (const char *name = prop->ui_name_func(ptr, prop, false)) {
2291 return name;
2292 }
2293 }
2294 return rna_ensure_property_name(prop);
2295}
2296
2297const char *RNA_property_ui_description(const PropertyRNA *prop, const PointerRNA *ptr)
2298{
2299 if (ptr && prop->magic == RNA_MAGIC && prop->ui_description_func) {
2300 if (const char *description = prop->ui_description_func(ptr, prop, true)) {
2301 return description;
2302 }
2303 }
2305}
2306
2307const char *RNA_property_ui_description_raw(const PropertyRNA *prop, const PointerRNA *ptr)
2308{
2309 if (ptr && prop->magic == RNA_MAGIC && prop->ui_description_func) {
2310 if (const char *description = prop->ui_description_func(ptr, prop, false)) {
2311 return description;
2312 }
2313 }
2315}
2316
2318{
2319 return rna_ensure_property(const_cast<PropertyRNA *>(prop))->translation_context;
2320}
2321
2323{
2324 return rna_ensure_property(const_cast<PropertyRNA *>(prop))->icon;
2325}
2326
2327bool RNA_property_undo_check(const PropertyRNA *prop, const StructRNA *type)
2328{
2329 if (type->flag & STRUCT_UNDO) {
2330 return true;
2331 }
2332 const PropertyRNA *rna_prop = rna_ensure_property(const_cast<PropertyRNA *>(prop));
2333 if (rna_prop->flag & PROP_FORCE_UNDO) {
2334 return true;
2335 }
2336 return false;
2337}
2338
2340 PropertyRNA *prop_orig,
2341 const int index,
2342 const char **r_info)
2343{
2344 ID *id = ptr->owner_id;
2345
2346 PropertyRNA *prop = rna_ensure_property(prop_orig);
2347
2348 const char *info = "";
2349 const PropertyFlag flag = (prop->itemeditable != nullptr && index >= 0) ?
2350 PropertyFlag(prop->itemeditable(ptr, index)) :
2351 (prop->editable != nullptr ?
2352 PropertyFlag(prop->editable(ptr, &info)) :
2353 prop->flag);
2354 if (r_info != nullptr) {
2355 *r_info = info;
2356 }
2357
2358 /* Early return if the property itself is not editable. */
2359 if ((flag & PROP_EDITABLE) == 0) {
2360 return false;
2361 }
2362 /* Only considered registerable properties "internal"
2363 * because regular properties may not be editable and still be displayed. */
2364 if (flag & PROP_REGISTER) {
2365 if (r_info != nullptr && (*r_info)[0] == '\0') {
2366 *r_info = N_("This property is for internal use only and cannot be edited");
2367 }
2368 return false;
2369 }
2370
2371 /* If there is no owning ID, the property is editable at this point. */
2372 if (id == nullptr) {
2373 return true;
2374 }
2375
2376 /* Handle linked or liboverride ID cases. */
2377 const bool is_linked_prop_exception = (prop->flag & PROP_LIB_EXCEPTION) != 0;
2378 if (!ID_IS_EDITABLE(id)) {
2379 if (is_linked_prop_exception) {
2380 return true;
2381 }
2382 if (r_info != nullptr && (*r_info)[0] == '\0') {
2383 *r_info = N_("Cannot edit this property from a linked data-block");
2384 }
2385 return false;
2386 }
2387 if (ID_IS_OVERRIDE_LIBRARY(id)) {
2388 const bool is_liboverride_system = BKE_lib_override_library_is_system_defined(G_MAIN, id);
2389 if (!RNA_property_overridable_get(ptr, prop_orig)) {
2390 if (r_info != nullptr && (*r_info)[0] == '\0') {
2391 *r_info = N_("Cannot edit this property from an override data-block");
2392 }
2393 return false;
2394 }
2395 if (is_liboverride_system && !is_linked_prop_exception) {
2396 if (r_info != nullptr && (*r_info)[0] == '\0') {
2397 *r_info = N_("Cannot edit this property from a system override data-block");
2398 }
2399 return false;
2400 }
2401 }
2402
2403 /* At this point, property is owned by a local ID and therefore fully editable. */
2404 return true;
2405}
2406
2408{
2409 return prop->flag_internal & PROP_INTERN_RUNTIME;
2410}
2411
2413{
2414 return rna_property_editable_do(ptr, prop, -1, nullptr);
2415}
2416
2417bool RNA_property_editable_info(const PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
2418{
2419 return rna_property_editable_do(ptr, prop, -1, r_info);
2420}
2421
2423{
2424 PropertyFlag flag;
2425 const char *dummy_info;
2426
2427 prop = rna_ensure_property(prop);
2428 flag = prop->editable ? PropertyFlag(prop->editable(ptr, &dummy_info)) : prop->flag;
2429 return (flag & PROP_EDITABLE) != 0;
2430}
2431
2433{
2434 BLI_assert(index >= 0);
2435
2436 return rna_property_editable_do(ptr, prop, index, nullptr);
2437}
2438
2440{
2441 /* check that base ID-block can support animation data */
2442 if (!id_can_have_animdata(ptr->owner_id)) {
2443 return false;
2444 }
2445
2446 PropertyRNA *prop_ensured = rna_ensure_property(prop_orig);
2447
2448 if (!(prop_ensured->flag & PROP_ANIMATABLE)) {
2449 return false;
2450 }
2451
2452 return true;
2453}
2454
2456{
2457 /* check that base ID-block can support animation data */
2458 if (!RNA_property_animateable(ptr, prop_orig)) {
2459 return false;
2460 }
2461
2462 /* Linked or LibOverride Action IDs are not editable at the FCurve level. */
2463 if (ptr->owner_id) {
2464 AnimData *anim_data = BKE_animdata_from_id(ptr->owner_id);
2465 if (anim_data && anim_data->action &&
2466 (!ID_IS_EDITABLE(anim_data->action) || ID_IS_OVERRIDE_LIBRARY(anim_data->action)))
2467 {
2468 return false;
2469 }
2470 }
2471
2472 return rna_property_editable_do(ptr, prop_orig, -1, nullptr);
2473}
2474
2476{
2477 if (!RNA_property_anim_editable(ptr, prop)) {
2478 return false;
2479 }
2480
2481 /* LibOverrides can only get drivers if their animdata (if any) was created for the local
2482 * liboverride, and there is none in the linked reference.
2483 *
2484 * See also #rna_AnimaData_override_apply. */
2485 if (ptr->owner_id && ID_IS_OVERRIDE_LIBRARY(ptr->owner_id)) {
2487 nullptr, ptr->owner_id, nullptr, nullptr);
2488 AnimData *linked_reference_anim_data = BKE_animdata_from_id(liboverride->reference);
2489 if (linked_reference_anim_data) {
2490 return false;
2491 }
2492 }
2493
2494 return true;
2495}
2496
2498{
2499 int len = 1, index;
2500 bool driven, special;
2501
2502 if (!prop) {
2503 return false;
2504 }
2505
2506 if (RNA_property_array_check(prop)) {
2507 len = RNA_property_array_length(ptr, prop);
2508 }
2509
2510 for (index = 0; index < len; index++) {
2511 if (BKE_fcurve_find_by_rna(ptr, prop, index, nullptr, nullptr, &driven, &special)) {
2512 return true;
2513 }
2514 }
2515
2516 return false;
2517}
2519{
2520 const std::optional<std::string> path = RNA_path_from_ID_to_property(ptr, prop);
2521 bool ret = false;
2522
2523 if (path) {
2524 PointerRNA ptr_test;
2525 PropertyRNA *prop_test;
2526
2528 if (RNA_path_resolve(&id_ptr, path->c_str(), &ptr_test, &prop_test) == true) {
2529 ret = (prop == prop_test);
2530 }
2531 }
2532
2533 return ret;
2534}
2535
2537 bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
2538{
2539 const bool is_rna = (prop->magic == RNA_MAGIC);
2540 prop = rna_ensure_property(prop);
2541
2542 if (is_rna) {
2543 if (prop->update) {
2544 /* ideally no context would be needed for update, but there's some
2545 * parts of the code that need it still, so we have this exception */
2546 if (prop->flag & PROP_CONTEXT_UPDATE) {
2547 if (C) {
2549 (reinterpret_cast<ContextPropUpdateFunc>(prop->update))(C, ptr, prop);
2550 }
2551 else {
2552 reinterpret_cast<ContextUpdateFunc>(reinterpret_cast<void *>(prop->update))(C, ptr);
2553 }
2554 }
2555 }
2556 else {
2557 prop->update(bmain, scene, ptr);
2558 }
2559 }
2560
2561#if 1
2562 /* TODO(@ideasman42): Should eventually be replaced entirely by message bus (below)
2563 * for now keep since copy-on-eval, bugs are hard to track when we have other missing updates.
2564 */
2565 if (prop->noteflag) {
2567 }
2568#endif
2569
2570 /* if C is nullptr, we're updating from animation.
2571 * avoid slow-down from f-curves by not publishing (for now). */
2572 if (C != nullptr) {
2573 wmMsgBus *mbus = CTX_wm_message_bus(C);
2574 /* we could add nullptr check, for now don't */
2575 WM_msg_publish_rna(mbus, ptr, prop);
2576 }
2577 if (ptr->owner_id != nullptr && ((prop->flag & PROP_NO_DEG_UPDATE) == 0)) {
2578 const short id_type = ptr->owner_id->id_type();
2579 if (ID_TYPE_USE_COPY_ON_EVAL(id_type)) {
2580 if (prop->flag & PROP_DEG_SYNC_ONLY) {
2582 }
2583 else {
2585 }
2586 }
2587 }
2588 /* End message bus. */
2589 }
2590
2591 /* NOTE(@ideasman42): Regarding the #RNA_OperatorProperties check.
2592 * Operator properties use ID-property storage but aren't custom properties,
2593 * exclude them so assigning them from UI layout code doesn't redraw every region.
2594 *
2595 * Without the operator exception, an operator property with an `update` callback can
2596 * enter into an eternal draw-loop, see: #163991.
2597 *
2598 * Currently operator properties are excluded, others types could be excluded too,
2599 * take care though as it's possible scripts rely on the redraw.
2600 * Operators are a clear case where we need to set the values in draw functions,
2601 * so triggering redraw and entering a loop isn't acceptable. */
2602 const bool is_idprop = (prop->flag & PROP_IDPROPERTY) &&
2603 !RNA_struct_is_a(ptr->type, RNA_OperatorProperties);
2604 const bool use_deg_update = !(prop->flag & PROP_NO_DEG_UPDATE);
2605 if (!is_rna || (is_idprop && use_deg_update)) {
2606
2607 /* Disclaimer: this logic is not applied consistently, causing some confusing behavior.
2608 *
2609 * - When animated (which skips update functions).
2610 * - When ID-properties are edited via Python (since RNA properties aren't used in this case).
2611 *
2612 * Adding updates will add a lot of overhead in the case of animation.
2613 * For Python it may cause unexpected slow-downs for developers using ID-properties
2614 * for data storage. Further, the root ID isn't available with nested data-structures.
2615 *
2616 * So editing custom properties only causes updates in the UI,
2617 * keep this exception because it happens to be useful for driving settings.
2618 * Python developers on the other hand will need to manually 'update_tag', see: #74000. */
2621
2622 /* When updating an ID pointer property, tag depsgraph for update. */
2623 if (prop->type == PROP_POINTER && RNA_struct_is_ID(RNA_property_pointer_type(ptr, prop))) {
2625 }
2626
2628 if (ptr->owner_id) {
2630 }
2631 /* Not nice as well, but the only way to make sure material preview
2632 * is updated with custom nodes.
2633 */
2634 if ((prop->flag & PROP_IDPROPERTY) != 0 && (ptr->owner_id != nullptr) &&
2635 (ptr->owner_id->id_type() == ID_NT))
2636 {
2638 }
2639 }
2640}
2641
2643{
2644 /* NOTE: must keep in sync with #rna_property_update. */
2645 return (prop->magic != RNA_MAGIC || prop->update || prop->noteflag);
2646}
2647
2652
2654{
2655 BLI_assert(bmain != nullptr);
2656 rna_property_update(nullptr, bmain, scene, ptr, prop);
2657}
2658
2659/* ---------------------------------------------------------------------- */
2660
2661/* Property Data */
2662
2663static bool property_boolean_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
2664{
2665 if (prop_rna_or_id.idprop) {
2666#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
2667 return IDP_int_or_bool_get(prop_rna_or_id.idprop);
2668#else
2669 return IDP_bool_get(prop_rna_or_id.idprop);
2670#endif
2671 }
2672 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop_rna_or_id.rnaprop);
2673 if (bprop->get) {
2674 return bprop->get(ptr);
2675 }
2676 if (bprop->get_ex) {
2677 return bprop->get_ex(ptr, bprop);
2678 }
2679 return bprop->defaultvalue;
2680}
2681
2683{
2685
2686 PropertyRNAOrID prop_rna_or_id;
2687 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
2688 BLI_assert(!prop_rna_or_id.is_array);
2689 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
2690 prop = nullptr;
2691 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop_rna_or_id.rnaprop);
2693
2694 bool value = property_boolean_get(ptr, prop_rna_or_id);
2695 if (bprop->get_transform) {
2696 value = bprop->get_transform(ptr, bprop, value, prop_rna_or_id.is_set);
2697 }
2698
2699 return value;
2700}
2701
2703{
2705
2706 PropertyRNAOrID prop_rna_or_id;
2707 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
2708 BLI_assert(!prop_rna_or_id.is_array);
2709 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
2710 prop = nullptr;
2711 IDProperty *idprop = prop_rna_or_id.idprop;
2712 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop_rna_or_id.rnaprop);
2714
2715 if (bprop->set_transform) {
2716 /* Get raw, untransformed (aka 'storage') value. */
2717 const bool curr_value = property_boolean_get(ptr, prop_rna_or_id);
2718 value = bprop->set_transform(ptr, bprop, value, curr_value, prop_rna_or_id.is_set);
2719 }
2720
2721 if (idprop) {
2722#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
2724#else
2725 IDP_bool_set(idprop, value);
2726#endif
2728 }
2729 else if (bprop->set) {
2730 bprop->set(ptr, value);
2731 }
2732 else if (bprop->set_ex) {
2733 bprop->set_ex(ptr, bprop, value);
2734 }
2735 else if (bprop->flag & PROP_EDITABLE) {
2736 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
2737#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
2739 group,
2740 bke::idprop::create(prop_rna_or_id.identifier.ref(), int(value), IDP_FLAG_STATIC_TYPE)
2741 .release());
2742#else
2744 group,
2746 .release());
2747#endif
2748 }
2749 }
2750}
2751
2753 const bool *defarr, int defarr_length, bool defvalue, int out_length, bool *r_values)
2754{
2755 if (defarr && defarr_length > 0) {
2756 defarr_length = std::min(defarr_length, out_length);
2757 memcpy(r_values, defarr, sizeof(bool) * defarr_length);
2758 }
2759 else {
2760 defarr_length = 0;
2761 }
2762
2763 for (int i = defarr_length; i < out_length; i++) {
2764 r_values[i] = defvalue;
2765 }
2766}
2767
2769 const int *defarr, int defarr_length, bool defvalue, int out_length, bool *r_values)
2770{
2771 if (defarr && defarr_length > 0) {
2772 defarr_length = std::min(defarr_length, out_length);
2773 for (int i = 0; i < defarr_length; i++) {
2774 r_values[i] = defarr[i] != 0;
2775 }
2776 }
2777 else {
2778 defarr_length = 0;
2779 }
2780
2781 for (int i = defarr_length; i < out_length; i++) {
2782 r_values[i] = defvalue;
2783 }
2784}
2785
2787 BoolPropertyRNA *bprop,
2788 bool *r_values)
2789{
2790 if (*ptr && bprop->get_default_array) {
2791 bprop->get_default_array(ptr, bprop, r_values);
2792 return;
2793 }
2794
2795 int length = bprop->totarraylength;
2796 int out_length = RNA_property_array_length(ptr, reinterpret_cast<PropertyRNA *>(bprop));
2797
2799 bprop->defaultarray, length, bprop->defaultvalue, out_length, r_values);
2800}
2801
2803 PropertyRNAOrID &prop_rna_or_id,
2804 MutableSpan<bool> r_values)
2805{
2806 PropertyRNA *rna_prop = prop_rna_or_id.rnaprop;
2807 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(rna_prop);
2808 if (prop_rna_or_id.idprop) {
2809 IDProperty *idprop = prop_rna_or_id.idprop;
2810 BLI_assert(idprop->len == RNA_property_array_length(ptr, rna_prop) ||
2811 (rna_prop->flag & PROP_IDPROPERTY));
2812 if (rna_prop->arraydimension == 0) {
2813 r_values[0] = RNA_property_boolean_get(ptr, rna_prop);
2814 }
2815 else if (idprop->subtype == IDP_INT) {
2816 /* Some boolean IDProperty arrays might be saved in files as an integer
2817 * array property, since the boolean IDProperty type was added later. */
2818 const int *values_src = IDP_array_int_get(idprop);
2819 for (int i = 0; i < idprop->len; i++) {
2820 r_values[i] = bool(values_src[i]);
2821 }
2822 }
2823 else if (idprop->subtype == IDP_BOOLEAN) {
2824 int8_t *values_src = IDP_array_bool_get(idprop);
2825 for (int i = 0; i < idprop->len; i++) {
2826 r_values[i] = values_src[i];
2827 }
2828 }
2829 }
2830 else if (rna_prop->arraydimension == 0) {
2831 r_values[0] = RNA_property_boolean_get(ptr, rna_prop);
2832 }
2833 else if (bprop->getarray) {
2834 bprop->getarray(ptr, r_values.data());
2835 }
2836 else if (bprop->getarray_ex) {
2837 bprop->getarray_ex(ptr, rna_prop, r_values.data());
2838 }
2839 else {
2841 }
2842}
2843
2845{
2847
2848 PropertyRNAOrID prop_rna_or_id;
2849 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
2850 BLI_assert(prop_rna_or_id.is_array);
2851 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
2852 prop = nullptr;
2853 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop_rna_or_id.rnaprop);
2855
2856 MutableSpan<bool> r_values(values, int64_t(prop_rna_or_id.array_len));
2857 values = nullptr; /* Do not access this 'raw' pointer anymore in code below. */
2858 property_boolean_get_array(ptr, prop_rna_or_id, r_values);
2859 if (bprop->getarray_transform) {
2860 /* NOTE: Given current implementation, it would _probably_ be safe to use `values` for both
2861 * input 'current values' and output 'final values', since python will make a copy of the input
2862 * anyways. Think it's better to keep it clean and make a copy here to avoid any potential
2863 * issues in the future though. */
2864 Array<bool, RNA_STACK_ARRAY> curr_values(r_values.as_span());
2865 bprop->getarray_transform(
2866 ptr, bprop, curr_values.data(), prop_rna_or_id.is_set, r_values.data());
2867 }
2868}
2869
2871 PropertyRNA *prop,
2872 bool *values,
2873 int values_num)
2874{
2875 BLI_assert(values_num >= 0);
2876 const int array_num = RNA_property_array_length(ptr, prop);
2877 if (values_num >= array_num) {
2878 RNA_property_boolean_get_array(ptr, prop, values);
2879 return;
2880 }
2881
2882 Array<bool, RNA_STACK_ARRAY> value_buf(array_num);
2883 RNA_property_boolean_get_array(ptr, prop, value_buf.data());
2884 memcpy(values, value_buf.data(), sizeof(*values) * values_num);
2885}
2886
2888{
2889 bool tmp[RNA_MAX_ARRAY_LENGTH];
2890 int len = rna_ensure_property_array_length(ptr, prop);
2891 bool value;
2892
2894 BLI_assert(RNA_property_array_check(prop) != false);
2895 BLI_assert(index >= 0);
2896 BLI_assert(index < len);
2897
2898 if (len <= RNA_MAX_ARRAY_LENGTH) {
2899 RNA_property_boolean_get_array(ptr, prop, tmp);
2900 value = tmp[index];
2901 }
2902 else {
2903 bool *tmparray;
2904
2905 tmparray = MEM_new_array_uninitialized<bool>(size_t(len), __func__);
2906 RNA_property_boolean_get_array(ptr, prop, tmparray);
2907 value = tmparray[index];
2908 MEM_delete(tmparray);
2909 }
2910
2911 BLI_assert(ELEM(value, false, true));
2912
2913 return value;
2914}
2915
2916void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
2917{
2919
2920 PropertyRNAOrID prop_rna_or_id;
2921 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
2922 BLI_assert(prop_rna_or_id.is_array);
2923 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
2924 prop = nullptr;
2925 IDProperty *idprop = prop_rna_or_id.idprop;
2926 PropertyRNA *rna_prop = prop_rna_or_id.rnaprop;
2927 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(rna_prop);
2929
2930 const int64_t values_num = int64_t(prop_rna_or_id.array_len);
2931 Span<bool> final_values(values, values_num);
2932 values = nullptr; /* Do not access this 'raw' pointer anymore in code below. */
2933 /* Default init does not allocate anything, so it's cheap. This is only reinitialized with actual
2934 * `values_num` items if `setarray_transform` is called. */
2935 Array<bool, RNA_STACK_ARRAY> final_values_storage{};
2936 if (bprop->setarray_transform) {
2937 /* Get raw, untransformed (aka 'storage') value. */
2938 Array<bool, RNA_STACK_ARRAY> curr_values(values_num);
2939 property_boolean_get_array(ptr, prop_rna_or_id, curr_values.as_mutable_span());
2940
2941 final_values_storage.reinitialize(values_num);
2942 bprop->setarray_transform(ptr,
2943 rna_prop,
2944 final_values.data(),
2945 curr_values.data(),
2946 prop_rna_or_id.is_set,
2947 final_values_storage.data());
2948 final_values = final_values_storage.as_span();
2949 }
2950
2951 if (idprop) {
2952 /* Support writing to integer and boolean IDProperties, since boolean
2953 * RNA properties used to be stored with integer IDProperties. */
2954 if (rna_prop->arraydimension == 0) {
2955 if (idprop->subtype == IDP_BOOLEAN) {
2956 IDP_bool_set(idprop, final_values[0]);
2957 }
2958 else {
2959 BLI_assert(idprop->subtype == IDP_INT);
2960 IDP_int_set(idprop, final_values[0]);
2961 }
2962 }
2963 else {
2964 BLI_assert(idprop->type == IDP_ARRAY);
2965 BLI_assert(idprop->len == values_num);
2966 if (idprop->subtype == IDP_BOOLEAN) {
2967 memcpy(IDP_array_bool_get(idprop),
2968 final_values.data(),
2969 sizeof(decltype(final_values)::value_type) * idprop->len);
2970 }
2971 else {
2972 BLI_assert(idprop->subtype == IDP_INT);
2973 int *values_dst = IDP_array_int_get(idprop);
2974 for (int i = 0; i < idprop->len; i++) {
2975 values_dst[i] = int(final_values[i]);
2976 }
2977 }
2978 }
2980 }
2981 else if (rna_prop->arraydimension == 0) {
2982 RNA_property_boolean_set(ptr, rna_prop, final_values[0]);
2983 }
2984 else if (bprop->setarray) {
2985 bprop->setarray(ptr, final_values.data());
2986 }
2987 else if (bprop->setarray_ex) {
2988 bprop->setarray_ex(ptr, rna_prop, final_values.data());
2989 }
2990 else if (rna_prop->flag & PROP_EDITABLE) {
2991 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
2992 IDPropertyTemplate val = {0};
2993 val.array.len = rna_prop->totarraylength;
2994#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
2995 val.array.type = IDP_INT;
2996#else
2997 val.array.type = IDP_BOOLEAN;
2998#endif
2999
3000 idprop = IDP_New(IDP_ARRAY, &val, prop_rna_or_id.identifier.ref(), IDP_FLAG_STATIC_TYPE);
3001 IDP_AddToGroup(group, idprop);
3002#ifdef USE_INT_IDPROPS_FOR_BOOLEAN_RNA_PROP
3003 int *values_dst = IDP_array_int_get(idprop);
3004 for (int i = 0; i < idprop->len; i++) {
3005 values_dst[i] = int(final_values[i]);
3006 }
3007#else
3008 int8_t *values_dst = IDP_array_bool_get(idprop);
3009 for (int i = 0; i < idprop->len; i++) {
3010 values_dst[i] = final_values[i];
3011 }
3012#endif
3013 }
3014 }
3015}
3016
3018 PropertyRNA *prop,
3019 const bool *values,
3020 int values_num)
3021{
3022 BLI_assert(values_num >= 0);
3023 const int array_num = RNA_property_array_length(ptr, prop);
3024 if (values_num >= array_num) {
3025 RNA_property_boolean_set_array(ptr, prop, values);
3026 return;
3027 }
3028
3029 Array<bool, RNA_STACK_ARRAY> value_buf(array_num);
3030 RNA_property_boolean_get_array(ptr, prop, value_buf.data());
3031 memcpy(value_buf.data(), values, sizeof(*values) * values_num);
3032 RNA_property_boolean_set_array(ptr, prop, value_buf.data());
3033}
3034
3036{
3037 bool tmp[RNA_MAX_ARRAY_LENGTH];
3038 int len = rna_ensure_property_array_length(ptr, prop);
3039
3041 BLI_assert(RNA_property_array_check(prop) != false);
3042 BLI_assert(index >= 0);
3043 BLI_assert(index < len);
3044 BLI_assert(ELEM(value, false, true));
3045
3046 if (len <= RNA_MAX_ARRAY_LENGTH) {
3047 RNA_property_boolean_get_array(ptr, prop, tmp);
3048 tmp[index] = value;
3049 RNA_property_boolean_set_array(ptr, prop, tmp);
3050 }
3051 else {
3052 bool *tmparray;
3053
3054 tmparray = MEM_new_array_uninitialized<bool>(size_t(len), __func__);
3055 RNA_property_boolean_get_array(ptr, prop, tmparray);
3056 tmparray[index] = value;
3057 RNA_property_boolean_set_array(ptr, prop, tmparray);
3058 MEM_delete(tmparray);
3059 }
3060}
3061
3063{
3064 /* TODO: Make defaults work for IDProperties. */
3065 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(rna_ensure_property(prop));
3067
3069 BLI_assert(RNA_property_array_check(prop) == false);
3070 BLI_assert(ELEM(bprop->defaultvalue, false, true));
3071
3072 if (prop->magic != RNA_MAGIC) {
3073 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
3074 if (idprop->ui_data) {
3075 switch (IDP_ui_data_type(idprop)) {
3077 const IDPropertyUIDataBool *ui_data = reinterpret_cast<const IDPropertyUIDataBool *>(
3078 idprop->ui_data);
3079 return ui_data->default_value;
3080 }
3081 case IDP_UI_DATA_TYPE_INT: {
3082 const IDPropertyUIDataInt *ui_data = reinterpret_cast<const IDPropertyUIDataInt *>(
3083 idprop->ui_data);
3084 return ui_data->default_value != 0;
3085 }
3086 default:
3088 }
3089 }
3090 return false;
3091 }
3092 if (bprop->get_default) {
3093 return bprop->get_default(ptr, prop);
3094 }
3095
3096 return bprop->defaultvalue;
3097}
3098
3100{
3101 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(rna_ensure_property(prop));
3103
3105 BLI_assert(RNA_property_array_check(prop) != false);
3106
3107 if (prop->magic != RNA_MAGIC) {
3108 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
3109 if (idprop->ui_data) {
3110 BLI_assert(idprop->type == IDP_ARRAY);
3111 switch (IDP_ui_data_type(idprop)) {
3113 const IDPropertyUIDataBool *ui_data = reinterpret_cast<const IDPropertyUIDataBool *>(
3114 idprop->ui_data);
3115 if (ui_data->default_array) {
3117 reinterpret_cast<const bool *>(ui_data->default_array),
3118 ui_data->default_array_len,
3119 ui_data->default_value,
3120 idprop->len,
3121 values);
3122 }
3123 else {
3125 nullptr, 0, ui_data->default_value, idprop->len, values);
3126 }
3127 break;
3128 }
3129 case IDP_UI_DATA_TYPE_INT: {
3130 const IDPropertyUIDataInt *ui_data = reinterpret_cast<const IDPropertyUIDataInt *>(
3131 idprop->ui_data);
3132 if (ui_data->default_array) {
3134 ui_data->default_array_len,
3135 ui_data->default_value,
3136 idprop->len,
3137 values);
3138 }
3139 else {
3141 nullptr, 0, ui_data->default_value, idprop->len, values);
3142 }
3143 break;
3144 }
3145 default:
3147 break;
3148 }
3149 }
3150 }
3151 else if (prop->arraydimension == 0) {
3152 values[0] = bprop->defaultvalue;
3153 }
3154 else {
3156 }
3157}
3158
3160{
3161 bool tmp[RNA_MAX_ARRAY_LENGTH];
3162 int len = rna_ensure_property_array_length(ptr, prop);
3163
3165 BLI_assert(RNA_property_array_check(prop) != false);
3166 BLI_assert(index >= 0);
3167 BLI_assert(index < len);
3168
3169 if (len <= RNA_MAX_ARRAY_LENGTH) {
3171 return tmp[index];
3172 }
3173 bool *tmparray, value;
3174
3175 tmparray = MEM_new_array_uninitialized<bool>(size_t(len), __func__);
3176 RNA_property_boolean_get_default_array(ptr, prop, tmparray);
3177 value = tmparray[index];
3178 MEM_delete(tmparray);
3179
3180 return value;
3181}
3182
3183static int property_int_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
3184{
3185 if (prop_rna_or_id.idprop) {
3186 return IDP_int_get(prop_rna_or_id.idprop);
3187 }
3188 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop_rna_or_id.rnaprop);
3189 if (iprop->get) {
3190 return iprop->get(ptr);
3191 }
3192 if (iprop->get_ex) {
3193 return iprop->get_ex(ptr, iprop);
3194 }
3195 return iprop->defaultvalue;
3196}
3197
3199{
3201
3202 PropertyRNAOrID prop_rna_or_id;
3203 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3204 BLI_assert(!prop_rna_or_id.is_array);
3205 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3206 prop = nullptr;
3207 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop_rna_or_id.rnaprop);
3209
3210 int value = property_int_get(ptr, prop_rna_or_id);
3211 if (iprop->get_transform) {
3212 value = iprop->get_transform(ptr, iprop, value, prop_rna_or_id.is_set);
3213 }
3214
3215 return value;
3216}
3217
3218void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
3219{
3221
3222 PropertyRNAOrID prop_rna_or_id;
3223 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3224 BLI_assert(!prop_rna_or_id.is_array);
3225 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3226 prop = nullptr;
3227 IDProperty *idprop = prop_rna_or_id.idprop;
3228 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop_rna_or_id.rnaprop);
3230
3231 if (iprop->set_transform) {
3232 /* Get raw, untransformed (aka 'storage') value. */
3233 const int curr_value = property_int_get(ptr, prop_rna_or_id);
3234 value = iprop->set_transform(ptr, iprop, value, curr_value, prop_rna_or_id.is_set);
3235 }
3236
3237 if (idprop) {
3238 RNA_property_int_clamp(ptr, iprop, &value);
3239 IDP_int_set(idprop, value);
3241 }
3242 else if (iprop->set) {
3243 iprop->set(ptr, value);
3244 }
3245 else if (iprop->set_ex) {
3246 iprop->set_ex(ptr, iprop, value);
3247 }
3248 else if (iprop->flag & PROP_EDITABLE) {
3249 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
3250 RNA_property_int_clamp(ptr, iprop, &value);
3252 group,
3253 bke::idprop::create(prop_rna_or_id.identifier.ref(), value, IDP_FLAG_STATIC_TYPE)
3254 .release());
3255 }
3256 }
3257}
3258
3260 const int *defarr, int defarr_length, int defvalue, int out_length, int *r_values)
3261{
3262 if (defarr && defarr_length > 0) {
3263 defarr_length = std::min(defarr_length, out_length);
3264 memcpy(r_values, defarr, sizeof(int) * defarr_length);
3265 }
3266 else {
3267 defarr_length = 0;
3268 }
3269
3270 for (int i = defarr_length; i < out_length; i++) {
3271 r_values[i] = defvalue;
3272 }
3273}
3274
3276 IntPropertyRNA *iprop,
3277 int *r_values)
3278{
3279 if (*ptr && iprop->get_default_array) {
3280 iprop->get_default_array(ptr, iprop, r_values);
3281 return;
3282 }
3283
3284 int length = iprop->totarraylength;
3285 int out_length = RNA_property_array_length(ptr, reinterpret_cast<PropertyRNA *>(iprop));
3286
3288 iprop->defaultarray, length, iprop->defaultvalue, out_length, r_values);
3289}
3290
3292 PropertyRNAOrID &prop_rna_or_id,
3293 MutableSpan<int> r_values)
3294{
3295 PropertyRNA *rna_prop = prop_rna_or_id.rnaprop;
3296 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(rna_prop);
3297 if (prop_rna_or_id.idprop) {
3298 IDProperty *idprop = prop_rna_or_id.idprop;
3299 BLI_assert(idprop->len == RNA_property_array_length(ptr, rna_prop) ||
3300 (rna_prop->flag & PROP_IDPROPERTY));
3301 if (rna_prop->arraydimension == 0) {
3302 r_values[0] = RNA_property_int_get(ptr, rna_prop);
3303 }
3304 else {
3305 memcpy(r_values.data(),
3307 sizeof(decltype(r_values)::value_type) * idprop->len);
3308 }
3309 }
3310 else if (rna_prop->arraydimension == 0) {
3311 r_values[0] = RNA_property_int_get(ptr, rna_prop);
3312 }
3313 else if (iprop->getarray) {
3314 iprop->getarray(ptr, r_values.data());
3315 }
3316 else if (iprop->getarray_ex) {
3317 iprop->getarray_ex(ptr, rna_prop, r_values.data());
3318 }
3319 else {
3320 rna_property_int_get_default_array_values(ptr, iprop, r_values.data());
3321 }
3322}
3323
3325{
3327
3328 PropertyRNAOrID prop_rna_or_id;
3329 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3330 BLI_assert(prop_rna_or_id.is_array);
3331 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3332 prop = nullptr;
3333 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop_rna_or_id.rnaprop);
3335
3336 MutableSpan<int> r_values(values, int64_t(prop_rna_or_id.array_len));
3337 values = nullptr; /* Do not access this 'raw' pointer anymore in code below. */
3338 property_int_get_array(ptr, prop_rna_or_id, r_values);
3339 if (iprop->getarray_transform) {
3340 /* NOTE: Given current implementation, it would _probably_ be safe to use `values` for both
3341 * input 'current values' and output 'final values', since python will make a copy of the input
3342 * anyways. Think it's better to keep it clean and make a copy here to avoid any potential
3343 * issues in the future though. */
3344 Array<int, RNA_STACK_ARRAY> curr_values(r_values.as_span());
3345 iprop->getarray_transform(
3346 ptr, iprop, curr_values.data(), prop_rna_or_id.is_set, r_values.data());
3347 }
3348}
3349
3351 PropertyRNA *prop,
3352 int *values,
3353 int values_num)
3354{
3355 BLI_assert(values_num >= 0);
3356 const int array_num = RNA_property_array_length(ptr, prop);
3357 if (values_num >= array_num) {
3358 RNA_property_int_get_array(ptr, prop, values);
3359 return;
3360 }
3361
3362 Array<int, RNA_STACK_ARRAY> value_buf(array_num);
3363 RNA_property_int_get_array(ptr, prop, value_buf.data());
3364 memcpy(values, value_buf.data(), sizeof(*values) * values_num);
3365}
3366
3368{
3369 const int array_len = RNA_property_array_length(ptr, prop);
3370
3371 if (array_len <= 0) {
3372 values[0] = 0;
3373 values[1] = 0;
3374 }
3375 else if (array_len == 1) {
3376 RNA_property_int_get_array(ptr, prop, values);
3377 values[1] = values[0];
3378 }
3379 else {
3380 int arr_stack[32];
3381 int *arr;
3382 int i;
3383
3384 if (array_len > 32) {
3385 arr = MEM_new_array_uninitialized<int>(size_t(array_len), __func__);
3386 }
3387 else {
3388 arr = arr_stack;
3389 }
3390
3391 RNA_property_int_get_array(ptr, prop, arr);
3392 values[0] = values[1] = arr[0];
3393 for (i = 1; i < array_len; i++) {
3394 values[0] = std::min(values[0], arr[i]);
3395 values[1] = std::max(values[1], arr[i]);
3396 }
3397
3398 if (arr != arr_stack) {
3399 MEM_delete(arr);
3400 }
3401 }
3402}
3403
3405{
3406 int tmp[RNA_MAX_ARRAY_LENGTH];
3407 int len = rna_ensure_property_array_length(ptr, prop);
3408
3410 BLI_assert(RNA_property_array_check(prop) != false);
3411 BLI_assert(index >= 0);
3412 BLI_assert(index < len);
3413
3414 if (len <= RNA_MAX_ARRAY_LENGTH) {
3415 RNA_property_int_get_array(ptr, prop, tmp);
3416 return tmp[index];
3417 }
3418 int *tmparray, value;
3419
3420 tmparray = MEM_new_array_uninitialized<int>(size_t(len), __func__);
3421 RNA_property_int_get_array(ptr, prop, tmparray);
3422 value = tmparray[index];
3423 MEM_delete(tmparray);
3424
3425 return value;
3426}
3427
3428void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
3429{
3431
3432 PropertyRNAOrID prop_rna_or_id;
3433 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3434 BLI_assert(prop_rna_or_id.is_array);
3435 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3436 prop = nullptr;
3437 IDProperty *idprop = prop_rna_or_id.idprop;
3438 PropertyRNA *rna_prop = prop_rna_or_id.rnaprop;
3439 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(rna_prop);
3441
3442 const int64_t values_num = int64_t(prop_rna_or_id.array_len);
3443 Span<int> final_values(values, values_num);
3444 values = nullptr; /* Do not access this 'raw' pointer anymore in code below. */
3445 /* Default init does not allocate anything, so it's cheap. This is only reinitialized with actual
3446 * `values_num` items if `setarray_transform` is called. */
3447 Array<int, RNA_STACK_ARRAY> final_values_storage{};
3448 if (iprop->setarray_transform) {
3449 /* Get raw, untransformed (aka 'storage') value. */
3450 Array<int, RNA_STACK_ARRAY> curr_values(values_num);
3451 property_int_get_array(ptr, prop_rna_or_id, curr_values.as_mutable_span());
3452
3453 final_values_storage.reinitialize(values_num);
3454 iprop->setarray_transform(ptr,
3455 rna_prop,
3456 final_values.data(),
3457 curr_values.data(),
3458 prop_rna_or_id.is_set,
3459 final_values_storage.data());
3460 final_values = final_values_storage.as_span();
3461 }
3462
3463 if (idprop) {
3464 BLI_assert(idprop->len == values_num);
3465 if (rna_prop->arraydimension == 0) {
3466 IDP_int_set(idprop, final_values[0]);
3467 }
3468 else {
3469 memcpy(IDP_array_int_get(idprop),
3470 final_values.data(),
3471 sizeof(decltype(final_values)::value_type) * idprop->len);
3472 }
3473
3475 }
3476 else if (rna_prop->arraydimension == 0) {
3477 RNA_property_int_set(ptr, rna_prop, final_values[0]);
3478 }
3479 else if (iprop->setarray) {
3480 iprop->setarray(ptr, final_values.data());
3481 }
3482 else if (iprop->setarray_ex) {
3483 iprop->setarray_ex(ptr, rna_prop, final_values.data());
3484 }
3485 else if (rna_prop->flag & PROP_EDITABLE) {
3486 // RNA_property_int_clamp_array(ptr, prop, &value); /* TODO. */
3487 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
3489 group,
3490 bke::idprop::create(prop_rna_or_id.identifier.ref(), final_values, IDP_FLAG_STATIC_TYPE)
3491 .release());
3492 }
3493 }
3494}
3495
3497 PropertyRNA *prop,
3498 const int *values,
3499 int values_num)
3500{
3501 BLI_assert(values_num >= 0);
3502 const int array_num = RNA_property_array_length(ptr, prop);
3503 if (values_num >= array_num) {
3504 RNA_property_int_set_array(ptr, prop, values);
3505 return;
3506 }
3507
3508 Array<int, RNA_STACK_ARRAY> value_buf(array_num);
3509 RNA_property_int_get_array(ptr, prop, value_buf.data());
3510 memcpy(value_buf.data(), values, sizeof(*values) * values_num);
3511 RNA_property_int_set_array(ptr, prop, value_buf.data());
3512}
3513
3515{
3516 int tmp[RNA_MAX_ARRAY_LENGTH];
3517 int len = rna_ensure_property_array_length(ptr, prop);
3518
3520 BLI_assert(RNA_property_array_check(prop) != false);
3521 BLI_assert(index >= 0);
3522 BLI_assert(index < len);
3523
3524 if (len <= RNA_MAX_ARRAY_LENGTH) {
3525 RNA_property_int_get_array(ptr, prop, tmp);
3526 tmp[index] = value;
3527 RNA_property_int_set_array(ptr, prop, tmp);
3528 }
3529 else {
3530 int *tmparray;
3531
3532 tmparray = MEM_new_array_uninitialized<int>(size_t(len), __func__);
3533 RNA_property_int_get_array(ptr, prop, tmparray);
3534 tmparray[index] = value;
3535 RNA_property_int_set_array(ptr, prop, tmparray);
3536 MEM_delete(tmparray);
3537 }
3538}
3539
3541{
3542 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(rna_ensure_property(prop));
3544
3545 if (prop->magic != RNA_MAGIC) {
3546 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
3547 if (idprop->ui_data) {
3548 const IDPropertyUIDataInt *ui_data = reinterpret_cast<const IDPropertyUIDataInt *>(
3549 idprop->ui_data);
3550 return ui_data->default_value;
3551 }
3552 }
3553 if (iprop->get_default) {
3554 return iprop->get_default(ptr, prop);
3555 }
3556
3557 return iprop->defaultvalue;
3558}
3559
3561{
3562 if (prop->magic == RNA_MAGIC) {
3563 return false;
3564 }
3565
3566 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
3567 BLI_assert(idprop->type == IDP_INT);
3568
3569 IDPropertyUIDataInt *ui_data = reinterpret_cast<IDPropertyUIDataInt *>(
3571 ui_data->default_value = value;
3572 return true;
3573}
3574
3576{
3577 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(rna_ensure_property(prop));
3579
3581 BLI_assert(RNA_property_array_check(prop) != false);
3582
3583 if (prop->magic != RNA_MAGIC) {
3585
3586 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
3587 if (idprop->ui_data) {
3588 BLI_assert(idprop->type == IDP_ARRAY);
3589 BLI_assert(idprop->subtype == IDP_INT);
3590 const IDPropertyUIDataInt *ui_data = reinterpret_cast<const IDPropertyUIDataInt *>(
3591 idprop->ui_data);
3592 if (ui_data->default_array) {
3594 ui_data->default_array_len,
3595 ui_data->default_value,
3596 length,
3597 values);
3598 }
3599 else {
3601 nullptr, 0, ui_data->default_value, length, values);
3602 }
3603 }
3604 }
3605 else if (prop->arraydimension == 0) {
3606 values[0] = iprop->defaultvalue;
3607 }
3608 else {
3610 }
3611}
3612
3614{
3615 int tmp[RNA_MAX_ARRAY_LENGTH];
3616 int len = rna_ensure_property_array_length(ptr, prop);
3617
3619 BLI_assert(RNA_property_array_check(prop) != false);
3620 BLI_assert(index >= 0);
3621 BLI_assert(index < len);
3622
3623 if (len <= RNA_MAX_ARRAY_LENGTH) {
3624 RNA_property_int_get_default_array(ptr, prop, tmp);
3625 return tmp[index];
3626 }
3627 int *tmparray, value;
3628
3629 tmparray = MEM_new_array_uninitialized<int>(size_t(len), __func__);
3630 RNA_property_int_get_default_array(ptr, prop, tmparray);
3631 value = tmparray[index];
3632 MEM_delete(tmparray);
3633
3634 return value;
3635}
3636
3637static float property_float_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
3638{
3639 if (prop_rna_or_id.idprop) {
3640 IDProperty *idprop = prop_rna_or_id.idprop;
3641 if (idprop->type == IDP_FLOAT) {
3642 return IDP_float_get(idprop);
3643 }
3644 return float(IDP_double_get(idprop));
3645 }
3646 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop_rna_or_id.rnaprop);
3647 if (fprop->get) {
3648 return fprop->get(ptr);
3649 }
3650 if (fprop->get_ex) {
3651 return fprop->get_ex(ptr, fprop);
3652 }
3653 return fprop->defaultvalue;
3654}
3655
3657{
3659
3660 PropertyRNAOrID prop_rna_or_id;
3661 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3662 BLI_assert(!prop_rna_or_id.is_array);
3663 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3664 prop = nullptr;
3665 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop_rna_or_id.rnaprop);
3667
3668 float value = property_float_get(ptr, prop_rna_or_id);
3669 if (fprop->get_transform) {
3670 value = fprop->get_transform(ptr, fprop, value, prop_rna_or_id.is_set);
3671 }
3672
3673 return value;
3674}
3675
3676void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
3677{
3679
3680 PropertyRNAOrID prop_rna_or_id;
3681 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3682 BLI_assert(!prop_rna_or_id.is_array);
3683 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3684 prop = nullptr;
3685 IDProperty *idprop = prop_rna_or_id.idprop;
3686 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop_rna_or_id.rnaprop);
3688
3689 if (fprop->set_transform) {
3690 /* Get raw, untransformed (aka 'storage') value. */
3691 const float curr_value = property_float_get(ptr, prop_rna_or_id);
3692 value = fprop->set_transform(ptr, fprop, value, curr_value, prop_rna_or_id.is_set);
3693 }
3694
3695 if (idprop) {
3696 RNA_property_float_clamp(ptr, fprop, &value);
3697 if (idprop->type == IDP_FLOAT) {
3698 IDP_float_set(idprop, value);
3699 }
3700 else {
3701 IDP_double_set(idprop, double(value));
3702 }
3704 }
3705 else if (fprop->set) {
3706 fprop->set(ptr, value);
3707 }
3708 else if (fprop->set_ex) {
3709 fprop->set_ex(ptr, fprop, value);
3710 }
3711 else if (fprop->flag & PROP_EDITABLE) {
3712 RNA_property_float_clamp(ptr, fprop, &value);
3713 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
3715 group,
3716 bke::idprop::create(prop_rna_or_id.identifier.ref(), value, IDP_FLAG_STATIC_TYPE)
3717 .release());
3718 }
3719 }
3720}
3721
3723 const float *defarr, int defarr_length, float defvalue, int out_length, float *r_values)
3724{
3725 if (defarr && defarr_length > 0) {
3726 defarr_length = std::min(defarr_length, out_length);
3727 memcpy(r_values, defarr, sizeof(float) * defarr_length);
3728 }
3729 else {
3730 defarr_length = 0;
3731 }
3732
3733 for (int i = defarr_length; i < out_length; i++) {
3734 r_values[i] = defvalue;
3735 }
3736}
3737
3741static void rna_property_float_fill_default_array_values_double(const double *default_array,
3742 const int default_array_len,
3743 const double default_value,
3744 const int out_length,
3745 float *r_values)
3746{
3747 const int array_copy_len = std::min(out_length, default_array_len);
3748
3749 for (int i = 0; i < array_copy_len; i++) {
3750 r_values[i] = float(default_array[i]);
3751 }
3752
3753 for (int i = array_copy_len; i < out_length; i++) {
3754 r_values[i] = float(default_value);
3755 }
3756}
3757
3759 FloatPropertyRNA *fprop,
3760 float *r_values)
3761{
3762 if (*ptr && fprop->get_default_array) {
3763 fprop->get_default_array(ptr, fprop, r_values);
3764 return;
3765 }
3766
3767 int length = fprop->totarraylength;
3768 int out_length = RNA_property_array_length(ptr, fprop);
3769
3771 fprop->defaultarray, length, fprop->defaultvalue, out_length, r_values);
3772}
3773
3775 PropertyRNAOrID &prop_rna_or_id,
3776 MutableSpan<float> r_values)
3777{
3778 PropertyRNA *rna_prop = prop_rna_or_id.rnaprop;
3779 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(rna_prop);
3780 if (prop_rna_or_id.idprop) {
3781 IDProperty *idprop = prop_rna_or_id.idprop;
3782 BLI_assert(idprop->len == RNA_property_array_length(ptr, rna_prop) ||
3783 (rna_prop->flag & PROP_IDPROPERTY));
3784 if (rna_prop->arraydimension == 0) {
3785 r_values[0] = RNA_property_float_get(ptr, rna_prop);
3786 }
3787 else if (idprop->subtype == IDP_FLOAT) {
3788 memcpy(r_values.data(),
3790 sizeof(decltype(r_values)::value_type) * idprop->len);
3791 }
3792 else {
3793 double *src_values = IDP_array_double_get(idprop);
3794 for (int i = 0; i < idprop->len; i++) {
3795 r_values[i] = float(src_values[i]);
3796 }
3797 }
3798 }
3799 else if (rna_prop->arraydimension == 0) {
3800 r_values[0] = RNA_property_float_get(ptr, rna_prop);
3801 }
3802 else if (fprop->getarray) {
3803 fprop->getarray(ptr, r_values.data());
3804 }
3805 else if (fprop->getarray_ex) {
3806 fprop->getarray_ex(ptr, rna_prop, r_values.data());
3807 }
3808 else {
3809 rna_property_float_get_default_array_values(ptr, fprop, r_values.data());
3810 }
3811}
3812
3814{
3816 BLI_assert(RNA_property_array_check(prop) != false);
3817
3818 PropertyRNAOrID prop_rna_or_id;
3819 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3820 BLI_assert(prop_rna_or_id.is_array);
3821 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3822 prop = nullptr;
3823 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop_rna_or_id.rnaprop);
3825
3826 MutableSpan<float> r_values(values, int64_t(prop_rna_or_id.array_len));
3827 values = nullptr; /* Do not access this 'raw' pointer anymore in code below. */
3828 property_float_get_array(ptr, prop_rna_or_id, r_values);
3829 if (fprop->getarray_transform) {
3830 /* NOTE: Given current implementation, it would _probably_ be safe to use `values` for both
3831 * input 'current values' and output 'final values', since python will make a copy of the input
3832 * anyways. Think it's better to keep it clean and make a copy here to avoid any potential
3833 * issues in the future though. */
3834 Array<float, RNA_STACK_ARRAY> curr_values(r_values.as_span());
3835 fprop->getarray_transform(
3836 ptr, fprop, curr_values.data(), prop_rna_or_id.is_set, r_values.data());
3837 }
3838}
3839
3841 PropertyRNA *prop,
3842 float *values,
3843 int values_num)
3844{
3845 BLI_assert(values_num >= 0);
3846 const int array_num = RNA_property_array_length(ptr, prop);
3847 if (values_num >= array_num) {
3848 RNA_property_float_get_array(ptr, prop, values);
3849 return;
3850 }
3851
3852 Array<float, RNA_STACK_ARRAY> value_buf(array_num);
3853 RNA_property_float_get_array(ptr, prop, value_buf.data());
3854 memcpy(values, value_buf.data(), sizeof(*values) * values_num);
3855}
3856
3858{
3859 const int array_len = RNA_property_array_length(ptr, prop);
3860
3861 if (array_len <= 0) {
3862 values[0] = 0.0f;
3863 values[1] = 0.0f;
3864 }
3865 else if (array_len == 1) {
3866 RNA_property_float_get_array(ptr, prop, values);
3867 values[1] = values[0];
3868 }
3869 else {
3870 float arr_stack[32];
3871 float *arr;
3872 int i;
3873
3874 if (array_len > 32) {
3875 arr = MEM_new_array_uninitialized<float>(size_t(array_len), __func__);
3876 }
3877 else {
3878 arr = arr_stack;
3879 }
3880
3881 RNA_property_float_get_array(ptr, prop, arr);
3882 values[0] = values[1] = arr[0];
3883 for (i = 1; i < array_len; i++) {
3884 values[0] = std::min(values[0], arr[i]);
3885 values[1] = std::max(values[1], arr[i]);
3886 }
3887
3888 if (arr != arr_stack) {
3889 MEM_delete(arr);
3890 }
3891 }
3892}
3893
3895{
3896 float tmp[RNA_MAX_ARRAY_LENGTH];
3897 int len = rna_ensure_property_array_length(ptr, prop);
3898
3900 BLI_assert(RNA_property_array_check(prop) != false);
3901 BLI_assert(index >= 0);
3902 BLI_assert(index < len);
3903
3904 if (len <= RNA_MAX_ARRAY_LENGTH) {
3905 RNA_property_float_get_array(ptr, prop, tmp);
3906 return tmp[index];
3907 }
3908 float *tmparray, value;
3909
3910 tmparray = MEM_new_array_uninitialized<float>(size_t(len), __func__);
3911 RNA_property_float_get_array(ptr, prop, tmparray);
3912 value = tmparray[index];
3913 MEM_delete(tmparray);
3914
3915 return value;
3916}
3917
3918void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
3919{
3921
3922 PropertyRNAOrID prop_rna_or_id;
3923 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
3924 BLI_assert(prop_rna_or_id.is_array);
3925 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
3926 prop = nullptr;
3927 IDProperty *idprop = prop_rna_or_id.idprop;
3928 PropertyRNA *rna_prop = prop_rna_or_id.rnaprop;
3929 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(rna_prop);
3931
3932 const int64_t values_num = int64_t(prop_rna_or_id.array_len);
3933 Span<float> final_values(values, values_num);
3934 values = nullptr; /* Do not access this 'raw' pointer anymore in code below. */
3935 /* Default init does not allocate anything, so it's cheap. This is only reinitialized with actual
3936 * `values_num` items if `setarray_transform` is called. */
3937 Array<float, RNA_STACK_ARRAY> final_values_storage{};
3938 if (fprop->setarray_transform) {
3939 /* Get raw, untransformed (aka 'storage') value. */
3940 Array<float, RNA_STACK_ARRAY> curr_values(values_num);
3941 property_float_get_array(ptr, prop_rna_or_id, curr_values.as_mutable_span());
3942
3943 final_values_storage.reinitialize(values_num);
3944 fprop->setarray_transform(ptr,
3945 rna_prop,
3946 final_values.data(),
3947 curr_values.data(),
3948 prop_rna_or_id.is_set,
3949 final_values_storage.data());
3950 final_values = final_values_storage.as_span();
3951 }
3952
3953 if (idprop) {
3954 BLI_assert(idprop->len == values_num);
3955 if (rna_prop->arraydimension == 0) {
3956 if (idprop->type == IDP_FLOAT) {
3957 IDP_float_set(idprop, final_values[0]);
3958 }
3959 else {
3960 IDP_double_set(idprop, double(final_values[0]));
3961 }
3962 }
3963 else if (idprop->subtype == IDP_FLOAT) {
3965 final_values.data(),
3966 sizeof(decltype(final_values)::value_type) * idprop->len);
3967 }
3968 else {
3969 double *dst_values = IDP_array_double_get(idprop);
3970 for (int i = 0; i < idprop->len; i++) {
3971 dst_values[i] = double(final_values[i]);
3972 }
3973 }
3974
3976 }
3977 else if (rna_prop->arraydimension == 0) {
3978 RNA_property_float_set(ptr, rna_prop, final_values[0]);
3979 }
3980 else if (fprop->setarray) {
3981 fprop->setarray(ptr, final_values.data());
3982 }
3983 else if (fprop->setarray_ex) {
3984 fprop->setarray_ex(ptr, rna_prop, final_values.data());
3985 }
3986 else if (rna_prop->flag & PROP_EDITABLE) {
3987 // RNA_property_float_clamp_array(ptr, prop, &value); /* TODO. */
3988 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
3990 group,
3991 bke::idprop::create(prop_rna_or_id.identifier.ref(), final_values, IDP_FLAG_STATIC_TYPE)
3992 .release());
3993 }
3994 }
3995}
3996
3998 PropertyRNA *prop,
3999 const float *values,
4000 int values_num)
4001{
4002 BLI_assert(values_num >= 0);
4003 const int array_num = RNA_property_array_length(ptr, prop);
4004 if (values_num >= array_num) {
4005 RNA_property_float_set_array(ptr, prop, values);
4006 return;
4007 }
4008
4009 Array<float, RNA_STACK_ARRAY> value_buf(array_num);
4010 RNA_property_float_get_array(ptr, prop, value_buf.data());
4011 memcpy(value_buf.data(), values, sizeof(*values) * values_num);
4012 RNA_property_float_set_array(ptr, prop, value_buf.data());
4013}
4014
4016{
4017 float tmp[RNA_MAX_ARRAY_LENGTH];
4018 int len = rna_ensure_property_array_length(ptr, prop);
4019
4021 BLI_assert(RNA_property_array_check(prop) != false);
4022 BLI_assert(index >= 0);
4023 BLI_assert(index < len);
4024
4025 if (len <= RNA_MAX_ARRAY_LENGTH) {
4026 RNA_property_float_get_array(ptr, prop, tmp);
4027 tmp[index] = value;
4028 RNA_property_float_set_array(ptr, prop, tmp);
4029 }
4030 else {
4031 float *tmparray;
4032
4033 tmparray = MEM_new_array_uninitialized<float>(size_t(len), __func__);
4034 RNA_property_float_get_array(ptr, prop, tmparray);
4035 tmparray[index] = value;
4036 RNA_property_float_set_array(ptr, prop, tmparray);
4037 MEM_delete(tmparray);
4038 }
4039}
4040
4042{
4043 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(rna_ensure_property(prop));
4045
4047 BLI_assert(RNA_property_array_check(prop) == false);
4048
4049 if (prop->magic != RNA_MAGIC) {
4050 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
4051 if (idprop->ui_data) {
4053 const IDPropertyUIDataFloat *ui_data = reinterpret_cast<const IDPropertyUIDataFloat *>(
4054 idprop->ui_data);
4055 return float(ui_data->default_value);
4056 }
4057 }
4058 if (fprop->get_default) {
4059 return fprop->get_default(ptr, prop);
4060 }
4061
4062 return fprop->defaultvalue;
4063}
4064
4066{
4067 if (prop->magic == RNA_MAGIC) {
4068 return false;
4069 }
4070
4071 IDProperty *idprop = reinterpret_cast<IDProperty *>(prop);
4072 BLI_assert(idprop->type == IDP_FLOAT);
4073
4074 IDPropertyUIDataFloat *ui_data = reinterpret_cast<IDPropertyUIDataFloat *>(
4076 ui_data->default_value = double(value);
4077 return true;
4078}
4079
4081{
4082 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(rna_ensure_property(prop));
4084
4086 BLI_assert(RNA_property_array_check(prop) != false);
4087
4088 if (prop->magic != RNA_MAGIC) {
4090
4091 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
4092 if (idprop->ui_data) {
4093 BLI_assert(idprop->type == IDP_ARRAY);
4095 const IDPropertyUIDataFloat *ui_data = reinterpret_cast<const IDPropertyUIDataFloat *>(
4096 idprop->ui_data);
4098 ui_data->default_array_len,
4099 ui_data->default_value,
4100 length,
4101 values);
4102 }
4103 }
4104 else if (prop->arraydimension == 0) {
4105 values[0] = fprop->defaultvalue;
4106 }
4107 else {
4109 }
4110}
4111
4113{
4114 float tmp[RNA_MAX_ARRAY_LENGTH];
4115 int len = rna_ensure_property_array_length(ptr, prop);
4116
4118 BLI_assert(RNA_property_array_check(prop) != false);
4119 BLI_assert(index >= 0);
4120 BLI_assert(index < len);
4121
4122 if (len <= RNA_MAX_ARRAY_LENGTH) {
4124 return tmp[index];
4125 }
4126 float *tmparray, value;
4127
4128 tmparray = MEM_new_array_uninitialized<float>(size_t(len), __func__);
4129 RNA_property_float_get_default_array(ptr, prop, tmparray);
4130 value = tmparray[index];
4131 MEM_delete(tmparray);
4132
4133 return value;
4134}
4135
4137{
4138 if (prop_rna_or_id.idprop) {
4139 IDProperty *idprop = prop_rna_or_id.idprop;
4140 if (idprop->subtype == IDP_STRING_SUB_BYTE) {
4141 return size_t(idprop->len);
4142 }
4143 /* these _must_ stay in sync */
4144 if (strlen(IDP_string_get(idprop)) != idprop->len - 1) {
4145 printf("%zu vs. %d\n", strlen(IDP_string_get(idprop)), idprop->len - 1);
4146 }
4147 BLI_assert(strlen(IDP_string_get(idprop)) == idprop->len - 1);
4148 return size_t(idprop->len - 1);
4149 }
4150
4151 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop_rna_or_id.rnaprop);
4152 if (sprop->length) {
4153 return sprop->length(ptr);
4154 }
4155 if (sprop->length_ex) {
4156 return size_t(sprop->length_ex(ptr, sprop));
4157 }
4158 if (sprop->get_default) {
4159 const std::string default_value = sprop->get_default(ptr, prop_rna_or_id.rnaprop);
4160 return default_value.size();
4161 }
4162 return strlen(sprop->defaultvalue);
4163}
4164
4165static std::string property_string_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
4166{
4167 if (prop_rna_or_id.idprop) {
4168 const size_t length = property_string_length_storage(ptr, prop_rna_or_id);
4169 return std::string{IDP_string_get(prop_rna_or_id.idprop), length};
4170 }
4171 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop_rna_or_id.rnaprop);
4172 if (sprop->get) {
4173 const size_t length = property_string_length_storage(ptr, prop_rna_or_id);
4174 /* Note: after `resize()` the underlying buffer is actually at least
4175 * `length + 1` bytes long, because (since C++11) `std::string` guarantees
4176 * a terminating null byte, but that is not considered part of the length. */
4177 std::string string_ret;
4178 string_ret.resize(length);
4179
4180 sprop->get(ptr, string_ret.data());
4181 return string_ret;
4182 }
4183 if (sprop->get_ex) {
4184 return sprop->get_ex(ptr, sprop);
4185 }
4186 if (sprop->get_default) {
4187 return sprop->get_default(ptr, prop_rna_or_id.rnaprop);
4188 }
4189 return sprop->defaultvalue;
4190}
4191
4193{
4195 PropertyRNAOrID prop_rna_or_id;
4196 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
4197 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
4198 prop = nullptr;
4199 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop_rna_or_id.rnaprop);
4201
4202 std::string string_ret = property_string_get(ptr, prop_rna_or_id);
4203 if (sprop->get_transform) {
4204 string_ret = sprop->get_transform(ptr, sprop, string_ret, prop_rna_or_id.is_set);
4205 }
4206
4207 BLI_assert_msg(!sprop->maxlength || string_ret.size() < sprop->maxlength,
4208 "Returned string exceeds the property's max length");
4209
4210 return string_ret;
4211}
4212
4213void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value)
4214{
4215 const std::string string_ret = RNA_property_string_get(ptr, prop);
4216
4217 memcpy(value, string_ret.c_str(), string_ret.size() + 1);
4218}
4219
4221 PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
4222{
4223 if (fixedbuf) {
4224 BLI_string_debug_size(fixedbuf, fixedlen);
4225 }
4226
4227 const std::string string_ret = RNA_property_string_get(ptr, prop);
4228
4229 char *buf;
4230 if (string_ret.size() < fixedlen) {
4231 buf = fixedbuf;
4232 }
4233 else {
4234 buf = MEM_new_array_uninitialized<char>(string_ret.size() + 1, __func__);
4235 }
4236
4237 memcpy(buf, string_ret.c_str(), string_ret.size() + 1);
4238 if (r_len) {
4239 *r_len = int(string_ret.size());
4240 }
4241
4242 return buf;
4243}
4244
4246{
4248 PropertyRNAOrID prop_rna_or_id;
4249 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
4250 prop = nullptr;
4251 /* NOTE: `prop` is kept unchanged, to allow e.g. call to `RNA_property_string_get` without
4252 * further complications.
4253 * `sprop->property` should be used when access to an actual RNA property is required.
4254 */
4255 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop_rna_or_id.rnaprop);
4257
4258 /* If there is a `get_transform` callback, no choice but get that final string to find out its
4259 * length. Otherwise, get the 'storage length', which is typically more efficient to compute. */
4260 if (sprop->get_transform) {
4261 std::string string_final = property_string_get(ptr, prop_rna_or_id);
4262 string_final = sprop->get_transform(ptr, sprop, string_final, prop_rna_or_id.is_set);
4263 return int(string_final.size());
4264 }
4265 return int(property_string_length_storage(ptr, prop_rna_or_id));
4266}
4267
4268void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
4269{
4271 PropertyRNAOrID prop_rna_or_id;
4272 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
4273 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
4274 prop = nullptr;
4275 IDProperty *idprop = prop_rna_or_id.idprop;
4276 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop_rna_or_id.rnaprop);
4278
4279 /* Value can be nullptr, see #145562. */
4280 /* FIXME: unclear if this function is supposed to accept nullptr values? */
4281 std::string value_set = value ? value : "";
4282 if (sprop->set_transform) {
4283 /* Get raw, untransformed (aka 'storage') value. */
4284 const std::string curr_value = property_string_get(ptr, prop_rna_or_id);
4285 value_set = sprop->set_transform(ptr, sprop, value_set, curr_value, prop_rna_or_id.is_set);
4286 }
4287
4288 if (idprop) {
4289 /* both IDP_STRING_SUB_BYTE / IDP_STRING_SUB_UTF8 */
4292 }
4293 else if (sprop->set) {
4294 sprop->set(ptr, value_set.c_str()); /* set function needs to clamp itself */
4295 }
4296 else if (sprop->set_ex) {
4297 sprop->set_ex(ptr, sprop, value_set); /* set function needs to clamp itself */
4298 }
4299 else if (sprop->flag & PROP_EDITABLE) {
4300 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
4301 IDP_AddToGroup(group,
4302 IDP_NewStringMaxSize(value_set.c_str(),
4304 prop_rna_or_id.identifier.ref(),
4306 }
4307 }
4308}
4309
4310void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len)
4311{
4314 PropertyRNAOrID prop_rna_or_id;
4315 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
4316 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
4317 prop = nullptr;
4318 IDProperty *idprop = prop_rna_or_id.idprop;
4319 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop_rna_or_id.rnaprop);
4321
4322 std::string value_set = {value, size_t(len)};
4323 if (sprop->set_transform) {
4324 /* Get raw, untransformed (aka 'storage') value. */
4325 const std::string curr_value = property_string_get(ptr, prop_rna_or_id);
4326 value_set = sprop->set_transform(ptr, sprop, value_set, curr_value, prop_rna_or_id.is_set);
4327 }
4328
4329 if (idprop) {
4330 IDP_ResizeArray(idprop, value_set.size());
4331 memcpy(idprop->data.pointer, value_set.data(), value_set.size());
4333 }
4334 else if (sprop->set) {
4335 sprop->set(ptr, value_set.c_str()); /* set function needs to clamp itself */
4336 }
4337 else if (sprop->set_ex) {
4338 sprop->set_ex(ptr, sprop, value_set); /* set function needs to clamp itself */
4339 }
4340 else if (sprop->flag & PROP_EDITABLE) {
4341 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
4342 IDPropertyTemplate val = {0};
4343 val.string.str = value_set.c_str();
4344 val.string.len = value_set.size();
4345 val.string.subtype = IDP_STRING_SUB_BYTE;
4347 group, IDP_New(IDP_STRING, &val, prop_rna_or_id.identifier.ref(), IDP_FLAG_STATIC_TYPE));
4348 }
4349 }
4350}
4351
4353 PropertyRNA *prop,
4354 char *value,
4355 const int value_maxncpy)
4356{
4357 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(rna_ensure_property(prop));
4358
4359 if (prop->magic != RNA_MAGIC) {
4360 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
4361 if (idprop->ui_data) {
4362 BLI_assert(idprop->type == IDP_STRING);
4363 const IDPropertyUIDataString *ui_data = reinterpret_cast<const IDPropertyUIDataString *>(
4364 idprop->ui_data);
4365 BLI_strncpy(value, ui_data->default_value, value_maxncpy);
4366 return;
4367 }
4368
4369 value[0] = '\0';
4370 return;
4371 }
4372
4375
4376 if (sprop->get_default) {
4377 std::string default_value = sprop->get_default(ptr, prop);
4378 if (RNA_property_string_is_utf8(prop)) {
4379 BLI_strncpy_utf8(value, default_value.c_str(), value_maxncpy);
4380 }
4381 else {
4382 BLI_strncpy(value, default_value.c_str(), value_maxncpy);
4383 }
4384 return;
4385 }
4386 if (RNA_property_string_is_utf8(prop)) {
4387 BLI_strncpy_utf8(value, sprop->defaultvalue, value_maxncpy);
4388 }
4389 else {
4390 BLI_strncpy(value, sprop->defaultvalue, value_maxncpy);
4391 }
4392}
4393
4395 PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
4396{
4397 char *buf;
4398 int length;
4399
4401
4403
4404 if (length + 1 < fixedlen) {
4405 buf = fixedbuf;
4406 }
4407 else {
4408 buf = MEM_new_array_zeroed<char>(size_t(length) + 1, __func__);
4409 }
4410
4411 RNA_property_string_get_default(ptr, prop, buf, length + 1);
4412
4413 if (r_len) {
4414 *r_len = length;
4415 }
4416
4417 return buf;
4418}
4419
4421{
4422 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(rna_ensure_property(prop));
4423
4424 if (prop->magic != RNA_MAGIC) {
4425 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
4426 if (idprop->ui_data) {
4427 BLI_assert(idprop->type == IDP_STRING);
4428 const IDPropertyUIDataString *ui_data = reinterpret_cast<const IDPropertyUIDataString *>(
4429 idprop->ui_data);
4430 if (ui_data->default_value != nullptr) {
4431 return strlen(ui_data->default_value);
4432 }
4433 }
4434
4435 return 0;
4436 }
4437
4439 if (sprop->get_default) {
4440 const std::string default_value = sprop->get_default(ptr, prop);
4441 return default_value.size();
4442 }
4443
4444 return strlen(sprop->defaultvalue);
4445}
4446
4448{
4449 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(rna_ensure_property(prop));
4450 if (prop->magic != RNA_MAGIC) {
4452 }
4454 if (sprop->search) {
4456 }
4457 else {
4458 BLI_assert(sprop->search_flag == 0);
4459 }
4460 return sprop->search_flag;
4461}
4462
4464 PointerRNA *ptr,
4465 PropertyRNA *prop,
4466 const char *edit_text,
4468{
4470 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(rna_ensure_property(prop));
4472 sprop->search(C, ptr, prop, edit_text, visit_fn);
4473}
4474
4475std::optional<std::string> RNA_property_string_path_filter(const bContext *C,
4476 PointerRNA *ptr,
4477 PropertyRNA *prop)
4478{
4480 PropertyRNA *rna_prop = rna_ensure_property(prop);
4481 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(rna_prop);
4483 if (!sprop->path_filter) {
4484 return std::nullopt;
4485 }
4486 return sprop->path_filter(C, ptr, rna_prop);
4487}
4488
4489static int property_enum_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
4490{
4491 if (prop_rna_or_id.idprop) {
4492 return IDP_int_get(prop_rna_or_id.idprop);
4493 }
4494 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop_rna_or_id.rnaprop);
4495 if (eprop->get) {
4496 return eprop->get(ptr);
4497 }
4498 if (eprop->get_ex) {
4499 return eprop->get_ex(ptr, eprop);
4500 }
4501 return eprop->defaultvalue;
4502}
4503
4505{
4507
4508 PropertyRNAOrID prop_rna_or_id;
4509 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
4510 BLI_assert(!prop_rna_or_id.is_array);
4511 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
4512 prop = nullptr;
4513 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop_rna_or_id.rnaprop);
4515
4516 int value = property_enum_get(ptr, prop_rna_or_id);
4517 if (eprop->get_transform) {
4518 value = eprop->get_transform(ptr, eprop, value, prop_rna_or_id.is_set);
4519 }
4520
4521 return value;
4522}
4523
4525{
4527
4528 PropertyRNAOrID prop_rna_or_id;
4529 rna_property_rna_or_id_get(prop, ptr, &prop_rna_or_id);
4530 BLI_assert(!prop_rna_or_id.is_array);
4531 /* Make initial `prop` pointer invalid, to ensure that it is not used anywhere below. */
4532 prop = nullptr;
4533 IDProperty *idprop = prop_rna_or_id.idprop;
4534 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop_rna_or_id.rnaprop);
4536
4537 if (eprop->set_transform) {
4538 /* Get raw, untransformed (aka 'storage') value. */
4539 const int curr_value = property_enum_get(ptr, prop_rna_or_id);
4540 value = eprop->set_transform(ptr, eprop, value, curr_value, prop_rna_or_id.is_set);
4541 }
4542
4543 if (idprop) {
4544 IDP_int_set(idprop, value);
4546 }
4547 else if (eprop->set) {
4548 eprop->set(ptr, value);
4549 }
4550 else if (eprop->set_ex) {
4551 eprop->set_ex(ptr, eprop, value);
4552 }
4553 else if (eprop->flag & PROP_EDITABLE) {
4554 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
4556 group,
4557 bke::idprop::create(prop_rna_or_id.identifier.ref(), value, IDP_FLAG_STATIC_TYPE)
4558 .release());
4559 }
4560 }
4561}
4562
4564{
4565 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(rna_ensure_property(prop));
4567
4568 if (prop->magic != RNA_MAGIC) {
4569 const IDProperty *idprop = reinterpret_cast<const IDProperty *>(prop);
4570 if (idprop->ui_data) {
4571 BLI_assert(idprop->type == IDP_INT);
4572 const IDPropertyUIDataInt *ui_data = reinterpret_cast<const IDPropertyUIDataInt *>(
4573 idprop->ui_data);
4574 return ui_data->default_value;
4575 }
4576 }
4578 if (eprop->get_default) {
4579 return eprop->get_default(ptr, prop);
4580 }
4581
4582 return eprop->defaultvalue;
4583}
4584
4586 const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step)
4587{
4588 const EnumPropertyItem *item_array;
4589 int totitem;
4590 bool free;
4591 int result_value = from_value;
4592 int i, i_init;
4593 int single_step = (step < 0) ? -1 : 1;
4594 int step_tot = 0;
4595
4596 RNA_property_enum_items(const_cast<bContext *>(C), ptr, prop, &item_array, &totitem, &free);
4597
4598 if (!totitem) {
4599 if (free) {
4600 MEM_delete(item_array);
4601 }
4602 return result_value;
4603 }
4604
4605 i = RNA_enum_from_value(item_array, from_value);
4606 i_init = i;
4607
4608 do {
4609 i = mod_i(i + single_step, totitem);
4610 if (item_array[i].identifier[0]) {
4611 step_tot += single_step;
4612 }
4613 } while ((i != i_init) && (step_tot != step));
4614
4615 if (i != i_init) {
4616 result_value = item_array[i].value;
4617 }
4618
4619 if (free) {
4620 MEM_delete(item_array);
4621 }
4622
4623 return result_value;
4624}
4625
4626static PointerRNA property_pointer_get(PointerRNA *ptr, PropertyRNA *prop, const bool do_create)
4627{
4628 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
4630
4631 static Mutex mutex;
4632
4634
4635 if ((idprop = rna_idproperty_check(&prop, ptr))) {
4636 pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
4637
4638 StructRNA *type = pprop->type_fn ? pprop->type_fn(ptr) : pprop->pointer_type;
4639
4640 if (RNA_struct_is_ID(type)) {
4641 /* ID PointerRNA should not have ancestors currently. */
4642 return RNA_id_pointer_create(idprop->type == IDP_GROUP ? nullptr : IDP_ID_get(idprop));
4643 }
4644
4645 /* for groups, data is idprop itself */
4646 return RNA_pointer_create_with_parent(*ptr, type, idprop);
4647 }
4649 if (pprop->get) {
4650 return pprop->get(ptr);
4651 }
4652 if (prop->flag & PROP_IDPROPERTY && do_create) {
4653 /* NOTE: While creating/writing data in an accessor is really bad design-wise, this is
4654 * currently very difficult to avoid in that case. So a global mutex is used to keep ensuring
4655 * thread safety. */
4656 std::scoped_lock lock(mutex);
4657 /* NOTE: We do not need to check again for existence of the pointer after locking here, since
4658 * this is also done in #RNA_property_pointer_add itself. */
4659 RNA_property_pointer_add(ptr, prop);
4660 return RNA_property_pointer_get(ptr, prop);
4661 }
4662 return {};
4663}
4664
4666{
4667 return property_pointer_get(ptr, prop, true);
4668}
4669
4674
4676 PropertyRNA *prop,
4677 PointerRNA ptr_value,
4678 ReportList *reports)
4679{
4680 /* Detect IDProperty and retrieve the actual PropertyRNA pointer before cast. */
4681 IDProperty *idprop = rna_idproperty_check(&prop, ptr);
4682
4684 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
4686
4687 /* This is a 'real' RNA property, not an IDProperty or a dynamic RNA property using an IDProperty
4688 * as backend storage. */
4689 if (pprop->set) {
4690 if (ptr_value.has_type() && !RNA_struct_is_a(ptr_value.type, pprop->pointer_type)) {
4691 BKE_reportf(reports,
4692 RPT_ERROR,
4693 "%s: expected %s type, not %s",
4694 __func__,
4695 pprop->pointer_type->identifier.c_str(),
4696 ptr_value.type->identifier.c_str());
4697 return;
4698 }
4699
4700#ifndef NDEBUG
4701 /* NOTE: By design, it can be safely assumed that both old and new ID pointers are valid when
4702 * accessed through RNA. Handling of invalid ID pointers, e.g. freed ones etc., should never
4703 * happen through RNA code, but directly on underlying (DNA) data.
4704 *
4705 * Setters are also not expected to free or otherwise invalidate ID pointers. So storing them
4706 * here should be safe. */
4707 BLI_assert(pprop->get);
4708 const bool is_id_refcounting = (prop->flag & PROP_ID_REFCOUNT) != 0;
4709
4710 const PointerRNA old_id_ptr = pprop->get(ptr);
4711 BLI_assert_msg(!is_id_refcounting || !old_id_ptr || RNA_struct_is_ID(old_id_ptr.type),
4712 "If the property is tagged with ID reference-counting, "
4713 "its current value should be null or an ID");
4714 const ID *old_id = (old_id_ptr.has_type() && RNA_struct_is_ID(old_id_ptr.type)) ?
4715 old_id_ptr.data_as<ID>() :
4716 nullptr;
4717 const int old_id_old_refcount = old_id ? ID_REFCOUNTING_USERS(old_id) : 0;
4718
4719 const ID *new_id = (ptr_value.type && RNA_struct_is_ID(ptr_value.type)) ?
4720 ptr_value.data_as<ID>() :
4721 nullptr;
4722 const int new_id_old_refcount = new_id ? ID_REFCOUNTING_USERS(new_id) : 0;
4723#endif
4724
4725 if (!((prop->flag & PROP_NEVER_NULL) && !ptr_value) &&
4726 !((prop->flag & PROP_ID_SELF_CHECK) && ptr->owner_id == ptr_value.owner_id))
4727 {
4728 pprop->set(ptr, ptr_value, reports);
4729 }
4730
4731#ifndef NDEBUG
4732 /* NOTE: Current checks are relatively flexible, but do expect 'reasonable' behavior (ID
4733 * handling) from custom setters.
4734 *
4735 * Should there be some very uncommon setter behavior, e.g. unassigning an ID from the property
4736 * automatically assigning it to several other reference-counting usages, this will have to be
4737 * tweaked, e.g. by adding a special 'skip checks' flag to such RNA properties. */
4738 PointerRNA current_id_ptr = pprop->get(ptr);
4740 !is_id_refcounting || !current_id_ptr || RNA_struct_is_ID(current_id_ptr.type),
4741 "If the property is tagged with ID reference-counting, its current value should be "
4742 "null or an ID");
4743 ID *current_id = (current_id_ptr.has_type() && RNA_struct_is_ID(current_id_ptr.type)) ?
4744 static_cast<ID *>(current_id_ptr.data) :
4745 nullptr;
4746
4747 if (old_id) {
4748 const int old_id_new_refcount = ID_REFCOUNTING_USERS(old_id);
4749 if (ELEM(old_id, new_id, current_id)) {
4750 BLI_assert_msg(old_id_new_refcount == old_id_old_refcount,
4751 "Reassigning the same ID to a RNA pointer property, or assignment failure, "
4752 "should not modify the original ID user-count");
4753 }
4754 else if (is_id_refcounting) {
4756 old_id_new_refcount < old_id_old_refcount,
4757 "Unassigning an ID from a reference-counting RNA pointer property should decrease "
4758 "its user-count");
4759 }
4760 else {
4762 old_id_new_refcount == old_id_old_refcount,
4763 "Unassigning an ID from a non-reference-counting RNA pointer property should not "
4764 "modify its user-count");
4765 }
4766 }
4767 if (new_id && new_id != old_id) {
4768 const int new_id_new_refcount = ID_REFCOUNTING_USERS(new_id);
4769 if (current_id == old_id) {
4770 BLI_assert_msg(new_id_new_refcount == new_id_old_refcount,
4771 "Failed assigning a new ID to a RNA pointer property, should not modify "
4772 "the new ID user-count");
4773 }
4774 else if (is_id_refcounting) {
4776 new_id_new_refcount > new_id_old_refcount,
4777 "Assigning an ID to a reference-counting RNA pointer property should increase "
4778 "its user-count");
4779 }
4780 else {
4782 new_id_new_refcount == new_id_old_refcount,
4783 "Assigning an ID to a non-reference-counting RNA pointer property should not "
4784 "modify its user-count");
4785 }
4786 }
4787#endif
4788
4789 return;
4790 }
4791
4792 /* Assigning to an IDProperty. */
4793 ID *value = static_cast<ID *>(ptr_value.data);
4794
4795 if (ptr_value.has_type() && !RNA_struct_is_a(ptr_value.type, RNA_ID)) {
4796 BKE_reportf(reports,
4797 RPT_ERROR,
4798 "%s: expected ID type, not %s",
4799 __func__,
4800 ptr_value.type->identifier.c_str());
4801 return;
4802 }
4803 if (value && (value->flag & ID_FLAG_EMBEDDED_DATA) != 0) {
4804 BKE_reportf(reports, RPT_ERROR, "%s: cannot assign an embedded ID to an IDProperty", __func__);
4805 return;
4806 }
4807
4808 /* We got an existing IDProperty. */
4809 if (idprop != nullptr) {
4810 /* Not-yet-defined ID IDProps have an IDP_GROUP type, not an IDP_ID one - because of reasons?
4811 * XXX This has to be investigated fully - there might be a good reason for it, but off hands
4812 * this seems really weird... */
4813 if (idprop->type == IDP_ID) {
4814 IDP_AssignID(idprop, value, 0);
4816 }
4817 else {
4818 BLI_assert(idprop->type == IDP_GROUP);
4819 IDProperty *group = RNA_struct_system_idprops(ptr, true);
4820 BLI_assert(group != nullptr);
4821
4823 group,
4824 bke::idprop::create(idprop->name, value, IDP_FLAG_STATIC_TYPE).release(),
4825 idprop,
4826 0);
4827 }
4828 }
4829 /* IDProperty disguised as RNA property (and not yet defined in ptr). */
4830 else if (prop->flag & PROP_EDITABLE) {
4831 if (IDProperty *group = RNA_struct_system_idprops(ptr, true)) {
4833 group,
4834 bke::idprop::create(prop->identifier.ref(), value, IDP_FLAG_STATIC_TYPE).release());
4835 }
4836 }
4837}
4838
4840{
4842 auto *pprop = reinterpret_cast<PointerPropertyRNA *>(&prop);
4843
4844 if (RNA_struct_is_a(pprop->pointer_type, RNA_ID)) {
4845 if (pprop->id_default_session_uid != 0) {
4846 ID *id = BKE_libblock_find_session_uid(&bmain, pprop->id_default_session_uid);
4847 return RNA_id_pointer_create(id);
4848 }
4849 }
4850
4851 return {};
4852}
4853
4855{
4856 // IDProperty *idprop;
4857
4859
4860 if (/*idprop=*/rna_idproperty_check(&prop, ptr)) {
4861 /* already exists */
4862 }
4863 else if (prop->flag & PROP_IDPROPERTY) {
4864 IDProperty *group;
4865
4866 group = RNA_struct_system_idprops(ptr, true);
4867 if (group) {
4869 group,
4871 }
4872 }
4873 else {
4874 printf("%s %s.%s: only supported for id properties.\n",
4875 __func__,
4876 ptr->type->identifier.c_str(),
4877 prop->identifier.c_str());
4878 }
4879}
4880
4882{
4883 IDProperty *idprop, *group;
4884
4886
4887 if ((idprop = rna_idproperty_check(&prop, ptr))) {
4888 group = RNA_struct_system_idprops(ptr, false);
4889
4890 if (group) {
4891 IDP_FreeFromGroup(group, idprop);
4892 }
4893 }
4894 else {
4895 printf("%s %s.%s: only supported for id properties.\n",
4896 __func__,
4897 ptr->type->identifier.c_str(),
4898 prop->identifier.c_str());
4899 }
4900}
4901
4903{
4904 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(iter->prop);
4905
4907 iter->parent, cprop->item_type, rna_iterator_array_get(iter), iter->ptr);
4908}
4909
4911 PropertyRNA *prop,
4913{
4915
4917
4918 *iter = {};
4919
4920 if ((idprop = rna_idproperty_check(&prop, ptr)) || (prop->flag & PROP_IDPROPERTY)) {
4921 iter->parent = *ptr;
4922 iter->prop = prop;
4923
4924 if (idprop) {
4926 ptr,
4928 sizeof(IDProperty),
4929 idprop->len,
4930 false,
4931 nullptr);
4932 }
4933 else {
4934 rna_iterator_array_begin(iter, ptr, nullptr, sizeof(IDProperty), 0, false, nullptr);
4935 }
4936
4937 if (iter->valid) {
4939 }
4940
4941 iter->idprop = 1;
4942 }
4943 else {
4945 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
4946 cprop->begin(iter, ptr);
4947 }
4948}
4949
4951{
4952 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
4953 rna_ensure_property(iter->prop));
4954
4955 if (iter->idprop) {
4957
4958 if (iter->valid) {
4960 }
4961 }
4962 else {
4963 cprop->next(iter);
4964 }
4965}
4966
4968{
4969 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
4970 rna_ensure_property(iter->prop));
4971 int i;
4972
4973 if (num > 1 && (iter->idprop || (cprop->flag_internal & PROP_INTERN_RAW_ARRAY))) {
4974 /* fast skip for array */
4975 ArrayIterator *internal = &iter->internal.array;
4976
4977 if (!internal->skip) {
4978 internal->ptr += internal->itemsize * (num - 1);
4979 iter->valid = (internal->ptr < internal->endptr);
4980 if (iter->valid) {
4982 }
4983 return;
4984 }
4985 }
4986
4987 /* slow iteration otherwise */
4988 for (i = 0; i < num && iter->valid; i++) {
4990 }
4991}
4992
4994{
4995 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
4996 rna_ensure_property(iter->prop));
4997
4998 if (iter->idprop) {
5000 }
5001 else {
5002 cprop->end(iter);
5003 }
5004}
5005
5007{
5008 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
5010
5012
5013 if ((idprop = rna_idproperty_check(&prop, ptr))) {
5014 return idprop->len;
5015 }
5017 if (cprop->length) {
5018 return cprop->length(ptr);
5019 }
5021 int length = 0;
5022
5023 RNA_property_collection_begin(ptr, prop, &iter);
5024 for (; iter.valid; RNA_property_collection_next(&iter)) {
5025 length++;
5026 }
5028
5029 return length;
5030}
5031
5033{
5036 RNA_property_collection_begin(ptr, prop, &iter);
5037 bool test = iter.valid;
5039 return !test;
5040}
5041
5042/* This helper checks whether given collection property itself is editable (we only currently
5043 * support a limited set of operations, insertion of new items, and re-ordering of those new items
5044 * exclusively). */
5046 PropertyRNA *prop,
5047 bool *r_is_liboverride)
5048{
5049 ID *id = ptr->owner_id;
5050 if (id == nullptr) {
5051 *r_is_liboverride = false;
5052 return true;
5053 }
5054
5055 const bool is_liboverride = *r_is_liboverride = ID_IS_OVERRIDE_LIBRARY(id);
5056
5057 if (!is_liboverride) {
5058 /* We return True also for linked data, as it allows tricks like py scripts 'overriding' data
5059 * of those. */
5060 return true;
5061 }
5062
5063 if (!RNA_property_overridable_get(ptr, prop)) {
5064 return false;
5065 }
5066
5067 if (prop->magic != RNA_MAGIC || (prop->flag & PROP_IDPROPERTY) == 0) {
5068 /* Insertion and such not supported for pure IDProperties for now, nor for pure RNA/DNA ones.
5069 */
5070 return false;
5071 }
5072 if ((prop->flag_override & PROPOVERRIDE_LIBRARY_INSERTION) == 0) {
5073 return false;
5074 }
5075
5076 /* No more checks to do, this collections is overridable. */
5077 return true;
5078}
5079
5081{
5083 // CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
5084
5086
5087 bool is_liboverride;
5088 if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
5089 if (r_ptr) {
5090 *r_ptr = {};
5091 }
5092 return;
5093 }
5094
5095 if ((idprop = rna_idproperty_check(&prop, ptr))) {
5096 IDProperty *item;
5097
5098 item = bke::idprop::create_group("", IDP_FLAG_STATIC_TYPE).release();
5099 if (is_liboverride) {
5101 }
5102 IDP_AppendArray(idprop, item);
5103 /* IDP_AppendArray does a shallow copy (memcpy), only free memory. */
5104 // IDP_FreeProperty(item);
5105 MEM_delete(item);
5107 }
5108 else if (prop->flag & PROP_IDPROPERTY) {
5109 IDProperty *group, *item;
5110
5111 group = RNA_struct_system_idprops(ptr, true);
5112 if (group) {
5114 IDP_AddToGroup(group, idprop);
5115
5116 item = bke::idprop::create_group("", IDP_FLAG_STATIC_TYPE).release();
5117 if (is_liboverride) {
5119 }
5120 IDP_AppendArray(idprop, item);
5121 /* #IDP_AppendArray does a shallow copy (memcpy), only free memory. */
5122 // IDP_FreeProperty(item);
5123 MEM_delete(item);
5124 }
5125 }
5126
5127 if (r_ptr) {
5128 if (idprop) {
5129 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
5130
5132 *ptr, cprop->item_type, IDP_GetIndexArray(idprop, idprop->len - 1), *r_ptr);
5133 }
5134 else {
5135 *r_ptr = {};
5136 }
5137 }
5138}
5139
5141{
5143 // CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
5144
5146
5147 bool is_liboverride;
5148 if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
5149 return false;
5150 }
5151
5152 if ((idprop = rna_idproperty_check(&prop, ptr))) {
5153 IDProperty tmp, *array;
5154 int len;
5155
5156 len = idprop->len;
5158
5159 if (key >= 0 && key < len) {
5160 if (is_liboverride && (array[key].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
5161 /* We can only remove items that we actually inserted in the local override. */
5162 return false;
5163 }
5164
5165 if (key + 1 < len) {
5166 /* move element to be removed to the back */
5167 memcpy(&tmp, &array[key], sizeof(IDProperty));
5168 memmove(array + key, array + key + 1, sizeof(IDProperty) * (len - (key + 1)));
5169 memcpy(&array[len - 1], &tmp, sizeof(IDProperty));
5170 }
5171
5173 }
5174
5175 return true;
5176 }
5177 if (prop->flag & PROP_IDPROPERTY) {
5178 return true;
5179 }
5180
5181 return false;
5182}
5183
5185 PropertyRNA *prop,
5186 int src_index,
5187 int dst_index)
5188{
5190
5191 bool is_liboverride;
5192 if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
5193 return eRNAStatus::Immutable;
5194 }
5195
5197 if ((idprop = rna_idproperty_check(&prop, ptr))) {
5198 int len = idprop->len;
5200
5201 if (src_index < 0 || src_index >= len || dst_index < 0 || dst_index >= len) {
5203 }
5204
5205 if (is_liboverride && (array[src_index].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) == 0) {
5206 /* We can only move items that we actually inserted in the local override. */
5207 return eRNAStatus::Immutable;
5208 }
5209
5210 if (src_index != dst_index) {
5211 IDProperty tmp;
5212 memcpy(&tmp, &array[src_index], sizeof(IDProperty));
5213 if (dst_index < src_index) {
5214 memmove(array + dst_index + 1,
5215 array + dst_index,
5216 sizeof(IDProperty) * (src_index - dst_index));
5217 }
5218 else {
5219 memmove(array + src_index,
5220 array + src_index + 1,
5221 sizeof(IDProperty) * (dst_index - src_index));
5222 }
5223 memcpy(&array[dst_index], &tmp, sizeof(IDProperty));
5224 }
5225 return eRNAStatus::Success;
5226 }
5227 if (prop->flag & PROP_IDPROPERTY) {
5228 /* No-init empty collection. */
5230 }
5231
5233}
5234
5236{
5238
5240
5241 bool is_liboverride;
5242 if (!property_collection_liboverride_editable(ptr, prop, &is_liboverride)) {
5243 return;
5244 }
5245
5246 if ((idprop = rna_idproperty_check(&prop, ptr))) {
5247 if (is_liboverride) {
5248 /* We can only move items that we actually inserted in the local override. */
5249 int len = idprop->len;
5251 for (int i = 0; i < len; i++) {
5252 if ((array[i].flag & IDP_FLAG_OVERRIDELIBRARY_LOCAL) != 0) {
5253 memcpy(&tmp, &array[i], sizeof(IDProperty));
5254 memmove(array + i, array + i + 1, sizeof(IDProperty) * (len - (i + 1)));
5255 memcpy(&array[len - 1], &tmp, sizeof(IDProperty));
5257 i--;
5258 }
5259 }
5260 }
5261 else {
5263 }
5265 }
5266}
5267
5269 PropertyRNA *prop,
5270 const PointerRNA *t_ptr)
5271{
5273 int index = 0;
5274
5276
5277 RNA_property_collection_begin(ptr, prop, &iter);
5278 for (index = 0; iter.valid; RNA_property_collection_next(&iter), index++) {
5279 if (iter.ptr.data == t_ptr->data) {
5280 break;
5281 }
5282 }
5284
5285 /* did we find it? */
5286 if (iter.valid) {
5287 return index;
5288 }
5289 return -1;
5290}
5291
5293{
5295 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
5296 rna_ensure_property(prop));
5297 return cprop->lookupint != nullptr;
5298}
5299
5301{
5303 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
5304 rna_ensure_property(prop));
5305 return cprop->lookupstring != nullptr;
5306}
5307
5315
5321
5323 PropertyRNA *prop,
5324 int key,
5325 PointerRNA *r_ptr)
5326{
5327 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
5328 rna_ensure_property(prop));
5330
5332
5333 if (cprop->lookupint) {
5334 /* we have a callback defined, use it */
5335 return cprop->lookupint(ptr, key, r_ptr);
5336 }
5337 /* no callback defined, just iterate and find the nth item */
5339 int i;
5340
5341 RNA_property_collection_begin(ptr, prop, &iter);
5342 for (i = 0; iter.valid; RNA_property_collection_next(&iter), i++) {
5343 if (i == key) {
5344 *r_ptr = iter.ptr;
5345 break;
5346 }
5347 }
5349
5350 if (!iter.valid) {
5351 *r_ptr = {};
5352 }
5353
5354 return iter.valid;
5355}
5356
5358 PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
5359{
5360 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
5361 rna_ensure_property(prop));
5363
5365
5366 if (!key) {
5367 *r_index = -1;
5368 *r_ptr = {};
5369 return false;
5370 }
5371
5372 if (cprop->lookupstring) {
5373 /* we have a callback defined, use it */
5374 return cprop->lookupstring(ptr, key, r_ptr);
5375 }
5376 /* no callback defined, compare with name properties if they exist */
5378 PropertyRNA *nameprop;
5379 char name_buf[256], *name;
5380 bool found = false;
5381 int keylen = strlen(key);
5382 int namelen;
5383 int index = 0;
5384
5385 RNA_property_collection_begin(ptr, prop, &iter);
5386 for (; iter.valid; RNA_property_collection_next(&iter), index++) {
5387 if (iter.ptr && iter.ptr.type->nameproperty) {
5388 nameprop = iter.ptr.type->nameproperty;
5389
5391 &iter.ptr, nameprop, name_buf, sizeof(name_buf), &namelen);
5392
5393 if ((keylen == namelen) && STREQ(name, key)) {
5394 *r_ptr = iter.ptr;
5395 found = true;
5396 }
5397
5398 if (name != name_buf) {
5399 MEM_delete(name);
5400 }
5401
5402 if (found) {
5403 break;
5404 }
5405 }
5406 }
5408
5409 if (!iter.valid) {
5410 *r_ptr = {};
5411 *r_index = -1;
5412 }
5413 else {
5414 *r_index = index;
5415 }
5416
5417 return iter.valid;
5418}
5419
5421 PropertyRNA *prop,
5422 const char *key,
5423 PointerRNA *r_ptr)
5424{
5425 int index;
5426 return RNA_property_collection_lookup_string_index(ptr, prop, key, r_ptr, &index);
5427}
5428
5430 PropertyRNA *prop,
5431 const int key,
5432 const PointerRNA *assign_ptr)
5433{
5434 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(
5435 rna_ensure_property(prop));
5437
5439
5440 if (cprop->assignint) {
5441 /* we have a callback defined, use it */
5442 return cprop->assignint(ptr, key, assign_ptr);
5443 }
5444
5445 return false;
5446}
5447
5448std::optional<PointerRNA> RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop)
5449{
5451 StructRNA *type = rna_ensure_property(prop)->srna;
5452 if (type == nullptr) {
5453 return std::nullopt;
5454 }
5455 return RNA_pointer_create_with_parent(*ptr, type, ptr->data);
5456}
5457
5459 PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, bool set, RawArray *array)
5460{
5463 char *arrayp;
5464
5466
5467 if (!(prop->flag_internal & PROP_INTERN_RAW_ARRAY) ||
5469 {
5470 return 0;
5471 }
5472
5473 RNA_property_collection_begin(ptr, prop, &iter);
5474
5475 if (iter.valid) {
5476 /* get data from array iterator and item property */
5477 internal = &iter.internal.array;
5478 arrayp = (iter.valid) ? static_cast<char *>(iter.ptr.data) : nullptr;
5479
5480 if (internal->skip || (set && !RNA_property_editable(&iter.ptr, itemprop))) {
5481 /* we might skip some items, so it's not a proper array */
5483 return 0;
5484 }
5485
5486 array->array = arrayp + itemprop->rawoffset;
5487 array->stride = internal->itemsize;
5488 array->len = (static_cast<char *>(internal->endptr) - arrayp) / internal->itemsize;
5489 array->type = itemprop->rawtype;
5490 }
5491 else {
5492 memset(array, 0, sizeof(RawArray));
5493 }
5494
5496
5497 return 1;
5498}
5499
5500#define RAW_GET(dtype, var, raw, a) \
5501 { \
5502 switch (raw.type) { \
5503 case PROP_RAW_CHAR: \
5504 var = (dtype)((char *)raw.array)[a]; \
5505 break; \
5506 case PROP_RAW_INT8: \
5507 var = (dtype)((int8_t *)raw.array)[a]; \
5508 break; \
5509 case PROP_RAW_UINT8: \
5510 var = (dtype)((uint8_t *)raw.array)[a]; \
5511 break; \
5512 case PROP_RAW_SHORT: \
5513 var = (dtype)((short *)raw.array)[a]; \
5514 break; \
5515 case PROP_RAW_UINT16: \
5516 var = (dtype)((uint16_t *)raw.array)[a]; \
5517 break; \
5518 case PROP_RAW_INT: \
5519 var = (dtype)((int *)raw.array)[a]; \
5520 break; \
5521 case PROP_RAW_BOOLEAN: \
5522 var = (dtype)((bool *)raw.array)[a]; \
5523 break; \
5524 case PROP_RAW_FLOAT: \
5525 var = (dtype)((float *)raw.array)[a]; \
5526 break; \
5527 case PROP_RAW_DOUBLE: \
5528 var = (dtype)((double *)raw.array)[a]; \
5529 break; \
5530 case PROP_RAW_INT64: \
5531 var = (dtype)((int64_t *)raw.array)[a]; \
5532 break; \
5533 case PROP_RAW_UINT64: \
5534 var = (dtype)((uint64_t *)raw.array)[a]; \
5535 break; \
5536 default: \
5537 var = (dtype)0; \
5538 } \
5539 } \
5540 (void)0
5541
5542#define RAW_SET(dtype, raw, a, var) \
5543 { \
5544 switch (raw.type) { \
5545 case PROP_RAW_CHAR: \
5546 ((char *)raw.array)[a] = char(var); \
5547 break; \
5548 case PROP_RAW_INT8: \
5549 ((int8_t *)raw.array)[a] = int8_t(var); \
5550 break; \
5551 case PROP_RAW_UINT8: \
5552 ((uint8_t *)raw.array)[a] = uint8_t(var); \
5553 break; \
5554 case PROP_RAW_SHORT: \
5555 ((short *)raw.array)[a] = short(var); \
5556 break; \
5557 case PROP_RAW_UINT16: \
5558 ((uint16_t *)raw.array)[a] = uint16_t(var); \
5559 break; \
5560 case PROP_RAW_INT: \
5561 ((int *)raw.array)[a] = int(var); \
5562 break; \
5563 case PROP_RAW_BOOLEAN: \
5564 ((bool *)raw.array)[a] = bool(var); \
5565 break; \
5566 case PROP_RAW_FLOAT: \
5567 ((float *)raw.array)[a] = float(var); \
5568 break; \
5569 case PROP_RAW_DOUBLE: \
5570 ((double *)raw.array)[a] = double(var); \
5571 break; \
5572 case PROP_RAW_INT64: \
5573 ((int64_t *)raw.array)[a] = int64_t(var); \
5574 break; \
5575 case PROP_RAW_UINT64: \
5576 ((uint64_t *)raw.array)[a] = uint64_t(var); \
5577 break; \
5578 default: \
5579 break; \
5580 } \
5581 } \
5582 (void)0
5583
5585{
5586 switch (type) {
5587 case PROP_RAW_CHAR:
5588 return sizeof(char);
5589 case PROP_RAW_INT8:
5590 return sizeof(int8_t);
5591 case PROP_RAW_UINT8:
5592 return sizeof(uint8_t);
5593 case PROP_RAW_SHORT:
5594 return sizeof(short);
5595 case PROP_RAW_UINT16:
5596 return sizeof(uint16_t);
5597 case PROP_RAW_INT:
5598 return sizeof(int);
5599 case PROP_RAW_BOOLEAN:
5600 return sizeof(bool);
5601 case PROP_RAW_FLOAT:
5602 return sizeof(float);
5603 case PROP_RAW_DOUBLE:
5604 return sizeof(double);
5605 case PROP_RAW_INT64:
5606 return sizeof(int64_t);
5607 case PROP_RAW_UINT64:
5608 return sizeof(uint64_t);
5609 default:
5610 return 0;
5611 }
5612}
5613
5615{
5617 const int dim = RNA_property_array_dimension(ptr, prop, len);
5618 int size;
5619
5620 if (dim == 0) {
5621 return 0;
5622 }
5623
5624 for (size = 1, i = 0; i < dim; i++) {
5625 size *= len[i];
5626 }
5627
5628 return size;
5629}
5630
5631static int rna_raw_access(ReportList *reports,
5632 PointerRNA *ptr,
5633 PropertyRNA *prop,
5634 const char *propname,
5635 void *inarray,
5636 RawPropertyType intype,
5637 int inlen,
5638 int set)
5639{
5640 StructRNA *ptype;
5641 PropertyRNA *itemprop, *iprop;
5642 PropertyType itemtype = PropertyType(0);
5643 RawArray in;
5644 /* Actual array length. Will always be `0` for non-array properties. */
5645 int array_len = 0;
5646 /* Item length. Will always be `1` for non-array properties. */
5647 int item_len = 0;
5648 /* Whether the accessed property is an array or not. */
5649 bool is_array;
5650
5651 /* initialize in array, stride assumed 0 in following code */
5652 in.array = inarray;
5653 in.type = intype;
5654 in.len = inlen;
5655 in.stride = 0;
5656
5657 ptype = RNA_property_pointer_type(ptr, prop);
5658
5659 /* try to get item property pointer */
5660 PointerRNA itemptr_base = RNA_pointer_create_discrete(nullptr, ptype, nullptr);
5661 itemprop = RNA_struct_find_property(&itemptr_base, propname);
5662
5663 if (itemprop) {
5664 /* we have item property pointer */
5665 RawArray out;
5666
5667 /* check type */
5668 itemtype = RNA_property_type(itemprop);
5669 is_array = RNA_property_array_check(itemprop);
5670
5671 if (!ELEM(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT, PROP_ENUM)) {
5672 BKE_report(reports, RPT_ERROR, "Only boolean, int, float, and enum properties supported");
5673 return 0;
5674 }
5675
5676 /* check item array */
5677 array_len = RNA_property_array_length(&itemptr_base, itemprop);
5678 item_len = is_array ? array_len : 1;
5679
5680 /* dynamic array? need to get length per item */
5681 if (itemprop->getlength) {
5682 itemprop = nullptr;
5683 }
5684 /* try to access as raw array */
5685 else if (RNA_property_collection_raw_array(ptr, prop, itemprop, set, &out)) {
5686 if (in.len != item_len * out.len) {
5687 BKE_reportf(reports,
5688 RPT_ERROR,
5689 "Array length mismatch (expected %d, got %d)",
5690 out.len * item_len,
5691 in.len);
5692 return 0;
5693 }
5694
5695 /* matching raw types */
5696 if (out.type == in.type) {
5697 void *inp = in.array;
5698 void *outp = out.array;
5699 size_t size;
5700
5701 size = RNA_raw_type_sizeof(out.type) * item_len;
5702
5703 if (size == out.stride) {
5704 /* The property is stored contiguously so the entire array can be copied at once. */
5705 if (set) {
5706 memcpy(outp, inp, size * out.len);
5707 }
5708 else {
5709 memcpy(inp, outp, size * out.len);
5710 }
5711 }
5712 else {
5713 for (int a = 0; a < out.len; a++) {
5714 if (set) {
5715 memcpy(outp, inp, size);
5716 }
5717 else {
5718 memcpy(inp, outp, size);
5719 }
5720
5721 inp = static_cast<char *>(inp) + size;
5722 outp = static_cast<char *>(outp) + out.stride;
5723 }
5724 }
5725
5726 return 1;
5727 }
5728
5729 /* Could also be faster with non-matching types,
5730 * for now we just do slower loop. */
5731 }
5732 BLI_assert_msg(array_len == 0 || itemtype != PROP_ENUM,
5733 "Enum array properties should not exist");
5734 }
5735
5736 {
5737 void *tmparray = nullptr;
5738 int tmplen = 0;
5739 int err = 0, j, a = 0;
5740 int needconv = 1;
5741
5742 if (((itemtype == PROP_INT) && (in.type == PROP_RAW_INT)) ||
5743 ((itemtype == PROP_BOOLEAN) && (in.type == PROP_RAW_BOOLEAN)) ||
5744 ((itemtype == PROP_FLOAT) && (in.type == PROP_RAW_FLOAT)))
5745 {
5746 /* avoid creating temporary buffer if the data type match */
5747 needconv = 0;
5748 }
5749 /* no item property pointer, can still be id property, or
5750 * property of a type derived from the collection pointer type */
5751 RNA_PROP_BEGIN (ptr, itemptr, prop) {
5752 if (itemptr) {
5753 if (itemprop) {
5754 /* we got the property already */
5755 iprop = itemprop;
5756 }
5757 else {
5758 /* not yet, look it up and verify if it is valid */
5759 iprop = RNA_struct_find_property(&itemptr, propname);
5760
5761 if (iprop) {
5762 is_array = RNA_property_array_check(iprop);
5763 array_len = rna_property_array_length_all_dimensions(&itemptr, iprop);
5764 item_len = is_array ? array_len : 1;
5765 itemtype = RNA_property_type(iprop);
5766 }
5767 else {
5768 BKE_reportf(reports, RPT_ERROR, "Property named '%s' not found", propname);
5769 err = 1;
5770 break;
5771 }
5772
5773 if (!ELEM(itemtype, PROP_BOOLEAN, PROP_INT, PROP_FLOAT, PROP_ENUM)) {
5774 BKE_report(
5775 reports, RPT_ERROR, "Only boolean, int, float and enum properties supported");
5776 err = 1;
5777 break;
5778 }
5779 BLI_assert_msg(array_len == 0 || itemtype != PROP_ENUM,
5780 "Enum array properties should not exist");
5781 }
5782
5783 /* editable check */
5784 if (!set || RNA_property_editable(&itemptr, iprop)) {
5785 if (a + item_len > in.len) {
5787 reports, RPT_ERROR, "Array length mismatch (got %d, expected more)", in.len);
5788 err = 1;
5789 break;
5790 }
5791
5792 if (array_len == 0) {
5793 /* handle conversions */
5794 if (set) {
5795 switch (itemtype) {
5796 case PROP_BOOLEAN: {
5797 int b;
5798 RAW_GET(bool, b, in, a);
5799 RNA_property_boolean_set(&itemptr, iprop, b);
5800 break;
5801 }
5802 case PROP_INT: {
5803 int i;
5804 RAW_GET(int, i, in, a);
5805 RNA_property_int_set(&itemptr, iprop, i);
5806 break;
5807 }
5808 case PROP_FLOAT: {
5809 float f;
5810 RAW_GET(float, f, in, a);
5811 RNA_property_float_set(&itemptr, iprop, f);
5812 break;
5813 }
5814 case PROP_ENUM: {
5815 int i;
5816 RAW_GET(int, i, in, a);
5817 RNA_property_enum_set(&itemptr, iprop, i);
5818 break;
5819 }
5820 default:
5822 break;
5823 }
5824 }
5825 else {
5826 switch (itemtype) {
5827 case PROP_BOOLEAN: {
5828 int b = RNA_property_boolean_get(&itemptr, iprop);
5829 RAW_SET(bool, in, a, b);
5830 break;
5831 }
5832 case PROP_INT: {
5833 int i = RNA_property_int_get(&itemptr, iprop);
5834 RAW_SET(int, in, a, i);
5835 break;
5836 }
5837 case PROP_FLOAT: {
5838 float f = RNA_property_float_get(&itemptr, iprop);
5839 RAW_SET(float, in, a, f);
5840 break;
5841 }
5842 case PROP_ENUM: {
5843 int i = RNA_property_enum_get(&itemptr, iprop);
5844 RAW_SET(int, in, a, i);
5845 break;
5846 }
5847 default:
5849 break;
5850 }
5851 }
5852 a++;
5853 }
5854 else if (needconv == 1) {
5855 /* allocate temporary array if needed */
5856 if (tmparray && tmplen != array_len) {
5857 MEM_delete_void(tmparray);
5858 tmparray = nullptr;
5859 }
5860 if (!tmparray) {
5861 tmparray = MEM_new_array_zeroed<float>(array_len, "RNA tmparray");
5862 tmplen = array_len;
5863 }
5864
5865 /* handle conversions */
5866 if (set) {
5867 switch (itemtype) {
5868 case PROP_BOOLEAN: {
5869 bool *array = static_cast<bool *>(tmparray);
5870 for (j = 0; j < array_len; j++, a++) {
5871 RAW_GET(bool, array[j], in, a);
5872 }
5873 RNA_property_boolean_set_array(&itemptr, iprop, array);
5874 break;
5875 }
5876 case PROP_INT: {
5877 int *array = static_cast<int *>(tmparray);
5878 for (j = 0; j < array_len; j++, a++) {
5879 RAW_GET(int, array[j], in, a);
5880 }
5881 RNA_property_int_set_array(&itemptr, iprop, array);
5882 break;
5883 }
5884 case PROP_FLOAT: {
5885 float *array = static_cast<float *>(tmparray);
5886 for (j = 0; j < array_len; j++, a++) {
5887 RAW_GET(float, array[j], in, a);
5888 }
5889 RNA_property_float_set_array(&itemptr, iprop, array);
5890 break;
5891 }
5892 default:
5894 break;
5895 }
5896 }
5897 else {
5898 switch (itemtype) {
5899 case PROP_BOOLEAN: {
5900 bool *array = static_cast<bool *>(tmparray);
5901 RNA_property_boolean_get_array(&itemptr, iprop, array);
5902 for (j = 0; j < array_len; j++, a++) {
5903 RAW_SET(int, in, a, ((bool *)tmparray)[j]);
5904 }
5905 break;
5906 }
5907 case PROP_INT: {
5908 int *array = static_cast<int *>(tmparray);
5909 RNA_property_int_get_array(&itemptr, iprop, array);
5910 for (j = 0; j < array_len; j++, a++) {
5911 RAW_SET(int, in, a, array[j]);
5912 }
5913 break;
5914 }
5915 case PROP_FLOAT: {
5916 float *array = static_cast<float *>(tmparray);
5917 RNA_property_float_get_array(&itemptr, iprop, array);
5918 for (j = 0; j < array_len; j++, a++) {
5919 RAW_SET(float, in, a, array[j]);
5920 }
5921 break;
5922 }
5923 default:
5925 break;
5926 }
5927 }
5928 }
5929 else {
5930 if (set) {
5931 switch (itemtype) {
5932 case PROP_BOOLEAN: {
5934 &itemptr, iprop, &(static_cast<bool *>(in.array))[a]);
5935 a += array_len;
5936 break;
5937 }
5938 case PROP_INT: {
5939 RNA_property_int_set_array(&itemptr, iprop, &(static_cast<int *>(in.array))[a]);
5940 a += array_len;
5941 break;
5942 }
5943 case PROP_FLOAT: {
5945 &itemptr, iprop, &(static_cast<float *>(in.array))[a]);
5946 a += array_len;
5947 break;
5948 }
5949 default:
5951 break;
5952 }
5953 }
5954 else {
5955 switch (itemtype) {
5956 case PROP_BOOLEAN: {
5958 &itemptr, iprop, &(static_cast<bool *>(in.array))[a]);
5959 a += array_len;
5960 break;
5961 }
5962 case PROP_INT: {
5963 RNA_property_int_get_array(&itemptr, iprop, &(static_cast<int *>(in.array))[a]);
5964 a += array_len;
5965 break;
5966 }
5967 case PROP_FLOAT: {
5969 &itemptr, iprop, &(static_cast<float *>(in.array))[a]);
5970 a += array_len;
5971 break;
5972 }
5973 default:
5975 break;
5976 }
5977 }
5978 }
5979 }
5980 }
5981 }
5983
5984 if (tmparray) {
5985 MEM_delete_void(tmparray);
5986 }
5987
5988 return !err;
5989 }
5990}
5991
5993{
5994 if (prop->rawtype == PROP_RAW_UNSET) {
5995 /* this property has no raw access,
5996 * yet we try to provide a raw type to help building the array. */
5997 switch (prop->type) {
5998 case PROP_BOOLEAN:
5999 return PROP_RAW_BOOLEAN;
6000 case PROP_INT:
6001 return PROP_RAW_INT;
6002 case PROP_FLOAT:
6003 return PROP_RAW_FLOAT;
6004 case PROP_ENUM:
6005 return PROP_RAW_INT;
6006 default:
6007 break;
6008 }
6009 }
6010 return prop->rawtype;
6011}
6012
6014 PointerRNA *ptr,
6015 PropertyRNA *prop,
6016 const char *propname,
6017 void *array,
6018 RawPropertyType type,
6019 int len)
6020{
6021 return rna_raw_access(reports, ptr, prop, propname, array, type, len, 0);
6022}
6023
6025 PointerRNA *ptr,
6026 PropertyRNA *prop,
6027 const char *propname,
6028 void *array,
6029 RawPropertyType type,
6030 int len)
6031{
6032 return rna_raw_access(reports, ptr, prop, propname, array, type, len, 1);
6033}
6034
6036{
6038 const int rna_array_size = RNA_property_array_length(&rna_ptr, &rna_prop);
6039 const auto fill_new = [&]() {
6041 if (rna_array_size > 1) {
6042 idprop.type = IDP_ARRAY;
6043 idprop.subtype = IDP_BOOLEAN;
6044 idprop.data.pointer = MEM_new_array_uninitialized<bool>(rna_array_size,
6045 "update_idprop_bool");
6046 idprop.len = rna_array_size;
6047 idprop.totallen = rna_array_size;
6049 &rna_ptr, &rna_prop, static_cast<bool *>(idprop.data.pointer));
6050 }
6051 else {
6052 idprop.type = IDP_BOOLEAN;
6054 }
6055 };
6056 /* If stored value was array and property is not (or vice versa), it can't be meaningfully
6057 * converted; use default. Happens when node group is switched and the same socket identifier
6058 * now maps to a very different socket. */
6059 if ((idprop.type == IDP_ARRAY) != (rna_array_size != 0)) {
6060 fill_new();
6061 return;
6062 }
6063 switch (eIDPropertyType(idprop.type)) {
6064 case IDP_STRING:
6065 case IDP_IDPARRAY:
6066 case IDP_ID:
6067 case IDP_GROUP: {
6068 fill_new();
6069 break;
6070 }
6071 case IDP_ARRAY: {
6072 const int idprop_array_size = idprop.len;
6073 switch (eIDPropertyType(idprop.subtype)) {
6074 case IDP_IDPARRAY:
6075 case IDP_ID:
6076 case IDP_STRING:
6077 case IDP_ARRAY:
6078 case IDP_GROUP: {
6080 fill_new();
6081 break;
6082 }
6083 case IDP_INT: {
6084 const int *old_values = IDP_array_int_get(&idprop);
6085 bool *new_values = MEM_new_array_zeroed<bool>(rna_array_size, __func__);
6086 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6087 new_values[i] = bool(old_values[i]);
6088 }
6090 idprop.subtype = IDP_BOOLEAN;
6091 idprop.len = rna_array_size;
6092 idprop.totallen = rna_array_size;
6093 idprop.data.pointer = new_values;
6094 break;
6095 }
6096 case IDP_FLOAT: {
6097 const float *old_values = IDP_array_float_get(&idprop);
6098 bool *new_values = MEM_new_array_zeroed<bool>(rna_array_size, __func__);
6099 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6100 new_values[i] = bool(old_values[i]);
6101 }
6103 idprop.subtype = IDP_BOOLEAN;
6104 idprop.len = rna_array_size;
6105 idprop.totallen = rna_array_size;
6106 idprop.data.pointer = new_values;
6107 break;
6108 }
6109 case IDP_DOUBLE: {
6110 const double *old_values = IDP_array_double_get(&idprop);
6111 bool *new_values = MEM_new_array_zeroed<bool>(rna_array_size, __func__);
6112 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6113 new_values[i] = bool(old_values[i]);
6114 }
6116 idprop.subtype = IDP_BOOLEAN;
6117 idprop.len = rna_array_size;
6118 idprop.totallen = rna_array_size;
6119 idprop.data.pointer = new_values;
6120 break;
6121 }
6122 case IDP_BOOLEAN: {
6123 if (idprop_array_size != rna_array_size) {
6124 if (rna_array_size == 0) {
6125 fill_new();
6126 }
6127 else {
6128 const int8_t *old_values = IDP_array_bool_get(&idprop);
6129 auto *new_values = MEM_new_array_zeroed<int8_t>(rna_array_size, __func__);
6130 std::copy_n(old_values, std::min(rna_array_size, idprop_array_size), new_values);
6132 idprop.subtype = IDP_BOOLEAN;
6133 idprop.len = rna_array_size;
6134 idprop.totallen = rna_array_size;
6135 idprop.data.pointer = new_values;
6136 }
6137 }
6138 break;
6139 }
6140 }
6141 break;
6142 }
6143 case IDP_INT: {
6144 const int value = IDP_int_get(&idprop);
6146 idprop.type = IDP_BOOLEAN;
6147 IDP_bool_set(&idprop, bool(value));
6148 break;
6149 }
6150 case IDP_FLOAT: {
6151 const float value = IDP_float_get(&idprop);
6153 idprop.type = IDP_BOOLEAN;
6154 IDP_bool_set(&idprop, bool(value));
6155 break;
6156 }
6157 case IDP_DOUBLE: {
6158 const double value = IDP_double_get(&idprop);
6160 idprop.type = IDP_BOOLEAN;
6161 IDP_bool_set(&idprop, bool(value));
6162 break;
6163 }
6164 case IDP_BOOLEAN: {
6165 if (rna_array_size != 0) {
6166 fill_new();
6167 }
6168 break;
6169 }
6170 }
6171}
6172
6174{
6175 BLI_assert(RNA_property_type(&rna_prop) == PROP_INT);
6176 const int rna_array_size = RNA_property_array_length(&rna_ptr, &rna_prop);
6177 const auto fill_new = [&]() {
6179 if (rna_array_size > 1) {
6180 idprop.type = IDP_ARRAY;
6181 idprop.subtype = PROP_INT;
6182 idprop.data.pointer = MEM_new_array_uninitialized<int>(rna_array_size, "update_idprop_int");
6183 idprop.len = rna_array_size;
6184 idprop.totallen = rna_array_size;
6186 &rna_ptr, &rna_prop, static_cast<int *>(idprop.data.pointer));
6187 }
6188 else {
6189 idprop.type = IDP_INT;
6190 IDP_int_set(&idprop, RNA_property_int_get_default(&rna_ptr, &rna_prop));
6191 }
6192 };
6193 /* If stored value was array and property is not (or vice versa), it can't be meaningfully
6194 * converted; use default. Happens when node group is switched and the same socket identifier
6195 * now maps to a very different socket. */
6196 if ((idprop.type == IDP_ARRAY) != (rna_array_size != 0)) {
6197 fill_new();
6198 return;
6199 }
6200 switch (eIDPropertyType(idprop.type)) {
6201 case IDP_STRING:
6202 case IDP_IDPARRAY:
6203 case IDP_ID:
6204 case IDP_GROUP: {
6205 fill_new();
6206 break;
6207 }
6208 case IDP_ARRAY: {
6209 const int idprop_array_size = idprop.len;
6210 switch (eIDPropertyType(idprop.subtype)) {
6211 case IDP_IDPARRAY:
6212 case IDP_ID:
6213 case IDP_STRING:
6214 case IDP_ARRAY:
6215 case IDP_GROUP: {
6217 fill_new();
6218 break;
6219 }
6220 case IDP_INT: {
6221 if (idprop_array_size != rna_array_size) {
6222 if (rna_array_size == 0) {
6223 fill_new();
6224 }
6225 else {
6226 const int *old_values = IDP_array_int_get(&idprop);
6227 auto *new_values = MEM_new_array_zeroed<int>(rna_array_size, __func__);
6228 std::copy_n(old_values, std::min(rna_array_size, idprop_array_size), new_values);
6230 idprop.subtype = PROP_INT;
6231 idprop.len = rna_array_size;
6232 idprop.totallen = rna_array_size;
6233 idprop.data.pointer = new_values;
6234 }
6235 }
6236 break;
6237 }
6238 case IDP_FLOAT: {
6239 const float *old_values = IDP_array_float_get(&idprop);
6240 auto *new_values = MEM_new_array_zeroed<int>(rna_array_size, __func__);
6241 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6242 new_values[i] = int(old_values[i]);
6243 }
6245 idprop.subtype = PROP_INT;
6246 idprop.len = rna_array_size;
6247 idprop.totallen = rna_array_size;
6248 idprop.data.pointer = new_values;
6249 break;
6250 }
6251 case IDP_DOUBLE: {
6252 const double *old_values = IDP_array_double_get(&idprop);
6253 auto *new_values = MEM_new_array_zeroed<int>(rna_array_size, __func__);
6254 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6255 new_values[i] = int(old_values[i]);
6256 }
6258 idprop.subtype = PROP_INT;
6259 idprop.len = rna_array_size;
6260 idprop.totallen = rna_array_size;
6261 idprop.data.pointer = new_values;
6262 break;
6263 }
6264 case IDP_BOOLEAN: {
6265 const int8_t *old_values = IDP_array_bool_get(&idprop);
6266 auto *new_values = MEM_new_array_zeroed<int>(rna_array_size, __func__);
6267 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6268 new_values[i] = int(old_values[i]);
6269 }
6271 idprop.subtype = PROP_INT;
6272 idprop.len = rna_array_size;
6273 idprop.totallen = rna_array_size;
6274 idprop.data.pointer = new_values;
6275 break;
6276 }
6277 }
6278 break;
6279 }
6280 case IDP_INT: {
6281 if (rna_array_size != 0) {
6282 fill_new();
6283 }
6284 break;
6285 }
6286 case IDP_FLOAT: {
6287 const float value = IDP_float_get(&idprop);
6289 idprop.type = IDP_INT;
6290 IDP_int_set(&idprop, int(value));
6291 break;
6292 }
6293 case IDP_DOUBLE: {
6294 const double value = IDP_double_get(&idprop);
6296 idprop.type = IDP_INT;
6297 IDP_int_set(&idprop, int(value));
6298 break;
6299 }
6300 case IDP_BOOLEAN: {
6301 const bool value = IDP_bool_get(&idprop);
6303 idprop.type = IDP_INT;
6304 IDP_int_set(&idprop, int(value));
6305 break;
6306 }
6307 }
6308}
6309
6311{
6313 const int rna_array_size = RNA_property_array_length(&rna_ptr, &rna_prop);
6314 const auto fill_new = [&]() {
6316 if (rna_array_size > 1) {
6317 idprop.type = IDP_ARRAY;
6318 idprop.subtype = IDP_FLOAT;
6319 idprop.data.pointer = MEM_new_array_uninitialized<float>(rna_array_size,
6320 "update_idprop_float");
6321 idprop.len = rna_array_size;
6322 idprop.totallen = rna_array_size;
6324 &rna_ptr, &rna_prop, static_cast<float *>(idprop.data.pointer));
6325 }
6326 else {
6327 idprop.type = IDP_FLOAT;
6328 IDP_float_set(&idprop, RNA_property_float_get_default(&rna_ptr, &rna_prop));
6329 }
6330 };
6331 /* If stored value was array and property is not (or vice versa), it can't be meaningfully
6332 * converted; use default. Happens when node group is switched and the same socket identifier
6333 * now maps to a very different socket. */
6334 if ((idprop.type == IDP_ARRAY) != (rna_array_size != 0)) {
6335 fill_new();
6336 return;
6337 }
6338 switch (eIDPropertyType(idprop.type)) {
6339 case IDP_STRING:
6340 case IDP_IDPARRAY:
6341 case IDP_ID:
6342 case IDP_GROUP: {
6343 fill_new();
6344 break;
6345 }
6346 case IDP_ARRAY: {
6347 const int idprop_array_size = idprop.len;
6348 switch (eIDPropertyType(idprop.subtype)) {
6349 case IDP_IDPARRAY:
6350 case IDP_ID:
6351 case IDP_STRING:
6352 case IDP_ARRAY:
6353 case IDP_GROUP: {
6355 fill_new();
6356 break;
6357 }
6358 case IDP_INT: {
6359 const int *old_values = IDP_array_int_get(&idprop);
6360 auto *new_values = MEM_new_array_zeroed<float>(rna_array_size, __func__);
6361 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6362 new_values[i] = float(old_values[i]);
6363 }
6365 idprop.subtype = IDP_FLOAT;
6366 idprop.len = rna_array_size;
6367 idprop.totallen = rna_array_size;
6368 idprop.data.pointer = new_values;
6369 break;
6370 }
6371 case IDP_FLOAT: {
6372 if (idprop_array_size != rna_array_size) {
6373 if (rna_array_size == 0) {
6374 fill_new();
6375 }
6376 else {
6377 const float *old_values = IDP_array_float_get(&idprop);
6378 auto *new_values = MEM_new_array_zeroed<float>(rna_array_size, __func__);
6379 std::copy_n(old_values, std::min(rna_array_size, idprop_array_size), new_values);
6381 idprop.subtype = IDP_FLOAT;
6382 idprop.len = rna_array_size;
6383 idprop.totallen = rna_array_size;
6384 idprop.data.pointer = new_values;
6385 }
6386 }
6387 break;
6388 }
6389 case IDP_DOUBLE: {
6390 if (idprop_array_size != rna_array_size) {
6391 if (rna_array_size == 0) {
6392 fill_new();
6393 }
6394 else {
6395 const double *old_values = IDP_array_double_get(&idprop);
6396 auto *new_values = MEM_new_array_zeroed<double>(rna_array_size, __func__);
6397 std::copy_n(old_values, std::min(rna_array_size, idprop_array_size), new_values);
6399 idprop.subtype = IDP_DOUBLE;
6400 idprop.len = rna_array_size;
6401 idprop.totallen = rna_array_size;
6402 idprop.data.pointer = new_values;
6403 }
6404 }
6405 break;
6406 }
6407 case IDP_BOOLEAN: {
6408 const int8_t *old_values = IDP_array_bool_get(&idprop);
6409 auto *new_values = MEM_new_array_zeroed<float>(rna_array_size, __func__);
6410 for (const int i : IndexRange(std::min(rna_array_size, idprop_array_size))) {
6411 new_values[i] = float(old_values[i]);
6412 }
6414 idprop.subtype = IDP_FLOAT;
6415 idprop.len = rna_array_size;
6416 idprop.totallen = rna_array_size;
6417 idprop.data.pointer = new_values;
6418 break;
6419 }
6420 }
6421 break;
6422 }
6423 case IDP_INT: {
6424 const int value = IDP_int_get(&idprop);
6426 idprop.type = IDP_FLOAT;
6427 IDP_float_set(&idprop, float(value));
6428 break;
6429 }
6430 case IDP_FLOAT: {
6431 if (rna_array_size != 0) {
6432 fill_new();
6433 }
6434 break;
6435 }
6436 case IDP_DOUBLE: {
6437 if (rna_array_size != 0) {
6438 fill_new();
6439 }
6440 break;
6441 }
6442 case IDP_BOOLEAN: {
6443 const bool value = IDP_bool_get(&idprop);
6445 idprop.type = IDP_FLOAT;
6446 IDP_float_set(&idprop, float(value));
6447 break;
6448 }
6449 }
6450}
6451
6452static void update_idprop_id(Main &bmain,
6453 PointerRNA &rna_ptr,
6454 PropertyRNA &rna_prop,
6456{
6457 const auto fill_new = [&]() {
6459 idprop.type = IDP_ID;
6460 PointerRNA default_ptr = RNA_property_pointer_get_default(bmain, rna_ptr, rna_prop);
6461 IDP_AssignID(&idprop, default_ptr.data_as<ID>(), 0);
6462 };
6463 if (idprop.type == IDP_ID) {
6464 return;
6465 }
6466 fill_new();
6467}
6468
6469static void sync_system_properties(Main &bmain,
6470 PointerRNA &ptr,
6471 IDProperty &idprops,
6472 const bool ensure)
6473{
6474 BLI_assert(idprops.type == IDP_GROUP);
6475 Set<IDProperty *> used_props;
6476 StructRNA &srna = *ptr.type;
6477 for (PropertyRNA &rna_prop : *RNA_struct_type_properties(&srna)) {
6478 if (RNA_property_builtin(&rna_prop)) {
6479 continue;
6480 }
6481 if (rna_prop.identifier == "rna_type"_ustr) {
6482 /* Avoid infinite loop trying to create property group for this property that's defined
6483 * automatically for every type, including the base type "RNA_Struct". */
6484 continue;
6485 }
6486
6487 const StringRefNull identifier = RNA_property_identifier(&rna_prop);
6488 IDProperty *idprop = IDP_GetPropertyFromGroup(&idprops, identifier);
6489 if (!idprop) {
6490 if (ensure) {
6491 /* Create an invalid property, to be filled correctly later by the code for each type. */
6492 idprop = bke::idprop::create_group(identifier).release();
6493 IDP_AddToGroup(&idprops, idprop);
6494 }
6495 else {
6496 continue;
6497 }
6498 }
6499
6500 used_props.add_new(idprop);
6501
6502 switch (RNA_property_type(&rna_prop)) {
6503 case PROP_BOOLEAN: {
6504 update_idprop_bool(ptr, rna_prop, *idprop);
6505 break;
6506 }
6507 case PROP_INT: {
6508 update_idprop_int(ptr, rna_prop, *idprop);
6509 break;
6510 }
6511 case PROP_FLOAT: {
6512 update_idprop_float(ptr, rna_prop, *idprop);
6513 break;
6514 }
6515 case PROP_STRING: {
6516 if (idprop->type != IDP_STRING) {
6518 idprop->type = IDP_STRING;
6519 idprop->subtype = IDP_STRING_SUB_UTF8;
6520 int len;
6521 char *string = RNA_property_string_get_default_alloc(&ptr, &rna_prop, nullptr, 0, &len);
6522 idprop->data.pointer = string;
6523 idprop->len = len + 1;
6524 idprop->totallen = len;
6525 }
6526 break;
6527 }
6528 case PROP_ENUM: {
6529 if (idprop->type != IDP_INT) {
6531 idprop->type = IDP_INT;
6532 idprop->data.val = RNA_property_enum_get_default(&ptr, &rna_prop);
6533 }
6534 break;
6535 }
6536 case PROP_POINTER: {
6537 StructRNA *prop_srna = RNA_property_pointer_type(&ptr, &rna_prop);
6538 if (RNA_struct_is_ID(prop_srna)) {
6539 update_idprop_id(bmain, ptr, rna_prop, *idprop);
6540 }
6541 else {
6542 if (idprop->type != IDP_GROUP) {
6544 idprop->type = IDP_GROUP;
6545 continue;
6546 }
6547 PointerRNA prop_ptr = RNA_property_pointer_get(&ptr, &rna_prop);
6548 sync_system_properties(bmain, prop_ptr, *idprop, ensure);
6549 }
6550 break;
6551 }
6552 case PROP_COLLECTION: {
6553 /* Not yet supported. */
6555 break;
6556 }
6557 }
6558 }
6559
6560 /* Remove old properties no longer used by the RNA type. */
6561 for (IDProperty &prop : idprops.data.group.items_mutable()) {
6562 if (!used_props.contains(&prop)) {
6563 IDP_FreeFromGroup(&idprops, &prop);
6564 }
6565 }
6566}
6567
6569{
6570 sync_system_properties(bmain, ptr, idprops, false);
6571}
6572
6574{
6575 sync_system_properties(bmain, ptr, idprops, true);
6576}
6577
6578/* Standard iterator functions */
6579
6581 PointerRNA *ptr,
6582 ListBase *lb,
6583 IteratorSkipFunc skip)
6584{
6585 iter->parent = *ptr;
6586
6587 ListBaseIterator *internal = &iter->internal.listbase;
6588
6589 internal->link = (lb) ? static_cast<Link *>(lb->first_) : nullptr;
6590 internal->skip = skip;
6591
6592 iter->valid = (internal->link != nullptr);
6593
6594 if (skip && iter->valid && skip(iter, internal->link)) {
6596 }
6597}
6598
6600{
6601 ListBaseIterator *internal = &iter->internal.listbase;
6602
6603 if (internal->skip) {
6604 do {
6605 internal->link = internal->link->next;
6606 iter->valid = (internal->link != nullptr);
6607 } while (iter->valid && internal->skip(iter, internal->link));
6608 }
6609 else {
6610 internal->link = internal->link->next;
6611 iter->valid = (internal->link != nullptr);
6612 }
6613}
6614
6616{
6617 ListBaseIterator *internal = &iter->internal.listbase;
6618
6619 return internal->link;
6620}
6621
6623
6625{
6626 void *data = BLI_findlink(lb, index);
6627 return RNA_pointer_create_with_parent(*ptr, type, data);
6628}
6629
6631 PointerRNA *ptr,
6632 void *data,
6633 size_t itemsize,
6635 bool free_ptr,
6636 IteratorSkipFunc skip)
6637{
6638 iter->parent = *ptr;
6639
6641 /* Ensure clearing `data` doesn't prevent it from being freed. */
6642 void *data_free = data;
6643
6644 if (data == nullptr) {
6645 length = 0;
6646 }
6647 else if (length == 0) {
6648 data = nullptr;
6649 itemsize = 0;
6650 }
6651 else if (length < 0 || length > std::numeric_limits<uint64_t>::max() / itemsize) [[unlikely]] {
6652 /* This path is never expected to execute. Assert and trace if it ever does. */
6654 data = nullptr;
6655 length = 0;
6656 }
6657
6658 internal = &iter->internal.array;
6659 internal->ptr = static_cast<char *>(data);
6660 internal->free_ptr = free_ptr ? data_free : nullptr;
6661 internal->endptr = (static_cast<char *>(data)) + itemsize * length;
6662 internal->itemsize = itemsize;
6663 internal->skip = skip;
6664 internal->length = length;
6665
6666 iter->valid = (internal->ptr != internal->endptr);
6667
6668 if (skip && iter->valid && skip(iter, internal->ptr)) {
6670 }
6671}
6672
6674{
6675 ArrayIterator *internal = &iter->internal.array;
6676
6677 if (internal->skip) {
6678 do {
6679 internal->ptr += internal->itemsize;
6680 iter->valid = (internal->ptr != internal->endptr);
6681 } while (iter->valid && internal->skip(iter, internal->ptr));
6682 }
6683 else {
6684 internal->ptr += internal->itemsize;
6685 iter->valid = (internal->ptr != internal->endptr);
6686 }
6687}
6688
6690{
6691 ArrayIterator *internal = &iter->internal.array;
6692
6693 return internal->ptr;
6694}
6695
6697{
6698 ArrayIterator *internal = &iter->internal.array;
6699
6700 /* for ** arrays */
6701 return *reinterpret_cast<void **>(internal->ptr);
6702}
6703
6705{
6706 ArrayIterator *internal = &iter->internal.array;
6707
6708 MEM_SAFE_DELETE_VOID(internal->free_ptr);
6709}
6710
6712 PointerRNA *ptr, StructRNA *type, void *data, size_t itemsize, int64_t length, int64_t index)
6713{
6714 if (index < 0 || index >= length) {
6715 return {};
6716 }
6717 if (index > std::numeric_limits<uint64_t>::max() / itemsize) [[unlikely]] {
6718 /* This path is never expected to execute. Assert and trace if it ever does. */
6720 return {};
6721 }
6722
6724 *ptr, type, (static_cast<char *>(data)) + itemsize * index);
6725}
6726
6727/* Quick name based property access */
6728
6729bool RNA_boolean_get(PointerRNA *ptr, const char *name)
6730{
6731 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6732
6733 if (prop) {
6734 return RNA_property_boolean_get(ptr, prop);
6735 }
6736 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6737 return false;
6738}
6739
6740void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
6741{
6742 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6743
6744 if (prop) {
6745 RNA_property_boolean_set(ptr, prop, value);
6746 }
6747 else {
6748 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6749 }
6750}
6751
6752void RNA_boolean_get_array(PointerRNA *ptr, const char *name, bool *values)
6753{
6754 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6755
6756 if (prop) {
6757 RNA_property_boolean_get_array(ptr, prop, values);
6758 }
6759 else {
6760 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6761 }
6762}
6763
6764void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const bool *values)
6765{
6766 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6767
6768 if (prop) {
6769 RNA_property_boolean_set_array(ptr, prop, values);
6770 }
6771 else {
6772 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6773 }
6774}
6775
6776int RNA_int_get(PointerRNA *ptr, const char *name)
6777{
6778 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6779
6780 if (prop) {
6781 return RNA_property_int_get(ptr, prop);
6782 }
6783 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6784 return 0;
6785}
6786
6787void RNA_int_set(PointerRNA *ptr, const char *name, int value)
6788{
6789 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6790
6791 if (prop) {
6792 RNA_property_int_set(ptr, prop, value);
6793 }
6794 else {
6795 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6796 }
6797}
6798
6799void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
6800{
6801 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6802
6803 if (prop) {
6804 RNA_property_int_get_array(ptr, prop, values);
6805 }
6806 else {
6807 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6808 }
6809}
6810
6811void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
6812{
6813 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6814
6815 if (prop) {
6816 RNA_property_int_set_array(ptr, prop, values);
6817 }
6818 else {
6819 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6820 }
6821}
6822
6823float RNA_float_get(PointerRNA *ptr, const char *name)
6824{
6825 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6826
6827 if (prop) {
6828 return RNA_property_float_get(ptr, prop);
6829 }
6830 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6831 return 0;
6832}
6833
6834void RNA_float_set(PointerRNA *ptr, const char *name, float value)
6835{
6836 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6837
6838 if (prop) {
6839 RNA_property_float_set(ptr, prop, value);
6840 }
6841 else {
6842 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6843 }
6844}
6845
6846void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
6847{
6848 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6849
6850 if (prop) {
6851 RNA_property_float_get_array(ptr, prop, values);
6852 }
6853 else {
6854 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6855 }
6856}
6857
6858void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
6859{
6860 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6861
6862 if (prop) {
6863 RNA_property_float_set_array(ptr, prop, values);
6864 }
6865 else {
6866 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6867 }
6868}
6869
6870int RNA_enum_get(PointerRNA *ptr, const char *name)
6871{
6872 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6873
6874 if (prop) {
6875 return RNA_property_enum_get(ptr, prop);
6876 }
6877 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6878 return 0;
6879}
6880
6881void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
6882{
6883 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6884
6885 if (prop) {
6886 RNA_property_enum_set(ptr, prop, value);
6887 }
6888 else {
6889 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6890 }
6891}
6892
6893void RNA_enum_set_identifier(bContext *C, PointerRNA *ptr, const char *name, const char *id)
6894{
6895 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6896
6897 if (prop) {
6898 int value;
6899 if (RNA_property_enum_value(C, ptr, prop, id, &value)) {
6900 RNA_property_enum_set(ptr, prop, value);
6901 }
6902 else {
6903 printf(
6904 "%s: %s.%s has no enum id '%s'.\n", __func__, ptr->type->identifier.c_str(), name, id);
6905 }
6906 }
6907 else {
6908 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6909 }
6910}
6911
6912bool RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
6913{
6914 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6915 const EnumPropertyItem *item;
6916 bool free;
6917
6918 if (prop) {
6919 int i;
6920 bool cmp = false;
6921
6922 RNA_property_enum_items(C, ptr, prop, &item, nullptr, &free);
6923 i = RNA_enum_from_identifier(item, enumname);
6924 if (i != -1) {
6925 cmp = (item[i].value == RNA_property_enum_get(ptr, prop));
6926 }
6927
6928 if (free) {
6929 MEM_delete(item);
6930 }
6931
6932 if (i != -1) {
6933 return cmp;
6934 }
6935
6936 printf(
6937 "%s: %s.%s item %s not found.\n", __func__, ptr->type->identifier.c_str(), name, enumname);
6938 return false;
6939 }
6940 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6941 return false;
6942}
6943
6944bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
6945{
6946 const int i = RNA_enum_from_identifier(item, identifier);
6947 if (i != -1) {
6948 *r_value = item[i].value;
6949 return true;
6950 }
6951 return false;
6952}
6953
6954bool RNA_enum_id_from_value(const EnumPropertyItem *item, int value, const char **r_identifier)
6955{
6956 const int i = RNA_enum_from_value(item, value);
6957 if (i != -1) {
6958 *r_identifier = item[i].identifier;
6959 return true;
6960 }
6961 return false;
6962}
6963
6964bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_icon)
6965{
6966 const int i = RNA_enum_from_value(item, value);
6967 if (i != -1) {
6968 *r_icon = item[i].icon;
6969 return true;
6970 }
6971 return false;
6972}
6973
6974bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
6975{
6976 const int i = RNA_enum_from_value(item, value);
6977 if (i != -1) {
6978 *r_name = item[i].name;
6979 return true;
6980 }
6981 return false;
6982}
6983
6984std::string RNA_string_get(PointerRNA *ptr, const char *name)
6985{
6986 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6987 if (!prop) {
6988 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
6989 return {};
6990 }
6991 return RNA_property_string_get(ptr, prop);
6992}
6993
6994void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
6995{
6996 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
6997
6998 if (prop) {
6999 RNA_property_string_get(ptr, prop, value);
7000 }
7001 else {
7002 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7003 value[0] = '\0';
7004 }
7005}
7006
7008 PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
7009{
7010 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7011
7012 if (prop) {
7013 return RNA_property_string_get_alloc(ptr, prop, fixedbuf, fixedlen, r_len);
7014 }
7015 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7016 if (r_len != nullptr) {
7017 *r_len = 0;
7018 }
7019 return nullptr;
7020}
7021
7022int RNA_string_length(PointerRNA *ptr, const char *name)
7023{
7024 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7025
7026 if (prop) {
7027 return RNA_property_string_length(ptr, prop);
7028 }
7029 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7030 return 0;
7031}
7032
7033void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
7034{
7035 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7036
7037 if (prop) {
7038 RNA_property_string_set(ptr, prop, value);
7039 }
7040 else {
7041 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7042 }
7043}
7044
7046{
7047 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7048
7049 if (prop) {
7050 return RNA_property_pointer_get(ptr, prop);
7051 }
7052 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7053
7054 return {};
7055}
7056
7057void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
7058{
7059 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7060
7061 if (prop) {
7062 RNA_property_pointer_set(ptr, prop, ptr_value, nullptr);
7063 }
7064 else {
7065 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7066 }
7067}
7068
7069void RNA_pointer_add(PointerRNA *ptr, const char *name)
7070{
7071 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7072
7073 if (prop) {
7074 RNA_property_pointer_add(ptr, prop);
7075 }
7076 else {
7077 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7078 }
7079}
7080
7082{
7083 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7084
7085 if (prop) {
7086 RNA_property_collection_begin(ptr, prop, iter);
7087 }
7088 else {
7089 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7090 }
7091}
7092
7093void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
7094{
7095 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7096
7097 if (prop) {
7098 RNA_property_collection_add(ptr, prop, r_value);
7099 }
7100 else {
7101 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7102 }
7103}
7104
7105void RNA_collection_clear(PointerRNA *ptr, const char *name)
7106{
7107 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7108
7109 if (prop) {
7111 }
7112 else {
7113 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7114 }
7115}
7116
7117int RNA_collection_length(PointerRNA *ptr, const char *name)
7118{
7119 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7120
7121 if (prop) {
7122 return RNA_property_collection_length(ptr, prop);
7123 }
7124 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7125 return 0;
7126}
7127
7128bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
7129{
7130 PropertyRNA *prop = RNA_struct_find_property(ptr, name);
7131
7132 if (prop) {
7133 return RNA_property_collection_is_empty(ptr, prop);
7134 }
7135 printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier.c_str(), name);
7136 return false;
7137}
7138
7139bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
7140{
7141 prop = rna_ensure_property(prop);
7142 if (prop->flag & PROP_IDPROPERTY) {
7144 return ((idprop != nullptr) && (use_ghost == false || !(idprop->flag & IDP_FLAG_GHOST)));
7145 }
7146 return true;
7147}
7148
7150{
7151 prop = rna_ensure_property(prop);
7152 if (prop->flag & PROP_IDPROPERTY) {
7154 return ((idprop != nullptr) && !(idprop->flag & IDP_FLAG_GHOST));
7155 }
7156 return true;
7157}
7158
7160{
7161 prop = rna_ensure_property(prop);
7162 if (prop->flag & PROP_IDPROPERTY) {
7164 }
7165}
7166
7167bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
7168{
7169 PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
7170
7171 if (prop) {
7172 return RNA_property_is_set_ex(ptr, prop, use_ghost);
7173 }
7174 /* python raises an error */
7175 // printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
7176 return false;
7177}
7178
7179bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
7180{
7181 PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
7182
7183 if (prop) {
7184 return RNA_property_is_set(ptr, prop);
7185 }
7186 /* python raises an error */
7187 // printf("%s: %s.%s not found.\n", __func__, ptr->type->identifier, name);
7188 return false;
7189}
7190
7191void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
7192{
7193 PropertyRNA *prop = RNA_struct_find_property(ptr, identifier);
7194
7195 if (prop) {
7196 RNA_property_unset(ptr, prop);
7197 }
7198}
7199
7201{
7202 return (prop->magic != RNA_MAGIC);
7203}
7204
7206{
7207 const int flag = RNA_property_flag(prop);
7208 if (RNA_property_type(prop) == PROP_STRING) {
7209 return (flag & PROP_NEVER_UNLINK) == 0;
7210 }
7211 return (flag & (PROP_NEVER_UNLINK | PROP_NEVER_NULL)) == 0;
7212}
7213
7215{
7216 std::stringstream ss;
7217
7218 const char *propname;
7219 int first_time = 1;
7220
7221 ss << '{';
7222
7223 RNA_STRUCT_BEGIN (ptr, prop) {
7224 propname = RNA_property_identifier(prop);
7225
7226 if (STREQ(propname, "rna_type")) {
7227 continue;
7228 }
7229
7230 if (first_time == 0) {
7231 ss << ", ";
7232 }
7233 first_time = 0;
7234
7235 const std::string str = RNA_property_as_string(C, ptr, prop, -1, INT_MAX);
7236 ss << fmt::format("\"{}\":{}", propname, str);
7237 }
7239
7240 ss << '}';
7241
7242 return ss.str();
7243}
7244
7245static std::optional<std::string> rna_pointer_as_string__bldata(PointerRNA *ptr)
7246{
7247 if (!ptr->has_type() || !ptr->has_owner_id()) {
7248 return "None";
7249 }
7250 if (RNA_struct_is_ID(ptr->type)) {
7251 return RNA_path_full_ID_py(ptr->owner_id);
7252 }
7253 return RNA_path_full_struct_py(ptr);
7254}
7255
7256std::optional<std::string> RNA_pointer_as_string(bContext *C,
7257 PointerRNA *ptr,
7258 PropertyRNA *prop_ptr,
7259 PointerRNA *ptr_prop)
7260{
7261 IDProperty *prop;
7262 if (!*ptr_prop) {
7263 return "None";
7264 }
7265 if ((prop = rna_idproperty_check(&prop_ptr, ptr)) && prop->type != IDP_ID) {
7266 return RNA_pointer_as_string_id(C, ptr_prop);
7267 }
7268 return rna_pointer_as_string__bldata(ptr_prop);
7269}
7270
7272 PointerRNA *ptr,
7273 const bool as_function,
7274 const bool all_args,
7275 const bool nested_args,
7276 const int max_prop_length,
7277 PropertyRNA *iterprop)
7278{
7279 const char *arg_name = nullptr;
7280
7281 PropertyRNA *prop;
7282
7283 std::stringstream ss;
7284
7285 bool first_iter = true;
7286 int flag, flag_parameter;
7287
7288 RNA_PROP_BEGIN (ptr, propptr, iterprop) {
7289 prop = static_cast<PropertyRNA *>(propptr.data);
7290
7291 flag = RNA_property_flag(prop);
7292 flag_parameter = RNA_parameter_flag(prop);
7293
7294 if (as_function && (flag_parameter & PARM_OUTPUT)) {
7295 continue;
7296 }
7297
7298 arg_name = RNA_property_identifier(prop);
7299
7300 if (STREQ(arg_name, "rna_type")) {
7301 continue;
7302 }
7303
7304 if ((nested_args == false) && (RNA_property_type(prop) == PROP_POINTER)) {
7305 continue;
7306 }
7307
7308 if (as_function && (prop->flag_parameter & PARM_REQUIRED)) {
7309 /* required args don't have useful defaults */
7310 ss << fmt::format(fmt::runtime(first_iter ? "{}" : ", {}"), arg_name);
7311 first_iter = false;
7312 }
7313 else {
7314 bool ok = true;
7315
7316 if (all_args == true) {
7317 /* pass */
7318 }
7319 else if (RNA_struct_system_idprops_check(ptr->type)) {
7320 ok = RNA_property_is_set(ptr, prop);
7321 }
7322
7323 if (ok) {
7324 std::string buf;
7325 if (as_function && RNA_property_type(prop) == PROP_POINTER) {
7326 /* don't expand pointers for functions */
7327 if (flag & PROP_NEVER_NULL) {
7328 /* we can't really do the right thing here. arg=arg?, hrmf! */
7329 buf = arg_name;
7330 }
7331 else {
7332 buf = "None";
7333 }
7334 }
7335 else {
7336 buf = RNA_property_as_string(C, ptr, prop, -1, max_prop_length);
7337 }
7338
7339 ss << fmt::format(fmt::runtime(first_iter ? "{}={}" : ", {}={}"), arg_name, buf);
7340 first_iter = false;
7341 }
7342 }
7343 }
7345
7346 return ss.str();
7347}
7348
7350 PointerRNA *ptr,
7351 const bool as_function,
7352 const bool all_args,
7353 const bool nested_args,
7354 const int max_prop_length)
7355{
7356 PropertyRNA *iterprop;
7357
7358 iterprop = RNA_struct_iterator_property(ptr->type);
7359
7361 C, ptr, as_function, all_args, nested_args, max_prop_length, iterprop);
7362}
7363
7365 FunctionRNA *func,
7366 const bool as_function,
7367 const bool all_args,
7368 const int max_prop_length)
7369{
7370 PointerRNA funcptr = RNA_pointer_create_discrete(nullptr, RNA_Function, func);
7371
7372 PropertyRNA *iterprop = RNA_struct_find_property(&funcptr, "parameters");
7373
7375
7377 C, &funcptr, as_function, all_args, true, max_prop_length, iterprop);
7378}
7379
7380static const char *bool_as_py_string(const int var)
7381{
7382 return var ? "True" : "False";
7383}
7384
7386 int type, int len, PointerRNA *ptr, PropertyRNA *prop, void **r_buf_end)
7387{
7388 switch (type) {
7389 case PROP_BOOLEAN: {
7390 bool *buf = MEM_new_array_uninitialized<bool>(size_t(len), __func__);
7391 RNA_property_boolean_get_array(ptr, prop, buf);
7392 *r_buf_end = buf + len;
7393 return buf;
7394 }
7395 case PROP_INT: {
7396 int *buf = MEM_new_array_uninitialized<int>(size_t(len), __func__);
7397 RNA_property_int_get_array(ptr, prop, buf);
7398 *r_buf_end = buf + len;
7399 return buf;
7400 }
7401 case PROP_FLOAT: {
7402 float *buf = MEM_new_array_uninitialized<float>(size_t(len), __func__);
7403 RNA_property_float_get_array(ptr, prop, buf);
7404 *r_buf_end = buf + len;
7405 return buf;
7406 }
7407 default:
7409 return nullptr;
7410 }
7411}
7412
7413static void rna_array_as_string_elem(int type, void **buf_p, int len, std::stringstream &ss)
7414{
7415 /* This will print a comma separated string of the array elements from
7416 * buf start to len. We will add a comma if len == 1 to preserve tuples. */
7417 const int end = len - 1;
7418 switch (type) {
7419 case PROP_BOOLEAN: {
7420 bool *buf = static_cast<bool *>(*buf_p);
7421 for (int i = 0; i < len; i++, buf++) {
7422 ss << fmt::format(fmt::runtime((i < end || !end) ? "{}, " : "{}"),
7423 bool_as_py_string(*buf));
7424 }
7425 *buf_p = buf;
7426 break;
7427 }
7428 case PROP_INT: {
7429 int *buf = static_cast<int *>(*buf_p);
7430 for (int i = 0; i < len; i++, buf++) {
7431 ss << fmt::format(fmt::runtime((i < end || !end) ? "{}, " : "{}"), *buf);
7432 }
7433 *buf_p = buf;
7434 break;
7435 }
7436 case PROP_FLOAT: {
7437 float *buf = static_cast<float *>(*buf_p);
7438 for (int i = 0; i < len; i++, buf++) {
7439 ss << fmt::format(fmt::runtime((i < end || !end) ? "{:g}, " : "{:g}"), *buf);
7440 }
7441 *buf_p = buf;
7442 break;
7443 }
7444 default:
7446 }
7447}
7448
7450 int type, void **buf_p, int totdim, const int *dim_size, std::stringstream &ss)
7451{
7452 ss << '(';
7453 if (totdim > 1) {
7454 totdim--;
7455 const int end = dim_size[totdim] - 1;
7456 for (int i = 0; i <= end; i++) {
7457 rna_array_as_string_recursive(type, buf_p, totdim, dim_size, ss);
7458 if (i < end || !end) {
7459 ss << ", ";
7460 }
7461 }
7462 }
7463 else {
7464 rna_array_as_string_elem(type, buf_p, dim_size[0], ss);
7465 }
7466 ss << ')';
7467}
7468
7470 int type, int len, PointerRNA *ptr, PropertyRNA *prop, std::stringstream &ss)
7471{
7472 void *buf_end;
7473 void *buf = rna_array_as_string_alloc(type, len, ptr, prop, &buf_end);
7474 void *buf_step = buf;
7475 int totdim, dim_size[RNA_MAX_ARRAY_DIMENSION];
7476
7477 totdim = RNA_property_array_dimension(ptr, prop, dim_size);
7478
7479 rna_array_as_string_recursive(type, &buf_step, totdim, dim_size, ss);
7480 BLI_assert(buf_step == buf_end);
7481 MEM_delete_void(buf);
7482}
7483
7485 bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
7486{
7487 int type = RNA_property_type(prop);
7488 int len = RNA_property_array_length(ptr, prop);
7489
7490 std::stringstream ss;
7491
7492 /* see if we can coerce into a python type - PropertyType */
7493 switch (type) {
7494 case PROP_BOOLEAN:
7495 if (len == 0) {
7497 }
7498 else {
7499 if (index != -1) {
7501 }
7502 else {
7503 rna_array_as_string(type, len, ptr, prop, ss);
7504 }
7505 }
7506 break;
7507 case PROP_INT:
7508 if (len == 0) {
7509 ss << RNA_property_int_get(ptr, prop);
7510 }
7511 else {
7512 if (index != -1) {
7513 ss << RNA_property_int_get_index(ptr, prop, index);
7514 }
7515 else {
7516 rna_array_as_string(type, len, ptr, prop, ss);
7517 }
7518 }
7519 break;
7520 case PROP_FLOAT:
7521 if (len == 0) {
7522 ss << fmt::format("{:g}", RNA_property_float_get(ptr, prop));
7523 }
7524 else {
7525 if (index != -1) {
7526 ss << fmt::format("{:g}", RNA_property_float_get_index(ptr, prop, index));
7527 }
7528 else {
7529 rna_array_as_string(type, len, ptr, prop, ss);
7530 }
7531 }
7532 break;
7533 case PROP_STRING: {
7534 const std::string str_value = RNA_property_string_get(ptr, prop);
7535 const std::string escaped = BLI_str_escape(str_value);
7536 ss << fmt::format("\"{}\"", escaped);
7537 break;
7538 }
7539 case PROP_ENUM: {
7540 /* string arrays don't exist */
7541 const char *identifier;
7542 int val = RNA_property_enum_get(ptr, prop);
7543
7544 if (RNA_property_flag(prop) & PROP_ENUM_FLAG) {
7545 /* represent as a python set */
7546 if (val) {
7547 const EnumPropertyItem *item_array;
7548 bool free;
7549
7550 ss << "{";
7551
7552 RNA_property_enum_items(C, ptr, prop, &item_array, nullptr, &free);
7553 if (item_array) {
7554 const EnumPropertyItem *item = item_array;
7555 bool is_first = true;
7556 for (; item->identifier; item++) {
7557 if (item->identifier[0] && item->value & val) {
7558 ss << fmt::format(fmt::runtime(is_first ? "'{}'" : ", '{}'"), item->identifier);
7559 is_first = false;
7560 }
7561 }
7562
7563 if (free) {
7564 MEM_delete(item_array);
7565 }
7566 }
7567
7568 ss << "}";
7569 }
7570 else {
7571 /* annoying exception, don't confuse with dictionary syntax above: {} */
7572 ss << "set()";
7573 }
7574 }
7575 else if (RNA_property_enum_identifier(C, ptr, prop, val, &identifier)) {
7576 ss << fmt::format("'{}'", identifier);
7577 }
7578 else {
7579 return "'<UNKNOWN ENUM>'";
7580 }
7581 break;
7582 }
7583 case PROP_POINTER: {
7584 PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
7585 ss << RNA_pointer_as_string(C, ptr, prop, &tptr).value_or("");
7586 break;
7587 }
7588 case PROP_COLLECTION: {
7589 int i = 0;
7590 CollectionPropertyIterator collect_iter;
7591 ss << "[";
7592
7593 for (RNA_property_collection_begin(ptr, prop, &collect_iter);
7594 (i < max_prop_length) && collect_iter.valid;
7595 RNA_property_collection_next(&collect_iter), i++)
7596 {
7597 PointerRNA itemptr = collect_iter.ptr;
7598
7599 if (i != 0) {
7600 ss << ", ";
7601 }
7602
7603 /* now get every prop of the collection */
7604 ss << RNA_pointer_as_string(C, ptr, prop, &itemptr).value_or("");
7605 }
7606
7607 RNA_property_collection_end(&collect_iter);
7608 ss << "]";
7609 break;
7610 }
7611 default:
7612 return "'<UNKNOWN TYPE>'"; /* TODO */
7613 }
7614
7615 return ss.str();
7616}
7617
7618/* Function */
7619
7621{
7622 return func->identifier.c_str();
7623}
7624
7626{
7627 return TIP_(func->description);
7628}
7629
7631{
7632 return func->description;
7633}
7634
7636{
7637 return func->flag;
7638}
7639
7641{
7642 return func->call != nullptr;
7643}
7644
7646{
7647 return static_cast<PropertyRNA *>(BLI_findlink(&func->cont.properties, index));
7648}
7649
7651 FunctionRNA *func,
7652 const char *identifier)
7653{
7654 PropertyRNA *parm;
7655
7656 parm = func->cont.properties.first();
7657 for (; parm; parm = parm->next) {
7658 if (STREQ(RNA_property_identifier(parm), identifier)) {
7659 break;
7660 }
7661 }
7662
7663 return parm;
7664}
7665
7666const ListBaseT<PropertyRNA> *RNA_function_defined_parameters(FunctionRNA *func)
7667{
7668 return &func->cont.properties;
7669}
7670
7671/* Utility */
7672
7674{
7675 return int(rna_ensure_property(prop)->flag_parameter);
7676}
7677
7679 PointerRNA * /*ptr*/,
7680 FunctionRNA *func)
7681{
7682 PointerRNA null_ptr = {};
7683 void *data;
7684 int alloc_size = 0, size;
7685
7686 parms->arg_count = 0;
7687 parms->ret_count = 0;
7688
7689 /* allocate data */
7690 for (PropertyRNA &parm : func->cont.properties) {
7691 alloc_size += rna_parameter_size_pad(rna_parameter_size(&parm));
7692
7693 if (parm.flag_parameter & PARM_OUTPUT) {
7694 parms->ret_count++;
7695 }
7696 else {
7697 parms->arg_count++;
7698 }
7699 }
7700
7701 parms->data = MEM_new_zeroed(alloc_size, "RNA_parameter_list_create");
7702 parms->func = func;
7703 parms->alloc_size = alloc_size;
7704
7705 /* set default values */
7706 data = parms->data;
7707
7708 for (PropertyRNA &parm : func->cont.properties) {
7709 size = rna_parameter_size(&parm);
7710
7711 /* set length to 0, these need to be set later, see bpy_array.c's py_to_array */
7712 if (parm.flag & PROP_DYNAMIC) {
7713 ParameterDynAlloc *data_alloc = static_cast<ParameterDynAlloc *>(data);
7714 data_alloc->array_tot = 0;
7715 data_alloc->array = nullptr;
7716 }
7717 else if ((parm.flag_parameter & PARM_RNAPTR) && (parm.flag & PROP_THICK_WRAP)) {
7718 BLI_assert(parm.type == PROP_POINTER);
7719 new (static_cast<PointerRNA *>(data)) PointerRNA();
7720 }
7721
7722 if (!(parm.flag_parameter & PARM_REQUIRED) && !(parm.flag & PROP_DYNAMIC)) {
7723 switch (parm.type) {
7724 case PROP_BOOLEAN:
7725 if (parm.arraydimension) {
7727 &null_ptr, reinterpret_cast<BoolPropertyRNA *>(&parm), static_cast<bool *>(data));
7728 }
7729 else {
7730 memcpy(data, &(reinterpret_cast<BoolPropertyRNA *>(&parm))->defaultvalue, size);
7731 }
7732 break;
7733 case PROP_INT:
7734 if (parm.arraydimension) {
7736 &null_ptr, reinterpret_cast<IntPropertyRNA *>(&parm), static_cast<int *>(data));
7737 }
7738 else {
7739 memcpy(data, &(reinterpret_cast<IntPropertyRNA *>(&parm))->defaultvalue, size);
7740 }
7741 break;
7742 case PROP_FLOAT:
7743 if (parm.arraydimension) {
7745 &null_ptr,
7746 reinterpret_cast<FloatPropertyRNA *>(&parm),
7747 static_cast<float *>(data));
7748 }
7749 else {
7750 memcpy(data, &(reinterpret_cast<FloatPropertyRNA *>(&parm))->defaultvalue, size);
7751 }
7752 break;
7753 case PROP_ENUM:
7754 memcpy(data, &(reinterpret_cast<EnumPropertyRNA *>(&parm))->defaultvalue, size);
7755 break;
7756 case PROP_STRING: {
7757 const char *defvalue = (reinterpret_cast<StringPropertyRNA *>(&parm))->defaultvalue;
7758 if (defvalue && defvalue[0]) {
7759 /* Causes bug #29988, possibly this is only correct for thick wrapped
7760 * need to look further into it - campbell */
7761#if 0
7762 BLI_strncpy(data, defvalue, size);
7763#else
7764 memcpy(data, &defvalue, size);
7765#endif
7766 }
7767 break;
7768 }
7769 case PROP_POINTER:
7770 case PROP_COLLECTION:
7771 break;
7772 }
7773 }
7774
7775 data = (static_cast<char *>(data)) + rna_parameter_size_pad(size);
7776 }
7777
7778 return parms;
7779}
7780
7782{
7783 PropertyRNA *parm;
7784
7785 parm = parms->func->cont.properties.first();
7786 void *data = parms->data;
7787 for (; parm; parm = parm->next) {
7788 if (parm->type == PROP_COLLECTION) {
7789 CollectionVector *vector = static_cast<CollectionVector *>(data);
7790 vector->~CollectionVector();
7791 }
7792 else if ((parm->flag_parameter & PARM_RNAPTR) && (parm->flag & PROP_THICK_WRAP)) {
7793 BLI_assert(parm->type == PROP_POINTER);
7794 PointerRNA *ptr = static_cast<PointerRNA *>(data);
7795 /* #RNA_parameter_list_create ensures that 'thick wrap' PointerRNA parameters are
7796 * constructed. */
7797 ptr->~PointerRNA();
7798 }
7799 else if (parm->flag & PROP_DYNAMIC) {
7800 /* for dynamic arrays and strings, data is a pointer to an array */
7801 ParameterDynAlloc *data_alloc = static_cast<ParameterDynAlloc *>(data);
7802 if (data_alloc->array) {
7803 MEM_delete_void(data_alloc->array);
7804 }
7805 }
7806 data = static_cast<char *>(data) + rna_parameter_size_pad(rna_parameter_size(parm));
7807 }
7808
7809 MEM_delete_void(parms->data);
7810 parms->data = nullptr;
7811
7812 parms->func = nullptr;
7813}
7814
7816{
7817 return parms->alloc_size;
7818}
7819
7821{
7822 return parms->arg_count;
7823}
7824
7826{
7827 return parms->ret_count;
7828}
7829
7831{
7832 /* may be useful but unused now */
7833 // RNA_pointer_create_discrete(nullptr, RNA_Function, parms->func, &iter->funcptr); /* UNUSED */
7834
7835 iter->parms = parms;
7836 iter->parm = parms->func->cont.properties.first();
7837 iter->valid = iter->parm != nullptr;
7838 iter->offset = 0;
7839
7840 if (iter->valid) {
7841 iter->size = rna_parameter_size(iter->parm);
7842 iter->data = (static_cast<char *>(iter->parms->data)); /* +iter->offset, always 0 */
7843 }
7844}
7845
7847{
7848 iter->offset += rna_parameter_size_pad(iter->size);
7849 iter->parm = iter->parm->next;
7850 iter->valid = iter->parm != nullptr;
7851
7852 if (iter->valid) {
7853 iter->size = rna_parameter_size(iter->parm);
7854 iter->data = ((static_cast<char *>(iter->parms->data)) + iter->offset);
7855 }
7856}
7857
7859{
7860 /* nothing to do */
7861}
7862
7863void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **r_value)
7864{
7865 ParameterIterator iter;
7866
7867 RNA_parameter_list_begin(parms, &iter);
7868
7869 for (; iter.valid; RNA_parameter_list_next(&iter)) {
7870 if (iter.parm == parm) {
7871 break;
7872 }
7873 }
7874
7875 if (iter.valid) {
7876 if (parm->flag & PROP_DYNAMIC) {
7877 /* for dynamic arrays and strings, data is a pointer to an array */
7878 ParameterDynAlloc *data_alloc = static_cast<ParameterDynAlloc *>(iter.data);
7879 *r_value = data_alloc->array;
7880 }
7881 else {
7882 *r_value = iter.data;
7883 }
7884 }
7885 else {
7886 *r_value = nullptr;
7887 }
7888
7890}
7891
7892void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **r_value)
7893{
7894 PropertyRNA *parm;
7895
7896 parm = parms->func->cont.properties.first();
7897 for (; parm; parm = parm->next) {
7898 if (STREQ(RNA_property_identifier(parm), identifier)) {
7899 break;
7900 }
7901 }
7902
7903 if (parm) {
7904 RNA_parameter_get(parms, parm, r_value);
7905 }
7906}
7907
7908void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
7909{
7910 ParameterIterator iter;
7911
7912 RNA_parameter_list_begin(parms, &iter);
7913
7914 for (; iter.valid; RNA_parameter_list_next(&iter)) {
7915 if (iter.parm == parm) {
7916 break;
7917 }
7918 }
7919
7920 if (iter.valid) {
7921 if (parm->flag & PROP_DYNAMIC) {
7922 /* for dynamic arrays and strings, data is a pointer to an array */
7923 ParameterDynAlloc *data_alloc = static_cast<ParameterDynAlloc *>(iter.data);
7924 size_t size = 0;
7925 switch (parm->type) {
7926 case PROP_STRING:
7927 size = sizeof(char);
7928 break;
7929 case PROP_INT:
7930 case PROP_BOOLEAN:
7931 size = sizeof(int);
7932 break;
7933 case PROP_FLOAT:
7934 size = sizeof(float);
7935 break;
7936 default:
7937 break;
7938 }
7939 size *= data_alloc->array_tot;
7940 if (data_alloc->array) {
7941 MEM_delete_void(data_alloc->array);
7942 }
7943 data_alloc->array = MEM_new_uninitialized(size, __func__);
7944 memcpy(data_alloc->array, value, size);
7945 }
7946 else if ((parm->flag_parameter & PARM_RNAPTR) && (parm->flag & PROP_THICK_WRAP)) {
7947 BLI_assert(parm->type == PROP_POINTER);
7948 BLI_assert(iter.size == sizeof(PointerRNA));
7949 PointerRNA *ptr = static_cast<PointerRNA *>(iter.data);
7950 /* #RNA_parameter_list_create ensures that 'thick wrap' PointerRNA parameters are
7951 * constructed. */
7952 *ptr = PointerRNA(*static_cast<const PointerRNA *>(value));
7953 }
7954 else {
7955 memcpy(iter.data, value, iter.size);
7956 }
7957 }
7958
7960}
7961
7962void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
7963{
7964 PropertyRNA *parm;
7965
7966 parm = parms->func->cont.properties.first();
7967 for (; parm; parm = parm->next) {
7968 if (STREQ(RNA_property_identifier(parm), identifier)) {
7969 break;
7970 }
7971 }
7972
7973 if (parm) {
7974 RNA_parameter_set(parms, parm, value);
7975 }
7976}
7977
7979{
7980 ParameterIterator iter;
7981 int len = 0;
7982
7983 RNA_parameter_list_begin(parms, &iter);
7984
7985 for (; iter.valid; RNA_parameter_list_next(&iter)) {
7986 if (iter.parm == parm) {
7987 break;
7988 }
7989 }
7990
7991 if (iter.valid) {
7992 len = RNA_parameter_dynamic_length_get_data(parms, parm, iter.data);
7993 }
7994
7996
7997 return len;
7998}
7999
8001{
8002 ParameterIterator iter;
8003
8004 RNA_parameter_list_begin(parms, &iter);
8005
8006 for (; iter.valid; RNA_parameter_list_next(&iter)) {
8007 if (iter.parm == parm) {
8008 break;
8009 }
8010 }
8011
8012 if (iter.valid) {
8014 }
8015
8017}
8018
8020{
8021 if (parm->flag & PROP_DYNAMIC) {
8022 return int((static_cast<ParameterDynAlloc *>(data))->array_tot);
8023 }
8024 return 0;
8025}
8026
8028 PropertyRNA *parm,
8029 void *data,
8030 int length)
8031{
8032 if (parm->flag & PROP_DYNAMIC) {
8033 (static_cast<ParameterDynAlloc *>(data))->array_tot = intptr_t(length);
8034 }
8035}
8036
8038 bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
8039{
8040 if (func->call) {
8041 func->call(C, reports, ptr, parms);
8042
8043 return 0;
8044 }
8045
8046 return -1;
8047}
8048
8049std::optional<StringRefNull> RNA_translate_ui_text(
8050 const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, int translate)
8051{
8052 return rna_translate_ui_text(text, text_ctxt, type, prop, translate);
8053}
8054
8056{
8057 int len;
8058
8059 /* get the length of the array to work with */
8060 len = RNA_property_array_length(ptr, prop);
8061
8062 /* get and set the default values as appropriate for the various types */
8063 switch (RNA_property_type(prop)) {
8064 case PROP_BOOLEAN:
8065 if (len) {
8066 if (index == -1) {
8067 bool *tmparray = MEM_new_array_zeroed<bool>(len, __func__);
8068
8069 RNA_property_boolean_get_default_array(ptr, prop, tmparray);
8070 RNA_property_boolean_set_array(ptr, prop, tmparray);
8071
8072 MEM_delete(tmparray);
8073 }
8074 else {
8075 int value = RNA_property_boolean_get_default_index(ptr, prop, index);
8076 RNA_property_boolean_set_index(ptr, prop, index, value);
8077 }
8078 }
8079 else {
8080 int value = RNA_property_boolean_get_default(ptr, prop);
8081 RNA_property_boolean_set(ptr, prop, value);
8082 }
8083 return true;
8084 case PROP_INT:
8085 if (len) {
8086 if (index == -1) {
8087 int *tmparray = MEM_new_array_zeroed<int>(len, __func__);
8088
8089 RNA_property_int_get_default_array(ptr, prop, tmparray);
8090 RNA_property_int_set_array(ptr, prop, tmparray);
8091
8092 MEM_delete(tmparray);
8093 }
8094 else {
8095 int value = RNA_property_int_get_default_index(ptr, prop, index);
8096 RNA_property_int_set_index(ptr, prop, index, value);
8097 }
8098 }
8099 else {
8100 int value = RNA_property_int_get_default(ptr, prop);
8101 RNA_property_int_set(ptr, prop, value);
8102 }
8103 return true;
8104 case PROP_FLOAT:
8105 if (len) {
8106 if (index == -1) {
8107 float *tmparray = MEM_new_array_zeroed<float>(len, __func__);
8108
8109 RNA_property_float_get_default_array(ptr, prop, tmparray);
8110 RNA_property_float_set_array(ptr, prop, tmparray);
8111
8112 MEM_delete(tmparray);
8113 }
8114 else {
8115 float value = RNA_property_float_get_default_index(ptr, prop, index);
8116 RNA_property_float_set_index(ptr, prop, index, value);
8117 }
8118 }
8119 else {
8120 float value = RNA_property_float_get_default(ptr, prop);
8121 RNA_property_float_set(ptr, prop, value);
8122 }
8123 return true;
8124 case PROP_ENUM: {
8125 int value = RNA_property_enum_get_default(ptr, prop);
8126 RNA_property_enum_set(ptr, prop, value);
8127 return true;
8128 }
8129
8130 case PROP_STRING: {
8131 char *value = RNA_property_string_get_default_alloc(ptr, prop, nullptr, 0, nullptr);
8132 RNA_property_string_set(ptr, prop, value);
8133 MEM_delete(value);
8134 return true;
8135 }
8136
8137 case PROP_POINTER: {
8138 PointerRNA value;
8139 if (bmain) {
8140 value = RNA_property_pointer_get_default(*bmain, *ptr, *prop);
8141 }
8142 else {
8143 value = {};
8144 }
8145 RNA_property_pointer_set(ptr, prop, value, nullptr);
8146 return true;
8147 }
8148
8149 default:
8150 /* FIXME: are there still any cases that haven't been handled?
8151 * comment out "default" block to check :) */
8152 return false;
8153 }
8154}
8155
8157{
8159 return false;
8160 }
8161
8162 /* get and set the default values as appropriate for the various types */
8163 switch (RNA_property_type(prop)) {
8164 case PROP_INT: {
8165 int value = RNA_property_int_get(ptr, prop);
8166 return RNA_property_int_set_default(prop, value);
8167 }
8168
8169 case PROP_FLOAT: {
8170 float value = RNA_property_float_get(ptr, prop);
8171 return RNA_property_float_set_default(prop, value);
8172 }
8173
8174 default:
8175 return false;
8176 }
8177}
8178
8179#ifdef WITH_PYTHON
8180extern void PyC_LineSpit();
8181#endif
8182
8183void _RNA_warning(const char *format, ...)
8184{
8185 va_list args;
8186
8187 va_start(args, format);
8188 vprintf(format, args);
8189 va_end(args);
8190
8191 /* gcc macro adds '\n', but can't use for other compilers */
8192#ifndef __GNUC__
8193 fputc('\n', stdout);
8194#endif
8195
8196#ifdef WITH_PYTHON
8197 {
8198 PyC_LineSpit();
8199 }
8200#endif
8201}
8202
8204 PropertyRNA *prop,
8205 const int prop_index,
8206 PathResolvedRNA *r_anim_rna)
8207{
8208 int array_len = RNA_property_array_length(ptr, prop);
8209
8210 if ((array_len == 0) || (prop_index < array_len)) {
8211 r_anim_rna->ptr = *ptr;
8212 r_anim_rna->prop = prop;
8213 r_anim_rna->prop_index = array_len ? prop_index : -1;
8214
8215 return true;
8216 }
8217 return false;
8218}
8219
8220static char rna_struct_state_owner[128];
8221void RNA_struct_state_owner_set(const char *name)
8222{
8223 if (name) {
8225 }
8226 else {
8227 rna_struct_state_owner[0] = '\0';
8228 }
8229}
8230
8232{
8233 if (rna_struct_state_owner[0]) {
8235 }
8236 return nullptr;
8237}
8238
8239} // namespace blender
#define G_MAIN
#define IDP_int_or_bool_set(prop, value)
#define IDP_ID_get(prop)
#define IDP_float_get(prop)
#define IDP_bool_set(prop, value)
#define IDP_int_get(prop)
#define IDP_array_double_get(prop)
#define IDP_int_set(prop, value)
#define IDP_string_get(prop)
#define IDP_double_get(prop)
#define IDP_array_bool_get(prop)
#define IDP_array_int_get(prop)
#define IDP_property_array_get(prop)
#define IDP_int_or_bool_get(prop)
#define IDP_float_set(prop, value)
#define IDP_double_set(prop, value)
#define IDP_array_float_get(prop)
#define IDP_bool_get(prop)
A dynamically sized string ADT.
#define BLI_string_debug_size(str, str_maxncpy)
#define TIP_(msgid)
#define CTX_IFACE_(context, msgid)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
ID and Library types, which are fundamental for SDNA.
#define ID_REFCOUNTING_USERS(id)
Definition DNA_ID.h:684
#define ID_TYPE_USE_COPY_ON_EVAL(_id_type)
Definition DNA_ID.h:746
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define IDP_NUMTYPES
Read Blender memory allocation and freeing.
#define RNA_PROP_END
#define RNA_STRUCT_BEGIN(sptr, prop)
#define RNA_STRUCT_END
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
#define RNA_MAX_ARRAY_LENGTH
Definition RNA_define.hh:26
#define RNA_MAX_ARRAY_DIMENSION
Definition RNA_define.hh:29
#define RNA_SUBTYPE_UNIT(subtype)
Definition RNA_types.hh:266
#define C
Definition RandGen.cpp:29
#define ND_SHADING
Definition WM_types.hh:520
#define NC_WINDOW
Definition WM_types.hh:388
#define NC_ID
Definition WM_types.hh:408
#define NA_EDITED
Definition WM_types.hh:634
#define NC_MATERIAL
Definition WM_types.hh:393
volatile int lock
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define BLI_INLINE
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
btScalar max
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
Span< T > as_span() const
Definition BLI_array.hh:254
MutableSpan< T > as_mutable_span()
Definition BLI_array.hh:259
const T * data() const
Definition BLI_array.hh:323
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
constexpr IndexRange()=default
constexpr T * data() const
Definition BLI_span.hh:545
constexpr Span< T > as_span() const
Definition BLI_span.hh:667
bool contains(const Key &key) const
Definition BLI_set.hh:310
void add_new(const Key &key)
Definition BLI_set.hh:233
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr Span()=default
const char * c_str() const
StringRefNull ref() const
UString()=default
#define str(s)
#define FLT_MAX
#define INT_MAX
#define main()
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
float length(VecOp< float, D >) RET
float4x4 translate(float4x4 mat, float3 translation)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
std::unique_ptr< IDProperty, IDPropertyDeleter > create_bool(StringRef prop_name, bool value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_BOOLEAN, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
void free(Subdiv *subdiv)
Definition subdiv.cc:192
BMesh Iterators.
MINLINE float min_ff(float a, float b)
void WM_main_add_notifier(uint type, void *reference)
IDProperty * rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
PropertyRNA * RNA_function_find_parameter(PointerRNA *, FunctionRNA *func, const char *identifier)
char * RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void RNA_collection_begin(PointerRNA *ptr, const char *name, CollectionPropertyIterator *iter)
bool RNA_property_assign_default(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
PointerRNA RNA_pointer_create_from_ancestor(const PointerRNA &ptr, const int ancestor_idx)
void RNA_property_string_get_default(PointerRNA *ptr, PropertyRNA *prop, char *value, const int value_maxncpy)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
const char * RNA_function_ui_description_raw(FunctionRNA *func)
static void property_float_get_array(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id, MutableSpan< float > r_values)
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
int RNA_property_enum_bitflag_identifiers(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_identifier)
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:812
bool rna_property_can_access_pointer_data(const PointerRNA &ptr, PropertyRNA &prop)
void ** RNA_struct_instance(PointerRNA *ptr)
static void update_idprop_int(PointerRNA &rna_ptr, PropertyRNA &rna_prop, IDProperty &idprop)
int RNA_parameter_dynamic_length_get_data(ParameterList *, PropertyRNA *parm, void *data)
unsigned __int64 uint64_t
Definition BKE_text.h:91
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
MINLINE int mod_i(int i, int n)
void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format,...) ATTR_PRINTF_FORMAT(2
std::string RNA_struct_to_string(const StructRNA &type)
__int64 int64_t
Definition BKE_text.h:90
bool RNA_struct_idprops_datablock_allowed(const StructRNA *type)
bool RNA_struct_system_idprops_check(StructRNA *srna)
void RNA_property_int_get_array_at_most(PointerRNA *ptr, PropertyRNA *prop, int *values, int values_num)
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
char * STRNCPY(char(&dst)[N], const char *src)
void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **r_value)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, float values[2])
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:737
static void rna_array_as_string_elem(int type, void **buf_p, int len, std::stringstream &ss)
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
@ RPT_WARNING
Definition BKE_report.hh:40
PropertyRNA * rna_struct_find_nested(PointerRNA *ptr, StructRNA *srna)
void RNA_property_float_get_array_at_most(PointerRNA *ptr, PropertyRNA *prop, float *values, int values_num)
PointerRNA RNA_main_pointer_create(Main *main)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
@ STRUCT_NO_IDPROPERTIES
@ STRUCT_RNA_DEFINITION
@ STRUCT_PUBLIC_NAMESPACE
@ STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
@ STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID
bool RNA_struct_idprops_check(const StructRNA *srna)
PointerRNA RNA_pointer_recast(PointerRNA *ptr)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
static int property_enum_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
int RNA_parameter_list_ret_count(const ParameterList *parms)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
unsigned int uint
Definition BKE_text.h:55
const char * RNA_property_ui_name_raw(const PropertyRNA *prop, const PointerRNA *ptr)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:529
static bool property_boolean_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
const char * RNA_function_ui_description(FunctionRNA *func)
static std::string property_string_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
void RNA_property_string_set_bytes(PointerRNA *ptr, PropertyRNA *prop, const char *value, int len)
void rna_iterator_array_end(CollectionPropertyIterator *iter)
static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
PointerRNA RNA_blender_rna_pointer_create()
int RNA_property_string_length(PointerRNA *ptr, PropertyRNA *prop)
static void rna_property_boolean_fill_default_array_values_from_ints(const int *defarr, int defarr_length, bool defvalue, int out_length, bool *r_values)
bool RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const char *enumname)
bool RNA_property_editable_flag(const PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_pointer_remove(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int values[2])
bool RNA_property_reset(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index)
bool RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_identifier)
PointerRNA RNA_id_pointer_create(ID *id)
void RNA_parameter_set(ParameterList *parms, PropertyRNA *parm, const void *value)
ID * BKE_libblock_find_session_uid(Main *bmain, short type, uint32_t session_uid)
Definition lib_id.cc:1826
void * RNA_struct_py_type_get(StructRNA *srna)
int RNA_property_collection_lookup_index(PointerRNA *ptr, PropertyRNA *prop, const PointerRNA *t_ptr)
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
std::optional< std::string > RNA_path_full_struct_py(const PointerRNA *ptr)
Definition rna_path.cc:1325
bool BLT_translate_tooltips()
int rna_parameter_size_pad(const int size)
PropertyRNA * RNA_struct_type_find_property_no_base(StructRNA *srna, const UString identifier)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
const char * RNA_property_identifier(const PropertyRNA *prop)
void RNA_parameter_dynamic_length_set(ParameterList *parms, PropertyRNA *parm, int length)
bool RNA_property_editable_info(const PointerRNA *ptr, PropertyRNA *prop, const char **r_info)
eRNAStatus RNA_property_collection_move(PointerRNA *ptr, PropertyRNA *prop, int src_index, int dst_index)
StructRNA * ID_code_to_RNA_type(short idcode)
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
bool RNA_property_builtin(PropertyRNA *prop)
bool RNA_property_enum_name(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
static bool property_collection_liboverride_editable(PointerRNA *ptr, PropertyRNA *prop, bool *r_is_liboverride)
bool RNA_property_float_set_default(PropertyRNA *prop, float value)
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_enum_items(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
int RNA_enum_bitflag_identifiers(const EnumPropertyItem *item, const int value, const char **r_identifier)
uint RNA_struct_count_properties(StructRNA *srna)
int RNA_property_collection_raw_get(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname, void *array, RawPropertyType type, int len)
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:818
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
int rna_parameter_size(PropertyRNA *parm)
static void update_idprop_id(Main &bmain, PointerRNA &rna_ptr, PropertyRNA &rna_prop, IDProperty &idprop)
PointerRNA RNA_property_pointer_get_default(Main &bmain, PointerRNA &, PropertyRNA &prop)
void RNA_sync_system_properties(Main &bmain, PointerRNA &ptr, IDProperty &idprops)
std::optional< AncestorPointerRNA > RNA_struct_search_closest_ancestor_by_type(const PointerRNA *ptr, const StructRNA *srna)
const char * RNA_struct_state_owner_get()
FCurve * BKE_fcurve_find_by_rna(PointerRNA *ptr, PropertyRNA *prop, int rnaindex, AnimData **r_adt, bAction **r_action, bool *r_driven, bool *r_special)
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
FunctionRNA * RNA_struct_find_function(StructRNA *srna, const char *identifier_c_str)
PointerRNA RNA_property_pointer_get_never_create(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_struct_property_is_set_ex(PointerRNA *ptr, const char *identifier, bool use_ghost)
void RNA_parameter_list_next(ParameterIterator *iter)
void * RNA_struct_blender_type_get(StructRNA *srna)
void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter)
bool RNA_struct_idprops_contains_datablock(const StructRNA *type)
PropertyUnit RNA_property_unit(PropertyRNA *prop)
void RNA_parameter_list_end(ParameterIterator *)
bool RNA_property_driver_editable(const PointerRNA *ptr, PropertyRNA *prop)
PropertyRNA * RNA_struct_find_property_check(PointerRNA &props, const char *name, const PropertyType property_type_check)
void RNA_struct_property_unset(PointerRNA *ptr, const char *identifier)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_overridable_get(const PointerRNA *ptr, PropertyRNA *prop)
StructUnregisterFunc RNA_struct_unregister(StructRNA *type)
bool RNA_property_enum_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *r_value)
bool RNA_property_collection_assign_int(PointerRNA *ptr, PropertyRNA *prop, const int key, const PointerRNA *assign_ptr)
int RNA_int_get(PointerRNA *ptr, const char *name)
std::optional< std::string > RNA_pointer_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop)
static const char * rna_ensure_property_description(const PropertyRNA *prop)
float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void rna_pointer_create_with_ancestors(const PointerRNA &parent, StructRNA *type, void *data, PointerRNA &r_ptr)
const char * RNA_property_description(PropertyRNA *prop)
bool RNA_property_string_is_utf8(PropertyRNA *prop)
IDProperty ** RNA_struct_system_idprops_p(PointerRNA *ptr)
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
const char * RNA_property_translation_context(const PropertyRNA *prop)
MINLINE int max_ii(int a, int b)
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
const char * RNA_struct_ui_name(const StructRNA *type)
bool RNA_property_animateable(const PointerRNA *ptr, PropertyRNA *prop_orig)
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
void RNA_property_string_search(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *edit_text, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
uint RNA_enum_items_count(const EnumPropertyItem *item)
static int property_int_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
void RNA_boolean_get_array(PointerRNA *ptr, const char *name, bool *values)
bool id_can_have_animdata(const ID *id)
Definition anim_data.cc:78
const char * RNA_struct_ui_name_raw(const StructRNA *type)
PropertyScaleType RNA_property_ui_scale(PropertyRNA *prop)
int RNA_property_array_item_index(PropertyRNA *prop, char name)
bool BKE_lib_override_library_is_system_defined(const Main *bmain, const ID *id)
eIDPropertyUIDataType IDP_ui_data_type(const IDProperty *prop)
Definition idprop.cc:1964
void IDP_AssignID(IDProperty *prop, ID *id, int flag)
Definition idprop.cc:616
int RNA_enum_from_value(const EnumPropertyItem *item, const int value)
StructRNA * RNA_struct_find(const char *identifier)
static bool rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDProperty *idprop)
void RNA_free(BlenderRNA *brna)
static void update_idprop_float(PointerRNA &rna_ptr, PropertyRNA &rna_prop, IDProperty &idprop)
void MEM_delete_void(void *vmemh)
void rna_iterator_listbase_end(CollectionPropertyIterator *)
std::optional< StringRefNull > rna_translate_ui_text(const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, bool translate)
char * RNA_string_get_alloc(PointerRNA *ptr, const char *name, char *fixedbuf, int fixedlen, int *r_len)
static void property_boolean_get_array(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id, MutableSpan< bool > r_values)
const ListBaseT< PropertyRNA > * RNA_struct_type_properties(StructRNA *srna)
void BLI_dynstr_free(DynStr *ds) ATTR_NONNULL()
PropertyPathTemplateType
Definition RNA_types.hh:564
void RNA_init()
Definition rna_access.cc:88
void RNA_pointer_add(PointerRNA *ptr, const char *name)
void PyC_LineSpit()
void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop_exist, int flag)
Definition idprop.cc:716
bool RNA_property_collection_remove(PointerRNA *ptr, PropertyRNA *prop, int key)
@ PROPOVERRIDE_LIBRARY_INSERTION
Definition RNA_types.hh:614
int RNA_function_flag(FunctionRNA *func)
ParameterList * RNA_parameter_list_create(ParameterList *parms, PointerRNA *, FunctionRNA *func)
void RNA_parameter_dynamic_length_set_data(ParameterList *, PropertyRNA *parm, void *data, int length)
PropertyRNA * RNA_function_get_parameter(PointerRNA *, FunctionRNA *func, int index)
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_array_check(PropertyRNA *prop)
void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *r_ptr)
bool RNA_enum_value_from_id(const EnumPropertyItem *item, const char *identifier, int *r_value)
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
bool RNA_property_enum_name_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **r_name)
void RNA_bpy_exit()
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
bool BKE_id_can_use_id(const ID &id_from, const ID &id_to)
Definition lib_id.cc:2787
unsigned short uint16_t
Definition BKE_text.h:80
static const char * rna_ensure_property_name(const PropertyRNA *prop)
std::string RNA_pointer_as_string_id(bContext *C, PointerRNA *ptr)
const EnumPropertyItem * RNA_struct_property_tag_defines(const StructRNA *type)
PropertyType RNA_property_type(PropertyRNA *prop)
bool RNA_property_collection_lookup_string_has_fn(PropertyRNA *prop)
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
static size_t property_string_length_storage(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
bool RNA_property_is_runtime(const PropertyRNA *prop)
static const char * rna_ensure_property_identifier(const PropertyRNA *prop)
bool RNA_property_undo_check(const PropertyRNA *prop, const StructRNA *type)
static bool rna_ensure_property_array_check(PropertyRNA *prop)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
Definition idprop.cc:203
void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) ATTR_NONNULL()
Definition BLI_dynstr.cc:58
PropertyPathTemplateType RNA_property_path_template_type(PropertyRNA *prop)
void RNA_int_set_array(PointerRNA *ptr, const char *name, const int *values)
BLI_INLINE void rna_pointer_refine(PointerRNA &r_ptr)
int RNA_function_defined(FunctionRNA *func)
int RNA_property_enum_get_default(PointerRNA *ptr, PropertyRNA *prop)
PropertyScaleType
Definition RNA_types.hh:251
@ PROP_SCALE_LINEAR
Definition RNA_types.hh:253
static void sync_system_properties(Main &bmain, PointerRNA &ptr, IDProperty &idprops, const bool ensure)
int RNA_enum_from_identifier(const EnumPropertyItem *item, const char *identifier)
bool RNA_property_anim_editable(const PointerRNA *ptr, PropertyRNA *prop_orig)
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1408
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
std::optional< StringRefNull > RNA_translate_ui_text(const char *text, const char *text_ctxt, StructRNA *type, PropertyRNA *prop, int translate)
void RNA_collection_clear(PointerRNA *ptr, const char *name)
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
bool RNA_enum_name_from_value(const EnumPropertyItem *item, int value, const char **r_name)
eStringPropertySearchFlag
Definition RNA_types.hh:869
@ PROP_STRING_SEARCH_SUPPORTED
Definition RNA_types.hh:874
static PropertyRNA * typemap[IDP_NUMTYPES]
int RNA_property_tags(PropertyRNA *prop)
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
IDProperty * RNA_struct_system_idprops(PointerRNA *ptr, bool create)
@ IDP_FLAG_GHOST
@ IDP_FLAG_OVERRIDELIBRARY_LOCAL
@ IDP_FLAG_STATIC_TYPE
void DEG_id_tag_update(ID *id, unsigned int flags)
static void update_idprop_bool(PointerRNA &rna_ptr, PropertyRNA &rna_prop, IDProperty &idprop)
const char * BLT_pgettext(const char *msgctxt, const char *msgid)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
static void rna_property_float_get_default_array_values(PointerRNA *ptr, FloatPropertyRNA *fprop, float *r_values)
BMesh const char void * data
std::string RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, const bool as_function, const bool all_args, const bool nested_args, const int max_prop_length)
void RNA_property_collection_end(CollectionPropertyIterator *iter)
void RNA_int_get_array(PointerRNA *ptr, const char *name, int *values)
bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
void RNA_exit()
void RNA_property_enum_items_ex(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const bool use_static, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
IDProperty * RNA_struct_idprops(PointerRNA *ptr, bool create)
bool RNA_enum_name(const EnumPropertyItem *item, const int value, const char **r_name)
bool(*)(Main *bmain, StructRNA *type) StructUnregisterFunc
std::string RNA_path_full_ID_py(ID *id)
Definition rna_path.cc:1290
@ PROP_RAW_UINT8
Definition RNA_types.hh:716
@ PROP_RAW_DOUBLE
Definition RNA_types.hh:714
@ PROP_RAW_INT8
Definition RNA_types.hh:720
@ PROP_RAW_UINT16
Definition RNA_types.hh:717
@ PROP_RAW_INT
Definition RNA_types.hh:710
@ PROP_RAW_UINT64
Definition RNA_types.hh:719
@ PROP_RAW_SHORT
Definition RNA_types.hh:711
@ PROP_RAW_FLOAT
Definition RNA_types.hh:715
@ PROP_RAW_INT64
Definition RNA_types.hh:718
@ PROP_RAW_BOOLEAN
Definition RNA_types.hh:713
@ PROP_RAW_UNSET
Definition RNA_types.hh:709
@ PROP_RAW_CHAR
Definition RNA_types.hh:712
bool RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
std::string RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, const bool as_function, const bool all_args, const int max_prop_length)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
PointerRNA rna_array_lookup_int(PointerRNA *ptr, StructRNA *type, void *data, size_t itemsize, int64_t length, int64_t index)
bool RNA_path_resolved_create(PointerRNA *ptr, PropertyRNA *prop, const int prop_index, PathResolvedRNA *r_anim_rna)
unsigned char uint8_t
Definition BKE_text.h:79
void * rna_iterator_array_dereference_get(CollectionPropertyIterator *iter)
bool RNA_struct_contains_property(PointerRNA *ptr, PropertyRNA *prop_test)
int RNA_parameter_dynamic_length_get(ParameterList *parms, PropertyRNA *parm)
void RNA_property_unset(PointerRNA *ptr, PropertyRNA *prop)
char RNA_property_array_item_char(PropertyRNA *prop, int index)
bool RNA_enum_icon_from_value(const EnumPropertyItem *item, int value, int *r_icon)
int RNA_property_flag(PropertyRNA *prop)
void rna_iterator_array_next(CollectionPropertyIterator *iter)
int RNA_property_float_clamp(PointerRNA *ptr, PropertyRNA *prop, float *value)
bool RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr)
const char * RNA_function_identifier(FunctionRNA *func)
void _RNA_warning(const char *format,...)
const char * RNA_property_ui_description_raw(const PropertyRNA *prop, const PointerRNA *ptr)
static char rna_struct_state_owner[128]
RawPropertyType RNA_property_raw_type(PropertyRNA *prop)
int RNA_parameter_list_size(const ParameterList *parms)
static void rna_property_boolean_fill_default_array_values(const bool *defarr, int defarr_length, bool defvalue, int out_length, bool *r_values)
bool RNA_property_is_idprop(const PropertyRNA *prop)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
void RNA_struct_py_type_set(StructRNA *srna, void *py_type)
bool RNA_property_enum_item_from_value_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PropertyRNA * RNA_struct_type_find_property(StructRNA *srna, const char *identifier)
char * BLI_dynstr_get_cstring(const DynStr *ds) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void(*)(bContext *C, PointerRNA *ptr, PropertyRNA *prop) ContextPropUpdateFunc
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
bool RNA_property_update_check(PropertyRNA *prop)
void RNA_property_boolean_set_array_at_most(PointerRNA *ptr, PropertyRNA *prop, const bool *values, int values_num)
void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
const char * RNA_struct_ui_description_raw(const StructRNA *type)
void RNA_property_float_set_array_at_most(PointerRNA *ptr, PropertyRNA *prop, const float *values, int values_num)
ATTR_WARN_UNUSED_RESULT const size_t num
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void(*)(bContext *C, PointerRNA *ptr) ContextUpdateFunc
void RNA_property_collection_skip(CollectionPropertyIterator *iter, int num)
bool RNA_enum_id_from_value(const EnumPropertyItem *item, int value, const char **r_identifier)
void RNA_property_pointer_add(PointerRNA *ptr, PropertyRNA *prop)
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
@ IDP_STRING_SUB_UTF8
@ IDP_STRING_SUB_BYTE
static PropertyRNA * arraytypemap[IDP_NUMTYPES]
void * rna_iterator_array_get(CollectionPropertyIterator *iter)
bool RNA_property_collection_lookup_int_has_fn(PropertyRNA *prop)
void IDP_ResizeArray(IDProperty *prop, int newlen)
Definition idprop.cc:263
IDProperty * IDP_GetIndexArray(IDProperty *prop, int index) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:165
int RNA_property_array_dimension(const PointerRNA *ptr, PropertyRNA *prop, int length[])
static void rna_property_float_fill_default_array_values(const float *defarr, int defarr_length, float defvalue, int out_length, float *r_values)
bool RNA_struct_system_idprops_unset(PointerRNA *ptr, const char *identifier)
void WM_msg_publish_rna(wmMsgBus *mbus, PointerRNA *ptr, PropertyRNA *prop)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
int RNA_parameter_list_arg_count(const ParameterList *parms)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
static int rna_property_array_length_all_dimensions(PointerRNA *ptr, PropertyRNA *prop)
PointerRNA rna_listbase_lookup_int(PointerRNA *ptr, StructRNA *type, ListBase *lb, int index)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
std::optional< std::string > RNA_property_string_path_filter(const bContext *C, PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_enum_item_from_value(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, EnumPropertyItem *r_item)
int RNA_struct_ui_icon(const StructRNA *type)
static void rna_system_idproperty_free(PointerRNA *ptr, const char *name)
bool RNA_struct_is_ID(const StructRNA *type)
bool(*)(PointerRNA *ptr, const PointerRNA value, const PropertyRNA *prop) PropPointerPollFuncPy
int RNA_string_length(PointerRNA *ptr, const char *name)
const char * BLT_translate_do_iface(const char *msgctxt, const char *msgid)
void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **r_value)
const DeprecatedRNA * RNA_property_deprecated(const PropertyRNA *prop)
void RNA_boolean_set_array(PointerRNA *ptr, const char *name, const bool *values)
bool RNA_struct_system_idprops_register_check(const StructRNA *type)
int RNA_property_enum_step(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, int from_value, int step)
const char * RNA_struct_identifier(const StructRNA *type)
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
void IDP_AppendArray(IDProperty *prop, IDProperty *item)
Definition idprop.cc:172
void RNA_struct_state_owner_set(const char *name)
bool RNA_enum_value_from_identifier(const EnumPropertyItem *item, const char *identifier, int *r_value)
void RNA_property_collection_next(CollectionPropertyIterator *iter)
int RNA_property_string_default_length(PointerRNA *ptr, PropertyRNA *prop)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
PropertySubType RNA_property_subtype(PropertyRNA *prop)
const char * RNA_struct_ui_description(const StructRNA *type)
bool RNA_enum_name_gettexted(const EnumPropertyItem *item, int value, const char *translation_context, const char **r_name)
bool RNA_property_collection_is_empty(PointerRNA *ptr, PropertyRNA *prop)
static void property_int_get_array(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id, MutableSpan< int > r_values)
int RNA_parameter_flag(PropertyRNA *prop)
bool RNA_struct_bl_idname_ok_or_report(ReportList *reports, const char *identifier, const char *sep)
void * rna_iterator_listbase_get(CollectionPropertyIterator *iter)
const StructRNA * RNA_struct_base_child_of(const StructRNA *type, const StructRNA *parent_type)
static float property_float_get(PointerRNA *ptr, PropertyRNAOrID &prop_rna_or_id)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
bool RNA_property_int_set_default(PropertyRNA *prop, int value)
float RNA_property_float_get_default(PointerRNA *ptr, PropertyRNA *prop)
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
StructRNA *(*)(Main *bmain, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) StructRegisterFunc
Main * CTX_data_main(const bContext *C)
int RNA_property_collection_raw_set(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname, void *array, RawPropertyType type, int len)
IDProperty * rna_system_idproperty_find(PointerRNA *ptr, const char *name)
StructRNA * RNA_struct_base(StructRNA *type)
void RNA_ensure_and_sync_system_properties(Main &bmain, PointerRNA &ptr, IDProperty &idprops)
char * RNA_struct_name_get_alloc_ex(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len, PropertyRNA **r_nameprop)
void RNA_property_collection_clear(PointerRNA *ptr, PropertyRNA *prop)
const char * RNA_property_ui_description(const PropertyRNA *prop, const PointerRNA *ptr)
std::optional< PointerRNA > RNA_property_collection_type_get(PointerRNA *ptr, PropertyRNA *prop)
MINLINE float max_ff(float a, float b)
static const char * bool_as_py_string(const int var)
static void rna_property_int_fill_default_array_values(const int *defarr, int defarr_length, int defvalue, int out_length, int *r_values)
std::mutex Mutex
Definition BLI_mutex.hh:51
int RNA_function_call(bContext *C, ReportList *reports, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
std::string RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, const bool as_function, const bool all_args, const bool nested_args, const int max_prop_length, PropertyRNA *iterprop)
bool RNA_enum_description(const EnumPropertyItem *item, const int value, const char **r_description)
@ ID_RECALC_PARAMETERS
Definition DNA_ID.h:1138
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ PROP_DEG_SYNC_ONLY
Definition RNA_types.hh:515
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:477
@ PROP_CONTEXT_PROPERTY_UPDATE
Definition RNA_types.hh:478
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_ENUM_NO_CONTEXT
Definition RNA_types.hh:500
@ PROP_ENUM_FLAG
Definition RNA_types.hh:474
@ PROP_FORCE_UNDO
Definition RNA_types.hh:552
@ PROP_DYNAMIC
Definition RNA_types.hh:498
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_IDPROPERTY
Definition RNA_types.hh:496
@ PROP_REGISTER
Definition RNA_types.hh:481
@ PROP_ENUM_NO_TRANSLATE
Definition RNA_types.hh:502
@ PROP_NEVER_UNLINK
Definition RNA_types.hh:454
@ PROP_ID_REFCOUNT
Definition RNA_types.hh:434
@ PROP_ID_SELF_CHECK
Definition RNA_types.hh:440
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
@ PROP_NO_DEG_UPDATE
Definition RNA_types.hh:509
@ PROP_LIB_EXCEPTION
Definition RNA_types.hh:382
int RNA_property_int_get_default(PointerRNA *ptr, PropertyRNA *prop)
void BPY_free_srna_pytype(StructRNA *srna)
Definition bpy_rna.cc:10480
bool RNA_property_collection_lookup_string_supported(PropertyRNA *prop)
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
void RNA_property_enum_set(PointerRNA *ptr, PropertyRNA *prop, int value)
bool RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, PointerRNA *r_ptr)
bool BLT_translate_iface()
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
bool RNA_property_collection_lookup_string_has_nameprop(PropertyRNA *prop)
bool RNA_property_editable(const PointerRNA *ptr, PropertyRNA *prop)
static CLG_LogRef LOG
Definition logging.cpp:12
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:1132
Span< std::unique_ptr< FunctionRNA > > RNA_struct_type_functions(StructRNA *srna)
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
static bool rna_property_editable_do(const PointerRNA *ptr, PropertyRNA *prop_orig, const int index, const char **r_info)
static void rna_property_float_fill_default_array_values_double(const double *default_array, const int default_array_len, const double default_value, const int out_length, float *r_values)
int RNA_property_int_clamp(PointerRNA *ptr, PropertyRNA *prop, int *value)
void DEG_relations_tag_update(Main *bmain)
PropertyRNA * rna_ensure_property(PropertyRNA *prop)
static void rna_ensure_property_multi_array_length(const PointerRNA *ptr, PropertyRNA *prop, int length[])
int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dimension)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
static void rna_property_boolean_get_default_array_values(PointerRNA *ptr, BoolPropertyRNA *bprop, bool *r_values)
Scene * CTX_data_scene(const bContext *C)
@ ID_FLAG_EMBEDDED_DATA
Definition DNA_ID.h:775
IDProperty * IDP_NewStringMaxSize(const char *st, size_t st_maxncpy, StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:400
static void * rna_array_as_string_alloc(int type, int len, PointerRNA *ptr, PropertyRNA *prop, void **r_buf_end)
int RNA_property_ui_icon(const PropertyRNA *prop)
bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_collection_lookup_string_index(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
bool RNA_collection_is_empty(PointerRNA *ptr, const char *name)
void RNA_pointer_set(PointerRNA *ptr, const char *name, PointerRNA ptr_value)
int RNA_enum_from_name(const EnumPropertyItem *item, const char *name)
void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value)
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *prop, const char *propname, void *inarray, RawPropertyType intype, int inlen, int set)
size_t RNA_raw_type_sizeof(RawPropertyType type)
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
bool RNA_enum_identifier(const EnumPropertyItem *item, const int value, const char **r_identifier)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter)
bool RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
static std::optional< std::string > rna_pointer_as_string__bldata(PointerRNA *ptr)
static void rna_array_as_string_recursive(int type, void **buf_p, int totdim, const int *dim_size, std::stringstream &ss)
void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, bool value)
void RNA_property_boolean_get_array_at_most(PointerRNA *ptr, PropertyRNA *prop, bool *values, int values_num)
@ PROP_ACCELERATION
Definition RNA_types.hh:321
@ PROP_XYZ_LENGTH
Definition RNA_types.hh:327
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_COORDS
Definition RNA_types.hh:331
@ PROP_FILENAME
Definition RNA_types.hh:286
@ PROP_BYTESTRING
Definition RNA_types.hh:295
@ PROP_VELOCITY
Definition RNA_types.hh:320
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PROP_QUATERNION
Definition RNA_types.hh:324
@ PROP_DIRPATH
Definition RNA_types.hh:285
@ PROP_AXISANGLE
Definition RNA_types.hh:325
@ PROP_DIRECTION
Definition RNA_types.hh:319
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:329
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_RNAPTR
Definition RNA_types.hh:633
@ PARM_OUTPUT
Definition RNA_types.hh:632
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, ListBase *lb, IteratorSkipFunc skip)
PropertyRNA * RNA_struct_find_collection_property_check(PointerRNA &props, const char *name, const StructRNA *struct_type_check)
static void rna_property_collection_get_idp(CollectionPropertyIterator *iter)
IDProperty * rna_idproperty_find(PointerRNA *ptr, const char *name)
int RNA_property_string_maxlength(PropertyRNA *prop)
const char * BLT_translate_do_tooltip(const char *msgctxt, const char *msgid)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
char * RNA_property_string_get_default_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
static void rna_array_as_string(int type, int len, PointerRNA *ptr, PropertyRNA *prop, std::stringstream &ss)
IDProperty ** RNA_struct_idprops_p(PointerRNA *ptr)
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int index)
eStringPropertySearchFlag RNA_property_string_search_flag(PropertyRNA *prop)
static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
IDPropertyUIData * IDP_ui_data_ensure(IDProperty *prop)
Definition idprop.cc:2034
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
void RNA_collection_add(PointerRNA *ptr, const char *name, PointerRNA *r_value)
MINLINE int min_ii(int a, int b)
DynStr * BLI_dynstr_new() ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition BLI_dynstr.cc:39
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
void rna_idproperty_touch(IDProperty *idprop)
@ IDP_UI_DATA_TYPE_INT
@ IDP_UI_DATA_TYPE_BOOLEAN
int RNA_property_collection_raw_array(PointerRNA *ptr, PropertyRNA *prop, PropertyRNA *itemprop, bool set, RawArray *array)
bool RNA_struct_in_public_namespace(const StructRNA *type)
bool RNA_property_pointer_poll(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *value)
static const char * rna_property_type_identifier(PropertyType prop_type)
bool RNA_property_boolean_get_default(PointerRNA *ptr, PropertyRNA *prop)
float RNA_float_get(PointerRNA *ptr, const char *name)
void rna_property_rna_or_id_get(PropertyRNA *prop, PointerRNA *ptr, PropertyRNAOrID *r_prop_rna_or_id)
int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
void rna_iterator_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, void *data, size_t itemsize, int64_t length, bool free_ptr, IteratorSkipFunc skip)
void RNA_enum_set_identifier(bContext *C, PointerRNA *ptr, const char *name, const char *id)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
IDProperty * IDP_NewIDPArray(StringRef name) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:104
bool(*)(CollectionPropertyIterator *iter, void *data) IteratorSkipFunc
Definition RNA_types.hh:649
signed char int8_t
Definition BKE_text.h:76
static void rna_property_int_get_default_array_values(PointerRNA *ptr, IntPropertyRNA *iprop, int *r_values)
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
const ListBaseT< PropertyRNA > * RNA_function_defined_parameters(FunctionRNA *func)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
void RNA_parameter_list_free(ParameterList *parms)
void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL()
Definition idprop.cc:470
const char * RNA_struct_translation_context(const StructRNA *type)
bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
int RNA_collection_length(PointerRNA *ptr, const char *name)
void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
void RNA_property_enum_items_gettexted_all(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const EnumPropertyItem **r_item, int *r_totitem, bool *r_free)
void RNA_property_int_set_array_at_most(PointerRNA *ptr, PropertyRNA *prop, const int *values, int values_num)
IDOverrideLibrary * BKE_lib_override_library_get(Main *bmain, ID *id, ID *owner_id_hint, ID **r_owner_id)
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
std::string RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
bool RNA_property_editable_index(const PointerRNA *ptr, PropertyRNA *prop, const int index)
StructRegisterFunc RNA_struct_register(StructRNA *type)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
BlenderRNA RNA_blender_rna_get()
static PointerRNA property_pointer_get(PointerRNA *ptr, PropertyRNA *prop, const bool do_create)
bool RNA_property_is_unlink(PropertyRNA *prop)
_W64 int intptr_t
Definition BKE_text.h:119
void * RNA_property_py_data_get(PropertyRNA *prop)
#define RAW_GET(dtype, var, raw, a)
#define RAW_SET(dtype, raw, a, var)
#define RNA_MAGIC
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
Map< UString, StructRNA * > structs_map
PropBooleanArraySetFunc setarray
PropBooleanGetTransformFunc get_transform
PropBooleanSetTransformFunc set_transform
PropBooleanArraySetTransformFunc setarray_transform
PropBooleanSetFuncEx set_ex
PropBooleanArraySetFuncEx setarray_ex
PropBooleanGetFuncEx get_default
PropBooleanArrayGetFunc getarray
PropBooleanArrayGetFuncEx getarray_ex
PropBooleanGetFuncEx get_ex
PropBooleanArrayGetFuncEx get_default_array
PropBooleanArrayGetTransformFunc getarray_transform
union blender::CollectionPropertyIterator::@041041065315317147142203032351220146061055321205 internal
PropCollectionLookupStringFunc lookupstring
PropCollectionAssignIntFunc assignint
PropCollectionLookupIntFunc lookupint
PropCollectionLengthFunc length
CustomIDVectorSet< PropertyRNA *, PropertyRNAIdentifierGetter > * prop_lookup_set
ListBaseT< PropertyRNA > properties
const EnumPropertyItem * item
PropEnumSetTransformFunc set_transform
PropEnumGetTransformFunc get_transform
PropFloatArraySetFuncEx setarray_ex
PropFloatGetTransformFunc get_transform
PropFloatRangeFuncEx range_ex
PropFloatSetTransformFunc set_transform
PropFloatArraySetTransformFunc setarray_transform
PropFloatArrayGetFuncEx getarray_ex
PropFloatArraySetFunc setarray
PropFloatArrayGetFuncEx get_default_array
PropFloatArrayGetTransformFunc getarray_transform
PropFloatArrayGetFunc getarray
ListBaseT< struct IDProperty > group
Definition DNA_ID.h:133
IDPropertyUIDataEnumItem * enum_items
Definition DNA_ID.h:81
eIDPropertyFlag flag
Definition DNA_ID.h:151
eIDPropertyType type
Definition DNA_ID.h:145
IDPropertyData data
Definition DNA_ID.h:157
short flag
Definition DNA_ID.h:439
PropIntArrayGetFunc getarray
PropIntArrayGetTransformFunc getarray_transform
PropIntArrayGetFuncEx getarray_ex
PropIntArraySetFuncEx setarray_ex
PropIntArraySetFunc setarray
PropIntArraySetTransformFunc setarray_transform
PropertyScaleType ui_scale_type
PropIntGetTransformFunc get_transform
PropIntSetTransformFunc set_transform
PropIntArrayGetFuncEx get_default_array
T * data_as() const
Definition RNA_types.hh:139
bool has_type() const
Definition RNA_types.hh:180
StructRNA * type
Definition RNA_types.hh:63
Vector< AncestorPointerRNA, ANCESTOR_POINTERRNA_DEFAULT_SIZE > ancestors
Definition RNA_types.hh:90
bool has_owner_id() const
Definition RNA_types.hh:186
PropUINameFunc ui_description_func
PropertyFlagIntern flag_internal
ItemEditableFunc itemeditable
PropArrayLengthGetFunc getlength
const DeprecatedRNA * deprecated
unsigned int arraylength[RNA_MAX_ARRAY_DIMENSION]
PropertyOverrideFlag flag_override
PropertyPathTemplateType path_template_type
eStringPropertySearchFlag search_flag
PropStringGetTransformFunc get_transform
StringPropertyPathFilterFunc path_filter
PropStringSetTransformFunc set_transform
StringPropertySearchFunc search
PropStringLengthFuncEx length_ex
StructInstanceFunc instance
PropertyRNA * iteratorproperty
IDPropertiesFunc system_idproperties
Vector< std::unique_ptr< FunctionRNA > > functions
IDPropertiesFunc idproperties
const EnumPropertyItem * prop_tag_defines
StructRegisterFunc reg
StructRefineFunc refine
StructUnregisterFunc unreg
const char * translation_context
struct blender::IDPropertyTemplate::@100215251242210352227251277016155305041022127377 array
struct blender::IDPropertyTemplate::@116303142222164257205355242364302075230051143265 string
#define N_(msgid)