[Bf-blender-cvs] [cfd11af9819] master: readfile: add id_tag_extra argument

Campbell Barton noreply at git.blender.org
Mon Mar 8 15:05:09 CET 2021


Commit: cfd11af9819433c5b83359b72f002fcd59fdc1ab
Author: Campbell Barton
Date:   Tue Mar 9 00:53:13 2021 +1100
Branches: master
https://developer.blender.org/rBcfd11af9819433c5b83359b72f002fcd59fdc1ab

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.

===================================================================

M	source/blender/blenkernel/intern/blender_copybuffer.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/python/intern/bpy_library_load.c
M	source/blender/windowmanager/intern/wm_files_link.c

===================================================================

diff --git a/source/blender/blenkernel/intern/blender_copybuffer.c b/source/blender/blenkernel/intern/blender_copybuffer.c
index 9f5e038fb82..ec8962d5f6d 100644
--- a/source/blender/blenkernel/intern/blender_copybuffer.c
+++ b/source/blender/blenkernel/intern/blender_copybuffer.c
@@ -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);
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index c7f02de21ea..09f4c405613 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -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);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 2eba9af233c..aa3362aa211 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -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)
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 7c14c7a19bf..9682b5456d2 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -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;
diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c
index 03771a8c294..5d9adb08f3d 100644
--- a/source/blender/python/intern/bpy_library_load.c
+++ b/source/blender/python/intern/bpy_library_load.c
@@ -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);
 
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index 6a1fc84774c..bf7cf81f0a9 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -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;



More information about the Bf-blender-cvs mailing list