Blender V4.3
lib_id.cc File Reference
#include <cctype>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#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_legacy_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_array.hh"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_linklist.h"
#include "BLI_memarena.h"
#include "BLI_string_ref.hh"
#include "BLI_string_utils.hh"
#include "BLT_translation.hh"
#include "BKE_anim_data.hh"
#include "BKE_armature.hh"
#include "BKE_asset.hh"
#include "BKE_bpath.hh"
#include "BKE_context.hh"
#include "BKE_global.hh"
#include "BKE_gpencil_legacy.h"
#include "BKE_idprop.hh"
#include "BKE_idtype.hh"
#include "BKE_key.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_override.hh"
#include "BKE_lib_query.hh"
#include "BKE_lib_remap.hh"
#include "BKE_main.hh"
#include "BKE_main_namemap.hh"
#include "BKE_node.hh"
#include "BKE_rigidbody.h"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_build.hh"
#include "DEG_depsgraph_query.hh"
#include "RNA_access.hh"
#include "BLO_read_write.hh"
#include "atomic_ops.h"
#include "lib_intern.hh"

Go to the source code of this file.

Classes

struct  IDCopyLibManagementData
 

Macros

#define LIB_ID_TYPES_NOCOPY   ID_LI, ID_SCR, ID_WM, ID_WS /* Not supported */
 
#define ID_SORT_STEP_SIZE   512
 

Functions

static bool lib_id_library_local_paths_callback (BPathForeachPathData *bpath_data, char *path_dst, size_t path_dst_maxncpy, const char *path_src)
 
static void lib_id_library_local_paths (Main *bmain, Library *lib_to, Library *lib_from, ID *id)
 
static int lib_id_clear_library_data_users_update_cb (LibraryIDLinkCallbackData *cb_data)
 
void BKE_lib_id_clear_library_data (Main *bmain, ID *id, const int flags)
 
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_newptr_and_tag_clear (ID *id)
 
static int lib_id_expand_local_cb (LibraryIDLinkCallbackData *cb_data)
 
void BKE_lib_id_expand_local (Main *bmain, ID *id, const int flags)
 
void lib_id_copy_ensure_local (Main *bmain, const ID *old_id, ID *new_id, const int flags)
 
void BKE_lib_id_make_local_generic_action_define (Main *bmain, ID *id, int flags, bool *r_force_local, bool *r_force_copy)
 
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 int flags)
 
static int id_copy_libmanagement_cb (LibraryIDLinkCallbackData *cb_data)
 
bool BKE_id_copy_is_allowed (const ID *id)
 
IDBKE_id_copy_in_lib (Main *bmain, std::optional< Library * > owner_library, const ID *id, const ID *new_owner_id, ID **new_id_p, const int flag)
 
IDBKE_id_copy_ex (Main *bmain, const ID *id, ID **new_id_p, 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, const int copy_flags)
 
static int foreach_assign_id_to_orig_callback (LibraryIDLinkCallbackData *cb_data)
 
IDBKE_id_copy_for_use_in_bmain (Main *bmain, const ID *id)
 
void BKE_id_move_to_same_lib (Main &bmain, ID &id, const ID &owner_id)
 
static void id_embedded_swap (ID **embedded_id_a, ID **embedded_id_b, const bool do_full_id, IDRemapper *remapper_id_a, IDRemapper *remapper_id_b)
 
static void id_swap (Main *bmain, ID *id_a, ID *id_b, const bool do_full_id, const bool do_self_remap, IDRemapper *input_remapper_id_a, IDRemapper *input_remapper_id_b, const int self_remap_flags)
 
void BKE_lib_id_swap (Main *bmain, ID *id_a, ID *id_b, const bool do_self_remap, const int self_remap_flags)
 
void BKE_lib_id_swap_full (Main *bmain, ID *id_a, ID *id_b, const bool do_self_remap, const int self_remap_flags)
 
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 (Main *mainvar, const short type, const int tag, const bool value)
 
void BKE_main_id_tag_all (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 (Main *bmain, ListBase *lb)
 
void BKE_main_lib_objects_recalc_all (Main *bmain)
 
size_t BKE_libblock_get_alloc_info (short type, const char **r_name)
 
void * BKE_libblock_alloc_notest (short type)
 
void * BKE_libblock_alloc_in_lib (Main *bmain, std::optional< Library * > owner_library, short type, const char *name, const int flag)
 
void * BKE_libblock_alloc (Main *bmain, short type, const char *name, const int flag)
 
void BKE_libblock_init_empty (ID *id)
 
void BKE_libblock_runtime_reset_remapping_status (ID *id)
 
void BKE_lib_libblock_session_uid_ensure (ID *id)
 
void BKE_lib_libblock_session_uid_renew (ID *id)
 
void * BKE_id_new_in_lib (Main *bmain, std::optional< Library * > owner_library, const short type, const char *name)
 
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_in_lib (Main *bmain, std::optional< Library * > owner_library, const ID *id, const ID *new_owner_id, ID **new_id_p, const int orig_flag)
 
void BKE_libblock_copy_ex (Main *bmain, const ID *id, ID **new_id_p, const int orig_flag)
 
void * BKE_libblock_copy (Main *bmain, const ID *id)
 
IDBKE_libblock_find_name (Main *bmain, const short type, const char *name, const std::optional< Library * > lib)
 
IDBKE_libblock_find_session_uid (Main *bmain, const short type, const uint32_t session_uid)
 
IDBKE_libblock_find_name_and_library (Main *bmain, const short type, const char *name, const char *lib_name)
 
IDBKE_libblock_find_name_and_library_filepath (Main *bmain, short type, const char *name, const char *lib_filepath_abs)
 
void id_sort_by_name (ListBase *lb, ID *id, ID *id_sorting_hint)
 
IDNewNameResult BKE_id_new_name_validate (Main &bmain, ListBase &lb, ID &id, const char *newname, IDNewNameMode mode, const bool do_linked_data)
 
void BKE_main_id_newptr_and_tag_clear (Main *bmain)
 
static int id_refcount_recompute_callback (LibraryIDLinkCallbackData *cb_data)
 
void BKE_main_id_refcount_recompute (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, const bool clear_asset_data)
 
IDNewNameResult BKE_libblock_rename (Main &bmain, ID &id, blender::StringRefNull name, const IDNewNameMode mode)
 
IDNewNameResult BKE_id_rename (Main &bmain, ID &id, blender::StringRefNull name, const IDNewNameMode mode)
 
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 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_main (Main *bmain, ID *id)
 
bool BKE_id_is_in_global_main (ID *id)
 
bool BKE_id_can_be_asset (const ID *id)
 
IDBKE_id_owner_get (ID *id, const bool debug_relationship_assert)
 
bool BKE_id_is_editable (const Main *bmain, const ID *id)
 
bool BKE_id_can_use_id (const ID &id_from, const ID &id_to)
 
static intid_order_get (ID *id)
 
static bool id_order_compare (ID *a, ID *b)
 
Vector< ID * > BKE_id_ordered_list (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 = {"bke.lib_id"}
 
IDTypeInfo IDType_ID_LINK_PLACEHOLDER
 
static uint global_session_uid = 0
 

Detailed Description

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

Definition in file lib_id.cc.

Macro Definition Documentation

◆ ID_SORT_STEP_SIZE

#define ID_SORT_STEP_SIZE   512

Referenced by id_sort_by_name().

◆ LIB_ID_TYPES_NOCOPY

#define LIB_ID_TYPES_NOCOPY   ID_LI, ID_SCR, ID_WM, ID_WS /* Not supported */

Referenced by BKE_id_copy_is_allowed().

Function Documentation

◆ BKE_id_blend_write()

◆ BKE_id_can_be_asset()

◆ BKE_id_can_use_id()

bool BKE_id_can_use_id ( const ID & id_from,
const ID & id_to )

Check that a pointer from one ID to another is possible.

Taking into account lib linking and main database membership.

Definition at line 2461 of file lib_id.cc.

References ID_TAG_NO_MAIN, ID::lib, and ID::tag.

Referenced by RNA_property_pointer_poll().

◆ BKE_id_copy()

◆ BKE_id_copy_ex()

ID * BKE_id_copy_ex ( Main * bmain,
const ID * id,
ID ** new_id_p,
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 user-count).

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 anim-data will be duplicated.
  • If LIB_ID_COPY_SHAPEKEY is defined, shape-keys will be duplicated.
  • If LIB_ID_CREATE_LOCAL is defined, root node trees will be deep-duplicated recursively.
Note
User-count of new copy is always set to 1.
Typically, the newly copied ID will be a local data (its lib pointer will be nullptr). In practice, ID copying follows the same behavior as ID creation (see BKE_libblock_alloc documentation), with one special case: when the special flag LIB_ID_CREATE_NO_ALLOCATE is specified, the copied ID will have the same library as the source ID.
Parameters
bmainMain database, may be NULL only if LIB_ID_CREATE_NO_MAIN is specified.
idSource data-block.
new_id_pPointer 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 760 of file lib_id.cc.

References BKE_id_copy_in_lib(), and flag.

Referenced by blender::ed::object::apply_grease_pencil_for_modifier(), blender::ed::object::apply_grease_pencil_for_modifier_all_keyframes(), blender::bke::asset_main_create_from_ID(), BKE_curves_copy_for_eval(), BKE_displist_make_curveTypes(), BKE_grease_pencil_copy_for_eval(), BKE_id_copy_for_duplicate(), BKE_lattice_modifiers_calc(), BKE_lib_id_make_local_generic(), BKE_lib_override_library_update(), BKE_mesh_copy_for_eval(), BKE_nlastrip_copy(), BKE_pointcloud_copy_for_eval(), BKE_volume_copy_for_eval(), clip_start_prefetch_job(), blender::ed::object::create_applied_mesh_for_modifier(), curve_from_curve_object(), curve_from_font_object(), do_hair_dynamics(), duplicate_ids(), blender::ed::space_node::duplicate_material(), flip_pose(), blender::ed::object::geometry_node_tree_copy_assign_exec(), blender::realtime_compositor::get_mask_raster_handles(), get_quick_mesh(), id_single_user(), blender::compositor::MaskOperation::init_execution(), mesh_new_from_mesh(), modify_mesh(), modify_mesh(), modify_mesh(), new_material_exec(), new_particle_settings_exec(), new_world_exec(), blender::bke::node_tree_copy_tree_ex(), normalEditModifier_do(), object_for_curve_to_mesh_create(), particle_settings_localize(), preview_get_localized_world(), psys_thread_context_init_distribute(), remap_hair_emitter(), seq_render_mask(), blender::ed::object::single_mat_users(), blender::ed::object::single_obdata_users(), blender::ed::object::single_object_users_collection(), and undomesh_from_editmesh().

◆ BKE_id_copy_for_duplicate()

ID * BKE_id_copy_for_duplicate ( Main * bmain,
ID * id,
eDupli_ID_Flags duplicate_flags,
int copy_flags )

Invoke the appropriate copy method for the block and return the new id as result.

Unlike BKE_id_copy, it does set the ID.newid pointer of the given id to the copied one.

It is designed as a basic common helper for the higher-level 'duplicate' operations (aka 'deep copy' of data-blocks and some of their dependency ones), see e.g. BKE_object_duplicate.

Currently, it only handles the given ID, and their shape keys and actions if any, according to the given duplicate_flags.

Parameters
duplicate_flagsis of type eDupli_ID_Flags, see UserDef.dupflag. Currently only USER_DUP_LINKED_ID and USER_DUP_ACT have an effect here.
copy_flagsflags passed to BKE_id_copy_ex.

Definition at line 770 of file lib_id.cc.

References BKE_animdata_duplicate_id_action(), BKE_id_copy_ex(), BKE_key_from_id(), ID_IS_LINKED, ID_NEW_SET, id_us_min(), and USER_DUP_LINKED_ID.

Referenced by BKE_object_duplicate(), BKE_scene_duplicate(), and collection_duplicate_recursive().

◆ BKE_id_copy_for_use_in_bmain()

ID * BKE_id_copy_for_use_in_bmain ( Main * bmain,
const ID * id )

Special version of BKE_id_copy which is safe from using evaluated id as source with a copy result appearing in the main database. Takes care of the referenced data-blocks consistency.

Definition at line 834 of file lib_id.cc.

References BKE_id_copy(), BKE_key_from_id_p(), BKE_library_foreach_ID_link(), DEG_is_evaluated_id(), foreach_assign_id_to_orig_callback(), and IDWALK_NOP.

◆ BKE_id_copy_in_lib()

ID * BKE_id_copy_in_lib ( Main * bmain,
std::optional< Library * > owner_library,
const ID * id,
const ID * new_owner_id,
ID ** new_id_p,
int flag )

◆ BKE_id_copy_is_allowed()

bool BKE_id_copy_is_allowed ( const ID * id)

Test whether given id can be copied or not.

Definition at line 647 of file lib_id.cc.

References ELEM, GS, ID_TYPE_IS_DEPRECATED, and LIB_ID_TYPES_NOCOPY.

Referenced by template_ID().

◆ 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 2365 of file lib_id.cc.

References BKE_id_name(), BLI_strncpy(), ID_IS_LINKED, and MAX_ID_FULL_NAME.

Referenced by BKE_id_full_name_ui_prefix_get(), blender::render::hydra::FinalEngine::render(), and SEQ_effect_text_font_load().

◆ 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,
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 2382 of file lib_id.cc.

References BKE_id_full_name_get(), ID_FLAG_FAKEUSER, ID_IS_OVERRIDE_LIBRARY, and ID_MISSING.

Referenced by add_collection_search_item(), id_search_add(), and ui_rna_collection_search_update_fn().

◆ BKE_id_is_editable()

bool BKE_id_is_editable ( const Main * bmain,
const ID * id )

Check if that ID can be considered as editable from a high-level (editor) perspective.

Note
Unlike the ID_IS_EDITABLE macro, this also take into account higher-level aspects, e.g. it checks if the given ID is a system overrides (which should not be editable from the UI).

Definition at line 2456 of file lib_id.cc.

References BKE_lib_override_library_is_system_defined(), and ID_IS_EDITABLE.

Referenced by action_unlink_poll(), blender::ed::object::bake_simulation::bake_simulation_validate_paths(), blender::ed::object::bake_simulation::collect_simulations_to_bake(), blender::ed::outliner::collection_flag_exec(), copy_particle_systems_to_object(), createTransObject(), createTransSculpt(), blender::ed::outliner::datastack_drop_init(), depthdropper_init(), depthdropper_poll(), depthdropper_test(), blender::ed::outliner::do_outliner_item_posemode_toggle(), draw_setting_widget(), ED_editors_init(), ED_object_posemode_enter(), ED_object_posemode_enter_ex(), ED_operator_node_editable(), ED_operator_object_active_editable_ex(), ED_operator_posemode_local(), ED_operator_scene_editable(), edbm_separate_exec(), blender::ed::object::edit_modifier_poll_generic(), blender::ed::object::edit_shaderfx_poll_generic(), blender::ed::geometry::geometry_attributes_poll(), initFlyInfo(), initWalkInfo(), insert_key(), lib_id_fake_user_toggle_exec(), blender::ed::object::make_links_data_exec(), blender::ed::object::make_links_scene_exec(), blender::ed::outliner::material_drop_invoke(), merge_actions_selection_exec(), merge_actions_selection_poll(), blender::ed::object::object_convert_exec(), blender::ed::curves::object_has_editable_curves(), blender::ed::geometry::object_has_editable_data(), blender::ed::object::object_origin_set_exec(), blender::ed::object::object_transform_to_mouse_exec(), blender::ed::outliner::outliner_color_tag_set_exec(), blender::ed::outliner::parent_drop_set_parents(), poselib_keytag_pose(), blender::ed::object::posemode_exec(), blender::ed::outliner::scene_drop_invoke(), blender::ed::object::shade_smooth_exec(), blender::ed::object::bake_simulation::simulate_to_frame_startjob(), blender::ed::object::single_mat_users(), blender::ed::object::single_obdata_users(), blender::ed::object::single_object_action_users(), blender::ed::object::single_objectdata_action_users(), special_aftertrans_update__sculpt(), text_edit_poll(), text_region_edit_poll(), text_space_edit_poll(), view3d_camera_to_view_poll(), WIDGETGROUP_camera_poll(), and WIDGETGROUP_camera_view_poll().

◆ 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 2433 of file lib_id.cc.

References BKE_id_is_in_main(), and G_MAIN.

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

◆ BKE_id_is_in_main()

bool BKE_id_is_in_main ( Main * bmain,
ID * id )

Check that given ID pointer actually is in given bmain.

Definition at line 2426 of file lib_id.cc.

References BLI_findindex(), GS, and which_libbase().

Referenced by BKE_id_is_in_global_main(), and BKE_libblock_rename().

◆ BKE_id_move_to_same_lib()

◆ BKE_id_new()

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

Generic helper to create a new empty data-block of given type in given bmain database.

Note
By default, IDs created in a Main database will get the current library of the Main, i.e. usually (besides in readfile case), they will have a nullptr lib pointer and be local data. IDs created outside of a Main database will always get a nullptr lib pointer.
Parameters
namecan be NULL, in which case we get default name for this ID type.

Definition at line 1482 of file lib_id.cc.

References BKE_id_new_in_lib().

Referenced by blender::animrig::tests::ActionQueryTest::action_new(), blender::bke::tests::add_id_in_library(), BKE_action_add(), BKE_armature_add(), BKE_brush_add(), BKE_cachefile_add(), BKE_camera_add(), BKE_curves_add(), BKE_grease_pencil_add(), BKE_key_add(), BKE_lattice_add(), BKE_light_add(), BKE_lightprobe_add(), BKE_material_add(), BKE_mball_add(), BKE_mesh_add(), BKE_paint_curve_add(), BKE_palette_add(), BKE_particlesettings_add(), BKE_pointcloud_add(), BKE_scene_add(), BKE_speaker_add(), BKE_text_add(), BKE_texture_add(), BKE_volume_add(), BKE_workspace_add(), BKE_world_add(), collection_add(), blender::animrig::tests::ActionLegacyTest::create_empty_action(), blender::ed::greasepencil::tests::GreasePencilIDTestContext::GreasePencilIDTestContext(), lib_override_library_create_post_process(), movieclip_alloc(), blender::ed::object::object_convert_exec(), blender::animrig::nla::tests::NLASlottedActionTest::SetUp(), blender::animrig::tests::ActionFilterTest::SetUp(), blender::animrig::tests::ActionIteratorsTest::SetUp(), blender::animrig::tests::ActionLayersTest::SetUp(), blender::animrig::tests::AnimationEvaluationTest::SetUp(), blender::animrig::tests::KeyframingTest::SetUp(), blender::bke::tests::BPathTest::SetUp(), blender::bke::greasepencil::tests::TEST(), blender::bke::greasepencil::tests::TEST(), blender::bke::greasepencil::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), blender::animrig::tests::TEST_F(), blender::animrig::tests::TEST_F(), blender::animrig::tests::TEST_F(), blender::animrig::tests::TEST_F(), blender::animrig::tests::TEST_F(), blender::bke::tests::TEST_F(), and blender::bke::tests::TEST_F().

◆ BKE_id_new_in_lib()

void * BKE_id_new_in_lib ( Main * bmain,
std::optional< Library * > owner_library,
short type,
const char * name )

Same as for BKE_id_new, but allows creating a data-block for (within) a given owner library.

Parameters
owner_librarythe Library to 'assign' the newly created ID to. Use nullptr to make ID not use any library (i.e. become a local ID). Use std::nullopt for default behavior (i.e. behavior of the BKE_id_new function).

Definition at line 1464 of file lib_id.cc.

References BKE_idtype_idcode_to_name(), BKE_libblock_alloc_in_lib(), BKE_libblock_init_empty(), BLI_assert, and DATA_.

Referenced by BKE_id_new(), blender::bke::blendfile::PartialWriteContext::id_create(), blender::bke::greasepencil::convert::legacy_gpencil_object(), and blender::bke::greasepencil::convert::legacy_main().

◆ BKE_id_new_name_validate()

IDNewNameResult BKE_id_new_name_validate ( Main & bmain,
ListBase & lb,
ID & id,
const char * newname,
IDNewNameMode mode,
bool do_linked_data )

Optionally set the given ID's name from given parameter, and ensure that the ID has a unique name in given listbase.

Uniqueness is only ensured within the ID's library (nullptr for local ones), libraries act as some kind of namespace for IDs.

Parameters
newnameThe new name of the given ID, if nullptr the current given ID name is used instead. If the given ID has no name (or the given name is an empty string), the default matching data name is used as fallback.
do_linked_dataif true, also ensure a unique name in case the given ID is linked (otherwise, just ensure that it is properly sorted).
Returns
How renaming went on, see IDNewNameResult for details.

Definition at line 1850 of file lib_id.cc.

References BKE_id_name(), BKE_idtype_idcode_to_name(), BKE_libblock_find_name(), BKE_main_namemap_get_name(), BLI_assert, BLI_str_utf8_invalid_strip(), BLI_string_split_name_number(), BLI_strncpy(), DATA_, ELEM, GS, ID_IS_LINKED, id_sort_by_name(), lib, MAX_ID_NAME, ID::name, IDNewNameResult::RENAMED_COLLISION_ADJUSTED, IDNewNameResult::RENAMED_COLLISION_FORCED, IDNewNameResult::RENAMED_NO_COLLISION, RenameExistingAlways, RenameExistingSameRoot, result, STREQ, STRNCPY, STRNCPY_UTF8, IDNewNameResult::UNCHANGED, and IDNewNameResult::UNCHANGED_COLLISION.

Referenced by BKE_id_move_to_same_lib(), BKE_lib_id_clear_library_data(), BKE_libblock_alloc_in_lib(), BKE_libblock_management_main_add(), BKE_libblock_rename(), BKE_main_id_repair_duplicate_names_listbase(), main_namemap_validate_and_fix(), reuse_bmain_move_id(), and versions_gpencil_add_main().

◆ BKE_id_new_nomain()

◆ BKE_id_newptr_and_tag_clear()

◆ BKE_id_ordered_list()

◆ BKE_id_owner_get()

ID * BKE_id_owner_get ( ID * id,
const bool debug_relationship_assert = true )

Return the owner ID of the given id, if any.

Note
This will only return non-NULL for embedded IDs (master collections etc.), and shape-keys.
Parameters
debug_relationship_assertTrue by default, whether to perform debug checks on validity of the pointers between owner and embedded IDs. In some cases, these relations are not yet (fully) valid, e.g. during ID copying.

Definition at line 2444 of file lib_id.cc.

References BKE_idtype_get_info_from_id(), and IDTypeInfo::owner_pointer_get.

Referenced by BKE_lib_override_library_get(), blender::ed::outliner::collection_duplicate_exec(), blender::animrig::find_related_ids(), blender::animrig::id_action_ensure(), blender::bke::blendfile::PartialWriteContext::id_add(), lib_query_unused_ids_tag_recurse(), libblock_remap_data(), library_foreach_ID_link(), blender::ed::outliner::outliner_collection_delete(), and RNA_find_real_ID_and_path().

◆ BKE_id_rename()

IDNewNameResult BKE_id_rename ( Main & bmain,
ID & id,
blender::StringRefNull name,
const IDNewNameMode mode = IDNewNameMode::RenameExistingNever )

Like BKE_libblock_rename, but also performs additional higher-level updates like depsgraph tagging when renaming Meta-ball objects, etc.

Returns
true if the name of the ID was actually modified.

Definition at line 2338 of file lib_id.cc.

References BKE_libblock_rename(), DEG_id_tag_update(), ELEM, GS, Object::id, ID_OB, ID_RECALC_GEOMETRY, OB_MBALL, result, Object::type, IDNewNameResult::UNCHANGED, and IDNewNameResult::UNCHANGED_COLLISION.

Referenced by ED_id_rename().

◆ 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 2524 of file lib_id.cc.

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

Referenced by workspace_append_activate_exec(), workspace_reorder_to_back_exec(), and workspace_reorder_to_front_exec().

◆ BKE_id_tag_clear_atomic()

void BKE_id_tag_clear_atomic ( ID * id,
int tag )

Definition at line 2421 of file lib_id.cc.

References atomic_fetch_and_and_int32().

◆ BKE_id_tag_set_atomic()

void BKE_id_tag_set_atomic ( ID * id,
int tag )

Definition at line 2416 of file lib_id.cc.

References atomic_fetch_and_or_int32().

◆ BKE_id_to_unique_string_key()

char * BKE_id_to_unique_string_key ( const 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 2403 of file lib_id.cc.

References BKE_id_name(), BLI_sprintfN(), BLI_strdup(), and ID_IS_LINKED.

◆ BKE_lib_id_clear_library_data()

◆ BKE_lib_id_expand_local()

void BKE_lib_id_expand_local ( Main * bmain,
ID * id,
int flags )

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

Definition at line 474 of file lib_id.cc.

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

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

◆ BKE_lib_id_make_local()

bool BKE_lib_id_make_local ( Main * bmain,
ID * id,
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 is the ID has successfully been made local.

Definition at line 584 of file lib_id.cc.

References BKE_idtype_get_info_from_id(), BKE_lib_id_make_local_generic(), BLI_assert, BLI_assert_msg, IDTypeInfo::flags, ID_TAG_INDIRECT, IDTYPE_FLAGS_NO_LIBLINKING, LIB_ID_MAKELOCAL_FULL_LIBRARY, LIB_ID_MAKELOCAL_INDIRECT, and IDTypeInfo::make_local.

Referenced by BKE_blendfile_append(), BKE_library_make_local(), brush_make_local(), blender::ed::outliner::id_local_fn(), and template_id_cb().

◆ BKE_lib_id_make_local_generic()

◆ BKE_lib_id_make_local_generic_action_define()

void BKE_lib_id_make_local_generic_action_define ( Main * bmain,
ID * id,
int flags,
bool * r_force_local,
bool * r_force_copy )

Helper to decide whether given id can be directly made local, or needs to be copied. r_force_local and r_force_copy cannot be true together. But both can be false, in case no action should be performed.

Note
low-level helper to de-duplicate logic between BKE_lib_id_make_local_generic and the specific corner-cases implementations needed for objects and brushes.

Definition at line 488 of file lib_id.cc.

References BKE_library_ID_test_usages(), BLI_assert, LIB_ID_MAKELOCAL_FORCE_COPY, LIB_ID_MAKELOCAL_FORCE_LOCAL, and LIB_ID_MAKELOCAL_FULL_LIBRARY.

Referenced by BKE_lib_id_make_local_generic(), and brush_make_local().

◆ BKE_lib_id_swap()

void BKE_lib_id_swap ( Main * bmain,
ID * id_a,
ID * id_b,
const bool do_self_remap,
const int self_remap_flags )

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 is no guarantee that internal remapping of ID pointers to themselves will be complete (regarding depsgraph and/or runtime data updates).
do_self_remapWhether to remap internal pointers to itself or not.
self_remap_flagsFlags controlling self remapping, see BKE_lib_remap.hh.

Definition at line 1022 of file lib_id.cc.

References id_swap().

Referenced by 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,
const bool do_self_remap,
const int self_remap_flags )

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

Note
All internal ID data itself is also swapped.

For parameters description, see BKE_lib_id_swap above.

Definition at line 1028 of file lib_id.cc.

References id_swap().

Referenced by read_libblock_undo_restore_at_old_address(), and swap_wm_data_for_blendfile().

◆ BKE_lib_libblock_session_uid_ensure()

void BKE_lib_libblock_session_uid_ensure ( ID * id)

Generate a session-wise UID 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 UID counter.

Definition at line 1445 of file lib_id.cc.

References atomic_add_and_fetch_uint32(), BLI_assert, global_session_uid, ID_TAG_TEMP_MAIN, MAIN_ID_SESSION_UID_UNSET, and UNLIKELY.

Referenced by BKE_lib_libblock_session_uid_renew(), BKE_libblock_alloc_in_lib(), BKE_libblock_management_main_add(), create_placeholder(), direct_link_id_common(), and versions_gpencil_add_main().

◆ BKE_lib_libblock_session_uid_renew()

void BKE_lib_libblock_session_uid_renew ( ID * id)

Re-generate a new session-wise UID 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 1458 of file lib_id.cc.

References BKE_lib_libblock_session_uid_ensure(), and MAIN_ID_SESSION_UID_UNSET.

Referenced by BKE_lib_id_clear_library_data(), reuse_bmain_move_id(), and swap_old_bmain_data_for_blendfile().

◆ BKE_libblock_alloc()

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

Allocates and returns an ID block of the specified type, with the specified name (adjusted as necessary to ensure uniqueness), and appended to the specified list. The user count is set to 1, all other content (apart from name and links) being initialized to zero.

Note
By default, IDs allocated in a Main database will get the current library of the Main, i.e. usually (besides in readfile case), they will have a nullptr lib pointer and be local data. IDs allocated outside of a Main database will always get a nullptr lib pointer.

Definition at line 1415 of file lib_id.cc.

References BKE_libblock_alloc_in_lib(), and flag.

Referenced by BKE_curve_add(), BKE_gpencil_data_addnew(), BKE_id_new_nomain(), BKE_linestyle_new(), BKE_mesh_new_nomain(), BKE_object_add_only_object(), BKE_pointcloud_add_default(), BKE_pointcloud_new_nomain(), BKE_sound_new_file(), BKE_text_load_ex(), BKE_vfont_load(), blo_find_main(), cachefile_open_exec(), mask_alloc(), screen_add(), and wm_add_default().

◆ BKE_libblock_alloc_in_lib()

void * BKE_libblock_alloc_in_lib ( Main * bmain,
std::optional< Library * > owner_library,
short type,
const char * name,
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 1310 of file lib_id.cc.

References BKE_libblock_get_alloc_info(), BLI_assert_msg, and MEM_callocN.

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

◆ BKE_libblock_copy()

void * BKE_libblock_copy ( Main * bmain,
const ID * id )

Used everywhere in blenkernel.

Note
Typically, the newly copied ID will be a local data (its lib pointer will be nullptr). In practice, ID copying follows the same behavior as ID creation (see BKE_libblock_alloc documentation), with one special case: when the special flag LIB_ID_CREATE_NO_ALLOCATE is specified, the copied ID will have the same library as the source ID.

Definition at line 1646 of file lib_id.cc.

References BKE_libblock_copy_in_lib().

◆ BKE_libblock_copy_ex()

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

Definition at line 1641 of file lib_id.cc.

References BKE_libblock_copy_in_lib().

◆ BKE_libblock_copy_in_lib()

void BKE_libblock_copy_in_lib ( Main * bmain,
std::optional< Library * > owner_library,
const ID * id,
const ID * new_owner_id,
ID ** new_id_p,
int orig_flag )

Same as BKE_libblock_copy_ex, but allows copying data into a library, and not as local data only.

Parameters
owner_librarythe Library to 'assign' the newly created ID to. Use nullptr to make ID not use any library (i.e. become a local ID). Use #std::nullopt for default behavior (i.e. behavior of the BKE_libblock_copy_ex function).
new_owner_idWhen copying an embedded ID, the owner ID of the new copy. Should be nullptr for regular ID copying, or in case the owner ID is not (yet) known.

Definition at line 1503 of file lib_id.cc.

References IdAdtTemplate::adt, ID::asset_data, BKE_animdata_copy_in_lib(), BKE_asset_metadata_copy(), BKE_id_name(), BKE_idtype_get_info_from_id(), BKE_lib_override_library_copy(), BKE_libblock_alloc_in_lib(), BKE_libblock_get_alloc_info(), BLI_assert, DEG_id_type_tag(), flag, ID::flag, GS, id_can_have_animdata(), ID_FLAG_EMBEDDED_DATA, ID_FLAG_EMBEDDED_DATA_LIB_OVERRIDE, ID_IS_OVERRIDE_LIBRARY_REAL, ID_IS_OVERRIDE_LIBRARY_VIRTUAL, ID_TAG_COPIED_ON_EVAL, ID_TAG_EXTERN, ID_TAG_INDIRECT, ID_TAG_NO_MAIN, ID_TAG_NO_USER_REFCOUNT, ID_TAG_NOT_ALLOCATED, IDP_CopyProperty_ex(), int, ID::lib, LIB_ID_COPY_ACTIONS, LIB_ID_COPY_ASSET_METADATA, LIB_ID_COPY_NO_ANIMDATA, LIB_ID_COPY_NO_LIB_OVERRIDE, LIB_ID_COPY_SET_COPIED_ON_WRITE, LIB_ID_CREATE_LOCAL, LIB_ID_CREATE_NO_ALLOCATE, LIB_ID_CREATE_NO_DEG_TAG, LIB_ID_CREATE_NO_MAIN, LIB_ID_CREATE_NO_USER_REFCOUNT, ID::library_weak_reference, ID::name, IDTypeInfo::owner_pointer_get, ID::properties, STRNCPY, ID::tag, and ID::us.

Referenced by BKE_id_copy_in_lib(), BKE_libblock_copy(), and BKE_libblock_copy_ex().

◆ BKE_libblock_find_name()

◆ BKE_libblock_find_name_and_library()

ID * BKE_libblock_find_name_and_library ( Main * bmain,
const short type,
const char * name,
const char * lib_name )

Definition at line 1687 of file lib_id.cc.

References BKE_id_name(), BLI_assert, LISTBASE_FOREACH, STREQ, and which_libbase().

◆ BKE_libblock_find_name_and_library_filepath()

ID * BKE_libblock_find_name_and_library_filepath ( Main * bmain,
short type,
const char * name,
const char * lib_filepath_abs )

◆ BKE_libblock_find_session_uid()

◆ BKE_libblock_get_alloc_info()

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

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

Definition at line 1293 of file lib_id.cc.

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

Referenced by BKE_id_copy_in_lib(), BKE_libblock_alloc_notest(), and BKE_libblock_copy_in_lib().

◆ 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 1420 of file lib_id.cc.

References BKE_idtype_get_info_from_id(), BLI_assert_msg, and IDTypeInfo::init_data.

Referenced by BKE_id_new_in_lib(), BKE_id_new_nomain(), BKE_mesh_new_nomain(), create_placeholder(), blender::eevee::LookdevWorld::LookdevWorld(), and blender::bke::node_tree_add_tree_do().

◆ 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 1130 of file lib_id.cc.

References BKE_id_name(), BKE_main_lock(), BKE_main_namemap_remove_name(), BKE_main_unlock(), BLI_assert, BLI_remlink(), GS, ID_TAG_NO_MAIN, Main::is_memfile_undo_written, and which_libbase().

Referenced by BKE_main_merge().

◆ 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()

◆ BKE_libblock_runtime_reset_remapping_status()

void BKE_libblock_runtime_reset_remapping_status ( ID * id)

Reset the runtime counters used by ID remapping.

Definition at line 1434 of file lib_id.cc.

Referenced by libblock_remap_foreach_idpair(), and libblock_remap_reset_remapping_status_fn().

◆ BKE_library_make_local()

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

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 ID_TAG_PRE_EXISTING.
set_fakeIf true, set fake user on all localized data-blocks (except group and objects ones).
clear_asset_dataIf true, clear the asset metadata on all localized data-blocks, making them normal non-asset data-blocks.

Definition at line 2075 of file lib_id.cc.

References BKE_idtype_idcode_is_linkable(), BKE_lib_id_clear_library_data(), BKE_lib_id_expand_local(), BKE_lib_id_make_local(), BKE_lib_override_library_main_hierarchy_root_ensure(), BKE_lib_override_library_make_local(), BKE_libblock_remap(), BKE_main_id_newptr_and_tag_clear(), 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(), ELEM, ListBase::first, GS, id_fake_user_set(), ID_GR, ID_IS_LINKED, ID_IS_OVERRIDE_LIBRARY_REAL, ID_OB, ID_REMAP_SKIP_INDIRECT_USAGE, ID_TAG_DOIT, ID_TAG_EXTERN, ID_TAG_INDIRECT, ID_TAG_NEW, ID_TAG_PRE_EXISTING, id_us_ensure_real(), INDEX_ID_MAX, lib, LIB_ID_MAKELOCAL_ASSET_DATA_CLEAR, LIB_ID_MAKELOCAL_FULL_LIBRARY, library_make_local_copying_check(), LinkNode::next, blender::bke::node_tree_from_id(), OB_ARMATURE, Main::objects, POSE_RECALC, printf, Main::relations, set_listbasepointers(), ID::tag, TIMEIT_END, TIMEIT_START, and TIMEIT_VALUE_PRINT.

Referenced by blender::ed::object::make_local_exec(), and blender::bke::blendfile::PartialWriteContext::write().

◆ BKE_main_id_flag_all()

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

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

Definition at line 1225 of file lib_id.cc.

References BKE_main_id_flag_listbase(), flag, INDEX_ID_MAX, and set_listbasepointers().

◆ BKE_main_id_flag_listbase()

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

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

Definition at line 1209 of file lib_id.cc.

References ListBase::first, flag, and ID::tag.

Referenced by BKE_main_id_flag_all(), and id_search_cb_objects_from_scene().

◆ BKE_main_id_newptr_and_tag_clear()

◆ BKE_main_id_refcount_recompute()

◆ BKE_main_id_repair_duplicate_names_listbase()

void BKE_main_id_repair_duplicate_names_listbase ( Main * bmain,
ListBase * lb )

◆ BKE_main_id_tag_all()

◆ BKE_main_id_tag_idcode()

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

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

Note
Affect whole Main database.

Definition at line 1191 of file lib_id.cc.

References BKE_main_id_tag_listbase(), and which_libbase().

Referenced by blender::ed::object::bake_objects_check(), blender::ed::object::bake_targets_init_image_textures(), BKE_blendfile_library_relocate(), blender::ed::outliner::id_delete_tag(), and sound_update_animation_flags_exec().

◆ BKE_main_id_tag_listbase()

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

◆ BKE_main_lib_objects_recalc_all()

◆ foreach_assign_id_to_orig_callback()

static int foreach_assign_id_to_orig_callback ( LibraryIDLinkCallbackData * cb_data)
static

◆ id_copy_libmanagement_cb()

◆ id_embedded_swap()

static void id_embedded_swap ( ID ** embedded_id_a,
ID ** embedded_id_b,
const bool do_full_id,
IDRemapper * remapper_id_a,
IDRemapper * remapper_id_b )
static

Definition at line 984 of file lib_id.cc.

References blender::bke::id::IDRemapper::add(), BLI_assert, and id_swap().

Referenced by id_swap().

◆ id_fake_user_clear()

◆ id_fake_user_set()

◆ id_lib_extern()

◆ id_lib_indirect_weak_link()

◆ id_order_compare()

static bool id_order_compare ( ID * a,
ID * b )
static

Definition at line 2488 of file lib_id.cc.

References b, and id_order_get().

Referenced by BKE_id_ordered_list().

◆ id_order_get()

static int * id_order_get ( ID * id)
static

Definition at line 2477 of file lib_id.cc.

References GS, and ID_WS.

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

◆ id_refcount_recompute_callback()

◆ id_single_user()

◆ 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 1737 of file lib_id.cc.

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

Referenced by blender::bke::tests::add_id_in_library(), BKE_id_new_name_validate(), blendfile_library_relocate_remap(), blender::bke::tests::change_name_global(), create_placeholder(), expand_doit_library(), lib_override_library_create_from(), link_named_part(), sort_linked_ids(), blender::bke::tests::TEST(), blender::bke::tests::TEST(), and blender::bke::tests::TEST().

◆ id_swap()

static void id_swap ( Main * bmain,
ID * id_a,
ID * id_b,
const bool do_full_id,
const bool do_self_remap,
IDRemapper * input_remapper_id_a,
IDRemapper * input_remapper_id_b,
const int self_remap_flags )
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 894 of file lib_id.cc.

References blender::bke::id::IDRemapper::add(), BKE_idtype_get_info_from_id(), BKE_libblock_relink_multiple(), BLI_assert, GS, id_embedded_swap(), ID_REMAP_TYPE_REMAP, ID_SCE, Scene::master_collection, ID::name, blender::bke::node_tree_ptr_from_id(), ID::properties, ID::recalc, and IDTypeInfo::struct_size.

Referenced by BKE_lib_id_swap(), BKE_lib_id_swap_full(), and id_embedded_swap().

◆ id_us_clear_real()

◆ id_us_ensure_real()

◆ id_us_min()

void id_us_min ( ID * id)

Definition at line 359 of file lib_id.cc.

References CLOG_ERROR, GS, ID_FAKE_USERS, ID_TAG_EXTRAUSER, ID_TYPE_IS_DEPRECATED, id_us_ensure_real(), and LOG.

Referenced by action_create_new(), action_to_animato(), blender::io::usd::USDMaterialReader::add_material(), blender::animrig::animdata_remove_empty_action(), animdata_set_action(), blender::bke::id::IDRemapper::apply(), blender::ed::object::apply_objects_internal(), blender::io::alembic::utils::assign_materials(), BCAnimation::BCAnimation(), BKE_animdata_free(), BKE_blendfile_library_relocate(), BKE_collection_object_replace(), BKE_freestyle_config_free(), BKE_freestyle_lineset_delete(), BKE_gpencil_brush_material_set(), BKE_gpencil_palette_ensure(), BKE_grease_pencil_object_material_new(), 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_main_proxy_convert(), BKE_lib_override_library_proxy_convert(), BKE_library_update_ID_link_user(), BKE_light_linking_collection_assign_only(), BKE_main_mesh_legacy_convert_auto_smooth(), BKE_mesh_assign_object(), BKE_mesh_new_from_object_to_bmain(), BKE_mesh_nomain_to_mesh(), BKE_mesh_to_curve(), BKE_mesh_to_pointcloud(), BKE_nlastrip_free(), BKE_object_add_only_object(), BKE_object_material_from_eval_data(), BKE_object_material_resize(), BKE_object_material_slot_remove(), BKE_paint_palette_set(), 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_vfont_builtin_get(), BKE_workspace_layout_remove(), cachefile_open_exec(), camera_background_image_remove_exec(), collection_add(), collection_child_remove(), collection_instance_fix_recursive(), collection_object_remove_no_gobject_hash(), con_unlink_refs_cb(), copy_particle_systems_to_object(), DocumentImporter::create_instance_node(), blender::ed::greasepencil::undo::StepDrawingReference::decode(), do_version_layers_to_collections(), do_versions_ipos_to_animato(), drop_world_exec(), blender::ed::object::duplibase_for_convert(), ED_mesh_join_objects_exec(), blender::ui::greasepencil::eyedropper_add_palette_color(), font_open_exec(), foreach_libblock_remap_callback_apply(), FRS_paste_active_lineset(), blender::animrig::generic_assign_action(), blender::ed::object::geometry_node_tree_copy_assign_exec(), blender::io::obj::get_or_create_material(), Freestyle::BlenderStrokeRenderer::GetStrokeShader(), gpencil_data_add_exec(), gpencil_data_unlink_exec(), blender::animrig::id_action_ensure(), blender::bke::blendfile::PartialWriteContext::id_create(), id_fake_user_clear(), id_single_user(), IDP_AssignID(), IDP_FreePropertyContent_ex(), image_new_exec(), image_open_exec(), import_file(), blender::io::usd::import_startjob(), ipo_to_animato(), ipo_to_animdata(), blender::bke::greasepencil::convert::legacy_gpencil_object(), blender::bke::greasepencil::convert::legacy_gpencil_sanitize_annotations(), blender::bke::greasepencil::convert::legacy_main(), lib_override_library_create_from(), lib_override_library_create_post_process(), libblock_management_us_min(), blender::ed::object::make_links_data_exec(), blender::ed::object::make_object_duplilist_real(), modifier_free_data_id_us_cb(), modifier_free_data_id_us_cb(), new_material_exec(), blender::ed::space_node::new_node_tree_exec(), new_particle_settings_exec(), new_texture_exec(), new_world_exec(), nlaedit_apply_scale_exec(), nlaedit_make_single_user_exec(), blender::ed::space_node::node_duplicate_exec(), blender::ed::space_node::node_id_remap(), blender::bke::node_remove_node(), blender::nodes_modifier_data_block_destruct(), blender::ed::object::object_convert_exec(), blender::ed::object::object_data_convert_curve_to_mesh(), blender::ed::object::object_image_add_invoke(), object_material_assign(), object_remove_particle_system(), blender::ed::object::object_unlink_data_exec(), open_exec(), paste_material_nodetree_ids_decref(), paste_material_nodetree_ids_relink_or_clear(), paste_mtex_copybuf(), blender::ed::outliner::restrictbutton_id_user_toggle(), reuse_bmain_data_invalid_local_usages_fix_cb(), scene_foreach_toolsettings_id_pointer_process(), separate_exec(), seq_convert_callback(), SEQ_effect_text_font_unload(), seq_sequence_free_ex(), set_current_brush_texture(), set_current_linestyle_texture(), set_current_particle_texture(), blender::io::usd::USDInstanceReader::set_instance_collection(), blender::animrig::tests::KeyframingTest::SetUp(), shaderfx_free_data_id_us_cb(), blender::ed::object::single_obdata_users(), blender::ed::object::single_object_users_collection(), blender::bke::node_interface::socket_types::socket_data_id_user_decrement(), blender::bke::node_interface::socket_types::socket_data_id_user_decrement(), blender::bke::node_interface::socket_types::socket_data_id_user_decrement(), blender::bke::node_interface::socket_types::socket_data_id_user_decrement(), blender::bke::node_interface::socket_types::socket_data_id_user_decrement(), blender::bke::socket_id_user_decrement(), solve_camera_freejob(), template_id_cb(), blender::animrig::nla::unassign_action(), blender::ed::outliner::unlink_material_fn(), blender::ed::outliner::unlink_texture_fn(), blender::ed::outliner::unlink_world_fn(), MeshImporter::write_geometry(), and DocumentImporter::writeMaterial().

◆ id_us_plus()

void id_us_plus ( ID * id)

Definition at line 351 of file lib_id.cc.

References id_lib_extern(), and id_us_plus_no_lib().

Referenced by blender::io::usd::USDGeomReader::add_cache_modifier(), blender::ed::space_node::add_node_group_asset(), blender::io::alembic::AbcObjectReader::addCacheModifier(), animdata_set_action(), blender::ed::object::apply_objects_internal(), blender::animrig::nla::assign_action(), BKE_animdata_copy_in_lib(), BKE_animdata_merge_copy(), BKE_camera_background_image_copy(), BKE_collection_object_replace(), BKE_gpencil_brush_material_set(), BKE_id_material_append(), BKE_id_material_assign(), BKE_id_materials_copy(), BKE_image_load_exists_in_lib(), BKE_lib_override_library_copy(), BKE_lib_override_library_init(), BKE_library_update_ID_link_user(), BKE_light_linking_collection_assign_only(), BKE_linestyle_alpha_modifier_copy(), BKE_linestyle_color_modifier_copy(), BKE_linestyle_thickness_modifier_copy(), BKE_mesh_assign_object(), BKE_movieclip_file_add_exists_ex(), BKE_nla_tweakmode_enter(), BKE_nlastrip_copy(), BKE_object_add_for_data(), BKE_object_copy_particlesystem(), BKE_object_material_from_eval_data(), BKE_paint_copy(), BKE_paint_palette_set(), 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(), blender::nodes::decl::IDSocketDeclaration::build(), collection_child_add(), blender::ed::object::collection_drop_exec(), blender::ed::object::collection_instance_add_exec(), blender::ed::outliner::collection_instance_exec(), collection_object_add(), con_fix_copied_refs_cb(), copy_lineset(), blender::bke::create_auto_smooth_modifier(), MeshImporter::create_mesh_object(), blender::ed::greasepencil::undo::StepDrawingReference::decode(), blender::ed::object::drop_geometry_nodes_invoke(), drop_world_exec(), ED_mesh_join_objects_exec(), ED_rigidbody_constraint_add(), foreach_assign_id_to_orig_callback(), foreach_libblock_make_usercounts_callback(), FRS_paste_active_lineset(), Freestyle::BlenderStrokeRenderer::GenerateStrokeMesh(), blender::animrig::generic_assign_action(), id_copy_libmanagement_cb(), id_fake_user_set(), IDP_AssignID(), IDP_CopyID(), IDP_New(), blender::nodes::node_composite_movieclip_cc::init(), blender::nodes::node_composite_moviedistortion_cc::init(), blender::nodes::node_composite_planetrackdeform_cc::init(), blender::nodes::node_composite_stabilize2d_cc::init(), blender::nodes::node_composite_trackpos_cc::init(), blender::nodes::node_composite_switchview_cc::init_switch_view(), blender::bke::greasepencil::convert::legacy_gpencil_object(), libblock_management_us_plus(), loose_data_instantiate_collection_process(), loose_data_instantiate_obdata_process(), blender::ed::object::make_links_data_exec(), blender::ed::object::make_local_all__instance_indirect_unused(), mesh_separate_material_assign_mat_nr(), blender::ed::object::modifier_add_asset_exec(), modifier_copy_data_id_us_cb(), blender::ed::space_node::node_add_collection_exec(), blender::ed::space_node::node_add_group_exec(), blender::ed::space_node::node_add_mask_exec(), blender::ed::space_node::node_add_material_exec(), blender::ed::space_node::node_add_object_exec(), blender::nodes::node_composite_keyingscreen_cc::node_composit_init_keyingscreen(), blender::nodes::node_composite_render_layer_cc::node_composit_init_rlayers(), blender::bke::node_copy_with_mapping(), blender::ed::space_node::node_duplicate_exec(), blender::ed::space_node::node_id_remap(), blender::bke::node_init(), blender::nodes::node_composite_cryptomatte_cc::node_init_api_cryptomatte(), blender::ed::space_node::node_link_item_apply(), node_socket_copy_default_value_data(), object_add_or_copy_particle_system(), blender::ed::object::object_convert_exec(), blender::ed::object::object_data_convert_curve_to_mesh(), blender::ed::object::object_grease_pencil_add_exec(), blender::ed::object::object_image_add_invoke(), object_material_assign(), blender::nodes::old_id_property_type_matches_socket_convert_to_new(), paste_material_nodetree_ids_relink_or_clear(), paste_mtex_copybuf(), blender::ed::space_node::NodeClipboard::paste_update_node_id_references(), blender::io::usd::USDXformReader::read_object_data(), blender::ed::outliner::restrictbutton_id_user_toggle(), blender::ed::space_node::search_link_ops_for_asset_metadata(), seq_dupli(), SEQ_effect_text_font_load(), set_current_brush_texture(), set_current_linestyle_texture(), set_current_particle_texture(), blender::io::usd::USDInstanceReader::set_instance_collection(), blender::io::alembic::AbcObjectReader::setupObjectTransform(), blender::ed::object::shade_auto_smooth_exec(), shaderfx_copy_data_id_us_cb(), blender::bke::node_interface::socket_types::socket_data_id_user_increment(), blender::bke::node_interface::socket_types::socket_data_id_user_increment(), blender::bke::node_interface::socket_types::socket_data_id_user_increment(), blender::bke::node_interface::socket_types::socket_data_id_user_increment(), blender::bke::node_interface::socket_types::socket_data_id_user_increment(), blender::bke::socket_id_user_increment(), solve_camera_freejob(), template_id_cb(), blender::animrig::tests::TEST_F(), tracking_plane_tracks_copy(), tracking_tracks_copy(), txt_add_object(), WM_drag_free_imported_drag_ID(), and WM_operator_drop_load_path().

◆ id_us_plus_no_lib()

void id_us_plus_no_lib ( ID * id)

◆ lib_id_clear_library_data_users_update_cb()

◆ lib_id_copy_ensure_local()

void lib_id_copy_ensure_local ( Main * bmain,
const ID * old_id,
ID * new_id,
const int flags )

Ensure new (copied) ID is fully made local.

Definition at line 480 of file lib_id.cc.

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

Referenced by BKE_id_copy_in_lib(), and lib_override_library_create_from().

◆ lib_id_expand_local_cb()

◆ lib_id_library_local_paths()

static void lib_id_library_local_paths ( Main * bmain,
Library * lib_to,
Library * lib_from,
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.

This function can be used to remap paths in both directions. Typically, an ID comes from a library and is made local (lib_to is then nullptr). But an ID can also be moved from current Main into a library (lib_from is thennullptr), or between two libraries (bothlib_toand lib_from` are provided then).

Parameters
lib_toThe library into which the id is moved to (used to get the destination root* path). If nullptr, the current Main::filepath is used.
lib_fromThe library from which the id is coming from (used to get the source root path). If nullptr, the current Main::filepath is used.

TODO: This can probably be replaced by an ID-level version of BKE_bpath_relative_rebase.

Definition at line 177 of file lib_id.cc.

References BKE_bpath_foreach_path_id(), BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE, BKE_main_blendfile_path(), BLI_assert, BPathForeachPathData::bmain, Library_Runtime::filepath_abs, lib_id_library_local_paths_callback(), and Library::runtime.

Referenced by BKE_id_copy_in_lib(), BKE_lib_id_clear_library_data(), and lib_id_copy_ensure_local().

◆ lib_id_library_local_paths_callback()

static bool lib_id_library_local_paths_callback ( BPathForeachPathData * bpath_data,
char * path_dst,
size_t path_dst_maxncpy,
const char * path_src )
static

Rewrites a relative path to be relative to the main file - unless the path is absolute, in which case it is not altered.

Definition at line 127 of file lib_id.cc.

References BLI_path_abs(), BLI_path_is_rel(), BLI_path_normalize(), BLI_path_rel(), BLI_strncpy(), CLOG_ERROR, FILE_MAX, FILE_MAXDIR, FILE_MAXFILE, LOG, and BPathForeachPathData::user_data.

Referenced by lib_id_library_local_paths().

◆ libblock_management_us_min()

◆ libblock_management_us_plus()

◆ library_make_local_copying_check()

Variable Documentation

◆ global_session_uid

uint global_session_uid = 0
static

Definition at line 1443 of file lib_id.cc.

Referenced by BKE_lib_libblock_session_uid_ensure().

◆ IDType_ID_LINK_PLACEHOLDER

IDTypeInfo IDType_ID_LINK_PLACEHOLDER
Initial value:
= {
0,
0,
sizeof(ID),
"LinkPlaceholder",
N_("link_placeholders"),
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
}
@ IDTYPE_FLAGS_NO_COPY
Definition BKE_idtype.hh:30
@ IDTYPE_FLAGS_NO_LIBLINKING
Definition BKE_idtype.hh:32
#define BLT_I18NCONTEXT_ID_ID
struct ID ID
@ INDEX_ID_NULL
Definition DNA_ID.h:1325
#define ID_LINK_PLACEHOLDER
#define N_(msgid)

Empty shell mostly, but needed for read code.

Definition at line 87 of file lib_id.cc.

Referenced by id_type_init().

◆ LOG

CLG_LogRef LOG = {"bke.lib_id"}
static

Definition at line 85 of file lib_id.cc.

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