[Bf-blender-cvs] [2ef68edad8b] master: Cleanup: animation, deduplicate "can edit action" logic

Sybren A. Stüvel noreply at git.blender.org
Fri Sep 25 14:21:39 CEST 2020


Commit: 2ef68edad8b9832d55c185d4db948417e74ae8c2
Author: Sybren A. Stüvel
Date:   Thu Sep 24 18:22:30 2020 +0200
Branches: master
https://developer.blender.org/rB2ef68edad8b9832d55c185d4db948417e74ae8c2

Cleanup: animation, deduplicate "can edit action" logic

Move "action editable" check from RNA code to Blender kernel
`BKE_animdata_action_editable()`.

No functional changes.

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

M	source/blender/blenkernel/BKE_anim_data.h
M	source/blender/blenkernel/intern/anim_data.c
M	source/blender/makesrna/intern/rna_animation.c

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

diff --git a/source/blender/blenkernel/BKE_anim_data.h b/source/blender/blenkernel/BKE_anim_data.h
index 8507793b1dc..48ea06ea9d8 100644
--- a/source/blender/blenkernel/BKE_anim_data.h
+++ b/source/blender/blenkernel/BKE_anim_data.h
@@ -56,6 +56,8 @@ struct AnimData *BKE_animdata_add_id(struct ID *id);
 /* Set active action used by AnimData from the given ID-block */
 bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct bAction *act);
 
+bool BKE_animdata_action_editable(const struct AnimData *adt);
+
 /* Free AnimData */
 void BKE_animdata_free(struct ID *id, const bool do_id_user);
 
diff --git a/source/blender/blenkernel/intern/anim_data.c b/source/blender/blenkernel/intern/anim_data.c
index 24908469a77..30b75734e77 100644
--- a/source/blender/blenkernel/intern/anim_data.c
+++ b/source/blender/blenkernel/intern/anim_data.c
@@ -180,17 +180,14 @@ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
 {
   AnimData *adt = BKE_animdata_from_id(id);
 
-  /* animdata validity check */
+  /* Animdata validity check. */
   if (adt == NULL) {
     BKE_report(reports, RPT_WARNING, "No AnimData to set action on");
     return false;
   }
 
-  /* active action is only editable when it is not a tweaking strip
-   * see rna_AnimData_action_editable() in rna_animation.c
-   */
-  if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) {
-    /* cannot remove, otherwise things turn to custard */
+  if (!BKE_animdata_action_editable(adt)) {
+    /* Cannot remove, otherwise things turn to custard. */
     BKE_report(reports, RPT_ERROR, "Cannot change action, as it is still being edited in NLA");
     return false;
   }
@@ -200,8 +197,6 @@ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
     id_us_min((ID *)adt->action);
   }
 
-  /* Assume that AnimData's action can in fact be edited. */
-
   if (act == NULL) {
     /* Just clearing the action. */
     adt->action = NULL;
@@ -227,6 +222,14 @@ bool BKE_animdata_set_action(ReportList *reports, ID *id, bAction *act)
   return true;
 }
 
+bool BKE_animdata_action_editable(const AnimData *adt)
+{
+  /* Active action is only editable when it is not a tweaking strip. */
+  const bool is_tweaking_strip = (adt->flag & ADT_NLA_EDIT_ON) || adt->actstrip != NULL ||
+                                 adt->tmpact != NULL;
+  return !is_tweaking_strip;
+}
+
 /* Freeing -------------------------------------------- */
 
 /* Free AnimData used by the nominated ID-block, and clear ID-block's AnimData pointer */
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index 823446a9d3b..a50d27a726b 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -144,14 +144,7 @@ static void rna_AnimData_dependency_update(Main *bmain, Scene *scene, PointerRNA
 static int rna_AnimData_action_editable(PointerRNA *ptr, const char **UNUSED(r_info))
 {
   AnimData *adt = (AnimData *)ptr->data;
-
-  /* active action is only editable when it is not a tweaking strip */
-  if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) {
-    return 0;
-  }
-  else {
-    return PROP_EDITABLE;
-  }
+  return BKE_animdata_action_editable(adt) ? PROP_EDITABLE : 0;
 }
 
 static void rna_AnimData_action_set(PointerRNA *ptr,



More information about the Bf-blender-cvs mailing list