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_lamp_types.h"
57 #include "DNA_lattice_types.h"
58 #include "DNA_linestyle_types.h"
59 #include "DNA_key_types.h"
60 #include "DNA_mask_types.h"
61 #include "DNA_material_types.h"
62 #include "DNA_mesh_types.h"
63 #include "DNA_meta_types.h"
64 #include "DNA_node_types.h"
65 #include "DNA_particle_types.h"
66 #include "DNA_space_types.h"
67 #include "DNA_sequence_types.h"
68 #include "DNA_scene_types.h"
69 #include "DNA_screen_types.h"
70 #include "DNA_speaker_types.h"
71 #include "DNA_world_types.h"
72 #include "DNA_gpencil_types.h"
73 #include "DNA_object_types.h"
75 #include "MEM_guardedalloc.h"
77 #include "BLI_blenlib.h"
78 #include "BLI_utildefines.h"
79 #include "BLI_alloca.h"
80 #include "BLI_ghash.h"
81 #include "BLI_string.h"
83 #include "BKE_animsys.h"
84 #include "BKE_action.h"
85 #include "BKE_fcurve.h"
86 #include "BKE_context.h"
87 #include "BKE_global.h"
88 #include "BKE_group.h"
91 #include "BKE_material.h"
92 #include "BKE_modifier.h"
95 #include "BKE_sequencer.h"
97 #include "ED_anim_api.h"
98 #include "ED_markers.h"
100 /* ************************************************************ */
101 /* Blender Context <-> Animation Context mapping */
103 /* ----------- Private Stuff - Action Editor ------------- */
105 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
106 /* Note: there's a similar function in key.c (BKE_key_from_object) */
107 static Key *actedit_get_shapekeys(bAnimContext *ac)
109 Scene *scene = ac->scene;
117 /* XXX pinning is not available in 'ShapeKey' mode... */
118 //if (saction->pin) return NULL;
120 /* shapekey data is stored with geometry data */
121 key = BKE_key_from_object(ob);
124 if (key->type == KEY_RELATIVE)
131 /* Get data being edited in Action Editor (depending on current 'mode') */
132 static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction)
135 ac->ads = &saction->ads;
137 /* sync settings with current view status, then return appropriate data */
138 switch (saction->mode) {
139 case SACTCONT_ACTION: /* 'Action Editor' */
140 /* if not pinned, sync with active object */
141 if (/*saction->pin == 0*/ true) {
142 if (ac->obact && ac->obact->adt)
143 saction->action = ac->obact->adt->action;
145 saction->action = NULL;
148 ac->datatype = ANIMCONT_ACTION;
149 ac->data = saction->action;
151 ac->mode = saction->mode;
154 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
155 ac->datatype = ANIMCONT_SHAPEKEY;
156 ac->data = actedit_get_shapekeys(ac);
158 /* if not pinned, sync with active object */
159 if (/*saction->pin == 0*/ true) {
160 Key *key = (Key *)ac->data;
163 saction->action = key->adt->action;
165 saction->action = NULL;
168 ac->mode = saction->mode;
171 case SACTCONT_GPENCIL: /* Grease Pencil */ /* XXX review how this mode is handled... */
172 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
173 saction->ads.source = (ID *)ac->scene;
175 ac->datatype = ANIMCONT_GPENCIL;
176 ac->data = &saction->ads;
178 ac->mode = saction->mode;
181 case SACTCONT_MASK: /* Mask */ /* XXX review how this mode is handled... */
183 /* TODO, other methods to get the mask */
184 // Sequence *seq = BKE_sequencer_active_get(ac->scene);
185 //MovieClip *clip = ac->scene->clip;
186 // struct Mask *mask = seq ? seq->mask : NULL;
188 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
189 saction->ads.source = (ID *)ac->scene;
191 ac->datatype = ANIMCONT_MASK;
192 ac->data = &saction->ads;
194 ac->mode = saction->mode;
197 case SACTCONT_DOPESHEET: /* DopeSheet */
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_DOPESHEET;
202 ac->data = &saction->ads;
204 ac->mode = saction->mode;
207 default: /* unhandled yet */
208 ac->datatype = ANIMCONT_NONE;
216 /* ----------- Private Stuff - Graph Editor ------------- */
218 /* Get data being edited in Graph Editor (depending on current 'mode') */
219 static bool graphedit_get_context(bAnimContext *ac, SpaceIpo *sipo)
221 /* init dopesheet data if non-existent (i.e. for old files) */
222 if (sipo->ads == NULL) {
223 sipo->ads = MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
224 sipo->ads->source = (ID *)ac->scene;
228 /* set settings for Graph Editor - "Selected = Editable" */
229 if (sipo->flag & SIPO_SELCUVERTSONLY)
230 sipo->ads->filterflag |= ADS_FILTER_SELEDIT;
232 sipo->ads->filterflag &= ~ADS_FILTER_SELEDIT;
234 /* sync settings with current view status, then return appropriate data */
235 switch (sipo->mode) {
236 case SIPO_MODE_ANIMATION: /* Animation F-Curve Editor */
237 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
238 sipo->ads->source = (ID *)ac->scene;
239 sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
241 ac->datatype = ANIMCONT_FCURVES;
242 ac->data = sipo->ads;
244 ac->mode = sipo->mode;
247 case SIPO_MODE_DRIVERS: /* Driver F-Curve Editor */
248 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
249 sipo->ads->source = (ID *)ac->scene;
250 sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
252 ac->datatype = ANIMCONT_DRIVERS;
253 ac->data = sipo->ads;
255 ac->mode = sipo->mode;
258 default: /* unhandled yet */
259 ac->datatype = ANIMCONT_NONE;
267 /* ----------- Private Stuff - NLA Editor ------------- */
269 /* Get data being edited in Graph Editor (depending on current 'mode') */
270 static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla)
272 /* init dopesheet data if non-existent (i.e. for old files) */
273 if (snla->ads == NULL)
274 snla->ads = MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet");
277 /* sync settings with current view status, then return appropriate data */
278 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
279 snla->ads->source = (ID *)ac->scene;
280 snla->ads->filterflag |= ADS_FILTER_ONLYNLA;
282 ac->datatype = ANIMCONT_NLA;
283 ac->data = snla->ads;
288 /* ----------- Public API --------------- */
290 /* Obtain current anim-data context, given that context info from Blender context has already been set
291 * - AnimContext to write to is provided as pointer to var on stack so that we don't have
292 * allocation/freeing costs (which are not that avoidable with channels).
294 bool ANIM_animdata_context_getdata(bAnimContext *ac)
296 SpaceLink *sl = ac->sl;
299 /* context depends on editor we are currently in */
301 switch (ac->spacetype) {
304 SpaceAction *saction = (SpaceAction *)sl;
305 ok = actedit_get_context(ac, saction);
310 SpaceIpo *sipo = (SpaceIpo *)sl;
311 ok = graphedit_get_context(ac, sipo);
316 SpaceNla *snla = (SpaceNla *)sl;
317 ok = nlaedit_get_context(ac, snla);
323 /* check if there's any valid data */
324 return (ok && ac->data);
327 /* Obtain current anim-data context from Blender Context info
328 * - AnimContext to write to is provided as pointer to var on stack so that we don't have
329 * allocation/freeing costs (which are not that avoidable with channels).
330 * - Clears data and sets the information from Blender Context which is useful
332 bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
334 ScrArea *sa = CTX_wm_area(C);
335 ARegion *ar = CTX_wm_region(C);
336 SpaceLink *sl = CTX_wm_space_data(C);
337 Scene *scene = CTX_data_scene(C);
339 /* clear old context info */
340 if (ac == NULL) return false;
341 memset(ac, 0, sizeof(bAnimContext));
343 /* get useful default context settings from context */
346 ac->markers = ED_context_get_markers(C);
347 ac->obact = (scene->basact) ? scene->basact->object : NULL;
352 ac->spacetype = (sa) ? sa->spacetype : 0;
353 ac->regiontype = (ar) ? ar->regiontype : 0;
355 /* get data context info */
356 // XXX: if the below fails, try to grab this info from context instead... (to allow for scripting)
357 return ANIM_animdata_context_getdata(ac);
360 /* ************************************************************ */
361 /* Blender Data <-- Filter --> Channels to be operated on */
363 /* macros to use before/after getting the sub-channels of some channel,
364 * to abstract away some of the tricky logic involved
367 * 1) Graph Edit main area (just data) OR channels visible in Channel List
368 * 2) If not showing channels, we're only interested in the data (Action Editor's editing)
369 * 3) We don't care what data, we just care there is some (so that a collapsed
370 * channel can be kept around). No need to clear channels-flag in order to
371 * keep expander channels with no sub-data out, as those cases should get
372 * dealt with by the recursive detection idiom in place.
374 * Implementation Note:
375 * YES the _doSubChannels variable is NOT read anywhere. BUT, this is NOT an excuse
376 * to go steamrolling the logic into a single-line expression as from experience,
377 * those are notoriously difficult to read + debug when extending later on. The code
378 * below is purposefully laid out so that each case noted above corresponds clearly to
381 #define BEGIN_ANIMFILTER_SUBCHANNELS(expanded_check) \
383 int _filter = filter_mode; \
384 short _doSubChannels = 0; \
385 if (!(filter_mode & ANIMFILTER_LIST_VISIBLE) || (expanded_check)) \
386 _doSubChannels = 1; \
387 else if (!(filter_mode & ANIMFILTER_LIST_CHANNELS)) \
388 _doSubChannels = 2; \
390 filter_mode |= ANIMFILTER_TMP_PEEK; \
394 (void) _doSubChannels; \
396 /* ... standard sub-channel filtering can go on here now ... */
397 #define END_ANIMFILTER_SUBCHANNELS \
398 filter_mode = _filter; \
401 /* ............................... */
403 /* quick macro to test if AnimData is usable */
404 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
406 /* quick macro to test if AnimData is usable for drivers */
407 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
409 /* quick macro to test if AnimData is usable for NLA */
410 #define ANIMDATA_HAS_NLA(id) ((id)->adt && (id)->adt->nla_tracks.first)
412 /* Quick macro to test for all three above usability tests, performing the appropriate provided
413 * action for each when the AnimData context is appropriate.
415 * Priority order for this goes (most important, to least): AnimData blocks, NLA, Drivers, Keyframes.
417 * For this to work correctly, a standard set of data needs to be available within the scope that this
419 * - ListBase anim_data;
421 * - bAnimListElem *ale;
424 * - id: ID block which should have an AnimData pointer following it immediately, to use
425 * - adtOk: line or block of code to execute for AnimData-blocks case (usually ANIMDATA_ADD_ANIMDATA)
426 * - nlaOk: line or block of code to execute for NLA tracks+strips case
427 * - driversOk: line or block of code to execute for Drivers case
428 * - nlaKeysOk: line or block of code for NLA Strip Keyframes case
429 * - keysOk: line or block of code for Keyframes case
431 * The checks for the various cases are as follows:
432 * 0) top level: checks for animdata and also that all the F-Curves for the block will be visible
433 * 1) animdata check: for filtering animdata blocks only
434 * 2A) nla tracks: include animdata block's data as there are NLA tracks+strips there
435 * 2B) actions to convert to nla: include animdata block's data as there is an action that can be
436 * converted to a new NLA strip, and the filtering options allow this
437 * 2C) allow non-animated datablocks to be included so that datablocks can be added
438 * 3) drivers: include drivers from animdata block (for Drivers mode in Graph Editor)
439 * 4A) nla strip keyframes: these are the per-strip controls for time and influence
440 * 4B) normal keyframes: only when there is an active action
442 #define ANIMDATA_FILTER_CASES(id, adtOk, nlaOk, driversOk, nlaKeysOk, keysOk) \
445 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !((id)->adt->flag & ADT_CURVES_NOT_VISIBLE)) { \
446 if (filter_mode & ANIMFILTER_ANIMDATA) { \
449 else if (ads->filterflag & ADS_FILTER_ONLYNLA) { \
450 if (ANIMDATA_HAS_NLA(id)) { \
453 else if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || ANIMDATA_HAS_KEYS(id)) { \
457 else if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) { \
458 if (ANIMDATA_HAS_DRIVERS(id)) { \
463 if (ANIMDATA_HAS_NLA(id)) { \
466 if (ANIMDATA_HAS_KEYS(id)) { \
474 /* ............................... */
476 /* Add a new animation channel, taking into account the "peek" flag, which is used to just check
477 * whether any channels will be added (but without needing them to actually get created).
479 * ! This causes the calling function to return early if we're only "peeking" for channels
481 // XXX: ale_statement stuff is really a hack for one special case. It shouldn't really be needed...
482 #define ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, ale_statement) \
483 if (filter_mode & ANIMFILTER_TMP_PEEK) \
486 bAnimListElem *ale = make_new_animlistelem(channel_data, channel_type, (ID *)owner_id); \
488 BLI_addtail(anim_data, ale); \
494 #define ANIMCHANNEL_NEW_CHANNEL(channel_data, channel_type, owner_id) \
495 ANIMCHANNEL_NEW_CHANNEL_FULL(channel_data, channel_type, owner_id, {})
497 /* ............................... */
499 /* quick macro to test if an anim-channel representing an AnimData block is suitably active */
500 #define ANIMCHANNEL_ACTIVEOK(ale) \
501 (!(filter_mode & ANIMFILTER_ACTIVE) || !(ale->adt) || (ale->adt->flag & ADT_UI_ACTIVE) )
503 /* quick macro to test if an anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
504 #define ANIMCHANNEL_SELOK(test_func) \
505 (!(filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) || \
506 ((filter_mode & ANIMFILTER_SEL) && test_func) || \
507 ((filter_mode & ANIMFILTER_UNSEL) && test_func == 0) )
509 /* quick macro to test if an anim-channel (F-Curve) is selected ok for editing purposes
510 * - _SELEDIT means that only selected curves will have visible+editable keyframes
512 * checks here work as follows:
513 * 1) seledit off - don't need to consider the implications of this option
514 * 2) foredit off - we're not considering editing, so channel is ok still
515 * 3) test_func (i.e. selection test) - only if selected, this test will pass
517 #define ANIMCHANNEL_SELEDITOK(test_func) \
518 (!(filter_mode & ANIMFILTER_SELEDIT) || \
519 !(filter_mode & ANIMFILTER_FOREDIT) || \
522 /* ----------- 'Private' Stuff --------------- */
524 /* this function allocates memory for a new bAnimListElem struct for the
525 * provided animation channel-data.
527 static bAnimListElem *make_new_animlistelem(void *data, short datatype, ID *owner_id)
529 bAnimListElem *ale = NULL;
531 /* only allocate memory if there is data to convert */
533 /* allocate and set generic data */
534 ale = MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
537 ale->type = datatype;
540 ale->adt = BKE_animdata_from_id(owner_id);
544 case ANIMTYPE_SUMMARY:
546 /* nothing to include for now... this is just a dummy wrappy around all the other channels
547 * in the DopeSheet, and gets included at the start of the list
549 ale->key_data = NULL;
550 ale->datatype = ALE_ALL;
555 Scene *sce = (Scene *)data;
557 ale->flag = sce->flag;
560 ale->datatype = ALE_SCE;
562 ale->adt = BKE_animdata_from_id(data);
565 case ANIMTYPE_OBJECT:
567 Base *base = (Base *)data;
568 Object *ob = base->object;
570 ale->flag = ob->flag;
573 ale->datatype = ALE_OB;
575 ale->adt = BKE_animdata_from_id(&ob->id);
578 case ANIMTYPE_FILLACTD:
580 bAction *act = (bAction *)data;
582 ale->flag = act->flag;
585 ale->datatype = ALE_ACT;
588 case ANIMTYPE_FILLDRIVERS:
590 AnimData *adt = (AnimData *)data;
592 ale->flag = adt->flag;
594 // XXX... drivers don't show summary for now
595 ale->key_data = NULL;
596 ale->datatype = ALE_NONE;
601 Material *ma = (Material *)data;
602 AnimData *adt = ma->adt;
604 ale->flag = FILTER_MAT_OBJD(ma);
606 ale->key_data = (adt) ? adt->action : NULL;
607 ale->datatype = ALE_ACT;
609 ale->adt = BKE_animdata_from_id(data);
614 Lamp *la = (Lamp *)data;
615 AnimData *adt = la->adt;
617 ale->flag = FILTER_LAM_OBJD(la);
619 ale->key_data = (adt) ? adt->action : NULL;
620 ale->datatype = ALE_ACT;
622 ale->adt = BKE_animdata_from_id(data);
627 Camera *ca = (Camera *)data;
628 AnimData *adt = ca->adt;
630 ale->flag = FILTER_CAM_OBJD(ca);
632 ale->key_data = (adt) ? adt->action : NULL;
633 ale->datatype = ALE_ACT;
635 ale->adt = BKE_animdata_from_id(data);
640 Curve *cu = (Curve *)data;
641 AnimData *adt = cu->adt;
643 ale->flag = FILTER_CUR_OBJD(cu);
645 ale->key_data = (adt) ? adt->action : NULL;
646 ale->datatype = ALE_ACT;
648 ale->adt = BKE_animdata_from_id(data);
653 bArmature *arm = (bArmature *)data;
654 AnimData *adt = arm->adt;
656 ale->flag = FILTER_ARM_OBJD(arm);
658 ale->key_data = (adt) ? adt->action : NULL;
659 ale->datatype = ALE_ACT;
661 ale->adt = BKE_animdata_from_id(data);
664 case ANIMTYPE_DSMESH:
666 Mesh *me = (Mesh *)data;
667 AnimData *adt = me->adt;
669 ale->flag = FILTER_MESH_OBJD(me);
671 ale->key_data = (adt) ? adt->action : NULL;
672 ale->datatype = ALE_ACT;
674 ale->adt = BKE_animdata_from_id(data);
679 Lattice *lt = (Lattice *)data;
680 AnimData *adt = lt->adt;
682 ale->flag = FILTER_LATTICE_OBJD(lt);
684 ale->key_data = (adt) ? adt->action : NULL;
685 ale->datatype = ALE_ACT;
687 ale->adt = BKE_animdata_from_id(data);
692 Speaker *spk = (Speaker *)data;
693 AnimData *adt = spk->adt;
695 ale->flag = FILTER_SPK_OBJD(spk);
697 ale->key_data = (adt) ? adt->action : NULL;
698 ale->datatype = ALE_ACT;
700 ale->adt = BKE_animdata_from_id(data);
703 case ANIMTYPE_DSSKEY:
705 Key *key = (Key *)data;
706 AnimData *adt = key->adt;
708 ale->flag = FILTER_SKE_OBJD(key);
710 ale->key_data = (adt) ? adt->action : NULL;
711 ale->datatype = ALE_ACT;
713 ale->adt = BKE_animdata_from_id(data);
718 World *wo = (World *)data;
719 AnimData *adt = wo->adt;
721 ale->flag = FILTER_WOR_SCED(wo);
723 ale->key_data = (adt) ? adt->action : NULL;
724 ale->datatype = ALE_ACT;
726 ale->adt = BKE_animdata_from_id(data);
729 case ANIMTYPE_DSNTREE:
731 bNodeTree *ntree = (bNodeTree *)data;
732 AnimData *adt = ntree->adt;
734 ale->flag = FILTER_NTREE_DATA(ntree);
736 ale->key_data = (adt) ? adt->action : NULL;
737 ale->datatype = ALE_ACT;
739 ale->adt = BKE_animdata_from_id(data);
742 case ANIMTYPE_DSLINESTYLE:
744 FreestyleLineStyle *linestyle = (FreestyleLineStyle *)data;
745 AnimData *adt = linestyle->adt;
747 ale->flag = FILTER_LS_SCED(linestyle);
749 ale->key_data = (adt) ? adt->action : NULL;
750 ale->datatype = ALE_ACT;
752 ale->adt = BKE_animdata_from_id(data);
755 case ANIMTYPE_DSPART:
757 ParticleSettings *part = (ParticleSettings *)ale->data;
758 AnimData *adt = part->adt;
760 ale->flag = FILTER_PART_OBJD(part);
762 ale->key_data = (adt) ? adt->action : NULL;
763 ale->datatype = ALE_ACT;
765 ale->adt = BKE_animdata_from_id(data);
770 Tex *tex = (Tex *)data;
771 AnimData *adt = tex->adt;
773 ale->flag = FILTER_TEX_DATA(tex);
775 ale->key_data = (adt) ? adt->action : NULL;
776 ale->datatype = ALE_ACT;
778 ale->adt = BKE_animdata_from_id(data);
781 case ANIMTYPE_DSGPENCIL:
783 bGPdata *gpd = (bGPdata *)data;
784 AnimData *adt = gpd->adt;
786 /* NOTE: we just reuse the same expand filter for this case */
787 ale->flag = EXPANDED_GPD(gpd);
789 // XXX: currently, this is only used for access to its animation data
790 ale->key_data = (adt) ? adt->action : NULL;
791 ale->datatype = ALE_ACT;
793 ale->adt = BKE_animdata_from_id(data);
796 case ANIMTYPE_NLACONTROLS:
798 AnimData *adt = (AnimData *)data;
800 ale->flag = adt->flag;
802 ale->key_data = NULL;
803 ale->datatype = ALE_NONE;
808 bActionGroup *agrp = (bActionGroup *)data;
810 ale->flag = agrp->flag;
812 ale->key_data = NULL;
813 ale->datatype = ALE_GROUP;
816 case ANIMTYPE_FCURVE:
818 FCurve *fcu = (FCurve *)data;
820 ale->flag = fcu->flag;
823 ale->datatype = ALE_FCURVE;
826 case ANIMTYPE_SHAPEKEY:
828 KeyBlock *kb = (KeyBlock *)data;
829 Key *key = (Key *)ale->id;
831 ale->flag = kb->flag;
833 /* whether we have keyframes depends on whether there is a Key block to find it from */
835 /* index of shapekey is defined by place in key's list */
836 ale->index = BLI_findindex(&key->block, kb);
838 /* the corresponding keyframes are from the animdata */
839 if (ale->adt && ale->adt->action) {
840 bAction *act = ale->adt->action;
841 char *rna_path = BKE_keyblock_curval_rnapath_get(key, kb);
843 /* try to find the F-Curve which corresponds to this exactly,
844 * then free the MEM_alloc'd string
847 ale->key_data = (void *)list_find_fcurve(&act->curves, rna_path, 0);
851 ale->datatype = (ale->key_data) ? ALE_FCURVE : ALE_NONE;
855 case ANIMTYPE_GPLAYER:
857 bGPDlayer *gpl = (bGPDlayer *)data;
859 ale->flag = gpl->flag;
861 ale->key_data = NULL;
862 ale->datatype = ALE_GPFRAME;
865 case ANIMTYPE_MASKLAYER:
867 MaskLayer *masklay = (MaskLayer *)data;
869 ale->flag = masklay->flag;
871 ale->key_data = NULL;
872 ale->datatype = ALE_MASKLAY;
875 case ANIMTYPE_NLATRACK:
877 NlaTrack *nlt = (NlaTrack *)data;
879 ale->flag = nlt->flag;
881 ale->key_data = &nlt->strips;
882 ale->datatype = ALE_NLASTRIP;
885 case ANIMTYPE_NLAACTION:
887 /* nothing to include for now... nothing editable from NLA-perspective here */
888 ale->key_data = NULL;
889 ale->datatype = ALE_NONE;
895 /* return created datatype */
899 /* ----------------------------------------- */
901 /* 'Only Selected' selected data and/or 'Include Hidden' filtering
902 * NOTE: when this function returns true, the F-Curve is to be skipped
904 static bool skip_fcurve_selected_data(bDopeSheet *ads, FCurve *fcu, ID *owner_id, int filter_mode)
906 /* hidden items should be skipped if we only care about visible data, but we aren't interested in hidden stuff */
907 const bool skip_hidden = (filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN);
909 if (GS(owner_id->name) == ID_OB) {
910 Object *ob = (Object *)owner_id;
912 /* only consider if F-Curve involves pose.bones */
913 if ((fcu->rna_path) && strstr(fcu->rna_path, "pose.bones")) {
917 /* get bone-name, and check if this bone is selected */
918 bone_name = BLI_str_quoted_substrN(fcu->rna_path, "pose.bones[");
919 pchan = BKE_pose_channel_find_name(ob->pose, bone_name);
920 if (bone_name) MEM_freeN(bone_name);
922 /* check whether to continue or skip */
923 if ((pchan) && (pchan->bone)) {
924 /* if only visible channels, skip if bone not visible unless user wants channels from hidden data too */
926 bArmature *arm = (bArmature *)ob->data;
928 /* skipping - not visible on currently visible layers */
929 if ((arm->layer & pchan->bone->layer) == 0)
931 /* skipping - is currently hidden */
932 if (pchan->bone->flag & BONE_HIDDEN_P)
936 /* can only add this F-Curve if it is selected */
937 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
938 if ((pchan->bone->flag & BONE_SELECTED) == 0)
944 else if (GS(owner_id->name) == ID_SCE) {
945 Scene *scene = (Scene *)owner_id;
947 /* only consider if F-Curve involves sequence_editor.sequences */
948 if ((fcu->rna_path) && strstr(fcu->rna_path, "sequences_all")) {
949 Editing *ed = BKE_sequencer_editing_get(scene, false);
950 Sequence *seq = NULL;
954 /* get strip name, and check if this strip is selected */
955 seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
956 seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false);
957 if (seq_name) MEM_freeN(seq_name);
960 /* can only add this F-Curve if it is selected */
961 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
962 if ((seq == NULL) || (seq->flag & SELECT) == 0)
967 else if (GS(owner_id->name) == ID_NT) {
968 bNodeTree *ntree = (bNodeTree *)owner_id;
970 /* check for selected nodes */
971 if ((fcu->rna_path) && strstr(fcu->rna_path, "nodes")) {
975 /* get strip name, and check if this strip is selected */
976 node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes[");
977 node = nodeFindNodebyName(ntree, node_name);
978 if (node_name) MEM_freeN(node_name);
980 /* can only add this F-Curve if it is selected */
981 if (ads->filterflag & ADS_FILTER_ONLYSEL) {
982 if ((node) && (node->flag & NODE_SELECT) == 0)
991 /* Helper for name-based filtering - Perform "partial/fuzzy matches" (as in 80a7efd) */
992 static bool name_matches_dopesheet_filter(bDopeSheet *ads, char *name)
994 if (ads->flag & ADS_FLAG_FUZZY_NAMES) {
995 /* full fuzzy, multi-word, case insensitive matches */
996 const size_t str_len = strlen(ads->searchstr);
997 const int words_max = (str_len / 2) + 1;
999 int (*words)[2] = BLI_array_alloca(words, words_max);
1000 const int words_len = BLI_string_find_split_words(ads->searchstr, str_len, ' ', words, words_max);
1003 /* match name against all search words */
1004 for (int index = 0; index < words_len; index++) {
1005 if (BLI_strncasestr(name, ads->searchstr + words[index][0], words[index][1])) {
1011 /* if we have a match somewhere, this returns true */
1015 /* fallback/default - just case insensitive, but starts from start of word */
1016 return BLI_strcasestr(name, ads->searchstr) != NULL;
1020 /* (Display-)Name-based F-Curve filtering
1021 * NOTE: when this function returns true, the F-Curve is to be skipped
1023 static bool skip_fcurve_with_name(bDopeSheet *ads, FCurve *fcu, ID *owner_id)
1025 bAnimListElem ale_dummy = {NULL};
1026 const bAnimChannelType *acf;
1028 /* create a dummy wrapper for the F-Curve */
1029 ale_dummy.type = ANIMTYPE_FCURVE;
1030 ale_dummy.id = owner_id;
1031 ale_dummy.data = fcu;
1033 /* get type info for channel */
1034 acf = ANIM_channel_get_typeinfo(&ale_dummy);
1035 if (acf && acf->name) {
1036 char name[256]; /* hopefully this will be enough! */
1039 acf->name(&ale_dummy, name);
1041 /* check for partial match with the match string, assuming case insensitive filtering
1042 * if match, this channel shouldn't be ignored!
1044 return !name_matches_dopesheet_filter(ads, name);
1047 /* just let this go... */
1052 * Check if F-Curve has errors and/or is disabled
1054 * \return true if F-Curve has errors/is disabled
1056 static bool fcurve_has_errors(FCurve *fcu)
1058 /* F-Curve disabled - path eval error */
1059 if (fcu->flag & FCURVE_DISABLED) {
1065 ChannelDriver *driver = fcu->driver;
1068 /* error flag on driver usually means that there is an error
1069 * BUT this may not hold with PyDrivers as this flag gets cleared
1070 * if no critical errors prevent the driver from working...
1072 if (driver->flag & DRIVER_FLAG_INVALID)
1075 /* check variables for other things that need linting... */
1076 // TODO: maybe it would be more efficient just to have a quick flag for this?
1077 for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
1078 DRIVER_TARGETS_USED_LOOPER(dvar)
1080 if (dtar->flag & DTAR_FLAG_INVALID)
1083 DRIVER_TARGETS_LOOPER_END
1087 /* no errors found */
1091 /* find the next F-Curve that is usable for inclusion */
1092 static FCurve *animfilter_fcurve_next(bDopeSheet *ads, FCurve *first, bActionGroup *grp, int filter_mode, ID *owner_id)
1096 /* loop over F-Curves - assume that the caller of this has already checked that these should be included
1097 * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
1099 for (fcu = first; ((fcu) && (fcu->grp == grp)); fcu = fcu->next) {
1100 /* special exception for Pose-Channel/Sequence-Strip/Node Based F-Curves:
1101 * - the 'Only Selected' and 'Include Hidden' data filters should be applied to sub-ID data which
1102 * can be independently selected/hidden, such as Pose-Channels, Sequence Strips, and Nodes.
1103 * Since these checks were traditionally done as first check for objects, we do the same here
1104 * - we currently use an 'approximate' method for getting these F-Curves that doesn't require
1105 * carefully checking the entire path
1106 * - this will also affect things like Drivers, and also works for Bone Constraints
1108 if (ads && owner_id) {
1109 if ((filter_mode & ANIMFILTER_TMP_IGNORE_ONLYSEL) == 0) {
1110 if ((ads->filterflag & ADS_FILTER_ONLYSEL) || (ads->filterflag & ADS_FILTER_INCL_HIDDEN) == 0) {
1111 if (skip_fcurve_selected_data(ads, fcu, owner_id, filter_mode))
1117 /* only include if visible (Graph Editor check, not channels check) */
1118 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
1119 /* only work with this channel and its subchannels if it is editable */
1120 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
1121 /* only include this curve if selected in a way consistent with the filtering requirements */
1122 if (ANIMCHANNEL_SELOK(SEL_FCU(fcu)) && ANIMCHANNEL_SELEDITOK(SEL_FCU(fcu))) {
1123 /* only include if this curve is active */
1124 if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
1125 /* name based filtering... */
1126 if ( ((ads) && (ads->filterflag & ADS_FILTER_BY_FCU_NAME)) && (owner_id) ) {
1127 if (skip_fcurve_with_name(ads, fcu, owner_id))
1131 /* error-based filtering... */
1132 if ((ads) && (ads->filterflag & ADS_FILTER_ONLY_ERRORS)) {
1133 /* skip if no errors... */
1134 if (fcurve_has_errors(fcu) == false)
1138 /* this F-Curve can be used, so return it */
1146 /* no (more) F-Curves from the list are suitable... */
1150 static size_t animfilter_fcurves(ListBase *anim_data, bDopeSheet *ads, FCurve *first, bActionGroup *grp, int filter_mode, ID *owner_id)
1155 /* loop over every F-Curve able to be included
1156 * - this for-loop works like this:
1157 * 1) the starting F-Curve is assigned to the fcu pointer so that we have a starting point to search from
1158 * 2) the first valid F-Curve to start from (which may include the one given as 'first') in the remaining
1159 * list of F-Curves is found, and verified to be non-null
1160 * 3) the F-Curve referenced by fcu pointer is added to the list
1161 * 4) the fcu pointer is set to the F-Curve after the one we just added, so that we can keep going through
1162 * the rest of the F-Curve list without an eternal loop. Back to step 2 :)
1164 for (fcu = first; ( (fcu = animfilter_fcurve_next(ads, fcu, grp, filter_mode, owner_id)) ); fcu = fcu->next) {
1165 ANIMCHANNEL_NEW_CHANNEL(fcu, ANIMTYPE_FCURVE, owner_id);
1168 /* return the number of items added to the list */
1172 static size_t animfilter_act_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *UNUSED(act), bActionGroup *agrp, int filter_mode, ID *owner_id)
1174 ListBase tmp_data = {NULL, NULL};
1175 size_t tmp_items = 0;
1177 //int ofilter = filter_mode;
1179 /* if we care about the selection status of the channels,
1180 * but the group isn't expanded (1)...
1181 * (1) this only matters if we actually care about the hierarchy though.
1182 * - Hierarchy matters: this hack should be applied
1183 * - Hierarchy ignored: cases like [#21276] won't work properly, unless we skip this hack
1185 if ( ((filter_mode & ANIMFILTER_LIST_VISIBLE) && EXPANDED_AGRP(ac, agrp) == 0) && /* care about hierarchy but group isn't expanded */
1186 (filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) ) /* care about selection status */
1188 /* if the group itself isn't selected appropriately, we shouldn't consider it's children either */
1189 if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) == 0)
1192 /* if we're still here, then the selection status of the curves within this group should not matter,
1193 * since this creates too much overhead for animators (i.e. making a slow workflow)
1195 * Tools affected by this at time of coding (2010 Feb 09):
1196 * - inserting keyframes on selected channels only
1197 * - pasting keyframes
1198 * - creating ghost curves in Graph Editor
1200 filter_mode &= ~(ANIMFILTER_SEL | ANIMFILTER_UNSEL | ANIMFILTER_LIST_VISIBLE);
1203 /* add grouped F-Curves */
1204 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_AGRP(ac, agrp))
1206 /* special filter so that we can get just the F-Curves within the active group */
1207 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
1208 /* for the Graph Editor, curves may be set to not be visible in the view to lessen clutter,
1209 * but to do this, we need to check that the group doesn't have it's not-visible flag set preventing
1210 * all its sub-curves to be shown
1212 if (!(filter_mode & ANIMFILTER_CURVE_VISIBLE) || !(agrp->flag & AGRP_NOTVISIBLE)) {
1213 /* group must be editable for its children to be editable (if we care about this) */
1214 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
1215 /* get first F-Curve which can be used here */
1216 FCurve *first_fcu = animfilter_fcurve_next(ads, agrp->channels.first, agrp, filter_mode, owner_id);
1218 /* filter list, starting from this F-Curve */
1219 tmp_items += animfilter_fcurves(&tmp_data, ads, first_fcu, agrp, filter_mode, owner_id);
1224 END_ANIMFILTER_SUBCHANNELS;
1226 /* did we find anything? */
1228 /* add this group as a channel first */
1229 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1230 /* restore original filter mode so that this next step works ok... */
1231 //filter_mode = ofilter;
1233 /* filter selection of channel specially here again, since may be open and not subject to previous test */
1234 if (ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
1235 ANIMCHANNEL_NEW_CHANNEL(agrp, ANIMTYPE_GROUP, owner_id);
1239 /* now add the list of collected channels */
1240 BLI_movelisttolist(anim_data, &tmp_data);
1241 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1245 /* return the number of items added to the list */
1249 static size_t animfilter_action(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bAction *act, int filter_mode, ID *owner_id)
1252 FCurve *lastchan = NULL;
1255 /* don't include anything from this action if it is linked in from another file,
1256 * and we're getting stuff for editing...
1258 if ((filter_mode & ANIMFILTER_FOREDIT) && ID_IS_LINKED_DATABLOCK(act))
1262 // TODO: do nested groups?
1263 for (agrp = act->groups.first; agrp; agrp = agrp->next) {
1264 /* store reference to last channel of group */
1265 if (agrp->channels.last)
1266 lastchan = agrp->channels.last;
1268 /* action group's channels */
1269 items += animfilter_act_group(ac, anim_data, ads, act, agrp, filter_mode, owner_id);
1272 /* un-grouped F-Curves (only if we're not only considering those channels in the active group) */
1273 if (!(filter_mode & ANIMFILTER_ACTGROUPED)) {
1274 FCurve *firstfcu = (lastchan) ? (lastchan->next) : (act->curves.first);
1275 items += animfilter_fcurves(anim_data, ads, firstfcu, NULL, filter_mode, owner_id);
1278 /* return the number of items added to the list */
1282 /* Include NLA-Data for NLA-Editor:
1283 * - when ANIMFILTER_LIST_CHANNELS is used, that means we should be filtering the list for display
1284 * Although the evaluation order is from the first track to the last and then apply the Action on top,
1285 * we present this in the UI as the Active Action followed by the last track to the first so that we
1286 * get the evaluation order presented as per a stack.
1287 * - for normal filtering (i.e. for editing), we only need the NLA-tracks but they can be in 'normal' evaluation
1288 * order, i.e. first to last. Otherwise, some tools may get screwed up.
1290 static size_t animfilter_nla(bAnimContext *UNUSED(ac), ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1293 NlaTrack *first = NULL, *next = NULL;
1296 /* if showing channels, include active action */
1297 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1298 /* if NLA action-line filtering is off, don't show unless there are keyframes,
1299 * in order to keep things more compact for doing transforms
1301 if (!(ads->filterflag & ADS_FILTER_NLA_NOACT) || (adt->action)) {
1302 /* there isn't really anything editable here, so skip if need editable */
1303 if ((filter_mode & ANIMFILTER_FOREDIT) == 0) {
1304 /* just add the action track now (this MUST appear for drawing)
1305 * - as AnimData may not have an action, we pass a dummy pointer just to get the list elem created, then
1306 * overwrite this with the real value - REVIEW THIS...
1308 ANIMCHANNEL_NEW_CHANNEL_FULL((void *)(&adt->action), ANIMTYPE_NLAACTION, owner_id,
1310 ale->data = adt->action ? adt->action : NULL;
1315 /* first track to include will be the last one if we're filtering by channels */
1316 first = adt->nla_tracks.last;
1319 /* first track to include will the first one (as per normal) */
1320 first = adt->nla_tracks.first;
1323 /* loop over NLA Tracks - assume that the caller of this has already checked that these should be included */
1324 for (nlt = first; nlt; nlt = next) {
1325 /* 'next' NLA-Track to use depends on whether we're filtering for drawing or not */
1326 if (filter_mode & ANIMFILTER_LIST_CHANNELS)
1331 /* if we're in NLA-tweakmode, don't show this track if it was disabled (due to tweaking) for now
1332 * - active track should still get shown though (even though it has disabled flag set)
1334 // FIXME: the channels after should still get drawn, just 'differently', and after an active-action channel
1335 if ((adt->flag & ADT_NLA_EDIT_ON) && (nlt->flag & NLATRACK_DISABLED) && (adt->act_track != nlt))
1338 /* only work with this channel and its subchannels if it is editable */
1339 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_NLT(nlt)) {
1340 /* only include this track if selected in a way consistent with the filtering requirements */
1341 if (ANIMCHANNEL_SELOK(SEL_NLT(nlt))) {
1342 /* only include if this track is active */
1343 if (!(filter_mode & ANIMFILTER_ACTIVE) || (nlt->flag & NLATRACK_ACTIVE)) {
1344 /* name based filtering... */
1345 if (((ads) && (ads->filterflag & ADS_FILTER_BY_FCU_NAME)) && (owner_id)) {
1346 bool track_ok = false, strip_ok = false;
1348 /* check if the name of the track, or the strips it has are ok... */
1349 track_ok = name_matches_dopesheet_filter(ads, nlt->name);
1351 if (track_ok == false) {
1353 for (strip = nlt->strips.first; strip; strip = strip->next) {
1354 if (name_matches_dopesheet_filter(ads, strip->name)) {
1361 /* skip if both fail this test... */
1362 if (!track_ok && !strip_ok) {
1367 /* add the track now that it has passed all our tests */
1368 ANIMCHANNEL_NEW_CHANNEL(nlt, ANIMTYPE_NLATRACK, owner_id);
1374 /* return the number of items added to the list */
1378 /* Include the control FCurves per NLA Strip in the channel list
1379 * NOTE: This is includes the expander too...
1381 static size_t animfilter_nla_controls(ListBase *anim_data, bDopeSheet *ads, AnimData *adt, int filter_mode, ID *owner_id)
1383 ListBase tmp_data = {NULL, NULL};
1384 size_t tmp_items = 0;
1387 /* add control curves from each NLA strip... */
1388 /* NOTE: ANIMTYPE_FCURVES are created here, to avoid duplicating the code needed */
1389 BEGIN_ANIMFILTER_SUBCHANNELS(((adt->flag & ADT_NLA_SKEYS_COLLAPSED) == 0))
1394 /* for now, we only go one level deep - so controls on grouped FCurves are not handled */
1395 for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
1396 for (strip = nlt->strips.first; strip; strip = strip->next) {
1397 ListBase strip_curves = {NULL, NULL};
1398 size_t strip_items = 0;
1400 /* create the raw items */
1401 strip_items += animfilter_fcurves(&strip_curves, ads, strip->fcurves.first, NULL, filter_mode, owner_id);
1403 /* change their types and add extra data
1404 * - There is no point making a separate copy of animfilter_fcurves for this now/yet,
1405 * unless we later get per-element control curves for other stuff too
1408 bAnimListElem *ale, *ale_n = NULL;
1410 for (ale = strip_curves.first; ale; ale = ale_n) {
1413 /* change the type to being a FCurve for editing NLA strip controls */
1414 BLI_assert(ale->type == ANIMTYPE_FCURVE);
1416 ale->type = ANIMTYPE_NLACURVE;
1419 ale->adt = NULL; /* XXX: This way, there are no problems with time mapping errors */
1423 /* add strip curves to the set of channels inside the group being collected */
1424 BLI_movelisttolist(&tmp_data, &strip_curves);
1425 BLI_assert(BLI_listbase_is_empty(&strip_curves));
1426 tmp_items += strip_items;
1430 END_ANIMFILTER_SUBCHANNELS;
1432 /* did we find anything? */
1434 /* add the expander as a channel first */
1435 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1436 /* currently these channels cannot be selected, so they should be skipped */
1437 if ((filter_mode & (ANIMFILTER_SEL | ANIMFILTER_UNSEL)) == 0) {
1438 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_NLACONTROLS, owner_id);
1442 /* now add the list of collected channels */
1443 BLI_movelisttolist(anim_data, &tmp_data);
1444 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1448 /* return the numebr of items added to the list */
1452 /* determine what animation data from AnimData block should get displayed */
1453 static size_t animfilter_block_data(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *id, int filter_mode)
1455 AnimData *adt = BKE_animdata_from_id(id);
1458 /* image object datablocks have no anim-data so check for NULL */
1460 IdAdtTemplate *iat = (IdAdtTemplate *)id;
1462 /* NOTE: this macro is used instead of inlining the logic here, since this sort of filtering is still needed
1463 * in a few places in the rest of the code still - notably for the few cases where special mode-based
1464 * different types of data expanders are required.
1466 ANIMDATA_FILTER_CASES(iat,
1468 /* specifically filter animdata block */
1469 if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(adt)) ) {
1470 ANIMCHANNEL_NEW_CHANNEL(adt, ANIMTYPE_ANIMDATA, id);
1474 items += animfilter_nla(ac, anim_data, ads, adt, filter_mode, id);
1477 items += animfilter_fcurves(anim_data, ads, adt->drivers.first, NULL, filter_mode, id);
1479 { /* NLA Control Keyframes */
1480 items += animfilter_nla_controls(anim_data, ads, adt, filter_mode, id);
1483 items += animfilter_action(ac, anim_data, ads, adt->action, filter_mode, id);
1493 /* Include ShapeKey Data for ShapeKey Editor */
1494 static size_t animdata_filter_shapekey(bAnimContext *ac, ListBase *anim_data, Key *key, int filter_mode)
1498 /* check if channels or only F-Curves */
1499 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1502 /* loop through the channels adding ShapeKeys as appropriate */
1503 for (kb = key->block.first; kb; kb = kb->next) {
1504 /* skip the first one, since that's the non-animatable basis */
1505 if (kb == key->block.first) continue;
1507 /* only work with this channel and its subchannels if it is editable */
1508 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_SHAPEKEY(kb)) {
1509 /* only include this track if selected in a way consistent with the filtering requirements */
1510 if (ANIMCHANNEL_SELOK(SEL_SHAPEKEY(kb)) ) {
1511 // TODO: consider 'active' too?
1513 /* owner-id here must be key so that the F-Curve can be resolved... */
1514 ANIMCHANNEL_NEW_CHANNEL(kb, ANIMTYPE_SHAPEKEY, key);
1520 /* just use the action associated with the shapekey */
1521 // TODO: somehow manage to pass dopesheet info down here too?
1523 if (filter_mode & ANIMFILTER_ANIMDATA) {
1524 if (ANIMCHANNEL_SELOK(SEL_ANIMDATA(key->adt)) ) {
1525 ANIMCHANNEL_NEW_CHANNEL(key->adt, ANIMTYPE_ANIMDATA, key);
1528 else if (key->adt->action) {
1529 items = animfilter_action(ac, anim_data, NULL, key->adt->action, filter_mode, (ID *)key);
1534 /* return the number of items added to the list */
1538 /* Helper for Grease Pencil - layers within a datablock */
1539 static size_t animdata_filter_gpencil_layers_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1544 /* loop over layers as the conditions are acceptable */
1545 for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
1546 /* only if selected */
1547 if (ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
1548 /* only if editable */
1549 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
1551 if (!(filter_mode & ANIMFILTER_ACTIVE) || (gpl->flag & GP_LAYER_ACTIVE)) {
1552 /* skip layer if the name doesn't match the filter string */
1553 if ((ads) && (ads->filterflag & ADS_FILTER_BY_FCU_NAME)) {
1554 if (name_matches_dopesheet_filter(ads, gpl->info) == false)
1560 ANIMCHANNEL_NEW_CHANNEL(gpl, ANIMTYPE_GPLAYER, gpd);
1569 /* Helper for Grease Pencil - Grease Pencil datablock - GP Frames */
1570 static size_t animdata_filter_gpencil_data(ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1574 /* When asked from "AnimData" blocks (i.e. the top-level containers for normal animation),
1575 * for convenience, this will return GP Datablocks instead. This may cause issues down
1576 * the track, but for now, this will do...
1578 if (filter_mode & ANIMFILTER_ANIMDATA) {
1579 /* just add GPD as a channel - this will add everything needed */
1580 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL);
1583 ListBase tmp_data = {NULL, NULL};
1584 size_t tmp_items = 0;
1586 /* add gpencil animation channels */
1587 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1589 tmp_items += animdata_filter_gpencil_layers_data(&tmp_data, ads, gpd, filter_mode);
1591 END_ANIMFILTER_SUBCHANNELS;
1593 /* did we find anything? */
1595 /* include data-expand widget first */
1596 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1597 /* add gpd as channel too (if for drawing, and it has layers) */
1598 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_GPDATABLOCK, NULL);
1601 /* now add the list of collected channels */
1602 BLI_movelisttolist(anim_data, &tmp_data);
1603 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1611 /* Grab all Grease Pencil datablocks in file */
1612 // TODO: should this be amalgamated with the dopesheet filtering code?
1613 static size_t animdata_filter_gpencil(bAnimContext *ac, ListBase *anim_data, void *UNUSED(data), int filter_mode)
1615 bDopeSheet *ads = ac->ads;
1618 if (ads->filterflag & ADS_FILTER_GP_3DONLY) {
1619 Scene *scene = (Scene *)ads->source;
1622 /* Active scene's GPencil block first - No parent item needed... */
1624 items += animdata_filter_gpencil_data(anim_data, ads, scene->gpd, filter_mode);
1627 /* Objects in the scene */
1628 for (base = scene->base.first; base; base = base->next) {
1629 /* Only consider this object if it has got some GP data (saving on all the other tests) */
1630 if (base->object && base->object->gpd) {
1631 Object *ob = base->object;
1633 /* firstly, check if object can be included, by the following factors:
1634 * - if only visible, must check for layer and also viewport visibility
1635 * --> while tools may demand only visible, user setting takes priority
1636 * as user option controls whether sets of channels get included while
1637 * tool-flag takes into account collapsed/open channels too
1638 * - if only selected, must check if object is selected
1639 * - there must be animation data to edit (this is done recursively as we
1640 * try to add the channels)
1642 if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
1643 /* layer visibility - we check both object and base, since these may not be in sync yet */
1644 if ((scene->lay & (ob->lay | base->lay)) == 0) continue;
1646 /* outliner restrict-flag */
1647 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1650 /* check selection and object type filters */
1651 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) /*|| (base == scene->basact)*/) ) {
1652 /* only selected should be shown */
1656 /* check if object belongs to the filtering group if option to filter
1657 * objects by the grouped status is on
1658 * - used to ease the process of doing multiple-character choreographies
1660 if (ads->filterflag & ADS_FILTER_ONLYOBGROUP) {
1661 if (BKE_group_object_exists(ads->filter_grp, ob) == 0)
1665 /* finally, include this object's grease pencil datablock */
1666 /* XXX: Should we store these under expanders per item? */
1667 items += animdata_filter_gpencil_data(anim_data, ads, ob->gpd, filter_mode);
1674 /* Grab all Grease Pencil datablocks directly from main, but only those that seem to be useful somewhere */
1675 for (gpd = G.main->gpencil.first; gpd; gpd = gpd->id.next) {
1676 /* only show if gpd is used by something... */
1677 if (ID_REAL_USERS(gpd) < 1)
1680 /* add GP frames from this datablock */
1681 items += animdata_filter_gpencil_data(anim_data, ads, gpd, filter_mode);
1685 /* return the number of items added to the list */
1689 /* Helper for Grease Pencil data integrated with main DopeSheet */
1690 static size_t animdata_filter_ds_gpencil(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, bGPdata *gpd, int filter_mode)
1692 ListBase tmp_data = {NULL, NULL};
1693 size_t tmp_items = 0;
1696 /* add relevant animation channels for Grease Pencil */
1697 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_GPD(gpd))
1699 /* add animation channels */
1700 tmp_items += animfilter_block_data(ac, &tmp_data, ads, &gpd->id, filter_mode);
1702 /* add Grease Pencil layers */
1703 // TODO: do these need a separate expander?
1704 // XXX: what order should these go in?
1706 END_ANIMFILTER_SUBCHANNELS;
1708 /* did we find anything? */
1710 /* include data-expand widget first */
1711 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1712 /* check if filtering by active status */
1713 // XXX: active check here needs checking
1714 if (ANIMCHANNEL_ACTIVEOK(gpd)) {
1715 ANIMCHANNEL_NEW_CHANNEL(gpd, ANIMTYPE_DSGPENCIL, gpd);
1719 /* now add the list of collected channels */
1720 BLI_movelisttolist(anim_data, &tmp_data);
1721 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1725 /* return the number of items added to the list */
1729 /* Helper for Mask Editing - mask layers */
1730 static size_t animdata_filter_mask_data(ListBase *anim_data, Mask *mask, const int filter_mode)
1732 MaskLayer *masklay_act = BKE_mask_layer_active(mask);
1736 /* loop over layers as the conditions are acceptable */
1737 for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
1738 /* only if selected */
1739 if (ANIMCHANNEL_SELOK(SEL_MASKLAY(masklay)) ) {
1740 /* only if editable */
1741 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_MASK(masklay)) {
1743 if (!(filter_mode & ANIMFILTER_ACTIVE) || (masklay_act == masklay)) {
1745 ANIMCHANNEL_NEW_CHANNEL(masklay, ANIMTYPE_MASKLAYER, mask);
1754 /* Grab all mask data */
1755 static size_t animdata_filter_mask(ListBase *anim_data, void *UNUSED(data), int filter_mode)
1760 /* for now, grab mask datablocks directly from main */
1761 // XXX: this is not good...
1762 for (mask = G.main->mask.first; mask; mask = mask->id.next) {
1763 ListBase tmp_data = {NULL, NULL};
1764 size_t tmp_items = 0;
1766 /* only show if mask is used by something... */
1767 if (ID_REAL_USERS(mask) < 1)
1770 /* add mask animation channels */
1771 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_MASK(mask))
1773 tmp_items += animdata_filter_mask_data(&tmp_data, mask, filter_mode);
1775 END_ANIMFILTER_SUBCHANNELS;
1777 /* did we find anything? */
1779 /* include data-expand widget first */
1780 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1781 /* add gpd as channel too (if for drawing, and it has layers) */
1782 ANIMCHANNEL_NEW_CHANNEL(mask, ANIMTYPE_MASKDATABLOCK, NULL);
1785 /* now add the list of collected channels */
1786 BLI_movelisttolist(anim_data, &tmp_data);
1787 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1792 /* return the number of items added to the list */
1796 /* NOTE: owner_id is scene, material, or texture block, which is the direct owner of the node tree in question */
1797 static size_t animdata_filter_ds_nodetree_group(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1799 ListBase tmp_data = {NULL, NULL};
1800 size_t tmp_items = 0;
1803 /* add nodetree animation channels */
1804 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_NTREE_DATA(ntree))
1806 /* animation data filtering */
1807 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ntree, filter_mode);
1809 END_ANIMFILTER_SUBCHANNELS;
1811 /* did we find anything? */
1813 /* include data-expand widget first */
1814 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1815 /* check if filtering by active status */
1816 if (ANIMCHANNEL_ACTIVEOK(ntree)) {
1817 ANIMCHANNEL_NEW_CHANNEL(ntree, ANIMTYPE_DSNTREE, owner_id);
1821 /* now add the list of collected channels */
1822 BLI_movelisttolist(anim_data, &tmp_data);
1823 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1827 /* return the number of items added to the list */
1831 static size_t animdata_filter_ds_nodetree(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, bNodeTree *ntree, int filter_mode)
1836 items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, ntree, filter_mode);
1838 for (node = ntree->nodes.first; node; node = node->next) {
1839 if (node->type == NODE_GROUP) {
1841 if ((ads->filterflag & ADS_FILTER_ONLYSEL) && (node->flag & NODE_SELECT) == 0) {
1844 items += animdata_filter_ds_nodetree_group(ac, anim_data, ads, owner_id, (bNodeTree *) node->id,
1845 filter_mode | ANIMFILTER_TMP_IGNORE_ONLYSEL);
1853 static size_t animdata_filter_ds_linestyle(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1855 SceneRenderLayer *srl;
1856 FreestyleLineSet *lineset;
1859 for (srl = sce->r.layers.first; srl; srl = srl->next) {
1860 for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
1861 if (lineset->linestyle) {
1862 lineset->linestyle->id.tag |= LIB_TAG_DOIT;
1867 for (srl = sce->r.layers.first; srl; srl = srl->next) {
1868 /* skip render layers without Freestyle enabled */
1869 if (!(srl->layflag & SCE_LAY_FRS))
1872 /* loop over linesets defined in the render layer */
1873 for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
1874 FreestyleLineStyle *linestyle = lineset->linestyle;
1875 ListBase tmp_data = {NULL, NULL};
1876 size_t tmp_items = 0;
1878 if ((linestyle == NULL) ||
1879 !(linestyle->id.tag & LIB_TAG_DOIT))
1883 linestyle->id.tag &= ~LIB_TAG_DOIT;
1885 /* add scene-level animation channels */
1886 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_LS_SCED(linestyle))
1888 /* animation data filtering */
1889 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)linestyle, filter_mode);
1891 END_ANIMFILTER_SUBCHANNELS;
1893 /* did we find anything? */
1895 /* include anim-expand widget first */
1896 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1897 /* check if filtering by active status */
1898 if (ANIMCHANNEL_ACTIVEOK(linestyle)) {
1899 ANIMCHANNEL_NEW_CHANNEL(linestyle, ANIMTYPE_DSLINESTYLE, sce);
1903 /* now add the list of collected channels */
1904 BLI_movelisttolist(anim_data, &tmp_data);
1905 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1911 /* return the number of items added to the list */
1915 static size_t animdata_filter_ds_texture(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads,
1916 Tex *tex, ID *owner_id, int filter_mode)
1918 ListBase tmp_data = {NULL, NULL};
1919 size_t tmp_items = 0;
1922 /* add texture's animation data to temp collection */
1923 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_TEX_DATA(tex))
1925 /* texture animdata */
1926 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)tex, filter_mode);
1929 if ((tex->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
1930 /* owner_id as id instead of texture, since it'll otherwise be impossible to track the depth */
1931 // FIXME: perhaps as a result, textures should NOT be included under materials, but under their own section instead
1932 // so that free-floating textures can also be animated
1933 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)tex, tex->nodetree, filter_mode);
1936 END_ANIMFILTER_SUBCHANNELS;
1938 /* did we find anything? */
1940 /* include texture-expand widget? */
1941 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
1942 /* check if filtering by active status */
1943 if (ANIMCHANNEL_ACTIVEOK(tex)) {
1944 ANIMCHANNEL_NEW_CHANNEL(tex, ANIMTYPE_DSTEX, owner_id);
1948 /* now add the list of collected channels */
1949 BLI_movelisttolist(anim_data, &tmp_data);
1950 BLI_assert(BLI_listbase_is_empty(&tmp_data));
1954 /* return the number of items added to the list */
1958 /* NOTE: owner_id is either material, lamp, or world block, which is the direct owner of the texture stack in question */
1959 static size_t animdata_filter_ds_textures(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
1965 /* get datatype specific data first */
1966 if (owner_id == NULL)
1969 switch (GS(owner_id->name)) {
1972 Material *ma = (Material *)owner_id;
1973 mtex = (MTex **)(&ma->mtex);
1978 Lamp *la = (Lamp *)owner_id;
1979 mtex = (MTex **)(&la->mtex);
1984 World *wo = (World *)owner_id;
1985 mtex = (MTex **)(&wo->mtex);
1990 ParticleSettings *part = (ParticleSettings *)owner_id;
1991 mtex = (MTex **)(&part->mtex);
1996 /* invalid/unsupported option */
1997 if (G.debug & G_DEBUG)
1998 printf("ERROR: Unsupported owner_id (i.e. texture stack) for filter textures - %s\n", owner_id->name);
2003 /* firstly check that we actuallly have some textures, by gathering all textures in a temp list */
2004 for (a = 0; a < MAX_MTEX; a++) {
2005 Tex *tex = (mtex[a]) ? mtex[a]->tex : NULL;
2007 /* for now, if no texture returned, skip (this shouldn't confuse the user I hope) */
2011 /* add texture's anim channels */
2012 items += animdata_filter_ds_texture(ac, anim_data, ads, tex, owner_id, filter_mode);
2015 /* return the number of items added to the list */
2020 static size_t animdata_filter_ds_material(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Material *ma, int filter_mode)
2022 ListBase tmp_data = {NULL, NULL};
2023 size_t tmp_items = 0;
2026 /* add material's animation data to temp collection */
2027 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_MAT_OBJD(ma))
2029 /* material's animation data */
2030 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode);
2033 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2034 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)ma, filter_mode);
2037 if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2038 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode);
2040 END_ANIMFILTER_SUBCHANNELS;
2042 /* did we find anything? */
2044 /* include material-expand widget first */
2045 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2046 /* check if filtering by active status */
2047 if (ANIMCHANNEL_ACTIVEOK(ma)) {
2048 ANIMCHANNEL_NEW_CHANNEL(ma, ANIMTYPE_DSMAT, ma);
2052 /* now add the list of collected channels */
2053 BLI_movelisttolist(anim_data, &tmp_data);
2054 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2061 static size_t animdata_filter_ds_materials(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2063 bool has_nested = false;
2067 /* first pass: take the materials referenced via the Material slots of the object */
2068 for (a = 1; a <= ob->totcol; a++) {
2069 Material *ma = give_current_material(ob, a);
2071 /* if material is valid, try to add relevant contents from here */
2074 items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2076 /* for optimising second pass - check if there's a nested material here to come back for */
2077 if (has_nested == false) {
2078 has_nested = (give_node_material(ma) != NULL);
2083 /* second pass: go through a second time looking for "nested" materials (material.material references)
2085 * NOTE: here we ignore the expanded status of the parent, as it could be too confusing as to why these are
2086 * disappearing/not available, since the relationships between these is not that clear
2089 for (a = 1; a <= ob->totcol; a++) {
2090 Material *base = give_current_material(ob, a);
2091 Material *ma = give_node_material(base);
2093 /* add channels from the nested material if it exists
2094 * - skip if the same material is referenced in its node tree
2095 * (which is common for BI materials) as that results in
2096 * confusing duplicates
2098 if ((ma) && (ma != base)) {
2099 items += animdata_filter_ds_material(ac, anim_data, ads, ma, filter_mode);
2104 /* return the number of items added to the list */
2111 /* Temporary context for modifier linked-data channel extraction */
2112 typedef struct tAnimFilterModifiersContext {
2113 bAnimContext *ac; /* anim editor context */
2114 bDopeSheet *ads; /* dopesheet filtering settings */
2116 ListBase tmp_data; /* list of channels created (but not yet added to the main list) */
2117 size_t items; /* number of channels created */
2119 int filter_mode; /* flags for stuff we want to filter */
2120 } tAnimFilterModifiersContext;
2123 /* dependency walker callback for modifier dependencies */
2124 static void animfilter_modifier_idpoin_cb(void *afm_ptr, Object *ob, ID **idpoin, int UNUSED(cd_flag))
2126 tAnimFilterModifiersContext *afm = (tAnimFilterModifiersContext *)afm_ptr;
2127 ID *owner_id = &ob->id;
2130 /* NOTE: the walker only guarantees to give us all the ID-ptr *slots*,
2131 * not just the ones which are actually used, so be careful!
2136 /* check if this is something we're interested in... */
2137 switch (GS(id->name)) {
2138 case ID_TE: /* Textures */
2140 Tex *tex = (Tex *)id;
2141 if (!(afm->ads->filterflag & ADS_FILTER_NOTEX)) {
2142 afm->items += animdata_filter_ds_texture(afm->ac, &afm->tmp_data, afm->ads, tex, owner_id, afm->filter_mode);
2151 /* animation linked to data used by modifiers
2152 * NOTE: strictly speaking, modifier animation is already included under Object level
2153 * but for some modifiers (e.g. Displace), there can be linked data that has settings
2154 * which would be nice to animate (i.e. texture parameters) but which are not actually
2155 * attached to any other objects/materials/etc. in the scene
2157 // TODO: do we want an expander for this?
2158 static size_t animdata_filter_ds_modifiers(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2160 tAnimFilterModifiersContext afm = {NULL};
2163 /* 1) create a temporary "context" containing all the info we have here to pass to the callback
2164 * use to walk through the dependencies of the modifiers
2166 * ! Assumes that all other unspecified values (i.e. accumulation buffers) are zero'd out properly
2170 afm.filter_mode = filter_mode;
2172 /* 2) walk over dependencies */
2173 modifiers_foreachIDLink(ob, animfilter_modifier_idpoin_cb, &afm);
2175 /* 3) extract data from the context, merging it back into the standard list */
2177 /* now add the list of collected channels */
2178 BLI_movelisttolist(anim_data, &afm.tmp_data);
2179 BLI_assert(BLI_listbase_is_empty(&afm.tmp_data));
2189 static size_t animdata_filter_ds_particles(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2191 ParticleSystem *psys;
2194 for (psys = ob->particlesystem.first; psys; psys = psys->next) {
2195 ListBase tmp_data = {NULL, NULL};
2196 size_t tmp_items = 0;
2198 /* if no material returned, skip - so that we don't get weird blank entries... */
2199 if (ELEM(NULL, psys->part, psys->part->adt))
2202 /* add particle-system's animation data to temp collection */
2203 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_PART_OBJD(psys->part))
2205 /* particle system's animation data */
2206 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2209 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2210 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)psys->part, filter_mode);
2212 END_ANIMFILTER_SUBCHANNELS;
2214 /* did we find anything? */
2216 /* include particle-expand widget first */
2217 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2218 /* check if filtering by active status */
2219 if (ANIMCHANNEL_ACTIVEOK(psys->part)) {
2220 ANIMCHANNEL_NEW_CHANNEL(psys->part, ANIMTYPE_DSPART, psys->part);
2224 /* now add the list of collected channels */
2225 BLI_movelisttolist(anim_data, &tmp_data);
2226 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2231 /* return the number of items added to the list */
2236 static size_t animdata_filter_ds_obdata(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2238 ListBase tmp_data = {NULL, NULL};
2239 size_t tmp_items = 0;
2242 IdAdtTemplate *iat = ob->data;
2243 short type = 0, expanded = 0;
2245 /* get settings based on data type */
2247 case OB_CAMERA: /* ------- Camera ------------ */
2249 Camera *ca = (Camera *)ob->data;
2251 if (ads->filterflag & ADS_FILTER_NOCAM)
2254 type = ANIMTYPE_DSCAM;
2255 expanded = FILTER_CAM_OBJD(ca);
2258 case OB_LAMP: /* ---------- Lamp ----------- */
2260 Lamp *la = (Lamp *)ob->data;
2262 if (ads->filterflag & ADS_FILTER_NOLAM)
2265 type = ANIMTYPE_DSLAM;
2266 expanded = FILTER_LAM_OBJD(la);
2269 case OB_CURVE: /* ------- Curve ---------- */
2270 case OB_SURF: /* ------- Nurbs Surface ---------- */
2271 case OB_FONT: /* ------- Text Curve ---------- */
2273 Curve *cu = (Curve *)ob->data;
2275 if (ads->filterflag & ADS_FILTER_NOCUR)
2278 type = ANIMTYPE_DSCUR;
2279 expanded = FILTER_CUR_OBJD(cu);
2282 case OB_MBALL: /* ------- MetaBall ---------- */
2284 MetaBall *mb = (MetaBall *)ob->data;
2286 if (ads->filterflag & ADS_FILTER_NOMBA)
2289 type = ANIMTYPE_DSMBALL;
2290 expanded = FILTER_MBALL_OBJD(mb);
2293 case OB_ARMATURE: /* ------- Armature ---------- */
2295 bArmature *arm = (bArmature *)ob->data;
2297 if (ads->filterflag & ADS_FILTER_NOARM)
2300 type = ANIMTYPE_DSARM;
2301 expanded = FILTER_ARM_OBJD(arm);
2304 case OB_MESH: /* ------- Mesh ---------- */
2306 Mesh *me = (Mesh *)ob->data;
2308 if (ads->filterflag & ADS_FILTER_NOMESH)
2311 type = ANIMTYPE_DSMESH;
2312 expanded = FILTER_MESH_OBJD(me);
2315 case OB_LATTICE: /* ---- Lattice ---- */
2317 Lattice *lt = (Lattice *)ob->data;
2319 if (ads->filterflag & ADS_FILTER_NOLAT)
2322 type = ANIMTYPE_DSLAT;
2323 expanded = FILTER_LATTICE_OBJD(lt);
2326 case OB_SPEAKER: /* ---------- Speaker ----------- */
2328 Speaker *spk = (Speaker *)ob->data;
2330 type = ANIMTYPE_DSSPK;
2331 expanded = FILTER_SPK_OBJD(spk);
2336 /* add object data animation channels */
2337 BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2339 /* animation data filtering */
2340 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)iat, filter_mode);
2342 /* sub-data filtering... */
2344 case OB_LAMP: /* lamp - textures + nodetree */
2346 Lamp *la = ob->data;
2347 bNodeTree *ntree = la->nodetree;
2350 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2351 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, &la->id, ntree, filter_mode);
2354 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2355 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, &la->id, filter_mode);
2360 END_ANIMFILTER_SUBCHANNELS;
2362 /* did we find anything? */
2364 /* include data-expand widget first */
2365 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2366 /* check if filtering by active status */
2367 if (ANIMCHANNEL_ACTIVEOK(iat)) {
2368 ANIMCHANNEL_NEW_CHANNEL(iat, type, iat);
2372 /* now add the list of collected channels */
2373 BLI_movelisttolist(anim_data, &tmp_data);
2374 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2378 /* return the number of items added to the list */
2382 /* shapekey-level animation */
2383 static size_t animdata_filter_ds_keyanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, Key *key, int filter_mode)
2385 ListBase tmp_data = {NULL, NULL};
2386 size_t tmp_items = 0;
2389 /* add shapekey-level animation channels */
2390 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_SKE_OBJD(key))
2392 /* animation data filtering */
2393 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)key, filter_mode);
2395 END_ANIMFILTER_SUBCHANNELS;
2397 /* did we find anything? */
2399 /* include key-expand widget first */
2400 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2401 if (ANIMCHANNEL_ACTIVEOK(key)) {
2402 ANIMCHANNEL_NEW_CHANNEL(key, ANIMTYPE_DSSKEY, ob);
2406 /* now add the list of collected channels */
2407 BLI_movelisttolist(anim_data, &tmp_data);
2408 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2412 /* return the number of items added to the list */
2417 /* object-level animation */
2418 static size_t animdata_filter_ds_obanim(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Object *ob, int filter_mode)
2420 ListBase tmp_data = {NULL, NULL};
2421 size_t tmp_items = 0;
2424 AnimData *adt = ob->adt;
2425 short type = 0, expanded = 1;
2428 /* determine the type of expander channels to use */
2429 /* this is the best way to do this for now... */
2430 ANIMDATA_FILTER_CASES(ob,
2431 { /* AnimData - no channel, but consider data */ },
2432 { /* NLA - no channel, but consider data */ },
2434 type = ANIMTYPE_FILLDRIVERS;
2436 expanded = EXPANDED_DRVD(adt);
2438 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2440 type = ANIMTYPE_FILLACTD;
2441 cdata = adt->action;
2442 expanded = EXPANDED_ACTC(adt->action);
2445 /* add object-level animation channels */
2446 BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2448 /* animation data filtering */
2449 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ob, filter_mode);
2451 END_ANIMFILTER_SUBCHANNELS;
2453 /* did we find anything? */
2455 /* include anim-expand widget first */
2456 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2457 if (type != ANIMTYPE_NONE) {
2458 /* NOTE: active-status (and the associated checks) don't apply here... */
2459 ANIMCHANNEL_NEW_CHANNEL(cdata, type, ob);
2463 /* now add the list of collected channels */
2464 BLI_movelisttolist(anim_data, &tmp_data);
2465 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2469 /* return the number of items added to the list */
2473 /* get animation channels from object2 */
2474 static size_t animdata_filter_dopesheet_ob(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
2476 ListBase tmp_data = {NULL, NULL};
2477 Object *ob = base->object;
2478 size_t tmp_items = 0;
2481 /* filter data contained under object first */
2482 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_OBJC(ob))
2484 Key *key = BKE_key_from_object(ob);
2486 /* object-level animation */
2487 if ((ob->adt) && !(ads->filterflag & ADS_FILTER_NOOBJ)) {
2488 tmp_items += animdata_filter_ds_obanim(ac, &tmp_data, ads, ob, filter_mode);
2492 if ((key && key->adt) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
2493 tmp_items += animdata_filter_ds_keyanim(ac, &tmp_data, ads, ob, key, filter_mode);
2497 if ((ob->modifiers.first) && !(ads->filterflag & ADS_FILTER_NOMODIFIERS)) {
2498 tmp_items += animdata_filter_ds_modifiers(ac, &tmp_data, ads, ob, filter_mode);
2502 if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT)) {
2503 tmp_items += animdata_filter_ds_materials(ac, &tmp_data, ads, ob, filter_mode);
2508 tmp_items += animdata_filter_ds_obdata(ac, &tmp_data, ads, ob, filter_mode);
2512 if ((ob->particlesystem.first) && !(ads->filterflag & ADS_FILTER_NOPART)) {
2513 tmp_items += animdata_filter_ds_particles(ac, &tmp_data, ads, ob, filter_mode);
2517 if ((ob->gpd) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
2518 tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, ob->gpd, filter_mode);
2521 END_ANIMFILTER_SUBCHANNELS;
2524 /* if we collected some channels, add these to the new list... */
2526 /* firstly add object expander if required */
2527 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2528 /* check if filtering by selection */
2529 // XXX: double-check on this - most of the time, a lot of tools need to filter out these channels!
2530 if (ANIMCHANNEL_SELOK((base->flag & SELECT))) {
2531 /* check if filtering by active status */
2532 if (ANIMCHANNEL_ACTIVEOK(ob)) {
2533 ANIMCHANNEL_NEW_CHANNEL(base, ANIMTYPE_OBJECT, ob);
2538 /* now add the list of collected channels */
2539 BLI_movelisttolist(anim_data, &tmp_data);
2540 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2544 /* return the number of items added */
2548 static size_t animdata_filter_ds_world(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, World *wo, int filter_mode)
2550 ListBase tmp_data = {NULL, NULL};
2551 size_t tmp_items = 0;
2554 /* add world animation channels */
2555 BEGIN_ANIMFILTER_SUBCHANNELS(FILTER_WOR_SCED(wo))
2557 /* animation data filtering */
2558 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode);
2560 /* textures for world */
2561 if (!(ads->filterflag & ADS_FILTER_NOTEX))
2562 tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)wo, filter_mode);
2565 if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
2566 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)wo, wo->nodetree, filter_mode);
2568 END_ANIMFILTER_SUBCHANNELS;
2570 /* did we find anything? */
2572 /* include data-expand widget first */
2573 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2574 /* check if filtering by active status */
2575 if (ANIMCHANNEL_ACTIVEOK(wo)) {
2576 ANIMCHANNEL_NEW_CHANNEL(wo, ANIMTYPE_DSWOR, sce);
2580 /* now add the list of collected channels */
2581 BLI_movelisttolist(anim_data, &tmp_data);
2582 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2586 /* return the number of items added to the list */
2590 static size_t animdata_filter_ds_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2592 ListBase tmp_data = {NULL, NULL};
2593 size_t tmp_items = 0;
2596 AnimData *adt = sce->adt;
2597 short type = 0, expanded = 1;
2600 /* determine the type of expander channels to use */
2601 // this is the best way to do this for now...
2602 ANIMDATA_FILTER_CASES(sce,
2603 { /* AnimData - no channel, but consider data */},
2604 { /* NLA - no channel, but consider data */},
2606 type = ANIMTYPE_FILLDRIVERS;
2608 expanded = EXPANDED_DRVD(adt);
2610 { /* NLA Strip Controls - no dedicated channel for now (XXX) */ },
2612 type = ANIMTYPE_FILLACTD;
2613 cdata = adt->action;
2614 expanded = EXPANDED_ACTC(adt->action);
2617 /* add scene-level animation channels */
2618 BEGIN_ANIMFILTER_SUBCHANNELS(expanded)
2620 /* animation data filtering */
2621 tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)sce, filter_mode);
2623 END_ANIMFILTER_SUBCHANNELS;
2625 /* did we find anything? */
2627 /* include anim-expand widget first */
2628 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2629 if (type != ANIMTYPE_NONE) {
2630 /* NOTE: active-status (and the associated checks) don't apply here... */
2631 ANIMCHANNEL_NEW_CHANNEL(cdata, type, sce);
2635 /* now add the list of collected channels */
2636 BLI_movelisttolist(anim_data, &tmp_data);
2637 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2641 /* return the number of items added to the list */
2645 static size_t animdata_filter_dopesheet_scene(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
2647 ListBase tmp_data = {NULL, NULL};
2648 size_t tmp_items = 0;
2651 /* filter data contained under object first */
2652 BEGIN_ANIMFILTER_SUBCHANNELS(EXPANDED_SCEC(sce))
2654 bNodeTree *ntree = sce->nodetree;
2655 bGPdata *gpd = sce->gpd;
2656 World *wo = sce->world;
2658 /* Action, Drivers, or NLA for Scene */
2659 if ((ads->filterflag & ADS_FILTER_NOSCE) == 0) {
2660 tmp_items += animdata_filter_ds_scene(ac, &tmp_data, ads, sce, filter_mode);
2664 if ((wo) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
2665 tmp_items += animdata_filter_ds_world(ac, &tmp_data, ads, sce, wo, filter_mode);
2669 if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE)) {
2670 tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)sce, ntree, filter_mode);
2674 if ((ads->filterflag & ADS_FILTER_NOLINESTYLE) == 0) {
2675 tmp_items += animdata_filter_ds_linestyle(ac, &tmp_data, ads, sce, filter_mode);
2679 if ((gpd) && !(ads->filterflag & ADS_FILTER_NOGPENCIL)) {
2680 tmp_items += animdata_filter_ds_gpencil(ac, &tmp_data, ads, gpd, filter_mode);
2683 /* TODO: one day, when sequencer becomes its own datatype, perhaps it should be included here */
2685 END_ANIMFILTER_SUBCHANNELS;
2687 /* if we collected some channels, add these to the new list... */
2689 /* firstly add object expander if required */
2690 if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
2691 /* check if filtering by selection */
2692 if (ANIMCHANNEL_SELOK((sce->flag & SCE_DS_SELECTED))) {
2693 /* NOTE: active-status doesn't matter for this! */
2694 ANIMCHANNEL_NEW_CHANNEL(sce, ANIMTYPE_SCENE, sce);
2698 /* now add the list of collected channels */
2699 BLI_movelisttolist(anim_data, &tmp_data);
2700 BLI_assert(BLI_listbase_is_empty(&tmp_data));
2704 /* return the number of items added */
2708 // TODO: implement pinning... (if and when pinning is done, what we need to do is to provide freeing mechanisms - to protect against data that was deleted)
2709 static size_t animdata_filter_dopesheet(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, int filter_mode)
2711 Scene *sce = (Scene *)ads->source;
2715 /* check that we do indeed have a scene */
2716 if ((ads->source == NULL) || (GS(ads->source->name) != ID_SCE)) {
2717 printf("Dope Sheet Error: No scene!\n");
2718 if (G.debug & G_DEBUG)
2719 printf("\tPointer = %p, Name = '%s'\n", (void *)ads->source, (ads->source) ? ads->source->name : NULL);
2723 /* augment the filter-flags with settings based on the dopesheet filterflags
2724 * so that some temp settings can get added automagically...
2726 if (ads->filterflag & ADS_FILTER_SELEDIT) {
2727 /* only selected F-Curves should get their keyframes considered for editability */
2728 filter_mode |= ANIMFILTER_SELEDIT;
2731 /* scene-linked animation - e.g. world, compositing nodes, scene anim (including sequencer currently) */
2732 items += animdata_filter_dopesheet_scene(ac, anim_data, ads, sce, filter_mode);
2734 /* loop over all bases (i.e.objects) in the scene */
2735 for (base = sce->base.first; base; base = base->next) {
2736 /* check if there's an object (all the relevant checks are done in the ob-function) */
2738 Object *ob = base->object;
2740 /* firstly, check if object can be included, by the following factors:
2741 * - if only visible, must check for layer and also viewport visibility
2742 * --> while tools may demand only visible, user setting takes priority
2743 * as user option controls whether sets of channels get included while
2744 * tool-flag takes into account collapsed/open channels too
2745 * - if only selected, must check if object is selected
2746 * - there must be animation data to edit (this is done recursively as we
2747 * try to add the channels)
2749 if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
2750 /* layer visibility - we check both object and base, since these may not be in sync yet */
2751 if ((sce->lay & (ob->lay | base->lay)) == 0) continue;
2753 /* outliner restrict-flag */
2754 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
2757 /* if only F-Curves with visible flags set can be shown, check that
2758 * datablock hasn't been set to invisible
2760 if (filter_mode & ANIMFILTER_CURVE_VISIBLE) {
2761 if ((ob->adt) && (ob->adt->flag & ADT_CURVES_NOT_VISIBLE))
2765 /* check selection and object type filters */
2766 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) /*|| (base == sce->basact)*/) ) {
2767 /* only selected should be shown */
2771 /* check if object belongs to the filtering group if option to filter
2772 * objects by the grouped status is on
2773 * - used to ease the process of doing multiple-character choreographies
2775 if (ads->filterflag & ADS_FILTER_ONLYOBGROUP) {
2776 if (BKE_group_object_exists(ads->filter_grp, ob) == 0)
2780 /* since we're still here, this object should be usable */
2781 items += animdata_filter_dopesheet_ob(ac, anim_data, ads, base, filter_mode);
2785 /* return the number of items in the list */
2789 /* Summary track for DopeSheet/Action Editor
2790 * - return code is whether the summary lets the other channels get drawn