[Bf-blender-cvs] [4293940] master: Refactor/enhance BKE_lattice_make_local(), and add BKE_lattice_copy_ex() that takes a Main as parameter.
Bastien Montagne
noreply at git.blender.org
Sat Jul 9 15:44:56 CEST 2016
Commit: 429394078bde004f608e0f9ba9937421ab35edfd
Author: Bastien Montagne
Date: Sat Jul 9 15:38:02 2016 +0200
Branches: master
https://developer.blender.org/rB429394078bde004f608e0f9ba9937421ab35edfd
Refactor/enhance BKE_lattice_make_local(), and add BKE_lattice_copy_ex() that takes a Main as parameter.
Now using modern features from libquery/libremap areas.
Provides same kind of fixes/improvements as for BKE_object_make_local() (see rBd1a4ae3f395a6).
===================================================================
M source/blender/blenkernel/BKE_lattice.h
M source/blender/blenkernel/intern/lattice.c
M source/blender/blenkernel/intern/library.c
M source/blender/editors/object/object_add.c
M source/blender/editors/object/object_relations.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h
index 828a40d..a825252 100644
--- a/source/blender/blenkernel/BKE_lattice.h
+++ b/source/blender/blenkernel/BKE_lattice.h
@@ -48,8 +48,9 @@ void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object *
void BKE_lattice_init(struct Lattice *lt);
struct Lattice *BKE_lattice_add(struct Main *bmain, const char *name);
struct Lattice *BKE_lattice_copy(struct Lattice *lt);
+struct Lattice *BKE_lattice_copy_ex(struct Main *bmain, struct Lattice *lt);
void BKE_lattice_free(struct Lattice *lt);
-void BKE_lattice_make_local(struct Lattice *lt);
+void BKE_lattice_make_local(struct Main *bmain, struct Lattice *lt);
void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du);
struct LatticeDeformData;
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 9bf417c..3e03690 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,11 +277,11 @@ Lattice *BKE_lattice_add(Main *bmain, const char *name)
return lt;
}
-Lattice *BKE_lattice_copy(Lattice *lt)
+Lattice *BKE_lattice_copy_ex(Main *bmain, Lattice *lt)
{
Lattice *ltn;
- ltn = BKE_libblock_copy(<->id);
+ ltn = BKE_libblock_copy_ex(bmain, <->id);
ltn->def = MEM_dupallocN(lt->def);
if (lt->key) {
@@ -296,12 +298,17 @@ Lattice *BKE_lattice_copy(Lattice *lt)
ltn->editlatt = NULL;
if (ID_IS_LINKED_DATABLOCK(lt)) {
- BKE_id_lib_local_paths(G.main, lt->id.lib, <n->id);
+ BKE_id_lib_local_paths(bmain, lt->id.lib, <n->id);
}
return ltn;
}
+Lattice *BKE_lattice_copy(Lattice *lt)
+{
+ return BKE_lattice_copy_ex(G.main, lt);
+}
+
/** Free (or release) any data used by this lattice (does not free the lattice itself). */
void BKE_lattice_free(Lattice *lt)
{
@@ -327,54 +334,38 @@ 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 (!ID_IS_LINKED_DATABLOCK(lt)) return;
- if (lt->id.us == 1) {
- id_clear_lib_data(bmain, <->id);
- if (lt->key) {
- BKE_key_make_local(bmain, lt->key);
- }
+
+ 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 (ID_IS_LINKED_DATABLOCK(ob)) is_lib = true;
- else is_local = true;
- }
- }
-
- if (is_local && is_lib == false) {
- id_clear_lib_data(bmain, <->id);
- if (lt->key) {
- BKE_key_make_local(bmain, lt->key);
- }
- }
- 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);
+ BKE_library_ID_test_usages(bmain, lt, &is_local, &is_lib);
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- if (ob->data == lt) {
- if (!ID_IS_LINKED_DATABLOCK(ob)) {
- ob->data = lt_new;
- id_us_plus(<_new->id);
- id_us_min(<->id);
- }
+ if (is_local) {
+ if (!is_lib) {
+ id_clear_lib_data(bmain, <->id);
+ if (lt->key) {
+ BKE_key_make_local(bmain, lt->key);
}
+ /* No extern_local_lattice... */
+ }
+ else {
+ Lattice *lt_new = BKE_lattice_copy_ex(bmain, 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);
+
+ BKE_libblock_remap(bmain, lt, lt_new, ID_REMAP_SKIP_INDIRECT_USAGE);
}
}
}
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 80bd1e9..fa63e7a 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -285,7 +285,7 @@ bool id_make_local(Main *bmain, ID *id, bool test)
if (!test) BKE_image_make_local((Image *)id);
return true;
case ID_LT:
- if (!test) BKE_lattice_make_local((Lattice *)id);
+ if (!test) BKE_lattice_make_local(bmain, (Lattice *)id);
return true;
case ID_LA:
if (!test) BKE_lamp_make_local((Lamp *)id);
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index aac9dcf..2ea3920 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -2050,7 +2050,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
if (dupflag != 0) {
ID_NEW_US2(obn->data)
else {
- obn->data = BKE_lattice_copy(obn->data);
+ obn->data = BKE_lattice_copy_ex(bmain, obn->data);
didit = 1;
}
id_us_min(id);
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 2e9db53..bf2dc55 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -1893,7 +1893,7 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
BKE_animdata_copy_id_action((ID *)cu->key);
break;
case OB_LATTICE:
- ob->data = lat = BKE_lattice_copy(ob->data);
+ ob->data = lat = BKE_lattice_copy_ex(bmain, ob->data);
if (lat->key)
BKE_animdata_copy_id_action((ID *)lat->key);
break;
More information about the Bf-blender-cvs
mailing list