2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2008 Blender Foundation, Joshua Leung
19 * All rights reserved.
22 * Contributor(s): Joshua Leung (original author)
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/editors/animation/anim_filter.c
28 * \ingroup edanimation
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.
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
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...
48 * -- Joshua Leung, Dec 2008 (Last revision July 2009)
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_object_types.h"
76 #include "DNA_userdef_types.h"
77 #include "DNA_layer_types.h"
79 #include "MEM_guardedalloc.h"
81 #include "BLI_blenlib.h"
82 #include "BLI_utildefines.h"
83 #include "BLI_alloca.h"
84 #include "BLI_ghash.h"
85 #include "BLI_string.h"
87 #include "BKE_animsys.h"
88 #include "BKE_action.h"
89 #include "BKE_fcurve.h"
90 #include "BKE_context.h"
91 #include "BKE_global.h"
92 #include "BKE_group.h"
94 #include "BKE_layer.h"
96 #include "BKE_material.h"
97 #include "BKE_modifier.h"
100 #include "BKE_sequencer.h"
102 #include "ED_anim_api.h"
103 #include "ED_markers.h"
105 #include "UI_resources.h" /* for TH_KEYFRAME_SCALE lookup */
107 /* ************************************************************ */
108 /* Blender Context <-> Animation Context mapping */
110 /* ----------- Private Stuff - General -------------------- */
112 /* Get vertical scaling factor (i.e. typically used for keyframe size) */
113 static void animedit_get_yscale_factor(bAnimContext *ac)
115 bTheme *btheme = UI_GetTheme();
117 /* grab scale factor directly from action editor setting
118 * NOTE: This theme setting doesn't have an ID, as it cannot be accessed normally
119 * since it is a float, and the theem settings methods can only handle chars.
121 ac->yscale_fac = btheme->tact.keyframe_scale_fac;
123 /* clamp to avoid problems with uninitialised values... */
124 if (ac->yscale_fac < 0.1f)
125 ac->yscale_fac = 1.0f;
126 //printf("yscale_fac = %f\n", ac->yscale_fac);
129 /* ----------- Private Stuff - Action Editor ------------- */
131 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
132 /* Note: there's a similar function in key.c (BKE_key_from_object) */
133 static Key *actedit_get_shapekeys(bAnimContext *ac)
135 SceneLayer *sl = ac->scene_layer;
143 /* XXX pinning is not available in 'ShapeKey' mode... */
144 //if (saction->pin) return NULL;
146 /* shapekey data is stored with geometry data */
147 key = BKE_key_from_object(ob);
150 if (key->type == KEY_RELATIVE)
157 /* Get data being edited in Action Editor (depending on current 'mode') */
158 static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction)
161 ac->ads = &saction->ads;
163 /* sync settings with current view status, then return appropriate data */
164 switch (saction->mode) {
165 case SACTCONT_ACTION: /* 'Action Editor' */
166 /* if not pinned, sync with active object */
167 if (/*saction->pin == 0*/ true) {
168 if (ac->obact && ac->obact->adt)
169 saction->action = ac->obact->adt->action;
171 saction->action = NULL;
174 ac->datatype = ANIMCONT_ACTION;
175 ac->data = saction->action;
177 ac->mode = saction->mode;
180 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
181 ac->datatype = ANIMCONT_SHAPEKEY;
182 ac->data = actedit_get_shapekeys(ac);
184 /* if not pinned, sync with active object */
185 if (/*saction->pin == 0*/ true) {
186 Key *key = (Key *)ac->data;
189 saction->action = key->adt->action;
191 saction->action = NULL;
194 ac->mode = saction->mode;
197 case SACTCONT_GPENCIL: /* Grease Pencil */ /* XXX review how this mode is handled... */
198 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
199 saction->ads.source = (ID *)ac->scene;
201 ac->datatype = ANIMCONT_GPENCIL;
202 ac->data = &saction->ads;
204 ac->mode = saction->mode;
207 case SACTCONT_CACHEFILE: /* Cache File */ /* XXX review how this mode is handled... */
208 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
209 saction->ads.source = (ID *)ac->scene;
211 ac->datatype = ANIMCONT_CHANNEL;
212 ac->data = &saction->ads;
214 ac->mode = saction->mode;
217 case SACTCONT_MASK: /* Mask */ /* XXX review how this mode is handled... */
219 /* TODO, other methods to get the mask */
220 // Sequence *seq = BKE_sequencer_active_get(ac->scene);
221 //MovieClip *clip = ac->scene->clip;
222 // struct Mask *mask = seq ? seq->mask : NULL;
224 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
225 saction->ads.source = (ID *)ac->scene;
227 ac->datatype = ANIMCONT_MASK;
228 ac->data = &saction->ads;
230 ac->mode = saction->mode;
233 case SACTCONT_DOPESHEET: /* DopeSheet */
234 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
235 saction->ads.source = (ID *)ac->scene;
237 ac->datatype = ANIMCONT_DOPESHEET;
238 ac->data = &saction->ads;
240 ac->mode = saction->mode;
243 default: /* unhandled yet */
244 ac->datatype = ANIMCONT_NONE;
252 /* ----------- Private Stuff - Graph Editor ------------- */
254 /* Get data being edited in Graph Editor (depending on current 'mode') */
255 static bool graphedit_get_context(bAnimContext *ac, SpaceIpo *sipo)
257 /* init dopesheet data if non-existent (i.e. for old files) */
258 if (sipo->ads == NULL) {
259 sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
260 sipo->ads->source = (ID *)ac->scene;
264 /* set settings for Graph Editor - "Selected = Editable" */
265 if (sipo->flag & SIPO_SELCUVERTSONLY)
266 sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
268 sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
270 /* sync settings with current view status, then return appropriate data */
271 switch (sipo->mode) {
272 case SIPO_MODE_ANIMATION: /* Animation F-Curve Editor */
273 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
274 sipo->ads->source = (ID *)ac->scene;
275 sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
277 ac->datatype = ANIMCONT_FCURVES;
278 ac->data = sipo->ads;
280 ac->mode = sipo->mode;
283 case SIPO_MODE_DRIVERS: /* Driver F-Curve Editor */
284 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
285 sipo->ads->source = (ID *)ac->scene;
286 sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
288 ac->datatype = ANIMCONT_DRIVERS;
289 ac->data = sipo->ads;
291 ac->mode = sipo->mode;
294 default: /* unhandled yet */
295 ac->datatype = ANIMCONT_NONE;
303 /* ----------- Private Stuff - NLA Editor ------------- */
305 /* Get data being edited in Graph Editor (depending on current 'mode') */
306 static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla)
308 /* init dopesheet data if non-existent (i.e. for old files) */
309 if (snla->ads == NULL)
310 snla->ads = MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
313 /* sync settings with current view status, then return appropriate data */
314 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
315 snla->ads->source = (ID *)ac->scene;
316 snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
318 ac->datatype = ANIMCONT_NLA;
319 ac->data = snla->ads;
324 /* ----------- Public API --------------- */
326 /* Obtain current anim-data context, given that context info from Blender context has already been set
327 * - AnimContext to write to is provided as pointer to var on stack so that we don't have
328 * allocation/freeing costs (which are not that avoidable with channels).
330 bool ANIM_animdata_context_getdata(bAnimContext *ac)
332 SpaceLink *sl = ac->sl;
335 /* context depends on editor we are currently in */
337 switch (ac->spacetype) {
340 SpaceAction *saction = (SpaceAction *)sl;
341 ok = actedit_get_context(ac, saction);
346 SpaceIpo *sipo = (SpaceIpo *)sl;
347 ok = graphedit_get_context(ac, sipo);
352 SpaceNla *snla = (SpaceNla *)sl;
353 ok = nlaedit_get_context(ac, snla);
359 /* check if there's any valid data */
360 return (ok && ac->data);
363 /* Obtain current anim-data context from Blender Context info
364 * - AnimContext to write to is provided as pointer to var on stack so that we don't have
365 * allocation/freeing costs (which are not that avoidable with channels).
366 * - Clears data and sets the information from Blender Context which is useful
368 bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
370 ScrArea *sa = CTX_wm_area(C);
371 ARegion *ar = CTX_wm_region(C);
372 SpaceLink *sl = CTX_wm_space_data(C);
373 Scene *scene = CTX_data_scene(C);
375 /* clear old context info */
376 if (ac == NULL) return false;
377 memset(ac, 0, sizeof(bAnimContext));
379 /* get useful default context settings from context */
382 ac->markers = ED_context_get_markers(C);
384 ac->scene_layer = CTX_data_scene_layer(C);
385 ac->obact = (ac->scene_layer->basact) ? ac->scene_layer->basact->object : NULL;
389 ac->spacetype = (sa) ? sa->spacetype : 0;
390 ac->regiontype = (ar) ? ar->regiontype : 0;
392 /* initialise default y-scale factor */
393 animedit_get_yscale_factor(ac);
395 /* get data context info */
396 // XXX: if the below fails, try to grab this info from context instead... (to allow for scripting)
397 return ANIM_animdata_context_getdata(ac);
400 /* ************************************************************ */
401 /* Blender Data <-- Filter --> Channels to be operated on */
403 /* macros to use before/after getting the sub-channels of some channel,
404 * to abstract away some of the tricky logic involved
407 * 1) Graph Edit main area (just data) OR channels visible in Channel List
408 * 2) If not showing channels, we're only interested in the data (Action Editor's editing)
409 * 3) We don't care what data, we just care there is some (so that a collapsed
410 * channel can be kept around). No need to clear channels-flag in order to
411 * keep expander channels with no sub-data out, as those cases should get
412 * dealt with by the recursive detection idiom in place.
414 * Implementation Note:
415 * YES the _doSubChannels variable is NOT read anywhere. BUT, this is NOT an excuse
416 * to go steamrolling the logic into a single-line expression as from experience,
417 * those are notoriously difficult to read + debug when extending later on. The code
418 * below is purposefully laid out so that each case noted above corresponds clearly to
421 #define BEGIN_ANIMFILTER_SUBCHANNELS(expanded_check) \
423 int _filter = filter_mode; \
424 short _doSubChannels = 0; \
425 if (!(filter_mode & ANIMFILTER_LIST_VISIBLE) || (expanded_check)) \
426 _doSubChannels = 1; \
427 else if (!(filter_mode & ANIMFILTER_LIST_CHANNELS)) \
428 _doSubChannels = 2; \
430 filter_mode |= ANIMFILTER_TMP_PEEK; \
434 (void) _doSubChannels; \
436 /* ... standard sub-channel filtering can go on here now ... */
437 #define END_ANIMFILTER_SUBCHANNELS \
438 filter_mode = _filter; \
441 /* ............................... */
443 /* quick macro to test if AnimData is usable */
444 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
446 /* quick macro to test if AnimData is usable for drivers */
447 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
449 /* quick macro to test if AnimData is usable for NLA */
450 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
452 /* Quick macro to test for all three above usability tests, performing the appropriate provided
453 * action for each when the AnimData context is appropriate.
455 * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
457 * For this to work correctly, a standard set of data needs to be available within the scope that this
459 * - ListBase anim_data;
461 * - bAnimListElem *ale;
464 * - id: ID block which should have an AnimData pointer following it immediately, to use
465 * - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA)
466 * - nlaOk: line or block of code to execute for NLA tracks+strips case
467 * - driversOk: line or block of code to execute for Drivers case
468 * - nlaKeysOk: line or block of code for NLA Strip Keyframes case
469 * - keysOk: line or block of code for Keyframes case
471 * The checks for the various cases are as follows:
472 * 0) top level: checks for animdata and also that all the F-Curves for the block will be visible
473 * 1) animdata check: for filtering animdata blocks only
474 * 2A) nla tracks: include animdata block's data as there are NLA tracks+strips there
475 * 2B) actions to convert to nla: include animdata block's data as there is an action that can be
476 * converted to a new NLA strip, and the filtering options allow this
477 * 2C) allow non-animated datablocks to be included so that datablocks can be added
478 * 3) drivers: include drivers from animdata block (for Drivers mode in Graph Editor)
479 * 4A) nla strip keyframes: these are the per-strip controls for time and influence
480 * 4B) normal keyframes: only when there is an active action
482 #define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, nlaKeysOk, keysOk) \
485 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) { \
486 if (filter_mode & ANIMFILTER_ANIMDATA) { \
489 else if (ads->filterflag & ADS_FILTER_ONLYNLA) { \
490 if (ANIMDATA_HAS_NLA(id)) { \
493 else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || ANIMDATA_HAS_KEYS(id)) { \
497 else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) { \
498 if (ANIMDATA_HAS_DRIVERS(id)) { \
503 if (ANIMDATA_HAS_NLA(id)) { \
506 if (ANIMDATA_HAS_KEYS(id)) { \
514 /* ............................... */
516 /* Add a new animation channel, taking into account the "peek" flag, which is used to just check
517 * whether any channels will be added (but without needing them to actually get created).
519 * ! This causes the calling function to return early if we're only "peeking" for channels
521 // XXX: ale_statement stuff is really a hack for one special case. It shouldn't really be needed...
522 #define ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, ale_statement) \
523 if (filter_mode & ANIMFILTER_TMP_PEEK) \
526 bAnimListElem *ale = make_new_animlistelem(channel_data, channel_type, (ID *)owner_id); \
528 BLI_addtail(anim_data, ale); \
534 #define ANIMCHANNEL_NEW_CHANNEL(channel_data, channel_type, owner_id) \
535 ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, {})
537 /* ............................... */
539 /* quick macro to test if an anim-channel representing an AnimData block is suitably active */
540 #define ANIMCHANNEL_ACTIVEOK(ale) \
541 (!(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE) )
543 /* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
544 #define ANIMCHANNEL_SELOK(test_func) \
545 (!(filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) || \
546 ((filter_mode & ANIMFILTER_SEL) && test_func) || \
547 ((filter_mode & ANIMFILTER_UNSEL) && test_func == 0) )
549 /* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes
550 * - _SELEDIT means that only selected curves will have visible+editable keyframes
552 * checks here work as follows:
553 * 1) seledit off - don't need to consider the implications of this option
554 * 2) foredit off - we're not considering editing, so channel is ok still
555 * 3) test_func (i.e. selection test) - only if selected, this test will pass
557 #define ANIMCHANNEL_SELEDITOK(test_func) \
558 (!(filter_mode & ANIMFILTER_SELEDIT) || \
559 !(filter_mode & ANIMFILTER_FOREDIT) || \
562 /* ----------- 'Private' Stuff --------------- */
564 /* this function allocates memory for a new bAnimListElem struct for the
565 * provided animation channel-data.
567 static bAnimListElem *make_new_animlistelem(void *data, short datatype, ID *owner_id)
569 bAnimListElem *ale = NULL;
571 /* only allocate memory if there is data to convert */
573 /* allocate and set generic data */
574 ale = MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
577 ale->type = datatype;
580 ale->adt = BKE_animdata_from_id(owner_id);
584 case ANIMTYPE_SUMMARY:
586 /* nothing to include for now... this is just a dummy wrappy around all the other channels
587 * in the DopeSheet, and gets included at the start of the list
589 ale->key_data = NULL;
590 ale->datatype = ALE_ALL;
595 Scene *sce = (Scene *)data;
597 ale->flag = sce->flag;
600 ale->datatype = ALE_SCE;
602 ale->adt = BKE_animdata_from_id(data);
605 case ANIMTYPE_OBJECT:
607 Base *base = (Base *)data;
608 Object *ob = base->object;
610 ale->flag = ob->flag;
613 ale->datatype = ALE_OB;
615 ale->adt = BKE_animdata_from_id(&ob->id);
618 case ANIMTYPE_FILLACTD:
620 bAction *act = (bAction *)data;
622 ale->flag = act->flag;
625 ale->datatype = ALE_ACT;
628 case ANIMTYPE_FILLDRIVERS:
630 AnimData *adt = (AnimData *)data;
632 ale->flag = adt->flag;
634 // XXX... drivers don't show summary for now
635 ale->key_data = NULL;
636 ale->datatype = ALE_NONE;
641 Material *ma = (Material *)data;
642 AnimData *adt = ma->adt;
644 ale->flag = FILTER_MAT_OBJD(ma);
646 ale->key_data = (adt) ? adt->action : NULL;
647 ale->datatype = ALE_ACT;
649 ale->adt = BKE_animdata_from_id(data);
654 Lamp *la = (Lamp *)data;
655 AnimData *adt = la->adt;
657 ale->flag = FILTER_LAM_OBJD(la);
659 ale->key_data = (adt) ? adt->action : NULL;
660 ale->datatype = ALE_ACT;
662 ale->adt = BKE_animdata_from_id(data);
667 Camera *ca = (Camera *)data;
668 AnimData *adt = ca->adt;
670 ale->flag = FILTER_CAM_OBJD(ca);
672 ale->key_data = (adt) ? adt->action : NULL;
673 ale->datatype = ALE_ACT;
675 ale->adt = BKE_animdata_from_id(data);
678 case ANIMTYPE_DSCACHEFILE:
680 CacheFile *cache_file = (CacheFile *)data;
681 AnimData *adt = cache_file->adt;
683 ale->flag = FILTER_CACHEFILE_OBJD(cache_file);
685 ale->key_data = (adt) ? adt->action : NULL;
686 ale->datatype = ALE_ACT;
688 ale->adt = BKE_animdata_from_id(data);
693 Curve *cu = (Curve *)data;
694 AnimData *adt = cu->adt;
696 ale->flag = FILTER_CUR_OBJD(cu);
698 ale->key_data = (adt) ? adt->action : NULL;
699 ale->datatype = ALE_ACT;
701 ale->adt = BKE_animdata_from_id(data);
706 bArmature *arm = (bArmature *)data;
707 AnimData *adt = arm->adt;
709 ale->flag = FILTER_ARM_OBJD(arm);
711 ale->key_data = (adt) ? adt->action : NULL;
712 ale->datatype = ALE_ACT;
714 ale->adt = BKE_animdata_from_id(data);
717 case ANIMTYPE_DSMESH:
719 Mesh *me = (Mesh *)data;
720 AnimData *adt = me->adt;
722 ale->flag = FILTER_MESH_OBJD(me);
724 ale->key_data = (adt) ? adt->action : NULL;
725 ale->datatype = ALE_ACT;
727 ale->adt = BKE_animdata_from_id(data);
732 Lattice *lt = (Lattice *)data;
733 AnimData *adt = lt->adt;
735 ale->flag = FILTER_LATTICE_OBJD(lt);
737 ale->key_data = (adt) ? adt->action : NULL;
738 ale->datatype = ALE_ACT;
740 ale->adt = BKE_animdata_from_id(data);
745 Speaker *spk = (Speaker *)data;
746 AnimData *adt = spk->adt;
748 ale->flag = FILTER_SPK_OBJD(spk);
750 ale->key_data = (adt) ? adt->action : NULL;
751 ale->datatype = ALE_ACT;
753 ale->adt = BKE_animdata_from_id(data);
756 case ANIMTYPE_DSSKEY:
758 Key *key = (Key *)data;
759 AnimData *adt = key->adt;
761 ale->flag = FILTER_SKE_OBJD(key);
763 ale->key_data = (adt) ? adt->action : NULL;
764 ale->datatype = ALE_ACT;
766 ale->adt = BKE_animdata_from_id(data);
771 World *wo = (World *)data;
772 AnimData *adt = wo->adt;
774 ale->flag = FILTER_WOR_SCED(wo);
776 ale->key_data = (adt) ? adt->action : NULL;
777 ale->datatype = ALE_ACT;
779 ale->adt = BKE_animdata_from_id(data);
782 case ANIMTYPE_DSNTREE:
784 bNodeTree *ntree = (bNodeTree *)data;
785 AnimData *adt = ntree->adt;
787 ale->flag = FILTER_NTREE_DATA(ntree);
789 ale->key_data = (adt) ? adt->action : NULL;
790 ale->datatype = ALE_ACT;
792 ale->adt = BKE_animdata_from_id(data);
795 case ANIMTYPE_DSLINESTYLE:
797 FreestyleLineStyle *linestyle = (FreestyleLineStyle *)data;
798 AnimData *adt = linestyle->adt;
800 ale->flag = FILTER_LS_SCED(linestyle);
802 ale->key_data = (adt) ? adt->action : NULL;
803 ale->datatype = ALE_ACT;
805 ale->adt = BKE_animdata_from_id(data);
808 case ANIMTYPE_DSPART:
810 ParticleSettings *part = (ParticleSettings *)ale->data;
811 AnimData *adt = part->adt;
813 ale->flag = FILTER_PART_OBJD(part);
815 ale->key_data = (adt) ? adt->action : NULL;
816 ale->datatype = ALE_ACT;
818 ale->adt = BKE_animdata_from_id(data);
823 Tex *tex = (Tex *)data;
824 AnimData *adt = tex->adt;
826 ale->flag = FILTER_TEX_DATA(tex);
828 ale->key_data = (adt) ? adt->action : NULL;
829 ale->datatype = ALE_ACT;
831 ale->adt = BKE_animdata_from_id(data);
834 case ANIMTYPE_DSGPENCIL:
836 bGPdata *gpd = (bGPdata *)data;
837 AnimData *adt = gpd->adt;
839 /* NOTE: we just reuse the same expand filter for this case */
840 ale->flag = EXPANDED_GPD(gpd);
842 // XXX: currently, this is only used for access to its animation data
843 ale->key_data = (adt) ? adt->action : NULL;
844 ale->datatype = ALE_ACT;
846 ale->adt = BKE_animdata_from_id(data);
849 case ANIMTYPE_DSMCLIP:
851 MovieClip *clip = (MovieClip *)data;
852 AnimData *adt = clip->adt;
854 ale->flag = EXPANDED_MCLIP(clip);
856 ale->key_data = (adt) ? adt->action : NULL;
857 ale->datatype = ALE_ACT;
859 ale->adt = BKE_animdata_from_id(data);
862 case ANIMTYPE_NLACONTROLS:
864 AnimData *adt = (AnimData *)data;
866 ale->flag = adt->flag;
868 ale->key_data = NULL;
869 ale->datatype = ALE_NONE;
874 bActionGroup *agrp = (bActionGroup *)data;
876 ale->flag = agrp->flag;
878 ale->key_data = NULL;
879 ale->datatype = ALE_GROUP;
882 case ANIMTYPE_FCURVE:
884 FCurve *fcu = (FCurve *)data;
886 ale->flag = fcu->flag;
889 ale->datatype = ALE_FCURVE;
892 case ANIMTYPE_SHAPEKEY:
894 KeyBlock *kb = (KeyBlock *)data;
895 Key *key = (Key *)ale->id;
897 ale->flag = kb->flag;
899 /* whether we have keyframes depends on whether there is a Key block to find it from */
901 /* index of shapekey is defined by place in key's list */
902 ale->index = BLI_findindex(&key->block, kb);
904 /* the corresponding keyframes are from the animdata */
905 if (ale->adt && ale->adt->action) {
906 bAction *act = ale->adt->action;
907 char *rna_path = BKE_keyblock_curval_rnapath_get(key, kb);
909 /* try to find the F-Curve which corresponds to this exactly,
910 * then free the MEM_alloc'd string
913 ale->key_data = (void *)list_find_fcurve(&act->curves, rna_path, 0);
917 ale->datatype = (ale->key_data) ? ALE_FCURVE : ALE_NONE;
921 case ANIMTYPE_GPLAYER:
923 bGPDlayer *gpl = (bGPDlayer *)data;
925 ale->flag = gpl->flag;
927 ale->key_data = NULL;
928 ale->datatype = ALE_GPFRAME;
931 case ANIMTYPE_MASKLAYER:
933 MaskLayer *masklay = (MaskLayer *)data;
935 ale->flag = masklay->flag;
937 ale->key_data = NULL;
938 ale->datatype = ALE_MASKLAY;
941 case ANIMTYPE_NLATRACK:
943 NlaTrack *nlt = (NlaTrack *)data;
945 ale->flag = nlt->flag;
947 ale->key_data = &nlt->strips;
948 ale->datatype = ALE_NLASTRIP;
951 case ANIMTYPE_NLAACTION:
953 /* nothing to include for now... nothing editable from NLA-perspective here */
954 ale->key_data = NULL;
955 ale->datatype = ALE_NONE;
961 /* return created datatype */
965 /* ----------------------------------------- */
967 /* 'Only Selected' selected data and/or 'Include Hidden' filtering
968 * NOTE: when this function returns true, the F-Curve is to be skipped
970 static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id, int filter_mode)
972 if (fcu->grp != NULL && fcu->grp->flag & ADT_CURVES_ALWAYS_VISIBLE) {
975 /* hidden items should be skipped if we only care about visible data, but we aren't interested in hidden stuff */
976 const bool skip_hidden = (filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN);
978 if (GS(owner_id->name) == ID_OB) {
979 Object *ob = (Object *)owner_id;
981 /* only consider if F-Curve involves pose.bones */
982 if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) {
986 /* get bone-name, and check if this bone is selected */
987 bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
988 pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
989 if (bone_name) MEM_freeN(bone_name);
991 /* check whether to continue or skip */
992 if ((pchan) && (pchan->bone)) {
993 /* if only visible channels, skip if bone not visible unless user wants channels from hidden data too */
995 bArmature *arm = (bArmature *)ob->data;
997 /* skipping - not visible on currently visible layers */
998 if ((arm->layer & pchan->bone->layer) == 0)
1000 /* skipping - is currently hidden */
1001 if (pchan->bone->flag & BONE_HIDDEN_P)
1005 /* can only add this F-Curve if it is selected */
1006 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1007 if ((pchan->bone->flag & BONE_SELECTED) == 0)
1013 else if (GS(owner_id->name) == ID_SCE) {
1014 Scene *scene = (Scene *)owner_id;
1016 /* only consider if F-Curve involves sequence_editor.sequences */
1017 if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
1018 Editing *ed = BKE_sequencer_editing_get(scene, false);
1019 Sequence *seq = NULL;
1023 /* get strip name, and check if this strip is selected */
1024 seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
1025 seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false);
1026 if (seq_name) MEM_freeN(seq_name);
1029 /* can only add this F-Curve if it is selected */
1030 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1031 if ((seq == NULL) || (seq->flag & SELECT) == 0)
1036 else if (GS(owner_id->name) == ID_NT) {
1037 bNodeTree *ntree = (bNodeTree *)owner_id;
1039 /* check for selected nodes */
1040 if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) {
1044 /* get strip name, and check if this strip is selected */
1045 node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes[");
1046 node = nodeFindNodebyName(ntree, node_name);
1047 if (node_name) MEM_freeN(node_name);
1049 /* can only add this F-Curve if it is selected */
1050 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
1051 if ((node) && (node->flag & NODE_SELECT) == 0)
1060 /* Helper for name-based filtering - Perform "partial/fuzzy matches" (as in 80a7efd) */
1061 static bool name_matches_dopesheet_filter(bDopeSheet *ads, char *name)
1063 if (ads->flag & ADS_FLAG_FUZZY_NAMES) {
1064 /* full fuzzy, multi-word, case insensitive matches */
1065 const size_t str_len = strlen(ads->searchstr);
1066 const int words_max = (str_len / 2) + 1;
1068 int (*words)[2] = BLI_array_alloca(words, words_max);
1069 const int words_len = BLI_string_find_split_words(ads->searchstr, str_len, ' ', words, words_max);
1072 /* match name against all search words */
1073 for (int index = 0; index < words_len; index++) {
1074 if (BLI_strncasestr(name, ads->searchstr + words[index][0], words[index][1])) {
1080 /* if we have a match somewhere, this returns true */
1084 /* fallback/default - just case insensitive, but starts from start of word */
1085 return BLI_strcasestr(name, ads->searchstr) != NULL;
1089 /* (Display-)Name-based F-Curve filtering
1090 * NOTE: when this function returns true, the F-Curve is to be skipped
1092 static bool skip_fcurve_with_name(bDopeSheet *ads, FCurve *fcu, ID *owner_id)
1094 bAnimListElem ale_dummy = {NULL};
1095 const bAnimChannelType *acf;
1097 /* create a dummy wrapper for the F-Curve */
1098 ale_dummy.type = ANIMTYPE_FCURVE;
1099 ale_dummy.id = owner_id;
1100 ale_dummy.data = fcu;
1102 /* get type info for channel */
1103 acf = ANIM_channel_get_typeinfo(&ale_dummy);
1104 if (acf && acf->name) {
1105 char name[256]; /* hopefully this will be enough! */
1108 acf->name(&ale_dummy, name);
1110 /* check for partial match with the match string, assuming case insensitive filtering
1111 * if match, this channel shouldn't be ignored!
1113 return !name_matches_dopesheet_filter(ads, name);
1116 /* just let this go... */
1121 * Check if F-Curve has errors and/or is disabled
1123 * \return true if F-Curve has errors/is disabled
1125 static bool fcurve_has_errors(FCurve *fcu)
1127 /* F-Curve disabled - path eval error */
1128 if (fcu->flag & FCURVE_DISABLED) {
1134 ChannelDriver *driver = fcu->driver;
1137 /* error flag on driver usually means that there is an error
1138 * BUT this may not hold with PyDrivers as this flag gets cleared
1139 * if no critical errors prevent the driver from working...
1141 if (driver->flag & DRIVER_FLAG_INVALID)
1144 /* check variables for other things that need linting... */
1145 // TODO: maybe it would be more efficient just to have a quick flag for this?
1146 for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
1147 DRIVER_TARGETS_USED_LOOPER(dvar)
1149 if (dtar->flag & DTAR_FLAG_INVALID)
1152 DRIVER_TARGETS_LOOPER_END
1156 /* no errors found */
1160 /* find the next F-Curve that is usable for inclusion */
1161 static FCurve *animfilter_fcurve_next(bDopeSheet *ads, FCurve *first, bActionGroup *grp, int filter_mode, ID *owner_id)
1165 /* loop over F-Curves - assume that the caller of this has already checked that these should be included
1166 * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
1168 for (fcu = first; ((fcu) && (fcu->grp == grp)); fcu = fcu->next) {
1169 /* special exception for Pose-Channel/Sequence-Strip/Node Based F-Curves:
1170 * - the 'Only Selected' and 'Include Hidden' data filters should be applied to sub-ID data which
1171 * can be independently selected/hidden, such as Pose-Channels, Sequence Strips, and Nodes.
1172 * Since these checks were traditionally done as first check for objects, we do the same here
1173 * - we currently use an 'approximate' method for getting these F-Curves that doesn't require
1174 * carefully checking the entire path
1175 * - this will also affect things like Drivers, and also works for Bone Constraints
1177 if (ads && owner_id) {
1178 if ((filter_mode & ANIMFILTER_TMP_IGNORE_ONLYSEL) == 0) {
1179 if ((ads->filterflag & ADS_FILTER_ONLYSEL) || (ads->filterflag & ADS_FILTER_INCL_HIDDEN) == 0) {
1180 if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode))
1186 /* only include if visible (Graph Editor check, not channels check) */
1187 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
1188 /* only work with this channel and its subchannels if it is editable */
1189 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
1190 /* only include this curve if selected in a way consistent with the filtering requirements */
1191 if (ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu))) {
1192 /* only include if this curve is active */
1193 if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
1194 /* name based filtering... */
1195 if ( ((ads) && (ads->filterflag & ADS_FILTER_BY_FCU_NAME)) && (owner_id) ) {
1196 if (skip_fcurve_with_name(ads, fcu, owner_id))
1200 /* error-based filtering... */
1201 if ((ads) && (ads->filterflag & ADS_FILTER_ONLY_ERRORS)) {
1202 /* skip if no errors... */
1203 if (fcurve_has_errors(fcu) == false)
1207 /* this F-Curve can be used, so return it */
1215 /* no (more) F-Curves from the list are suitable... */
1219 static size_t animfilter_fcurves(ListBase *anim_data, bDopeSheet *ads, FCurve *first, bActionGroup *grp, int filter_mode, ID *owner_id)
1224 /* loop over every F-Curve able to be included
1225 * - this for-loop works like this:
1226 * 1) the starting F-Curve is assigned to the fcu pointer so that we have a starting point to search from
1227 * 2) the first valid F-Curve to start from (which may include the one given as 'first') in the remaining
1228 * list of F-Curves is found, and verified to be non-null
1229 * 3) the F-Curve referenced by fcu pointer is added to the list
1230 * 4) the fcu pointer is set to the F-Curve after the one we just added, so that we can keep going through
1231 * the rest of the F-Curve list without an eternal loop. Back to step 2 :)
1233 for (fcu = first; ( (fcu = animfilter_fcurve_next(ads, fcu, grp, filter_mode, owner_id)) ); fcu = fcu->next) {
1234 ANIMCHANNEL_NEW_CHANNEL(fcu, ANIMTYPE_FCURVE, owner_id);
1237 /* return the number of items added to the list */
1241 static size_t animfilter_act_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *UNUSED(act), bActionGroup *agrp, int filter_mode, ID *owner_id)
1243 ListBase tmp_data = {NULL, NULL};
1244 size_t tmp_items = 0;
1246 //int ofilter = filter_mode;
1248 /* if we care about the selection status of the channels,
1249 * but the group isn't expanded (1)...
1250 * (1) this only matters if we actually care about the hierarchy though.
1251 * - Hierarchy matters: this hack should be applied
1252 * - Hierarchy ignored: cases like [#21276] won't work properly, unless we skip this hack
1254 if ( ((filter_mode & ANIMFILTER_LIST_VISIBLE) && EXPANDED_AGRP(ac, agrp) == 0) && /* care about hierarchy but group isn't expanded */
1255 (filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) ) /* care about selection status */
1257 /* if the group itself isn't selected appropriately, we shouldn't consider it's children either */
1258 if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0)
1261 /* if we're still here, then the selection status of the curves within this group should not matter,
1262 * since this creates too much overhead for animators (i.e. making a slow workflow)
1264 * Tools affected by this at time of coding (2010 Feb 09):
1265 * - inserting keyframes on selected channels only
1266 * - pasting keyframes
1267 * - creating ghost curves in Graph Editor
1269 filter_mode &= ~(ANIMFILTER_SEL | ANIMFILTER_UNSEL | ANIMFILTER_LIST_VISIBLE);
1272 /* add grouped F-Curves */
1273 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_AGRP(ac, agrp))
1275 /* special filter so that we can get just the F-Curves within the active group */
1276 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
1277 /* for the Graph Editor, curves may be set to not be visible in the view to lessen clutter,
1278 * but to do this, we need to check that the group doesn't have it's not-visible flag set preventing
1279 * all its sub-curves to be shown
1281 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE)) {
1282 /* group must be editable for its children to be editable (if we care about this) */
1283 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
1284 /* get first F-Curve which can be used here */
1285 FCurve *first_fcu = animfilter_fcurve_next(ads, agrp->channels.first, agrp, filter_mode, owner_id);
1287 /* filter list, starting from this F-Curve */
1288 tmp_items += animfilter_fcurves(&tmp_data, ads, first_fcu, agrp, filter_mode, owner_id);
1293 END_ANIMFILTER_SUBCHANNELS;
1295 /* did we find anything? */
1297 /* add this group as a channel first */
1298 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1299 /* restore original filter mode so that this next step works ok... */
1300 //filter_mode = ofilter;
1302 /* filter selection of channel specially here again, since may be open and not subject to previous test */
1303 if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
1304 ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id);
1308 /* now add the list of collected channels */
1309 BLI_movelisttolist(anim_data, &tmp_data);
1310 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1314 /* return the number of items added to the list */
1318 static size_t animfilter_action(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, ID *owner_id)
1321 FCurve *lastchan = NULL;
1324 /* don't include anything from this action if it is linked in from another file,
1325 * and we're getting stuff for editing...
1327 if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED_DATABLOCK(act))
1331 // TODO: do nested groups?
1332 for (agrp = act->groups.first; agrp; agrp = agrp->next) {
1333 /* store reference to last channel of group */
1334 if (agrp->channels.last)
1335 lastchan = agrp->channels.last;
1337 /* action group's channels */
1338 items += animfilter_act_group(ac, anim_data, ads, act, agrp, filter_mode, owner_id);
1341 /* un-grouped F-Curves (only if we're not only considering those channels in the active group) */
1342 if (!(filter_mode & ANIMFILTER_ACTGROUPED)) {
1343 FCurve *firstfcu = (lastchan) ? (lastchan->next) : (act->curves.first);
1344 items += animfilter_fcurves(anim_data, ads, firstfcu, NULL, filter_mode, owner_id);
1347 /* return the number of items added to the list */
1351 /* Include NLA-Data for NLA-Editor:
1352 * - when ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display
1353 * Although the evaluation order is from the first track to the last and then apply the Action on top,
1354 * we present this in the UI as the Active Action followed by the last track to the first so that we
1355 * get the evaluation order presented as per a stack.
1356 * - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
1357 * order, i.e. first to last. Otherwise, some tools may get screwed up.
1359 static size_t animfilter_nla(bAnimContext *UNUSED(ac), ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1362 NlaTrack *first = NULL, *next = NULL;
1365 /* if showing channels, include active action */
1366 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1367 /* if NLA action-line filtering is off, don't show unless there are keyframes,
1368 * in order to keep things more compact for doing transforms
1370 if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) {
1371 /* there isn't really anything editable here, so skip if need editable */
1372 if ((filter_mode & ANIMFILTER_FOREDIT) == 0) {
1373 /* just add the action track now (this MUST appear for drawing)
1374 * - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
1375 * overwrite this with the real value - REVIEW THIS...
1377 ANIMCHANNEL_NEW_CHANNEL_FULL((void *)(&adt->action), ANIMTYPE_NLAACTION, owner_id,
1379 ale->data = adt->action ? adt->action : NULL;
1384 /* first track to include will be the last one if we're filtering by channels */
1385 first = adt->nla_tracks.last;
1388 /* first track to include will the first one (as per normal) */
1389 first = adt->nla_tracks.first;
1392 /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
1393 for (nlt = first; nlt; nlt = next) {
1394 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
1395 if (filter_mode & ANIMFILTER_LIST_CHANNELS)
1400 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now
1401 * - active track should still get shown though (even though it has disabled flag set)
1403 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
1404 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && (adt->act_track != nlt))
1407 /* only work with this channel and its subchannels if it is editable */
1408 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
1409 /* only include this track if selected in a way consistent with the filtering requirements */
1410 if (ANIMCHANNEL_SELOK(SEL_NLT(nlt))) {
1411 /* only include if this track is active */
1412 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
1413 /* name based filtering... */
1414 if (((ads) && (ads->filterflag & ADS_FILTER_BY_FCU_NAME)) && (owner_id)) {
1415 bool track_ok = false, strip_ok = false;
1417 /* check if the name of the track, or the strips it has are ok... */
1418 track_ok = name_matches_dopesheet_filter(ads, nlt->name);
1420 if (track_ok == false) {
1422 for (strip = nlt->strips.first; strip; strip = strip->next) {
1423 if (name_matches_dopesheet_filter(ads, strip->name)) {
1430 /* skip if both fail this test... */
1431 if (!track_ok && !strip_ok) {
1436 /* add the track now that it has passed all our tests */
1437 ANIMCHANNEL_NEW_CHANNEL(nlt, ANIMTYPE_NLATRACK, owner_id);
1443 /* return the number of items added to the list */
1447 /* Include the control FCurves per NLA Strip in the channel list
1448 * NOTE: This is includes the expander too...
1450 static size_t animfilter_nla_controls(ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1452 ListBase tmp_data = {NULL, NULL};
1453 size_t tmp_items = 0;
1456 /* add control curves from each NLA strip... */
1457 /* NOTE: ANIMTYPE_FCURVES are created here, to avoid duplicating the code needed */
1458 BEGIN_ANIMFILTER_SUBCHANNELS(((adt->flag & ADT_NLA_SKEYS_COLLAPSED) == 0))
1463 /* for now, we only go one level deep - so controls on grouped FCurves are not handled */
1464 for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
1465 for (strip = nlt->strips.first; strip; strip = strip->next) {
1466 ListBase strip_curves = {NULL, NULL};
1467 size_t strip_items = 0;
1469 /* create the raw items */
1470 strip_items += animfilter_fcurves(&strip_curves, ads, strip->fcurves.first, NULL, filter_mode, owner_id);
1472 /* change their types and add extra data
1473 * - There is no point making a separate copy of animfilter_fcurves for this now/yet,
1474 * unless we later get per-element control curves for other stuff too
1477 bAnimListElem *ale, *ale_n = NULL;
1479 for (ale = strip_curves.first; ale; ale = ale_n) {
1482 /* change the type to being a FCurve for editing NLA strip controls */
1483 BLI_assert(ale->type == ANIMTYPE_FCURVE);
1485 ale->type = ANIMTYPE_NLACURVE;
1488 ale->adt = NULL; /* XXX: This way, there are no problems with time mapping errors */
1492 /* add strip curves to the set of channels inside the group being collected */
1493 BLI_movelisttolist(&tmp_data, &strip_curves);
1494 BLI_assert(BLI_listbase_is_empty(&strip_curves));
1495 tmp_items += strip_items;
1499 END_ANIMFILTER_SUBCHANNELS;
1501 /* did we find anything? */
1503 /* add the expander as a channel first */
1504 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1505 /* currently these channels cannot be selected, so they should be skipped */
1506 if ((filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) == 0) {
1507 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_NLACONTROLS, owner_id);
1511 /* now add the list of collected channels */
1512 BLI_movelisttolist(anim_data, &tmp_data);
1513 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1517 /* return the numebr of items added to the list */
1521 /* determine what animation data from AnimData block should get displayed */
1522 static size_t animfilter_block_data(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *id, int filter_mode)
1524 AnimData *adt = BKE_animdata_from_id(id);
1527 /* image object datablocks have no anim-data so check for NULL */
1529 IdAdtTemplate *iat = (IdAdtTemplate *)id;
1531 /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed
1532 * in a few places in the rest of the code still - notably for the few cases where special mode-based
1533 * different types of data expanders are required.
1535 ANIMDATA_FILTER_CASES(iat,
1537 /* specifically filter animdata block */
1538 if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(adt)) ) {
1539 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id);
1543 items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
1546 items += animfilter_fcurves(anim_data, ads, adt->drivers.first, NULL, filter_mode, id);
1548 { /* NLA Control Keyframes */
1549 items += animfilter_nla_controls(anim_data, ads, adt, filter_mode, id);
1552 items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
1562 /* Include ShapeKey Data for ShapeKey Editor */
1563 static size_t animdata_filter_shapekey(bAnimContext *ac, ListBase *anim_data, Key *key, int filter_mode)
1567 /* check if channels or only F-Curves */
1568 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1571 /* loop through the channels adding ShapeKeys as appropriate */
1572 for (kb = key->block.first; kb; kb = kb->next) {
1573 /* skip the first one, since that's the non-animatable basis */
1574 if (kb == key->block.first) continue;
1576 /* only work with this channel and its subchannels if it is editable */
1577 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) {
1578 /* only include this track if selected in a way consistent with the filtering requirements */
1579 if (ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb)) ) {
1580 // TODO: consider 'active' too?
1582 /* owner-id here must be key so that the F-Curve can be resolved... */
1583 ANIMCHANNEL_NEW_CHANNEL(kb, ANIMTYPE_SHAPEKEY, key);
1589 /* just use the action associated with the shapekey */
1590 // TODO: somehow manage to pass dopesheet info down here too?
1592 if (filter_mode & ANIMFILTER_ANIMDATA) {
1593 if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(key->adt)) ) {
1594 ANIMCHANNEL_NEW_CHANNEL(key->adt, ANIMTYPE_ANIMDATA, key);
1597 else if (key->adt->action) {
1598 items = animfilter_action(ac, anim_data, NULL, key->adt->action, filter_mode, (ID *)key);
1603 /* return the number of items added to the list */
1607 /* Helper for Grease Pencil - layers within a datablock */
1608 static size_t animdata_filter_gpencil_layers_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1613 /* loop over layers as the conditions are acceptable */
1614 for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1615 /* only if selected */
1616 if (ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
1617 /* only if editable */
1618 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
1620 if (!(filter_mode & ANIMFILTER_ACTIVE) || (gpl->flag & GP_LAYER_ACTIVE)) {
1621 /* skip layer if the name doesn't match the filter string */
1622 if ((ads) && (ads->filterflag & ADS_FILTER_BY_FCU_NAME)) {
1623 if (name_matches_dopesheet_filter(ads, gpl->info) == false)
1629 ANIMCHANNEL_NEW_CHANNEL(gpl, ANIMTYPE_GPLAYER, gpd);
1638 /* Helper for Grease Pencil - Grease Pencil datablock - GP Frames */
1639 static size_t animdata_filter_gpencil_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1643 /* When asked from "AnimData" blocks (i.e. the top-level containers for normal animation),
1644 * for convenience, this will return GP Datablocks instead. This may cause issues down
1645 * the track, but for now, this will do...
1647 if (filter_mode & ANIMFILTER_ANIMDATA) {
1648 /* just add GPD as a channel - this will add everything needed */
1649 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL);
1652 ListBase tmp_data = {NULL, NULL};
1653 size_t tmp_items = 0;
1655 /* add gpencil animation channels */
1656 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1658 tmp_items += animdata_filter_gpencil_layers_data(&tmp_data, ads, gpd, filter_mode);
1660 END_ANIMFILTER_SUBCHANNELS;
1662 /* did we find anything? */
1664 /* include data-expand widget first */
1665 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1666 /* add gpd as channel too (if for drawing, and it has layers) */
1667 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL);
1670 /* now add the list of collected channels */
1671 BLI_movelisttolist(anim_data, &tmp_data);
1672 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1680 /* Grab all Grease Pencil datablocks in file */
1681 // TODO: should this be amalgamated with the dopesheet filtering code?
1682 static size_t animdata_filter_gpencil(bAnimContext *ac, ListBase *anim_data, void *UNUSED(data), int filter_mode)
1684 bDopeSheet *ads = ac->ads;
1687 if (ads->filterflag & ADS_FILTER_GP_3DONLY) {
1688 Scene *scene = (Scene *)ads->source;
1689 SceneLayer *sl = (SceneLayer *)ac->scene_layer;
1692 /* Active scene's GPencil block first - No parent item needed... */
1694 items += animdata_filter_gpencil_data(anim_data, ads, scene->gpd, filter_mode);
1697 /* Objects in the scene */
1698 for (base = sl->object_bases.first; base; base = base->next) {
1699 /* Only consider this object if it has got some GP data (saving on all the other tests) */
1700 if (base->object && base->object->gpd) {
1701 Object *ob = base->object;
1703 /* firstly, check if object can be included, by the following factors:
1704 * - if only visible, must check for layer and also viewport visibility
1705 * --> while tools may demand only visible, user setting takes priority
1706 * as user option controls whether sets of channels get included while
1707 * tool-flag takes into account collapsed/open channels too
1708 * - if only selected, must check if object is selected
1709 * - there must be animation data to edit (this is done recursively as we
1710 * try to add the channels)
1712 if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
1713 /* layer visibility - we check both object and base, since these may not be in sync yet */
1714 if ((base->flag & BASE_VISIBLED) == 0) continue;
1716 /* outliner restrict-flag */
1717 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1720 /* check selection and object type filters */
1721 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED) /*|| (base == scene->basact)*/) ) {
1722 /* only selected should be shown */
1726 /* check if object belongs to the filtering group if option to filter
1727 * objects by the grouped status is on
1728 * - used to ease the process of doing multiple-character choreographies
1730 if (ads->filterflag & ADS_FILTER_ONLYOBGROUP) {
1731 if (BKE_group_object_exists(ads->filter_grp, ob) == 0)
1735 /* finally, include this object's grease pencil datablock */
1736 /* XXX: Should we store these under expanders per item? */
1737 items += animdata_filter_gpencil_data(anim_data, ads, ob->gpd, filter_mode);
1744 /* Grab all Grease Pencil datablocks directly from main, but only those that seem to be useful somewhere */
1745 for (gpd = G.main->gpencil.first; gpd; gpd = gpd->id.next) {
1746 /* only show if gpd is used by something... */
1747 if (ID_REAL_USERS(gpd) < 1)
1750 /* add GP frames from this datablock */
1751 items += animdata_filter_gpencil_data(anim_data, ads, gpd, filter_mode);
1755 /* return the number of items added to the list */
1759 /* Helper for Grease Pencil data integrated with main DopeSheet */
1760 static size_t animdata_filter_ds_gpencil(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1762 ListBase tmp_data = {NULL, NULL};
1763 size_t tmp_items = 0;
1766 /* add relevant animation channels for Grease Pencil */
1767 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1769 /* add animation channels */
1770 tmp_items += animfilter_block_data(ac, &tmp_data, ads, &gpd->id, filter_mode);
1772 /* add Grease Pencil layers */
1773 // TODO: do these need a separate expander?
1774 // XXX: what order should these go in?
1776 END_ANIMFILTER_SUBCHANNELS;
1778 /* did we find anything? */
1780 /* include data-expand widget first */
1781 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1782 /* check if filtering by active status */
1783 // XXX: active check here needs checking
1784 if (ANIMCHANNEL_ACTIVEOK(gpd)) {
1785 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_DSGPENCIL, gpd);
1789 /* now add the list of collected channels */
1790 BLI_movelisttolist(anim_data, &tmp_data);
1791 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1795 /* return the number of items added to the list */
1799 /* Helper for Cache File data integrated with main DopeSheet */
1800 static size_t animdata_filter_ds_cachefile(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, CacheFile *cache_file, int filter_mode)
1802 ListBase tmp_data = {NULL, NULL};
1803 size_t tmp_items = 0;
1806 /* add relevant animation channels for Cache File */
1807 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_CACHEFILE_OBJD(cache_file))
1809 /* add animation channels */
1810 tmp_items += animfilter_block_data(ac, &tmp_data, ads, &cache_file->id, filter_mode);
1812 END_ANIMFILTER_SUBCHANNELS;
1814 /* did we find anything? */
1816 /* include data-expand widget first */
1817 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1818 /* check if filtering by active status */
1819 // XXX: active check here needs checking
1820 if (ANIMCHANNEL_ACTIVEOK(cache_file)) {
1821 ANIMCHANNEL_NEW_CHANNEL(cache_file, ANIMTYPE_DSCACHEFILE, cache_file);
1825 /* now add the list of collected channels */
1826 BLI_movelisttolist(anim_data, &tmp_data);
1827 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1831 /* return the number of items added to the list */
1835 /* Helper for Mask Editing - mask layers */
1836 static size_t animdata_filter_mask_data(ListBase *anim_data, Mask *mask, const int filter_mode)
1838 MaskLayer *masklay_act = BKE_mask_layer_active(mask);
1842 /* loop over layers as the conditions are acceptable */
1843 for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
1844 /* only if selected */
1845 if (ANIMCHANNEL_SELOK(SEL_MASKLAY(masklay)) ) {
1846 /* only if editable */
1847 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_MASK(masklay)) {
1849 if (!(filter_mode & ANIMFILTER_ACTIVE) || (masklay_act == masklay)) {
1851 ANIMCHANNEL_NEW_CHANNEL(masklay, ANIMTYPE_MASKLAYER, mask);
1860 /* Grab all mask data */
1861 static size_t animdata_filter_mask(ListBase *anim_data, void *UNUSED(data), int filter_mode)
1866 /* for now, grab mask datablocks directly from main */
1867 // XXX: this is not good...
1868 for (mask = G.main->mask.first; mask; mask = mask->id.next) {
1869 ListBase tmp_data = {NULL, NULL};
1870 size_t tmp_items = 0;
1872 /* only show if mask is used by something... */
1873 if (ID_REAL_USERS(mask) < 1)
1876 /* add mask animation channels */
1877 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MASK(mask))
1879 tmp_items += animdata_filter_mask_data(&tmp_data, mask, filter_mode);
1881 END_ANIMFILTER_SUBCHANNELS;
1883 /* did we find anything? */
1885 /* include data-expand widget first */
1886 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1887 /* add gpd as channel too (if for drawing, and it has layers) */
1888 ANIMCHANNEL_NEW_CHANNEL(mask, ANIMTYPE_MASKDATABLOCK, NULL);
1891 /* now add the list of collected channels */
1892 BLI_movelisttolist(anim_data, &tmp_data);
1893 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1898 /* return the number of items added to the list */
1902 /* NOTE: owner_id is scene, material, or texture block, which is the direct owner of the node tree in question */
1903 static size_t animdata_filter_ds_nodetree_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1905 ListBase tmp_data = {NULL, NULL};
1906 size_t tmp_items = 0;
1909 /* add nodetree animation channels */
1910 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_NTREE_DATA(ntree))
1912 /* animation data filtering */
1913 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ntree, filter_mode);
1915 END_ANIMFILTER_SUBCHANNELS;
1917 /* did we find anything? */
1919 /* include data-expand widget first */
1920 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1921 /* check if filtering by active status */
1922 if (ANIMCHANNEL_ACTIVEOK(ntree)) {
1923 ANIMCHANNEL_NEW_CHANNEL(ntree, ANIMTYPE_DSNTREE, owner_id);
1927 /* now add the list of collected channels */
1928 BLI_movelisttolist(anim_data, &tmp_data);
1929 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1933 /* return the number of items added to the list */
1937 static size_t animdata_filter_ds_nodetree(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1942 items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, ntree, filter_mode);
1944 for (node = ntree->nodes.first; node; node = node->next) {
1945 if (node->type == NODE_GROUP) {
1947 if ((ads->filterflag & ADS_FILTER_ONLYSEL) && (node->flag & NODE_SELECT) == 0) {
1950 items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, (bNodeTree *) node->id,
1951 filter_mode | ANIMFILTER_TMP_IGNORE_ONLYSEL);
1959 static size_t animdata_filter_ds_linestyle(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1961 SceneRenderLayer *srl;
1962 FreestyleLineSet *lineset;
1965 for (srl = sce->r.layers.first; srl; srl = srl->next) {
1966 for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
1967 if (lineset->linestyle) {
1968 lineset->linestyle->id.tag |= LIB_TAG_DOIT;
1973 for (srl = sce->r.layers.first; srl; srl = srl->next) {
1974 /* skip render layers without Freestyle enabled */
1975 if (!(srl->layflag & SCE_LAY_FRS))
1978 /* loop over linesets defined in the render layer */
1979 for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
1980 FreestyleLineStyle *linestyle = lineset->linestyle;
1981 ListBase tmp_data = {NULL, NULL};
1982 size_t tmp_items = 0;
1984 if ((linestyle == NULL) ||
1985 !(linestyle->id.tag & LIB_TAG_DOIT))
1989 linestyle->id.tag &= ~LIB_TAG_DOIT;
1991 /* add scene-level animation channels */
1992 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle))
1994 /* animation data filtering */
1995 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
1997 END_ANIMFILTER_SUBCHANNELS;
1999 /* did we find anything? */
2001 /* include anim-expand widget first */
2002 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2003 /* check if filtering by active status */
2004 if (ANIMCHANNEL_ACTIVEOK(linestyle)) {
2005 ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce);
2009 /* now add the list of collected channels */
2010 BLI_movelisttolist(anim_data, &tmp_data);
2011 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2017 /* return the number of items added to the list */
2021 static size_t animdata_filter_ds_texture(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads,
2022 Tex *tex, ID *owner_id, int filter_mode)
2024 ListBase tmp_data = {NULL, NULL};
2025 size_t tmp_items = 0;
2028 /* add texture's animation data to temp collection */
2029 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_TEX_DATA(tex))
2031 /* texture animdata */
2032 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)tex, filter_mode);
2035 if ((tex->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2036 /* owner_id as id instead of texture, since it'll otherwise be impossible to track the depth */
2037 // FIXME: perhaps as a result, textures should NOT be included under materials, but under their own section instead
2038 // so that free-floating textures can also be animated
2039 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)tex, tex->nodetree, filter_mode);
2042 END_ANIMFILTER_SUBCHANNELS;
2044 /* did we find anything? */
2046 /* include texture-expand widget? */
2047 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2048 /* check if filtering by active status */
2049 if (ANIMCHANNEL_ACTIVEOK(tex)) {
2050 ANIMCHANNEL_NEW_CHANNEL(tex, ANIMTYPE_DSTEX, owner_id);
2054 /* now add the list of collected channels */
2055 BLI_movelisttolist(anim_data, &tmp_data);
2056 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2060 /* return the number of items added to the list */
2064 /* NOTE: owner_id is either material, lamp, or world block, which is the direct owner of the texture stack in question */
2065 static size_t animdata_filter_ds_textures(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
2071 /* get datatype specific data first */
2072 if (owner_id == NULL)
2075 switch (GS(owner_id->name)) {
2078 Material *ma = (Material *)owner_id;
2079 mtex = (MTex **)(&ma->mtex);
2084 Lamp *la = (Lamp *)owner_id;
2085 mtex = (MTex **)(&la->mtex);
2090 World *wo = (World *)owner_id;
2091 mtex = (MTex **)(&wo->mtex);
2096 ParticleSettings *part = (ParticleSettings *)owner_id;
2097 mtex = (MTex **)(&part->mtex);
2102 /* invalid/unsupported option */
2103 if (G.debug & G_DEBUG)
2104 printf("ERROR: Unsupported owner_id (i.e. texture stack) for filter textures - %s\n", owner_id->name);
2109 /* firstly check that we actuallly have some textures, by gathering all textures in a temp list */
2110 for (a = 0; a < MAX_MTEX; a++) {
2111 Tex *tex = (mtex[a]) ? mtex[a]->tex : NULL;
2113 /* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */
2117 /* add texture's anim channels */
2118 items += animdata_filter_ds_texture(ac, anim_data, ads, tex, owner_id, filter_mode);
2121 /* return the number of items added to the list */
2126 static size_t animdata_filter_ds_material(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Material *ma, int filter_mode)
2128 ListBase tmp_data = {NULL, NULL};
2129 size_t tmp_items = 0;
2132 /* add material's animation data to temp collection */
2133 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_MAT_OBJD(ma))
2135 /* material's animation data */
2136 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode);
2139 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2140 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)ma, filter_mode);
2143 if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2144 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode);
2146 END_ANIMFILTER_SUBCHANNELS;
2148 /* did we find anything? */
2150 /* include material-expand widget first */
2151 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2152 /* check if filtering by active status */
2153 if (ANIMCHANNEL_ACTIVEOK(ma)) {
2154 ANIMCHANNEL_NEW_CHANNEL(ma, ANIMTYPE_DSMAT, ma);
2158 /* now add the list of collected channels */
2159 BLI_movelisttolist(anim_data, &tmp_data);
2160 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2167 static size_t animdata_filter_ds_materials(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2169 bool has_nested = false;
2173 /* first pass: take the materials referenced via the Material slots of the object */
2174 for (a = 1; a <= ob->totcol; a++) {
2175 Material *ma = give_current_material(ob, a);
2177 /* if material is valid, try to add relevant contents from here */
2180 items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2182 /* for optimising second pass - check if there's a nested material here to come back for */
2183 if (has_nested == false) {
2184 has_nested = (give_node_material(ma) != NULL);
2189 /* second pass: go through a second time looking for "nested" materials (material.material references)
2191 * NOTE: here we ignore the expanded status of the parent, as it could be too confusing as to why these are
2192 * disappearing/not available, since the relationships between these is not that clear
2195 for (a = 1; a <= ob->totcol; a++) {
2196 Material *base = give_current_material(ob, a);
2197 Material *ma = give_node_material(base);
2199 /* add channels from the nested material if it exists
2200 * - skip if the same material is referenced in its node tree
2201 * (which is common for BI materials) as that results in
2202 * confusing duplicates
2204 if ((ma) && (ma != base)) {
2205 items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2210 /* return the number of items added to the list */
2217 /* Temporary context for modifier linked-data channel extraction */
2218 typedef struct tAnimFilterModifiersContext {
2219 bAnimContext *ac; /* anim editor context */
2220 bDopeSheet *ads; /* dopesheet filtering settings */
2222 ListBase tmp_data; /* list of channels created (but not yet added to the main list) */
2223 size_t items; /* number of channels created */
2225 int filter_mode; /* flags for stuff we want to filter */
2226 } tAnimFilterModifiersContext;
2229 /* dependency walker callback for modifier dependencies */
2230 static void animfilter_modifier_idpoin_cb(void *afm_ptr, Object *ob, ID **idpoin, int UNUSED(cb_flag))
2232 tAnimFilterModifiersContext *afm = (tAnimFilterModifiersContext *)afm_ptr;
2233 ID *owner_id = &ob->id;
2236 /* NOTE: the walker only guarantees to give us all the ID-ptr *slots*,
2237 * not just the ones which are actually used, so be careful!
2242 /* check if this is something we're interested in... */
2243 switch (GS(id->name)) {
2244 case ID_TE: /* Textures */
2246 Tex *tex = (Tex *)id;
2247 if (!(afm->ads->filterflag & ADS_FILTER_NOTEX)) {
2248 afm->items += animdata_filter_ds_texture(afm->ac, &afm->tmp_data, afm->ads, tex, owner_id, afm->filter_mode);
2259 /* animation linked to data used by modifiers
2260 * NOTE: strictly speaking, modifier animation is already included under Object level
2261 * but for some modifiers (e.g. Displace), there can be linked data that has settings
2262 * which would be nice to animate (i.e. texture parameters) but which are not actually
2263 * attached to any other objects/materials/etc. in the scene
2265 // TODO: do we want an expander for this?
2266 static size_t animdata_filter_ds_modifiers(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2268 tAnimFilterModifiersContext afm = {NULL};
2271 /* 1) create a temporary "context" containing all the info we have here to pass to the callback
2272 * use to walk through the dependencies of the modifiers
2274 * ! Assumes that all other unspecified values (i.e. accumulation buffers) are zero'd out properly
2278 afm.filter_mode = filter_mode;
2280 /* 2) walk over dependencies */
2281 modifiers_foreachIDLink(ob, animfilter_modifier_idpoin_cb, &afm);
2283 /* 3) extract data from the context, merging it back into the standard list */
2285 /* now add the list of collected channels */
2286 BLI_movelisttolist(anim_data, &afm.tmp_data);
2287 BLI_assert(BLI_listbase_is_empty(&afm.tmp_data));
2297 static size_t animdata_filter_ds_particles(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2299 ParticleSystem *psys;
2302 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
2303 ListBase tmp_data = {NULL, NULL};
2304 size_t tmp_items = 0;
2306 /* if no material returned, skip - so that we don't get weird blank entries... */
2307 if (ELEM(NULL, psys->part, psys->part->adt))
2310 /* add particle-system's animation data to temp collection */
2311 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_PART_OBJD(psys->part))
2313 /* particle system's animation data */
2314 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2317 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2318 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2320 END_ANIMFILTER_SUBCHANNELS;
2322 /* did we find anything? */
2324 /* include particle-expand widget first */
2325 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2326 /* check if filtering by active status */
2327 if (ANIMCHANNEL_ACTIVEOK(psys->part)) {
2328 ANIMCHANNEL_NEW_CHANNEL(psys->part, ANIMTYPE_DSPART, psys->part);
2332 /* now add the list of collected channels */
2333 BLI_movelisttolist(anim_data, &tmp_data);
2334 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2339 /* return the number of items added to the list */
2344 static size_t animdata_filter_ds_obdata(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2346 ListBase tmp_data = {NULL, NULL};
2347 size_t tmp_items = 0;
2350 IdAdtTemplate *iat = ob->data;
2351 short type = 0, expanded = 0;
2353 /* get settings based on data type */
2355 case OB_CAMERA: /* ------- Camera ------------ */
2357 Camera *ca = (Camera *)ob->data;
2359 if (ads->filterflag & ADS_FILTER_NOCAM)
2362 type = ANIMTYPE_DSCAM;
2363 expanded = FILTER_CAM_OBJD(ca);
2366 case OB_LAMP: /* ---------- Lamp ----------- */
2368 Lamp *la = (Lamp *)ob->data;
2370 if (ads->filterflag & ADS_FILTER_NOLAM)
2373 type = ANIMTYPE_DSLAM;
2374 expanded = FILTER_LAM_OBJD(la);
2377 case OB_CURVE: /* ------- Curve ---------- */
2378 case OB_SURF: /* ------- Nurbs Surface ---------- */
2379 case OB_FONT: /* ------- Text Curve ---------- */
2381 Curve *cu = (Curve *)ob->data;
2383 if (ads->filterflag & ADS_FILTER_NOCUR)
2386 type = ANIMTYPE_DSCUR;
2387 expanded = FILTER_CUR_OBJD(cu);
2390 case OB_MBALL: /* ------- MetaBall ---------- */
2392 MetaBall *mb = (MetaBall *)ob->data;
2394 if (ads->filterflag & ADS_FILTER_NOMBA)
2397 type = ANIMTYPE_DSMBALL;
2398 expanded = FILTER_MBALL_OBJD(mb);
2401 case OB_ARMATURE: /* ------- Armature ---------- */
2403 bArmature *arm = (bArmature *)ob->data;
2405 if (ads->filterflag & ADS_FILTER_NOARM)
2408 type = ANIMTYPE_DSARM;
2409 expanded = FILTER_ARM_OBJD(arm);
2412 case OB_MESH: /* ------- Mesh ---------- */
2414 Mesh *me = (Mesh *)ob->data;
2416 if (ads->filterflag & ADS_FILTER_NOMESH)
2419 type = ANIMTYPE_DSMESH;
2420 expanded = FILTER_MESH_OBJD(me);
2423 case OB_LATTICE: /* ---- Lattice ---- */
2425 Lattice *lt = (Lattice *)ob->data;
2427 if (ads->filterflag & ADS_FILTER_NOLAT)
2430 type = ANIMTYPE_DSLAT;
2431 expanded = FILTER_LATTICE_OBJD(lt);
2434 case OB_SPEAKER: /* ---------- Speaker ----------- */
2436 Speaker *spk = (Speaker *)ob->data;
2438 type = ANIMTYPE_DSSPK;
2439 expanded = FILTER_SPK_OBJD(spk);
2444 /* add object data animation channels */
2445 BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2447 /* animation data filtering */
2448 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)iat, filter_mode);
2450 /* sub-data filtering... */
2452 case OB_LAMP: /* lamp - textures + nodetree */
2454 Lamp *la = ob->data;
2455 bNodeTree *ntree = la->nodetree;
2458 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2459 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, &la->id, ntree, filter_mode);
2462 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2463 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, &la->id, filter_mode);
2468 END_ANIMFILTER_SUBCHANNELS;
2470 /* did we find anything? */
2472 /* include data-expand widget first */
2473 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2474 /* check if filtering by active status */
2475 if (ANIMCHANNEL_ACTIVEOK(iat)) {
2476 ANIMCHANNEL_NEW_CHANNEL(iat, type, iat);
2480 /* now add the list of collected channels */
2481 BLI_movelisttolist(anim_data, &tmp_data);
2482 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2486 /* return the number of items added to the list */
2490 /* shapekey-level animation */
2491 static size_t animdata_filter_ds_keyanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, Key *key, int filter_mode)
2493 ListBase tmp_data = {NULL, NULL};
2494 size_t tmp_items = 0;
2497 /* add shapekey-level animation channels */
2498 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_SKE_OBJD(key))
2500 /* animation data filtering */
2501 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)key, filter_mode);
2503 END_ANIMFILTER_SUBCHANNELS;
2505 /* did we find anything? */
2507 /* include key-expand widget first */
2508 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2509 if (ANIMCHANNEL_ACTIVEOK(key)) {
2510 ANIMCHANNEL_NEW_CHANNEL(key, ANIMTYPE_DSSKEY, ob);
2514 /* now add the list of collected channels */
2515 BLI_movelisttolist(anim_data, &tmp_data);
2516 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2520 /* return the number of items added to the list */
2525 /* object-level animation */
2526 static size_t animdata_filter_ds_obanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2528 ListBase tmp_data = {NULL, NULL};
2529 size_t tmp_items = 0;
2532 AnimData *adt = ob->adt;
2533 short type = 0, expanded = 1;
2536 /* determine the type of expander channels to use */
2537 /* this is the best way to do this for now... */
2538 ANIMDATA_FILTER_CASES(ob,
2539 { /* AnimData - no channel, but consider data */ },
2540 { /* NLA - no channel, but consider data */ },
2542 type = ANIMTYPE_FILLDRIVERS;
2544 expanded = EXPANDED_DRVD(adt);
2546 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2548 type = ANIMTYPE_FILLACTD;
2549 cdata = adt->action;
2550 expanded = EXPANDED_ACTC(adt->action);
2553 /* add object-level animation channels */
2554 BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2556 /* animation data filtering */
2557 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ob, filter_mode);
2559 END_ANIMFILTER_SUBCHANNELS;
2561 /* did we find anything? */
2563 /* include anim-expand widget first */
2564 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2565 if (type != ANIMTYPE_NONE) {
2566 /* NOTE: active-status (and the associated checks) don't apply here... */
2567 ANIMCHANNEL_NEW_CHANNEL(cdata, type, ob);
2571 /* now add the list of collected channels */
2572 BLI_movelisttolist(anim_data, &tmp_data);
2573 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2577 /* return the number of items added to the list */
2581 /* get animation channels from object2 */
2582 static size_t animdata_filter_dopesheet_ob(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
2584 ListBase tmp_data = {NULL, NULL};
2585 Object *ob = base->object;
2586 size_t tmp_items = 0;
2589 /* filter data contained under object first */
2590 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_OBJC(ob))
2592 Key *key = BKE_key_from_object(ob);
2594 /* object-level animation */
2595 if ((ob->adt) && !(ads->filterflag & ADS_FILTER_NOOBJ)) {
2596 tmp_items += animdata_filter_ds_obanim(ac, &tmp_data, ads, ob, filter_mode);
2600 if ((key && key->adt) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
2601 tmp_items += animdata_filter_ds_keyanim(ac, &tmp_data, ads, ob, key, filter_mode);
2605 if ((ob->modifiers.first) && !(ads->filterflag & ADS_FILTER_NOMODIFIERS)) {
2606 tmp_items += animdata_filter_ds_modifiers(ac, &tmp_data, ads, ob, filter_mode);
2610 if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT)) {
2611 tmp_items += animdata_filter_ds_materials(ac, &tmp_data, ads, ob, filter_mode);
2616 tmp_items += animdata_filter_ds_obdata(ac, &tmp_data, ads, ob, filter_mode);
2620 if ((ob->particlesystem.first) && !(ads->filterflag & ADS_FILTER_NOPART)) {
2621 tmp_items += animdata_filter_ds_particles(ac, &tmp_data, ads, ob, filter_mode);
2625 if ((ob->gpd) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
2626 tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, ob->gpd, filter_mode);
2629 END_ANIMFILTER_SUBCHANNELS;
2632 /* if we collected some channels, add these to the new list... */
2634 /* firstly add object expander if required */
2635 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2636 /* check if filtering by selection */
2637 // XXX: double-check on this - most of the time, a lot of tools need to filter out these channels!
2638 if (ANIMCHANNEL_SELOK((base->flag & BASE_SELECTED))) {
2639 /* check if filtering by active status */
2640 if (ANIMCHANNEL_ACTIVEOK(ob)) {
2641 ANIMCHANNEL_NEW_CHANNEL(base, ANIMTYPE_OBJECT, ob);
2646 /* now add the list of collected channels */
2647 BLI_movelisttolist(anim_data, &tmp_data);
2648 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2652 /* return the number of items added */
2656 static size_t animdata_filter_ds_world(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, World *wo, int filter_mode)
2658 ListBase tmp_data = {NULL, NULL};
2659 size_t tmp_items = 0;
2662 /* add world animation channels */
2663 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_WOR_SCED(wo))
2665 /* animation data filtering */
2666 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode);
2668 /* textures for world */
2669 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2670 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)wo, filter_mode);
2673 if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2674 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)wo, wo->nodetree, filter_mode);
2676 END_ANIMFILTER_SUBCHANNELS;
2678 /* did we find anything? */
2680 /* include data-expand widget first */
2681 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2682 /* check if filtering by active status */
2683 if (ANIMCHANNEL_ACTIVEOK(wo)) {
2684 ANIMCHANNEL_NEW_CHANNEL(wo, ANIMTYPE_DSWOR, sce);
2688 /* now add the list of collected channels */
2689 BLI_movelisttolist(anim_data, &tmp_data);
2690 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2694 /* return the number of items added to the list */
2698 static size_t animdata_filter_ds_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2700 ListBase tmp_data = {NULL, NULL};
2701 size_t tmp_items = 0;
2704 AnimData *adt = sce->adt;
2705 short type = 0, expanded = 1;
2708 /* determine the type of expander channels to use */
2709 // this is the best way to do this for now...
2710 ANIMDATA_FILTER_CASES(sce,
2711 { /* AnimData - no channel, but consider data */},
2712 { /* NLA - no channel, but consider data */},
2714 type = ANIMTYPE_FILLDRIVERS;
2716 expanded = EXPANDED_DRVD(adt);
2718 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2720 type = ANIMTYPE_FILLACTD;
2721 cdata = adt->action;
2722 expanded = EXPANDED_ACTC(adt->action);
2725 /* add scene-level animation channels */
2726 BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2728 /* animation data filtering */
2729 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)sce, filter_mode);
2731 END_ANIMFILTER_SUBCHANNELS;
2733 /* did we find anything? */
2735 /* include anim-expand widget first */
2736 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2737 if (type != ANIMTYPE_NONE) {
2738 /* NOTE: active-status (and the associated checks) don't apply here... */
2739 ANIMCHANNEL_NEW_CHANNEL(cdata, type, sce);
2743 /* now add the list of collected channels */
2744 BLI_movelisttolist(anim_data, &tmp_data);
2745 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2749 /* return the number of items added to the list */
2753 static size_t animdata_filter_dopesheet_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2755 ListBase tmp_data = {NULL, NULL};
2756 size_t tmp_items = 0;
2759 /* filter data contained under object first */
2760 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_SCEC(sce))
2762 bNodeTree *ntree = sce->nodetree;
2763 bGPdata *gpd = sce->gpd;
2764 World *wo = sce->world;
2766 /* Action, Drivers, or NLA for Scene */
2767 if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
2768 tmp_items += animdata_filter_ds_scene(ac, &tmp_data, ads, sce, filter_mode);
2772 if ((wo) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
2773 tmp_items += animdata_filter_ds_world(ac, &tmp_data, ads, sce, wo, filter_mode);
2777 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2778 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
2782 if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
2783 tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
2787 if ((gpd) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
2788 tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, gpd, filter_mode);
2791 /* TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here */
2793 END_ANIMFILTER_SUBCHANNELS;
2795 /* if we collected some channels, add these to the new list... */
2797 /* firstly add object expander if required */
2798 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2799 /* check if filtering by selection */
2800 if (ANIMCHANNEL_SELOK((sce->flag & SCE_DS_SELECTED))) {
2801 /* NOTE: active-status doesn't matter for this! */
2802 ANIMCHANNEL_NEW_CHANNEL(sce, ANIMTYPE_SCENE, sce);
2806 /* now add the list of