diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-10 17:15:03 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2016-07-10 18:14:45 +0300 |
commit | 8932b5945ee05e61feeb4e5891a5ce4a786dd645 (patch) | |
tree | de49fea092e092dd3595de1a9974e72a39b3c2bb /source/blender/blenkernel/intern/lamp.c | |
parent | 0f0eeffeceafdb47b4cdb2975865d4306d0d94b4 (diff) |
Refactor/enhance BKE_lamp_make_local() and BKE_camera_make_local().
Now using modern features from libquery/libremap areas.
Provides same kind of fixes/improvements as for BKE_object_make_local() (see rBd1a4ae3f395a6).
Diffstat (limited to 'source/blender/blenkernel/intern/lamp.c')
-rw-r--r-- | source/blender/blenkernel/intern/lamp.c | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c index 7ab71938cf2..36ba5dbb09b 100644 --- a/source/blender/blenkernel/intern/lamp.c +++ b/source/blender/blenkernel/intern/lamp.c @@ -50,6 +50,8 @@ #include "BKE_global.h" #include "BKE_lamp.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_node.h" @@ -170,10 +172,23 @@ Lamp *localize_lamp(Lamp *la) return lan; } -void BKE_lamp_make_local(Lamp *la) +static int extern_local_lamp_callback( + void *UNUSED(user_data), struct ID *UNUSED(id_self), struct ID **id_pointer, int cd_flag) +{ + /* We only tag usercounted ID usages as extern... Why? */ + if ((cd_flag & IDWALK_USER) && *id_pointer) { + id_lib_extern(*id_pointer); + } + return IDWALK_RET_NOP; +} + +static void extern_local_lamp(Lamp *la) +{ + BKE_library_foreach_ID_link(&la->id, extern_local_lamp_callback, NULL, 0); +} + +void BKE_lamp_make_local(Main *bmain, Lamp *la) { - Main *bmain = G.main; - Object *ob; bool is_local = false, is_lib = false; /* - only lib users: do nothing @@ -181,42 +196,26 @@ void BKE_lamp_make_local(Lamp *la) * - mixed: make copy */ - if (!ID_IS_LINKED_DATABLOCK(la)) return; - if (la->id.us == 1) { - id_clear_lib_data(bmain, &la->id); + if (!ID_IS_LINKED_DATABLOCK(la)) { return; } - - ob = bmain->object.first; - while (ob) { - if (ob->data == la) { - if (ID_IS_LINKED_DATABLOCK(ob)) is_lib = true; - else is_local = true; + + BKE_library_ID_test_usages(bmain, la, &is_local, &is_lib); + + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, &la->id); + extern_local_lamp(la); } - ob = ob->id.next; - } - - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, &la->id); - } - else if (is_local && is_lib) { - Lamp *la_new = BKE_lamp_copy(bmain, la); - la_new->id.us = 0; - - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, la->id.lib, &la_new->id); - - ob = bmain->object.first; - while (ob) { - if (ob->data == la) { - - if (!ID_IS_LINKED_DATABLOCK(ob)) { - ob->data = la_new; - id_us_plus(&la_new->id); - id_us_min(&la->id); - } - } - ob = ob->id.next; + else { + Lamp *la_new = BKE_lamp_copy(bmain, la); + + la_new->id.us = 0; + + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, la->id.lib, &la_new->id); + + BKE_libblock_remap(bmain, la, la_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } |