1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
|
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation, Joshua Leung
* All rights reserved.
*
* Contributor(s): Joshua Leung
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "DNA_anim_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_key_types.h"
#include "DNA_gpencil_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "BKE_action.h"
#include "BKE_fcurve.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "UI_view2d.h"
#include "ED_anim_api.h"
#include "ED_keyframes_edit.h" // XXX move the select modes out of there!
#include "ED_screen.h"
#include "WM_api.h"
#include "WM_types.h"
/* ************************************************************************** */
/* CHANNELS API - Exposed API */
/* -------------------------- Selection ------------------------------------- */
/* Set the given animation-channel as the active one for the active context */
// TODO: extend for animdata types...
void ANIM_set_active_channel (bAnimContext *ac, void *data, short datatype, int filter, void *channel_data, short channel_type)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
/* try to build list of filtered items */
ANIM_animdata_filter(ac, &anim_data, filter, data, datatype);
if (anim_data.first == NULL)
return;
/* only clear the 'active' flag for the channels of the same type */
for (ale= anim_data.first; ale; ale= ale->next) {
/* skip if types don't match */
if (channel_type != ale->type)
continue;
/* flag to set depends on type */
switch (ale->type) {
case ANIMTYPE_GROUP:
{
bActionGroup *agrp= (bActionGroup *)ale->data;
ACHANNEL_SET_FLAG(agrp, ACHANNEL_SETFLAG_CLEAR, AGRP_ACTIVE);
}
break;
case ANIMTYPE_FCURVE:
{
FCurve *fcu= (FCurve *)ale->data;
ACHANNEL_SET_FLAG(fcu, ACHANNEL_SETFLAG_CLEAR, FCURVE_ACTIVE);
}
break;
case ANIMTYPE_NLATRACK:
{
NlaTrack *nlt= (NlaTrack *)ale->data;
ACHANNEL_SET_FLAG(nlt, ACHANNEL_SETFLAG_CLEAR, NLATRACK_ACTIVE);
}
break;
case ANIMTYPE_FILLACTD: /* Action Expander */
case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
case ANIMTYPE_DSLAM:
case ANIMTYPE_DSCAM:
case ANIMTYPE_DSCUR:
case ANIMTYPE_DSSKEY:
case ANIMTYPE_DSWOR:
case ANIMTYPE_DSPART:
case ANIMTYPE_DSMBALL:
case ANIMTYPE_DSARM:
case ANIMTYPE_DSMESH:
case ANIMTYPE_DSTEX:
case ANIMTYPE_DSLAT:
{
/* need to verify that this data is valid for now */
if (ale->adt) {
ACHANNEL_SET_FLAG(ale->adt, ACHANNEL_SETFLAG_CLEAR, ADT_UI_ACTIVE);
}
}
break;
}
}
/* set active flag */
if (channel_data) {
switch (channel_type) {
case ANIMTYPE_GROUP:
{
bActionGroup *agrp= (bActionGroup *)channel_data;
agrp->flag |= AGRP_ACTIVE;
}
break;
case ANIMTYPE_FCURVE:
{
FCurve *fcu= (FCurve *)channel_data;
fcu->flag |= FCURVE_ACTIVE;
}
break;
case ANIMTYPE_NLATRACK:
{
NlaTrack *nlt= (NlaTrack *)channel_data;
nlt->flag |= NLATRACK_ACTIVE;
}
break;
case ANIMTYPE_FILLACTD: /* Action Expander */
case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
case ANIMTYPE_DSLAM:
case ANIMTYPE_DSCAM:
case ANIMTYPE_DSCUR:
case ANIMTYPE_DSSKEY:
case ANIMTYPE_DSWOR:
case ANIMTYPE_DSPART:
case ANIMTYPE_DSMBALL:
case ANIMTYPE_DSARM:
case ANIMTYPE_DSMESH:
case ANIMTYPE_DSLAT:
{
/* need to verify that this data is valid for now */
// XXX: ale may be null!
if (ale->adt)
ale->adt->flag |= ADT_UI_ACTIVE;
}
break;
}
}
/* clean up */
BLI_freelistN(&anim_data);
}
/* Deselect all animation channels
* - data: pointer to datatype, as contained in bAnimContext
* - datatype: the type of data that 'data' represents (eAnimCont_Types)
* - test: check if deselecting instead of selecting
* - sel: eAnimChannels_SetFlag;
*/
void ANIM_deselect_anim_channels (bAnimContext *ac, void *data, short datatype, short test, short sel)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
/* filter data */
filter= ANIMFILTER_VISIBLE|ANIMFILTER_CHANNELS;
ANIM_animdata_filter(ac, &anim_data, filter, data, datatype);
/* See if we should be selecting or deselecting */
if (test) {
for (ale= anim_data.first; ale; ale= ale->next) {
if (sel == 0)
break;
switch (ale->type) {
case ANIMTYPE_SCENE:
if (ale->flag & SCE_DS_SELECTED)
sel= ACHANNEL_SETFLAG_CLEAR;
break;
case ANIMTYPE_OBJECT:
#if 0 /* for now, do not take object selection into account, since it gets too annoying */
if (ale->flag & SELECT)
sel= ACHANNEL_SETFLAG_CLEAR;
#endif
break;
case ANIMTYPE_GROUP:
if (ale->flag & AGRP_SELECTED)
sel= ACHANNEL_SETFLAG_CLEAR;
break;
case ANIMTYPE_FCURVE:
if (ale->flag & FCURVE_SELECTED)
sel= ACHANNEL_SETFLAG_CLEAR;
break;
case ANIMTYPE_SHAPEKEY:
if (ale->flag & KEYBLOCK_SEL)
sel= ACHANNEL_SETFLAG_CLEAR;
break;
case ANIMTYPE_NLATRACK:
if (ale->flag & NLATRACK_SELECTED)
sel= ACHANNEL_SETFLAG_CLEAR;
break;
case ANIMTYPE_FILLACTD: /* Action Expander */
case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
case ANIMTYPE_DSLAM:
case ANIMTYPE_DSCAM:
case ANIMTYPE_DSCUR:
case ANIMTYPE_DSSKEY:
case ANIMTYPE_DSWOR:
case ANIMTYPE_DSPART:
case ANIMTYPE_DSMBALL:
case ANIMTYPE_DSARM:
case ANIMTYPE_DSMESH:
case ANIMTYPE_DSNTREE:
case ANIMTYPE_DSTEX:
case ANIMTYPE_DSLAT:
{
if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED))
sel= ACHANNEL_SETFLAG_CLEAR;
}
break;
case ANIMTYPE_GPLAYER:
if (ale->flag & GP_LAYER_SELECT)
sel= ACHANNEL_SETFLAG_CLEAR;
break;
}
}
}
/* Now set the flags */
for (ale= anim_data.first; ale; ale= ale->next) {
switch (ale->type) {
case ANIMTYPE_SCENE:
{
Scene *scene= (Scene *)ale->data;
ACHANNEL_SET_FLAG(scene, sel, SCE_DS_SELECTED);
if (scene->adt) {
ACHANNEL_SET_FLAG(scene, sel, ADT_UI_SELECTED);
}
}
break;
case ANIMTYPE_OBJECT:
#if 0 /* for now, do not take object selection into account, since it gets too annoying */
{
Base *base= (Base *)ale->data;
Object *ob= base->object;
ACHANNEL_SET_FLAG(base, sel, SELECT);
ACHANNEL_SET_FLAG(ob, sel, SELECT);
if (ob->adt) {
ACHANNEL_SET_FLAG(ob, sel, ADT_UI_SELECTED);
}
}
#endif
break;
case ANIMTYPE_GROUP:
{
bActionGroup *agrp= (bActionGroup *)ale->data;
ACHANNEL_SET_FLAG(agrp, sel, AGRP_SELECTED);
agrp->flag &= ~AGRP_ACTIVE;
}
break;
case ANIMTYPE_FCURVE:
{
FCurve *fcu= (FCurve *)ale->data;
ACHANNEL_SET_FLAG(fcu, sel, FCURVE_SELECTED);
fcu->flag &= ~FCURVE_ACTIVE;
}
break;
case ANIMTYPE_SHAPEKEY:
{
KeyBlock *kb= (KeyBlock *)ale->data;
ACHANNEL_SET_FLAG(kb, sel, KEYBLOCK_SEL);
}
break;
case ANIMTYPE_NLATRACK:
{
NlaTrack *nlt= (NlaTrack *)ale->data;
ACHANNEL_SET_FLAG(nlt, sel, NLATRACK_SELECTED);
nlt->flag &= ~NLATRACK_ACTIVE;
}
break;
case ANIMTYPE_FILLACTD: /* Action Expander */
case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
case ANIMTYPE_DSLAM:
case ANIMTYPE_DSCAM:
case ANIMTYPE_DSCUR:
case ANIMTYPE_DSSKEY:
case ANIMTYPE_DSWOR:
case ANIMTYPE_DSPART:
case ANIMTYPE_DSMBALL:
case ANIMTYPE_DSARM:
case ANIMTYPE_DSMESH:
case ANIMTYPE_DSNTREE:
case ANIMTYPE_DSTEX:
case ANIMTYPE_DSLAT:
{
/* need to verify that this data is valid for now */
if (ale->adt) {
ACHANNEL_SET_FLAG(ale->adt, sel, ADT_UI_SELECTED);
ale->adt->flag &= ~ADT_UI_ACTIVE;
}
}
break;
case ANIMTYPE_GPLAYER:
{
bGPDlayer *gpl = (bGPDlayer *)ale->data;
ACHANNEL_SET_FLAG(gpl, sel, GP_LAYER_SELECT);
}
break;
}
}
/* Cleanup */
BLI_freelistN(&anim_data);
}
/* ---------------------------- Graph Editor ------------------------------------- */
/* Flush visibility (for Graph Editor) changes up/down hierarchy for changes in the given setting
* - anim_data: list of the all the anim channels that can be chosen
* -> filtered using ANIMFILTER_CHANNELS only, since if we took VISIBLE too,
* then the channels under closed expanders get ignored...
* - ale_setting: the anim channel (not in the anim_data list directly, though occuring there)
* with the new state of the setting that we want flushed up/down the hierarchy
* - setting: type of setting to set
* - on: whether the visibility setting has been enabled or disabled
*/
void ANIM_flush_setting_anim_channels (bAnimContext *ac, ListBase *anim_data, bAnimListElem *ale_setting, int setting, short on)
{
bAnimListElem *ale, *match=NULL;
int prevLevel=0, matchLevel=0;
/* sanity check */
if (ELEM(NULL, anim_data, anim_data->first))
return;
/* find the channel that got changed */
for (ale= anim_data->first; ale; ale= ale->next) {
/* compare data, and type as main way of identifying the channel */
if ((ale->data == ale_setting->data) && (ale->type == ale_setting->type)) {
/* we also have to check the ID, this is assigned to, since a block may have multiple users */
// TODO: is the owner-data more revealing?
if (ale->id == ale_setting->id) {
match= ale;
break;
}
}
}
if (match == NULL) {
printf("ERROR: no channel matching the one changed was found \n");
return;
}
else {
bAnimChannelType *acf= ANIM_channel_get_typeinfo(ale_setting);
if (acf == NULL) {
printf("ERROR: no channel info for the changed channel \n");
return;
}
/* get the level of the channel that was affected
* - we define the level as simply being the offset for the start of the channel
*/
matchLevel= (acf->get_offset)? acf->get_offset(ac, ale_setting) : 0;
prevLevel= matchLevel;
}
/* flush up?
*
* For Visibility:
* - only flush up if the current state is now enabled (positive 'on' state is default)
* (otherwise, it's too much work to force the parents to be inactive too)
*
* For everything else:
* - only flush up if the current state is now disabled (negative 'off' state is default)
* (otherwise, it's too much work to force the parents to be active too)
*/
if ( ((setting == ACHANNEL_SETTING_VISIBLE) && on) ||
((setting != ACHANNEL_SETTING_VISIBLE) && on==0) )
{
/* go backwards in the list, until the highest-ranking element (by indention has been covered) */
for (ale= match->prev; ale; ale= ale->prev) {
bAnimChannelType *acf= ANIM_channel_get_typeinfo(ale);
int level;
/* if no channel info was found, skip, since this type might not have any useful info */
if (acf == NULL)
continue;
/* get the level of the current channel traversed
* - we define the level as simply being the offset for the start of the channel
*/
level= (acf->get_offset)? acf->get_offset(ac, ale) : 0;
/* if the level is 'less than' (i.e. more important) the level we're matching
* but also 'less than' the level just tried (i.e. only the 1st group above grouped F-Curves,
* when toggling visibility of F-Curves, gets flushed, which should happen if we don't let prevLevel
* get updated below once the first 1st group is found)...
*/
if (level < prevLevel) {
/* flush the new status... */
ANIM_channel_setting_set(ac, ale, setting, on);
/* store this level as the 'old' level now */
prevLevel= level;
}
/* if the level is 'greater than' (i.e. less important) than the previous level... */
else if (level > prevLevel) {
/* if previous level was a base-level (i.e. 0 offset / root of one hierarchy),
* stop here
*/
if (prevLevel == 0)
break;
/* otherwise, this level weaves into another sibling hierarchy to the previous one just
* finished, so skip until we get to the parent of this level
*/
else
continue;
}
}
}
/* flush down (always) */
{
/* go forwards in the list, until the lowest-ranking element (by indention has been covered) */
for (ale= match->next; ale; ale= ale->next) {
bAnimChannelType *acf= ANIM_channel_get_typeinfo(ale);
int level;
/* if no channel info was found, skip, since this type might not have any useful info */
if (acf == NULL)
continue;
/* get the level of the current channel traversed
* - we define the level as simply being the offset for the start of the channel
*/
level= (acf->get_offset)? acf->get_offset(ac, ale) : 0;
/* if the level is 'greater than' (i.e. less important) the channel that was changed,
* flush the new status...
*/
if (level > matchLevel)
ANIM_channel_setting_set(ac, ale, setting, on);
/* however, if the level is 'less than or equal to' the channel that was changed,
* (i.e. the current channel is as important if not more important than the changed channel)
* then we should stop, since we've found the last one of the children we should flush
*/
else
break;
/* store this level as the 'old' level now */
prevLevel= level; // XXX: prevLevel is unused
}
}
}
/* -------------------------- F-Curves ------------------------------------- */
/* Delete the given F-Curve from its AnimData block */
void ANIM_fcurve_delete_from_animdata (bAnimContext *ac, AnimData *adt, FCurve *fcu)
{
/* - if no AnimData, we've got nowhere to remove the F-Curve from
* (this doesn't guarantee that the F-Curve is in there, but at least we tried
* - if no F-Curve, there is nothing to remove
*/
if (ELEM(NULL, adt, fcu))
return;
/* remove from whatever list it came from
* - Action Group
* - Action
* - Drivers
* - TODO... some others?
*/
if (fcu->grp)
action_groups_remove_channel(adt->action, fcu);
else if ((ac) && (ac->datatype == ANIMCONT_DRIVERS))
BLI_remlink(&adt->drivers, fcu);
else if (adt->action)
BLI_remlink(&adt->action->curves, fcu);
/* free the F-Curve itself */
free_fcurve(fcu);
}
/* ************************************************************************** */
/* OPERATORS */
/* ****************** Operator Utilities ********************************** */
/* poll callback for being in an Animation Editor channels list region */
int animedit_poll_channels_active (bContext *C)
{
ScrArea *sa= CTX_wm_area(C);
/* channels region test */
// TODO: could enhance with actually testing if channels region?
if (ELEM(NULL, sa, CTX_wm_region(C)))
return 0;
/* animation editor test */
if (ELEM3(sa->spacetype, SPACE_ACTION, SPACE_IPO, SPACE_NLA) == 0)
return 0;
return 1;
}
/* poll callback for Animation Editor channels list region + not in NLA-tweakmode for NLA */
int animedit_poll_channels_nla_tweakmode_off (bContext *C)
{
ScrArea *sa= CTX_wm_area(C);
Scene *scene = CTX_data_scene(C);
/* channels region test */
// TODO: could enhance with actually testing if channels region?
if (ELEM(NULL, sa, CTX_wm_region(C)))
return 0;
/* animation editor test */
if (ELEM3(sa->spacetype, SPACE_ACTION, SPACE_IPO, SPACE_NLA) == 0)
return 0;
/* NLA TweakMode test */
if (sa->spacetype == SPACE_NLA) {
if ((scene == NULL) || (scene->flag & SCE_NLA_EDIT_ON))
return 0;
}
return 1;
}
/* ****************** Rearrange Channels Operator ******************* */
/* constants for channel rearranging */
/* WARNING: don't change exising ones without modifying rearrange func accordingly */
enum {
REARRANGE_ANIMCHAN_TOP= -2,
REARRANGE_ANIMCHAN_UP= -1,
REARRANGE_ANIMCHAN_DOWN= 1,
REARRANGE_ANIMCHAN_BOTTOM= 2
};
/* defines for rearranging channels */
EnumPropertyItem prop_animchannel_rearrange_types[] = {
{REARRANGE_ANIMCHAN_TOP, "TOP", 0, "To Top", ""},
{REARRANGE_ANIMCHAN_UP, "UP", 0, "Up", ""},
{REARRANGE_ANIMCHAN_DOWN, "DOWN", 0, "Down", ""},
{REARRANGE_ANIMCHAN_BOTTOM, "BOTTOM", 0, "To Bottom", ""},
{0, NULL, 0, NULL, NULL}
};
/* Rearrange Utilities --------------------------------------------- */
/* checks if a channel should be considered for moving */
static short rearrange_animchannel_is_ok (Link *channel, short type)
{
if (type == ANIMTYPE_GROUP) {
bActionGroup *agrp= (bActionGroup *)channel;
if (SEL_AGRP(agrp) && !(agrp->flag & AGRP_MOVED))
return 1;
}
else if (type == ANIMTYPE_FCURVE) {
FCurve *fcu= (FCurve *)channel;
// FIXME: F-Curve visibility is difficult... needs special filtering tests these days...
if (SEL_FCU(fcu) && !(fcu->flag & FCURVE_TAGGED))
return 1;
}
else if (type == ANIMTYPE_NLATRACK) {
NlaTrack *nlt = (NlaTrack *)channel;
if (SEL_NLT(nlt) && !(nlt->flag & NLASTRIP_FLAG_EDIT_TOUCHED))
return 1;
}
return 0;
}
/* checks if another channel can be placed after the given one */
static short rearrange_animchannel_after_ok (Link *channel, short type)
{
if (type == ANIMTYPE_GROUP) {
bActionGroup *agrp= (bActionGroup *)channel;
if (agrp->flag & AGRP_TEMP)
return 0;
}
return 1;
}
/* Rearrange Methods --------------------------------------------- */
static short rearrange_animchannel_top (ListBase *list, Link *channel, short type)
{
if (rearrange_animchannel_is_ok(channel, type)) {
/* take it out off the chain keep data */
BLI_remlink(list, channel);
/* make it first element */
BLI_insertlinkbefore(list, list->first, channel);
return 1;
}
return 0;
}
static short rearrange_animchannel_up (ListBase *list, Link *channel, short type)
{
if (rearrange_animchannel_is_ok(channel, type)) {
Link *prev= channel->prev;
if (prev) {
/* take it out off the chain keep data */
BLI_remlink(list, channel);
/* push it up */
BLI_insertlinkbefore(list, prev, channel);
return 1;
}
}
return 0;
}
static short rearrange_animchannel_down (ListBase *list, Link *channel, short type)
{
if (rearrange_animchannel_is_ok(channel, type)) {
Link *next = (channel->next) ? channel->next->next : NULL;
if (next) {
/* take it out off the chain keep data */
BLI_remlink(list, channel);
/* move it down */
BLI_insertlinkbefore(list, next, channel);
return 1;
}
else if (rearrange_animchannel_after_ok(list->last, type)) {
/* take it out off the chain keep data */
BLI_remlink(list, channel);
/* add at end */
BLI_addtail(list, channel);
return 1;
}
else {
/* take it out off the chain keep data */
BLI_remlink(list, channel);
/* add just before end */
BLI_insertlinkbefore(list, list->last, channel);
return 1;
}
}
return 0;
}
static short rearrange_animchannel_bottom (ListBase *list, Link *channel, short type)
{
if (rearrange_animchannel_is_ok(channel, type)) {
if (rearrange_animchannel_after_ok(list->last, type)) {
/* take it out off the chain keep data */
BLI_remlink(list, channel);
/* add at end */
BLI_addtail(list, channel);
return 1;
}
}
return 0;
}
/* Generic Stuff ---------------------------------------------------------- */
/* typedef for channel rearranging function
* < list: list that channels belong to
* < channel: channel to be moved
* < type: type of channel (eAnim_ChannelType)
* > return[0]: whether operation was a success
*/
typedef short (*AnimChanRearrangeFp)(ListBase *list, Link *channel, short type);
/* get rearranging function, given 'rearrange' mode */
static AnimChanRearrangeFp rearrange_get_mode_func (short mode)
{
switch (mode) {
case REARRANGE_ANIMCHAN_TOP:
return rearrange_animchannel_top;
case REARRANGE_ANIMCHAN_UP:
return rearrange_animchannel_up;
case REARRANGE_ANIMCHAN_DOWN:
return rearrange_animchannel_down;
case REARRANGE_ANIMCHAN_BOTTOM:
return rearrange_animchannel_bottom;
default:
return NULL;
}
}
/* ........ */
/* These iteration helpers (ideally should be inlined, but probably not necessary) */
static Link *rearrange_iter_first (ListBase *list, short mode)
{
return (mode > 0) ? list->first : list->last;
}
static Link *rearrange_iter_next (Link *item, short mode)
{
return (mode > 0) ? item->next : item->prev;
}
/* ........ */
/* Clear 'tag' on all F-Curves */
static void rearrange_clear_fcurve_tags (ListBase *list)
{
FCurve *fcu;
for (fcu = list->first; fcu; fcu = fcu->next)
fcu->flag &= ~FCURVE_TAGGED;
}
/* NLA Specific Stuff ----------------------------------------------------- */
/* Change the order NLA Tracks within NLA Stack
* ! NLA tracks are displayed in opposite order, so directions need care
* mode: REARRANGE_ANIMCHAN_*
*/
static void rearrange_nla_channels (bAnimContext *UNUSED(ac), AnimData *adt, short mode)
{
NlaTrack *nlt, *track;
AnimChanRearrangeFp rearrange_func;
/* hack: invert mode so that functions will work in right order */
mode *= -1;
/* get rearranging function */
rearrange_func = rearrange_get_mode_func(mode);
if (rearrange_func == NULL)
return;
/* only consider NLA data if it's accessible */
//if (EXPANDED_DRVD(adt) == 0)
// return;
/* clear "moved" flag from all tracks */
for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next)
nlt->flag &= ~NLASTRIP_FLAG_EDIT_TOUCHED;
/* reorder all selected tracks */
for (nlt= (NlaTrack *)rearrange_iter_first(&adt->nla_tracks, mode); nlt; nlt= track) {
/* Get next channel to consider */
track= (NlaTrack *)rearrange_iter_next((Link *)nlt, mode);
/* Try to do channel */
if (rearrange_func(&adt->nla_tracks, (Link *)nlt, ANIMTYPE_NLATRACK))
nlt->flag |= NLASTRIP_FLAG_EDIT_TOUCHED;
}
/* clear "moved" flag from all tracks */
for (nlt= adt->nla_tracks.first; nlt; nlt= nlt->next)
nlt->flag &= ~NLASTRIP_FLAG_EDIT_TOUCHED;
}
/* Drivers Specific Stuff ------------------------------------------------- */
/* Change the order drivers within AnimData block
* mode: REARRANGE_ANIMCHAN_*
*/
static void rearrange_driver_channels (bAnimContext *UNUSED(ac), AnimData *adt, short mode)
{
FCurve *fcu, *fcun;
/* get rearranging function */
AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode);
if (rearrange_func == NULL)
return;
/* only consider drivers if they're accessible */
if (EXPANDED_DRVD(adt) == 0)
return;
rearrange_clear_fcurve_tags(&adt->drivers);
/* reorder all selected driver F-Curves */
for (fcu= (FCurve *)rearrange_iter_first(&adt->drivers, mode); fcu; fcu= fcun) {
/* Get next channel to consider */
fcun= (FCurve *)rearrange_iter_next((Link *)fcu, mode);
/* Try to do channel */
if (rearrange_func(&adt->drivers, (Link *)fcu, ANIMTYPE_FCURVE))
fcu->flag |= FCURVE_TAGGED;
}
rearrange_clear_fcurve_tags(&adt->drivers);
}
/* Action Specific Stuff ------------------------------------------------- */
/* make sure all action-channels belong to a group (and clear action's list) */
static void split_groups_action_temp (bAction *act, bActionGroup *tgrp)
{
bActionGroup *agrp;
FCurve *fcu;
if (act == NULL)
return;
/* clear "moved" flag from all FCurves */
rearrange_clear_fcurve_tags(&act->curves);
/* Separate F-Curves into lists per group */
for (agrp= act->groups.first; agrp; agrp= agrp->next) {
if (agrp->channels.first) {
fcu= agrp->channels.last;
act->curves.first= fcu->next;
fcu= agrp->channels.first;
fcu->prev= NULL;
fcu= agrp->channels.last;
fcu->next= NULL;
}
}
/* Initialise memory for temp-group */
memset(tgrp, 0, sizeof(bActionGroup));
tgrp->flag |= (AGRP_EXPANDED|AGRP_TEMP);
BLI_strncpy(tgrp->name, "#TempGroup", sizeof(tgrp->name));
/* Move any action-channels not already moved, to the temp group */
if (act->curves.first) {
/* start of list */
fcu= act->curves.first;
fcu->prev= NULL;
tgrp->channels.first= fcu;
act->curves.first= NULL;
/* end of list */
fcu= act->curves.last;
fcu->next= NULL;
tgrp->channels.last= fcu;
act->curves.last= NULL;
}
/* Add temp-group to list */
BLI_addtail(&act->groups, tgrp);
}
/* link lists of channels that groups have */
static void join_groups_action_temp (bAction *act)
{
bActionGroup *agrp;
for (agrp= act->groups.first; agrp; agrp= agrp->next) {
ListBase tempGroup;
/* add list of channels to action's channels */
tempGroup= agrp->channels;
BLI_movelisttolist(&act->curves, &agrp->channels);
agrp->channels= tempGroup;
/* clear moved flag */
agrp->flag &= ~AGRP_MOVED;
/* if temp-group... remove from list (but don't free as it's on the stack!) */
if (agrp->flag & AGRP_TEMP) {
BLI_remlink(&act->groups, agrp);
break;
}
}
/* clear "moved" flag from all fcurve's */
rearrange_clear_fcurve_tags(&act->curves);
}
/* Change the order of anim-channels within action
* mode: REARRANGE_ANIMCHAN_*
*/
static void rearrange_action_channels (bAnimContext *ac, bAction *act, short mode)
{
bActionGroup *agrp, *grp;
bActionGroup tgrp;
FCurve *fcu, *fcun;
short do_channels = 1;
/* get rearranging function */
AnimChanRearrangeFp rearrange_func = rearrange_get_mode_func(mode);
if (rearrange_func == NULL)
return;
/* make sure we're only operating with groups */
split_groups_action_temp(act, &tgrp);
/* rearrange groups first (and then, only consider channels if the groups weren't moved) */
for (agrp= (bActionGroup *)rearrange_iter_first(&act->groups, mode); agrp; agrp= grp) {
/* Get next group to consider */
grp= (bActionGroup *)rearrange_iter_next((Link *)agrp, mode);
/* try to do group first */
if (rearrange_func(&act->groups, (Link *)agrp, ANIMTYPE_GROUP)) {
do_channels= 0;
agrp->flag |= AGRP_MOVED;
}
}
if (do_channels) {
for (agrp= (bActionGroup *)rearrange_iter_first(&act->groups, mode); agrp; agrp= grp) {
/* Get next group to consider */
grp= (bActionGroup *)rearrange_iter_next((Link *)agrp, mode);
/* only consider F-Curves if they're visible (group expanded) */
if (EXPANDED_AGRP(agrp)) {
for (fcu= (FCurve *)rearrange_iter_first(&agrp->channels, mode); fcu; fcu= fcun) {
/* Get next channel to consider */
fcun= (FCurve *)rearrange_iter_next((Link *)fcu, mode);
/* Try to do channel */
if (rearrange_func(&agrp->channels, (Link *)fcu, ANIMTYPE_FCURVE))
fcu->flag |= FCURVE_TAGGED;
}
}
}
}
/* assemble lists into one list (and clear moved tags) */
join_groups_action_temp(act);
}
/* ------------------- */
static int animchannels_rearrange_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
short mode;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* get mode */
mode= RNA_enum_get(op->ptr, "direction");
/* get animdata blocks */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_ANIMDATA);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
for (ale = anim_data.first; ale; ale = ale->next) {
AnimData *adt= ale->data;
switch (ac.datatype) {
case ANIMCONT_NLA: /* NLA-tracks only */
rearrange_nla_channels(&ac, adt, mode);
break;
case ANIMCONT_DRIVERS: /* Drivers list only */
rearrange_driver_channels(&ac, adt, mode);
break;
case ANIMCONT_GPENCIL: /* Grease Pencil channels */
// FIXME: this case probably needs to get moved out of here or treated specially...
printf("grease pencil not supported for moving yet\n");
break;
case ANIMCONT_SHAPEKEY: // DOUBLE CHECK ME...
default: /* some collection of actions */
// FIXME: actions should only be considered once!
if (adt->action)
rearrange_action_channels(&ac, adt->action, mode);
else
printf("animdata has no action\n");
break;
}
}
/* free temp data */
BLI_freelistN(&anim_data);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_move (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Move Channels";
ot->idname= "ANIM_OT_channels_move";
ot->description = "Rearrange selected animation channels";
/* api callbacks */
ot->exec= animchannels_rearrange_exec;
ot->poll= animedit_poll_channels_nla_tweakmode_off;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
RNA_def_enum(ot->srna, "direction", prop_animchannel_rearrange_types, REARRANGE_ANIMCHAN_DOWN, "Direction", "");
}
/* ******************** Delete Channel Operator *********************** */
static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op))
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* cannot delete in shapekey */
if (ac.datatype == ANIMCONT_SHAPEKEY)
return OPERATOR_CANCELLED;
/* do groups only first (unless in Drivers mode, where there are none) */
if (ac.datatype != ANIMCONT_DRIVERS) {
/* filter data */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_CHANNELS | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* delete selected groups and their associated channels */
for (ale= anim_data.first; ale; ale= ale->next) {
/* only groups - don't check other types yet, since they may no-longer exist */
if (ale->type == ANIMTYPE_GROUP) {
bActionGroup *agrp= (bActionGroup *)ale->data;
AnimData *adt= ale->adt;
FCurve *fcu, *fcn;
/* skip this group if no AnimData available, as we can't safely remove the F-Curves */
if (adt == NULL)
continue;
/* delete all of the Group's F-Curves, but no others */
for (fcu= agrp->channels.first; fcu && fcu->grp==agrp; fcu= fcn) {
fcn= fcu->next;
/* remove from group and action, then free */
action_groups_remove_channel(adt->action, fcu);
free_fcurve(fcu);
}
/* free the group itself */
if (adt->action)
BLI_freelinkN(&adt->action->groups, agrp);
else
MEM_freeN(agrp);
}
}
/* cleanup */
BLI_freelistN(&anim_data);
}
/* now do F-Curves */
if (ac.datatype != ANIMCONT_GPENCIL) {
/* filter data */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* delete selected F-Curves */
for (ale= anim_data.first; ale; ale= ale->next) {
/* only F-Curves, and only if we can identify its parent */
if (ale->type == ANIMTYPE_FCURVE) {
AnimData *adt= ale->adt;
FCurve *fcu= (FCurve *)ale->data;
/* try to free F-Curve */
ANIM_fcurve_delete_from_animdata(&ac, adt, fcu);
}
}
/* cleanup */
BLI_freelistN(&anim_data);
}
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_delete (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Delete Channels";
ot->idname= "ANIM_OT_channels_delete";
ot->description= "Delete all selected animation channels";
/* api callbacks */
ot->exec= animchannels_delete_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* ******************** Set Channel Visibility Operator *********************** */
/* NOTE: this operator is only valid in the Graph Editor channels region */
static int animchannels_visibility_set_exec(bContext *C, wmOperator *UNUSED(op))
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
ListBase all_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* get list of all channels that selection may need to be flushed to */
filter= ANIMFILTER_CHANNELS;
ANIM_animdata_filter(&ac, &all_data, filter, ac.data, ac.datatype);
/* hide all channels not selected */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_UNSEL | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
for (ale= anim_data.first; ale; ale= ale->next) {
/* clear setting first */
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR);
/* now also flush selection status as appropriate
* NOTE: in some cases, this may result in repeat flushing being performed
*/
ANIM_flush_setting_anim_channels(&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, 0);
}
BLI_freelistN(&anim_data);
/* make all the selected channels visible */
filter= (ANIMFILTER_SEL | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
for (ale= anim_data.first; ale; ale= ale->next) {
/* hack: skip object channels for now, since flushing those will always flush everything, but they are always included */
// TODO: find out why this is the case, and fix that
if (ale->type == ANIMTYPE_OBJECT)
continue;
/* enable the setting */
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
/* now, also flush selection status up/down as appropriate */
ANIM_flush_setting_anim_channels(&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, 1);
}
BLI_freelistN(&anim_data);
BLI_freelistN(&all_data);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_visibility_set (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Set Visibility";
ot->idname= "ANIM_OT_channels_visibility_set";
ot->description= "Make only the selected animation channels visible in the Graph Editor";
/* api callbacks */
ot->exec= animchannels_visibility_set_exec;
ot->poll= ED_operator_graphedit_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* ******************** Toggle Channel Visibility Operator *********************** */
/* NOTE: this operator is only valid in the Graph Editor channels region */
static int animchannels_visibility_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
ListBase all_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
short vis= ACHANNEL_SETFLAG_ADD;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* get list of all channels that selection may need to be flushed to */
filter= (ANIMFILTER_CHANNELS | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &all_data, filter, ac.data, ac.datatype);
/* filter data */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* See if we should be making showing all selected or hiding */
for (ale= anim_data.first; ale; ale= ale->next) {
/* set the setting in the appropriate way (if available) */
if (ANIM_channel_setting_get(&ac, ale, ACHANNEL_SETTING_VISIBLE)) {
vis= ACHANNEL_SETFLAG_CLEAR;
break;
}
}
/* Now set the flags */
for (ale= anim_data.first; ale; ale= ale->next) {
/* hack: skip object channels for now, since flushing those will always flush everything, but they are always included */
// TODO: find out why this is the case, and fix that
if (ale->type == ANIMTYPE_OBJECT)
continue;
/* change the setting */
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, vis);
/* now, also flush selection status up/down as appropriate */
ANIM_flush_setting_anim_channels(&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, (vis == ACHANNEL_SETFLAG_ADD));
}
/* cleanup */
BLI_freelistN(&anim_data);
BLI_freelistN(&all_data);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_visibility_toggle (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Toggle Visibility";
ot->idname= "ANIM_OT_channels_visibility_toggle";
ot->description= "Toggle visibility in Graph Editor of all selected animation channels";
/* api callbacks */
ot->exec= animchannels_visibility_toggle_exec;
ot->poll= ED_operator_graphedit_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* ********************** Set Flags Operator *********************** */
/* defines for setting animation-channel flags */
EnumPropertyItem prop_animchannel_setflag_types[] = {
{ACHANNEL_SETFLAG_TOGGLE, "TOGGLE", 0, "Toggle", ""},
{ACHANNEL_SETFLAG_CLEAR, "DISABLE", 0, "Disable", ""},
{ACHANNEL_SETFLAG_ADD, "ENABLE", 0, "Enable", ""},
{ACHANNEL_SETFLAG_INVERT, "INVERT", 0, "Invert", ""},
{0, NULL, 0, NULL, NULL}
};
/* defines for set animation-channel settings */
// TODO: could add some more types, but those are really quite dependent on the mode...
EnumPropertyItem prop_animchannel_settings_types[] = {
{ACHANNEL_SETTING_PROTECT, "PROTECT", 0, "Protect", ""},
{ACHANNEL_SETTING_MUTE, "MUTE", 0, "Mute", ""},
{0, NULL, 0, NULL, NULL}
};
/* ------------------- */
/* macro to be used in setflag_anim_channels */
#define ASUBCHANNEL_SEL_OK(ale) ( (onlysel == 0) || \
((ale->id) && (GS(ale->id->name)==ID_OB) && (((Object *)ale->id)->flag & SELECT)) )
/* Set/clear a particular flag (setting) for all selected + visible channels
* setting: the setting to modify
* mode: eAnimChannels_SetFlag
* onlysel: only selected channels get the flag set
*/
// TODO: enable a setting which turns flushing on/off?
static void setflag_anim_channels (bAnimContext *ac, short setting, short mode, short onlysel, short flush)
{
ListBase anim_data = {NULL, NULL};
ListBase all_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
/* filter data that we need if flush is on */
if (flush) {
/* get list of all channels that selection may need to be flushed to */
filter= ANIMFILTER_CHANNELS;
ANIM_animdata_filter(ac, &all_data, filter, ac->data, ac->datatype);
}
/* filter data that we're working on */
// XXX: noduplis enabled so that results don't cancel, but will be problematic for some channels where only type differs
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS | ANIMFILTER_NODUPLIS);
if (onlysel) filter |= ANIMFILTER_SEL;
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* if toggling, check if disable or enable */
if (mode == ACHANNEL_SETFLAG_TOGGLE) {
/* default to turn all on, unless we encounter one that's on... */
mode= ACHANNEL_SETFLAG_ADD;
/* see if we should turn off instead... */
for (ale= anim_data.first; ale; ale= ale->next) {
/* set the setting in the appropriate way (if available) */
if (ANIM_channel_setting_get(ac, ale, setting) > 0) {
mode= ACHANNEL_SETFLAG_CLEAR;
break;
}
}
}
/* apply the setting */
for (ale= anim_data.first; ale; ale= ale->next) {
/* skip channel if setting is not available */
if (ANIM_channel_setting_get(ac, ale, setting) == -1)
continue;
/* set the setting in the appropriate way */
ANIM_channel_setting_set(ac, ale, setting, mode);
/* if flush status... */
if (flush)
ANIM_flush_setting_anim_channels(ac, &all_data, ale, setting, mode);
}
BLI_freelistN(&anim_data);
BLI_freelistN(&all_data);
}
/* ------------------- */
static int animchannels_setflag_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
short mode, setting;
short flush=1;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* mode (eAnimChannels_SetFlag), setting (eAnimChannel_Settings) */
mode= RNA_enum_get(op->ptr, "mode");
setting= RNA_enum_get(op->ptr, "type");
/* check if setting is flushable */
if (setting == ACHANNEL_SETTING_EXPAND)
flush= 0;
/* modify setting
* - only selected channels are affected
*/
setflag_anim_channels(&ac, setting, mode, 1, flush);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_setting_enable (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Enable Channel Setting";
ot->idname= "ANIM_OT_channels_setting_enable";
ot->description= "Enable specified setting on all selected animation channels";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= animchannels_setflag_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
/* flag-setting mode */
RNA_def_enum(ot->srna, "mode", prop_animchannel_setflag_types, ACHANNEL_SETFLAG_ADD, "Mode", "");
/* setting to set */
ot->prop= RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, 0, "Type", "");
}
void ANIM_OT_channels_setting_disable (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Disable Channel Setting";
ot->idname= "ANIM_OT_channels_setting_disable";
ot->description= "Disable specified setting on all selected animation channels";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= animchannels_setflag_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
/* flag-setting mode */
RNA_def_enum(ot->srna, "mode", prop_animchannel_setflag_types, ACHANNEL_SETFLAG_CLEAR, "Mode", "");
/* setting to set */
ot->prop= RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, 0, "Type", "");
}
void ANIM_OT_channels_setting_invert (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Invert Channel Setting";
ot->idname= "ANIM_OT_channels_setting_toggle";
ot->description= "Invert specified setting on all selected animation channels";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= animchannels_setflag_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
/* flag-setting mode */
RNA_def_enum(ot->srna, "mode", prop_animchannel_setflag_types, ACHANNEL_SETFLAG_INVERT, "Mode", "");
/* setting to set */
ot->prop= RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, 0, "Type", "");
}
void ANIM_OT_channels_setting_toggle (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Toggle Channel Setting";
ot->idname= "ANIM_OT_channels_setting_toggle";
ot->description= "Toggle specified setting on all selected animation channels";
/* api callbacks */
ot->invoke= WM_menu_invoke;
ot->exec= animchannels_setflag_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
/* flag-setting mode */
RNA_def_enum(ot->srna, "mode", prop_animchannel_setflag_types, ACHANNEL_SETFLAG_TOGGLE, "Mode", "");
/* setting to set */
ot->prop= RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, 0, "Type", "");
}
void ANIM_OT_channels_editable_toggle (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Toggle Channel Editability";
ot->idname= "ANIM_OT_channels_editable_toggle";
ot->description= "Toggle editability of selected channels";
/* api callbacks */
ot->exec= animchannels_setflag_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
/* flag-setting mode */
RNA_def_enum(ot->srna, "mode", prop_animchannel_setflag_types, ACHANNEL_SETFLAG_TOGGLE, "Mode", "");
/* setting to set */
RNA_def_enum(ot->srna, "type", prop_animchannel_settings_types, ACHANNEL_SETTING_PROTECT, "Type", "");
}
/* ********************** Expand Channels Operator *********************** */
static int animchannels_expand_exec (bContext *C, wmOperator *op)
{
bAnimContext ac;
short onlysel= 1;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* only affect selected channels? */
if (RNA_boolean_get(op->ptr, "all"))
onlysel= 0;
/* modify setting */
setflag_anim_channels(&ac, ACHANNEL_SETTING_EXPAND, ACHANNEL_SETFLAG_ADD, onlysel, 0);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_expand (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Expand Channels";
ot->idname= "ANIM_OT_channels_expand";
ot->description= "Expand (i.e. open) all selected expandable animation channels";
/* api callbacks */
ot->exec= animchannels_expand_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
ot->prop= RNA_def_boolean(ot->srna, "all", 1, "All", "Expand all channels (not just selected ones)");
}
/* ********************** Collapse Channels Operator *********************** */
static int animchannels_collapse_exec (bContext *C, wmOperator *op)
{
bAnimContext ac;
short onlysel= 1;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* only affect selected channels? */
if (RNA_boolean_get(op->ptr, "all"))
onlysel= 0;
/* modify setting */
setflag_anim_channels(&ac, ACHANNEL_SETTING_EXPAND, ACHANNEL_SETFLAG_CLEAR, onlysel, 0);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_collapse (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Collapse Channels";
ot->idname= "ANIM_OT_channels_collapse";
ot->description= "Collapse (i.e. close) all selected expandable animation channels";
/* api callbacks */
ot->exec= animchannels_collapse_exec;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
ot->prop= RNA_def_boolean(ot->srna, "all", 1, "All", "Collapse all channels (not just selected ones)");
}
/* ******************* Reenable Disabled Operator ******************* */
static int animchannels_enable_poll (bContext *C)
{
ScrArea *sa= CTX_wm_area(C);
/* channels region test */
// TODO: could enhance with actually testing if channels region?
if (ELEM(NULL, sa, CTX_wm_region(C)))
return 0;
/* animation editor test - Action/Dopesheet/etc. and Graph only */
if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_IPO) == 0)
return 0;
return 1;
}
static int animchannels_enable_exec (bContext *C, wmOperator *UNUSED(op))
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* filter data */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVESONLY | ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* loop through filtered data and clean curves */
for (ale= anim_data.first; ale; ale= ale->next) {
FCurve *fcu = (FCurve *)ale->data;
fcu->flag &= ~FCURVE_DISABLED;
}
/* free temp data */
BLI_freelistN(&anim_data);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_fcurves_enable (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Revive Disabled F-Curves";
ot->idname= "ANIM_OT_channels_fcurves_enable";
ot->description= "Clears 'disabled' tag from all F-Curves to get broken F-Curves working again";
/* api callbacks */
ot->exec= animchannels_enable_exec;
ot->poll= animchannels_enable_poll;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* ********************** Select All Operator *********************** */
static int animchannels_deselectall_exec (bContext *C, wmOperator *op)
{
bAnimContext ac;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* 'standard' behaviour - check if selected, then apply relevant selection */
if (RNA_boolean_get(op->ptr, "invert"))
ANIM_deselect_anim_channels(&ac, ac.data, ac.datatype, 0, ACHANNEL_SETFLAG_TOGGLE);
else
ANIM_deselect_anim_channels(&ac, ac.data, ac.datatype, 1, ACHANNEL_SETFLAG_ADD);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_SELECTED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_select_all_toggle (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Select All";
ot->idname= "ANIM_OT_channels_select_all_toggle";
ot->description= "Toggle selection of all animation channels";
/* api callbacks */
ot->exec= animchannels_deselectall_exec;
ot->poll= animedit_poll_channels_nla_tweakmode_off;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* props */
ot->prop= RNA_def_boolean(ot->srna, "invert", 0, "Invert", "");
}
/* ******************** Borderselect Operator *********************** */
static void borderselect_anim_channels (bAnimContext *ac, rcti *rect, short selectmode)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
View2D *v2d= &ac->ar->v2d;
rctf rectf;
float ymin, ymax;
/* set initial y extents */
if (ac->datatype == ANIMCONT_NLA) {
ymin = (float)(-NLACHANNEL_HEIGHT);
ymax = 0.0f;
}
else {
ymin = 0.0f;
ymax = (float)(-ACHANNEL_HEIGHT);
}
/* convert border-region to view coordinates */
UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin+2, &rectf.xmin, &rectf.ymin);
UI_view2d_region_to_view(v2d, rect->xmax, rect->ymax-2, &rectf.xmax, &rectf.ymax);
/* filter data */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS);
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* loop over data, doing border select */
for (ale= anim_data.first; ale; ale= ale->next) {
if (ac->datatype == ANIMCONT_NLA)
ymin= ymax - NLACHANNEL_STEP;
else
ymin= ymax - ACHANNEL_STEP;
/* if channel is within border-select region, alter it */
if (!((ymax < rectf.ymin) || (ymin > rectf.ymax))) {
/* set selection flags only */
ANIM_channel_setting_set(ac, ale, ACHANNEL_SETTING_SELECT, selectmode);
/* type specific actions */
switch (ale->type) {
case ANIMTYPE_GROUP:
{
bActionGroup *agrp= (bActionGroup *)ale->data;
/* always clear active flag after doing this */
agrp->flag &= ~AGRP_ACTIVE;
}
break;
case ANIMTYPE_NLATRACK:
{
NlaTrack *nlt= (NlaTrack *)ale->data;
/* for now, it's easier just to do this here manually, as defining a new type
* currently adds complications when doing other stuff
*/
ACHANNEL_SET_FLAG(nlt, selectmode, NLATRACK_SELECTED);
}
break;
}
}
/* set minimum extent to be the maximum of the next channel */
ymax= ymin;
}
/* cleanup */
BLI_freelistN(&anim_data);
}
/* ------------------- */
static int animchannels_borderselect_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
rcti rect;
short selectmode=0;
int gesture_mode;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* get settings from operator */
rect.xmin= RNA_int_get(op->ptr, "xmin");
rect.ymin= RNA_int_get(op->ptr, "ymin");
rect.xmax= RNA_int_get(op->ptr, "xmax");
rect.ymax= RNA_int_get(op->ptr, "ymax");
gesture_mode= RNA_int_get(op->ptr, "gesture_mode");
if (gesture_mode == GESTURE_MODAL_SELECT)
selectmode = ACHANNEL_SETFLAG_ADD;
else
selectmode = ACHANNEL_SETFLAG_CLEAR;
/* apply borderselect animation channels */
borderselect_anim_channels(&ac, &rect, selectmode);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|ND_ANIMCHAN|NA_SELECTED, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_select_border(wmOperatorType *ot)
{
/* identifiers */
ot->name= "Border Select";
ot->idname= "ANIM_OT_channels_select_border";
ot->description= "Select all animation channels within the specified region";
/* api callbacks */
ot->invoke= WM_border_select_invoke;
ot->exec= animchannels_borderselect_exec;
ot->modal= WM_border_select_modal;
ot->poll= animedit_poll_channels_nla_tweakmode_off;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* rna */
WM_operator_properties_gesture_border(ot, FALSE);
}
/* ******************** Mouse-Click Operator *********************** */
/* Handle selection changes due to clicking on channels. Settings will get caught by UI code... */
static int mouse_anim_channels (bAnimContext *ac, float UNUSED(x), int channel_index, short selectmode)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
int notifierFlags = 0;
/* get the channel that was clicked on */
/* filter channels */
filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CHANNELS);
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* get channel from index */
ale= BLI_findlink(&anim_data, channel_index);
if (ale == NULL) {
/* channel not found */
if (G.f & G_DEBUG)
printf("Error: animation channel (index = %d) not found in mouse_anim_channels() \n", channel_index);
BLI_freelistN(&anim_data);
return 0;
}
/* selectmode -1 is a special case for ActionGroups only, which selects all of the channels underneath it only... */
// TODO: should this feature be extended to work with other channel types too?
if ((selectmode == -1) && (ale->type != ANIMTYPE_GROUP)) {
/* normal channels should not behave normally in this case */
BLI_freelistN(&anim_data);
return 0;
}
/* action to take depends on what channel we've got */
// WARNING: must keep this in sync with the equivalent function in nla_channels.c
switch (ale->type) {
case ANIMTYPE_SCENE:
{
Scene *sce= (Scene *)ale->data;
AnimData *adt= sce->adt;
/* set selection status */
if (selectmode == SELECT_INVERT) {
/* swap select */
sce->flag ^= SCE_DS_SELECTED;
if (adt) adt->flag ^= ADT_UI_SELECTED;
}
else {
sce->flag |= SCE_DS_SELECTED;
if (adt) adt->flag |= ADT_UI_SELECTED;
}
notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
}
break;
case ANIMTYPE_OBJECT:
{
bDopeSheet *ads= (bDopeSheet *)ac->data;
Scene *sce= (Scene *)ads->source;
Base *base= (Base *)ale->data;
Object *ob= base->object;
AnimData *adt= ob->adt;
/* set selection status */
if (selectmode == SELECT_INVERT) {
/* swap select */
base->flag ^= SELECT;
ob->flag= base->flag;
if (adt) adt->flag ^= ADT_UI_SELECTED;
}
else {
Base *b;
/* deselect all */
// TODO: should this deselect all other types of channels too?
for (b= sce->base.first; b; b= b->next) {
b->flag &= ~SELECT;
b->object->flag= b->flag;
if (b->object->adt) b->object->adt->flag &= ~(ADT_UI_SELECTED|ADT_UI_ACTIVE);
}
/* select object now */
base->flag |= SELECT;
ob->flag |= SELECT;
if (adt) adt->flag |= ADT_UI_SELECTED;
}
if ((adt) && (adt->flag & ADT_UI_SELECTED))
adt->flag |= ADT_UI_ACTIVE;
notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
}
break;
case ANIMTYPE_FILLACTD: /* Action Expander */
case ANIMTYPE_DSMAT: /* Datablock AnimData Expanders */
case ANIMTYPE_DSLAM:
case ANIMTYPE_DSCAM:
case ANIMTYPE_DSCUR:
case ANIMTYPE_DSSKEY:
case ANIMTYPE_DSWOR:
case ANIMTYPE_DSPART:
case ANIMTYPE_DSMBALL:
case ANIMTYPE_DSARM:
case ANIMTYPE_DSMESH:
case ANIMTYPE_DSNTREE:
case ANIMTYPE_DSTEX:
case ANIMTYPE_DSLAT:
{
/* sanity checking... */
if (ale->adt) {
/* select/deselect */
if (selectmode == SELECT_INVERT) {
/* inverse selection status of this AnimData block only */
ale->adt->flag ^= ADT_UI_SELECTED;
}
else {
/* select AnimData block by itself */
ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
ale->adt->flag |= ADT_UI_SELECTED;
}
/* set active? */
if ((ale->adt) && (ale->adt->flag & ADT_UI_SELECTED))
ale->adt->flag |= ADT_UI_ACTIVE;
}
notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
}
break;
case ANIMTYPE_GROUP:
{
bActionGroup *agrp= (bActionGroup *)ale->data;
/* select/deselect group */
if (selectmode == SELECT_INVERT) {
/* inverse selection status of this group only */
agrp->flag ^= AGRP_SELECTED;
}
else if (selectmode == -1) {
/* select all in group (and deselect everthing else) */
FCurve *fcu;
/* deselect all other channels */
ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
/* only select channels in group and group itself */
for (fcu= agrp->channels.first; fcu && fcu->grp==agrp; fcu= fcu->next)
fcu->flag |= FCURVE_SELECTED;
agrp->flag |= AGRP_SELECTED;
}
else {
/* select group by itself */
ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
agrp->flag |= AGRP_SELECTED;
}
/* if group is selected now, make group the 'active' one in the visible list */
if (agrp->flag & AGRP_SELECTED)
ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, agrp, ANIMTYPE_GROUP);
notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
}
break;
case ANIMTYPE_FCURVE:
{
FCurve *fcu= (FCurve *)ale->data;
/* select/deselect */
if (selectmode == SELECT_INVERT) {
/* inverse selection status of this F-Curve only */
fcu->flag ^= FCURVE_SELECTED;
}
else {
/* select F-Curve by itself */
ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
fcu->flag |= FCURVE_SELECTED;
}
/* if F-Curve is selected now, make F-Curve the 'active' one in the visible list */
if (fcu->flag & FCURVE_SELECTED)
ANIM_set_active_channel(ac, ac->data, ac->datatype, filter, fcu, ANIMTYPE_FCURVE);
notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
}
break;
case ANIMTYPE_SHAPEKEY:
{
KeyBlock *kb= (KeyBlock *)ale->data;
/* select/deselect */
if (selectmode == SELECT_INVERT) {
/* inverse selection status of this ShapeKey only */
kb->flag ^= KEYBLOCK_SEL;
}
else {
/* select ShapeKey by itself */
ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
kb->flag |= KEYBLOCK_SEL;
}
notifierFlags |= (ND_ANIMCHAN|NA_SELECTED);
}
break;
case ANIMTYPE_GPDATABLOCK:
{
bGPdata *gpd= (bGPdata *)ale->data;
/* toggle expand
* - although the triangle widget already allows this, the whole channel can also be used for this purpose
*/
gpd->flag ^= GP_DATA_EXPAND;
notifierFlags |= (ND_ANIMCHAN|NA_EDITED);
}
break;
case ANIMTYPE_GPLAYER:
{
bGPDlayer *gpl= (bGPDlayer *)ale->data;
/* select/deselect */
if (selectmode == SELECT_INVERT) {
/* invert selection status of this layer only */
gpl->flag ^= GP_LAYER_SELECT;
}
else {
/* select layer by itself */
ANIM_deselect_anim_channels(ac, ac->data, ac->datatype, 0, ACHANNEL_SETFLAG_CLEAR);
gpl->flag |= GP_LAYER_SELECT;
}
notifierFlags |= (ND_ANIMCHAN|NA_EDITED);
}
break;
default:
if (G.f & G_DEBUG)
printf("Error: Invalid channel type in mouse_anim_channels() \n");
}
/* free channels */
BLI_freelistN(&anim_data);
/* return notifier flags */
return notifierFlags;
}
/* ------------------- */
/* handle clicking */
static int animchannels_mouseclick_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
bAnimContext ac;
ARegion *ar;
View2D *v2d;
int mval[2], channel_index;
int notifierFlags = 0;
short selectmode;
float x, y;
/* get editor data */
if (ANIM_animdata_get_context(C, &ac) == 0)
return OPERATOR_CANCELLED;
/* get useful pointers from animation context data */
ar= ac.ar;
v2d= &ar->v2d;
/* get mouse coordinates (in region coordinates) */
mval[0]= (event->x - ar->winrct.xmin);
mval[1]= (event->y - ar->winrct.ymin);
/* select mode is either replace (deselect all, then add) or add/extend */
if (RNA_boolean_get(op->ptr, "extend"))
selectmode= SELECT_INVERT;
else if (RNA_boolean_get(op->ptr, "children_only"))
selectmode= -1; /* this is a bit of a special case for ActionGroups only... should it be removed or extended to all instead? */
else
selectmode= SELECT_REPLACE;
/* figure out which channel user clicked in
* Note: although channels technically start at y= ACHANNEL_FIRST, we need to adjust by half a channel's height
* so that the tops of channels get caught ok. Since ACHANNEL_FIRST is really ACHANNEL_HEIGHT, we simply use
* ACHANNEL_HEIGHT_HALF.
*/
UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
UI_view2d_listview_view_to_cell(v2d, ACHANNEL_NAMEWIDTH, ACHANNEL_STEP, 0, (float)ACHANNEL_HEIGHT_HALF, x, y, NULL, &channel_index);
/* handle mouse-click in the relevant channel then */
notifierFlags= mouse_anim_channels(&ac, x, channel_index, selectmode);
/* set notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION|notifierFlags, NULL);
return OPERATOR_FINISHED;
}
void ANIM_OT_channels_click (wmOperatorType *ot)
{
/* identifiers */
ot->name= "Mouse Click on Channels";
ot->idname= "ANIM_OT_channels_click";
ot->description= "Handle mouse-clicks over animation channels";
/* api callbacks */
ot->invoke= animchannels_mouseclick_invoke;
ot->poll= animedit_poll_channels_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* id-props */
RNA_def_boolean(ot->srna, "extend", 0, "Extend Select", ""); // SHIFTKEY
RNA_def_boolean(ot->srna, "children_only", 0, "Select Children Only", ""); // CTRLKEY|SHIFTKEY
}
/* ************************************************************************** */
/* Operator Registration */
void ED_operatortypes_animchannels(void)
{
WM_operatortype_append(ANIM_OT_channels_select_all_toggle);
WM_operatortype_append(ANIM_OT_channels_select_border);
WM_operatortype_append(ANIM_OT_channels_click);
WM_operatortype_append(ANIM_OT_channels_setting_enable);
WM_operatortype_append(ANIM_OT_channels_setting_disable);
WM_operatortype_append(ANIM_OT_channels_setting_invert);
WM_operatortype_append(ANIM_OT_channels_setting_toggle);
WM_operatortype_append(ANIM_OT_channels_delete);
// XXX does this need to be a separate operator?
WM_operatortype_append(ANIM_OT_channels_editable_toggle);
WM_operatortype_append(ANIM_OT_channels_move);
WM_operatortype_append(ANIM_OT_channels_expand);
WM_operatortype_append(ANIM_OT_channels_collapse);
WM_operatortype_append(ANIM_OT_channels_visibility_toggle);
WM_operatortype_append(ANIM_OT_channels_visibility_set);
WM_operatortype_append(ANIM_OT_channels_fcurves_enable);
}
// TODO: check on a poll callback for this, to get hotkeys into menus
void ED_keymap_animchannels(wmKeyConfig *keyconf)
{
wmKeyMap *keymap = WM_keymap_find(keyconf, "Animation Channels", 0, 0);
/* selection */
/* click-select */
// XXX for now, only leftmouse....
WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, 0, 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "extend", 1);
RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_click", LEFTMOUSE, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "children_only", 1);
/* deselect all */
WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", AKEY, KM_PRESS, 0, 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_select_all_toggle", IKEY, KM_PRESS, KM_CTRL, 0)->ptr, "invert", 1);
/* borderselect */
WM_keymap_add_item(keymap, "ANIM_OT_channels_select_border", BKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_select_border", EVT_TWEAK_L, KM_ANY, 0, 0);
/* delete */
WM_keymap_add_item(keymap, "ANIM_OT_channels_delete", XKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_delete", DELKEY, KM_PRESS, 0, 0);
/* settings */
WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_toggle", WKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_enable", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_setting_disable", WKEY, KM_PRESS, KM_ALT, 0);
/* settings - specialised hotkeys */
WM_keymap_add_item(keymap, "ANIM_OT_channels_editable_toggle", TABKEY, KM_PRESS, 0, 0);
/* expand/collapse */
WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, 0, 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_expand", PADPLUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "all", 0);
RNA_boolean_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_collapse", PADMINUS, KM_PRESS, KM_CTRL, 0)->ptr, "all", 0);
/* rearranging */
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEUPKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "direction", REARRANGE_ANIMCHAN_UP);
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "direction", REARRANGE_ANIMCHAN_DOWN);
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEUPKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "direction", REARRANGE_ANIMCHAN_TOP);
RNA_enum_set(WM_keymap_add_item(keymap, "ANIM_OT_channels_move", PAGEDOWNKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0)->ptr, "direction", REARRANGE_ANIMCHAN_BOTTOM);
/* Graph Editor only */
WM_keymap_add_item(keymap, "ANIM_OT_channels_visibility_set", VKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "ANIM_OT_channels_visibility_toggle", VKEY, KM_PRESS, KM_SHIFT, 0);
}
/* ************************************************************************** */
|