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