[Bf-blender-cvs] [b15c658801e] master: Cleanup: keyframe API naming, high level keyframe API

Campbell Barton noreply at git.blender.org
Fri Mar 6 04:25:12 CET 2020


Commit: b15c658801e191e09a4e9e8933a9ac79a3805e1b
Author: Campbell Barton
Date:   Fri Mar 6 13:41:27 2020 +1100
Branches: master
https://developer.blender.org/rBb15c658801e191e09a4e9e8933a9ac79a3805e1b

Cleanup: keyframe API naming, high level keyframe API

- Split 'verify_fcurve' into two functions:

  ED_action_fcurve_ensure which adds the f-curve if needed.
  ED_action_fcurve_find which returns NULL when not found.

  Callers of ED_action_fcurve_find had unused 'group'
  argument which has been removed.

- Rename verify_adt_action to ED_id_action_ensure

  It had an argument to add data which was always true,
  remove this instead of splitting in into a separate function.

===================================================================

M	source/blender/collada/AnimationImporter.cpp
M	source/blender/editors/animation/anim_channels_defines.c
M	source/blender/editors/animation/keyframing.c
M	source/blender/editors/animation/keyingsets.c
M	source/blender/editors/gpencil/gpencil_convert.c
M	source/blender/editors/include/ED_keyframing.h
M	source/blender/editors/object/object_constraint.c
M	source/blender/editors/object/object_relations.c
M	source/blender/makesrna/intern/rna_action.c
M	source/blender/python/intern/bpy_rna_anim.c

===================================================================

diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp
index 18ca6ae7a0f..715cd9e1a12 100644
--- a/source/blender/collada/AnimationImporter.cpp
+++ b/source/blender/collada/AnimationImporter.cpp
@@ -197,7 +197,7 @@ void AnimationImporter::add_fcurves_to_object(Main *bmain,
   bAction *act;
 
   if (!ob->adt || !ob->adt->action) {
-    act = verify_adt_action(bmain, (ID *)&ob->id, 1);
+    act = ED_id_action_ensure(bmain, (ID *)&ob->id);
   }
   else {
     act = ob->adt->action;
@@ -941,7 +941,7 @@ void AnimationImporter::apply_matrix_curves(Object *ob,
     }
   }
   Main *bmain = CTX_data_main(mContext);
-  verify_adt_action(bmain, (ID *)&ob->id, 1);
+  ED_id_action_ensure(bmain, (ID *)&ob->id);
 
   ListBase *curves = &ob->adt->action->curves;
 
@@ -1006,7 +1006,7 @@ static ListBase &get_animation_curves(Main *bmain, Material *ma)
 {
   bAction *act;
   if (!ma->adt || !ma->adt->action) {
-    act = verify_adt_action(bmain, (ID *)&ma->id, 1);
+    act = ED_id_action_ensure(bmain, (ID *)&ma->id);
   }
   else {
     act = ma->adt->action;
@@ -1052,7 +1052,7 @@ void AnimationImporter::translate_Animations(
     }
 
     if (!ob->adt || !ob->adt->action) {
-      act = verify_adt_action(bmain, (ID *)&ob->id, 1);
+      act = ED_id_action_ensure(bmain, (ID *)&ob->id);
     }
     else {
       act = ob->adt->action;
@@ -1115,7 +1115,7 @@ void AnimationImporter::translate_Animations(
   if ((animType->light) != 0) {
     Light *lamp = (Light *)ob->data;
     if (!lamp->adt || !lamp->adt->action) {
-      act = verify_adt_action(bmain, (ID *)&lamp->id, 1);
+      act = ED_id_action_ensure(bmain, (ID *)&lamp->id);
     }
     else {
       act = lamp->adt->action;
@@ -1153,7 +1153,7 @@ void AnimationImporter::translate_Animations(
 
     Camera *cam = (Camera *)ob->data;
     if (!cam->adt || !cam->adt->action) {
-      act = verify_adt_action(bmain, (ID *)&cam->id, 1);
+      act = ED_id_action_ensure(bmain, (ID *)&cam->id);
     }
     else {
       act = cam->adt->action;
@@ -1209,7 +1209,7 @@ void AnimationImporter::translate_Animations(
 
     Material *ma = BKE_object_material_get(ob, 1);
     if (!ma->adt || !ma->adt->action) {
-      act = verify_adt_action(bmain, (ID *)&ma->id, 1);
+      act = ED_id_action_ensure(bmain, (ID *)&ma->id);
     }
     else {
       act = ma->adt->action;
@@ -1390,7 +1390,7 @@ void AnimationImporter::add_bone_animation_sampled(Object *ob,
     }
   }
   Main *bmain = CTX_data_main(mContext);
-  verify_adt_action(bmain, (ID *)&ob->id, 1);
+  ED_id_action_ensure(bmain, (ID *)&ob->id);
 
   /* add curves */
   for (int i = 0; i < totcu; i++) {
@@ -1823,7 +1823,7 @@ Object *AnimationImporter::translate_animation_OLD(
 #endif
   }
   Main *bmain = CTX_data_main(mContext);
-  verify_adt_action(bmain, (ID *)&ob->id, 1);
+  ED_id_action_ensure(bmain, (ID *)&ob->id);
 
   ListBase *curves = &ob->adt->action->curves;
 
@@ -2129,7 +2129,7 @@ Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root,
     mul_v3_fl(job->scale, 0.5f);
     DEG_id_tag_update(&job->id, ID_RECALC_TRANSFORM);
 
-    verify_adt_action((ID *)&job->id, 1);
+    ED_id_action_ensure((ID *)&job->id);
 
     job->rotmode = ROT_MODE_QUAT;
 
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index 055c64290db..1af5721bffd 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -4432,8 +4432,8 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi
   if (RNA_path_resolve_property(&id_ptr, rna_path, &ptr, &prop)) {
     /* find or create new F-Curve */
     // XXX is the group name for this ok?
-    bAction *act = verify_adt_action(bmain, (ID *)key, 1);
-    FCurve *fcu = verify_fcurve(bmain, act, NULL, &ptr, rna_path, 0, 1);
+    bAction *act = ED_id_action_ensure(bmain, (ID *)key);
+    FCurve *fcu = ED_action_fcurve_ensure(bmain, act, NULL, &ptr, rna_path, 0);
 
     /* set the special 'replace' flag if on a keyframe */
     if (fcurve_frame_has_keyframe(fcu, cfra, 0)) {
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index 315761e9893..b48b96830d2 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -131,13 +131,13 @@ short ANIM_get_keyframing_flags(Scene *scene, short incl_mode)
 /* Get (or add relevant data to be able to do so) the Active Action for the given
  * Animation Data block, given an ID block where the Animation Data should reside.
  */
-bAction *verify_adt_action(Main *bmain, ID *id, short add)
+bAction *ED_id_action_ensure(Main *bmain, ID *id)
 {
   AnimData *adt;
 
   /* init animdata if none available yet */
   adt = BKE_animdata_from_id(id);
-  if ((adt == NULL) && (add)) {
+  if (adt == NULL) {
     adt = BKE_animdata_add_id(id);
   }
   if (adt == NULL) {
@@ -148,7 +148,7 @@ bAction *verify_adt_action(Main *bmain, ID *id, short add)
 
   /* init action if none available yet */
   /* TODO: need some wizardry to handle NLA stuff correct */
-  if ((adt->action == NULL) && (add)) {
+  if (adt->action == NULL) {
     /* init action name from name of ID block */
     char actname[sizeof(id->name) - 2];
     BLI_snprintf(actname, sizeof(actname), "%sAction", id->name + 2);
@@ -172,21 +172,34 @@ bAction *verify_adt_action(Main *bmain, ID *id, short add)
   return adt->action;
 }
 
-/* Get (or add relevant data to be able to do so) F-Curve from the Active Action,
+/**
+ * Find the F-Curve from the Active Action,
  * for the given Animation Data block. This assumes that all the destinations are valid.
  */
-FCurve *verify_fcurve(Main *bmain,
-                      bAction *act,
-                      const char group[],
-                      PointerRNA *ptr,
-                      const char rna_path[],
-                      const int array_index,
-                      short add)
+FCurve *ED_action_fcurve_find(struct bAction *act, const char rna_path[], const int array_index)
+{
+  /* Sanity checks. */
+  if (ELEM(NULL, act, rna_path)) {
+    return NULL;
+  }
+  return list_find_fcurve(&act->curves, rna_path, array_index);
+}
+
+/**
+ * Get (or add relevant data to be able to do so) F-Curve from the Active Action,
+ * for the given Animation Data block. This assumes that all the destinations are valid.
+ */
+FCurve *ED_action_fcurve_ensure(struct Main *bmain,
+                                struct bAction *act,
+                                const char group[],
+                                struct PointerRNA *ptr,
+                                const char rna_path[],
+                                const int array_index)
 {
   bActionGroup *agrp;
   FCurve *fcu;
 
-  /* sanity checks */
+  /* Sanity checks. */
   if (ELEM(NULL, act, rna_path)) {
     return NULL;
   }
@@ -197,7 +210,7 @@ FCurve *verify_fcurve(Main *bmain,
    */
   fcu = list_find_fcurve(&act->curves, rna_path, array_index);
 
-  if ((fcu == NULL) && (add)) {
+  if (fcu == NULL) {
     /* use default settings to make a F-Curve */
     fcu = MEM_callocN(sizeof(FCurve), "FCurve");
 
@@ -1284,7 +1297,9 @@ static bool insert_keyframe_fcurve_value(Main *bmain,
    *   but still try to get the F-Curve if it exists...
    */
   bool can_create_curve = (flag & (INSERTKEY_REPLACE | INSERTKEY_AVAILABLE)) == 0;
-  FCurve *fcu = verify_fcurve(bmain, act, group, ptr, rna_path, array_index, can_create_curve);
+  FCurve *fcu = can_create_curve ?
+                    ED_action_fcurve_ensure(bmain, act, group, ptr, rna_path, array_index) :
+                    ED_action_fcurve_find(act, rna_path, array_index);
 
   /* we may not have a F-Curve when we're replacing only... */
   if (fcu) {
@@ -1361,7 +1376,7 @@ short insert_keyframe(Main *bmain,
   /* if no action is provided, keyframe to the default one attached to this ID-block */
   if (act == NULL) {
     /* get action to add F-Curve+keyframe to */
-    act = verify_adt_action(bmain, id, 1);
+    act = ED_id_action_ensure(bmain, id);
 
     if (act == NULL) {
       BKE_reportf(reports,
@@ -1559,7 +1574,6 @@ short delete_keyframe(Main *bmain,
                       ReportList *reports,
                       ID *id,
                       bAction *act,
-                      const char group[],
                       const char rna_path[],
                       int array_index,
                       float cfra,
@@ -1625,7 +1639,7 @@ short delete_keyframe(Main *bmain,
 
   /* will only loop once unless the array index was -1 */
   for (; array_index < array_index_max; array_index++) {
-    FCurve *fcu = verify_fcurve(bmain, act, group, &ptr, rna_path, array_index, 0);
+    FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
 
     /* check if F-Curve exists and/or whether it can be edited */
     if (fcu == NULL) {
@@ -1665,7 +1679,6 @@ static short clear_keyframe(Main *bmain,
                             ReportList *reports,
                             ID *id,
                             bAction *act,
-                            const char group[],
                             const char rna_path[],
                             int array_index,
                             eInsertKeyFlags UNUSED(flag))
@@ -1727,7 +1740,7 @@ static short clear_keyframe(Main *bmain,
 
   /* will only loop once unless the array index was -1 */
   for (; array_index < array_index_max; array_index++) {
-    FCurve *fcu = verify_fcurve(bmain, act, group, &ptr, rna_path, array_index, 0);
+    FCurve *fcu = ED_action_fcurve_find(act, rna_path, array_index);
 
     /* check if F-Curve exists and/or whether it can be edited */
     if (fcu == NULL) {
@@ -2576,8 +2589,7 @@ static int delete_key_button_exec(bContext *C, wmOperator *op)
           index = -1;
         }
 
-        success = delete_keyframe(
-            bmain, op->reports, ptr.owner_id, NULL, NULL, path, index, cfra, 0);
+        success = delete_keyframe(bmain, op->reports, ptr.owner_id, NULL, path, index, cfra, 0);
         MEM_freeN(path);
       }
       else if (G.debug & G_DEBUG) {
@@ -2645,7 +2657,7 @@ sta

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list