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