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