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