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