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