Blender V5.0
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
8
9#include <cstdlib>
10
11#include "DNA_scene_types.h"
12
13#include "BLI_listbase.h"
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/* -------------------------------------------------------------------- */
45
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 */
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 */
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 */
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 */
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 default: {
188 break;
189 }
190 }
191
193}
194
196{
197 /* identifiers */
198 ot->name = "Set Cursor";
199 ot->idname = "GRAPH_OT_cursor_set";
200 ot->description = "Interactively set the current frame and value cursor";
201
202 /* API callbacks. */
204 ot->invoke = graphview_cursor_invoke;
205 ot->modal = graphview_cursor_modal;
207
208 /* flags */
210
211 /* rna */
212 RNA_def_float(ot->srna, "frame", 0, MINAFRAMEF, MAXFRAMEF, "Frame", "", MINAFRAMEF, MAXFRAMEF);
213 RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Value", "", -100.0f, 100.0f);
214}
215
217
218/* -------------------------------------------------------------------- */
221
223{
224 bAnimContext ac;
225 ListBase anim_data = {nullptr, nullptr};
226 ListBase all_data = {nullptr, nullptr};
227 int filter;
228 const bool unselected = RNA_boolean_get(op->ptr, "unselected");
229
230 /* get editor data */
231 if (ANIM_animdata_get_context(C, &ac) == 0) {
232 return OPERATOR_CANCELLED;
233 }
234
235 /* get list of all channels that selection may need to be flushed to
236 * - hierarchy must not affect what we have access to here...
237 */
241 &ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
242
243 /* filter data
244 * - of the remaining visible curves, we want to hide the ones that are
245 * selected/unselected (depending on "unselected" prop)
246 */
249 if (unselected) {
251 }
252 else {
254 }
255
257 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
258
259 LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
260 /* hack: skip object channels for now, since flushing those will always flush everything,
261 * but they are always included */
262 /* TODO: find out why this is the case, and fix that */
263 if (ale->type == ANIMTYPE_OBJECT) {
264 continue;
265 }
266
267 /* change the hide setting, and unselect it... */
270
271 /* now, also flush selection status up/down as appropriate */
274 }
275
276 /* cleanup */
277 ANIM_animdata_freelist(&anim_data);
278 BLI_freelistN(&all_data);
279
280 /* unhide selected */
281 if (unselected) {
282 /* turn off requirement for visible */
285
286 /* flushing has been done */
288 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
289
290 LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
291 /* hack: skip object channels for now, since flushing those
292 * will always flush everything, but they are always included */
293
294 /* TODO: find out why this is the case, and fix that */
295 if (ale->type == ANIMTYPE_OBJECT) {
296 continue;
297 }
298
299 /* change the hide setting, and unselect it... */
302
303 /* now, also flush selection status up/down as appropriate */
305 &ac, &anim_data, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
306 }
307 ANIM_animdata_freelist(&anim_data);
308 }
309
310 /* send notifier that things have changed */
312
313 return OPERATOR_FINISHED;
314}
315
317{
318 /* identifiers */
319 ot->name = "Hide Curves";
320 ot->idname = "GRAPH_OT_hide";
321 ot->description = "Hide selected curves from Graph Editor view";
322
323 /* API callbacks. */
326
327 /* flags */
329
330 /* props */
332 ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected curves");
333}
334
335/* ........ */
336
338{
339 bAnimContext ac;
340 ListBase anim_data = {nullptr, nullptr};
341 ListBase all_data = {nullptr, nullptr};
342 int filter;
343 const bool select = RNA_boolean_get(op->ptr, "select");
344
345 /* get editor data */
346 if (ANIM_animdata_get_context(C, &ac) == 0) {
347 return OPERATOR_CANCELLED;
348 }
349
350 /* get list of all channels that selection may need to be flushed to
351 * - hierarchy must not affect what we have access to here...
352 */
356 &ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
357
358 /* filter data
359 * - just go through all visible channels, ensuring that everything is set to be curve-visible
360 */
364 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
365
366 LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
367 /* hack: skip object channels for now, since flushing those will always flush everything,
368 * but they are always included. */
369 /* TODO: find out why this is the case, and fix that */
370 if (ale->type == ANIMTYPE_OBJECT) {
371 continue;
372 }
373
374 /* select if it is not visible */
377 ale,
380 }
381
382 /* change the visibility setting */
384
385 /* now, also flush selection status up/down as appropriate */
387 &ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, eAnimChannels_SetFlag(true));
388 }
389
390 /* cleanup */
391 ANIM_animdata_freelist(&anim_data);
392 BLI_freelistN(&all_data);
393
394 /* send notifier that things have changed */
396
397 return OPERATOR_FINISHED;
398}
399
401{
402 /* identifiers */
403 ot->name = "Reveal Curves";
404 ot->idname = "GRAPH_OT_reveal";
405 ot->description = "Make previously hidden curves visible again in Graph Editor view";
406
407 /* API callbacks. */
410
411 /* flags */
413
414 RNA_def_boolean(ot->srna, "select", true, "Select", "");
415}
416
418
419/* -------------------------------------------------------------------- */
422
424{
425 /* view */
427
432
435
438
439 /* keyframes */
440 /* selection */
452
453 /* editing */
488
491
494
495 /* F-Curve Modifiers */
499
500 /* Drivers */
504}
505
507{
509 wmOperatorTypeMacro *otmacro;
510
511 ot = WM_operatortype_append_macro("GRAPH_OT_duplicate_move",
512 "Duplicate",
513 "Make a copy of all selected keyframes and move them",
515 WM_operatortype_macro_define(ot, "GRAPH_OT_duplicate");
516 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
517 RNA_boolean_set(otmacro->ptr, "use_duplicated_keyframes", true);
518 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
519}
520
522
523/* -------------------------------------------------------------------- */
526
528{
529 /* keymap for all regions */
530 WM_keymap_ensure(keyconf, "Graph Editor Generic", SPACE_GRAPH, RGN_TYPE_WINDOW);
531
532 /* channels */
533 /* Channels are not directly handled by the Graph Editor module,
534 * but are inherited from the Animation module.
535 * All the relevant operations, keymaps, drawing, etc.
536 * can therefore all be found in that module instead,
537 * as these are all used for the Graph Editor too.
538 */
539
540 /* keyframes */
541 WM_keymap_ensure(keyconf, "Graph Editor", SPACE_GRAPH, RGN_TYPE_WINDOW);
542}
543
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(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
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:1125
#define PSFRA
#define MAXFRAMEF
@ SCER_LOCK_FRAME_SELECTION
#define MINAFRAMEF
#define PEFRA
@ RGN_TYPE_WINDOW
@ SPACE_GRAPH
@ SIPO_MODE_DRIVERS
#define FRAMENUMBER_MIN_CLAMP(cfra)
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ 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)
#define C
Definition RandGen.cpp:29
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:1668
@ KM_RELEASE
Definition WM_types.hh:312
#define NC_ANIMATION
Definition WM_types.hh:388
#define NC_SCENE
Definition WM_types.hh:378
@ OPTYPE_BLOCKING
Definition WM_types.hh:184
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
@ OPTYPE_GRAB_CURSOR_X
Definition WM_types.hh:190
#define NA_EDITED
Definition WM_types.hh:584
#define ND_FRAME
Definition WM_types.hh:434
#define ND_ANIMCHAN
Definition WM_types.hh:496
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:463
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)
#define filter
#define select(A, B, C)
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:423
void ED_operatormacros_graph()
Definition graph_ops.cc:506
void graphedit_keymap(wmKeyConfig *keyconf)
Definition graph_ops.cc:527
static wmOperatorStatus graphview_curves_hide_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:222
static void graphview_cursor_apply(bContext *C, wmOperator *op)
Definition graph_ops.cc:57
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:195
static void GRAPH_OT_hide(wmOperatorType *ot)
Definition graph_ops.cc:316
static wmOperatorStatus graphview_curves_reveal_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:337
static wmOperatorStatus graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:131
static wmOperatorStatus graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:153
static void GRAPH_OT_reveal(wmOperatorType *ot)
Definition graph_ops.cc:400
static wmOperatorStatus graphview_cursor_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:102
static bool graphview_cursor_poll(bContext *C)
Definition graph_ops.cc:46
#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
struct RenderData r
eAnimCont_Types datatype
wmEventType type
Definition WM_types.hh:757
short val
Definition WM_types.hh:759
int mval[2]
Definition WM_types.hh:763
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:4237
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:895
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)