39e27ed6e208f7808337bb9fe58adbd46732381d
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from rna_prop_ui import PropertyPanel
22
23 narrowui = bpy.context.user_preferences.view.properties_width_check
24
25
26 class BoneButtonsPanel():
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "bone"
30
31     @staticmethod
32     def poll(context):
33         return (context.bone or context.edit_bone)
34
35
36 class BONE_PT_context_bone(BoneButtonsPanel, bpy.types.Panel):
37     bl_label = ""
38     bl_show_header = False
39
40     def draw(self, context):
41         layout = self.layout
42
43         bone = context.bone
44         if not bone:
45             bone = context.edit_bone
46
47         row = layout.row()
48         row.label(text="", icon='BONE_DATA')
49         row.prop(bone, "name", text="")
50
51
52 class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, bpy.types.Panel):
53
54     @property
55     def _context_path(self):
56         obj = bpy.context.object
57         if obj and obj.mode == 'POSE':
58             return "active_pose_bone"
59         else:
60             return "active_bone"
61
62
63 class BONE_PT_transform(BoneButtonsPanel, bpy.types.Panel):
64     bl_label = "Transform"
65
66     def draw(self, context):
67         layout = self.layout
68
69         ob = context.object
70         bone = context.bone
71         wide_ui = context.region.width > narrowui
72
73         if not bone:
74             bone = context.edit_bone
75             if wide_ui:
76                 row = layout.row()
77                 row.column().prop(bone, "head")
78                 row.column().prop(bone, "tail")
79
80                 col = row.column()
81                 sub = col.column(align=True)
82                 sub.label(text="Roll:")
83                 sub.prop(bone, "roll", text="")
84                 sub.label()
85                 sub.prop(bone, "lock")
86             else:
87                 col = layout.column()
88                 col.prop(bone, "head")
89                 col.prop(bone, "tail")
90                 col.prop(bone, "roll")
91                 col.prop(bone, "lock")
92
93         else:
94             pchan = ob.pose.bones[context.bone.name]
95
96             if wide_ui:
97                 row = layout.row()
98                 col = row.column()
99                 col.prop(pchan, "location")
100                 col.active = not (bone.parent and bone.connected)
101
102                 col = row.column()
103                 if pchan.rotation_mode == 'QUATERNION':
104                     col.prop(pchan, "rotation_quaternion", text="Rotation")
105                 elif pchan.rotation_mode == 'AXIS_ANGLE':
106                     #col.label(text="Rotation")
107                     #col.prop(pchan, "rotation_angle", text="Angle")
108                     #col.prop(pchan, "rotation_axis", text="Axis")
109                     col.prop(pchan, "rotation_axis_angle", text="Rotation")
110                 else:
111                     col.prop(pchan, "rotation_euler", text="Rotation")
112
113                 row.column().prop(pchan, "scale")
114
115                 layout.prop(pchan, "rotation_mode")
116             else:
117                 col = layout.column()
118                 sub = col.column()
119                 sub.active = not (bone.parent and bone.connected)
120                 sub.prop(pchan, "location")
121                 col.label(text="Rotation:")
122                 col.prop(pchan, "rotation_mode", text="")
123                 if pchan.rotation_mode == 'QUATERNION':
124                     col.prop(pchan, "rotation_quaternion", text="")
125                 elif pchan.rotation_mode == 'AXIS_ANGLE':
126                     col.prop(pchan, "rotation_axis_angle", text="")
127                 else:
128                     col.prop(pchan, "rotation_euler", text="")
129                 col.prop(pchan, "scale")
130
131
132 class BONE_PT_transform_locks(BoneButtonsPanel, bpy.types.Panel):
133     bl_label = "Transform Locks"
134     bl_default_closed = True
135
136     @staticmethod
137     def poll(context):
138         return context.bone
139
140     def draw(self, context):
141         layout = self.layout
142
143         ob = context.object
144         bone = context.bone
145         pchan = ob.pose.bones[context.bone.name]
146
147         row = layout.row()
148         col = row.column()
149         col.prop(pchan, "lock_location")
150         col.active = not (bone.parent and bone.connected)
151
152         col = row.column()
153         if pchan.rotation_mode in ('QUATERNION', 'AXIS_ANGLE'):
154             col.prop(pchan, "lock_rotations_4d", text="Lock Rotation")
155             if pchan.lock_rotations_4d:
156                 col.prop(pchan, "lock_rotation_w", text="W")
157             col.prop(pchan, "lock_rotation", text="")
158         else:
159             col.prop(pchan, "lock_rotation", text="Rotation")
160
161         row.column().prop(pchan, "lock_scale")
162
163
164 class BONE_PT_relations(BoneButtonsPanel, bpy.types.Panel):
165     bl_label = "Relations"
166
167     def draw(self, context):
168         layout = self.layout
169
170         ob = context.object
171         bone = context.bone
172         arm = context.armature
173         wide_ui = context.region.width > narrowui
174
175         if not bone:
176             bone = context.edit_bone
177             pchan = None
178         else:
179             pchan = ob.pose.bones[context.bone.name]
180
181         split = layout.split()
182
183         col = split.column()
184         col.label(text="Layers:")
185         col.prop(bone, "layer", text="")
186
187         col.separator()
188
189         if ob and pchan:
190             col.label(text="Bone Group:")
191             col.prop_object(pchan, "bone_group", ob.pose, "bone_groups", text="")
192
193         if wide_ui:
194             col = split.column()
195         col.label(text="Parent:")
196         if context.bone:
197             col.prop(bone, "parent", text="")
198         else:
199             col.prop_object(bone, "parent", arm, "edit_bones", text="")
200
201         sub = col.column()
202         sub.active = (bone.parent is not None)
203         sub.prop(bone, "connected")
204         sub.prop(bone, "hinge", text="Inherit Rotation")
205         sub.prop(bone, "inherit_scale", text="Inherit Scale")
206         sub = col.column()
207         sub.active = (not bone.parent or not bone.connected)
208         sub.prop(bone, "local_location", text="Local Location")
209
210
211 class BONE_PT_display(BoneButtonsPanel, bpy.types.Panel):
212     bl_label = "Display"
213
214     @staticmethod
215     def poll(context):
216         return context.bone
217
218     def draw(self, context):
219         layout = self.layout
220
221         ob = context.object
222         bone = context.bone
223         wide_ui = context.region.width > narrowui
224
225         if not bone:
226             bone = context.edit_bone
227             pchan = None
228         else:
229             pchan = ob.pose.bones[context.bone.name]
230
231         if ob and pchan:
232
233             split = layout.split()
234
235             col = split.column()
236             col.prop(bone, "draw_wire", text="Wireframe")
237             col.prop(bone, "hide", text="Hide")
238
239             if wide_ui:
240                 col = split.column()
241
242             col.label(text="Custom Shape:")
243             col.prop(pchan, "custom_shape", text="")
244             if pchan.custom_shape:
245                 col.prop_object(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
246
247
248 class BONE_PT_inverse_kinematics(BoneButtonsPanel, bpy.types.Panel):
249     bl_label = "Inverse Kinematics"
250     bl_default_closed = True
251
252     @staticmethod
253     def poll(context):
254         return context.active_pose_bone
255
256     def draw(self, context):
257         layout = self.layout
258
259         ob = context.object
260         bone = context.bone
261         pchan = ob.pose.bones[bone.name]
262         wide_ui = context.region.width > narrowui
263
264         row = layout.row()
265         row.prop(ob.pose, "ik_solver")
266
267         split = layout.split(percentage=0.25)
268         split.prop(pchan, "ik_dof_x", text="X")
269         split.active = pchan.has_ik
270         row = split.row()
271         row.prop(pchan, "ik_stiffness_x", text="Stiffness", slider=True)
272         row.active = pchan.ik_dof_x and pchan.has_ik
273
274         if wide_ui:
275             split = layout.split(percentage=0.25)
276             sub = split.row()
277         else:
278             sub = layout.column(align=True)
279         sub.prop(pchan, "ik_limit_x", text="Limit")
280         sub.active = pchan.ik_dof_x and pchan.has_ik
281         if wide_ui:
282             sub = split.row(align=True)
283         sub.prop(pchan, "ik_min_x", text="")
284         sub.prop(pchan, "ik_max_x", text="")
285         sub.active = pchan.ik_dof_x and pchan.ik_limit_x and pchan.has_ik
286
287         split = layout.split(percentage=0.25)
288         split.prop(pchan, "ik_dof_y", text="Y")
289         split.active = pchan.has_ik and pchan.has_ik
290         row = split.row()
291         row.prop(pchan, "ik_stiffness_y", text="Stiffness", slider=True)
292         row.active = pchan.ik_dof_y and pchan.has_ik
293
294         if wide_ui:
295             split = layout.split(percentage=0.25)
296             sub = split.row()
297         else:
298             sub = layout.column(align=True)
299         sub.prop(pchan, "ik_limit_y", text="Limit")
300         sub.active = pchan.ik_dof_y and pchan.has_ik
301         if wide_ui:
302             sub = split.row(align=True)
303         sub.prop(pchan, "ik_min_y", text="")
304         sub.prop(pchan, "ik_max_y", text="")
305         sub.active = pchan.ik_dof_y and pchan.ik_limit_y and pchan.has_ik
306
307         split = layout.split(percentage=0.25)
308         split.prop(pchan, "ik_dof_z", text="Z")
309         split.active = pchan.has_ik and pchan.has_ik
310         sub = split.row()
311         sub.prop(pchan, "ik_stiffness_z", text="Stiffness", slider=True)
312         sub.active = pchan.ik_dof_z and pchan.has_ik
313
314         if wide_ui:
315             split = layout.split(percentage=0.25)
316             sub = split.row()
317         else:
318             sub = layout.column(align=True)
319         sub.prop(pchan, "ik_limit_z", text="Limit")
320         sub.active = pchan.ik_dof_z and pchan.has_ik
321         if wide_ui:
322             sub = split.row(align=True)
323         sub.prop(pchan, "ik_min_z", text="")
324         sub.prop(pchan, "ik_max_z", text="")
325         sub.active = pchan.ik_dof_z and pchan.ik_limit_z and pchan.has_ik
326         split = layout.split()
327         split.prop(pchan, "ik_stretch", text="Stretch", slider=True)
328         if wide_ui:
329             split.label()
330         split.active = pchan.has_ik
331
332         if ob.pose.ik_solver == 'ITASC':
333             split = layout.split()
334             col = split.column()
335             col.prop(pchan, "ik_rot_control", text="Control Rotation")
336             col.active = pchan.has_ik
337             if wide_ui:
338                 col = split.column()
339             col.prop(pchan, "ik_rot_weight", text="Weight", slider=True)
340             col.active = pchan.has_ik
341             # not supported yet
342             #row = layout.row()
343             #row.prop(pchan, "ik_lin_control", text="Joint Size")
344             #row.prop(pchan, "ik_lin_weight", text="Weight", slider=True)
345
346
347 class BONE_PT_deform(BoneButtonsPanel, bpy.types.Panel):
348     bl_label = "Deform"
349     bl_default_closed = True
350
351     def draw_header(self, context):
352         bone = context.bone
353
354         if not bone:
355             bone = context.edit_bone
356
357         self.layout.prop(bone, "deform", text="")
358
359     def draw(self, context):
360         layout = self.layout
361
362         bone = context.bone
363         wide_ui = context.region.width > narrowui
364
365         if not bone:
366             bone = context.edit_bone
367
368         layout.active = bone.deform
369
370         split = layout.split()
371
372         col = split.column()
373         col.label(text="Envelope:")
374
375         sub = col.column(align=True)
376         sub.prop(bone, "envelope_distance", text="Distance")
377         sub.prop(bone, "envelope_weight", text="Weight")
378         col.prop(bone, "multiply_vertexgroup_with_envelope", text="Multiply")
379
380         sub = col.column(align=True)
381         sub.label(text="Radius:")
382         sub.prop(bone, "head_radius", text="Head")
383         sub.prop(bone, "tail_radius", text="Tail")
384
385         if wide_ui:
386             col = split.column()
387         col.label(text="Curved Bones:")
388
389         sub = col.column(align=True)
390         sub.prop(bone, "bbone_segments", text="Segments")
391         sub.prop(bone, "bbone_in", text="Ease In")
392         sub.prop(bone, "bbone_out", text="Ease Out")
393
394         col.label(text="Offset:")
395         col.prop(bone, "cyclic_offset")
396
397
398 def register():
399     pass
400
401
402 def unregister():
403     pass
404
405 if __name__ == "__main__":
406     register()