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