Blender V5.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
8
9#include <cstdlib>
10#include <optional>
11
12#include "DNA_scene_types.h"
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_listbase.hh"
17#include "BLI_math_base_c.hh"
18#include "BLI_utildefines.hh"
19
20#include "BKE_context.hh"
21#include "BKE_global.hh"
22#include "BKE_scene.hh"
23
24#include "UI_view2d.hh"
25
26#include "ED_anim_api.hh"
27#include "ED_screen.hh"
28
29#include "graph_intern.hh"
30
31#include "RNA_access.hh"
32#include "RNA_define.hh"
33
34#include "DEG_depsgraph.hh"
35
36#include "WM_api.hh"
37#include "WM_types.hh"
38
39namespace blender {
40
41/* -------------------------------------------------------------------- */
48
49/* XXX should these really be here? */
50
52{
53 /* prevent changes during render */
54 if (G.is_rendering) {
55 return false;
56 }
57
59}
60
61/* Set the new frame number */
63{
64 Scene *scene = CTX_data_scene(C);
66 /* this isn't technically "frame", but it'll do... */
67 float frame = RNA_float_get(op->ptr, "frame");
68
69 /* adjust the frame or the cursor x-value */
70 if (sipo->mode == SIPO_MODE_DRIVERS) {
71 /* adjust cursor x-value */
72 sipo->cursorTime = frame;
73 }
74 else {
75 /* Adjust the frame.
76 * NOTE: sync this part of the code with #ANIM_OT_change_frame. */
77
78 /* 1) frame is rounded to the nearest int, since frames are ints */
79 scene->r.cfra = round_fl_to_int(frame);
80
81 if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) {
82 /* Clip to preview range
83 * NOTE: Preview range won't go into negative values,
84 * so only clamping once should be fine.
85 */
86 const ScenePlaybackRange playback_range = BKE_scene_get_playback_range(scene);
87 CLAMP(scene->r.cfra, playback_range.start_frame, playback_range.end_frame);
88 }
89 else {
90 /* Prevent negative frames */
92 }
93
94 scene->r.subframe = 0.0f;
96 }
97
98 /* set the cursor value */
99 sipo->cursorVal = RNA_float_get(op->ptr, "value");
100
101 /* send notifiers - notifiers for frame should force an update for both vars ok... */
103}
104
105/* ... */
106
107/* Non-modal callback for running operator without user input */
113
114/* ... */
115
116/* set the operator properties from the initial event */
117static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
118{
119 ARegion *region = CTX_wm_region(C);
120 float viewx, viewy;
121
122 /* abort if not active region (should not really be possible) */
123 if (region == nullptr) {
124 return;
125 }
126
127 /* convert from region coordinates to View2D 'tot' space */
128 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
129
130 /* store the values in the operator properties */
131 /* NOTE: we don't clamp frame here, as it might be used for the drivers cursor */
132 RNA_float_set(op->ptr, "frame", viewx);
133 RNA_float_set(op->ptr, "value", viewy);
134}
135
136/* Modal Operator init */
138{
139 bScreen *screen = CTX_wm_screen(C);
140
141 /* Change to frame that mouse is over before adding modal handler,
142 * as user could click on a single frame (jump to frame) as well as
143 * click-dragging over a range (modal scrubbing). Apply this change.
144 */
145 graphview_cursor_setprops(C, op, event);
147
148 /* Signal that a scrubbing operating is starting */
149 if (screen) {
150 const std::optional<PreScrubbingState> pre_scrubbing = ED_screen_scrubbing_enable(*C, *screen);
151 if (pre_scrubbing) {
152 op->customdata = MEM_new<PreScrubbingState>(__func__, *pre_scrubbing);
153 }
154 }
155
156 /* add temp handler */
159}
160
161/* Modal event handling of cursor changing */
163{
164 Scene *scene = CTX_data_scene(C);
165
166 /* execute the events */
167 switch (event->type) {
168 case EVT_ESCKEY:
170 break;
171
172 case MOUSEMOVE:
173 /* set the new values */
174 graphview_cursor_setprops(C, op, event);
176 return OPERATOR_RUNNING_MODAL; /* Scrubbing continues. */
177
178 case LEFTMOUSE:
179 case RIGHTMOUSE:
180 case MIDDLEMOUSE:
181 /* We check for either mouse-button to end, to work with all user keymaps. */
182 if (event->val == KM_RELEASE) {
184 }
185 break;
186 default:
187 return OPERATOR_RUNNING_MODAL; /* Scrubbing continues. */
188 }
189
190 /* Scrubbing ended, so return the playback state to what it was before scrubbing started. */
191 PreScrubbingState *pre_scrubbing = static_cast<PreScrubbingState *>(op->customdata);
192 bScreen *screen = CTX_wm_screen(C);
193 if (screen) {
194 std::optional<PreScrubbingState> resume = pre_scrubbing ? std::optional(*pre_scrubbing) :
195 std::nullopt;
196 ED_screen_scrubbing_disable(*C, *screen, resume);
197 }
198
199 MEM_delete(pre_scrubbing);
200 op->customdata = nullptr;
201
202 return OPERATOR_FINISHED;
203}
204
206{
207 /* identifiers */
208 ot->name = "Set Cursor";
209 ot->idname = "GRAPH_OT_cursor_set";
210 ot->description = "Interactively set the current frame and value cursor";
211
212 /* API callbacks. */
217
218 /* flags */
220
221 /* rna */
222 RNA_def_float(ot->srna, "frame", 0, MINAFRAMEF, MAXFRAMEF, "Frame", "", MINAFRAMEF, MAXFRAMEF);
223 RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Value", "", -100.0f, 100.0f);
224}
225
227
228/* -------------------------------------------------------------------- */
231
233{
234 bAnimContext ac;
235 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
236 ListBaseT<bAnimListElem> all_data = {nullptr, nullptr};
237 int filter;
238 const bool unselected = RNA_boolean_get(op->ptr, "unselected");
239
240 /* get editor data */
241 if (ANIM_animdata_get_context(C, &ac) == 0) {
242 return OPERATOR_CANCELLED;
243 }
244
245 /* get list of all channels that selection may need to be flushed to
246 * - hierarchy must not affect what we have access to here...
247 */
251 &ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
252
253 /* filter data
254 * - of the remaining visible curves, we want to hide the ones that are
255 * selected/unselected (depending on "unselected" prop)
256 */
259 if (unselected) {
261 }
262 else {
264 }
265
267 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
268
269 for (bAnimListElem &ale : anim_data) {
270 /* hack: skip object channels for now, since flushing those will always flush everything,
271 * but they are always included */
272 /* TODO: find out why this is the case, and fix that */
273 if (ale.type == ANIMTYPE_OBJECT) {
274 continue;
275 }
276
277 /* change the hide setting, and unselect it... */
280
281 /* now, also flush selection status up/down as appropriate */
283 &ac, &all_data, &ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR);
284 }
285
286 /* cleanup */
287 ANIM_animdata_freelist(&anim_data);
288 all_data.free_no_destruct();
289
290 /* unhide selected */
291 if (unselected) {
292 /* turn off requirement for visible */
295
296 /* flushing has been done */
298 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
299
300 for (bAnimListElem &ale : anim_data) {
301 /* hack: skip object channels for now, since flushing those
302 * will always flush everything, but they are always included */
303
304 /* TODO: find out why this is the case, and fix that */
305 if (ale.type == ANIMTYPE_OBJECT) {
306 continue;
307 }
308
309 /* change the hide setting, and unselect it... */
312
313 /* now, also flush selection status up/down as appropriate */
315 &ac, &anim_data, &ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
316 }
317 ANIM_animdata_freelist(&anim_data);
318 }
319
320 /* send notifier that things have changed */
322
323 return OPERATOR_FINISHED;
324}
325
327{
328 /* identifiers */
329 ot->name = "Hide Curves";
330 ot->idname = "GRAPH_OT_hide";
331 ot->description = "Hide selected curves from Graph Editor view";
332
333 /* API callbacks. */
336
337 /* flags */
339
340 /* props */
342 ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected curves");
343}
344
345/* ........ */
346
348{
349 bAnimContext ac;
350 ListBaseT<bAnimListElem> anim_data = {nullptr, nullptr};
351 ListBaseT<bAnimListElem> all_data = {nullptr, nullptr};
352 int filter;
353 const bool select = RNA_boolean_get(op->ptr, "select");
354
355 /* get editor data */
356 if (ANIM_animdata_get_context(C, &ac) == 0) {
357 return OPERATOR_CANCELLED;
358 }
359
360 /* get list of all channels that selection may need to be flushed to
361 * - hierarchy must not affect what we have access to here...
362 */
366 &ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
367
368 /* filter data
369 * - just go through all visible channels, ensuring that everything is set to be curve-visible
370 */
374 &ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
375
376 for (bAnimListElem &ale : anim_data) {
377 /* hack: skip object channels for now, since flushing those will always flush everything,
378 * but they are always included. */
379 /* TODO: find out why this is the case, and fix that */
380 if (ale.type == ANIMTYPE_OBJECT) {
381 continue;
382 }
383
384 /* select if it is not visible */
387 &ale,
390 }
391
392 /* change the visibility setting */
394
395 /* now, also flush selection status up/down as appropriate */
397 &ac, &all_data, &ale, ACHANNEL_SETTING_VISIBLE, eAnimChannels_SetFlag(true));
398 }
399
400 /* cleanup */
401 ANIM_animdata_freelist(&anim_data);
402 all_data.free_no_destruct();
403
404 /* send notifier that things have changed */
406
407 return OPERATOR_FINISHED;
408}
409
411{
412 /* identifiers */
413 ot->name = "Reveal Curves";
414 ot->idname = "GRAPH_OT_reveal";
415 ot->description = "Make previously hidden curves visible again in Graph Editor view";
416
417 /* API callbacks. */
420
421 /* flags */
423
424 RNA_def_boolean(ot->srna, "select", true, "Select", "");
425}
426
428
429/* -------------------------------------------------------------------- */
432
434{
435 /* view */
437
442
445
449
450 /* keyframes */
451 /* selection */
463
464 /* editing */
499
502
505
506 /* F-Curve Modifiers */
511
512 /* Drivers */
516}
517
519{
520 wmOperatorType *ot;
521 wmOperatorTypeMacro *otmacro;
522
523 ot = WM_operatortype_append_macro("GRAPH_OT_duplicate_move",
524 "Duplicate",
525 "Make a copy of all selected keyframes and move them",
527 WM_operatortype_macro_define(ot, "GRAPH_OT_duplicate");
528 otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
529 RNA_boolean_set(otmacro->ptr, "use_duplicated_keyframes", true);
530 RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
531}
532
534
535/* -------------------------------------------------------------------- */
538
540{
541 /* keymap for all regions */
542 WM_keymap_ensure(keyconf, "Graph Editor Generic", SPACE_GRAPH, RGN_TYPE_WINDOW);
543
544 /* channels */
545 /* Channels are not directly handled by the Graph Editor module,
546 * but are inherited from the Animation module.
547 * All the relevant operations, keymaps, drawing, etc.
548 * can therefore all be found in that module instead,
549 * as these are all used for the Graph Editor too.
550 */
551
552 /* keyframes */
553 WM_keymap_ensure(keyconf, "Graph Editor", SPACE_GRAPH, RGN_TYPE_WINDOW);
554}
555
557
558} // namespace blender
#define MAXFRAMEF
#define MINAFRAMEF
#define FRAMENUMBER_MIN_CLAMP(cfra)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define NC_ANIMATION
Definition WM_types.hh:401
#define NC_SCENE
Definition WM_types.hh:391
#define NA_EDITED
Definition WM_types.hh:634
#define ND_FRAME
Definition WM_types.hh:453
#define ND_ANIMCHAN
Definition WM_types.hh:539
#define CLAMP(a, b, c)
#define FLT_MAX
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
BMesh Iterators.
void GRAPH_OT_easing_type(wmOperatorType *ot)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void GRAPH_OT_keys_to_samples(wmOperatorType *ot)
void void GRAPH_OT_previewrange_set(wmOperatorType *ot)
void GRAPH_OT_click_insert(wmOperatorType *ot)
void GRAPH_OT_blend_to_default(wmOperatorType *ot)
short ANIM_channel_setting_get(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting)
void GRAPH_OT_equalize_handles(wmOperatorType *ot)
void GRAPH_OT_match_slope(wmOperatorType *ot)
void GRAPH_OT_smooth(wmOperatorType *ot)
void GRAPH_OT_select_column(wmOperatorType *ot)
void graphedit_keymap(wmKeyConfig *keyconf)
Definition graph_ops.cc:539
void GRAPH_OT_fmodifier_copy(wmOperatorType *ot)
bool ED_operator_graphedit_active(bContext *C)
void GRAPH_OT_select_linked(wmOperatorType *ot)
void GRAPH_OT_select_all(wmOperatorType *ot)
void GRAPH_OT_delete(wmOperatorType *ot)
void GRAPH_OT_copy(wmOperatorType *ot)
void GRAPH_OT_blend_offset(wmOperatorType *ot)
static wmOperatorStatus graphview_curves_hide_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:232
static bool graphview_cursor_poll(bContext *C)
Definition graph_ops.cc:51
void GRAPH_OT_keyframe_jump(wmOperatorType *ot)
MINLINE int round_fl_to_int(float a)
void GRAPH_OT_bake_keys(wmOperatorType *ot)
static void GRAPH_OT_cursor_set(wmOperatorType *ot)
Definition graph_ops.cc:205
static void graphview_cursor_apply(bContext *C, wmOperator *op)
Definition graph_ops.cc:62
void GRAPH_OT_ease(wmOperatorType *ot)
void GRAPH_OT_blend_to_ease(wmOperatorType *ot)
void GRAPH_OT_ghost_curves_clear(wmOperatorType *ot)
static void GRAPH_OT_reveal(wmOperatorType *ot)
Definition graph_ops.cc:410
bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
void GRAPH_OT_breakdown(wmOperatorType *ot)
static void GRAPH_OT_hide(wmOperatorType *ot)
Definition graph_ops.cc:326
wmOperatorTypeMacro * WM_operatortype_macro_define(wmOperatorType *ot, const char *idname)
static wmOperatorStatus graphview_cursor_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:108
eAnimChannels_SetFlag
@ ACHANNEL_SETFLAG_CLEAR
@ ACHANNEL_SETFLAG_ADD
void GRAPH_OT_blend_to_neighbor(wmOperatorType *ot)
void GRAPH_OT_select_circle(wmOperatorType *ot)
void GRAPH_OT_fmodifier_delete(wmOperatorType *ot)
@ ANIMTYPE_OBJECT
void GRAPH_OT_sound_to_samples(wmOperatorType *ot)
void GRAPH_OT_clean(wmOperatorType *ot)
void GRAPH_OT_select_less(wmOperatorType *ot)
void GRAPH_OT_extrapolation_type(wmOperatorType *ot)
void GRAPH_OT_gaussian_smooth(wmOperatorType *ot)
void GRAPH_OT_select_leftright(wmOperatorType *ot)
static wmOperatorStatus graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:137
void GRAPH_OT_frame_jump(wmOperatorType *ot)
void GRAPH_OT_samples_to_keys(wmOperatorType *ot)
ScenePlaybackRange BKE_scene_get_playback_range(const Scene *scene)
Definition scene.cc:2607
Global G
Definition blender.cc:57
void GRAPH_OT_fmodifier_add(wmOperatorType *ot)
@ ACHANNEL_SETTING_VISIBLE
@ ACHANNEL_SETTING_SELECT
size_t ANIM_animdata_filter(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, const eAnimFilter_Flags filter_mode, void *data, const eAnimCont_Types datatype)
std::optional< PreScrubbingState > ED_screen_scrubbing_enable(bContext &C, bScreen &screen)
void ED_operatormacros_graph()
Definition graph_ops.cc:518
@ ANIMFILTER_FCURVESONLY
@ ANIMFILTER_LIST_VISIBLE
@ ANIMFILTER_DATA_VISIBLE
@ ANIMFILTER_CURVE_VISIBLE
@ ANIMFILTER_UNSEL
@ ANIMFILTER_NODUPLIS
@ ANIMFILTER_LIST_CHANNELS
void DEG_id_tag_update(ID *id, unsigned int flags)
void ANIM_channel_setting_set(bAnimContext *ac, bAnimListElem *ale, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode)
void GRAPH_OT_keyframe_insert(wmOperatorType *ot)
void GRAPH_OT_select_key_handles(wmOperatorType *ot)
void GRAPH_OT_snap_cursor_value(wmOperatorType *ot)
void GRAPH_OT_view_frame(wmOperatorType *ot)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
void GRAPH_OT_clickselect(wmOperatorType *ot)
SpaceGraph * CTX_wm_space_graph(const bContext *C)
void GRAPH_OT_interpolation_type(wmOperatorType *ot)
void graphedit_operatortypes()
Definition graph_ops.cc:433
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void GRAPH_OT_driver_delete_invalid(wmOperatorType *ot)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
@ SCER_LOCK_FRAME_SELECTION
static wmOperatorStatus graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:162
static wmOperatorStatus graphview_curves_reveal_exec(bContext *C, wmOperator *op)
Definition graph_ops.cc:347
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
void GRAPH_OT_select_box(wmOperatorType *ot)
wmOperatorType * WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag)
void GRAPH_OT_shear(wmOperatorType *ot)
void ANIM_flush_setting_anim_channels(bAnimContext *ac, ListBaseT< bAnimListElem > *anim_data, bAnimListElem *ale_setting, eAnimChannel_Settings setting, eAnimChannels_SetFlag mode)
void GRAPH_OT_butterworth_smooth(wmOperatorType *ot)
void GRAPH_OT_driver_variables_paste(wmOperatorType *ot)
void GRAPH_OT_ghost_curves_create(wmOperatorType *ot)
void ANIM_animdata_freelist(ListBaseT< bAnimListElem > *anim_data)
Definition anim_deps.cc:472
void GRAPH_OT_scale_from_neighbor(wmOperatorType *ot)
static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
Definition graph_ops.cc:117
void GRAPH_OT_duplicate(wmOperatorType *ot)
void GRAPH_OT_decimate(wmOperatorType *ot)
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
void GRAPH_OT_snap(wmOperatorType *ot)
void GRAPH_OT_time_offset(wmOperatorType *ot)
@ KM_RELEASE
Definition WM_types.hh:325
void GRAPH_OT_driver_variables_copy(wmOperatorType *ot)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
void GRAPH_OT_mirror(wmOperatorType *ot)
void GRAPH_OT_view_selected(wmOperatorType *ot)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_X
Definition WM_types.hh:198
void GRAPH_OT_scale_average(wmOperatorType *ot)
void ED_screen_scrubbing_disable(bContext &C, bScreen &screen, const std::optional< PreScrubbingState > &resume)
void GRAPH_OT_fmodifier_paste(wmOperatorType *ot)
void GRAPH_OT_handle_type(wmOperatorType *ot)
void GRAPH_OT_euler_filter(wmOperatorType *ot)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void GRAPH_OT_push_pull(wmOperatorType *ot)
void GRAPH_OT_local_view(wmOperatorType *ot)
void GRAPH_OT_select_lasso(wmOperatorType *ot)
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)
ARegion * CTX_wm_region(const bContext *C)
void GRAPH_OT_select_more(wmOperatorType *ot)
float RNA_float_get(PointerRNA *ptr, const char *name)
void GRAPH_OT_view_all(wmOperatorType *ot)
void GRAPH_OT_paste(wmOperatorType *ot)
struct RenderData r
eGraphEdit_Mode mode
eAnimCont_Types datatype
wmEventType type
Definition WM_types.hh:817
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157