Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2016-07-10 17:15:03 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2016-07-10 18:14:45 +0300
commit8932b5945ee05e61feeb4e5891a5ce4a786dd645 (patch)
treede49fea092e092dd3595de1a9974e72a39b3c2bb /source/blender
parent0f0eeffeceafdb47b4cdb2975865d4306d0d94b4 (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')
-rw-r--r--source/blender/blenkernel/BKE_camera.h2
-rw-r--r--source/blender/blenkernel/BKE_lamp.h2
-rw-r--r--source/blender/blenkernel/intern/camera.c47
-rw-r--r--source/blender/blenkernel/intern/lamp.c71
-rw-r--r--source/blender/blenkernel/intern/library.c4
5 files changed, 56 insertions, 70 deletions
diff --git a/source/blender/blenkernel/BKE_camera.h b/source/blender/blenkernel/BKE_camera.h
index f78df88c77a..97f4b30894b 100644
--- a/source/blender/blenkernel/BKE_camera.h
+++ b/source/blender/blenkernel/BKE_camera.h
@@ -53,7 +53,7 @@ struct GPUFXSettings;
void BKE_camera_init(struct Camera *cam);
void *BKE_camera_add(struct Main *bmain, const char *name);
struct Camera *BKE_camera_copy(struct Main *bmain, struct Camera *cam);
-void BKE_camera_make_local(struct Camera *cam);
+void BKE_camera_make_local(struct Main *bmain, struct Camera *cam);
void BKE_camera_free(struct Camera *ca);
/* Camera Usage */
diff --git a/source/blender/blenkernel/BKE_lamp.h b/source/blender/blenkernel/BKE_lamp.h
index 3bdef8eca48..49b43550e67 100644
--- a/source/blender/blenkernel/BKE_lamp.h
+++ b/source/blender/blenkernel/BKE_lamp.h
@@ -46,7 +46,7 @@ void BKE_lamp_init(struct Lamp *la);
struct Lamp *BKE_lamp_add(struct Main *bmain, const char *name) ATTR_WARN_UNUSED_RESULT;
struct Lamp *BKE_lamp_copy(struct Main *bmain, struct Lamp *la) ATTR_WARN_UNUSED_RESULT;
struct Lamp *localize_lamp(struct Lamp *la) ATTR_WARN_UNUSED_RESULT;
-void BKE_lamp_make_local(struct Lamp *la);
+void BKE_lamp_make_local(struct Main *bmain, struct Lamp *la);
void BKE_lamp_free(struct Lamp *la);
void lamp_drivers_update(struct Scene *scene, struct Lamp *la, float ctime);
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);