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:
Diffstat (limited to 'source/blender/blenkernel/intern/blender_copybuffer.c')
-rw-r--r--source/blender/blenkernel/intern/blender_copybuffer.c153
1 files changed, 57 insertions, 96 deletions
diff --git a/source/blender/blenkernel/intern/blender_copybuffer.c b/source/blender/blenkernel/intern/blender_copybuffer.c
index f8b943d3479..211d7f693d4 100644
--- a/source/blender/blenkernel/intern/blender_copybuffer.c
+++ b/source/blender/blenkernel/intern/blender_copybuffer.c
@@ -38,6 +38,7 @@
#include "BKE_blender_copybuffer.h" /* own include */
#include "BKE_blendfile.h"
+#include "BKE_blendfile_link_append.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_layer.h"
@@ -57,25 +58,16 @@
/** \name Copy/Paste `.blend`, partial saves.
* \{ */
-/** Initialize a copy operation. */
void BKE_copybuffer_copy_begin(Main *bmain_src)
{
BKE_blendfile_write_partial_begin(bmain_src);
}
-/** Mark an ID to be copied. Should only be called after a call to #BKE_copybuffer_copy_begin. */
void BKE_copybuffer_copy_tag_ID(ID *id)
{
BKE_blendfile_write_partial_tag_ID(id, true);
}
-/**
- * Finalize a copy operation into given .blend file 'buffer'.
- *
- * \param filename: Full path to the .blend file used as copy/paste buffer.
- *
- * \return true on success, false otherwise.
- */
bool BKE_copybuffer_copy_end(Main *bmain_src, const char *filename, ReportList *reports)
{
const int write_flags = 0;
@@ -88,63 +80,60 @@ bool BKE_copybuffer_copy_end(Main *bmain_src, const char *filename, ReportList *
return retval;
}
-/**
- * Paste datablocks from the given .blend file 'buffer' (i.e. append them).
- *
- * Unlike #BKE_copybuffer_paste, it does not perform any instantiation of collections/objects/etc.
- *
- * \param libname: Full path to the .blend file used as copy/paste buffer.
- * \param id_types_mask: Only directly link IDs of those types from the given .blend file buffer.
- *
- * \return true on success, false otherwise.
- */
+/* Common helper for paste functions. */
+static void copybuffer_append(BlendfileLinkAppendContext *lapp_context,
+ Main *bmain,
+ ReportList *reports)
+{
+ /* Tag existing IDs in given `bmain_dst` as already existing. */
+ BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
+
+ BKE_blendfile_link(lapp_context, reports);
+
+ /* Mark all library linked objects to be updated. */
+ BKE_main_lib_objects_recalc_all(bmain);
+ IMB_colormanagement_check_file_config(bmain);
+
+ /* Append, rather than linking */
+ BKE_blendfile_append(lapp_context, reports);
+
+ /* This must be unset, otherwise these object won't link into other scenes from this blend
+ * file. */
+ BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
+
+ /* Recreate dependency graph to include new objects. */
+ DEG_relations_tag_update(bmain);
+}
+
bool BKE_copybuffer_read(Main *bmain_dst,
const char *libname,
ReportList *reports,
const uint64_t id_types_mask)
{
- BlendFileReadReport bf_reports = {.reports = reports};
- BlendHandle *bh = BLO_blendhandle_from_file(libname, &bf_reports);
- if (bh == NULL) {
- /* Error reports will have been made by BLO_blendhandle_from_file(). */
- return false;
- }
- /* Here appending/linking starts. */
+ /* Note: No recursive append here (no `BLO_LIBLINK_APPEND_RECURSIVE`), external linked data
+ * should remain linked. */
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, 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);
- /* Mark all library linked objects to be updated. */
- BKE_main_lib_objects_recalc_all(bmain_dst);
- IMB_colormanagement_check_file_config(bmain_dst);
- /* Append, rather than linking. */
- Library *lib = BLI_findstring(&bmain_dst->libraries, libname, offsetof(Library, filepath_abs));
- BKE_library_make_local(bmain_dst, lib, NULL, true, false);
- /* Important we unset, otherwise these object won't
- * link into other scenes from this blend file.
- */
- BKE_main_id_tag_all(bmain_dst, LIB_TAG_PRE_EXISTING, false);
- BLO_blendhandle_close(bh);
+
+ BlendfileLinkAppendContext *lapp_context = BKE_blendfile_link_append_context_new(
+ &liblink_params);
+ BKE_blendfile_link_append_context_library_add(lapp_context, libname, NULL);
+
+ const int num_pasted = BKE_blendfile_link_append_context_item_idtypes_from_library_add(
+ lapp_context, reports, id_types_mask, 0);
+ if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
+ BKE_blendfile_link_append_context_free(lapp_context);
+ return false;
+ }
+
+ copybuffer_append(lapp_context, bmain_dst, reports);
+
+ BKE_blendfile_link_append_context_free(lapp_context);
return true;
}
-/**
- * Paste datablocks from the given .blend file 'buffer' (i.e. append them).
- *
- * Similar to #BKE_copybuffer_read, but also handles instantiation of collections/objects/etc.
- *
- * \param libname: Full path to the .blend file used as copy/paste buffer.
- * \param flag: A combination of #eBLOLibLinkFlags and ##eFileSel_Params_Flag to control
- * link/append behavior.
- * \note: Ignores #FILE_LINK flag, since it always appends IDs.
- * \param id_types_mask: Only directly link IDs of those types from the given .blend file buffer.
- *
- * \return Number of IDs directly pasted from the buffer (does not includes indirectly linked
- * ones).
- */
int BKE_copybuffer_paste(bContext *C,
const char *libname,
const int flag,
@@ -155,59 +144,31 @@ int BKE_copybuffer_paste(bContext *C,
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C); /* may be NULL. */
- Main *mainl = NULL;
- Library *lib;
- BlendHandle *bh;
const int id_tag_extra = 0;
- BlendFileReadReport bf_reports = {.reports = reports};
- bh = BLO_blendhandle_from_file(libname, &bf_reports);
-
- if (bh == NULL) {
- /* error reports will have been made by BLO_blendhandle_from_file() */
- return 0;
- }
-
- BKE_view_layer_base_deselect_all(view_layer);
-
- /* tag everything, all untagged data can be made local
- * its also generally useful to know what is new
- *
- * take extra care BKE_main_id_flag_all(bmain, LIB_TAG_PRE_EXISTING, false) is called after! */
- BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
+ /* Note: No recursive append here, external linked data should remain linked. */
+ BLI_assert((flag & BLO_LIBLINK_APPEND_RECURSIVE) == 0);
- /* here appending/linking starts */
struct LibraryLink_Params liblink_params;
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);
-
- BLO_library_link_end(mainl, &bh, &liblink_params);
-
- /* mark all library linked objects to be updated */
- BKE_main_lib_objects_recalc_all(bmain);
- IMB_colormanagement_check_file_config(bmain);
- /* append, rather than linking */
- lib = BLI_findstring(&bmain->libraries, libname, offsetof(Library, filepath_abs));
- BKE_library_make_local(bmain, lib, NULL, true, false);
+ BlendfileLinkAppendContext *lapp_context = BKE_blendfile_link_append_context_new(
+ &liblink_params);
+ BKE_blendfile_link_append_context_library_add(lapp_context, libname, NULL);
- /* important we unset, otherwise these object won't
- * link into other scenes from this blend file */
- BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
-
- /* recreate dependency graph to include new objects */
- DEG_relations_tag_update(bmain);
+ const int num_pasted = BKE_blendfile_link_append_context_item_idtypes_from_library_add(
+ lapp_context, reports, id_types_mask, 0);
+ if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
+ BKE_blendfile_link_append_context_free(lapp_context);
+ return 0;
+ }
- /* Tag update the scene to flush base collection settings, since the new object is added to a
- * new (active) collection, not its original collection, thus need recalculation. */
- DEG_id_tag_update(&scene->id, 0);
+ BKE_view_layer_base_deselect_all(view_layer);
- BLO_blendhandle_close(bh);
- /* remove library... */
+ copybuffer_append(lapp_context, bmain, reports);
+ BKE_blendfile_link_append_context_free(lapp_context);
return num_pasted;
}