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