f0f8cf1028d9d34f3f7cc5a50563893baf4b9aec
[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         layout = self.layout
299         st = context.space_data
300
301         layout.menu("DOPESHEET_MT_view")
302         layout.menu("DOPESHEET_MT_select")
303         layout.menu("DOPESHEET_MT_marker")
304
305         if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action is not None):
306             layout.menu("DOPESHEET_MT_channel")
307         elif st.mode == 'GPENCIL':
308             layout.menu("DOPESHEET_MT_gpencil_channel")
309
310         if st.mode != 'GPENCIL':
311             layout.menu("DOPESHEET_MT_key")
312         else:
313             layout.menu("DOPESHEET_MT_gpencil_frame")
314
315
316 class DOPESHEET_MT_view(Menu):
317     bl_label = "View"
318
319     def draw(self, context):
320         layout = self.layout
321
322         st = context.space_data
323
324         layout.operator("action.properties", icon='MENU_PANEL')
325         layout.separator()
326
327         layout.prop(st.dopesheet, "use_multi_word_filter", text="Multi-word Match Search")
328
329         layout.separator()
330
331         layout.prop(st, "use_realtime_update")
332         layout.prop(st, "show_frame_indicator")
333         layout.prop(st, "show_sliders")
334         layout.prop(st, "show_group_colors")
335         layout.prop(st, "show_interpolation")
336         layout.prop(st, "show_extremes")
337         layout.prop(st, "use_auto_merge_keyframes")
338
339         layout.prop(st, "show_seconds")
340         layout.prop(st, "show_locked_time")
341
342         layout.separator()
343         layout.operator("anim.previewrange_set")
344         layout.operator("anim.previewrange_clear")
345         layout.operator("action.previewrange_set")
346
347         layout.separator()
348         layout.operator("action.view_all")
349         layout.operator("action.view_selected")
350         layout.operator("action.view_frame")
351
352         # Add this to show key-binding (reverse action in dope-sheet).
353         layout.separator()
354         props = layout.operator("wm.context_set_enum", text="Toggle Graph Editor")
355         props.data_path = "area.type"
356         props.value = 'GRAPH_EDITOR'
357
358         layout.separator()
359         layout.menu("INFO_MT_area")
360
361
362 class DOPESHEET_MT_select(Menu):
363     bl_label = "Select"
364
365     def draw(self, context):
366         layout = self.layout
367
368         layout.operator("action.select_all", text="All").action = 'SELECT'
369         layout.operator("action.select_all", text="None").action = 'DESELECT'
370         layout.operator("action.select_all", text="Invert").action = 'INVERT'
371
372         layout.separator()
373         layout.operator("action.select_box").axis_range = False
374         layout.operator("action.select_box", text="Border Axis Range").axis_range = True
375
376         layout.operator("action.select_circle")
377
378         layout.separator()
379         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
380         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
381
382         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
383         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
384
385         layout.separator()
386         props = layout.operator("action.select_leftright", text="Before Current Frame")
387         props.extend = False
388         props.mode = 'LEFT'
389         props = layout.operator("action.select_leftright", text="After Current Frame")
390         props.extend = False
391         props.mode = 'RIGHT'
392
393         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
394         if context.space_data.mode != 'GPENCIL':
395             layout.separator()
396             layout.operator("action.select_more")
397             layout.operator("action.select_less")
398
399             layout.separator()
400             layout.operator("action.select_linked")
401
402
403 class DOPESHEET_MT_marker(Menu):
404     bl_label = "Marker"
405
406     def draw(self, context):
407         layout = self.layout
408
409         from .space_time import marker_menu_generic
410         marker_menu_generic(layout)
411
412         st = context.space_data
413
414         if st.mode in {'ACTION', 'SHAPEKEY'} and st.action:
415             layout.separator()
416             layout.prop(st, "show_pose_markers")
417
418             if st.show_pose_markers is False:
419                 layout.operator("action.markers_make_local")
420
421         layout.prop(st, "use_marker_sync")
422
423 #######################################
424 # Keyframe Editing
425
426
427 class DOPESHEET_MT_channel(Menu):
428     bl_label = "Channel"
429
430     def draw(self, context):
431         layout = self.layout
432
433         layout.operator_context = 'INVOKE_REGION_CHANNELS'
434
435         layout.operator("anim.channels_delete")
436
437         layout.separator()
438         layout.operator("anim.channels_group")
439         layout.operator("anim.channels_ungroup")
440
441         layout.separator()
442         layout.operator_menu_enum("anim.channels_setting_toggle", "type")
443         layout.operator_menu_enum("anim.channels_setting_enable", "type")
444         layout.operator_menu_enum("anim.channels_setting_disable", "type")
445
446         layout.separator()
447         layout.operator("anim.channels_editable_toggle")
448         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
449
450         layout.separator()
451         layout.operator("anim.channels_expand")
452         layout.operator("anim.channels_collapse")
453
454         layout.separator()
455         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
456
457         layout.separator()
458         layout.operator("anim.channels_fcurves_enable")
459
460
461 class DOPESHEET_MT_key(Menu):
462     bl_label = "Key"
463
464     def draw(self, context):
465         layout = self.layout
466
467         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
468
469         layout.operator_menu_enum("action.snap", "type", text="Snap")
470         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
471
472         layout.separator()
473         layout.operator("action.keyframe_insert")
474
475         layout.separator()
476         layout.operator("action.frame_jump")
477
478         layout.separator()
479         layout.operator("action.copy")
480         layout.operator("action.paste")
481         layout.operator("action.paste", text="Paste Flipped").flipped = True
482         layout.operator("action.duplicate_move")
483         layout.operator("action.delete")
484
485         layout.separator()
486         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
487         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
488         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
489
490         layout.separator()
491         layout.operator("action.clean").channels = False
492         layout.operator("action.clean", text="Clean Channels").channels = True
493         layout.operator("action.sample")
494
495
496 class DOPESHEET_MT_key_transform(Menu):
497     bl_label = "Transform"
498
499     def draw(self, context):
500         layout = self.layout
501
502         layout.operator("transform.transform", text="Move").mode = 'TIME_TRANSLATE'
503         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
504         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
505         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
506
507
508 #######################################
509 # Grease Pencil Editing
510
511 class DOPESHEET_MT_gpencil_channel(Menu):
512     bl_label = "Channel"
513
514     def draw(self, context):
515         layout = self.layout
516
517         layout.operator_context = 'INVOKE_REGION_CHANNELS'
518
519         layout.operator("anim.channels_delete")
520
521         layout.separator()
522         layout.operator("anim.channels_setting_toggle")
523         layout.operator("anim.channels_setting_enable")
524         layout.operator("anim.channels_setting_disable")
525
526         layout.separator()
527         layout.operator("anim.channels_editable_toggle")
528
529         # XXX: to be enabled when these are ready for use!
530         # layout.separator()
531         # layout.operator("anim.channels_expand")
532         # layout.operator("anim.channels_collapse")
533
534         # layout.separator()
535         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
536
537
538 class DOPESHEET_MT_gpencil_frame(Menu):
539     bl_label = "Frame"
540
541     def draw(self, context):
542         layout = self.layout
543
544         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
545         layout.operator_menu_enum("action.snap", "type", text="Snap")
546         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
547
548         layout.separator()
549         layout.operator("action.duplicate")
550         layout.operator("action.delete")
551
552         layout.separator()
553         layout.operator("action.keyframe_type")
554
555         # layout.separator()
556         # layout.operator("action.copy")
557         # layout.operator("action.paste")
558
559
560 class DOPESHEET_MT_delete(Menu):
561     bl_label = "Delete"
562
563     def draw(self, context):
564         layout = self.layout
565
566         layout.operator("action.delete")
567
568         layout.separator()
569
570         layout.operator("action.clean").channels = False
571         layout.operator("action.clean", text="Clean Channels").channels = True
572
573
574 class DOPESHEET_MT_specials(Menu):
575     bl_label = "Dope Sheet Context Menu"
576
577     def draw(self, context):
578         layout = self.layout
579
580         layout.operator("action.copy", text="Copy")
581         layout.operator("action.paste", text="Paste")
582         layout.operator("action.paste", text="Paste Flipped").flipped = True
583
584         layout.separator()
585
586         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
587         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
588         layout.operator_menu_enum("action.easing_type", "type", text="Easing Type")
589
590         layout.separator()
591
592         layout.operator("action.keyframe_insert").type = 'SEL'
593         layout.operator("action.duplicate_move")
594         layout.operator("action.delete")
595
596         layout.separator()
597
598         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
599         layout.operator_menu_enum("action.snap", "type", text="Snap")
600
601
602 class DOPESHEET_MT_channel_specials(Menu):
603     bl_label = "Dope Sheet Channel Context Menu"
604
605     def draw(self, context):
606         layout = self.layout
607
608         layout.operator("anim.channels_setting_enable", text="Mute Channels").type = 'MUTE'
609         layout.operator("anim.channels_setting_disable", text="Unmute Channels").type = 'MUTE'
610         layout.separator()
611         layout.operator("anim.channels_setting_enable", text="Protect Channels").type = 'PROTECT'
612         layout.operator("anim.channels_setting_disable", text="Unprotect Channels").type = 'PROTECT'
613
614         layout.separator()
615         layout.operator("anim.channels_group")
616         layout.operator("anim.channels_ungroup")
617
618         layout.separator()
619         layout.operator("anim.channels_editable_toggle")
620         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
621
622         layout.separator()
623         layout.operator("anim.channels_expand")
624         layout.operator("anim.channels_collapse")
625
626         layout.separator()
627         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
628
629         layout.separator()
630
631         layout.operator("anim.channels_delete")
632
633
634 class DOPESHEET_MT_snap_pie(Menu):
635     bl_label = "Snap"
636
637     def draw(self, context):
638         layout = self.layout
639         pie = layout.menu_pie()
640
641         pie.operator("action.snap", text="Current Frame").type = 'CFRA'
642         pie.operator("action.snap", text="Nearest Frame").type = 'NEAREST_FRAME'
643         pie.operator("action.snap", text="Nearest Second").type = 'NEAREST_SECOND'
644         pie.operator("action.snap", text="Nearest Marker").type = 'NEAREST_MARKER'
645
646
647 classes = (
648     DOPESHEET_HT_header,
649     DOPESHEET_HT_editor_buttons,
650     DOPESHEET_MT_editor_menus,
651     DOPESHEET_MT_view,
652     DOPESHEET_MT_select,
653     DOPESHEET_MT_marker,
654     DOPESHEET_MT_channel,
655     DOPESHEET_MT_key,
656     DOPESHEET_MT_key_transform,
657     DOPESHEET_MT_gpencil_channel,
658     DOPESHEET_MT_gpencil_frame,
659     DOPESHEET_MT_delete,
660     DOPESHEET_MT_specials,
661     DOPESHEET_MT_channel_specials,
662     DOPESHEET_MT_snap_pie,
663     DOPESHEET_PT_filters,
664 )
665
666 if __name__ == "__main__":  # only for live edit.
667     from bpy.utils import register_class
668     for cls in classes:
669         register_class(cls)