Cleanup: pep8
[blender.git] / release / scripts / startup / bl_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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import (
22     Header,
23     Menu,
24     Panel,
25 )
26 from .properties_paint_common import (
27     UnifiedPaintPanel,
28 )
29 from .properties_grease_pencil_common import (
30     AnnotationDataPanel,
31     AnnotationOnionSkin,
32     GreasePencilMaterialsPanel,
33 )
34 from .space_toolsystem_common import (
35     ToolActivePanelHelper,
36 )
37 from bpy.app.translations import contexts as i18n_contexts
38
39
40 class VIEW3D_HT_tool_header(Header):
41     bl_space_type = 'VIEW_3D'
42     bl_region_type = 'TOOL_HEADER'
43
44     def draw(self, context):
45         layout = self.layout
46
47         layout.row(align=True).template_header()
48
49         self.draw_tool_settings(context)
50
51         layout.separator_spacer()
52
53         VIEW3D_HT_header.draw_xform_template(layout, context)
54
55         layout.separator_spacer()
56
57         self.draw_mode_settings(context)
58
59     def draw_tool_settings(self, context):
60         layout = self.layout
61         tool_mode = context.mode
62
63         # Active Tool
64         # -----------
65         from .space_toolsystem_common import ToolSelectPanelHelper
66         tool = ToolSelectPanelHelper.draw_active_tool_header(
67             context, layout,
68             tool_key=('VIEW_3D', tool_mode),
69         )
70
71         # Object Mode Options
72         # -------------------
73
74         # Example of how tool_settings can be accessed as pop-overs.
75
76         # TODO(campbell): editing options should be after active tool options
77         # (obviously separated for from the users POV)
78         draw_fn = getattr(_draw_tool_settings_context_mode, tool_mode, None)
79         if draw_fn is not None:
80             draw_fn(context, layout, tool)
81
82         # Note: general mode options should be added to 'draw_mode_settings'.
83         if tool_mode == 'SCULPT':
84             if (tool is not None) and tool.has_datablock:
85                 layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".paint_common", category="Tool")
86         elif tool_mode == 'PAINT_VERTEX':
87             if (tool is not None) and tool.has_datablock:
88                 layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".paint_common", category="Tool")
89         elif tool_mode == 'PAINT_WEIGHT':
90             if (tool is not None) and tool.has_datablock:
91                 layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".paint_common", category="Tool")
92         elif tool_mode == 'PAINT_TEXTURE':
93             if (tool is not None) and tool.has_datablock:
94                 layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".paint_common", category="Tool")
95         elif tool_mode == 'EDIT_ARMATURE':
96             pass
97         elif tool_mode == 'EDIT_CURVE':
98             pass
99         elif tool_mode == 'EDIT_MESH':
100             pass
101         elif tool_mode == 'POSE':
102             pass
103         elif tool_mode == 'PARTICLE':
104             # Disable, only shows "Brush" panel, which is already in the top-bar.
105             # if tool.has_datablock:
106             #     layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".paint_common", category="Tool")
107             pass
108         elif tool_mode == 'PAINT_GPENCIL':
109             if (tool is not None) and tool.has_datablock:
110                 layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".greasepencil_paint", category="Tool")
111         elif tool_mode == 'SCULPT_GPENCIL':
112             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".greasepencil_sculpt", category="Tool")
113         elif tool_mode == 'WEIGHT_GPENCIL':
114             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".greasepencil_weight", category="Tool")
115
116     def draw_mode_settings(self, context):
117         layout = self.layout
118         mode_string = context.mode
119
120         def row_for_mirror():
121             row = layout.row(align=True)
122             row.label(icon='MOD_MIRROR')
123             sub = row.row(align=True)
124             sub.scale_x = 0.6
125             return row, sub
126
127         if mode_string == 'EDIT_MESH':
128             _row, sub = row_for_mirror()
129             sub.prop(context.object.data, "use_mirror_x", text="X", toggle=True)
130             tool_settings = context.tool_settings
131             layout.prop(tool_settings, "use_mesh_automerge", text="")
132         elif mode_string == 'EDIT_ARMATURE':
133             _row, sub = row_for_mirror()
134             sub.prop(context.object.data, "use_mirror_x", text="X", toggle=True)
135         elif mode_string == 'POSE':
136             _row, sub = row_for_mirror()
137             sub.prop(context.object.pose, "use_mirror_x", text="X", toggle=True)
138         elif mode_string == 'PAINT_WEIGHT':
139             row, sub = row_for_mirror()
140             sub.prop(context.object.data, "use_mirror_x", text="X", toggle=True)
141             row.popover(panel="VIEW3D_PT_tools_weightpaint_symmetry_for_topbar", text="")
142         elif mode_string == 'SCULPT':
143             row, sub = row_for_mirror()
144             sculpt = context.tool_settings.sculpt
145             sub.prop(sculpt, "use_symmetry_x", text="X", toggle=True)
146             sub.prop(sculpt, "use_symmetry_y", text="Y", toggle=True)
147             sub.prop(sculpt, "use_symmetry_z", text="Z", toggle=True)
148             row.popover(panel="VIEW3D_PT_sculpt_symmetry_for_topbar", text="")
149         elif mode_string == 'PAINT_TEXTURE':
150             _row, sub = row_for_mirror()
151             ipaint = context.tool_settings.image_paint
152             sub.prop(ipaint, "use_symmetry_x", text="X", toggle=True)
153             sub.prop(ipaint, "use_symmetry_y", text="Y", toggle=True)
154             sub.prop(ipaint, "use_symmetry_z", text="Z", toggle=True)
155             # No need for a popover, the panel only has these options.
156         elif mode_string == 'PAINT_VERTEX':
157             row, sub = row_for_mirror()
158             vpaint = context.tool_settings.vertex_paint
159             sub.prop(vpaint, "use_symmetry_x", text="X", toggle=True)
160             sub.prop(vpaint, "use_symmetry_y", text="Y", toggle=True)
161             sub.prop(vpaint, "use_symmetry_z", text="Z", toggle=True)
162             row.popover(panel="VIEW3D_PT_tools_vertexpaint_symmetry_for_topbar", text="")
163
164         # Expand panels from the side-bar as popovers.
165         if mode_string == 'SCULPT':
166             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".sculpt_mode", category="Tool")
167         elif mode_string == 'PAINT_VERTEX':
168             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".vertexpaint", category="Tool")
169         elif mode_string == 'PAINT_WEIGHT':
170             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".weightpaint", category="Tool")
171         elif mode_string == 'PAINT_TEXTURE':
172             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".imagepaint", category="Tool")
173         elif mode_string == 'EDIT_TEXT':
174             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".text_edit", category="Tool")
175         elif mode_string == 'EDIT_ARMATURE':
176             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".armature_edit", category="Tool")
177         elif mode_string == 'EDIT_METABALL':
178             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".mball_edit", category="Tool")
179         elif mode_string == 'EDIT_LATTICE':
180             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".lattice_edit", category="Tool")
181         elif mode_string == 'EDIT_CURVE':
182             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".curve_edit", category="Tool")
183         elif mode_string == 'EDIT_MESH':
184             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".mesh_edit", category="Tool")
185         elif mode_string == 'POSE':
186             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".posemode", category="Tool")
187         elif mode_string == 'PARTICLE':
188             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".particlemode", category="Tool")
189         elif mode_string == 'OBJECT':
190             layout.popover_group(space_type='VIEW_3D', region_type='UI', context=".objectmode", category="Tool")
191         elif mode_string in {'PAINT_GPENCIL', 'EDIT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}:
192             # Grease pencil layer.
193             gpl = context.active_gpencil_layer
194             if gpl and gpl.info is not None:
195                 text = gpl.info
196                 maxw = 25
197                 if len(text) > maxw:
198                     text = text[:maxw - 5] + '..' + text[-3:]
199             else:
200                 text = ""
201
202             layout.label(text="Layer:")
203             sub = layout.row()
204             sub.ui_units_x = 8
205             sub.popover(
206                 panel="TOPBAR_PT_gpencil_layers",
207                 text=text,
208             )
209
210
211 class _draw_tool_settings_context_mode:
212     @staticmethod
213     def SCULPT(context, layout, tool):
214         if (tool is None) or (not tool.has_datablock):
215             return
216
217         paint = context.tool_settings.sculpt
218         layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
219
220         brush = paint.brush
221         if brush is None:
222             return
223
224         from .properties_paint_common import (
225             brush_basic_sculpt_settings,
226         )
227         brush_basic_sculpt_settings(layout, context, brush, compact=True)
228
229     @staticmethod
230     def PAINT_TEXTURE(context, layout, tool):
231         if (tool is None) or (not tool.has_datablock):
232             return
233
234         paint = context.tool_settings.image_paint
235         layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
236
237         brush = paint.brush
238         if brush is None:
239             return
240
241         from .properties_paint_common import (
242             UnifiedPaintPanel,
243             brush_basic_texpaint_settings,
244         )
245         capabilities = brush.image_paint_capabilities
246         if capabilities.has_color:
247             UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
248         brush_basic_texpaint_settings(layout, context, brush, compact=True)
249
250     @staticmethod
251     def PAINT_VERTEX(context, layout, tool):
252         if (tool is None) or (not tool.has_datablock):
253             return
254
255         paint = context.tool_settings.vertex_paint
256         layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
257
258         brush = paint.brush
259         if brush is None:
260             return
261
262         from .properties_paint_common import (
263             UnifiedPaintPanel,
264             brush_basic_vpaint_settings,
265         )
266         capabilities = brush.vertex_paint_capabilities
267         if capabilities.has_color:
268             UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
269         brush_basic_vpaint_settings(layout, context, brush, compact=True)
270
271     @staticmethod
272     def PAINT_WEIGHT(context, layout, tool):
273         if (tool is None) or (not tool.has_datablock):
274             return
275
276         paint = context.tool_settings.weight_paint
277         layout.template_ID_preview(paint, "brush", rows=3, cols=8, hide_buttons=True)
278         brush = paint.brush
279         if brush is None:
280             return
281
282         from .properties_paint_common import brush_basic_wpaint_settings
283         brush_basic_wpaint_settings(layout, context, brush, compact=True)
284
285     @staticmethod
286     def PAINT_GPENCIL(context, layout, tool):
287         if tool is None:
288             return
289
290         # is_paint = True
291         # FIXME: tools must use their own UI drawing!
292         if tool.idname in {"builtin.line", "builtin.box", "builtin.circle", "builtin.arc", "builtin.curve"}:
293             # is_paint = False
294             pass
295         elif tool.idname == "Cutter":
296             row = layout.row(align=True)
297             row.prop(context.tool_settings.gpencil_sculpt, "intersection_threshold")
298             return
299         elif not tool.has_datablock:
300             return
301
302         paint = context.tool_settings.gpencil_paint
303         brush = paint.brush
304         if brush is None:
305             return
306
307         gp_settings = brush.gpencil_settings
308
309         def draw_color_selector():
310             ma = gp_settings.material
311             row = layout.row(align=True)
312             if not gp_settings.use_material_pin:
313                 ma = context.object.active_material
314             icon_id = 0
315             if ma:
316                 icon_id = ma.id_data.preview.icon_id
317                 txt_ma = ma.name
318                 maxw = 25
319                 if len(txt_ma) > maxw:
320                     txt_ma = txt_ma[:maxw - 5] + '..' + txt_ma[-3:]
321             else:
322                 txt_ma = ""
323
324             sub = row.row()
325             sub.ui_units_x = 8
326             sub.popover(
327                 panel="TOPBAR_PT_gpencil_materials",
328                 text=txt_ma,
329                 icon_value=icon_id,
330             )
331
332             row.prop(gp_settings, "use_material_pin", text="")
333
334         row = layout.row(align=True)
335         tool_settings = context.scene.tool_settings
336         settings = tool_settings.gpencil_paint
337         row.template_ID_preview(settings, "brush", rows=3, cols=8, hide_buttons=True)
338
339         if context.object and brush.gpencil_tool in {'FILL', 'DRAW'}:
340             draw_color_selector()
341
342         from .properties_paint_common import (
343             brush_basic_gpencil_paint_settings,
344         )
345         brush_basic_gpencil_paint_settings(layout, context, brush, compact=True)
346
347         # FIXME: tools must use their own UI drawing!
348         if tool.idname in {"builtin.arc", "builtin.curve", "builtin.line", "builtin.box", "builtin.circle"}:
349             settings = context.tool_settings.gpencil_sculpt
350             row = layout.row(align=True)
351             row.prop(settings, "use_thickness_curve", text="", icon='CURVE_DATA')
352             sub = row.row(align=True)
353             sub.active = settings.use_thickness_curve
354             sub.popover(
355                 panel="TOPBAR_PT_gpencil_primitive",
356                 text="Thickness Profile",
357             )
358
359         if brush.gpencil_tool == 'FILL':
360             settings = context.tool_settings.gpencil_sculpt
361             row = layout.row(align=True)
362             sub = row.row(align=True)
363             sub.popover(
364                 panel="TOPBAR_PT_gpencil_fill",
365                 text="Fill Options",
366             )
367
368     @staticmethod
369     def SCULPT_GPENCIL(context, layout, tool):
370         if (tool is None) or (not tool.has_datablock):
371             return
372         tool_settings = context.tool_settings
373         settings = tool_settings.gpencil_sculpt
374         brush = settings.brush
375
376         from .properties_paint_common import (
377             brush_basic_gpencil_sculpt_settings,
378         )
379         brush_basic_gpencil_sculpt_settings(layout, context, brush, compact=True)
380
381     @staticmethod
382     def WEIGHT_GPENCIL(context, layout, tool):
383         if (tool is None) or (not tool.has_datablock):
384             return
385         tool_settings = context.tool_settings
386         settings = tool_settings.gpencil_sculpt
387         brush = settings.brush
388
389         from .properties_paint_common import (
390             brush_basic_gpencil_weight_settings,
391         )
392         brush_basic_gpencil_weight_settings(layout, context, brush, compact=True)
393
394     @staticmethod
395     def PARTICLE(context, layout, tool):
396         if (tool is None) or (not tool.has_datablock):
397             return
398
399         # See: 'VIEW3D_PT_tools_brush', basically a duplicate
400         settings = context.tool_settings.particle_edit
401         brush = settings.brush
402         tool = settings.tool
403         if tool != 'NONE':
404             layout.prop(brush, "size", slider=True)
405             if tool == 'ADD':
406                 layout.prop(brush, "count")
407
408                 layout.prop(settings, "use_default_interpolate")
409                 layout.prop(brush, "steps", slider=True)
410                 layout.prop(settings, "default_key_count", slider=True)
411             else:
412                 layout.prop(brush, "strength", slider=True)
413
414                 if tool == 'LENGTH':
415                     layout.row().prop(brush, "length_mode", expand=True)
416                 elif tool == 'PUFF':
417                     layout.row().prop(brush, "puff_mode", expand=True)
418                     layout.prop(brush, "use_puff_volume")
419                 elif tool == 'COMB':
420                     row = layout.row()
421                     row.active = settings.is_editable
422                     row.prop(settings, "use_emitter_deflect", text="Deflect Emitter")
423                     sub = row.row(align=True)
424                     sub.active = settings.use_emitter_deflect
425                     sub.prop(settings, "emitter_distance", text="Distance")
426
427
428 class VIEW3D_HT_header(Header):
429     bl_space_type = 'VIEW_3D'
430
431     @staticmethod
432     def draw_xform_template(layout, context):
433         obj = context.active_object
434         object_mode = 'OBJECT' if obj is None else obj.mode
435         has_pose_mode = (
436             (object_mode == 'POSE') or
437             (object_mode == 'WEIGHT_PAINT' and context.pose_object is not None)
438         )
439
440         tool_settings = context.tool_settings
441
442         # Mode & Transform Settings
443         scene = context.scene
444
445         # Orientation
446         if object_mode in {'OBJECT', 'EDIT', 'EDIT_GPENCIL'} or has_pose_mode:
447             orient_slot = scene.transform_orientation_slots[0]
448             row = layout.row(align=True)
449
450             sub = row.row()
451             sub.ui_units_x = 4
452             sub.prop_with_popover(
453                 orient_slot,
454                 "type",
455                 text="",
456                 panel="VIEW3D_PT_transform_orientations",
457             )
458
459         # Pivot
460         if object_mode in {'OBJECT', 'EDIT', 'EDIT_GPENCIL', 'SCULPT_GPENCIL'} or has_pose_mode:
461             layout.prop_with_popover(
462                 tool_settings,
463                 "transform_pivot_point",
464                 text="",
465                 icon_only=True,
466                 panel="VIEW3D_PT_pivot_point",
467             )
468
469         # Snap
470         show_snap = False
471         if obj is None:
472             show_snap = True
473         else:
474             if (object_mode not in {
475                     'SCULPT', 'VERTEX_PAINT', 'WEIGHT_PAINT', 'TEXTURE_PAINT',
476                     'PAINT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'
477             }) or has_pose_mode:
478                 show_snap = True
479             else:
480
481                 from .properties_paint_common import UnifiedPaintPanel
482                 paint_settings = UnifiedPaintPanel.paint_settings(context)
483
484                 if paint_settings:
485                     brush = paint_settings.brush
486                     if brush and brush.stroke_method == 'CURVE':
487                         show_snap = True
488
489         if show_snap:
490             snap_items = bpy.types.ToolSettings.bl_rna.properties["snap_elements"].enum_items
491             snap_elements = tool_settings.snap_elements
492             if len(snap_elements) == 1:
493                 text = ""
494                 for elem in snap_elements:
495                     icon = snap_items[elem].icon
496                     break
497             else:
498                 text = "Mix"
499                 icon = 'NONE'
500             del snap_items, snap_elements
501
502             row = layout.row(align=True)
503             row.prop(tool_settings, "use_snap", text="")
504
505             sub = row.row(align=True)
506             sub.popover(
507                 panel="VIEW3D_PT_snapping",
508                 icon=icon,
509                 text=text,
510             )
511
512         # Proportional editing
513         if object_mode in {'EDIT', 'PARTICLE_EDIT', 'SCULPT_GPENCIL', 'EDIT_GPENCIL', 'OBJECT'}:
514             row = layout.row(align=True)
515             kw = {}
516             if object_mode == 'OBJECT':
517                 attr = "use_proportional_edit_objects"
518             else:
519                 attr = "use_proportional_edit"
520
521                 if tool_settings.use_proportional_edit:
522                     if tool_settings.use_proportional_connected:
523                         kw["icon"] = 'PROP_CON'
524                     elif tool_settings.use_proportional_projected:
525                         kw["icon"] = 'PROP_PROJECTED'
526                     else:
527                         kw["icon"] = 'PROP_ON'
528                 else:
529                     kw["icon"] = 'PROP_OFF'
530
531             row.prop(tool_settings, attr, icon_only=True, **kw)
532             sub = row.row(align=True)
533             sub.active = getattr(tool_settings, attr)
534             sub.prop_with_popover(
535                 tool_settings,
536                 "proportional_edit_falloff",
537                 text="",
538                 icon_only=True,
539                 panel="VIEW3D_PT_proportional_edit",
540             )
541
542     def draw(self, context):
543         layout = self.layout
544
545         tool_settings = context.tool_settings
546         view = context.space_data
547         shading = view.shading
548         # mode_string = context.mode
549         obj = context.active_object
550         show_region_tool_header = view.show_region_tool_header
551
552         if not show_region_tool_header:
553             layout.row(align=True).template_header()
554
555         row = layout.row(align=True)
556         object_mode = 'OBJECT' if obj is None else obj.mode
557
558         # Note: This is actually deadly in case enum_items have to be dynamically generated
559         #       (because internal RNA array iterator will free everything immediately...).
560         # XXX This is an RNA internal issue, not sure how to fix it.
561         # Note: Tried to add an accessor to get translated UI strings instead of manual call
562         #       to pgettext_iface below, but this fails because translated enumitems
563         #       are always dynamically allocated.
564         act_mode_item = bpy.types.Object.bl_rna.properties["mode"].enum_items[object_mode]
565         act_mode_i18n_context = bpy.types.Object.bl_rna.properties["mode"].translation_context
566
567         sub = row.row(align=True)
568         sub.ui_units_x = 5.5
569         sub.operator_menu_enum(
570             "object.mode_set", "mode",
571             text=bpy.app.translations.pgettext_iface(act_mode_item.name, act_mode_i18n_context),
572             icon=act_mode_item.icon,
573         )
574         del act_mode_item
575
576         layout.template_header_3D_mode()
577
578         # Contains buttons like Mode, Pivot, Layer, Mesh Select Mode...
579         if obj:
580             # Particle edit
581             if object_mode == 'PARTICLE_EDIT':
582                 row = layout.row()
583                 row.prop(tool_settings.particle_edit, "select_mode", text="", expand=True)
584
585         # Grease Pencil
586         if obj and obj.type == 'GPENCIL' and context.gpencil_data:
587             gpd = context.gpencil_data
588
589             if gpd.is_stroke_paint_mode:
590                 row = layout.row()
591                 sub = row.row(align=True)
592                 sub.prop(tool_settings, "use_gpencil_draw_onback", text="", icon='MOD_OPACITY')
593                 sub.separator(factor=0.4)
594                 sub.prop(tool_settings, "use_gpencil_weight_data_add", text="", icon='WPAINT_HLT')
595                 sub.separator(factor=0.4)
596                 sub.prop(tool_settings, "use_gpencil_draw_additive", text="", icon='FREEZE')
597
598             if gpd.use_stroke_edit_mode:
599                 row = layout.row(align=True)
600                 row.prop(tool_settings, "gpencil_selectmode", text="", expand=True)
601
602             if gpd.use_stroke_edit_mode or gpd.is_stroke_sculpt_mode or gpd.is_stroke_weight_mode:
603                 row = layout.row(align=True)
604
605                 if gpd.is_stroke_sculpt_mode:
606                     row.prop(tool_settings.gpencil_sculpt, "use_select_mask", text="")
607                     row.separator()
608
609                 row.prop(gpd, "use_multiedit", text="", icon='GP_MULTIFRAME_EDITING')
610
611                 sub = row.row(align=True)
612                 sub.active = gpd.use_multiedit
613                 sub.popover(
614                     panel="VIEW3D_PT_gpencil_multi_frame",
615                     text="Multiframe",
616                 )
617
618             if gpd.use_stroke_edit_mode:
619                 row = layout.row(align=True)
620                 row.prop(tool_settings.gpencil_sculpt, "use_select_mask", text="")
621
622                 row.popover(
623                     panel="VIEW3D_PT_tools_grease_pencil_interpolate",
624                     text="Interpolate",
625                 )
626
627         overlay = view.overlay
628
629         VIEW3D_MT_editor_menus.draw_collapsible(context, layout)
630
631         layout.separator_spacer()
632
633         if object_mode in {'PAINT_GPENCIL', 'SCULPT_GPENCIL'}:
634             # Grease pencil
635             if object_mode == 'PAINT_GPENCIL':
636                 layout.prop_with_popover(
637                     tool_settings,
638                     "gpencil_stroke_placement_view3d",
639                     text="",
640                     panel="VIEW3D_PT_gpencil_origin",
641                 )
642
643             if object_mode in {'PAINT_GPENCIL', 'SCULPT_GPENCIL'}:
644                 layout.prop_with_popover(
645                     tool_settings.gpencil_sculpt,
646                     "lock_axis",
647                     text="",
648                     panel="VIEW3D_PT_gpencil_lock",
649                 )
650
651             if object_mode == 'PAINT_GPENCIL':
652                 # FIXME: this is bad practice!
653                 # Tool options are to be displayed in the topbar.
654                 if context.workspace.tools.from_space_view3d_mode(object_mode).idname == "builtin_brush.Draw":
655                     settings = tool_settings.gpencil_sculpt.guide
656                     row = layout.row(align=True)
657                     row.prop(settings, "use_guide", text="", icon='GRID')
658                     sub = row.row(align=True)
659                     sub.active = settings.use_guide
660                     sub.popover(
661                         panel="VIEW3D_PT_gpencil_guide",
662                         text="Guides",
663                     )
664
665             layout.separator_spacer()
666         elif not show_region_tool_header:
667             # Transform settings depending on tool header visibility
668             VIEW3D_HT_header.draw_xform_template(layout, context)
669
670             layout.separator_spacer()
671
672         # Viewport Settings
673         layout.popover(
674             panel="VIEW3D_PT_object_type_visibility",
675             icon_value=view.icon_from_show_object_viewport,
676             text="",
677         )
678
679         # Gizmo toggle & popover.
680         row = layout.row(align=True)
681         # FIXME: place-holder icon.
682         row.prop(view, "show_gizmo", text="", toggle=True, icon='GIZMO')
683         sub = row.row(align=True)
684         sub.active = view.show_gizmo
685         sub.popover(
686             panel="VIEW3D_PT_gizmo_display",
687             text="",
688         )
689
690         # Overlay toggle & popover.
691         row = layout.row(align=True)
692         row.prop(overlay, "show_overlays", icon='OVERLAY', text="")
693         sub = row.row(align=True)
694         sub.active = overlay.show_overlays
695         sub.popover(panel="VIEW3D_PT_overlay", text="")
696
697         row = layout.row()
698         row.active = (shading.type in {'WIREFRAME', 'SOLID'}) or object_mode in {'EDIT'}
699
700         if shading.type == 'WIREFRAME':
701             row.prop(shading, "show_xray_wireframe", text="", icon='XRAY')
702         else:
703             row.prop(shading, "show_xray", text="", icon='XRAY')
704
705         row = layout.row(align=True)
706         row.prop(shading, "type", text="", expand=True)
707         sub = row.row(align=True)
708         # TODO, currently render shading type ignores mesh two-side, until it's supported
709         # show the shading popover which shows double-sided option.
710
711         # sub.enabled = shading.type != 'RENDERED'
712         sub.popover(panel="VIEW3D_PT_shading", text="")
713
714
715 class VIEW3D_MT_editor_menus(Menu):
716     bl_label = ""
717
718     def draw(self, context):
719         layout = self.layout
720         obj = context.active_object
721         mode_string = context.mode
722         edit_object = context.edit_object
723         gp_edit = obj and obj.mode in {'EDIT_GPENCIL', 'PAINT_GPENCIL', 'SCULPT_GPENCIL', 'WEIGHT_GPENCIL'}
724
725         layout.menu("VIEW3D_MT_view")
726
727         # Select Menu
728         if gp_edit:
729             if mode_string not in {'PAINT_GPENCIL', 'WEIGHT_GPENCIL'}:
730                 layout.menu("VIEW3D_MT_select_gpencil")
731         elif mode_string in {'PAINT_WEIGHT', 'PAINT_VERTEX', 'PAINT_TEXTURE'}:
732             mesh = obj.data
733             if mesh.use_paint_mask:
734                 layout.menu("VIEW3D_MT_select_paint_mask")
735             elif mesh.use_paint_mask_vertex and mode_string in {'PAINT_WEIGHT', 'PAINT_VERTEX'}:
736                 layout.menu("VIEW3D_MT_select_paint_mask_vertex")
737         elif mode_string != 'SCULPT':
738             layout.menu("VIEW3D_MT_select_%s" % mode_string.lower())
739
740         if gp_edit:
741             pass
742         elif mode_string == 'OBJECT':
743             layout.menu("VIEW3D_MT_add", text="Add", text_ctxt=i18n_contexts.operator_default)
744         elif mode_string == 'EDIT_MESH':
745             layout.menu("VIEW3D_MT_mesh_add", text="Add", text_ctxt=i18n_contexts.operator_default)
746         elif mode_string == 'EDIT_CURVE':
747             layout.menu("VIEW3D_MT_curve_add", text="Add", text_ctxt=i18n_contexts.operator_default)
748         elif mode_string == 'EDIT_SURFACE':
749             layout.menu("VIEW3D_MT_surface_add", text="Add", text_ctxt=i18n_contexts.operator_default)
750         elif mode_string == 'EDIT_METABALL':
751             layout.menu("VIEW3D_MT_metaball_add", text="Add", text_ctxt=i18n_contexts.operator_default)
752         elif mode_string == 'EDIT_ARMATURE':
753             layout.menu("TOPBAR_MT_edit_armature_add", text="Add", text_ctxt=i18n_contexts.operator_default)
754
755         if gp_edit:
756             if obj and obj.mode == 'PAINT_GPENCIL':
757                 layout.menu("VIEW3D_MT_paint_gpencil")
758             elif obj and obj.mode == 'EDIT_GPENCIL':
759                 layout.menu("VIEW3D_MT_edit_gpencil")
760             elif obj and obj.mode == 'WEIGHT_GPENCIL':
761                 layout.menu("VIEW3D_MT_weight_gpencil")
762
763         elif edit_object:
764             layout.menu("VIEW3D_MT_edit_%s" % edit_object.type.lower())
765
766             if mode_string == 'EDIT_MESH':
767                 layout.menu("VIEW3D_MT_edit_mesh_vertices")
768                 layout.menu("VIEW3D_MT_edit_mesh_edges")
769                 layout.menu("VIEW3D_MT_edit_mesh_faces")
770                 layout.menu("VIEW3D_MT_uv_map", text="UV")
771             elif mode_string in {'EDIT_CURVE', 'EDIT_SURFACE'}:
772                 layout.menu("VIEW3D_MT_edit_curve_ctrlpoints")
773                 layout.menu("VIEW3D_MT_edit_curve_segments")
774
775         elif obj:
776             if mode_string != 'PAINT_TEXTURE':
777                 layout.menu("VIEW3D_MT_%s" % mode_string.lower())
778             if mode_string in {'SCULPT', 'PAINT_VERTEX', 'PAINT_WEIGHT', 'PAINT_TEXTURE'}:
779                 layout.menu("VIEW3D_MT_brush")
780             if mode_string == 'SCULPT':
781                 layout.menu("VIEW3D_MT_hide_mask")
782         else:
783             layout.menu("VIEW3D_MT_object")
784
785
786 # ********** Menu **********
787
788
789 # ********** Utilities **********
790
791
792 class ShowHideMenu:
793     bl_label = "Show/Hide"
794     _operator_name = ""
795
796     def draw(self, _context):
797         layout = self.layout
798
799         layout.operator("%s.reveal" % self._operator_name)
800         layout.operator("%s.hide" % self._operator_name, text="Hide Selected").unselected = False
801         layout.operator("%s.hide" % self._operator_name, text="Hide Unselected").unselected = True
802
803
804 # Standard transforms which apply to all cases
805 # NOTE: this doesn't seem to be able to be used directly
806 class VIEW3D_MT_transform_base(Menu):
807     bl_label = "Transform"
808     bl_category = "View"
809
810     # TODO: get rid of the custom text strings?
811     def draw(self, context):
812         layout = self.layout
813
814         layout.operator("transform.translate")
815         layout.operator("transform.rotate")
816         layout.operator("transform.resize", text="Scale")
817
818         layout.separator()
819
820         layout.operator("transform.tosphere", text="To Sphere")
821         layout.operator("transform.shear", text="Shear")
822         layout.operator("transform.bend", text="Bend")
823         layout.operator("transform.push_pull", text="Push/Pull")
824
825         if context.mode != 'OBJECT':
826             layout.operator("transform.vertex_warp", text="Warp")
827             layout.operator("transform.vertex_random", text="Randomize")
828
829
830 # Generic transform menu - geometry types
831 class VIEW3D_MT_transform(VIEW3D_MT_transform_base):
832     def draw(self, context):
833         # base menu
834         VIEW3D_MT_transform_base.draw(self, context)
835
836         # generic...
837         layout = self.layout
838         if context.mode == 'EDIT_MESH':
839             layout.operator("transform.shrink_fatten", text="Shrink Fatten")
840         elif context.mode == 'EDIT_CURVE':
841             layout.operator("transform.transform", text="Radius").mode = 'CURVE_SHRINKFATTEN'
842
843         layout.separator()
844
845         layout.operator("transform.translate", text="Move Texture Space").texture_space = True
846         layout.operator("transform.resize", text="Scale Texture Space").texture_space = True
847
848
849 # Object-specific extensions to Transform menu
850 class VIEW3D_MT_transform_object(VIEW3D_MT_transform_base):
851     def draw(self, context):
852         layout = self.layout
853
854         # base menu
855         VIEW3D_MT_transform_base.draw(self, context)
856
857         # object-specific option follow...
858         layout.separator()
859
860         layout.operator("transform.translate", text="Move Texture Space").texture_space = True
861         layout.operator("transform.resize", text="Scale Texture Space").texture_space = True
862
863         layout.separator()
864
865         layout.operator_context = 'EXEC_REGION_WIN'
866         # XXX see alignmenu() in edit.c of b2.4x to get this working
867         layout.operator("transform.transform", text="Align to Transform Orientation").mode = 'ALIGN'
868
869         layout.separator()
870
871         layout.operator("object.randomize_transform")
872         layout.operator("object.align")
873
874         # TODO: there is a strange context bug here.
875         """
876         layout.operator_context = 'INVOKE_REGION_WIN'
877         layout.operator("object.transform_axis_target")
878         """
879
880
881 # Armature EditMode extensions to Transform menu
882 class VIEW3D_MT_transform_armature(VIEW3D_MT_transform_base):
883     def draw(self, context):
884         layout = self.layout
885
886         # base menu
887         VIEW3D_MT_transform_base.draw(self, context)
888
889         # armature specific extensions follow...
890         obj = context.object
891         if obj.type == 'ARMATURE' and obj.mode in {'EDIT', 'POSE'}:
892             if obj.data.display_type == 'BBONE':
893                 layout.separator()
894
895                 layout.operator("transform.transform", text="Scale BBone").mode = 'BONE_SIZE'
896             elif obj.data.display_type == 'ENVELOPE':
897                 layout.separator()
898
899                 layout.operator("transform.transform", text="Scale Envelope Distance").mode = 'BONE_SIZE'
900                 layout.operator("transform.transform", text="Scale Radius").mode = 'BONE_ENVELOPE'
901
902         if context.edit_object and context.edit_object.type == 'ARMATURE':
903             layout.separator()
904
905             layout.operator("armature.align")
906
907
908 class VIEW3D_MT_mirror(Menu):
909     bl_label = "Mirror"
910
911     def draw(self, _context):
912         layout = self.layout
913
914         layout.operator("transform.mirror", text="Interactive Mirror")
915
916         layout.separator()
917
918         layout.operator_context = 'EXEC_REGION_WIN'
919
920         for (space_name, space_id) in (("Global", 'GLOBAL'), ("Local", 'LOCAL')):
921             for axis_index, axis_name in enumerate("XYZ"):
922                 props = layout.operator("transform.mirror", text=f"{axis_name!s} {space_name!s}")
923                 props.constraint_axis[axis_index] = True
924                 props.orient_type = 'GLOBAL'
925
926             if space_id == 'GLOBAL':
927                 layout.separator()
928
929
930 class VIEW3D_MT_snap(Menu):
931     bl_label = "Snap"
932
933     def draw(self, _context):
934         layout = self.layout
935
936         layout.operator("view3d.snap_selected_to_grid", text="Selection to Grid")
937         layout.operator("view3d.snap_selected_to_cursor", text="Selection to Cursor").use_offset = False
938         layout.operator("view3d.snap_selected_to_cursor", text="Selection to Cursor (Keep Offset)").use_offset = True
939         layout.operator("view3d.snap_selected_to_active", text="Selection to Active")
940
941         layout.separator()
942
943         layout.operator("view3d.snap_cursor_to_selected", text="Cursor to Selected")
944         layout.operator("view3d.snap_cursor_to_center", text="Cursor to World Origin")
945         layout.operator("view3d.snap_cursor_to_grid", text="Cursor to Grid")
946         layout.operator("view3d.snap_cursor_to_active", text="Cursor to Active")
947
948
949 class VIEW3D_MT_uv_map(Menu):
950     bl_label = "UV Mapping"
951
952     def draw(self, _context):
953         layout = self.layout
954
955         layout.operator("uv.unwrap")
956
957         layout.operator_context = 'INVOKE_DEFAULT'
958         layout.operator("uv.smart_project")
959         layout.operator("uv.lightmap_pack")
960         layout.operator("uv.follow_active_quads")
961
962         layout.separator()
963
964         layout.operator_context = 'EXEC_REGION_WIN'
965         layout.operator("uv.cube_project")
966         layout.operator("uv.cylinder_project")
967         layout.operator("uv.sphere_project")
968
969         layout.separator()
970
971         layout.operator_context = 'INVOKE_REGION_WIN'
972         layout.operator("uv.project_from_view").scale_to_bounds = False
973         layout.operator("uv.project_from_view", text="Project from View (Bounds)").scale_to_bounds = True
974
975         layout.separator()
976
977         layout.operator("mesh.mark_seam").clear = False
978         layout.operator("mesh.mark_seam", text="Clear Seam").clear = True
979
980         layout.separator()
981
982         layout.operator("uv.reset")
983
984
985 # ********** View menus **********
986
987
988 class VIEW3D_MT_view(Menu):
989     bl_label = "View"
990
991     def draw(self, context):
992         layout = self.layout
993         view = context.space_data
994
995         layout.prop(view, "show_region_toolbar")
996         layout.prop(view, "show_region_ui")
997         layout.prop(view, "show_region_tool_header")
998         layout.prop(view, "show_region_hud")
999
1000         layout.separator()
1001
1002         layout.operator("view3d.view_selected", text="Frame Selected").use_all_regions = False
1003         if view.region_quadviews:
1004             layout.operator("view3d.view_selected", text="Frame Selected (Quad View)").use_all_regions = True
1005
1006         layout.operator("view3d.view_all", text="Frame All").center = False
1007         layout.operator("view3d.view_persportho", text="Perspective/Orthographic")
1008         layout.menu("VIEW3D_MT_view_local")
1009
1010         layout.separator()
1011
1012         layout.menu("VIEW3D_MT_view_cameras", text="Cameras")
1013
1014         layout.separator()
1015         layout.menu("VIEW3D_MT_view_viewpoint")
1016         layout.menu("VIEW3D_MT_view_navigation")
1017         layout.menu("VIEW3D_MT_view_align")
1018
1019         layout.separator()
1020
1021         layout.operator_context = 'INVOKE_REGION_WIN'
1022         layout.menu("VIEW3D_MT_view_regions", text="View Regions")
1023
1024         layout.separator()
1025
1026         layout.operator("screen.animation_play", text="Play Animation")
1027
1028         layout.separator()
1029
1030         layout.operator("render.opengl", text="Viewport Render Image", icon='RENDER_STILL')
1031         layout.operator("render.opengl", text="Viewport Render Animation", icon='RENDER_ANIMATION').animation = True
1032
1033         layout.separator()
1034
1035         layout.menu("INFO_MT_area")
1036
1037
1038 class VIEW3D_MT_view_local(Menu):
1039     bl_label = "Local View"
1040
1041     def draw(self, _context):
1042         layout = self.layout
1043
1044         layout.operator("view3d.localview", text="Toggle Local View")
1045         layout.operator("view3d.localview_remove_from")
1046
1047
1048 class VIEW3D_MT_view_cameras(Menu):
1049     bl_label = "Cameras"
1050
1051     def draw(self, _context):
1052         layout = self.layout
1053
1054         layout.operator("view3d.object_as_camera")
1055         layout.operator("view3d.view_camera", text="Active Camera")
1056
1057
1058 class VIEW3D_MT_view_viewpoint(Menu):
1059     bl_label = "Viewpoint"
1060
1061     def draw(self, _context):
1062         layout = self.layout
1063
1064         layout.operator("view3d.view_camera", text="Camera")
1065
1066         layout.separator()
1067
1068         layout.operator("view3d.view_axis", text="Top").type = 'TOP'
1069         layout.operator("view3d.view_axis", text="Bottom").type = 'BOTTOM'
1070
1071         layout.separator()
1072
1073         layout.operator("view3d.view_axis", text="Front").type = 'FRONT'
1074         layout.operator("view3d.view_axis", text="Back").type = 'BACK'
1075
1076         layout.separator()
1077
1078         layout.operator("view3d.view_axis", text="Right").type = 'RIGHT'
1079         layout.operator("view3d.view_axis", text="Left").type = 'LEFT'
1080
1081
1082 class VIEW3D_MT_view_navigation(Menu):
1083     bl_label = "Navigation"
1084
1085     def draw(self, _context):
1086         from math import pi
1087         layout = self.layout
1088
1089         layout.operator_enum("view3d.view_orbit", "type")
1090         props = layout.operator("view3d.view_orbit", text="Orbit Opposite")
1091         props.type = 'ORBITRIGHT'
1092         props.angle = pi
1093
1094         layout.separator()
1095
1096         layout.operator("view3d.view_roll", text="Roll Left").type = 'LEFT'
1097         layout.operator("view3d.view_roll", text="Roll Right").type = 'RIGHT'
1098
1099         layout.separator()
1100
1101         layout.operator_enum("view3d.view_pan", "type")
1102
1103         layout.separator()
1104
1105         layout.operator("view3d.zoom", text="Zoom In").delta = 1
1106         layout.operator("view3d.zoom", text="Zoom Out").delta = -1
1107         layout.operator("view3d.zoom_border", text="Zoom Border...")
1108         layout.operator("view3d.zoom_camera_1_to_1", text="Zoom Camera 1:1")
1109
1110         layout.separator()
1111
1112         layout.operator("view3d.fly")
1113         layout.operator("view3d.walk")
1114
1115
1116 class VIEW3D_MT_view_align(Menu):
1117     bl_label = "Align View"
1118
1119     def draw(self, _context):
1120         layout = self.layout
1121
1122         layout.menu("VIEW3D_MT_view_align_selected")
1123
1124         layout.separator()
1125
1126         layout.operator("view3d.camera_to_view", text="Align Active Camera to View")
1127         layout.operator("view3d.camera_to_view_selected", text="Align Active Camera to Selected")
1128
1129         layout.separator()
1130
1131         layout.operator("view3d.view_all", text="Center Cursor and View All").center = True
1132         layout.operator("view3d.view_center_cursor")
1133
1134         layout.separator()
1135
1136         layout.operator("view3d.view_lock_to_active")
1137         layout.operator("view3d.view_lock_clear")
1138
1139
1140 class VIEW3D_MT_view_align_selected(Menu):
1141     bl_label = "Align View to Active"
1142
1143     def draw(self, _context):
1144         layout = self.layout
1145
1146         props = layout.operator("view3d.view_axis", text="Top")
1147         props.align_active = True
1148         props.type = 'TOP'
1149
1150         props = layout.operator("view3d.view_axis", text="Bottom")
1151         props.align_active = True
1152         props.type = 'BOTTOM'
1153
1154         layout.separator()
1155
1156         props = layout.operator("view3d.view_axis", text="Front")
1157         props.align_active = True
1158         props.type = 'FRONT'
1159
1160         props = layout.operator("view3d.view_axis", text="Back")
1161         props.align_active = True
1162         props.type = 'BACK'
1163
1164         layout.separator()
1165
1166         props = layout.operator("view3d.view_axis", text="Right")
1167         props.align_active = True
1168         props.type = 'RIGHT'
1169
1170         props = layout.operator("view3d.view_axis", text="Left")
1171         props.align_active = True
1172         props.type = 'LEFT'
1173
1174
1175 class VIEW3D_MT_view_regions(Menu):
1176     bl_label = "View Regions"
1177
1178     def draw(self, _context):
1179         layout = self.layout
1180         layout.operator("view3d.clip_border", text="Clipping Region...")
1181         layout.operator("view3d.render_border", text="Render Region...")
1182
1183         layout.separator()
1184
1185         layout.operator("view3d.clear_render_border")
1186
1187
1188 # ********** Select menus, suffix from context.mode **********
1189
1190 class VIEW3D_MT_select_object_more_less(Menu):
1191     bl_label = "Select More/Less"
1192
1193     def draw(self, _context):
1194         layout = self.layout
1195
1196         layout = self.layout
1197
1198         layout.operator("object.select_more", text="More")
1199         layout.operator("object.select_less", text="Less")
1200
1201         layout.separator()
1202
1203         props = layout.operator("object.select_hierarchy", text="Parent")
1204         props.extend = False
1205         props.direction = 'PARENT'
1206
1207         props = layout.operator("object.select_hierarchy", text="Child")
1208         props.extend = False
1209         props.direction = 'CHILD'
1210
1211         layout.separator()
1212
1213         props = layout.operator("object.select_hierarchy", text="Extend Parent")
1214         props.extend = True
1215         props.direction = 'PARENT'
1216
1217         props = layout.operator("object.select_hierarchy", text="Extend Child")
1218         props.extend = True
1219         props.direction = 'CHILD'
1220
1221
1222 class VIEW3D_MT_select_object(Menu):
1223     bl_label = "Select"
1224
1225     def draw(self, _context):
1226         layout = self.layout
1227
1228         layout.operator("object.select_all", text="All").action = 'SELECT'
1229         layout.operator("object.select_all", text="None").action = 'DESELECT'
1230         layout.operator("object.select_all", text="Invert").action = 'INVERT'
1231
1232         layout.separator()
1233
1234         layout.operator("view3d.select_box")
1235         layout.operator("view3d.select_circle")
1236
1237         layout.separator()
1238
1239         layout.operator_menu_enum("object.select_by_type", "type", text="Select All by Type...")
1240         layout.operator("object.select_camera", text="Select Active Camera")
1241         layout.operator("object.select_mirror", text="Mirror Selection")
1242         layout.operator("object.select_random", text="Select Random")
1243
1244         layout.separator()
1245
1246         layout.menu("VIEW3D_MT_select_object_more_less")
1247
1248         layout.separator()
1249
1250         layout.operator_menu_enum("object.select_grouped", "type", text="Select Grouped")
1251         layout.operator_menu_enum("object.select_linked", "type", text="Select Linked")
1252         layout.operator("object.select_pattern", text="Select Pattern...")
1253
1254
1255 class VIEW3D_MT_select_pose_more_less(Menu):
1256     bl_label = "Select More/Less"
1257
1258     def draw(self, _context):
1259         layout = self.layout
1260
1261         layout = self.layout
1262
1263         props = layout.operator("pose.select_hierarchy", text="Parent")
1264         props.extend = False
1265         props.direction = 'PARENT'
1266
1267         props = layout.operator("pose.select_hierarchy", text="Child")
1268         props.extend = False
1269         props.direction = 'CHILD'
1270
1271         layout.separator()
1272
1273         props = layout.operator("pose.select_hierarchy", text="Extend Parent")
1274         props.extend = True
1275         props.direction = 'PARENT'
1276
1277         props = layout.operator("pose.select_hierarchy", text="Extend Child")
1278         props.extend = True
1279         props.direction = 'CHILD'
1280
1281
1282 class VIEW3D_MT_select_pose(Menu):
1283     bl_label = "Select"
1284
1285     def draw(self, _context):
1286         layout = self.layout
1287
1288         layout.operator("pose.select_all", text="All").action = 'SELECT'
1289         layout.operator("pose.select_all", text="None").action = 'DESELECT'
1290         layout.operator("pose.select_all", text="Invert").action = 'INVERT'
1291
1292         layout.separator()
1293
1294         layout.operator("view3d.select_box")
1295         layout.operator("view3d.select_circle")
1296
1297         layout.separator()
1298
1299         layout.operator("pose.select_mirror", text="Flip Active")
1300
1301         layout.separator()
1302
1303         layout.operator("pose.select_constraint_target", text="Constraint Target")
1304         layout.operator("pose.select_linked", text="Linked")
1305
1306         layout.separator()
1307
1308         layout.menu("VIEW3D_MT_select_pose_more_less")
1309
1310         layout.separator()
1311
1312         layout.operator_menu_enum("pose.select_grouped", "type", text="Grouped")
1313         layout.operator("object.select_pattern", text="Select Pattern...")
1314
1315
1316 class VIEW3D_MT_select_particle(Menu):
1317     bl_label = "Select"
1318
1319     def draw(self, _context):
1320         layout = self.layout
1321
1322         layout.operator("particle.select_all", text="All").action = 'SELECT'
1323         layout.operator("particle.select_all", text="None").action = 'DESELECT'
1324         layout.operator("particle.select_all", text="Invert").action = 'INVERT'
1325
1326         layout.separator()
1327
1328         layout.operator("view3d.select_box")
1329         layout.operator("view3d.select_circle")
1330
1331         layout.separator()
1332
1333         layout.operator("particle.select_linked")
1334
1335         layout.separator()
1336
1337         layout.operator("particle.select_more")
1338         layout.operator("particle.select_less")
1339
1340         layout.separator()
1341
1342         layout.operator("particle.select_random")
1343
1344         layout.separator()
1345
1346         layout.operator("particle.select_roots", text="Roots")
1347         layout.operator("particle.select_tips", text="Tips")
1348
1349
1350 class VIEW3D_MT_edit_mesh_select_similar(Menu):
1351     bl_label = "Select Similar"
1352
1353     def draw(self, _context):
1354         layout = self.layout
1355
1356         layout.operator_enum("mesh.select_similar", "type")
1357
1358         layout.separator()
1359
1360         layout.operator("mesh.select_similar_region", text="Face Regions")
1361
1362
1363 class VIEW3D_MT_edit_mesh_select_by_trait(Menu):
1364     bl_label = "Select All by Trait"
1365
1366     def draw(self, context):
1367         layout = self.layout
1368         tool_settings = context.tool_settings
1369         if tool_settings.mesh_select_mode[2] is False:
1370             layout.operator("mesh.select_non_manifold", text="Non Manifold")
1371         layout.operator("mesh.select_loose", text="Loose Geometry")
1372         layout.operator("mesh.select_interior_faces", text="Interior Faces")
1373         layout.operator("mesh.select_face_by_sides", text="Faces by Sides")
1374
1375         layout.separator()
1376
1377         layout.operator("mesh.select_ungrouped", text="Ungrouped Verts")
1378
1379
1380 class VIEW3D_MT_edit_mesh_select_more_less(Menu):
1381     bl_label = "Select More/Less"
1382
1383     def draw(self, _context):
1384         layout = self.layout
1385
1386         layout.operator("mesh.select_more", text="More")
1387         layout.operator("mesh.select_less", text="Less")
1388
1389         layout.separator()
1390
1391         layout.operator("mesh.select_next_item", text="Next Active")
1392         layout.operator("mesh.select_prev_item", text="Previous Active")
1393
1394
1395 class VIEW3D_MT_edit_mesh_select_linked(Menu):
1396     bl_label = "Select Linked"
1397
1398     def draw(self, _context):
1399         layout = self.layout
1400
1401         layout.operator("mesh.select_linked", text="Linked")
1402         layout.operator("mesh.shortest_path_select", text="Shortest Path")
1403         layout.operator("mesh.faces_select_linked_flat", text="Linked Flat Faces")
1404
1405
1406 class VIEW3D_MT_edit_mesh_select_loops(Menu):
1407     bl_label = "Select Loops"
1408
1409     def draw(self, _context):
1410         layout = self.layout
1411
1412         layout.operator("mesh.loop_multi_select", text="Edge Loops").ring = False
1413         layout.operator("mesh.loop_multi_select", text="Edge Rings").ring = True
1414
1415         layout.separator()
1416
1417         layout.operator("mesh.loop_to_region")
1418         layout.operator("mesh.region_to_loop")
1419
1420
1421 class VIEW3D_MT_select_edit_mesh(Menu):
1422     bl_label = "Select"
1423
1424     def draw(self, _context):
1425         layout = self.layout
1426
1427         # primitive
1428         layout.operator("mesh.select_all", text="All").action = 'SELECT'
1429         layout.operator("mesh.select_all", text="None").action = 'DESELECT'
1430         layout.operator("mesh.select_all", text="Invert").action = 'INVERT'
1431
1432         layout.separator()
1433
1434         layout.operator("view3d.select_box")
1435         layout.operator("view3d.select_circle")
1436
1437         layout.separator()
1438
1439         # numeric
1440         layout.operator("mesh.select_random", text="Select Random")
1441         layout.operator("mesh.select_nth")
1442
1443         layout.separator()
1444
1445         # geometric
1446         layout.operator("mesh.edges_select_sharp", text="Select Sharp Edges")
1447
1448         layout.separator()
1449
1450         # other ...
1451         layout.menu("VIEW3D_MT_edit_mesh_select_similar")
1452
1453         layout.separator()
1454
1455         layout.menu("VIEW3D_MT_edit_mesh_select_by_trait")
1456
1457         layout.separator()
1458
1459         layout.menu("VIEW3D_MT_edit_mesh_select_more_less")
1460
1461         layout.separator()
1462
1463         layout.menu("VIEW3D_MT_edit_mesh_select_loops")
1464
1465         layout.separator()
1466
1467         layout.menu("VIEW3D_MT_edit_mesh_select_linked")
1468
1469         layout.separator()
1470
1471         layout.operator("mesh.select_axis", text="Side of Active")
1472         layout.operator("mesh.select_mirror", text="Mirror Selection")
1473
1474
1475 class VIEW3D_MT_select_edit_curve(Menu):
1476     bl_label = "Select"
1477
1478     def draw(self, _context):
1479         layout = self.layout
1480
1481         layout.operator("curve.select_all", text="All").action = 'SELECT'
1482         layout.operator("curve.select_all", text="None").action = 'DESELECT'
1483         layout.operator("curve.select_all", text="Invert").action = 'INVERT'
1484
1485         layout.separator()
1486
1487         layout.operator("view3d.select_box")
1488         layout.operator("view3d.select_circle")
1489
1490         layout.separator()
1491
1492         layout.operator("curve.select_random")
1493         layout.operator("curve.select_nth")
1494         layout.operator("curve.select_linked", text="Select Linked")
1495         layout.operator("curve.select_similar", text="Select Similar")
1496
1497         layout.separator()
1498
1499         layout.operator("curve.de_select_first")
1500         layout.operator("curve.de_select_last")
1501         layout.operator("curve.select_next")
1502         layout.operator("curve.select_previous")
1503
1504         layout.separator()
1505
1506         layout.operator("curve.select_more")
1507         layout.operator("curve.select_less")
1508
1509
1510 class VIEW3D_MT_select_edit_surface(Menu):
1511     bl_label = "Select"
1512
1513     def draw(self, _context):
1514         layout = self.layout
1515
1516         layout.operator("curve.select_all", text="All").action = 'SELECT'
1517         layout.operator("curve.select_all", text="None").action = 'DESELECT'
1518         layout.operator("curve.select_all", text="Invert").action = 'INVERT'
1519
1520         layout.separator()
1521
1522         layout.operator("view3d.select_box")
1523         layout.operator("view3d.select_circle")
1524
1525         layout.separator()
1526
1527         layout.operator("curve.select_random")
1528         layout.operator("curve.select_nth")
1529         layout.operator("curve.select_linked", text="Select Linked")
1530         layout.operator("curve.select_similar", text="Select Similar")
1531
1532         layout.separator()
1533
1534         layout.operator("curve.select_row")
1535
1536         layout.separator()
1537
1538         layout.operator("curve.select_more")
1539         layout.operator("curve.select_less")
1540
1541
1542 class VIEW3D_MT_edit_text_context_menu(Menu):
1543     bl_label = "Text Context Menu"
1544
1545     def draw(self, _context):
1546         layout = self.layout
1547
1548         layout.operator_context = 'INVOKE_DEFAULT'
1549
1550         layout.operator("font.text_cut", text="Cut")
1551         layout.operator("font.text_copy", text="Copy", icon='COPYDOWN')
1552         layout.operator("font.text_paste", text="Paste", icon='PASTEDOWN')
1553
1554         layout.separator()
1555
1556         layout.operator("font.select_all")
1557
1558         layout.separator()
1559
1560         layout.menu("VIEW3D_MT_edit_font")
1561
1562
1563 class VIEW3D_MT_select_edit_text(Menu):
1564     # intentional name mismatch
1565     # select menu for 3d-text doesn't make sense
1566     bl_label = "Edit"
1567
1568     def draw(self, _context):
1569         layout = self.layout
1570
1571         layout.operator("ed.undo")
1572         layout.operator("ed.redo")
1573
1574         layout.separator()
1575
1576         layout.operator("font.text_cut", text="Cut")
1577         layout.operator("font.text_copy", text="Copy", icon='COPYDOWN')
1578         layout.operator("font.text_paste", text="Paste", icon='PASTEDOWN')
1579
1580         layout.separator()
1581
1582         layout.operator("font.text_paste_from_file")
1583
1584         layout.separator()
1585
1586         layout.operator("font.select_all")
1587
1588         layout.separator()
1589
1590         layout.menu("VIEW3D_MT_edit_text_chars")
1591
1592
1593 class VIEW3D_MT_select_edit_metaball(Menu):
1594     bl_label = "Select"
1595
1596     def draw(self, _context):
1597         layout = self.layout
1598
1599         layout.operator("mball.select_all", text="All").action = 'SELECT'
1600         layout.operator("mball.select_all", text="None").action = 'DESELECT'
1601         layout.operator("mball.select_all", text="Invert").action = 'INVERT'
1602
1603         layout.separator()
1604
1605         layout.operator("view3d.select_box")
1606         layout.operator("view3d.select_circle")
1607
1608         layout.separator()
1609
1610         layout.operator("mball.select_random_metaelems")
1611
1612         layout.separator()
1613
1614         layout.operator_menu_enum("mball.select_similar", "type", text="Similar")
1615
1616
1617 class VIEW3D_MT_edit_lattice_context_menu(Menu):
1618     bl_label = "Lattice Context Menu"
1619
1620     def draw(self, _context):
1621         layout = self.layout
1622
1623         layout = self.layout
1624
1625         layout.menu("VIEW3D_MT_mirror")
1626         layout.operator_menu_enum("lattice.flip", "axis")
1627         layout.menu("VIEW3D_MT_snap")
1628
1629         layout.separator()
1630
1631         layout.operator("lattice.make_regular")
1632
1633
1634 class VIEW3D_MT_select_edit_lattice(Menu):
1635     bl_label = "Select"
1636
1637     def draw(self, _context):
1638         layout = self.layout
1639
1640         layout.operator("lattice.select_all", text="All").action = 'SELECT'
1641         layout.operator("lattice.select_all", text="None").action = 'DESELECT'
1642         layout.operator("lattice.select_all", text="Invert").action = 'INVERT'
1643
1644         layout.separator()
1645
1646         layout.operator("view3d.select_box")
1647         layout.operator("view3d.select_circle")
1648
1649         layout.separator()
1650
1651         layout.operator("lattice.select_mirror")
1652         layout.operator("lattice.select_random")
1653
1654         layout.separator()
1655
1656         layout.operator("lattice.select_more")
1657         layout.operator("lattice.select_less")
1658
1659         layout.separator()
1660
1661         layout.operator("lattice.select_ungrouped", text="Ungrouped Verts")
1662
1663
1664 class VIEW3D_MT_select_edit_armature(Menu):
1665     bl_label = "Select"
1666
1667     def draw(self, _context):
1668         layout = self.layout
1669
1670         layout.operator("armature.select_all", text="All").action = 'SELECT'
1671         layout.operator("armature.select_all", text="None").action = 'DESELECT'
1672         layout.operator("armature.select_all", text="Invert").action = 'INVERT'
1673
1674         layout.separator()
1675
1676         layout.operator("view3d.select_box")
1677         layout.operator("view3d.select_circle")
1678
1679         layout.separator()
1680
1681         layout.operator("armature.select_mirror", text="Mirror").extend = False
1682
1683         layout.separator()
1684
1685         layout.operator("armature.select_more", text="More")
1686         layout.operator("armature.select_less", text="Less")
1687
1688         layout.separator()
1689
1690         props = layout.operator("armature.select_hierarchy", text="Parent")
1691         props.extend = False
1692         props.direction = 'PARENT'
1693
1694         props = layout.operator("armature.select_hierarchy", text="Child")
1695         props.extend = False
1696         props.direction = 'CHILD'
1697
1698         layout.separator()
1699
1700         props = layout.operator("armature.select_hierarchy", text="Extend Parent")
1701         props.extend = True
1702         props.direction = 'PARENT'
1703
1704         props = layout.operator("armature.select_hierarchy", text="Extend Child")
1705         props.extend = True
1706         props.direction = 'CHILD'
1707
1708         layout.operator_menu_enum("armature.select_similar", "type", text="Similar")
1709         layout.operator("object.select_pattern", text="Select Pattern...")
1710
1711
1712 class VIEW3D_MT_select_gpencil(Menu):
1713     bl_label = "Select"
1714
1715     def draw(self, _context):
1716         layout = self.layout
1717
1718         layout.operator("gpencil.select_all", text="All").action = 'SELECT'
1719         layout.operator("gpencil.select_all", text="None").action = 'DESELECT'
1720         layout.operator("gpencil.select_all", text="Invert").action = 'INVERT'
1721
1722         layout.separator()
1723
1724         layout.operator("gpencil.select_box")
1725         layout.operator("gpencil.select_circle")
1726
1727         layout.separator()
1728
1729         layout.operator("gpencil.select_linked", text="Linked")
1730         layout.operator("gpencil.select_alternate")
1731         layout.operator_menu_enum("gpencil.select_grouped", "type", text="Grouped")
1732
1733         layout.separator()
1734
1735         layout.operator("gpencil.select_first")
1736         layout.operator("gpencil.select_last")
1737
1738         layout.separator()
1739
1740         layout.operator("gpencil.select_more")
1741         layout.operator("gpencil.select_less")
1742
1743
1744 class VIEW3D_MT_select_paint_mask(Menu):
1745     bl_label = "Select"
1746
1747     def draw(self, _context):
1748         layout = self.layout
1749
1750         layout.operator("paint.face_select_all", text="All").action = 'SELECT'
1751         layout.operator("paint.face_select_all", text="None").action = 'DESELECT'
1752         layout.operator("paint.face_select_all", text="Invert").action = 'INVERT'
1753
1754         layout.separator()
1755
1756         layout.operator("view3d.select_box")
1757         layout.operator("view3d.select_circle")
1758
1759         layout.separator()
1760
1761         layout.operator("paint.face_select_linked", text="Linked")
1762
1763
1764 class VIEW3D_MT_select_paint_mask_vertex(Menu):
1765     bl_label = "Select"
1766
1767     def draw(self, _context):
1768         layout = self.layout
1769
1770         layout.operator("paint.vert_select_all", text="All").action = 'SELECT'
1771         layout.operator("paint.vert_select_all", text="None").action = 'DESELECT'
1772         layout.operator("paint.vert_select_all", text="Invert").action = 'INVERT'
1773
1774         layout.separator()
1775
1776         layout.operator("view3d.select_box")
1777         layout.operator("view3d.select_circle")
1778
1779         layout.separator()
1780
1781         layout.operator("paint.vert_select_ungrouped", text="Ungrouped Verts")
1782
1783
1784 class VIEW3D_MT_angle_control(Menu):
1785     bl_label = "Angle Control"
1786
1787     @classmethod
1788     def poll(cls, context):
1789         settings = UnifiedPaintPanel.paint_settings(context)
1790         if not settings:
1791             return False
1792
1793         brush = settings.brush
1794         tex_slot = brush.texture_slot
1795
1796         return tex_slot.has_texture_angle and tex_slot.has_texture_angle_source
1797
1798     def draw(self, context):
1799         layout = self.layout
1800
1801         settings = UnifiedPaintPanel.paint_settings(context)
1802         brush = settings.brush
1803
1804         sculpt = (context.sculpt_object is not None)
1805
1806         tex_slot = brush.texture_slot
1807
1808         layout.prop(tex_slot, "use_rake", text="Rake")
1809
1810         if brush.brush_capabilities.has_random_texture_angle and tex_slot.has_random_texture_angle:
1811             if sculpt:
1812                 if brush.sculpt_capabilities.has_random_texture_angle:
1813                     layout.prop(tex_slot, "use_random", text="Random")
1814             else:
1815                 layout.prop(tex_slot, "use_random", text="Random")
1816
1817
1818 class VIEW3D_MT_mesh_add(Menu):
1819     bl_idname = "VIEW3D_MT_mesh_add"
1820     bl_label = "Mesh"
1821
1822     def draw(self, _context):
1823         layout = self.layout
1824
1825         layout.operator_context = 'INVOKE_REGION_WIN'
1826
1827         layout.operator("mesh.primitive_plane_add", text="Plane", icon='MESH_PLANE')
1828         layout.operator("mesh.primitive_cube_add", text="Cube", icon='MESH_CUBE')
1829         layout.operator("mesh.primitive_circle_add", text="Circle", icon='MESH_CIRCLE')
1830         layout.operator("mesh.primitive_uv_sphere_add", text="UV Sphere", icon='MESH_UVSPHERE')
1831         layout.operator("mesh.primitive_ico_sphere_add", text="Ico Sphere", icon='MESH_ICOSPHERE')
1832         layout.operator("mesh.primitive_cylinder_add", text="Cylinder", icon='MESH_CYLINDER')
1833         layout.operator("mesh.primitive_cone_add", text="Cone", icon='MESH_CONE')
1834         layout.operator("mesh.primitive_torus_add", text="Torus", icon='MESH_TORUS')
1835
1836         layout.separator()
1837
1838         layout.operator("mesh.primitive_grid_add", text="Grid", icon='MESH_GRID')
1839         layout.operator("mesh.primitive_monkey_add", text="Monkey", icon='MESH_MONKEY')
1840
1841
1842 class VIEW3D_MT_curve_add(Menu):
1843     bl_idname = "VIEW3D_MT_curve_add"
1844     bl_label = "Curve"
1845
1846     def draw(self, _context):
1847         layout = self.layout
1848
1849         layout.operator_context = 'INVOKE_REGION_WIN'
1850
1851         layout.operator("curve.primitive_bezier_curve_add", text="Bezier", icon='CURVE_BEZCURVE')
1852         layout.operator("curve.primitive_bezier_circle_add", text="Circle", icon='CURVE_BEZCIRCLE')
1853
1854         layout.separator()
1855
1856         layout.operator("curve.primitive_nurbs_curve_add", text="Nurbs Curve", icon='CURVE_NCURVE')
1857         layout.operator("curve.primitive_nurbs_circle_add", text="Nurbs Circle", icon='CURVE_NCIRCLE')
1858         layout.operator("curve.primitive_nurbs_path_add", text="Path", icon='CURVE_PATH')
1859
1860
1861 class VIEW3D_MT_surface_add(Menu):
1862     bl_idname = "VIEW3D_MT_surface_add"
1863     bl_label = "Surface"
1864
1865     def draw(self, _context):
1866         layout = self.layout
1867
1868         layout.operator_context = 'INVOKE_REGION_WIN'
1869
1870         layout.operator("surface.primitive_nurbs_surface_curve_add", text="Nurbs Curve", icon='SURFACE_NCURVE')
1871         layout.operator("surface.primitive_nurbs_surface_circle_add", text="Nurbs Circle", icon='SURFACE_NCIRCLE')
1872         layout.operator("surface.primitive_nurbs_surface_surface_add", text="Nurbs Surface", icon='SURFACE_NSURFACE')
1873         layout.operator("surface.primitive_nurbs_surface_cylinder_add",
1874                         text="Nurbs Cylinder", icon='SURFACE_NCYLINDER')
1875         layout.operator("surface.primitive_nurbs_surface_sphere_add", text="Nurbs Sphere", icon='SURFACE_NSPHERE')
1876         layout.operator("surface.primitive_nurbs_surface_torus_add", text="Nurbs Torus", icon='SURFACE_NTORUS')
1877
1878
1879 class VIEW3D_MT_edit_metaball_context_menu(Menu):
1880     bl_label = "Metaball Context Menu"
1881
1882     def draw(self, _context):
1883         layout = self.layout
1884
1885         layout.operator_context = 'INVOKE_REGION_WIN'
1886
1887         # Add
1888         layout.operator("mball.duplicate_move")
1889
1890         layout.separator()
1891
1892         # Modify
1893         layout.menu("VIEW3D_MT_mirror")
1894         layout.menu("VIEW3D_MT_snap")
1895
1896         layout.separator()
1897
1898         # Remove
1899         layout.operator_context = 'EXEC_DEFAULT'
1900         layout.operator("mball.delete_metaelems", text="Delete")
1901
1902
1903 class VIEW3D_MT_metaball_add(Menu):
1904     bl_idname = "VIEW3D_MT_metaball_add"
1905     bl_label = "Metaball"
1906
1907     def draw(self, _context):
1908         layout = self.layout
1909
1910         layout.operator_context = 'INVOKE_REGION_WIN'
1911         layout.operator_enum("object.metaball_add", "type")
1912
1913
1914 class TOPBAR_MT_edit_curve_add(Menu):
1915     bl_idname = "TOPBAR_MT_edit_curve_add"
1916     bl_label = "Add"
1917     bl_translation_context = i18n_contexts.operator_default
1918
1919     def draw(self, context):
1920         is_surf = context.active_object.type == 'SURFACE'
1921
1922         layout = self.layout
1923         layout.operator_context = 'EXEC_REGION_WIN'
1924
1925         if is_surf:
1926             VIEW3D_MT_surface_add.draw(self, context)
1927         else:
1928             VIEW3D_MT_curve_add.draw(self, context)
1929
1930
1931 class TOPBAR_MT_edit_armature_add(Menu):
1932     bl_idname = "TOPBAR_MT_edit_armature_add"
1933     bl_label = "Armature"
1934
1935     def draw(self, _context):
1936         layout = self.layout
1937
1938         layout.operator_context = 'EXEC_REGION_WIN'
1939         layout.operator("armature.bone_primitive_add", text="Single Bone", icon='BONE_DATA')
1940
1941
1942 class VIEW3D_MT_armature_add(Menu):
1943     bl_idname = "VIEW3D_MT_armature_add"
1944     bl_label = "Armature"
1945
1946     def draw(self, _context):
1947         layout = self.layout
1948
1949         layout.operator_context = 'EXEC_REGION_WIN'
1950         layout.operator("object.armature_add", text="Single Bone", icon='BONE_DATA')
1951
1952
1953 class VIEW3D_MT_light_add(Menu):
1954     bl_idname = "VIEW3D_MT_light_add"
1955     bl_label = "Light"
1956
1957     def draw(self, _context):
1958         layout = self.layout
1959
1960         layout.operator_context = 'INVOKE_REGION_WIN'
1961         layout.operator_enum("object.light_add", "type")
1962
1963
1964 class VIEW3D_MT_lightprobe_add(Menu):
1965     bl_idname = "VIEW3D_MT_lightprobe_add"
1966     bl_label = "Light Probe"
1967
1968     def draw(self, _context):
1969         layout = self.layout
1970
1971         layout.operator_context = 'INVOKE_REGION_WIN'
1972         layout.operator_enum("object.lightprobe_add", "type")
1973
1974
1975 class VIEW3D_MT_camera_add(Menu):
1976     bl_idname = "VIEW3D_MT_camera_add"
1977     bl_label = "Camera"
1978
1979     def draw(self, _context):
1980         layout = self.layout
1981         layout.operator_context = 'EXEC_REGION_WIN'
1982         layout.operator("object.camera_add", text="Camera", icon='OUTLINER_OB_CAMERA')
1983
1984
1985 class VIEW3D_MT_add(Menu):
1986     bl_label = "Add"
1987     bl_translation_context = i18n_contexts.operator_default
1988
1989     def draw(self, context):
1990         layout = self.layout
1991
1992         # note, don't use 'EXEC_SCREEN' or operators won't get the 'v3d' context.
1993
1994         # Note: was EXEC_AREA, but this context does not have the 'rv3d', which prevents
1995         #       "align_view" to work on first call (see [#32719]).
1996         layout.operator_context = 'EXEC_REGION_WIN'
1997
1998         # layout.operator_menu_enum("object.mesh_add", "type", text="Mesh", icon='OUTLINER_OB_MESH')
1999         layout.menu("VIEW3D_MT_mesh_add", icon='OUTLINER_OB_MESH')
2000
2001         # layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
2002         layout.menu("VIEW3D_MT_curve_add", icon='OUTLINER_OB_CURVE')
2003         # layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
2004         layout.menu("VIEW3D_MT_surface_add", icon='OUTLINER_OB_SURFACE')
2005         layout.menu("VIEW3D_MT_metaball_add", text="Metaball", icon='OUTLINER_OB_META')
2006         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
2007         layout.operator_menu_enum("object.gpencil_add", "type", text="Grease Pencil", icon='OUTLINER_OB_GREASEPENCIL')
2008
2009         layout.separator()
2010
2011         if VIEW3D_MT_armature_add.is_extended():
2012             layout.menu("VIEW3D_MT_armature_add", icon='OUTLINER_OB_ARMATURE')
2013         else:
2014             layout.operator("object.armature_add", text="Armature", icon='OUTLINER_OB_ARMATURE')
2015
2016         layout.operator("object.add", text="Lattice", icon='OUTLINER_OB_LATTICE').type = 'LATTICE'
2017
2018         layout.separator()
2019
2020         layout.operator_menu_enum("object.empty_add", "type", text="Empty", icon='OUTLINER_OB_EMPTY')
2021         layout.menu("VIEW3D_MT_image_add", text="Image", icon='OUTLINER_OB_IMAGE')
2022
2023         layout.separator()
2024
2025         layout.menu("VIEW3D_MT_light_add", icon='OUTLINER_OB_LIGHT')
2026         layout.menu("VIEW3D_MT_lightprobe_add", icon='OUTLINER_OB_LIGHTPROBE')
2027
2028         layout.separator()
2029
2030         if VIEW3D_MT_camera_add.is_extended():
2031             layout.menu("VIEW3D_MT_camera_add", icon='OUTLINER_OB_CAMERA')
2032         else:
2033             VIEW3D_MT_camera_add.draw(self, context)
2034
2035         layout.separator()
2036
2037         layout.operator("object.speaker_add", text="Speaker", icon='OUTLINER_OB_SPEAKER')
2038
2039         layout.separator()
2040
2041         layout.operator_menu_enum("object.effector_add", "type", text="Force Field", icon='OUTLINER_OB_FORCE_FIELD')
2042
2043         layout.separator()
2044
2045         has_collections = bool(bpy.data.collections)
2046         col = layout.column()
2047         col.enabled = has_collections
2048
2049         if not has_collections or len(bpy.data.collections) > 10:
2050             col.operator_context = 'INVOKE_REGION_WIN'
2051             col.operator(
2052                 "object.collection_instance_add",
2053                 text="Collection Instance..." if has_collections else "No Collections to Instance",
2054                 icon='OUTLINER_OB_GROUP_INSTANCE',
2055             )
2056         else:
2057             col.operator_menu_enum(
2058                 "object.collection_instance_add",
2059                 "collection",
2060                 text="Collection Instance",
2061                 icon='OUTLINER_OB_GROUP_INSTANCE',
2062             )
2063
2064
2065 class VIEW3D_MT_image_add(Menu):
2066     bl_label = "Add Image"
2067
2068     def draw(self, _context):
2069         layout = self.layout
2070         layout.operator("object.load_reference_image", text="Reference", icon='IMAGE_REFERENCE')
2071         layout.operator("object.load_background_image", text="Background", icon='IMAGE_BACKGROUND')
2072
2073
2074 class VIEW3D_MT_object_relations(Menu):
2075     bl_label = "Relations"
2076
2077     def draw(self, _context):
2078         layout = self.layout
2079
2080         layout.operator("object.proxy_make", text="Make Proxy...")
2081
2082         layout.operator("object.make_dupli_face")
2083
2084         layout.separator()
2085
2086         layout.operator_menu_enum("object.make_local", "type", text="Make Local...")
2087         layout.menu("VIEW3D_MT_make_single_user")
2088
2089         layout.separator()
2090
2091         layout.operator("object.data_transfer")
2092         layout.operator("object.datalayout_transfer")
2093
2094
2095 class VIEW3D_MT_object(Menu):
2096     bl_context = "objectmode"
2097     bl_label = "Object"
2098
2099     def draw(self, context):
2100         layout = self.layout
2101
2102         layout.menu("VIEW3D_MT_transform_object")
2103         layout.operator_menu_enum("object.origin_set", text="Set Origin", property="type")
2104         layout.menu("VIEW3D_MT_mirror")
2105         layout.menu("VIEW3D_MT_object_clear")
2106         layout.menu("VIEW3D_MT_object_apply")
2107         layout.menu("VIEW3D_MT_snap")
2108
2109         layout.separator()
2110
2111         layout.operator("object.duplicate_move")
2112         layout.operator("object.duplicate_move_linked")
2113         layout.operator("object.join")
2114
2115         layout.separator()
2116
2117         layout.operator("view3d.copybuffer", text="Copy Objects", icon='COPYDOWN')
2118         layout.operator("view3d.pastebuffer", text="Paste Objects", icon='PASTEDOWN')
2119
2120         layout.separator()
2121
2122         layout.menu("VIEW3D_MT_object_parent")
2123         layout.menu("VIEW3D_MT_object_collection")
2124         layout.menu("VIEW3D_MT_object_relations")
2125         layout.menu("VIEW3D_MT_object_constraints")
2126         layout.menu("VIEW3D_MT_object_track")
2127         layout.menu("VIEW3D_MT_make_links", text="Make Links")
2128
2129         layout.separator()
2130
2131         layout.operator("object.shade_smooth")
2132         layout.operator("object.shade_flat")
2133
2134         layout.separator()
2135
2136         layout.menu("VIEW3D_MT_object_animation")
2137         layout.menu("VIEW3D_MT_object_rigid_body")
2138
2139         layout.separator()
2140
2141         layout.menu("VIEW3D_MT_object_quick_effects")
2142
2143         layout.separator()
2144
2145         ob = context.active_object
2146         if ob and ob.type == 'GPENCIL' and context.gpencil_data:
2147             layout.operator_menu_enum("gpencil.convert", "type", text="Convert to")
2148         else:
2149             layout.operator_menu_enum("object.convert", "target")
2150
2151         layout.separator()
2152
2153         layout.menu("VIEW3D_MT_object_showhide")
2154
2155         layout.separator()
2156
2157         layout.operator_context = 'EXEC_DEFAULT'
2158         layout.operator("object.delete", text="Delete").use_global = False
2159         layout.operator("object.delete", text="Delete Global").use_global = True
2160
2161
2162 class VIEW3D_MT_object_animation(Menu):
2163     bl_label = "Animation"
2164
2165     def draw(self, _context):
2166         layout = self.layout
2167
2168         layout.operator("anim.keyframe_insert_menu", text="Insert Keyframe...")
2169         layout.operator("anim.keyframe_delete_v3d", text="Delete Keyframes...")
2170         layout.operator("anim.keyframe_clear_v3d", text="Clear Keyframes...")
2171         layout.operator("anim.keying_set_active_set", text="Change Keying Set...")
2172
2173         layout.separator()
2174
2175         layout.operator("nla.bake", text="Bake Action...")
2176
2177
2178 class VIEW3D_MT_object_rigid_body(Menu):
2179     bl_label = "Rigid Body"
2180
2181     def draw(self, _context):
2182         layout = self.layout
2183
2184         layout.operator("rigidbody.objects_add", text="Add Active").type = 'ACTIVE'
2185         layout.operator("rigidbody.objects_add", text="Add Passive").type = 'PASSIVE'
2186
2187         layout.separator()
2188
2189         layout.operator("rigidbody.objects_remove", text="Remove")
2190
2191         layout.separator()
2192
2193         layout.operator("rigidbody.shape_change", text="Change Shape")
2194         layout.operator("rigidbody.mass_calculate", text="Calculate Mass")
2195         layout.operator("rigidbody.object_settings_copy", text="Copy from Active")
2196         layout.operator("object.visual_transform_apply", text="Apply Transformation")
2197         layout.operator("rigidbody.bake_to_keyframes", text="Bake To Keyframes")
2198
2199         layout.separator()
2200
2201         layout.operator("rigidbody.connect", text="Connect")
2202
2203
2204 class VIEW3D_MT_object_clear(Menu):
2205     bl_label = "Clear"
2206
2207     def draw(self, _context):
2208         layout = self.layout
2209
2210         layout.operator("object.location_clear", text="Location").clear_delta = False
2211         layout.operator("object.rotation_clear", text="Rotation").clear_delta = False
2212         layout.operator("object.scale_clear", text="Scale").clear_delta = False
2213
2214         layout.separator()
2215
2216         layout.operator("object.origin_clear", text="Origin")
2217
2218
2219 class VIEW3D_MT_object_context_menu(Menu):
2220     bl_label = "Object Context Menu"
2221
2222     def draw(self, context):
2223
2224         layout = self.layout
2225         view = context.space_data
2226
2227         obj = context.object
2228         is_eevee = context.scene.render.engine == 'BLENDER_EEVEE'
2229
2230         selected_objects_len = len(context.selected_objects)
2231
2232         # If nothing is selected
2233         # (disabled for now until it can be made more useful).
2234         '''
2235         if selected_objects_len == 0:
2236
2237             layout.menu("VIEW3D_MT_add", text="Add", text_ctxt=i18n_contexts.operator_default)
2238             layout.operator("view3d.pastebuffer", text="Paste Objects", icon='PASTEDOWN')
2239
2240             return
2241         '''
2242
2243         # If something is selected
2244         if obj is not None and obj.type in {'MESH', 'CURVE', 'SURFACE'}:
2245             layout.operator("object.shade_smooth", text="Shade Smooth")
2246             layout.operator("object.shade_flat", text="Shade Flat")
2247
2248             layout.separator()
2249
2250         if obj is None:
2251             pass
2252         elif obj.type == 'MESH':
2253             layout.operator_context = 'INVOKE_REGION_WIN'
2254             layout.operator_menu_enum("object.origin_set", text="Set Origin", property="type")
2255
2256             layout.operator_context = 'INVOKE_DEFAULT'
2257             # If more than one object is selected
2258             if selected_objects_len > 1:
2259                 layout.operator("object.join")
2260
2261             layout.separator()
2262
2263         elif obj.type == 'CAMERA':
2264             layout.operator_context = 'INVOKE_REGION_WIN'
2265
2266             if obj.data.type == 'PERSP':
2267                 props = layout.operator("wm.context_modal_mouse", text="Camera Lens Angle")
2268                 props.data_path_iter = "selected_editable_objects"
2269                 props.data_path_item = "data.lens"
2270                 props.input_scale = 0.1
2271                 if obj.data.lens_unit == 'MILLIMETERS':
2272                     props.header_text = "Camera Lens Angle: %.1fmm"
2273                 else:
2274                     props.header_text = "Camera Lens Angle: %.1f\u00B0"
2275
2276             else:
2277                 props = layout.operator("wm.context_modal_mouse", text="Camera Lens Scale")
2278                 props.data_path_iter = "selected_editable_objects"
2279                 props.data_path_item = "data.ortho_scale"
2280                 props.input_scale = 0.01
2281                 props.header_text = "Camera Lens Scale: %.3f"
2282
2283             if not obj.data.dof.focus_object:
2284                 if view and view.camera == obj and view.region_3d.view_perspective == 'CAMERA':
2285                     props = layout.operator("ui.eyedropper_depth", text="DOF Distance (Pick)")
2286                 else:
2287                     props = layout.operator("wm.context_modal_mouse", text="DOF Distance")
2288                     props.data_path_iter = "selected_editable_objects"
2289                     props.data_path_item = "data.dof.focus_distance"
2290                     props.input_scale = 0.02
2291                     props.header_text = "DOF Distance: %.3f"
2292
2293             layout.separator()
2294
2295         elif obj.type in {'CURVE', 'FONT'}:
2296             layout.operator_context = 'INVOKE_REGION_WIN'
2297
2298             props = layout.operator("wm.context_modal_mouse", text="Extrude Size")
2299             props.data_path_iter = "selected_editable_objects"
2300             props.data_path_item = "data.extrude"
2301             props.input_scale = 0.01
2302             props.header_text = "Extrude Size: %.3f"
2303
2304             props = layout.operator("wm.context_modal_mouse", text="Width Size")
2305             props.data_path_iter = "selected_editable_objects"
2306             props.data_path_item = "data.offset"
2307             props.input_scale = 0.01
2308             props.header_text = "Width Size: %.3f"
2309
2310             layout.separator()
2311
2312             layout.operator("object.convert", text="Convert to Mesh").target = 'MESH'
2313             layout.operator_menu_enum("object.origin_set", text="Set Origin", property="type")
2314
2315             layout.separator()
2316
2317         elif obj.type == 'GPENCIL':
2318             layout.operator("gpencil.convert", text="Convert to Path").type = 'PATH'
2319             layout.operator("gpencil.convert", text="Convert to Bezier Curves").type = 'CURVE'
2320             layout.operator("gpencil.convert", text="Convert to Mesh").type = 'POLY'
2321
2322             layout.operator_menu_enum("object.origin_set", text="Set Origin", property="type")
2323
2324             layout.separator()
2325
2326         elif obj.type == 'EMPTY':
2327             layout.operator_context = 'INVOKE_REGION_WIN'
2328
2329             props = layout.operator("wm.context_modal_mouse", text="Empty Draw Size")
2330             props.data_path_iter = "selected_editable_objects"
2331             props.data_path_item = "empty_display_size"
2332             props.input_scale = 0.01
2333             props.header_text = "Empty Draw Size: %.3f"
2334
2335             layout.separator()
2336
2337         elif obj.type == 'LIGHT':
2338             light = obj.data
2339
2340             layout.operator_context = 'INVOKE_REGION_WIN'
2341
2342             props = layout.operator("wm.context_modal_mouse", text="Energy")
2343             props.data_path_iter = "selected_editable_objects"
2344             props.data_path_item = "data.energy"
2345             props.header_text = "Light Energy: %.3f"
2346
2347             if light.type == 'AREA':
2348                 props = layout.operator("wm.context_modal_mouse", text="Size X")
2349                 props.data_path_iter = "selected_editable_objects"
2350                 props.data_path_item = "data.size"
2351                 props.header_text = "Light Size X: %.3f"
2352
2353                 if light.shape in {'RECTANGLE', 'ELLIPSE'}:
2354                     props = layout.operator("wm.context_modal_mouse", text="Size Y")
2355                     props.data_path_iter = "selected_editable_objects"
2356                     props.data_path_item = "data.size_y"
2357                     props.header_text = "Light Size Y: %.3f"
2358
2359             elif light.type in {'SPOT', 'POINT'}:
2360                 props = layout.operator("wm.context_modal_mouse", text="Radius")
2361                 props.data_path_iter = "selected_editable_objects"
2362                 props.data_path_item = "data.shadow_soft_size"
2363                 props.header_text = "Light Radius: %.3f"
2364
2365             elif light.type == 'SUN':
2366                 props = layout.operator("wm.context_modal_mouse", text="Angle")
2367                 props.data_path_iter = "selected_editable_objects"
2368                 props.data_path_item = "data.angle"
2369                 props.header_text = "Light Angle: %.3f"
2370
2371             if light.type == 'SPOT':
2372                 layout.separator()
2373
2374                 props = layout.operator("wm.context_modal_mouse", text="Spot Size")
2375                 props.data_path_iter = "selected_editable_objects"
2376                 props.data_path_item = "data.spot_size"
2377                 props.input_scale = 0.01
2378                 props.header_text = "Spot Size: %.2f"
2379
2380                 props = layout.operator("wm.context_modal_mouse", text="Spot Blend")
2381                 props.data_path_iter = "selected_editable_objects"
2382                 props.data_path_item = "data.spot_blend"
2383                 props.input_scale = -0.01
2384                 props.header_text = "Spot Blend: %.2f"
2385
2386             layout.separator()
2387
2388         layout.operator("view3d.copybuffer", text="Copy Objects", icon='COPYDOWN')
2389         layout.operator("view3d.pastebuffer", text="Paste Objects", icon='PASTEDOWN')
2390
2391         layout.separator()
2392
2393         layout.operator("object.duplicate_move", icon='DUPLICATE')
2394         layout.operator("object.duplicate_move_linked")
2395
2396         layout.separator()
2397
2398         props = layout.operator("wm.call_panel", text="Rename Active Object...")
2399         props.name = "TOPBAR_PT_name"
2400         props.keep_open = False
2401
2402         layout.separator()
2403
2404         layout.menu("VIEW3D_MT_mirror")
2405         layout.menu("VIEW3D_MT_snap")
2406         layout.menu("VIEW3D_MT_object_parent")
2407         layout.operator_context = 'INVOKE_REGION_WIN'
2408
2409         if view and view.local_view:
2410             layout.operator("view3d.localview_remove_from")
2411         else:
2412             layout.operator("object.move_to_collection")
2413
2414         layout.separator()
2415
2416         layout.operator("anim.keyframe_insert_menu", text="Insert Keyframe...")
2417
2418         layout.separator()
2419
2420         layout.operator_context = 'EXEC_DEFAULT'
2421         layout.operator("object.delete", text="Delete").use_global = False
2422
2423
2424 class VIEW3D_MT_object_shading(Menu):
2425     # XXX, this menu is a place to store shading operator in object mode
2426     bl_label = "Shading"
2427
2428     def draw(self, _context):
2429         layout = self.layout
2430         layout.operator("object.shade_smooth", text="Smooth")
2431         layout.operator("object.shade_flat", text="Flat")
2432
2433
2434 class VIEW3D_MT_object_apply(Menu):
2435     bl_label = "Apply"
2436
2437     def draw(self, _context):
2438         layout = self.layout
2439
2440         props = layout.operator("object.transform_apply", text="Location", text_ctxt=i18n_contexts.default)
2441         props.location, props.rotation, props.scale = True, False, False
2442
2443         props = layout.operator("object.transform_apply", text="Rotation", text_ctxt=i18n_contexts.default)
2444         props.location, props.rotation, props.scale = False, True, False
2445
2446         props = layout.operator("object.transform_apply", text="Scale", text_ctxt=i18n_contexts.default)
2447         props.location, props.rotation, props.scale = False, False, True
2448
2449         props = layout.operator("object.transform_apply", text="All Transforms", text_ctxt=i18n_contexts.default)
2450         props.location, props.rotation, props.scale = True, True, True
2451
2452         props = layout.operator("object.transform_apply", text="Rotation & Scale", text_ctxt=i18n_contexts.default)
2453         props.location, props.rotation, props.scale = False, True, True
2454
2455         layout.separator()
2456
2457         layout.operator(
2458             "object.transforms_to_deltas",
2459             text="Location to Deltas",
2460             text_ctxt=i18n_contexts.default,
2461         ).mode = 'LOC'
2462         layout.operator(
2463             "object.transforms_to_deltas",
2464             text="Rotation to Deltas",
2465             text_ctxt=i18n_contexts.default,
2466         ).mode = 'ROT'
2467         layout.operator(
2468             "object.transforms_to_deltas",
2469             text="Scale to Deltas",
2470             text_ctxt=i18n_contexts.default,
2471         ).mode = 'SCALE'
2472
2473         layout.operator(
2474             "object.transforms_to_deltas",
2475             text="All Transforms to Deltas",
2476             text_ctxt=i18n_contexts.default,
2477         ).mode = 'ALL'
2478         layout.operator("object.anim_transforms_to_deltas")
2479
2480         layout.separator()
2481
2482         layout.operator(
2483             "object.visual_transform_apply",
2484             text="Visual Transform",
2485             text_ctxt=i18n_contexts.default,
2486         )
2487         layout.operator(
2488             "object.convert",
2489             text="Visual Geometry to Mesh",
2490             text_ctxt=i18n_contexts.default,
2491         ).target = 'MESH'
2492         layout.operator("object.duplicates_make_real")
2493
2494
2495 class VIEW3D_MT_object_parent(Menu):
2496     bl_label = "Parent"
2497
2498     def draw(self, _context):
2499         layout = self.layout
2500
2501         layout.operator_enum("object.parent_set", "type")
2502
2503         layout.separator()
2504
2505         layout.operator_enum("object.parent_clear", "type")
2506
2507
2508 class VIEW3D_MT_object_track(Menu):
2509     bl_label = "Track"
2510
2511     def draw(self, _context):
2512         layout = self.layout
2513
2514         layout.operator_enum("object.track_set", "type")
2515
2516         layout.separator()
2517
2518         layout.operator_enum("object.track_clear", "type")
2519
2520
2521 class VIEW3D_MT_object_collection(Menu):
2522     bl_label = "Collection"
2523
2524     def draw(self, _context):
2525         layout = self.layout
2526
2527         layout.operator("object.move_to_collection")
2528         layout.operator("object.link_to_collection")
2529
2530         layout.separator()
2531
2532         layout.operator("collection.create")
2533         # layout.operator_menu_enum("collection.objects_remove", "collection")  # BUGGY
2534         layout.operator("collection.objects_remove")
2535         layout.operator("collection.objects_remove_all")
2536
2537         layout.separator()
2538
2539         layout.operator("collection.objects_add_active")
2540         layout.operator("collection.objects_remove_active")
2541
2542
2543 class VIEW3D_MT_object_constraints(Menu):
2544     bl_label = "Constraints"
2545
2546     def draw(self, _context):
2547         layout = self.layout
2548
2549         layout.operator("object.constraint_add_with_targets")
2550         layout.operator("object.constraints_copy")
2551
2552         layout.separator()
2553
2554         layout.operator("object.constraints_clear")
2555
2556
2557 class VIEW3D_MT_object_quick_effects(Menu):
2558     bl_label = "Quick Effects"
2559
2560     def draw(self, _context):
2561         layout = self.layout
2562
2563         layout.operator("object.quick_fur")
2564         layout.operator("object.quick_explode")
2565         layout.operator("object.quick_smoke")
2566         layout.operator("object.quick_fluid")
2567
2568
2569 class VIEW3D_MT_object_showhide(Menu):
2570     bl_label = "Show/Hide"
2571
2572     def draw(self, _context):
2573         layout = self.layout
2574
2575         layout.operator("object.hide_view_clear")
2576
2577         layout.separator()
2578
2579         layout.operator("object.hide_view_set", text="Hide Selected").unselected = False
2580         layout.operator("object.hide_view_set", text="Hide Unselected").unselected = True
2581
2582
2583 class VIEW3D_MT_make_single_user(Menu):
2584     bl_label = "Make Single User"
2585
2586     def draw(self, _context):
2587         layout = self.layout
2588
2589         props = layout.operator("object.make_single_user", text="Object")
2590         props.object = True
2591         props.obdata = props.material = props.animation = False
2592
2593         props = layout.operator("object.make_single_user", text="Object & Data")
2594         props.object = props.obdata = True
2595         props.material = props.animation = False
2596
2597         props = layout.operator("object.make_single_user", text="Object & Data & Materials")
2598         props.object = props.obdata = props.material = True
2599         props.animation = False
2600
2601         props = layout.operator("object.make_single_user", text="Materials")
2602         props.material = True
2603         props.object = props.obdata = props.animation = False
2604
2605         props = layout.operator("object.make_single_user", text="Object Animation")
2606         props.animation = True
2607         props.object = props.obdata = props.material = False
2608
2609
2610 class VIEW3D_MT_make_links(Menu):
2611     bl_label = "Make Links"
2612
2613     def draw(self, _context):
2614         layout = self.layout
2615         operator_context_default = layout.operator_context
2616
2617         if len(bpy.data.scenes) > 10:
2618             layout.operator_context = 'INVOKE_REGION_WIN'
2619             layout.operator("object.make_links_scene", text="Objects to Scene...", icon='OUTLINER_OB_EMPTY')
2620         else:
2621             layout.operator_context = 'EXEC_REGION_WIN'
2622             layout.operator_menu_enum("object.make_links_scene", "scene", text="Objects to Scene")
2623
2624         layout.separator()
2625
2626         layout.operator_context = operator_context_default
2627
2628         layout.operator_enum("object.make_links_data", "type")  # inline
2629
2630         layout.operator("object.join_uvs")  # stupid place to add this!
2631
2632
2633 class VIEW3D_MT_brush(Menu):
2634     bl_label = "Brush"
2635
2636     def draw(self, context):
2637         layout = self.layout
2638
2639         tool_settings = context.tool_settings
2640         settings = UnifiedPaintPanel.paint_settings(context)
2641         brush = getattr(settings, "brush", None)
2642
2643         ups = tool_settings.unified_paint_settings
2644         layout.prop(ups, "use_unified_size", text="Unified Size")
2645         layout.prop(ups, "use_unified_strength", text="Unified Strength")
2646         if context.image_paint_object or context.vertex_paint_object:
2647             layout.prop(ups, "use_unified_color", text="Unified Color")
2648         layout.separator()
2649
2650         # skip if no active brush
2651         if not brush:
2652             layout.label(text="No Brushes currently available", icon='INFO')
2653             return
2654
2655         # brush paint modes
2656         layout.menu("VIEW3D_MT_brush_paint_modes")
2657
2658         # brush tool
2659         if context.sculpt_object:
2660             layout.operator("brush.reset")
2661             layout.prop_menu_enum(brush, "sculpt_tool")
2662         elif context.image_paint_object:
2663             layout.prop_menu_enum(brush, "image_tool")
2664         elif context.vertex_paint_object:
2665             layout.prop_menu_enum(brush, "vertex_tool")
2666         elif context.weight_paint_object:
2667             layout.prop_menu_enum(brush, "weight_tool")
2668
2669         # TODO: still missing a lot of brush options here
2670
2671         # sculpt options
2672         if context.sculpt_object:
2673
2674             sculpt_tool = brush.sculpt_tool
2675
2676             layout.separator()
2677             layout.operator_menu_enum("brush.curve_preset", "shape", text="Curve Preset")
2678             layout.separator()
2679
2680             if sculpt_tool != 'GRAB':
2681                 layout.prop_menu_enum(brush, "stroke_method")
2682
2683                 if sculpt_tool in {'DRAW', 'PINCH', 'INFLATE', 'LAYER', 'CLAY'}:
2684                     layout.prop_menu_enum(brush, "direction")
2685
2686                 if sculpt_tool == 'LAYER':
2687                     layout.prop(brush, "use_persistent")
2688                     layout.operator("sculpt.set_persistent_base")
2689
2690
2691 class VIEW3D_MT_brush_paint_modes(Menu):
2692     bl_label = "Enabled Modes"
2693
2694     def draw(self, context):
2695         layout = self.layout
2696
2697         settings = UnifiedPaintPanel.paint_settings(context)
2698         brush = settings.brush
2699
2700         layout.prop(brush, "use_paint_sculpt", text="Sculpt")
2701         layout.prop(brush, "use_paint_uv_sculpt", text="UV Sculpt")
2702         layout.prop(brush, "use_paint_vertex", text="Vertex Paint")
2703         layout.prop(brush, "use_paint_weight", text="Weight Paint")
2704         layout.prop(brush, "use_paint_image", text="Texture Paint")
2705
2706
2707 class VIEW3D_MT_paint_vertex(Menu):
2708     bl_label = "Paint"
2709
2710     def draw(self, _context):
2711         layout = self.layout
2712
2713         layout.operator("paint.vertex_color_set")
2714         layout.operator("paint.vertex_color_smooth")
2715         layout.operator("paint.vertex_color_dirt")
2716         layout.operator("paint.vertex_color_from_weight")
2717
2718         layout.separator()
2719
2720         layout.operator("paint.vertex_color_invert", text="Invert")
2721         layout.operator("paint.vertex_color_levels", text="Levels")
2722         layout.operator("paint.vertex_color_hsv", text="Hue Saturation Value")
2723         layout.operator("paint.vertex_color_brightness_contrast", text="Bright/Contrast")
2724
2725
2726 class VIEW3D_MT_hook(Menu):
2727     bl_label = "Hooks"
2728
2729     def draw(self, context):
2730         layout = self.layout
2731         layout.operator_context = 'EXEC_AREA'
2732         layout.operator("object.hook_add_newob")
2733         layout.operator("object.hook_add_selob").use_bone = False
2734         layout.operator("object.hook_add_selob", text="Hook to Selected Object Bone").use_bone = True
2735
2736         if [mod.type == 'HOOK' for mod in context.active_object.modifiers]:
2737             layout.separator()
2738
2739             layout.operator_menu_enum("object.hook_assign", "modifier")
2740             layout.operator_menu_enum("object.hook_remove", "modifier")
2741
2742             layout.separator()
2743
2744             layout.operator_menu_enum("object.hook_select", "modifier")
2745             layout.operator_menu_enum("object.hook_reset", "modifier")
2746             layout.operator_menu_enum("object.hook_recenter", "modifier")
2747
2748
2749 class VIEW3D_MT_vertex_group(Menu):
2750     bl_label = "Vertex Groups"
2751
2752     def draw(self, context):
2753         layout = self.layout
2754
2755         layout.operator_context = 'EXEC_AREA'
2756         layout.operator("object.vertex_group_assign_new")
2757
2758         ob = context.active_object
2759         if ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex):
2760             if ob.vertex_groups.active:
2761                 layout.separator()
2762
2763                 layout.operator("object.vertex_group_assign", text="Assign to Active Group")
2764                 layout.operator(
2765                     "object.vertex_group_remove_from",
2766                     text="Remove from Active Group",
2767                 ).use_all_groups = False
2768                 layout.operator("object.vertex_group_remove_from", text="Remove from All").use_all_groups = True
2769
2770         if ob.vertex_groups.active:
2771             layout.separator()
2772
2773             layout.operator_menu_enum("object.vertex_group_set_active", "group", text="Set Active Group")
2774             layout.operator("object.vertex_group_remove", text="Remove Active Group").all = False
2775             layout.operator("object.vertex_group_remove", text="Remove All Groups").all = True
2776
2777
2778 class VIEW3D_MT_paint_weight(Menu):
2779     bl_label = "Weights"
2780
2781     @staticmethod
2782     def draw_generic(layout, is_editmode=False):
2783
2784         if not is_editmode:
2785
2786             layout.operator("paint.weight_from_bones", text="Assign Automatic From Bones").type = 'AUTOMATIC'
2787             layout.operator("paint.weight_from_bones", text="Assign From Bone Envelopes").type = 'ENVELOPES'
2788
2789             layout.separator()
2790
2791         layout.operator("object.vertex_group_normalize_all", text="Normalize All")
2792         layout.operator("object.vertex_group_normalize", text="Normalize")
2793
2794         layout.separator()
2795
2796         layout.operator("object.vertex_group_mirror", text="Mirror")
2797         layout.operator("object.vertex_group_invert", text="Invert")
2798         layout.operator("object.vertex_group_clean", text="Clean")
2799
2800         layout.separator()
2801
2802         layout.operator("object.vertex_group_quantize", text="Quantize")
2803         layout.operator("object.vertex_group_levels", text="Levels")
2804         layout.operator("object.vertex_group_smooth", text="Smooth")
2805
2806         if not is_editmode:
2807             props = layout.operator("object.data_transfer", text="Transfer Weights")
2808             props.use_reverse_transfer = True
2809             props.data_type = 'VGROUP_WEIGHTS'
2810
2811         layout.operator("object.vertex_group_limit_total", text="Limit Total")
2812         layout.operator("object.vertex_group_fix", text="Fix Deforms")
2813
2814         if not is_editmode:
2815             layout.separator()
2816
2817             layout.operator("paint.weight_set")
2818
2819     def draw(self, _context):
2820         self.draw_generic(self.layout, is_editmode=False)
2821
2822
2823 class VIEW3D_MT_sculpt(Menu):
2824     bl_label = "Sculpt"
2825
2826     def draw(self, context):
2827         layout = self.layout
2828
2829         tool_settings = context.tool_settings
2830         sculpt = tool_settings.sculpt
2831
2832         layout.operator("sculpt.dynamic_topology_toggle", text="Toggle Dynamic Topology")
2833
2834         layout.separator()
2835
2836         layout.prop(sculpt, "use_symmetry_x")
2837         layout.prop(sculpt, "use_symmetry_y")
2838         layout.prop(sculpt, "use_symmetry_z")
2839
2840         layout.separator()
2841
2842         layout.prop(sculpt, "lock_x")
2843         layout.prop(sculpt, "lock_y")
2844         layout.prop(sculpt, "lock_z")
2845
2846         layout.separator()
2847
2848         layout.prop(sculpt, "use_threaded", text="Threaded Sculpt")
2849         layout.prop(sculpt, "show_low_resolution")
2850         layout.prop(sculpt, "show_brush")
2851         layout.prop(sculpt, "use_deform_only")
2852         layout.prop(sculpt, "show_diffuse_color")
2853         layout.prop(sculpt, "show_mask")
2854
2855
2856 class VIEW3D_MT_hide_mask(Menu):
2857     bl_label = "Hide/Mask"
2858
2859     def draw(self, _context):
2860         layout = self.layout
2861
2862         props = layout.operator("paint.hide_show", text="Show All")
2863         props.action = 'SHOW'
2864         props.area = 'ALL'
2865
2866         props = layout.operator("paint.hide_show", text="Hide Bounding Box")
2867         props.action = 'HIDE'
2868         props.area = 'INSIDE'
2869
2870         props = layout.operator("paint.hide_show", text="Show Bounding Box")
2871         props.action = 'SHOW'
2872         props.area = 'INSIDE'
2873
2874         props = layout.operator("paint.hide_show", text="Hide Masked")
2875         props.area = 'MASKED'
2876         props.action = 'HIDE'
2877
2878         layout.separator()
2879
2880         props = layout.operator("paint.mask_flood_fill", text="Invert Mask")
2881         props.mode = 'INVERT'
2882
2883         props = layout.operator("paint.mask_flood_fill", text="Fill Mask")
2884         props.mode = 'VALUE'
2885         props.value = 1
2886
2887         props = layout.operator("paint.mask_flood_fill", text="Clear Mask")
2888         props.mode = 'VALUE'
2889         props.value = 0
2890
2891         props = layout.operator("view3d.select_box", text="Box Mask")
2892         props = layout.operator("paint.mask_lasso_gesture", text="Lasso Mask")
2893
2894
2895 class VIEW3D_MT_particle(Menu):
2896     bl_label = "Particle"
2897
2898     def draw(self, context):
2899         layout = self.layout
2900         tool_settings = context.tool_settings
2901
2902         particle_edit = tool_settings.particle_edit
2903
2904         layout.operator("particle.mirror")
2905
2906         layout.operator("particle.remove_doubles")
2907
2908         layout.separator()
2909
2910         if particle_edit.select_mode == 'POINT':
2911             layout.operator("particle.subdivide")
2912
2913         layout.operator("particle.unify_length")
2914         layout.operator("particle.rekey")
2915         layout.operator("particle.weight_set")
2916
2917         layout.separator()
2918
2919         layout.menu("VIEW3D_MT_particle_showhide")
2920
2921         layout.separator()
2922
2923         layout.operator("particle.delete")
2924
2925
2926 class VIEW3D_MT_particle_context_menu(Menu):
2927     bl_label = "Particle Context Menu"
2928
2929     def draw(self, context):
2930         layout = self.layout
2931         tool_settings = context.tool_settings
2932
2933         particle_edit = tool_settings.particle_edit
2934
2935         layout.operator("particle.rekey")
2936
2937         layout.separator()
2938
2939         layout.operator("particle.delete")
2940
2941         layout.separator()
2942
2943         layout.operator("particle.remove_doubles")
2944         layout.operator("particle.unify_length")
2945
2946         if particle_edit.select_mode == 'POINT':
2947             layout.operator("particle.subdivide")
2948
2949         layout.operator("particle.weight_set")
2950
2951         layout.separator()
2952
2953         layout.operator("particle.mirror")
2954
2955         if particle_edit.select_mode == 'POINT':
2956             layout.separator()
2957
2958             layout.operator("particle.select_all", text="All").action = 'SELECT'
2959             layout.operator("particle.select_all", text="None").action = 'DESELECT'
2960             layout.operator("particle.select_all", text="Invert").action = 'INVERT'
2961
2962             layout.separator()
2963
2964             layout.operator("particle.select_roots")
2965             layout.operator("particle.select_tips")
2966
2967             layout.separator()
2968
2969             layout.operator("particle.select_random")
2970
2971             layout.separator()
2972
2973             layout.operator("particle.select_more")
2974             layout.operator("particle.select_less")
2975
2976             layout.separator()
2977
2978             layout.operator("particle.select_linked")
2979
2980
2981 class VIEW3D_MT_particle_showhide(ShowHideMenu, Menu):
2982     _operator_name = "particle"
2983
2984
2985 class VIEW3D_MT_pose(Menu):
2986     bl_label = "Pose"
2987
2988     def draw(self, _context):
2989         layout = self.layout
2990
2991         layout.menu("VIEW3D_MT_transform_armature")
2992
2993         layout.menu("VIEW3D_MT_pose_transform")
2994         layout.menu("VIEW3D_MT_pose_apply")
2995
2996         layout.menu("VIEW3D_MT_snap")
2997
2998         layout.separator()
2999
3000         layout.menu("VIEW3D_MT_object_animation")
3001
3002         layout.separator()
3003
3004         layout.menu("VIEW3D_MT_pose_slide")
3005         layout.menu("VIEW3D_MT_pose_propagate")
3006
3007         layout.separator()
3008
3009         layout.operator("pose.copy", icon='COPYDOWN')
3010         layout.operator("pose.paste", icon='PASTEDOWN').flipped = False
3011         layout.operator("pose.paste", icon='PASTEFLIPDOWN', text="Paste Pose Flipped").flipped = True
3012
3013         layout.separator()
3014
3015         layout.menu("VIEW3D_MT_pose_library")
3016         layout.menu("VIEW3D_MT_pose_motion")
3017         layout.menu("VIEW3D_MT_pose_group")
3018
3019         layout.separator()
3020
3021         layout.menu("VIEW3D_MT_object_parent")
3022         layout.menu("VIEW3D_MT_pose_ik")
3023         layout.menu("VIEW3D_MT_pose_constraints")
3024
3025         layout.separator()
3026
3027         layout.operator_context = 'EXEC_AREA'
3028         layout.operator("pose.autoside_names", text="AutoName Left/Right").axis = 'XAXIS'
3029         layout.operator("pose.autoside_names", text="AutoName Front/Back").axis = 'YAXIS'
3030         layout.operator("pose.autoside_names", text="AutoName Top/Bottom").axis = 'ZAXIS'
3031
3032         layout.operator("pose.flip_names")
3033
3034         layout.operator("pose.quaternions_flip")
3035
3036         layout.separator()
3037
3038         layout.operator_context = 'INVOKE_AREA'
3039         layout.operator("armature.armature_layers", text="Change Armature Layers...")
3040         layout.operator("pose.bone_layers", text="Change Bone Layers...")
3041
3042         layout.separator()
3043
3044         layout.menu("VIEW3D_MT_pose_showhide")
3045         layout.menu("VIEW3D_MT_bone_options_toggle", text="Bone Settings")
3046
3047
3048 class VIEW3D_MT_pose_transform(Menu):
3049     bl_label = "Clear Transform"
3050
3051     def draw(self, _context):
3052         layout = self.layout
3053
3054         layout.operator("pose.transforms_clear", text="All")
3055
3056         layout.separator()
3057
3058         layout.operator("pose.loc_clear", text="Location")
3059         layout.operator("pose.rot_clear", text="Rotation")
3060         layout.operator("pose.scale_clear", text="Scale")
3061
3062         layout.separator()
3063
3064         layout.operator("pose.user_transforms_clear", text="Reset Unkeyed")
3065
3066
3067 class VIEW3D_MT_pose_slide(Menu):
3068     bl_label = "In-Betweens"
3069
3070     def draw(self, _context):
3071         layout = self.layout
3072
3073         layout.operator("pose.push_rest")
3074         layout.operator("pose.relax_rest")
3075         layout.operator("pose.push")
3076         layout.operator("pose.relax")
3077         layout.operator("pose.breakdown")
3078
3079
3080 class VIEW3D_MT_pose_propagate(Menu):
3081     bl_label = "Propagate"
3082
3083     def draw(self, _context):
3084         layout = self.layout
3085
3086         layout.operator("pose.propagate").mode = 'WHILE_HELD'
3087
3088         layout.separator()
3089
3090         layout.operator("pose.propagate", text="To Next Keyframe").mode = 'NEXT_KEY'
3091         layout.operator("pose.propagate", text="To Last Keyframe (Make Cyclic)").mode = 'LAST_KEY'
3092
3093         layout.separator()
3094
3095         layout.operator("pose.propagate", text="On Selected Keyframes").mode = 'SELECTED_KEYS'
3096
3097         layout.separator()
3098
3099         layout.operator("pose.propagate", text="On Selected Markers").mode = 'SELECTED_MARKERS'
3100
3101
3102 class VIEW3D_MT_pose_library(Menu):
3103     bl_label = "Pose Library"
3104
3105     def draw(self, _context):
3106         layout = self.layout
3107
3108         layout.operator("poselib.browse_interactive", text="Browse Poses...")
3109
3110         layout.separator()
3111
3112         layout.operator("poselib.pose_add", text="Add Pose...")
3113         layout.operator("poselib.pose_rename", text="Rename Pose...")
3114         layout.operator("poselib.pose_remove", text="Remove Pose...")
3115
3116
3117 class VIEW3D_MT_pose_motion(Menu):
3118     bl_label = "Motion Paths"
3119
3120     def draw(self, _context):
3121         layout = self.layout
3122
3123         layout.operator("pose.paths_calculate", text="Calculate")
3124         layout.operator("pose.paths_clear", text="Clear")
3125
3126
3127 class VIEW3D_MT_pose_group(Menu):
3128     bl_label = "Bone Groups"
3129
3130     def draw(self, context):
3131         layout = self.layout
3132
3133         pose = context.active_object.pose
3134
3135         layout.operator_context = 'EXEC_AREA'
3136         layout.operator("pose.group_assign", text="Assign to New Group").type = 0
3137
3138         if pose.bone_groups:
3139             active_group = pose.bone_groups.active_index + 1
3140             layout.operator("pose.group_assign", text="Assign to Group").type = active_group
3141
3142             layout.separator()
3143
3144             # layout.operator_context = 'INVOKE_AREA'
3145             layout.operator("pose.group_unassign")
3146             layout.operator("pose.group_remove")
3147
3148
3149 class VIEW3D_MT_pose_ik(Menu):
3150     bl_label = "Inverse Kinematics"
3151
3152     def draw(self, _context):
3153         layout = self.layout
3154
3155         layout.operator("pose.ik_add")
3156         layout.operator("pose.ik_clear")
3157
3158
3159 class VIEW3D_MT_pose_constraints(Menu):
3160     bl_label = "Constraints"
3161
3162     def draw(self, _context):
3163         layout = self.layout
3164
3165         layout.operator("pose.constraint_add_with_targets", text="Add (With Targets)...")
3166         layout.operator("pose.constraints_copy")
3167         layout.operator("pose.constraints_clear")
3168
3169
3170 class VIEW3D_MT_pose_showhide(ShowHideMenu, Menu):
3171     _operator_name = "pose"
3172
3173
3174 class VIEW3D_MT_pose_apply(Menu):
3175     bl_label = "Apply"
3176
3177     def draw(self, _context):
3178         layout = self.layout
3179
3180         layout.operator("pose.armature_apply").selected = False
3181         layout.operator("pose.armature_apply", text="Apply Selected as Rest Pose").selected = True
3182         layout.operator("pose.visual_transform_apply")
3183
3184         layout.separator()
3185
3186         props = layout.operator("object.assign_property_defaults")
3187         props.process_bones = True
3188
3189
3190 class VIEW3D_MT_pose_context_menu(Menu):
3191     bl_label = "Pose Context Menu"
3192
3193     def draw(self, _context):
3194         layout = self.layout
3195
3196         layout.operator_context = 'INVOKE_REGION_WIN'
3197
3198         layout.operator("anim.keyframe_insert_menu", text="Insert Keyframe...")
3199
3200         layout.separator()
3201
3202         layout.operator("pose.copy", icon='COPYDOWN')
3203         layout.operator("pose.paste", icon='PASTEDOWN').flipped = False
3204         layout.operator("pose.paste", icon='PASTEFLIPDOWN', text="Paste X-Flipped Pose").flipped = True
3205
3206         layout.separator()
3207
3208         props = layout.operator("wm.call_panel", text="Rename Active Bone...")
3209         props.name = "TOPBAR_PT_name"
3210         props.keep_open = False
3211
3212         layout.separator()
3213
3214         layout.operator("pose.paths_calculate", text="Calculate")
3215         layout.operator("pose.paths_clear", text="Clear")
3216
3217         layout.separator()
3218
3219         layout.operator("pose.push")
3220         layout.operator("pose.relax")
3221         layout.operator("pose.breakdown")
3222
3223         layout.separator()
3224
3225         layout.operator("pose.paths_calculate", text="Calculate Motion Paths")
3226         layout.operator("pose.paths_clear", text="Clear Motion Paths")
3227
3228         layout.separator()
3229
3230         layout.operator("pose.hide").unselected = False
3231         layout.operator("pose.reveal")
3232
3233         layout.separator()
3234
3235         layout.operator("pose.user_transforms_clear")
3236
3237
3238 class BoneOptions:
3239     def draw(self, context):
3240         layout = self.layout
3241
3242         options = [
3243             "show_wire",
3244             "use_deform",
3245             "use_envelope_multiply",
3246             "use_inherit_rotation",
3247             "use_inherit_scale",
3248         ]
3249
3250         if context.mode == 'EDIT_ARMATURE':
3251             bone_props = bpy.types.EditBone.bl_rna.properties
3252             data_path_iter = "selected_bones"
3253             opt_suffix = ""
3254             options.append("lock")
3255         else:  # pose-mode
3256             bone_props = bpy.types.Bone.bl_rna.properties
3257             data_path_iter = "selected_pose_bones"
3258             opt_suffix = "bone."
3259
3260         for opt in options:
3261             props = layout.operator("wm.context_collection_boolean_set", text=bone_props[opt].name,
3262                                     text_ctxt=i18n_contexts.default)
3263             props.data_path_iter = data_path_iter
3264             props.data_path_item = opt_suffix + opt
3265             props.type = self.type
3266
3267
3268 class VIEW3D_MT_bone_options_toggle(Menu, BoneOptions):
3269     bl_label = "Toggle Bone Options"
3270     type = 'TOGGLE'
3271
3272
3273 class VIEW3D_MT_bone_options_enable(Menu, BoneOptions):
3274     bl_label = "Enable Bone Options"
3275     type = 'ENABLE'
3276
3277
3278 class VIEW3D_MT_bone_options_disable(Menu, BoneOptions):
3279     bl_label = "Disable Bone Options"
3280     type = 'DISABLE'
3281
3282
3283 # ********** Edit Menus, suffix from ob.type **********
3284
3285
3286 class VIEW3D_MT_edit_mesh(Menu):
3287     bl_label = "Mesh"
3288
3289     def draw(self, _context):
3290         layout = self.layout
3291
3292         with_bullet = bpy.app.build_options.bullet
3293
3294         layout.menu("VIEW3D_MT_transform")
3295         layout.menu("VIEW3D_MT_mirror")
3296         layout.menu("VIEW3D_MT_snap")
3297
3298         layout.separator()
3299
3300         layout.operator("mesh.duplicate_move", text="Duplicate")
3301         layout.menu("VIEW3D_MT_edit_mesh_extrude")
3302         layout.operator("mesh.split")
3303         layout.operator("mesh.bisect")
3304         layout.operator("mesh.knife_project")
3305
3306         if with_bullet:
3307             layout.operator("mesh.convex_hull")
3308
3309         layout.separator()
3310
3311         layout.operator("mesh.symmetrize")
3312         layout.operator("mesh.symmetry_snap")
3313
3314         layout.separator()
3315
3316         layout.menu("VIEW3D_MT_edit_mesh_normals")
3317         layout.menu("VIEW3D_MT_edit_mesh_shading")
3318         layout.menu("VIEW3D_MT_edit_mesh_weights")
3319         layout.operator_menu_enum("mesh.sort_elements", "type", text="Sort Elements...")
3320
3321         layout.separator()
3322
3323         layout.menu("VIEW3D_MT_edit_mesh_showhide")
3324         layout.operator_menu_enum("mesh.separate", "type")
3325         layout.menu("VIEW3D_MT_edit_mesh_clean")
3326
3327         layout.separator()
3328
3329         layout.menu("VIEW3D_MT_edit_mesh_delete")
3330
3331
3332 class VIEW3D_MT_edit_mesh_context_menu(Menu):
3333     bl_label = ""
3334
3335     def draw(self, context):
3336
3337         def count_selected_items_for_objects_in_mode():
3338             selected_verts_len = 0
3339             selected_edges_len = 0
3340             selected_faces_len = 0
3341             for ob in context.objects_in_mode_unique_data:
3342                 v, e, f = ob.data.count_selected_items()
3343                 selected_verts_len += v
3344                 selected_edges_len += e
3345                 selected_faces_len += f
3346             return (selected_verts_len, selected_edges_len, selected_faces_len)
3347
3348         is_vert_mode, is_edge_mode, is_face_mode = context.tool_settings.mesh_select_mode
3349         selected_verts_len, selected_edges_len, selected_faces_len = count_selected_items_for_objects_in_mode()
3350
3351         del count_selected_items_for_objects_in_mode
3352
3353         layout = self.layout
3354
3355         layout.operator_context = 'INVOKE_REGION_WIN'
3356
3357         # If nothing is selected
3358         # (disabled for now until it can be made more useful).
3359         '''
3360         # If nothing is selected
3361         if not (selected_verts_len or selected_edges_len or selected_faces_len):
3362             layout.menu("VIEW3D_MT_mesh_add", text="Add", text_ctxt=i18n_contexts.operator_default)
3363
3364             return
3365         '''
3366
3367         # Else something is selected
3368
3369         row = layout.row()
3370
3371         if is_vert_mode:
3372             col = row.column()
3373
3374             col.label(text="Vertex Context Menu", icon='VERTEXSEL')
3375             col.separator()
3376
3377             # Additive Operators
3378             col.operator("mesh.subdivide", text="Subdivide")
3379
3380             col.separator()
3381
3382             col.operator("mesh.extrude_vertices_move", text="Extrude Vertices")
3383             col.operator("mesh.bevel", text="Bevel Vertices").vertex_only = True
3384
3385             if selected_verts_len > 1:
3386                 col.separator()
3387                 col.operator("mesh.edge_face_add", text="New Edge/Face from Vertices")
3388                 col.operator("mesh.vert_connect_path", text="Connect Vertex Path")
3389                 col.operator("mesh.vert_connect", text="Connect Vertex Pairs")
3390
3391             col.separator()
3392
3393             # Deform Operators
3394             col.operator("transform.push_pull", text="Push/Pull")
3395             col.operator("transform.shrink_fatten", text="Shrink/Fatten")
3396             col.operator("transform.shear", text="Shear")
3397             col.operator("transform.vert_slide", text="Slide Vertices")
3398             col.operator("transform.vertex_random", text="Randomize Vertices")
3399             col.operator("mesh.vertices_smooth", text="Smooth Vertices")
3400             col.operator("mesh.vertices_smooth_laplacian", text="Smooth Laplacian")
3401
3402             col.separator()
3403
3404             col.menu("VIEW3D_MT_mirror", text="Mirror Vertices")
3405             col.menu("VIEW3D_MT_snap", text="Snap Vertices")
3406
3407             col.separator()
3408
3409             # Removal Operators
3410             if selected_verts_len > 1:
3411                 col.menu("VIEW3D_MT_edit_mesh_merge", text="Merge Vertices")
3412             col.operator("mesh.split")
3413             col.operator_menu_enum("mesh.separate", "type")
3414             col.operator("mesh.dissolve_verts")
3415             col.operator("mesh.delete", text="Delete Vertices").type = 'VERT'
3416
3417         if is_edge_mode:
3418             render = context.scene.render
3419
3420             col = row.column()
3421             col.label(text="Edge Context Menu", icon='EDGESEL')
3422             col.separator()
3423
3424             # Additive Operators
3425             col.operator("mesh.subdivide", text="Subdivide")
3426
3427             col.separator()
3428
3429             col.operator("mesh.extrude_edges_move", text="Extrude Edges")
3430             col.operator("mesh.bevel", text="Bevel Edges").vertex_only = False
3431             if selected_edges_len >= 2:
3432                 col.operator("mesh.bridge_edge_loops")
3433             if selected_edges_len >= 1:
3434                 col.operator("mesh.edge_face_add", text="New Face from Edges")
3435             if selected_edges_len >= 2:
3436                 col.operator("mesh.fill")
3437
3438             col.separator()
3439
3440             col.operator("mesh.loopcut_slide")
3441             col.operator("mesh.offset_edge_loops_slide")
3442             col.operator("mesh.knife_tool")
3443             col.operator("mesh.bisect")
3444             col.operator("mesh.bridge_edge_loops", text="Bridge Edge Loops")
3445
3446             col.separator()
3447
3448             # Deform Operators
3449             col.operator("mesh.edge_rotate", text="Rotate Edge CW").use_ccw = False
3450             col.operator("transform.edge_slide")
3451             col.operator("mesh.edge_split")
3452
3453             col.separator()
3454
3455             # Edge Flags
3456             col.operator("transform.edge_crease")
3457             col.operator("transform.edge_bevelweight")
3458
3459             col.separator()
3460
3461             col.operator("mesh.mark_seam").clear = False
3462             col.operator("mesh.mark_seam", text="Clear Seam").clear = True
3463
3464             col.separator()
3465
3466             col.operator("mesh.mark_sharp")
3467             col.operator("mesh.mark_sharp", text="Clear Sharp").clear = True
3468
3469             if render.use_freestyle:
3470                 col.separator()
3471
3472                 col.operator("mesh.mark_freestyle_edge").clear = False
3473                 col.operator("mesh.mark_freestyle_edge", text="Clear Freestyle Edge").clear = True
3474
3475             col.separator()
3476
3477             # Removal Operators
3478             col.operator("mesh.unsubdivide")
3479             col.operator("mesh.split")
3480             col.operator_menu_enum("mesh.separate", "type")
3481             col.operator("mesh.dissolve_edges")
3482             col.operator("mesh.delete", text="Delete Edges").type = 'EDGE'
3483
3484         if is_face_mode:
3485             col = row.column()
3486
3487             col.label(text="Face Context Menu", icon='FACESEL')
3488             col.separator()
3489
3490             # Additive Operators
3491             col.operator("mesh.subdivide", text="Subdivide")
3492
3493             col.separator()
3494
3495             col.operator("view3d.edit_mesh_extrude_move_normal", text="Extrude Faces")
3496             col.operator("view3d.edit_mesh_extrude_move_shrink_fatten", text="Extrude Faces Along Normals")
3497             col.operator("mesh.extrude_faces_move", text="Extrude Individual Faces")
3498
3499             col.operator("mesh.inset")
3500             col.operator("mesh.poke")
3501
3502             if selected_faces_len >= 2:
3503                 col.operator("mesh.bridge_edge_loops", text="Bridge Faces")
3504
3505             col.separator()
3506
3507             # Modify Operators