Animation Editors: Name-based filtering
[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
23
24 #######################################
25 # DopeSheet Filtering
26
27 # used for DopeSheet, NLA, and Graph Editors
28 def dopesheet_filter(layout, context, genericFiltersOnly=False):
29     dopesheet = context.space_data.dopesheet
30     is_nla = context.area.type == 'NLA_EDITOR'
31
32     row = layout.row(align=True)
33     row.prop(dopesheet, "show_only_selected", text="")
34     row.prop(dopesheet, "show_hidden", text="")
35
36     if not genericFiltersOnly:
37         row = layout.row(align=True)
38         row.prop(dopesheet, "show_transforms", text="")
39
40         if is_nla:
41             row.prop(dopesheet, "show_missing_nla", text="")
42
43         row = layout.row(align=True)
44         row.prop(dopesheet, "show_scenes", text="")
45         row.prop(dopesheet, "show_worlds", text="")
46         row.prop(dopesheet, "show_nodes", text="")
47
48         if bpy.data.meshes:
49             row.prop(dopesheet, "show_meshes", text="")
50         if bpy.data.shape_keys:
51             row.prop(dopesheet, "show_shapekeys", text="")
52         if bpy.data.materials:
53             row.prop(dopesheet, "show_materials", text="")
54         if bpy.data.lamps:
55             row.prop(dopesheet, "show_lamps", text="")
56         if bpy.data.textures:
57             row.prop(dopesheet, "show_textures", text="")
58         if bpy.data.cameras:
59             row.prop(dopesheet, "show_cameras", text="")
60         if bpy.data.curves:
61             row.prop(dopesheet, "show_curves", text="")
62         if bpy.data.metaballs:
63             row.prop(dopesheet, "show_metaballs", text="")
64         if bpy.data.lattices:
65             row.prop(dopesheet, "show_lattices", text="")
66         if bpy.data.armatures:
67             row.prop(dopesheet, "show_armatures", text="")
68         if bpy.data.particles:
69             row.prop(dopesheet, "show_particles", text="")
70
71         if bpy.data.groups:
72             row = layout.row(align=True)
73             row.prop(dopesheet, "show_only_group_objects", text="")
74             if dopesheet.show_only_group_objects:
75                 row.prop(dopesheet, "filter_group", text="")
76    
77     if not is_nla:
78         row = layout.row(align=True)
79         row.prop(dopesheet, "show_only_matching_fcurves", text="")
80         if dopesheet.show_only_matching_fcurves:
81             row.prop(dopesheet, "filter_fcurve_name", text="")
82
83
84 #######################################
85 # DopeSheet Editor - General/Standard UI
86
87 class DOPESHEET_HT_header(bpy.types.Header):
88     bl_space_type = 'DOPESHEET_EDITOR'
89
90     def draw(self, context):
91         layout = self.layout
92
93         st = context.space_data
94
95         row = layout.row(align=True)
96         row.template_header()
97
98         if context.area.show_menus:
99             sub = row.row(align=True)
100
101             sub.menu("DOPESHEET_MT_view")
102             sub.menu("DOPESHEET_MT_select")
103             sub.menu("DOPESHEET_MT_marker")
104
105             if st.mode == 'DOPESHEET' or (st.mode == 'ACTION' and st.action != None):
106                 sub.menu("DOPESHEET_MT_channel")
107             elif st.mode == 'GPENCIL':
108                 sub.menu("DOPESHEET_MT_gpencil_channel")
109
110             if st.mode != 'GPENCIL':
111                 sub.menu("DOPESHEET_MT_key")
112             else:
113                 sub.menu("DOPESHEET_MT_gpencil_frame")
114
115         layout.prop(st, "mode", text="")
116         layout.prop(st.dopesheet, "show_summary", text="Summary")
117
118         if st.mode == 'DOPESHEET':
119             dopesheet_filter(layout, context)
120         elif st.mode == 'ACTION':
121             # 'genericFiltersOnly' limits the options to only the relevant 'generic' subset of
122             # filters which will work here and are useful (especially for character animation)
123             dopesheet_filter(layout, context, genericFiltersOnly=True)
124
125         if st.mode in {'ACTION', 'SHAPEKEY'}:
126             layout.template_ID(st, "action", new="action.new")
127
128         # Grease Pencil mode doesn't need snapping, as it's frame-aligned only
129         if st.mode != 'GPENCIL':
130             layout.prop(st, "auto_snap", text="")
131
132         row = layout.row(align=True)
133         row.operator("action.copy", text="", icon='COPYDOWN')
134         row.operator("action.paste", text="", icon='PASTEDOWN')
135
136
137 class DOPESHEET_MT_view(bpy.types.Menu):
138     bl_label = "View"
139
140     def draw(self, context):
141         layout = self.layout
142
143         st = context.space_data
144
145         layout.column()
146
147         layout.prop(st, "use_realtime_update")
148         layout.prop(st, "show_frame_indicator")
149         layout.prop(st, "show_sliders")
150         layout.prop(st, "use_auto_merge_keyframes")
151         layout.prop(st, "use_marker_sync")
152
153         if st.show_seconds:
154             layout.operator("anim.time_toggle", text="Show Frames")
155         else:
156             layout.operator("anim.time_toggle", text="Show Seconds")
157
158         layout.separator()
159         layout.operator("anim.previewrange_set")
160         layout.operator("anim.previewrange_clear")
161         layout.operator("action.previewrange_set")
162
163         layout.separator()
164         layout.operator("action.frame_jump")
165         layout.operator("action.view_all")
166         layout.operator("action.view_selected")
167
168         layout.separator()
169         layout.operator("screen.area_dupli")
170         layout.operator("screen.screen_full_area")
171
172
173 class DOPESHEET_MT_select(bpy.types.Menu):
174     bl_label = "Select"
175
176     def draw(self, context):
177         layout = self.layout
178
179         layout.column()
180         # This is a bit misleading as the operator's default text is "Select All" while it actually *toggles* All/None
181         layout.operator("action.select_all_toggle")
182         layout.operator("action.select_all_toggle", text="Invert Selection").invert = True
183
184         layout.separator()
185         layout.operator("action.select_border")
186         layout.operator("action.select_border", text="Border Axis Range").axis_range = True
187
188         layout.separator()
189         layout.operator("action.select_column", text="Columns on Selected Keys").mode = 'KEYS'
190         layout.operator("action.select_column", text="Column on Current Frame").mode = 'CFRA'
191
192         layout.operator("action.select_column", text="Columns on Selected Markers").mode = 'MARKERS_COLUMN'
193         layout.operator("action.select_column", text="Between Selected Markers").mode = 'MARKERS_BETWEEN'
194
195         layout.separator()
196         layout.operator("action.select_leftright", text="Before Current Frame").mode = 'LEFT'
197         layout.operator("action.select_leftright", text="After Current Frame").mode = 'RIGHT'
198
199         # FIXME: grease pencil mode isn't supported for these yet, so skip for that mode only
200         if context.space_data.mode != 'GPENCIL':
201             layout.separator()
202             layout.operator("action.select_more")
203             layout.operator("action.select_less")
204
205             layout.separator()
206             layout.operator("action.select_linked")
207
208
209 class DOPESHEET_MT_marker(bpy.types.Menu):
210     bl_label = "Marker"
211
212     def draw(self, context):
213         layout = self.layout
214
215         st = context.space_data
216
217         #layout.operator_context = 'EXEC_REGION_WIN'
218
219         layout.column()
220         layout.operator("marker.add", "Add Marker")
221         layout.operator("marker.duplicate", text="Duplicate Marker")
222         layout.operator("marker.delete", text="Delete Marker")
223
224         layout.separator()
225
226         layout.operator("marker.rename", text="Rename Marker")
227         layout.operator("marker.move", text="Grab/Move Marker")
228
229         if st.mode in {'ACTION', 'SHAPEKEY'} and st.action:
230             layout.separator()
231             layout.prop(st, "show_pose_markers")
232
233             if st.show_pose_markers is False:
234                 layout.operator("action.markers_make_local")
235
236
237 #######################################
238 # Keyframe Editing
239
240 class DOPESHEET_MT_channel(bpy.types.Menu):
241     bl_label = "Channel"
242
243     def draw(self, context):
244         layout = self.layout
245
246         layout.operator_context = 'INVOKE_REGION_CHANNELS'
247
248         layout.column()
249         layout.operator("anim.channels_delete")
250
251         layout.separator()
252         layout.operator("anim.channels_setting_toggle")
253         layout.operator("anim.channels_setting_enable")
254         layout.operator("anim.channels_setting_disable")
255
256         layout.separator()
257         layout.operator("anim.channels_editable_toggle")
258         layout.operator_menu_enum("action.extrapolation_type", "type", text="Extrapolation Mode")
259
260         layout.separator()
261         layout.operator("anim.channels_expand")
262         layout.operator("anim.channels_collapse")
263
264         layout.separator()
265         layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
266
267         layout.separator()
268         layout.operator("anim.channels_fcurves_enable")
269
270
271 class DOPESHEET_MT_key(bpy.types.Menu):
272     bl_label = "Key"
273
274     def draw(self, context):
275         layout = self.layout
276
277         layout.column()
278         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
279
280         layout.operator_menu_enum("action.snap", "type", text="Snap")
281         layout.operator_menu_enum("action.mirror", "type", text="Mirror")
282
283         layout.separator()
284         layout.operator("action.keyframe_insert")
285
286         layout.separator()
287         layout.operator("action.duplicate")
288         layout.operator("action.delete")
289
290         layout.separator()
291         layout.operator_menu_enum("action.keyframe_type", "type", text="Keyframe Type")
292         layout.operator_menu_enum("action.handle_type", "type", text="Handle Type")
293         layout.operator_menu_enum("action.interpolation_type", "type", text="Interpolation Mode")
294
295         layout.separator()
296         layout.operator("action.clean")
297         layout.operator("action.sample")
298
299         layout.separator()
300         layout.operator("action.copy")
301         layout.operator("action.paste")
302
303
304 class DOPESHEET_MT_key_transform(bpy.types.Menu):
305     bl_label = "Transform"
306
307     def draw(self, context):
308         layout = self.layout
309
310         layout.column()
311         layout.operator("transform.transform", text="Grab/Move").mode = 'TIME_TRANSLATE'
312         layout.operator("transform.transform", text="Extend").mode = 'TIME_EXTEND'
313         layout.operator("transform.transform", text="Slide").mode = 'TIME_SLIDE'
314         layout.operator("transform.transform", text="Scale").mode = 'TIME_SCALE'
315
316
317 #######################################
318 # Grease Pencil Editing
319
320 class DOPESHEET_MT_gpencil_channel(bpy.types.Menu):
321     bl_label = "Channel"
322
323     def draw(self, context):
324         layout = self.layout
325
326         layout.operator_context = 'INVOKE_REGION_CHANNELS'
327
328         layout.column()
329         layout.operator("anim.channels_delete")
330
331         layout.separator()
332         layout.operator("anim.channels_setting_toggle")
333         layout.operator("anim.channels_setting_enable")
334         layout.operator("anim.channels_setting_disable")
335
336         layout.separator()
337         layout.operator("anim.channels_editable_toggle")
338
339         # XXX: to be enabled when these are ready for use!
340         #layout.separator()
341         #layout.operator("anim.channels_expand")
342         #layout.operator("anim.channels_collapse")
343
344         #layout.separator()
345         #layout.operator_menu_enum("anim.channels_move", "direction", text="Move...")
346
347
348 class DOPESHEET_MT_gpencil_frame(bpy.types.Menu):
349     bl_label = "Frame"
350
351     def draw(self, context):
352         layout = self.layout
353
354         layout.column()
355         layout.menu("DOPESHEET_MT_key_transform", text="Transform")
356
357         #layout.operator_menu_enum("action.snap", "type", text="Snap")
358         #layout.operator_menu_enum("action.mirror", "type", text="Mirror")
359
360         layout.separator()
361         layout.operator("action.duplicate")
362         layout.operator("action.delete")
363
364         #layout.separator()
365         #layout.operator("action.copy")
366         #layout.operator("action.paste")