2.5 - Action Editor: IPO Curve Protect works now
[blender.git] / source / blender / editors / animation / anim_filter.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 Blender Foundation.
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_ONLYICU) || (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         IpoCurve *icu;
550         short owned= (owner && ownertype)? 1 : 0;
551         int items = 0;
552         
553         /* only work with this channel and its subchannels if it is visible */
554         if (!(filter_mode & ANIMFILTER_VISIBLE) || VISIBLE_ACHAN(achan)) {
555                 /* only work with this channel and its subchannels if it is editable */
556                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_ACHAN(achan)) {
557                         /* check if this achan should only be included if it is selected */
558                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_ACHAN(achan)) {
559                                 /* are we only interested in the ipo-curves? */
560                                 if ((filter_mode & ANIMFILTER_ONLYICU)==0) {
561                                         ale= make_new_animlistelem(achan, ANIMTYPE_ACHAN, achan, ANIMTYPE_ACHAN);
562                                         
563                                         if (ale) {
564                                                 if (owned) ale->id= owner;
565                                                 BLI_addtail(anim_data, ale);
566                                                 items++;
567                                         }
568                                 }
569                         }
570                         else {
571                                 /* for insert key... this check could be improved */
572                                 //return;  // FIXME...
573                         }
574                         
575                         /* check if expanded - if not, continue on to next animion channel */
576                         if (EXPANDED_ACHAN(achan) == 0 && (filter_mode & ANIMFILTER_ONLYICU)==0) {
577                                 /* only exit if we don't need to include constraint channels for group-channel keyframes */
578                                 if ( !(filter_mode & ANIMFILTER_IPOKEYS) || (achan->grp == NULL) || (EXPANDED_AGRP(achan->grp)==0) )
579                                         return items;
580                         }
581                                 
582                         /* ipo channels */
583                         if ((achan->ipo) && (filter_mode & ANIMFILTER_IPOKEYS)==0) {
584                                 /* include ipo-expand widget? */
585                                 if ((filter_mode & ANIMFILTER_CHANNELS) && (filter_mode & ANIMFILTER_ONLYICU)==0) {
586                                         ale= make_new_animlistelem(achan, ANIMTYPE_FILLIPO, achan, ANIMTYPE_ACHAN);
587                                         
588                                         if (ale) {
589                                                 if (owned) ale->id= owner;
590                                                 BLI_addtail(anim_data, ale);
591                                                 items++;
592                                         }
593                                 }
594                                 
595                                 /* add ipo-curve channels? */
596                                 if (FILTER_IPO_ACHAN(achan) || (filter_mode & ANIMFILTER_ONLYICU)) {
597                                         /* loop through ipo-curve channels, adding them */
598                                         items += animdata_filter_ipocurves(anim_data, achan->ipo, filter_mode, achan, ANIMTYPE_ACHAN, (owned)?(owner):(NULL));
599                                 }
600                         }
601                         
602                         /* constraint channels */
603                         if (achan->constraintChannels.first) {
604                                 /* include constraint-expand widget? */
605                                 if ( (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_ONLYICU)
606                                          && !(filter_mode & ANIMFILTER_IPOKEYS) ) 
607                                 {
608                                         ale= make_new_animlistelem(achan, ANIMTYPE_FILLCON, achan, ANIMTYPE_ACHAN);
609                                         
610                                         if (ale) {
611                                                 if (owned) ale->id= owner;
612                                                 BLI_addtail(anim_data, ale);
613                                                 items++;
614                                         }
615                                 }
616                                 
617                                 /* add constraint channels? */
618                                 if (FILTER_CON_ACHAN(achan) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
619                                         /* loop through constraint channels, checking and adding them */
620                                         for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next) {
621                                                 /* only work with this channel and its subchannels if it is editable */
622                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_CONCHAN(conchan)) {
623                                                         /* check if this conchan should only be included if it is selected */
624                                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_CONCHAN(conchan)) {
625                                                                 if (filter_mode & ANIMFILTER_IPOKEYS) {
626                                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN2, achan, ANIMTYPE_ACHAN);
627                                                                         
628                                                                         if (ale) {
629                                                                                 if (owned) ale->id= owner;
630                                                                                 BLI_addtail(anim_data, ale);
631                                                                                 items++;
632                                                                         }
633                                                                 }
634                                                                 else {
635                                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN, achan, ANIMTYPE_ACHAN);
636                                                                         
637                                                                         if (ale) {
638                                                                                 if (owned) ale->id= owner;
639                                                                                 BLI_addtail(anim_data, ale);
640                                                                                 items++;
641                                                                         }
642                                                                 }
643                                                         }
644                                                 }
645                                         }
646                                 }
647                         }
648                 }               
649         }
650         
651         /* return the number of items added to the list */
652         return items;
653 }
654
655 static int animdata_filter_action (ListBase *anim_data, bAction *act, int filter_mode, void *owner, short ownertype)
656 {
657         bAnimListElem *ale=NULL;
658         bActionGroup *agrp;
659         bActionChannel *achan, *lastchan=NULL;
660         short owned= (owner && ownertype) ? 1 : 0;
661         int items = 0;
662         
663         /* loop over groups */
664         for (agrp= act->groups.first; agrp; agrp= agrp->next) {
665                 /* add this group as a channel first */
666                 if (!(filter_mode & ANIMFILTER_ONLYICU) && !(filter_mode & ANIMFILTER_IPOKEYS)) {
667                         /* check if filtering by selection */
668                         if ( !(filter_mode & ANIMFILTER_SEL) || SEL_AGRP(agrp) ) {
669                                 ale= make_new_animlistelem(agrp, ANIMTYPE_GROUP, NULL, ANIMTYPE_NONE);
670                                 if (ale) {
671                                         if (owned) ale->id= owner;
672                                         BLI_addtail(anim_data, ale);
673                                         items++;
674                                 }
675                         }
676                 }
677                 
678                 /* store reference to last channel of group */
679                 if (agrp->channels.last) 
680                         lastchan= agrp->channels.last;
681                 
682                 
683                 /* there are some situations, where only the channels of the animive group should get considered */
684                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
685                         /* filters here are a bit convoulted...
686                          *      - groups show a "summary" of keyframes beside their name which must accessable for tools which handle keyframes
687                          *      - groups can be collapsed (and those tools which are only interested in channels rely on knowing that group is closed)
688                          *
689                          * cases when we should include animion-channels and so-forth inside group:
690                          *      - we don't care about visibility
691                          *      - group is expanded
692                          *      - we're interested in keyframes, but not if they appear in selected channels
693                          */
694                         if ( (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_AGRP(agrp)) || 
695                                  ( ((filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) && 
696                                    (!(filter_mode & ANIMFILTER_SEL) || (SEL_AGRP(agrp))) ) ) 
697                         {
698                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {                                       
699                                         for (achan= agrp->channels.first; achan && achan->grp==agrp; achan= achan->next) {
700                                                 items += animdata_filter_actionchannel(anim_data, achan, filter_mode, owner, ownertype);
701                                         }
702                                         
703                                         /* remove group from filtered list if last element is group 
704                                          * (i.e. only if group had channels, which were all hidden)
705                                          */
706                                         // XXX this is really hacky... it should be fixed in a much more elegant way!
707                                         if ( (ale) && (anim_data->last == ale) && 
708                                                  (ale->data == agrp) && (agrp->channels.first) ) 
709                                         {
710                                                 BLI_freelinkN(anim_data, ale);
711                                                 items--;
712                                         }
713                                 }
714                         }
715                 }
716         }
717         
718         /* loop over un-grouped animion channels (only if we're not only considering those channels in the animive group) */
719         if (!(filter_mode & ANIMFILTER_ACTGROUPED))  {
720                 for (achan=(lastchan)?(lastchan->next):(act->chanbase.first); achan; achan=achan->next) {
721                         items += animdata_filter_actionchannel(anim_data, achan, filter_mode, owner, ownertype);
722                 }
723         }
724         
725         /* return the number of items added to the list */
726         return items;
727 }
728
729 static int animdata_filter_shapekey (ListBase *anim_data, Key *key, int filter_mode, void *owner, short ownertype)
730 {
731         bAnimListElem *ale;
732         KeyBlock *kb;
733         IpoCurve *icu;
734         short owned= (owner && ownertype)? 1 : 0;
735         int i, items=0;
736         
737         /* are we filtering for display or editing */
738         if (filter_mode & ANIMFILTER_FORDRAWING) {
739                 /* for display - loop over shapekeys, adding ipo-curve references where needed */
740                 kb= key->block.first;
741                 
742                 /* loop through possible shapekeys, manually creating entries */
743                 for (i= 1; i < key->totkey; i++) {
744                         ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
745                         kb = kb->next; /* do this even on the first try, as the first is 'Basis' (which doesn't get included) */
746                         
747                         ale->data= kb;
748                         ale->type= ANIMTYPE_SHAPEKEY; /* 'abused' usage of this type */
749                         ale->owner= key;
750                         ale->ownertype= ANIMTYPE_SHAPEKEY;
751                         ale->datatype= ALE_NONE;
752                         ale->index = i;
753                         
754                         if (key->ipo) {
755                                 for (icu= key->ipo->curve.first; icu; icu=icu->next) {
756                                         if (icu->adrcode == i) {
757                                                 ale->key_data= icu;
758                                                 ale->datatype= ALE_ICU;
759                                                 break;
760                                         }
761                                 }
762                         }
763                         
764                         if (owned) ale->id= owner;
765                         
766                         BLI_addtail(anim_data, ale);
767                         items++;
768                 }
769         }
770         else {
771                 /* loop over ipo curves if present - for editing */
772                 if (key->ipo) {
773                         if (filter_mode & ANIMFILTER_IPOKEYS) {
774                                 ale= make_new_animlistelem(key->ipo, ANIMTYPE_IPO, key, ANIMTYPE_SHAPEKEY);
775                                 if (ale) {
776                                         if (owned) ale->id= owner;
777                                         BLI_addtail(anim_data, ale);
778                                         items++;
779                                 }
780                         }
781                         else {
782                                 items += animdata_filter_ipocurves(anim_data, key->ipo, filter_mode, key, ANIMTYPE_SHAPEKEY, (owned)?(owner):(NULL));
783                         }
784                 }
785         }
786         
787         /* return the number of items added to the list */
788         return items;
789 }
790  
791 #if 0
792 // FIXME: switch this to use the bDopeSheet...
793 static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter_mode)
794 {
795         bAnimListElem *ale;
796         ScrArea *sa, *curarea;
797         bGPdata *gpd;
798         bGPDlayer *gpl;
799         int items = 0;
800         
801         /* check if filtering types are appropriate */
802         if ( !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU|ANIMFILTER_ACTGROUPED)) ) 
803         {
804                 /* special hack for fullscreen area (which must be this one then):
805                  *      - we use the curarea->full as screen to get spaces from, since the
806                  *        old (pre-fullscreen) screen was stored there...
807                  *      - this is needed as all data would otherwise disappear
808                  */
809                 // XXX need to get new alternative for curarea
810                 if ((curarea->full) && (curarea->spacetype==SPACE_ACTION))
811                         sc= curarea->full;
812                 
813                 /* loop over spaces in current screen, finding gpd blocks (could be slow!) */
814                 for (sa= sc->areabase.first; sa; sa= sa->next) {
815                         /* try to get gp data */
816                         // XXX need to put back grease pencil api...
817                         gpd= gpencil_data_getactive(sa);
818                         if (gpd == NULL) continue;
819                         
820                         /* add gpd as channel too (if for drawing, and it has layers) */
821                         if ((filter_mode & ANIMFILTER_FORDRAWING) && (gpd->layers.first)) {
822                                 /* add to list */
823                                 ale= make_new_animlistelem(gpd, ANIMTYPE_GPDATABLOCK, sa, ANIMTYPE_SPECIALDATA);
824                                 if (ale) {
825                                         BLI_addtail(anim_data, ale);
826                                         items++;
827                                 }
828                         }
829                         
830                         /* only add layers if they will be visible (if drawing channels) */
831                         if ( !(filter_mode & ANIMFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) {
832                                 /* loop over layers as the conditions are acceptable */
833                                 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
834                                         /* only if selected */
835                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_GPL(gpl)) {
836                                                 /* only if editable */
837                                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
838                                                         /* add to list */
839                                                         ale= make_new_animlistelem(gpl, ANIMTYPE_GPLAYER, gpd, ANIMTYPE_GPDATABLOCK);
840                                                         if (ale) {
841                                                                 BLI_addtail(anim_data, ale);
842                                                                 items++;
843                                                         }
844                                                 }
845                                         }
846                                 }
847                         }
848                 }
849         }
850         
851         /* return the number of items added to the list */
852         return items;
853 }
854 #endif 
855
856 static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
857 {
858         bAnimListElem *ale=NULL;
859         Object *ob= base->object;
860         IpoCurve *icu;
861         int items = 0;
862         
863         /* include materials-expand widget? */
864         if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU))) {
865                 ale= make_new_animlistelem(ob, ANIMTYPE_FILLMATD, base, ANIMTYPE_OBJECT);
866                 if (ale) {
867                         BLI_addtail(anim_data, ale);
868                         items++;
869                 }
870         }
871         
872         /* add materials? */
873         if (FILTER_MAT_OBJC(ob) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
874                 short a;
875                 
876                 /* for each material, either add channels separately, or as ipo-block */
877                 for (a=0; a<ob->totcol; a++) {
878                         Material *ma= give_current_material(ob, a);
879                         
880                         /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
881                         if (ELEM(NULL, ma, ma->ipo)) continue;
882                         
883                         /* include material-expand widget? */
884                         // hmm... do we need to store the index of this material in the array anywhere?
885                         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
886                                 ale= make_new_animlistelem(ma, ANIMTYPE_DSMAT, base, ANIMTYPE_OBJECT);
887                                 if (ale) {
888                                         BLI_addtail(anim_data, ale);
889                                         items++;
890                                 }
891                         }
892                         
893                         /* add material's ipo-curve channels? */
894                         if ( (FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_ONLYICU)) && 
895                                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
896                         {
897                                 items += animdata_filter_ipocurves(anim_data, ma->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)ma);
898                         }
899                 }
900
901         }
902         
903         /* return the number of items added to the list */
904         return items;
905 }
906
907 static int animdata_filter_dopesheet_cam (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
908 {
909         bAnimListElem *ale=NULL;
910         Object *ob= base->object;
911         Camera *ca= (Camera *)ob->data;
912         int items = 0;
913         
914         /* include camera-expand widget? */
915         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
916                 ale= make_new_animlistelem(ca, ANIMTYPE_DSCAM, base, ANIMTYPE_OBJECT);
917                 if (ale) {
918                         BLI_addtail(anim_data, ale);
919                         items++;
920                 }
921         }
922         
923         /* add camera ipo-curve channels? */
924         if ( (FILTER_CAM_OBJD(ca) || (filter_mode & ANIMFILTER_ONLYICU)) && 
925                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
926         {
927                 items += animdata_filter_ipocurves(anim_data, ca->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)ca);
928         }
929         
930         /* return the number of items added to the list */
931         return items;
932 }
933
934 static int animdata_filter_dopesheet_lamp (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
935 {
936         bAnimListElem *ale=NULL;
937         Object *ob= base->object;
938         Lamp *la= (Lamp *)ob->data;
939         int items = 0;
940         
941         /* include lamp-expand widget? */
942         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
943                 ale= make_new_animlistelem(la, ANIMTYPE_DSLAM, base, ANIMTYPE_OBJECT);
944                 if (ale) {
945                         BLI_addtail(anim_data, ale);
946                         items++;
947                 }
948         }
949         
950         /* add lamp ipo-curve channels? */
951         if ( (FILTER_LAM_OBJD(la) || (filter_mode & ANIMFILTER_ONLYICU)) && 
952                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
953         {
954                 items += animdata_filter_ipocurves(anim_data, la->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)la);
955         }
956         
957         /* return the number of items added to the list */
958         return items;
959 }
960
961 static int animdata_filter_dopesheet_curve (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
962 {
963         bAnimListElem *ale=NULL;
964         Object *ob= base->object;
965         Curve *cu= (Curve *)ob->data;
966         int items = 0;
967         
968         /* include curve-expand widget? */
969         if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
970                 ale= make_new_animlistelem(cu, ANIMTYPE_DSCUR, base, ANIMTYPE_OBJECT);
971                 if (ale) {
972                         BLI_addtail(anim_data, ale);
973                         items++;
974                 }
975         }
976         
977         /* add curve ipo-curve channels? */
978         if ( (FILTER_CUR_OBJD(cu) || (filter_mode & ANIMFILTER_ONLYICU)) && 
979                   !(filter_mode & ANIMFILTER_IPOKEYS) ) 
980         {
981                 items += animdata_filter_ipocurves(anim_data, cu->ipo, filter_mode, base, ANIMTYPE_OBJECT, (ID *)cu);
982         }
983         
984         /* return the number of items added to the list */
985         return items;
986 }
987
988 static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
989 {
990         bAnimListElem *ale=NULL;
991         Scene *sce= (Scene *)ads->source;
992         Object *ob= base->object;
993         Key *key= ob_get_key(ob);
994         int items = 0;
995         
996         /* add this object as a channel first */
997         if (!(filter_mode & ANIMFILTER_ONLYICU) && !(filter_mode & ANIMFILTER_IPOKEYS)) {
998                 /* check if filtering by selection */
999                 if ( !(filter_mode & ANIMFILTER_SEL) || ((base->flag & SELECT) || (base == sce->basact)) ) {
1000                         ale= make_new_animlistelem(base, ANIMTYPE_OBJECT, NULL, ANIMTYPE_NONE);
1001                         if (ale) {
1002                                 BLI_addtail(anim_data, ale);
1003                                 items++;
1004                         }
1005                 }
1006         }
1007         
1008         /* if collapsed, don't go any further (unless adding keyframes only) */
1009         if ( (EXPANDED_OBJC(ob) == 0) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU)) )
1010                 return items;
1011         
1012         /* IPO? */
1013         if ((ob->ipo) && !(ads->filterflag & ADS_FILTER_NOIPOS)) {              
1014                 /* include ipo-expand widget? */
1015                 if (filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_IPOKEYS)) {
1016                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLIPOD, base, ANIMTYPE_OBJECT);
1017                         if (ale) {
1018                                 BLI_addtail(anim_data, ale);
1019                                 items++;
1020                         }
1021                 }
1022                 
1023                 /* add ipo-curve channels? */
1024                 if ( (FILTER_IPO_OBJC(ob) || (filter_mode & ANIMFILTER_ONLYICU)) && 
1025                           !(filter_mode & ANIMFILTER_IPOKEYS) ) 
1026                 {
1027                         items += animdata_filter_ipocurves(anim_data, ob->ipo, filter_mode, base, ANIMTYPE_OBJECT, NULL); // err... why not set ob?
1028                 }
1029         }
1030         
1031         /* Action? */
1032         if ((ob->action) && !(ads->filterflag & ADS_FILTER_NOACTS)) {
1033                 /* include animion-expand widget? */
1034                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU))) {
1035                         ale= make_new_animlistelem(ob->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT);
1036                         if (ale) {
1037                                 ale->id= (ID *)ob; // err.... is this a good idea?
1038                                 BLI_addtail(anim_data, ale);
1039                                 items++;
1040                         }
1041                 }
1042                 
1043                 /* add ipo-curve channels? */
1044                 if (EXPANDED_ACTC(ob->action) || !(filter_mode & (ANIMFILTER_CHANNELS|ANIMFILTER_FORDRAWING))) {
1045                         // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
1046                         items += animdata_filter_action(anim_data, ob->action, filter_mode, ob, ANIMTYPE_OBJECT); 
1047                 }
1048         }
1049         
1050         /* ShapeKeys? */
1051         if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
1052                 /* include shapekey-expand widget? */
1053                 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & (ANIMFILTER_IPOKEYS|ANIMFILTER_ONLYICU))) {
1054                         ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT);
1055                         if (ale) {
1056                                 BLI_addtail(anim_data, ale);
1057                                 items++;
1058                         }
1059                 }
1060                 
1061                 /* add channels */
1062                 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
1063                         items += animdata_filter_shapekey(anim_data, key, filter_mode, ob, ANIMTYPE_OBJECT);
1064                 }
1065         }
1066         
1067         /* Materials? */
1068         if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
1069                 items += animdata_filter_dopesheet_mats(anim_data, ads, base, filter_mode);
1070         
1071         /* Object Data */
1072         switch (ob->type) {
1073                 case OB_CAMERA: /* ------- Camera ------------ */
1074                 {
1075                         Camera *ca= (Camera *)ob->data;
1076                         if ((ca->ipo) && !(ads->filterflag & ADS_FILTER_NOCAM))
1077                                 items += animdata_filter_dopesheet_cam(anim_data, ads, base, filter_mode);
1078                 }
1079                         break;
1080                 case OB_LAMP: /* ---------- Lamp ----------- */
1081                 {
1082                         Lamp *la= (Lamp *)ob->data;
1083                         if ((la->ipo) && !(ads->filterflag & ADS_FILTER_NOLAM))
1084                                 items += animdata_filter_dopesheet_lamp(anim_data, ads, base, filter_mode);
1085                 }
1086                         break;
1087                 case OB_CURVE: /* ------- Curve ---------- */
1088                 {
1089                         Curve *cu= (Curve *)ob->data;
1090                         if ((cu->ipo) && !(ads->filterflag & ADS_FILTER_NOCUR))
1091                                 items += animdata_filter_dopesheet_curve(anim_data, ads, base, filter_mode);
1092                 }
1093                         break;
1094         }
1095         
1096         /* Constraint Channels? */
1097         if ((ob->constraintChannels.first) && !(ads->filterflag & ADS_FILTER_NOCONSTRAINTS)) {
1098                 bConstraintChannel *conchan;
1099                 
1100                 /* include constraint-expand widget? */
1101                 if ( (filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_ONLYICU)
1102                          && !(filter_mode & ANIMFILTER_IPOKEYS) ) 
1103                 {
1104                         ale= make_new_animlistelem(ob, ANIMTYPE_FILLCOND, base, ANIMTYPE_OBJECT);
1105                         if (ale) {
1106                                 BLI_addtail(anim_data, ale);
1107                                 items++;
1108                         }
1109                 }
1110                 
1111                 /* add constraint channels? */
1112                 if (FILTER_CON_OBJC(ob) || (filter_mode & ANIMFILTER_IPOKEYS) || (filter_mode & ANIMFILTER_ONLYICU)) {
1113                         /* loop through constraint channels, checking and adding them */
1114                         for (conchan=ob->constraintChannels.first; conchan; conchan=conchan->next) {
1115                                 /* only work with this channel and its subchannels if it is editable */
1116                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_CONCHAN(conchan)) {
1117                                         /* check if this conchan should only be included if it is selected */
1118                                         if (!(filter_mode & ANIMFILTER_SEL) || SEL_CONCHAN(conchan)) {
1119                                                 if (filter_mode & ANIMFILTER_IPOKEYS) {
1120                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN2, base, ANIMTYPE_OBJECT);
1121                                                         if (ale) {
1122                                                                 ale->id= (ID *)ob;
1123                                                                 BLI_addtail(anim_data, ale);
1124                                                                 items++;
1125                                                         }
1126                                                 }
1127                                                 else {
1128                                                         ale= make_new_animlistelem(conchan, ANIMTYPE_CONCHAN, base, ANIMTYPE_OBJECT);
1129                                                         if (ale) {
1130                                                                 ale->id= (ID *)ob;
1131                                                                 BLI_addtail(anim_data, ale);
1132                                                                 items++;
1133                                                         }
1134                                                 }
1135                                         }
1136                                 }
1137                         }
1138                 }
1139         }
1140         
1141         /* return the number of items added to the list */
1142         return items;
1143 }       
1144
1145 // 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)
1146 static int animdata_filter_dopesheet (ListBase *anim_data, bDopeSheet *ads, int filter_mode)
1147 {
1148         Scene *sce= (Scene *)ads->source;
1149         Base *base;
1150         int items = 0;
1151         
1152         /* check that we do indeed have a scene */
1153         if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
1154                 printf("DopeSheet Error: Not scene! \n");
1155                 return 0;
1156         }
1157         
1158         /* loop over all bases in the scene */
1159         for (base= sce->base.first; base; base= base->next) {
1160                 /* check if there's an object (all the relevant checks are done in the ob-function) */
1161                 if (base->object) {
1162                         Object *ob= base->object;
1163                         Key *key= ob_get_key(ob);
1164                         short ipoOk, actOk, constsOk, keyOk, dataOk;
1165                         
1166                         /* firstly, check if object can be included, by the following fanimors:
1167                          *      - if only visible, must check for layer and also viewport visibility
1168                          *      - if only selected, must check if object is selected 
1169                          *      - there must be animation data to edit
1170                          */
1171                         // TODO: if cache is implemented, just check name here, and then 
1172                         if (filter_mode & ANIMFILTER_VISIBLE) {
1173                                 /* layer visibility */
1174                                 if ((ob->lay & sce->lay)==0) continue;
1175                                 
1176                                 /* outliner restrict-flag */
1177                                 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1178                         }
1179                         
1180                         /* additionally, dopesheet filtering also affects what objects to consider */
1181                         if (ads->filterflag) {
1182                                 /* check selection and object type filters */
1183                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) || (base == sce->basact)) )  {
1184                                         /* only selected should be shown */
1185                                         continue;
1186                                 }
1187                                 if ((ads->filterflag & ADS_FILTER_NOARM) && (ob->type == OB_ARMATURE)) {
1188                                         /* not showing armatures  */
1189                                         continue;
1190                                 }
1191                                 if ((ads->filterflag & ADS_FILTER_NOOBJ) && (ob->type != OB_ARMATURE)) {
1192                                         /* not showing objects that aren't armatures */
1193                                         continue;
1194                                 }
1195                                 
1196                                 /* check filters for datatypes */
1197                                 ipoOk= ((ob->ipo) && !(ads->filterflag & ADS_FILTER_NOIPOS));
1198                                 actOk= ((ob->action) && !(ads->filterflag & ADS_FILTER_NOACTS));
1199                                 constsOk= ((ob->constraintChannels.first) && !(ads->filterflag & ADS_FILTER_NOCONSTRAINTS));
1200                                 keyOk= ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS));
1201                                 
1202                                 switch (ob->type) {
1203                                         case OB_CAMERA: /* ------- Camera ------------ */
1204                                         {
1205                                                 Camera *ca= (Camera *)ob->data;
1206                                                 dataOk= ((ca->ipo) && !(ads->filterflag & ADS_FILTER_NOCAM));                                           
1207                                         }
1208                                                 break;
1209                                         case OB_LAMP: /* ---------- Lamp ----------- */
1210                                         {
1211                                                 Lamp *la= (Lamp *)ob->data;
1212                                                 dataOk= ((la->ipo) && !(ads->filterflag & ADS_FILTER_NOLAM));
1213                                         }
1214                                                 break;
1215                                         case OB_CURVE: /* -------- Curve ---------- */
1216                                         {
1217                                                 Curve *cu= (Curve *)ob->data;
1218                                                 dataOk= ((cu->ipo) && !(ads->filterflag & ADS_FILTER_NOCUR));
1219                                         }
1220                                                 break;
1221                                         default: /* --- other --- */
1222                                                 dataOk= 0;
1223                                                 break;
1224                                 }
1225                                 
1226                                 /* check if all bad (i.e. nothing to show) */
1227                                 if (!ipoOk && !actOk && !constsOk && !keyOk && !dataOk)
1228                                         continue;
1229                         }
1230                         else {
1231                                 /* check data-types */
1232                                 ipoOk= (ob->ipo != NULL);
1233                                 actOk= (ob->action != NULL);
1234                                 constsOk= (ob->constraintChannels.first != NULL);
1235                                 keyOk= (key != NULL);
1236                                 
1237                                 switch (ob->type) {
1238                                         case OB_CAMERA: /* ------- Camera ------------ */
1239                                         {
1240                                                 Camera *ca= (Camera *)ob->data;
1241                                                 dataOk= (ca->ipo != NULL);                                              
1242                                         }
1243                                                 break;
1244                                         case OB_LAMP: /* ---------- Lamp ----------- */
1245                                         {
1246                                                 Lamp *la= (Lamp *)ob->data;
1247                                                 dataOk= (la->ipo != NULL);
1248                                         }
1249                                                 break;
1250                                         case OB_CURVE: /* -------- Curve ---------- */
1251                                         {
1252                                                 Curve *cu= (Curve *)ob->data;
1253                                                 dataOk= (cu->ipo != NULL);
1254                                         }
1255                                                 break;
1256                                         default: /* --- other --- */
1257                                                 dataOk= 0;
1258                                                 break;
1259                                 }
1260                                 
1261                                 /* check if all bad (i.e. nothing to show) */
1262                                 if (!ipoOk && !actOk && !constsOk && !keyOk && !dataOk)
1263                                         continue;
1264                         }
1265                         
1266                         /* since we're still here, this object should be usable */
1267                         items += animdata_filter_dopesheet_ob(anim_data, ads, base, filter_mode);
1268                 }
1269         }
1270         
1271         /* return the number of items in the list */
1272         return items;
1273 }
1274
1275 /* ----------- Public API --------------- */
1276
1277 /* This function filters the active data source to leave only animation channels suitable for
1278  * usage by the caller. It will return the length of the list 
1279  * 
1280  *      *act_data: is a pointer to a ListBase, to which the filtered animation channels
1281  *              will be placed for use.
1282  *      filter_mode: how should the data be filtered - bitmapping accessed flags
1283  */
1284 int ANIM_animdata_filter (ListBase *anim_data, int filter_mode, void *data, short datatype)
1285 {
1286         int items = 0;
1287         
1288         /* only filter data if there's somewhere to put it */
1289         if (data && anim_data) {
1290                 bAnimListElem *ale, *next;
1291                 
1292                 /* firstly filter the data */
1293                 switch (datatype) {
1294                         case ANIMCONT_ACTION:
1295                                 items= animdata_filter_action(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE);
1296                                 break;
1297                         case ANIMCONT_SHAPEKEY:
1298                                 items= animdata_filter_shapekey(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE);
1299                                 break;
1300                         case ANIMCONT_GPENCIL:
1301                                 //items= animdata_filter_gpencil(anim_data, data, filter_mode);
1302                                 break;
1303                         case ANIMCONT_DOPESHEET:
1304                                 items= animdata_filter_dopesheet(anim_data, data, filter_mode);
1305                                 break;
1306                                 
1307                         case ANIMCONT_IPO:
1308                                 // FIXME: this will be used for showing a single IPO-block (not too useful from animator perspective though!)
1309                                 //items= 0;
1310                                 break;
1311                 }
1312                         
1313                 /* remove any weedy entries */
1314                 // XXX this is weedy code!
1315                 for (ale= anim_data->first; ale; ale= next) {
1316                         next= ale->next;
1317                         
1318                         if (ale->type == ANIMTYPE_NONE) {
1319                                 items--;
1320                                 BLI_freelinkN(anim_data, ale);
1321                         }
1322                         
1323                         if (filter_mode & ANIMFILTER_IPOKEYS) {
1324                                 if (ale->datatype != ALE_IPO) {
1325                                         items--;
1326                                         BLI_freelinkN(anim_data, ale);
1327                                 }
1328                                 else if (ale->key_data == NULL) {
1329                                         items--;
1330                                         BLI_freelinkN(anim_data, ale);
1331                                 }
1332                         }
1333                 }
1334         }
1335         
1336         /* return the number of items in the list */
1337         return items;
1338 }
1339
1340 /* ************************************************************ */