Blender V4.3
lib_remap.cc File Reference
#include "CLG_log.h"
#include "BLI_array.hh"
#include "BLI_linklist.h"
#include "BLI_utildefines.h"
#include "DNA_collection_types.h"
#include "DNA_object_types.h"
#include "BKE_armature.hh"
#include "BKE_collection.hh"
#include "BKE_curve.hh"
#include "BKE_layer.hh"
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_lib_remap.hh"
#include "BKE_main.hh"
#include "BKE_material.h"
#include "BKE_mball.hh"
#include "BKE_modifier.hh"
#include "BKE_multires.hh"
#include "BKE_node.hh"
#include "BKE_node_tree_update.hh"
#include "BKE_object.hh"
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_build.hh"
#include "lib_intern.hh"

Go to the source code of this file.

Classes

struct  IDRemap
 
struct  RelinkToNewIDData
 

Functions

void BKE_library_callback_free_notifier_reference_set (BKE_library_free_notifier_reference_cb func)
 
void BKE_library_callback_remap_editor_id_reference_set (BKE_library_remap_editor_id_reference_cb func)
 
static void foreach_libblock_remap_callback_skip (const ID *, ID **id_ptr, const int cb_flag, const bool is_indirect, const bool is_reference, const bool violates_never_null, const bool, const bool is_obj_editmode)
 
static void foreach_libblock_remap_callback_apply (ID *id_owner, ID *id_self, ID **id_ptr, IDRemap *id_remap_data, const IDRemapper &mappings, const IDRemapperApplyOptions id_remapper_options, const int cb_flag, const bool is_indirect, const bool violates_never_null)
 
static int foreach_libblock_remap_callback (LibraryIDLinkCallbackData *cb_data)
 
static void libblock_remap_data_preprocess_ob (Object *ob, eIDRemapType remap_type, const IDRemapper &id_remapper)
 
static void libblock_remap_data_preprocess (ID *id_owner, eIDRemapType remap_type, const IDRemapper &id_remapper)
 
static void libblock_remap_data_postprocess_object_update (Main *bmain, Object *old_ob, Object *, const bool do_sync_collection)
 
static void libblock_remap_data_postprocess_collection_update (Main *bmain, Collection *owner_collection, Collection *, Collection *new_collection)
 
static void libblock_remap_data_postprocess_obdata_relink (Main *bmain, Object *ob, ID *new_id)
 
static void libblock_remap_data_postprocess_nodetree_update (Main *bmain, ID *new_id)
 
static void libblock_remap_data_update_tags (ID *old_id, ID *new_id, IDRemap *id_remap_data)
 
static void libblock_remap_reset_remapping_status_fn (ID *old_id, ID *new_id)
 
static void libblock_remap_data (Main *bmain, ID *id, eIDRemapType remap_type, IDRemapper &id_remapper, const int remap_flags)
 
static void libblock_remap_foreach_idpair (ID *old_id, ID *new_id, Main *bmain, int remap_flags)
 
void BKE_libblock_remap_multiple_locked (Main *bmain, IDRemapper &mappings, const int remap_flags)
 
void BKE_libblock_remap_multiple_raw (Main *bmain, IDRemapper &mappings, const int remap_flags)
 
void BKE_libblock_remap_locked (Main *bmain, void *old_idv, void *new_idv, const int remap_flags)
 
void BKE_libblock_remap (Main *bmain, void *old_idv, void *new_idv, const int remap_flags)
 
void BKE_libblock_remap_multiple (Main *bmain, IDRemapper &mappings, const int remap_flags)
 
void BKE_libblock_unlink (Main *bmain, void *idv, const bool do_skip_indirect)
 
static void libblock_relink_foreach_idpair (ID *old_id, ID *new_id, Main *bmain, const blender::Span< ID * > ids)
 
void BKE_libblock_relink_multiple (Main *bmain, const blender::Span< ID * > ids, const eIDRemapType remap_type, IDRemapper &id_remapper, const int remap_flags)
 
void BKE_libblock_relink_ex (Main *bmain, void *idv, void *old_idv, void *new_idv, const int remap_flags)
 
static void libblock_relink_to_newid_prepare_data (Main *bmain, ID *id, RelinkToNewIDData *relink_data)
 
static int id_relink_to_newid_looper (LibraryIDLinkCallbackData *cb_data)
 
void BKE_libblock_relink_to_newid (Main *bmain, ID *id, const int remap_flag)
 

Variables

static CLG_LogRef LOG = {"bke.lib_remap"}
 
BKE_library_free_notifier_reference_cb free_notifier_reference_cb = nullptr
 
BKE_library_remap_editor_id_reference_cb remap_editor_id_reference_cb = nullptr
 

Detailed Description

Contains management of ID's for remapping.

Definition in file lib_remap.cc.

Function Documentation

◆ BKE_libblock_relink_ex()

void BKE_libblock_relink_ex ( Main * bmain,
void * idv,
void * old_idv,
void * new_idv,
int remap_flags )

Similar to libblock_remap, but only affects IDs used by given idv ID.

Parameters
old_idvUnlike BKE_libblock_remap, can be NULL, in which case all ID usages by given idv will be cleared.
bmainMay be NULL, in which case there won't be depsgraph updates nor post-processing on some ID types (like collections or objects) to ensure their runtime data is valid.

Definition at line 844 of file lib_remap.cc.

References blender::bke::id::IDRemapper::add(), BKE_libblock_relink_multiple(), BLI_assert, GS, ID_REMAP_TYPE_CLEANUP, ID_REMAP_TYPE_REMAP, ID::name, and UNUSED_VARS_NDEBUG.

Referenced by BKE_lib_override_library_create_from_id(), id_free(), and scene_copy_data().

◆ BKE_libblock_relink_multiple()

◆ BKE_libblock_relink_to_newid()

void BKE_libblock_relink_to_newid ( Main * bmain,
ID * id,
int remap_flag )

Remaps ID usages of given ID to their id->newid pointer if not None, and proceeds recursively in the dependency tree of IDs for all data-blocks tagged with ID_TAG_NEW.

Note
ID_TAG_NEW is cleared.

Very specific usage, not sure we'll keep it on the long run, currently only used in Object/Collection duplication code.

Definition at line 921 of file lib_remap.cc.

References BKE_libblock_relink_multiple(), BLI_assert, ID_IS_LINKED, ID_REMAP_SKIP_INDIRECT_USAGE, ID_REMAP_SKIP_OVERRIDE_LIBRARY, ID_REMAP_TYPE_REMAP, libblock_relink_to_newid_prepare_data(), and Main::relations.

Referenced by blender::ed::object::add_duplicate(), BKE_blendfile_append(), BKE_collection_duplicate(), BKE_object_duplicate(), BKE_scene_duplicate(), blender::ed::object::copy_object_set_idnew(), blender::ed::object::libblock_relink_collection(), blender::ed::object::make_object_duplilist_real(), and blender::ed::object::single_object_users().

◆ BKE_libblock_remap()

void BKE_libblock_remap ( Main * bmain,
void * old_idv,
void * new_idv,
const int remap_flags )

Definition at line 692 of file lib_remap.cc.

References BKE_libblock_remap_locked(), BKE_main_lock(), and BKE_main_unlock().

◆ BKE_libblock_remap_locked()

void BKE_libblock_remap_locked ( Main * bmain,
void * old_idv,
void * new_idv,
const int remap_flags )

◆ BKE_libblock_remap_multiple()

void BKE_libblock_remap_multiple ( Main * bmain,
IDRemapper & mappings,
const int remap_flags )

◆ BKE_libblock_remap_multiple_locked()

void BKE_libblock_remap_multiple_locked ( Main * bmain,
blender::bke::id::IDRemapper & mappings,
const int remap_flags )

◆ BKE_libblock_remap_multiple_raw()

void BKE_libblock_remap_multiple_raw ( Main * bmain,
blender::bke::id::IDRemapper & mappings,
const int remap_flags )

Bare raw remapping of IDs, with no other processing than actually updating the ID pointers. No user-count, direct vs indirect linked status update, depsgraph tagging, etc.

This is way more efficient than regular remapping from BKE_libblock_remap_multiple & co, but it implies that calling code handles all the other aspects described above. This is typically the case e.g. in read-file process.

WARNING: This call will likely leave the given BMain in invalid state in many aspects.

Definition at line 669 of file lib_remap.cc.

References ID_REMAP_SKIP_UPDATE_TAGGING, ID_REMAP_SKIP_USER_REFCOUNT, ID_REMAP_TYPE_REMAP, blender::bke::id::IDRemapper::is_empty(), and libblock_remap_data().

Referenced by blender::bke::asset_main_create_from_ID(), and setup_app_data().

◆ BKE_libblock_unlink()

void BKE_libblock_unlink ( Main * bmain,
void * idv,
bool do_skip_indirect )

Unlink given id from given bmain (does not touch to indirect, i.e. library, usages of the ID).

Definition at line 710 of file lib_remap.cc.

References BKE_libblock_remap_locked(), BKE_main_lock(), BKE_main_unlock(), and ID_REMAP_SKIP_INDIRECT_USAGE.

Referenced by BKE_id_free_us().

◆ BKE_library_callback_free_notifier_reference_set()

void BKE_library_callback_free_notifier_reference_set ( BKE_library_free_notifier_reference_cb func)

Definition at line 47 of file lib_remap.cc.

References free_notifier_reference_cb.

Referenced by WM_init().

◆ BKE_library_callback_remap_editor_id_reference_set()

void BKE_library_callback_remap_editor_id_reference_set ( BKE_library_remap_editor_id_reference_cb func)

Definition at line 54 of file lib_remap.cc.

References remap_editor_id_reference_cb.

Referenced by WM_init().

◆ foreach_libblock_remap_callback()

static int foreach_libblock_remap_callback ( LibraryIDLinkCallbackData * cb_data)
static

◆ foreach_libblock_remap_callback_apply()

◆ foreach_libblock_remap_callback_skip()

static void foreach_libblock_remap_callback_skip ( const ID * ,
ID ** id_ptr,
const int cb_flag,
const bool is_indirect,
const bool is_reference,
const bool violates_never_null,
const bool ,
const bool is_obj_editmode )
static

◆ id_relink_to_newid_looper()

◆ libblock_relink_foreach_idpair()

static void libblock_relink_foreach_idpair ( ID * old_id,
ID * new_id,
Main * bmain,
const blender::Span< ID * > ids )
static

◆ libblock_relink_to_newid_prepare_data()

static void libblock_relink_to_newid_prepare_data ( Main * bmain,
ID * id,
RelinkToNewIDData * relink_data )
static

◆ libblock_remap_data()

static void libblock_remap_data ( Main * bmain,
ID * id,
eIDRemapType remap_type,
IDRemapper & id_remapper,
const int remap_flags )
static

Execute the 'data' part of the remapping (that is, all ID pointers from other ID data-blocks).

Behavior differs depending on whether given id is nullptr or not:

  • id nullptr: old_id must be non-nullptr, new_id may be nullptr (unlinking old_id) or not (remapping old_id to new_id). The whole bmain database is checked, and all pointers to old_id are remapped to new_id.
  • id is non-nullptr:
    • If old_id is nullptr, new_id must also be nullptr, and all ID pointers from id are cleared (i.e. id does not references any other data-block anymore).
    • If old_id is non-nullptr, behavior is as with a nullptr id, but only within given id.
Parameters
bmainthe Main data storage to operate on (may be nullptr, in which case part of the post-process/depsgraph update won't happen).
idthe data-block to operate on (can be nullptr, in which case we operate over all IDs from given bmain).
old_idthe data-block to dereference (may be nullptr if id is non-nullptr).
new_idthe new data-block to replace old_id references with (may be nullptr).
r_id_remap_dataif non-nullptr, the IDRemap struct to use (useful to retrieve info about remapping process).

Definition at line 487 of file lib_remap.cc.

References BKE_id_owner_get(), BKE_library_foreach_ID_link(), BKE_library_id_can_use_filter_id(), blender::bke::id::IDRemapper::contains_mappings_for_any(), foreach_libblock_remap_callback(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, ID_FLAG_EMBEDDED_DATA, IDRemap::id_owner, ID_REMAP_DO_LIBRARY_POINTERS, ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS, ID_REMAP_FORCE_UI_POINTERS, ID_REMAP_NO_ORIG_POINTERS_ACCESS, IDWALK_DO_INTERNAL_RUNTIME_POINTERS, IDWALK_DO_LIBRARY_POINTER, IDWALK_INCLUDE_UI, IDWALK_NO_ORIG_POINTERS_ACCESS, IDWALK_NOP, blender::bke::id::IDRemapper::iter(), libblock_remap_data_preprocess(), libblock_remap_data_update_tags(), libblock_remap_reset_remapping_status_fn(), and printf.

Referenced by BKE_libblock_relink_multiple(), BKE_libblock_remap_multiple_locked(), and BKE_libblock_remap_multiple_raw().

◆ libblock_remap_data_postprocess_collection_update()

static void libblock_remap_data_postprocess_collection_update ( Main * bmain,
Collection * owner_collection,
Collection * ,
Collection * new_collection )
static

◆ libblock_remap_data_postprocess_nodetree_update()

static void libblock_remap_data_postprocess_nodetree_update ( Main * bmain,
ID * new_id )
static

Definition at line 426 of file lib_remap.cc.

References blender::bke::node_tree_update_all_users().

Referenced by libblock_remap_foreach_idpair().

◆ libblock_remap_data_postprocess_obdata_relink()

static void libblock_remap_data_postprocess_obdata_relink ( Main * bmain,
Object * ob,
ID * new_id )
static

◆ libblock_remap_data_postprocess_object_update()

static void libblock_remap_data_postprocess_object_update ( Main * bmain,
Object * old_ob,
Object * ,
const bool do_sync_collection )
static

◆ libblock_remap_data_preprocess()

static void libblock_remap_data_preprocess ( ID * id_owner,
eIDRemapType remap_type,
const IDRemapper & id_remapper )
static

Definition at line 331 of file lib_remap.cc.

References GS, ID_OB, libblock_remap_data_preprocess_ob(), and ID::name.

Referenced by libblock_remap_data().

◆ libblock_remap_data_preprocess_ob()

◆ libblock_remap_data_update_tags()

static void libblock_remap_data_update_tags ( ID * old_id,
ID * new_id,
IDRemap * id_remap_data )
static

◆ libblock_remap_foreach_idpair()

◆ libblock_remap_reset_remapping_status_fn()

static void libblock_remap_reset_remapping_status_fn ( ID * old_id,
ID * new_id )
static

Definition at line 456 of file lib_remap.cc.

References BKE_libblock_runtime_reset_remapping_status().

Referenced by libblock_remap_data().

Variable Documentation

◆ free_notifier_reference_cb

◆ LOG

CLG_LogRef LOG = {"bke.lib_remap"}
static

Definition at line 43 of file lib_remap.cc.

Referenced by libblock_remap_foreach_idpair().

◆ remap_editor_id_reference_cb