Blender  V2.93
clip_dopesheet_ops.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2012 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "DNA_scene_types.h"
25 
26 #include "BLI_math.h"
27 #include "BLI_rect.h"
28 #include "BLI_utildefines.h"
29 
30 #include "BKE_context.h"
31 #include "BKE_tracking.h"
32 
33 #include "WM_api.h"
34 #include "WM_types.h"
35 
36 #include "ED_clip.h"
37 #include "ED_screen.h"
38 
39 #include "UI_interface.h"
40 
41 #include "RNA_access.h"
42 #include "RNA_define.h"
43 
44 #include "UI_view2d.h"
45 
46 #include "clip_intern.h" /* own include */
47 
49 {
52 
53  if (sc->view == SC_VIEW_DOPESHEET) {
54  ARegion *region = CTX_wm_region(C);
55 
56  return region->regiontype == RGN_TYPE_PREVIEW;
57  }
58  }
59 
60  return false;
61 }
62 
63 /********************** select channel operator *********************/
64 
66 {
68 
69  if (sc && sc->clip) {
70  return sc->view == SC_VIEW_DOPESHEET;
71  }
72 
73  return false;
74 }
75 
77 {
80  MovieTracking *tracking = &clip->tracking;
82  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
84  ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, object);
85  float location[2];
86  const bool extend = RNA_boolean_get(op->ptr, "extend");
87  int current_channel_index = 0, channel_index;
88  const bool show_selected_only = (dopesheet->flag & TRACKING_DOPE_SELECTED_ONLY) != 0;
89 
90  RNA_float_get_array(op->ptr, "location", location);
91  channel_index = -(location[1] - (CHANNEL_FIRST + CHANNEL_HEIGHT_HALF)) / CHANNEL_STEP;
92 
93  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
94  MovieTrackingTrack *track = channel->track;
95 
96  if (current_channel_index == channel_index) {
97  if (extend) {
98  track->flag ^= TRACK_DOPE_SEL;
99  }
100  else {
101  track->flag |= TRACK_DOPE_SEL;
102  }
103 
104  if (track->flag & TRACK_DOPE_SEL) {
105  tracking->act_track = track;
106  BKE_tracking_track_select(tracksbase, track, TRACK_AREA_ALL, true);
107  }
108  else if (show_selected_only == false) {
110  }
111  }
112  else if (!extend) {
113  track->flag &= ~TRACK_DOPE_SEL;
114  }
115 
116  current_channel_index++;
117  }
118 
120 
121  return OPERATOR_FINISHED;
122 }
123 
125 {
126  ARegion *region = CTX_wm_region(C);
127  float location[2];
128 
130  &region->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
131  RNA_float_set_array(op->ptr, "location", location);
132 
133  return dopesheet_select_channel_exec(C, op);
134 }
135 
137 {
138  /* identifiers */
139  ot->name = "Select Channel";
140  ot->description = "Select movie tracking channel";
141  ot->idname = "CLIP_OT_dopesheet_select_channel";
142 
143  /* api callbacks */
147 
148  /* flags */
150 
151  /* properties */
153  "location",
154  2,
155  NULL,
156  -FLT_MAX,
157  FLT_MAX,
158  "Location",
159  "Mouse location to select channel",
160  -100.0f,
161  100.0f);
163  "extend",
164  0,
165  "Extend",
166  "Extend selection rather than clearing the existing selection");
167 }
168 
169 /********************** View All operator *********************/
170 
172 {
174  ARegion *region = CTX_wm_region(C);
175  View2D *v2d = &region->v2d;
176  MovieClip *clip = ED_space_clip_get_clip(sc);
177  MovieTracking *tracking = &clip->tracking;
178  MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
180  int frame_min = INT_MAX, frame_max = INT_MIN;
181 
182  for (channel = dopesheet->channels.first; channel; channel = channel->next) {
183  frame_min = min_ii(frame_min, channel->segments[0]);
184  frame_max = max_ii(frame_max, channel->segments[channel->tot_segment]);
185  }
186 
187  if (frame_min < frame_max) {
188  float extra;
189 
190  v2d->cur.xmin = frame_min;
191  v2d->cur.xmax = frame_max;
192 
193  /* we need an extra "buffer" factor on either side so that the endpoints are visible */
194  extra = 0.01f * BLI_rctf_size_x(&v2d->cur);
195  v2d->cur.xmin -= extra;
196  v2d->cur.xmax += extra;
197 
198  ED_region_tag_redraw(region);
199  }
200 
201  return OPERATOR_FINISHED;
202 }
203 
205 {
206  /* identifiers */
207  ot->name = "Frame All";
208  ot->description = "Reset viewable area to show full keyframe range";
209  ot->idname = "CLIP_OT_dopesheet_view_all";
210 
211  /* api callbacks */
214 
215  /* flags */
217 }
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:899
struct ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:725
void BKE_tracking_track_deselect(struct MovieTrackingTrack *track, int area)
Definition: tracking.c:1367
#define TRACK_AREA_ALL
Definition: BKE_tracking.h:524
void BKE_tracking_track_select(struct ListBase *tracksbase, struct MovieTrackingTrack *track, int area, bool extend)
Definition: tracking.c:1340
struct ListBase * BKE_tracking_object_get_tracks(struct MovieTracking *tracking, struct MovieTrackingObject *object)
Definition: tracking.c:2218
struct MovieTrackingObject * BKE_tracking_object_get_active(struct MovieTracking *tracking)
Definition: tracking.c:2198
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition: BLI_rect.h:161
#define UNUSED(x)
@ RGN_TYPE_PREVIEW
@ SC_VIEW_DOPESHEET
@ TRACK_DOPE_SEL
@ TRACKING_DOPE_SELECTED_ONLY
@ OPERATOR_FINISHED
bool ED_space_clip_tracking_poll(struct bContext *C)
Definition: clip_editor.c:98
struct MovieClip * ED_space_clip_get_clip(struct SpaceClip *sc)
Definition: clip_editor.c:572
void ED_region_tag_redraw(struct ARegion *region)
Definition: area.c:667
#define C
Definition: RandGen.cpp:39
void UI_view2d_region_to_view(const struct View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
#define NC_GEOM
Definition: WM_types.h:294
@ OPTYPE_UNDO
Definition: WM_types.h:155
@ OPTYPE_REGISTER
Definition: WM_types.h:153
#define ND_SELECT
Definition: WM_types.h:407
static bool space_clip_dopesheet_poll(bContext *C)
void CLIP_OT_dopesheet_view_all(wmOperatorType *ot)
void CLIP_OT_dopesheet_select_channel(wmOperatorType *ot)
static int dopesheet_view_all_exec(bContext *C, wmOperator *UNUSED(op))
static int dopesheet_select_channel_exec(bContext *C, wmOperator *op)
static int dopesheet_select_channel_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool dopesheet_select_channel_poll(bContext *C)
#define CHANNEL_STEP
Definition: clip_intern.h:41
#define CHANNEL_FIRST
Definition: clip_intern.h:37
#define CHANNEL_HEIGHT_HALF
Definition: clip_intern.h:39
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:6378
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
Definition: rna_access.c:6390
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, bool default_value, const char *ui_name, const char *ui_description)
Definition: rna_define.c:3481
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, int len, const float *default_value, float hardmin, float hardmax, const char *ui_name, const char *ui_description, float softmin, float softmax)
Definition: rna_define.c:3851
short regiontype
void * first
Definition: DNA_listBase.h:47
struct MovieTracking tracking
struct MovieTrackingDopesheetChannel * next
MovieTrackingDopesheet dopesheet
MovieTrackingTrack * act_track
struct MovieClip * clip
float xmax
Definition: DNA_vec_types.h:85
float xmin
Definition: DNA_vec_types.h:85
int mval[2]
Definition: WM_types.h:583
int(* invoke)(struct bContext *, struct wmOperator *, const struct wmEvent *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:752
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
bool(* poll)(struct bContext *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:776
struct StructRNA * srna
Definition: WM_types.h:802
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156