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