Blender  V2.93
Classes | Typedefs | Enumerations | Functions | Variables
lib_remap.c File Reference
#include "CLG_log.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
 

Typedefs

typedef struct IDRemap IDRemap
 

Enumerations

enum  { ID_REMAP_IS_LINKED_DIRECT = 1 << 0 , ID_REMAP_IS_USER_ONE_SKIPPED = 1 << 1 }
 

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 int foreach_libblock_remap_callback (LibraryIDLinkCallbackData *cb_data)
 
static void libblock_remap_data_preprocess (IDRemap *r_id_remap_data)
 
static void libblock_remap_data_postprocess_object_update (Main *bmain, Object *old_ob, Object *new_ob)
 
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 (Main *bmain, ID *id, ID *old_id, ID *new_id, const short remap_flags, IDRemap *r_id_remap_data)
 
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_unlink (Main *bmain, void *idv, const bool do_flag_never_null, const bool do_skip_indirect)
 
void BKE_libblock_relink_ex (Main *bmain, void *idv, void *old_idv, void *new_idv, const short remap_flags)
 
static int id_relink_to_newid_looper (LibraryIDLinkCallbackData *cb_data)
 
void BKE_libblock_relink_to_newid (ID *id)
 

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

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ID_REMAP_IS_LINKED_DIRECT 
ID_REMAP_IS_USER_ONE_SKIPPED 

Definition at line 88 of file lib_remap.c.

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 
)

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.
us_min_never_nullIf true and new_id is NULL, 'NEVER_NULL' ID usages keep their old id, but this one still gets its user count decremented (needed when given idv is going to be deleted right after being unlinked).

Definition at line 605 of file lib_remap.c.

References BLI_assert, DEG_relations_tag_update(), GS, id, ID_GR, ID_OB, ID_SCE, libblock_remap_data(), libblock_remap_data_postprocess_collection_update(), libblock_remap_data_postprocess_obdata_relink(), libblock_remap_data_postprocess_object_update(), ID::name, and NULL.

◆ BKE_libblock_relink_to_newid()

void BKE_libblock_relink_to_newid ( ID id)

Similar to #libblock_relink_ex, but is remapping IDs to their newid value if non-NULL, in given id.

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

Definition at line 702 of file lib_remap.c.

References BKE_library_foreach_ID_link(), ID_IS_LINKED, id_relink_to_newid_looper(), and NULL.

Referenced by BKE_collection_duplicate(), BKE_object_duplicate(), BKE_scene_duplicate(), copy_object_set_idnew(), ED_object_add_duplicate(), id_relink_to_newid_looper(), 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 557 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_unlink()

void BKE_libblock_unlink ( Main bmain,
void *  idv,
const bool  do_flag_never_null,
const 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 573 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 54 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 61 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

◆ id_relink_to_newid_looper()

static int id_relink_to_newid_looper ( LibraryIDLinkCallbackData cb_data)
static

◆ libblock_remap_data()

static void libblock_remap_data ( Main bmain,
ID id,
ID old_id,
ID new_id,
const short  remap_flags,
IDRemap r_id_remap_data 
)
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 (uselful to retrieve info about remapping process).

Definition at line 373 of file lib_remap.c.

References BKE_library_foreach_ID_link(), BKE_library_id_can_use_idtype(), IDRemap::bmain, foreach_libblock_remap_callback(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, GS, id, id_fake_user_clear(), id_fake_user_set(), ID_REMAP_FORCE_INTERNAL_RUNTIME_POINTERS, ID_REMAP_IS_LINKED_DIRECT, ID_REMAP_NO_INDIRECT_PROXY_DATA_USAGE, ID_REMAP_SKIP_USER_CLEAR, id_us_clear_real(), IDWALK_DO_INTERNAL_RUNTIME_POINTERS, IDWALK_NO_INDIRECT_PROXY_DATA_USAGE, IDWALK_NOP, ID::lib, LIB_FAKEUSER, LIB_INDIRECT_WEAK_LINK, LIB_TAG_EXTERN, LIB_TAG_INDIRECT, libblock_remap_data_preprocess(), ID::name, and NULL.

Referenced by BKE_libblock_relink_ex(), and BKE_libblock_remap_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 344 of file lib_remap.c.

References ntreeUpdateAllUsers().

Referenced by BKE_libblock_remap_locked().

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

Can be called with both old_ob and new_ob being NULL, this means we have to check whole Main database then.

Definition at line 273 of file lib_remap.c.

References BKE_collections_object_remove_nulls(), BKE_main_collection_sync_remap(), BKE_mball_is_basis(), BKE_mball_is_basis_for(), DEG_id_tag_update(), ListBase::first, ID_RECALC_GEOMETRY, NULL, OB_MBALL, and Main::objects.

Referenced by BKE_libblock_relink_ex(), and BKE_libblock_remap_locked().

◆ libblock_remap_data_preprocess()

static void libblock_remap_data_preprocess ( IDRemap r_id_remap_data)
static

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

Referenced by BKE_libblock_remap_locked().

◆ remap_editor_id_reference_cb

BKE_library_remap_editor_id_reference_cb remap_editor_id_reference_cb = NULL