diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-12-08 09:37:44 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-12-08 09:51:45 +0300 |
commit | 4f48b2992bdfa2926c61457b364b75900d7416b0 (patch) | |
tree | 74992624a706803e3aa135722f39735338431cf3 /source/blender/blenloader/BLO_readfile.h | |
parent | 93ba5e237546f58819cdff838334470e30ec0294 (diff) |
Cleanup: move public doc-strings into headers for 'blenloader'
Ref T92709
Diffstat (limited to 'source/blender/blenloader/BLO_readfile.h')
-rw-r--r-- | source/blender/blenloader/BLO_readfile.h | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 70006bb6d23..f86528db452 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -144,19 +144,50 @@ typedef enum eBLOReadSkip { } eBLOReadSkip; #define BLO_READ_SKIP_ALL (BLO_READ_SKIP_USERDEF | BLO_READ_SKIP_DATA) +/** + * Open a blender file from a pathname. The function returns NULL + * and sets a report in the list if it cannot open the file. + * + * \param filepath: The path of the file to open. + * \param reports: If the return value is NULL, errors indicating the cause of the failure. + * \return The data of the file. + */ BlendFileData *BLO_read_from_file(const char *filepath, eBLOReadSkip skip_flags, struct BlendFileReadReport *reports); +/** + * Open a blender file from memory. The function returns NULL + * and sets a report in the list if it cannot open the file. + * + * \param mem: The file data. + * \param memsize: The length of \a mem. + * \param reports: If the return value is NULL, errors indicating the cause of the failure. + * \return The data of the file. + */ BlendFileData *BLO_read_from_memory(const void *mem, int memsize, eBLOReadSkip skip_flags, struct ReportList *reports); +/** + * Used for undo/redo, skips part of libraries reading + * (assuming their data are already loaded & valid). + * + * \param oldmain: old main, + * from which we will keep libraries and other data-blocks that should not have changed. + * \param filename: current file, only for retrieving library data. + */ BlendFileData *BLO_read_from_memfile(struct Main *oldmain, const char *filename, struct MemFile *memfile, const struct BlendFileReadParams *params, struct ReportList *reports); +/** + * Frees a BlendFileData structure and *all* the data associated with it + * (the userdef data, and the main libblock data). + * + * \param bfd: The structure to free. + */ void BLO_blendfiledata_free(BlendFileData *bfd); /** \} */ @@ -170,24 +201,89 @@ typedef struct BLODataBlockInfo { struct AssetMetaData *asset_data; } BLODataBlockInfo; +/** + * Open a blendhandle from a file path. + * + * \param filepath: The file path to open. + * \param reports: Report errors in opening the file (can be NULL). + * \return A handle on success, or NULL on failure. + */ BlendHandle *BLO_blendhandle_from_file(const char *filepath, struct BlendFileReadReport *reports); +/** + * Open a blendhandle from memory. + * + * \param mem: The data to load from. + * \param memsize: The size of the data. + * \return A handle on success, or NULL on failure. + */ BlendHandle *BLO_blendhandle_from_memory(const void *mem, int memsize, struct BlendFileReadReport *reports); +/** + * Gets the names of all the data-blocks in a file of a certain type + * (e.g. all the scene names in a file). + * + * \param bh: The blendhandle to access. + * \param ofblocktype: The type of names to get. + * \param tot_names: The length of the returned list. + * \param use_assets_only: Only list IDs marked as assets. + * \return A BLI_linklist of strings. The string links should be freed with #MEM_freeN(). + */ struct LinkNode *BLO_blendhandle_get_datablock_names(BlendHandle *bh, int ofblocktype, const bool use_assets_only, int *r_tot_names); +/** + * Gets the names and asset-data (if ID is an asset) of data-blocks in a file of a certain type. + * The data-blocks can be limited to assets. + * + * \param bh: The blendhandle to access. + * \param ofblocktype: The type of names to get. + * \param use_assets_only: Limit the result to assets only. + * \param tot_info_items: The length of the returned list. + * \return A BLI_linklist of `BLODataBlockInfo *`. + * The links and #BLODataBlockInfo.asset_data should be freed with MEM_freeN. + */ struct LinkNode * /*BLODataBlockInfo */ BLO_blendhandle_get_datablock_info( BlendHandle *bh, int ofblocktype, const bool use_assets_only, int *r_tot_info_items); +/** + * Gets the previews of all the data-blocks in a file of a certain type + * (e.g. all the scene previews in a file). + * + * \param bh: The blendhandle to access. + * \param ofblocktype: The type of names to get. + * \param r_tot_prev: The length of the returned list. + * \return A BLI_linklist of #PreviewImage. The #PreviewImage links should be freed with malloc. + */ struct LinkNode *BLO_blendhandle_get_previews(BlendHandle *bh, int ofblocktype, int *r_tot_prev); +/** + * Get the PreviewImage of a single data block in a file. + * (e.g. all the scene previews in a file). + * + * \param bh: The blendhandle to access. + * \param ofblocktype: The type of names to get. + * \param name: Name of the block without the ID_ prefix, to read the preview image from. + * \return PreviewImage or NULL when no preview Images have been found. Caller owns the returned + */ struct PreviewImage *BLO_blendhandle_get_preview_for_id(BlendHandle *bh, int ofblocktype, const char *name); +/** + * Gets the names of all the linkable data-block types available in a file. + * (e.g. "Scene", "Mesh", "Light", etc.). + * + * \param bh: The blendhandle to access. + * \return A BLI_linklist of strings. The string links should be freed with #MEM_freeN(). + */ struct LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh); +/** + * Close and free a blendhandle. The handle becomes invalid after this call. + * + * \param bh: The handle to close. + */ void BLO_blendhandle_close(BlendHandle *bh); /** \} */ @@ -195,7 +291,25 @@ void BLO_blendhandle_close(BlendHandle *bh); #define BLO_GROUP_MAX 32 #define BLO_EMBEDDED_STARTUP_BLEND "<startup.blend>" +/** + * Check whether given path ends with a blend file compatible extension + * (`.blend`, `.ble` or `.blend.gz`). + * + * \param str: The path to check. + * \return true is this path ends with a blender file extension. + */ bool BLO_has_bfile_extension(const char *str); +/** + * Try to explode given path into its 'library components' + * (i.e. a .blend file, id type/group, and data-block itself). + * + * \param path: the full path to explode. + * \param r_dir: the string that'll contain path up to blend file itself ('library' path). + * WARNING! Must be #FILE_MAX_LIBEXTRA long (it also stores group and name strings)! + * \param r_group: the string that'll contain 'group' part of the path, if any. May be NULL. + * \param r_name: the string that'll contain data's name part of the path, if any. May be NULL. + * \return true if path contains a blend file. + */ bool BLO_library_path_explode(const char *path, char *r_dir, char **r_group, char **r_name); /* -------------------------------------------------------------------- */ @@ -263,14 +377,41 @@ void BLO_library_link_params_init_with_context(struct LibraryLink_Params *params struct ViewLayer *view_layer, const struct View3D *v3d); +/** + * Initialize the #BlendHandle for linking library data. + * + * \param bh: A blender file handle as returned by + * #BLO_blendhandle_from_file or #BLO_blendhandle_from_memory. + * \param filepath: Used for relative linking, copied to the `lib->filepath`. + * \param params: Settings for linking that don't change from beginning to end of linking. + * \return the library #Main, to be passed to #BLO_library_link_named_part as \a mainl. + */ struct Main *BLO_library_link_begin(BlendHandle **bh, const char *filepath, const struct LibraryLink_Params *params); +/** + * Link a named data-block from an external blend file. + * + * \param mainl: The main database to link from (not the active one). + * \param bh: The blender file handle. + * \param idcode: The kind of data-block to link. + * \param name: The name of the data-block (without the 2 char ID prefix). + * \return the linked ID when found. + */ struct ID *BLO_library_link_named_part(struct Main *mainl, BlendHandle **bh, const short idcode, const char *name, const struct LibraryLink_Params *params); +/** + * Finalize linking from a given .blend file (library). + * Optionally instance the indirect object/collection in the scene when the flags are set. + * \note Do not use \a bh after calling this function, it may frees it. + * + * \param mainl: The main database to link from (not the active one). + * \param bh: The blender file handle (WARNING! may be freed by this function!). + * \param params: Settings for linking that don't change from beginning to end of linking. + */ void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, const struct LibraryLink_Params *params); @@ -304,6 +445,10 @@ void BLO_library_temp_free(TempLibraryContext *temp_lib_ctx); void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char *blockname); /* internal function but we need to expose it */ +/** + * Used to link a file (without UI) to the current UI. + * Note that it assumes the old pointers in UI are still valid, so old Main is not freed. + */ void blo_lib_link_restore(struct Main *oldmain, struct Main *newmain, struct wmWindowManager *curwm, @@ -312,19 +457,48 @@ void blo_lib_link_restore(struct Main *oldmain, typedef void (*BLOExpandDoitCallback)(void *fdhandle, struct Main *mainvar, void *idv); +/** + * Set the callback func used over all ID data found by \a BLO_expand_main func. + * + * \param expand_doit_func: Called for each ID block it finds. + */ void BLO_main_expander(BLOExpandDoitCallback expand_doit_func); +/** + * Loop over all ID data in Main to mark relations. + * Set (id->tag & LIB_TAG_NEED_EXPAND) to mark expanding. Flags get cleared after expanding. + * + * \param fdhandle: usually filedata, or own handle. + * \param mainvar: the Main database to expand. + */ void BLO_expand_main(void *fdhandle, struct Main *mainvar); /** * Update defaults in startup.blend, without having to save and embed it. * \note defaults for preferences are stored in `userdef_default.c` and can be updated there. */ +/** + * Update defaults in startup.blend, without having to save and embed the file. + * This function can be emptied each time the startup.blend is updated. + * + * \note Screen data may be cleared at this point, this will happen in the case + * an app-template's data needs to be versioned when read-file is called with "Load UI" disabled. + * Versioning the screen data can be safely skipped without "Load UI" since the screen data + * will have been versioned when it was first loaded. + */ void BLO_update_defaults_startup_blend(struct Main *bmain, const char *app_template); void BLO_update_defaults_workspace(struct WorkSpace *workspace, const char *app_template); /* Disable unwanted experimental feature settings on startup. */ void BLO_sanitize_experimental_features_userpref_blend(struct UserDef *userdef); +/** + * Does a very light reading of given .blend file to extract its stored thumbnail. + * + * \param filepath: The path of the file to extract thumbnail from. + * \return The raw thumbnail + * (MEM-allocated, as stored in file, use #BKE_main_thumbnail_to_imbuf() + * to convert it to ImBuf image). + */ struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath); /* datafiles (generated theme) */ |