Merge branch 'blender-v2.92-release'
[blender-addons.git] / space_view3d_spacebar_menu / object_menus.py
blobf6b0ba29f7a19fe1820be5f365eccf17e3287270
1 # ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
17 # ##### END GPL LICENSE BLOCK #####
18 # Contributed to by: meta-androcto, JayDez, sim88, sam, lijenstina, mkb, wisaac, CoDEmanX #
21 import bpy
22 from bpy.types import (
23 Operator,
24 Menu,
26 from bpy.props import (
27 BoolProperty,
28 StringProperty,
31 from bl_ui.properties_paint_common import UnifiedPaintPanel
33 from . edit_mesh import *
34 from . view_menus import *
35 # Object Menus #
37 # ********** Object Menu **********
38 class VIEW3D_MT_Object(Menu):
39 bl_context = "objectmode"
40 bl_label = "Object"
42 def draw(self, context):
43 layout = self.layout
44 view = context.space_data
46 layout.menu("VIEW3D_MT_mirror")
47 layout.menu("VIEW3D_MT_object_parent")
48 layout.menu("VIEW3D_MT_Duplicate")
49 layout.operator("object.join")
50 layout.menu("VIEW3D_MT_make_links", text="Make Links")
51 layout.menu("VIEW3D_MT_object_relations")
52 layout.separator()
54 ob = context.active_object
55 if ob and ob.type == 'GPENCIL' and context.gpencil_data:
56 layout.operator_menu_enum("gpencil.convert", "type", text="Convert to")
57 else:
58 layout.operator_menu_enum("object.convert", "target")
60 layout.menu("VIEW3D_MT_object_showhide")
61 layout.separator()
63 layout.menu("VIEW3D_MT_object_constraints")
64 layout.menu("VIEW3D_MT_object_track")
65 layout.separator()
67 layout.menu("VIEW3D_MT_object_rigid_body")
68 layout.menu("VIEW3D_MT_object_quick_effects")
69 layout.separator()
71 layout.operator("view3d.copybuffer", text="Copy Objects", icon='COPYDOWN')
72 layout.operator("view3d.pastebuffer", text="Paste Objects", icon='PASTEDOWN')
73 layout.separator()
75 layout.operator_context = 'EXEC_DEFAULT'
76 layout.operator("object.delete", text="Delete").use_global = False
77 layout.operator("object.delete", text="Delete Global").use_global = True
80 # ********** Object Interactive Mode **********
81 class VIEW3D_MT_InteractiveMode(Menu):
82 bl_label = "Interactive Mode"
83 bl_description = "Menu of objects' interactive modes (Window Types)"
85 def draw(self, context):
86 layout = self.layout
87 obj = context.active_object
88 psys = hasattr(obj, "particle_systems")
89 psys_items = len(obj.particle_systems.items()) > 0 if psys else False
91 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Object", icon="OBJECT_DATAMODE").mode = "OBJECT"
92 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Edit", icon="EDITMODE_HLT").mode = "EDIT"
93 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Sculpt", icon="SCULPTMODE_HLT").mode = "SCULPT"
94 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Vertex Paint", icon="VPAINT_HLT").mode = "VERTEX_PAINT"
95 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Weight Paint", icon="WPAINT_HLT").mode = "WEIGHT_PAINT"
96 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Texture Paint", icon="TPAINT_HLT").mode = "TEXTURE_PAINT"
97 if obj and psys_items:
98 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Particle Edit",
99 icon="PARTICLEMODE").mode = "PARTICLE_EDIT"
100 # if context.gpencil_data:
101 # layout.operator("view3d.interactive_mode_grease_pencil", icon="GREASEPENCIL")
104 # ********** Interactive Mode Other **********
105 class VIEW3D_MT_InteractiveModeOther(Menu):
106 bl_idname = "VIEW3D_MT_Object_Interactive_Other"
107 bl_label = "Interactive Mode"
108 bl_description = "Menu of objects interactive mode"
110 def draw(self, context):
111 layout = self.layout
112 layout.operator("object.editmode_toggle", text="Edit/Object Toggle",
113 icon='OBJECT_DATA')
116 # ********** Grease Pencil Interactive Mode **********
117 class VIEW3D_OT_Interactive_Mode_Grease_Pencil(Operator):
118 bl_idname = "view3d.interactive_mode_grease_pencil"
119 bl_label = "Edit Strokes"
120 bl_description = "Toggle Edit Strokes for Grease Pencil"
122 @classmethod
123 def poll(cls, context):
124 return (context.gpencil_data is not None)
126 def execute(self, context):
127 try:
128 bpy.ops.gpencil.editmode_toggle()
129 except:
130 self.report({'WARNING'}, "It is not possible to enter into the interactive mode")
131 return {'FINISHED'}
133 class VIEW3D_MT_Interactive_Mode_GPencil(Menu):
134 bl_idname = "VIEW3D_MT_interactive_mode_gpencil"
135 bl_label = "Interactive Mode"
136 bl_description = "Menu of objects interactive mode"
138 def draw(self, context):
139 toolsettings = context.tool_settings
140 layout = self.layout
141 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Object", icon="OBJECT_DATAMODE").mode = "OBJECT"
142 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Edit", icon="EDITMODE_HLT").mode = "EDIT_GPENCIL"
143 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Sculpt", icon="SCULPTMODE_HLT").mode = "SCULPT_GPENCIL"
144 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Draw", icon="GREASEPENCIL").mode = "PAINT_GPENCIL"
145 layout.operator(VIEW3D_OT_SetObjectMode.bl_idname, text="Weight Paint", icon="WPAINT_HLT").mode = "WEIGHT_GPENCIL"
148 # ********** Text Interactive Mode **********
149 class VIEW3D_OT_Interactive_Mode_Text(Operator):
150 bl_idname = "view3d.interactive_mode_text"
151 bl_label = "Enter Edit Mode"
152 bl_description = "Toggle object's editmode"
154 @classmethod
155 def poll(cls, context):
156 return (context.active_object is not None)
158 def execute(self, context):
159 bpy.ops.object.editmode_toggle()
160 self.report({'INFO'}, "Spacebar shortcut won't work in the Text Edit mode")
161 return {'FINISHED'}
164 # ********** Object Camera Options **********
165 class VIEW3D_MT_Camera_Options(Menu):
166 bl_label = "Camera"
168 def draw(self, context):
169 layout = self.layout
170 layout.operator_context = 'EXEC_REGION_WIN'
171 layout.operator("object.select_camera", text="Select Camera")
172 layout.operator("object.camera_add", text="Add Camera")
173 layout.operator("view3d.view_camera", text="View Camera")
174 layout.operator("view3d.camera_to_view", text="Camera to View")
175 layout.operator("view3d.camera_to_view_selected", text="Camera to Selected")
176 layout.operator("view3d.object_as_camera", text="Object As Camera")
179 class VIEW3D_MT_Duplicate(Menu):
180 bl_label = "Duplicate"
182 def draw(self, context):
183 layout = self.layout
185 layout.operator("object.duplicate_move")
186 layout.operator("object.duplicate_move_linked")
189 class VIEW3D_MT_UndoS(Menu):
190 bl_label = "Undo/Redo"
192 def draw(self, context):
193 layout = self.layout
195 layout.operator("ed.undo")
196 layout.operator("ed.redo")
197 layout.separator()
198 layout.operator("ed.undo_history")
201 # Set Mode Operator #
202 class VIEW3D_OT_SetObjectMode(Operator):
203 bl_idname = "object.set_object_mode"
204 bl_label = "Set the object interactive mode"
205 bl_description = "I set the interactive mode of object"
206 bl_options = {'REGISTER'}
208 mode: StringProperty(
209 name="Interactive mode",
210 default="OBJECT"
213 def execute(self, context):
214 if (context.active_object):
215 try:
216 bpy.ops.object.mode_set(mode=self.mode)
217 except TypeError:
218 msg = context.active_object.name + ": It is not possible to enter into the interactive mode"
219 self.report(type={"WARNING"}, message=msg)
220 else:
221 self.report(type={"WARNING"}, message="There is no active object")
222 return {'FINISHED'}
225 # currently unused
226 class VIEW3D_MT_Edit_Gpencil(Menu):
227 bl_label = "GPencil"
229 def draw(self, context):
230 toolsettings = context.tool_settings
231 layout = self.layout
233 layout.operator("gpencil.brush_paint", text="Sculpt Strokes").wait_for_input = True
234 layout.prop_menu_enum(toolsettings.gpencil_sculpt, "tool", text="Sculpt Brush")
235 layout.separator()
236 layout.menu("VIEW3D_MT_edit_gpencil_transform")
237 layout.operator("transform.mirror", text="Mirror")
238 layout.menu("GPENCIL_MT_snap")
239 layout.separator()
240 layout.menu("VIEW3D_MT_object_animation") # NOTE: provides keyingset access...
241 layout.separator()
242 layout.menu("VIEW3D_MT_edit_gpencil_delete")
243 layout.operator("gpencil.duplicate_move", text="Duplicate")
244 layout.separator()
245 layout.menu("VIEW3D_MT_select_gpencil")
246 layout.separator()
247 layout.operator("gpencil.copy", text="Copy")
248 layout.operator("gpencil.paste", text="Paste")
249 layout.separator()
250 layout.prop_menu_enum(toolsettings, "proportional_edit")
251 layout.prop_menu_enum(toolsettings, "proportional_edit_falloff")
252 layout.separator()
253 layout.operator("gpencil.reveal")
254 layout.operator("gpencil.hide", text="Show Active Layer Only").unselected = True
255 layout.operator("gpencil.hide", text="Hide Active Layer").unselected = False
256 layout.separator()
257 layout.operator_menu_enum("gpencil.move_to_layer", "layer", text="Move to Layer")
258 layout.operator_menu_enum("gpencil.convert", "type", text="Convert to Geometry...")
261 # List The Classes #
263 classes = (
264 VIEW3D_MT_Object,
265 VIEW3D_MT_UndoS,
266 VIEW3D_MT_Camera_Options,
267 VIEW3D_MT_InteractiveMode,
268 VIEW3D_MT_InteractiveModeOther,
269 VIEW3D_OT_SetObjectMode,
270 VIEW3D_MT_Duplicate,
271 VIEW3D_OT_Interactive_Mode_Text,
272 VIEW3D_OT_Interactive_Mode_Grease_Pencil,
273 VIEW3D_MT_Interactive_Mode_GPencil,
274 VIEW3D_MT_Edit_Gpencil,
278 # Register Classes & Hotkeys #
279 def register():
280 for cls in classes:
281 bpy.utils.register_class(cls)
284 # Unregister Classes & Hotkeys #
285 def unregister():
287 for cls in reversed(classes):
288 bpy.utils.unregister_class(cls)
291 if __name__ == "__main__":
292 register()