Blender  V3.3
Classes | Typedefs | Functions
main.c File Reference
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_mempool.h"
#include "BLI_threads.h"
#include "DNA_ID.h"
#include "BKE_global.h"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BKE_main.h"
#include "BKE_main_idmap.h"
#include "BKE_main_namemap.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"

Go to the source code of this file.

Classes

struct  LibWeakRefKey
 

Typedefs

typedef struct LibWeakRefKey LibWeakRefKey
 

Functions

MainBKE_main_new (void)
 
void BKE_main_free (Main *mainvar)
 
bool BKE_main_is_empty (struct Main *bmain)
 
void BKE_main_lock (struct Main *bmain)
 
void BKE_main_unlock (struct Main *bmain)
 
static int main_relations_create_idlink_cb (LibraryIDLinkCallbackData *cb_data)
 
void BKE_main_relations_create (Main *bmain, const short flag)
 
void BKE_main_relations_free (Main *bmain)
 
void BKE_main_relations_tag_set (struct Main *bmain, const eMainIDRelationsEntryTags tag, const bool value)
 
GSetBKE_main_gset_create (Main *bmain, GSet *gset)
 
static LibWeakRefKeylib_weak_key_create (LibWeakRefKey *key, const char *lib_path, const char *id_name)
 
static uint lib_weak_key_hash (const void *ptr)
 
static bool lib_weak_key_cmp (const void *a, const void *b)
 
GHashBKE_main_library_weak_reference_create (Main *bmain)
 
void BKE_main_library_weak_reference_destroy (GHash *library_weak_reference_mapping)
 
IDBKE_main_library_weak_reference_search_item (GHash *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name)
 
void BKE_main_library_weak_reference_add_item (GHash *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name, ID *new_id)
 
void BKE_main_library_weak_reference_update_item (GHash *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name, ID *old_id, ID *new_id)
 
void BKE_main_library_weak_reference_remove_item (GHash *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name, ID *old_id)
 
BlendThumbnailBKE_main_thumbnail_from_imbuf (Main *bmain, ImBuf *img)
 
ImBufBKE_main_thumbnail_to_imbuf (Main *bmain, BlendThumbnail *data)
 
void BKE_main_thumbnail_create (struct Main *bmain)
 
const char * BKE_main_blendfile_path (const Main *bmain)
 
const char * BKE_main_blendfile_path_from_global (void)
 
ListBasewhich_libbase (Main *bmain, short type)
 
int set_listbasepointers (Main *bmain, ListBase *lb[])
 

Detailed Description

Contains management of Main database itself.

Definition in file main.c.

Typedef Documentation

◆ LibWeakRefKey

typedef struct LibWeakRefKey LibWeakRefKey

Function Documentation

◆ BKE_main_blendfile_path()

const char* BKE_main_blendfile_path ( const Main bmain)

Definition at line 557 of file main.c.

References Main::filepath.

Referenced by BKE_main_blendfile_path_from_global().

◆ BKE_main_blendfile_path_from_global()

const char* BKE_main_blendfile_path_from_global ( void  )

Return file-path of global main G_MAIN.

Warning
Usage is not recommended, you should always try to get a valid Main pointer from context.

Definition at line 562 of file main.c.

References BKE_main_blendfile_path(), and G_MAIN.

Referenced by BKE_modifier_path_init(), BKE_ptcache_toggle_disk_cache(), block_create_autorun_warning(), bpy_lib_write(), blender::compositor::OutputOpenExrSingleLayerMultiViewOperation::deinit_execution(), blender::compositor::OutputOpenExrMultiLayerMultiViewOperation::deinit_execution(), blender::compositor::OutputStereoOperation::deinit_execution(), blender::compositor::OutputSingleLayerOperation::deinit_execution(), blender::compositor::OutputOpenExrMultiLayerOperation::deinit_execution(), dynamicPaint_outputSurfaceImage(), filelist_setdir(), fileselect_ensure_updated_file_params(), fileselect_initialize_params_common(), get_drag_path(), get_proxy_fname(), icon_preview_imbuf_from_brush(), blender::io::usd::import_startjob(), library_link_end(), main(), movieclip_open_anim_file(), pose_copy_exec(), pose_paste_exec(), ptcache_file_open(), ptcache_filename(), ptcache_path(), render_result_exr_file_cache_path(), save_set_compress(), screenshot_exec(), screenshot_invoke(), SEQ_add_image_init_alpha_mode(), SEQ_add_reload_new_file(), seq_open_anim_file(), seq_proxy_get_custom_file_fname(), seq_proxy_get_fname(), seq_proxy_multiview_context_invalid(), seq_render_image_strip(), stampdata(), wm_history_file_update(), WM_init(), wm_link_append_invoke(), wm_revert_mainfile_poll(), wm_save_mainfile_invoke(), wm_window_title(), and write_crash_blend().

◆ BKE_main_free()

void BKE_main_free ( Main mainvar)

◆ BKE_main_gset_create()

GSet* BKE_main_gset_create ( struct Main bmain,
struct 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 346 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_is_empty()

bool BKE_main_is_empty ( struct Main bmain)

Check whether given bmain is empty or contains some IDs.

Definition at line 204 of file main.c.

References FOREACH_MAIN_ID_BEGIN, and FOREACH_MAIN_ID_END.

Referenced by library_link_end().

◆ BKE_main_library_weak_reference_add_item()

void BKE_main_library_weak_reference_add_item ( struct GHash library_weak_reference_mapping,
const char *  library_filepath,
const char *  library_id_name,
struct ID new_id 
)

Add the given ID weak library reference to given local ID and the runtime mapping.

Parameters
library_weak_reference_mappingthe mapping data generated by BKE_main_library_weak_reference_create.
library_filepaththe path of a blend file library (relative to current working one).
library_id_namethe full ID name, including the leading two chars encoding the ID type.
new_idNew local ID matching given weak reference.

Definition at line 440 of file main.c.

References BKE_idtype_idcode_append_is_reusable(), BLI_assert, BLI_ghash_ensure_p(), BLI_strncpy(), GS, lib_weak_key_create(), LibraryWeakReference::library_filepath, LibraryWeakReference::library_id_name, ID::library_weak_reference, MEM_mallocN, ID::name, NULL, and UNUSED_VARS_NDEBUG.

Referenced by BKE_blendfile_append().

◆ BKE_main_library_weak_reference_create()

GHash* BKE_main_library_weak_reference_create ( struct Main bmain)

◆ BKE_main_library_weak_reference_destroy()

void BKE_main_library_weak_reference_destroy ( struct GHash library_weak_reference_mapping)

Destroy the data generated by BKE_main_library_weak_reference_create.

Definition at line 426 of file main.c.

References BLI_ghash_free(), MEM_freeN, and NULL.

Referenced by BKE_blendfile_append().

◆ BKE_main_library_weak_reference_remove_item()

void BKE_main_library_weak_reference_remove_item ( struct GHash library_weak_reference_mapping,
const char *  library_filepath,
const char *  library_id_name,
struct ID old_id 
)

Remove the given ID weak library reference from the given local ID and the runtime mapping.

Parameters
library_weak_reference_mappingthe mapping data generated by BKE_main_library_weak_reference_create.
library_filepaththe path of a blend file library (relative to current working one).
library_id_namethe full ID name, including the leading two chars encoding the ID type.
old_idExisting local ID matching given weak reference.

Definition at line 491 of file main.c.

References BLI_assert, BLI_ghash_lookup(), BLI_ghash_remove(), GS, lib_weak_key_create(), ID::library_weak_reference, MEM_freeN, MEM_SAFE_FREE, ID::name, and NULL.

Referenced by BKE_blendfile_append().

◆ BKE_main_library_weak_reference_search_item()

ID* BKE_main_library_weak_reference_search_item ( struct GHash library_weak_reference_mapping,
const char *  library_filepath,
const char *  library_id_name 
)

Search for a local ID matching the given linked ID reference.

Parameters
library_weak_reference_mappingthe mapping data generated by BKE_main_library_weak_reference_create.
library_filepaththe path of a blend file library (relative to current working one).
library_id_namethe full ID name, including the leading two chars encoding the ID type.

Definition at line 431 of file main.c.

References BLI_ghash_lookup(), and lib_weak_key_create().

Referenced by BKE_blendfile_append().

◆ BKE_main_library_weak_reference_update_item()

void BKE_main_library_weak_reference_update_item ( struct GHash library_weak_reference_mapping,
const char *  library_filepath,
const char *  library_id_name,
struct ID old_id,
struct ID new_id 
)

Update the status of the given ID weak library reference in current local IDs and the runtime mapping.

This effectively transfers the 'ownership' of the given weak reference from old_id to new_id.

Parameters
library_weak_reference_mappingthe mapping data generated by BKE_main_library_weak_reference_create.
library_filepaththe path of a blend file library (relative to current working one).
library_id_namethe full ID name, including the leading two chars encoding the ID type.
old_idExisting local ID matching given weak reference.
new_idNew local ID matching given weak reference.

Definition at line 468 of file main.c.

References BLI_assert, BLI_ghash_lookup_p(), GS, lib_weak_key_create(), LibraryWeakReference::library_filepath, LibraryWeakReference::library_id_name, ID::library_weak_reference, ID::name, NULL, and STREQ.

◆ BKE_main_lock()

void BKE_main_lock ( struct Main bmain)

◆ BKE_main_new()

Main* BKE_main_new ( void  )

◆ BKE_main_relations_create()

void BKE_main_relations_create ( struct Main bmain,
short  flag 
)

◆ BKE_main_relations_free()

void BKE_main_relations_free ( Main bmain)

◆ BKE_main_relations_tag_set()

void BKE_main_relations_tag_set ( struct Main bmain,
eMainIDRelationsEntryTags  tag,
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 548 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()

BlendThumbnail* BKE_main_thumbnail_from_imbuf ( struct Main bmain,
struct 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 508 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_from_camera(), and blend_file_thumb_from_screenshot().

◆ BKE_main_thumbnail_to_imbuf()

ImBuf* BKE_main_thumbnail_to_imbuf ( struct Main bmain,
struct 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 532 of file main.c.

References Main::blen_thumb, data, IMB_allocFromBuffer(), and NULL.

Referenced by imb_thumb_load_from_blendfile(), and wm_file_write().

◆ BKE_main_unlock()

void BKE_main_unlock ( struct Main bmain)

◆ lib_weak_key_cmp()

static bool lib_weak_key_cmp ( const void a,
const void b 
)
static

◆ lib_weak_key_create()

static LibWeakRefKey* lib_weak_key_create ( LibWeakRefKey key,
const char *  lib_path,
const char *  id_name 
)
static

◆ lib_weak_key_hash()

static uint lib_weak_key_hash ( const void ptr)
static

◆ main_relations_create_idlink_cb()

static int main_relations_create_idlink_cb ( LibraryIDLinkCallbackData cb_data)
static

◆ set_listbasepointers()

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

Put the pointers to all the ListBase structs in given bmain into the *lb[INDEX_ID_MAX] array, and return the number of those for convenience.

This is useful for generic traversal of all the blocks in a Main (by traversing all the lists in turn), without worrying about block types.

Parameters
lbArray of lists INDEX_ID_MAX in length.
Note
The order of each ID type ListBase in the array is determined by the INDEX_ID_<IDTYPE> enum definitions in DNA_ID.h. See also the FOREACH_MAIN_ID_BEGIN macro in BKE_main.h

Definition at line 654 of file main.c.

References Main::actions, Main::armatures, Main::brushes, Main::cachefiles, Main::cameras, Main::collections, Main::curves, Main::fonts, Main::gpencils, Main::hair_curves, Main::images, INDEX_ID_AC, INDEX_ID_AR, INDEX_ID_BR, INDEX_ID_CA, INDEX_ID_CF, INDEX_ID_CU_LEGACY, INDEX_ID_CV, INDEX_ID_GD, INDEX_ID_GR, INDEX_ID_IM, INDEX_ID_IP, INDEX_ID_KE, INDEX_ID_LA, INDEX_ID_LI, INDEX_ID_LP, INDEX_ID_LS, INDEX_ID_LT, INDEX_ID_MA, INDEX_ID_MAX, INDEX_ID_MB, INDEX_ID_MC, INDEX_ID_ME, INDEX_ID_MSK, INDEX_ID_NT, INDEX_ID_NULL, INDEX_ID_OB, INDEX_ID_PA, INDEX_ID_PAL, INDEX_ID_PC, INDEX_ID_PT, INDEX_ID_SCE, INDEX_ID_SCR, INDEX_ID_SIM, INDEX_ID_SO, INDEX_ID_SPK, INDEX_ID_TE, INDEX_ID_TXT, INDEX_ID_VF, INDEX_ID_VO, INDEX_ID_WM, INDEX_ID_WO, INDEX_ID_WS, 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, Main::volumes, Main::wm, Main::workspaces, and Main::worlds.

Referenced by add_main_to_main(), BKE_blendfile_library_relocate(), BKE_blendfile_write_partial(), BKE_library_ID_test_usages(), BKE_library_indirectly_used_data_tag_clear(), BKE_library_make_local(), BKE_main_free(), BKE_main_id_flag_all(), BKE_main_id_tag_all(), blo_add_library_pointer_map(), blo_do_versions_270(), BLO_expand_main(), BLO_main_validate_libraries(), blo_split_main(), blender::ed::outliner::TreeDisplayIDOrphans::buildTree(), has_linked_ids_to_read(), id_delete(), library_ID_is_used(), read_library_clear_weak_links(), read_library_linked_ids(), split_main_newid(), write_file_handle(), and write_libraries().

◆ which_libbase()

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

Definition at line 567 of file main.c.

References Main::actions, Main::armatures, Main::brushes, Main::cachefiles, Main::cameras, Main::collections, Main::curves, Main::fonts, Main::gpencils, Main::hair_curves, ID_AC, ID_AR, ID_BR, ID_CA, ID_CF, ID_CU_LEGACY, ID_CV, ID_GD, ID_GR, 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_blendfile_library_relocate(), BKE_id_free_ex(), BKE_id_is_in_global_main(), BKE_lib_id_clear_library_data(), BKE_libblock_alloc(), BKE_libblock_find_name(), BKE_libblock_find_session_uuid(), 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(), blendfile_library_relocate_remap(), BLI_libblock_ensure_unique_name(), blo_do_versions_280(), blo_do_versions_290(), blo_do_versions_300(), blender::ed::outliner::TreeDisplayIDOrphans::buildTree(), create_placeholder(), do_versions_rename_id(), expand_doit_library(), is_yet_read(), link_named_part(), main_namemap_validate_and_fix(), 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(), seqclipboard_ptr_restore(), split_libdata(), ui_template_id(), and undosys_id_ref_resolve().