Blender  V3.3
blender_copybuffer.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include <stdlib.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "DNA_scene_types.h"
14 #include "DNA_screen_types.h"
15 #include "DNA_userdef_types.h"
16 #include "DNA_view3d_types.h"
18 
19 #include "BLI_blenlib.h"
20 #include "BLI_utildefines.h"
21 
22 #include "IMB_imbuf.h"
23 #include "IMB_moviecache.h"
24 
25 #include "BKE_blender_copybuffer.h" /* own include */
26 #include "BKE_blendfile.h"
28 #include "BKE_context.h"
29 #include "BKE_global.h"
30 #include "BKE_layer.h"
31 #include "BKE_lib_id.h"
32 #include "BKE_main.h"
33 #include "BKE_scene.h"
34 
35 #include "DEG_depsgraph.h"
36 #include "DEG_depsgraph_build.h"
37 
38 #include "BLO_readfile.h"
39 #include "BLO_writefile.h"
40 
41 #include "IMB_colormanagement.h"
42 
43 /* -------------------------------------------------------------------- */
48 {
50 }
51 
53 {
55 }
56 
57 bool BKE_copybuffer_copy_end(Main *bmain_src, const char *filename, ReportList *reports)
58 {
59  const int write_flags = 0;
61 
62  bool retval = BKE_blendfile_write_partial(bmain_src, filename, write_flags, remap_mode, reports);
63 
65 
66  return retval;
67 }
68 
69 /* Common helper for paste functions. */
71  Main *bmain,
72  ReportList *reports)
73 {
74  /* Tag existing IDs in given `bmain_dst` as already existing. */
76 
77  BKE_blendfile_link(lapp_context, reports);
78 
79  /* Mark all library linked objects to be updated. */
82 
83  /* Append, rather than linking */
84  BKE_blendfile_append(lapp_context, reports);
85 
86  /* This must be unset, otherwise these object won't link into other scenes from this blend
87  * file. */
89 
90  /* Recreate dependency graph to include new objects. */
92 }
93 
94 bool BKE_copybuffer_read(Main *bmain_dst,
95  const char *libname,
96  ReportList *reports,
97  const uint64_t id_types_mask)
98 {
99  /* NOTE: No recursive append here (no `BLO_LIBLINK_APPEND_RECURSIVE`), external linked data
100  * should remain linked. */
101  const int flag = 0;
102  const int id_tag_extra = 0;
103  struct LibraryLink_Params liblink_params;
104  BLO_library_link_params_init(&liblink_params, bmain_dst, flag, id_tag_extra);
105 
107  &liblink_params);
108  BKE_blendfile_link_append_context_library_add(lapp_context, libname, NULL);
109 
111  lapp_context, reports, id_types_mask, 0);
112  if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
114  return false;
115  }
116 
117  copybuffer_append(lapp_context, bmain_dst, reports);
118 
120  return true;
121 }
122 
124  const char *libname,
125  const int flag,
126  ReportList *reports,
127  const uint64_t id_types_mask)
128 {
132  View3D *v3d = CTX_wm_view3d(C); /* may be NULL. */
133  const int id_tag_extra = 0;
134 
135  /* NOTE: No recursive append here, external linked data should remain linked. */
137 
138  struct LibraryLink_Params liblink_params;
140  &liblink_params, bmain, flag, id_tag_extra, scene, view_layer, v3d);
141 
143  &liblink_params);
144  BKE_blendfile_link_append_context_library_add(lapp_context, libname, NULL);
145 
147  lapp_context, reports, id_types_mask, 0);
148  if (num_pasted == BLENDFILE_LINK_APPEND_INVALID) {
150  return 0;
151  }
152 
154 
155  copybuffer_append(lapp_context, bmain, reports);
156 
158  return num_pasted;
159 }
160 
void BKE_blendfile_write_partial_begin(struct Main *bmain_src)
Definition: blendfile.c:872
void BKE_blendfile_write_partial_end(struct Main *bmain_src)
Definition: blendfile.c:984
bool BKE_blendfile_write_partial(struct Main *bmain_src, const char *filepath, int write_flags, int remap_mode, struct ReportList *reports)
Definition: blendfile.c:902
void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set)
Definition: blendfile.c:877
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer)
Definition: layer.c:388
void BKE_main_id_tag_all(struct Main *mainvar, int tag, bool value)
Definition: lib_id.c:930
void BKE_main_lib_objects_recalc_all(struct Main *bmain)
Definition: lib_id.c:998
#define BLI_assert(a)
Definition: BLI_assert.h:46
external readfile function prototypes.
@ BLO_LIBLINK_APPEND_RECURSIVE
Definition: BLO_readfile.h:339
void BLO_library_link_params_init(struct LibraryLink_Params *params, struct Main *bmain, int flag, int id_tag_extra)
Definition: readfile.c:4622
void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params, struct Main *bmain, int flag, int id_tag_extra, struct Scene *scene, struct ViewLayer *view_layer, const struct View3D *v3d)
Definition: readfile.c:4633
external writefile.c function prototypes.
eBLO_WritePathRemap
Definition: BLO_writefile.h:29
@ BLO_WRITE_PATH_REMAP_RELATIVE
Definition: BLO_writefile.h:33
void DEG_relations_tag_update(struct Main *bmain)
@ LIB_TAG_PRE_EXISTING
Definition: DNA_ID.h:709
void IMB_colormanagement_check_file_config(struct Main *bmain)
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:25
bool BKE_copybuffer_read(Main *bmain_dst, const char *libname, ReportList *reports, const uint64_t id_types_mask)
bool BKE_copybuffer_copy_end(Main *bmain_src, const char *filename, ReportList *reports)
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)
void BKE_copybuffer_copy_begin(Main *bmain_src)
void BKE_copybuffer_copy_tag_ID(ID *id)
Scene scene
unsigned __int64 uint64_t
Definition: stdint.h:90
Definition: DNA_ID.h:368
Definition: BKE_main.h:121