Made blender compilable with strict flags again.
[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
100     extend = BoolProperty(
101             name="Extend",
102             description="Extend selection instead of deselecting everything first",
103             default=False,
104             )
105
106     toggle = BoolProperty(
107             name="Toggle",
108             description="Toggle the selection",
109             default=False,
110             )
111
112     deselect = BoolProperty(
113             name="Deselect",
114             description="Remove from selection",
115             default=False,
116             )
117
118     center = BoolProperty(
119             name="Center",
120             description="Use the object center when selecting, in editmode used to extend object selection",
121             default=False,
122             )
123
124     enumerate = BoolProperty(
125             name="Enumerate",
126             description="List objects under the mouse (object mode only)",
127             default=False,
128             )
129
130     object = BoolProperty(
131             name="Object",
132             description="Use object selection (editmode only)",
133             default=False,
134             )
135
136     def invoke(self, context, event):
137         x = event.mouse_region_x
138         y = event.mouse_region_y
139
140         if self.extend == False and self.toggle == False and self.deselect == False:
141             active_object = context.active_object
142
143             if active_object:
144                 if active_object.mode == 'EDIT':
145                     if active_object.type == 'MESH':
146                         bpy.ops.mesh.select_all(action='DESELECT')
147                     elif active_object.type == 'CURVE':
148                         bpy.ops.curve.select_all(action='DESELECT')
149                     elif active_object.type == 'SURFACE':
150                         bpy.ops.curve.select_all(action='DESELECT')
151                     elif active_object.type == 'LATTICE':
152                         bpy.ops.lattice.select_all(action='DESELECT')
153                     elif active_object.type == 'META':
154                         bpy.ops.mball.select_all(action='DESELECT')
155                     elif active_object.type == 'ARMATURE':
156                         bpy.ops.armature.select_all(action='DESELECT')
157                 elif active_object.mode == 'POSE':
158                     bpy.ops.pose.select_all(action='DESELECT')
159                 elif active_object.mode == 'PARTICLE_EDIT':
160                     bpy.ops.particle.select_all(action='DESELECT')
161                 else:
162                     bpy.ops.object.select_all(action='DESELECT')
163             else:
164                 bpy.ops.object.select_all(action='DESELECT')
165
166         return bpy.ops.view3d.select(extend=self.extend,
167                                      deselect=self.deselect,
168                                      toggle=self.toggle,
169                                      center=self.center,
170                                      enumerate=self.enumerate,
171                                      object=self.object,
172                                      location=(x, y))