Commit: 2ec17e655c4fdabc6251b5c81f4404451160923c
Author: Bastien Montagne
Date:   Mon Jul 11 19:13:42 2016 +0200
Branches: master
https://developer.blender.org/rB2ec17e655c4fdabc6251b5c81f4404451160923c

Use new generic BKE_id_expand_local() for both make_local() and copy() 
functions of obdata
(armature, mesh, curve, mball, lattice, lamp, camera, and speaker).

This greatly simplifies said code, once again no change expected from user PoV.

===================================================================

M       source/blender/blenkernel/intern/armature.c
M       source/blender/blenkernel/intern/camera.c
M       source/blender/blenkernel/intern/curve.c
M       source/blender/blenkernel/intern/lamp.c
M       source/blender/blenkernel/intern/lattice.c
M       source/blender/blenkernel/intern/mball.c
M       source/blender/blenkernel/intern/mesh.c
M       source/blender/blenkernel/intern/speaker.c

===================================================================

diff --git a/source/blender/blenkernel/intern/armature.c 
b/source/blender/blenkernel/intern/armature.c
index 2473dbe..3850e4b 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -162,6 +162,7 @@ void BKE_armature_make_local(Main *bmain, bArmature *arm)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &arm->id);
+                       BKE_id_expand_local(&arm->id, false);
                }
                else {
                        bArmature *arm_new = BKE_armature_copy(bmain, arm);
@@ -221,6 +222,8 @@ bArmature *BKE_armature_copy(Main *bmain, bArmature *arm)
        newArm->act_edbone = NULL;
        newArm->sketch = NULL;
 
+       BKE_id_expand_local(&newArm->id, true);
+
        if (ID_IS_LINKED_DATABLOCK(arm)) {
                BKE_id_lib_local_paths(bmain, arm->id.lib, &newArm->id);
        }
diff --git a/source/blender/blenkernel/intern/camera.c 
b/source/blender/blenkernel/intern/camera.c
index 8336c1f..8ae714d 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -99,7 +99,7 @@ Camera *BKE_camera_copy(Main *bmain, Camera *cam)
        
        camn = BKE_libblock_copy(bmain, &cam->id);
 
-       id_lib_extern((ID *)camn->dof_ob);
+       BKE_id_expand_local(&camn->id, true);
 
        if (ID_IS_LINKED_DATABLOCK(cam)) {
                BKE_id_lib_local_paths(bmain, cam->id.lib, &camn->id);
@@ -126,6 +126,7 @@ void BKE_camera_make_local(Main *bmain, Camera *cam)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &cam->id);
+                       BKE_id_expand_local(&cam->id, false);
                }
                else {
                        Camera *cam_new = BKE_camera_copy(bmain, cam);
diff --git a/source/blender/blenkernel/intern/curve.c 
b/source/blender/blenkernel/intern/curve.c
index 3a7be94..4fb2cda 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -177,7 +177,6 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int 
type)
 Curve *BKE_curve_copy(Main *bmain, Curve *cu)
 {
        Curve *cun;
-       int a;
 
        cun = BKE_libblock_copy(bmain, &cu->id);
 
@@ -185,9 +184,6 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
        BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb));
 
        cun->mat = MEM_dupallocN(cu->mat);
-       for (a = 0; a < cun->totcol; a++) {
-               id_us_plus((ID *)cun->mat[a]);
-       }
 
        cun->str = MEM_dupallocN(cu->str);
        cun->strinfo = MEM_dupallocN(cu->strinfo);
@@ -196,21 +192,14 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
 
        if (cu->key) {
                cun->key = BKE_key_copy(bmain, cu->key);
+               cun->key->id.us = 0;  /* Will be increased again by 
BKE_id_expand_local. */
                cun->key->from = (ID *)cun;
        }
 
        cun->editnurb = NULL;
        cun->editfont = NULL;
 
-#if 0   // XXX old animation system
-       /* single user ipo too */
-       if (cun->ipo) cun->ipo = copy_ipo(cun->ipo);
-#endif // XXX old animation system
-
-       id_us_plus((ID *)cun->vfont);
-       id_us_plus((ID *)cun->vfontb);
-       id_us_plus((ID *)cun->vfonti);
-       id_us_plus((ID *)cun->vfontbi);
+       BKE_id_expand_local(&cun->id, true);
 
        if (ID_IS_LINKED_DATABLOCK(cu)) {
                BKE_id_lib_local_paths(bmain, cu->id.lib, &cun->id);
@@ -219,21 +208,6 @@ Curve *BKE_curve_copy(Main *bmain, Curve *cu)
        return cun;
 }
 
-static int extern_local_curve_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_curve(Curve *cu)
-{
-       BKE_library_foreach_ID_link(&cu->id, extern_local_curve_callback, NULL, 
0);
-}
-
 void BKE_curve_make_local(Main *bmain, Curve *cu)
 {
        bool is_local = false, is_lib = false;
@@ -255,7 +229,6 @@ void BKE_curve_make_local(Main *bmain, Curve *cu)
                        if (cu->key) {
                                BKE_key_make_local(bmain, cu->key);
                        }
-                       extern_local_curve(cu);
                }
                else {
                        Curve *cu_new = BKE_curve_copy(bmain, cu);
diff --git a/source/blender/blenkernel/intern/lamp.c 
b/source/blender/blenkernel/intern/lamp.c
index 3e656a2..e1aec61 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -127,7 +127,6 @@ Lamp *BKE_lamp_copy(Main *bmain, Lamp *la)
                if (lan->mtex[a]) {
                        lan->mtex[a] = MEM_mallocN(sizeof(MTex), "copylamptex");
                        memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex));
-                       id_us_plus((ID *)lan->mtex[a]->tex);
                }
        }
        
@@ -136,9 +135,10 @@ Lamp *BKE_lamp_copy(Main *bmain, Lamp *la)
        if (la->nodetree)
                lan->nodetree = ntreeCopyTree(bmain, la->nodetree);
        
-       if (la->preview)
-               lan->preview = BKE_previewimg_copy(la->preview);
-       
+       lan->preview = BKE_previewimg_copy(la->preview);
+
+       BKE_id_expand_local(&lan->id, true);
+
        if (ID_IS_LINKED_DATABLOCK(la)) {
                BKE_id_lib_local_paths(bmain, la->id.lib, &lan->id);
        }
@@ -167,26 +167,11 @@ Lamp *localize_lamp(Lamp *la)
        if (la->nodetree)
                lan->nodetree = ntreeLocalize(la->nodetree);
        
-       lan->preview = BKE_previewimg_copy(la->preview);
+       lan->preview = NULL;
 
        return lan;
 }
 
-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)
 {
        bool is_local = false, is_lib = false;
@@ -205,7 +190,7 @@ void BKE_lamp_make_local(Main *bmain, Lamp *la)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &la->id);
-                       extern_local_lamp(la);
+                       BKE_id_expand_local(&la->id, false);
                }
                else {
                        Lamp *la_new = BKE_lamp_copy(bmain, la);
diff --git a/source/blender/blenkernel/intern/lattice.c 
b/source/blender/blenkernel/intern/lattice.c
index 88b0418..7ffec1e 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -286,6 +286,7 @@ Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt)
 
        if (lt->key) {
                ltn->key = BKE_key_copy(bmain, ltn->key);
+               ltn->key->id.us = 0;  /* Will be increased again by 
BKE_id_expand_local. */
                ltn->key->from = (ID *)ltn;
        }
        
@@ -297,6 +298,8 @@ Lattice *BKE_lattice_copy(Main *bmain, Lattice *lt)
 
        ltn->editlatt = NULL;
 
+       BKE_id_expand_local(&ltn->id, true);
+
        if (ID_IS_LINKED_DATABLOCK(lt)) {
                BKE_id_lib_local_paths(bmain, lt->id.lib, &ltn->id);
        }
@@ -350,7 +353,7 @@ void BKE_lattice_make_local(Main *bmain, Lattice *lt)
                        if (lt->key) {
                                BKE_key_make_local(bmain, lt->key);
                        }
-                       /* No extern_local_lattice... */
+                       BKE_id_expand_local(&lt->id, false);
                }
                else {
                        Lattice *lt_new = BKE_lattice_copy(bmain, lt);
diff --git a/source/blender/blenkernel/intern/mball.c 
b/source/blender/blenkernel/intern/mball.c
index 0a29b2d..e615c22 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -105,20 +105,18 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name)
 MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb)
 {
        MetaBall *mbn;
-       int a;
        
        mbn = BKE_libblock_copy(bmain, &mb->id);
 
        BLI_duplicatelist(&mbn->elems, &mb->elems);
        
        mbn->mat = MEM_dupallocN(mb->mat);
-       for (a = 0; a < mbn->totcol; a++) {
-               id_us_plus((ID *)mbn->mat[a]);
-       }
 
        mbn->editelems = NULL;
        mbn->lastelem = NULL;
        
+       BKE_id_expand_local(&mbn->id, true);
+
        if (ID_IS_LINKED_DATABLOCK(mb)) {
                BKE_id_lib_local_paths(bmain, mb->id.lib, &mbn->id);
        }
@@ -126,21 +124,6 @@ MetaBall *BKE_mball_copy(Main *bmain, MetaBall *mb)
        return mbn;
 }
 
-static int extern_local_mball_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_mball(MetaBall *mb)
-{
-       BKE_library_foreach_ID_link(&mb->id, extern_local_mball_callback, NULL, 
0);
-}
-
 void BKE_mball_make_local(Main *bmain, MetaBall *mb)
 {
        bool is_local = false, is_lib = false;
@@ -159,7 +142,7 @@ void BKE_mball_make_local(Main *bmain, MetaBall *mb)
        if (is_local) {
                if (!is_lib) {
                        id_clear_lib_data(bmain, &mb->id);
-                       extern_local_mball(mb);
+                       BKE_id_expand_local(&mb->id, false);
                }
                else {
                        MetaBall *mb_new = BKE_mball_copy(bmain, mb);
diff --git a/source/blender/blenkernel/intern/mesh.c 
b/source/blender/blenkernel/intern/mesh.c
index e737696..cfcc88e 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -496,18 +496,11 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name)
 Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
 {
        Mesh *men;
-       MTFace *tface;
-       MTexPoly *txface;
-       int a, i;
        const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* 
only do tessface if we have no polys */
        
        men = BKE_libblock_copy(bmain, &me->id);
        
        men->mat = MEM_dupallocN(me->mat);
-       for (a = 0; a < men->totcol; a++) {
-               id_us_plus((ID *)men->mat[a]);
-       }
-       id_us_plus((ID *)men->texcomesh);
 
        CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, 
men->totvert);
        CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, 
men->totedge);
@@ -522,37 +515,19 @@ Mesh *BKE_mesh_copy(Main *bmain, Mesh *me)
 
        BKE_mesh_update_customdata_pointers(men, do_tessface);
 
-       /* ensure indirect linked data becomes lib-extern */
-       for (i = 0; i < me->fdata.totlayer; i++) {
-               if (me->fdata.layers[i].type == CD_MTFACE) {
-                       tface = (MTFace *)me->fdata.layers[i].data;
-
-                       for (a = 0; a < me->totface; a++, tface++)
-                               if (tface->tpage)
-                                       id_lib_extern((ID *)tface->tpage);
-               }
-       }
-       
-       for (i = 0; i < me->pdata.totlayer; i++) {
-               if (me->pdata.layers[i].type == CD_MTEXPOLY) {
-                       txface = (MTexPoly *)me->pdata.layers[i].data;
-
-                       for (a = 0; a < me->totpoly; a++, txface++)
-                               if (txface->tpage)
-                                       id_lib_extern((ID *)txface->tpage);
-               }
-       }
-
        men->edit_btmesh = NULL;
 
        men->mselect = MEM_dupallocN(men->mselect);
        men->bb = MEM_dupallocN(men->bb);
-       
+
        if (me->key) {
                men->key = BKE_key_copy(bmain, me->key);

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to