ea097420d1ac78101e518ab5875513d2e27d5d6b
[blender-staging.git] / source / blender / editors / animation / anim_filter.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 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_SUMMARY:
462                         {
463                                 /* nothing to include for now... this is just a dummy wrappy around all the other channels 
464                                  * in the DopeSheet, and gets included at the start of the list
465                                  */
466                                 ale->key_data= NULL;
467                                 ale->datatype= ALE_ALL;
468                         }
469                                 break;
470                         
471                         case ANIMTYPE_SCENE:
472                         {
473                                 Scene *sce= (Scene *)data;
474                                 
475                                 ale->flag= sce->flag;
476                                 
477                                 ale->key_data= sce;
478                                 ale->datatype= ALE_SCE;
479                                 
480                                 ale->adt= BKE_animdata_from_id(data);
481                         }
482                                 break;
483                         case ANIMTYPE_OBJECT:
484                         {
485                                 Base *base= (Base *)data;
486                                 Object *ob= base->object;
487                                 
488                                 ale->flag= ob->flag;
489                                 
490                                 ale->key_data= ob;
491                                 ale->datatype= ALE_OB;
492                                 
493                                 ale->adt= BKE_animdata_from_id(&ob->id);
494                         }
495                                 break;
496                         case ANIMTYPE_FILLACTD:
497                         {
498                                 bAction *act= (bAction *)data;
499                                 
500                                 ale->flag= act->flag;
501                                 
502                                 ale->key_data= act;
503                                 ale->datatype= ALE_ACT;
504                         }
505                                 break;
506                         case ANIMTYPE_FILLDRIVERS:
507                         {
508                                 AnimData *adt= (AnimData *)data;
509                                 
510                                 ale->flag= adt->flag;
511                                 
512                                         // XXX... drivers don't show summary for now
513                                 ale->key_data= NULL;
514                                 ale->datatype= ALE_NONE;
515                         }
516                                 break;
517                         case ANIMTYPE_FILLMATD:
518                         {
519                                 Object *ob= (Object *)data;
520                                 
521                                 ale->flag= FILTER_MAT_OBJC(ob);
522                                 
523                                 ale->key_data= NULL;
524                                 ale->datatype= ALE_NONE;
525                         }
526                                 break;
527                         case ANIMTYPE_FILLPARTD:
528                         {
529                                 Object *ob= (Object *)data;
530                                 
531                                 ale->flag= FILTER_PART_OBJC(ob);
532                                 
533                                 ale->key_data= NULL;
534                                 ale->datatype= ALE_NONE;
535                         }
536                                 break;
537                         
538                         case ANIMTYPE_DSMAT:
539                         {
540                                 Material *ma= (Material *)data;
541                                 AnimData *adt= ma->adt;
542                                 
543                                 ale->flag= FILTER_MAT_OBJD(ma);
544                                 
545                                 ale->key_data= (adt) ? adt->action : NULL;
546                                 ale->datatype= ALE_ACT;
547                                 
548                                 ale->adt= BKE_animdata_from_id(data);
549                         }
550                                 break;
551                         case ANIMTYPE_DSLAM:
552                         {
553                                 Lamp *la= (Lamp *)data;
554                                 AnimData *adt= la->adt;
555                                 
556                                 ale->flag= FILTER_LAM_OBJD(la);
557                                 
558                                 ale->key_data= (adt) ? adt->action : NULL;
559                                 ale->datatype= ALE_ACT;
560                                 
561                                 ale->adt= BKE_animdata_from_id(data);
562                         }
563                                 break;
564                         case ANIMTYPE_DSCAM:
565                         {
566                                 Camera *ca= (Camera *)data;
567                                 AnimData *adt= ca->adt;
568                                 
569                                 ale->flag= FILTER_CAM_OBJD(ca);
570                                 
571                                 ale->key_data= (adt) ? adt->action : NULL;
572                                 ale->datatype= ALE_ACT;
573                                 
574                                 ale->adt= BKE_animdata_from_id(data);
575                         }
576                                 break;
577                         case ANIMTYPE_DSCUR:
578                         {
579                                 Curve *cu= (Curve *)data;
580                                 AnimData *adt= cu->adt;
581                                 
582                                 ale->flag= FILTER_CUR_OBJD(cu);
583                                 
584                                 ale->key_data= (adt) ? adt->action : NULL;
585                                 ale->datatype= ALE_ACT;
586                                 
587                                 ale->adt= BKE_animdata_from_id(data);
588                         }
589                                 break;
590                         case ANIMTYPE_DSSKEY:
591                         {
592                                 Key *key= (Key *)data;
593                                 AnimData *adt= key->adt;
594                                 
595                                 ale->flag= FILTER_SKE_OBJD(key); 
596                                 
597                                 ale->key_data= (adt) ? adt->action : NULL;
598                                 ale->datatype= ALE_ACT;
599                                 
600                                 ale->adt= BKE_animdata_from_id(data);
601                         }
602                                 break;
603                         case ANIMTYPE_DSWOR:
604                         {
605                                 World *wo= (World *)data;
606                                 AnimData *adt= wo->adt;
607                                 
608                                 ale->flag= FILTER_WOR_SCED(wo); 
609                                 
610                                 ale->key_data= (adt) ? adt->action : NULL;
611                                 ale->datatype= ALE_ACT;
612                                 
613                                 ale->adt= BKE_animdata_from_id(data);
614                         }
615                                 break;
616                         case ANIMTYPE_DSPART:
617                         {
618                                 ParticleSettings *part= (ParticleSettings*)ale->data;
619                                 AnimData *adt= part->adt;
620                                 
621                                 ale->flag= FILTER_PART_OBJD(part); 
622                                 
623                                 ale->key_data= (adt) ? adt->action : NULL;
624                                 ale->datatype= ALE_ACT;
625                                 
626                                 ale->adt= BKE_animdata_from_id(data);
627                         }
628                                 break;
629                                 
630                         case ANIMTYPE_GROUP:
631                         {
632                                 bActionGroup *agrp= (bActionGroup *)data;
633                                 
634                                 ale->flag= agrp->flag;
635                                 
636                                 ale->key_data= NULL;
637                                 ale->datatype= ALE_GROUP;
638                         }
639                                 break;
640                         case ANIMTYPE_FCURVE:
641                         {
642                                 FCurve *fcu= (FCurve *)data;
643                                 
644                                 ale->flag= fcu->flag;
645                                 
646                                 ale->key_data= fcu;
647                                 ale->datatype= ALE_FCURVE;
648                         }
649                                 break;
650                         
651                         case ANIMTYPE_GPLAYER:
652                         {
653                                 bGPDlayer *gpl= (bGPDlayer *)data;
654                                 
655                                 ale->flag= gpl->flag;
656                                 
657                                 ale->key_data= NULL;
658                                 ale->datatype= ALE_GPFRAME;
659                         }
660                                 break;
661                                 
662                         case ANIMTYPE_NLATRACK:
663                         {
664                                 NlaTrack *nlt= (NlaTrack *)data;
665                                 
666                                 ale->flag= nlt->flag;
667                                 
668                                         // XXX or should this be done some other way?
669                                 ale->key_data= &nlt->strips;
670                                 ale->datatype= ALE_NLASTRIP;
671                         }
672                                 break;
673                         case ANIMTYPE_NLAACTION:
674                         {
675                                 /* nothing to include for now... nothing editable from NLA-perspective here */
676                                 ale->key_data= NULL;
677                                 ale->datatype= ALE_NONE;
678                         }
679                                 break;
680                 }
681         }
682         
683         /* return created datatype */
684         return ale;
685 }
686  
687 /* ----------------------------------------- */
688
689
690 static int animdata_filter_fcurves (ListBase *anim_data, bDopeSheet *ads, FCurve *first, bActionGroup *grp, void *owner, short ownertype, int filter_mode, ID *owner_id)
691 {
692         bAnimListElem *ale = NULL;
693         FCurve *fcu;
694         int items = 0;
695         
696         /* loop over F-Curves - assume that the caller of this has already checked that these should be included 
697          * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
698          */
699         for (fcu= first; ((fcu) && (fcu->grp==grp)); fcu= fcu->next) {
700                 /* special exception for Pose-Channel Based F-Curves:
701                  *      - the 'Only Selected' data filter should be applied to Pose-Channel data too, but those are
702                  *        represented as F-Curves. The way the filter for objects worked was to be the first check
703                  *        after 'normal' visibility, so this is done first here too...
704                  *      - we currently use an 'approximate' method for getting these F-Curves that doesn't require
705                  *        carefully checking the entire path
706                  *      - this will also affect things like Drivers, and also works for Bone Constraints
707                  */
708                 if ( ((ads) && (ads->filterflag & ADS_FILTER_ONLYSEL)) && 
709                          ((owner_id) && (GS(owner_id->name) == ID_OB)) ) 
710                 {
711                         Object *ob= (Object *)owner_id;
712                         
713                         /* only consider if F-Curve involves pose_channels */
714                         if ((fcu->rna_path) && strstr(fcu->rna_path, "pose_channels")) {
715                                 bPoseChannel *pchan;
716                                 char *bone_name;
717                                 
718                                 /* get bone-name, and check if this bone is selected */
719                                 bone_name= BLI_getQuotedStr(fcu->rna_path, "pose_channels[");
720                                 pchan= get_pose_channel(ob->pose, bone_name);
721                                 if (bone_name) MEM_freeN(bone_name);
722                                 
723                                 /* can only add this F-Curve if it is selected */
724                                 if ((pchan) && (pchan->bone) && (pchan->bone->flag & BONE_SELECTED)==0)
725                                         continue;
726                         }
727                 }
728                 
729                 /* only include if visible (Graph Editor check, not channels check) */
730                 if (!(filter_mode & ANIMFILTER_CURVEVISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
731                         /* only work with this channel and its subchannels if it is editable */
732                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
733                                 /* only include this curve if selected in a way consistent with the filtering requirements */
734                                 if ( ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu)) ) {
735                                         /* only include if this curve is active */
736                                         if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
737                                                 ale= make_new_animlistelem(fcu, ANIMTYPE_FCURVE, owner, ownertype, owner_id);
738                                                 
739                                                 if (ale) {
740                                                         BLI_addtail(anim_data, ale);
741                                                         items++;
742                                                 }
743                                         }
744                                 }
745                         }
746                 }
747         }
748         
749         /* return the number of items added to the list */
750         return items;
751 }
752
753 static int animdata_filter_action (ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, void *owner, short ownertype, ID *owner_id)
754 {
755         bAnimListElem *ale=NULL;
756         bActionGroup *agrp;
757         FCurve *lastchan=NULL;
758         int items = 0;
759         
760         /* loop over groups */
761         // TODO: in future, should we expect to need nested groups?
762         for (agrp= act->groups.first; agrp; agrp= agrp->next) {
763                 /* add this group as a channel first */
764                 if ((filter_mode & ANIMFILTER_CHANNELS) || !(filter_mode & ANIMFILTER_CURVESONLY)) {
765                         /* check if filtering by selection */
766                         if ( ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
767                                 ale= make_new_animlistelem(agrp, ANIMTYPE_GROUP, NULL, ANIMTYPE_NONE, owner_id);
768                                 if (ale) {
769                                         BLI_addtail(anim_data, ale);
770                                         items++;
771                                 }
772                         }
773                 }
774                 
775                 /* store reference to last channel of group */
776                 if (agrp->channels.last) 
777                         lastchan= agrp->channels.last;
778                 
779                 
780                 /* there are some situations, where only the channels of the action group should get considered */
781                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
782                         /* filters here are a bit convoulted...
783                          *      - groups show a "summary" of keyframes beside their name which must accessable for tools which handle keyframes
784                          *      - groups can be collapsed (and those tools which are only interested in channels rely on knowing that group is closed)
785                          *
786                          * cases when we should include F-Curves inside group:
787                          *      - we don't care about visibility
788                          *      - group is expanded
789                          *      - we just need the F-Curves present
790                          */
791                         if ( (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_AGRP(agrp)) || (filter_mode & ANIMFILTER_CURVESONLY) ) 
792                         {
793                                 /* for the Graph Editor, curves may be set to not be visible in the view to lessen clutter,
794                                  * but to do this, we need to check that the group doesn't have it's not-visible flag set preventing 
795                                  * all its sub-curves to be shown
796                                  */
797                                 if ( !(filter_mode & ANIMFILTER_CURVEVISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE) )
798                                 {
799                                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
800                                                 items += animdata_filter_fcurves(anim_data, ads, agrp->channels.first, agrp, owner, ownertype, filter_mode, owner_id);
801                                         }
802                                 }
803                         }
804                 }
805                 
806                 // TODO: but we still need to deal with the case when the group may be closed, but it has no visible curves too
807         }
808         
809         /* loop over un-grouped F-Curves (only if we're not only considering those channels in the animive group) */
810         if (!(filter_mode & ANIMFILTER_ACTGROUPED))  {
811                 // XXX the 'owner' info here needs review...
812                 items += animdata_filter_fcurves(anim_data, ads, (lastchan)?(lastchan->next):(act->curves.first), NULL, owner, ownertype, filter_mode, owner_id);
813         }
814         
815         /* return the number of items added to the list */
816         return items;
817 }
818
819 /* Include NLA-Data for NLA-Editor:
820  *      - when ANIMFILTER_CHANNELS is used, that means we should be filtering the list for display
821  *        Although the evaluation order is from the first track to the last and then apply the Action on top,
822  *        we present this in the UI as the Active Action followed by the last track to the first so that we 
823  *        get the evaluation order presented as per a stack.
824  *      - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
825  *        order, i.e. first to last. Otherwise, some tools may get screwed up.
826  */
827 static int animdata_filter_nla (ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, void *owner, short ownertype, ID *owner_id)
828 {
829         bAnimListElem *ale;
830         NlaTrack *nlt;
831         NlaTrack *first=NULL, *next=NULL;
832         int items = 0;
833         
834         /* if showing channels, include active action */
835         if (filter_mode & ANIMFILTER_CHANNELS) {
836                 /* there isn't really anything editable here, so skip if need editable */
837                 // TODO: currently, selection isn't checked since it doesn't matter
838                 if ((filter_mode & ANIMFILTER_FOREDIT) == 0) { 
839                         /* just add the action track now (this MUST appear for drawing)
840                          *      - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
841                          *        overwrite this with the real value - REVIEW THIS...
842                          */
843                         ale= make_new_animlistelem((void *)(&adt->action), ANIMTYPE_NLAACTION, owner, ownertype, owner_id);
844                         ale->data= (adt->action) ? adt->action : NULL;
845                                 
846                         if (ale) {
847                                 BLI_addtail(anim_data, ale);
848                                 items++;
849                         }
850                 }
851                 
852                 /* first track to include will be the last one if we're filtering by channels */
853                 first= adt->nla_tracks.last;
854         }
855         else {
856                 /* first track to include will the the first one (as per normal) */
857                 first= adt->nla_tracks.first;
858         }
859         
860         /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
861         for (nlt= first; nlt; nlt= next) {
862                 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
863                 if (filter_mode & ANIMFILTER_CHANNELS) 
864                         next= nlt->prev;
865                 else
866                         next= nlt->next;
867                 
868                 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now 
869                  *      - active track should still get shown though (even though it has disabled flag set)
870                  */
871                 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
872                 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && !(nlt->flag & NLATRACK_ACTIVE))
873                         continue;
874                 
875                 /* only work with this channel and its subchannels if it is editable */
876                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
877                         /* only include this track if selected in a way consistent with the filtering requirements */
878                         if ( ANIMCHANNEL_SELOK(SEL_NLT(nlt)) ) {
879                                 /* only include if this track is active */
880                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
881                                         ale= make_new_animlistelem(nlt, ANIMTYPE_NLATRACK, owner, ownertype, owner_id);
882                                                 
883                                         if (ale) {
884                                                 BLI_addtail(anim_data, ale);
885                                                 items++;
886                                         }
887                                 }
888                         }
889                 }
890         }
891         
892         /* return the number of items added to the list */
893         return items;
894 }
895  
896 #if 0
897 // FIXME: switch this to use the bDopeSheet...
898 static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter_mode)
899 {
900         bAnimListElem *ale;
901         ScrArea *sa, *curarea;
902         bGPdata *gpd;
903         bGPDlayer *gpl;
904         int items = 0;
905         
906         /* check if filtering types are appropriate */
907         {
908                 /* special hack for fullscreen area (which must be this one then):
909                  *      - we use the curarea->full as screen to get spaces from, since the
910                  *        old (pre-fullscreen) screen was stored there...
911                  *      - this is needed as all data would otherwise disappear
912                  */
913                 // XXX need to get new alternative for curarea
914                 if ((curarea->full) && (curarea->spacetype==SPACE_ACTION))
915                         sc= curarea->full;
916                 
917                 /* loop over spaces in current screen, finding gpd blocks (could be slow!) */
918                 for (sa= sc->areabase.first; sa; sa= sa->next) {
919                         /* try to get gp data */
920                         // XXX need to put back grease pencil api...
921                         gpd= gpencil_data_get_active(sa);
922                         if (gpd == NULL) continue;
923                         
924                         /* add gpd as channel too (if for drawing, and it has layers) */
925                         if ((filter_mode & ANIMFILTER_CHANNELS) && (gpd->layers.first)) {
926                                 /* add to list */
927                                 ale= make_new_animlistelem(gpd, ANIMTYPE_GPDATABLOCK, sa, ANIMTYPE_SPECIALDATA);
928                                 if (ale) {
929                                         BLI_addtail(anim_data, ale);
930                                         items++;
931                                 }
932                         }
933                         
934                         /* only add layers if they will be visible (if drawing channels) */
935                         if ( !(filter_mode & ANIMFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) {
936                                 /* loop over layers as the conditions are acceptable */
937                                 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
938                                         /* only if selected */
939                                         if ( ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
940                                                 /* only if editable */
941                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
942                                                         /* add to list */
943                                                         ale= make_new_animlistelem(gpl, ANIMTYPE_GPLAYER, gpd, ANIMTYPE_GPDATABLOCK);
944                                                         if (ale) {
945                                                                 BLI_addtail(anim_data, ale);
946                                                                 items++;
947                                                         }
948                                                 }
949                                         }
950                                 }
951                         }
952                 }
953         }
954         
955         /* return the number of items added to the list */
956         return items;
957 }
958 #endif 
959
960
961 static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
962 {
963         ListBase mats = {NULL, NULL};
964         LinkData *ld;
965         
966         bAnimListElem *ale=NULL;
967         Object *ob= base->object;
968         int items=0, a=0;
969         
970         /* firstly check that we actuallly have some materials, by gathering all materials in a temp list */
971         for (a=0; a < ob->totcol; a++) {
972                 Material *ma= give_current_material(ob, a);
973                 short ok = 0;
974                 
975                 /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
976                 if (ELEM(NULL, ma, ma->adt)) 
977                         continue;
978                 
979                 /* check if ok */
980                 ANIMDATA_FILTER_CASES(ma, 
981                         { /* AnimData blocks - do nothing... */ },
982                         ok=1;, 
983                         ok=1;, 
984                         ok=1;)
985                 if (ok == 0) continue;
986                 
987                 /* make a temp list elem for this */
988                 ld= MEM_callocN(sizeof(LinkData), "DopeSheet-MaterialCache");
989                 ld->data= ma;
990                 BLI_addtail(&mats, ld);
991         }
992         
993         /* if there were no channels found, no need to carry on */
994         if (mats.first == NULL)
995                 return 0;
996         
997         /* include materials-expand widget? */
998         if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
999                 ale= make_new_animlistelem(ob, ANIMTYPE_FILLMATD, base, ANIMTYPE_OBJECT, (ID *)ob);
1000                 if (ale) {
1001                         BLI_addtail(anim_data, ale);
1002                         items++;
1003                 }
1004         }
1005         
1006         /* add materials? */
1007         if (FILTER_MAT_OBJC(ob) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1008                 /* for each material in cache, add channels  */
1009                 for (ld= mats.first; ld; ld= ld->next) {
1010                         Material *ma= (Material *)ld->data;
1011                         
1012                         /* include material-expand widget? */
1013                         // hmm... do we need to store the index of this material in the array anywhere?
1014                         if (filter_mode & ANIMFILTER_CHANNELS) {
1015                                 /* check if filtering by active status */
1016                                 if ANIMCHANNEL_ACTIVEOK(ma) {
1017                                         ale= make_new_animlistelem(ma, ANIMTYPE_DSMAT, base, ANIMTYPE_OBJECT, (ID *)ma);
1018                                         if (ale) {
1019                                                 BLI_addtail(anim_data, ale);
1020                                                 items++;
1021                                         }
1022                                 }
1023                         }
1024                         
1025                         /* add material's animation data */
1026                         if (FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1027                                 ANIMDATA_FILTER_CASES(ma, 
1028                                         { /* AnimData blocks - do nothing... */ },
1029                                         items += animdata_filter_nla(anim_data, ads, ma->adt, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);, 
1030                                         items += animdata_filter_fcurves(anim_data, ads, ma->adt->drivers.first, NULL, ma, ANIMTYPE_DSMAT, filter_mode, (ID *)ma);, 
1031                                         items += animdata_filter_action(anim_data, ads, ma->adt->action, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);)
1032                         }
1033                 }
1034         }
1035         
1036         /* free cache */
1037         BLI_freelistN(&mats);
1038         
1039         /* return the number of items added to the list */
1040         return items;
1041 }
1042
1043 static int animdata_filter_dopesheet_particles (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1044 {
1045         bAnimListElem *ale=NULL;
1046         Object *ob= base->object;
1047         ParticleSystem *psys = ob->particlesystem.first;
1048         int items= 0, first = 1;
1049
1050         for(; psys; psys=psys->next) {
1051                 short ok = 0;
1052
1053                 if(ELEM(NULL, psys->part, psys->part->adt))
1054                         continue;
1055
1056                 ANIMDATA_FILTER_CASES(psys->part,
1057                         { /* AnimData blocks - do nothing... */ },
1058                         ok=1;, 
1059                         ok=1;, 
1060                         ok=1;)
1061                 if (ok == 0) continue;
1062
1063                 /* include particles-expand widget? */
1064                 if (first && (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1065                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLPARTD, base, ANIMTYPE_OBJECT, (ID *)ob);
1066                         if (ale) {
1067                                 BLI_addtail(anim_data, ale);
1068                                 items++;
1069                         }
1070                         first = 0;
1071                 }
1072                 
1073                 /* add particle settings? */
1074                 if (FILTER_PART_OBJC(ob) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1075                         if ((filter_mode & ANIMFILTER_CHANNELS)) {
1076                                 /* check if filtering by active status */
1077                                 if ANIMCHANNEL_ACTIVEOK(psys->part) {
1078                                         ale = make_new_animlistelem(psys->part, ANIMTYPE_DSPART, base, ANIMTYPE_OBJECT, (ID *)psys->part);
1079                                         if (ale) {
1080                                                 BLI_addtail(anim_data, ale);
1081                                                 items++;
1082                                         }
1083                                 }
1084                         }
1085                         
1086                         if (FILTER_PART_OBJD(psys->part) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1087                                 ANIMDATA_FILTER_CASES(psys->part,
1088                                         { /* AnimData blocks - do nothing... */ },
1089                                         items += animdata_filter_nla(anim_data, ads, psys->part->adt, filter_mode, psys->part, ANIMTYPE_DSPART, (ID *)psys->part);, 
1090                                         items += animdata_filter_fcurves(anim_data, ads, psys->part->adt->drivers.first, NULL, psys->part, ANIMTYPE_DSPART, filter_mode, (ID *)psys->part);, 
1091                                         items += animdata_filter_action(anim_data, ads, psys->part->adt->action, filter_mode, psys->part, ANIMTYPE_DSPART, (ID *)psys->part);)
1092                         }
1093                 }
1094         }
1095         
1096         /* return the number of items added to the list */
1097         return items;
1098 }
1099
1100 static int animdata_filter_dopesheet_obdata (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1101 {
1102         bAnimListElem *ale=NULL;
1103         Object *ob= base->object;
1104         IdAdtTemplate *iat= ob->data;
1105         AnimData *adt= iat->adt;
1106         short type=0, expanded=0;
1107         int items= 0;
1108         
1109         /* get settings based on data type */
1110         switch (ob->type) {
1111                 case OB_CAMERA: /* ------- Camera ------------ */
1112                 {
1113                         Camera *ca= (Camera *)ob->data;
1114                         
1115                         type= ANIMTYPE_DSCAM;
1116                         expanded= FILTER_CAM_OBJD(ca);
1117                 }
1118                         break;
1119                 case OB_LAMP: /* ---------- Lamp ----------- */
1120                 {
1121                         Lamp *la= (Lamp *)ob->data;
1122                         
1123                         type= ANIMTYPE_DSLAM;
1124                         expanded= FILTER_LAM_OBJD(la);
1125                 }
1126                         break;
1127                 case OB_CURVE: /* ------- Curve ---------- */
1128                 {
1129                         Curve *cu= (Curve *)ob->data;
1130                         
1131                         type= ANIMTYPE_DSCUR;
1132                         expanded= FILTER_CUR_OBJD(cu);
1133                 }
1134                         break;
1135                 case OB_MBALL: /* ------- MetaBall ---------- */
1136                 {
1137                         MetaBall *mb= (MetaBall *)ob->data;
1138                         
1139                         type= ANIMTYPE_DSMBALL;
1140                         expanded= FILTER_MBALL_OBJD(mb);
1141                 }
1142                         break;
1143                 case OB_ARMATURE: /* ------- Armature ---------- */
1144                 {
1145                         bArmature *arm= (bArmature *)ob->data;
1146                         
1147                         type= ANIMTYPE_DSARM;
1148                         expanded= FILTER_ARM_OBJD(arm);
1149                 }
1150                         break;
1151         }
1152         
1153         /* special exception for drivers instead of action */
1154         if (ads->filterflag & ADS_FILTER_ONLYDRIVERS)
1155                 expanded= EXPANDED_DRVD(adt);
1156         
1157         /* include data-expand widget? */
1158         if ((filter_mode & ANIMFILTER_CURVESONLY) == 0) {       
1159                 /* check if filtering by active status */
1160                 if ANIMCHANNEL_ACTIVEOK(iat) {
1161                         ale= make_new_animlistelem(iat, type, base, ANIMTYPE_OBJECT, (ID *)iat);
1162                         if (ale) BLI_addtail(anim_data, ale);
1163                 }
1164         }
1165         
1166         /* add object-data animation channels? */
1167         if ((expanded) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1168                 /* filtering for channels - nla, drivers, keyframes */
1169                 ANIMDATA_FILTER_CASES(iat, 
1170                         { /* AnimData blocks - do nothing... */ },
1171                         items+= animdata_filter_nla(anim_data, ads, iat->adt, filter_mode, iat, type, (ID *)iat);,
1172                         items+= animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, iat, type, filter_mode, (ID *)iat);, 
1173                         items += animdata_filter_action(anim_data, ads, iat->adt->action, filter_mode, iat, type, (ID *)iat);)
1174         }
1175         
1176         /* return the number of items added to the list */
1177         return items;
1178 }
1179
1180 static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
1181 {
1182         bAnimListElem *ale=NULL;
1183         AnimData *adt = NULL;
1184         Object *ob= base->object;
1185         Key *key= ob_get_key(ob);
1186         short obdata_ok = 0;
1187         int items = 0;
1188         
1189         /* add this object as a channel first */
1190         if ((filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) == 0) {
1191                 /* check if filtering by selection */
1192                 if ANIMCHANNEL_SELOK((base->flag & SELECT)) {
1193                         /* check if filtering by active status */
1194                         if ANIMCHANNEL_ACTIVEOK(ob) {
1195                                 ale= make_new_animlistelem(base, ANIMTYPE_OBJECT, NULL, ANIMTYPE_NONE, (ID *)ob);
1196                                 if (ale) {
1197                                         BLI_addtail(anim_data, ale);
1198                                         items++;
1199                                 }
1200                         }
1201                 }
1202         }
1203         
1204         /* if collapsed, don't go any further (unless adding keyframes only) */
1205         if ( (EXPANDED_OBJC(ob) == 0) && !(filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) )
1206                 return items;
1207         
1208         /* Action, Drivers, or NLA */
1209         if (ob->adt) {
1210                 adt= ob->adt;
1211                 ANIMDATA_FILTER_CASES(ob,
1212                         { /* AnimData blocks - do nothing... */ },
1213                         { /* nla */
1214                                 /* add NLA tracks */
1215                                 items += animdata_filter_nla(anim_data, ads, adt, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
1216                         },
1217                         { /* drivers */
1218                                 /* include drivers-expand widget? */
1219                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1220                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, base, ANIMTYPE_OBJECT, (ID *)ob);
1221                                         if (ale) {
1222                                                 BLI_addtail(anim_data, ale);
1223                                                 items++;
1224                                         }
1225                                 }
1226                                 
1227                                 /* add F-Curve channels (drivers are F-Curves) */
1228                                 if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1229                                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1230                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)ob);
1231                                 }
1232                         },
1233                         { /* action (keyframes) */
1234                                 /* include action-expand widget? */
1235                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1236                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT, (ID *)ob);
1237                                         if (ale) {
1238                                                 BLI_addtail(anim_data, ale);
1239                                                 items++;
1240                                         }
1241                                 }
1242                                 
1243                                 /* add F-Curve channels? */
1244                                 if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1245                                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1246                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob); 
1247                                 }
1248                         }
1249                 );
1250         }
1251         
1252         
1253         /* ShapeKeys? */
1254         if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
1255                 adt= key->adt;
1256                 ANIMDATA_FILTER_CASES(key,
1257                         { /* AnimData blocks - do nothing... */ },
1258                         { /* nla */
1259                                 /* include shapekey-expand widget? */
1260                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1261                                         /* check if filtering by active status */
1262                                         if ANIMCHANNEL_ACTIVEOK(key) {
1263                                                 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1264                                                 if (ale) {
1265                                                         BLI_addtail(anim_data, ale);
1266                                                         items++;
1267                                                 }
1268                                         }
1269                                 }
1270                                 
1271                                 /* add NLA tracks - only if expanded or so */
1272                                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY))
1273                                         items += animdata_filter_nla(anim_data, ads, adt, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
1274                         },
1275                         { /* drivers */
1276                                 /* include shapekey-expand widget? */
1277                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1278                                         ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1279                                         if (ale) {
1280                                                 BLI_addtail(anim_data, ale);
1281                                                 items++;
1282                                         }
1283                                 }
1284                                 
1285                                 /* add channels */
1286                                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1287                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, key, ANIMTYPE_DSSKEY, filter_mode, (ID *)key);
1288                                 }
1289                         },
1290                         { /* action (keyframes) */
1291                                 /* include shapekey-expand widget? */
1292                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1293                                         /* check if filtering by active status */
1294                                         if ANIMCHANNEL_ACTIVEOK(key) {
1295                                                 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
1296                                                 if (ale) {
1297                                                         BLI_addtail(anim_data, ale);
1298                                                         items++;
1299                                                 }
1300                                         }
1301                                 }
1302                                 
1303                                 /* add channels */
1304                                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1305                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, key, ANIMTYPE_DSSKEY, (ID *)key); 
1306                                 }
1307                         }
1308                 );
1309         }
1310
1311         /* Materials? */
1312         if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
1313                 items += animdata_filter_dopesheet_mats(anim_data, ads, base, filter_mode);
1314         
1315         /* Object Data */
1316         switch (ob->type) {
1317                 case OB_CAMERA: /* ------- Camera ------------ */
1318                 {
1319                         Camera *ca= (Camera *)ob->data;
1320                         
1321                         if ((ads->filterflag & ADS_FILTER_NOCAM) == 0) {
1322                                 ANIMDATA_FILTER_CASES(ca,
1323                                         { /* AnimData blocks - do nothing... */ },
1324                                         obdata_ok= 1;,
1325                                         obdata_ok= 1;,
1326                                         obdata_ok= 1;)
1327                         }
1328                 }
1329                         break;
1330                 case OB_LAMP: /* ---------- Lamp ----------- */
1331                 {
1332                         Lamp *la= (Lamp *)ob->data;
1333                         
1334                         if ((ads->filterflag & ADS_FILTER_NOLAM) == 0) {
1335                                 ANIMDATA_FILTER_CASES(la,
1336                                         { /* AnimData blocks - do nothing... */ },
1337                                         obdata_ok= 1;,
1338                                         obdata_ok= 1;,
1339                                         obdata_ok= 1;)
1340                         }
1341                 }
1342                         break;
1343                 case OB_CURVE: /* ------- Curve ---------- */
1344                 {
1345                         Curve *cu= (Curve *)ob->data;
1346                         
1347                         if ((ads->filterflag & ADS_FILTER_NOCUR) == 0) {
1348                                 ANIMDATA_FILTER_CASES(cu,
1349                                         { /* AnimData blocks - do nothing... */ },
1350                                         obdata_ok= 1;,
1351                                         obdata_ok= 1;,
1352                                         obdata_ok= 1;)
1353                         }
1354                 }
1355                         break;
1356                 case OB_MBALL: /* ------- MetaBall ---------- */
1357                 {
1358                         MetaBall *mb= (MetaBall *)ob->data;
1359                         
1360                         if ((ads->filterflag & ADS_FILTER_NOMBA) == 0) {
1361                                 ANIMDATA_FILTER_CASES(mb,
1362                                         { /* AnimData blocks - do nothing... */ },
1363                                         obdata_ok= 1;,
1364                                         obdata_ok= 1;,
1365                                         obdata_ok= 1;)
1366                         }
1367                 }
1368                         break;
1369                 case OB_ARMATURE: /* ------- Armature ---------- */
1370                 {
1371                         bArmature *arm= (bArmature *)ob->data;
1372                         
1373                         if ((ads->filterflag & ADS_FILTER_NOARM) == 0) {
1374                                 ANIMDATA_FILTER_CASES(arm,
1375                                         { /* AnimData blocks - do nothing... */ },
1376                                         obdata_ok= 1;,
1377                                         obdata_ok= 1;,
1378                                         obdata_ok= 1;)
1379                         }
1380                 }
1381                         break;
1382         }
1383         if (obdata_ok) 
1384                 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
1385
1386         /* particles */
1387         if (ob->particlesystem.first && !(ads->filterflag & ADS_FILTER_NOPART))
1388                 items += animdata_filter_dopesheet_particles(anim_data, ads, base, filter_mode);
1389         
1390         /* return the number of items added to the list */
1391         return items;
1392 }       
1393
1394 static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1395 {
1396         World *wo= sce->world;
1397         AnimData *adt= NULL;
1398         bAnimListElem *ale;
1399         int items = 0;
1400         
1401         /* add scene as a channel first (even if we aren't showing scenes we still need to show the scene's sub-data */
1402         if ((filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) == 0) {
1403                 /* check if filtering by selection */
1404                 if (ANIMCHANNEL_SELOK( (sce->flag & SCE_DS_SELECTED) )) {
1405                         ale= make_new_animlistelem(sce, ANIMTYPE_SCENE, NULL, ANIMTYPE_NONE, NULL);
1406                         if (ale) {
1407                                 BLI_addtail(anim_data, ale);
1408                                 items++;
1409                         }
1410                 }
1411         }
1412         
1413         /* if collapsed, don't go any further (unless adding keyframes only) */
1414         if ( (EXPANDED_SCEC(sce) == 0) && !(filter_mode & (ANIMFILTER_CURVESONLY|ANIMFILTER_NLATRACKS)) )
1415                 return items;
1416                 
1417         /* Action, Drivers, or NLA for Scene */
1418         if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
1419                 adt= sce->adt;
1420                 ANIMDATA_FILTER_CASES(sce,
1421                         { /* AnimData blocks - do nothing... */ },
1422                         { /* nla */
1423                                 /* add NLA tracks */
1424                                 items += animdata_filter_nla(anim_data, ads, adt, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce);
1425                         },
1426                         { /* drivers */
1427                                 /* include drivers-expand widget? */
1428                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1429                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, sce, ANIMTYPE_SCENE, (ID *)sce);
1430                                         if (ale) {
1431                                                 BLI_addtail(anim_data, ale);
1432                                                 items++;
1433                                         }
1434                                 }
1435                                 
1436                                 /* add F-Curve channels (drivers are F-Curves) */
1437                                 if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1438                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, sce, ANIMTYPE_SCENE, filter_mode, (ID *)sce);
1439                                 }
1440                         },
1441                         { /* action */
1442                                 /* include action-expand widget? */
1443                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1444                                         ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, sce, ANIMTYPE_SCENE, (ID *)sce);
1445                                         if (ale) {
1446                                                 BLI_addtail(anim_data, ale);
1447                                                 items++;
1448                                         }
1449                                 }
1450                                 
1451                                 /* add F-Curve channels? */
1452                                 if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1453                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce); 
1454                                 }
1455                         }
1456                 )
1457         }
1458         
1459         /* world */
1460         if ((wo && wo->adt) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
1461                 /* Action, Drivers, or NLA for World */
1462                 adt= wo->adt;
1463                 ANIMDATA_FILTER_CASES(wo,
1464                         { /* AnimData blocks - do nothing... */ },
1465                         { /* nla */
1466                                 /* add NLA tracks */
1467                                 items += animdata_filter_nla(anim_data, ads, adt, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo);
1468                         },
1469                         { /* drivers */
1470                                 /* include world-expand widget? */
1471                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1472                                         ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)wo);
1473                                         if (ale) {
1474                                                 BLI_addtail(anim_data, ale);
1475                                                 items++;
1476                                         }
1477                                 }
1478                                 
1479                                 /* add F-Curve channels (drivers are F-Curves) */
1480                                 if (FILTER_WOR_SCED(wo)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
1481                                         // XXX owner info is messed up now...
1482                                         items += animdata_filter_fcurves(anim_data, ads, adt->drivers.first, NULL, wo, ANIMTYPE_DSWOR, filter_mode, (ID *)wo);
1483                                 }
1484                         },
1485                         { /* action */
1486                                 /* include world-expand widget? */
1487                                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1488                                         ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)sce);
1489                                         if (ale) {
1490                                                 BLI_addtail(anim_data, ale);
1491                                                 items++;
1492                                         }
1493                                 }
1494                                 
1495                                 /* add channels */
1496                                 if (FILTER_WOR_SCED(wo) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1497                                         items += animdata_filter_action(anim_data, ads, adt->action, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo); 
1498                                 }
1499                         }
1500                 )
1501         }
1502         
1503         // TODO: scene compositing nodes (these aren't standard node-trees)
1504         
1505         /* return the number of items added to the list */
1506         return items;
1507 }
1508
1509 // 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)
1510 static int animdata_filter_dopesheet (ListBase *anim_data, bAnimContext *ac, bDopeSheet *ads, int filter_mode)
1511 {
1512         Scene *sce= (Scene *)ads->source;
1513         Base *base;
1514         bAnimListElem *ale;
1515         int items = 0;
1516         
1517         /* check that we do indeed have a scene */
1518         if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
1519                 printf("DopeSheet Error: Not scene! \n");
1520                 return 0;
1521         }
1522         
1523         /* scene-linked animation */
1524         // TODO: sequencer, composite nodes - are we to include those here too?
1525         {
1526                 short sceOk= 0, worOk= 0;
1527                 
1528                 /* check filtering-flags if ok */
1529                 ANIMDATA_FILTER_CASES(sce, 
1530                         {
1531                                 /* for the special AnimData blocks only case, we only need to add
1532                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1533                                  */
1534                                 ANIMDATA_ADD_ANIMDATA(sce);
1535                                 sceOk=0;
1536                         },
1537                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);, 
1538                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);, 
1539                         sceOk= !(ads->filterflag & ADS_FILTER_NOSCE);)
1540                 if (sce->world) {
1541                         ANIMDATA_FILTER_CASES(sce->world, 
1542                                 {
1543                                         /* for the special AnimData blocks only case, we only need to add
1544                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1545                                          */
1546                                         ANIMDATA_ADD_ANIMDATA(sce->world);
1547                                         worOk=0;
1548                                 },
1549                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);, 
1550                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);, 
1551                                 worOk= !(ads->filterflag & ADS_FILTER_NOWOR);)
1552                 }
1553                 
1554                 /* if only F-Curves with visible flags set can be shown, check that 
1555                  * datablocks haven't been set to invisible 
1556                  */
1557                 if (filter_mode & ANIMFILTER_CURVEVISIBLE) {
1558                         if ((sce->adt) && (sce->adt->flag & ADT_CURVES_NOT_VISIBLE))
1559                                 sceOk= worOk= 0;
1560                 }
1561                 
1562                 /* check if not all bad (i.e. so there is something to show) */
1563                 if ( !(!sceOk && !worOk) ) {
1564                         /* add scene data to the list of filtered channels */
1565                         items += animdata_filter_dopesheet_scene(anim_data, ads, sce, filter_mode);
1566                 }
1567         }
1568         
1569         
1570         /* loop over all bases in the scene */
1571         for (base= sce->base.first; base; base= base->next) {
1572                 /* check if there's an object (all the relevant checks are done in the ob-function) */
1573                 if (base->object) {
1574                         Object *ob= base->object;
1575                         Key *key= ob_get_key(ob);
1576                         short actOk=1, keyOk=1, dataOk=1, matOk=1, partOk=1;
1577                         
1578                         /* firstly, check if object can be included, by the following factors:
1579                          *      - if only visible, must check for layer and also viewport visibility
1580                          *      - if only selected, must check if object is selected 
1581                          *      - there must be animation data to edit
1582                          */
1583                         // TODO: if cache is implemented, just check name here, and then 
1584                         if (filter_mode & ANIMFILTER_VISIBLE) {
1585                                 /* layer visibility - we check both object and base, since these may not be in sync yet */
1586                                 if ((sce->lay & (ob->lay|base->lay))==0) continue;
1587                                 
1588                                 /* outliner restrict-flag */
1589                                 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1590                         }
1591                         
1592                         /* if only F-Curves with visible flags set can be shown, check that 
1593                          * datablock hasn't been set to invisible 
1594                          */
1595                         if (filter_mode & ANIMFILTER_CURVEVISIBLE) {
1596                                 if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE))
1597                                         continue;
1598                         }
1599                         
1600                         /* additionally, dopesheet filtering also affects what objects to consider */
1601                         if (ads->filterflag) {
1602                                 /* check selection and object type filters */
1603                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) || (base == sce->basact)) )  {
1604                                         /* only selected should be shown */
1605                                         continue;
1606                                 }
1607                                 
1608                                 /* check filters for datatypes */
1609                                         /* object */
1610                                 actOk= 0;
1611                                 keyOk= 0;
1612                                 ANIMDATA_FILTER_CASES(ob, 
1613                                         {
1614                                                 /* for the special AnimData blocks only case, we only need to add
1615                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1616                                                  */
1617                                                 ANIMDATA_ADD_ANIMDATA(ob);
1618                                                 actOk=0;
1619                                         },
1620                                         actOk= 1;, 
1621                                         actOk= 1;, 
1622                                         actOk= 1;)
1623                                 if (key) {
1624                                         /* shapekeys */
1625                                         ANIMDATA_FILTER_CASES(key, 
1626                                                 {
1627                                                         /* for the special AnimData blocks only case, we only need to add
1628                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1629                                                          */
1630                                                         ANIMDATA_ADD_ANIMDATA(key);
1631                                                         keyOk=0;
1632                                                 },
1633                                                 keyOk= 1;, 
1634                                                 keyOk= 1;, 
1635                                                 keyOk= 1;)
1636                                 }
1637                                 
1638                                 /* materials - only for geometric types */
1639                                 matOk= 0; /* by default, not ok... */
1640                                 if ( !(ads->filterflag & ADS_FILTER_NOMAT) && (ob->totcol) && 
1641                                          ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) ) 
1642                                 {
1643                                         int a;
1644                                         
1645                                         /* firstly check that we actuallly have some materials */
1646                                         for (a=0; a < ob->totcol; a++) {
1647                                                 Material *ma= give_current_material(ob, a);
1648                                                 
1649                                                 if (ma) {
1650                                                         /* if material has relevant animation data, break */
1651                                                         ANIMDATA_FILTER_CASES(ma, 
1652                                                                 {
1653                                                                         /* for the special AnimData blocks only case, we only need to add
1654                                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1655                                                                          */
1656                                                                         ANIMDATA_ADD_ANIMDATA(ma);
1657                                                                         matOk=0;
1658                                                                 },
1659                                                                 matOk= 1;, 
1660                                                                 matOk= 1;, 
1661                                                                 matOk= 1;)
1662                                                 }
1663                                                         
1664                                                 if (matOk) 
1665                                                         break;
1666                                         }
1667                                 }
1668                                 
1669                                 /* data */
1670                                 switch (ob->type) {
1671                                         case OB_CAMERA: /* ------- Camera ------------ */
1672                                         {
1673                                                 Camera *ca= (Camera *)ob->data;
1674                                                 dataOk= 0;
1675                                                 ANIMDATA_FILTER_CASES(ca, 
1676                                                         if ((ads->filterflag & ADS_FILTER_NOCAM)==0) {
1677                                                                 /* for the special AnimData blocks only case, we only need to add
1678                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1679                                                                  */
1680                                                                 ANIMDATA_ADD_ANIMDATA(ca);
1681                                                                 dataOk=0;
1682                                                         },
1683                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);, 
1684                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);, 
1685                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCAM);)
1686                                         }
1687                                                 break;
1688                                         case OB_LAMP: /* ---------- Lamp ----------- */
1689                                         {
1690                                                 Lamp *la= (Lamp *)ob->data;
1691                                                 dataOk= 0;
1692                                                 ANIMDATA_FILTER_CASES(la, 
1693                                                         if ((ads->filterflag & ADS_FILTER_NOLAM)==0) {
1694                                                                 /* for the special AnimData blocks only case, we only need to add
1695                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1696                                                                  */
1697                                                                 ANIMDATA_ADD_ANIMDATA(la);
1698                                                                 dataOk=0;
1699                                                         },
1700                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);, 
1701                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);, 
1702                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOLAM);)
1703                                         }
1704                                                 break;
1705                                         case OB_CURVE: /* ------- Curve ---------- */
1706                                         {
1707                                                 Curve *cu= (Curve *)ob->data;
1708                                                 dataOk= 0;
1709                                                 ANIMDATA_FILTER_CASES(cu, 
1710                                                         if ((ads->filterflag & ADS_FILTER_NOCUR)==0) {
1711                                                                 /* for the special AnimData blocks only case, we only need to add
1712                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1713                                                                  */
1714                                                                 ANIMDATA_ADD_ANIMDATA(cu);
1715                                                                 dataOk=0;
1716                                                         },
1717                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);, 
1718                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);, 
1719                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOCUR);)
1720                                         }
1721                                                 break;
1722                                         case OB_MBALL: /* ------- MetaBall ---------- */
1723                                         {
1724                                                 MetaBall *mb= (MetaBall *)ob->data;
1725                                                 dataOk= 0;
1726                                                 ANIMDATA_FILTER_CASES(mb, 
1727                                                         if ((ads->filterflag & ADS_FILTER_NOMBA)==0) {
1728                                                                 /* for the special AnimData blocks only case, we only need to add
1729                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1730                                                                  */
1731                                                                 ANIMDATA_ADD_ANIMDATA(mb);
1732                                                                 dataOk=0;
1733                                                         },
1734                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);, 
1735                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);, 
1736                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOMBA);)
1737                                         }
1738                                                 break;
1739                                         case OB_ARMATURE: /* ------- Armature ---------- */
1740                                         {
1741                                                 bArmature *arm= (bArmature *)ob->data;
1742                                                 dataOk= 0;
1743                                                 ANIMDATA_FILTER_CASES(arm, 
1744                                                         if ((ads->filterflag & ADS_FILTER_NOARM)==0) {
1745                                                                 /* for the special AnimData blocks only case, we only need to add
1746                                                                  * the block if it is valid... then other cases just get skipped (hence ok=0)
1747                                                                  */
1748                                                                 ANIMDATA_ADD_ANIMDATA(arm);
1749                                                                 dataOk=0;
1750                                                         },
1751                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
1752                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);, 
1753                                                         dataOk= !(ads->filterflag & ADS_FILTER_NOARM);)
1754                                         }
1755                                                 break;
1756                                         default: /* --- other --- */
1757                                                 dataOk= 0;
1758                                                 break;
1759                                 }
1760                                 
1761                                 /* particles */
1762                                 partOk = 0;
1763                                 if (!(ads->filterflag & ADS_FILTER_NOPART) && ob->particlesystem.first) {
1764                                         ParticleSystem *psys = ob->particlesystem.first;
1765                                         for(; psys; psys=psys->next) {
1766                                                 if (psys->part) {
1767                                                         /* if particlesettings has relevant animation data, break */
1768                                                         ANIMDATA_FILTER_CASES(psys->part, 
1769                                                                 {
1770                                                                         /* for the special AnimData blocks only case, we only need to add
1771                                                                          * the block if it is valid... then other cases just get skipped (hence ok=0)
1772                                                                          */
1773                                                                         ANIMDATA_ADD_ANIMDATA(psys->part);
1774                                                                         partOk=0;
1775                                                                 },
1776                                                                 partOk= 1;, 
1777                                                                 partOk= 1;, 
1778                                                                 partOk= 1;)
1779                                                 }
1780                                                         
1781                                                 if (partOk) 
1782                                                         break;
1783                                         }
1784                                 }
1785                                 
1786                                 /* check if all bad (i.e. nothing to show) */
1787                                 if (!actOk && !keyOk && !dataOk && !matOk && !partOk)
1788                                         continue;
1789                         }
1790                         else {
1791                                 /* check data-types */
1792                                 actOk= ANIMDATA_HAS_KEYS(ob);
1793                                 keyOk= (key != NULL);
1794                                 
1795                                 /* materials - only for geometric types */
1796                                 matOk= 0; /* by default, not ok... */
1797                                 if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) && (ob->totcol)) 
1798                                 {
1799                                         int a;
1800                                         
1801                                         /* firstly check that we actuallly have some materials */
1802                                         for (a=0; a < ob->totcol; a++) {
1803                                                 Material *ma= give_current_material(ob, a);
1804                                                 
1805                                                 if ((ma) && ANIMDATA_HAS_KEYS(ma)) {
1806                                                         matOk= 1;
1807                                                         break;
1808                                                 }
1809                                         }
1810                                 }
1811                                 
1812                                 /* data */
1813                                 switch (ob->type) {
1814                                         case OB_CAMERA: /* ------- Camera ------------ */
1815                                         {
1816                                                 Camera *ca= (Camera *)ob->data;
1817                                                 dataOk= ANIMDATA_HAS_KEYS(ca);                                          
1818                                         }
1819                                                 break;
1820                                         case OB_LAMP: /* ---------- Lamp ----------- */
1821                                         {
1822                                                 Lamp *la= (Lamp *)ob->data;
1823                                                 dataOk= ANIMDATA_HAS_KEYS(la);  
1824                                         }
1825                                                 break;
1826                                         case OB_CURVE: /* -------- Curve ---------- */
1827                                         {
1828                                                 Curve *cu= (Curve *)ob->data;
1829                                                 dataOk= ANIMDATA_HAS_KEYS(cu);  
1830                                         }
1831                                                 break;
1832                                         case OB_MBALL: /* -------- Metas ---------- */
1833                                         {
1834                                                 MetaBall *mb= (MetaBall *)ob->data;
1835                                                 dataOk= ANIMDATA_HAS_KEYS(mb);  
1836                                         }
1837                                                 break;
1838                                         case OB_ARMATURE: /* -------- Armature ---------- */
1839                                         {
1840                                                 bArmature *arm= (bArmature *)ob->data;
1841                                                 dataOk= ANIMDATA_HAS_KEYS(arm); 
1842                                         }
1843                                                 break;
1844                                         default: /* --- other --- */
1845                                                 dataOk= 0;
1846                                                 break;
1847                                 }
1848                                 
1849                                 /* particles */
1850                                 partOk = 0;
1851                                 if (ob->particlesystem.first) {
1852                                         ParticleSystem *psys = ob->particlesystem.first;
1853                                         for(; psys; psys=psys->next) {
1854                                                 if(psys->part && ANIMDATA_HAS_KEYS(psys->part)) {
1855                                                         partOk = 1;
1856                                                         break;
1857                                                 }
1858                                         }
1859                                 }
1860                                 
1861                                 /* check if all bad (i.e. nothing to show) */
1862                                 if (!actOk && !keyOk && !dataOk && !matOk && !partOk)
1863                                         continue;
1864                         }
1865                         
1866                         /* since we're still here, this object should be usable */
1867                         items += animdata_filter_dopesheet_ob(anim_data, ads, base, filter_mode);
1868                 }
1869         }
1870         
1871         /* return the number of items in the list */
1872         return items;
1873 }
1874
1875 /* Summary track for DopeSheet/Action Editor 
1876  *      - return code is whether the summary lets the other channels get drawn
1877  */
1878 static short animdata_filter_dopesheet_summary (bAnimContext *ac, ListBase *anim_data, int filter_mode, int *items)
1879 {
1880         bDopeSheet *ads = NULL;
1881         
1882         /* get the DopeSheet information to use 
1883          *      - we should only need to deal with the DopeSheet/Action Editor, 
1884          *        since all the other Animation Editors won't have this concept
1885          *        being applicable.
1886          */
1887         if ((ac && ac->sa) && (ac->sa->spacetype == SPACE_ACTION)) {
1888                 SpaceAction *saction= (SpaceAction *)ac->sa->spacedata.first;
1889                 ads= &saction->ads;
1890         }
1891         else {
1892                 /* invalid space type - skip this summary channels */
1893                 return 1;
1894         }
1895         
1896         /* dopesheet summary 
1897          *      - only for drawing and/or selecting keyframes in channels, but not for real editing 
1898          *      - only useful for DopeSheet Editor, where the summary is useful
1899          */
1900         // TODO: we should really check if some other prohibited filters are also active, but that can be for later
1901         if ((filter_mode & ANIMFILTER_CHANNELS) && (ads->filterflag & ADS_FILTER_SUMMARY)) {
1902                 bAnimListElem *ale= make_new_animlistelem(ac, ANIMTYPE_SUMMARY, NULL, ANIMTYPE_NONE, NULL);
1903                 if (ale) {
1904                         BLI_addtail(anim_data, ale);
1905                         (*items)++;
1906                 }
1907                 
1908                 /* if summary is collapsed, don't show other channels beneath this 
1909                  *      - this check is put inside the summary check so that it doesn't interfere with normal operation
1910                  */ 
1911                 if (ads->flag & ADS_FLAG_SUMMARY_COLLAPSED)
1912                         return 0;
1913         }
1914         
1915         /* the other channels beneath this can be shown */
1916         return 1;
1917 }  
1918
1919 /* ----------- Public API --------------- */
1920
1921 /* This function filters the active data source to leave only animation channels suitable for
1922  * usage by the caller. It will return the length of the list 
1923  * 
1924  *      *anim_data: is a pointer to a ListBase, to which the filtered animation channels
1925  *              will be placed for use.
1926  *      filter_mode: how should the data be filtered - bitmapping accessed flags
1927  */
1928 int ANIM_animdata_filter (bAnimContext *ac, ListBase *anim_data, int filter_mode, void *data, short datatype)
1929 {
1930         int items = 0;
1931         
1932         /* only filter data if there's somewhere to put it */
1933         if (data && anim_data) {
1934                 bAnimListElem *ale, *next;
1935                 Object *obact= (ac) ? ac->obact : NULL;
1936                 
1937                 /* firstly filter the data */
1938                 switch (datatype) {
1939                         case ANIMCONT_ACTION:   /* 'Action Editor' */
1940                         {
1941                                 /* the check for the DopeSheet summary is included here since the summary works here too */
1942                                 if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items))
1943                                         items += animdata_filter_action(anim_data, NULL, data, filter_mode, NULL, ANIMTYPE_NONE, (ID *)obact);
1944                         }
1945                                 break;
1946                                 
1947                         case ANIMCONT_SHAPEKEY:
1948                         {
1949                                 //items= animdata_filter_shapekey(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE, (ID *)obact);
1950                         }
1951                                 break;
1952                                 
1953                         case ANIMCONT_GPENCIL:
1954                         {
1955                                 //items= animdata_filter_gpencil(anim_data, data, filter_mode);
1956                         }
1957                                 break;
1958                                 
1959                         case ANIMCONT_DOPESHEET: /* 'DopeSheet Editor' */
1960                         {
1961                                 /* the DopeSheet editor is the primary place where the DopeSheet summaries are useful */
1962                                 if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items))
1963                                         items += animdata_filter_dopesheet(anim_data, ac, data, filter_mode);
1964                         }
1965                                 break;
1966                                 
1967                         case ANIMCONT_FCURVES: /* Graph Editor -> FCurves/Animation Editing */
1968                         case ANIMCONT_DRIVERS: /* Graph Editor -> Drivers Editing */
1969                         case ANIMCONT_NLA: /* NLA Editor */
1970                         {
1971                                 /* all of these editors use the basic DopeSheet data for filtering options, but don't have all the same features */
1972                                 items = animdata_filter_dopesheet(anim_data, ac, data, filter_mode);
1973                         }
1974                                 break;
1975                 }
1976                         
1977                 /* remove any weedy entries */
1978                 // XXX this is weedy code!
1979                 for (ale= anim_data->first; ale; ale= next) {
1980                         next= ale->next;
1981                         
1982                         if (ale->type == ANIMTYPE_NONE) {
1983                                 items--;
1984                                 BLI_freelinkN(anim_data, ale);
1985                         }
1986                 }
1987         }
1988         
1989         /* return the number of items in the list */
1990         return items;
1991 }
1992
1993 /* ************************************************************ */