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