Blender V5.3
BKE_blendfile.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
9
10#include "BKE_main.hh"
11
12#include "BLI_enum_flags.hh"
13#include "BLI_function_ref.hh"
14#include "BLI_map.hh"
15#include "BLI_utility_mixins.hh"
16
17#include <string>
18
19namespace blender {
20
21struct bContext;
22struct BlendFileData;
27struct ID;
28struct IDNameLib_Map;
29struct Library;
31struct MemFile;
32struct ReportList;
33struct UserDef;
35
39#define BLENDER_ASSET_FILE_SUFFIX ".asset.blend"
40
48bool BKE_blendfile_extension_check(const char *str);
62bool BKE_blendfile_library_path_explode(const char *path,
63 char *r_dir,
64 char **r_group,
65 char **r_name);
66
72bool BKE_blendfile_is_readable(const char *path, ReportList *reports);
73
83 BlendFileData *bfd,
84 const BlendFileReadParams *params,
85 BlendFileReadWMSetupData *wm_setup_data,
86 BlendFileReadReport *reports,
87 bool startup_update_defaults,
88 const char *startup_app_template);
89
94void BKE_blendfile_read_setup_undo(bContext *C,
95 BlendFileData *bfd,
96 const BlendFileReadParams *params,
97 BlendFileReadReport *reports);
98
103BlendFileData *BKE_blendfile_read(const char *filepath,
104 const BlendFileReadParams *params,
105 BlendFileReadReport *reports);
106
111BlendFileData *BKE_blendfile_read_from_memory(const void *file_buf,
112 int file_buf_size,
113 const BlendFileReadParams *params,
114 ReportList *reports);
115
122BlendFileData *BKE_blendfile_read_from_memfile(Main *bmain,
123 MemFile *memfile,
124 const BlendFileReadParams *params,
125 ReportList *reports);
130void BKE_blendfile_read_make_empty(bContext *C);
131
135UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports);
136UserDef *BKE_blendfile_userdef_read_from_memory(const void *file_buf,
137 int file_buf_size,
138 ReportList *reports);
140
145bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports);
153bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *reports);
154
155bool BKE_blendfile_userdef_write_all(ReportList *reports);
156
157WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath,
158 const void *file_buf,
159 int file_buf_size,
160 ReportList *reports);
161void BKE_blendfile_workspace_config_data_free(WorkspaceConfigFileData *workspace_config);
162
163namespace bke::blendfile {
164
184 public:
187
188 private:
199 std::string reference_root_filepath_;
207 IDNameLib_Map *matching_uid_map_;
208
210 Map<std::string, Library *> libraries_map_;
211
212 public:
213 /* Passing a reference root filepath is mandatory, for remapping of relative paths to work as
214 * expected. */
216 PartialWriteContext(Main &reference_main);
218
303
309
326 ID *id_add(const ID *id,
329 dependencies_filter_cb = nullptr);
330
343 ID *id_create(short id_type, StringRefNull id_name, Library *library, IDAddOptions options);
344
355 void id_delete(const ID *id);
356
365 void remove_unused(bool clear_extra_user = false);
366
370 void clear();
371
379 bool is_valid();
380
386 bool write(const char *write_filepath, int write_flags, int remap_mode, ReportList &reports);
387 bool write(const char *write_filepath, ReportList &reports);
393 bool write_as_copypaste_buffer(const char *write_filepath, ReportList &reports);
394
395 /* TODO: To allow editing an existing external blendfile:
396 * - API to load a context from a blendfile.
397 * - API to 'match' a context's content with another Main database's content (based on ID
398 * names and libraries).
399 * - API to replace the matching context IDs by a 'new version' (similar to 'add_id', but
400 * ensuring that the context ID, if it already exists, is a pristine copy of the given source
401 * one).
402 * - Rework the remapping of relative filepaths, since data already existing in the
403 * loaded-from-disk temp context will have different root-path than the data from current
404 * G_MAIN.
405 */
406
407 private:
413 void preempt_session_uid(ID *ctx_id, unsigned int session_uid);
421 void process_added_id(ID *ctx_id, const IDAddOperations operations);
426 ID *id_add_copy(const ID *id, bool regenerate_session_uid);
428 void make_local(ID *ctx_id, int make_local_flags);
433 Library *ensure_library(ID *ctx_id);
438 Library *ensure_library(StringRefNull library_absolute_path);
439
441 bool write_impl(const char *write_filepath,
442 int write_flags,
443 const BlendFileWriteParams &blend_file_write_params,
444 ReportList &reports);
445};
446
448
449} // namespace bke::blendfile
450} // namespace blender
#define C
Definition RandGen.cpp:29
ID * id_add(const ID *id, IDAddOptions options, FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
void remove_unused(bool clear_extra_user=false)
bool write_as_copypaste_buffer(const char *write_filepath, ReportList &reports)
bool write(const char *write_filepath, int write_flags, int remap_mode, ReportList &reports)
ID * id_create(short id_type, StringRefNull id_name, Library *library, IDAddOptions options)
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
CCL_NAMESPACE_BEGIN struct Options options
#define str(s)
ENUM_OPERATORS(PartialWriteContext::IDAddOperations)
BMesh Iterators.
void BKE_blendfile_workspace_config_data_free(WorkspaceConfigFileData *workspace_config)
bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *reports)
void BKE_blendfile_read_make_empty(bContext *C)
bool BKE_blendfile_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name)
Definition blendfile.cc:94
UserDef * BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
WorkspaceConfigFileData * BKE_blendfile_workspace_config_read(const char *filepath, const void *file_buf, int file_buf_size, ReportList *reports)
bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
void BKE_blendfile_read_setup_readfile(bContext *C, BlendFileData *bfd, const BlendFileReadParams *params, BlendFileReadWMSetupData *wm_setup_data, BlendFileReadReport *reports, bool startup_update_defaults, const char *startup_app_template)
bool BKE_blendfile_is_readable(const char *path, ReportList *reports)
Definition blendfile.cc:157
UserDef * BKE_blendfile_userdef_read_from_memory(const void *file_buf, int file_buf_size, ReportList *reports)
BlendFileData * BKE_blendfile_read_from_memfile(Main *bmain, MemFile *memfile, const BlendFileReadParams *params, ReportList *reports)
BlendFileData * BKE_blendfile_read_from_memory(const void *file_buf, int file_buf_size, const BlendFileReadParams *params, ReportList *reports)
void BKE_blendfile_read_setup_undo(bContext *C, BlendFileData *bfd, const BlendFileReadParams *params, BlendFileReadReport *reports)
BlendFileData * BKE_blendfile_read(const char *filepath, const BlendFileReadParams *params, BlendFileReadReport *reports)
bool BKE_blendfile_userdef_write_all(ReportList *reports)
bool BKE_blendfile_extension_check(const char *str)
Definition blendfile.cc:88
UserDef * BKE_blendfile_userdef_from_defaults()