cf5b94277e7560e6bb17eaab8cafe0416486ff9c
[blender.git] / release / scripts / startup / bl_ui / space_clip.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-80 compliant>
20
21 import bpy
22 from bpy.types import Panel, Header, Menu, UIList
23
24
25 class CLIP_UL_tracking_objects(UIList):
26     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
27         if not (item is None or isinstance(item, bpy.types.MovieTrackingObject)):
28             return
29         tobj = item
30         if self.layout_type in {'DEFAULT', 'COMPACT'}:
31             layout.label(tobj.name, icon='CAMERA_DATA' if tobj.is_camera else 'OBJECT_DATA')
32         elif self.layout_type in {'GRID'}:
33             layout.alignment = 'CENTER'
34             layout.label("", icon='CAMERA_DATA' if tobj.is_camera else 'OBJECT_DATA')
35
36
37 class CLIP_HT_header(Header):
38     bl_space_type = 'CLIP_EDITOR'
39
40     def _draw_tracking(self, context):
41         layout = self.layout
42
43         sc = context.space_data
44         clip = sc.clip
45
46         row = layout.row(align=True)
47         row.template_header()
48
49         if context.area.show_menus:
50             sub = row.row(align=True)
51             sub.menu("CLIP_MT_view")
52
53             if sc.view == 'CLIP':
54                 if clip:
55                     sub.menu("CLIP_MT_select")
56                     sub.menu("CLIP_MT_clip")
57                     sub.menu("CLIP_MT_track")
58                     sub.menu("CLIP_MT_reconstruction")
59                 else:
60                     sub.menu("CLIP_MT_clip")
61
62         row = layout.row()
63         row.template_ID(sc, "clip", open="clip.open")
64
65         if clip:
66             tracking = clip.tracking
67             active_object = tracking.objects.active
68
69             if sc.view == 'CLIP':
70                 layout.prop(sc, "mode", text="")
71                 layout.prop(sc, "view", text="", expand=True)
72                 layout.prop(sc, "pivot_point", text="", icon_only=True)
73
74                 r = active_object.reconstruction
75
76                 if r.is_valid and sc.view == 'CLIP':
77                     layout.label(text="Solve error: %.4f" %
78                                  (r.average_error))
79             elif sc.view == 'GRAPH':
80                 layout.prop(sc, "view", text="", expand=True)
81
82                 row = layout.row(align=True)
83                 row.prop(sc, "show_graph_only_selected", text="")
84                 row.prop(sc, "show_graph_hidden", text="")
85
86                 row = layout.row(align=True)
87
88                 if sc.show_filters:
89                     row.prop(sc, "show_filters", icon='DISCLOSURE_TRI_DOWN',
90                              text="Filters")
91
92                     sub = row.column()
93                     sub.active = clip.tracking.reconstruction.is_valid
94                     sub.prop(sc, "show_graph_frames", icon='SEQUENCE', text="")
95
96                     row.prop(sc, "show_graph_tracks", icon='ANIM', text="")
97                 else:
98                     row.prop(sc, "show_filters", icon='DISCLOSURE_TRI_RIGHT',
99                              text="Filters")
100             elif sc.view == 'DOPESHEET':
101                 dopesheet = tracking.dopesheet
102                 layout.prop(sc, "view", text="", expand=True)
103
104                 row = layout.row(align=True)
105                 row.prop(dopesheet, "show_only_selected", text="")
106                 row.prop(dopesheet, "show_hidden", text="")
107
108                 row = layout.row(align=True)
109                 row.prop(dopesheet, "sort_method", text="")
110                 row.prop(dopesheet, "use_invert_sort",
111                          text="Invert", toggle=True)
112         else:
113             layout.prop(sc, "view", text="", expand=True)
114
115     def _draw_masking(self, context):
116         layout = self.layout
117
118         toolsettings = context.tool_settings
119         sc = context.space_data
120         clip = sc.clip
121
122         row = layout.row(align=True)
123         row.template_header()
124
125         if context.area.show_menus:
126             sub = row.row(align=True)
127             sub.menu("CLIP_MT_view")
128
129             if clip:
130                 sub.menu("MASK_MT_select")
131                 sub.menu("CLIP_MT_clip")  # XXX - remove?
132                 sub.menu("MASK_MT_mask")
133             else:
134                 sub.menu("CLIP_MT_clip")  # XXX - remove?
135
136         row = layout.row()
137         row.template_ID(sc, "clip", open="clip.open")
138
139         layout.prop(sc, "mode", text="")
140
141         row = layout.row()
142         row.template_ID(sc, "mask", new="mask.new")
143
144         layout.prop(sc, "pivot_point", text="", icon_only=True)
145
146         row = layout.row(align=True)
147         row.prop(toolsettings, "use_proportional_edit_mask",
148                  text="", icon_only=True)
149         if toolsettings.use_proportional_edit_mask:
150             row.prop(toolsettings, "proportional_edit_falloff",
151                      text="", icon_only=True)
152
153     def draw(self, context):
154         layout = self.layout
155
156         sc = context.space_data
157
158         if sc.mode in {'TRACKING', 'RECONSTRUCTION', 'DISTORTION'}:
159             self._draw_tracking(context)
160         else:
161             self._draw_masking(context)
162
163         layout.template_running_jobs()
164
165
166 class CLIP_PT_clip_view_panel:
167
168     @classmethod
169     def poll(cls, context):
170         sc = context.space_data
171         clip = sc.clip
172
173         return clip and sc.view == 'CLIP'
174
175
176 class CLIP_PT_tracking_panel:
177
178     @classmethod
179     def poll(cls, context):
180         sc = context.space_data
181         clip = sc.clip
182
183         return clip and sc.mode == 'TRACKING' and sc.view == 'CLIP'
184
185
186 class CLIP_PT_reconstruction_panel:
187
188     @classmethod
189     def poll(cls, context):
190         sc = context.space_data
191         clip = sc.clip
192
193         return clip and sc.mode == 'RECONSTRUCTION' and sc.view == 'CLIP'
194
195
196 class CLIP_PT_tools_marker(CLIP_PT_tracking_panel, Panel):
197     bl_space_type = 'CLIP_EDITOR'
198     bl_region_type = 'TOOLS'
199     bl_label = "Marker"
200
201     def draw(self, context):
202         layout = self.layout
203
204         sc = context.space_data
205         clip = sc.clip
206         settings = clip.tracking.settings
207
208         col = layout.column(align=True)
209         col.operator("clip.add_marker_move")
210         col.operator("clip.detect_features")
211         col.operator("clip.delete_track")
212
213         box = layout.box()
214         row = box.row(align=True)
215         row.prop(settings, "show_default_expanded", text="", emboss=False)
216         row.label(text="Tracking Settings")
217
218         if settings.show_default_expanded:
219             col = box.column()
220             row = col.row(align=True)
221             label = CLIP_MT_tracking_settings_presets.bl_label
222             row.menu('CLIP_MT_tracking_settings_presets', text=label)
223             row.operator("clip.tracking_settings_preset_add",
224                          text="", icon='ZOOMIN')
225             props = row.operator("clip.tracking_settings_preset_add",
226                                  text="", icon='ZOOMOUT')
227             props.remove_active = True
228
229             col.separator()
230
231             row = col.row(align=True)
232             row.prop(settings, "use_default_red_channel",
233                      text="R", toggle=True)
234             row.prop(settings, "use_default_green_channel",
235                      text="G", toggle=True)
236             row.prop(settings, "use_default_blue_channel",
237                      text="B", toggle=True)
238
239             col.separator()
240
241             sub = col.column(align=True)
242             sub.prop(settings, "default_pattern_size")
243             sub.prop(settings, "default_search_size")
244
245             col.label(text="Tracker:")
246             col.prop(settings, "default_motion_model")
247             col.prop(settings, "use_default_brute")
248             col.prop(settings, "use_default_normalization")
249             col.prop(settings, "use_default_mask")
250             col.prop(settings, "default_correlation_min")
251
252             col.separator()
253
254             sub = col.column(align=True)
255             sub.prop(settings, "default_frames_limit")
256             sub.prop(settings, "default_margin")
257
258             col.label(text="Match:")
259             col.prop(settings, "default_pattern_match", text="")
260
261             col.separator()
262             col.operator("clip.track_settings_as_default",
263                          text="Copy From Active Track")
264
265
266 class CLIP_PT_tools_tracking(CLIP_PT_tracking_panel, Panel):
267     bl_space_type = 'CLIP_EDITOR'
268     bl_region_type = 'TOOLS'
269     bl_label = "Track"
270
271     def draw(self, context):
272         layout = self.layout
273
274         row = layout.row(align=True)
275
276         props = row.operator("clip.track_markers", text="", icon='FRAME_PREV')
277         props.backwards = True
278         props.sequence = False
279         props = row.operator("clip.track_markers", text="",
280                              icon='PLAY_REVERSE')
281         props.backwards = True
282         props.sequence = True
283         props = row.operator("clip.track_markers", text="", icon='PLAY')
284         props.backwards = False
285         props.sequence = True
286         props = row.operator("clip.track_markers", text="", icon='FRAME_NEXT')
287         props.backwards = False
288         props.sequence = False
289
290         col = layout.column(align=True)
291         props = col.operator("clip.clear_track_path", text="Clear After")
292         props.action = 'REMAINED'
293
294         props = col.operator("clip.clear_track_path", text="Clear Before")
295         props.action = 'UPTO'
296         col.operator("clip.clear_track_path", text="Clear").action = 'ALL'
297
298         layout.operator("clip.join_tracks", text="Join")
299
300
301 class CLIP_PT_tools_solve(CLIP_PT_tracking_panel, Panel):
302     bl_space_type = 'CLIP_EDITOR'
303     bl_region_type = 'TOOLS'
304     bl_label = "Solve"
305
306     def draw(self, context):
307         layout = self.layout
308
309         clip = context.space_data.clip
310         tracking = clip.tracking
311         settings = tracking.settings
312         tracking_object = tracking.objects.active
313
314         col = layout.column(align=True)
315
316         col.operator("clip.solve_camera",
317                      text="Camera Motion" if tracking_object.is_camera
318                      else "Object Motion")
319         col.operator("clip.clear_solution")
320
321         col = layout.column()
322         col.prop(settings, "use_tripod_solver")
323
324         col = layout.column(align=True)
325         col.active = not settings.use_tripod_solver
326         col.prop(tracking_object, "keyframe_a")
327         col.prop(tracking_object, "keyframe_b")
328
329         col = layout.column(align=True)
330         col.active = (tracking_object.is_camera and
331                       not settings.use_tripod_solver)
332         col.label(text="Refine:")
333         col.prop(settings, "refine_intrinsics", text="")
334
335         col = layout.column(align=True)
336         col.active = not settings.use_tripod_solver
337         col.prop(settings, "use_fallback_reconstruction", text="Allow Fallback")
338         sub = col.column()
339         sub.active = settings.use_fallback_reconstruction
340         sub.prop(settings, "reconstruction_success_threshold")
341
342
343 class CLIP_PT_tools_cleanup(CLIP_PT_tracking_panel, Panel):
344     bl_space_type = 'CLIP_EDITOR'
345     bl_region_type = 'TOOLS'
346     bl_label = "Clean up"
347
348     def draw(self, context):
349         layout = self.layout
350         clip = context.space_data.clip
351         settings = clip.tracking.settings
352
353         layout.operator("clip.clean_tracks")
354
355         layout.prop(settings, "clean_frames", text="Frames")
356         layout.prop(settings, "clean_error", text="Error")
357         layout.prop(settings, "clean_action", text="")
358
359
360 class CLIP_PT_tools_geometry(CLIP_PT_reconstruction_panel, Panel):
361     bl_space_type = 'CLIP_EDITOR'
362     bl_region_type = 'TOOLS'
363     bl_label = "Geometry"
364
365     def draw(self, context):
366         layout = self.layout
367
368         layout.operator("clip.bundles_to_mesh")
369         layout.operator("clip.track_to_empty")
370
371
372 class CLIP_PT_tools_orientation(CLIP_PT_reconstruction_panel, Panel):
373     bl_space_type = 'CLIP_EDITOR'
374     bl_region_type = 'TOOLS'
375     bl_label = "Orientation"
376
377     def draw(self, context):
378         sc = context.space_data
379         layout = self.layout
380         settings = sc.clip.tracking.settings
381
382         col = layout.column(align=True)
383         row = col.row()
384         props = row.operator("clip.set_plane", text="Floor")
385         props.plane = 'FLOOR'
386         props = row.operator("clip.set_plane", text="Wall")
387         props.plane = 'WALL'
388         col.operator("clip.set_origin")
389
390         row = col.row()
391         row.operator("clip.set_axis", text="Set X Axis").axis = 'X'
392         row.operator("clip.set_axis", text="Set Y Axis").axis = 'Y'
393
394         layout.separator()
395
396         col = layout.column()
397         col.operator("clip.set_scale")
398         col.prop(settings, "distance")
399
400
401 class CLIP_PT_tools_object(CLIP_PT_reconstruction_panel, Panel):
402     bl_space_type = 'CLIP_EDITOR'
403     bl_region_type = 'TOOLS'
404     bl_label = "Object"
405
406     @classmethod
407     def poll(cls, context):
408         if CLIP_PT_reconstruction_panel.poll(context):
409             sc = context.space_data
410             clip = sc.clip
411
412             tracking_object = clip.tracking.objects.active
413
414             return not tracking_object.is_camera
415
416         return False
417
418     def draw(self, context):
419         layout = self.layout
420
421         sc = context.space_data
422         clip = sc.clip
423         tracking_object = clip.tracking.objects.active
424         settings = sc.clip.tracking.settings
425
426         col = layout.column()
427
428         col.prop(tracking_object, "scale")
429
430         col.separator()
431
432         col.operator("clip.set_solution_scale", text="Set Scale")
433         col.prop(settings, "object_distance")
434
435
436 class CLIP_PT_tools_grease_pencil(Panel):
437     bl_space_type = 'CLIP_EDITOR'
438     bl_region_type = 'TOOLS'
439     bl_label = "Grease Pencil"
440
441     @classmethod
442     def poll(cls, context):
443         sc = context.space_data
444         clip = sc.clip
445
446         if not clip:
447             return False
448
449         if sc.mode == 'DISTORTION':
450             return sc.view == 'CLIP'
451         elif sc.mode == 'MASK':
452             return True
453
454         return False
455
456     def draw(self, context):
457         layout = self.layout
458
459         col = layout.column(align=True)
460
461         row = col.row(align=True)
462         row.operator("gpencil.draw", text="Draw").mode = 'DRAW'
463         row.operator("gpencil.draw", text="Line").mode = 'DRAW_STRAIGHT'
464
465         row = col.row(align=True)
466         row.operator("gpencil.draw", text="Poly").mode = 'DRAW_POLY'
467         row.operator("gpencil.draw", text="Erase").mode = 'ERASER'
468
469         row = col.row()
470         row.prop(context.tool_settings, "use_grease_pencil_sessions")
471
472
473 class CLIP_PT_objects(CLIP_PT_clip_view_panel, Panel):
474     bl_space_type = 'CLIP_EDITOR'
475     bl_region_type = 'UI'
476     bl_label = "Objects"
477     bl_options = {'DEFAULT_CLOSED'}
478
479     def draw(self, context):
480         layout = self.layout
481
482         sc = context.space_data
483         tracking = sc.clip.tracking
484
485         row = layout.row()
486         row.template_list("CLIP_UL_tracking_objects", "", tracking, "objects", tracking, "active_object_index", rows=3)
487
488         sub = row.column(align=True)
489
490         sub.operator("clip.tracking_object_new", icon='ZOOMIN', text="")
491         sub.operator("clip.tracking_object_remove", icon='ZOOMOUT', text="")
492
493         active = tracking.objects.active
494         if active:
495             layout.prop(active, "name")
496
497
498 class CLIP_PT_track(CLIP_PT_tracking_panel, Panel):
499     bl_space_type = 'CLIP_EDITOR'
500     bl_region_type = 'UI'
501     bl_label = "Track"
502
503     def draw(self, context):
504         layout = self.layout
505
506         sc = context.space_data
507         clip = context.space_data.clip
508         act_track = clip.tracking.tracks.active
509
510         if not act_track:
511             layout.active = False
512             layout.label(text="No active track")
513             return
514
515         row = layout.row()
516         row.prop(act_track, "name", text="")
517
518         sub = row.row(align=True)
519
520         sub.template_marker(sc, "clip", sc.clip_user, act_track, True)
521
522         icon = 'LOCKED' if act_track.lock else 'UNLOCKED'
523         sub.prop(act_track, "lock", text="", icon=icon)
524
525         layout.template_track(sc, "scopes")
526
527         row = layout.row(align=True)
528         sub = row.row()
529         sub.prop(act_track, "use_red_channel", text="R", toggle=True)
530         sub.prop(act_track, "use_green_channel", text="G", toggle=True)
531         sub.prop(act_track, "use_blue_channel", text="B", toggle=True)
532
533         row.separator()
534
535         sub = row.row()
536         sub.prop(act_track, "use_grayscale_preview", text="B/W", toggle=True)
537
538         row.separator()
539         sub = row.row()
540         sub.prop(act_track, "use_alpha_preview",
541                  text="", toggle=True, icon='IMAGE_ALPHA')
542
543         layout.separator()
544
545         row = layout.row(align=True)
546         label = bpy.types.CLIP_MT_track_color_presets.bl_label
547         row.menu('CLIP_MT_track_color_presets', text=label)
548         row.menu('CLIP_MT_track_color_specials', text="", icon='DOWNARROW_HLT')
549         row.operator("clip.track_color_preset_add", text="", icon='ZOOMIN')
550         props = row.operator("clip.track_color_preset_add",
551                              text="", icon='ZOOMOUT')
552         props.remove_active = True
553
554         row = layout.row()
555         row.prop(act_track, "use_custom_color")
556         if act_track.use_custom_color:
557             row.prop(act_track, "color", text="")
558
559         if act_track.has_bundle:
560             label_text = "Average Error: %.4f" % (act_track.average_error)
561             layout.label(text=label_text)
562
563
564 class CLIP_PT_track_settings(CLIP_PT_tracking_panel, Panel):
565     bl_space_type = 'CLIP_EDITOR'
566     bl_region_type = 'UI'
567     bl_label = "Tracking Settings"
568     bl_options = {'DEFAULT_CLOSED'}
569
570     def draw(self, context):
571         layout = self.layout
572
573         clip = context.space_data.clip
574         settings = clip.tracking.settings
575
576         col = layout.column()
577
578         active = clip.tracking.tracks.active
579         if active:
580             col.prop(active, "motion_model")
581             col.prop(active, "use_brute")
582             col.prop(active, "use_normalization")
583             col.prop(active, "use_mask")
584             col.prop(active, "correlation_min")
585
586             col.separator()
587             col.prop(active, "frames_limit")
588             col.prop(active, "margin")
589             col.prop(active, "pattern_match", text="Match")
590
591         col.prop(settings, "speed")
592
593
594 class CLIP_PT_tracking_camera(Panel):
595     bl_space_type = 'CLIP_EDITOR'
596     bl_region_type = 'UI'
597     bl_label = "Camera Data"
598     bl_options = {'DEFAULT_CLOSED'}
599
600     @classmethod
601     def poll(cls, context):
602         if CLIP_PT_clip_view_panel.poll(context):
603             sc = context.space_data
604
605             return sc.mode in {'TRACKING', 'DISTORTION'} and sc.clip
606
607         return False
608
609     def draw(self, context):
610         layout = self.layout
611
612         sc = context.space_data
613         clip = sc.clip
614
615         row = layout.row(align=True)
616         label = bpy.types.CLIP_MT_camera_presets.bl_label
617         row.menu('CLIP_MT_camera_presets', text=label)
618         row.operator("clip.camera_preset_add", text="", icon='ZOOMIN')
619         props = row.operator("clip.camera_preset_add", text="", icon='ZOOMOUT')
620         props.remove_active = True
621
622         row = layout.row(align=True)
623         sub = row.split(percentage=0.65)
624         if clip.tracking.camera.units == 'MILLIMETERS':
625             sub.prop(clip.tracking.camera, "focal_length")
626         else:
627             sub.prop(clip.tracking.camera, "focal_length_pixels")
628         sub.prop(clip.tracking.camera, "units", text="")
629
630         col = layout.column(align=True)
631         col.label(text="Sensor:")
632         col.prop(clip.tracking.camera, "sensor_width", text="Width")
633         col.prop(clip.tracking.camera, "pixel_aspect")
634
635         col = layout.column()
636         col.label(text="Optical Center:")
637         row = col.row()
638         row.prop(clip.tracking.camera, "principal", text="")
639         col.operator("clip.set_center_principal", text="Center")
640
641         col = layout.column(align=True)
642         col.label(text="Lens Distortion:")
643         col.prop(clip.tracking.camera, "k1")
644         col.prop(clip.tracking.camera, "k2")
645         col.prop(clip.tracking.camera, "k3")
646
647
648 class CLIP_PT_display(CLIP_PT_clip_view_panel, Panel):
649     bl_space_type = 'CLIP_EDITOR'
650     bl_region_type = 'UI'
651     bl_label = "Display"
652
653     def draw(self, context):
654         layout = self.layout
655         sc = context.space_data
656
657         row = layout.row(align=True)
658         sub = row.row()
659         sub.prop(sc, "show_red_channel", text="R", toggle=True)
660         sub.prop(sc, "show_green_channel", text="G", toggle=True)
661         sub.prop(sc, "show_blue_channel", text="B", toggle=True)
662
663         row.separator()
664
665         sub = row.row()
666         sub.prop(sc, "use_grayscale_preview", text="B/W", toggle=True)
667
668         col = layout.column(align=True)
669
670         col.prop(sc, "show_disabled", "Disabled Tracks")
671         col.prop(sc, "show_names", text="Names and Status")
672         col.prop(sc, "show_bundles", text="3D Markers")
673
674         col.prop(sc, "use_mute_footage", text="Mute Footage")
675         col.prop(sc, "lock_selection")
676
677         if sc.view == 'GRAPH':
678             col.prop(sc, "lock_time_cursor")
679
680         if sc.mode == 'DISTORTION':
681             col.prop(sc, "show_grid", text="Grid")
682             col.prop(sc, "use_manual_calibration")
683         elif sc.mode == 'RECONSTRUCTION':
684             col.prop(sc, "show_stable", text="Stable")
685
686         clip = sc.clip
687         if clip:
688             col.label(text="Display Aspect Ratio:")
689             row = col.row()
690             row.prop(clip, "display_aspect", text="")
691
692
693 class CLIP_PT_marker_display(CLIP_PT_clip_view_panel, Panel):
694     bl_space_type = 'CLIP_EDITOR'
695     bl_region_type = 'UI'
696     bl_label = "Marker Display"
697
698     @classmethod
699     def poll(cls, context):
700         sc = context.space_data
701
702         return sc.mode != 'MASK'
703
704     def draw(self, context):
705         layout = self.layout
706         sc = context.space_data
707
708         col = layout.column(align=True)
709
710         row = col.row()
711         row.prop(sc, "show_marker_pattern", text="Pattern")
712         row.prop(sc, "show_marker_search", text="Search")
713
714         col.prop(sc, "show_tiny_markers", text="Thin Markers")
715         col.prop(sc, "show_track_path", text="Path")
716
717         row = col.row()
718         row.active = sc.show_track_path
719         row.prop(sc, "path_length", text="Length")
720
721
722 class CLIP_PT_stabilization(CLIP_PT_reconstruction_panel, Panel):
723     bl_space_type = 'CLIP_EDITOR'
724     bl_region_type = 'UI'
725     bl_label = "2D Stabilization"
726     bl_options = {'DEFAULT_CLOSED'}
727
728     def draw_header(self, context):
729         stab = context.space_data.clip.tracking.stabilization
730
731         self.layout.prop(stab, "use_2d_stabilization", text="")
732
733     def draw(self, context):
734         layout = self.layout
735
736         tracking = context.space_data.clip.tracking
737         stab = tracking.stabilization
738
739         layout.active = stab.use_2d_stabilization
740
741         row = layout.row()
742         row.template_list("UI_UL_list", "", stab, "tracks", stab, "active_track_index", rows=3)
743
744         sub = row.column(align=True)
745
746         sub.operator("clip.stabilize_2d_add", icon='ZOOMIN', text="")
747         sub.operator("clip.stabilize_2d_remove", icon='ZOOMOUT', text="")
748
749         sub.menu('CLIP_MT_stabilize_2d_specials', text="",
750                  icon='DOWNARROW_HLT')
751
752         layout.prop(stab, "influence_location")
753
754         layout.prop(stab, "use_autoscale")
755         col = layout.column()
756         col.active = stab.use_autoscale
757         col.prop(stab, "scale_max")
758         col.prop(stab, "influence_scale")
759
760         layout.prop(stab, "use_stabilize_rotation")
761         col = layout.column()
762         col.active = stab.use_stabilize_rotation
763
764         row = col.row(align=True)
765         row.prop_search(stab, "rotation_track", tracking, "tracks", text="")
766         row.operator("clip.stabilize_2d_set_rotation", text="", icon='ZOOMIN')
767
768         row = col.row()
769         row.active = stab.rotation_track is not None
770         row.prop(stab, "influence_rotation")
771
772         layout.prop(stab, "filter_type")
773
774
775 class CLIP_PT_marker(CLIP_PT_tracking_panel, Panel):
776     bl_space_type = 'CLIP_EDITOR'
777     bl_region_type = 'UI'
778     bl_label = "Marker"
779     bl_options = {'DEFAULT_CLOSED'}
780
781     def draw(self, context):
782         layout = self.layout
783         sc = context.space_data
784         clip = context.space_data.clip
785         act_track = clip.tracking.tracks.active
786
787         if act_track:
788             layout.template_marker(sc, "clip", sc.clip_user, act_track, False)
789         else:
790             layout.active = False
791             layout.label(text="No active track")
792
793
794 class CLIP_PT_proxy(CLIP_PT_clip_view_panel, Panel):
795     bl_space_type = 'CLIP_EDITOR'
796     bl_region_type = 'UI'
797     bl_label = "Proxy / Timecode"
798     bl_options = {'DEFAULT_CLOSED'}
799
800     def draw_header(self, context):
801         sc = context.space_data
802
803         self.layout.prop(sc.clip, "use_proxy", text="")
804
805     def draw(self, context):
806         layout = self.layout
807
808         sc = context.space_data
809         clip = sc.clip
810
811         col = layout.column()
812         col.active = clip.use_proxy
813
814         col.label(text="Build Original:")
815
816         row = col.row(align=True)
817         row.prop(clip.proxy, "build_25", toggle=True)
818         row.prop(clip.proxy, "build_50", toggle=True)
819         row.prop(clip.proxy, "build_75", toggle=True)
820         row.prop(clip.proxy, "build_100", toggle=True)
821
822         col.label(text="Build Undistorted:")
823
824         row = col.row(align=True)
825         row.prop(clip.proxy, "build_undistorted_25", toggle=True)
826         row.prop(clip.proxy, "build_undistorted_50", toggle=True)
827         row.prop(clip.proxy, "build_undistorted_75", toggle=True)
828         row.prop(clip.proxy, "build_undistorted_100", toggle=True)
829
830         col.prop(clip.proxy, "quality")
831
832         col.prop(clip, "use_proxy_custom_directory")
833         if clip.use_proxy_custom_directory:
834             col.prop(clip.proxy, "directory")
835
836         col.operator("clip.rebuild_proxy", text="Build Proxy")
837
838         if clip.source == 'MOVIE':
839             col2 = col.column()
840
841             col2.label(text="Use timecode index:")
842             col2.prop(clip.proxy, "timecode", text="")
843
844         col2 = col.column()
845         col2.label(text="Proxy render size:")
846
847         col.prop(sc.clip_user, "proxy_render_size", text="")
848
849         col = layout.column()
850         col.prop(sc.clip_user, "use_render_undistorted")
851
852
853 class CLIP_PT_footage(CLIP_PT_clip_view_panel, Panel):
854     bl_space_type = 'CLIP_EDITOR'
855     bl_region_type = 'UI'
856     bl_label = "Footage Settings"
857     bl_options = {'DEFAULT_CLOSED'}
858
859     def draw(self, context):
860         layout = self.layout
861
862         sc = context.space_data
863         clip = sc.clip
864
865         col = layout.column()
866         col.template_movieclip(sc, "clip", compact=True)
867         col.prop(clip, "frame_start")
868         col.prop(clip, "frame_offset")
869
870
871 class CLIP_PT_tools_clip(CLIP_PT_clip_view_panel, Panel):
872     bl_space_type = 'CLIP_EDITOR'
873     bl_region_type = 'TOOLS'
874     bl_label = "Clip"
875
876     def draw(self, context):
877         layout = self.layout
878
879         layout.operator("clip.set_viewport_background")
880         layout.operator("clip.setup_tracking_scene")
881
882
883 class CLIP_MT_view(Menu):
884     bl_label = "View"
885
886     def draw(self, context):
887         layout = self.layout
888
889         sc = context.space_data
890
891         if sc.view == 'CLIP':
892             layout.operator("clip.properties", icon='MENU_PANEL')
893             layout.operator("clip.tools", icon='MENU_PANEL')
894             layout.separator()
895
896             layout.operator("clip.view_selected")
897             layout.operator("clip.view_all")
898
899             layout.separator()
900             layout.operator("clip.view_zoom_in")
901             layout.operator("clip.view_zoom_out")
902
903             layout.separator()
904
905             ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
906
907             for a, b in ratios:
908                 text = "Zoom %d:%d" % (a, b)
909                 layout.operator("clip.view_zoom_ratio",
910                                 text=text).ratio = a / b
911         else:
912             if sc.view == 'GRAPH':
913                 layout.operator_context = 'INVOKE_REGION_PREVIEW'
914                 layout.operator("clip.graph_center_current_frame")
915                 layout.operator("clip.graph_view_all")
916                 layout.operator_context = 'INVOKE_DEFAULT'
917
918             layout.prop(sc, "show_seconds")
919             layout.separator()
920
921         layout.separator()
922         layout.operator("screen.area_dupli")
923         layout.operator("screen.screen_full_area")
924
925
926 class CLIP_MT_clip(Menu):
927     bl_label = "Clip"
928
929     def draw(self, context):
930         layout = self.layout
931
932         sc = context.space_data
933         clip = sc.clip
934
935         layout.operator("clip.open")
936
937         if clip:
938             layout.operator("clip.reload")
939             layout.menu("CLIP_MT_proxy")
940
941
942 class CLIP_MT_proxy(Menu):
943     bl_label = "Proxy"
944
945     def draw(self, context):
946         layout = self.layout
947
948         layout.operator("clip.rebuild_proxy")
949         layout.operator("clip.delete_proxy")
950
951
952 class CLIP_MT_track(Menu):
953     bl_label = "Track"
954
955     def draw(self, context):
956         layout = self.layout
957
958         layout.operator("clip.clear_solution")
959         layout.operator("clip.solve_camera")
960
961         layout.separator()
962         props = layout.operator("clip.clear_track_path", text="Clear After")
963         props.action = 'REMAINED'
964
965         props = layout.operator("clip.clear_track_path", text="Clear Before")
966         props.action = 'UPTO'
967
968         props = layout.operator("clip.clear_track_path",
969                                 text="Clear Track Path")
970         props.action = 'ALL'
971
972         layout.separator()
973         layout.operator("clip.join_tracks")
974
975         layout.separator()
976         layout.operator("clip.clean_tracks")
977
978         layout.separator()
979         layout.operator("clip.copy_tracks")
980         layout.operator("clip.paste_tracks")
981
982         layout.separator()
983         props = layout.operator("clip.track_markers",
984                                 text="Track Frame Backwards")
985         props.backwards = True
986
987         props = layout.operator("clip.track_markers", text="Track Backwards")
988         props.backwards = True
989         props.sequence = True
990
991         props = layout.operator("clip.track_markers", text="Track Forwards")
992         props.sequence = True
993         layout.operator("clip.track_markers", text="Track Frame Forwards")
994
995         layout.separator()
996         layout.operator("clip.delete_track")
997         layout.operator("clip.delete_marker")
998
999         layout.separator()
1000         layout.operator("clip.add_marker_move")
1001
1002         layout.separator()
1003         layout.menu("CLIP_MT_track_visibility")
1004         layout.menu("CLIP_MT_track_transform")
1005
1006
1007 class CLIP_MT_reconstruction(Menu):
1008     bl_label = "Reconstruction"
1009
1010     def draw(self, context):
1011         layout = self.layout
1012
1013         layout.operator("clip.set_origin")
1014         props = layout.operator("clip.set_plane", text="Set Floor")
1015         props.plane = 'FLOOR'
1016         props = layout.operator("clip.set_plane", text="Set Wall")
1017         props.plane = 'WALL'
1018
1019         layout.operator("clip.set_axis", text="Set X Axis").axis = "X"
1020         layout.operator("clip.set_axis", text="Set Y Axis").axis = "Y"
1021
1022         layout.operator("clip.set_scale")
1023
1024         layout.separator()
1025
1026         layout.operator("clip.track_to_empty")
1027         layout.operator("clip.bundles_to_mesh")
1028
1029
1030 class CLIP_MT_track_visibility(Menu):
1031     bl_label = "Show/Hide"
1032
1033     def draw(self, context):
1034         layout = self.layout
1035
1036         layout.operator("clip.hide_tracks_clear", text="Show Hidden")
1037         layout.operator("clip.hide_tracks", text="Hide Selected")
1038
1039         props = layout.operator("clip.hide_tracks", text="Hide Unselected")
1040         props.unselected = True
1041
1042
1043 class CLIP_MT_track_transform(Menu):
1044     bl_label = "Transform"
1045
1046     def draw(self, context):
1047         layout = self.layout
1048
1049         layout.operator("transform.translate")
1050         layout.operator("transform.resize")
1051
1052
1053 class CLIP_MT_select(Menu):
1054     bl_label = "Select"
1055
1056     def draw(self, context):
1057         layout = self.layout
1058
1059         layout.operator("clip.select_border")
1060         layout.operator("clip.select_circle")
1061
1062         layout.separator()
1063
1064         layout.operator("clip.select_all"
1065                         ).action = 'TOGGLE'
1066         layout.operator("clip.select_all",
1067                         text="Inverse").action = 'INVERT'
1068
1069         layout.menu("CLIP_MT_select_grouped")
1070
1071
1072 class CLIP_MT_select_grouped(Menu):
1073     bl_label = "Select Grouped"
1074
1075     def draw(self, context):
1076         layout = self.layout
1077
1078         layout.operator_enum("clip.select_grouped", "group")
1079
1080
1081 class CLIP_MT_tracking_specials(Menu):
1082     bl_label = "Specials"
1083
1084     @classmethod
1085     def poll(cls, context):
1086         return context.space_data.clip
1087
1088     def draw(self, context):
1089         layout = self.layout
1090
1091         props = layout.operator("clip.disable_markers",
1092                                 text="Enable Markers")
1093         props.action = 'ENABLE'
1094
1095         props = layout.operator("clip.disable_markers", text="Disable markers")
1096         props.action = 'DISABLE'
1097
1098         layout.separator()
1099         layout.operator("clip.set_origin")
1100
1101         layout.separator()
1102         layout.operator("clip.hide_tracks")
1103         layout.operator("clip.hide_tracks_clear", text="Show Tracks")
1104
1105         layout.separator()
1106         props = layout.operator("clip.lock_tracks", text="Lock Tracks")
1107         props.action = 'LOCK'
1108
1109         props = layout.operator("clip.lock_tracks", text="Unlock Tracks")
1110         props.action = 'UNLOCK'
1111
1112
1113 class CLIP_MT_select_mode(Menu):
1114     bl_label = "Select Mode"
1115
1116     def draw(self, context):
1117         layout = self.layout
1118
1119         layout.operator_context = 'INVOKE_REGION_WIN'
1120
1121         layout.operator_enum("clip.mode_set", "mode")
1122
1123
1124 class CLIP_MT_camera_presets(Menu):
1125     """Predefined tracking camera intrinsics"""
1126     bl_label = "Camera Presets"
1127     preset_subdir = "tracking_camera"
1128     preset_operator = "script.execute_preset"
1129     draw = Menu.draw_preset
1130
1131
1132 class CLIP_MT_track_color_presets(Menu):
1133     """Predefined track color"""
1134     bl_label = "Color Presets"
1135     preset_subdir = "tracking_track_color"
1136     preset_operator = "script.execute_preset"
1137     draw = Menu.draw_preset
1138
1139
1140 class CLIP_MT_tracking_settings_presets(Menu):
1141     """Predefined tracking settings"""
1142     bl_label = "Tracking Presets"
1143     preset_subdir = "tracking_settings"
1144     preset_operator = "script.execute_preset"
1145     draw = Menu.draw_preset
1146
1147
1148 class CLIP_MT_track_color_specials(Menu):
1149     bl_label = "Track Color Specials"
1150
1151     def draw(self, context):
1152         layout = self.layout
1153
1154         layout.operator("clip.track_copy_color", icon='COPY_ID')
1155
1156
1157 class CLIP_MT_stabilize_2d_specials(Menu):
1158     bl_label = "Track Color Specials"
1159
1160     def draw(self, context):
1161         layout = self.layout
1162
1163         layout.operator("clip.stabilize_2d_select")
1164
1165
1166 # -----------------------------------------------------------------------------
1167 # Mask (similar code in space_image.py, keep in sync)
1168
1169
1170 from bl_ui.properties_mask_common import (MASK_PT_mask,
1171                                           MASK_PT_layers,
1172                                           MASK_PT_spline,
1173                                           MASK_PT_point,
1174                                           MASK_PT_display,
1175                                           MASK_PT_tools)
1176
1177
1178 class CLIP_PT_mask(MASK_PT_mask, Panel):
1179     bl_space_type = 'CLIP_EDITOR'
1180     bl_region_type = 'UI'
1181
1182
1183 class CLIP_PT_mask_layers(MASK_PT_layers, Panel):
1184     bl_space_type = 'CLIP_EDITOR'
1185     bl_region_type = 'UI'
1186
1187
1188 class CLIP_PT_mask_display(MASK_PT_display, Panel):
1189     bl_space_type = 'CLIP_EDITOR'
1190     bl_region_type = 'UI'
1191
1192
1193 class CLIP_PT_active_mask_spline(MASK_PT_spline, Panel):
1194     bl_space_type = 'CLIP_EDITOR'
1195     bl_region_type = 'UI'
1196
1197
1198 class CLIP_PT_active_mask_point(MASK_PT_point, Panel):
1199     bl_space_type = 'CLIP_EDITOR'
1200     bl_region_type = 'UI'
1201
1202
1203 class CLIP_PT_tools_mask(MASK_PT_tools, Panel):
1204     bl_space_type = 'CLIP_EDITOR'
1205     bl_region_type = 'TOOLS'
1206
1207 # --- end mask ---
1208
1209 if __name__ == "__main__":  # only for live edit.
1210     bpy.utils.register_module(__name__)