74f33170384104a3a385cf64623cd3966a221e96
[blender.git] / release / scripts / startup / bl_ui / properties_data_armature.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 bpy.types import Panel, Menu
22 from rna_prop_ui import PropertyPanel
23
24
25 class ArmatureButtonsPanel():
26     bl_space_type = 'PROPERTIES'
27     bl_region_type = 'WINDOW'
28     bl_context = "data"
29
30     @classmethod
31     def poll(cls, context):
32         return context.armature
33
34
35 class DATA_PT_context_arm(ArmatureButtonsPanel, Panel):
36     bl_label = ""
37     bl_options = {'HIDE_HEADER'}
38
39     def draw(self, context):
40         layout = self.layout
41
42         ob = context.object
43         arm = context.armature
44         space = context.space_data
45
46         if ob:
47             layout.template_ID(ob, "data")
48         elif arm:
49             layout.template_ID(space, "pin_id")
50
51
52 class DATA_PT_skeleton(ArmatureButtonsPanel, Panel):
53     bl_label = "Skeleton"
54
55     def draw(self, context):
56         layout = self.layout
57
58         arm = context.armature
59
60         layout.prop(arm, "pose_position", expand=True)
61
62         col = layout.column()
63         col.label(text="Layers:")
64         col.prop(arm, "layers", text="")
65         col.label(text="Protected Layers:")
66         col.prop(arm, "layers_protected", text="")
67
68         if context.scene.render.engine == 'BLENDER_GAME':
69             col = layout.column()
70             col.label(text="Deform:")
71             col.prop(arm, "deform_method", expand=True)
72
73
74 class DATA_PT_display(ArmatureButtonsPanel, Panel):
75     bl_label = "Display"
76
77     def draw(self, context):
78         layout = self.layout
79
80         ob = context.object
81         arm = context.armature
82
83         layout.prop(arm, "draw_type", expand=True)
84
85         split = layout.split()
86
87         col = split.column()
88         col.prop(arm, "show_names", text="Names")
89         col.prop(arm, "show_axes", text="Axes")
90         col.prop(arm, "show_bone_custom_shapes", text="Shapes")
91
92         col = split.column()
93         col.prop(arm, "show_group_colors", text="Colors")
94         if ob:
95             col.prop(ob, "show_x_ray", text="X-Ray")
96         col.prop(arm, "use_deform_delay", text="Delay Refresh")
97
98
99 class DATA_PT_bone_group_specials(Menu):
100     bl_label = "Bone Group Specials"
101
102     def draw(self, context):
103         layout = self.layout
104
105         layout.operator("pose.group_sort", icon='SORTALPHA')
106
107
108 class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel):
109     bl_label = "Bone Groups"
110
111     @classmethod
112     def poll(cls, context):
113         return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
114
115     def draw(self, context):
116         layout = self.layout
117
118         ob = context.object
119         pose = ob.pose
120         group = pose.bone_groups.active
121
122         row = layout.row()
123
124         rows = 2
125         if group:
126             rows = 5
127         row.template_list("UI_UL_list", "bone_groups", pose, "bone_groups", pose.bone_groups, "active_index", rows=rows)
128
129         col = row.column(align=True)
130         col.active = (ob.proxy is None)
131         col.operator("pose.group_add", icon='ZOOMIN', text="")
132         col.operator("pose.group_remove", icon='ZOOMOUT', text="")
133         col.menu("DATA_PT_bone_group_specials", icon='DOWNARROW_HLT', text="")
134         if group:
135             col.separator()
136             col.operator("pose.group_move", icon='TRIA_UP', text="").direction = 'UP'
137             col.operator("pose.group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
138
139         if group:
140             col = layout.column()
141             col.active = (ob.proxy is None)
142             col.prop(group, "name")
143
144             split = layout.split()
145             split.active = (ob.proxy is None)
146
147             col = split.column()
148             col.prop(group, "color_set")
149             if group.color_set:
150                 col = split.column()
151                 sub = col.row(align=True)
152                 sub.prop(group.colors, "normal", text="")
153                 sub.prop(group.colors, "select", text="")
154                 sub.prop(group.colors, "active", text="")
155
156         row = layout.row()
157         row.active = (ob.proxy is None)
158
159         sub = row.row(align=True)
160         sub.operator("pose.group_assign", text="Assign")
161         sub.operator("pose.group_unassign", text="Remove")  # row.operator("pose.bone_group_remove_from", text="Remove")
162
163         sub = row.row(align=True)
164         sub.operator("pose.group_select", text="Select")
165         sub.operator("pose.group_deselect", text="Deselect")
166
167
168 class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
169     bl_label = "Pose Library"
170     bl_options = {'DEFAULT_CLOSED'}
171
172     @classmethod
173     def poll(cls, context):
174         return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
175
176     def draw(self, context):
177         layout = self.layout
178
179         ob = context.object
180         poselib = ob.pose_library
181
182         layout.template_ID(ob, "pose_library", new="poselib.new", unlink="poselib.unlink")
183
184         if poselib:
185             # list of poses in pose library
186             row = layout.row()
187             row.template_list("UI_UL_list", "pose_markers", poselib, "pose_markers",
188                               poselib.pose_markers, "active_index", rows=5)
189
190             # column of operators for active pose
191             # - goes beside list
192             col = row.column(align=True)
193             col.active = (poselib.library is None)
194
195             # invoke should still be used for 'add', as it is needed to allow
196             # add/replace options to be used properly
197             col.operator("poselib.pose_add", icon='ZOOMIN', text="")
198
199             col.operator_context = 'EXEC_DEFAULT'  # exec not invoke, so that menu doesn't need showing
200
201             pose_marker_active = poselib.pose_markers.active
202
203             if pose_marker_active is not None:
204                 col.operator("poselib.pose_remove", icon='ZOOMOUT', text="")
205                 col.operator("poselib.apply_pose", icon='ZOOM_SELECTED', text="").pose_index = poselib.pose_markers.active_index
206
207             col.operator("poselib.action_sanitize", icon='HELP', text="")  # XXX: put in menu?
208
209             # properties for active marker
210             if pose_marker_active is not None:
211                 layout.prop(pose_marker_active, "name")
212
213
214 # TODO: this panel will soon be deprecated deprecated too
215 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
216     bl_label = "Ghost"
217
218     def draw(self, context):
219         layout = self.layout
220
221         arm = context.armature
222
223         layout.prop(arm, "ghost_type", expand=True)
224
225         split = layout.split()
226
227         col = split.column(align=True)
228
229         if arm.ghost_type == 'RANGE':
230             col.prop(arm, "ghost_frame_start", text="Start")
231             col.prop(arm, "ghost_frame_end", text="End")
232             col.prop(arm, "ghost_size", text="Step")
233         elif arm.ghost_type == 'CURRENT_FRAME':
234             col.prop(arm, "ghost_step", text="Range")
235             col.prop(arm, "ghost_size", text="Step")
236
237         col = split.column()
238         col.label(text="Display:")
239         col.prop(arm, "show_only_ghost_selected", text="Selected Only")
240
241
242 class DATA_PT_iksolver_itasc(ArmatureButtonsPanel, Panel):
243     bl_label = "Inverse Kinematics"
244     bl_options = {'DEFAULT_CLOSED'}
245
246     @classmethod
247     def poll(cls, context):
248         ob = context.object
249         return (ob and ob.pose)
250
251     def draw(self, context):
252         layout = self.layout
253
254         ob = context.object
255         itasc = ob.pose.ik_param
256
257         layout.prop(ob.pose, "ik_solver")
258
259         if itasc:
260             layout.prop(itasc, "mode", expand=True)
261             simulation = (itasc.mode == 'SIMULATION')
262             if simulation:
263                 layout.label(text="Reiteration:")
264                 layout.prop(itasc, "reiteration_method", expand=True)
265
266             row = layout.row()
267             row.active = not simulation or itasc.reiteration_method != 'NEVER'
268             row.prop(itasc, "precision")
269             row.prop(itasc, "iterations")
270
271             if simulation:
272                 layout.prop(itasc, "use_auto_step")
273                 row = layout.row()
274                 if itasc.use_auto_step:
275                     row.prop(itasc, "step_min", text="Min")
276                     row.prop(itasc, "step_max", text="Max")
277                 else:
278                     row.prop(itasc, "step_count")
279
280             layout.prop(itasc, "solver")
281             if simulation:
282                 layout.prop(itasc, "feedback")
283                 layout.prop(itasc, "velocity_max")
284             if itasc.solver == 'DLS':
285                 row = layout.row()
286                 row.prop(itasc, "damping_max", text="Damp", slider=True)
287                 row.prop(itasc, "damping_epsilon", text="Eps", slider=True)
288
289 from bl_ui.properties_animviz import (MotionPathButtonsPanel,
290                                       OnionSkinButtonsPanel,
291                                       )
292
293
294 class DATA_PT_motion_paths(MotionPathButtonsPanel, Panel):
295     #bl_label = "Bones Motion Paths"
296     bl_context = "data"
297
298     @classmethod
299     def poll(cls, context):
300         # XXX: include pose-mode check?
301         return (context.object) and (context.armature)
302
303     def draw(self, context):
304         layout = self.layout
305
306         ob = context.object
307         avs = ob.pose.animation_visualization
308
309         pchan = context.active_pose_bone
310         mpath = pchan.motion_path if pchan else None
311
312         self.draw_settings(context, avs, mpath, bones=True)
313
314
315 class DATA_PT_onion_skinning(OnionSkinButtonsPanel):  # , Panel): # inherit from panel when ready
316     #bl_label = "Bones Onion Skinning"
317     bl_context = "data"
318
319     @classmethod
320     def poll(cls, context):
321         # XXX: include pose-mode check?
322         return (context.object) and (context.armature)
323
324     def draw(self, context):
325         ob = context.object
326
327         self.draw_settings(context, ob.pose.animation_visualization, bones=True)
328
329
330 class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
331     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
332     _context_path = "object.data"
333     _property_type = bpy.types.Armature
334
335 if __name__ == "__main__":  # only for live edit.
336     bpy.utils.register_module(__name__)