Refactor: Move code related to animdata to animrig #114581

Merged
Christoph Lendenfeld merged 4 commits from ChrisLend/blender:refactor_ed_include into main 2023-11-07 16:46:46 +01:00
12 changed files with 142 additions and 103 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -9,6 +9,7 @@
#include <cmath>
#include <string.h>
#include "ANIM_animdata.hh"
#include "ANIM_fcurve.hh"
#include "BKE_fcurve.h"
#include "DNA_anim_types.h"

View File

@ -10,6 +10,7 @@
#include <cmath>
#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"

View File

@ -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"

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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` */

View File

@ -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;
}
}

View File

@ -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;
}
}