Correction to previous maya keymap commit
[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
32     def execute(self, context):
33         mesh = context.object.data
34         select_mode = context.tool_settings.mesh_select_mode
35
36         totface = mesh.total_face_sel
37         totedge = mesh.total_edge_sel
38         #~ totvert = mesh.total_vert_sel
39
40         if select_mode[2] and totface == 1:
41             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN',
42                     TRANSFORM_OT_translate={
43                         "constraint_orientation": 'NORMAL',
44                         "constraint_axis": (False, False, True)})
45         elif select_mode[2] and totface > 1:
46             bpy.ops.mesh.extrude_faces_move('INVOKE_REGION_WIN')
47         elif select_mode[1] and totedge >= 1:
48             bpy.ops.mesh.extrude_edges_move('INVOKE_REGION_WIN')
49         else:
50             bpy.ops.mesh.extrude_vertices_move('INVOKE_REGION_WIN')
51
52         # ignore return from operators above because they are 'RUNNING_MODAL',
53         # and cause this one not to be freed. [#24671]
54         return {'FINISHED'}
55
56     def invoke(self, context, event):
57         return self.execute(context)
58
59
60 class VIEW3D_OT_edit_mesh_extrude_move(Operator):
61     "Extrude and move along normals"
62     bl_label = "Extrude and Move on Normals"
63     bl_idname = "view3d.edit_mesh_extrude_move_normal"
64
65     def execute(self, context):
66         mesh = context.object.data
67
68         totface = mesh.total_face_sel
69         totedge = mesh.total_edge_sel
70         #~ totvert = mesh.total_vert_sel
71
72         if totface >= 1:
73             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN',
74                     TRANSFORM_OT_translate={
75                         "constraint_orientation": 'NORMAL',
76                         "constraint_axis": (False, False, True)})
77         elif totedge == 1:
78             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN',
79                     TRANSFORM_OT_translate={
80                         "constraint_orientation": 'NORMAL',
81                         # not a popular choice, too restrictive for retopo.
82                         #~ "constraint_axis": (True, True, False)})
83                         "constraint_axis": (False, False, False)})
84         else:
85             bpy.ops.mesh.extrude_region_move('INVOKE_REGION_WIN')
86
87         # ignore return from operators above because they are 'RUNNING_MODAL',
88         # and cause this one not to be freed. [#24671]
89         return {'FINISHED'}
90
91     def invoke(self, context, event):
92         return self.execute(context)
93
94
95 class VIEW3D_OT_select_or_deselect_all(Operator):
96     "Select element under the mouse, deselect everything is there's nothing under the mouse"
97     bl_label = "Select or Deselect All"
98     bl_idname = "view3d.select_or_deselect_all"
99     bl_options = {'UNDO'}
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))