diff options
Diffstat (limited to 'source/blender/editors/curve/editcurve_undo.c')
-rw-r--r-- | source/blender/editors/curve/editcurve_undo.c | 77 |
1 files changed, 64 insertions, 13 deletions
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c index 4eb2abaefad..ad17331853b 100644 --- a/source/blender/editors/curve/editcurve_undo.c +++ b/source/blender/editors/curve/editcurve_undo.c @@ -22,12 +22,14 @@ * \ingroup edcurve */ +#include "MEM_guardedalloc.h" + +#include "CLG_log.h" + #include "DNA_object_types.h" #include "DNA_scene_types.h" #include "DNA_anim_types.h" -#include "MEM_guardedalloc.h" - #include "BLI_blenlib.h" #include "BLI_ghash.h" #include "BLI_array_utils.h" @@ -35,6 +37,7 @@ #include "BKE_context.h" #include "BKE_curve.h" #include "BKE_fcurve.h" +#include "BKE_layer.h" #include "BKE_library.h" #include "BKE_animsys.h" #include "BKE_undo_system.h" @@ -42,6 +45,7 @@ #include "DEG_depsgraph.h" #include "ED_object.h" +#include "ED_undo.h" #include "ED_util.h" #include "ED_curve.h" @@ -50,6 +54,9 @@ #include "curve_intern.h" +/** We only need this locally. */ +static CLG_LogRef LOG = {"ed.undo.curve"}; + /* -------------------------------------------------------------------- */ /** \name Undo Conversion * \{ */ @@ -187,13 +194,19 @@ static Object *editcurve_object_from_context(bContext *C) /* -------------------------------------------------------------------- */ /** \name Implements ED Undo System + * + * \note This is similar for all edit-mode types. * \{ */ -typedef struct CurveUndoStep { - UndoStep step; - /* note: will split out into list for multi-object-editmode. */ +typedef struct CurveUndoStep_Elem { UndoRefID_Object obedit_ref; UndoCurve data; +} CurveUndoStep_Elem; + +typedef struct CurveUndoStep { + UndoStep step; + CurveUndoStep_Elem *elems; + uint elems_len; } CurveUndoStep; static bool curve_undosys_poll(bContext *C) @@ -205,9 +218,23 @@ static bool curve_undosys_poll(bContext *C) static bool curve_undosys_step_encode(struct bContext *C, UndoStep *us_p) { CurveUndoStep *us = (CurveUndoStep *)us_p; - us->obedit_ref.ptr = editcurve_object_from_context(C); - undocurve_from_editcurve(&us->data, us->obedit_ref.ptr->data, us->obedit_ref.ptr->shapenr); - us->step.data_size = us->data.undo_size; + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + + us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__); + us->elems_len = objects_len; + + for (uint i = 0; i < objects_len; i++) { + Object *ob = objects[i]; + CurveUndoStep_Elem *elem = &us->elems[i]; + + elem->obedit_ref.ptr = ob; + undocurve_from_editcurve(&elem->data, ob->data, ob->shapenr); + us->step.data_size += elem->data.undo_size; + } + MEM_freeN(objects); return true; } @@ -218,23 +245,47 @@ static void curve_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UN BLI_assert(curve_undosys_poll(C)); CurveUndoStep *us = (CurveUndoStep *)us_p; - Object *obedit = us->obedit_ref.ptr; - undocurve_to_editcurve(&us->data, obedit->data, &obedit->shapenr); - DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + + for (uint i = 0; i < us->elems_len; i++) { + CurveUndoStep_Elem *elem = &us->elems[i]; + Object *obedit = elem->obedit_ref.ptr; + Curve *cu = obedit->data; + if (cu->editnurb == NULL) { + /* Should never fail, may not crash but can give odd behavior. */ + CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", + us_p->name, obedit->id.name); + continue; + } + undocurve_to_editcurve(&elem->data, obedit->data, &obedit->shapenr); + DEG_id_tag_update(&obedit->id, OB_RECALC_DATA); + } + + /* The first element is always active */ + ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); + WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL); } static void curve_undosys_step_free(UndoStep *us_p) { CurveUndoStep *us = (CurveUndoStep *)us_p; - undocurve_free_data(&us->data); + + for (uint i = 0; i < us->elems_len; i++) { + CurveUndoStep_Elem *elem = &us->elems[i]; + undocurve_free_data(&elem->data); + } + MEM_freeN(us->elems); } static void curve_undosys_foreach_ID_ref( UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data) { CurveUndoStep *us = (CurveUndoStep *)us_p; - foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref)); + + for (uint i = 0; i < us->elems_len; i++) { + CurveUndoStep_Elem *elem = &us->elems[i]; + foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref)); + } } /* Export for ED_undo_sys. */ |