[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14871] branches/apricot/source/blender/ src: added library loading where you can select many libraries or a directory of libs and load them without appending or linking anything .

Campbell Barton ideasman42 at gmail.com
Fri May 16 22:21:41 CEST 2008


Revision: 14871
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14871
Author:   campbellbarton
Date:     2008-05-16 22:21:40 +0200 (Fri, 16 May 2008)

Log Message:
-----------
added library loading where you can select many libraries or a directory of libs and load them without appending or linking anything.
This is so the outliner can be used to link in data from existing libraries without having to open each blend file.

Modified Paths:
--------------
    branches/apricot/source/blender/src/filesel.c
    branches/apricot/source/blender/src/header_oops.c
    branches/apricot/source/blender/src/outliner.c

Modified: branches/apricot/source/blender/src/filesel.c
===================================================================
--- branches/apricot/source/blender/src/filesel.c	2008-05-16 17:36:06 UTC (rev 14870)
+++ branches/apricot/source/blender/src/filesel.c	2008-05-16 20:21:40 UTC (rev 14871)
@@ -2276,13 +2276,122 @@
 	return 1;
 }
 
+
+
+/* APRICOT HACK */
+static int library_load_blend(char *path, int rel)
+{
+	Library *lib;
+	if (!BLI_testextensie(path, ".blend")) {
+		return 0;
+	} else {
+		char otherpath[FILE_MAX]; /* path of loaded lib */
+		
+		/* First deal with the blend file we have */
+		BLI_strncpy(otherpath, G.sce, FILE_MAX);
+		BLI_cleanup_file(G.sce, path);
+		
+		if (strcmp(path, otherpath)==0) {
+			return 0; /* cant load this  blend file!! */
+		}
+		
+		BLI_cleanup_file(G.sce, otherpath);
+		
+		/* Check if we need to load the lib */
+		for(lib= G.main->library.first; lib; lib= lib->id.next) {
+			BLI_strncpy(otherpath, lib->name, FILE_MAX);
+			BLI_cleanup_file(G.sce, otherpath);
+			
+			if (strcmp(path, otherpath)==0) {
+				return 0; /* cant load this  blend file!! */
+			}
+		}
+		
+	}
+	
+	lib= alloc_libblock(&G.main->library, ID_LI, "lib");
+	strncpy(lib->name, path, sizeof(lib->name)-1);
+	BLI_strncpy(lib->filename, path, sizeof(lib->filename));
+	
+	if (rel) {
+		BLI_convertstringcode(lib->name, G.sce);
+	}
+	return 1;
+}
+
+
+static int library_load_blends(SpaceFile *sfile)
+{
+	int a, ok=0;
+	for(a=0; a<sfile->totfile; a++) {
+		if(sfile->filelist[a].flags & ACTIVE) {
+			if( (sfile->filelist[a].type & S_IFDIR) && BLI_testextensie(sfile->filelist[a].relname, ".blend")) { /* a blend file is a DIR. odd */
+				char name[FILE_MAX];
+				BLI_join_dirfile(name, sfile->dir, sfile->filelist[a].relname);
+				ok += library_load_blend(name, sfile->flag & FILE_STRINGCODE);
+			}
+		}
+	}
+	return ok;
+}
+
+
+static int library_load_recursive(SpaceFile *sfile, char *dir, char *group)
+{
+	struct direntry *files;
+	int a, totfile, ok=0;
+
+	waitcursor(1);
+
+	/* also read contents of directories */
+	files= sfile->filelist;
+	totfile= sfile->totfile;
+	sfile->filelist= 0;
+	sfile->totfile= 0;
+
+	for(a=0; a<totfile; a++) {
+		if(files[a].flags & ACTIVE) {
+			if( (files[a].type & S_IFDIR) ) {
+				if (BLI_testextensie(files[a].relname, ".blend")) {
+					char name[FILE_MAX];
+					BLI_join_dirfile(name, sfile->dir, files[a].relname);
+					ok += library_load_blend(name, sfile->flag & FILE_STRINGCODE);
+				} else {
+					strncat(sfile->dir, files[a].relname, FILE_MAXFILE-1);
+					strcat(sfile->dir,"/");
+					read_dir(sfile);
+	
+					/* select all */
+					swapselect_file(sfile);
+					
+					ok += library_load_blends(sfile);
+					
+					parent(sfile);
+				}
+			}
+		}
+	}
+
+	sfile->filelist= files;
+	sfile->totfile= totfile;
+
+	waitcursor(0);
+	if (ok) {
+		BIF_undo_push("Load Libraries");
+		return 1;
+	}
+	return 0;
+}
+/* END APRICOT HACK */
+
 static void do_library_append(SpaceFile *sfile)
 {
 	Library *lib;
 	char dir[FILE_MAX], group[GROUP_MAX];
 	
 	if ( is_a_library(sfile, dir, group)==0 ) {
-		error("Not a library");
+		if (!library_load_recursive(sfile, dir, group))
+			error("Not a library");
 	} else if (!sfile->libfiledata) {
 		error("Library not loaded");
 	} else if (group[0]==0) {
@@ -2329,7 +2438,9 @@
 		BLI_strncpy(G.lib, sfile->dir, sizeof(G.lib) );
 	}
 }
+/* END APRICOT HACK */
 
+
 static void library_to_filelist(SpaceFile *sfile)
 {
 	LinkNode *l, *names;

Modified: branches/apricot/source/blender/src/header_oops.c
===================================================================
--- branches/apricot/source/blender/src/header_oops.c	2008-05-16 17:36:06 UTC (rev 14870)
+++ branches/apricot/source/blender/src/header_oops.c	2008-05-16 20:21:40 UTC (rev 14871)
@@ -280,7 +280,7 @@
 			uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Show Restriction Columns", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
 		
 		if(soops->outlinevis == SO_LIBRARIES) {
-			uiDefIconTextBlockBut(block, oops_viewmenu_showtypes, NULL, ICON_RIGHTARROW_THIN, "Show Library Types", 0, yco-=20, 120, 19, "");
+			uiDefIconTextBlockBut(block, oops_viewmenu_showtypes, NULL, ICON_RIGHTARROW_THIN, "Show Library Types (Ctrl for solo)", 0, yco-=20, 120, 19, "");
 		}
 		
 		uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");

Modified: branches/apricot/source/blender/src/outliner.c
===================================================================
--- branches/apricot/source/blender/src/outliner.c	2008-05-16 17:36:06 UTC (rev 14870)
+++ branches/apricot/source/blender/src/outliner.c	2008-05-16 20:21:40 UTC (rev 14871)
@@ -57,6 +57,7 @@
 #include "DNA_text_types.h"
 #include "DNA_world_types.h"
 #include "DNA_sdna_types.h"
+#include "DNA_view3d_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"
@@ -73,6 +74,7 @@
 #include "BKE_screen.h"
 #include "BKE_scene.h"
 #include "BKE_utildefines.h"
+#include "BKE_object.h"
 
 #ifdef WITH_VERSE
 #include "BKE_verse.h"
@@ -588,13 +590,6 @@
 			continue;
 		}
 		
-#define OOPS_WO		1<<15
-#define OOPS_AC		1<<16
-#define OOPS_CA		1<<17
-#define OOPS_TXT	1<<18
-		
-		
-		
 		blockname =  BLO_idcode_to_name( blocktype );
 		
 		TreeElement *tenla= outliner_add_element(soops, lb, lib, te, TSE_LIBRARY_MEMBER_BASE, 0);
@@ -1958,8 +1953,8 @@
 					if ((group_iter->id.lib == lib) && (strcmp(group_iter->id.name+2, te->name)==0) )
 						break;
 			}
-		
-			if (!ob) {
+			
+			if (!ob || ob->type!=OB_EMPTY) {
 				Base *base;
 				/* add an empty */
 				ob = add_only_object(OB_EMPTY, te->name);
@@ -1969,7 +1964,18 @@
 				/* link to scene */
 				base = MEM_callocN( sizeof( Base ), "pynewbase" );
 				base->object = ob;	/* link object to the new base */
-				base->lay= ob->lay = G.scene->lay & ((1<<20)-1);
+				
+				if (G.vd) {
+					if (G.vd->localview) {
+						ob->lay = G.vd->layact + G.vd->lay;
+					} else {
+						ob->lay= G.vd->layact;
+					}
+				} else {
+					ob->lay = G.scene->lay & ((1<<20)-1);
+				}
+				base->lay = ob->lay;
+				
 				base->flag = SELECT;
 				ob->id.us = 1; /* we will exist once in this scene */
 
@@ -1985,9 +1991,6 @@
 				ob->dup_group = group_iter;
 				group_iter->id.us++;
 			}
-		
-	
-		
 			allqueue(REDRAWALL, 0);	
 		
 			return 1;





More information about the Bf-blender-cvs mailing list