Blender V5.0
ed_undo.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "CLG_log.h"
12
13#include "DNA_object_types.h"
14#include "DNA_scene_types.h"
15
16#include "BLI_listbase.h"
17#include "BLI_utildefines.h"
18
19#include "BKE_blender_undo.hh"
20#include "BKE_callbacks.hh"
21#include "BKE_context.hh"
22#include "BKE_global.hh"
23#include "BKE_layer.hh"
24#include "BKE_main.hh"
25#include "BKE_paint.hh"
26#include "BKE_report.hh"
27#include "BKE_scene.hh"
28#include "BKE_screen.hh"
29#include "BKE_undo_system.hh"
30#include "BKE_workspace.hh"
31
32#include "BLO_blend_validate.hh"
33
34#include "ED_asset.hh"
35#include "ED_gpencil_legacy.hh"
36#include "ED_object.hh"
37#include "ED_outliner.hh"
38#include "ED_render.hh"
39#include "ED_screen.hh"
40#include "ED_sculpt.hh"
41#include "ED_undo.hh"
42
43#include "WM_api.hh"
44#include "WM_toolsystem.hh"
45#include "WM_types.hh"
46
47#include "RNA_access.hh"
48#include "RNA_define.hh"
49#include "RNA_enum_types.hh"
50
51using blender::Set;
52using blender::Vector;
53
55static CLG_LogRef LOG = {"undo"};
56
57/* -------------------------------------------------------------------- */
62
64{
66
67 /* Currently only checks matching begin/end calls. */
68 if (wm->runtime->undo_stack == nullptr) {
69 /* No undo stack is valid, nothing to do. */
70 return true;
71 }
72 if (wm->runtime->undo_stack->group_level != 0) {
73 /* If this fails #ED_undo_grouped_begin, #ED_undo_grouped_end calls don't match. */
74 return false;
75 }
76 if (wm->runtime->undo_stack->step_active != nullptr) {
77 if (wm->runtime->undo_stack->step_active->skip == true) {
78 /* Skip is only allowed between begin/end calls,
79 * a state that should never happen in main event loop. */
80 return false;
81 }
82 }
83 return true;
84}
85
91
97
98void ED_undo_push(bContext *C, const char *str)
99{
100 CLOG_INFO(&LOG, "Push '%s'", str);
102
104 int steps = U.undosteps;
105
106 /* Ensure steps that have been initialized are always pushed,
107 * even when undo steps are zero.
108 *
109 * Note that some modes (paint, sculpt) initialize an undo step before an action runs,
110 * then accumulate changes there, or restore data from it in the case of 2D painting.
111 *
112 * For this reason we need to handle the undo step even when undo steps is set to zero.
113 */
114 if ((steps <= 0) && wm->runtime->undo_stack->step_init != nullptr) {
115 steps = 1;
116 }
117 if (steps <= 0) {
118 return;
119 }
120 if (G.background) {
121 /* Python developers may have explicitly created the undo stack in background mode,
122 * otherwise allow it to be nullptr, see: #60934.
123 * Otherwise it must never be nullptr, even when undo is disabled. */
124 if (wm->runtime->undo_stack == nullptr) {
125 return;
126 }
127 }
128
129 eUndoPushReturn push_retval;
130
131 /* Only apply limit if this is the last undo step. */
132 if (wm->runtime->undo_stack->step_active &&
133 (wm->runtime->undo_stack->step_active->next == nullptr))
134 {
135 BKE_undosys_stack_limit_steps_and_memory(wm->runtime->undo_stack, steps - 1, 0);
136 }
137
138 push_retval = BKE_undosys_step_push(wm->runtime->undo_stack, C, str);
139
140 if (U.undomemory != 0) {
141 const size_t memory_limit = size_t(U.undomemory) * 1024 * 1024;
143 }
144
146 BKE_undosys_print(wm->runtime->undo_stack);
147 }
148
149 if (push_retval & UNDO_PUSH_RET_OVERRIDE_CHANGED) {
151 }
152}
153
158 wmWindowManager *wm,
159 const enum eUndoStepDir undo_dir,
160 ReportList *reports)
161{
162 BLI_assert(ELEM(undo_dir, STEP_UNDO, STEP_REDO));
163
164 Main *bmain = CTX_data_main(C);
165 Scene *scene = CTX_data_scene(C);
166
167 /* undo during jobs are running can easily lead to freeing data using by jobs,
168 * or they can just lead to freezing job in some other cases */
170
171 if (G.debug & G_DEBUG_IO) {
172 if (bmain->lock != nullptr) {
174 reports, RPT_DEBUG, "Checking validity of current .blend file *BEFORE* undo step");
175 BLO_main_validate_libraries(bmain, reports);
176 }
177 }
178
179 /* App-Handlers (pre). */
180 {
181 /* NOTE: ignore grease pencil for now. */
182 wm->op_undo_depth++;
184 bmain, &scene->id, (undo_dir == STEP_UNDO) ? BKE_CB_EVT_UNDO_PRE : BKE_CB_EVT_REDO_PRE);
185 wm->op_undo_depth--;
186 }
187}
188
195 wmWindowManager *wm,
196 const enum eUndoStepDir undo_dir,
197 ReportList *reports)
198{
199 using namespace blender::ed;
200 BLI_assert(ELEM(undo_dir, STEP_UNDO, STEP_REDO));
201
202 Main *bmain = CTX_data_main(C);
203 Scene *scene = CTX_data_scene(C);
204
205 /* App-Handlers (post). */
206 {
207 wm->op_undo_depth++;
209 bmain, &scene->id, (undo_dir == STEP_UNDO) ? BKE_CB_EVT_UNDO_POST : BKE_CB_EVT_REDO_POST);
210 wm->op_undo_depth--;
211 }
212
213 if (G.debug & G_DEBUG_IO) {
214 if (bmain->lock != nullptr) {
215 BKE_report(reports, RPT_INFO, "Checking validity of current .blend file *AFTER* undo step");
216 BLO_main_validate_libraries(bmain, reports);
217 }
218 }
219
222
225
227
229 BKE_undosys_print(wm->runtime->undo_stack);
230 }
231}
232
239 enum eUndoStepDir step,
240 ReportList *reports)
241{
243
244 CLOG_INFO(&LOG, "Step direction=%s", (step == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO");
245
247
248 ed_undo_step_pre(C, wm, step, reports);
249
250 if (step == STEP_UNDO) {
251 BKE_undosys_step_undo(wm->runtime->undo_stack, C);
252 }
253 else {
254 BKE_undosys_step_redo(wm->runtime->undo_stack, C);
255 }
256
257 ed_undo_step_post(C, wm, step, reports);
258
259 return OPERATOR_FINISHED;
260}
261
267static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports)
268{
269 BLI_assert(undo_name != nullptr);
270
272 UndoStep *undo_step_from_name = BKE_undosys_step_find_by_name(wm->runtime->undo_stack,
273 undo_name);
274 if (undo_step_from_name == nullptr) {
275 CLOG_ERROR(&LOG, "Step name='%s' not found in current undo stack", undo_name);
276
277 return OPERATOR_CANCELLED;
278 }
279
280 UndoStep *undo_step_target = undo_step_from_name->prev;
281 if (undo_step_target == nullptr) {
282 CLOG_ERROR(&LOG, "Step name='%s' cannot be undone", undo_name);
283
284 return OPERATOR_CANCELLED;
285 }
286
287 const int undo_dir_i = BKE_undosys_step_calc_direction(
288 wm->runtime->undo_stack, undo_step_target, nullptr);
289 BLI_assert(ELEM(undo_dir_i, -1, 1));
290 const enum eUndoStepDir undo_dir = (undo_dir_i == -1) ? STEP_UNDO : STEP_REDO;
291
292 CLOG_INFO(&LOG,
293 "Step name='%s', found direction=%s",
294 undo_name,
295 (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO");
296
297 ed_undo_step_pre(C, wm, undo_dir, reports);
298
299 BKE_undosys_step_load_data_ex(wm->runtime->undo_stack, C, undo_step_target, nullptr, true);
300
301 ed_undo_step_post(C, wm, undo_dir, reports);
302
303 return OPERATOR_FINISHED;
304}
305
311static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *reports)
312{
313 BLI_assert(undo_index >= 0);
314
316 const int active_step_index = BLI_findindex(&wm->runtime->undo_stack->steps,
317 wm->runtime->undo_stack->step_active);
318 if (undo_index == active_step_index) {
319 return OPERATOR_CANCELLED;
320 }
321 const enum eUndoStepDir undo_dir = (undo_index < active_step_index) ? STEP_UNDO : STEP_REDO;
322
323 CLOG_INFO(&LOG,
324 "Step index='%d', found direction=%s",
325 undo_index,
326 (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO");
327
328 ed_undo_step_pre(C, wm, undo_dir, reports);
329
330 BKE_undosys_step_load_from_index(wm->runtime->undo_stack, C, undo_index);
331
332 ed_undo_step_post(C, wm, undo_dir, reports);
333
334 return OPERATOR_FINISHED;
335}
336
338{
339 /* do nothing if previous undo task is the same as this one (or from the same undo group) */
341 const UndoStep *us = wm->runtime->undo_stack->step_active;
342 if (us && STREQ(str, us->name)) {
343 BKE_undosys_stack_clear_active(wm->runtime->undo_stack);
344 }
345
346 /* push as usual */
348}
349
351{
353}
355{
357}
358
360{
361 /* in future, get undo string info? */
362 ED_undo_push(C, op->type->name);
363}
364
366{
367 if (op->type->undo_group[0] != '\0') {
369 }
370 else {
372 }
373}
374
376{
377 /* search back a couple of undo's, in case something else added pushes */
379}
380
381bool ED_undo_is_valid(const bContext *C, const char *undoname)
382{
384 return BKE_undosys_stack_has_undo(wm->runtime->undo_stack, undoname);
385}
386
388{
389 /* Some modes don't co-exist with memfile undo, disable their use: #60593
390 * (this matches 2.7x behavior). */
391 const Scene *scene = CTX_data_scene(C);
392 ViewLayer *view_layer = CTX_data_view_layer(C);
393 if (view_layer != nullptr) {
394 BKE_view_layer_synced_ensure(scene, view_layer);
395 Object *obact = BKE_view_layer_active_object_get(view_layer);
396 if (obact != nullptr) {
397 if (obact->mode & OB_MODE_EDIT) {
398 return false;
399 }
400 }
401 }
402 return true;
403}
404
406{
407 if (!RNA_struct_undo_check(ptr.type)) {
408 return false;
409 }
410 /* If the whole ID type doesn't support undo there is no need to check the current context. */
411 if (id && !ID_CHECK_UNDO(id)) {
412 return false;
413 }
414
415 const Scene *scene = CTX_data_scene(C);
416 ViewLayer *view_layer = CTX_data_view_layer(C);
417 if (view_layer != nullptr) {
418 BKE_view_layer_synced_ensure(scene, view_layer);
419 Object *obact = BKE_view_layer_active_object_get(view_layer);
420 if (obact != nullptr) {
422 /* For all non-weight-paint paint modes: Don't store property changes when painting.
423 * Weight Paint and Vertex Paint use global undo, and thus don't need to be special-cased
424 * here. */
425 CLOG_DEBUG(&LOG, "skipping undo for paint-mode");
426 return false;
427 }
428 if (obact->mode & OB_MODE_EDIT) {
429 if ((id == nullptr) || (obact->data == nullptr) ||
430 (GS(id->name) != GS(((ID *)obact->data)->name)))
431 {
432 /* No undo push on id type mismatch in edit-mode. */
433 CLOG_DEBUG(&LOG, "skipping undo for edit-mode");
434 return false;
435 }
436 }
437 }
438 }
439 return true;
440}
441
443{
444 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
445 return wm->runtime->undo_stack;
446}
447
449
450/* -------------------------------------------------------------------- */
453
458{
459 /* The "last operator" should disappear, later we can tie this with undo stack nicer. */
461
462 /* Keep button under the cursor active. */
464
466}
467
469{
470 /* "last operator" should disappear, later we can tie this with undo stack nicer */
473 if (ret & OPERATOR_FINISHED) {
475 }
476 return ret;
477}
478
480{
481 if (G.background) {
482 /* Exception for background mode, see: #60934.
483 * NOTE: since the undo stack isn't initialized on startup, background mode behavior
484 * won't match regular usage, this is just for scripts to do explicit undo pushes. */
486 if (wm->runtime->undo_stack == nullptr) {
487 wm->runtime->undo_stack = BKE_undosys_stack_create();
488 }
489 }
490 char str[BKE_UNDO_STR_MAX];
491 RNA_string_get(op->ptr, "message", str);
493 return OPERATOR_FINISHED;
494}
495
504
506{
510 if (ret & OPERATOR_FINISHED) {
511 /* Keep button under the cursor active. */
513 }
514 return ret;
515}
516
517/* Disable in background mode, we could support if it's useful, #60934. */
518
520{
522 if (wm->runtime->undo_stack == nullptr) {
523 /* This message is intended for Python developers,
524 * it will be part of the exception when attempting to call undo in background mode. */
526 C,
527 "Undo disabled at startup in background-mode "
528 "(call `ed.undo_push()` to explicitly initialize the undo-system)");
529 return false;
530 }
531 return true;
532}
533
535{
536 if (ed_undo_is_init_poll(C) == false) {
537 return false;
538 }
540}
541
543{
545 return (last_op && ed_undo_is_init_and_screenactive_poll(C) &&
547}
548
550{
552 return false;
553 }
555 return (undo_stack->step_active != nullptr) && (undo_stack->step_active->prev != nullptr);
556}
557
559{
560 /* identifiers */
561 ot->name = "Undo";
562 ot->description = "Undo previous action";
563 ot->idname = "ED_OT_undo";
564
565 /* API callbacks. */
566 ot->exec = ed_undo_exec;
567 ot->poll = ed_undo_poll;
568}
569
571{
572 /* identifiers */
573 ot->name = "Undo Push";
574 ot->description = "Add an undo state (internal use only)";
575 ot->idname = "ED_OT_undo_push";
576
577 /* API callbacks. */
578 ot->exec = ed_undo_push_exec;
579 /* Unlike others undo operators this initializes undo stack. */
581
582 ot->flag = OPTYPE_INTERNAL;
583
584 RNA_def_string(ot->srna,
585 "message",
586 "Add an undo step *function may be moved*",
588 "Undo Message",
589 "");
590}
591
593{
595 return false;
596 }
598 return (undo_stack->step_active != nullptr) && (undo_stack->step_active->next != nullptr);
599}
600
602{
603 /* identifiers */
604 ot->name = "Redo";
605 ot->description = "Redo previous action";
606 ot->idname = "ED_OT_redo";
607
608 /* API callbacks. */
609 ot->exec = ed_redo_exec;
610 ot->poll = ed_redo_poll;
611}
612
614{
615 /* identifiers */
616 ot->name = "Undo and Redo";
617 ot->description = "Undo and redo previous action";
618 ot->idname = "ED_OT_undo_redo";
619
620 /* API callbacks. */
621 ot->exec = ed_undo_redo_exec;
622 ot->poll = ed_undo_redo_poll;
623}
624
626
627/* -------------------------------------------------------------------- */
630
632{
633 bool success = false;
634
635 if (op) {
636 CLOG_INFO(&LOG, "Operator repeat idname='%s'", op->type->idname);
638 const ScrArea *area = CTX_wm_area(C);
639 Scene *scene = CTX_data_scene(C);
640
641 /* keep in sync with logic in view3d_panel_operator_redo() */
642 ARegion *region_orig = CTX_wm_region(C);
643 /* If the redo is called from a HUD, this knows about the region type the operator was
644 * initially called in, so attempt to restore that. */
645 ARegion *redo_region_from_hud = (region_orig->regiontype == RGN_TYPE_HUD) ?
646 ED_area_type_hud_redo_region_find(area, region_orig) :
647 nullptr;
648 ARegion *region_repeat = redo_region_from_hud ? redo_region_from_hud :
650
651 if (region_repeat) {
652 CTX_wm_region_set(C, region_repeat);
653 }
654
656 /* NOTE: undo/redo can't run if there are jobs active,
657 * check for screen jobs only so jobs like material/texture/world preview
658 * (which copy their data), won't stop redo, see #29579.
659 *
660 * NOTE: WM_operator_check_ui_enabled() jobs test _must_ stay in sync with this. */
661 (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY) == 0))
662 {
663 if (G.debug & G_DEBUG) {
664 printf("redo_cb: operator redo %s\n", op->type->name);
665 }
666
668
669 ED_undo_pop_op(C, op);
670
671 if (op->type->check) {
672 if (op->type->check(C, op)) {
673 /* check for popup and re-layout buttons */
674 ARegion *region_popup = CTX_wm_region_popup(C);
675 if (region_popup) {
676 ED_region_tag_refresh_ui(region_popup);
677 }
678 }
679 }
680
681 const wmOperatorStatus retval = WM_operator_repeat(C, op);
682 if ((retval & OPERATOR_FINISHED) == 0) {
683 if (G.debug & G_DEBUG) {
684 printf("redo_cb: operator redo failed: %s, return %d\n", op->type->name, retval);
685 }
687 }
688 else {
689 success = true;
690 }
691 }
692 else {
693 if (G.debug & G_DEBUG) {
694 printf("redo_cb: WM_operator_repeat_check returned false %s\n", op->type->name);
695 }
696 }
697
698 /* set region back */
699 CTX_wm_region_set(C, region_orig);
700 }
701 else {
702 CLOG_WARN(&LOG, "called with nullptr 'op'");
703 }
704
705 return success;
706}
707
708void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void * /*arg_unused*/)
709{
711}
712
713void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int /*arg_unused*/)
714{
716}
717
719
720/* -------------------------------------------------------------------- */
725
726/* NOTE: also check #ed_undo_step() in top if you change notifiers. */
728{
729 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item");
730 if (RNA_property_is_set(op->ptr, prop)) {
731 const int item = RNA_property_int_get(op->ptr, prop);
732 const int ret = ed_undo_step_by_index(C, item, op->reports);
733 if (ret & OPERATOR_FINISHED) {
735
737 return OPERATOR_FINISHED;
738 }
739 }
740 return OPERATOR_CANCELLED;
741}
742
744{
745 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item");
746 if (RNA_property_is_set(op->ptr, prop)) {
747 return undo_history_exec(C, op);
748 }
749
751 return OPERATOR_FINISHED;
752}
753
755{
756 /* identifiers */
757 ot->name = "Undo History";
758 ot->description = "Redo specific action in history";
759 ot->idname = "ED_OT_undo_history";
760
761 /* API callbacks. */
762 ot->invoke = undo_history_invoke;
763 ot->exec = undo_history_exec;
765
766 RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX);
767}
768
770
771/* -------------------------------------------------------------------- */
774
776 Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
777{
778 using namespace blender::ed;
779 BKE_view_layer_synced_ensure(scene, view_layer);
780 Object *ob_prev = BKE_view_layer_active_object_get(view_layer);
781 if (ob_prev != ob) {
782 Base *base = BKE_view_layer_base_find(view_layer, ob);
783 if (base != nullptr) {
784 view_layer->basact = base;
785 object::base_active_refresh(G_MAIN, scene, view_layer);
786 }
787 else {
788 /* Should never fail, may not crash but can give odd behavior. */
789 CLOG_WARN(log, "'%s' failed to restore active object: '%s'", info, ob->id.name + 2);
790 }
791 }
792}
793
795 const Scene *scene_ref,
796 Scene **scene_p,
797 ViewLayer **view_layer_p)
798{
799 if (*scene_p == scene_ref) {
800 return;
801 }
802 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
803 if (win->scene == scene_ref) {
804 *scene_p = win->scene;
805 *view_layer_p = WM_window_get_active_view_layer(win);
806 return;
807 }
808 }
809}
810
812 ViewLayer *view_layer,
813 Object **object_array,
814 uint object_array_len,
815 uint object_array_stride)
816{
817 using namespace blender::ed;
818 Main *bmain = G_MAIN;
819 /* Don't request unique data because we want to de-select objects when exiting edit-mode
820 * for that to be done on all objects we can't skip ones that share data. */
822 for (Base *base : bases) {
823 ((ID *)base->object->data)->tag |= ID_TAG_DOIT;
824 }
825 Object **ob_p = object_array;
826 for (uint i = 0; i < object_array_len;
827 i++, ob_p = static_cast<Object **>(POINTER_OFFSET(ob_p, object_array_stride)))
828 {
829 Object *obedit = *ob_p;
831 ((ID *)obedit->data)->tag &= ~ID_TAG_DOIT;
832 }
833 for (Base *base : bases) {
834 const ID *id = static_cast<ID *>(base->object->data);
835 if (id->tag & ID_TAG_DOIT) {
836 object::editmode_exit_ex(bmain, scene, base->object, object::EM_FREEDATA);
837 /* Ideally we would know the selection state it was before entering edit-mode,
838 * for now follow the convention of having them unselected when exiting the mode. */
840 }
841 }
842}
843
845
846/* -------------------------------------------------------------------- */
855
857 ViewLayer *view_layer)
858{
859 BKE_view_layer_synced_ensure(scene, view_layer);
860 Base *baseact = BKE_view_layer_active_base_get(view_layer);
861 if ((baseact == nullptr) || (baseact->object->mode & OB_MODE_EDIT) == 0) {
862 return {};
863 }
864 Set<const ID *> object_data;
865 const short object_type = baseact->object->type;
866 Vector<Object *> objects(object_data.size());
867 /* Base iteration, starting with the active-base to ensure it's the first item in the array.
868 * Looping over the active-base twice is OK as the tag check prevents it being handled twice. */
869 for (Base *base = baseact,
870 *base_next = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first);
871 base;
872 base = base_next, base_next = base_next ? base_next->next : nullptr)
873 {
874 Object *ob = base->object;
875 if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
876 if (object_data.add(static_cast<const ID *>(ob->data))) {
877 objects.append(ob);
878 }
879 }
880 }
881 BLI_assert(!object_data.is_empty());
882 BLI_assert(objects[0] == baseact->object);
883 return objects;
884}
885
887{
888 BKE_view_layer_synced_ensure(scene, view_layer);
889 Base *baseact = BKE_view_layer_active_base_get(view_layer);
890 if ((baseact == nullptr) || (baseact->object->mode & OB_MODE_EDIT) == 0) {
891 return {};
892 }
893 Set<const ID *> object_data;
894 const short object_type = baseact->object->type;
895 Vector<Base *> bases;
896 /* Base iteration, starting with the active-base to ensure it's the first item in the array.
897 * Looping over the active-base twice is OK as the tag check prevents it being handled twice. */
898 for (Base *base = BKE_view_layer_active_base_get(view_layer),
899 *base_next = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first);
900 base;
901 base = base_next, base_next = base_next ? base_next->next : nullptr)
902 {
903 Object *ob = base->object;
904 if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
905 if (object_data.add(static_cast<const ID *>(ob->data))) {
906 bases.append(base);
907 }
908 }
909 }
910
911 BLI_assert(!object_data.is_empty());
912 BLI_assert(bases[0] == baseact);
913 return bases;
914}
915
917{
918 size_t total_memory = 0;
919
920 for (UndoStep *us = static_cast<UndoStep *>(ustack->steps.first); us != nullptr; us = us->next) {
921 if (us->type == BKE_UNDOSYS_TYPE_SCULPT) {
923 }
924 else if (us->data_size > 0) {
925 total_memory += us->data_size;
926 }
927 }
928
929 return total_memory;
930}
931
#define BKE_UNDO_STR_MAX
void BKE_callback_exec_id(Main *bmain, ID *id, eCbEvent evt)
Definition callbacks.cc:43
@ BKE_CB_EVT_REDO_POST
@ BKE_CB_EVT_REDO_PRE
@ BKE_CB_EVT_UNDO_PRE
@ BKE_CB_EVT_UNDO_POST
ARegion * CTX_wm_region_popup(const bContext *C)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
ScrArea * CTX_wm_area(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
ARegion * CTX_wm_region(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
@ G_DEBUG
@ G_DEBUG_IO
#define G_MAIN
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
ListBase * BKE_view_layer_object_bases_get(ViewLayer *view_layer)
@ RPT_INFO
Definition BKE_report.hh:35
@ RPT_DEBUG
Definition BKE_report.hh:34
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
ARegion * BKE_area_find_region_active_win(const ScrArea *area)
Definition screen.cc:859
void BKE_undosys_step_load_from_index(UndoStack *ustack, bContext *C, int index)
bool BKE_undosys_stack_has_undo(const UndoStack *ustack, const char *name)
const UndoType * BKE_UNDOSYS_TYPE_SCULPT
bool BKE_undosys_step_redo(UndoStack *ustack, bContext *C)
bool BKE_undosys_step_undo(UndoStack *ustack, bContext *C)
void BKE_undosys_stack_clear_active(UndoStack *ustack)
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)
eUndoStepDir
@ STEP_UNDO
@ STEP_REDO
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_OVERRIDE_CHANGED
void BKE_undosys_stack_group_end(UndoStack *ustack)
UndoStack * BKE_undosys_stack_create()
void BKE_undosys_print(UndoStack *ustack)
void BKE_undosys_stack_group_begin(UndoStack *ustack)
#define BLI_assert(a)
Definition BLI_assert.h:46
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
#define LISTBASE_FOREACH(type, var, list)
unsigned int uint
#define ELEM(...)
#define POINTER_OFFSET(v, ofs)
#define STREQ(a, b)
Utilities ensuring .blend file (i.e. Main) is in valid state during write and/or read process.
bool BLO_main_validate_libraries(Main *bmain, ReportList *reports)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define CLOG_CHECK(clg_ref, verbose_level,...)
Definition CLG_log.h:147
@ CLG_LEVEL_DEBUG
Definition CLG_log.h:62
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
@ ID_TAG_DOIT
Definition DNA_ID.h:1036
#define ID_CHECK_UNDO(id)
Definition DNA_ID.h:683
#define OB_MODE_ALL_PAINT
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ RGN_TYPE_HUD
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
void ED_outliner_select_sync_from_all_tag(bContext *C)
void ED_region_tag_refresh_ui(ARegion *region)
Definition area.cc:647
ARegion * ED_area_type_hud_redo_region_find(const ScrArea *area, const ARegion *hud_region)
bool ED_operator_screenactive(bContext *C)
#define C
Definition RandGen.cpp:29
@ WM_JOB_TYPE_ANY
Definition WM_api.hh:1775
#define NC_WINDOW
Definition WM_types.hh:375
#define NC_WM
Definition WM_types.hh:374
#define ND_LIB_OVERRIDE_CHANGED
Definition WM_types.hh:419
@ OPTYPE_INTERNAL
Definition WM_types.hh:202
#define ND_UNDO
Definition WM_types.hh:417
#define U
int64_t size() const
Definition BLI_set.hh:587
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:595
void append(const T &value)
void ED_undo_object_set_active_or_warn(Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
Definition ed_undo.cc:775
void ED_undo_push(bContext *C, const char *str)
Definition ed_undo.cc:98
bool ED_undo_is_legacy_compatible_for_property(bContext *C, ID *id, PointerRNA &ptr)
Definition ed_undo.cc:405
void ED_OT_redo(wmOperatorType *ot)
Definition ed_undo.cc:601
UndoStack * ED_undo_stack_get()
Definition ed_undo.cc:442
static wmOperatorStatus undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition ed_undo.cc:743
static void ed_undo_step_pre(bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
Definition ed_undo.cc:157
void ED_undo_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:359
void ED_undo_pop_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:375
void ED_undo_group_begin(bContext *C)
Definition ed_undo.cc:86
size_t ED_undosys_total_memory_calc(UndoStack *ustack)
Definition ed_undo.cc:916
bool ED_undo_is_valid(const bContext *C, const char *undoname)
Definition ed_undo.cc:381
void ED_OT_undo_redo(wmOperatorType *ot)
Definition ed_undo.cc:613
void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int)
Definition ed_undo.cc:713
static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *reports)
Definition ed_undo.cc:311
void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void *)
Definition ed_undo.cc:708
void ED_OT_undo_push(wmOperatorType *ot)
Definition ed_undo.cc:570
static wmOperatorStatus ed_undo_step_direction(bContext *C, enum eUndoStepDir step, ReportList *reports)
Definition ed_undo.cc:238
static void ed_undo_step_post(bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
Definition ed_undo.cc:194
static void ed_undo_refresh_for_op(bContext *C)
Definition ed_undo.cc:457
static wmOperatorStatus ed_undo_push_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:479
static wmOperatorStatus ed_undo_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:468
Vector< Object * > ED_undo_editmode_objects_from_view_layer(const Scene *scene, ViewLayer *view_layer)
Definition ed_undo.cc:856
static bool ed_redo_poll(bContext *C)
Definition ed_undo.cc:592
static bool ed_undo_is_init_poll(bContext *C)
Definition ed_undo.cc:519
static bool ed_undo_is_init_and_screenactive_poll(bContext *C)
Definition ed_undo.cc:534
static wmOperatorStatus ed_redo_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:496
static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports)
Definition ed_undo.cc:267
void ED_undo_redo(bContext *C)
Definition ed_undo.cc:354
static wmOperatorStatus ed_undo_redo_exec(bContext *C, wmOperator *)
Definition ed_undo.cc:505
bool ED_undo_is_state_valid(bContext *C)
Definition ed_undo.cc:63
static wmOperatorStatus undo_history_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:727
void ED_OT_undo(wmOperatorType *ot)
Definition ed_undo.cc:558
bool ED_undo_operator_repeat(bContext *C, wmOperator *op)
Definition ed_undo.cc:631
void ED_OT_undo_history(wmOperatorType *ot)
Definition ed_undo.cc:754
static bool ed_undo_poll(bContext *C)
Definition ed_undo.cc:549
void ED_undo_object_editmode_restore_helper(Scene *scene, ViewLayer *view_layer, Object **object_array, uint object_array_len, uint object_array_stride)
Definition ed_undo.cc:811
void ED_undo_grouped_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:365
static bool ed_undo_redo_poll(bContext *C)
Definition ed_undo.cc:542
bool ED_undo_is_memfile_compatible(const bContext *C)
Definition ed_undo.cc:387
void ED_undo_pop(bContext *C)
Definition ed_undo.cc:350
void ED_undo_object_editmode_validate_scene_from_windows(wmWindowManager *wm, const Scene *scene_ref, Scene **scene_p, ViewLayer **view_layer_p)
Definition ed_undo.cc:794
void ED_undo_group_end(bContext *C)
Definition ed_undo.cc:92
void ED_undo_grouped_push(bContext *C, const char *str)
Definition ed_undo.cc:337
Vector< Base * > ED_undo_editmode_bases_from_view_layer(const Scene *scene, ViewLayer *view_layer)
Definition ed_undo.cc:886
#define str(s)
#define GS(x)
#define printf(...)
#define log
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define LOG(level)
Definition log.h:97
#define G(x, y, z)
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)
return ret
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
bool RNA_struct_undo_check(const StructRNA *type)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
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)
struct Base * next
struct Object * object
Definition DNA_ID.h:414
int tag
Definition DNA_ID.h:442
char name[258]
Definition DNA_ID.h:432
void * first
MainLock * lock
Definition BKE_main.hh:343
ListBase steps
UndoStep * prev
UndoStep * next
char name[64]
struct Base * basact
const char * name
Definition WM_types.hh:1033
const char * idname
Definition WM_types.hh:1035
bool(* check)(bContext *C, wmOperator *op)
Definition WM_types.hh:1057
const char * undo_group
Definition WM_types.hh:1041
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
WindowManagerRuntimeHandle * runtime
i
Definition text_draw.cc:230
#define undo_stack
void WM_operator_stack_clear(wmWindowManager *wm)
Definition wm.cc:358
void WM_operator_free_all_after(wmWindowManager *wm, wmOperator *op)
Definition wm.cc:294
bool WM_operator_poll(bContext *C, wmOperatorType *ot)
bool WM_operator_repeat_check(const bContext *, wmOperator *op)
void WM_main_add_notifier(uint type, void *reference)
wmOperatorStatus WM_operator_repeat(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_menu_name_call(bContext *C, const char *menu_name, blender::wm::OpCallContext context)
void WM_event_add_mousemove(wmWindow *win)
void WM_file_tag_modified()
Definition wm_files.cc:177
PointerRNA * ptr
Definition wm_files.cc:4238
wmOperatorType * ot
Definition wm_files.cc:4237
void WM_jobs_kill_all(wmWindowManager *wm)
Definition wm_jobs.cc:602
bool WM_jobs_test(const wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:247
bool WM_operator_check_ui_enabled(const bContext *C, const char *idname)
wmOperator * WM_operator_last_redo(const bContext *C)
size_t memory_limit
void WM_toolsystem_refresh_screen_all(Main *bmain)
void WM_toolsystem_refresh_active(bContext *C)
ViewLayer * WM_window_get_active_view_layer(const wmWindow *win)