Support more kinds of paths for path re-writing / traversing, patch from Alex Fraser...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 26 Oct 2011 22:46:06 +0000 (22:46 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 26 Oct 2011 22:46:06 +0000 (22:46 +0000)
this now supports as many types as bpath iterator which its intended to replace.

source/blender/blenkernel/intern/library.c
source/blender/blenlib/intern/bpath.c
source/blender/editors/space_outliner/outliner_draw.c
source/blender/editors/space_sequencer/sequencer_draw.c

index 308fa82..f6a5a7f 100644 (file)
@@ -1477,7 +1477,12 @@ void name_uiprefix_id(char *name, ID *id)
 
 void BKE_library_filepath_set(Library *lib, const char *filepath)
 {
-       BLI_strncpy(lib->name, filepath, sizeof(lib->name));
+       /* in some cases this is used to update the absolute path from the
+        * relative */
+       if (lib->name != filepath) {
+               BLI_strncpy(lib->name, filepath, sizeof(lib->name));
+       }
+
        BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath));
 
        /* not essential but set filepath is an absolute copy of value which
index 0d22981..9b1f2ca 100644 (file)
@@ -55,6 +55,8 @@
 #include "DNA_sequence_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_windowmanager_types.h"
+#include "DNA_object_types.h"
+#include "DNA_object_fluidsim.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_bpath.h"
@@ -66,6 +68,7 @@
 #include "BKE_main.h"
 #include "BKE_utildefines.h"
 #include "BKE_report.h"
+#include "BKE_library.h"
 
 typedef struct BPathIteratorSeqData
 {
@@ -953,27 +956,138 @@ void findMissingFiles(Main *bmain, const char *str)
 }
 
 /* Run a visitor on a string, replacing the contents of the string as needed. */
-static void rewrite_path(char *path, BPathVisitor visit, void *userdata)
+static int rewrite_path_fixed(char path[FILE_MAX], BPathVisitor visit_cb, void *userdata)
 {
-       char pathOut[FILE_MAX];
-       if (visit(userdata, path, pathOut))
-               BLI_strncpy(path, pathOut, FILE_MAX);
+       char path_dst[FILE_MAX];
+
+       if (visit_cb(userdata, path_dst, (const char *)path)) {
+               BLI_strncpy(path, path_dst, FILE_MAX);
+               return TRUE;
+       }
+       else {
+               return FALSE;
+       }
+}
+
+static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR], char path_file[FILE_MAXFILE], BPathVisitor visit_cb, void *userdata)
+{
+       char path_src[FILE_MAX];
+       char path_dst[FILE_MAX];
+
+       BLI_join_dirfile(path_src, sizeof(path_src), path_dir, path_file);
+
+       if (visit_cb(userdata, path_dst, (const char *)path_src)) {
+               BLI_split_dirfile(path_dst, path_dir, path_file,
+                                 sizeof(path_dir), sizeof(path_file));
+               return TRUE;
+       }
+       else {
+               return FALSE;
+       }
+}
+
+static int rewrite_path_alloc(char **path, BPathVisitor visit_cb, void *userdata)
+{
+       char path_dst[FILE_MAX];
+
+       if (visit_cb(userdata, path_dst, (const char *)(*path))) {
+               MEM_freeN((*path));
+               (*path)= BLI_strdup(path_dst);
+               return TRUE;
+       }
+       else {
+               return FALSE;
+       }
 }
 
 /* Run visitor function 'visit' on all paths contained in 'id'. */
-void bpath_traverse_id(ID *id, BPathVisitor visit, void *userdata)
+void bpath_traverse_id(ID *id, BPathVisitor visit_cb, void *userdata)
 {
        Image *ima;
 
        switch(GS(id->name)) {
        case ID_IM:
-               ima = (Image*)id;
+               ima = (Image *)id;
                if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE))
-                       rewrite_path(ima->name, visit, userdata);
+                       rewrite_path_fixed(ima->name, visit_cb, userdata);
                break;
        case ID_OB:
+               {
+                       Object *ob= (Object *)id;
+                       if (ob->fluidsimSettings) {
+                               rewrite_path_fixed(ob->fluidsimSettings->surfdataPath, visit_cb, userdata);
+                       }
+                       /* TODO: add modifiers, e.g. point cache for particles. */
+               }
+               break;
        case ID_SO:
+               rewrite_path_fixed(((bSound *)id)->name, visit_cb, userdata);
+               break;
        case ID_TXT:
+               if (((Text*)id)->name) {
+                       rewrite_path_alloc(&((Text *)id)->name, visit_cb, userdata);
+               }
+               break;
+       case ID_VF:
+               if (strcmp(((VFont*)id)->name, FO_BUILTIN_NAME) != 0) {
+                       rewrite_path_fixed(((VFont *)id)->name, visit_cb, userdata);
+               }
+               break;
+       case ID_TE:
+               {
+                       Tex *tex = (Tex *)id;
+                       if (tex->plugin) {
+                               /* FIXME: rewrite_path assumes path length of FILE_MAX, but
+                                          tex->plugin->name is 160. ... is this field even a path? */
+                               //rewrite_path(tex->plugin->name, visit_cb, userdata);
+                       }
+                       if (tex->type == TEX_VOXELDATA && TEX_VD_IS_SOURCE_PATH(tex->vd->file_format)) {
+                               rewrite_path_fixed(tex->vd->source_path, visit_cb, userdata);
+                       }
+               }
+               break;
+
+       case ID_SCE:
+               {
+                       Scene *scene= (Scene *)id;
+                       if (scene->ed) {
+                               Sequence *seq;
+
+                               SEQ_BEGIN(scene->ed, seq) {
+                                       if (SEQ_HAS_PATH(seq)) {
+                                               if (ELEM3(seq->type, SEQ_IMAGE, SEQ_MOVIE, SEQ_SOUND)) {
+                                                       rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name, visit_cb, userdata);
+                                               }
+                                               else {
+                                                       /* simple case */
+                                                       rewrite_path_fixed(seq->strip->dir, visit_cb, userdata);
+                                               }
+                                       }
+                                       else if (seq->plugin) {
+                                               rewrite_path_fixed(seq->plugin->name, visit_cb, userdata);
+                                       }
+
+                               }
+                               SEQ_END
+                       }
+               }
+               break;
+       case ID_ME:
+               {
+                       Mesh *me= (Mesh *)id;
+                       if (me->fdata.external) {
+                               rewrite_path_fixed(me->fdata.external->filename, visit_cb, userdata);
+                       }
+               }
+               break;
+       case ID_LI:
+               {
+                       Library *lib= (Library *)id;
+                       if(rewrite_path_fixed(lib->name, visit_cb, userdata)) {
+                               BKE_library_filepath_set(lib, lib->name);
+                       }
+               }
+               break;
        /* TODO: add other ID types e.g. object (modifiers) */
        default:
                /* Nothing to do for other IDs that don't contain file paths. */
index 608a3c4..96b5548 100644 (file)
@@ -313,13 +313,9 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
                                Library *lib= (Library *)tselem->id;
                                char expanded[FILE_MAX];
 
-                               BLI_strncpy(expanded, lib->name, sizeof(expanded));
-
-                               /* even though we already set the name this syncs the absolute
-                                * path, this is intentionally not already expanded yet to
-                                * avoid copying lib->name to its self. */
-                               BKE_library_filepath_set(lib, expanded);
+                               BKE_library_filepath_set(lib, lib->name);
 
+                               BLI_strncpy(expanded, lib->name, sizeof(expanded));
                                BLI_path_abs(expanded, G.main->name);
                                if (!BLI_exists(expanded)) {
                                        BKE_reportf(CTX_wm_reports(C), RPT_ERROR, "Library path '%s' does not exist, correct this before saving", expanded);
index 18360f8..ddfa2fd 100644 (file)
@@ -72,7 +72,8 @@
 #define SEQ_RIGHTHANDLE        2
 
 
-/* Note, Dont use WHILE_SEQ while drawing! - it messes up transform, - Campbell */
+/* Note, Dont use SEQ_BEGIN/SEQ_END while drawing!
+ * it messes up transform, - Campbell */
 static void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2);
 
 static void get_seq_color3ubv(Scene *curscene, Sequence *seq, unsigned char col[3])
@@ -253,8 +254,10 @@ static void drawmeta_stipple(int value)
 
 static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float x2, float y2)
 {
-       /* Note, this used to use WHILE_SEQ, but it messes up the seq->depth value, (needed by transform when doing overlap checks)
-        * so for now, just use the meta's immediate children, could be fixed but its only drawing - Campbell */
+       /* note: this used to use SEQ_BEGIN/SEQ_END, but it messes up the
+        * seq->depth value, (needed by transform when doing overlap checks)
+        * so for now, just use the meta's immediate children, could be fixed but
+        * its only drawing - campbell */
        Sequence *seq;
        unsigned char col[4];