Merge branch 'master' into blender2.8
[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 = 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=3)
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
205 # TODO: this panel will soon be deprecated too
206 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
207     bl_label = "Ghost"
208
209     def draw(self, context):
210         layout = self.layout
211
212         arm = context.armature
213
214         layout.prop(arm, "ghost_type", expand=True)
215
216         split = layout.split()
217
218         col = split.column(align=True)
219
220         if arm.ghost_type == 'RANGE':
221             col.prop(arm, "ghost_frame_start", text="Start")
222             col.prop(arm, "ghost_frame_end", text="End")
223             col.prop(arm, "ghost_size", text="Step")
224         elif arm.ghost_type == 'CURRENT_FRAME':
225             col.prop(arm, "ghost_step", text="Range")
226             col.prop(arm, "ghost_size", text="Step")
227
228         col = split.column()
229         col.label(text="Display:")
230         col.prop(arm, "show_only_ghost_selected", text="Selected Only")
231
232
233 class DATA_PT_iksolver_itasc(ArmatureButtonsPanel, Panel):
234     bl_label = "Inverse Kinematics"
235     bl_options = {'DEFAULT_CLOSED'}
236
237     @classmethod
238     def poll(cls, context):
239         ob = context.object
240         return (ob and ob.pose)
241
242     def draw(self, context):
243         layout = self.layout
244
245         ob = context.object
246         itasc = ob.pose.ik_param
247
248         layout.prop(ob.pose, "ik_solver")
249
250         if itasc:
251             layout.prop(itasc, "mode", expand=True)
252             simulation = (itasc.mode == 'SIMULATION')
253             if simulation:
254                 layout.label(text="Reiteration:")
255                 layout.prop(itasc, "reiteration_method", expand=True)
256
257             row = layout.row()
258             row.active = not simulation or itasc.reiteration_method != 'NEVER'
259             row.prop(itasc, "precision")
260             row.prop(itasc, "iterations")
261
262             if simulation:
263                 layout.prop(itasc, "use_auto_step")
264                 row = layout.row()
265                 if itasc.use_auto_step:
266                     row.prop(itasc, "step_min", text="Min")
267                     row.prop(itasc, "step_max", text="Max")
268                 else:
269                     row.prop(itasc, "step_count")
270
271             layout.prop(itasc, "solver")
272             if simulation:
273                 layout.prop(itasc, "feedback")
274                 layout.prop(itasc, "velocity_max")
275             if itasc.solver == 'DLS':
276                 row = layout.row()
277                 row.prop(itasc, "damping_max", text="Damp", slider=True)
278                 row.prop(itasc, "damping_epsilon", text="Eps", slider=True)
279
280 from bl_ui.properties_animviz import (
281         MotionPathButtonsPanel,
282         OnionSkinButtonsPanel,
283         )
284
285
286 class DATA_PT_motion_paths(MotionPathButtonsPanel, Panel):
287     #bl_label = "Bones Motion Paths"
288     bl_context = "data"
289
290     @classmethod
291     def poll(cls, context):
292         # XXX: include pose-mode check?
293         return (context.object) and (context.armature)
294
295     def draw(self, context):
296         # layout = self.layout
297
298         ob = context.object
299         avs = ob.pose.animation_visualization
300
301         pchan = context.active_pose_bone
302         mpath = pchan.motion_path if pchan else None
303
304         self.draw_settings(context, avs, mpath, bones=True)
305
306
307 class DATA_PT_onion_skinning(OnionSkinButtonsPanel):  # , Panel): # inherit from panel when ready
308     #bl_label = "Bones Onion Skinning"
309     bl_context = "data"
310
311     @classmethod
312     def poll(cls, context):
313         # XXX: include pose-mode check?
314         return (context.object) and (context.armature)
315
316     def draw(self, context):
317         ob = context.object
318
319         self.draw_settings(context, ob.pose.animation_visualization, bones=True)
320
321
322 class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
323     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
324     _context_path = "object.data"
325     _property_type = bpy.types.Armature
326
327 if __name__ == "__main__":  # only for live edit.
328     bpy.utils.register_module(__name__)