[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14860] branches/apricot/source/blender: basic support for browsing libraries from the outliner, clicking on a group links it in and applies it to the active object as a dupli or adds the object if none are

Campbell Barton ideasman42 at gmail.com
Fri May 16 01:49:43 CEST 2008


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

Log Message:
-----------
basic support for browsing libraries from the outliner, clicking on a group links it in and applies it to the active object as a dupli or adds the object if none are 
active.
also made dupligroup drawing use the most basic drawtype from teh dupli of the object that instances it. this is so apricot can have low poly objects as lods but not 
have overlaping rendering.

Modified Paths:
--------------
    branches/apricot/source/blender/blenkernel/BKE_utildefines.h
    branches/apricot/source/blender/blenkernel/intern/library.c
    branches/apricot/source/blender/blenloader/intern/readfile.c
    branches/apricot/source/blender/blenloader/intern/writefile.c
    branches/apricot/source/blender/include/BIF_outliner.h
    branches/apricot/source/blender/src/drawview.c
    branches/apricot/source/blender/src/outliner.c

Modified: branches/apricot/source/blender/blenkernel/BKE_utildefines.h
===================================================================
--- branches/apricot/source/blender/blenkernel/BKE_utildefines.h	2008-05-15 23:33:30 UTC (rev 14859)
+++ branches/apricot/source/blender/blenkernel/BKE_utildefines.h	2008-05-15 23:49:43 UTC (rev 14860)
@@ -55,6 +55,8 @@
 #define ELEM7(a, b, c, d, e, f, g, h)   ( ELEM3(a, b, c, d) || ELEM4(a, e, f, g, h) )
 #define ELEM8(a, b, c, d, e, f, g, h, i)        ( ELEM4(a, b, c, d, e) || ELEM4(a, f, g, h, i) )
 #define ELEM9(a, b, c, d, e, f, g, h, i, j)        ( ELEM4(a, b, c, d, e) || ELEM5(a, f, g, h, i, j) )
+#define ELEM10(a, b, c, d, e, f, g, h, i, j, k)        ( ELEM4(a, b, c, d, e) || ELEM6(a, f, g, h, i, j, k) )
+#define ELEM11(a, b, c, d, e, f, g, h, i, j, k, l)        ( ELEM4(a, b, c, d, e) || ELEM7(a, f, g, h, i, j, k, l) )
 
 /* shift around elements */
 #define SHIFT3(type, a, b, c) { type tmp; tmp = a; a = c; c = b; b = tmp; }

Modified: branches/apricot/source/blender/blenkernel/intern/library.c
===================================================================
--- branches/apricot/source/blender/blenkernel/intern/library.c	2008-05-15 23:33:30 UTC (rev 14859)
+++ branches/apricot/source/blender/blenkernel/intern/library.c	2008-05-15 23:49:43 UTC (rev 14860)
@@ -421,6 +421,11 @@
 
 static void free_library(Library *lib)
 {
+	/* outliner uses this */
+	if (lib->filedata) {
+		blo_freefiledata(lib->filedata);
+		lib->filedata = NULL;
+	}
     /* no freeing needed for libraries yet */
 }
 

Modified: branches/apricot/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/apricot/source/blender/blenloader/intern/readfile.c	2008-05-15 23:33:30 UTC (rev 14859)
+++ branches/apricot/source/blender/blenloader/intern/readfile.c	2008-05-15 23:49:43 UTC (rev 14860)
@@ -960,7 +960,7 @@
 FileData *blo_openblenderfile(char *name, BlendReadError *error_r)
 {
 	gzFile gzfile;
-	
+	printf("opening: blo_openblenderfile '%s'\n", name);
 	gzfile= gzopen(name, "rb");
 
 	if (NULL == gzfile) {
@@ -1011,6 +1011,8 @@
 
 void blo_freefiledata(FileData *fd)
 {
+	printf("freeing: blo_freefiledata '%s'\n", fd->filename);
+	
 	if (fd) {
 		
 		if (fd->filedes != -1) {
@@ -8982,8 +8984,12 @@
 		if(mainptr->curlib->filedata)
 			lib_link_all(mainptr->curlib->filedata, mainptr);
 		
+		/* APRICOT HACK */
+		/* Experement with keeping the file open, the outliner can then browse it */
+		/*
 		if(mainptr->curlib->filedata) blo_freefiledata(mainptr->curlib->filedata);
 		mainptr->curlib->filedata= NULL;
+		*/
 	}
 }
 

Modified: branches/apricot/source/blender/blenloader/intern/writefile.c
===================================================================
--- branches/apricot/source/blender/blenloader/intern/writefile.c	2008-05-15 23:33:30 UTC (rev 14859)
+++ branches/apricot/source/blender/blenloader/intern/writefile.c	2008-05-15 23:49:43 UTC (rev 14860)
@@ -1717,12 +1717,20 @@
 		}
 
 		if(foundone) {
-			writestruct(wd, ID_LI, "Library", 1, main->curlib);
-
-			while(a--) {
-				for(id= lbarray[a]->first; id; id= id->next) {
-					if(id->us>0 && (id->flag & LIB_EXTERN)) {
-						writestruct(wd, ID_ID, "ID", 1, id);
+			/* this should always be true */
+			if (main->curlib) {
+				void *fd = main->curlib->filedata; /* This is not nice, but we cant save filedata pointers */
+				main->curlib->filedata = NULL; 
+				
+				writestruct(wd, ID_LI, "Library", 1, main->curlib);
+				
+				main->curlib->filedata = fd;
+				
+				while(a--) {
+					for(id= lbarray[a]->first; id; id= id->next) {
+						if(id->us>0 && (id->flag & LIB_EXTERN)) {
+							writestruct(wd, ID_ID, "ID", 1, id);
+						}
 					}
 				}
 			}

Modified: branches/apricot/source/blender/include/BIF_outliner.h
===================================================================
--- branches/apricot/source/blender/include/BIF_outliner.h	2008-05-15 23:33:30 UTC (rev 14859)
+++ branches/apricot/source/blender/include/BIF_outliner.h	2008-05-15 23:49:43 UTC (rev 14860)
@@ -77,6 +77,8 @@
 #define TSE_LINKED_LAMP		23
 #define TSE_POSEGRP_BASE	24
 #define TSE_POSEGRP			25
+#define TSE_LIBRARY_MEMBER_BASE	26
+#define TSE_LIBRARY_MEMBER		27
 
 /* outliner search flags */
 #define OL_FIND					0

Modified: branches/apricot/source/blender/src/drawview.c
===================================================================
--- branches/apricot/source/blender/src/drawview.c	2008-05-15 23:33:30 UTC (rev 14859)
+++ branches/apricot/source/blender/src/drawview.c	2008-05-15 23:49:43 UTC (rev 14860)
@@ -2752,7 +2752,8 @@
 			tbase.object= dob->ob;
 			
 			/* extra service: draw the duplicator in drawtype of parent */
-			dt= tbase.object->dt; tbase.object->dt= base->object->dt;
+			/* MIN2 for the drawtype to allow bounding box objects in groups for lods */
+			dt= tbase.object->dt;	tbase.object->dt= MIN2(tbase.object->dt, base->object->dt);
 			dtx= tbase.object->dtx; tbase.object->dtx= base->object->dtx;
 			
 			/* negative scale flag has to propagate */

Modified: branches/apricot/source/blender/src/outliner.c
===================================================================
--- branches/apricot/source/blender/src/outliner.c	2008-05-15 23:33:30 UTC (rev 14859)
+++ branches/apricot/source/blender/src/outliner.c	2008-05-15 23:49:43 UTC (rev 14860)
@@ -56,8 +56,10 @@
 #include "DNA_texture_types.h"
 #include "DNA_text_types.h"
 #include "DNA_world_types.h"
+#include "DNA_sdna_types.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_linklist.h"
 
 #include "BKE_constraint.h"
 #include "BKE_deform.h"
@@ -112,7 +114,7 @@
 #include "BSE_drawipo.h"
 #include "BSE_edit.h"
 #include "BSE_view.h"
-
+#include "BLO_readfile.h"
 #include "PIL_time.h" 
 
 #include "blendef.h"
@@ -537,7 +539,55 @@
 	}
 
 }
+/* APRICOT HACK */
+extern struct BHead *blo_firstbhead(struct FileData *fd);
+extern struct BHead *blo_nextbhead(struct FileData *fd, struct BHead *thisblock);
+extern struct BHead *blo_prevbhead(struct FileData *fd, struct BHead *thisblock);
+extern char *bhead_id_name(struct FileData *fd, struct BHead *bhead);
 
+static void outliner_add_lib_contents(SpaceOops *soops, ListBase *lb, Library *lib, TreeElement *te)
+{
+	LinkNode *l = NULL, *names = NULL;
+	char *blockname;
+	int blocktype = 0;
+	
+	
+	if (!lib->filedata) {
+		lib->filedata = BLO_blendhandle_from_file(lib->filename);
+	}
+	
+	if (!lib->filedata) {
+		return;
+	}
+	
+	names = BLO_blendhandle_get_linkable_groups( lib->filedata );
+	if( !names ) return;	
+		
+	for( l = names; l; l = l->next ) {
+		blocktype = ( int ) BLO_idcode_from_name( ( char * ) l->link );
+		blockname =  BLO_idcode_to_name( blocktype );
+		
+		TreeElement *tenla= outliner_add_element(soops, lb, lib, te, TSE_LIBRARY_MEMBER_BASE, 0);
+		
+		tenla->name = blockname; /* Use this because blockname is free'd */
+		
+		{
+			BHead *bhead;
+			for (bhead= blo_firstbhead(lib->filedata); bhead; bhead= blo_nextbhead(lib->filedata, bhead)) {
+				if (bhead->code==blocktype) {
+					char *idname= bhead_id_name(lib->filedata, bhead);
+					TreeElement *tenlay = outliner_add_element(soops, &tenla->subtree, lib, tenla, TSE_LIBRARY_MEMBER, 0);
+					tenlay->name= idname+2;
+				} else if (bhead->code==ENDB)
+					break;
+			}
+		}
+		
+	}
+	BLI_linklist_free( names, free );	/* free linklist *and* each node's data */
+}
+
+
 static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *idv, 
 										 TreeElement *parent, short type, short index)
 {
@@ -569,6 +619,9 @@
 		switch(GS(id->name)) {
 		case ID_LI:
 			te->name= ((Library *)id)->name;
+			if(soops->outlinevis == SO_LIBRARIES) {
+				outliner_add_lib_contents(soops, &te->subtree, (Library *)id, te);
+			}
 			break;
 		case ID_SCE:
 			outliner_add_scene_contents(soops, &te->subtree, (Scene *)id, te);
@@ -1845,6 +1898,100 @@
 	return 0;
 }
 
+static int tree_element_active_linked_data(TreeElement *te, TreeStoreElem *tselem, int set)
+{
+	Library *lib = (Library *)tselem->id;
+	
+	if (strcmp(te->parent->name, "Group")==0) {
+		if (set) {
+			Object *ob = OBACT;
+			Group *group_iter;
+			BlendHandle  *bh = NULL;
+			//printf("%s\n", te->name);
+		
+			/* first see if we have the group alredy */
+			for(group_iter = G.main->group.first;  group_iter; group_iter = group_iter->id.next )
+				if ((group_iter->id.lib == lib) && (strcmp(group_iter->id.name+2, te->name)==0) )
+					break;
+		
+			if (!group_iter) {
+			
+				if (!lib->filedata) {
+					lib->filedata = BLO_blendhandle_from_file(lib->filename);
+				}
+				bh = (BlendHandle *)lib->filedata;
+			
+				/* import from the libary */
+				BLO_script_library_append( &bh, lib->filename, te->name, ID_GR, FILE_LINK, G.scene );
+			
+				for(group_iter = G.main->group.first;  group_iter; group_iter = group_iter->id.next )
+					if ((group_iter->id.lib == lib) && (strcmp(group_iter->id.name+2, te->name)==0) )
+						break;
+			}
+		
+			if (!ob) {
+				Base *base;
+				/* add an empty */
+				ob = add_only_object(OB_EMPTY, te->name);
+				ob->flag = SELECT;
+			
+			
+				/* 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);
+				base->flag = SELECT;
+				ob->id.us = 1; /* we will exist once in this scene */
+
+				BLI_addhead( &(G.scene->base), base );	/* finally, link new base to scene */
+				VECCOPY(ob->loc, G.scene->cursor);
+				VECCOPY(ob->obmat[3], G.scene->cursor);
+				ob->transflag |= OB_DUPLIGROUP;
+			}
+		
+			if (group_iter) {
+				if (ob->dup_group)
+					ob->dup_group->id.us--;
+				ob->dup_group = group_iter;
+				group_iter->id.us++;
+			}
+		
+	
+		
+			allqueue(REDRAWALL, 0);	
+		
+			return 1;
+		} else {
+			Object *ob = OBACT;
+			if (ob && ob->dup_group && (ob->transflag & OB_DUPLIGROUP) && (ob->dup_group->id.lib == lib) && strcmp(ob->dup_group->id.name+2, te->name )==0) return 1;
+		}
+	} else {
+		/* Unknown linkable type */
+		if (set) {
+			BlendHandle  *bh = NULL;
+			
+			if (!lib->filedata) {
+				lib->filedata = BLO_blendhandle_from_file(lib->filename);
+			}
+			bh = (BlendHandle *)lib->filedata;
+			
+			/* import from the libary */
+			BLO_script_library_append( &bh, lib->filename, te->name, BLO_idcode_from_name(te->parent->name), FILE_LINK, G.scene );
+		
+			allqueue(REDRAWALL, 0);	
+		
+			return 1;
+		} else {
+			return 0; /* unknown, not active */
+		}
+	
+	
+	}
+	return 0;
+}
+
+
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list