Merge branch 'master' into blender2.8
[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.speakers:
96                 row.prop(dopesheet, "show_speakers", text="")
97             if bpy.data.linestyles:
98                 row.prop(dopesheet, "show_linestyles", text="")
99             if bpy.data.grease_pencil:
100                 row.prop(dopesheet, "show_gpencil", text="")
101
102
103 #######################################
104 # DopeSheet Editor - General/Standard UI
105
106 class DOPESHEET_HT_header(Header):
107     bl_space_type = 'DOPESHEET_EDITOR'
108
109     def draw(self, context):
110         layout = self.layout
111
112         st = context.space_data
113         toolsettings = context.tool_settings
114
115         row = layout.row(align=True)
116         row.template_header()
117
118         DOPESHEET_MT_editor_menus.draw_collapsible(context, layout)
119
120         layout.prop(st, "mode", text="")
121
122         if st.mode in {'ACTION', 'SHAPEKEY'}:
123             row = layout.row(align=True)
124             row.operator("action.layer_prev", text="", icon='TRIA_DOWN')
125             row.operator("action.layer_next", text="", icon='TRIA_UP')
126
127             layout.template_ID(st, "action", new="action.new", unlink="action.unlink")
128
129             row = layout.row(align=True)
130             row.operator("action.push_down", text="Push Down", icon='NLA_PUSHDOWN')
131             row.operator("action.stash", text="Stash", icon='FREEZE')
132
133         layout.prop(st.dopesheet, "show_summary", text="Summary")
134
135         if st.mode == 'DOPESHEET':
136             dopesheet_filter(layout, context)
137         elif st.mode == 'ACTION':
138             # 'genericFiltersOnly' limits the options to only the relevant 'generic' subset of
139             # filters which will work here and are useful (especially for character animation)
140             dopesheet_filter(layout, context, genericFiltersOnly=True)
141         elif st.mode == 'GPENCIL':
142             row = layout.row(align=True)
143             row.prop(st.dopesheet, "show_gpencil_3d_only", text="Active Only")
144
145             if st.dopesheet.show_gpencil_3d_only:
146                 row = layout.row(align=True)
147                 row.prop(st.dopesheet, "show_only_selected", text="")
148                 row.prop(st.dopesheet, "show_hidden", text="")
149
150             row = layout.row(align=True)
151             row.prop(st.dopesheet, "use_filter_text", text="")
152             if st.dopesheet.use_filter_text:
153                 row.prop(st.dopesheet, "filter_text", text="")
154                 row.prop(st.dopesheet, "use_multi_word_filter", text="")
155
156         row = layout.row(align=True)
157         row.prop(toolsettings, "use_proportional_action",
158                  text="", icon_only=True)
159         if toolsettings.use_proportional_action:
160             row.prop(toolsettings, "proportional_edit_falloff",
161                      text="", icon_only=True)
162
163         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
164         if st.mode != 'GPENCIL':
165             layout.prop(st, "auto_snap", text="")
166
167         row = layout.row(align=True)
168         row.operator("action.copy", text="", icon='COPYDOWN')
169         row.operator("action.paste", text="", icon='PASTEDOWN')
170         if st.mode not in ('GPENCIL', 'MASK'):
171             row.operator("action.paste", text="", icon='PASTEFLIPDOWN').flipped = True
172
173
174 class DOPESHEET_MT_editor_menus(Menu):
175     bl_idname = "DOPESHEET_MT_editor_menus"
176     bl_label = ""
177
178     def draw(self, context):
179         self.draw_menus(self.layout, context)
180
181     @staticmethod
182     def draw_menus(layout, context):
183         st = context.space_data
184
185         layout.menu("DOPESHEET_MT_view")
186         layout.menu("DOPESHEET_MT_select")
187         layout.menu("DOPESHEET_MT_marker")
188
189         if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action is not None):
190             layout.menu("DOPESHEET_MT_channel")
191         elif st.mode == 'GPENCIL':
192             layout.menu("DOPESHEET_MT_gpencil_channel")
193
194         if st.mode != 'GPENCIL':
195             layout.menu("DOPESHEET_MT_key")
196         else:
197             layout.menu("DOPESHEET_MT_gpencil_frame")
198
199
200 class DOPESHEET_MT_view(Menu):
201     bl_label = "View"
202
203     def draw(self, context):
204         layout = self.layout
205
206         st = context.space_data
207
208         layout.operator("action.properties", icon='MENU_PANEL')
209         layout.separator()
210
211         layout.prop(st, "use_realtime_update")
212         layout.prop(st, "show_frame_indicator")
213         layout.prop(st, "show_sliders")
214         layout.prop(st, "show_group_colors")
215         layout.prop(st, "use_auto_merge_keyframes")
216         layout.prop(st, "use_marker_sync")
217
218         layout.prop(st, "show_seconds")
219         layout.prop(st, "show_locked_time")
220
221         layout.separator()
222         layout.operator("anim.previewrange_set")
223         layout.operator("anim.previewrange_clear")
224         layout.operator("action.previewrange_set")
225
226         layout.separator()
227         layout.operator("action.view_all")
228         layout.operator("action.view_selected")
229         layout.operator("action.view_frame")
230
231         layout.separator()
232         layout.operator("screen.area_dupli")
233         layout.operator("screen.screen_full_area", text="Toggle Maximize Area")
234         layout.operator("screen.screen_full_area").use_hide_panels = True
235
236
237 class DOPESHEET_MT_select(Menu):
238     bl_label = "Select"
239
240     def draw(self, context):
241         layout = self.layout
242
243         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
244         layout.operator("action.select_all_toggle").invert = False
245         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
246
247         layout.separator()
248         layout.operator("action.select_border").axis_range = False
249         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
250
251         layout.separator()
252         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
253         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
254
255         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
256         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
257
258         layout.separator()
259         props = layout.operator("action.select_leftright", text="Before Current Frame")
260         props.extend = False
261         props.mode = 'LEFT'
262         props = layout.operator("action.select_leftright", text="After Current Frame")
263         props.extend = False
264         props.mode = 'RIGHT'
265
266         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
267         if context.space_data.mode != 'GPENCIL':
268             layout.separator()
269             layout.operator("action.select_more")
270             layout.operator("action.select_less")
271
272             layout.separator()
273             layout.operator("action.select_linked")
274
275
276 class DOPESHEET_MT_marker(Menu):
277     bl_label = "Marker"
278
279     def draw(self, context):
280         layout = self.layout
281
282         from bl_ui.space_time import marker_menu_generic
283         marker_menu_generic(layout)
284
285         st = context.space_data
286
287         if st.mode in {'ACTION', 'SHAPEKEY'} and st.action:
288             layout.separator()
289             layout.prop(st, "show_pose_markers")
290
291             if st.show_pose_markers is False:
292                 layout.operator("action.markers_make_local")
293
294
295 #######################################
296 # Keyframe Editing
297
298 class DOPESHEET_MT_channel(Menu):
299     bl_label = "Channel"
300
301     def draw(self, context):
302         layout = self.layout
303
304         layout.operator_context = 'INVOKE_REGION_CHANNELS'
305
306         layout.operator("anim.channels_delete")
307
308         layout.separator()
309         layout.operator("anim.channels_group")
310         layout.operator("anim.channels_ungroup")
311
312         layout.separator()
313         layout.operator_menu_enum("anim.channels_setting_toggle", "type")
314         layout.operator_menu_enum("anim.channels_setting_enable", "type")
315         layout.operator_menu_enum("anim.channels_setting_disable", "type")
316
317         layout.separator()
318         layout.operator("anim.channels_editable_toggle")
319         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
320
321         layout.separator()
322         layout.operator("anim.channels_expand")
323         layout.operator("anim.channels_collapse")
324
325         layout.separator()
326         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
327
328         layout.separator()
329         layout.operator("anim.channels_fcurves_enable")
330
331
332 class DOPESHEET_MT_key(Menu):
333     bl_label = "Key"
334
335     def draw(self, context):
336         layout = self.layout
337
338         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
339
340         layout.operator_menu_enum("action.snap", "type", text="Snap")
341         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
342
343         layout.separator()
344         layout.operator("action.keyframe_insert")
345
346         layout.separator()
347         layout.operator("action.frame_jump")
348
349         layout.separator()
350         layout.operator("action.duplicate_move")
351         layout.operator("action.delete")
352
353         layout.separator()
354         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
355         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
356         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
357
358         layout.separator()
359         layout.operator("action.clean").channels = False
360         layout.operator("action.clean", text="Clean Channels").channels = True
361         layout.operator("action.sample")
362
363         layout.separator()
364         layout.operator("action.copy")
365         layout.operator("action.paste")
366
367
368 class DOPESHEET_MT_key_transform(Menu):
369     bl_label = "Transform"
370
371     def draw(self, context):
372         layout = self.layout
373
374         layout.operator("transform.transform", text="Grab/Move").mode = 'TIME_TRANSLATE'
375         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
376         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
377         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
378
379
380 #######################################
381 # Grease Pencil Editing
382
383 class DOPESHEET_MT_gpencil_channel(Menu):
384     bl_label = "Channel"
385
386     def draw(self, context):
387         layout = self.layout
388
389         layout.operator_context = 'INVOKE_REGION_CHANNELS'
390
391         layout.operator("anim.channels_delete")
392
393         layout.separator()
394         layout.operator("anim.channels_setting_toggle")
395         layout.operator("anim.channels_setting_enable")
396         layout.operator("anim.channels_setting_disable")
397
398         layout.separator()
399         layout.operator("anim.channels_editable_toggle")
400
401         # XXX: to be enabled when these are ready for use!
402         #layout.separator()
403         #layout.operator("anim.channels_expand")
404         #layout.operator("anim.channels_collapse")
405
406         #layout.separator()
407         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
408
409
410 class DOPESHEET_MT_gpencil_frame(Menu):
411     bl_label = "Frame"
412
413     def draw(self, context):
414         layout = self.layout
415
416         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
417         layout.operator_menu_enum("action.snap", "type", text="Snap")
418         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
419
420         layout.separator()
421         layout.operator("action.duplicate")
422         layout.operator("action.delete")
423
424         layout.separator()
425         layout.operator("action.keyframe_type")
426
427         #layout.separator()
428         #layout.operator("action.copy")
429         #layout.operator("action.paste")
430
431
432 class DOPESHEET_MT_delete(Menu):
433     bl_label = "Delete"
434
435     def draw(self, context):
436         layout = self.layout
437
438         layout.operator("action.delete")
439
440         layout.separator()
441
442         layout.operator("action.clean").channels = False
443         layout.operator("action.clean", text="Clean Channels").channels = True
444
445
446 if __name__ == "__main__":  # only for live edit.
447     bpy.utils.register_module(__name__)