Merging r39312 through r39329 from trunk into soc-2011-tomato
[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
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         layout.label(text="Deform:")
69         flow = layout.column_flow()
70         flow.prop(arm, "use_deform_vertex_groups", text="Vertex Groups")
71         flow.prop(arm, "use_deform_envelopes", text="Envelopes")
72         flow.prop(arm, "use_deform_preserve_volume", text="Quaternion")
73
74
75 class DATA_PT_display(ArmatureButtonsPanel, Panel):
76     bl_label = "Display"
77
78     def draw(self, context):
79         layout = self.layout
80
81         ob = context.object
82         arm = context.armature
83
84         layout.prop(arm, "draw_type", expand=True)
85
86         split = layout.split()
87
88         col = split.column()
89         col.prop(arm, "show_names", text="Names")
90         col.prop(arm, "show_axes", text="Axes")
91         col.prop(arm, "show_bone_custom_shapes", text="Shapes")
92
93         col = split.column()
94         col.prop(arm, "show_group_colors", text="Colors")
95         if ob:
96             col.prop(ob, "show_x_ray", text="X-Ray")
97         col.prop(arm, "use_deform_delay", text="Delay Refresh")
98
99
100 class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel):
101     bl_label = "Bone Groups"
102
103     @classmethod
104     def poll(cls, context):
105         return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
106
107     def draw(self, context):
108         layout = self.layout
109
110         ob = context.object
111         pose = ob.pose
112
113         row = layout.row()
114         row.template_list(pose, "bone_groups", pose.bone_groups, "active_index", rows=2)
115
116         col = row.column(align=True)
117         col.active = (ob.proxy is None)
118         col.operator("pose.group_add", icon='ZOOMIN', text="")
119         col.operator("pose.group_remove", icon='ZOOMOUT', text="")
120
121         group = pose.bone_groups.active
122         if group:
123             col = layout.column()
124             col.active = (ob.proxy is None)
125             col.prop(group, "name")
126
127             split = layout.split()
128             split.active = (ob.proxy is None)
129
130             col = split.column()
131             col.prop(group, "color_set")
132             if group.color_set:
133                 col = split.column()
134                 sub = col.row(align=True)
135                 sub.prop(group.colors, "normal", text="")
136                 sub.prop(group.colors, "select", text="")
137                 sub.prop(group.colors, "active", text="")
138
139         row = layout.row()
140         row.active = (ob.proxy is None)
141
142         sub = row.row(align=True)
143         sub.operator("pose.group_assign", text="Assign")
144         sub.operator("pose.group_unassign", text="Remove")  # row.operator("pose.bone_group_remove_from", text="Remove")
145
146         sub = row.row(align=True)
147         sub.operator("pose.group_select", text="Select")
148         sub.operator("pose.group_deselect", text="Deselect")
149
150
151 class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
152     bl_label = "Pose Library"
153     bl_options = {'DEFAULT_CLOSED'}
154
155     @classmethod
156     def poll(cls, context):
157         return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
158
159     def draw(self, context):
160         layout = self.layout
161
162         ob = context.object
163         poselib = ob.pose_library
164
165         layout.template_ID(ob, "pose_library", new="poselib.new", unlink="poselib.unlink")
166
167         if poselib:
168             row = layout.row()
169             row.template_list(poselib, "pose_markers", poselib.pose_markers, "active_index", rows=5)
170
171             col = row.column(align=True)
172             col.active = (poselib.library is None)
173
174             # invoke should still be used for 'add', as it is needed to allow
175             # add/replace options to be used properly
176             col.operator("poselib.pose_add", icon='ZOOMIN', text="")
177
178             col.operator_context = 'EXEC_DEFAULT'  # exec not invoke, so that menu doesn't need showing
179
180             pose_marker_active = poselib.pose_markers.active
181
182             if pose_marker_active is not None:
183                 col.operator("poselib.pose_remove", icon='ZOOMOUT', text="").pose = pose_marker_active.name
184                 col.operator("poselib.apply_pose", icon='ZOOM_SELECTED', text="").pose_index = poselib.pose_markers.active_index
185
186             layout.operator("poselib.action_sanitise")
187
188
189 # TODO: this panel will soon be depreceated too
190 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
191     bl_label = "Ghost"
192
193     def draw(self, context):
194         layout = self.layout
195
196         arm = context.armature
197
198         layout.prop(arm, "ghost_type", expand=True)
199
200         split = layout.split()
201
202         col = split.column(align=True)
203
204         if arm.ghost_type == 'RANGE':
205             col.prop(arm, "ghost_frame_start", text="Start")
206             col.prop(arm, "ghost_frame_end", text="End")
207             col.prop(arm, "ghost_size", text="Step")
208         elif arm.ghost_type == 'CURRENT_FRAME':
209             col.prop(arm, "ghost_step", text="Range")
210             col.prop(arm, "ghost_size", text="Step")
211
212         col = split.column()
213         col.label(text="Display:")
214         col.prop(arm, "show_only_ghost_selected", text="Selected Only")
215
216
217 class DATA_PT_iksolver_itasc(ArmatureButtonsPanel, Panel):
218     bl_label = "iTaSC parameters"
219     bl_options = {'DEFAULT_CLOSED'}
220
221     @classmethod
222     def poll(cls, context):
223         ob = context.object
224         return (ob and ob.pose)
225
226     def draw(self, context):
227         layout = self.layout
228
229         ob = context.object
230         itasc = ob.pose.ik_param
231
232         layout.prop(ob.pose, "ik_solver")
233
234         if itasc:
235             layout.prop(itasc, "mode", expand=True)
236             simulation = (itasc.mode == 'SIMULATION')
237             if simulation:
238                 layout.label(text="Reiteration:")
239                 layout.prop(itasc, "reiteration_method", expand=True)
240
241             row = layout.row()
242             row.active = not simulation or itasc.reiteration_method != 'NEVER'
243             row.prop(itasc, "precision")
244             row.prop(itasc, "iterations")
245
246             if simulation:
247                 layout.prop(itasc, "use_auto_step")
248                 row = layout.row()
249                 if itasc.use_auto_step:
250                     row.prop(itasc, "step_min", text="Min")
251                     row.prop(itasc, "step_max", text="Max")
252                 else:
253                     row.prop(itasc, "step_count")
254
255             layout.prop(itasc, "solver")
256             if simulation:
257                 layout.prop(itasc, "feedback")
258                 layout.prop(itasc, "velocity_max")
259             if itasc.solver == 'DLS':
260                 row = layout.row()
261                 row.prop(itasc, "damping_max", text="Damp", slider=True)
262                 row.prop(itasc, "damping_epsilon", text="Eps", slider=True)
263
264 from bl_ui.properties_animviz import (
265     MotionPathButtonsPanel,
266     OnionSkinButtonsPanel,
267     )
268
269
270 class DATA_PT_motion_paths(MotionPathButtonsPanel, Panel):
271     #bl_label = "Bones Motion Paths"
272     bl_context = "data"
273
274     @classmethod
275     def poll(cls, context):
276         # XXX: include posemode check?
277         return (context.object) and (context.armature)
278
279     def draw(self, context):
280         layout = self.layout
281
282         ob = context.object
283
284         self.draw_settings(context, ob.pose.animation_visualisation, bones=True)
285
286         layout.separator()
287
288         split = layout.split()
289         split.operator("pose.paths_calculate", text="Calculate Paths")
290         split.operator("pose.paths_clear", text="Clear Paths")
291
292
293 class DATA_PT_onion_skinning(OnionSkinButtonsPanel):  # , Panel): # inherit from panel when ready
294     #bl_label = "Bones Onion Skinning"
295     bl_context = "data"
296
297     @classmethod
298     def poll(cls, context):
299         # XXX: include posemode check?
300         return (context.object) and (context.armature)
301
302     def draw(self, context):
303         ob = context.object
304         self.draw_settings(context, ob.pose.animation_visualisation, bones=True)
305
306
307 class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
308     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
309     _context_path = "object.data"
310     _property_type = bpy.types.Armature
311
312 if __name__ == "__main__":  # only for live edit.
313     bpy.utils.register_module(__name__)