2bf433dab463be98f601ff4e8c392e5b3017c2be
[blender-staging.git] / source / blender / editors / animation / anim_filter.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Joshua Leung
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /* This file contains a system used to provide a layer of abstraction between sources
30  * of animation data and tools in Animation Editors. The method used here involves 
31  * generating a list of edit structures which enable tools to naively perform the actions 
32  * they require without all the boiler-plate associated with loops within loops and checking 
33  * for cases to ignore. 
34  *
35  * While this is primarily used for the Action/Dopesheet Editor (and its accessory modes),
36  * the IPO Editor also uses this for it's channel list and for determining which curves
37  * are being edited.
38  *
39  * Note: much of the original system this was based on was built before the creation of the RNA
40  * system. In future, it would be interesting to replace some parts of this code with RNA queries,
41  * however, RNA does not eliminate some of the boiler-plate reduction benefits presented by this 
42  * system, so if any such work does occur, it should only be used for the internals used here...
43  *
44  * -- Joshua Leung, Dec 2008
45  */
46
47 #include <string.h>
48 #include <stdio.h>
49
50 #include "DNA_listBase.h"
51 #include "DNA_ID.h"
52 #include "DNA_action_types.h"
53 #include "DNA_constraint_types.h"
54 #include "DNA_camera_types.h"
55 #include "DNA_curve_types.h"
56 #include "DNA_gpencil_types.h"
57 #include "DNA_ipo_types.h"
58 #include "DNA_lamp_types.h"
59 #include "DNA_lattice_types.h"
60 #include "DNA_key_types.h"
61 #include "DNA_material_types.h"
62 #include "DNA_mesh_types.h"
63 #include "DNA_object_types.h"
64 #include "DNA_space_types.h"
65 #include "DNA_scene_types.h"
66 #include "DNA_screen_types.h"
67 #include "DNA_windowmanager_types.h"
68
69 #include "MEM_guardedalloc.h"
70
71 #include "BLI_blenlib.h"
72
73 #include "BKE_context.h"
74 #include "BKE_global.h"
75 #include "BKE_key.h"
76 #include "BKE_object.h"
77 #include "BKE_material.h"
78 #include "BKE_screen.h"
79 #include "BKE_utildefines.h"
80
81 #include "ED_anim_api.h"
82 #include "ED_types.h"
83 #include "ED_util.h"
84
85 #include "WM_api.h"
86 #include "WM_types.h"
87
88 #include "BIF_gl.h"
89 #include "BIF_glutil.h"
90
91 #include "UI_interface.h"
92 #include "UI_resources.h"
93 #include "UI_view2d.h"
94
95 /* ************************************************************ */
96 /* Blender Context <-> Animation Context mapping */
97
98 /* ----------- Private Stuff - Action Editor ------------- */
99
100 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
101 /* Note: there's a similar function in key.c (ob_get_key) */
102 Key *actedit_get_shapekeys (bAnimContext *ac, SpaceAction *saction) 
103 {
104     Scene *scene= ac->scene;
105     Object *ob;
106     Key *key;
107         
108     ob = OBACT;
109     if (ob == NULL) 
110                 return NULL;
111         
112         /* XXX pinning is not available in 'ShapeKey' mode... */
113         //if (saction->pin) return NULL;
114         
115         /* shapekey data is stored with geometry data */
116         switch (ob->type) {
117                 case OB_MESH:
118                         key= ((Mesh *)ob->data)->key;
119                         break;
120                         
121                 case OB_LATTICE:
122                         key= ((Lattice *)ob->data)->key;
123                         break;
124                         
125                 case OB_CURVE:
126                 case OB_SURF:
127                         key= ((Curve *)ob->data)->key;
128                         break;
129                         
130                 default:
131                         return NULL;
132         }
133         
134         if (key) {
135                 if (key->type == KEY_RELATIVE)
136                         return key;
137         }
138         
139     return NULL;
140 }
141
142 /* Get data being edited in Action Editor (depending on current 'mode') */
143 static short actedit_get_context (bAnimContext *ac, SpaceAction *saction)
144 {
145         /* sync settings with current view status, then return appropriate data */
146         switch (saction->mode) {
147                 case SACTCONT_ACTION: /* 'Action Editor' */
148                         /* if not pinned, sync with active object */
149                         if (saction->pin == 0) {
150                                 if (ac->obact)
151                                         saction->action = ac->obact->action;
152                                 else
153                                         saction->action= NULL;
154                         }
155                         
156                         ac->datatype= ANIMCONT_ACTION;
157                         ac->data= saction->action;
158                         
159                         ac->mode= saction->mode;
160                         return 1;
161                         
162                 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
163                         ac->datatype= ANIMCONT_SHAPEKEY;
164                         ac->data= actedit_get_shapekeys(ac, saction);
165                         
166                         ac->mode= saction->mode;
167                         return 1;
168                         
169                 case SACTCONT_GPENCIL: /* Grease Pencil */ // XXX review how this mode is handled...
170                         ac->datatype=ANIMCONT_GPENCIL;
171                         //ac->data= CTX_wm_screen(C); // FIXME: add that dopesheet type thing here!
172                         ac->data= NULL; // !!!
173                         
174                         ac->mode= saction->mode;
175                         return 1;
176                         
177                 case SACTCONT_DOPESHEET: /* DopeSheet */
178                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
179                         saction->ads.source= (ID *)ac->scene;
180                         
181                         ac->datatype= ANIMCONT_DOPESHEET;
182                         ac->data= &saction->ads;
183                         
184                         ac->mode= saction->mode;
185                         return 1;
186                 
187                 default: /* unhandled yet */
188                         ac->datatype= ANIMCONT_NONE;
189                         ac->data= NULL;
190                         
191                         ac->mode= -1;
192                         return 0;
193         }
194 }
195
196 /* ----------- Private Stuff - IPO Editor ------------- */
197
198 /* Get data being edited in IPO Editor (depending on current 'mode') */
199 static short ipoedit_get_context (bAnimContext *ac, SpaceIpo *sipo)
200 {
201         // XXX FIXME...
202         return 0;
203 }
204
205 /* ----------- Public API --------------- */
206
207 /* Obtain current anim-data context, given that context info from Blender context has already been set 
208  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
209  *        allocation/freeing costs (which are not that avoidable with channels).
210  */
211 short ANIM_animdata_context_getdata (bAnimContext *ac)
212 {
213         ScrArea *sa= ac->sa;
214         short ok= 0;
215         
216         /* context depends on editor we are currently in */
217         if (sa) {
218                 switch (sa->spacetype) {
219                         case SPACE_ACTION:
220                         {
221                                 SpaceAction *saction= (SpaceAction *)sa->spacedata.first;
222                                 ok= actedit_get_context(ac, saction);
223                         }
224                                 break;
225                                 
226                         case SPACE_IPO:
227                         {
228                                 SpaceIpo *sipo= (SpaceIpo *)sa->spacedata.first;
229                                 ok= ipoedit_get_context(ac, sipo);
230                         }
231                                 break;
232                 }
233         }
234         
235         /* check if there's any valid data */
236         if (ok && ac->data)
237                 return 1;
238         else
239                 return 0;
240 }
241
242 /* Obtain current anim-data context from Blender Context info 
243  *      - AnimContext to write to is provided as pointer to var on stack so that we don't have
244  *        allocation/freeing costs (which are not that avoidable with channels).
245  *      - Clears data and sets the information from Blender Context which is useful
246  */
247 short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac)
248 {
249         ScrArea *sa= CTX_wm_area(C);
250         ARegion *ar= CTX_wm_region(C);
251         Scene *scene= CTX_data_scene(C);
252         
253         /* clear old context info */
254         if (ac == NULL) return 0;
255         memset(ac, 0, sizeof(bAnimContext));
256         
257         /* get useful default context settings from context */
258         ac->scene= scene;
259         ac->obact= (scene && scene->basact)?  scene->basact->object : NULL;
260         ac->sa= sa;
261         ac->ar= ar;
262         ac->spacetype= (sa) ? sa->spacetype : 0;
263         ac->regiontype= (ar) ? ar->regiontype : 0;
264         
265         /* get data context info */
266         return ANIM_animdata_context_getdata(ac);
267 }
268
269 /* ************************************************************ */
270 /* Blender Data <-- Filter --> Channels to be operated on */
271
272 /* ----------- 'Private' Stuff --------------- */
273
274 /* this function allocates memory for a new bAnimListElem struct for the 
275  * provided animation channel-data. 
276  */
277 bAnimListElem *make_new_animlistelem (void *data, short datatype, void *owner, short ownertype)
278 {
279         bAnimListElem *ale= NULL;
280         
281         /* only allocate memory if there is data to convert */
282         if (data) {
283                 /* allocate and set generic data */
284                 ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
285                 
286                 ale->data= data;
287                 ale->type= datatype;
288                 ale->owner= owner;
289                 ale->ownertype= ownertype;
290                 
291                 if ((owner) && (ownertype == ANIMTYPE_ACHAN)) {
292                         bActionChannel *ochan= (bActionChannel *)owner;
293                         ale->grp= ochan->grp;
294                 }
295                 else 
296                         ale->grp= NULL;
297                 
298                 /* do specifics */
299                 switch (datatype) {
300                         case ANIMTYPE_OBJECT:
301                         {
302                                 Base *base= (Base *)data;
303                                 Object *ob= base->object;
304                                 
305                                 ale->flag= ob->flag;
306                                 
307                                 ale->key_data= ob;
308                                 ale->datatype= ALE_OB;
309                         }
310                                 break;
311                         case ANIMTYPE_FILLACTD:
312                         {
313                                 bAction *act= (bAction *)data;
314                                 
315                                 ale->flag= act->flag;
316                                 
317                                 ale->key_data= act;
318                                 ale->datatype= ALE_ACT;
319                         }
320                                 break;
321                         case ANIMTYPE_FILLIPOD:
322                         {
323                                 Object *ob= (Object *)data;
324                                 
325                                 ale->flag= FILTER_IPO_OBJC(ob);
326                                 
327                                 ale->key_data= ob->ipo;
328                                 ale->datatype= ALE_IPO;
329                         }
330                                 break;
331                         case ANIMTYPE_FILLCOND:
332                         {
333                                 Object *ob= (Object *)data;
334                                 
335                                 ale->flag= FILTER_CON_OBJC(ob);
336                                 
337                                 ale->key_data= NULL;
338                                 ale->datatype= ALE_NONE;
339                         }
340                                 break;
341                         case ANIMTYPE_FILLMATD:
342                         {
343                                 Object *ob= (Object *)data;
344                                 
345                                 ale->flag= FILTER_MAT_OBJC(ob);
346                                 
347                                 ale->key_data= NULL;
348                                 ale->datatype= ALE_NONE;
349                         }
350                                 break;
351                         
352                         case ANIMTYPE_DSMAT:
353                         {
354                                 Material *ma= (Material *)data;
355                                 
356                                 ale->flag= FILTER_MAT_OBJD(ma);
357                                 
358                                 ale->key_data= ma->ipo;
359                                 ale->datatype= ALE_IPO;
360                         }
361                                 break;
362                         case ANIMTYPE_DSLAM:
363                         {
364                                 Lamp *la= (Lamp *)data;
365                                 
366                                 ale->flag= FILTER_LAM_OBJD(la);
367                                 
368                                 ale->key_data= la->ipo;
369                                 ale->datatype= ALE_IPO;
370                         }
371                                 break;
372                         case ANIMTYPE_DSCAM:
373                         {
374                                 Camera *ca= (Camera *)data;
375                                 
376                                 ale->flag= FILTER_CAM_OBJD(ca);
377                                 
378                                 ale->key_data= ca->ipo;
379                                 ale->datatype= ALE_IPO;
380                         }
381                                 break;
382                         case ANIMTYPE_DSCUR:
383                         {
384                                 Curve *cu= (Curve *)data;
385                                 
386                                 ale->flag= FILTER_CUR_OBJD(cu);
387                                 
388                                 ale->key_data= cu->ipo;
389                                 ale->datatype= ALE_IPO;
390                         }
391                                 break;
392                         case ANIMTYPE_DSSKEY:
393                         {
394                                 Key *key= (Key *)data;
395                                 
396                                 ale->flag= FILTER_SKE_OBJD(key);
397                                 
398                                 ale->key_data= key->ipo;
399                                 ale->datatype= ALE_IPO;
400                         }
401                                 break;
402                                 
403                         case ANIMTYPE_GROUP:
404                         {
405                                 bActionGroup *agrp= (bActionGroup *)data;
406                                 
407                                 ale->flag= agrp->flag;
408                                 
409                                 ale->key_data= NULL;
410                                 ale->datatype= ALE_GROUP;
411                         }
412                                 break;
413                         case ANIMTYPE_ACHAN:
414                         {
415                                 bActionChannel *achan= (bActionChannel *)data;
416                                 
417                                 ale->flag= achan->flag;
418                                 
419                                 if (achan->ipo) {
420                                         ale->key_data= achan->ipo;
421                                         ale->datatype= ALE_IPO;
422                                 }
423                                 else {
424                                         ale->key_data= NULL;
425                                         ale->datatype= ALE_NONE;
426                                 }
427                         }       
428                                 break;
429                         case ANIMTYPE_CONCHAN:
430                         case ANIMTYPE_CONCHAN2:
431                         {
432                                 bConstraintChannel *conchan= (bConstraintChannel *)data;
433                                 
434                                 ale->flag= conchan->flag;
435                                 
436                                 if (datatype == ANIMTYPE_CONCHAN2) {
437                                         /* CONCHAN2 is a hack so that constraint-channels keyframes can be edited */
438                                         if (conchan->ipo) {
439                                                 ale->key_data= conchan->ipo;
440                                                 ale->datatype= ALE_IPO;
441                                         }
442                                         else {
443                                                 ale->key_data= NULL;
444                                                 ale->datatype= ALE_NONE;
445                                         }
446                                 }
447                                 else {
448                                         if ((conchan->ipo) && (conchan->ipo->curve.first)) {
449                                                 /* we assume that constraint ipo blocks only have 1 curve:
450                                                  * INFLUENCE, so we pretend that a constraint channel is 
451                                                  * really just a Ipo-Curve channel instead.
452                                                  */
453                                                 ale->key_data= conchan->ipo->curve.first;
454                                                 ale->datatype= ALE_ICU;
455                                         }
456                                         else {
457                                                 ale->key_data= NULL;
458                                                 ale->datatype= ALE_NONE;
459                                         }
460                                 }
461                         }
462                                 break;
463                         case ANIMTYPE_ICU:
464                         {
465                                 IpoCurve *icu= (IpoCurve *)data;
466                                 
467                                 ale->flag= icu->flag;
468                                 
469                                 ale->key_data= icu;
470                                 ale->datatype= ALE_ICU;
471                         }
472                                 break;
473                         case ANIMTYPE_FILLIPO:
474                         case ANIMTYPE_FILLCON:
475                         {
476                                 bActionChannel *achan= (bActionChannel *)data;
477                                 
478                                 if (datatype == ANIMTYPE_FILLIPO)
479                                         ale->flag= FILTER_IPO_ACHAN(achan);
480                                 else
481                                         ale->flag= FILTER_CON_ACHAN(achan);
482                                         
483                                 ale->key_data= NULL;
484                                 ale->datatype= ALE_NONE;
485                         }
486                                 break;
487                         case ANIMTYPE_IPO:
488                         {
489                                 ale->flag= 0;
490                                 
491                                 ale->key_data= data;
492                                 ale->datatype= ALE_IPO;
493                         }
494                                 break;
495                         
496                         case ANIMTYPE_GPLAYER:
497                         {
498                                 bGPDlayer *gpl= (bGPDlayer *)data;
499                                 
500                                 ale->flag= gpl->flag;
501                                 
502                                 ale->key_data= NULL;
503                                 ale->datatype= ALE_GPFRAME;
504                         }
505                                 break;
506                 }
507         }
508         
509         /* return created datatype */
510         return ale;
511 }
512  
513 /* ----------------------------------------- */
514
515 // FIXME: use this...
516 static int animdata_filter_ipocurves (ListBase *anim_data, Ipo *ipo, int filter_mode, void *owner, short ownertype, ID *owner_id)
517 {
518         bAnimListElem *ale = NULL;
519         IpoCurve *icu;
520         int items = 0;
521         
522         /* loop over ipo curves - assume that the caller of this has already checked that these should be included */
523         for (icu= ipo->curve.first; icu; icu= icu->next) {
524                 /* only work with this channel and its subchannels if it is editable */
525                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_ICU(icu)) {
526                         /* only include this curve if selected or we are including all IPO-curves */
527                         if (!(filter_mode & ANIMFILTER_SEL) || (filter_mode & ANIMFILTER_ONLYFCU) || (SEL_ICU(icu))) {
528                                 /* owner/ownertype will be either object or action-channel, depending if it was dopesheet or part of an action */
529                                 ale= make_new_animlistelem(icu, ANIMTYPE_ICU, owner, ownertype);
530                                 
531                                 if (ale) {
532                                         /* ID will only be Object if data to write to directly belongs there, otherwise, another pointer will be used */
533                                         ale->id= owner_id;
534                                         BLI_addtail(anim_data, ale);
535                                         items++;
536                                 }
537                         }
538                 }
539         }
540         
541         /* return the number of items added to the list */
542         return items;
543 }
544
545 static int animdata_filter_actionchannel (ListBase *anim_data, bActionChannel *achan, int filter_mode, void *owner, short ownertype)
546 {
547         bAnimListElem *ale = NULL;
548         bConstraintChannel *conchan;
549         short owned= (owner && ownertype)? 1 : 0;
550         int items = 0;
551         
552         /* only work with this channel and its subchannels if it is visible */
553         if (!(filter_mode & ANIMFILTER_VISIBLE) || VISIBLE_ACHAN(achan)) {
554                 /* only work with this channel and its subchannels if it is editable */
555                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_ACHAN(achan)) {
556                         /* check if this achan should only be included if it is selected */
557                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_ACHAN(achan)) {
558                                 /* are we only interested in the ipo-curves? */
559                                 if ((filter_mode & ANIMFILTER_ONLYFCU)==0) {
560                                         ale= make_new_animlistelem(achan, ANIMTYPE_ACHAN, achan, ANIMTYPE_ACHAN);
561                                         
562                                         if (ale) {
563                                                 if (owned) ale->id= owner;
564                                                 BLI_addtail(anim_data, ale);
565                                                 items++;
566                                         }
567                                 }
568                         }
569                         else {
570                                 /* for insert key... this check could be improved */
571                                 //return;  // FIXME...
572                         }
573                         
574                         /* check if expanded - if not, continue on to next animion channel */
575                         if (EXPANDED_ACHAN(achan) == 0 && (filter_mode & ANIMFILTER_ONLYFCU)==0) {
576                                 /* only exit if we don't need to include constraint channels for group-channel keyframes */
577                                 if ( !(filter_mode & ANIMFILTER_IPOKEYS) || (achan->grp == NULL) || (EXPANDED_AGRP(achan->grp)==0) )
578                                         return items;
579                         }
580                                 
581                         /* ipo channels */
582                         if ((achan->ipo) && (filter_mode & ANIMFILTER_IPOKEYS)==0) {
583                                 /* include ipo-expand widget? */
584                                 if ((filter_mode & ANIMFILTER_CHANNELS) && (filter_mode & ANIMFILTER_ONLYFCU)==0) {
585                                         ale= make_new_animlistelem(achan, ANIMTYPE_FILLIPO, achan, ANIMTYPE_ACHAN);
586                                         
587                                         if (ale) {
588                                                 if (owned) ale->id= owner;
589                                                 BLI_addtail(anim_data, ale);
590                                                 items++;
591                                         }
592                                 }
593                                 
594                                 /* add ipo-curve channels? */
595                                 if (FILTER_IPO_ACHAN(achan) || (filter_mode & ANIMFILTER_ONLYFCU)) {
596                                         /* loop through ipo-curve channels, adding them */
597                                         items += animdata_filter_ipocurves(anim_data, achan->ipo, filter_mode, achan, ANIMTYPE_ACHAN, (owned)?(owner):(NULL));
598                                 }
599                         }
600                         
601                         /* constraint channels */
602                         if (achan->constraintChannels.first) {
603                                 /* include constraint-expand widget? */
604                                 if ( (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_ONLYFCU)
605                                          && !(filter_mode & ANIMFILTER_IPOKEYS) ) 
606                                 {
607                                         ale= make_new_animlistelem(achan, ANIMTYPE_FILLCON, achan, ANIMTYPE_ACHAN);
608                                         
609                                         if (ale) {
610                                                 if (owned) ale->id= owner;
611                                                 BLI_addtail(anim_data, ale);
612                                                 items++;
613                                         }
614                                 }
615                                 
616                                 /* add constraint channels? */
617                                 if (FILTER_CON_ACHAN(achan) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYFCU)) {
618                                         /* loop through constraint channels, checking and adding them */
619                                         for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next) {
620                                                 /* only work with this channel and its subchannels if it is editable */
621                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_CONCHAN(conchan)) {
622                                                         /* check if this conchan should only be included if it is selected */
623                                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_CONCHAN(conchan)) {
624                                                                 if (filter_mode & ANIMFILTER_IPOKEYS) {
625                                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN2, achan, ANIMTYPE_ACHAN);
626                                                                         
627                                                                         if (ale) {
628                                                                                 if (owned) ale->id= owner;
629                                                                                 BLI_addtail(anim_data, ale);
630                                                                                 items++;
631                                                                         }
632                                                                 }
633                                                                 else {
634                                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN, achan, ANIMTYPE_ACHAN);
635                                                                         
636                                                                         if (ale) {
637                                                                                 if (owned) ale->id= owner;
638                                                                                 BLI_addtail(anim_data, ale);
639                                                                                 items++;
640                                                                         }
641                                                                 }
642                                                         }
643                                                 }
644                                         }
645                                 }
646                         }
647                 }               
648         }
649         
650         /* return the number of items added to the list */
651         return items;
652 }
653
654 static int animdata_filter_action (ListBase *anim_data, bAction *act, int filter_mode, void *owner, short ownertype)
655 {
656         bAnimListElem *ale=NULL;
657         bActionGroup *agrp;
658         bActionChannel *achan, *lastchan=NULL;
659         short owned= (owner && ownertype) ? 1 : 0;
660         int items = 0;
661         
662         /* loop over groups */
663         for (agrp= act->groups.first; agrp; agrp= agrp->next) {
664                 /* add this group as a channel first */
665                 if (!(filter_mode & ANIMFILTER_ONLYFCU) && !(filter_mode & ANIMFILTER_IPOKEYS)) {
666                         /* check if filtering by selection */
667                         if ( !(filter_mode & ANIMFILTER_SEL) || SEL_AGRP(agrp) ) {
668                                 ale= make_new_animlistelem(agrp, ANIMTYPE_GROUP, NULL, ANIMTYPE_NONE);
669                                 if (ale) {
670                                         if (owned) ale->id= owner;
671                                         BLI_addtail(anim_data, ale);
672                                         items++;
673                                 }
674                         }
675                 }
676                 
677                 /* store reference to last channel of group */
678                 if (agrp->channels.last) 
679                         lastchan= agrp->channels.last;
680                 
681                 
682                 /* there are some situations, where only the channels of the animive group should get considered */
683                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
684                         /* filters here are a bit convoulted...
685                          *      - groups show a "summary" of keyframes beside their name which must accessable for tools which handle keyframes
686                          *      - groups can be collapsed (and those tools which are only interested in channels rely on knowing that group is closed)
687                          *
688                          * cases when we should include animion-channels and so-forth inside group:
689                          *      - we don't care about visibility
690                          *      - group is expanded
691                          *      - we're interested in keyframes, but not if they appear in selected channels
692                          */
693                         if ( (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_AGRP(agrp)) || 
694                                  ( ((filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYFCU)) && 
695                                    (!(filter_mode & ANIMFILTER_SEL) || (SEL_AGRP(agrp))) ) ) 
696                         {
697                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {                                       
698                                         for (achan= agrp->channels.first; achan && achan->grp==agrp; achan= achan->next) {
699                                                 items += animdata_filter_actionchannel(anim_data, achan, filter_mode, owner, ownertype);
700                                         }
701                                         
702                                         /* remove group from filtered list if last element is group 
703                                          * (i.e. only if group had channels, which were all hidden)
704                                          */
705                                         // XXX this is really hacky... it should be fixed in a much more elegant way!
706                                         if ( (ale) && (anim_data->last == ale) && 
707                                                  (ale->data == agrp) && (agrp->channels.first) ) 
708                                         {
709                                                 BLI_freelinkN(anim_data, ale);
710                                                 items--;
711                                         }
712                                 }
713                         }
714                 }
715         }
716         
717         /* loop over un-grouped animion channels (only if we're not only considering those channels in the animive group) */
718         if (!(filter_mode & ANIMFILTER_ACTGROUPED))  {
719                 for (achan=(lastchan)?(lastchan->next):(act->chanbase.first); achan; achan=achan->next) {
720                         items += animdata_filter_actionchannel(anim_data, achan, filter_mode, owner, ownertype);
721                 }
722         }
723         
724         /* return the number of items added to the list */
725         return items;
726 }
727
728 static int animdata_filter_shapekey (ListBase *anim_data, Key *key, int filter_mode, void *owner, short ownertype)
729 {
730         bAnimListElem *ale;
731         KeyBlock *kb;
732         IpoCurve *icu;
733         short owned= (owner && ownertype)? 1 : 0;
734         int i, items=0;
735         
736         /* are we filtering for display or editing */
737         if (filter_mode & ANIMFILTER_FORDRAWING) {
738                 /* for display - loop over shapekeys, adding ipo-curve references where needed */
739                 kb= key->block.first;
740                 
741                 /* loop through possible shapekeys, manually creating entries */
742                 for (i= 1; i < key->totkey; i++) {
743                         ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
744                         kb = kb->next; /* do this even on the first try, as the first is 'Basis' (which doesn't get included) */
745                         
746                         ale->data= kb;
747                         ale->type= ANIMTYPE_SHAPEKEY; /* 'abused' usage of this type */
748                         ale->owner= key;
749                         ale->ownertype= ANIMTYPE_SHAPEKEY;
750                         ale->datatype= ALE_NONE;
751                         ale->index = i;
752                         
753                         if (key->ipo) {
754                                 for (icu= key->ipo->curve.first; icu; icu=icu->next) {
755                                         if (icu->adrcode == i) {
756                                                 ale->key_data= icu;
757                                                 ale->datatype= ALE_ICU;
758                                                 break;
759                                         }
760                                 }
761                         }
762                         
763                         if (owned) ale->id= owner;
764                         
765                         BLI_addtail(anim_data, ale);
766                         items++;
767                 }
768         }
769         else {
770                 /* loop over ipo curves if present - for editing */
771                 if (key->ipo) {
772                         if (filter_mode & ANIMFILTER_IPOKEYS) {
773                                 ale= make_new_animlistelem(key->ipo, ANIMTYPE_IPO, key, ANIMTYPE_SHAPEKEY);
774                                 if (ale) {
775                                         if (owned) ale->id= owner;
776                                         BLI_addtail(anim_data, ale);
777                                         items++;
778                                 }
779                         }
780                         else {
781                                 items += animdata_filter_ipocurves(anim_data, key->ipo, filter_mode, key, ANIMTYPE_SHAPEKEY, (owned)?(owner):(NULL));
782                         }
783                 }
784         }
785         
786         /* return the number of items added to the list */
787         return items;
788 }
789  
790 #if 0
791 // FIXME: switch this to use the bDopeSheet...
792 static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter_mode)
793 {
794         bAnimListElem *ale;
795         ScrArea *sa, *curarea;
796         bGPdata *gpd;
797         bGPDlayer *gpl;
798         int items = 0;
799         
800         /* check if filtering types are appropriate */
801         if ( !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYFCU|ANIMFILTER_ACTGROUPED)) ) 
802         {
803                 /* special hack for fullscreen area (which must be this one then):
804                  *      - we use the curarea->full as screen to get spaces from, since the
805                  *        old (pre-fullscreen) screen was stored there...
806                  *      - this is needed as all data would otherwise disappear
807                  */
808                 // XXX need to get new alternative for curarea
809                 if ((curarea->full) && (curarea->spacetype==SPACE_ACTION))
810                         sc= curarea->full;
811                 
812                 /* loop over spaces in current screen, finding gpd blocks (could be slow!) */
813                 for (sa= sc->areabase.first; sa; sa= sa->next) {
814                         /* try to get gp data */
815                         // XXX need to put back grease pencil api...
816                         gpd= gpencil_data_getactive(sa);
817                         if (gpd == NULL) continue;
818                         
819                         /* add gpd as channel too (if for drawing, and it has layers) */
820                         if ((filter_mode & ANIMFILTER_FORDRAWING) && (gpd->layers.first)) {
821                                 /* add to list */
822                                 ale= make_new_animlistelem(gpd, ANIMTYPE_GPDATABLOCK, sa, ANIMTYPE_SPECIALDATA);
823                                 if (ale) {
824                                         BLI_addtail(anim_data, ale);
825                                         items++;
826                                 }
827                         }
828                         
829                         /* only add layers if they will be visible (if drawing channels) */
830                         if ( !(filter_mode & ANIMFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) {
831                                 /* loop over layers as the conditions are acceptable */
832                                 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
833                                         /* only if selected */
834                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_GPL(gpl)) {
835                                                 /* only if editable */
836                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
837                                                         /* add to list */
838                                                         ale= make_new_animlistelem(gpl, ANIMTYPE_GPLAYER, gpd, ANIMTYPE_GPDATABLOCK);
839                                                         if (ale) {
840                                                                 BLI_addtail(anim_data, ale);
841                                                                 items++;
842                                                         }
843                                                 }
844                                         }
845                                 }
846                         }
847                 }
848         }
849         
850         /* return the number of items added to the list */
851         return items;
852 }
853 #endif 
854
855 static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
856 {
857         bAnimListElem *ale=NULL;
858         Object *ob= base->object;
859         int items = 0;
860         
861         /* include materials-expand widget? */
862         if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYFCU))) {
863                 ale= make_new_animlistelem(ob, ANIMTYPE_FILLMATD, base, ANIMTYPE_OBJECT);
864                 if (ale) {
865                         BLI_addtail(anim_data, ale);
866                         items++;
867                 }
868         }
869         
870         /* add materials? */
871         if (FILTER_MAT_OBJC(ob) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYFCU)) {
872                 short a;
873                 
874                 /* for each material, either add channels separately, or as ipo-block */
875                 for (a=0; a<ob->totcol; a++) {
876                         Material *ma= give_current_material(ob, a);
877                         
878                         /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
879                         if (ELEM(NULL, ma, ma->ipo)) continue;
880                         
881                         /* include material-expand widget? */
882                         // hmm... do we need to store the index of this material in the array anywhere?
883                         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
884                                 ale= make_new_animlistelem(ma, ANIMTYPE_DSMAT, base, ANIMTYPE_OBJECT);
885                                 if (ale) {
886                                         BLI_addtail(anim_data, ale);
887                                         items++;
888                                 }
889                         }
890                         
891                         /* add material's ipo-curve channels? */
892                         if ( (FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_ONLYFCU)) && 
893                                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
894                         {
895                                 items += animdata_filter_ipocurves(anim_data, ma->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)ma);
896                         }
897                 }
898
899         }
900         
901         /* return the number of items added to the list */
902         return items;
903 }
904
905 static int animdata_filter_dopesheet_cam (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
906 {
907         bAnimListElem *ale=NULL;
908         Object *ob= base->object;
909         Camera *ca= (Camera *)ob->data;
910         int items = 0;
911         
912         /* include camera-expand widget? */
913         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
914                 ale= make_new_animlistelem(ca, ANIMTYPE_DSCAM, base, ANIMTYPE_OBJECT);
915                 if (ale) {
916                         BLI_addtail(anim_data, ale);
917                         items++;
918                 }
919         }
920         
921         /* add camera ipo-curve channels? */
922         if ( (FILTER_CAM_OBJD(ca) || (filter_mode & ANIMFILTER_ONLYFCU)) && 
923                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
924         {
925                 items += animdata_filter_ipocurves(anim_data, ca->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)ca);
926         }
927         
928         /* return the number of items added to the list */
929         return items;
930 }
931
932 static int animdata_filter_dopesheet_lamp (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
933 {
934         bAnimListElem *ale=NULL;
935         Object *ob= base->object;
936         Lamp *la= (Lamp *)ob->data;
937         int items = 0;
938         
939         /* include lamp-expand widget? */
940         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
941                 ale= make_new_animlistelem(la, ANIMTYPE_DSLAM, base, ANIMTYPE_OBJECT);
942                 if (ale) {
943                         BLI_addtail(anim_data, ale);
944                         items++;
945                 }
946         }
947         
948         /* add lamp ipo-curve channels? */
949         if ( (FILTER_LAM_OBJD(la) || (filter_mode & ANIMFILTER_ONLYFCU)) && 
950                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
951         {
952                 items += animdata_filter_ipocurves(anim_data, la->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)la);
953         }
954         
955         /* return the number of items added to the list */
956         return items;
957 }
958
959 static int animdata_filter_dopesheet_curve (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
960 {
961         bAnimListElem *ale=NULL;
962         Object *ob= base->object;
963         Curve *cu= (Curve *)ob->data;
964         int items = 0;
965         
966         /* include curve-expand widget? */
967         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
968                 ale= make_new_animlistelem(cu, ANIMTYPE_DSCUR, base, ANIMTYPE_OBJECT);
969                 if (ale) {
970                         BLI_addtail(anim_data, ale);
971                         items++;
972                 }
973         }
974         
975         /* add curve ipo-curve channels? */
976         if ( (FILTER_CUR_OBJD(cu) || (filter_mode & ANIMFILTER_ONLYFCU)) && 
977                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
978         {
979                 items += animdata_filter_ipocurves(anim_data, cu->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)cu);
980         }
981         
982         /* return the number of items added to the list */
983         return items;
984 }
985
986 static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
987 {
988         bAnimListElem *ale=NULL;
989         Scene *sce= (Scene *)ads->source;
990         Object *ob= base->object;
991         Key *key= ob_get_key(ob);
992         int items = 0;
993         
994         /* add this object as a channel first */
995         if (!(filter_mode & ANIMFILTER_ONLYFCU) && !(filter_mode & ANIMFILTER_IPOKEYS)) {
996                 /* check if filtering by selection */
997                 if ( !(filter_mode & ANIMFILTER_SEL) || ((base->flag & SELECT) || (base == sce->basact)) ) {
998                         ale= make_new_animlistelem(base, ANIMTYPE_OBJECT, NULL, ANIMTYPE_NONE);
999                         if (ale) {
1000                                 BLI_addtail(anim_data, ale);
1001                                 items++;
1002                         }
1003                 }
1004         }
1005         
1006         /* if collapsed, don't go any further (unless adding keyframes only) */
1007         if ( (EXPANDED_OBJC(ob) == 0) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYFCU)) )
1008                 return items;
1009         
1010         /* IPO? */
1011         if ((ob->ipo) && !(ads->filterflag & ADS_FILTER_NOIPOS)) {              
1012                 /* include ipo-expand widget? */
1013                 if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
1014                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLIPOD, base, ANIMTYPE_OBJECT);
1015                         if (ale) {
1016                                 BLI_addtail(anim_data, ale);
1017                                 items++;
1018                         }
1019                 }
1020                 
1021                 /* add ipo-curve channels? */
1022                 if ( (FILTER_IPO_OBJC(ob) || (filter_mode & ANIMFILTER_ONLYFCU)) && 
1023                           !(filter_mode & ANIMFILTER_IPOKEYS) ) 
1024                 {
1025                         items += animdata_filter_ipocurves(anim_data, ob->ipo, filter_mode, base, ANIMTYPE_OBJECT, NULL); // err... why not set ob?
1026                 }
1027         }
1028         
1029         /* Action? */
1030         if ((ob->action) && !(ads->filterflag & ADS_FILTER_NOACTS)) {
1031                 /* include animion-expand widget? */
1032                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYFCU))) {
1033                         ale= make_new_animlistelem(ob->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT);
1034                         if (ale) {
1035                                 ale->id= (ID *)ob; // err.... is this a good idea?
1036                                 BLI_addtail(anim_data, ale);
1037                                 items++;
1038                         }
1039                 }
1040                 
1041                 /* add ipo-curve channels? */
1042                 if (EXPANDED_ACTC(ob->action) || !(filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_FORDRAWING))) {
1043                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1044                         items += animdata_filter_action(anim_data, ob->action, filter_mode, ob, ANIMTYPE_OBJECT); 
1045                 }
1046         }
1047         
1048         /* ShapeKeys? */
1049         if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
1050                 /* include shapekey-expand widget? */
1051                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYFCU))) {
1052                         ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT);
1053                         if (ale) {
1054                                 BLI_addtail(anim_data, ale);
1055                                 items++;
1056                         }
1057                 }
1058                 
1059                 /* add channels */
1060                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYFCU)) {
1061                         items += animdata_filter_shapekey(anim_data, key, filter_mode, ob, ANIMTYPE_OBJECT);
1062                 }
1063         }
1064         
1065         /* Materials? */
1066         if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
1067                 items += animdata_filter_dopesheet_mats(anim_data, ads, base, filter_mode);
1068         
1069         /* Object Data */
1070         switch (ob->type) {
1071                 case OB_CAMERA: /* ------- Camera ------------ */
1072                 {
1073                         Camera *ca= (Camera *)ob->data;
1074                         if ((ca->ipo) && !(ads->filterflag & ADS_FILTER_NOCAM))
1075                                 items += animdata_filter_dopesheet_cam(anim_data, ads, base, filter_mode);
1076                 }
1077                         break;
1078                 case OB_LAMP: /* ---------- Lamp ----------- */
1079                 {
1080                         Lamp *la= (Lamp *)ob->data;
1081                         if ((la->ipo) && !(ads->filterflag & ADS_FILTER_NOLAM))
1082                                 items += animdata_filter_dopesheet_lamp(anim_data, ads, base, filter_mode);
1083                 }
1084                         break;
1085                 case OB_CURVE: /* ------- Curve ---------- */
1086                 {
1087                         Curve *cu= (Curve *)ob->data;
1088                         if ((cu->ipo) && !(ads->filterflag & ADS_FILTER_NOCUR))
1089                                 items += animdata_filter_dopesheet_curve(anim_data, ads, base, filter_mode);
1090                 }
1091                         break;
1092         }
1093         
1094         /* Constraint Channels? */
1095         if ((ob->constraintChannels.first) && !(ads->filterflag & ADS_FILTER_NOCONSTRAINTS)) {
1096                 bConstraintChannel *conchan;
1097                 
1098                 /* include constraint-expand widget? */
1099                 if ( (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_ONLYFCU)
1100                          && !(filter_mode & ANIMFILTER_IPOKEYS) ) 
1101                 {
1102                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLCOND, base, ANIMTYPE_OBJECT);
1103                         if (ale) {
1104                                 BLI_addtail(anim_data, ale);
1105                                 items++;
1106                         }
1107                 }
1108                 
1109                 /* add constraint channels? */
1110                 if (FILTER_CON_OBJC(ob) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYFCU)) {
1111                         /* loop through constraint channels, checking and adding them */
1112                         for (conchan=ob->constraintChannels.first; conchan; conchan=conchan->next) {
1113                                 /* only work with this channel and its subchannels if it is editable */
1114                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_CONCHAN(conchan)) {
1115                                         /* check if this conchan should only be included if it is selected */
1116                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_CONCHAN(conchan)) {
1117                                                 if (filter_mode & ANIMFILTER_IPOKEYS) {
1118                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN2, base, ANIMTYPE_OBJECT);
1119                                                         if (ale) {
1120                                                                 ale->id= (ID *)ob;
1121                                                                 BLI_addtail(anim_data, ale);
1122                                                                 items++;
1123                                                         }
1124                                                 }
1125                                                 else {
1126                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN, base, ANIMTYPE_OBJECT);
1127                                                         if (ale) {
1128                                                                 ale->id= (ID *)ob;
1129                                                                 BLI_addtail(anim_data, ale);
1130                                                                 items++;
1131                                                         }
1132                                                 }
1133                                         }
1134                                 }
1135                         }
1136                 }
1137         }
1138         
1139         /* return the number of items added to the list */
1140         return items;
1141 }       
1142
1143 // 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)
1144 static int animdata_filter_dopesheet (ListBase *anim_data, bDopeSheet *ads, int filter_mode)
1145 {
1146         Scene *sce= (Scene *)ads->source;
1147         Base *base;
1148         int items = 0;
1149         
1150         /* check that we do indeed have a scene */
1151         if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
1152                 printf("DopeSheet Error: Not scene! \n");
1153                 return 0;
1154         }
1155         
1156         /* loop over all bases in the scene */
1157         for (base= sce->base.first; base; base= base->next) {
1158                 /* check if there's an object (all the relevant checks are done in the ob-function) */
1159                 if (base->object) {
1160                         Object *ob= base->object;
1161                         Key *key= ob_get_key(ob);
1162                         short ipoOk, actOk, constsOk, keyOk, dataOk;
1163                         
1164                         /* firstly, check if object can be included, by the following fanimors:
1165                          *      - if only visible, must check for layer and also viewport visibility
1166                          *      - if only selected, must check if object is selected 
1167                          *      - there must be animation data to edit
1168                          */
1169                         // TODO: if cache is implemented, just check name here, and then 
1170                         if (filter_mode & ANIMFILTER_VISIBLE) {
1171                                 /* layer visibility */
1172                                 if ((ob->lay & sce->lay)==0) continue;
1173                                 
1174                                 /* outliner restrict-flag */
1175                                 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1176                         }
1177                         
1178                         /* additionally, dopesheet filtering also affects what objects to consider */
1179                         if (ads->filterflag) {
1180                                 /* check selection and object type filters */
1181                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) || (base == sce->basact)) )  {
1182                                         /* only selected should be shown */
1183                                         continue;
1184                                 }
1185                                 if ((ads->filterflag & ADS_FILTER_NOARM) && (ob->type == OB_ARMATURE)) {
1186                                         /* not showing armatures  */
1187                                         continue;
1188                                 }
1189                                 if ((ads->filterflag & ADS_FILTER_NOOBJ) && (ob->type != OB_ARMATURE)) {
1190                                         /* not showing objects that aren't armatures */
1191                                         continue;
1192                                 }
1193                                 
1194                                 /* check filters for datatypes */
1195                                 ipoOk= ((ob->ipo) && !(ads->filterflag & ADS_FILTER_NOIPOS));
1196                                 actOk= ((ob->action) && !(ads->filterflag & ADS_FILTER_NOACTS));
1197                                 constsOk= ((ob->constraintChannels.first) && !(ads->filterflag & ADS_FILTER_NOCONSTRAINTS));
1198                                 keyOk= ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS));
1199                                 
1200                                 switch (ob->type) {
1201                                         case OB_CAMERA: /* ------- Camera ------------ */
1202                                         {
1203                                                 Camera *ca= (Camera *)ob->data;
1204                                                 dataOk= ((ca->ipo) && !(ads->filterflag & ADS_FILTER_NOCAM));                                           
1205                                         }
1206                                                 break;
1207                                         case OB_LAMP: /* ---------- Lamp ----------- */
1208                                         {
1209                                                 Lamp *la= (Lamp *)ob->data;
1210                                                 dataOk= ((la->ipo) && !(ads->filterflag & ADS_FILTER_NOLAM));
1211                                         }
1212                                                 break;
1213                                         case OB_CURVE: /* -------- Curve ---------- */
1214                                         {
1215                                                 Curve *cu= (Curve *)ob->data;
1216                                                 dataOk= ((cu->ipo) && !(ads->filterflag & ADS_FILTER_NOCUR));
1217                                         }
1218                                                 break;
1219                                         default: /* --- other --- */
1220                                                 dataOk= 0;
1221                                                 break;
1222                                 }
1223                                 
1224                                 /* check if all bad (i.e. nothing to show) */
1225                                 if (!ipoOk && !actOk && !constsOk && !keyOk && !dataOk)
1226                                         continue;
1227                         }
1228                         else {
1229                                 /* check data-types */
1230                                 ipoOk= (ob->ipo != NULL);
1231                                 actOk= (ob->action != NULL);
1232                                 constsOk= (ob->constraintChannels.first != NULL);
1233                                 keyOk= (key != NULL);
1234                                 
1235                                 switch (ob->type) {
1236                                         case OB_CAMERA: /* ------- Camera ------------ */
1237                                         {
1238                                                 Camera *ca= (Camera *)ob->data;
1239                                                 dataOk= (ca->ipo != NULL);                                              
1240                                         }
1241                                                 break;
1242                                         case OB_LAMP: /* ---------- Lamp ----------- */
1243                                         {
1244                                                 Lamp *la= (Lamp *)ob->data;
1245                                                 dataOk= (la->ipo != NULL);
1246                                         }
1247                                                 break;
1248                                         case OB_CURVE: /* -------- Curve ---------- */
1249                                         {
1250                                                 Curve *cu= (Curve *)ob->data;
1251                                                 dataOk= (cu->ipo != NULL);
1252                                         }
1253                                                 break;
1254                                         default: /* --- other --- */
1255                                                 dataOk= 0;
1256                                                 break;
1257                                 }
1258                                 
1259                                 /* check if all bad (i.e. nothing to show) */
1260                                 if (!ipoOk && !actOk && !constsOk && !keyOk && !dataOk)
1261                                         continue;
1262                         }
1263                         
1264                         /* since we're still here, this object should be usable */
1265                         items += animdata_filter_dopesheet_ob(anim_data, ads, base, filter_mode);
1266                 }
1267         }
1268         
1269         /* return the number of items in the list */
1270         return items;
1271 }
1272
1273 /* ----------- Public API --------------- */
1274
1275 /* This function filters the active data source to leave only animation channels suitable for
1276  * usage by the caller. It will return the length of the list 
1277  * 
1278  *      *act_data: is a pointer to a ListBase, to which the filtered animation channels
1279  *              will be placed for use.
1280  *      filter_mode: how should the data be filtered - bitmapping accessed flags
1281  */
1282 int ANIM_animdata_filter (ListBase *anim_data, int filter_mode, void *data, short datatype)
1283 {
1284         int items = 0;
1285         
1286         /* only filter data if there's somewhere to put it */
1287         if (data && anim_data) {
1288                 bAnimListElem *ale, *next;
1289                 
1290                 /* firstly filter the data */
1291                 switch (datatype) {
1292                         case ANIMCONT_ACTION:
1293                                 items= animdata_filter_action(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE);
1294                                 break;
1295                         case ANIMCONT_SHAPEKEY:
1296                                 items= animdata_filter_shapekey(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE);
1297                                 break;
1298                         case ANIMCONT_GPENCIL:
1299                                 //items= animdata_filter_gpencil(anim_data, data, filter_mode);
1300                                 break;
1301                         case ANIMCONT_DOPESHEET:
1302                                 items= animdata_filter_dopesheet(anim_data, data, filter_mode);
1303                                 break;
1304                                 
1305                         case ANIMCONT_IPO:
1306                                 // FIXME: this will be used for showing a single IPO-block (not too useful from animator perspective though!)
1307                                 //items= 0;
1308                                 break;
1309                 }
1310                         
1311                 /* remove any weedy entries */
1312                 // XXX this is weedy code!
1313                 for (ale= anim_data->first; ale; ale= next) {
1314                         next= ale->next;
1315                         
1316                         if (ale->type == ANIMTYPE_NONE) {
1317                                 items--;
1318                                 BLI_freelinkN(anim_data, ale);
1319                         }
1320                         
1321                         if (filter_mode & ANIMFILTER_IPOKEYS) {
1322                                 if (ale->datatype != ALE_IPO) {
1323                                         items--;
1324                                         BLI_freelinkN(anim_data, ale);
1325                                 }
1326                                 else if (ale->key_data == NULL) {
1327                                         items--;
1328                                         BLI_freelinkN(anim_data, ale);
1329                                 }
1330                         }
1331                 }
1332         }
1333         
1334         /* return the number of items in the list */
1335         return items;
1336 }
1337
1338 /* ************************************************************ */