|
Blender V5.0
|
#include <BKE_blendfile.hh>
Inherits blender::NonCopyable, and blender::NonMovable.
Classes | |
| struct | IDAddOptions |
Public Types | |
| enum | IDAddOperations { NOP = 0 , MAKE_LOCAL = 1 << 0 , SET_FAKE_USER = 1 << 1 , SET_CLIPBOARD_MARK = 1 << 4 , CLEAR_DEPENDENCIES = 1 << 8 , ADD_DEPENDENCIES = 1 << 9 , DUPLICATE_DEPENDENCIES = 1 << 10 , MASK_INHERITED = (MAKE_LOCAL | CLEAR_DEPENDENCIES | ADD_DEPENDENCIES | DUPLICATE_DEPENDENCIES) , MASK_PER_ID_USAGE } |
Public Member Functions | |
| PartialWriteContext ()=delete | |
| PartialWriteContext (Main &reference_main) | |
| ~PartialWriteContext () | |
| ID * | id_add (const ID *id, IDAddOptions options, blender::FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> dependencies_filter_cb=nullptr) |
| ID * | id_create (short id_type, StringRefNull id_name, Library *library, IDAddOptions options) |
| void | id_delete (const ID *id) |
| void | remove_unused (bool clear_extra_user=false) |
| void | clear () |
| bool | is_valid () |
| bool | write (const char *write_filepath, int write_flags, int remap_mode, ReportList &reports) |
| bool | write (const char *write_filepath, ReportList &reports) |
Public Attributes | |
| Main | bmain = {} |
Partial blendfile writing.
This wrapper around the Main struct is designed to have a very short life span, during which it will contain independent copies of the IDs that are added to it.
In general, the G_MAIN data should not change while such a context exists, otherwise mapping info between the context content and the G_MAIN content cannot be kept up-to-date.
The context can then be written to disk, and destroyed.
It also has advanced ways to handle ID dependencies (and libraries for linked IDs), by allowing specific handling for each dependency individually. By using the dependencies_filter_cb optional parameter of id_add, it is possible to skip (ignore) certain dependencies, or make linked ones local in the context, etc.
Design task: #122061
Definition at line 179 of file BKE_blendfile.hh.
Control how to handle IDs and their dependencies when they are added to this context.
| Enumerator | |
|---|---|
| NOP | |
| MAKE_LOCAL | Do not keep linked info (library and/or liboverride references).
|
| SET_FAKE_USER | Set the 'fake user' flag to the added ID. Ensures that it is never auto-removed from the context, and always written to disk. |
| SET_CLIPBOARD_MARK | Set the 'clipboard' flag to the added ID. Ensures that it is treated as potential source data for a 'paste ID' operation. |
| CLEAR_DEPENDENCIES | Clear all dependency IDs that are not in the partial write context. Mutually exclusive with ADD_DEPENDENCIES. WARNING: This also means that dependencies like obdata, shape-keys or actions are not duplicated either. NOTE: Either CLEAR_DEPENDENCIES or ADD_DEPENDENCIES must be specified in the final operation flags for all ID dependencies. This can be achieved by |
| ADD_DEPENDENCIES | Also add (or reuse if already there) dependency IDs into the partial write context. Mutually exclusive with CLEAR_DEPENDENCIES. |
| DUPLICATE_DEPENDENCIES | For each explicitly added IDs (i.e. these with a fake user), ensure all of their dependencies are independent copies, instead of being shared with other explicitly added IDs. Only relevant with ADD_DEPENDENCIES.
|
| MASK_INHERITED | Operation flags that are (by default) inherited by all dependencies.
|
| MASK_PER_ID_USAGE | Operation flags that are defined by the #dependencies_filter_cb callback, if given.
|
Definition at line 232 of file BKE_blendfile.hh.
|
delete |
| blender::bke::blendfile::PartialWriteContext::PartialWriteContext | ( | Main & | reference_main | ) |
Definition at line 1779 of file blendfile.cc.
References BKE_main_blendfile_path(), BKE_main_idmap_create(), bmain, Main::colorspace, MAIN_IDMAP_TYPE_NAME, and MAIN_IDMAP_TYPE_UID.
| blender::bke::blendfile::PartialWriteContext::~PartialWriteContext | ( | ) |
Definition at line 1793 of file blendfile.cc.
References BKE_main_idmap_destroy().
| void blender::bke::blendfile::PartialWriteContext::clear | ( | ) |
Fully empty the partial write context.
Definition at line 2216 of file blendfile.cc.
References BKE_main_clear(), BKE_main_idmap_clear(), and bmain.
| ID * blender::bke::blendfile::PartialWriteContext::id_add | ( | const ID * | id, |
| PartialWriteContext::IDAddOptions | options, | ||
| blender::FunctionRef< IDAddOperations(LibraryIDLinkCallbackData *cb_data, IDAddOptions options)> | dependencies_filter_cb = nullptr ) |
Add a copy of the given ID to the partial write context.
| options | Control how the added ID (and its dependencies) are handled. See IDAddOptions and IDAddOperations above for details. If no #dependencies_filter_cb callback is specified, #options.operations must contain either CLEAR_DEPENDENCIES or ADD_DEPENDENCIES. |
| dependencies_filter_cb | Optional, a callback called for each ID usages, which returns specific operations flags for each ID usage. Currently, only accepted return values are the ones included in MASK_PER_ID_USAGE. Returned flags must always contain either CLEAR_DEPENDENCIES or ADD_DEPENDENCIES. |
Definition at line 1974 of file blendfile.cc.
References blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), blender::VectorSet< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), ADD_DEPENDENCIES, blender::Vector< T, InlineBufferCapacity, Allocator >::append(), BKE_id_owner_get(), BKE_library_foreach_ID_link(), BKE_main_idmap_lookup_uid(), BLI_assert, bmain, LibraryIDLinkCallbackData::cb_flag, CLEAR_DEPENDENCIES, CLOG_ERROR, CLOG_WARN, DUPLICATE_DEPENDENCIES, ID_FLAG_EMBEDDED_DATA, ID_IS_PACKED, LibraryIDLinkCallbackData::id_pointer, IDWALK_CB_EMBEDDED, IDWALK_CB_EMBEDDED_NOT_OWNING, IDWALK_CB_INTERNAL, IDWALK_CB_LOOPBACK, IDWALK_CB_NEVER_NULL, IDWALK_DO_INTERNAL_RUNTIME_POINTERS, IDWALK_RET_NOP, blender::VectorSet< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::is_empty(), LIB_ID_MAKELOCAL_FORCE_LOCAL, LIB_ID_MAKELOCAL_INDIRECT, LIB_ID_MAKELOCAL_LIBOVERRIDE_CLEAR, LOG_PARTIALWRITE, blender::Map< Key, Value, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::lookup(), MAKE_LOCAL, MASK_INHERITED, MASK_PER_ID_USAGE, ID::name, options, LibraryIDLinkCallbackData::owner_id, blender::VectorSet< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::pop(), ID::session_uid, and UNUSED_VARS_NDEBUG.
Referenced by blender::bke::asset_write_in_library(), bpy_lib_write(), copy_material_exec(), blender::ed::outliner::outliner_id_copy_tag(), pose_copy_exec(), blender::ed::vse::sequencer_write_copy_paste_file(), and view3d_copybuffer_exec().
| ID * blender::bke::blendfile::PartialWriteContext::id_create | ( | short | id_type, |
| const blender::StringRefNull | id_name, | ||
| Library * | library, | ||
| PartialWriteContext::IDAddOptions | options ) |
Add and return a new ID into the partial write context.
NOTE: Since this ID is created in the partial write buffer, by definition it has no matching counterpart in the current G_MAIN. Therefore, there is no need to add it to #matching_uid_map_, and its session_uid is not guaranteed to be constant (as it may be preempted later by another ID added from the current G_MAIN).
| options | Control how the created ID is handled. See IDAddOptions and IDAddOperations above for details, note that the only relevant operation flags currently are the SET_FAKE_USER and SET_CLIPBOARD_MARK ones. |
Definition at line 2160 of file blendfile.cc.
References BKE_id_new_in_lib(), BKE_main_idmap_insert_id(), bmain, blender::StringRefNull::c_str(), ID_TAG_TEMP_MAIN, id_us_min(), options, and ID::tag.
Referenced by blender::ed::vse::sequencer_write_copy_paste_file().
| void blender::bke::blendfile::PartialWriteContext::id_delete | ( | const ID * | id | ) |
Delete the copy of the given ID from the partial write context.
Definition at line 2179 of file blendfile.cc.
References BKE_id_delete(), BKE_main_idmap_lookup_uid(), BKE_main_idmap_remove_id(), and bmain.
| bool blender::bke::blendfile::PartialWriteContext::is_valid | ( | ) |
Debug: Check if the current partial write context is fully valid.
Currently, check if any ID in the context still has relations to IDs not in the context.
Definition at line 2222 of file blendfile.cc.
References blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::add(), BKE_library_foreach_ID_link(), bmain, CLOG_ERROR, blender::Set< Key, InlineBufferCapacity, ProbingStrategy, Hash, IsEqual, Slot, Allocator >::contains(), FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, IDWALK_CB_EMBEDDED, IDWALK_CB_EMBEDDED_NOT_OWNING, IDWALK_READONLY, IDWALK_RET_NOP, is_valid(), LOG_PARTIALWRITE, ID::name, and ID::session_uid.
Referenced by bpy_lib_write(), is_valid(), blender::ed::vse::sequencer_write_copy_paste_file(), and write().
| void blender::bke::blendfile::PartialWriteContext::remove_unused | ( | bool | clear_extra_user = false | ) |
Remove all unused IDs from the current context.
| clear_extra_user | If true, the runtime tag ensuring that IDs are written on disk will be cleared. In other words, only IDs flagged with 'fake user' and their dependencies will be kept. Allows to also remove IDs that were added to this context during the same editing session, and were not flagged as 'fake user'. |
Definition at line 2187 of file blendfile.cc.
References BKE_id_multi_tagged_delete(), BKE_lib_query_unused_ids_tag(), BKE_main_idmap_remove_id(), bmain, CLOG_DEBUG, LibQueryUnusedIDsData::do_linked_ids, LibQueryUnusedIDsData::do_local_ids, LibQueryUnusedIDsData::do_recursive, FOREACH_MAIN_ID_BEGIN, FOREACH_MAIN_ID_END, ID_TAG_DOIT, id_us_clear_real(), INDEX_ID_NULL, LOG_PARTIALWRITE, LibQueryUnusedIDsData::num_total, and ID::tag.
| bool blender::bke::blendfile::PartialWriteContext::write | ( | const char * | write_filepath, |
| int | write_flags, | ||
| int | remap_mode, | ||
| ReportList & | reports ) |
Write the content of the current context as a blendfile on disk.
Definition at line 2284 of file blendfile.cc.
References blender::Vector< T, InlineBufferCapacity, Allocator >::append(), BKE_id_delete(), BKE_library_make_local(), BLI_assert, BLI_assert_msg, BLO_write_file(), bmain, blender::Vector< T, InlineBufferCapacity, Allocator >::clear(), CLOG_WARN, is_valid(), lib, LISTBASE_FOREACH, LOG_PARTIALWRITE, BlendFileWriteParams::remap_mode, blender::Vector< T, InlineBufferCapacity, Allocator >::size(), and STREQ.
Referenced by blender::bke::asset_write_in_library(), bpy_lib_write(), copy_material_exec(), blender::ed::outliner::outliner_id_copy_exec(), blender::ed::vse::sequencer_write_copy_paste_file(), view3d_copybuffer_exec(), and write().
| bool blender::bke::blendfile::PartialWriteContext::write | ( | const char * | write_filepath, |
| ReportList & | reports ) |
Definition at line 2323 of file blendfile.cc.
References BLO_WRITE_PATH_REMAP_RELATIVE, and write().
| Main blender::bke::blendfile::PartialWriteContext::bmain = {} |
The temp Main itself, storing all IDs copied into this partial write context.
Definition at line 182 of file BKE_blendfile.hh.
Referenced by blender::bke::asset_write_in_library(), clear(), id_add(), id_create(), id_delete(), is_valid(), PartialWriteContext(), remove_unused(), view3d_copybuffer_exec(), and write().