Fix uilists showing data names translated (reported on bf-translations ML by Satoshi...
[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, UIList
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 Vertex Groups").all = True
38         layout.operator("object.vertex_group_remove_from", icon='X', text="Remove Selected from All Vertex Groups").all = True
39         layout.separator()
40         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock All").action = 'LOCK'
41         layout.operator("object.vertex_group_lock", icon='UNLOCKED', text="UnLock All").action = 'UNLOCK'
42         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock Invert All").action = 'INVERT'
43
44
45 class MESH_MT_shape_key_specials(Menu):
46     bl_label = "Shape Key Specials"
47     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
48
49     def draw(self, context):
50         layout = self.layout
51
52         layout.operator("object.shape_key_transfer", icon='COPY_ID')  # icon is not ideal
53         layout.operator("object.join_shapes", icon='COPY_ID')  # icon is not ideal
54         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT')
55         layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix").from_mix = True
56
57
58 class MESH_UL_vgroups(UIList):
59     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
60         # assert(isinstance(item, bpy.types.VertexGroup)
61         vgroup = item
62         if self.layout_type in {'DEFAULT', 'COMPACT'}:
63             layout.label(text=vgroup.name, translate=False, icon_value=icon)
64             icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
65             layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
66         elif self.layout_type in {'GRID'}:
67             layout.alignment = 'CENTER'
68             layout.label(text="", icon_value=icon)
69
70
71 class MESH_UL_shape_keys(UIList):
72     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
73         # assert(isinstance(item, bpy.types.ShapeKey)
74         obj = active_data
75         key = data
76         key_block = item
77         if self.layout_type in {'DEFAULT', 'COMPACT'}:
78             split = layout.split(0.66, False)
79             split.label(text=item.name, translate=False, icon_value=icon)
80             row = split.row(True)
81             if key_block.mute or (obj.mode == 'EDIT' and not (obj.use_shape_key_edit_mode and obj.type == 'MESH')):
82                 row.active = False
83             if not item.relative_key or index > 0:
84                 row.prop(key_block, "value", text="", emboss=False)
85             else:
86                 row.label(text="")
87             row.prop(key_block, "mute", text="", emboss=False)
88         elif self.layout_type in {'GRID'}:
89             layout.alignment = 'CENTER'
90             layout.label(text="", icon_value=icon)
91
92
93 class MESH_UL_uvmaps_vcols(UIList):
94     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
95         # assert(isinstance(item, (bpy.types.MeshTexturePolyLayer, bpy.types.MeshLoopColorLayer))
96         if self.layout_type in {'DEFAULT', 'COMPACT'}:
97             layout.label(text=item.name, translate=False, icon_value=icon)
98             icon = 'RESTRICT_RENDER_OFF' if item.active_render else 'RESTRICT_RENDER_ON'
99             layout.prop(item, "active_render", text="", icon=icon, emboss=False)
100         elif self.layout_type in {'GRID'}:
101             layout.alignment = 'CENTER'
102             layout.label(text="", icon_value=icon)
103
104
105 class MeshButtonsPanel():
106     bl_space_type = 'PROPERTIES'
107     bl_region_type = 'WINDOW'
108     bl_context = "data"
109
110     @classmethod
111     def poll(cls, context):
112         engine = context.scene.render.engine
113         return context.mesh and (engine in cls.COMPAT_ENGINES)
114
115
116 class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
117     bl_label = ""
118     bl_options = {'HIDE_HEADER'}
119     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
120
121     def draw(self, context):
122         layout = self.layout
123
124         ob = context.object
125         mesh = context.mesh
126         space = context.space_data
127
128         if ob:
129             layout.template_ID(ob, "data")
130         elif mesh:
131             layout.template_ID(space, "pin_id")
132
133
134 class DATA_PT_normals(MeshButtonsPanel, Panel):
135     bl_label = "Normals"
136     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
137
138     def draw(self, context):
139         layout = self.layout
140
141         mesh = context.mesh
142
143         split = layout.split()
144
145         col = split.column()
146         col.prop(mesh, "use_auto_smooth")
147         sub = col.column()
148         sub.active = mesh.use_auto_smooth
149         sub.prop(mesh, "auto_smooth_angle", text="Angle")
150
151         split.prop(mesh, "show_double_sided")
152
153
154 class DATA_PT_texture_space(MeshButtonsPanel, Panel):
155     bl_label = "Texture Space"
156     bl_options = {'DEFAULT_CLOSED'}
157     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
158
159     def draw(self, context):
160         layout = self.layout
161
162         mesh = context.mesh
163
164         layout.prop(mesh, "texture_mesh")
165
166         layout.separator()
167
168         layout.prop(mesh, "use_auto_texspace")
169         row = layout.row()
170         row.column().prop(mesh, "texspace_location", text="Location")
171         row.column().prop(mesh, "texspace_size", text="Size")
172
173
174 class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
175     bl_label = "Vertex Groups"
176     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
177
178     @classmethod
179     def poll(cls, context):
180         engine = context.scene.render.engine
181         obj = context.object
182         return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
183
184     def draw(self, context):
185         layout = self.layout
186
187         ob = context.object
188         group = ob.vertex_groups.active
189
190         rows = 2
191         if group:
192             rows = 5
193
194         row = layout.row()
195         row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
196
197         col = row.column(align=True)
198         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
199         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False
200         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
201         if group:
202             col.separator()
203             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
204             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
205
206         if group:
207             row = layout.row()
208             row.prop(group, "name")
209
210         if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
211             row = layout.row()
212
213             sub = row.row(align=True)
214             sub.operator("object.vertex_group_assign", text="Assign").new = False
215             sub.operator("object.vertex_group_remove_from", text="Remove")
216
217             sub = row.row(align=True)
218             sub.operator("object.vertex_group_select", text="Select")
219             sub.operator("object.vertex_group_deselect", text="Deselect")
220
221             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
222
223
224 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
225     bl_label = "Shape Keys"
226     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
227
228     @classmethod
229     def poll(cls, context):
230         engine = context.scene.render.engine
231         obj = context.object
232         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
233
234     def draw(self, context):
235         layout = self.layout
236
237         ob = context.object
238         key = ob.data.shape_keys
239         kb = ob.active_shape_key
240
241         enable_edit = ob.mode != 'EDIT'
242         enable_edit_value = False
243
244         if ob.show_only_shape_key is False:
245             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
246                 enable_edit_value = True
247
248         row = layout.row()
249
250         rows = 2
251         if kb:
252             rows = 5
253         row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
254
255         col = row.column()
256
257         sub = col.column(align=True)
258         sub.operator("object.shape_key_add", icon='ZOOMIN', text="").from_mix = False
259         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="")
260         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
261
262         if kb:
263             col.separator()
264
265             sub = col.column(align=True)
266             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
267             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
268
269             split = layout.split(percentage=0.4)
270             row = split.row()
271             row.enabled = enable_edit
272             row.prop(key, "use_relative")
273
274             row = split.row()
275             row.alignment = 'RIGHT'
276
277             sub = row.row(align=True)
278             sub.label()  # XXX, for alignment only
279             subsub = sub.row(align=True)
280             subsub.active = enable_edit_value
281             subsub.prop(ob, "show_only_shape_key", text="")
282             sub.prop(ob, "use_shape_key_edit_mode", text="")
283
284             sub = row.row()
285             if key.use_relative:
286                 sub.operator("object.shape_key_clear", icon='X', text="")
287             else:
288                 sub.operator("object.shape_key_retime", icon='RECOVER_LAST', text="")
289
290             row = layout.row()
291             row.prop(kb, "name")
292
293             if key.use_relative:
294                 if ob.active_shape_key_index != 0:
295                     row = layout.row()
296                     row.active = enable_edit_value
297                     row.prop(kb, "value")
298
299                     split = layout.split()
300
301                     col = split.column(align=True)
302                     col.active = enable_edit_value
303                     col.label(text="Range:")
304                     col.prop(kb, "slider_min", text="Min")
305                     col.prop(kb, "slider_max", text="Max")
306
307                     col = split.column(align=True)
308                     col.active = enable_edit_value
309                     col.label(text="Blend:")
310                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
311                     col.prop_search(kb, "relative_key", key, "key_blocks", text="")
312
313             else:
314                 layout.prop(kb, "interpolation")
315                 row = layout.column()
316                 row.active = enable_edit_value
317                 row.prop(key, "eval_time")
318                 row.prop(key, "slurph")
319
320
321 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
322     bl_label = "UV Maps"
323     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
324
325     def draw(self, context):
326         layout = self.layout
327
328         me = context.mesh
329
330         row = layout.row()
331         col = row.column()
332
333         col.template_list("MESH_UL_uvmaps_vcols", "uvmaps", me, "uv_textures", me.uv_textures, "active_index", rows=2)
334
335         col = row.column(align=True)
336         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
337         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
338
339         lay = me.uv_textures.active
340         if lay:
341             layout.prop(lay, "name")
342
343
344 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
345     bl_label = "Vertex Colors"
346     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
347
348     def draw(self, context):
349         layout = self.layout
350
351         me = context.mesh
352
353         row = layout.row()
354         col = row.column()
355
356         col.template_list("MESH_UL_uvmaps_vcols", "vcols", me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
357
358         col = row.column(align=True)
359         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
360         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
361
362         lay = me.vertex_colors.active
363         if lay:
364             layout.prop(lay, "name")
365
366
367 class DATA_PT_customdata(MeshButtonsPanel, Panel):
368     bl_label = "Geometry Data"
369     bl_options = {'DEFAULT_CLOSED'}
370     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
371
372     def draw(self, context):
373         layout = self.layout
374
375         obj = context.object
376         me = context.mesh
377         col = layout.column()
378
379         col.operator("mesh.customdata_clear_mask", icon='X')
380         col.operator("mesh.customdata_clear_skin", icon='X')
381
382         col = layout.column()
383
384         col.enabled = (obj.mode != 'EDIT')
385         col.prop(me, "use_customdata_vertex_bevel")
386         col.prop(me, "use_customdata_edge_bevel")
387         col.prop(me, "use_customdata_edge_crease")
388
389
390 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
391     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
392     _context_path = "object.data"
393     _property_type = bpy.types.Mesh
394
395
396 if __name__ == "__main__":  # only for live edit.
397     bpy.utils.register_module(__name__)