remove use of gettext: _("...") style translation now its handled by rna.
[blender.git] / release / scripts / startup / bl_ui / properties_data_mesh.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 Menu, Panel
22 from rna_prop_ui import PropertyPanel
23
24
25 class MESH_MT_vertex_group_specials(Menu):
26     bl_label = "Vertex Group Specials"
27     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
28
29     def draw(self, context):
30         layout = self.layout
31
32         layout.operator("object.vertex_group_sort", icon='SORTALPHA')
33         layout.operator("object.vertex_group_copy", icon='COPY_ID')
34         layout.operator("object.vertex_group_copy_to_linked", icon='LINK_AREA')
35         layout.operator("object.vertex_group_copy_to_selected", icon='LINK_AREA')
36         layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT')
37         layout.operator("object.vertex_group_remove", icon='X', text="Delete All").all = True
38         layout.separator()
39         layout.operator("object.vertex_group_lock", icon='LOCK', text="Lock All").action = 'SELECT'
40         layout.operator("object.vertex_group_lock", icon='UNLOCK', text="UnLock All").action = 'DESELECT'
41         layout.operator("object.vertex_group_lock", icon='LOCK', text="Lock Invert All").action = 'INVERT'
42
43
44 class MESH_MT_shape_key_specials(Menu):
45     bl_label = "Shape Key Specials"
46     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
47
48     def draw(self, context):
49         layout = self.layout
50
51         layout.operator("object.shape_key_transfer", icon='COPY_ID')  # icon is not ideal
52         layout.operator("object.join_shapes", icon='COPY_ID')  # icon is not ideal
53         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT')
54         op = layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix")
55         op.from_mix = True
56
57
58 class MeshButtonsPanel():
59     bl_space_type = 'PROPERTIES'
60     bl_region_type = 'WINDOW'
61     bl_context = "data"
62
63     @classmethod
64     def poll(cls, context):
65         engine = context.scene.render.engine
66         return context.mesh and (engine in cls.COMPAT_ENGINES)
67
68
69 class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
70     bl_label = ""
71     bl_options = {'HIDE_HEADER'}
72     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
73
74     def draw(self, context):
75         layout = self.layout
76
77         ob = context.object
78         mesh = context.mesh
79         space = context.space_data
80
81         if ob:
82             layout.template_ID(ob, "data")
83         elif mesh:
84             layout.template_ID(space, "pin_id")
85
86
87 class DATA_PT_normals(MeshButtonsPanel, Panel):
88     bl_label = "Normals"
89     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
90
91     def draw(self, context):
92         layout = self.layout
93
94         mesh = context.mesh
95
96         split = layout.split()
97
98         col = split.column()
99         col.prop(mesh, "use_auto_smooth")
100         sub = col.column()
101         sub.active = mesh.use_auto_smooth
102         sub.prop(mesh, "auto_smooth_angle", text="Angle")
103
104         split.prop(mesh, "show_double_sided")
105
106
107 class DATA_PT_texture_space(MeshButtonsPanel, Panel):
108     bl_label = "Texture Space"
109     bl_options = {'DEFAULT_CLOSED'}
110     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
111
112     def draw(self, context):
113         layout = self.layout
114
115         mesh = context.mesh
116
117         layout.prop(mesh, "texture_mesh")
118
119         layout.separator()
120
121         layout.prop(mesh, "use_auto_texspace")
122         row = layout.row()
123         row.column().prop(mesh, "texspace_location", text="Location")
124         row.column().prop(mesh, "texspace_size", text="Size")
125
126
127 class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
128     bl_label = "Vertex Groups"
129     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
130
131     @classmethod
132     def poll(cls, context):
133         engine = context.scene.render.engine
134         obj = context.object
135         return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
136
137     def draw(self, context):
138         layout = self.layout
139
140         ob = context.object
141         group = ob.vertex_groups.active
142
143         rows = 2
144         if group:
145             rows = 5
146
147         row = layout.row()
148         row.template_list(ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
149
150         col = row.column(align=True)
151         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
152         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="")
153         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
154         if group:
155             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
156             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
157
158         if group:
159             row = layout.row()
160             row.prop(group, "name")
161
162         if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
163             row = layout.row()
164
165             sub = row.row(align=True)
166             sub.operator("object.vertex_group_assign", text="Assign")
167             sub.operator("object.vertex_group_remove_from", text="Remove")
168
169             sub = row.row(align=True)
170             sub.operator("object.vertex_group_select", text="Select")
171             sub.operator("object.vertex_group_deselect", text="Deselect")
172
173             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
174
175
176 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
177     bl_label = "Shape Keys"
178     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
179
180     @classmethod
181     def poll(cls, context):
182         engine = context.scene.render.engine
183         obj = context.object
184         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
185
186     def draw(self, context):
187         layout = self.layout
188
189         ob = context.object
190         key = ob.data.shape_keys
191         kb = ob.active_shape_key
192
193         enable_edit = ob.mode != 'EDIT'
194         enable_edit_value = False
195
196         if ob.show_only_shape_key is False:
197             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
198                 enable_edit_value = True
199
200         row = layout.row()
201
202         rows = 2
203         if kb:
204             rows = 5
205         row.template_list(key, "key_blocks", ob, "active_shape_key_index", rows=rows)
206
207         col = row.column()
208
209         sub = col.column(align=True)
210         op = sub.operator("object.shape_key_add", icon='ZOOMIN', text="")
211         op.from_mix = False
212         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="")
213         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
214
215         if kb:
216             col.separator()
217
218             sub = col.column(align=True)
219             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
220             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
221
222             split = layout.split(percentage=0.4)
223             row = split.row()
224             row.enabled = enable_edit
225             row.prop(key, "use_relative")
226
227             row = split.row()
228             row.alignment = 'RIGHT'
229
230             sub = row.row(align=True)
231             subsub = sub.row(align=True)
232             subsub.active = enable_edit_value
233             subsub.prop(ob, "show_only_shape_key", text="")
234             subsub.prop(kb, "mute", text="")
235             sub.prop(ob, "use_shape_key_edit_mode", text="")
236
237             sub = row.row()
238             sub.operator("object.shape_key_clear", icon='X', text="")
239
240             row = layout.row()
241             row.prop(kb, "name")
242
243             if key.use_relative:
244                 if ob.active_shape_key_index != 0:
245                     row = layout.row()
246                     row.active = enable_edit_value
247                     row.prop(kb, "value")
248
249                     split = layout.split()
250
251                     col = split.column(align=True)
252                     col.active = enable_edit_value
253                     col.label(text="Range:")
254                     col.prop(kb, "slider_min", text="Min")
255                     col.prop(kb, "slider_max", text="Max")
256
257                     col = split.column(align=True)
258                     col.active = enable_edit_value
259                     col.label(text="Blend:")
260                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
261                     col.prop_search(kb, "relative_key", key, "key_blocks", text="")
262
263             else:
264                 row = layout.row()
265                 row.active = enable_edit_value
266                 row.prop(key, "slurph")
267
268
269 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
270     bl_label = "UV Texture"
271     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
272
273     def draw(self, context):
274         layout = self.layout
275
276         me = context.mesh
277
278         row = layout.row()
279         col = row.column()
280
281         col.template_list(me, "uv_textures", me.uv_textures, "active_index", rows=2)
282
283         col = row.column(align=True)
284         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
285         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
286
287         lay = me.uv_textures.active
288         if lay:
289             layout.prop(lay, "name")
290
291
292 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
293     bl_label = "Vertex Colors"
294     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
295
296     def draw(self, context):
297         layout = self.layout
298
299         me = context.mesh
300
301         row = layout.row()
302         col = row.column()
303
304         col.template_list(me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
305
306         col = row.column(align=True)
307         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
308         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
309
310         lay = me.vertex_colors.active
311         if lay:
312             layout.prop(lay, "name")
313
314
315 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
316     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
317     _context_path = "object.data"
318     _property_type = bpy.types.Mesh
319
320 if __name__ == "__main__":  # only for live edit.
321     bpy.utils.register_module(__name__)