Bugfix; appending with using relative paths made all dynamic links from
authorTon Roosendaal <ton@blender.org>
Tue, 25 Oct 2005 18:22:34 +0000 (18:22 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 25 Oct 2005 18:22:34 +0000 (18:22 +0000)
other libraries local.

Also added some securities in the temporal 'sync pose' testing code. It now
asks with a menu to confirm the object to be replaced too. Later more!

source/blender/blenloader/intern/readfile.c
source/blender/src/filesel.c

index d139af27d2551c64d78583acfd51582287a74679..84ac4bae323ed59975fbcc839995b8dfcb1b0cf2 100644 (file)
@@ -5846,7 +5846,6 @@ void BLO_library_append(SpaceFile *sfile, char *dir, int idcode)
        BLI_strncpy(filename, G.sce, sizeof(filename));
        BLI_strncpy(G.sce, fd->filename, sizeof(filename));             // already opened file, to reconstruct relative paths
        
-       
        if(sfile->flag & FILE_AUTOSELECT) scene_deselect_all(G.scene);
 
        fd->mainlist.first= fd->mainlist.last= G.main;
@@ -5893,7 +5892,12 @@ void BLO_library_append(SpaceFile *sfile, char *dir, int idcode)
                sfile->libfiledata= 0;
        }
        
-       if(sfile->flag & FILE_STRINGCODE) BLI_makestringcode(filename, mainl->curlib->name);    // uses old .blend file as reference
+       if(sfile->flag & FILE_STRINGCODE) {
+               /* uses old .blend file (*filename) as reference */
+               BLI_makestringcode(filename, mainl->curlib->name);
+               /* the caller checks for appended library, so we make sure names match */
+               BLI_strncpy(dir, mainl->curlib->name, sizeof(mainl->curlib->name));
+       }
        
        if(sfile->flag & FILE_ATCURSOR) {
                centerbase= (G.scene->base.first);
index 96178d2f20c9d0f3909fadd40adaa00264e7a1a4..c87c8a63693cf694dc019cfb75e98bff02df08a8 100644 (file)
@@ -2264,37 +2264,44 @@ static void do_sync_pose(Library *lib)
                if(ob->type==OB_ARMATURE && ob->id.lib==lib)
                        break;
        
-       if(ob==NULL || ob->pose==NULL)
+       if(ob==NULL || ob->pose==NULL) {
                error("No pose appended");
+               return;
+       }
        
        arm= ob->data;
 
        /* for all visible objects in this scene */
        for(base= G.scene->base.first; base; base= base->next) {
-               if((base->flag & SELECT) || (base->object->flag & OB_POSEMODE)) {
+               if((base->flag & SELECT)) {
                        obt= base->object;
                        if(obt->type==OB_ARMATURE && obt->pose && ob!=obt) {
-                               bPoseChannel *chan;
-                               bArmature *oldarm= obt->data;
-                               
-                               /* link armature */
-                               oldarm->id.us--;
-                               obt->data= arm;
-                               arm->id.us++;
+                               char str[128];
                                
-                               /* link pose */
-                               free_pose_channels(obt->pose);
-                               MEM_freeN(obt->pose);
-                               copy_pose(&obt->pose, ob->pose, 1);
-                               
-                               /* relink */
-                               ob->id.newid= &obt->id;
-                               for (chan = obt->pose->chanbase.first; chan; chan=chan->next){
-                                       relink_constraints(&chan->constraints);
+                               sprintf(str, "Replace Object %s", obt->id.name);
+                               if(okee(str)) {
+                                       bPoseChannel *chan;
+                                       bArmature *oldarm= obt->data;
+                                       
+                                       /* link armature */
+                                       oldarm->id.us--;
+                                       obt->data= arm;
+                                       arm->id.us++;
+                                       
+                                       /* link pose */
+                                       free_pose_channels(obt->pose);
+                                       MEM_freeN(obt->pose);
+                                       copy_pose(&obt->pose, ob->pose, 1);
+                                       
+                                       /* relink */
+                                       ob->id.newid= &obt->id;
+                                       for (chan = obt->pose->chanbase.first; chan; chan=chan->next){
+                                               relink_constraints(&chan->constraints);
+                                       }
+                                       
+                                       obt->pose->flag |= POSE_RECALC;
+                                       obt->recalc |= OB_RECALC_DATA;
                                }
-                               
-                               obt->pose->flag |= POSE_RECALC;
-                               obt->recalc |= OB_RECALC_DATA;
                        }
                }
        }
@@ -2308,6 +2315,8 @@ static void do_sync_pose(Library *lib)
        if(base) {
                free_and_unlink_base(base);
        }
+
+       DAG_scene_sort(G.scene);        // for accidentally appended other objects
 }
 
 static void do_library_append(SpaceFile *sfile)
@@ -2327,7 +2336,7 @@ static void do_library_append(SpaceFile *sfile)
                Object *ob;
                int idcode = groupname_to_code(group);
                
-               BLO_library_append(sfile, dir, idcode);
+               BLO_library_append(sfile, dir, idcode); /* warning; if relative, it changes the *dir to relative path */
 
                /* DISPLISTS? */
                ob= G.main->object.first;
@@ -2338,9 +2347,6 @@ static void do_library_append(SpaceFile *sfile)
                        ob= ob->id.next;
                }
        
-               /* in sfile->dir is the whole lib name */
-               strcpy(G.lib, sfile->dir);
-               
                /* and now find the latest append lib file */
                lib= G.main->library.first;
                while(lib) {
@@ -2348,12 +2354,16 @@ static void do_library_append(SpaceFile *sfile)
                        lib= lib->id.next;
                }
                
-               if(sfile->flag & FILE_SYNCPOSE)
-                       do_sync_pose(lib);
-               if((sfile->flag & FILE_LINK)==0) 
-                       all_local(lib);
+               if(lib) {
+                       if(sfile->flag & FILE_SYNCPOSE)
+                               do_sync_pose(lib);
+                       if((sfile->flag & FILE_LINK)==0) 
+                               all_local(lib);
+               }
+               
+               /* in sfile->dir is the whole lib name */
+               strcpy(G.lib, sfile->dir);
                
-               DAG_scene_sort(G.scene);
        }
 }