Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/lattice/editlattice_undo.c
| Show All 32 Lines | |||||
| #include "BLI_array_utils.h" | #include "BLI_array_utils.h" | ||||
| #include "DNA_curve_types.h" | #include "DNA_curve_types.h" | ||||
| #include "DNA_lattice_types.h" | #include "DNA_lattice_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "BKE_context.h" | #include "BKE_context.h" | ||||
| #include "BKE_lattice.h" | |||||
| #include "BKE_layer.h" | #include "BKE_layer.h" | ||||
| #include "BKE_main.h" | #include "BKE_main.h" | ||||
| #include "BKE_undo_system.h" | #include "BKE_undo_system.h" | ||||
| #include "DEG_depsgraph.h" | #include "DEG_depsgraph.h" | ||||
| #include "ED_object.h" | #include "ED_object.h" | ||||
| #include "ED_lattice.h" | #include "ED_lattice.h" | ||||
| Show All 13 Lines | |||||
| * \{ */ | * \{ */ | ||||
| typedef struct UndoLattice { | typedef struct UndoLattice { | ||||
| BPoint *def; | BPoint *def; | ||||
| int pntsu, pntsv, pntsw, actbp; | int pntsu, pntsv, pntsw, actbp; | ||||
| size_t undo_size; | size_t undo_size; | ||||
| } UndoLattice; | } UndoLattice; | ||||
| static void undolatt_to_editlatt(UndoLattice *ult, EditLatt *editlatt) | static void undolatt_to_editlatt(Object *obedit, Lattice *lt, UndoLattice *ult, EditLatt *editlatt) | ||||
| { | { | ||||
| const int len_src = ult->pntsu * ult->pntsv * ult->pntsw; | const int len_src = ult->pntsu * ult->pntsv * ult->pntsw; | ||||
| const int len_dst = editlatt->latt->pntsu * editlatt->latt->pntsv * editlatt->latt->pntsw; | const int len_dst = editlatt->latt->pntsu * editlatt->latt->pntsv * editlatt->latt->pntsw; | ||||
| if (len_src != len_dst) { | if (len_src != len_dst) { | ||||
| MEM_freeN(editlatt->latt->def); | /* Not quite sure why MEM_dupallocN(ult->def) wasnt working ?*/ | ||||
| editlatt->latt->def = MEM_dupallocN(ult->def); | BKE_lattice_resize(lt, ult->pntsu, ult->pntsv, ult->pntsw, obedit); | ||||
| BKE_lattice_resize(editlatt->latt, ult->pntsu, ult->pntsv, ult->pntsw, obedit); | |||||
| } | } | ||||
| else { | else { | ||||
| memcpy(editlatt->latt->def, ult->def, sizeof(BPoint) * len_src); | memcpy(editlatt->latt->def, ult->def, sizeof(BPoint) * len_src); | ||||
| } | |||||
| editlatt->latt->pntsu = ult->pntsu; | editlatt->latt->pntsu = ult->pntsu; | ||||
| editlatt->latt->pntsv = ult->pntsv; | editlatt->latt->pntsv = ult->pntsv; | ||||
| editlatt->latt->pntsw = ult->pntsw; | editlatt->latt->pntsw = ult->pntsw; | ||||
| editlatt->latt->actbp = ult->actbp; | editlatt->latt->actbp = ult->actbp; | ||||
| } | } | ||||
| } | |||||
| static void *undolatt_from_editlatt(UndoLattice *ult, EditLatt *editlatt) | static void *undolatt_from_editlatt(UndoLattice *ult, EditLatt *editlatt) | ||||
| { | { | ||||
| BLI_assert(BLI_array_is_zeroed(ult, 1)); | BLI_assert(BLI_array_is_zeroed(ult, 1)); | ||||
| ult->def = MEM_dupallocN(editlatt->latt->def); | ult->def = MEM_dupallocN(editlatt->latt->def); | ||||
| ult->pntsu = editlatt->latt->pntsu; | ult->pntsu = editlatt->latt->pntsu; | ||||
| ult->pntsv = editlatt->latt->pntsv; | ult->pntsv = editlatt->latt->pntsv; | ||||
| ▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | for (uint i = 0; i < us->elems_len; i++) { | ||||
| if (lt->editlatt == NULL) { | if (lt->editlatt == NULL) { | ||||
| /* Should never fail, may not crash but can give odd behavior. */ | /* Should never fail, may not crash but can give odd behavior. */ | ||||
| CLOG_ERROR(&LOG, | CLOG_ERROR(&LOG, | ||||
| "name='%s', failed to enter edit-mode for object '%s', undo state invalid", | "name='%s', failed to enter edit-mode for object '%s', undo state invalid", | ||||
| us_p->name, | us_p->name, | ||||
| obedit->id.name); | obedit->id.name); | ||||
| continue; | continue; | ||||
| } | } | ||||
| undolatt_to_editlatt(&elem->data, lt->editlatt); | undolatt_to_editlatt(obedit, lt, &elem->data, lt->editlatt); | ||||
| lt->editlatt->needs_flush_to_id = 1; | lt->editlatt->needs_flush_to_id = 1; | ||||
| DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY); | DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY); | ||||
| } | } | ||||
| /* The first element is always active */ | /* The first element is always active */ | ||||
| ED_undo_object_set_active_or_warn( | ED_undo_object_set_active_or_warn( | ||||
| CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); | CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG); | ||||
| ▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines | |||||