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