Blender V4.3
graph_ops.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
9#include <cmath>
10#include <cstdlib>
11
12#include "DNA_scene_types.h"
13
14#include "BLI_math_base.h"
15#include "BLI_utildefines.h"
16
17#include "BKE_context.hh"
18#include "BKE_global.hh"
19
20#include "UI_view2d.hh"
21
22#include "ED_anim_api.hh"
23#include "ED_screen.hh"
24
25#include "graph_intern.hh"
26
27#include "RNA_access.hh"
28#include "RNA_define.hh"
29
30#include "DEG_depsgraph.hh"
31
32#include "WM_api.hh"
33#include "WM_types.hh"
34
35/* ************************** view-based operators **********************************/
36/* XXX should these really be here? */
37
38/* -------------------------------------------------------------------- */
47{
48 /* prevent changes during render */
49 if (G.is_rendering) {
50 return false;
51 }
52
54}
55
56/* Set the new frame number */
58{
59 Scene *scene = CTX_data_scene(C);
61 /* this isn't technically "frame", but it'll do... */
62 float frame = RNA_float_get(op->ptr, "frame");
63
64 /* adjust the frame or the cursor x-value */
65 if (sipo->mode == SIPO_MODE_DRIVERS) {
66 /* adjust cursor x-value */
67 sipo->cursorTime = frame;
68 }
69 else {
70 /* adjust the frame
71 * NOTE: sync this part of the code with ANIM_OT_change_frame
72 */
73 /* 1) frame is rounded to the nearest int, since frames are ints */
74 scene->r.cfra = round_fl_to_int(frame);
75
76 if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) {
77 /* Clip to preview range
78 * NOTE: Preview range won't go into negative values,
79 * so only clamping once should be fine.
80 */
81 CLAMP(scene->r.cfra, PSFRA, PEFRA);
82 }
83 else {
84 /* Prevent negative frames */
85 FRAMENUMBER_MIN_CLAMP(scene->r.cfra);
86 }
87
88 scene->r.subframe = 0.0f;
90 }
91
92 /* set the cursor value */
93 sipo->cursorVal = RNA_float_get(op->ptr, "value");
94
95 /* send notifiers - notifiers for frame should force an update for both vars ok... */
97}
98
99/* ... */
100
101/* Non-modal callback for running operator without user input */
103{
105 return OPERATOR_FINISHED;
106}
107
108/* ... */
109
110/* set the operator properties from the initial event */
111static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
112{
113 ARegion *region = CTX_wm_region(C);
114 float viewx, viewy;
115
116 /* abort if not active region (should not really be possible) */
117 if (region == nullptr) {
118 return;
119 }
120
121 /* convert from region coordinates to View2D 'tot' space */
122 UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
123
124 /* store the values in the operator properties */
125 /* NOTE: we don't clamp frame here, as it might be used for the drivers cursor */
126 RNA_float_set(op->ptr, "frame", viewx);
127 RNA_float_set(op->ptr, "value", viewy);
128}
129
130/* Modal Operator init */
131static int graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
132{
133 bScreen *screen = CTX_wm_screen(C);
134
135 /* Change to frame that mouse is over before adding modal handler,
136 * as user could click on a single frame (jump to frame) as well as
137 * click-dragging over a range (modal scrubbing). Apply this change.
138 */
139 graphview_cursor_setprops(C, op, event);
141
142 /* Signal that a scrubbing operating is starting */
143 if (screen) {
144 screen->scrubbing = true;
145 }
146
147 /* add temp handler */
150}
151
152/* Modal event handling of cursor changing */
153static int graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *event)
154{
155 bScreen *screen = CTX_wm_screen(C);
156 Scene *scene = CTX_data_scene(C);
157
158 /* execute the events */
159 switch (event->type) {
160 case EVT_ESCKEY:
161 if (screen) {
162 screen->scrubbing = false;
163 }
164
166 return OPERATOR_FINISHED;
167
168 case MOUSEMOVE:
169 /* set the new values */
170 graphview_cursor_setprops(C, op, event);
172 break;
173
174 case LEFTMOUSE:
175 case RIGHTMOUSE:
176 case MIDDLEMOUSE:
177 /* We check for either mouse-button to end, to work with all user keymaps. */
178 if (event->val == KM_RELEASE) {
179 if (screen) {
180 screen->scrubbing = false;
181 }
182
184 return OPERATOR_FINISHED;
185 }
186 break;
187 }
188
190}
191
193{
194 /* identifiers */
195 ot->name = "Set Cursor";
196 ot->idname = "GRAPH_OT_cursor_set";
197 ot->description = "Interactively set the current frame and value cursor";
198
199 /* api callbacks */
204
205 /* flags */
207
208 /* rna */
209 RNA_def_float(ot->srna, "frame", 0, MINAFRAMEF, MAXFRAMEF, "Frame", "", MINAFRAMEF, MAXFRAMEF);
210 RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Value", "", -100.0f, 100.0f);
211}
212
215/* -------------------------------------------------------------------- */
220{
221 bAnimContext ac;
222 ListBase anim_data = {nullptr, nullptr};
223 ListBase all_data = {nullptr, nullptr};
224 int filter;
225 const bool unselected = RNA_boolean_get(op->ptr, "unselected");
226
227 /* get editor data */
228 if (ANIM_animdata_get_context(C, &ac) == 0) {
229 return OPERATOR_CANCELLED;
230 }
231
232 /* get list of all channels that selection may need to be flushed to
233 * - hierarchy must not affect what we have access to here...
234 */
238 &ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
239
240 /* filter data
241 * - of the remaining visible curves, we want to hide the ones that are
242 * selected/unselected (depending on "unselected" prop)
243 */
246 if (unselected) {
247 filter |= ANIMFILTER_UNSEL;
248 }
249 else {
250 filter |= ANIMFILTER_SEL;
251 }
252
254 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
255
256 LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
257 /* hack: skip object channels for now, since flushing those will always flush everything,
258 * but they are always included */
259 /* TODO: find out why this is the case, and fix that */
260 if (ale->type == ANIMTYPE_OBJECT) {
261 continue;
262 }
263
264 /* change the hide setting, and unselect it... */
267
268 /* now, also flush selection status up/down as appropriate */
271 }
272
273 /* cleanup */
274 ANIM_animdata_freelist(&anim_data);
275 BLI_freelistN(&all_data);
276
277 /* unhide selected */
278 if (unselected) {
279 /* turn off requirement for visible */
282
283 /* flushing has been done */
285 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
286
287 LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
288 /* hack: skip object channels for now, since flushing those
289 * will always flush everything, but they are always included */
290
291 /* TODO: find out why this is the case, and fix that */
292 if (ale->type == ANIMTYPE_OBJECT) {
293 continue;
294 }
295
296 /* change the hide setting, and unselect it... */
299
300 /* now, also flush selection status up/down as appropriate */
302 &ac, &anim_data, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
303 }
304 ANIM_animdata_freelist(&anim_data);
305 }
306
307 /* send notifier that things have changed */
309
310 return OPERATOR_FINISHED;
311}
312
314{
315 /* identifiers */
316 ot->name = "Hide Curves";
317 ot->idname = "GRAPH_OT_hide";
318 ot->description = "Hide selected curves from Graph Editor view";
319
320 /* api callbacks */
323
324 /* flags */
326
327 /* props */
329 ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected curves");
330}
331
332/* ........ */
333
335{
336 bAnimContext ac;
337 ListBase anim_data = {nullptr, nullptr};
338 ListBase all_data = {nullptr, nullptr};
339 int filter;
340 const bool select = RNA_boolean_get(op->ptr, "select");
341
342 /* get editor data */
343 if (ANIM_animdata_get_context(C, &ac) == 0) {
344 return OPERATOR_CANCELLED;
345 }
346
347 /* get list of all channels that selection may need to be flushed to
348 * - hierarchy must not affect what we have access to here...
349 */
353 &ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
354
355 /* filter data
356 * - just go through all visible channels, ensuring that everything is set to be curve-visible
357 */
361 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
362
363 LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
364 /* hack: skip object channels for now, since flushing those will always flush everything,
365 * but they are always included. */
366 /* TODO: find out why this is the case, and fix that */
367 if (ale->type == ANIMTYPE_OBJECT) {
368 continue;
369 }
370
371 /* select if it is not visible */
374 ale,
377 }
378
379 /* change the visibility setting */
381
382 /* now, also flush selection status up/down as appropriate */
384 &ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, eAnimChannels_SetFlag(true));
385 }
386
387 /* cleanup */
388 ANIM_animdata_freelist(&anim_data);
389 BLI_freelistN(&all_data);
390
391 /* send notifier that things have changed */
393
394 return OPERATOR_FINISHED;
395}
396
398{
399 /* identifiers */
400 ot->name = "Reveal Curves";
401 ot->idname = "GRAPH_OT_reveal";
402 ot->description = "Make previously hidden curves visible again in Graph Editor view";
403
404 /* api callbacks */
407
408 /* flags */
410
411 RNA_def_boolean(ot->srna, "select", true, "Select", "");
412}
413
416/* -------------------------------------------------------------------- */
421{
422 /* view */
424
429
432
435
436 /* keyframes */
437 /* selection */
449
450 /* editing */
485
488
491
492 /* F-Curve Modifiers */
496
497 /* Drivers */
501}
502
504{
506 wmOperatorTypeMacro *otmacro;
507
508 ot = WM_operatortype_append_macro("GRAPH_OT_duplicate_move",
509 "Duplicate",
510 "Make a copy of all selected keyframes and move them",
512 WM_operatortype_macro_define(ot, "GRAPH_OT_duplicate");
513 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
514 RNA_boolean_set(otmacro->ptr, "use_duplicated_keyframes", true);
515 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
516}
517
520/* -------------------------------------------------------------------- */
525{
526 /* keymap for all regions */
527 WM_keymap_ensure(keyconf, "Graph Editor Generic", SPACE_GRAPH, RGN_TYPE_WINDOW);
528
529 /* channels */
530 /* Channels are not directly handled by the Graph Editor module,
531 * but are inherited from the Animation module.
532 * All the relevant operations, keymaps, drawing, etc.
533 * can therefore all be found in that module instead,
534 * as these are all used for the Graph Editor too.
535 */
536
537 /* keyframes */
538 WM_keymap_ensure(keyconf, "Graph Editor", SPACE_GRAPH, RGN_TYPE_WINDOW);
539}
540
SpaceGraph * CTX_wm_space_graph(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
#define LISTBASE_FOREACH(type, var, list)
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:496
MINLINE int round_fl_to_int(float a)
#define CLAMP(a, b, c)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1092
@ SCER_LOCK_FRAME_SELECTION
#define PSFRA
#define MAXFRAMEF
#define MINAFRAMEF
#define PEFRA
@ RGN_TYPE_WINDOW
@ SPACE_GRAPH
@ SIPO_MODE_DRIVERS
#define FRAMENUMBER_MIN_CLAMP(cfra)
@ OPERATOR_RUNNING_MODAL
eAnimChannels_SetFlag
@ ACHANNEL_SETFLAG_ADD
@ ACHANNEL_SETFLAG_CLEAR
@ ANIMTYPE_OBJECT
eAnimCont_Types
@ ACHANNEL_SETTING_VISIBLE
@ ACHANNEL_SETTING_SELECT
eAnimFilter_Flags
@ ANIMFILTER_UNSEL
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_CURVE_VISIBLE
@ ANIMFILTER_LIST_VISIBLE
@ ANIMFILTER_LIST_CHANNELS
@ ANIMFILTER_NODUPLIS
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_SEL
bool ED_operator_graphedit_active(bContext *C)
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1663
@ OPTYPE_BLOCKING
Definition WM_types.hh:164
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
@ OPTYPE_GRAB_CURSOR_X
Definition WM_types.hh:170
#define NC_ANIMATION
Definition WM_types.hh:355
@ KM_RELEASE
Definition WM_types.hh:285
#define NC_SCENE
Definition WM_types.hh:345
#define NA_EDITED
Definition WM_types.hh:550
#define ND_FRAME
Definition WM_types.hh:401
#define ND_ANIMCHAN
Definition WM_types.hh:463
void ANIM_channel_setting_set(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode)
short ANIM_channel_setting_get(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting)
void ANIM_flush_setting_anim_channels(bAnimContext *ac, ListBase *anim_data, bAnimListElem *ale_setting, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode)
void ANIM_animdata_freelist(ListBase *anim_data)
Definition anim_deps.cc:457
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
size_t ANIM_animdata_filter(bAnimContext *ac, ListBase *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
void GRAPH_OT_delete(wmOperatorType *ot)
void GRAPH_OT_click_insert(wmOperatorType *ot)
void GRAPH_OT_fmodifier_paste(wmOperatorType *ot)
void GRAPH_OT_smooth(wmOperatorType *ot)
void GRAPH_OT_equalize_handles(wmOperatorType *ot)
void GRAPH_OT_keyframe_jump(wmOperatorType *ot)
void GRAPH_OT_snap_cursor_value(wmOperatorType *ot)
void GRAPH_OT_bake_keys(wmOperatorType *ot)
void GRAPH_OT_mirror(wmOperatorType *ot)
void GRAPH_OT_keys_to_samples(wmOperatorType *ot)
void GRAPH_OT_fmodifier_copy(wmOperatorType *ot)
void GRAPH_OT_samples_to_keys(wmOperatorType *ot)
void GRAPH_OT_handle_type(wmOperatorType *ot)
void GRAPH_OT_frame_jump(wmOperatorType *ot)
void GRAPH_OT_driver_variables_copy(wmOperatorType *ot)
void GRAPH_OT_extrapolation_type(wmOperatorType *ot)
void GRAPH_OT_sound_to_samples(wmOperatorType *ot)
void GRAPH_OT_driver_variables_paste(wmOperatorType *ot)
void GRAPH_OT_interpolation_type(wmOperatorType *ot)
void GRAPH_OT_easing_type(wmOperatorType *ot)
void GRAPH_OT_copy(wmOperatorType *ot)
void GRAPH_OT_driver_delete_invalid(wmOperatorType *ot)
void GRAPH_OT_keyframe_insert(wmOperatorType *ot)
void GRAPH_OT_duplicate(wmOperatorType *ot)
void GRAPH_OT_euler_filter(wmOperatorType *ot)
void GRAPH_OT_clean(wmOperatorType *ot)
void GRAPH_OT_snap(wmOperatorType *ot)
void GRAPH_OT_fmodifier_add(wmOperatorType *ot)
void GRAPH_OT_paste(wmOperatorType *ot)
void GRAPH_OT_butterworth_smooth(wmOperatorType *ot)
void GRAPH_OT_select_box(wmOperatorType *ot)
void GRAPH_OT_select_column(wmOperatorType *ot)
void GRAPH_OT_time_offset(wmOperatorType *ot)
void GRAPH_OT_blend_to_neighbor(wmOperatorType *ot)
void GRAPH_OT_blend_to_ease(wmOperatorType *ot)
void GRAPH_OT_select_lasso(wmOperatorType *ot)
void GRAPH_OT_ghost_curves_create(wmOperatorType *ot)
void GRAPH_OT_gaussian_smooth(wmOperatorType *ot)
void GRAPH_OT_blend_offset(wmOperatorType *ot)
void GRAPH_OT_select_circle(wmOperatorType *ot)
void GRAPH_OT_clickselect(wmOperatorType *ot)
void GRAPH_OT_select_more(wmOperatorType *ot)
void GRAPH_OT_breakdown(wmOperatorType *ot)
void GRAPH_OT_push_pull(wmOperatorType *ot)
void GRAPH_OT_select_linked(wmOperatorType *ot)
void GRAPH_OT_view_all(wmOperatorType *ot)
void GRAPH_OT_scale_average(wmOperatorType *ot)
void GRAPH_OT_view_frame(wmOperatorType *ot)
void GRAPH_OT_view_selected(wmOperatorType *ot)
void GRAPH_OT_match_slope(wmOperatorType *ot)
void GRAPH_OT_select_key_handles(wmOperatorType *ot)
void GRAPH_OT_previewrange_set(wmOperatorType *ot)
void GRAPH_OT_ghost_curves_clear(wmOperatorType *ot)
void GRAPH_OT_select_leftright(wmOperatorType *ot)
void GRAPH_OT_decimate(wmOperatorType *ot)
void GRAPH_OT_ease(wmOperatorType *ot)
void GRAPH_OT_scale_from_neighbor(wmOperatorType *ot)
void GRAPH_OT_shear(wmOperatorType *ot)
void GRAPH_OT_blend_to_default(wmOperatorType *ot)
void GRAPH_OT_select_all(wmOperatorType *ot)
void GRAPH_OT_select_less(wmOperatorType *ot)
void graphedit_operatortypes()
Definition graph_ops.cc:420
void ED_operatormacros_graph()
Definition graph_ops.cc:503
void graphedit_keymap(wmKeyConfig *keyconf)
Definition graph_ops.cc:524
static int graphview_curves_hide_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:219
static void graphview_cursor_apply(bContext *C, wmOperator *op)
Definition graph_ops.cc:57
static int graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:153
static int graphview_cursor_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:102
static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:111
static void GRAPH_OT_cursor_set(wmOperatorType *ot)
Definition graph_ops.cc:192
static void GRAPH_OT_hide(wmOperatorType *ot)
Definition graph_ops.cc:313
static void GRAPH_OT_reveal(wmOperatorType *ot)
Definition graph_ops.cc:397
static int graphview_curves_reveal_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:334
static bool graphview_cursor_poll(bContext *C)
Definition graph_ops.cc:46
static int graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:131
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
ccl_device_inline float4 select(const int4 mask, const float4 a, const float4 b)
#define G(x, y, z)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
float RNA_float_get(PointerRNA *ptr, const char *name)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
#define FLT_MAX
Definition stdcycles.h:14
eAnimCont_Types datatype
short val
Definition WM_types.hh:724
int mval[2]
Definition WM_types.hh:728
short type
Definition WM_types.hh:722
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* modal)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1036
int(* invoke)(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1022
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
StructRNA * srna
Definition WM_types.hh:1080
struct PointerRNA * ptr
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ RIGHTMOUSE
@ MOUSEMOVE
@ LEFTMOUSE
@ MIDDLEMOUSE
@ EVT_ESCKEY
wmOperatorType * ot
Definition wm_files.cc:4125
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:897
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)