Blender V5.3
rna_rna.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 <cstdlib>
10
11#include <CLG_log.h>
12
13#include "BLT_translation.hh"
14
15#include "RNA_define.hh"
16#include "RNA_enum_types.hh"
17
18#include "rna_internal.hh"
19
20namespace blender {
21
22/* -------------------------------------------------------------------- */
25
26/* Reuse for dynamic types. */
27
29 {0, nullptr, 0, nullptr, nullptr},
30};
31
32/* Reuse for dynamic types with default value. */
33
35 {0, "DEFAULT", 0, "Default", ""},
36 {0, nullptr, 0, nullptr, nullptr},
37};
38
40
41/* -------------------------------------------------------------------- */
44
46 {PROP_BOOLEAN, "BOOLEAN", 0, "Boolean", ""},
47 {PROP_INT, "INT", 0, "Integer", ""},
48 {PROP_FLOAT, "FLOAT", 0, "Float", ""},
49 {PROP_STRING, "STRING", 0, "String", ""},
50 {PROP_ENUM, "ENUM", 0, "Enumeration", ""},
51 {PROP_POINTER, "POINTER", 0, "Pointer", ""},
52 {PROP_COLLECTION, "COLLECTION", 0, "Collection", ""},
53 {0, nullptr, 0, nullptr, nullptr},
54};
55
56/* Wraps multiple enums onto a single line in a way that is difficult to read.
57 * NOTE: these enums are split up based on their use in `bpy.props` Python module. */
58
59/* clang-format off */
60#define RNA_ENUM_PROPERTY_SUBTYPE_STRING_ITEMS \
61 {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""}, \
62 {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""}, \
63 {PROP_FILENAME, "FILE_NAME", 0, "File Name", ""}, \
64 {PROP_BYTESTRING, "BYTE_STRING", 0, "Byte String", ""}, \
65 {PROP_PASSWORD, "PASSWORD", 0, "Password", "A string that is displayed hidden ('********')"}
66
67#define RNA_ENUM_PROPERTY_SUBTYPE_NUMBER_ITEMS \
68 {PROP_PIXEL, "PIXEL", 0, "Pixel", "A distance on screen"}, \
69 {PROP_PIXEL_DIAMETER, "PIXEL_DIAMETER", 0, "Pixel", "A distance on screen, specifically representing a diameter value"}, \
70 {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""}, \
71 {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", "A percentage between 0 and 100"}, \
72 {PROP_FACTOR, "FACTOR", 0, "Factor", "A factor between 0.0 and 1.0"}, \
73 {PROP_MASS, "MASS", 0, "Mass", "A mass, based on scene unit settings"}, \
74 {PROP_ANGLE, "ANGLE", 0, "Angle", "A rotational value specified in radians"}, \
75 {PROP_TIME, "TIME", 0, "Time (Scene Relative)", \
76 "Time specified in frames, converted to seconds based on scene frame rate"}, \
77 {PROP_TIME_ABSOLUTE, "TIME_ABSOLUTE", 0, "Time (Absolute)", \
78 "Time specified in seconds, independent of the scene"}, \
79 {PROP_DISTANCE, "DISTANCE", 0, "Distance", "A distance between two points"}, \
80 {PROP_DISTANCE_DIAMETER, "DISTANCE_DIAMETER", 0, "Distance", "A distance between two points, specifically representing a diameter value"}, \
81 {PROP_DISTANCE_CAMERA, "DISTANCE_CAMERA", 0, "Camera Distance", ""}, \
82 {PROP_POWER, "POWER", 0, "Power", ""}, \
83 {PROP_TEMPERATURE, "TEMPERATURE", 0, "Temperature", ""}, \
84 {PROP_WAVELENGTH, "WAVELENGTH", 0, "Wavelength", ""}, \
85 {PROP_COLOR_TEMPERATURE, "COLOR_TEMPERATURE", 0, "Color Temperature", ""}, \
86 {PROP_FREQUENCY, "FREQUENCY", 0, "Frequency", ""}
87
88#define RNA_ENUM_PROPERTY_SUBTYPE_NUMBER_ARRAY_ITEMS \
89 {PROP_COLOR, "COLOR", 0, "Linear Color", "Color in the scene linear working color space"}, \
90 {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""}, \
91 {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""}, \
92 {PROP_VELOCITY, "VELOCITY", 0, "Velocity", ""}, \
93 {PROP_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""}, \
94 {PROP_MATRIX, "MATRIX", 0, "Matrix", ""}, \
95 {PROP_EULER, "EULER", 0, "Euler Angles", "Euler rotation angles in radians"}, \
96 {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", "Quaternion rotation (affects NLA blending)"}, \
97 {PROP_AXISANGLE, "AXISANGLE", 0, "Axis-Angle", "Angle and axis to rotate around"}, \
98 {PROP_XYZ, "XYZ", 0, "XYZ", ""}, \
99 {PROP_XYZ_LENGTH, "XYZ_LENGTH", 0, "XYZ Length", ""}, \
100 {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "sRGB Color", "Color in sRGB color space (mainly for user interface colors)"}, \
101 {PROP_COORDS, "COORDINATES", 0, "Coordinates", ""}, \
102 /* Boolean. */ \
103 {PROP_LAYER, "LAYER", 0, "Layer", ""}, \
104 {PROP_LAYER_MEMBER, "LAYER_MEMBER", 0, "Layer Member", ""}
105
106/* clang-format on */
107
110
111 {PROP_NONE, "NONE", 0, "None", ""},
112 {0, nullptr, 0, nullptr, nullptr},
113};
114
117
118 {PROP_NONE, "NONE", 0, "None", ""},
119 {0, nullptr, 0, nullptr, nullptr},
120};
121
124
125 {PROP_NONE, "NONE", 0, "None", ""},
126 {0, nullptr, 0, nullptr, nullptr},
127};
128
130 {PROP_NONE, "NONE", 0, "None", ""},
131
132 /* String. */
134
135 /* Number. */
137
138 /* Number array. */
140
141 {0, nullptr, 0, nullptr, nullptr},
142};
143
145 {PROP_UNIT_NONE, "NONE", 0, "None", ""},
146 {PROP_UNIT_LENGTH, "LENGTH", 0, "Length", ""},
147 {PROP_UNIT_AREA, "AREA", 0, "Area", ""},
148 {PROP_UNIT_VOLUME, "VOLUME", 0, "Volume", ""},
149 {PROP_UNIT_ROTATION, "ROTATION", 0, "Rotation", ""},
150 {PROP_UNIT_TIME, "TIME", 0, "Time (Scene Relative)", ""},
151 {PROP_UNIT_TIME_ABSOLUTE, "TIME_ABSOLUTE", 0, "Time (Absolute)", ""},
152 {PROP_UNIT_VELOCITY, "VELOCITY", 0, "Velocity", ""},
153 {PROP_UNIT_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""},
154 {PROP_UNIT_MASS, "MASS", 0, "Mass", ""},
155 {PROP_UNIT_CAMERA, "CAMERA", 0, "Camera", ""},
156 {PROP_UNIT_POWER, "POWER", 0, "Power", ""},
157 {PROP_UNIT_TEMPERATURE, "TEMPERATURE", 0, "Temperature", ""},
158 {PROP_UNIT_WAVELENGTH, "WAVELENGTH", 0, "Wavelength", ""},
159 {PROP_UNIT_COLOR_TEMPERATURE, "COLOR_TEMPERATURE", 0, "Color Temperature", ""},
160 {PROP_UNIT_FREQUENCY, "FREQUENCY", 0, "Frequency", ""},
161 {0, nullptr, 0, nullptr, nullptr},
162};
163
164/* Descriptions for rna_enum_property_flag_items and rna_enum_property_flag_enum_items. */
165static constexpr auto PROP_READ_ONLY_DESCR = "When set, the property cannot be edited";
166static constexpr auto PROP_HIDDEN_DESCR =
167 "For operators: hide from places in the user interface where Blender would add the property "
168 "automatically, like Adjust Last Operation. Also this property is not written to presets.";
169static constexpr auto PROP_SKIP_SAVE_DESCR =
170 "For operators: the value of this property will not be remembered between invocations of the "
171 "operator; instead, each invocation will start by using the default value. Also this "
172 "property is not written to presets.";
173static constexpr auto PROP_SKIP_PRESET_DESCR = "Do not write in presets";
174static constexpr auto PROP_ANIMATABLE_DESCR = "";
175static constexpr auto PROP_LIB_EXCEPTION_DESCR =
176 "This property can be edited, even when it is used on linked data (which normally is "
177 "read-only). Note that edits to the property will not be saved to the blend file.";
178static constexpr auto PROP_PROPORTIONAL_DESCR = "";
179static constexpr auto PROP_TEXTEDIT_UPDATE_DESCR = "";
180static constexpr auto PROP_PATH_OUTPUT_DESCR = "";
181static constexpr auto PROP_PATH_RELATIVE_DESCR =
182 "This path supports relative prefix \"//\" which is expanded the directory "
183 "where the current \".blend\" file is located.";
185 "This path supports the \"{variable_name}\" template syntax, which substitutes the "
186 "value of the referenced variable in place of the template expression";
187static constexpr auto PROP_ENUM_FLAG_DESCR = "";
188
190 /* NOTE: This is used only in the `bpy.props` module to define runtime RNA properties.
191 * The value of this 'READ_ONLY' enum item is logically inverted compared to the
192 * `PROP_EDITABLE` used everywhere else in RNA-related code.
193 *
194 * This inversion logic is handled by the bpy property definition code (see
195 * #bpy_prop_assign_flag), and does not affect any other code area.
196 *
197 * This special handling is done to allow python property definitions to create by default
198 * editable properties, without having to specify the `options={'EDITABLE', ...}` parameter all
199 * the time.
200 */
201 {PROP_EDITABLE, "READ_ONLY", 0, "Read Only", PROP_READ_ONLY_DESCR},
202
203 {PROP_HIDDEN, "HIDDEN", 0, "Hidden", PROP_HIDDEN_DESCR},
204 {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", PROP_SKIP_SAVE_DESCR},
205 {PROP_SKIP_PRESET, "SKIP_PRESET", 0, "Skip Preset", PROP_SKIP_PRESET_DESCR},
206 {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animatable", PROP_ANIMATABLE_DESCR},
207 {PROP_LIB_EXCEPTION, "LIBRARY_EDITABLE", 0, "Library Editable", PROP_LIB_EXCEPTION_DESCR},
209 "PROPORTIONAL",
210 0,
211 "Adjust values proportionally to each other",
214 "TEXTEDIT_UPDATE",
215 0,
216 "Update on every keystroke in textedit 'mode'",
218 {PROP_PATH_OUTPUT, "OUTPUT_PATH", 0, "Output Path", PROP_PATH_OUTPUT_DESCR},
220 "PATH_SUPPORTS_BLEND_RELATIVE",
221 0,
222 "Relative Path Support",
225 "SUPPORTS_TEMPLATES",
226 0,
227 "Variable expression support",
229 {0, nullptr, 0, nullptr, nullptr},
230};
231
234 /* NOTE: This is used only in the `bpy.props` module to define runtime RNA properties.
235 * The value of this 'READ_ONLY' enum item is logically inverted compared to the
236 * `PROP_EDITABLE` used everywhere else in RNA-related code.
237 *
238 * This inversion logic is handled by the bpy property definition code (see
239 * #bpy_prop_assign_flag), and does not affect any other code area.
240 *
241 * This special handling is done to allow python property definitions to create by default
242 * editable properties, without having to specify the `options={'EDITABLE', ...}` parameter all
243 * the time.
244 */
245 {PROP_EDITABLE, "READ_ONLY", 0, "Read Only", PROP_READ_ONLY_DESCR},
246
247 {PROP_HIDDEN, "HIDDEN", 0, "Hidden", PROP_HIDDEN_DESCR},
248 {PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", PROP_SKIP_SAVE_DESCR},
249 {PROP_ANIMATABLE, "ANIMATABLE", 0, "Animatable", PROP_ANIMATABLE_DESCR},
250 {PROP_LIB_EXCEPTION, "LIBRARY_EDITABLE", 0, "Library Editable", PROP_LIB_EXCEPTION_DESCR},
251 {PROP_ENUM_FLAG, "ENUM_FLAG", 0, "Enum Flag", PROP_ENUM_FLAG_DESCR},
252 {0, nullptr, 0, nullptr, nullptr},
253};
254
257 "LIBRARY_OVERRIDABLE",
258 0,
259 "Library Overridable",
260 "Make that property editable in library overrides of linked data-blocks.\n"
261 "NOTE: For a property to be overridable, its whole chain of parent properties must also be "
262 "defined as overridable"};
263
268
272 "NO_PROPERTY_NAME",
273 0,
274 "No Name",
275 "Do not use the names of the items, only their indices in the collection"},
277 "USE_INSERTION",
278 0,
279 "Use Insertion",
280 "Allow users to add new items in that collection in library overrides"},
281 {0, nullptr, 0, nullptr, nullptr},
282};
283
285 {PROP_STRING_SEARCH_SORT, "SORT", 0, "Sort Search Results", ""},
287 "SUGGESTION",
288 0,
289 "Suggestion",
290 "Search results are suggestions (other values may be entered)"},
291
292 {0, nullptr, 0, nullptr, nullptr},
293};
294
296
297} // namespace blender
298
299#ifdef RNA_RUNTIME
300
301# include "BLI_ghash.hh"
302# include "BLI_listbase.hh"
303# include "BLI_string.hh"
304
305# include "MEM_guardedalloc.h"
306
307# include "BKE_idprop.hh"
308# include "BKE_lib_override.hh"
309
310# include "RNA_path.hh"
311
312# include <optional>
313# include <string>
314
315# include <fmt/format.h>
316
317namespace blender {
318
319static CLG_LogRef LOG_COMPARE_OVERRIDE = {"rna.rna_compare_override"};
320
321/* -------------------------------------------------------------------- */
324
325/* Struct */
326
327static void rna_Struct_identifier_get(PointerRNA *ptr, char *value)
328{
329 strcpy(value, (static_cast<StructRNA *>(ptr->data))->identifier.c_str());
330}
331
332static int rna_Struct_identifier_length(PointerRNA *ptr)
333{
334 return static_cast<StructRNA *>(ptr->data)->identifier.size();
335}
336
337static void rna_Struct_description_get(PointerRNA *ptr, char *value)
338{
339 strcpy(value, (static_cast<StructRNA *>(ptr->data))->description);
340}
341
342static int rna_Struct_description_length(PointerRNA *ptr)
343{
344 return strlen((static_cast<StructRNA *>(ptr->data))->description);
345}
346
347static void rna_Struct_name_get(PointerRNA *ptr, char *value)
348{
349 strcpy(value, (static_cast<StructRNA *>(ptr->data))->name);
350}
351
352static int rna_Struct_name_length(PointerRNA *ptr)
353{
354 return strlen((static_cast<StructRNA *>(ptr->data))->name);
355}
356
357static void rna_Struct_translation_context_get(PointerRNA *ptr, char *value)
358{
359 strcpy(value, (static_cast<StructRNA *>(ptr->data))->translation_context);
360}
361
362static int rna_Struct_translation_context_length(PointerRNA *ptr)
363{
364 return strlen((static_cast<StructRNA *>(ptr->data))->translation_context);
365}
366
367static PointerRNA rna_Struct_base_get(PointerRNA *ptr)
368{
370 nullptr, RNA_Struct, (static_cast<StructRNA *>(ptr->data))->base);
371}
372
373static PointerRNA rna_Struct_nested_get(PointerRNA *ptr)
374{
376 nullptr, RNA_Struct, (static_cast<StructRNA *>(ptr->data))->nested);
377}
378
379static PointerRNA rna_Struct_name_property_get(PointerRNA *ptr)
380{
382 nullptr, RNA_Property, (static_cast<StructRNA *>(ptr->data))->nameproperty);
383}
384
385/* Struct property iteration. This is quite complicated, the purpose is to
386 * iterate over properties of all inheritance levels, and for each struct to
387 * also iterator over id properties not known by RNA. */
388
389static bool rna_idproperty_known(CollectionPropertyIterator *iter, void *data)
390{
391 IDProperty *idprop = static_cast<IDProperty *>(data);
392 PropertyRNA *prop;
393 StructRNA *ptype = iter->builtin_parent.type;
394
395 /* Function to skip any id properties that are already known by RNA,
396 * for the second loop where we go over unknown id properties.
397 *
398 * Note that only dynamically-defined RNA properties (the ones actually using IDProperties as
399 * storage back-end) should be checked here. If a custom property is named the same as a 'normal'
400 * RNA property, they are different data. */
401 const UString idprop_name(idprop->name);
402 do {
403 for (prop = ptype->cont.properties.first(); prop; prop = prop->next) {
404 if ((prop->flag_internal & PROP_INTERN_BUILTIN) == 0 &&
405 (prop->flag & PROP_IDPROPERTY) != 0 && prop->identifier == idprop_name)
406 {
407 return true;
408 }
409 }
410 } while ((ptype = ptype->base));
411
412 return false;
413}
414
415static bool rna_property_builtin(CollectionPropertyIterator * /*iter*/, void *data)
416{
417 PropertyRNA *prop = static_cast<PropertyRNA *>(data);
418
419 /* function to skip builtin rna properties */
420
421 return (prop->flag_internal & PROP_INTERN_BUILTIN) != 0;
422}
423
424static void rna_inheritance_next_level_restart(CollectionPropertyIterator *iter,
425 PointerRNA *ptr,
426 IteratorSkipFunc skip)
427{
428 /* RNA struct inheritance */
429 while (!iter->valid && iter->level > 0) {
430 StructRNA *srna;
431 int i;
432
433 srna = static_cast<StructRNA *>(iter->parent.data);
434 iter->level--;
435 for (i = iter->level; i > 0; i--) {
436 srna = srna->base;
437 }
438
440
441 rna_iterator_listbase_begin(iter, ptr, &srna->cont.properties, skip);
442 }
443}
444
445static void rna_inheritance_properties_listbase_begin(CollectionPropertyIterator *iter,
446 PointerRNA *ptr,
447 ListBase *lb,
448 IteratorSkipFunc skip)
449{
450 rna_iterator_listbase_begin(iter, ptr, lb, skip);
451 rna_inheritance_next_level_restart(iter, ptr, skip);
452}
453
454static void rna_inheritance_properties_listbase_next(CollectionPropertyIterator *iter,
455 IteratorSkipFunc skip)
456{
458 rna_inheritance_next_level_restart(iter, &iter->parent, skip);
459}
460
461static void rna_Struct_properties_next(CollectionPropertyIterator *iter)
462{
463 ListBaseIterator *internal = &iter->internal.listbase;
464 IDProperty *group;
465
466 if (internal->flag) {
467 /* id properties */
469 }
470 else {
471 /* regular properties */
472 rna_inheritance_properties_listbase_next(iter, rna_property_builtin);
473
474 /* Try IDProperties (i.e. custom data).
475 *
476 * NOTE: System IDProperties should not need to be handled here, as they are expected to have a
477 * valid (runtime-defined) RNA property to wrap them, which will have been processed above as
478 * part of `rna_inheritance_properties_listbase_next`. */
479 if (!iter->valid) {
480 group = RNA_struct_idprops(&iter->builtin_parent, 0);
481
482 if (group) {
484 rna_iterator_listbase_begin(iter, &iter->parent, &group->data.group, rna_idproperty_known);
485 internal = &iter->internal.listbase;
486 internal->flag = 1;
487 }
488 }
489 }
490}
491
492static void rna_Struct_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
493{
494 StructRNA *srna;
495
496 /* here ptr->data should always be the same as iter->parent.type */
497 srna = static_cast<StructRNA *>(ptr->data);
498
499 while (srna->base) {
500 iter->level++;
501 srna = srna->base;
502 }
503
504 rna_inheritance_properties_listbase_begin(
505 iter, ptr, &srna->cont.properties, rna_property_builtin);
506}
507
508static PointerRNA rna_Struct_properties_get(CollectionPropertyIterator *iter)
509{
510 ListBaseIterator *internal = &iter->internal.listbase;
511
512 /* we return either PropertyRNA* or IDProperty*, the rna_access.cc
513 * functions can handle both as PropertyRNA* with some tricks */
514 return RNA_pointer_create_discrete(nullptr, RNA_Property, internal->link);
515}
516
517static Vector<StructRNA *> struct_hierarchy_get(StructRNA *srna)
518{
520 for (StructRNA *srna_iter = srna; srna_iter != nullptr; srna_iter = srna_iter->base) {
521 types.append(srna_iter);
522 }
523 std::reverse(types.begin(), types.end());
524 return types;
525}
526
527static void rna_Struct_functions_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
528{
529 /* Collect all functions of struct and its base structs, with base struct functions first. */
530 Vector<FunctionRNA *> functions;
531 for (StructRNA *srna : struct_hierarchy_get(ptr->data_as<StructRNA>())) {
532 for (std::unique_ptr<FunctionRNA> &func : srna->functions) {
533 if ((func->flag & FUNC_BUILTIN) != 0) {
534 continue;
535 }
536 functions.append(func.get());
537 }
538 }
539 VectorData data = functions.release();
540 rna_iterator_array_begin(iter, ptr, data.data, sizeof(FunctionRNA *), data.size, true, nullptr);
541}
542
543static PointerRNA rna_Struct_functions_get(CollectionPropertyIterator *iter)
544{
545 ArrayIterator *internal = &iter->internal.array;
546
547 /* we return either PropertyRNA* or IDProperty*, the rna_access.cc
548 * functions can handle both as PropertyRNA* with some tricks */
550 nullptr, RNA_Function, *reinterpret_cast<FunctionRNA **>(internal->ptr));
551}
552
553static void rna_Struct_property_tags_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
554{
555 /* here ptr->data should always be the same as iter->parent.type */
556 StructRNA *srna = static_cast<StructRNA *>(ptr->data);
557 const EnumPropertyItem *tag_defines = RNA_struct_property_tag_defines(srna);
558 uint tag_count = tag_defines ? RNA_enum_items_count(tag_defines) : 0;
559
561 iter, ptr, (void *)tag_defines, sizeof(EnumPropertyItem), tag_count, 0, nullptr);
562}
563
564/* Builtin properties iterator re-uses the Struct properties iterator, only
565 * difference is that we need to set the ptr data to the type of the struct
566 * whose properties we want to iterate over. */
567
569{
570 PointerRNA newptr;
571
572 /* we create a new pointer with the type as the data */
573 newptr.type = RNA_Struct;
574 newptr.data = ptr->type;
575
576 if (ptr->type->flag & STRUCT_ID) {
577 newptr.owner_id = static_cast<ID *>(ptr->data);
578 }
579 else {
580 newptr.owner_id = nullptr;
581 }
582
583 iter->parent = newptr;
584 iter->builtin_parent = *ptr;
585
586 rna_Struct_properties_begin(iter, &newptr);
587}
588
590{
591 rna_Struct_properties_next(iter);
592}
593
595{
596 return rna_Struct_properties_get(iter);
597}
598
599bool rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
600{
602 if (!prop) {
603 *r_ptr = {};
604 return false;
605 }
606 *r_ptr = {nullptr, RNA_Property, prop};
607 return true;
608}
609
611{
612 return RNA_pointer_create_discrete(nullptr, RNA_Struct, ptr->type);
613}
614
615/* Property */
616
617static StructRNA *rna_Property_refine(PointerRNA *ptr)
618{
619 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
620
621 switch (RNA_property_type(prop)) {
622 case PROP_BOOLEAN:
623 return RNA_BoolProperty;
624 case PROP_INT:
625 return RNA_IntProperty;
626 case PROP_FLOAT:
627 return RNA_FloatProperty;
628 case PROP_STRING:
629 return RNA_StringProperty;
630 case PROP_ENUM:
631 return RNA_EnumProperty;
632 case PROP_POINTER:
633 return RNA_PointerProperty;
634 case PROP_COLLECTION:
635 return RNA_CollectionProperty;
636 default:
637 return RNA_Property;
638 }
639}
640
641static void rna_Property_identifier_get(PointerRNA *ptr, char *value)
642{
643 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
644 strcpy(value, RNA_property_identifier(prop));
645}
646
647static int rna_Property_identifier_length(PointerRNA *ptr)
648{
649 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
650 return strlen(RNA_property_identifier(prop));
651}
652
653static void rna_Property_name_get(PointerRNA *ptr, char *value)
654{
655 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
656 const char *name = RNA_property_ui_name_raw(prop);
657 strcpy(value, name ? name : "");
658}
659
660static int rna_Property_name_length(PointerRNA *ptr)
661{
662 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
663 const char *name = RNA_property_ui_name_raw(prop);
664 return name ? strlen(name) : 0;
665}
666
667static void rna_Property_description_get(PointerRNA *ptr, char *value)
668{
669 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
670 const char *description = RNA_property_ui_description_raw(prop);
671 strcpy(value, description ? description : "");
672}
673static int rna_Property_description_length(PointerRNA *ptr)
674{
675 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
676 const char *description = RNA_property_ui_description_raw(prop);
677 return description ? strlen(description) : 0;
678}
679
680static void rna_Property_translation_context_get(PointerRNA *ptr, char *value)
681{
682 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
683 strcpy(value, RNA_property_translation_context(prop));
684}
685
686static int rna_Property_translation_context_length(PointerRNA *ptr)
687{
688 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
689 return strlen(RNA_property_translation_context(prop));
690}
691
692static int rna_Property_type_get(PointerRNA *ptr)
693{
694 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
695 return RNA_property_type(prop);
696}
697
698static int rna_Property_subtype_get(PointerRNA *ptr)
699{
700 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
701 return RNA_property_subtype(prop);
702}
703
704static PointerRNA rna_Property_srna_get(PointerRNA *ptr)
705{
706 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
707 prop = rna_ensure_property(prop);
708 return RNA_pointer_create_discrete(nullptr, RNA_Struct, prop->srna);
709}
710
711static int rna_Property_unit_get(PointerRNA *ptr)
712{
713 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
714 return RNA_property_unit(prop);
715}
716
717static int rna_Property_icon_get(PointerRNA *ptr)
718{
719 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
720 return RNA_property_ui_icon(prop);
721}
722
723static bool rna_Property_readonly_get(PointerRNA *ptr)
724{
725 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
726
727 /* don't use this because it will call functions that check the internal
728 * data for introspection we only need to know if it can be edited so the
729 * flag is better for this */
730 // return RNA_property_editable(ptr, prop);
731 return (prop->flag & PROP_EDITABLE) == 0;
732}
733
734static bool rna_Property_animatable_get(PointerRNA *ptr)
735{
736 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
737
738 return (prop->flag & PROP_ANIMATABLE) != 0;
739}
740
741static bool rna_Property_overridable_get(PointerRNA *ptr)
742{
743 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
744
746
747 return idprop != nullptr ? (idprop->flag & IDP_FLAG_OVERRIDABLE_LIBRARY) != 0 :
748 (prop->flag_override & PROPOVERRIDE_OVERRIDABLE_LIBRARY) != 0;
749}
750
751static bool rna_Property_use_output_get(PointerRNA *ptr)
752{
753 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
754 return (prop->flag_parameter & PARM_OUTPUT) != 0;
755}
756
757static bool rna_Property_is_required_get(PointerRNA *ptr)
758{
759 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
760 return (prop->flag_parameter & PARM_REQUIRED) != 0;
761}
762
763static bool rna_Property_is_argument_optional_get(PointerRNA *ptr)
764{
765 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
766 return (prop->flag_parameter & PARM_PYFUNC_REGISTER_OPTIONAL) != 0;
767}
768
769static bool rna_Property_is_never_none_get(PointerRNA *ptr)
770{
771 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
772 return (prop->flag & PROP_NEVER_NULL) != 0;
773}
774
775static bool rna_Property_is_hidden_get(PointerRNA *ptr)
776{
777 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
778 return (prop->flag & PROP_HIDDEN) != 0;
779}
780
781static bool rna_Property_is_skip_save_get(PointerRNA *ptr)
782{
783 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
784 return (prop->flag & PROP_SKIP_SAVE) != 0;
785}
786
787static bool rna_Property_is_skip_preset_get(PointerRNA *ptr)
788{
789 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
790 return (prop->flag & (PROP_SKIP_SAVE | PROP_HIDDEN | PROP_SKIP_PRESET)) != 0;
791}
792
793static bool rna_Property_is_enum_flag_get(PointerRNA *ptr)
794{
795 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
796 return (prop->flag & PROP_ENUM_FLAG) != 0;
797}
798
799static bool rna_Property_is_library_editable_flag_get(PointerRNA *ptr)
800{
801 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
802 return (prop->flag & PROP_LIB_EXCEPTION) != 0;
803}
804
805static bool rna_Property_is_path_output_flag_get(PointerRNA *ptr)
806{
807 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
808 return (prop->flag & PROP_PATH_OUTPUT) != 0;
809}
810
811static bool rna_Property_is_path_supports_blend_relative_flag_get(PointerRNA *ptr)
812{
813 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
814 return (prop->flag & PROP_PATH_SUPPORTS_BLEND_RELATIVE) != 0;
815}
816
817static bool rna_Property_is_path_supports_templates_flag_get(PointerRNA *ptr)
818{
819 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
820 return (prop->flag & PROP_PATH_SUPPORTS_TEMPLATES) != 0;
821}
822
823static int rna_Property_tags_get(PointerRNA *ptr)
824{
825 return RNA_property_tags(static_cast<PropertyRNA *>(ptr->data));
826}
827
828static const EnumPropertyItem *rna_Property_tags_itemf(bContext * /*C*/,
829 PointerRNA *ptr,
830 PropertyRNA * /*prop*/,
831 bool *r_free)
832{
833 PropertyRNA *this_prop = static_cast<PropertyRNA *>(ptr->data);
834 const StructRNA *srna = RNA_property_pointer_type(ptr, this_prop);
835 EnumPropertyItem *prop_tags;
836 EnumPropertyItem tmp = {0, "", 0, "", ""};
837 int totitem = 0;
838
839 for (const EnumPropertyItem *struct_tags = RNA_struct_property_tag_defines(srna);
840 struct_tags != nullptr && struct_tags->identifier != nullptr;
841 struct_tags++)
842 {
843 memcpy(&tmp, struct_tags, sizeof(tmp));
844 RNA_enum_item_add(&prop_tags, &totitem, &tmp);
845 }
846 RNA_enum_item_end(&prop_tags, &totitem);
847 *r_free = true;
848
849 return prop_tags;
850}
851
852static int rna_Property_array_length_get(PointerRNA *ptr)
853{
854 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
855 prop = rna_ensure_property(prop);
856 return prop->totarraylength;
857}
858
859static void rna_Property_array_dimensions_get(PointerRNA *ptr,
860 int dimensions[RNA_MAX_ARRAY_DIMENSION])
861{
862 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
863 prop = rna_ensure_property(prop);
864
865 if (prop->arraydimension > 1) {
866 for (int i = RNA_MAX_ARRAY_DIMENSION; i--;) {
867 dimensions[i] = (i >= prop->arraydimension) ? 0 : prop->arraylength[i];
868 }
869 }
870 else {
871 memset(dimensions, 0, sizeof(*dimensions) * RNA_MAX_ARRAY_DIMENSION);
872 dimensions[0] = prop->totarraylength;
873 }
874}
875
876static bool rna_Property_is_registered_get(PointerRNA *ptr)
877{
878 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
879 return (prop->flag & PROP_REGISTER) != 0;
880}
881
882static bool rna_Property_is_registered_optional_get(PointerRNA *ptr)
883{
884 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
885 return (prop->flag & PROP_REGISTER_OPTIONAL) != 0;
886}
887
888static bool rna_Property_is_runtime_get(PointerRNA *ptr)
889{
890 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
891 return RNA_property_is_runtime(prop);
892}
893
894static bool rna_Property_is_deprecated_get(PointerRNA *ptr)
895{
896 const PropertyRNA *prop = static_cast<const PropertyRNA *>(ptr->data);
897 return RNA_property_deprecated(prop) != nullptr;
898}
899
900static int rna_Property_deprecated_note_length(PointerRNA *ptr)
901{
902 const PropertyRNA *prop = static_cast<const PropertyRNA *>(ptr->data);
903 if (const DeprecatedRNA *deprecated = RNA_property_deprecated(prop)) {
904 return strlen(deprecated->note);
905 }
906 return 0;
907}
908
909static void rna_Property_deprecated_note_get(PointerRNA *ptr, char *value)
910{
911 const PropertyRNA *prop = static_cast<const PropertyRNA *>(ptr->data);
912 if (const DeprecatedRNA *deprecated = RNA_property_deprecated(prop)) {
913 strcpy(value, deprecated->note);
914 }
915 else {
916 value[0] = '\0';
917 }
918}
919
920static void rna_Property_deprecated_version_get(PointerRNA *ptr, int *value)
921{
922 const PropertyRNA *prop = static_cast<const PropertyRNA *>(ptr->data);
923 short version = 0;
924 if (const DeprecatedRNA *deprecated = RNA_property_deprecated(prop)) {
925 version = deprecated->version;
926 }
927 ARRAY_SET_ITEMS(value, version / 100, version % 100, 0);
928}
929
930static void rna_Property_deprecated_removal_version_get(PointerRNA *ptr, int *value)
931{
932 const PropertyRNA *prop = static_cast<const PropertyRNA *>(ptr->data);
933 short version = 0;
934 if (const DeprecatedRNA *deprecated = RNA_property_deprecated(prop)) {
935 version = deprecated->removal_version;
936 }
937
938 ARRAY_SET_ITEMS(value, version / 100, version % 100, 0);
939}
940
941static bool rna_BoolProperty_default_get(PointerRNA *ptr)
942{
943 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
944 prop = rna_ensure_property(prop);
945 return (reinterpret_cast<BoolPropertyRNA *>(prop))->defaultvalue;
946}
947
948static int rna_IntProperty_default_get(PointerRNA *ptr)
949{
950 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
951 prop = rna_ensure_property(prop);
952 return (reinterpret_cast<IntPropertyRNA *>(prop))->defaultvalue;
953}
954/* int/float/bool */
955static int rna_NumberProperty_default_array_get_length(const PointerRNA *ptr,
957{
958 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
959 prop = rna_ensure_property(prop);
960
961 length[0] = prop->totarraylength;
962
963 return length[0];
964}
965static bool rna_NumberProperty_is_array_get(PointerRNA *ptr)
966{
967 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
968
969 return RNA_property_array_check(prop);
970}
971
972static void rna_IntProperty_default_array_get(PointerRNA *ptr, int *values)
973{
974 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
975 prop = rna_ensure_property(prop);
976 if (prop->totarraylength > 0) {
977 PointerRNA null_ptr = {};
978 RNA_property_int_get_default_array(&null_ptr, prop, values);
979 }
980}
981
982static void rna_BoolProperty_default_array_get(PointerRNA *ptr, bool *values)
983{
984 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
985 prop = rna_ensure_property(prop);
986 if (prop->totarraylength > 0) {
987 PointerRNA null_ptr = {};
988 RNA_property_boolean_get_default_array(&null_ptr, prop, values);
989 }
990}
991
992static void rna_FloatProperty_default_array_get(PointerRNA *ptr, float *values)
993{
994 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
995 prop = rna_ensure_property(prop);
996 if (prop->totarraylength > 0) {
997 PointerRNA null_ptr = {};
998 RNA_property_float_get_default_array(&null_ptr, prop, values);
999 }
1000}
1001
1002static int rna_IntProperty_hard_min_get(PointerRNA *ptr)
1003{
1004 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1005 prop = rna_ensure_property(prop);
1006 return (reinterpret_cast<IntPropertyRNA *>(prop))->hardmin;
1007}
1008
1009static int rna_IntProperty_hard_max_get(PointerRNA *ptr)
1010{
1011 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1012 prop = rna_ensure_property(prop);
1013 return (reinterpret_cast<IntPropertyRNA *>(prop))->hardmax;
1014}
1015
1016static int rna_IntProperty_soft_min_get(PointerRNA *ptr)
1017{
1018 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1019 prop = rna_ensure_property(prop);
1020 return (reinterpret_cast<IntPropertyRNA *>(prop))->softmin;
1021}
1022
1023static int rna_IntProperty_soft_max_get(PointerRNA *ptr)
1024{
1025 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1026 prop = rna_ensure_property(prop);
1027 return (reinterpret_cast<IntPropertyRNA *>(prop))->softmax;
1028}
1029
1030static int rna_IntProperty_step_get(PointerRNA *ptr)
1031{
1032 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1033 prop = rna_ensure_property(prop);
1034 return (reinterpret_cast<IntPropertyRNA *>(prop))->step;
1035}
1036
1037static float rna_FloatProperty_default_get(PointerRNA *ptr)
1038{
1039 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1040 prop = rna_ensure_property(prop);
1041 return (reinterpret_cast<FloatPropertyRNA *>(prop))->defaultvalue;
1042}
1043static float rna_FloatProperty_hard_min_get(PointerRNA *ptr)
1044{
1045 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1046 prop = rna_ensure_property(prop);
1047 return (reinterpret_cast<FloatPropertyRNA *>(prop))->hardmin;
1048}
1049
1050static float rna_FloatProperty_hard_max_get(PointerRNA *ptr)
1051{
1052 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1053 prop = rna_ensure_property(prop);
1054 return (reinterpret_cast<FloatPropertyRNA *>(prop))->hardmax;
1055}
1056
1057static float rna_FloatProperty_soft_min_get(PointerRNA *ptr)
1058{
1059 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1060 prop = rna_ensure_property(prop);
1061 return (reinterpret_cast<FloatPropertyRNA *>(prop))->softmin;
1062}
1063
1064static float rna_FloatProperty_soft_max_get(PointerRNA *ptr)
1065{
1066 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1067 prop = rna_ensure_property(prop);
1068 return (reinterpret_cast<FloatPropertyRNA *>(prop))->softmax;
1069}
1070
1071static float rna_FloatProperty_step_get(PointerRNA *ptr)
1072{
1073 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1074 prop = rna_ensure_property(prop);
1075 return (reinterpret_cast<FloatPropertyRNA *>(prop))->step;
1076}
1077
1078static int rna_FloatProperty_precision_get(PointerRNA *ptr)
1079{
1080 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1081 prop = rna_ensure_property(prop);
1082 return (reinterpret_cast<FloatPropertyRNA *>(prop))->precision;
1083}
1084
1085static void rna_StringProperty_default_get(PointerRNA *ptr, char *value)
1086{
1087 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1088 prop = rna_ensure_property(prop);
1089 strcpy(value, (reinterpret_cast<StringPropertyRNA *>(prop))->defaultvalue);
1090}
1091static int rna_StringProperty_default_length(PointerRNA *ptr)
1092{
1093 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1094 prop = rna_ensure_property(prop);
1095 return strlen((reinterpret_cast<StringPropertyRNA *>(prop))->defaultvalue);
1096}
1097
1098static int rna_StringProperty_max_length_get(PointerRNA *ptr)
1099{
1100 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1101 prop = rna_ensure_property(prop);
1102 return (reinterpret_cast<StringPropertyRNA *>(prop))->maxlength;
1103}
1104
1105static const EnumPropertyItem *rna_EnumProperty_default_itemf(bContext *C,
1106 PointerRNA *ptr,
1107 PropertyRNA *prop_parent,
1108 bool *r_free)
1109{
1110 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1111 EnumPropertyRNA *eprop;
1112
1113 prop = rna_ensure_property(prop);
1114 eprop = reinterpret_cast<EnumPropertyRNA *>(prop);
1115
1116 /* incompatible default attributes */
1117 if ((prop_parent->flag & PROP_ENUM_FLAG) != (prop->flag & PROP_ENUM_FLAG)) {
1119 }
1120
1121 if ((eprop->item_fn == nullptr) || (eprop->item_fn == rna_EnumProperty_default_itemf) ||
1122 (ptr->type == RNA_EnumProperty) || (C == nullptr))
1123 {
1124 if (eprop->item) {
1125 return eprop->item;
1126 }
1127 }
1128
1129 return eprop->item_fn(C, ptr, prop, r_free);
1130}
1131
1132/* XXX: not sure this is needed? */
1133static int rna_EnumProperty_default_get(PointerRNA *ptr)
1134{
1135 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1136 prop = rna_ensure_property(prop);
1137 return (reinterpret_cast<EnumPropertyRNA *>(prop))->defaultvalue;
1138}
1139
1140static bool rna_enum_check_separator(CollectionPropertyIterator * /*iter*/, void *data)
1141{
1142 EnumPropertyItem *item = static_cast<EnumPropertyItem *>(data);
1143
1144 return (item->identifier[0] == 0);
1145}
1146
1147static void rna_EnumProperty_items_begin_impl(CollectionPropertyIterator *iter,
1148 PointerRNA *ptr,
1149 IteratorSkipFunc skip_fn)
1150{
1151 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1152 // EnumPropertyRNA *eprop; /* UNUSED */
1153 const EnumPropertyItem *item = nullptr;
1154 int totitem;
1155 bool free;
1156
1157 prop = rna_ensure_property(prop);
1158 // eprop = (EnumPropertyRNA *)prop;
1159
1161 ptr,
1162 prop,
1163 iter->prop->identifier == "enum_items_static"_ustr,
1164 &item,
1165 &totitem,
1166 &free);
1168 iter, ptr, (void *)item, sizeof(EnumPropertyItem), totitem, free, skip_fn);
1169}
1170
1171static void rna_EnumProperty_items_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1172{
1173 rna_EnumProperty_items_begin_impl(iter, ptr, rna_enum_check_separator);
1174}
1175
1176static void rna_EnumProperty_items_ui_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1177{
1178 /* No skip-function, include all "UI" items. */
1179 rna_EnumProperty_items_begin_impl(iter, ptr, nullptr);
1180}
1181
1182static void rna_EnumPropertyItem_identifier_get(PointerRNA *ptr, char *value)
1183{
1184 strcpy(value, (static_cast<EnumPropertyItem *>(ptr->data))->identifier);
1185}
1186
1187static int rna_EnumPropertyItem_identifier_length(PointerRNA *ptr)
1188{
1189 return strlen((static_cast<EnumPropertyItem *>(ptr->data))->identifier);
1190}
1191
1192static void rna_EnumPropertyItem_name_get(PointerRNA *ptr, char *value)
1193{
1194 const EnumPropertyItem *eprop = static_cast<const EnumPropertyItem *>(ptr->data);
1195 /* Name can be nullptr in the case of separators
1196 * which are exposed via `_bpy.rna_enum_items_static`. */
1197 if (eprop->name) {
1198 strcpy(value, eprop->name);
1199 }
1200 else {
1201 value[0] = '\0';
1202 }
1203}
1204
1205static int rna_EnumPropertyItem_name_length(PointerRNA *ptr)
1206{
1207 const EnumPropertyItem *eprop = static_cast<const EnumPropertyItem *>(ptr->data);
1208 if (eprop->name) {
1209 return strlen(eprop->name);
1210 }
1211 return 0;
1212}
1213
1214static void rna_EnumPropertyItem_description_get(PointerRNA *ptr, char *value)
1215{
1216 const EnumPropertyItem *eprop = static_cast<const EnumPropertyItem *>(ptr->data);
1217
1218 if (eprop->description) {
1219 strcpy(value, eprop->description);
1220 }
1221 else {
1222 value[0] = '\0';
1223 }
1224}
1225
1226static int rna_EnumPropertyItem_description_length(PointerRNA *ptr)
1227{
1228 EnumPropertyItem *eprop = static_cast<EnumPropertyItem *>(ptr->data);
1229
1230 if (eprop->description) {
1231 return strlen(eprop->description);
1232 }
1233 return 0;
1234}
1235
1236static int rna_EnumPropertyItem_value_get(PointerRNA *ptr)
1237{
1238 return (static_cast<EnumPropertyItem *>(ptr->data))->value;
1239}
1240
1241static int rna_EnumPropertyItem_icon_get(PointerRNA *ptr)
1242{
1243 return (static_cast<EnumPropertyItem *>(ptr->data))->icon;
1244}
1245
1246static PointerRNA rna_PointerProperty_fixed_type_get(PointerRNA *ptr)
1247{
1248 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1249 prop = rna_ensure_property(prop);
1251 nullptr, RNA_Struct, ((PointerPropertyRNA *)prop)->pointer_type);
1252}
1253
1254static PointerRNA rna_CollectionProperty_fixed_type_get(PointerRNA *ptr)
1255{
1256 PropertyRNA *prop = static_cast<PropertyRNA *>(ptr->data);
1257 prop = rna_ensure_property(prop);
1259 nullptr, RNA_Struct, ((CollectionPropertyRNA *)prop)->item_type);
1260}
1261
1262/* Function */
1263
1264static void rna_Function_identifier_get(PointerRNA *ptr, char *value)
1265{
1266 strcpy(value, (static_cast<FunctionRNA *>(ptr->data))->identifier.c_str());
1267}
1268
1269static int rna_Function_identifier_length(PointerRNA *ptr)
1270{
1271 return static_cast<FunctionRNA *>(ptr->data)->identifier.size();
1272}
1273
1274static void rna_Function_description_get(PointerRNA *ptr, char *value)
1275{
1276 strcpy(value, (static_cast<FunctionRNA *>(ptr->data))->description);
1277}
1278
1279static int rna_Function_description_length(PointerRNA *ptr)
1280{
1281 return strlen((static_cast<FunctionRNA *>(ptr->data))->description);
1282}
1283
1284static void rna_Function_parameters_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1285{
1287 iter, ptr, &(static_cast<FunctionRNA *>(ptr->data))->cont.properties, rna_property_builtin);
1288}
1289
1290static bool rna_Function_registered_get(PointerRNA *ptr)
1291{
1292 FunctionRNA *func = static_cast<FunctionRNA *>(ptr->data);
1293 return 0 != (func->flag & FUNC_REGISTER);
1294}
1295
1296static bool rna_Function_registered_optional_get(PointerRNA *ptr)
1297{
1298 FunctionRNA *func = static_cast<FunctionRNA *>(ptr->data);
1299 return 0 != (func->flag & (FUNC_REGISTER_OPTIONAL & ~FUNC_REGISTER));
1300}
1301
1302static bool rna_Function_no_self_get(PointerRNA *ptr)
1303{
1304 FunctionRNA *func = static_cast<FunctionRNA *>(ptr->data);
1305 return !(func->flag & FUNC_NO_SELF);
1306}
1307
1308static bool rna_Function_use_self_type_get(PointerRNA *ptr)
1309{
1310 FunctionRNA *func = static_cast<FunctionRNA *>(ptr->data);
1311 return 0 != (func->flag & FUNC_USE_SELF_TYPE);
1312}
1313
1314/* Blender RNA */
1315
1316static bool rna_struct_is_publc(CollectionPropertyIterator * /*iter*/, void *data)
1317{
1318 const StructRNA **srna_ptr_ptr = static_cast<const StructRNA **>(data);
1319 const StructRNA *srna = *srna_ptr_ptr;
1320
1321 return !(srna->flag & STRUCT_PUBLIC_NAMESPACE);
1322}
1323
1324static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
1325{
1326 BlenderRNA *brna = static_cast<BlenderRNA *>(ptr->data);
1327 static_assert(sizeof(StructRNA *) == sizeof(std::unique_ptr<StructRNA>));
1329 ptr,
1330 brna->structs.data(),
1331 sizeof(StructRNA *),
1332 brna->structs.size(),
1333 false,
1334 rna_struct_is_publc);
1335}
1336
1337/* optional, for faster lookups */
1338static int rna_BlenderRNA_structs_length(PointerRNA *ptr)
1339{
1340 BlenderRNA *brna = static_cast<BlenderRNA *>(ptr->data);
1341 return brna->structs.size();
1342}
1343static bool rna_BlenderRNA_structs_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr)
1344{
1345 BlenderRNA *brna = static_cast<BlenderRNA *>(ptr->data);
1346 StructRNA *srna = index < brna->structs.size() ? brna->structs[index].get() : nullptr;
1347 if (srna != nullptr) {
1348 *r_ptr = RNA_pointer_create_discrete(nullptr, RNA_Struct, srna);
1349 return true;
1350 }
1351 else {
1352 return false;
1353 }
1354}
1355static bool rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr,
1356 const char *key,
1357 PointerRNA *r_ptr)
1358{
1359 BlenderRNA *brna = static_cast<BlenderRNA *>(ptr->data);
1360 StructRNA *srna = brna->structs_map.lookup_default(UString(key), nullptr);
1361 if (srna != nullptr) {
1362 *r_ptr = RNA_pointer_create_discrete(nullptr, RNA_Struct, srna);
1363 return true;
1364 }
1365
1366 return false;
1367}
1368
1369/* Default override (and compare) callbacks. */
1370
1375struct RNACompareOverrideDiffPropPtrContext {
1377 RNAPropertyOverrideDiffContext &rnadiff_ctx;
1378
1380 ID *owner_id_a = nullptr;
1381 ID *owner_id_b = nullptr;
1382 PointerRNA propptr_a = {};
1383 PointerRNA propptr_b = {};
1384 PropertyType property_type = PROP_BOOLEAN;
1385
1390 bool no_ownership = false;
1395 bool no_prop_name = false;
1400 bool do_force_name = false;
1402 bool use_id_pointer = false;
1403
1413 bool has_liboverride_apply_cb = false;
1414
1416 /* NOTE: names (and ID pointers, in case items are ID pointers) are typically set by a call
1417 * to #rna_property_override_diff_propptr_validate_diffing. Indices are typically set directly
1418 * from the loop over all RNA collections items in #rna_property_override_diff_default. */
1419 std::optional<std::string> rna_itemname_a;
1420 std::optional<std::string> rna_itemname_b;
1421 std::optional<ID *> rna_itemid_a;
1422 std::optional<ID *> rna_itemid_b;
1423 int rna_itemindex_a = -1;
1424 int rna_itemindex_b = -1;
1425
1435 bool is_valid_for_diffing = true;
1436
1437 bool is_id = false;
1438 bool is_null = false;
1439 bool is_type_diff = false;
1440
1441 RNACompareOverrideDiffPropPtrContext(RNAPropertyOverrideDiffContext &rnadiff_ctx_)
1442 : rnadiff_ctx(rnadiff_ctx_)
1443 {
1444 }
1445};
1446static void rna_property_override_diff_propptr_validate_diffing(
1447 RNACompareOverrideDiffPropPtrContext &ptrdiff_ctx)
1448{
1449 PointerRNA *propptr_a = &ptrdiff_ctx.propptr_a;
1450 PointerRNA *propptr_b = &ptrdiff_ctx.propptr_b;
1451 const bool no_ownership = ptrdiff_ctx.no_ownership;
1452 const bool no_prop_name = ptrdiff_ctx.no_prop_name;
1453 const bool do_force_name = ptrdiff_ctx.do_force_name;
1454 const bool is_same_type = propptr_b != nullptr && (ptrdiff_ctx.rnadiff_ctx.liboverride ?
1456 propptr_a->type, propptr_b->type) :
1457 propptr_a->type == propptr_b->type);
1458
1459 ptrdiff_ctx.is_valid_for_diffing = true;
1460
1461 BLI_assert(propptr_a != nullptr);
1462
1463 if (do_force_name || ptrdiff_ctx.use_id_pointer) {
1464 BLI_assert(!no_prop_name);
1465 }
1466
1467 /* Beware, might be null and is considered a 'blank page'! */
1468 if (!*propptr_a) {
1469 if (propptr_b == nullptr || !*propptr_b) {
1470 ptrdiff_ctx.is_null = true;
1471 }
1472 else {
1473 ptrdiff_ctx.is_id = RNA_struct_is_ID(propptr_b->type);
1474 ptrdiff_ctx.is_null = true;
1475 ptrdiff_ctx.is_type_diff = !is_same_type;
1476 }
1477 ptrdiff_ctx.is_valid_for_diffing = false;
1478 }
1479 else {
1480 ptrdiff_ctx.is_id = RNA_struct_is_ID(propptr_a->type);
1481 ptrdiff_ctx.is_null = (propptr_b == nullptr || !*propptr_b);
1482 ptrdiff_ctx.is_type_diff = !is_same_type;
1483 ptrdiff_ctx.is_valid_for_diffing = !((ptrdiff_ctx.is_id && no_ownership) ||
1484 ptrdiff_ctx.is_null || ptrdiff_ctx.is_type_diff);
1485 }
1486
1487 /* We do a generic quick first comparison checking for "name" and/or "type" properties.
1488 * We assume that is any of those are false, then we are not handling the same data.
1489 * This helps a lot in library override case, especially to detect inserted items in collections.
1490 */
1491 if (!no_prop_name && (ptrdiff_ctx.is_valid_for_diffing || do_force_name)) {
1492 PropertyRNA *nameprop_a = (propptr_a->has_type()) ? RNA_struct_name_property(propptr_a->type) :
1493 nullptr;
1494 PropertyRNA *nameprop_b = (propptr_b != nullptr && propptr_b->has_type()) ?
1495 RNA_struct_name_property(propptr_b->type) :
1496 nullptr;
1497 const bool do_id_pointer = ptrdiff_ctx.use_id_pointer && ptrdiff_ctx.is_id;
1498
1499 /* NOTE: Until we have a `std::string` version of `RNA_property_string_get`, these C string
1500 * pointers and buffers are needed here. Otherwise, in case of C string allocation, if the
1501 * result of `RNA_property_string_get` is directly assigned to a `std::string`, there is no way
1502 * to free this memory. */
1503 int rna_itemname_a_len = 0, rna_itemname_b_len = 0;
1504 char *rna_itemname_a = nullptr;
1505 char *rna_itemname_b = nullptr;
1506 char buff_a[4096];
1507 char buff_b[4096];
1508 if (nameprop_a != nullptr) {
1509 rna_itemname_a = RNA_property_string_get_alloc(
1510 propptr_a, nameprop_a, buff_a, sizeof(buff_a), &rna_itemname_a_len);
1511 // printf("rna_itemname_a = %s\n", rna_itemname_a ? rna_itemname_a : "<NONE>");
1512 ptrdiff_ctx.rna_itemname_a = rna_itemname_a;
1513 }
1514 // else printf("item of type %s a has no name property!\n", propptr_a->type->name);
1515 if (nameprop_b != nullptr) {
1516 rna_itemname_b = RNA_property_string_get_alloc(
1517 propptr_b, nameprop_b, buff_b, sizeof(buff_b), &rna_itemname_b_len);
1518 ptrdiff_ctx.rna_itemname_b = rna_itemname_b;
1519 }
1520
1521 /* NOTE: This will always assign nullptr to these lib-pointers in case `do_id_lib` is false,
1522 * which ensures that they will not affect the result of `ptrdiff_ctx.is_valid_for_diffing` in
1523 * the last check below. */
1524 ID *rna_itemid_a = (do_id_pointer && *propptr_a) ? static_cast<ID *>(propptr_a->data) :
1525 nullptr;
1526 ID *rna_itemid_b = (do_id_pointer && *propptr_b) ? static_cast<ID *>(propptr_b->data) :
1527 nullptr;
1528 if (do_id_pointer) {
1529 ptrdiff_ctx.rna_itemid_a = rna_itemid_a;
1530 ptrdiff_ctx.rna_itemid_b = rna_itemid_b;
1531 }
1532
1533 if (rna_itemname_a != nullptr && rna_itemname_b != nullptr) {
1534 if (rna_itemid_a != rna_itemid_b || rna_itemname_a_len != rna_itemname_b_len ||
1535 rna_itemname_a[0] != rna_itemname_b[0] || !STREQ(rna_itemname_a, rna_itemname_b))
1536 {
1537 ptrdiff_ctx.is_valid_for_diffing = false;
1538 // printf("%s: different names\n", rna_path ? rna_path : "<UNKNOWN>");
1539 }
1540 }
1541 if (rna_itemname_a && rna_itemname_a != buff_a) [[unlikely]] {
1542 MEM_delete(rna_itemname_a);
1543 }
1544 if (rna_itemname_b && rna_itemname_b != buff_b) [[unlikely]] {
1545 MEM_delete(rna_itemname_b);
1546 }
1547 }
1548
1549 if (ptrdiff_ctx.is_id) {
1550 BLI_assert(propptr_a->data == propptr_a->owner_id && propptr_b->data == propptr_b->owner_id);
1551 }
1552}
1553
1554/* Used for both Pointer and Collection properties. */
1555static void rna_property_override_diff_propptr(Main *bmain,
1556 RNACompareOverrideDiffPropPtrContext &ptrdiff_ctx)
1557{
1558 ID *owner_id_a = ptrdiff_ctx.owner_id_a;
1559 ID *owner_id_b = ptrdiff_ctx.owner_id_b;
1560 PointerRNA *propptr_a = &ptrdiff_ctx.propptr_a;
1561 PointerRNA *propptr_b = &ptrdiff_ctx.propptr_b;
1562
1563 eRNACompareMode mode = ptrdiff_ctx.rnadiff_ctx.mode;
1564 const bool no_ownership = ptrdiff_ctx.no_ownership;
1565
1566 IDOverrideLibrary *liboverride = ptrdiff_ctx.rnadiff_ctx.liboverride;
1567 const eRNAOverrideMatch liboverride_flags = ptrdiff_ctx.rnadiff_ctx.liboverride_flags;
1568 const char *rna_path = ptrdiff_ctx.rnadiff_ctx.rna_path;
1569 size_t rna_path_len = ptrdiff_ctx.rnadiff_ctx.rna_path_len;
1570 const PropertyType property_type = ptrdiff_ctx.property_type;
1571
1572 std::optional<std::string> &rna_itemname_a = ptrdiff_ctx.rna_itemname_a;
1573 std::optional<std::string> &rna_itemname_b = ptrdiff_ctx.rna_itemname_b;
1574 const int rna_itemindex_a = ptrdiff_ctx.rna_itemindex_a;
1575 const int rna_itemindex_b = ptrdiff_ctx.rna_itemindex_b;
1576
1577 BLI_assert(ELEM(property_type, PROP_POINTER, PROP_COLLECTION));
1578
1579 rna_property_override_diff_propptr_validate_diffing(ptrdiff_ctx);
1580
1581 /* If false, it means that the whole data itself is different,
1582 * so no point in going inside of it at all! */
1583 const bool is_valid_for_diffing = ptrdiff_ctx.is_valid_for_diffing;
1584 const bool is_id = ptrdiff_ctx.is_id;
1585 const bool is_null = ptrdiff_ctx.is_null;
1586 const bool is_type_diff = ptrdiff_ctx.is_type_diff;
1587
1588 const bool has_liboverride_apply_cb = ptrdiff_ctx.has_liboverride_apply_cb;
1589 const bool do_create = (liboverride != nullptr &&
1590 /* Replacing a Pointer can only happen if it's an ID one, or there is a
1591 * dedicated apply callback defined for the property. */
1592 (is_id || has_liboverride_apply_cb) &&
1593 (liboverride_flags & RNA_OVERRIDE_COMPARE_CREATE) != 0 &&
1594 rna_path != nullptr);
1595
1596 if (is_id) {
1597 /* Owned IDs (the ones we want to actually compare in depth, instead of just comparing pointer
1598 * values) should be always properly tagged as 'virtual' overrides. */
1599 ID *id = propptr_a->owner_id;
1600 if (id != nullptr && !ID_IS_OVERRIDE_LIBRARY(id)) {
1601 id = propptr_b->owner_id;
1602 if (id != nullptr && !ID_IS_OVERRIDE_LIBRARY(id)) {
1603 id = nullptr;
1604 }
1605 }
1606
1607 BLI_assert(no_ownership || id == nullptr || ID_IS_OVERRIDE_LIBRARY_VIRTUAL(id));
1609 }
1610
1611 if (liboverride) {
1612 if (no_ownership || is_null || is_type_diff || !is_valid_for_diffing) {
1613 /* In case this pointer prop does not own its data (or one is nullptr), do not compare
1614 * structs! This is a quite safe path to infinite loop, among other nasty issues. Instead,
1615 * just compare pointers themselves. */
1616 ptrdiff_ctx.rnadiff_ctx.comparison = (propptr_a->data != propptr_b->data);
1617
1618 if (do_create && ptrdiff_ctx.rnadiff_ctx.comparison != 0) {
1619 bool created = false;
1621 liboverride, rna_path, &created);
1622
1623 /* If not yet overridden, or if we are handling sub-items (inside a collection)... */
1624 if (op != nullptr) {
1625 if (created || op->rna_prop_type == 0) {
1626 op->rna_prop_type = property_type;
1627 }
1628 else {
1629 BLI_assert(op->rna_prop_type == property_type);
1630 }
1631
1632 IDOverrideLibraryPropertyOperation *opop = nullptr;
1633 if (created || (rna_itemname_a && !rna_itemname_a->empty()) ||
1634 (rna_itemname_b && !rna_itemname_b->empty()) || rna_itemindex_a != -1 ||
1635 rna_itemindex_b != -1)
1636 {
1637 const char *subitem_refname = rna_itemname_b ? rna_itemname_b->c_str() : nullptr;
1638 const char *subitem_locname = rna_itemname_a ? rna_itemname_a->c_str() : nullptr;
1641 subitem_refname,
1642 subitem_locname,
1643 ptrdiff_ctx.rna_itemid_b,
1644 ptrdiff_ctx.rna_itemid_a,
1645 rna_itemindex_b,
1646 rna_itemindex_a,
1647 true,
1648 nullptr,
1649 &created);
1650 /* Do not use BKE_lib_override_library_operations_tag here, we do not want to validate
1651 * as used all of its operations. */
1654 if (created) {
1655 ptrdiff_ctx.rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
1656 }
1657 }
1658 else {
1660 }
1661
1662 if (is_id && no_ownership) {
1663 if (opop == nullptr) {
1664 const char *subitem_refname = rna_itemname_b ? rna_itemname_b->c_str() : nullptr;
1665 const char *subitem_locname = rna_itemname_a ? rna_itemname_a->c_str() : nullptr;
1668 subitem_refname,
1669 subitem_locname,
1670 ptrdiff_ctx.rna_itemid_b,
1671 ptrdiff_ctx.rna_itemid_a,
1672 rna_itemindex_b,
1673 rna_itemindex_a,
1674 true,
1675 nullptr,
1676 &created);
1677 /* Do not use BKE_lib_override_library_operations_tag here, we do not want to
1678 * validate as used all of its operations. */
1681 if (created) {
1682 ptrdiff_ctx.rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
1683 }
1684 }
1685
1686 BLI_assert(propptr_a->data == propptr_a->owner_id);
1687 BLI_assert(propptr_b->data == propptr_b->owner_id);
1688 ID *id_a = static_cast<ID *>(propptr_a->data);
1689 ID *id_b = static_cast<ID *>(propptr_b->data);
1690 if (ELEM(nullptr, id_a, id_b)) {
1691 /* In case one of the pointer is nullptr and not the other, we consider that the
1692 * liboverride is not matching its reference anymore. */
1694 }
1695 else if ((owner_id_a->tag & ID_TAG_LIBOVERRIDE_NEED_RESYNC) != 0 ||
1696 (owner_id_b->tag & ID_TAG_LIBOVERRIDE_NEED_RESYNC) != 0)
1697 {
1698 /* In case one of the owner of the checked property is tagged as needing resync, do
1699 * not change the 'match reference' status of its ID pointer properties overrides,
1700 * since many non-matching ones are likely due to missing resync. */
1701 CLOG_DEBUG(
1702 &LOG_COMPARE_OVERRIDE,
1703 "Not checking matching ID pointer properties, since owner %s is tagged as "
1704 "needing resync.\n",
1705 id_a->name);
1706 }
1707 else if (id_a->override_library != nullptr &&
1708 id_a->override_library->reference == id_b)
1709 {
1711 }
1712 else if (id_b->override_library != nullptr &&
1713 id_b->override_library->reference == id_a)
1714 {
1716 }
1717 else {
1719 }
1720 }
1721 }
1722 }
1723 }
1724 else {
1725/* In case we got some array/collection like items identifiers, now is the time to generate a
1726 * proper rna path from those. */
1727# define RNA_PATH_BUFFSIZE 8192
1728
1729 char extended_rna_path_buffer[RNA_PATH_BUFFSIZE];
1730 char *extended_rna_path = extended_rna_path_buffer;
1731 size_t extended_rna_path_len = 0;
1732
1733 /* There may be a propname defined in some cases, while no actual name set
1734 * (e.g. happens with point cache), in that case too we want to fall back to index.
1735 * Note that we do not need the RNA path for insertion operations. */
1736 if (rna_path) {
1737 if ((rna_itemname_a && !rna_itemname_a->empty()) &&
1738 (rna_itemname_b && !rna_itemname_b->empty()))
1739 {
1740 BLI_assert(*rna_itemname_a == *rna_itemname_b);
1741
1742 char esc_item_name[RNA_PATH_BUFFSIZE];
1743 const size_t esc_item_name_len = BLI_str_escape(
1744 esc_item_name, rna_itemname_a->c_str(), sizeof(esc_item_name));
1745 extended_rna_path_len = rna_path_len + 2 + esc_item_name_len + 2;
1746 if (extended_rna_path_len >= RNA_PATH_BUFFSIZE) {
1747 extended_rna_path = MEM_new_array_uninitialized<char>(extended_rna_path_len + 1,
1748 __func__);
1749 }
1750
1751 memcpy(extended_rna_path, rna_path, rna_path_len);
1752 extended_rna_path[rna_path_len] = '[';
1753 extended_rna_path[rna_path_len + 1] = '"';
1754 memcpy(extended_rna_path + rna_path_len + 2, esc_item_name, esc_item_name_len);
1755 extended_rna_path[rna_path_len + 2 + esc_item_name_len] = '"';
1756 extended_rna_path[rna_path_len + 2 + esc_item_name_len + 1] = ']';
1757 extended_rna_path[extended_rna_path_len] = '\0';
1758 }
1759 else if (rna_itemindex_a != -1) { /* Based on index... */
1760 BLI_assert(rna_itemindex_a == rna_itemindex_b);
1761
1762 /* low-level specific highly-efficient conversion of positive integer to string. */
1763 char item_index_buff[32];
1764 size_t item_index_buff_len = 0;
1765 if (rna_itemindex_a == 0) {
1766 item_index_buff[0] = '0';
1767 item_index_buff_len = 1;
1768 }
1769 else {
1770 uint index;
1771 for (index = rna_itemindex_a;
1772 index > 0 && item_index_buff_len < sizeof(item_index_buff);
1773 index /= 10)
1774 {
1775 item_index_buff[item_index_buff_len++] = '0' + char(index % 10);
1776 }
1777 BLI_assert(index == 0);
1778 }
1779
1780 extended_rna_path_len = rna_path_len + item_index_buff_len + 2;
1781 if (extended_rna_path_len >= RNA_PATH_BUFFSIZE) {
1782 extended_rna_path = MEM_new_array_uninitialized<char>(extended_rna_path_len + 1,
1783 __func__);
1784 }
1785
1786 memcpy(extended_rna_path, rna_path, rna_path_len);
1787 extended_rna_path[rna_path_len] = '[';
1788 for (size_t i = 1; i <= item_index_buff_len; i++) {
1789 /* The first loop above generated inverted string representation of our index number.
1790 */
1791 extended_rna_path[rna_path_len + i] = item_index_buff[item_index_buff_len - i];
1792 }
1793 extended_rna_path[rna_path_len + 1 + item_index_buff_len] = ']';
1794 extended_rna_path[extended_rna_path_len] = '\0';
1795 }
1796 else {
1797 extended_rna_path = const_cast<char *>(rna_path);
1798 extended_rna_path_len = rna_path_len;
1799 }
1800 }
1801
1802 const bool match = RNA_struct_override_matches(bmain,
1803 propptr_a,
1804 propptr_b,
1805 extended_rna_path,
1806 extended_rna_path_len,
1808 liboverride_flags,
1809 &ptrdiff_ctx.rnadiff_ctx.report_flag);
1810 ptrdiff_ctx.rnadiff_ctx.comparison = !match;
1811
1812 /* Regardless of whether the data from both pointers matches or not, a potentially existing
1813 * operation on current extended rna path should be removed. This is done by tagging said
1814 * operation as unused, while clearing the property tag (see also
1815 * #RNA_struct_override_matches handling of #LIBOVERRIDE_PROP_OP_TAG_UNUSED). Note that a
1816 * property with no operations will also be cleared by
1817 * #BKE_lib_override_library_id_unused_cleanup. */
1819 extended_rna_path);
1820 if (op != nullptr) {
1822 }
1823
1824 if (!ELEM(extended_rna_path, extended_rna_path_buffer, rna_path)) {
1825 MEM_delete(extended_rna_path);
1826 }
1827
1828# undef RNA_PATH_BUFFSIZE
1829 }
1830 }
1831 else {
1832 if (no_ownership || is_null || is_type_diff || !is_valid_for_diffing) {
1833 /* In case this pointer prop does not own its data (or one is nullptr), do not compare
1834 * structs! This is a quite safe path to infinite loop, among other nasty issues. Instead,
1835 * just compare pointers themselves. */
1836 ptrdiff_ctx.rnadiff_ctx.comparison = (propptr_a->data != propptr_b->data);
1837 }
1838 else {
1839 /* We could also use is_diff_pointer, but then we potentially lose the greater-than/less-than
1840 * info - and don't think performances are critical here for now anyway. */
1841 ptrdiff_ctx.rnadiff_ctx.comparison = !RNA_struct_equals(bmain, propptr_a, propptr_b, mode);
1842 }
1843 }
1844}
1845
1846# define RNA_PROPERTY_GET_SINGLE(_typename, _ptr, _prop, _index) \
1847 (is_array ? RNA_property_##_typename##_get_index((_ptr), (_prop), (_index)) : \
1848 RNA_property_##_typename##_get((_ptr), (_prop)))
1849# define RNA_PROPERTY_SET_SINGLE(_typename, _ptr, _prop, _index, _value) \
1850 (is_array ? RNA_property_##_typename##_set_index((_ptr), (_prop), (_index), (_value)) : \
1851 RNA_property_##_typename##_set((_ptr), (_prop), (_value)))
1852
1859{
1860 PropertyRNAOrID *prop_a = rnadiff_ctx.prop_a;
1861 PropertyRNAOrID *prop_b = rnadiff_ctx.prop_b;
1862 PointerRNA *ptr_a = prop_a->ptr;
1863 PointerRNA *ptr_b = prop_b->ptr;
1864 PropertyRNA *rawprop_a = prop_a->rawprop;
1865 PropertyRNA *rawprop_b = prop_b->rawprop;
1866 const uint len_a = prop_a->array_len;
1867 const uint len_b = prop_b->array_len;
1868
1869 IDOverrideLibrary *liboverride = rnadiff_ctx.liboverride;
1870 const char *rna_path = rnadiff_ctx.rna_path;
1871 const int liboverride_flags = rnadiff_ctx.liboverride_flags;
1872
1873 BLI_assert(len_a == len_b);
1874
1875 /* NOTE: at this point, we are sure that when len_a is zero,
1876 * we are not handling an (empty) array. */
1877
1878 const bool do_create = liboverride != nullptr &&
1879 (liboverride_flags & RNA_OVERRIDE_COMPARE_CREATE) != 0 &&
1880 rna_path != nullptr;
1881
1882 const bool no_ownership = (prop_a->rnaprop->flag & PROP_PTR_NO_OWNERSHIP) != 0;
1883
1884 const PropertyType rna_prop_type = RNA_property_type(prop_a->rnaprop);
1885 bool created = false;
1886 IDOverrideLibraryProperty *op = nullptr;
1887
1888 switch (rna_prop_type) {
1889 case PROP_BOOLEAN: {
1890 if (len_a) {
1891 bool array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1892 bool *array_a, *array_b;
1893
1894 array_a = (len_a > RNA_STACK_ARRAY) ?
1895 MEM_new_array_uninitialized<bool>(size_t(len_a), "RNA equals") :
1896 array_stack_a;
1897 array_b = (len_b > RNA_STACK_ARRAY) ?
1898 MEM_new_array_uninitialized<bool>(size_t(len_b), "RNA equals") :
1899 array_stack_b;
1900
1901 RNA_property_boolean_get_array(ptr_a, rawprop_a, array_a);
1902 RNA_property_boolean_get_array(ptr_b, rawprop_b, array_b);
1903
1904 rnadiff_ctx.comparison = memcmp(array_a, array_b, sizeof(bool) * len_a);
1905
1906 if (do_create && rnadiff_ctx.comparison != 0) {
1907 /* XXX TODO: this will have to be refined to handle array items. */
1909
1910 if (op != nullptr && created) {
1913 nullptr,
1914 nullptr,
1915 {},
1916 {},
1917 -1,
1918 -1,
1919 true,
1920 nullptr,
1921 nullptr);
1922 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
1923 }
1924 else {
1925 /* Already overridden prop, we'll have to check arrays items etc. */
1926 }
1927 }
1928
1929 if (array_a != array_stack_a) {
1930 MEM_delete(array_a);
1931 }
1932 if (array_b != array_stack_b) {
1933 MEM_delete(array_b);
1934 }
1935 }
1936 else {
1937 const bool value_a = RNA_property_boolean_get(ptr_a, rawprop_a);
1938 const bool value_b = RNA_property_boolean_get(ptr_b, rawprop_b);
1939 rnadiff_ctx.comparison = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
1940
1941 if (do_create && rnadiff_ctx.comparison != 0) {
1942 op = BKE_lib_override_library_property_get(liboverride, rna_path, &created);
1943
1944 if (op != nullptr && created) { /* If not yet overridden... */
1945 BKE_lib_override_library_property_operation_get(op,
1946 LIBOVERRIDE_OP_REPLACE,
1947 nullptr,
1948 nullptr,
1949 {},
1950 {},
1951 -1,
1952 -1,
1953 true,
1954 nullptr,
1955 nullptr);
1956 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
1957 }
1958 }
1959 }
1960 break;
1961 }
1962
1963 case PROP_INT: {
1964 if (len_a) {
1965 int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
1966 int *array_a, *array_b;
1967
1968 array_a = (len_a > RNA_STACK_ARRAY) ?
1969 MEM_new_array_uninitialized<int>(size_t(len_a), "RNA equals") :
1970 array_stack_a;
1971 array_b = (len_b > RNA_STACK_ARRAY) ?
1972 MEM_new_array_uninitialized<int>(size_t(len_b), "RNA equals") :
1973 array_stack_b;
1974
1975 RNA_property_int_get_array(ptr_a, rawprop_a, array_a);
1976 RNA_property_int_get_array(ptr_b, rawprop_b, array_b);
1977
1978 rnadiff_ctx.comparison = memcmp(array_a, array_b, sizeof(int) * len_a);
1979
1980 if (do_create && rnadiff_ctx.comparison != 0) {
1981 /* XXX TODO: this will have to be refined to handle array items. */
1983
1984 if (op != nullptr && created) {
1987 nullptr,
1988 nullptr,
1989 {},
1990 {},
1991 -1,
1992 -1,
1993 true,
1994 nullptr,
1995 nullptr);
1996 if (created) {
1997 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
1998 }
1999 }
2000 else {
2001 /* Already overridden prop, we'll have to check arrays items etc. */
2002 }
2003 }
2004
2005 if (array_a != array_stack_a) {
2006 MEM_delete(array_a);
2007 }
2008 if (array_b != array_stack_b) {
2009 MEM_delete(array_b);
2010 }
2011 }
2012 else {
2013 const int value_a = RNA_property_int_get(ptr_a, rawprop_a);
2014 const int value_b = RNA_property_int_get(ptr_b, rawprop_b);
2015 rnadiff_ctx.comparison = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
2016
2017 if (do_create && rnadiff_ctx.comparison != 0) {
2018 op = BKE_lib_override_library_property_get(liboverride, rna_path, &created);
2019
2020 if (op != nullptr && created) { /* If not yet overridden... */
2021 BKE_lib_override_library_property_operation_get(op,
2022 LIBOVERRIDE_OP_REPLACE,
2023 nullptr,
2024 nullptr,
2025 {},
2026 {},
2027 -1,
2028 -1,
2029 true,
2030 nullptr,
2031 nullptr);
2032 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
2033 }
2034 }
2035 }
2036 break;
2037 }
2038
2039 case PROP_FLOAT: {
2040 if (len_a) {
2041 float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
2042 float *array_a, *array_b;
2043
2044 array_a = (len_a > RNA_STACK_ARRAY) ?
2045 MEM_new_array_uninitialized<float>(size_t(len_a), "RNA equals") :
2046 array_stack_a;
2047 array_b = (len_b > RNA_STACK_ARRAY) ?
2048 MEM_new_array_uninitialized<float>(size_t(len_b), "RNA equals") :
2049 array_stack_b;
2050
2051 RNA_property_float_get_array(ptr_a, rawprop_a, array_a);
2052 RNA_property_float_get_array(ptr_b, rawprop_b, array_b);
2053
2054 rnadiff_ctx.comparison = memcmp(array_a, array_b, sizeof(float) * len_a);
2055
2056 if (do_create && rnadiff_ctx.comparison != 0) {
2057 /* XXX TODO: this will have to be refined to handle array items. */
2059
2060 if (op != nullptr && created) {
2063 nullptr,
2064 nullptr,
2065 {},
2066 {},
2067 -1,
2068 -1,
2069 true,
2070 nullptr,
2071 nullptr);
2072 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
2073 }
2074 else {
2075 /* Already overridden prop, we'll have to check arrays items etc. */
2076 }
2077 }
2078
2079 if (array_a != array_stack_a) {
2080 MEM_delete(array_a);
2081 }
2082 if (array_b != array_stack_b) {
2083 MEM_delete(array_b);
2084 }
2085 }
2086 else {
2087 const float value_a = RNA_property_float_get(ptr_a, rawprop_a);
2088 const float value_b = RNA_property_float_get(ptr_b, rawprop_b);
2089 rnadiff_ctx.comparison = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
2090
2091 if (do_create && rnadiff_ctx.comparison != 0) {
2092 op = BKE_lib_override_library_property_get(liboverride, rna_path, &created);
2093
2094 if (op != nullptr && created) { /* If not yet overridden... */
2095 BKE_lib_override_library_property_operation_get(op,
2096 LIBOVERRIDE_OP_REPLACE,
2097 nullptr,
2098 nullptr,
2099 {},
2100 {},
2101 -1,
2102 -1,
2103 true,
2104 nullptr,
2105 nullptr);
2106 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
2107 }
2108 }
2109 }
2110 break;
2111 }
2112
2113 case PROP_ENUM: {
2114 const int value_a = RNA_property_enum_get(ptr_a, rawprop_a);
2115 const int value_b = RNA_property_enum_get(ptr_b, rawprop_b);
2116 rnadiff_ctx.comparison = value_a != value_b;
2117
2118 if (do_create && rnadiff_ctx.comparison != 0) {
2119 op = BKE_lib_override_library_property_get(liboverride, rna_path, &created);
2120
2121 if (op != nullptr && created) { /* If not yet overridden... */
2123 LIBOVERRIDE_OP_REPLACE,
2124 nullptr,
2125 nullptr,
2126 {},
2127 {},
2128 -1,
2129 -1,
2130 true,
2131 nullptr,
2132 nullptr);
2133 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
2134 }
2135 }
2136 break;
2137 }
2138
2139 case PROP_STRING: {
2140 char fixed_a[4096], fixed_b[4096];
2141 int len_str_a, len_str_b;
2142 char *value_a = RNA_property_string_get_alloc(
2143 ptr_a, rawprop_a, fixed_a, sizeof(fixed_a), &len_str_a);
2144 char *value_b = RNA_property_string_get_alloc(
2145 ptr_b, rawprop_b, fixed_b, sizeof(fixed_b), &len_str_b);
2146/* TODO: we could do a check on length too,
2147 * but then we would not have a 'real' string comparison...
2148 * Maybe behind a eRNAOverrideMatch flag? */
2149# if 0
2150 rnadiff_ctx.comparison = len_str_a < len_str_b ? -1 :
2151 len_str_a > len_str_b ? 1 :
2152 strcmp(value_a, value_b);
2153# endif
2154 rnadiff_ctx.comparison = strcmp(value_a, value_b);
2155
2156 if (do_create && rnadiff_ctx.comparison != 0) {
2157 op = BKE_lib_override_library_property_get(liboverride, rna_path, &created);
2158
2159 if (op != nullptr && created) { /* If not yet overridden... */
2161 LIBOVERRIDE_OP_REPLACE,
2162 nullptr,
2163 nullptr,
2164 {},
2165 {},
2166 -1,
2167 -1,
2168 true,
2169 nullptr,
2170 nullptr);
2171 rnadiff_ctx.report_flag |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
2172 }
2173 }
2174
2175 if (value_a != fixed_a) {
2176 MEM_delete(value_a);
2177 }
2178 if (value_b != fixed_b) {
2179 MEM_delete(value_b);
2180 }
2181 break;
2182 }
2183
2184 case PROP_POINTER: {
2185 /* Using property name check only makes sense for items of a collection, not for a single
2186 * pointer.
2187 * Doing this here avoids having to manually specify `PROPOVERRIDE_NO_PROP_NAME` to things
2188 * like ShapeKey pointers. */
2189 if (prop_a->identifier == "rna_type"_ustr) {
2190 /* Dummy 'pass' answer, this is a meta-data and must be ignored... */
2191 return;
2192 }
2193 else {
2194 RNACompareOverrideDiffPropPtrContext ptrdiff_ctx(rnadiff_ctx);
2195 ptrdiff_ctx.owner_id_a = ptr_a->owner_id;
2196 ptrdiff_ctx.owner_id_b = ptr_b->owner_id;
2197 /* Do not create empty IDPGroup properties here. This is not only a totally useless
2198 * overhead, but it also remains unsafe in parallelized context, despite the usage of a
2199 * mutex in #property_pointer_get(). See also #146221. */
2200 ptrdiff_ctx.propptr_a = RNA_property_pointer_get_never_create(ptr_a, rawprop_a);
2201 ptrdiff_ctx.propptr_b = RNA_property_pointer_get_never_create(ptr_b, rawprop_b);
2202 ptrdiff_ctx.no_prop_name = true;
2203 ptrdiff_ctx.no_ownership = no_ownership;
2204 ptrdiff_ctx.property_type = PROP_POINTER;
2205 /* IDProperties (real or backend storage for dynamic RNA) have a default handling for
2206 * 'pointer' data creation. */
2207 if (prop_a->is_idprop || prop_a->is_rna_storage_idprop || prop_a->rnaprop->override_apply)
2208 {
2209 BLI_assert(prop_a->is_idprop == prop_b->is_idprop);
2210 BLI_assert(prop_a->is_rna_storage_idprop == prop_b->is_rna_storage_idprop);
2211 BLI_assert(prop_a->rnaprop->override_apply == prop_b->rnaprop->override_apply);
2212 ptrdiff_ctx.has_liboverride_apply_cb = true;
2213 }
2214 rna_property_override_diff_propptr(bmain, ptrdiff_ctx);
2215 }
2216 break;
2217 }
2218
2219 case PROP_COLLECTION: {
2220 const bool no_prop_name = (prop_a->rnaprop->flag_override & PROPOVERRIDE_NO_PROP_NAME) != 0;
2221
2222 /* IDProperties (real or backend storage for dynamic RNA) have a default handling for
2223 * 'pointer' data creation and 'collection' items insertion. */
2224 BLI_assert(prop_a->is_idprop == prop_b->is_idprop);
2225 BLI_assert(prop_a->is_rna_storage_idprop == prop_b->is_rna_storage_idprop);
2226 BLI_assert(prop_a->rnaprop->override_apply == prop_b->rnaprop->override_apply);
2227 const bool has_liboverride_apply_cb = (prop_a->is_idprop || prop_a->is_rna_storage_idprop ||
2228 prop_a->rnaprop->override_apply);
2229 if (!has_liboverride_apply_cb &&
2230 (prop_a->rnaprop->flag_override & PROPOVERRIDE_LIBRARY_INSERTION) != 0)
2231 {
2232 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2233 "RNA collection '%s' defined as supporting liboverride insertion of items, but "
2234 "no liboverride apply callback defined for it. No insertion will happen.",
2235 rna_path);
2236 }
2237
2238 /* NOTE: we assume we only insert in ptr_a (i.e. we can only get new items in ptr_a),
2239 * and that we never remove anything. */
2240 const bool use_collection_insertion = has_liboverride_apply_cb && do_create &&
2241 (prop_a->rnaprop->flag_override &
2243
2244 bool equals = true;
2245 bool abort = false;
2246 int idx_a = 0;
2247 int idx_b = 0;
2248 std::optional<std::string> prev_rna_itemname_a;
2249 std::optional<ID *> prev_rna_itemid_a;
2250
2251 CollectionPropertyIterator iter_a, iter_b;
2252 RNA_property_collection_begin(ptr_a, rawprop_a, &iter_a);
2253 RNA_property_collection_begin(ptr_b, rawprop_b, &iter_b);
2254
2255 if (use_collection_insertion) {
2256 /* We need to clean up all possible existing insertion operations, and then re-generate
2257 * them, otherwise we'd end up with a mess of opop's every time something changes. */
2258 op = BKE_lib_override_library_property_find(liboverride, rna_path);
2259 if (op != nullptr) {
2260 for (IDOverrideLibraryPropertyOperation &opop : op->operations.items_mutable()) {
2261 if (ELEM(opop.operation, LIBOVERRIDE_OP_INSERT_AFTER, LIBOVERRIDE_OP_INSERT_BEFORE)) {
2263 }
2264 }
2265 op = nullptr;
2266 }
2267 }
2268
2269 for (; iter_a.valid && !abort;) {
2270 do {
2271 bool is_valid_for_insertion = use_collection_insertion;
2272
2273 RNACompareOverrideDiffPropPtrContext ptrdiff_ctx(rnadiff_ctx);
2274 ptrdiff_ctx.owner_id_a = ptr_a->owner_id;
2275 ptrdiff_ctx.owner_id_b = ptr_b->owner_id;
2276 ptrdiff_ctx.propptr_a = iter_a.ptr;
2277 if (iter_b.valid) {
2278 ptrdiff_ctx.propptr_b = iter_b.ptr;
2279 }
2280 ptrdiff_ctx.no_prop_name = no_prop_name;
2281 ptrdiff_ctx.do_force_name = !no_prop_name;
2282 ptrdiff_ctx.use_id_pointer = !no_prop_name;
2283 ptrdiff_ctx.no_ownership = no_ownership;
2284 ptrdiff_ctx.property_type = PROP_COLLECTION;
2285 ptrdiff_ctx.has_liboverride_apply_cb = has_liboverride_apply_cb;
2286
2287 if (iter_b.valid || use_collection_insertion) {
2288 rna_property_override_diff_propptr_validate_diffing(ptrdiff_ctx);
2289 /* Getting props names has already been done in call above, no need to redo it later
2290 * when calling #rna_property_override_diff_propptr. */
2291 ptrdiff_ctx.no_prop_name = true;
2292 ptrdiff_ctx.do_force_name = false;
2293 ptrdiff_ctx.use_id_pointer = false;
2294 }
2295
2296 const bool is_valid_for_diffing = ptrdiff_ctx.is_valid_for_diffing;
2297 const bool is_id = ptrdiff_ctx.is_id;
2298
2299 /* We do not support insertion of IDs for now, neither handle nullptr pointers. */
2300 if (is_id || is_valid_for_diffing) {
2301 is_valid_for_insertion = false;
2302 }
2303
2304# if 0
2305 if (rna_path) {
2306 printf(
2307 "Checking %s, %s [%d] vs %s [%d]; is_id: %d, diffing: %d; "
2308 "insert: %d (could be used: %d, do_create: %d)\n",
2309 rna_path,
2310 ptrdiff_ctx.rna_itemname_a ? ptrdiff_ctx.rna_itemname_a->c_str() : "",
2311 idx_a,
2312 ptrdiff_ctx.rna_itemname_b ? ptrdiff_ctx.rna_itemname_b->c_str() : "",
2313 idx_b,
2314 is_id,
2315 is_valid_for_diffing,
2316 is_valid_for_insertion,
2317 use_collection_insertion,
2318 do_create);
2319 }
2320# endif
2321
2322 if (!(is_id || is_valid_for_diffing || is_valid_for_insertion)) {
2323 /* Differences we cannot handle, we can break here. */
2324 equals = false;
2325 abort = true;
2326 break;
2327 }
2328
2329 /* Collections do not support replacement of their data (except for collections of ID
2330 * pointers), since they do not support removing, only in *some* cases, insertion. We
2331 * also assume then that _a data is the one where things are inserted.
2332 *
2333 * NOTE: In insertion case, both 'local' and 'reference' (aka anchor) sub-item
2334 * identifiers refer to collection items in the local override. The 'reference' may match
2335 * an item in the linked reference data, but it can also be another local-only item added
2336 * by a previous INSERT operation. */
2337 if (is_valid_for_insertion && use_collection_insertion) {
2338 op = BKE_lib_override_library_property_get(liboverride, rna_path, &created);
2339
2341 op,
2342 LIBOVERRIDE_OP_INSERT_AFTER,
2343 (no_prop_name || !prev_rna_itemname_a) ? nullptr : prev_rna_itemname_a->c_str(),
2344 (no_prop_name || !ptrdiff_ctx.rna_itemname_a) ?
2345 nullptr :
2346 ptrdiff_ctx.rna_itemname_a->c_str(),
2347 prev_rna_itemid_a,
2348 ptrdiff_ctx.rna_itemid_a,
2349 idx_a - 1,
2350 idx_a,
2351 true,
2352 nullptr,
2353 nullptr);
2354# if 0
2355 printf("%s: Adding insertion op override after '%s'/%d\n",
2356 rna_path,
2357 prev_rna_itemname_a ? prev_rna_itemname_a->c_str() : "",
2358 idx_a - 1);
2359# endif
2360 op = nullptr;
2361
2362 equals = false;
2363 }
2364 else if (is_id || is_valid_for_diffing) {
2365 if (equals || do_create) {
2366 ptrdiff_ctx.rna_itemindex_a = idx_a;
2367 ptrdiff_ctx.rna_itemindex_b = idx_b;
2368 rna_property_override_diff_propptr(bmain, ptrdiff_ctx);
2369 equals = equals && (rnadiff_ctx.comparison == 0);
2370 }
2371 }
2372
2373 if (ptrdiff_ctx.rna_itemname_a) {
2374 prev_rna_itemname_a = std::move(*ptrdiff_ctx.rna_itemname_a);
2375 }
2376 else {
2377 prev_rna_itemname_a.reset();
2378 }
2379 prev_rna_itemid_a = ptrdiff_ctx.rna_itemid_a;
2380
2381 if (!do_create && !equals) {
2382 abort = true; /* Early out in case we do not want to loop over whole collection. */
2383 break;
2384 }
2385
2386 if (!(use_collection_insertion && !(is_id || is_valid_for_diffing))) {
2387 break;
2388 }
2389
2390 if (iter_a.valid) {
2392 idx_a++;
2393 }
2394 } while (iter_a.valid);
2395
2396 if (iter_a.valid) {
2398 idx_a++;
2399 }
2400 if (iter_b.valid) {
2402 idx_b++;
2403 }
2404 }
2405
2406 /* Not same number of items in both collections. */
2407 equals = equals && !(iter_a.valid || iter_b.valid) && !abort;
2410
2411 rnadiff_ctx.comparison = (equals == false);
2412 return;
2413 }
2414
2415 default:
2416 break;
2417 }
2418
2419 if (op != nullptr) {
2420 /* In theory, if the liboverride operation already existed, it should already be of the right
2421 * type. However, in some rare cases a same exact RNA path can end up pointing at different
2422 * data of a different path than when the liboverride property was created, so just always
2423 * ensure the type is now valid. */
2424 op->rna_prop_type = rna_prop_type;
2425 }
2426
2427 return;
2428}
2429
2430bool rna_property_override_store_default(Main * /*bmain*/,
2431 PointerRNA *ptr_local,
2432 PointerRNA *ptr_reference,
2433 PointerRNA *ptr_storage,
2434 PropertyRNA *prop_local,
2435 PropertyRNA *prop_reference,
2436 PropertyRNA *prop_storage,
2437 const int len_local,
2438 const int len_reference,
2439 const int len_storage,
2440 IDOverrideLibraryPropertyOperation *opop)
2441{
2442 BLI_assert(len_local == len_reference && (!ptr_storage || len_local == len_storage));
2443 UNUSED_VARS_NDEBUG(len_reference, len_storage);
2444
2445 bool changed = false;
2446 const bool is_array = len_local > 0;
2447 const int index = is_array ? opop->subitem_reference_index : 0;
2448
2449 if (!ELEM(opop->operation, LIBOVERRIDE_OP_ADD, LIBOVERRIDE_OP_SUBTRACT, LIBOVERRIDE_OP_MULTIPLY))
2450 {
2451 return changed;
2452 }
2453
2454 /* XXX TODO: About range limits.
2455 * Ideally, it would be great to get rid of RNA range in that specific case.
2456 * However, this won't be that easy and will add yet another layer of complexity in
2457 * generated code, not to mention that we could most likely *not* bypass custom setters anyway.
2458 * So for now, if needed second operand value is not in valid range, we simply fall back
2459 * to a mere REPLACE operation.
2460 * Time will say whether this is acceptable limitation or not. */
2461 switch (RNA_property_type(prop_local)) {
2462 case PROP_BOOLEAN:
2463 /* TODO: support boolean ops? Really doubt this would ever be useful though. */
2464 BLI_assert_msg(0, "Boolean properties support no override diff operation");
2465 break;
2466 case PROP_INT: {
2467 int prop_min, prop_max;
2468 RNA_property_int_range(ptr_local, prop_local, &prop_min, &prop_max);
2469
2470 if (is_array && index == -1) {
2471 int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
2472 int *array_a, *array_b;
2473
2474 array_a = (len_local > RNA_STACK_ARRAY) ?
2475 MEM_new_array_uninitialized<int>(size_t(len_local), __func__) :
2476 array_stack_a;
2477 RNA_property_int_get_array(ptr_reference, prop_reference, array_a);
2478
2479 switch (opop->operation) {
2480 case LIBOVERRIDE_OP_ADD:
2482 const int fac = opop->operation == LIBOVERRIDE_OP_ADD ? 1 : -1;
2483 const eID_OverrideLib_Op other_op = opop->operation == LIBOVERRIDE_OP_ADD ?
2486 bool do_set = true;
2487 array_b = (len_local > RNA_STACK_ARRAY) ?
2488 MEM_new_array_uninitialized<int>(size_t(len_local), __func__) :
2489 array_stack_b;
2490 RNA_property_int_get_array(ptr_local, prop_local, array_b);
2491 for (int i = len_local; i--;) {
2492 array_b[i] = fac * (array_b[i] - array_a[i]);
2493 if (array_b[i] < prop_min || array_b[i] > prop_max) {
2494 opop->operation = other_op;
2495 for (int j = len_local; j--;) {
2496 array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
2497 if (array_b[j] < prop_min || array_b[j] > prop_max) {
2498 /* We failed to find a suitable diff op,
2499 * fall back to plain REPLACE one. */
2500 opop->operation = LIBOVERRIDE_OP_REPLACE;
2501 do_set = false;
2502 break;
2503 }
2504 }
2505 break;
2506 }
2507 }
2508 if (do_set) {
2509 changed = true;
2510 RNA_property_int_set_array(ptr_storage, prop_storage, array_b);
2511 }
2512 if (array_b != array_stack_b) {
2513 MEM_delete(array_b);
2514 }
2515 break;
2516 }
2517 default:
2518 BLI_assert_msg(0, "Unsupported RNA override diff operation on integer");
2519 break;
2520 }
2521
2522 if (array_a != array_stack_a) {
2523 MEM_delete(array_a);
2524 }
2525 }
2526 else {
2527 const int value = RNA_PROPERTY_GET_SINGLE(int, ptr_reference, prop_reference, index);
2528
2529 switch (opop->operation) {
2530 case LIBOVERRIDE_OP_ADD:
2532 const int fac = opop->operation == LIBOVERRIDE_OP_ADD ? 1 : -1;
2533 const eID_OverrideLib_Op other_op = opop->operation == LIBOVERRIDE_OP_ADD ?
2536 int b = fac * (RNA_PROPERTY_GET_SINGLE(int, ptr_local, prop_local, index) - value);
2537 if (b < prop_min || b > prop_max) {
2538 opop->operation = other_op;
2539 b = -b;
2540 if (b < prop_min || b > prop_max) {
2541 opop->operation = LIBOVERRIDE_OP_REPLACE;
2542 break;
2543 }
2544 }
2545 changed = true;
2546 RNA_PROPERTY_SET_SINGLE(int, ptr_storage, prop_storage, index, b);
2547 break;
2548 }
2549 default:
2550 BLI_assert_msg(0, "Unsupported RNA override diff operation on integer");
2551 break;
2552 }
2553 }
2554 break;
2555 }
2556 case PROP_FLOAT: {
2557 float prop_min, prop_max;
2558 RNA_property_float_range(ptr_local, prop_local, &prop_min, &prop_max);
2559
2560 if (is_array && index == -1) {
2561 float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
2562 float *array_a, *array_b;
2563
2564 array_a = (len_local > RNA_STACK_ARRAY) ?
2565 MEM_new_array_uninitialized<float>(size_t(len_local), __func__) :
2566 array_stack_a;
2567
2568 RNA_property_float_get_array(ptr_reference, prop_reference, array_a);
2569 switch (opop->operation) {
2570 case LIBOVERRIDE_OP_ADD:
2572 const float fac = opop->operation == LIBOVERRIDE_OP_ADD ? 1.0 : -1.0;
2573 const eID_OverrideLib_Op other_op = opop->operation == LIBOVERRIDE_OP_ADD ?
2576 bool do_set = true;
2577 array_b = (len_local > RNA_STACK_ARRAY) ?
2578 MEM_new_array_uninitialized<float>(size_t(len_local), __func__) :
2579 array_stack_b;
2580 RNA_property_float_get_array(ptr_local, prop_local, array_b);
2581 for (int i = len_local; i--;) {
2582 array_b[i] = fac * (array_b[i] - array_a[i]);
2583 if (array_b[i] < prop_min || array_b[i] > prop_max) {
2584 opop->operation = other_op;
2585 for (int j = len_local; j--;) {
2586 array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
2587 if (array_b[j] < prop_min || array_b[j] > prop_max) {
2588 /* We failed to find a suitable diff op,
2589 * fall back to plain REPLACE one. */
2590 opop->operation = LIBOVERRIDE_OP_REPLACE;
2591 do_set = false;
2592 break;
2593 }
2594 }
2595 break;
2596 }
2597 }
2598 if (do_set) {
2599 changed = true;
2600 RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
2601 }
2602 if (array_b != array_stack_b) {
2603 MEM_delete(array_b);
2604 }
2605 break;
2606 }
2608 bool do_set = true;
2609 array_b = (len_local > RNA_STACK_ARRAY) ?
2610 MEM_new_array_uninitialized<float>(size_t(len_local), __func__) :
2611 array_stack_b;
2612 RNA_property_float_get_array(ptr_local, prop_local, array_b);
2613 for (int i = len_local; i--;) {
2614 array_b[i] = array_a[i] == 0.0f ? array_b[i] : array_b[i] / array_a[i];
2615 if (array_b[i] < prop_min || array_b[i] > prop_max) {
2616 opop->operation = LIBOVERRIDE_OP_REPLACE;
2617 do_set = false;
2618 break;
2619 }
2620 }
2621 if (do_set) {
2622 changed = true;
2623 RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
2624 }
2625 if (array_b != array_stack_b) {
2626 MEM_delete(array_b);
2627 }
2628 break;
2629 }
2630 default:
2631 BLI_assert_msg(0, "Unsupported RNA override diff operation on float");
2632 break;
2633 }
2634
2635 if (array_a != array_stack_a) {
2636 MEM_delete(array_a);
2637 }
2638 }
2639 else {
2640 const float value = RNA_PROPERTY_GET_SINGLE(float, ptr_reference, prop_reference, index);
2641
2642 switch (opop->operation) {
2643 case LIBOVERRIDE_OP_ADD:
2645 const float fac = opop->operation == LIBOVERRIDE_OP_ADD ? 1.0f : -1.0f;
2646 const eID_OverrideLib_Op other_op = opop->operation == LIBOVERRIDE_OP_ADD ?
2649 float b = fac * (RNA_PROPERTY_GET_SINGLE(float, ptr_local, prop_local, index) - value);
2650 if (b < prop_min || b > prop_max) {
2651 opop->operation = other_op;
2652 b = -b;
2653 if (b < prop_min || b > prop_max) {
2654 opop->operation = LIBOVERRIDE_OP_REPLACE;
2655 break;
2656 }
2657 }
2658 changed = true;
2659 RNA_PROPERTY_SET_SINGLE(float, ptr_storage, prop_storage, index, b);
2660 break;
2661 }
2663 const float b = RNA_property_float_get_index(ptr_local, prop_local, index) /
2664 (value == 0.0f ? 1.0f : value);
2665 if (b < prop_min || b > prop_max) {
2666 opop->operation = LIBOVERRIDE_OP_REPLACE;
2667 break;
2668 }
2669 changed = true;
2670 RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
2671 break;
2672 }
2673 default:
2674 BLI_assert_msg(0, "Unsupported RNA override diff operation on float");
2675 break;
2676 }
2677 }
2678 return true;
2679 }
2680 case PROP_ENUM:
2681 /* TODO: support add/sub, for bitflags? */
2682 BLI_assert_msg(0, "Enum properties support no override diff operation");
2683 break;
2684 case PROP_POINTER:
2685 BLI_assert_msg(0, "Pointer properties support no override diff operation");
2686 break;
2687 case PROP_STRING:
2688 BLI_assert_msg(0, "String properties support no override diff operation");
2689 break;
2690 case PROP_COLLECTION:
2691 /* XXX TODO: support this of course... */
2692 BLI_assert_msg(0, "Collection properties support no override diff operation");
2693 break;
2694 default:
2695 break;
2696 }
2697
2698 return changed;
2699}
2700
2702 RNAPropertyOverrideApplyContext &rnaapply_ctx)
2703{
2704 PointerRNA *ptr_dst = &rnaapply_ctx.ptr_dst;
2705 PointerRNA *ptr_src = &rnaapply_ctx.ptr_src;
2706 PointerRNA *ptr_storage = &rnaapply_ctx.ptr_storage;
2707 PropertyRNA *prop_dst = rnaapply_ctx.prop_dst;
2708 PropertyRNA *prop_src = rnaapply_ctx.prop_src;
2709 PropertyRNA *prop_storage = rnaapply_ctx.prop_storage;
2710 const int len_dst = rnaapply_ctx.len_src;
2711 const int len_src = rnaapply_ctx.len_src;
2712 const int len_storage = rnaapply_ctx.len_storage;
2713 IDOverrideLibraryPropertyOperation *opop = rnaapply_ctx.liboverride_operation;
2714
2715 const PropertyType prop_src_type = RNA_property_type(prop_src);
2716 const PropertyType prop_dst_type = RNA_property_type(prop_dst);
2717
2718 /* It is possible that a same exact RNA path points to a different property of a different type
2719 * (due to changes in the program, or in some custom data...). */
2720 if (prop_src_type != prop_dst_type ||
2721 (prop_storage && prop_src_type != RNA_property_type(prop_storage)))
2722 {
2723 std::optional<std::string> prop_rna_path = rnaapply_ctx.liboverride_property ?
2724 rnaapply_ctx.liboverride_property->rna_path :
2725 RNA_path_from_ID_to_property(ptr_dst, prop_dst);
2726 CLOG_WARN(&LOG_COMPARE_OVERRIDE,
2727 "%s.%s: Inconsistency between stored property type (%d) and linked reference one "
2728 "(%d), skipping liboverride apply",
2729 ptr_dst->owner_id->name,
2730 prop_rna_path ? prop_rna_path->c_str() :
2731 fmt::format(" ... .{}", prop_dst->name).c_str(),
2732 prop_src_type,
2733 prop_dst_type);
2734 /* Keep the liboverride property, update its type to the new actual one. */
2735 if (rnaapply_ctx.liboverride_property) {
2736 rnaapply_ctx.liboverride_property->rna_prop_type = prop_dst_type;
2737 }
2738 return false;
2739 }
2740
2741 BLI_assert(len_dst == len_src && (!prop_storage || len_dst == len_storage));
2742 UNUSED_VARS_NDEBUG(len_src, len_storage);
2743
2744 const bool is_array = len_dst > 0;
2745 const int index = is_array ? opop->subitem_reference_index : 0;
2746 const eID_OverrideLib_Op override_op = opop->operation;
2747
2748 bool ret_success = true;
2749
2750 switch (RNA_property_type(prop_dst)) {
2751 case PROP_BOOLEAN:
2752 if (is_array && index == -1) {
2753 bool array_stack_a[RNA_STACK_ARRAY];
2754 bool *array_a;
2755
2756 array_a = (len_dst > RNA_STACK_ARRAY) ?
2757 MEM_new_array_uninitialized<bool>(size_t(len_dst), __func__) :
2758 array_stack_a;
2759
2760 RNA_property_boolean_get_array(ptr_src, prop_src, array_a);
2761
2762 switch (override_op) {
2764 RNA_property_boolean_set_array(ptr_dst, prop_dst, array_a);
2765 break;
2766 default:
2767 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2768 "Unsupported '%s' RNA override operation on boolean array",
2769 BKE_lib_override_operation_as_string(override_op).c_str());
2770 return false;
2771 }
2772
2773 if (array_a != array_stack_a) {
2774 MEM_delete(array_a);
2775 }
2776 }
2777 else {
2778 const bool value = RNA_PROPERTY_GET_SINGLE(boolean, ptr_src, prop_src, index);
2779
2780 switch (override_op) {
2782 RNA_PROPERTY_SET_SINGLE(boolean, ptr_dst, prop_dst, index, value);
2783 break;
2784 default:
2785 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2786 "Unsupported '%s' RNA override operation on boolean",
2787 BKE_lib_override_operation_as_string(override_op).c_str());
2788 return false;
2789 }
2790 }
2791 break;
2792 case PROP_INT:
2793 if (is_array && index == -1) {
2794 int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
2795 int *array_a, *array_b;
2796
2797 array_a = (len_dst > RNA_STACK_ARRAY) ?
2798 MEM_new_array_uninitialized<int>(size_t(len_dst), __func__) :
2799 array_stack_a;
2800
2801 switch (override_op) {
2803 RNA_property_int_get_array(ptr_src, prop_src, array_a);
2804 RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
2805 break;
2806 case LIBOVERRIDE_OP_ADD:
2808 RNA_property_int_get_array(ptr_dst, prop_dst, array_a);
2809 array_b = (len_dst > RNA_STACK_ARRAY) ?
2810 MEM_new_array_uninitialized<int>(size_t(len_dst), __func__) :
2811 array_stack_b;
2812 RNA_property_int_get_array(ptr_storage, prop_storage, array_b);
2813 if (override_op == LIBOVERRIDE_OP_ADD) {
2814 for (int i = len_dst; i--;) {
2815 array_a[i] += array_b[i];
2816 }
2817 }
2818 else {
2819 for (int i = len_dst; i--;) {
2820 array_a[i] -= array_b[i];
2821 }
2822 }
2823 RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
2824 if (array_b != array_stack_b) {
2825 MEM_delete(array_b);
2826 }
2827 break;
2828 default:
2829 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2830 "Unsupported '%s' RNA override operation on integer array",
2831 BKE_lib_override_operation_as_string(override_op).c_str());
2832 return false;
2833 }
2834
2835 if (array_a != array_stack_a) {
2836 MEM_delete(array_a);
2837 }
2838 }
2839 else {
2840 const int storage_value = prop_storage ? RNA_PROPERTY_GET_SINGLE(
2841 int, ptr_storage, prop_storage, index) :
2842 0;
2843
2844 switch (override_op) {
2846 RNA_PROPERTY_SET_SINGLE(int,
2847 ptr_dst,
2848 prop_dst,
2849 index,
2850 RNA_PROPERTY_GET_SINGLE(int, ptr_src, prop_src, index));
2851 break;
2852 case LIBOVERRIDE_OP_ADD:
2853 RNA_PROPERTY_SET_SINGLE(int,
2854 ptr_dst,
2855 prop_dst,
2856 index,
2857 RNA_PROPERTY_GET_SINGLE(int, ptr_dst, prop_dst, index) -
2858 storage_value);
2859 break;
2861 RNA_PROPERTY_SET_SINGLE(int,
2862 ptr_dst,
2863 prop_dst,
2864 index,
2865 RNA_PROPERTY_GET_SINGLE(int, ptr_dst, prop_dst, index) -
2866 storage_value);
2867 break;
2868 default:
2869 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2870 "Unsupported '%s' RNA override operation on integer",
2871 BKE_lib_override_operation_as_string(override_op).c_str());
2872 return false;
2873 }
2874 }
2875 break;
2876 case PROP_FLOAT:
2877 if (is_array && index == -1) {
2878 float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
2879 float *array_a, *array_b;
2880
2881 array_a = (len_dst > RNA_STACK_ARRAY) ?
2882 MEM_new_array_uninitialized<float>(size_t(len_dst), __func__) :
2883 array_stack_a;
2884
2885 switch (override_op) {
2887 RNA_property_float_get_array(ptr_src, prop_src, array_a);
2888 RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
2889 break;
2890 case LIBOVERRIDE_OP_ADD:
2893 RNA_property_float_get_array(ptr_dst, prop_dst, array_a);
2894 array_b = (len_dst > RNA_STACK_ARRAY) ?
2895 MEM_new_array_uninitialized<float>(size_t(len_dst), __func__) :
2896 array_stack_b;
2897 RNA_property_float_get_array(ptr_storage, prop_storage, array_b);
2898 if (override_op == LIBOVERRIDE_OP_ADD) {
2899 for (int i = len_dst; i--;) {
2900 array_a[i] += array_b[i];
2901 }
2902 }
2903 else if (override_op == LIBOVERRIDE_OP_SUBTRACT) {
2904 for (int i = len_dst; i--;) {
2905 array_a[i] -= array_b[i];
2906 }
2907 }
2908 else {
2909 for (int i = len_dst; i--;) {
2910 array_a[i] *= array_b[i];
2911 }
2912 }
2913 RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
2914 if (array_b != array_stack_b) {
2915 MEM_delete(array_b);
2916 }
2917 break;
2918 default:
2919 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2920 "Unsupported '%s' RNA override operation on float array",
2921 BKE_lib_override_operation_as_string(override_op).c_str());
2922 return false;
2923 }
2924
2925 if (array_a != array_stack_a) {
2926 MEM_delete(array_a);
2927 }
2928 }
2929 else {
2930 const float storage_value = prop_storage ? RNA_PROPERTY_GET_SINGLE(
2931 float, ptr_storage, prop_storage, index) :
2932 0.0f;
2933
2934 switch (override_op) {
2936 RNA_PROPERTY_SET_SINGLE(float,
2937 ptr_dst,
2938 prop_dst,
2939 index,
2940 RNA_PROPERTY_GET_SINGLE(float, ptr_src, prop_src, index));
2941 break;
2942 case LIBOVERRIDE_OP_ADD:
2943 RNA_PROPERTY_SET_SINGLE(float,
2944 ptr_dst,
2945 prop_dst,
2946 index,
2947 RNA_PROPERTY_GET_SINGLE(float, ptr_dst, prop_dst, index) +
2948 storage_value);
2949 break;
2951 RNA_PROPERTY_SET_SINGLE(float,
2952 ptr_dst,
2953 prop_dst,
2954 index,
2955 RNA_PROPERTY_GET_SINGLE(float, ptr_dst, prop_dst, index) -
2956 storage_value);
2957 break;
2959 RNA_PROPERTY_SET_SINGLE(float,
2960 ptr_dst,
2961 prop_dst,
2962 index,
2963 RNA_PROPERTY_GET_SINGLE(float, ptr_dst, prop_dst, index) *
2964 storage_value);
2965 break;
2966 default:
2967 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2968 "Unsupported '%s' RNA override operation on float",
2969 BKE_lib_override_operation_as_string(override_op).c_str());
2970 return false;
2971 }
2972 }
2973 break;
2974 case PROP_ENUM: {
2975 const int value = RNA_property_enum_get(ptr_src, prop_src);
2976
2977 switch (override_op) {
2979 RNA_property_enum_set(ptr_dst, prop_dst, value);
2980 break;
2981 /* TODO: support add/sub, for bitflags? */
2982 default:
2983 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2984 "Unsupported '%s' RNA override operation on enum",
2985 BKE_lib_override_operation_as_string(override_op).c_str());
2986 return false;
2987 }
2988 break;
2989 }
2990 case PROP_POINTER: {
2991 PointerRNA value = RNA_property_pointer_get(ptr_src, prop_src);
2992
2993 switch (override_op) {
2995 RNA_property_pointer_set(ptr_dst, prop_dst, value, nullptr);
2996 break;
2997 default:
2998 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
2999 "Unsupported '%s' RNA override operation on pointer",
3000 BKE_lib_override_operation_as_string(override_op).c_str());
3001 return false;
3002 }
3003 break;
3004 }
3005 case PROP_STRING: {
3006 char buff[256];
3007 char *value = RNA_property_string_get_alloc(ptr_src, prop_src, buff, sizeof(buff), nullptr);
3008
3009 switch (override_op) {
3011 RNA_property_string_set(ptr_dst, prop_dst, value);
3012 break;
3013 default:
3014 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
3015 "Unsupported '%s' RNA override operation on string",
3016 BKE_lib_override_operation_as_string(override_op).c_str());
3017 return false;
3018 }
3019
3020 if (value != buff) {
3021 MEM_delete(value);
3022 }
3023 break;
3024 }
3025 case PROP_COLLECTION: {
3026 /* We only support IDProperty-based collection insertion here. */
3027 const bool is_src_idprop = (prop_src->magic != RNA_MAGIC) ||
3028 (prop_src->flag & PROP_IDPROPERTY) != 0;
3029 const bool is_dst_idprop = (prop_dst->magic != RNA_MAGIC) ||
3030 (prop_dst->flag & PROP_IDPROPERTY) != 0;
3031 if (!(is_src_idprop && is_dst_idprop)) {
3032 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
3033 "'%s': Override operations on RNA collections require a specific override "
3034 "apply callback to be defined.",
3035 rnaapply_ctx.liboverride_property->rna_path);
3036 return false;
3037 }
3038
3039 switch (override_op) {
3041 PointerRNA item_ptr_src, item_ptr_ref, item_ptr_dst;
3042 int item_index_dst;
3043 bool is_valid = false;
3044 if (opop->subitem_local_name != nullptr && opop->subitem_local_name[0] != '\0') {
3045 /* Find from name. */
3046 int item_index_src, item_index_ref;
3048 ptr_src, prop_src, opop->subitem_local_name, &item_ptr_src, &item_index_src) &&
3050 prop_dst,
3051 opop->subitem_reference_name,
3052 &item_ptr_ref,
3053 &item_index_ref))
3054 {
3055 is_valid = true;
3056 item_index_dst = item_index_ref + 1;
3057 }
3058 }
3059 if (!is_valid && opop->subitem_local_index >= 0) {
3060 /* Find from index. */
3062 ptr_src, prop_src, opop->subitem_local_index, &item_ptr_src) &&
3064 ptr_dst, prop_dst, opop->subitem_reference_index, &item_ptr_ref))
3065 {
3066 item_index_dst = opop->subitem_reference_index + 1;
3067 is_valid = true;
3068 }
3069 }
3070 if (!is_valid) {
3071 /* Assume it is inserted in first position. */
3072 if (RNA_property_collection_lookup_int(ptr_src, prop_src, 0, &item_ptr_src)) {
3073 item_index_dst = 0;
3074 is_valid = true;
3075 }
3076 }
3077 if (!is_valid) {
3078 return false;
3079 }
3080
3081 RNA_property_collection_add(ptr_dst, prop_dst, &item_ptr_dst);
3082 const int item_index_added = RNA_property_collection_length(ptr_dst, prop_dst) - 1;
3083 BLI_assert(item_index_added >= 0);
3084
3085 /* This is the section of code that makes it specific to IDProperties (the rest could be
3086 * used with some regular RNA/DNA data too, if `RNA_property_collection_add` where
3087 * actually implemented for those).
3088 * Currently it is close to impossible to copy arbitrary 'real' RNA data between
3089 * Collection items. */
3090 IDProperty *item_idprop_src = static_cast<IDProperty *>(item_ptr_src.data);
3091 IDProperty *item_idprop_dst = static_cast<IDProperty *>(item_ptr_dst.data);
3092 IDP_CopyPropertyContent(item_idprop_dst, item_idprop_src);
3093
3094 ret_success = RNA_property_collection_move(
3095 ptr_dst, prop_dst, item_index_added, item_index_dst) ==
3096 eRNAStatus::Success;
3097 break;
3098 }
3099 default:
3100 CLOG_ERROR(&LOG_COMPARE_OVERRIDE,
3101 "Unsupported '%s' RNA override operation on collection",
3102 BKE_lib_override_operation_as_string(override_op).c_str());
3103 return false;
3104 }
3105 break;
3106 }
3107 default:
3109 return false;
3110 }
3111
3112 /* Default apply callback always call property update. */
3113 if (ret_success) {
3114 RNA_property_update_main(bmain, nullptr, ptr_dst, prop_dst);
3115 }
3116
3117 return ret_success;
3118}
3119
3120# undef RNA_PROPERTY_GET_SINGLE
3121# undef RNA_PROPERTY_SET_SINGLE
3122
3124
3125/* -------------------------------------------------------------------- */
3128
3129/* Primitive String. */
3130
3131static void rna_PrimitiveString_value_get(PointerRNA *ptr, char *result)
3132{
3133 const PrimitiveStringRNA *data = static_cast<const PrimitiveStringRNA *>(ptr->data);
3134 strcpy(result, data->value ? data->value : "");
3135}
3136
3137static int rna_PrimitiveString_value_length(PointerRNA *ptr)
3138{
3139 const PrimitiveStringRNA *data = static_cast<const PrimitiveStringRNA *>(ptr->data);
3140 return data->value ? strlen(data->value) : 0;
3141}
3142
3143/* Primitive Int. */
3144
3145static int rna_PrimitiveInt_value_get(PointerRNA *ptr)
3146{
3147 const PrimitiveIntRNA *data = static_cast<const PrimitiveIntRNA *>(ptr->data);
3148 return data->value;
3149}
3150
3151/* Primitive Float. */
3152
3153static float rna_PrimitiveFloat_value_get(PointerRNA *ptr)
3154{
3155 const PrimitiveFloatRNA *data = static_cast<const PrimitiveFloatRNA *>(ptr->data);
3156 return data->value;
3157}
3158
3159/* Primitive Boolean. */
3160
3161static bool rna_PrimitiveBoolean_value_get(PointerRNA *ptr)
3162{
3163 const PrimitiveBooleanRNA *data = static_cast<const PrimitiveBooleanRNA *>(ptr->data);
3164 return data->value;
3165}
3166
3168
3169} // namespace blender
3170
3171#else
3172
3173namespace blender {
3174
3175static void rna_def_struct(BlenderRNA *brna)
3176{
3177 StructRNA *srna;
3178 PropertyRNA *prop;
3179
3180 srna = RNA_def_struct(brna, "Struct", nullptr);
3181 RNA_def_struct_ui_text(srna, "Struct Definition", "RNA structure definition");
3182 RNA_def_struct_ui_icon(srna, ICON_RNA);
3184
3185 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
3187 RNA_def_property_string_funcs(prop, "rna_Struct_name_get", "rna_Struct_name_length", nullptr);
3188 RNA_def_property_ui_text(prop, "Name", "Human readable name");
3189
3190 prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
3193 prop, "rna_Struct_identifier_get", "rna_Struct_identifier_length", nullptr);
3194 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
3195 RNA_def_struct_name_property(srna, prop);
3196
3197 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
3200 prop, "rna_Struct_description_get", "rna_Struct_description_length", nullptr);
3201 RNA_def_property_ui_text(prop, "Description", "Description of the Struct's purpose");
3202
3203 prop = RNA_def_property(srna, "translation_context", PROP_STRING, PROP_NONE);
3206 "rna_Struct_translation_context_get",
3207 "rna_Struct_translation_context_length",
3208 nullptr);
3210 prop, "Translation Context", "Translation context of the struct's name");
3211
3212 prop = RNA_def_property(srna, "base", PROP_POINTER, PROP_NONE);
3214 RNA_def_property_struct_type(prop, "Struct");
3215 RNA_def_property_pointer_funcs(prop, "rna_Struct_base_get", nullptr, nullptr, nullptr);
3216 RNA_def_property_ui_text(prop, "Base", "Struct definition this is derived from");
3217
3218 prop = RNA_def_property(srna, "nested", PROP_POINTER, PROP_NONE);
3220 RNA_def_property_struct_type(prop, "Struct");
3221 RNA_def_property_pointer_funcs(prop, "rna_Struct_nested_get", nullptr, nullptr, nullptr);
3223 prop,
3224 "Nested",
3225 "Struct in which this struct is always nested, and to which it logically belongs");
3226
3227 prop = RNA_def_property(srna, "name_property", PROP_POINTER, PROP_NONE);
3229 RNA_def_property_struct_type(prop, "StringProperty");
3230 RNA_def_property_pointer_funcs(prop, "rna_Struct_name_property_get", nullptr, nullptr, nullptr);
3231 RNA_def_property_ui_text(prop, "Name Property", "Property that gives the name of the struct");
3232
3233 prop = RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE);
3235 RNA_def_property_struct_type(prop, "Property");
3237 "rna_Struct_properties_begin",
3238 "rna_Struct_properties_next",
3239 "rna_iterator_listbase_end",
3240 "rna_Struct_properties_get",
3241 nullptr,
3242 nullptr,
3243 nullptr,
3244 nullptr);
3245 RNA_def_property_ui_text(prop, "Properties", "Properties in the struct");
3246
3247 prop = RNA_def_property(srna, "functions", PROP_COLLECTION, PROP_NONE);
3249 RNA_def_property_struct_type(prop, "Function");
3251 "rna_Struct_functions_begin",
3252 "rna_iterator_array_next",
3253 "rna_iterator_array_end",
3254 "rna_Struct_functions_get",
3255 nullptr,
3256 nullptr,
3257 nullptr,
3258 nullptr);
3259 RNA_def_property_ui_text(prop, "Functions", "");
3260
3261 prop = RNA_def_property(srna, "property_tags", PROP_COLLECTION, PROP_NONE);
3263 RNA_def_property_struct_type(prop, "EnumPropertyItem");
3265 "rna_Struct_property_tags_begin",
3266 "rna_iterator_array_next",
3267 "rna_iterator_array_end",
3268 "rna_iterator_array_get",
3269 nullptr,
3270 nullptr,
3271 nullptr,
3272 nullptr);
3274 prop, "Property Tags", "Tags that properties can use to influence behavior");
3275}
3276
3278{
3279 StructRNA *srna;
3280 PropertyRNA *prop;
3281 static const EnumPropertyItem dummy_prop_tags[] = {
3282 {0, nullptr, 0, nullptr, nullptr},
3283 };
3284
3285 srna = RNA_def_struct(brna, "Property", nullptr);
3286 RNA_def_struct_ui_text(srna, "Property Definition", "RNA property definition");
3287 RNA_def_struct_refine_func(srna, "rna_Property_refine");
3288 RNA_def_struct_ui_icon(srna, ICON_RNA);
3290
3291 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
3294 prop, "rna_Property_name_get", "rna_Property_name_length", nullptr);
3295 RNA_def_property_ui_text(prop, "Name", "Human readable name");
3296
3297 prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
3300 prop, "rna_Property_identifier_get", "rna_Property_identifier_length", nullptr);
3301 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
3302 RNA_def_struct_name_property(srna, prop);
3303
3304 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
3307 prop, "rna_Property_description_get", "rna_Property_description_length", nullptr);
3308 RNA_def_property_ui_text(prop, "Description", "Description of the property for tooltips");
3309
3310 prop = RNA_def_property(srna, "translation_context", PROP_STRING, PROP_NONE);
3313 "rna_Property_translation_context_get",
3314 "rna_Property_translation_context_length",
3315 nullptr);
3317 prop, "Translation Context", "Translation context of the property's name");
3318
3319 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
3322 RNA_def_property_enum_funcs(prop, "rna_Property_type_get", nullptr, nullptr);
3323 RNA_def_property_ui_text(prop, "Type", "Data type of the property");
3324
3325 prop = RNA_def_property(srna, "subtype", PROP_ENUM, PROP_NONE);
3328 RNA_def_property_enum_funcs(prop, "rna_Property_subtype_get", nullptr, nullptr);
3329 RNA_def_property_ui_text(prop, "Subtype", "Semantic interpretation of the property");
3331
3332 prop = RNA_def_property(srna, "srna", PROP_POINTER, PROP_NONE);
3334 RNA_def_property_struct_type(prop, "Struct");
3335 RNA_def_property_pointer_funcs(prop, "rna_Property_srna_get", nullptr, nullptr, nullptr);
3337 prop, "Base", "Struct definition used for properties assigned to this item");
3338
3339 prop = RNA_def_property(srna, "unit", PROP_ENUM, PROP_NONE);
3343 RNA_def_property_enum_funcs(prop, "rna_Property_unit_get", nullptr, nullptr);
3344 RNA_def_property_ui_text(prop, "Unit", "Type of units for this property");
3345
3346 prop = RNA_def_property(srna, "icon", PROP_ENUM, PROP_NONE);
3349 RNA_def_property_enum_funcs(prop, "rna_Property_icon_get", nullptr, nullptr);
3350 RNA_def_property_ui_text(prop, "Icon", "Icon of the item");
3351
3352 prop = RNA_def_property(srna, "is_readonly", PROP_BOOLEAN, PROP_NONE);
3354 RNA_def_property_boolean_funcs(prop, "rna_Property_readonly_get", nullptr);
3355 RNA_def_property_ui_text(prop, "Read Only", "Property is editable through RNA");
3356
3357 prop = RNA_def_property(srna, "is_animatable", PROP_BOOLEAN, PROP_NONE);
3359 RNA_def_property_boolean_funcs(prop, "rna_Property_animatable_get", nullptr);
3360 RNA_def_property_ui_text(prop, "Animatable", "Property is animatable through RNA");
3361
3362 prop = RNA_def_property(srna, "is_overridable", PROP_BOOLEAN, PROP_NONE);
3364 RNA_def_property_boolean_funcs(prop, "rna_Property_overridable_get", nullptr);
3365 RNA_def_property_ui_text(prop, "Overridable", "Property is overridable through RNA");
3366
3367 prop = RNA_def_property(srna, "is_required", PROP_BOOLEAN, PROP_NONE);
3369 RNA_def_property_boolean_funcs(prop, "rna_Property_is_required_get", nullptr);
3371 prop, "Required", "False when this property is an optional argument in an RNA function");
3372
3373 prop = RNA_def_property(srna, "is_argument_optional", PROP_BOOLEAN, PROP_NONE);
3375 RNA_def_property_boolean_funcs(prop, "rna_Property_is_argument_optional_get", nullptr);
3377 prop,
3378 "Optional Argument",
3379 "True when the property is optional in a Python function implementing an RNA function");
3380
3381 prop = RNA_def_property(srna, "is_never_none", PROP_BOOLEAN, PROP_NONE);
3383 RNA_def_property_boolean_funcs(prop, "rna_Property_is_never_none_get", nullptr);
3384 RNA_def_property_ui_text(prop, "Never None", "True when this value cannot be set to None");
3385
3386 prop = RNA_def_property(srna, "is_hidden", PROP_BOOLEAN, PROP_NONE);
3388 RNA_def_property_boolean_funcs(prop, "rna_Property_is_hidden_get", nullptr);
3389 RNA_def_property_ui_text(prop, "Hidden", "True when the property is hidden");
3390
3391 prop = RNA_def_property(srna, "is_skip_save", PROP_BOOLEAN, PROP_NONE);
3393 RNA_def_property_boolean_funcs(prop, "rna_Property_is_skip_save_get", nullptr);
3394 RNA_def_property_ui_text(prop, "Skip Save", "True when the property uses ghost values");
3395
3396 prop = RNA_def_property(srna, "is_skip_preset", PROP_BOOLEAN, PROP_NONE);
3398 RNA_def_property_boolean_funcs(prop, "rna_Property_is_skip_preset_get", nullptr);
3399 RNA_def_property_ui_text(prop, "Skip Preset", "True when the property is not saved in presets");
3400
3401 prop = RNA_def_property(srna, "is_output", PROP_BOOLEAN, PROP_NONE);
3403 RNA_def_property_boolean_funcs(prop, "rna_Property_use_output_get", nullptr);
3405 prop, "Return", "True when this property is an output value from an RNA function");
3406
3407 prop = RNA_def_property(srna, "is_registered", PROP_BOOLEAN, PROP_NONE);
3409 RNA_def_property_boolean_funcs(prop, "rna_Property_is_registered_get", nullptr);
3411 prop, "Registered", "Property is registered as part of type registration");
3412
3413 prop = RNA_def_property(srna, "is_registered_optional", PROP_BOOLEAN, PROP_NONE);
3415 RNA_def_property_boolean_funcs(prop, "rna_Property_is_registered_optional_get", nullptr);
3417 "Registered Optionally",
3418 "Property is optionally registered as part of type registration");
3419
3420 prop = RNA_def_property(srna, "is_runtime", PROP_BOOLEAN, PROP_NONE);
3422 RNA_def_property_boolean_funcs(prop, "rna_Property_is_runtime_get", nullptr);
3423 RNA_def_property_ui_text(prop, "Runtime", "Property has been dynamically created at runtime");
3424
3425 prop = RNA_def_property(srna, "is_enum_flag", PROP_BOOLEAN, PROP_NONE);
3427 RNA_def_property_boolean_funcs(prop, "rna_Property_is_enum_flag_get", nullptr);
3428 RNA_def_property_ui_text(prop, "Enum Flag", "True when multiple enums");
3429
3430 prop = RNA_def_property(srna, "is_library_editable", PROP_BOOLEAN, PROP_NONE);
3432 RNA_def_property_boolean_funcs(prop, "rna_Property_is_library_editable_flag_get", nullptr);
3434 prop, "Library Editable", "Property is editable from linked instances (changes not saved)");
3435
3436 prop = RNA_def_property(srna, "is_path_output", PROP_BOOLEAN, PROP_NONE);
3438 RNA_def_property_boolean_funcs(prop, "rna_Property_is_path_output_flag_get", nullptr);
3440 prop, "Path Output", "Property is a filename, filepath or directory output");
3441
3442 prop = RNA_def_property(srna, "is_path_supports_blend_relative", PROP_BOOLEAN, PROP_NONE);
3445 prop, "rna_Property_is_path_supports_blend_relative_flag_get", nullptr);
3447 prop,
3448 "Path Relative",
3449 "Property is a path which supports the \"//\" prefix, "
3450 "signifying the location as relative to the \".blend\" file's directory");
3451
3452 prop = RNA_def_property(srna, "is_path_supports_templates", PROP_BOOLEAN, PROP_NONE);
3455 prop, "rna_Property_is_path_supports_templates_flag_get", nullptr);
3457 prop,
3458 "Variable Expression Support",
3459 "Property is a path which supports the \"{variable_name}\" variable expression syntax, "
3460 "which substitutes the value of the referenced variable in place of the expression");
3461
3462 prop = RNA_def_property(srna, "is_deprecated", PROP_BOOLEAN, PROP_NONE);
3464 RNA_def_property_boolean_funcs(prop, "rna_Property_is_deprecated_get", nullptr);
3465 RNA_def_property_ui_text(prop, "Deprecated", "The property is deprecated");
3466
3467 prop = RNA_def_property(srna, "deprecated_note", PROP_STRING, PROP_NONE);
3470 prop, "rna_Property_deprecated_note_get", "rna_Property_deprecated_note_length", nullptr);
3471 RNA_def_property_ui_text(prop, "Deprecated Note", "A note regarding deprecation");
3472
3473 prop = RNA_def_property(srna, "deprecated_version", PROP_INT, PROP_NONE);
3475 /* Use 3 values to match `bpy.app.version`. */
3476 RNA_def_property_array(prop, 3);
3477 RNA_def_property_ui_text(prop, "Deprecated Version", "The Blender version this was deprecated");
3478 RNA_def_property_int_funcs(prop, "rna_Property_deprecated_version_get", nullptr, nullptr);
3479
3480 prop = RNA_def_property(srna, "deprecated_removal_version", PROP_INT, PROP_NONE);
3482 RNA_def_property_array(prop, 3);
3484 prop, "Deprecated Removal Version", "The Blender version this is expected to be removed");
3486 prop, "rna_Property_deprecated_removal_version_get", nullptr, nullptr);
3487
3488 prop = RNA_def_property(srna, "tags", PROP_ENUM, PROP_NONE);
3491 RNA_def_property_enum_items(prop, dummy_prop_tags);
3492 RNA_def_property_enum_funcs(prop, "rna_Property_tags_get", nullptr, "rna_Property_tags_itemf");
3494 prop, "Tags", "Subset of tags (defined in parent struct) that are set for this property");
3495}
3496
3498{
3499 StructRNA *srna;
3500 PropertyRNA *prop;
3501
3502 srna = RNA_def_struct(brna, "Function", nullptr);
3503 /* While this is technically a meta-data definition, functions never really wrap actual data, so
3504 * all of there parameters should always be accessible.
3505 *
3506 * TODO: Re-check this and see if maybe all parameters of functions should automatically be
3507 * tagged as `PROP_INTERN_RNA_DEFINITION` instead? */
3508 // RNA_def_struct_flag(srna, STRUCT_RNA_DEFINITION);
3509 RNA_def_struct_ui_text(srna, "Function Definition", "RNA function definition");
3510 RNA_def_struct_ui_icon(srna, ICON_RNA);
3511
3512 prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
3515 prop, "rna_Function_identifier_get", "rna_Function_identifier_length", nullptr);
3516 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
3517 RNA_def_struct_name_property(srna, prop);
3518
3519 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
3522 prop, "rna_Function_description_get", "rna_Function_description_length", nullptr);
3523 RNA_def_property_ui_text(prop, "Description", "Description of the Function's purpose");
3524
3525 prop = RNA_def_property(srna, "parameters", PROP_COLLECTION, PROP_NONE);
3526 // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
3527 RNA_def_property_struct_type(prop, "Property");
3529 "rna_Function_parameters_begin",
3530 "rna_iterator_listbase_next",
3531 "rna_iterator_listbase_end",
3532 "rna_iterator_listbase_get",
3533 nullptr,
3534 nullptr,
3535 nullptr,
3536 nullptr);
3537 RNA_def_property_ui_text(prop, "Parameters", "Parameters for the function");
3538
3539 prop = RNA_def_property(srna, "is_registered", PROP_BOOLEAN, PROP_NONE);
3541 RNA_def_property_boolean_funcs(prop, "rna_Function_registered_get", nullptr);
3543 prop, "Registered", "Function is registered as callback as part of type registration");
3544
3545 prop = RNA_def_property(srna, "is_registered_optional", PROP_BOOLEAN, PROP_NONE);
3547 RNA_def_property_boolean_funcs(prop, "rna_Function_registered_optional_get", nullptr);
3549 prop,
3550 "Registered Optionally",
3551 "Function is optionally registered as callback part of type registration");
3552
3553 prop = RNA_def_property(srna, "use_self", PROP_BOOLEAN, PROP_NONE);
3555 RNA_def_property_boolean_funcs(prop, "rna_Function_no_self_get", nullptr);
3557 prop,
3558 "No Self",
3559 "Function does not pass itself as an argument (becomes a static method in Python)");
3560
3561 prop = RNA_def_property(srna, "use_self_type", PROP_BOOLEAN, PROP_NONE);
3563 RNA_def_property_boolean_funcs(prop, "rna_Function_use_self_type_get", nullptr);
3565 "Use Self Type",
3566 "Function passes itself type as an argument (becomes a class method "
3567 "in Python if use_self is false)");
3568}
3569
3571{
3572 PropertyRNA *prop;
3573
3574 prop = RNA_def_property(srna, "default", type, PROP_NONE);
3576 RNA_def_property_ui_text(prop, "Default", "Default value for this number");
3577
3578 switch (type) {
3579 case PROP_BOOLEAN:
3580 RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_get", nullptr);
3581 break;
3582 case PROP_INT:
3583 RNA_def_property_int_funcs(prop, "rna_IntProperty_default_get", nullptr, nullptr);
3584 break;
3585 case PROP_FLOAT:
3586 RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_get", nullptr, nullptr);
3587 break;
3588 default:
3589 break;
3590 }
3591
3592 prop = RNA_def_property(srna, "default_array", type, PROP_NONE);
3594
3595 /* no fixed default length, important its not 0 though. */
3597
3600 prop, "rna_NumberProperty_default_array_get_length"); /* same for all types */
3601
3602 switch (type) {
3603 case PROP_BOOLEAN:
3604 RNA_def_property_boolean_funcs(prop, "rna_BoolProperty_default_array_get", nullptr);
3605 break;
3606 case PROP_INT:
3607 RNA_def_property_int_funcs(prop, "rna_IntProperty_default_array_get", nullptr, nullptr);
3608 break;
3609 case PROP_FLOAT:
3610 RNA_def_property_float_funcs(prop, "rna_FloatProperty_default_array_get", nullptr, nullptr);
3611 break;
3612 default:
3613 break;
3614 }
3615 RNA_def_property_ui_text(prop, "Default Array", "Default value for this array");
3616
3617 prop = RNA_def_property(srna, "array_length", PROP_INT, PROP_UNSIGNED);
3619 RNA_def_property_int_funcs(prop, "rna_Property_array_length_get", nullptr, nullptr);
3620 RNA_def_property_ui_text(prop, "Array Length", "Maximum length of the array, 0 means unlimited");
3621
3622 prop = RNA_def_property(srna, "array_dimensions", PROP_INT, PROP_UNSIGNED);
3625 RNA_def_property_int_funcs(prop, "rna_Property_array_dimensions_get", nullptr, nullptr);
3626 RNA_def_property_ui_text(prop, "Array Dimensions", "Length of each dimension of the array");
3627
3628 prop = RNA_def_property(srna, "is_array", PROP_BOOLEAN, PROP_NONE);
3630 RNA_def_property_boolean_funcs(prop, "rna_NumberProperty_is_array_get", nullptr);
3631 RNA_def_property_ui_text(prop, "Is Array", "");
3632
3633 if (type == PROP_BOOLEAN) {
3634 return;
3635 }
3636
3637 prop = RNA_def_property(srna, "hard_min", type, PROP_NONE);
3639 if (type == PROP_INT) {
3640 RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_min_get", nullptr, nullptr);
3641 }
3642 else {
3643 RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_min_get", nullptr, nullptr);
3644 }
3646 prop,
3647 "Hard Minimum",
3648 "Hard minimum, trying to assign a value below will silently assign this minimum instead");
3649
3650 prop = RNA_def_property(srna, "hard_max", type, PROP_NONE);
3652 if (type == PROP_INT) {
3653 RNA_def_property_int_funcs(prop, "rna_IntProperty_hard_max_get", nullptr, nullptr);
3654 }
3655 else {
3656 RNA_def_property_float_funcs(prop, "rna_FloatProperty_hard_max_get", nullptr, nullptr);
3657 }
3659 prop,
3660 "Hard Maximum",
3661 "Hard maximum, trying to assign a value above will silently assign this maximum instead");
3662
3663 prop = RNA_def_property(srna, "soft_min", type, PROP_NONE);
3665 if (type == PROP_INT) {
3666 RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_min_get", nullptr, nullptr);
3667 }
3668 else {
3669 RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_min_get", nullptr, nullptr);
3670 }
3672 prop,
3673 "Soft Minimum",
3674 "Soft minimum (>= hard_min), user cannot drag widgets below this value in the UI");
3675
3676 prop = RNA_def_property(srna, "soft_max", type, PROP_NONE);
3678 if (type == PROP_INT) {
3679 RNA_def_property_int_funcs(prop, "rna_IntProperty_soft_max_get", nullptr, nullptr);
3680 }
3681 else {
3682 RNA_def_property_float_funcs(prop, "rna_FloatProperty_soft_max_get", nullptr, nullptr);
3683 }
3685 prop,
3686 "Soft Maximum",
3687 "Soft maximum (<= hard_max), user cannot drag widgets above this value in the UI");
3688
3689 prop = RNA_def_property(srna, "step", type, PROP_UNSIGNED);
3691 if (type == PROP_INT) {
3692 RNA_def_property_int_funcs(prop, "rna_IntProperty_step_get", nullptr, nullptr);
3693 }
3694 else {
3695 RNA_def_property_float_funcs(prop, "rna_FloatProperty_step_get", nullptr, nullptr);
3696 }
3698 prop, "Step", "Step size used by number buttons, for floats 1/100th of the step size");
3699
3700 if (type == PROP_FLOAT) {
3701 prop = RNA_def_property(srna, "precision", PROP_INT, PROP_UNSIGNED);
3703 RNA_def_property_int_funcs(prop, "rna_FloatProperty_precision_get", nullptr, nullptr);
3705 "Precision",
3706 "Number of digits after the dot used by buttons. Fraction is "
3707 "automatically hidden for exact integer values of fields with unit "
3708 "'NONE' or 'TIME' (frame count) and step divisible by 100.");
3709 }
3710}
3711
3713{
3714 PropertyRNA *prop;
3715
3716 prop = RNA_def_property(srna, "default", PROP_STRING, PROP_NONE);
3719 prop, "rna_StringProperty_default_get", "rna_StringProperty_default_length", nullptr);
3720 RNA_def_property_ui_text(prop, "Default", "String default value");
3721
3722 prop = RNA_def_property(srna, "length_max", PROP_INT, PROP_UNSIGNED);
3724 RNA_def_property_int_funcs(prop, "rna_StringProperty_max_length_get", nullptr, nullptr);
3726 prop, "Maximum Length", "Maximum length of the string, 0 means unlimited");
3727}
3728
3730{
3731 PropertyRNA *prop;
3732
3733 prop = RNA_def_property(srna, "default", PROP_ENUM, PROP_NONE);
3737 prop, "rna_EnumProperty_default_get", nullptr, "rna_EnumProperty_default_itemf");
3738 RNA_def_property_ui_text(prop, "Default", "Default value for this enum");
3739
3740 /* same 'default' but uses 'PROP_ENUM_FLAG' */
3741 prop = RNA_def_property(srna, "default_flag", PROP_ENUM, PROP_NONE);
3746 prop, "rna_EnumProperty_default_get", nullptr, "rna_EnumProperty_default_itemf");
3747 RNA_def_property_ui_text(prop, "Default", "Default value for this enum");
3748
3749 prop = RNA_def_property(srna, "enum_items", PROP_COLLECTION, PROP_NONE);
3751 RNA_def_property_struct_type(prop, "EnumPropertyItem");
3753 "rna_EnumProperty_items_begin",
3754 "rna_iterator_array_next",
3755 "rna_iterator_array_end",
3756 "rna_iterator_array_get",
3757 nullptr,
3758 nullptr,
3759 nullptr,
3760 nullptr);
3761 RNA_def_property_ui_text(prop, "Items", "Possible values for the property");
3762
3763 prop = RNA_def_property(srna, "enum_items_static", PROP_COLLECTION, PROP_NONE);
3765 RNA_def_property_struct_type(prop, "EnumPropertyItem");
3767 "rna_EnumProperty_items_begin",
3768 "rna_iterator_array_next",
3769 "rna_iterator_array_end",
3770 "rna_iterator_array_get",
3771 nullptr,
3772 nullptr,
3773 nullptr,
3774 nullptr);
3776 prop,
3777 "Static Items",
3778 "Possible values for the property (never calls optional dynamic generation of those)");
3779
3780 /* Expose a UI version of `enum_items_static` to allow separator & title access,
3781 * needed for the tool-system to access separators from brush enums. */
3782 prop = RNA_def_property(srna, "enum_items_static_ui", PROP_COLLECTION, PROP_NONE);
3784 RNA_def_property_struct_type(prop, "EnumPropertyItem");
3786 "rna_EnumProperty_items_ui_begin",
3787 "rna_iterator_array_next",
3788 "rna_iterator_array_end",
3789 "rna_iterator_array_get",
3790 nullptr,
3791 nullptr,
3792 nullptr,
3793 nullptr);
3795 prop,
3796 "Static Items with UI Elements",
3797 "Possible values for the property (never calls optional dynamic generation of those). "
3798 "Includes UI elements (separators and section headings).");
3799
3800 srna = RNA_def_struct(brna, "EnumPropertyItem", nullptr);
3803 srna, "Enum Item Definition", "Definition of a choice in an RNA enum property");
3804 RNA_def_struct_ui_icon(srna, ICON_RNA);
3805
3806 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
3809 prop, "rna_EnumPropertyItem_name_get", "rna_EnumPropertyItem_name_length", nullptr);
3810 RNA_def_property_ui_text(prop, "Name", "Human readable name");
3811
3812 prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
3815 "rna_EnumPropertyItem_description_get",
3816 "rna_EnumPropertyItem_description_length",
3817 nullptr);
3818 RNA_def_property_ui_text(prop, "Description", "Description of the item's purpose");
3819
3820 prop = RNA_def_property(srna, "identifier", PROP_STRING, PROP_NONE);
3823 "rna_EnumPropertyItem_identifier_get",
3824 "rna_EnumPropertyItem_identifier_length",
3825 nullptr);
3826 RNA_def_property_ui_text(prop, "Identifier", "Unique name used in the code and scripting");
3827 RNA_def_struct_name_property(srna, prop);
3828
3829 prop = RNA_def_property(srna, "value", PROP_INT, PROP_UNSIGNED);
3831 RNA_def_property_int_funcs(prop, "rna_EnumPropertyItem_value_get", nullptr, nullptr);
3832 RNA_def_property_ui_text(prop, "Value", "Value of the item");
3833
3834 prop = RNA_def_property(srna, "icon", PROP_ENUM, PROP_NONE);
3837 RNA_def_property_enum_funcs(prop, "rna_EnumPropertyItem_icon_get", nullptr, nullptr);
3838 RNA_def_property_ui_text(prop, "Icon", "Icon of the item");
3839}
3840
3842{
3843 PropertyRNA *prop;
3844
3845 prop = RNA_def_property(srna, "fixed_type", PROP_POINTER, PROP_NONE);
3847 RNA_def_property_struct_type(prop, "Struct");
3848 if (type == PROP_POINTER) {
3850 prop, "rna_PointerProperty_fixed_type_get", nullptr, nullptr, nullptr);
3851 }
3852 else {
3854 prop, "rna_CollectionProperty_fixed_type_get", nullptr, nullptr, nullptr);
3855 }
3856 RNA_def_property_ui_text(prop, "Pointer Type", "Fixed pointer type, empty if variable type");
3857}
3858
3860{
3861 /* Primitive Values, use when passing #PointerRNA is used for primitive types.
3862 * For the rare cases we want to pass a value as RNA which wraps a primitive data. */
3863
3864 StructRNA *srna;
3865 PropertyRNA *prop;
3866
3867 srna = RNA_def_struct(brna, "PrimitiveString", nullptr);
3868 RNA_def_struct_ui_text(srna, "String Value", "RNA wrapped string");
3869 prop = RNA_def_property(srna, "value", PROP_STRING, PROP_BYTESTRING);
3872 prop, "rna_PrimitiveString_value_get", "rna_PrimitiveString_value_length", nullptr);
3873
3874 srna = RNA_def_struct(brna, "PrimitiveInt", nullptr);
3875 RNA_def_struct_ui_text(srna, "Primitive Int", "RNA wrapped int");
3876 prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
3878 RNA_def_property_int_funcs(prop, "rna_PrimitiveInt_value_get", nullptr, nullptr);
3879
3880 srna = RNA_def_struct(brna, "PrimitiveFloat", nullptr);
3881 RNA_def_struct_ui_text(srna, "Primitive Float", "RNA wrapped float");
3882 prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
3884 RNA_def_property_float_funcs(prop, "rna_PrimitiveFloat_value_get", nullptr, nullptr);
3885
3886 srna = RNA_def_struct(brna, "PrimitiveBoolean", nullptr);
3887 RNA_def_struct_ui_text(srna, "Primitive Boolean", "RNA wrapped boolean");
3888 prop = RNA_def_property(srna, "value", PROP_BOOLEAN, PROP_NONE);
3890 RNA_def_property_boolean_funcs(prop, "rna_PrimitiveBoolean_value_get", nullptr);
3891}
3892
3894{
3895 StructRNA *srna;
3896 PropertyRNA *prop;
3897
3898 /* Struct */
3899 rna_def_struct(brna);
3900
3901 /* Property */
3902 rna_def_property(brna);
3903
3904 /* BoolProperty */
3905 srna = RNA_def_struct(brna, "BoolProperty", "Property");
3906 RNA_def_struct_ui_text(srna, "Boolean Definition", "RNA boolean property definition");
3908
3909 /* IntProperty */
3910 srna = RNA_def_struct(brna, "IntProperty", "Property");
3911 RNA_def_struct_ui_text(srna, "Int Definition", "RNA integer number property definition");
3913
3914 /* FloatProperty */
3915 srna = RNA_def_struct(brna, "FloatProperty", "Property");
3917 "Float Definition",
3918 "RNA floating-point number (single precision) property definition");
3920
3921 /* StringProperty */
3922 srna = RNA_def_struct(brna, "StringProperty", "Property");
3923 RNA_def_struct_ui_text(srna, "String Definition", "RNA text string property definition");
3925
3926 /* EnumProperty */
3927 srna = RNA_def_struct(brna, "EnumProperty", "Property");
3929 srna,
3930 "Enum Definition",
3931 "RNA enumeration property definition, to choose from a number of predefined options");
3932 rna_def_enum_property(brna, srna);
3933
3934 /* PointerProperty */
3935 srna = RNA_def_struct(brna, "PointerProperty", "Property");
3937 srna, "Pointer Definition", "RNA pointer property to point to another RNA struct");
3939
3940 /* CollectionProperty */
3941 srna = RNA_def_struct(brna, "CollectionProperty", "Property");
3943 "Collection Definition",
3944 "RNA collection property to define lists, arrays and mappings");
3946
3947 /* Function */
3948 rna_def_function(brna);
3949
3950 /* Blender RNA */
3951 srna = RNA_def_struct(brna, "BlenderRNA", nullptr);
3953 RNA_def_struct_ui_text(srna, "Blender RNA", "Blender RNA structure definitions");
3954 RNA_def_struct_ui_icon(srna, ICON_RNA);
3955
3956 prop = RNA_def_property(srna, "structs", PROP_COLLECTION, PROP_NONE);
3958 RNA_def_property_struct_type(prop, "Struct");
3960 "rna_BlenderRNA_structs_begin",
3961 "rna_iterator_array_next",
3962 "rna_iterator_array_end",
3963 "rna_iterator_array_dereference_get",
3964/* included for speed, can be removed */
3965# if 0
3966 nullptr,
3967 nullptr,
3968 nullptr,
3969 nullptr);
3970# else
3971 "rna_BlenderRNA_structs_length",
3972 "rna_BlenderRNA_structs_lookup_int",
3973 "rna_BlenderRNA_structs_lookup_string",
3974 nullptr);
3975# endif
3976
3977 RNA_def_property_ui_text(prop, "Structs", "");
3978
3980}
3981
3982} // namespace blender
3983
3984#endif
#define BLT_I18NCONTEXT_UNIT
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define ID_IS_OVERRIDE_LIBRARY_VIRTUAL(_id)
Definition DNA_ID.h:733
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
Read Blender memory allocation and freeing.
#define RNA_MAX_ARRAY_DIMENSION
Definition RNA_define.hh:29
#define RNA_STACK_ARRAY
Definition RNA_types.hh:274
#define C
Definition RandGen.cpp:29
#define BLI_assert_unreachable()
#define ARRAY_SET_ITEMS(...)
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert(a)
#define ELEM(...)
#define BLI_assert_msg(a, msg)
#define STREQ(a, b)
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
UString()=default
#define printf
#define index(i)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str)
Definition mallocn.cc:129
void free(Subdiv *subdiv)
Definition subdiv.cc:192
constexpr toml::spec version
Definition recents.cc:33
BMesh Iterators.
IDProperty * rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
char * RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
@ RNA_OVERRIDE_MATCH_RESULT_CREATED
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
const EnumPropertyItem rna_enum_property_flag_items[]
Definition rna_rna.cc:189
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_property_int_get_default_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
static void rna_def_string_property(StructRNA *srna)
Definition rna_rna.cc:3712
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
@ STRUCT_RNA_DEFINITION
@ STRUCT_PUBLIC_NAMESPACE
static constexpr auto PROP_SKIP_SAVE_DESCR
Definition rna_rna.cc:169
void rna_builtin_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
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
const EnumPropertyItem rna_enum_property_string_search_flag_items[]
Definition rna_rna.cc:284
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
static constexpr auto PROP_PROPORTIONAL_DESCR
Definition rna_rna.cc:178
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
StringRefNull BKE_lib_override_operation_as_string(const eID_OverrideLib_Op operation)
void RNA_def_rna(BlenderRNA *brna)
Definition rna_rna.cc:3893
std::optional< std::string > RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop)
Definition rna_path.cc:1237
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
const char * RNA_property_identifier(const PropertyRNA *prop)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
eRNAStatus RNA_property_collection_move(PointerRNA *ptr, PropertyRNA *prop, int src_index, int dst_index)
bool rna_struct_override_type_matches(const StructRNA *type_a, const StructRNA *type_b)
void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
static constexpr auto PROP_ENUM_FLAG_DESCR
Definition rna_rna.cc:187
int RNA_property_enum_get(PointerRNA *ptr, PropertyRNA *prop)
const EnumPropertyItem rna_enum_property_unit_items[]
Definition rna_rna.cc:144
float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index)
@ PROP_UNIT_POWER
Definition RNA_types.hh:232
@ PROP_UNIT_LENGTH
Definition RNA_types.hh:222
@ PROP_UNIT_CAMERA
Definition RNA_types.hh:231
@ PROP_UNIT_TIME_ABSOLUTE
Definition RNA_types.hh:228
@ PROP_UNIT_VELOCITY
Definition RNA_types.hh:229
@ PROP_UNIT_COLOR_TEMPERATURE
Definition RNA_types.hh:235
@ PROP_UNIT_FREQUENCY
Definition RNA_types.hh:236
@ PROP_UNIT_ROTATION
Definition RNA_types.hh:226
@ PROP_UNIT_AREA
Definition RNA_types.hh:223
@ PROP_UNIT_TEMPERATURE
Definition RNA_types.hh:233
@ PROP_UNIT_NONE
Definition RNA_types.hh:221
@ PROP_UNIT_VOLUME
Definition RNA_types.hh:224
@ PROP_UNIT_ACCELERATION
Definition RNA_types.hh:230
@ PROP_UNIT_WAVELENGTH
Definition RNA_types.hh:234
@ PROP_UNIT_MASS
Definition RNA_types.hh:225
@ PROP_UNIT_TIME
Definition RNA_types.hh:227
const EnumPropertyItem rna_enum_property_subtype_items[]
Definition rna_rna.cc:129
bool RNA_struct_equals(Main *bmain, PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACompareMode mode)
@ LIBOVERRIDE_PROP_OP_TAG_UNUSED
Definition DNA_ID.h:239
@ FUNC_USE_SELF_TYPE
@ FUNC_NO_SELF
Definition RNA_types.hh:998
@ FUNC_REGISTER_OPTIONAL
@ FUNC_REGISTER
PointerRNA RNA_property_pointer_get_never_create(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_collection_begin(PointerRNA *ptr, PropertyRNA *prop, CollectionPropertyIterator *iter)
PropertyUnit RNA_property_unit(PropertyRNA *prop)
static void rna_def_property(BlenderRNA *brna)
Definition rna_rna.cc:3277
static constexpr auto PROP_LIB_EXCEPTION_DESCR
Definition rna_rna.cc:175
void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values)
const char * RNA_property_translation_context(const PropertyRNA *prop)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna)
Definition rna_rna.cc:3729
void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const bool *values)
@ RNA_OVERRIDE_COMPARE_CREATE
uint RNA_enum_items_count(const EnumPropertyItem *item)
int RNA_property_collection_length(PointerRNA *ptr, PropertyRNA *prop)
void rna_builtin_properties_next(CollectionPropertyIterator *iter)
static const EnumPropertyItem rna_enum_property_item_library_overridable
Definition rna_rna.cc:255
eID_OverrideLib_Op
Definition DNA_ID.h:182
@ LIBOVERRIDE_OP_ADD
Definition DNA_ID.h:192
@ LIBOVERRIDE_OP_INSERT_AFTER
Definition DNA_ID.h:200
@ LIBOVERRIDE_OP_SUBTRACT
Definition DNA_ID.h:194
@ LIBOVERRIDE_OP_MULTIPLY
Definition DNA_ID.h:196
@ LIBOVERRIDE_OP_REPLACE
Definition DNA_ID.h:188
const EnumPropertyItem rna_enum_property_subtype_string_items[]
Definition rna_rna.cc:108
void rna_iterator_listbase_end(CollectionPropertyIterator *)
static constexpr auto PROP_ANIMATABLE_DESCR
Definition rna_rna.cc:174
@ PROPOVERRIDE_NO_PROP_NAME
Definition RNA_types.hh:622
@ PROPOVERRIDE_LIBRARY_INSERTION
Definition RNA_types.hh:614
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:588
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)
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
void rna_property_override_diff_default(Main *bmain, RNAPropertyOverrideDiffContext &rnadiff_ctx)
static constexpr auto PROP_PATH_SUPPORTS_TEMPLATES_DESCR
Definition rna_rna.cc:184
void IDP_CopyPropertyContent(IDProperty *dst, const IDProperty *src) ATTR_NONNULL()
Definition idprop.cc:991
const EnumPropertyItem * RNA_struct_property_tag_defines(const StructRNA *type)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier_c_str, int type, int subtype)
PropertyType RNA_property_type(PropertyRNA *prop)
const EnumPropertyItem rna_enum_property_override_flag_collection_items[]
Definition rna_rna.cc:269
const EnumPropertyItem rna_enum_property_type_items[]
Definition rna_rna.cc:45
bool RNA_property_is_runtime(const PropertyRNA *prop)
static constexpr auto PROP_READ_ONLY_DESCR
Definition rna_rna.cc:165
static constexpr auto PROP_PATH_OUTPUT_DESCR
Definition rna_rna.cc:180
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
const EnumPropertyItem rna_enum_property_subtype_number_array_items[]
Definition rna_rna.cc:122
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
@ PROP_STRING_SEARCH_SORT
Definition RNA_types.hh:876
@ PROP_STRING_SEARCH_SUGGESTION
Definition RNA_types.hh:883
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
@ IDP_FLAG_OVERRIDABLE_LIBRARY
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
BMesh const char void * data
void RNA_property_collection_end(CollectionPropertyIterator *iter)
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)
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
static constexpr auto PROP_SKIP_PRESET_DESCR
Definition rna_rna.cc:173
void BKE_lib_override_library_operations_tag(IDOverrideLibraryProperty *liboverride_property, eID_OverrideLib_PropTag tag, bool do_set)
bool RNA_struct_override_matches(Main *bmain, PointerRNA *ptr_local, PointerRNA *ptr_reference, const char *root_path, const size_t root_path_len, IDOverrideLibrary *liboverride, const eRNAOverrideMatch flags, eRNAOverrideMatchResult *r_report_flags)
PointerRNA rna_builtin_properties_get(CollectionPropertyIterator *iter)
const char * RNA_property_ui_description_raw(const PropertyRNA *prop, const PointerRNA *ptr)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void BKE_lib_override_library_property_operation_delete(IDOverrideLibraryProperty *liboverride_property, IDOverrideLibraryPropertyOperation *liboverride_property_operation)
bool rna_builtin_properties_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
const EnumPropertyItem rna_enum_property_flag_enum_items[]
Definition rna_rna.cc:233
IDOverrideLibraryProperty * BKE_lib_override_library_property_find(IDOverrideLibrary *liboverride, const char *rna_path)
const EnumPropertyItem rna_enum_dummy_DEFAULT_items[]
Definition rna_rna.cc:34
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
PointerRNA rna_builtin_type_get(PointerRNA *ptr)
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
static void rna_def_pointer_property(StructRNA *srna, PropertyType type)
Definition rna_rna.cc:3841
static constexpr auto PROP_TEXTEDIT_UPDATE_DESCR
Definition rna_rna.cc:179
bool RNA_struct_is_ID(const StructRNA *type)
const EnumPropertyItem rna_enum_property_override_flag_items[]
Definition rna_rna.cc:264
const DeprecatedRNA * RNA_property_deprecated(const PropertyRNA *prop)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_property_collection_next(CollectionPropertyIterator *iter)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
PropertySubType RNA_property_subtype(PropertyRNA *prop)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_struct_flag(StructRNA *srna, StructFlag flag)
const EnumPropertyItem rna_enum_property_subtype_number_items[]
Definition rna_rna.cc:115
static void rna_def_rna_primitive(BlenderRNA *brna)
Definition rna_rna.cc:3859
IDOverrideLibraryProperty * BKE_lib_override_library_property_get(IDOverrideLibrary *liboverride, const char *rna_path, bool *r_created)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
@ PROP_TEXTEDIT_UPDATE
Definition RNA_types.hh:396
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_ENUM_FLAG
Definition RNA_types.hh:474
@ PROP_PROPORTIONAL
Definition RNA_types.hh:419
@ PROP_SKIP_PRESET
Definition RNA_types.hh:543
@ PROP_PATH_OUTPUT
Definition RNA_types.hh:521
@ PROP_PATH_SUPPORTS_TEMPLATES
Definition RNA_types.hh:540
@ PROP_DYNAMIC
Definition RNA_types.hh:498
@ PROP_IDPROPERTY
Definition RNA_types.hh:496
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:465
@ PROP_REGISTER_OPTIONAL
Definition RNA_types.hh:482
@ PROP_REGISTER
Definition RNA_types.hh:481
@ PROP_PATH_SUPPORTS_BLEND_RELATIVE
Definition RNA_types.hh:526
@ PROP_NEVER_NULL
Definition RNA_types.hh:447
@ PROP_HIDDEN
Definition RNA_types.hh:408
@ PROP_ANIMATABLE
Definition RNA_types.hh:389
@ PROP_LIB_EXCEPTION
Definition RNA_types.hh:382
@ ID_TAG_LIBOVERRIDE_NEED_RESYNC
Definition DNA_ID.h:909
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)
void RNA_property_float_get_default_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
PropertyRNA * rna_ensure_property(PropertyRNA *prop)
int RNA_property_ui_icon(const PropertyRNA *prop)
bool RNA_property_collection_lookup_string_index(PointerRNA *ptr, PropertyRNA *prop, const char *key, PointerRNA *r_ptr, int *r_index)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value)
static FunctionRNA * rna_def_function(StructRNA *srna, const UString identifier)
static void rna_def_struct(BlenderRNA *brna)
Definition rna_rna.cc:3175
@ PROP_BYTESTRING
Definition RNA_types.hh:295
@ PROP_UNSIGNED
Definition RNA_types.hh:306
@ PARM_REQUIRED
Definition RNA_types.hh:631
@ PARM_PYFUNC_REGISTER_OPTIONAL
Definition RNA_types.hh:643
@ PARM_OUTPUT
Definition RNA_types.hh:632
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, ListBase *lb, IteratorSkipFunc skip)
static constexpr auto PROP_PATH_RELATIVE_DESCR
Definition rna_rna.cc:181
const EnumPropertyItem rna_enum_icon_items[]
Definition rna_ui_api.cc:30
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_property_int_range(PointerRNA *ptr, PropertyRNA *prop, int *hardmin, int *hardmax)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop, const bool allow_replace)
static void rna_def_number_property(StructRNA *srna, PropertyType type)
Definition rna_rna.cc:3570
bool rna_property_override_store_default(Main *bmain, PointerRNA *ptr_local, PointerRNA *ptr_reference, PointerRNA *ptr_storage, PropertyRNA *prop_local, PropertyRNA *prop_reference, PropertyRNA *prop_storage, int len_local, int len_reference, int len_storage, IDOverrideLibraryPropertyOperation *opop)
void RNA_property_boolean_get_default_array(PointerRNA *ptr, PropertyRNA *prop, bool *values)
void RNA_def_property_array(PropertyRNA *prop, int length)
IDOverrideLibraryPropertyOperation * BKE_lib_override_library_property_operation_get(IDOverrideLibraryProperty *liboverride_property, eID_OverrideLib_Op operation, const char *subitem_refname, const char *subitem_locname, const std::optional< ID * > &subitem_refid, const std::optional< ID * > &subitem_locid, int subitem_refindex, int subitem_locindex, bool strict, bool *r_strict, bool *r_created)
@ LIBOVERRIDE_OP_FLAG_IDPOINTER_MATCH_REFERENCE
Definition DNA_ID.h:226
void rna_iterator_array_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, void *data, size_t itemsize, int64_t length, bool free_ptr, IteratorSkipFunc skip)
bool rna_property_override_apply_default(Main *bmain, RNAPropertyOverrideApplyContext &rnaapply_ctx)
bool(*)(CollectionPropertyIterator *iter, void *data) IteratorSkipFunc
Definition RNA_types.hh:649
void rna_iterator_listbase_next(CollectionPropertyIterator *iter)
void RNA_property_float_range(PointerRNA *ptr, PropertyRNA *prop, float *hardmin, float *hardmax)
static constexpr auto PROP_HIDDEN_DESCR
Definition rna_rna.cc:166
#define RNA_PATH_BUFFSIZE
#define RNA_MAGIC
#define RNA_ENUM_PROPERTY_SUBTYPE_STRING_ITEMS
Definition rna_rna.cc:60
#define RNA_ENUM_PROPERTY_SUBTYPE_NUMBER_ARRAY_ITEMS
Definition rna_rna.cc:88
#define RNA_ENUM_PROPERTY_SUBTYPE_NUMBER_ITEMS
Definition rna_rna.cc:67
Vector< std::unique_ptr< StructRNA > > structs
StructRNA * type
Definition RNA_types.hh:63