Patch from William
[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
13 class DATA_PT_context2(DataButtonsPanel):
14         __idname__ = "DATA_PT_context2"
15         __label__ = " "
16         
17         def poll(self, context):
18                 return (context.object and context.object.type == 'MESH')
19
20         def draw(self, context):
21                 layout = self.layout
22                 
23                 ob = context.object
24                 mesh = context.mesh
25                 space = context.space_data
26
27                 split = layout.split(percentage=0.65)
28
29                 if ob:
30                         split.template_ID(ob, "data")
31                         split.itemS()
32                 elif mesh:
33                         split.template_ID(space, "pin_id")
34                         split.itemS()
35
36
37
38
39 class DATA_PT_mesh(DataButtonsPanel):
40         __idname__ = "DATA_PT_mesh"
41         __label__ = "Mesh"
42         
43         def poll(self, context):
44                 return (context.object and context.object.type == 'MESH')
45
46         def draw(self, context):
47                 layout = self.layout
48                 
49                 ob = context.object
50                 mesh = context.mesh
51                 space = context.space_data
52
53                 if mesh:
54                         split = layout.split()
55                 
56                         col = split.column()
57                         col.itemR(mesh, "autosmooth")
58                         colsub = col.column()
59                         colsub.active = mesh.autosmooth
60                         colsub.itemR(mesh, "autosmooth_angle", text="Angle")
61                         sub = split.column()
62                         sub.itemR(mesh, "vertex_normal_flip")
63                         sub.itemR(mesh, "double_sided")
64                         
65                         layout.itemS()
66                         layout.itemR(mesh, "texco_mesh")
67
68
69 class DATA_PT_materials(DataButtonsPanel):
70         __idname__ = "DATA_PT_materials"
71         __label__ = "Materials"
72         
73         def poll(self, context):
74                 return (context.object and context.object.type in ('MESH', 'CURVE', 'FONT', 'SURFACE'))
75
76         def draw(self, context):
77                 layout = self.layout
78                 ob = context.object
79
80                 row = layout.row()
81
82                 row.template_list(ob, "materials", ob, "active_material_index")
83
84                 col = row.column(align=True)
85                 col.itemO("OBJECT_OT_material_slot_add", icon="ICON_ZOOMIN", text="")
86                 col.itemO("OBJECT_OT_material_slot_remove", icon="ICON_ZOOMOUT", text="")
87
88                 if context.edit_object:
89                         row = layout.row(align=True)
90
91                         row.itemO("OBJECT_OT_material_slot_assign", text="Assign")
92                         row.itemO("OBJECT_OT_material_slot_select", text="Select")
93                         row.itemO("OBJECT_OT_material_slot_deselect", text="Deselect")
94
95                 """
96                 layout.itemS()
97
98                 box= layout.box()
99
100                 row = box.row()
101                 row.template_list(ob, "materials", ob, "active_material_index", compact=True)
102
103                 subrow = row.row(align=True)
104                 subrow.itemO("OBJECT_OT_material_slot_add", icon="ICON_ZOOMIN", text="")
105                 subrow.itemO("OBJECT_OT_material_slot_remove", icon="ICON_ZOOMOUT", text="")
106                 """
107
108 class DATA_PT_vertex_groups(DataButtonsPanel):
109         __idname__ = "DATA_PT_vertex_groups"
110         __label__ = "Vertex Groups"
111         
112         def poll(self, context):
113                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
114
115         def draw(self, context):
116                 layout = self.layout
117                 ob = context.object
118
119                 row = layout.row()
120
121                 row.template_list(ob, "vertex_groups", ob, "active_vertex_group_index")
122
123                 col = row.column(align=True)
124                 col.itemO("OBJECT_OT_vertex_group_add", icon="ICON_ZOOMIN", text="")
125                 col.itemO("OBJECT_OT_vertex_group_remove", icon="ICON_ZOOMOUT", text="")
126
127                 col.itemO("OBJECT_OT_vertex_group_copy", icon="ICON_BLANK1", text="")
128                 if ob.data.users > 1:
129                         col.itemO("OBJECT_OT_vertex_group_copy_to_linked", icon="ICON_BLANK1", text="")
130
131                 if context.edit_object:
132                         row = layout.row(align=True)
133
134                         row.itemO("OBJECT_OT_vertex_group_assign", text="Assign")
135                         row.itemO("OBJECT_OT_vertex_group_remove_from", text="Remove")
136                         row.itemO("OBJECT_OT_vertex_group_select", text="Select")
137                         row.itemO("OBJECT_OT_vertex_group_deselect", text="Deselect")
138
139                         layout.itemR(context.tool_settings, "vertex_group_weight", text="Weight")
140
141 class DATA_PT_shape_keys(DataButtonsPanel):
142         __idname__ = "DATA_PT_shape_keys"
143         __label__ = "Shape Keys"
144         
145         def poll(self, context):
146                 return (context.object and context.object.type in ('MESH', 'LATTICE'))
147
148         def draw(self, context):
149                 layout = self.layout
150                 ob = context.object
151                 key = ob.data.shape_keys
152                 kb = ob.active_shape_key
153
154                 row = layout.row()
155                 row.template_list(key, "keys", ob, "active_shape_key_index")
156
157                 col = row.column()
158
159                 subcol = col.column(align=True)
160                 subcol.itemO("OBJECT_OT_shape_key_add", icon="ICON_ZOOMIN", text="")
161                 subcol.itemO("OBJECT_OT_shape_key_remove", icon="ICON_ZOOMOUT", text="")
162
163                 if kb:
164                         col.itemS()
165
166                         subcol = col.column(align=True)
167                         subcol.itemR(ob, "shape_key_lock", icon="ICON_PINNED", text="")
168                         subcol.itemR(kb, "mute", icon="ICON_MUTE_IPO_ON", text="")
169
170                         if key.relative:
171                                 row = layout.row()
172                                 row.itemR(key, "relative")
173                                 row.itemL()
174
175                                 if ob.active_shape_key_index != 0:
176                                         if not ob.shape_key_lock:
177                                                 row = layout.row(align=True)
178                                                 row.itemR(kb, "value", text="")
179                                                 row.itemR(kb, "slider_min", text="Min")
180                                                 row.itemR(kb, "slider_max", text="Max")
181
182                                         row = layout.row()
183                                         row.item_pointerR(kb, "vertex_group", ob, "vertex_groups", text="")
184                                         row.item_pointerR(kb, "relative_key", key, "keys", text="")
185                         else:
186                                 row = layout.row()
187                                 row.itemR(key, "relative")
188                                 row.itemR(key, "slurph")
189
190                 if context.edit_object:
191                         layout.enabled = False
192
193 class DATA_PT_uv_texture(DataButtonsPanel):
194         __idname__ = "DATA_PT_uv_texture"
195         __label__ = "UV Texture"
196         
197         def draw(self, context):
198                 layout = self.layout
199                 me = context.mesh
200
201                 row = layout.row()
202
203                 row.template_list(me, "uv_textures", me, "active_uv_texture_index")
204
205                 col = row.column(align=True)
206                 col.itemO("MESH_OT_uv_texture_add", icon="ICON_ZOOMIN", text="")
207                 col.itemO("MESH_OT_uv_texture_remove", icon="ICON_ZOOMOUT", text="")
208
209 class DATA_PT_vertex_colors(DataButtonsPanel):
210         __idname__ = "DATA_PT_vertex_colors"
211         __label__ = "Vertex Colors"
212         
213         def draw(self, context):
214                 layout = self.layout
215                 me = context.mesh
216
217                 row = layout.row()
218
219                 row.template_list(me, "vertex_colors", me, "active_vertex_color_index")
220
221                 col = row.column(align=True)
222                 col.itemO("MESH_OT_vertex_color_add", icon="ICON_ZOOMIN", text="")
223                 col.itemO("MESH_OT_vertex_color_remove", icon="ICON_ZOOMOUT", text="")
224
225 bpy.types.register(DATA_PT_context2)
226 bpy.types.register(DATA_PT_mesh)
227 bpy.types.register(DATA_PT_materials)
228 bpy.types.register(DATA_PT_vertex_groups)
229 bpy.types.register(DATA_PT_shape_keys)
230 bpy.types.register(DATA_PT_uv_texture)
231 bpy.types.register(DATA_PT_vertex_colors)
232