Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-05-27 00:45:19 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-05-27 00:45:19 +0400
commit06fea1a0ff01590e88ef210edd2314615e077400 (patch)
treece2a9530afaa9d1b3d069c2072b9ec819137851a
parent78d41d061bb0bd1a16f533d1f5f0664d27556db6 (diff)
split BLO_library_append_named_part into 2 function, one that adds objects into the scene and another that just links/appends.
-rw-r--r--source/blender/blenloader/BLO_readfile.h18
-rw-r--r--source/blender/blenloader/intern/readfile.c100
-rw-r--r--source/blender/python/intern/bpy_library.c2
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c4
4 files changed, 74 insertions, 50 deletions
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index d9594f7da75..85d4b936c51 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -213,18 +213,32 @@ int BLO_is_a_library(const char *path, char *dir, char *group);
struct Main* BLO_library_append_begin(const struct bContext *C, BlendHandle** bh, const char *filepath);
+
/**
* Link/Append a named datablock from an external blend file.
*
+ * @param mainl The main database to link from (not the active one).
+ * @param bh The blender file handle.
+ * @param idname The name of the datablock (without the 2 char ID prefix)
+ * @param idcode The kind of datablock to link.
+ * @return the appended ID when found.
+ */
+struct ID *BLO_library_append_named_part(struct Main *mainl, BlendHandle** bh, const char *idname, const int idcode);
+
+/**
+ * Link/Append a named datablock from an external blend file.
+ * optionally instance the object in the scene when the flags are set.
+ *
* @param C The context, when NULL instancing object in the scene isnt done.
* @param mainl The main database to link from (not the active one).
* @param bh The blender file handle.
* @param idname The name of the datablock (without the 2 char ID prefix)
* @param idcode The kind of datablock to link.
* @param flag Options for linking, used for instancing.
- * @return Boolean, 0 when the datablock could not be found.
+ * @return the appended ID when found.
*/
-struct ID *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_ex(const struct bContext *C, struct Main *mainl, BlendHandle** bh, const char *idname, const int idcode, const 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);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bf00abf1008..03cd6e188c4 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -12806,24 +12806,17 @@ static void give_base_to_groups(Main *mainvar, Scene *scene)
}
/* returns true if the item was found
- * but it may already have already been appended/linked */
-static ID *append_named_part(const bContext *C, Main *mainl, FileData *fd, const char *idname, int idcode, short flag)
+* but it may already have already been appended/linked */
+static ID *append_named_part(Main *mainl, FileData *fd, const char *idname, const short idcode)
{
- Scene *scene= CTX_data_scene(C); /* can be NULL */
- Object *ob;
- Base *base;
BHead *bhead;
ID *id= NULL;
- int endloop=0;
int found=0;
- bhead = blo_firstbhead(fd);
- while(bhead && endloop==0) {
-
- if(bhead->code==ENDB) endloop= 1;
- else if(bhead->code==idcode) {
+ for(bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
+ if(bhead->code==idcode) {
const char *idname_test= bhead_id_name(fd, bhead);
-
+
if(strcmp(idname_test + 2, idname)==0) {
found= 1;
id= is_yet_read(fd, mainl, bhead);
@@ -12839,38 +12832,12 @@ static ID *append_named_part(const bContext *C, Main *mainl, FileData *fd, const
}
}
- /* 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);
-
- 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);
- if (v3d) {
- ob->lay = v3d->layact;
- } else {
- ob->lay = scene->lay;
- }
- }
- ob->mode= 0;
- base->lay= ob->lay;
- base->object= ob;
- ob->id.us++;
-
- if(flag & FILE_AUTOSELECT) {
- base->flag |= SELECT;
- base->object->flag = base->flag;
- /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
- }
- }
- endloop= 1;
+ break;
}
}
-
- bhead = blo_nextbhead(fd, bhead);
+ else if(bhead->code==ENDB) {
+ break;
+ }
}
/* if we found the id but the id is NULL, this is really bad */
@@ -12879,10 +12846,53 @@ static ID *append_named_part(const bContext *C, Main *mainl, FileData *fd, const
return found ? id : NULL;
}
-ID *BLO_library_append_named_part(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, int idcode, short flag)
+static ID *append_named_part_ex(const bContext *C, Main *mainl, FileData *fd, const char *idname, const int idcode, const int flag)
+{
+ ID *id= append_named_part(mainl, fd, idname, idcode);
+
+ if(id && (GS(id->name) == ID_OB)) { /* loose object: give a base */
+ Scene *scene= CTX_data_scene(C); /* can be NULL */
+ if(scene) {
+ Base *base;
+ Object *ob;
+
+ base= MEM_callocN( sizeof(Base), "app_nam_part");
+ BLI_addtail(&scene->base, base);
+
+ 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);
+ ob->lay = v3d ? v3d->layact : scene->lay;
+ }
+
+ ob->mode= 0;
+ base->lay= ob->lay;
+ base->object= ob;
+ ob->id.us++;
+
+ if(flag & FILE_AUTOSELECT) {
+ base->flag |= SELECT;
+ base->object->flag = base->flag;
+ /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
+ }
+ }
+ }
+
+ return id;
+}
+
+ID *BLO_library_append_named_part(Main *mainl, BlendHandle** bh, const char *idname, const int idcode)
+{
+ FileData *fd= (FileData*)(*bh);
+ return append_named_part(mainl, fd, idname, idcode);
+}
+
+ID *BLO_library_append_named_part_ex(const bContext *C, Main *mainl, BlendHandle** bh, const char *idname, const int idcode, const short flag)
{
FileData *fd= (FileData*)(*bh);
- return append_named_part(C, mainl, fd, idname, idcode, flag);
+ return append_named_part_ex(C, mainl, fd, idname, idcode, flag);
}
static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r)
@@ -12891,7 +12901,7 @@ static void append_id_part(FileData *fd, Main *mainvar, ID *id, ID **id_r)
for (bhead= blo_firstbhead(fd); bhead; bhead= blo_nextbhead(fd, bhead)) {
if (bhead->code == GS(id->name)) {
-
+
if (BLI_streq(id->name, bhead_id_name(fd, bhead))) {
id->flag &= ~LIB_READ;
id->flag |= LIB_TEST;
diff --git a/source/blender/python/intern/bpy_library.c b/source/blender/python/intern/bpy_library.c
index 49d5eaea9be..10e97573447 100644
--- a/source/blender/python/intern/bpy_library.c
+++ b/source/blender/python/intern/bpy_library.c
@@ -340,7 +340,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
// printf(" %s\n", item_str);
if(item_str) {
- ID *id= BLO_library_append_named_part(NULL, mainl, &(self->blo_handle), item_str, code, self->flag);
+ ID *id= BLO_library_append_named_part(mainl, &(self->blo_handle), item_str, code);
if(id) {
#ifdef USE_RNA_DATABLOCKS
PointerRNA id_ptr;
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 7f404f719ac..f5a1b6b0298 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -1642,12 +1642,12 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
/* here appending/linking starts */
mainl = BLO_library_append_begin(C, &bh, libname);
if(totfiles == 0) {
- BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
+ BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
}
else {
RNA_BEGIN(op->ptr, itemptr, "files") {
RNA_string_get(&itemptr, "name", name);
- BLO_library_append_named_part(C, mainl, &bh, name, idcode, flag);
+ BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
}
RNA_END;
}