1
1

ID management: add options to force make local or force copy IDs when making them local.

This is to be used when calling code already knows whether the 'made
local' linked ID should be copied, or can directly be converted to a
local one.

Currently unused , this is preparation for rewrite of append code.
This commit is contained in:
2021-09-06 17:37:04 +02:00
parent d7d8eb7de4
commit 8cc3d2d6f5
4 changed files with 42 additions and 19 deletions

View File

@@ -237,6 +237,11 @@ enum {
/** Making that ID local is part of making local a whole library. */
LIB_ID_MAKELOCAL_FULL_LIBRARY = 1 << 0,
/** In case caller code already knows this ID should be made local without copying. */
LIB_ID_MAKELOCAL_FORCE_LOCAL = 1 << 1,
/** In case caller code already knows this ID should be made local using copying. */
LIB_ID_MAKELOCAL_FORCE_COPY = 1 << 2,
/* Special type-specific options. */
/** For Objects, do not clear the proxy pointers while making the data-block local. */
LIB_ID_MAKELOCAL_OBJECT_NO_PROXY_CLEARING = 1 << 16,

View File

@@ -142,8 +142,16 @@ static void brush_free_data(ID *id)
static void brush_make_local(Main *bmain, ID *id, const int flags)
{
if (!ID_IS_LINKED(id)) {
return;
}
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;
BLI_assert(force_copy == false || force_copy != force_local);
bool is_local = false, is_lib = false;
/* - only lib users: do nothing (unless force_local is set)
@@ -151,19 +159,17 @@ static void brush_make_local(Main *bmain, ID *id, const int flags)
* - mixed: make copy
*/
if (!ID_IS_LINKED(brush)) {
return;
}
if (brush->clone.image) {
/* Special case: ima always local immediately. Clone image should only have one user anyway. */
BKE_lib_id_make_local(bmain, &brush->clone.image->id, false, 0);
}
BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib);
if (!force_local && !force_copy) {
BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib);
}
if (lib_local || is_local) {
if (!is_lib) {
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);

View File

@@ -406,7 +406,15 @@ static void lib_id_copy_ensure_local(Main *bmain, const ID *old_id, ID *new_id)
*/
void BKE_lib_id_make_local_generic(Main *bmain, ID *id, const int flags)
{
if (!ID_IS_LINKED(id)) {
return;
}
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;
BLI_assert(force_copy == false || force_copy != force_local);
bool is_local = false, is_lib = false;
/* - only lib users: do nothing (unless force_local is set)
@@ -416,14 +424,12 @@ void BKE_lib_id_make_local_generic(Main *bmain, ID *id, const int flags)
* we always want to localize, and we skip remapping (done later).
*/
if (!ID_IS_LINKED(id)) {
return;
if (!force_copy && !force_local) {
BKE_library_ID_test_usages(bmain, id, &is_local, &is_lib);
}
BKE_library_ID_test_usages(bmain, id, &is_local, &is_lib);
if (lib_local || is_local) {
if (!is_lib) {
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);
}

View File

@@ -324,9 +324,17 @@ static void object_free_data(ID *id)
static void object_make_local(Main *bmain, ID *id, const int flags)
{
if (!ID_IS_LINKED(id)) {
return;
}
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;
BLI_assert(force_copy == false || force_copy != force_local);
bool is_local = false, is_lib = false;
/* - only lib users: do nothing (unless force_local is set)
@@ -336,14 +344,12 @@ static void object_make_local(Main *bmain, ID *id, const int flags)
* we always want to localize, and we skip remapping (done later).
*/
if (!ID_IS_LINKED(ob)) {
return;
if (!force_local && !force_copy) {
BKE_library_ID_test_usages(bmain, ob, &is_local, &is_lib);
}
BKE_library_ID_test_usages(bmain, ob, &is_local, &is_lib);
if (lib_local || is_local) {
if (!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) {