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