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-20 20:49:45 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2016-07-21 17:54:36 +0300
commitd8d4bef6ccc3556a5691e5b633ebad895a795872 (patch)
tree2faf0473d311809060e6d2e7cfa9c813d1880100 /source/blender/blenkernel/intern
parent2977dcf2f7471e00079100803fd4203fcf97f20a (diff)
Refactor/deduplicate even more make_local code (and fix part of T48907).
Turns out most BKE_foo_make_local datablock-specific functions are actually doing exactly the same thing, only two currently need special additional operations (object and brush ones). So added a BKE_id_make_local_generic instead of copying same code over and over. Also, changed a bit how make_local works in case we are localizing a whole library. We need to do the 'remap' step (from old linked ID to new local one) in the second loop, otherwise we miss some dependencies. This fixes main part of T48907.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r--source/blender/blenkernel/intern/action.c29
-rw-r--r--source/blender/blenkernel/intern/armature.c29
-rw-r--r--source/blender/blenkernel/intern/brush.c8
-rw-r--r--source/blender/blenkernel/intern/camera.c29
-rw-r--r--source/blender/blenkernel/intern/curve.c29
-rw-r--r--source/blender/blenkernel/intern/image.c29
-rw-r--r--source/blender/blenkernel/intern/lamp.c29
-rw-r--r--source/blender/blenkernel/intern/lattice.c29
-rw-r--r--source/blender/blenkernel/intern/library.c113
-rw-r--r--source/blender/blenkernel/intern/material.c29
-rw-r--r--source/blender/blenkernel/intern/mball.c29
-rw-r--r--source/blender/blenkernel/intern/mesh.c29
-rw-r--r--source/blender/blenkernel/intern/node.c29
-rw-r--r--source/blender/blenkernel/intern/object.c9
-rw-r--r--source/blender/blenkernel/intern/particle.c29
-rw-r--r--source/blender/blenkernel/intern/speaker.c29
-rw-r--r--source/blender/blenkernel/intern/texture.c29
-rw-r--r--source/blender/blenkernel/intern/world.c29
18 files changed, 121 insertions, 444 deletions
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index fa49797126d..8f82610a8bb 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -95,34 +95,9 @@ bAction *add_empty_action(Main *bmain, const char name[])
/* .................................. */
// does copy_fcurve...
-void BKE_action_make_local(Main *bmain, bAction *act, const bool force_local)
+void BKE_action_make_local(Main *bmain, bAction *act, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(act)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, act, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &act->id);
- BKE_id_expand_local(&act->id);
- }
- else {
- bAction *act_new = BKE_action_copy(bmain, act);
-
- act_new->id.us = 0;
-
- BKE_libblock_remap(bmain, act, act_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &act->id, true, lib_local);
}
/* .................................. */
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 53e28177bdf..b618eb5561e 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -144,34 +144,9 @@ void BKE_armature_free(bArmature *arm)
}
}
-void BKE_armature_make_local(Main *bmain, bArmature *arm, const bool force_local)
+void BKE_armature_make_local(Main *bmain, bArmature *arm, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(arm)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, arm, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &arm->id);
- BKE_id_expand_local(&arm->id);
- }
- else {
- bArmature *arm_new = BKE_armature_copy(bmain, arm);
-
- arm_new->id.us = 0;
-
- BKE_libblock_remap(bmain, arm, arm_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &arm->id, true, lib_local);
}
static void copy_bonechildren(Bone *newBone, Bone *oldBone, Bone *actBone, Bone **newActBone)
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 3d9cabdc15d..9027287a457 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -219,7 +219,7 @@ void BKE_brush_free(Brush *brush)
BKE_previewimg_free(&(brush->preview));
}
-void BKE_brush_make_local(Main *bmain, Brush *brush, const bool force_local)
+void BKE_brush_make_local(Main *bmain, Brush *brush, const bool lib_local)
{
bool is_local = false, is_lib = false;
@@ -239,7 +239,7 @@ void BKE_brush_make_local(Main *bmain, Brush *brush, const bool force_local)
BKE_library_ID_test_usages(bmain, brush, &is_local, &is_lib);
- if (force_local || is_local) {
+ if (lib_local || is_local) {
if (!is_lib) {
id_clear_lib_data(bmain, &brush->id);
BKE_id_expand_local(&brush->id);
@@ -252,7 +252,9 @@ void BKE_brush_make_local(Main *bmain, Brush *brush, const bool force_local)
brush_new->id.us = 0;
- BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
+ if (!lib_local) {
+ BKE_libblock_remap(bmain, brush, brush_new, ID_REMAP_SKIP_INDIRECT_USAGE);
+ }
}
}
}
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index cd085816b4d..b7e6e409999 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -107,34 +107,9 @@ Camera *BKE_camera_copy(Main *bmain, Camera *cam)
return camn;
}
-void BKE_camera_make_local(Main *bmain, Camera *cam, const bool force_local)
+void BKE_camera_make_local(Main *bmain, Camera *cam, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(cam)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, cam, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &cam->id);
- BKE_id_expand_local(&cam->id);
- }
- else {
- Camera *cam_new = BKE_camera_copy(bmain, cam);
-
- cam_new->id.us = 0;
-
- BKE_libblock_remap(bmain, cam, cam_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &cam->id, true, lib_local);
}
/** Free (or release) any data used by this camera (does not free the camera itself). */
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 693e7eb0c80..07f4e4f1610 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -215,34 +215,9 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
return cun;
}
-void BKE_curve_make_local(Main *bmain, Curve *cu, const bool force_local)
+void BKE_curve_make_local(Main *bmain, Curve *cu, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - when there are only local users: set flag
- * - mixed: do a copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(cu)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, cu, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &cu->id);
- BKE_id_expand_local(&cu->id);
- }
- else {
- Curve *cu_new = BKE_curve_copy(bmain, cu);
-
- cu_new->id.us = 0;
-
- BKE_libblock_remap(bmain, cu, cu_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &cu->id, true, lib_local);
}
/* Get list of nurbs from editnurbs structure */
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 0032eb35d3a..44bea5c8138 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -469,34 +469,9 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
return nima;
}
-void BKE_image_make_local(Main *bmain, Image *ima, const bool force_local)
+void BKE_image_make_local(Main *bmain, Image *ima, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(ima)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, ima, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &ima->id);
- BKE_id_expand_local(&ima->id);
- }
- else {
- Image *ima_new = BKE_image_copy(bmain, ima);
-
- ima_new->id.us = 0;
-
- BKE_libblock_remap(bmain, ima, ima_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &ima->id, true, lib_local);
}
void BKE_image_merge(Image *dest, Image *source)
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 81bcdbde1dc..35fcf211b05 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -172,34 +172,9 @@ Lamp *localize_lamp(Lamp *la)
return lan;
}
-void BKE_lamp_make_local(Main *bmain, Lamp *la, const bool force_local)
+void BKE_lamp_make_local(Main *bmain, Lamp *la, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(la)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, la, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &la->id);
- BKE_id_expand_local(&la->id);
- }
- else {
- Lamp *la_new = BKE_lamp_copy(bmain, la);
-
- la_new->id.us = 0;
-
- BKE_libblock_remap(bmain, la, la_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &la->id, true, lib_local);
}
void BKE_lamp_free(Lamp *la)
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index c2675fabe3b..82b179d4f1c 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -330,34 +330,9 @@ void BKE_lattice_free(Lattice *lt)
}
-void BKE_lattice_make_local(Main *bmain, Lattice *lt, const bool force_local)
+void BKE_lattice_make_local(Main *bmain, Lattice *lt, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(lt)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, lt, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &lt->id);
- BKE_id_expand_local(&lt->id);
- }
- else {
- Lattice *lt_new = BKE_lattice_copy(bmain, lt);
-
- lt_new->id.us = 0;
-
- BKE_libblock_remap(bmain, lt, lt_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &lt->id, true, lib_local);
}
typedef struct LatticeDeformData {
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 2e066528f56..0ecc223de71 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -96,6 +96,7 @@
#include "BKE_lattice.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_library_remap.h"
#include "BKE_linestyle.h"
#include "BKE_mesh.h"
#include "BKE_material.h"
@@ -269,9 +270,54 @@ void BKE_id_expand_local(ID *id)
BKE_library_foreach_ID_link(id, id_expand_local_callback, NULL, 0);
}
-/* calls the appropriate make_local method for the block, unless test. Returns true
- * if the block can be made local. */
-bool id_make_local(Main *bmain, ID *id, const bool test, const bool force_local)
+/**
+ * Generic 'make local' function, works for most of datablock types...
+ */
+void BKE_id_make_local_generic(Main *bmain, ID *id, const bool id_in_mainlist, const bool lib_local)
+{
+ bool is_local = false, is_lib = false;
+
+ /* - only lib users: do nothing (unless force_local is set)
+ * - only local users: set flag
+ * - mixed: make copy
+ * In case we make a whole lib's content local, we always want to localize, and we skip remapping (done later).
+ */
+
+ if (!ID_IS_LINKED_DATABLOCK(id)) {
+ return;
+ }
+
+ BKE_library_ID_test_usages(bmain, id, &is_local, &is_lib);
+
+ if (lib_local || is_local) {
+ if (!is_lib) {
+ id_clear_lib_data_ex(bmain, id, id_in_mainlist);
+ BKE_id_expand_local(id);
+ }
+ else {
+ ID *id_new;
+
+ /* Should not fail in expected usecases, but id_copy does not copy Scene e.g. */
+ if (id_copy(bmain, id, &id_new, false)) {
+ id_new->us = 0;
+
+ if (!lib_local) {
+ BKE_libblock_remap(bmain, id, id_new, ID_REMAP_SKIP_INDIRECT_USAGE);
+ }
+ }
+ }
+ }
+
+}
+
+/**
+ * Calls the appropriate make_local method for the block, unless test is set.
+ *
+ * \param lib_local Special flag used when making a whole library's content local, it needs specific handling.
+ *
+ * \return true if the block can be made local.
+ */
+bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local)
{
if (id->tag & LIB_TAG_INDIRECT)
return false;
@@ -282,44 +328,44 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool force_local)
case ID_LI:
return false; /* can't be linked */
case ID_OB:
- if (!test) BKE_object_make_local(bmain, (Object *)id, force_local);
+ if (!test) BKE_object_make_local(bmain, (Object *)id, lib_local);
return true;
case ID_ME:
- if (!test) BKE_mesh_make_local(bmain, (Mesh *)id, force_local);
+ if (!test) BKE_mesh_make_local(bmain, (Mesh *)id, lib_local);
return true;
case ID_CU:
- if (!test) BKE_curve_make_local(bmain, (Curve *)id, force_local);
+ if (!test) BKE_curve_make_local(bmain, (Curve *)id, lib_local);
return true;
case ID_MB:
- if (!test) BKE_mball_make_local(bmain, (MetaBall *)id, force_local);
+ if (!test) BKE_mball_make_local(bmain, (MetaBall *)id, lib_local);
return true;
case ID_MA:
- if (!test) BKE_material_make_local(bmain, (Material *)id, force_local);
+ if (!test) BKE_material_make_local(bmain, (Material *)id, lib_local);
return true;
case ID_TE:
- if (!test) BKE_texture_make_local(bmain, (Tex *)id, force_local);
+ if (!test) BKE_texture_make_local(bmain, (Tex *)id, lib_local);
return true;
case ID_IM:
- if (!test) BKE_image_make_local(bmain, (Image *)id, force_local);
+ if (!test) BKE_image_make_local(bmain, (Image *)id, lib_local);
return true;
case ID_LT:
- if (!test) BKE_lattice_make_local(bmain, (Lattice *)id, force_local);
+ if (!test) BKE_lattice_make_local(bmain, (Lattice *)id, lib_local);
return true;
case ID_LA:
- if (!test) BKE_lamp_make_local(bmain, (Lamp *)id, force_local);
+ if (!test) BKE_lamp_make_local(bmain, (Lamp *)id, lib_local);
return true;
case ID_CA:
- if (!test) BKE_camera_make_local(bmain, (Camera *)id, force_local);
+ if (!test) BKE_camera_make_local(bmain, (Camera *)id, lib_local);
return true;
case ID_SPK:
- if (!test) BKE_speaker_make_local(bmain, (Speaker *)id, force_local);
+ if (!test) BKE_speaker_make_local(bmain, (Speaker *)id, lib_local);
return true;
case ID_IP:
return false; /* deprecated */
case ID_KE:
return false; /* can't be linked */
case ID_WO:
- if (!test) BKE_world_make_local(bmain, (World *)id, force_local);
+ if (!test) BKE_world_make_local(bmain, (World *)id, lib_local);
return true;
case ID_SCR:
return false; /* can't be linked */
@@ -332,19 +378,19 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool force_local)
case ID_GR:
return false; /* not implemented */
case ID_AR:
- if (!test) BKE_armature_make_local(bmain, (bArmature *)id, force_local);
+ if (!test) BKE_armature_make_local(bmain, (bArmature *)id, lib_local);
return true;
case ID_AC:
- if (!test) BKE_action_make_local(bmain, (bAction *)id, force_local);
+ if (!test) BKE_action_make_local(bmain, (bAction *)id, lib_local);
return true;
case ID_NT:
- if (!test) ntreeMakeLocal(bmain, (bNodeTree *)id, true, force_local);
+ if (!test) ntreeMakeLocal(bmain, (bNodeTree *)id, true, lib_local);
return true;
case ID_BR:
- if (!test) BKE_brush_make_local(bmain, (Brush *)id, force_local);
+ if (!test) BKE_brush_make_local(bmain, (Brush *)id, lib_local);
return true;
case ID_PA:
- if (!test) BKE_particlesettings_make_local(bmain, (ParticleSettings *)id, force_local);
+ if (!test) BKE_particlesettings_make_local(bmain, (ParticleSettings *)id, lib_local);
return true;
case ID_WM:
return false; /* can't be linked */
@@ -1467,7 +1513,7 @@ bool new_id(ListBase *lb, ID *id, const char *tname)
* Pull an ID out of a library (make it local). Only call this for IDs that
* don't have other library users.
*/
-void id_clear_lib_data_ex(Main *bmain, ID *id, bool id_in_mainlist)
+void id_clear_lib_data_ex(Main *bmain, ID *id, const bool id_in_mainlist)
{
bNodeTree *ntree = NULL;
Key *key = NULL;
@@ -1581,16 +1627,13 @@ static void lib_indirect_test_id(ID *id, const Library *lib)
void BKE_library_make_local(Main *bmain, const Library *lib, const bool untagged_only, const bool set_fake)
{
ListBase *lbarray[MAX_LIBARRAY];
- ID *id, *idn;
+ ID *id, *id_next;
int a;
- a = set_listbasepointers(bmain, lbarray);
- while (a--) {
- id = lbarray[a]->first;
-
- while (id) {
+ for (a = set_listbasepointers(bmain, lbarray); a--; ) {
+ for (id = lbarray[a]->first; id; id = id_next) {
id->newid = NULL;
- idn = id->next; /* id is possibly being inserted again */
+ id_next = id->next; /* id is possibly being inserted again */
/* The check on the second line (LIB_TAG_PRE_EXISTING) is done so its
* possible to tag data you don't want to be made local, used for
@@ -1617,15 +1660,19 @@ void BKE_library_make_local(Main *bmain, const Library *lib, const bool untagged
}
}
}
-
- id = idn;
}
}
- a = set_listbasepointers(bmain, lbarray);
- while (a--) {
- for (id = lbarray[a]->first; id; id = id->next)
+ /* We have to remap local usages of old (linked) ID to new (local) id in a second loop, as lbarray ordering is not
+ * enough to ensure us we did catch all dependencies (e.g. if making local a parent object before its child...).
+ * See T48907. */
+ for (a = set_listbasepointers(bmain, lbarray); a--; ) {
+ for (id = lbarray[a]->first; id; id = id->next) {
+ if (id->newid) {
+ BKE_libblock_remap(bmain, id, id->newid, ID_REMAP_SKIP_INDIRECT_USAGE);
+ }
lib_indirect_test_id(id, lib);
+ }
}
}
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 340eab83414..62aba1af694 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -285,34 +285,9 @@ Material *localize_material(Material *ma)
return man;
}
-void BKE_material_make_local(Main *bmain, Material *ma, const bool force_local)
+void BKE_material_make_local(Main *bmain, Material *ma, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(ma)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, ma, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &ma->id);
- BKE_id_expand_local(&ma->id);
- }
- else {
- Material *ma_new = BKE_material_copy(bmain, ma);
-
- ma_new->id.us = 0;
-
- BKE_libblock_remap(bmain, ma, ma_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &ma->id, true, lib_local);
}
Material ***give_matarar(Object *ob)
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index aeb38b3bd1d..7e363e5600f 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -127,34 +127,9 @@ MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb)
return mbn;
}
-void BKE_mball_make_local(Main *bmain, MetaBall *mb, const bool force_local)
+void BKE_mball_make_local(Main *bmain, MetaBall *mb, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(mb)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, mb, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &mb->id);
- BKE_id_expand_local(&mb->id);
- }
- else {
- MetaBall *mb_new = BKE_mball_copy(bmain, mb);
-
- mb_new->id.us = 0;
-
- BKE_libblock_remap(bmain, mb, mb_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &mb->id, true, lib_local);
}
/* most simple meta-element adding function
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 99b1e96cf20..2b35cdc9d64 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -556,34 +556,9 @@ BMesh *BKE_mesh_to_bmesh(
return bm;
}
-void BKE_mesh_make_local(Main *bmain, Mesh *me, const bool force_local)
+void BKE_mesh_make_local(Main *bmain, Mesh *me, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(me)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, me, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &me->id);
- BKE_id_expand_local(&me->id);
- }
- else {
- Mesh *me_new = BKE_mesh_copy(bmain, me);
-
- me_new->id.us = 0;
-
- BKE_libblock_remap(bmain, me, me_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &me->id, true, lib_local);
}
bool BKE_mesh_uv_cdlayer_rename_index(Mesh *me, const int poly_index, const int loop_index, const int face_index,
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index eec09973a82..8bae0484920 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -1950,34 +1950,9 @@ bNodeTree *ntreeFromID(ID *id)
}
}
-void ntreeMakeLocal(Main *bmain, bNodeTree *ntree, bool id_in_mainlist, const bool force_local)
+void ntreeMakeLocal(Main *bmain, bNodeTree *ntree, bool id_in_mainlist, const bool lib_local)
{
- bool is_lib = false, is_local = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(ntree)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, ntree, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data_ex(bmain, (ID *)ntree, id_in_mainlist);
- BKE_id_expand_local(&ntree->id);
- }
- else {
- bNodeTree *ntree_new = ntreeCopyTree(bmain, ntree);
-
- ntree_new->id.us = 0;
-
- BKE_libblock_remap(bmain, ntree, ntree_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &ntree->id, id_in_mainlist, lib_local);
}
int ntreeNodeExists(bNodeTree *ntree, bNode *testnode)
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 4bdcec51360..9c48fdfbf08 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1186,13 +1186,14 @@ Object *BKE_object_copy(Main *bmain, Object *ob)
return BKE_object_copy_ex(bmain, ob, false);
}
-void BKE_object_make_local(Main *bmain, Object *ob, const bool force_local)
+void BKE_object_make_local(Main *bmain, Object *ob, const bool lib_local)
{
bool is_local = false, is_lib = false;
/* - only lib users: do nothing (unless force_local is set)
* - only local users: set flag
* - mixed: make copy
+ * In case we make a whole lib's content local, we always want to localize, and we skip remapping (done later).
*/
if (!ID_IS_LINKED_DATABLOCK(ob)) {
@@ -1201,7 +1202,7 @@ void BKE_object_make_local(Main *bmain, Object *ob, const bool force_local)
BKE_library_ID_test_usages(bmain, ob, &is_local, &is_lib);
- if (force_local || is_local) {
+ if (lib_local || is_local) {
if (!is_lib) {
id_clear_lib_data(bmain, &ob->id);
BKE_id_expand_local(&ob->id);
@@ -1212,7 +1213,9 @@ void BKE_object_make_local(Main *bmain, Object *ob, const bool force_local)
ob_new->id.us = 0;
ob_new->proxy = ob_new->proxy_from = ob_new->proxy_group = NULL;
- BKE_libblock_remap(bmain, ob, ob_new, ID_REMAP_SKIP_INDIRECT_USAGE);
+ if (!lib_local) {
+ BKE_libblock_remap(bmain, ob, ob_new, ID_REMAP_SKIP_INDIRECT_USAGE);
+ }
}
}
}
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 2ff6c6c8b65..9fef220bcc9 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -3343,34 +3343,9 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
return partn;
}
-void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part, const bool force_local)
+void BKE_particlesettings_make_local(Main *bmain, ParticleSettings *part, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(part)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, part, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &part->id);
- BKE_id_expand_local(&part->id);
- }
- else {
- ParticleSettings *part_new = BKE_particlesettings_copy(bmain, part);
-
- part_new->id.us = 0;
-
- BKE_libblock_remap(bmain, part, part_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &part->id, true, lib_local);
}
/************************************************/
diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c
index c027f3b38ca..80ee6d50d7e 100644
--- a/source/blender/blenkernel/intern/speaker.c
+++ b/source/blender/blenkernel/intern/speaker.c
@@ -85,34 +85,9 @@ Speaker *BKE_speaker_copy(Main *bmain, Speaker *spk)
return spkn;
}
-void BKE_speaker_make_local(Main *bmain, Speaker *spk, const bool force_local)
+void BKE_speaker_make_local(Main *bmain, Speaker *spk, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(spk)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, spk, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &spk->id);
- BKE_id_expand_local(&spk->id);
- }
- else {
- Speaker *spk_new = BKE_speaker_copy(bmain, spk);
-
- spk_new->id.us = 0;
-
- BKE_libblock_remap(bmain, spk, spk_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &spk->id, true, lib_local);
}
void BKE_speaker_free(Speaker *spk)
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index ecc169077cd..ed7f32b938f 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -917,34 +917,9 @@ Tex *BKE_texture_localize(Tex *tex)
/* ------------------------------------------------------------------------- */
-void BKE_texture_make_local(Main *bmain, Tex *tex, const bool force_local)
+void BKE_texture_make_local(Main *bmain, Tex *tex, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(tex)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, tex, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &tex->id);
- BKE_id_expand_local(&tex->id);
- }
- else {
- Tex *tex_new = BKE_texture_copy(bmain, tex);
-
- tex_new->id.us = 0;
-
- BKE_libblock_remap(bmain, tex, tex_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &tex->id, true, lib_local);
}
Tex *give_current_object_texture(Object *ob)
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index f926e29ea84..78342e9919a 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -176,32 +176,7 @@ World *localize_world(World *wrld)
return wrldn;
}
-void BKE_world_make_local(Main *bmain, World *wrld, const bool force_local)
+void BKE_world_make_local(Main *bmain, World *wrld, const bool lib_local)
{
- bool is_local = false, is_lib = false;
-
- /* - only lib users: do nothing (unless force_local is set)
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if (!ID_IS_LINKED_DATABLOCK(wrld)) {
- return;
- }
-
- BKE_library_ID_test_usages(bmain, wrld, &is_local, &is_lib);
-
- if (force_local || is_local) {
- if (!is_lib) {
- id_clear_lib_data(bmain, &wrld->id);
- BKE_id_expand_local(&wrld->id);
- }
- else {
- World *wrld_new = BKE_world_copy(bmain, wrld);
-
- wrld_new->id.us = 0;
-
- BKE_libblock_remap(bmain, wrld, wrld_new, ID_REMAP_SKIP_INDIRECT_USAGE);
- }
- }
+ BKE_id_make_local_generic(bmain, &wrld->id, true, lib_local);
}