Blender V4.3
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
9#include <cstring>
10
11#include "MEM_guardedalloc.h"
12
13#include "CLG_log.h"
14
15#include "DNA_object_types.h"
16#include "DNA_scene_types.h"
17
18#include "BLI_listbase.h"
19#include "BLI_utildefines.h"
20
21#include "BLT_translation.hh"
22
23#include "BKE_blender_undo.hh"
24#include "BKE_callbacks.hh"
25#include "BKE_context.hh"
26#include "BKE_global.hh"
27#include "BKE_layer.hh"
28#include "BKE_main.hh"
29#include "BKE_paint.hh"
30#include "BKE_report.hh"
31#include "BKE_scene.hh"
32#include "BKE_screen.hh"
33#include "BKE_undo_system.hh"
34#include "BKE_workspace.hh"
35
36#include "BLO_blend_validate.hh"
37
38#include "ED_asset.hh"
39#include "ED_gpencil_legacy.hh"
40#include "ED_object.hh"
41#include "ED_outliner.hh"
42#include "ED_render.hh"
43#include "ED_screen.hh"
44#include "ED_undo.hh"
45
46#include "WM_api.hh"
47#include "WM_toolsystem.hh"
48#include "WM_types.hh"
49
50#include "RNA_access.hh"
51#include "RNA_define.hh"
52#include "RNA_enum_types.hh"
53
54#include "UI_interface.hh"
55#include "UI_resources.hh"
56
57using blender::Set;
58using blender::Vector;
59
61static CLG_LogRef LOG = {"ed.undo"};
62
63/* -------------------------------------------------------------------- */
70{
72
73 /* Currently only checks matching begin/end calls. */
74 if (wm->undo_stack == nullptr) {
75 /* No undo stack is valid, nothing to do. */
76 return true;
77 }
78 if (wm->undo_stack->group_level != 0) {
79 /* If this fails #ED_undo_grouped_begin, #ED_undo_grouped_end calls don't match. */
80 return false;
81 }
82 if (wm->undo_stack->step_active != nullptr) {
83 if (wm->undo_stack->step_active->skip == true) {
84 /* Skip is only allowed between begin/end calls,
85 * a state that should never happen in main event loop. */
86 return false;
87 }
88 }
89 return true;
90}
91
97
103
104void ED_undo_push(bContext *C, const char *str)
105{
106 CLOG_INFO(&LOG, 1, "name='%s'", str);
108
110 int steps = U.undosteps;
111
112 /* Ensure steps that have been initialized are always pushed,
113 * even when undo steps are zero.
114 *
115 * Note that some modes (paint, sculpt) initialize an undo step before an action runs,
116 * then accumulate changes there, or restore data from it in the case of 2D painting.
117 *
118 * For this reason we need to handle the undo step even when undo steps is set to zero.
119 */
120 if ((steps <= 0) && wm->undo_stack->step_init != nullptr) {
121 steps = 1;
122 }
123 if (steps <= 0) {
124 return;
125 }
126 if (G.background) {
127 /* Python developers may have explicitly created the undo stack in background mode,
128 * otherwise allow it to be nullptr, see: #60934.
129 * Otherwise it must never be nullptr, even when undo is disabled. */
130 if (wm->undo_stack == nullptr) {
131 return;
132 }
133 }
134
135 eUndoPushReturn push_retval;
136
137 /* Only apply limit if this is the last undo step. */
138 if (wm->undo_stack->step_active && (wm->undo_stack->step_active->next == nullptr)) {
140 }
141
142 push_retval = BKE_undosys_step_push(wm->undo_stack, C, str);
143
144 if (U.undomemory != 0) {
145 const size_t memory_limit = size_t(U.undomemory) * 1024 * 1024;
147 }
148
149 if (CLOG_CHECK(&LOG, 1)) {
151 }
152
153 if (push_retval & UNDO_PUSH_RET_OVERRIDE_CHANGED) {
155 }
156}
157
162 wmWindowManager *wm,
163 const enum eUndoStepDir undo_dir,
164 ReportList *reports)
165{
166 BLI_assert(ELEM(undo_dir, STEP_UNDO, STEP_REDO));
167
168 Main *bmain = CTX_data_main(C);
169 Scene *scene = CTX_data_scene(C);
170
171 /* undo during jobs are running can easily lead to freeing data using by jobs,
172 * or they can just lead to freezing job in some other cases */
174
175 if (G.debug & G_DEBUG_IO) {
176 if (bmain->lock != nullptr) {
178 reports, RPT_DEBUG, "Checking validity of current .blend file *BEFORE* undo step");
179 BLO_main_validate_libraries(bmain, reports);
180 }
181 }
182
183 /* App-Handlers (pre). */
184 {
185 /* NOTE: ignore grease pencil for now. */
186 wm->op_undo_depth++;
188 bmain, &scene->id, (undo_dir == STEP_UNDO) ? BKE_CB_EVT_UNDO_PRE : BKE_CB_EVT_REDO_PRE);
189 wm->op_undo_depth--;
190 }
191}
192
199 wmWindowManager *wm,
200 const enum eUndoStepDir undo_dir,
201 ReportList *reports)
202{
203 using namespace blender::ed;
204 BLI_assert(ELEM(undo_dir, STEP_UNDO, STEP_REDO));
205
206 Main *bmain = CTX_data_main(C);
207 Scene *scene = CTX_data_scene(C);
208
209 /* App-Handlers (post). */
210 {
211 wm->op_undo_depth++;
213 bmain, &scene->id, (undo_dir == STEP_UNDO) ? BKE_CB_EVT_UNDO_POST : BKE_CB_EVT_REDO_POST);
214 wm->op_undo_depth--;
215 }
216
217 if (G.debug & G_DEBUG_IO) {
218 if (bmain->lock != nullptr) {
219 BKE_report(reports, RPT_INFO, "Checking validity of current .blend file *AFTER* undo step");
220 BLO_main_validate_libraries(bmain, reports);
221 }
222 }
223
224 WM_event_add_notifier(C, NC_WINDOW, nullptr);
225 WM_event_add_notifier(C, NC_WM | ND_UNDO, nullptr);
226
229
230 asset::list::storage_tag_main_data_dirty();
231
232 if (CLOG_CHECK(&LOG, 1)) {
234 }
235}
236
242static int ed_undo_step_direction(bContext *C, enum eUndoStepDir step, ReportList *reports)
243{
245
246 CLOG_INFO(&LOG, 1, "direction=%s", (step == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO");
247
248 /* TODO(@ideasman42): undo_system: use undo system */
249 /* grease pencil can be can be used in plenty of spaces, so check it first */
250 /* FIXME: This gpencil undo effectively only supports the one step undo/redo, undo based on name
251 * or index is fully not implemented.
252 * FIXME: However, it seems to never be used in current code (`ED_gpencil_session_active` seems
253 * to always return false). */
255 return ED_undo_gpencil_step(C, step);
256 }
257
259
260 ed_undo_step_pre(C, wm, step, reports);
261
262 if (step == STEP_UNDO) {
264 }
265 else {
267 }
268
269 ed_undo_step_post(C, wm, step, reports);
270
271 return OPERATOR_FINISHED;
272}
273
279static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports)
280{
281 BLI_assert(undo_name != nullptr);
282
283 /* FIXME: See comments in `ed_undo_step_direction`. */
285 BLI_assert_msg(0, "Not implemented currently.");
286 }
287
289 UndoStep *undo_step_from_name = BKE_undosys_step_find_by_name(wm->undo_stack, undo_name);
290 if (undo_step_from_name == nullptr) {
291 CLOG_ERROR(&LOG, "Step name='%s' not found in current undo stack", undo_name);
292
293 return OPERATOR_CANCELLED;
294 }
295
296 UndoStep *undo_step_target = undo_step_from_name->prev;
297 if (undo_step_target == nullptr) {
298 CLOG_ERROR(&LOG, "Step name='%s' cannot be undone", undo_name);
299
300 return OPERATOR_CANCELLED;
301 }
302
303 const int undo_dir_i = BKE_undosys_step_calc_direction(
304 wm->undo_stack, undo_step_target, nullptr);
305 BLI_assert(ELEM(undo_dir_i, -1, 1));
306 const enum eUndoStepDir undo_dir = (undo_dir_i == -1) ? STEP_UNDO : STEP_REDO;
307
308 CLOG_INFO(&LOG,
309 1,
310 "name='%s', found direction=%s",
311 undo_name,
312 (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO");
313
314 ed_undo_step_pre(C, wm, undo_dir, reports);
315
316 BKE_undosys_step_load_data_ex(wm->undo_stack, C, undo_step_target, nullptr, true);
317
318 ed_undo_step_post(C, wm, undo_dir, reports);
319
320 return OPERATOR_FINISHED;
321}
322
328static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *reports)
329{
330 BLI_assert(undo_index >= 0);
331
332 /* FIXME: See comments in `ed_undo_step_direction`. */
334 BLI_assert_msg(0, "Not implemented currently.");
335 }
336
338 const int active_step_index = BLI_findindex(&wm->undo_stack->steps, wm->undo_stack->step_active);
339 if (undo_index == active_step_index) {
340 return OPERATOR_CANCELLED;
341 }
342 const enum eUndoStepDir undo_dir = (undo_index < active_step_index) ? STEP_UNDO : STEP_REDO;
343
344 CLOG_INFO(&LOG,
345 1,
346 "index='%d', found direction=%s",
347 undo_index,
348 (undo_dir == STEP_UNDO) ? "STEP_UNDO" : "STEP_REDO");
349
350 ed_undo_step_pre(C, wm, undo_dir, reports);
351
353
354 ed_undo_step_post(C, wm, undo_dir, reports);
355
356 return OPERATOR_FINISHED;
357}
358
359void ED_undo_grouped_push(bContext *C, const char *str)
360{
361 /* do nothing if previous undo task is the same as this one (or from the same undo group) */
363 const UndoStep *us = wm->undo_stack->step_active;
364 if (us && STREQ(str, us->name)) {
366 }
367
368 /* push as usual */
369 ED_undo_push(C, str);
370}
371
373{
375}
377{
379}
380
382{
383 /* in future, get undo string info? */
384 ED_undo_push(C, op->type->name);
385}
386
388{
389 if (op->type->undo_group[0] != '\0') {
391 }
392 else {
394 }
395}
396
398{
399 /* search back a couple of undo's, in case something else added pushes */
401}
402
403bool ED_undo_is_valid(const bContext *C, const char *undoname)
404{
406 return BKE_undosys_stack_has_undo(wm->undo_stack, undoname);
407}
408
410{
411 /* Some modes don't co-exist with memfile undo, disable their use: #60593
412 * (this matches 2.7x behavior). */
413 const Scene *scene = CTX_data_scene(C);
414 ViewLayer *view_layer = CTX_data_view_layer(C);
415 if (view_layer != nullptr) {
416 BKE_view_layer_synced_ensure(scene, view_layer);
417 Object *obact = BKE_view_layer_active_object_get(view_layer);
418 if (obact != nullptr) {
419 if (obact->mode & OB_MODE_EDIT) {
420 return false;
421 }
422 }
423 }
424 return true;
425}
426
428{
429 const Scene *scene = CTX_data_scene(C);
430 ViewLayer *view_layer = CTX_data_view_layer(C);
431 if (view_layer != nullptr) {
432 BKE_view_layer_synced_ensure(scene, view_layer);
433 Object *obact = BKE_view_layer_active_object_get(view_layer);
434 if (obact != nullptr) {
435 if (obact->mode & OB_MODE_ALL_PAINT) {
436 /* Don't store property changes when painting
437 * (only do undo pushes on brush strokes which each paint operator handles on its own). */
438 CLOG_INFO(&LOG, 1, "skipping undo for paint-mode");
439 return false;
440 }
441 if (obact->mode & OB_MODE_EDIT) {
442 if ((id == nullptr) || (obact->data == nullptr) ||
443 (GS(id->name) != GS(((ID *)obact->data)->name)))
444 {
445 /* No undo push on id type mismatch in edit-mode. */
446 CLOG_INFO(&LOG, 1, "skipping undo for edit-mode");
447 return false;
448 }
449 }
450 }
451 }
452 return true;
453}
454
456{
457 wmWindowManager *wm = static_cast<wmWindowManager *>(G_MAIN->wm.first);
458 return wm->undo_stack;
459}
460
463/* -------------------------------------------------------------------- */
471{
472 /* The "last operator" should disappear, later we can tie this with undo stack nicer. */
474
475 /* Keep button under the cursor active. */
477
479}
480
482{
483 /* "last operator" should disappear, later we can tie this with undo stack nicer */
486 if (ret & OPERATOR_FINISHED) {
488 }
489 return ret;
490}
491
493{
494 if (G.background) {
495 /* Exception for background mode, see: #60934.
496 * NOTE: since the undo stack isn't initialized on startup, background mode behavior
497 * won't match regular usage, this is just for scripts to do explicit undo pushes. */
499 if (wm->undo_stack == nullptr) {
501 }
502 }
503 char str[BKE_UNDO_STR_MAX];
504 RNA_string_get(op->ptr, "message", str);
505 ED_undo_push(C, str);
506 return OPERATOR_FINISHED;
507}
508
510{
512 if (ret & OPERATOR_FINISHED) {
514 }
515 return ret;
516}
517
518static int ed_undo_redo_exec(bContext *C, wmOperator * /*op*/)
519{
520 wmOperator *last_op = WM_operator_last_redo(C);
521 int ret = ED_undo_operator_repeat(C, last_op);
523 if (ret & OPERATOR_FINISHED) {
524 /* Keep button under the cursor active. */
526 }
527 return ret;
528}
529
530/* Disable in background mode, we could support if it's useful, #60934. */
531
533{
535 if (wm->undo_stack == nullptr) {
536 /* This message is intended for Python developers,
537 * it will be part of the exception when attempting to call undo in background mode. */
539 C,
540 "Undo disabled at startup in background-mode "
541 "(call `ed.undo_push()` to explicitly initialize the undo-system)");
542 return false;
543 }
544 return true;
545}
546
548{
549 if (ed_undo_is_init_poll(C) == false) {
550 return false;
551 }
552 return ED_operator_screenactive(C);
553}
554
556{
557 wmOperator *last_op = WM_operator_last_redo(C);
558 return (last_op && ed_undo_is_init_and_screenactive_poll(C) &&
560}
561
562static bool ed_undo_poll(bContext *C)
563{
565 return false;
566 }
568 return (undo_stack->step_active != nullptr) && (undo_stack->step_active->prev != nullptr);
569}
570
572{
573 /* identifiers */
574 ot->name = "Undo";
575 ot->description = "Undo previous action";
576 ot->idname = "ED_OT_undo";
577
578 /* api callbacks */
581}
582
584{
585 /* identifiers */
586 ot->name = "Undo Push";
587 ot->description = "Add an undo state (internal use only)";
588 ot->idname = "ED_OT_undo_push";
589
590 /* api callbacks */
592 /* Unlike others undo operators this initializes undo stack. */
594
596
598 "message",
599 "Add an undo step *function may be moved*",
601 "Undo Message",
602 "");
603}
604
605static bool ed_redo_poll(bContext *C)
606{
608 return false;
609 }
611 return (undo_stack->step_active != nullptr) && (undo_stack->step_active->next != nullptr);
612}
613
615{
616 /* identifiers */
617 ot->name = "Redo";
618 ot->description = "Redo previous action";
619 ot->idname = "ED_OT_redo";
620
621 /* api callbacks */
624}
625
627{
628 /* identifiers */
629 ot->name = "Undo and Redo";
630 ot->description = "Undo and redo previous action";
631 ot->idname = "ED_OT_undo_redo";
632
633 /* api callbacks */
636}
637
640/* -------------------------------------------------------------------- */
645{
646 int ret = 0;
647
648 if (op) {
649 CLOG_INFO(&LOG, 1, "idname='%s'", op->type->idname);
651 const ScrArea *area = CTX_wm_area(C);
652 Scene *scene = CTX_data_scene(C);
653
654 /* keep in sync with logic in view3d_panel_operator_redo() */
655 ARegion *region_orig = CTX_wm_region(C);
656 /* If the redo is called from a HUD, this knows about the region type the operator was
657 * initially called in, so attempt to restore that. */
658 ARegion *redo_region_from_hud = (region_orig->regiontype == RGN_TYPE_HUD) ?
659 ED_area_type_hud_redo_region_find(area, region_orig) :
660 nullptr;
661 ARegion *region_repeat = redo_region_from_hud ? redo_region_from_hud :
663
664 if (region_repeat) {
665 CTX_wm_region_set(C, region_repeat);
666 }
667
668 if (WM_operator_repeat_check(C, op) && WM_operator_poll(C, op->type) &&
669 /* NOTE: undo/redo can't run if there are jobs active,
670 * check for screen jobs only so jobs like material/texture/world preview
671 * (which copy their data), won't stop redo, see #29579.
672 *
673 * NOTE: WM_operator_check_ui_enabled() jobs test _must_ stay in sync with this. */
674 (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY) == 0))
675 {
676 int retval;
677
678 if (G.debug & G_DEBUG) {
679 printf("redo_cb: operator redo %s\n", op->type->name);
680 }
681
683
684 ED_undo_pop_op(C, op);
685
686 if (op->type->check) {
687 if (op->type->check(C, op)) {
688 /* check for popup and re-layout buttons */
689 ARegion *region_popup = CTX_wm_region_popup(C);
690 if (region_popup) {
691 ED_region_tag_refresh_ui(region_popup);
692 }
693 }
694 }
695
696 retval = WM_operator_repeat(C, op);
697 if ((retval & OPERATOR_FINISHED) == 0) {
698 if (G.debug & G_DEBUG) {
699 printf("redo_cb: operator redo failed: %s, return %d\n", op->type->name, retval);
700 }
701 ED_undo_redo(C);
702 }
703 else {
704 ret = 1;
705 }
706 }
707 else {
708 if (G.debug & G_DEBUG) {
709 printf("redo_cb: WM_operator_repeat_check returned false %s\n", op->type->name);
710 }
711 }
712
713 /* set region back */
714 CTX_wm_region_set(C, region_orig);
715 }
716 else {
717 CLOG_WARN(&LOG, "called with nullptr 'op'");
718 }
719
720 return ret;
721}
722
723void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void * /*arg_unused*/)
724{
726}
727
728void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int /*arg_unused*/)
729{
731}
732
735/* -------------------------------------------------------------------- */
741/* NOTE: also check #ed_undo_step() in top if you change notifiers. */
743{
744 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item");
745 if (RNA_property_is_set(op->ptr, prop)) {
746 const int item = RNA_property_int_get(op->ptr, prop);
747 const int ret = ed_undo_step_by_index(C, item, op->reports);
748 if (ret & OPERATOR_FINISHED) {
750
751 WM_event_add_notifier(C, NC_WINDOW, nullptr);
752 return OPERATOR_FINISHED;
753 }
754 }
755 return OPERATOR_CANCELLED;
756}
757
758static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent * /*event*/)
759{
760 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "item");
761 if (RNA_property_is_set(op->ptr, prop)) {
762 return undo_history_exec(C, op);
763 }
764
765 WM_menu_name_call(C, "TOPBAR_MT_undo_history", WM_OP_INVOKE_DEFAULT);
766 return OPERATOR_FINISHED;
767}
768
770{
771 /* identifiers */
772 ot->name = "Undo History";
773 ot->description = "Redo specific action in history";
774 ot->idname = "ED_OT_undo_history";
775
776 /* api callbacks */
780
781 RNA_def_int(ot->srna, "item", 0, 0, INT_MAX, "Item", "", 0, INT_MAX);
782}
783
786/* -------------------------------------------------------------------- */
791 Scene *scene, ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
792{
793 using namespace blender::ed;
794 BKE_view_layer_synced_ensure(scene, view_layer);
795 Object *ob_prev = BKE_view_layer_active_object_get(view_layer);
796 if (ob_prev != ob) {
797 Base *base = BKE_view_layer_base_find(view_layer, ob);
798 if (base != nullptr) {
799 view_layer->basact = base;
800 object::base_active_refresh(G_MAIN, scene, view_layer);
801 }
802 else {
803 /* Should never fail, may not crash but can give odd behavior. */
804 CLOG_WARN(log, "'%s' failed to restore active object: '%s'", info, ob->id.name + 2);
805 }
806 }
807}
808
810 const Scene *scene_ref,
811 Scene **scene_p,
812 ViewLayer **view_layer_p)
813{
814 if (*scene_p == scene_ref) {
815 return;
816 }
817 LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
818 if (win->scene == scene_ref) {
819 *scene_p = win->scene;
820 *view_layer_p = WM_window_get_active_view_layer(win);
821 return;
822 }
823 }
824}
825
827 ViewLayer *view_layer,
828 Object **object_array,
829 uint object_array_len,
830 uint object_array_stride)
831{
832 using namespace blender::ed;
833 Main *bmain = G_MAIN;
834 /* Don't request unique data because we want to de-select objects when exiting edit-mode
835 * for that to be done on all objects we can't skip ones that share data. */
837 for (Base *base : bases) {
838 ((ID *)base->object->data)->tag |= ID_TAG_DOIT;
839 }
840 Object **ob_p = object_array;
841 for (uint i = 0; i < object_array_len;
842 i++, ob_p = static_cast<Object **>(POINTER_OFFSET(ob_p, object_array_stride)))
843 {
844 Object *obedit = *ob_p;
845 object::editmode_enter_ex(bmain, scene, obedit, object::EM_NO_CONTEXT);
846 ((ID *)obedit->data)->tag &= ~ID_TAG_DOIT;
847 }
848 for (Base *base : bases) {
849 const ID *id = static_cast<ID *>(base->object->data);
850 if (id->tag & ID_TAG_DOIT) {
851 object::editmode_exit_ex(bmain, scene, base->object, object::EM_FREEDATA);
852 /* Ideally we would know the selection state it was before entering edit-mode,
853 * for now follow the convention of having them unselected when exiting the mode. */
854 object::base_select(base, object::BA_DESELECT);
855 }
856 }
857}
858
861/* -------------------------------------------------------------------- */
872 ViewLayer *view_layer)
873{
874 BKE_view_layer_synced_ensure(scene, view_layer);
875 Base *baseact = BKE_view_layer_active_base_get(view_layer);
876 if ((baseact == nullptr) || (baseact->object->mode & OB_MODE_EDIT) == 0) {
877 return {};
878 }
879 Set<const ID *> object_data;
880 const short object_type = baseact->object->type;
881 Vector<Object *> objects(object_data.size());
882 /* Base iteration, starting with the active-base to ensure it's the first item in the array.
883 * Looping over the active-base twice is OK as the tag check prevents it being handled twice. */
884 for (Base *base = baseact,
885 *base_next = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first);
886 base;
887 base = base_next, base_next = base_next ? base_next->next : nullptr)
888 {
889 Object *ob = base->object;
890 if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
891 if (object_data.add(static_cast<const ID *>(ob->data))) {
892 objects.append(ob);
893 }
894 }
895 }
896 BLI_assert(!object_data.is_empty());
897 BLI_assert(objects[0] == baseact->object);
898 return objects;
899}
900
902{
903 BKE_view_layer_synced_ensure(scene, view_layer);
904 Base *baseact = BKE_view_layer_active_base_get(view_layer);
905 if ((baseact == nullptr) || (baseact->object->mode & OB_MODE_EDIT) == 0) {
906 return {};
907 }
908 Set<const ID *> object_data;
909 const short object_type = baseact->object->type;
910 Vector<Base *> bases;
911 /* Base iteration, starting with the active-base to ensure it's the first item in the array.
912 * Looping over the active-base twice is OK as the tag check prevents it being handled twice. */
913 for (Base *base = BKE_view_layer_active_base_get(view_layer),
914 *base_next = static_cast<Base *>(BKE_view_layer_object_bases_get(view_layer)->first);
915 base;
916 base = base_next, base_next = base_next ? base_next->next : nullptr)
917 {
918 Object *ob = base->object;
919 if ((ob->type == object_type) && (ob->mode & OB_MODE_EDIT)) {
920 if (object_data.add(static_cast<const ID *>(ob->data))) {
921 bases.append(base);
922 }
923 }
924 }
925
926 BLI_assert(!object_data.is_empty());
927 BLI_assert(bases[0] == baseact);
928 return bases;
929}
930
#define BKE_UNDO_STR_MAX
void BKE_callback_exec_id(Main *bmain, ID *id, eCbEvent evt)
Definition callbacks.cc:44
@ 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)
#define G_MAIN
@ G_DEBUG
@ G_DEBUG_IO
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)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
ARegion * BKE_area_find_region_active_win(const ScrArea *area)
Definition screen.cc:828
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)
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:50
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
#define LISTBASE_FOREACH(type, var, list)
int BLI_findindex(const struct ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
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:182
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:181
#define CLOG_CHECK(clg_ref, verbose_level,...)
Definition CLG_log.h:153
#define CLOG_INFO(clg_ref, level,...)
Definition CLG_log.h:179
@ ID_TAG_DOIT
Definition DNA_ID.h:1003
#define OB_MODE_ALL_PAINT
@ OB_MODE_EDIT
Object is a sort of wrapper for general info.
@ RGN_TYPE_HUD
void ED_outliner_select_sync_from_all_tag(bContext *C)
void ED_region_tag_refresh_ui(ARegion *region)
Definition area.cc:662
ARegion * ED_area_type_hud_redo_region_find(const ScrArea *area, const ARegion *hud_region)
bool ED_operator_screenactive(bContext *C)
Read Guarded memory(de)allocation.
@ WM_JOB_TYPE_ANY
Definition WM_api.hh:1575
@ OPTYPE_INTERNAL
Definition WM_types.hh:182
#define NC_WINDOW
Definition WM_types.hh:342
#define NC_WM
Definition WM_types.hh:341
#define ND_LIB_OVERRIDE_CHANGED
Definition WM_types.hh:386
#define ND_UNDO
Definition WM_types.hh:384
@ WM_OP_INVOKE_DEFAULT
Definition WM_types.hh:218
unsigned int U
Definition btGjkEpa3.h:78
int64_t size() const
Definition BLI_set.hh:564
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:572
void append(const T &value)
#define printf
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:790
void ED_undo_push(bContext *C, const char *str)
Definition ed_undo.cc:104
void ED_OT_redo(wmOperatorType *ot)
Definition ed_undo.cc:614
UndoStack * ED_undo_stack_get()
Definition ed_undo.cc:455
static int ed_undo_push_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:492
static void ed_undo_step_pre(bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
Definition ed_undo.cc:161
void ED_undo_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:381
bool ED_undo_is_legacy_compatible_for_property(bContext *C, ID *id)
Definition ed_undo.cc:427
void ED_undo_pop_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:397
void ED_undo_group_begin(bContext *C)
Definition ed_undo.cc:92
bool ED_undo_is_valid(const bContext *C, const char *undoname)
Definition ed_undo.cc:403
void ED_OT_undo_redo(wmOperatorType *ot)
Definition ed_undo.cc:626
void ED_undo_operator_repeat_cb_evt(bContext *C, void *arg_op, int)
Definition ed_undo.cc:728
static int ed_undo_step_by_index(bContext *C, const int undo_index, ReportList *reports)
Definition ed_undo.cc:328
void ED_undo_operator_repeat_cb(bContext *C, void *arg_op, void *)
Definition ed_undo.cc:723
void ED_OT_undo_push(wmOperatorType *ot)
Definition ed_undo.cc:583
int ED_undo_operator_repeat(bContext *C, wmOperator *op)
Definition ed_undo.cc:644
static void ed_undo_step_post(bContext *C, wmWindowManager *wm, const enum eUndoStepDir undo_dir, ReportList *reports)
Definition ed_undo.cc:198
static void ed_undo_refresh_for_op(bContext *C)
Definition ed_undo.cc:470
static int ed_undo_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:481
Vector< Object * > ED_undo_editmode_objects_from_view_layer(const Scene *scene, ViewLayer *view_layer)
Definition ed_undo.cc:871
static int undo_history_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition ed_undo.cc:758
static int undo_history_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:742
static bool ed_redo_poll(bContext *C)
Definition ed_undo.cc:605
static bool ed_undo_is_init_poll(bContext *C)
Definition ed_undo.cc:532
static bool ed_undo_is_init_and_screenactive_poll(bContext *C)
Definition ed_undo.cc:547
static int ed_redo_exec(bContext *C, wmOperator *op)
Definition ed_undo.cc:509
static int ed_undo_step_by_name(bContext *C, const char *undo_name, ReportList *reports)
Definition ed_undo.cc:279
void ED_undo_redo(bContext *C)
Definition ed_undo.cc:376
bool ED_undo_is_state_valid(bContext *C)
Definition ed_undo.cc:69
void ED_OT_undo(wmOperatorType *ot)
Definition ed_undo.cc:571
static int ed_undo_step_direction(bContext *C, enum eUndoStepDir step, ReportList *reports)
Definition ed_undo.cc:242
void ED_OT_undo_history(wmOperatorType *ot)
Definition ed_undo.cc:769
static bool ed_undo_poll(bContext *C)
Definition ed_undo.cc:562
static CLG_LogRef LOG
Definition ed_undo.cc:61
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:826
void ED_undo_grouped_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:387
static bool ed_undo_redo_poll(bContext *C)
Definition ed_undo.cc:555
bool ED_undo_is_memfile_compatible(const bContext *C)
Definition ed_undo.cc:409
void ED_undo_pop(bContext *C)
Definition ed_undo.cc:372
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:809
void ED_undo_group_end(bContext *C)
Definition ed_undo.cc:98
static int ed_undo_redo_exec(bContext *C, wmOperator *)
Definition ed_undo.cc:518
void ED_undo_grouped_push(bContext *C, const char *str)
Definition ed_undo.cc:359
Vector< Base * > ED_undo_editmode_bases_from_view_layer(const Scene *scene, ViewLayer *view_layer)
Definition ed_undo.cc:901
#define str(s)
int ED_undo_gpencil_step(bContext *C, const int step)
int ED_gpencil_session_active()
#define GS(x)
Definition iris.cc:202
ccl_device_inline float3 log(float3 v)
#define G(x, y, z)
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)
void RNA_string_get(PointerRNA *ptr, const char *name, char *value)
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)
static const int steps
struct Base * next
struct Object * object
Definition DNA_ID.h:413
char name[66]
Definition DNA_ID.h:425
MainLock * lock
Definition BKE_main.hh:272
UndoStep * step_init
UndoStep * step_active
ListBase steps
UndoStep * prev
UndoStep * next
char name[64]
struct Base * basact
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
bool(* check)(bContext *C, wmOperator *op)
Definition WM_types.hh:1014
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
const char * undo_group
Definition WM_types.hh:998
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct wmOperatorType * type
struct PointerRNA * ptr
struct UndoStack * undo_stack
#define undo_stack
void WM_operator_stack_clear(wmWindowManager *wm)
Definition wm.cc:382
void WM_operator_free_all_after(wmWindowManager *wm, wmOperator *op)
Definition wm.cc:318
void WM_menu_name_call(bContext *C, const char *menu_name, short context)
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)
int WM_operator_repeat(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_event_add_mousemove(wmWindow *win)
void WM_file_tag_modified()
Definition wm_files.cc:171
wmOperatorType * ot
Definition wm_files.cc:4125
void WM_jobs_kill_all(wmWindowManager *wm)
Definition wm_jobs.cc:576
bool WM_jobs_test(const wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:223
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)