Blender  V3.3
Classes | Typedefs | Functions | Variables
lib_remap.c File Reference
#include "CLG_log.h"
#include "BLI_linklist.h"
#include "BLI_utildefines.h"
#include "DNA_collection_types.h"
#include "DNA_object_types.h"
#include "BKE_armature.h"
#include "BKE_collection.h"
#include "BKE_curve.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_lib_remap.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mball.h"
#include "BKE_modifier.h"
#include "BKE_multires.h"
#include "BKE_node.h"
#include "BKE_object.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "lib_intern.h"

Go to the source code of this file.

Classes

struct  IDRemap
 
struct  LibblockRemapMultipleUserData
 
struct  LibblockRelinkMultipleUserData
 
struct  RelinkToNewIDData
 

Typedefs

typedef struct IDRemap IDRemap
 
typedef struct LibblockRemapMultipleUserData LibBlockRemapMultipleUserData
 
typedef struct LibblockRelinkMultipleUserData LibBlockRelinkMultipleUserData
 
typedef struct RelinkToNewIDData 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 *UNUSED(id_owner), ID **id_ptr, const int cb_flag, const bool is_indirect, const bool is_reference, const bool violates_never_null, const bool UNUSED(is_obj), 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 struct IDRemapper *mappings, const IDRemapperApplyOptions id_remapper_options, const int cb_flag, const bool is_indirect, const bool violates_never_null, const bool force_user_refcount)
 
static int foreach_libblock_remap_callback (LibraryIDLinkCallbackData *cb_data)
 
static void libblock_remap_data_preprocess_ob (Object *ob, eIDRemapType remap_type, const struct IDRemapper *id_remapper)
 
static void libblock_remap_data_preprocess (ID *id_owner, eIDRemapType remap_type, const struct IDRemapper *id_remapper)
 
static void libblock_remap_data_postprocess_object_update (Main *bmain, Object *old_ob, Object *new_ob, const bool do_sync_collection)
 
static void libblock_remap_data_postprocess_collection_update (Main *bmain, Collection *owner_collection, Collection *UNUSED(old_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, void *user_data)
 
static void libblock_remap_reset_remapping_status_callback (ID *old_id, ID *new_id, void *UNUSED(user_data))
 
static void libblock_remap_data (Main *bmain, ID *id, eIDRemapType remap_type, struct IDRemapper *id_remapper, const short remap_flags)
 
static void libblock_remap_foreach_idpair_cb (ID *old_id, ID *new_id, void *user_data)
 
void BKE_libblock_remap_multiple_locked (Main *bmain, struct IDRemapper *mappings, const short remap_flags)
 
void BKE_libblock_remap_locked (Main *bmain, void *old_idv, void *new_idv, const short remap_flags)
 
void BKE_libblock_remap (Main *bmain, void *old_idv, void *new_idv, const short remap_flags)
 
void BKE_libblock_remap_multiple (Main *bmain, struct IDRemapper *mappings, const short remap_flags)
 
void BKE_libblock_unlink (Main *bmain, void *idv, const bool do_flag_never_null, const bool do_skip_indirect)
 
static void libblock_relink_foreach_idpair_cb (ID *old_id, ID *new_id, void *user_data)
 
void BKE_libblock_relink_multiple (Main *bmain, LinkNode *ids, const eIDRemapType remap_type, struct IDRemapper *id_remapper, const short remap_flags)
 
void BKE_libblock_relink_ex (Main *bmain, void *idv, void *old_idv, void *new_idv, const short 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 = {.identifier = "bke.lib_remap"}
 
BKE_library_free_notifier_reference_cb free_notifier_reference_cb = NULL
 
BKE_library_remap_editor_id_reference_cb remap_editor_id_reference_cb = NULL
 

Detailed Description

Contains management of ID's for remapping.

Definition in file lib_remap.c.

Typedef Documentation

◆ IDRemap

typedef struct IDRemap IDRemap

◆ LibBlockRelinkMultipleUserData

◆ LibBlockRemapMultipleUserData

◆ RelinkToNewIDData

Function Documentation

◆ BKE_libblock_relink_ex()

void BKE_libblock_relink_ex ( Main bmain,
void idv,
void old_idv,
void new_idv,
const short  remap_flags 
)

◆ BKE_libblock_relink_multiple()

void BKE_libblock_relink_multiple ( struct Main bmain,
struct LinkNode ids,
eIDRemapType  remap_type,
struct IDRemapper *  id_remapper,
short  remap_flags 
)

◆ BKE_libblock_relink_to_newid()

void BKE_libblock_relink_to_newid ( struct Main bmain,
struct 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 LIB_TAG_NEW.

Note
LIB_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 894 of file lib_remap.c.

References BKE_id_remapper_create(), BKE_id_remapper_free(), BKE_libblock_relink_multiple(), BLI_assert, BLI_linklist_free(), ID_IS_LINKED, ID_REMAP_SKIP_INDIRECT_USAGE, ID_REMAP_SKIP_OVERRIDE_LIBRARY, ID_REMAP_TYPE_REMAP, RelinkToNewIDData::id_remapper, RelinkToNewIDData::ids, libblock_relink_to_newid_prepare_data(), NULL, and Main::relations.

Referenced by BKE_blendfile_append(), BKE_collection_duplicate(), BKE_object_duplicate(), BKE_scene_duplicate(), copy_object_set_idnew(), ED_object_add_duplicate(), libblock_relink_collection(), make_object_duplilist_real(), and single_object_users().

◆ BKE_libblock_remap()

void BKE_libblock_remap ( Main bmain,
void old_idv,
void new_idv,
const short  remap_flags 
)

Definition at line 652 of file lib_remap.c.

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 short  remap_flags 
)

◆ BKE_libblock_remap_multiple()

void BKE_libblock_remap_multiple ( Main bmain,
struct IDRemapper *  mappings,
const short  remap_flags 
)

◆ BKE_libblock_remap_multiple_locked()

void BKE_libblock_remap_multiple_locked ( struct Main bmain,
struct IDRemapper *  mappings,
short  remap_flags 
)

Replace all references in given Main using the given mappings

Note
Is preferred over BKE_libblock_remap_locked due to performance.

Definition at line 614 of file lib_remap.c.

References BKE_id_remapper_is_empty(), BKE_id_remapper_iter(), DEG_relations_tag_update(), ID_REMAP_TYPE_REMAP, libblock_remap_data(), libblock_remap_foreach_idpair_cb(), NULL, remap_editor_id_reference_cb, and user_data.

Referenced by BKE_libblock_remap_locked(), BKE_libblock_remap_multiple(), and id_delete().

◆ BKE_libblock_unlink()

void BKE_libblock_unlink ( struct Main bmain,
void idv,
bool  do_flag_never_null,
bool  do_skip_indirect 
)

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

Parameters
do_flag_never_nullIf true, all IDs using idv in a 'non-NULL' way are flagged by LIB_TAG_DOIT flag (quite obviously, 'non-NULL' usages can never be unlinked by this function).

Definition at line 670 of file lib_remap.c.

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

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 41 of file lib_remap.c.

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 48 of file lib_remap.c.

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

static void foreach_libblock_remap_callback_apply ( ID id_owner,
ID id_self,
ID **  id_ptr,
IDRemap id_remap_data,
const struct IDRemapper *  mappings,
const IDRemapperApplyOptions  id_remapper_options,
const int  cb_flag,
const bool  is_indirect,
const bool  violates_never_null,
const bool  force_user_refcount 
)
static

◆ foreach_libblock_remap_callback_skip()

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

◆ id_relink_to_newid_looper()

static int id_relink_to_newid_looper ( LibraryIDLinkCallbackData cb_data)
static

◆ libblock_relink_foreach_idpair_cb()

static void libblock_relink_foreach_idpair_cb ( ID old_id,
ID new_id,
void user_data 
)
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,
struct IDRemapper *  id_remapper,
const short  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 NULL or not:

  • id NULL: old_id must be non-NULL, new_id may be NULL (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-NULL:
    • If old_id is NULL, new_id must also be NULL, and all ID pointers from id are cleared (i.e. id does not references any other data-block anymore).
    • If old_id is non-NULL, behavior is as with a NULL id, but only within given id.
Parameters
bmainthe Main data storage to operate on (must never be NULL).
idthe data-block to operate on (can be NULL, in which case we operate over all IDs from given bmain).
old_idthe data-block to dereference (may be NULL if id is non-NULL).
new_idthe new data-block to replace old_id references with (may be NULL).
r_id_remap_dataif non-NULL, the IDRemap struct to use (useful to retrieve info about remapping process).

Definition at line 463 of file lib_remap.c.

References BKE_id_remapper_has_mapping_for(), BKE_id_remapper_iter(), BKE_library_foreach_ID_link(), BKE_library_id_can_use_filter_id(), IDRemap::bmain, IDRemap::flag, foreach_libblock_remap_callback(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, id, IDRemap::id_owner, ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS, IDRemap::id_remapper, IDWALK_DO_INTERNAL_RUNTIME_POINTERS, IDWALK_NOP, ID::lib, libblock_remap_data_preprocess(), libblock_remap_data_update_tags(), libblock_remap_reset_remapping_status_callback(), ID::name, NULL, and IDRemap::type.

Referenced by BKE_libblock_relink_multiple(), and BKE_libblock_remap_multiple_locked().

◆ libblock_remap_data_postprocess_collection_update()

static void libblock_remap_data_postprocess_collection_update ( Main bmain,
Collection owner_collection,
Collection UNUSEDold_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 400 of file lib_remap.c.

References ntreeUpdateAllUsers().

Referenced by libblock_remap_foreach_idpair_cb().

◆ 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 new_ob,
const bool  do_sync_collection 
)
static

◆ libblock_remap_data_preprocess()

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

Definition at line 301 of file lib_remap.c.

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

Referenced by libblock_remap_data().

◆ libblock_remap_data_preprocess_ob()

static void libblock_remap_data_preprocess_ob ( Object ob,
eIDRemapType  remap_type,
const struct IDRemapper *  id_remapper 
)
static

◆ libblock_remap_data_update_tags()

static void libblock_remap_data_update_tags ( ID old_id,
ID new_id,
void user_data 
)
static

◆ libblock_remap_foreach_idpair_cb()

static void libblock_remap_foreach_idpair_cb ( ID old_id,
ID new_id,
void user_data 
)
static

◆ libblock_remap_reset_remapping_status_callback()

static void libblock_remap_reset_remapping_status_callback ( ID old_id,
ID new_id,
void UNUSEDuser_data 
)
static

Definition at line 430 of file lib_remap.c.

References BKE_libblock_runtime_reset_remapping_status(), and NULL.

Referenced by libblock_remap_data().

Variable Documentation

◆ free_notifier_reference_cb

BKE_library_free_notifier_reference_cb free_notifier_reference_cb = NULL

◆ LOG

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

Definition at line 37 of file lib_remap.c.

Referenced by libblock_remap_foreach_idpair_cb().

◆ remap_editor_id_reference_cb

BKE_library_remap_editor_id_reference_cb remap_editor_id_reference_cb = NULL