Fix T41226: Wrong Undo on curves and hooks

This commit is contained in:
Sergey Sharybin 2014-07-31 18:21:30 +06:00
parent cba027c8c3
commit e042c8428f
Notes: blender-bot 2023-02-14 10:17:40 +01:00
Referenced by commit 2f2bf513e9, Revert "Fix T41226: Wrong Undo on curves and hooks"
Referenced by issue #41226, Wrong Undo on curves
1 changed files with 43 additions and 16 deletions

View File

@ -1165,7 +1165,7 @@ int ED_curve_updateAnimPaths(Curve *cu)
/* ********************* LOAD and MAKE *************** */
static int *initialize_index_map(Object *obedit, int *r_old_totvert)
static int *initialize_index_map(Object *obedit, int *r_old_totvert, bool reverse)
{
Curve *curve = (Curve *) obedit->data;
EditNurb *editnurb = curve->editnurb;
@ -1200,15 +1200,29 @@ static int *initialize_index_map(Object *obedit, int *r_old_totvert)
while (a--) {
keyIndex = getCVKeyIndex(editnurb, bezt);
if (keyIndex) {
if (keyIndex->switched) {
old_to_new_map[keyIndex->vertex_index] = vertex_index + 2;
old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1;
old_to_new_map[keyIndex->vertex_index + 2] = vertex_index;
if (reverse) {
if (keyIndex->switched) {
old_to_new_map[vertex_index] = keyIndex->vertex_index + 2;
old_to_new_map[vertex_index + 1] = keyIndex->vertex_index + 1;
old_to_new_map[vertex_index + 2] = keyIndex->vertex_index;
}
else {
old_to_new_map[vertex_index] = keyIndex->vertex_index;
old_to_new_map[vertex_index + 1] = keyIndex->vertex_index + 1;
old_to_new_map[vertex_index + 2] = keyIndex->vertex_index + 2;
}
}
else {
old_to_new_map[keyIndex->vertex_index] = vertex_index;
old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1;
old_to_new_map[keyIndex->vertex_index + 2] = vertex_index + 2;
if (keyIndex->switched) {
old_to_new_map[keyIndex->vertex_index] = vertex_index + 2;
old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1;
old_to_new_map[keyIndex->vertex_index + 2] = vertex_index;
}
else {
old_to_new_map[keyIndex->vertex_index] = vertex_index;
old_to_new_map[keyIndex->vertex_index + 1] = vertex_index + 1;
old_to_new_map[keyIndex->vertex_index + 2] = vertex_index + 2;
}
}
}
vertex_index += 3;
@ -1222,7 +1236,12 @@ static int *initialize_index_map(Object *obedit, int *r_old_totvert)
while (a--) {
keyIndex = getCVKeyIndex(editnurb, bp);
if (keyIndex) {
old_to_new_map[keyIndex->vertex_index] = vertex_index;
if (reverse) {
old_to_new_map[vertex_index] = keyIndex->vertex_index;
}
else {
old_to_new_map[keyIndex->vertex_index] = vertex_index;
}
}
vertex_index++;
bp++;
@ -1234,7 +1253,7 @@ static int *initialize_index_map(Object *obedit, int *r_old_totvert)
return old_to_new_map;
}
static void remap_hooks_and_vertex_parents(Object *obedit)
static void remap_hooks_and_vertex_parents(Object *obedit, bool reverse)
{
Object *object;
Curve *curve = (Curve *) obedit->data;
@ -1249,7 +1268,9 @@ static void remap_hooks_and_vertex_parents(Object *obedit)
ELEM(object->partype, PARVERT1, PARVERT3))
{
if (old_to_new_map == NULL) {
old_to_new_map = initialize_index_map(obedit, &old_totvert);
old_to_new_map = initialize_index_map(obedit,
&old_totvert,
reverse);
}
if (object->par1 < old_totvert) {
@ -1278,7 +1299,9 @@ static void remap_hooks_and_vertex_parents(Object *obedit)
int i, j;
if (old_to_new_map == NULL) {
old_to_new_map = initialize_index_map(obedit, &old_totvert);
old_to_new_map = initialize_index_map(obedit,
&old_totvert,
reverse);
}
for (i = j = 0; i < hmd->totindex; i++) {
@ -1315,8 +1338,6 @@ void load_editNurb(Object *obedit)
Nurb *nu, *newnu;
ListBase newnurb = {NULL, NULL}, oldnurb = cu->nurb;
remap_hooks_and_vertex_parents(obedit);
for (nu = editnurb->first; nu; nu = nu->next) {
newnu = BKE_nurb_duplicate(nu);
BLI_addtail(&newnurb, newnu);
@ -6871,8 +6892,9 @@ void CURVE_OT_tilt_clear(wmOperatorType *ot)
/****************** undo for curves ****************/
static void undoCurve_to_editCurve(void *ucu, void *UNUSED(edata), void *cu_v)
static void undoCurve_to_editCurve(void *ucu, void *edata, void *cu_v)
{
Object *obedit = (Object *) edata;
Curve *cu = cu_v;
UndoCurve *undoCurve = ucu;
ListBase *undobase = &undoCurve->nubase;
@ -6881,6 +6903,8 @@ static void undoCurve_to_editCurve(void *ucu, void *UNUSED(edata), void *cu_v)
EditNurb *editnurb = cu->editnurb;
AnimData *ad = BKE_animdata_from_id(&cu->id);
remap_hooks_and_vertex_parents(obedit, true);
BKE_nurbList_free(editbase);
if (undoCurve->undoIndex) {
@ -6914,8 +6938,9 @@ static void undoCurve_to_editCurve(void *ucu, void *UNUSED(edata), void *cu_v)
ED_curve_updateAnimPaths(cu);
}
static void *editCurve_to_undoCurve(void *UNUSED(edata), void *cu_v)
static void *editCurve_to_undoCurve(void *edata, void *cu_v)
{
Object *obedit = (Object *) edata;
Curve *cu = cu_v;
ListBase *nubase = BKE_curve_editNurbs_get(cu);
UndoCurve *undoCurve;
@ -6951,6 +6976,8 @@ static void *editCurve_to_undoCurve(void *UNUSED(edata), void *cu_v)
undoCurve->actvert = cu->actvert;
undoCurve->actnu = cu->actnu;
remap_hooks_and_vertex_parents(obedit, false);
return undoCurve;
}