added path traversal flag - BPATH_TRAVERSE_SKIP_MULTIFILE,
authorCampbell Barton <ideasman42@gmail.com>
Tue, 1 Nov 2011 06:26:55 +0000 (06:26 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 1 Nov 2011 06:26:55 +0000 (06:26 +0000)
so path manipulation functions dont run multiple times on the same path in the case of sequence strips where the one directory is used as the base for many images.

19 files changed:
source/blender/blenkernel/BKE_library.h
source/blender/blenkernel/intern/action.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/blender.c
source/blender/blenkernel/intern/brush.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/lattice.c
source/blender/blenkernel/intern/library.c
source/blender/blenkernel/intern/material.c
source/blender/blenkernel/intern/mball.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/object.c
source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/speaker.c
source/blender/blenkernel/intern/texture.c
source/blender/blenkernel/intern/world.c
source/blender/blenlib/BLI_bpath.h
source/blender/blenlib/intern/bpath.c

index e2033915caab96eef539d1b9570b0352111ecbcb..9130cac6cd60f2feaa86769ef8e094db148627b9 100644 (file)
@@ -49,6 +49,7 @@ void *alloc_libblock(struct ListBase *lb, short type, const char *name);
 void *copy_libblock(void *rt);
 void copy_libblock_data(struct ID *id, const struct ID *id_from, const short do_action);
 
+void BKE_id_lib_local_paths(struct Main *bmain, struct ID *id);
 void id_lib_extern(struct ID *id);
 void BKE_library_filepath_set(struct Library *lib, const char *filepath);
 void id_us_plus(struct ID *id);
index 2a1794fe2fced69b9aa06435066b776374a15aad..944f7c6a0b627a3bda5ee895088d3d8c4bbee338 100644 (file)
@@ -146,13 +146,10 @@ void make_local_action(bAction *act)
                id_clear_lib_data(bmain, &act->id);
        }
        else if (mlac.is_local && mlac.is_lib) {
-               char *bpath_user_data[2]= {bmain->name, act->id.lib->filepath};
-
                mlac.actn= copy_action(act);
                mlac.actn->id.us= 0;
 
-               /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &mlac.actn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &mlac.actn->id);
 
                BKE_animdata_main_cb(bmain, make_localact_apply_cb, &mlac);
        }
index 9fba18dd7cf34fcc660e1359e3c4f0d448f1fed4..e9a19b50a81eead516522933249f8e516ad88ebd 100644 (file)
@@ -157,12 +157,11 @@ void make_local_armature(bArmature *arm)
                id_clear_lib_data(bmain, &arm->id);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, arm->id.lib->filepath};
                bArmature *armn= copy_armature(arm);
                armn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &armn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &armn->id);
 
                for(ob= bmain->object.first; ob; ob= ob->id.next) {
                        if(ob->data == arm) {
index 6e343e874f1135a8f1885d4d8b55a775d76724af..d68b0b361d1db13d3449b2543320825997f0290c 100644 (file)
@@ -172,7 +172,7 @@ static void clean_paths(Main *main)
 {
        Scene *scene;
 
-       bpath_traverse_main(main, clean_paths_visit_cb, 0, NULL);
+       bpath_traverse_main(main, clean_paths_visit_cb, BPATH_TRAVERSE_SKIP_MULTIFILE, NULL);
 
        for(scene= main->scene.first; scene; scene= scene->id.next) {
                BLI_clean(scene->r.pic);
index 10f056e9b78993ebc6423f31bb62ad10e9e4b8c7..e78b89441c908037af9a451f66c64d3bcb92c0ef 100644 (file)
@@ -224,13 +224,12 @@ void make_local_brush(Brush *brush)
                }
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, brush->id.lib->filepath};
                Brush *brushn= copy_brush(brush);
                brushn->id.us= 1; /* only keep fake user */
                brushn->id.flag |= LIB_FAKEUSER;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &brushn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &brush->id);
                
                for(scene= bmain->scene.first; scene; scene=scene->id.next) {
                        if(paint_brush(&scene->toolsettings->imapaint.paint)==brush) {
index 13b1da224493c774c0676820091f90976c168583..5d2180fe70219d7d78bef014d7a24abe370507ba 100644 (file)
@@ -273,13 +273,10 @@ void make_local_curve(Curve *cu)
                extern_local_curve(cu);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, cu->id.lib->filepath};
                Curve *cun= copy_curve(cu);
                cun->id.us= 0;
 
-
-               /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &cun->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &cun->id);
 
                for(ob= bmain->object.first; ob; ob= ob->id.next) {
                        if(ob->data==cu) {
index 9aeacb9d7fa36f830841d1a5599fda2eb429319f..08440849a4e1f10a97553be531eb805b04b2285d 100644 (file)
@@ -385,13 +385,12 @@ void make_local_image(struct Image *ima)
                extern_local_image(ima);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, ima->id.lib->filepath};
                Image *iman= copy_image(ima);
 
                iman->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &iman->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &iman->id);
 
                tex= bmain->tex.first;
                while(tex) {
index 9a528b541431cb6b45abad6c088f4d0cbd3dc27d..478782426044dbb7e51967ba749ab42edea80578 100644 (file)
@@ -271,12 +271,11 @@ void make_local_lattice(Lattice *lt)
                id_clear_lib_data(bmain, &lt->id);
        }
        else if(is_local && is_lib) {
-               char *bath_user_data[2]= {bmain->name, lt->id.lib->filepath};
                Lattice *ltn= copy_lattice(lt);
                ltn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &ltn->id, bpath_relocate_visitor, 0, bath_user_data);
+               BKE_id_lib_local_paths(bmain, &ltn->id);
 
                for(ob= bmain->object.first; ob; ob= ob->id.next) {
                        if(ob->data==lt) {
index 9d8acc44e88138f30ac60fe7652525d227d2015a..35b50730a3113a5fc44ceea583b653dd3fd39143 100644 (file)
 
 /* ************* general ************************ */
 
+
+/* this has to be called from each make_local_* func, we could call
+ * from id_make_local() but then the make local functions would not be self
+ * contained.
+ * also note that the id _must_ have a library - campbell */
+void BKE_id_lib_local_paths(Main *bmain, ID *id)
+{
+       char *bpath_user_data[2]= {bmain->name, (id)->lib->filepath};
+
+       bpath_traverse_id(bmain, id,
+                                         bpath_relocate_visitor,
+                                         BPATH_TRAVERSE_SKIP_MULTIFILE,
+                                         bpath_user_data);
+}
+
 void id_lib_extern(ID *id)
 {
        if(id) {
@@ -1252,8 +1267,8 @@ int new_id(ListBase *lb, ID *id, const char *tname)
    don't have other library users. */
 void id_clear_lib_data(Main *bmain, ID *id)
 {
-       char *bpath_user_data[2]= {bmain->name, id->lib->filepath};
-       bpath_traverse_id(bmain, id, bpath_relocate_visitor, 0, bpath_user_data);
+       BKE_id_lib_local_paths(bmain, id);
+
        id->lib= NULL;
        id->flag= LIB_LOCAL;
        new_id(which_libbase(bmain, GS(id->name)), id, NULL);
index 2ad3da9f3a0885db8b82d090c39faefcc84797d9..7be3514e0f2733792168907530cc092512452e58 100644 (file)
@@ -364,13 +364,12 @@ void make_local_material(Material *ma)
        }
        /* Both user and local, so copy. */
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, ma->id.lib->filepath};
                Material *man= copy_material(ma);
 
                man->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &man->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &man->id);
 
                /* do objects */
                ob= bmain->object.first;
index 98646bd2faa49529ddb5d9a439283d84b6b707fa..327306b32eed899a465ea75c5cb3bb13fc8a5b38 100644 (file)
@@ -174,12 +174,11 @@ void make_local_mball(MetaBall *mb)
                extern_local_mball(mb);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, mb->id.lib->filepath};
                MetaBall *mbn= copy_mball(mb);
                mbn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &mbn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &mbn->id);
 
                for(ob= G.main->object.first; ob; ob= ob->id.next) {
                        if(ob->data == mb) {
index 6f66e189dcf7b527f5504ddfae0053160950c861..4a8bc34cdf762002ec760a0c8072725d4532f6f0 100644 (file)
@@ -298,13 +298,12 @@ void make_local_mesh(Mesh *me)
                expand_local_mesh(me);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, me->id.lib->filepath};
                Mesh *men= copy_mesh(me);
                men->id.us= 0;
 
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &men->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &men->id);
 
                for(ob= bmain->object.first; ob; ob= ob->id.next) {
                        if(me == ob->data) {
index 0d0552cf3b3718da54b80594f238a30d80a22f5a..635e0744aa13c3b47ef56c59d220bbdbda79abcd 100644 (file)
@@ -772,13 +772,12 @@ void make_local_camera(Camera *cam)
                id_clear_lib_data(bmain, &cam->id);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, cam->id.lib->filepath};
                Camera *camn= copy_camera(cam);
 
                camn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &camn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &camn->id);
 
                for(ob= bmain->object.first; ob; ob= ob->id.next) {
                        if(ob->data == cam) {
@@ -939,13 +938,11 @@ void make_local_lamp(Lamp *la)
                id_clear_lib_data(bmain, &la->id);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, la->id.lib->filepath};
                Lamp *lan= copy_lamp(la);
                lan->id.us= 0;
-               
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &lan->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &lan->id);
 
                ob= bmain->object.first;
                while(ob) {
@@ -1486,13 +1483,12 @@ void make_local_object(Object *ob)
                        extern_local_object(ob);
                }
                else if(is_local && is_lib) {
-                       char *bpath_user_data[2]= {bmain->name, ob->id.lib->filepath};
                        Object *obn= copy_object(ob);
 
                        obn->id.us= 0;
                        
                        /* Remap paths of new ID using old library as base. */
-                       bpath_traverse_id(bmain, &obn->id, bpath_relocate_visitor, 0, bpath_user_data);
+                       BKE_id_lib_local_paths(bmain, &obn->id);
 
                        sce= bmain->scene.first;
                        while(sce) {
index a1ed0862336a4cb25706f8110ace41a23253f42d..7678da1c7c407199dfa3b545f33a2092db45f7cd 100644 (file)
@@ -3632,13 +3632,12 @@ void make_local_particlesettings(ParticleSettings *part)
                expand_local_particlesettings(part);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, part->id.lib->filepath};
                ParticleSettings *partn= psys_copy_settings(part);
 
                partn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &partn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &partn->id);
 
                /* do objects */
                for(ob= bmain->object.first; ob; ob= ob->id.next) {
index d5788d7a748aab1398221dd55390f2e734f58146..018c7a197ffdb701c8d3b174ae0a6b49dac5f7ee 100644 (file)
@@ -106,12 +106,11 @@ void make_local_speaker(Speaker *spk)
                id_clear_lib_data(bmain, &spk->id);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, spk->id.lib->filepath};
                Speaker *spkn= copy_speaker(spk);
                spkn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &spkn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &spkn->id);
 
                ob= bmain->object.first;
                while(ob) {
index e3713b1e1770ff257b5901ca546d691f21377fce..d3bd7d7b766a351b94dc1c47fa3a55e1277ae059 100644 (file)
@@ -897,13 +897,12 @@ void make_local_texture(Tex *tex)
                extern_local_texture(tex);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, tex->id.lib->filepath};
                Tex *texn= copy_texture(tex);
 
                texn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &texn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &texn->id);
                
                ma= bmain->mat.first;
                while(ma) {
index 4d7a7c9a2627d4c8dd19c0eeff35b500d6205c09..5797c6c3f157c62c0f0c5e7e68e02487615755f2 100644 (file)
@@ -176,12 +176,11 @@ void make_local_world(World *wrld)
                id_clear_lib_data(bmain, &wrld->id);
        }
        else if(is_local && is_lib) {
-               char *bpath_user_data[2]= {bmain->name, wrld->id.lib->filepath};
                World *wrldn= copy_world(wrld);
                wrldn->id.us= 0;
 
                /* Remap paths of new ID using old library as base. */
-               bpath_traverse_id(bmain, &wrldn->id, bpath_relocate_visitor, 0, bpath_user_data);
+               BKE_id_lib_local_paths(bmain, &wrldn->id);
 
                for(sce= bmain->scene.first; sce; sce= sce->id.next) {
                        if(sce->world == wrld) {
index 89ba4b2675eac2908c8aad9967c0a4130d265cb2..e850db5a171d7b819a3fdbc13edee03c18b78266 100644 (file)
@@ -48,9 +48,13 @@ void bpath_traverse_id_list(struct Main *bmain, struct ListBase *lb, BPathVisito
 void bpath_traverse_main(struct Main *bmain, BPathVisitor visit_cb, const int flag, void *userdata);
 int bpath_relocate_visitor(void *oldbasepath, char *path_dst, const char *path_src);
 
-#define BPATH_TRAVERSE_ABS          (1<<0) /* convert paths to absolute */
-#define BPATH_TRAVERSE_SKIP_LIBRARY (1<<2) /* skip library paths */
-#define BPATH_TRAVERSE_SKIP_PACKED  (1<<3) /* skip packed data */
+#define BPATH_TRAVERSE_ABS             (1<<0) /* convert paths to absolute */
+#define BPATH_TRAVERSE_SKIP_LIBRARY    (1<<2) /* skip library paths */
+#define BPATH_TRAVERSE_SKIP_PACKED     (1<<3) /* skip packed data */
+#define BPATH_TRAVERSE_SKIP_MULTIFILE  (1<<4) /* skip paths where a single dir is used with an array of files, eg.
+                                               * sequence strip images and pointcache. in this case only use the first
+                                               * file, this is needed for directory manipulation functions which might
+                                               * otherwise modify the same directory multiple times */
 
 /* high level funcs */
 
index b7fe7ef5efdd83b6417b00b202037043d2ba1a31..259b25e67dd41dc43977d53a6c7f32d79e030913 100644 (file)
@@ -499,6 +499,11 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla
                                                        int len= MEM_allocN_len(se) / sizeof(*se);
                                                        int i;
 
+                                                       if (flag & BPATH_TRAVERSE_SKIP_MULTIFILE) {
+                                                               /* only operate on one path */
+                                                               len= MIN2(1, len);
+                                                       }
+
                                                        for(i= 0; i < len; i++, se++) {
                                                                rewrite_path_fixed_dirfile(seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data);
                                                        }