Blender V5.0
BKE_undo_system.hh File Reference
#include "BLI_path_utils.hh"
#include "BLI_utildefines.h"
#include "DNA_ID.h"
#include "DNA_listBase.h"
#include "DNA_userdef_types.h"

Go to the source code of this file.

Classes

struct  UndoRefID
struct  UndoStack
struct  UndoStep
struct  UndoType

Macros

#define UNDO_REF_ID_TYPE(ptr_ty)
#define BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP(ty)
#define BKE_undosys_stack_limit_steps_and_memory_defaults(ustack)

Typedefs

using UndoTypeForEachIDRefFn = void (*)(void *user_data, UndoRefID *id_ref)

Enumerations

enum  eUndoStepDir { STEP_REDO = 1 , STEP_UNDO = -1 , STEP_INVALID = 0 }
enum  eUndoPushReturn { UNDO_PUSH_RET_FAILURE = 0 , UNDO_PUSH_RET_SUCCESS = (1 << 0) , UNDO_PUSH_RET_OVERRIDE_CHANGED = (1 << 1) }
enum  eUndoTypeFlags { UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE = 1 << 0 , UNDOTYPE_FLAG_DECODE_ACTIVE_STEP = 1 << 1 }

Functions

 UNDO_REF_ID_TYPE (GreasePencil)
 UNDO_REF_ID_TYPE (Mesh)
 UNDO_REF_ID_TYPE (Object)
 UNDO_REF_ID_TYPE (Scene)
 UNDO_REF_ID_TYPE (Text)
 UNDO_REF_ID_TYPE (Image)
 UNDO_REF_ID_TYPE (PaintCurve)
UndoStackBKE_undosys_stack_create ()
void BKE_undosys_stack_destroy (UndoStack *ustack)
void BKE_undosys_stack_clear (UndoStack *ustack)
void BKE_undosys_stack_clear_active (UndoStack *ustack)
bool BKE_undosys_stack_has_undo (const UndoStack *ustack, const char *name)
void BKE_undosys_stack_init_from_main (UndoStack *ustack, Main *bmain)
void BKE_undosys_stack_init_from_context (UndoStack *ustack, bContext *C)
UndoStepBKE_undosys_stack_active_with_type (UndoStack *ustack, const UndoType *ut)
UndoStepBKE_undosys_stack_init_or_active_with_type (UndoStack *ustack, const UndoType *ut)
void BKE_undosys_stack_limit_steps_and_memory (UndoStack *ustack, int steps, size_t memory_limit)
void BKE_undosys_stack_group_begin (UndoStack *ustack)
void BKE_undosys_stack_group_end (UndoStack *ustack)
UndoStepBKE_undosys_step_push_init_with_type (UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
UndoStepBKE_undosys_step_push_init (UndoStack *ustack, bContext *C, const char *name)
eUndoPushReturn BKE_undosys_step_push_with_type (UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
eUndoPushReturn BKE_undosys_step_push (UndoStack *ustack, bContext *C, const char *name)
UndoStepBKE_undosys_step_find_by_name_with_type (UndoStack *ustack, const char *name, const UndoType *ut)
UndoStepBKE_undosys_step_find_by_type (UndoStack *ustack, const UndoType *ut)
UndoStepBKE_undosys_step_find_by_name (UndoStack *ustack, const char *name)
eUndoStepDir BKE_undosys_step_calc_direction (const UndoStack *ustack, const UndoStep *us_target, const UndoStep *us_reference)
bool BKE_undosys_step_load_data_ex (UndoStack *ustack, bContext *C, UndoStep *us_target, UndoStep *us_reference, bool use_skip)
bool BKE_undosys_step_load_data (UndoStack *ustack, bContext *C, UndoStep *us_target)
void BKE_undosys_step_load_from_index (UndoStack *ustack, bContext *C, int index)
bool BKE_undosys_step_undo_with_data_ex (UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
bool BKE_undosys_step_undo_with_data (UndoStack *ustack, bContext *C, UndoStep *us_target)
bool BKE_undosys_step_undo (UndoStack *ustack, bContext *C)
bool BKE_undosys_step_redo_with_data_ex (UndoStack *ustack, bContext *C, UndoStep *us_target, bool use_skip)
bool BKE_undosys_step_redo_with_data (UndoStack *ustack, bContext *C, UndoStep *us_target)
bool BKE_undosys_step_redo (UndoStack *ustack, bContext *C)
UndoStepBKE_undosys_step_same_type_next (UndoStep *us)
UndoStepBKE_undosys_step_same_type_prev (UndoStep *us)
UndoTypeBKE_undosys_type_append (void(*undosys_fn)(UndoType *))
void BKE_undosys_type_free_all ()
void BKE_undosys_print (UndoStack *ustack)

Variables

Public Undo Types

Expose since we need to perform operations on specific undo types (rarely).

const UndoTypeBKE_UNDOSYS_TYPE_IMAGE
const UndoTypeBKE_UNDOSYS_TYPE_MEMFILE
const UndoTypeBKE_UNDOSYS_TYPE_PAINTCURVE
const UndoTypeBKE_UNDOSYS_TYPE_PARTICLE
const UndoTypeBKE_UNDOSYS_TYPE_SCULPT
const UndoTypeBKE_UNDOSYS_TYPE_TEXT

Macro Definition Documentation

◆ BKE_undosys_stack_limit_steps_and_memory_defaults

#define BKE_undosys_stack_limit_steps_and_memory_defaults ( ustack)
Value:
BKE_undosys_stack_limit_steps_and_memory(ustack, U.undosteps, (size_t)U.undomemory * 1024 * 1024)
void BKE_undosys_stack_limit_steps_and_memory(UndoStack *ustack, int steps, size_t memory_limit)
#define U

Definition at line 202 of file BKE_undo_system.hh.

Referenced by ED_image_undo_push_end(), ED_paintcurve_undo_push_end(), and blender::ed::sculpt_paint::undo::geometry_end().

◆ BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP

#define BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP ( ty)
Value:
const UndoType * BKE_UNDOSYS_TYPE_IMAGE
#define ELEM(...)

Definition at line 184 of file BKE_undo_system.hh.

Referenced by memfile_undosys_step_decode().

◆ UNDO_REF_ID_TYPE

#define UNDO_REF_ID_TYPE ( ptr_ty)
Value:
struct UndoRefID_##ptr_ty { \
struct ptr_ty *ptr; \
char name[MAX_ID_NAME]; \
char library_filepath_abs[FILE_MAX]; \
}
#define FILE_MAX
#define MAX_ID_NAME
Definition DNA_ID.h:373
const char * name
PointerRNA * ptr
Definition wm_files.cc:4238

Definition at line 36 of file BKE_undo_system.hh.

Typedef Documentation

◆ UndoTypeForEachIDRefFn

using UndoTypeForEachIDRefFn = void (*)(void *user_data, UndoRefID *id_ref)

Definition at line 107 of file BKE_undo_system.hh.

Enumeration Type Documentation

◆ eUndoPushReturn

Enumerator
UNDO_PUSH_RET_FAILURE 
UNDO_PUSH_RET_SUCCESS 
UNDO_PUSH_RET_OVERRIDE_CHANGED 

Definition at line 100 of file BKE_undo_system.hh.

◆ eUndoStepDir

Enumerator
STEP_REDO 
STEP_UNDO 
STEP_INVALID 

Definition at line 94 of file BKE_undo_system.hh.

◆ eUndoTypeFlags

#UndoType.flag bit-flags.

Enumerator
UNDOTYPE_FLAG_NEED_CONTEXT_FOR_ENCODE 

This undo type encode callback needs a valid context, it will fail otherwise.

Note
Callback is still supposed to properly deal with a NULL context pointer.
UNDOTYPE_FLAG_DECODE_ACTIVE_STEP 

When the active undo step is of this type, it must be read before loading other undo steps.

This is typically used for undo systems that store both before/after states.

Definition at line 154 of file BKE_undo_system.hh.

Function Documentation

◆ BKE_undosys_print()

void BKE_undosys_print ( UndoStack * ustack)

◆ BKE_undosys_stack_active_with_type()

UndoStep * BKE_undosys_stack_active_with_type ( UndoStack * ustack,
const UndoType * ut )

◆ BKE_undosys_stack_clear()

◆ BKE_undosys_stack_clear_active()

void BKE_undosys_stack_clear_active ( UndoStack * ustack)

◆ BKE_undosys_stack_create()

UndoStack * BKE_undosys_stack_create ( )

Definition at line 270 of file undo_system.cc.

References MEM_callocN().

Referenced by ed_undo_push_exec(), and wm_file_read_post().

◆ BKE_undosys_stack_destroy()

void BKE_undosys_stack_destroy ( UndoStack * ustack)

◆ BKE_undosys_stack_group_begin()

void BKE_undosys_stack_group_begin ( UndoStack * ustack)

Definition at line 943 of file undo_system.cc.

References BLI_assert, and UndoStack::group_level.

Referenced by ED_undo_group_begin().

◆ BKE_undosys_stack_group_end()

void BKE_undosys_stack_group_end ( UndoStack * ustack)

◆ BKE_undosys_stack_has_undo()

bool BKE_undosys_stack_has_undo ( const UndoStack * ustack,
const char * name )

◆ BKE_undosys_stack_init_from_context()

void BKE_undosys_stack_init_from_context ( UndoStack * ustack,
bContext * C )

◆ BKE_undosys_stack_init_from_main()

void BKE_undosys_stack_init_from_main ( UndoStack * ustack,
Main * bmain )

Definition at line 364 of file undo_system.cc.

References IFACE_, UNDO_NESTED_ASSERT, and undosys_stack_push_main().

Referenced by wm_file_read_post().

◆ BKE_undosys_stack_init_or_active_with_type()

◆ BKE_undosys_stack_limit_steps_and_memory()

void BKE_undosys_stack_limit_steps_and_memory ( UndoStack * ustack,
int steps,
size_t memory_limit )
Parameters
stepsLimit the number of undo steps.
memory_limitLimit the amount of memory used by the undo stack.

Definition at line 408 of file undo_system.cc.

References BKE_UNDOSYS_TYPE_MEMFILE, CLOG_DEBUG, UndoStep::data_size, ListBase::last, LOG, memory_limit, UndoStep::prev, UndoStep::skip, UndoStack::steps, UndoStep::type, UNDO_NESTED_ASSERT, and undosys_stack_clear_all_first().

Referenced by ED_undo_push().

◆ BKE_undosys_step_calc_direction()

eUndoStepDir BKE_undosys_step_calc_direction ( const UndoStack * ustack,
const UndoStep * us_target,
const UndoStep * us_reference )

Return direction of the undo/redo from us_reference (or ustack->step_active if NULL), and us_target.

Note
If us_reference and us_target are the same, we consider this is an undo.
Returns
-1 for undo, 1 for redo, 0 in case of error.

Definition at line 687 of file undo_system.cc.

References BLI_assert, BLI_assert_msg, ELEM, UndoStep::next, UndoStep::prev, UndoStack::step_active, STEP_INVALID, STEP_REDO, and STEP_UNDO.

Referenced by BKE_undosys_step_load_data_ex(), BKE_undosys_step_redo_with_data_ex(), BKE_undosys_step_undo_with_data_ex(), and ed_undo_step_by_name().

◆ BKE_undosys_step_find_by_name()

UndoStep * BKE_undosys_step_find_by_name ( UndoStack * ustack,
const char * name )

Definition at line 672 of file undo_system.cc.

References BLI_rfindstring(), name, offsetof, and UndoStack::steps.

Referenced by ed_undo_step_by_name().

◆ BKE_undosys_step_find_by_name_with_type()

UndoStep * BKE_undosys_step_find_by_name_with_type ( UndoStack * ustack,
const char * name,
const UndoType * ut )

Definition at line 658 of file undo_system.cc.

References LISTBASE_FOREACH_BACKWARD, name, UndoStack::steps, and STREQ.

◆ BKE_undosys_step_find_by_type()

UndoStep * BKE_undosys_step_find_by_type ( UndoStack * ustack,
const UndoType * ut )

Definition at line 677 of file undo_system.cc.

References LISTBASE_FOREACH_BACKWARD, and UndoStack::steps.

Referenced by memfile_undosys_step_encode().

◆ BKE_undosys_step_load_data()

bool BKE_undosys_step_load_data ( UndoStack * ustack,
bContext * C,
UndoStep * us_target )

Undo/Redo until the given us_target step becomes the active (currently loaded) one.

Definition at line 833 of file undo_system.cc.

References BKE_undosys_step_load_data_ex(), and C.

Referenced by BKE_undosys_step_load_from_index().

◆ BKE_undosys_step_load_data_ex()

bool BKE_undosys_step_load_data_ex ( UndoStack * ustack,
bContext * C,
UndoStep * us_target,
UndoStep * us_reference,
bool use_skip )

Undo/Redo until the given us_target step becomes the active (currently loaded) one.

Note
Unless us_target is a 'skipped' one and use_skip is true, us_target will become the active step.
In case use_skip is true, the final target will always be beyond the given one (if the given one has to be skipped).
Parameters
us_referenceIf NULL, will be set to current active step in the undo stack. Otherwise, it is assumed to match the current state, and will be used as basis for the undo/redo process (i.e. all steps in-between us_reference and us_target will be processed).

Definition at line 746 of file undo_system.cc.

References BKE_undosys_step_calc_direction(), BLI_assert, BLI_assert_msg, C, CLOG_DEBUG, CLOG_ERROR, G_MAIN, LOG, UndoStep::name, UndoType::name, UndoStep::next, UndoStep::prev, UndoStep::skip, UndoStack::step_active, STEP_INVALID, UndoStep::type, UNDO_NESTED_ASSERT, undosys_stack_validate(), undosys_step_decode(), and undosys_step_iter_first().

Referenced by BKE_undosys_step_load_data(), BKE_undosys_step_redo_with_data_ex(), BKE_undosys_step_undo_with_data_ex(), and ed_undo_step_by_name().

◆ BKE_undosys_step_load_from_index()

void BKE_undosys_step_load_from_index ( UndoStack * ustack,
bContext * C,
int index )

Undo/Redo until the step matching given index in the undo stack becomes the active (currently loaded) one.

Definition at line 839 of file undo_system.cc.

References BKE_undosys_step_load_data(), BLI_assert, BLI_findlink(), C, UndoStep::skip, UndoStack::step_active, and UndoStack::steps.

Referenced by ed_undo_step_by_index().

◆ BKE_undosys_step_push()

◆ BKE_undosys_step_push_init()

UndoStep * BKE_undosys_step_push_init ( UndoStack * ustack,
bContext * C,
const char * name )

◆ BKE_undosys_step_push_init_with_type()

◆ BKE_undosys_step_push_with_type()

◆ BKE_undosys_step_redo()

bool BKE_undosys_step_redo ( UndoStack * ustack,
bContext * C )

Redo one step from current active one.

Definition at line 896 of file undo_system.cc.

References BKE_undosys_step_redo_with_data(), C, UndoStep::next, and UndoStack::step_active.

Referenced by ed_undo_step_direction().

◆ BKE_undosys_step_redo_with_data()

bool BKE_undosys_step_redo_with_data ( UndoStack * ustack,
bContext * C,
UndoStep * us_target )

Redo until us_target step becomes the active (currently loaded) one.

Note
See BKE_undosys_step_redo_with_data_ex for details.

Definition at line 891 of file undo_system.cc.

References BKE_undosys_step_redo_with_data_ex(), and C.

Referenced by BKE_undosys_step_redo().

◆ BKE_undosys_step_redo_with_data_ex()

bool BKE_undosys_step_redo_with_data_ex ( UndoStack * ustack,
bContext * C,
UndoStep * us_target,
bool use_skip )

Redo until us_target step becomes the active (currently loaded) one.

Warning
This function assumes that the given target step is after current active one.
Note
Unless us_target is a 'skipped' one and use_skip is true, us_target will become the active step.
In case use_skip is true, the final target will always be after the given one (if the given one has to be skipped).

Definition at line 877 of file undo_system.cc.

References BKE_undosys_step_calc_direction(), BKE_undosys_step_load_data_ex(), BLI_assert, C, UndoStep::prev, and UndoStack::step_active.

Referenced by BKE_undosys_step_redo_with_data().

◆ BKE_undosys_step_same_type_next()

UndoStep * BKE_undosys_step_same_type_next ( UndoStep * us)

Useful when we want to diff against previous undo data but can't be sure the types match.

Definition at line 632 of file undo_system.cc.

References UndoStep::next, and UndoStep::type.

Referenced by memfile_undosys_step_free().

◆ BKE_undosys_step_same_type_prev()

UndoStep * BKE_undosys_step_same_type_prev ( UndoStep * us)

Useful when we want to diff against previous undo data but can't be sure the types match.

Definition at line 645 of file undo_system.cc.

References UndoStep::prev, and UndoStep::type.

◆ BKE_undosys_step_undo()

bool BKE_undosys_step_undo ( UndoStack * ustack,
bContext * C )

Undo one step from current active (currently loaded) one.

Definition at line 869 of file undo_system.cc.

References BKE_undosys_step_undo_with_data(), C, UndoStep::prev, and UndoStack::step_active.

Referenced by ed_undo_step_direction().

◆ BKE_undosys_step_undo_with_data()

bool BKE_undosys_step_undo_with_data ( UndoStack * ustack,
bContext * C,
UndoStep * us_target )

Undo until us_target step becomes the active (currently loaded) one.

Note
See BKE_undosys_step_undo_with_data_ex for details.

Definition at line 864 of file undo_system.cc.

References BKE_undosys_step_undo_with_data_ex(), and C.

Referenced by BKE_undosys_step_undo().

◆ BKE_undosys_step_undo_with_data_ex()

bool BKE_undosys_step_undo_with_data_ex ( UndoStack * ustack,
bContext * C,
UndoStep * us_target,
bool use_skip )

Undo until us_target step becomes the active (currently loaded) one.

Warning
This function assumes that the given target step is before current active one.
Note
Unless us_target is a 'skipped' one and use_skip is true, us_target will become the active step.
In case use_skip is true, the final target will always be before the given one (if the given one has to be skipped).

Definition at line 849 of file undo_system.cc.

References BKE_undosys_step_calc_direction(), BKE_undosys_step_load_data_ex(), BLI_assert, C, and UndoStack::step_active.

Referenced by BKE_undosys_step_undo_with_data().

◆ BKE_undosys_type_append()

UndoType * BKE_undosys_type_append ( void(* undosys_fn )(UndoType *))

Similar to WM_operatortype_append

Definition at line 904 of file undo_system.cc.

References BLI_addtail(), g_undo_types, and MEM_callocN().

Referenced by ED_undosys_type_init().

◆ BKE_undosys_type_free_all()

void BKE_undosys_type_free_all ( )

Definition at line 915 of file undo_system.cc.

References BLI_pophead(), g_undo_types, and MEM_freeN().

Referenced by ED_undosys_type_free().

◆ UNDO_REF_ID_TYPE() [1/7]

UNDO_REF_ID_TYPE ( GreasePencil )

◆ UNDO_REF_ID_TYPE() [2/7]

UNDO_REF_ID_TYPE ( Image )

◆ UNDO_REF_ID_TYPE() [3/7]

UNDO_REF_ID_TYPE ( Mesh )

◆ UNDO_REF_ID_TYPE() [4/7]

UNDO_REF_ID_TYPE ( Object )

◆ UNDO_REF_ID_TYPE() [5/7]

UNDO_REF_ID_TYPE ( PaintCurve )

◆ UNDO_REF_ID_TYPE() [6/7]

UNDO_REF_ID_TYPE ( Scene )

◆ UNDO_REF_ID_TYPE() [7/7]

UNDO_REF_ID_TYPE ( Text )

Variable Documentation

◆ BKE_UNDOSYS_TYPE_IMAGE

const UndoType* BKE_UNDOSYS_TYPE_IMAGE
extern

◆ BKE_UNDOSYS_TYPE_MEMFILE

◆ BKE_UNDOSYS_TYPE_PAINTCURVE

const UndoType* BKE_UNDOSYS_TYPE_PAINTCURVE
extern

Definition at line 64 of file undo_system.cc.

Referenced by ED_paintcurve_undo_push_begin(), and ED_undosys_type_init().

◆ BKE_UNDOSYS_TYPE_PARTICLE

const UndoType* BKE_UNDOSYS_TYPE_PARTICLE
extern

Definition at line 65 of file undo_system.cc.

Referenced by ED_undosys_type_init().

◆ BKE_UNDOSYS_TYPE_SCULPT

◆ BKE_UNDOSYS_TYPE_TEXT

const UndoType* BKE_UNDOSYS_TYPE_TEXT
extern