more ui api changes.
[blender.git] / release / scripts / ui / properties_data_bone.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21
22 narrowui = 180
23
24
25 class BoneButtonsPanel(bpy.types.Panel):
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "bone"
29
30     def poll(self, context):
31         return (context.bone or context.edit_bone)
32
33
34 class BONE_PT_context_bone(BoneButtonsPanel):
35     bl_label = ""
36     bl_show_header = False
37
38     def draw(self, context):
39         layout = self.layout
40
41         bone = context.bone
42         if not bone:
43             bone = context.edit_bone
44
45         row = layout.row()
46         row.label(text="", icon='ICON_BONE_DATA')
47         row.prop(bone, "name", text="")
48
49
50 class BONE_PT_transform(BoneButtonsPanel):
51     bl_label = "Transform"
52
53     def draw(self, context):
54         layout = self.layout
55
56         ob = context.object
57         bone = context.bone
58         wide_ui = context.region.width > narrowui
59
60         if not bone:
61             bone = context.edit_bone
62             if wide_ui:
63                 row = layout.row()
64                 row.column().prop(bone, "head")
65                 row.column().prop(bone, "tail")
66
67                 col = row.column()
68                 sub = col.column(align=True)
69                 sub.label(text="Roll:")
70                 sub.prop(bone, "roll", text="")
71                 sub.label()
72                 sub.prop(bone, "locked")
73             else:
74                 col = layout.column()
75                 col.prop(bone, "head")
76                 col.prop(bone, "tail")
77                 col.prop(bone, "roll")
78                 col.prop(bone, "locked")
79
80         else:
81             pchan = ob.pose.bones[context.bone.name]
82
83             if wide_ui:
84                 row = layout.row()
85                 col = row.column()
86                 col.prop(pchan, "location")
87                 col.active = not (bone.parent and bone.connected)
88
89                 col = row.column()
90                 if pchan.rotation_mode == 'QUATERNION':
91                     col.prop(pchan, "rotation_quaternion", text="Rotation")
92                 elif pchan.rotation_mode == 'AXIS_ANGLE':
93                     #col.label(text="Rotation")
94                     #col.prop(pchan, "rotation_angle", text="Angle")
95                     #col.prop(pchan, "rotation_axis", text="Axis")
96                     col.prop(pchan, "rotation_axis_angle", text="Rotation")
97                 else:
98                     col.prop(pchan, "rotation_euler", text="Rotation")
99
100                 row.column().prop(pchan, "scale")
101
102                 layout.prop(pchan, "rotation_mode")
103             else:
104                 col = layout.column()
105                 sub = col.column()
106                 sub.active = not (bone.parent and bone.connected)
107                 sub.prop(pchan, "location")
108                 col.label(text="Rotation:")
109                 col.prop(pchan, "rotation_mode", text="")
110                 if pchan.rotation_mode == 'QUATERNION':
111                     col.prop(pchan, "rotation_quaternion", text="")
112                 elif pchan.rotation_mode == 'AXIS_ANGLE':
113                     col.prop(pchan, "rotation_axis_angle", text="")
114                 else:
115                     col.prop(pchan, "rotation_euler", text="")
116                 col.prop(pchan, "scale")
117
118
119 class BONE_PT_transform_locks(BoneButtonsPanel):
120     bl_label = "Transform Locks"
121     bl_default_closed = True
122
123     def poll(self, context):
124         return context.bone
125
126     def draw(self, context):
127         layout = self.layout
128
129         ob = context.object
130         bone = context.bone
131         pchan = ob.pose.bones[context.bone.name]
132
133         row = layout.row()
134         col = row.column()
135         col.prop(pchan, "lock_location")
136         col.active = not (bone.parent and bone.connected)
137
138         col = row.column()
139         if pchan.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
140             col.prop(pchan, "lock_rotations_4d", text="Lock Rotation")
141             if pchan.lock_rotations_4d:
142                 col.prop(pchan, "lock_rotation_w", text="W")
143             col.prop(pchan, "lock_rotation", text="")
144         else:
145             col.prop(pchan, "lock_rotation", text="Rotation")
146
147         row.column().prop(pchan, "lock_scale")
148
149
150 class BONE_PT_relations(BoneButtonsPanel):
151     bl_label = "Relations"
152
153     def draw(self, context):
154         layout = self.layout
155
156         ob = context.object
157         bone = context.bone
158         arm = context.armature
159         wide_ui = context.region.width > narrowui
160
161         if not bone:
162             bone = context.edit_bone
163             pchan = None
164         else:
165             pchan = ob.pose.bones[context.bone.name]
166
167         split = layout.split()
168
169         col = split.column()
170         col.label(text="Layers:")
171         col.prop(bone, "layer", text="")
172
173         col.separator()
174
175         if ob and pchan:
176             col.label(text="Bone Group:")
177             col.prop_object(pchan, "bone_group", ob.pose, "bone_groups", text="")
178
179         if wide_ui:
180             col = split.column()
181         col.label(text="Parent:")
182         if context.bone:
183             col.prop(bone, "parent", text="")
184         else:
185             col.prop_object(bone, "parent", arm, "edit_bones", text="")
186
187         sub = col.column()
188         sub.active = (bone.parent is not None)
189         sub.prop(bone, "connected")
190         sub.prop(bone, "hinge", text="Inherit Rotation")
191         sub.prop(bone, "inherit_scale", text="Inherit Scale")
192
193
194 class BONE_PT_display(BoneButtonsPanel):
195     bl_label = "Display"
196
197     def poll(self, context):
198         return context.bone
199
200     def draw(self, context):
201         layout = self.layout
202
203         ob = context.object
204         bone = context.bone
205         wide_ui = context.region.width > narrowui
206
207         if not bone:
208             bone = context.edit_bone
209             pchan = None
210         else:
211             pchan = ob.pose.bones[context.bone.name]
212
213         if ob and pchan:
214
215             split = layout.split()
216
217             col = split.column()
218             col.prop(bone, "draw_wire", text="Wireframe")
219             col.prop(bone, "hidden", text="Hide")
220
221             if wide_ui:
222                 col = split.column()
223             col.label(text="Custom Shape:")
224             col.prop(pchan, "custom_shape", text="")
225
226
227 class BONE_PT_deform(BoneButtonsPanel):
228     bl_label = "Deform"
229     bl_default_closed = True
230
231     def draw_header(self, context):
232         bone = context.bone
233
234         if not bone:
235             bone = context.edit_bone
236
237         self.layout.prop(bone, "deform", text="")
238
239     def draw(self, context):
240         layout = self.layout
241
242         bone = context.bone
243         wide_ui = context.region.width > narrowui
244
245         if not bone:
246             bone = context.edit_bone
247
248         layout.active = bone.deform
249
250         split = layout.split()
251
252         col = split.column()
253         col.label(text="Envelope:")
254
255         sub = col.column(align=True)
256         sub.prop(bone, "envelope_distance", text="Distance")
257         sub.prop(bone, "envelope_weight", text="Weight")
258         col.prop(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
259
260         sub = col.column(align=True)
261         sub.label(text="Radius:")
262         sub.prop(bone, "head_radius", text="Head")
263         sub.prop(bone, "tail_radius", text="Tail")
264
265         if wide_ui:
266             col = split.column()
267         col.label(text="Curved Bones:")
268
269         sub = col.column(align=True)
270         sub.prop(bone, "bbone_segments", text="Segments")
271         sub.prop(bone, "bbone_in", text="Ease In")
272         sub.prop(bone, "bbone_out", text="Ease Out")
273
274         col.label(text="Offset:")
275         col.prop(bone, "cyclic_offset")
276
277
278 class BONE_PT_properties(BoneButtonsPanel):
279     bl_label = "Properties"
280     bl_default_closed = True
281
282     def draw(self, context):
283         import rna_prop_ui
284         # reload(rna_prop_ui)
285         obj = context.object
286         if obj and obj.mode == 'POSE':
287             item = "active_pchan"
288         else:
289             item = "active_bone"
290
291         rna_prop_ui.draw(self.layout, context, item)
292
293 bpy.types.register(BONE_PT_context_bone)
294 bpy.types.register(BONE_PT_transform)
295 bpy.types.register(BONE_PT_transform_locks)
296 bpy.types.register(BONE_PT_relations)
297 bpy.types.register(BONE_PT_display)
298 bpy.types.register(BONE_PT_deform)
299 bpy.types.register(BONE_PT_properties)