Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions
lib_query.c File Reference
#include <stdlib.h>
#include "DNA_anim_types.h"
#include "BLI_ghash.h"
#include "BLI_linklist_stack.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BKE_anim_data.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_node.h"

Go to the source code of this file.

Classes

struct  LibraryForeachIDData
 
struct  IDUsersIter
 

Macros

#define CALLBACK_INVOKE_ID(check_id, cb_flag)
 
#define CALLBACK_INVOKE(check_id_super, cb_flag)
 

Typedefs

typedef struct LibraryForeachIDData LibraryForeachIDData
 
typedef struct IDUsersIter IDUsersIter
 

Enumerations

enum  { IDWALK_STOP = 1 << 0 }
 

Functions

bool BKE_lib_query_foreachid_iter_stop (LibraryForeachIDData *data)
 
void BKE_lib_query_foreachid_process (LibraryForeachIDData *data, ID **id_pp, int cb_flag)
 
int BKE_lib_query_foreachid_process_flags_get (LibraryForeachIDData *data)
 
int BKE_lib_query_foreachid_process_callback_flag_override (LibraryForeachIDData *data, const int cb_flag, const bool do_replace)
 
static bool library_foreach_ID_link (Main *bmain, ID *id_owner, ID *id, LibraryIDLinkCallback callback, void *user_data, int flag, LibraryForeachIDData *inherit_data)
 
void BKE_lib_query_idpropertiesForeachIDLink_callback (IDProperty *id_prop, void *user_data)
 
void BKE_library_foreach_ID_embedded (LibraryForeachIDData *data, ID **id_pp)
 
static void library_foreach_ID_data_cleanup (LibraryForeachIDData *data)
 
void BKE_library_foreach_ID_link (Main *bmain, ID *id, LibraryIDLinkCallback callback, void *user_data, int flag)
 
void BKE_library_update_ID_link_user (ID *id_dst, ID *id_src, const int cb_flag)
 
uint64_t BKE_library_id_can_use_filter_id (const ID *id_owner)
 
bool BKE_library_id_can_use_idtype (ID *id_owner, const short id_type_used)
 
static int foreach_libblock_id_users_callback (LibraryIDLinkCallbackData *cb_data)
 
int BKE_library_ID_use_ID (ID *id_user, ID *id_used)
 
static bool library_ID_is_used (Main *bmain, void *idv, const bool check_linked)
 
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 *is_used_local, bool *is_used_linked)
 
static bool lib_query_unused_ids_tag_recurse (Main *bmain, const int tag, const bool do_local_ids, const bool do_linked_ids, ID *id, int *r_num_tagged)
 
void BKE_lib_query_unused_ids_tag (Main *bmain, const int tag, const bool do_local_ids, const bool do_linked_ids, const bool do_tag_recursive, int *r_num_tagged)
 
static int foreach_libblock_used_linked_data_tag_clear_cb (LibraryIDLinkCallbackData *cb_data)
 
void BKE_library_unused_linked_data_set_tag (Main *bmain, const bool do_init_tag)
 
void BKE_library_indirectly_used_data_tag_clear (Main *bmain)
 

Macro Definition Documentation

◆ CALLBACK_INVOKE

#define CALLBACK_INVOKE (   check_id_super,
  cb_flag 
)
Value:
{ \
CHECK_TYPE(&((check_id_super)->id), ID *); \
BKE_lib_query_foreachid_process(&data, (ID **)&(check_id_super), (cb_flag)); \
library_foreach_ID_data_cleanup(&data); \
return false; \
} \
} \
((void)0)
SyclQueue void void size_t num_bytes void
bool BKE_lib_query_foreachid_iter_stop(LibraryForeachIDData *data)
Definition: lib_query.c:63
Definition: DNA_ID.h:368

◆ CALLBACK_INVOKE_ID

#define CALLBACK_INVOKE_ID (   check_id,
  cb_flag 
)
Value:
{ \
CHECK_TYPE_ANY((check_id), ID *, void *); \
BKE_lib_query_foreachid_process(&data, (ID **)&(check_id), (cb_flag)); \
library_foreach_ID_data_cleanup(&data); \
return false; \
} \
} \
((void)0)

Typedef Documentation

◆ IDUsersIter

typedef struct IDUsersIter IDUsersIter

◆ LibraryForeachIDData

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
IDWALK_STOP 

Definition at line 26 of file lib_query.c.

Function Documentation

◆ BKE_lib_query_foreachid_iter_stop()

bool BKE_lib_query_foreachid_iter_stop ( struct 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 63 of file lib_query.c.

References data, and 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()

void BKE_lib_query_foreachid_process ( LibraryForeachIDData data,
ID **  id_pp,
int  cb_flag 
)

◆ BKE_lib_query_foreachid_process_callback_flag_override()

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

Definition at line 114 of file lib_query.c.

References data.

◆ BKE_lib_query_foreachid_process_flags_get()

int BKE_lib_query_foreachid_process_flags_get ( LibraryForeachIDData data)

Definition at line 109 of file lib_query.c.

References data.

Referenced by screen_foreach_id(), and window_manager_foreach_id().

◆ BKE_lib_query_idpropertiesForeachIDLink_callback()

void BKE_lib_query_idpropertiesForeachIDLink_callback ( IDProperty id_prop,
void user_data 
)

◆ BKE_lib_query_unused_ids_tag()

void BKE_lib_query_unused_ids_tag ( struct Main bmain,
int  tag,
bool  do_local_ids,
bool  do_linked_ids,
bool  do_tag_recursive,
int *  r_num_tagged 
)

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

By default only tag IDs with 0 user count. If do_tag_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_taggedIf non-NULL, must be a zero-initialized array of INDEX_ID_MAX integers. Number of tagged-as-unused IDs is then set for each type, and as total in INDEX_ID_NULL item.

Definition at line 778 of file lib_query.c.

References BKE_idtype_idcode_to_index(), BKE_main_relations_create(), BKE_main_relations_free(), BLI_assert, BLI_ghash_lookup(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, GS, id, ID_IS_LINKED, INDEX_ID_NULL, lib_query_unused_ids_tag_recurse(), MAINIDRELATIONS_ENTRY_TAGS_INPROGRESS, MAINIDRELATIONS_ENTRY_TAGS_PROCESSED, ID::name, NULL, Main::relations, MainIDRelations::relations_from_pointers, ID::tag, MainIDRelationsEntry::tags, and ID::us.

Referenced by bpy_orphans_purge(), outliner_orphans_purge_exec(), and outliner_orphans_purge_invoke().

◆ BKE_library_foreach_ID_embedded()

void BKE_library_foreach_ID_embedded ( struct LibraryForeachIDData data,
struct 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 147 of file lib_query.c.

References BKE_lib_query_foreachid_iter_stop(), BKE_lib_query_foreachid_process(), BLI_assert, BLI_gset_add(), BLI_LINKSTACK_PUSH, data, IDWALK_CB_EMBEDDED, IDWALK_IGNORE_EMBEDDED_ID, IDWALK_RECURSE, IDWALK_STOP, library_foreach_ID_link(), and NULL.

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

◆ BKE_library_foreach_ID_link()

void BKE_library_foreach_ID_link ( struct Main bmain,
struct ID id,
LibraryIDLinkCallback  callback,
void user_data,
int  flag 
)

◆ BKE_library_id_can_use_filter_id()

uint64_t BKE_library_id_can_use_filter_id ( const ID id_owner)

◆ BKE_library_id_can_use_idtype()

bool BKE_library_id_can_use_idtype ( struct ID id_owner,
short  id_type_used 
)

Say whether given id_owner 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 484 of file lib_query.c.

References BKE_idtype_idcode_to_idfilter(), BKE_library_id_can_use_filter_id(), ELEM, GS, ID_CU_LEGACY, ID_KE, ID_LI, ID_LT, ID_ME, ID_SCR, ID_WS, ID::name, and ID::properties.

Referenced by BKE_library_ID_test_usages(), and library_ID_is_used().

◆ BKE_library_ID_is_indirectly_used()

bool BKE_library_ID_is_indirectly_used ( struct Main bmain,
void idv 
)

◆ BKE_library_ID_is_locally_used()

bool BKE_library_ID_is_locally_used ( struct Main bmain,
void idv 
)

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

Definition at line 610 of file lib_query.c.

References library_ID_is_used().

◆ BKE_library_ID_test_usages()

void BKE_library_ID_test_usages ( struct Main bmain,
void idv,
bool is_used_local,
bool is_used_linked 
)

◆ BKE_library_ID_use_ID()

int BKE_library_ID_use_ID ( struct ID id_user,
struct 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 562 of file lib_query.c.

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

◆ BKE_library_indirectly_used_data_tag_clear()

void BKE_library_indirectly_used_data_tag_clear ( struct 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 903 of file lib_query.c.

References BKE_library_foreach_ID_link(), foreach_libblock_used_linked_data_tag_clear_cb(), id, ID_IS_LINKED, IDWALK_READONLY, INDEX_ID_MAX, LIB_TAG_DOIT, LISTBASE_FOREACH, set_listbasepointers(), and ID::tag.

◆ BKE_library_unused_linked_data_set_tag()

void BKE_library_unused_linked_data_set_tag ( struct 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 LIB_TAG_DOIT are checked.

Definition at line 874 of file lib_query.c.

References BKE_library_foreach_ID_link(), foreach_libblock_used_linked_data_tag_clear_cb(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, id, IDWALK_READONLY, ID::lib, LIB_TAG_DOIT, LIB_TAG_INDIRECT, and ID::tag.

◆ BKE_library_update_ID_link_user()

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

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

Definition at line 356 of file lib_query.c.

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

◆ foreach_libblock_id_users_callback()

static int foreach_libblock_id_users_callback ( LibraryIDLinkCallbackData cb_data)
static

◆ foreach_libblock_used_linked_data_tag_clear_cb()

static int foreach_libblock_used_linked_data_tag_clear_cb ( LibraryIDLinkCallbackData cb_data)
static

◆ lib_query_unused_ids_tag_recurse()

static bool lib_query_unused_ids_tag_recurse ( Main bmain,
const int  tag,
const bool  do_local_ids,
const bool  do_linked_ids,
ID id,
int *  r_num_tagged 
)
static

◆ library_foreach_ID_data_cleanup()

static void library_foreach_ID_data_cleanup ( LibraryForeachIDData data)
static

Definition at line 184 of file lib_query.c.

References BLI_gset_free(), BLI_LINKSTACK_FREE, data, and NULL.

Referenced by library_foreach_ID_link().

◆ library_foreach_ID_link()

static bool library_foreach_ID_link ( Main bmain,
ID id_owner,
ID id,
LibraryIDLinkCallback  callback,
void user_data,
int  flag,
LibraryForeachIDData inherit_data 
)
static

◆ library_ID_is_used()

static bool library_ID_is_used ( Main bmain,
void idv,
const bool  check_linked 
)
static