731032bafa82a31556b6d20af5259a28c45461b1
[blender.git] / release / scripts / startup / bl_ui / space_dopesheet.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 import bpy
22 from bpy.types import Header, Menu
23
24
25 #######################################
26 # DopeSheet Filtering
27
28 # used for DopeSheet, NLA, and Graph Editors
29 def dopesheet_filter(layout, context, genericFiltersOnly=False):
30     dopesheet = context.space_data.dopesheet
31     is_nla = context.area.type == 'NLA_EDITOR'
32
33     row = layout.row(align=True)
34     row.prop(dopesheet, "show_only_selected", text="")
35     row.prop(dopesheet, "show_hidden", text="")
36
37     if is_nla:
38         row.prop(dopesheet, "show_missing_nla", text="")
39     else:  # graph and dopesheet editors - F-Curves and drivers only
40         row.prop(dopesheet, "show_only_errors", text="")
41
42     if not genericFiltersOnly:
43         if bpy.data.groups:
44             row = layout.row(align=True)
45             row.prop(dopesheet, "show_only_group_objects", text="")
46             if dopesheet.show_only_group_objects:
47                 row.prop(dopesheet, "filter_group", text="")
48
49     if not is_nla:
50         row = layout.row(align=True)
51         row.prop(dopesheet, "show_only_matching_fcurves", text="")
52         if dopesheet.show_only_matching_fcurves:
53             row.prop(dopesheet, "filter_fcurve_name", text="")
54             row.prop(dopesheet, "use_multi_word_filter", text="")
55     else:
56         row = layout.row(align=True)
57         row.prop(dopesheet, "use_filter_text", text="")
58         if dopesheet.use_filter_text:
59             row.prop(dopesheet, "filter_text", text="")
60             row.prop(dopesheet, "use_multi_word_filter", text="")
61
62     if not genericFiltersOnly:
63         row = layout.row(align=True)
64         row.prop(dopesheet, "show_datablock_filters", text="Filters")
65
66         if dopesheet.show_datablock_filters:
67             row.prop(dopesheet, "show_scenes", text="")
68             row.prop(dopesheet, "show_worlds", text="")
69             row.prop(dopesheet, "show_nodes", text="")
70
71             row.prop(dopesheet, "show_transforms", text="")
72
73             if bpy.data.meshes:
74                 row.prop(dopesheet, "show_meshes", text="")
75             if bpy.data.shape_keys:
76                 row.prop(dopesheet, "show_shapekeys", text="")
77             if bpy.data.meshes:
78                 row.prop(dopesheet, "show_modifiers", text="")
79             if bpy.data.materials:
80                 row.prop(dopesheet, "show_materials", text="")
81             if bpy.data.lamps:
82                 row.prop(dopesheet, "show_lamps", text="")
83             if bpy.data.textures:
84                 row.prop(dopesheet, "show_textures", text="")
85             if bpy.data.cameras:
86                 row.prop(dopesheet, "show_cameras", text="")
87             if bpy.data.curves:
88                 row.prop(dopesheet, "show_curves", text="")
89             if bpy.data.metaballs:
90                 row.prop(dopesheet, "show_metaballs", text="")
91             if bpy.data.lattices:
92                 row.prop(dopesheet, "show_lattices", text="")
93             if bpy.data.armatures:
94                 row.prop(dopesheet, "show_armatures", text="")
95             if bpy.data.particles:
96                 row.prop(dopesheet, "show_particles", text="")
97             if bpy.data.speakers:
98                 row.prop(dopesheet, "show_speakers", text="")
99             if bpy.data.linestyles:
100                 row.prop(dopesheet, "show_linestyles", text="")
101             if bpy.data.grease_pencil:
102                 row.prop(dopesheet, "show_gpencil", text="")
103
104             layout.prop(dopesheet, "use_datablock_sort", text="")
105
106
107 #######################################
108 # DopeSheet Editor - General/Standard UI
109
110 class DOPESHEET_HT_header(Header):
111     bl_space_type = 'DOPESHEET_EDITOR'
112
113     def draw(self, context):
114         layout = self.layout
115
116         st = context.space_data
117         toolsettings = context.tool_settings
118
119         row = layout.row(align=True)
120         row.template_header()
121
122         DOPESHEET_MT_editor_menus.draw_collapsible(context, layout)
123
124         layout.prop(st, "mode", text="")
125
126         if st.mode in {'ACTION', 'SHAPEKEY'}:
127             row = layout.row(align=True)
128             row.operator("action.layer_prev", text="", icon='TRIA_DOWN')
129             row.operator("action.layer_next", text="", icon='TRIA_UP')
130
131             layout.template_ID(st, "action", new="action.new", unlink="action.unlink")
132
133             row = layout.row(align=True)
134             row.operator("action.push_down", text="Push Down", icon='NLA_PUSHDOWN')
135             row.operator("action.stash", text="Stash", icon='FREEZE')
136
137         layout.prop(st.dopesheet, "show_summary", text="Summary")
138
139         if st.mode == 'DOPESHEET':
140             dopesheet_filter(layout, context)
141         elif st.mode == 'ACTION':
142             # 'genericFiltersOnly' limits the options to only the relevant 'generic' subset of
143             # filters which will work here and are useful (especially for character animation)
144             dopesheet_filter(layout, context, genericFiltersOnly=True)
145         elif st.mode == 'GPENCIL':
146             row = layout.row(align=True)
147             row.prop(st.dopesheet, "show_gpencil_3d_only", text="Active Only")
148
149             if st.dopesheet.show_gpencil_3d_only:
150                 row = layout.row(align=True)
151                 row.prop(st.dopesheet, "show_only_selected", text="")
152                 row.prop(st.dopesheet, "show_hidden", text="")
153
154             row = layout.row(align=True)
155             row.prop(st.dopesheet, "use_filter_text", text="")
156             if st.dopesheet.use_filter_text:
157                 row.prop(st.dopesheet, "filter_text", text="")
158                 row.prop(st.dopesheet, "use_multi_word_filter", text="")
159
160         row = layout.row(align=True)
161         row.prop(toolsettings, "use_proportional_action",
162                  text="", icon_only=True)
163         if toolsettings.use_proportional_action:
164             row.prop(toolsettings, "proportional_edit_falloff",
165                      text="", icon_only=True)
166
167         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
168         if st.mode != 'GPENCIL':
169             layout.prop(st, "auto_snap", text="")
170
171         row = layout.row(align=True)
172         row.operator("action.copy", text="", icon='COPYDOWN')
173         row.operator("action.paste", text="", icon='PASTEDOWN')
174         if st.mode not in ('GPENCIL', 'MASK'):
175             row.operator("action.paste", text="", icon='PASTEFLIPDOWN').flipped = True
176
177
178 class DOPESHEET_MT_editor_menus(Menu):
179     bl_idname = "DOPESHEET_MT_editor_menus"
180     bl_label = ""
181
182     def draw(self, context):
183         self.draw_menus(self.layout, context)
184
185     @staticmethod
186     def draw_menus(layout, context):
187         st = context.space_data
188
189         layout.menu("DOPESHEET_MT_view")
190         layout.menu("DOPESHEET_MT_select")
191         layout.menu("DOPESHEET_MT_marker")
192
193         if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action is not None):
194             layout.menu("DOPESHEET_MT_channel")
195         elif st.mode == 'GPENCIL':
196             layout.menu("DOPESHEET_MT_gpencil_channel")
197
198         if st.mode != 'GPENCIL':
199             layout.menu("DOPESHEET_MT_key")
200         else:
201             layout.menu("DOPESHEET_MT_gpencil_frame")
202
203
204 class DOPESHEET_MT_view(Menu):
205     bl_label = "View"
206
207     def draw(self, context):
208         layout = self.layout
209
210         st = context.space_data
211
212         layout.operator("action.properties", icon='MENU_PANEL')
213         layout.separator()
214
215         layout.prop(st, "use_realtime_update")
216         layout.prop(st, "show_frame_indicator")
217         layout.prop(st, "show_sliders")
218         layout.prop(st, "show_group_colors")
219         layout.prop(st, "use_auto_merge_keyframes")
220         layout.prop(st, "use_marker_sync")
221
222         layout.prop(st, "show_seconds")
223         layout.prop(st, "show_locked_time")
224
225         layout.separator()
226         layout.operator("anim.previewrange_set")
227         layout.operator("anim.previewrange_clear")
228         layout.operator("action.previewrange_set")
229
230         layout.separator()
231         layout.operator("action.view_all")
232         layout.operator("action.view_selected")
233         layout.operator("action.view_frame")
234
235         layout.separator()
236         layout.operator("screen.area_dupli")
237         layout.operator("screen.screen_full_area")
238         layout.operator("screen.screen_full_area", text="Toggle Fullscreen Area").use_hide_panels = True
239
240
241 class DOPESHEET_MT_select(Menu):
242     bl_label = "Select"
243
244     def draw(self, context):
245         layout = self.layout
246
247         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
248         layout.operator("action.select_all_toggle").invert = False
249         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
250
251         layout.separator()
252         layout.operator("action.select_border").axis_range = False
253         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
254
255         layout.operator("action.select_circle")
256
257         layout.separator()
258         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
259         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
260
261         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
262         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
263
264         layout.separator()
265         props = layout.operator("action.select_leftright", text="Before Current Frame")
266         props.extend = False
267         props.mode = 'LEFT'
268         props = layout.operator("action.select_leftright", text="After Current Frame")
269         props.extend = False
270         props.mode = 'RIGHT'
271
272         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
273         if context.space_data.mode != 'GPENCIL':
274             layout.separator()
275             layout.operator("action.select_more")
276             layout.operator("action.select_less")
277
278             layout.separator()
279             layout.operator("action.select_linked")
280
281
282 class DOPESHEET_MT_marker(Menu):
283     bl_label = "Marker"
284
285     def draw(self, context):
286         layout = self.layout
287
288         from .space_time import marker_menu_generic
289         marker_menu_generic(layout)
290
291         st = context.space_data
292
293         if st.mode in {'ACTION', 'SHAPEKEY'} and st.action:
294             layout.separator()
295             layout.prop(st, "show_pose_markers")
296
297             if st.show_pose_markers is False:
298                 layout.operator("action.markers_make_local")
299
300
301 #######################################
302 # Keyframe Editing
303
304 class DOPESHEET_MT_channel(Menu):
305     bl_label = "Channel"
306
307     def draw(self, context):
308         layout = self.layout
309
310         layout.operator_context = 'INVOKE_REGION_CHANNELS'
311
312         layout.operator("anim.channels_delete")
313
314         layout.separator()
315         layout.operator("anim.channels_group")
316         layout.operator("anim.channels_ungroup")
317
318         layout.separator()
319         layout.operator_menu_enum("anim.channels_setting_toggle", "type")
320         layout.operator_menu_enum("anim.channels_setting_enable", "type")
321         layout.operator_menu_enum("anim.channels_setting_disable", "type")
322
323         layout.separator()
324         layout.operator("anim.channels_editable_toggle")
325         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
326
327         layout.separator()
328         layout.operator("anim.channels_expand")
329         layout.operator("anim.channels_collapse")
330
331         layout.separator()
332         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
333
334         layout.separator()
335         layout.operator("anim.channels_fcurves_enable")
336
337
338 class DOPESHEET_MT_key(Menu):
339     bl_label = "Key"
340
341     def draw(self, context):
342         layout = self.layout
343
344         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
345
346         layout.operator_menu_enum("action.snap", "type", text="Snap")
347         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
348
349         layout.separator()
350         layout.operator("action.keyframe_insert")
351
352         layout.separator()
353         layout.operator("action.frame_jump")
354
355         layout.separator()
356         layout.operator("action.duplicate_move")
357         layout.operator("action.delete")
358
359         layout.separator()
360         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
361         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
362         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
363
364         layout.separator()
365         layout.operator("action.clean").channels = False
366         layout.operator("action.clean", text="Clean Channels").channels = True
367         layout.operator("action.sample")
368
369         layout.separator()
370         layout.operator("action.copy")
371         layout.operator("action.paste")
372
373
374 class DOPESHEET_MT_key_transform(Menu):
375     bl_label = "Transform"
376
377     def draw(self, context):
378         layout = self.layout
379
380         layout.operator("transform.transform", text="Grab/Move").mode = 'TIME_TRANSLATE'
381         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
382         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
383         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
384
385
386 #######################################
387 # Grease Pencil Editing
388
389 class DOPESHEET_MT_gpencil_channel(Menu):
390     bl_label = "Channel"
391
392     def draw(self, context):
393         layout = self.layout
394
395         layout.operator_context = 'INVOKE_REGION_CHANNELS'
396
397         layout.operator("anim.channels_delete")
398
399         layout.separator()
400         layout.operator("anim.channels_setting_toggle")
401         layout.operator("anim.channels_setting_enable")
402         layout.operator("anim.channels_setting_disable")
403
404         layout.separator()
405         layout.operator("anim.channels_editable_toggle")
406
407         # XXX: to be enabled when these are ready for use!
408         # layout.separator()
409         # layout.operator("anim.channels_expand")
410         # layout.operator("anim.channels_collapse")
411
412         # layout.separator()
413         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
414
415
416 class DOPESHEET_MT_gpencil_frame(Menu):
417     bl_label = "Frame"
418
419     def draw(self, context):
420         layout = self.layout
421
422         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
423         layout.operator_menu_enum("action.snap", "type", text="Snap")
424         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
425
426         layout.separator()
427         layout.operator("action.duplicate")
428         layout.operator("action.delete")
429
430         layout.separator()
431         layout.operator("action.keyframe_type")
432
433         # layout.separator()
434         # layout.operator("action.copy")
435         # layout.operator("action.paste")
436
437
438 class DOPESHEET_MT_delete(Menu):
439     bl_label = "Delete"
440
441     def draw(self, context):
442         layout = self.layout
443
444         layout.operator("action.delete")
445
446         layout.separator()
447
448         layout.operator("action.clean").channels = False
449         layout.operator("action.clean", text="Clean Channels").channels = True
450
451
452 classes = (
453     DOPESHEET_HT_header,
454     DOPESHEET_MT_editor_menus,
455     DOPESHEET_MT_view,
456     DOPESHEET_MT_select,
457     DOPESHEET_MT_marker,
458     DOPESHEET_MT_channel,
459     DOPESHEET_MT_key,
460     DOPESHEET_MT_key_transform,
461     DOPESHEET_MT_gpencil_channel,
462     DOPESHEET_MT_gpencil_frame,
463     DOPESHEET_MT_delete,
464 )
465
466 if __name__ == "__main__":  # only for live edit.
467     from bpy.utils import register_class
468     for cls in classes:
469         register_class(cls)