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-09 16:38:02 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2016-07-09 16:44:12 +0300
commit429394078bde004f608e0f9ba9937421ab35edfd (patch)
tree2c409fe417cd75efb25944fb32c8936c605f87e1 /source/blender/blenkernel/intern/lattice.c
parent338121e2a0d4471574f243aa36cbf93fdf495ca2 (diff)
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).
Diffstat (limited to 'source/blender/blenkernel/intern/lattice.c')
-rw-r--r--source/blender/blenkernel/intern/lattice.c69
1 files changed, 30 insertions, 39 deletions
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 9bf417c6120..3e03690a1a6 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(&lt->id);
+ ltn = BKE_libblock_copy_ex(bmain, &lt->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, &ltn->id);
+ BKE_id_lib_local_paths(bmain, lt->id.lib, &ltn->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, &lt->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, &lt->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, &lt_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(&lt_new->id);
- id_us_min(&lt->id);
- }
+ if (is_local) {
+ if (!is_lib) {
+ id_clear_lib_data(bmain, &lt->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, &lt_new->id);
+
+ BKE_libblock_remap(bmain, lt, lt_new, ID_REMAP_SKIP_INDIRECT_USAGE);
}
}
}