Blender V4.3
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
11#include <cstdlib>
12
13#include "MEM_guardedalloc.h"
14
15#include "DNA_userdef_types.h"
16
17#include "BLI_utildefines.h"
18
19#include "BKE_blender_copybuffer.hh" /* own include */
21#include "BKE_context.hh"
22#include "BKE_layer.hh"
23#include "BKE_lib_id.hh"
24
26
27#include "BLO_readfile.hh"
28#include "BLO_writefile.hh"
29
31
32/* -------------------------------------------------------------------- */
36/* Common helper for paste functions. */
38 Main *bmain,
39 ReportList *reports)
40{
41 /* Tag existing IDs in given `bmain_dst` as already existing. */
43
45
46 BKE_blendfile_link(lapp_context, reports);
47
48 /* Mark all library linked objects to be updated. */
51
52 /* Append, rather than linking */
53 BKE_blendfile_append(lapp_context, reports);
54
55 /* Instantiate loose data in the scene (e.g. add object to the active collection). */
57
59
60 /* This must be unset, otherwise these object won't link into other scenes from this blend
61 * file. */
63
64 /* Recreate dependency graph to include new objects. */
66}
67
68bool BKE_copybuffer_read(Main *bmain_dst,
69 const char *libname,
70 ReportList *reports,
71 const uint64_t id_types_mask)
72{
73 /* NOTE: No recursive append here (no `BLO_LIBLINK_APPEND_RECURSIVE`), external linked data
74 * should remain linked. */
75 const int flag = 0;
76 const int id_tag_extra = 0;
77 LibraryLink_Params liblink_params;
78 BLO_library_link_params_init(&liblink_params, bmain_dst, flag, id_tag_extra);
79
81 &liblink_params);
82 BKE_blendfile_link_append_context_library_add(lapp_context, libname, nullptr);
83
85 lapp_context, reports, id_types_mask, 0);
86 if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
88 return false;
89 }
90
91 copybuffer_append(lapp_context, bmain_dst, reports);
92
94 return true;
95}
96
98 const char *libname,
99 const int flag,
100 ReportList *reports,
101 const uint64_t id_types_mask)
102{
103 Main *bmain = CTX_data_main(C);
104 Scene *scene = CTX_data_scene(C);
105 ViewLayer *view_layer = CTX_data_view_layer(C);
106 View3D *v3d = CTX_wm_view3d(C); /* may be nullptr. */
107 const int id_tag_extra = 0;
108
109 /* NOTE: No recursive append here, external linked data should remain linked. */
111
112 LibraryLink_Params liblink_params;
114 &liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
115
117 &liblink_params);
118 BKE_blendfile_link_append_context_library_add(lapp_context, libname, nullptr);
119
121 lapp_context, reports, id_types_mask, 0);
122 if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
124 return 0;
125 }
126
127 BKE_view_layer_base_deselect_all(scene, view_layer);
128
129 copybuffer_append(lapp_context, bmain, reports);
130
132 return num_pasted;
133}
134
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:1267
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1198
#define BLI_assert(a)
Definition BLI_assert.h:50
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:4304
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:4315
external writefile.cc function prototypes.
void DEG_relations_tag_update(Main *bmain)
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:872
void IMB_colormanagement_check_file_config(Main *bmain)
Read Guarded memory(de)allocation.
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 __int64 uint64_t
Definition stdint.h:90
uint8_t flag
Definition wm_window.cc:138