Blender  V3.3
Classes | Macros | Typedefs | Enumerations | Functions
BKE_undo_system.h File Reference
#include "DNA_ID.h"
#include "DNA_listBase.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)   ELEM(ty, BKE_UNDOSYS_TYPE_IMAGE)
 
#define BKE_undosys_stack_limit_steps_and_memory_defaults(ustack)    BKE_undosys_stack_limit_steps_and_memory(ustack, U.undosteps, (size_t)U.undomemory * 1024 * 1024)
 

Typedefs

typedef struct UndoRefID UndoRefID
 
typedef struct UndoStack UndoStack
 
typedef struct UndoStep UndoStep
 
typedef enum eUndoStepDir eUndoStepDir
 
typedef enum eUndoPushReturn eUndoPushReturn
 
typedef void(* UndoTypeForEachIDRefFn) (void *user_data, struct UndoRefID *id_ref)
 
typedef struct UndoType UndoType
 
typedef enum eUndoTypeFlags eUndoTypeFlags
 

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 (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)
 
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, struct Main *bmain)
 
void BKE_undosys_stack_init_from_context (UndoStack *ustack, struct 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, struct bContext *C, const char *name, const UndoType *ut)
 
UndoStepBKE_undosys_step_push_init (UndoStack *ustack, struct bContext *C, const char *name)
 
eUndoPushReturn BKE_undosys_step_push_with_type (UndoStack *ustack, struct bContext *C, const char *name, const UndoType *ut)
 
eUndoPushReturn BKE_undosys_step_push (UndoStack *ustack, struct 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, struct bContext *C, UndoStep *us_target, UndoStep *us_reference, bool use_skip)
 
bool BKE_undosys_step_load_data (UndoStack *ustack, struct bContext *C, UndoStep *us_target)
 
void BKE_undosys_step_load_from_index (UndoStack *ustack, struct bContext *C, int index)
 
bool BKE_undosys_step_undo_with_data_ex (UndoStack *ustack, struct bContext *C, UndoStep *us, bool use_skip)
 
bool BKE_undosys_step_undo_with_data (UndoStack *ustack, struct bContext *C, UndoStep *us_target)
 
bool BKE_undosys_step_undo (UndoStack *ustack, struct bContext *C)
 
bool BKE_undosys_step_redo_with_data_ex (UndoStack *ustack, struct bContext *C, UndoStep *us, bool use_skip)
 
bool BKE_undosys_step_redo_with_data (UndoStack *ustack, struct bContext *C, UndoStep *us_target)
 
bool BKE_undosys_step_redo (UndoStack *ustack, struct 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)
 
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)     BKE_undosys_stack_limit_steps_and_memory(ustack, U.undosteps, (size_t)U.undomemory * 1024 * 1024)

Definition at line 193 of file BKE_undo_system.h.

◆ BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP

#define BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP (   ty)    ELEM(ty, BKE_UNDOSYS_TYPE_IMAGE)

Definition at line 175 of file BKE_undo_system.h.

◆ UNDO_REF_ID_TYPE

#define UNDO_REF_ID_TYPE (   ptr_ty)
Value:
typedef struct UndoRefID_##ptr_ty { \
struct ptr_ty *ptr; \
char name[MAX_ID_NAME]; \
} UndoRefID_##ptr_ty
#define MAX_ID_NAME
Definition: DNA_ID.h:337
PointerRNA * ptr
Definition: wm_files.c:3480

Definition at line 31 of file BKE_undo_system.h.

Typedef Documentation

◆ eUndoPushReturn

◆ eUndoStepDir

typedef enum eUndoStepDir eUndoStepDir

◆ eUndoTypeFlags

#UndoType.flag bitflags.

◆ UndoRefID

typedef struct UndoRefID UndoRefID

◆ UndoStack

typedef struct UndoStack UndoStack

◆ UndoStep

typedef struct UndoStep UndoStep

◆ UndoType

typedef struct UndoType UndoType

◆ UndoTypeForEachIDRefFn

typedef void(* UndoTypeForEachIDRefFn) (void *user_data, struct UndoRefID *id_ref)

Definition at line 97 of file BKE_undo_system.h.

Enumeration Type Documentation

◆ eUndoPushReturn

Enumerator
UNDO_PUSH_RET_FAILURE 
UNDO_PUSH_RET_SUCCESS 
UNDO_PUSH_RET_OVERRIDE_CHANGED 

Definition at line 91 of file BKE_undo_system.h.

◆ eUndoStepDir

Enumerator
STEP_REDO 
STEP_UNDO 
STEP_INVALID 

Definition at line 85 of file BKE_undo_system.h.

◆ eUndoTypeFlags

#UndoType.flag bitflags.

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 145 of file BKE_undo_system.h.

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()

void BKE_undosys_stack_clear ( UndoStack ustack)

◆ BKE_undosys_stack_clear_active()

void BKE_undosys_stack_clear_active ( UndoStack ustack)

◆ BKE_undosys_stack_create()

UndoStack* BKE_undosys_stack_create ( void  )

Definition at line 250 of file undo_system.c.

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)

Definition at line 256 of file undo_system.c.

References BKE_undosys_stack_clear(), and MEM_freeN.

Referenced by ED_editors_exit(), and wm_close_and_free().

◆ BKE_undosys_stack_group_begin()

void BKE_undosys_stack_group_begin ( UndoStack ustack)

Definition at line 919 of file undo_system.c.

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 
)

Definition at line 354 of file undo_system.c.

References BLI_listbase_is_empty(), BLI_rfindstring(), UndoStep::prev, and UndoStack::steps.

Referenced by ED_undo_is_valid().

◆ BKE_undosys_stack_init_from_context()

void BKE_undosys_stack_init_from_context ( UndoStack ustack,
struct bContext C 
)

◆ BKE_undosys_stack_init_from_main()

void BKE_undosys_stack_init_from_main ( UndoStack ustack,
struct Main bmain 
)

Definition at line 340 of file undo_system.c.

References IFACE_, UNDO_NESTED_ASSERT, and undosys_stack_push_main().

Referenced by wm_file_read_post().

◆ BKE_undosys_stack_init_or_active_with_type()

UndoStep* BKE_undosys_stack_init_or_active_with_type ( UndoStack ustack,
const UndoType ut 
)

◆ 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 383 of file undo_system.c.

References BKE_UNDOSYS_TYPE_MEMFILE, CLOG_INFO, UndoStep::data_size, ListBase::last, LOG, memory_limit, NULL, UndoStep::prev, UndoStep::skip, steps, 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 659 of file undo_system.c.

References BLI_assert, BLI_assert_msg, ELEM, UndoStep::next, NULL, 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 644 of file undo_system.c.

References BLI_rfindstring(), 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 630 of file undo_system.c.

References ListBase::last, NULL, 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 649 of file undo_system.c.

References ListBase::last, NULL, and UndoStack::steps.

Referenced by memfile_undosys_step_encode().

◆ BKE_undosys_step_load_data()

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

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

Definition at line 806 of file undo_system.c.

References BKE_undosys_step_load_data_ex(), C, and NULL.

Referenced by BKE_undosys_step_load_from_index().

◆ BKE_undosys_step_load_data_ex()

bool BKE_undosys_step_load_data_ex ( UndoStack ustack,
struct 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 718 of file undo_system.c.

References BKE_undosys_step_calc_direction(), BLI_assert, C, CLOG_ERROR, CLOG_INFO, G_MAIN, LOG, UndoStep::name, UndoType::name, UndoStep::next, NULL, UndoStep::prev, UndoStep::skip, UndoStack::step_active, STEP_INVALID, CLG_LogRef::type, 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,
struct 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 812 of file undo_system.c.

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()

eUndoPushReturn BKE_undosys_step_push ( UndoStack ustack,
struct bContext C,
const char *  name 
)

◆ BKE_undosys_step_push_init()

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

◆ BKE_undosys_step_push_init_with_type()

UndoStep* BKE_undosys_step_push_init_with_type ( UndoStack ustack,
struct bContext C,
const char *  name,
const UndoType ut 
)

◆ BKE_undosys_step_push_with_type()

eUndoPushReturn BKE_undosys_step_push_with_type ( UndoStack ustack,
struct bContext C,
const char *  name,
const UndoType ut 
)

◆ BKE_undosys_step_redo()

bool BKE_undosys_step_redo ( UndoStack ustack,
struct bContext C 
)

Redo one step from current active one.

Definition at line 869 of file undo_system.c.

References BKE_undosys_step_redo_with_data(), C, UndoStep::next, NULL, 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,
struct 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 864 of file undo_system.c.

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,
struct bContext C,
UndoStep us,
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 850 of file undo_system.c.

References BKE_undosys_step_calc_direction(), BKE_undosys_step_load_data_ex(), BLI_assert, C, NULL, 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 604 of file undo_system.c.

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 617 of file undo_system.c.

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

◆ BKE_undosys_step_undo()

bool BKE_undosys_step_undo ( UndoStack ustack,
struct bContext C 
)

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

Definition at line 842 of file undo_system.c.

References BKE_undosys_step_undo_with_data(), C, NULL, 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,
struct 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 837 of file undo_system.c.

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,
struct bContext C,
UndoStep us,
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 822 of file undo_system.c.

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

Referenced by BKE_undosys_step_undo_with_data().

◆ BKE_undosys_type_append()

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

Similar to WM_operatortype_append

Definition at line 877 of file undo_system.c.

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 ( void  )

Definition at line 890 of file undo_system.c.

References BLI_pophead(), g_undo_types, and MEM_freeN.

Referenced by ED_undosys_type_free().

◆ UNDO_REF_ID_TYPE() [1/6]

UNDO_REF_ID_TYPE ( Image  )

◆ UNDO_REF_ID_TYPE() [2/6]

UNDO_REF_ID_TYPE ( Mesh  )

◆ UNDO_REF_ID_TYPE() [3/6]

UNDO_REF_ID_TYPE ( Object  )

◆ UNDO_REF_ID_TYPE() [4/6]

UNDO_REF_ID_TYPE ( PaintCurve  )

◆ UNDO_REF_ID_TYPE() [5/6]

UNDO_REF_ID_TYPE ( Scene  )

◆ UNDO_REF_ID_TYPE() [6/6]

UNDO_REF_ID_TYPE ( Text  )

Variable Documentation

◆ BKE_UNDOSYS_TYPE_IMAGE

const UndoType* BKE_UNDOSYS_TYPE_IMAGE
extern

◆ BKE_UNDOSYS_TYPE_MEMFILE

const UndoType* BKE_UNDOSYS_TYPE_MEMFILE
extern

◆ BKE_UNDOSYS_TYPE_PAINTCURVE

const UndoType* BKE_UNDOSYS_TYPE_PAINTCURVE
extern

Definition at line 55 of file undo_system.c.

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 56 of file undo_system.c.

Referenced by ED_undosys_type_init().

◆ BKE_UNDOSYS_TYPE_SCULPT

const UndoType* BKE_UNDOSYS_TYPE_SCULPT
extern

◆ BKE_UNDOSYS_TYPE_TEXT

const UndoType* BKE_UNDOSYS_TYPE_TEXT
extern