Blender V5.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
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#include "BKE_main.hh"
19
21
22#include "BLO_readfile.hh"
23#include "BLO_writefile.hh"
24
26
27namespace blender {
28
29/* -------------------------------------------------------------------- */
32
33/* Common helper for paste functions. */
35 Main *bmain,
36 ReportList *reports)
37{
38 /* Tag existing IDs in given `bmain_dst` as already existing. */
40
42
43 BKE_blendfile_link(lapp_context, reports);
44
45 /* Mark all library linked objects to be updated. */
48
49 /* Append, rather than linking */
50 BKE_blendfile_append(lapp_context, reports);
51
52 /* Instantiate loose data in the scene (e.g. add object to the active collection). */
54
56
57 /* This must be unset, otherwise these object won't link into other scenes from this blend
58 * file. */
60
61 /* Recreate dependency graph to include new objects. */
63}
64
65Main *BKE_copybuffer_read(Main &reference_bmain,
66 const char *libname,
67 ReportList *reports,
68 const uint64_t id_types_mask)
69{
70 Main *bmain_src = BKE_main_new();
71 BKE_main_init_from_reference(*bmain_src, reference_bmain);
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_src, 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 BKE_main_free(bmain_src);
89 return nullptr;
90 }
91
92 copybuffer_append(lapp_context, bmain_src, reports);
93
95 return bmain_src;
96}
97
99 const char *libname,
100 const int flag,
101 ReportList *reports,
102 const uint64_t id_types_mask)
103{
104 Main *bmain = CTX_data_main(C);
105 Scene *scene = CTX_data_scene(C);
106 ViewLayer *view_layer = CTX_data_view_layer(C);
107 View3D *v3d = CTX_wm_view3d(C); /* may be nullptr. */
108 const int id_tag_extra = 0;
109
110 /* NOTE: No recursive append here, external linked data should remain linked. */
112
113 LibraryLink_Params liblink_params;
115 &liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
116
118 &liblink_params);
119 BKE_blendfile_link_append_context_library_add(lapp_context, libname, nullptr);
120
122 lapp_context, reports, id_types_mask, 0);
123 if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
125 return 0;
126 }
127
128 BKE_view_layer_base_deselect_all(*bmain, scene, view_layer);
129
130 copybuffer_append(lapp_context, bmain, reports);
131
132 /* When doing regular, basic pasting of IDs, clear the CLIPBOARD_MARK flag. */
134
136 return num_pasted;
137}
138
140
141} // namespace blender
external readfile function prototypes.
external writefile.cc function prototypes.
#define C
Definition RandGen.cpp:29
BMesh Iterators.
void BKE_blendfile_link_append_instantiate_loose(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned __int64 uint64_t
Definition BKE_text.h:91
BlendfileLinkAppendContext * BKE_blendfile_link_append_context_new(LibraryLink_Params *params)
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:5758
Main * BKE_copybuffer_read(Main &reference_bmain, const char *libname, ReportList *reports, uint64_t id_types_mask)
void BKE_main_id_flag_all(Main *bmain, int flag, bool value)
Definition lib_id.cc:1339
void BKE_blendfile_link_append_context_free(BlendfileLinkAppendContext *lapp_context)
Main * BKE_main_new()
Definition main.cc:93
void BKE_main_init_from_reference(Main &bmain, const Main &reference)
Definition main.cc:100
static void copybuffer_append(BlendfileLinkAppendContext *lapp_context, Main *bmain, ReportList *reports)
@ BLO_LIBLINK_APPEND_RECURSIVE
ViewLayer * CTX_data_view_layer(const bContext *C)
void BLO_library_link_params_init(LibraryLink_Params *params, Main *bmain, int flag, int id_tag_extra)
Definition readfile.cc:5747
void BKE_blendfile_link_append_context_finalize(BlendfileLinkAppendContext *lapp_context)
void BKE_blendfile_append(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1314
void BKE_view_layer_base_deselect_all(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void BKE_main_free(Main *bmain)
Definition main.cc:202
Main * CTX_data_main(const bContext *C)
void BKE_blendfile_link_append_context_library_add(BlendfileLinkAppendContext *lapp_context, const char *libname, BlendHandle *blo_handle)
@ ID_TAG_PRE_EXISTING
Definition DNA_ID.h:929
int BKE_copybuffer_paste(bContext *C, const char *libname, int flag, ReportList *reports, uint64_t id_types_mask)
void BKE_main_lib_objects_recalc_all(Main *bmain)
Definition lib_id.cc:1379
void DEG_relations_tag_update(Main *bmain)
void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *reports)
Scene * CTX_data_scene(const bContext *C)
@ ID_FLAG_CLIPBOARD_MARK
Definition DNA_ID.h:801
int BKE_blendfile_link_append_context_item_idtypes_from_library_add(BlendfileLinkAppendContext *lapp_context, ReportList *reports, uint64_t id_types_filter, int library_index)
void IMB_colormanagement_check_file_config(Main *bmain)
void BKE_blendfile_link_append_context_init_done(BlendfileLinkAppendContext *lapp_context)
View3D * CTX_wm_view3d(const bContext *C)