From fc74f341a5fe9fbf7b01cf46434a231cb4d25453 Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 7 Nov 2023 16:46:38 +0100 Subject: [PATCH] Refactor: Move code related to animdata to animrig No functional changes. Move the following functions `ANIM_fcurve_delete_from_animdata` and `ANIM_remove_empty_action_from_animdata` to `ANIM_animdata.hh` / `animdata.cc` in animrig This removes some includes to `ED_anim_api.hh` from animrig Pull Request: https://projects.blender.org/blender/blender/pulls/114581 --- source/blender/animrig/ANIM_animdata.hh | 31 ++++++ source/blender/animrig/CMakeLists.txt | 2 + source/blender/animrig/intern/animdata.cc | 95 +++++++++++++++++++ source/blender/animrig/intern/fcurve.cc | 1 + source/blender/animrig/intern/keyframing.cc | 2 +- source/blender/animrig/intern/visualkey.cc | 2 - .../editors/animation/anim_channels_edit.cc | 81 +--------------- .../editors/animation/keyframes_general.cc | 5 +- .../blender/editors/animation/keyframing.cc | 6 +- source/blender/editors/include/ED_anim_api.hh | 14 --- .../editors/space_action/action_edit.cc | 3 +- .../blender/editors/space_graph/graph_edit.cc | 3 +- 12 files changed, 142 insertions(+), 103 deletions(-) create mode 100644 source/blender/animrig/ANIM_animdata.hh create mode 100644 source/blender/animrig/intern/animdata.cc diff --git a/source/blender/animrig/ANIM_animdata.hh b/source/blender/animrig/ANIM_animdata.hh new file mode 100644 index 00000000000..e09343f5957 --- /dev/null +++ b/source/blender/animrig/ANIM_animdata.hh @@ -0,0 +1,31 @@ +/* SPDX-FileCopyrightText: 2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup animrig + * + * \brief Functions to work with AnimData. + */ + +struct bAnimContext; +struct AnimData; +struct FCurve; + +namespace blender::animrig { + +/** + * Delete the F-Curve from the given AnimData block (if possible), + * as appropriate according to animation context. + */ +void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, AnimData *adt, FCurve *fcu); + +/** + * Unlink the action from animdata if it's empty. + * + * If the action has no F-Curves, unlink it from AnimData if it did not + * come from a NLA Strip being tweaked. + */ +bool ANIM_remove_empty_action_from_animdata(AnimData *adt); + +} // namespace blender::animrig \ No newline at end of file diff --git a/source/blender/animrig/CMakeLists.txt b/source/blender/animrig/CMakeLists.txt index d0bcc381f5d..9f2ae882225 100644 --- a/source/blender/animrig/CMakeLists.txt +++ b/source/blender/animrig/CMakeLists.txt @@ -22,6 +22,7 @@ set(INC_SYS set(SRC intern/action.cc intern/anim_rna.cc + intern/animdata.cc intern/bone_collections.cc intern/bonecolor.cc intern/fcurve.cc @@ -30,6 +31,7 @@ set(SRC intern/visualkey.cc ANIM_action.hh + ANIM_animdata.hh ANIM_armature_iter.hh ANIM_bone_collections.h ANIM_bone_collections.hh diff --git a/source/blender/animrig/intern/animdata.cc b/source/blender/animrig/intern/animdata.cc new file mode 100644 index 00000000000..3a7ea86355c --- /dev/null +++ b/source/blender/animrig/intern/animdata.cc @@ -0,0 +1,95 @@ +/* SPDX-FileCopyrightText: 2023 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup animrig + */ + +#include "ANIM_animdata.hh" +#include "BKE_action.h" +#include "BKE_fcurve.h" +#include "BKE_lib_id.h" +#include "BLI_listbase.h" +#include "DNA_anim_types.h" +#include "ED_anim_api.hh" + +namespace blender::animrig { + +/* -------------------------------------------------------------------- */ +/** \name Public F-Curves API + * \{ */ + +void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, AnimData *adt, FCurve *fcu) +{ + /* - if no AnimData, we've got nowhere to remove the F-Curve from + * (this doesn't guarantee that the F-Curve is in there, but at least we tried + * - if no F-Curve, there is nothing to remove + */ + if (ELEM(nullptr, adt, fcu)) { + return; + } + + /* remove from whatever list it came from + * - Action Group + * - Action + * - Drivers + * - TODO... some others? + */ + if ((ac) && (ac->datatype == ANIMCONT_DRIVERS)) { + /* driver F-Curve */ + BLI_remlink(&adt->drivers, fcu); + } + else if (adt->action) { + bAction *act = adt->action; + + /* remove from group or action, whichever one "owns" the F-Curve */ + if (fcu->grp) { + bActionGroup *agrp = fcu->grp; + + /* remove F-Curve from group+action */ + action_groups_remove_channel(act, fcu); + + /* if group has no more channels, remove it too, + * otherwise can have many dangling groups #33541. + */ + if (BLI_listbase_is_empty(&agrp->channels)) { + BLI_freelinkN(&act->groups, agrp); + } + } + else { + BLI_remlink(&act->curves, fcu); + } + + /* if action has no more F-Curves as a result of this, unlink it from + * AnimData if it did not come from a NLA Strip being tweaked. + * + * This is done so that we don't have dangling Object+Action entries in + * channel list that are empty, and linger around long after the data they + * are for has disappeared (and probably won't come back). + */ + ANIM_remove_empty_action_from_animdata(adt); + } + + /* free the F-Curve itself */ + BKE_fcurve_free(fcu); +} + +bool ANIM_remove_empty_action_from_animdata(AnimData *adt) +{ + if (adt->action != nullptr) { + bAction *act = adt->action; + + if (BLI_listbase_is_empty(&act->curves) && (adt->flag & ADT_NLA_EDIT_ON) == 0) { + id_us_min(&act->id); + adt->action = nullptr; + return true; + } + } + + return false; +} + +/** \} */ + +} // namespace blender::animrig \ No newline at end of file diff --git a/source/blender/animrig/intern/fcurve.cc b/source/blender/animrig/intern/fcurve.cc index fdfdbb5a21f..a31559b530c 100644 --- a/source/blender/animrig/intern/fcurve.cc +++ b/source/blender/animrig/intern/fcurve.cc @@ -9,6 +9,7 @@ #include #include +#include "ANIM_animdata.hh" #include "ANIM_fcurve.hh" #include "BKE_fcurve.h" #include "DNA_anim_types.h" diff --git a/source/blender/animrig/intern/keyframing.cc b/source/blender/animrig/intern/keyframing.cc index 96ebfff525a..601cd1071f7 100644 --- a/source/blender/animrig/intern/keyframing.cc +++ b/source/blender/animrig/intern/keyframing.cc @@ -10,6 +10,7 @@ #include #include "ANIM_action.hh" +#include "ANIM_animdata.hh" #include "ANIM_fcurve.hh" #include "ANIM_keyframing.hh" #include "ANIM_rna.hh" @@ -32,7 +33,6 @@ #include "DEG_depsgraph.hh" #include "DEG_depsgraph_query.hh" #include "DNA_anim_types.h" -#include "ED_anim_api.hh" #include "ED_keyframing.hh" #include "MEM_guardedalloc.h" #include "RNA_access.hh" diff --git a/source/blender/animrig/intern/visualkey.cc b/source/blender/animrig/intern/visualkey.cc index 13a7823a679..34a6ea45e31 100644 --- a/source/blender/animrig/intern/visualkey.cc +++ b/source/blender/animrig/intern/visualkey.cc @@ -23,8 +23,6 @@ #include "DNA_object_types.h" #include "DNA_rigidbody_types.h" -#include "ED_keyframing.hh" - #include "RNA_access.hh" #include "RNA_prototypes.h" #include "RNA_types.hh" diff --git a/source/blender/editors/animation/anim_channels_edit.cc b/source/blender/editors/animation/anim_channels_edit.cc index 355b698f5cc..7c6c2f1a00d 100644 --- a/source/blender/editors/animation/anim_channels_edit.cc +++ b/source/blender/editors/animation/anim_channels_edit.cc @@ -46,7 +46,6 @@ #include "UI_interface.hh" #include "UI_view2d.hh" -#include "ED_anim_api.hh" #include "ED_armature.hh" #include "ED_keyframes_edit.hh" /* XXX move the select modes out of there! */ #include "ED_markers.hh" @@ -54,6 +53,8 @@ #include "ED_screen.hh" #include "ED_select_utils.hh" +#include "ANIM_animdata.hh" + #include "WM_api.hh" #include "WM_types.hh" @@ -857,82 +858,6 @@ void ANIM_frame_channel_y_extents(bContext *C, bAnimContext *ac) } /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Public F-Curves API - * \{ */ - -void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, AnimData *adt, FCurve *fcu) -{ - /* - if no AnimData, we've got nowhere to remove the F-Curve from - * (this doesn't guarantee that the F-Curve is in there, but at least we tried - * - if no F-Curve, there is nothing to remove - */ - if (ELEM(nullptr, adt, fcu)) { - return; - } - - /* remove from whatever list it came from - * - Action Group - * - Action - * - Drivers - * - TODO... some others? - */ - if ((ac) && (ac->datatype == ANIMCONT_DRIVERS)) { - /* driver F-Curve */ - BLI_remlink(&adt->drivers, fcu); - } - else if (adt->action) { - bAction *act = adt->action; - - /* remove from group or action, whichever one "owns" the F-Curve */ - if (fcu->grp) { - bActionGroup *agrp = fcu->grp; - - /* remove F-Curve from group+action */ - action_groups_remove_channel(act, fcu); - - /* if group has no more channels, remove it too, - * otherwise can have many dangling groups #33541. - */ - if (BLI_listbase_is_empty(&agrp->channels)) { - BLI_freelinkN(&act->groups, agrp); - } - } - else { - BLI_remlink(&act->curves, fcu); - } - - /* if action has no more F-Curves as a result of this, unlink it from - * AnimData if it did not come from a NLA Strip being tweaked. - * - * This is done so that we don't have dangling Object+Action entries in - * channel list that are empty, and linger around long after the data they - * are for has disappeared (and probably won't come back). - */ - ANIM_remove_empty_action_from_animdata(adt); - } - - /* free the F-Curve itself */ - BKE_fcurve_free(fcu); -} - -bool ANIM_remove_empty_action_from_animdata(AnimData *adt) -{ - if (adt->action != nullptr) { - bAction *act = adt->action; - - if (BLI_listbase_is_empty(&act->curves) && (adt->flag & ADT_NLA_EDIT_ON) == 0) { - id_us_min(&act->id); - adt->action = nullptr; - return true; - } - } - - return false; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Operator Utilities * \{ */ @@ -2211,7 +2136,7 @@ static int animchannels_delete_exec(bContext *C, wmOperator * /*op*/) FCurve *fcu = (FCurve *)ale->data; /* try to free F-Curve */ - ANIM_fcurve_delete_from_animdata(&ac, adt, fcu); + blender::animrig::ANIM_fcurve_delete_from_animdata(&ac, adt, fcu); tag_update_animation_element(ale); break; } diff --git a/source/blender/editors/animation/keyframes_general.cc b/source/blender/editors/animation/keyframes_general.cc index f1c1434bb15..94496024b13 100644 --- a/source/blender/editors/animation/keyframes_general.cc +++ b/source/blender/editors/animation/keyframes_general.cc @@ -34,10 +34,9 @@ #include "RNA_enum_types.hh" #include "RNA_path.hh" -#include "ED_anim_api.hh" #include "ED_keyframes_edit.hh" -#include "ED_keyframing.hh" +#include "ANIM_animdata.hh" #include "ANIM_fcurve.hh" /* This file contains code for various keyframe-editing tools which are 'destructive' @@ -229,7 +228,7 @@ void clean_fcurve(bAnimContext *ac, /* check if curve is really unused and if it is, return signal for deletion */ if (BKE_fcurve_is_empty(fcu)) { AnimData *adt = ale->adt; - ANIM_fcurve_delete_from_animdata(ac, adt, fcu); + blender::animrig::ANIM_fcurve_delete_from_animdata(ac, adt, fcu); ale->key_data = nullptr; } } diff --git a/source/blender/editors/animation/keyframing.cc b/source/blender/editors/animation/keyframing.cc index 41a912ad5cc..dd574e4e396 100644 --- a/source/blender/editors/animation/keyframing.cc +++ b/source/blender/editors/animation/keyframing.cc @@ -39,11 +39,11 @@ #include "DEG_depsgraph.hh" #include "DEG_depsgraph_build.hh" -#include "ED_keyframes_edit.hh" #include "ED_keyframing.hh" #include "ED_object.hh" #include "ED_screen.hh" +#include "ANIM_animdata.hh" #include "ANIM_bone_collections.h" #include "ANIM_fcurve.hh" #include "ANIM_keyframing.hh" @@ -628,14 +628,14 @@ static int clear_anim_v3d_exec(bContext *C, wmOperator * /*op*/) /* delete F-Curve completely */ if (can_delete) { - ANIM_fcurve_delete_from_animdata(nullptr, adt, fcu); + blender::animrig::ANIM_fcurve_delete_from_animdata(nullptr, adt, fcu); DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM); changed = true; } } /* Delete the action itself if it is empty. */ - if (ANIM_remove_empty_action_from_animdata(adt)) { + if (blender::animrig::ANIM_remove_empty_action_from_animdata(adt)) { changed = true; } } diff --git a/source/blender/editors/include/ED_anim_api.hh b/source/blender/editors/include/ED_anim_api.hh index 7ef2f2158d3..bfec6e8d9da 100644 --- a/source/blender/editors/include/ED_anim_api.hh +++ b/source/blender/editors/include/ED_anim_api.hh @@ -718,20 +718,6 @@ void ANIM_set_active_channel(bAnimContext *ac, */ bool ANIM_is_active_channel(bAnimListElem *ale); -/** - * Delete the F-Curve from the given AnimData block (if possible), - * as appropriate according to animation context. - */ -void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, AnimData *adt, FCurve *fcu); - -/** - * Unlink the action from animdata if it's empty. - * - * If the action has no F-Curves, unlink it from AnimData if it did not - * come from a NLA Strip being tweaked. - */ -bool ANIM_remove_empty_action_from_animdata(AnimData *adt); - /* ************************************************ */ /* DRAWING API */ /* `anim_draw.cc` */ diff --git a/source/blender/editors/space_action/action_edit.cc b/source/blender/editors/space_action/action_edit.cc index 00aa1419747..a07be36bb76 100644 --- a/source/blender/editors/space_action/action_edit.cc +++ b/source/blender/editors/space_action/action_edit.cc @@ -43,6 +43,7 @@ #include "UI_view2d.hh" +#include "ANIM_animdata.hh" #include "ANIM_fcurve.hh" #include "ANIM_keyframing.hh" #include "ED_anim_api.hh" @@ -1110,7 +1111,7 @@ static bool delete_action_keys(bAnimContext *ac) /* Only delete curve too if it won't be doing anything anymore */ if (BKE_fcurve_is_empty(fcu)) { - ANIM_fcurve_delete_from_animdata(ac, adt, fcu); + blender::animrig::ANIM_fcurve_delete_from_animdata(ac, adt, fcu); ale->key_data = nullptr; } } diff --git a/source/blender/editors/space_graph/graph_edit.cc b/source/blender/editors/space_graph/graph_edit.cc index 343b329a0b0..7eb058244a7 100644 --- a/source/blender/editors/space_graph/graph_edit.cc +++ b/source/blender/editors/space_graph/graph_edit.cc @@ -47,6 +47,7 @@ #include "UI_interface.hh" #include "UI_view2d.hh" +#include "ANIM_animdata.hh" #include "ANIM_fcurve.hh" #include "ANIM_keyframing.hh" #include "ED_anim_api.hh" @@ -765,7 +766,7 @@ static bool delete_graph_keys(bAnimContext *ac) /* Only delete curve too if it won't be doing anything anymore. */ if (BKE_fcurve_is_empty(fcu)) { - ANIM_fcurve_delete_from_animdata(ac, adt, fcu); + blender::animrig::ANIM_fcurve_delete_from_animdata(ac, adt, fcu); ale->key_data = nullptr; } }