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:
Diffstat (limited to 'source/blender/blenlib/intern/bpath.c')
-rw-r--r--source/blender/blenlib/intern/bpath.c226
1 files changed, 145 insertions, 81 deletions
diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c
index 654ade8955f..98d53ca16db 100644
--- a/source/blender/blenlib/intern/bpath.c
+++ b/source/blender/blenlib/intern/bpath.c
@@ -56,6 +56,7 @@
#include "DNA_sequence_types.h"
#include "DNA_vfont_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_freestyle_types.h"
#include "BLI_blenlib.h"
#include "BLI_bpath.h"
@@ -72,10 +73,16 @@ typedef struct BPathIteratorSeqData
{
int totseq;
int seq;
- struct Sequence **seqar; /* Sequence */
- struct Scene *scene; /* Current scene */
+ struct Sequence **seqar; /* Sequence */
+ struct Scene *scene; /* Current scene */
} BPathIteratorSeqData;
+typedef struct BPathIteratorFrsModuleData {
+ struct Scene *scene; /* Current scene */
+ struct SceneRenderLayer *layer; /* Scene render layer */
+ struct FreestyleModuleConfig *module;
+} BPathIteratorFrsModuleData;
+
typedef struct BPathIterator
{
char* _path; /* never access directly, use BLI_bpathIterator_getPath */
@@ -95,6 +102,8 @@ typedef struct BPathIterator
/* only for seq data */
struct BPathIteratorSeqData seqdata;
+ /* only for Freestyle module data */
+ struct BPathIteratorFrsModuleData frsmoduledata;
} BPathIterator;
#define FILE_MAX 240
@@ -110,8 +119,9 @@ enum BPathTypes {
BPATH_LIB,
BPATH_SEQ,
BPATH_CDATA,
+ BPATH_FRS_MODULE,
- BPATH_DONE
+ BPATH_DONE
};
void BLI_bpathIterator_init(struct BPathIterator **bpi_pt, Main *bmain, const char *basedir, const int flag)
@@ -123,10 +133,10 @@ void BLI_bpathIterator_init(struct BPathIterator **bpi_pt, Main *bmain, const ch
bpi->type= BPATH_IMAGE;
bpi->data= NULL;
-
+
bpi->getpath_callback= NULL;
bpi->setpath_callback= NULL;
-
+
/* Sequencer specific */
bpi->seqdata.totseq= 0;
bpi->seqdata.seq= 0;
@@ -135,6 +145,11 @@ void BLI_bpathIterator_init(struct BPathIterator **bpi_pt, Main *bmain, const ch
bpi->flag= flag;
+ /* Freestyle module specific */
+ bpi->frsmoduledata.scene= NULL;
+ bpi->frsmoduledata.layer= NULL;
+ bpi->frsmoduledata.module= NULL;
+
bpi->base_path= basedir; /* normally bmain->name */
bpi->bmain= bmain;
@@ -154,14 +169,17 @@ void BLI_bpathIterator_free(struct BPathIterator *bpi)
MEM_freeN((void *)bpi->seqdata.seqar);
bpi->seqdata.seqar= NULL;
bpi->seqdata.scene= NULL;
-
+ bpi->frsmoduledata.scene= NULL;
+ bpi->frsmoduledata.layer= NULL;
+ bpi->frsmoduledata.module= NULL;
+
MEM_freeN(bpi);
}
void BLI_bpathIterator_getPath(struct BPathIterator *bpi, char *path)
{
if (bpi->getpath_callback) {
- bpi->getpath_callback(bpi, path);
+ bpi->getpath_callback( bpi, path );
}
else {
strcpy(path, bpi->_path); /* warning, we assume 'path' are long enough */
@@ -171,7 +189,7 @@ void BLI_bpathIterator_getPath(struct BPathIterator *bpi, char *path)
void BLI_bpathIterator_setPath(struct BPathIterator *bpi, const char *path)
{
if (bpi->setpath_callback) {
- bpi->setpath_callback(bpi, path);
+ bpi->setpath_callback( bpi, path );
}
else {
strcpy(bpi->_path, path); /* warning, we assume 'path' are long enough */
@@ -181,10 +199,10 @@ void BLI_bpathIterator_setPath(struct BPathIterator *bpi, const char *path)
void BLI_bpathIterator_getPathExpanded(struct BPathIterator *bpi, char *path_expanded)
{
const char *libpath;
-
+
BLI_bpathIterator_getPath(bpi, path_expanded);
libpath= BLI_bpathIterator_getLib(bpi);
-
+
if (libpath) { /* check the files location relative to its library path */
BLI_path_abs(path_expanded, libpath);
}
@@ -219,10 +237,10 @@ static struct Image *ima_stepdata__internal(struct Image *ima, const int step_ne
{
if (ima==NULL)
return NULL;
-
+
if (step_next)
ima= ima->id.next;
-
+
while (ima) {
if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
if(ima->packedfile==NULL || (flag & BPATH_USE_PACKED)) {
@@ -231,7 +249,7 @@ static struct Image *ima_stepdata__internal(struct Image *ima, const int step_ne
}
/* image is not a image with a path, skip it */
ima= ima->id.next;
- }
+ }
return ima;
}
@@ -248,7 +266,7 @@ static struct Tex *tex_stepdata__internal(struct Tex *tex, const int step_next,
break;
/* image is not a image with a path, skip it */
tex= tex->id.next;
- }
+ }
return tex;
}
@@ -265,7 +283,7 @@ static struct Text *text_stepdata__internal(struct Text *text, const int step_ne
break;
/* image is not a image with a path, skip it */
text= text->id.next;
- }
+ }
return text;
}
@@ -273,20 +291,20 @@ static struct VFont *vf_stepdata__internal(struct VFont *vf, const int step_next
{
if (vf==NULL)
return NULL;
-
+
if (step_next)
vf= vf->id.next;
-
+
while (vf) {
if (strcmp(vf->name, FO_BUILTIN_NAME)!=0) {
if(vf->packedfile==NULL || (flag & BPATH_USE_PACKED)) {
break;
}
}
-
+
/* font with no path, skip it */
vf= vf->id.next;
- }
+ }
return vf;
}
@@ -294,10 +312,10 @@ static struct bSound *snd_stepdata__internal(struct bSound *snd, int step_next,
{
if (snd==NULL)
return NULL;
-
+
if (step_next)
snd= snd->id.next;
-
+
while (snd) {
if(snd->packedfile==NULL || (flag & BPATH_USE_PACKED)) {
break;
@@ -305,7 +323,7 @@ static struct bSound *snd_stepdata__internal(struct bSound *snd, int step_next,
/* font with no path, skip it */
snd= snd->id.next;
- }
+ }
return snd;
}
@@ -313,16 +331,16 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
{
Editing *ed;
Sequence *seq;
-
+
/* Initializing */
if (bpi->seqdata.scene==NULL) {
bpi->seqdata.scene= bpi->bmain->scene.first;
}
-
+
if (step_next) {
bpi->seqdata.seq++;
}
-
+
while (bpi->seqdata.scene) {
ed= seq_give_editing(bpi->seqdata.scene, 0);
if (ed) {
@@ -331,7 +349,7 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
seq_array(ed, &bpi->seqdata.seqar, &bpi->seqdata.totseq, 0);
bpi->seqdata.seq= 0;
}
-
+
if (bpi->seqdata.seq >= bpi->seqdata.totseq) {
seq= NULL;
}
@@ -363,6 +381,35 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
bpi->seqdata.scene= bpi->seqdata.scene->id.next;
}
}
+
+ return NULL;
+}
+
+static struct FreestyleModuleConfig *frs_module_stepdata__internal(struct BPathIterator *bpi, int step_next)
+{
+ struct FreestyleModuleConfig *module;
+
+ /* Initializing */
+ if (bpi->frsmoduledata.scene==NULL) {
+ bpi->frsmoduledata.scene= G.main->scene.first;
+ bpi->frsmoduledata.layer= (bpi->frsmoduledata.scene) ? bpi->frsmoduledata.scene->r.layers.first : NULL;
+ bpi->frsmoduledata.module= (bpi->frsmoduledata.layer) ? bpi->frsmoduledata.layer->freestyleConfig.modules.first : NULL;
+ }
+
+ while (bpi->frsmoduledata.scene) {
+ while (bpi->frsmoduledata.layer) {
+ while (bpi->frsmoduledata.module) {
+ module= bpi->frsmoduledata.module;
+ bpi->frsmoduledata.module= module->next;
+ return module;
+ }
+ bpi->frsmoduledata.layer= bpi->frsmoduledata.layer->next;
+ bpi->frsmoduledata.module= (bpi->frsmoduledata.layer) ? bpi->frsmoduledata.layer->freestyleConfig.modules.first : NULL;
+ }
+ bpi->frsmoduledata.scene= bpi->frsmoduledata.scene->id.next;
+ bpi->frsmoduledata.layer= (bpi->frsmoduledata.scene) ? bpi->frsmoduledata.scene->r.layers.first : NULL;
+ bpi->frsmoduledata.module= (bpi->frsmoduledata.layer) ? bpi->frsmoduledata.layer->freestyleConfig.modules.first : NULL;
+ }
return NULL;
}
@@ -371,7 +418,7 @@ static void seq_getpath(struct BPathIterator *bpi, char *path)
{
Sequence *seq= (Sequence *)bpi->data;
-
+
path[0]= '\0'; /* incase we cant get the path */
if (seq==NULL) return;
if (SEQ_HAS_PATH(seq)) {
@@ -381,7 +428,7 @@ static void seq_getpath(struct BPathIterator *bpi, char *path)
if (seq->strip->stripdata) { /* should always be true! */
/* Using the first image is weak for image sequences */
strcat(path, seq->strip->stripdata->name);
- }
+ }
}
else {
/* simple case */
@@ -396,8 +443,8 @@ static void seq_getpath(struct BPathIterator *bpi, char *path)
static void seq_setpath(struct BPathIterator *bpi, const char *path)
{
Sequence *seq= (Sequence *)bpi->data;
- if (seq==NULL) return;
-
+ if (seq==NULL) return;
+
if (SEQ_HAS_PATH(seq)) {
if (ELEM3(seq->type, SEQ_IMAGE, SEQ_MOVIE, SEQ_SOUND)) {
BLI_split_dirfile(path, seq->strip->dir, seq->strip->stripdata->name);
@@ -424,7 +471,7 @@ static void text_getpath(struct BPathIterator *bpi, char *path)
static void text_setpath(struct BPathIterator *bpi, const char *path)
{
Text *text= (Text *)bpi->data;
- if (text==NULL) return;
+ if (text==NULL) return;
if(text->name) {
MEM_freeN(text->name);
@@ -437,17 +484,17 @@ static struct Mesh *cdata_stepdata__internal(struct Mesh *me, int step_next)
{
if (me==NULL)
return NULL;
-
+
if (step_next)
me= me->id.next;
-
+
while (me) {
if (me->fdata.external) {
break;
}
-
+
me= me->id.next;
- }
+ }
return me;
}
@@ -455,7 +502,7 @@ static void bpi_type_step__internal(struct BPathIterator *bpi)
{
bpi->type++; /* advance to the next type */
bpi->data= NULL;
-
+
switch (bpi->type) {
case BPATH_SEQ:
bpi->getpath_callback= seq_getpath;
@@ -475,21 +522,21 @@ static void bpi_type_step__internal(struct BPathIterator *bpi)
void BLI_bpathIterator_step(struct BPathIterator *bpi)
{
while (bpi->type != BPATH_DONE) {
-
+
if ((bpi->type) == BPATH_IMAGE) {
/*if (bpi->data) bpi->data= ((ID *)bpi->data)->next;*/
if (bpi->data) bpi->data= ima_stepdata__internal((Image *)bpi->data, 1, bpi->flag); /* must skip images that have no path */
else bpi->data= ima_stepdata__internal(bpi->bmain->image.first, 0, bpi->flag);
-
+
if (bpi->data) {
/* get the path info from this datatype */
Image *ima= (Image *)bpi->data;
-
+
bpi->_lib= ima->id.lib ? ima->id.lib->filepath : NULL;
bpi->_path= ima->name;
bpi->_name= ima->id.name+2;
bpi->len= sizeof(ima->name);
-
+
/* we are done, advancing to the next item, this type worked fine */
break;
@@ -570,10 +617,10 @@ void BLI_bpathIterator_step(struct BPathIterator *bpi)
}
}
else if ((bpi->type) == BPATH_FONT) {
-
+
if (bpi->data) bpi->data= vf_stepdata__internal((VFont *)bpi->data, 1, bpi->flag);
else bpi->data= vf_stepdata__internal(bpi->bmain->vfont.first, 0, bpi->flag);
-
+
if (bpi->data) {
/* get the path info from this datatype */
VFont *vf= (VFont *)bpi->data;
@@ -594,16 +641,16 @@ void BLI_bpathIterator_step(struct BPathIterator *bpi)
else if ((bpi->type) == BPATH_LIB) {
if (bpi->data) bpi->data= ((ID *)bpi->data)->next;
else bpi->data= bpi->bmain->library.first;
-
+
if (bpi->data) {
/* get the path info from this datatype */
Library *lib= (Library *)bpi->data;
-
+
bpi->_lib= NULL;
bpi->_path= lib->name;
bpi->_name= NULL;
bpi->len= sizeof(lib->name);
-
+
/* we are done, advancing to the next item, this type worked fine */
break;
}
@@ -640,6 +687,20 @@ void BLI_bpathIterator_step(struct BPathIterator *bpi)
else {
bpi_type_step__internal(bpi);
}
+ } else if ((bpi->type) == BPATH_FRS_MODULE) {
+ if (bpi->data) bpi->data= frs_module_stepdata__internal( bpi, 1 );
+ else bpi->data= frs_module_stepdata__internal( bpi, 0 );
+
+ if (bpi->data) {
+ FreestyleModuleConfig *module= (FreestyleModuleConfig *)bpi->data;
+ bpi->_lib= NULL;
+ bpi->_path= module->module_path;
+ bpi->_name= NULL;
+ bpi->len= sizeof(module->module_path);
+ break;
+ } else {
+ bpi_type_step__internal(bpi);
+ }
}
}
}
@@ -654,7 +715,7 @@ static void bpath_as_report(struct BPathIterator *bpi, const char *message, Repo
const char *prefix;
const char *name;
char path_expanded[FILE_MAXDIR*2];
-
+
if(reports==NULL)
return;
@@ -683,11 +744,14 @@ static void bpath_as_report(struct BPathIterator *bpi, const char *message, Repo
case BPATH_CDATA:
prefix= "Mesh Data";
break;
+ case BPATH_FRS_MODULE:
+ prefix= "Freestyle Module";
+ break;
default:
prefix= "Unknown";
break;
}
-
+
name= BLI_bpathIterator_getName(bpi);
BLI_bpathIterator_getPathExpanded(bpi, path_expanded);
@@ -701,14 +765,14 @@ static void bpath_as_report(struct BPathIterator *bpi, const char *message, Repo
/* high level function */
void checkMissingFiles(Main *bmain, ReportList *reports) {
struct BPathIterator *bpi;
-
+
/* be sure there is low chance of the path being too short */
- char filepath_expanded[FILE_MAXDIR*2];
-
+ char filepath_expanded[FILE_MAXDIR*2];
+
BLI_bpathIterator_init(&bpi, bmain, bmain->name, 0);
while (!BLI_bpathIterator_isDone(bpi)) {
BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
-
+
if (!BLI_exists(filepath_expanded))
bpath_as_report(bpi, "file not found", reports);
@@ -723,7 +787,7 @@ void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) {
struct BPathIterator *bpi;
char filepath[FILE_MAX];
const char *libpath;
-
+
/* be sure there is low chance of the path being too short */
char filepath_relative[(FILE_MAXDIR * 2) + FILE_MAXFILE];
@@ -736,7 +800,7 @@ void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) {
while (!BLI_bpathIterator_isDone(bpi)) {
BLI_bpathIterator_getPath(bpi, filepath);
libpath= BLI_bpathIterator_getLib(bpi);
-
+
if(strncmp(filepath, "//", 2)) {
if (libpath) { /* cant make relative if we are library - TODO, LOG THIS */
linked++;
@@ -744,7 +808,7 @@ void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) {
else { /* local data, use the blend files path */
BLI_strncpy(filepath_relative, filepath, sizeof(filepath_relative));
/* Important BLI_cleanup_dir runs before the path is made relative
- * because it wont work for paths that start with "//../" */
+ * because it wont work for paths that start with "//../" */
BLI_cleanup_file(bpi->base_path, filepath_relative); /* fix any /foo/../foo/ */
BLI_path_rel(filepath_relative, bpi->base_path);
/* be safe and check the length */
@@ -782,7 +846,7 @@ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports)
struct BPathIterator *bpi;
char filepath[FILE_MAX];
const char *libpath;
-
+
/* be sure there is low chance of the path being too short */
char filepath_absolute[(FILE_MAXDIR * 2) + FILE_MAXFILE];
@@ -795,7 +859,7 @@ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports)
while (!BLI_bpathIterator_isDone(bpi)) {
BLI_bpathIterator_getPath(bpi, filepath);
libpath= BLI_bpathIterator_getLib(bpi);
-
+
if(strncmp(filepath, "//", 2)==0) {
if (libpath) { /* cant make absolute if we are library - TODO, LOG THIS */
linked++;
@@ -844,25 +908,25 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
struct stat status;
char path[FILE_MAX];
int size;
-
+
dir= opendir(dirname);
-
+
if (dir==NULL)
return 0;
-
+
if (*filesize == -1)
*filesize= 0; /* dir opened fine */
-
+
while ((de= readdir(dir)) != NULL) {
-
+
if (strcmp(".", de->d_name)==0 || strcmp("..", de->d_name)==0)
continue;
-
+
BLI_join_dirfile(path, sizeof(path), dirname, de->d_name);
-
+
if (stat(path, &status) != 0)
continue; /* cant stat, dont bother with this file, could print debug info here */
-
+
if (S_ISREG(status.st_mode)) { /* is file */
if (strncmp(filename, de->d_name, FILE_MAX)==0) { /* name matches */
/* open the file to read its size */
@@ -888,55 +952,55 @@ static int findFileRecursive(char *filename_new, const char *dirname, const char
/* high level function - call from fileselector */
void findMissingFiles(Main *bmain, const char *str) {
struct BPathIterator *bpi;
-
+
/* be sure there is low chance of the path being too short */
- char filepath_expanded[FILE_MAXDIR*2];
+ char filepath_expanded[FILE_MAXDIR*2];
char filepath[FILE_MAX];
const char *libpath;
int filesize, recur_depth;
-
+
char dirname[FILE_MAX], filename_new[FILE_MAX];
-
+
//XXX waitcursor( 1 );
-
+
BLI_split_dirfile(str, dirname, NULL);
-
+
BLI_bpathIterator_init(&bpi, bmain, bmain->name, 0);
-
+
while (!BLI_bpathIterator_isDone(bpi)) {
BLI_bpathIterator_getPath(bpi, filepath);
libpath= BLI_bpathIterator_getLib(bpi);
-
+
/* Check if esc was pressed because searching files can be slow */
/*XXX if (blender_test_break()) {
break;
}*/
-
+
if (libpath==NULL) {
-
+
BLI_bpathIterator_getPathExpanded(bpi, filepath_expanded);
-
+
if (!BLI_exists(filepath_expanded)) {
/* can the dir be opened? */
filesize= -1;
recur_depth= 0;
-
+
findFileRecursive(filename_new, dirname, BLI_path_basename(filepath), &filesize, &recur_depth);
if (filesize == -1) { /* could not open dir */
printf("Could not open dir \"%s\"\n", dirname);
return;
}
-
+
if (filesize > 0) {
-
- if (BLI_bpathIterator_getPathMaxLen(bpi) < strlen(filename_new)) {
+
+ if (BLI_bpathIterator_getPathMaxLen(bpi) < strlen(filename_new)) {
printf("cannot set path \"%s\" too long!", filename_new);
}
else {
/* copy the found path into the old one */
if (G.relbase_valid)
BLI_path_rel(filename_new, bpi->base_path);
-
+
BLI_bpathIterator_setPath(bpi, filename_new);
}
}
@@ -945,6 +1009,6 @@ void findMissingFiles(Main *bmain, const char *str) {
BLI_bpathIterator_step(bpi);
}
BLI_bpathIterator_free(bpi);
-
+
//XXX waitcursor( 0 );
}