~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/editors/animation/keyframing.c

  • Committer: Reinhard Tartler
  • Date: 2014-05-31 01:50:05 UTC
  • mfrom: (14.2.27 sid)
  • Revision ID: siretart@tauware.de-20140531015005-ml6druahuj82nsav
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
#include "BKE_animsys.h"
58
58
#include "BKE_action.h"
59
59
#include "BKE_armature.h"
60
 
#include "BKE_constraint.h"
61
60
#include "BKE_depsgraph.h"
62
61
#include "BKE_fcurve.h"
63
62
#include "BKE_main.h"
184
183
                fcu = MEM_callocN(sizeof(FCurve), "FCurve");
185
184
                
186
185
                fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
187
 
                if (act->curves.first == NULL)
 
186
                if (BLI_listbase_is_empty(&act->curves))
188
187
                        fcu->flag |= FCURVE_ACTIVE;  /* first one added active */
189
188
                        
190
189
                /* store path - make copy, and store that */
229
228
        return fcu;
230
229
}
231
230
 
 
231
/* Helper */
 
232
static void update_autoflags_fcurve_direct(FCurve *fcu, PropertyRNA *prop)
 
233
{
 
234
        /* set additional flags for the F-Curve (i.e. only integer values) */
 
235
        fcu->flag &= ~(FCURVE_INT_VALUES | FCURVE_DISCRETE_VALUES);
 
236
        switch (RNA_property_type(prop)) {
 
237
                case PROP_FLOAT:
 
238
                        /* do nothing */
 
239
                        break;
 
240
                case PROP_INT:
 
241
                        /* do integer (only 'whole' numbers) interpolation between all points */
 
242
                        fcu->flag |= FCURVE_INT_VALUES;
 
243
                        break;
 
244
                default:
 
245
                        /* do 'discrete' (i.e. enum, boolean values which cannot take any intermediate
 
246
                         * values at all) interpolation between all points
 
247
                         *    - however, we must also ensure that evaluated values are only integers still
 
248
                         */
 
249
                        fcu->flag |= (FCURVE_DISCRETE_VALUES | FCURVE_INT_VALUES);
 
250
                        break;
 
251
        }
 
252
}
 
253
 
 
254
/*  Update integer/discrete flags of the FCurve (used when creating/inserting keyframes,
 
255
 *  but also through RNA when editing an ID prop, see T37103).
 
256
 */
 
257
void update_autoflags_fcurve(FCurve *fcu, bContext *C, ReportList *reports, PointerRNA *ptr)
 
258
{
 
259
        PointerRNA tmp_ptr;
 
260
        PropertyRNA *prop;
 
261
        int old_flag = fcu->flag;
 
262
 
 
263
        if ((ptr->id.data == NULL) && (ptr->data == NULL)) {
 
264
                BKE_report(reports, RPT_ERROR, "No RNA pointer available to retrieve values for this fcurve");
 
265
                return;
 
266
        }
 
267
 
 
268
        /* try to get property we should be affecting */
 
269
        if (RNA_path_resolve_property(ptr, fcu->rna_path, &tmp_ptr, &prop) == false) {
 
270
                /* property not found... */
 
271
                const char *idname = (ptr->id.data) ? ((ID *)ptr->id.data)->name : TIP_("<No ID pointer>");
 
272
 
 
273
                BKE_reportf(reports, RPT_ERROR,
 
274
                            "Could not update flags for this fcurve, as RNA path is invalid for the given ID "
 
275
                            "(ID = %s, path = %s)",
 
276
                            idname, fcu->rna_path);
 
277
                return;
 
278
        }
 
279
 
 
280
        update_autoflags_fcurve_direct(fcu, prop);
 
281
 
 
282
        if (old_flag != fcu->flag) {
 
283
                /* Same as if keyframes had been changed */
 
284
                WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
 
285
        }
 
286
}
 
287
 
232
288
/* ************************************************** */
233
289
/* KEYFRAME INSERTION */
234
290
 
722
778
                rotmode = ob->rotmode;
723
779
        }
724
780
        else if (ptr->type == &RNA_PoseBone) {
725
 
                Object *ob = (Object *)ptr->id.data; /* we assume that this is always set, and is an object */
726
781
                bPoseChannel *pchan = (bPoseChannel *)ptr->data;
727
782
                
728
 
                /* Although it is not strictly required for this particular space conversion, 
729
 
                 * arg1 must not be null, as there is a null check for the other conversions to
730
 
                 * be safe. Therefore, the active object is passed here, and in many cases, this
731
 
                 * will be what owns the pose-channel that is getting this anyway.
732
 
                 */
733
 
                copy_m4_m4(tmat, pchan->pose_mat);
734
 
                BKE_constraint_mat_convertspace(ob, pchan, tmat, CONSTRAINT_SPACE_POSE, CONSTRAINT_SPACE_LOCAL);
 
783
                BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, tmat);
735
784
                rotmode = pchan->rotmode;
736
785
                
737
786
                /* Loc code is specific... */
835
884
                }
836
885
        }
837
886
        
838
 
        /* set additional flags for the F-Curve (i.e. only integer values) */
839
 
        fcu->flag &= ~(FCURVE_INT_VALUES | FCURVE_DISCRETE_VALUES);
840
 
        switch (RNA_property_type(prop)) {
841
 
                case PROP_FLOAT:
842
 
                        /* do nothing */
843
 
                        break;
844
 
                case PROP_INT:
845
 
                        /* do integer (only 'whole' numbers) interpolation between all points */
846
 
                        fcu->flag |= FCURVE_INT_VALUES;
847
 
                        break;
848
 
                default:
849
 
                        /* do 'discrete' (i.e. enum, boolean values which cannot take any intermediate
850
 
                         * values at all) interpolation between all points
851
 
                         *      - however, we must also ensure that evaluated values are only integers still
852
 
                         */
853
 
                        fcu->flag |= (FCURVE_DISCRETE_VALUES | FCURVE_INT_VALUES);
854
 
                        break;
855
 
        }
 
887
        update_autoflags_fcurve_direct(fcu, prop);
856
888
        
857
889
        /* obtain value to give keyframe */
858
890
        if ( (flag & INSERTKEY_MATRIX) && 
1100
1132
 
1101
1133
                if (BKE_fcurve_is_protected(fcu)) {
1102
1134
                        BKE_reportf(reports, RPT_WARNING,
1103
 
                                    "not deleting keyframe for locked F-Curve '%s' for %s '%s'",
 
1135
                                    "Not deleting keyframe for locked F-Curve '%s' for %s '%s'",
1104
1136
                                    fcu->rna_path, BKE_idcode_to_name(GS(id->name)), id->name + 2);
1105
1137
                        continue;
1106
1138
                }
1217
1249
{
1218
1250
        ScrArea *sa = CTX_wm_area(C);
1219
1251
        Scene *scene = CTX_data_scene(C);
1220
 
        SpaceOops *so = CTX_wm_space_outliner(C);
1221
1252
        
1222
1253
        /* if no area or active scene */
1223
1254
        if (ELEM(NULL, sa, scene)) 
1224
1255
                return 0;
1225
1256
        
1226
 
        /* if Outliner, don't allow in some views */
1227
 
        if (so) {
1228
 
                if (ELEM5(so->outlinevis, SO_GROUPS, SO_LIBRARIES, SO_SEQUENCE, SO_USERDEF, SO_KEYMAP)) {
1229
 
                        return 0;
1230
 
                }
1231
 
        }
1232
 
        
1233
 
        /* TODO: checks for other space types can be added here */
1234
 
        
1235
1257
        /* should be fine */
1236
1258
        return 1;
1237
1259
}
1476
1498
 
1477
1499
static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op))
1478
1500
{
 
1501
        bool changed = false;
 
1502
 
1479
1503
        CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
1480
1504
        {
1481
1505
                /* just those in active action... */
1515
1539
                                /* delete F-Curve completely */
1516
1540
                                if (can_delete) {
1517
1541
                                        ANIM_fcurve_delete_from_animdata(NULL, adt, fcu);
 
1542
                                        DAG_id_tag_update(&ob->id, OB_RECALC_OB);
 
1543
                                        changed = true;
1518
1544
                                }
1519
1545
                        }
1520
1546
                }
1521
 
                
1522
 
                /* update... */
1523
 
                DAG_id_tag_update(&ob->id, OB_RECALC_OB);
1524
1547
        }
1525
1548
        CTX_DATA_END;
1526
 
        
 
1549
 
 
1550
        if (!changed) {
 
1551
                return OPERATOR_CANCELLED;
 
1552
        }
 
1553
 
1527
1554
        /* send updates */
1528
1555
        WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL);
1529
1556
        
1570
1597
 
1571
1598
                                if (BKE_fcurve_is_protected(fcu)) {
1572
1599
                                        BKE_reportf(op->reports, RPT_WARNING,
1573
 
                                                    "not deleting keyframe for locked F-Curve '%s', object '%s'",
 
1600
                                                    "Not deleting keyframe for locked F-Curve '%s', object '%s'",
1574
1601
                                                    fcu->rna_path, id->name + 2);
1575
1602
                                        continue;
1576
1603
                                }
1622
1649
        char *path;
1623
1650
        float cfra = (float)CFRA;
1624
1651
        short success = 0;
1625
 
        int a, index, length, all = RNA_boolean_get(op->ptr, "all");
 
1652
        int a, index, length;
 
1653
        const bool all = RNA_boolean_get(op->ptr, "all");
1626
1654
        short flag = 0;
1627
1655
        
1628
1656
        /* flags for inserting keyframes */
1713
1741
        char *path;
1714
1742
        float cfra = (float)CFRA; // XXX for now, don't bother about all the yucky offset crap
1715
1743
        short success = 0;
1716
 
        int a, index, length, all = RNA_boolean_get(op->ptr, "all");
 
1744
        int a, index, length;
 
1745
        const bool all = RNA_boolean_get(op->ptr, "all");
1717
1746
        
1718
1747
        /* try to insert keyframe using property retrieved from UI */
1719
1748
        uiContextActiveProperty(C, &ptr, &prop, &index);
1782
1811
        PropertyRNA *prop = NULL;
1783
1812
        char *path;
1784
1813
        short success = 0;
1785
 
        int a, index, length, all = RNA_boolean_get(op->ptr, "all");
 
1814
        int a, index, length;
 
1815
        const bool all = RNA_boolean_get(op->ptr, "all");
1786
1816
 
1787
1817
        /* try to insert keyframe using property retrieved from UI */
1788
1818
        uiContextActiveProperty(C, &ptr, &prop, &index);
1871
1901
/* --------------- API/Per-Datablock Handling ------------------- */
1872
1902
 
1873
1903
/* Checks if some F-Curve has a keyframe for a given frame */
1874
 
short fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter)
 
1904
bool fcurve_frame_has_keyframe(FCurve *fcu, float frame, short filter)
1875
1905
{
1876
1906
        /* quick sanity check */
1877
1907
        if (ELEM(NULL, fcu, fcu->bezt))
1939
1969
        }
1940
1970
        
1941
1971
        /* try shapekey keyframes (if available, and allowed by filter) */
1942
 
        if (!(filter & ANIMFILTER_KEYS_LOCAL) && !(filter & ANIMFILTER_KEYS_NOSKEY) ) {
 
1972
        if (!(filter & ANIMFILTER_KEYS_LOCAL) && !(filter & ANIMFILTER_KEYS_NOSKEY)) {
1943
1973
                Key *key = BKE_key_from_object(ob);
1944
1974
                
1945
1975
                /* shapekeys can have keyframes ('Relative Shape Keys') 
1955
1985
        }
1956
1986
 
1957
1987
        /* try materials */
1958
 
        if (!(filter & ANIMFILTER_KEYS_LOCAL) && !(filter & ANIMFILTER_KEYS_NOMAT) ) {
 
1988
        if (!(filter & ANIMFILTER_KEYS_LOCAL) && !(filter & ANIMFILTER_KEYS_NOMAT)) {
1959
1989
                /* if only active, then we can skip a lot of looping */
1960
1990
                if (filter & ANIMFILTER_KEYS_ACTIVE) {
1961
1991
                        Material *ma = give_current_material(ob, (ob->actcol + 1));