d4bf9698a895d3d9326286df17ae350a857af94f
[blender.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 class DATA_PT_vertex_groups(DataButtonsPanel):
53         __idname__ = "DATA_PT_vertex_groups"
54         __label__ = "Vertex Groups"
55         
56         def poll(self, context):
57                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
58
59         def draw(self, context):
60                 layout = self.layout
61                 ob = context.object
62
63                 row = layout.row()
64
65                 row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index")
66
67                 col = row.column(align=True)
68                 col.itemO("object.vertex_group_add", icon="ICON_ZOOMIN", text="")
69                 col.itemO("object.vertex_group_remove", icon="ICON_ZOOMOUT", text="")
70
71                 col.itemO("object.vertex_group_copy", icon="ICON_BLANK1", text="")
72                 if ob.data.users > 1:
73                         col.itemO("object.vertex_group_copy_to_linked", icon="ICON_BLANK1", text="")
74
75                 group = ob.active_vertex_group
76                 if group:
77                         row = layout.row()
78                         row.itemR(group, "name")
79
80                 if context.edit_object:
81                         row = layout.row(align=True)
82
83                         row.itemO("object.vertex_group_assign", text="Assign")
84                         row.itemO("object.vertex_group_remove_from", text="Remove")
85                         row.itemO("object.vertex_group_select", text="Select")
86                         row.itemO("object.vertex_group_deselect", text="Deselect")
87
88                         layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
89
90 class DATA_PT_shape_keys(DataButtonsPanel):
91         __idname__ = "DATA_PT_shape_keys"
92         __label__ = "Shape Keys"
93         
94         def poll(self, context):
95                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
96
97         def draw(self, context):
98                 layout = self.layout
99                 ob = context.object
100                 key = ob.data.shape_keys
101                 kb = ob.active_shape_key
102
103                 row = layout.row()
104                 row.template_list(key, "keys", ob, "active_shape_key_index")
105
106                 col = row.column()
107
108                 subcol = col.column(align=True)
109                 subcol.itemO("object.shape_key_add", icon="ICON_ZOOMIN", text="")
110                 subcol.itemO("object.shape_key_remove", icon="ICON_ZOOMOUT", text="")
111
112                 if kb:
113                         col.itemS()
114
115                         subcol = col.column(align=True)
116                         subcol.itemR(ob, "shape_key_lock", icon="ICON_UNPINNED", text="")
117                         subcol.itemR(kb, "mute", icon="ICON_MUTE_IPO_ON", text="")
118
119                         if key.relative:
120                                 row = layout.row()
121                                 row.itemR(key, "relative")
122                                 row.itemL()
123
124                                 row = layout.row()
125                                 row.itemR(kb, "name")
126
127                                 if ob.active_shape_key_index != 0:
128                                         if not ob.shape_key_lock:
129                                                 row = layout.row(align=True)
130                                                 row.itemR(kb, "value", text="")
131                                                 row.itemR(kb, "slider_min", text="Min")
132                                                 row.itemR(kb, "slider_max", text="Max")
133
134                                         row = layout.row()
135                                         row.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
136                                         row.item_pointerR(kb, "relative_key", key, "keys", text="")
137                         else:
138                                 row = layout.row()
139                                 row.itemR(key, "relative")
140                                 row.itemR(key, "slurph")
141
142                                 row = layout.row()
143                                 row.itemR(kb, "name")
144
145                 if context.edit_object:
146                         layout.enabled = False
147
148 class DATA_PT_uv_texture(DataButtonsPanel):
149         __idname__ = "DATA_PT_uv_texture"
150         __label__ = "UV Texture"
151         
152         def draw(self, context):
153                 layout = self.layout
154                 me = context.mesh
155
156                 row = layout.row()
157
158                 col = row.column()
159                 col.template_list(me, "uv_textures", me, "active_uv_texture_index", rows=2)
160
161                 col = row.column(align=True)
162                 col.itemO("mesh.uv_texture_add", icon="ICON_ZOOMIN", text="")
163                 col.itemO("mesh.uv_texture_remove", icon="ICON_ZOOMOUT", text="")
164
165                 lay = me.active_uv_texture
166                 if lay:
167                         layout.itemR(lay, "name")
168
169 class DATA_PT_vertex_colors(DataButtonsPanel):
170         __idname__ = "DATA_PT_vertex_colors"
171         __label__ = "Vertex Colors"
172         
173         def draw(self, context):
174                 layout = self.layout
175                 me = context.mesh
176
177                 row = layout.row()
178                 col = row.column()
179
180                 col.template_list(me, "vertex_colors", me, "active_vertex_color_index", rows=2)
181
182                 col = row.column(align=True)
183                 col.itemO("mesh.vertex_color_add", icon="ICON_ZOOMIN", text="")
184                 col.itemO("mesh.vertex_color_remove", icon="ICON_ZOOMOUT", text="")
185
186                 lay = me.active_vertex_color
187                 if lay:
188                         layout.itemR(lay, "name")
189
190 bpy.types.register(DATA_PT_context_mesh)
191 bpy.types.register(DATA_PT_normals)
192 bpy.types.register(DATA_PT_vertex_groups)
193 bpy.types.register(DATA_PT_shape_keys)
194 bpy.types.register(DATA_PT_uv_texture)
195 bpy.types.register(DATA_PT_vertex_colors)
196