diff options
Diffstat (limited to 'source/blender/blenkernel/intern/lattice.c')
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 68 |
1 files changed, 30 insertions, 38 deletions
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 58c0a567116..67f49266efc 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -59,6 +59,8 @@ #include "BKE_key.h" #include "BKE_lattice.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_modifier.h" #include "BKE_object.h" @@ -275,15 +277,17 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name) return lt; } -Lattice *BKE_lattice_copy(Lattice *lt) +Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt) { Lattice *ltn; - ltn = BKE_libblock_copy(<->id); + ltn = BKE_libblock_copy(bmain, <->id); ltn->def = MEM_dupallocN(lt->def); - ltn->key = BKE_key_copy(ltn->key); - if (ltn->key) ltn->key->from = (ID *)ltn; + if (lt->key) { + ltn->key = BKE_key_copy(bmain, ltn->key); + ltn->key->from = (ID *)ltn; + } if (lt->dvert) { int tot = lt->pntsu * lt->pntsv * lt->pntsw; @@ -293,8 +297,9 @@ Lattice *BKE_lattice_copy(Lattice *lt) ltn->editlatt = NULL; - if (lt->id.lib) { - BKE_id_lib_local_paths(G.main, lt->id.lib, <n->id); + if (ID_IS_LINKED_DATABLOCK(lt)) { + BKE_id_expand_local(<n->id); + BKE_id_lib_local_paths(bmain, lt->id.lib, <n->id); } return ltn; @@ -325,48 +330,35 @@ void BKE_lattice_free(Lattice *lt) } -void BKE_lattice_make_local(Lattice *lt) +void BKE_lattice_make_local(Main *bmain, Lattice *lt) { - Main *bmain = G.main; - Object *ob; bool is_local = false, is_lib = false; /* - only lib users: do nothing * - only local users: set flag * - mixed: make copy */ - - if (lt->id.lib == NULL) return; - if (lt->id.us == 1) { - id_clear_lib_data(bmain, <->id); + + if (!ID_IS_LINKED_DATABLOCK(lt)) { return; } - - for (ob = bmain->object.first; ob && ELEM(false, is_lib, is_local); ob = ob->id.next) { - if (ob->data == lt) { - if (ob->id.lib) is_lib = true; - else is_local = true; - } - } - - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, <->id); - } - else if (is_local && is_lib) { - Lattice *lt_new = BKE_lattice_copy(lt); - lt_new->id.us = 0; - - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, lt->id.lib, <_new->id); - - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->data == lt) { - if (ob->id.lib == NULL) { - ob->data = lt_new; - id_us_plus(<_new->id); - id_us_min(<->id); - } + + BKE_library_ID_test_usages(bmain, lt, &is_local, &is_lib); + + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, <->id); + if (lt->key) { + BKE_key_make_local(bmain, lt->key); } + BKE_id_expand_local(<->id); + } + else { + Lattice *lt_new = BKE_lattice_copy(bmain, lt); + + lt_new->id.us = 0; + + BKE_libblock_remap(bmain, lt, lt_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } |