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