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