47c5de861cabf0b9f11fe36d5d095bee6c2d16fc
[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 class DOPESHEET_MT_channel(Menu):
427     bl_label = "Channel"
428
429     def draw(self, context):
430         layout = self.layout
431
432         layout.operator_context = 'INVOKE_REGION_CHANNELS'
433
434         layout.operator("anim.channels_delete")
435
436         layout.separator()
437         layout.operator("anim.channels_group")
438         layout.operator("anim.channels_ungroup")
439
440         layout.separator()
441         layout.operator_menu_enum("anim.channels_setting_toggle", "type")
442         layout.operator_menu_enum("anim.channels_setting_enable", "type")
443         layout.operator_menu_enum("anim.channels_setting_disable", "type")
444
445         layout.separator()
446         layout.operator("anim.channels_editable_toggle")
447         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
448
449         layout.separator()
450         layout.operator("anim.channels_expand")
451         layout.operator("anim.channels_collapse")
452
453         layout.separator()
454         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
455
456         layout.separator()
457         layout.operator("anim.channels_fcurves_enable")
458
459
460 class DOPESHEET_MT_key(Menu):
461     bl_label = "Key"
462
463     def draw(self, context):
464         layout = self.layout
465
466         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
467
468         layout.operator_menu_enum("action.snap", "type", text="Snap")
469         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
470
471         layout.separator()
472         layout.operator("action.keyframe_insert")
473
474         layout.separator()
475         layout.operator("action.frame_jump")
476
477         layout.separator()
478         layout.operator("action.copy")
479         layout.operator("action.paste")
480         layout.operator("action.paste", text="Paste Flipped").flipped = True
481         layout.operator("action.duplicate_move")
482         layout.operator("action.delete")
483
484         layout.separator()
485         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
486         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
487         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
488
489         layout.separator()
490         layout.operator("action.clean").channels = False
491         layout.operator("action.clean", text="Clean Channels").channels = True
492         layout.operator("action.sample")
493
494
495 class DOPESHEET_MT_key_transform(Menu):
496     bl_label = "Transform"
497
498     def draw(self, context):
499         layout = self.layout
500
501         layout.operator("transform.transform", text="Move").mode = 'TIME_TRANSLATE'
502         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
503         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
504         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
505
506
507 #######################################
508 # Grease Pencil Editing
509
510 class DOPESHEET_MT_gpencil_channel(Menu):
511     bl_label = "Channel"
512
513     def draw(self, context):
514         layout = self.layout
515
516         layout.operator_context = 'INVOKE_REGION_CHANNELS'
517
518         layout.operator("anim.channels_delete")
519
520         layout.separator()
521         layout.operator("anim.channels_setting_toggle")
522         layout.operator("anim.channels_setting_enable")
523         layout.operator("anim.channels_setting_disable")
524
525         layout.separator()
526         layout.operator("anim.channels_editable_toggle")
527
528         # XXX: to be enabled when these are ready for use!
529         # layout.separator()
530         # layout.operator("anim.channels_expand")
531         # layout.operator("anim.channels_collapse")
532
533         # layout.separator()
534         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
535
536
537 class DOPESHEET_MT_gpencil_frame(Menu):
538     bl_label = "Frame"
539
540     def draw(self, context):
541         layout = self.layout
542
543         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
544         layout.operator_menu_enum("action.snap", "type", text="Snap")
545         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
546
547         layout.separator()
548         layout.operator("action.duplicate")
549         layout.operator("action.delete")
550
551         layout.separator()
552         layout.operator("action.keyframe_type")
553
554         # layout.separator()
555         # layout.operator("action.copy")
556         # layout.operator("action.paste")
557
558
559 class DOPESHEET_MT_delete(Menu):
560     bl_label = "Delete"
561
562     def draw(self, context):
563         layout = self.layout
564
565         layout.operator("action.delete")
566
567         layout.separator()
568
569         layout.operator("action.clean").channels = False
570         layout.operator("action.clean", text="Clean Channels").channels = True
571
572
573 class DOPESHEET_MT_specials(Menu):
574     bl_label = "Dope Sheet Context Menu"
575
576     def draw(self, context):
577         layout = self.layout
578
579         layout.operator("action.copy", text="Copy")
580         layout.operator("action.paste", text="Paste")
581         layout.operator("action.paste", text="Paste Flipped").flipped = True
582
583         layout.separator()
584
585         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
586         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
587         layout.operator_menu_enum("action.easing_type", "type", text="Easing Type")
588
589         layout.separator()
590
591         layout.operator("action.keyframe_insert").type = 'SEL'
592         layout.operator("action.duplicate_move")
593         layout.operator("action.delete")
594
595         layout.separator()
596
597         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
598         layout.operator_menu_enum("action.snap", "type", text="Snap")
599
600
601 class DOPESHEET_MT_channel_specials(Menu):
602     bl_label = "Dope Sheet Channel Context Menu"
603
604     def draw(self, context):
605         layout = self.layout
606
607         layout.operator("anim.channels_setting_enable", text="Mute Channels").type = 'MUTE'
608         layout.operator("anim.channels_setting_disable", text="Unmute Channels").type = 'MUTE'
609         layout.separator()
610         layout.operator("anim.channels_setting_enable", text="Protect Channels").type = 'PROTECT'
611         layout.operator("anim.channels_setting_disable", text="Unprotect Channels").type = 'PROTECT'
612
613         layout.separator()
614         layout.operator("anim.channels_group")
615         layout.operator("anim.channels_ungroup")
616
617         layout.separator()
618         layout.operator("anim.channels_editable_toggle")
619         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
620
621         layout.separator()
622         layout.operator("anim.channels_expand")
623         layout.operator("anim.channels_collapse")
624
625         layout.separator()
626         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
627
628         layout.separator()
629
630         layout.operator("anim.channels_delete")
631
632
633 class DOPESHEET_MT_snap_pie(Menu):
634     bl_label = "Snap"
635
636     def draw(self, context):
637         layout = self.layout
638         pie = layout.menu_pie()
639
640         pie.operator("action.snap", text="Current Frame").type = 'CFRA'
641         pie.operator("action.snap", text="Nearest Frame").type = 'NEAREST_FRAME'
642         pie.operator("action.snap", text="Nearest Second").type = 'NEAREST_SECOND'
643         pie.operator("action.snap", text="Nearest Marker").type = 'NEAREST_MARKER'
644
645
646 classes = (
647     DOPESHEET_HT_header,
648     DOPESHEET_HT_editor_buttons,
649     DOPESHEET_MT_editor_menus,
650     DOPESHEET_MT_view,
651     DOPESHEET_MT_select,
652     DOPESHEET_MT_marker,
653     DOPESHEET_MT_channel,
654     DOPESHEET_MT_key,
655     DOPESHEET_MT_key_transform,
656     DOPESHEET_MT_gpencil_channel,
657     DOPESHEET_MT_gpencil_frame,
658     DOPESHEET_MT_delete,
659     DOPESHEET_MT_specials,
660     DOPESHEET_MT_channel_specials,
661     DOPESHEET_MT_snap_pie,
662     DOPESHEET_PT_filters,
663 )
664
665 if __name__ == "__main__":  # only for live edit.
666     from bpy.utils import register_class
667     for cls in classes:
668         register_class(cls)