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