DopeSheet/Graph Editors: Restored Copy/Paste operators
authorJoshua Leung <aligorith@gmail.com>
Tue, 24 Feb 2009 11:18:24 +0000 (11:18 +0000)
committerJoshua Leung <aligorith@gmail.com>
Tue, 24 Feb 2009 11:18:24 +0000 (11:18 +0000)
The channel-matching code when pasting still needs improvements to work really nicely...

source/blender/editors/animation/keyframes_general.c
source/blender/editors/include/ED_keyframes_edit.h
source/blender/editors/space_action/action_edit.c
source/blender/editors/space_graph/graph_edit.c
source/blender/editors/space_graph/graph_ops.c
source/blender/windowmanager/intern/wm_init_exit.c

index cf7d56da5d9485f68e47b51fac1e667e18e57399..fc6ed9b00bb91c7a3b4cef7a25d172057181561f 100644 (file)
@@ -38,7 +38,6 @@
 #include "DNA_anim_types.h"
 #include "DNA_action_types.h"
 #include "DNA_curve_types.h"
-#include "DNA_ipo_types.h" // XXX to be removed
 #include "DNA_key_types.h"
 #include "DNA_object_types.h"
 #include "DNA_space_types.h"
@@ -357,3 +356,187 @@ void smooth_fcurve (FCurve *fcu)
 }
 
 /* **************************************************** */
+/* Copy/Paste Tools */
+/* - The copy/paste buffer currently stores a set of temporary F-Curves containing only the keyframes 
+ *   that were selected in each of the original F-Curves
+ * - All pasted frames are offset by the same amount. This is calculated as the difference in the times of
+ *     the current frame and the 'first keyframe' (i.e. the earliest one in all channels).
+ * - The earliest frame is calculated per copy operation.
+ */
+
+/* globals for copy/paste data (like for other copy/paste buffers) */
+ListBase animcopybuf = {NULL, NULL};
+static float animcopy_firstframe= 999999999.0f;
+
+/* datatype for use in copy/paste buffer */
+// XXX F-Curve editor should use this too
+typedef struct tAnimCopybufItem {
+       struct tAnimCopybufItem *next, *prev;
+       
+       ID *id;                         /* ID which owns the curve */
+       bActionGroup *grp;      /* Action Group */
+       char *rna_path;         /* RNA-Path */
+       int array_index;        /* array index */
+       
+       int totvert;            /* number of keyframes stored for this channel */
+       BezTriple *bezt;        /* keyframes in buffer */
+} tAnimCopybufItem;
+
+
+/* This function frees any MEM_calloc'ed copy/paste buffer data */
+// XXX find some header to put this in!
+void free_anim_copybuf (void)
+{
+       tAnimCopybufItem *aci, *acn;
+       
+       /* free each buffer element */
+       for (aci= animcopybuf.first; aci; aci= acn) {
+               acn= aci->next;
+               
+               /* free keyframes */
+               if (aci->bezt) 
+                       MEM_freeN(aci->bezt);
+                       
+               /* free RNA-path */
+               if (aci->rna_path)
+                       MEM_freeN(aci->rna_path);
+                       
+               /* free ourself */
+               BLI_freelinkN(&animcopybuf, aci);
+       }
+       
+       /* restore initial state */
+       animcopybuf.first= animcopybuf.last= NULL;
+       animcopy_firstframe= 999999999.0f;
+}
+
+/* ------------------- */
+
+/* This function adds data to the keyframes copy/paste buffer, freeing existing data first */
+short copy_animedit_keys (bAnimContext *ac, ListBase *anim_data)
+{      
+       bAnimListElem *ale;
+       
+       /* clear buffer first */
+       free_anim_copybuf();
+       
+       /* assume that each of these is an ipo-block */
+       for (ale= anim_data->first; ale; ale= ale->next) {
+               FCurve *fcu= (FCurve *)ale->key_data;
+               tAnimCopybufItem *aci;
+               BezTriple *bezt, *newbuf;
+               int i;
+               
+               /* init copybuf item info */
+               aci= MEM_callocN(sizeof(tAnimCopybufItem), "AnimCopybufItem");
+               aci->id= ale->id;
+               aci->grp= fcu->grp;
+               aci->rna_path= MEM_dupallocN(fcu->rna_path);
+               aci->array_index= fcu->array_index;
+               BLI_addtail(&animcopybuf, aci);
+               
+               /* add selected keyframes to buffer */
+               // XXX we don't cope with sample-data yet
+               // TODO: currently, we resize array everytime we add a new vert - this works ok as long as it is assumed only a few keys are copied
+               for (i=0, bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
+                       if (BEZSELECTED(bezt)) {
+                               /* add to buffer */
+                               newbuf= MEM_callocN(sizeof(BezTriple)*(aci->totvert+1), "copybuf beztriple");
+                               
+                               /* assume that since we are just resizing the array, just copy all existing data across */
+                               if (aci->bezt)
+                                       memcpy(newbuf, aci->bezt, sizeof(BezTriple)*(aci->totvert));
+                               
+                               /* copy current beztriple across too */
+                               *(newbuf + aci->totvert)= *bezt; 
+                               
+                               /* free old array and set the new */
+                               if (aci->bezt) MEM_freeN(aci->bezt);
+                               aci->bezt= newbuf;
+                               aci->totvert++;
+                               
+                               /* check if this is the earliest frame encountered so far */
+                               if (bezt->vec[1][0] < animcopy_firstframe)
+                                       animcopy_firstframe= bezt->vec[1][0];
+                       }
+               }
+               
+       }
+       
+       /* check if anything ended up in the buffer */
+       if (ELEM(NULL, animcopybuf.first, animcopybuf.last))
+               return -1;
+       
+       /* everything went fine */
+       return 0;
+}
+
+/* This function pastes data from the keyframes copy/paste buffer */
+short paste_animedit_keys (bAnimContext *ac, ListBase *anim_data)
+{
+       bAnimListElem *ale;
+       const Scene *scene= (ac->scene);
+       const float offset = (float)(CFRA - animcopy_firstframe);
+       short no_name= 0;
+       
+       /* check if buffer is empty */
+       if (ELEM(NULL, animcopybuf.first, animcopybuf.last)) {
+               //error("No data in buffer to paste");
+               return -1;
+       }
+       /* check if single channel in buffer (disregard names if so)  */
+       if (animcopybuf.first == animcopybuf.last)
+               no_name= 1;
+       
+       /* from selected channels */
+       for (ale= anim_data->first; ale; ale= ale->next) {
+               FCurve *fcu = (FCurve *)ale->data;              /* destination F-Curve */
+               tAnimCopybufItem *aci= NULL;
+               BezTriple *bezt;
+               int i;
+               
+               /* find buffer item to paste from 
+                *      - if names don't matter (i.e. only 1 channel in buffer), don't check id/group
+                *      - if names do matter, only check if id-type is ok for now (group check is not that important)
+                *      - most importantly, rna-paths should match (array indices are unimportant for now)
+                */
+               // TODO: the matching algorithm here is pathetic!
+               for (aci= animcopybuf.first; aci; aci= aci->next) {
+                       /* check that paths exist */
+                       if (aci->rna_path && fcu->rna_path) {
+                               if (strcmp(aci->rna_path, fcu->rna_path) == 0) {
+                                       /* should be a match unless there's more than one of these */
+                                       if ((no_name) || (aci->array_index == fcu->array_index)) 
+                                               break;
+                               }
+                       }
+               }
+               
+               
+               /* copy the relevant data from the matching buffer curve */
+               if (aci) {
+                       /* just start pasting, with the the first keyframe on the current frame, and so on */
+                       for (i=0, bezt=aci->bezt; i < aci->totvert; i++, bezt++) {                                              
+                               /* temporarily apply offset to src beztriple while copying */
+                               bezt->vec[0][0] += offset;
+                               bezt->vec[1][0] += offset;
+                               bezt->vec[2][0] += offset;
+                               
+                               /* insert the keyframe */
+                               insert_bezt_fcurve(fcu, bezt);
+                               
+                               /* un-apply offset from src beztriple after copying */
+                               bezt->vec[0][0] -= offset;
+                               bezt->vec[1][0] -= offset;
+                               bezt->vec[2][0] -= offset;
+                       }
+                       
+                       /* recalculate F-Curve's handles? */
+                       calchandles_fcurve(fcu);
+               }
+       }
+       
+       return 0;
+}
+
+/* **************************************************** */
index c0646514d1a0a3f2f6c079833e4f804437563410..1da1196a462545c642eeb33dda4bb84bded0af26 100644 (file)
@@ -134,6 +134,12 @@ void duplicate_fcurve_keys(struct FCurve *fcu);
 void clean_fcurve(struct FCurve *fcu, float thresh);
 void smooth_fcurve(struct FCurve *fcu);
 
+/* ----------- */
+
+void free_anim_copybuf(void);
+short copy_animedit_keys(struct bAnimContext *ac, ListBase *anim_data);
+short paste_animedit_keys(struct bAnimContext *ac, ListBase *anim_data);
+
 /* ************************************************ */
 
 #endif /* ED_KEYFRAMES_EDIT_H */
index 68e61d24b626d26e2f5270e760bc3f2556cc5a7d..99f18a2e653398633bec12d7bdec21862d1ea65b 100644 (file)
@@ -236,255 +236,42 @@ void ACT_OT_view_all (wmOperatorType *ot)
 /* GENERAL STUFF */
 
 /* ******************** Copy/Paste Keyframes Operator ************************* */
-/* - The copy/paste buffer currently stores a set of temporary F-Curves containing only the keyframes 
- *   that were selected in each of the original F-Curves
- * - All pasted frames are offset by the same amount. This is calculated as the difference in the times of
- *     the current frame and the 'first keyframe' (i.e. the earliest one in all channels).
- * - The earliest frame is calculated per copy operation.
- */
-
-/* globals for copy/paste data (like for other copy/paste buffers) */
-ListBase actcopybuf = {NULL, NULL};
-static float actcopy_firstframe= 999999999.0f;
-
-/* This function frees any MEM_calloc'ed copy/paste buffer data */
-// XXX find some header to put this in!
-void free_actcopybuf ()
-{
-       FCurve *fcu, *fcn;
-       
-       /* free_fcurve() frees F-Curve memory too, but we don't need to do remlink first, as we're freeing all 
-        * channels anyway, and the freeing func only cares about the data it's given
-        */
-       for (fcu= actcopybuf.first; fcu; fcu= fcn) {
-               fcn= fcu->next;
-               free_fcurve(fcu);
-       }
-       
-       actcopybuf.first= actcopybuf.last= NULL;
-       actcopy_firstframe= 999999999.0f;
-}
-
-/* ------------------- */
+/* NOTE: the backend code for this is shared with the graph editor */
 
-/* This function adds data to the copy/paste buffer, freeing existing data first
- * Only the selected action channels gets their selected keyframes copied.
- */
 static short copy_action_keys (bAnimContext *ac)
 {      
        ListBase anim_data = {NULL, NULL};
-       bAnimListElem *ale;
-       int filter;
+       int filter, ok=0;
        
        /* clear buffer first */
-       free_actcopybuf();
+       free_anim_copybuf();
        
        /* filter data */
        filter= (ANIMFILTER_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_CURVESONLY);
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
-       /* assume that each of these is an ipo-block */
-       for (ale= anim_data.first; ale; ale= ale->next) {
-#if 0
-               bActionChannel *achan;
-               Ipo *ipo= ale->key_data;
-               Ipo *ipn;
-               IpoCurve *icu, *icn;
-               BezTriple *bezt;
-               int i;
-               
-               /* coerce an action-channel out of owner */
-               if (ale->ownertype == ANIMTYPE_ACHAN) {
-                       bActionChannel *achanO= ale->owner;
-                       achan= MEM_callocN(sizeof(bActionChannel), "ActCopyPasteAchan");
-                       strcpy(achan->name, achanO->name);
-               }
-               else if (ale->ownertype == ANIMTYPE_SHAPEKEY) {
-                       achan= MEM_callocN(sizeof(bActionChannel), "ActCopyPasteAchan");
-                       strcpy(achan->name, "#ACP_ShapeKey");
-               }
-               else
-                       continue;
-               BLI_addtail(&actcopybuf, achan);
-               
-               /* add constraint channel if needed, then add new ipo-block */
-               if (ale->type == ANIMTYPE_CONCHAN) {
-                       bConstraintChannel *conchanO= ale->data;
-                       bConstraintChannel *conchan;
-                       
-                       conchan= MEM_callocN(sizeof(bConstraintChannel), "ActCopyPasteConchan");
-                       strcpy(conchan->name, conchanO->name);
-                       BLI_addtail(&achan->constraintChannels, conchan);
-                       
-                       conchan->ipo= ipn= MEM_callocN(sizeof(Ipo), "ActCopyPasteIpo");
-               }
-               else {
-                       achan->ipo= ipn= MEM_callocN(sizeof(Ipo), "ActCopyPasteIpo");
-               }
-               ipn->blocktype = ipo->blocktype;
-               
-               /* now loop through curves, and only copy selected keyframes */
-               for (icu= ipo->curve.first; icu; icu= icu->next) {
-                       /* allocate a new curve */
-                       icn= MEM_callocN(sizeof(IpoCurve), "ActCopyPasteIcu");
-                       icn->blocktype = icu->blocktype;
-                       icn->adrcode = icu->adrcode;
-                       BLI_addtail(&ipn->curve, icn);
-                       
-                       /* find selected BezTriples to add to the buffer (and set first frame) */
-                       for (i=0, bezt=icu->bezt; i < icu->totvert; i++, bezt++) {
-                               if (BEZSELECTED(bezt)) {
-                                       /* add to buffer ipo-curve */
-                                       //insert_bezt_icu(icn, bezt); // XXX
-                                       
-                                       /* check if this is the earliest frame encountered so far */
-                                       if (bezt->vec[1][0] < actcopy_firstframe)
-                                               actcopy_firstframe= bezt->vec[1][0];
-                               }
-                       }
-               }
-#endif
-               //FCurve *fcu= (FCurve *)ale->key_data;
-               //FCurve *fcn;
-               //BezTriple *bezt;
-               //int i;
-               
-               
-       }
-       
-       /* check if anything ended up in the buffer */
-       if (ELEM(NULL, actcopybuf.first, actcopybuf.last))
-               return -1;
+       /* copy keyframes */
+       ok= copy_animedit_keys(ac, &anim_data);
        
-       /* free temp memory */
+       /* clean up */
        BLI_freelistN(&anim_data);
-       
-       /* everything went fine */
-       return 0;
 }
 
+
 static short paste_action_keys (bAnimContext *ac)
-{
-#if 0 // XXX old animation system
+{      
        ListBase anim_data = {NULL, NULL};
-       bAnimListElem *ale;
-       int filter;
-       
-       const Scene *scene= (ac->scene);
-       const float offset = (float)(CFRA - actcopy_firstframe);
-       char *actname = NULL, *conname = NULL;
-       short no_name= 0;
-       
-       /* check if buffer is empty */
-       if (ELEM(NULL, actcopybuf.first, actcopybuf.last)) {
-               //error("No data in buffer to paste");
-               return -1;
-       }
-       /* check if single channel in buffer (disregard names if so)  */
-       if (actcopybuf.first == actcopybuf.last)
-               no_name= 1;
+       int filter, ok=0;
        
        /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_IPOKEYS);
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
-       /* from selected channels */
-       for (ale= anim_data.first; ale; ale= ale->next) {
-               Ipo *ipo_src = NULL;
-               bActionChannel *achan;
-               IpoCurve *ico, *icu;
-               BezTriple *bezt;
-               int i;
-               
-               /* find suitable IPO-block from buffer to paste from */
-               for (achan= actcopybuf.first; achan; achan= achan->next) {
-                       /* try to match data */
-                       if (ale->ownertype == ANIMTYPE_ACHAN) {
-                               bActionChannel *achant= ale->owner;
-                               
-                               /* check if we have a corresponding action channel */
-                               if ((no_name) || (strcmp(achan->name, achant->name)==0)) {
-                                       actname= achant->name;
-                                       
-                                       /* check if this is a constraint channel */
-                                       if (ale->type == ANIMTYPE_CONCHAN) {
-                                               bConstraintChannel *conchant= ale->data;
-                                               bConstraintChannel *conchan;
-                                               
-                                               for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next) {
-                                                       if (strcmp(conchan->name, conchant->name)==0) {
-                                                               conname= conchant->name;
-                                                               ipo_src= conchan->ipo;
-                                                               break;
-                                                       }
-                                               }
-                                               if (ipo_src) break;
-                                       }
-                                       else {
-                                               ipo_src= achan->ipo;
-                                               break;
-                                       }
-                               }
-                       }
-                       else if (ale->ownertype == ANIMTYPE_SHAPEKEY) {
-                               /* check if this action channel is "#ACP_ShapeKey" */
-                               if ((no_name) || (strcmp(achan->name, "#ACP_ShapeKey")==0)) {
-                                       actname= NULL;
-                                       ipo_src= achan->ipo;
-                                       break;
-                               }
-                       }       
-               }
-               
-               /* this shouldn't happen, but it might */
-               if (ipo_src == NULL)
-                       continue;
-               
-               /* loop over curves, pasting keyframes */
-               for (ico= ipo_src->curve.first; ico; ico= ico->next) {
-                       /* get IPO-curve to paste to (IPO-curve might not exist for destination, so gets created) */
-                       //icu= verify_ipocurve(ale->id, ico->blocktype, actname, conname, NULL, ico->adrcode, 1);
-                       
-                       
-                       if (icu) {
-                               /* just start pasting, with the the first keyframe on the current frame, and so on */
-                               for (i=0, bezt=ico->bezt; i < ico->totvert; i++, bezt++) {                                              
-                                       /* temporarily apply offset to src beztriple while copying */
-                                       bezt->vec[0][0] += offset;
-                                       bezt->vec[1][0] += offset;
-                                       bezt->vec[2][0] += offset;
-                                       
-                                       /* insert the keyframe */
-                                       //insert_bezt_icu(icu, bezt); // XXX
-                                       
-                                       /* un-apply offset from src beztriple after copying */
-                                       bezt->vec[0][0] -= offset;
-                                       bezt->vec[1][0] -= offset;
-                                       bezt->vec[2][0] -= offset;
-                               }
-                               
-                               /* recalculate channel's handles? */
-                               //calchandles_fcurve(fcu);
-                       }
-               }
-       }
+       /* paste keyframes */
+       ok= paste_animedit_keys(ac, &anim_data);
        
-       /* free temp memory */
+       /* clean up */
        BLI_freelistN(&anim_data);
-       
-       /* do depsgraph updates (for 3d-view)? */
-#if 0
-       if ((ob) && (G.saction->pin==0)) {
-               if (ob->type == OB_ARMATURE)
-                       DAG_object_flush_update(G.scene, ob, OB_RECALC_OB|OB_RECALC_DATA);
-               else
-                       DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
-       }
-#endif
-
-#endif // XXX old animation system
-
-       return 0;
 }
 
 /* ------------------- */
@@ -582,88 +369,6 @@ EnumPropertyItem prop_actkeys_insertkey_types[] = {
        {0, NULL, NULL, NULL}
 };
 
-#if 0
-void insertkey_action(void)
-{
-       void *data;
-       short datatype;
-       
-       short mode;
-       float cfra;
-       
-       /* get data */
-       data= get_action_context(&datatype);
-       if (data == NULL) return;
-       cfra = frame_to_float(CFRA);
-       
-       if (ELEM(datatype, ACTCONT_ACTION, ACTCONT_DOPESHEET)) {
-               ListBase act_data = {NULL, NULL};
-               bActListElem *ale;
-               int filter;
-               
-               /* ask user what to keyframe */
-               if (datatype == ACTCONT_ACTION)
-                       mode = pupmenu("Insert Key%t|All Channels%x1|Only Selected Channels%x2|In Active Group%x3");
-               else
-                       mode = pupmenu("Insert Key%t|All Channels%x1|Only Selected Channels%x2");
-               if (mode <= 0) return;
-               
-               /* filter data */
-               filter= (ACTFILTER_VISIBLE | ACTFILTER_FOREDIT | ACTFILTER_ONLYICU );
-               if (mode == 2)                  filter |= ACTFILTER_SEL;
-               else if (mode == 3)     filter |= ACTFILTER_ACTGROUPED;
-               
-               actdata_filter(&act_data, filter, data, datatype);
-               
-               /* loop through ipo curves retrieved */
-               for (ale= act_data.first; ale; ale= ale->next) {
-                       /* verify that this is indeed an ipo curve */
-                       if ((ale->key_data) && ((ale->owner) || (ale->id))) {
-                               bActionChannel *achan= (ale->ownertype==ACTTYPE_ACHAN) ? ((bActionChannel *)ale->owner) : (NULL);
-                               bConstraintChannel *conchan= (ale->type==ACTTYPE_CONCHAN) ? ale->data : NULL;
-                               IpoCurve *icu= (IpoCurve *)ale->key_data;
-                               ID *id= NULL;
-                               
-                               if (datatype == ACTCONT_ACTION) {
-                                       if (ale->owner) 
-                                               id= ale->owner;
-                               }
-                               else if (datatype == ACTCONT_DOPESHEET) {
-                                       if (ale->id)
-                                               id= ale->id;
-                               }
-                               
-                               if (id)
-                                       insertkey(id, icu->blocktype, ((achan)?(achan->name):(NULL)), ((conchan)?(conchan->name):(NULL)), icu->adrcode, 0);
-                               else
-                                       insert_vert_icu(icu, cfra, icu->curval, 0);
-                       }
-               }
-               
-               /* cleanup */
-               BLI_freelistN(&act_data);
-       }
-       else if (datatype == ACTCONT_SHAPEKEY) {
-               Key *key= (Key *)data;
-               IpoCurve *icu;
-               
-               /* ask user if they want to insert a keyframe */
-               mode = okee("Insert Keyframe?");
-               if (mode <= 0) return;
-               
-               if (key->ipo) {
-                       for (icu= key->ipo->curve.first; icu; icu=icu->next) {
-                               insert_vert_icu(icu, cfra, icu->curval, 0);
-                       }
-               }
-       }
-       else {
-               /* this tool is not supported in this mode */
-               return;
-       }
-}
-#endif
-
 /* this function is responsible for snapping keyframes to frame-times */
 static void insert_action_keys(bAnimContext *ac, short mode) 
 {
index e252a75532d0bed3e474bec70cdc4cd3106538a9..132beec85c97c43ef73109d266001a2c1f4933f4 100644 (file)
@@ -241,246 +241,45 @@ void GRAPHEDIT_OT_view_all (wmOperatorType *ot)
 /* ************************************************************************** */
 /* GENERAL STUFF */
 
-#if 0 // XXX stuff to be sanitised for the new anim system
-
-// TODO:
-//     - insert key
+// TODO: insertkey
 
 /* ******************** Copy/Paste Keyframes Operator ************************* */
-/* - xxx...
- * - All pasted frames are offset by the same amount. This is calculated as the difference in the times of
- *     the current frame and the 'first keyframe' (i.e. the earliest one in all channels).
- * - The earliest frame is calculated per copy operation.
- */
-
-#if 0
-/* globals for copy/paste data (like for other copy/paste buffers) */
-ListBase actcopybuf = {NULL, NULL};
-static float actcopy_firstframe= 999999999.0f;
+/* NOTE: the backend code for this is shared with the dopesheet editor */
 
-/* This function frees any MEM_calloc'ed copy/paste buffer data */
-// XXX find some header to put this in!
-void free_actcopybuf ()
-{
-       FCurve *fcu, *fcn;
-       
-       /* free_fcurve() frees F-Curve memory too, but we don't need to do remlink first, as we're freeing all 
-        * channels anyway, and the freeing func only cares about the data it's given
-        */
-       for (fcu= actcopybuf.first; fcu; fcu= fcn) {
-               fcn= fcu->next;
-               free_fcurve(fcu);
-       }
-       
-       actcopybuf.first= actcopybuf.last= NULL;
-       actcopy_firstframe= 999999999.0f;
-}
-#endif
-
-/* ------------------- */
-
-/* This function adds data to the copy/paste buffer, freeing existing data first
- * Only the selected action channels gets their selected keyframes copied.
- */
 static short copy_graph_keys (bAnimContext *ac)
 {      
-#if 0 // XXX old animation system
        ListBase anim_data = {NULL, NULL};
-       bAnimListElem *ale;
-       int filter;
+       int filter, ok=0;
        
        /* clear buffer first */
-       free_actcopybuf();
+       free_anim_copybuf();
        
        /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE| ANIMFILTER_SEL | ANIMFILTER_IPOKEYS);
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_SEL | ANIMFILTER_CURVESONLY);
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
-       /* assume that each of these is an ipo-block */
-       for (ale= anim_data.first; ale; ale= ale->next) {
-               bActionChannel *achan;
-               Ipo *ipo= ale->key_data;
-               Ipo *ipn;
-               IpoCurve *icu, *icn;
-               BezTriple *bezt;
-               int i;
-               
-               /* coerce an action-channel out of owner */
-               if (ale->ownertype == ANIMTYPE_ACHAN) {
-                       bActionChannel *achanO= ale->owner;
-                       achan= MEM_callocN(sizeof(bActionChannel), "ActCopyPasteAchan");
-                       strcpy(achan->name, achanO->name);
-               }
-               else if (ale->ownertype == ANIMTYPE_SHAPEKEY) {
-                       achan= MEM_callocN(sizeof(bActionChannel), "ActCopyPasteAchan");
-                       strcpy(achan->name, "#ACP_ShapeKey");
-               }
-               else
-                       continue;
-               BLI_addtail(&actcopybuf, achan);
-               
-               /* add constraint channel if needed, then add new ipo-block */
-               if (ale->type == ANIMTYPE_CONCHAN) {
-                       bConstraintChannel *conchanO= ale->data;
-                       bConstraintChannel *conchan;
-                       
-                       conchan= MEM_callocN(sizeof(bConstraintChannel), "ActCopyPasteConchan");
-                       strcpy(conchan->name, conchanO->name);
-                       BLI_addtail(&achan->constraintChannels, conchan);
-                       
-                       conchan->ipo= ipn= MEM_callocN(sizeof(Ipo), "ActCopyPasteIpo");
-               }
-               else {
-                       achan->ipo= ipn= MEM_callocN(sizeof(Ipo), "ActCopyPasteIpo");
-               }
-               ipn->blocktype = ipo->blocktype;
-               
-               /* now loop through curves, and only copy selected keyframes */
-               for (icu= ipo->curve.first; icu; icu= icu->next) {
-                       /* allocate a new curve */
-                       icn= MEM_callocN(sizeof(IpoCurve), "ActCopyPasteIcu");
-                       icn->blocktype = icu->blocktype;
-                       icn->adrcode = icu->adrcode;
-                       BLI_addtail(&ipn->curve, icn);
-                       
-                       /* find selected BezTriples to add to the buffer (and set first frame) */
-                       for (i=0, bezt=icu->bezt; i < icu->totvert; i++, bezt++) {
-                               if (BEZSELECTED(bezt)) {
-                                       /* add to buffer ipo-curve */
-                                       //insert_bezt_icu(icn, bezt); // XXX
-                                       
-                                       /* check if this is the earliest frame encountered so far */
-                                       if (bezt->vec[1][0] < actcopy_firstframe)
-                                               actcopy_firstframe= bezt->vec[1][0];
-                               }
-                       }
-               }
-       }
-       
-       /* check if anything ended up in the buffer */
-       if (ELEM(NULL, actcopybuf.first, actcopybuf.last))
-       //      error("Nothing copied to buffer");
-               return -1;
+       /* copy keyframes */
+       ok= copy_animedit_keys(ac, &anim_data);
        
-       /* free temp memory */
+       /* clean up */
        BLI_freelistN(&anim_data);
-#endif // XXX old animation system
-       
-       /* everything went fine */
-       return 0;
 }
 
+
 static short paste_graph_keys (bAnimContext *ac)
-{
-#if 0 // XXX old animation system
+{      
        ListBase anim_data = {NULL, NULL};
-       bAnimListElem *ale;
-       int filter;
-       
-       const Scene *scene= (ac->scene);
-       const float offset = (float)(CFRA - actcopy_firstframe);
-       char *actname = NULL, *conname = NULL;
-       short no_name= 0;
-       
-       /* check if buffer is empty */
-       if (ELEM(NULL, actcopybuf.first, actcopybuf.last)) {
-               //error("No data in buffer to paste");
-               return -1;
-       }
-       /* check if single channel in buffer (disregard names if so)  */
-       if (actcopybuf.first == actcopybuf.last)
-               no_name= 1;
+       int filter, ok=0;
        
        /* filter data */
-       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE| ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_IPOKEYS);
+       filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
        ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
        
-       /* from selected channels */
-       for (ale= anim_data.first; ale; ale= ale->next) {
-               Ipo *ipo_src = NULL;
-               bActionChannel *achan;
-               IpoCurve *ico, *icu;
-               BezTriple *bezt;
-               int i;
-               
-               /* find suitable IPO-block from buffer to paste from */
-               for (achan= actcopybuf.first; achan; achan= achan->next) {
-                       /* try to match data */
-                       if (ale->ownertype == ANIMTYPE_ACHAN) {
-                               bActionChannel *achant= ale->owner;
-                               
-                               /* check if we have a corresponding action channel */
-                               if ((no_name) || (strcmp(achan->name, achant->name)==0)) {
-                                       actname= achant->name;
-                                       
-                                       /* check if this is a constraint channel */
-                                       if (ale->type == ANIMTYPE_CONCHAN) {
-                                               bConstraintChannel *conchant= ale->data;
-                                               bConstraintChannel *conchan;
-                                               
-                                               for (conchan=achan->constraintChannels.first; conchan; conchan=conchan->next) {
-                                                       if (strcmp(conchan->name, conchant->name)==0) {
-                                                               conname= conchant->name;
-                                                               ipo_src= conchan->ipo;
-                                                               break;
-                                                       }
-                                               }
-                                               if (ipo_src) break;
-                                       }
-                                       else {
-                                               ipo_src= achan->ipo;
-                                               break;
-                                       }
-                               }
-                       }
-                       else if (ale->ownertype == ANIMTYPE_SHAPEKEY) {
-                               /* check if this action channel is "#ACP_ShapeKey" */
-                               if ((no_name) || (strcmp(achan->name, "#ACP_ShapeKey")==0)) {
-                                       actname= NULL;
-                                       ipo_src= achan->ipo;
-                                       break;
-                               }
-                       }       
-               }
-               
-               /* this shouldn't happen, but it might */
-               if (ipo_src == NULL)
-                       continue;
-               
-               /* loop over curves, pasting keyframes */
-               for (ico= ipo_src->curve.first; ico; ico= ico->next) {
-                       /* get IPO-curve to paste to (IPO-curve might not exist for destination, so gets created) */
-                       //icu= verify_ipocurve(ale->id, ico->blocktype, actname, conname, NULL, ico->adrcode, 1);
-                       
-                       
-                       if (icu) {
-                               /* just start pasting, with the the first keyframe on the current frame, and so on */
-                               for (i=0, bezt=ico->bezt; i < ico->totvert; i++, bezt++) {                                              
-                                       /* temporarily apply offset to src beztriple while copying */
-                                       bezt->vec[0][0] += offset;
-                                       bezt->vec[1][0] += offset;
-                                       bezt->vec[2][0] += offset;
-                                       
-                                       /* insert the keyframe */
-                                       //insert_bezt_icu(icu, bezt); // XXX
-                                       
-                                       /* un-apply offset from src beztriple after copying */
-                                       bezt->vec[0][0] -= offset;
-                                       bezt->vec[1][0] -= offset;
-                                       bezt->vec[2][0] -= offset;
-                               }
-                               
-                               /* recalculate channel's handles? */
-                               //calchandles_fcurve(fcu);
-                       }
-               }
-       }
+       /* paste keyframes */
+       ok= paste_animedit_keys(ac, &anim_data);
        
-       /* free temp memory */
+       /* clean up */
        BLI_freelistN(&anim_data);
-#endif // XXX old animation system
-
-       return 0;
 }
 
 /* ------------------- */
@@ -496,7 +295,7 @@ static int graphkeys_copy_exec(bContext *C, wmOperator *op)
        /* copy keyframes */
        if (copy_graph_keys(&ac)) {     
                // XXX errors - need a way to inform the user 
-               printf("Action Copy: No keyframes copied to copy-paste buffer\n");
+               printf("Graph Copy: No keyframes copied to copy-paste buffer\n");
        }
        
        /* set notifier tha things have changed */
@@ -532,7 +331,7 @@ static int graphkeys_paste_exec(bContext *C, wmOperator *op)
        /* paste keyframes */
        if (paste_graph_keys(&ac)) {
                // XXX errors - need a way to inform the user 
-               printf("Action Paste: Nothing to paste, as Copy-Paste buffer was empty.\n");
+               printf("Graph Paste: Nothing to paste, as Copy-Paste buffer was empty.\n");
        }
        
        /* validate keyframes after editing */
@@ -558,8 +357,6 @@ void GRAPHEDIT_OT_keyframes_paste (wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-#endif // XXX code to be sanitied for new system
-
 /* ******************** Duplicate Keyframes Operator ************************* */
 
 static void duplicate_graph_keys (bAnimContext *ac)
index f9900306c53de247c82d4832cd0d25eb3e9d7cba..d13ab1a86b903b1122022fe50a1db9a892fdc7c8 100644 (file)
@@ -120,10 +120,11 @@ void graphedit_operatortypes(void)
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_clean);
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_delete);
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_duplicate);
-#if 0 // XXX code to be sanitied for new system        
+       
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_copy);
        WM_operatortype_append(GRAPHEDIT_OT_keyframes_paste);
-#endif // XXX code to be sanitied for new system
+       
+       //TODO: insertkey...
 }
 
 /* ************************** registration - keymaps **********************************/
@@ -180,11 +181,12 @@ static void graphedit_keymap_keyframes (wmWindowManager *wm, ListBase *keymap)
        
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
        
-#if 0 // XXX code to be sanitied for new system
+               /* insertkey */
+       // TODO..
+       
                /* copy/paste */
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_copy", CKEY, KM_PRESS, KM_CTRL, 0);
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_keyframes_paste", VKEY, KM_PRESS, KM_CTRL, 0);
-#endif // XXX code to be sanitied for new system       
        
                /* auto-set range */
        WM_keymap_add_item(keymap, "GRAPHEDIT_OT_set_previewrange", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
index 9c13a321cf1f235792a3cb076a12dd31144cda4f..01e959715d3de7b3b20ca1d4fb07f5d31c80352d 100644 (file)
@@ -170,7 +170,7 @@ extern wchar_t *copybuf;
 extern wchar_t *copybufinfo;
 
        // XXX copy/paste buffer stuff...
-extern void free_actcopybuf(); 
+extern void free_anim_copybuf(); 
 
 /* called in creator.c even... tsk, split this! */
 void WM_exit(bContext *C)
@@ -220,8 +220,7 @@ void WM_exit(bContext *C)
        ED_preview_free_dbase();        /* frees a Main dbase, before free_blender! */
        free_blender();                         /* blender.c, does entire library and spacetypes */
 //     free_matcopybuf();
-//     free_ipocopybuf();
-       free_actcopybuf();
+       free_anim_copybuf();
 //     free_vertexpaint();
 //     free_imagepaint();