Moving classes to separate listing broke panel order
[blender-staging.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 = 1
125         if group:
126             rows = 4
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             split = layout.split()
140             split.active = (ob.proxy is None)
141
142             col = split.column()
143             col.prop(group, "color_set")
144             if group.color_set:
145                 col = split.column()
146                 sub = col.row(align=True)
147                 sub.enabled = group.is_custom_color_set  # only custom colors are editable
148                 sub.prop(group.colors, "normal", text="")
149                 sub.prop(group.colors, "select", text="")
150                 sub.prop(group.colors, "active", text="")
151
152         row = layout.row()
153         row.active = (ob.proxy is None)
154
155         sub = row.row(align=True)
156         sub.operator("pose.group_assign", text="Assign")
157         sub.operator("pose.group_unassign", text="Remove")  # row.operator("pose.bone_group_remove_from", text="Remove")
158
159         sub = row.row(align=True)
160         sub.operator("pose.group_select", text="Select")
161         sub.operator("pose.group_deselect", text="Deselect")
162
163
164 class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
165     bl_label = "Pose Library"
166     bl_options = {'DEFAULT_CLOSED'}
167
168     @classmethod
169     def poll(cls, context):
170         return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
171
172     def draw(self, context):
173         layout = self.layout
174
175         ob = context.object
176         poselib = ob.pose_library
177
178         layout.template_ID(ob, "pose_library", new="poselib.new", unlink="poselib.unlink")
179
180         if poselib:
181             # list of poses in pose library
182             row = layout.row()
183             row.template_list("UI_UL_list", "pose_markers", poselib, "pose_markers",
184                               poselib.pose_markers, "active_index", rows=5)
185
186             # column of operators for active pose
187             # - goes beside list
188             col = row.column(align=True)
189
190             # invoke should still be used for 'add', as it is needed to allow
191             # add/replace options to be used properly
192             col.operator("poselib.pose_add", icon='ZOOMIN', text="")
193
194             col.operator_context = 'EXEC_DEFAULT'  # exec not invoke, so that menu doesn't need showing
195
196             pose_marker_active = poselib.pose_markers.active
197
198             if pose_marker_active is not None:
199                 col.operator("poselib.pose_remove", icon='ZOOMOUT', text="")
200                 col.operator("poselib.apply_pose", icon='ZOOM_SELECTED', text="").pose_index = poselib.pose_markers.active_index
201
202             col.operator("poselib.action_sanitize", icon='HELP', text="")  # XXX: put in menu?
203
204             if pose_marker_active is not None:
205                 col.operator("poselib.pose_move", icon='TRIA_UP', text="").direction = 'UP'
206                 col.operator("poselib.pose_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
207
208
209 # TODO: this panel will soon be deprecated too
210 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
211     bl_label = "Ghost"
212
213     def draw(self, context):
214         layout = self.layout
215
216         arm = context.armature
217
218         layout.prop(arm, "ghost_type", expand=True)
219
220         split = layout.split()
221
222         col = split.column(align=True)
223
224         if arm.ghost_type == 'RANGE':
225             col.prop(arm, "ghost_frame_start", text="Start")
226             col.prop(arm, "ghost_frame_end", text="End")
227             col.prop(arm, "ghost_size", text="Step")
228         elif arm.ghost_type == 'CURRENT_FRAME':
229             col.prop(arm, "ghost_step", text="Range")
230             col.prop(arm, "ghost_size", text="Step")
231
232         col = split.column()
233         col.label(text="Display:")
234         col.prop(arm, "show_only_ghost_selected", text="Selected Only")
235
236
237 class DATA_PT_iksolver_itasc(ArmatureButtonsPanel, Panel):
238     bl_label = "Inverse Kinematics"
239     bl_options = {'DEFAULT_CLOSED'}
240
241     @classmethod
242     def poll(cls, context):
243         ob = context.object
244         return (ob and ob.pose)
245
246     def draw(self, context):
247         layout = self.layout
248
249         ob = context.object
250         itasc = ob.pose.ik_param
251
252         layout.prop(ob.pose, "ik_solver")
253
254         if itasc:
255             layout.prop(itasc, "mode", expand=True)
256             simulation = (itasc.mode == 'SIMULATION')
257             if simulation:
258                 layout.label(text="Reiteration:")
259                 layout.prop(itasc, "reiteration_method", expand=True)
260
261             row = layout.row()
262             row.active = not simulation or itasc.reiteration_method != 'NEVER'
263             row.prop(itasc, "precision")
264             row.prop(itasc, "iterations")
265
266             if simulation:
267                 layout.prop(itasc, "use_auto_step")
268                 row = layout.row()
269                 if itasc.use_auto_step:
270                     row.prop(itasc, "step_min", text="Min")
271                     row.prop(itasc, "step_max", text="Max")
272                 else:
273                     row.prop(itasc, "step_count")
274
275             layout.prop(itasc, "solver")
276             if simulation:
277                 layout.prop(itasc, "feedback")
278                 layout.prop(itasc, "velocity_max")
279             if itasc.solver == 'DLS':
280                 row = layout.row()
281                 row.prop(itasc, "damping_max", text="Damp", slider=True)
282                 row.prop(itasc, "damping_epsilon", text="Eps", slider=True)
283
284 from bl_ui.properties_animviz import (
285         MotionPathButtonsPanel,
286         OnionSkinButtonsPanel,
287         )
288
289
290 class DATA_PT_motion_paths(MotionPathButtonsPanel, Panel):
291     #bl_label = "Bones Motion Paths"
292     bl_context = "data"
293
294     @classmethod
295     def poll(cls, context):
296         # XXX: include pose-mode check?
297         return (context.object) and (context.armature)
298
299     def draw(self, context):
300         # layout = self.layout
301
302         ob = context.object
303         avs = ob.pose.animation_visualization
304
305         pchan = context.active_pose_bone
306         mpath = pchan.motion_path if pchan else None
307
308         self.draw_settings(context, avs, mpath, bones=True)
309
310
311 class DATA_PT_onion_skinning(OnionSkinButtonsPanel):  # , Panel): # inherit from panel when ready
312     #bl_label = "Bones Onion Skinning"
313     bl_context = "data"
314
315     @classmethod
316     def poll(cls, context):
317         # XXX: include pose-mode check?
318         return (context.object) and (context.armature)
319
320     def draw(self, context):
321         ob = context.object
322
323         self.draw_settings(context, ob.pose.animation_visualization, bones=True)
324
325
326 class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
327     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
328     _context_path = "object.data"
329     _property_type = bpy.types.Armature
330
331
332 classes = (
333     DATA_PT_context_arm,
334     DATA_PT_skeleton,
335     DATA_PT_display,
336     DATA_PT_bone_group_specials,
337     DATA_PT_bone_groups,
338     DATA_PT_pose_library,
339     DATA_PT_ghost,
340     DATA_PT_iksolver_itasc,
341     DATA_PT_motion_paths,
342     DATA_PT_custom_props_arm,
343 )
344
345 if __name__ == "__main__":  # only for live edit.
346     from bpy.utils import register_class
347     for cls in classes:
348         register_class(cls)