Blender V5.3
anim_deps.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_anim_types.h"
14#include "DNA_armature_types.h"
17#include "DNA_mask_types.h"
18#include "DNA_object_types.h"
19#include "DNA_scene_types.h"
20#include "DNA_sequence_types.h"
21#include "DNA_space_types.h"
23
24#include "BLI_listbase.hh"
25#include "BLI_set.hh"
26#include "BLI_string.hh"
27#include "BLI_utildefines.hh"
28
29#include "BKE_action.hh"
30#include "BKE_anim_data.hh"
31#include "BKE_annotations.h"
32#include "BKE_context.hh"
33#include "BKE_fcurve.hh"
34#include "BKE_grease_pencil.hh"
35#include "BKE_screen.hh"
36#include "BKE_workspace.hh"
37
38#include "DEG_depsgraph.hh"
39
40#include "RNA_access.hh"
41#include "RNA_path.hh"
42
43#include "SEQ_sequencer.hh"
44#include "SEQ_utils.hh"
45
46#include "ED_anim_api.hh"
47
48#include "ANIM_action.hh"
49
50namespace blender {
51
52/* **************************** depsgraph tagging ******************************** */
53
55{
56 ID *id;
57 FCurve *fcu;
58 AnimData *adt;
59
60 id = ale->id;
61 if (!id) {
62 return;
63 }
64
65 /* tag AnimData for refresh so that other views will update in realtime with these changes */
66 adt = BKE_animdata_from_id(id);
67 if (adt) {
69 if (adt->action != nullptr) {
71 }
72 }
73
74 /* Tag copy on the main object if updating anything directly inside AnimData */
76 {
78 return;
79 }
80
81 /* update data */
82 fcu = static_cast<FCurve *>((ale->datatype == ALE_FCURVE) ? ale->key_data : nullptr);
83
84 if (fcu && !fcu->rna_path().is_empty()) {
85 /* If we have an fcurve, call the update for the property we
86 * are editing, this is then expected to do the proper redraws
87 * and depsgraph updates. */
88 PointerRNA ptr;
89 PropertyRNA *prop;
90
92
93 if (RNA_path_resolve_property(&id_ptr, fcu->rna_path_parsed(), &ptr, &prop)) {
94 RNA_property_update_main(bmain, scene, &ptr, prop);
95 }
96 }
97 else {
98 /* in other case we do standard depsgraph update, ideally
99 * we'd be calling property update functions here too ... */
100 DEG_id_tag_update(id, /* XXX: or do we want something more restrictive? */
102 }
103}
104
105void ANIM_id_update(Main *bmain, ID *id)
106{
107 if (id) {
109 id, /* XXX: or do we want something more restrictive? */
111 }
112}
113
114/* **************************** animation data <-> data syncing ******************************** */
115/* This code here is used to synchronize the
116 * - selection (to find selected data easier)
117 * - ... (insert other relevant items here later)
118 * status in relevant Blender data with the status stored in animation channels.
119 *
120 * This should be called in the refresh() callbacks for various editors in
121 * response to appropriate notifiers.
122 */
123
124/* perform syncing updates for Action Groups */
125static void animchan_sync_group(bAnimContext *ac, bAnimListElem *ale, bActionGroup **active_agrp)
126{
127 bActionGroup *agrp = static_cast<bActionGroup *>(ale->data);
128 ID *owner_id = ale->id;
129
130 /* major priority is selection status
131 * so we need both a group and an owner
132 */
133 if (ELEM(nullptr, agrp, owner_id)) {
134 return;
135 }
136
137 /* for standard Objects, check if group is the name of some bone */
138 if (GS(owner_id->name) == ID_OB) {
139 Object *ob = reinterpret_cast<Object *>(owner_id);
140
141 /* check if there are bones, and whether the name matches any
142 * NOTE: this feature will only really work if groups by default contain the F-Curves
143 * for a single bone.
144 */
145 if (ob->pose) {
147
148 if (pchan) {
149 Bone *bone = pchan->bone_get(*ob);
150 /* if one matches, sync the selection status */
151 if (bone && (pchan->flag & POSE_SELECTED)) {
152 agrp->flag |= AGRP_SELECTED;
153 }
154 else {
155 agrp->flag &= ~AGRP_SELECTED;
156 }
157
158 /* also sync active group status */
159 bArmature *arm = id_cast<bArmature *>(ob->data);
160 if ((ob == ac->obact) && (bone == arm->act_bone)) {
161 /* if no previous F-Curve has active flag, then we're the first and only one to get it */
162 if (*active_agrp == nullptr) {
163 agrp->flag |= AGRP_ACTIVE;
164 *active_agrp = agrp;
165 }
166 else {
167 /* someone else has already taken it - set as not active */
168 agrp->flag &= ~AGRP_ACTIVE;
169 }
170 }
171 else {
172 /* this can't possibly be active now */
173 agrp->flag &= ~AGRP_ACTIVE;
174 }
175
176 /* sync bone color */
177 action_group_colors_set_from_posebone(agrp, {pchan, bone});
178 }
179 }
180 }
181}
182
184{
185 ID *owner_id = ale->id;
186 BLI_assert(GS(owner_id->name) == ID_SCE);
187 Scene *scene = reinterpret_cast<Scene *>(owner_id);
188 FCurve *fcu = static_cast<FCurve *>(ale->data);
189 Strip *strip = nullptr;
190
191 /* Only affect if F-Curve involves sequence_editor.strips. */
192 char strip_name[sizeof(strip->name)];
194 fcu->rna_path().c_str(), "strips_all[", strip_name, sizeof(strip_name)))
195 {
196 return;
197 }
198
199 /* Check if this strip is selected. */
200 Editing *ed = seq::editing_get(scene);
201 if (ed == nullptr) {
202 /* The existence of the F-Curve doesn't imply the existence of the sequencer
203 * strip, or even the sequencer itself. */
204 return;
205 }
206 strip = seq::get_strip_by_name(ed->current_strips(), strip_name, false);
207 if (strip == nullptr) {
208 return;
209 }
210
211 /* update selection status */
212 if (strip->flag & SEQ_SELECT) {
213 fcu->flag |= FCURVE_SELECTED;
214 }
215 else {
216 fcu->flag &= ~FCURVE_SELECTED;
217 }
218}
219
220/* perform syncing updates for F-Curves */
222{
223 FCurve *fcu = static_cast<FCurve *>(ale->data);
224 ID *owner_id = ale->id;
225
226 /* major priority is selection status, so refer to the checks done in `anim_filter.cc`
227 * #skip_fcurve_selected_data() for reference about what's going on here.
228 */
229 if (ELEM(nullptr, fcu, owner_id)) {
230 return;
231 }
232
233 if (fcu->rna_path().is_empty()) {
234 return;
235 }
236
237 switch (GS(owner_id->name)) {
238 case ID_SCE:
240 break;
241 default:
242 break;
243 }
244}
245
246/* perform syncing updates for GPencil Layers */
248{
249 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale->data);
250
251 /* Make sure the selection flags agree with the "active" flag.
252 * The selection flags are used in the Dope-sheet only, whereas
253 * the active flag is used everywhere else. Hence, we try to
254 * sync these here so that it all seems to be have as the user
255 * expects - #50184
256 *
257 * Assume that we only really do this when the active status changes.
258 * (NOTE: This may prove annoying if it means selection is always lost)
259 */
260 if (gpl->flag & GP_LAYER_ACTIVE) {
261 gpl->flag |= GP_LAYER_SELECT;
262 }
263 else {
264 gpl->flag &= ~GP_LAYER_SELECT;
265 }
266}
267
268/* ---------------- */
269
271{
272 bAnimContext ac;
273 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
274 int filter;
275
276 bActionGroup *active_agrp = nullptr;
277
278 /* get animation context info for filtering the channels */
279 if (ANIM_animdata_get_context(C, &ac) == 0) {
280 return;
281 }
282
283 /* filter data */
284
285 /* NOTE: we want all channels, since we want to be able to set selection status on some of them
286 * even when collapsed... however,
287 * don't include duplicates so that selection statuses don't override each other.
288 */
291 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
292
293 /* flush settings as appropriate depending on the types of the channels */
294 for (bAnimListElem &ale : anim_data) {
295 switch (ale.type) {
296 case ANIMTYPE_GROUP:
297 animchan_sync_group(&ac, &ale, &active_agrp);
298 break;
299
300 case ANIMTYPE_FCURVE:
302 break;
303
304 case ANIMTYPE_GPLAYER:
306 break;
308 using namespace blender::bke::greasepencil;
309 GreasePencil *grease_pencil = reinterpret_cast<GreasePencil *>(ale.id);
310 Layer *layer = static_cast<Layer *>(ale.data);
311 layer->set_selected(grease_pencil->is_layer_active(layer));
312 break;
313 }
314
315 case ANIMTYPE_NONE:
318 case ANIMTYPE_SUMMARY:
319 case ANIMTYPE_SCENE:
320 case ANIMTYPE_OBJECT:
327 case ANIMTYPE_DSMAT:
328 case ANIMTYPE_DSLAM:
329 case ANIMTYPE_DSCAM:
331 case ANIMTYPE_DSCUR:
332 case ANIMTYPE_DSSKEY:
333 case ANIMTYPE_DSWOR:
334 case ANIMTYPE_DSNTREE:
335 case ANIMTYPE_DSPART:
336 case ANIMTYPE_DSMBALL:
337 case ANIMTYPE_DSARM:
338 case ANIMTYPE_DSMESH:
339 case ANIMTYPE_DSTEX:
340 case ANIMTYPE_DSLAT:
342 case ANIMTYPE_DSSPK:
344 case ANIMTYPE_DSMCLIP:
345 case ANIMTYPE_DSHAIR:
356 case ANIMTYPE_PALETTE:
358 break;
359 }
360 }
361
362 ANIM_animdata_freelist(&anim_data);
363}
364
365void ANIM_animdata_update(bAnimContext *ac, ListBaseT<bAnimListElem> *anim_data)
366{
367 for (bAnimListElem &ale : *anim_data) {
368 if (ale.type == ANIMTYPE_GPLAYER) {
369 bGPDlayer *gpl = static_cast<bGPDlayer *>(ale.data);
370
371 if (ale.update & ANIM_UPDATE_ORDER) {
372 ale.update &= ~ANIM_UPDATE_ORDER;
373 if (gpl) {
375 }
376 }
377
378 if (ale.update & ANIM_UPDATE_DEPS) {
379 ale.update &= ~ANIM_UPDATE_DEPS;
380 ANIM_list_elem_update(ac->bmain, ac->scene, &ale);
381 }
382 /* disable handles to avoid crash */
383 if (ale.update & ANIM_UPDATE_HANDLES) {
384 ale.update &= ~ANIM_UPDATE_HANDLES;
385 }
386 }
387 else if (ale.datatype == ALE_MASKLAY) {
388 MaskLayer *masklay = static_cast<MaskLayer *>(ale.data);
389
390 if (ale.update & ANIM_UPDATE_ORDER) {
391 ale.update &= ~ANIM_UPDATE_ORDER;
392 if (masklay) {
393 /* While correct & we could enable it: 'posttrans_mask_clean' currently
394 * both sorts and removes doubles, so this is not necessary here. */
395 // BKE_mask_layer_shape_sort(masklay);
396 }
397 }
398
399 if (ale.update & ANIM_UPDATE_DEPS) {
400 ale.update &= ~ANIM_UPDATE_DEPS;
401 ANIM_list_elem_update(ac->bmain, ac->scene, &ale);
402 }
403 /* Disable handles to avoid assert. */
404 if (ale.update & ANIM_UPDATE_HANDLES) {
405 ale.update &= ~ANIM_UPDATE_HANDLES;
406 }
407 }
408 else if (ale.datatype == ALE_FCURVE) {
409 FCurve *fcu = static_cast<FCurve *>(ale.key_data);
410
411 if (ale.update & ANIM_UPDATE_ORDER) {
412 ale.update &= ~ANIM_UPDATE_ORDER;
413 if (fcu) {
414 sort_time_fcurve(*fcu);
415 }
416 }
417
418 if (ale.update & ANIM_UPDATE_HANDLES) {
419 ale.update &= ~ANIM_UPDATE_HANDLES;
420 if (fcu) {
422 }
423 }
424
425 if (ale.update & ANIM_UPDATE_DEPS) {
426 ale.update &= ~ANIM_UPDATE_DEPS;
427 ANIM_list_elem_update(ac->bmain, ac->scene, &ale);
428 }
429 }
430 else if (ELEM(ale.type,
435 {
436 if (ale.update & ANIM_UPDATE_DEPS) {
437 ale.update &= ~ANIM_UPDATE_DEPS;
438 ANIM_list_elem_update(ac->bmain, ac->scene, &ale);
439 }
440 }
441 else if (ELEM(ale.type,
445 {
446 if (ale.update & ANIM_UPDATE_DEPS) {
447 ale.update &= ~ANIM_UPDATE_DEPS;
448 ANIM_list_elem_update(ac->bmain, ac->scene, &ale);
449 }
450 /* Order appears to be already handled in `grease_pencil_layer_apply_trans_data` when
451 * translating. */
452 ale.update &= ~(ANIM_UPDATE_HANDLES | ANIM_UPDATE_ORDER);
453 }
454 else if (ale.update) {
455#if 0
456 if (G.debug & G_DEBUG) {
457 printf("%s: Unhandled animchannel updates (%d) for type=%d (%p)\n",
458 __func__,
459 ale->update,
460 ale->type,
461 ale->data);
462 }
463#endif
464 /* Prevent crashes in cases where it can't be handled */
465 ale.update = eAnim_Update_Flags(0);
466 }
467
468 BLI_assert(ale.update == 0);
469 }
470}
471
472void ANIM_animdata_freelist(ListBaseT<bAnimListElem> *anim_data)
473{
474#ifndef NDEBUG
475 bAnimListElem *ale, *ale_next;
476 for (ale = anim_data->first(); ale; ale = ale_next) {
477 ale_next = ale->next;
478 BLI_assert(ale->update == 0);
479 MEM_delete(ale);
480 }
481 anim_data->clear_no_delete();
482#else
483 anim_data->free_no_destruct();
484#endif
485}
486
488{
489 wmWindow *ctx_window = CTX_wm_window(C);
490 ScrArea *ctx_area = CTX_wm_area(C);
491 ARegion *ctx_region = CTX_wm_region(C);
492
493 Set<bAction *> dna_actions;
494 for (wmWindow &win : CTX_wm_manager(C)->windows) {
495 bScreen *screen = BKE_workspace_active_screen_get(win.workspace_hook);
496
497 for (ScrArea &area : screen->areabase) {
498 if (!ELEM(area.spacetype, SPACE_GRAPH, SPACE_ACTION)) {
499 continue;
500 }
501 ARegion *window_region = BKE_area_find_region_type(&area, RGN_TYPE_WINDOW);
502
503 if (!window_region) {
504 continue;
505 }
506
507 CTX_wm_window_set(C, &win);
508 CTX_wm_area_set(C, &area);
509 CTX_wm_region_set(C, window_region);
510 bAnimContext ac;
511 if (!ANIM_animdata_get_context(C, &ac)) {
512 continue;
513 }
514 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
516 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, eAnimCont_Types(ac.datatype));
517 for (bAnimListElem &ale : anim_data) {
518 if (!ale.adt || !ale.adt->action) {
519 continue;
520 }
521 dna_actions.add(ale.adt->action);
522 }
523 ANIM_animdata_freelist(&anim_data);
524 }
525 }
526
527 CTX_wm_window_set(C, ctx_window);
528 CTX_wm_area_set(C, ctx_area);
529 CTX_wm_region_set(C, ctx_region);
530
531 for (bAction *dna_action : dna_actions) {
532 animrig::action_deselect_keys(dna_action->wrap());
533 }
534}
535
536} // namespace blender
Functions and classes to work with Actions.
Blender kernel action and pose functionality.
Low-level operations for grease pencil.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ELEM(...)
bool add(const Key &key)
Definition BLI_set.hh:248
#define layer
void action_deselect_keys(Action &action)
Editing * editing_get(const Scene *scene)
Definition sequencer.cc:304
Strip * get_strip_by_name(ListBaseT< Strip > *seqbase, const char *name, bool recursive)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void animchan_sync_fcurve_scene(bAnimListElem *ale)
Definition anim_deps.cc:183
ScrArea * CTX_wm_area(const bContext *C)
bool bool BLI_str_quoted_substr(const char *__restrict str, const char *__restrict prefix, char *result, size_t result_maxncpy)
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
PointerRNA RNA_id_pointer_create(ID *id)
void CTX_wm_window_set(bContext *C, wmWindow *win)
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
static void animchan_sync_fcurve(bAnimListElem *ale)
Definition anim_deps.cc:221
wmWindow * CTX_wm_window(const bContext *C)
static void animchan_sync_group(bAnimContext *ac, bAnimListElem *ale, bActionGroup **active_agrp)
Definition anim_deps.cc:125
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:684
@ ANIMTYPE_MASKDATABLOCK
@ ANIMTYPE_NLAACTION
@ ANIMTYPE_NLACURVE
@ ANIMTYPE_GREASE_PENCIL_LAYER_GROUP
@ ANIMTYPE_DSPOINTCLOUD
@ ANIMTYPE_DSMCLIP
@ ANIMTYPE_DSLIGHTPROBE
@ ANIMTYPE_DSNTREE
@ ANIMTYPE_GREASE_PENCIL_DATABLOCK
@ ANIMTYPE_FCURVE
@ ANIMTYPE_ANIMDATA
@ ANIMTYPE_DSVOLUME
@ ANIMTYPE_NLATRACK
@ ANIMTYPE_OBJECT
@ ANIMTYPE_GPLAYER
@ ANIMTYPE_GREASE_PENCIL_LAYER
@ ANIMTYPE_DSMBALL
@ ANIMTYPE_DSMESH
@ ANIMTYPE_NUM_TYPES
@ ANIMTYPE_NLACONTROLS
@ ANIMTYPE_DSHAIR
@ ANIMTYPE_FILLDRIVERS
@ ANIMTYPE_SUMMARY
@ ANIMTYPE_FILLACT_LAYERED
@ ANIMTYPE_SHAPEKEY
@ ANIMTYPE_SPECIALDATA__UNUSED
@ ANIMTYPE_ACTION_SLOT
@ ANIMTYPE_DSCACHEFILE
@ ANIMTYPE_MASKLAYER
@ ANIMTYPE_DSGPENCIL
@ ANIMTYPE_DSPART
@ ANIMTYPE_FILLACTD
@ ANIMTYPE_DSSKEY
@ ANIMTYPE_DSLINESTYLE
@ ANIMTYPE_PALETTE
void ANIM_animdata_update(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:365
Global G
Definition blender.cc:57
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
void ANIM_id_update(Main *bmain, ID *id)
Definition anim_deps.cc:105
void DEG_id_tag_update_ex(Main *bmain, ID *id, unsigned int flags)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_NODUPLIS
@ ANIMFILTER_LIST_CHANNELS
void BKE_fcurve_handles_recalc(FCurve &fcu)
void DEG_id_tag_update(ID *id, unsigned int flags)
void ANIM_list_elem_update(Main *bmain, Scene *scene, bAnimListElem *ale)
Definition anim_deps.cc:54
void ANIM_deselect_keys_in_animation_editors(bContext *C)
Definition anim_deps.cc:487
wmWindowManager * CTX_wm_manager(const bContext *C)
ARegion * BKE_area_find_region_type(const ScrArea *area, int region_type)
Definition screen.cc:1024
static void animchan_sync_gplayer(bAnimListElem *ale)
Definition anim_deps.cc:247
void ANIM_sync_animchannels_to_data(const bContext *C)
Definition anim_deps.cc:270
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
@ ID_RECALC_ANIMATION
Definition DNA_ID.h:1077
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
ID_Type GS(const char *name)
Definition DNA_ID.h:410
void CTX_wm_region_set(bContext *C, ARegion *region)
void BKE_annotations_layer_frames_sort(struct bGPDlayer *gpl, bool *r_has_duplicate_frames)
bool RNA_path_resolve_property(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:578
ARegion * CTX_wm_region(const bContext *C)
@ ANIM_UPDATE_ORDER
@ ANIM_UPDATE_DEPS
@ ANIM_UPDATE_HANDLES
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
void action_group_colors_set_from_posebone(bActionGroup *grp, bke::PChanBoneConst pchanbone)
void sort_time_fcurve(FCurve &fcu)
void CTX_wm_area_set(bContext *C, ScrArea *area)
eFCurve_Flags flag
char name[258]
Definition DNA_ID.h:433
struct bPose * pose
eAnimCont_Types datatype
eAnim_ChannelType type
eAnim_Update_Flags update
bAnimListElem * next
ListBaseT< struct ScrArea > areabase