Blender  V3.3
Macros | Typedefs | Enumerations | Functions
BKE_blendfile_link_append.h File Reference

Go to the source code of this file.

Macros

#define BLENDFILE_LINK_APPEND_INVALID   -1
 

Typedefs

typedef struct BlendfileLinkAppendContext BlendfileLinkAppendContext
 
typedef struct BlendfileLinkAppendContextItem BlendfileLinkAppendContextItem
 
typedef enum eBlendfileLinkAppendForeachItemFlag eBlendfileLinkAppendForeachItemFlag
 
typedef bool(* BKE_BlendfileLinkAppendContexteItemFunction) (struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item, void *userdata)
 

Enumerations

enum  eBlendfileLinkAppendForeachItemFlag { BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_DIRECT = 1 << 0 , BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_INDIRECT = 1 << 1 }
 

Functions

BlendfileLinkAppendContextBKE_blendfile_link_append_context_new (struct LibraryLink_Params *params)
 
void BKE_blendfile_link_append_context_free (struct BlendfileLinkAppendContext *lapp_context)
 
void BKE_blendfile_link_append_context_flag_set (struct BlendfileLinkAppendContext *lapp_context, int flag, bool do_set)
 
void BKE_blendfile_link_append_context_embedded_blendfile_set (struct BlendfileLinkAppendContext *lapp_context, const void *blendfile_mem, int blendfile_memsize)
 
void BKE_blendfile_link_append_context_embedded_blendfile_clear (struct BlendfileLinkAppendContext *lapp_context)
 
void BKE_blendfile_link_append_context_library_add (struct BlendfileLinkAppendContext *lapp_context, const char *libname, struct BlendHandle *blo_handle)
 
struct BlendfileLinkAppendContextItemBKE_blendfile_link_append_context_item_add (struct BlendfileLinkAppendContext *lapp_context, const char *idname, short idcode, void *userdata)
 
int BKE_blendfile_link_append_context_item_idtypes_from_library_add (struct BlendfileLinkAppendContext *lapp_context, struct ReportList *reports, uint64_t id_types_filter, int library_index)
 
void BKE_blendfile_link_append_context_item_library_index_enable (struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item, int library_index)
 
bool BKE_blendfile_link_append_context_is_empty (struct BlendfileLinkAppendContext *lapp_context)
 
voidBKE_blendfile_link_append_context_item_userdata_get (struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item)
 
struct IDBKE_blendfile_link_append_context_item_newid_get (struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item)
 
short BKE_blendfile_link_append_context_item_idcode_get (struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item)
 
void BKE_blendfile_link_append_context_item_foreach (struct BlendfileLinkAppendContext *lapp_context, BKE_BlendfileLinkAppendContexteItemFunction callback_function, eBlendfileLinkAppendForeachItemFlag flag, void *userdata)
 
void BKE_blendfile_append (struct BlendfileLinkAppendContext *lapp_context, struct ReportList *reports)
 
void BKE_blendfile_link (struct BlendfileLinkAppendContext *lapp_context, struct ReportList *reports)
 
void BKE_blendfile_library_relocate (struct BlendfileLinkAppendContext *lapp_context, struct ReportList *reports, struct Library *library, bool do_reload)
 

Macro Definition Documentation

◆ BLENDFILE_LINK_APPEND_INVALID

#define BLENDFILE_LINK_APPEND_INVALID   -1

Definition at line 90 of file BKE_blendfile_link_append.h.

Typedef Documentation

◆ BKE_BlendfileLinkAppendContexteItemFunction

typedef bool(* BKE_BlendfileLinkAppendContexteItemFunction) (struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item, void *userdata)

Callback called by BKE_blendfile_link_append_context_item_foreach over each (or a subset of each) of the items in given BlendfileLinkAppendContext.

Parameters
userdataAn opaque void pointer passed to the callback_function.
Returns
true if iteration should continue, false otherwise.

Definition at line 149 of file BKE_blendfile_link_append.h.

◆ BlendfileLinkAppendContext

Definition at line 1 of file BKE_blendfile_link_append.h.

◆ BlendfileLinkAppendContextItem

Definition at line 1 of file BKE_blendfile_link_append.h.

◆ eBlendfileLinkAppendForeachItemFlag

Enumeration Type Documentation

◆ eBlendfileLinkAppendForeachItemFlag

Enumerator
BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_DIRECT 

Loop over directly linked items (i.e. those explicitly defined by user code).

BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_INDIRECT 

Loop over indirectly linked items (i.e. those defined by internal code, as dependencies of direct ones).

IMPORTANT: Those 'indirect' items currently may not cover all indirectly linked data. See comments in foreach_libblock_link_append_callback.

Definition at line 131 of file BKE_blendfile_link_append.h.

Function Documentation

◆ BKE_blendfile_append()

void BKE_blendfile_append ( struct BlendfileLinkAppendContext lapp_context,
struct ReportList reports 
)

Perform append operation, using modern ID usage looper to detect which ID should be kept linked, made local, duplicated as local, re-used from local etc.

The IDs processed by this functions are the one that have been linked by a previous call to BKE_blendfile_link on the same lapp_context.

Definition at line 1001 of file blendfile_link_append.c.

References BlendfileLinkAppendContextItem::action, BKE_id_multi_tagged_delete(), BKE_idtype_idcode_append_is_reusable(), BKE_lib_id_make_local(), BKE_libblock_relink_to_newid(), BKE_library_foreach_ID_link(), BKE_main_id_newptr_and_tag_clear(), BKE_main_id_tag_all(), BKE_main_library_weak_reference_add_item(), BKE_main_library_weak_reference_create(), BKE_main_library_weak_reference_destroy(), BKE_main_library_weak_reference_remove_item(), BKE_main_library_weak_reference_search_item(), blendfile_link_append_proxies_convert(), BLI_assert, BLI_assert_unreachable, BLI_strncpy(), BLO_LIBLINK_APPEND_ASSET_DATA_CLEAR, BLO_LIBLINK_APPEND_LOCAL_ID_REUSE, BLO_LIBLINK_APPEND_SET_FAKEUSER, LibraryLink_Params::bmain, CLOG_ERROR, CLOG_INFO, ELEM, FILE_LINK, FILE_MAX, Library::filepath, LibraryLink_Params::flag, foreach_libblock_link_append_callback(), GS, id, id_fake_user_set(), ID_GR, ID_IS_LINKED, ID_NEW_SET, ID_OB, IDWALK_NOP, BlendfileLinkAppendContext::items, BlendfileLinkAppendContextCallBack::lapp_context, LooseDataInstantiateContext::lapp_context, ID::lib, LIB_ID_MAKELOCAL_ASSET_DATA_CLEAR, LIB_ID_MAKELOCAL_FORCE_COPY, LIB_ID_MAKELOCAL_FORCE_LOCAL, LIB_ID_MAKELOCAL_FULL_LIBRARY, LIB_TAG_DOIT, LIB_TAG_PRE_EXISTING, BlendfileLinkAppendContext::library_weak_reference_mapping, LinkNode::link, LINK_APPEND_ACT_COPY_LOCAL, LINK_APPEND_ACT_KEEP_LINKED, LINK_APPEND_ACT_MAKE_LOCAL, LINK_APPEND_ACT_REUSE_LOCAL, LINK_APPEND_ACT_UNSET, LinkNodePair::list, LOG, loose_data_instantiate(), MAX_ID_NAME, ID::name, BlendfileLinkAppendContextItem::new_id, new_id_to_item_mapping_create(), ID::newid, LinkNode::next, NULL, BlendfileLinkAppendContext::num_items, BlendfileLinkAppendContext::params, ID::tag, and BlendfileLinkAppendContextItem::userdata.

Referenced by bpy_lib_exit(), copybuffer_append(), wm_file_link_append_datablock_ex(), and wm_link_append_exec().

◆ BKE_blendfile_library_relocate()

void BKE_blendfile_library_relocate ( struct BlendfileLinkAppendContext lapp_context,
struct ReportList reports,
struct Library library,
bool  do_reload 
)

Try to relocate all linked IDs added to lapp_context, belonging to the given library.

This function searches for matching IDs (type and name) in all libraries added to the given lapp_context.

Typical usages include:

  • Relocating a library:
    • Add the new target library path to lapp_context.
    • Add all IDs from the library to relocate to lapp_context
    • Mark the new target library to be considered for each ID.
    • Call this function.
  • Searching for (e.g.missing) linked IDs in a set or sub-set of libraries:
    • Add all potential library sources paths to lapp_context.
    • Add all IDs to search for to lapp_context.
    • Mark which libraries should be considered for each ID.
    • Call this function.

NOTE: content of lapp_context after execution of that function should not be assumed valid anymore, and should immediately be freed.

Definition at line 1403 of file blendfile_link_append.c.

References BKE_blendfile_link(), BKE_blendfile_link_append_context_item_add(), BKE_id_free(), BKE_id_multi_tagged_delete(), BKE_idtype_idcode_is_linkable(), BKE_key_from_id(), BKE_key_from_id_p(), BKE_lib_override_library_main_operations_create(), BKE_lib_override_library_main_resync(), BKE_lib_override_library_update(), BKE_main_collection_sync(), BKE_main_id_refcount_recompute(), BKE_main_id_tag_all(), BKE_main_id_tag_idcode(), BKE_main_lock(), BKE_main_unlock(), BKE_view_layer_find(), blendfile_library_relocate_remap(), BLI_addtail(), BLI_assert, BLI_bitmap_set_all(), BLI_remlink(), LibraryLink_Params::bmain, CLOG_INFO, LibraryLink_Params::context, ListBase::first, ID::flag, FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, GS, id, Library::id, Key::id, Scene::id, ID_IS_LINKED, ID_IS_OVERRIDE_LIBRARY_REAL, ID_KE, ID_LI, ID_REMAP_SKIP_INDIRECT_USAGE, ID_REMAP_SKIP_NEVER_NULL_USAGE, ID_SCE, id_us_clear_real(), id_us_min(), id_us_plus_no_lib(), INDEX_ID_MAX, BlendfileLinkAppendContext::items, lib, ID::lib, LIB_TAG_DOIT, LIB_TAG_MISSING, LIB_TAG_PRE_EXISTING, BlendfileLinkAppendContextItem::libraries, library, LinkNode::link, LinkNodePair::list, LOG, ViewLayer::name, ID::name, BlendfileLinkAppendContextItem::new_id, LinkNode::next, ID::next, NULL, BlendfileLinkAppendContext::num_items, BlendfileLinkAppendContext::num_libraries, ID::override_library, BlendfileLinkAppendContext::params, IDOverrideLibrary::reference, LibraryLink_Params::scene, set_listbasepointers(), ID::tag, ID::us, USER_EXPERIMENTAL_TEST, BlendfileLinkAppendContextItem::userdata, LibraryLink_Params::view_layer, Scene::view_layers, and which_libbase().

Referenced by WM_lib_reload(), and wm_lib_relocate_exec_do().

◆ BKE_blendfile_link()

void BKE_blendfile_link ( struct BlendfileLinkAppendContext lapp_context,
struct ReportList reports 
)

Perform linking operation on all items added to given lapp_context.

Definition at line 1205 of file blendfile_link_append.c.

References BKE_library_foreach_ID_link(), BKE_reportf(), blendfile_link_append_proxies_convert(), BLI_assert, BLI_bitmap_set_all(), BLI_BITMAP_TEST, BLO_library_link_begin(), BLO_library_link_end(), BLO_library_link_named_part(), LibraryLink_Params::bmain, LibraryLink_Params::context, Main::curlib, FILE_LINK, LibraryLink_Params::flag, foreach_libblock_link_append_callback(), BlendfileLinkAppendContextItem::idcode, IDWALK_NOP, BlendfileLinkAppendContext::items, BlendfileLinkAppendContextCallBack::lapp_context, LooseDataInstantiateContext::lapp_context, lib, ID::lib, LIB_TAG_MISSING, BlendfileLinkAppendContextItem::libraries, BlendfileLinkAppendContext::libraries, LinkNode::link, link_append_context_library_blohandle_ensure(), link_append_context_library_blohandle_release(), LinkNodePair::list, loose_data_instantiate(), BlendfileLinkAppendContextItem::name, BlendfileLinkAppendContextItem::new_id, new_id_to_item_mapping_create(), LinkNode::next, NULL, BlendfileLinkAppendContext::num_items, BlendfileLinkAppendContext::num_libraries, BlendfileLinkAppendContext::params, BlendfileLinkAppendContextLibrary::path, RPT_WARNING, LibraryLink_Params::scene, BlendfileLinkAppendContextItem::source_library, Main::subversionfile, BlendfileLinkAppendContextItem::userdata, and Main::versionfile.

Referenced by BKE_blendfile_library_relocate(), bpy_lib_exit(), copybuffer_append(), wm_file_link_append_datablock_ex(), and wm_link_append_exec().

◆ BKE_blendfile_link_append_context_embedded_blendfile_clear()

void BKE_blendfile_link_append_context_embedded_blendfile_clear ( struct BlendfileLinkAppendContext lapp_context)

Clear reference to Blender's embedded startup file into the context.

Definition at line 225 of file blendfile_link_append.c.

References BlendfileLinkAppendContext::blendfile_mem, BlendfileLinkAppendContext::blendfile_memsize, and NULL.

◆ BKE_blendfile_link_append_context_embedded_blendfile_set()

void BKE_blendfile_link_append_context_embedded_blendfile_set ( struct BlendfileLinkAppendContext lapp_context,
const void blendfile_mem,
int  blendfile_memsize 
)

Store reference to a Blender's embedded memfile into the context.

Note
This is required since embedded startup blender file is handled in ED module, which cannot be linked in BKE code.

Definition at line 215 of file blendfile_link_append.c.

References BlendfileLinkAppendContext::blendfile_mem, BlendfileLinkAppendContext::blendfile_memsize, BLI_assert_msg, and NULL.

Referenced by wm_file_link_append_datablock_ex(), and wm_link_append_exec().

◆ BKE_blendfile_link_append_context_flag_set()

void BKE_blendfile_link_append_context_flag_set ( struct BlendfileLinkAppendContext lapp_context,
int  flag,
bool  do_set 
)

Set or clear flags in given lapp_context.

Parameters
flagA combination of:
do_setSet the given flag if true, clear it otherwise.

Definition at line 203 of file blendfile_link_append.c.

References LibraryLink_Params::flag, and BlendfileLinkAppendContext::params.

Referenced by wm_lib_relocate_exec_do().

◆ BKE_blendfile_link_append_context_free()

void BKE_blendfile_link_append_context_free ( struct BlendfileLinkAppendContext lapp_context)

◆ BKE_blendfile_link_append_context_is_empty()

bool BKE_blendfile_link_append_context_is_empty ( struct BlendfileLinkAppendContext lapp_context)

Check if given link/append context is empty (has no items to process) or not.

Definition at line 337 of file blendfile_link_append.c.

References BlendfileLinkAppendContext::num_items.

Referenced by wm_link_append_exec().

◆ BKE_blendfile_link_append_context_item_add()

struct BlendfileLinkAppendContextItem* BKE_blendfile_link_append_context_item_add ( struct BlendfileLinkAppendContext lapp_context,
const char *  idname,
short  idcode,
void userdata 
)

◆ BKE_blendfile_link_append_context_item_foreach()

void BKE_blendfile_link_append_context_item_foreach ( struct BlendfileLinkAppendContext lapp_context,
BKE_BlendfileLinkAppendContexteItemFunction  callback_function,
eBlendfileLinkAppendForeachItemFlag  flag,
void userdata 
)

Iterate over all (or a subset) of the items listed in given BlendfileLinkAppendContext, and call the callback_function on them.

Parameters
flagControl which type of items to process (see eBlendfileLinkAppendForeachItemFlag enum flags).
userdataAn opaque void pointer passed to the callback_function.

Definition at line 361 of file blendfile_link_append.c.

References BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_DIRECT, BKE_BLENDFILE_LINK_APPEND_FOREACH_ITEM_FLAG_DO_INDIRECT, BlendfileLinkAppendContext::items, LINK_APPEND_TAG_INDIRECT, LinkNodePair::list, LinkNode::next, and BlendfileLinkAppendContextItem::tag.

Referenced by bpy_lib_exit().

◆ BKE_blendfile_link_append_context_item_idcode_get()

short BKE_blendfile_link_append_context_item_idcode_get ( struct BlendfileLinkAppendContext lapp_context,
struct BlendfileLinkAppendContextItem item 
)

◆ BKE_blendfile_link_append_context_item_idtypes_from_library_add()

int BKE_blendfile_link_append_context_item_idtypes_from_library_add ( struct BlendfileLinkAppendContext lapp_context,
struct ReportList reports,
uint64_t  id_types_filter,
int  library_index 
)

Search for all ID matching given id_types_filter in given library_index, and add them to the list of items to process.

Note
BKE_blendfile_link_append_context_library_add should never be called on the same lapp_context after this function.
Parameters
id_types_filterA set of FILTER_ID bitflags, the types of IDs to add to the items list.
library_indexThe index of the library to look into, in given lapp_context.
Returns
The number of items found and added to the list, or BLENDFILE_LINK_APPEND_INVALID if it could not open the .blend file.

Definition at line 278 of file blendfile_link_append.c.

References BKE_blendfile_link_append_context_item_add(), BKE_blendfile_link_append_context_item_library_index_enable(), BKE_idtype_idcode_is_linkable(), BKE_idtype_idcode_iter_step(), BKE_idtype_idcode_to_idfilter(), BLENDFILE_LINK_APPEND_INVALID, BLI_linklist_find(), BLO_blendhandle_get_datablock_names(), FILE_ASSETS_ONLY, LibraryLink_Params::flag, id_name(), BlendfileLinkAppendContext::libraries, LinkNode::link, link_append_context_library_blohandle_ensure(), LinkNodePair::list, MEM_freeN, LinkNode::next, NULL, and BlendfileLinkAppendContext::params.

Referenced by BKE_copybuffer_paste(), and BKE_copybuffer_read().

◆ BKE_blendfile_link_append_context_item_library_index_enable()

void BKE_blendfile_link_append_context_item_library_index_enable ( struct BlendfileLinkAppendContext lapp_context,
struct BlendfileLinkAppendContextItem item,
int  library_index 
)

Enable search of the given item into the library stored at given index in the link/append context.

Referenced by bpy_lib_exit(), wm_file_link_append_datablock_ex(), and wm_link_append_exec().

◆ BKE_blendfile_link_append_context_item_newid_get()

struct ID* BKE_blendfile_link_append_context_item_newid_get ( struct BlendfileLinkAppendContext lapp_context,
struct BlendfileLinkAppendContextItem item 
)

◆ BKE_blendfile_link_append_context_item_userdata_get()

void* BKE_blendfile_link_append_context_item_userdata_get ( struct BlendfileLinkAppendContext lapp_context,
struct BlendfileLinkAppendContextItem item 
)

◆ BKE_blendfile_link_append_context_library_add()

void BKE_blendfile_link_append_context_library_add ( struct BlendfileLinkAppendContext lapp_context,
const char *  libname,
struct BlendHandle blo_handle 
)

Add a new source library to search for items to be linked to the given link/append context.

Parameters
libnamethe absolute path to the library blend file.
blo_handlethe blend file handle of the library, NULL is not available. Note that this is only borrowed for linking purpose, no releasing or other management will be performed by #BKE_blendfile_link_append code on it.
Note
Never call BKE_blendfile_link_append_context_library_add() after having added some items.

Definition at line 232 of file blendfile_link_append.c.

References BLI_assert, BLI_linklist_append_arena(), BLI_memarena_alloc(), BLI_memarena_calloc(), BLI_strncpy(), BlendfileLinkAppendContextLibrary::blo_handle, BlendfileLinkAppendContextLibrary::blo_handle_is_owned, BlendfileLinkAppendContext::items, len, BlendfileLinkAppendContext::libraries, LinkNodePair::list, BlendfileLinkAppendContext::memarena, NULL, BlendfileLinkAppendContext::num_libraries, and BlendfileLinkAppendContextLibrary::path.

Referenced by BKE_copybuffer_paste(), BKE_copybuffer_read(), bpy_lib_exit(), wm_file_link_append_datablock_ex(), WM_lib_reload(), wm_lib_relocate_exec_do(), and wm_link_append_exec().

◆ BKE_blendfile_link_append_context_new()

BlendfileLinkAppendContext* BKE_blendfile_link_append_context_new ( struct LibraryLink_Params params)