2.5 Part 1 of Layout Code Cleanup:
[blender-staging.git] / release / ui / buttons_data_bone.py
1
2 import bpy
3  
4 class BoneButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
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                 bone = context.bone
78                 arm = context.armature
79                 if not bone:
80                         bone = context.edit_bone
81
82                 split = layout.split()
83
84                 col = split.column()
85                 col.itemL(text="Parent:")
86                 if context.bone:
87                         col.itemR(bone, "parent", text="")
88                 else:
89                         col.item_pointerR(bone, "parent", arm, "edit_bones", text="")
90
91                 row = col.row()
92                 row.active = bone.parent != None
93                 row.itemR(bone, "connected")
94
95                 col.itemL(text="Layers:")
96                 col.template_layers(bone, "layer")
97
98                 col = split.column()
99                 col.itemL(text="Inherit:")
100                 col.itemR(bone, "hinge", text="Rotation")
101                 col.itemR(bone, "inherit_scale", text="Scale")
102                 col.itemL(text="Display:")
103                 col.itemR(bone, "draw_wire", text="Wireframe")
104                 col.itemR(bone, "hidden", text="Hide")
105
106 class BONE_PT_inverse_kinematics(BoneButtonsPanel):
107         __label__ = "Inverse Kinematics"
108         __default_closed__ = True
109         
110         def poll(self, context):
111                 ob = context.object
112                 bone = context.bone
113
114                 if ob and context.bone:
115                         pchan = ob.pose.pose_channels[context.bone.name]
116                         return pchan.has_ik
117                 
118                 return False
119
120         def draw(self, context):
121                 layout = self.layout
122                 
123                 ob = context.object
124                 bone = context.bone
125                 pchan = ob.pose.pose_channels[context.bone.name]
126
127                 split = layout.split(percentage=0.25)
128                 split.itemR(pchan, "ik_dof_x", text="X")
129                 row = split.row()
130                 row.itemR(pchan, "ik_stiffness_x", text="Stiffness")
131                 row.active = pchan.ik_dof_x
132
133                 split = layout.split(percentage=0.25)
134                 row = split.row()
135                 row.itemR(pchan, "ik_limit_x", text="Limit")
136                 row.active = pchan.ik_dof_x
137                 row = split.row(align=True)
138                 row.itemR(pchan, "ik_min_x", text="")
139                 row.itemR(pchan, "ik_max_x", text="")
140                 row.active = pchan.ik_dof_x and pchan.ik_limit_x
141
142                 split = layout.split(percentage=0.25)
143                 split.itemR(pchan, "ik_dof_y", text="Y")
144                 row = split.row()
145                 row.itemR(pchan, "ik_stiffness_y", text="Stiffness")
146                 row.active = pchan.ik_dof_y
147
148                 split = layout.split(percentage=0.25)
149                 row = split.row()
150                 row.itemR(pchan, "ik_limit_y", text="Limit")
151                 row.active = pchan.ik_dof_y
152                 row = split.row(align=True)
153                 row.itemR(pchan, "ik_min_y", text="")
154                 row.itemR(pchan, "ik_max_y", text="")
155                 row.active = pchan.ik_dof_y and pchan.ik_limit_y
156
157                 split = layout.split(percentage=0.25)
158                 split.itemR(pchan, "ik_dof_z", text="Z")
159                 row = split.row()
160                 row.itemR(pchan, "ik_stiffness_z", text="Stiffness")
161                 row.active = pchan.ik_dof_z
162
163                 split = layout.split(percentage=0.25)
164                 row = split.row()
165                 row.itemR(pchan, "ik_limit_z", text="Limit")
166                 row.active = pchan.ik_dof_z
167                 row = split.row(align=True)
168                 row.itemR(pchan, "ik_min_z", text="")
169                 row.itemR(pchan, "ik_max_z", text="")
170                 row.active = pchan.ik_dof_z and pchan.ik_limit_z
171
172                 split = layout.split()
173                 split.itemR(pchan, "ik_stretch", text="Stretch")
174                 split.itemL()
175
176 class BONE_PT_deform(BoneButtonsPanel):
177         __label__ = "Deform"
178         __default_closed__ = True
179
180         def draw_header(self, context):
181                 layout = self.layout
182                 
183                 bone = context.bone
184                 if not bone:
185                         bone = context.edit_bone
186                         
187                 layout.itemR(bone, "deform", text="")
188
189         def draw(self, context):
190                 layout = self.layout
191                 
192                 bone = context.bone
193                 if not bone:
194                         bone = context.edit_bone
195         
196                 layout.active = bone.deform
197                         
198                 split = layout.split()
199
200                 col = split.column()
201                 col.itemL(text="Envelope:")
202                 
203                 sub = col.column(align=True)
204                 sub.itemR(bone, "envelope_distance", text="Distance")
205                 sub.itemR(bone, "envelope_weight", text="Weight")
206                 col.itemR(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
207
208                 sub = col.column(align=True)
209                 sub.itemL(text="Radius:")
210                 sub.itemR(bone, "head_radius", text="Head")
211                 sub.itemR(bone, "tail_radius", text="Tail")
212
213                 col = split.column()
214                 col.itemL(text="Curved Bones:")
215                 
216                 sub = col.column(align=True)
217                 sub.itemR(bone, "bbone_segments", text="Segments")
218                 sub.itemR(bone, "bbone_in", text="Ease In")
219                 sub.itemR(bone, "bbone_out", text="Ease Out")
220                 
221                 col.itemL(text="Offset:")
222                 col.itemR(bone, "cyclic_offset")
223
224 bpy.types.register(BONE_PT_context_bone)
225 bpy.types.register(BONE_PT_transform)
226 bpy.types.register(BONE_PT_bone)
227 bpy.types.register(BONE_PT_deform)
228 bpy.types.register(BONE_PT_inverse_kinematics)