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