IDmanagement: makelocal: Fix mistake in recent commit.
rB8cc3d2d6f51f introduced option to force make_local code to either copy or actually make a linked ID local, but logic of boolean options handling was broken. This commit simplifies logic here and fixes the issue. NOTE: Since those new options were not used yet this was a harmless bug.
This commit is contained in:
@@ -148,8 +148,8 @@ static void brush_make_local(Main *bmain, ID *id, const int flags)
|
||||
|
||||
Brush *brush = (Brush *)id;
|
||||
const bool lib_local = (flags & LIB_ID_MAKELOCAL_FULL_LIBRARY) != 0;
|
||||
const bool force_local = (flags & LIB_ID_MAKELOCAL_FORCE_LOCAL) != 0;
|
||||
const bool force_copy = (flags & LIB_ID_MAKELOCAL_FORCE_COPY) != 0;
|
||||
bool force_local = (flags & LIB_ID_MAKELOCAL_FORCE_LOCAL) != 0;
|
||||
bool force_copy = (flags & LIB_ID_MAKELOCAL_FORCE_COPY) != 0;
|
||||
BLI_assert(force_copy == false || force_copy != force_local);
|
||||
|
||||
bool is_local = false, is_lib = false;
|
||||
@@ -166,27 +166,33 @@ static void brush_make_local(Main *bmain, ID *id, const int flags)
|
||||
|
||||
if (!force_local && !force_copy) {
|
||||
BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib);
|
||||
if (lib_local || is_local) {
|
||||
if (!is_lib) {
|
||||
force_local = true;
|
||||
}
|
||||
else {
|
||||
force_copy = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lib_local || is_local || force_copy || force_local) {
|
||||
if (!is_lib || force_local) {
|
||||
BKE_lib_id_clear_library_data(bmain, &brush->id);
|
||||
BKE_lib_id_expand_local(bmain, &brush->id);
|
||||
if (force_local) {
|
||||
BKE_lib_id_clear_library_data(bmain, &brush->id);
|
||||
BKE_lib_id_expand_local(bmain, &brush->id);
|
||||
|
||||
/* enable fake user by default */
|
||||
id_fake_user_set(&brush->id);
|
||||
}
|
||||
else {
|
||||
Brush *brush_new = (Brush *)BKE_id_copy(bmain, &brush->id); /* Ensures FAKE_USER is set */
|
||||
/* enable fake user by default */
|
||||
id_fake_user_set(&brush->id);
|
||||
}
|
||||
else if (force_copy) {
|
||||
Brush *brush_new = (Brush *)BKE_id_copy(bmain, &brush->id); /* Ensures FAKE_USER is set */
|
||||
|
||||
brush_new->id.us = 0;
|
||||
brush_new->id.us = 0;
|
||||
|
||||
/* setting newid is mandatory for complex make_lib_local logic... */
|
||||
ID_NEW_SET(brush, brush_new);
|
||||
/* setting newid is mandatory for complex make_lib_local logic... */
|
||||
ID_NEW_SET(brush, brush_new);
|
||||
|
||||
if (!lib_local) {
|
||||
BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
||||
}
|
||||
if (!lib_local) {
|
||||
BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -411,8 +411,8 @@ void BKE_lib_id_make_local_generic(Main *bmain, ID *id, const int flags)
|
||||
}
|
||||
|
||||
const bool lib_local = (flags & LIB_ID_MAKELOCAL_FULL_LIBRARY) != 0;
|
||||
const bool force_local = (flags & LIB_ID_MAKELOCAL_FORCE_LOCAL) != 0;
|
||||
const bool force_copy = (flags & LIB_ID_MAKELOCAL_FORCE_COPY) != 0;
|
||||
bool force_local = (flags & LIB_ID_MAKELOCAL_FORCE_LOCAL) != 0;
|
||||
bool force_copy = (flags & LIB_ID_MAKELOCAL_FORCE_COPY) != 0;
|
||||
BLI_assert(force_copy == false || force_copy != force_local);
|
||||
|
||||
bool is_local = false, is_lib = false;
|
||||
@@ -426,42 +426,48 @@ void BKE_lib_id_make_local_generic(Main *bmain, ID *id, const int flags)
|
||||
|
||||
if (!force_copy && !force_local) {
|
||||
BKE_library_ID_test_usages(bmain, id, &is_local, &is_lib);
|
||||
if (lib_local || is_local) {
|
||||
if (!is_lib) {
|
||||
force_local = true;
|
||||
}
|
||||
else {
|
||||
force_copy = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lib_local || is_local || force_copy || force_local) {
|
||||
if (!is_lib || force_local) {
|
||||
BKE_lib_id_clear_library_data(bmain, id);
|
||||
BKE_lib_id_expand_local(bmain, id);
|
||||
}
|
||||
else {
|
||||
ID *id_new = BKE_id_copy(bmain, id);
|
||||
if (force_local) {
|
||||
BKE_lib_id_clear_library_data(bmain, id);
|
||||
BKE_lib_id_expand_local(bmain, id);
|
||||
}
|
||||
else if (force_copy) {
|
||||
ID *id_new = BKE_id_copy(bmain, id);
|
||||
|
||||
/* Should not fail in expected use cases,
|
||||
* but a few ID types cannot be copied (LIB, WM, SCR...). */
|
||||
if (id_new != NULL) {
|
||||
id_new->us = 0;
|
||||
/* Should not fail in expected use cases,
|
||||
* but a few ID types cannot be copied (LIB, WM, SCR...). */
|
||||
if (id_new != NULL) {
|
||||
id_new->us = 0;
|
||||
|
||||
/* setting newid is mandatory for complex make_lib_local logic... */
|
||||
ID_NEW_SET(id, id_new);
|
||||
Key *key = BKE_key_from_id(id), *key_new = BKE_key_from_id(id);
|
||||
if (key && key_new) {
|
||||
ID_NEW_SET(key, key_new);
|
||||
}
|
||||
bNodeTree *ntree = ntreeFromID(id), *ntree_new = ntreeFromID(id_new);
|
||||
if (ntree && ntree_new) {
|
||||
ID_NEW_SET(ntree, ntree_new);
|
||||
}
|
||||
if (GS(id->name) == ID_SCE) {
|
||||
Collection *master_collection = ((Scene *)id)->master_collection,
|
||||
*master_collection_new = ((Scene *)id_new)->master_collection;
|
||||
if (master_collection && master_collection_new) {
|
||||
ID_NEW_SET(master_collection, master_collection_new);
|
||||
}
|
||||
/* setting newid is mandatory for complex make_lib_local logic... */
|
||||
ID_NEW_SET(id, id_new);
|
||||
Key *key = BKE_key_from_id(id), *key_new = BKE_key_from_id(id);
|
||||
if (key && key_new) {
|
||||
ID_NEW_SET(key, key_new);
|
||||
}
|
||||
bNodeTree *ntree = ntreeFromID(id), *ntree_new = ntreeFromID(id_new);
|
||||
if (ntree && ntree_new) {
|
||||
ID_NEW_SET(ntree, ntree_new);
|
||||
}
|
||||
if (GS(id->name) == ID_SCE) {
|
||||
Collection *master_collection = ((Scene *)id)->master_collection,
|
||||
*master_collection_new = ((Scene *)id_new)->master_collection;
|
||||
if (master_collection && master_collection_new) {
|
||||
ID_NEW_SET(master_collection, master_collection_new);
|
||||
}
|
||||
}
|
||||
|
||||
if (!lib_local) {
|
||||
BKE_libblock_remap(bmain, id, id_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
||||
}
|
||||
if (!lib_local) {
|
||||
BKE_libblock_remap(bmain, id, id_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,8 +331,8 @@ static void object_make_local(Main *bmain, ID *id, const int flags)
|
||||
Object *ob = (Object *)id;
|
||||
const bool lib_local = (flags & LIB_ID_MAKELOCAL_FULL_LIBRARY) != 0;
|
||||
const bool clear_proxy = (flags & LIB_ID_MAKELOCAL_OBJECT_NO_PROXY_CLEARING) == 0;
|
||||
const bool force_local = (flags & LIB_ID_MAKELOCAL_FORCE_LOCAL) != 0;
|
||||
const bool force_copy = (flags & LIB_ID_MAKELOCAL_FORCE_COPY) != 0;
|
||||
bool force_local = (flags & LIB_ID_MAKELOCAL_FORCE_LOCAL) != 0;
|
||||
bool force_copy = (flags & LIB_ID_MAKELOCAL_FORCE_COPY) != 0;
|
||||
BLI_assert(force_copy == false || force_copy != force_local);
|
||||
|
||||
bool is_local = false, is_lib = false;
|
||||
@@ -346,32 +346,38 @@ static void object_make_local(Main *bmain, ID *id, const int flags)
|
||||
|
||||
if (!force_local && !force_copy) {
|
||||
BKE_library_ID_test_usages(bmain, ob, &is_local, &is_lib);
|
||||
}
|
||||
|
||||
if (lib_local || is_local || force_copy || force_local) {
|
||||
if (!is_lib || force_local) {
|
||||
BKE_lib_id_clear_library_data(bmain, &ob->id);
|
||||
BKE_lib_id_expand_local(bmain, &ob->id);
|
||||
if (clear_proxy) {
|
||||
if (ob->proxy_from != NULL) {
|
||||
ob->proxy_from->proxy = NULL;
|
||||
ob->proxy_from->proxy_group = NULL;
|
||||
}
|
||||
ob->proxy = ob->proxy_from = ob->proxy_group = NULL;
|
||||
if (lib_local || is_local) {
|
||||
if (!is_lib) {
|
||||
force_local = true;
|
||||
}
|
||||
else {
|
||||
force_copy = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
Object *ob_new = (Object *)BKE_id_copy(bmain, &ob->id);
|
||||
id_us_min(&ob_new->id);
|
||||
}
|
||||
|
||||
ob_new->proxy = ob_new->proxy_from = ob_new->proxy_group = NULL;
|
||||
|
||||
/* setting newid is mandatory for complex make_lib_local logic... */
|
||||
ID_NEW_SET(ob, ob_new);
|
||||
|
||||
if (!lib_local) {
|
||||
BKE_libblock_remap(bmain, ob, ob_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
||||
if (force_local) {
|
||||
BKE_lib_id_clear_library_data(bmain, &ob->id);
|
||||
BKE_lib_id_expand_local(bmain, &ob->id);
|
||||
if (clear_proxy) {
|
||||
if (ob->proxy_from != NULL) {
|
||||
ob->proxy_from->proxy = NULL;
|
||||
ob->proxy_from->proxy_group = NULL;
|
||||
}
|
||||
ob->proxy = ob->proxy_from = ob->proxy_group = NULL;
|
||||
}
|
||||
}
|
||||
else if (force_copy) {
|
||||
Object *ob_new = (Object *)BKE_id_copy(bmain, &ob->id);
|
||||
id_us_min(&ob_new->id);
|
||||
|
||||
ob_new->proxy = ob_new->proxy_from = ob_new->proxy_group = NULL;
|
||||
|
||||
/* setting newid is mandatory for complex make_lib_local logic... */
|
||||
ID_NEW_SET(ob, ob_new);
|
||||
|
||||
if (!lib_local) {
|
||||
BKE_libblock_remap(bmain, ob, ob_new, ID_REMAP_SKIP_INDIRECT_USAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user