2.5 - A few bugfixes...
[blender.git] / release / ui / buttons_data_bone.py
1
2 import bpy
3  
4 class BoneButtonsPanel(bpy.types.Panel):
5         __space_type__ = 'PROPERTIES'
6         __region_type__ = 'WINDOW'
7         __context__ = "bone"
8         
9         def poll(self, context):
10                 return (context.bone or context.edit_bone)
11
12 class BONE_PT_context_bone(BoneButtonsPanel):
13         __show_header__ = False
14
15         def draw(self, context):
16                 layout = self.layout
17                 
18                 bone = context.bone
19                 if not bone:
20                         bone = context.edit_bone
21                 
22                 row = layout.row()
23                 row.itemL(text="", icon='ICON_BONE_DATA')
24                 row.itemR(bone, "name", text="")
25
26 class BONE_PT_transform(BoneButtonsPanel):
27         __label__ = "Transform"
28
29         def draw(self, context):
30                 layout = self.layout
31                 
32                 ob = context.object
33                 bone = context.bone
34                 if not bone:
35                         bone = context.edit_bone
36
37                         row = layout.row()
38                         row.column().itemR(bone, "head")
39                         row.column().itemR(bone, "tail")
40
41                         col = row.column()
42                         sub = col.column(align=True)
43                         sub.itemL(text="Roll:")
44                         sub.itemR(bone, "roll", text="")
45                         sub.itemL()
46                         sub.itemR(bone, "locked")
47
48                 else:
49                         pchan = ob.pose.pose_channels[context.bone.name]
50
51                         layout.itemR(pchan, "rotation_mode")
52
53                         row = layout.row()
54                         col = row.column()
55                         col.itemR(pchan, "location")
56                         col.active = not (bone.parent and bone.connected)
57
58                         col = row.column()
59                         if pchan.rotation_mode == 'QUATERNION':
60                                 col.itemR(pchan, "rotation", text="Rotation")
61                         else:
62                                 col.itemR(pchan, "euler_rotation", text="Rotation")
63
64                         row.column().itemR(pchan, "scale")
65
66                         if pchan.rotation_mode == 'QUATERNION':
67                                 col = layout.column(align=True)
68                                 col.itemL(text="Euler:")
69                                 col.row().itemR(pchan, "euler_rotation", text="")
70
71 class BONE_PT_bone(BoneButtonsPanel):
72         __label__ = "Bone"
73
74         def draw(self, context):
75                 layout = self.layout
76                 
77                 ob = context.object
78                 bone = context.bone
79                 arm = context.armature
80                 
81                 if not bone:
82                         bone = context.edit_bone
83                         pchan = None
84                 else:
85                         pchan = ob.pose.pose_channels[context.bone.name]
86
87                 split = layout.split()
88
89                 col = split.column()
90                 col.itemL(text="Parent:")
91                 if context.bone:
92                         col.itemR(bone, "parent", text="")
93                 else:
94                         col.item_pointerR(bone, "parent", arm, "edit_bones", text="")
95                 
96                 row = col.row()
97                 row.active = bone.parent != None
98                 row.itemR(bone, "connected")
99                 
100                 col.itemL(text="Layers:")
101                 col.template_layers(bone, "layer")
102                 
103                 col = split.column()
104                 col.itemL(text="Inherit:")
105                 col.itemR(bone, "hinge", text="Rotation")
106                 col.itemR(bone, "inherit_scale", text="Scale")
107                 col.itemL(text="Display:")
108                 col.itemR(bone, "draw_wire", text="Wireframe")
109                 col.itemR(bone, "hidden", text="Hide")
110                 
111                 if ob and pchan:
112                         split = layout.split()
113                         
114                         col = split.column()
115                         col.itemL(text="Bone Group:")
116                         col.item_pointerR(pchan, "bone_group", ob.pose, "bone_groups", text="")
117                         
118                         col = split.column()
119                         col.itemL(text="Custom Shape:")
120                         col.itemR(pchan, "custom_shape", text="")
121
122 class BONE_PT_inverse_kinematics(BoneButtonsPanel):
123         __label__ = "Inverse Kinematics"
124         __default_closed__ = True
125         
126         def poll(self, context):
127                 ob = context.object
128                 bone = context.bone
129
130                 if ob and context.bone:
131                         pchan = ob.pose.pose_channels[context.bone.name]
132                         return pchan.has_ik
133                 
134                 return False
135
136         def draw(self, context):
137                 layout = self.layout
138                 
139                 ob = context.object
140                 bone = context.bone
141                 pchan = ob.pose.pose_channels[context.bone.name]
142
143                 split = layout.split(percentage=0.25)
144                 split.itemR(pchan, "ik_dof_x", text="X")
145                 row = split.row()
146                 row.itemR(pchan, "ik_stiffness_x", text="Stiffness")
147                 row.active = pchan.ik_dof_x
148
149                 split = layout.split(percentage=0.25)
150                 row = split.row()
151                 row.itemR(pchan, "ik_limit_x", text="Limit")
152                 row.active = pchan.ik_dof_x
153                 row = split.row(align=True)
154                 row.itemR(pchan, "ik_min_x", text="")
155                 row.itemR(pchan, "ik_max_x", text="")
156                 row.active = pchan.ik_dof_x and pchan.ik_limit_x
157
158                 split = layout.split(percentage=0.25)
159                 split.itemR(pchan, "ik_dof_y", text="Y")
160                 row = split.row()
161                 row.itemR(pchan, "ik_stiffness_y", text="Stiffness")
162                 row.active = pchan.ik_dof_y
163
164                 split = layout.split(percentage=0.25)
165                 row = split.row()
166                 row.itemR(pchan, "ik_limit_y", text="Limit")
167                 row.active = pchan.ik_dof_y
168                 row = split.row(align=True)
169                 row.itemR(pchan, "ik_min_y", text="")
170                 row.itemR(pchan, "ik_max_y", text="")
171                 row.active = pchan.ik_dof_y and pchan.ik_limit_y
172
173                 split = layout.split(percentage=0.25)
174                 split.itemR(pchan, "ik_dof_z", text="Z")
175                 row = split.row()
176                 row.itemR(pchan, "ik_stiffness_z", text="Stiffness")
177                 row.active = pchan.ik_dof_z
178
179                 split = layout.split(percentage=0.25)
180                 row = split.row()
181                 row.itemR(pchan, "ik_limit_z", text="Limit")
182                 row.active = pchan.ik_dof_z
183                 row = split.row(align=True)
184                 row.itemR(pchan, "ik_min_z", text="")
185                 row.itemR(pchan, "ik_max_z", text="")
186                 row.active = pchan.ik_dof_z and pchan.ik_limit_z
187
188                 split = layout.split()
189                 split.itemR(pchan, "ik_stretch", text="Stretch")
190                 split.itemL()
191
192 class BONE_PT_deform(BoneButtonsPanel):
193         __label__ = "Deform"
194         __default_closed__ = True
195
196         def draw_header(self, context):
197                 bone = context.bone
198                 
199                 if not bone:
200                         bone = context.edit_bone
201                         
202                 self.layout.itemR(bone, "deform", text="")
203
204         def draw(self, context):
205                 layout = self.layout
206                 
207                 bone = context.bone
208                 
209                 if not bone:
210                         bone = context.edit_bone
211         
212                 layout.active = bone.deform
213                         
214                 split = layout.split()
215
216                 col = split.column()
217                 col.itemL(text="Envelope:")
218                 
219                 sub = col.column(align=True)
220                 sub.itemR(bone, "envelope_distance", text="Distance")
221                 sub.itemR(bone, "envelope_weight", text="Weight")
222                 col.itemR(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
223
224                 sub = col.column(align=True)
225                 sub.itemL(text="Radius:")
226                 sub.itemR(bone, "head_radius", text="Head")
227                 sub.itemR(bone, "tail_radius", text="Tail")
228
229                 col = split.column()
230                 col.itemL(text="Curved Bones:")
231                 
232                 sub = col.column(align=True)
233                 sub.itemR(bone, "bbone_segments", text="Segments")
234                 sub.itemR(bone, "bbone_in", text="Ease In")
235                 sub.itemR(bone, "bbone_out", text="Ease Out")
236                 
237                 col.itemL(text="Offset:")
238                 col.itemR(bone, "cyclic_offset")
239
240 bpy.types.register(BONE_PT_context_bone)
241 bpy.types.register(BONE_PT_transform)
242 bpy.types.register(BONE_PT_bone)
243 bpy.types.register(BONE_PT_deform)
244 bpy.types.register(BONE_PT_inverse_kinematics)