a7a352f303b10d9c08ac0baa876ade40d8f4c91a
[blender-staging.git] / release / scripts / startup / bl_ui / space_clip.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8-80 compliant>
20
21 import bpy
22 from bpy.types import Panel, Header, Menu, UIList
23 from bpy.app.translations import pgettext_iface as iface_
24 from bl_ui.properties_grease_pencil_common import (
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 in {'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 in {'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 in {'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 in {'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 in {'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", text="Build Proxy")
991
992         if clip.source == 'MOVIE':
993             col2 = col.column()
994
995             col2.label(text="Use timecode index:")
996             col2.prop(clip.proxy, "timecode", text="")
997
998         col2 = col.column()
999         col2.label(text="Proxy render size:")
1000
1001         col.prop(sc.clip_user, "proxy_render_size", text="")
1002
1003
1004 # -----------------------------------------------------------------------------
1005 # Mask (similar code in space_image.py, keep in sync)
1006
1007 from bl_ui.properties_mask_common import (
1008         MASK_PT_mask,
1009         MASK_PT_layers,
1010         MASK_PT_spline,
1011         MASK_PT_point,
1012         MASK_PT_display,
1013         MASK_PT_tools,
1014         MASK_PT_transforms,
1015         MASK_PT_add,
1016         )
1017
1018
1019 class CLIP_PT_mask_layers(MASK_PT_layers, Panel):
1020     bl_space_type = 'CLIP_EDITOR'
1021     bl_region_type = 'UI'
1022
1023
1024 class CLIP_PT_mask_display(MASK_PT_display, Panel):
1025     bl_space_type = 'CLIP_EDITOR'
1026     bl_region_type = 'UI'
1027
1028
1029 class CLIP_PT_active_mask_spline(MASK_PT_spline, Panel):
1030     bl_space_type = 'CLIP_EDITOR'
1031     bl_region_type = 'UI'
1032
1033
1034 class CLIP_PT_active_mask_point(MASK_PT_point, Panel):
1035     bl_space_type = 'CLIP_EDITOR'
1036     bl_region_type = 'UI'
1037
1038
1039 class CLIP_PT_mask(MASK_PT_mask, Panel):
1040     bl_space_type = 'CLIP_EDITOR'
1041     bl_region_type = 'UI'
1042
1043
1044 class CLIP_PT_tools_mask_add(MASK_PT_add, Panel):
1045     bl_space_type = 'CLIP_EDITOR'
1046     bl_region_type = 'TOOLS'
1047
1048
1049 class CLIP_PT_tools_mask_transforms(MASK_PT_transforms, Panel):
1050     bl_space_type = 'CLIP_EDITOR'
1051     bl_region_type = 'TOOLS'
1052
1053
1054 class CLIP_PT_tools_mask(MASK_PT_tools, Panel):
1055     bl_space_type = 'CLIP_EDITOR'
1056     bl_region_type = 'TOOLS'
1057
1058 # --- end mask ---
1059
1060
1061 class CLIP_PT_footage(CLIP_PT_clip_view_panel, Panel):
1062     bl_space_type = 'CLIP_EDITOR'
1063     bl_region_type = 'UI'
1064     bl_label = "Footage Settings"
1065     bl_options = {'DEFAULT_CLOSED'}
1066
1067     def draw(self, context):
1068         layout = self.layout
1069
1070         sc = context.space_data
1071         clip = sc.clip
1072
1073         col = layout.column()
1074         col.template_movieclip(sc, "clip", compact=True)
1075         col.prop(clip, "frame_start")
1076         col.prop(clip, "frame_offset")
1077
1078
1079 class CLIP_PT_footage_info(CLIP_PT_clip_view_panel, Panel):
1080     bl_space_type = 'CLIP_EDITOR'
1081     bl_region_type = 'UI'
1082     bl_label = "Footage Information"
1083     bl_options = {'DEFAULT_CLOSED'}
1084
1085     def draw(self, context):
1086         layout = self.layout
1087
1088         sc = context.space_data
1089
1090         col = layout.column()
1091         col.template_movieclip_information(sc, "clip", sc.clip_user)
1092
1093
1094 class CLIP_PT_tools_scenesetup(Panel):
1095     bl_space_type = 'CLIP_EDITOR'
1096     bl_region_type = 'TOOLS'
1097     bl_label = "Scene Setup"
1098     bl_translation_context = bpy.app.translations.contexts.id_movieclip
1099     bl_category = "Solve"
1100
1101     @classmethod
1102     def poll(cls, context):
1103         sc = context.space_data
1104         clip = sc.clip
1105
1106         return clip and sc.view == 'CLIP' and sc.mode != 'MASK'
1107
1108     def draw(self, context):
1109         layout = self.layout
1110
1111         layout.operator("clip.set_viewport_background")
1112         layout.operator("clip.setup_tracking_scene")
1113
1114
1115 # Grease Pencil properties
1116 class CLIP_PT_grease_pencil(GreasePencilDataPanel, CLIP_PT_clip_view_panel, Panel):
1117     bl_space_type = 'CLIP_EDITOR'
1118     bl_region_type = 'UI'
1119     bl_options = {'DEFAULT_CLOSED'}
1120
1121     # NOTE: this is just a wrapper around the generic GP Panel
1122     # But, this should only be visible in "clip" view
1123
1124
1125 # Grease Pencil drawing tools
1126 class CLIP_PT_tools_grease_pencil_draw(GreasePencilDrawingToolsPanel, Panel):
1127     bl_space_type = 'CLIP_EDITOR'
1128
1129
1130 # Grease Pencil stroke editing tools
1131 class CLIP_PT_tools_grease_pencil_edit(GreasePencilStrokeEditPanel, Panel):
1132     bl_space_type = 'CLIP_EDITOR'
1133
1134
1135 class CLIP_MT_view(Menu):
1136     bl_label = "View"
1137
1138     def draw(self, context):
1139         layout = self.layout
1140
1141         sc = context.space_data
1142
1143         if sc.view == 'CLIP':
1144             layout.operator("clip.properties", icon='MENU_PANEL')
1145             layout.operator("clip.tools", icon='MENU_PANEL')
1146             layout.separator()
1147
1148             layout.operator("clip.view_selected")
1149             layout.operator("clip.view_all")
1150
1151             layout.separator()
1152             layout.operator("clip.view_zoom_in")
1153             layout.operator("clip.view_zoom_out")
1154
1155             layout.separator()
1156
1157             ratios = ((1, 8), (1, 4), (1, 2), (1, 1), (2, 1), (4, 1), (8, 1))
1158
1159             text = iface_("Zoom %d:%d")
1160             for a, b in ratios:
1161                 layout.operator("clip.view_zoom_ratio",
1162                                 text=text % (a, b),
1163                                 translate=False).ratio = a / b
1164         else:
1165             if sc.view == 'GRAPH':
1166                 layout.operator_context = 'INVOKE_REGION_PREVIEW'
1167                 layout.operator("clip.graph_center_current_frame")
1168                 layout.operator("clip.graph_view_all")
1169                 layout.operator_context = 'INVOKE_DEFAULT'
1170
1171             layout.prop(sc, "show_seconds")
1172             layout.prop(sc, "show_locked_time")
1173             layout.separator()
1174
1175         layout.separator()
1176         layout.operator("screen.area_dupli")
1177         layout.operator("screen.screen_full_area", text="Toggle Maximize Area")
1178         layout.operator("screen.screen_full_area").use_hide_panels = True
1179
1180
1181 class CLIP_MT_clip(Menu):
1182     bl_label = "Clip"
1183     bl_translation_context = bpy.app.translations.contexts.id_movieclip
1184
1185     def draw(self, context):
1186         layout = self.layout
1187
1188         sc = context.space_data
1189         clip = sc.clip
1190
1191         layout.operator("clip.open")
1192
1193         if clip:
1194             layout.operator("clip.prefetch")
1195             layout.operator("clip.reload")
1196             layout.menu("CLIP_MT_proxy")
1197
1198
1199 class CLIP_MT_proxy(Menu):
1200     bl_label = "Proxy"
1201
1202     def draw(self, context):
1203         layout = self.layout
1204
1205         layout.operator("clip.rebuild_proxy")
1206         layout.operator("clip.delete_proxy")
1207
1208
1209 class CLIP_MT_track(Menu):
1210     bl_label = "Track"
1211
1212     def draw(self, context):
1213         layout = self.layout
1214
1215         layout.operator("clip.clear_solution")
1216         layout.operator("clip.solve_camera")
1217
1218         layout.separator()
1219         props = layout.operator("clip.clear_track_path", text="Clear After")
1220         props.clear_active = False
1221         props.action = 'REMAINED'
1222
1223         props = layout.operator("clip.clear_track_path", text="Clear Before")
1224         props.clear_active = False
1225         props.action = 'UPTO'
1226
1227         props = layout.operator("clip.clear_track_path", text="Clear Track Path")
1228         props.clear_active = False
1229         props.action = 'ALL'
1230
1231         layout.separator()
1232         layout.operator("clip.join_tracks")
1233
1234         layout.separator()
1235         layout.operator("clip.clean_tracks")
1236
1237         layout.separator()
1238         layout.operator("clip.copy_tracks")
1239         layout.operator("clip.paste_tracks")
1240
1241         layout.separator()
1242         props = layout.operator("clip.track_markers", text="Track Frame Backwards")
1243         props.backwards = True
1244         props.sequence = False
1245
1246         props = layout.operator("clip.track_markers", text="Track Backwards")
1247         props.backwards = True
1248         props.sequence = True
1249
1250         props = layout.operator("clip.track_markers", text="Track Forwards")
1251         props.backwards = False
1252         props.sequence = True
1253
1254         props = layout.operator("clip.track_markers", text="Track Frame Forwards")
1255         props.backwards = False
1256         props.sequence = False
1257
1258         layout.separator()
1259         layout.operator("clip.delete_track")
1260         layout.operator("clip.delete_marker")
1261
1262         layout.separator()
1263         layout.operator("clip.add_marker_move")
1264
1265         layout.separator()
1266         layout.menu("CLIP_MT_track_visibility")
1267         layout.menu("CLIP_MT_track_transform")
1268
1269
1270 class CLIP_MT_reconstruction(Menu):
1271     bl_label = "Reconstruction"
1272
1273     def draw(self, context):
1274         layout = self.layout
1275
1276         layout.operator("clip.set_origin")
1277         layout.operator("clip.set_plane", text="Set Floor").plane = 'FLOOR'
1278         layout.operator("clip.set_plane", text="Set Wall").plane = 'WALL'
1279
1280         layout.operator("clip.set_axis", text="Set X Axis").axis = 'X'
1281         layout.operator("clip.set_axis", text="Set Y Axis").axis = 'Y'
1282
1283         layout.operator("clip.set_scale")
1284
1285         layout.separator()
1286
1287         layout.operator("clip.track_to_empty")
1288         layout.operator("clip.bundles_to_mesh")
1289
1290
1291 class CLIP_MT_track_visibility(Menu):
1292     bl_label = "Show/Hide"
1293
1294     def draw(self, context):
1295         layout = self.layout
1296
1297         layout.operator("clip.hide_tracks_clear", text="Show Hidden")
1298         layout.operator("clip.hide_tracks", text="Hide Selected").unselected = False
1299         layout.operator("clip.hide_tracks", text="Hide Unselected").unselected = True
1300
1301
1302 class CLIP_MT_track_transform(Menu):
1303     bl_label = "Transform"
1304
1305     def draw(self, context):
1306         layout = self.layout
1307
1308         layout.operator("transform.translate")
1309         layout.operator("transform.resize")
1310
1311
1312 class CLIP_MT_select(Menu):
1313     bl_label = "Select"
1314
1315     def draw(self, context):
1316         layout = self.layout
1317
1318         layout.operator("clip.select_border")
1319         layout.operator("clip.select_circle")
1320
1321         layout.separator()
1322
1323         layout.operator("clip.select_all"
1324                         ).action = 'TOGGLE'
1325         layout.operator("clip.select_all",
1326                         text="Inverse").action = 'INVERT'
1327
1328         layout.menu("CLIP_MT_select_grouped")
1329
1330
1331 class CLIP_MT_select_grouped(Menu):
1332     bl_label = "Select Grouped"
1333
1334     def draw(self, context):
1335         layout = self.layout
1336
1337         layout.operator_enum("clip.select_grouped", "group")
1338
1339
1340 class CLIP_MT_tracking_specials(Menu):
1341     bl_label = "Specials"
1342
1343     @classmethod
1344     def poll(cls, context):
1345         return context.space_data.clip
1346
1347     def draw(self, context):
1348         layout = self.layout
1349
1350         layout.operator("clip.disable_markers",
1351                         text="Enable Markers").action = 'ENABLE'
1352
1353         layout.operator("clip.disable_markers",
1354                         text="Disable markers").action = 'DISABLE'
1355
1356         layout.separator()
1357         layout.operator("clip.set_origin")
1358
1359         layout.separator()
1360         layout.operator("clip.hide_tracks")
1361         layout.operator("clip.hide_tracks_clear", text="Show Tracks")
1362
1363         layout.separator()
1364         layout.operator("clip.lock_tracks", text="Lock Tracks").action = 'LOCK'
1365
1366         layout.operator("clip.lock_tracks",
1367                         text="Unlock Tracks").action = 'UNLOCK'
1368
1369
1370 class CLIP_MT_camera_presets(Menu):
1371     """Predefined tracking camera intrinsics"""
1372     bl_label = "Camera Presets"
1373     preset_subdir = "tracking_camera"
1374     preset_operator = "script.execute_preset"
1375     draw = Menu.draw_preset
1376
1377
1378 class CLIP_MT_track_color_presets(Menu):
1379     """Predefined track color"""
1380     bl_label = "Color Presets"
1381     preset_subdir = "tracking_track_color"
1382     preset_operator = "script.execute_preset"
1383     draw = Menu.draw_preset
1384
1385
1386 class CLIP_MT_tracking_settings_presets(Menu):
1387     """Predefined tracking settings"""
1388     bl_label = "Tracking Presets"
1389     preset_subdir = "tracking_settings"
1390     preset_operator = "script.execute_preset"
1391     draw = Menu.draw_preset
1392
1393
1394 class CLIP_MT_track_color_specials(Menu):
1395     bl_label = "Track Color Specials"
1396
1397     def draw(self, context):
1398         layout = self.layout
1399
1400         layout.operator("clip.track_copy_color", icon='COPY_ID')
1401
1402
1403 class CLIP_MT_stabilize_2d_specials(Menu):
1404     bl_label = "Track Color Specials"
1405
1406     def draw(self, context):
1407         layout = self.layout
1408
1409         layout.operator("clip.stabilize_2d_select")
1410
1411
1412 if __name__ == "__main__":  # only for live edit.
1413     bpy.utils.register_module(__name__)