Fix #35661: Maya key config - select operations are skipped by "undo"
[blender.git] / release / scripts / startup / bl_operators / 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-80 compliant>
20
21 import bpy
22 import mathutils
23 from bpy.types import Operator
24 from bpy.props import BoolProperty
25
26
27 class VIEW3D_OT_edit_mesh_extrude_individual_move(Operator):
28     "Extrude individual elements and move"
29     bl_label = "Extrude Individual and Move"
30     bl_idname = "view3d.edit_mesh_extrude_individual_move"
31     bl_options = {'UNDO'}
32
33     def execute(self, context):
34         mesh = context.object.data
35         select_mode = context.tool_settings.mesh_select_mode
36
37         totface = mesh.total_face_sel
38         totedge = mesh.total_edge_sel
39         #~ totvert = mesh.total_vert_sel
40
41         if select_mode[2] and totface == 1:
42             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN',
43                     TRANSFORM_OT_translate={
44                         "constraint_orientation": 'NORMAL',
45                         "constraint_axis": (False, False, True)})
46         elif select_mode[2] and totface > 1:
47             bpy.ops.mesh.extrude_faces_move('INVOKE_REGION_WIN')
48         elif select_mode[1] and totedge >= 1:
49             bpy.ops.mesh.extrude_edges_move('INVOKE_REGION_WIN')
50         else:
51             bpy.ops.mesh.extrude_vertices_move('INVOKE_REGION_WIN')
52
53         # ignore return from operators above because they are 'RUNNING_MODAL',
54         # and cause this one not to be freed. [#24671]
55         return {'FINISHED'}
56
57     def invoke(self, context, event):
58         return self.execute(context)
59
60
61 class VIEW3D_OT_edit_mesh_extrude_move(Operator):
62     "Extrude and move along normals"
63     bl_label = "Extrude and Move on Normals"
64     bl_idname = "view3d.edit_mesh_extrude_move_normal"
65
66     def execute(self, context):
67         mesh = context.object.data
68
69         totface = mesh.total_face_sel
70         totedge = mesh.total_edge_sel
71         #~ totvert = mesh.total_vert_sel
72
73         if totface >= 1:
74             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN',
75                     TRANSFORM_OT_translate={
76                         "constraint_orientation": 'NORMAL',
77                         "constraint_axis": (False, False, True)})
78         elif totedge == 1:
79             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN',
80                     TRANSFORM_OT_translate={
81                         "constraint_orientation": 'NORMAL',
82                         # not a popular choice, too restrictive for retopo.
83                         #~ "constraint_axis": (True, True, False)})
84                         "constraint_axis": (False, False, False)})
85         else:
86             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN')
87
88         # ignore return from operators above because they are 'RUNNING_MODAL',
89         # and cause this one not to be freed. [#24671]
90         return {'FINISHED'}
91
92     def invoke(self, context, event):
93         return self.execute(context)
94
95
96 class VIEW3D_OT_select_or_deselect_all(Operator):
97     "Select element under the mouse, deselect everything is there's nothing under the mouse"
98     bl_label = "Select or Deselect All"
99     bl_idname = "view3d.select_or_deselect_all"
100
101     extend = BoolProperty(
102             name="Extend",
103             description="Extend selection instead of deselecting everything first",
104             default=False,
105             )
106
107     toggle = BoolProperty(
108             name="Toggle",
109             description="Toggle the selection",
110             default=False,
111             )
112
113     deselect = BoolProperty(
114             name="Deselect",
115             description="Remove from selection",
116             default=False,
117             )
118
119     center = BoolProperty(
120             name="Center",
121             description="Use the object center when selecting, in editmode used to extend object selection",
122             default=False,
123             )
124
125     enumerate = BoolProperty(
126             name="Enumerate",
127             description="List objects under the mouse (object mode only)",
128             default=False,
129             )
130
131     object = BoolProperty(
132             name="Object",
133             description="Use object selection (editmode only)",
134             default=False,
135             )
136
137     def invoke(self, context, event):
138         x = event.mouse_region_x
139         y = event.mouse_region_y
140
141         if self.extend == False and self.toggle == False and self.deselect == False:
142             active_object = context.active_object
143
144             if active_object:
145                 if active_object.mode == 'EDIT':
146                     if active_object.type == 'MESH':
147                         bpy.ops.mesh.select_all(action='DESELECT')
148                     elif active_object.type == 'CURVE':
149                         bpy.ops.curve.select_all(action='DESELECT')
150                     elif active_object.type == 'SURFACE':
151                         bpy.ops.curve.select_all(action='DESELECT')
152                     elif active_object.type == 'LATTICE':
153                         bpy.ops.lattice.select_all(action='DESELECT')
154                     elif active_object.type == 'META':
155                         bpy.ops.mball.select_all(action='DESELECT')
156                     elif active_object.type == 'ARMATURE':
157                         bpy.ops.armature.select_all(action='DESELECT')
158                 elif active_object.mode == 'POSE':
159                     bpy.ops.pose.select_all(action='DESELECT')
160                 elif active_object.mode == 'PARTICLE_EDIT':
161                     bpy.ops.particle.select_all(action='DESELECT')
162                 else:
163                     bpy.ops.object.select_all(action='DESELECT')
164             else:
165                 bpy.ops.object.select_all(action='DESELECT')
166
167         return bpy.ops.view3d.select(extend=self.extend,
168                                      deselect=self.deselect,
169                                      toggle=self.toggle,
170                                      center=self.center,
171                                      enumerate=self.enumerate,
172                                      object=self.object,
173                                      location=(x, y))