[Bf-blender-cvs] [1f09dcc121a] master: Cleanup: Animation, split `graph_edit.c` into separate files

Christoph Lendenfeld noreply at git.blender.org
Mon Nov 23 15:27:10 CET 2020


Commit: 1f09dcc121ab31fe08c76947820ed59ec8f76788
Author: Christoph Lendenfeld
Date:   Mon Nov 23 15:11:51 2020 +0100
Branches: master
https://developer.blender.org/rB1f09dcc121ab31fe08c76947820ed59ec8f76788

Cleanup: Animation, split `graph_edit.c` into separate files

Split some of the code of `graph_edit.c` into:
* `graph_view.c`: preview range, view all, view selected etc.
* `graph_slider_ops.c`: the decimate modal operator code.

The latter file will be extended later with more slider-based operators.

Maniphest Tasks: T81785

Reviewed By: sybren

Differential Revision: https://developer.blender.org/D9312

===================================================================

M	source/blender/editors/space_graph/CMakeLists.txt
M	source/blender/editors/space_graph/graph_edit.c
A	source/blender/editors/space_graph/graph_slider_ops.c
A	source/blender/editors/space_graph/graph_view.c

===================================================================

diff --git a/source/blender/editors/space_graph/CMakeLists.txt b/source/blender/editors/space_graph/CMakeLists.txt
index fd5c5863608..414e5c87f5a 100644
--- a/source/blender/editors/space_graph/CMakeLists.txt
+++ b/source/blender/editors/space_graph/CMakeLists.txt
@@ -34,8 +34,10 @@ set(SRC
   graph_draw.c
   graph_edit.c
   graph_ops.c
+  graph_slider_ops.c
   graph_select.c
   graph_utils.c
+  graph_view.c
   space_graph.c
 
   graph_intern.h
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index bcd3adec1ab..1647fd4a6a6 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -61,7 +61,6 @@
 #include "ED_keyframes_edit.h"
 #include "ED_keyframing.h"
 #include "ED_markers.h"
-#include "ED_numinput.h"
 #include "ED_screen.h"
 #include "ED_transform.h"
 
@@ -71,497 +70,7 @@
 #include "graph_intern.h"
 
 /* ************************************************************************** */
-/* KEYFRAME-RANGE STUFF */
-
-/* *************************** Calculate Range ************************** */
-
-/* Get the min/max keyframes. */
-/* Note: it should return total boundbox, filter for selection only can be argument... */
-void get_graph_keyframe_extents(bAnimContext *ac,
-                                float *xmin,
-                                float *xmax,
-                                float *ymin,
-                                float *ymax,
-                                const bool do_sel_only,
-                                const bool include_handles)
-{
-  Scene *scene = ac->scene;
-  SpaceGraph *sipo = (SpaceGraph *)ac->sl;
-
-  ListBase anim_data = {NULL, NULL};
-  bAnimListElem *ale;
-  int filter;
-
-  /* Get data to filter, from Dopesheet. */
-  filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
-  if (sipo->flag & SIPO_SELCUVERTSONLY) {
-    filter |= ANIMFILTER_SEL;
-  }
-
-  ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
-
-  /* Set large values initial values that will be easy to override. */
-  if (xmin) {
-    *xmin = 999999999.0f;
-  }
-  if (xmax) {
-    *xmax = -999999999.0f;
-  }
-  if (ymin) {
-    *ymin = 999999999.0f;
-  }
-  if (ymax) {
-    *ymax = -999999999.0f;
-  }
-
-  /* Check if any channels to set range with. */
-  if (anim_data.first) {
-    bool foundBounds = false;
-
-    /* Go through channels, finding max extents. */
-    for (ale = anim_data.first; ale; ale = ale->next) {
-      AnimData *adt = ANIM_nla_mapping_get(ac, ale);
-      FCurve *fcu = (FCurve *)ale->key_data;
-      float txmin, txmax, tymin, tymax;
-      float unitFac, offset;
-
-      /* Get range. */
-      if (BKE_fcurve_calc_bounds(
-              fcu, &txmin, &txmax, &tymin, &tymax, do_sel_only, include_handles)) {
-        short mapping_flag = ANIM_get_normalization_flags(ac);
-
-        /* Apply NLA scaling. */
-        if (adt) {
-          txmin = BKE_nla_tweakedit_remap(adt, txmin, NLATIME_CONVERT_MAP);
-          txmax = BKE_nla_tweakedit_remap(adt, txmax, NLATIME_CONVERT_MAP);
-        }
-
-        /* Apply unit corrections. */
-        unitFac = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag, &offset);
-        tymin += offset;
-        tymax += offset;
-        tymin *= unitFac;
-        tymax *= unitFac;
-
-        /* Try to set cur using these values, if they're more extreme than previously set values.
-         */
-        if ((xmin) && (txmin < *xmin)) {
-          *xmin = txmin;
-        }
-        if ((xmax) && (txmax > *xmax)) {
-          *xmax = txmax;
-        }
-        if ((ymin) && (tymin < *ymin)) {
-          *ymin = tymin;
-        }
-        if ((ymax) && (tymax > *ymax)) {
-          *ymax = tymax;
-        }
-
-        foundBounds = true;
-      }
-    }
-
-    /* Ensure that the extents are not too extreme that view implodes...*/
-    if (foundBounds) {
-      if ((xmin && xmax) && (fabsf(*xmax - *xmin) < 0.001f)) {
-        *xmin -= 0.0005f;
-        *xmax += 0.0005f;
-      }
-      if ((ymin && ymax) && (fabsf(*ymax - *ymin) < 0.001f)) {
-        *ymax -= 0.0005f;
-        *ymax += 0.0005f;
-      }
-    }
-    else {
-      if (xmin) {
-        *xmin = (float)PSFRA;
-      }
-      if (xmax) {
-        *xmax = (float)PEFRA;
-      }
-      if (ymin) {
-        *ymin = -5;
-      }
-      if (ymax) {
-        *ymax = 5;
-      }
-    }
-
-    /* Free memory. */
-    ANIM_animdata_freelist(&anim_data);
-  }
-  else {
-    /* Set default range. */
-    if (ac->scene) {
-      if (xmin) {
-        *xmin = (float)PSFRA;
-      }
-      if (xmax) {
-        *xmax = (float)PEFRA;
-      }
-    }
-    else {
-      if (xmin) {
-        *xmin = -5;
-      }
-      if (xmax) {
-        *xmax = 100;
-      }
-    }
-
-    if (ymin) {
-      *ymin = -5;
-    }
-    if (ymax) {
-      *ymax = 5;
-    }
-  }
-}
-
-/* ****************** Automatic Preview-Range Operator ****************** */
-
-static int graphkeys_previewrange_exec(bContext *C, wmOperator *UNUSED(op))
-{
-  bAnimContext ac;
-  Scene *scene;
-  float min, max;
-
-  /* Get editor data. */
-  if (ANIM_animdata_get_context(C, &ac) == 0) {
-    return OPERATOR_CANCELLED;
-  }
-  if (ac.scene == NULL) {
-    return OPERATOR_CANCELLED;
-  }
-
-  scene = ac.scene;
-
-  /* Set the range directly. */
-  get_graph_keyframe_extents(&ac, &min, &max, NULL, NULL, false, false);
-  scene->r.flag |= SCER_PRV_RANGE;
-  scene->r.psfra = round_fl_to_int(min);
-  scene->r.pefra = round_fl_to_int(max);
-
-  /* Set notifier that things have changed. */
-  // XXX Err... there's nothing for frame ranges yet, but this should do fine too.
-  WM_event_add_notifier(C, NC_SCENE | ND_FRAME, ac.scene);
-
-  return OPERATOR_FINISHED;
-}
-
-void GRAPH_OT_previewrange_set(wmOperatorType *ot)
-{
-  /* Identifiers */
-  ot->name = "Auto-Set Preview Range";
-  ot->idname = "GRAPH_OT_previewrange_set";
-  ot->description = "Automatically set Preview Range based on range of keyframes";
-
-  /* API callbacks */
-  ot->exec = graphkeys_previewrange_exec;
-  /* XXX: unchecked poll to get fsamples working too, but makes modifier damage trickier. */
-  ot->poll = ED_operator_graphedit_active;
-
-  /* Flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/* ****************** View-All Operator ****************** */
-
-static int graphkeys_viewall(bContext *C,
-                             const bool do_sel_only,
-                             const bool include_handles,
-                             const int smooth_viewtx)
-{
-  bAnimContext ac;
-  rctf cur_new;
-
-  /* Get editor data. */
-  if (ANIM_animdata_get_context(C, &ac) == 0) {
-    return OPERATOR_CANCELLED;
-  }
-
-  /* Set the horizontal range, with an extra offset so that the extreme keys will be in view. */
-  get_graph_keyframe_extents(&ac,
-                             &cur_new.xmin,
-                             &cur_new.xmax,
-                             &cur_new.ymin,
-                             &cur_new.ymax,
-                             do_sel_only,
-                             include_handles);
-
-  /* Give some more space at the borders. */
-  BLI_rctf_scale(&cur_new, 1.1f);
-
-  /* Take regions into account, that could block the view.
-   * Marker region is supposed to be larger than the scroll-bar, so prioritize it.*/
-  float pad_top = UI_TIME_SCRUB_MARGIN_Y;
-  float pad_bottom = BLI_listbase_is_empty(ED_context_get_markers(C)) ? V2D_SCROLL_HANDLE_HEIGHT :
-                                                                        UI_MARKER_MARGIN_Y;
-  BLI_rctf_pad_y(&cur_new, ac.region->winy, pad_bottom, pad_top);
-
-  UI_view2d_smooth_view(C, ac.region, &cur_new, smooth_viewtx);
-  return OPERATOR_FINISHED;
-}
-
-/* ......... */
-
-static int graphkeys_viewall_exec(bContext *C, wmOperator *op)
-{
-  const bool include_handles = RNA_boolean_get(op->ptr, "include_handles");
-  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
-
-  /* Whole range */
-  return graphkeys_viewall(C, false, include_handles, smooth_viewtx);
-}
-
-static int graphkeys_view_selected_exec(bContext *C, wmOperator *op)
-{
-  const bool include_handles = RNA_boolean_get(op->ptr, "include_handles");
-  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
-
-  /* Only selected. */
-  return graphkeys_viewall(C, true, include_handles, smooth_viewtx);
-}
-
-/* ......... */
-
-void GRAPH_OT_view_all(wmOperatorType *ot)
-{
-  /* Identifiers */
-  ot->name = "Frame All";
-  ot->idname = "GRAPH_OT_view_all";
-  ot->description = "Reset viewable area to show full keyframe range";
-
-  /* API callbacks */
-  ot->exec = graphkeys_viewall_exec;
-  /* XXX: Unchecked poll to get fsamples working too, but makes modifier damage trickier... */
-  ot->poll = ED_operator_graphedit_active;
-
-  /* Flags */
-  ot->flag = 0;
-
-  /* Props */
-  ot->prop = RNA_def_boolean(ot->srna,
-                             "include_handles",
-                             true,
-                             "Include Handles",
-                             "Include handles of keyframes when calculating extents");
-}
-
-void GRAPH_OT_view_selected(wmOperatorType *ot)
-{
-  /* Identifiers */
-  ot->name = "Frame Selected";
-  ot->idname = "GRAPH_OT_view_selected";
-  ot->description = "Reset viewable area to show selected keyframe range";
-
-  /* API callbacks */
-  ot->exec = graphkeys_view_selected_exec;
-  /* XXX: Unchecked poll to get fsamples working too, but makes modifier damage trickier... */
-  ot->poll = ED_operator_graphedit_active;
-
-  /* Flags */
-  ot->flag = 0;
-
-  /* Props */
-  ot->prop = RNA_def_boolean(ot->srna,
-                             "include_handles",
-                             true,
-                             "Include Handles",
-                             "Include handles of keyframes when calculating extents");
-}
-
-/* ********************** View Frame Operator ****************************** */
-
-static int graphkeys_view_frame_exec(bContext *C, wmOperator *op)
-{
-  const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
-  ANIM_center_frame(C, smooth_viewtx);
-  return OPERATOR_FINISHED;
-}
-
-void GRAPH_OT_view_f

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list