[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36868] trunk/blender/source/blender/ blenloader: BLO_library_append_named_part now returns the newly linked/ appended datablock.
Campbell Barton
ideasman42 at gmail.com
Tue May 24 17:02:47 CEST 2011
Revision: 36868
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36868
Author: campbellbarton
Date: 2011-05-24 15:02:46 +0000 (Tue, 24 May 2011)
Log Message:
-----------
BLO_library_append_named_part now returns the newly linked/appended datablock.
Modified Paths:
--------------
trunk/blender/source/blender/blenloader/BLO_readfile.h
trunk/blender/source/blender/blenloader/intern/readfile.c
Modified: trunk/blender/source/blender/blenloader/BLO_readfile.h
===================================================================
--- trunk/blender/source/blender/blenloader/BLO_readfile.h 2011-05-24 14:06:44 UTC (rev 36867)
+++ trunk/blender/source/blender/blenloader/BLO_readfile.h 2011-05-24 15:02:46 UTC (rev 36868)
@@ -224,7 +224,7 @@
* @param flag Options for linking, used for instancing.
* @return Boolean, 0 when the datablock could not be found.
*/
-int BLO_library_append_named_part(const struct bContext *C, struct Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag);
+struct ID *BLO_library_append_named_part(const struct bContext *C, struct Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag);
void BLO_library_append_end(const struct bContext *C, struct Main *mainl, BlendHandle** bh, int idcode, short flag);
void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname);
Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c 2011-05-24 14:06:44 UTC (rev 36867)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c 2011-05-24 15:02:46 UTC (rev 36868)
@@ -12804,13 +12804,13 @@
/* returns true if the item was found
* but it may already have already been appended/linked */
-static int append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *idname, int idcode, short flag)
+static ID *append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *idname, int idcode, short flag)
{
- Scene *scene= CTX_data_scene(C);
+ Scene *scene= CTX_data_scene(C); /* can be NULL */
Object *ob;
Base *base;
BHead *bhead;
- ID *id;
+ ID *id= NULL;
int endloop=0;
int found=0;
@@ -12825,7 +12825,7 @@
found= 1;
id= is_yet_read(fd, mainl, bhead);
if(id==NULL) {
- read_libblock(fd, mainl, bhead, LIB_TESTEXT, NULL);
+ read_libblock(fd, mainl, bhead, LIB_TESTEXT, &id);
}
else {
printf("append: already linked\n");
@@ -12836,13 +12836,13 @@
}
}
- if(idcode==ID_OB && scene) { /* loose object: give a base */
+ /* TODO, move out of append and into own func the caller can use */
+ if(scene && id && (GS(id->name) == ID_OB)) { /* loose object: give a base */
base= MEM_callocN( sizeof(Base), "app_nam_part");
BLI_addtail(&scene->base, base);
- if(id==NULL) ob= mainl->object.last;
- else ob= (Object *)id;
-
+ ob= (Object *)id;
+
/* link at active layer (view3d->lay if in context, else scene->lay */
if((flag & FILE_ACTIVELAY)) {
View3D *v3d = CTX_wm_view3d(C);
@@ -12870,10 +12870,13 @@
bhead = blo_nextbhead(fd, bhead);
}
- return found;
+ /* if we found the id but the id is NULL, this is really bad */
+ BLI_assert((found != 0) == (id != NULL));
+
+ return found ? id : NULL;
}
-int BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag)
+ID *BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag)
{
FileData *fd= (FileData*)(*bh);
return append_named_part(C, mainl, fd, idname, idcode, flag);
More information about the Bf-blender-cvs
mailing list