Merged changes in the trunk up to revision 34996.
[blender.git] / source / blender / blenlib / intern / bpath.c
index 560eb55981fded8ca7336de269f10d0b003b53c8..473a6172047370c1db6bf140e9f90db19b0b1982 100644 (file)
@@ -51,6 +51,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"
@@ -77,6 +78,12 @@ typedef struct BPathIteratorSeqData {
        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 */
        const char*     _lib;
@@ -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,6 +119,7 @@ enum BPathTypes {
        BPATH_LIB,
        BPATH_SEQ,
        BPATH_CDATA,
+       BPATH_FRS_MODULE,
 
         BPATH_DONE
 };
@@ -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;
 
@@ -147,32 +162,35 @@ static void BLI_bpathIterator_alloc(struct BPathIterator **bpi) {
 }
 #endif
 
-void BLI_bpathIterator_free(struct BPathIterator *bpi) {
+void BLI_bpathIterator_free( struct BPathIterator *bpi ) {
        if (bpi->seqdata.seqar)
                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) {
+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 */
        }
 }
 
-void BLI_bpathIterator_setPath(struct BPathIterator *bpi, const 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 */
        }
 }
 
-void BLI_bpathIterator_getPathExpanded(struct BPathIterator *bpi, char *path_expanded) {
+void BLI_bpathIterator_getPathExpanded( struct BPathIterator *bpi, char *path_expanded) {
        const char *libpath;
        
        BLI_bpathIterator_getPath(bpi, path_expanded);
@@ -185,19 +203,19 @@ void BLI_bpathIterator_getPathExpanded(struct BPathIterator *bpi, char *path_exp
        }
        BLI_cleanup_file(NULL, path_expanded);
 }
-const char* BLI_bpathIterator_getLib(struct BPathIterator *bpi) {
+const char* BLI_bpathIterator_getLib( struct BPathIterator *bpi) {
        return bpi->_lib;
 }
-const char* BLI_bpathIterator_getName(struct BPathIterator *bpi) {
+const char* BLI_bpathIterator_getName( struct BPathIterator *bpi) {
        return bpi->_name;
 }
-int    BLI_bpathIterator_getType(struct BPathIterator *bpi) {
+int    BLI_bpathIterator_getType( struct BPathIterator *bpi) {
        return bpi->type;
 }
-int    BLI_bpathIterator_getPathMaxLen(struct BPathIterator *bpi) {
+int    BLI_bpathIterator_getPathMaxLen( struct BPathIterator *bpi) {
        return bpi->len;
 }
-const char* BLI_bpathIterator_getBasePath(struct BPathIterator *bpi) {
+const char* BLI_bpathIterator_getBasePath( struct BPathIterator *bpi) {
        return bpi->base_path;
 }
 
@@ -351,6 +369,35 @@ static struct Sequence *seq_stepdata__internal(struct BPathIterator *bpi, int st
        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;
+}
+
 static void seq_getpath(struct BPathIterator *bpi, char *path) {
        Sequence *seq= (Sequence *)bpi->data;
 
@@ -430,7 +477,7 @@ static struct Mesh *cdata_stepdata__internal(struct Mesh *me, int step_next) {
        return me;
 }
 
-static void bpi_type_step__internal(struct BPathIterator *bpi) {
+static void bpi_type_step__internal( struct BPathIterator *bpi) {
        bpi->type++; /* advance to the next type */
        bpi->data= NULL;
        
@@ -450,7 +497,7 @@ static void bpi_type_step__internal(struct BPathIterator *bpi) {
        }
 }
 
-void BLI_bpathIterator_step(struct BPathIterator *bpi) {
+void BLI_bpathIterator_step( struct BPathIterator *bpi) {
        while (bpi->type != BPATH_DONE) {
                
                if  ((bpi->type) == BPATH_IMAGE) {
@@ -608,6 +655,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);
+                       }
                }
        }
 }
@@ -651,6 +712,9 @@ 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;