Blender V4.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
10#include "BKE_main.hh"
11
12#include "BLI_function_ref.hh"
13#include "BLI_map.hh"
14#include "BLI_utility_mixins.hh"
15
16#include <string>
17
18struct bContext;
19struct BlendFileData;
23struct ID;
24struct IDNameLib_Map;
25struct Library;
27struct MemFile;
28struct ReportList;
29struct UserDef;
31
35#define BLENDER_ASSET_FILE_SUFFIX ".asset.blend"
36
44bool BKE_blendfile_extension_check(const char *str);
58bool BKE_blendfile_library_path_explode(const char *path,
59 char *r_dir,
60 char **r_group,
61 char **r_name);
62
68bool BKE_blendfile_is_readable(const char *path, ReportList *reports);
69
79 BlendFileData *bfd,
81 BlendFileReadWMSetupData *wm_setup_data,
82 BlendFileReadReport *reports,
83 bool startup_update_defaults,
84 const char *startup_app_template);
85
91 BlendFileData *bfd,
93 BlendFileReadReport *reports);
94
99BlendFileData *BKE_blendfile_read(const char *filepath,
101 BlendFileReadReport *reports);
102
108 int file_buf_size,
110 ReportList *reports);
111
119 MemFile *memfile,
121 ReportList *reports);
127
131UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports);
133 int file_buf_size,
134 ReportList *reports);
136
141bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports);
149bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *reports);
150
152
154 const void *file_buf,
155 int file_buf_size,
156 ReportList *reports);
158
160
180 public:
183
184 private:
195 std::string reference_root_filepath_;
203 IDNameLib_Map *matching_uid_map_;
204
207
208 public:
209 /* Passing a reference root filepath is mandatory, for remapping of relative paths to work as
210 * expected. */
212 PartialWriteContext(StringRefNull reference_root_filepath);
214
322 ID *id_add(const ID *id,
325 IDAddOptions options)> dependencies_filter_cb =
326 nullptr);
327
340 ID *id_create(short id_type, StringRefNull id_name, Library *library, IDAddOptions options);
341
352 void id_delete(const ID *id);
353
362 void remove_unused(bool clear_extra_user = false);
363
367 void clear();
368
376 bool is_valid();
377
383 bool write(const char *write_filepath, int write_flags, int remap_mode, ReportList &reports);
384 bool write(const char *write_filepath, ReportList &reports);
385
386 /* TODO: To allow editing an existing external blendfile:
387 * - API to load a context from a blendfile.
388 * - API to 'match' a context's content with another Main database's content (based on ID
389 * names and libraries).
390 * - API to replace the matching context IDs by a 'new version' (similar to 'add_id', but
391 * ensuring that the context ID, if it already exists, is a pristine copy of the given source
392 * one).
393 * - Rework the remapping of relative filepaths, since data already existing in the
394 * loaded-from-disk temp context will have different root-path than the data from current
395 * G_MAIN.
396 */
397
398 private:
404 void preempt_session_uid(ID *ctx_id, unsigned int session_uid);
412 void process_added_id(ID *ctx_id, const IDAddOperations operations);
417 ID *id_add_copy(const ID *id, bool regenerate_session_uid);
419 void make_local(ID *ctx_id, int make_local_flags);
424 Library *ensure_library(ID *ctx_id);
429 Library *ensure_library(StringRefNull library_absolute_path);
430};
431
432} // namespace blender::bke::blendfile
void BKE_blendfile_read_setup_undo(bContext *C, BlendFileData *bfd, const BlendFileReadParams *params, BlendFileReadReport *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_userdef_write_all(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_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:89
bool BKE_blendfile_extension_check(const char *str)
Definition blendfile.cc:83
void BKE_blendfile_workspace_config_data_free(WorkspaceConfigFileData *workspace_config)
UserDef * BKE_blendfile_userdef_from_defaults()
UserDef * BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
BlendFileData * BKE_blendfile_read_from_memfile(Main *bmain, MemFile *memfile, const BlendFileReadParams *params, ReportList *reports)
UserDef * BKE_blendfile_userdef_read_from_memory(const void *file_buf, int file_buf_size, ReportList *reports)
BlendFileData * BKE_blendfile_read(const char *filepath, const BlendFileReadParams *params, BlendFileReadReport *reports)
BlendFileData * BKE_blendfile_read_from_memory(const void *file_buf, int file_buf_size, const BlendFileReadParams *params, ReportList *reports)
bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *reports)
bool BKE_blendfile_is_readable(const char *path, ReportList *reports)
Definition blendfile.cc:152
void remove_unused(bool clear_extra_user=false)
ID * id_add(const ID *id, IDAddOptions options, blender::FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr)
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)
std::string id_name(void *id)
CCL_NAMESPACE_BEGIN struct Options options
#define str(s)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
Definition DNA_ID.h:413