Blender  V2.93
Classes | Macros | Functions | Variables
lib_id.c File Reference
#include <ctype.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
#include "DNA_ID.h"
#include "DNA_anim_types.h"
#include "DNA_collection_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_key_types.h"
#include "DNA_node_types.h"
#include "DNA_workspace_types.h"
#include "BLI_utildefines.h"
#include "BLI_alloca.h"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_linklist.h"
#include "BLI_memarena.h"
#include "BLI_string_utils.h"
#include "BLT_translation.h"
#include "BKE_anim_data.h"
#include "BKE_armature.h"
#include "BKE_asset.h"
#include "BKE_bpath.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_gpencil.h"
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_key.h"
#include "BKE_lib_id.h"
#include "BKE_lib_override.h"
#include "BKE_lib_query.h"
#include "BKE_lib_remap.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_rigidbody.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "RNA_access.h"
#include "BLO_read_write.h"
#include "atomic_ops.h"

Go to the source code of this file.

Classes

struct  IDCopyLibManagementData
 

Macros

#define LIB_ID_TYPES_NOCOPY
 
#define ID_SORT_STEP_SIZE   512
 
#define MAX_NUMBER   1000000000
 
#define MIN_NUMBER   1
 
#define MAX_NUMBERS_IN_USE   1024
 

Functions

static void lib_id_library_local_paths (Main *bmain, Library *lib, ID *id)
 
static int lib_id_clear_library_data_users_update_cb (LibraryIDLinkCallbackData *cb_data)
 
static void lib_id_clear_library_data_ex (Main *bmain, ID *id)
 
void BKE_lib_id_clear_library_data (Main *bmain, ID *id)
 
void id_lib_extern (ID *id)
 
void id_lib_indirect_weak_link (ID *id)
 
void id_us_ensure_real (ID *id)
 
void id_us_clear_real (ID *id)
 
void id_us_plus_no_lib (ID *id)
 
void id_us_plus (ID *id)
 
void id_us_min (ID *id)
 
void id_fake_user_set (ID *id)
 
void id_fake_user_clear (ID *id)
 
void BKE_id_clear_newpoin (ID *id)
 
static int lib_id_expand_local_cb (LibraryIDLinkCallbackData *cb_data)
 
void BKE_lib_id_expand_local (Main *bmain, ID *id)
 
static void lib_id_copy_ensure_local (Main *bmain, const ID *old_id, ID *new_id)
 
void BKE_lib_id_make_local_generic (Main *bmain, ID *id, const int flags)
 
bool BKE_lib_id_make_local (Main *bmain, ID *id, const bool test, const int flags)
 
static int id_copy_libmanagement_cb (LibraryIDLinkCallbackData *cb_data)
 
bool BKE_id_copy_is_allowed (const ID *id)
 
IDBKE_id_copy_ex (Main *bmain, const ID *id, ID **r_newid, const int flag)
 
IDBKE_id_copy (Main *bmain, const ID *id)
 
IDBKE_id_copy_for_duplicate (Main *bmain, ID *id, const eDupli_ID_Flags duplicate_flags)
 
static void id_swap (Main *bmain, ID *id_a, ID *id_b, const bool do_full_id)
 
void BKE_lib_id_swap (Main *bmain, ID *id_a, ID *id_b)
 
void BKE_lib_id_swap_full (Main *bmain, ID *id_a, ID *id_b)
 
bool id_single_user (bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
 
static int libblock_management_us_plus (LibraryIDLinkCallbackData *cb_data)
 
static int libblock_management_us_min (LibraryIDLinkCallbackData *cb_data)
 
void BKE_libblock_management_main_add (Main *bmain, void *idv)
 
void BKE_libblock_management_main_remove (Main *bmain, void *idv)
 
void BKE_libblock_management_usercounts_set (Main *bmain, void *idv)
 
void BKE_libblock_management_usercounts_clear (Main *bmain, void *idv)
 
void BKE_main_id_tag_listbase (ListBase *lb, const int tag, const bool value)
 
void BKE_main_id_tag_idcode (struct Main *mainvar, const short type, const int tag, const bool value)
 
void BKE_main_id_tag_all (struct Main *mainvar, const int tag, const bool value)
 
void BKE_main_id_flag_listbase (ListBase *lb, const int flag, const bool value)
 
void BKE_main_id_flag_all (Main *bmain, const int flag, const bool value)
 
void BKE_main_id_repair_duplicate_names_listbase (ListBase *lb)
 
void BKE_main_lib_objects_recalc_all (Main *bmain)
 
size_t BKE_libblock_get_alloc_info (short type, const char **name)
 
void * BKE_libblock_alloc_notest (short type)
 
void * BKE_libblock_alloc (Main *bmain, short type, const char *name, const int flag)
 
void BKE_libblock_init_empty (ID *id)
 
void BKE_lib_libblock_session_uuid_ensure (ID *id)
 
void BKE_lib_libblock_session_uuid_renew (ID *id)
 
void * BKE_id_new (Main *bmain, const short type, const char *name)
 
void * BKE_id_new_nomain (const short type, const char *name)
 
void BKE_libblock_copy_ex (Main *bmain, const ID *id, ID **r_newid, const int orig_flag)
 
void * BKE_libblock_copy (Main *bmain, const ID *id)
 
void * BKE_libblock_copy_for_localize (const ID *id)
 
IDBKE_libblock_find_name (struct Main *bmain, const short type, const char *name)
 
void id_sort_by_name (ListBase *lb, ID *id, ID *id_sorting_hint)
 
static bool id_name_final_build (char *name, char *base_name, size_t base_name_len, int number)
 
static bool check_for_dupid (ListBase *lb, ID *id, char *name, ID **r_id_sorting_hint)
 
bool BKE_id_new_name_validate (ListBase *lb, ID *id, const char *tname)
 
void BKE_main_id_clear_newpoins (Main *bmain)
 
static int id_refcount_recompute_callback (LibraryIDLinkCallbackData *cb_data)
 
void BKE_main_id_refcount_recompute (struct Main *bmain, const bool do_linked_only)
 
static void library_make_local_copying_check (ID *id, GSet *loop_tags, MainIDRelations *id_relations, GSet *done_ids)
 
void BKE_library_make_local (Main *bmain, const Library *lib, GHash *old_to_new_ids, const bool untagged_only, const bool set_fake)
 
void BLI_libblock_ensure_unique_name (Main *bmain, const char *name)
 
void BKE_libblock_rename (Main *bmain, ID *id, const char *name)
 
void BKE_id_full_name_get (char name[MAX_ID_FULL_NAME], const ID *id, char separator_char)
 
void BKE_id_full_name_ui_prefix_get (char name[MAX_ID_FULL_NAME_UI], const ID *id, const bool add_lib_hint, char separator_char, int *r_prefix_len)
 
char * BKE_id_to_unique_string_key (const struct ID *id)
 
void BKE_id_tag_set_atomic (ID *id, int tag)
 
void BKE_id_tag_clear_atomic (ID *id, int tag)
 
bool BKE_id_is_in_global_main (ID *id)
 
bool BKE_id_can_be_asset (const ID *id)
 
static int * id_order_get (ID *id)
 
static int id_order_compare (const void *a, const void *b)
 
void BKE_id_ordered_list (ListBase *ordered_lb, const ListBase *lb)
 
void BKE_id_reorder (const ListBase *lb, ID *id, ID *relative, bool after)
 
void BKE_id_blend_write (BlendWriter *writer, ID *id)
 

Variables

static CLG_LogRef LOG = {.identifier = "bke.lib_id"}
 
IDTypeInfo IDType_ID_LINK_PLACEHOLDER
 
static uint global_session_uuid = 0
 

Detailed Description

Contains management of ID's and libraries allocate and free of all library data

Definition in file lib_id.c.

Macro Definition Documentation

◆ ID_SORT_STEP_SIZE

#define ID_SORT_STEP_SIZE   512

◆ LIB_ID_TYPES_NOCOPY

#define LIB_ID_TYPES_NOCOPY
Value:
ID_LI, ID_SCR, ID_WM, ID_WS, /* Not supported */ \
ID_IP /* Deprecated */
@ ID_WM
Definition: DNA_ID_enums.h:84
@ ID_LI
Definition: DNA_ID_enums.h:58
@ ID_WS
Definition: DNA_ID_enums.h:91
@ ID_SCR
Definition: DNA_ID_enums.h:72

◆ MAX_NUMBER

#define MAX_NUMBER   1000000000

Definition at line 1435 of file lib_id.c.

◆ MAX_NUMBERS_IN_USE

#define MAX_NUMBERS_IN_USE   1024

Definition at line 1441 of file lib_id.c.

◆ MIN_NUMBER

#define MIN_NUMBER   1

Definition at line 1437 of file lib_id.c.

Function Documentation

◆ BKE_id_blend_write()

void BKE_id_blend_write ( BlendWriter writer,
ID id 
)

◆ BKE_id_can_be_asset()

bool BKE_id_can_be_asset ( const ID id)

◆ BKE_id_clear_newpoin()

void BKE_id_clear_newpoin ( ID id)

Definition at line 344 of file lib_id.c.

References id, LIB_TAG_NEW, ID::newid, and NULL.

◆ BKE_id_copy()

ID* BKE_id_copy ( Main bmain,
const ID id 
)

Invokes the appropriate copy method for the block and returns the result in newid, unless test. Returns true if the block can be copied.

Definition at line 636 of file lib_id.c.

References BKE_id_copy_ex(), LIB_ID_COPY_DEFAULT, and NULL.

Referenced by BKE_id_copy_for_duplicate(), and BKE_lib_id_make_local_generic().

◆ BKE_id_copy_ex()

ID* BKE_id_copy_ex ( Main bmain,
const ID id,
ID **  r_newid,
const int  flag 
)

Generic entry point for copying a data-block (new API).

Note
Copy is generally only affecting the given data-block (no ID used by copied one will be affected, besides usercount). There are exceptions though:
  • Embedded IDs (root node trees and master collections) are always copied with their owner.
  • If LIB_ID_COPY_ACTIONS is defined, actions used by animdata will be duplicated.
  • If LIB_ID_COPY_SHAPEKEY is defined, shapekeys will be duplicated.
  • If LIB_ID_CREATE_LOCAL is defined, root node trees will be deep-duplicated recursively.
Usercount of new copy is always set to 1.
Parameters
bmainMain database, may be NULL only if LIB_ID_CREATE_NO_MAIN is specified.
idSource data-block.
r_newidPointer to new (copied) ID pointer, may be NULL. Used to allow copying into already allocated memory.
flagSet of copy options, see DNA_ID.h enum for details (leave to zero for default, full copy).
Returns
NULL when copying that ID type is not supported, the new copy otherwise.

Definition at line 570 of file lib_id.c.

References BKE_idtype_get_info_from_id(), BKE_libblock_copy_ex(), BKE_libblock_get_alloc_info(), BKE_library_foreach_ID_link(), BLI_assert, IDTypeInfo::copy_data, data, IDCopyLibManagementData::flag, ID::flag, IDTypeInfo::flags, GS, id, id_copy_libmanagement_cb(), IDTYPE_FLAGS_NO_COPY, IDWALK_NOP, ID::lib, lib_id_copy_ensure_local(), LIB_ID_COPY_KEEP_LIB, LIB_ID_CREATE_NO_ALLOCATE, LIB_ID_CREATE_NO_MAIN, ID::name, NULL, and size().

Referenced by BKE_id_copy(), and id_single_user().

◆ BKE_id_copy_for_duplicate()

ID* BKE_id_copy_for_duplicate ( Main bmain,
ID id,
const eDupli_ID_Flags  duplicate_flags 
)

Invokes the appropriate copy method for the block and returns the result in newid, unless test. Returns true if the block can be copied.

Definition at line 645 of file lib_id.c.

References BKE_animdata_duplicate_id_action(), BKE_id_copy(), BKE_key_from_id(), id, ID_IS_LINKED, ID_NEW_SET, id_us_min(), ID::newid, NULL, and USER_DUP_LINKED_ID.

◆ BKE_id_copy_is_allowed()

bool BKE_id_copy_is_allowed ( const ID id)

Definition at line 538 of file lib_id.c.

References ELEM, GS, id, LIB_ID_TYPES_NOCOPY, and ID::name.

◆ BKE_id_full_name_get()

void BKE_id_full_name_get ( char  name[MAX_ID_FULL_NAME],
const ID id,
char  separator_char 
)

Generate full name of the data-block (without ID code, but with library if any).

Note
Result is unique to a given ID type in a given Main database.
Parameters
nameAn allocated string of minimal length MAX_ID_FULL_NAME, will be filled with generated string.
separator_charCharacter to use for separating name and library name. Can be 0 to use default (' ').

Definition at line 2205 of file lib_id.c.

References id, Library::id, ID::lib, ID::name, and NULL.

Referenced by BKE_id_full_name_ui_prefix_get().

◆ BKE_id_full_name_ui_prefix_get()

void BKE_id_full_name_ui_prefix_get ( char  name[MAX_ID_FULL_NAME_UI],
const ID id,
const bool  add_lib_hint,
char  separator_char,
int *  r_prefix_len 
)

Generate full name of the data-block (without ID code, but with library if any), with a 2 to 3 character prefix prepended indicating whether it comes from a library, is overriding, has a fake or no user, etc.

Note
Result is unique to a given ID type in a given Main database.
Parameters
nameAn allocated string of minimal length MAX_ID_FULL_NAME_UI, will be filled with generated string.
separator_charCharacter to use for separating name and library name. Can be 0 to use default (' ').
r_prefix_lenThe length of the prefix added.

Definition at line 2234 of file lib_id.c.

References BKE_id_full_name_get(), id, ID_IS_OVERRIDE_LIBRARY, ID_MISSING, LIB_FAKEUSER, and ID::us.

◆ BKE_id_is_in_global_main()

bool BKE_id_is_in_global_main ( ID id)

Check that given ID pointer actually is in G_MAIN. Main intended use is for debug asserts in places we cannot easily get rid of G_Main...

Definition at line 2287 of file lib_id.c.

References BLI_findindex(), G_MAIN, GS, id, ID::name, NULL, and which_libbase().

Referenced by bpy_bmesh_to_mesh(), pygpu_offscreen_draw_view3d(), and pyrna_struct_keyframe_insert().

◆ BKE_id_new()

void* BKE_id_new ( Main bmain,
const short  type,
const char *  name 
)

◆ BKE_id_new_name_validate()

bool BKE_id_new_name_validate ( ListBase lb,
ID id,
const char *  tname 
)

Ensures given ID has a unique name in given listbase.

Only for local IDs (linked ones already have a unique ID in their library).

Returns
true if a new name had to be created.

Definition at line 1690 of file lib_id.c.

References BKE_idtype_idcode_to_name(), BLI_strncpy(), BLI_utf8_invalid_strip(), check_for_dupid(), DATA_, GS, id, ID_IS_LINKED, id_sort_by_name(), MAX_ID_NAME, ID::name, NULL, and result.

Referenced by BKE_libblock_alloc(), BKE_libblock_management_main_add(), BKE_libblock_rename(), BKE_main_id_repair_duplicate_names_listbase(), BLI_libblock_ensure_unique_name(), and lib_id_clear_library_data_ex().

◆ BKE_id_new_nomain()

void* BKE_id_new_nomain ( const short  type,
const char *  name 
)

◆ BKE_id_ordered_list()

void BKE_id_ordered_list ( ListBase ordered_lb,
const ListBase lb 
)

Returns ordered list of data-blocks for display in the UI. Result is list of LinkData of IDs that must be freed.

Definition at line 2337 of file lib_id.c.

References BLI_addtail(), BLI_genericNodeN(), BLI_listbase_clear(), BLI_listbase_sort(), id_order_compare(), id_order_get(), LISTBASE_FOREACH, and order.

◆ BKE_id_reorder()

void BKE_id_reorder ( const ListBase lb,
ID id,
ID relative,
bool  after 
)

Reorder ID in the list, before or after the "relative" ID.

Definition at line 2359 of file lib_id.c.

References BLI_listbase_count(), id_order_get(), LISTBASE_FOREACH, and order.

◆ BKE_id_tag_clear_atomic()

void BKE_id_tag_clear_atomic ( ID id,
int  tag 
)

Definition at line 2278 of file lib_id.c.

References atomic_fetch_and_and_int32(), id, and ID::tag.

◆ BKE_id_tag_set_atomic()

void BKE_id_tag_set_atomic ( ID id,
int  tag 
)

Definition at line 2273 of file lib_id.c.

References atomic_fetch_and_or_int32(), id, and ID::tag.

◆ BKE_id_to_unique_string_key()

char* BKE_id_to_unique_string_key ( const struct ID id)

Generate a concatenation of ID name (including two-chars type code) and its lib name, if any.

Returns
A unique allocated string key for any ID in the whole Main database.

Definition at line 2260 of file lib_id.c.

References BLI_sprintfN(), BLI_strdup(), id, Library::id, ID::lib, ID::name, and NULL.

Referenced by gpencil_strokes_copypastebuf_colors_material_to_name_create(), and gpencil_strokes_copypastebuf_colors_name_to_material_create().

◆ BKE_lib_id_clear_library_data()

void BKE_lib_id_clear_library_data ( Main bmain,
ID id 
)

Definition at line 202 of file lib_id.c.

References lib_id_clear_library_data_ex().

Referenced by brush_make_local(), id_local_fn(), and object_make_local().

◆ BKE_lib_id_expand_local()

void BKE_lib_id_expand_local ( Main bmain,
ID id 
)

Expand ID usages of given id as 'extern' (and no more indirect) linked data. Used by ID copy/make_local functions.

Definition at line 393 of file lib_id.c.

References BKE_library_foreach_ID_link(), IDWALK_READONLY, and lib_id_expand_local_cb().

Referenced by BKE_lib_id_make_local_generic(), BKE_library_make_local(), brush_make_local(), lib_id_copy_ensure_local(), and object_make_local().

◆ BKE_lib_id_make_local()

bool BKE_lib_id_make_local ( Main bmain,
ID id,
const bool  test,
const int  flags 
)

Calls the appropriate make_local method for the block, unless test is set.

Note
Always set ID.newid pointer in case it gets duplicated.
Parameters
flagsSpecial flag used when making a whole library's content local, it needs specific handling.
Returns
true if the block can be made local.

Definition at line 479 of file lib_id.c.

References BKE_idtype_get_info_from_id(), BKE_lib_id_make_local_generic(), BLI_assert, IDTypeInfo::flags, id, IDTYPE_FLAGS_NO_MAKELOCAL, LIB_ID_MAKELOCAL_FULL_LIBRARY, LIB_TAG_INDIRECT, IDTypeInfo::make_local, NULL, and ID::tag.

Referenced by BKE_library_make_local(), brush_make_local(), id_local_fn(), template_ID(), and template_id_cb().

◆ BKE_lib_id_make_local_generic()

void BKE_lib_id_make_local_generic ( Main bmain,
ID id,
const int  flags 
)

◆ BKE_lib_id_swap()

void BKE_lib_id_swap ( Main bmain,
ID id_a,
ID id_b 
)

Does a mere memory swap over the whole IDs data (including type-specific memory).

Note
Most internal ID data itself is not swapped (only IDProperties are).
Parameters
bmainMay be NULL, in which case there will be no remapping of internal pointers to itself.

Definition at line 729 of file lib_id.c.

References id_swap().

Referenced by brush_undo_preserve(), lib_override_id_swap(), and palette_undo_preserve().

◆ BKE_lib_id_swap_full()

void BKE_lib_id_swap_full ( Main bmain,
ID id_a,
ID id_b 
)

Does a mere memory swap over the whole IDs data (including type-specific memory).

Note
All internal ID data itself is also swapped.
Parameters
bmainMay be NULL, in which case there will be no remapping of internal pointers to itself.

Definition at line 741 of file lib_id.c.

References id_swap().

Referenced by read_libblock_undo_restore_at_old_address().

◆ BKE_lib_libblock_session_uuid_ensure()

void BKE_lib_libblock_session_uuid_ensure ( ID id)

Generate a session-wise uuid for the given id.

Note
"session-wise" here means while editing a given .blend file. Once a new .blend file is loaded or created, undo history is cleared/reset, and so is the uuid counter.

Definition at line 1145 of file lib_id.c.

References atomic_add_and_fetch_uint32(), BLI_assert, global_session_uuid, id, LIB_TAG_TEMP_MAIN, MAIN_ID_SESSION_UUID_UNSET, ID::session_uuid, ID::tag, and UNLIKELY.

Referenced by BKE_lib_libblock_session_uuid_renew(), BKE_libblock_alloc(), BKE_libblock_management_main_add(), create_placeholder(), direct_link_id_common(), and versions_gpencil_add_main().

◆ BKE_lib_libblock_session_uuid_renew()

void BKE_lib_libblock_session_uuid_renew ( ID id)

Re-generate a new session-wise uuid for the given id.

Warning
This has a few very specific use-cases, no other usage is expected currently:
  • To handle UI-related data-blocks that are kept across new file reading, when we do keep existing UI.
  • For IDs that are made local without needing any copying.

Definition at line 1166 of file lib_id.c.

References BKE_lib_libblock_session_uuid_ensure(), and MAIN_ID_SESSION_UUID_UNSET.

Referenced by lib_id_clear_library_data_ex(), and setup_app_data().

◆ BKE_libblock_alloc()

void* BKE_libblock_alloc ( Main bmain,
short  type,
const char *  name,
const int  flag 
)

◆ BKE_libblock_alloc_notest()

void* BKE_libblock_alloc_notest ( short  type)

Allocates and returns memory of the right size for the specified block type, initialized to zero.

Definition at line 1045 of file lib_id.c.

References BKE_libblock_get_alloc_info(), BLI_assert, MEM_callocN, NULL, size(), and type.

Referenced by BKE_libblock_alloc(), create_placeholder(), and blender::deg::IDNode::init_copy_on_write().

◆ BKE_libblock_copy()

void* BKE_libblock_copy ( Main bmain,
const ID id 
)

Definition at line 1315 of file lib_id.c.

References BKE_libblock_copy_ex().

◆ BKE_libblock_copy_ex()

void BKE_libblock_copy_ex ( Main bmain,
const ID id,
ID **  r_newid,
const int  orig_flag 
)

◆ BKE_libblock_copy_for_localize()

void* BKE_libblock_copy_for_localize ( const ID id)

Definition at line 1325 of file lib_id.c.

References BKE_libblock_copy_ex(), LIB_ID_COPY_LOCALIZE, LIB_ID_COPY_NO_ANIMDATA, and NULL.

◆ BKE_libblock_find_name()

ID* BKE_libblock_find_name ( struct Main bmain,
const short  type,
const char *  name 
)

◆ BKE_libblock_get_alloc_info()

size_t BKE_libblock_get_alloc_info ( short  type,
const char **  name 
)

Get allocation size of a given data-block type and optionally allocation name.

Definition at line 1024 of file lib_id.c.

References BKE_idtype_get_info_from_idcode(), IDTypeInfo::name, NULL, IDTypeInfo::struct_size, and type.

Referenced by BKE_id_copy_ex(), BKE_libblock_alloc_notest(), and BKE_libblock_copy_ex().

◆ BKE_libblock_init_empty()

void BKE_libblock_init_empty ( ID id)

Initialize an ID of given type, such that it has valid 'empty' data. ID is assumed to be just calloc'ed.

Definition at line 1122 of file lib_id.c.

References BKE_idtype_get_info_from_id(), BLI_assert, IDTypeInfo::init_data, and NULL.

Referenced by BKE_id_new(), BKE_id_new_nomain(), BKE_mesh_new_nomain(), and create_placeholder().

◆ BKE_libblock_management_main_add()

void BKE_libblock_management_main_add ( Main bmain,
void *  idv 
)

◆ BKE_libblock_management_main_remove()

void BKE_libblock_management_main_remove ( Main bmain,
void *  idv 
)

Remove a data-block from given main (set it to 'NO_MAIN' status).

Definition at line 844 of file lib_id.c.

References BKE_main_lock(), BKE_main_unlock(), BLI_assert, BLI_remlink(), GS, id, Main::is_memfile_undo_written, LIB_TAG_NO_MAIN, ID::name, NULL, ID::tag, and which_libbase().

◆ BKE_libblock_management_usercounts_clear()

void BKE_libblock_management_usercounts_clear ( Main bmain,
void *  idv 
)

◆ BKE_libblock_management_usercounts_set()

void BKE_libblock_management_usercounts_set ( Main bmain,
void *  idv 
)

◆ BKE_libblock_rename()

void BKE_libblock_rename ( Main bmain,
ID id,
const char *  name 
)

Sets the name of a block to name, suitably adjusted for uniqueness.

Definition at line 2187 of file lib_id.c.

References BKE_id_new_name_validate(), GS, id, Main::is_memfile_undo_written, ID::name, and which_libbase().

Referenced by DocumentImporter::write_node().

◆ BKE_library_make_local()

void BKE_library_make_local ( Main bmain,
const Library lib,
GHash old_to_new_ids,
const bool  untagged_only,
const bool  set_fake 
)

Make linked data-blocks local.

Parameters
bmainAlmost certainly global main.
libIf not NULL, only make local data-blocks from this library.
untagged_onlyIf true, only make local data-blocks not tagged with LIB_TAG_PRE_EXISTING.
set_fakeIf true, set fake user on all localized data-blocks (except group and objects ones).

Definition at line 1879 of file lib_id.c.

References Freestyle::a, BKE_idtype_idcode_is_linkable(), BKE_lib_id_expand_local(), BKE_lib_id_make_local(), BKE_lib_override_library_make_local(), BKE_libblock_remap(), BKE_library_ID_test_usages(), BKE_main_id_clear_newpoins(), BKE_main_relations_create(), BKE_main_relations_free(), BKE_pose_rebuild(), BKE_rigidbody_ensure_local_object(), BLI_assert, BLI_ghash_insert(), BLI_gset_add(), BLI_gset_free(), BLI_gset_len(), BLI_gset_ptr_new(), BLI_linklist_prepend_arena(), BLI_linklist_prepend_nlink(), BLI_memarena_free(), BLI_memarena_new(), CLOG_WARN, ELEM, ListBase::first, GS, id, Object::id, id_fake_user_set(), ID_GR, ID_IS_LINKED, ID_IS_OVERRIDE_LIBRARY_REAL, ID_OB, ID_REMAP_SKIP_INDIRECT_USAGE, id_us_ensure_real(), if(), INDEX_ID_MAX, lib, ID::lib, lib_id_clear_library_data_ex(), LIB_ID_MAKELOCAL_FULL_LIBRARY, LIB_ID_MAKELOCAL_OBJECT_NO_PROXY_CLEARING, LIB_INDIRECT_WEAK_LINK, LIB_TAG_DOIT, LIB_TAG_EXTERN, LIB_TAG_INDIRECT, LIB_TAG_NEW, LIB_TAG_PRE_EXISTING, library_make_local_copying_check(), LOG, ID::name, ID::newid, LinkNode::next, ID::next, ntree, ntreeFromID(), NULL, OB_ARMATURE, Main::objects, ID::override_library, POSE_RECALC, Object::proxy, Object::proxy_from, Object::proxy_group, IDOverrideLibrary::reference, Main::relations, set_listbasepointers(), ID::tag, TIMEIT_END, TIMEIT_START, and TIMEIT_VALUE_PRINT.

◆ BKE_main_id_clear_newpoins()

void BKE_main_id_clear_newpoins ( Main bmain)

◆ BKE_main_id_flag_all()

void BKE_main_id_flag_all ( Main bmain,
const int  flag,
const bool  value 
)

Clear or set given flags for all ids in bmain (persistent flags).

Definition at line 956 of file lib_id.c.

References Freestyle::a, BKE_main_id_flag_listbase(), IDCopyLibManagementData::flag, INDEX_ID_MAX, and set_listbasepointers().

◆ BKE_main_id_flag_listbase()

void BKE_main_id_flag_listbase ( ListBase lb,
const int  flag,
const bool  value 
)

Clear or set given flags for all ids in listbase (persistent flags).

Definition at line 937 of file lib_id.c.

References ListBase::first, IDCopyLibManagementData::flag, id, ID::next, and ID::tag.

Referenced by BKE_main_id_flag_all(), and id_search_cb_objects_from_scene().

◆ BKE_main_id_refcount_recompute()

void BKE_main_id_refcount_recompute ( struct Main bmain,
const bool  do_linked_only 
)

◆ BKE_main_id_repair_duplicate_names_listbase()

void BKE_main_id_repair_duplicate_names_listbase ( ListBase lb)

◆ BKE_main_id_tag_all()

void BKE_main_id_tag_all ( struct Main mainvar,
const int  tag,
const bool  value 
)

◆ BKE_main_id_tag_idcode()

void BKE_main_id_tag_idcode ( struct Main mainvar,
const short  type,
const int  tag,
const bool  value 
)

Clear or set given tags for all ids of given type in bmain (runtime tags).

Definition at line 910 of file lib_id.c.

References BKE_main_id_tag_listbase(), type, and which_libbase().

Referenced by bake_objects_check(), bake_targets_init_image_textures(), lib_relocate_do(), library_link_clear_tag(), and sound_update_animation_flags_exec().

◆ BKE_main_id_tag_listbase()

void BKE_main_id_tag_listbase ( ListBase lb,
const int  tag,
const bool  value 
)

◆ BKE_main_lib_objects_recalc_all()

void BKE_main_lib_objects_recalc_all ( Main bmain)

◆ BLI_libblock_ensure_unique_name()

void BLI_libblock_ensure_unique_name ( Main bmain,
const char *  name 
)

Use after setting the ID's name When name exists: call 'new_id'

Definition at line 2165 of file lib_id.c.

References BKE_id_new_name_validate(), BLI_findstring(), GS, Main::is_memfile_undo_written, NULL, and which_libbase().

Referenced by BLO_update_defaults_startup_blend(), namebutton_fn(), and rename_id_for_versioning().

◆ check_for_dupid()

static bool check_for_dupid ( ListBase lb,
ID id,
char *  name,
ID **  r_id_sorting_hint 
)
static

Check to see if an ID name is already used, and find a new one if so. Return true if a new name was created (returned in name).

Normally the ID that's being checked is already in the ListBase, so ID *id points at the new entry. The Python Library module needs to know what the name of a data-block will be before it is appended, in this case ID *id is NULL.

Definition at line 1489 of file lib_id.c.

References BLI_assert, BLI_split_name_num(), BLI_strncpy(), ELEM, ListBase::first, GS, ID_IS_LINKED, ID_LINK_PLACEHOLDER, id_name_final_build(), is_valid, MAX_ID_NAME, MAX_NUMBER, MAX_NUMBERS_IN_USE, MIN_NUMBER, ID::name, ID::next, NULL, STREQ, and STREQLEN.

Referenced by BKE_id_new_name_validate().

◆ id_copy_libmanagement_cb()

static int id_copy_libmanagement_cb ( LibraryIDLinkCallbackData cb_data)
static

◆ id_fake_user_clear()

void id_fake_user_clear ( ID id)

◆ id_fake_user_set()

void id_fake_user_set ( ID id)

◆ id_lib_extern()

void id_lib_extern ( ID id)

◆ id_lib_indirect_weak_link()

void id_lib_indirect_weak_link ( ID id)

◆ id_name_final_build()

static bool id_name_final_build ( char *  name,
char *  base_name,
size_t  base_name_len,
int  number 
)
static

Helper building final ID name from given base_name and number.

If everything goes well and we do generate a valid final ID name in given name, we return true. In case the final name would overflow the allowed ID name length, or given number is bigger than maximum allowed value, we truncate further the base_name (and given name, which is assumed to have the same 'base_name' part), and return false.

Definition at line 1451 of file lib_id.c.

References ARRAY_SIZE, BLI_snprintf_rlen(), BLI_strncpy(), BLI_utf8_invalid_strip(), MAX_ID_NAME, and MAX_NUMBER.

Referenced by check_for_dupid().

◆ id_order_compare()

static int id_order_compare ( const void *  a,
const void *  b 
)
static

Definition at line 2313 of file lib_id.c.

References Freestyle::a, id_order_get(), and ID::name.

Referenced by BKE_id_ordered_list().

◆ id_order_get()

static int* id_order_get ( ID id)
static

Definition at line 2302 of file lib_id.c.

References GS, id, ID_WS, ID::name, and NULL.

Referenced by BKE_id_ordered_list(), BKE_id_reorder(), and id_order_compare().

◆ id_refcount_recompute_callback()

static int id_refcount_recompute_callback ( LibraryIDLinkCallbackData cb_data)
static

◆ id_single_user()

bool id_single_user ( bContext C,
ID id,
PointerRNA ptr,
PropertyRNA prop 
)

◆ id_sort_by_name()

void id_sort_by_name ( ListBase lb,
ID id,
ID id_sorting_hint 
)

Sort given id into given lb list, using case-insensitive comparison of the id names.

Note
All other IDs beside given one are assumed already properly sorted in the list.
Parameters
id_sorting_hintIgnored if NULL. Otherwise, used to check if we can insert id immediately before or after that pointer. It must always be into given lb list.

Definition at line 1348 of file lib_id.c.

References BLI_addhead(), BLI_assert, BLI_findindex(), BLI_insertlinkafter(), BLI_insertlinkbefore(), BLI_remlink(), BLI_strcasecmp(), ELEM, ListBase::first, id, ID_SORT_STEP_SIZE, ListBase::last, ID::lib, ID::name, ID::next, NULL, and ID::prev.

Referenced by BKE_blendfile_write_partial(), BKE_id_new_name_validate(), BLO_library_link_copypaste(), create_placeholder(), lib_relocate_do_remap(), and link_named_part().

◆ id_swap()

static void id_swap ( Main bmain,
ID id_a,
ID id_b,
const bool  do_full_id 
)
static

Does a mere memory swap over the whole IDs data (including type-specific memory).

Note
Most internal ID data itself is not swapped (only IDProperties are).

Definition at line 685 of file lib_id.c.

References BKE_idtype_get_info_from_id(), BKE_libblock_relink_ex(), BLI_assert, GS, ID_REMAP_SKIP_NEVER_NULL_USAGE, ID::name, NULL, ID::properties, ID::recalc, and IDTypeInfo::struct_size.

Referenced by BKE_lib_id_swap(), and BKE_lib_id_swap_full().

◆ id_us_clear_real()

void id_us_clear_real ( ID id)

◆ id_us_ensure_real()

void id_us_ensure_real ( ID id)

◆ id_us_min()

void id_us_min ( ID id)

Definition at line 297 of file lib_id.c.

References BLI_assert, CLOG_ERROR, Library::filepath_abs, GS, id, ID_FAKE_USERS, ID_IP, id_us_ensure_real(), ID::lib, LIB_TAG_EXTRAUSER, LOG, ID::name, ID::tag, and ID::us.

Referenced by action_create_new(), action_to_animato(), ANIM_remove_empty_action_from_animdata(), animdata_copy_id_action(), animrecord_check_state(), background_image_remove_exec(), BCAnimation::BCAnimation(), BKE_animdata_free(), BKE_animdata_set_action(), BKE_animdata_transfer_by_basepath(), BKE_brush_add_gpencil(), BKE_freestyle_config_free(), BKE_freestyle_lineset_delete(), BKE_gpencil_brush_material_set(), BKE_gpencil_brush_preset_set(), BKE_gpencil_object_material_new(), BKE_gpencil_palette_ensure(), BKE_id_copy_for_duplicate(), BKE_id_free_us(), BKE_id_material_assign(), BKE_id_material_clear(), BKE_id_material_pop(), BKE_id_material_resize(), BKE_lib_override_library_clear(), BKE_lib_override_library_init(), BKE_library_update_ID_link_user(), BKE_mesh_assign_object(), BKE_mesh_from_nurbs_displist(), BKE_mesh_new_from_object_to_bmain(), BKE_mesh_nomain_to_mesh(), BKE_mesh_to_curve(), BKE_mesh_to_pointcloud(), BKE_nla_action_pushdown(), BKE_nla_tweakmode_exit(), BKE_nlastrip_free(), BKE_object_add_only_object(), BKE_object_material_assign(), BKE_object_material_resize(), BKE_object_material_slot_remove(), BKE_paint_brush_set(), BKE_paint_curve_set(), BKE_paint_init(), BKE_paint_palette_set(), BKE_paint_toolslots_brush_update_ex(), BKE_paint_toolslots_brush_validate(), BKE_pointcloud_to_mesh(), BKE_pose_channel_free_ex(), BKE_scene_add(), BKE_scene_duplicate(), BKE_text_add(), BKE_text_load_ex(), BKE_texture_mtex_add_id(), BKE_workspace_layout_remove(), BLO_update_defaults_startup_blend(), brush_add_exec(), brush_add_gpencil_exec(), brush_generic_tool_set(), brush_undo_preserve_cb(), cachefile_open_exec(), collection_add(), collection_child_remove(), collection_instance_fix_recursive(), collection_object_remove(), con_unlink_refs_cb(), copy_particle_systems_to_object(), DocumentImporter::create_instance_node(), do_version_layers_to_collections(), do_versions_ipos_to_animato(), duplibase_for_convert(), ED_mesh_join_objects_exec(), empty_drop_named_image_invoke(), eyedropper_add_palette_color(), font_open_exec(), foreach_libblock_remap_callback(), FRS_paste_active_lineset(), Freestyle::BlenderStrokeRenderer::GetStrokeShader(), gpencil_data_add_exec(), gpencil_data_unlink_exec(), gpencil_stroke_separate_exec(), id_fake_user_clear(), id_single_user(), IDP_AssignID(), IDP_FreePropertyContent_ex(), image_id_remap(), image_new_exec(), image_open_exec(), import_startjob(), ipo_to_animato(), lib_override_library_create_from(), lib_relocate_do(), libblock_management_us_min(), make_links_data_exec(), make_object_duplilist_real(), modifier_free_data_id_us_cb(), new_material_exec(), new_node_tree_exec(), new_particle_settings_exec(), new_texture_exec(), new_world_exec(), nlaedit_apply_scale_exec(), nlaedit_make_single_user_exec(), node_id_remap(), nodeRemoveNode(), object_convert_exec(), object_data_convert_curve_to_mesh(), object_make_local(), object_remove_particle_system(), object_unlink_data_exec(), open_exec(), paste_mtex_copybuf(), poselib_init_new(), poselib_unlink_exec(), restrictbutton_id_user_toggle(), scene_foreach_toolsettings_id_pointer_process(), separate_exec(), SEQ_effect_text_font_unload(), seq_sequence_free_ex(), sequencer_id_remap(), set_current_brush_texture(), set_current_linestyle_texture(), set_current_particle_texture(), shaderfx_free_data_id_us_cb(), single_obdata_users(), single_object_users_collection(), socket_id_user_decrement(), solve_camera_freejob(), template_id_cb(), unlink_material_fn(), unlink_texture_fn(), unlink_world_fn(), and MeshImporter::write_geometry().

◆ id_us_plus()

void id_us_plus ( ID id)

Definition at line 288 of file lib_id.c.

References id_lib_extern(), and id_us_plus_no_lib().

Referenced by add_collections_to_scene(), add_loose_object_data_to_scene(), blender::io::alembic::AbcObjectReader::addCacheModifier(), BKE_animdata_copy(), BKE_animdata_merge_copy(), BKE_animdata_set_action(), BKE_gpencil_brush_material_set(), BKE_id_material_append(), BKE_id_material_assign(), BKE_id_materials_copy(), BKE_image_load_exists_ex(), BKE_lib_override_library_copy(), BKE_lib_override_library_init(), BKE_library_update_ID_link_user(), BKE_linestyle_alpha_modifier_copy(), BKE_linestyle_color_modifier_copy(), BKE_linestyle_thickness_modifier_copy(), BKE_mesh_assign_object(), BKE_mesh_from_nurbs_displist(), BKE_movieclip_file_add_exists_ex(), BKE_nla_tweakmode_enter(), BKE_nlastrip_copy(), BKE_nlastrip_new(), BKE_node_copy_ex(), BKE_object_add_for_data(), BKE_object_copy_particlesystem(), BKE_object_make_proxy(), BKE_object_material_assign(), BKE_paint_brush_set(), BKE_paint_copy(), BKE_paint_curve_set(), BKE_paint_palette_set(), BKE_paint_toolslots_brush_update_ex(), BKE_pose_channel_copy_data(), BKE_pose_copy_data_ex(), BKE_sound_new_file_exists_ex(), BKE_vfont_load_exists_ex(), BKE_view_layer_copy_data(), BKE_workspace_layout_add(), collection_child_add(), collection_instance_add_exec(), collection_instance_exec(), collection_object_add(), con_fix_copied_refs_cb(), copy_lineset(), MeshImporter::create_mesh_object(), ED_mesh_join_objects_exec(), empty_drop_named_image_invoke(), foreach_libblock_make_usercounts_callback(), FRS_paste_active_lineset(), Freestyle::BlenderStrokeRenderer::GenerateStrokeMesh(), gpencil_modifier_copy_data_id_us_cb(), id_copy_libmanagement_cb(), id_fake_user_set(), IDP_AssignID(), IDP_CopyID(), IDP_New(), image_id_remap(), init(), init_switch_view(), libblock_management_us_plus(), make_links_data_exec(), make_local_all__instance_indirect_unused(), mesh_separate_material_assign_mat_nr(), modifier_copy_data_id_us_cb(), node_add_collection_exec(), node_add_group_exec(), node_add_mask_exec(), node_add_object_exec(), node_add_texture_exec(), node_composit_init_rlayers(), node_id_remap(), node_init(), node_init_api_cryptomatte(), node_link_item_apply(), node_socket_copy_default_value(), object_add_or_copy_particle_system(), object_convert_exec(), object_data_convert_curve_to_mesh(), object_gpencil_add_exec(), paint_toolslots_init(), paste_mtex_copybuf(), pose_proxy_sync(), restrictbutton_id_user_toggle(), seq_dupli(), SEQ_effect_text_font_load(), sequencer_id_remap(), set_current_brush_texture(), set_current_linestyle_texture(), set_current_particle_texture(), blender::io::alembic::AbcObjectReader::setupObjectTransform(), shaderfx_copy_data_id_us_cb(), socket_id_user_increment(), solve_camera_freejob(), template_id_cb(), tracking_plane_tracks_copy(), tracking_tracks_copy(), txt_add_object(), and WM_operator_drop_load_path().

◆ id_us_plus_no_lib()

void id_us_plus_no_lib ( ID id)

Same as id_us_plus, but does not handle lib indirect -> extern. Only used by readfile.c so far, but simpler/safer to keep it here nonetheless.

Definition at line 272 of file lib_id.c.

References BLI_assert, id, LIB_TAG_EXTRAUSER, LIB_TAG_EXTRAUSER_SET, ID::tag, and ID::us.

Referenced by BKE_object_modifiers_lib_link_common(), brush_undo_preserve_cb(), id_refcount_recompute_callback(), id_us_plus(), lib_relocate_do(), scene_blend_read_lib(), and scene_foreach_toolsettings_id_pointer_process().

◆ lib_id_clear_library_data_ex()

static void lib_id_clear_library_data_ex ( Main bmain,
ID id 
)
static

◆ lib_id_clear_library_data_users_update_cb()

static int lib_id_clear_library_data_users_update_cb ( LibraryIDLinkCallbackData cb_data)
static

◆ lib_id_copy_ensure_local()

static void lib_id_copy_ensure_local ( Main bmain,
const ID old_id,
ID new_id 
)
static

Ensure new (copied) ID is fully made local.

Definition at line 401 of file lib_id.c.

References BKE_lib_id_expand_local(), ID_IS_LINKED, ID::lib, and lib_id_library_local_paths().

Referenced by BKE_id_copy_ex().

◆ lib_id_expand_local_cb()

static int lib_id_expand_local_cb ( LibraryIDLinkCallbackData cb_data)
static

◆ lib_id_library_local_paths()

static void lib_id_library_local_paths ( Main bmain,
Library lib,
ID id 
)
static

This has to be called from each make_local_* func, we could call from BKE_lib_id_make_local() but then the make local functions would not be self contained. Also note that the id must have a library - campbell

Definition at line 130 of file lib_id.c.

References BKE_bpath_relocate_visitor(), BKE_bpath_traverse_id(), BKE_BPATH_TRAVERSE_SKIP_MULTIFILE, BKE_main_blendfile_path(), and lib.

Referenced by lib_id_clear_library_data_ex(), and lib_id_copy_ensure_local().

◆ libblock_management_us_min()

static int libblock_management_us_min ( LibraryIDLinkCallbackData cb_data)
static

◆ libblock_management_us_plus()

static int libblock_management_us_plus ( LibraryIDLinkCallbackData cb_data)
static

◆ library_make_local_copying_check()

static void library_make_local_copying_check ( ID id,
GSet loop_tags,
MainIDRelations id_relations,
GSet done_ids 
)
static

Variable Documentation

◆ global_session_uuid

uint global_session_uuid = 0
static

Definition at line 1137 of file lib_id.c.

Referenced by BKE_lib_libblock_session_uuid_ensure().

◆ IDType_ID_LINK_PLACEHOLDER

IDTypeInfo IDType_ID_LINK_PLACEHOLDER
Initial value:
= {
.id_code = ID_LINK_PLACEHOLDER,
.id_filter = 0,
.main_listbase_index = INDEX_ID_NULL,
.struct_size = sizeof(ID),
.name = "LinkPlaceholder",
.name_plural = "link_placeholders",
.translation_context = BLT_I18NCONTEXT_ID_ID,
.copy_data = NULL,
.free_data = NULL,
.make_local = NULL,
.foreach_id = NULL,
.foreach_cache = NULL,
.blend_write = NULL,
.blend_read_data = NULL,
.blend_read_lib = NULL,
.blend_read_expand = NULL,
.blend_read_undo_preserve = NULL,
.lib_override_apply_post = NULL,
}
@ IDTYPE_FLAGS_NO_MAKELOCAL
Definition: BKE_idtype.h:49
@ IDTYPE_FLAGS_NO_COPY
Definition: BKE_idtype.h:45
@ IDTYPE_FLAGS_NO_LIBLINKING
Definition: BKE_idtype.h:47
#define BLT_I18NCONTEXT_ID_ID
struct ID ID
@ INDEX_ID_NULL
Definition: DNA_ID.h:858
#define ID_LINK_PLACEHOLDER
Definition: DNA_ID_enums.h:100
static void init_data(ModifierData *md)

Definition at line 93 of file lib_id.c.

Referenced by id_type_init().

◆ LOG

CLG_LogRef LOG = {.identifier = "bke.lib_id"}
static

Definition at line 90 of file lib_id.c.

Referenced by BKE_library_make_local(), id_us_ensure_real(), and id_us_min().