55#include "RNA_prototypes.hh"
73 if (
wm->runtime->undo_stack ==
nullptr) {
77 if (
wm->runtime->undo_stack->group_level != 0) {
81 if (
wm->runtime->undo_stack->step_active !=
nullptr) {
82 if (
wm->runtime->undo_stack->step_active->skip ==
true) {
113 if (
wm->runtime->undo_stack ==
nullptr) {
118 int steps =
U.undosteps;
128 if ((steps <= 0) &&
wm->runtime->undo_stack->step_init !=
nullptr) {
138 if (
wm->runtime->undo_stack->step_active &&
139 (
wm->runtime->undo_stack->step_active->next ==
nullptr))
146 if (
U.undomemory != 0) {
147 const size_t memory_limit = size_t(
U.undomemory) * 1024 * 1024;
179 if (bmain->
lock !=
nullptr) {
181 reports,
RPT_DEBUG,
"Checking validity of current .blend file *BEFORE* undo step");
221 if (bmain->
lock !=
nullptr) {
222 BKE_report(reports,
RPT_INFO,
"Checking validity of current .blend file *AFTER* undo step");
285 if (undo_step_from_name ==
nullptr) {
286 CLOG_ERROR(&
LOG,
"Step name='%s' not found in current undo stack", undo_name);
292 if (undo_step_target ==
nullptr) {
293 CLOG_ERROR(&
LOG,
"Step name='%s' cannot be undone", undo_name);
299 wm->runtime->undo_stack, undo_step_target,
nullptr);
304 "Step name='%s', found direction=%s",
306 (undo_dir ==
STEP_UNDO) ?
"STEP_UNDO" :
"STEP_REDO");
327 const int active_step_index =
BLI_findindex(&
wm->runtime->undo_stack->steps,
328 wm->runtime->undo_stack->step_active);
329 if (undo_index == active_step_index) {
335 "Step index='%d', found direction=%s",
337 (undo_dir ==
STEP_UNDO) ?
"STEP_UNDO" :
"STEP_REDO");
364 if (ustack ==
nullptr) {
397 const ID *id_first =
static_cast<const ID *
>(taskdata);
405 if (id_type ==
ID_OB) {
407 for (
const ID *
id = id_first;
id && !modified.load();
id =
static_cast<ID *
>(
id->next)) {
408 if (
id->recalc_after_undo_push ==
false) {
424 modified.store(
true);
427 else if (id_type ==
ID_KE) {
429 for (
const ID *
id = id_first;
id && !modified.load();
id =
static_cast<ID *
>(
id->next)) {
430 if (
id->recalc_after_undo_push ==
false) {
435 const ID *key_from =
reinterpret_cast<const ID *
>(
reinterpret_cast<const Key *
>(
id)->
from);
441 modified.store(
true);
446 for (
const ID *
id = id_first;
id && !modified.load();
id =
static_cast<ID *
>(
id->next)) {
447 if (
id->recalc_after_undo_push ==
false) {
456 modified.store(
true);
461 for (
const ID *
id = id_first;
id && !modified.load();
id =
static_cast<ID *
>(
id->next)) {
462 if (
id->recalc_after_undo_push ==
false) {
465 modified.store(
true);
488 for (
const ListBaseT<ID> *lb : lbarray) {
489 const ID *id_first = lb->first();
504 std::atomic<bool> modified =
false;
506 for (
const ID *id_first : ids) {
507 if (modified.load()) {
516 return modified.load();
526 if (ustack ==
nullptr) {
595 if (view_layer !=
nullptr) {
598 if (obact !=
nullptr) {
626 &rna_Object_active_shape_key_index))
634 if (view_layer !=
nullptr) {
637 if (obact !=
nullptr) {
660 const bool is_id_in_editmode = (
id && obact->
data &&
667 if (is_id_in_editmode ==
false) {
668 bool skip_undo =
true;
693 return wm->runtime->undo_stack;
734 if (
wm->runtime->undo_stack ==
nullptr) {
770 if (
wm->runtime->undo_stack ==
nullptr) {
775 "Undo disabled at startup in background-mode "
776 "(call `ed.undo_push()` to explicitly initialize the undo-system)");
811 ot->
idname =
"ED_OT_undo";
821 ot->
name =
"Undo Push";
822 ot->
description =
"Add an undo state (internal use only)";
823 ot->
idname =
"ED_OT_undo_push";
834 "Add an undo step *function may be moved*",
854 ot->
idname =
"ED_OT_redo";
864 ot->
name =
"Undo and Redo";
866 ot->
idname =
"ED_OT_undo_redo";
881 bool success =
false;
896 ARegion *region_repeat = redo_region_from_hud ? redo_region_from_hud :
932 printf(
"redo_cb: operator redo failed: %s, return %d\n", op->
type->
name, retval);
942 printf(
"redo_cb: WM_operator_repeat_check returned false %s\n", op->
type->
name);
1005 ot->
name =
"Undo History";
1007 "Undo or redo from the current active step until the specified action in history";
1008 ot->
idname =
"ED_OT_undo_history";
1034 if (ob_prev != ob) {
1036 if (base !=
nullptr) {
1037 view_layer->
basact = base;
1048 const Scene *scene_ref,
1052 if (*scene_p == scene_ref) {
1056 if (win.
scene == scene_ref) {
1057 *scene_p = win.
scene;
1067 uint object_array_len,
1068 uint object_array_stride)
1075 for (
Base *base : bases) {
1078 Object **ob_p = object_array;
1079 for (
uint i = 0; i < object_array_len;
1086 for (
Base *base : bases) {
1087 const ID *
id = base->object->data;
1119 const short object_type = baseact->
object->
type;
1125 base = base_next, base_next = base_next ? base_next->next :
nullptr)
1127 Object *ob = base->object;
1129 if (object_data.
add(
static_cast<const ID *
>(ob->
data))) {
1149 const short object_type = baseact->
object->
type;
1156 base = base_next, base_next = base_next ? base_next->next :
nullptr)
1158 Object *ob = base->object;
1160 if (object_data.
add(
static_cast<const ID *
>(ob->
data))) {
1173 size_t total_memory = 0;
1175 for (
UndoStep *us = ustack->
steps.first(); us !=
nullptr; us = us->next) {
1179 else if (us->data_size > 0) {
1180 total_memory += us->data_size;
1184 return total_memory;
General operations, lookup, etc. for blender objects.
Utilities ensuring .blend file (i.e. Main) is in valid state during write and/or read process.
#define CLOG_ERROR(clg_ref,...)
#define CLOG_DEBUG(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
#define CLOG_CHECK(clg_ref, verbose_level,...)
#define CLOG_INFO(clg_ref,...)
#define ID_CHECK_UNDO(id)
Object is a sort of wrapper for general info.
#define OB_DATA_SUPPORT_EDITMODE(_type)
#define ND_LIB_OVERRIDE_CHANGED
#define POINTER_OFFSET(v, ofs)
void append(const T &value)
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void storage_tag_main_data_dirty()
void base_select(Base *base, eObjectSelect_Mode mode)
bool editmode_enter_ex(Main *bmain, Scene *scene, Object *ob, int flag)
void base_active_refresh(Main *bmain, Scene *scene, ViewLayer *view_layer)
bool editmode_exit_ex(Main *bmain, Scene *scene, Object *obedit, int flag)
size_t step_memory_size_get(UndoStep *step)
ARegion * ED_area_type_hud_redo_region_find(const ScrArea *area, const ARegion *hud_region)
void WM_main_add_notifier(uint type, void *reference)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_toolsystem_refresh_active(bContext *C)
ARegion * BKE_area_find_region_active_win(const ScrArea *area)
std::array< ListBaseT< ID > *, INDEX_ID_MAX - 1 > MainListsArray
void ED_OT_undo_push(wmOperatorType *ot)
bool ED_undo_has_redo_step(const bContext *C)
ScrArea * CTX_wm_area(const bContext *C)
static bool ed_undo_poll(bContext *C)
static bool ed_undo_is_init_poll(bContext *C)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
bool ED_undo_operator_repeat(bContext *C, wmOperator *op)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
void ED_undo_grouped_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
bool ED_undo_is_memfile_compatible(const bContext *C)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
bool BKE_undosys_stack_has_undo(const UndoStack *ustack, const char *name)
void ED_OT_undo_redo(wmOperatorType *ot)
UndoStack * ED_undo_stack_get()
@ UNDOTYPE_FLAG_ENCODE_PRE_MEMFILE_SUPPORTED
void ED_preview_kill_jobs_for_undo(wmWindowManager *wm, Main *bmain)
static bool ed_undo_redo_poll(bContext *C)
bool ED_undo_is_state_valid(bContext *C)
void BKE_undosys_stack_clear_active(UndoStack *ustack)
void BKE_undosys_stack_group_end(UndoStack *ustack)
void ED_undo_object_set_active_or_warn(const Main &bmain, Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
static wmOperatorStatus ed_undo_step_direction(bContext *C, enum eUndoStepDir step, ReportList *reports)
static wmOperatorStatus ed_undo_redo_exec(bContext *C, wmOperator *)
void ED_outliner_select_sync_from_all_tag(bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
static wmOperatorStatus undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
void BKE_callback_exec_id(Main *bmain, ID *id, eCbEvent evt)
MainListsArray BKE_main_lists_get(Main &bmain)
void ED_OT_undo(wmOperatorType *ot)
void ED_OT_redo(wmOperatorType *ot)
UndoStack * BKE_undosys_stack_create()
Vector< Object * > ED_undo_editmode_objects_from_view_layer(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
void ED_undo_push_op(bContext *C, wmOperator *op)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)
static void ed_undo_refresh_for_op(bContext *C)
std::optional< UndoEncodeHints > ED_undo_is_legacy_compatible_for_property(bContext *C, ID *id, const PointerRNA &ptr, const PropertyRNA &prop)
ViewLayer * CTX_data_view_layer(const bContext *C)
void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void *arg_unused)
static bool ed_undo_is_init_and_screenactive_poll(bContext *C)
void BLI_task_pool_work_and_wait(TaskPool *pool)
void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int arg_unused)
void * BLI_task_pool_user_data(TaskPool *pool)
bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
void ED_undo_grouped_push_op(bContext *C, wmOperator *op)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
bool RNA_property_undo_check(const PropertyRNA *prop, const StructRNA *type)
void BKE_undosys_stack_group_begin(UndoStack *ustack)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
static void ed_undo_push_check_id_changes_fn(TaskPool *__restrict pool, void *taskdata)
void WM_toolsystem_refresh_screen_all(Main *bmain)
eUndoStepDir BKE_undosys_step_calc_direction(const UndoStack *ustack, const UndoStep *us_target, const UndoStep *us_reference)
void ED_region_tag_refresh_ui(ARegion *region)
void ED_undo_redo(bContext *C)
void ED_undo_pop_op(bContext *C, wmOperator *op)
static wmOperatorStatus ed_redo_exec(bContext *C, wmOperator *op)
void BKE_undosys_print(UndoStack *ustack)
void BKE_undosys_step_load_from_index(UndoStack *ustack, bContext *C, int index)
void BKE_report(ReportList *reports, eReportType type, const char *message)
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
wmWindowManager * CTX_wm_manager(const bContext *C)
wmOperatorStatus WM_operator_repeat(bContext *C, wmOperator *op)
void ED_undo_pop(bContext *C)
static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *reports)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
static void ed_undo_step_post(bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
bool BKE_object_data_is_in_editmode(const Object *ob, const ID *id)
void WM_menu_name_call(bContext *C, const char *menu_name, wm::OpCallContext context)
void WM_operator_free_all_after(wmWindowManager *wm, wmOperator *op)
const UndoType * BKE_UNDOSYS_TYPE_SCULPT
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
const UndoType * BKE_UNDOSYS_TYPE_MEMFILE
Vector< Base * > ED_undo_editmode_bases_from_view_layer(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
static wmOperatorStatus ed_undo_push_exec(bContext *C, wmOperator *op)
bool BKE_undosys_step_undo(UndoStack *ustack, bContext *C)
void ED_OT_undo_history(wmOperatorType *ot)
size_t ED_undosys_total_memory_calc(UndoStack *ustack)
bool BKE_undosys_step_redo(UndoStack *ustack, bContext *C)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void ED_undo_group_begin(bContext *C)
void BLI_task_pool_free(TaskPool *pool)
static void ed_undo_step_pre(bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
TaskPool * BLI_task_pool_create(void *userdata, eTaskPriority priority)
static bool ed_undo_push_check_id_changes_outside_mode(Main *bmain)
@ UNDO_PUSH_RET_OVERRIDE_CHANGED
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void WM_event_handling_break(const bContext &C)
void WM_operator_stack_clear(wmWindowManager *wm)
void WM_file_tag_modified()
Main * CTX_data_main(const bContext *C)
static UndoEncodeHints undo_encode_hints_from_context(bContext *C, const char *str)
ID_Type GS(const char *name)
ARegion * CTX_wm_region_popup(const bContext *C)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
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)
wmOperator * WM_operator_last_redo(const bContext *C)
bool WM_operator_repeat_check(const bContext *, wmOperator *op)
void ED_undo_object_editmode_restore_helper(Scene *scene, ViewLayer *view_layer, Object **object_array, uint object_array_len, uint object_array_stride)
static bool ed_undo_grouped_check_by_name(const UndoStack *ustack, const char *str)
Scene * CTX_data_scene(const bContext *C)
static bool ed_redo_poll(bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
bool BKE_undosys_step_load_data_ex(UndoStack *ustack, bContext *C, UndoStep *us_target, UndoStep *us_reference, bool use_skip)
static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports)
UndoStep * BKE_undosys_step_find_by_name(UndoStack *ustack, const char *name)
void WM_jobs_kill_all(wmWindowManager *wm)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus undo_history_exec(bContext *C, wmOperator *op)
void ED_undo_group_end(bContext *C)
void WM_event_add_mousemove(wmWindow *win)
bool WM_operator_check_ui_enabled(const bContext *C, const char *idname)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
bool WM_operator_poll(bContext *C, wmOperatorType *ot)
const UndoType * BKE_undosys_type_from_context(bContext *C)
void BLI_task_pool_push(TaskPool *pool, TaskRunFunction run, void *taskdata, bool free_taskdata, TaskFreeFunction freedata)
ARegion * CTX_wm_region(const bContext *C)
bool ED_undo_is_valid(const bContext *C, const char *undoname)
static wmOperatorStatus ed_undo_exec(bContext *C, wmOperator *op)
ListBaseT< Base > * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
eUndoPushReturn BKE_undosys_step_push(UndoStack *ustack, bContext *C, const char *name, UndoEncodeHints hints)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
bool ED_operator_screenactive(bContext *C)
void ED_undo_object_editmode_validate_scene_from_windows(wmWindowManager *wm, const Scene *scene_ref, Scene **scene_p, ViewLayer **view_layer_p)
bool is_memfile_undo_written
ListBaseT< UndoStep > steps
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) check(bContext *C, wmOperator *op)
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
struct ReportList * reports
struct wmOperatorType * type
bke::WindowManagerRuntime * runtime