Blender V5.3
action_legacy.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "ANIM_action.hh"
10#include "ANIM_action_legacy.hh"
11
13
14#include "BKE_fcurve.hh"
15
16#include "BLT_translation.hh"
17
19
20/* Lots of template args to support transparent non-const and const versions. */
21template<typename ActionType,
22 typename FCurveType,
23 typename LayerType,
24 typename StripType,
25 typename StripKeyframeDataType,
26 typename ChannelbagType>
28{
29 Vector<FCurveType *> all_fcurves;
30 for (LayerType *layer : action.layers()) {
31 for (StripType *strip : layer->strips()) {
32 switch (strip->type()) {
34 StripKeyframeDataType &strip_data = strip->template data<StripKeyframeData>(action);
35 for (ChannelbagType *bag : strip_data.channelbags()) {
36 for (FCurveType *fcurve : bag->fcurves()) {
37 all_fcurves.append(fcurve);
38 }
39 }
40 }
41 }
42 }
43 }
44 return all_fcurves;
45}
46
48{
49 if (!action) {
50 return {};
51 }
53 action->wrap());
54}
55
57{
58 if (!action) {
59 return {};
60 }
61 return fcurves_all_templated<const Action,
62 const FCurve,
63 const Layer,
64 const Strip,
66 const Channelbag>(action->wrap());
67}
68
69/* Lots of template args to support transparent non-const and const versions. */
70template<typename ActionType,
71 typename FCurveType,
72 typename LayerType,
73 typename StripType,
74 typename StripKeyframeDataType,
75 typename ChannelbagType>
77 const slot_handle_t slot_handle)
78{
79 Vector<FCurveType *> as_vector(animrig::fcurves_for_action_slot(action, slot_handle));
80 return as_vector;
81}
82
84{
85 if (adt == nullptr || adt->action == nullptr) {
86 return false;
87 }
88
89 Action &action = adt->action->wrap();
90 return action.has_keyframes(adt->slot_handle);
91}
92
94{
95 if (!action) {
96 return {};
97 }
98
99 Action &action_wrap = action->wrap();
100 Vector<bActionGroup *> all_groups;
101 for (Layer *layer : action_wrap.layers()) {
102 for (Strip *strip : layer->strips()) {
103 switch (strip->type()) {
105 StripKeyframeData &strip_data = strip->template data<StripKeyframeData>(action_wrap);
106 for (Channelbag *bag : strip_data.channelbags()) {
107 all_groups.extend(bag->channel_groups());
108 }
109 }
110 }
111 }
112 }
113 return all_groups;
114}
115
117{
118 if (!adt || !adt->action) {
119 return {};
120 }
121
122 Action &action = adt->action->wrap();
124 if (!bag) {
125 return {};
126 }
127
128 Vector<bActionGroup *> slot_groups(bag->channel_groups());
129 return slot_groups;
130}
131
133 const slot_handle_t slot_handle,
134 const StringRefNull rna_path_prefix)
135{
136 BLI_assert(!rna_path_prefix.is_empty());
137 if (rna_path_prefix.is_empty()) {
138 return false;
139 }
140
141 Channelbag *bag = channelbag_for_action_slot(action.wrap(), slot_handle);
142 if (!bag) {
143 return false;
144 }
145
146 bool any_removed = false;
147 for (int64_t fcurve_index = 0; fcurve_index < bag->fcurve_array_num; fcurve_index++) {
148 FCurve *fcurve = bag->fcurve(fcurve_index);
149 const StringRefNull rna_path = fcurve->rna_path();
150 if (rna_path.is_empty()) {
151 continue;
152 }
153
154 if (rna_path.startswith(rna_path_prefix)) {
155 bag->fcurve_remove_by_index(fcurve_index);
156 fcurve_index--;
157 any_removed = true;
158 }
159 }
160 return any_removed;
161}
162
163} // namespace blender::animrig::legacy
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
void append(const T &value)
void extend(Span< T > array)
bool has_keyframes(slot_handle_t action_slot_handle) const ATTR_WARN_UNUSED_RESULT
Span< const Layer * > layers() const
const FCurve * fcurve(int64_t index) const
void fcurve_remove_by_index(int64_t fcurve_index)
Span< const bActionGroup * > channel_groups() const
Span< const Channelbag * > channelbags() const
constexpr bool is_empty() const
#define layer
static Vector< FCurveType * > fcurves_all_templated(ActionType &action)
Vector< bActionGroup * > channel_groups_for_assigned_slot(AnimData *adt)
Vector< const FCurve * > fcurves_all(const bAction *action)
bool action_fcurves_remove(bAction &action, slot_handle_t slot_handle, StringRefNull rna_path_prefix)
bool assigned_action_has_keyframes(AnimData *adt)
Vector< bActionGroup * > channel_groups_all(bAction *action)
static Vector< FCurveType * > fcurves_for_action_slot_templated(ActionType &action, const slot_handle_t slot_handle)
decltype(blender::ActionSlot::handle) slot_handle_t
const animrig::Channelbag * channelbag_for_action_slot(const Action &action, slot_handle_t slot_handle)
Span< FCurve * > fcurves_for_action_slot(Action &action, slot_handle_t slot_handle)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
BMesh const char void * data