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