From 145af8d45b83acdf2bd99855953ad371ec71bb5d Mon Sep 17 00:00:00 2001 From: Christoph Lendenfeld Date: Tue, 22 Apr 2025 10:28:39 +0200 Subject: [PATCH] Refactor: Add function to query editable Graph Editor curves No functional changes intended. This patch extracts functionality to get all `bAnimListElem` that are editable in the Graph Editor into a separate function so it can be re-used by other operators. This makes it easy to ensure the same data is retrieved and filter flags can't go out of sync. Extracted from #135913 Part of: #135794 Pull Request: https://projects.blender.org/blender/blender/pulls/137142 --- .../editors/space_graph/CMakeLists.txt | 2 ++ .../editors/space_graph/ED_space_graph.hh | 21 ++++++++++++++++ .../blender/editors/space_graph/graph_edit.cc | 15 +++++------- .../editors/space_graph/graph_query.cc | 24 +++++++++++++++++++ 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 source/blender/editors/space_graph/ED_space_graph.hh create mode 100644 source/blender/editors/space_graph/graph_query.cc diff --git a/source/blender/editors/space_graph/CMakeLists.txt b/source/blender/editors/space_graph/CMakeLists.txt index 4f1286d1231..d1ad624054e 100644 --- a/source/blender/editors/space_graph/CMakeLists.txt +++ b/source/blender/editors/space_graph/CMakeLists.txt @@ -22,9 +22,11 @@ set(SRC graph_slider_ops.cc graph_utils.cc graph_view.cc + graph_query.cc space_graph.cc graph_intern.hh + ED_space_graph.hh ) set(LIB diff --git a/source/blender/editors/space_graph/ED_space_graph.hh b/source/blender/editors/space_graph/ED_space_graph.hh new file mode 100644 index 00000000000..6027c896044 --- /dev/null +++ b/source/blender/editors/space_graph/ED_space_graph.hh @@ -0,0 +1,21 @@ +/* SPDX-FileCopyrightText: 2025 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "BLI_vector.hh" + +struct bAnimContext; +struct ListBase; + +namespace blender::ed::graph { + +/** + * Return all bAnimListElem for which the keyframes are visible in the + * GUI. This excludes FCurves that are drawn as curves but whose keyframes are NOT shown. + * All entries of the list will be of type ANIMTYPE_FCURVE. + * + * The listbase will have to be freed by the caller with ANIM_animdata_freelist; + */ +ListBase get_editable_fcurves(bAnimContext &ac); + +} // namespace blender::ed::graph diff --git a/source/blender/editors/space_graph/graph_edit.cc b/source/blender/editors/space_graph/graph_edit.cc index 5562ccda11c..43becd828e6 100644 --- a/source/blender/editors/space_graph/graph_edit.cc +++ b/source/blender/editors/space_graph/graph_edit.cc @@ -56,6 +56,7 @@ #include "ED_keyframing.hh" #include "ED_markers.hh" #include "ED_screen.hh" +#include "ED_space_graph.hh" #include "ED_transform.hh" #include "WM_api.hh" @@ -2274,15 +2275,11 @@ static wmOperatorStatus keyframe_jump_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - ListBase anim_data = {nullptr, nullptr}; - int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_FCURVESONLY | - ANIMFILTER_NODUPLIS); - if (U.animation_flag & USER_ANIM_ONLY_SHOW_SELECTED_CURVE_KEYS) { - filter |= ANIMFILTER_SEL; - } + ListBase anim_data = blender::ed::graph::get_editable_fcurves(ac); - ANIM_animdata_filter( - &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype)); + if (BLI_listbase_is_empty(&anim_data)) { + return OPERATOR_CANCELLED; + } float closest_frame = next ? FLT_MAX : -FLT_MAX; bool found = false; @@ -2323,7 +2320,7 @@ static wmOperatorStatus keyframe_jump_exec(bContext *C, wmOperator *op) DEG_id_tag_update(&scene->id, ID_RECALC_FRAME_CHANGE); /* Set notifier that things have changed. */ - WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene); + WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_graph/graph_query.cc b/source/blender/editors/space_graph/graph_query.cc new file mode 100644 index 00000000000..d8aefad4a3f --- /dev/null +++ b/source/blender/editors/space_graph/graph_query.cc @@ -0,0 +1,24 @@ +/* SPDX-FileCopyrightText: 2025 Blender Authors + * + * SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "BLI_listbase.h" +#include "ED_anim_api.hh" +#include "ED_space_graph.hh" + +namespace blender::ed::graph { + +ListBase get_editable_fcurves(bAnimContext &ac) +{ + ListBase anim_data = {nullptr, nullptr}; + eAnimFilter_Flags filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | + ANIMFILTER_FCURVESONLY | ANIMFILTER_NODUPLIS); + if (U.animation_flag & USER_ANIM_ONLY_SHOW_SELECTED_CURVE_KEYS) { + filter |= ANIMFILTER_SEL; + } + + ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, eAnimCont_Types(ac.datatype)); + return anim_data; +} + +} // namespace blender::ed::graph