Files
test/source/blender/editors/space_graph/graph_ops.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

543 lines
17 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2008 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spgraph
2011-02-27 20:29:51 +00:00
*/
#include <cmath>
#include <cstdlib>
#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#include "BLI_math_base.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "UI_view2d.hh"
#include "ED_anim_api.hh"
#include "ED_screen.hh"
#include "ED_transform.hh"
#include "graph_intern.h"
#include "RNA_access.hh"
#include "RNA_define.hh"
#include "DEG_depsgraph.hh"
#include "WM_api.hh"
#include "WM_types.hh"
/* ************************** view-based operators **********************************/
/* XXX should these really be here? */
/* -------------------------------------------------------------------- */
/** \name Set Cursor
*
* The 'cursor' in the Graph Editor consists of two parts:
2018-11-14 12:53:15 +11:00
* 1) Current Frame Indicator (as per ANIM_OT_change_frame)
* 2) Value Indicator (stored per Graph Editor instance)
* \{ */
2018-07-02 11:47:00 +02:00
static bool graphview_cursor_poll(bContext *C)
{
/* prevent changes during render */
2019-04-22 09:19:45 +10:00
if (G.is_rendering) {
return false;
2019-04-22 09:19:45 +10:00
}
return ED_operator_graphedit_active(C);
}
/* Set the new frame number */
static void graphview_cursor_apply(bContext *C, wmOperator *op)
{
2012-05-08 20:18:33 +00:00
Scene *scene = CTX_data_scene(C);
2019-02-16 10:16:16 +11:00
SpaceGraph *sipo = CTX_wm_space_graph(C);
/* this isn't technically "frame", but it'll do... */
float frame = RNA_float_get(op->ptr, "frame");
/* adjust the frame or the cursor x-value */
if (sipo->mode == SIPO_MODE_DRIVERS) {
/* adjust cursor x-value */
sipo->cursorTime = frame;
}
else {
/* adjust the frame
* NOTE: sync this part of the code with ANIM_OT_change_frame
*/
/* 1) frame is rounded to the nearest int, since frames are ints */
scene->r.cfra = round_fl_to_int(frame);
if (scene->r.flag & SCER_LOCK_FRAME_SELECTION) {
/* Clip to preview range
* NOTE: Preview range won't go into negative values,
* so only clamping once should be fine.
*/
CLAMP(scene->r.cfra, PSFRA, PEFRA);
}
else {
/* Prevent negative frames */
FRAMENUMBER_MIN_CLAMP(scene->r.cfra);
}
scene->r.subframe = 0.0f;
DEG_id_tag_update(&scene->id, ID_RECALC_FRAME_CHANGE);
}
/* set the cursor value */
2012-05-08 20:18:33 +00:00
sipo->cursorVal = RNA_float_get(op->ptr, "value");
/* send notifiers - notifiers for frame should force an update for both vars ok... */
2012-05-08 20:18:33 +00:00
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
}
/* ... */
/* Non-modal callback for running operator without user input */
static int graphview_cursor_exec(bContext *C, wmOperator *op)
{
graphview_cursor_apply(C, op);
return OPERATOR_FINISHED;
}
/* ... */
/* set the operator properties from the initial event */
static void graphview_cursor_setprops(bContext *C, wmOperator *op, const wmEvent *event)
{
ARegion *region = CTX_wm_region(C);
float viewx, viewy;
/* abort if not active region (should not really be possible) */
if (region == nullptr) {
return;
2019-04-22 09:19:45 +10:00
}
/* convert from region coordinates to View2D 'tot' space */
UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
/* store the values in the operator properties */
/* NOTE: we don't clamp frame here, as it might be used for the drivers cursor */
RNA_float_set(op->ptr, "frame", viewx);
RNA_float_set(op->ptr, "value", viewy);
}
/* Modal Operator init */
static int graphview_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
bScreen *screen = CTX_wm_screen(C);
/* Change to frame that mouse is over before adding modal handler,
* as user could click on a single frame (jump to frame) as well as
* click-dragging over a range (modal scrubbing). Apply this change.
*/
graphview_cursor_setprops(C, op, event);
graphview_cursor_apply(C, op);
/* Signal that a scrubbing operating is starting */
2019-04-22 09:19:45 +10:00
if (screen) {
screen->scrubbing = true;
2019-04-22 09:19:45 +10:00
}
/* add temp handler */
WM_event_add_modal_handler(C, op);
return OPERATOR_RUNNING_MODAL;
}
/* Modal event handling of cursor changing */
static int graphview_cursor_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
bScreen *screen = CTX_wm_screen(C);
Scene *scene = CTX_data_scene(C);
/* execute the events */
switch (event->type) {
case EVT_ESCKEY:
2019-04-22 09:19:45 +10:00
if (screen) {
screen->scrubbing = false;
2019-04-22 09:19:45 +10:00
}
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
return OPERATOR_FINISHED;
case MOUSEMOVE:
/* set the new values */
graphview_cursor_setprops(C, op, event);
graphview_cursor_apply(C, op);
break;
case LEFTMOUSE:
case RIGHTMOUSE:
case MIDDLEMOUSE:
/* We check for either mouse-button to end, to work with all user keymaps. */
if (event->val == KM_RELEASE) {
2019-04-22 09:19:45 +10:00
if (screen) {
screen->scrubbing = false;
2019-04-22 09:19:45 +10:00
}
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
return OPERATOR_FINISHED;
}
break;
}
return OPERATOR_RUNNING_MODAL;
}
static void GRAPH_OT_cursor_set(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Set Cursor";
ot->idname = "GRAPH_OT_cursor_set";
ot->description = "Interactively set the current frame and value cursor";
/* api callbacks */
ot->exec = graphview_cursor_exec;
ot->invoke = graphview_cursor_invoke;
ot->modal = graphview_cursor_modal;
ot->poll = graphview_cursor_poll;
/* flags */
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_CURSOR_X | OPTYPE_UNDO;
/* rna */
RNA_def_float(ot->srna, "frame", 0, MINAFRAMEF, MAXFRAMEF, "Frame", "", MINAFRAMEF, MAXFRAMEF);
2012-08-07 19:49:38 +00:00
RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Value", "", -100.0f, 100.0f);
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Hide/Reveal
* \{ */
static int graphview_curves_hide_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
ListBase anim_data = {nullptr, nullptr};
ListBase all_data = {nullptr, nullptr};
int filter;
const bool unselected = RNA_boolean_get(op->ptr, "unselected");
/* get editor data */
2019-04-22 09:19:45 +10:00
if (ANIM_animdata_get_context(C, &ac) == 0) {
return OPERATOR_CANCELLED;
2019-04-22 09:19:45 +10:00
}
/* get list of all channels that selection may need to be flushed to
* - hierarchy must not affect what we have access to here...
*/
Animation: Add GP layers in regular Dopesheet Grease Pencil animation channels are now also shown in the Dopesheet mode of the Dopesheet editor and in the Timeline. Grease pencil related events are now listened not only by container `SACTCONT_GPENCIL` (Grease Pencil Dopesheet), but also `SACTCONT_DOPESHEET` (main Dopesheet), and `SACTCONT_TIMELINE` (timeline). A new Animation Filter flag was added: `ANIMFILTER_FCURVESONLY`. For now this only filters out Grease Pencil Layer channels. **Implemented:** - Preview range set: now only considers selected Grease Pencil keyframes when `onlySel` parameter is true. Not only this allows the operator to work with grease pencil keyframes in main dopesheet, but it also fixes the operator in the Grease Pencil dopesheet. - Translation: allocation (and freeing) of specific memory for translation of Grease Pencil keyframes. - Copy/Paste: call to both Fcurve and GPencil operators, to allow for mixed selection. Errors are only reported when both the FCurve and GPencil functions fail to paste anything. - Keyframe Type change and Insert Keyframe: removed some code here to unify Grease Pencil dopesheet and main dopesheet code. - Jump, Snap, Mirror, Select all/box/lasso/circle, Select left/right, Clickselect: account for Grease Pencil channels within the channels loop, no need for `ANIMFILTER_FCURVESONLY` there. **Not Implemented:** - Graph-related operators. The filter `ANIMFILTER_FCURVESONLY` is naively added to all graph-related operators, meaning more-or-less all operators that used `ANIMFILTER_CURVE_VISIBLE`. - Select linked: is for F-curves channel only - Select more/less: not yet implemented for grease pencil layers. - Clean Keys, Sample, Extrapolation, Interpolation, Easing, and Handle type change: work on Fcurve-channels only, so the `ANIMFILTER_FCURVESONLY` filter is activated Graying out these operators (when no fcurve keyframe is selected) can be done with custom poll functions BUT may affect performance. This is NOT done in this patch. **Dopesheet Summary Selection:** The main summary of the dopesheet now also takes into account Grease Pencil keyframes, using some nasty copy/pasting of code, as explained [on devtalk](https://devtalk.blender.org/t/gpencil-layers-integration-in-main-dopesheet-selection-issue/24527). It works, but may be improved, providing some deeper changes. Reviewed By: mendio, pepeland, sybren Maniphest Tasks: T97477 Differential Revision: https://developer.blender.org/D15003
2022-06-30 15:16:05 +02:00
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FCURVESONLY | ANIMFILTER_LIST_CHANNELS |
ANIMFILTER_NODUPLIS);
ANIM_animdata_filter(
&ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
/* filter data
* - of the remaining visible curves, we want to hide the ones that are
* selected/unselected (depending on "unselected" prop)
*/
Animation: Add GP layers in regular Dopesheet Grease Pencil animation channels are now also shown in the Dopesheet mode of the Dopesheet editor and in the Timeline. Grease pencil related events are now listened not only by container `SACTCONT_GPENCIL` (Grease Pencil Dopesheet), but also `SACTCONT_DOPESHEET` (main Dopesheet), and `SACTCONT_TIMELINE` (timeline). A new Animation Filter flag was added: `ANIMFILTER_FCURVESONLY`. For now this only filters out Grease Pencil Layer channels. **Implemented:** - Preview range set: now only considers selected Grease Pencil keyframes when `onlySel` parameter is true. Not only this allows the operator to work with grease pencil keyframes in main dopesheet, but it also fixes the operator in the Grease Pencil dopesheet. - Translation: allocation (and freeing) of specific memory for translation of Grease Pencil keyframes. - Copy/Paste: call to both Fcurve and GPencil operators, to allow for mixed selection. Errors are only reported when both the FCurve and GPencil functions fail to paste anything. - Keyframe Type change and Insert Keyframe: removed some code here to unify Grease Pencil dopesheet and main dopesheet code. - Jump, Snap, Mirror, Select all/box/lasso/circle, Select left/right, Clickselect: account for Grease Pencil channels within the channels loop, no need for `ANIMFILTER_FCURVESONLY` there. **Not Implemented:** - Graph-related operators. The filter `ANIMFILTER_FCURVESONLY` is naively added to all graph-related operators, meaning more-or-less all operators that used `ANIMFILTER_CURVE_VISIBLE`. - Select linked: is for F-curves channel only - Select more/less: not yet implemented for grease pencil layers. - Clean Keys, Sample, Extrapolation, Interpolation, Easing, and Handle type change: work on Fcurve-channels only, so the `ANIMFILTER_FCURVESONLY` filter is activated Graying out these operators (when no fcurve keyframe is selected) can be done with custom poll functions BUT may affect performance. This is NOT done in this patch. **Dopesheet Summary Selection:** The main summary of the dopesheet now also takes into account Grease Pencil keyframes, using some nasty copy/pasting of code, as explained [on devtalk](https://devtalk.blender.org/t/gpencil-layers-integration-in-main-dopesheet-selection-issue/24527). It works, but may be improved, providing some deeper changes. Reviewed By: mendio, pepeland, sybren Maniphest Tasks: T97477 Differential Revision: https://developer.blender.org/D15003
2022-06-30 15:16:05 +02:00
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FCURVESONLY | ANIMFILTER_CURVE_VISIBLE |
ANIMFILTER_NODUPLIS);
2019-04-22 09:19:45 +10:00
if (unselected) {
filter |= ANIMFILTER_UNSEL;
2019-04-22 09:19:45 +10:00
}
else {
filter |= ANIMFILTER_SEL;
2019-04-22 09:19:45 +10:00
}
ANIM_animdata_filter(
&ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
/* hack: skip object channels for now, since flushing those will always flush everything,
* but they are always included */
/* TODO: find out why this is the case, and fix that */
2019-04-22 09:19:45 +10:00
if (ale->type == ANIMTYPE_OBJECT) {
continue;
2019-04-22 09:19:45 +10:00
}
/* change the hide setting, and unselect it... */
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR);
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_SELECT, ACHANNEL_SETFLAG_CLEAR);
/* now, also flush selection status up/down as appropriate */
ANIM_flush_setting_anim_channels(
&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_CLEAR);
}
/* cleanup */
ANIM_animdata_freelist(&anim_data);
BLI_freelistN(&all_data);
/* unhide selected */
if (unselected) {
/* turn off requirement for visible */
Animation: Add GP layers in regular Dopesheet Grease Pencil animation channels are now also shown in the Dopesheet mode of the Dopesheet editor and in the Timeline. Grease pencil related events are now listened not only by container `SACTCONT_GPENCIL` (Grease Pencil Dopesheet), but also `SACTCONT_DOPESHEET` (main Dopesheet), and `SACTCONT_TIMELINE` (timeline). A new Animation Filter flag was added: `ANIMFILTER_FCURVESONLY`. For now this only filters out Grease Pencil Layer channels. **Implemented:** - Preview range set: now only considers selected Grease Pencil keyframes when `onlySel` parameter is true. Not only this allows the operator to work with grease pencil keyframes in main dopesheet, but it also fixes the operator in the Grease Pencil dopesheet. - Translation: allocation (and freeing) of specific memory for translation of Grease Pencil keyframes. - Copy/Paste: call to both Fcurve and GPencil operators, to allow for mixed selection. Errors are only reported when both the FCurve and GPencil functions fail to paste anything. - Keyframe Type change and Insert Keyframe: removed some code here to unify Grease Pencil dopesheet and main dopesheet code. - Jump, Snap, Mirror, Select all/box/lasso/circle, Select left/right, Clickselect: account for Grease Pencil channels within the channels loop, no need for `ANIMFILTER_FCURVESONLY` there. **Not Implemented:** - Graph-related operators. The filter `ANIMFILTER_FCURVESONLY` is naively added to all graph-related operators, meaning more-or-less all operators that used `ANIMFILTER_CURVE_VISIBLE`. - Select linked: is for F-curves channel only - Select more/less: not yet implemented for grease pencil layers. - Clean Keys, Sample, Extrapolation, Interpolation, Easing, and Handle type change: work on Fcurve-channels only, so the `ANIMFILTER_FCURVESONLY` filter is activated Graying out these operators (when no fcurve keyframe is selected) can be done with custom poll functions BUT may affect performance. This is NOT done in this patch. **Dopesheet Summary Selection:** The main summary of the dopesheet now also takes into account Grease Pencil keyframes, using some nasty copy/pasting of code, as explained [on devtalk](https://devtalk.blender.org/t/gpencil-layers-integration-in-main-dopesheet-selection-issue/24527). It works, but may be improved, providing some deeper changes. Reviewed By: mendio, pepeland, sybren Maniphest Tasks: T97477 Differential Revision: https://developer.blender.org/D15003
2022-06-30 15:16:05 +02:00
filter = ANIMFILTER_SEL | ANIMFILTER_NODUPLIS | ANIMFILTER_LIST_CHANNELS |
ANIMFILTER_FCURVESONLY;
/* flushing has been done */
ANIM_animdata_filter(
&ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
/* hack: skip object channels for now, since flushing those
* will always flush everything, but they are always included */
/* TODO: find out why this is the case, and fix that */
2019-04-22 09:19:45 +10:00
if (ale->type == ANIMTYPE_OBJECT) {
continue;
2019-04-22 09:19:45 +10:00
}
/* change the hide setting, and unselect it... */
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_SELECT, ACHANNEL_SETFLAG_ADD);
/* now, also flush selection status up/down as appropriate */
ANIM_flush_setting_anim_channels(
&ac, &anim_data, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
}
ANIM_animdata_freelist(&anim_data);
}
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, nullptr);
return OPERATOR_FINISHED;
}
static void GRAPH_OT_hide(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Hide Curves";
ot->idname = "GRAPH_OT_hide";
ot->description = "Hide selected curves from Graph Editor view";
/* api callbacks */
ot->exec = graphview_curves_hide_exec;
ot->poll = ED_operator_graphedit_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* props */
RNA_def_boolean(
ot->srna, "unselected", false, "Unselected", "Hide unselected rather than selected curves");
}
/* ........ */
static int graphview_curves_reveal_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
ListBase anim_data = {nullptr, nullptr};
ListBase all_data = {nullptr, nullptr};
int filter;
const bool select = RNA_boolean_get(op->ptr, "select");
/* get editor data */
2019-04-22 09:19:45 +10:00
if (ANIM_animdata_get_context(C, &ac) == 0) {
return OPERATOR_CANCELLED;
2019-04-22 09:19:45 +10:00
}
/* get list of all channels that selection may need to be flushed to
* - hierarchy must not affect what we have access to here...
*/
Animation: Add GP layers in regular Dopesheet Grease Pencil animation channels are now also shown in the Dopesheet mode of the Dopesheet editor and in the Timeline. Grease pencil related events are now listened not only by container `SACTCONT_GPENCIL` (Grease Pencil Dopesheet), but also `SACTCONT_DOPESHEET` (main Dopesheet), and `SACTCONT_TIMELINE` (timeline). A new Animation Filter flag was added: `ANIMFILTER_FCURVESONLY`. For now this only filters out Grease Pencil Layer channels. **Implemented:** - Preview range set: now only considers selected Grease Pencil keyframes when `onlySel` parameter is true. Not only this allows the operator to work with grease pencil keyframes in main dopesheet, but it also fixes the operator in the Grease Pencil dopesheet. - Translation: allocation (and freeing) of specific memory for translation of Grease Pencil keyframes. - Copy/Paste: call to both Fcurve and GPencil operators, to allow for mixed selection. Errors are only reported when both the FCurve and GPencil functions fail to paste anything. - Keyframe Type change and Insert Keyframe: removed some code here to unify Grease Pencil dopesheet and main dopesheet code. - Jump, Snap, Mirror, Select all/box/lasso/circle, Select left/right, Clickselect: account for Grease Pencil channels within the channels loop, no need for `ANIMFILTER_FCURVESONLY` there. **Not Implemented:** - Graph-related operators. The filter `ANIMFILTER_FCURVESONLY` is naively added to all graph-related operators, meaning more-or-less all operators that used `ANIMFILTER_CURVE_VISIBLE`. - Select linked: is for F-curves channel only - Select more/less: not yet implemented for grease pencil layers. - Clean Keys, Sample, Extrapolation, Interpolation, Easing, and Handle type change: work on Fcurve-channels only, so the `ANIMFILTER_FCURVESONLY` filter is activated Graying out these operators (when no fcurve keyframe is selected) can be done with custom poll functions BUT may affect performance. This is NOT done in this patch. **Dopesheet Summary Selection:** The main summary of the dopesheet now also takes into account Grease Pencil keyframes, using some nasty copy/pasting of code, as explained [on devtalk](https://devtalk.blender.org/t/gpencil-layers-integration-in-main-dopesheet-selection-issue/24527). It works, but may be improved, providing some deeper changes. Reviewed By: mendio, pepeland, sybren Maniphest Tasks: T97477 Differential Revision: https://developer.blender.org/D15003
2022-06-30 15:16:05 +02:00
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_CHANNELS | ANIMFILTER_NODUPLIS |
ANIMFILTER_FCURVESONLY);
ANIM_animdata_filter(
&ac, &all_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
/* filter data
* - just go through all visible channels, ensuring that everything is set to be curve-visible
*/
Animation: Add GP layers in regular Dopesheet Grease Pencil animation channels are now also shown in the Dopesheet mode of the Dopesheet editor and in the Timeline. Grease pencil related events are now listened not only by container `SACTCONT_GPENCIL` (Grease Pencil Dopesheet), but also `SACTCONT_DOPESHEET` (main Dopesheet), and `SACTCONT_TIMELINE` (timeline). A new Animation Filter flag was added: `ANIMFILTER_FCURVESONLY`. For now this only filters out Grease Pencil Layer channels. **Implemented:** - Preview range set: now only considers selected Grease Pencil keyframes when `onlySel` parameter is true. Not only this allows the operator to work with grease pencil keyframes in main dopesheet, but it also fixes the operator in the Grease Pencil dopesheet. - Translation: allocation (and freeing) of specific memory for translation of Grease Pencil keyframes. - Copy/Paste: call to both Fcurve and GPencil operators, to allow for mixed selection. Errors are only reported when both the FCurve and GPencil functions fail to paste anything. - Keyframe Type change and Insert Keyframe: removed some code here to unify Grease Pencil dopesheet and main dopesheet code. - Jump, Snap, Mirror, Select all/box/lasso/circle, Select left/right, Clickselect: account for Grease Pencil channels within the channels loop, no need for `ANIMFILTER_FCURVESONLY` there. **Not Implemented:** - Graph-related operators. The filter `ANIMFILTER_FCURVESONLY` is naively added to all graph-related operators, meaning more-or-less all operators that used `ANIMFILTER_CURVE_VISIBLE`. - Select linked: is for F-curves channel only - Select more/less: not yet implemented for grease pencil layers. - Clean Keys, Sample, Extrapolation, Interpolation, Easing, and Handle type change: work on Fcurve-channels only, so the `ANIMFILTER_FCURVESONLY` filter is activated Graying out these operators (when no fcurve keyframe is selected) can be done with custom poll functions BUT may affect performance. This is NOT done in this patch. **Dopesheet Summary Selection:** The main summary of the dopesheet now also takes into account Grease Pencil keyframes, using some nasty copy/pasting of code, as explained [on devtalk](https://devtalk.blender.org/t/gpencil-layers-integration-in-main-dopesheet-selection-issue/24527). It works, but may be improved, providing some deeper changes. Reviewed By: mendio, pepeland, sybren Maniphest Tasks: T97477 Differential Revision: https://developer.blender.org/D15003
2022-06-30 15:16:05 +02:00
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_NODUPLIS |
ANIMFILTER_FCURVESONLY);
ANIM_animdata_filter(
&ac, &anim_data, eAnimFilter_Flags(filter), ac.data, eAnimCont_Types(ac.datatype));
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
/* hack: skip object channels for now, since flushing those will always flush everything,
* but they are always included. */
/* TODO: find out why this is the case, and fix that */
2019-04-22 09:19:45 +10:00
if (ale->type == ANIMTYPE_OBJECT) {
continue;
2019-04-22 09:19:45 +10:00
}
/* select if it is not visible */
if (ANIM_channel_setting_get(&ac, ale, ACHANNEL_SETTING_VISIBLE) == 0) {
ANIM_channel_setting_set(&ac,
ale,
ACHANNEL_SETTING_SELECT,
select ? ACHANNEL_SETFLAG_ADD : ACHANNEL_SETFLAG_CLEAR);
}
/* change the visibility setting */
ANIM_channel_setting_set(&ac, ale, ACHANNEL_SETTING_VISIBLE, ACHANNEL_SETFLAG_ADD);
/* now, also flush selection status up/down as appropriate */
ANIM_flush_setting_anim_channels(
&ac, &all_data, ale, ACHANNEL_SETTING_VISIBLE, eAnimChannels_SetFlag(true));
}
/* cleanup */
ANIM_animdata_freelist(&anim_data);
BLI_freelistN(&all_data);
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, nullptr);
return OPERATOR_FINISHED;
}
static void GRAPH_OT_reveal(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Reveal Curves";
ot->idname = "GRAPH_OT_reveal";
ot->description = "Make previously hidden curves visible again in Graph Editor view";
/* api callbacks */
ot->exec = graphview_curves_reveal_exec;
ot->poll = ED_operator_graphedit_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_boolean(ot->srna, "select", true, "Select", "");
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Registration: operator types
* \{ */
void graphedit_operatortypes()
{
/* view */
WM_operatortype_append(GRAPH_OT_cursor_set);
WM_operatortype_append(GRAPH_OT_previewrange_set);
WM_operatortype_append(GRAPH_OT_view_all);
WM_operatortype_append(GRAPH_OT_view_selected);
WM_operatortype_append(GRAPH_OT_view_frame);
WM_operatortype_append(GRAPH_OT_ghost_curves_create);
WM_operatortype_append(GRAPH_OT_ghost_curves_clear);
WM_operatortype_append(GRAPH_OT_hide);
WM_operatortype_append(GRAPH_OT_reveal);
/* keyframes */
2012-05-08 20:18:33 +00:00
/* selection */
WM_operatortype_append(GRAPH_OT_clickselect);
WM_operatortype_append(GRAPH_OT_select_all);
WM_operatortype_append(GRAPH_OT_select_box);
WM_operatortype_append(GRAPH_OT_select_lasso);
WM_operatortype_append(GRAPH_OT_select_circle);
WM_operatortype_append(GRAPH_OT_select_column);
WM_operatortype_append(GRAPH_OT_select_linked);
WM_operatortype_append(GRAPH_OT_select_more);
WM_operatortype_append(GRAPH_OT_select_less);
WM_operatortype_append(GRAPH_OT_select_leftright);
WM_operatortype_append(GRAPH_OT_select_key_handles);
2012-05-08 20:18:33 +00:00
/* editing */
WM_operatortype_append(GRAPH_OT_snap);
WM_operatortype_append(GRAPH_OT_equalize_handles);
WM_operatortype_append(GRAPH_OT_mirror);
WM_operatortype_append(GRAPH_OT_frame_jump);
WM_operatortype_append(GRAPH_OT_keyframe_jump);
WM_operatortype_append(GRAPH_OT_snap_cursor_value);
WM_operatortype_append(GRAPH_OT_handle_type);
WM_operatortype_append(GRAPH_OT_interpolation_type);
WM_operatortype_append(GRAPH_OT_extrapolation_type);
WM_operatortype_append(GRAPH_OT_easing_type);
WM_operatortype_append(GRAPH_OT_bake_keys);
WM_operatortype_append(GRAPH_OT_keys_to_samples);
WM_operatortype_append(GRAPH_OT_samples_to_keys);
WM_operatortype_append(GRAPH_OT_sound_to_samples);
WM_operatortype_append(GRAPH_OT_smooth);
WM_operatortype_append(GRAPH_OT_clean);
WM_operatortype_append(GRAPH_OT_decimate);
WM_operatortype_append(GRAPH_OT_blend_to_neighbor);
WM_operatortype_append(GRAPH_OT_breakdown);
WM_operatortype_append(GRAPH_OT_ease);
WM_operatortype_append(GRAPH_OT_shear);
WM_operatortype_append(GRAPH_OT_scale_average);
WM_operatortype_append(GRAPH_OT_blend_offset);
WM_operatortype_append(GRAPH_OT_blend_to_ease);
WM_operatortype_append(GRAPH_OT_match_slope);
WM_operatortype_append(GRAPH_OT_time_offset);
WM_operatortype_append(GRAPH_OT_blend_to_default);
WM_operatortype_append(GRAPH_OT_push_pull);
WM_operatortype_append(GRAPH_OT_gaussian_smooth);
Animation: Butterworth Smoothing filter Implements the Butterworth Filter (https://en.wikipedia.org/wiki/Butterworth_filter) for smoothing FCurves. This filter is ideal for smoothing dense data, like motion capture recordings. It has the advantage of keeping the shape of the curve intact while reducing minimal fluctuations. The disadvantage is the impulse response has a twang, meaning extreme spikes cause fluctuations to either side. The implementation is based on the GPL code found here: https://exstrom.com/journal/sigproc/dsigproc.html In order to avoid phase shifting, the filter is run forward and backward, effectively doubling the filter order. The Redo panel offers the following options * Frequency Cutoff: 0-n value, where 0 means it cuts everything so the curve will become straight, the max value is the Nyquist frequency and depends on the frame rate and the "Samples per Frame" option * Filter Order: Higher values mean the frequency cutoff is steeper * Samples per Frame: Before the filter is applied, the curve is resampled at this interval to avoid errors when there are uneven spaces between frames. If the keys are on subframes, e.g. a 60fps file in a 30fps scene, increase this value to 2 * Blend: 0-1 value to blend between the original curve and the filter result * Blend In/Out: The number of frames at the start and end for which to blend between the filtered and unfiltered curve. This can help reduce any resulting jumps in the animation at the selection border The operator can be called from the Key menu. (Key->Smooth->Butterworth Smooth) Pull Request: https://projects.blender.org/blender/blender/pulls/106952
2023-07-13 09:10:42 +02:00
WM_operatortype_append(GRAPH_OT_butterworth_smooth);
WM_operatortype_append(GRAPH_OT_euler_filter);
WM_operatortype_append(GRAPH_OT_delete);
WM_operatortype_append(GRAPH_OT_duplicate);
WM_operatortype_append(GRAPH_OT_copy);
WM_operatortype_append(GRAPH_OT_paste);
operator renaming for more consistent word ordering (_add/_remmove shold be last, ACT_OT_* --> ACTION_OT_*) ACT_OT_clean --> ACTION_OT_clean ACT_OT_clickselect --> ACTION_OT_clickselect ACT_OT_copy --> ACTION_OT_copy ACT_OT_delete --> ACTION_OT_delete ACT_OT_duplicate --> ACTION_OT_duplicate ACT_OT_extrapolation_type --> ACTION_OT_extrapolation_type ACT_OT_frame_jump --> ACTION_OT_frame_jump ACT_OT_handle_type --> ACTION_OT_handle_type ACT_OT_insert_keyframe --> ACTION_OT_insert_keyframe ACT_OT_insert_keyframe --> ACT_OT_keyframe_insert ACT_OT_interpolation_type --> ACTION_OT_interpolation_type ACT_OT_keyframe_type --> ACTION_OT_keyframe_type ACT_OT_mirror --> ACTION_OT_mirror ACT_OT_new --> ACTION_OT_new ACT_OT_paste --> ACTION_OT_paste ACT_OT_previewrange_set --> ACTION_OT_previewrange_set ACT_OT_properties --> ACTION_OT_properties ACT_OT_sample --> ACTION_OT_sample ACT_OT_select_all_toggle --> ACTION_OT_select_all_toggle ACT_OT_select_border --> ACTION_OT_select_border ACT_OT_select_column --> ACTION_OT_select_column ACT_OT_snap --> ACTION_OT_snap ACT_OT_test --> ACTION_OT_test ACT_OT_unlink --> ACTION_OT_unlink ACT_OT_view_all --> ACTION_OT_view_all ANIM_OT_add_driver_button --> ANIM_OT_driver_button_add ANIM_OT_add_keyingset_button --> ANIM_OT_keyingset_button_add ANIM_OT_delete_keyframe --> ANIM_OT_keyframe_delete ANIM_OT_delete_keyframe_button --> ANIM_OT_keyframe_delete_button ANIM_OT_delete_keyframe_v3d --> ANIM_OT_keyframe_delete_v3d ANIM_OT_insert_keyframe --> ANIM_OT_keyframe_insert ANIM_OT_insert_keyframe_button --> ANIM_OT_keyframe_insert_button ANIM_OT_insert_keyframe_menu --> ANIM_OT_keyframe_insert_menu ANIM_OT_remove_driver_button --> ANIM_OT_driver_button_remove ANIM_OT_remove_keyingset_button --> ANIM_OT_keyingset_button_remove FILE_OT_add_bookmark --> FILE_OT_bookmark_add GRAPH_OT_insert_keyframe --> GRAPH_OT_keyframe_insert NLA_OT_add_actionclip --> NLA_OT_actionclip_add NLA_OT_add_meta --> NLA_OT_meta_add NLA_OT_add_tracks --> NLA_OT_tracks_add NLA_OT_add_transition --> NLA_OT_transition_add NLA_OT_remove_meta --> NLA_OT_meta_remove PARTICLE_OT_remove_target --> PARTICLE_OT_target_remove PTCACHE_OT_add_new --> PTCACHE_OT_add
2009-11-28 14:37:21 +00:00
WM_operatortype_append(GRAPH_OT_keyframe_insert);
WM_operatortype_append(GRAPH_OT_click_insert);
/* F-Curve Modifiers */
WM_operatortype_append(GRAPH_OT_fmodifier_add);
WM_operatortype_append(GRAPH_OT_fmodifier_copy);
WM_operatortype_append(GRAPH_OT_fmodifier_paste);
/* Drivers */
WM_operatortype_append(GRAPH_OT_driver_variables_copy);
WM_operatortype_append(GRAPH_OT_driver_variables_paste);
WM_operatortype_append(GRAPH_OT_driver_delete_invalid);
}
void ED_operatormacros_graph()
{
wmOperatorType *ot;
wmOperatorTypeMacro *otmacro;
ot = WM_operatortype_append_macro("GRAPH_OT_duplicate_move",
"Duplicate",
"Make a copy of all selected keyframes and move them",
2012-05-08 20:18:33 +00:00
OPTYPE_UNDO | OPTYPE_REGISTER);
WM_operatortype_macro_define(ot, "GRAPH_OT_duplicate");
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_boolean_set(otmacro->ptr, "use_duplicated_keyframes", true);
RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Registration: Key-Maps
* \{ */
void graphedit_keymap(wmKeyConfig *keyconf)
{
/* keymap for all regions */
WM_keymap_ensure(keyconf, "Graph Editor Generic", SPACE_GRAPH, RGN_TYPE_WINDOW);
/* channels */
/* Channels are not directly handled by the Graph Editor module,
* but are inherited from the Animation module.
* All the relevant operations, keymaps, drawing, etc.
* can therefore all be found in that module instead,
* as these are all used for the Graph Editor too.
*/
/* keyframes */
WM_keymap_ensure(keyconf, "Graph Editor", SPACE_GRAPH, RGN_TYPE_WINDOW);
}
/** \} */