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 | |
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')
-rw-r--r-- | source/blender/blenkernel/intern/camera.c | 47 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lamp.c | 71 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 4 |
3 files changed, 54 insertions, 68 deletions
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 41c67ef5365..8336c1fb3fb 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -49,6 +49,8 @@ #include "BKE_object.h" #include "BKE_global.h" #include "BKE_library.h" +#include "BKE_library_query.h" +#include "BKE_library_remap.h" #include "BKE_main.h" #include "BKE_scene.h" #include "BKE_screen.h" @@ -106,49 +108,34 @@ Camera *BKE_camera_copy(Main *bmain, Camera *cam) return camn; } -void BKE_camera_make_local(Camera *cam) +void BKE_camera_make_local(Main *bmain, Camera *cam) { - 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 (!ID_IS_LINKED_DATABLOCK(cam)) return; - if (cam->id.us == 1) { - id_clear_lib_data(bmain, &cam->id); + + if (!ID_IS_LINKED_DATABLOCK(cam)) { return; } - - for (ob = bmain->object.first; ob && ELEM(0, is_lib, is_local); ob = ob->id.next) { - if (ob->data == cam) { - if (ID_IS_LINKED_DATABLOCK(ob)) is_lib = true; - else is_local = true; + + BKE_library_ID_test_usages(bmain, cam, &is_local, &is_lib); + + if (is_local) { + if (!is_lib) { + id_clear_lib_data(bmain, &cam->id); } - } - - if (is_local && is_lib == false) { - id_clear_lib_data(bmain, &cam->id); - } - else if (is_local && is_lib) { - Camera *cam_new = BKE_camera_copy(bmain, cam); + else { + Camera *cam_new = BKE_camera_copy(bmain, cam); - cam_new->id.us = 0; + cam_new->id.us = 0; - /* Remap paths of new ID using old library as base. */ - BKE_id_lib_local_paths(bmain, cam->id.lib, &cam_new->id); + /* Remap paths of new ID using old library as base. */ + BKE_id_lib_local_paths(bmain, cam->id.lib, &cam_new->id); - for (ob = bmain->object.first; ob; ob = ob->id.next) { - if (ob->data == cam) { - if (!ID_IS_LINKED_DATABLOCK(ob)) { - ob->data = cam_new; - id_us_plus(&cam_new->id); - id_us_min(&cam->id); - } - } + BKE_libblock_remap(bmain, cam, cam_new, ID_REMAP_SKIP_INDIRECT_USAGE); } } } 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); } } } diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 06b977b290b..1304de95367 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -288,10 +288,10 @@ bool id_make_local(Main *bmain, ID *id, bool test) if (!test) BKE_lattice_make_local(bmain, (Lattice *)id); return true; case ID_LA: - if (!test) BKE_lamp_make_local((Lamp *)id); + if (!test) BKE_lamp_make_local(bmain, (Lamp *)id); return true; case ID_CA: - if (!test) BKE_camera_make_local((Camera *)id); + if (!test) BKE_camera_make_local(bmain, (Camera *)id); return true; case ID_SPK: if (!test) BKE_speaker_make_local(bmain, (Speaker *)id); |