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