Moved the buttons around slightly in shape keys, to make it clearer what is action...
[blender.git] / release / scripts / 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22
23 class DataButtonsPanel(bpy.types.Panel):
24     bl_space_type = 'PROPERTIES'
25     bl_region_type = 'WINDOW'
26     bl_context = "data"
27
28     def poll(self, context):
29         return context.mesh
30
31
32 class DATA_PT_context_mesh(DataButtonsPanel):
33     bl_label = ""
34     bl_show_header = False
35
36     def draw(self, context):
37         layout = self.layout
38
39         ob = context.object
40         mesh = context.mesh
41         space = context.space_data
42
43         split = layout.split(percentage=0.65)
44
45         if ob:
46             split.template_ID(ob, "data")
47             split.itemS()
48         elif mesh:
49             split.template_ID(space, "pin_id")
50             split.itemS()
51
52
53 class DATA_PT_normals(DataButtonsPanel):
54     bl_label = "Normals"
55
56     def draw(self, context):
57         layout = self.layout
58
59         mesh = context.mesh
60
61         split = layout.split()
62
63         col = split.column()
64         col.itemR(mesh, "autosmooth")
65         sub = col.column()
66         sub.active = mesh.autosmooth
67         sub.itemR(mesh, "autosmooth_angle", text="Angle")
68
69         col = split.column()
70         col.itemR(mesh, "vertex_normal_flip")
71         col.itemR(mesh, "double_sided")
72
73
74 class DATA_PT_settings(DataButtonsPanel):
75     bl_label = "Settings"
76
77     def draw(self, context):
78         layout = self.layout
79
80         mesh = context.mesh
81
82         split = layout.split()
83
84         col = split.column()
85         col.itemR(mesh, "texture_mesh")
86
87
88 class DATA_PT_vertex_groups(DataButtonsPanel):
89     bl_label = "Vertex Groups"
90
91     def poll(self, context):
92         return (context.object and context.object.type in ('MESH', 'LATTICE'))
93
94     def draw(self, context):
95         layout = self.layout
96
97         ob = context.object
98         group = ob.active_vertex_group
99
100         rows = 2
101         if group:
102             rows = 5
103
104         row = layout.row()
105         row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index", rows=rows)
106
107         col = row.column(align=True)
108         col.itemO("object.vertex_group_add", icon='ICON_ZOOMIN', text="")
109         col.itemO("object.vertex_group_remove", icon='ICON_ZOOMOUT', text="")
110
111         col.itemO("object.vertex_group_copy", icon='ICON_COPY_ID', text="")
112         if ob.data.users > 1:
113             col.itemO("object.vertex_group_copy_to_linked", icon='ICON_LINK_AREA', text="")
114
115         if group:
116             row = layout.row()
117             row.itemR(group, "name")
118
119         if ob.mode == 'EDIT' and len(ob.vertex_groups) > 0:
120             row = layout.row()
121
122             sub = row.row(align=True)
123             sub.itemO("object.vertex_group_assign", text="Assign")
124             sub.itemO("object.vertex_group_remove_from", text="Remove")
125
126             sub = row.row(align=True)
127             sub.itemO("object.vertex_group_select", text="Select")
128             sub.itemO("object.vertex_group_deselect", text="Deselect")
129
130             layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
131
132
133 class DATA_PT_shape_keys(DataButtonsPanel):
134     bl_label = "Shape Keys"
135
136     def poll(self, context):
137         return (context.object and context.object.type in ('MESH', 'LATTICE', 'CURVE', 'SURFACE'))
138
139     def draw(self, context):
140         layout = self.layout
141
142         ob = context.object
143         key = ob.data.shape_keys
144         kb = ob.active_shape_key
145
146         enable_edit = ob.mode != 'EDIT'
147         enable_edit_value = False
148
149         if ob.shape_key_lock == False:
150             if enable_edit or (ob.type == 'MESH' and ob.shape_key_edit_mode):
151                 enable_edit_value = True
152
153         row = layout.row()
154
155         rows = 2
156         if kb:
157             rows = 5
158         row.template_list(key, "keys", ob, "active_shape_key_index", rows=rows)
159
160         col = row.column()
161
162         subcol = col.column(align=True)
163         subcol.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="")
164         subcol.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="")
165
166         if kb:
167             col.itemS()
168
169             subcol = col.column(align=True)
170             subcol.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="")
171             subcol.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="")
172
173             split = layout.split(percentage=0.4)
174             sub = split.row()
175             sub.enabled = enable_edit
176             sub.itemR(key, "relative")
177
178             sub = split.row()
179             sub.alignment = 'RIGHT'
180
181             subrow = sub.row(align=True)
182             subrow1 = subrow.row(align=True)
183             subrow1.active = enable_edit_value
184             if ob.shape_key_lock:
185                 subrow1.itemR(ob, "shape_key_lock", icon='ICON_PINNED', text="")
186             else:
187                 subrow1.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
188             if kb.mute:
189                 subrow1.itemR(kb, "mute", icon='ICON_MUTE_IPO_ON', text="")
190             else:
191                 subrow1.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="")
192             subrow.itemR(ob, "shape_key_edit_mode", text="")
193             
194             subrow = sub.row(align=True)
195             subrow.itemO("object.shape_key_mirror", icon='ICON_ARROW_LEFTRIGHT', text="")
196             subrow.itemO("object.shape_key_clear", icon='ICON_X', text="")
197             
198
199             row = layout.row()
200             row.itemR(kb, "name")
201
202             if key.relative:
203                 if ob.active_shape_key_index != 0:
204                     row = layout.row()
205                     row.active = enable_edit_value
206                     row.itemR(kb, "value")
207
208                     split = layout.split()
209                     sub = split.column(align=True)
210                     sub.active = enable_edit_value
211                     sub.itemL(text="Range:")
212                     sub.itemR(kb, "slider_min", text="Min")
213                     sub.itemR(kb, "slider_max", text="Max")
214
215                     sub = split.column(align=True)
216                     sub.active = enable_edit_value
217                     sub.itemL(text="Blend:")
218                     sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
219                     sub.item_pointerR(kb, "relative_key", key, "keys", text="")
220
221             else:
222                 row = layout.row()
223                 row.active = enable_edit_value
224                 row.itemR(key, "slurph")
225
226
227 class DATA_PT_uv_texture(DataButtonsPanel):
228     bl_label = "UV Texture"
229
230     def draw(self, context):
231         layout = self.layout
232
233         me = context.mesh
234
235         row = layout.row()
236         col = row.column()
237
238         col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
239
240         col = row.column(align=True)
241         col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="")
242         col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="")
243
244         lay = me.active_uv_texture
245         if lay:
246             layout.itemR(lay, "name")
247
248
249 class DATA_PT_vertex_colors(DataButtonsPanel):
250     bl_label = "Vertex Colors"
251
252     def draw(self, context):
253         layout = self.layout
254
255         me = context.mesh
256
257         row = layout.row()
258         col = row.column()
259
260         col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
261
262         col = row.column(align=True)
263         col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="")
264         col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="")
265
266         lay = me.active_vertex_color
267         if lay:
268             layout.itemR(lay, "name")
269
270 bpy.types.register(DATA_PT_context_mesh)
271 bpy.types.register(DATA_PT_normals)
272 bpy.types.register(DATA_PT_settings)
273 bpy.types.register(DATA_PT_vertex_groups)
274 bpy.types.register(DATA_PT_shape_keys)
275 bpy.types.register(DATA_PT_uv_texture)
276 bpy.types.register(DATA_PT_vertex_colors)