remove type checks on drawing uiList's,
[blender.git] / release / scripts / startup / bl_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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Menu, Panel, UIList
22 from rna_prop_ui import PropertyPanel
23
24
25 class MESH_MT_vertex_group_specials(Menu):
26     bl_label = "Vertex Group Specials"
27     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
28
29     def draw(self, context):
30         layout = self.layout
31
32         layout.operator("object.vertex_group_sort", icon='SORTALPHA')
33         layout.operator("object.vertex_group_copy", icon='COPY_ID')
34         layout.operator("object.vertex_group_copy_to_linked", icon='LINK_AREA')
35         layout.operator("object.vertex_group_copy_to_selected", icon='LINK_AREA')
36         layout.operator("object.vertex_group_mirror", icon='ARROW_LEFTRIGHT')
37         layout.operator("object.vertex_group_remove", icon='X', text="Delete All").all = True
38         layout.separator()
39         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock All").action = 'LOCK'
40         layout.operator("object.vertex_group_lock", icon='UNLOCKED', text="UnLock All").action = 'UNLOCK'
41         layout.operator("object.vertex_group_lock", icon='LOCKED', text="Lock Invert All").action = 'INVERT'
42
43
44 class MESH_MT_shape_key_specials(Menu):
45     bl_label = "Shape Key Specials"
46     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
47
48     def draw(self, context):
49         layout = self.layout
50
51         layout.operator("object.shape_key_transfer", icon='COPY_ID')  # icon is not ideal
52         layout.operator("object.join_shapes", icon='COPY_ID')  # icon is not ideal
53         layout.operator("object.shape_key_mirror", icon='ARROW_LEFTRIGHT')
54         layout.operator("object.shape_key_add", icon='ZOOMIN', text="New Shape From Mix").from_mix = True
55
56
57 class MESH_UL_vgroups(UIList):
58     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
59         # assert(isinstance(item, bpy.types.VertexGroup)
60         vgroup = item
61         if self.layout_type in {'DEFAULT', 'COMPACT'}:
62             layout.label(vgroup.name, icon_value=icon)
63             icon = 'LOCKED' if vgroup.lock_weight else 'UNLOCKED'
64             layout.prop(vgroup, "lock_weight", text="", icon=icon, emboss=False)
65         elif self.layout_type in {'GRID'}:
66             layout.alignment = 'CENTER'
67             layout.label("", icon_value=icon)
68
69
70 class MESH_UL_shape_keys(UIList):
71     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
72         # assert(isinstance(item, bpy.types.ShapeKey)
73         obj = active_data
74         key = data
75         key_block = item
76         if self.layout_type in {'DEFAULT', 'COMPACT'}:
77             split = layout.split(0.66, False)
78             split.label(item.name, icon_value=icon)
79             row = split.row(True)
80             if key_block.mute or (obj.mode == 'EDIT' and not (obj.use_shape_key_edit_mode and obj.type == 'MESH')):
81                 row.active = False
82             if not item.relative_key or index > 0:
83                 row.prop(key_block, "value", text="", emboss=False)
84             else:
85                 row.label("")
86             row.prop(key_block, "mute", text="", emboss=False)
87         elif self.layout_type in {'GRID'}:
88             layout.alignment = 'CENTER'
89             layout.label("", icon_value=icon)
90
91
92 class MESH_UL_uvmaps_vcols(UIList):
93     def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
94         # assert(isinstance(item, (bpy.types.MeshTexturePolyLayer, bpy.types.MeshLoopColorLayer))
95         if self.layout_type in {'DEFAULT', 'COMPACT'}:
96             layout.label(item.name, icon_value=icon)
97             icon = 'RESTRICT_RENDER_OFF' if item.active_render else 'RESTRICT_RENDER_ON'
98             layout.prop(item, "active_render", text="", icon=icon, emboss=False)
99         elif self.layout_type in {'GRID'}:
100             layout.alignment = 'CENTER'
101             layout.label("", icon_value=icon)
102
103
104 class MeshButtonsPanel():
105     bl_space_type = 'PROPERTIES'
106     bl_region_type = 'WINDOW'
107     bl_context = "data"
108
109     @classmethod
110     def poll(cls, context):
111         engine = context.scene.render.engine
112         return context.mesh and (engine in cls.COMPAT_ENGINES)
113
114
115 class DATA_PT_context_mesh(MeshButtonsPanel, Panel):
116     bl_label = ""
117     bl_options = {'HIDE_HEADER'}
118     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
119
120     def draw(self, context):
121         layout = self.layout
122
123         ob = context.object
124         mesh = context.mesh
125         space = context.space_data
126
127         if ob:
128             layout.template_ID(ob, "data")
129         elif mesh:
130             layout.template_ID(space, "pin_id")
131
132
133 class DATA_PT_normals(MeshButtonsPanel, Panel):
134     bl_label = "Normals"
135     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
136
137     def draw(self, context):
138         layout = self.layout
139
140         mesh = context.mesh
141
142         split = layout.split()
143
144         col = split.column()
145         col.prop(mesh, "use_auto_smooth")
146         sub = col.column()
147         sub.active = mesh.use_auto_smooth
148         sub.prop(mesh, "auto_smooth_angle", text="Angle")
149
150         split.prop(mesh, "show_double_sided")
151
152
153 class DATA_PT_texture_space(MeshButtonsPanel, Panel):
154     bl_label = "Texture Space"
155     bl_options = {'DEFAULT_CLOSED'}
156     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
157
158     def draw(self, context):
159         layout = self.layout
160
161         mesh = context.mesh
162
163         layout.prop(mesh, "texture_mesh")
164
165         layout.separator()
166
167         layout.prop(mesh, "use_auto_texspace")
168         row = layout.row()
169         row.column().prop(mesh, "texspace_location", text="Location")
170         row.column().prop(mesh, "texspace_size", text="Size")
171
172
173 class DATA_PT_vertex_groups(MeshButtonsPanel, Panel):
174     bl_label = "Vertex Groups"
175     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
176
177     @classmethod
178     def poll(cls, context):
179         engine = context.scene.render.engine
180         obj = context.object
181         return (obj and obj.type in {'MESH', 'LATTICE'} and (engine in cls.COMPAT_ENGINES))
182
183     def draw(self, context):
184         layout = self.layout
185
186         ob = context.object
187         group = ob.vertex_groups.active
188
189         rows = 2
190         if group:
191             rows = 5
192
193         row = layout.row()
194         row.template_list("MESH_UL_vgroups", "", ob, "vertex_groups", ob.vertex_groups, "active_index", rows=rows)
195
196
197         col = row.column(align=True)
198         col.operator("object.vertex_group_add", icon='ZOOMIN', text="")
199         col.operator("object.vertex_group_remove", icon='ZOOMOUT', text="").all = False
200         col.menu("MESH_MT_vertex_group_specials", icon='DOWNARROW_HLT', text="")
201         if group:
202             col.separator()
203             col.operator("object.vertex_group_move", icon='TRIA_UP', text="").direction = 'UP'
204             col.operator("object.vertex_group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
205
206         if group:
207             row = layout.row()
208             row.prop(group, "name")
209
210         if ob.vertex_groups and (ob.mode == 'EDIT' or (ob.mode == 'WEIGHT_PAINT' and ob.type == 'MESH' and ob.data.use_paint_mask_vertex)):
211             row = layout.row()
212
213             sub = row.row(align=True)
214             sub.operator("object.vertex_group_assign", text="Assign").new = False
215             sub.operator("object.vertex_group_remove_from", text="Remove")
216
217             sub = row.row(align=True)
218             sub.operator("object.vertex_group_select", text="Select")
219             sub.operator("object.vertex_group_deselect", text="Deselect")
220
221             layout.prop(context.tool_settings, "vertex_group_weight", text="Weight")
222
223
224 class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
225     bl_label = "Shape Keys"
226     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
227
228     @classmethod
229     def poll(cls, context):
230         engine = context.scene.render.engine
231         obj = context.object
232         return (obj and obj.type in {'MESH', 'LATTICE', 'CURVE', 'SURFACE'} and (engine in cls.COMPAT_ENGINES))
233
234     def draw(self, context):
235         layout = self.layout
236
237         ob = context.object
238         key = ob.data.shape_keys
239         kb = ob.active_shape_key
240
241         enable_edit = ob.mode != 'EDIT'
242         enable_edit_value = False
243
244         if ob.show_only_shape_key is False:
245             if enable_edit or (ob.type == 'MESH' and ob.use_shape_key_edit_mode):
246                 enable_edit_value = True
247
248         row = layout.row()
249
250         rows = 2
251         if kb:
252             rows = 5
253         row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
254
255         col = row.column()
256
257         sub = col.column(align=True)
258         sub.operator("object.shape_key_add", icon='ZOOMIN', text="").from_mix = False
259         sub.operator("object.shape_key_remove", icon='ZOOMOUT', text="")
260         sub.menu("MESH_MT_shape_key_specials", icon='DOWNARROW_HLT', text="")
261
262         if kb:
263             col.separator()
264
265             sub = col.column(align=True)
266             sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
267             sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
268
269             split = layout.split(percentage=0.4)
270             row = split.row()
271             row.enabled = enable_edit
272             row.prop(key, "use_relative")
273
274             row = split.row()
275             row.alignment = 'RIGHT'
276
277             sub = row.row(align=True)
278             sub.label()  # XXX, for alignment only
279             subsub = sub.row(align=True)
280             subsub.active = enable_edit_value
281             subsub.prop(ob, "show_only_shape_key", text="")
282             sub.prop(ob, "use_shape_key_edit_mode", text="")
283
284             sub = row.row()
285             if key.use_relative:
286                 sub.operator("object.shape_key_clear", icon='X', text="")
287             else:
288                 sub.operator("object.shape_key_retime", icon='RECOVER_LAST', text="")
289
290             row = layout.row()
291             row.prop(kb, "name")
292
293             if key.use_relative:
294                 if ob.active_shape_key_index != 0:
295                     row = layout.row()
296                     row.active = enable_edit_value
297                     row.prop(kb, "value")
298
299                     split = layout.split()
300
301                     col = split.column(align=True)
302                     col.active = enable_edit_value
303                     col.label(text="Range:")
304                     col.prop(kb, "slider_min", text="Min")
305                     col.prop(kb, "slider_max", text="Max")
306
307                     col = split.column(align=True)
308                     col.active = enable_edit_value
309                     col.label(text="Blend:")
310                     col.prop_search(kb, "vertex_group", ob, "vertex_groups", text="")
311                     col.prop_search(kb, "relative_key", key, "key_blocks", text="")
312
313             else:
314                 layout.prop(kb, "interpolation")
315                 row = layout.column()
316                 row.active = enable_edit_value
317                 row.prop(key, "eval_time")
318                 row.prop(key, "slurph")
319
320
321 class DATA_PT_uv_texture(MeshButtonsPanel, Panel):
322     bl_label = "UV Maps"
323     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
324
325     def draw(self, context):
326         layout = self.layout
327
328         me = context.mesh
329
330         row = layout.row()
331         col = row.column()
332
333         col.template_list("MESH_UL_uvmaps_vcols", "", me, "uv_textures", me.uv_textures, "active_index", rows=2)
334
335         col = row.column(align=True)
336         col.operator("mesh.uv_texture_add", icon='ZOOMIN', text="")
337         col.operator("mesh.uv_texture_remove", icon='ZOOMOUT', text="")
338
339         lay = me.uv_textures.active
340         if lay:
341             layout.prop(lay, "name")
342
343
344 class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
345     bl_label = "Vertex Colors"
346     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
347
348     def draw(self, context):
349         layout = self.layout
350
351         me = context.mesh
352
353         row = layout.row()
354         col = row.column()
355
356         col.template_list("MESH_UL_uvmaps_vcols", "", me, "vertex_colors", me.vertex_colors, "active_index", rows=2)
357
358         col = row.column(align=True)
359         col.operator("mesh.vertex_color_add", icon='ZOOMIN', text="")
360         col.operator("mesh.vertex_color_remove", icon='ZOOMOUT', text="")
361
362         lay = me.vertex_colors.active
363         if lay:
364             layout.prop(lay, "name")
365
366
367 class DATA_PT_customdata(MeshButtonsPanel, Panel):
368     bl_label = "Geometry Data"
369     bl_options = {'DEFAULT_CLOSED'}
370     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
371
372     def draw(self, context):
373         layout = self.layout
374
375         # me = context.mesh
376         col = layout.column()
377         # sticky has no UI access since 2.49 - we may remove
378         '''
379         row = col.row(align=True)
380         row.operator("mesh.customdata_create_sticky")
381         row.operator("mesh.customdata_clear_sticky", icon='X')
382         '''
383         col.operator("mesh.customdata_clear_mask", icon='X')
384         col.operator("mesh.customdata_clear_skin", icon='X')
385
386
387 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
388     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
389     _context_path = "object.data"
390     _property_type = bpy.types.Mesh
391
392
393 if __name__ == "__main__":  # only for live edit.
394     bpy.utils.register_module(__name__)