Cleanup: indentation, wrapping
[blender.git] / source / blender / editors / animation / anim_filter.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation, Joshua Leung
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup edanimation
22  */
23
24
25 /* This file contains a system used to provide a layer of abstraction between sources
26  * of animation data and tools in Animation Editors. The method used here involves
27  * generating a list of edit structures which enable tools to naively perform the actions
28  * they require without all the boiler-plate associated with loops within loops and checking
29  * for cases to ignore.
30  *
31  * While this is primarily used for the Action/Dopesheet Editor (and its accessory modes),
32  * the Graph Editor also uses this for its channel list and for determining which curves
33  * are being edited. Likewise, the NLA Editor also uses this for its channel list and in
34  * its operators.
35  *
36  * Note: much of the original system this was based on was built before the creation of the RNA
37  * system. In future, it would be interesting to replace some parts of this code with RNA queries,
38  * however, RNA does not eliminate some of the boiler-plate reduction benefits presented by this
39  * system, so if any such work does occur, it should only be used for the internals used here...
40  *
41  * -- Joshua Leung, Dec 2008 (Last revision July 2009)
42  */
43
44 #include <string.h>
45
46 #include "DNA_anim_types.h"
47 #include "DNA_armature_types.h"
48 #include "DNA_camera_types.h"
49 #include "DNA_cachefile_types.h"
50 #include "DNA_light_types.h"
51 #include "DNA_lattice_types.h"
52 #include "DNA_linestyle_types.h"
53 #include "DNA_key_types.h"
54 #include "DNA_mask_types.h"
55 #include "DNA_material_types.h"
56 #include "DNA_mesh_types.h"
57 #include "DNA_meta_types.h"
58 #include "DNA_movieclip_types.h"
59 #include "DNA_node_types.h"
60 #include "DNA_particle_types.h"
61 #include "DNA_space_types.h"
62 #include "DNA_sequence_types.h"
63 #include "DNA_scene_types.h"
64 #include "DNA_screen_types.h"
65 #include "DNA_speaker_types.h"
66 #include "DNA_world_types.h"
67 #include "DNA_gpencil_types.h"
68 #include "DNA_brush_types.h"
69 #include "DNA_object_types.h"
70 #include "DNA_userdef_types.h"
71 #include "DNA_layer_types.h"
72
73 #include "MEM_guardedalloc.h"
74
75 #include "BLI_blenlib.h"
76 #include "BLI_utildefines.h"
77 #include "BLI_alloca.h"
78 #include "BLI_ghash.h"
79 #include "BLI_string.h"
80
81 #include "BKE_action.h"
82 #include "BKE_animsys.h"
83 #include "BKE_collection.h"
84 #include "BKE_context.h"
85 #include "BKE_fcurve.h"
86 #include "BKE_global.h"
87 #include "BKE_key.h"
88 #include "BKE_layer.h"
89 #include "BKE_main.h"
90 #include "BKE_material.h"
91 #include "BKE_modifier.h"
92 #include "BKE_node.h"
93 #include "BKE_mask.h"
94 #include "BKE_sequencer.h"
95
96 #include "ED_anim_api.h"
97 #include "ED_markers.h"
98
99 #include "UI_resources.h"  /* for TH_KEYFRAME_SCALE lookup */
100
101 /* ************************************************************ */
102 /* Blender Context <-> Animation Context mapping */
103
104 /* ----------- Private Stuff - General -------------------- */
105
106 /* Get vertical scaling factor (i.e. typically used for keyframe size) */
107 static void animedit_get_yscale_factor(bAnimContext *ac)
108 {
109         bTheme *btheme = UI_GetTheme();
110
111         /* grab scale factor directly from action editor setting
112          * NOTE: This theme setting doesn't have an ID, as it cannot be accessed normally
113          *       since it is a float, and the theme settings methods can only handle chars.
114          */
115         ac->yscale_fac = btheme->space_action.keyframe_scale_fac;
116
117         /* clamp to avoid problems with uninitialised values... */
118         if (ac->yscale_fac < 0.1f)
119                 ac->yscale_fac = 1.0f;
120         //printf("yscale_fac = %f\n", ac->yscale_fac);
121 }
122
123 /* ----------- Private Stuff - Action Editor ------------- */
124
125 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
126 /* Note: there's a similar function in key.c (BKE_key_from_object) */
127 static Key *actedit_get_shapekeys(bAnimContext *ac)
128 {
129         ViewLayer *view_layer = ac->view_layer;
130         Object *ob;
131         Key *key;
132
133         ob = OBACT(view_layer);
134         if (ob == NULL)
135                 return NULL;
136
137         /* XXX pinning is not available in 'ShapeKey' mode... */
138         //if (saction->pin) return NULL;
139
140         /* shapekey data is stored with geometry data */
141         key = BKE_key_from_object(ob);
142
143         if (key) {
144                 if (key->type == KEY_RELATIVE)
145                         return key;
146         }
147
148         return NULL;
149 }
150
151 /* Get data being edited in Action Editor (depending on current 'mode') */
152 static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction)
153 {
154         /* get dopesheet */
155         ac->ads = &saction->ads;
156
157         /* sync settings with current view status, then return appropriate data */
158         switch (saction->mode) {
159                 case SACTCONT_ACTION: /* 'Action Editor' */
160                         /* if not pinned, sync with active object */
161                         if (/*saction->pin == 0*/ true) {
162                                 if (ac->obact && ac->obact->adt)
163                                         saction->action = ac->obact->adt->action;
164                                 else
165                                         saction->action = NULL;
166                         }
167
168                         ac->datatype = ANIMCONT_ACTION;
169                         ac->data = saction->action;
170
171                         ac->mode = saction->mode;
172                         return true;
173
174                 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
175                         ac->datatype = ANIMCONT_SHAPEKEY;
176                         ac->data = actedit_get_shapekeys(ac);
177
178                         /* if not pinned, sync with active object */
179                         if (/*saction->pin == 0*/ true) {
180                                 Key *key = (Key *)ac->data;
181
182                                 if (key && key->adt)
183                                         saction->action = key->adt->action;
184                                 else
185                                         saction->action = NULL;
186                         }
187
188                         ac->mode = saction->mode;
189                         return true;
190
191                 case SACTCONT_GPENCIL: /* Grease Pencil */ /* XXX review how this mode is handled... */
192                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
193                         saction->ads.source = (ID *)ac->scene;
194
195                         ac->datatype = ANIMCONT_GPENCIL;
196                         ac->data = &saction->ads;
197
198                         ac->mode = saction->mode;
199                         return true;
200
201                 case SACTCONT_CACHEFILE: /* Cache File */ /* XXX review how this mode is handled... */
202                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
203                         saction->ads.source = (ID *)ac->scene;
204
205                         ac->datatype = ANIMCONT_CHANNEL;
206                         ac->data = &saction->ads;
207
208                         ac->mode = saction->mode;
209                         return true;
210
211                 case SACTCONT_MASK: /* Mask */ /* XXX review how this mode is handled... */
212                 {
213                         /* TODO, other methods to get the mask */
214                         // Sequence *seq = BKE_sequencer_active_get(ac->scene);
215                         //MovieClip *clip = ac->scene->clip;
216 //                      struct Mask *mask = seq ? seq->mask : NULL;
217
218                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
219                         saction->ads.source = (ID *)ac->scene;
220
221                         ac->datatype = ANIMCONT_MASK;
222                         ac->data = &saction->ads;
223
224                         ac->mode = saction->mode;
225                         return true;
226                 }
227
228                 case SACTCONT_DOPESHEET: /* DopeSheet */
229                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
230                         saction->ads.source = (ID *)ac->scene;
231
232                         ac->datatype = ANIMCONT_DOPESHEET;
233                         ac->data = &saction->ads;
234
235                         ac->mode = saction->mode;
236                         return true;
237
238                 case SACTCONT_TIMELINE: /* Timeline */
239                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
240                         saction->ads.source = (ID *)ac->scene;
241
242                         /* sync scene's "selected keys only" flag with our "only selected" flag
243                          * XXX: This is a workaround for T55525. We shouldn't really be syncing the flags like this,
244                          *      but it's a simpler fix for now than also figuring out how the next/prev keyframe tools
245                          *      should work in the 3D View if we allowed full access to the timeline's dopesheet filters
246                          *      (i.e. we'd have to figure out where to host those settings, to be on a scene level like
247                          *      this flag currently is, along with several other unknowns)
248                          */
249                         if (ac->scene->flag & SCE_KEYS_NO_SELONLY)
250                                 saction->ads.filterflag &= ~ADS_FILTER_ONLYSEL;
251                         else
252                                 saction->ads.filterflag |= ADS_FILTER_ONLYSEL;
253
254                         ac->datatype = ANIMCONT_TIMELINE;
255                         ac->data = &saction->ads;
256
257                         ac->mode = saction->mode;
258                         return true;
259
260                 default: /* unhandled yet */
261                         ac->datatype = ANIMCONT_NONE;
262                         ac->data = NULL;
263
264                         ac->mode = -1;
265                         return false;
266         }
267 }
268
269 /* ----------- Private Stuff - Graph Editor ------------- */
270
271 /* Get data being edited in Graph Editor (depending on current 'mode') */
272 static bool graphedit_get_context(bAnimContext *ac, SpaceGraph *sipo)
273 {
274         /* init dopesheet data if non-existent (i.e. for old files) */
275         if (sipo->ads == NULL) {
276                 sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
277                 sipo->ads->source = (ID *)ac->scene;
278         }
279         ac->ads = sipo->ads;
280
281         /* set settings for Graph Editor - "Selected = Editable" */
282         if (sipo->flag & SIPO_SELCUVERTSONLY)
283                 sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
284         else
285                 sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
286
287         /* sync settings with current view status, then return appropriate data */
288         switch (sipo->mode) {
289                 case SIPO_MODE_ANIMATION:  /* Animation F-Curve Editor */
290                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
291                         sipo->ads->source = (ID *)ac->scene;
292                         sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
293
294                         ac->datatype = ANIMCONT_FCURVES;
295                         ac->data = sipo->ads;
296
297                         ac->mode = sipo->mode;
298                         return true;
299
300                 case SIPO_MODE_DRIVERS:  /* Driver F-Curve Editor */
301                         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
302                         sipo->ads->source = (ID *)ac->scene;
303                         sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
304
305                         ac->datatype = ANIMCONT_DRIVERS;
306                         ac->data = sipo->ads;
307
308                         ac->mode = sipo->mode;
309                         return true;
310
311                 default: /* unhandled yet */
312                         ac->datatype = ANIMCONT_NONE;
313                         ac->data = NULL;
314
315                         ac->mode = -1;
316                         return false;
317         }
318 }
319
320 /* ----------- Private Stuff - NLA Editor ------------- */
321
322 /* Get data being edited in Graph Editor (depending on current 'mode') */
323 static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla)
324 {
325         /* init dopesheet data if non-existent (i.e. for old files) */
326         if (snla->ads == NULL)
327                 snla->ads = MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
328         ac->ads = snla->ads;
329
330         /* sync settings with current view status, then return appropriate data */
331         /* update scene-pointer (no need to check for pinning yet, as not implemented) */
332         snla->ads->source = (ID *)ac->scene;
333         snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
334
335         ac->datatype = ANIMCONT_NLA;
336         ac->data = snla->ads;
337
338         return true;
339 }
340
341 /* ----------- Public API --------------- */
342
343 /* Obtain current anim-data context, given that context info from Blender context has already been set
344  * - AnimContext to write to is provided as pointer to var on stack so that we don't have
345  *   allocation/freeing costs (which are not that avoidable with channels).
346  */
347 bool ANIM_animdata_context_getdata(bAnimContext *ac)
348 {
349         SpaceLink *sl = ac->sl;
350         bool ok = false;
351
352         /* context depends on editor we are currently in */
353         if (sl) {
354                 switch (ac->spacetype) {
355                         case SPACE_ACTION:
356                         {
357                                 SpaceAction *saction = (SpaceAction *)sl;
358                                 ok = actedit_get_context(ac, saction);
359                                 break;
360                         }
361                         case SPACE_GRAPH:
362                         {
363                                 SpaceGraph *sipo = (SpaceGraph *)sl;
364                                 ok = graphedit_get_context(ac, sipo);
365                                 break;
366                         }
367                         case SPACE_NLA:
368                         {
369                                 SpaceNla *snla = (SpaceNla *)sl;
370                                 ok = nlaedit_get_context(ac, snla);
371                                 break;
372                         }
373                 }
374         }
375
376         /* check if there's any valid data */
377         return (ok && ac->data);
378 }
379
380 /* Obtain current anim-data context from Blender Context info
381  * - AnimContext to write to is provided as pointer to var on stack so that we don't have
382  *   allocation/freeing costs (which are not that avoidable with channels).
383  * - Clears data and sets the information from Blender Context which is useful
384  */
385 bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
386 {
387         Main *bmain = CTX_data_main(C);
388         ScrArea *sa = CTX_wm_area(C);
389         ARegion *ar = CTX_wm_region(C);
390         SpaceLink *sl = CTX_wm_space_data(C);
391         Scene *scene = CTX_data_scene(C);
392
393         /* clear old context info */
394         if (ac == NULL) return false;
395         memset(ac, 0, sizeof(bAnimContext));
396
397         /* get useful default context settings from context */
398         ac->bmain = bmain;
399         ac->scene = scene;
400         if (scene) {
401                 ac->markers = ED_context_get_markers(C);
402         }
403         ac->depsgraph = CTX_data_depsgraph(C);
404         ac->view_layer = CTX_data_view_layer(C);
405         ac->obact = (ac->view_layer->basact) ? ac->view_layer->basact->object : NULL;
406         ac->sa = sa;
407         ac->ar = ar;
408         ac->sl = sl;
409         ac->spacetype = (sa) ? sa->spacetype : 0;
410         ac->regiontype = (ar) ? ar->regiontype : 0;
411
412         /* initialise default y-scale factor */
413         animedit_get_yscale_factor(ac);
414
415         /* get data context info */
416         // XXX: if the below fails, try to grab this info from context instead... (to allow for scripting)
417         return ANIM_animdata_context_getdata(ac);
418 }
419
420 /* ************************************************************ */
421 /* Blender Data <-- Filter --> Channels to be operated on */
422
423 /* macros to use before/after getting the sub-channels of some channel,
424  * to abstract away some of the tricky logic involved
425  *
426  * cases:
427  * 1) Graph Edit main area (just data) OR channels visible in Channel List
428  * 2) If not showing channels, we're only interested in the data (Action Editor's editing)
429  * 3) We don't care what data, we just care there is some (so that a collapsed
430  *    channel can be kept around). No need to clear channels-flag in order to
431  *    keep expander channels with no sub-data out, as those cases should get
432  *    dealt with by the recursive detection idiom in place.
433  *
434  * Implementation Note:
435  *  YES the _doSubChannels variable is NOT read anywhere. BUT, this is NOT an excuse
436  *  to go steamrolling the logic into a single-line expression as from experience,
437  *  those are notoriously difficult to read + debug when extending later on. The code
438  *  below is purposefully laid out so that each case noted above corresponds clearly to
439  *  one case below.
440  */
441 #define BEGIN_ANIMFILTER_SUBCHANNELS(expanded_check) \
442         { \
443                 int _filter = filter_mode; \
444                 short _doSubChannels = 0; \
445                 if (!(filter_mode & ANIMFILTER_LIST_VISIBLE) || (expanded_check)) \
446                         _doSubChannels = 1; \
447                 else if (!(filter_mode & ANIMFILTER_LIST_CHANNELS)) \
448                         _doSubChannels = 2; \
449                 else { \
450                         filter_mode |= ANIMFILTER_TMP_PEEK; \
451                 } \
452                  \
453                 { \
454                         (void) _doSubChannels; \
455                 }
456 /* ... standard sub-channel filtering can go on here now ... */
457 #define END_ANIMFILTER_SUBCHANNELS \
458                 filter_mode = _filter; \
459         } (void)0
460
461 /* ............................... */
462
463 /* quick macro to test if AnimData is usable */
464 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
465
466 /* quick macro to test if AnimData is usable for drivers */
467 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
468
469 /* quick macro to test if AnimData is usable for NLA */
470 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
471
472 /* Quick macro to test for all three above usability tests, performing the appropriate provided
473  * action for each when the AnimData context is appropriate.
474  *
475  * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
476  *
477  * For this to work correctly, a standard set of data needs to be available within the scope that this
478  * gets called in:
479  * - ListBase anim_data;
480  * - bDopeSheet *ads;
481  * - bAnimListElem *ale;
482  * - size_t items;
483  *
484  * - id: ID block which should have an AnimData pointer following it immediately, to use
485  * - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA)
486  * - nlaOk: line or block of code to execute for NLA tracks+strips case
487  * - driversOk: line or block of code to execute for Drivers case
488  * - nlaKeysOk: line or block of code for NLA Strip Keyframes case
489  * - keysOk: line or block of code for Keyframes case
490  *
491  * The checks for the various cases are as follows:
492  * 0) top level: checks for animdata and also that all the F-Curves for the block will be visible
493  * 1) animdata check: for filtering animdata blocks only
494  * 2A) nla tracks: include animdata block's data as there are NLA tracks+strips there
495  * 2B) actions to convert to nla: include animdata block's data as there is an action that can be
496  *     converted to a new NLA strip, and the filtering options allow this
497  * 2C) allow non-animated datablocks to be included so that datablocks can be added
498  * 3) drivers: include drivers from animdata block (for Drivers mode in Graph Editor)
499  * 4A) nla strip keyframes: these are the per-strip controls for time and influence
500  * 4B) normal keyframes: only when there is an active action
501  */
502 #define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, nlaKeysOk, keysOk) \
503         { \
504                 if ((id)->adt) { \
505                         if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) { \
506                                 if (filter_mode & ANIMFILTER_ANIMDATA) { \
507                                         adtOk \
508                                 } \
509                                 else if (ads->filterflag & ADS_FILTER_ONLYNLA) { \
510                                         if (ANIMDATA_HAS_NLA(id)) { \
511                                                 nlaOk \
512                                         } \
513                                         else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || ANIMDATA_HAS_KEYS(id)) { \
514                                                 nlaOk \
515                                         } \
516                                 } \
517                                 else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) { \
518                                         if (ANIMDATA_HAS_DRIVERS(id)) { \
519                                                 driversOk \
520                                         } \
521                                 } \
522                                 else { \
523                                         if (ANIMDATA_HAS_NLA(id)) { \
524                                                 nlaKeysOk \
525                                         } \
526                                         if (ANIMDATA_HAS_KEYS(id)) { \
527                                                 keysOk \
528                                         } \
529                                 } \
530                         } \
531                 } \
532         } (void)0
533
534 /* ............................... */
535
536 /* Add a new animation channel, taking into account the "peek" flag, which is used to just check
537  * whether any channels will be added (but without needing them to actually get created).
538  *
539  * ! This causes the calling function to return early if we're only "peeking" for channels
540  */
541 // XXX: ale_statement stuff is really a hack for one special case. It shouldn't really be needed...
542 #define ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, fcurve_owner_id, ale_statement) \
543         if (filter_mode & ANIMFILTER_TMP_PEEK) \
544                 return 1; \
545         else { \
546                 bAnimListElem *ale = make_new_animlistelem(channel_data, channel_type, (ID *)owner_id, fcurve_owner_id); \
547                 if (ale) { \
548                         BLI_addtail(anim_data, ale); \
549                         items ++; \
550                         ale_statement \
551                 } \
552         } (void)0
553
554 #define ANIMCHANNEL_NEW_CHANNEL(channel_data, channel_type, owner_id, fcurve_owner_id) \
555         ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, fcurve_owner_id, {})
556
557 /* ............................... */
558
559 /* quick macro to test if an anim-channel representing an AnimData block is suitably active */
560 #define ANIMCHANNEL_ACTIVEOK(ale) \
561         (!(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE) )
562
563 /* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
564 #define ANIMCHANNEL_SELOK(test_func) \
565         (!(filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) || \
566          ((filter_mode & ANIMFILTER_SEL) && test_func) || \
567          ((filter_mode & ANIMFILTER_UNSEL) && test_func == 0) )
568
569 /* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes
570  * - _SELEDIT means that only selected curves will have visible+editable keyframes
571  *
572  * checks here work as follows:
573  * 1) seledit off - don't need to consider the implications of this option
574  * 2) foredit off - we're not considering editing, so channel is ok still
575  * 3) test_func (i.e. selection test) - only if selected, this test will pass
576  */
577 #define ANIMCHANNEL_SELEDITOK(test_func) \
578         (!(filter_mode & ANIMFILTER_SELEDIT) || \
579          !(filter_mode & ANIMFILTER_FOREDIT) || \
580          (test_func) )
581
582 /* ----------- 'Private' Stuff --------------- */
583
584 /* this function allocates memory for a new bAnimListElem struct for the
585  * provided animation channel-data.
586  */
587 static bAnimListElem *make_new_animlistelem(void *data, short datatype, ID *owner_id, ID *fcurve_owner_id)
588 {
589         bAnimListElem *ale = NULL;
590
591         /* only allocate memory if there is data to convert */
592         if (data) {
593                 /* allocate and set generic data */
594                 ale = MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
595
596                 ale->data = data;
597                 ale->type = datatype;
598
599                 ale->id = owner_id;
600                 ale->adt = BKE_animdata_from_id(owner_id);
601                 ale->fcurve_owner_id = fcurve_owner_id;
602
603                 /* do specifics */
604                 switch (datatype) {
605                         case ANIMTYPE_SUMMARY:
606                         {
607                                 /* nothing to include for now... this is just a dummy wrappy around all the other channels
608                                  * in the DopeSheet, and gets included at the start of the list
609                                  */
610                                 ale->key_data = NULL;
611                                 ale->datatype = ALE_ALL;
612                                 break;
613                         }
614                         case ANIMTYPE_SCENE:
615                         {
616                                 Scene *sce = (Scene *)data;
617
618                                 ale->flag = sce->flag;
619
620                                 ale->key_data = sce;
621                                 ale->datatype = ALE_SCE;
622
623                                 ale->adt = BKE_animdata_from_id(data);
624                                 break;
625                         }
626                         case ANIMTYPE_OBJECT:
627                         {
628                                 Base *base = (Base *)data;
629                                 Object *ob = base->object;
630
631                                 ale->flag = ob->flag;
632
633                                 ale->key_data = ob;
634                                 ale->datatype = ALE_OB;
635
636                                 ale->adt = BKE_animdata_from_id(&ob->id);
637                                 break;
638                         }
639                         case ANIMTYPE_FILLACTD:
640                         {
641                                 bAction *act = (bAction *)data;
642
643                                 ale->flag = act->flag;
644
645                                 ale->key_data = act;
646                                 ale->datatype = ALE_ACT;
647                                 break;
648                         }
649                         case ANIMTYPE_FILLDRIVERS:
650                         {
651                                 AnimData *adt = (AnimData *)data;
652
653                                 ale->flag = adt->flag;
654
655                                 // XXX... drivers don't show summary for now
656                                 ale->key_data = NULL;
657                                 ale->datatype = ALE_NONE;
658                                 break;
659                         }
660                         case ANIMTYPE_DSMAT:
661                         {
662                                 Material *ma = (Material *)data;
663                                 AnimData *adt = ma->adt;
664
665                                 ale->flag = FILTER_MAT_OBJD(ma);
666
667                                 ale->key_data = (adt) ? adt->action : NULL;
668                                 ale->datatype = ALE_ACT;
669
670                                 ale->adt = BKE_animdata_from_id(data);
671                                 break;
672                         }
673                         case ANIMTYPE_DSLAM:
674                         {
675                                 Light *la = (Light *)data;
676                                 AnimData *adt = la->adt;
677
678                                 ale->flag = FILTER_LAM_OBJD(la);
679
680                                 ale->key_data = (adt) ? adt->action : NULL;
681                                 ale->datatype = ALE_ACT;
682
683                                 ale->adt = BKE_animdata_from_id(data);
684                                 break;
685                         }
686                         case ANIMTYPE_DSCAM:
687                         {
688                                 Camera *ca = (Camera *)data;
689                                 AnimData *adt = ca->adt;
690
691                                 ale->flag = FILTER_CAM_OBJD(ca);
692
693                                 ale->key_data = (adt) ? adt->action : NULL;
694                                 ale->datatype = ALE_ACT;
695
696                                 ale->adt = BKE_animdata_from_id(data);
697                                 break;
698                         }
699                         case ANIMTYPE_DSCACHEFILE:
700                         {
701                                 CacheFile *cache_file = (CacheFile *)data;
702                                 AnimData *adt = cache_file->adt;
703
704                                 ale->flag = FILTER_CACHEFILE_OBJD(cache_file);
705
706                                 ale->key_data = (adt) ? adt->action : NULL;
707                                 ale->datatype = ALE_ACT;
708
709                                 ale->adt = BKE_animdata_from_id(data);
710                                 break;
711                         }
712                         case ANIMTYPE_DSCUR:
713                         {
714                                 Curve *cu = (Curve *)data;
715                                 AnimData *adt = cu->adt;
716
717                                 ale->flag = FILTER_CUR_OBJD(cu);
718
719                                 ale->key_data = (adt) ? adt->action : NULL;
720                                 ale->datatype = ALE_ACT;
721
722                                 ale->adt = BKE_animdata_from_id(data);
723                                 break;
724                         }
725                         case ANIMTYPE_DSARM:
726                         {
727                                 bArmature *arm = (bArmature *)data;
728                                 AnimData *adt = arm->adt;
729
730                                 ale->flag = FILTER_ARM_OBJD(arm);
731
732                                 ale->key_data = (adt) ? adt->action : NULL;
733                                 ale->datatype = ALE_ACT;
734
735                                 ale->adt = BKE_animdata_from_id(data);
736                                 break;
737                         }
738                         case ANIMTYPE_DSMESH:
739                         {
740                                 Mesh *me = (Mesh *)data;
741                                 AnimData *adt = me->adt;
742
743                                 ale->flag = FILTER_MESH_OBJD(me);
744
745                                 ale->key_data = (adt) ? adt->action : NULL;
746                                 ale->datatype = ALE_ACT;
747
748                                 ale->adt = BKE_animdata_from_id(data);
749                                 break;
750                         }
751                         case ANIMTYPE_DSLAT:
752                         {
753                                 Lattice *lt = (Lattice *)data;
754                                 AnimData *adt = lt->adt;
755
756                                 ale->flag = FILTER_LATTICE_OBJD(lt);
757
758                                 ale->key_data = (adt) ? adt->action : NULL;
759                                 ale->datatype = ALE_ACT;
760
761                                 ale->adt = BKE_animdata_from_id(data);
762                                 break;
763                         }
764                         case ANIMTYPE_DSSPK:
765                         {
766                                 Speaker *spk = (Speaker *)data;
767                                 AnimData *adt = spk->adt;
768
769                                 ale->flag = FILTER_SPK_OBJD(spk);
770
771                                 ale->key_data = (adt) ? adt->action : NULL;
772                                 ale->datatype = ALE_ACT;
773
774                                 ale->adt = BKE_animdata_from_id(data);
775                                 break;
776                         }
777                         case ANIMTYPE_DSSKEY:
778                         {
779                                 Key *key = (Key *)data;
780                                 AnimData *adt = key->adt;
781
782                                 ale->flag = FILTER_SKE_OBJD(key);
783
784                                 ale->key_data = (adt) ? adt->action : NULL;
785                                 ale->datatype = ALE_ACT;
786
787                                 ale->adt = BKE_animdata_from_id(data);
788                                 break;
789                         }
790                         case ANIMTYPE_DSWOR:
791                         {
792                                 World *wo = (World *)data;
793                                 AnimData *adt = wo->adt;
794
795                                 ale->flag = FILTER_WOR_SCED(wo);
796
797                                 ale->key_data = (adt) ? adt->action : NULL;
798                                 ale->datatype = ALE_ACT;
799
800                                 ale->adt = BKE_animdata_from_id(data);
801                                 break;
802                         }
803                         case ANIMTYPE_DSNTREE:
804                         {
805                                 bNodeTree *ntree = (bNodeTree *)data;
806                                 AnimData *adt = ntree->adt;
807
808                                 ale->flag = FILTER_NTREE_DATA(ntree);
809
810                                 ale->key_data = (adt) ? adt->action : NULL;
811                                 ale->datatype = ALE_ACT;
812
813                                 ale->adt = BKE_animdata_from_id(data);
814                                 break;
815                         }
816                         case ANIMTYPE_DSLINESTYLE:
817                         {
818                                 FreestyleLineStyle *linestyle = (FreestyleLineStyle *)data;
819                                 AnimData *adt = linestyle->adt;
820
821                                 ale->flag = FILTER_LS_SCED(linestyle);
822
823                                 ale->key_data = (adt) ? adt->action : NULL;
824                                 ale->datatype = ALE_ACT;
825
826                                 ale->adt = BKE_animdata_from_id(data);
827                                 break;
828                         }
829                         case ANIMTYPE_DSPART:
830                         {
831                                 ParticleSettings *part = (ParticleSettings *)ale->data;
832                                 AnimData *adt = part->adt;
833
834                                 ale->flag = FILTER_PART_OBJD(part);
835
836                                 ale->key_data = (adt) ? adt->action : NULL;
837                                 ale->datatype = ALE_ACT;
838
839                                 ale->adt = BKE_animdata_from_id(data);
840                                 break;
841                         }
842                         case ANIMTYPE_DSTEX:
843                         {
844                                 Tex *tex = (Tex *)data;
845                                 AnimData *adt = tex->adt;
846
847                                 ale->flag = FILTER_TEX_DATA(tex);
848
849                                 ale->key_data = (adt) ? adt->action : NULL;
850                                 ale->datatype = ALE_ACT;
851
852                                 ale->adt = BKE_animdata_from_id(data);
853                                 break;
854                         }
855                         case ANIMTYPE_DSGPENCIL:
856                         {
857                                 bGPdata *gpd = (bGPdata *)data;
858                                 AnimData *adt = gpd->adt;
859
860                                 /* NOTE: we just reuse the same expand filter for this case */
861                                 ale->flag = EXPANDED_GPD(gpd);
862
863                                 // XXX: currently, this is only used for access to its animation data
864                                 ale->key_data = (adt) ? adt->action : NULL;
865                                 ale->datatype = ALE_ACT;
866
867                                 ale->adt = BKE_animdata_from_id(data);
868                                 break;
869                         }
870                         case ANIMTYPE_DSMCLIP:
871                         {
872                                 MovieClip *clip = (MovieClip *)data;
873                                 AnimData *adt = clip->adt;
874
875                                 ale->flag = EXPANDED_MCLIP(clip);
876
877                                 ale->key_data = (adt) ? adt->action : NULL;
878                                 ale->datatype = ALE_ACT;
879
880                                 ale->adt = BKE_animdata_from_id(data);
881                                 break;
882                         }
883                         case ANIMTYPE_NLACONTROLS:
884                         {
885                                 AnimData *adt = (AnimData *)data;
886
887                                 ale->flag = adt->flag;
888
889                                 ale->key_data = NULL;
890                                 ale->datatype = ALE_NONE;
891                                 break;
892                         }
893                         case ANIMTYPE_GROUP:
894                         {
895                                 bActionGroup *agrp = (bActionGroup *)data;
896
897                                 ale->flag = agrp->flag;
898
899                                 ale->key_data = NULL;
900                                 ale->datatype = ALE_GROUP;
901                                 break;
902                         }
903                         case ANIMTYPE_FCURVE:
904                         case ANIMTYPE_NLACURVE: /* practically the same as ANIMTYPE_FCURVE.
905                                                  * Differences are applied post-creation */
906                         {
907                                 FCurve *fcu = (FCurve *)data;
908
909                                 ale->flag = fcu->flag;
910
911                                 ale->key_data = fcu;
912                                 ale->datatype = ALE_FCURVE;
913                                 break;
914                         }
915                         case ANIMTYPE_SHAPEKEY:
916                         {
917                                 KeyBlock *kb = (KeyBlock *)data;
918                                 Key *key = (Key *)ale->id;
919
920                                 ale->flag = kb->flag;
921
922                                 /* whether we have keyframes depends on whether there is a Key block to find it from */
923                                 if (key) {
924                                         /* index of shapekey is defined by place in key's list */
925                                         ale->index = BLI_findindex(&key->block, kb);
926
927                                         /* the corresponding keyframes are from the animdata */
928                                         if (ale->adt && ale->adt->action) {
929                                                 bAction *act = ale->adt->action;
930                                                 char *rna_path = BKE_keyblock_curval_rnapath_get(key, kb);
931
932                                                 /* try to find the F-Curve which corresponds to this exactly,
933                                                  * then free the MEM_alloc'd string
934                                                  */
935                                                 if (rna_path) {
936                                                         ale->key_data = (void *)list_find_fcurve(&act->curves, rna_path, 0);
937                                                         MEM_freeN(rna_path);
938                                                 }
939                                         }
940                                         ale->datatype = (ale->key_data) ? ALE_FCURVE : ALE_NONE;
941                                 }
942                                 break;
943                         }
944                         case ANIMTYPE_GPLAYER:
945                         {
946                                 bGPDlayer *gpl = (bGPDlayer *)data;
947
948                                 ale->flag = gpl->flag;
949
950                                 ale->key_data = NULL;
951                                 ale->datatype = ALE_GPFRAME;
952                                 break;
953                         }
954                         case ANIMTYPE_MASKLAYER:
955                         {
956                                 MaskLayer *masklay = (MaskLayer *)data;
957
958                                 ale->flag = masklay->flag;
959
960                                 ale->key_data = NULL;
961                                 ale->datatype = ALE_MASKLAY;
962                                 break;
963                         }
964                         case ANIMTYPE_NLATRACK:
965                         {
966                                 NlaTrack *nlt = (NlaTrack *)data;
967
968                                 ale->flag = nlt->flag;
969
970                                 ale->key_data = &nlt->strips;
971                                 ale->datatype = ALE_NLASTRIP;
972                                 break;
973                         }
974                         case ANIMTYPE_NLAACTION:
975                         {
976                                 /* nothing to include for now... nothing editable from NLA-perspective here */
977                                 ale->key_data = NULL;
978                                 ale->datatype = ALE_NONE;
979                                 break;
980                         }
981                 }
982         }
983
984         /* return created datatype */
985         return ale;
986 }
987
988 /* ----------------------------------------- */
989
990 /* 'Only Selected' selected data and/or 'Include Hidden' filtering
991  * NOTE: when this function returns true, the F-Curve is to be skipped
992  */
993 static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id, int filter_mode)
994 {
995         if (fcu->grp != NULL && fcu->grp->flag & ADT_CURVES_ALWAYS_VISIBLE) {
996                 return false;
997         }
998         /* hidden items should be skipped if we only care about visible data,
999          * but we aren't interested in hidden stuff */
1000         const bool skip_hidden = (filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN);
1001
1002         if (GS(owner_id->name) == ID_OB) {
1003                 Object *ob = (Object *)owner_id;
1004
1005                 /* only consider if F-Curve involves pose.bones */
1006                 if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) {
1007                         bPoseChannel *pchan;
1008                         char *bone_name;
1009
1010                         /* get bone-name, and check if this bone is selected */
1011                         bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
1012                         pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
1013                         if (bone_name) MEM_freeN(bone_name);
1014
1015                         /* check whether to continue or skip */
1016                         if ((pchan) && (pchan->bone)) {
1017                                 /* if only visible channels, skip if bone not visible unless user wants channels from hidden data too */
1018                                 if (skip_hidden) {
1019                                         bArmature *arm = (bArmature *)ob->data;
1020
1021                                         /* skipping - not visible on currently visible layers */
1022                                         if ((arm->layer & pchan->bone->layer) == 0)
1023                                                 return true;
1024                                         /* skipping - is currently hidden */
1025                                         if (pchan->bone->flag & BONE_HIDDEN_P)
1026                                                 return true;
1027                                 }
1028
1029                                 /* can only add this F-Curve if it is selected */
1030                                 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1031                                         if ((pchan->bone->flag & BONE_SELECTED) == 0)
1032                                                 return true;
1033                                 }
1034                         }
1035                 }
1036         }
1037         else if (GS(owner_id->name) == ID_SCE) {
1038                 Scene *scene = (Scene *)owner_id;
1039
1040                 /* only consider if F-Curve involves sequence_editor.sequences */
1041                 if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
1042                         Editing *ed = BKE_sequencer_editing_get(scene, false);
1043                         Sequence *seq = NULL;
1044                         char *seq_name;
1045
1046                         if (ed) {
1047                                 /* get strip name, and check if this strip is selected */
1048                                 seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
1049                                 seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false);
1050                                 if (seq_name) MEM_freeN(seq_name);
1051                         }
1052
1053                         /* can only add this F-Curve if it is selected */
1054                         if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1055                                 if ((seq == NULL) || (seq->flag & SELECT) == 0)
1056                                         return true;
1057                         }
1058                 }
1059         }
1060         else if (GS(owner_id->name) == ID_NT) {
1061                 bNodeTree *ntree = (bNodeTree *)owner_id;
1062
1063                 /* check for selected nodes */
1064                 if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) {
1065                         bNode *node;
1066                         char *node_name;
1067
1068                         /* get strip name, and check if this strip is selected */
1069                         node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes[");
1070                         node = nodeFindNodebyName(ntree, node_name);
1071                         if (node_name) MEM_freeN(node_name);
1072
1073                         /* can only add this F-Curve if it is selected */
1074                         if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1075                                 if ((node) && (node->flag & NODE_SELECT) == 0)
1076                                         return true;
1077                         }
1078                 }
1079         }
1080
1081         return false;
1082 }
1083
1084 /* Helper for name-based filtering - Perform "partial/fuzzy matches" (as in 80a7efd) */
1085 static bool name_matches_dopesheet_filter(bDopeSheet *ads, char *name)
1086 {
1087         if (ads->flag & ADS_FLAG_FUZZY_NAMES) {
1088                 /* full fuzzy, multi-word, case insensitive matches */
1089                 const size_t str_len = strlen(ads->searchstr);
1090                 const int words_max = (str_len / 2) + 1;
1091
1092                 int (*words)[2] = BLI_array_alloca(words, words_max);
1093                 const int words_len = BLI_string_find_split_words(ads->searchstr, str_len, ' ', words, words_max);
1094                 bool found = false;
1095
1096                 /* match name against all search words */
1097                 for (int index = 0; index < words_len; index++) {
1098                         if (BLI_strncasestr(name, ads->searchstr + words[index][0], words[index][1])) {
1099                                 found = true;
1100                                 break;
1101                         }
1102                 }
1103
1104                 /* if we have a match somewhere, this returns true */
1105                 return found;
1106         }
1107         else {
1108                 /* fallback/default - just case insensitive, but starts from start of word */
1109                 return BLI_strcasestr(name, ads->searchstr) != NULL;
1110         }
1111 }
1112
1113 /* (Display-)Name-based F-Curve filtering
1114  * NOTE: when this function returns true, the F-Curve is to be skipped
1115  */
1116 static bool skip_fcurve_with_name(bDopeSheet *ads, FCurve *fcu, eAnim_ChannelType channel_type, void *owner, ID *owner_id)
1117 {
1118         bAnimListElem ale_dummy = {NULL};
1119         const bAnimChannelType *acf;
1120
1121         /* create a dummy wrapper for the F-Curve, so we can get typeinfo for it */
1122         ale_dummy.type = channel_type;
1123         ale_dummy.owner = owner;
1124         ale_dummy.id = owner_id;
1125         ale_dummy.data = fcu;
1126
1127         /* get type info for channel */
1128         acf = ANIM_channel_get_typeinfo(&ale_dummy);
1129         if (acf && acf->name) {
1130                 char name[256]; /* hopefully this will be enough! */
1131
1132                 /* get name */
1133                 acf->name(&ale_dummy, name);
1134
1135                 /* check for partial match with the match string, assuming case insensitive filtering
1136                  * if match, this channel shouldn't be ignored!
1137                  */
1138                 return !name_matches_dopesheet_filter(ads, name);
1139         }
1140
1141         /* just let this go... */
1142         return true;
1143 }
1144
1145 /**
1146  * Check if F-Curve has errors and/or is disabled
1147  *
1148  * \return true if F-Curve has errors/is disabled
1149  */
1150 static bool fcurve_has_errors(FCurve *fcu)
1151 {
1152         /* F-Curve disabled - path eval error */
1153         if (fcu->flag & FCURVE_DISABLED) {
1154                 return true;
1155         }
1156
1157         /* driver? */
1158         if (fcu->driver) {
1159                 ChannelDriver *driver = fcu->driver;
1160                 DriverVar *dvar;
1161
1162                 /* error flag on driver usually means that there is an error
1163                  * BUT this may not hold with PyDrivers as this flag gets cleared
1164                  *     if no critical errors prevent the driver from working...
1165                  */
1166                 if (driver->flag & DRIVER_FLAG_INVALID)
1167                         return true;
1168
1169                 /* check variables for other things that need linting... */
1170                 // TODO: maybe it would be more efficient just to have a quick flag for this?
1171                 for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
1172                         DRIVER_TARGETS_USED_LOOPER_BEGIN(dvar)
1173                         {
1174                                 if (dtar->flag & DTAR_FLAG_INVALID)
1175                                         return true;
1176                         }
1177                         DRIVER_TARGETS_LOOPER_END;
1178                 }
1179         }
1180
1181         /* no errors found */
1182         return false;
1183 }
1184
1185 /* find the next F-Curve that is usable for inclusion */
1186 static FCurve *animfilter_fcurve_next(bDopeSheet *ads, FCurve *first, eAnim_ChannelType channel_type, int filter_mode, void *owner, ID *owner_id)
1187 {
1188         bActionGroup *grp = (channel_type == ANIMTYPE_FCURVE) ? owner : NULL;
1189         FCurve *fcu = NULL;
1190
1191         /* loop over F-Curves - assume that the caller of this has already checked that these should be included
1192          * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
1193          */
1194         for (fcu = first; ((fcu) && (fcu->grp == grp)); fcu = fcu->next) {
1195                 /* special exception for Pose-Channel/Sequence-Strip/Node Based F-Curves:
1196                  * - the 'Only Selected' and 'Include Hidden' data filters should be applied to sub-ID data which
1197                  *   can be independently selected/hidden, such as Pose-Channels, Sequence Strips, and Nodes.
1198                  *   Since these checks were traditionally done as first check for objects, we do the same here
1199                  * - we currently use an 'approximate' method for getting these F-Curves that doesn't require
1200                  *   carefully checking the entire path
1201                  * - this will also affect things like Drivers, and also works for Bone Constraints
1202                  */
1203                 if (ads && owner_id) {
1204                         if ((filter_mode & ANIMFILTER_TMP_IGNORE_ONLYSEL) == 0) {
1205                                 if ((ads->filterflag & ADS_FILTER_ONLYSEL) || (ads->filterflag & ADS_FILTER_INCL_HIDDEN) == 0) {
1206                                         if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode))
1207                                                 continue;
1208                                 }
1209                         }
1210                 }
1211
1212                 /* only include if visible (Graph Editor check, not channels check) */
1213                 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
1214                         /* only work with this channel and its subchannels if it is editable */
1215                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
1216                                 /* only include this curve if selected in a way consistent with the filtering requirements */
1217                                 if (ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu))) {
1218                                         /* only include if this curve is active */
1219                                         if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
1220                                                 /* name based filtering... */
1221                                                 if ( ((ads) && (ads->searchstr[0] != '\0')) && (owner_id) ) {
1222                                                         if (skip_fcurve_with_name(ads, fcu, channel_type, owner, owner_id))
1223                                                                 continue;
1224                                                 }
1225
1226                                                 /* error-based filtering... */
1227                                                 if ((ads) && (ads->filterflag & ADS_FILTER_ONLY_ERRORS)) {
1228                                                         /* skip if no errors... */
1229                                                         if (fcurve_has_errors(fcu) == false)
1230                                                                 continue;
1231                                                 }
1232
1233                                                 /* this F-Curve can be used, so return it */
1234                                                 return fcu;
1235                                         }
1236                                 }
1237                         }
1238                 }
1239         }
1240
1241         /* no (more) F-Curves from the list are suitable... */
1242         return NULL;
1243 }
1244
1245 static size_t animfilter_fcurves(ListBase *anim_data, bDopeSheet *ads,
1246                                  FCurve *first, eAnim_ChannelType fcurve_type,
1247                                  int filter_mode,
1248                                  void *owner, ID *owner_id, ID *fcurve_owner_id)
1249 {
1250         FCurve *fcu;
1251         size_t items = 0;
1252
1253         /* loop over every F-Curve able to be included
1254          * - this for-loop works like this:
1255          *   1) the starting F-Curve is assigned to the fcu pointer so that we have a starting point to search from
1256          *   2) the first valid F-Curve to start from (which may include the one given as 'first') in the remaining
1257          *      list of F-Curves is found, and verified to be non-null
1258          *   3) the F-Curve referenced by fcu pointer is added to the list
1259          *   4) the fcu pointer is set to the F-Curve after the one we just added, so that we can keep going through
1260          *      the rest of the F-Curve list without an eternal loop. Back to step 2 :)
1261          */
1262         for (fcu = first; ( (fcu = animfilter_fcurve_next(ads, fcu, fcurve_type, filter_mode, owner, owner_id)) ); fcu = fcu->next) {
1263                 if (UNLIKELY(fcurve_type == ANIMTYPE_NLACURVE)) {
1264                         /* NLA Control Curve - Basically the same as normal F-Curves,
1265                          * except we need to set some stuff differently */
1266                         ANIMCHANNEL_NEW_CHANNEL_FULL(fcu, ANIMTYPE_NLACURVE, owner_id, fcurve_owner_id, {
1267                                 ale->owner = owner; /* strip */
1268                                 ale->adt = NULL;    /* to prevent time mapping from causing problems */
1269                         });
1270                 }
1271                 else {
1272                         /* Normal FCurve */
1273                         ANIMCHANNEL_NEW_CHANNEL(fcu, ANIMTYPE_FCURVE, owner_id, fcurve_owner_id);
1274                 }
1275         }
1276
1277         /* return the number of items added to the list */
1278         return items;
1279 }
1280
1281 static size_t animfilter_act_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, bActionGroup *agrp, int filter_mode, ID *owner_id)
1282 {
1283         ListBase tmp_data = {NULL, NULL};
1284         size_t tmp_items = 0;
1285         size_t items = 0;
1286         //int ofilter = filter_mode;
1287
1288         /* if we care about the selection status of the channels,
1289          * but the group isn't expanded (1)...
1290          * (1) this only matters if we actually care about the hierarchy though.
1291          *     - Hierarchy matters: this hack should be applied
1292          *     - Hierarchy ignored: cases like [#21276] won't work properly, unless we skip this hack
1293          */
1294         if (
1295                 /* care about hierarchy but group isn't expanded */
1296                 ((filter_mode & ANIMFILTER_LIST_VISIBLE) && EXPANDED_AGRP(ac, agrp) == 0) &&
1297                 /* care about selection status */
1298                 (filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) )
1299         {
1300                 /* if the group itself isn't selected appropriately, we shouldn't consider it's children either */
1301                 if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0)
1302                         return 0;
1303
1304                 /* if we're still here, then the selection status of the curves within this group should not matter,
1305                  * since this creates too much overhead for animators (i.e. making a slow workflow)
1306                  *
1307                  * Tools affected by this at time of coding (2010 Feb 09):
1308                  * - inserting keyframes on selected channels only
1309                  * - pasting keyframes
1310                  * - creating ghost curves in Graph Editor
1311                  */
1312                 filter_mode &= ~(ANIMFILTER_SEL | ANIMFILTER_UNSEL | ANIMFILTER_LIST_VISIBLE);
1313         }
1314
1315         /* add grouped F-Curves */
1316         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_AGRP(ac, agrp))
1317         {
1318                 /* special filter so that we can get just the F-Curves within the active group */
1319                 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
1320                         /* for the Graph Editor, curves may be set to not be visible in the view to lessen
1321                          * clutter, but to do this, we need to check that the group doesn't have it's
1322                          * not-visible flag set preventing all its sub-curves to be shown
1323                          */
1324                         if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE)) {
1325                                 /* group must be editable for its children to be editable (if we care about this) */
1326                                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
1327                                         /* get first F-Curve which can be used here */
1328                                         FCurve *first_fcu = animfilter_fcurve_next(ads, agrp->channels.first, ANIMTYPE_FCURVE, filter_mode, agrp, owner_id);
1329
1330                                         /* filter list, starting from this F-Curve */
1331                                         tmp_items += animfilter_fcurves(&tmp_data, ads, first_fcu, ANIMTYPE_FCURVE, filter_mode, agrp, owner_id, &act->id);
1332                                 }
1333                         }
1334                 }
1335         }
1336         END_ANIMFILTER_SUBCHANNELS;
1337
1338         /* did we find anything? */
1339         if (tmp_items) {
1340                 /* add this group as a channel first */
1341                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1342                         /* restore original filter mode so that this next step works ok... */
1343                         //filter_mode = ofilter;
1344
1345                         /* filter selection of channel specially here again,
1346                          * since may be open and not subject to previous test */
1347                         if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
1348                                 ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id, NULL);
1349                         }
1350                 }
1351
1352                 /* now add the list of collected channels */
1353                 BLI_movelisttolist(anim_data, &tmp_data);
1354                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1355                 items += tmp_items;
1356         }
1357
1358         /* return the number of items added to the list */
1359         return items;
1360 }
1361
1362 static size_t animfilter_action(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, ID *owner_id)
1363 {
1364         bActionGroup *agrp;
1365         FCurve *lastchan = NULL;
1366         size_t items = 0;
1367
1368         /* don't include anything from this action if it is linked in from another file,
1369          * and we're getting stuff for editing...
1370          */
1371         if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED(act))
1372                 return 0;
1373
1374         /* do groups */
1375         // TODO: do nested groups?
1376         for (agrp = act->groups.first; agrp; agrp = agrp->next) {
1377                 /* store reference to last channel of group */
1378                 if (agrp->channels.last)
1379                         lastchan = agrp->channels.last;
1380
1381                 /* action group's channels */
1382                 items += animfilter_act_group(ac, anim_data, ads, act, agrp, filter_mode, owner_id);
1383         }
1384
1385         /* un-grouped F-Curves (only if we're not only considering those channels in the active group) */
1386         if (!(filter_mode & ANIMFILTER_ACTGROUPED)) {
1387                 FCurve *firstfcu = (lastchan) ? (lastchan->next) : (act->curves.first);
1388                 items += animfilter_fcurves(anim_data, ads, firstfcu, ANIMTYPE_FCURVE, filter_mode, NULL, owner_id, &act->id);
1389         }
1390
1391         /* return the number of items added to the list */
1392         return items;
1393 }
1394
1395 /* Include NLA-Data for NLA-Editor:
1396  * - when ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display
1397  *   Although the evaluation order is from the first track to the last and then apply the Action on top,
1398  *   we present this in the UI as the Active Action followed by the last track to the first so that we
1399  *   get the evaluation order presented as per a stack.
1400  * - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
1401  *   order, i.e. first to last. Otherwise, some tools may get screwed up.
1402  */
1403 static size_t animfilter_nla(bAnimContext *UNUSED(ac), ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1404 {
1405         NlaTrack *nlt;
1406         NlaTrack *first = NULL, *next = NULL;
1407         size_t items = 0;
1408
1409         /* if showing channels, include active action */
1410         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1411                 /* if NLA action-line filtering is off, don't show unless there are keyframes,
1412                  * in order to keep things more compact for doing transforms
1413                  */
1414                 if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) {
1415                         /* there isn't really anything editable here, so skip if need editable */
1416                         if ((filter_mode & ANIMFILTER_FOREDIT) == 0) {
1417                                 /* just add the action track now (this MUST appear for drawing)
1418                                  * - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
1419                                  *   overwrite this with the real value - REVIEW THIS...
1420                                  */
1421                                 ANIMCHANNEL_NEW_CHANNEL_FULL(
1422                                         (void *)(&adt->action), ANIMTYPE_NLAACTION, owner_id, NULL,
1423                                         {
1424                                             ale->data = adt->action ? adt->action : NULL;
1425                                         });
1426                         }
1427                 }
1428
1429                 /* first track to include will be the last one if we're filtering by channels */
1430                 first = adt->nla_tracks.last;
1431         }
1432         else {
1433                 /* first track to include will the first one (as per normal) */
1434                 first = adt->nla_tracks.first;
1435         }
1436
1437         /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
1438         for (nlt = first; nlt; nlt = next) {
1439                 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
1440                 if (filter_mode & ANIMFILTER_LIST_CHANNELS)
1441                         next = nlt->prev;
1442                 else
1443                         next = nlt->next;
1444
1445                 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now
1446                  * - active track should still get shown though (even though it has disabled flag set)
1447                  */
1448                 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
1449                 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && (adt->act_track != nlt))
1450                         continue;
1451
1452                 /* only work with this channel and its subchannels if it is editable */
1453                 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
1454                         /* only include this track if selected in a way consistent with the filtering requirements */
1455                         if (ANIMCHANNEL_SELOK(SEL_NLT(nlt))) {
1456                                 /* only include if this track is active */
1457                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
1458                                         /* name based filtering... */
1459                                         if (((ads) && (ads->searchstr[0] != '\0')) && (owner_id)) {
1460                                                 bool track_ok = false, strip_ok = false;
1461
1462                                                 /* check if the name of the track, or the strips it has are ok... */
1463                                                 track_ok = name_matches_dopesheet_filter(ads, nlt->name);
1464
1465                                                 if (track_ok == false) {
1466                                                         NlaStrip *strip;
1467                                                         for (strip = nlt->strips.first; strip; strip = strip->next) {
1468                                                                 if (name_matches_dopesheet_filter(ads, strip->name)) {
1469                                                                         strip_ok = true;
1470                                                                         break;
1471                                                                 }
1472                                                         }
1473                                                 }
1474
1475                                                 /* skip if both fail this test... */
1476                                                 if (!track_ok && !strip_ok) {
1477                                                         continue;
1478                                                 }
1479                                         }
1480
1481                                         /* add the track now that it has passed all our tests */
1482                                         ANIMCHANNEL_NEW_CHANNEL(nlt, ANIMTYPE_NLATRACK, owner_id, NULL);
1483                                 }
1484                         }
1485                 }
1486         }
1487
1488         /* return the number of items added to the list */
1489         return items;
1490 }
1491
1492 /* Include the control FCurves per NLA Strip in the channel list
1493  * NOTE: This is includes the expander too...
1494  */
1495 static size_t animfilter_nla_controls(ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1496 {
1497         ListBase tmp_data = {NULL, NULL};
1498         size_t tmp_items = 0;
1499         size_t items = 0;
1500
1501         /* add control curves from each NLA strip... */
1502         /* NOTE: ANIMTYPE_FCURVES are created here, to avoid duplicating the code needed */
1503         BEGIN_ANIMFILTER_SUBCHANNELS(((adt->flag & ADT_NLA_SKEYS_COLLAPSED) == 0))
1504         {
1505                 NlaTrack *nlt;
1506                 NlaStrip *strip;
1507
1508                 /* for now, we only go one level deep - so controls on grouped FCurves are not handled */
1509                 for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
1510                         for (strip = nlt->strips.first; strip; strip = strip->next) {
1511                                 /* pass strip as the "owner", so that the name lookups (used while filtering) will resolve */
1512                                 /* NLA tracks are coming from AnimData, so owner of f-curves
1513                                  * is the same as owner of animation data. */
1514                                 tmp_items += animfilter_fcurves(&tmp_data, ads, strip->fcurves.first, ANIMTYPE_NLACURVE,
1515                                                                 filter_mode, strip, owner_id, owner_id);
1516                         }
1517                 }
1518         }
1519         END_ANIMFILTER_SUBCHANNELS;
1520
1521         /* did we find anything? */
1522         if (tmp_items) {
1523                 /* add the expander as a channel first */
1524                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1525                         /* currently these channels cannot be selected, so they should be skipped */
1526                         if ((filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) == 0) {
1527                                 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_NLACONTROLS, owner_id, NULL);
1528                         }
1529                 }
1530
1531                 /* now add the list of collected channels */
1532                 BLI_movelisttolist(anim_data, &tmp_data);
1533                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1534                 items += tmp_items;
1535         }
1536
1537         /* return the number of items added to the list */
1538         return items;
1539 }
1540
1541 /* determine what animation data from AnimData block should get displayed */
1542 static size_t animfilter_block_data(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *id, int filter_mode)
1543 {
1544         AnimData *adt = BKE_animdata_from_id(id);
1545         size_t items = 0;
1546
1547         /* image object datablocks have no anim-data so check for NULL */
1548         if (adt) {
1549                 IdAdtTemplate *iat = (IdAdtTemplate *)id;
1550
1551                 /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed
1552                  * in a few places in the rest of the code still - notably for the few cases where special mode-based
1553                  * different types of data expanders are required.
1554                  */
1555                 ANIMDATA_FILTER_CASES(
1556                         iat,
1557                         { /* AnimData */
1558                             /* specifically filter animdata block */
1559                             if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(adt)) ) {
1560                                 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id, NULL);
1561                             }
1562                         },
1563                         { /* NLA */
1564                             items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
1565                         },
1566                         { /* Drivers */
1567                             items += animfilter_fcurves(anim_data, ads, adt->drivers.first, ANIMTYPE_FCURVE,
1568                                                         filter_mode, NULL, id, id);
1569                         },
1570                         { /* NLA Control Keyframes */
1571                             items += animfilter_nla_controls(anim_data, ads, adt, filter_mode, id);
1572                         },
1573                         { /* Keyframes */
1574                             items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
1575                         }
1576                 );
1577         }
1578
1579         return items;
1580 }
1581
1582
1583
1584 /* Include ShapeKey Data for ShapeKey Editor */
1585 static size_t animdata_filter_shapekey(bAnimContext *ac, ListBase *anim_data, Key *key, int filter_mode)
1586 {
1587         size_t items = 0;
1588
1589         /* check if channels or only F-Curves */
1590         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1591                 KeyBlock *kb;
1592
1593                 /* loop through the channels adding ShapeKeys as appropriate */
1594                 for (kb = key->block.first; kb; kb = kb->next) {
1595                         /* skip the first one, since that's the non-animatable basis */
1596                         if (kb == key->block.first) continue;
1597
1598                         /* only work with this channel and its subchannels if it is editable */
1599                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) {
1600                                 /* only include this track if selected in a way consistent with the filtering requirements */
1601                                 if (ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb)) ) {
1602                                         // TODO: consider 'active' too?
1603
1604                                         /* owner-id here must be key so that the F-Curve can be resolved... */
1605                                         ANIMCHANNEL_NEW_CHANNEL(kb, ANIMTYPE_SHAPEKEY, key, NULL);
1606                                 }
1607                         }
1608                 }
1609         }
1610         else {
1611                 /* just use the action associated with the shapekey */
1612                 // TODO: somehow manage to pass dopesheet info down here too?
1613                 if (key->adt) {
1614                         if (filter_mode & ANIMFILTER_ANIMDATA) {
1615                                 if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(key->adt)) ) {
1616                                         ANIMCHANNEL_NEW_CHANNEL(key->adt, ANIMTYPE_ANIMDATA, key, NULL);
1617                                 }
1618                         }
1619                         else if (key->adt->action) {
1620                                 items = animfilter_action(ac, anim_data, NULL, key->adt->action, filter_mode, (ID *)key);
1621                         }
1622                 }
1623         }
1624
1625         /* return the number of items added to the list */
1626         return items;
1627 }
1628
1629 /* Helper for Grease Pencil - layers within a datablock */
1630 static size_t animdata_filter_gpencil_layers_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1631 {
1632         bGPDlayer *gpl;
1633         size_t items = 0;
1634
1635         /* loop over layers as the conditions are acceptable (top-Down order) */
1636         for (gpl = gpd->layers.last; gpl; gpl = gpl->prev) {
1637                 /* only if selected */
1638                 if (ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
1639                         /* only if editable */
1640                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
1641                                 /* active... */
1642                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (gpl->flag & GP_LAYER_ACTIVE)) {
1643                                         /* skip layer if the name doesn't match the filter string */
1644                                         if ((ads) && (ads->searchstr[0] != '\0')) {
1645                                                 if (name_matches_dopesheet_filter(ads, gpl->info) == false)
1646                                                         continue;
1647                                         }
1648                                         /* add to list */
1649                                         ANIMCHANNEL_NEW_CHANNEL(gpl, ANIMTYPE_GPLAYER, gpd, NULL);
1650                                 }
1651                         }
1652                 }
1653         }
1654
1655         return items;
1656 }
1657
1658 /* Helper for Grease Pencil - Grease Pencil datablock - GP Frames */
1659 static size_t animdata_filter_gpencil_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1660 {
1661         size_t items = 0;
1662
1663         /* When asked from "AnimData" blocks (i.e. the top-level containers for normal animation),
1664          * for convenience, this will return GP Datablocks instead. This may cause issues down
1665          * the track, but for now, this will do...
1666          */
1667         if (filter_mode & ANIMFILTER_ANIMDATA) {
1668                 /* just add GPD as a channel - this will add everything needed */
1669                 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, gpd, NULL);
1670         }
1671         else {
1672                 ListBase tmp_data = {NULL, NULL};
1673                 size_t tmp_items = 0;
1674
1675                 /* add gpencil animation channels */
1676                 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1677                 {
1678                         tmp_items += animdata_filter_gpencil_layers_data(&tmp_data, ads, gpd, filter_mode);
1679                 }
1680                 END_ANIMFILTER_SUBCHANNELS;
1681
1682                 /* did we find anything? */
1683                 if (tmp_items) {
1684                         /* include data-expand widget first */
1685                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1686                                 /* add gpd as channel too (if for drawing, and it has layers) */
1687                                 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL, NULL);
1688                         }
1689
1690                         /* now add the list of collected channels */
1691                         BLI_movelisttolist(anim_data, &tmp_data);
1692                         BLI_assert(BLI_listbase_is_empty(&tmp_data));
1693                         items += tmp_items;
1694                 }
1695         }
1696
1697         return items;
1698 }
1699
1700 /* Grab all Grease Pencil datablocks in file */
1701 // TODO: should this be amalgamated with the dopesheet filtering code?
1702 static size_t animdata_filter_gpencil(bAnimContext *ac, ListBase *anim_data, void *UNUSED(data), int filter_mode)
1703 {
1704         bDopeSheet *ads = ac->ads;
1705         size_t items = 0;
1706
1707         if (ads->filterflag & ADS_FILTER_GP_3DONLY) {
1708                 Scene *scene = (Scene *)ads->source;
1709                 ViewLayer *view_layer = (ViewLayer *)ac->view_layer;
1710                 Base *base;
1711
1712                 /* Active scene's GPencil block first - No parent item needed... */
1713                 if (scene->gpd) {
1714                         items += animdata_filter_gpencil_data(anim_data, ads, scene->gpd, filter_mode);
1715                 }
1716
1717                 /* Objects in the scene */
1718                 for (base = view_layer->object_bases.first; base; base = base->next) {
1719                         /* Only consider this object if it has got some GP data (saving on all the other tests) */
1720                         if (base->object && (base->object->type == OB_GPENCIL)) {
1721                                 Object *ob = base->object;
1722
1723                                 /* firstly, check if object can be included, by the following factors:
1724                                  * - if only visible, must check for layer and also viewport visibility
1725                                  *   --> while tools may demand only visible, user setting takes priority
1726                                  *       as user option controls whether sets of channels get included while
1727                                  *       tool-flag takes into account collapsed/open channels too
1728                                  * - if only selected, must check if object is selected
1729                                  * - there must be animation data to edit (this is done recursively as we
1730                                  *   try to add the channels)
1731                                  */
1732                                 if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
1733                                         /* layer visibility - we check both object and base, since these may not be in sync yet */
1734                                         if ((base->flag & BASE_VISIBLE) == 0) continue;
1735
1736                                         /* outliner restrict-flag */
1737                                         if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1738                                 }
1739
1740                                 /* check selection and object type filters */
1741                                 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED) /*|| (base == scene->basact)*/) ) {
1742                                         /* only selected should be shown */
1743                                         continue;
1744                                 }
1745
1746                                 /* check if object belongs to the filtering group if option to filter
1747                                  * objects by the grouped status is on
1748                                  * - used to ease the process of doing multiple-character choreographies
1749                                  */
1750                                 if (ads->filter_grp != NULL) {
1751                                         if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0)
1752                                                 continue;
1753                                 }
1754
1755                                 /* finally, include this object's grease pencil datablock */
1756                                 /* XXX: Should we store these under expanders per item? */
1757                                 items += animdata_filter_gpencil_data(anim_data, ads, ob->data, filter_mode);
1758                         }
1759                 }
1760         }
1761         else {
1762                 bGPdata *gpd;
1763
1764                 /* Grab all Grease Pencil datablocks directly from main,
1765                  * but only those that seem to be useful somewhere */
1766                 for (gpd = ac->bmain->gpencils.first; gpd; gpd = gpd->id.next) {
1767                         /* only show if gpd is used by something... */
1768                         if (ID_REAL_USERS(gpd) < 1)
1769                                 continue;
1770
1771                         /* add GP frames from this datablock */
1772                         items += animdata_filter_gpencil_data(anim_data, ads, gpd, filter_mode);
1773                 }
1774         }
1775
1776         /* return the number of items added to the list */
1777         return items;
1778 }
1779
1780 /* Helper for Grease Pencil data integrated with main DopeSheet */
1781 static size_t animdata_filter_ds_gpencil(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1782 {
1783         ListBase tmp_data = {NULL, NULL};
1784         size_t tmp_items = 0;
1785         size_t items = 0;
1786
1787         /* add relevant animation channels for Grease Pencil */
1788         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1789         {
1790                 /* add animation channels */
1791                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, &gpd->id, filter_mode);
1792
1793                 /* add Grease Pencil layers */
1794                 // TODO: do these need a separate expander?
1795                 // XXX:  what order should these go in?
1796         }
1797         END_ANIMFILTER_SUBCHANNELS;
1798
1799         /* did we find anything? */
1800         if (tmp_items) {
1801                 /* include data-expand widget first */
1802                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1803                         /* check if filtering by active status */
1804                         // XXX: active check here needs checking
1805                         if (ANIMCHANNEL_ACTIVEOK(gpd)) {
1806                                 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_DSGPENCIL, gpd, NULL);
1807                         }
1808                 }
1809
1810                 /* now add the list of collected channels */
1811                 BLI_movelisttolist(anim_data, &tmp_data);
1812                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1813                 items += tmp_items;
1814         }
1815
1816         /* return the number of items added to the list */
1817         return items;
1818 }
1819
1820 /* Helper for Cache File data integrated with main DopeSheet */
1821 static size_t animdata_filter_ds_cachefile(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, CacheFile *cache_file, int filter_mode)
1822 {
1823         ListBase tmp_data = {NULL, NULL};
1824         size_t tmp_items = 0;
1825         size_t items = 0;
1826
1827         /* add relevant animation channels for Cache File */
1828         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_CACHEFILE_OBJD(cache_file))
1829         {
1830                 /* add animation channels */
1831                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, &cache_file->id, filter_mode);
1832         }
1833         END_ANIMFILTER_SUBCHANNELS;
1834
1835         /* did we find anything? */
1836         if (tmp_items) {
1837                 /* include data-expand widget first */
1838                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1839                         /* check if filtering by active status */
1840                         // XXX: active check here needs checking
1841                         if (ANIMCHANNEL_ACTIVEOK(cache_file)) {
1842                                 ANIMCHANNEL_NEW_CHANNEL(cache_file, ANIMTYPE_DSCACHEFILE, cache_file, NULL);
1843                         }
1844                 }
1845
1846                 /* now add the list of collected channels */
1847                 BLI_movelisttolist(anim_data, &tmp_data);
1848                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1849                 items += tmp_items;
1850         }
1851
1852         /* return the number of items added to the list */
1853         return items;
1854 }
1855
1856 /* Helper for Mask Editing - mask layers */
1857 static size_t animdata_filter_mask_data(ListBase *anim_data, Mask *mask, const int filter_mode)
1858 {
1859         MaskLayer *masklay_act = BKE_mask_layer_active(mask);
1860         MaskLayer *masklay;
1861         size_t items = 0;
1862
1863         /* loop over layers as the conditions are acceptable */
1864         for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
1865                 /* only if selected */
1866                 if (ANIMCHANNEL_SELOK(SEL_MASKLAY(masklay)) ) {
1867                         /* only if editable */
1868                         if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_MASK(masklay)) {
1869                                 /* active... */
1870                                 if (!(filter_mode & ANIMFILTER_ACTIVE) || (masklay_act == masklay)) {
1871                                         /* add to list */
1872                                         ANIMCHANNEL_NEW_CHANNEL(masklay, ANIMTYPE_MASKLAYER, mask, NULL);
1873                                 }
1874                         }
1875                 }
1876         }
1877
1878         return items;
1879 }
1880
1881 /* Grab all mask data */
1882 static size_t animdata_filter_mask(Main *bmain, ListBase *anim_data, void *UNUSED(data), int filter_mode)
1883 {
1884         Mask *mask;
1885         size_t items = 0;
1886
1887         /* for now, grab mask datablocks directly from main */
1888         // XXX: this is not good...
1889         for (mask = bmain->masks.first; mask; mask = mask->id.next) {
1890                 ListBase tmp_data = {NULL, NULL};
1891                 size_t tmp_items = 0;
1892
1893                 /* only show if mask is used by something... */
1894                 if (ID_REAL_USERS(mask) < 1)
1895                         continue;
1896
1897                 /* add mask animation channels */
1898                 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MASK(mask))
1899                 {
1900                         tmp_items += animdata_filter_mask_data(&tmp_data, mask, filter_mode);
1901                 }
1902                 END_ANIMFILTER_SUBCHANNELS;
1903
1904                 /* did we find anything? */
1905                 if (tmp_items) {
1906                         /* include data-expand widget first */
1907                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1908                                 /* add mask datablock as channel too (if for drawing, and it has layers) */
1909                                 ANIMCHANNEL_NEW_CHANNEL(mask, ANIMTYPE_MASKDATABLOCK, NULL, NULL);
1910                         }
1911
1912                         /* now add the list of collected channels */
1913                         BLI_movelisttolist(anim_data, &tmp_data);
1914                         BLI_assert(BLI_listbase_is_empty(&tmp_data));
1915                         items += tmp_items;
1916                 }
1917         }
1918
1919         /* return the number of items added to the list */
1920         return items;
1921 }
1922
1923 /* NOTE: owner_id is scene, material, or texture block, which is the direct owner of the node tree in question */
1924 static size_t animdata_filter_ds_nodetree_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1925 {
1926         ListBase tmp_data = {NULL, NULL};
1927         size_t tmp_items = 0;
1928         size_t items = 0;
1929
1930         /* add nodetree animation channels */
1931         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_NTREE_DATA(ntree))
1932         {
1933                 /* animation data filtering */
1934                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ntree, filter_mode);
1935         }
1936         END_ANIMFILTER_SUBCHANNELS;
1937
1938         /* did we find anything? */
1939         if (tmp_items) {
1940                 /* include data-expand widget first */
1941                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1942                         /* check if filtering by active status */
1943                         if (ANIMCHANNEL_ACTIVEOK(ntree)) {
1944                                 ANIMCHANNEL_NEW_CHANNEL(ntree, ANIMTYPE_DSNTREE, owner_id, NULL);
1945                         }
1946                 }
1947
1948                 /* now add the list of collected channels */
1949                 BLI_movelisttolist(anim_data, &tmp_data);
1950                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1951                 items += tmp_items;
1952         }
1953
1954         /* return the number of items added to the list */
1955         return items;
1956 }
1957
1958 static size_t animdata_filter_ds_nodetree(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1959 {
1960         bNode *node;
1961         size_t items = 0;
1962
1963         items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, ntree, filter_mode);
1964
1965         for (node = ntree->nodes.first; node; node = node->next) {
1966                 if (node->type == NODE_GROUP) {
1967                         if (node->id) {
1968                                 if ((ads->filterflag & ADS_FILTER_ONLYSEL) && (node->flag & NODE_SELECT) == 0) {
1969                                         continue;
1970                                 }
1971                                 items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, (bNodeTree *) node->id,
1972                                                                            filter_mode | ANIMFILTER_TMP_IGNORE_ONLYSEL);
1973                         }
1974                 }
1975         }
1976
1977         return items;
1978 }
1979
1980 static size_t animdata_filter_ds_linestyle(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1981 {
1982         ViewLayer *view_layer;
1983         FreestyleLineSet *lineset;
1984         size_t items = 0;
1985
1986         for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
1987                 for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
1988                         if (lineset->linestyle) {
1989                                 lineset->linestyle->id.tag |= LIB_TAG_DOIT;
1990                         }
1991                 }
1992         }
1993
1994         for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
1995                 /* skip render layers without Freestyle enabled */
1996                 if ((view_layer->flag & VIEW_LAYER_FREESTYLE) == 0) {
1997                         continue;
1998                 }
1999
2000                 /* loop over linesets defined in the render layer */
2001                 for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
2002                         FreestyleLineStyle *linestyle = lineset->linestyle;
2003                         ListBase tmp_data = {NULL, NULL};
2004                         size_t tmp_items = 0;
2005
2006                         if ((linestyle == NULL) ||
2007                             !(linestyle->id.tag & LIB_TAG_DOIT))
2008                         {
2009                                 continue;
2010                         }
2011                         linestyle->id.tag &= ~LIB_TAG_DOIT;
2012
2013                         /* add scene-level animation channels */
2014                         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle))
2015                         {
2016                                 /* animation data filtering */
2017                                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
2018                         }
2019                         END_ANIMFILTER_SUBCHANNELS;
2020
2021                         /* did we find anything? */
2022                         if (tmp_items) {
2023                                 /* include anim-expand widget first */
2024                                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2025                                         /* check if filtering by active status */
2026                                         if (ANIMCHANNEL_ACTIVEOK(linestyle)) {
2027                                                 ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce, NULL);
2028                                         }
2029                                 }
2030
2031                                 /* now add the list of collected channels */
2032                                 BLI_movelisttolist(anim_data, &tmp_data);
2033                                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2034                                 items += tmp_items;
2035                         }
2036                 }
2037         }
2038
2039         /* return the number of items added to the list */
2040         return items;
2041 }
2042
2043 static size_t animdata_filter_ds_texture(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads,
2044                                          Tex *tex, ID *owner_id, int filter_mode)
2045 {
2046         ListBase tmp_data = {NULL, NULL};
2047         size_t tmp_items = 0;
2048         size_t items = 0;
2049
2050         /* add texture's animation data to temp collection */
2051         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_TEX_DATA(tex))
2052         {
2053                 /* texture animdata */
2054                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)tex, filter_mode);
2055
2056                 /* nodes */
2057                 if ((tex->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2058                         /* owner_id as id instead of texture, since it'll otherwise be impossible to track the depth */
2059                         // FIXME: perhaps as a result, textures should NOT be included under materials, but under their own section instead
2060                         // so that free-floating textures can also be animated
2061                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)tex, tex->nodetree, filter_mode);
2062                 }
2063         }
2064         END_ANIMFILTER_SUBCHANNELS;
2065
2066         /* did we find anything? */
2067         if (tmp_items) {
2068                 /* include texture-expand widget? */
2069                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2070                         /* check if filtering by active status */
2071                         if (ANIMCHANNEL_ACTIVEOK(tex)) {
2072                                 ANIMCHANNEL_NEW_CHANNEL(tex, ANIMTYPE_DSTEX, owner_id, NULL);
2073                         }
2074                 }
2075
2076                 /* now add the list of collected channels */
2077                 BLI_movelisttolist(anim_data, &tmp_data);
2078                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2079                 items += tmp_items;
2080         }
2081
2082         /* return the number of items added to the list */
2083         return items;
2084 }
2085
2086 /* NOTE: owner_id is the direct owner of the texture stack in question
2087  *       It used to be Material/Light/World before the Blender Internal removal for 2.8
2088  */
2089 static size_t animdata_filter_ds_textures(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
2090 {
2091         MTex **mtex = NULL;
2092         size_t items = 0;
2093         int a = 0;
2094
2095         /* get datatype specific data first */
2096         if (owner_id == NULL)
2097                 return 0;
2098
2099         switch (GS(owner_id->name)) {
2100                 case ID_PA:
2101                 {
2102                         ParticleSettings *part = (ParticleSettings *)owner_id;
2103                         mtex = (MTex **)(&part->mtex);
2104                         break;
2105                 }
2106                 default:
2107                 {
2108                         /* invalid/unsupported option */
2109                         if (G.debug & G_DEBUG)
2110                                 printf("ERROR: Unsupported owner_id (i.e. texture stack) for filter textures - %s\n", owner_id->name);
2111                         return 0;
2112                 }
2113         }
2114
2115         /* firstly check that we actuallly have some textures, by gathering all textures in a temp list */
2116         for (a = 0; a < MAX_MTEX; a++) {
2117                 Tex *tex = (mtex[a]) ? mtex[a]->tex : NULL;
2118
2119                 /* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */
2120                 if (tex == NULL)
2121                         continue;
2122
2123                 /* add texture's anim channels */
2124                 items += animdata_filter_ds_texture(ac, anim_data, ads, tex, owner_id, filter_mode);
2125         }
2126
2127         /* return the number of items added to the list */
2128         return items;
2129 }
2130
2131
2132 static size_t animdata_filter_ds_material(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Material *ma, int filter_mode)
2133 {
2134         ListBase tmp_data = {NULL, NULL};
2135         size_t tmp_items = 0;
2136         size_t items = 0;
2137
2138         /* add material's animation data to temp collection */
2139         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_MAT_OBJD(ma))
2140         {
2141                 /* material's animation data */
2142                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode);
2143
2144                 /* nodes */
2145                 if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2146                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode);
2147         }
2148         END_ANIMFILTER_SUBCHANNELS;
2149
2150         /* did we find anything? */
2151         if (tmp_items) {
2152                 /* include material-expand widget first */
2153                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2154                         /* check if filtering by active status */
2155                         if (ANIMCHANNEL_ACTIVEOK(ma)) {
2156                                 ANIMCHANNEL_NEW_CHANNEL(ma, ANIMTYPE_DSMAT, ma, NULL);
2157                         }
2158                 }
2159
2160                 /* now add the list of collected channels */
2161                 BLI_movelisttolist(anim_data, &tmp_data);
2162                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2163                 items += tmp_items;
2164         }
2165
2166         return items;
2167 }
2168
2169 static size_t animdata_filter_ds_materials(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2170 {
2171         bool has_nested = false;
2172         size_t items = 0;
2173         int a = 0;
2174
2175         /* first pass: take the materials referenced via the Material slots of the object */
2176         for (a = 1; a <= ob->totcol; a++) {
2177                 Material *ma = give_current_material(ob, a);
2178
2179                 /* if material is valid, try to add relevant contents from here */
2180                 if (ma) {
2181                         /* add channels */
2182                         items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2183
2184                         /* for optimising second pass - check if there's a nested material here to come back for */
2185                         if (has_nested == false) {
2186                                 has_nested = (give_node_material(ma) != NULL);
2187                         }
2188                 }
2189         }
2190
2191         /* second pass: go through a second time looking for "nested" materials (material.material references)
2192          *
2193          * NOTE: here we ignore the expanded status of the parent, as it could be too confusing as to why these are
2194          *       disappearing/not available, since the relationships between these is not that clear
2195          */
2196         if (has_nested) {
2197                 for (a = 1; a <= ob->totcol; a++) {
2198                         Material *base = give_current_material(ob, a);
2199                         Material *ma   = give_node_material(base);
2200
2201                         /* add channels from the nested material if it exists
2202                          *   - skip if the same material is referenced in its node tree
2203                          *     (which is common for BI materials) as that results in
2204                          *     confusing duplicates
2205                          */
2206                         if ((ma) && (ma != base)) {
2207                                 items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2208                         }
2209                 }
2210         }
2211
2212         /* return the number of items added to the list */
2213         return items;
2214 }
2215
2216
2217 /* ............ */
2218
2219 /* Temporary context for modifier linked-data channel extraction */
2220 typedef struct tAnimFilterModifiersContext {
2221         bAnimContext *ac;       /* anim editor context */
2222         bDopeSheet *ads;    /* dopesheet filtering settings */
2223
2224         ListBase tmp_data;  /* list of channels created (but not yet added to the main list) */
2225         size_t items;       /* number of channels created */
2226
2227         int filter_mode;    /* flags for stuff we want to filter */
2228 } tAnimFilterModifiersContext;
2229
2230
2231 /* dependency walker callback for modifier dependencies */
2232 static void animfilter_modifier_idpoin_cb(void *afm_ptr, Object *ob, ID **idpoin, int UNUSED(cb_flag))
2233 {
2234         tAnimFilterModifiersContext *afm = (tAnimFilterModifiersContext *)afm_ptr;
2235         ID *owner_id = &ob->id;
2236         ID *id = *idpoin;
2237
2238         /* NOTE: the walker only guarantees to give us all the ID-ptr *slots*,
2239          * not just the ones which are actually used, so be careful!
2240          */
2241         if (id == NULL)
2242                 return;
2243
2244         /* check if this is something we're interested in... */
2245         switch (GS(id->name)) {
2246                 case ID_TE: /* Textures */
2247                 {
2248                         Tex *tex = (Tex *)id;
2249                         if (!(afm->ads->filterflag & ADS_FILTER_NOTEX)) {
2250                                 afm->items += animdata_filter_ds_texture(afm->ac, &afm->tmp_data, afm->ads, tex, owner_id, afm->filter_mode);
2251                         }
2252                         break;
2253                 }
2254
2255                 /* TODO: images? */
2256                 default:
2257                         break;
2258         }
2259 }
2260
2261 /* animation linked to data used by modifiers
2262  * NOTE: strictly speaking, modifier animation is already included under Object level
2263  *       but for some modifiers (e.g. Displace), there can be linked data that has settings
2264  *       which would be nice to animate (i.e. texture parameters) but which are not actually
2265  *       attached to any other objects/materials/etc. in the scene
2266  */
2267 // TODO: do we want an expander for this?
2268 static size_t animdata_filter_ds_modifiers(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2269 {
2270         tAnimFilterModifiersContext afm = {NULL};
2271         size_t items = 0;
2272
2273         /* 1) create a temporary "context" containing all the info we have here to pass to the callback
2274          *    use to walk through the dependencies of the modifiers
2275          *
2276          * ! Assumes that all other unspecified values (i.e. accumulation buffers) are zero'd out properly
2277          */
2278         afm.ac          = ac;
2279         afm.ads         = ads;
2280         afm.filter_mode = filter_mode;
2281
2282         /* 2) walk over dependencies */
2283         modifiers_foreachIDLink(ob, animfilter_modifier_idpoin_cb, &afm);
2284
2285         /* 3) extract data from the context, merging it back into the standard list */
2286         if (afm.items) {
2287                 /* now add the list of collected channels */
2288                 BLI_movelisttolist(anim_data, &afm.tmp_data);
2289                 BLI_assert(BLI_listbase_is_empty(&afm.tmp_data));
2290                 items += afm.items;
2291         }
2292
2293         return items;
2294 }
2295
2296 /* ............ */
2297
2298
2299 static size_t animdata_filter_ds_particles(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2300 {
2301         ParticleSystem *psys;
2302         size_t items = 0;
2303
2304         for (psys = ob->particlesystem.first; psys; psys = psys->next) {
2305                 ListBase tmp_data = {NULL, NULL};
2306                 size_t tmp_items = 0;
2307
2308                 /* if no material returned, skip - so that we don't get weird blank entries... */
2309                 if (ELEM(NULL, psys->part, psys->part->adt))
2310                         continue;
2311
2312                 /* add particle-system's animation data to temp collection */
2313                 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_PART_OBJD(psys->part))
2314                 {
2315                         /* particle system's animation data */
2316                         tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2317
2318                         /* textures */
2319                         if (!(ads->filterflag & ADS_FILTER_NOTEX))
2320                                 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2321                 }
2322                 END_ANIMFILTER_SUBCHANNELS;
2323
2324                 /* did we find anything? */
2325                 if (tmp_items) {
2326                         /* include particle-expand widget first */
2327                         if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2328                                 /* check if filtering by active status */
2329                                 if (ANIMCHANNEL_ACTIVEOK(psys->part)) {
2330                                         ANIMCHANNEL_NEW_CHANNEL(psys->part, ANIMTYPE_DSPART, psys->part, NULL);
2331                                 }
2332                         }
2333
2334                         /* now add the list of collected channels */
2335                         BLI_movelisttolist(anim_data, &tmp_data);
2336                         BLI_assert(BLI_listbase_is_empty(&tmp_data));
2337                         items += tmp_items;
2338                 }
2339         }
2340
2341         /* return the number of items added to the list */
2342         return items;
2343 }
2344
2345
2346 static size_t animdata_filter_ds_obdata(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2347 {
2348         ListBase tmp_data = {NULL, NULL};
2349         size_t tmp_items = 0;
2350         size_t items = 0;
2351
2352         IdAdtTemplate *iat = ob->data;
2353         short type = 0, expanded = 0;
2354
2355         /* get settings based on data type */
2356         switch (ob->type) {
2357                 case OB_CAMERA: /* ------- Camera ------------ */
2358                 {
2359                         Camera *ca = (Camera *)ob->data;
2360
2361                         if (ads->filterflag & ADS_FILTER_NOCAM)
2362                                 return 0;
2363
2364                         type = ANIMTYPE_DSCAM;
2365                         expanded = FILTER_CAM_OBJD(ca);
2366                         break;
2367                 }
2368                 case OB_LAMP: /* ---------- Light ----------- */
2369                 {
2370                         Light *la = (Light *)ob->data;
2371
2372                         if (ads->filterflag & ADS_FILTER_NOLAM)
2373                                 return 0;
2374
2375                         type = ANIMTYPE_DSLAM;
2376                         expanded = FILTER_LAM_OBJD(la);
2377                         break;
2378                 }
2379                 case OB_CURVE: /* ------- Curve ---------- */
2380                 case OB_SURF: /* ------- Nurbs Surface ---------- */
2381                 case OB_FONT: /* ------- Text Curve ---------- */
2382                 {
2383                         Curve *cu = (Curve *)ob->data;
2384
2385                         if (ads->filterflag & ADS_FILTER_NOCUR)
2386                                 return 0;
2387
2388                         type = ANIMTYPE_DSCUR;
2389                         expanded = FILTER_CUR_OBJD(cu);
2390                         break;
2391                 }
2392                 case OB_MBALL: /* ------- MetaBall ---------- */
2393                 {
2394                         MetaBall *mb = (MetaBall *)ob->data;
2395
2396                         if (ads->filterflag & ADS_FILTER_NOMBA)
2397                                 return 0;
2398
2399                         type = ANIMTYPE_DSMBALL;
2400                         expanded = FILTER_MBALL_OBJD(mb);
2401                         break;
2402                 }
2403                 case OB_ARMATURE: /* ------- Armature ---------- */
2404                 {
2405                         bArmature *arm = (bArmature *)ob->data;
2406
2407                         if (ads->filterflag & ADS_FILTER_NOARM)
2408                                 return 0;
2409
2410                         type = ANIMTYPE_DSARM;
2411                         expanded = FILTER_ARM_OBJD(arm);
2412                         break;
2413                 }
2414                 case OB_MESH: /* ------- Mesh ---------- */
2415                 {
2416                         Mesh *me = (Mesh *)ob->data;
2417
2418                         if (ads->filterflag & ADS_FILTER_NOMESH)
2419                                 return 0;
2420
2421                         type = ANIMTYPE_DSMESH;
2422                         expanded = FILTER_MESH_OBJD(me);
2423                         break;
2424                 }
2425                 case OB_LATTICE: /* ---- Lattice ---- */
2426                 {
2427                         Lattice *lt = (Lattice *)ob->data;
2428
2429                         if (ads->filterflag & ADS_FILTER_NOLAT)
2430                                 return 0;
2431
2432                         type = ANIMTYPE_DSLAT;
2433                         expanded = FILTER_LATTICE_OBJD(lt);
2434                         break;
2435                 }
2436                 case OB_SPEAKER: /* ---------- Speaker ----------- */
2437                 {
2438                         Speaker *spk = (Speaker *)ob->data;
2439
2440                         type = ANIMTYPE_DSSPK;
2441                         expanded = FILTER_SPK_OBJD(spk);
2442                         break;
2443                 }
2444         }
2445
2446         /* add object data animation channels */
2447         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2448         {
2449                 /* animation data filtering */
2450                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)iat, filter_mode);
2451
2452                 /* sub-data filtering... */
2453                 switch (ob->type) {
2454                         case OB_LAMP:  /* light - textures + nodetree */
2455                         {
2456                                 Light *la = ob->data;
2457                                 bNodeTree *ntree = la->nodetree;
2458
2459                                 /* nodetree */
2460                                 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2461                                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, &la->id, ntree, filter_mode);
2462                                 break;
2463                         }
2464                 }
2465         }
2466         END_ANIMFILTER_SUBCHANNELS;
2467
2468         /* did we find anything? */
2469         if (tmp_items) {
2470                 /* include data-expand widget first */
2471                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2472                         /* check if filtering by active status */
2473                         if (ANIMCHANNEL_ACTIVEOK(iat)) {
2474                                 ANIMCHANNEL_NEW_CHANNEL(iat, type, iat, NULL);
2475                         }
2476                 }
2477
2478                 /* now add the list of collected channels */
2479                 BLI_movelisttolist(anim_data, &tmp_data);
2480                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2481                 items += tmp_items;
2482         }
2483
2484         /* return the number of items added to the list */
2485         return items;
2486 }
2487
2488 /* shapekey-level animation */
2489 static size_t animdata_filter_ds_keyanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, Key *key, int filter_mode)
2490 {
2491         ListBase tmp_data = {NULL, NULL};
2492         size_t tmp_items = 0;
2493         size_t items = 0;
2494
2495         /* add shapekey-level animation channels */
2496         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_SKE_OBJD(key))
2497         {
2498                 /* animation data filtering */
2499                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)key, filter_mode);
2500         }
2501         END_ANIMFILTER_SUBCHANNELS;
2502
2503         /* did we find anything? */
2504         if (tmp_items) {
2505                 /* include key-expand widget first */
2506                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2507                         if (ANIMCHANNEL_ACTIVEOK(key)) {
2508                                 ANIMCHANNEL_NEW_CHANNEL(key, ANIMTYPE_DSSKEY, ob, NULL);
2509                         }
2510                 }
2511
2512                 /* now add the list of collected channels */
2513                 BLI_movelisttolist(anim_data, &tmp_data);
2514                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2515                 items += tmp_items;
2516         }
2517
2518         /* return the number of items added to the list */
2519         return items;
2520 }
2521
2522
2523 /* object-level animation */
2524 static size_t animdata_filter_ds_obanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2525 {
2526         ListBase tmp_data = {NULL, NULL};
2527         size_t tmp_items = 0;
2528         size_t items = 0;
2529
2530         AnimData *adt = ob->adt;
2531         short type = 0, expanded = 1;
2532         void *cdata = NULL;
2533
2534         /* determine the type of expander channels to use */
2535         /* this is the best way to do this for now... */
2536         ANIMDATA_FILTER_CASES(
2537                 ob,
2538                 { /* AnimData - no channel, but consider data */ },
2539                 { /* NLA - no channel, but consider data */ },
2540                 { /* Drivers */
2541                     type = ANIMTYPE_FILLDRIVERS;
2542                     cdata = adt;
2543                     expanded = EXPANDED_DRVD(adt);
2544                 },
2545                 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2546                 { /* Keyframes */
2547                     type = ANIMTYPE_FILLACTD;
2548                     cdata = adt->action;
2549                     expanded = EXPANDED_ACTC(adt->action);
2550                 });
2551
2552         /* add object-level animation channels */
2553         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2554         {
2555                 /* animation data filtering */
2556                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ob, filter_mode);
2557         }
2558         END_ANIMFILTER_SUBCHANNELS;
2559
2560         /* did we find anything? */
2561         if (tmp_items) {
2562                 /* include anim-expand widget first */
2563                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2564                         if (type != ANIMTYPE_NONE) {
2565                                 /* NOTE: active-status (and the associated checks) don't apply here... */
2566                                 ANIMCHANNEL_NEW_CHANNEL(cdata, type, ob, NULL);
2567                         }
2568                 }
2569
2570                 /* now add the list of collected channels */
2571                 BLI_movelisttolist(anim_data, &tmp_data);
2572                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2573                 items += tmp_items;
2574         }
2575
2576         /* return the number of items added to the list */
2577         return items;
2578 }
2579
2580 /* get animation channels from object2 */
2581 static size_t animdata_filter_dopesheet_ob(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
2582 {
2583         ListBase tmp_data = {NULL, NULL};
2584         Object *ob = base->object;
2585         size_t tmp_items = 0;
2586         size_t items = 0;
2587
2588         /* filter data contained under object first */
2589         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_OBJC(ob))
2590         {
2591                 Key *key = BKE_key_from_object(ob);
2592
2593                 /* object-level animation */
2594                 if ((ob->adt) && !(ads->filterflag & ADS_FILTER_NOOBJ)) {
2595                         tmp_items += animdata_filter_ds_obanim(ac, &tmp_data, ads, ob, filter_mode);
2596                 }
2597
2598                 /* shape-key */
2599                 if ((key && key->adt) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
2600                         tmp_items += animdata_filter_ds_keyanim(ac, &tmp_data, ads, ob, key, filter_mode);
2601                 }
2602
2603                 /* modifiers */
2604                 if ((ob->modifiers.first) && !(ads->filterflag & ADS_FILTER_NOMODIFIERS)) {
2605                         tmp_items += animdata_filter_ds_modifiers(ac, &tmp_data, ads, ob, filter_mode);
2606                 }
2607
2608                 /* materials */
2609                 if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT)) {
2610                         tmp_items += animdata_filter_ds_materials(ac, &tmp_data, ads, ob, filter_mode);
2611                 }
2612
2613                 /* object data */
2614                 if (ob->data) {
2615                         tmp_items += animdata_filter_ds_obdata(ac, &tmp_data, ads, ob, filter_mode);
2616                 }
2617
2618                 /* particles */
2619                 if ((ob->particlesystem.first) && !(ads->filterflag & ADS_FILTER_NOPART)) {
2620                         tmp_items += animdata_filter_ds_particles(ac, &tmp_data, ads, ob, filter_mode);
2621                 }
2622
2623                 /* grease pencil */
2624                 if ((ob->type == OB_GPENCIL) &&
2625                     (ob->data) && !(ads->filterflag & ADS_FILTER_NOGPENCIL))
2626                 {
2627                         tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, ob->data, filter_mode);
2628                 }
2629         }
2630         END_ANIMFILTER_SUBCHANNELS;
2631
2632
2633         /* if we collected some channels, add these to the new list... */
2634         if (tmp_items) {
2635                 /* firstly add object expander if required */
2636                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2637                         /* check if filtering by selection */
2638                         // XXX: double-check on this - most of the time, a lot of tools need to filter out these channels!
2639                         if (ANIMCHANNEL_SELOK((base->flag & BASE_SELECTED))) {
2640                                 /* check if filtering by active status */
2641                                 if (ANIMCHANNEL_ACTIVEOK(ob)) {
2642                                         ANIMCHANNEL_NEW_CHANNEL(base, ANIMTYPE_OBJECT, ob, NULL);
2643                                 }
2644                         }
2645                 }
2646
2647                 /* now add the list of collected channels */
2648                 BLI_movelisttolist(anim_data, &tmp_data);
2649                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2650                 items += tmp_items;
2651         }
2652
2653         /* return the number of items added */
2654         return items;
2655 }
2656
2657 static size_t animdata_filter_ds_world(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, World *wo, int filter_mode)
2658 {
2659         ListBase tmp_data = {NULL, NULL};
2660         size_t tmp_items = 0;
2661         size_t items = 0;
2662
2663         /* add world animation channels */
2664         BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_WOR_SCED(wo))
2665         {
2666                 /* animation data filtering */
2667                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode);
2668
2669                 /* nodes */
2670                 if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2671                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)wo, wo->nodetree, filter_mode);
2672         }
2673         END_ANIMFILTER_SUBCHANNELS;
2674
2675         /* did we find anything? */
2676         if (tmp_items) {
2677                 /* include data-expand widget first */
2678                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2679                         /* check if filtering by active status */
2680                         if (ANIMCHANNEL_ACTIVEOK(wo)) {
2681                                 ANIMCHANNEL_NEW_CHANNEL(wo, ANIMTYPE_DSWOR, sce, NULL);
2682                         }
2683                 }
2684
2685                 /* now add the list of collected channels */
2686                 BLI_movelisttolist(anim_data, &tmp_data);
2687                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2688                 items += tmp_items;
2689         }
2690
2691         /* return the number of items added to the list */
2692         return items;
2693 }
2694
2695 static size_t animdata_filter_ds_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2696 {
2697         ListBase tmp_data = {NULL, NULL};
2698         size_t tmp_items = 0;
2699         size_t items = 0;
2700
2701         AnimData *adt = sce->adt;
2702         short type = 0, expanded = 1;
2703         void *cdata = NULL;
2704
2705         /* determine the type of expander channels to use */
2706         // this is the best way to do this for now...
2707         ANIMDATA_FILTER_CASES(
2708                 sce,
2709                 { /* AnimData - no channel, but consider data */},
2710                 { /* NLA - no channel, but consider data */},
2711                 { /* Drivers */
2712                     type = ANIMTYPE_FILLDRIVERS;
2713                     cdata = adt;
2714                     expanded = EXPANDED_DRVD(adt);
2715                 },
2716                 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2717                 { /* Keyframes */
2718                     type = ANIMTYPE_FILLACTD;
2719                     cdata = adt->action;
2720                     expanded = EXPANDED_ACTC(adt->action);
2721                 });
2722
2723         /* add scene-level animation channels */
2724         BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2725         {
2726                 /* animation data filtering */
2727                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)sce, filter_mode);
2728         }
2729         END_ANIMFILTER_SUBCHANNELS;
2730
2731         /* did we find anything? */
2732         if (tmp_items) {
2733                 /* include anim-expand widget first */
2734                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2735                         if (type != ANIMTYPE_NONE) {
2736                                 /* NOTE: active-status (and the associated checks) don't apply here... */
2737                                 ANIMCHANNEL_NEW_CHANNEL(cdata, type, sce, NULL);
2738                         }
2739                 }
2740
2741                 /* now add the list of collected channels */
2742                 BLI_movelisttolist(anim_data, &tmp_data);
2743                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2744                 items += tmp_items;
2745         }
2746
2747         /* return the number of items added to the list */
2748         return items;
2749 }
2750
2751 static size_t animdata_filter_dopesheet_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2752 {
2753         ListBase tmp_data = {NULL, NULL};
2754         size_t tmp_items = 0;
2755         size_t items = 0;
2756
2757         /* filter data contained under object first */
2758         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_SCEC(sce))
2759         {
2760                 bNodeTree *ntree = sce->nodetree;
2761                 bGPdata *gpd = sce->gpd;
2762                 World *wo = sce->world;
2763
2764                 /* Action, Drivers, or NLA for Scene */
2765                 if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
2766                         tmp_items += animdata_filter_ds_scene(ac, &tmp_data, ads, sce, filter_mode);
2767                 }
2768
2769                 /* world */
2770                 if ((wo) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
2771                         tmp_items += animdata_filter_ds_world(ac, &tmp_data, ads, sce, wo, filter_mode);
2772                 }
2773
2774                 /* nodetree */
2775                 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2776                         tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
2777                 }
2778
2779                 /* line styles */
2780                 if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
2781                         tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
2782                 }
2783
2784                 /* grease pencil */
2785                 if ((gpd) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
2786                         tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, gpd, filter_mode);
2787                 }
2788
2789                 /* TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here */
2790         }
2791         END_ANIMFILTER_SUBCHANNELS;
2792
2793         /* if we collected some channels, add these to the new list... */
2794         if (tmp_items) {
2795                 /* firstly add object expander if required */
2796                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2797                         /* check if filtering by selection */
2798                         if (ANIMCHANNEL_SELOK((sce->flag & SCE_DS_SELECTED))) {
2799                                 /* NOTE: active-status doesn't matter for this! */
2800                                 ANIMCHANNEL_NEW_CHANNEL(sce, ANIMTYPE_SCENE, sce, NULL);
2801                         }
2802                 }
2803
2804                 /* now add the list of collected channels */
2805                 BLI_movelisttolist(anim_data, &tmp_data);
2806                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2807                 items += tmp_items;
2808         }
2809
2810         /* return the number of items added */
2811         return items;
2812 }
2813
2814 static size_t animdata_filter_ds_movieclip(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, MovieClip *clip, int filter_mode)
2815 {
2816         ListBase tmp_data = {NULL, NULL};
2817         size_t tmp_items = 0;
2818         size_t items = 0;
2819         /* add world animation channels */
2820         BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MCLIP(clip))
2821         {
2822                 /* animation data filtering */
2823                 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)clip, filter_mode);
2824         }
2825         END_ANIMFILTER_SUBCHANNELS;
2826         /* did we find anything? */
2827         if (tmp_items) {
2828                 /* include data-expand widget first */
2829                 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2830                         /* check if filtering by active status */
2831                         if (ANIMCHANNEL_ACTIVEOK(clip)) {
2832                                 ANIMCHANNEL_NEW_CHANNEL(clip, ANIMTYPE_DSMCLIP, clip, NULL);
2833                         }
2834                 }
2835                 /* now add the list of collected channels */
2836                 BLI_movelisttolist(anim_data, &tmp_data);
2837                 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2838                 items += tmp_items;
2839         }
2840         /* return the number of items added to the list */
2841         return items;
2842 }
2843
2844 static size_t animdata_filter_dopesheet_movieclips(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, int filter_mode)
2845 {
2846         size_t items = 0;
2847         MovieClip *clip;
2848         for (clip = ac->bmain->movieclips.first; clip != NULL; clip = clip->id.next) {
2849                 /* only show if gpd is used by something... */
2850                 if (ID_REAL_USERS(clip) < 1) {
2851                         continue;
2852                 }
2853                 items += animdata_filter_ds_movieclip(ac, anim_data, ads, clip, filter_mode);
2854         }
2855         /* return the number of items added to the list */
2856         return items;
2857 }
2858
2859 /* Helper for animdata_filter_dopesheet() - For checking if an object should be included or not */
2860 static bool animdata_filter_base_is_ok(bDopeSheet *ads, Base *base, int filter_mode)
2861 {
2862         Object *ob = base->object;
2863
2864         if (base->object == NULL)
2865                 return false;
2866
2867         /* firstly, check if object can be included, by the following factors:
2868          * - if only visible, must check for layer and also viewport visibility
2869          *   --> while tools may demand only visible, user setting takes priority
2870          *       as user option controls whether sets of channels get included while
2871          *       tool-flag takes into account collapsed/open channels too
2872          * - if only selected, must check if object is selected
2873          * - there must be animation data to edit (this is done recursively as we
2874          *   try to add the channels)
2875          */
2876         if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
2877                 /* layer visibility - we check both object and base, since these may not be in sync yet */
2878                 if ((base->flag & BASE_VISIBLE) == 0)
2879                         return false;
2880
2881                 /* outliner restrict-flag */
2882                 if (ob->restrictflag & OB_RESTRICT_VIEW)
2883                         return false;
2884         }
2885
2886         /* if only F-Curves with visible flags set can be shown, check that
2887          * datablock hasn't been set to invisible
2888          */
2889         if (filter_mode & ANIMFILTER_CURVE_VISIBLE) {
2890                 if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE))
2891                         return false;
2892         }
2893
2894         /* Pinned curves are visible regardless of selection flags. */
2895         if ((ob->adt) && (ob->adt->flag & ADT_CURVES_ALWAYS_VISIBLE)) {
2896                 return true;
2897         }
2898
2899         /* Special case.
2900          * We don't do recursive checks for pin, but we need to deal with tricky
2901          * setup like animated camera lens without animated camera location.
2902          * Without such special handle here we wouldn't be able to bin such
2903          * camera data only animation to the editor.
2904          */
2905         if (ob->adt == NULL && ob->data != NULL) {
2906                 AnimData *data_adt = BKE_animdata_from_id(ob->data);
2907                 if (data_adt != NULL && (data_adt->flag & ADT_CURVES_ALWAYS_VISIBLE)) {
2908                         return true;
2909                 }
2910         }
2911
2912         /* check selection and object type filters */
2913         if ((ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED) /*|| (base == sce->basact)*/)) {
2914                 /* only selected should be shown */
2915                 return false;
2916         }
2917
2918         /* check if object belongs to the filtering group if option to filter
2919          * objects by the grouped status is on
2920          * - used to ease the process of doing multiple-character choreographies
2921          */
2922         if (ads->filter_grp != NULL) {
2923                 if (BKE_collection_has_object_recursive(ads->filter_grp, ob) == 0)
2924                         return false;
2925         }
2926
2927         /* no reason to exclude this object... */
2928         return true;
2929 }
2930
2931 /* Helper for animdata_filter_ds_sorted_bases() - Comparison callback for two Base pointers... */
2932 static int ds_base_sorting_cmp(const void *base1_ptr, const void *base2_ptr)
2933 {