Restore bezier handles to their original flag if the transform is canceled, for IPO's and curve edit mode.

Also retopo was running of curve transform was canceled.
This commit is contained in:
Campbell Barton
2008-04-04 15:06:50 +00:00
parent eb667866df
commit 6b6e5eb4c9
4 changed files with 109 additions and 18 deletions

View File

@@ -137,6 +137,13 @@ typedef struct TransData2D {
float *loc2d; /* Pointer to real 2d location of data */
} TransData2D;
/* we need to store 2 handles for each transdata incase the other handle wasnt selected */
typedef struct TransDataCurveHandleFlags {
short ih1, ih2;
short *h1, *h2;
} TransDataCurveHandleFlags;
typedef struct TransData {
float dist; /* Distance needed to affect element (for Proportionnal Editing) */
float rdist; /* Distance to the nearest element (for Proportionnal Editing) */
@@ -153,7 +160,11 @@ typedef struct TransData {
struct bConstraint *con; /* for objects/bones, the first constraint in its constraint stack */
TransDataExtension *ext; /* for objects, poses. 1 single malloc per TransInfo! */
TransDataIpokey *tdi; /* for objects, ipo keys. per transdata a malloc */
void *tdmir; /* mirrored element pointer, in editmode mesh to EditVert */
union {
void *tdmir; /* mirrored element pointer, in editmode mesh to EditVert */
TransDataCurveHandleFlags *hdata;
} misc;
short flag; /* Various flags */
short protectflag; /* If set, copy of Object or PoseChannel protection */
/*#ifdef WITH_VERSE*/
@@ -289,6 +300,7 @@ typedef struct TransInfo {
#define TD_NOCENTER (1 << 9)
#define TD_NO_EXT (1 << 10) /* ext abused for particle key timing */
#define TD_SKIP (1 << 11) /* don't transform this data */
#define TD_BEZTRIPLE (1 << 12) /* if this is a bez triple, we need to restore the handles, if this is set transdata->misc.hdata needs freeing */
/* transsnap->status */
#define SNAP_ON 1

View File

@@ -5066,7 +5066,7 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, float *loc, flo
td2d->loc[2] = 0.0f;
td2d->loc2d = loc;
td->flag = 0;
/*td->flag = 0;*/ /* can be set beforehand, else make sure its set to 0 */
td->loc = td2d->loc;
VECCOPY(td->center, cent);
VECCOPY(td->iloc, td->loc);
@@ -5077,7 +5077,7 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, float *loc, flo
td2d->loc[2] = 0.0f;
td2d->loc2d = loc;
td->flag = 0;
/*td->flag = 0;*/ /* can be set beforehand, else make sure its set to 0 */
td->loc = td2d->loc;
VECCOPY(td->center, cent);
VECCOPY(td->iloc, td->loc);
@@ -5168,19 +5168,51 @@ void make_ipo_transdata (TransInfo *t)
bezt= ei->icu->bezt;
for (b=0; b < ei->icu->totvert; b++, bezt++) {
TransDataCurveHandleFlags *hdata = NULL;
/* only include handles if selected, and interpolaton mode uses beztriples */
if (ei->icu->ipo==IPO_BEZ) {
if (bezt->f1 & SELECT)
if (bezt->f1 & SELECT) {
td->flag |= TD_BEZTRIPLE;
hdata = td->misc.hdata = MEM_mallocN(sizeof(TransDataCurveHandleFlags), "CuHandle Data");
hdata->ih1 = bezt->h1;
hdata->h1 = &bezt->h1;
hdata->ih2 = bezt->h2; /* incase the second is not selected */
hdata->h2 = &bezt->h2;
bezt_to_transdata(td++, td2d++, bezt->vec[0], bezt->vec[1], 1, onlytime);
if (bezt->f3 & SELECT)
}
if (bezt->f3 & SELECT) {
if (hdata==NULL) {
td->flag |= TD_BEZTRIPLE;
hdata = td->misc.hdata = MEM_mallocN(sizeof(TransDataCurveHandleFlags), "CuHandle Data");
hdata->ih1 = bezt->h1;
hdata->h1 = &bezt->h1;
hdata->ih2 = bezt->h2; /* incase the second is not selected */
hdata->h2 = &bezt->h2;
}
bezt_to_transdata(td++, td2d++, bezt->vec[2], bezt->vec[1], 1, onlytime);
}
}
/* only include main vert if selected */
if (bezt->f2 & SELECT) {
if ((bezt->f1&SELECT)==0 && (bezt->f3&SELECT)==0) {
if (hdata==NULL) {
td->flag |= TD_BEZTRIPLE;
hdata = td->misc.hdata = MEM_mallocN(sizeof(TransDataCurveHandleFlags), "CuHandle Data");
hdata->ih1 = bezt->h1;
hdata->h1 = &bezt->h1;
hdata->ih2 = bezt->h2; /* incase the second is not selected */
hdata->h2 = &bezt->h2;
}
}
bezt_to_transdata(td++, td2d++, bezt->vec[1], bezt->vec[1], 1, onlytime);
}
}
/* Sets handles based on the selection */
testhandles_ipocurve(ei->icu);
}
}
}

View File

@@ -1281,7 +1281,7 @@ static void createTransCurveVerts(TransInfo *t)
Mat3CpyMat4(mtx, G.obedit->obmat);
Mat3Inv(smtx, mtx);
td = t->data;
for(nu= editNurb.first; nu; nu= nu->next) {
if((nu->type & 7)==CU_BEZIER) {
@@ -1289,6 +1289,7 @@ static void createTransCurveVerts(TransInfo *t)
head = tail = td;
for(a=0, bezt= nu->bezt; a<nu->pntsu; a++, bezt++) {
if(bezt->hide==0) {
TransDataCurveHandleFlags *hdata = NULL;
if( propmode ||
((bezt->f2 & SELECT) && (G.f & G_HIDDENHANDLES)) ||
@@ -1307,6 +1308,13 @@ static void createTransCurveVerts(TransInfo *t)
td->ext = NULL;
td->tdi = NULL;
td->val = NULL;
td->flag |= TD_BEZTRIPLE;
hdata = td->misc.hdata = MEM_mallocN(sizeof(TransDataCurveHandleFlags), "CuHandle Data");
hdata->ih1 = bezt->h1;
hdata->h1 = &bezt->h1;
hdata->ih2 = bezt->h2; /* incase the second is not selected */
hdata->h2 = &bezt->h2;
Mat3CpyMat3(td->smtx, smtx);
Mat3CpyMat3(td->mtx, mtx);
@@ -1338,7 +1346,18 @@ static void createTransCurveVerts(TransInfo *t)
Mat3CpyMat3(td->smtx, smtx);
Mat3CpyMat3(td->mtx, mtx);
if ((bezt->f1&SELECT)==0 && (bezt->f3&SELECT)==0)
/* If the middle is selected but the sides arnt, this is needed */
if (hdata==NULL) { /* if the handle was not saved by the previous handle */
td->flag |= TD_BEZTRIPLE;
hdata = td->misc.hdata = MEM_mallocN(sizeof(TransDataCurveHandleFlags), "CuHandle Data");
hdata->ih1 = bezt->h1;
hdata->h1 = &bezt->h1;
hdata->ih2 = bezt->h2; /* incase the second is not selected */
hdata->h2 = &bezt->h2;
}
td++;
count++;
tail++;
@@ -1361,6 +1380,15 @@ static void createTransCurveVerts(TransInfo *t)
td->tdi = NULL;
td->val = NULL;
if (hdata==NULL) { /* if the handle was not saved by the previous handle */
td->flag |= TD_BEZTRIPLE;
hdata = td->misc.hdata = MEM_mallocN(sizeof(TransDataCurveHandleFlags), "CuHandle Data");
hdata->ih1 = bezt->h1;
hdata->h1 = &bezt->h1;
hdata->ih2 = bezt->h2; /* incase the second is not selected */
hdata->h2 = &bezt->h2;
}
Mat3CpyMat3(td->smtx, smtx);
Mat3CpyMat3(td->mtx, mtx);
@@ -1376,6 +1404,8 @@ static void createTransCurveVerts(TransInfo *t)
}
if (propmode && head != tail)
calc_distanceCurveVerts(head, tail-1);
testhandlesNurb(nu); /* sets the handles based on their selection, do this after the data is copied to the TransData */
}
else {
TransData *head, *tail;
@@ -1789,7 +1819,7 @@ static void VertsToTransData(TransData *td, EditVert *eve)
td->ext = NULL;
td->tdi = NULL;
td->val = NULL;
td->tdmir= NULL;
td->misc.tdmir= NULL;
if (BIF_GetTransInfo()->mode == TFM_BWEIGHT) {
td->val = &(eve->bweight);
td->ival = eve->bweight;
@@ -2142,7 +2172,7 @@ static void createTransEditVerts(TransInfo *t)
/* Mirror? */
if( (mirror>0 && tob->iloc[0]>0.0f) || (mirror<0 && tob->iloc[0]<0.0f)) {
EditVert *vmir= editmesh_get_x_mirror_vert(G.obedit, tob->iloc); /* initializes octree on first call */
if(vmir!=eve) tob->tdmir= vmir;
if(vmir!=eve) tob->misc.tdmir= vmir;
}
tob++;
}

View File

@@ -255,7 +255,7 @@ static void editmesh_apply_to_mirror(TransInfo *t)
if (td->flag & TD_SKIP)
continue;
eve= td->tdmir;
eve= td->misc.tdmir;
if(eve) {
eve->co[0]= -td->loc[0];
eve->co[1]= td->loc[1];
@@ -325,8 +325,11 @@ void recalcData(TransInfo *t)
if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
/* watch it: if the time is wrong: do not correct handles */
if (test_time_ipocurve(ei->icu)) dosort++;
else testhandles_ipocurve(ei->icu);
if (test_time_ipocurve(ei->icu)) {
dosort++;
} else {
calchandles_ipocurve(ei->icu);
}
}
}
@@ -398,13 +401,20 @@ void recalcData(TransInfo *t)
Nurb *nu= editNurb.first;
DAG_object_flush_update(G.scene, G.obedit, OB_RECALC_DATA); /* sets recalc flags */
while(nu) {
test2DNurb(nu);
testhandlesNurb(nu); /* test for bezier too */
nu= nu->next;
if (t->state == TRANS_CANCEL) {
while(nu) {
calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
nu= nu->next;
}
} else {
/* Normal updating */
while(nu) {
test2DNurb(nu);
calchandlesNurb(nu);
nu= nu->next;
}
retopo_do_all();
}
retopo_do_all();
}
else if(G.obedit->type==OB_ARMATURE){ /* no recalc flag, does pose */
bArmature *arm= G.obedit->data;
@@ -711,6 +721,7 @@ void postTrans (TransInfo *t)
/* since ipokeys are optional on objects, we mallocced them per trans-data */
for(a=0, td= t->data; a<t->total; a++, td++) {
if(td->tdi) MEM_freeN(td->tdi);
if (td->flag & TD_BEZTRIPLE) MEM_freeN(td->misc.hdata);
}
MEM_freeN(t->data);
}
@@ -774,6 +785,12 @@ static void restoreElement(TransData *td) {
}
}
}
if (td->flag & TD_BEZTRIPLE) {
*(td->misc.hdata->h1) = td->misc.hdata->ih1;
*(td->misc.hdata->h2) = td->misc.hdata->ih2;
}
if(td->tdi) {
TransDataIpokey *tdi= td->tdi;