Blender  V2.93
Classes | Macros | Typedefs | Enumerations | Functions
BKE_main.h File Reference
#include "DNA_listBase.h"
#include "BLI_compiler_attrs.h"
#include "BLI_sys_types.h"

Go to the source code of this file.

Classes

struct  BlendThumbnail
 
struct  MainIDRelationsEntryItem
 
struct  MainIDRelationsEntry
 
struct  MainIDRelations
 
struct  Main
 

Macros

#define FOREACH_MAIN_LISTBASE_ID_BEGIN(_lb, _id)
 
#define FOREACH_MAIN_LISTBASE_ID_END
 
#define FOREACH_MAIN_LISTBASE_BEGIN(_bmain, _lb)
 
#define FOREACH_MAIN_LISTBASE_END
 
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
 
#define FOREACH_MAIN_ID_END
 
#define MAIN_VERSION_ATLEAST(main, ver, subver)
 
#define MAIN_VERSION_OLDER(main, ver, subver)
 
#define BLEN_THUMB_SIZE   128
 
#define BLEN_THUMB_MEMSIZE(_x, _y)    (sizeof(BlendThumbnail) + ((size_t)(_x) * (size_t)(_y)) * sizeof(int))
 
#define BLEN_THUMB_MEMSIZE_IS_VALID(_x, _y)    (((_x) > 0 && (_y) > 0) && ((uint64_t)(_x) * (uint64_t)(_y) < (SIZE_MAX / (sizeof(int) * 4))))
 

Typedefs

typedef struct BlendThumbnail BlendThumbnail
 
typedef struct MainIDRelationsEntryItem MainIDRelationsEntryItem
 
typedef struct MainIDRelationsEntry MainIDRelationsEntry
 
typedef enum MainIDRelationsEntryTags MainIDRelationsEntryTags
 
typedef struct MainIDRelations MainIDRelations
 
typedef struct Main Main
 

Enumerations

enum  MainIDRelationsEntryTags { MAINIDRELATIONS_ENTRY_TAGS_DOIT = 1 << 0 , MAINIDRELATIONS_ENTRY_TAGS_PROCESSED = 1 << 1 }
 
enum  { MAINIDRELATIONS_INCLUDE_UI = 1 << 0 }
 

Functions

struct MainBKE_main_new (void)
 
void BKE_main_free (struct Main *mainvar)
 
void BKE_main_lock (struct Main *bmain)
 
void BKE_main_unlock (struct Main *bmain)
 
void BKE_main_relations_create (struct Main *bmain, const short flag)
 
void BKE_main_relations_free (struct Main *bmain)
 
void BKE_main_relations_tag_set (struct Main *bmain, const MainIDRelationsEntryTags tag, const bool value)
 
struct GSetBKE_main_gset_create (struct Main *bmain, struct GSet *gset)
 
struct BlendThumbnailBKE_main_thumbnail_from_imbuf (struct Main *bmain, struct ImBuf *img)
 
struct ImBufBKE_main_thumbnail_to_imbuf (struct Main *bmain, struct BlendThumbnail *data)
 
void BKE_main_thumbnail_create (struct Main *bmain)
 
const char * BKE_main_blendfile_path (const struct Main *bmain) ATTR_NONNULL()
 
const char * BKE_main_blendfile_path_from_global (void)
 
struct ListBasewhich_libbase (struct Main *bmain, short type)
 
int set_listbasepointers (struct Main *main, struct ListBase *lb[])
 

Detailed Description

Main struct

Main is the root of the 'data-base' of a Blender context. All data is put into lists, and all these lists are stored here.

Note
A Blender file is not much more than a binary dump of these lists. This list of lists is not serialized itself.
BKE_main files are for operations over the Main database itself, or generating extra temp data to help working with it. Those should typically not affect the data-blocks themselves.

Names

Definition in file BKE_main.h.

Macro Definition Documentation

◆ BLEN_THUMB_MEMSIZE

#define BLEN_THUMB_MEMSIZE (   _x,
  _y 
)     (sizeof(BlendThumbnail) + ((size_t)(_x) * (size_t)(_y)) * sizeof(int))

Definition at line 279 of file BKE_main.h.

◆ BLEN_THUMB_MEMSIZE_IS_VALID

#define BLEN_THUMB_MEMSIZE_IS_VALID (   _x,
  _y 
)     (((_x) > 0 && (_y) > 0) && ((uint64_t)(_x) * (uint64_t)(_y) < (SIZE_MAX / (sizeof(int) * 4))))

Protect against buffer overflow vulnerability & negative sizes.

Definition at line 282 of file BKE_main.h.

◆ BLEN_THUMB_SIZE

#define BLEN_THUMB_SIZE   128

Definition at line 277 of file BKE_main.h.

◆ FOREACH_MAIN_ID_BEGIN

#define FOREACH_MAIN_ID_BEGIN (   _bmain,
  _id 
)
Value:
{ \
ListBase *_lb; \
FOREACH_MAIN_LISTBASE_BEGIN ((_bmain), _lb) { \
FOREACH_MAIN_LISTBASE_ID_BEGIN (_lb, (_id))

Top level foreach-like macro allowing to loop over all IDs in a given Main data-base.

NOTE: Order tries to go from 'user IDs' to 'used IDs' (e.g. collections will be processed before objects, which will be processed before obdata types, etc.).

WARNING: DO NOT use break statement with that macro, use #FOREACH_MAIN_LISTBASE and #FOREACH_MAIN_LISTBASE_ID instead if you need that kind of control flow.

Definition at line 244 of file BKE_main.h.

◆ FOREACH_MAIN_ID_END

#define FOREACH_MAIN_ID_END
Value:
} \
FOREACH_MAIN_LISTBASE_END; \
} \
((void)0)
#define FOREACH_MAIN_LISTBASE_ID_END
Definition: BKE_main.h:219

Definition at line 250 of file BKE_main.h.

◆ FOREACH_MAIN_LISTBASE_BEGIN

#define FOREACH_MAIN_LISTBASE_BEGIN (   _bmain,
  _lb 
)
Value:
{ \
ListBase *_lbarray[INDEX_ID_MAX]; \
int _i = set_listbasepointers((_bmain), _lbarray); \
while (_i--) { \
(_lb) = _lbarray[_i];
int set_listbasepointers(struct Main *main, struct ListBase *lb[])
@ INDEX_ID_MAX
Definition: DNA_ID.h:859

Definition at line 224 of file BKE_main.h.

◆ FOREACH_MAIN_LISTBASE_END

#define FOREACH_MAIN_LISTBASE_END
Value:
} \
} \
((void)0)

Definition at line 231 of file BKE_main.h.

◆ FOREACH_MAIN_LISTBASE_ID_BEGIN

#define FOREACH_MAIN_LISTBASE_ID_BEGIN (   _lb,
  _id 
)
Value:
{ \
ID *_id_next = (_lb)->first; \
for ((_id) = _id_next; (_id) != NULL; (_id) = _id_next) { \
_id_next = (_id)->next;
static ulong * next

Definition at line 213 of file BKE_main.h.

◆ FOREACH_MAIN_LISTBASE_ID_END

#define FOREACH_MAIN_LISTBASE_ID_END
Value:
} \
} \
((void)0)

Definition at line 219 of file BKE_main.h.

◆ MAIN_VERSION_ATLEAST

#define MAIN_VERSION_ATLEAST (   main,
  ver,
  subver 
)
Value:
((main)->versionfile > (ver) || \
((main)->versionfile == (ver) && (main)->subversionfile >= (subver)))
int main(int argc, char **argv)
Definition: msgfmt.c:457

Definition at line 269 of file BKE_main.h.

◆ MAIN_VERSION_OLDER

#define MAIN_VERSION_OLDER (   main,
  ver,
  subver 
)
Value:
((main)->versionfile < (ver) || \
((main)->versionfile == (ver) && (main)->subversionfile < (subver)))

Definition at line 273 of file BKE_main.h.

Typedef Documentation

◆ BlendThumbnail

◆ Main

typedef struct Main Main

◆ MainIDRelations

◆ MainIDRelationsEntry

◆ MainIDRelationsEntryItem

◆ MainIDRelationsEntryTags

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MAINIDRELATIONS_INCLUDE_UI 

Definition at line 111 of file BKE_main.h.

◆ MainIDRelationsEntryTags

Enumerator
MAINIDRELATIONS_ENTRY_TAGS_DOIT 
MAINIDRELATIONS_ENTRY_TAGS_PROCESSED 

Definition at line 92 of file BKE_main.h.

Function Documentation

◆ BKE_main_blendfile_path()

const char* BKE_main_blendfile_path ( const struct Main bmain)

Referenced by blender::io::alembic::ArchiveReader::ArchiveReader(), bake_targets_output_external(), BKE_blendfile_read_from_memfile(), BKE_bpath_missing_files_find(), BKE_image_load(), BKE_library_filepath_set(), BKE_memfile_undo_decode(), BKE_movieclip_file_add(), BKE_movieclip_file_add_exists_ex(), BKE_packedfile_pack_all(), BKE_packedfile_pack_all_libraries(), BKE_packedfile_unpack_all_libraries(), BKE_packedfile_unpack_image(), BKE_packedfile_unpack_sound(), BKE_packedfile_unpack_vfont(), BKE_packedfile_unpack_volume(), BKE_scene_set_name(), BKE_sound_new_file(), BKE_sound_new_file_exists_ex(), BKE_vfont_load(), BKE_vfont_load_exists_ex(), blf_dir_search(), blo_do_versions_250(), BLO_memfile_main_get(), block_create__close_file_dialog(), bookmark_select_exec(), bpy_lib_load(), BPY_modules_load_user(), cachefile_open_invoke(), detect_clip_source(), do_write_image_or_movie(), ED_image_filesel_detect_sequences(), file_browse_exec(), file_directory_enter_handle(), file_exec(), file_expand_directory(), file_filename_enter_handle(), file_operator_to_sfile(), file_parent_exec(), file_select_do(), file_sfile_to_operator_ex(), filelist_readjob_start(), blender::io::gpencil::GpencilIO::filename_set(), image_open_exec(), image_save_options_from_op(), image_save_options_init(), image_save_sequence_exec(), lib_id_library_local_paths(), library_link_begin(), library_link_end(), load_data_init_from_operator(), make_paths_absolute_exec(), make_paths_relative_exec(), multires_external_save_exec(), namebutton_fn(), preview_prepare_scene(), RE_RenderAnim(), RE_RenderFrame(), read_global(), save_set_filepath(), screen_opengl_render_anim_step(), screen_opengl_render_write(), SEQ_add_image_strip(), SEQ_add_movie_strip(), seq_disk_cache_get_project_dir(), sequencer_change_path_exec(), sequencer_export_subtitles_invoke(), sequencer_generic_invoke_path__internal(), sound_mixdown_exec(), text_open_exec(), text_open_invoke(), text_save_as_invoke(), txt_write_file(), unpack_menu(), volume_import_exec(), wm_block_file_close_save(), WM_file_read(), wm_file_write(), wm_lib_relocate_exec_do(), wm_link_append_exec(), wm_open_mainfile__select_file_path(), WM_operator_drop_load_path(), wm_revert_mainfile_exec(), wm_save_as_mainfile_exec(), and write_result_func().

◆ BKE_main_blendfile_path_from_global()

const char* BKE_main_blendfile_path_from_global ( void  )

◆ BKE_main_free()

void BKE_main_free ( struct Main mainvar)

◆ BKE_main_gset_create()

struct GSet* BKE_main_gset_create ( Main bmain,
GSet gset 
)

Create a GSet storing all IDs present in given bmain, by their pointers.

Parameters
gsetIf not NULL, given GSet will be extended with IDs from given bmain, instead of creating a new one.

Definition at line 342 of file main.c.

References BLI_ghashutil_ptrcmp(), BLI_ghashutil_ptrhash(), BLI_gset_add(), BLI_gset_new(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, id, and NULL.

Referenced by BKE_main_idmap_create().

◆ BKE_main_lock()

void BKE_main_lock ( struct Main bmain)

◆ BKE_main_new()

struct Main* BKE_main_new ( void  )

◆ BKE_main_relations_create()

void BKE_main_relations_create ( Main bmain,
const short  flag 
)

◆ BKE_main_relations_free()

void BKE_main_relations_free ( struct Main bmain)

◆ BKE_main_relations_tag_set()

void BKE_main_relations_tag_set ( struct Main bmain,
const MainIDRelationsEntryTags  tag,
const bool  value 
)

◆ BKE_main_thumbnail_create()

void BKE_main_thumbnail_create ( struct Main bmain)

Generates an empty (black) thumbnail for given Main.

Definition at line 416 of file main.c.

References Main::blen_thumb, BLEN_THUMB_MEMSIZE, BLEN_THUMB_SIZE, BlendThumbnail::height, MEM_callocN, MEM_SAFE_FREE, and BlendThumbnail::width.

◆ BKE_main_thumbnail_from_imbuf()

struct BlendThumbnail* BKE_main_thumbnail_from_imbuf ( Main bmain,
ImBuf img 
)

Generates a raw .blend file thumbnail data from given image.

Parameters
bmainIf not NULL, also store generated data in this Main.
imgImBuf image to generate thumbnail data from.
Returns
The generated .blend file raw thumbnail data.

Definition at line 363 of file main.c.

References Main::blen_thumb, BLEN_THUMB_MEMSIZE, data, IMB_rect_from_float(), MEM_mallocN, MEM_SAFE_FREE, NULL, ImBuf::rect, ImBuf::x, and ImBuf::y.

Referenced by blend_file_thumb().

◆ BKE_main_thumbnail_to_imbuf()

struct ImBuf* BKE_main_thumbnail_to_imbuf ( Main bmain,
BlendThumbnail data 
)

Generates an image from raw .blend file thumbnail data.

Parameters
bmainUse this bmain->blen_thumb data if given data is NULL.
dataRaw .blend file thumbnail data.
Returns
An ImBuf from given data, or NULL if invalid.

Definition at line 394 of file main.c.

References Main::blen_thumb, BLEN_THUMB_MEMSIZE, data, IB_metadata, IB_rect, IMB_allocImBuf(), NULL, and ImBuf::rect.

Referenced by blend_file_thumb(), and IMB_thumb_load_blend().

◆ BKE_main_unlock()

void BKE_main_unlock ( struct Main bmain)

◆ set_listbasepointers()

int set_listbasepointers ( struct Main main,
struct ListBase lb[] 
)

◆ which_libbase()

struct ListBase* which_libbase ( Main bmain,
short  type 
)
Returns
A pointer to the ListBase of given bmain for requested type ID type.

Definition at line 447 of file main.c.

References Main::actions, Main::armatures, Main::brushes, Main::cachefiles, Main::cameras, Main::collections, Main::curves, Main::fonts, Main::gpencils, Main::hairs, ID_AC, ID_AR, ID_BR, ID_CA, ID_CF, ID_CU, ID_GD, ID_GR, ID_HA, ID_IM, ID_IP, ID_KE, ID_LA, ID_LI, ID_LP, ID_LS, ID_LT, ID_MA, ID_MB, ID_MC, ID_ME, ID_MSK, ID_NT, ID_OB, ID_PA, ID_PAL, ID_PC, ID_PT, ID_SCE, ID_SCR, ID_SIM, ID_SO, ID_SPK, ID_TE, ID_TXT, ID_VF, ID_VO, ID_WM, ID_WO, ID_WS, Main::images, Main::ipo, Main::lattices, Main::libraries, Main::lightprobes, Main::lights, Main::linestyles, Main::masks, Main::materials, Main::meshes, Main::metaballs, Main::movieclips, Main::nodetrees, NULL, Main::objects, Main::paintcurves, Main::palettes, Main::particles, Main::pointclouds, Main::scenes, Main::screens, Main::shapekeys, Main::simulations, Main::sounds, Main::speakers, Main::texts, Main::textures, type, Main::volumes, Main::wm, Main::workspaces, and Main::worlds.

Referenced by BKE_id_free_ex(), BKE_id_is_in_global_main(), BKE_libblock_alloc(), BKE_libblock_find_name(), BKE_libblock_management_main_add(), BKE_libblock_management_main_remove(), BKE_libblock_rename(), BKE_main_id_tag_idcode(), BKE_main_idmap_lookup_name(), BKE_mask_clipboard_paste_to_layer(), BKE_node_clipboard_validate(), BLI_libblock_ensure_unique_name(), blo_do_versions_280(), blo_do_versions_290(), BLO_library_link_copypaste(), blender::ed::outliner::TreeDisplayIDOrphans::buildTree(), create_placeholder(), is_yet_read(), lib_id_clear_library_data_ex(), lib_relocate_do(), lib_relocate_do_remap(), link_named_part(), outliner_id_itemf(), outliner_id_remap_exec(), pastebuf_match_path_property(), read_libblock(), read_libblock_undo_restore_at_old_address(), read_libblock_undo_restore_identical(), rename_id_for_versioning(), seqclipboard_ptr_restore(), split_libdata(), ui_template_id(), and undosys_id_ref_resolve().