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