757745d039ea87db0d4bf7734699bc7f49a3f49f
[blender-staging.git] / release / ui / buttons_data_mesh.py
1
2 import bpy
3
4 class DataButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "data"
8         
9         def poll(self, context):
10                 return (context.mesh != None)
11
12 class DATA_PT_context_mesh(DataButtonsPanel):
13         __idname__ = "DATA_PT_context_mesh"
14         __no_header__ = True
15         
16         def draw(self, context):
17                 layout = self.layout
18                 
19                 ob = context.object
20                 mesh = context.mesh
21                 space = context.space_data
22
23                 split = layout.split(percentage=0.65)
24
25                 if ob:
26                         split.template_ID(ob, "data")
27                         split.itemS()
28                 elif mesh:
29                         split.template_ID(space, "pin_id")
30                         split.itemS()
31
32 class DATA_PT_normals(DataButtonsPanel):
33         __idname__ = "DATA_PT_normals"
34         __label__ = "Normals"
35
36         def draw(self, context):
37                 layout = self.layout
38                 
39                 mesh = context.mesh
40                 
41                 split = layout.split()
42                 
43                 col = split.column()
44                 col.itemR(mesh, "autosmooth")
45                 colsub = col.column()
46                 colsub.active = mesh.autosmooth
47                 colsub.itemR(mesh, "autosmooth_angle", text="Angle")
48                 sub = split.column()
49                 sub.itemR(mesh, "vertex_normal_flip")
50                 sub.itemR(mesh, "double_sided")
51
52                 row = layout.row(align=True)
53                 if context.edit_object:
54                         row.itemO("MESH_OT_faces_shade_smooth")
55                         row.itemO("MESH_OT_faces_shade_flat")
56                 else:
57                         row.itemO("OBJECT_OT_shade_smooth")
58                         row.itemO("OBJECT_OT_shade_flat")
59
60 class DATA_PT_vertex_groups(DataButtonsPanel):
61         __idname__ = "DATA_PT_vertex_groups"
62         __label__ = "Vertex Groups"
63         
64         def poll(self, context):
65                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
66
67         def draw(self, context):
68                 layout = self.layout
69                 ob = context.object
70
71                 row = layout.row()
72
73                 row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index")
74
75                 col = row.column(align=True)
76                 col.itemO("object.vertex_group_add", icon="ICON_ZOOMIN", text="")
77                 col.itemO("object.vertex_group_remove", icon="ICON_ZOOMOUT", text="")
78
79                 col.itemO("object.vertex_group_copy", icon="ICON_BLANK1", text="")
80                 if ob.data.users > 1:
81                         col.itemO("object.vertex_group_copy_to_linked", icon="ICON_BLANK1", text="")
82
83                 group = ob.active_vertex_group
84                 if group:
85                         row = layout.row()
86                         row.itemR(group, "name")
87
88                 if context.edit_object:
89                         row = layout.row(align=True)
90
91                         row.itemO("object.vertex_group_assign", text="Assign")
92                         row.itemO("object.vertex_group_remove_from", text="Remove")
93                         row.itemO("object.vertex_group_select", text="Select")
94                         row.itemO("object.vertex_group_deselect", text="Deselect")
95
96                         layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
97
98 class DATA_PT_shape_keys(DataButtonsPanel):
99         __idname__ = "DATA_PT_shape_keys"
100         __label__ = "Shape Keys"
101         
102         def poll(self, context):
103                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
104
105         def draw(self, context):
106                 layout = self.layout
107                 ob = context.object
108                 key = ob.data.shape_keys
109                 kb = ob.active_shape_key
110
111                 row = layout.row()
112                 row.template_list(key, "keys", ob, "active_shape_key_index")
113
114                 col = row.column()
115
116                 subcol = col.column(align=True)
117                 subcol.itemO("object.shape_key_add", icon="ICON_ZOOMIN", text="")
118                 subcol.itemO("object.shape_key_remove", icon="ICON_ZOOMOUT", text="")
119
120                 if kb:
121                         col.itemS()
122
123                         subcol = col.column(align=True)
124                         subcol.itemR(ob, "shape_key_lock", icon="ICON_UNPINNED", text="")
125                         subcol.itemR(kb, "mute", icon="ICON_MUTE_IPO_ON", text="")
126
127                         if key.relative:
128                                 row = layout.row()
129                                 row.itemR(key, "relative")
130                                 row.itemL()
131
132                                 row = layout.row()
133                                 row.itemR(kb, "name")
134
135                                 if ob.active_shape_key_index != 0:
136                                         if not ob.shape_key_lock:
137                                                 row = layout.row(align=True)
138                                                 row.itemR(kb, "value", text="")
139                                                 row.itemR(kb, "slider_min", text="Min")
140                                                 row.itemR(kb, "slider_max", text="Max")
141
142                                         row = layout.row()
143                                         row.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
144                                         row.item_pointerR(kb, "relative_key", key, "keys", text="")
145                         else:
146                                 row = layout.row()
147                                 row.itemR(key, "relative")
148                                 row.itemR(key, "slurph")
149
150                                 row = layout.row()
151                                 row.itemR(kb, "name")
152
153                 if context.edit_object:
154                         layout.enabled = False
155
156 class DATA_PT_uv_texture(DataButtonsPanel):
157         __idname__ = "DATA_PT_uv_texture"
158         __label__ = "UV Texture"
159         
160         def draw(self, context):
161                 layout = self.layout
162                 me = context.mesh
163
164                 row = layout.row()
165
166                 col = row.column()
167                 col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
168
169                 col = row.column(align=True)
170                 col.itemO("mesh.uv_texture_add", icon="ICON_ZOOMIN", text="")
171                 col.itemO("mesh.uv_texture_remove", icon="ICON_ZOOMOUT", text="")
172
173                 lay = me.active_uv_texture
174                 if lay:
175                         layout.itemR(lay, "name")
176
177 class DATA_PT_vertex_colors(DataButtonsPanel):
178         __idname__ = "DATA_PT_vertex_colors"
179         __label__ = "Vertex Colors"
180         
181         def draw(self, context):
182                 layout = self.layout
183                 me = context.mesh
184
185                 row = layout.row()
186                 col = row.column()
187
188                 col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
189
190                 col = row.column(align=True)
191                 col.itemO("mesh.vertex_color_add", icon="ICON_ZOOMIN", text="")
192                 col.itemO("mesh.vertex_color_remove", icon="ICON_ZOOMOUT", text="")
193
194                 lay = me.active_vertex_color
195                 if lay:
196                         layout.itemR(lay, "name")
197
198 bpy.types.register(DATA_PT_context_mesh)
199 bpy.types.register(DATA_PT_normals)
200 bpy.types.register(DATA_PT_vertex_groups)
201 bpy.types.register(DATA_PT_shape_keys)
202 bpy.types.register(DATA_PT_uv_texture)
203 bpy.types.register(DATA_PT_vertex_colors)
204