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