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