Fix #32964: IK constraint had a "Target" option, which actually is an internal
[blender.git] / release / scripts / startup / bl_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
21 import bpy
22 from bpy.types import Panel
23 from rna_prop_ui import PropertyPanel
24
25
26 class BoneButtonsPanel():
27     bl_space_type = 'PROPERTIES'
28     bl_region_type = 'WINDOW'
29     bl_context = "bone"
30
31     @classmethod
32     def poll(cls, context):
33         return (context.bone or context.edit_bone)
34
35
36 class BONE_PT_context_bone(BoneButtonsPanel, Panel):
37     bl_label = ""
38     bl_options = {'HIDE_HEADER'}
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_transform(BoneButtonsPanel, Panel):
53     bl_label = "Transform"
54
55     @classmethod
56     def poll(cls, context):
57         if context.edit_bone:
58             return True
59
60         ob = context.object
61         return ob and ob.mode == 'POSE' and context.bone
62
63     def draw(self, context):
64         layout = self.layout
65
66         ob = context.object
67         bone = context.bone
68
69         if bone and ob:
70             pchan = ob.pose.bones[bone.name]
71
72             row = layout.row()
73             col = row.column()
74             col.prop(pchan, "location")
75             col.active = not (bone.parent and bone.use_connect)
76
77             col = row.column()
78             if pchan.rotation_mode == 'QUATERNION':
79                 col.prop(pchan, "rotation_quaternion", text="Rotation")
80             elif pchan.rotation_mode == 'AXIS_ANGLE':
81                 #col.label(text="Rotation")
82                 #col.prop(pchan, "rotation_angle", text="Angle")
83                 #col.prop(pchan, "rotation_axis", text="Axis")
84                 col.prop(pchan, "rotation_axis_angle", text="Rotation")
85             else:
86                 col.prop(pchan, "rotation_euler", text="Rotation")
87
88             row.column().prop(pchan, "scale")
89
90             layout.prop(pchan, "rotation_mode")
91
92         elif context.edit_bone:
93             bone = context.edit_bone
94             row = layout.row()
95             row.column().prop(bone, "head")
96             row.column().prop(bone, "tail")
97
98             col = row.column()
99             sub = col.column(align=True)
100             sub.label(text="Roll:")
101             sub.prop(bone, "roll", text="")
102             sub.label()
103             sub.prop(bone, "lock")
104
105
106 class BONE_PT_transform_locks(BoneButtonsPanel, Panel):
107     bl_label = "Transform Locks"
108     bl_options = {'DEFAULT_CLOSED'}
109
110     @classmethod
111     def poll(cls, context):
112         ob = context.object
113         return ob and ob.mode == 'POSE' and context.bone
114
115     def draw(self, context):
116         layout = self.layout
117
118         ob = context.object
119         bone = context.bone
120         pchan = ob.pose.bones[bone.name]
121
122         split = layout.split(percentage=0.1)
123
124         col = split.column(align=True)
125         col.label(text="")
126         col.label(text="X:")
127         col.label(text="Y:")
128         col.label(text="Z:")
129
130         col = split.row()
131         sub = col.row()
132         sub.active = not (bone.parent and bone.use_connect)
133         sub.column().prop(pchan, "lock_location", text="Location")
134         col.column().prop(pchan, "lock_rotation", text="Rotation")
135         col.column().prop(pchan, "lock_scale", text="Scale")
136
137         if pchan.rotation_mode in {'QUATERNION', 'AXIS_ANGLE'}:
138             row = layout.row()
139             row.prop(pchan, "lock_rotations_4d", text="Lock Rotation")
140
141             sub = row.row()
142             sub.active = pchan.lock_rotations_4d
143             sub.prop(pchan, "lock_rotation_w", text="W")
144
145
146 class BONE_PT_relations(BoneButtonsPanel, Panel):
147     bl_label = "Relations"
148
149     def draw(self, context):
150         layout = self.layout
151
152         ob = context.object
153         bone = context.bone
154         arm = context.armature
155         pchan = None
156
157         if ob and bone:
158             pchan = ob.pose.bones[bone.name]
159         elif bone is None:
160             bone = context.edit_bone
161
162         split = layout.split()
163
164         col = split.column()
165         col.label(text="Layers:")
166         col.prop(bone, "layers", text="")
167
168         col.separator()
169
170         if ob and pchan:
171             col.label(text="Bone Group:")
172             col.prop_search(pchan, "bone_group", ob.pose, "bone_groups", text="")
173
174         col = split.column()
175         col.label(text="Parent:")
176         if context.bone:
177             col.prop(bone, "parent", text="")
178         else:
179             col.prop_search(bone, "parent", arm, "edit_bones", text="")
180
181         sub = col.column()
182         sub.active = (bone.parent is not None)
183         sub.prop(bone, "use_connect")
184         sub.prop(bone, "use_inherit_rotation", text="Inherit Rotation")
185         sub.prop(bone, "use_inherit_scale", text="Inherit Scale")
186         sub = col.column()
187         sub.active = (not bone.parent or not bone.use_connect)
188         sub.prop(bone, "use_local_location", text="Local Location")
189
190
191 class BONE_PT_display(BoneButtonsPanel, Panel):
192     bl_label = "Display"
193
194     @classmethod
195     def poll(cls, context):
196         return context.bone
197
198     def draw(self, context):
199         # note. this works ok in edit-mode but isn't
200         # all that useful so disabling for now.
201         layout = self.layout
202
203         ob = context.object
204         bone = context.bone
205         pchan = None
206
207         if ob and bone:
208             pchan = ob.pose.bones[bone.name]
209         elif bone is None:
210             bone = context.edit_bone
211
212         if bone:
213             split = layout.split()
214
215             col = split.column()
216             col.prop(bone, "hide", text="Hide")
217             sub = col.column()
218             sub.active = bool(pchan.custom_shape)
219             sub.prop(bone, "show_wire", text="Wireframe")
220
221             if pchan:
222                 col = split.column()
223
224                 col.label(text="Custom Shape:")
225                 col.prop(pchan, "custom_shape", text="")
226                 if pchan.custom_shape:
227                     col.prop_search(pchan, "custom_shape_transform", ob.pose, "bones", text="At")
228
229
230 class BONE_PT_inverse_kinematics(BoneButtonsPanel, Panel):
231     bl_label = "Inverse Kinematics"
232     bl_options = {'DEFAULT_CLOSED'}
233
234     @classmethod
235     def poll(cls, context):
236         ob = context.object
237         return ob and ob.mode == 'POSE' and context.bone
238
239     def draw(self, context):
240         layout = self.layout
241
242         ob = context.object
243         bone = context.bone
244         pchan = ob.pose.bones[bone.name]
245
246         row = layout.row()
247         row.prop(ob.pose, "ik_solver")
248
249         active = pchan.is_in_ik_chain
250
251         split = layout.split(percentage=0.25)
252         split.prop(pchan, "lock_ik_x", icon='LOCKED' if pchan.lock_ik_x else 'UNLOCKED', text="X")
253         split.active = active
254         row = split.row()
255         row.prop(pchan, "ik_stiffness_x", text="Stiffness", slider=True)
256         row.active = pchan.lock_ik_x is False and active
257
258         split = layout.split(percentage=0.25)
259         sub = split.row()
260
261         sub.prop(pchan, "use_ik_limit_x", text="Limit")
262         sub.active = pchan.lock_ik_x is False and active
263         sub = split.row(align=True)
264         sub.prop(pchan, "ik_min_x", text="")
265         sub.prop(pchan, "ik_max_x", text="")
266         sub.active = pchan.lock_ik_x is False and pchan.use_ik_limit_x and active
267
268         split = layout.split(percentage=0.25)
269         split.prop(pchan, "lock_ik_y", icon='LOCKED' if pchan.lock_ik_y else 'UNLOCKED', text="Y")
270         split.active = active
271         row = split.row()
272         row.prop(pchan, "ik_stiffness_y", text="Stiffness", slider=True)
273         row.active = pchan.lock_ik_y is False and active
274
275         split = layout.split(percentage=0.25)
276         sub = split.row()
277
278         sub.prop(pchan, "use_ik_limit_y", text="Limit")
279         sub.active = pchan.lock_ik_y is False and active
280
281         sub = split.row(align=True)
282         sub.prop(pchan, "ik_min_y", text="")
283         sub.prop(pchan, "ik_max_y", text="")
284         sub.active = pchan.lock_ik_y is False and pchan.use_ik_limit_y and active
285
286         split = layout.split(percentage=0.25)
287         split.prop(pchan, "lock_ik_z", icon='LOCKED' if pchan.lock_ik_z else 'UNLOCKED', text="Z")
288         split.active = active
289         sub = split.row()
290         sub.prop(pchan, "ik_stiffness_z", text="Stiffness", slider=True)
291         sub.active = pchan.lock_ik_z is False and active
292
293         split = layout.split(percentage=0.25)
294         sub = split.row()
295
296         sub.prop(pchan, "use_ik_limit_z", text="Limit")
297         sub.active = pchan.lock_ik_z is False and active
298         sub = split.row(align=True)
299         sub.prop(pchan, "ik_min_z", text="")
300         sub.prop(pchan, "ik_max_z", text="")
301         sub.active = pchan.lock_ik_z is False and pchan.use_ik_limit_z and active
302
303         split = layout.split(percentage=0.25)
304         split.label(text="Stretch:")
305         sub = split.row()
306         sub.prop(pchan, "ik_stretch", text="", slider=True)
307         sub.active = active
308
309         if ob.pose.ik_solver == 'ITASC':
310             split = layout.split()
311             col = split.column()
312             col.prop(pchan, "use_ik_rotation_control", text="Control Rotation")
313             col.active = active
314             col = split.column()
315             col.prop(pchan, "ik_rotation_weight", text="Weight", slider=True)
316             col.active = active
317             # not supported yet
318             #row = layout.row()
319             #row.prop(pchan, "use_ik_linear_control", text="Joint Size")
320             #row.prop(pchan, "ik_linear_weight", text="Weight", slider=True)
321
322
323 class BONE_PT_deform(BoneButtonsPanel, Panel):
324     bl_label = "Deform"
325     bl_options = {'DEFAULT_CLOSED'}
326
327     def draw_header(self, context):
328         bone = context.bone
329
330         if not bone:
331             bone = context.edit_bone
332
333         self.layout.prop(bone, "use_deform", text="")
334
335     def draw(self, context):
336         layout = self.layout
337
338         bone = context.bone
339
340         if not bone:
341             bone = context.edit_bone
342
343         layout.active = bone.use_deform
344
345         split = layout.split()
346
347         col = split.column()
348         col.label(text="Envelope:")
349
350         sub = col.column(align=True)
351         sub.prop(bone, "envelope_distance", text="Distance")
352         sub.prop(bone, "envelope_weight", text="Weight")
353         col.prop(bone, "use_envelope_multiply", text="Multiply")
354
355         sub = col.column(align=True)
356         sub.label(text="Radius:")
357         sub.prop(bone, "head_radius", text="Head")
358         sub.prop(bone, "tail_radius", text="Tail")
359
360         col = split.column()
361         col.label(text="Curved Bones:")
362
363         sub = col.column(align=True)
364         sub.prop(bone, "bbone_segments", text="Segments")
365         sub.prop(bone, "bbone_in", text="Ease In")
366         sub.prop(bone, "bbone_out", text="Ease Out")
367
368
369 class BONE_PT_custom_props(BoneButtonsPanel, PropertyPanel, Panel):
370     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
371     _property_type = bpy.types.Bone, bpy.types.EditBone, bpy.types.PoseBone
372
373     @property
374     def _context_path(self):
375         obj = bpy.context.object
376         if obj and obj.mode == 'POSE':
377             return "active_pose_bone"
378         else:
379             return "active_bone"
380
381 if __name__ == "__main__":  # only for live edit.
382     bpy.utils.register_module(__name__)