Merging r44140 through r44226 from trunk into soc-2011-tomato
[blender.git] / source / blender / blenloader / intern / readfile.c
index 27a0ddd..d50a063 100644 (file)
@@ -97,9 +97,9 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
-#include "BLI_utildefines.h"
 
 #include "BKE_anim.h"
 #include "BKE_action.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
 #include "BKE_sequencer.h"
+#include "BKE_text.h" // for txt_extended_ascii_as_utf8
 #include "BKE_texture.h" // for open_plugin_tex
 #include "BKE_tracking.h"
 #include "BKE_utildefines.h" // SWITCH_INT DATA ENDB DNA1 O_BINARY GLOB USER TEST REND
@@ -3837,7 +3838,7 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
        
        if((fd->flags & FD_FLAGS_SWITCH_ENDIAN) && mesh->tface) {
                TFace *tf= mesh->tface;
-               unsigned int i;
+               int i;
 
                for (i=0; i< (mesh->totface); i++, tf++) {
                        SWITCH_INT(tf->col[0]);
@@ -4714,7 +4715,7 @@ static void lib_link_scene(FileData *fd, Main *main)
                        link_paint(fd, sce, &sce->toolsettings->vpaint->paint);
                        link_paint(fd, sce, &sce->toolsettings->wpaint->paint);
                        link_paint(fd, sce, &sce->toolsettings->imapaint.paint);
-
+                       link_paint(fd, sce, &sce->toolsettings->uvsculpt->paint);
                        sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
 
                        for(base= sce->base.first; base; base= next) {
@@ -4768,8 +4769,8 @@ static void lib_link_scene(FileData *fd, Main *main)
                        (void)marker;
 #endif
 
-                       if(sce->ed)
-                               seq_update_muting(sce->ed);
+                       seq_update_muting(sce->ed);
+                       seq_update_sound_bounds_all(sce);
                        
                        if(sce->nodetree) {
                                lib_link_ntree(fd, &sce->id, sce->nodetree);
@@ -4844,6 +4845,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
                direct_link_paint(fd, (Paint**)&sce->toolsettings->sculpt);
                direct_link_paint(fd, (Paint**)&sce->toolsettings->vpaint);
                direct_link_paint(fd, (Paint**)&sce->toolsettings->wpaint);
+               direct_link_paint(fd, (Paint**)&sce->toolsettings->uvsculpt);
 
                sce->toolsettings->imapaint.paintcursor= NULL;
                sce->toolsettings->particle.paintcursor= NULL;
@@ -5160,7 +5162,6 @@ static void lib_link_screen(FileData *fd, Main *main)
                                        }
                                        else if(sl->spacetype==SPACE_BUTS) {
                                                SpaceButs *sbuts= (SpaceButs *)sl;
-                                               sbuts->ri= NULL;
                                                sbuts->pinid= newlibadr(fd, sc->id.lib, sbuts->pinid);
                                                sbuts->mainbo= sbuts->mainb;
                                                sbuts->mainbuser= sbuts->mainb;
@@ -5272,6 +5273,7 @@ static void lib_link_screen(FileData *fd, Main *main)
                                                sclip->clip= newlibadr_us(fd, sc->id.lib, sclip->clip);
 
                                                sclip->scopes.track_preview = NULL;
+                                               sclip->draw_context = NULL;
                                                sclip->scopes.ok = 0;
                                        }
                                }
@@ -5308,6 +5310,30 @@ static void *restore_pointer_by_name(Main *mainp, ID *id, int user)
        return NULL;
 }
 
+static int lib_link_seq_clipboard_cb(Sequence *seq, void *arg_pt)
+{
+       Main *newmain = (Main *)arg_pt;
+
+       if(seq->sound) {
+               seq->sound = restore_pointer_by_name(newmain, (ID *)seq->sound, 0);
+               seq->sound->id.us++;
+       }
+
+       if(seq->scene)
+               seq->scene = restore_pointer_by_name(newmain, (ID *)seq->scene, 1);
+
+       if(seq->scene_camera)
+               seq->scene_camera = restore_pointer_by_name(newmain, (ID *)seq->scene_camera, 1);
+
+       return 1;
+}
+
+static void lib_link_clipboard_restore(Main *newmain)
+{
+       /* update IDs stored in sequencer clipboard */
+       seqbase_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, newmain);
+}
+
 /* called from kernel/blender.c */
 /* used to link a file (without UI) to the current UI */
 /* note that it assumes the old pointers in UI are still valid, so old Main is not freed */
@@ -5515,6 +5541,9 @@ void lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
                        sa= sa->next;
                }
        }
+
+       /* update IDs stored in all possible clipboards */
+       lib_link_clipboard_restore(newmain);
 }
 
 static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
@@ -6022,6 +6051,8 @@ static void direct_link_movieclip(FileData *fd, MovieClip *clip)
        MovieTracking *tracking= &clip->tracking;
        MovieTrackingObject *object;
 
+       clip->adt= newdataadr(fd, clip->adt);
+
        if(fd->movieclipmap) clip->cache= newmclipadr(fd, clip->cache);
        else clip->cache= NULL;
 
@@ -6059,6 +6090,9 @@ static void lib_link_movieclip(FileData *fd, Main *main)
        clip= main->movieclip.first;
        while(clip) {
                if(clip->id.flag & LIB_NEEDLINK) {
+                       if (clip->adt)
+                               lib_link_animdata(fd, &clip->id, clip->adt);
+
                        clip->gpd= newlibadr_us(fd, clip->id.lib, clip->gpd);
 
                        clip->id.flag -= LIB_NEEDLINK;
@@ -6560,14 +6594,14 @@ static void customdata_version_242(Mesh *me)
                if (layer->type == CD_MTFACE) {
                        if (layer->name[0] == 0) {
                                if (mtfacen == 0) strcpy(layer->name, "UVMap");
-                               else sprintf(layer->name, "UVMap.%.3d", mtfacen);
+                               else BLI_snprintf(layer->name, sizeof(layer->name), "UVMap.%.3d", mtfacen);
                        }
                        mtfacen++;
                }
                else if (layer->type == CD_MCOL) {
                        if (layer->name[0] == 0) {
                                if (mcoln == 0) strcpy(layer->name, "Col");
-                               else sprintf(layer->name, "Col.%.3d", mcoln);
+                               else BLI_snprintf(layer->name, sizeof(layer->name), "Col.%.3d", mcoln);
                        }
                        mcoln++;
                }
@@ -7464,15 +7498,16 @@ static void do_versions_nodetree_convert_angle(bNodeTree *ntree)
 
 void do_versions_image_settings_2_60(Scene *sce)
 {
-       /* note: rd->subimtype is moved into indervidual settings now and no longer
+       /* note: rd->subimtype is moved into individual settings now and no longer
         * exists */
        RenderData *rd= &sce->r;
        ImageFormatData *imf= &sce->r.im_format;
 
-       imf->imtype= rd->imtype;
-       imf->planes= rd->planes;
-       imf->compress= rd->quality;
-       imf->quality= rd->quality;
+       /* we know no data loss happens here, the old values were in char range */
+       imf->imtype=   (char)rd->imtype;
+       imf->planes=   (char)rd->planes;
+       imf->compress= (char)rd->quality;
+       imf->quality=  (char)rd->quality;
 
        /* default, was stored in multiple places, may override later */
        imf->depth= R_IMF_CHAN_DEPTH_8;
@@ -7547,6 +7582,32 @@ static void do_versions_nodetree_socket_use_flags_2_62(bNodeTree *ntree)
        }
 }
 
+/* set the SOCK_AUTO_HIDDEN flag on collapsed nodes */
+static void do_versions_nodetree_socket_auto_hidden_flags_2_62(bNodeTree *ntree)
+{
+       bNode *node;
+       bNodeSocket *sock;
+       
+       for (node=ntree->nodes.first; node; node=node->next) {
+               if (node->flag & NODE_HIDDEN) {
+                       for (sock=node->inputs.first; sock; sock=sock->next) {
+                               if (sock->link==NULL)
+                                       sock->flag |= SOCK_AUTO_HIDDEN;
+                       }
+                       for(sock=node->outputs.first; sock; sock= sock->next) {
+                               if(nodeCountSocketLinks(ntree, sock)==0)
+                                       sock->flag |= SOCK_AUTO_HIDDEN;
+                       }
+               }
+               else {
+                       for(sock=node->inputs.first; sock; sock= sock->next)
+                               sock->flag &= ~SOCK_AUTO_HIDDEN;
+                       for(sock=node->outputs.first; sock; sock= sock->next)
+                               sock->flag &= ~SOCK_AUTO_HIDDEN;
+               }
+       }
+}
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
        /* WATCH IT!!!: pointers from libdata have not been converted */
@@ -9036,8 +9097,9 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                                        strcpy(kb->name, "Basis");
                                        }
                                        else {
-                                               if(kb->name[0]==0)
-                                                       sprintf(kb->name, "Key %d", index);
+                                               if (kb->name[0]==0) {
+                                                       BLI_snprintf(kb->name, sizeof(kb->name), "Key %d", index);
+                                               }
                                                kb->adrcode= index++;
                                        }
                                }
@@ -10030,7 +10092,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                BLI_addtail(&ob->particlesystem, psys);
 
                                md= modifier_new(eModifierType_ParticleSystem);
-                               sprintf(md->name, "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
+                               BLI_snprintf(md->name, sizeof(md->name), "ParticleSystem %i", BLI_countlist(&ob->particlesystem));
                                psmd= (ParticleSystemModifierData*) md;
                                psmd->psys=psys;
                                BLI_addtail(&ob->modifiers, md);
@@ -10877,7 +10939,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                        sce->gm.dome.warptext = sce->r.dometext;
 
                        //Stand Alone
-                       sce->gm.fullscreen = sce->r.fullscreen;
+                       sce->gm.playerflag |= (sce->r.fullscreen?GAME_PLAYER_FULLSCREEN:0);
                        sce->gm.xplay = sce->r.xplay;
                        sce->gm.yplay = sce->r.yplay;
                        sce->gm.freqplay = sce->r.freqplay;
@@ -12779,7 +12841,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
-       /* put compatibility code here until next subversion bump */
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 1))
        {
                {
                        /* update use flags for node sockets (was only temporary before) */
@@ -12879,6 +12941,149 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                }
                        }
                }
+               {
+                       /* set the SOCK_AUTO_HIDDEN flag on collapsed nodes */
+                       Scene *sce;
+                       Material *mat;
+                       Tex *tex;
+                       Lamp *lamp;
+                       World *world;
+                       bNodeTree *ntree;
+
+                       for (sce=main->scene.first; sce; sce=sce->id.next)
+                               if (sce->nodetree)
+                                       do_versions_nodetree_socket_auto_hidden_flags_2_62(sce->nodetree);
+
+                       for (mat=main->mat.first; mat; mat=mat->id.next)
+                               if (mat->nodetree)
+                                       do_versions_nodetree_socket_auto_hidden_flags_2_62(mat->nodetree);
+
+                       for (tex=main->tex.first; tex; tex=tex->id.next)
+                               if (tex->nodetree)
+                                       do_versions_nodetree_socket_auto_hidden_flags_2_62(tex->nodetree);
+
+                       for (lamp=main->lamp.first; lamp; lamp=lamp->id.next)
+                               if (lamp->nodetree)
+                                       do_versions_nodetree_socket_auto_hidden_flags_2_62(lamp->nodetree);
+
+                       for (world=main->world.first; world; world=world->id.next)
+                               if (world->nodetree)
+                                       do_versions_nodetree_socket_auto_hidden_flags_2_62(world->nodetree);
+
+                       for (ntree=main->nodetree.first; ntree; ntree=ntree->id.next)
+                               do_versions_nodetree_socket_auto_hidden_flags_2_62(ntree);
+               }
+       }
+
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 2))
+       {
+               {
+                       /* convert Camera Actuator values to defines */
+                       Object *ob;
+                       bActuator *act;
+                       for(ob = main->object.first; ob; ob= ob->id.next) {
+                               for(act= ob->actuators.first; act; act= act->next) {
+                                       if (act->type == ACT_CAMERA) {
+                                               bCameraActuator *ba= act->data;
+
+                                               if(ba->axis==(float) 'x') ba->axis=OB_POSX;
+                                               else if (ba->axis==(float)'y') ba->axis=OB_POSY;
+                                               /* don't do an if/else to avoid imediate subversion bump*/
+//                                     ba->axis=((ba->axis == (float) 'x')?OB_POSX_X:OB_POSY);
+                                       }
+                               }
+                       }
+               }
+
+               {
+                       /* convert deprecated sculpt_paint_unified_* fields to
+                          UnifiedPaintSettings */
+                       Scene *scene;
+                       for(scene= main->scene.first; scene; scene= scene->id.next) {
+                               ToolSettings *ts= scene->toolsettings;
+                               UnifiedPaintSettings *ups= &ts->unified_paint_settings;
+                               ups->size= ts->sculpt_paint_unified_size;
+                               ups->unprojected_radius= ts->sculpt_paint_unified_unprojected_radius;
+                               ups->alpha= ts->sculpt_paint_unified_alpha;
+                               ups->flag= ts->sculpt_paint_settings;
+                       }
+               }
+       }
+
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 3))
+       {
+               {
+                       /* convert extended ascii to utf-8 for text editor */
+                       Text *text;
+                       for (text= main->text.first; text; text= text->id.next)
+                               if(!(text->flags & TXT_ISEXT)) {
+                                       TextLine *tl;
+                                       
+                                       for (tl= text->lines.first; tl; tl= tl->next) {
+                                               int added= txt_extended_ascii_as_utf8(&tl->line);
+                                               tl->len+= added;
+                                               
+                                               /* reset cursor position if line was changed */
+                                               if (added && tl == text->curl)
+                                                       text->curc = 0;
+                                       }
+                               }
+               }
+               {
+                       /* set new dynamic paint values */
+                       Object *ob;
+                       for(ob = main->object.first; ob; ob = ob->id.next) {
+                               ModifierData *md;
+                               for(md= ob->modifiers.first; md; md= md->next) {
+                                       if (md->type == eModifierType_DynamicPaint) {
+                                               DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
+                                               if(pmd->canvas)
+                                               {
+                                                       DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
+                                                       for (; surface; surface=surface->next) {
+                                                               surface->color_dry_threshold = 1.0f;
+                                                               surface->influence_scale = 1.0f;
+                                                               surface->radius_scale = 1.0f;
+                                                               surface->flags |= MOD_DPAINT_USE_DRYING;
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 4))
+       {
+               {
+                       /* set fluidsim rate */
+                       Object *ob;
+                       for (ob = main->object.first; ob; ob = ob->id.next) {
+                               ModifierData *md;
+                               for (md = ob->modifiers.first; md; md = md->next) {
+                                       if (md->type == eModifierType_Fluidsim) {
+                                               FluidsimSettings *fss = (FluidsimSettings *)md;
+                                               fss->animRate = 1.0f;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       if (main->versionfile < 262)
+       {
+               Object *ob;
+               for(ob=main->object.first; ob; ob= ob->id.next) {
+                       ModifierData *md;
+
+                       for (md=ob->modifiers.first; md; md=md->next) {
+                               if (md->type==eModifierType_Cloth) {
+                                       ClothModifierData *clmd = (ClothModifierData*) md;
+                                       if(clmd->sim_parms)
+                                               clmd->sim_parms->vel_damping = 1.0f;
+                               }
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
@@ -13882,6 +14087,11 @@ static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
        expand_doit(fd, mainvar, snd->ipo); // XXX depreceated - old animation system
 }
 
+static void expand_movieclip(FileData *fd, Main *mainvar, MovieClip *clip)
+{
+       if (clip->adt)
+               expand_animdata(fd, mainvar, clip->adt);
+}
 
 static void expand_main(FileData *fd, Main *mainvar)
 {
@@ -13965,6 +14175,10 @@ static void expand_main(FileData *fd, Main *mainvar)
                                                break;
                                        case ID_PA:
                                                expand_particlesettings(fd, mainvar, (ParticleSettings *)id);
+                                               break;
+                                       case ID_MC:
+                                               expand_movieclip(fd, mainvar, (MovieClip *)id);
+                                               break;
                                        }
 
                                        doit= 1;
@@ -14340,7 +14554,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
                                        /* allow typing in a new lib path */
                                        if(G.rt==-666) {
                                                while(fd==NULL) {
-                                                       char newlib_path[240] = { 0 };
+                                                       char newlib_path[FILE_MAX] = { 0 };
                                                        printf("Missing library...'\n");
                                                        printf("        current file: %s\n", G.main->name);
                                                        printf("        absolute lib: %s\n", mainptr->curlib->filepath);