49using namespace blender::bke;
58 this->
lock = (MainLock *)main_lock;
73 if (main_it ==
this) {
76 main_it->split_mains.reset();
83 "'.blend' relative \"//\" must not be used in Main!");
95 Main *bmain = MEM_new<Main>(__func__);
118 int a = lbarray.size();
120 ListBaseT<ID> *lb = lbarray[a];
123 for (
id = lb->first();
id !=
nullptr;
id = id_next) {
124 id_next =
static_cast<ID *
>(
id->next);
131# define CASE_ID_INDEX(id_index) \
133 BKE_id_free_ex(&bmain, id, free_flag, false); \
152 CASE_ID_INDEX(INDEX_ID_SIM);
186 lb->clear_no_delete();
225 if ((!id_1 && id_2->id_type() ==
ID_LI) || id_1->id_type() ==
ID_LI) {
232 if (lib_1 && lib_2) {
262 if (!id_1->
lib && !id_2->
lib) {
269 BLI_assert_msg(
false,
"No packed ID should be passed to this function currently.");
273 BLI_assert_msg(
false,
"No packed ID should be passed to this function currently.");
277 if (id_1->
lib && id_2->
lib) {
278 if (id_1->
lib == id_2->
lib) {
312 const bool is_library,
316 bool is_id_src_from_bmain_dst =
false;
317 if (is_id_src_linked) {
326 is_id_src_from_bmain_dst = !id_src_lib_dst.
is_empty() && !id_src_lib_dst[0];
328 CLOG_DEBUG(&
LOG,
"ID '%s' is linked from dst Main: %d", id_src->
name, is_id_src_from_bmain_dst);
330 if (is_id_src_from_bmain_dst) {
336 "ID '%s' defined in source Main as linked from destination Main (file '%s'), but "
337 "not found in given destination Main, will be skipped",
340 id_remapper.
add(id_src,
nullptr);
348 Library *lib_src = id_cast<Library *>(id_src);
357 ids_to_move.
append(id_src);
367 Main *bmain_src = *r_bmain_src;
373 ID *id_iter_dst, *id_iter_src;
375 if (id_iter_dst->id_type() ==
ID_LI) {
410 const bool is_library = id_iter_src->id_type() ==
ID_LI;
427 id_remapper.
add(id_iter_src, id_packed_dst);
432 bmain_dst, id_map_dst, id_iter_src, id_remapper, ids_to_move, is_library, reports);
437 is_library ?
reinterpret_cast<Library *
>(id_iter_src)->runtime->filepath_abs :
445 bmain_dst, id_map_dst, id_iter_src, id_remapper, ids_to_move, is_library, reports);
449 bool src_has_match_in_dst =
false;
452 if (!force_merge_src_ids || !force_merge_src_ids->
contains(id_iter_src)) {
453 for (
ID *id_iter_dst : ids_dst) {
455 bmain_dst, id_iter_dst, bmain_src, id_iter_src))
459 if (!src_has_match_in_dst) {
461 id_remapper_libraries.
add(id_iter_src, id_iter_dst);
465 id_remapper.
add(id_iter_src, id_iter_dst);
468 src_has_match_in_dst =
true;
476 if (!src_has_match_in_dst) {
478 bmain_dst, id_map_dst, id_iter_src, id_remapper, ids_to_move, is_library, reports);
488 if (bmain_src->
filepath[0] !=
'\0') {
493 if (bmain_dst->
filepath[0] !=
'\0') {
504 for (
ID *id_iter_src : ids_to_move) {
520 Span(&id_iter_src, 1),
522 id_remapper_libraries,
537 for (
ID *id_iter_src : ids_to_move) {
550 "Merged %d IDs from '%s' Main into '%s' Main; %d IDs and %d Libraries already existed as "
551 "part of the destination Main, and %d IDs missing from destination Main, were freed "
552 "together with the source Main",
567 *r_bmain_src =
nullptr;
583 Main &bmain_src = *r_bmain_src;
589 if (id_iter.id_type() ==
ID_LI) {
591 "Unexpected Library ID in source Main when merging as archive library");
594 ids_to_move.
append(&id_iter);
600 for (
ID *
id : ids_to_move) {
602 id->lib = &dst_external_library;
609 if (ntree !=
nullptr) {
610 ntree->
id.
lib = &dst_external_library;
614 Collection *master_collection = (id_cast<Scene *>(
id))->master_collection;
615 if (master_collection !=
nullptr) {
616 master_collection->
id.
lib = &dst_external_library;
626 for (
ID *
id : ids_to_move) {
634 r_bmain_src =
nullptr;
685 "main_relations_create_idlink_cb entry");
694 to_id_entry->
session_uid = (*id_pointer !=
nullptr) ? (*id_pointer)->session_uid :
697 entry->
to_ids = to_id_entry;
701 if (*id_pointer !=
nullptr) {
705 "main_relations_create_idlink_cb entry");
790 if (set ==
nullptr) {
791 set = MEM_new<Set<const ID *>>(__func__);
809 STRNCPY(this->filepath, lib_path);
830 auto *library_weak_reference_mapping = MEM_new<MainLibraryWeakReferenceMap>(__func__);
834 ID *id_iter = lb->first();
835 if (id_iter ==
nullptr) {
850 library_weak_reference_mapping->map.add(key, id_iter);
856 return library_weak_reference_mapping;
862 MEM_delete(library_weak_reference_mapping);
867 const char *library_filepath,
868 const char *library_id_name)
871 return library_weak_reference_mapping->
map.lookup_default(key,
nullptr);
876 const char *library_filepath,
877 const char *library_id_name,
893 library_weak_reference_mapping->
map.add(key, new_id);
900 const char *library_filepath,
901 const char *library_id_name,
913 BLI_assert(library_weak_reference_mapping->
map.lookup(key) == old_id);
914 library_weak_reference_mapping->
map.add_overwrite(key, new_id);
922 const char *library_filepath,
923 const char *library_id_name,
931 BLI_assert(library_weak_reference_mapping->
map.lookup(key) == old_id);
932 library_weak_reference_mapping->
map.remove(key);
938 const char *library_filepath,
939 const char *library_id_name)
942 char library_filepath_abs[
FILE_MAX];
943 STRNCPY(library_filepath_abs, library_filepath);
947 for (
ID &existing_id : *id_list) {
951 if (!(existing_id.library_weak_reference &&
952 STREQ(existing_id.library_weak_reference->library_id_name, library_id_name)))
957 char existing_filepath_abs[
FILE_MAX];
958 STRNCPY(existing_filepath_abs, existing_id.library_weak_reference->library_filepath);
961 if (!
STREQ(existing_filepath_abs, library_filepath_abs)) {
972 const char *library_filepath,
973 const char *library_id_name)
994 data->width = size[0];
995 data->height = size[1];
996 memcpy(
data->rect, rect, data_size -
sizeof(*
data));
1018 data->width = img->
x;
1019 data->height = img->
y;
1031 ImBuf *img =
nullptr;
1033 if (!
data && bmain) {
1070 return library.runtime->filepath_abs;
1077 return &(bmain->
scenes.cast<
ID>());
1083 return &(bmain->
meshes.cast<
ID>());
1085 return &(bmain->
curves.cast<
ID>());
1093 return &(bmain->
images.cast<
ID>());
1097 return &(bmain->
lights.cast<
ID>());
1103 return &(bmain->
worlds.cast<
ID>());
1107 return &(bmain->
fonts.cast<
ID>());
1109 return &(bmain->
texts.cast<
ID>());
1115 return &(bmain->
sounds.cast<
ID>());
1129 return &(bmain->
wm.cast<
ID>());
1137 return &(bmain->
masks.cast<
ID>());
1227 BLI_assert(curr_lbarray_index_ > -1 && curr_lbarray_index_ <
int64_t(lbarray_.size()));
1228 curr_id_ =
static_cast<ID *
>(curr_id_->next);
1237 if (curr_lbarray_index_ == lbarray_index_upper_bound()) {
1241 lbarray_index_step_next();
1243 if (curr_lbarray_index_ == lbarray_index_upper_bound()) {
1248 ListBaseT<ID> *lb_ids = lbarray_[size_t(curr_lbarray_index_)];
1249 if (lb_ids && !lb_ids->is_empty()) {
1250 curr_id_ = lb_ids->first();
1261 BLI_assert(curr_lbarray_index_ > -1 && curr_lbarray_index_ <
int64_t(lbarray_.size()));
1262 curr_id_ =
static_cast<ID *
>(curr_id_->prev);
1270 if (curr_lbarray_index_ == lbarray_index_lower_bound()) {
1274 lbarray_index_step_prev();
1276 if (curr_lbarray_index_ == lbarray_index_lower_bound()) {
1281 ListBaseT<ID> *lb_ids = lbarray_[size_t(curr_lbarray_index_)];
1282 if (lb_ids && !lb_ids->is_empty()) {
1283 curr_id_ = lb_ids->last();
1294 for (
const ListBaseT<ID> *lb_ids : lbarray_) {
1300 size += lb_ids->count();
#define MAIN_ID_SESSION_UID_UNSET
#define FOREACH_MAIN_ID_END
#define FOREACH_MAIN_LISTBASE_ID_END
#define FOREACH_MAIN_LISTBASE_ID_BEGIN(_lb, _id)
#define FOREACH_MAIN_LISTBASE_END
#define FOREACH_MAIN_LISTBASE_BEGIN(_bmain, _lb)
#define FOREACH_MAIN_ID_BEGIN(_bmain, _id)
#define BLEN_THUMB_MEMSIZE(_x, _y)
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
ID and Library types, which are fundamental for SDNA.
#define ID_IS_PACKED(_id)
#define ID_IS_LINKED(_id)
Object groups, one object can be in many groups at once.
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define BLI_assert_msg(a, msg)
MainAllIDsIterator & operator++()
MainAllIDsIterator & operator--()
bool add(const Key &key, const Value &value)
Value lookup_default(const Key &key, const Value &default_value) const
void add_new(const Key &key, const Value &value)
bool contains(const Key &key) const
Value & lookup_or_add(const Key &key, const Value &value)
bool contains(const Key &key) const
void prepend(const T &value)
void append(const T &value)
void add(ID *old_id, ID *new_id)
bNodeTree * node_tree_from_id(ID *id)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void BKE_main_relations_free(Main *bmain)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
std::array< ListBaseT< ID > *, INDEX_ID_MAX - 1 > MainListsArray
void id_lib_extern(ID *id, bool enforce_fix=false)
unsigned __int64 uint64_t
char * STRNCPY(char(&dst)[N], const char *src)
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()
static void main_merge_add_id_to_move(Main *bmain_dst, Map< std::string, Vector< ID * > > &id_map_dst, ID *id_src, id::IDRemapper &id_remapper, Vector< ID * > &ids_to_move, const bool is_library, MainMergeReport &reports)
ID * BKE_main_library_weak_reference_search_item(MainLibraryWeakReferenceMap *library_weak_reference_mapping, const char *library_filepath, const char *library_id_name) ATTR_NONNULL()
pthread_spinlock_t SpinLock
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
ImBuf * BKE_main_thumbnail_to_imbuf(Main *bmain, BlendThumbnail *data)
bool BKE_idtype_idcode_is_linkable(short idcode)
void BKE_main_library_weak_reference_add(ID *local_id, const char *library_filepath, const char *library_id_name)
static bool are_ids_from_different_mains_matching(Main *bmain_1, ID *id_1, Main *bmain_2, ID *id_2)
void BKE_main_init_from_reference(Main &bmain, const Main &reference)
void BKE_main_namemap_destroy(UniqueName_Map **r_name_map) ATTR_NONNULL()
void BKE_id_free_ex(Main *bmain, void *idv, int flag_orig, bool use_flag_from_idtag)
void BKE_bpath_relative_rebase(Main *bmain, const char *basedir_src, const char *basedir_dst, ReportList *reports, BPathSummary *r_summary=nullptr)
void BKE_libblock_management_main_remove(Main *bmain, void *idv)
void BKE_main_thumbnail_create(Main *bmain)
bool BKE_idtype_idcode_append_is_reusable(short idcode)
@ ID_REMAP_DO_LIBRARY_POINTERS
const char * BKE_main_blendfile_path_from_global()
MainListsArray BKE_main_lists_get(Main &bmain)
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()
@ LIB_ID_FREE_NO_USER_REFCOUNT
BlendThumbnail * BKE_main_thumbnail_from_imbuf(Main *bmain, ImBuf *img)
void MEM_delete_void(void *vmemh)
@ MAINIDRELATIONS_INCLUDE_UI
eMainIDRelationsEntryTags
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
void BKE_main_library_weak_reference_destroy(MainLibraryWeakReferenceMap *library_weak_reference_mapping) ATTR_NONNULL()
void IMB_colormanagement_working_space_init_default(Main *bmain)
bool BKE_main_needs_overwrite_confirm(const Main *bmain)
void BLI_mempool_destroy(BLI_mempool *pool) ATTR_NONNULL(1)
void BLI_spin_end(SpinLock *spin)
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
BlendThumbnail * BKE_main_thumbnail_from_buffer(Main *bmain, const uint8_t *rect, const int size[2])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
BMesh const char void * data
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()
BLI_mempool * BLI_mempool_create(unsigned int esize, unsigned int elem_num, unsigned int pchunk, unsigned int flag) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
bool BKE_main_has_issues(const Main *bmain)
void BKE_main_merge_as_archive_library(Main &bmain_dst, Main *&r_bmain_src, Library &dst_external_library, MainMergeReport &reports)
void BKE_main_merge(Main *bmain_dst, Set< ID * > *force_merge_src_ids, Main **r_bmain_src, MainMergeReport &reports)
void BKE_main_namemap_clear(Main &bmain)
@ LIBRARY_FLAG_IS_ARCHIVE
@ LIBRARY_FLAG_IS_EXTERNAL
void BKE_main_relations_create(Main *bmain, short flag)
bool BKE_main_namemap_validate(Main &bmain)
void BKE_main_relations_tag_set(Main *bmain, eMainIDRelationsEntryTags tag, bool value)
void BKE_main_free(Main *bmain)
void BLI_spin_unlock(SpinLock *spin)
Set< const ID * > * BKE_main_set_create(Main *bmain, Set< const ID * > *set)
void BLI_spin_init(SpinLock *spin)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
void IMB_byte_from_float(ImBuf *ibuf)
void BKE_main_unlock(Main *bmain)
ImBuf * IMB_allocFromBuffer(const uint8_t *byte_buffer, const float *float_buffer, unsigned int w, unsigned int h, unsigned int channels)
ID_Type GS(const char *name)
ID * BKE_main_library_weak_reference_find(Main *bmain, const char *library_filepath, const char *library_id_name)
void BKE_main_lock(Main *bmain)
void BKE_libblock_management_main_add(Main *bmain, void *idv)
int BLI_path_normalize_native(char *path) ATTR_NONNULL(1)
void * BLI_mempool_alloc(BLI_mempool *pool) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL ATTR_NONNULL(1)
@ ID_FLAG_LINKED_AND_PACKED
void BKE_main_clear(Main &bmain)
LibraryForeachIDCallbackFlag
void BKE_bpath_absolute_convert(Main *bmain, const char *basedir, ReportList *reports, BPathSummary *r_summary=nullptr)
void BKE_libblock_relink_multiple(Main *bmain, const Span< ID * > ids, eIDRemapType remap_type, bke::id::IDRemapper &id_remapper, int remap_flags)
void BLI_spin_lock(SpinLock *spin)
bool BKE_main_is_empty(Main *bmain)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
static int main_relations_create_idlink_cb(LibraryIDLinkCallbackData *cb_data)
const char * BKE_main_blendfile_path_from_library(const Library &library)
ListBaseT< ID > * which_libbase(Main *bmain, short type)
MainLibraryWeakReferenceMap * BKE_main_library_weak_reference_create(Main *bmain) ATTR_NONNULL()
void BKE_main_idmap_destroy(IDNameLib_Map *id_map) ATTR_NONNULL()
struct LibraryWeakReference * library_weak_reference
const uint8_t * byte_data() const
friend bool operator==(const LibWeakRefKey &a, const LibWeakRefKey &b)
LibWeakRefKey(const char *lib_path, const char *id_name)
char id_name[MAX_ID_NAME]
LibraryForeachIDCallbackFlag cb_flag
char library_filepath[1024]
char library_id_name[258]
struct Library * archive_parent_library
bke::library::LibraryRuntime * runtime
bool is_missing_opencolorio_config
LibraryForeachIDCallbackFlag usage_flag
MainIDRelationsEntryItem * next
union blender::MainIDRelationsEntryItem::@147225153336151171020043026201123101032025326304 id_pointer
MainIDRelationsEntryItem * from_ids
MainIDRelationsEntryItem * to_ids
Map< const ID *, MainIDRelationsEntry * > * relations_from_pointers
BLI_mempool * entry_items_pool
Map< LibWeakRefKey, ID * > map
int num_remapped_libraries
ListBaseT< Key > shapekeys
ListBaseT< wmWindowManager > wm
ListBaseT< Collection > collections
ListBaseT< bArmature > armatures
bool is_action_slot_to_id_map_dirty
ListBaseT< bGPdata > gpencils
MainIDRelations * relations
MainColorspace colorspace
ListBaseT< Lattice > lattices
std::shared_ptr< VectorSet< Main * > > split_mains
ListBaseT< Palette > palettes
ListBaseT< bNodeTree > nodetrees
ListBaseT< Curves > hair_curves
ListBaseT< Camera > cameras
UniqueName_Map * name_map_global
ListBaseT< MetaBall > metaballs
ListBaseT< FreestyleLineStyle > linestyles
ListBaseT< Library > libraries
ListBaseT< Light > lights
ListBaseT< World > worlds
ListBaseT< PointCloud > pointclouds
ListBaseT< MovieClip > movieclips
ListBaseT< Brush > brushes
ListBaseT< Material > materials
ListBaseT< Object > objects
ListBaseT< CacheFile > cachefiles
ListBaseT< Curve > curves
ListBaseT< PaintCurve > paintcurves
ListBaseT< WorkSpace > workspaces
UniqueName_Map * name_map
ListBaseT< Speaker > speakers
ListBaseT< bSound > sounds
ListBaseT< ParticleSettings > particles
bool has_forward_compatibility_issues
ListBaseT< Image > images
ListBaseT< bAction > actions
ListBaseT< Scene > scenes
ListBaseT< GreasePencil > grease_pencils
ListBaseT< LightProbe > lightprobes
ListBaseT< Tex > textures
BlendThumbnail * blen_thumb
ListBaseT< Volume > volumes
ListBaseT< bScreen > screens
Vector< Library * > archived_libraries