Animation Editors: 'Only Selected' filtering option now works on Pose Channels too
[blender.git] / source / blender / editors / animation / anim_filter.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 #include <stdio.h>
50
51 #include "DNA_listBase.h"
52 #include "DNA_ID.h"
53 #include "DNA_anim_types.h"
54 #include "DNA_action_types.h"
55 #include "DNA_armature_types.h"
56 #include "DNA_constraint_types.h"
57 #include "DNA_camera_types.h"
58 #include "DNA_curve_types.h"
59 #include "DNA_gpencil_types.h"
60 #include "DNA_ipo_types.h"
61 #include "DNA_lamp_types.h"
62 #include "DNA_lattice_types.h"
63 #include "DNA_key_types.h"
64 #include "DNA_material_types.h"
65 #include "DNA_mesh_types.h"
66 #include "DNA_meta_types.h"
67 #include "DNA_object_types.h"
68 #include "DNA_particle_types.h"
69 #include "DNA_space_types.h"
70 #include "DNA_scene_types.h"
71 #include "DNA_screen_types.h"
72 #include "DNA_windowmanager_types.h"
73 #include "DNA_world_types.h"
74
75 #include "MEM_guardedalloc.h"
76
77 #include "BLI_blenlib.h"
78
79 #include "BKE_animsys.h"
80 #include "BKE_action.h"
81 #include "BKE_context.h"
82 #include "BKE_global.h"
83 #include "BKE_key.h"
84 #include "BKE_object.h"
85 #include "BKE_material.h"
86 #include "BKE_screen.h"
87 #include "BKE_utildefines.h"
88
89 #include "ED_anim_api.h"
90 #include "ED_types.h"
91 #include "ED_util.h"
92
93 #include "WM_api.h"
94 #include "WM_types.h"
95
96 #include "BIF_gl.h"
97 #include "BIF_glutil.h"
98
99 #include "UI_interface.h"
100 #include "UI_resources.h"
101 #include "UI_view2d.h"
102
103 /* ************************************************************ */
104 /* Blender Context <-> Animation Context mapping */
105
106 /* ----------- Private Stuff - Action Editor ------------- */
107
108 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
109 /* Note: there's a similar function in key.c (ob_get_key) */
110 Key *actedit_get_shapekeys (bAnimContext *ac, SpaceAction *saction) 
111 {
112     Scene *scene= ac->scene;
113     Object *ob;
114     Key *key;
115         
116     ob = OBACT;
117     if (ob == NULL) 
118                 return NULL;
119         
120         /* XXX pinning is not available in 'ShapeKey' mode... */
121         //if (saction->pin) return NULL;
122         
123         /* shapekey data is stored with geometry data */
124         switch (ob->type) {
125                 case OB_MESH:
126                         key= ((Mesh *)ob->data)->key;
127                         break;
128                         
129                 case OB_LATTICE:
130                         key= ((Lattice *)ob->data)->key;
131                         break;
132                         
133                 case OB_CURVE:
134                 case OB_SURF:
135                         key= ((Curve *)ob->data)->key;
136                         break;
137                         
138                 default:
139                         return NULL;
140         }
141         
142         if (key) {
143                 if (key->type == KEY_RELATIVE)
144                         return key;
145         }
146         
147     return NULL;
148 }
149
150 /* Get data being edited in Action Editor (depending on current 'mode') */
151 static short actedit_get_context (bAnimContext *ac, SpaceAction *saction)
152 {
153         /* sync settings with current view status, then return appropriate data */
154         switch (saction->mode) {
155                 case SACTCONT_ACTION: /* 'Action Editor' */
156                         /* if not pinned, sync with active object */
157                         if (saction->pin == 0) {
158                                 if (ac->obact && ac->obact->adt)
159                                         saction->action = ac->obact->adt->action;
160                                 else
161                                         saction->action= NULL;
162                         }
163                         
164                         ac->datatype= ANIMCONT_ACTION;
165                         ac->data= saction->action;
166                         
167                         ac->mode= saction->mode;
168                         return 1;
169                         
170                 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
171                         ac->datatype= ANIMCONT_SHAPEKEY;
172                         ac->data= actedit_get_shapekeys(ac, saction);
173                         
174                         ac->mode= saction->mode;
175                         return 1;
176                         
177                 case SACTCONT_GPENCIL: /* Grease Pencil */ // XXX review how this mode is handled...
178                         ac->datatype=ANIMCONT_GPENCIL;
179                         //ac->data= CTX_wm_screen(C); // FIXME: add that dopesheet type thing here!
180                         ac->data= NULL; // !!!
181                         
182                         ac->mode= saction->mode;
183                         return 1;
184                         
185                 case SACTCONT_DOPESHEET: /* DopeSheet */
186                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
187                         saction->ads.source= (ID *)ac->scene;
188                         
189                         ac->datatype= ANIMCONT_DOPESHEET;
190                         ac->data= &saction->ads;
191                         
192                         ac->mode= saction->mode;
193                         return 1;
194                 
195                 default: /* unhandled yet */
196                         ac->datatype= ANIMCONT_NONE;
197                         ac->data= NULL;
198                         
199                         ac->mode= -1;
200                         return 0;
201         }
202 }
203
204 /* ----------- Private Stuff - Graph Editor ------------- */
205
206 /* Get data being edited in Graph Editor (depending on current 'mode') */
207 static short graphedit_get_context (bAnimContext *ac, SpaceIpo *sipo)
208 {
209         /* init dopesheet data if non-existant (i.e. for old files) */
210         if (sipo->ads == NULL)
211                 sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
212         
213         /* set settings for Graph Editor - "Selected = Editable" */
214         if (sipo->flag & SIPO_SELCUVERTSONLY)
215                 sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
216         else
217                 sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
218         
219         /* sync settings with current view status, then return appropriate data */
220         switch (sipo->mode) {
221                 case SIPO_MODE_ANIMATION:       /* Animation F-Curve Editor */
222                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
223                         sipo->ads->source= (ID *)ac->scene;
224                         sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
225                         
226                         ac->datatype= ANIMCONT_FCURVES;
227                         ac->data= sipo->ads;
228                         
229                         ac->mode= sipo->mode;
230                         return 1;
231                 
232                 case SIPO_MODE_DRIVERS:         /* Driver F-Curve Editor */
233                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
234                         sipo->ads->source= (ID *)ac->scene;
235                         sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
236                         
237                         ac->datatype= ANIMCONT_DRIVERS;
238                         ac->data= sipo->ads;
239                         
240                         ac->mode= sipo->mode;
241                         return 1;
242                 
243                 default: /* unhandled yet */
244                         ac->datatype= ANIMCONT_NONE;
245                         ac->data= NULL;
246                         
247                         ac->mode= -1;
248                         return 0;
249         }
250 }
251
252 /* ----------- Private Stuff - NLA Editor ------------- */
253
254 /* Get data being edited in Graph Editor (depending on current 'mode') */
255 static short nlaedit_get_context (bAnimContext *ac, SpaceNla *snla)
256 {
257         /* init dopesheet data if non-existant (i.e. for old files) */
258         if (snla->ads == NULL)
259                 snla->ads= MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
260         
261         /* sync settings with current view status, then return appropriate data */
262         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
263         snla->ads->source= (ID *)ac->scene;
264         snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
265         
266         ac->datatype= ANIMCONT_NLA;
267         ac->data= snla->ads;
268         
269         return 1;
270 }
271
272 /* ----------- Public API --------------- */
273
274 /* Obtain current anim-data context, given that context info from Blender context has already been set 
275  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
276  *        allocation/freeing costs (which are not that avoidable with channels).
277  */
278 short ANIM_animdata_context_getdata (bAnimContext *ac)
279 {
280         ScrArea *sa= ac->sa;
281         short ok= 0;
282         
283         /* context depends on editor we are currently in */
284         if (sa) {
285                 switch (sa->spacetype) {
286                         case SPACE_ACTION:
287                         {
288                                 SpaceAction *saction= (SpaceAction *)sa->spacedata.first;
289                                 ok= actedit_get_context(ac, saction);
290                         }
291                                 break;
292                                 
293                         case SPACE_IPO:
294                         {
295                                 SpaceIpo *sipo= (SpaceIpo *)sa->spacedata.first;
296                                 ok= graphedit_get_context(ac, sipo);
297                         }
298                                 break;
299                                 
300                         case SPACE_NLA:
301                         {
302                                 SpaceNla *snla= (SpaceNla *)sa->spacedata.first;
303                                 ok= nlaedit_get_context(ac, snla);
304                         }
305                                 break;
306                 }
307         }
308         
309         /* check if there's any valid data */
310         if (ok && ac->data)
311                 return 1;
312         else
313                 return 0;
314 }
315
316 /* Obtain current anim-data context from Blender Context info 
317  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
318  *        allocation/freeing costs (which are not that avoidable with channels).
319  *      - Clears data and sets the information from Blender Context which is useful
320  */
321 short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac)
322 {
323         ScrArea *sa= CTX_wm_area(C);
324         ARegion *ar= CTX_wm_region(C);
325         Scene *scene= CTX_data_scene(C);
326         
327         /* clear old context info */
328         if (ac == NULL) return 0;
329         memset(ac, 0, sizeof(bAnimContext));
330         
331         /* get useful default context settings from context */
332         ac->scene= scene;
333         if (scene) {
334                 ac->markers= &scene->markers;           
335                 ac->obact= (scene->basact)?  scene->basact->object : NULL;
336         }
337         ac->sa= sa;
338         ac->ar= ar;
339         ac->spacetype= (sa) ? sa->spacetype : 0;
340         ac->regiontype= (ar) ? ar->regiontype : 0;
341         
342         /* get data context info */
343         return ANIM_animdata_context_getdata(ac);
344 }
345
346 /* ************************************************************ */
347 /* Blender Data <-- Filter --> Channels to be operated on */
348
349 /* quick macro to test if AnimData is usable */
350 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
351
352 /* quick macro to test if AnimData is usable for drivers */
353 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
354
355 /* quick macro to test if AnimData is usable for NLA */
356 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
357
358
359 /* Quick macro to test for all three avove usability tests, performing the appropriate provided 
360  * action for each when the AnimData context is appropriate. 
361  *
362  * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
363  *
364  * For this to work correctly, a standard set of data needs to be available within the scope that this
365  * gets called in: 
366  *      - ListBase anim_data;
367  *      - bDopeSheet *ads;
368  *      - bAnimListElem *ale;
369  *      - int items;
370  *
371  *      - id: ID block which should have an AnimData pointer following it immediately, to use
372  *      - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA)
373  *      - nlaOk: line or block of code to execute for NLA case
374  *      - driversOk: line or block of code to execute for Drivers case
375  *      - keysOk: line or block of code for Keyframes case
376  */
377 #define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, keysOk) \
378         {\
379                 if ((id)->adt) {\
380                         if (!(filter_mode & ANIMFILTER_CURVEVISIBLE) || !((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) {\
381                                 if (filter_mode & ANIMFILTER_ANIMDATA) {\
382                                         adtOk\
383                                 }\
384                                 else if (ads->filterflag & ADS_FILTER_ONLYNLA) {\
385                                         if (ANIMDATA_HAS_NLA(id)) {\
386                                                 nlaOk\
387                                         }\
388                                         else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) && ANIMDATA_HAS_KEYS(id)) {\
389                                                 nlaOk\
390                                         }\
391                                 }\
392                                 else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) {\
393                                         if (ANIMDATA_HAS_DRIVERS(id)) {\
394                                                 driversOk\
395                                         }\
396                                 }\
397                                 else {\
398                                         if (ANIMDATA_HAS_KEYS(id)) {\
399                                                 keysOk\
400                                         }\
401                                 }\
402                         }\
403                 }\
404         }
405
406
407 /* quick macro to add a pointer to an AnimData block as a channel */
408 #define ANIMDATA_ADD_ANIMDATA(id) \
409         {\
410                 ale= make_new_animlistelem((id)->adt, ANIMTYPE_ANIMDATA, NULL, ANIMTYPE_NONE, (ID *)id);\
411                 if (ale) {\
412                         BLI_addtail(anim_data, ale);\
413                         items++;\
414                 }\
415         }
416         
417 /* quick macro to test if an anim-channel representing an AnimData block is suitably active */
418 #define ANIMCHANNEL_ACTIVEOK(ale) \
419         ( !(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE) )
420
421 /* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
422 #define ANIMCHANNEL_SELOK(test_func) \
423                 ( !(filter_mode & (ANIMFILTER_SEL|ANIMFILTER_UNSEL)) || \
424                   ((filter_mode & ANIMFILTER_SEL) && test_func) || \
425                   ((filter_mode & ANIMFILTER_UNSEL) && test_func==0) ) 
426                   
427 /* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes 
428  *      - _SELEDIT means that only selected curves will have visible+editable keyframes
429  */
430 // FIXME: this doesn't work cleanly yet...
431 #define ANIMCHANNEL_SELEDITOK(test_func) \
432                 ( !(filter_mode & ANIMFILTER_SELEDIT) || \
433                   (filter_mode & ANIMFILTER_CHANNELS) || \
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                 ale->owner= owner;
454                 ale->ownertype= ownertype;
455                 
456                 ale->id= owner_id;
457                 ale->adt= BKE_animdata_from_id(owner_id);
458                 
459                 /* do specifics */
460                 switch (datatype) {
461                         case ANIMTYPE_SCENE:
462                         {
463                                 Scene *sce= (Scene *)data;
464                                 
465                                 ale->flag= sce->flag;
466                                 
467                                 ale->key_data= sce;
468                                 ale->datatype= ALE_SCE;
469                                 
470                                 ale->adt= BKE_animdata_from_id(data);
471                         }
472                                 break;
473                         case ANIMTYPE_OBJECT:
474                         {
475                                 Base *base= (Base *)data;
476                                 Object *ob= base->object;
477                                 
478                                 ale->flag= ob->flag;
479                                 
480                                 ale->key_data= ob;
481                                 ale->datatype= ALE_OB;
482                                 
483                                 ale->adt= BKE_animdata_from_id(&ob->id);
484                         }
485                                 break;
486                         case ANIMTYPE_FILLACTD:
487                         {
488                                 bAction *act= (bAction *)data;
489                                 
490                                 ale->flag= act->flag;
491                                 
492                                 ale->key_data= act;
493                                 ale->datatype= ALE_ACT;
494                         }
495                                 break;
496                         case ANIMTYPE_FILLDRIVERS:
497                         {
498                                 AnimData *adt= (AnimData *)data;
499                                 
500                                 ale->flag= adt->flag;
501                                 
502                                         // XXX... drivers don't show summary for now
503                                 ale->key_data= NULL;
504                                 ale->datatype= ALE_NONE;
505                         }
506                                 break;
507                         case ANIMTYPE_FILLMATD:
508                         {
509                                 Object *ob= (Object *)data;
510                                 
511                                 ale->flag= FILTER_MAT_OBJC(ob);
512                                 
513                                 ale->key_data= NULL;
514                                 ale->datatype= ALE_NONE;
515                         }
516                                 break;
517                         case ANIMTYPE_FILLPARTD:
518                         {
519                                 Object *ob= (Object *)data;
520                                 
521                                 ale->flag= FILTER_PART_OBJC(ob);
522                                 
523                                 ale->key_data= NULL;
524                                 ale->datatype= ALE_NONE;
525                         }
526                                 break;
527                         
528                         case ANIMTYPE_DSMAT:
529                         {
530                                 Material *ma= (Material *)data;
531                                 AnimData *adt= ma->adt;
532                                 
533                                 ale->flag= FILTER_MAT_OBJD(ma);
534                                 
535                                 ale->key_data= (adt) ? adt->action : NULL;
536                                 ale->datatype= ALE_ACT;
537                                 
538                                 ale->adt= BKE_animdata_from_id(data);
539                         }
540                                 break;
541                         case ANIMTYPE_DSLAM:
542                         {
543                                 Lamp *la= (Lamp *)data;
544                                 AnimData *adt= la->adt;
545                                 
546                                 ale->flag= FILTER_LAM_OBJD(la);
547                                 
548                                 ale->key_data= (adt) ? adt->action : NULL;
549                                 ale->datatype= ALE_ACT;
550                                 
551                                 ale->adt= BKE_animdata_from_id(data);
552                         }
553                                 break;
554                         case ANIMTYPE_DSCAM:
555                         {
556                                 Camera *ca= (Camera *)data;
557                                 AnimData *adt= ca->adt;
558                                 
559                                 ale->flag= FILTER_CAM_OBJD(ca);
560                                 
561                                 ale->key_data= (adt) ? adt->action : NULL;
562                                 ale->datatype= ALE_ACT;
563                                 
564                                 ale->adt= BKE_animdata_from_id(data);
565                         }
566                                 break;
567                         case ANIMTYPE_DSCUR:
568                         {
569                                 Curve *cu= (Curve *)data;
570                                 AnimData *adt= cu->adt;
571                                 
572                                 ale->flag= FILTER_CUR_OBJD(cu);
573                                 
574                                 ale->key_data= (adt) ? adt->action : NULL;
575                                 ale->datatype= ALE_ACT;
576                                 
577                                 ale->adt= BKE_animdata_from_id(data);
578                         }
579                                 break;
580                         case ANIMTYPE_DSSKEY:
581                         {
582                                 Key *key= (Key *)data;
583                                 AnimData *adt= key->adt;
584                                 
585                                 ale->flag= FILTER_SKE_OBJD(key); 
586                                 
587                                 ale->key_data= (adt) ? adt->action : NULL;
588                                 ale->datatype= ALE_ACT;
589                                 
590                                 ale->adt= BKE_animdata_from_id(data);
591                         }
592                                 break;
593                         case ANIMTYPE_DSWOR:
594                         {
595                                 World *wo= (World *)data;
596                                 AnimData *adt= wo->adt;
597                                 
598                                 ale->flag= FILTER_WOR_SCED(wo); 
599                                 
600                                 ale->key_data= (adt) ? adt->action : NULL;
601                                 ale->datatype= ALE_ACT;
602                                 
603                                 ale->adt= BKE_animdata_from_id(data);
604                         }
605                                 break;
606                         case ANIMTYPE_DSPART:
607                         {
608                                 ParticleSettings *part= (ParticleSettings*)ale->data;
609                                 AnimData *adt= part->adt;
610                                 
611                                 ale->flag= FILTER_PART_OBJD(part); 
612                                 
613                                 ale->key_data= (adt) ? adt->action : NULL;
614                                 ale->datatype= ALE_ACT;
615                                 
616                                 ale->adt= BKE_animdata_from_id(data);
617                         }
618                                 break;
619                                 
620                         case ANIMTYPE_GROUP:
621                         {
622                                 bActionGroup *agrp= (bActionGroup *)data;
623                                 
624                                 ale->flag= agrp->flag;
625                                 
626                                 ale->key_data= NULL;
627                                 ale->datatype= ALE_GROUP;
628                         }
629                                 break;
630                         case ANIMTYPE_FCURVE:
631                         {
632                                 FCurve *fcu= (FCurve *)data;
633                                 
634                                 ale->flag= fcu->flag;
635                                 
636                                 ale->key_data= fcu;
637                                 ale->datatype= ALE_FCURVE;
638                         }
639                                 break;
640                         
641                         case ANIMTYPE_GPLAYER:
642                         {
643                                 bGPDlayer *gpl= (bGPDlayer *)data;
644                                 
645                                 ale->flag= gpl->flag;
646                                 
647                                 ale->key_data= NULL;
648                                 ale->datatype= ALE_GPFRAME;
649                         }
650                                 break;
651                                 
652                         case ANIMTYPE_NLATRACK:
653                         {
654                                 NlaTrack *nlt= (NlaTrack *)data;
655                                 
656                                 ale->flag= nlt->flag;
657                                 
658                                         // XXX or should this be done some other way?
659                                 ale->key_data= &nlt->strips;
660                                 ale->datatype= ALE_NLASTRIP;
661                         }
662                                 break;
663                         case ANIMTYPE_NLAACTION:
664                         {
665                                 /* nothing to include for now... nothing editable from NLA-perspective here */
666                                 ale->key_data= NULL;
667                                 ale->datatype= ALE_NONE;
668                         }
669                                 break;
670                 }
671         }
672         
673         /* return created datatype */
674         return ale;
675 }
676  
677 /* ----------------------------------------- */
678
679
680 static int animdata_filter_fcurves (ListBase *anim_data, bDopeSheet *ads, FCurve *first, bActionGroup *grp, void *owner, short ownertype, int filter_mode, ID *owner_id)
681 {
682         bAnimListElem *ale = NULL;
683         FCurve *fcu;
684         int items = 0;
685         
686         /* loop over F-Curves - assume that the caller of this has already checked that these should be included 
687          * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
688          */
689         for (fcu= first; ((fcu) && (fcu->grp==grp)); fcu= fcu->next) {
690                 /* special exception for Pose-Channel Based F-Curves:
691                  *      - the 'Only Selected' data filter should be applied to Pose-Channel data too, but those are
692                  *        represented as F-Curves. The way the filter for objects worked was to be the first check
693                  *        after 'normal' visibility, so this is done first here too...
694                  *      - we currently use an 'approximate' method for getting these F-Curves that doesn't require
695                  *        carefully checking the entire path
696                  *      - this will also affect things like Drivers, and also works for Bone Constraints
697                  */
698                 if ( ((ads) && (ads->filterflag & ADS_FILTER_ONLYSEL)) && 
699                          ((owner_id) && (GS(owner_id->name) == ID_OB)) ) 
700                 {
701                         Object *ob= (Object *)owner_id;
702                         
703                         /* only consider if F-Curve involves pose_channels */
704                         if ((fcu->rna_path) && strstr(fcu->rna_path, "pose_channels")) {
705                                 bPoseChannel *pchan;
706                                 char *bone_name;
707                                 
708                                 /* get bone-name, and check if this bone is selected */
709                                 bone_name= BLI_getQuotedStr(fcu->rna_path, "pose_channels[");
710                                 pchan= get_pose_channel(ob->pose, bone_name);
711                                 if (bone_name) MEM_freeN(bone_name);
712                                 
713                                 /* can only add this F-Curve if it is selected */
714                                 if ((pchan) && (pchan->bone) && (pchan->bone->flag & BONE_SELECTED)==0)
715                                         continue;
716                         }
717                 }
718                 
719                 /* only include if visible (Graph Editor check, not channels check) */
720                 if (!(filter_mode & ANIMFILTER_CURVEVISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
721                         /* only work with this channel and its subchannels if it is editable */
722                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
723                                 /* only include this curve if selected in a way consistent with the filtering requirements */
724                                 if ( ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu)) ) {
725                                         /* only include if this curve is active */
726                                         if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
727                                                 ale= make_new_animlistelem(fcu, ANIMTYPE_FCURVE, owner, ownertype, owner_id);
728                                                 
729                                                 if (ale) {
730                                                         BLI_addtail(anim_data, ale);
731                                                         items++;
732                                                 }
733                                         }
734                                 }
735                         }
736                 }
737         }
738         
739         /* return the number of items added to the list */
740         return items;
741 }
742
743 static int animdata_filter_action (ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, void *owner, short ownertype, ID *owner_id)
744 {
745         bAnimListElem *ale=NULL;
746         bActionGroup *agrp;
747         FCurve *lastchan=NULL;
748         int items = 0;
749         
750         /* loop over groups */
751         // TODO: in future, should we expect to need nested groups?
752         for (agrp= act->groups.first; agrp; agrp= agrp->next) {
753                 ListBase tmp_channels = {NULL, NULL};
754                 short grp_channel=0;
755                 int tmp_items = 0;
756                 
757                 
758                 /* add this group as a channel first */
759                 if ((filter_mode & ANIMFILTER_CHANNELS) || !(filter_mode & ANIMFILTER_CURVESONLY)) {
760                         /* check if filtering by selection */
761                         if ( ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
762                                 ale= make_new_animlistelem(agrp, ANIMTYPE_GROUP, NULL, ANIMTYPE_NONE, owner_id);
763                                 if (ale) {
764                                         BLI_addtail(&tmp_channels, ale);
765                                         grp_channel=1;
766                                 }
767                         }
768                 }
769                 
770                 /* store reference to last channel of group */
771                 if (agrp->channels.last) 
772                         lastchan= agrp->channels.last;
773                 
774                 
775                 /* there are some situations, where only the channels of the action group should get considered */
776                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
777                         /* filters here are a bit convoulted...
778                          *      - groups show a "summary" of keyframes beside their name which must accessable for tools which handle keyframes
779                          *      - groups can be collapsed (and those tools which are only interested in channels rely on knowing that group is closed)
780                          *
781                          * cases when we should include F-Curves inside group:
782                          *      - we don't care about visibility
783                          *      - group is expanded
784                          *      - we just need the F-Curves present
785                          */
786                         if ( (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_AGRP(agrp)) || (filter_mode & ANIMFILTER_CURVESONLY) ) 
787                         {
788                                 /* for the Graph Editor, curves may be set to not be visible in the view to lessen clutter,
789                                  * but to do this, we need to check that the group doesn't have it's not-visible flag set preventing 
790                                  * all its sub-curves to be shown
791                                  */
792                                 if ( !(filter_mode & ANIMFILTER_CURVEVISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE) )
793                                 {
794                                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
795                                                 // XXX the 'owner' info here needs review...
796                                                 tmp_items += animdata_filter_fcurves(&tmp_channels, ads, agrp->channels.first, agrp, owner, ownertype, filter_mode, owner_id);
797                                         }
798                                 }
799                         }
800                 }
801                 
802                 /* check group had any F-Curves visible */
803                 // TODO: this needs more work to truly work so that closed group with no visible channels, and visible group with visible channels are differentiated between
804                 if (/*tmp_items*/1) {
805                         /* add the temp channels to the list of filtered channels */
806                         addlisttolist(anim_data, &tmp_channels);
807                         
808                         /* increase the counts as appropriate */
809                         items += tmp_items + grp_channel;
810                 }
811                 else {
812                         BLI_freelistN(&tmp_channels);
813                 }
814         }
815         
816         /* loop over un-grouped F-Curves (only if we're not only considering those channels in the animive group) */
817         if (!(filter_mode & ANIMFILTER_ACTGROUPED))  {
818                 // XXX the 'owner' info here needs review...
819                 items += animdata_filter_fcurves(anim_data, ads, (lastchan)?(lastchan->next):(act->curves.first), NULL, owner, ownertype, filter_mode, owner_id);
820         }
821         
822         /* return the number of items added to the list */
823         return items;
824 }
825
826 /* Include NLA-Data for NLA-Editor:
827  *      - when ANIMFILTER_CHANNELS is used, that means we should be filtering the list for display
828  *        Although the evaluation order is from the first track to the last and then apply the Action on top,
829  *        we present this in the UI as the Active Action followed by the last track to the first so that we 
830  *        get the evaluation order presented as per a stack.
831  *      - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
832  *        order, i.e. first to last. Otherwise, some tools may get screwed up.
833  */
834 static int animdata_filter_nla (ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, void *owner, short ownertype, ID *owner_id)
835 {
836         bAnimListElem *ale;
837         NlaTrack *nlt;
838         NlaTrack *first=NULL, *next=NULL;
839         int items = 0;
840         
841         /* if showing channels, include active action */
842         if (filter_mode & ANIMFILTER_CHANNELS) {
843                 /* there isn't really anything editable here, so skip if need editable */
844                 // TODO: currently, selection isn't checked since it doesn't matter
845                 if ((filter_mode & ANIMFILTER_FOREDIT) == 0) { 
846                         /* just add the action track now (this MUST appear for drawing)
847                          *      - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
848                          *        overwrite this with the real value - REVIEW THIS...
849                          */
850                         ale= make_new_animlistelem((void *)(&adt->action), ANIMTYPE_NLAACTION, owner, ownertype, owner_id);
851                         ale->data= (adt->action) ? adt->action : NULL;
852                                 
853                         if (ale) {
854                                 BLI_addtail(anim_data, ale);
855                                 items++;
856                         }
857                 }
858                 
859                 /* first track to include will be the last one if we're filtering by channels */
860                 first= adt->nla_tracks.last;
861         }
862         else {
863                 /* first track to include will the the first one (as per normal) */
864                 first= adt->nla_tracks.first;
865         }
866         
867         /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
868         for (nlt= first; nlt; nlt= next) {
869                 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
870                 if (filter_mode & ANIMFILTER_CHANNELS) 
871                         next= nlt->prev;
872                 else
873                         next= nlt->next;
874                 
875                 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now 
876                  *      - active track should still get shown though (even though it has disabled flag set)
877                  */
878                 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
879                 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && !(nlt->flag & NLATRACK_ACTIVE))
880                         continue;
881                 
882                 /* only work with this channel and its subchannels if it is editable */
883                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
884                         /* only include this track if selected in a way consistent with the filtering requirements */
885                         if ( ANIMCHANNEL_SELOK(SEL_NLT(nlt)) ) {
886                                 /* only include if this track is active */
887                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
888                                         ale= make_new_animlistelem(nlt, ANIMTYPE_NLATRACK, owner, ownertype, owner_id);
889                                                 
890                                         if (ale) {
891                                                 BLI_addtail(anim_data, ale);
892                                                 items++;
893                                         }
894                                 }
895                         }
896                 }
897         }
898         
899         /* return the number of items added to the list */
900         return items;
901 }
902  
903 #if 0
904 // FIXME: switch this to use the bDopeSheet...
905 static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter_mode)
906 {
907         bAnimListElem *ale;
908         ScrArea *sa, *curarea;
909         bGPdata *gpd;
910         bGPDlayer *gpl;
911         int items = 0;
912         
913         /* check if filtering types are appropriate */
914         {
915                 /* special hack for fullscreen area (which must be this one then):
916                  *      - we use the curarea->full as screen to get spaces from, since the
917                  *        old (pre-fullscreen) screen was stored there...
918                  *      - this is needed as all data would otherwise disappear
919                  */
920                 // XXX need to get new alternative for curarea
921                 if ((curarea->full) && (curarea->spacetype==SPACE_ACTION))
922                         sc= curarea->full;
923                 
924                 /* loop over spaces in current screen, finding gpd blocks (could be slow!) */
925                 for (sa= sc->areabase.first; sa; sa= sa->next) {
926                         /* try to get gp data */
927                         // XXX need to put back grease pencil api...
928                         gpd= gpencil_data_get_active(sa);
929                         if (gpd == NULL) continue;
930                         
931                         /* add gpd as channel too (if for drawing, and it has layers) */
932                         if ((filter_mode & ANIMFILTER_CHANNELS) && (gpd->layers.first)) {
933                                 /* add to list */
934                                 ale= make_new_animlistelem(gpd, ANIMTYPE_GPDATABLOCK, sa, ANIMTYPE_SPECIALDATA);
935                                 if (ale) {
936                                         BLI_addtail(anim_data, ale);
937                                         items++;
938                                 }
939                         }
940                         
941                         /* only add layers if they will be visible (if drawing channels) */
942                         if ( !(filter_mode & ANIMFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) {
943                                 /* loop over layers as the conditions are acceptable */
944                                 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
945                                         /* only if selected */
946                                         if ( ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
947                                                 /* only if editable */
948                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
949                                                         /* add to list */
950                                                         ale= make_new_animlistelem(gpl, ANIMTYPE_GPLAYER, gpd, ANIMTYPE_GPDATABLOCK);
951                                                         if (ale) {
952                                                                 BLI_addtail(anim_data, ale);
953                                                                 items++;
954                                                         }
955                                                 }
956                                         }
957                                 }
958                         }
959                 }
960         }
961         
962         /* return the number of items added to the list */
963         return items;
964 }
965 #endif 
966
967
968 static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
969 {
970         ListBase mats = {NULL, NULL};
971         LinkData *ld;
972         
973         bAnimListElem *ale=NULL;
974         Object *ob= base->object;
975         int items=0, a=0;
976         
977         /* firstly check that we actuallly have some materials, by gathering all materials in a temp list */
978         for (a=0; a < ob->totcol; a++) {
979                 Material *ma= give_current_material(ob, a);
980                 short ok = 0;
981                 
982                 /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
983                 if (ELEM(NULL, ma, ma->adt)) 
984                         continue;
985                 
986                 /* check if ok */
987                 ANIMDATA_FILTER_CASES(ma, 
988                         { /* AnimData blocks - do nothing... */ },
989                         ok=1;, 
990                         ok=1;, 
991                         ok=1;)
992                 if (ok == 0) continue;
993                 
994                 /* make a temp list elem for this */
995                 ld= MEM_callocN(sizeof(LinkData), "DopeSheet-MaterialCache");
996                 ld->data= ma;
997                 BLI_addtail(&mats, ld);
998         }
999         
1000         /* if there were no channels found, no need to carry on */
1001         if (mats.first == NULL)
1002                 return 0;
1003         
1004         /* include materials-expand widget? */
1005         if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1006                 ale= make_new_animlistelem(ob, ANIMTYPE_FILLMATD, base, ANIMTYPE_OBJECT, (ID *)ob);
1007                 if (ale) {
1008                         BLI_addtail(anim_data, ale);
1009                         items++;
1010                 }
1011         }
1012         
1013         /* add materials? */
1014         if (FILTER_MAT_OBJC(ob) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1015                 /* for each material in cache, add channels  */
1016                 for (ld= mats.first; ld; ld= ld->next) {
1017                         Material *ma= (Material *)ld->data;
1018                         
1019                         /* include material-expand widget? */
1020                         // hmm... do we need to store the index of this material in the array anywhere?
1021                         if (filter_mode & ANIMFILTER_CHANNELS) {
1022                                 /* check if filtering by active status */
1023                                 if ANIMCHANNEL_ACTIVEOK(ma) {
1024                                         ale= make_new_animlistelem(ma, ANIMTYPE_DSMAT, base, ANIMTYPE_OBJECT, (ID *)ma);
1025                                         if (ale) {
1026                                                 BLI_addtail(anim_data, ale);
1027                                                 items++;
1028                                         }
1029                                 }
1030                         }
1031                         
1032                         /* add material's animation data */
1033                         if (FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1034                                 ANIMDATA_FILTER_CASES(ma, 
1035                                         { /* AnimData blocks - do nothing... */ },
1036                                         items += animdata_filter_nla(anim_data, ads, ma->adt, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);, 
1037                                         items += animdata_filter_fcurves(anim_data, ads, ma->adt->drivers.first, NULL, ma, ANIMTYPE_DSMAT, filter_mode, (ID *)ma);, 
1038                                         items += animdata_filter_action(anim_data, ads, ma->adt->action, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);)
1039                         }
1040                 }
1041         }
1042         
1043         /* free cache */
1044         BLI_freelistN(&mats);
1045         
1046         /* return the number of items added to the list */
1047         return items;
1048 }
1049
1050 static int animdata_filter_dopesheet_particles (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1051 {
1052         bAnimListElem *ale=NULL;
1053         Object *ob= base->object;
1054         ParticleSystem *psys = ob->particlesystem.first;
1055         int items= 0, first = 1;
1056
1057         for(; psys; psys=psys->next) {
1058                 short ok = 0;
1059
1060                 if(ELEM(NULL, psys->part, psys->part->adt))
1061                         continue;
1062
1063                 ANIMDATA_FILTER_CASES(psys->part,
1064                         { /* AnimData blocks - do nothing... */ },
1065                         ok=1;, 
1066                         ok=1;, 
1067                         ok=1;)
1068                 if (ok == 0) continue;
1069
1070                 /* include particles-expand widget? */
1071                 if (first && (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1072                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLPARTD, base, ANIMTYPE_OBJECT, (ID *)ob);
1073                         if (ale) {
1074                                 BLI_addtail(anim_data, ale);
1075                                 items++;
1076                         }
1077                         first = 0;
1078                 }
1079                 
1080                 /* add particle settings? */
1081                 if (FILTER_PART_OBJC(ob) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1082                         if ((filter_mode & ANIMFILTER_CHANNELS)) {
1083                                 /* check if filtering by active status */
1084                                 if ANIMCHANNEL_ACTIVEOK(psys->part) {
1085                                         ale = make_new_animlistelem(psys->part, ANIMTYPE_DSPART, base, ANIMTYPE_OBJECT, (ID *)psys->part);
1086                                         if (ale) {
1087                                                 BLI_addtail(anim_data, ale);
1088                                                 items++;
1089                                         }
1090                                 }
1091                         }
1092                         
1093                         if (FILTER_PART_OBJD(psys->part) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1094                                 ANIMDATA_FILTER_CASES(psys->part,
1095                                         { /* AnimData blocks - do nothing... */ },
1096                                         items += animdata_filter_nla(anim_data, ads, psys->part->adt, filter_mode, psys->part, ANIMTYPE_DSPART, (ID *)psys->part);, 
1097                                         items += animdata_filter_fcurves(anim_data, ads, psys->part->adt->drivers.first, NULL, psys->part, ANIMTYPE_DSPART, filter_mode, (ID *)psys->part);, 
1098                                         items += animdata_filter_action(anim_data, ads, psys->part->adt->action, filter_mode, psys->part, ANIMTYPE_DSPART, (ID *)psys->part);)
1099                         }
1100                 }
1101         }
1102         
1103         /* return the number of items added to the list */
1104         return items;
1105 }
1106
1107 static int animdata_filter_dopesheet_obdata (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1108 {
1109         bAnimListElem *ale=NULL;
1110         Object *ob= base->object;
1111         IdAdtTemplate *iat= ob->data;
1112         AnimData *adt= iat->adt;
1113         short type=0, expanded=0;
1114         int items= 0;
1115         
1116         /* get settings based on data type */
1117         switch (ob->type) {
1118                 case OB_CAMERA: /* ------- Camera ------------ */
1119                 {
1120                         Camera *ca= (Camera *)ob->data;
1121                         
1122                         type= ANIMTYPE_DSCAM;
1123                         expanded= FILTER_CAM_OBJD(ca);
1124                 }
1125                         break;
1126                 case OB_LAMP: /* ---------- Lamp ----------- */
1127                 {
1128                         Lamp *la= (Lamp *)ob->data;
1129                         
1130                         type= ANIMTYPE_DSLAM;
1131                         expanded= FILTER_LAM_OBJD(la);
1132                 }
1133                         break;
1134                 case OB_CURVE: /* ------- Curve ---------- */
1135                 {
1136                         Curve *cu= (Curve *)ob->data;
1137                         
1138                         type= ANIMTYPE_DSCUR;
1139                         expanded= FILTER_CUR_OBJD(cu);
1140                 }
1141                         break;
1142                 case OB_MBALL: /* ------- MetaBall ---------- */
1143                 {
1144                         MetaBall *mb= (MetaBall *)ob->data;
1145                         
1146                         type= ANIMTYPE_DSMBALL;
1147                         expanded= FILTER_MBALL_OBJD(mb);
1148                 }
1149                         break;
1150                 case OB_ARMATURE: /* ------- Armature ---------- */
1151                 {
1152                         bArmature *arm= (bArmature *)ob->data;
1153                         
1154                         type= ANIMTYPE_DSARM;
1155                         expanded= FILTER_ARM_OBJD(arm);
1156                 }
1157                         break;
1158         }
1159         
1160         /* special exception for drivers instead of action */
1161         if (ads->filterflag & ADS_FILTER_ONLYDRIVERS)
1162                 expanded= EXPANDED_DRVD(adt);
1163         
1164         /* include data-expand widget? */
1165         if ((filter_mode & ANIMFILTER_CURVESONLY) == 0) {       
1166                 /* check if filtering by active status */
1167                 if ANIMCHANNEL_ACTIVEOK(iat) {
1168                         ale= make_new_animlistelem(iat, type, base, ANIMTYPE_OBJECT, (ID *)iat);
1169                         if (ale) BLI_addtail(anim_data, ale);
1170                 }
1171         }
1172         
1173         /* add object-data animation channels? */
1174         if ((expanded) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1175                 /* filtering for channels - nla, drivers, keyframes */
1176                 ANIMDATA_FILTER_CASES(iat, 
1177                         { /* AnimData blocks - do nothing... */ },
1178                         items+= animdata_filter_nla(anim_data, ads, iat->adt, filter_mode, iat, type, (ID *)iat);,
1179                         items+= animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, iat, type, filter_mode, (ID *)iat);, 
1180                         items += animdata_filter_action(anim_data, ads, iat->adt->action, filter_mode, iat, type, (ID *)iat);)
1181         }
1182         
1183         /* return the number of items added to the list */
1184         return items;
1185 }
1186
1187 static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1188 {
1189         bAnimListElem *ale=NULL;
1190         AnimData *adt = NULL;
1191         Object *ob= base->object;
1192         Key *key= ob_get_key(ob);
1193         short obdata_ok = 0;
1194         int items = 0;
1195         
1196         /* add this object as a channel first */
1197         if ((filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) == 0) {
1198                 /* check if filtering by selection */
1199                 if ANIMCHANNEL_SELOK((base->flag & SELECT)) {
1200                         /* check if filtering by active status */
1201                         if ANIMCHANNEL_ACTIVEOK(ob) {
1202                                 ale= make_new_animlistelem(base, ANIMTYPE_OBJECT, NULL, ANIMTYPE_NONE, (ID *)ob);
1203                                 if (ale) {
1204                                         BLI_addtail(anim_data, ale);
1205                                         items++;
1206                                 }
1207                         }
1208                 }
1209         }
1210         
1211         /* if collapsed, don't go any further (unless adding keyframes only) */
1212         if ( (EXPANDED_OBJC(ob) == 0) && !(filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) )
1213                 return items;
1214         
1215         /* Action, Drivers, or NLA */
1216         if (ob->adt) {
1217                 adt= ob->adt;
1218                 ANIMDATA_FILTER_CASES(ob,
1219                         { /* AnimData blocks - do nothing... */ },
1220                         { /* nla */
1221                                 /* add NLA tracks */
1222                                 items += animdata_filter_nla(anim_data, ads, adt, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
1223                         },
1224                         { /* drivers */
1225                                 /* include drivers-expand widget? */
1226                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1227                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, base, ANIMTYPE_OBJECT, (ID *)ob);
1228                                         if (ale) {
1229                                                 BLI_addtail(anim_data, ale);
1230                                                 items++;
1231                                         }
1232                                 }
1233                                 
1234                                 /* add F-Curve channels (drivers are F-Curves) */
1235                                 if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1236                                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1237                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)ob);
1238                                 }
1239                         },
1240                         { /* action (keyframes) */
1241                                 /* include action-expand widget? */
1242                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1243                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT, (ID *)ob);
1244                                         if (ale) {
1245                                                 BLI_addtail(anim_data, ale);
1246                                                 items++;
1247                                         }
1248                                 }
1249                                 
1250                                 /* add F-Curve channels? */
1251                                 if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1252                                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1253                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob); 
1254                                 }
1255                         }
1256                 );
1257         }
1258         
1259         
1260         /* ShapeKeys? */
1261         if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
1262                 adt= key->adt;
1263                 ANIMDATA_FILTER_CASES(key,
1264                         { /* AnimData blocks - do nothing... */ },
1265                         { /* nla */
1266                                 /* include shapekey-expand widget? */
1267                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1268                                         /* check if filtering by active status */
1269                                         if ANIMCHANNEL_ACTIVEOK(key) {
1270                                                 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1271                                                 if (ale) {
1272                                                         BLI_addtail(anim_data, ale);
1273                                                         items++;
1274                                                 }
1275                                         }
1276                                 }
1277                                 
1278                                 /* add NLA tracks - only if expanded or so */
1279                                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY))
1280                                         items += animdata_filter_nla(anim_data, ads, adt, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
1281                         },
1282                         { /* drivers */
1283                                 /* include shapekey-expand widget? */
1284                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1285                                         ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1286                                         if (ale) {
1287                                                 BLI_addtail(anim_data, ale);
1288                                                 items++;
1289                                         }
1290                                 }
1291                                 
1292                                 /* add channels */
1293                                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1294                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, key, ANIMTYPE_DSSKEY, filter_mode, (ID *)key);
1295                                 }
1296                         },
1297                         { /* action (keyframes) */
1298                                 /* include shapekey-expand widget? */
1299                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1300                                         /* check if filtering by active status */
1301                                         if ANIMCHANNEL_ACTIVEOK(key) {
1302                                                 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1303                                                 if (ale) {
1304                                                         BLI_addtail(anim_data, ale);
1305                                                         items++;
1306                                                 }
1307                                         }
1308                                 }
1309                                 
1310                                 /* add channels */
1311                                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1312                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, key, ANIMTYPE_DSSKEY, (ID *)key); 
1313                                 }
1314                         }
1315                 );
1316         }
1317
1318         /* Materials? */
1319         if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
1320                 items += animdata_filter_dopesheet_mats(anim_data, ads, base, filter_mode);
1321         
1322         /* Object Data */
1323         switch (ob->type) {
1324                 case OB_CAMERA: /* ------- Camera ------------ */
1325                 {
1326                         Camera *ca= (Camera *)ob->data;
1327                         
1328                         if ((ads->filterflag & ADS_FILTER_NOCAM) == 0) {
1329                                 ANIMDATA_FILTER_CASES(ca,
1330                                         { /* AnimData blocks - do nothing... */ },
1331                                         obdata_ok= 1;,
1332                                         obdata_ok= 1;,
1333                                         obdata_ok= 1;)
1334                         }
1335                 }
1336                         break;
1337                 case OB_LAMP: /* ---------- Lamp ----------- */
1338                 {
1339                         Lamp *la= (Lamp *)ob->data;
1340                         
1341                         if ((ads->filterflag & ADS_FILTER_NOLAM) == 0) {
1342                                 ANIMDATA_FILTER_CASES(la,
1343                                         { /* AnimData blocks - do nothing... */ },
1344                                         obdata_ok= 1;,
1345                                         obdata_ok= 1;,
1346                                         obdata_ok= 1;)
1347                         }
1348                 }
1349                         break;
1350                 case OB_CURVE: /* ------- Curve ---------- */
1351                 {
1352                         Curve *cu= (Curve *)ob->data;
1353                         
1354                         if ((ads->filterflag & ADS_FILTER_NOCUR) == 0) {
1355                                 ANIMDATA_FILTER_CASES(cu,
1356                                         { /* AnimData blocks - do nothing... */ },
1357                                         obdata_ok= 1;,
1358                                         obdata_ok= 1;,
1359                                         obdata_ok= 1;)
1360                         }
1361                 }
1362                         break;
1363                 case OB_MBALL: /* ------- MetaBall ---------- */
1364                 {
1365                         MetaBall *mb= (MetaBall *)ob->data;
1366                         
1367                         if ((ads->filterflag & ADS_FILTER_NOMBA) == 0) {
1368                                 ANIMDATA_FILTER_CASES(mb,
1369                                         { /* AnimData blocks - do nothing... */ },
1370                                         obdata_ok= 1;,
1371                                         obdata_ok= 1;,
1372                                         obdata_ok= 1;)
1373                         }
1374                 }
1375                         break;
1376                 case OB_ARMATURE: /* ------- Armature ---------- */
1377                 {
1378                         bArmature *arm= (bArmature *)ob->data;
1379                         
1380                         if ((ads->filterflag & ADS_FILTER_NOARM) == 0) {
1381                                 ANIMDATA_FILTER_CASES(arm,
1382                                         { /* AnimData blocks - do nothing... */ },
1383                                         obdata_ok= 1;,
1384                                         obdata_ok= 1;,
1385                                         obdata_ok= 1;)
1386                         }
1387                 }
1388                         break;
1389         }
1390         if (obdata_ok) 
1391                 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
1392
1393         /* particles */
1394         if (ob->particlesystem.first && !(ads->filterflag & ADS_FILTER_NOPART))
1395                 items += animdata_filter_dopesheet_particles(anim_data, ads, base, filter_mode);
1396         
1397         /* return the number of items added to the list */
1398         return items;
1399 }       
1400
1401 static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1402 {
1403         World *wo= sce->world;
1404         AnimData *adt= NULL;
1405         bAnimListElem *ale;
1406         int items = 0;
1407         
1408         /* add scene as a channel first (even if we aren't showing scenes we still need to show the scene's sub-data */
1409         if ((filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) == 0) {
1410                 /* check if filtering by selection */
1411                 if (ANIMCHANNEL_SELOK( (sce->flag & SCE_DS_SELECTED) )) {
1412                         ale= make_new_animlistelem(sce, ANIMTYPE_SCENE, NULL, ANIMTYPE_NONE, NULL);
1413                         if (ale) {
1414                                 BLI_addtail(anim_data, ale);
1415                                 items++;
1416                         }
1417                 }
1418         }
1419         
1420         /* if collapsed, don't go any further (unless adding keyframes only) */
1421         if ( (EXPANDED_SCEC(sce) == 0) && !(filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) )
1422                 return items;
1423                 
1424         /* Action, Drivers, or NLA for Scene */
1425         if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
1426                 adt= sce->adt;
1427                 ANIMDATA_FILTER_CASES(sce,
1428                         { /* AnimData blocks - do nothing... */ },
1429                         { /* nla */
1430                                 /* add NLA tracks */
1431                                 items += animdata_filter_nla(anim_data, ads, adt, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce);
1432                         },
1433                         { /* drivers */
1434                                 /* include drivers-expand widget? */
1435                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1436                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, sce, ANIMTYPE_SCENE, (ID *)sce);
1437                                         if (ale) {
1438                                                 BLI_addtail(anim_data, ale);
1439                                                 items++;
1440                                         }
1441                                 }
1442                                 
1443                                 /* add F-Curve channels (drivers are F-Curves) */
1444                                 if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1445                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, sce, ANIMTYPE_SCENE, filter_mode, (ID *)sce);
1446                                 }
1447                         },
1448                         { /* action */
1449                                 /* include action-expand widget? */
1450                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1451                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, sce, ANIMTYPE_SCENE, (ID *)sce);
1452                                         if (ale) {
1453                                                 BLI_addtail(anim_data, ale);
1454                                                 items++;
1455                                         }
1456                                 }
1457                                 
1458                                 /* add F-Curve channels? */
1459                                 if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1460                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce); 
1461                                 }
1462                         }
1463                 )
1464         }
1465         
1466         /* world */
1467         if ((wo && wo->adt) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
1468                 /* Action, Drivers, or NLA for World */
1469                 adt= wo->adt;
1470                 ANIMDATA_FILTER_CASES(wo,
1471                         { /* AnimData blocks - do nothing... */ },
1472                         { /* nla */
1473                                 /* add NLA tracks */
1474                                 items += animdata_filter_nla(anim_data, ads, adt, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo);
1475                         },
1476                         { /* drivers */
1477                                 /* include world-expand widget? */
1478                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1479                                         ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)wo);
1480                                         if (ale) {
1481                                                 BLI_addtail(anim_data, ale);
1482                                                 items++;
1483                                         }
1484                                 }
1485                                 
1486                                 /* add F-Curve channels (drivers are F-Curves) */
1487                                 if (FILTER_WOR_SCED(wo)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
1488                                         // XXX owner info is messed up now...
1489                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, wo, ANIMTYPE_DSWOR, filter_mode, (ID *)wo);
1490                                 }
1491                         },
1492                         { /* action */
1493                                 /* include world-expand widget? */
1494                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1495                                         ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)sce);
1496                                         if (ale) {
1497                                                 BLI_addtail(anim_data, ale);
1498                                                 items++;
1499                                         }
1500                                 }
1501                                 
1502                                 /* add channels */
1503                                 if (FILTER_WOR_SCED(wo) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1504                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo); 
1505                                 }
1506                         }
1507                 )
1508         }
1509         
1510         // TODO: scene compositing nodes (these aren't standard node-trees)
1511         
1512         /* return the number of items added to the list */
1513         return items;
1514 }
1515
1516 // 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)
1517 static int animdata_filter_dopesheet (ListBase *anim_data, bDopeSheet *ads, int filter_mode)
1518 {
1519         Scene *sce= (Scene *)ads->source;
1520         Base *base;
1521         bAnimListElem *ale;
1522         int items = 0;
1523         
1524         /* check that we do indeed have a scene */
1525         if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
1526                 printf("DopeSheet Error: Not scene! \n");
1527                 return 0;
1528         }
1529         
1530         /* scene-linked animation */
1531         // TODO: sequencer, composite nodes - are we to include those here too?
1532         {
1533                 short sceOk= 0, worOk= 0;
1534                 
1535                 /* check filtering-flags if ok */
1536                 ANIMDATA_FILTER_CASES(sce, 
1537                         {
1538                                 /* for the special AnimData blocks only case, we only need to add
1539                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1540                                  */
1541                                 ANIMDATA_ADD_ANIMDATA(sce);
1542                                 sceOk=0;
1543                         },
1544                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);, 
1545                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);, 
1546                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);)
1547                 if (sce->world) {
1548                         ANIMDATA_FILTER_CASES(sce->world, 
1549                                 {
1550                                         /* for the special AnimData blocks only case, we only need to add
1551                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1552                                          */
1553                                         ANIMDATA_ADD_ANIMDATA(sce->world);
1554                                         worOk=0;
1555                                 },
1556                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);, 
1557                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);, 
1558                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);)
1559                 }
1560                 
1561                 /* if only F-Curves with visible flags set can be shown, check that 
1562                  * datablocks haven't been set to invisible 
1563                  */
1564                 if (filter_mode & ANIMFILTER_CURVEVISIBLE) {
1565                         if ((sce->adt) && (sce->adt->flag & ADT_CURVES_NOT_VISIBLE))
1566                                 sceOk= worOk= 0;
1567                 }
1568                 
1569                 /* check if not all bad (i.e. so there is something to show) */
1570                 if ( !(!sceOk && !worOk) ) {
1571                         /* add scene data to the list of filtered channels */
1572                         items += animdata_filter_dopesheet_scene(anim_data, ads, sce, filter_mode);
1573                 }
1574         }
1575         
1576         
1577         /* loop over all bases in the scene */
1578         for (base= sce->base.first; base; base= base->next) {
1579                 /* check if there's an object (all the relevant checks are done in the ob-function) */
1580                 if (base->object) {
1581                         Object *ob= base->object;
1582                         Key *key= ob_get_key(ob);
1583                         short actOk=1, keyOk=1, dataOk=1, matOk=1, partOk=1;
1584                         
1585                         /* firstly, check if object can be included, by the following factors:
1586                          *      - if only visible, must check for layer and also viewport visibility
1587                          *      - if only selected, must check if object is selected 
1588                          *      - there must be animation data to edit
1589                          */
1590                         // TODO: if cache is implemented, just check name here, and then 
1591                         if (filter_mode & ANIMFILTER_VISIBLE) {
1592                                 /* layer visibility - we check both object and base, since these may not be in sync yet */
1593                                 if ((sce->lay & (ob->lay|base->lay))==0) continue;
1594                                 
1595                                 /* outliner restrict-flag */
1596                                 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1597                         }
1598                         
1599                         /* if only F-Curves with visible flags set can be shown, check that 
1600                          * datablock hasn't been set to invisible 
1601                          */
1602                         if (filter_mode & ANIMFILTER_CURVEVISIBLE) {
1603                                 if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE))
1604                                         continue;
1605                         }
1606                         
1607                         /* additionally, dopesheet filtering also affects what objects to consider */
1608                         if (ads->filterflag) {
1609                                 /* check selection and object type filters */
1610                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) || (base == sce->basact)) )  {
1611                                         /* only selected should be shown */
1612                                         continue;
1613                                 }
1614                                 
1615                                 /* check filters for datatypes */
1616                                         /* object */
1617                                 actOk= 0;
1618                                 keyOk= 0;
1619                                 ANIMDATA_FILTER_CASES(ob, 
1620                                         {
1621                                                 /* for the special AnimData blocks only case, we only need to add
1622                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1623                                                  */
1624                                                 ANIMDATA_ADD_ANIMDATA(ob);
1625                                                 actOk=0;
1626                                         },
1627                                         actOk= 1;, 
1628                                         actOk= 1;, 
1629                                         actOk= 1;)
1630                                 if (key) {
1631                                         /* shapekeys */
1632                                         ANIMDATA_FILTER_CASES(key, 
1633                                                 {
1634                                                         /* for the special AnimData blocks only case, we only need to add
1635                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1636                                                          */
1637                                                         ANIMDATA_ADD_ANIMDATA(key);
1638                                                         keyOk=0;
1639                                                 },
1640                                                 keyOk= 1;, 
1641                                                 keyOk= 1;, 
1642                                                 keyOk= 1;)
1643                                 }
1644                                 
1645                                 /* materials - only for geometric types */
1646                                 matOk= 0; /* by default, not ok... */
1647                                 if ( !(ads->filterflag & ADS_FILTER_NOMAT) && (ob->totcol) && 
1648                                          ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) ) 
1649                                 {
1650                                         int a;
1651                                         
1652                                         /* firstly check that we actuallly have some materials */
1653                                         for (a=0; a < ob->totcol; a++) {
1654                                                 Material *ma= give_current_material(ob, a);
1655                                                 
1656                                                 if (ma) {
1657                                                         /* if material has relevant animation data, break */
1658                                                         ANIMDATA_FILTER_CASES(ma, 
1659                                                                 {
1660                                                                         /* for the special AnimData blocks only case, we only need to add
1661                                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1662                                                                          */
1663                                                                         ANIMDATA_ADD_ANIMDATA(ma);
1664                                                                         matOk=0;
1665                                                                 },
1666                                                                 matOk= 1;, 
1667                                                                 matOk= 1;, 
1668                                                                 matOk= 1;)
1669                                                 }
1670                                                         
1671                                                 if (matOk) 
1672                                                         break;
1673                                         }
1674                                 }
1675                                 
1676                                 /* data */
1677                                 switch (ob->type) {
1678                                         case OB_CAMERA: /* ------- Camera ------------ */
1679                                         {
1680                                                 Camera *ca= (Camera *)ob->data;
1681                                                 dataOk= 0;
1682                                                 ANIMDATA_FILTER_CASES(ca, 
1683                                                         if ((ads->filterflag & ADS_FILTER_NOCAM)==0) {
1684                                                                 /* for the special AnimData blocks only case, we only need to add
1685                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1686                                                                  */
1687                                                                 ANIMDATA_ADD_ANIMDATA(ca);
1688                                                                 dataOk=0;
1689                                                         },
1690                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);, 
1691                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);, 
1692                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);)
1693                                         }
1694                                                 break;
1695                                         case OB_LAMP: /* ---------- Lamp ----------- */
1696                                         {
1697                                                 Lamp *la= (Lamp *)ob->data;
1698                                                 dataOk= 0;
1699                                                 ANIMDATA_FILTER_CASES(la, 
1700                                                         if ((ads->filterflag & ADS_FILTER_NOLAM)==0) {
1701                                                                 /* for the special AnimData blocks only case, we only need to add
1702                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1703                                                                  */
1704                                                                 ANIMDATA_ADD_ANIMDATA(la);
1705                                                                 dataOk=0;
1706                                                         },
1707                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);, 
1708                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);, 
1709                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);)
1710                                         }
1711                                                 break;
1712                                         case OB_CURVE: /* ------- Curve ---------- */
1713                                         {
1714                                                 Curve *cu= (Curve *)ob->data;
1715                                                 dataOk= 0;
1716                                                 ANIMDATA_FILTER_CASES(cu, 
1717                                                         if ((ads->filterflag & ADS_FILTER_NOCUR)==0) {
1718                                                                 /* for the special AnimData blocks only case, we only need to add
1719                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1720                                                                  */
1721                                                                 ANIMDATA_ADD_ANIMDATA(cu);
1722                                                                 dataOk=0;
1723                                                         },
1724                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);, 
1725                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);, 
1726                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);)
1727                                         }
1728                                                 break;
1729                                         case OB_MBALL: /* ------- MetaBall ---------- */
1730                                         {
1731                                                 MetaBall *mb= (MetaBall *)ob->data;
1732                                                 dataOk= 0;
1733                                                 ANIMDATA_FILTER_CASES(mb, 
1734                                                         if ((ads->filterflag & ADS_FILTER_NOMBA)==0) {
1735                                                                 /* for the special AnimData blocks only case, we only need to add
1736                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1737                                                                  */
1738                                                                 ANIMDATA_ADD_ANIMDATA(mb);
1739                                                                 dataOk=0;
1740                                                         },
1741                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);, 
1742                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);, 
1743                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);)
1744                                         }
1745                                                 break;
1746                                         case OB_ARMATURE: /* ------- Armature ---------- */
1747                                         {
1748                                                 bArmature *arm= (bArmature *)ob->data;
1749                                                 dataOk= 0;
1750                                                 ANIMDATA_FILTER_CASES(arm, 
1751                                                         if ((ads->filterflag & ADS_FILTER_NOARM)==0) {
1752                                                                 /* for the special AnimData blocks only case, we only need to add
1753                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1754                                                                  */
1755                                                                 ANIMDATA_ADD_ANIMDATA(arm);
1756                                                                 dataOk=0;
1757                                                         },
1758                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
1759                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
1760                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);)
1761                                         }
1762                                                 break;
1763                                         default: /* --- other --- */
1764                                                 dataOk= 0;
1765                                                 break;
1766                                 }
1767                                 
1768                                 /* particles */
1769                                 partOk = 0;
1770                                 if (!(ads->filterflag & ADS_FILTER_NOPART) && ob->particlesystem.first) {
1771                                         ParticleSystem *psys = ob->particlesystem.first;
1772                                         for(; psys; psys=psys->next) {
1773                                                 if (psys->part) {
1774                                                         /* if particlesettings has relevant animation data, break */
1775                                                         ANIMDATA_FILTER_CASES(psys->part, 
1776                                                                 {
1777                                                                         /* for the special AnimData blocks only case, we only need to add
1778                                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1779                                                                          */
1780                                                                         ANIMDATA_ADD_ANIMDATA(psys->part);
1781                                                                         partOk=0;
1782                                                                 },
1783                                                                 partOk= 1;, 
1784                                                                 partOk= 1;, 
1785                                                                 partOk= 1;)
1786                                                 }
1787                                                         
1788                                                 if (partOk) 
1789                                                         break;
1790                                         }
1791                                 }
1792                                 
1793                                 /* check if all bad (i.e. nothing to show) */
1794                                 if (!actOk && !keyOk && !dataOk && !matOk && !partOk)
1795                                         continue;
1796                         }
1797                         else {
1798                                 /* check data-types */
1799                                 actOk= ANIMDATA_HAS_KEYS(ob);
1800                                 keyOk= (key != NULL);
1801                                 
1802                                 /* materials - only for geometric types */
1803                                 matOk= 0; /* by default, not ok... */
1804                                 if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) && (ob->totcol)) 
1805                                 {
1806                                         int a;
1807                                         
1808                                         /* firstly check that we actuallly have some materials */
1809                                         for (a=0; a < ob->totcol; a++) {
1810                                                 Material *ma= give_current_material(ob, a);
1811                                                 
1812                                                 if ((ma) && ANIMDATA_HAS_KEYS(ma)) {
1813                                                         matOk= 1;
1814                                                         break;
1815                                                 }
1816                                         }
1817                                 }
1818                                 
1819                                 /* data */
1820                                 switch (ob->type) {
1821                                         case OB_CAMERA: /* ------- Camera ------------ */
1822                                         {
1823                                                 Camera *ca= (Camera *)ob->data;
1824                                                 dataOk= ANIMDATA_HAS_KEYS(ca);                                          
1825                                         }
1826                                                 break;
1827                                         case OB_LAMP: /* ---------- Lamp ----------- */
1828                                         {
1829                                                 Lamp *la= (Lamp *)ob->data;
1830                                                 dataOk= ANIMDATA_HAS_KEYS(la);  
1831                                         }
1832                                                 break;
1833                                         case OB_CURVE: /* -------- Curve ---------- */
1834                                         {
1835                                                 Curve *cu= (Curve *)ob->data;
1836                                                 dataOk= ANIMDATA_HAS_KEYS(cu);  
1837                                         }
1838                                                 break;
1839                                         case OB_MBALL: /* -------- Metas ---------- */
1840                                         {
1841                                                 MetaBall *mb= (MetaBall *)ob->data;
1842                                                 dataOk= ANIMDATA_HAS_KEYS(mb);  
1843                                         }
1844                                                 break;
1845                                         case OB_ARMATURE: /* -------- Armature ---------- */
1846                                         {
1847                                                 bArmature *arm= (bArmature *)ob->data;
1848                                                 dataOk= ANIMDATA_HAS_KEYS(arm); 
1849                                         }
1850                                                 break;
1851                                         default: /* --- other --- */
1852                                                 dataOk= 0;
1853                                                 break;
1854                                 }
1855                                 
1856                                 /* particles */
1857                                 partOk = 0;
1858                                 if (ob->particlesystem.first) {
1859                                         ParticleSystem *psys = ob->particlesystem.first;
1860                                         for(; psys; psys=psys->next) {
1861                                                 if(psys->part && ANIMDATA_HAS_KEYS(psys->part)) {
1862                                                         partOk = 1;
1863                                                         break;
1864                                                 }
1865                                         }
1866                                 }
1867                                 
1868                                 /* check if all bad (i.e. nothing to show) */
1869                                 if (!actOk && !keyOk && !dataOk && !matOk && !partOk)
1870                                         continue;
1871                         }
1872                         
1873                         /* since we're still here, this object should be usable */
1874                         items += animdata_filter_dopesheet_ob(anim_data, ads, base, filter_mode);
1875                 }
1876         }
1877         
1878         /* return the number of items in the list */
1879         return items;
1880 }
1881
1882 /* ----------- Public API --------------- */
1883
1884 /* This function filters the active data source to leave only animation channels suitable for
1885  * usage by the caller. It will return the length of the list 
1886  * 
1887  *      *anim_data: is a pointer to a ListBase, to which the filtered animation channels
1888  *              will be placed for use.
1889  *      filter_mode: how should the data be filtered - bitmapping accessed flags
1890  */
1891 int ANIM_animdata_filter (bAnimContext *ac, ListBase *anim_data, int filter_mode, void *data, short datatype)
1892 {
1893         int items = 0;
1894         
1895         /* only filter data if there's somewhere to put it */
1896         if (data && anim_data) {
1897                 bAnimListElem *ale, *next;
1898                 Object *obact= (ac) ? ac->obact : NULL;
1899                 
1900                 /* firstly filter the data */
1901                 switch (datatype) {
1902                         case ANIMCONT_ACTION:
1903                                 items= animdata_filter_action(anim_data, NULL, data, filter_mode, NULL, ANIMTYPE_NONE, (ID *)obact);
1904                                 break;
1905                                 
1906                         case ANIMCONT_SHAPEKEY:
1907                                 //items= animdata_filter_shapekey(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE, (ID *)obact);
1908                                 break;
1909                                 
1910                         case ANIMCONT_GPENCIL:
1911                                 //items= animdata_filter_gpencil(anim_data, data, filter_mode);
1912                                 break;
1913                                 
1914                         case ANIMCONT_DOPESHEET:
1915                         case ANIMCONT_FCURVES:
1916                         case ANIMCONT_DRIVERS:
1917                         case ANIMCONT_NLA:
1918                                 items= animdata_filter_dopesheet(anim_data, data, filter_mode);
1919                                 break;
1920                 }
1921                         
1922                 /* remove any weedy entries */
1923                 // XXX this is weedy code!
1924                 for (ale= anim_data->first; ale; ale= next) {
1925                         next= ale->next;
1926                         
1927                         if (ale->type == ANIMTYPE_NONE) {
1928                                 items--;
1929                                 BLI_freelinkN(anim_data, ale);
1930                         }
1931                 }
1932         }
1933         
1934         /* return the number of items in the list */
1935         return items;
1936 }
1937
1938 /* ************************************************************ */