operator renaming for more consistent word ordering (_add/_remmove shold be last...
[blender-staging.git] / release / scripts / ui / space_view3d.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 import dynamic_menu
22
23
24 class VIEW3D_HT_header(bpy.types.Header):
25     bl_space_type = 'VIEW_3D'
26
27     def draw(self, context):
28         layout = self.layout
29
30         # view = context.space_data
31         mode_string = context.mode
32         edit_object = context.edit_object
33         object = context.active_object
34
35         row = layout.row(align=True)
36         row.template_header()
37
38         # Menus
39         if context.area.show_menus:
40             sub = row.row(align=True)
41
42             sub.menu("VIEW3D_MT_view")
43
44             # Select Menu
45             if mode_string not in ('EDIT_TEXT', 'SCULPT', 'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE'):
46                 sub.menu("VIEW3D_MT_select_%s" % mode_string.lower())
47
48             if edit_object:
49                 sub.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())
50             elif object:
51                 if mode_string not in ['PAINT_WEIGHT', 'PAINT_TEXTURE']:
52                     sub.menu("VIEW3D_MT_%s" % mode_string.lower())
53             else:
54                 sub.menu("VIEW3D_MT_object")
55
56         layout.template_header_3D()
57
58 # ********** Menu **********
59
60 # ********** Utilities **********
61
62
63 class VIEW3D_MT_showhide(bpy.types.Menu):
64     bl_label = "Show/Hide"
65     _operator_name = ""
66
67     def draw(self, context):
68         layout = self.layout
69
70         layout.operator("%s.reveal" % self._operator_name, text="Show Hidden")
71         layout.operator("%s.hide" % self._operator_name, text="Hide Selected")
72         layout.operator("%s.hide" % self._operator_name, text="Hide Unselected").unselected = True
73
74
75 class VIEW3D_MT_transform(bpy.types.Menu):
76     bl_label = "Transform"
77
78     # TODO: get rid of the custom text strings?
79     def draw(self, context):
80         layout = self.layout
81         
82         layout.operator("tfm.translate", text="Grab/Move")
83         # TODO: sub-menu for grab per axis
84         layout.operator("tfm.rotate", text="Rotate")
85         # TODO: sub-menu for rot per axis
86         layout.operator("tfm.resize", text="Scale")
87         # TODO: sub-menu for scale per axis
88         
89         layout.separator()
90         
91         layout.operator("tfm.tosphere", text="To Sphere")
92         layout.operator("tfm.shear", text="Shear")
93         layout.operator("tfm.warp", text="Warp")
94         layout.operator("tfm.transform", text="Push/Pull").mode = 'PUSHPULL'
95         if context.edit_object and context.edit_object.type == 'ARMATURE':
96             layout.operator("armature.align")
97         else:
98             layout.operator_context = 'EXEC_AREA'
99             layout.operator("tfm.transform", text="Align to Transform Orientation").mode = 'ALIGN' # XXX see alignmenu() in edit.c of b2.4x to get this working
100         
101         layout.separator()
102         
103         layout.operator_context = 'EXEC_AREA'
104         
105         layout.operator("object.center_set", text="ObData to Centroid").type = 'CENTER'
106         layout.operator("object.center_set", text="Centroid to ObData").type = 'CENTER_NEW'
107         layout.operator("object.center_set", text="Centroid to 3D Cursor").type = 'CENTER_CURSOR'
108      
109 class VIEW3D_MT_mirror(bpy.types.Menu):
110     bl_label = "Mirror"
111
112     def draw(self, context):
113         layout = self.layout
114
115         layout.operator("tfm.mirror", text="Interactive Mirror")
116         
117         layout.separator()
118         
119         layout.operator_context = 'INVOKE_REGION_WIN'
120         
121         props = layout.operator("tfm.mirror", text="X Global")
122         props.constraint_axis = (True, False, False)
123         props.constraint_orientation = 'GLOBAL'
124         props = layout.operator("tfm.mirror", text="Y Global")
125         props.constraint_axis = (False, True, False)
126         props.constraint_orientation = 'GLOBAL'
127         props = layout.operator("tfm.mirror", text="Z Global")
128         props.constraint_axis = (False, False, True)
129         props.constraint_orientation = 'GLOBAL'
130         
131         if context.edit_object:
132             layout.separator()
133             
134             props = layout.operator("tfm.mirror", text="X Local")
135             props.constraint_axis = (True, False, False)
136             props.constraint_orientation = 'LOCAL'
137             props = layout.operator("tfm.mirror", text="Y Local")
138             props.constraint_axis = (False, True, False)
139             props.constraint_orientation = 'LOCAL'
140             props = layout.operator("tfm.mirror", text="Z Local")
141             props.constraint_axis = (False, False, True)
142             props.constraint_orientation = 'LOCAL'
143    
144 class VIEW3D_MT_snap(bpy.types.Menu):
145     bl_label = "Snap"
146
147     def draw(self, context):
148         layout = self.layout
149
150         layout.operator("view3d.snap_selected_to_grid", text="Selection to Grid")
151         layout.operator("view3d.snap_selected_to_cursor", text="Selection to Cursor")
152         layout.operator("view3d.snap_selected_to_center", text="Selection to Center")
153
154         layout.separator()
155
156         layout.operator("view3d.snap_cursor_to_selected", text="Cursor to Selected")
157         layout.operator("view3d.snap_cursor_to_grid", text="Cursor to Grid")
158         layout.operator("view3d.snap_cursor_to_active", text="Cursor to Active")
159
160
161 class VIEW3D_MT_uv_map(dynamic_menu.DynMenu):
162     bl_label = "UV Mapping"
163
164     def draw(self, context):
165         layout = self.layout
166
167         layout.operator("uv.unwrap")
168         layout.operator("uv.cube_project")
169         layout.operator("uv.cylinder_project")
170         layout.operator("uv.sphere_project")
171         layout.operator("uv.project_from_view")
172
173         layout.separator()
174
175         layout.operator("uv.reset")
176
177 # ********** View menus **********
178
179
180 class VIEW3D_MT_view(bpy.types.Menu):
181     bl_label = "View"
182
183     def draw(self, context):
184         layout = self.layout
185
186         layout.operator("view3d.properties", icon='ICON_MENU_PANEL')
187         layout.operator("view3d.toolbar", icon='ICON_MENU_PANEL')
188
189         layout.separator()
190
191         layout.operator("view3d.viewnumpad", text="Camera").type = 'CAMERA'
192         layout.operator("view3d.viewnumpad", text="Top").type = 'TOP'
193         layout.operator("view3d.viewnumpad", text="Front").type = 'FRONT'
194         layout.operator("view3d.viewnumpad", text="Right").type = 'RIGHT'
195
196         layout.menu("VIEW3D_MT_view_cameras", text="Cameras")
197
198         layout.separator()
199
200         layout.operator("view3d.view_persportho")
201
202         layout.separator()
203
204         layout.menu("VIEW3D_MT_view_navigation")
205         layout.menu("VIEW3D_MT_view_align")
206
207         layout.separator()
208
209         layout.operator_context = 'INVOKE_REGION_WIN'
210
211         layout.operator("view3d.clip_border", text="Clipping Border...")
212         layout.operator("view3d.zoom_border", text="Zoom Border...")
213
214         layout.separator()
215
216         layout.operator("view3d.layers", text="Show All Layers").nr = 0
217
218         layout.separator()
219
220         layout.operator("view3d.localview", text="View Global/Local")
221         layout.operator("view3d.view_center")
222         layout.operator("view3d.view_all")
223
224         layout.separator()
225
226         layout.operator("screen.region_foursplit", text="Toggle Quad View")
227         layout.operator("screen.screen_full_area", text="Toggle Full Screen")
228
229         layout.separator()
230
231         layout.operator("screen.animation_play", text="Playback Animation", icon='ICON_PLAY')
232
233
234 class VIEW3D_MT_view_navigation(bpy.types.Menu):
235     bl_label = "Navigation"
236
237     def draw(self, context):
238         layout = self.layout
239
240         layout.operator_enums("view3d.view_orbit", "type")
241
242         layout.separator()
243
244         layout.operator_enums("view3d.view_pan", "type")
245
246         layout.separator()
247
248         layout.operator("view3d.zoom", text="Zoom In").delta = 1.0
249         layout.operator("view3d.zoom", text="Zoom Out").delta = -1.0
250
251         layout.separator()
252
253         layout.operator("view3d.fly")
254
255
256 class VIEW3D_MT_view_align(bpy.types.Menu):
257     bl_label = "Align View"
258
259     def draw(self, context):
260         layout = self.layout
261
262         layout.menu("VIEW3D_MT_view_align_selected")
263
264         layout.separator()
265
266         layout.operator("view3d.view_all", text="Center Cursor and View All").center = True
267         layout.operator("view3d.camera_to_view", text="Align Active Camera to View")
268         layout.operator("view3d.view_center")
269         layout.operator("view3d.view_center_cursor")
270
271
272 class VIEW3D_MT_view_align_selected(bpy.types.Menu):
273     bl_label = "Align View to Selected"
274
275     def draw(self, context):
276         layout = self.layout
277
278         props = layout.operator("view3d.viewnumpad", text="Top")
279         props.align_active = True
280         props.type = 'TOP'
281         props = layout.operator("view3d.viewnumpad", text="Bottom")
282         props.align_active = True
283         props.type = 'BOTTOM'
284         props = layout.operator("view3d.viewnumpad", text="Front")
285         props.align_active = True
286         props.type = 'FRONT'
287         props = layout.operator("view3d.viewnumpad", text="Back")
288         props.align_active = True
289         props.type = 'BACK'
290         props = layout.operator("view3d.viewnumpad", text="Right")
291         props.align_active = True
292         props.type = 'RIGHT'
293         props = layout.operator("view3d.viewnumpad", text="Left")
294         props.align_active = True
295         props.type = 'LEFT'
296
297
298 class VIEW3D_MT_view_cameras(bpy.types.Menu):
299     bl_label = "Cameras"
300
301     def draw(self, context):
302         layout = self.layout
303
304         layout.operator("view3d.object_as_camera")
305         layout.operator("view3d.viewnumpad", text="Active Camera").type = 'CAMERA'
306
307 # ********** Select menus, suffix from context.mode **********
308
309
310 class VIEW3D_MT_select_object(bpy.types.Menu):
311     bl_label = "Select"
312
313     def draw(self, context):
314         layout = self.layout
315
316         layout.operator("view3d.select_border")
317         layout.operator("view3d.select_circle")
318
319         layout.separator()
320
321         layout.operator("object.select_all_toggle", text="Select/Deselect All")
322         layout.operator("object.select_inverse", text="Inverse")
323         layout.operator("object.select_random", text="Random")
324         layout.operator("object.select_mirror", text="Mirror")
325         layout.operator("object.select_by_layer", text="Select All by Layer")
326         layout.operator_menu_enum("object.select_by_type", "type", "", text="Select All by Type...")
327
328         layout.separator()
329
330         layout.operator_menu_enum("object.select_grouped", "type", text="Grouped")
331         layout.operator_menu_enum("object.select_linked", "type", text="Linked")
332         layout.operator("object.select_pattern", text="Select Pattern...")
333
334
335 class VIEW3D_MT_select_pose(bpy.types.Menu):
336     bl_label = "Select"
337
338     def draw(self, context):
339         layout = self.layout
340
341         layout.operator("view3d.select_border")
342
343         layout.separator()
344
345         layout.operator("pose.select_all_toggle", text="Select/Deselect All")
346         layout.operator("pose.select_inverse", text="Inverse")
347         layout.operator("pose.select_constraint_target", text="Constraint Target")
348         layout.operator("pose.select_linked", text="Linked")
349
350         layout.separator()
351
352         layout.operator("pose.select_hierarchy", text="Parent").direction = 'PARENT'
353         layout.operator("pose.select_hierarchy", text="Child").direction = 'CHILD'
354
355         layout.separator()
356
357         props = layout.operator("pose.select_hierarchy", text="Extend Parent")
358         props.extend = True
359         props.direction = 'PARENT'
360
361         props = layout.operator("pose.select_hierarchy", text="Extend Child")
362         props.extend = True
363         props.direction = 'CHILD'
364
365
366 class VIEW3D_MT_select_particle(bpy.types.Menu):
367     bl_label = "Select"
368
369     def draw(self, context):
370         layout = self.layout
371
372         layout.operator("view3d.select_border")
373
374         layout.separator()
375
376         layout.operator("particle.select_all_toggle", text="Select/Deselect All")
377         layout.operator("particle.select_linked")
378         layout.operator("particle.select_inverse")
379
380         layout.separator()
381
382         layout.operator("particle.select_more")
383         layout.operator("particle.select_less")
384
385         layout.separator()
386
387         layout.operator("particle.select_first", text="Roots")
388         layout.operator("particle.select_last", text="Tips")
389
390
391 class VIEW3D_MT_select_edit_mesh(bpy.types.Menu):
392     bl_label = "Select"
393
394     def draw(self, context):
395         layout = self.layout
396
397         layout.operator("view3d.select_border")
398         layout.operator("view3d.select_circle")
399
400         layout.separator()
401
402         layout.operator("mesh.select_all_toggle", text="Select/Deselect All")
403         layout.operator("mesh.select_inverse", text="Inverse")
404
405         layout.separator()
406
407         layout.operator("mesh.select_random", text="Random...")
408         layout.operator("mesh.edges_select_sharp", text="Sharp Edges")
409         layout.operator("mesh.faces_select_linked_flat", text="Linked Flat Faces")
410         layout.operator("mesh.faces_select_interior", text="Interior Faces")
411         layout.operator("mesh.select_axis", text="Side of Active")
412
413         layout.separator()
414
415         layout.operator("mesh.select_by_number_vertices", text="Triangles").type = 'TRIANGLES'
416         layout.operator("mesh.select_by_number_vertices", text="Quads").type = 'QUADS'
417         layout.operator("mesh.select_by_number_vertices", text="Loose Verts/Edges").type = 'OTHER'
418         layout.operator("mesh.select_similar", text="Similar...")
419
420         layout.separator()
421
422         layout.operator("mesh.select_less", text="Less")
423         layout.operator("mesh.select_more", text="More")
424
425         layout.separator()
426
427         layout.operator("mesh.select_mirror", text="Mirror")
428
429         layout.operator("mesh.select_linked", text="Linked")
430         layout.operator("mesh.select_vertex_path", text="Vertex Path")
431         layout.operator("mesh.loop_multi_select", text="Edge Loop")
432         layout.operator("mesh.loop_multi_select", text="Edge Ring").ring = True
433
434         layout.separator()
435
436         layout.operator("mesh.loop_to_region")
437         layout.operator("mesh.region_to_loop")
438
439
440 class VIEW3D_MT_select_edit_curve(bpy.types.Menu):
441     bl_label = "Select"
442
443     def draw(self, context):
444         layout = self.layout
445
446         layout.operator("view3d.select_border")
447         layout.operator("view3d.select_circle")
448
449         layout.separator()
450
451         layout.operator("curve.select_all_toggle", text="Select/Deselect All")
452         layout.operator("curve.select_inverse")
453         layout.operator("curve.select_random")
454         layout.operator("curve.select_every_nth")
455
456         layout.separator()
457
458         layout.operator("curve.de_select_first")
459         layout.operator("curve.de_select_last")
460         layout.operator("curve.select_next")
461         layout.operator("curve.select_previous")
462
463         layout.separator()
464
465         layout.operator("curve.select_more")
466         layout.operator("curve.select_less")
467
468
469 class VIEW3D_MT_select_edit_surface(bpy.types.Menu):
470     bl_label = "Select"
471
472     def draw(self, context):
473         layout = self.layout
474
475         layout.operator("view3d.select_border")
476         layout.operator("view3d.select_circle")
477
478         layout.separator()
479
480         layout.operator("curve.select_all_toggle", text="Select/Deselect All")
481         layout.operator("curve.select_inverse")
482         layout.operator("curve.select_random")
483         layout.operator("curve.select_every_nth")
484
485         layout.separator()
486
487         layout.operator("curve.select_row")
488
489         layout.separator()
490
491         layout.operator("curve.select_more")
492         layout.operator("curve.select_less")
493
494
495 class VIEW3D_MT_select_edit_metaball(bpy.types.Menu):
496     bl_label = "Select"
497
498     def draw(self, context):
499         layout = self.layout
500
501         layout.operator("view3d.select_border")
502
503         layout.separator()
504
505         layout.operator("mball.select_deselect_all_metaelems")
506         layout.operator("mball.select_inverse_metaelems")
507
508         layout.separator()
509
510         layout.operator("mball.select_random_metaelems")
511
512
513 class VIEW3D_MT_select_edit_lattice(bpy.types.Menu):
514     bl_label = "Select"
515
516     def draw(self, context):
517         layout = self.layout
518
519         layout.operator("view3d.select_border")
520
521         layout.separator()
522
523         layout.operator("lattice.select_all_toggle", text="Select/Deselect All")
524
525
526 class VIEW3D_MT_select_edit_armature(bpy.types.Menu):
527     bl_label = "Select"
528
529     def draw(self, context):
530         layout = self.layout
531
532         layout.operator("view3d.select_border")
533
534
535         layout.separator()
536
537         layout.operator("armature.select_all_toggle", text="Select/Deselect All")
538         layout.operator("armature.select_inverse", text="Inverse")
539
540         layout.separator()
541
542         layout.operator("armature.select_hierarchy", text="Parent").direction = 'PARENT'
543         layout.operator("armature.select_hierarchy", text="Child").direction = 'CHILD'
544
545         layout.separator()
546
547         props = layout.operator("armature.select_hierarchy", text="Extend Parent")
548         props.extend = True
549         props.direction = 'PARENT'
550
551         props = layout.operator("armature.select_hierarchy", text="Extend Child")
552         props.extend = True
553         props.direction = 'CHILD'
554
555
556 class VIEW3D_MT_select_face(bpy.types.Menu):# XXX no matching enum
557     bl_label = "Select"
558
559     def draw(self, context):
560         layout = self.layout
561         
562         # TODO
563         # see view3d_select_faceselmenu
564
565 # ********** Object menu **********
566
567
568 class VIEW3D_MT_object(bpy.types.Menu):
569     bl_context = "objectmode"
570     bl_label = "Object"
571
572     def draw(self, context):
573         layout = self.layout
574
575         layout.menu("VIEW3D_MT_transform")
576         layout.menu("VIEW3D_MT_mirror")
577         layout.menu("VIEW3D_MT_object_clear")
578         layout.menu("VIEW3D_MT_object_apply")
579         layout.menu("VIEW3D_MT_snap")
580
581         layout.separator()
582
583         layout.operator("anim.keyframe_insert_menu", text="Insert Keyframe...")
584         layout.operator("anim.keyframe_delete_v3d", text="Delete Keyframe...")
585
586         layout.separator()
587
588         layout.operator("object.duplicate_move")
589         layout.operator("object.duplicate", text="Duplicate Linked").linked = True
590         layout.operator("object.delete", text="Delete...")
591         layout.operator("object.proxy_make", text="Make Proxy...")
592         layout.menu("VIEW3D_MT_make_links", text="Make Links...")
593         layout.operator_menu_enum("object.make_local", "type", text="Make Local...")
594         layout.menu("VIEW3D_MT_make_single_user")
595         layout.menu("VIEW3D_MT_make_links")
596
597         layout.separator()
598
599         layout.menu("VIEW3D_MT_object_parent")
600         layout.menu("VIEW3D_MT_object_track")
601         layout.menu("VIEW3D_MT_object_group")
602         layout.menu("VIEW3D_MT_object_constraints")
603
604         layout.separator()
605
606         layout.operator("object.join_shapes")
607         layout.operator("object.join")
608
609         layout.separator()
610
611         layout.operator("object.move_to_layer", text="Move to Layer...")
612         layout.menu("VIEW3D_MT_object_showhide")
613
614         layout.operator_menu_enum("object.convert", "target")
615
616
617 class VIEW3D_MT_object_clear(bpy.types.Menu):
618     bl_label = "Clear"
619
620     def draw(self, context):
621         layout = self.layout
622
623         layout.operator("object.location_clear", text="Location")
624         layout.operator("object.rotation_clear", text="Rotation")
625         layout.operator("object.scale_clear", text="Scale")
626         layout.operator("object.origin_clear", text="Origin")
627
628
629 class VIEW3D_MT_object_apply(bpy.types.Menu):
630     bl_label = "Apply"
631
632     def draw(self, context):
633         layout = self.layout
634
635         layout.operator("object.location_apply", text="Location")
636         layout.operator("object.rotation_apply", text="Rotation")
637         layout.operator("object.scale_apply", text="Scale")
638         layout.separator()
639         layout.operator("object.visual_transform_apply", text="Visual Transform")
640         layout.operator("object.duplicates_make_real")
641
642
643 class VIEW3D_MT_object_parent(bpy.types.Menu):
644     bl_label = "Parent"
645
646     def draw(self, context):
647         layout = self.layout
648
649         layout.operator("object.parent_set", text="Set")
650         layout.operator("object.parent_clear", text="Clear")
651
652
653 class VIEW3D_MT_object_track(bpy.types.Menu):
654     bl_label = "Track"
655
656     def draw(self, context):
657         layout = self.layout
658
659         layout.operator("object.track_set", text="Set")
660         layout.operator("object.track_clear", text="Clear")
661
662
663 class VIEW3D_MT_object_group(bpy.types.Menu):
664     bl_label = "Group"
665
666     def draw(self, context):
667         layout = self.layout
668
669         layout.operator("group.create")
670         layout.operator("group.objects_remove")
671
672         layout.separator()
673
674         layout.operator("group.objects_add_active")
675         layout.operator("group.objects_remove_active")
676
677
678 class VIEW3D_MT_object_constraints(bpy.types.Menu):
679     bl_label = "Constraints"
680
681     def draw(self, context):
682         layout = self.layout
683
684         layout.operator("object.constraint_add_with_targets")
685         layout.operator("object.constraints_clear")
686
687
688 class VIEW3D_MT_object_showhide(bpy.types.Menu):
689     bl_label = "Show/Hide"
690
691     def draw(self, context):
692         layout = self.layout
693
694         layout.operator("object.restrictview_clear", text="Show Hidden")
695         layout.operator("object.restrictview_set", text="Hide Selected")
696         layout.operator("object.restrictview_set", text="Hide Unselected").unselected = True
697
698
699 class VIEW3D_MT_make_single_user(bpy.types.Menu):
700     bl_label = "Make Single User"
701
702     def draw(self, context):
703         layout = self.layout
704
705         props = layout.operator("object.make_single_user", text="Object")
706         props.object = True
707
708         props = layout.operator("object.make_single_user", text="Object & ObData")
709         props.object = props.obdata = True
710
711         props = layout.operator("object.make_single_user", text="Object & ObData & Materials+Tex")
712         props.object = props.obdata = props.material = props.texture = True
713
714         props = layout.operator("object.make_single_user", text="Materials+Tex")
715         props.material = props.texture = True
716
717         props = layout.operator("object.make_single_user", text="Animation")
718         props.animation = True
719
720
721 class VIEW3D_MT_make_links(bpy.types.Menu):
722     bl_label = "Make Links"
723
724     def draw(self, context):
725         layout = self.layout
726
727         layout.operator_menu_enum("object.make_links_scene", "type", text="Objects to Scene...")
728
729         layout.operator_enums("object.make_links_data", property="type") # inline
730
731
732 # ********** Vertex paint menu **********
733
734
735 class VIEW3D_MT_paint_vertex(bpy.types.Menu):
736     bl_label = "Paint"
737
738     def draw(self, context):
739         layout = self.layout
740
741         layout.operator("paint.vertex_color_set")
742         layout.operator("paint.vertex_color_set", text="Set Selected Vertex Colors").selected = True
743
744
745 class VIEW3D_MT_hook(bpy.types.Menu):
746     bl_label = "Hooks"
747
748     def draw(self, context):
749         layout = self.layout
750         layout.operator_context = 'EXEC_AREA'
751         layout.operator("object.hook_add_newob")
752         layout.operator("object.hook_add_selob")
753         
754         if [mod.type == 'HOOK' for mod in context.active_object.modifiers]:
755             layout.separator()
756             layout.operator_menu_enum("object.hook_assign", "modifier")
757             layout.operator_menu_enum("object.hook_remove", "modifier")
758             layout.separator()
759             layout.operator_menu_enum("object.hook_select", "modifier")
760             layout.operator_menu_enum("object.hook_reset", "modifier")
761             layout.operator_menu_enum("object.hook_recenter", "modifier")
762
763
764 class VIEW3D_MT_vertex_group(bpy.types.Menu):
765     bl_label = "Vertex Groups"
766
767     def draw(self, context):
768         layout = self.layout
769         layout.operator_context = 'EXEC_AREA'
770         layout.operator("object.vertex_group_assign", text="Assign to New Group").new = True
771         
772         ob = context.active_object
773         if ob.mode == 'EDIT':
774             if ob.vertex_groups and ob.active_vertex_group:
775                 layout.separator()
776                 layout.operator("object.vertex_group_assign", text="Assign to Active Group")
777                 layout.operator("object.vertex_group_remove_from", text="Remove from Active Group")
778                 layout.operator("object.vertex_group_remove_from", text="Remove from All").all = True
779                 layout.separator()
780         
781         if ob.vertex_groups and ob.active_vertex_group:
782             layout.operator_menu_enum("object.vertex_group_set_active", "group", text="Set Active Group")
783             layout.operator("object.vertex_group_remove", text="Remove Active Group")
784             layout.operator("object.vertex_group_remove", text="Remove All Groups").all = True
785
786
787 # ********** Sculpt menu **********
788
789
790 class VIEW3D_MT_sculpt(bpy.types.Menu):
791     bl_label = "Sculpt"
792
793     def draw(self, context):
794         layout = self.layout
795
796         sculpt = context.tool_settings.sculpt
797         brush = context.tool_settings.sculpt.brush
798
799         layout.prop(sculpt, "symmetry_x")
800         layout.prop(sculpt, "symmetry_y")
801         layout.prop(sculpt, "symmetry_z")
802         layout.separator()
803         layout.prop(sculpt, "lock_x")
804         layout.prop(sculpt, "lock_y")
805         layout.prop(sculpt, "lock_z")
806         layout.separator()
807         layout.operator_menu_enum("brush.curve_preset", property="shape")
808         layout.separator()
809
810         sculpt_tool = brush.sculpt_tool
811
812         if sculpt_tool != 'GRAB':
813             layout.prop(brush, "use_airbrush")
814
815             if sculpt_tool != 'LAYER':
816                 layout.prop(brush, "use_anchor")
817
818             if sculpt_tool in ('DRAW', 'PINCH', 'INFLATE', 'LAYER', 'CLAY'):
819                 layout.prop(brush, "flip_direction")
820
821             if sculpt_tool == 'LAYER':
822                 layout.prop(brush, "use_persistent")
823                 layout.operator("sculpt.set_persistent_base")
824
825 # ********** Particle menu **********
826
827
828 class VIEW3D_MT_particle(bpy.types.Menu):
829     bl_label = "Particle"
830
831     def draw(self, context):
832         layout = self.layout
833
834         particle_edit = context.tool_settings.particle_edit
835
836         layout.operator("particle.mirror")
837
838         layout.separator()
839
840         layout.operator("particle.remove_doubles")
841         layout.operator("particle.delete")
842
843         if particle_edit.selection_mode == 'POINT':
844             layout.operator("particle.subdivide")
845
846         layout.operator("particle.rekey")
847
848         layout.separator()
849
850         layout.menu("VIEW3D_MT_particle_showhide")
851
852
853 class VIEW3D_MT_particle_showhide(VIEW3D_MT_showhide):
854     _operator_name = "particle"
855
856 # ********** Pose Menu **********
857
858
859 class VIEW3D_MT_pose(bpy.types.Menu):
860     bl_label = "Pose"
861
862     def draw(self, context):
863         layout = self.layout
864
865         arm = context.active_object.data
866         
867         layout.menu("VIEW3D_MT_transform")
868         layout.menu("VIEW3D_MT_snap")
869         if arm.drawtype in ('BBONE', 'ENVELOPE'):
870             layout.operator("tfm.transform", text="Scale Envelope Distance").mode = 'BONESIZE'
871
872         layout.menu("VIEW3D_MT_pose_transform")
873
874         layout.separator()
875
876         layout.operator("anim.keyframe_insert_menu", text="Insert Keyframe...")
877         layout.operator("anim.keyframe_delete_v3d", text="Delete Keyframe...")
878
879         layout.separator()
880
881         layout.operator("pose.apply")
882         layout.operator("pose.relax")
883
884         layout.separator()
885
886         layout.operator("pose.copy")
887         layout.operator("pose.paste")
888         layout.operator("pose.paste", text="Paste X-Flipped Pose").flipped = True
889
890         layout.separator()
891
892         layout.menu("VIEW3D_MT_pose_pose")
893         layout.menu("VIEW3D_MT_pose_motion")
894         layout.menu("VIEW3D_MT_pose_group")
895
896         layout.separator()
897
898         layout.menu("VIEW3D_MT_pose_ik")
899         layout.menu("VIEW3D_MT_pose_constraints")
900
901         layout.separator()
902
903         layout.operator_context = 'EXEC_AREA'
904         layout.operator("pose.autoside_names", text="AutoName Left/Right").axis = 'XAXIS'
905         layout.operator("pose.autoside_names", text="AutoName Front/Back").axis = 'YAXIS'
906         layout.operator("pose.autoside_names", text="AutoName Top/Bottom").axis = 'ZAXIS'
907
908         layout.operator("pose.flip_names")
909
910         layout.separator()
911
912         layout.operator_context = 'INVOKE_AREA'
913         layout.operator("pose.armature_layers", text="Change Armature Layers...")
914         layout.operator("pose.bone_layers", text="Change Bone Layers...")
915
916         layout.separator()
917
918         layout.menu("VIEW3D_MT_pose_showhide")
919         layout.operator_menu_enum("pose.flags_set", 'mode', text="Bone Settings")
920
921
922 class VIEW3D_MT_pose_transform(bpy.types.Menu):
923     bl_label = "Clear Transform"
924
925     def draw(self, context):
926         layout = self.layout
927
928         layout.label(text="User Transform")
929
930         layout.operator("pose.loc_clear", text="Location")
931         layout.operator("pose.rot_clear", text="Rotation")
932         layout.operator("pose.scale_clear", text="Scale")
933
934         layout.label(text="Origin")
935
936
937 class VIEW3D_MT_pose_pose(bpy.types.Menu):
938     bl_label = "Pose Library"
939
940     def draw(self, context):
941         layout = self.layout
942
943         layout.operator("poselib.browse_interactive", text="Browse Poses...")
944
945         layout.separator()
946
947         layout.operator("poselib.pose_add", text="Add Pose...")
948         layout.operator("poselib.pose_rename", text="Rename Pose...")
949         layout.operator("poselib.pose_remove", text="Remove Pose...")
950
951
952 class VIEW3D_MT_pose_motion(bpy.types.Menu):
953     bl_label = "Motion Paths"
954
955     def draw(self, context):
956         layout = self.layout
957
958         layout.operator("pose.paths_calculate", text="Calculate")
959         layout.operator("pose.paths_clear", text="Clear")
960
961
962 class VIEW3D_MT_pose_group(bpy.types.Menu):
963     bl_label = "Bone Groups"
964
965     def draw(self, context):
966         layout = self.layout
967         layout.operator("pose.group_add")
968         layout.operator("pose.group_remove")
969
970         layout.separator()
971
972         layout.operator("pose.group_assign")
973         layout.operator("pose.group_unassign")
974
975
976 class VIEW3D_MT_pose_ik(bpy.types.Menu):
977     bl_label = "Inverse Kinematics"
978
979     def draw(self, context):
980         layout = self.layout
981
982         layout.operator("pose.ik_add")
983         layout.operator("pose.ik_clear")
984
985
986 class VIEW3D_MT_pose_constraints(bpy.types.Menu):
987     bl_label = "Constraints"
988
989     def draw(self, context):
990         layout = self.layout
991
992         layout.operator("pose.constraint_add_with_targets", text="Add (With Targets)...")
993         layout.operator("pose.constraints_clear")
994
995
996 class VIEW3D_MT_pose_showhide(VIEW3D_MT_showhide):
997     _operator_name = "pose"
998
999 # ********** Edit Menus, suffix from ob.type **********
1000
1001
1002 class VIEW3D_MT_edit_mesh(bpy.types.Menu):
1003     bl_label = "Mesh"
1004
1005     def draw(self, context):
1006         layout = self.layout
1007
1008         settings = context.tool_settings
1009
1010         layout.operator("ed.undo")
1011         layout.operator("ed.redo")
1012
1013         layout.separator()
1014
1015         layout.menu("VIEW3D_MT_transform")
1016         layout.menu("VIEW3D_MT_mirror")
1017         layout.menu("VIEW3D_MT_snap")
1018
1019         layout.separator()
1020
1021         layout.menu("VIEW3D_MT_uv_map", text="UV Unwrap...")
1022
1023         layout.separator()
1024
1025         layout.operator("mesh.extrude_move")
1026         layout.operator("mesh.duplicate_move")
1027         layout.operator("mesh.delete", text="Delete...")
1028
1029         layout.separator()
1030
1031         layout.menu("VIEW3D_MT_edit_mesh_vertices")
1032         layout.menu("VIEW3D_MT_edit_mesh_edges")
1033         layout.menu("VIEW3D_MT_edit_mesh_faces")
1034         layout.menu("VIEW3D_MT_edit_mesh_normals")
1035
1036         layout.separator()
1037
1038         layout.prop(settings, "automerge_editing")
1039         layout.prop_menu_enum(settings, "proportional_editing")
1040         layout.prop_menu_enum(settings, "proportional_editing_falloff")
1041
1042         layout.separator()
1043
1044         layout.menu("VIEW3D_MT_edit_mesh_showhide")
1045
1046
1047 class VIEW3D_MT_edit_mesh_specials(bpy.types.Menu):
1048     bl_label = "Specials"
1049
1050     def draw(self, context):
1051         layout = self.layout
1052
1053         layout.operator_context = 'INVOKE_REGION_WIN'
1054
1055         layout.operator("mesh.subdivide", text="Subdivide")
1056         layout.operator("mesh.subdivide", text="Subdivide Smooth").smoothness = 1.0
1057         layout.operator("mesh.merge", text="Merge...")
1058         layout.operator("mesh.remove_doubles")
1059         layout.operator("mesh.hide", text="Hide")
1060         layout.operator("mesh.reveal", text="Reveal")
1061         layout.operator("mesh.select_inverse")
1062         layout.operator("mesh.flip_normals")
1063         layout.operator("mesh.vertices_smooth", text="Smooth")
1064         # layout.operator("mesh.bevel", text="Bevel")
1065         layout.operator("mesh.faces_shade_smooth")
1066         layout.operator("mesh.faces_shade_flat")
1067         layout.operator("mesh.blend_from_shape")
1068         layout.operator("mesh.shape_propagate_to_all")
1069         layout.operator("mesh.select_vertex_path")
1070
1071
1072 class VIEW3D_MT_edit_mesh_vertices(bpy.types.Menu):
1073     bl_label = "Vertices"
1074
1075     def draw(self, context):
1076         layout = self.layout
1077         layout.operator_context = 'INVOKE_REGION_WIN'
1078
1079         layout.operator("mesh.merge")
1080         layout.operator("mesh.rip")
1081         layout.operator("mesh.split")
1082         layout.operator("mesh.separate")
1083
1084         layout.separator()
1085
1086         layout.operator("mesh.vertices_smooth")
1087         layout.operator("mesh.remove_doubles")
1088
1089         layout.operator("mesh.select_vertex_path")
1090
1091         layout.operator("mesh.blend_from_shape")
1092
1093         layout.operator("object.vertex_group_blend")
1094         layout.operator("mesh.shape_propagate_to_all")
1095
1096         layout.separator()
1097
1098         layout.menu("VIEW3D_MT_vertex_group")
1099         layout.menu("VIEW3D_MT_hook")
1100
1101
1102 class VIEW3D_MT_edit_mesh_edges(bpy.types.Menu):
1103     bl_label = "Edges"
1104
1105     def draw(self, context):
1106         layout = self.layout
1107         layout.operator_context = 'INVOKE_REGION_WIN'
1108
1109         layout.operator("mesh.edge_face_add")
1110         layout.operator("mesh.subdivide")
1111
1112         layout.separator()
1113
1114         layout.operator("mesh.mark_seam")
1115         layout.operator("mesh.mark_seam", text="Clear Seam").clear = True
1116
1117         layout.separator()
1118
1119         layout.operator("mesh.mark_sharp")
1120         layout.operator("mesh.mark_sharp", text="Clear Sharp").clear = True
1121
1122         layout.separator()
1123
1124         layout.operator("mesh.edge_rotate", text="Rotate Edge CW").direction = 'CW'
1125         layout.operator("mesh.edge_rotate", text="Rotate Edge CCW").direction = 'CCW'
1126
1127         layout.separator()
1128
1129         layout.operator("TFM_OT_edge_slide", text="Edge Slide")
1130         layout.operator("mesh.loop_multi_select", text="Edge Loop")
1131
1132         # uiItemO(layout, "Loopcut", 0, "mesh.loop_cut"); // CutEdgeloop(em, 1);
1133         # uiItemO(layout, "Edge Slide", 0, "mesh.edge_slide"); // EdgeSlide(em, 0,0.0);
1134
1135         layout.operator("mesh.loop_multi_select", text="Edge Ring").ring = True
1136
1137         layout.operator("mesh.loop_to_region")
1138         layout.operator("mesh.region_to_loop")
1139
1140
1141 class VIEW3D_MT_edit_mesh_faces(dynamic_menu.DynMenu):
1142     bl_label = "Faces"
1143     bl_idname = "VIEW3D_MT_edit_mesh_faces"
1144
1145     def draw(self, context):
1146         layout = self.layout
1147         layout.operator_context = 'INVOKE_REGION_WIN'
1148
1149         # layout.operator("mesh.bevel")
1150         # layout.operator("mesh.bevel")
1151         layout.operator("mesh.edge_face_add")
1152         layout.operator("mesh.fill")
1153         layout.operator("mesh.beauty_fill")
1154
1155         layout.separator()
1156
1157         layout.operator("mesh.quads_convert_to_tris")
1158         layout.operator("mesh.tris_convert_to_quads")
1159         layout.operator("mesh.edge_flip")
1160
1161         layout.separator()
1162
1163         layout.operator("mesh.faces_shade_smooth")
1164         layout.operator("mesh.faces_shade_flat")
1165
1166         layout.separator()
1167
1168         # uiItemO(layout, NULL, 0, "mesh.face_mode"); // mesh_set_face_flags(em, 1);
1169         # uiItemBooleanO(layout, NULL, 0, "mesh.face_mode", "clear", 1); // mesh_set_face_flags(em, 0);
1170
1171         layout.operator("mesh.edge_rotate", text="Rotate Edge CW").direction = 'CW'
1172
1173         layout.separator()
1174
1175         layout.operator_menu_enum("mesh.uvs_rotate", "direction")
1176         layout.operator_menu_enum("mesh.uvs_mirror", "axis")
1177         layout.operator_menu_enum("mesh.colors_rotate", "direction")
1178         layout.operator_menu_enum("mesh.colors_mirror", "axis")
1179
1180
1181 class VIEW3D_MT_edit_mesh_normals(bpy.types.Menu):
1182     bl_label = "Normals"
1183
1184     def draw(self, context):
1185         layout = self.layout
1186
1187         layout.operator("mesh.normals_make_consistent", text="Recalculate Outside")
1188         layout.operator("mesh.normals_make_consistent", text="Recalculate Inside").inside = True
1189
1190         layout.separator()
1191
1192         layout.operator("mesh.flip_normals")
1193
1194
1195 class VIEW3D_MT_edit_mesh_showhide(VIEW3D_MT_showhide):
1196     _operator_name = "mesh"
1197
1198 # Edit Curve
1199 # draw_curve is used by VIEW3D_MT_edit_curve and VIEW3D_MT_edit_surface
1200
1201
1202 def draw_curve(self, context):
1203     layout = self.layout
1204
1205     settings = context.tool_settings
1206     
1207     layout.menu("VIEW3D_MT_transform")
1208     layout.menu("VIEW3D_MT_mirror")
1209     layout.menu("VIEW3D_MT_snap")
1210
1211     layout.separator()
1212
1213     layout.operator("curve.extrude")
1214     layout.operator("curve.duplicate")
1215     layout.operator("curve.separate")
1216     layout.operator("curve.make_segment")
1217     layout.operator("curve.cyclic_toggle")
1218     layout.operator("curve.delete", text="Delete...")
1219
1220     layout.separator()
1221
1222     layout.menu("VIEW3D_MT_edit_curve_ctrlpoints")
1223     layout.menu("VIEW3D_MT_edit_curve_segments")
1224
1225     layout.separator()
1226
1227     layout.prop_menu_enum(settings, "proportional_editing")
1228     layout.prop_menu_enum(settings, "proportional_editing_falloff")
1229
1230     layout.separator()
1231
1232     layout.menu("VIEW3D_MT_edit_curve_showhide")
1233
1234
1235 class VIEW3D_MT_edit_curve(bpy.types.Menu):
1236     bl_label = "Curve"
1237
1238     draw = draw_curve
1239
1240
1241 class VIEW3D_MT_edit_curve_ctrlpoints(bpy.types.Menu):
1242     bl_label = "Control Points"
1243
1244     def draw(self, context):
1245         layout = self.layout
1246
1247         edit_object = context.edit_object
1248
1249         if edit_object.type == 'CURVE':
1250             layout.operator("tfm.transform").mode = 'TILT'
1251             layout.operator("curve.tilt_clear")
1252             layout.operator("curve.separate")
1253
1254             layout.separator()
1255
1256             layout.operator_menu_enum("curve.handle_type_set", "type")
1257
1258             layout.separator()
1259
1260             layout.menu("VIEW3D_MT_hook")
1261
1262
1263 class VIEW3D_MT_edit_curve_segments(bpy.types.Menu):
1264     bl_label = "Segments"
1265
1266     def draw(self, context):
1267         layout = self.layout
1268
1269         layout.operator("curve.subdivide")
1270         layout.operator("curve.switch_direction")
1271
1272
1273 class VIEW3D_MT_edit_curve_showhide(VIEW3D_MT_showhide):
1274     _operator_name = "curve"
1275
1276
1277 class VIEW3D_MT_edit_surface(bpy.types.Menu):
1278     bl_label = "Surface"
1279
1280     draw = draw_curve
1281
1282
1283 class VIEW3D_MT_edit_text(bpy.types.Menu):
1284     bl_label = "Text"
1285
1286     def draw(self, context):
1287         layout = self.layout
1288
1289         layout.operator("font.file_paste")
1290
1291         layout.separator()
1292
1293         layout.menu("VIEW3D_MT_edit_text_chars")
1294
1295
1296 class VIEW3D_MT_edit_text_chars(bpy.types.Menu):
1297     bl_label = "Special Characters"
1298
1299     def draw(self, context):
1300         layout = self.layout
1301
1302         layout.operator("font.text_insert", text="Copyright|Alt C").text = b'\xC2\xA9'.decode()
1303         layout.operator("font.text_insert", text="Registered Trademark|Alt R").text = b'\xC2\xAE'.decode()
1304
1305         layout.separator()
1306
1307         layout.operator("font.text_insert", text="Degree Sign|Alt G").text = b'\xC2\xB0'.decode()
1308         layout.operator("font.text_insert", text="Multiplication Sign|Alt x").text = b'\xC3\x97'.decode()
1309         layout.operator("font.text_insert", text="Circle|Alt .").text = b'\xC2\x8A'.decode()
1310         layout.operator("font.text_insert", text="Superscript 1|Alt 1").text = b'\xC2\xB9'.decode()
1311         layout.operator("font.text_insert", text="Superscript 2|Alt 2").text = b'\xC2\xB2'.decode()
1312         layout.operator("font.text_insert", text="Superscript 3|Alt 3").text = b'\xC2\xB3'.decode()
1313         layout.operator("font.text_insert", text="Double >>|Alt >").text = b'\xC2\xBB'.decode()
1314         layout.operator("font.text_insert", text="Double <<|Alt <").text = b'\xC2\xAB'.decode()
1315         layout.operator("font.text_insert", text="Promillage|Alt %").text = b'\xE2\x80\xB0'.decode()
1316
1317         layout.separator()
1318
1319         layout.operator("font.text_insert", text="Dutch Florin|Alt F").text = b'\xC2\xA4'.decode()
1320         layout.operator("font.text_insert", text="British Pound|Alt L").text = b'\xC2\xA3'.decode()
1321         layout.operator("font.text_insert", text="Japanese Yen|Alt Y").text = b'\xC2\xA5'.decode()
1322
1323         layout.separator()
1324
1325         layout.operator("font.text_insert", text="German S|Alt S").text = b'\xC3\x9F'.decode()
1326         layout.operator("font.text_insert", text="Spanish Question Mark|Alt ?").text = b'\xC2\xBF'.decode()
1327         layout.operator("font.text_insert", text="Spanish Exclamation Mark|Alt !").text = b'\xC2\xA1'.decode()
1328
1329
1330 class VIEW3D_MT_edit_meta(bpy.types.Menu):
1331     bl_label = "Metaball"
1332
1333     def draw(self, context):
1334         layout = self.layout
1335
1336         settings = context.tool_settings
1337
1338         layout.operator("ed.undo")
1339         layout.operator("ed.redo")
1340
1341         layout.separator()
1342         
1343         layout.menu("VIEW3D_MT_transform")
1344         layout.menu("VIEW3D_MT_mirror")
1345         layout.menu("VIEW3D_MT_snap")
1346
1347         layout.separator()
1348
1349         layout.operator("mball.delete_metaelems", text="Delete...")
1350         layout.operator("mball.duplicate_metaelems")
1351
1352         layout.separator()
1353
1354         layout.prop_menu_enum(settings, "proportional_editing")
1355         layout.prop_menu_enum(settings, "proportional_editing_falloff")
1356
1357         layout.separator()
1358
1359         layout.menu("VIEW3D_MT_edit_meta_showhide")
1360
1361
1362 class VIEW3D_MT_edit_meta_showhide(bpy.types.Menu):
1363     bl_label = "Show/Hide"
1364
1365     def draw(self, context):
1366         layout = self.layout
1367
1368         layout.operator("mball.reveal_metaelems", text="Show Hidden")
1369         layout.operator("mball.hide_metaelems", text="Hide Selected")
1370         layout.operator("mball.hide_metaelems", text="Hide Unselected").unselected = True
1371
1372
1373 class VIEW3D_MT_edit_lattice(bpy.types.Menu):
1374     bl_label = "Lattice"
1375
1376     def draw(self, context):
1377         layout = self.layout
1378
1379         settings = context.tool_settings
1380         
1381         layout.menu("VIEW3D_MT_transform")
1382         layout.menu("VIEW3D_MT_mirror")
1383         layout.menu("VIEW3D_MT_snap")
1384
1385         layout.separator()
1386
1387         layout.operator("lattice.make_regular")
1388
1389         layout.separator()
1390
1391         layout.prop_menu_enum(settings, "proportional_editing")
1392         layout.prop_menu_enum(settings, "proportional_editing_falloff")
1393
1394
1395 class VIEW3D_MT_edit_armature(bpy.types.Menu):
1396     bl_label = "Armature"
1397
1398     def draw(self, context):
1399         layout = self.layout
1400
1401         edit_object = context.edit_object
1402         arm = edit_object.data
1403         
1404         layout.menu("VIEW3D_MT_transform")
1405         layout.menu("VIEW3D_MT_mirror")
1406         layout.menu("VIEW3D_MT_snap")
1407         layout.menu("VIEW3D_MT_edit_armature_roll")
1408
1409         if arm.drawtype == 'ENVELOPE':
1410             layout.operator("tfm.transform", text="Scale Envelope Distance").mode = 'BONESIZE'
1411         else:
1412             layout.operator("tfm.transform", text="Scale B-Bone Width").mode = 'BONESIZE'
1413
1414         layout.separator()
1415
1416         layout.operator("armature.extrude_move")
1417
1418         if arm.x_axis_mirror:
1419             layout.operator("armature.extrude_forked")
1420
1421         layout.operator("armature.duplicate_move")
1422         layout.operator("armature.merge")
1423         layout.operator("armature.fill")
1424         layout.operator("armature.delete")
1425         layout.operator("armature.separate")
1426
1427         layout.separator()
1428
1429         layout.operator("armature.subdivide_multi", text="Subdivide")
1430         layout.operator("armature.switch_direction", text="Switch Direction")
1431
1432         layout.separator()
1433
1434         layout.operator_context = 'EXEC_AREA'
1435         layout.operator("armature.autoside_names", text="AutoName Left/Right").type = 'XAXIS'
1436         layout.operator("armature.autoside_names", text="AutoName Front/Back").type = 'YAXIS'
1437         layout.operator("armature.autoside_names", text="AutoName Top/Bottom").type = 'ZAXIS'
1438         layout.operator("armature.flip_names")
1439
1440         layout.separator()
1441
1442         layout.operator_context = 'INVOKE_DEFAULT'
1443         layout.operator("armature.armature_layers")
1444         layout.operator("armature.bone_layers")
1445
1446         layout.separator()
1447
1448         layout.menu("VIEW3D_MT_edit_armature_parent")
1449
1450         layout.separator()
1451
1452         layout.operator_menu_enum("armature.flags_set", "mode", text="Bone Settings")
1453
1454
1455 class VIEW3D_MT_armature_specials(bpy.types.Menu):
1456     bl_label = "Specials"
1457
1458     def draw(self, context):
1459         layout = self.layout
1460
1461         layout.operator_context = 'INVOKE_REGION_WIN'
1462
1463         layout.operator("armature.subdivide_multi", text="Subdivide")
1464         layout.operator("armature.switch_direction", text="Switch Direction")
1465
1466         layout.separator()
1467
1468         layout.operator_context = 'EXEC_REGION_WIN'
1469         layout.operator("armature.autoside_names", text="AutoName Left/Right").type = 'XAXIS'
1470         layout.operator("armature.autoside_names", text="AutoName Front/Back").type = 'YAXIS'
1471         layout.operator("armature.autoside_names", text="AutoName Top/Bottom").type = 'ZAXIS'
1472         layout.operator("armature.flip_names", text="Flip Names")
1473
1474
1475 class VIEW3D_MT_edit_armature_parent(bpy.types.Menu):
1476     bl_label = "Parent"
1477
1478     def draw(self, context):
1479         layout = self.layout
1480
1481         layout.operator("armature.parent_set", text="Make")
1482         layout.operator("armature.parent_clear", text="Clear")
1483
1484
1485 class VIEW3D_MT_edit_armature_roll(bpy.types.Menu):
1486     bl_label = "Bone Roll"
1487
1488     def draw(self, context):
1489         layout = self.layout
1490
1491         layout.operator("armature.calculate_roll", text="Clear Roll (Z-Axis Up)").type = 'GLOBALUP'
1492         layout.operator("armature.calculate_roll", text="Roll to Cursor").type = 'CURSOR'
1493
1494         layout.separator()
1495
1496         layout.operator("tfm.transform", text="Set Roll").mode = 'BONE_ROLL'
1497
1498 # ********** Panel **********
1499
1500
1501 class VIEW3D_PT_3dview_properties(bpy.types.Panel):
1502     bl_space_type = 'VIEW_3D'
1503     bl_region_type = 'UI'
1504     bl_label = "View"
1505
1506     def poll(self, context):
1507         view = context.space_data
1508         return (view)
1509
1510     def draw(self, context):
1511         layout = self.layout
1512
1513         view = context.space_data
1514         scene = context.scene
1515
1516         col = layout.column()
1517         col.label(text="Camera:")
1518         col.prop(view, "camera", text="")
1519         col.prop(view, "lens")
1520         col.label(text="Lock to Object:")
1521         col.prop(view, "lock_object", text="")
1522         if view.lock_object and view.lock_object.type == 'ARMATURE':
1523             col.prop_object(view, "lock_bone", view.lock_object.data, "bones", text="")
1524
1525         col = layout.column(align=True)
1526         col.label(text="Clip:")
1527         col.prop(view, "clip_start", text="Start")
1528         col.prop(view, "clip_end", text="End")
1529
1530
1531
1532         layout.column().prop(scene, "cursor_location", text="3D Cursor:")
1533         
1534         
1535
1536
1537 class VIEW3D_PT_3dview_name(bpy.types.Panel):
1538     bl_space_type = 'VIEW_3D'
1539     bl_region_type = 'UI'
1540     bl_label = "Item"
1541
1542     def poll(self, context):
1543         return (context.space_data and context.active_object)
1544
1545     def draw(self, context):
1546         layout = self.layout
1547
1548         ob = context.active_object
1549         row = layout.row()
1550         row.label(text="", icon='ICON_OBJECT_DATA')
1551         row.prop(ob, "name", text="")
1552
1553         if ob.type == 'ARMATURE' and ob.mode in ('EDIT', 'POSE'):
1554             bone = context.active_bone
1555             if bone:
1556                 row = layout.row()
1557                 row.label(text="", icon='ICON_BONE_DATA')
1558                 row.prop(bone, "name", text="")
1559
1560
1561 class VIEW3D_PT_3dview_display(bpy.types.Panel):
1562     bl_space_type = 'VIEW_3D'
1563     bl_region_type = 'UI'
1564     bl_label = "Display"
1565     bl_default_closed = True
1566
1567     def poll(self, context):
1568         view = context.space_data
1569         return (view)
1570
1571     def draw(self, context):
1572         layout = self.layout
1573
1574         view = context.space_data
1575         gs = context.scene.game_data
1576         ob = context.object
1577         
1578         col = layout.column()
1579         col.prop(view, "display_x_axis", text="X Axis")
1580         col.prop(view, "display_y_axis", text="Y Axis")
1581         col.prop(view, "display_z_axis", text="Z Axis")
1582         col.prop(view, "outline_selected")
1583         col.prop(view, "all_object_centers")
1584         col.prop(view, "relationship_lines")
1585         if ob and ob.type == 'MESH':
1586             mesh = ob.data
1587             col.prop(mesh, "all_edges")
1588         
1589         col = layout.column()
1590         col.prop(view, "display_floor", text="Grid Floor")
1591         sub = col.column(align=True)
1592         sub.active = view.display_floor
1593         sub.prop(view, "grid_lines", text="Lines")
1594         sub.prop(view, "grid_spacing", text="Spacing")
1595         sub.prop(view, "grid_subdivisions", text="Subdivisions")
1596         
1597         col = layout.column()
1598         col.label(text="Shading:")
1599         col.prop(gs, "material_mode", text="")
1600         col.prop(view, "textured_solid")
1601
1602 # XXX - the Quad View options don't work yet
1603 #               layout.separator()
1604 #
1605 #               layout.operator("screen.region_foursplit", text="Toggle Quad View")
1606 #               col = layout.column()
1607 #               col.prop(view, "lock_rotation")
1608 #               col.prop(view, "box_preview")
1609 #               col.prop(view, "box_clip")
1610
1611
1612 class VIEW3D_PT_3dview_meshdisplay(bpy.types.Panel):
1613     bl_space_type = 'VIEW_3D'
1614     bl_region_type = 'UI'
1615     bl_label = "Mesh Display"
1616
1617     def poll(self, context):
1618         # The active object check is needed because of localmode
1619         return (context.active_object and (context.mode == 'EDIT_MESH'))
1620
1621     def draw(self, context):
1622         layout = self.layout
1623
1624         mesh = context.active_object.data
1625
1626         col = layout.column()
1627         col.label(text="Overlays:")
1628         col.prop(mesh, "draw_edges", text="Edges")
1629         col.prop(mesh, "draw_faces", text="Faces")
1630         col.prop(mesh, "draw_creases", text="Creases")
1631         col.prop(mesh, "draw_bevel_weights", text="Bevel Weights")
1632         col.prop(mesh, "draw_seams", text="Seams")
1633         col.prop(mesh, "draw_sharp", text="Sharp")
1634
1635         col.separator()
1636         col.label(text="Normals:")
1637         col.prop(mesh, "draw_normals", text="Face")
1638         col.prop(mesh, "draw_vertex_normals", text="Vertex")
1639         col.prop(context.scene.tool_settings, "normal_size", text="Normal Size")
1640
1641         col.separator()
1642         col.label(text="Numerics:")
1643         col.prop(mesh, "draw_edge_lenght")
1644         col.prop(mesh, "draw_edge_angle")
1645         col.prop(mesh, "draw_face_area")
1646
1647
1648 class VIEW3D_PT_3dview_curvedisplay(bpy.types.Panel):
1649     bl_space_type = 'VIEW_3D'
1650     bl_region_type = 'UI'
1651     bl_label = "Curve Display"
1652
1653     def poll(self, context):
1654         editmesh = context.mode == 'EDIT_CURVE'
1655         return (editmesh)
1656
1657     def draw(self, context):
1658         layout = self.layout
1659
1660         curve = context.active_object.data
1661
1662         col = layout.column()
1663         col.label(text="Overlays:")
1664         col.prop(curve, "draw_handles", text="Handles")
1665         col.prop(curve, "draw_normals", text="Normals")
1666         col.prop(context.scene.tool_settings, "normal_size", text="Normal Size")
1667
1668
1669 class VIEW3D_PT_background_image(bpy.types.Panel):
1670     bl_space_type = 'VIEW_3D'
1671     bl_region_type = 'UI'
1672     bl_label = "Background Image"
1673     bl_default_closed = True
1674
1675     def poll(self, context):
1676         view = context.space_data
1677         # bg = context.space_data.background_image
1678         return (view)
1679
1680     def draw_header(self, context):
1681         layout = self.layout
1682         view = context.space_data
1683
1684         layout.prop(view, "display_background_image", text="")
1685
1686     def draw(self, context):
1687         layout = self.layout
1688
1689         view = context.space_data
1690         bg = view.background_image
1691
1692         if bg:
1693             layout.active = view.display_background_image
1694
1695             col = layout.column()
1696             col.template_ID(bg, "image", open="image.open")
1697             col.prop(bg, "size")
1698             col.prop(bg, "transparency", slider=True)
1699
1700
1701             col = layout.column(align=True)
1702             col.label(text="Offset:")
1703             col.prop(bg, "offset_x", text="X")
1704             col.prop(bg, "offset_y", text="Y")
1705
1706
1707 class VIEW3D_PT_transform_orientations(bpy.types.Panel):
1708     bl_space_type = 'VIEW_3D'
1709     bl_region_type = 'UI'
1710     bl_label = "Transform Orientations"
1711     bl_default_closed = True
1712
1713     def poll(self, context):
1714         view = context.space_data
1715         return (view)
1716
1717     def draw(self, context):
1718         layout = self.layout
1719
1720         view = context.space_data
1721
1722         col = layout.column()
1723
1724         col.prop(view, "transform_orientation")
1725         col.operator("tfm.create_orientation", text="Create")
1726
1727         orientation = view.current_orientation
1728
1729         if orientation:
1730             col.prop(orientation, "name")
1731             col.operator("tfm.delete_orientation", text="Delete")
1732
1733
1734 class VIEW3D_PT_etch_a_ton(bpy.types.Panel):
1735     bl_space_type = 'VIEW_3D'
1736     bl_region_type = 'UI'
1737     bl_label = "Skeleton Sketching"
1738     bl_default_closed = True
1739
1740     def poll(self, context):
1741         scene = context.space_data
1742         ob = context.active_object
1743         return scene and ob and ob.type == 'ARMATURE' and ob.mode == 'EDIT'
1744
1745     def draw_header(self, context):
1746         layout = self.layout
1747         toolsettings = context.scene.tool_settings
1748
1749         layout.prop(toolsettings, "bone_sketching", text="")
1750
1751     def draw(self, context):
1752         layout = self.layout
1753         toolsettings = context.scene.tool_settings
1754
1755         col = layout.column()
1756
1757         col.prop(toolsettings, "etch_quick")
1758         col.prop(toolsettings, "etch_overdraw")
1759
1760         col.prop(toolsettings, "etch_convert_mode")
1761
1762         if toolsettings.etch_convert_mode == 'LENGTH':
1763             col.prop(toolsettings, "etch_length_limit")
1764         elif toolsettings.etch_convert_mode == 'ADAPTIVE':
1765             col.prop(toolsettings, "etch_adaptive_limit")
1766         elif toolsettings.etch_convert_mode == 'FIXED':
1767             col.prop(toolsettings, "etch_subdivision_number")
1768         elif toolsettings.etch_convert_mode == 'RETARGET':
1769             col.prop(toolsettings, "etch_template")
1770             col.prop(toolsettings, "etch_roll_mode")
1771             col.prop(toolsettings, "etch_autoname")
1772             col.prop(toolsettings, "etch_number")
1773             col.prop(toolsettings, "etch_side")
1774
1775
1776 class VIEW3D_PT_context_properties(bpy.types.Panel):
1777     bl_space_type = 'VIEW_3D'
1778     bl_region_type = 'UI'
1779     bl_label = "Properties"
1780     bl_default_closed = True
1781
1782     def _active_context_member(self, context):
1783         obj = context.object
1784         if obj:
1785             mode = obj.mode
1786             if mode == 'POSE':
1787                 return "active_pose_bone"
1788             elif mode == 'EDIT' and obj.type == 'ARMATURE':
1789                 return "active_bone"
1790             else:
1791                 return "object"
1792
1793         return ""
1794     
1795     def poll(self, context):
1796         member = self._active_context_member(context)
1797         if member:
1798             context_member = getattr(context, member)
1799             return context_member and context_member.keys()
1800
1801         return False
1802
1803     def draw(self, context):
1804         import rna_prop_ui
1805         # reload(rna_prop_ui)
1806         member = self._active_context_member(context)
1807
1808         if member:
1809             # Draw with no edit button
1810             rna_prop_ui.draw(self.layout, context, member, False)
1811
1812
1813 # Operators
1814 from bpy.props import *
1815
1816
1817 class OBJECT_OT_select_pattern(bpy.types.Operator):
1818     '''Select object matching a naming pattern.'''
1819     bl_idname = "object.select_pattern"
1820     bl_label = "Select Pattern"
1821     bl_register = True
1822     bl_undo = True
1823
1824     pattern = StringProperty(name="Pattern", description="Name filter using '*' and '?' wildcard chars", maxlen=32, default="*")
1825     case_sensitive = BoolProperty(name="Case Sensitive", description="Do a case sensitive compare", default=False)
1826     extend = BoolProperty(name="Extend", description="Extend the existing selection", default=True)
1827
1828     def execute(self, context):
1829
1830         import fnmatch
1831
1832         if self.properties.case_sensitive:
1833             pattern_match = fnmatch.fnmatchcase
1834         else:
1835             pattern_match = lambda a, b: fnmatch.fnmatchcase(a.upper(), b.upper())
1836
1837         for ob in context.visible_objects:
1838             if pattern_match(ob.name, self.properties.pattern):
1839                 ob.selected = True
1840             elif not self.properties.extend:
1841                 ob.selected = False
1842
1843         return ('FINISHED',)
1844
1845         # TODO - python cant do popups yet
1846     '''
1847     def invoke(self, context, event):
1848         wm = context.manager
1849         wm.add_fileselect(self)
1850         return ('RUNNING_MODAL',)
1851     '''
1852
1853 bpy.types.register(VIEW3D_HT_header) # Header
1854
1855 bpy.types.register(VIEW3D_MT_view) #View Menus
1856 bpy.types.register(VIEW3D_MT_view_navigation)
1857 bpy.types.register(VIEW3D_MT_view_align)
1858 bpy.types.register(VIEW3D_MT_view_align_selected)
1859 bpy.types.register(VIEW3D_MT_view_cameras)
1860
1861 bpy.types.register(VIEW3D_MT_select_object) # Select Menus
1862 bpy.types.register(VIEW3D_MT_select_pose)
1863 bpy.types.register(VIEW3D_MT_select_particle)
1864 bpy.types.register(VIEW3D_MT_select_edit_mesh)
1865 bpy.types.register(VIEW3D_MT_select_edit_curve)
1866 bpy.types.register(VIEW3D_MT_select_edit_surface)
1867 bpy.types.register(VIEW3D_MT_select_edit_metaball)
1868 bpy.types.register(VIEW3D_MT_select_edit_lattice)
1869 bpy.types.register(VIEW3D_MT_select_edit_armature)
1870 bpy.types.register(VIEW3D_MT_select_face) # XXX todo
1871
1872 bpy.types.register(VIEW3D_MT_transform) # Object/Edit Menus
1873 bpy.types.register(VIEW3D_MT_mirror) # Object/Edit Menus
1874 bpy.types.register(VIEW3D_MT_snap) # Object/Edit Menus
1875 bpy.types.register(VIEW3D_MT_uv_map) # Edit Menus
1876
1877 bpy.types.register(VIEW3D_MT_object) # Object Menu
1878 bpy.types.register(VIEW3D_MT_object_apply)
1879 bpy.types.register(VIEW3D_MT_object_clear)
1880 bpy.types.register(VIEW3D_MT_object_parent)
1881 bpy.types.register(VIEW3D_MT_object_track)
1882 bpy.types.register(VIEW3D_MT_object_group)
1883 bpy.types.register(VIEW3D_MT_object_constraints)
1884 bpy.types.register(VIEW3D_MT_object_showhide)
1885 bpy.types.register(VIEW3D_MT_make_single_user)
1886 bpy.types.register(VIEW3D_MT_make_links)
1887
1888 bpy.types.register(VIEW3D_MT_hook)
1889 bpy.types.register(VIEW3D_MT_vertex_group)
1890
1891 bpy.types.register(VIEW3D_MT_sculpt) # Sculpt Menu
1892
1893 bpy.types.register(VIEW3D_MT_paint_vertex)
1894
1895 bpy.types.register(VIEW3D_MT_particle) # Particle Menu
1896 bpy.types.register(VIEW3D_MT_particle_showhide)
1897
1898 bpy.types.register(VIEW3D_MT_pose) # POSE Menu
1899 bpy.types.register(VIEW3D_MT_pose_transform)
1900 bpy.types.register(VIEW3D_MT_pose_pose)
1901 bpy.types.register(VIEW3D_MT_pose_motion)
1902 bpy.types.register(VIEW3D_MT_pose_group)
1903 bpy.types.register(VIEW3D_MT_pose_ik)
1904 bpy.types.register(VIEW3D_MT_pose_constraints)
1905 bpy.types.register(VIEW3D_MT_pose_showhide)
1906
1907 bpy.types.register(VIEW3D_MT_edit_mesh)
1908 bpy.types.register(VIEW3D_MT_edit_mesh_specials) # Only as a menu for keybindings
1909 bpy.types.register(VIEW3D_MT_edit_mesh_vertices)
1910 bpy.types.register(VIEW3D_MT_edit_mesh_edges)
1911 bpy.types.register(VIEW3D_MT_edit_mesh_faces)
1912 bpy.types.register(VIEW3D_MT_edit_mesh_normals)
1913 bpy.types.register(VIEW3D_MT_edit_mesh_showhide)
1914
1915 bpy.types.register(VIEW3D_MT_edit_curve)
1916 bpy.types.register(VIEW3D_MT_edit_curve_ctrlpoints)
1917 bpy.types.register(VIEW3D_MT_edit_curve_segments)
1918 bpy.types.register(VIEW3D_MT_edit_curve_showhide)
1919
1920 bpy.types.register(VIEW3D_MT_edit_surface)
1921
1922 bpy.types.register(VIEW3D_MT_edit_text)
1923 bpy.types.register(VIEW3D_MT_edit_text_chars)
1924
1925 bpy.types.register(VIEW3D_MT_edit_meta)
1926 bpy.types.register(VIEW3D_MT_edit_meta_showhide)
1927
1928 bpy.types.register(VIEW3D_MT_edit_lattice)
1929
1930 bpy.types.register(VIEW3D_MT_edit_armature)
1931 bpy.types.register(VIEW3D_MT_edit_armature_parent)
1932 bpy.types.register(VIEW3D_MT_edit_armature_roll)
1933
1934 bpy.types.register(VIEW3D_MT_armature_specials) # Only as a menu for keybindings
1935
1936  # Panels
1937 bpy.types.register(VIEW3D_PT_3dview_properties)
1938 bpy.types.register(VIEW3D_PT_3dview_display)
1939 bpy.types.register(VIEW3D_PT_3dview_name)
1940 bpy.types.register(VIEW3D_PT_3dview_meshdisplay)
1941 bpy.types.register(VIEW3D_PT_3dview_curvedisplay)
1942 bpy.types.register(VIEW3D_PT_background_image)
1943 bpy.types.register(VIEW3D_PT_transform_orientations)
1944 bpy.types.register(VIEW3D_PT_etch_a_ton)
1945
1946 bpy.types.register(VIEW3D_PT_context_properties)
1947
1948 bpy.ops.add(OBJECT_OT_select_pattern)