Refactor: move keyingset enums to animrig #121132

Merged
Christoph Lendenfeld merged 1 commits from ChrisLend/blender:refactor_move_keyingset_enums into main 2024-05-02 12:00:50 +02:00
13 changed files with 101 additions and 60 deletions

View File

@ -0,0 +1,28 @@
/* SPDX-FileCopyrightText: 2024 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup animrig
*
* \brief Functionality to interact with keying sets.
*/
namespace blender::animrig {
/** Mode for modify_keyframes. */
enum class ModifyKeyMode {
INSERT = 0,
DELETE,
};
/** Return codes for errors (with Relative KeyingSets). */
enum class ModifyKeyReturn {
SUCCESS = 0,
/** Context info was invalid for using the Keying Set. */
INVALID_CONTEXT = -1,
/** There isn't any type-info for generating paths from context. */
MISSING_TYPEINFO = -2,
};
} // namespace blender::animrig

View File

@ -43,6 +43,7 @@ set(SRC
ANIM_evaluation.hh
ANIM_fcurve.hh
ANIM_keyframing.hh
ANIM_keyingsets.hh
ANIM_rna.hh
ANIM_visualkey.hh
intern/bone_collections_internal.hh

View File

@ -22,6 +22,7 @@
#include "ED_keyframing.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "WM_api.hh"
#include "WM_types.hh"
@ -127,7 +128,7 @@ void autokeyframe_object(bContext *C, Scene *scene, Object *ob, Span<std::string
* does not need to have its iterator overridden.
*/
ANIM_apply_keyingset(
C, &sources, active_ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
C, &sources, active_ks, ModifyKeyMode::INSERT, anim_eval_context.eval_time);
return;
}
@ -184,7 +185,7 @@ bool autokeyframe_object(bContext *C, Scene *scene, Object *ob, KeyingSet *ks)
*/
blender::Vector<PointerRNA> sources;
ANIM_relative_keyingset_add_source(sources, &ob->id);
ANIM_apply_keyingset(C, &sources, ks, MODIFYKEY_MODE_INSERT, BKE_scene_frame_get(scene));
ANIM_apply_keyingset(C, &sources, ks, ModifyKeyMode::INSERT, BKE_scene_frame_get(scene));
return true;
}
@ -202,7 +203,7 @@ bool autokeyframe_pchan(bContext *C, Scene *scene, Object *ob, bPoseChannel *pch
*/
blender::Vector<PointerRNA> sources;
ANIM_relative_keyingset_add_source(sources, &ob->id, &RNA_PoseBone, pchan);
ANIM_apply_keyingset(C, &sources, ks, MODIFYKEY_MODE_INSERT, BKE_scene_frame_get(scene));
ANIM_apply_keyingset(C, &sources, ks, ModifyKeyMode::INSERT, BKE_scene_frame_get(scene));
return true;
}
@ -255,7 +256,7 @@ void autokeyframe_pose_channel(bContext *C,
if (is_keying_flag(scene, AUTOKEY_FLAG_ONLYKEYINGSET) && (active_ks)) {
/* Run the active Keying Set on the current data-source. */
ANIM_apply_keyingset(
C, &sources, active_ks, MODIFYKEY_MODE_INSERT, anim_eval_context.eval_time);
C, &sources, active_ks, ModifyKeyMode::INSERT, anim_eval_context.eval_time);
return;
}

View File

@ -48,6 +48,7 @@
#include "ANIM_driver.hh"
#include "ANIM_fcurve.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "ANIM_rna.hh"
#include "UI_interface.hh"
@ -180,7 +181,8 @@ static int insert_key_with_keyingset(bContext *C, wmOperator *op, KeyingSet *ks)
}
/* try to insert keyframes for the channels specified by KeyingSet */
const int num_channels = ANIM_apply_keyingset(C, nullptr, ks, MODIFYKEY_MODE_INSERT, cfra);
const int num_channels = ANIM_apply_keyingset(
C, nullptr, ks, blender::animrig::ModifyKeyMode::INSERT, cfra);
if (G.debug & G_DEBUG) {
BKE_reportf(op->reports,
RPT_INFO,
@ -594,7 +596,8 @@ static int delete_key_using_keying_set(bContext *C, wmOperator *op, KeyingSet *k
const bool confirm = op->flag & OP_IS_INVOKE;
/* try to delete keyframes for the channels specified by KeyingSet */
num_channels = ANIM_apply_keyingset(C, nullptr, ks, MODIFYKEY_MODE_DELETE, cfra);
num_channels = ANIM_apply_keyingset(
C, nullptr, ks, blender::animrig::ModifyKeyMode::DELETE, cfra);
if (G.debug & G_DEBUG) {
printf("KeyingSet '%s' - Successfully removed %d Keyframes\n", ks->name, num_channels);
}

View File

@ -29,6 +29,8 @@
#include "DEG_depsgraph.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "ED_keyframing.hh"
#include "ED_screen.hh"
@ -928,17 +930,18 @@ void ANIM_relative_keyingset_add_source(blender::Vector<PointerRNA> &sources, ID
/* KeyingSet Operations (Insert/Delete Keyframes) ------------ */
eModifyKey_Returns ANIM_validate_keyingset(bContext *C,
blender::Vector<PointerRNA> *sources,
KeyingSet *keyingset)
blender::animrig::ModifyKeyReturn ANIM_validate_keyingset(bContext *C,
blender::Vector<PointerRNA> *sources,
KeyingSet *keyingset)
{
using namespace blender::animrig;
if (keyingset == nullptr) {
return MODIFYKEY_SUCCESS;
return ModifyKeyReturn::SUCCESS;
}
/* If relative Keying Sets, poll and build up the paths. */
if (keyingset->flag & KEYINGSET_ABSOLUTE) {
return MODIFYKEY_SUCCESS;
return ModifyKeyReturn::SUCCESS;
}
KeyingSetInfo *keyingset_info = ANIM_keyingset_info_find_name(keyingset->typeinfo);
@ -951,7 +954,7 @@ eModifyKey_Returns ANIM_validate_keyingset(bContext *C,
/* Get the associated 'type info' for this KeyingSet. */
if (keyingset_info == nullptr) {
return MODIFYKEY_MISSING_TYPEINFO;
return ModifyKeyReturn::MISSING_TYPEINFO;
}
/* TODO: check for missing callbacks! */
@ -959,7 +962,7 @@ eModifyKey_Returns ANIM_validate_keyingset(bContext *C,
if (!keyingset_info->poll(keyingset_info, C)) {
/* Poll callback tells us that KeyingSet is useless in current context. */
/* FIXME: the poll callback needs to give us more info why. */
return MODIFYKEY_INVALID_CONTEXT;
return ModifyKeyReturn::INVALID_CONTEXT;
}
/* If a list of data sources are provided, run a special iterator over them,
@ -976,10 +979,10 @@ eModifyKey_Returns ANIM_validate_keyingset(bContext *C,
/* FIXME: we need some error conditions (to be retrieved from the iterator why this failed!)
*/
if (BLI_listbase_is_empty(&keyingset->paths)) {
return MODIFYKEY_INVALID_CONTEXT;
return ModifyKeyReturn::INVALID_CONTEXT;
}
return MODIFYKEY_SUCCESS;
return ModifyKeyReturn::SUCCESS;
}
/* Determine which keying flags apply based on the override flags. */
@ -1017,7 +1020,7 @@ static int insert_key_to_keying_set_path(bContext *C,
KS_Path *keyingset_path,
KeyingSet *keyingset,
const eInsertKeyFlags insert_key_flags,
const eModifyKey_Modes mode,
const blender::animrig::ModifyKeyMode mode,
const float frame)
{
using namespace blender::animrig;
@ -1078,7 +1081,7 @@ static int insert_key_to_keying_set_path(bContext *C,
CombinedKeyingResult combined_result;
for (; array_index < array_length; array_index++) {
if (mode == MODIFYKEY_MODE_INSERT) {
if (mode == ModifyKeyMode::INSERT) {
CombinedKeyingResult result = insert_keyframe(bmain,
*keyingset_path->id,
groupname,
@ -1090,7 +1093,7 @@ static int insert_key_to_keying_set_path(bContext *C,
keyed_channels += result.get_count(SingleKeyingResult::SUCCESS);
combined_result.merge(result);
}
else if (mode == MODIFYKEY_MODE_DELETE) {
else if (mode == ModifyKeyMode::DELETE) {
keyed_channels += delete_keyframe(bmain,
reports,
keyingset_path->id,
@ -1128,32 +1131,33 @@ static int insert_key_to_keying_set_path(bContext *C,
int ANIM_apply_keyingset(bContext *C,
blender::Vector<PointerRNA> *sources,
KeyingSet *keyingset,
short mode,
float cfra)
const blender::animrig::ModifyKeyMode mode,
const float cfra)
{
using namespace blender::animrig;
if (keyingset == nullptr) {
return 0;
}
Scene *scene = CTX_data_scene(C);
const eInsertKeyFlags base_kflags = blender::animrig::get_keyframing_flags(scene);
const eInsertKeyFlags base_kflags = get_keyframing_flags(scene);
eInsertKeyFlags kflag = INSERTKEY_NOFLAGS;
if (mode == MODIFYKEY_MODE_INSERT) {
if (mode == ModifyKeyMode::INSERT) {
/* use context settings as base */
kflag = keyingset_apply_keying_flags(base_kflags,
eInsertKeyFlags(keyingset->keyingoverride),
eInsertKeyFlags(keyingset->keyingflag));
}
else if (mode == MODIFYKEY_MODE_DELETE) {
else if (mode == ModifyKeyMode::DELETE) {
kflag = INSERTKEY_NOFLAGS;
}
/* If relative Keying Sets, poll and build up the paths. */
{
const eModifyKey_Returns error = ANIM_validate_keyingset(C, sources, keyingset);
if (error != MODIFYKEY_SUCCESS) {
BLI_assert(error < 0);
return error;
const ModifyKeyReturn error = ANIM_validate_keyingset(C, sources, keyingset);
if (error != ModifyKeyReturn::SUCCESS) {
BLI_assert(int(error) < 0);
return int(error);
}
}
@ -1174,7 +1178,7 @@ int ANIM_apply_keyingset(bContext *C,
}
keyed_channels += insert_key_to_keying_set_path(
C, keyingset_path, keyingset, kflag, eModifyKey_Modes(mode), cfra);
C, keyingset_path, keyingset, kflag, mode, cfra);
}
/* Return the number of channels successfully affected. */

View File

@ -47,6 +47,7 @@
#include "ANIM_bone_collections.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "armature_intern.hh"
@ -155,7 +156,8 @@ static void poselib_keytag_pose(bContext *C, Scene *scene, PoseBlendData *pbd)
}
/* Perform actual auto-keying. */
ANIM_apply_keyingset(C, &sources, ks, MODIFYKEY_MODE_INSERT, float(scene->r.cfra));
ANIM_apply_keyingset(
C, &sources, ks, blender::animrig::ModifyKeyMode::INSERT, float(scene->r.cfra));
/* send notifiers for this */
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, nullptr);

View File

@ -49,6 +49,7 @@
#include "ANIM_bone_collections.hh"
#include "ANIM_bonecolor.hh"
#include "ANIM_keyingsets.hh"
#include "armature_intern.hh"
@ -976,7 +977,7 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex
BKE_report(reports, RPT_ERROR, "No active Keying Set to use");
return false;
}
if (ANIM_validate_keyingset(C, nullptr, ks) != 0) {
if (ANIM_validate_keyingset(C, nullptr, ks) != blender::animrig::ModifyKeyReturn::SUCCESS) {
if (ks->paths.first == nullptr) {
if ((ks->flag & KEYINGSET_ABSOLUTE) == 0) {
BKE_report(reports,

View File

@ -48,6 +48,7 @@
#include "ANIM_bone_collections.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
@ -1228,7 +1229,8 @@ static int pose_clear_transform_generic_exec(bContext *C,
KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, default_ksName);
/* insert keyframes */
ANIM_apply_keyingset(C, &sources, ks, MODIFYKEY_MODE_INSERT, float(scene->r.cfra));
ANIM_apply_keyingset(
C, &sources, ks, blender::animrig::ModifyKeyMode::INSERT, float(scene->r.cfra));
/* now recalculate paths */
if (ob_iter->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) {

View File

@ -37,6 +37,7 @@
#include "ED_keyframing.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "armature_intern.hh"
@ -293,7 +294,7 @@ void poseAnim_mapping_autoKeyframe(bContext *C, Scene *scene, ListBase *pfLinks,
}
/* insert keyframes for all relevant bones in one go */
ANIM_apply_keyingset(C, &sources, ks, MODIFYKEY_MODE_INSERT, cframe);
ANIM_apply_keyingset(C, &sources, ks, blender::animrig::ModifyKeyMode::INSERT, cframe);
/* do the bone paths
* - only do this if keyframes should have been added

View File

@ -35,6 +35,11 @@ struct PropertyRNA;
struct NlaKeyframingContext;
namespace blender::animrig {
enum class ModifyKeyReturn;
enum class ModifyKeyMode;
} // namespace blender::animrig
/* -------------------------------------------------------------------- */
/** \name Key-Framing Management
* \{ */
@ -123,21 +128,6 @@ void ANIM_relative_keyingset_add_source(blender::Vector<PointerRNA> &sources,
void *data);
void ANIM_relative_keyingset_add_source(blender::Vector<PointerRNA> &sources, ID *id);
/** Mode for modify_keyframes. */
enum eModifyKey_Modes {
MODIFYKEY_MODE_INSERT = 0,
MODIFYKEY_MODE_DELETE,
};
/** Return codes for errors (with Relative KeyingSets). */
enum eModifyKey_Returns {
MODIFYKEY_SUCCESS = 0,
/** Context info was invalid for using the Keying Set. */
MODIFYKEY_INVALID_CONTEXT = -1,
/** There isn't any type-info for generating paths from context. */
MODIFYKEY_MISSING_TYPEINFO = -2,
};
/**
* Given a #KeyingSet and context info, validate Keying Set's paths.
* This is only really necessary with relative/built-in KeyingSets
@ -148,9 +138,9 @@ enum eModifyKey_Returns {
*
* \return 0 if succeeded, otherwise an error code: #eModifyKey_Returns.
*/
eModifyKey_Returns ANIM_validate_keyingset(bContext *C,
blender::Vector<PointerRNA> *sources,
KeyingSet *ks);
blender::animrig::ModifyKeyReturn ANIM_validate_keyingset(bContext *C,
blender::Vector<PointerRNA> *sources,
KeyingSet *ks);
/**
* Use the specified #KeyingSet and context info (if required)
@ -162,8 +152,11 @@ eModifyKey_Returns ANIM_validate_keyingset(bContext *C,
* \returns the number of channels that key-frames were added or
* an #eModifyKey_Returns value (always a negative number).
*/
int ANIM_apply_keyingset(
bContext *C, blender::Vector<PointerRNA> *sources, KeyingSet *ks, short mode, float cfra);
int ANIM_apply_keyingset(bContext *C,
blender::Vector<PointerRNA> *sources,
KeyingSet *ks,
blender::animrig::ModifyKeyMode mode,
float cfra);
/* -------- */

View File

@ -54,6 +54,7 @@
#include "ED_select_utils.hh"
#include "ANIM_bone_collections.hh"
#include "ANIM_keyingsets.hh"
#include "UI_interface.hh"
#include "UI_resources.hh"
@ -961,7 +962,7 @@ static bool select_grouped_keyingset(bContext *C, Object * /*ob*/, ReportList *r
BKE_report(reports, RPT_ERROR, "No active Keying Set to use");
return false;
}
if (ANIM_validate_keyingset(C, nullptr, ks) != 0) {
if (ANIM_validate_keyingset(C, nullptr, ks) != blender::animrig::ModifyKeyReturn::SUCCESS) {
if (ks->paths.first == nullptr) {
if ((ks->flag & KEYINGSET_ABSOLUTE) == 0) {
BKE_report(reports,

View File

@ -49,6 +49,7 @@
#include "ED_view3d.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_keyingsets.hh"
#include "UI_resources.hh"
@ -637,7 +638,8 @@ bool ED_view3d_camera_lock_sync(const Depsgraph *depsgraph, View3D *v3d, RegionV
bool ED_view3d_camera_autokey(
const Scene *scene, ID *id_key, bContext *C, const bool do_rotate, const bool do_translate)
{
if (blender::animrig::autokeyframe_cfra_can_key(scene, id_key)) {
using namespace blender::animrig;
if (autokeyframe_cfra_can_key(scene, id_key)) {
const float cfra = float(scene->r.cfra);
blender::Vector<PointerRNA> sources;
/* add data-source override for the camera object */
@ -650,11 +652,11 @@ bool ED_view3d_camera_autokey(
*/
if (do_rotate) {
KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_ROTATION_ID);
ANIM_apply_keyingset(C, &sources, ks, MODIFYKEY_MODE_INSERT, cfra);
ANIM_apply_keyingset(C, &sources, ks, ModifyKeyMode::INSERT, cfra);
}
if (do_translate) {
KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOCATION_ID);
ANIM_apply_keyingset(C, &sources, ks, MODIFYKEY_MODE_INSERT, cfra);
ANIM_apply_keyingset(C, &sources, ks, ModifyKeyMode::INSERT, cfra);
}
return true;

View File

@ -24,23 +24,25 @@
# include "BKE_nla.h"
# include "BKE_report.hh"
# include "ANIM_keyingsets.hh"
# include "ED_keyframing.hh"
static void rna_KeyingSet_context_refresh(KeyingSet *ks, bContext *C, ReportList *reports)
{
using namespace blender::animrig;
/* TODO: enable access to providing a list of overrides (dsources)? */
const eModifyKey_Returns error = ANIM_validate_keyingset(C, nullptr, ks);
const ModifyKeyReturn error = ANIM_validate_keyingset(C, nullptr, ks);
if (error == MODIFYKEY_SUCCESS) {
if (error == ModifyKeyReturn::SUCCESS) {
return;
}
switch (error) {
case MODIFYKEY_INVALID_CONTEXT:
case ModifyKeyReturn::INVALID_CONTEXT:
BKE_report(reports, RPT_ERROR, "Invalid context for keying set");
break;
case MODIFYKEY_MISSING_TYPEINFO:
case ModifyKeyReturn::MISSING_TYPEINFO:
BKE_report(
reports, RPT_ERROR, "Incomplete built-in keying set, appears to be missing type info");
break;