diff options
author | Bastien Montagne <bastien@blender.org> | 2021-11-11 16:40:11 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2021-11-23 14:18:37 +0300 |
commit | 605cdc4346e5f82c031c4a5d6ecd91bf8268f7ff (patch) | |
tree | f6acf2c18a5fdf4c71a298d309860b5630c68f24 /source/blender/blenkernel/intern | |
parent | 0452a04f1a1840544287810528e2aaab1daca2ce (diff) |
BKE LibLink/Append: Add mechanism for external code to loop over link/append context items.
Will be required for python's `bpy.data.libraries.load()` refactor.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/blendfile_link_append.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/source/blender/blenkernel/intern/blendfile_link_append.c b/source/blender/blenkernel/intern/blendfile_link_append.c index 107e89e0e1e..36f03990953 100644 --- a/source/blender/blenkernel/intern/blendfile_link_append.c +++ b/source/blender/blenkernel/intern/blendfile_link_append.c @@ -277,9 +277,6 @@ void BKE_blendfile_link_append_context_library_add(BlendfileLinkAppendContext *l BlendfileLinkAppendContextLibrary *lib_context = BLI_memarena_calloc(lapp_context->memarena, sizeof(*lib_context)); - BlendfileLinkAppendContextLibrary *ctx_lib = BLI_memarena_alloc(lapp_context->memarena, - sizeof(*ctx_lib)); - size_t len = strlen(libname) + 1; char *libpath = BLI_memarena_alloc(lapp_context->memarena, len); BLI_strncpy(libpath, libname, len); @@ -349,6 +346,44 @@ ID *BKE_blendfile_link_append_context_item_newid_get( return item->new_id; } +short BKE_blendfile_link_append_context_item_idcode_get( + struct BlendfileLinkAppendContext *UNUSED(lapp_context), + struct BlendfileLinkAppendContextItem *item) +{ + return item->idcode; +} + +/** Iterate over all (or a subset) of the items listed in given #BlendfileLinkAppendContext, and + * call the `callback_function` on them. + * + * \param flag: Control which type of items to process (see + * #eBlendfileLinkAppendForeachItemFlag enum flags). + * \param userdata: An opaque void pointer passed to the `callback_function`. + */ +void BKE_blendfile_link_append_context_item_foreach( + struct BlendfileLinkAppendContext *lapp_context, + BKE_BlendfileLinkAppendContexteItemFunction callback_function, + const eBlendfileLinkAppendForeachItemFlag flag, + void *userdata) +{ + for (LinkNode *itemlink = lapp_context->items.list; itemlink; itemlink = itemlink->next) { + BlendfileLinkAppendContextItem *item = itemlink->link; + + if ((flag & BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_DIRECT) == 0 && + (item->tag & LINK_APPEND_TAG_INDIRECT) == 0) { + continue; + } + if ((flag & BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_INDIRECT) == 0 && + (item->tag & LINK_APPEND_TAG_INDIRECT) != 0) { + continue; + } + + if (!callback_function(lapp_context, item, userdata)) { + break; + } + } +} + /** \} */ /* -------------------------------------------------------------------- */ |