Cleanup: factorize the 'ensure local' part of datablock copy into a single BKE_id_cop...
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 25 Jul 2016 14:15:37 +0000 (16:15 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Mon, 25 Jul 2016 14:16:35 +0000 (16:16 +0200)
24 files changed:
source/blender/blenkernel/BKE_library.h
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/camera.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/group.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/key.c
source/blender/blenkernel/intern/lamp.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/linestyle.c
source/blender/blenkernel/intern/mask.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/node.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/speaker.c
source/blender/blenkernel/intern/text.c
source/blender/blenkernel/intern/texture.c
source/blender/blenkernel/intern/world.c

index 2ac7e3c97fbada698e944b716dc253fdf11d2a9b..e32bc2ffb206829b343ebc23aaae9dade90fd111 100644 (file)
@@ -86,6 +86,7 @@ bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, s
 bool id_copy(struct Main *bmain, struct ID *id, struct ID **newid, bool test);
 void id_sort_by_name(struct ListBase *lb, struct ID *id);
 void BKE_id_expand_local(struct ID *id);
+void BKE_id_copy_ensure_local(struct Main *bmain, struct ID *old_id, struct ID *new_id);
 
 bool new_id(struct ListBase *lb, struct ID *id, const char *name);
 void id_clear_lib_data(struct Main *bmain, struct ID *id);
index 8f82610a8bbf2e660c3e4d80eb01330f98905f2d..470098f8c7cd42958d829373f70b8e0ea66905a9 100644 (file)
@@ -156,10 +156,7 @@ bAction *BKE_action_copy(Main *bmain, bAction *src)
                }
        }
        
-       if (ID_IS_LINKED_DATABLOCK(src)) {
-               BKE_id_expand_local(&dst->id);
-               BKE_id_lib_local_paths(bmain, src->id.lib, &dst->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &src->id, &dst->id);
 
        return dst;
 }
index 790272c44113a07e69e6b0db23cf1d9bacc646d7..c644fe0936461109d12e033228dc0ca94c861dc2 100644 (file)
@@ -194,10 +194,7 @@ bArmature *BKE_armature_copy(Main *bmain, bArmature *arm)
        newArm->act_edbone = NULL;
        newArm->sketch = NULL;
 
-       if (ID_IS_LINKED_DATABLOCK(arm)) {
-               BKE_id_expand_local(&newArm->id);
-               BKE_id_lib_local_paths(bmain, arm->id.lib, &newArm->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &arm->id, &newArm->id);
 
        return newArm;
 }
index 9027287a457213b587c1ff8de7c3b5aa99283a61..8ef1fae115590797c358c5bfccc69fb6de522bee 100644 (file)
@@ -197,10 +197,7 @@ Brush *BKE_brush_copy(Main *bmain, Brush *brush)
        /* enable fake user by default */
        id_fake_user_set(&brush->id);
 
-       if (ID_IS_LINKED_DATABLOCK(brush)) {
-               BKE_id_expand_local(&brushn->id);
-               BKE_id_lib_local_paths(bmain, brush->id.lib, &brushn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id);
 
        return brushn;
 }
index 4229b2a727eebf77a28a2c4d488e21e7146b2e9d..85ce399b7709db9db046e11d43803e9ccda161e4 100644 (file)
@@ -99,10 +99,7 @@ Camera *BKE_camera_copy(Main *bmain, Camera *cam)
        
        camn = BKE_libblock_copy(bmain, &cam->id);
 
-       if (ID_IS_LINKED_DATABLOCK(cam)) {
-               BKE_id_expand_local(&camn->id);
-               BKE_id_lib_local_paths(bmain, cam->id.lib, &camn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &cam->id, &camn->id);
 
        return camn;
 }
index 07f4e4f16107ec94935b6c9043a081709b1728d3..90a514781d7061999c872d9b6580e0320e27197b 100644 (file)
@@ -207,10 +207,7 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
        id_us_plus((ID *)cun->vfonti);
        id_us_plus((ID *)cun->vfontbi);
 
-       if (ID_IS_LINKED_DATABLOCK(cu)) {
-               BKE_id_expand_local(&cun->id);
-               BKE_id_lib_local_paths(bmain, cu->id.lib, &cun->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &cu->id, &cun->id);
 
        return cun;
 }
index f58d26f47dc6c3afa3f5d2945f9d292bd0f77a49..9b011dbb003c537c380e9c74ecf19b596367eb14 100644 (file)
@@ -97,10 +97,7 @@ Group *BKE_group_copy(Main *bmain, Group *group)
        /* Do not copy group's preview (same behavior as for objects). */
        groupn->preview = NULL;
 
-       if (ID_IS_LINKED_DATABLOCK(group)) {
-               BKE_id_expand_local(&groupn->id);
-               BKE_id_lib_local_paths(bmain, group->id.lib, &groupn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &group->id, &groupn->id);
 
        return groupn;
 }
index 017eb41cd49db81f3bbec13b11426f9f868735e6..ea28dabb94548bf05390da4ef428fc4225f211d7 100644 (file)
@@ -462,10 +462,7 @@ Image *BKE_image_copy(Main *bmain, Image *ima)
 
        BKE_previewimg_id_copy(&nima->id, &ima->id);
 
-       if (ID_IS_LINKED_DATABLOCK(ima)) {
-               BKE_id_expand_local(&nima->id);
-               BKE_id_lib_local_paths(bmain, ima->id.lib, &nima->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &ima->id, &nima->id);
 
        return nima;
 }
index a524f927cad61a6bae0d4ba97855b7fb1d8f936c..6cdeaf5e59b33a4865bbd6ae6faa5706314df0fb 100644 (file)
@@ -170,10 +170,7 @@ Key *BKE_key_copy(Main *bmain, Key *key)
                kb = kb->next;
        }
 
-       if (ID_IS_LINKED_DATABLOCK(key)) {
-               BKE_id_expand_local(&keyn->id);
-               BKE_id_lib_local_paths(bmain, key->id.lib, &keyn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &key->id, &keyn->id);
 
        return keyn;
 }
index 35fcf211b0506e0a694e1a41d64f6abfb91a4b80..e9d039ad48073945e0df590857012d2208ea391a 100644 (file)
@@ -138,10 +138,7 @@ Lamp *BKE_lamp_copy(Main *bmain, Lamp *la)
 
        BKE_previewimg_id_copy(&lan->id, &la->id);
 
-       if (ID_IS_LINKED_DATABLOCK(la)) {
-               BKE_id_expand_local(&lan->id);
-               BKE_id_lib_local_paths(bmain, la->id.lib, &lan->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &la->id, &lan->id);
 
        return lan;
 }
index 82b179d4f1cbb5529b5762a77349ea78d9693907..b0671f33094c8eb13b570c8ef9f8a79e62cb94b4 100644 (file)
@@ -297,10 +297,7 @@ Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt)
 
        ltn->editlatt = NULL;
 
-       if (ID_IS_LINKED_DATABLOCK(lt)) {
-               BKE_id_expand_local(&ltn->id);
-               BKE_id_lib_local_paths(bmain, lt->id.lib, &ltn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &lt->id, &ltn->id);
 
        return ltn;
 }
index c31df6851368121ddd7dbc2deca65747a744de4c..ce70e5da82fec3f85d76b65ef95d1a76a3247be2 100644 (file)
@@ -271,6 +271,17 @@ void BKE_id_expand_local(ID *id)
        BKE_library_foreach_ID_link(id, id_expand_local_callback, NULL, 0);
 }
 
+/**
+ * Ensure new (copied) ID is fully made local.
+ */
+void BKE_id_copy_ensure_local(Main *bmain, ID *old_id, ID *new_id)
+{
+       if (ID_IS_LINKED_DATABLOCK(old_id)) {
+               BKE_id_expand_local(new_id);
+               BKE_id_lib_local_paths(bmain, old_id->lib, new_id);
+       }
+}
+
 /**
  * Generic 'make local' function, works for most of datablock types...
  */
index 1aff5d502f810620f3886210272283a11ee9fa90..430935a5fad3d875bf4c69128bc86b30e420f92f 100644 (file)
@@ -218,10 +218,7 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, FreestyleLineStyle *l
        for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next)
                BKE_linestyle_geometry_modifier_copy(new_linestyle, m);
 
-       if (ID_IS_LINKED_DATABLOCK(linestyle)) {
-               BKE_id_expand_local(&new_linestyle->id);
-               BKE_id_lib_local_paths(bmain, linestyle->id.lib, &new_linestyle->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &linestyle->id, &new_linestyle->id);
 
        return new_linestyle;
 }
index 014461e0d228f2275193b67d66ae46ccbf8f5516..21023d9f53cedf36bf1542de783281f83cc32921 100644 (file)
@@ -853,10 +853,7 @@ Mask *BKE_mask_copy(Main *bmain, Mask *mask)
        /* enable fake user by default */
        id_fake_user_set(&mask->id);
 
-       if (ID_IS_LINKED_DATABLOCK(mask)) {
-               BKE_id_expand_local(&mask_new->id);
-               BKE_id_lib_local_paths(bmain, mask->id.lib, &mask_new->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &mask->id, &mask_new->id);
 
        return mask_new;
 }
index 62aba1af694296f25e25e2ae07e53a8c9cc19134..0be32c9b84c00efa1d313b0ab5672f8a6daf2c55 100644 (file)
@@ -247,10 +247,7 @@ Material *BKE_material_copy(Main *bmain, Material *ma)
 
        BLI_listbase_clear(&man->gpumaterial);
 
-       if (ID_IS_LINKED_DATABLOCK(ma)) {
-               BKE_id_expand_local(&man->id);
-               BKE_id_lib_local_paths(bmain, ma->id.lib, &man->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &ma->id, &man->id);
 
        return man;
 }
index 7e363e5600f07f308cec2b24c1f0a6752fd70307..8d024ea9aa531811570ff8a05daa2a7561aa3b07 100644 (file)
@@ -119,10 +119,7 @@ MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb)
        mbn->editelems = NULL;
        mbn->lastelem = NULL;
        
-       if (ID_IS_LINKED_DATABLOCK(mb)) {
-               BKE_id_expand_local(&mbn->id);
-               BKE_id_lib_local_paths(bmain, mb->id.lib, &mbn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &mb->id, &mbn->id);
 
        return mbn;
 }
index 2b35cdc9d6490040f5e1e08906a243e73e74ab3b..733e903005637c2c1a4751a123a1460d6e097bdd 100644 (file)
@@ -531,10 +531,7 @@ Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
                men->key->from = (ID *)men;
        }
 
-       if (ID_IS_LINKED_DATABLOCK(me)) {
-               BKE_id_expand_local(&men->id);
-               BKE_id_lib_local_paths(bmain, me->id.lib, &men->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &me->id, &men->id);
 
        return men;
 }
index 8bae04849202b1ecd2b18d36b68ef6ce339ffe7c..2b88ae4823c33bd4ec695be287d834d4cb5a628a 100644 (file)
@@ -1290,10 +1290,7 @@ static bNodeTree *ntreeCopyTree_internal(bNodeTree *ntree, Main *bmain, bool ski
        /* node tree will generate its own interface type */
        newtree->interface_type = NULL;
        
-       if (ID_IS_LINKED_DATABLOCK(ntree)) {
-               BKE_id_expand_local(&newtree->id);
-               BKE_id_lib_local_paths(bmain, ntree->id.lib, &newtree->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &ntree->id, &newtree->id);
 
        return newtree;
 }
index 9c48fdfbf0877ace5ea64294d38963cb2d03a4f0..d736a45516375111672589d74dbfcccd33d025a6 100644 (file)
@@ -1169,10 +1169,7 @@ Object *BKE_object_copy_ex(Main *bmain, Object *ob, bool copy_caches)
        /* Copy runtime surve data. */
        obn->curve_cache = NULL;
 
-       if (ID_IS_LINKED_DATABLOCK(ob)) {
-               BKE_id_expand_local(&obn->id);
-               BKE_id_lib_local_paths(bmain, ob->id.lib, &obn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &ob->id, &obn->id);
 
        /* Do not copy object's preview (mostly due to the fact renderers create temp copy of objects). */
        obn->preview = NULL;
index 9fef220bcc9e8091100b04ccd2423fd18e850d64..42b818b35a5960a307b958a03eca4925380c7270 100644 (file)
@@ -3335,10 +3335,7 @@ ParticleSettings *BKE_particlesettings_copy(Main *bmain, ParticleSettings *part)
 
        BLI_duplicatelist(&partn->dupliweights, &part->dupliweights);
        
-       if (ID_IS_LINKED_DATABLOCK(part)) {
-               BKE_id_expand_local(&partn->id);
-               BKE_id_lib_local_paths(bmain, part->id.lib, &partn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &part->id, &partn->id);
 
        return partn;
 }
index 80ee6d50d7e0013c47546ccc8bfc1879f4fba109..ee6886e3fb2d29afbe39831d6eedb11866fc4e61 100644 (file)
@@ -77,10 +77,7 @@ Speaker *BKE_speaker_copy(Main *bmain, Speaker *spk)
        if (spkn->sound)
                id_us_plus(&spkn->sound->id);
 
-       if (ID_IS_LINKED_DATABLOCK(spk)) {
-               BKE_id_expand_local(&spkn->id);
-               BKE_id_lib_local_paths(G.main, spk->id.lib, &spkn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &spk->id, &spkn->id);
 
        return spkn;
 }
index 82c3132d73e5ec3ba94a90c75ce53f9bed699569..1636042f479e1828aa93b10b938cb675967030b1 100644 (file)
@@ -491,10 +491,7 @@ Text *BKE_text_copy(Main *bmain, Text *ta)
 
        init_undo_text(tan);
 
-       if (ID_IS_LINKED_DATABLOCK(ta)) {
-               BKE_id_expand_local(&tan->id);
-               BKE_id_lib_local_paths(bmain, ta->id.lib, &tan->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &ta->id, &tan->id);
 
        return tan;
 }
index ed7f32b938f3ab8f6acc9ee65326aa3e8ff158a2..2d3ecad19ad1f59e92e0b8b5119abdda938ff755 100644 (file)
@@ -873,10 +873,7 @@ Tex *BKE_texture_copy(Main *bmain, Tex *tex)
 
        BKE_previewimg_id_copy(&texn->id, &tex->id);
 
-       if (ID_IS_LINKED_DATABLOCK(tex)) {
-               BKE_id_expand_local(&texn->id);
-               BKE_id_lib_local_paths(bmain, tex->id.lib, &texn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &tex->id, &texn->id);
 
        return texn;
 }
index 78342e9919aae2ccc945e77d55451c35f355b2a7..de1e3187a70a968d3b9841fb83067f7365dda680 100644 (file)
@@ -142,10 +142,7 @@ World *BKE_world_copy(Main *bmain, World *wrld)
 
        BLI_listbase_clear(&wrldn->gpumaterial);
 
-       if (ID_IS_LINKED_DATABLOCK(wrld)) {
-               BKE_id_expand_local(&wrldn->id);
-               BKE_id_lib_local_paths(bmain, wrld->id.lib, &wrldn->id);
-       }
+       BKE_id_copy_ensure_local(bmain, &wrld->id, &wrldn->id);
 
        return wrldn;
 }