Blender V5.0
BKE_undo_system.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4#pragma once
5
9
10#include "BLI_path_utils.hh"
11#include "BLI_utildefines.h"
12
13#include "DNA_ID.h"
14#include "DNA_listBase.h"
15#include "DNA_userdef_types.h"
16
17struct Main;
18struct UndoStep;
19struct UndoType;
20struct bContext;
21
22/* IDs */
23struct GreasePencil;
24struct Main;
25struct Mesh;
26struct Object;
27struct Scene;
28struct Text;
29
35/* UndoRefID_Mesh & friends. */
36#define UNDO_REF_ID_TYPE(ptr_ty) \
37 struct UndoRefID_##ptr_ty { \
38 struct ptr_ty *ptr; \
39 char name[MAX_ID_NAME]; \
40 char library_filepath_abs[FILE_MAX]; \
41 }
49
73
74struct UndoStep {
76 char name[64];
77 const UndoType *type;
79 size_t data_size;
81 bool skip;
91 /* Over alloc 'type->struct_size'. */
92};
93
99
106
107using UndoTypeForEachIDRefFn = void (*)(void *user_data, UndoRefID *id_ref);
108
109struct UndoType {
112 const char *name;
113
120 bool (*poll)(struct bContext *C);
121
129
130 bool (*step_encode)(bContext *C, Main *bmain, UndoStep *us);
131 void (*step_decode)(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final);
132
138 void (*step_free)(UndoStep *us);
139
141 UndoTypeForEachIDRefFn foreach_ID_ref_fn,
142 void *user_data);
143
146
150 size_t step_size;
151};
152
168
169/* -------------------------------------------------------------------- */
174
175extern const UndoType *BKE_UNDOSYS_TYPE_IMAGE;
180extern const UndoType *BKE_UNDOSYS_TYPE_TEXT;
181
183
184#define BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP(ty) ELEM(ty, BKE_UNDOSYS_TYPE_IMAGE)
185
190/* name optional */
191bool BKE_undosys_stack_has_undo(const UndoStack *ustack, const char *name);
193/* Called after #BKE_undosys_stack_init_from_main. */
202#define BKE_undosys_stack_limit_steps_and_memory_defaults(ustack) \
203 BKE_undosys_stack_limit_steps_and_memory(ustack, U.undosteps, (size_t)U.undomemory * 1024 * 1024)
204
207
212 bContext *C,
213 const char *name,
214 const UndoType *ut);
216
221 bContext *C,
222 const char *name,
223 const UndoType *ut);
225
227 const char *name,
228 const UndoType *ut);
231
241 const UndoStep *us_target,
242 const UndoStep *us_reference);
243
258 UndoStack *ustack, bContext *C, UndoStep *us_target, UndoStep *us_reference, bool use_skip);
262bool BKE_undosys_step_load_data(UndoStack *ustack, bContext *C, UndoStep *us_target);
267void BKE_undosys_step_load_from_index(UndoStack *ustack, bContext *C, int index);
268
281 bContext *C,
282 UndoStep *us_target,
283 bool use_skip);
294
307 bContext *C,
308 UndoStep *us_target,
309 bool use_skip);
320
329
330/* Type System. */
331
335UndoType *BKE_undosys_type_append(void (*undosys_fn)(UndoType *));
337
338/* ID Accessor. */
339
340#if 0 /* functionality is only used internally for now. */
341void BKE_undosys_foreach_ID_ref(UndoStack *ustack,
342 UndoTypeForEachIDRefFn foreach_ID_ref_fn,
343 void *user_data);
344#endif
345
346void BKE_undosys_print(UndoStack *ustack);
void BKE_undosys_step_load_from_index(UndoStack *ustack, bContext *C, int index)
eUndoTypeFlags
@ UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE
@ UNDOTYPE_FLAG_DECODE_ACTIVE_STEP
bool BKE_undosys_step_undo_with_data_ex(UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
bool BKE_undosys_stack_has_undo(const UndoStack *ustack, const char *name)
#define UNDO_REF_ID_TYPE(ptr_ty)
const UndoType * BKE_UNDOSYS_TYPE_SCULPT
bool BKE_undosys_step_redo_with_data(UndoStack *ustack, bContext *C, UndoStep *us_target)
void BKE_undosys_stack_init_from_context(UndoStack *ustack, bContext *C)
UndoStep * BKE_undosys_step_find_by_name_with_type(UndoStack *ustack, const char *name, const UndoType *ut)
bool BKE_undosys_step_redo(UndoStack *ustack, bContext *C)
UndoStep * BKE_undosys_step_find_by_type(UndoStack *ustack, const UndoType *ut)
UndoStep * BKE_undosys_step_same_type_next(UndoStep *us)
bool BKE_undosys_step_undo(UndoStack *ustack, bContext *C)
void BKE_undosys_stack_clear_active(UndoStack *ustack)
bool BKE_undosys_step_undo_with_data(UndoStack *ustack, bContext *C, UndoStep *us_target)
void(*)(void *user_data, UndoRefID *id_ref) UndoTypeForEachIDRefFn
eUndoPushReturn BKE_undosys_step_push(UndoStack *ustack, bContext *C, const char *name)
eUndoStepDir BKE_undosys_step_calc_direction(const UndoStack *ustack, const UndoStep *us_target, const UndoStep *us_reference)
const UndoType * BKE_UNDOSYS_TYPE_MEMFILE
UndoStep * BKE_undosys_step_same_type_prev(UndoStep *us)
const UndoType * BKE_UNDOSYS_TYPE_PARTICLE
eUndoStepDir
@ STEP_INVALID
@ STEP_UNDO
@ STEP_REDO
void BKE_undosys_type_free_all()
void BKE_undosys_stack_clear(UndoStack *ustack)
const UndoType * BKE_UNDOSYS_TYPE_TEXT
void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size_t memory_limit)
UndoStep * BKE_undosys_step_find_by_name(UndoStack *ustack, const char *name)
bool BKE_undosys_step_load_data_ex(UndoStack *ustack, bContext *C, UndoStep *us_target, UndoStep *us_reference, bool use_skip)
eUndoPushReturn
@ UNDO_PUSH_RET_SUCCESS
@ UNDO_PUSH_RET_OVERRIDE_CHANGED
@ UNDO_PUSH_RET_FAILURE
eUndoPushReturn BKE_undosys_step_push_with_type(UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
UndoStep * BKE_undosys_step_push_init_with_type(UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
void BKE_undosys_stack_destroy(UndoStack *ustack)
void BKE_undosys_stack_init_from_main(UndoStack *ustack, Main *bmain)
void BKE_undosys_stack_group_end(UndoStack *ustack)
UndoStep * BKE_undosys_stack_active_with_type(UndoStack *ustack, const UndoType *ut)
bool BKE_undosys_step_load_data(UndoStack *ustack, bContext *C, UndoStep *us_target)
UndoStack * BKE_undosys_stack_create()
const UndoType * BKE_UNDOSYS_TYPE_PAINTCURVE
bool BKE_undosys_step_redo_with_data_ex(UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
UndoType * BKE_undosys_type_append(void(*undosys_fn)(UndoType *))
void BKE_undosys_print(UndoStack *ustack)
UndoStep * BKE_undosys_stack_init_or_active_with_type(UndoStack *ustack, const UndoType *ut)
UndoStep * BKE_undosys_step_push_init(UndoStack *ustack, bContext *C, const char *name)
void BKE_undosys_stack_group_begin(UndoStack *ustack)
const UndoType * BKE_UNDOSYS_TYPE_IMAGE
#define FILE_MAX
unsigned int uint
#define ENUM_OPERATORS(_type, _max)
ID and Library types, which are fundamental for SDNA.
#define MAX_ID_NAME
Definition DNA_ID.h:373
These structs are the foundation for all linked lists in the library system.
#define C
Definition RandGen.cpp:29
const char * name
Definition DNA_ID.h:414
char name[MAX_ID_NAME]
struct ID * ptr
char library_filepath_abs[FILE_MAX]
UndoStep * step_init
UndoStep * step_active_memfile
UndoStep * step_active
ListBase steps
size_t data_size
UndoStep * prev
bool use_old_bmain_data
UndoStep * next
const UndoType * type
bool use_memfile_step
char name[64]
void(* step_encode_init)(bContext *C, UndoStep *us)
void(* step_foreach_ID_ref)(UndoStep *us, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
const char * name
void(* step_free)(UndoStep *us)
bool(* poll)(struct bContext *C)
void(* step_decode)(bContext *C, Main *bmain, UndoStep *us, eUndoStepDir dir, bool is_final)
UndoType * prev
UndoType * next
bool(* step_encode)(bContext *C, Main *bmain, UndoStep *us)
size_t memory_limit