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