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