4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2008 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Joshua Leung
26 * ***** END GPL LICENSE BLOCK *****
29 /* This file contains a system used to provide a layer of abstraction between sources
30 * of animation data and tools in Animation Editors. The method used here involves
31 * generating a list of edit structures which enable tools to naively perform the actions
32 * they require without all the boiler-plate associated with loops within loops and checking
33 * for cases to ignore.
35 * While this is primarily used for the Action/Dopesheet Editor (and its accessory modes),
36 * the IPO Editor also uses this for it's channel list and for determining which curves
39 * Note: much of the original system this was based on was built before the creation of the RNA
40 * system. In future, it would be interesting to replace some parts of this code with RNA queries,
41 * however, RNA does not eliminate some of the boiler-plate reduction benefits presented by this
42 * system, so if any such work does occur, it should only be used for the internals used here...
44 * -- Joshua Leung, Dec 2008
50 #include "DNA_listBase.h"
52 #include "DNA_anim_types.h"
53 #include "DNA_action_types.h"
54 #include "DNA_constraint_types.h"
55 #include "DNA_camera_types.h"
56 #include "DNA_curve_types.h"
57 #include "DNA_gpencil_types.h"
58 #include "DNA_ipo_types.h"
59 #include "DNA_lamp_types.h"
60 #include "DNA_lattice_types.h"
61 #include "DNA_key_types.h"
62 #include "DNA_material_types.h"
63 #include "DNA_mesh_types.h"
64 #include "DNA_object_types.h"
65 #include "DNA_space_types.h"
66 #include "DNA_scene_types.h"
67 #include "DNA_screen_types.h"
68 #include "DNA_windowmanager_types.h"
69 #include "DNA_world_types.h"
71 #include "MEM_guardedalloc.h"
73 #include "BLI_blenlib.h"
75 #include "BKE_context.h"
76 #include "BKE_global.h"
78 #include "BKE_object.h"
79 #include "BKE_material.h"
80 #include "BKE_screen.h"
81 #include "BKE_utildefines.h"
83 #include "ED_anim_api.h"
91 #include "BIF_glutil.h"
93 #include "UI_interface.h"
94 #include "UI_resources.h"
95 #include "UI_view2d.h"
97 /* ************************************************************ */
98 /* Blender Context <-> Animation Context mapping */
100 /* ----------- Private Stuff - Action Editor ------------- */
102 /* Get shapekey data being edited (for Action Editor -> ShapeKey mode) */
103 /* Note: there's a similar function in key.c (ob_get_key) */
104 Key *actedit_get_shapekeys (bAnimContext *ac, SpaceAction *saction)
106 Scene *scene= ac->scene;
114 /* XXX pinning is not available in 'ShapeKey' mode... */
115 //if (saction->pin) return NULL;
117 /* shapekey data is stored with geometry data */
120 key= ((Mesh *)ob->data)->key;
124 key= ((Lattice *)ob->data)->key;
129 key= ((Curve *)ob->data)->key;
137 if (key->type == KEY_RELATIVE)
144 /* Get data being edited in Action Editor (depending on current 'mode') */
145 static short actedit_get_context (bAnimContext *ac, SpaceAction *saction)
147 /* sync settings with current view status, then return appropriate data */
148 switch (saction->mode) {
149 case SACTCONT_ACTION: /* 'Action Editor' */
150 /* if not pinned, sync with active object */
151 if (saction->pin == 0) {
152 if (ac->obact && ac->obact->adt)
153 saction->action = ac->obact->adt->action;
155 saction->action= NULL;
158 ac->datatype= ANIMCONT_ACTION;
159 ac->data= saction->action;
161 ac->mode= saction->mode;
164 case SACTCONT_SHAPEKEY: /* 'ShapeKey Editor' */
165 ac->datatype= ANIMCONT_SHAPEKEY;
166 ac->data= actedit_get_shapekeys(ac, saction);
168 ac->mode= saction->mode;
171 case SACTCONT_GPENCIL: /* Grease Pencil */ // XXX review how this mode is handled...
172 ac->datatype=ANIMCONT_GPENCIL;
173 //ac->data= CTX_wm_screen(C); // FIXME: add that dopesheet type thing here!
174 ac->data= NULL; // !!!
176 ac->mode= saction->mode;
179 case SACTCONT_DOPESHEET: /* DopeSheet */
180 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
181 saction->ads.source= (ID *)ac->scene;
183 ac->datatype= ANIMCONT_DOPESHEET;
184 ac->data= &saction->ads;
186 ac->mode= saction->mode;
189 default: /* unhandled yet */
190 ac->datatype= ANIMCONT_NONE;
198 /* ----------- Private Stuff - IPO Editor ------------- */
200 /* Get data being edited in Graph Editor (depending on current 'mode') */
201 static short graphedit_get_context (bAnimContext *ac, SpaceIpo *sipo)
203 /* init dopesheet data if non-existant (i.e. for old files) */
204 if (sipo->ads == NULL)
205 sipo->ads= MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet");
207 /* sync settings with current view status, then return appropriate data */
208 switch (sipo->mode) {
209 case SIPO_MODE_ANIMATION: /* Animation F-Curve Editor */
210 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
211 sipo->ads->source= (ID *)ac->scene;
212 sipo->ads->filterflag &= ~ADS_FILTER_ONLYDRIVERS;
214 ac->datatype= ANIMCONT_FCURVES;
217 ac->mode= sipo->mode;
220 case SIPO_MODE_DRIVERS: /* Driver F-Curve Editor */
221 /* update scene-pointer (no need to check for pinning yet, as not implemented) */
222 sipo->ads->source= (ID *)ac->scene;
223 sipo->ads->filterflag |= ADS_FILTER_ONLYDRIVERS;
225 ac->datatype= ANIMCONT_DRIVERS;
228 ac->mode= sipo->mode;
231 default: /* unhandled yet */
232 ac->datatype= ANIMCONT_NONE;
240 /* ----------- Public API --------------- */
242 /* Obtain current anim-data context, given that context info from Blender context has already been set
243 * - AnimContext to write to is provided as pointer to var on stack so that we don't have
244 * allocation/freeing costs (which are not that avoidable with channels).
246 short ANIM_animdata_context_getdata (bAnimContext *ac)
251 /* context depends on editor we are currently in */
253 switch (sa->spacetype) {
256 SpaceAction *saction= (SpaceAction *)sa->spacedata.first;
257 ok= actedit_get_context(ac, saction);
263 SpaceIpo *sipo= (SpaceIpo *)sa->spacedata.first;
264 ok= graphedit_get_context(ac, sipo);
270 /* check if there's any valid data */
277 /* Obtain current anim-data context from Blender Context info
278 * - AnimContext to write to is provided as pointer to var on stack so that we don't have
279 * allocation/freeing costs (which are not that avoidable with channels).
280 * - Clears data and sets the information from Blender Context which is useful
282 short ANIM_animdata_get_context (const bContext *C, bAnimContext *ac)
284 ScrArea *sa= CTX_wm_area(C);
285 ARegion *ar= CTX_wm_region(C);
286 Scene *scene= CTX_data_scene(C);
288 /* clear old context info */
289 if (ac == NULL) return 0;
290 memset(ac, 0, sizeof(bAnimContext));
292 /* get useful default context settings from context */
294 ac->obact= (scene && scene->basact)? scene->basact->object : NULL;
297 ac->spacetype= (sa) ? sa->spacetype : 0;
298 ac->regiontype= (ar) ? ar->regiontype : 0;
300 /* get data context info */
301 return ANIM_animdata_context_getdata(ac);
304 /* ************************************************************ */
305 /* Blender Data <-- Filter --> Channels to be operated on */
307 /* quick macro to test if AnimData is usable */
308 #define ANIMDATA_HAS_KEYS(id) ((id)->adt && (id)->adt->action)
310 /* quick macro to test if AnimData is usable for drivers */
311 #define ANIMDATA_HAS_DRIVERS(id) ((id)->adt && (id)->adt->drivers.first)
313 /* quick macro to test if a anim-channel (F-Curve, Group, etc.) is selected in an acceptable way */
314 #define ANIMCHANNEL_SELOK(test_func) \
315 ( !(filter_mode & (ANIMFILTER_SEL|ANIMFILTER_UNSEL)) || \
316 ((filter_mode & ANIMFILTER_SEL) && test_func) || \
317 ((filter_mode & ANIMFILTER_UNSEL) && test_func==0) )
319 /* ----------- 'Private' Stuff --------------- */
321 /* this function allocates memory for a new bAnimListElem struct for the
322 * provided animation channel-data.
324 bAnimListElem *make_new_animlistelem (void *data, short datatype, void *owner, short ownertype, ID *owner_id)
326 bAnimListElem *ale= NULL;
328 /* only allocate memory if there is data to convert */
330 /* allocate and set generic data */
331 ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
335 // XXX what is the point of the owner data?
337 ale->ownertype= ownertype;
345 Scene *sce= (Scene *)data;
347 ale->flag= sce->flag;
350 ale->datatype= ALE_SCE;
353 case ANIMTYPE_OBJECT:
355 Base *base= (Base *)data;
356 Object *ob= base->object;
361 ale->datatype= ALE_OB;
364 case ANIMTYPE_FILLACTD:
366 bAction *act= (bAction *)data;
368 ale->flag= act->flag;
371 ale->datatype= ALE_ACT;
374 case ANIMTYPE_FILLDRIVERS:
376 AnimData *adt= (AnimData *)data;
378 ale->flag= adt->flag;
380 // XXX... drivers don't show summary for now
382 ale->datatype= ALE_NONE;
385 case ANIMTYPE_FILLMATD:
387 Object *ob= (Object *)data;
389 ale->flag= FILTER_MAT_OBJC(ob);
392 ale->datatype= ALE_NONE;
398 Material *ma= (Material *)data;
399 AnimData *adt= ma->adt;
401 ale->flag= FILTER_MAT_OBJD(ma);
403 ale->key_data= (adt) ? adt->action : NULL;
404 ale->datatype= ALE_ACT;
409 Lamp *la= (Lamp *)data;
410 AnimData *adt= la->adt;
412 ale->flag= FILTER_LAM_OBJD(la);
414 ale->key_data= (adt) ? adt->action : NULL;
415 ale->datatype= ALE_ACT;
420 Camera *ca= (Camera *)data;
421 AnimData *adt= ca->adt;
423 ale->flag= FILTER_CAM_OBJD(ca);
425 ale->key_data= (adt) ? adt->action : NULL;
426 ale->datatype= ALE_ACT;
431 Curve *cu= (Curve *)data;
432 AnimData *adt= cu->adt;
434 ale->flag= FILTER_CUR_OBJD(cu);
436 ale->key_data= (adt) ? adt->action : NULL;
437 ale->datatype= ALE_ACT;
440 case ANIMTYPE_DSSKEY:
442 Key *key= (Key *)data;
443 AnimData *adt= key->adt;
445 ale->flag= FILTER_SKE_OBJD(key);
447 ale->key_data= (adt) ? adt->action : NULL;
448 ale->datatype= ALE_ACT;
453 World *wo= (World *)data;
454 AnimData *adt= wo->adt;
456 ale->flag= FILTER_WOR_SCED(wo);
458 ale->key_data= (adt) ? adt->action : NULL;
459 ale->datatype= ALE_ACT;
465 bActionGroup *agrp= (bActionGroup *)data;
467 ale->flag= agrp->flag;
470 ale->datatype= ALE_GROUP;
473 case ANIMTYPE_FCURVE:
475 FCurve *fcu= (FCurve *)data;
477 ale->flag= fcu->flag;
480 ale->datatype= ALE_FCURVE;
484 case ANIMTYPE_GPLAYER:
486 bGPDlayer *gpl= (bGPDlayer *)data;
488 ale->flag= gpl->flag;
491 ale->datatype= ALE_GPFRAME;
497 /* return created datatype */
501 /* ----------------------------------------- */
504 static int animdata_filter_fcurves (ListBase *anim_data, FCurve *first, bActionGroup *grp, void *owner, short ownertype, int filter_mode, ID *owner_id)
506 bAnimListElem *ale = NULL;
510 /* loop over F-Curves - assume that the caller of this has already checked that these should be included
511 * NOTE: we need to check if the F-Curves belong to the same group, as this gets called for groups too...
513 for (fcu= first; ((fcu) && (fcu->grp==grp)); fcu= fcu->next) {
514 /* only include if visible (Graph Editor check, not channels check) */
515 if (!(filter_mode & ANIMFILTER_CURVEVISIBLE) || (fcu->flag & FCURVE_VISIBLE)) {
516 /* only work with this channel and its subchannels if it is editable */
517 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_FCU(fcu)) {
518 /* only include this curve if selected in a way consistent with the filtering requirements */
519 if ( ANIMCHANNEL_SELOK(SEL_FCU(fcu)) ) {
520 /* only include if this curve is active */
521 if (!(filter_mode & ANIMFILTER_ACTIVE) || (fcu->flag & FCURVE_ACTIVE)) {
522 /* owner/ownertype will be either object or action-channel, depending if it was dopesheet or part of an action */
523 ale= make_new_animlistelem(fcu, ANIMTYPE_FCURVE, owner, ownertype, owner_id);
526 BLI_addtail(anim_data, ale);
535 /* return the number of items added to the list */
539 static int animdata_filter_action (ListBase *anim_data, bAction *act, int filter_mode, void *owner, short ownertype, ID *owner_id)
541 bAnimListElem *ale=NULL;
543 FCurve *lastchan=NULL;
546 /* loop over groups */
547 // XXX in future, we need to be prepared for nestled groups...
548 for (agrp= act->groups.first; agrp; agrp= agrp->next) {
549 /* add this group as a channel first */
550 if ((filter_mode & ANIMFILTER_CHANNELS) || !(filter_mode & ANIMFILTER_CURVESONLY)) {
551 /* check if filtering by selection */
552 if ( ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) ) {
553 ale= make_new_animlistelem(agrp, ANIMTYPE_GROUP, NULL, ANIMTYPE_NONE, owner_id);
555 BLI_addtail(anim_data, ale);
561 /* store reference to last channel of group */
562 if (agrp->channels.last)
563 lastchan= agrp->channels.last;
566 /* there are some situations, where only the channels of the action group should get considered */
567 if (!(filter_mode & ANIMFILTER_ACTGROUPED) || (agrp->flag & AGRP_ACTIVE)) {
568 /* filters here are a bit convoulted...
569 * - groups show a "summary" of keyframes beside their name which must accessable for tools which handle keyframes
570 * - groups can be collapsed (and those tools which are only interested in channels rely on knowing that group is closed)
572 * cases when we should include F-Curves inside group:
573 * - we don't care about visibility
574 * - group is expanded
575 * - we're interested in keyframes, but not if they appear in selected channels
577 // XXX what was the selection check here for again?
578 if ( (!(filter_mode & ANIMFILTER_VISIBLE) || EXPANDED_AGRP(agrp)) ||
579 ( /*ANIMCHANNEL_SELOK(SEL_AGRP(agrp)) &&*/ (filter_mode & ANIMFILTER_CURVESONLY) ) )
581 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_AGRP(agrp)) {
582 // XXX the 'owner' info here needs review...
583 items += animdata_filter_fcurves(anim_data, agrp->channels.first, agrp, owner, ownertype, filter_mode, owner_id);
585 /* remove group from filtered list if last element is group
586 * (i.e. only if group had channels, which were all hidden)
588 // XXX this is really hacky... it should be fixed in a much more elegant way!
589 if ( (ale) && (anim_data->last == ale) &&
590 (ale->data == agrp) && (agrp->channels.first) )
592 BLI_freelinkN(anim_data, ale);
600 /* loop over un-grouped F-Curves (only if we're not only considering those channels in the animive group) */
601 if (!(filter_mode & ANIMFILTER_ACTGROUPED)) {
602 // XXX the 'owner' info here needs review...
603 items += animdata_filter_fcurves(anim_data, (lastchan)?(lastchan->next):(act->curves.first), NULL, owner, ownertype, filter_mode, owner_id);
606 /* return the number of items added to the list */
610 static int animdata_filter_shapekey (ListBase *anim_data, Key *key, int filter_mode, void *owner, short ownertype, ID *owner_id)
617 /* are we filtering for display or editing */
618 if (filter_mode & ANIMFILTER_CHANNELS) {
619 /* for display - loop over shapekeys, adding ipo-curve references where needed */
620 kb= key->block.first;
622 /* loop through possible shapekeys, manually creating entries */
623 for (i= 1; i < key->totkey; i++) {
624 ale= MEM_callocN(sizeof(bAnimListElem), "bAnimListElem");
625 kb = kb->next; /* do this even on the first try, as the first is 'Basis' (which doesn't get included) */
628 ale->type= ANIMTYPE_SHAPEKEY; /* 'abused' usage of this type */
630 ale->ownertype= ANIMTYPE_SHAPEKEY;
631 ale->datatype= ALE_NONE;
634 #if 0 // XXX fixme... old system
636 for (icu= key->ipo->curve.first; icu; icu=icu->next) {
637 if (icu->adrcode == i) {
639 ale->datatype= ALE_ICU;
644 #endif // XXX fixme... old system
648 BLI_addtail(anim_data, ale);
653 #if 0 // XXX fixme... old system
654 /* loop over ipo curves if present - for editing */
656 if (filter_mode & ANIMFILTER_IPOKEYS) {
657 ale= make_new_animlistelem(key->ipo, ANIMTYPE_IPO, key, ANIMTYPE_SHAPEKEY);
659 if (owned) ale->id= owner;
660 BLI_addtail(anim_data, ale);
665 items += animdata_filter_ipocurves(anim_data, key->ipo, filter_mode, key, ANIMTYPE_SHAPEKEY, (owned)?(owner):(NULL));
668 #endif // XXX fixme... old system
671 /* return the number of items added to the list */
676 // FIXME: switch this to use the bDopeSheet...
677 static int animdata_filter_gpencil (ListBase *anim_data, bScreen *sc, int filter_mode)
680 ScrArea *sa, *curarea;
685 /* check if filtering types are appropriate */
687 /* special hack for fullscreen area (which must be this one then):
688 * - we use the curarea->full as screen to get spaces from, since the
689 * old (pre-fullscreen) screen was stored there...
690 * - this is needed as all data would otherwise disappear
692 // XXX need to get new alternative for curarea
693 if ((curarea->full) && (curarea->spacetype==SPACE_ACTION))
696 /* loop over spaces in current screen, finding gpd blocks (could be slow!) */
697 for (sa= sc->areabase.first; sa; sa= sa->next) {
698 /* try to get gp data */
699 // XXX need to put back grease pencil api...
700 gpd= gpencil_data_getactive(sa);
701 if (gpd == NULL) continue;
703 /* add gpd as channel too (if for drawing, and it has layers) */
704 if ((filter_mode & ANIMFILTER_CHANNELS) && (gpd->layers.first)) {
706 ale= make_new_animlistelem(gpd, ANIMTYPE_GPDATABLOCK, sa, ANIMTYPE_SPECIALDATA);
708 BLI_addtail(anim_data, ale);
713 /* only add layers if they will be visible (if drawing channels) */
714 if ( !(filter_mode & ANIMFILTER_VISIBLE) || (EXPANDED_GPD(gpd)) ) {
715 /* loop over layers as the conditions are acceptable */
716 for (gpl= gpd->layers.first; gpl; gpl= gpl->next) {
717 /* only if selected */
718 if ( ANIMCHANNEL_SELOK(SEL_GPL(gpl)) ) {
719 /* only if editable */
720 if (!(filter_mode & ANIMFILTER_FOREDIT) || EDITABLE_GPL(gpl)) {
722 ale= make_new_animlistelem(gpl, ANIMTYPE_GPLAYER, gpd, ANIMTYPE_GPDATABLOCK);
724 BLI_addtail(anim_data, ale);
734 /* return the number of items added to the list */
740 static int animdata_filter_dopesheet_mats (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
742 ListBase mats = {NULL, NULL};
745 bAnimListElem *ale=NULL;
746 Object *ob= base->object;
749 /* firstly check that we actuallly have some materials, by gathering all materials in a temp list */
750 for (a=0; a < ob->totcol; a++) {
751 Material *ma= give_current_material(ob, a);
753 /* for now, if no material returned, skip (this shouldn't confuse the user I hope) */
754 if (ELEM3(NULL, ma, ma->adt, ma->adt->action)) continue;
756 /* make a temp list elem for this */
757 ld= MEM_callocN(sizeof(LinkData), "DopeSheet-MaterialCache");
759 BLI_addtail(&mats, ld);
762 /* if there were no channels found, no need to carry on */
763 if (mats.first == NULL)
766 /* include materials-expand widget? */
767 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
768 ale= make_new_animlistelem(ob, ANIMTYPE_FILLMATD, base, ANIMTYPE_OBJECT, (ID *)ob);
770 BLI_addtail(anim_data, ale);
776 if (FILTER_MAT_OBJC(ob) || (filter_mode & ANIMFILTER_CURVESONLY)) {
777 /* for each material in cache, add channels */
778 for (ld= mats.first; ld; ld= ld->next) {
779 Material *ma= (Material *)ld->data;
781 /* include material-expand widget? */
782 // hmm... do we need to store the index of this material in the array anywhere?
783 if (filter_mode & ANIMFILTER_CHANNELS) {
784 ale= make_new_animlistelem(ma, ANIMTYPE_DSMAT, base, ANIMTYPE_OBJECT, (ID *)ma);
786 BLI_addtail(anim_data, ale);
791 /* add material's F-Curve channels? */
792 if (FILTER_MAT_OBJD(ma) || (filter_mode & ANIMFILTER_CURVESONLY)) {
793 // XXX the 'owner' info here is still subject to improvement
794 items += animdata_filter_action(anim_data, ma->adt->action, filter_mode, ma, ANIMTYPE_DSMAT, (ID *)ma);
800 BLI_freelistN(&mats);
802 /* return the number of items added to the list */
806 static int animdata_filter_dopesheet_obdata (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
808 bAnimListElem *ale=NULL;
809 Object *ob= base->object;
810 IdAdtTemplate *iat= ob->data;
811 AnimData *adt= iat->adt;
812 short type=0, expanded=0;
815 /* get settings based on data type */
817 case OB_CAMERA: /* ------- Camera ------------ */
819 Camera *ca= (Camera *)ob->data;
821 type= ANIMTYPE_DSCAM;
822 expanded= FILTER_CAM_OBJD(ca);
825 case OB_LAMP: /* ---------- Lamp ----------- */
827 Lamp *la= (Lamp *)ob->data;
829 type= ANIMTYPE_DSLAM;
830 expanded= FILTER_LAM_OBJD(la);
833 case OB_CURVE: /* ------- Curve ---------- */
835 Curve *cu= (Curve *)ob->data;
837 type= ANIMTYPE_DSCUR;
838 expanded= FILTER_CUR_OBJD(cu);
843 /* special exception for drivers instead of action */
844 if (ads->filterflag & ADS_FILTER_ONLYDRIVERS)
845 expanded= EXPANDED_DRVD(adt);
847 /* include data-expand widget? */
848 if ((filter_mode & ANIMFILTER_CURVESONLY) == 0) {
849 ale= make_new_animlistelem(iat, type, base, ANIMTYPE_OBJECT, (ID *)iat);
850 if (ale) BLI_addtail(anim_data, ale);
853 /* add object-data animation channels? */
854 if ((expanded) || (filter_mode & ANIMFILTER_CURVESONLY)) {
855 /* Action or Drivers? */
856 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
857 // XXX the 'owner' info here is still subject to improvement
858 items += animdata_filter_action(anim_data, iat->adt->action, filter_mode, iat, type, (ID *)iat);
861 // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
862 items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, iat, type, filter_mode, (ID *)iat);
866 /* return the number of items added to the list */
870 static int animdata_filter_dopesheet_ob (ListBase *anim_data, bDopeSheet *ads, Base *base, int filter_mode)
872 bAnimListElem *ale=NULL;
873 Object *ob= base->object;
874 Key *key= ob_get_key(ob);
877 /* add this object as a channel first */
878 if ((filter_mode & ANIMFILTER_CURVESONLY) == 0) {
879 /* check if filtering by selection */
880 if ANIMCHANNEL_SELOK((base->flag & SELECT)) {
881 ale= make_new_animlistelem(base, ANIMTYPE_OBJECT, NULL, ANIMTYPE_NONE, NULL);
883 BLI_addtail(anim_data, ale);
889 /* if collapsed, don't go any further (unless adding keyframes only) */
890 if ( (EXPANDED_OBJC(ob) == 0) && !(filter_mode & ANIMFILTER_CURVESONLY) )
893 /* Action or Drivers */
894 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
896 if (ANIMDATA_HAS_KEYS(ob) /*&& !(ads->filterflag & ADS_FILTER_NOACTS)*/) {
897 AnimData *adt= ob->adt;
899 /* include action-expand widget? */
900 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
901 ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, base, ANIMTYPE_OBJECT, (ID *)ob);
903 BLI_addtail(anim_data, ale);
908 /* add F-Curve channels? */
909 if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
910 // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
911 items += animdata_filter_action(anim_data, adt->action, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
917 if (ANIMDATA_HAS_DRIVERS(ob)) {
918 AnimData *adt= ob->adt;
920 /* include drivers-expand widget? */
921 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
922 ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, base, ANIMTYPE_OBJECT, (ID *)ob);
924 BLI_addtail(anim_data, ale);
929 /* add F-Curve channels (drivers are F-Curves) */
930 if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
931 // need to make the ownertype normal object here... (maybe type should be a separate one for clarity?)
932 items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)ob);
938 if ((key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS)) {
939 /* Animation or Drivers */
940 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
941 /* include shapekey-expand widget? */
942 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
943 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
945 BLI_addtail(anim_data, ale);
951 if (FILTER_SKE_OBJD(key) || (filter_mode & ANIMFILTER_CURVESONLY)) {
952 items += animdata_filter_shapekey(anim_data, key, filter_mode, ob, ANIMTYPE_OBJECT, (ID *)ob);
957 if (ANIMDATA_HAS_DRIVERS(key)) {
958 AnimData *adt= key->adt;
960 /* include shapekey-expand widget? */
961 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
962 ale= make_new_animlistelem(key, ANIMTYPE_DSSKEY, base, ANIMTYPE_OBJECT, (ID *)ob);
964 BLI_addtail(anim_data, ale);
969 /* add F-Curve channels (drivers are F-Curves) */
970 if (FILTER_SKE_OBJD(key)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
971 // XXX owner info is messed up now...
972 items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, ob, ANIMTYPE_OBJECT, filter_mode, (ID *)key);
980 if ((ob->totcol) && !(ads->filterflag & ADS_FILTER_NOMAT))
981 items += animdata_filter_dopesheet_mats(anim_data, ads, base, filter_mode);
985 case OB_CAMERA: /* ------- Camera ------------ */
987 Camera *ca= (Camera *)ob->data;
989 if ((ads->filterflag & ADS_FILTER_NOCAM) == 0) {
990 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
991 if (ANIMDATA_HAS_KEYS(ca))
992 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
995 if (ANIMDATA_HAS_DRIVERS(ca))
996 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
1001 case OB_LAMP: /* ---------- Lamp ----------- */
1003 Lamp *la= (Lamp *)ob->data;
1005 if ((ads->filterflag & ADS_FILTER_NOLAM) == 0) {
1006 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
1007 if (ANIMDATA_HAS_KEYS(la))
1008 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
1011 if (ANIMDATA_HAS_DRIVERS(la))
1012 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
1017 case OB_CURVE: /* ------- Curve ---------- */
1019 Curve *cu= (Curve *)ob->data;
1021 if ((ads->filterflag & ADS_FILTER_NOCUR) == 0) {
1022 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS)==0) {
1023 if (ANIMDATA_HAS_KEYS(cu))
1024 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
1027 if (ANIMDATA_HAS_DRIVERS(cu))
1028 items += animdata_filter_dopesheet_obdata(anim_data, ads, base, filter_mode);
1035 /* return the number of items added to the list */
1039 static int animdata_filter_dopesheet_scene (ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
1041 World *wo= sce->world;
1045 /* add scene as a channel first (even if we aren't showing scenes we still need to show the scene's sub-data */
1046 if ((filter_mode & ANIMFILTER_CURVESONLY) == 0) {
1047 /* check if filtering by selection */
1048 if (ANIMCHANNEL_SELOK( (sce->flag & SCE_DS_SELECTED) )) {
1049 ale= make_new_animlistelem(sce, ANIMTYPE_SCENE, NULL, ANIMTYPE_NONE, NULL);
1051 BLI_addtail(anim_data, ale);
1057 /* if collapsed, don't go any further (unless adding keyframes only) */
1058 if ( (EXPANDED_SCEC(sce) == 0) && !(filter_mode & ANIMFILTER_CURVESONLY) )
1061 /* Action or Drivers */
1062 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
1064 if (ANIMDATA_HAS_KEYS(sce) && !(ads->filterflag & ADS_FILTER_NOSCE)) {
1065 AnimData *adt= sce->adt;
1067 /* include action-expand widget? */
1068 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1069 ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLACTD, sce, ANIMTYPE_SCENE, (ID *)sce);
1071 BLI_addtail(anim_data, ale);
1076 /* add F-Curve channels? */
1077 if (EXPANDED_ACTC(adt->action) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1078 items += animdata_filter_action(anim_data, adt->action, filter_mode, sce, ANIMTYPE_SCENE, (ID *)sce);
1084 if (ANIMDATA_HAS_DRIVERS(sce) && !(ads->filterflag & ADS_FILTER_NOSCE)) {
1085 AnimData *adt= sce->adt;
1087 /* include drivers-expand widget? */
1088 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1089 ale= make_new_animlistelem(adt->action, ANIMTYPE_FILLDRIVERS, sce, ANIMTYPE_SCENE, (ID *)sce);
1091 BLI_addtail(anim_data, ale);
1096 /* add F-Curve channels (drivers are F-Curves) */
1097 if (EXPANDED_DRVD(adt) || !(filter_mode & ANIMFILTER_CHANNELS)) {
1098 items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, sce, ANIMTYPE_SCENE, filter_mode, (ID *)sce);
1104 if ((wo && wo->adt) && !(ads->filterflag & ADS_FILTER_NOWOR)) {
1105 /* Animation or Drivers */
1106 if ((ads->filterflag & ADS_FILTER_ONLYDRIVERS) == 0) {
1107 AnimData *adt= wo->adt;
1109 /* include world-expand widget? */
1110 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1111 ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)sce);
1113 BLI_addtail(anim_data, ale);
1119 if (FILTER_WOR_SCED(wo) || (filter_mode & ANIMFILTER_CURVESONLY)) {
1120 items += animdata_filter_action(anim_data, adt->action, filter_mode, wo, ANIMTYPE_DSWOR, (ID *)wo);
1125 if (ANIMDATA_HAS_DRIVERS(wo)) {
1126 AnimData *adt= wo->adt;
1128 /* include shapekey-expand widget? */
1129 if ((filter_mode & ANIMFILTER_CHANNELS) && !(filter_mode & ANIMFILTER_CURVESONLY)) {
1130 ale= make_new_animlistelem(wo, ANIMTYPE_DSWOR, sce, ANIMTYPE_SCENE, (ID *)wo);
1132 BLI_addtail(anim_data, ale);
1137 /* add F-Curve channels (drivers are F-Curves) */
1138 if (FILTER_WOR_SCED(wo)/*EXPANDED_DRVD(adt)*/ || !(filter_mode & ANIMFILTER_CHANNELS)) {
1139 // XXX owner info is messed up now...
1140 items += animdata_filter_fcurves(anim_data, adt->drivers.first, NULL, wo, ANIMTYPE_DSWOR, filter_mode, (ID *)wo);
1146 /* return the number of items added to the list */
1150 // 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)
1151 static int animdata_filter_dopesheet (ListBase *anim_data, bDopeSheet *ads, int filter_mode)
1153 Scene *sce= (Scene *)ads->source;
1157 /* check that we do indeed have a scene */
1158 if ((ads->source == NULL) || (GS(ads->source->name)!=ID_SCE)) {
1159 printf("DopeSheet Error: Not scene! \n");
1163 /* scene-linked animation */
1164 // TODO: sequencer, composite nodes - are we to include those here too?
1168 /* check filtering-flags if ok */
1169 if (ads->filterflag) {
1170 if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) {
1171 sceOk= (ANIMDATA_HAS_DRIVERS(sce) && !(ads->filterflag & ADS_FILTER_NOSCE));
1172 worOk= ((sce->world) && ANIMDATA_HAS_DRIVERS(sce->world) && !(ads->filterflag & ADS_FILTER_NOWOR));
1175 sceOk= (ANIMDATA_HAS_KEYS(sce) && !(ads->filterflag & ADS_FILTER_NOSCE));
1176 worOk= ((sce->world) && ANIMDATA_HAS_KEYS(sce->world) && !(ads->filterflag & ADS_FILTER_NOWOR));
1180 sceOk= (ANIMDATA_HAS_KEYS(sce));
1181 worOk= ((sce->world) && ANIMDATA_HAS_KEYS(sce->world));
1184 /* check if not all bad (i.e. so there is something to show) */
1185 if ( !(!sceOk && !worOk) ) {
1186 /* add scene data to the list of filtered channels */
1187 items += animdata_filter_dopesheet_scene(anim_data, ads, sce, filter_mode);
1192 /* loop over all bases in the scene */
1193 for (base= sce->base.first; base; base= base->next) {
1194 /* check if there's an object (all the relevant checks are done in the ob-function) */
1196 Object *ob= base->object;
1197 Key *key= ob_get_key(ob);
1198 short actOk=1, keyOk=1, dataOk=1, matOk=1;
1200 /* firstly, check if object can be included, by the following fanimors:
1201 * - if only visible, must check for layer and also viewport visibility
1202 * - if only selected, must check if object is selected
1203 * - there must be animation data to edit
1205 // TODO: if cache is implemented, just check name here, and then
1206 if (filter_mode & ANIMFILTER_VISIBLE) {
1207 /* layer visibility - we check both object and base, since these may not be in sync yet */
1208 if ((sce->lay & (ob->lay|base->lay))==0) continue;
1210 /* outliner restrict-flag */
1211 if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
1214 /* additionally, dopesheet filtering also affects what objects to consider */
1215 if (ads->filterflag) {
1216 /* check selection and object type filters */
1217 if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) || (base == sce->basact)) ) {
1218 /* only selected should be shown */
1222 /* check filters for datatypes */
1223 if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) {
1224 actOk= (ANIMDATA_HAS_DRIVERS(ob));
1225 keyOk= ((key) && ANIMDATA_HAS_DRIVERS(key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS));
1228 actOk= ANIMDATA_HAS_KEYS(ob);
1229 keyOk= ((key) && ANIMDATA_HAS_KEYS(key) && !(ads->filterflag & ADS_FILTER_NOSHAPEKEYS));
1232 /* materials - only for geometric types */
1233 matOk= 0; /* by default, not ok... */
1234 if ( !(ads->filterflag & ADS_FILTER_NOMAT) && (ob->totcol) &&
1235 ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) )
1239 /* firstly check that we actuallly have some materials */
1240 for (a=0; a < ob->totcol; a++) {
1241 Material *ma= give_current_material(ob, a);
1243 /* if material has relevant animation data, break */
1244 if (ads->filterflag & ADS_FILTER_ONLYDRIVERS) {
1245 if (ANIMDATA_HAS_DRIVERS(ma)) {
1251 if (ANIMDATA_HAS_KEYS(ma)) {
1261 case OB_CAMERA: /* ------- Camera ------------ */
1263 Camera *ca= (Camera *)ob->data;
1264 if (ads->filterflag & ADS_FILTER_ONLYDRIVERS)
1265 dataOk= (ANIMDATA_HAS_DRIVERS(ca) && !(ads->filterflag & ADS_FILTER_NOCAM));
1267 dataOk= (ANIMDATA_HAS_KEYS(ca) && !(ads->filterflag & ADS_FILTER_NOCAM));
1270 case OB_LAMP: /* ---------- Lamp ----------- */
1272 Lamp *la= (Lamp *)ob->data;
1273 if (ads->filterflag & ADS_FILTER_ONLYDRIVERS)
1274 dataOk= (ANIMDATA_HAS_DRIVERS(la) && !(ads->filterflag & ADS_FILTER_NOLAM));
1276 dataOk= (ANIMDATA_HAS_KEYS(la) && !(ads->filterflag & ADS_FILTER_NOLAM));
1279 default: /* --- other --- */
1284 /* check if all bad (i.e. nothing to show) */
1285 if (!actOk && !keyOk && !dataOk && !matOk)
1289 /* check data-types */
1290 actOk= ANIMDATA_HAS_KEYS(ob);
1291 keyOk= (key != NULL);
1293 /* materials - only for geometric types */
1294 matOk= 0; /* by default, not ok... */
1295 if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL) && (ob->totcol))
1299 /* firstly check that we actuallly have some materials */
1300 for (a=0; a < ob->totcol; a++) {
1301 Material *ma= give_current_material(ob, a);
1303 if ((ma) && ANIMDATA_HAS_KEYS(ma)) {
1312 case OB_CAMERA: /* ------- Camera ------------ */
1314 Camera *ca= (Camera *)ob->data;
1315 dataOk= ANIMDATA_HAS_KEYS(ca);
1318 case OB_LAMP: /* ---------- Lamp ----------- */
1320 Lamp *la= (Lamp *)ob->data;
1321 dataOk= ANIMDATA_HAS_KEYS(la);
1324 case OB_CURVE: /* -------- Curve ---------- */
1326 Curve *cu= (Curve *)ob->data;
1327 dataOk= ANIMDATA_HAS_KEYS(cu);
1330 default: /* --- other --- */
1335 /* check if all bad (i.e. nothing to show) */
1336 if (!actOk && !keyOk && !dataOk && !matOk)
1340 /* since we're still here, this object should be usable */
1341 items += animdata_filter_dopesheet_ob(anim_data, ads, base, filter_mode);
1345 /* return the number of items in the list */
1349 /* ----------- Public API --------------- */
1351 /* This function filters the active data source to leave only animation channels suitable for
1352 * usage by the caller. It will return the length of the list
1354 * *anim_data: is a pointer to a ListBase, to which the filtered animation channels
1355 * will be placed for use.
1356 * filter_mode: how should the data be filtered - bitmapping accessed flags
1358 int ANIM_animdata_filter (bAnimContext *ac, ListBase *anim_data, int filter_mode, void *data, short datatype)
1362 /* only filter data if there's somewhere to put it */
1363 if (data && anim_data) {
1364 bAnimListElem *ale, *next;
1365 Object *obact= (ac) ? ac->obact : NULL;
1367 /* firstly filter the data */
1369 case ANIMCONT_ACTION:
1370 items= animdata_filter_action(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE, (ID *)obact);
1373 case ANIMCONT_SHAPEKEY:
1374 items= animdata_filter_shapekey(anim_data, data, filter_mode, NULL, ANIMTYPE_NONE, (ID *)obact);
1377 case ANIMCONT_GPENCIL:
1378 //items= animdata_filter_gpencil(anim_data, data, filter_mode);
1381 case ANIMCONT_DOPESHEET:
1382 case ANIMCONT_FCURVES:
1383 case ANIMCONT_DRIVERS:
1384 items= animdata_filter_dopesheet(anim_data, data, filter_mode);
1388 /* remove any weedy entries */
1389 // XXX this is weedy code!
1390 for (ale= anim_data->first; ale; ale= next) {
1393 if (ale->type == ANIMTYPE_NONE) {
1395 BLI_freelinkN(anim_data, ale);
1400 /* return the number of items in the list */
1404 /* ************************************************************ */