49e26a2e8c2fcd70d349280c55eca6b560385d09
[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         sub = col.column(align=True)
163         sub.itemO("object.shape_key_add", icon='ICON_ZOOMIN', text="")
164         sub.itemO("object.shape_key_remove", icon='ICON_ZOOMOUT', text="")
165
166         if kb:
167             col.itemS()
168
169             sub = col.column(align=True)
170             sub.item_enumO("object.shape_key_move", "type", 'UP', icon='ICON_TRIA_UP', text="")
171             sub.item_enumO("object.shape_key_move", "type", 'DOWN', icon='ICON_TRIA_DOWN', text="")
172
173             split = layout.split(percentage=0.4)
174             row = split.row()
175             row.enabled = enable_edit
176             row.itemR(key, "relative")
177
178             row = split.row()
179             row.alignment = 'RIGHT'
180
181             sub = row.row(align=True)
182             subsub = sub.row(align=True)
183             subsub.active = enable_edit_value
184             if ob.shape_key_lock:
185                 subsub.itemR(ob, "shape_key_lock", icon='ICON_PINNED', text="")
186             else:
187                 subsub.itemR(ob, "shape_key_lock", icon='ICON_UNPINNED', text="")
188             if kb.mute:
189                 subsub.itemR(kb, "mute", icon='ICON_MUTE_IPO_ON', text="")
190             else:
191                 subsub.itemR(kb, "mute", icon='ICON_MUTE_IPO_OFF', text="")
192             sub.itemR(ob, "shape_key_edit_mode", text="")
193
194             sub = row.row(align=True)
195             sub.itemO("object.shape_key_mirror", icon='ICON_ARROW_LEFTRIGHT', text="")
196             sub.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
210                     col = split.column(align=True)
211                     col.active = enable_edit_value
212                     col.itemL(text="Range:")
213                     col.itemR(kb, "slider_min", text="Min")
214                     col.itemR(kb, "slider_max", text="Max")
215
216                     col = split.column(align=True)
217                     col.active = enable_edit_value
218                     col.itemL(text="Blend:")
219                     col.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
220                     col.item_pointerR(kb, "relative_key", key, "keys", text="")
221
222             else:
223                 row = layout.row()
224                 row.active = enable_edit_value
225                 row.itemR(key, "slurph")
226
227
228 class DATA_PT_uv_texture(DataButtonsPanel):
229     bl_label = "UV Texture"
230
231     def draw(self, context):
232         layout = self.layout
233
234         me = context.mesh
235
236         row = layout.row()
237         col = row.column()
238
239         col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
240
241         col = row.column(align=True)
242         col.itemO("mesh.uv_texture_add", icon='ICON_ZOOMIN', text="")
243         col.itemO("mesh.uv_texture_remove", icon='ICON_ZOOMOUT', text="")
244
245         lay = me.active_uv_texture
246         if lay:
247             layout.itemR(lay, "name")
248
249
250 class DATA_PT_vertex_colors(DataButtonsPanel):
251     bl_label = "Vertex Colors"
252
253     def draw(self, context):
254         layout = self.layout
255
256         me = context.mesh
257
258         row = layout.row()
259         col = row.column()
260
261         col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
262
263         col = row.column(align=True)
264         col.itemO("mesh.vertex_color_add", icon='ICON_ZOOMIN', text="")
265         col.itemO("mesh.vertex_color_remove", icon='ICON_ZOOMOUT', text="")
266
267         lay = me.active_vertex_color
268         if lay:
269             layout.itemR(lay, "name")
270
271 bpy.types.register(DATA_PT_context_mesh)
272 bpy.types.register(DATA_PT_normals)
273 bpy.types.register(DATA_PT_settings)
274 bpy.types.register(DATA_PT_vertex_groups)
275 bpy.types.register(DATA_PT_shape_keys)
276 bpy.types.register(DATA_PT_uv_texture)
277 bpy.types.register(DATA_PT_vertex_colors)