Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2020-09-18 16:17:42 +0300
committerBastien Montagne <bastien@blender.org>2020-09-20 17:26:39 +0300
commitdb314ee7a47287483b7c6ad475ea3486e661496c (patch)
tree24e7592bfa6e18844f8d438277ea981a1413cc8e /source/blender/makesrna/intern/rna_rna.c
parent5e509a3aa9d1f14d3293da3b0cc72fb633d7773a (diff)
LibOverride: support inserting items in py-defined (IDProp-based) collections.
Supporting IDProperty-based data storage here in a generic way is fairly simple, unlike actual RNA data (DNA-based), for which getting a proper generic way to duplicate them from within RNA is currently not really possible. Part of T79562.
Diffstat (limited to 'source/blender/makesrna/intern/rna_rna.c')
-rw-r--r--source/blender/makesrna/intern/rna_rna.c71
1 files changed, 69 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 9aef0b5a1cb..a9135f20a26 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -128,6 +128,7 @@ const EnumPropertyItem rna_enum_property_unit_items[] = {
# include "BLI_string.h"
# include "MEM_guardedalloc.h"
+# include "BKE_idprop.h"
# include "BKE_lib_override.h"
/* Struct */
@@ -2528,8 +2529,74 @@ bool rna_property_override_apply_default(Main *UNUSED(bmain),
return true;
}
case PROP_COLLECTION: {
- BLI_assert(!"You need to define a specific override apply callback for enums.");
- return false;
+ /* We only support IDProperty-based collection insertion here. */
+ const bool is_src_idprop = (prop_src->magic != RNA_MAGIC) ||
+ (prop_src->flag & PROP_IDPROPERTY) != 0;
+ const bool is_dst_idprop = (prop_dst->magic != RNA_MAGIC) ||
+ (prop_dst->flag & PROP_IDPROPERTY) != 0;
+ if (!(is_src_idprop && is_dst_idprop)) {
+ BLI_assert(0 && "You need to define a specific override apply callback for collections");
+ return false;
+ }
+
+ switch (override_op) {
+ case IDOVERRIDE_LIBRARY_OP_INSERT_AFTER: {
+ PointerRNA item_ptr_src, item_ptr_ref, item_ptr_dst;
+ int item_index_dst;
+ bool is_valid = false;
+ if (opop->subitem_local_name != NULL && opop->subitem_local_name[0] != '\0') {
+ /* Find from name. */
+ int item_index_src, item_index_ref;
+ if (RNA_property_collection_lookup_string_index(
+ ptr_src, prop_src, opop->subitem_local_name, &item_ptr_src, &item_index_src) &&
+ RNA_property_collection_lookup_int(
+ ptr_src, prop_src, item_index_src + 1, &item_ptr_src) &&
+ RNA_property_collection_lookup_string_index(
+ ptr_dst, prop_dst, opop->subitem_local_name, &item_ptr_ref, &item_index_ref)) {
+ is_valid = true;
+ item_index_dst = item_index_ref + 1;
+ }
+ }
+ if (!is_valid && opop->subitem_local_index >= 0) {
+ /* Find from index. */
+ if (RNA_property_collection_lookup_int(
+ ptr_src, prop_src, opop->subitem_local_index + 1, &item_ptr_src) &&
+ RNA_property_collection_lookup_int(
+ ptr_dst, prop_dst, opop->subitem_local_index, &item_ptr_ref)) {
+ item_index_dst = opop->subitem_local_index + 1;
+ is_valid = true;
+ }
+ }
+ if (!is_valid) {
+ /* Assume it is inserted in first position. */
+ if (RNA_property_collection_lookup_int(ptr_src, prop_src, 0, &item_ptr_src)) {
+ item_index_dst = 0;
+ is_valid = true;
+ }
+ }
+ if (!is_valid) {
+ return false;
+ }
+
+ RNA_property_collection_add(ptr_dst, prop_dst, &item_ptr_dst);
+ const int item_index_added = RNA_property_collection_length(ptr_dst, prop_dst) - 1;
+ BLI_assert(item_index_added >= 0);
+
+ /* This is the section of code that makes it specific to IDProperties (the rest could be
+ * used with some regular RNA/DNA data too).
+ * Currently it is close to impossible to copy arbitrary 'real' RNA data between
+ * Collection items. */
+ IDProperty *item_idprop_src = item_ptr_src.data;
+ IDProperty *item_idprop_dst = item_ptr_dst.data;
+ IDP_CopyPropertyContent(item_idprop_dst, item_idprop_src);
+
+ return RNA_property_collection_move(ptr_dst, prop_dst, item_index_added, item_index_dst);
+ break;
+ }
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on collection");
+ return false;
+ }
}
default:
BLI_assert(0);