1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* All rights reserved.
*/
/** \file
* \ingroup edanimation
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_mask_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_sequence_types.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BKE_action.h"
#include "BKE_anim_data.h"
#include "BKE_context.h"
#include "BKE_fcurve.h"
#include "BKE_gpencil.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_sequencer.h"
#include "DEG_depsgraph.h"
#include "RNA_access.h"
#include "ED_anim_api.h"
/* **************************** depsgraph tagging ******************************** */
/* tags the given anim list element for refreshes (if applicable)
* due to Animation Editor editing
*/
void ANIM_list_elem_update(Main *bmain, Scene *scene, bAnimListElem *ale)
{
ID *id;
FCurve *fcu;
AnimData *adt;
id = ale->id;
if (!id) {
return;
}
/* tag AnimData for refresh so that other views will update in realtime with these changes */
adt = BKE_animdata_from_id(id);
if (adt) {
DEG_id_tag_update(id, ID_RECALC_ANIMATION);
if (adt->action != NULL) {
DEG_id_tag_update(&adt->action->id, ID_RECALC_ANIMATION);
}
}
/* Tag copy on the main object if updating anything directly inside AnimData */
if (ELEM(ale->type,
ANIMTYPE_ANIMDATA,
ANIMTYPE_NLAACTION,
ANIMTYPE_NLATRACK,
ANIMTYPE_NLACURVE)) {
DEG_id_tag_update(id, ID_RECALC_ANIMATION);
return;
}
/* update data */
fcu = (ale->datatype == ALE_FCURVE) ? ale->key_data : NULL;
if (fcu && fcu->rna_path) {
/* if we have an fcurve, call the update for the property we
* are editing, this is then expected to do the proper redraws
* and depsgraph updates */
PointerRNA id_ptr, ptr;
PropertyRNA *prop;
RNA_id_pointer_create(id, &id_ptr);
if (RNA_path_resolve_property(&id_ptr, fcu->rna_path, &ptr, &prop)) {
RNA_property_update_main(bmain, scene, &ptr, prop);
}
}
else {
/* in other case we do standard depsgraph update, ideally
* we'd be calling property update functions here too ... */
DEG_id_tag_update(id,
ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY |
ID_RECALC_ANIMATION); /* XXX or do we want something more restrictive? */
}
}
/* tags the given ID block for refreshes (if applicable) due to
* Animation Editor editing */
void ANIM_id_update(Main *bmain, ID *id)
{
if (id) {
DEG_id_tag_update_ex(
bmain,
id,
ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY |
ID_RECALC_ANIMATION); /* XXX or do we want something more restrictive? */
}
}
/* **************************** animation data <-> data syncing ******************************** */
/* This code here is used to synchronize the
* - selection (to find selected data easier)
* - ... (insert other relevant items here later)
* status in relevant Blender data with the status stored in animation channels.
*
* This should be called in the refresh() callbacks for various editors in
* response to appropriate notifiers.
*/
/* perform syncing updates for Action Groups */
static void animchan_sync_group(bAnimContext *ac, bAnimListElem *ale, bActionGroup **active_agrp)
{
bActionGroup *agrp = (bActionGroup *)ale->data;
ID *owner_id = ale->id;
/* major priority is selection status
* so we need both a group and an owner
*/
if (ELEM(NULL, agrp, owner_id)) {
return;
}
/* for standard Objects, check if group is the name of some bone */
if (GS(owner_id->name) == ID_OB) {
Object *ob = (Object *)owner_id;
/* check if there are bones, and whether the name matches any
* NOTE: this feature will only really work if groups by default contain the F-Curves
* for a single bone.
*/
if (ob->pose) {
bPoseChannel *pchan = BKE_pose_channel_find_name(ob->pose, agrp->name);
bArmature *arm = ob->data;
if (pchan) {
bActionGroup *bgrp;
/* if one matches, sync the selection status */
if ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED)) {
agrp->flag |= AGRP_SELECTED;
}
else {
agrp->flag &= ~AGRP_SELECTED;
}
/* also sync active group status */
if ((ob == ac->obact) && (pchan->bone == arm->act_bone)) {
/* if no previous F-Curve has active flag, then we're the first and only one to get it */
if (*active_agrp == NULL) {
agrp->flag |= AGRP_ACTIVE;
*active_agrp = agrp;
}
else {
/* someone else has already taken it - set as not active */
agrp->flag &= ~AGRP_ACTIVE;
}
}
else {
/* this can't possibly be active now */
agrp->flag &= ~AGRP_ACTIVE;
}
/* sync group colors */
bgrp = (bActionGroup *)BLI_findlink(&ob->pose->agroups, (pchan->agrp_index - 1));
if (bgrp) {
agrp->customCol = bgrp->customCol;
action_group_colors_sync(agrp, bgrp);
}
}
}
}
}
static void animchan_sync_fcurve_scene(bAnimListElem *ale)
{
ID *owner_id = ale->id;
BLI_assert(GS(owner_id->name) == ID_SCE);
Scene *scene = (Scene *)owner_id;
FCurve *fcu = (FCurve *)ale->data;
/* only affect if F-Curve involves sequence_editor.sequences */
if (!strstr(fcu->rna_path, "sequences_all")) {
return;
}
Editing *ed = BKE_sequencer_editing_get(scene, false);
/* get strip name, and check if this strip is selected */
char *seq_name = BLI_str_quoted_substrN(fcu->rna_path, "sequences_all[");
Sequence *seq = BKE_sequence_get_by_name(ed->seqbasep, seq_name, false);
if (seq_name) {
MEM_freeN(seq_name);
}
if (seq == NULL) {
return;
}
/* update selection status */
if (seq->flag & SELECT) {
fcu->flag |= FCURVE_SELECTED;
}
else {
fcu->flag &= ~FCURVE_SELECTED;
}
}
static void animchan_sync_fcurve_nodetree(bAnimListElem *ale, FCurve **active_fcurve)
{
ID *owner_id = ale->id;
BLI_assert(GS(owner_id->name) == ID_NT);
bNodeTree *ntree = (bNodeTree *)owner_id;
FCurve *fcu = (FCurve *)ale->data;
/* check for selected nodes */
if (!strstr(fcu->rna_path, "nodes")) {
return;
}
/* get strip name, and check if this strip is selected */
char *node_name = BLI_str_quoted_substrN(fcu->rna_path, "nodes[");
bNode *node = nodeFindNodebyName(ntree, node_name);
if (node_name) {
MEM_freeN(node_name);
}
if (node == NULL) {
return;
}
/* update selection status */
if (node->flag & NODE_SELECT) {
fcu->flag |= FCURVE_SELECTED;
}
else {
fcu->flag &= ~FCURVE_SELECTED;
}
/* update active status */
/* XXX: this may interfere with setting bones as active if both exist at once;
* then again, if that's the case, production setups aren't likely to be animating
* nodes while working with bones?
*/
if (node->flag & NODE_ACTIVE) {
if (*active_fcurve == NULL) {
fcu->flag |= FCURVE_ACTIVE;
*active_fcurve = fcu;
}
else {
fcu->flag &= ~FCURVE_ACTIVE;
}
}
else {
fcu->flag &= ~FCURVE_ACTIVE;
}
}
/* perform syncing updates for F-Curves */
static void animchan_sync_fcurve(bAnimListElem *ale, FCurve **active_fcurve)
{
FCurve *fcu = (FCurve *)ale->data;
ID *owner_id = ale->id;
/* major priority is selection status, so refer to the checks done in anim_filter.c
* skip_fcurve_selected_data() for reference about what's going on here...
*/
if (ELEM(NULL, fcu, fcu->rna_path, owner_id)) {
return;
}
switch (GS(owner_id->name)) {
case ID_SCE:
animchan_sync_fcurve_scene(ale);
break;
case ID_NT:
animchan_sync_fcurve_nodetree(ale, active_fcurve);
break;
default:
break;
}
}
/* perform syncing updates for GPencil Layers */
static void animchan_sync_gplayer(bAnimListElem *ale)
{
bGPDlayer *gpl = (bGPDlayer *)ale->data;
/* Make sure the selection flags agree with the "active" flag.
* The selection flags are used in the Dopesheet only, whereas
* the active flag is used everywhere else. Hence, we try to
* sync these here so that it all seems to be have as the user
* expects - T50184
*
* Assume that we only really do this when the active status changes.
* (NOTE: This may prove annoying if it means selection is always lost)
*/
if (gpl->flag & GP_LAYER_ACTIVE) {
gpl->flag |= GP_LAYER_SELECT;
}
else {
gpl->flag &= ~GP_LAYER_SELECT;
}
}
/* ---------------- */
/* Main call to be exported to animation editors */
void ANIM_sync_animchannels_to_data(const bContext *C)
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
bActionGroup *active_agrp = NULL;
FCurve *active_fcurve = NULL;
/* get animation context info for filtering the channels */
if (ANIM_animdata_get_context(C, &ac) == 0) {
return;
}
/* filter data */
/* NOTE: we want all channels, since we want to be able to set selection status on some of them
* even when collapsed... however,
* don't include duplicates so that selection statuses don't override each other.
*/
filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS;
ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
/* flush settings as appropriate depending on the types of the channels */
for (ale = anim_data.first; ale; ale = ale->next) {
switch (ale->type) {
case ANIMTYPE_GROUP:
animchan_sync_group(&ac, ale, &active_agrp);
break;
case ANIMTYPE_FCURVE:
animchan_sync_fcurve(ale, &active_fcurve);
break;
case ANIMTYPE_GPLAYER:
animchan_sync_gplayer(ale);
break;
}
}
ANIM_animdata_freelist(&anim_data);
}
void ANIM_animdata_update(bAnimContext *ac, ListBase *anim_data)
{
bAnimListElem *ale;
for (ale = anim_data->first; ale; ale = ale->next) {
if (ale->type == ANIMTYPE_GPLAYER) {
bGPDlayer *gpl = ale->data;
if (ale->update & ANIM_UPDATE_ORDER) {
ale->update &= ~ANIM_UPDATE_ORDER;
if (gpl) {
BKE_gpencil_layer_frames_sort(gpl, NULL);
}
}
if (ale->update & ANIM_UPDATE_DEPS) {
ale->update &= ~ANIM_UPDATE_DEPS;
ANIM_list_elem_update(ac->bmain, ac->scene, ale);
}
/* disable handles to avoid crash */
if (ale->update & ANIM_UPDATE_HANDLES) {
ale->update &= ~ANIM_UPDATE_HANDLES;
}
}
else if (ale->datatype == ALE_MASKLAY) {
MaskLayer *masklay = ale->data;
if (ale->update & ANIM_UPDATE_ORDER) {
ale->update &= ~ANIM_UPDATE_ORDER;
if (masklay) {
/* While correct & we could enable it: 'posttrans_mask_clean' currently
* both sorts and removes doubles, so this is not necessary here. */
// BKE_mask_layer_shape_sort(masklay);
}
}
if (ale->update & ANIM_UPDATE_DEPS) {
ale->update &= ~ANIM_UPDATE_DEPS;
ANIM_list_elem_update(ac->bmain, ac->scene, ale);
}
/* Disable handles to avoid assert. */
if (ale->update & ANIM_UPDATE_HANDLES) {
ale->update &= ~ANIM_UPDATE_HANDLES;
}
}
else if (ale->datatype == ALE_FCURVE) {
FCurve *fcu = ale->key_data;
if (ale->update & ANIM_UPDATE_ORDER) {
ale->update &= ~ANIM_UPDATE_ORDER;
if (fcu) {
sort_time_fcurve(fcu);
}
}
if (ale->update & ANIM_UPDATE_HANDLES) {
ale->update &= ~ANIM_UPDATE_HANDLES;
if (fcu) {
calchandles_fcurve(fcu);
}
}
if (ale->update & ANIM_UPDATE_DEPS) {
ale->update &= ~ANIM_UPDATE_DEPS;
ANIM_list_elem_update(ac->bmain, ac->scene, ale);
}
}
else if (ELEM(ale->type,
ANIMTYPE_ANIMDATA,
ANIMTYPE_NLAACTION,
ANIMTYPE_NLATRACK,
ANIMTYPE_NLACURVE)) {
if (ale->update & ANIM_UPDATE_DEPS) {
ale->update &= ~ANIM_UPDATE_DEPS;
ANIM_list_elem_update(ac->bmain, ac->scene, ale);
}
}
else if (ale->update) {
#if 0
if (G.debug & G_DEBUG) {
printf("%s: Unhandled animchannel updates (%d) for type=%d (%p)\n",
__func__,
ale->update,
ale->type,
ale->data);
}
#endif
/* Prevent crashes in cases where it can't be handled */
ale->update = 0;
}
BLI_assert(ale->update == 0);
}
}
void ANIM_animdata_freelist(ListBase *anim_data)
{
#ifndef NDEBUG
bAnimListElem *ale, *ale_next;
for (ale = anim_data->first; ale; ale = ale_next) {
ale_next = ale->next;
BLI_assert(ale->update == 0);
MEM_freeN(ale);
}
BLI_listbase_clear(anim_data);
#else
BLI_freelistN(anim_data);
#endif
}
|