diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2015-01-29 22:53:12 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2015-04-20 13:24:33 +0300 |
commit | 5e42aff39795643490f0d3af9f9bd4ee1c730904 (patch) | |
tree | 882a14a1e440c1a3aa75826c5f1ba4f32391b8f5 /source/blender/editors/util | |
parent | 3f539c987f412ac3b2078b75d8eafcc2a392b07c (diff) |
Basic undo support in the new strand edit mode.
This uses the generalized undo stack system which is also used for
object data edit. An extension is necessary to tell the undo functions
which object is specifically used for generating undo data and
identifying the stack, since strand editing does not edit the obdata
itself.
Diffstat (limited to 'source/blender/editors/util')
-rw-r--r-- | source/blender/editors/util/editmode_undo.c | 19 | ||||
-rw-r--r-- | source/blender/editors/util/undo.c | 12 |
2 files changed, 26 insertions, 5 deletions
diff --git a/source/blender/editors/util/editmode_undo.c b/source/blender/editors/util/editmode_undo.c index bc7a8374c73..06bcbd2e71a 100644 --- a/source/blender/editors/util/editmode_undo.c +++ b/source/blender/editors/util/editmode_undo.c @@ -84,6 +84,7 @@ typedef struct UndoElem { void *undodata; uintptr_t undosize; char name[BKE_UNDO_STR_MAX]; + Object *(*get_object)(const bContext *C); void * (*getdata)(bContext * C); void (*freedata)(void *); void (*to_editmode)(void *, void *, void *); @@ -106,14 +107,15 @@ static void undo_restore(UndoElem *undo, void *editdata, void *obdata) /* name can be a dynamic string */ void undo_editmode_push(bContext *C, const char *name, - void * (*getdata)(bContext * C), + Object *(*get_object)(const bContext *C), + void * (*getdata)(bContext *C), void (*freedata)(void *), void (*to_editmode)(void *, void *, void *), void *(*from_editmode)(void *, void *), int (*validate_undo)(void *, void *)) { UndoElem *uel; - Object *obedit = CTX_data_edit_object(C); + Object *obedit = get_object(C); void *editdata; int nr; uintptr_t memused, totmem, maxmem; @@ -133,6 +135,7 @@ void undo_editmode_push(bContext *C, const char *name, BLI_strncpy(uel->name, name, sizeof(uel->name)); BLI_addtail(&undobase, uel); + uel->get_object = get_object; uel->getdata = getdata; uel->freedata = freedata; uel->to_editmode = to_editmode; @@ -193,13 +196,13 @@ void undo_editmode_push(bContext *C, const char *name, static void undo_clean_stack(bContext *C) { UndoElem *uel, *next; - Object *obedit = CTX_data_edit_object(C); /* global undo changes pointers, so we also allow identical names */ /* side effect: when deleting/renaming object and start editing new one with same name */ uel = undobase.first; while (uel) { + Object *obedit = uel->get_object(C); void *editdata = uel->getdata(C); bool is_valid = false; next = uel->next; @@ -232,12 +235,13 @@ static void undo_clean_stack(bContext *C) /* 1 = an undo, -1 is a redo. we have to make sure 'curundo' remains at current situation */ void undo_editmode_step(bContext *C, int step) { - Object *obedit = CTX_data_edit_object(C); + Object *obedit; /* prevent undo to happen on wrong object, stack can be a mix */ undo_clean_stack(C); if (step == 0) { + obedit = curundo->get_object(C); undo_restore(curundo, curundo->getdata(C), obedit->data); } else if (step == 1) { @@ -248,6 +252,7 @@ void undo_editmode_step(bContext *C, int step) else { if (G.debug & G_DEBUG) printf("undo %s\n", curundo->name); curundo = curundo->prev; + obedit = curundo->get_object(C); undo_restore(curundo, curundo->getdata(C), obedit->data); } } @@ -258,15 +263,19 @@ void undo_editmode_step(bContext *C, int step) error("No more steps to redo"); } else { + obedit = curundo->get_object(C); undo_restore(curundo->next, curundo->getdata(C), obedit->data); curundo = curundo->next; if (G.debug & G_DEBUG) printf("redo %s\n", curundo->name); } } + obedit = curundo->get_object(C); + /* special case for editmesh, mode must be copied back to the scene */ if (obedit->type == OB_MESH) { - EDBM_selectmode_to_scene(C); + if (obedit == CTX_data_edit_object(C)) + EDBM_selectmode_to_scene(C); } DAG_id_tag_update(&obedit->id, OB_RECALC_DATA); diff --git a/source/blender/editors/util/undo.c b/source/blender/editors/util/undo.c index ee6101d2952..3eef8401db9 100644 --- a/source/blender/editors/util/undo.c +++ b/source/blender/editors/util/undo.c @@ -55,6 +55,7 @@ #include "ED_mball.h" #include "ED_mesh.h" #include "ED_object.h" +#include "ED_physics.h" #include "ED_render.h" #include "ED_screen.h" #include "ED_paint.h" @@ -104,6 +105,9 @@ void ED_undo_push(bContext *C, const char *str) PE_undo_push(CTX_data_scene(C), str); } + else if (obact && obact->mode & OB_MODE_HAIR_EDIT) { + undo_push_strands(C, str); + } else if (obact && obact->mode & OB_MODE_SCULPT) { /* do nothing for now */ } @@ -189,6 +193,14 @@ static int ed_undo_step(bContext *C, int step, const char *undoname) else PE_redo(scene); } + else if (obact && obact->mode & OB_MODE_HAIR_EDIT) { + if (undoname) + undo_editmode_name(C, undoname); + else + undo_editmode_step(C, step); + + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); + } else if (U.uiflag & USER_GLOBALUNDO) { // note python defines not valid here anymore. //#ifdef WITH_PYTHON |