This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/space_graph/graph_utils.c

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

301 lines
8.1 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0-or-later
* Copyright 2009 Blender Foundation. All rights reserved. */
/** \file
* \ingroup spgraph
2011-02-27 20:29:51 +00:00
*/
#include <float.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "DNA_anim_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BKE_context.h"
#include "BKE_fcurve.h"
#include "BKE_screen.h"
#include "ED_anim_api.h"
#include "ED_screen.h"
#include "UI_interface.h"
#include "RNA_access.h"
#include "RNA_prototypes.h"
2012-05-08 20:18:33 +00:00
#include "graph_intern.h" /* own include */
/* -------------------------------------------------------------------- */
/** \name Set Up Drivers Editor
* \{ */
void ED_drivers_editor_init(bContext *C, ScrArea *area)
{
SpaceGraph *sipo = (SpaceGraph *)area->spacedata.first;
/* Set mode */
sipo->mode = SIPO_MODE_DRIVERS;
/* Show Properties Region (or else the settings can't be edited) */
ARegion *region_props = BKE_area_find_region_type(area, RGN_TYPE_UI);
if (region_props) {
UI_panel_category_active_set(region_props, "Drivers");
region_props->flag &= ~RGN_FLAG_HIDDEN;
/* XXX: Adjust width of this too? */
ED_region_visibility_change_update(C, area, region_props);
}
else {
printf("%s: Couldn't find properties region for Drivers Editor - %p\n", __func__, area);
}
/* Adjust framing in graph region */
/* TODO: Have a way of not resetting this every time?
* (e.g. So that switching back and forth between editors doesn't keep jumping?)
*/
ARegion *region_main = BKE_area_find_region_type(area, RGN_TYPE_WINDOW);
if (region_main) {
/* XXX: Ideally we recenter based on the range instead... */
region_main->v2d.tot.xmin = -2.0f;
region_main->v2d.tot.ymin = -2.0f;
region_main->v2d.tot.xmax = 2.0f;
region_main->v2d.tot.ymax = 2.0f;
region_main->v2d.cur = region_main->v2d.tot;
}
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Active F-Curve
* \{ */
2012-05-08 20:18:33 +00:00
bAnimListElem *get_active_fcurve_channel(bAnimContext *ac)
{
ListBase anim_data = {NULL, NULL};
2012-05-08 20:18:33 +00:00
int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_ACTIVE);
size_t items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* We take the first F-Curve only, since some other ones may have had 'active' flag set
* if they were from linked data.
*/
if (items) {
2012-05-08 20:18:33 +00:00
bAnimListElem *ale = (bAnimListElem *)anim_data.first;
/* remove first item from list, then free the rest of the list and return the stored one */
BLI_remlink(&anim_data, ale);
ANIM_animdata_freelist(&anim_data);
return ale;
}
/* no active F-Curve */
return NULL;
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Operator Polling Callbacks
* \{ */
2018-07-02 11:47:00 +02:00
bool graphop_visible_keyframes_poll(bContext *C)
{
bAnimContext ac;
bAnimListElem *ale;
ListBase anim_data = {NULL, NULL};
ScrArea *area = CTX_wm_area(C);
size_t items;
int filter;
bool found = false;
/* firstly, check if in Graph Editor */
/* TODO: also check for region? */
if ((area == NULL) || (area->spacetype != SPACE_GRAPH)) {
return found;
2019-04-22 09:19:45 +10:00
}
/* try to init Anim-Context stuff ourselves and check */
2019-04-22 09:19:45 +10:00
if (ANIM_animdata_get_context(C, &ac) == 0) {
return found;
2019-04-22 09:19:45 +10:00
}
/* loop over the visible (selection doesn't matter) F-Curves, and see if they're suitable
* stopping on the first successful match
*/
2012-05-08 20:18:33 +00:00
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE);
items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
2019-04-22 09:19:45 +10:00
if (items == 0) {
return found;
2019-04-22 09:19:45 +10:00
}
2012-05-08 20:18:33 +00:00
for (ale = anim_data.first; ale; ale = ale->next) {
FCurve *fcu = (FCurve *)ale->data;
/* visible curves for selection must fulfill the following criteria:
2018-11-14 12:53:15 +11:00
* - it has bezier keyframes
* - F-Curve modifiers do not interfere with the result too much
* (i.e. the modifier-control drawing check returns false)
*/
2019-04-22 09:19:45 +10:00
if (fcu->bezt == NULL) {
continue;
2019-04-22 09:19:45 +10:00
}
2020-06-05 09:30:15 +02:00
if (BKE_fcurve_are_keyframes_usable(fcu)) {
found = true;
break;
}
}
/* cleanup and return findings */
ANIM_animdata_freelist(&anim_data);
return found;
}
2018-07-02 11:47:00 +02:00
bool graphop_editable_keyframes_poll(bContext *C)
{
bAnimContext ac;
bAnimListElem *ale;
ListBase anim_data = {NULL, NULL};
ScrArea *area = CTX_wm_area(C);
size_t items;
int filter;
bool found = false;
/* firstly, check if in Graph Editor */
/* TODO: also check for region? */
if ((area == NULL) || (area->spacetype != SPACE_GRAPH)) {
return found;
2019-04-22 09:19:45 +10:00
}
/* try to init Anim-Context stuff ourselves and check */
2019-04-22 09:19:45 +10:00
if (ANIM_animdata_get_context(C, &ac) == 0) {
return found;
2019-04-22 09:19:45 +10:00
}
/* loop over the editable F-Curves, and see if they're suitable
* stopping on the first successful match
*/
2012-05-08 20:18:33 +00:00
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVE_VISIBLE);
items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
2019-04-22 09:19:45 +10:00
if (items == 0) {
CTX_wm_operator_poll_msg_set(C, "There is no animation data to operate on");
return found;
2019-04-22 09:19:45 +10:00
}
2012-05-08 20:18:33 +00:00
for (ale = anim_data.first; ale; ale = ale->next) {
FCurve *fcu = (FCurve *)ale->data;
/* editable curves must fulfill the following criteria:
2018-11-14 12:53:15 +11:00
* - it has bezier keyframes
* - it must not be protected from editing (this is already checked for with the edit flag
* - F-Curve modifiers do not interfere with the result too much
* (i.e. the modifier-control drawing check returns false)
*/
if (fcu->bezt == NULL && fcu->fpt != NULL) {
/* This is a baked curve, it is never editable. */
continue;
2019-04-22 09:19:45 +10:00
}
2020-06-05 09:30:15 +02:00
if (BKE_fcurve_is_keyframable(fcu)) {
found = true;
break;
}
}
/* cleanup and return findings */
ANIM_animdata_freelist(&anim_data);
return found;
}
2018-07-02 11:47:00 +02:00
bool graphop_active_fcurve_poll(bContext *C)
{
bAnimContext ac;
bAnimListElem *ale;
ScrArea *area = CTX_wm_area(C);
bool has_fcurve = false;
/* firstly, check if in Graph Editor */
/* TODO: also check for region? */
if ((area == NULL) || (area->spacetype != SPACE_GRAPH)) {
return has_fcurve;
2019-04-22 09:19:45 +10:00
}
/* try to init Anim-Context stuff ourselves and check */
2019-04-22 09:19:45 +10:00
if (ANIM_animdata_get_context(C, &ac) == 0) {
return has_fcurve;
2019-04-22 09:19:45 +10:00
}
/* try to get the Active F-Curve */
2012-05-08 20:18:33 +00:00
ale = get_active_fcurve_channel(&ac);
2019-04-22 09:19:45 +10:00
if (ale == NULL) {
return has_fcurve;
2019-04-22 09:19:45 +10:00
}
/* Do we have a suitable F-Curves?
* - For most cases, NLA Control Curves are sufficiently similar to NLA
* curves to serve this role too. Under the hood, they are F-Curves too.
* The only problems which will arise here are if these need to be
* in an Action too (but drivers would then also be affected!)
*/
has_fcurve = ((ale->data) && ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE));
Animation Channel Filtering Refactor - Part 3 (Visibility Flag Split) * This (big) commit is aimed at cleaning up the filtering flags used by the animation channel filtering code. The list of filtering flags has been growing a bit "organically" since it's humble origins for use in the Action Editor some 3 years (IIRC) ago now during a weekend hackathon. Obviously, some things have ended up tacked on, while others have been the product of other flag options. Nevertheless, it was time for a bit of a spring clean! * Most notably, one area where the system outgrown its original design for the Action Editor was in terms of the "visibility" filtering flag it was using. While in the Action Editor the concept of what channels to include was strictly dictated by whether the channel hierarchy showed it, in the Graph Editor this is not always the case. In other words, there was a difference between the data the channels represented being visible and the channels for that data being visible in the hierarchy. Long story short: this lead to bug report [#27076] (and many like it), where if you selected an F-Curve, then collapsed the Group it was in, then even after selecting another F-Curve in another Group, the original F-Curve's properties would still be shown in the Properties Region. The good news is that this commit fixes this issue right away! * More good news will follow, as I start checking on the flag usage of other tools, but I'm committing this first so that we have a stable reference (of code similar to the old buggy stuff) on which we can fall back to later to find bugs (should they pop up). Anyways, back to the trenches!
2011-06-22 11:41:26 +00:00
if (has_fcurve) {
2012-05-08 20:18:33 +00:00
FCurve *fcu = (FCurve *)ale->data;
has_fcurve = (fcu->flag & FCURVE_VISIBLE) != 0;
}
/* free temp data... */
MEM_freeN(ale);
/* return success */
return has_fcurve;
}
bool graphop_active_editable_fcurve_ctx_poll(bContext *C)
{
PointerRNA ptr = CTX_data_pointer_get_type(C, "active_editable_fcurve", &RNA_FCurve);
return ptr.data != NULL;
}
2018-07-02 11:47:00 +02:00
bool graphop_selected_fcurve_poll(bContext *C)
{
bAnimContext ac;
ListBase anim_data = {NULL, NULL};
ScrArea *area = CTX_wm_area(C);
size_t items;
int filter;
/* firstly, check if in Graph Editor */
/* TODO: also check for region? */
if ((area == NULL) || (area->spacetype != SPACE_GRAPH)) {
return false;
2019-04-22 09:19:45 +10:00
}
/* try to init Anim-Context stuff ourselves and check */
2019-04-22 09:19:45 +10:00
if (ANIM_animdata_get_context(C, &ac) == 0) {
return false;
2019-04-22 09:19:45 +10:00
}
/* Get the editable + selected F-Curves, and as long as we got some, we can return.
* NOTE: curve-visible flag isn't included,
* otherwise selecting a curve via list to edit is too cumbersome. */
2012-05-08 20:18:33 +00:00
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_SEL | ANIMFILTER_FOREDIT);
items = ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
2019-04-22 09:19:45 +10:00
if (items == 0) {
return false;
2019-04-22 09:19:45 +10:00
}
/* cleanup and return findings */
ANIM_animdata_freelist(&anim_data);
return true;
}
/** \} */