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 (
23     Header,
24     Menu,
25     Panel,
26 )
27
28 #######################################
29 # DopeSheet Filtering - Header Buttons
30
31 # used for DopeSheet, NLA, and Graph Editors
32
33
34 def dopesheet_filter(layout, context, generic_filters_only=False):
35     dopesheet = context.space_data.dopesheet
36     is_nla = context.area.type == 'NLA_EDITOR'
37
38     row = layout.row(align=True)
39     row.prop(dopesheet, "show_only_selected", text="")
40     row.prop(dopesheet, "show_hidden", text="")
41
42     if is_nla:
43         row.prop(dopesheet, "show_missing_nla", text="")
44     else:  # graph and dopesheet editors - F-Curves and drivers only
45         row.prop(dopesheet, "show_only_errors", text="")
46
47     if not generic_filters_only:
48         if bpy.data.collections:
49             row = layout.row(align=True)
50             row.prop(dopesheet, "filter_collection", text="")
51
52     if not is_nla:
53         row = layout.row(align=True)
54         row.prop(dopesheet, "filter_fcurve_name", text="")
55     else:
56         row = layout.row(align=True)
57         row.prop(dopesheet, "filter_text", text="")
58
59 #######################################
60 # Dopesheet Filtering Popovers
61
62 # Generic Layout - Used as base for filtering popovers used in all animation editors
63 # Used for DopeSheet, NLA, and Graph Editors
64
65
66 class DopesheetFilterPopoverBase:
67     bl_region_type = 'HEADER'
68     bl_label = "Filters"
69
70     # Generic = Affects all datatypes
71     # XXX: Perhaps we want these to stay in the header instead, for easy/fast access
72     @classmethod
73     def draw_generic_filters(cls, context, layout):
74         dopesheet = context.space_data.dopesheet
75         is_nla = context.area.type == 'NLA_EDITOR'
76
77         col = layout.column(align=True)
78         col.prop(dopesheet, "show_only_selected", icon='NONE')
79         col.prop(dopesheet, "show_hidden", icon='NONE')
80
81         if is_nla:
82             col.prop(dopesheet, "show_missing_nla", icon='NONE')
83         else:  # graph and dopesheet editors - F-Curves and drivers only
84             col.prop(dopesheet, "show_only_errors", icon='NONE')
85
86     # Name/Membership Filters
87     # XXX: Perhaps these should just stay in the headers (exclusively)?
88     @classmethod
89     def draw_search_filters(cls, context, layout, generic_filters_only=False):
90         dopesheet = context.space_data.dopesheet
91         is_nla = context.area.type == 'NLA_EDITOR'
92
93         col = layout.column(align=True)
94         col.label(text="With Name:")
95         if not is_nla:
96             row = col.row(align=True)
97             row.prop(dopesheet, "filter_fcurve_name", text="")
98         else:
99             row = col.row(align=True)
100             row.prop(dopesheet, "filter_text", text="")
101
102         if (not generic_filters_only) and (bpy.data.collections):
103             col = layout.column(align=True)
104             col.label(text="In Collection:")
105             col.prop(dopesheet, "filter_collection", text="")
106
107     # Standard = Present in all panels
108     @classmethod
109     def draw_standard_filters(cls, context, layout):
110         dopesheet = context.space_data.dopesheet
111
112         # datablock filters
113         layout.label(text="Filter by Type:")
114         flow = layout.grid_flow(row_major=True, columns=2, even_rows=False, align=False)
115
116         flow.prop(dopesheet, "show_scenes", text="Scenes")
117         flow.prop(dopesheet, "show_nodes", text="Node Trees")
118
119         # object types
120         if bpy.data.armatures:
121             flow.prop(dopesheet, "show_armatures", text="Armatures")
122         if bpy.data.cameras:
123             flow.prop(dopesheet, "show_cameras", text="Cameras")
124         if bpy.data.grease_pencil:
125             flow.prop(dopesheet, "show_gpencil", text="Grease Pencil Objects")
126         if bpy.data.lights:
127             flow.prop(dopesheet, "show_lights", text="Lights")
128         if bpy.data.meshes:
129             flow.prop(dopesheet, "show_meshes", text="Meshes")
130         if bpy.data.curves:
131             flow.prop(dopesheet, "show_curves", text="Curves")
132         if bpy.data.lattices:
133             flow.prop(dopesheet, "show_lattices", text="Lattices")
134         if bpy.data.metaballs:
135             flow.prop(dopesheet, "show_metaballs", text="Metaballs")
136
137         # data types
138         flow.prop(dopesheet, "show_worlds", text="Worlds")
139         if bpy.data.particles:
140             flow.prop(dopesheet, "show_particles", text="Particles")
141         if bpy.data.linestyles:
142             flow.prop(dopesheet, "show_linestyles", text="Line Styles")
143         if bpy.data.speakers:
144             flow.prop(dopesheet, "show_speakers", text="Speakers")
145         if bpy.data.materials:
146             flow.prop(dopesheet, "show_materials", text="Materials")
147         if bpy.data.textures:
148             flow.prop(dopesheet, "show_textures", text="Textures")
149         if bpy.data.shape_keys:
150             flow.prop(dopesheet, "show_shapekeys", text="Shape Keys")
151
152         layout.separator()
153
154         # Object Data Filters
155
156         # TODO: Add per-channel/axis convenience toggles?
157         split = layout.split()
158
159         col = split.column()
160         col.prop(dopesheet, "show_transforms", text="Transforms")
161
162         col = split.column()
163         col.prop(dopesheet, "show_modifiers", text="Modifiers")
164
165         layout.separator()
166
167         # performance-related options (users will mostly have these enabled)
168         col = layout.column(align=True)
169         col.label(text="Options:")
170         col.prop(dopesheet, "use_datablock_sort", icon='NONE')
171
172
173 # Popover for Dopesheet Editor(s) - Dopesheet, Action, Shapekey, GPencil, Mask, etc.
174 class DOPESHEET_PT_filters(DopesheetFilterPopoverBase, Panel):
175     bl_space_type = 'DOPESHEET_EDITOR'
176     bl_region_type = 'HEADER'
177     bl_label = "Filters"
178
179     def draw(self, context):
180         layout = self.layout
181
182         dopesheet = context.space_data.dopesheet
183         ds_mode = context.space_data.mode
184
185         layout.prop(dopesheet, "show_summary", text="Summary")
186
187         DopesheetFilterPopoverBase.draw_generic_filters(context, layout)
188
189         if ds_mode in {'DOPESHEET', 'ACTION', 'GPENCIL'}:
190             layout.separator()
191             generic_filters_only = ds_mode != 'DOPESHEET'
192             DopesheetFilterPopoverBase.draw_search_filters(context, layout,
193                                                            generic_filters_only=generic_filters_only)
194
195         if ds_mode == 'DOPESHEET':
196             layout.separator()
197             DopesheetFilterPopoverBase.draw_standard_filters(context, layout)
198
199
200 #######################################
201 # DopeSheet Editor - General/Standard UI
202
203 class DOPESHEET_HT_header(Header):
204     bl_space_type = 'DOPESHEET_EDITOR'
205
206     def draw(self, context):
207         layout = self.layout
208
209         st = context.space_data
210
211         row = layout.row(align=True)
212         row.template_header()
213
214         if st.mode == 'TIMELINE':
215             from .space_time import (
216                 TIME_MT_editor_menus,
217                 TIME_HT_editor_buttons,
218             )
219             TIME_MT_editor_menus.draw_collapsible(context, layout)
220             TIME_HT_editor_buttons.draw_header(context, layout)
221         else:
222             layout.prop(st, "ui_mode", text="")
223
224             DOPESHEET_MT_editor_menus.draw_collapsible(context, layout)
225             DOPESHEET_HT_editor_buttons.draw_header(context, layout)
226
227
228 # Header for "normal" dopesheet editor modes (e.g. Dope Sheet, Action, Shape Keys, etc.)
229 class DOPESHEET_HT_editor_buttons(Header):
230     bl_idname = "DOPESHEET_HT_editor_buttons"
231     bl_space_type = 'DOPESHEET_EDITOR'
232     bl_label = ""
233
234     def draw(self, context):
235         pass
236
237     @staticmethod
238     def draw_header(context, layout):
239         st = context.space_data
240         tool_settings = context.tool_settings
241
242         if st.mode in {'ACTION', 'SHAPEKEY'}:
243             # TODO: These buttons need some tidying up - Probably by using a popover, and bypassing the template_id() here
244             row = layout.row(align=True)
245             row.operator("action.layer_prev", text="", icon='TRIA_DOWN')
246             row.operator("action.layer_next", text="", icon='TRIA_UP')
247
248             row = layout.row(align=True)
249             row.operator("action.push_down", text="Push Down", icon='NLA_PUSHDOWN')
250             row.operator("action.stash", text="Stash", icon='FREEZE')
251
252             layout.separator_spacer()
253
254             layout.template_ID(st, "action", new="action.new", unlink="action.unlink")
255
256         layout.separator_spacer()
257
258         if st.mode == 'DOPESHEET':
259             dopesheet_filter(layout, context)
260         elif st.mode == 'ACTION':
261             # 'generic_filters_only' limits the options to only the relevant 'generic' subset of
262             # filters which will work here and are useful (especially for character animation)
263             dopesheet_filter(layout, context, generic_filters_only=True)
264         elif st.mode == 'GPENCIL':
265             row = layout.row(align=True)
266             row.prop(st.dopesheet, "show_gpencil_3d_only", text="Active Only")
267
268             if st.dopesheet.show_gpencil_3d_only:
269                 row = layout.row(align=True)
270                 row.prop(st.dopesheet, "show_only_selected", text="")
271                 row.prop(st.dopesheet, "show_hidden", text="")
272
273             row = layout.row(align=True)
274             row.prop(st.dopesheet, "filter_text", text="")
275
276         layout.popover(
277             panel="DOPESHEET_PT_filters",
278             text="",
279             icon='FILTER',
280         )
281
282         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
283         if st.mode != 'GPENCIL':
284             layout.prop(st, "auto_snap", text="")
285
286         row = layout.row(align=True)
287         row.prop(tool_settings, "use_proportional_action", text="", icon_only=True)
288         sub = row.row(align=True)
289         sub.active = tool_settings.use_proportional_action
290         sub.prop(tool_settings, "proportional_edit_falloff", text="", icon_only=True)
291
292
293 class DOPESHEET_MT_editor_menus(Menu):
294     bl_idname = "DOPESHEET_MT_editor_menus"
295     bl_label = ""
296
297     def draw(self, context):
298         self.draw_menus(self.layout, context)
299
300     @staticmethod
301     def draw_menus(layout, context):
302         st = context.space_data
303
304         layout.menu("DOPESHEET_MT_view")
305         layout.menu("DOPESHEET_MT_select")
306         layout.menu("DOPESHEET_MT_marker")
307
308         if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action is not None):
309             layout.menu("DOPESHEET_MT_channel")
310         elif st.mode == 'GPENCIL':
311             layout.menu("DOPESHEET_MT_gpencil_channel")
312
313         if st.mode != 'GPENCIL':
314             layout.menu("DOPESHEET_MT_key")
315         else:
316             layout.menu("DOPESHEET_MT_gpencil_frame")
317
318
319 class DOPESHEET_MT_view(Menu):
320     bl_label = "View"
321
322     def draw(self, context):
323         layout = self.layout
324
325         st = context.space_data
326
327         layout.operator("action.properties", icon='MENU_PANEL')
328         layout.separator()
329
330         layout.prop(st.dopesheet, "use_multi_word_filter", text="Multi-word Match Search")
331
332         layout.separator()
333
334         layout.prop(st, "use_realtime_update")
335         layout.prop(st, "show_frame_indicator")
336         layout.prop(st, "show_sliders")
337         layout.prop(st, "show_group_colors")
338         layout.prop(st, "show_interpolation")
339         layout.prop(st, "show_extremes")
340         layout.prop(st, "use_auto_merge_keyframes")
341
342         layout.prop(st, "show_seconds")
343         layout.prop(st, "show_locked_time")
344
345         layout.separator()
346         layout.operator("anim.previewrange_set")
347         layout.operator("anim.previewrange_clear")
348         layout.operator("action.previewrange_set")
349
350         layout.separator()
351         layout.operator("action.view_all")
352         layout.operator("action.view_selected")
353         layout.operator("action.view_frame")
354
355         # Add this to show key-binding (reverse action in dope-sheet).
356         layout.separator()
357         props = layout.operator("wm.context_set_enum", text="Toggle Graph Editor")
358         props.data_path = "area.type"
359         props.value = 'GRAPH_EDITOR'
360
361         layout.separator()
362         layout.menu("INFO_MT_area")
363
364
365 class DOPESHEET_MT_select(Menu):
366     bl_label = "Select"
367
368     def draw(self, context):
369         layout = self.layout
370
371         layout.operator("action.select_all", text="All").action = 'SELECT'
372         layout.operator("action.select_all", text="None").action = 'DESELECT'
373         layout.operator("action.select_all", text="Invert").action = 'INVERT'
374
375         layout.separator()
376         layout.operator("action.select_box").axis_range = False
377         layout.operator("action.select_box", text="Border Axis Range").axis_range = True
378
379         layout.operator("action.select_circle")
380
381         layout.separator()
382         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
383         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
384
385         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
386         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
387
388         layout.separator()
389         props = layout.operator("action.select_leftright", text="Before Current Frame")
390         props.extend = False
391         props.mode = 'LEFT'
392         props = layout.operator("action.select_leftright", text="After Current Frame")
393         props.extend = False
394         props.mode = 'RIGHT'
395
396         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
397         if context.space_data.mode != 'GPENCIL':
398             layout.separator()
399             layout.operator("action.select_more")
400             layout.operator("action.select_less")
401
402             layout.separator()
403             layout.operator("action.select_linked")
404
405
406 class DOPESHEET_MT_marker(Menu):
407     bl_label = "Marker"
408
409     def draw(self, context):
410         layout = self.layout
411
412         from .space_time import marker_menu_generic
413         marker_menu_generic(layout)
414
415         st = context.space_data
416
417         if st.mode in {'ACTION', 'SHAPEKEY'} and st.action:
418             layout.separator()
419             layout.prop(st, "show_pose_markers")
420
421             if st.show_pose_markers is False:
422                 layout.operator("action.markers_make_local")
423
424         layout.prop(st, "use_marker_sync")
425
426 #######################################
427 # Keyframe Editing
428
429 class DOPESHEET_MT_channel(Menu):
430     bl_label = "Channel"
431
432     def draw(self, context):
433         layout = self.layout
434
435         layout.operator_context = 'INVOKE_REGION_CHANNELS'
436
437         layout.operator("anim.channels_delete")
438
439         layout.separator()
440         layout.operator("anim.channels_group")
441         layout.operator("anim.channels_ungroup")
442
443         layout.separator()
444         layout.operator_menu_enum("anim.channels_setting_toggle", "type")
445         layout.operator_menu_enum("anim.channels_setting_enable", "type")
446         layout.operator_menu_enum("anim.channels_setting_disable", "type")
447
448         layout.separator()
449         layout.operator("anim.channels_editable_toggle")
450         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
451
452         layout.separator()
453         layout.operator("anim.channels_expand")
454         layout.operator("anim.channels_collapse")
455
456         layout.separator()
457         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
458
459         layout.separator()
460         layout.operator("anim.channels_fcurves_enable")
461
462
463 class DOPESHEET_MT_key(Menu):
464     bl_label = "Key"
465
466     def draw(self, context):
467         layout = self.layout
468
469         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
470
471         layout.operator_menu_enum("action.snap", "type", text="Snap")
472         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
473
474         layout.separator()
475         layout.operator("action.keyframe_insert")
476
477         layout.separator()
478         layout.operator("action.frame_jump")
479
480         layout.separator()
481         layout.operator("action.copy")
482         layout.operator("action.paste")
483         layout.operator("action.paste", text="Paste Flipped").flipped = True
484         layout.operator("action.duplicate_move")
485         layout.operator("action.delete")
486
487         layout.separator()
488         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
489         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
490         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
491
492         layout.separator()
493         layout.operator("action.clean").channels = False
494         layout.operator("action.clean", text="Clean Channels").channels = True
495         layout.operator("action.sample")
496
497
498 class DOPESHEET_MT_key_transform(Menu):
499     bl_label = "Transform"
500
501     def draw(self, context):
502         layout = self.layout
503
504         layout.operator("transform.transform", text="Move").mode = 'TIME_TRANSLATE'
505         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
506         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
507         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
508
509
510 #######################################
511 # Grease Pencil Editing
512
513 class DOPESHEET_MT_gpencil_channel(Menu):
514     bl_label = "Channel"
515
516     def draw(self, context):
517         layout = self.layout
518
519         layout.operator_context = 'INVOKE_REGION_CHANNELS'
520
521         layout.operator("anim.channels_delete")
522
523         layout.separator()
524         layout.operator("anim.channels_setting_toggle")
525         layout.operator("anim.channels_setting_enable")
526         layout.operator("anim.channels_setting_disable")
527
528         layout.separator()
529         layout.operator("anim.channels_editable_toggle")
530
531         # XXX: to be enabled when these are ready for use!
532         # layout.separator()
533         # layout.operator("anim.channels_expand")
534         # layout.operator("anim.channels_collapse")
535
536         # layout.separator()
537         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
538
539
540 class DOPESHEET_MT_gpencil_frame(Menu):
541     bl_label = "Frame"
542
543     def draw(self, context):
544         layout = self.layout
545
546         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
547         layout.operator_menu_enum("action.snap", "type", text="Snap")
548         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
549
550         layout.separator()
551         layout.operator("action.duplicate")
552         layout.operator("action.delete")
553
554         layout.separator()
555         layout.operator("action.keyframe_type")
556
557         # layout.separator()
558         # layout.operator("action.copy")
559         # layout.operator("action.paste")
560
561
562 class DOPESHEET_MT_delete(Menu):
563     bl_label = "Delete"
564
565     def draw(self, context):
566         layout = self.layout
567
568         layout.operator("action.delete")
569
570         layout.separator()
571
572         layout.operator("action.clean").channels = False
573         layout.operator("action.clean", text="Clean Channels").channels = True
574
575
576 class DOPESHEET_MT_specials(Menu):
577     bl_label = "Dope Sheet Context Menu"
578
579     def draw(self, context):
580         layout = self.layout
581
582         layout.operator("action.copy", text="Copy")
583         layout.operator("action.paste", text="Paste")
584         layout.operator("action.paste", text="Paste Flipped").flipped = True
585
586         layout.separator()
587
588         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
589         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
590         layout.operator_menu_enum("action.easing_type", "type", text="Easing Type")
591
592         layout.separator()
593
594         layout.operator("action.keyframe_insert").type = 'SEL'
595         layout.operator("action.duplicate_move")
596         layout.operator("action.delete")
597
598         layout.separator()
599
600         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
601         layout.operator_menu_enum("action.snap", "type", text="Snap")
602
603
604 class DOPESHEET_MT_channel_specials(Menu):
605     bl_label = "Dope Sheet Channel Context Menu"
606
607     def draw(self, context):
608         layout = self.layout
609
610         layout.operator("anim.channels_setting_enable", text="Mute Channels").type = 'MUTE'
611         layout.operator("anim.channels_setting_disable", text="Unmute Channels").type = 'MUTE'
612         layout.separator()
613         layout.operator("anim.channels_setting_enable", text="Protect Channels").type = 'PROTECT'
614         layout.operator("anim.channels_setting_disable", text="Unprotect Channels").type = 'PROTECT'
615
616         layout.separator()
617         layout.operator("anim.channels_group")
618         layout.operator("anim.channels_ungroup")
619
620         layout.separator()
621         layout.operator("anim.channels_editable_toggle")
622         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
623
624         layout.separator()
625         layout.operator("anim.channels_expand")
626         layout.operator("anim.channels_collapse")
627
628         layout.separator()
629         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
630
631         layout.separator()
632
633         layout.operator("anim.channels_delete")
634
635
636 class DOPESHEET_MT_snap_pie(Menu):
637     bl_label = "Snap"
638
639     def draw(self, context):
640         layout = self.layout
641         pie = layout.menu_pie()
642
643         pie.operator("action.snap", text="Current Frame").type = 'CFRA'
644         pie.operator("action.snap", text="Nearest Frame").type = 'NEAREST_FRAME'
645         pie.operator("action.snap", text="Nearest Second").type = 'NEAREST_SECOND'
646         pie.operator("action.snap", text="Nearest Marker").type = 'NEAREST_MARKER'
647
648
649 classes = (
650     DOPESHEET_HT_header,
651     DOPESHEET_HT_editor_buttons,
652     DOPESHEET_MT_editor_menus,
653     DOPESHEET_MT_view,
654     DOPESHEET_MT_select,
655     DOPESHEET_MT_marker,
656     DOPESHEET_MT_channel,
657     DOPESHEET_MT_key,
658     DOPESHEET_MT_key_transform,
659     DOPESHEET_MT_gpencil_channel,
660     DOPESHEET_MT_gpencil_frame,
661     DOPESHEET_MT_delete,
662     DOPESHEET_MT_specials,
663     DOPESHEET_MT_channel_specials,
664     DOPESHEET_MT_snap_pie,
665     DOPESHEET_PT_filters,
666 )
667
668 if __name__ == "__main__":  # only for live edit.
669     from bpy.utils import register_class
670     for cls in classes:
671         register_class(cls)