~ubuntu-branches/ubuntu/intrepid/blender/intrepid-updates

« back to all changes in this revision

Viewing changes to source/blender/src/editipo.c

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2008-08-08 02:45:40 UTC
  • mfrom: (12.1.14 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080808024540-kkjp7ekfivzhuw3l
Tags: 2.46+dfsg-4
* Fix python syntax warning in import_dxf.py, which led to nasty output
  in installation/upgrade logs during byte-compilation, using a patch
  provided by the script author (Closes: #492280):
   - debian/patches/45_fix_python_syntax_warning

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
 * $Id: editipo.c,v 1.101 2006/06/26 11:01:09 ton Exp $
 
2
 * $Id: editipo.c 14813 2008-05-12 17:16:54Z schlaile $
3
3
 *
4
4
 * ***** BEGIN GPL LICENSE BLOCK *****
5
5
 *
20
20
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21
21
 * All rights reserved.
22
22
 *
23
 
 * Contributor(s): Blender Foundation, 2005. Full recode
 
23
 * Contributor(s): Blender Foundation, 2005. Full recode.
 
24
 * Roland Hess, 2007. Visual Key refactor.
24
25
 *
25
26
 * ***** END GPL LICENSE BLOCK *****
26
27
 */
61
62
#include "DNA_material_types.h"
62
63
#include "DNA_object_types.h"
63
64
#include "DNA_object_fluidsim.h"
 
65
#include "DNA_particle_types.h"
64
66
#include "DNA_screen_types.h"
65
67
#include "DNA_scene_types.h"
66
68
#include "DNA_space_types.h"
72
74
#include "DNA_world_types.h"
73
75
 
74
76
#include "BKE_action.h"
 
77
#include "BKE_armature.h"
75
78
#include "BKE_anim.h"
76
79
#include "BKE_constraint.h"
77
80
#include "BKE_depsgraph.h"
80
83
#include "BKE_ipo.h"
81
84
#include "BKE_key.h"
82
85
#include "BKE_material.h"
 
86
#include "BKE_particle.h"
83
87
#include "BKE_texture.h"
84
88
#include "BKE_utildefines.h"
 
89
#include "BKE_object.h"
85
90
 
86
91
#include "BIF_butspace.h"
87
92
#include "BIF_editaction.h"
100
105
 
101
106
#include "BDR_drawobject.h"
102
107
#include "BDR_editobject.h"
 
108
#include "BDR_editcurve.h"      // for bezt_compare 
103
109
 
104
110
#include "BSE_trans_types.h"
105
111
#include "BSE_editipo_types.h"
109
115
#include "BSE_drawview.h"
110
116
#include "BSE_headerbuttons.h"
111
117
#include "BSE_node.h"
 
118
#include "BSE_sequence.h"
 
119
#include "BSE_seqaudio.h"
 
120
#include "BSE_time.h"
112
121
 
113
122
#include "blendef.h"
114
123
#include "mydevice.h"
 
124
#include "transform.h"
115
125
 
116
126
extern int ob_ar[];
117
127
extern int ma_ar[];
125
135
extern int co_ar[];
126
136
extern int te_ar[];
127
137
extern int fluidsim_ar[]; // NT
 
138
extern int part_ar[];
128
139
 
129
140
/* forwards */
130
 
#define BEZSELECTED(bezt)   (((bezt)->f1 & 1) || ((bezt)->f2 & 1) || ((bezt)->f3 & 1))
131
 
 
132
141
#define IPOTHRESH       0.9
133
 
#define ISPOIN(a, b, c)                       ( (a->b) && (a->c) )
134
 
#define ISPOIN3(a, b, c, d)           ( (a->b) && (a->c) && (a->d) )
135
142
 
136
143
/* tests if only one editipo is active */
137
144
static void check_active_editipo(void)
247
254
                        
248
255
                        if(ei->flag & IPO_VISIBLE) {
249
256
                
250
 
                                boundbox_ipocurve(ei->icu);
 
257
                                boundbox_ipocurve(ei->icu, 0);
251
258
                                sort_time_ipocurve(ei->icu);
252
259
                                if(first) {
253
260
                                        si->v2d.tot= ei->icu->totrct;
324
331
                        allqueue(REDRAWBUTSEDIT, 0);
325
332
                        allqueue(REDRAWVIEW3D, 0);
326
333
                }
327
 
                else if(si->blocktype==ID_SEQ) clear_seq_belonging_to_ipo(si->ipo);
 
334
                else if(si->blocktype==ID_SEQ) free_imbuf_seq_with_ipo(si->ipo);
328
335
                else if(si->blocktype==ID_PO) {
329
336
                        Object *ob= OBACT;
330
337
                        if(ob && ob->pose) {
342
349
                        DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
343
350
                        allqueue(REDRAWVIEW3D, 0);
344
351
                }
 
352
                else if(si->blocktype==ID_PA){
 
353
                        DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
 
354
                        allqueue(REDRAWVIEW3D, 0);
 
355
                }
345
356
        }
346
357
 
347
358
        if(si->showkey) make_ipokey();
434
445
        //fprintf(stderr,"FSIMAKE_OPBJ call %d \n", si->totipo);
435
446
}
436
447
 
 
448
static void make_part_editipo(SpaceIpo *si)
 
449
{
 
450
        EditIpo *ei;
 
451
        int a;
 
452
        char *name;
 
453
        
 
454
        if(si->from==0) return;
 
455
        
 
456
        ei= si->editipo= MEM_callocN(PART_TOTIPO*sizeof(EditIpo), "editipo");
 
457
        
 
458
        si->totipo= PART_TOTIPO;
 
459
        
 
460
        for(a=0; a<PART_TOTIPO; a++) {
 
461
                name = getname_part_ei(part_ar[a]);
 
462
                strcpy(ei->name, name);
 
463
                ei->adrcode= part_ar[a];
 
464
                
 
465
                //if(ei->adrcode & MA_MAP1) {
 
466
                //      ei->adrcode-= MA_MAP1;
 
467
                //      ei->adrcode |= texchannel_to_adrcode(si->channel);
 
468
                //}
 
469
                //else {
 
470
                //      if(ei->adrcode==MA_MODE) ei->disptype= IPO_DISPBITS;
 
471
                //}
 
472
                
 
473
                ei->col= ipo_rainbow(a, PART_TOTIPO);
 
474
                
 
475
                //len= strlen(ei->name);
 
476
                //if(len) {
 
477
                //      if( ei->name[ len-1 ]=='R') ei->col= 0x5050FF;
 
478
                //      else if( ei->name[ len-1 ]=='G') ei->col= 0x50FF50;
 
479
                //      else if( ei->name[ len-1 ]=='B') ei->col= 0xFF7050;
 
480
                //}
 
481
                
 
482
                ei->icu= find_ipocurve(si->ipo, ei->adrcode);
 
483
                if(ei->icu) {
 
484
                        ei->flag= ei->icu->flag;
 
485
                }
 
486
                
 
487
                ei++;
 
488
        }
 
489
}
 
490
 
437
491
// copied from make_seq_editipo
438
492
static void make_fluidsim_editipo(SpaceIpo *si) // NT
439
493
{
911
965
                        make_fluidsim_editipo(G.sipo);
912
966
                }
913
967
        }
 
968
        else if(G.sipo->blocktype==ID_PA) {
 
969
                if (ob) {
 
970
                        ob->ipowin= ID_PA;
 
971
                        make_part_editipo(G.sipo);
 
972
                }
 
973
        }
914
974
 
915
975
        if(G.sipo->editipo==0) return;
916
976
        
920
980
        }
921
981
        editipo_changed(G.sipo, 0);
922
982
        
923
 
        if(G.sipo->ipo) {
924
 
 
925
 
                if (G.sipo->pin)
926
 
                        rf= &(G.sipo->v2d.cur);
927
 
                else
928
 
                        rf= &(G.sipo->ipo->cur);
929
 
                
930
 
                if(rf->xmin<rf->xmax && rf->ymin<rf->ymax) G.v2d->cur= *rf;
931
 
                else ipo_default_v2d_cur(G.sipo->blocktype, &G.v2d->cur);
932
 
        }
933
 
        else {
934
 
                ipo_default_v2d_cur(G.sipo->blocktype, &G.v2d->cur);
935
 
        }
936
 
        
 
983
        /* sets globals, bad stuff but we need these variables in other parts of code */
 
984
        get_status_editipo();
 
985
        
 
986
        
 
987
        if (G.sipo->flag & SIPO_LOCK_VIEW) {
 
988
                rf= &(G.v2d->cur); /* view is locked, dont move it, just to sanity check */
 
989
                if(rf->xmin>=rf->xmax || rf->ymin>=rf->ymax) ipo_default_v2d_cur(G.sipo->blocktype, &G.v2d->cur);
 
990
        } else {
 
991
                if(G.sipo->ipo) {
 
992
                        if (G.sipo->pin)
 
993
                                rf= &(G.sipo->v2d.cur);
 
994
                        else
 
995
                                rf= &(G.sipo->ipo->cur);
 
996
                        
 
997
                        if(rf->xmin<rf->xmax && rf->ymin<rf->ymax) G.v2d->cur= *rf;
 
998
                        else ipo_default_v2d_cur(G.sipo->blocktype, &G.v2d->cur);
 
999
                }
 
1000
                else {
 
1001
                        ipo_default_v2d_cur(G.sipo->blocktype, &G.v2d->cur);
 
1002
                }
 
1003
        }
937
1004
        view2d_do_locks(curarea, V2D_LOCK_COPY);
938
1005
}
939
1006
 
940
1007
/* evaluates context in the current UI */
941
1008
/* blocktype is type of ipo */
942
1009
/* from is the base pointer to find data to change (ob in case of action or pose) */
943
 
static void get_ipo_context(short blocktype, ID **from, Ipo **ipo, char *actname, char *constname)
 
1010
/* bonename is for local bone ipos (constraint only now) */
 
1011
static void get_ipo_context(short blocktype, ID **from, Ipo **ipo, char *actname, char *constname, char *bonename)
944
1012
{
945
1013
        Object *ob= OBACT;
946
1014
        
953
1021
                        bConstraint *con= get_active_constraint(ob);
954
1022
                        
955
1023
                        if(con) {
 
1024
                                *from= &ob->id;
 
1025
                                
956
1026
                                BLI_strncpy(constname, con->name, 32);
957
1027
                                
958
 
                                chan= get_active_constraint_channel(ob);
959
 
                                if(chan) {
960
 
                                        *ipo= chan->ipo;
961
 
                                        BLI_strncpy(constname, con->name, 32);
962
 
                                }
963
 
                                
964
 
                                *from= &ob->id;
965
 
                                
966
 
                                /* set actname if in posemode */
967
 
                                if(ob->action) {
 
1028
                                /* a bit hackish, but we want con->ipo to work */
 
1029
                                if(con->flag & CONSTRAINT_OWN_IPO) {
968
1030
                                        if(ob->flag & OB_POSEMODE) {
969
1031
                                                bPoseChannel *pchan= get_active_posechannel(ob);
970
 
                                                if(pchan)
971
 
                                                        BLI_strncpy(actname, pchan->name, 32);
972
 
                                        }
973
 
                                        else if(ob->ipoflag & OB_ACTION_OB)
974
 
                                                strcpy(actname, "Object");
 
1032
                                                if(pchan) {
 
1033
                                                        BLI_strncpy(bonename, pchan->name, 32);
 
1034
                                                        *ipo= con->ipo;
 
1035
                                                }
 
1036
                                        }
 
1037
                                }
 
1038
                                else {
 
1039
                                        chan= get_active_constraint_channel(ob);
 
1040
                                        if(chan) {
 
1041
                                                *ipo= chan->ipo;
 
1042
                                                BLI_strncpy(constname, con->name, 32);
 
1043
                                        }
 
1044
                                        
 
1045
                                        /* set actname if in posemode */
 
1046
                                        if (ob->action) {
 
1047
                                                if (ob->flag & OB_POSEMODE) {
 
1048
                                                        bPoseChannel *pchan= get_active_posechannel(ob);
 
1049
                                                        if (pchan) {
 
1050
                                                                BLI_strncpy(actname, pchan->name, 32);
 
1051
                                                                BLI_strncpy(bonename, pchan->name, 32);
 
1052
                                                        }
 
1053
                                                }
 
1054
                                                else if (ob->ipoflag & OB_ACTION_OB)
 
1055
                                                        strcpy(actname, "Object");
 
1056
                                        }
 
1057
                                        else {
 
1058
                                                if (ob->flag & OB_POSEMODE) {
 
1059
                                                        bPoseChannel *pchan= get_active_posechannel(ob);
 
1060
                                                        if (pchan) {
 
1061
                                                                BLI_strncpy(actname, pchan->name, 32);
 
1062
                                                                BLI_strncpy(bonename, pchan->name, 32);
 
1063
                                                        }
 
1064
                                                }
 
1065
                                        }
975
1066
                                }
976
1067
                        }
977
1068
                }
1013
1104
        else if(blocktype==ID_SEQ) {
1014
1105
                Sequence *last_seq = get_last_seq();
1015
1106
                
1016
 
                if(last_seq && ((last_seq->type & SEQ_EFFECT)||(last_seq->type == SEQ_HD_SOUND)||(last_seq->type == SEQ_RAM_SOUND))) {
 
1107
                if(last_seq) {
1017
1108
                        *from= (ID *)last_seq;
1018
1109
                        *ipo= last_seq->ipo;
1019
1110
                }
1092
1183
                        if(fss) *ipo= fss->ipo;
1093
1184
                }
1094
1185
        }
 
1186
        else if(blocktype==ID_PA) {
 
1187
                ParticleSystem *psys = psys_get_current(ob);
 
1188
                if(psys){
 
1189
                        *from= (ID *)ob;
 
1190
                        *ipo= psys->part->ipo;
 
1191
                }
 
1192
        }
1095
1193
}
1096
1194
 
1097
1195
/* called on each redraw, check if editipo data has to be remade */
1102
1200
        if(G.sipo->pin==0) {
1103
1201
                Ipo *ipo;
1104
1202
                ID *from;
1105
 
                char actname[32]="", constname[32]="";
 
1203
                char actname[32]="", constname[32]="", bonename[32]="";
1106
1204
                
1107
 
                get_ipo_context(G.sipo->blocktype, &from, &ipo, actname, constname);
 
1205
                get_ipo_context(G.sipo->blocktype, &from, &ipo, actname, constname, bonename);
1108
1206
                
1109
1207
                if(G.sipo->ipo != ipo) {
1110
1208
                        G.sipo->ipo= ipo;
1111
 
                        if(ipo) G.v2d->cur= ipo->cur;
 
1209
                        /* if lock we don't copy from ipo, this makes the UI jump around confusingly */
 
1210
                        if(G.v2d->flag & V2D_VIEWLOCK || G.sipo->flag & SIPO_LOCK_VIEW);
 
1211
                        else if(ipo) G.v2d->cur= ipo->cur;
1112
1212
                        doit= 1;
1113
1213
                }
1114
1214
                if(G.sipo->from != from) {
1123
1223
                        BLI_strncpy(G.sipo->constname, constname, 32);
1124
1224
                        doit= 1;
1125
1225
                }
 
1226
                if( strcmp(G.sipo->bonename, bonename)) {
 
1227
                        BLI_strncpy(G.sipo->bonename, bonename, 32);
 
1228
                        /* urmf; if bonename, then no action */
 
1229
                        if(bonename[0]) G.sipo->actname[0]= 0;
 
1230
                        doit= 1;
 
1231
                }
1126
1232
                
1127
1233
                if(G.sipo->ipo)
1128
1234
                        G.sipo->ipo->cur = G.v2d->cur;
1136
1242
 
1137
1243
/* ****************** EditIpo ************************ */
1138
1244
 
1139
 
int totipo_edit, totipo_sel, totipo_curve, totipo_vis, totipo_vert, totipo_vertsel, totipo_key, totipo_keysel;
 
1245
int totipo_edit=0, totipo_sel=0, totipo_curve=0, totipo_vis=0, totipo_vert=0, totipo_vertsel=0, totipo_key=0, totipo_keysel=0;
1140
1246
 
1141
1247
void get_status_editipo(void)
1142
1248
{
1174
1280
                                                b= ei->icu->totvert;
1175
1281
                                                while(b--) {
1176
1282
                                                        if(ei->icu->ipo==IPO_BEZ) {
1177
 
                                                                if(bezt->f1 & 1) totipo_vertsel++;
1178
 
                                                                if(bezt->f3 & 1) totipo_vertsel++;
 
1283
                                                                if(bezt->f1 & SELECT) totipo_vertsel++;
 
1284
                                                                if(bezt->f3 & SELECT) totipo_vertsel++;
1179
1285
                                                                totipo_vert+= 2;
1180
1286
                                                        }
1181
 
                                                        if(bezt->f2 & 1) totipo_vertsel++;
 
1287
                                                        if(bezt->f2 & SELECT) totipo_vertsel++;
1182
1288
                                                        
1183
1289
                                                        totipo_vert++;
1184
1290
                                                        bezt++;
1219
1325
                        for(a=0; a<G.sipo->totipo; a++) {
1220
1326
                                if(ik->data[a]) {
1221
1327
                                        if(ik->flag & 1) {
1222
 
                                                ik->data[a]->f1 |= 1;
1223
 
                                                ik->data[a]->f2 |= 1;
1224
 
                                                ik->data[a]->f3 |= 1;
 
1328
                                                ik->data[a]->f1 |= SELECT;
 
1329
                                                ik->data[a]->f2 |= SELECT;
 
1330
                                                ik->data[a]->f3 |= SELECT;
1225
1331
                                        }
1226
1332
                                        else {
1227
 
                                                ik->data[a]->f1 &= ~1;
1228
 
                                                ik->data[a]->f2 &= ~1;
1229
 
                                                ik->data[a]->f3 &= ~1;
 
1333
                                                ik->data[a]->f1 &= ~SELECT;
 
1334
                                                ik->data[a]->f2 &= ~SELECT;
 
1335
                                                ik->data[a]->f3 &= ~SELECT;
1230
1336
                                        }
1231
1337
                                }
1232
1338
                        }
1313
1419
                                        }
1314
1420
                                        else temp= abs(mval[0]- sco[1][0])+ abs(mval[1]- sco[1][1]);
1315
1421
 
1316
 
                                        if( bezt1->f2 & 1) temp+=5;
 
1422
                                        if( bezt1->f2 & SELECT) temp+=5;
1317
1423
                                        if(temp<dist) { 
1318
1424
                                                hpoint= 1; 
1319
1425
                                                *bezt= bezt1; 
1358
1464
        IpoCurve *icu;
1359
1465
        IpoKey *ik, *actik;
1360
1466
        BezTriple *bezt;
 
1467
        TimeMarker *marker;
1361
1468
        float x, y, dist, mindist;
1362
1469
        int a, oldflag = 0, hand, ok;
1363
1470
        short mval[2], xo, yo;
1365
1472
        if(G.sipo->editipo==0) return;
1366
1473
        
1367
1474
        get_status_editipo();
 
1475
        marker=find_nearest_marker(SCE_MARKERS, 1);
 
1476
        
 
1477
        /* map ipo-points for editing if scaled ipo */
 
1478
        if (NLA_IPO_SCALED) {
 
1479
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 0, 0);
 
1480
        }
1368
1481
        
1369
1482
        if(G.sipo->showkey) {
 
1483
                float pixelwidth;
 
1484
                
 
1485
                view2d_getscale(G.v2d, &pixelwidth, NULL);
 
1486
                
1370
1487
                getmouseco_areawin(mval);
1371
 
                
1372
1488
                areamouseco_to_ipoco(G.v2d, mval, &x, &y);
1373
1489
                actik= 0;
1374
1490
                mindist= 1000.0;
1375
1491
                ik= G.sipo->ipokey.first;
1376
1492
                while(ik) {
1377
1493
                        dist= (float)(fabs(ik->val-x));
1378
 
                        if(ik->flag & 1) dist+= 1.0;
 
1494
                        if(ik->flag & SELECT) dist+= pixelwidth;
1379
1495
                        if(dist < mindist) {
1380
1496
                                actik= ik;
1381
1497
                                mindist= dist;
1408
1524
                                                bezt->f1= bezt->f2= bezt->f3= 0;
1409
1525
                                        }
1410
1526
                                        else {
1411
 
                                                bezt->f1= bezt->f2= bezt->f3= 1;
 
1527
                                                bezt->f1= bezt->f2= bezt->f3= SELECT;
1412
1528
                                        }
1413
1529
                                }
1414
1530
                                else if(hand==0) {
1415
 
                                        if(bezt->f1 & 1) bezt->f1= 0;
1416
 
                                        else bezt->f1= 1;
 
1531
                                        if(bezt->f1 & SELECT) bezt->f1= 0;
 
1532
                                        else bezt->f1= SELECT;
1417
1533
                                }
1418
1534
                                else {
1419
 
                                        if(bezt->f3 & 1) bezt->f3= 0;
1420
 
                                        else bezt->f3= 1;
 
1535
                                        if(bezt->f3 & SELECT) bezt->f3= 0;
 
1536
                                        else bezt->f3= SELECT;
1421
1537
                                }
1422
1538
                        }                               
1423
1539
                }
1426
1542
                        
1427
1543
                        if(bezt) {
1428
1544
                                if(hand==1) {
1429
 
                                        bezt->f1|= 1; bezt->f2|= 1; bezt->f3|= 1;
 
1545
                                        bezt->f1|= SELECT; bezt->f2|= SELECT; bezt->f3|= SELECT;
1430
1546
                                }
1431
 
                                else if(hand==0) bezt->f1|= 1;
1432
 
                                else bezt->f3|= 1;
 
1547
                                else if(hand==0) bezt->f1 |= SELECT;
 
1548
                                else bezt->f3 |= SELECT;
1433
1549
                        }
1434
1550
                }
1435
1551
        }
 
1552
        else if (marker) {
 
1553
                /* select timeline marker */
 
1554
                if ((G.qual & LR_SHIFTKEY)==0) {
 
1555
                        oldflag= marker->flag;
 
1556
                        deselect_markers(0, 0);
 
1557
                        
 
1558
                        if (oldflag & SELECT)
 
1559
                                marker->flag &= ~SELECT;
 
1560
                        else
 
1561
                                marker->flag |= SELECT;
 
1562
                }
 
1563
                else {
 
1564
                        marker->flag |= SELECT;                         
 
1565
                }               
 
1566
        }
1436
1567
        else {
1437
1568
                
1438
1569
                /* vertex keys ? */
1509
1640
                }
1510
1641
        }
1511
1642
        
 
1643
        /* undo mapping of ipo-points for editing if scaled ipo */
 
1644
        if (NLA_IPO_SCALED) {
 
1645
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 1, 0);
 
1646
        }
 
1647
        
1512
1648
        update_editipo_flags();
1513
1649
        
1514
1650
        force_draw(0);
1518
1654
                ob= OBACT;
1519
1655
                if(ob && (ob->ipoflag & OB_DRAWKEY)) allqueue(REDRAWVIEW3D, 0);
1520
1656
        }
 
1657
        /* points inside of curve are drawn selected too */
 
1658
        if(G.sipo->blocktype==ID_CU)
 
1659
                allqueue(REDRAWVIEW3D, 0);
1521
1660
        
1522
1661
        getmouseco_areawin(mval);
1523
1662
        xo= mval[0]; 
1524
1663
        yo= mval[1];
1525
1664
        
1526
 
        while(get_mbut()&R_MOUSE) {             
 
1665
        while (get_mbut() & ((U.flag & USER_LMOUSESELECT)?L_MOUSE:R_MOUSE)) {           
1527
1666
                getmouseco_areawin(mval);
1528
1667
                if(abs(mval[0]-xo)+abs(mval[1]-yo) > 4) {
1529
1668
                        
1530
 
                        if(actkb) move_keys(OBACT);
1531
 
                        else transform_ipo('g');
 
1669
                        if (marker) {
 
1670
                                transform_markers('g', 0);
 
1671
                        }
 
1672
                        else {
 
1673
                                if(actkb) move_keys(OBACT);
 
1674
                                else transform_ipo('g');
 
1675
                        }
1532
1676
                        
1533
1677
                        return;
1534
1678
                }
1593
1737
        getmouseco_areawin(mval);
1594
1738
 
1595
1739
        nr= -(mval[1]-curarea->winy+30-G.sipo->butofs-IPOBUTY)/IPOBUTY;
 
1740
        if(G.sipo->blocktype==ID_KE) nr--;              /* keys show something else in first channel */
 
1741
        
1596
1742
        if(nr>=0 && nr<G.sipo->totipo) {
1597
1743
                ei= G.sipo->editipo;
1598
1744
                ei+= nr;
1629
1775
 
1630
1776
/* ********************************* Inserting keys ********************************************* */
1631
1777
 
1632
 
/* depending type, it returns ipo, if neded it creates one */
 
1778
/* depending type, it returns ipo, if needed it creates one */
1633
1779
/* returns either action ipo or "real" ipo */
1634
1780
/* arguments define full context;
1635
1781
   - *from has to be set always, to Object in case of Actions
1636
1782
   - blocktype defines available channels of Ipo struct (blocktype ID_OB can be in action too)
1637
 
   - if actname, use this to locate action, and optional constname to find the channel 
 
1783
   - if actname, use this to locate actionchannel, and optional constname 
 
1784
   - if bonename, the constname is the ipo to the constraint
1638
1785
*/
1639
1786
 
1640
1787
/* note; check header_ipo.c, spaceipo_assign_ipo() too */
1641
 
Ipo *verify_ipo(ID *from, short blocktype, char *actname, char *constname)
 
1788
Ipo *verify_ipo(ID *from, short blocktype, char *actname, char *constname, char *bonename)
1642
1789
{
1643
1790
 
1644
1791
        if(from==NULL || from->lib) return NULL;
1654
1801
                }
1655
1802
                
1656
1803
                if(ob->action==NULL)
1657
 
                        ob->action= add_empty_action(blocktype);
 
1804
                        ob->action= add_empty_action("Action");
1658
1805
                
1659
1806
                achan= verify_action_channel(ob->action, actname);
1660
1807
                
1661
1808
                if(achan) {
 
1809
                        /* automatically assign achan to act-group based on pchan's grouping */
 
1810
                        if (blocktype == ID_PO)
 
1811
                                verify_pchan2achan_grouping(ob->action, ob->pose, actname);
 
1812
                        
1662
1813
                        /* constraint exception */
1663
1814
                        if(blocktype==ID_CO) {
1664
1815
                                bConstraintChannel *conchan= verify_constraint_channel(&achan->constraintChannels, constname);
1682
1833
                case ID_OB:
1683
1834
                        {
1684
1835
                                Object *ob= (Object *)from;
 
1836
                                
1685
1837
                                /* constraint exception */
1686
1838
                                if(blocktype==ID_CO) {
1687
 
                                        bConstraintChannel *conchan= verify_constraint_channel(&ob->constraintChannels, constname);
1688
 
                                        if(conchan->ipo==NULL) {
1689
 
                                                conchan->ipo= add_ipo("CoIpo", ID_CO);  
1690
 
                                        }
1691
 
                                        return conchan->ipo;
 
1839
                                        /* check the local constraint ipo */
 
1840
                                        if(bonename && bonename[0] && ob->pose) {
 
1841
                                                bPoseChannel *pchan= get_pose_channel(ob->pose, bonename);
 
1842
                                                bConstraint *con;
 
1843
                                                for(con= pchan->constraints.first; con; con= con->next)
 
1844
                                                        if(strcmp(con->name, constname)==0)
 
1845
                                                                break;
 
1846
                                                if(con) {
 
1847
                                                        if(con->ipo==NULL) {
 
1848
                                                                con->ipo= add_ipo("CoIpo", ID_CO);
 
1849
                                                        }
 
1850
                                                        return con->ipo;
 
1851
                                                }
 
1852
                                        }
 
1853
                                        else { /* the actionchannel */
 
1854
                                                bConstraintChannel *conchan= verify_constraint_channel(&ob->constraintChannels, constname);
 
1855
                                                if(conchan->ipo==NULL) {
 
1856
                                                        conchan->ipo= add_ipo("CoIpo", ID_CO);  
 
1857
                                                }
 
1858
                                                return conchan->ipo;
 
1859
                                        }
1692
1860
                                }
1693
1861
                                else if(blocktype==ID_OB) {
1694
1862
                                        if(ob->ipo==NULL) {
1718
1886
                                                return fss->ipo;
1719
1887
                                        }
1720
1888
                                }
 
1889
                                else if(blocktype== ID_PA){
 
1890
                                        Object *ob= (Object *)from;
 
1891
                                        ParticleSystem *psys= psys_get_current(ob);
 
1892
                                        if(psys){
 
1893
                                                if(psys->part->ipo==0)
 
1894
                                                        psys->part->ipo= add_ipo("ParticleIpo", ID_PA);
 
1895
                                                return psys->part->ipo;
 
1896
                                        }
 
1897
                                        return NULL;
 
1898
                                }
1721
1899
                        }
1722
1900
                        break;
1723
1901
                case ID_MA:
1744
1922
                        {
1745
1923
                                Sequence *seq= (Sequence *)from;        /* note, sequence is mimicing Id */
1746
1924
 
1747
 
                                if((seq->type & SEQ_EFFECT)||
1748
 
                                   (seq->type == SEQ_RAM_SOUND)||
1749
 
                                   (seq->type == SEQ_HD_SOUND)) {
1750
 
                                        if(seq->ipo==NULL) {
1751
 
                                                seq->ipo= add_ipo("SeqIpo", ID_SEQ);
1752
 
                                        }
1753
 
                                        update_seq_ipo_rect(seq);
1754
 
                                        return seq->ipo;
 
1925
                                if(seq->ipo==NULL) {
 
1926
                                        seq->ipo= add_ipo("SeqIpo", ID_SEQ);
1755
1927
                                }
 
1928
                                update_seq_ipo_rect(seq);
 
1929
                                return seq->ipo;
1756
1930
                        }
1757
1931
                        break;
1758
1932
                case ID_CU:
1810
1984
        return NULL;    
1811
1985
}
1812
1986
 
1813
 
/* returns and creates */
1814
 
IpoCurve *verify_ipocurve(ID *from, short blocktype, char *actname, char *constname, int adrcode)
 
1987
/* returns and creates
 
1988
 * Make sure functions check for NULL or they will crash!
 
1989
 *  */
 
1990
IpoCurve *verify_ipocurve(ID *from, short blocktype, char *actname, char *constname, char *bonename, int adrcode)
1815
1991
{
1816
1992
        Ipo *ipo;
1817
1993
        IpoCurve *icu= NULL;
1818
1994
        
1819
1995
        /* return 0 if lib */
1820
1996
        /* creates ipo too */
1821
 
        ipo= verify_ipo(from, blocktype, actname, constname);
 
1997
        ipo= verify_ipo(from, blocktype, actname, constname, bonename);
1822
1998
        
1823
 
        if(ipo && ipo->id.lib==NULL) {
 
1999
        if(ipo && ipo->id.lib==NULL && from->lib==NULL) {
1824
2000
                
1825
2001
                for(icu= ipo->curve.first; icu; icu= icu->next) {
1826
2002
                        if(icu->adrcode==adrcode) break;
1827
2003
                }
1828
2004
                if(icu==NULL) {
1829
2005
                        icu= MEM_callocN(sizeof(IpoCurve), "ipocurve");
1830
 
 
 
2006
                        
1831
2007
                        icu->flag |= IPO_VISIBLE|IPO_AUTO_HORIZ;
 
2008
                        if(ipo->curve.first==NULL) icu->flag |= IPO_ACTIVE;     /* first one added active */
 
2009
                        
1832
2010
                        icu->blocktype= blocktype;
1833
2011
                        icu->adrcode= adrcode;
1834
2012
                        
1835
2013
                        set_icu_vars(icu);
1836
2014
                        
1837
2015
                        BLI_addtail( &(ipo->curve), icu);
 
2016
                        
 
2017
                        switch (GS(from->name)) {
 
2018
                                case ID_SEQ: {
 
2019
                                        Sequence *seq= (Sequence *)from;
 
2020
                                        
 
2021
                                        update_seq_icu_rects(seq);
 
2022
                                        break;
 
2023
                                }
 
2024
                        }
1838
2025
                }
1839
2026
        }
1840
2027
 
1841
2028
        return icu;
1842
2029
}
1843
2030
 
1844
 
void insert_vert_ipo(IpoCurve *icu, float x, float y)
1845
 
{
1846
 
        BezTriple *bezt, beztr, *newbezt;
1847
 
        int a = 0, h1, h2;
1848
 
        
 
2031
 
 
2032
/* threshold for inserting keyframes - threshold here should be good enough for now, but should become userpref */
 
2033
#define BEZT_INSERT_THRESH      0.00001
 
2034
 
 
2035
/* Binary search algorithm for finding where to insert BezTriple. (for use by insert_bezt_icu)
 
2036
 * Returns the index to insert at (data already at that index will be offset if replace is 0)
 
2037
 */
 
2038
static int binarysearch_bezt_index (BezTriple array[], BezTriple *item, int arraylen, short *replace)
 
2039
{
 
2040
        int start=0, end=arraylen;
 
2041
        int loopbreaker= 0, maxloop= arraylen * 2;
 
2042
        const float frame= (item)? item->vec[1][0] : 0.0f;
 
2043
        
 
2044
        /* initialise replace-flag first */
 
2045
        *replace= 0;
 
2046
        
 
2047
        /* sneaky optimisations (don't go through searching process if...):
 
2048
         *      - keyframe to be added is to be added out of current bounds
 
2049
         *      - keyframe to be added would replace one of the existing ones on bounds
 
2050
         */
 
2051
        if ((arraylen <= 0) || ELEM(NULL, array, item)) {
 
2052
                printf("Warning: binarysearch_bezt_index encountered invalid array \n");
 
2053
                return 0;
 
2054
        }
 
2055
        else {
 
2056
                /* check whether to add before/after/on */
 
2057
                float framenum;
 
2058
                
 
2059
                /* 'First' Keyframe (when only one keyframe, this case is used) */
 
2060
                framenum= array[0].vec[1][0];
 
2061
                if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH)) {
 
2062
                        *replace = 1;
 
2063
                        return 0;
 
2064
                }
 
2065
                else if (frame < framenum)
 
2066
                        return 0;
 
2067
                        
 
2068
                /* 'Last' Keyframe */
 
2069
                framenum= array[(arraylen-1)].vec[1][0];
 
2070
                if (IS_EQT(frame, framenum, BEZT_INSERT_THRESH)) {
 
2071
                        *replace= 1;
 
2072
                        return (arraylen - 1);
 
2073
                }
 
2074
                else if (frame > framenum)
 
2075
                        return arraylen;
 
2076
        }
 
2077
        
 
2078
        
 
2079
        /* most of the time, this loop is just to find where to put it
 
2080
         * 'loopbreaker' is just here to prevent infinite loops 
 
2081
         */
 
2082
        for (loopbreaker=0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) {
 
2083
                /* compute and get midpoint */
 
2084
                int mid = (start + end) / 2;
 
2085
                float midfra= array[mid].vec[1][0];
 
2086
                
 
2087
                /* check if exactly equal to midpoint */
 
2088
                if (IS_EQT(frame, midfra, BEZT_INSERT_THRESH)) {
 
2089
                        *replace = 1;
 
2090
                        return mid;
 
2091
                }
 
2092
                
 
2093
                /* repeat in upper/lower half */
 
2094
                if (frame > midfra)
 
2095
                        start= mid + 1;
 
2096
                else if (frame < midfra)
 
2097
                        end= mid - 1;
 
2098
        }
 
2099
        
 
2100
        /* print error if loop-limit exceeded */
 
2101
        if (loopbreaker == (maxloop-1)) {
 
2102
                printf("Error: binarysearch_bezt_index was taking too long \n");
 
2103
                
 
2104
                // include debug info 
 
2105
                printf("\tround = %d: start = %d, end = %d, arraylen = %d \n", loopbreaker, start, end, arraylen);
 
2106
        }
 
2107
        
 
2108
        /* not found, so return where to place it */
 
2109
        return start;
 
2110
}
 
2111
 
 
2112
/* This function adds a given BezTriple to an IPO-Curve. It will allocate 
 
2113
 * memory for the array if needed, and will insert the BezTriple into a
 
2114
 * suitable place in chronological order.
 
2115
 * 
 
2116
 * NOTE: any recalculate of the IPO-Curve that needs to be done will need to 
 
2117
 *              be done by the caller.
 
2118
 */
 
2119
int insert_bezt_icu (IpoCurve *icu, BezTriple *bezt)
 
2120
{
 
2121
        BezTriple *newb;
 
2122
        int i= 0;
 
2123
        
 
2124
        if (icu->bezt == NULL) {
 
2125
                icu->bezt= MEM_callocN(sizeof(BezTriple), "beztriple");
 
2126
                *(icu->bezt)= *bezt;
 
2127
                icu->totvert= 1;
 
2128
        }
 
2129
        else {
 
2130
                short replace = -1;
 
2131
                i = binarysearch_bezt_index(icu->bezt, bezt, icu->totvert, &replace);
 
2132
                
 
2133
                if (replace) {                  
 
2134
                        /* sanity check: 'i' may in rare cases exceed arraylen */
 
2135
                        if ((i >= 0) && (i < icu->totvert))
 
2136
                                *(icu->bezt + i) = *bezt;
 
2137
                }
 
2138
                else {
 
2139
                        /* add new */
 
2140
                        newb= MEM_callocN((icu->totvert+1)*sizeof(BezTriple), "beztriple");
 
2141
                        
 
2142
                        /* add the beztriples that should occur before the beztriple to be pasted (originally in ei->icu) */
 
2143
                        if (i > 0)
 
2144
                                memcpy(newb, icu->bezt, i*sizeof(BezTriple));
 
2145
                        
 
2146
                        /* add beztriple to paste at index i */
 
2147
                        *(newb + i)= *bezt;
 
2148
                        
 
2149
                        /* add the beztriples that occur after the beztriple to be pasted (originally in icu) */
 
2150
                        if (i < icu->totvert) 
 
2151
                                memcpy(newb+i+1, icu->bezt+i, (icu->totvert-i)*sizeof(BezTriple));
 
2152
                        
 
2153
                        /* replace (+ free) old with new */
 
2154
                        MEM_freeN(icu->bezt);
 
2155
                        icu->bezt= newb;
 
2156
                        
 
2157
                        icu->totvert++;
 
2158
                }
 
2159
        }
 
2160
        
 
2161
        /* we need to return the index, so that some tools which do post-processing can 
 
2162
         * detect where we added the BezTriple in the array
 
2163
         */
 
2164
        return i;
 
2165
}
 
2166
 
 
2167
/* This function is a wrapper for insert_bezt_icu, and should be used when
 
2168
 * adding a new keyframe to a curve, when the keyframe doesn't exist anywhere
 
2169
 * else yet. 
 
2170
 * 
 
2171
 * 'fast' - is only for the python API where importing BVH's would take an extreamly long time.
 
2172
 */
 
2173
void insert_vert_icu (IpoCurve *icu, float x, float y, short fast)
 
2174
{
 
2175
        BezTriple beztr;
 
2176
        int a, h1, h2;
 
2177
        
 
2178
        /* set all three points, for nicer start position */
1849
2179
        memset(&beztr, 0, sizeof(BezTriple));
1850
 
        beztr.vec[0][0]= x; // set all three points, for nicer start position
 
2180
        beztr.vec[0][0]= x; 
1851
2181
        beztr.vec[0][1]= y;
1852
2182
        beztr.vec[1][0]= x;
1853
2183
        beztr.vec[1][1]= y;
1856
2186
        beztr.hide= IPO_BEZ;
1857
2187
        beztr.f1= beztr.f2= beztr.f3= SELECT;
1858
2188
        beztr.h1= beztr.h2= HD_AUTO;
1859
 
                
1860
 
        bezt= icu->bezt;
1861
 
                
1862
 
        if(bezt==NULL) {
1863
 
                icu->bezt= MEM_callocN( sizeof(BezTriple), "beztriple");
1864
 
                *(icu->bezt)= beztr;
1865
 
                icu->totvert= 1;
1866
 
        }
1867
 
        else {
1868
 
                /* all vertices deselect */
1869
 
                for(a=0; a<icu->totvert; a++, bezt++) {
1870
 
                        bezt->f1= bezt->f2= bezt->f3= 0;
1871
 
                }
1872
 
        
1873
 
                bezt= icu->bezt;
1874
 
                for(a=0; a<=icu->totvert; a++, bezt++) {
1875
 
                        
1876
 
                        /* no double points */
1877
 
                        if(a<icu->totvert && (bezt->vec[1][0]>x-IPOTHRESH && bezt->vec[1][0]<x+IPOTHRESH)) {
1878
 
                                *(bezt)= beztr;
1879
 
                                break;
1880
 
                        }
1881
 
                        if(a==icu->totvert || bezt->vec[1][0] > x) {
1882
 
                                newbezt= MEM_callocN( (icu->totvert+1)*sizeof(BezTriple), "beztriple");
1883
 
                                
1884
 
                                if(a>0) memcpy(newbezt, icu->bezt, a*sizeof(BezTriple));
1885
 
                                
1886
 
                                bezt= newbezt+a;
1887
 
                                *(bezt)= beztr;
1888
 
                                
1889
 
                                if(a<icu->totvert) memcpy(newbezt+a+1, icu->bezt+a, (icu->totvert-a)*sizeof(BezTriple));
1890
 
                                
1891
 
                                MEM_freeN(icu->bezt);
1892
 
                                icu->bezt= newbezt;
1893
 
                                
1894
 
                                icu->totvert++;
1895
 
                                break;
1896
 
                        }
1897
 
                }
1898
 
        }
1899
 
        
1900
 
        
1901
 
        calchandles_ipocurve(icu);
 
2189
        
 
2190
        /* add temp beztriple to keyframes */
 
2191
        a= insert_bezt_icu(icu, &beztr);
 
2192
        if (!fast) calchandles_ipocurve(icu);
1902
2193
        
1903
2194
        /* set handletype */
1904
 
        if(icu->totvert>2) {
 
2195
        if (icu->totvert > 2) {
 
2196
                BezTriple *bezt;
 
2197
                
1905
2198
                h1= h2= HD_AUTO;
1906
 
                if(a>0) h1= (bezt-1)->h2;
1907
 
                if(a<icu->totvert-1) h2= (bezt+1)->h1;
 
2199
                bezt= (icu->bezt + a);
 
2200
                
 
2201
                if (a > 0) h1= (bezt-1)->h2;
 
2202
                if (a < icu->totvert-1) h2= (bezt+1)->h1;
 
2203
                
1908
2204
                bezt->h1= h1;
1909
2205
                bezt->h2= h2;
1910
 
 
1911
 
                calchandles_ipocurve(icu);
 
2206
                
 
2207
                if (!fast) calchandles_ipocurve(icu);
1912
2208
        }
1913
2209
}
1914
2210
 
1938
2234
        
1939
2235
        areamouseco_to_ipoco(G.v2d, mval, &x, &y);
1940
2236
        
 
2237
        /* convert click-time to ipo-time */
 
2238
        if (NLA_IPO_SCALED) {
 
2239
                x= get_action_frame(OBACT, x);
 
2240
        }
 
2241
        
1941
2242
        if(ei->icu==NULL) {
1942
2243
                if(G.sipo->from) {
1943
 
                        ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, ei->adrcode);
1944
 
                        ei->flag |= ei->icu->flag & IPO_AUTO_HORIZ;     /* new curve could have been added, weak... */
 
2244
                        ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, G.sipo->bonename, ei->adrcode);
 
2245
                        if (ei->icu)
 
2246
                                ei->flag |= ei->icu->flag & IPO_AUTO_HORIZ;     /* new curve could have been added, weak... */
 
2247
                        else
 
2248
                                error("Cannot create an IPO curve, you may be using libdata");
1945
2249
                }
1946
2250
        }
1947
2251
        if(ei->icu==NULL) return;
1953
2257
                y= (float)(1 << val);
1954
2258
        }
1955
2259
        
1956
 
        insert_vert_ipo(ei->icu, x, y);
 
2260
        insert_vert_icu(ei->icu, x, y, 0);
1957
2261
 
1958
2262
        /* to be sure: if icu was 0, or only 1 curve visible */
1959
2263
        ei->flag |= IPO_SELECT;
1963
2267
        BIF_undo_push("Add Ipo vertex");
1964
2268
}
1965
2269
 
1966
 
static void *get_context_ipo_poin(ID *id, int blocktype, char *actname, IpoCurve *icu, int *vartype)
 
2270
static void *get_context_ipo_poin(ID *id, int blocktype, char *actname, char *constname, IpoCurve *icu, int *vartype)
1967
2271
{
1968
 
        if(blocktype==ID_PO) {
1969
 
                if(GS(id->name)==ID_OB) {
 
2272
        if (blocktype==ID_PO) {
 
2273
                if (GS(id->name)==ID_OB) {
1970
2274
                        Object *ob= (Object *)id;
1971
2275
                        bPoseChannel *pchan= get_pose_channel(ob->pose, actname);
1972
2276
                        
1973
 
                        *vartype= IPO_FLOAT;
1974
 
                        return get_pchan_ipo_poin(pchan, icu->adrcode);
 
2277
                        if (pchan) {
 
2278
                                *vartype= IPO_FLOAT;
 
2279
                                return get_pchan_ipo_poin(pchan, icu->adrcode);
 
2280
                        }
 
2281
                        else
 
2282
                                return NULL;
 
2283
                }
 
2284
                return NULL;
 
2285
        }
 
2286
        else if (blocktype==ID_CO) {
 
2287
                if ((GS(id->name)==ID_OB) && (constname && constname[0])) {
 
2288
                        Object *ob= (Object *)id;
 
2289
                        bConstraint *con;
 
2290
                        
 
2291
                        /* assume that we only want the influence (as only used for Constraint Channels) */
 
2292
                        if ((ob->ipoflag & OB_ACTION_OB) && !strcmp(actname, "Object")) {
 
2293
                                for (con= ob->constraints.first; con; con= con->next) {
 
2294
                                        if (strcmp(constname, con->name)==0) {
 
2295
                                                *vartype= IPO_FLOAT;
 
2296
                                                return &con->enforce;
 
2297
                                        }
 
2298
                                }
 
2299
                        }
 
2300
                        else if (ob->pose) {
 
2301
                                bPoseChannel *pchan= get_pose_channel(ob->pose, actname);
 
2302
                                
 
2303
                                if (pchan) {
 
2304
                                        for (con= pchan->constraints.first; con; con= con->next) {
 
2305
                                                if (strcmp(constname, con->name)==0) {
 
2306
                                                        *vartype= IPO_FLOAT;
 
2307
                                                        return &con->enforce;
 
2308
                                                }
 
2309
                                        }
 
2310
                                }
 
2311
                        }
1975
2312
                }
1976
2313
                return NULL;
1977
2314
        }
1980
2317
 
1981
2318
}
1982
2319
 
1983
 
void insertkey(ID *id, int blocktype, char *actname, char *constname, int adrcode)
1984
 
{
1985
 
        IpoCurve *icu;
1986
 
        Object *ob;
1987
 
        void *poin= NULL;
1988
 
        float curval, cfra;
1989
 
        int vartype;
1990
 
        
1991
 
        icu= verify_ipocurve(id, blocktype, actname, constname, adrcode);
 
2320
#define KEYNEEDED_DONTADD       0
 
2321
#define KEYNEEDED_JUSTADD       1
 
2322
#define KEYNEEDED_DELPREV       2
 
2323
#define KEYNEEDED_DELNEXT       3
 
2324
 
 
2325
static int new_key_needed(IpoCurve *icu, float cFrame, float nValue) 
 
2326
{
 
2327
        /* This function determines whether a new keyframe is needed */
 
2328
        /* Cases where keyframes should not be added:
 
2329
         *      1. Keyframe to be added bewteen two keyframes with similar values
 
2330
         *      2. Keyframe to be added on frame where two keyframes are already situated
 
2331
         *      3. Keyframe lies at point that intersects the linear line between two keyframes
 
2332
         */
 
2333
        
 
2334
        BezTriple *bezt=NULL, *prev=NULL;
 
2335
        int totCount, i;
 
2336
        float valA = 0.0f, valB = 0.0f;
 
2337
        
 
2338
        /* safety checking */
 
2339
        if (!icu) return KEYNEEDED_JUSTADD;
 
2340
        totCount= icu->totvert;
 
2341
        if (totCount==0) return KEYNEEDED_JUSTADD;
 
2342
        
 
2343
        /* loop through checking if any are the same */
 
2344
        bezt= icu->bezt;
 
2345
        for (i=0; i<totCount; i++) {
 
2346
                float prevPosi=0.0f, prevVal=0.0f;
 
2347
                float beztPosi=0.0f, beztVal=0.0f;
 
2348
                        
 
2349
                /* get current time+value */    
 
2350
                beztPosi= bezt->vec[1][0];
 
2351
                beztVal= bezt->vec[1][1];
 
2352
                        
 
2353
                if (prev) {
 
2354
                        /* there is a keyframe before the one currently being examined */               
 
2355
                        
 
2356
                        /* get previous time+value */
 
2357
                        prevPosi= prev->vec[1][0];
 
2358
                        prevVal= prev->vec[1][1];
 
2359
                        
 
2360
                        /* keyframe to be added at point where there are already two similar points? */
 
2361
                        if (IS_EQ(prevPosi, cFrame) && IS_EQ(beztPosi, cFrame) && IS_EQ(beztPosi, prevPosi)) {
 
2362
                                return KEYNEEDED_DONTADD;
 
2363
                        }
 
2364
                        
 
2365
                        /* keyframe between prev+current points ? */
 
2366
                        if ((prevPosi <= cFrame) && (cFrame <= beztPosi)) {
 
2367
                                /* is the value of keyframe to be added the same as keyframes on either side ? */
 
2368
                                if (IS_EQ(prevVal, nValue) && IS_EQ(beztVal, nValue) && IS_EQ(prevVal, beztVal)) {
 
2369
                                        return KEYNEEDED_DONTADD;
 
2370
                                }
 
2371
                                else {
 
2372
                                        float realVal;
 
2373
                                        
 
2374
                                        /* get real value of curve at that point */
 
2375
                                        realVal= eval_icu(icu, cFrame);
 
2376
                                
 
2377
                                        /* compare whether it's the same as proposed */
 
2378
                                        if (IS_EQ(realVal, nValue)) 
 
2379
                                                return KEYNEEDED_DONTADD;
 
2380
                                        else 
 
2381
                                                return KEYNEEDED_JUSTADD;
 
2382
                                }
 
2383
                        }
 
2384
                        
 
2385
                        /* new keyframe before prev beztriple? */
 
2386
                        if (cFrame < prevPosi) {
 
2387
                                /* A new keyframe will be added. However, whether the previous beztriple
 
2388
                                 * stays around or not depends on whether the values of previous/current
 
2389
                                 * beztriples and new keyframe are the same.
 
2390
                                 */
 
2391
                                if (IS_EQ(prevVal, nValue) && IS_EQ(beztVal, nValue) && IS_EQ(prevVal, beztVal))
 
2392
                                        return KEYNEEDED_DELNEXT;
 
2393
                                else 
 
2394
                                        return KEYNEEDED_JUSTADD;
 
2395
                        }
 
2396
                }
 
2397
                else {
 
2398
                        /* just add a keyframe if there's only one keyframe 
 
2399
                         * and the new one occurs before the exisiting one does.
 
2400
                         */
 
2401
                        if ((cFrame < beztPosi) && (totCount==1))
 
2402
                                return KEYNEEDED_JUSTADD;
 
2403
                }
 
2404
                
 
2405
                /* continue. frame to do not yet passed (or other conditions not met) */
 
2406
                if (i < (totCount-1)) {
 
2407
                        prev= bezt;
 
2408
                        bezt++;
 
2409
                }
 
2410
                else
 
2411
                        break;
 
2412
        }
 
2413
        
 
2414
        /* Frame in which to add a new-keyframe occurs after all other keys
 
2415
         * -> If there are at least two existing keyframes, then if the values of the
 
2416
         *       last two keyframes and the new-keyframe match, the last existing keyframe
 
2417
         *       gets deleted as it is no longer required.
 
2418
         * -> Otherwise, a keyframe is just added. 1.0 is added so that fake-2nd-to-last
 
2419
         *       keyframe is not equal to last keyframe.
 
2420
         */
 
2421
        bezt= (icu->bezt + (icu->totvert - 1));
 
2422
        valA= bezt->vec[1][1];
 
2423
        
 
2424
        if (prev)
 
2425
                valB= prev->vec[1][1];
 
2426
        else 
 
2427
                valB= bezt->vec[1][1] + 1.0f; 
 
2428
                
 
2429
        if (IS_EQ(valA, nValue) && IS_EQ(valA, valB)) 
 
2430
                return KEYNEEDED_DELPREV;
 
2431
        else 
 
2432
                return KEYNEEDED_JUSTADD;
 
2433
}
 
2434
 
 
2435
/* a duplicate of insertkey that does not check for routing to insertmatrixkey 
 
2436
        to avoid recursion problems */
 
2437
static void insertkey_nonrecurs(ID *id, int blocktype, char *actname, char *constname, int adrcode)
 
2438
{
 
2439
        IpoCurve *icu;
 
2440
        Object *ob;
 
2441
        void *poin= NULL;
 
2442
        float curval, cfra;
 
2443
        int vartype;
 
2444
        int matset=0;
 
2445
        
 
2446
        if (matset==0) {
 
2447
                icu= verify_ipocurve(id, blocktype, actname, constname, NULL, adrcode);
 
2448
                
 
2449
                if(icu) {
 
2450
                        
 
2451
                        poin= get_context_ipo_poin(id, blocktype, actname, constname, icu, &vartype);
 
2452
                        
 
2453
                        if(poin) {
 
2454
                                curval= read_ipo_poin(poin, vartype);
 
2455
                                
 
2456
                                cfra= frame_to_float(CFRA);
 
2457
                                
 
2458
                                /* if action is mapped in NLA, it returns a correction */
 
2459
                                if(actname && actname[0] && GS(id->name)==ID_OB)
 
2460
                                        cfra= get_action_frame((Object *)id, cfra);
 
2461
                                
 
2462
                                if( GS(id->name)==ID_OB ) {
 
2463
                                        ob= (Object *)id;
 
2464
                                        if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
 
2465
                                                /* actually frametofloat calc again! */
 
2466
                                                cfra-= give_timeoffset(ob)*G.scene->r.framelen;
 
2467
                                        }
 
2468
                                }
 
2469
                                
 
2470
                                insert_vert_icu(icu, cfra, curval, 0);
 
2471
                        }
 
2472
                }
 
2473
        }
 
2474
}
 
2475
 
 
2476
int insertmatrixkey(ID *id, int blocktype, char *actname, char *constname, int adrcode)
 
2477
{
 
2478
        int matindex=0;
 
2479
        /* branch on adrcode and blocktype, generating the proper matrix-based
 
2480
        values to send to insertfloatkey */
 
2481
        if (GS(id->name)==ID_OB) {
 
2482
                Object *ob= (Object *)id;
 
2483
 
 
2484
                if ( blocktype==ID_OB ){ //working with an object
 
2485
                        if ((ob)&&!(ob->parent)) {
 
2486
                                if ((adrcode==OB_ROT_X)||(adrcode==OB_ROT_Y)||(adrcode==OB_ROT_Z)) { //get a rotation
 
2487
                                        float eul[3];
 
2488
                                        switch (adrcode) {
 
2489
                                                case OB_ROT_X:
 
2490
                                                        matindex=0;
 
2491
                                                        break;
 
2492
                                                case OB_ROT_Y:
 
2493
                                                        matindex=1;
 
2494
                                                        break;
 
2495
                                                case OB_ROT_Z:
 
2496
                                                        matindex=2;
 
2497
                                                        break;
 
2498
                                        }
 
2499
                                        Mat4ToEul(ob->obmat, eul);
 
2500
                                        insertfloatkey(id, ID_OB, actname, NULL, adrcode, eul[matindex]*(5.72958));
 
2501
                                        return 1;
 
2502
                                } else if ((adrcode==OB_LOC_X)||(adrcode==OB_LOC_Y)||(adrcode==OB_LOC_Z)) {//get a translation
 
2503
                                        switch (adrcode) {
 
2504
                                                case OB_LOC_X:
 
2505
                                                        matindex=0;
 
2506
                                                        break;
 
2507
                                                case OB_LOC_Y:
 
2508
                                                        matindex=1;
 
2509
                                                        break;
 
2510
                                                case OB_LOC_Z:
 
2511
                                                        matindex=2;
 
2512
                                                        break;
 
2513
                                        }
 
2514
                                        insertfloatkey(id, ID_OB, actname, NULL, adrcode, ob->obmat[3][matindex]);
 
2515
                                        return 1;
 
2516
                                }
 
2517
                        }
 
2518
                } else if ( blocktype==ID_PO) { //working with a pose channel
 
2519
                        bPoseChannel *pchan= get_pose_channel(ob->pose, actname);
 
2520
                        if (pchan) {
 
2521
                                if ((adrcode==AC_LOC_X)||(adrcode==AC_LOC_Y)||(adrcode==AC_LOC_Z)) {
 
2522
                                        switch (adrcode) {
 
2523
                                                case AC_LOC_X:
 
2524
                                                        matindex=0;
 
2525
                                                        break;
 
2526
                                                case AC_LOC_Y:
 
2527
                                                        matindex=1;
 
2528
                                                        break;
 
2529
                                                case AC_LOC_Z:
 
2530
                                                        matindex=2;
 
2531
                                                        break;
 
2532
                                        }
 
2533
                                        if (!(pchan->bone->parent)||((pchan->bone->parent)&&!(pchan->bone->flag&BONE_CONNECTED))) { /* don't use for non-connected child bones */
 
2534
                                                float delta_mat[4][4]; 
 
2535
                                                armature_mat_pose_to_delta(delta_mat, pchan->pose_mat, pchan->bone->arm_mat);
 
2536
                                                insertfloatkey(id, ID_PO, pchan->name, NULL, adrcode, delta_mat[3][matindex]);
 
2537
                                                return 1;
 
2538
                                        }
 
2539
                                } else if ((adrcode==AC_QUAT_W)||(adrcode==AC_QUAT_X)||(adrcode==AC_QUAT_Y)||(adrcode==AC_QUAT_Z)) { 
 
2540
                                        float tmat[4][4], trimat[3][3], localQuat[4];
 
2541
                                        
 
2542
                                        switch (adrcode) {
 
2543
                                                case AC_QUAT_W:
 
2544
                                                        matindex=0;
 
2545
                                                        break;
 
2546
                                                case AC_QUAT_X:
 
2547
                                                        matindex=1;
 
2548
                                                        break;
 
2549
                                                case AC_QUAT_Y:
 
2550
                                                        matindex=2;
 
2551
                                                        break;
 
2552
                                                case AC_QUAT_Z:
 
2553
                                                        matindex=3;
 
2554
                                                        break;
 
2555
                                        }
 
2556
                                        
 
2557
                                        /* it should be reasonable to assume that we are keyframing on the active object, although it is not 
 
2558
                                         * strictly required for this particular space conversion, arg1 must not be null for this to work
 
2559
                                         */
 
2560
                                        Mat4CpyMat4(tmat, pchan->pose_mat);
 
2561
                                        constraint_mat_convertspace(OBACT, pchan, tmat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL);
 
2562
                                        
 
2563
                                        Mat3CpyMat4(trimat, tmat);
 
2564
                                        Mat3ToQuat_is_ok(trimat, localQuat);
 
2565
                                        insertfloatkey(id, ID_PO, pchan->name, NULL, adrcode, localQuat[matindex]);
 
2566
                                        
 
2567
                                        return 1;
 
2568
                                }
 
2569
                        }
 
2570
                }
 
2571
        }
 
2572
        /* failed to set a matrix key -- use traditional, but the non-recursing version */
 
2573
        insertkey_nonrecurs(id,blocktype,actname,constname,adrcode);
 
2574
        return 0;
 
2575
}
 
2576
 
 
2577
static int match_adr_constraint(ID * id, int blocktype, char *actname, int adrcode)
 
2578
{       /* This function matches constraint blocks with adrcodes to see if the
 
2579
                visual keying method should be used. For example, an object looking to key
 
2580
                location and having a CopyLoc constraint would return true. */
 
2581
                
 
2582
        Object *ob=NULL;
 
2583
        int foundmatch=0;
 
2584
        int searchtype=0;
 
2585
        bConstraint *conref=NULL, *con=NULL;
 
2586
        
 
2587
        /*Retrieve constraint list*/
 
2588
        if( GS(id->name)==ID_OB ) 
 
2589
                ob= (Object *)id;
 
2590
        if (ob) {
 
2591
                if (blocktype==ID_PO) {
 
2592
                        bPoseChannel *pchan= get_pose_channel(ob->pose, actname);
 
2593
                        conref=pchan->constraints.first;
 
2594
                } else if (blocktype==ID_OB) {
 
2595
                        conref=ob->constraints.first;
 
2596
                }
 
2597
                
 
2598
                if (conref) {
 
2599
                        /*Set search type: 1 is for translation contraints, 2 is for rotation*/
 
2600
                        if ((adrcode==OB_LOC_X)||(adrcode==OB_LOC_Y)||(adrcode==OB_LOC_Z)||(adrcode==AC_LOC_X)||(adrcode==AC_LOC_Y)||(adrcode==AC_LOC_Z)) {
 
2601
                                searchtype=1;
 
2602
                        } else if ((adrcode==OB_ROT_X)||(adrcode==OB_ROT_Y)||(adrcode==OB_ROT_Z)||(adrcode==AC_QUAT_W)||(adrcode==AC_QUAT_X)||(adrcode==AC_QUAT_Y)||(adrcode==AC_QUAT_Z)) {
 
2603
                                searchtype=2;
 
2604
                        }
 
2605
                        
 
2606
                        if (searchtype>0) {
 
2607
                                for (con=conref; (con)&&(foundmatch==0); con=con->next) {
 
2608
                                        switch (con->type) {
 
2609
                                        /* match constraint types to which kinds of keying they would affect */
 
2610
                                                case CONSTRAINT_TYPE_CHILDOF:
 
2611
                                                        foundmatch=1;
 
2612
                                                        break;
 
2613
                                                case CONSTRAINT_TYPE_TRACKTO:
 
2614
                                                        if (searchtype==2) foundmatch=1;
 
2615
                                                        break;
 
2616
                                                case CONSTRAINT_TYPE_FOLLOWPATH:
 
2617
                                                        foundmatch=1;
 
2618
                                                        break;
 
2619
                                                case CONSTRAINT_TYPE_ROTLIMIT:
 
2620
                                                        if (searchtype==2) foundmatch=1;
 
2621
                                                        break;
 
2622
                                                case CONSTRAINT_TYPE_LOCLIMIT:
 
2623
                                                        if (searchtype==1) foundmatch=1;
 
2624
                                                        break;
 
2625
                                                case CONSTRAINT_TYPE_ROTLIKE:
 
2626
                                                        if (searchtype==2) foundmatch=1;
 
2627
                                                        break;
 
2628
                                                case CONSTRAINT_TYPE_LOCLIKE:
 
2629
                                                        if (searchtype==1) foundmatch=1;
 
2630
                                                        break;
 
2631
                                                case CONSTRAINT_TYPE_LOCKTRACK:
 
2632
                                                        if (searchtype==2) foundmatch=1;
 
2633
                                                        break;
 
2634
                                                case CONSTRAINT_TYPE_DISTLIMIT:
 
2635
                                                        if (searchtype==1) foundmatch=1;
 
2636
                                                        break;
 
2637
                                                case CONSTRAINT_TYPE_MINMAX:
 
2638
                                                        if (searchtype==1) foundmatch=1;
 
2639
                                                        break;
 
2640
                                                case CONSTRAINT_TYPE_TRANSFORM:
 
2641
                                                        foundmatch=1;
 
2642
                                                        break;
 
2643
                                                default:
 
2644
                                                        break;
 
2645
                                        }
 
2646
                                }
 
2647
                        }
 
2648
                }
 
2649
        }
 
2650
        
 
2651
        return foundmatch;
 
2652
                        
 
2653
}
 
2654
 
 
2655
void insertkey(ID *id, int blocktype, char *actname, char *constname, int adrcode, short fast)
 
2656
{
 
2657
        IpoCurve *icu;
 
2658
        Object *ob;
 
2659
        void *poin= NULL;
 
2660
        float curval, cfra;
 
2661
        int vartype;
 
2662
        int matset=0;
 
2663
        
 
2664
        if ((IS_AUTOKEY_FLAG(AUTOMATKEY))&&(match_adr_constraint(id, blocktype, actname, adrcode))) {
 
2665
                matset=insertmatrixkey(id, blocktype, actname, constname, adrcode);
 
2666
        } 
 
2667
        if (matset==0) {
 
2668
                icu= verify_ipocurve(id, blocktype, actname, constname, NULL, adrcode);
 
2669
                
 
2670
                if(icu) {
 
2671
                        
 
2672
                        poin= get_context_ipo_poin(id, blocktype, actname, constname, icu, &vartype);
 
2673
                        
 
2674
                        if(poin) {
 
2675
                                curval= read_ipo_poin(poin, vartype);
 
2676
                                
 
2677
                                cfra= frame_to_float(CFRA);
 
2678
                                
 
2679
                                /* if action is mapped in NLA, it returns a correction */
 
2680
                                if(actname && actname[0] && GS(id->name)==ID_OB)
 
2681
                                        cfra= get_action_frame((Object *)id, cfra);
 
2682
                                
 
2683
                                if( GS(id->name)==ID_OB ) {
 
2684
                                        ob= (Object *)id;
 
2685
                                        if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
 
2686
                                                /* actually frametofloat calc again! */
 
2687
                                                cfra-= give_timeoffset(ob)*G.scene->r.framelen;
 
2688
                                        }
 
2689
                                }
 
2690
                                
 
2691
                                insert_vert_icu(icu, cfra, curval, fast);
 
2692
                        }
 
2693
                }
 
2694
        }
 
2695
}
 
2696
 
 
2697
 
 
2698
 
 
2699
/* This function is a 'smarter' version of the insert key code.
 
2700
 * It uses an auxilliary function to check whether a keyframe is really needed */
 
2701
void insertkey_smarter(ID *id, int blocktype, char *actname, char *constname, int adrcode)
 
2702
{
 
2703
        IpoCurve *icu;
 
2704
        Object *ob;
 
2705
        void *poin= NULL;
 
2706
        float curval, cfra;
 
2707
        int vartype;
 
2708
        int insert_mode;
 
2709
        
 
2710
        icu= verify_ipocurve(id, blocktype, actname, constname, NULL, adrcode);
1992
2711
        
1993
2712
        if(icu) {
1994
2713
                
1995
 
                poin= get_context_ipo_poin(id, blocktype, actname, icu, &vartype);
 
2714
                poin= get_context_ipo_poin(id, blocktype, actname, constname, icu, &vartype);
1996
2715
                
1997
2716
                if(poin) {
1998
2717
                        curval= read_ipo_poin(poin, vartype);
2005
2724
                        
2006
2725
                        if( GS(id->name)==ID_OB ) {
2007
2726
                                ob= (Object *)id;
2008
 
                                if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
 
2727
                                if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
2009
2728
                                        /* actually frametofloat calc again! */
2010
 
                                        cfra-= ob->sf*G.scene->r.framelen;
 
2729
                                        cfra-= give_timeoffset(ob)*G.scene->r.framelen;
2011
2730
                                }
2012
2731
                        }
2013
2732
                        
2014
 
                        insert_vert_ipo(icu, cfra, curval);
 
2733
                        /* check whether this curve really needs a new keyframe */
 
2734
                        insert_mode= new_key_needed(icu, cfra, curval);
 
2735
                        
 
2736
                        /* insert new keyframe at current frame */
 
2737
                        if (insert_mode) 
 
2738
                                insert_vert_icu(icu, cfra, curval, 0);
 
2739
                        
 
2740
                        /* delete keyframe immediately before/after newly added */
 
2741
                        switch (insert_mode) {
 
2742
                                case KEYNEEDED_DELPREV:
 
2743
                                        delete_icu_key(icu, icu->totvert-2, 1);
 
2744
                                        break;
 
2745
                                case KEYNEEDED_DELNEXT:
 
2746
                                        delete_icu_key(icu, 1, 1);
 
2747
                                        break;
 
2748
                        }
2015
2749
                }
2016
2750
        }
2017
2751
}
2018
2752
 
2019
 
/* For inserting keys based on the object matrix - not on the current IPO value
2020
 
   Generically - it inserts the passed float value into the appropriate IPO */
2021
 
void insertmatrixkey(ID *id, int blocktype, char *actname, char *constname, int adrcode, float matrixvalue)
 
2753
/* For inserting keys based on an arbitrary float value */
 
2754
void insertfloatkey(ID *id, int blocktype, char *actname, char *constname, int adrcode, float floatkey)
2022
2755
{
2023
2756
        IpoCurve *icu;
2024
2757
        Object *ob;
2026
2759
        float cfra;
2027
2760
        int vartype;
2028
2761
        
2029
 
        icu= verify_ipocurve(id, blocktype, actname, constname, adrcode);
 
2762
        icu= verify_ipocurve(id, blocktype, actname, constname, NULL, adrcode);
2030
2763
        
2031
2764
        if(icu) {
2032
2765
                
2033
 
                poin= get_context_ipo_poin(id, blocktype, actname, icu, &vartype);
 
2766
                poin= get_context_ipo_poin(id, blocktype, actname, constname, icu, &vartype);
2034
2767
                
2035
2768
                if(poin) {
2036
2769
                        
2042
2775
                        
2043
2776
                        if( GS(id->name)==ID_OB ) {
2044
2777
                                ob= (Object *)id;
2045
 
                                if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
 
2778
                                if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
2046
2779
                                        /* actually frametofloat calc again! */
2047
 
                                        cfra-= ob->sf*G.scene->r.framelen;
 
2780
                                        cfra-= give_timeoffset(ob)*G.scene->r.framelen;
2048
2781
                                }
2049
2782
                        }
2050
 
                        insert_vert_ipo(icu, cfra, matrixvalue);
 
2783
                        
 
2784
                        /* insert new keyframe at current frame */
 
2785
                        insert_vert_icu(icu, cfra, floatkey, 0);
2051
2786
                }
2052
2787
        }
2053
2788
}
2078
2813
                ei->icu->totvert= 0;
2079
2814
                ei->icu->bezt= NULL;
2080
2815
                
2081
 
                insert_vert_ipo(ei->icu, 0.0f, 0.0f);
 
2816
                insert_vert_icu(ei->icu, 0.0f, 0.0f, 0);
2082
2817
                
2083
2818
                if(ELEM3(driver->adrcode, OB_ROT_X, OB_ROT_Y, OB_ROT_Z)) {
2084
2819
                        if(ei->disptype==IPO_DISPDEGR)
2085
 
                                insert_vert_ipo(ei->icu, 18.0f, 18.0f);
 
2820
                                insert_vert_icu(ei->icu, 18.0f, 18.0f, 0);
2086
2821
                        else
2087
 
                                insert_vert_ipo(ei->icu, 18.0f, 1.0f);
 
2822
                                insert_vert_icu(ei->icu, 18.0f, 1.0f, 0);
2088
2823
                }
2089
2824
                else
2090
 
                        insert_vert_ipo(ei->icu, 1.0f, 1.0f);
 
2825
                        insert_vert_icu(ei->icu, 1.0f, 1.0f, 0);
2091
2826
                
2092
2827
                ei->flag |= IPO_SELECT|IPO_VISIBLE;
2093
2828
                ei->icu->flag= ei->flag;
2122
2857
                                                id= G.sipo->from;       
2123
2858
                                                if(id && GS(id->name)==ID_OB ) {
2124
2859
                                                        Object *ob= (Object *)id;
2125
 
                                                        if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
2126
 
                                                                cfra-= ob->sf*G.scene->r.framelen;
 
2860
                                                        if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
 
2861
                                                                cfra-= give_timeoffset(ob)*G.scene->r.framelen;
2127
2862
                                                        }
2128
2863
                                                }
2129
2864
                                                else if(id && GS(id->name)==ID_SEQ) {
2133
2868
                                                                cfra= (float)(100.0*(cfra-last_seq->startdisp)/((float)(last_seq->enddisp-last_seq->startdisp)));
2134
2869
                                                        }
2135
2870
                                                }
 
2871
                                                
 
2872
                                                /* convert cfra to ipo-time */
 
2873
                                                if (NLA_IPO_SCALED) {
 
2874
                                                        cfra= get_action_frame(OBACT, cfra);
 
2875
                                                }
2136
2876
                                
2137
2877
                                                insertvals= MEM_mallocN(sizeof(float)*2*tot, "insertkey_editipo");
2138
2878
                                                /* make sure icu->curval is correct */
2159
2899
                                                }
2160
2900
                                                fp= insertvals;
2161
2901
                                                for(a=0; a<tot; a++, fp+=2) {
2162
 
                                                        insert_vert_ipo(ei->icu, fp[0], fp[1]);
 
2902
                                                        insert_vert_icu(ei->icu, fp[0], fp[1], 0);
2163
2903
                                                }
2164
2904
                                                
2165
2905
                                                MEM_freeN(insertvals);
2193
2933
        if(curarea->spacetype==SPACE_IPO) {
2194
2934
                insertkey_editipo();
2195
2935
        }
 
2936
        else if(curarea->spacetype==SPACE_ACTION) {
 
2937
                insertkey_action();
 
2938
        }
2196
2939
        else if(curarea->spacetype==SPACE_BUTS) {
2197
2940
                if(G.buts->mainb==CONTEXT_SHADING) {
2198
2941
                        int tab= G.buts->tab[CONTEXT_SHADING];
2209
2952
                                        map= texchannel_to_adrcode(ma->texact);
2210
2953
 
2211
2954
                                        if(event==0 || event==10) {
2212
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_COL_R);
2213
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_COL_G);
2214
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_COL_B);
 
2955
                                                insertkey(id, ID_MA, NULL, NULL, MA_COL_R, 0);
 
2956
                                                insertkey(id, ID_MA, NULL, NULL, MA_COL_G, 0);
 
2957
                                                insertkey(id, ID_MA, NULL, NULL, MA_COL_B, 0);
2215
2958
                                        }
2216
2959
                                        if(event==1 || event==10) {
2217
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_ALPHA);
 
2960
                                                insertkey(id, ID_MA, NULL, NULL, MA_ALPHA, 0);
2218
2961
                                        }
2219
2962
                                        if(event==2 || event==10) {
2220
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_HASIZE);
 
2963
                                                insertkey(id, ID_MA, NULL, NULL, MA_HASIZE, 0);
2221
2964
                                        }
2222
2965
                                        if(event==3 || event==10) {
2223
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_MODE);
 
2966
                                                insertkey(id, ID_MA, NULL, NULL, MA_MODE, 0);
2224
2967
                                        }
2225
2968
                                        if(event==10) {
2226
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC_R);
2227
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC_G);
2228
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC_B);
2229
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_REF);
2230
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_EMIT);
2231
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_AMB);
2232
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC);
2233
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_HARD);
2234
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_MODE);
2235
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_TRANSLU);
2236
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_ADD);
 
2969
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC_R, 0);
 
2970
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC_G, 0);
 
2971
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC_B, 0);
 
2972
                                                insertkey(id, ID_MA, NULL, NULL, MA_REF, 0);
 
2973
                                                insertkey(id, ID_MA, NULL, NULL, MA_EMIT, 0);
 
2974
                                                insertkey(id, ID_MA, NULL, NULL, MA_AMB, 0);
 
2975
                                                insertkey(id, ID_MA, NULL, NULL, MA_SPEC, 0);
 
2976
                                                insertkey(id, ID_MA, NULL, NULL, MA_HARD, 0);
 
2977
                                                insertkey(id, ID_MA, NULL, NULL, MA_MODE, 0);
 
2978
                                                insertkey(id, ID_MA, NULL, NULL, MA_TRANSLU, 0);
 
2979
                                                insertkey(id, ID_MA, NULL, NULL, MA_ADD, 0);
2237
2980
                                        }
2238
2981
                                        if(event==14) {
2239
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_RAYM);
2240
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESMIR);
2241
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESMIRI);
2242
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESTRA);
2243
 
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESTRAI);
 
2982
                                                insertkey(id, ID_MA, NULL, NULL, MA_RAYM, 0);
 
2983
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESMIR, 0);
 
2984
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESMIRI, 0);
 
2985
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESTRA, 0);
 
2986
                                                insertkey(id, ID_MA, NULL, NULL, MA_FRESTRAI, 0);
2244
2987
                                        }
2245
2988
                                        if(event==12 || event==11) {
2246
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_X);
2247
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Y);
2248
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Z);
 
2989
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_X, 0);
 
2990
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Y, 0);
 
2991
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_OFS_Z, 0);
2249
2992
                                        }
2250
2993
                                        if(event==13 || event==11) {
2251
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_X);
2252
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Y);
2253
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Z);
 
2994
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_X, 0);
 
2995
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Y, 0);
 
2996
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_SIZE_Z, 0);
2254
2997
                                        }
2255
2998
                                        if(event==11) {
2256
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_R);
2257
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_G);
2258
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_B);
2259
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_DVAR);
2260
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_COLF);
2261
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_NORF);
2262
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_VARF);
2263
 
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_DISP);
 
2999
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_R, 0);
 
3000
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_G, 0);
 
3001
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_B, 0);
 
3002
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_DVAR, 0);
 
3003
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_COLF, 0);
 
3004
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_NORF, 0);
 
3005
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_VARF, 0);
 
3006
                                                insertkey(id, ID_MA, NULL, NULL, map+MAP_DISP, 0);
2264
3007
                                        }
2265
3008
                                }
2266
3009
                        }
2274
3017
                                        map= texchannel_to_adrcode(wo->texact);
2275
3018
 
2276
3019
                                        if(event==0) {
2277
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_ZEN_R);
2278
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_ZEN_G);
2279
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_ZEN_B);
 
3020
                                                insertkey(id, ID_WO, NULL, NULL, WO_ZEN_R, 0);
 
3021
                                                insertkey(id, ID_WO, NULL, NULL, WO_ZEN_G, 0);
 
3022
                                                insertkey(id, ID_WO, NULL, NULL, WO_ZEN_B, 0);
2280
3023
                                        }
2281
3024
                                        if(event==1) {
2282
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_HOR_R);
2283
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_HOR_G);
2284
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_HOR_B);
 
3025
                                                insertkey(id, ID_WO, NULL, NULL, WO_HOR_R, 0);
 
3026
                                                insertkey(id, ID_WO, NULL, NULL, WO_HOR_G, 0);
 
3027
                                                insertkey(id, ID_WO, NULL, NULL, WO_HOR_B, 0);
2285
3028
                                        }
2286
3029
                                        if(event==2) {
2287
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISI);
2288
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISTDI);
2289
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISTSTA);
2290
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISTHI);
 
3030
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISI, 0);
 
3031
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISTDI, 0);
 
3032
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISTSTA, 0);
 
3033
                                                insertkey(id, ID_WO, NULL, NULL, WO_MISTHI, 0);
2291
3034
                                        }
2292
3035
                                        if(event==3) {
2293
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_STAR_R);
2294
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_STAR_G);
2295
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_STAR_B);
2296
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_STARDIST);
2297
 
                                                insertkey(id, ID_WO, NULL, NULL, WO_STARSIZE);
 
3036
                                                insertkey(id, ID_WO, NULL, NULL, WO_STAR_R, 0);
 
3037
                                                insertkey(id, ID_WO, NULL, NULL, WO_STAR_G, 0);
 
3038
                                                insertkey(id, ID_WO, NULL, NULL, WO_STAR_B, 0);
 
3039
                                                insertkey(id, ID_WO, NULL, NULL, WO_STARDIST, 0);
 
3040
                                                insertkey(id, ID_WO, NULL, NULL, WO_STARSIZE, 0);
2298
3041
                                        }
2299
3042
                                        if(event==12) {
2300
 
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_X);
2301
 
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Y);
2302
 
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Z);
 
3043
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_X, 0);
 
3044
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Y, 0);
 
3045
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_OFS_Z, 0);
2303
3046
                                        }
2304
3047
                                        if(event==13) {
2305
 
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_X);
2306
 
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Y);
2307
 
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Z);
 
3048
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_X, 0);
 
3049
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Y, 0);
 
3050
                                                insertkey(id, ID_WO, NULL, NULL, map+MAP_SIZE_Z, 0);
2308
3051
                                        }
2309
3052
                                }
2310
3053
                        }
2318
3061
                                        map= texchannel_to_adrcode(la->texact);
2319
3062
 
2320
3063
                                        if(event==0) {
2321
 
                                                insertkey(id, ID_LA, NULL, NULL, LA_COL_R);
2322
 
                                                insertkey(id, ID_LA, NULL, NULL, LA_COL_G);
2323
 
                                                insertkey(id, ID_LA, NULL, NULL, LA_COL_B);
 
3064
                                                insertkey(id, ID_LA, NULL, NULL, LA_COL_R, 0);
 
3065
                                                insertkey(id, ID_LA, NULL, NULL, LA_COL_G, 0);
 
3066
                                                insertkey(id, ID_LA, NULL, NULL, LA_COL_B, 0);
2324
3067
                                        }
2325
3068
                                        if(event==1) {
2326
 
                                                insertkey(id, ID_LA, NULL, NULL, LA_ENERGY);
 
3069
                                                insertkey(id, ID_LA, NULL, NULL, LA_ENERGY, 0);
2327
3070
                                        }
2328
3071
                                        if(event==2) {
2329
 
                                                insertkey(id, ID_LA, NULL, NULL, LA_SPOTSI);
 
3072
                                                insertkey(id, ID_LA, NULL, NULL, LA_SPOTSI, 0);
2330
3073
                                        }
2331
3074
                                        if(event==12) {
2332
 
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_OFS_X);
2333
 
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_OFS_Y);
2334
 
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_OFS_Z);
 
3075
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_OFS_X, 0);
 
3076
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_OFS_Y, 0);
 
3077
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_OFS_Z, 0);
2335
3078
                                        }
2336
3079
                                        if(event==13) {
2337
 
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_SIZE_X);
2338
 
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_SIZE_Y);
2339
 
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_SIZE_Z);
 
3080
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_SIZE_X, 0);
 
3081
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_SIZE_Y, 0);
 
3082
                                                insertkey(id, ID_LA, NULL, NULL, map+MAP_SIZE_Z, 0);
2340
3083
                                        }
2341
3084
 
2342
3085
                                }
2345
3088
                                id= G.buts->lockpoin;
2346
3089
                                te= G.buts->lockpoin;
2347
3090
                                if(id) {
2348
 
                                        event= pupmenu("Insert Key %t|Cloud%x0|Mable%x1|Stucci%x2|Wood%x3|Magic%x4|Blend%x5|Musgrave%x6|Voronoi%x7|Distnoise%x8|ColourFilter%x9");
 
3091
                                        event= pupmenu("Insert Key %t|Clouds%x0|Marble%x1|Stucci%x2|Wood%x3|Magic%x4|Blend%x5|Musgrave%x6|Voronoi%x7|DistortedNoise%x8|ColorFilter%x9");
2349
3092
                                        if(event== -1) return;
2350
3093
 
2351
3094
                                        if(event==0) {
2352
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2353
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH);
2354
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2355
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2356
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
 
3095
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
 
3096
                                                insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH, 0);
 
3097
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
 
3098
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
 
3099
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
2357
3100
                                        }
2358
3101
                                        if(event==1) {
2359
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2360
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH);
2361
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2362
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB);
2363
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2364
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
2365
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2);
 
3102
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
 
3103
                                                insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH, 0);
 
3104
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
 
3105
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
 
3106
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
 
3107
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
 
3108
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2, 0);
2366
3109
                                        }
2367
3110
                                        if(event==2) {
2368
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2369
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2370
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB);
2371
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2372
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
 
3111
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
 
3112
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
 
3113
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
 
3114
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
 
3115
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
2373
3116
                                        }
2374
3117
                                        if(event==3) {
2375
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
2376
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE);
2377
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB);
2378
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2379
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1);
2380
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2);
 
3118
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
 
3119
                                                insertkey(id, ID_TE, NULL, NULL, TE_NTYPE, 0);
 
3120
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
 
3121
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
 
3122
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS1, 0);
 
3123
                                                insertkey(id, ID_TE, NULL, NULL, TE_N_BAS2, 0);
2381
3124
                                        }
2382
3125
                                        if(event==4) {
2383
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH);
2384
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB);
 
3126
                                                insertkey(id, ID_TE, NULL, NULL, TE_NDEPTH, 0);
 
3127
                                                insertkey(id, ID_TE, NULL, NULL, TE_TURB, 0);
2385
3128
                                        }
2386
3129
                                        if(event==5) {
2387
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
 
3130
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
2388
3131
                                        } 
2389
3132
                                        if(event==6) {
2390
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP);
2391
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MGH);
2392
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_LAC);
2393
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT);
2394
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF);
2395
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN);
 
3133
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_TYP, 0);
 
3134
                                                insertkey(id, ID_TE, NULL, NULL, TE_MGH, 0);
 
3135
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_LAC, 0);
 
3136
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT, 0);
 
3137
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF, 0);
 
3138
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN, 0);
2396
3139
                                        }
2397
3140
                                        if(event==7) {
2398
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW1);
2399
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW2);
2400
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW3);
2401
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW4);
2402
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNMEXP);
2403
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_VN_DISTM);
2404
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_VN_COLT);
2405
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_ISCA);
2406
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE);
 
3141
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW1, 0);
 
3142
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW2, 0);
 
3143
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW3, 0);
 
3144
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNW4, 0);
 
3145
                                                insertkey(id, ID_TE, NULL, NULL, TE_VNMEXP, 0);
 
3146
                                                insertkey(id, ID_TE, NULL, NULL, TE_VN_DISTM, 0);
 
3147
                                                insertkey(id, ID_TE, NULL, NULL, TE_VN_COLT, 0);
 
3148
                                                insertkey(id, ID_TE, NULL, NULL, TE_ISCA, 0);
 
3149
                                                insertkey(id, ID_TE, NULL, NULL, TE_NSIZE, 0);
2407
3150
                                        }
2408
3151
                                        if(event==8) {
2409
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT);
2410
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF);
2411
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN);
2412
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_DISTA);
 
3152
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OCT, 0);
 
3153
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_OFF, 0);
 
3154
                                                insertkey(id, ID_TE, NULL, NULL, TE_MG_GAIN, 0);
 
3155
                                                insertkey(id, ID_TE, NULL, NULL, TE_DISTA, 0);
2413
3156
                                        }
2414
3157
                                        if(event==9) {
2415
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_COL_R);
2416
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_COL_G);
2417
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_COL_B);
2418
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_BRIGHT);
2419
 
                                                insertkey(id, ID_TE, NULL, NULL, TE_CONTRA);
 
3158
                                                insertkey(id, ID_TE, NULL, NULL, TE_COL_R, 0);
 
3159
                                                insertkey(id, ID_TE, NULL, NULL, TE_COL_G, 0);
 
3160
                                                insertkey(id, ID_TE, NULL, NULL, TE_COL_B, 0);
 
3161
                                                insertkey(id, ID_TE, NULL, NULL, TE_BRIGHT, 0);
 
3162
                                                insertkey(id, ID_TE, NULL, NULL, TE_CONTRA, 0);
2420
3163
                                        }
2421
3164
                                }
2422
3165
                        }
2423
3166
                }
2424
3167
                else if(G.buts->mainb==CONTEXT_OBJECT) {
2425
3168
                        ob= OBACT;
2426
 
                        if(ob && ob->type==OB_MESH) {
 
3169
                        if(ob) {
2427
3170
                                id= (ID *) (ob);
2428
3171
                                if(id) {
2429
 
                                        event= pupmenu("Insert Key %t|Surface Damping%x0|Random Damping%x1|Permeability%x2|Force Strength%x3|Force Falloff%x4");
2430
 
                                        if(event== -1) return;
 
3172
                                        if(ob->type==OB_MESH) 
 
3173
                                                event= pupmenu("Insert Key %t|Surface Damping%x0|Random Damping%x1|Permeability%x2|Force Strength%x3|Force Falloff%x4");
 
3174
                                        else
 
3175
                                                event= pupmenu("Insert Key %t|Force Strength%x3|Force Falloff%x4");
 
3176
                                        if(event == -1) return;
2431
3177
 
2432
3178
                                        if(event==0) {
2433
 
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_SDAMP);
 
3179
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_SDAMP, 0);
2434
3180
                                        }
2435
3181
                                        if(event==1) {
2436
 
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_RDAMP);
 
3182
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_RDAMP, 0);
2437
3183
                                        }
2438
3184
                                        if(event==2) {
2439
 
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_PERM);
 
3185
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_PERM, 0);
2440
3186
                                        }
2441
3187
                                        if(event==3) {
2442
 
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_FSTR);
 
3188
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_FSTR, 0);
2443
3189
                                        }
2444
3190
                                        if(event==4) {
2445
 
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_FFALL);
2446
 
                                        }
2447
 
 
 
3191
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_FFALL, 0);
 
3192
                                        }
 
3193
                                        if(event==5) {
 
3194
                                                insertkey(id, ID_OB, NULL, NULL, OB_PD_FMAXD, 0);
 
3195
                                        }
2448
3196
                                }
2449
3197
                        }
2450
3198
                }
2454
3202
                                id= G.buts->lockpoin;
2455
3203
                                if(id) {
2456
3204
                                        /* yafray: insert key extended with aperture and focal distance */
 
3205
                                        /* qdn: FocalDistance now enabled for Blender as wel, for use with defocus node */
2457
3206
                                        if (G.scene->r.renderer==R_INTERN)
2458
 
                                                event= pupmenu("Insert Key %t|Lens%x0|Clipping%x1");
 
3207
                                                event= pupmenu("Insert Key %t|Lens%x0|Clipping%x1|FocalDistance%x3|Viewplane Shift%x4");
2459
3208
                                        else
2460
3209
                                                event= pupmenu("Insert Key %t|Lens%x0|Clipping%x1|Aperture%x2|FocalDistance%x3");
2461
3210
                                        if(event== -1) return;
2462
3211
 
2463
3212
                                        if(event==0) {
2464
 
                                                insertkey(id, ID_CA, NULL, NULL, CAM_LENS);
 
3213
                                                insertkey(id, ID_CA, NULL, NULL, CAM_LENS, 0);
2465
3214
                                        }
2466
3215
                                        else if(event==1) {
2467
 
                                                insertkey(id, ID_CA, NULL, NULL, CAM_STA);
2468
 
                                                insertkey(id, ID_CA, NULL, NULL, CAM_END);
 
3216
                                                insertkey(id, ID_CA, NULL, NULL, CAM_STA, 0);
 
3217
                                                insertkey(id, ID_CA, NULL, NULL, CAM_END, 0);
2469
3218
                                        }
2470
3219
                                        else if(event==2) {
2471
 
                                                insertkey(id, ID_CA, NULL, NULL, CAM_YF_APERT);
 
3220
                                                insertkey(id, ID_CA, NULL, NULL, CAM_YF_APERT, 0);
2472
3221
                                        }
2473
3222
                                        else if(event==3) {
2474
 
                                                insertkey(id, ID_CA, NULL, NULL, CAM_YF_FDIST);
 
3223
                                                insertkey(id, ID_CA, NULL, NULL, CAM_YF_FDIST, 0);
 
3224
                                        }
 
3225
                                        else if(event==4) {
 
3226
                                                insertkey(id, ID_CA, NULL, NULL, CAM_SHIFT_X, 0);
 
3227
                                                insertkey(id, ID_CA, NULL, NULL, CAM_SHIFT_Y, 0);
2475
3228
                                        }
2476
3229
                                }
2477
3230
                        }
2484
3237
                                        if(event== -1) return;
2485
3238
 
2486
3239
                                        if(event==0) {
2487
 
                                                insertkey(id, ID_SO, NULL, NULL, SND_VOLUME);
 
3240
                                                insertkey(id, ID_SO, NULL, NULL, SND_VOLUME, 0);
2488
3241
                                        }
2489
3242
                                        if(event==1) {
2490
 
                                                insertkey(id, ID_SO, NULL, NULL, SND_PITCH);
 
3243
                                                insertkey(id, ID_SO, NULL, NULL, SND_PITCH, 0);
2491
3244
                                        }
2492
3245
                                        if(event==2) {
2493
 
                                                insertkey(id, ID_SO, NULL, NULL, SND_PANNING);
 
3246
                                                insertkey(id, ID_SO, NULL, NULL, SND_PANNING, 0);
2494
3247
                                        }
2495
3248
                                        if(event==3) {
2496
 
                                                insertkey(id, ID_SO, NULL, NULL, SND_ATTEN);
 
3249
                                                insertkey(id, ID_SO, NULL, NULL, SND_ATTEN, 0);
2497
3250
                                        }
2498
3251
                                }
2499
3252
                        }
2511
3264
                ob= OBACT;
2512
3265
 
2513
3266
                if (ob && (ob->flag & OB_POSEMODE)) {
2514
 
                        strcpy(menustr, "Insert Key%t|Loc%x0|Rot%x1|Scale%x2|LocRot%x3|LocRotScale%x4|Avail%x9|VisualLoc%x11|VisualRot%x12|VisualLocRot%x13");
 
3267
                        bPoseChannel *pchan;
 
3268
                        
 
3269
                        set_pose_keys(ob);  /* sets pchan->flag to POSE_KEY if bone selected, and clears if not */
 
3270
                        for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next)
 
3271
                                if (pchan->flag & POSE_KEY)
 
3272
                                        break;
 
3273
                        if(pchan==NULL) return;
 
3274
                        strcpy(menustr, "Insert Key%t|Loc%x0|Rot%x1|Scale%x2|LocRot%x3|LocRotScale%x4|Avail%x9|Needed%x15|VisualLoc%x11|VisualRot%x12|VisualLocRot%x13");
2515
3275
                }
2516
3276
                else {
2517
3277
                        base= FIRSTBASE;
2518
3278
                        while(base) {
2519
 
                                if TESTBASELIB(base) break;
 
3279
                                if (TESTBASELIB(base)) break;
2520
3280
                                base= base->next;
2521
3281
                        }
2522
3282
                        if(base==NULL) return;
2523
 
                        strcpy(menustr, "Insert Key%t|Loc%x0|Rot%x1|Scale%x2|LocRot%x3|LocRotScale%x4|Layer%x5|Avail%x9|VisualLoc%x11|VisualRot%x12|VisualLocRot%x13");
 
3283
                        strcpy(menustr, "Insert Key%t|Loc%x0|Rot%x1|Scale%x2|LocRot%x3|LocRotScale%x4|Layer%x5|Avail%x9|Needed%x15|VisualLoc%x11|VisualRot%x12|VisualLocRot%x13");
2524
3284
                }
2525
3285
 
2526
3286
                if(ob) {
2540
3300
 
2541
3301
                if (ob && (ob->flag & OB_POSEMODE)){
2542
3302
                        bPoseChannel *pchan;
2543
 
 
 
3303
                        short recalc_bonepaths= 0;
 
3304
                        
2544
3305
                        if (ob->action && ob->action->id.lib) {
2545
3306
                                error ("Can't key libactions");
2546
3307
                                return;
2547
3308
                        }
2548
 
 
2549
 
                        set_pose_keys(ob);  // sets pchan->flag to POSE_KEY if bone selected
 
3309
                        
2550
3310
                        id= &ob->id;
2551
3311
                        for (pchan=ob->pose->chanbase.first; pchan; pchan=pchan->next) {
2552
 
                                if (pchan->flag & POSE_KEY){
 
3312
                                if (pchan->flag & POSE_KEY) {
 
3313
                                        /* insert relevant keyframes */
2553
3314
                                        if(event==0 || event==3 ||event==4) {
2554
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X);
2555
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y);
2556
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z);
 
3315
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, 0);
 
3316
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, 0);
 
3317
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, 0);
2557
3318
                                        }
2558
 
                                        if(event==1 || event==3 ||event==4) {
2559
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X);
2560
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y);
2561
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z);
2562
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W);
 
3319
                                        if(event==1 || event==3 || event==4) {
 
3320
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, 0);
 
3321
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, 0);
 
3322
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, 0);
 
3323
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, 0);
2563
3324
                                        }
2564
3325
                                        if(event==2 || event==4) {
2565
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_X);
2566
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Y);
2567
 
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Z);
 
3326
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_X, 0);
 
3327
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Y, 0);
 
3328
                                                insertkey(id, ID_PO, pchan->name, NULL, AC_SIZE_Z, 0);
2568
3329
                                        }
2569
3330
                                        if (event==9 && ob->action) {
2570
3331
                                                bActionChannel *achan;
2571
 
 
 
3332
                                                
2572
3333
                                                for (achan = ob->action->chanbase.first; achan; achan=achan->next){
2573
3334
                                                        if (achan->ipo && !strcmp (achan->name, pchan->name)){
2574
3335
                                                                for (icu = achan->ipo->curve.first; icu; icu=icu->next){
2575
 
                                                                        insertkey(id, ID_PO, achan->name, NULL, icu->adrcode);
 
3336
                                                                        insertkey(id, ID_PO, achan->name, NULL, icu->adrcode, 0);
2576
3337
                                                                }
2577
3338
                                                                break;
2578
3339
                                                        }
2579
3340
                                                }
2580
3341
                                        }
2581
3342
                                        if(event==11 || event==13) {
2582
 
                                                float obSpaceBoneMat[4][4]; 
2583
 
                                                
2584
 
                                                bone2objectspace(obSpaceBoneMat, pchan->pose_mat, pchan->bone->arm_mat);
2585
 
                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, obSpaceBoneMat[3][0]);
2586
 
                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, obSpaceBoneMat[3][1]);
2587
 
                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, obSpaceBoneMat[3][2]);
 
3343
                                                int matok=0; 
 
3344
                                                /* check one to make sure we're not trying to set visual loc keys on
 
3345
                                                        bones inside of a chain, which only leads to tears. */
 
3346
                                                matok=  insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_X);
 
3347
                                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y);
 
3348
                                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z);
 
3349
                                                
 
3350
                                                if (matok == 0) {
 
3351
                                                        insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_X, 0);
 
3352
                                                        insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Y, 0);
 
3353
                                                        insertkey(id, ID_PO, pchan->name, NULL, AC_LOC_Z, 0);
 
3354
                                                }
2588
3355
                                        }
2589
3356
                                        if(event==12 || event==13) {
2590
 
                                                float obSpaceBoneMat[4][4];
2591
 
                                                float localQuat[4];
2592
 
                                                
2593
 
                                                bone2objectspace(obSpaceBoneMat, pchan->pose_mat, pchan->bone->arm_mat);
2594
 
                                                Mat4ToQuat(obSpaceBoneMat, localQuat);
2595
 
                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, localQuat[0]);
2596
 
                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, localQuat[1]);
2597
 
                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, localQuat[2]);
2598
 
                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, localQuat[2]);
 
3357
                                                int matok=0; 
 
3358
                                                /* check one to make sure we're not trying to set visual rot keys on
 
3359
                                                        bones inside of a chain, which only leads to tears. */
 
3360
                                                matok=  insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W);
 
3361
                                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X);
 
3362
                                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y);
 
3363
                                                                insertmatrixkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z);
 
3364
                                                
 
3365
                                                if (matok == 0) {
 
3366
                                                        insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_W, 0);
 
3367
                                                        insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_X, 0);
 
3368
                                                        insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Y, 0);
 
3369
                                                        insertkey(id, ID_PO, pchan->name, NULL, AC_QUAT_Z, 0);
 
3370
                                                }
2599
3371
                                        }
 
3372
                                        if (event==15 && ob->action) {
 
3373
                                                bActionChannel *achan;
 
3374
                                                
 
3375
                                                for (achan = ob->action->chanbase.first; achan; achan=achan->next){
 
3376
                                                        if (achan->ipo && !strcmp (achan->name, pchan->name)){
 
3377
                                                                for (icu = achan->ipo->curve.first; icu; icu=icu->next){
 
3378
                                                                        insertkey_smarter(id, ID_PO, achan->name, NULL, icu->adrcode);
 
3379
                                                                }
 
3380
                                                                break;
 
3381
                                                        }
 
3382
                                                }
 
3383
                                        }
 
3384
                                        
 
3385
                                        /* clear unkeyed flag (it doesn't matter if it's set or not) */
 
3386
                                        if (pchan->bone)
 
3387
                                                pchan->bone->flag &= ~BONE_UNKEYED;
 
3388
                                                
 
3389
                                        /* check if bone has a path */
 
3390
                                        if (pchan->path)
 
3391
                                                recalc_bonepaths = 1;
2600
3392
                                }
2601
3393
                        }
 
3394
                        
 
3395
                        /* recalculate ipo handles, etc. */
2602
3396
                        if(ob->action)
2603
3397
                                remake_action_ipos(ob->action);
2604
 
 
 
3398
                                
 
3399
                        /* recalculate bone-paths on adding new keyframe? */
 
3400
                        // TODO: currently, there is no setting to turn this on/off globally
 
3401
                        if (recalc_bonepaths)
 
3402
                                pose_recalculate_paths(ob);
 
3403
                        
 
3404
                        
2605
3405
                        allqueue(REDRAWIPO, 0);
2606
3406
                        allqueue(REDRAWACTION, 0);
2607
3407
                        allqueue(REDRAWNLA, 0);
2609
3409
                else {
2610
3410
                        base= FIRSTBASE;
2611
3411
                        while(base) {
2612
 
                                if TESTBASELIB(base) {
 
3412
                                if (TESTBASELIB(base)) {
2613
3413
                                        char *actname= NULL;
2614
3414
 
2615
3415
                                        id= (ID *)(base->object);
2616
3416
 
2617
 
                                        if(ob->ipoflag & OB_ACTION_OB)
 
3417
                                        if(base->object->ipoflag & OB_ACTION_OB)
2618
3418
                                                actname= "Object";
2619
3419
 
2620
3420
                                        /* all curves in ipo deselect */
2621
 
                                        if(base->object->ipo) {
2622
 
                                                icu= base->object->ipo->curve.first;
 
3421
                                        if(base->object->ipo || base->object->action) {
 
3422
                                                if (base->object->ipo) {
 
3423
                                                        icu= base->object->ipo->curve.first;
 
3424
                                                }
 
3425
                                                else {
 
3426
                                                        bActionChannel *achan;
 
3427
                                                        achan= get_action_channel(base->object->action, actname);
 
3428
                                                        
 
3429
                                                        if (achan && achan->ipo)
 
3430
                                                                icu= achan->ipo->curve.first;
 
3431
                                                        else
 
3432
                                                                icu= NULL;
 
3433
                                                }
 
3434
                                                
2623
3435
                                                while(icu) {
2624
3436
                                                        icu->flag &= ~IPO_SELECT;
2625
 
                                                        if(event==9) insertkey(id, ID_OB, actname, NULL, icu->adrcode);
 
3437
                                                        
 
3438
                                                        switch (event) {
 
3439
                                                                case 9: 
 
3440
                                                                        insertkey(id, ID_OB, actname, NULL, icu->adrcode, 0);
 
3441
                                                                        break;
 
3442
                                                                case 15:
 
3443
                                                                        insertkey_smarter(id, ID_OB, actname, NULL, icu->adrcode);
 
3444
                                                                        break;
 
3445
                                                        }
2626
3446
                                                        icu= icu->next;
2627
3447
                                                }
2628
3448
                                        }
2629
3449
 
2630
3450
                                        if(event==0 || event==3 ||event==4) {
2631
 
                                                insertkey(id, ID_OB, actname, NULL, OB_LOC_X);
2632
 
                                                insertkey(id, ID_OB, actname, NULL, OB_LOC_Y);
2633
 
                                                insertkey(id, ID_OB, actname, NULL, OB_LOC_Z);
 
3451
                                                insertkey(id, ID_OB, actname, NULL, OB_LOC_X, 0);
 
3452
                                                insertkey(id, ID_OB, actname, NULL, OB_LOC_Y, 0);
 
3453
                                                insertkey(id, ID_OB, actname, NULL, OB_LOC_Z, 0);
2634
3454
                                        }
2635
3455
                                        if(event==1 || event==3 ||event==4) {
2636
 
                                                insertkey(id, ID_OB, actname, NULL, OB_ROT_X);
2637
 
                                                insertkey(id, ID_OB, actname, NULL, OB_ROT_Y);
2638
 
                                                insertkey(id, ID_OB, actname, NULL, OB_ROT_Z);
 
3456
                                                insertkey(id, ID_OB, actname, NULL, OB_ROT_X, 0);
 
3457
                                                insertkey(id, ID_OB, actname, NULL, OB_ROT_Y, 0);
 
3458
                                                insertkey(id, ID_OB, actname, NULL, OB_ROT_Z, 0);
2639
3459
                                        }
2640
3460
                                        if(event==2 || event==4) {
2641
 
                                                insertkey(id, ID_OB, actname, NULL, OB_SIZE_X);
2642
 
                                                insertkey(id, ID_OB, actname, NULL, OB_SIZE_Y);
2643
 
                                                insertkey(id, ID_OB, actname, NULL, OB_SIZE_Z);
 
3461
                                                insertkey(id, ID_OB, actname, NULL, OB_SIZE_X, 0);
 
3462
                                                insertkey(id, ID_OB, actname, NULL, OB_SIZE_Y, 0);
 
3463
                                                insertkey(id, ID_OB, actname, NULL, OB_SIZE_Z, 0);
2644
3464
                                        }
2645
3465
                                        if(event==5) {
2646
3466
                                                /* remove localview  */
2647
3467
                                                tlay= base->object->lay;
2648
3468
                                                base->object->lay &= 0xFFFFFF;
2649
 
                                                insertkey(id, ID_OB, actname, NULL, OB_LAY);
 
3469
                                                insertkey(id, ID_OB, actname, NULL, OB_LAY, 0);
2650
3470
                                                base->object->lay= tlay;
2651
3471
                                        }
2652
3472
                                        if(event==11 || event==13) {
2653
 
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_X, ob->obmat[3][0]);
2654
 
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Y, ob->obmat[3][1]);
2655
 
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Z, ob->obmat[3][2]);
 
3473
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_X);
 
3474
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Y);
 
3475
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_LOC_Z);
2656
3476
                                        }
2657
3477
                                        if(event==12 || event==13) {
2658
 
                                                float eul[3];
2659
 
                                                float rotMat[3][3];
2660
 
                                                
2661
 
                                                Mat3CpyMat4(rotMat, ob->obmat);
2662
 
                                                Mat3ToEul(rotMat, eul);
2663
 
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_X, eul[0]*(5.72958));
2664
 
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Y, eul[1]*(5.72958));
2665
 
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Z, eul[2]*(5.72958));
 
3478
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_X);
 
3479
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Y);
 
3480
                                                insertmatrixkey(id, ID_OB, actname, NULL, OB_ROT_Z);
2666
3481
                                        }
2667
3482
                                        base->object->recalc |= OB_RECALC_OB;
2668
3483
                                }
2674
3489
                else if(event==1) BIF_undo_push("Insert Rot Key");
2675
3490
                else if(event==2) BIF_undo_push("Insert Scale Key");
2676
3491
                else if(event==3) BIF_undo_push("Insert LocRot Key");
2677
 
                else if(event==4) BIF_undo_push("Insert LocRotSca;e Key");
 
3492
                else if(event==4) BIF_undo_push("Insert LocRotScale Key");
2678
3493
                else if(event==5) BIF_undo_push("Insert Layer Key");
2679
3494
                else if(event==7) BIF_undo_push("Insert Vertex Key");
2680
3495
                else if(event==9) BIF_undo_push("Insert Avail Key");
 
3496
                else if(event==11) BIF_undo_push("Insert VisualLoc Key");
 
3497
                else if(event==12) BIF_undo_push("Insert VisualRot Key");
 
3498
                else if(event==13) BIF_undo_push("Insert VisualLocRot Key");
 
3499
                else if(event==15) BIF_undo_push("Insert Needed Key");
2681
3500
                
2682
 
                DAG_scene_flush_update(G.scene, screen_view3d_layers());
 
3501
                DAG_scene_flush_update(G.scene, screen_view3d_layers(), 0);
2683
3502
                
2684
3503
                allspace(REMAKEIPO, 0);
2685
3504
                allqueue(REDRAWIPO, 0);
2714
3533
                                b= icu->totvert;
2715
3534
                                bezt= icu->bezt;
2716
3535
                                while(b--) {
2717
 
                                        if(bezt->f2 & 1) tot++;
 
3536
                                        if(bezt->f2 & SELECT) tot++;
2718
3537
                                        bezt++;
2719
3538
                                }
2720
3539
                                
2725
3544
                                        b= icu->totvert-tot;
2726
3545
                                        while(b--) {
2727
3546
                                                *beztn= *bezt;
2728
 
                                                if(bezt->f2 & 1) {
 
3547
                                                if(bezt->f2 & SELECT) {
2729
3548
                                                        beztn->f1= beztn->f2= beztn->f3= 0;
2730
3549
                                                        beztn++;
2731
3550
                                                        *beztn= *bezt;
2779
3598
                                while(b--) {
2780
3599
                                        
2781
3600
                                        /* can we remove? */
2782
 
                                        if(mode==2 || (bezt->f2 & 1)) {
 
3601
                                        if(mode==2 || (bezt->f2 & SELECT)) {
2783
3602
                                        
2784
3603
                                                /* are the points different? */
2785
3604
                                                if( fabs( bezt->vec[1][0]-newb->vec[1][0] ) > 0.9 ) {
2842
3661
        deselectall_editipo();
2843
3662
}
2844
3663
 
 
3664
 
 
3665
void clean_ipo(void) 
 
3666
{
 
3667
        EditIpo *ei;
 
3668
        short ok;
 
3669
        int b;
 
3670
        
 
3671
        ok= fbutton(&G.scene->toolsettings->clean_thresh, 
 
3672
                                0.0000001f, 1.0, 0.001, 0.1,
 
3673
                                "Threshold");
 
3674
        if (!ok) return;
 
3675
        
 
3676
        get_status_editipo();
 
3677
 
 
3678
        ei= G.sipo->editipo;
 
3679
        for(b=0; b<G.sipo->totipo; b++, ei++) {
 
3680
                if (ISPOIN3(ei, flag & IPO_VISIBLE, icu, icu->bezt)) {
 
3681
                
 
3682
                        ok= 0;
 
3683
                        if(G.sipo->showkey) ok= 1;
 
3684
                        else if(totipo_vert && (ei->flag & IPO_EDIT)) ok= 2;
 
3685
                        else if(totipo_vert==0 && (ei->flag & IPO_SELECT)) ok= 3;
 
3686
                        
 
3687
                        if(ok) {
 
3688
                                /* only clean if ok */
 
3689
                                clean_ipo_curve(ei->icu);
 
3690
                        }
 
3691
                }
 
3692
        }
 
3693
        
 
3694
        editipo_changed(G.sipo, 1);
 
3695
        BIF_undo_push("Clean IPO");
 
3696
}
 
3697
 
 
3698
void clean_ipo_curve(IpoCurve *icu)
 
3699
{
 
3700
        BezTriple *old_bezts, *bezt, *beztn;
 
3701
        BezTriple *lastb;
 
3702
        int totCount, i;
 
3703
        float thresh;
 
3704
        
 
3705
        /* check if any points  */
 
3706
        if (icu == NULL || icu->totvert <= 1) 
 
3707
                return;
 
3708
        
 
3709
        /* get threshold for match-testing */
 
3710
        thresh= G.scene->toolsettings->clean_thresh;
 
3711
        
 
3712
        /* make a copy of the old BezTriples, and clear IPO curve */
 
3713
        old_bezts = icu->bezt;
 
3714
        totCount = icu->totvert;        
 
3715
        icu->bezt = NULL;
 
3716
        icu->totvert = 0;
 
3717
        
 
3718
        /* now insert first keyframe, as it should be ok */
 
3719
        bezt = old_bezts;
 
3720
        insert_vert_icu(icu, bezt->vec[1][0], bezt->vec[1][1], 0);
 
3721
        
 
3722
        /* Loop through BezTriples, comparing them. Skip any that do 
 
3723
         * not fit the criteria for "ok" points.
 
3724
         */
 
3725
        for (i=1; i<totCount; i++) {    
 
3726
                float prev[2], cur[2], next[2];
 
3727
                
 
3728
                /* get BezTriples and their values */
 
3729
                if (i < (totCount - 1)) {
 
3730
                        beztn = (old_bezts + (i+1));
 
3731
                        next[0]= beztn->vec[1][0]; next[1]= beztn->vec[1][1];
 
3732
                }
 
3733
                else {
 
3734
                        beztn = NULL;
 
3735
                        next[0] = next[1] = 0.0f;
 
3736
                }
 
3737
                lastb= (icu->bezt + (icu->totvert - 1));
 
3738
                bezt= (old_bezts + i);
 
3739
                
 
3740
                /* get references for quicker access */
 
3741
                prev[0] = lastb->vec[1][0]; prev[1] = lastb->vec[1][1];
 
3742
                cur[0] = bezt->vec[1][0]; cur[1] = bezt->vec[1][1];
 
3743
                
 
3744
                /* check if current bezt occurs at same time as last ok */
 
3745
                if (IS_EQT(cur[0], prev[0], thresh)) {
 
3746
                        /* If there is a next beztriple, and if occurs at the same time, only insert 
 
3747
                         * if there is a considerable distance between the points, and also if the 
 
3748
                         * current is further away than the next one is to the previous.
 
3749
                         */
 
3750
                        if (beztn && (IS_EQT(cur[0], next[0], thresh)) && 
 
3751
                                (IS_EQT(next[1], prev[1], thresh)==0)) 
 
3752
                        {
 
3753
                                /* only add if current is further away from previous */
 
3754
                                if (cur[1] > next[1]) {
 
3755
                                        if (IS_EQT(cur[1], prev[1], thresh) == 0) {
 
3756
                                                /* add new keyframe */
 
3757
                                                insert_vert_icu(icu, cur[0], cur[1], 0);
 
3758
                                        }
 
3759
                                }
 
3760
                        }
 
3761
                        else {
 
3762
                                /* only add if values are a considerable distance apart */
 
3763
                                if (IS_EQT(cur[1], prev[1], thresh) == 0) {
 
3764
                                        /* add new keyframe */
 
3765
                                        insert_vert_icu(icu, cur[0], cur[1], 0);
 
3766
                                }
 
3767
                        }
 
3768
                }
 
3769
                else {
 
3770
                        /* checks required are dependent on whether this is last keyframe or not */
 
3771
                        if (beztn) {
 
3772
                                /* does current have same value as previous and next? */
 
3773
                                if (IS_EQT(cur[1], prev[1], thresh) == 0) {
 
3774
                                        /* add new keyframe*/
 
3775
                                        insert_vert_icu(icu, cur[0], cur[1], 0);
 
3776
                                }
 
3777
                                else if (IS_EQT(cur[1], next[1], thresh) == 0) {
 
3778
                                        /* add new keyframe */
 
3779
                                        insert_vert_icu(icu, cur[0], cur[1], 0);
 
3780
                                }
 
3781
                        }
 
3782
                        else {  
 
3783
                                /* add if value doesn't equal that of previous */
 
3784
                                if (IS_EQT(cur[1], prev[1], thresh) == 0) {
 
3785
                                        /* add new keyframe */
 
3786
                                        insert_vert_icu(icu, cur[0], cur[1], 0);
 
3787
                                }
 
3788
                        }
 
3789
                }
 
3790
        }
 
3791
        
 
3792
        /* now free the memory used by the old BezTriples */
 
3793
        if (old_bezts)
 
3794
                MEM_freeN(old_bezts);
 
3795
}
 
3796
 
 
3797
 
 
3798
/* temp struct used for smooth_ipo */
 
3799
typedef struct tSmooth_Bezt {
 
3800
        float *h1, *h2, *h3;    /* bezt->vec[0,1,2][1] */
 
3801
} tSmooth_Bezt;
 
3802
 
 
3803
void smooth_ipo(void)
 
3804
{
 
3805
        EditIpo *ei;
 
3806
        short ok;
 
3807
        int b;
 
3808
        
 
3809
        get_status_editipo();
 
3810
 
 
3811
        ei= G.sipo->editipo;
 
3812
        for(b=0; b<G.sipo->totipo; b++, ei++) {
 
3813
                if (ISPOIN3(ei, flag & IPO_VISIBLE, icu, icu->bezt)) {
 
3814
                        ok= 0;
 
3815
                        if(G.sipo->showkey) ok= 1;
 
3816
                        else if(totipo_vert && (ei->flag & IPO_EDIT)) ok= 2;
 
3817
                        else if(totipo_vert==0 && (ei->flag & IPO_SELECT)) ok= 3;
 
3818
                        
 
3819
                        if(ok) {
 
3820
                                IpoCurve *icu= ei->icu;
 
3821
                                BezTriple *bezt;
 
3822
                                int i, x, totSel = 0;
 
3823
                                
 
3824
                                /* check if enough points */
 
3825
                                if (icu->totvert >= 3) {
 
3826
                                        /* first loop through - count how many verts are selected, and fix up handles */
 
3827
                                        bezt= icu->bezt;
 
3828
                                        for (i=0; i < icu->totvert; i++, bezt++) {                                              
 
3829
                                                if (BEZSELECTED(bezt)) {                                                        
 
3830
                                                        /* line point's handles up with point's vertical position */
 
3831
                                                        bezt->vec[0][1]= bezt->vec[2][1]= bezt->vec[1][1];
 
3832
                                                        if ((bezt->h1==HD_AUTO) || (bezt->h1==HD_VECT)) bezt->h1= HD_ALIGN;
 
3833
                                                        if ((bezt->h2==HD_AUTO) || (bezt->h2==HD_VECT)) bezt->h2= HD_ALIGN;
 
3834
                                                        
 
3835
                                                        /* add value to total */
 
3836
                                                        totSel++;
 
3837
                                                }
 
3838
                                        }
 
3839
                                        
 
3840
                                        /* if any points were selected, allocate tSmooth_Bezt points to work on */
 
3841
                                        if (totSel >= 3) {
 
3842
                                                tSmooth_Bezt *tarray, *tsb;
 
3843
                                                
 
3844
                                                /* allocate memory in one go */
 
3845
                                                tsb= tarray= MEM_callocN(totSel*sizeof(tSmooth_Bezt), "tSmooth_Bezt Array");
 
3846
                                                
 
3847
                                                /* populate tarray with data of selected points */
 
3848
                                                bezt= icu->bezt;
 
3849
                                                for (i=0, x=0; (i < icu->totvert) && (x < totSel); i++, bezt++) {
 
3850
                                                        if (BEZSELECTED(bezt)) {
 
3851
                                                                /* tsb simply needs pointer to vec, and index */
 
3852
                                                                tsb->h1 = &bezt->vec[0][1];
 
3853
                                                                tsb->h2 = &bezt->vec[1][1];
 
3854
                                                                tsb->h3 = &bezt->vec[2][1];
 
3855
                                                                
 
3856
                                                                /* advance to the next tsb to populate */
 
3857
                                                                if (x < totSel- 1) 
 
3858
                                                                        tsb++;
 
3859
                                                                else
 
3860
                                                                        break;
 
3861
                                                        }
 
3862
                                                }
 
3863
                                                
 
3864
                                                /* calculate the new smoothed ipo's with weighted averages:
 
3865
                                                 *      - this is done with two passes
 
3866
                                                 *      - uses 5 points for each operation (which stores in the relevant handles)
 
3867
                                                 *      -       previous: w/a ratio = 3:5:2:1:1
 
3868
                                                 *      -       next: w/a ratio = 1:1:2:5:3
 
3869
                                                 */
 
3870
                                                
 
3871
                                                /* round 1: calculate previous and next */ 
 
3872
                                                tsb= tarray;
 
3873
                                                for (i=0; i < totSel; i++, tsb++) {
 
3874
                                                        /* don't touch end points (otherwise, curves slowly explode) */
 
3875
                                                        if (ELEM(i, 0, (totSel-1)) == 0) {
 
3876
                                                                tSmooth_Bezt *tP1 = tsb - 1;
 
3877
                                                                tSmooth_Bezt *tP2 = (i-2 > 0) ? (tsb - 2) : (NULL);
 
3878
                                                                tSmooth_Bezt *tN1 = tsb + 1;
 
3879
                                                                tSmooth_Bezt *tN2 = (i+2 < totSel) ? (tsb + 2) : (NULL);
 
3880
                                                                
 
3881
                                                                float p1 = *tP1->h2;
 
3882
                                                                float p2 = (tP2) ? (*tP2->h2) : (*tP1->h2);
 
3883
                                                                float c1 = *tsb->h2;
 
3884
                                                                float n1 = *tN1->h2;
 
3885
                                                                float n2 = (tN2) ? (*tN2->h2) : (*tN1->h2);
 
3886
                                                                
 
3887
                                                                /* calculate previous and next */
 
3888
                                                                *tsb->h1= (3*p2 + 5*p1 + 2*c1 + n1 + n2) / 12;
 
3889
                                                                *tsb->h3= (p2 + p1 + 2*c1 + 5*n1 + 3*n2) / 12;
 
3890
                                                        }
 
3891
                                                }
 
3892
                                                
 
3893
                                                /* round 2: calculate new values and reset handles */
 
3894
                                                tsb= tarray;
 
3895
                                                for (i=0; i < totSel; i++, tsb++) {
 
3896
                                                        /* calculate new position by averaging handles */
 
3897
                                                        *tsb->h2 = (*tsb->h1 + *tsb->h3) / 2;
 
3898
                                                        
 
3899
                                                        /* reset handles now */
 
3900
                                                        *tsb->h1 = *tsb->h2;
 
3901
                                                        *tsb->h3 = *tsb->h2;
 
3902
                                                }
 
3903
                                                
 
3904
                                                /* free memory required for tarray */
 
3905
                                                MEM_freeN(tarray);
 
3906
                                        }
 
3907
                                }
 
3908
                                
 
3909
                                /* recalculate handles */
 
3910
                                calchandles_ipocurve(icu);
 
3911
                        }
 
3912
                }
 
3913
        }
 
3914
        
 
3915
        editipo_changed(G.sipo, 1);
 
3916
        BIF_undo_push("Smooth IPO");
 
3917
}
 
3918
 
2845
3919
void join_ipo_menu(void)
2846
3920
{
2847
3921
        int mode = 0;
2885
3959
                                b= icu->totvert;
2886
3960
                                bezt= icu->bezt;
2887
3961
                                while(b--) {
2888
 
                                        if(bezt->f2 & 1) tot++;
 
3962
                                        if(bezt->f2 & SELECT) tot++;
2889
3963
                                        bezt++;
2890
3964
                                }
2891
3965
                                
2902
3976
                                        b= icu->totvert+tot+1;
2903
3977
                                        while(b--) {
2904
3978
                                                
2905
 
                                                if(bezt->f2 & 1) {
 
3979
                                                if(bezt->f2 & SELECT) {
2906
3980
                                                        if(tot==0) *newb= *bezt;
2907
3981
                                                        else {
2908
3982
                                                                VecAddf(newb->vec[0], newb->vec[0], bezt->vec[0]);
2999
4073
         */
3000
4074
         
3001
4075
        get_status_editipo();
 
4076
        
 
4077
        /* map ipo-points for editing if scaled ipo */
 
4078
        if (NLA_IPO_SCALED) {
 
4079
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 0, 0);
 
4080
        }
3002
4081
 
3003
4082
        ei= G.sipo->editipo;
3004
4083
        for(b=0; b<G.sipo->totipo; b++, ei++) {
3015
4094
                                while(a--) {
3016
4095
                                        ok= 0;
3017
4096
                                        if(totipo_vert) {
3018
 
                                                 if(bezt->f2 & 1) ok= 1;
 
4097
                                                if(bezt->f2 & SELECT) ok= 1;
3019
4098
                                        }
3020
4099
                                        else ok= 1;
3021
4100
                                        
3067
4146
                        }
3068
4147
                }
3069
4148
        }
 
4149
        
 
4150
        /* undo mapping of ipo-points for editing if scaled ipo */
 
4151
        if (NLA_IPO_SCALED) {
 
4152
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 1, 0);
 
4153
        }
 
4154
        
3070
4155
        editipo_changed(G.sipo, 1);
3071
4156
        BIF_undo_push("Snap Ipo");
3072
4157
}
3073
4158
 
 
4159
void ipo_mirror_menu(void)
 
4160
{
 
4161
        int mode = 0;
 
4162
        mode= pupmenu("Mirror Over%t|Current Frame%x1|Vertical Axis%x2|Horizontal Axis%x3");
 
4163
        
 
4164
        if (mode == -1) return;
 
4165
        
 
4166
        ipo_mirror(mode);
 
4167
}
 
4168
 
 
4169
void ipo_mirror(short mode)
 
4170
{
 
4171
        EditIpo *ei;
 
4172
        BezTriple *bezt;
 
4173
        
 
4174
        int a, b;
 
4175
        short ok, ok2, i;
 
4176
        float diff;
 
4177
        
 
4178
        /* what's this for? */
 
4179
        get_status_editipo();
 
4180
 
 
4181
        /* get edit ipo */
 
4182
        ei= G.sipo->editipo;
 
4183
        if (!ei) return;
 
4184
        
 
4185
        /* map ipo-points for editing if scaled ipo */
 
4186
        if (NLA_IPO_SCALED) {
 
4187
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 0, 0);
 
4188
        }
 
4189
        
 
4190
        /* look throught ipo curves */
 
4191
        for(b=0; b<G.sipo->totipo; b++, ei++) {
 
4192
                if (ISPOIN3(ei, flag & IPO_VISIBLE, icu, icu->bezt)) {
 
4193
                
 
4194
                        ok2= 0;
 
4195
                        if(G.sipo->showkey) ok2= 1;
 
4196
                        else if(totipo_vert && (ei->flag & IPO_EDIT)) ok2= 2;
 
4197
                        else if(totipo_vert==0 && (ei->flag & IPO_SELECT)) ok2= 3;
 
4198
                        
 
4199
                        if(ok2) {
 
4200
                                bezt= ei->icu->bezt;
 
4201
                                a= ei->icu->totvert;
 
4202
                                
 
4203
                                /* loop through beztriples, mirroring them */
 
4204
                                while(a--) {
 
4205
                                        ok= 0;
 
4206
                                        if(totipo_vert) {
 
4207
                                                if(bezt->f2 & SELECT) ok= 1;
 
4208
                                        }
 
4209
                                        else ok= 1;
 
4210
                                        
 
4211
                                        if(ok) {
 
4212
                                                switch (mode) {
 
4213
                                                        case 1: /* mirror over current frame */
 
4214
                                                        {
 
4215
                                                                for (i=0; i<3; i++) {
 
4216
                                                                        diff= ((float)CFRA - bezt->vec[i][0]);
 
4217
                                                                        bezt->vec[i][0]= ((float)CFRA + diff);
 
4218
                                                                }
 
4219
                                                        }
 
4220
                                                                break;
 
4221
                                                        case 2: /* mirror over vertical axis (frame 0) */
 
4222
                                                        {
 
4223
                                                                for (i=0; i<3; i++) {
 
4224
                                                                        diff= (0.0f - bezt->vec[i][0]);
 
4225
                                                                        bezt->vec[i][0]= (0.0f + diff);
 
4226
                                                                }
 
4227
                                                        }
 
4228
                                                                break;
 
4229
                                                        case 3: /* mirror over horizontal axis */
 
4230
                                                        {
 
4231
                                                                for (i=0; i<3; i++) {
 
4232
                                                                        diff= (0.0f - bezt->vec[i][1]);
 
4233
                                                                        bezt->vec[i][1]= (0.0f + diff);
 
4234
                                                                }
 
4235
                                                        }
 
4236
                                                                break;
 
4237
                                                }
 
4238
                                        }
 
4239
                                        
 
4240
                                        bezt++;
 
4241
                                }
 
4242
                                
 
4243
                                /* sort out order and handles */
 
4244
                                sort_time_ipocurve(ei->icu);
 
4245
                                calchandles_ipocurve(ei->icu);
 
4246
                        }
 
4247
                }
 
4248
        }
 
4249
        
 
4250
        /* undo mapping of ipo-points for editing if scaled ipo */
 
4251
        if (NLA_IPO_SCALED) {
 
4252
                actstrip_map_ipo_keys(OBACT, G.sipo->ipo, 1, 0);
 
4253
        }
 
4254
        
 
4255
        /* cleanup and undo push */
 
4256
        editipo_changed(G.sipo, 1);
 
4257
        BIF_undo_push("Mirror Ipo");
 
4258
}
 
4259
 
3074
4260
/*
3075
4261
 * When deleting an IPO curve from Python, check if the Ipo is being
3076
4262
 * edited and if so clear the pointer to the old curve.
3091
4277
        }
3092
4278
}
3093
4279
 
3094
 
void del_ipo(void)
 
4280
void del_ipo(int need_check)
3095
4281
{
3096
4282
        EditIpo *ei;
3097
4283
        BezTriple *bezt, *bezt1;
3102
4288
        if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
3103
4289
        
3104
4290
        if(totipo_edit==0 && totipo_sel==0 && totipo_vertsel==0) {
3105
 
                if(okee("Erase selected keys"))
3106
 
                   delete_key(OBACT);
 
4291
                if (need_check) {
 
4292
                        if(okee("Erase selected keys"))
 
4293
                           delete_key(OBACT);
 
4294
                }
 
4295
                else 
 
4296
                        delete_key(OBACT);
3107
4297
                return;
3108
4298
        }
3109
4299
        
3110
 
        if( okee("Erase selected")==0 ) return;
 
4300
        if (need_check)
 
4301
                if( okee("Erase selected")==0 ) return;
3111
4302
 
3112
4303
        // first round, can we delete entire parts? 
3113
4304
        ei= G.sipo->editipo;
3171
4362
                                        bezt= ei->icu->bezt;
3172
4363
                                        for(a=0; a<ei->icu->totvert; a++) {
3173
4364
                                                if( BEZSELECTED(bezt) ) {
3174
 
                                                        memcpy(bezt, bezt+1, (ei->icu->totvert-a-1)*sizeof(BezTriple));
 
4365
                                                        memmove(bezt, bezt+1, (ei->icu->totvert-a-1)*sizeof(BezTriple));
3175
4366
                                                        ei->icu->totvert--;
3176
4367
                                                        a--;
3177
4368
                                                        event= 1;
3197
4388
        
3198
4389
        get_status_editipo();   /* count again */
3199
4390
        check_active_editipo();
 
4391
        editipo_changed(G.sipo, 1);
3200
4392
        
3201
4393
        BIF_undo_push("Delete Ipo");
3202
4394
        allqueue(REDRAWNLA, 0);
3255
4447
{
3256
4448
        EditIpo *ei;
3257
4449
        IpoCurve *icu;
3258
 
        int a, ok;
3259
 
        
3260
 
        if(G.sipo->showkey) return;
3261
 
        
3262
 
        if(totipocopybuf==0) return;
3263
 
        if(G.sipo->ipo==0) return;
3264
 
        if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
 
4450
        int a;
 
4451
        
 
4452
        if (G.sipo->showkey) return;
 
4453
        
 
4454
        if (totipocopybuf==0) return;
 
4455
        if (G.sipo->ipo==0) return;
 
4456
        if (G.sipo->ipo && G.sipo->ipo->id.lib) return;
3265
4457
 
3266
4458
        get_status_editipo();
3267
4459
        
3268
 
        if(totipo_vis==0) {
 
4460
        if (totipo_vis==0) {
3269
4461
                error("No visible channels");
 
4462
                return;
3270
4463
        }
3271
 
        else if(totipo_vis!=totipocopybuf && totipo_sel!=totipocopybuf) {
 
4464
        else if (totipo_vis!=totipocopybuf && totipo_sel!=totipocopybuf) {
3272
4465
                error("Incompatible paste");
 
4466
                return;
3273
4467
        }
3274
 
        else {
3275
 
                /* prevent problems: splines visible that are not selected */
3276
 
                if(totipo_vis==totipo_sel) totipo_vis= 0;
3277
 
                
3278
 
                icu= ipocopybuf.first;
3279
 
                if(icu==0) return;
3280
 
 
3281
 
                ei= G.sipo->editipo;
3282
 
                for(a=0; a<G.sipo->totipo; a++, ei++) {
3283
 
                        if(ei->flag & IPO_VISIBLE) {
3284
 
                                ok= 0;
3285
 
                                if(totipo_vis==totipocopybuf) ok= 1;
3286
 
                                if(totipo_sel==totipocopybuf && (ei->flag & IPO_SELECT)) ok= 1;
3287
 
        
3288
 
                                if(ok) {
 
4468
        
 
4469
        icu= ipocopybuf.first;
 
4470
        
 
4471
        for (a=0, ei=G.sipo->editipo; a<G.sipo->totipo; a++, ei++) {
 
4472
                if (ei->flag & IPO_VISIBLE) {
 
4473
                        /* don't attempt pasting if no valid buffer-curve to paste from anymore */
 
4474
                        if (icu == 0) return;
3289
4475
                        
3290
 
                                        ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, ei->adrcode);
3291
 
                                        if(ei->icu==NULL) return;
3292
 
                                        
3293
 
                                        if(ei->icu->bezt) MEM_freeN(ei->icu->bezt);
3294
 
                                        ei->icu->bezt= NULL;
3295
 
                                        if(ei->icu->driver) MEM_freeN(ei->icu->driver);
3296
 
                                        ei->icu->driver= NULL;
3297
 
                                        
3298
 
                                        ei->icu->totvert= icu->totvert;
3299
 
                                        ei->icu->flag= ei->flag= icu->flag;
3300
 
                                        ei->icu->extrap= icu->extrap;
3301
 
                                        ei->icu->ipo= icu->ipo;
3302
 
                                        
3303
 
                                        if(icu->bezt)
3304
 
                                                ei->icu->bezt= MEM_dupallocN(icu->bezt);
3305
 
                                        if(icu->driver)
3306
 
                                                ei->icu->driver= MEM_dupallocN(icu->driver);
3307
 
                                        
3308
 
                                        icu= icu->next;
3309
 
                                        
 
4476
                        /* if in editmode, paste keyframes */ 
 
4477
                        if (ei->flag & IPO_EDIT) {
 
4478
                                BezTriple *bezt;
 
4479
                                float offset= 0.0f;
 
4480
                                short offsetInit= 0;
 
4481
                                int i;
 
4482
                                
 
4483
                                /* make sure an ipo-curve exists (it may not, as this is an editipo) */
 
4484
                                ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, G.sipo->bonename, ei->adrcode);
 
4485
                                if (ei->icu == NULL) return;
 
4486
                                
 
4487
                                /* Copy selected beztriples from source icu onto this edit-icu,
 
4488
                                 * with all added keyframes being offsetted by the difference between
 
4489
                                 * the first source keyframe and the current frame.
 
4490
                                 */
 
4491
                                for (i=0, bezt=icu->bezt; i < icu->totvert; i++, bezt++) {
 
4492
                                        /* skip if not selected */
 
4493
                                        if (BEZSELECTED(bezt) == 0) continue;
 
4494
                                        
 
4495
                                        /* initialise offset (if not already done) */
 
4496
                                        if (offsetInit==0) {
 
4497
                                                offset= CFRA - bezt->vec[1][0];
 
4498
                                                offsetInit= 1;
 
4499
                                        }
 
4500
                                        /* temporarily apply offset to src beztriple while copying */
 
4501
                                        bezt->vec[0][0] += offset;
 
4502
                                        bezt->vec[1][0] += offset;
 
4503
                                        bezt->vec[2][0] += offset;
 
4504
                                                
 
4505
                                        /* insert the keyframe */
 
4506
                                        insert_bezt_icu(ei->icu, bezt);
 
4507
                                        
 
4508
                                        /* un-apply offset from src beztriple after copying */
 
4509
                                        bezt->vec[0][0] -= offset;
 
4510
                                        bezt->vec[1][0] -= offset;
 
4511
                                        bezt->vec[2][0] -= offset;
3310
4512
                                }
 
4513
                                
 
4514
                                /* recalculate handles of curve that data was pasted into */
 
4515
                                calchandles_ipocurve(ei->icu);
 
4516
                                
 
4517
                                /* advance to next copy/paste buffer ipo-curve */
 
4518
                                icu= icu->next;
 
4519
                        }
 
4520
                        
 
4521
                        /* otherwise paste entire curve data */
 
4522
                        else  {
 
4523
                                
 
4524
                                /* make sure an ipo-curve exists (it may not, as this is an editipo) */
 
4525
                                ei->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, G.sipo->bonename, ei->adrcode);
 
4526
                                if (ei->icu==NULL) return;
 
4527
                                
 
4528
                                /* clear exisiting dynamic memory (keyframes, driver) */
 
4529
                                if (ei->icu->bezt) MEM_freeN(ei->icu->bezt);
 
4530
                                ei->icu->bezt= NULL;
 
4531
                                if (ei->icu->driver) MEM_freeN(ei->icu->driver);
 
4532
                                ei->icu->driver= NULL;
 
4533
                                
 
4534
                                ei->icu->totvert= icu->totvert;
 
4535
                                ei->icu->flag= ei->flag= icu->flag;
 
4536
                                ei->icu->extrap= icu->extrap;
 
4537
                                ei->icu->ipo= icu->ipo;
 
4538
                                
 
4539
                                /* make a copy of the source icu's data */
 
4540
                                if (icu->bezt)
 
4541
                                        ei->icu->bezt= MEM_dupallocN(icu->bezt);
 
4542
                                if (icu->driver)
 
4543
                                        ei->icu->driver= MEM_dupallocN(icu->driver);
 
4544
                                
 
4545
                                /* advance to next copy/paste buffer ipo-curve */
 
4546
                                icu= icu->next;
3311
4547
                        }
3312
4548
                }
3313
 
                editipo_changed(G.sipo, 1);
3314
 
                BIF_undo_push("Paste Ipo curves");
3315
4549
        }
 
4550
        
 
4551
        editipo_changed(G.sipo, 1);
 
4552
        BIF_undo_push("Paste Ipo curves");
3316
4553
}
3317
4554
 
3318
4555
/* *********************** */
3350
4587
        EditIpo *ei;
3351
4588
        BezTriple *bezt, *beztar[3];
3352
4589
        float vec1[3], vec2[3];
3353
 
        int a, b, totvert, didit=0;
 
4590
        int a, b, totvert, didit=0, done_error = 0;
3354
4591
                
3355
4592
        if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
3356
4593
 
3381
4618
                                                vec1[2]= (beztar[2]->vec[1][1] - beztar[2]->vec[0][1]) / (beztar[2]->vec[1][0] - beztar[2]->vec[0][0]) ;
3382
4619
                                                vec2[2]= (beztar[2]->vec[1][1] - beztar[2]->vec[2][1]) / (beztar[2]->vec[2][0] - beztar[2]->vec[1][0]) ;
3383
4620
                                                
3384
 
                                                Normalise(vec1);
3385
 
                                                Normalise(vec2);
 
4621
                                                Normalize(vec1);
 
4622
                                                Normalize(vec2);
3386
4623
                                                
3387
4624
                                                VecMulf(vec1, speed);
3388
4625
                                                VecMulf(vec2, speed);
3399
4636
                                                didit= 1;
3400
4637
                                        }
3401
4638
                                        else {
3402
 
                                                error("Only works for 3 visible curves with handles");
 
4639
                                                if (done_error==0) {
 
4640
                                                        error("Only works for 3 visible curves with handles");
 
4641
                                                }
 
4642
                                                done_error = 1;
3403
4643
                                        }
3404
4644
                                }
3405
4645
                        }
3453
4693
                if( ik->val==bezt->vec[1][0] ) {
3454
4694
                        if(ik->data[nr]==0) {   /* double points! */
3455
4695
                                ik->data[nr]= bezt;
3456
 
                                if(bezt->f2 & 1) ik->flag= 1;
 
4696
                                if(bezt->f2 & SELECT) ik->flag= 1;
3457
4697
                                return;
3458
4698
                        }
3459
4699
                }
3470
4710
        ikn->data[nr]= bezt;
3471
4711
        ikn->val= bezt->vec[1][0];
3472
4712
 
3473
 
        if(bezt->f2 & 1) ikn->flag= 1;
 
4713
        if(bezt->f2 & SELECT) ikn->flag= 1;
3474
4714
}
3475
4715
 
3476
4716
void make_ipokey(void)
3501
4741
                }
3502
4742
        }
3503
4743
        
3504
 
        /* test selectflags */
 
4744
        /* test selectflags & scaling */
3505
4745
        ik= lb->first;
3506
4746
        while(ik) {
3507
4747
                sel= desel= 0;
3508
4748
                for(a=0; a<G.sipo->totipo; a++) {
3509
4749
                        if(ik->data[a]) {
3510
4750
                                bezt= ik->data[a];
3511
 
                                if(bezt->f2 & 1) sel++;
 
4751
                                if(bezt->f2 & SELECT) sel++;
3512
4752
                                else desel++;
3513
4753
                        }
3514
4754
                }
3517
4757
                        if(ik->data[a]) {
3518
4758
                                bezt= ik->data[a];
3519
4759
                                if(sel) {
3520
 
                                        bezt->f1 |= 1;
3521
 
                                        bezt->f2 |= 1;
3522
 
                                        bezt->f3 |= 1;
 
4760
                                        bezt->f1 |= SELECT;
 
4761
                                        bezt->f2 |= SELECT;
 
4762
                                        bezt->f3 |= SELECT;
3523
4763
                                }
3524
4764
                                else {
3525
 
                                        bezt->f1 &= ~1;
3526
 
                                        bezt->f2 &= ~1;
3527
 
                                        bezt->f3 &= ~1;
 
4765
                                        bezt->f1 &= ~SELECT;
 
4766
                                        bezt->f2 &= ~SELECT;
 
4767
                                        bezt->f3 &= ~SELECT;
3528
4768
                                }
3529
4769
                        }
3530
4770
                }
3531
4771
                if(sel) ik->flag = 1;
3532
4772
                else ik->flag= 0;
3533
4773
                
 
4774
                /* map ipo-keys for drawing/editing if scaled ipo */
 
4775
                if (NLA_IPO_SCALED) {
 
4776
                        ik->val= get_action_frame_inv(OBACT, ik->val);
 
4777
                }
 
4778
                
3534
4779
                ik= ik->next;
3535
4780
        }
 
4781
        
3536
4782
        get_status_editipo();
3537
4783
}
3538
4784
 
3540
4786
{
3541
4787
        IpoCurve *icu;
3542
4788
        BezTriple *bezt;
 
4789
        IpoKey *ik;
3543
4790
        int a, adrcode = 0, ok, dloc=0, drot=0, dsize=0;
3544
4791
        
3545
4792
        if(ob->ipo==NULL) return;
3615
4862
                                bezt= icu->bezt;
3616
4863
                                a= icu->totvert;
3617
4864
                                while(a--) {
3618
 
                                        if(sel==0 || (bezt->f2 & 1)) {
 
4865
                                        if(sel==0 || (bezt->f2 & SELECT)) {
3619
4866
                                                add_to_ipokey(lb, bezt, adrcode, OB_TOTIPO);
3620
4867
                                        }
3621
4868
                                        bezt++;
3624
4871
                }
3625
4872
                icu= icu->next;
3626
4873
        }
 
4874
        
 
4875
        
 
4876
        ik= lb->first;
 
4877
        while(ik) {
 
4878
                /* map ipo-keys for drawing/editing if scaled ipo */
 
4879
                if (NLA_IPO_SCALED) {
 
4880
                        ik->val= get_action_frame_inv(OBACT, ik->val);
 
4881
                }
 
4882
                
 
4883
                ik= ik->next;
 
4884
        }
3627
4885
}
3628
4886
 
3629
4887
void update_ipokey_val(void)    /* after moving vertices */
3636
4894
                for(a=0; a<G.sipo->totipo; a++) {
3637
4895
                        if(ik->data[a]) {
3638
4896
                                ik->val= ik->data[a]->vec[1][0];
 
4897
                                
 
4898
                                /* map ipo-keys for drawing/editing if scaled ipo */
 
4899
                                if (NLA_IPO_SCALED) {
 
4900
                                        ik->val= get_action_frame_inv(OBACT, ik->val);
 
4901
                                }
3639
4902
                                break;
3640
4903
                        }
3641
4904
                }
3775
5038
        int a;
3776
5039
        float toframe= CFRA;
3777
5040
        
 
5041
        if (!G.vd)
 
5042
                return;
 
5043
        
3778
5044
        base= FIRSTBASE;
3779
5045
        while(base) {
3780
 
                if TESTBASE(base) {
 
5046
                if TESTBASELIB(base) {
3781
5047
                        ob= base->object;
3782
5048
                        if(ob->ipo && ob->ipo->showkey) {
3783
5049
                                elems.first= elems.last= 0;
3822
5088
 
3823
5089
}
3824
5090
/* **************************************************** */
3825
 
 
3826
 
 
3827
 
void remake_ipo_transverts(TransVert *transmain, float *dvec, int tot)
3828
 
{
 
5091
/* IPO TRANSFORM TOOLS 
 
5092
 * 
 
5093
 * Only the helper functions are stored here these days. They are here as
 
5094
 * there are heaps of ugly globals which the IPO editor relies on. 
 
5095
 * However, the actual transforms go through the transform system these days.
 
5096
 */
 
5097
 
 
5098
/* Helper function for make_ipo_transdata, which is reponsible for associating
 
5099
 * source data with transform data
 
5100
 */
 
5101
static void bezt_to_transdata (TransData *td, TransData2D *td2d, float *loc, float *cent, short selected, short onlytime)
 
5102
{
 
5103
        /* New location from td gets dumped onto the old-location of td2d, which then
 
5104
         * gets copied to the actual data at td2d->loc2d (bezt->vec[n])
 
5105
         *
 
5106
         * Due to NLA scaling, we apply NLA scaling to some of the verts here,
 
5107
         * and then that scaling will be undone after transform is done.
 
5108
         */
 
5109
        
 
5110
        if (NLA_IPO_SCALED) {
 
5111
                td2d->loc[0] = get_action_frame_inv(OBACT, loc[0]);
 
5112
                td2d->loc[1] = loc[1];
 
5113
                td2d->loc[2] = 0.0f;
 
5114
                td2d->loc2d = loc;
 
5115
                
 
5116
                /*td->flag = 0;*/ /* can be set beforehand, else make sure its set to 0 */
 
5117
                td->loc = td2d->loc;
 
5118
                td->center[0] = get_action_frame_inv(OBACT, cent[0]);
 
5119
                td->center[1] = cent[1];
 
5120
                td->center[2] = 0.0f;
 
5121
                
 
5122
                VECCOPY(td->iloc, td->loc);
 
5123
        }
 
5124
        else {
 
5125
                td2d->loc[0] = loc[0];
 
5126
                td2d->loc[1] = loc[1];
 
5127
                td2d->loc[2] = 0.0f;
 
5128
                td2d->loc2d = loc;
 
5129
                
 
5130
                /*td->flag = 0;*/ /* can be set beforehand, else make sure its set to 0 */
 
5131
                td->loc = td2d->loc;
 
5132
                VECCOPY(td->center, cent);
 
5133
                VECCOPY(td->iloc, td->loc);
 
5134
        }
 
5135
 
 
5136
        memset(td->axismtx, 0, sizeof(td->axismtx));
 
5137
        td->axismtx[2][2] = 1.0f;
 
5138
 
 
5139
        td->ext= NULL; td->tdi= NULL; td->val= NULL;
 
5140
 
 
5141
        if (selected) {
 
5142
                td->flag |= TD_SELECTED;
 
5143
                td->dist= 0.0;
 
5144
        }
 
5145
        else
 
5146
                td->dist= MAXFLOAT;
 
5147
        
 
5148
        if (onlytime)
 
5149
                td->flag |= TD_TIMEONLY;
 
5150
        
 
5151
        Mat3One(td->mtx);
 
5152
        Mat3One(td->smtx);
 
5153
}       
 
5154
 
 
5155
/* This function is called by createTransIpoData and remake_ipo_transdata to
 
5156
 * create the TransData and TransData2D arrays for transform. The costly counting
 
5157
 * stage is only performed for createTransIpoData case, and is indicated by t->total==-1;
 
5158
 */
 
5159
void make_ipo_transdata (TransInfo *t)
 
5160
{
 
5161
        TransData *td = NULL;
 
5162
        TransData2D *td2d = NULL;
 
5163
        
3829
5164
        EditIpo *ei;
3830
 
        TransVert *tv;
3831
5165
        BezTriple *bezt;
3832
5166
        int a, b;
3833
5167
        
 
5168
        /* countsel and propmode are used for proportional edit, which is not yet available */
 
5169
        int count=0/*, countsel=0*/;
 
5170
        /*int propmode = t->flag & T_PROP_EDIT;*/
 
5171
        
 
5172
        /* count data and allocate memory (if needed) */
 
5173
        if (t->total == 0) {
 
5174
                /* count data first */
 
5175
                if (totipo_vertsel) {
 
5176
                        /* we're probably in editmode, so only selected verts */
 
5177
                        count= totipo_vertsel;
 
5178
                }
 
5179
                else if (totipo_edit==0 && totipo_sel!=0) {
 
5180
                        /* we're not in editmode, so entire curves get moved */
 
5181
                        ei= G.sipo->editipo;
 
5182
                        for (a=0; a<G.sipo->totipo; a++, ei++) {
 
5183
                                if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
 
5184
                                        if (ei->icu->bezt && ei->icu->ipo==IPO_BEZ)
 
5185
                                                count+= 3*ei->icu->totvert;
 
5186
                                        else 
 
5187
                                                count+= ei->icu->totvert;
 
5188
                                }
 
5189
                        }
 
5190
                        if (count==0) return;
 
5191
                }
 
5192
                else {
 
5193
                        /* this case should not happen */
 
5194
                        return;
 
5195
                }
 
5196
                
 
5197
                /* memory allocation */
 
5198
                /*t->total= (propmode)? count: countsel;*/
 
5199
                t->total= count;
 
5200
                t->data= MEM_callocN(t->total*sizeof(TransData), "TransData (IPO Editor)");
 
5201
                        /* for each 2d vert a 3d vector is allocated, so that they can be treated just as if they were 3d verts */
 
5202
                t->data2d= MEM_callocN(t->total*sizeof(TransData2D), "TransData2D (IPO Editor)");
 
5203
        }
 
5204
        
 
5205
        td= t->data;
 
5206
        td2d= t->data2d;
 
5207
        
 
5208
        /* add verts */
 
5209
        if (totipo_vertsel) {
 
5210
                /* we're probably in editmode, so only selected verts */
 
5211
                ei= G.sipo->editipo;
 
5212
                for (a=0; a<G.sipo->totipo; a++, ei++) {
 
5213
                        /* only consider those curves that are visible and are being edited/used for showkeys */
 
5214
                        if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
 
5215
                                if ( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
 
5216
                                        if (ei->icu->bezt) {
 
5217
                                                short onlytime= (ei->disptype==IPO_DISPBITS) ? 1 : (G.sipo->showkey) ? 1 : 0;
 
5218
                                                bezt= ei->icu->bezt;
 
5219
                                                
 
5220
                                                for (b=0; b < ei->icu->totvert; b++, bezt++) {
 
5221
                                                        TransDataCurveHandleFlags *hdata = NULL;
 
5222
                                                        /* only include handles if selected, and interpolaton mode uses beztriples */
 
5223
                                                        if (ei->icu->ipo==IPO_BEZ) {
 
5224
                                                                if (bezt->f1 & SELECT) {
 
5225
                                                                        hdata = initTransDataCurveHandes(td, bezt);
 
5226
                                                                        bezt_to_transdata(td++, td2d++, bezt->vec[0], bezt->vec[1], 1, onlytime);
 
5227
                                                                }
 
5228
                                                                if (bezt->f3 & SELECT) {
 
5229
                                                                        if (hdata==NULL) {
 
5230
                                                                                hdata = initTransDataCurveHandes(td, bezt);
 
5231
                                                                        }
 
5232
                                                                        bezt_to_transdata(td++, td2d++, bezt->vec[2], bezt->vec[1], 1, onlytime);
 
5233
                                                                }
 
5234
                                                        }
 
5235
                                                        
 
5236
                                                        /* only include main vert if selected */
 
5237
                                                        if (bezt->f2 & SELECT) {
 
5238
                                                                
 
5239
                                                                if ((bezt->f1&SELECT)==0 && (bezt->f3&SELECT)==0) {
 
5240
                                                                        if (hdata==NULL) {
 
5241
                                                                                hdata = initTransDataCurveHandes(td, bezt);
 
5242
                                                                        }
 
5243
                                                                }
 
5244
                                                                
 
5245
                                                                bezt_to_transdata(td++, td2d++, bezt->vec[1], bezt->vec[1], 1, onlytime);
 
5246
                                                        }
 
5247
                                                }
 
5248
                                                /* Sets handles based on the selection */
 
5249
                                                testhandles_ipocurve(ei->icu);
 
5250
                                        }
 
5251
                                }
 
5252
                        }
 
5253
                }
 
5254
        }
 
5255
        else if (totipo_edit==0 && totipo_sel!=0) {
 
5256
                /* we're not in editmode, so entire curves get moved */
 
5257
                ei= G.sipo->editipo;
 
5258
                for (a=0; a<G.sipo->totipo; a++, ei++) {
 
5259
                        /* only include curves that are visible and selected */
 
5260
                        if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
 
5261
                                if (ei->icu->bezt) {
 
5262
                                        short onlytime= (ei->disptype==IPO_DISPBITS) ? 1 : (G.sipo->showkey) ? 1 : 0;
 
5263
                                        bezt= ei->icu->bezt;
 
5264
                                        b= ei->icu->totvert;
 
5265
                                        
 
5266
                                        for (b=0; b < ei->icu->totvert; b++, bezt++) {
 
5267
                                                /* only include handles if interpolation mode is bezier not bpoint */
 
5268
                                                if (ei->icu->ipo==IPO_BEZ) {
 
5269
                                                        bezt_to_transdata(td++, td2d++, bezt->vec[0], bezt->vec[1], 1, onlytime);
 
5270
                                                        bezt_to_transdata(td++, td2d++, bezt->vec[2], bezt->vec[1], 1, onlytime);
 
5271
                                                }
 
5272
                                                
 
5273
                                                /* always include the main handle */
 
5274
                                                bezt_to_transdata(td++, td2d++, bezt->vec[1], bezt->vec[1], 1, onlytime);
 
5275
                                        }
 
5276
                                }
 
5277
                        }
 
5278
                }
 
5279
        }
 
5280
}
 
5281
 
 
5282
/* ------------------------ */
 
5283
 
 
5284
/* struct for use in re-sorting BezTriples during IPO transform */
 
5285
typedef struct BeztMap {
 
5286
        BezTriple *bezt;
 
5287
        int oldIndex;           /* index of bezt in icu->bezt array before sorting */
 
5288
        int newIndex;           /* index of bezt in icu->bezt array after sorting */
 
5289
        short swapHs;           /* swap order of handles (-1=clear; 0=not checked, 1=swap) */
 
5290
} BeztMap;
 
5291
 
 
5292
 
 
5293
/* This function converts an IpoCurve's BezTriple array to a BeztMap array
 
5294
 * NOTE: this allocates memory that will need to get freed later
 
5295
 */
 
5296
static BeztMap *bezt_to_beztmaps (BezTriple *bezts, int totvert)
 
5297
{
 
5298
        BezTriple *bezt= bezts;
 
5299
        BeztMap *bezm, *bezms;
 
5300
        int i;
 
5301
        
 
5302
        /* allocate memory for this array */
 
5303
        if (totvert==0 || bezts==NULL)
 
5304
                return NULL;
 
5305
        bezm= bezms= MEM_callocN(sizeof(BeztMap)*totvert, "BeztMaps");
 
5306
        
 
5307
        /* assign beztriples to beztmaps */
 
5308
        for (i=0; i < totvert; i++, bezm++, bezt++) {
 
5309
                bezm->bezt= bezt;
 
5310
                bezm->oldIndex= i;
 
5311
                bezm->newIndex= i;
 
5312
        }
 
5313
        
 
5314
        return bezms;
 
5315
}
 
5316
 
 
5317
/* This function copies the code of sort_time_ipocurve, but acts on BeztMap structs instead */
 
5318
static void sort_time_beztmaps (BeztMap *bezms, int totvert)
 
5319
{
 
5320
        BeztMap *bezm;
 
5321
        int i, ok= 1;
 
5322
        
 
5323
        /* keep repeating the process until nothing is out of place anymore */
 
5324
        while (ok) {
 
5325
                ok= 0;
 
5326
                
 
5327
                bezm= bezms;
 
5328
                i= totvert;
 
5329
                while (i--) {
 
5330
                        /* is current bezm out of order (i.e. occurs later than next)? */
 
5331
                        if (i > 0) {
 
5332
                                if (bezm->bezt->vec[1][0] > (bezm+1)->bezt->vec[1][0]) {
 
5333
                                        bezm->newIndex++;
 
5334
                                        (bezm+1)->newIndex--;
 
5335
                                        
 
5336
                                        SWAP(BeztMap, *bezm, *(bezm+1));
 
5337
                                        
 
5338
                                        ok= 1;
 
5339
                                }
 
5340
                        }
 
5341
                        
 
5342
                        /* do we need to check if the handles need to be swapped?
 
5343
                         * optimisation: this only needs to be performed in the first loop
 
5344
                         */
 
5345
                        if (bezm->swapHs == 0) {
 
5346
                                if ( (bezm->bezt->vec[0][0] > bezm->bezt->vec[1][0]) && 
 
5347
                                         (bezm->bezt->vec[2][0] < bezm->bezt->vec[1][0]) )
 
5348
                                {
 
5349
                                        /* handles need to be swapped */
 
5350
                                        bezm->swapHs = 1;
 
5351
                                }
 
5352
                                else {
 
5353
                                        /* handles need to be cleared */
 
5354
                                        bezm->swapHs = -1;
 
5355
                                }
 
5356
                        }
 
5357
                        
 
5358
                        bezm++;
 
5359
                }       
 
5360
        }
 
5361
}
 
5362
 
 
5363
/* This function firstly adjusts the pointers that the transdata has to each BezTriple*/
 
5364
static void beztmap_to_data (TransInfo *t, EditIpo *ei, BeztMap *bezms, int totvert)
 
5365
{
 
5366
        BezTriple *bezts = ei->icu->bezt;
 
5367
        BeztMap *bezm;
 
5368
        TransData2D *td;
 
5369
        int i, j;
 
5370
        char *adjusted;
 
5371
        
 
5372
        /* dynamically allocate an array of chars to mark whether an TransData's 
 
5373
         * pointers have been fixed already, so that we don't override ones that are
 
5374
         * already done
 
5375
         */
 
5376
        adjusted= MEM_callocN(t->total, "beztmap_adjusted_map");
 
5377
        
 
5378
        /* for each beztmap item, find if it is used anywhere */
 
5379
        bezm= bezms;
 
5380
        for (i= 0; i < totvert; i++, bezm++) {
 
5381
                /* loop through transdata, testing if we have a hit 
 
5382
                 * for the handles (vec[0]/vec[2]), we must also check if they need to be swapped...
 
5383
                 */
 
5384
                td= t->data2d;
 
5385
                for (j= 0; j < t->total; j++, td++) {
 
5386
                        /* skip item if already marked */
 
5387
                        if (adjusted[j] != 0) continue;
 
5388
                        
 
5389
                        if (totipo_vertsel) {
 
5390
                                /* only selected verts */
 
5391
                                if (ei->icu->ipo==IPO_BEZ) {
 
5392
                                        if (bezm->bezt->f1 & SELECT) {
 
5393
                                                if (td->loc2d == bezm->bezt->vec[0]) {
 
5394
                                                        if (bezm->swapHs == 1)
 
5395
                                                                td->loc2d= (bezts + bezm->newIndex)->vec[2];
 
5396
                                                        else
 
5397
                                                                td->loc2d= (bezts + bezm->newIndex)->vec[0];
 
5398
                                                        adjusted[j] = 1;
 
5399
                                                }
 
5400
                                        }
 
5401
                                        if (bezm->bezt->f3 & SELECT) {
 
5402
                                                if (td->loc2d == bezm->bezt->vec[2]) {
 
5403
                                                        if (bezm->swapHs == 1)
 
5404
                                                                td->loc2d= (bezts + bezm->newIndex)->vec[0];
 
5405
                                                        else
 
5406
                                                                td->loc2d= (bezts + bezm->newIndex)->vec[2];
 
5407
                                                        adjusted[j] = 1;
 
5408
                                                }
 
5409
                                        }
 
5410
                                }
 
5411
                                if (bezm->bezt->f2 & SELECT) {
 
5412
                                        if (td->loc2d == bezm->bezt->vec[1]) {
 
5413
                                                td->loc2d= (bezts + bezm->newIndex)->vec[1];
 
5414
                                                adjusted[j] = 1;
 
5415
                                        }
 
5416
                                }
 
5417
                        }
 
5418
                        else {
 
5419
                                /* whole curve */
 
5420
                                if (ei->icu->ipo==IPO_BEZ) {
 
5421
                                        if (td->loc2d == bezm->bezt->vec[0]) {
 
5422
                                                if (bezm->swapHs == 1)
 
5423
                                                        td->loc2d= (bezts + bezm->newIndex)->vec[2];
 
5424
                                                else
 
5425
                                                        td->loc2d= (bezts + bezm->newIndex)->vec[0];
 
5426
                                                adjusted[j] = 1;
 
5427
                                        }
 
5428
                                        
 
5429
                                        if (td->loc2d == bezm->bezt->vec[2]) {
 
5430
                                                if (bezm->swapHs == 1)
 
5431
                                                        td->loc2d= (bezts + bezm->newIndex)->vec[0];
 
5432
                                                else
 
5433
                                                        td->loc2d= (bezts + bezm->newIndex)->vec[2];
 
5434
                                                adjusted[j] = 1;
 
5435
                                        }
 
5436
                                }
 
5437
                                if (td->loc2d == bezm->bezt->vec[1]) {
 
5438
                                        td->loc2d= (bezts + bezm->newIndex)->vec[1];
 
5439
                                        adjusted[j] = 1;
 
5440
                                }
 
5441
                        }
 
5442
                }
 
5443
                
 
5444
        }
 
5445
        
 
5446
        /* free temp memory used for 'adjusted' array */
 
5447
        MEM_freeN(adjusted);
 
5448
}
 
5449
 
 
5450
/* This function is called by recalcData during the Transform loop to recalculate 
 
5451
 * the handles of curves and sort the keyframes so that the curves draw correctly.
 
5452
 * It is only called if some keyframes have moved out of order.
 
5453
 */
 
5454
void remake_ipo_transdata (TransInfo *t)
 
5455
{
 
5456
        EditIpo *ei;
 
5457
        int a;
 
5458
        
 
5459
        /* sort and reassign verts */
3834
5460
        ei= G.sipo->editipo;
3835
 
        for(a=0; a<G.sipo->totipo; a++, ei++) {
3836
 
                
 
5461
        for (a=0; a<G.sipo->totipo; a++, ei++) {
3837
5462
                if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
3838
 
                                
3839
 
                        if(ei->icu->bezt) {
 
5463
                        if (ei->icu->bezt) {
 
5464
                                BeztMap *bezm;
 
5465
                                
 
5466
                                /* adjust transform-data pointers */
 
5467
                                bezm= bezt_to_beztmaps(ei->icu->bezt, ei->icu->totvert);
 
5468
                                sort_time_beztmaps(bezm, ei->icu->totvert);
 
5469
                                beztmap_to_data(t, ei, bezm, ei->icu->totvert);
 
5470
                                
 
5471
                                /* re-sort actual beztriples (perhaps this could be done using the beztmaps to save time?) */
3840
5472
                                sort_time_ipocurve(ei->icu);
 
5473
                                
 
5474
                                /* free mapping stuff */
 
5475
                                MEM_freeN(bezm);
 
5476
                                
 
5477
                                /* make sure handles are all set correctly */
 
5478
                                testhandles_ipocurve(ei->icu);
3841
5479
                        }
3842
5480
                }
3843
5481
        }
3844
 
 
3845
 
        ei= G.sipo->editipo;
3846
 
        tv= transmain;
3847
 
        for(a=0; a<G.sipo->totipo; a++, ei++) {
3848
5482
                
3849
 
                if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
3850
 
                        if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
3851
 
                                if(ei->icu->bezt) {
3852
 
                                        bezt= ei->icu->bezt;
3853
 
                                        b= ei->icu->totvert;
3854
 
                                        while(b--) {
3855
 
                                                if(ei->icu->ipo==IPO_BEZ) {
3856
 
                                                        if(bezt->f1 & 1) {
3857
 
                                                                tv->loc= bezt->vec[0];
3858
 
                                                                tv++;
3859
 
                                                        }
3860
 
                                                        if(bezt->f3 & 1) {
3861
 
                                                                tv->loc= bezt->vec[2];
3862
 
                                                                tv++;
3863
 
                                                        }
3864
 
                                                }
3865
 
                                                if(bezt->f2 & 1) {
3866
 
                                                        tv->loc= bezt->vec[1];
3867
 
                                                        tv++;
3868
 
                                                }
3869
 
                                                
3870
 
                                                bezt++;
3871
 
                                        }
3872
 
                                        testhandles_ipocurve(ei->icu);
3873
 
                                }
3874
 
                        }
3875
 
                }
3876
 
        }
3877
 
        
3878
 
        if(G.sipo->showkey) make_ipokey();
3879
 
        
3880
 
        if(dvec==0) return;
3881
 
        
3882
 
        tv= transmain;
3883
 
        for(a=0; a<tot; a++, tv++) {
3884
 
                tv->oldloc[0]= tv->loc[0]-dvec[0];
3885
 
                tv->oldloc[1]= tv->loc[1]-dvec[1];
3886
 
        }
 
5483
        /* remake ipokeys */
 
5484
        if (G.sipo->showkey) make_ipokey();
3887
5485
}
3888
5486
 
3889
 
void transform_ipo(int mode)
 
5487
/* This function acts as the entrypoint for transforms in the IPO editor (as for
 
5488
 * the Action and NLA editors). The actual transform loop is not here anymore.
 
5489
 */
 
5490
void transform_ipo (int mode)
3890
5491
{
3891
 
        EditIpo *ei;
3892
 
        BezTriple *bezt;
3893
 
        TransVert *transmain = NULL, *tv;
3894
 
        float xref=1.0, yref=1.0, dx, dy, dvec[2], min[3], max[3], vec[2], div, cent[2], size[2], sizefac;
3895
 
        int tot=0, a, b, firsttime=1, afbreek=0, midtog= 0, dosort, proj = 0;
3896
 
        unsigned short event = 0;
3897
 
        short mval[2], val, xo, yo, xn, yn, xc, yc;
3898
 
        char str[64];
3899
 
        
3900
 
        if(G.sipo->ipo && G.sipo->ipo->id.lib) return;
3901
 
        if(G.sipo->editipo==0) return;
3902
 
        if(mode=='r') return;   /* from gesture */
3903
 
        
3904
 
        INIT_MINMAX(min, max);
3905
 
        
3906
 
        /* which vertices are involved */
 
5492
        short tmode;
 
5493
        short context = (U.flag & USER_DRAGIMMEDIATE)?CTX_TWEAK:CTX_NONE;
 
5494
        
 
5495
        /* data-validation */
 
5496
        if (G.sipo->ipo && G.sipo->ipo->id.lib) return;
 
5497
        if (G.sipo->editipo==0) return;
 
5498
        
 
5499
        /* convert ascii-based mode to transform system constants (mode) */
 
5500
        switch (mode) {
 
5501
                case 'g':       
 
5502
                        tmode= TFM_TRANSLATION;
 
5503
                        break;
 
5504
                case 'r':
 
5505
                        tmode= TFM_ROTATION;
 
5506
                        break;
 
5507
                case 's':
 
5508
                        tmode= TFM_RESIZE;
 
5509
                        break;
 
5510
                default:
 
5511
                        tmode= 0;
 
5512
                        return;
 
5513
        }
 
5514
        
 
5515
        /* the transform system method involved depends on the selection */
3907
5516
        get_status_editipo();
3908
 
        if(totipo_vertsel) {
3909
 
                tot= totipo_vertsel;
3910
 
                tv=transmain= MEM_callocN(tot*sizeof(TransVert), "transmain");
3911
 
                
3912
 
                ei= G.sipo->editipo;
3913
 
                for(a=0; a<G.sipo->totipo; a++, ei++) {
3914
 
                        
3915
 
                        if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
3916
 
                                if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
3917
 
 
3918
 
                                
3919
 
                                        if(ei->icu->bezt) {
3920
 
                                                bezt= ei->icu->bezt;
3921
 
                                                b= ei->icu->totvert;
3922
 
                                                while(b--) {
3923
 
                                                        if(ei->icu->ipo==IPO_BEZ) {
3924
 
                                                                if(bezt->f1 & 1) {
3925
 
                                                                        tv->loc= bezt->vec[0];
3926
 
                                                                        VECCOPY(tv->oldloc, tv->loc);
3927
 
                                                                        if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3928
 
                                                                        
3929
 
                                                                        /* we take the middle vertex */
3930
 
                                                                        DO_MINMAX2(bezt->vec[1], min, max);
3931
 
 
3932
 
                                                                        tv++;
3933
 
                                                                }
3934
 
                                                                if(bezt->f3 & 1) {
3935
 
                                                                        tv->loc= bezt->vec[2];
3936
 
                                                                        VECCOPY(tv->oldloc, tv->loc);
3937
 
                                                                        if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3938
 
                                                                        
3939
 
                                                                        /* we take the middle vertex */
3940
 
                                                                        DO_MINMAX2(bezt->vec[1], min, max);
3941
 
 
3942
 
                                                                        tv++;
3943
 
                                                                }
3944
 
                                                        }
3945
 
                                                        if(bezt->f2 & 1) {
3946
 
                                                                tv->loc= bezt->vec[1];
3947
 
                                                                VECCOPY(tv->oldloc, tv->loc);
3948
 
                                                                if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3949
 
                                                                DO_MINMAX2(bezt->vec[1], min, max);
3950
 
                                                                tv++;
3951
 
                                                        }
3952
 
                                                        bezt++;
3953
 
                                                }
3954
 
                                        }
3955
 
                                }
3956
 
                        }
3957
 
                }
3958
 
                
3959
 
        }
3960
 
        else if(totipo_edit==0 && totipo_sel!=0) {
3961
 
                
3962
 
                ei= G.sipo->editipo;
3963
 
                for(a=0; a<G.sipo->totipo; a++, ei++) {
3964
 
                        if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
3965
 
                                if(ei->icu->bezt && ei->icu->ipo==IPO_BEZ) tot+= 3*ei->icu->totvert;
3966
 
                                else tot+= ei->icu->totvert;
3967
 
                        }
3968
 
                }
3969
 
                if(tot==0) return;
3970
 
                
3971
 
                tv=transmain= MEM_callocN(tot*sizeof(TransVert), "transmain");
3972
 
 
3973
 
                ei= G.sipo->editipo;
3974
 
                for(a=0; a<G.sipo->totipo; a++, ei++) {
3975
 
                        if (ISPOIN3(ei, flag & IPO_VISIBLE, flag & IPO_SELECT, icu)) {
3976
 
                                if(ei->icu->bezt) {
3977
 
                                        
3978
 
                                        bezt= ei->icu->bezt;
3979
 
                                        b= ei->icu->totvert;
3980
 
                                        while(b--) {
3981
 
                                                if(ei->icu->ipo==IPO_BEZ) {
3982
 
                                                        tv->loc= bezt->vec[0];
3983
 
                                                        VECCOPY(tv->oldloc, tv->loc);
3984
 
                                                        if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3985
 
                                                        tv++;
3986
 
                                                
3987
 
                                                        tv->loc= bezt->vec[2];
3988
 
                                                        VECCOPY(tv->oldloc, tv->loc);
3989
 
                                                        if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3990
 
                                                        tv++;
3991
 
                                                }
3992
 
                                                tv->loc= bezt->vec[1];
3993
 
                                                VECCOPY(tv->oldloc, tv->loc);
3994
 
                                                if(ei->disptype==IPO_DISPBITS) tv->flag= 1;
3995
 
                                                
3996
 
                                                DO_MINMAX2(bezt->vec[1], min, max);
3997
 
                                                
3998
 
                                                tv++;
3999
 
                                                
4000
 
                                                bezt++;
4001
 
                                        }
4002
 
                                }
4003
 
                        }
4004
 
                }
4005
 
 
4006
 
        }
4007
 
 
4008
 
        if(tot==0) {
4009
 
                if(totipo_edit==0) move_keys(OBACT);
 
5517
        if (totipo_vertsel) {
 
5518
                /* we're probably in editmode, so only selected verts - transform system */
 
5519
                initTransform(tmode, context);
 
5520
                Transform();
 
5521
        }
 
5522
        else if (totipo_edit==0 && totipo_sel!=0) {
 
5523
                /* we're not in editmode, so entire curves get moved - transform system*/
 
5524
                initTransform(tmode, context);
 
5525
                Transform();
 
5526
        }
 
5527
        else {
 
5528
                /* shapekey mode? special transform code */
 
5529
                if (totipo_edit==0) 
 
5530
                        move_keys(OBACT);
4010
5531
                return;
4011
5532
        }
4012
 
 
4013
 
        cent[0]= (float)((min[0]+max[0])/2.0);
4014
 
        cent[1]= (float)((min[1]+max[1])/2.0);
4015
 
 
4016
 
        if(G.sipo->showkey) {
4017
 
                midtog= 1;
4018
 
                proj= 1;
4019
 
        }
4020
 
        
4021
 
        ipoco_to_areaco(G.v2d, cent, mval);
4022
 
        xc= mval[0];
4023
 
        yc= mval[1];
4024
 
        
4025
 
        getmouseco_areawin(mval);
4026
 
        xo= xn= mval[0];
4027
 
        yo= yn= mval[1];
4028
 
        dvec[0]= dvec[1]= 0.0;
4029
 
        
4030
 
        sizefac= (float)(sqrt( (float)((yc-yn)*(yc-yn)+(xn-xc)*(xn-xc)) ));
4031
 
        if(sizefac<2.0) sizefac= 2.0;
4032
 
 
4033
 
        while(afbreek==0) {
4034
 
                getmouseco_areawin(mval);
4035
 
                if(mval[0]!=xo || mval[1]!=yo || firsttime) {
4036
 
                        
4037
 
                        if(mode=='g') {
4038
 
                        
4039
 
                                dx= (float)(mval[0]- xo);
4040
 
                                dy= (float)(mval[1]- yo);
4041
 
        
4042
 
                                div= (float)(G.v2d->mask.xmax-G.v2d->mask.xmin);
4043
 
                                dvec[0]+= (G.v2d->cur.xmax-G.v2d->cur.xmin)*(dx)/div;
4044
 
        
4045
 
                                div= (float)(G.v2d->mask.ymax-G.v2d->mask.ymin);
4046
 
                                dvec[1]+= (G.v2d->cur.ymax-G.v2d->cur.ymin)*(dy)/div;
4047
 
                                
4048
 
                                if(midtog) dvec[proj]= 0.0;
4049
 
                                
4050
 
                                /* vec is reused below: remake_ipo_transverts */
4051
 
                                vec[0]= dvec[0];
4052
 
                                vec[1]= dvec[1];
4053
 
                                
4054
 
                                apply_keyb_grid(vec, 0.0, (float)1.0, (float)0.1, U.flag & USER_AUTOGRABGRID);
4055
 
                                apply_keyb_grid(vec+1, 0.0, (float)1.0, (float)0.1, 0);
4056
 
                                
4057
 
                                tv= transmain;
4058
 
                                for(a=0; a<tot; a++, tv++) {
4059
 
                                        tv->loc[0]= tv->oldloc[0]+vec[0];
4060
 
 
4061
 
                                        if(tv->flag==0) tv->loc[1]= tv->oldloc[1]+vec[1];
4062
 
                                }
4063
 
                                
4064
 
                                sprintf(str, "X: %.3f   Y: %.3f  ", vec[0], vec[1]);
4065
 
                                headerprint(str);
4066
 
                        }
4067
 
                        else if(mode=='s') {
4068
 
                                
4069
 
                                size[0]=size[1]=(float)( (sqrt( (float)((yc-mval[1])*(yc-mval[1])+(mval[0]-xc)*(mval[0]-xc)) ))/sizefac);
4070
 
                                
4071
 
                                if(midtog) size[proj]= 1.0;
4072
 
                                size[0]*= xref;
4073
 
                                size[1]*= yref;
4074
 
                                
4075
 
                                apply_keyb_grid(size, 0.0, (float)0.2, (float)0.1, U.flag & USER_AUTOSIZEGRID);
4076
 
                                apply_keyb_grid(size+1, 0.0, (float)0.2, (float)0.1, U.flag & USER_AUTOSIZEGRID);
4077
 
 
4078
 
                                tv= transmain;
4079
 
 
4080
 
                                for(a=0; a<tot; a++, tv++) {
4081
 
                                        tv->loc[0]= size[0]*(tv->oldloc[0]-cent[0])+ cent[0];
4082
 
                                        if(tv->flag==0) tv->loc[1]= size[1]*(tv->oldloc[1]-cent[1])+ cent[1];
4083
 
                                }
4084
 
                                
4085
 
                                sprintf(str, "scaleX: %.3f   scaleY: %.3f  ", size[0], size[1]);
4086
 
                                headerprint(str);
4087
 
                                
4088
 
                        }
4089
 
                        
4090
 
                        xo= mval[0];
4091
 
                        yo= mval[1];
4092
 
                                
4093
 
                        dosort= 0;
4094
 
                        ei= G.sipo->editipo;
4095
 
                        for(a=0; a<G.sipo->totipo; a++, ei++) {
4096
 
                                if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
4097
 
                                        
4098
 
                                        /* watch it: if the time is wrong: do not correct handles */
4099
 
                                        if (test_time_ipocurve(ei->icu) ) dosort++;
4100
 
                                        else testhandles_ipocurve(ei->icu);
4101
 
                                }
4102
 
                        }
4103
 
                        
4104
 
                        if(dosort) {
4105
 
                                if(mode=='g') remake_ipo_transverts(transmain, vec, tot);
4106
 
                                else remake_ipo_transverts(transmain, 0, tot);
4107
 
                        }
4108
 
                        if(G.sipo->showkey) update_ipokey_val();
4109
 
                        
4110
 
                        calc_ipo(G.sipo->ipo, (float)CFRA);
4111
 
 
4112
 
                        /* update realtime */
4113
 
                        if(G.sipo->lock) {
4114
 
                                if(G.sipo->blocktype==ID_MA || G.sipo->blocktype==ID_TE) {
4115
 
                                        do_ipo(G.sipo->ipo);
4116
 
                                        force_draw_plus(SPACE_BUTS, 0);
4117
 
                                }
4118
 
                                else if(G.sipo->blocktype==ID_CA) {
4119
 
                                        do_ipo(G.sipo->ipo);
4120
 
                                        force_draw_plus(SPACE_VIEW3D, 0);
4121
 
                                }
4122
 
                                else if(G.sipo->blocktype==ID_KE) {
4123
 
                                        Object *ob= OBACT;
4124
 
                                        if(ob) {
4125
 
                                                ob->shapeflag &= ~OB_SHAPE_TEMPLOCK;
4126
 
                                                DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
4127
 
                                        }
4128
 
                                        force_draw_plus(SPACE_VIEW3D, 0);
4129
 
                                }
4130
 
                                else if(G.sipo->blocktype==ID_PO) {
4131
 
                                        Object *ob= OBACT;
4132
 
                                        if(ob && ob->pose) {
4133
 
                                                DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
4134
 
                                        }
4135
 
                                        force_draw_plus(SPACE_VIEW3D, 0);
4136
 
                                }
4137
 
                                else if(G.sipo->blocktype==ID_OB) {
4138
 
                                        Base *base= FIRSTBASE;
4139
 
                                        
4140
 
                                        while(base) {
4141
 
                                                if(base->object->ipo==G.sipo->ipo) {
4142
 
                                                        do_ob_ipo(base->object);
4143
 
                                                        base->object->recalc |= OB_RECALC_OB;
4144
 
                                                }
4145
 
                                                base= base->next;
4146
 
                                        }
4147
 
                                        DAG_scene_flush_update(G.scene, screen_view3d_layers());
4148
 
                                        force_draw_plus(SPACE_VIEW3D, 0);
4149
 
                                }
4150
 
                                else force_draw(0);
4151
 
                        }
4152
 
                        else {
4153
 
                                force_draw(0);
4154
 
                        }
4155
 
                        firsttime= 0;
4156
 
                }
4157
 
                else BIF_wait_for_statechange();
4158
 
                
4159
 
                while(qtest()) {
4160
 
                        event= extern_qread(&val);
4161
 
                        if(val) {
4162
 
                                switch(event) {
4163
 
                                case ESCKEY:
4164
 
                                case LEFTMOUSE:
4165
 
                                case RIGHTMOUSE:
4166
 
                                case SPACEKEY:
4167
 
                                case RETKEY:
4168
 
                                        afbreek= 1;
4169
 
                                        break;
4170
 
                                case MIDDLEMOUSE:
4171
 
                                        if(G.sipo->showkey==0) {
4172
 
                                                midtog= ~midtog;
4173
 
                                                if(midtog) {
4174
 
                                                        if( abs(mval[0]-xn) > abs(mval[1]-yn)) proj= 1;
4175
 
                                                        else proj= 0;
4176
 
                                                        firsttime= 1;
4177
 
                                                }
4178
 
                                        }
4179
 
                                        break;
4180
 
                                case XKEY:
4181
 
                                case YKEY:
4182
 
                                        if(event==XKEY) xref= -xref;
4183
 
                                        else if(G.sipo->showkey==0) yref= -yref;
4184
 
                                        firsttime= 1;
4185
 
                                        break;
4186
 
                                case LEFTCTRLKEY:
4187
 
                                case RIGHTCTRLKEY:
4188
 
                                        firsttime= 1;
4189
 
                                        break;
4190
 
                                default:
4191
 
                                        if(mode=='g') {
4192
 
                                                if(G.qual & LR_CTRLKEY) {
4193
 
                                                        if(event==LEFTARROWKEY) {dvec[0]-= 1.0; firsttime= 1;}
4194
 
                                                        else if(event==RIGHTARROWKEY) {dvec[0]+= 1.0; firsttime= 1;}
4195
 
                                                        else if(event==UPARROWKEY) {dvec[1]+= 1.0; firsttime= 1;}
4196
 
                                                        else if(event==DOWNARROWKEY) {dvec[1]-= 1.0; firsttime= 1;}
4197
 
                                                }
4198
 
                                                else arrows_move_cursor(event);
4199
 
                                        }
4200
 
                                        else arrows_move_cursor(event);
4201
 
                                }
4202
 
                        }
4203
 
                        if(afbreek) break;
4204
 
                }
4205
 
        }
4206
 
        
4207
 
        if(event==ESCKEY || event==RIGHTMOUSE) {
4208
 
                tv= transmain;
4209
 
                for(a=0; a<tot; a++, tv++) {
4210
 
                        tv->loc[0]= tv->oldloc[0];
4211
 
                        tv->loc[1]= tv->oldloc[1];
4212
 
                }
4213
 
                
4214
 
                dosort= 0;
4215
 
                ei= G.sipo->editipo;
4216
 
                for(a=0; a<G.sipo->totipo; a++, ei++) {
4217
 
                        if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
4218
 
                                if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
4219
 
                                        if( test_time_ipocurve(ei->icu)) {
4220
 
                                                dosort= 1;
4221
 
                                                break;
4222
 
                                        }
4223
 
                                }
4224
 
                        }
4225
 
                }
4226
 
                
4227
 
                if(dosort) remake_ipo_transverts(transmain, 0, tot);
4228
 
                
4229
 
                ei= G.sipo->editipo;
4230
 
                for(a=0; a<G.sipo->totipo; a++, ei++) {
4231
 
                        if (ISPOIN(ei, flag & IPO_VISIBLE, icu)) {
4232
 
                                if( (ei->flag & IPO_EDIT) || G.sipo->showkey) {
4233
 
                                        testhandles_ipocurve(ei->icu);
4234
 
                                }
4235
 
                        }
4236
 
                }
4237
 
                calc_ipo(G.sipo->ipo, (float)CFRA);
4238
 
        }
4239
 
        else BIF_undo_push("Transform Ipo");
4240
 
 
 
5533
        
 
5534
        /* cleanup */
4241
5535
        editipo_changed(G.sipo, 1);
4242
 
 
4243
 
        MEM_freeN(transmain);
4244
5536
}
4245
5537
 
 
5538
/**************************************************/
 
5539
 
4246
5540
void filter_sampledata(float *data, int sfra, int efra)
4247
5541
{
4248
5542
        float *da;
4343
5637
 
4344
5638
        /* make curves ready, start values */
4345
5639
        if(ei1->icu==NULL) 
4346
 
                ei1->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, ei1->adrcode);
 
5640
                ei1->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, G.sipo->bonename, ei1->adrcode);
4347
5641
        if(ei1->icu==NULL) return;
4348
5642
        
4349
5643
        poin= get_ipo_poin(G.sipo->from, ei1->icu, &type);
4350
5644
        if(poin) ei1->icu->curval= read_ipo_poin(poin, type);
4351
5645
        or1= ei1->icu->curval;
4352
5646
        ei1->icu->flag |= IPO_LOCK;
4353
 
        
 
5647
 
4354
5648
        if(ei2) {
4355
5649
                if(ei2->icu==NULL)
4356
 
                        ei2->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, ei2->adrcode);
 
5650
                        ei2->icu= verify_ipocurve(G.sipo->from, G.sipo->blocktype, G.sipo->actname, G.sipo->constname, G.sipo->bonename, ei2->adrcode);
4357
5651
                if(ei2->icu==NULL) return;
4358
5652
                
4359
5653
                poin= get_ipo_poin(G.sipo->from, ei2->icu, &type);
4378
5672
                }               
4379
5673
                sa= sa->next;   
4380
5674
        }
 
5675
 
4381
5676
        if(sa) areawinset(sa->win);
4382
 
        
 
5677
 
4383
5678
        /* can we? */
4384
5679
        while(get_mbut()&L_MOUSE) BIF_wait_for_statechange();
4385
5680
        data1= MEM_callocN(sizeof(float)*(EFRA-SFRA+1), "data1");
4388
5683
        getmouseco_areawin(mvalo);
4389
5684
        xn= mvalo[0]; yn= mvalo[1];
4390
5685
        waitcursor(1);
4391
 
        
 
5686
 
4392
5687
        tottime= 0.0;
4393
 
        swaptime= 1.0/(float)G.scene->r.frs_sec;
 
5688
        swaptime= 1.0/FPS;
4394
5689
 
4395
5690
        cfrao= CFRA;
4396
5691
        cfra=efra= SFRA;
4397
5692
        sfra= EFRA;
4398
 
        
 
5693
 
 
5694
        if (G.scene->audio.flag & AUDIO_SYNC) {
 
5695
                audiostream_start(cfra);
 
5696
        }
 
5697
 
4399
5698
        while(afbreek==0) {
4400
5699
                
4401
5700
                getmouseco_areawin(mval);
4405
5704
                        else firsttime= 0;
4406
5705
 
4407
5706
                        set_timecursor(cfra);
4408
 
                        
 
5707
        
4409
5708
                        /* do ipo: first all, then the specific ones */
4410
5709
                        if(anim==2) {
4411
5710
                                do_ob_ipo(ob);
4436
5735
 
4437
5736
                        /* minimal wait swaptime */
4438
5737
                        tottime -= swaptime;
4439
 
                        while (update_time()) PIL_sleep_ms(1);
 
5738
                        while (update_time(cfra)) PIL_sleep_ms(1);
4440
5739
 
4441
5740
                        screen_swapbuffers();
4442
5741
                        
4446
5745
                        mvalo[1]= mval[1];
4447
5746
                        
4448
5747
                        if(anim || (G.qual & LR_CTRLKEY)) {
4449
 
                                cfra++;
4450
 
                                if(cfra>EFRA) cfra= SFRA;
 
5748
                                if (G.scene->audio.flag & AUDIO_SYNC) {
 
5749
                                        cfra = audiostream_pos();
 
5750
                                } else {
 
5751
                                        cfra++;
 
5752
                                }
 
5753
                                if(cfra>EFRA) {
 
5754
                                        cfra= SFRA;
 
5755
                                        if (G.scene->audio.flag & AUDIO_SYNC) {
 
5756
                                                audiostream_stop();
 
5757
                                                audiostream_start( cfra );
 
5758
                                        }
 
5759
                                }
4451
5760
                        }
4452
5761
                }
4453
5762
                
4500
5809
        editipo_changed(G.sipo, 0);
4501
5810
        do_ipo(G.sipo->ipo);
4502
5811
        waitcursor(0);
 
5812
        if (G.scene->audio.flag & AUDIO_SYNC) {
 
5813
                audiostream_stop();
 
5814
        }
4503
5815
 
4504
5816
        allqueue(REDRAWVIEW3D, 0);
4505
5817
        if(sa) scrarea_queue_headredraw(sa);    /* headerprint */
4530
5842
        }
4531
5843
}
4532
5844
 
 
5845
/* Only delete the nominated keyframe from provided ipo-curve. 
 
5846
 * Not recommended to be used many times successively. For that
 
5847
 * there is delete_ipo_keys(). 
 
5848
 */
 
5849
void delete_icu_key(IpoCurve *icu, int index, short do_recalc)
 
5850
{
 
5851
        /* firstly check that index is valid */
 
5852
        if (index < 0) 
 
5853
                index *= -1;
 
5854
        if (icu == NULL) 
 
5855
                return;
 
5856
        if (index >= icu->totvert)
 
5857
                return;
 
5858
        
 
5859
        /*      Delete this key */
 
5860
        memmove(&icu->bezt[index], &icu->bezt[index+1], sizeof(BezTriple)*(icu->totvert-index-1));
 
5861
        icu->totvert--;
 
5862
        
 
5863
        /* recalc handles - only if it won't cause problems */
 
5864
        if (do_recalc)
 
5865
                calchandles_ipocurve(icu);
 
5866
}
 
5867
 
4533
5868
void delete_ipo_keys(Ipo *ipo)
4534
5869
{
4535
5870
        IpoCurve *icu, *next;
4536
5871
        int i;
4537
5872
        
4538
 
        if (!ipo)
 
5873
        if (ipo == NULL)
4539
5874
                return;
4540
5875
        
4541
 
        for (icu=ipo->curve.first; icu; icu=next){
 
5876
        for (icu= ipo->curve.first; icu; icu= next) {
4542
5877
                next = icu->next;
4543
 
                for (i=0; i<icu->totvert; i++){
4544
 
                        if (icu->bezt[i].f2 & 1){
4545
 
                                //      Delete the item
4546
 
                                memcpy (&icu->bezt[i], &icu->bezt[i+1], sizeof (BezTriple)*(icu->totvert-i-1));
 
5878
                
 
5879
                /* Delete selected BezTriples */
 
5880
                for (i=0; i<icu->totvert; i++) {
 
5881
                        if (icu->bezt[i].f2 & SELECT) {
 
5882
                                memmove(&icu->bezt[i], &icu->bezt[i+1], sizeof(BezTriple)*(icu->totvert-i-1));
4547
5883
                                icu->totvert--;
4548
5884
                                i--;
4549
5885
                        }
4550
5886
                }
4551
 
                if (!icu->totvert){
4552
 
                        /* Delete the curve */
4553
 
                        BLI_remlink( &(ipo->curve), icu);
 
5887
                
 
5888
                /* Only delete if there isn't an ipo-driver still hanging around on an empty curve */
 
5889
                if (icu->totvert==0 && icu->driver==NULL) {
 
5890
                        BLI_remlink(&ipo->curve, icu);
4554
5891
                        free_ipo_curve(icu);
4555
5892
                }
4556
5893
        }
4647
5984
                                                        id= G.sipo->from;
4648
5985
                                                        if(id && GS(id->name)==ID_OB ) {
4649
5986
                                                                Object *ob= (Object *)id;
4650
 
                                                                if(ob->sf!=0.0 && (ob->ipoflag & OB_OFFS_OB) ) {
4651
 
                                                                        cfra+= ob->sf/G.scene->r.framelen;
 
5987
                                                                if((ob->ipoflag & OB_OFFS_OB) && (give_timeoffset(ob)!=0.0) ) {
 
5988
                                                                        cfra+= give_timeoffset(ob)/G.scene->r.framelen;
4652
5989
                                                                }
4653
5990
                                                        }
4654
5991
                                                        CFRA= (int)floor(cfra+0.5);
4666
6003
        }
4667
6004
        BIF_undo_push("Set frame to selected Ipo vertex");
4668
6005
}
4669
 
 
4670
 
void bone2objectspace(float obSpaceBoneMat[][4], float obSpace[][4], float restPos[][4])
4671
 
{
4672
 
        float imat[4][4];
4673
 
 
4674
 
        Mat4Invert(imat, restPos);
4675
 
        Mat4MulMat4(obSpaceBoneMat, obSpace, imat);
4676
 
}
4677