Merging r46111 through r46136 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / writefile.c
index ab620e9..0cd57ee 100644 (file)
@@ -133,6 +133,7 @@ Any case: direct data is ALWAYS after the lib block
 #include "DNA_world_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_movieclip_types.h"
+#include "DNA_mask_types.h"
 
 #include "MEM_guardedalloc.h" // MEM_freeN
 #include "BLI_bitmap.h"
@@ -239,7 +240,7 @@ static void writedata_free(WriteData *wd)
  
 #define MYWRITE_FLUSH          NULL
 
-static void mywrite( WriteData *wd, const void *adr, int len)
+static void mywrite(WriteData *wd, const void *adr, int len)
 {
        if (wd->error) return;
 
@@ -974,7 +975,7 @@ static void write_particlesystems(WriteData *wd, ListBase *particles)
                writestruct(wd, DATA, "ParticleSystem", 1, psys);
 
                if (psys->particles) {
-                       writestruct(wd, DATA, "ParticleData", psys->totpart ,psys->particles);
+                       writestruct(wd, DATA, "ParticleData", psys->totpartpsys->particles);
 
                        if (psys->particles->hair) {
                                ParticleData *pa = psys->particles;
@@ -993,7 +994,7 @@ static void write_particlesystems(WriteData *wd, ListBase *particles)
                for (; pt; pt=pt->next)
                        writestruct(wd, DATA, "ParticleTarget", 1, pt);
 
-               if (psys->child) writestruct(wd, DATA, "ChildParticle", psys->totchild ,psys->child);
+               if (psys->child) writestruct(wd, DATA, "ChildParticle", psys->totchildpsys->child);
 
                if (psys->clmd) {
                        writestruct(wd, DATA, "ClothModifierData", 1, psys->clmd);
@@ -2108,13 +2109,15 @@ static void write_scenes(WriteData *wd, ListBase *scebase)
                        
                        /* reset write flags too */
                        
-                       SEQ_BEGIN(ed, seq) {
+                       SEQ_BEGIN (ed, seq)
+                       {
                                if (seq->strip) seq->strip->done= 0;
                                writestruct(wd, DATA, "Sequence", 1, seq);
                        }
                        SEQ_END
                        
-                       SEQ_BEGIN(ed, seq) {
+                       SEQ_BEGIN (ed, seq)
+                       {
                                if (seq->strip && seq->strip->done==0) {
                                        /* write strip with 'done' at 0 because readfile */
                                        
@@ -2677,6 +2680,18 @@ static void write_movieTracks(WriteData *wd, ListBase *tracks)
        }
 }
 
+static void write_movieDopesheet(WriteData *wd, MovieTrackingDopesheet *dopesheet)
+{
+       MovieTrackingDopesheetChannel *channel;
+
+       channel = dopesheet->channels.first;
+       while (channel) {
+               writestruct(wd, DATA, "MovieTrackingDopesheetChannel", 1, channel);
+
+               channel = channel->next;
+       }
+}
+
 static void write_movieReconstruction(WriteData *wd, MovieTrackingReconstruction *reconstruction)
 {
        if (reconstruction->camnr)
@@ -2709,6 +2724,8 @@ static void write_movieclips(WriteData *wd, ListBase *idbase)
 
                                object= object->next;
                        }
+
+                       write_movieDopesheet(wd, &tracking->dopesheet);
                }
 
                clip= clip->id.next;
@@ -2718,6 +2735,54 @@ static void write_movieclips(WriteData *wd, ListBase *idbase)
        mywrite(wd, MYWRITE_FLUSH, 0);
 }
 
+static void write_masks(WriteData *wd, ListBase *idbase)
+{
+       Mask *mask;
+
+       mask = idbase->first;
+       while (mask) {
+               if (mask->id.us > 0 || wd->current) {
+                       MaskShape *shape;
+
+                       writestruct(wd, ID_MSK, "Mask", 1, mask);
+
+                       if (mask->adt)
+                               write_animdata(wd, mask->adt);
+
+                       shape = mask->shapes.first;
+                       while (shape) {
+                               MaskSpline *spline;
+
+                               writestruct(wd, DATA, "MaskShape", 1, shape);
+
+                               spline = shape->splines.first;
+                               while (spline) {
+                                       int i;
+
+                                       writestruct(wd, DATA, "MaskSpline", 1, spline);
+                                       writestruct(wd, DATA, "MaskSplinePoint", spline->tot_point, spline->points);
+
+                                       for (i = 0; i < spline->tot_point; i++) {
+                                               MaskSplinePoint *point = &spline->points[i];
+
+                                               if (point->tot_uw)
+                                                       writestruct(wd, DATA, "MaskSplinePointUW", point->tot_uw, point->uw);
+                                       }
+
+                                       spline = spline->next;
+                               }
+
+                               shape = shape->next;
+                       }
+               }
+
+               mask = mask->id.next;
+       }
+
+       /* flush helps the compression for undo-save */
+       mywrite(wd, MYWRITE_FLUSH, 0);
+}
+
 /* context is usually defined by WM, two cases where no WM is available:
  * - for forward compatibility, curscreen has to be saved
  * - for undofile, curscene needs to be saved */
@@ -2802,6 +2867,7 @@ static int write_file_handle(Main *mainvar, int handle, MemFile *compare, MemFil
                write_screens  (wd, &mainvar->screen);
        }
        write_movieclips (wd, &mainvar->movieclip);
+       write_masks    (wd, &mainvar->mask);
        write_scenes   (wd, &mainvar->scene);
        write_curves   (wd, &mainvar->curve);
        write_mballs   (wd, &mainvar->mball);
@@ -2891,7 +2957,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
        /* open temporary file, so we preserve the original in case we crash */
        BLI_snprintf(tempname, sizeof(tempname), "%s@", filepath);
 
-       file = BLI_open(tempname,O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
+       file = BLI_open(tempname, O_BINARY+O_WRONLY+O_CREAT+O_TRUNC, 0666);
        if (file == -1) {
                BKE_reportf(reports, RPT_ERROR, "Can't open file %s for writing: %s.", tempname, strerror(errno));
                return 0;
@@ -2929,7 +2995,7 @@ int BLO_write_file(Main *mainvar, const char *filepath, int write_flags, ReportL
                makeFilesRelative(mainvar, filepath, NULL); /* note, making relative to something OTHER then G.main->name */
 
        /* actual file writing */
-       err= write_file_handle(mainvar, file, NULL,NULL, write_user_block, write_flags, thumb);
+       err= write_file_handle(mainvar, file, NULL, NULL, write_user_block, write_flags, thumb);
        close(file);
 
        if (err) {