Blender V4.3
BKE_main.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
23#include "DNA_listBase.h"
24
25#include "BLI_compiler_attrs.h"
26#include "BLI_sys_types.h"
27
28struct BLI_mempool;
29struct BlendThumbnail;
30struct GHash;
31struct GSet;
32struct ID;
33struct IDNameLib_Map;
34struct ImBuf;
35struct Library;
36struct MainLock;
37struct ReportList;
38struct UniqueName_Map;
39
46 char rect[0];
47};
48
52
53 union {
54 /* For `from_ids` list, a user of the hashed ID. */
56 /* For `to_ids` list, an ID used by the hashed ID. */
57 ID **to;
59 /* Session uid of the `id_pointer`. */
61
62 int usage_flag; /* Using IDWALK_ enums, defined in BKE_lib_query.hh */
63};
64
66 /* Linked list of IDs using that ID. */
68 /* Linked list of IDs used by that ID. */
70
71 /* Session uid of the ID matching that entry. */
73
74 /* Runtime tags, users should ensure those are reset after usage. */
76};
77
80 /* Generic tag marking the entry as to be processed. */
82
83 /* Generic tag marking the entry as processed in the `to` direction (i.e. the IDs used by this
84 * item have been processed). */
86 /* Generic tag marking the entry as processed in the `from` direction (i.e. the IDs using this
87 * item have been processed). */
89 /* Generic tag marking the entry as processed. */
92
93 /* Generic tag marking the entry as being processed in the `to` direction (i.e. the IDs used by
94 * this item are being processed). Useful for dependency loops detection and handling. */
96 /* Generic tag marking the entry as being processed in the `from` direction (i.e. the IDs using
97 * this item are being processed). Useful for dependency loops detection and handling. */
99 /* Generic tag marking the entry as being processed. Useful for dependency loops detection and
100 * handling. */
103};
104
106 /* Mapping from an ID pointer to all of its parents (IDs using it) and children (IDs it uses).
107 * Values are `MainIDRelationsEntry` pointers. */
109 /* NOTE: we could add more mappings when needed (e.g. from session uid?). */
110
111 short flag;
112
113 /* Private... */
115};
116
117enum {
118 /* Those bmain relations include pointers/usages from editors. */
120};
121
122struct Main {
136 char filepath[1024]; /* 1024 = FILE_MAX */
137 short versionfile, subversionfile; /* see BLENDER_FILE_VERSION, BLENDER_FILE_SUBVERSION */
145
152
156 char build_hash[16];
171
177
184
192
206
208
222 ListBase ipo; /* Deprecated (only for versioning). */
239 ListBase wm; /* Singleton (exception). */
240 ListBase gpencils; /* Legacy Grease Pencil. */
254
261
264
267
268 /* Used for efficient calculations of unique names. Covers all names in current Main, including
269 * linked data ones. */
271
272 MainLock *lock;
273};
274
281Main *BKE_main_new(void);
288void BKE_main_init(Main &bmain);
298void BKE_main_clear(Main &bmain);
307void BKE_main_destroy(Main &bmain);
312void BKE_main_free(Main *bmain);
313
331
347void BKE_main_merge(Main *bmain_dst, Main **r_bmain_src, MainMergeReport &reports);
348
352bool BKE_main_is_empty(Main *bmain);
353
357bool BKE_main_has_issues(const Main *bmain);
358
363bool BKE_main_needs_overwrite_confirm(const Main *bmain);
364
365void BKE_main_lock(Main *bmain);
366void BKE_main_unlock(Main *bmain);
367
369void BKE_main_relations_create(Main *bmain, short flag);
370void BKE_main_relations_free(Main *bmain);
372void BKE_main_relations_tag_set(Main *bmain, eMainIDRelationsEntryTags tag, bool value);
373
380GSet *BKE_main_gset_create(Main *bmain, GSet *gset);
381
382/* Temporary runtime API to allow re-using local (already appended)
383 * IDs instead of appending a new copy again. */
384
386
398 MainLibraryWeakReferenceMap *library_weak_reference_mapping) ATTR_NONNULL();
409 MainLibraryWeakReferenceMap *library_weak_reference_mapping,
410 const char *library_filepath,
411 const char *library_id_name) ATTR_NONNULL();
422 MainLibraryWeakReferenceMap *library_weak_reference_mapping,
423 const char *library_filepath,
424 const char *library_id_name,
425 ID *new_id) ATTR_NONNULL();
441 MainLibraryWeakReferenceMap *library_weak_reference_mapping,
442 const char *library_filepath,
443 const char *library_id_name,
444 ID *old_id,
445 ID *new_id) ATTR_NONNULL();
456 MainLibraryWeakReferenceMap *library_weak_reference_mapping,
457 const char *library_filepath,
458 const char *library_id_name,
459 ID *old_id) ATTR_NONNULL();
460
461/* *** Generic utils to loop over whole Main database. *** */
462
463#define FOREACH_MAIN_LISTBASE_ID_BEGIN(_lb, _id) \
464 { \
465 ID *_id_next = static_cast<ID *>((_lb)->first); \
466 for ((_id) = _id_next; (_id) != nullptr; (_id) = _id_next) { \
467 _id_next = static_cast<ID *>((_id)->next);
468
469#define FOREACH_MAIN_LISTBASE_ID_END \
470 } \
471 } \
472 ((void)0)
473
474#define FOREACH_MAIN_LISTBASE_BEGIN(_bmain, _lb) \
475 { \
476 ListBase *_lbarray[INDEX_ID_MAX]; \
477 int _i = set_listbasepointers((_bmain), _lbarray); \
478 while (_i--) { \
479 (_lb) = _lbarray[_i];
480
481#define FOREACH_MAIN_LISTBASE_END \
482 } \
483 } \
484 ((void)0)
485
494#define FOREACH_MAIN_ID_BEGIN(_bmain, _id) \
495 { \
496 ListBase *_lb; \
497 FOREACH_MAIN_LISTBASE_BEGIN ((_bmain), _lb) { \
498 FOREACH_MAIN_LISTBASE_ID_BEGIN (_lb, (_id))
499
500#define FOREACH_MAIN_ID_END \
501 FOREACH_MAIN_LISTBASE_ID_END; \
502 } \
503 FOREACH_MAIN_LISTBASE_END; \
504 } \
505 ((void)0)
506
516 const uint8_t *rect,
517 const int size[2]);
518
539
543const char *BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL();
551
555ListBase *which_libbase(Main *bmain, short type);
556
557// #define INDEX_ID_MAX 41
570int set_listbasepointers(Main *bmain, ListBase *lb[]);
571
572#define MAIN_VERSION_FILE_ATLEAST(main, ver, subver) \
573 ((main)->versionfile > (ver) || \
574 ((main)->versionfile == (ver) && (main)->subversionfile >= (subver)))
575
576#define MAIN_VERSION_FILE_OLDER(main, ver, subver) \
577 ((main)->versionfile < (ver) || \
578 ((main)->versionfile == (ver) && (main)->subversionfile < (subver)))
579
580#define MAIN_VERSION_FILE_OLDER_OR_EQUAL(main, ver, subver) \
581 ((main)->versionfile < (ver) || \
582 ((main)->versionfile == (ver) && (main)->subversionfile <= (subver)))
583
584#define LIBRARY_VERSION_FILE_ATLEAST(lib, ver, subver) \
585 ((lib)->runtime.versionfile > (ver) || \
586 ((lib)->runtime.versionfile == (ver) && (lib)->runtime.subversionfile >= (subver)))
587
595#define BLEN_THUMB_SIZE 128
596
597#define BLEN_THUMB_MEMSIZE(_x, _y) \
598 (sizeof(BlendThumbnail) + ((size_t)(_x) * (size_t)(_y)) * sizeof(int))
600#define BLEN_THUMB_MEMSIZE_IS_VALID(_x, _y) \
601 (((_x) > 0 && (_y) > 0) && ((uint64_t)(_x) * (uint64_t)(_y) < (SIZE_MAX / (sizeof(int) * 4))))
BlendThumbnail * BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
Definition main.cc:782
ListBase * which_libbase(Main *bmain, short type)
Definition main.cc:842
void BKE_main_clear(Main &bmain)
Definition main.cc:64
void BKE_main_library_weak_reference_destroy(MainLibraryWeakReferenceMap *library_weak_reference_mapping) ATTR_NONNULL()
Definition main.cc:686
@ MAINIDRELATIONS_INCLUDE_UI
Definition BKE_main.hh:119
void BKE_main_merge(Main *bmain_dst, Main **r_bmain_src, MainMergeReport &reports)
Definition main.cc:321
void BKE_main_destroy(Main &bmain)
Definition main.cc:166
bool BKE_main_needs_overwrite_confirm(const Main *bmain)
Definition main.cc:474
bool BKE_main_has_issues(const Main *bmain)
Definition main.cc:469
ID * BKE_main_library_weak_reference_search_item(MainLibraryWeakReferenceMap *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name) ATTR_NONNULL()
Definition main.cc:692
eMainIDRelationsEntryTags
Definition BKE_main.hh:79
@ MAINIDRELATIONS_ENTRY_TAGS_INPROGRESS_FROM
Definition BKE_main.hh:98
@ MAINIDRELATIONS_ENTRY_TAGS_PROCESSED_TO
Definition BKE_main.hh:85
@ MAINIDRELATIONS_ENTRY_TAGS_PROCESSED
Definition BKE_main.hh:90
@ MAINIDRELATIONS_ENTRY_TAGS_INPROGRESS
Definition BKE_main.hh:101
@ MAINIDRELATIONS_ENTRY_TAGS_DOIT
Definition BKE_main.hh:81
@ MAINIDRELATIONS_ENTRY_TAGS_PROCESSED_FROM
Definition BKE_main.hh:88
@ MAINIDRELATIONS_ENTRY_TAGS_INPROGRESS_TO
Definition BKE_main.hh:95
void BKE_main_lock(Main *bmain)
Definition main.cc:479
int set_listbasepointers(Main *bmain, ListBase *lb[])
Definition main.cc:929
void BKE_main_thumbnail_create(Main *bmain)
Definition main.cc:822
void BKE_main_relations_tag_set(Main *bmain, eMainIDRelationsEntryTags tag, bool value)
Definition main.cc:592
ImBuf * BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
Definition main.cc:806
void BKE_main_init(Main &bmain)
Definition main.cc:52
Main * BKE_main_new(void)
Definition main.cc:45
void BKE_main_free(Main *bmain)
Definition main.cc:175
void BKE_main_relations_create(Main *bmain, short flag)
Definition main.cc:544
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:832
MainLibraryWeakReferenceMap * BKE_main_library_weak_reference_create(Main *bmain) ATTR_NONNULL()
Definition main.cc:656
BlendThumbnail * BKE_main_thumbnail_from_buffer(Main *bmain, const uint8_t *rect, const int size[2])
Definition main.cc:760
void BKE_main_unlock(Main *bmain)
Definition main.cc:484
bool BKE_main_is_empty(Main *bmain)
Definition main.cc:457
void BKE_main_library_weak_reference_remove_item(MainLibraryWeakReferenceMap *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name, ID *old_id) ATTR_NONNULL()
Definition main.cc:743
GSet * BKE_main_gset_create(Main *bmain, GSet *gset)
Definition main.cc:615
void BKE_main_library_weak_reference_update_item(MainLibraryWeakReferenceMap *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name, ID *old_id, ID *new_id) ATTR_NONNULL()
Definition main.cc:721
void BKE_main_relations_free(Main *bmain)
Definition main.cc:580
void BKE_main_library_weak_reference_add_item(MainLibraryWeakReferenceMap *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name, ID *new_id) ATTR_NONNULL()
Definition main.cc:701
const char * BKE_main_blendfile_path_from_global()
Definition main.cc:837
#define ATTR_NONNULL(...)
struct GSet GSet
Definition BLI_ghash.h:341
unsigned int uint
These structs are the foundation for all linked lists in the library system.
unsigned char uint8_t
Definition stdint.h:78
unsigned __int64 uint64_t
Definition stdint.h:90
char rect[0]
Definition BKE_main.hh:46
Definition DNA_ID.h:413
union MainIDRelationsEntryItem::@41 id_pointer
MainIDRelationsEntryItem * next
Definition BKE_main.hh:51
MainIDRelationsEntryItem * from_ids
Definition BKE_main.hh:67
MainIDRelationsEntryItem * to_ids
Definition BKE_main.hh:69
GHash * relations_from_pointers
Definition BKE_main.hh:108
BLI_mempool * entry_items_pool
Definition BKE_main.hh:114
int num_remapped_libraries
Definition BKE_main.hh:329
ReportList * reports
Definition BKE_main.hh:316
ListBase volumes
Definition BKE_main.hh:253
ListBase lightprobes
Definition BKE_main.hh:229
ListBase brushes
Definition BKE_main.hh:235
ListBase masks
Definition BKE_main.hh:243
bool is_locked_for_linking
Definition BKE_main.hh:176
ListBase scenes
Definition BKE_main.hh:210
ListBase grease_pencils
Definition BKE_main.hh:241
UniqueName_Map * name_map_global
Definition BKE_main.hh:270
ListBase wm
Definition BKE_main.hh:239
short subversionfile
Definition BKE_main.hh:137
bool is_asset_edit_file
Definition BKE_main.hh:151
bool has_forward_compatibility_issues
Definition BKE_main.hh:144
ListBase textures
Definition BKE_main.hh:217
ListBase actions
Definition BKE_main.hh:233
UniqueName_Map * name_map
Definition BKE_main.hh:266
ListBase texts
Definition BKE_main.hh:227
ListBase meshes
Definition BKE_main.hh:213
char filepath[1024]
Definition BKE_main.hh:136
ListBase movieclips
Definition BKE_main.hh:242
ListBase ipo
Definition BKE_main.hh:222
ListBase hair_curves
Definition BKE_main.hh:251
ListBase lights
Definition BKE_main.hh:220
ListBase paintcurves
Definition BKE_main.hh:238
bool is_memfile_undo_written
Definition BKE_main.hh:160
ListBase fonts
Definition BKE_main.hh:226
bool recovered
Definition BKE_main.hh:158
ListBase nodetrees
Definition BKE_main.hh:234
BlendThumbnail * blen_thumb
Definition BKE_main.hh:207
ListBase particles
Definition BKE_main.hh:236
ListBase materials
Definition BKE_main.hh:216
bool is_action_slot_to_id_map_dirty
Definition BKE_main.hh:205
Main * prev
Definition BKE_main.hh:123
ListBase linestyles
Definition BKE_main.hh:244
ListBase pointclouds
Definition BKE_main.hh:252
short minversionfile
Definition BKE_main.hh:138
uint64_t build_commit_timestamp
Definition BKE_main.hh:154
ListBase lattices
Definition BKE_main.hh:219
ListBase sounds
Definition BKE_main.hh:230
ListBase shapekeys
Definition BKE_main.hh:223
bool is_memfile_undo_flush_needed
Definition BKE_main.hh:165
ListBase libraries
Definition BKE_main.hh:211
ListBase cameras
Definition BKE_main.hh:221
IDNameLib_Map * id_map
Definition BKE_main.hh:263
bool use_memfile_full_barrier
Definition BKE_main.hh:170
ListBase armatures
Definition BKE_main.hh:232
ListBase speakers
Definition BKE_main.hh:228
MainLock * lock
Definition BKE_main.hh:272
ListBase curves
Definition BKE_main.hh:214
char build_hash[16]
Definition BKE_main.hh:156
Main * next
Definition BKE_main.hh:123
ListBase worlds
Definition BKE_main.hh:224
short minsubversionfile
Definition BKE_main.hh:138
ListBase screens
Definition BKE_main.hh:225
short versionfile
Definition BKE_main.hh:137
ListBase workspaces
Definition BKE_main.hh:246
bool is_read_invalid
Definition BKE_main.hh:183
ListBase palettes
Definition BKE_main.hh:237
ListBase metaballs
Definition BKE_main.hh:215
bool is_global_main
Definition BKE_main.hh:191
ListBase collections
Definition BKE_main.hh:231
Library * curlib
Definition BKE_main.hh:209
ListBase images
Definition BKE_main.hh:218
ListBase gpencils
Definition BKE_main.hh:240
MainIDRelations * relations
Definition BKE_main.hh:260
ListBase objects
Definition BKE_main.hh:212
ListBase cachefiles
Definition BKE_main.hh:245
uint8_t flag
Definition wm_window.cc:138