Merged changes in the trunk up to revision 34193.
[blender.git] / source / blender / editors / animation / anim_filter.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation, Joshua Leung
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Joshua Leung (original author)
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /* This file contains a system used to provide a layer of abstraction between sources
30  * of animation data and tools in Animation Editors. The method used here involves 
31  * generating a list of edit structures which enable tools to naively perform the actions 
32  * they require without all the boiler-plate associated with loops within loops and checking 
33  * for cases to ignore. 
34  *
35  * While this is primarily used for the Action/Dopesheet Editor (and its accessory modes),
36  * the Graph Editor also uses this for its channel list and for determining which curves
37  * are being edited. Likewise, the NLA Editor also uses this for its channel list and in
38  * its operators.
39  *
40  * Note: much of the original system this was based on was built before the creation of the RNA
41  * system. In future, it would be interesting to replace some parts of this code with RNA queries,
42  * however, RNA does not eliminate some of the boiler-plate reduction benefits presented by this 
43  * system, so if any such work does occur, it should only be used for the internals used here...
44  *
45  * -- Joshua Leung, Dec 2008 (Last revision July 2009)
46  */
47
48 #include <string.h>
49
50 #include "DNA_anim_types.h"
51 #include "DNA_armature_types.h"
52 #include "DNA_camera_types.h"
53 #include "DNA_lamp_types.h"
54 #include "DNA_lattice_types.h"
55 #include "DNA_linestyle_types.h"
56 #include "DNA_key_types.h"
57 #include "DNA_material_types.h"
58 #include "DNA_mesh_types.h"
59 #include "DNA_meta_types.h"
60 #include "DNA_node_types.h"
61 #include "DNA_particle_types.h"
62 #include "DNA_space_types.h"
63 #include "DNA_sequence_types.h"
64 #include "DNA_scene_types.h"
65 #include "DNA_screen_types.h"
66 #include "DNA_world_types.h"
67 #include "DNA_gpencil_types.h"
68 #include "DNA_object_types.h"
69
70 #include "MEM_guardedalloc.h"
71
72 #include "BLI_blenlib.h"
73 #include "BLI_utildefines.h"
74 #include "BLI_ghash.h"
75
76 #include "BKE_animsys.h"
77 #include "BKE_action.h"
78 #include "BKE_fcurve.h"
79 #include "BKE_context.h"
80 #include "BKE_global.h"
81 #include "BKE_group.h"
82 #include "BKE_key.h"
83 #include "BKE_material.h"
84 #include "BKE_node.h"
85 #include "BKE_sequencer.h"
86 #include "BKE_utildefines.h"
87
88 #include "ED_anim_api.h"
89
90 /* ************************************************************ */
91 /* Blender Context <-> Animation Context mapping */
92
93 /* ----------- Private Stuff - Action Editor ------------- */
94
95 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
96 /* Note: there's a similar function in key.c (ob_get_key) */
97 static Key *actedit_get_shapekeys (bAnimContext *ac) 
98 {
99         Scene *scene= ac->scene;
100         Object *ob;
101         Key *key;
102         
103         ob = OBACT;
104         if (ob == NULL) 
105                 return NULL;
106         
107         /* XXX pinning is not available in 'ShapeKey' mode... */
108         //if (saction->pin) return NULL;
109         
110         /* shapekey data is stored with geometry data */
111         key= ob_get_key(ob);
112         
113         if (key) {
114                 if (key->type == KEY_RELATIVE)
115                         return key;
116         }
117         
118         return NULL;
119 }
120
121 /* Get data being edited in Action Editor (depending on current 'mode') */
122 static short actedit_get_context (bAnimContext *ac, SpaceAction *saction)
123 {
124         /* sync settings with current view status, then return appropriate data */
125         switch (saction->mode) {
126                 case SACTCONT_ACTION: /* 'Action Editor' */
127                         /* if not pinned, sync with active object */
128                         if (/*saction->pin == 0*/1) {
129                                 if (ac->obact && ac->obact->adt)
130                                         saction->action = ac->obact->adt->action;
131                                 else
132                                         saction->action= NULL;
133                         }
134                         
135                         ac->datatype= ANIMCONT_ACTION;
136                         ac->data= saction->action;
137                         
138                         ac->mode= saction->mode;
139                         return 1;
140                         
141                 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
142                         ac->datatype= ANIMCONT_SHAPEKEY;
143                         ac->data= actedit_get_shapekeys(ac);
144                         
145                         ac->mode= saction->mode;
146                         return 1;
147                         
148                 case SACTCONT_GPENCIL: /* Grease Pencil */ // XXX review how this mode is handled...
149                         ac->datatype=ANIMCONT_GPENCIL;
150                         //ac->data= CTX_wm_screen(C); // FIXME: add that dopesheet type thing here!
151                         ac->data= NULL; // !!!
152                         
153                         ac->mode= saction->mode;
154                         return 1;
155                         
156                 case SACTCONT_DOPESHEET: /* DopeSheet */
157                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
158                         saction->ads.source= (ID *)ac->scene;
159                         
160                         ac->datatype= ANIMCONT_DOPESHEET;
161                         ac->data= &saction->ads;
162                         
163                         ac->mode= saction->mode;
164                         return 1;
165                 
166                 default: /* unhandled yet */
167                         ac->datatype= ANIMCONT_NONE;
168                         ac->data= NULL;
169                         
170                         ac->mode= -1;
171                         return 0;
172         }
173 }
174
175 /* ----------- Private Stuff - Graph Editor ------------- */
176
177 /* Get data being edited in Graph Editor (depending on current 'mode') */
178 static short graphedit_get_context (bAnimContext *ac, SpaceIpo *sipo)
179 {
180         /* init dopesheet data if non-existant (i.e. for old files) */
181         if (sipo->ads == NULL) {
182                 sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
183                 sipo->ads->source= (ID *)ac->scene;
184         }
185         
186         /* set settings for Graph Editor - "Selected = Editable" */
187         if (sipo->flag & SIPO_SELCUVERTSONLY)
188                 sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
189         else
190                 sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
191         
192         /* sync settings with current view status, then return appropriate data */
193         switch (sipo->mode) {
194                 case SIPO_MODE_ANIMATION:       /* Animation F-Curve Editor */
195                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
196                         sipo->ads->source= (ID *)ac->scene;
197                         sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
198                         
199                         ac->datatype= ANIMCONT_FCURVES;
200                         ac->data= sipo->ads;
201                         
202                         ac->mode= sipo->mode;
203                         return 1;
204                 
205                 case SIPO_MODE_DRIVERS:         /* Driver F-Curve Editor */
206                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
207                         sipo->ads->source= (ID *)ac->scene;
208                         sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
209                         
210                         ac->datatype= ANIMCONT_DRIVERS;
211                         ac->data= sipo->ads;
212                         
213                         ac->mode= sipo->mode;
214                         return 1;
215                 
216                 default: /* unhandled yet */
217                         ac->datatype= ANIMCONT_NONE;
218                         ac->data= NULL;
219                         
220                         ac->mode= -1;
221                         return 0;
222         }
223 }
224
225 /* ----------- Private Stuff - NLA Editor ------------- */
226
227 /* Get data being edited in Graph Editor (depending on current 'mode') */
228 static short nlaedit_get_context (bAnimContext *ac, SpaceNla *snla)
229 {
230         /* init dopesheet data if non-existant (i.e. for old files) */
231         if (snla->ads == NULL)
232                 snla->ads= MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
233         
234         /* sync settings with current view status, then return appropriate data */
235         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
236         snla->ads->source= (ID *)ac->scene;
237         snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
238         
239         ac->datatype= ANIMCONT_NLA;
240         ac->data= snla->ads;
241         
242         return 1;
243 }
244
245 /* ----------- Public API --------------- */
246
247 /* Obtain current anim-data context, given that context info from Blender context has already been set 
248  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
249  *        allocation/freeing costs (which are not that avoidable with channels).
250  */
251 short ANIM_animdata_context_getdata (bAnimContext *ac)
252 {
253         ScrArea *sa= ac->sa;
254         short ok= 0;
255         
256         /* context depends on editor we are currently in */
257         if (sa) {
258                 switch (sa->spacetype) {
259                         case SPACE_ACTION:
260                         {
261                                 SpaceAction *saction= (SpaceAction *)sa->spacedata.first;
262                                 ok= actedit_get_context(ac, saction);
263                         }
264                                 break;
265                                 
266                         case SPACE_IPO:
267                         {
268                                 SpaceIpo *sipo= (SpaceIpo *)sa->spacedata.first;
269                                 ok= graphedit_get_context(ac, sipo);
270                         }
271                                 break;
272                                 
273                         case SPACE_NLA:
274                         {
275                                 SpaceNla *snla= (SpaceNla *)sa->spacedata.first;
276                                 ok= nlaedit_get_context(ac, snla);
277                         }
278                                 break;
279                 }
280         }
281         
282         /* check if there's any valid data */
283         if (ok && ac->data)
284                 return 1;
285         else
286                 return 0;
287 }
288
289 /* Obtain current anim-data context from Blender Context info 
290  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
291  *        allocation/freeing costs (which are not that avoidable with channels).
292  *      - Clears data and sets the information from Blender Context which is useful
293  */
294 short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac)
295 {
296         ScrArea *sa= CTX_wm_area(C);
297         ARegion *ar= CTX_wm_region(C);
298         Scene *scene= CTX_data_scene(C);
299         
300         /* clear old context info */
301         if (ac == NULL) return 0;
302         memset(ac, 0, sizeof(bAnimContext));
303         
304         /* get useful default context settings from context */
305         ac->scene= scene;
306         if (scene) {
307                 ac->markers= &scene->markers;           
308                 ac->obact= (scene->basact)?  scene->basact->object : NULL;
309         }
310         ac->sa= sa;
311         ac->ar= ar;
312         ac->spacetype= (sa) ? sa->spacetype : 0;
313         ac->regiontype= (ar) ? ar->regiontype : 0;
314         
315         /* get data context info */
316         return ANIM_animdata_context_getdata(ac);
317 }
318
319 /* ************************************************************ */
320 /* Blender Data <-- Filter --> Channels to be operated on */
321
322 /* quick macro to test if AnimData is usable */
323 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
324
325 /* quick macro to test if AnimData is usable for drivers */
326 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
327
328 /* quick macro to test if AnimData is usable for NLA */
329 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
330
331
332 /* Quick macro to test for all three avove usability tests, performing the appropriate provided 
333  * action for each when the AnimData context is appropriate. 
334  *
335  * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
336  *
337  * For this to work correctly, a standard set of data needs to be available within the scope that this
338  * gets called in: 
339  *      - ListBase anim_data;
340  *      - bDopeSheet *ads;
341  *      - bAnimListElem *ale;
342  *      - int items;
343  *
344  *      - id: ID block which should have an AnimData pointer following it immediately, to use
345  *      - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA)
346  *      - nlaOk: line or block of code to execute for NLA tracks+strips case
347  *      - driversOk: line or block of code to execute for Drivers case
348  *      - keysOk: line or block of code for Keyframes case
349  *
350  * The checks for the various cases are as follows:
351  *      0) top level: checks for animdata and also that all the F-Curves for the block will be visible
352  *      1) animdata check: for filtering animdata blocks only
353  *      2A) nla tracks: include animdata block's data as there are NLA tracks+strips there
354  *      2B) actions to convert to nla: include animdata block's data as there is an action that can be 
355  *              converted to a new NLA strip, and the filtering options allow this
356  *      3) drivers: include drivers from animdata block (for Drivers mode in Graph Editor)
357  *      4) normal keyframes: only when there is an active action
358  */
359 #define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, keysOk) \
360         {\
361                 if ((id)->adt) {\
362                         if (!(filter_mode & ANIMFILTER_CURVEVISIBLE) || !((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) {\
363                                 if (filter_mode & ANIMFILTER_ANIMDATA) {\
364                                         adtOk\
365                                 }\
366                                 else if (ads->filterflag & ADS_FILTER_ONLYNLA) {\
367                                         if (ANIMDATA_HAS_NLA(id)) {\
368                                                 nlaOk\
369                                         }\
370                                         else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) && ANIMDATA_HAS_KEYS(id)) {\
371                                                 nlaOk\
372                                         }\
373                                 }\
374                                 else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) {\
375                                         if (ANIMDATA_HAS_DRIVERS(id)) {\
376                                                 driversOk\
377                                         }\
378                                 }\
379                                 else {\
380                                         if (ANIMDATA_HAS_KEYS(id)) {\
381                                                 keysOk\
382                                         }\
383                                 }\
384                         }\
385                 }\
386         }
387
388
389 /* quick macro to add a pointer to an AnimData block as a channel */
390 #define ANIMDATA_ADD_ANIMDATA(id) \
391         {\
392                 ale= make_new_animlistelem((id)->adt, ANIMTYPE_ANIMDATA, NULL, ANIMTYPE_NONE, (ID *)id);\
393                 if (ale) {\
394                         BLI_addtail(anim_data, ale);\
395                         items++;\
396                 }\
397         }
398         
399 /* quick macro to test if an anim-channel representing an AnimData block is suitably active */
400 #define ANIMCHANNEL_ACTIVEOK(ale) \
401         ( !(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE) )
402
403 /* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
404 #define ANIMCHANNEL_SELOK(test_func) \
405                 ( !(filter_mode & (ANIMFILTER_SEL|ANIMFILTER_UNSEL)) || \
406                   ((filter_mode & ANIMFILTER_SEL) && test_func) || \
407                   ((filter_mode & ANIMFILTER_UNSEL) && test_func==0) ) 
408                   
409 /* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes 
410  *      - _SELEDIT means that only selected curves will have visible+editable keyframes
411  *
412  * checks here work as follows:
413  *      1) seledit off - don't need to consider the implications of this option
414  *      2) foredit off - we're not considering editing, so channel is ok still
415  *      3) test_func (i.e. selection test) - only if selected, this test will pass
416  */
417 #define ANIMCHANNEL_SELEDITOK(test_func) \
418                 ( !(filter_mode & ANIMFILTER_SELEDIT) || \
419                   !(filter_mode & ANIMFILTER_FOREDIT) || \
420                   (test_func) )
421
422 /* ----------- 'Private' Stuff --------------- */
423
424 /* this function allocates memory for a new bAnimListElem struct for the 
425  * provided animation channel-data. 
426  */
427 bAnimListElem *make_new_animlistelem (void *data, short datatype, void *owner, short ownertype, ID *owner_id)
428 {
429         bAnimListElem *ale= NULL;
430         
431         /* only allocate memory if there is data to convert */
432         if (data) {
433                 /* allocate and set generic data */
434                 ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
435                 
436                 ale->data= data;
437                 ale->type= datatype;
438                         // XXX what is the point of the owner data?
439                         // xxx try and use this to simplify the problem of finding whether parent channels are working...
440                 ale->owner= owner;
441                 ale->ownertype= ownertype;
442                 
443                 ale->id= owner_id;
444                 ale->adt= BKE_animdata_from_id(owner_id);
445                 
446                 /* do specifics */
447                 switch (datatype) {
448                         case ANIMTYPE_SUMMARY:
449                         {
450                                 /* nothing to include for now... this is just a dummy wrappy around all the other channels 
451                                  * in the DopeSheet, and gets included at the start of the list
452                                  */
453                                 ale->key_data= NULL;
454                                 ale->datatype= ALE_ALL;
455                         }
456                                 break;
457                         
458                         case ANIMTYPE_SCENE:
459                         {
460                                 Scene *sce= (Scene *)data;
461                                 
462                                 ale->flag= sce->flag;
463                                 
464                                 ale->key_data= sce;
465                                 ale->datatype= ALE_SCE;
466                                 
467                                 ale->adt= BKE_animdata_from_id(data);
468                         }
469                                 break;
470                         case ANIMTYPE_OBJECT:
471                         {
472                                 Base *base= (Base *)data;
473                                 Object *ob= base->object;
474                                 
475                                 ale->flag= ob->flag;
476                                 
477                                 ale->key_data= ob;
478                                 ale->datatype= ALE_OB;
479                                 
480                                 ale->adt= BKE_animdata_from_id(&ob->id);
481                         }
482                                 break;
483                         case ANIMTYPE_FILLACTD:
484                         {
485                                 bAction *act= (bAction *)data;
486                                 
487                                 ale->flag= act->flag;
488                                 
489                                 ale->key_data= act;
490                                 ale->datatype= ALE_ACT;
491                         }
492                                 break;
493                         case ANIMTYPE_FILLDRIVERS:
494                         {
495                                 AnimData *adt= (AnimData *)data;
496                                 
497                                 ale->flag= adt->flag;
498                                 
499                                         // XXX... drivers don't show summary for now
500                                 ale->key_data= NULL;
501                                 ale->datatype= ALE_NONE;
502                         }
503                                 break;
504                         case ANIMTYPE_FILLMATD:
505                         {
506                                 Object *ob= (Object *)data;
507                                 
508                                 ale->flag= FILTER_MAT_OBJC(ob);
509                                 
510                                 ale->key_data= NULL;
511                                 ale->datatype= ALE_NONE;
512                         }
513                                 break;
514                         case ANIMTYPE_FILLPARTD:
515                         {
516                                 Object *ob= (Object *)data;
517                                 
518                                 ale->flag= FILTER_PART_OBJC(ob);
519                                 
520                                 ale->key_data= NULL;
521                                 ale->datatype= ALE_NONE;
522                         }
523                                 break;
524                         case ANIMTYPE_FILLTEXD:
525                         {
526                                 ID *id= (ID *)data;
527                                 
528                                 switch (GS(id->name)) {
529                                         case ID_MA:
530                                         {
531                                                 Material *ma= (Material *)id;
532                                                 ale->flag= FILTER_TEX_MATC(ma);
533                                         }
534                                                 break;
535                                         case ID_LA:
536                                         {
537                                                 Lamp *la= (Lamp *)id;
538                                                 ale->flag= FILTER_TEX_LAMC(la);
539                                         }
540                                                 break;
541                                         case ID_WO:
542                                         {
543                                                 World *wo= (World *)id;
544                                                 ale->flag= FILTER_TEX_WORC(wo);
545                                         }
546                                                 break;
547                                 }
548                                 
549                                 ale->key_data= NULL;
550                                 ale->datatype= ALE_NONE;
551                         }
552                                 break;
553                         
554                         case ANIMTYPE_DSMAT:
555                         {
556                                 Material *ma= (Material *)data;
557                                 AnimData *adt= ma->adt;
558                                 
559                                 ale->flag= FILTER_MAT_OBJD(ma);
560                                 
561                                 ale->key_data= (adt) ? adt->action : NULL;
562                                 ale->datatype= ALE_ACT;
563                                 
564                                 ale->adt= BKE_animdata_from_id(data);
565                         }
566                                 break;
567                         case ANIMTYPE_DSLAM:
568                         {
569                                 Lamp *la= (Lamp *)data;
570                                 AnimData *adt= la->adt;
571                                 
572                                 ale->flag= FILTER_LAM_OBJD(la);
573                                 
574                                 ale->key_data= (adt) ? adt->action : NULL;
575                                 ale->datatype= ALE_ACT;
576                                 
577                                 ale->adt= BKE_animdata_from_id(data);
578                         }
579                                 break;
580                         case ANIMTYPE_DSCAM:
581                         {
582                                 Camera *ca= (Camera *)data;
583                                 AnimData *adt= ca->adt;
584                                 
585                                 ale->flag= FILTER_CAM_OBJD(ca);
586                                 
587                                 ale->key_data= (adt) ? adt->action : NULL;
588                                 ale->datatype= ALE_ACT;
589                                 
590                                 ale->adt= BKE_animdata_from_id(data);
591                         }
592                                 break;
593                         case ANIMTYPE_DSCUR:
594                         {
595                                 Curve *cu= (Curve *)data;
596                                 AnimData *adt= cu->adt;
597                                 
598                                 ale->flag= FILTER_CUR_OBJD(cu);
599                                 
600                                 ale->key_data= (adt) ? adt->action : NULL;
601                                 ale->datatype= ALE_ACT;
602                                 
603                                 ale->adt= BKE_animdata_from_id(data);
604                         }
605                                 break;
606                         case ANIMTYPE_DSARM:
607                         {
608                                 bArmature *arm= (bArmature *)data;
609                                 AnimData *adt= arm->adt;
610                                 
611                                 ale->flag= FILTER_ARM_OBJD(arm);
612                                 
613                                 ale->key_data= (adt) ? adt->action : NULL;
614                                 ale->datatype= ALE_ACT;
615                                 
616                                 ale->adt= BKE_animdata_from_id(data);
617                         }
618                                 break;
619                         case ANIMTYPE_DSMESH:
620                         {
621                                 Mesh *me= (Mesh *)data;
622                                 AnimData *adt= me->adt;
623                                 
624                                 ale->flag= FILTER_MESH_OBJD(me);
625                                 
626                                 ale->key_data= (adt) ? adt->action : NULL;
627                                 ale->datatype= ALE_ACT;
628                                 
629                                 ale->adt= BKE_animdata_from_id(data);
630                         }
631                                 break;
632                         case ANIMTYPE_DSLAT:
633                         {
634                                 Lattice *lt= (Lattice *)data;
635                                 AnimData *adt= lt->adt;
636                                 
637                                 ale->flag= FILTER_LATTICE_OBJD(lt);
638                                 
639                                 ale->key_data= (adt) ? adt->action : NULL;
640                                 ale->datatype= ALE_ACT;
641                                 
642                                 ale->adt= BKE_animdata_from_id(data);
643                         }       
644                                 break;
645                         case ANIMTYPE_DSSKEY:
646                         {
647                                 Key *key= (Key *)data;
648                                 AnimData *adt= key->adt;
649                                 
650                                 ale->flag= FILTER_SKE_OBJD(key); 
651                                 
652                                 ale->key_data= (adt) ? adt->action : NULL;
653                                 ale->datatype= ALE_ACT;
654                                 
655                                 ale->adt= BKE_animdata_from_id(data);
656                         }
657                                 break;
658                         case ANIMTYPE_DSWOR:
659                         {
660                                 World *wo= (World *)data;
661                                 AnimData *adt= wo->adt;
662                                 
663                                 ale->flag= FILTER_WOR_SCED(wo); 
664                                 
665                                 ale->key_data= (adt) ? adt->action : NULL;
666                                 ale->datatype= ALE_ACT;
667                                 
668                                 ale->adt= BKE_animdata_from_id(data);
669                         }
670                                 break;
671                         case ANIMTYPE_DSNTREE:
672                         {
673                                 bNodeTree *ntree= (bNodeTree *)data;
674                                 AnimData *adt= ntree->adt;
675                                 
676                                 ale->flag= FILTER_NTREE_SCED(ntree); 
677                                 
678                                 ale->key_data= (adt) ? adt->action : NULL;
679                                 ale->datatype= ALE_ACT;
680                                 
681                                 ale->adt= BKE_animdata_from_id(data);
682                         }
683                                 break;
684                         case ANIMTYPE_DSLINESTYLE:
685                         {
686                                 FreestyleLineStyle *linestyle= (FreestyleLineStyle *)data;
687                                 AnimData *adt= linestyle->adt;
688                                 
689                                 ale->flag= FILTER_LS_SCED(linestyle); 
690                                 
691                                 ale->key_data= (adt) ? adt->action : NULL;
692                                 ale->datatype= ALE_ACT;
693                                 
694                                 ale->adt= BKE_animdata_from_id(data);
695                         }
696                                 break;
697                         case ANIMTYPE_DSPART:
698                         {
699                                 ParticleSettings *part= (ParticleSettings*)ale->data;
700                                 AnimData *adt= part->adt;
701                                 
702                                 ale->flag= FILTER_PART_OBJD(part); 
703                                 
704                                 ale->key_data= (adt) ? adt->action : NULL;
705                                 ale->datatype= ALE_ACT;
706                                 
707                                 ale->adt= BKE_animdata_from_id(data);
708                         }
709                                 break;
710                         case ANIMTYPE_DSTEX:
711                         {
712                                 Tex *tex= (Tex *)data;
713                                 AnimData *adt= tex->adt;
714                                 
715                                 ale->flag= FILTER_TEX_DATA(tex); 
716                                 
717                                 ale->key_data= (adt) ? adt->action : NULL;
718                                 ale->datatype= ALE_ACT;
719                                 
720                                 ale->adt= BKE_animdata_from_id(data);
721                         }
722                                 break;
723                                 
724                         case ANIMTYPE_GROUP:
725                         {
726                                 bActionGroup *agrp= (bActionGroup *)data;
727                                 
728                                 ale->flag= agrp->flag;
729                                 
730                                 ale->key_data= NULL;
731                                 ale->datatype= ALE_GROUP;
732                         }
733                                 break;
734                         case ANIMTYPE_FCURVE:
735                         {
736                                 FCurve *fcu= (FCurve *)data;
737                                 
738                                 ale->flag= fcu->flag;
739                                 
740                                 ale->key_data= fcu;
741                                 ale->datatype= ALE_FCURVE;
742                         }
743                                 break;
744                                 
745                         case ANIMTYPE_SHAPEKEY:
746                         {
747                                 KeyBlock *kb= (KeyBlock *)data;
748                                 Key *key= (Key *)ale->id;
749                                 
750                                 ale->flag= kb->flag;
751                                 
752                                 /* whether we have keyframes depends on whether there is a Key block to find it from */
753                                 if (key) {
754                                         /* index of shapekey is defined by place in key's list */
755                                         ale->index= BLI_findindex(&key->block, kb);
756                                         
757                                         /* the corresponding keyframes are from the animdata */
758                                         if (ale->adt && ale->adt->action) {
759                                                 bAction *act= ale->adt->action;
760                                                 char *rna_path = key_get_curValue_rnaPath(key, kb);
761                                                 
762                                                 /* try to find the F-Curve which corresponds to this exactly,
763                                                  * then free the MEM_alloc'd string
764                                                  */
765                                                 if (rna_path) {
766                                                         ale->key_data= (void *)list_find_fcurve(&act->curves, rna_path, 0);
767                                                         MEM_freeN(rna_path);
768                                                 }
769                                         }
770                                         ale->datatype= (ale->key_data)? ALE_FCURVE : ALE_NONE;
771                                 }
772                         }       
773                                 break;
774                         
775                         case ANIMTYPE_GPLAYER:
776                         {
777                                 bGPDlayer *gpl= (bGPDlayer *)data;
778                                 
779                                 ale->flag= gpl->flag;
780                                 
781                                 ale->key_data= NULL;
782                                 ale->datatype= ALE_GPFRAME;
783                         }
784                                 break;
785                                 
786                         case ANIMTYPE_NLATRACK:
787                         {
788                                 NlaTrack *nlt= (NlaTrack *)data;
789                                 
790                                 ale->flag= nlt->flag;
791                                 
792                                 ale->key_data= &nlt->strips;
793                                 ale->datatype= ALE_NLASTRIP;
794                         }
795                                 break;
796                         case ANIMTYPE_NLAACTION:
797                         {
798                                 /* nothing to include for now... nothing editable from NLA-perspective here */
799                                 ale->key_data= NULL;
800                                 ale->datatype= ALE_NONE;
801                         }
802                                 break;
803                 }
804         }
805         
806         /* return created datatype */
807         return ale;
808 }
809  
810 /* ----------------------------------------- */
811
812 /* NOTE: when this function returns true, the F-Curve is to be skipped */
813 static int skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id, int filter_mode)
814 {
815         if (GS(owner_id->name) == ID_OB) {
816                 Object *ob= (Object *)owner_id;
817                 
818                 /* only consider if F-Curve involves pose.bones */
819                 if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) {
820                         bPoseChannel *pchan;
821                         char *bone_name;
822                         
823                         /* get bone-name, and check if this bone is selected */
824                         bone_name= BLI_getQuotedStr(fcu->rna_path, "pose.bones[");
825                         pchan= get_pose_channel(ob->pose, bone_name);
826                         if (bone_name) MEM_freeN(bone_name);
827                         
828                         /* check whether to continue or skip */
829                         if ((pchan) && (pchan->bone)) {
830                                 /* if only visible channels, skip if bone not visible unless user wants channels from hidden data too */
831                                 if ((filter_mode & ANIMFILTER_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
832                                         bArmature *arm= (bArmature *)ob->data;
833                                         
834                                         if ((arm->layer & pchan->bone->layer) == 0)
835                                                 return 1;
836                                 }
837                                 
838                                 /* can only add this F-Curve if it is selected */
839                                 if ((pchan->bone->flag & BONE_SELECTED) == 0)
840                                         return 1;
841                         }
842                 }
843         }
844         else if (GS(owner_id->name) == ID_SCE) {
845                 Scene *scene = (Scene *)owner_id;
846                 
847                 /* only consider if F-Curve involves sequence_editor.sequences */
848                 if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
849                         Editing *ed= seq_give_editing(scene, FALSE);
850                         Sequence *seq;
851                         char *seq_name;
852                         
853                         /* get strip name, and check if this strip is selected */
854                         seq_name= BLI_getQuotedStr(fcu->rna_path, "sequences_all[");
855                         seq = get_seq_by_name(ed->seqbasep, seq_name, FALSE);
856                         if (seq_name) MEM_freeN(seq_name);
857                         
858                         /* can only add this F-Curve if it is selected */
859                         if (seq==NULL || (seq->flag & SELECT)==0)
860                                 return 1;
861                 }
862         }
863         else if (GS(owner_id->name) == ID_NT) {
864                 bNodeTree *ntree = (bNodeTree *)owner_id;
865                 
866                 /* check for selected  nodes */
867                 if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) {
868                         bNode *node;
869                         char *node_name;
870                         
871                         /* get strip name, and check if this strip is selected */
872                         node_name= BLI_getQuotedStr(fcu->rna_path, "nodes[");
873                         node = nodeFindNodebyName(ntree, node_name);
874                         if (node_name) MEM_freeN(node_name);
875                         
876                         /* can only add this F-Curve if it is selected */
877                         if ((node) && (node->flag & NODE_SELECT)==0)
878                                 return 1;
879                 }
880         }
881         return 0;
882 }
883
884 /* find the next F-Curve that is usable for inclusion */
885 static FCurve *animdata_filter_fcurve_next (bDopeSheet *ads, FCurve *first, bActionGroup *grp, int filter_mode, ID *owner_id)
886 {
887         FCurve *fcu = NULL;
888         
889         /* loop over F-Curves - assume that the caller of this has already checked that these should be included 
890          * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
891          */
892         for (fcu= first; ((fcu) && (fcu->grp==grp)); fcu= fcu->next) {
893                 /* special exception for Pose-Channel Based F-Curves:
894                  *      - the 'Only Selected' data filter should be applied to Pose-Channel data too, but those are
895                  *        represented as F-Curves. The way the filter for objects worked was to be the first check
896                  *        after 'normal' visibility, so this is done first here too...
897                  *      - we currently use an 'approximate' method for getting these F-Curves that doesn't require
898                  *        carefully checking the entire path
899                  *      - this will also affect things like Drivers, and also works for Bone Constraints
900                  */
901                 if ( ((ads) && (ads->filterflag & ADS_FILTER_ONLYSEL)) && (owner_id) ) {
902                         if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode))
903                                 continue;
904                 }
905                         
906                 /* only include if visible (Graph Editor check, not channels check) */
907                 if (!(filter_mode & ANIMFILTER_CURVEVISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
908                         /* only work with this channel and its subchannels if it is editable */
909                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
910                                 /* only include this curve if selected in a way consistent with the filtering requirements */
911                                 if ( ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu)) ) {
912                                         /* only include if this curve is active */
913                                         if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
914                                                 /* this F-Curve can be used, so return it */
915                                                 return fcu;
916                                         }
917                                 }
918                         }
919                 }
920         }
921         
922         /* no (more) F-Curves from the list are suitable... */
923         return NULL;
924 }
925
926 static int animdata_filter_fcurves (ListBase *anim_data, bDopeSheet *ads, FCurve *first, bActionGroup *grp, void *owner, short ownertype, int filter_mode, ID *owner_id)
927 {
928         FCurve *fcu;
929         int items = 0;
930         
931         /* loop over every F-Curve able to be included 
932          *      - this for-loop works like this: 
933          *              1) the starting F-Curve is assigned to the fcu pointer so that we have a starting point to search from
934          *              2) the first valid F-Curve to start from (which may include the one given as 'first') in the remaining 
935          *                 list of F-Curves is found, and verified to be non-null
936          *              3) the F-Curve referenced by fcu pointer is added to the list
937          *              4) the fcu pointer is set to the F-Curve after the one we just added, so that we can keep going through 
938          *                 the rest of the F-Curve list without an eternal loop. Back to step 2 :)
939          */
940         for (fcu=first; ( (fcu = animdata_filter_fcurve_next(ads, fcu, grp, filter_mode, owner_id)) ); fcu=fcu->next)
941         {
942                 bAnimListElem *ale = make_new_animlistelem(fcu, ANIMTYPE_FCURVE, owner, ownertype, owner_id);
943                 
944                 if (ale) {
945                         BLI_addtail(anim_data, ale);
946                         items++;
947                 }
948         }
949         
950         /* return the number of items added to the list */
951         return items;
952 }
953
954 static int animdata_filter_action (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, void *owner, short ownertype, ID *owner_id)
955 {
956         bAnimListElem *ale=NULL;
957         bActionGroup *agrp;
958         FCurve *lastchan=NULL;
959         int items = 0;
960         
961         /* don't include anything from this action if it is linked in from another file,
962          * and we're getting stuff for editing...
963          */
964         // TODO: need a way of tagging other channels that may also be affected...
965         if ((filter_mode & ANIMFILTER_FOREDIT) && (act->id.lib))
966                 return 0;
967         
968         /* loop over groups */
969         // TODO: in future, should we expect to need nested groups?
970         for (agrp= act->groups.first; agrp; agrp= agrp->next) {
971                 FCurve *first_fcu;
972                 int filter_gmode;
973                 
974                 /* store reference to last channel of group */
975                 if (agrp->channels.last) 
976                         lastchan= agrp->channels.last;
977                 
978                 
979                 /* make a copy of filtering flags for use by the sub-channels of this group */
980                 filter_gmode= filter_mode;
981                 
982                 /* if we care about the selection status of the channels, 
983                  * but the group isn't expanded...
984                  */
985                 if ( (filter_mode & (ANIMFILTER_SEL|ANIMFILTER_UNSEL)) &&       /* care about selection status */
986                          (EXPANDED_AGRP(agrp)==0) )                                                             /* group isn't expanded */
987                 {
988                         /* if the group itself isn't selected appropriately, we shouldn't consider it's children either */
989                         if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0)
990                                 continue;
991                         
992                         /* if we're still here, then the selection status of the curves within this group should not matter,
993                          * since this creates too much overhead for animators (i.e. making a slow workflow)
994                          *
995                          * Tools affected by this at time of coding (2010 Feb 09):
996                          *      - inserting keyframes on selected channels only
997                          *      - pasting keyframes
998                          *      - creating ghost curves in Graph Editor
999                          */
1000                         filter_gmode &= ~(ANIMFILTER_SEL|ANIMFILTER_UNSEL);
1001                 }
1002                 
1003                 
1004                 /* get the first F-Curve in this group we can start to use, and if there isn't any F-Curve to start from,  
1005                  * then don't use this group at all...
1006                  *
1007                  * NOTE: use filter_gmode here not filter_mode, since there may be some flags we shouldn't consider under certain circumstances
1008                  */
1009                 first_fcu = animdata_filter_fcurve_next(ads, agrp->channels.first, agrp, filter_gmode, owner_id);
1010                 
1011                 /* Bug note: 
1012                  *      Selecting open group to toggle visbility of the group, where the F-Curves of the group are not suitable 
1013                  *      for inclusion due to their selection status (vs visibility status of bones/etc., as is usually the case),
1014                  *      will not work, since the group gets skipped. However, fixing this can easily reintroduce the bugs whereby
1015                  *      hidden groups (due to visibility status of bones/etc.) that were selected before becoming invisible, can
1016                  *      easily get deleted accidentally as they'd be included in the list filtered for that purpose.
1017                  *
1018                  *      So, for now, best solution is to just leave this note here, and hope to find a solution at a later date.
1019                  *      -- Joshua Leung, 2010 Feb 10
1020                  */
1021                 if (first_fcu) {
1022                         /* add this group as a channel first */
1023                         if ((filter_mode & ANIMFILTER_CHANNELS) || !(filter_mode & ANIMFILTER_CURVESONLY)) {
1024                                 /* filter selection of channel specially here again, since may be open and not subject to previous test */
1025                                 if ( ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
1026                                         ale= make_new_animlistelem(agrp, ANIMTYPE_GROUP, NULL, ANIMTYPE_NONE, owner_id);
1027                                         if (ale) {
1028                                                 BLI_addtail(anim_data, ale);
1029                                                 items++;
1030                                         }
1031                                 }
1032                         }
1033                         
1034                         /* there are some situations, where only the channels of the action group should get considered */
1035                         if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
1036                                 /* filters here are a bit convoulted...
1037                                  *      - groups show a "summary" of keyframes beside their name which must accessable for tools which handle keyframes
1038                                  *      - groups can be collapsed (and those tools which are only interested in channels rely on knowing that group is closed)
1039                                  *
1040                                  * cases when we should include F-Curves inside group:
1041                                  *      - we don't care about visibility
1042                                  *      - group is expanded
1043                                  *      - we just need the F-Curves present
1044                                  */
1045                                 if ( (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_AGRP(agrp)) || (filter_mode & ANIMFILTER_CURVESONLY) ) 
1046                                 {
1047                                         /* for the Graph Editor, curves may be set to not be visible in the view to lessen clutter,
1048                                          * but to do this, we need to check that the group doesn't have it's not-visible flag set preventing 
1049                                          * all its sub-curves to be shown
1050                                          */
1051                                         if ( !(filter_mode & ANIMFILTER_CURVEVISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE) )
1052                                         {
1053                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
1054                                                         /* NOTE: filter_gmode is used here, not standard filter_mode, since there may be some flags that shouldn't apply */
1055                                                         items += animdata_filter_fcurves(anim_data, ads, first_fcu, agrp, owner, ownertype, filter_gmode, owner_id);
1056                                                 }
1057                                         }
1058                                 }
1059                         }
1060                 }
1061         }
1062         
1063         /* loop over un-grouped F-Curves (only if we're not only considering those channels in the animive group) */
1064         if (!(filter_mode & ANIMFILTER_ACTGROUPED))  {
1065                 // XXX the 'owner' info here needs review...
1066                 items += animdata_filter_fcurves(anim_data, ads, (lastchan)?(lastchan->next):(act->curves.first), NULL, owner, ownertype, filter_mode, owner_id);
1067         }
1068         
1069         /* return the number of items added to the list */
1070         return items;
1071 }
1072
1073 /* Include NLA-Data for NLA-Editor:
1074  *      - when ANIMFILTER_CHANNELS is used, that means we should be filtering the list for display
1075  *        Although the evaluation order is from the first track to the last and then apply the Action on top,
1076  *        we present this in the UI as the Active Action followed by the last track to the first so that we 
1077  *        get the evaluation order presented as per a stack.
1078  *      - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
1079  *        order, i.e. first to last. Otherwise, some tools may get screwed up.
1080  */
1081 static int animdata_filter_nla (bAnimContext *UNUSED(ac), ListBase *anim_data, bDopeSheet *UNUSED(ads), AnimData *adt, int filter_mode, void *owner, short ownertype, ID *owner_id)
1082 {
1083         bAnimListElem *ale;
1084         NlaTrack *nlt;
1085         NlaTrack *first=NULL, *next=NULL;
1086         int items = 0;
1087         
1088         /* if showing channels, include active action */
1089         if (filter_mode & ANIMFILTER_CHANNELS) {
1090                 /* there isn't really anything editable here, so skip if need editable */
1091                 // TODO: currently, selection isn't checked since it doesn't matter
1092                 if ((filter_mode & ANIMFILTER_FOREDIT) == 0) { 
1093                         /* just add the action track now (this MUST appear for drawing)
1094                          *      - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
1095                          *        overwrite this with the real value - REVIEW THIS...
1096                          */
1097                         ale= make_new_animlistelem((void *)(&adt->action), ANIMTYPE_NLAACTION, owner, ownertype, owner_id);
1098                         ale->data= (adt->action) ? adt->action : NULL;
1099                                 
1100                         if (ale) {
1101                                 BLI_addtail(anim_data, ale);
1102                                 items++;
1103                         }
1104                 }
1105                 
1106                 /* first track to include will be the last one if we're filtering by channels */
1107                 first= adt->nla_tracks.last;
1108         }
1109         else {
1110                 /* first track to include will the the first one (as per normal) */
1111                 first= adt->nla_tracks.first;
1112         }
1113         
1114         /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
1115         for (nlt= first; nlt; nlt= next) {
1116                 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
1117                 if (filter_mode & ANIMFILTER_CHANNELS) 
1118                         next= nlt->prev;
1119                 else
1120                         next= nlt->next;
1121                 
1122                 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now 
1123                  *      - active track should still get shown though (even though it has disabled flag set)
1124                  */
1125                 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
1126                 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && !(nlt->flag & NLATRACK_ACTIVE))
1127                         continue;
1128                 
1129                 /* only work with this channel and its subchannels if it is editable */
1130                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
1131                         /* only include this track if selected in a way consistent with the filtering requirements */
1132                         if ( ANIMCHANNEL_SELOK(SEL_NLT(nlt)) ) {
1133                                 /* only include if this track is active */
1134                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
1135                                         ale= make_new_animlistelem(nlt, ANIMTYPE_NLATRACK, owner, ownertype, owner_id);
1136                                                 
1137                                         if (ale) {
1138                                                 BLI_addtail(anim_data, ale);
1139                                                 items++;
1140                                         }
1141                                 }
1142                         }
1143                 }
1144         }
1145         
1146         /* return the number of items added to the list */
1147         return items;
1148 }
1149
1150 /* Include ShapeKey Data for ShapeKey Editor */
1151 static int animdata_filter_shapekey (bAnimContext *ac, ListBase *anim_data, Key *key, int filter_mode)
1152 {
1153         bAnimListElem *ale;
1154         int items = 0;
1155         
1156         /* check if channels or only F-Curves */
1157         if ((filter_mode & ANIMFILTER_CURVESONLY) == 0) {
1158                 KeyBlock *kb;
1159                 
1160                 /* loop through the channels adding ShapeKeys as appropriate */
1161                 for (kb= key->block.first; kb; kb= kb->next) {
1162                         /* skip the first one, since that's the non-animateable basis */
1163                         // XXX maybe in future this may become handy?
1164                         if (kb == key->block.first) continue;
1165                         
1166                         /* only work with this channel and its subchannels if it is editable */
1167                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) {
1168                                 /* only include this track if selected in a way consistent with the filtering requirements */
1169                                 if ( ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb)) ) {
1170                                         // TODO: consider 'active' too?
1171                                         
1172                                         /* owner-id here must be key so that the F-Curve can be resolved... */
1173                                         ale= make_new_animlistelem(kb, ANIMTYPE_SHAPEKEY, NULL, ANIMTYPE_NONE, (ID *)key);
1174                                         
1175                                         if (ale) {
1176                                                 BLI_addtail(anim_data, ale);
1177                                                 items++;
1178                                         }
1179                                 }
1180                         }
1181                 }
1182         }
1183         else {
1184                 /* just use the action associated with the shapekey */
1185                 // FIXME: is owner-id and having no owner/dopesheet really fine?
1186                 if (key->adt) {
1187                         if (filter_mode & ANIMFILTER_ANIMDATA)
1188                                 ANIMDATA_ADD_ANIMDATA(key)
1189                         else if (key->adt->action)
1190                                 items= animdata_filter_action(ac, anim_data, NULL, key->adt->action, filter_mode, NULL, ANIMTYPE_NONE, (ID *)key);
1191                 }
1192         }
1193         
1194         /* return the number of items added to the list */
1195         return items;
1196 }
1197
1198 #if 0
1199 // FIXME: switch this to use the bDopeSheet...
1200 static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter_mode)
1201 {
1202         bAnimListElem *ale;
1203         ScrArea *sa, *curarea;
1204         bGPdata *gpd;
1205         bGPDlayer *gpl;
1206         int items = 0;
1207         
1208         /* check if filtering types are appropriate */
1209         {
1210                 /* special hack for fullscreen area (which must be this one then):
1211                  *      - we use the curarea->full as screen to get spaces from, since the
1212                  *        old (pre-fullscreen) screen was stored there...
1213                  *      - this is needed as all data would otherwise disappear
1214                  */
1215                 // XXX need to get new alternative for curarea
1216                 if ((curarea->full) && (curarea->spacetype==SPACE_ACTION))
1217                         sc= curarea->full;
1218                 
1219                 /* loop over spaces in current screen, finding gpd blocks (could be slow!) */
1220                 for (sa= sc->areabase.first; sa; sa= sa->next) {
1221                         /* try to get gp data */
1222                         // XXX need to put back grease pencil api...
1223                         gpd= gpencil_data_get_active(sa);
1224                         if (gpd == NULL) continue;
1225                         
1226                         /* add gpd as channel too (if for drawing, and it has layers) */
1227                         if ((filter_mode & ANIMFILTER_CHANNELS) && (gpd->layers.first)) {
1228                                 /* add to list */
1229                                 ale= make_new_animlistelem(gpd, ANIMTYPE_GPDATABLOCK, sa, ANIMTYPE_SPECIALDATA);
1230                                 if (ale) {
1231                                         BLI_addtail(anim_data, ale);
1232                                         items++;
1233                                 }
1234                         }
1235                         
1236                         /* only add layers if they will be visible (if drawing channels) */
1237                         if ( !(filter_mode & ANIMFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) {
1238                                 /* loop over layers as the conditions are acceptable */
1239                                 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
1240                                         /* only if selected */
1241                                         if ( ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
1242                                                 /* only if editable */
1243                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
1244                                                         /* add to list */
1245                                                         ale= make_new_animlistelem(gpl, ANIMTYPE_GPLAYER, gpd, ANIMTYPE_GPDATABLOCK);
1246                                                         if (ale) {
1247                                                                 BLI_addtail(anim_data, ale);
1248                                                                 items++;
1249                                                         }
1250                                                 }
1251                                         }
1252                                 }
1253                         }
1254                 }
1255         }
1256         
1257         /* return the number of items added to the list */
1258         return items;
1259 }
1260 #endif 
1261
1262 /* NOTE: owner_id is either material, lamp, or world block, which is the direct owner of the texture stack in question */
1263 static int animdata_filter_dopesheet_texs (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
1264 {
1265         ListBase texs = {NULL, NULL};
1266         LinkData *ld;
1267         MTex **mtex = NULL;
1268         short expanded=0;
1269         int ownertype = ANIMTYPE_NONE;
1270         
1271         bAnimListElem *ale=NULL;
1272         int items=0, a=0;
1273         
1274         /* get datatype specific data first */
1275         if (owner_id == NULL)
1276                 return 0;
1277         
1278         switch (GS(owner_id->name)) {
1279                 case ID_MA:
1280                 {
1281                         Material *ma= (Material *)owner_id;
1282                         
1283                         mtex= (MTex**)(&ma->mtex);
1284                         expanded= FILTER_TEX_MATC(ma);
1285                         ownertype= ANIMTYPE_DSMAT;
1286                 }
1287                         break;
1288                 case ID_LA:
1289                 {
1290                         Lamp *la= (Lamp *)owner_id;
1291                         
1292                         mtex= (MTex**)(&la->mtex);
1293                         expanded= FILTER_TEX_LAMC(la);
1294                         ownertype= ANIMTYPE_DSLAM;
1295                 }
1296                         break;
1297                 case ID_WO:
1298                 {
1299                         World *wo= (World *)owner_id;
1300                         
1301                         mtex= (MTex**)(&wo->mtex);
1302                         expanded= FILTER_TEX_WORC(wo);
1303                         ownertype= ANIMTYPE_DSWOR;
1304                 }
1305                         break;
1306                 default: 
1307                 {
1308                         /* invalid/unsupported option */
1309                         if (G.f & G_DEBUG)
1310                                 printf("ERROR: unsupported owner_id (i.e. texture stack) for filter textures - %s \n", owner_id->name);
1311                         return 0;
1312                 }
1313         }
1314         
1315         /* firstly check that we actuallly have some textures, by gathering all textures in a temp list */
1316         for (a=0; a < MAX_MTEX; a++) {
1317                 Tex *tex= (mtex[a]) ? mtex[a]->tex : NULL;
1318                 short ok = 0;
1319                 
1320                 /* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */
1321                 if (ELEM(NULL, tex, tex->adt)) 
1322                         continue;
1323                 
1324                 /* check if ok */
1325                 ANIMDATA_FILTER_CASES(tex, 
1326                         { /* AnimData blocks - do nothing... */ },
1327                         ok=1;, 
1328                         ok=1;, 
1329                         ok=1;)
1330                 if (ok == 0) continue;
1331                 
1332                 /* make a temp list elem for this */
1333                 ld= MEM_callocN(sizeof(LinkData), "DopeSheet-TextureCache");
1334                 ld->data= tex;
1335                 BLI_addtail(&texs, ld);
1336         }
1337         
1338         /* if there were no channels found, no need to carry on */
1339         if (texs.first == NULL)
1340                 return 0;
1341         
1342         /* include textures-expand widget? */
1343         if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1344                 ale= make_new_animlistelem(owner_id, ANIMTYPE_FILLTEXD, owner_id, ownertype, owner_id);
1345                 if (ale) {
1346                         BLI_addtail(anim_data, ale);
1347                         items++;
1348                 }
1349         }
1350         
1351         /* add textures */
1352         if ((expanded) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1353                 /* for each texture in cache, add channels  */
1354                 for (ld= texs.first; ld; ld= ld->next) {
1355                         Tex *tex= (Tex *)ld->data;
1356                         
1357                         /* include texture-expand widget? */
1358                         if (filter_mode & ANIMFILTER_CHANNELS) {
1359                                 /* check if filtering by active status */
1360                                 if ANIMCHANNEL_ACTIVEOK(tex) {
1361                                         ale= make_new_animlistelem(tex, ANIMTYPE_DSTEX, owner_id, ownertype, owner_id);
1362                                         if (ale) {
1363                                                 BLI_addtail(anim_data, ale);
1364                                                 items++;
1365                                         }
1366                                 }
1367                         }
1368                         
1369                         /* add texture's animation data
1370                          * NOTE: for these, we make the owner/ownertype the material/lamp/etc. not the texture, otherwise the
1371                          * drawing code cannot resolve the indention easily
1372                          */
1373                         if (!(filter_mode & ANIMFILTER_VISIBLE) || FILTER_TEX_DATA(tex) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1374                                 ANIMDATA_FILTER_CASES(tex, 
1375                                         { /* AnimData blocks - do nothing... */ },
1376                                         items += animdata_filter_nla(ac, anim_data, ads, tex->adt, filter_mode, owner_id, ownertype, (ID *)tex);, 
1377                                         items += animdata_filter_fcurves(anim_data, ads, tex->adt->drivers.first, NULL, owner_id, ownertype, filter_mode, (ID *)tex);, 
1378                                         items += animdata_filter_action(ac, anim_data, ads, tex->adt->action, filter_mode, owner_id, ownertype, (ID *)tex);)
1379                         }
1380                 }
1381         }
1382         
1383         /* free cache */
1384         BLI_freelistN(&texs);
1385         
1386         /* return the number of items added to the list */
1387         return items;
1388 }
1389
1390 static int animdata_filter_dopesheet_mats (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1391 {
1392         ListBase mats = {NULL, NULL};
1393         LinkData *ld;
1394         
1395         bAnimListElem *ale=NULL;
1396         Object *ob= base->object;
1397         int items=0, a=0;
1398         
1399         /* firstly check that we actuallly have some materials, by gathering all materials in a temp list */
1400         for (a=1; a <= ob->totcol; a++) {
1401                 Material *ma= give_current_material(ob, a);
1402                 short ok = 0;
1403                 
1404                 /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
1405                 if (ma == NULL) continue;
1406
1407                 /* check if ok */
1408                 ANIMDATA_FILTER_CASES(ma, 
1409                         { /* AnimData blocks - do nothing... */ },
1410                         ok=1;, 
1411                         ok=1;, 
1412                         ok=1;)
1413
1414                 /* need to check textures */
1415                 if (ok == 0 && !(ads->filterflag & ADS_FILTER_NOTEX)) {
1416                         int mtInd;
1417
1418                         for (mtInd=0; mtInd < MAX_MTEX; mtInd++) {
1419                                 MTex *mtex = ma->mtex[mtInd];
1420
1421                                 if(mtex && mtex->tex) {
1422                                         ANIMDATA_FILTER_CASES(mtex->tex,
1423                                         { /* AnimData blocks - do nothing... */ },
1424                                         ok=1;, 
1425                                         ok=1;, 
1426                                         ok=1;)
1427                                 }
1428
1429                                 if(ok)
1430                                         break;
1431                         }
1432                 }
1433                 
1434                 if (ok == 0) continue;
1435                 
1436                 /* make a temp list elem for this */
1437                 ld= MEM_callocN(sizeof(LinkData), "DopeSheet-MaterialCache");
1438                 ld->data= ma;
1439                 BLI_addtail(&mats, ld);
1440         }
1441         
1442         /* if there were no channels found, no need to carry on */
1443         if (mats.first == NULL)
1444                 return 0;
1445         
1446         /* include materials-expand widget? */
1447         if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1448                 ale= make_new_animlistelem(ob, ANIMTYPE_FILLMATD, base, ANIMTYPE_OBJECT, (ID *)ob);
1449                 if (ale) {
1450                         BLI_addtail(anim_data, ale);
1451                         items++;
1452                 }
1453         }
1454         
1455         /* add materials? */
1456         if (FILTER_MAT_OBJC(ob) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1457                 /* for each material in cache, add channels  */
1458                 for (ld= mats.first; ld; ld= ld->next) {
1459                         Material *ma= (Material *)ld->data;
1460                         
1461                         /* include material-expand widget? */
1462                         // hmm... do we need to store the index of this material in the array anywhere?
1463                         if (filter_mode & ANIMFILTER_CHANNELS) {
1464                                 /* check if filtering by active status */
1465                                 if ANIMCHANNEL_ACTIVEOK(ma) {
1466                                         ale= make_new_animlistelem(ma, ANIMTYPE_DSMAT, base, ANIMTYPE_OBJECT, (ID *)ma);
1467                                         if (ale) {
1468                                                 BLI_addtail(anim_data, ale);
1469                                                 items++;
1470                                         }
1471                                 }
1472                         }
1473                         
1474                         /* add material's animation data */
1475                         if (!(filter_mode & ANIMFILTER_VISIBLE) || FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1476                                 /* material's animation data */
1477                                 ANIMDATA_FILTER_CASES(ma, 
1478                                         { /* AnimData blocks - do nothing... */ },
1479                                         items += animdata_filter_nla(ac, anim_data, ads, ma->adt, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);, 
1480                                         items += animdata_filter_fcurves(anim_data, ads, ma->adt->drivers.first, NULL, ma, ANIMTYPE_DSMAT, filter_mode, (ID *)ma);, 
1481                                         items += animdata_filter_action(ac, anim_data, ads, ma->adt->action, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);)
1482                                         
1483                                 /* textures */
1484                                 if (!(ads->filterflag & ADS_FILTER_NOTEX))
1485                                         items += animdata_filter_dopesheet_texs(ac, anim_data, ads, (ID *)ma, filter_mode);
1486                         }
1487                 }
1488         }
1489         
1490         /* free cache */
1491         BLI_freelistN(&mats);
1492         
1493         /* return the number of items added to the list */
1494         return items;
1495 }
1496
1497 static int animdata_filter_dopesheet_particles (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1498 {
1499         bAnimListElem *ale=NULL;
1500         Object *ob= base->object;
1501         ParticleSystem *psys = ob->particlesystem.first;
1502         int items= 0, first = 1;
1503
1504         for(; psys; psys=psys->next) {
1505                 short ok = 0;
1506
1507                 if(ELEM(NULL, psys->part, psys->part->adt))
1508                         continue;
1509
1510                 ANIMDATA_FILTER_CASES(psys->part,
1511                         { /* AnimData blocks - do nothing... */ },
1512                         ok=1;, 
1513                         ok=1;, 
1514                         ok=1;)
1515                 if (ok == 0) continue;
1516
1517                 /* include particles-expand widget? */
1518                 if (first && (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1519                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLPARTD, base, ANIMTYPE_OBJECT, (ID *)ob);
1520                         if (ale) {
1521                                 BLI_addtail(anim_data, ale);
1522                                 items++;
1523                         }
1524                         first = 0;
1525                 }
1526                 
1527                 /* add particle settings? */
1528                 if (FILTER_PART_OBJC(ob) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1529                         if ((filter_mode & ANIMFILTER_CHANNELS)) {
1530                                 /* check if filtering by active status */
1531                                 if ANIMCHANNEL_ACTIVEOK(psys->part) {
1532                                         ale = make_new_animlistelem(psys->part, ANIMTYPE_DSPART, base, ANIMTYPE_OBJECT, (ID *)psys->part);
1533                                         if (ale) {
1534                                                 BLI_addtail(anim_data, ale);
1535                                                 items++;
1536                                         }
1537                                 }
1538                         }
1539                         
1540                         if (!(filter_mode & ANIMFILTER_VISIBLE) || FILTER_PART_OBJD(psys->part) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1541                                 ANIMDATA_FILTER_CASES(psys->part,
1542                                         { /* AnimData blocks - do nothing... */ },
1543                                         items += animdata_filter_nla(ac, anim_data, ads, psys->part->adt, filter_mode, psys->part, ANIMTYPE_DSPART, (ID *)psys->part);, 
1544                                         items += animdata_filter_fcurves(anim_data, ads, psys->part->adt->drivers.first, NULL, psys->part, ANIMTYPE_DSPART, filter_mode, (ID *)psys->part);, 
1545                                         items += animdata_filter_action(ac, anim_data, ads, psys->part->adt->action, filter_mode, psys->part, ANIMTYPE_DSPART, (ID *)psys->part);)
1546                         }
1547                 }
1548         }
1549         
1550         /* return the number of items added to the list */
1551         return items;
1552 }
1553
1554 static int animdata_filter_dopesheet_obdata (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1555 {
1556         bAnimListElem *ale=NULL;
1557         Object *ob= base->object;
1558         IdAdtTemplate *iat= ob->data;
1559         AnimData *adt= iat->adt;
1560         short type=0, expanded=0;
1561         int items= 0;
1562         
1563         /* get settings based on data type */
1564         switch (ob->type) {
1565                 case OB_CAMERA: /* ------- Camera ------------ */
1566                 {
1567                         Camera *ca= (Camera *)ob->data;
1568                         
1569                         type= ANIMTYPE_DSCAM;
1570                         expanded= FILTER_CAM_OBJD(ca);
1571                 }
1572                         break;
1573                 case OB_LAMP: /* ---------- Lamp ----------- */
1574                 {
1575                         Lamp *la= (Lamp *)ob->data;
1576                         
1577                         type= ANIMTYPE_DSLAM;
1578                         expanded= FILTER_LAM_OBJD(la);
1579                 }
1580                         break;
1581                 case OB_CURVE: /* ------- Curve ---------- */
1582                 case OB_SURF: /* ------- Nurbs Surface ---------- */
1583                 case OB_FONT: /* ------- Text Curve ---------- */
1584                 {
1585                         Curve *cu= (Curve *)ob->data;
1586                         
1587                         type= ANIMTYPE_DSCUR;
1588                         expanded= FILTER_CUR_OBJD(cu);
1589                 }
1590                         break;
1591                 case OB_MBALL: /* ------- MetaBall ---------- */
1592                 {
1593                         MetaBall *mb= (MetaBall *)ob->data;
1594                         
1595                         type= ANIMTYPE_DSMBALL;
1596                         expanded= FILTER_MBALL_OBJD(mb);
1597                 }
1598                         break;
1599                 case OB_ARMATURE: /* ------- Armature ---------- */
1600                 {
1601                         bArmature *arm= (bArmature *)ob->data;
1602                         
1603                         type= ANIMTYPE_DSARM;
1604                         expanded= FILTER_ARM_OBJD(arm);
1605                 }
1606                         break;
1607                 case OB_MESH: /* ------- Mesh ---------- */
1608                 {
1609                         Mesh *me= (Mesh *)ob->data;
1610                         
1611                         type= ANIMTYPE_DSMESH;
1612                         expanded= FILTER_MESH_OBJD(me);
1613                 }
1614                         break;
1615                 case OB_LATTICE: /* ---- Lattice ---- */
1616                 {
1617                         Lattice *lt = (Lattice *)ob->data;
1618                         
1619                         type= ANIMTYPE_DSLAT;
1620                         expanded= FILTER_LATTICE_OBJD(lt);
1621                 }
1622                         break;
1623         }
1624         
1625         /* special exception for drivers instead of action */
1626         if (ads->filterflag & ADS_FILTER_ONLYDRIVERS)
1627                 expanded= EXPANDED_DRVD(adt);
1628         
1629         /* include data-expand widget? */
1630         if ((filter_mode & ANIMFILTER_CURVESONLY) == 0) {       
1631                 /* check if filtering by active status */
1632                 if ANIMCHANNEL_ACTIVEOK(iat) {
1633                         ale= make_new_animlistelem(iat, type, base, ANIMTYPE_OBJECT, (ID *)iat);
1634                         if (ale) BLI_addtail(anim_data, ale);
1635                 }
1636         }
1637         
1638         /* add object-data animation channels? */
1639         if (!(filter_mode & ANIMFILTER_VISIBLE) || (expanded) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1640                 /* filtering for channels - nla, drivers, keyframes */
1641                 ANIMDATA_FILTER_CASES(iat, 
1642                         { /* AnimData blocks - do nothing... */ },
1643                         items+= animdata_filter_nla(ac, anim_data, ads, iat->adt, filter_mode, iat, type, (ID *)iat);,
1644                         items+= animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, iat, type, filter_mode, (ID *)iat);, 
1645                         items+= animdata_filter_action(ac, anim_data, ads, iat->adt->action, filter_mode, iat, type, (ID *)iat);)
1646                         
1647                 /* sub-data filtering... */
1648                 switch (ob->type) {
1649                         case OB_LAMP:   /* lamp - textures */
1650                         {
1651                                 /* textures */
1652                                 if (!(ads->filterflag & ADS_FILTER_NOTEX))
1653                                         items += animdata_filter_dopesheet_texs(ac, anim_data, ads, ob->data, filter_mode);
1654                         }
1655                                 break;
1656                 }
1657         }
1658         
1659         /* return the number of items added to the list */
1660         return items;
1661 }
1662
1663 static int animdata_filter_dopesheet_ob (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1664 {
1665         bAnimListElem *ale=NULL;
1666         AnimData *adt = NULL;
1667         Object *ob= base->object;
1668         Key *key= ob_get_key(ob);
1669         short obdata_ok = 0;
1670         int items = 0;
1671         
1672         /* add this object as a channel first */
1673         if ((filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) == 0) {
1674                 /* check if filtering by selection */
1675                 if ANIMCHANNEL_SELOK((base->flag & SELECT)) {
1676                         /* check if filtering by active status */
1677                         if ANIMCHANNEL_ACTIVEOK(ob) {
1678                                 ale= make_new_animlistelem(base, ANIMTYPE_OBJECT, NULL, ANIMTYPE_NONE, (ID *)ob);
1679                                 if (ale) {
1680                                         BLI_addtail(anim_data, ale);
1681                                         items++;
1682                                 }
1683                         }
1684                 }
1685         }
1686         
1687         /* if collapsed, don't go any further (unless adding keyframes only) */
1688         if ( ((filter_mode & ANIMFILTER_VISIBLE) && EXPANDED_OBJC(ob) == 0) &&
1689                  !(filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) )
1690                 return items;
1691         
1692         /* Action, Drivers, or NLA */
1693         if (ob->adt && !(ads->filterflag & ADS_FILTER_NOOBJ)) {
1694                 adt= ob->adt;
1695                 ANIMDATA_FILTER_CASES(ob,
1696                         { /* AnimData blocks - do nothing... */ },
1697                         { /* nla */
1698                                 /* add NLA tracks */
1699                                 items += animdata_filter_nla(ac, anim_data, ads, adt, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
1700                         },
1701                         { /* drivers */
1702                                 /* include drivers-expand widget? */
1703                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1704                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, base, ANIMTYPE_OBJECT, (ID *)ob);
1705                                         if (ale) {
1706                                                 BLI_addtail(anim_data, ale);
1707                                                 items++;
1708                                         }
1709                                 }
1710                                 
1711                                 /* add F-Curve channels (drivers are F-Curves) */
1712                                 if (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1713                                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1714                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)ob);
1715                                 }
1716                         },
1717                         { /* action (keyframes) */
1718                                 /* include action-expand widget? */
1719                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1720                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT, (ID *)ob);
1721                                         if (ale) {
1722                                                 BLI_addtail(anim_data, ale);
1723                                                 items++;
1724                                         }
1725                                 }
1726                                 
1727                                 /* add F-Curve channels? */
1728                                 if (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1729                                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1730                                         items += animdata_filter_action(ac, anim_data, ads, adt->action, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob); 
1731                                 }
1732                         }
1733                 );
1734         }
1735         
1736         
1737         /* ShapeKeys? */
1738         if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
1739                 adt= key->adt;
1740                 ANIMDATA_FILTER_CASES(key,
1741                         { /* AnimData blocks - do nothing... */ },
1742                         { /* nla */
1743                                 /* include shapekey-expand widget? */
1744                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1745                                         /* check if filtering by active status */
1746                                         if ANIMCHANNEL_ACTIVEOK(key) {
1747                                                 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1748                                                 if (ale) {
1749                                                         BLI_addtail(anim_data, ale);
1750                                                         items++;
1751                                                 }
1752                                         }
1753                                 }
1754                                 
1755                                 /* add NLA tracks - only if expanded or so */
1756                                 if (!(filter_mode & ANIMFILTER_VISIBLE) || FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY))
1757                                         items += animdata_filter_nla(ac, anim_data, ads, adt, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)key);
1758                         },
1759                         { /* drivers */
1760                                 /* include shapekey-expand widget? */
1761                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1762                                         ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1763                                         if (ale) {
1764                                                 BLI_addtail(anim_data, ale);
1765                                                 items++;
1766                                         }
1767                                 }
1768                                 
1769                                 /* add channels */
1770                                 if (!(filter_mode & ANIMFILTER_VISIBLE) || FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1771                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, key, ANIMTYPE_DSSKEY, filter_mode, (ID *)key);
1772                                 }
1773                         },
1774                         { /* action (keyframes) */
1775                                 /* include shapekey-expand widget? */
1776                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1777                                         /* check if filtering by active status */
1778                                         if ANIMCHANNEL_ACTIVEOK(key) {
1779                                                 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1780                                                 if (ale) {
1781                                                         BLI_addtail(anim_data, ale);
1782                                                         items++;
1783                                                 }
1784                                         }
1785                                 }
1786                                 
1787                                 /* add channels */
1788                                 if (!(filter_mode & ANIMFILTER_VISIBLE) || FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1789                                         items += animdata_filter_action(ac, anim_data, ads, adt->action, filter_mode, key, ANIMTYPE_DSSKEY, (ID *)key); 
1790                                 }
1791                         }
1792                 );
1793         }
1794
1795         /* Materials? */
1796         if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
1797                 items += animdata_filter_dopesheet_mats(ac, anim_data, ads, base, filter_mode);
1798         
1799         /* Object Data */
1800         switch (ob->type) {
1801                 case OB_CAMERA: /* ------- Camera ------------ */
1802                 {
1803                         Camera *ca= (Camera *)ob->data;
1804                         
1805                         if ((ads->filterflag & ADS_FILTER_NOCAM) == 0) {
1806                                 ANIMDATA_FILTER_CASES(ca,
1807                                         { /* AnimData blocks - do nothing... */ },
1808                                         obdata_ok= 1;,
1809                                         obdata_ok= 1;,
1810                                         obdata_ok= 1;)
1811                         }
1812                 }
1813                         break;
1814                 case OB_LAMP: /* ---------- Lamp ----------- */
1815                 {
1816                         Lamp *la= (Lamp *)ob->data;
1817                         
1818                         if ((ads->filterflag & ADS_FILTER_NOLAM) == 0) {
1819                                 ANIMDATA_FILTER_CASES(la,
1820                                         { /* AnimData blocks - do nothing... */ },
1821                                         obdata_ok= 1;,
1822                                         obdata_ok= 1;,
1823                                         obdata_ok= 1;)
1824                         }
1825                 }
1826                         break;
1827                 case OB_CURVE: /* ------- Curve ---------- */
1828                 case OB_SURF: /* ------- Nurbs Surface ---------- */
1829                 case OB_FONT: /* ------- Text Curve ---------- */
1830                 {
1831                         Curve *cu= (Curve *)ob->data;
1832                         
1833                         if ((ads->filterflag & ADS_FILTER_NOCUR) == 0) {
1834                                 ANIMDATA_FILTER_CASES(cu,
1835                                         { /* AnimData blocks - do nothing... */ },
1836                                         obdata_ok= 1;,
1837                                         obdata_ok= 1;,
1838                                         obdata_ok= 1;)
1839                         }
1840                 }
1841                         break;
1842                 case OB_MBALL: /* ------- MetaBall ---------- */
1843                 {
1844                         MetaBall *mb= (MetaBall *)ob->data;
1845                         
1846                         if ((ads->filterflag & ADS_FILTER_NOMBA) == 0) {
1847                                 ANIMDATA_FILTER_CASES(mb,
1848                                         { /* AnimData blocks - do nothing... */ },
1849                                         obdata_ok= 1;,
1850                                         obdata_ok= 1;,
1851                                         obdata_ok= 1;)
1852                         }
1853                 }
1854                         break;
1855                 case OB_ARMATURE: /* ------- Armature ---------- */
1856                 {
1857                         bArmature *arm= (bArmature *)ob->data;
1858                         
1859                         if ((ads->filterflag & ADS_FILTER_NOARM) == 0) {
1860                                 ANIMDATA_FILTER_CASES(arm,
1861                                         { /* AnimData blocks - do nothing... */ },
1862                                         obdata_ok= 1;,
1863                                         obdata_ok= 1;,
1864                                         obdata_ok= 1;)
1865                         }
1866                 }
1867                         break;
1868                 case OB_MESH: /* ------- Mesh ---------- */
1869                 {
1870                         Mesh *me= (Mesh *)ob->data;
1871                         
1872                         if ((ads->filterflag & ADS_FILTER_NOMESH) == 0) {
1873                                 ANIMDATA_FILTER_CASES(me,
1874                                         { /* AnimData blocks - do nothing... */ },
1875                                         obdata_ok= 1;,
1876                                         obdata_ok= 1;,
1877                                         obdata_ok= 1;)
1878                         }
1879                 }
1880                         break;
1881                 case OB_LATTICE: /* ------- Lattice ---------- */
1882                 {
1883                         Lattice *lt= (Lattice *)ob->data;
1884                         
1885                         if ((ads->filterflag & ADS_FILTER_NOLAT) == 0) {
1886                                 ANIMDATA_FILTER_CASES(lt,
1887                                         { /* AnimData blocks - do nothing... */ },
1888                                         obdata_ok= 1;,
1889                                         obdata_ok= 1;,
1890                                         obdata_ok= 1;)
1891                         }
1892                 }
1893                         break;
1894         }
1895         if (obdata_ok) 
1896                 items += animdata_filter_dopesheet_obdata(ac, anim_data, ads, base, filter_mode);
1897
1898         /* particles */
1899         if (ob->particlesystem.first && !(ads->filterflag & ADS_FILTER_NOPART))
1900                 items += animdata_filter_dopesheet_particles(ac, anim_data, ads, base, filter_mode);
1901         
1902         /* return the number of items added to the list */
1903         return items;
1904 }       
1905
1906 static int animdata_filter_dopesheet_scene (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1907 {
1908         World *wo= sce->world;
1909         bNodeTree *ntree= sce->nodetree;
1910         AnimData *adt= NULL;
1911         bAnimListElem *ale;
1912         int items = 0;
1913         
1914         /* add scene as a channel first (even if we aren't showing scenes we still need to show the scene's sub-data */
1915         if ((filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) == 0) {
1916                 /* check if filtering by selection */
1917                 if (ANIMCHANNEL_SELOK( (sce->flag & SCE_DS_SELECTED) )) {
1918                         ale= make_new_animlistelem(sce, ANIMTYPE_SCENE, NULL, ANIMTYPE_NONE, NULL);
1919                         if (ale) {
1920                                 BLI_addtail(anim_data, ale);
1921                                 items++;
1922                         }
1923                 }
1924         }
1925         
1926         /* if collapsed, don't go any further (unless adding keyframes only) */
1927         if ( (EXPANDED_SCEC(sce) == 0) && !(filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) )
1928                 return items;
1929                 
1930         /* Action, Drivers, or NLA for Scene */
1931         if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
1932                 adt= sce->adt;
1933                 ANIMDATA_FILTER_CASES(sce,
1934                         { /* AnimData blocks - do nothing... */ },
1935                         { /* nla */
1936                                 /* add NLA tracks */
1937                                 items += animdata_filter_nla(ac, anim_data, ads, adt, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce);
1938                         },
1939                         { /* drivers */
1940                                 /* include drivers-expand widget? */
1941                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1942                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, sce, ANIMTYPE_SCENE, (ID *)sce);
1943                                         if (ale) {
1944                                                 BLI_addtail(anim_data, ale);
1945                                                 items++;
1946                                         }
1947                                 }
1948                                 
1949                                 /* add F-Curve channels (drivers are F-Curves) */
1950                                 if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1951                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, sce, ANIMTYPE_SCENE, filter_mode, (ID *)sce);
1952                                 }
1953                         },
1954                         { /* action */
1955                                 /* include action-expand widget? */
1956                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1957                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, sce, ANIMTYPE_SCENE, (ID *)sce);
1958                                         if (ale) {
1959                                                 BLI_addtail(anim_data, ale);
1960                                                 items++;
1961                                         }
1962                                 }
1963                                 
1964                                 /* add F-Curve channels? */
1965                                 if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1966                                         items += animdata_filter_action(ac, anim_data, ads, adt->action, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce); 
1967                                 }
1968                         }
1969                 )
1970         }
1971         
1972         /* world */
1973         if ((wo && wo->adt) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
1974                 /* Action, Drivers, or NLA for World */
1975                 adt= wo->adt;
1976                 ANIMDATA_FILTER_CASES(wo,
1977                         { /* AnimData blocks - do nothing... */ },
1978                         { /* nla */
1979                                 /* add NLA tracks */
1980                                 items += animdata_filter_nla(ac, anim_data, ads, adt, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo);
1981                         },
1982                         { /* drivers */
1983                                 /* include world-expand widget? */
1984                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1985                                         ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)wo);
1986                                         if (ale) {
1987                                                 BLI_addtail(anim_data, ale);
1988                                                 items++;
1989                                         }
1990                                 }
1991                                 
1992                                 /* add F-Curve channels (drivers are F-Curves) */
1993                                 if (FILTER_WOR_SCED(wo)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
1994                                         // XXX owner info is messed up now...
1995                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, wo, ANIMTYPE_DSWOR, filter_mode, (ID *)wo);
1996                                 }
1997                         },
1998                         { /* action */
1999                                 /* include world-expand widget? */
2000                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
2001                                         ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)sce);
2002                                         if (ale) {
2003                                                 BLI_addtail(anim_data, ale);
2004                                                 items++;
2005                                         }
2006                                 }
2007                                 
2008                                 /* add channels */
2009                                 if (FILTER_WOR_SCED(wo) || (filter_mode & ANIMFILTER_CURVESONLY)) {
2010                                         items += animdata_filter_action(ac, anim_data, ads, adt->action, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo); 
2011                                 }
2012                         }
2013                 )
2014                 
2015                 /* if expanded, check world textures too */
2016                 if (FILTER_WOR_SCED(wo) || (filter_mode & ANIMFILTER_CURVESONLY)) {
2017                         /* textures for world */
2018                         if (!(ads->filterflag & ADS_FILTER_NOTEX))
2019                                 items += animdata_filter_dopesheet_texs(ac, anim_data, ads, (ID *)wo, filter_mode);
2020                 }
2021         }
2022         /* nodetree */
2023         if ((ntree && ntree->adt) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2024                 /* Action, Drivers, or NLA for Nodetree */
2025                 adt= ntree->adt;
2026                 ANIMDATA_FILTER_CASES(ntree,
2027                         { /* AnimData blocks - do nothing... */ },
2028                         { /* nla */
2029                                 /* add NLA tracks */
2030                                 items += animdata_filter_nla(ac, anim_data, ads, adt, filter_mode, ntree, ANIMTYPE_DSNTREE, (ID *)ntree);
2031                         },
2032                         { /* drivers */
2033                                 /* include nodetree-expand widget? */
2034                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
2035                                         ale= make_new_animlistelem(ntree, ANIMTYPE_DSNTREE, sce, ANIMTYPE_SCENE, (ID *)ntree);
2036                                         if (ale) {
2037                                                 BLI_addtail(anim_data, ale);
2038                                                 items++;
2039                                         }
2040                                 }
2041                                 
2042                                 /* add F-Curve channels (drivers are F-Curves) */
2043                                 if (FILTER_NTREE_SCED(ntree)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
2044                                         // XXX owner info is messed up now...
2045                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, ntree, ANIMTYPE_DSNTREE, filter_mode, (ID *)ntree);
2046                                 }
2047                         },
2048                         { /* action */
2049                                 /* include nodetree-expand widget? */
2050                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
2051                                         ale= make_new_animlistelem(ntree, ANIMTYPE_DSNTREE, sce, ANIMTYPE_SCENE, (ID *)sce);
2052                                         if (ale) {
2053                                                 BLI_addtail(anim_data, ale);
2054                                                 items++;
2055                                         }
2056                                 }
2057                                 
2058                                 /* add channels */
2059                                 if (FILTER_NTREE_SCED(ntree) || (filter_mode & ANIMFILTER_CURVESONLY)) {
2060                                         items += animdata_filter_action(ac, anim_data, ads, adt->action, filter_mode, ntree, ANIMTYPE_DSNTREE, (ID *)ntree); 
2061                                 }
2062                         }
2063                 )
2064         }
2065
2066         /* line styles */
2067         if (!(ads->filterflag & ADS_FILTER_NOLINESTYLE)) {
2068                 ListBase linestyles = {NULL, NULL};
2069                 LinkData *link;
2070                 SceneRenderLayer *srl;
2071                 FreestyleLineSet *lineset;
2072                 FreestyleLineStyle *linestyle;
2073
2074                 for (srl = (SceneRenderLayer *)sce->r.layers.first; srl; srl = srl->next) {
2075                         if (!(srl->layflag & SCE_LAY_FRS))
2076                                 continue;
2077                         for (lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
2078                                 short ok = 0;
2079
2080                                 linestyle = lineset->linestyle;
2081                                 if (!linestyle->adt)
2082                                         continue;
2083
2084                                 ANIMDATA_FILTER_CASES(linestyle, 
2085                                         { /* AnimData blocks - do nothing... */ },
2086                                         ok=1;, 
2087                                         ok=1;, 
2088                                         ok=1;)
2089                                 if (ok == 0) continue;
2090
2091                                 /* check if the same linestyle is already in the list */
2092                                 for (link = (LinkData *)linestyles.first; link; link = link->next) {
2093                                         if (link->data == linestyle) {
2094                                                 ok = 0;
2095                                                 break;
2096                                         }
2097                                 }
2098                                 if (ok == 0) continue;
2099
2100                                 /* add this linestyle to the list */
2101                                 link= MEM_callocN(sizeof(LinkData), "DopeSheet LineStyle cache");
2102                                 link->data= linestyle;
2103                                 BLI_addtail(&linestyles, link);
2104                         }
2105                 }
2106
2107                 if (linestyles.first) {
2108
2109                         for (link = (LinkData *)linestyles.first; link; link = link->next) {
2110                                 linestyle = (FreestyleLineStyle *)link->data;
2111
2112                                 /* Action, Drivers, or NLA for line styles */
2113                                 adt= linestyle->adt;
2114                                 ANIMDATA_FILTER_CASES(linestyle,
2115                                         { /* AnimData blocks - do nothing... */ },
2116                                         { /* nla */
2117                                                 /* add NLA tracks */
2118                                                 items += animdata_filter_nla(ac, anim_data, ads, adt, filter_mode, linestyle, ANIMTYPE_DSLINESTYLE, (ID *)linestyle);
2119                                         },
2120                                         { /* drivers */
2121                                                 /* include linestyle-expand widget? */
2122                                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
2123                                                         ale= make_new_animlistelem(linestyle, ANIMTYPE_DSLINESTYLE, sce, ANIMTYPE_SCENE, (ID *)linestyle);
2124                                                         if (ale) {
2125                                                                 BLI_addtail(anim_data, ale);
2126                                                                 items++;
2127                                                         }
2128                                                 }
2129                                                 
2130                                                 /* add F-Curve channels (drivers are F-Curves) */
2131                                                 if (FILTER_LS_SCED(linestyle)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
2132                                                         // XXX owner info is messed up now...
2133                                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, linestyle, ANIMTYPE_DSLINESTYLE, filter_mode, (ID *)linestyle);
2134                                                 }
2135                                         },
2136                                         { /* action */
2137                                                 /* include nodetree-expand widget? */
2138                                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
2139                                                         ale= make_new_animlistelem(linestyle, ANIMTYPE_DSLINESTYLE, sce, ANIMTYPE_SCENE, (ID *)sce);
2140                                                         if (ale) {
2141                                                                 BLI_addtail(anim_data, ale);
2142                                                                 items++;
2143                                                         }
2144                                                 }
2145                                                 
2146                                                 /* add channels */
2147                                                 if (FILTER_LS_SCED(linestyle) || (filter_mode & ANIMFILTER_CURVESONLY)) {
2148                                                         items += animdata_filter_action(ac, anim_data, ads, adt->action, filter_mode, linestyle, ANIMTYPE_DSLINESTYLE, (ID *)linestyle); 
2149                                                 }
2150                                         }
2151                                 )
2152                         }
2153
2154                         /* free cache */
2155                         BLI_freelistN(&linestyles);
2156                 }
2157         }
2158
2159         // TODO: scene compositing nodes (these aren't standard node-trees)
2160         
2161         /* return the number of items added to the list */
2162         return items;
2163 }
2164
2165 // TODO: implement pinning... (if and when pinning is done, what we need to do is to provide freeing mechanisms - to protect against data that was deleted)
2166 static int animdata_filter_dopesheet (bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, int filter_mode)
2167 {
2168         Scene *sce= (Scene *)ads->source;
2169         Base *base;
2170         bAnimListElem *ale;
2171         int items = 0;
2172         
2173         /* check that we do indeed have a scene */
2174         if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
2175                 printf("DopeSheet Error: Not scene!\n");
2176                 if (G.f & G_DEBUG)
2177                         printf("\tPointer = %p, Name = '%s' \n", (void *)ads->source, (ads->source)?ads->source->name:NULL);
2178                 return 0;
2179         }
2180         
2181         /* augment the filter-flags with settings based on the dopesheet filterflags 
2182          * so that some temp settings can get added automagically...
2183          */
2184         if (ads->filterflag & ADS_FILTER_SELEDIT) {
2185                 /* only selected F-Curves should get their keyframes considered for editability */
2186                 filter_mode |= ANIMFILTER_SELEDIT;
2187         }
2188         
2189         /* scene-linked animation */
2190         // TODO: sequencer, composite nodes - are we to include those here too?
2191         {
2192                 short sceOk= 0, worOk= 0, nodeOk=0, lsOk = 0;
2193                 
2194                 /* check filtering-flags if ok */
2195                 ANIMDATA_FILTER_CASES(sce, 
2196                         {
2197                                 /* for the special AnimData blocks only case, we only need to add
2198                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2199                                  */
2200                                 ANIMDATA_ADD_ANIMDATA(sce);
2201                                 sceOk=0;
2202                         },
2203                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);, 
2204                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);, 
2205                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);)
2206                 if (sce->world) {
2207                         ANIMDATA_FILTER_CASES(sce->world, 
2208                                 {
2209                                         /* for the special AnimData blocks only case, we only need to add
2210                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
2211                                          */
2212                                         ANIMDATA_ADD_ANIMDATA(sce->world);
2213                                         worOk=0;
2214                                 },
2215                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);, 
2216                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);, 
2217                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);)
2218                 }
2219                 if (sce->nodetree) {
2220                         ANIMDATA_FILTER_CASES(sce->nodetree, 
2221                                 {
2222                                         /* for the special AnimData blocks only case, we only need to add
2223                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
2224                                          */
2225                                         ANIMDATA_ADD_ANIMDATA(sce->nodetree);
2226                                         nodeOk=0;
2227                                 },
2228                                 nodeOk= !(ads->filterflag & ADS_FILTER_NONTREE);, 
2229                                 nodeOk= !(ads->filterflag & ADS_FILTER_NONTREE);, 
2230                                 nodeOk= !(ads->filterflag & ADS_FILTER_NONTREE);)
2231                 }
2232
2233                 /* line styles */
2234                 {
2235                         SceneRenderLayer *srl;
2236                         FreestyleLineSet *lineset;
2237
2238                         for (srl = (SceneRenderLayer *)sce->r.layers.first; srl; srl = srl->next) {
2239                                 if (srl->layflag & SCE_LAY_FRS) {
2240                                         for (lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
2241                                                 ANIMDATA_FILTER_CASES(lineset->linestyle, 
2242                                                         {
2243                                                                 /* for the special AnimData blocks only case, we only need to add
2244                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2245                                                                  */
2246                                                                 ANIMDATA_ADD_ANIMDATA(lineset->linestyle);
2247                                                                 lsOk=0;
2248                                                         },
2249                                                         lsOk= !(ads->filterflag & ADS_FILTER_NOLINESTYLE);, 
2250                                                         lsOk= !(ads->filterflag & ADS_FILTER_NOLINESTYLE);, 
2251                                                         lsOk= !(ads->filterflag & ADS_FILTER_NOLINESTYLE);)
2252                                         }
2253                                 }
2254                         }
2255                 }
2256                 
2257                 /* if only F-Curves with visible flags set can be shown, check that 
2258                  * datablocks haven't been set to invisible 
2259                  */
2260                 if (filter_mode & ANIMFILTER_CURVEVISIBLE) {
2261                         if ((sce->adt) && (sce->adt->flag & ADT_CURVES_NOT_VISIBLE))
2262                                 sceOk= worOk= nodeOk= lsOk= 0;
2263                 }
2264                 
2265                 /* check if not all bad (i.e. so there is something to show) */
2266                 if ( !(!sceOk && !worOk && !nodeOk && !lsOk) ) {
2267                         /* add scene data to the list of filtered channels */
2268                         items += animdata_filter_dopesheet_scene(ac, anim_data, ads, sce, filter_mode);
2269                 }
2270         }
2271         
2272         
2273         /* loop over all bases in the scene */
2274         for (base= sce->base.first; base; base= base->next) {
2275                 /* check if there's an object (all the relevant checks are done in the ob-function) */
2276                 if (base->object) {
2277                         Object *ob= base->object;
2278                         Key *key= ob_get_key(ob);
2279                         short actOk=1, keyOk=1, dataOk=1, matOk=1, partOk=1;
2280                         
2281                         /* firstly, check if object can be included, by the following factors:
2282                          *      - if only visible, must check for layer and also viewport visibility
2283                          *              --> while tools may demand only visible, user setting takes priority
2284                          *                      as user option controls whether sets of channels get included while
2285                          *                      tool-flag takes into account collapsed/open channels too
2286                          *      - if only selected, must check if object is selected 
2287                          *      - there must be animation data to edit
2288                          */
2289                         // TODO: if cache is implemented, just check name here, and then 
2290                         if ((filter_mode & ANIMFILTER_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
2291                                 /* layer visibility - we check both object and base, since these may not be in sync yet */
2292                                 if ((sce->lay & (ob->lay|base->lay))==0) continue;
2293                                 
2294                                 /* outliner restrict-flag */
2295                                 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
2296                         }
2297                         
2298                         /* if only F-Curves with visible flags set can be shown, check that 
2299                          * datablock hasn't been set to invisible 
2300                          */
2301                         if (filter_mode & ANIMFILTER_CURVEVISIBLE) {
2302                                 if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE))
2303                                         continue;
2304                         }
2305                         
2306                         /* additionally, dopesheet filtering also affects what objects to consider */
2307                         {
2308                                 /* check selection and object type filters */
2309                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) /*|| (base == sce->basact)*/) )  {
2310                                         /* only selected should be shown */
2311                                         continue;
2312                                 }
2313                                 
2314                                 /* check if object belongs to the filtering group if option to filter 
2315                                  * objects by the grouped status is on
2316                                  *      - used to ease the process of doing multiple-character choreographies
2317                                  */
2318                                 if (ads->filterflag & ADS_FILTER_ONLYOBGROUP) {
2319                                         if (object_in_group(ob, ads->filter_grp) == 0)
2320                                                 continue;
2321                                 }
2322                                 
2323                                 /* check filters for datatypes */
2324                                         /* object */
2325                                 actOk= 0;
2326                                 if (!(ads->filterflag & ADS_FILTER_NOOBJ)) {
2327                                         ANIMDATA_FILTER_CASES(ob, 
2328                                                 {
2329                                                         /* for the special AnimData blocks only case, we only need to add
2330                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
2331                                                          */
2332                                                         ANIMDATA_ADD_ANIMDATA(ob);
2333                                                         actOk=0;
2334                                                 },
2335                                                 actOk= 1;, 
2336                                                 actOk= 1;, 
2337                                                 actOk= 1;)
2338                                 }
2339                                 
2340                                 keyOk= 0;
2341                                 if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
2342                                         /* shapekeys */
2343                                         ANIMDATA_FILTER_CASES(key, 
2344                                                 {
2345                                                         /* for the special AnimData blocks only case, we only need to add
2346                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
2347                                                          */
2348                                                         ANIMDATA_ADD_ANIMDATA(key);
2349                                                         keyOk=0;
2350                                                 },
2351                                                 keyOk= 1;, 
2352                                                 keyOk= 1;, 
2353                                                 keyOk= 1;)
2354                                 }
2355                                 
2356                                 /* materials - only for geometric types */
2357                                 matOk= 0; /* by default, not ok... */
2358                                 if ( !(ads->filterflag & ADS_FILTER_NOMAT) && (ob->totcol) && 
2359                                          ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) ) 
2360                                 {
2361                                         int a;
2362                                         
2363                                         /* firstly check that we actuallly have some materials */
2364                                         for (a=1; a <= ob->totcol; a++) {
2365                                                 Material *ma= give_current_material(ob, a);
2366                                                 
2367                                                 if (ma) {
2368                                                         /* if material has relevant animation data, break */
2369                                                         ANIMDATA_FILTER_CASES(ma, 
2370                                                                 {
2371                                                                         /* for the special AnimData blocks only case, we only need to add
2372                                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
2373                                                                          */
2374                                                                         ANIMDATA_ADD_ANIMDATA(ma);
2375                                                                         matOk=0;
2376                                                                 },
2377                                                                 matOk= 1;, 
2378                                                                 matOk= 1;, 
2379                                                                 matOk= 1;)
2380                                                                 
2381                                                         if (matOk) 
2382                                                                 break;
2383                                                         
2384                                                         /* textures? */
2385                                                         // TODO: make this a macro that is used in the other checks too
2386                                                         // NOTE: this has little use on its own, since the actual filtering still ignores if no anim on the data
2387                                                         if (!(ads->filterflag & ADS_FILTER_NOTEX)) {
2388                                                                 int mtInd;
2389                                                                 
2390                                                                 for (mtInd= 0; mtInd < MAX_MTEX; mtInd++) {
2391                                                                         MTex *mtex= ma->mtex[mtInd];
2392                                                                         
2393                                                                         if (mtex && mtex->tex) {
2394                                                                                 /* if texture has relevant animation data, break */
2395                                                                                 ANIMDATA_FILTER_CASES(mtex->tex, 
2396                                                                                         {
2397                                                                                                 /* for the special AnimData blocks only case, we only need to add
2398                                                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2399                                                                                                  */
2400                                                                                                 ANIMDATA_ADD_ANIMDATA(mtex->tex);
2401                                                                                                 matOk=0;
2402                                                                                         },
2403                                                                                         matOk= 1;, 
2404                                                                                         matOk= 1;, 
2405                                                                                         matOk= 1;)
2406                                                                                         
2407                                                                                 if (matOk) 
2408                                                                                         break;
2409                                                                         }
2410                                                                 }
2411                                                         }
2412                                                         
2413                                                 }
2414                                         }
2415                                 }
2416                                 
2417                                 /* data */
2418                                 switch (ob->type) {
2419                                         case OB_CAMERA: /* ------- Camera ------------ */
2420                                         {
2421                                                 Camera *ca= (Camera *)ob->data;
2422                                                 dataOk= 0;
2423                                                 ANIMDATA_FILTER_CASES(ca, 
2424                                                         if ((ads->filterflag & ADS_FILTER_NOCAM)==0) {
2425                                                                 /* for the special AnimData blocks only case, we only need to add
2426                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2427                                                                  */
2428                                                                 ANIMDATA_ADD_ANIMDATA(ca);
2429                                                                 dataOk=0;
2430                                                         },
2431                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);, 
2432                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);, 
2433                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);)
2434                                         }
2435                                                 break;
2436                                         case OB_LAMP: /* ---------- Lamp ----------- */
2437                                         {
2438                                                 Lamp *la= (Lamp *)ob->data;
2439                                                 dataOk= 0;
2440                                                 ANIMDATA_FILTER_CASES(la, 
2441                                                         if ((ads->filterflag & ADS_FILTER_NOLAM)==0) {
2442                                                                 /* for the special AnimData blocks only case, we only need to add
2443                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2444                                                                  */
2445                                                                 ANIMDATA_ADD_ANIMDATA(la);
2446                                                                 dataOk=0;
2447                                                         },
2448                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);, 
2449                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);, 
2450                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);)
2451                                         }
2452                                                 break;
2453                                         case OB_CURVE: /* ------- Curve ---------- */
2454                                         case OB_SURF: /* ------- Nurbs Surface ---------- */
2455                                         case OB_FONT: /* ------- Text Curve ---------- */
2456                                         {
2457                                                 Curve *cu= (Curve *)ob->data;
2458                                                 dataOk= 0;
2459                                                 ANIMDATA_FILTER_CASES(cu, 
2460                                                         if ((ads->filterflag & ADS_FILTER_NOCUR)==0) {
2461                                                                 /* for the special AnimData blocks only case, we only need to add
2462                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2463                                                                  */
2464                                                                 ANIMDATA_ADD_ANIMDATA(cu);
2465                                                                 dataOk=0;
2466                                                         },
2467                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);, 
2468                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);, 
2469                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);)
2470                                         }
2471                                                 break;
2472                                         case OB_MBALL: /* ------- MetaBall ---------- */
2473                                         {
2474                                                 MetaBall *mb= (MetaBall *)ob->data;
2475                                                 dataOk= 0;
2476                                                 ANIMDATA_FILTER_CASES(mb, 
2477                                                         if ((ads->filterflag & ADS_FILTER_NOMBA)==0) {
2478                                                                 /* for the special AnimData blocks only case, we only need to add
2479                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2480                                                                  */
2481                                                                 ANIMDATA_ADD_ANIMDATA(mb);
2482                                                                 dataOk=0;
2483                                                         },
2484                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);, 
2485                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);, 
2486                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);)
2487                                         }
2488                                                 break;
2489                                         case OB_ARMATURE: /* ------- Armature ---------- */
2490                                         {
2491                                                 bArmature *arm= (bArmature *)ob->data;
2492                                                 dataOk= 0;
2493                                                 ANIMDATA_FILTER_CASES(arm, 
2494                                                         if ((ads->filterflag & ADS_FILTER_NOARM)==0) {
2495                                                                 /* for the special AnimData blocks only case, we only need to add
2496                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2497                                                                  */
2498                                                                 ANIMDATA_ADD_ANIMDATA(arm);
2499                                                                 dataOk=0;
2500                                                         },
2501                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
2502                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
2503                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);)
2504                                         }
2505                                                 break;
2506                                         case OB_MESH: /* ------- Mesh ---------- */
2507                                         {
2508                                                 Mesh *me= (Mesh *)ob->data;
2509                                                 dataOk= 0;
2510                                                 ANIMDATA_FILTER_CASES(me, 
2511                                                         if ((ads->filterflag & ADS_FILTER_NOMESH)==0) {
2512                                                                 /* for the special AnimData blocks only case, we only need to add
2513                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
2514                                                                  */
2515                                                                 ANIMDATA_ADD_ANIMDATA(me);
2516                                                                 dataOk=0;
2517                                                         },
2518