Blender V5.0
blender_copybuffer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <cstdlib>
12
13#include "BKE_blender_copybuffer.hh" /* own include */
15#include "BKE_context.hh"
16#include "BKE_layer.hh"
17#include "BKE_lib_id.hh"
18
20
21#include "BLO_readfile.hh"
22#include "BLO_writefile.hh"
23
25
26/* -------------------------------------------------------------------- */
29
30/* Common helper for paste functions. */
32 Main *bmain,
33 ReportList *reports)
34{
35 /* Tag existing IDs in given `bmain_dst` as already existing. */
37
39
40 BKE_blendfile_link(lapp_context, reports);
41
42 /* Mark all library linked objects to be updated. */
45
46 /* Append, rather than linking */
47 BKE_blendfile_append(lapp_context, reports);
48
49 /* Instantiate loose data in the scene (e.g. add object to the active collection). */
51
53
54 /* This must be unset, otherwise these object won't link into other scenes from this blend
55 * file. */
57
58 /* Recreate dependency graph to include new objects. */
60}
61
62bool BKE_copybuffer_read(Main *bmain_dst,
63 const char *libname,
64 ReportList *reports,
65 const uint64_t id_types_mask)
66{
67 /* NOTE: No recursive append here (no `BLO_LIBLINK_APPEND_RECURSIVE`), external linked data
68 * should remain linked. */
69 const int flag = 0;
70 const int id_tag_extra = 0;
71 LibraryLink_Params liblink_params;
72 BLO_library_link_params_init(&liblink_params, bmain_dst, flag, id_tag_extra);
73
75 &liblink_params);
76 BKE_blendfile_link_append_context_library_add(lapp_context, libname, nullptr);
77
79 lapp_context, reports, id_types_mask, 0);
80 if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
82 return false;
83 }
84
85 copybuffer_append(lapp_context, bmain_dst, reports);
86
88 return true;
89}
90
92 const char *libname,
93 const int flag,
94 ReportList *reports,
95 const uint64_t id_types_mask)
96{
97 Main *bmain = CTX_data_main(C);
98 Scene *scene = CTX_data_scene(C);
99 ViewLayer *view_layer = CTX_data_view_layer(C);
100 View3D *v3d = CTX_wm_view3d(C); /* may be nullptr. */
101 const int id_tag_extra = 0;
102
103 /* NOTE: No recursive append here, external linked data should remain linked. */
105
106 LibraryLink_Params liblink_params;
108 &liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
109
111 &liblink_params);
112 BKE_blendfile_link_append_context_library_add(lapp_context, libname, nullptr);
113
115 lapp_context, reports, id_types_mask, 0);
116 if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
118 return 0;
119 }
120
121 BKE_view_layer_base_deselect_all(scene, view_layer);
122
123 copybuffer_append(lapp_context, bmain, reports);
124
126 return num_pasted;
127}
128
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_view_layer_base_deselect_all(const Scene *scene, ViewLayer *view_layer)
void BKE_main_lib_objects_recalc_all(Main *bmain)
Definition lib_id.cc:1290
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1224
#define BLI_assert(a)
Definition BLI_assert.h:46
external readfile function prototypes.
@ BLO_LIBLINK_APPEND_RECURSIVE
void BLO_library_link_params_init(LibraryLink_Params *params, Main *bmain, int flag, int id_tag_extra)
Definition readfile.cc:5105
void BLO_library_link_params_init_with_context(LibraryLink_Params *params, Main *bmain, int flag, int id_tag_extra, Scene *scene, ViewLayer *view_layer, const View3D *v3d)
Definition readfile.cc:5116
external writefile.cc function prototypes.
void DEG_relations_tag_update(Main *bmain)
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:926
void IMB_colormanagement_check_file_config(Main *bmain)
#define C
Definition RandGen.cpp:29
bool BKE_copybuffer_read(Main *bmain_dst, const char *libname, ReportList *reports, const uint64_t id_types_mask)
int BKE_copybuffer_paste(bContext *C, const char *libname, const int flag, ReportList *reports, const uint64_t id_types_mask)
static void copybuffer_append(BlendfileLinkAppendContext *lapp_context, Main *bmain, ReportList *reports)
unsigned long long int uint64_t
uint8_t flag
Definition wm_window.cc:145