* merge r22734 from trunk
[blender.git] / source / blender / editors / transform / transform_conversions.c
index 60d209ae2db8066980efe23181ab2cf52aa137e7..57a77ae75b82206ded26d3d86947aa20b0452829 100644 (file)
@@ -917,7 +917,7 @@ static short pose_grab_with_ik(Object *ob)
        Bone *bonec;
        short tot_ik= 0;
 
-       if ((ob==NULL) || (ob->pose==NULL) || (ob->flag & OB_POSEMODE)==0)
+       if ((ob==NULL) || (ob->pose==NULL) || (ob->mode & OB_MODE_POSE)==0)
                return 0;
 
        arm = ob->data;
@@ -1217,8 +1217,7 @@ static void createTransArmatureVerts(bContext *C, TransInfo *t)
 
 static void createTransMBallVerts(bContext *C, TransInfo *t)
 {
-       // TRANSFORM_FIX_ME
-#if 0
+       MetaBall *mb = (MetaBall*)t->obedit->data;
        MetaElem *ml;
        TransData *td;
        TransDataExtension *tx;
@@ -1227,7 +1226,7 @@ static void createTransMBallVerts(bContext *C, TransInfo *t)
        int propmode = t->flag & T_PROP_EDIT;
 
        /* count totals */
-       for(ml= editelems.first; ml; ml= ml->next) {
+       for(ml= mb->editelems->first; ml; ml= ml->next) {
                if(ml->flag & SELECT) countsel++;
                if(propmode) count++;
        }
@@ -1244,7 +1243,7 @@ static void createTransMBallVerts(bContext *C, TransInfo *t)
        Mat3CpyMat4(mtx, t->obedit->obmat);
        Mat3Inv(smtx, mtx);
 
-       for(ml= editelems.first; ml; ml= ml->next) {
+       for(ml= mb->editelems->first; ml; ml= ml->next) {
                if(propmode || (ml->flag & SELECT)) {
                        td->loc= &ml->x;
                        VECCOPY(td->iloc, td->loc);
@@ -1285,7 +1284,6 @@ static void createTransMBallVerts(bContext *C, TransInfo *t)
                        tx++;
                }
        }
-#endif
 }
 
 /* ********************* curve/surface ********* */
@@ -2416,7 +2414,7 @@ static void UVsToTransData(SpaceImage *sima, TransData *td, TransData2D *td2d, f
 
 static void createTransUVs(bContext *C, TransInfo *t)
 {
-       SpaceImage *sima = (SpaceImage*)CTX_wm_space_data(C);
+       SpaceImage *sima = CTX_wm_space_image(C);
        Image *ima = CTX_data_edit_image(C);
        Scene *scene = CTX_data_scene(C);
        TransData *td = NULL;
@@ -2578,28 +2576,28 @@ static void createTransNlaData(bContext *C, TransInfo *t)
        Scene *scene= CTX_data_scene(C);
        TransData *td = NULL;
        TransDataNla *tdn = NULL;
-
+       
        bAnimContext ac;
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
        int filter;
-
+       
        int count=0;
        char side;
-
+       
        /* determine what type of data we are operating on */
        if (ANIM_animdata_get_context(C, &ac) == 0)
                return;
-
+       
        /* filter data */
        filter= (ANIMFILTER_VISIBLE | ANIMFILTER_NLATRACKS | ANIMFILTER_FOREDIT);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
+       
        /* which side of the current frame should be allowed */
        if (t->mode == TFM_TIME_EXTEND) {
                /* only side on which mouse is gets transformed */
                float xmouse, ymouse;
-
+               
                UI_view2d_region_to_view(&ac.ar->v2d, t->imval[0], t->imval[1], &xmouse, &ymouse);
                side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
        }
@@ -2607,15 +2605,15 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                /* normal transform - both sides of current frame are considered */
                side = 'B';
        }
-
+       
        /* loop 1: count how many strips are selected (consider each strip as 2 points) */
        for (ale= anim_data.first; ale; ale= ale->next) {
                NlaTrack *nlt= (NlaTrack *)ale->data;
                NlaStrip *strip;
-
+               
                /* make some meta-strips for chains of selected strips */
                BKE_nlastrips_make_metas(&nlt->strips, 1);
-
+               
                /* only consider selected strips */
                for (strip= nlt->strips.first; strip; strip= strip->next) {
                        // TODO: we can make strips have handles later on...
@@ -2628,29 +2626,29 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                        }
                }
        }
-
+       
        /* stop if trying to build list if nothing selected */
        if (count == 0) {
                /* cleanup temp list */
                BLI_freelistN(&anim_data);
                return;
        }
-
+       
        /* allocate memory for data */
        t->total= count;
-
+       
        t->data= MEM_callocN(t->total*sizeof(TransData), "TransData(NLA Editor)");
        td= t->data;
        t->customData= MEM_callocN(t->total*sizeof(TransDataNla), "TransDataNla (NLA Editor)");
        tdn= t->customData;
-
+       
        /* loop 2: build transdata array */
        for (ale= anim_data.first; ale; ale= ale->next) {
                /* only if a real NLA-track */
                if (ale->type == ANIMTYPE_NLATRACK) {
                        NlaTrack *nlt= (NlaTrack *)ale->data;
                        NlaStrip *strip;
-
+                       
                        /* only consider selected strips */
                        for (strip= nlt->strips.first; strip; strip= strip->next) {
                                // TODO: we can make strips have handles later on...
@@ -2667,44 +2665,45 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                                                 *        cases, there will need to be 1 of these tdn elements in the array skipped...
                                                 */
                                                float center[3], yval;
-
+                                               
                                                /* firstly, init tdn settings */
+                                               tdn->id= ale->id;
                                                tdn->oldTrack= tdn->nlt= nlt;
                                                tdn->strip= strip;
                                                tdn->trackIndex= BLI_findindex(&nlt->strips, strip);
-
+                                               
                                                yval= (float)(tdn->trackIndex * NLACHANNEL_STEP);
-
+                                               
                                                tdn->h1[0]= strip->start;
                                                tdn->h1[1]= yval;
                                                tdn->h2[0]= strip->end;
                                                tdn->h2[1]= yval;
-
+                                               
                                                center[0]= (float)CFRA;
                                                center[1]= yval;
                                                center[2]= 0.0f;
-
+                                               
                                                /* set td's based on which handles are applicable */
                                                if (FrameOnMouseSide(side, strip->start, (float)CFRA))
                                                {
                                                        /* just set tdn to assume that it only has one handle for now */
                                                        tdn->handle= -1;
-
+                                                       
                                                        /* now, link the transform data up to this data */
                                                        if (t->mode == TFM_TRANSLATION) {
                                                                td->loc= tdn->h1;
                                                                VECCOPY(td->iloc, tdn->h1);
-
+                                                               
                                                                /* store all the other gunk that is required by transform */
                                                                VECCOPY(td->center, center);
                                                                memset(td->axismtx, 0, sizeof(td->axismtx));
                                                                td->axismtx[2][2] = 1.0f;
-
+                                                               
                                                                td->ext= NULL; td->tdi= NULL; td->val= NULL;
-
+                                                               
                                                                td->flag |= TD_SELECTED;
                                                                td->dist= 0.0f;
-
+                                                               
                                                                Mat3One(td->mtx);
                                                                Mat3One(td->smtx);
                                                        }
@@ -2712,7 +2711,7 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                                                                td->val= &tdn->h1[0];
                                                                td->ival= tdn->h1[0];
                                                        }
-
+                                                       
                                                        td->extra= tdn;
                                                        td++;
                                                }
@@ -2720,22 +2719,22 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                                                {
                                                        /* if tdn is already holding the start handle, then we're doing both, otherwise, only end */
                                                        tdn->handle= (tdn->handle) ? 2 : 1;
-
+                                                       
                                                        /* now, link the transform data up to this data */
                                                        if (t->mode == TFM_TRANSLATION) {
                                                                td->loc= tdn->h2;
                                                                VECCOPY(td->iloc, tdn->h2);
-
+                                                               
                                                                /* store all the other gunk that is required by transform */
                                                                VECCOPY(td->center, center);
                                                                memset(td->axismtx, 0, sizeof(td->axismtx));
                                                                td->axismtx[2][2] = 1.0f;
-
+                                                               
                                                                td->ext= NULL; td->tdi= NULL; td->val= NULL;
-
+                                                               
                                                                td->flag |= TD_SELECTED;
                                                                td->dist= 0.0f;
-
+                                                               
                                                                Mat3One(td->mtx);
                                                                Mat3One(td->smtx);
                                                        }
@@ -2743,11 +2742,11 @@ static void createTransNlaData(bContext *C, TransInfo *t)
                                                                td->val= &tdn->h2[0];
                                                                td->ival= tdn->h2[0];
                                                        }
-
+                                                       
                                                        td->extra= tdn;
                                                        td++;
                                                }
-
+                                               
                                                /* if both handles were used, skip the next tdn (i.e. leave it blank) since the counting code is dumb...
                                                 * otherwise, just advance to the next one...
                                                 */
@@ -3114,32 +3113,32 @@ static void createTransActionData(bContext *C, TransInfo *t)
        Scene *scene= CTX_data_scene(C);
        TransData *td = NULL;
        tGPFtransdata *tfd = NULL;
-
+       
        bAnimContext ac;
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
        int filter;
-
+       
        int count=0;
        float cfra;
        char side;
-
+       
        /* determine what type of data we are operating on */
        if (ANIM_animdata_get_context(C, &ac) == 0)
                return;
-
+       
        /* filter data */
        if (ac.datatype == ANIMCONT_GPENCIL)
                filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT);
        else
                filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
+       
        /* which side of the current frame should be allowed */
        if (t->mode == TFM_TIME_EXTEND) {
                /* only side on which mouse is gets transformed */
                float xmouse, ymouse;
-
+               
                UI_view2d_region_to_view(&ac.ar->v2d, t->imval[0], t->imval[1], &xmouse, &ymouse);
                side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
        }
@@ -3147,11 +3146,11 @@ static void createTransActionData(bContext *C, TransInfo *t)
                /* normal transform - both sides of current frame are considered */
                side = 'B';
        }
-
+       
        /* loop 1: fully select ipo-keys and count how many BezTriples are selected */
        for (ale= anim_data.first; ale; ale= ale->next) {
                AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
-
+               
                /* convert current-frame to action-time (slightly less accurate, espcially under
                 * higher scaling ratios, but is faster than converting all points)
                 */
@@ -3159,26 +3158,26 @@ static void createTransActionData(bContext *C, TransInfo *t)
                        cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
                else
                        cfra = (float)CFRA;
-
+               
                //if (ale->type == ANIMTYPE_GPLAYER)
                //      count += count_gplayer_frames(ale->data, side, cfra);
                //else
                        count += count_fcurve_keys(ale->key_data, side, cfra);
        }
-
+       
        /* stop if trying to build list if nothing selected */
        if (count == 0) {
                /* cleanup temp list */
                BLI_freelistN(&anim_data);
                return;
        }
-
+       
        /* allocate memory for data */
        t->total= count;
-
+       
        t->data= MEM_callocN(t->total*sizeof(TransData), "TransData(Action Editor)");
        td= t->data;
-
+       
        if (ac.datatype == ANIMCONT_GPENCIL) {
                if (t->mode == TFM_TIME_SLIDE) {
                        t->customData= MEM_callocN((sizeof(float)*2)+(sizeof(tGPFtransdata)*count), "TimeSlide + tGPFtransdata");
@@ -3191,7 +3190,7 @@ static void createTransActionData(bContext *C, TransInfo *t)
        }
        else if (t->mode == TFM_TIME_SLIDE)
                t->customData= MEM_callocN(sizeof(float)*2, "TimeSlide Min/Max");
-
+       
        /* loop 2: build transdata array */
        for (ale= anim_data.first; ale; ale= ale->next) {
                //if (ale->type == ANIMTYPE_GPLAYER) {
@@ -3205,7 +3204,7 @@ static void createTransActionData(bContext *C, TransInfo *t)
                //else {
                        AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
                        FCurve *fcu= (FCurve *)ale->key_data;
-
+                       
                        /* convert current-frame to action-time (slightly less accurate, espcially under
                         * higher scaling ratios, but is faster than converting all points)
                         */
@@ -3213,22 +3212,22 @@ static void createTransActionData(bContext *C, TransInfo *t)
                                cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
                        else
                                cfra = (float)CFRA;
-
+                       
                        td= FCurveToTransData(td, fcu, adt, side, cfra);
                //}
        }
-
+       
        /* check if we're supposed to be setting minx/maxx for TimeSlide */
        if (t->mode == TFM_TIME_SLIDE) {
                float min=999999999.0f, max=-999999999.0f;
                int i;
-
+               
                td= (t->data + 1);
                for (i=1; i < count; i+=3, td+=3) {
                        if (min > *(td->val)) min= *(td->val);
                        if (max < *(td->val)) max= *(td->val);
                }
-
+               
                /* minx/maxx values used by TimeSlide are stored as a
                 * calloced 2-float array in t->customData. This gets freed
                 * in postTrans (T_FREE_CUSTOMDATA).
@@ -3254,18 +3253,18 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, AnimData *adt,
         * Due to NLA mapping, we apply NLA mapping to some of the verts here,
         * and then that mapping will be undone after transform is done.
         */
-
+       
        if (adt) {
                td2d->loc[0] = BKE_nla_tweakedit_remap(adt, loc[0], NLATIME_CONVERT_UNMAP);
                td2d->loc[1] = loc[1];
                td2d->loc[2] = 0.0f;
                td2d->loc2d = loc;
-
+               
                td->loc = td2d->loc;
                td->center[0] = BKE_nla_tweakedit_remap(adt, cent[0], NLATIME_CONVERT_UNMAP);
                td->center[1] = cent[1];
                td->center[2] = 0.0f;
-
+               
                VECCOPY(td->iloc, td->loc);
        }
        else {
@@ -3273,32 +3272,32 @@ static void bezt_to_transdata (TransData *td, TransData2D *td2d, AnimData *adt,
                td2d->loc[1] = loc[1];
                td2d->loc[2] = 0.0f;
                td2d->loc2d = loc;
-
+               
                td->loc = td2d->loc;
                VECCOPY(td->center, cent);
                VECCOPY(td->iloc, td->loc);
        }
-
+       
        memset(td->axismtx, 0, sizeof(td->axismtx));
        td->axismtx[2][2] = 1.0f;
-
+       
        td->ext= NULL; td->tdi= NULL; td->val= NULL;
-
+       
        /* store AnimData info in td->extra, for applying mapping when flushing */
        td->extra= adt;
-
+       
        if (selected) {
                td->flag |= TD_SELECTED;
                td->dist= 0.0f;
        }
        else
                td->dist= MAXFLOAT;
-
+       
        if (ishandle)
                td->flag |= TD_NOTIMESNAP;
        if (intvals)
                td->flag |= TD_INTVALUES;
-
+       
        Mat3One(td->mtx);
        Mat3One(td->smtx);
 }
@@ -3308,34 +3307,34 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
        Scene *scene= CTX_data_scene(C);
        ARegion *ar= CTX_wm_region(C);
        View2D *v2d= &ar->v2d;
-
+       
        TransData *td = NULL;
        TransData2D *td2d = NULL;
-
+       
        bAnimContext ac;
        ListBase anim_data = {NULL, NULL};
        bAnimListElem *ale;
        int filter;
-
+       
        BezTriple *bezt, *prevbezt;
        int count=0, i;
        float cfra;
        char side;
-
+       
        /* determine what type of data we are operating on */
        if (ANIM_animdata_get_context(C, &ac) == 0)
                return;
-
+       
        /* filter data */
        filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY | ANIMFILTER_CURVEVISIBLE);
        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
+       
        /* which side of the current frame should be allowed */
                // XXX we still want this mode, but how to get this using standard transform too?
        if (t->mode == TFM_TIME_EXTEND) {
                /* only side on which mouse is gets transformed */
                float xmouse, ymouse;
-
+               
                UI_view2d_region_to_view(&ac.ar->v2d, t->imval[0], t->imval[1], &xmouse, &ymouse);
                side = (xmouse > CFRA) ? 'R' : 'L'; // XXX use t->frame_side
        }
@@ -3343,12 +3342,12 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                /* normal transform - both sides of current frame are considered */
                side = 'B';
        }
-
+       
        /* loop 1: count how many BezTriples (specifically their verts) are selected (or should be edited) */
        for (ale= anim_data.first; ale; ale= ale->next) {
                AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
                FCurve *fcu= (FCurve *)ale->key_data;
-
+               
                /* convert current-frame to action-time (slightly less accurate, espcially under
                 * higher scaling ratios, but is faster than converting all points)
                 */
@@ -3356,7 +3355,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                        cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
                else
                        cfra = (float)CFRA;
-
+               
                /* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse */
                if (fcu->bezt) {
                        for (i=0, bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
@@ -3384,30 +3383,30 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                        }
                }
        }
-
+       
        /* stop if trying to build list if nothing selected */
        if (count == 0) {
                /* cleanup temp list */
                BLI_freelistN(&anim_data);
                return;
        }
-
+       
        /* allocate memory for data */
        t->total= count;
-
+       
        t->data= MEM_callocN(t->total*sizeof(TransData), "TransData (Graph Editor)");
                /* for each 2d vert a 3d vector is allocated, so that they can be treated just as if they were 3d verts */
        t->data2d= MEM_callocN(t->total*sizeof(TransData2D), "TransData2D (Graph Editor)");
-
+       
        td= t->data;
        td2d= t->data2d;
-
+       
        /* loop 2: build transdata arrays */
        for (ale= anim_data.first; ale; ale= ale->next) {
                AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
                FCurve *fcu= (FCurve *)ale->key_data;
                short intvals= (fcu->flag & FCURVE_INT_VALUES);
-
+               
                /* convert current-frame to action-time (slightly less accurate, espcially under
                 * higher scaling ratios, but is faster than converting all points)
                 */
@@ -3415,16 +3414,16 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                        cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
                else
                        cfra = (float)CFRA;
-
+               
                /* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse (if applicable) */
                bezt= fcu->bezt;
                prevbezt= NULL;
-
+               
                for (i=0; i < fcu->totvert; i++, prevbezt=bezt, bezt++) {
                        if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
                                TransDataCurveHandleFlags *hdata = NULL;
                                short h1=1, h2=1;
-
+                               
                                /* only include handles if selected, and interpolaton mode uses beztriples */
                                if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) {
                                        if (bezt->f1 & SELECT) {
@@ -3443,7 +3442,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                                        else
                                                h2= 0;
                                }
-
+                               
                                /* only include main vert if selected */
                                if (bezt->f2 & SELECT) {
                                        /* if scaling around individuals centers, do no include keyframes */
@@ -3453,10 +3452,10 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                                                        if (hdata == NULL)
                                                                hdata = initTransDataCurveHandes(td, bezt);
                                                }
-
+                                               
                                                bezt_to_transdata(td++, td2d++, adt, bezt->vec[1], bezt->vec[1], 1, 0, intvals);
                                        }
-
+                                       
                                        /* special hack (must be done after initTransDataCurveHandes(), as that stores handle settings to restore...):
                                         *      - Check if we've got entire BezTriple selected and we're scaling/rotating that point,
                                         *        then check if we're using auto-handles.
@@ -3471,11 +3470,11 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                                }
                        }
                }
-
+               
                /* Sets handles based on the selection */
                testhandles_fcurve(fcu);
        }
-
+       
        /* cleanup temp list */
        BLI_freelistN(&anim_data);
 }
@@ -3502,19 +3501,19 @@ static BeztMap *bezt_to_beztmaps (BezTriple *bezts, int totvert)
        BezTriple *prevbezt= NULL;
        BeztMap *bezm, *bezms;
        int i;
-
+       
        /* allocate memory for this array */
        if (totvert==0 || bezts==NULL)
                return NULL;
        bezm= bezms= MEM_callocN(sizeof(BeztMap)*totvert, "BeztMaps");
-
+       
        /* assign beztriples to beztmaps */
        for (i=0; i < totvert; i++, bezm++, prevbezt=bezt, bezt++) {
                bezm->bezt= bezt;
-
+               
                bezm->oldIndex= i;
                bezm->newIndex= i;
-
+               
                bezm->pipo= (prevbezt) ? prevbezt->ipo : bezt->ipo;
                bezm->cipo= bezt->ipo;
        }
@@ -3527,11 +3526,11 @@ static void sort_time_beztmaps (BeztMap *bezms, int totvert)
 {
        BeztMap *bezm;
        int i, ok= 1;
-
+       
        /* keep repeating the process until nothing is out of place anymore */
        while (ok) {
                ok= 0;
-
+               
                bezm= bezms;
                i= totvert;
                while (i--) {
@@ -3540,13 +3539,13 @@ static void sort_time_beztmaps (BeztMap *bezms, int totvert)
                                if (bezm->bezt->vec[1][0] > (bezm+1)->bezt->vec[1][0]) {
                                        bezm->newIndex++;
                                        (bezm+1)->newIndex--;
-
+                                       
                                        SWAP(BeztMap, *bezm, *(bezm+1));
-
+                                       
                                        ok= 1;
                                }
                        }
-
+                       
                        /* do we need to check if the handles need to be swapped?
                         * optimisation: this only needs to be performed in the first loop
                         */
@@ -3562,7 +3561,7 @@ static void sort_time_beztmaps (BeztMap *bezms, int totvert)
                                        bezm->swapHs = -1;
                                }
                        }
-
+                       
                        bezm++;
                }
        }
@@ -3576,13 +3575,13 @@ static void beztmap_to_data (TransInfo *t, FCurve *fcu, BeztMap *bezms, int totv
        TransData2D *td;
        int i, j;
        char *adjusted;
-
+       
        /* dynamically allocate an array of chars to mark whether an TransData's
         * pointers have been fixed already, so that we don't override ones that are
         * already done
         */
        adjusted= MEM_callocN(t->total, "beztmap_adjusted_map");
-
+       
        /* for each beztmap item, find if it is used anywhere */
        bezm= bezms;
        for (i= 0; i < totvert; i++, bezm++) {
@@ -3593,7 +3592,7 @@ static void beztmap_to_data (TransInfo *t, FCurve *fcu, BeztMap *bezms, int totv
                for (j= 0; j < t->total; j++, td++) {
                        /* skip item if already marked */
                        if (adjusted[j] != 0) continue;
-
+                       
                        /* only selected verts */
                        if (bezm->pipo == BEZT_IPO_BEZ) {
                                if (bezm->bezt->f1 & SELECT) {
@@ -3624,9 +3623,9 @@ static void beztmap_to_data (TransInfo *t, FCurve *fcu, BeztMap *bezms, int totv
                                }
                        }
                }
-
+               
        }
-
+       
        /* free temp memory used for 'adjusted' array */
        MEM_freeN(adjusted);
 }
@@ -3641,25 +3640,25 @@ static void beztmap_to_data (TransInfo *t, FCurve *fcu, BeztMap *bezms, int totv
 void remake_graph_transdata (TransInfo *t, ListBase *anim_data)
 {
        bAnimListElem *ale;
-
+       
        /* sort and reassign verts */
        for (ale= anim_data->first; ale; ale= ale->next) {
                FCurve *fcu= (FCurve *)ale->key_data;
-
+               
                if (fcu->bezt) {
                        BeztMap *bezm;
-
+                       
                        /* adjust transform-data pointers */
                        bezm= bezt_to_beztmaps(fcu->bezt, fcu->totvert);
                        sort_time_beztmaps(bezm, fcu->totvert);
                        beztmap_to_data(t, fcu, bezm, fcu->totvert);
-
+                       
                        /* free mapping stuff */
                        MEM_freeN(bezm);
-
+                       
                        /* re-sort actual beztriples (perhaps this could be done using the beztmaps to save time?) */
                        sort_time_fcurve(fcu);
-
+                       
                        /* make sure handles are all set correctly */
                        testhandles_fcurve(fcu);
                }
@@ -3677,11 +3676,11 @@ void flushTransGraphData(TransInfo *t)
        Scene *scene= t->scene;
        double secf= FPS;
        int a;
-
+       
        /* flush to 2d vector from internally used 3d vector */
        for (a=0, td= t->data, td2d=t->data2d; a<t->total; a++, td++, td2d++) {
                AnimData *adt= (AnimData *)td->extra; /* pointers to relevant AnimData blocks are stored in the td->extra pointers */
-
+               
                /* handle snapping for time values
                 *      - we should still be in NLA-mapping timespace
                 *      - only apply to keyframes (but never to handles)
@@ -3694,19 +3693,19 @@ void flushTransGraphData(TransInfo *t)
                                        else
                                                td2d->loc[0]= (float)( floor(td2d->loc[0]+0.5f) );
                                        break;
-
+                               
                                case SACTSNAP_MARKER: /* snap to nearest marker */
                                        td2d->loc[0]= (float)ED_markers_find_nearest_marker_time(&t->scene->markers, td2d->loc[0]);
                                        break;
                        }
                }
-
-               /* we need to unapply the nla-scaling from the time in some situations */
+               
+               /* we need to unapply the nla-mapping from the time in some situations */
                if (adt)
                        td2d->loc2d[0]= BKE_nla_tweakedit_remap(adt, td2d->loc[0], NLATIME_CONVERT_UNMAP);
                else
                        td2d->loc2d[0]= td2d->loc[0];
-
+               
                /* if int-values only, truncate to integers */
                if (td->flag & TD_INTVALUES)
                        td2d->loc2d[1]= (float)((int)td2d->loc[1]);
@@ -4312,21 +4311,6 @@ static void clear_trans_object_base_flags(TransInfo *t)
        }
 }
 
-/* auto-keyframing feature - checks for whether anything should be done for the current frame */
-// TODO: this should probably be done per channel instead...
-short autokeyframe_cfra_can_key(Scene *scene, Object *ob)
-{
-       float cfra= (float)CFRA; // XXX for now, this will do
-
-       /* only filter if auto-key mode requires this */
-       if (IS_AUTOKEY_ON(scene) == 0)
-               return 0;
-       else if (IS_AUTOKEY_MODE(scene, NORMAL))
-               return 1;
-       else
-               return id_frame_has_keyframe(&ob->id, cfra, ANIMFILTER_KEYS_LOCAL);
-}
-
 /* auto-keyframing feature - for objects
  *     tmode: should be a transform mode
  */
@@ -4335,7 +4319,8 @@ void autokeyframe_ob_cb_func(Scene *scene, View3D *v3d, Object *ob, int tmode)
        ID *id= &ob->id;
        FCurve *fcu;
 
-       if (autokeyframe_cfra_can_key(scene, ob)) {
+       // TODO: this should probably be done per channel instead...
+       if (autokeyframe_cfra_can_key(scene, id)) {
                AnimData *adt= ob->adt;
                float cfra= (float)CFRA; // xxx this will do for now
                short flag = 0;
@@ -4436,7 +4421,8 @@ void autokeyframe_pose_cb_func(Scene *scene, View3D *v3d, Object *ob, int tmode,
        bPoseChannel *pchan;
        FCurve *fcu;
 
-       if (autokeyframe_cfra_can_key(scene, ob)) {
+       // TODO: this should probably be done per channel instead...
+       if (autokeyframe_cfra_can_key(scene, id)) {
                float cfra= (float)CFRA;
                short flag= 0;
                char buf[512];
@@ -4657,34 +4643,34 @@ void special_aftertrans_update(TransInfo *t)
                SpaceAction *saction= (SpaceAction *)t->sa->spacedata.first;
                Scene *scene;
                bAnimContext ac;
-
+               
                /* initialise relevant anim-context 'context' data from TransInfo data */
                        /* NOTE: sync this with the code in ANIM_animdata_get_context() */
                memset(&ac, 0, sizeof(bAnimContext));
-
+               
                scene= ac.scene= t->scene;
                ob= ac.obact= OBACT;
                ac.sa= t->sa;
                ac.ar= t->ar;
                ac.spacetype= (t->sa)? t->sa->spacetype : 0;
                ac.regiontype= (t->ar)? t->ar->regiontype : 0;
-
+               
                if (ANIM_animdata_context_getdata(&ac) == 0)
                        return;
-
+               
                if (ac.datatype == ANIMCONT_DOPESHEET) {
                        ListBase anim_data = {NULL, NULL};
                        bAnimListElem *ale;
                        short filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
-
+                       
                        /* get channels to work on */
                        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
+                       
                        /* these should all be ipo-blocks */
                        for (ale= anim_data.first; ale; ale= ale->next) {
                                AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
                                FCurve *fcu= (FCurve *)ale->key_data;
-
+                               
                                if ( (saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
                                     ((cancelled == 0) || (duplicate)) )
                                {
@@ -4697,7 +4683,7 @@ void special_aftertrans_update(TransInfo *t)
                                                posttrans_fcurve_clean(fcu);
                                }
                        }
-
+                       
                        /* free temp memory */
                        BLI_freelistN(&anim_data);
                }
@@ -4706,13 +4692,13 @@ void special_aftertrans_update(TransInfo *t)
                        // fixme... some of this stuff is not good
                        if (ob) {
                                ob->ctime= -1234567.0f;
-
+                               
                                if (ob->pose || ob_get_key(ob))
                                        DAG_object_flush_update(scene, ob, OB_RECALC);
                                else
                                        DAG_object_flush_update(scene, ob, OB_RECALC_OB);
                        }
-
+                       
                        /* Do curve cleanups? */
                        if ( (saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
                             ((cancelled == 0) || (duplicate)) )
@@ -4724,7 +4710,7 @@ void special_aftertrans_update(TransInfo *t)
 #if 0 // XXX old animation system
                        /* fix up the Ipocurves and redraw stuff */
                        Key *key= (Key *)ac.data;
-
+                       
                        if (key->ipo) {
                                if ( (saction->flag & SACTION_NOTRANSKEYCULL)==0 &&
                                     ((cancelled == 0) || (duplicate)) )
@@ -4733,7 +4719,7 @@ void special_aftertrans_update(TransInfo *t)
                                }
                        }
 #endif // XXX old animation system
-
+                       
                        DAG_object_flush_update(scene, OBACT, OB_RECALC_DATA);
                }
 #if 0 // XXX future of this is still not clear
@@ -4743,23 +4729,23 @@ void special_aftertrans_update(TransInfo *t)
                        {
                                bScreen *sc= (bScreen *)ac.data;
                                ScrArea *sa;
-
+                               
                                /* BAD... we need to loop over all screen areas for current screen...
                                 *      - sync this with actdata_filter_gpencil() in editaction.c
                                 */
                                for (sa= sc->areabase.first; sa; sa= sa->next) {
                                        bGPdata *gpd= gpencil_data_getactive(sa);
-
+                                       
                                        if (gpd)
                                                posttrans_gpd_clean(gpd);
                                }
                        }
                }
 #endif // XXX future of this is still not clear
-
+               
                /* make sure all F-Curves are set correctly */
                ANIM_editkeyframes_refresh(&ac);
-
+               
                /* clear flag that was set for time-slide drawing */
                saction->flag &= ~SACTION_MOVING;
        }
@@ -4767,35 +4753,34 @@ void special_aftertrans_update(TransInfo *t)
                SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
                Scene *scene;
                bAnimContext ac;
-
+               
                /* initialise relevant anim-context 'context' data from TransInfo data */
                        /* NOTE: sync this with the code in ANIM_animdata_get_context() */
                memset(&ac, 0, sizeof(bAnimContext));
-
+               
                scene= ac.scene= t->scene;
                ob= ac.obact= OBACT;
                ac.sa= t->sa;
                ac.ar= t->ar;
                ac.spacetype= (t->sa)? t->sa->spacetype : 0;
                ac.regiontype= (t->ar)? t->ar->regiontype : 0;
-
+               
                if (ANIM_animdata_context_getdata(&ac) == 0)
                        return;
-
+               
                if (ac.datatype)
                {
                        ListBase anim_data = {NULL, NULL};
                        bAnimListElem *ale;
                        short filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY | ANIMFILTER_CURVEVISIBLE);
-
+                       
                        /* get channels to work on */
                        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
-                       /* these should all be ipo-blocks */
+                       
                        for (ale= anim_data.first; ale; ale= ale->next) {
                                AnimData *adt= ANIM_nla_mapping_get(&ac, ale);
                                FCurve *fcu= (FCurve *)ale->key_data;
-
+                               
                                if ( (sipo->flag & SIPO_NOTRANSKEYCULL)==0 &&
                                     ((cancelled == 0) || (duplicate)) )
                                {
@@ -4808,58 +4793,57 @@ void special_aftertrans_update(TransInfo *t)
                                                posttrans_fcurve_clean(fcu);
                                }
                        }
-
+                       
                        /* free temp memory */
                        BLI_freelistN(&anim_data);
                }
-
+               
                /* make sure all F-Curves are set correctly */
                ANIM_editkeyframes_refresh(&ac);
        }
        else if (t->spacetype == SPACE_NLA) {
                Scene *scene;
                bAnimContext ac;
-
+               
                /* initialise relevant anim-context 'context' data from TransInfo data */
                /* NOTE: sync this with the code in ANIM_animdata_get_context() */
                memset(&ac, 0, sizeof(bAnimContext));
-
+               
                scene= ac.scene= t->scene;
                ob= ac.obact= OBACT;
                ac.sa= t->sa;
                ac.ar= t->ar;
                ac.spacetype= (t->sa)? t->sa->spacetype : 0;
                ac.regiontype= (t->ar)? t->ar->regiontype : 0;
-
+               
                if (ANIM_animdata_context_getdata(&ac) == 0)
                        return;
-
+                       
                if (ac.datatype)
                {
                        ListBase anim_data = {NULL, NULL};
                        bAnimListElem *ale;
                        short filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_NLATRACKS);
-
+                       
                        /* get channels to work on */
                        ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
-
+                       
                        for (ale= anim_data.first; ale; ale= ale->next) {
                                NlaTrack *nlt= (NlaTrack *)ale->data;
-
+                               
                                /* make sure strips are in order again */
                                BKE_nlatrack_sort_strips(nlt);
-
+                               
                                /* remove the temp metas */
                                BKE_nlastrips_clear_metas(&nlt->strips, 0, 1);
                        }
-
+                       
                        /* free temp memory */
                        BLI_freelistN(&anim_data);
+                       
+                       /* perform after-transfrom validation */
+                       ED_nla_postop_refresh(&ac);
                }
-
-               // XXX check on the calls below... we need some of these sanity checks
-               //synchronize_action_strips();
-               //ANIM_editkeyframes_refresh(&ac);
        }
        else if (t->obedit) {
                // TRANSFORM_FIX_ME
@@ -4914,7 +4898,7 @@ void special_aftertrans_update(TransInfo *t)
                //      allqueue(REDRAWBUTSEDIT, 0);
 
        }
-       else if(G.f & G_PARTICLEEDIT) {
+       else if(t->scene->basact && (ob = t->scene->basact->object) && ob->mode & OB_MODE_PARTICLE_EDIT) {
                ;
        }
        else {
@@ -4973,9 +4957,9 @@ static void createTransObject(bContext *C, TransInfo *t)
        set_trans_object_base_flags(C, t);
 
        /* count */
+#if 0 // TRANSFORM_FIX_ME
        CTX_DATA_BEGIN(C, Object*, ob, selected_objects)
        {
-#if 0 // TRANSFORM_FIX_ME
                /* store ipo keys? */
                if ((ob->id.lib == 0) && (ob->ipo) && (ob->ipo->showkey) && (ob->ipoflag & OB_DRAWKEY)) {
                        elems.first= elems.last= NULL;
@@ -4989,12 +4973,14 @@ static void createTransObject(bContext *C, TransInfo *t)
                        if(elems.first==NULL)
                                t->total++;
                }
-#endif
 //             else {
                        t->total++;
 //             }
        }
        CTX_DATA_END;
+#else
+       t->total= CTX_DATA_COUNT(C, selected_objects);
+#endif
 
        if(!t->total) {
                /* clear here, main transform function escapes too */
@@ -5248,18 +5234,18 @@ void createTransData(bContext *C, TransInfo *t)
                        t->poseobj = ob;        /* <- tsk tsk, this is going to give issues one day */
                }
        }
-       else if (ob && (ob->flag & OB_POSEMODE)) {
+       else if (ob && (ob->mode & OB_MODE_POSE)) {
                // XXX this is currently limited to active armature only...
                // XXX active-layer checking isn't done as that should probably be checked through context instead
                createTransPose(C, t, ob);
        }
-       else if (G.f & G_WEIGHTPAINT) {
+       else if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) {
                /* exception, we look for the one selected armature */
                CTX_DATA_BEGIN(C, Object*, ob_armature, selected_objects)
                {
                        if(ob_armature->type==OB_ARMATURE)
                        {
-                               if(ob_armature->flag & OB_POSEMODE)
+                               if(ob_armature->mode & OB_MODE_POSE)
                                {
                                        createTransPose(C, t, ob_armature);
                                        break;
@@ -5268,7 +5254,7 @@ void createTransData(bContext *C, TransInfo *t)
                }
                CTX_DATA_END;
        }
-       else if (G.f & G_PARTICLEEDIT && PE_can_edit(PE_get_current(scene, ob))) {
+       else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT) && PE_can_edit(PE_get_current(scene, ob))) {
                createTransParticleVerts(C, t);
 
                if(t->data && t->flag & T_PROP_EDIT) {