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