[Bf-blender-cvs] [8e3879ab527] master: Cleanup: Rename & refactor several F-curve functions

Colin Basnett noreply at git.blender.org
Thu Jul 14 10:27:01 CEST 2022


Commit: 8e3879ab5276cf24ebd59a7bf0df69232fd5e4e6
Author: Colin Basnett
Date:   Thu Jul 14 10:22:30 2022 +0200
Branches: master
https://developer.blender.org/rB8e3879ab5276cf24ebd59a7bf0df69232fd5e4e6

Cleanup: Rename & refactor several F-curve functions

Rename and refactor several F-curve key manipulation functions, and move
them from `editors` to `blenkernel`.

The functions formerly known as `delete_fcurve_key`,
`delete_fcurve_keys`, and `clear_fcurve_keys` have been moved from
`ED_keyframes_edit.h` to `BKE_fcurve.h` and have been renamed according
to hierarchical naming rules.

Below is a table of the naming changes.

| From | To |
| -- | -- |
| `delete_fcurve_key(fcu, index, do_recalc)` | `BKE_fcurve_delete_key(fcu, index)` |
| `delete_fcurve_keys(fcu)` | `BKE_fcurve_delete_keys_selected(fcu)` |
| `clear_fcurve_keys(fcu)` | `BKE_fcurve_delete_keys_all(fcu)` |
| `calchandles_fcurve()` | `BKE_fcurve_handles_recalc()` |
| `calchandles_fcurve_ex()`| `BKE_fcurve_handles_recalc_ex()` |

The function formerly known as `delete_fcurve_key` no longer takes a
`do_fast` parameter, which determined whether or not to call
`calchandles_fcurve`. Now, the responsibility is on the caller to run
the new `BKE_fcurve_handles_recalc` function if they have want to
recalculate the handles.

In addition, there is now a new static private function called
`fcurve_bezt_free` which sets the key count to zero and frees the key
array. This function is now used in couple of instances of functionally
equivalent code. Note that `BKE_fcurve_delete_keys_all` is just a
wrapper around `fcurve_bezt_free`.

This change was initially spurred by the fact that `delete_fcurve_keys`
was improperly named; this was a good opportunity to fix the location
and naming of a few of these functions.

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D15282

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

M	source/blender/blenkernel/BKE_fcurve.h
M	source/blender/blenkernel/intern/action_mirror.c
M	source/blender/blenkernel/intern/fcurve.c
M	source/blender/blenkernel/intern/fmodifier.c
M	source/blender/editors/animation/anim_deps.c
M	source/blender/editors/animation/drivers.c
M	source/blender/editors/animation/fmodifier_ui.c
M	source/blender/editors/animation/keyframes_edit.c
M	source/blender/editors/animation/keyframes_general.c
M	source/blender/editors/animation/keyframing.c
M	source/blender/editors/armature/pose_lib.c
M	source/blender/editors/gpencil/gpencil_convert.c
M	source/blender/editors/include/ED_keyframes_edit.h
M	source/blender/editors/space_action/action_edit.c
M	source/blender/editors/space_graph/graph_buttons.c
M	source/blender/editors/space_graph/graph_edit.c
M	source/blender/editors/space_nla/nla_edit.c
M	source/blender/editors/transform/transform_convert.c
M	source/blender/editors/transform/transform_convert_graph.c
M	source/blender/io/collada/AnimationImporter.cpp
M	source/blender/io/collada/BCAnimationCurve.cpp
M	source/blender/makesrna/intern/rna_fcurve.c
M	source/blender/python/intern/bpy_rna_anim.c

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

diff --git a/source/blender/blenkernel/BKE_fcurve.h b/source/blender/blenkernel/BKE_fcurve.h
index 10d9ce3364d..3ccbd2ac1da 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -463,23 +463,38 @@ bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt,
                                        struct BezTriple *next,
                                        float *r_pdelta);
 
+/**
+ * Delete a keyframe from an F-curve at a specific index.
+ */
+void BKE_fcurve_delete_key(struct FCurve *fcu, int index);
+
+/**
+ * Delete selected keyframes from an F-curve.
+ */
+bool BKE_fcurve_delete_keys_selected(struct FCurve *fcu);
+
+/**
+ * Delete all keyframes from an F-curve.
+ */
+void BKE_fcurve_delete_keys_all(struct FCurve *fcu);
+
 /* -------- Curve Sanity -------- */
 
 /**
  * This function recalculates the handles of an F-Curve. Acts based on selection with `SELECT`
- * flag. To use a different flag, use #calchandles_fcurve_ex().
+ * flag. To use a different flag, use #BKE_fcurve_handles_recalc_ex().
  *
  * If the BezTriples have been rearranged, sort them first before using this.
  */
-void calchandles_fcurve(struct FCurve *fcu);
+void BKE_fcurve_handles_recalc(struct FCurve *fcu);
 /**
- * Variant of #calchandles_fcurve() that allows calculating based on a different select flag.
+ * Variant of #BKE_fcurve_handles_recalc() that allows calculating based on a different select flag.
  *
  * \param handle_sel_flag: The flag (bezt.f1/2/3) value to use to determine selection.
  * Usually `SELECT`, but may want to use a different one at times
  * (if caller does not operate on selection).
  */
-void calchandles_fcurve_ex(struct FCurve *fcu, eBezTriple_Flag handle_sel_flag);
+void BKE_fcurve_handles_recalc_ex(struct FCurve *fcu, eBezTriple_Flag handle_sel_flag);
 /**
  * Update handles, making sure the handle-types are valid (e.g. correctly deduced from an "Auto"
  * type), and recalculating their position vectors.
diff --git a/source/blender/blenkernel/intern/action_mirror.c b/source/blender/blenkernel/intern/action_mirror.c
index 7ef561c8216..0663538f3bb 100644
--- a/source/blender/blenkernel/intern/action_mirror.c
+++ b/source/blender/blenkernel/intern/action_mirror.c
@@ -363,7 +363,7 @@ static void action_flip_pchan(Object *ob_arm,
 
   /* Recalculate handles. */
   for (int i = 0; i < fcurve_array_len; i++) {
-    calchandles_fcurve_ex(fcurve_array[i], 0);
+    BKE_fcurve_handles_recalc_ex(fcurve_array[i], 0);
   }
 
   MEM_freeN((void *)keyed_frames);
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 0203620df84..972ff377519 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1146,7 +1146,7 @@ void fcurve_samples_to_keyframes(FCurve *fcu, const int start, const int end)
   MEM_SAFE_FREE(fcu->fpt);
 
   /* Not strictly needed since we use linear interpolation, but better be consistent here. */
-  calchandles_fcurve(fcu);
+  BKE_fcurve_handles_recalc(fcu);
 }
 
 /* ***************************** F-Curve Sanity ********************************* */
@@ -1216,7 +1216,7 @@ static BezTriple *cycle_offset_triple(
   return out;
 }
 
-void calchandles_fcurve_ex(FCurve *fcu, eBezTriple_Flag handle_sel_flag)
+void BKE_fcurve_handles_recalc_ex(FCurve *fcu, eBezTriple_Flag handle_sel_flag)
 {
   BezTriple *bezt, *prev, *next;
   int a = fcu->totvert;
@@ -1299,9 +1299,9 @@ void calchandles_fcurve_ex(FCurve *fcu, eBezTriple_Flag handle_sel_flag)
   }
 }
 
-void calchandles_fcurve(FCurve *fcu)
+void BKE_fcurve_handles_recalc(FCurve *fcu)
 {
-  calchandles_fcurve_ex(fcu, SELECT);
+  BKE_fcurve_handles_recalc_ex(fcu, SELECT);
 }
 
 void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, const bool use_handle)
@@ -1320,7 +1320,7 @@ void testhandles_fcurve(FCurve *fcu, eBezTriple_Flag sel_flag, const bool use_ha
   }
 
   /* Recalculate handles. */
-  calchandles_fcurve_ex(fcu, sel_flag);
+  BKE_fcurve_handles_recalc_ex(fcu, sel_flag);
 }
 
 void sort_time_fcurve(FCurve *fcu)
@@ -1590,6 +1590,12 @@ static void berekeny(float f1, float f2, float f3, float f4, float *o, int b)
   }
 }
 
+static void fcurve_bezt_free(FCurve *fcu)
+{
+  MEM_SAFE_FREE(fcu->bezt);
+  fcu->totvert = 0;
+}
+
 bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt,
                                        struct BezTriple *prev,
                                        struct BezTriple *next,
@@ -1651,6 +1657,69 @@ bool BKE_fcurve_bezt_subdivide_handles(struct BezTriple *bezt,
   return true;
 }
 
+void BKE_fcurve_delete_key(FCurve *fcu, int index)
+{
+  /* sanity check */
+  if (fcu == NULL) {
+    return;
+  }
+
+  /* verify the index:
+   * 1) cannot be greater than the number of available keyframes
+   * 2) negative indices are for specifying a value from the end of the array
+   */
+  if (abs(index) >= fcu->totvert) {
+    return;
+  }
+  if (index < 0) {
+    index += fcu->totvert;
+  }
+
+  /* Delete this keyframe */
+  memmove(
+      &fcu->bezt[index], &fcu->bezt[index + 1], sizeof(BezTriple) * (fcu->totvert - index - 1));
+  fcu->totvert--;
+
+  /* Free the array of BezTriples if there are not keyframes */
+  if (fcu->totvert == 0) {
+    fcurve_bezt_free(fcu);
+  }
+}
+
+bool BKE_fcurve_delete_keys_selected(FCurve *fcu)
+{
+  bool changed = false;
+
+  if (fcu->bezt == NULL) { /* ignore baked curves */
+    return false;
+  }
+
+  /* Delete selected BezTriples */
+  for (int i = 0; i < fcu->totvert; i++) {
+    if (fcu->bezt[i].f2 & SELECT) {
+      if (i == fcu->active_keyframe_index) {
+        BKE_fcurve_active_keyframe_set(fcu, NULL);
+      }
+      memmove(&fcu->bezt[i], &fcu->bezt[i + 1], sizeof(BezTriple) * (fcu->totvert - i - 1));
+      fcu->totvert--;
+      i--;
+      changed = true;
+    }
+  }
+
+  /* Free the array of BezTriples if there are not keyframes */
+  if (fcu->totvert == 0) {
+    fcurve_bezt_free(fcu);
+  }
+
+  return changed;
+}
+
+void BKE_fcurve_delete_keys_all(FCurve *fcu)
+{
+  fcurve_bezt_free(fcu);
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
diff --git a/source/blender/blenkernel/intern/fmodifier.c b/source/blender/blenkernel/intern/fmodifier.c
index 1bb7c49d616..e4c7572b9e4 100644
--- a/source/blender/blenkernel/intern/fmodifier.c
+++ b/source/blender/blenkernel/intern/fmodifier.c
@@ -1127,7 +1127,7 @@ FModifier *add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu)
 
   /* update the fcurve if the Cycles modifier is added */
   if ((owner_fcu) && (type == FMODIFIER_TYPE_CYCLES)) {
-    calchandles_fcurve(owner_fcu);
+    BKE_fcurve_handles_recalc(owner_fcu);
   }
 
   /* return modifier for further editing */
@@ -1215,7 +1215,7 @@ bool remove_fmodifier(ListBase *modifiers, FModifier *fcm)
 
     /* update the fcurve if the Cycles modifier is removed */
     if (update_fcu) {
-      calchandles_fcurve(update_fcu);
+      BKE_fcurve_handles_recalc(update_fcu);
     }
 
     return true;
diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c
index d80eac2422e..ff53ad42e84 100644
--- a/source/blender/editors/animation/anim_deps.c
+++ b/source/blender/editors/animation/anim_deps.c
@@ -356,7 +356,7 @@ void ANIM_animdata_update(bAnimContext *ac, ListBase *anim_data)
       if (ale->update & ANIM_UPDATE_HANDLES) {
         ale->update &= ~ANIM_UPDATE_HANDLES;
         if (fcu) {
-          calchandles_fcurve(fcu);
+          BKE_fcurve_handles_recalc(fcu);
         }
       }
 
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index c6f68228807..effedd4307d 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -124,7 +124,7 @@ struct FCurve *alloc_driver_fcurve(const char rna_path[],
       insert_vert_fcurve(
           fcu, 1.0f, 1.0f, BEZT_KEYTYPE_KEYFRAME, INSERTKEY_FAST | INSERTKEY_NO_USERPREF);
       fcu->extend = FCURVE_EXTRAPOLATE_LINEAR;
-      calchandles_fcurve(fcu);
+      BKE_fcurve_handles_recalc(fcu);
     }
   }
 
diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c
index 6f31472907b..d2f0ee622c4 100644
--- a/source/blender/editors/animation/fmodifier_ui.c
+++ b/source/blender/editors/animation/fmodifier_ui.c
@@ -1020,7 +1020,7 @@ bool ANIM_fmodifiers_paste_from_buf(ListBase *modifiers, bool replace, FCurve *c
 
   /* adding or removing the Cycles modifier requires an update to handles */
   if (curve && BKE_fcurve_is_cyclic(curve) != was_cyclic) {
-    calchandles_fcurve(curve);
+    BKE_fcurve_handles_recalc(curve);
   }
 
   /* did we succeed? */
diff --git a/source/blender/editors/animation/keyframes_edit.c b/source/blender/editors/animation/keyframes_edit.c
index 88207f7d514..706db498a82 100644
--- a/source/blender/editors/animation/keyframes_edit.c
+++ b/source/blender/editors/animation/keyframes_edit.c
@@ -444,7 +444,7 @@ void ANIM_animdata_keyframe_callback(bAnimContext *ac,
   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
 
   for (ale = anim_data.first; ale; ale = ale->next) {
-    ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, callback_fn, calchandles_fcurve);
+    ANIM_fcurve_keyframes_loop(NULL, ale->key_data, NULL, callback_fn, BKE_fcurve_handles_recalc);
     ale->update |= ANIM_UPDATE_DEFAULT;
   }
 
diff --git a/source/blender/editors/animation/keyframes_general.c b/source/blender/editors/animation/keyframes_general.c
index dd88752af14..7723c221a40 100644
--- a/source/blender/editors/animation/keyframes_general.c
+++ b/source/blender/editors/animation/keyframes_general.c
@@ -47,77 +47,6 @@
 
 /* **************************************************** */
 
-void delete_fcurve_key(FCurve *fcu, int index, bool do_recalc)
-{
-  /* sanity check */
-  if (fcu == NULL) {
-    return;
-  }
-
-  /* verify the index:
-   * 1) cannot be greater than the number of available keyframes
-   * 2) negative indices are for specifying a value from the end of the array
-   */
-  if (abs(index) >= fcu->totvert) {
-    return;
-  }
-  if (index < 0) {
-    index += fcu->totvert

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list