Cleanup: Rename BKE_libblock_relink, and move it to BKE_library_remap.h
Was a waaaaayyyyy to much generic name for such a specific func, renamed to much more descriptive BKE_libblock_relink_to_newid(). In near future (few weeks, to limit as much as possible silent mismatch in branches), will rename BKE_libblock_relink_ex to BKE_libblock_relink, this is the real generic data-block relinking func!
This commit is contained in:
@@ -56,7 +56,6 @@ void BKE_libblock_init_empty(struct ID *id);
|
||||
void *BKE_libblock_copy(struct Main *bmain, struct ID *id) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
||||
void *BKE_libblock_copy_nolib(struct ID *id, const bool do_action) ATTR_NONNULL();
|
||||
void BKE_libblock_copy_data(struct ID *id, const struct ID *id_from, const bool do_action);
|
||||
void BKE_libblock_relink(struct ID *id);
|
||||
void BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL();
|
||||
void BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL();
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ void BKE_libblock_relink_ex(
|
||||
struct Main *bmain, void *idv, void *old_idv, void *new_idv,
|
||||
const bool us_min_never_null) ATTR_NONNULL(1, 2);
|
||||
|
||||
void BKE_libblock_relink_to_newid(struct ID *id) ATTR_NONNULL();
|
||||
|
||||
typedef void (*BKE_library_free_window_manager_cb)(struct bContext *, struct wmWindowManager *);
|
||||
typedef void (*BKE_library_free_notifier_reference_cb)(const void *);
|
||||
|
||||
@@ -1173,31 +1173,6 @@ void *BKE_libblock_copy_nolib(ID *id, const bool do_action)
|
||||
return idn;
|
||||
}
|
||||
|
||||
static int id_relink_looper(void *UNUSED(user_data), ID *UNUSED(self_id), ID **id_pointer, const int cd_flag)
|
||||
{
|
||||
ID *id = *id_pointer;
|
||||
if (id) {
|
||||
/* See: NEW_ID macro */
|
||||
if (id->newid) {
|
||||
BKE_library_update_ID_link_user(id->newid, id, cd_flag);
|
||||
*id_pointer = id->newid;
|
||||
}
|
||||
else if (id->tag & LIB_TAG_NEW) {
|
||||
id->tag &= ~LIB_TAG_NEW;
|
||||
BKE_libblock_relink(id);
|
||||
}
|
||||
}
|
||||
return IDWALK_RET_NOP;
|
||||
}
|
||||
|
||||
void BKE_libblock_relink(ID *id)
|
||||
{
|
||||
if (ID_IS_LINKED_DATABLOCK(id))
|
||||
return;
|
||||
|
||||
BKE_library_foreach_ID_link(id, id_relink_looper, NULL, 0);
|
||||
}
|
||||
|
||||
void BKE_library_free(Library *lib)
|
||||
{
|
||||
if (lib->packedfile)
|
||||
|
||||
@@ -680,6 +680,35 @@ void BKE_libblock_relink_ex(
|
||||
}
|
||||
}
|
||||
|
||||
static int id_relink_to_newid_looper(void *UNUSED(user_data), ID *UNUSED(self_id), ID **id_pointer, const int cd_flag)
|
||||
{
|
||||
ID *id = *id_pointer;
|
||||
if (id) {
|
||||
/* See: NEW_ID macro */
|
||||
if (id->newid) {
|
||||
BKE_library_update_ID_link_user(id->newid, id, cd_flag);
|
||||
*id_pointer = id->newid;
|
||||
}
|
||||
else if (id->tag & LIB_TAG_NEW) {
|
||||
id->tag &= ~LIB_TAG_NEW;
|
||||
BKE_libblock_relink_to_newid(id);
|
||||
}
|
||||
}
|
||||
return IDWALK_RET_NOP;
|
||||
}
|
||||
|
||||
/** Similar to libblock_relink_ex, but is remapping IDs to their newid value if non-NULL, in given \a id.
|
||||
*
|
||||
* Very specific usage, not sure we'll keep it on the long run, currently only used in Object duplication code...
|
||||
*/
|
||||
void BKE_libblock_relink_to_newid(ID *id)
|
||||
{
|
||||
if (ID_IS_LINKED_DATABLOCK(id))
|
||||
return;
|
||||
|
||||
BKE_library_foreach_ID_link(id, id_relink_to_newid_looper, NULL, 0);
|
||||
}
|
||||
|
||||
void BKE_libblock_free_data(Main *UNUSED(bmain), ID *id)
|
||||
{
|
||||
if (id->properties) {
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_library_query.h"
|
||||
#include "BKE_library_remap.h"
|
||||
#include "BKE_key.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_material.h"
|
||||
@@ -1241,7 +1242,7 @@ static void copy_object_set_idnew(bContext *C)
|
||||
|
||||
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
|
||||
{
|
||||
BKE_libblock_relink(&ob->id);
|
||||
BKE_libblock_relink_to_newid(&ob->id);
|
||||
}
|
||||
CTX_DATA_END;
|
||||
|
||||
@@ -1395,7 +1396,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
|
||||
}
|
||||
|
||||
/* Remap new object to itself, and clear again newid pointer of orig object. */
|
||||
BKE_libblock_relink(&ob->id);
|
||||
BKE_libblock_relink_to_newid(&ob->id);
|
||||
set_sca_new_poins_ob(ob);
|
||||
BKE_id_clear_newpoin(&dob->ob->id);
|
||||
|
||||
@@ -2219,7 +2220,7 @@ Base *ED_object_add_duplicate(Main *bmain, Scene *scene, Base *base, int dupflag
|
||||
ob = basen->object;
|
||||
|
||||
/* link own references to the newly duplicated data [#26816] */
|
||||
BKE_libblock_relink(&ob->id);
|
||||
BKE_libblock_relink_to_newid(&ob->id);
|
||||
set_sca_new_poins_ob(ob);
|
||||
|
||||
/* DAG_relations_tag_update(bmain); */ /* caller must do */
|
||||
|
||||
@@ -76,6 +76,7 @@
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_library_query.h"
|
||||
#include "BKE_library_remap.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_mball.h"
|
||||
@@ -1806,7 +1807,7 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in
|
||||
|
||||
/* object and group pointers */
|
||||
for (base = FIRSTBASE; base; base = base->next) {
|
||||
BKE_libblock_relink(&base->object->id);
|
||||
BKE_libblock_relink_to_newid(&base->object->id);
|
||||
}
|
||||
|
||||
set_sca_new_poins();
|
||||
|
||||
Reference in New Issue
Block a user