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