43#define undo_stack _wm_undo_stack_disallow
46#define WITH_GLOBAL_UNDO_KEEP_ONE
49#define WITH_GLOBAL_UNDO_ENSURE_UPDATED
55#define WITH_GLOBAL_UNDO_CORRECT_ORDER
86 if (ut.poll && ut.poll(
C)) {
103#define WITH_NESTED_UNDO_CHECK
105#ifdef WITH_NESTED_UNDO_CHECK
107# define UNDO_NESTED_ASSERT(state) BLI_assert(g_undo_callback_running == state)
108# define UNDO_NESTED_CHECK_BEGIN \
110 UNDO_NESTED_ASSERT(false); \
111 g_undo_callback_running = true; \
114# define UNDO_NESTED_CHECK_END \
116 UNDO_NESTED_ASSERT(true); \
117 g_undo_callback_running = false; \
121# define UNDO_NESTED_ASSERT(state) ((void)0)
122# define UNDO_NESTED_CHECK_BEGIN ((void)0)
123# define UNDO_NESTED_CHECK_END ((void)0)
148 id_ref->
ptr =
nullptr;
156 Main *bmain =
static_cast<Main *
>(user_data);
177#ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
199#ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
227#ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
243#ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
249 G_MAIN->is_memfile_undo_written =
false;
270 if (expect_non_empty) {
294 for (
UndoStep *us = ustack->
steps.last(), *us_prev; us; us = us_prev) {
302 ustack->
steps.clear_no_delete();
312 while (us && us->
skip) {
317 bool is_not_empty = ustack->
step_active !=
nullptr;
331 bool is_not_empty =
true;
334 us_iter = ustack->
steps.last();
338 }
while (us != us_iter);
344 if (us && us == us_exclude) {
349 bool is_not_empty =
true;
352 us_iter = ustack->
steps.first();
353 if (us_iter == us_exclude) {
354 us_iter = us_iter->
next;
359 }
while (us != us_iter);
395 return us && us->
prev;
398 return !ustack->
steps.is_empty();
412 while (us && (us->
type != ut)) {
430 if ((steps == -1) && (memory_limit == 0)) {
434 CLOG_DEBUG(&
LOG,
"Limit steps=%d, memory_limit=%zu", steps, memory_limit);
438 size_t data_size_all = 0;
440 for (us = ustack->
steps.last(); us && us->
prev; us = us->
prev) {
443 if (data_size_all > memory_limit) {
445 "At step %zu: data_size_all=%zu >= memory_limit=%zu",
453 if (us_count == steps) {
456 if (us->
skip ==
false) {
462 CLOG_DEBUG(&
LOG,
"Total steps %zu: data_size_all=%zu", us_count, data_size_all);
465#ifdef WITH_GLOBAL_UNDO_KEEP_ONE
468 us_exclude = us->
prev;
470 us_exclude = us_exclude->
prev;
476 us_exclude->
skip =
true;
510 if (name !=
nullptr) {
545 bool is_not_empty = ustack->
step_active !=
nullptr;
552 G_MAIN,
false,
reinterpret_cast<int *
>(&report_flags));
574#ifdef WITH_GLOBAL_UNDO_ENSURE_UPDATED
576 if (
G_MAIN->is_memfile_undo_written ==
false || force_memfile_step) {
577 const char *name_internal =
"MemFile Internal (pre)";
588# ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
596 bool use_memfile_step =
false;
602 if (us->
name[0] ==
'\0') {
634 if (use_memfile_step) {
638 const char *name_internal = us_prev->
name;
643 us_prev->
skip =
true;
644#ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
679 while ((us = us->
next)) {
680 if (us->
type == ut) {
692 while ((us = us->
prev)) {
693 if (us->
type == ut) {
707 if (
STREQ(name, us.name)) {
734 if (us_reference ==
nullptr) {
746 if (
ELEM(us_target, us_reference, us_reference->
prev)) {
749 if (us_target == us_reference->
next) {
754 for (
UndoStep *us_iter = us_reference->
next; us_iter !=
nullptr; us_iter = us_iter->
next) {
755 if (us_iter == us_target) {
759 for (
UndoStep *us_iter = us_reference->
prev; us_iter !=
nullptr; us_iter = us_iter->
prev) {
760 if (us_iter == us_target) {
766 "Target undo step not found, this should not happen and may indicate an undo "
782 return (undo_dir == -1) ? us_reference : us_reference->
next;
786 return (undo_dir == -1) ? us_reference->
prev : us_reference->
next;
796 if (us_target ==
nullptr) {
802 if (us_reference ==
nullptr) {
805 if (us_reference ==
nullptr) {
806 CLOG_ERROR(&
LOG,
"could not find a valid initial active target step as reference");
818 UndoStep *us_target_active = us_target;
820 while (us_target_active !=
nullptr && us_target_active->
skip) {
821 us_target_active = (undo_dir == -1) ? us_target_active->
prev : us_target_active->
next;
823 if (us_target_active ==
nullptr) {
825 "undo/redo did not find a step after stepping over skip-steps "
826 "(undo limit exceeded)");
832 "addr=%p, name='%s', type='%s', undo_dir=%d",
840 bool is_processing_extra_skipped_steps =
false;
842 us_iter = (undo_dir == -1) ? us_iter->
prev : us_iter->
next)
846 const bool is_final = (us_iter == us_target_active);
848 if (!is_final && is_processing_extra_skipped_steps) {
851 "undo/redo continue with skip addr=%p, name='%s', type='%s'",
854 us_iter->type->identifier);
860 if (us_iter == us_target) {
861 is_processing_extra_skipped_steps =
true;
872 "This should never be reached, either undo stack is corrupted, or code above is buggy");
949 UndoType *ut = MEM_new<UndoType>(__func__);
1043 printf(
"No undo steps recorded yet.\n");
1046 printf(
"Undo %d Steps (*: active, #=applied, M=memfile-active, S=skip)\n",
1047 ustack->
steps.count());
1050 printf(
"[%c%c%c%c] %3d {%p} type='%s', name='%s'\n",
1054 us.
skip ?
'S' :
' ',
1056 static_cast<void *
>(&us),
#define CLOG_ERROR(clg_ref,...)
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_INFO(clg_ref,...)
These structs are the foundation for all linked lists in the library system.
Read Blender memory allocation and freeing.
#define UNUSED_FUNCTION(x)
#define BLI_assert_unreachable()
#define BLI_assert_msg(a, msg)
@ RNA_OVERRIDE_MATCH_RESULT_CREATED
@ RNA_OVERRIDE_MATCH_RESULT_INIT
void BKE_undosys_stack_init_from_main(UndoStack *ustack, Main *bmain)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_undosys_type_free_all()
char * STRNCPY(char(&dst)[N], const char *src)
static UndoStep * undosys_step_iter_first(UndoStep *us_reference, const eUndoStepDir undo_dir)
UndoStep * BKE_undosys_step_same_type_next(UndoStep *us)
bool BKE_undosys_stack_has_undo(const UndoStack *ustack, const char *name)
static void undosys_stack_clear_all_first(UndoStack *ustack, UndoStep *us, UndoStep *us_exclude)
@ UNDOTYPE_FLAG_DECODE_ACTIVE_STEP
@ UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE
@ UNDOTYPE_FLAG_ENCODE_PRE_MEMFILE_SUPPORTED
const UndoType * BKE_UNDOSYS_TYPE_PAINTCURVE
const UndoType * BKE_UNDOSYS_TYPE_PARTICLE
bool BKE_undosys_step_redo_with_data(UndoStack *ustack, bContext *C, UndoStep *us_target)
ID * BKE_libblock_find_name_and_library_filepath(Main *bmain, short type, const char *name, const char *lib_filepath_abs)
void BKE_undosys_stack_clear_active(UndoStack *ustack)
void BKE_undosys_stack_group_end(UndoStack *ustack)
static void undosys_id_ref_resolve(void *user_data, UndoRefID *id_ref)
void * BLI_rfindstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static bool undosys_stack_push_main(UndoStack *ustack, const char *name, Main *bmain)
static void undosys_step_decode(bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us, const eUndoStepDir dir, bool is_final)
UndoStack * BKE_undosys_stack_create()
bool BKE_undosys_step_undo_with_data_ex(UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
bool BKE_undosys_step_load_data(UndoStack *ustack, bContext *C, UndoStep *us_target)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void BKE_undosys_stack_group_begin(UndoStack *ustack)
static bool undosys_step_encode(bContext *C, Main *bmain, UndoStack *ustack, UndoStep *us)
void BKE_undosys_stack_clear(UndoStack *ustack)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
eUndoStepDir BKE_undosys_step_calc_direction(const UndoStack *ustack, const UndoStep *us_target, const UndoStep *us_reference)
static void undosys_id_ref_store(void *, UndoRefID *id_ref)
void BKE_undosys_print(UndoStack *ustack)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BKE_undosys_step_load_from_index(UndoStack *ustack, bContext *C, int index)
static void undosys_step_free_and_unlink(UndoStack *ustack, UndoStep *us)
const UndoType * BKE_UNDOSYS_TYPE_TEXT
bool BKE_undosys_type_foreach(FunctionRef< bool(const UndoType *ut)> fn)
UndoStep * BKE_undosys_stack_init_or_active_with_type(UndoStack *ustack, const UndoType *ut)
static void undosys_stack_validate(UndoStack *ustack, bool expect_non_empty)
void CTX_free(bContext *C)
const UndoType * BKE_UNDOSYS_TYPE_SCULPT
static void undosys_stack_clear_all_last(UndoStack *ustack, UndoStep *us)
static ListBaseT< UndoType > g_undo_types
const UndoType * BKE_UNDOSYS_TYPE_MEMFILE
bool BKE_undosys_step_undo(UndoStack *ustack, bContext *C)
bool BKE_undosys_step_undo_with_data(UndoStack *ustack, bContext *C, UndoStep *us_target)
bool BKE_undosys_step_redo(UndoStack *ustack, bContext *C)
void BKE_lib_override_library_main_operations_create(Main *bmain, bool force_auto, int *r_report_flags)
static bool g_undo_callback_running
UndoStep * BKE_undosys_step_push_init(UndoStack *ustack, bContext *C, const char *name)
UndoStep * BKE_undosys_stack_active_with_type(UndoStack *ustack, const UndoType *ut)
@ UNDO_PUSH_RET_OVERRIDE_CHANGED
void bke_undo_system_linker_workaround()
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void BKE_undosys_stack_init_from_context(UndoStack *ustack, bContext *C)
ID_Type GS(const char *name)
void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size_t memory_limit)
bool BKE_undosys_stack_has_redo(const UndoStack *ustack)
UndoStep * BKE_undosys_step_find_by_name_with_type(UndoStack *ustack, const char *name, const UndoType *ut)
void(*)(void *user_data, UndoRefID *id_ref) UndoTypeForEachIDRefFn
UndoStep * BKE_undosys_step_same_type_prev(UndoStep *us)
void CTX_data_main_set(bContext *C, Main *bmain)
bool BKE_undosys_step_load_data_ex(UndoStack *ustack, bContext *C, UndoStep *us_target, UndoStep *us_reference, bool use_skip)
UndoStep * BKE_undosys_step_find_by_name(UndoStack *ustack, const char *name)
void BKE_undosys_stack_destroy(UndoStack *ustack)
UndoStep * BKE_undosys_step_find_by_type(UndoStack *ustack, const UndoType *ut)
eUndoPushReturn BKE_undosys_step_push_with_type(UndoStack *ustack, bContext *C, const char *name, UndoEncodeHints hints, const UndoType *ut)
bool BKE_undosys_step_redo_with_data_ex(UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
const UndoType * BKE_UNDOSYS_TYPE_IMAGE
const UndoType * BKE_undosys_type_from_context(bContext *C)
void BKE_memfile_undo_free(MemFileUndoData *mfu)
UndoType * BKE_undosys_type_append(void(*undosys_fn)(UndoType *))
eUndoPushReturn BKE_undosys_step_push(UndoStack *ustack, bContext *C, const char *name, UndoEncodeHints hints)
UndoStep * BKE_undosys_step_push_init_with_type(UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
bke::library::LibraryRuntime * runtime
char library_filepath_abs[FILE_MAX]
UndoStep * step_active_memfile
ListBaseT< UndoStep > steps
void(*) step_free(UndoStep *us)
void(*) step_decode(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final)
void(*) step_foreach_ID_ref(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
bool(*) step_encode(bContext *C, Main *bmain, UndoStep *us)
void(*) step_encode_init(bContext *C, UndoStep *us)
#define UNDO_NESTED_CHECK_END
#define UNDO_NESTED_CHECK_BEGIN
#define UNDO_NESTED_ASSERT(state)