readfile: add id_tag_extra argument
This allows adding ID tags when linking/loading data. This is needed to implement loading non 'G.main' ID data-blocks, see D10612.
This commit is contained in:
@@ -94,8 +94,9 @@ bool BKE_copybuffer_read(Main *bmain_dst,
|
||||
}
|
||||
/* Here appending/linking starts. */
|
||||
const int flag = 0;
|
||||
const int id_tag_extra = 0;
|
||||
struct LibraryLink_Params liblink_params;
|
||||
BLO_library_link_params_init(&liblink_params, bmain_dst, flag);
|
||||
BLO_library_link_params_init(&liblink_params, bmain_dst, flag, id_tag_extra);
|
||||
Main *mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
||||
BLO_library_link_copypaste(mainl, bh, id_types_mask);
|
||||
BLO_library_link_end(mainl, &bh, &liblink_params);
|
||||
@@ -130,6 +131,7 @@ int BKE_copybuffer_paste(bContext *C,
|
||||
Main *mainl = NULL;
|
||||
Library *lib;
|
||||
BlendHandle *bh;
|
||||
const int id_tag_extra = 0;
|
||||
|
||||
bh = BLO_blendhandle_from_file(libname, reports);
|
||||
|
||||
@@ -148,7 +150,8 @@ int BKE_copybuffer_paste(bContext *C,
|
||||
|
||||
/* here appending/linking starts */
|
||||
struct LibraryLink_Params liblink_params;
|
||||
BLO_library_link_params_init_with_context(&liblink_params, bmain, flag, scene, view_layer, v3d);
|
||||
BLO_library_link_params_init_with_context(
|
||||
&liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
|
||||
mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
||||
|
||||
const int num_pasted = BLO_library_link_copypaste(mainl, bh, id_types_mask);
|
||||
|
||||
@@ -182,6 +182,8 @@ struct LibraryLink_Params {
|
||||
struct Main *bmain;
|
||||
/** Options for linking, used for instantiating. */
|
||||
int flag;
|
||||
/** Additional tag for #ID.tag. */
|
||||
int id_tag_extra;
|
||||
/** Context for instancing objects (optional, no instantiation will be performed when NULL). */
|
||||
struct {
|
||||
/** The scene in which to instantiate objects/collections. */
|
||||
@@ -195,10 +197,12 @@ struct LibraryLink_Params {
|
||||
|
||||
void BLO_library_link_params_init(struct LibraryLink_Params *params,
|
||||
struct Main *bmain,
|
||||
const int flag);
|
||||
const int flag,
|
||||
const int id_tag_extra);
|
||||
void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params,
|
||||
struct Main *bmain,
|
||||
const int flag,
|
||||
const int id_tag_extra,
|
||||
struct Scene *scene,
|
||||
struct ViewLayer *view_layer,
|
||||
const struct View3D *v3d);
|
||||
|
||||
@@ -4411,7 +4411,7 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
|
||||
if (id == NULL) {
|
||||
/* ID has not been read yet, add placeholder to the main of the
|
||||
* library it belongs to, so that it will be read later. */
|
||||
read_libblock(fd, libmain, bhead, LIB_TAG_INDIRECT, false, NULL);
|
||||
read_libblock(fd, libmain, bhead, fd->id_tag_extra | LIB_TAG_INDIRECT, false, NULL);
|
||||
/* commented because this can print way too much */
|
||||
// if (G.debug & G_DEBUG) printf("expand_doit: other lib %s\n", lib->filepath);
|
||||
|
||||
@@ -4466,7 +4466,12 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
|
||||
|
||||
ID *id = is_yet_read(fd, mainvar, bhead);
|
||||
if (id == NULL) {
|
||||
read_libblock(fd, mainvar, bhead, LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT, false, NULL);
|
||||
read_libblock(fd,
|
||||
mainvar,
|
||||
bhead,
|
||||
fd->id_tag_extra | LIB_TAG_NEED_EXPAND | LIB_TAG_INDIRECT,
|
||||
false,
|
||||
NULL);
|
||||
}
|
||||
else {
|
||||
/* Convert any previously read weak link to regular link
|
||||
@@ -4847,7 +4852,7 @@ static ID *link_named_part(
|
||||
id = is_yet_read(fd, mainl, bhead);
|
||||
if (id == NULL) {
|
||||
/* not read yet */
|
||||
const int tag = force_indirect ? LIB_TAG_INDIRECT : LIB_TAG_EXTERN;
|
||||
const int tag = ((force_indirect ? LIB_TAG_INDIRECT : LIB_TAG_EXTERN) | fd->id_tag_extra);
|
||||
read_libblock(fd, mainl, bhead, tag | LIB_TAG_NEED_EXPAND, false, &id);
|
||||
|
||||
if (id) {
|
||||
@@ -4988,10 +4993,13 @@ static void library_link_clear_tag(Main *mainvar, const int flag)
|
||||
}
|
||||
}
|
||||
|
||||
static Main *library_link_begin(Main *mainvar, FileData **fd, const char *filepath, const int flag)
|
||||
static Main *library_link_begin(
|
||||
Main *mainvar, FileData **fd, const char *filepath, const int flag, const int id_tag_extra)
|
||||
{
|
||||
Main *mainl;
|
||||
|
||||
(*fd)->id_tag_extra = id_tag_extra;
|
||||
|
||||
(*fd)->mainlist = MEM_callocN(sizeof(ListBase), "FileData.mainlist");
|
||||
|
||||
if (flag & BLO_LIBLINK_NEEDS_ID_TAG_DOIT) {
|
||||
@@ -5017,22 +5025,25 @@ static Main *library_link_begin(Main *mainvar, FileData **fd, const char *filepa
|
||||
|
||||
void BLO_library_link_params_init(struct LibraryLink_Params *params,
|
||||
struct Main *bmain,
|
||||
const int flag)
|
||||
const int flag,
|
||||
const int id_tag_extra)
|
||||
{
|
||||
memset(params, 0, sizeof(*params));
|
||||
params->bmain = bmain;
|
||||
params->flag = flag;
|
||||
params->id_tag_extra = id_tag_extra;
|
||||
}
|
||||
|
||||
void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params,
|
||||
struct Main *bmain,
|
||||
const int flag,
|
||||
const int id_tag_extra,
|
||||
/* Context arguments. */
|
||||
struct Scene *scene,
|
||||
struct ViewLayer *view_layer,
|
||||
const struct View3D *v3d)
|
||||
{
|
||||
BLO_library_link_params_init(params, bmain, flag);
|
||||
BLO_library_link_params_init(params, bmain, flag, id_tag_extra);
|
||||
if (scene != NULL) {
|
||||
/* Tagging is needed for instancing. */
|
||||
params->flag |= BLO_LIBLINK_NEEDS_ID_TAG_DOIT;
|
||||
@@ -5057,7 +5068,7 @@ Main *BLO_library_link_begin(BlendHandle **bh,
|
||||
const struct LibraryLink_Params *params)
|
||||
{
|
||||
FileData *fd = (FileData *)(*bh);
|
||||
return library_link_begin(params->bmain, &fd, filepath, params->flag);
|
||||
return library_link_begin(params->bmain, &fd, filepath, params->flag, params->id_tag_extra);
|
||||
}
|
||||
|
||||
static void split_main_newid(Main *mainptr, Main *main_newid)
|
||||
|
||||
@@ -120,6 +120,14 @@ typedef struct FileData {
|
||||
/** Optionally skip some data-blocks when they're not needed. */
|
||||
eBLOReadSkip skip_flags;
|
||||
|
||||
/**
|
||||
* Tag to apply to all loaded ID data-blocks.
|
||||
*
|
||||
* \note This is initialized from #LibraryLink_Params.id_tag_extra since passing it as an
|
||||
* argument would need an additional argument to be passed around when expanding library data.
|
||||
*/
|
||||
int id_tag_extra;
|
||||
|
||||
struct OldNewMap *datamap;
|
||||
struct OldNewMap *globmap;
|
||||
struct OldNewMap *libmap;
|
||||
|
||||
@@ -345,7 +345,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
|
||||
/* here appending/linking starts */
|
||||
struct LibraryLink_Params liblink_params;
|
||||
BLO_library_link_params_init(&liblink_params, bmain, self->flag);
|
||||
BLO_library_link_params_init(&liblink_params, bmain, self->flag, 0);
|
||||
|
||||
mainl = BLO_library_link_begin(&(self->blo_handle), self->relpath, &liblink_params);
|
||||
|
||||
|
||||
@@ -229,6 +229,7 @@ static void wm_link_do(WMLinkAppendData *lapp_data,
|
||||
Library *lib;
|
||||
|
||||
const int flag = lapp_data->flag;
|
||||
const int id_tag_extra = 0;
|
||||
|
||||
LinkNode *liblink, *itemlink;
|
||||
int lib_idx, item_idx;
|
||||
@@ -255,7 +256,7 @@ static void wm_link_do(WMLinkAppendData *lapp_data,
|
||||
/* here appending/linking starts */
|
||||
struct LibraryLink_Params liblink_params;
|
||||
BLO_library_link_params_init_with_context(
|
||||
&liblink_params, bmain, flag, scene, view_layer, v3d);
|
||||
&liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
|
||||
|
||||
mainl = BLO_library_link_begin(&bh, libname, &liblink_params);
|
||||
lib = mainl->curlib;
|
||||
|
||||
Reference in New Issue
Block a user