Blender V4.3
BKE_lib_query.hh File Reference
#include "DNA_ID.h"
#include "BLI_function_ref.hh"
#include "BLI_sys_types.h"
#include <array>

Go to the source code of this file.

Classes

struct  LibraryIDLinkCallbackData
 
struct  LibQueryUnusedIDsData
 

Macros

#define BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK(data_, id_, cb_flag_)
 
#define BKE_LIB_FOREACHID_PROCESS_ID(data_, id_, cb_flag_)
 
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER_P(data_, id_super_p_, cb_flag_)
 
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
 
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
 

Typedefs

using LibraryIDLinkCallback = int(LibraryIDLinkCallbackData *cb_data)
 

Enumerations

enum  {
  IDWALK_CB_NOP = 0 , IDWALK_CB_NEVER_NULL = (1 << 0) , IDWALK_CB_NEVER_SELF = (1 << 1) , IDWALK_CB_INDIRECT_USAGE = (1 << 2) ,
  IDWALK_CB_DIRECT_WEAK_LINK = (1 << 3) , IDWALK_CB_EMBEDDED = (1 << 4) , IDWALK_CB_EMBEDDED_NOT_OWNING = (1 << 5) , IDWALK_CB_LOOPBACK = (1 << 6) ,
  IDWALK_CB_INTERNAL = (1 << 9) , IDWALK_CB_READFILE_IGNORE = (1 << 10) , IDWALK_CB_USER = (1 << 11) , IDWALK_CB_USER_ONE = (1 << 12) ,
  IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE = (1 << 16) , IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE = (1 << 17) , IDWALK_CB_OVERRIDE_LIBRARY_HIERARCHY_DEFAULT = (1 << 18)
}
 
enum  { IDWALK_RET_NOP = 0 , IDWALK_RET_STOP_ITER = 1 << 0 , IDWALK_RET_STOP_RECURSION = 1 << 1 }
 
enum  {
  IDWALK_NOP = 0 , IDWALK_READONLY = (1 << 0) , IDWALK_RECURSE = (1 << 1) , IDWALK_INCLUDE_UI = (1 << 2) ,
  IDWALK_IGNORE_EMBEDDED_ID = (1 << 3) , IDWALK_NO_ORIG_POINTERS_ACCESS = (1 << 5) , IDWALK_IGNORE_MISSING_OWNER_ID = (1 << 6) , IDWALK_DO_INTERNAL_RUNTIME_POINTERS = (1 << 9) ,
  IDWALK_DO_LIBRARY_POINTER = (1 << 10) , IDWALK_DO_DEPRECATED_POINTERS = (1 << 11)
}
 

Functions

bool BKE_lib_query_foreachid_iter_stop (const LibraryForeachIDData *data)
 
void BKE_lib_query_foreachid_process (LibraryForeachIDData *data, ID **id_pp, int cb_flag)
 
int BKE_lib_query_foreachid_process_flags_get (const LibraryForeachIDData *data)
 
MainBKE_lib_query_foreachid_process_main_get (const LibraryForeachIDData *data)
 
int BKE_lib_query_foreachid_process_callback_flag_override (LibraryForeachIDData *data, int cb_flag, bool do_replace)
 
void BKE_library_foreach_ID_embedded (LibraryForeachIDData *data, ID **id_pp)
 
void BKE_lib_query_idpropertiesForeachIDLink_callback (IDProperty *id_prop, void *user_data)
 
void BKE_library_foreach_ID_link (Main *bmain, ID *id, blender::FunctionRef< LibraryIDLinkCallback > callback, void *user_data, int flag)
 
void BKE_library_foreach_subdata_id (Main *bmain, ID *owner_id, ID *self_id, blender::FunctionRef< void(LibraryForeachIDData *data)> subdata_foreach_id, blender::FunctionRef< LibraryIDLinkCallback > callback, void *user_data, const int flag)
 
void BKE_library_update_ID_link_user (ID *id_dst, ID *id_src, int cb_flag)
 
int BKE_library_ID_use_ID (ID *id_user, ID *id_used)
 
bool BKE_library_id_can_use_idtype (ID *owner_id, short id_type_used)
 
uint64_t BKE_library_id_can_use_filter_id (const ID *owner_id, const bool include_ui, const IDTypeInfo *owner_id_type=nullptr)
 
bool BKE_library_ID_is_locally_used (Main *bmain, void *idv)
 
bool BKE_library_ID_is_indirectly_used (Main *bmain, void *idv)
 
void BKE_library_ID_test_usages (Main *bmain, void *idv, bool *r_is_used_local, bool *r_is_used_linked)
 
void BKE_lib_query_unused_ids_amounts (Main *bmain, LibQueryUnusedIDsData &parameters)
 
void BKE_lib_query_unused_ids_tag (Main *bmain, int tag, LibQueryUnusedIDsData &parameters)
 
void BKE_library_unused_linked_data_set_tag (Main *bmain, bool do_init_tag)
 
void BKE_library_indirectly_used_data_tag_clear (Main *bmain)
 

Detailed Description

API to perform operations over all ID pointers used by a given data-block.

Note
BKE_lib_ files are for operations over data-blocks themselves, although they might alter Main as well (when creating/renaming/deleting an ID e.g.).

Names

Warning
Descriptions below is ideal goal, current status of naming does not yet fully follow it (this is WIP).
  • BKE_lib_query_ should be used for functions in that file.

Definition in file BKE_lib_query.hh.

Macro Definition Documentation

◆ BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL

◆ BKE_LIB_FOREACHID_PROCESS_ID

◆ BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK

#define BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK ( data_,
id_,
cb_flag_ )
Value:
{ \
BKE_lib_query_foreachid_process((data_), (ID **)&(id_), (cb_flag_)); \
return; \
} \
} \
((void)0)

Should typically only be used when processing deprecated ID types (like IPO ones).

Definition at line 246 of file BKE_lib_query.hh.

Referenced by blender::bke::action_foreach_id(), camera_foreach_id(), curve_foreach_id(), lattice_foreach_id(), light_foreach_id(), material_foreach_id(), mesh_foreach_id(), metaball_foreach_id(), object_foreach_id(), shapekey_foreach_id(), sound_foreach_id(), texture_foreach_id(), and world_foreach_id().

◆ BKE_LIB_FOREACHID_PROCESS_IDSUPER

#define BKE_LIB_FOREACHID_PROCESS_IDSUPER ( data_,
id_super_,
cb_flag_ )
Value:
{ \
BKE_LIB_FOREACHID_PROCESS_IDSUPER_P(data_, &(id_super_), cb_flag_); \
} \
((void)0)

Definition at line 272 of file BKE_lib_query.hh.

Referenced by action_foreach_id(), blender::bke::action_foreach_id(), BKE_animdata_foreach_id(), BKE_nla_strip_foreach_id(), BKE_screen_foreach_id_screen_area(), BKE_texture_mtex_foreach_id(), brush_foreach_id(), buttons_foreach_id(), camera_foreach_id(), clip_foreach_id(), collection_foreach_id(), curve_foreach_id(), curves_foreach_id(), graph_foreach_id(), grease_pencil_foreach_id(), greasepencil_foreach_id(), image_foreach_id(), ipo_foreach_id(), lattice_foreach_id(), library_foreach_id(), blender::bke::library_foreach_node_socket(), lightprobe_foreach_id(), linestyle_foreach_id(), material_foreach_id(), mesh_foreach_id(), metaball_foreach_id(), movie_clip_foreach_id(), nla_foreach_id(), blender::bke::node_foreach_id(), blender::ed::space_node::node_foreach_id(), object_foreach_id(), particle_settings_foreach_id(), pointcloud_foreach_id(), scene_foreach_id(), scene_foreach_layer_collection(), screen_foreach_id(), script_foreach_id(), sequencer_foreach_id(), blender::bke::node_interface::socket_types::socket_data_foreach_id_impl(), blender::bke::node_interface::socket_types::socket_data_foreach_id_impl(), blender::bke::node_interface::socket_types::socket_data_foreach_id_impl(), blender::bke::node_interface::socket_types::socket_data_foreach_id_impl(), blender::bke::node_interface::socket_types::socket_data_foreach_id_impl(), speaker_foreach_id(), text_foreach_id(), texture_foreach_id(), view3d_foreach_id(), volume_foreach_id(), window_manager_foreach_id(), and workspace_foreach_id().

◆ BKE_LIB_FOREACHID_PROCESS_IDSUPER_P

#define BKE_LIB_FOREACHID_PROCESS_IDSUPER_P ( data_,
id_super_p_,
cb_flag_ )
Value:
{ \
CHECK_TYPE(&((*(id_super_p_))->id), ID *); \
BKE_lib_query_foreachid_process((data_), (ID **)(id_super_p_), (cb_flag_)); \
return; \
} \
} \
((void)0)

Definition at line 262 of file BKE_lib_query.hh.

Typedef Documentation

◆ LibraryIDLinkCallback

Call a callback for each ID link which the given ID uses.

Returns
a set of flags to control further iteration (0 to keep going).

Definition at line 157 of file BKE_lib_query.hh.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
IDWALK_CB_NOP 
IDWALK_CB_NEVER_NULL 
IDWALK_CB_NEVER_SELF 
IDWALK_CB_INDIRECT_USAGE 

Indicates whether this is direct (i.e. by local data) or indirect (i.e. by linked data) usage.

IDWALK_CB_DIRECT_WEAK_LINK 

Indicates that this is a direct weak link usage, i.e. if the user is a local ID, and is using (pointing to) a linked ID, that usage does not make the linked ID directly linked.

E.g. usages of linked collections or objects by ViewLayerCollections or Bases in scenes.

Also used for most Editors ID usages (active node tree in the Node editor, shown image in the Image editor, and so on).

See also ID_FLAG_INDIRECT_WEAK_LINK in DNA_ID.h

IDWALK_CB_EMBEDDED 

That ID is used as mere sub-data by its owner (only case currently: those root node-trees in materials etc., and the Scene's master collections). This means callback shall not do anything, only use this as informative data if it needs it.

IDWALK_CB_EMBEDDED_NOT_OWNING 

That ID pointer points to an embedded ID, but does not own it.

E.g the collection pointer of the first ViewLayerCollection of a ViewLayer should always point to the scene's master collection, which is an embedded ID 'owned' by Scene.master_collection.

IDWALK_CB_LOOPBACK 

That ID is not really used by its owner, it's just an internal hint/helper. This marks the 'from' pointers issue, like Key->from. How to handle that kind of cases totally depends on what caller code is doing...

IDWALK_CB_INTERNAL 

Indicates that this is an internal runtime ID pointer, like e.g. ID.newid or ID.original.

Note
Those should be ignored in most cases, and won't be processed/generated anyway unless IDWALK_DO_INTERNAL_RUNTIME_POINTERS option is enabled.
IDWALK_CB_READFILE_IGNORE 

This ID usage should not be processed during readfile (neither during lib-linking nor expanding).

Note that all embedded IDs pointers (IDWALK_CB_EMBEDDED and IDWALK_CB_EMBEDDED_NOT_OWNING) cases are also ignored during readfile.

Mainly used for some 'loopback' pointers like the 'owner_id' of the embedded IDs.

IDWALK_CB_USER 

This ID usage is fully refcounted. Callback is responsible to deal accordingly with ID.us if needed.

IDWALK_CB_USER_ONE 

This ID usage is not refcounted, but at least one user should be generated by it (to avoid e.g. losing the used ID on save/reload). Callback is responsible to deal accordingly with ID.us if needed.

IDWALK_CB_OVERRIDE_LIBRARY_REFERENCE 

This ID is used as library override's reference by its owner.

IDWALK_CB_OVERRIDE_LIBRARY_NOT_OVERRIDABLE 

This ID pointer is not overridable.

IDWALK_CB_OVERRIDE_LIBRARY_HIERARCHY_DEFAULT 

This ID pointer is expected to be overridden by default, in liboverride hierarchy context.

Definition at line 34 of file BKE_lib_query.hh.

◆ anonymous enum

anonymous enum
Enumerator
IDWALK_RET_NOP 
IDWALK_RET_STOP_ITER 

Completely stop iteration.

Note
Should never be returned by a callback in case IDWALK_READONLY is not set.
IDWALK_RET_STOP_RECURSION 

Stop recursion, that is, do not loop over ID used by current one.

Note
Should never be returned by a callback in case IDWALK_READONLY is not set.

Definition at line 118 of file BKE_lib_query.hh.

◆ anonymous enum

anonymous enum
Enumerator
IDWALK_NOP 
IDWALK_READONLY 

The callback will never modify the ID pointers it processes. WARNING: It is very important to pass this flag when valid, as it can lead to important optimizations and debug/assert code.

IDWALK_RECURSE 

Recurse into 'descendant' IDs. Each ID is only processed once. Order of ID processing is not guaranteed.

Also implies IDWALK_READONLY, and excludes IDWALK_DO_INTERNAL_RUNTIME_POINTERS.

NOTE: When enabled, embedded IDs are processed separately from their owner, as if they were regular IDs. The owner ID remains available in the LibraryForeachIDData callback data, unless IDWALK_IGNORE_MISSING_OWNER_ID is passed.

IDWALK_INCLUDE_UI 

Include UI pointers (from WM and screens editors).

IDWALK_IGNORE_EMBEDDED_ID 

Do not process ID pointers inside embedded IDs. Needed by depsgraph processing e.g.

IDWALK_NO_ORIG_POINTERS_ACCESS 

Do not access original processed pointer's data, only process its address value.

This is required in cases where to current address may not be valid anymore (e.g. during readfile process). A few ID pointers (like e.g. the LayerCollection.collection one) are by default accessed to check things (e.g. whether they are pointing to an embedded ID or a regular one).

Note
Access to owning embedded ID pointers (e.g. Scene.master_collection) is not affected here, these are presumed always valid.
This flag is mutually exclusive with IDWALK_RECURSE, since by definition accessing the current ID pointer is required for recursion.
Also implies IDWALK_IGNORE_MISSING_OWNER_ID.
After remapping, code may access the newly set ID pointer, which is always presumed valid.
Warning
Use only with great caution, this flag will modify the handling of some ID pointers (especially when it comes to detecting IDWALK_CB_EMBEDDED_NOT_OWNING usages).
IDWALK_IGNORE_MISSING_OWNER_ID 

Do not attempt to find the owner ID of an embedded one if not explicitly given.

Note
This is needed in some cases, when the loop-back 'owner' ID pointer of the processed embedded data is known to be invalid (as part of depsgraph ID copying code, where embedded IDs are mostly processed on their own, separately from their owner ID).
Also implied by IDWALK_NO_ORIG_POINTERS_ACCESS.
IDWALK_DO_INTERNAL_RUNTIME_POINTERS 

Also process internal ID pointers like ID.newid or ID.orig_id. WARNING: Dangerous, use with caution.

IDWALK_DO_LIBRARY_POINTER 

Also process the ID.lib pointer. It is an option because this pointer can usually be fully ignored.

IDWALK_DO_DEPRECATED_POINTERS 

Also process the DNA-deprecated pointers. Should only be used in readfile related code (for proper lib_linking and expanding of older files).

Definition at line 160 of file BKE_lib_query.hh.

Function Documentation

◆ BKE_lib_query_foreachid_iter_stop()

bool BKE_lib_query_foreachid_iter_stop ( const LibraryForeachIDData * data)

Check whether current iteration over ID usages should be stopped or not.

Returns
true if the iteration should be stopped, false otherwise.

Definition at line 66 of file lib_query.cc.

References IDWALK_STOP.

Referenced by BKE_lib_query_foreachid_process(), BKE_library_foreach_ID_embedded(), library_foreach_ID_link(), and window_manager_foreach_id().

◆ BKE_lib_query_foreachid_process()

◆ BKE_lib_query_foreachid_process_callback_flag_override()

int BKE_lib_query_foreachid_process_callback_flag_override ( LibraryForeachIDData * data,
int cb_flag,
bool do_replace )

Definition at line 130 of file lib_query.cc.

◆ BKE_lib_query_foreachid_process_flags_get()

◆ BKE_lib_query_foreachid_process_main_get()

Main * BKE_lib_query_foreachid_process_main_get ( const LibraryForeachIDData * data)

Definition at line 125 of file lib_query.cc.

Referenced by blender::bke::action_foreach_id().

◆ BKE_lib_query_idpropertiesForeachIDLink_callback()

void BKE_lib_query_idpropertiesForeachIDLink_callback ( IDProperty * id_prop,
void * user_data )

◆ BKE_lib_query_unused_ids_amounts()

void BKE_lib_query_unused_ids_amounts ( Main * bmain,
LibQueryUnusedIDsData & parameters )

Compute amount of unused IDs (a.k.a 'orphaned').

By default only consider IDs with 0 user count. If do_recursive is set, it will check dependencies to detect all IDs that are not actually used in current file, including 'archipelagos‘ (i.e. set of IDs referencing each other in loops, but without any 'external’ valid usages.

Valid usages here are defined as ref-counting usages, which are not towards embedded or loop-back data.

Parameters
r_num_totalA zero-initialized array of INDEX_ID_MAX integers. Number of IDs detected as unused from given parameters, per ID type in the matching index, and as total in INDEX_ID_NULL item.
r_num_localA zero-initialized array of INDEX_ID_MAX integers. Number of local IDs detected as unused from given parameters (but assuming do_local_ids is true), per ID type in the matching index, and as total in INDEX_ID_NULL item.
r_num_linkedA zero-initialized array of INDEX_ID_MAX integers. Number of linked IDs detected as unused from given parameters (but assuming do_linked_ids is true), per ID type in the matching index, and as total in INDEX_ID_NULL item.

Definition at line 904 of file lib_query.cc.

References BKE_main_relations_create(), BKE_main_relations_free(), data, lib_query_unused_ids_tag(), and parameters.

Referenced by blender::ed::outliner::outliner_orphans_purge_check(), and blender::ed::outliner::unused_message_popup_width_compute().

◆ BKE_lib_query_unused_ids_tag()

void BKE_lib_query_unused_ids_tag ( Main * bmain,
int tag,
LibQueryUnusedIDsData & parameters )

Tag all unused IDs (a.k.a 'orphaned').

By default only tag IDs with 0 user count. If do_recursive is set, it will check dependencies to detect all IDs that are not actually used in current file, including 'archipelagos‘ (i.e. set of IDs referencing each other in loops, but without any 'external’ valid usages.

Valid usages here are defined as ref-counting usages, which are not towards embedded or loop-back data.

Parameters
tagthe ID tag to use to mark the ID as unused. Should never be 0.
r_num_tagged_totalA zero-initialized array of INDEX_ID_MAX integers. Number of IDs tagged as unused from given parameters, per ID type in the matching index, and as total in INDEX_ID_NULL item.

Definition at line 962 of file lib_query.cc.

References BKE_main_relations_create(), BKE_main_relations_free(), BLI_assert, data, lib_query_unused_ids_tag(), and parameters.

Referenced by bpy_orphans_purge(), lib_override_cleanup_after_resync(), blender::ed::outliner::outliner_orphans_purge_exec(), and blender::bke::blendfile::PartialWriteContext::remove_unused().

◆ BKE_library_foreach_ID_embedded()

void BKE_library_foreach_ID_embedded ( LibraryForeachIDData * data,
ID ** id_pp )

Process embedded ID pointers (root node-trees, master collections, ...).

Those require specific care, since they are technically sub-data of their owner, yet in some cases they still behave as regular IDs.

Definition at line 163 of file lib_query.cc.

References BKE_lib_query_foreachid_iter_stop(), BKE_lib_query_foreachid_process(), BLI_assert, BLI_gset_add(), BLI_LINKSTACK_PUSH, flag, ID::flag, IDWALK_CB_EMBEDDED, IDWALK_IGNORE_EMBEDDED_ID, IDWALK_RECURSE, IDWALK_STOP, and library_foreach_ID_link().

Referenced by light_foreach_id(), linestyle_foreach_id(), material_foreach_id(), scene_foreach_id(), texture_foreach_id(), and world_foreach_id().

◆ BKE_library_foreach_ID_link()

void BKE_library_foreach_ID_link ( Main * bmain,
ID * id,
blender::FunctionRef< LibraryIDLinkCallback > callback,
void * user_data,
int flag )

Loop over all of the ID's this data-block links to.

Parameters
bmainThe Main data-base containing owner_id, may be null.
idThe ID to process. Note that currently, embedded IDs may also be passed here.
callbackThe callback processing a given ID usage (i.e. a given ID pointer within the given id data).
user_dataOpaque user data for the callback processing a given ID usage.
flagFlags controlling how/which ID pointers are processed.

Definition at line 416 of file lib_query.cc.

References callback, flag, and library_foreach_ID_link().

Referenced by BKE_blendfile_link_append_instantiate_loose(), BKE_id_copy_for_use_in_bmain(), BKE_id_copy_in_lib(), BKE_lib_id_clear_library_data(), BKE_lib_id_expand_local(), BKE_lib_override_library_is_hierarchy_leaf(), BKE_libblock_management_main_add(), BKE_libblock_management_usercounts_clear(), BKE_libblock_management_usercounts_set(), BKE_library_ID_test_usages(), BKE_library_ID_use_ID(), BKE_library_indirectly_used_data_tag_clear(), BKE_library_unused_linked_data_set_tag(), BKE_main_id_refcount_recompute(), BKE_main_relations_create(), BKE_mesh_new_from_object_to_bmain(), blendfile_append_define_actions(), BLO_expand_main(), bpy_user_map(), blender::deg::deg_validate_eval_copy_datablock(), foreach_libblock_link_append_common_processing(), gather_frames_to_render(), blender::bke::blendfile::PartialWriteContext::id_add(), blender::bke::blendfile::PartialWriteContext::is_valid(), lib_link_all(), lib_override_libraries_index_define(), libblock_relink_to_newid_prepare_data(), libblock_remap_data(), library_ID_is_used(), memfile_undosys_step_decode(), paste_material_exec(), previews_ensure_exec(), read_undo_remap_noundo_data(), blender::animrig::internal::rebuild_slot_user_cache(), reuse_bmain_data_invalid_local_usages_fix(), reuse_editable_asset_bmain_data_for_blendfile(), sequencer_write_copy_paste_file(), swap_old_bmain_data_dependencies_process(), blender::ed::object::tag_localizable_objects(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::deg::DepsgraphNodeBuilder::update_invalid_cow_pointers(), and write_file_handle().

◆ BKE_library_foreach_subdata_id()

void BKE_library_foreach_subdata_id ( Main * bmain,
ID * owner_id,
ID * self_id,
blender::FunctionRef< void(LibraryForeachIDData *data)> subdata_foreach_id,
blender::FunctionRef< LibraryIDLinkCallback > callback,
void * user_data,
const int flag )

Apply callback to all ID usages of the data as defined by subdata_foreach_id. Useful to e.g. process all ID usages of a node, or a modifier, and so on.

Note
This function is fully unaware of which data is actually processed. The given subdata_foreach_id callback is responsible to decide which data to process, and to call the relevant 'foreach_id' helpers (typically shared with the relevant IDTypeInfo::foreach_id code path). This is typically done by using a lambda as subdata_foreach_id, which captures the required extra parameters do process the target subdata.
main, owner_id and self_id may be null. There is also no requirement for owner_id or self_id to be actual owner IDs of the processed subdata. This function merely initializes a LibraryForeachIDData object with given parameters, and wraps a call to given subdata_foreach_id.
Parameters
bmainThe Main data-base containing owner_id, may be null.
owner_idThe owner ID, i.e. the data-block owning the given sub-data (may differ from self_id in case the later is an embedded ID).
self_idTypically the same as owner_id, unless it is an embedded ID.
subdata_foreach_idThe callback handling which data to process, and iterating over all ID usages of this subdata. Typically a lambda capturing that subdata, see comments above for details.
callbackThe callback processing a given ID usage, see BKE_library_foreach_ID_link.
user_dataOpaque user data for the callback processing a given ID usage, see BKE_library_foreach_ID_link.
flagFlags controlling the process, see BKE_library_foreach_ID_link. Note that some flags are not accepted here (IDWALK_RECURSE, IDWALK_DO_INTERNAL_RUNTIME_POINTERS, IDWALK_DO_LIBRARY_POINTER, IDWALK_INCLUDE_UI).

Definition at line 436 of file lib_query.cc.

References BLI_assert, LibraryForeachIDData::bmain, callback, flag, ID::flag, IDWALK_DO_INTERNAL_RUNTIME_POINTERS, IDWALK_DO_LIBRARY_POINTER, IDWALK_INCLUDE_UI, and IDWALK_RECURSE.

Referenced by blender::ed::space_node::NodeClipboard::copy_add_node(), blender::ed::space_node::NodeClipboard::paste_update_node_id_references(), blender::ed::space_node::NodeClipboard::paste_validate_id_references(), and blender::bke::tests::TEST().

◆ BKE_library_id_can_use_filter_id()

uint64_t BKE_library_id_can_use_filter_id ( const ID * owner_id,
const bool include_ui,
const IDTypeInfo * owner_id_type = nullptr )

◆ BKE_library_id_can_use_idtype()

bool BKE_library_id_can_use_idtype ( ID * owner_id,
short id_type_used )

Say whether given owner_id may use (in any way) a data-block of id_type_used.

This is a 'simplified' abstract version of BKE_library_foreach_ID_link() above, quite useful to reduce useless iterations in some cases.

Definition at line 502 of file lib_query.cc.

References BKE_idtype_get_info_from_id(), BKE_idtype_idcode_to_idfilter(), and BKE_library_id_can_use_filter_id().

Referenced by BKE_library_ID_test_usages(), and library_ID_is_used().

◆ BKE_library_ID_is_indirectly_used()

◆ BKE_library_ID_is_locally_used()

bool BKE_library_ID_is_locally_used ( Main * bmain,
void * idv )

Check whether given ID is used locally (i.e. by another non-linked ID).

Definition at line 608 of file lib_query.cc.

References library_ID_is_used().

◆ BKE_library_ID_test_usages()

◆ BKE_library_ID_use_ID()

int BKE_library_ID_use_ID ( ID * id_user,
ID * id_used )

Return the number of times given id_user uses/references id_used.

Note
This only checks for pointer references of an ID, shallow usages (like e.g. by RNA paths, as done for FCurves) are not detected at all.
Parameters
id_userthe ID which is supposed to use (reference) id_used.
id_usedthe ID which is supposed to be used (referenced) by id_user.
Returns
the number of direct usages/references of id_used by id_user.

Definition at line 560 of file lib_query.cc.

References BKE_library_foreach_ID_link(), IDUsersIter::count_direct, IDUsersIter::count_indirect, IDUsersIter::curr_id, foreach_libblock_id_users_callback(), IDUsersIter::id, and IDWALK_READONLY.

◆ BKE_library_indirectly_used_data_tag_clear()

void BKE_library_indirectly_used_data_tag_clear ( Main * bmain)

Untag linked data blocks used by other untagged linked data-blocks. Used to detect data-blocks that we can forcefully make local (instead of copying them to later get rid of original): All data-blocks we want to make local are tagged by caller, after this function has ran caller knows data-blocks still tagged can directly be made local, since they are only used by other data-blocks that will also be made fully local.

Definition at line 1035 of file lib_query.cc.

References BKE_library_foreach_ID_link(), foreach_libblock_used_linked_data_tag_clear_cb(), ID_IS_LINKED, ID_TAG_DOIT, IDWALK_READONLY, INDEX_ID_MAX, LISTBASE_FOREACH, and set_listbasepointers().

◆ BKE_library_unused_linked_data_set_tag()

void BKE_library_unused_linked_data_set_tag ( Main * bmain,
bool do_init_tag )

Detect orphaned linked data blocks (i.e. linked data not used (directly or indirectly) in any way by any local data), including complex cases like 'linked archipelagoes', i.e. linked data-blocks that use each other in loops, which prevents their deletion by 'basic' usage checks.

Parameters
do_init_tagif true, all linked data are checked, if false, only linked data-blocks already tagged with ID_TAG_DOIT are checked.

Definition at line 1006 of file lib_query.cc.

References BKE_library_foreach_ID_link(), foreach_libblock_used_linked_data_tag_clear_cb(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, ID_TAG_DOIT, ID_TAG_INDIRECT, IDWALK_READONLY, and ID::tag.

◆ BKE_library_update_ID_link_user()

void BKE_library_update_ID_link_user ( ID * id_dst,
ID * id_src,
int cb_flag )

Re-usable function, use when replacing ID's.

Definition at line 425 of file lib_query.cc.

References id_us_ensure_real(), id_us_min(), id_us_plus(), IDWALK_CB_USER, and IDWALK_CB_USER_ONE.