4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2004 Blender Foundation
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
35 #include "MEM_guardedalloc.h"
37 #include "DNA_mesh_types.h"
38 #include "DNA_meshdata_types.h"
39 #include "DNA_object_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_scene_types.h"
42 #include "DNA_space_types.h"
43 #include "DNA_userdef_types.h"
45 #include "BKE_blender.h"
46 #include "BKE_context.h"
47 #include "BKE_depsgraph.h"
48 #include "BKE_global.h"
49 #include "BKE_object.h"
52 #include "BLI_blenlib.h"
53 #include "BLI_editVert.h"
54 #include "BLI_dynstr.h"
56 #include "BKE_utildefines.h"
58 #include "ED_armature.h"
59 #include "ED_particle.h"
62 #include "ED_object.h"
63 #include "ED_screen.h"
64 #include "ED_sculpt.h"
71 #include "UI_interface.h"
72 #include "UI_resources.h"
74 #include "util_intern.h"
76 /* ***************** generic undo system ********************* */
78 /* ********* XXX **************** */
79 static void sound_initialize_sounds() {}
80 /* ********* XXX **************** */
82 void ED_undo_push(bContext *C, char *str)
84 wmWindowManager *wm= CTX_wm_manager(C);
85 Object *obedit= CTX_data_edit_object(C);
88 if (U.undosteps == 0) return;
90 if(obedit->type==OB_MESH)
91 undo_push_mesh(C, str);
92 else if ELEM(obedit->type, OB_CURVE, OB_SURF)
93 undo_push_curve(C, str);
94 else if (obedit->type==OB_FONT)
95 undo_push_font(C, str);
96 else if (obedit->type==OB_MBALL)
97 undo_push_mball(C, str);
98 else if (obedit->type==OB_LATTICE)
99 undo_push_lattice(C, str);
100 else if (obedit->type==OB_ARMATURE)
101 undo_push_armature(C, str);
103 else if(G.f & G_PARTICLEEDIT) {
104 if (U.undosteps == 0) return;
106 PE_undo_push(CTX_data_scene(C), str);
109 if(U.uiflag & USER_GLOBALUNDO)
110 BKE_write_undo(C, str);
115 WM_event_add_notifier(C, NC_WM|ND_DATACHANGED, NULL);
119 static int ed_undo_step(bContext *C, int step, const char *undoname)
121 Object *obedit= CTX_data_edit_object(C);
122 ScrArea *sa= CTX_wm_area(C);
124 if(sa && sa->spacetype==SPACE_IMAGE) {
125 SpaceImage *sima= (SpaceImage *)sa->spacedata.first;
127 if(G.f & G_TEXTUREPAINT || sima->flag & SI_DRAWTOOL) {
128 undo_imagepaint_step(step);
130 WM_event_add_notifier(C, NC_WINDOW, NULL);
131 return OPERATOR_FINISHED;
135 if(sa && sa->spacetype==SPACE_TEXT) {
136 ED_text_undo_step(C, step);
139 if ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE) {
141 undo_editmode_name(C, undoname);
143 undo_editmode_step(C, step);
149 if(G.f & G_TEXTUREPAINT)
150 undo_imagepaint_step(step);
151 else if(G.f & G_PARTICLEEDIT) {
153 PE_undo(CTX_data_scene(C));
155 PE_redo(CTX_data_scene(C));
162 if(U.uiflag & USER_GLOBALUNDO) {
163 #ifndef DISABLE_PYTHON
164 // XXX BPY_scripts_clear_pyobjects();
167 BKE_undo_name(C, undoname);
169 BKE_undo_step(C, step);
170 sound_initialize_sounds();
176 WM_event_add_notifier(C, NC_WINDOW, NULL);
178 return OPERATOR_FINISHED;
181 void ED_undo_pop(bContext *C)
183 ed_undo_step(C, 1, NULL);
185 void ED_undo_redo(bContext *C)
187 ed_undo_step(C, -1, NULL);
190 void ED_undo_push_op(bContext *C, wmOperator *op)
192 /* in future, get undo string info? */
193 ED_undo_push(C, op->type->name);
196 void ED_undo_pop_op(bContext *C, wmOperator *op)
198 /* search back a couple of undo's, in case something else added pushes */
199 ed_undo_step(C, 0, op->type->name);
202 static int ed_undo_exec(bContext *C, wmOperator *op)
204 /* "last operator" should disappear, later we can tie ths with undo stack nicer */
205 WM_operator_stack_clear(C);
206 return ed_undo_step(C, 1, NULL);
209 static int ed_redo_exec(bContext *C, wmOperator *op)
211 return ed_undo_step(C, -1, NULL);
214 void ED_undo_menu(bContext *C)
216 Object *obedit= CTX_data_edit_object(C);
219 //if ELEM7(obedit->type, OB_MESH, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL, OB_LATTICE, OB_ARMATURE)
220 // undo_editmode_menu();
223 if(G.f & G_PARTICLEEDIT)
224 PE_undo_menu(CTX_data_scene(C), CTX_data_active_object(C));
225 else if(U.uiflag & USER_GLOBALUNDO) {
226 char *menu= BKE_undo_menu_string();
228 short event= 0; // XXX pupmenu_col(menu, 20);
231 BKE_undo_number(C, event);
232 sound_initialize_sounds();
239 /* ********************** */
241 void ED_OT_undo(wmOperatorType *ot)
245 ot->idname= "ED_OT_undo";
248 ot->exec= ed_undo_exec;
249 ot->poll= ED_operator_screenactive;
252 void ED_OT_redo(wmOperatorType *ot)
256 ot->idname= "ED_OT_redo";
259 ot->exec= ed_redo_exec;
260 ot->poll= ED_operator_screenactive;