20360fa5ee363e3351247083b0da7075160144ae
[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             subrow.active = enable_edit_value
183             if ob.shape_key_lock:
184                 subrow.itemR(ob, "shape_key_lock", icon='ICON_PINNED', text="")
185             else:
186                 subrow.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
187             if kb.mute:
188                 subrow.itemR(kb, "mute", icon='ICON_MUTE_IPO_ON', text="")
189             else:
190                 subrow.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="")
191             subrow.itemO("object.shape_key_clear", icon='ICON_X', text="")
192
193             sub.itemO("object.shape_key_mirror", icon='ICON_MOD_MIRROR', text="")
194
195             sub.itemR(ob, "shape_key_edit_mode", text="")
196
197             row = layout.row()
198             row.itemR(kb, "name")
199
200             if key.relative:
201                 if ob.active_shape_key_index != 0:
202                     row = layout.row()
203                     row.active = enable_edit_value
204                     row.itemR(kb, "value")
205
206                     split = layout.split()
207                     sub = split.column(align=True)
208                     sub.active = enable_edit_value
209                     sub.itemL(text="Range:")
210                     sub.itemR(kb, "slider_min", text="Min")
211                     sub.itemR(kb, "slider_max", text="Max")
212
213                     sub = split.column(align=True)
214                     sub.active = enable_edit_value
215                     sub.itemL(text="Blend:")
216                     sub.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
217                     sub.item_pointerR(kb, "relative_key", key, "keys", text="")
218
219             else:
220                 row = layout.row()
221                 row.active = enable_edit_value
222                 row.itemR(key, "slurph")
223
224
225 class DATA_PT_uv_texture(DataButtonsPanel):
226     bl_label = "UV Texture"
227
228     def draw(self, context):
229         layout = self.layout
230
231         me = context.mesh
232
233         row = layout.row()
234         col = row.column()
235
236         col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
237
238         col = row.column(align=True)
239         col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="")
240         col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="")
241
242         lay = me.active_uv_texture
243         if lay:
244             layout.itemR(lay, "name")
245
246
247 class DATA_PT_vertex_colors(DataButtonsPanel):
248     bl_label = "Vertex Colors"
249
250     def draw(self, context):
251         layout = self.layout
252
253         me = context.mesh
254
255         row = layout.row()
256         col = row.column()
257
258         col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
259
260         col = row.column(align=True)
261         col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="")
262         col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="")
263
264         lay = me.active_vertex_color
265         if lay:
266             layout.itemR(lay, "name")
267
268 bpy.types.register(DATA_PT_context_mesh)
269 bpy.types.register(DATA_PT_normals)
270 bpy.types.register(DATA_PT_settings)
271 bpy.types.register(DATA_PT_vertex_groups)
272 bpy.types.register(DATA_PT_shape_keys)
273 bpy.types.register(DATA_PT_uv_texture)
274 bpy.types.register(DATA_PT_vertex_colors)