Workspace: Move engines to workspace and Properties Editor cleanup
[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.row().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.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.row().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_MT_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_MT_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             # warning about poselib being in an invalid state
182             if len(poselib.fcurves) > 0 and len(poselib.pose_markers) == 0:
183                 layout.label(icon='ERROR', text="Error: Potentially corrupt library, run 'Sanitize' operator to fix")
184
185             # list of poses in pose library
186             row = layout.row()
187             row.template_list("UI_UL_list", "pose_markers", poselib, "pose_markers",
188                               poselib.pose_markers, "active_index", rows=5)
189
190             # column of operators for active pose
191             # - goes beside list
192             col = row.column(align=True)
193
194             # invoke should still be used for 'add', as it is needed to allow
195             # add/replace options to be used properly
196             col.operator("poselib.pose_add", icon='ZOOMIN', text="")
197
198             col.operator_context = 'EXEC_DEFAULT'  # exec not invoke, so that menu doesn't need showing
199
200             pose_marker_active = poselib.pose_markers.active
201
202             if pose_marker_active is not None:
203                 col.operator("poselib.pose_remove", icon='ZOOMOUT', text="")
204                 col.operator("poselib.apply_pose", icon='ZOOM_SELECTED', text="").pose_index = poselib.pose_markers.active_index
205
206             col.operator("poselib.action_sanitize", icon='HELP', text="")  # XXX: put in menu?
207
208             if pose_marker_active is not None:
209                 col.operator("poselib.pose_move", icon='TRIA_UP', text="").direction = 'UP'
210                 col.operator("poselib.pose_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
211
212
213 # TODO: this panel will soon be deprecated too
214 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
215     bl_label = "Ghost"
216
217     def draw(self, context):
218         layout = self.layout
219
220         arm = context.armature
221
222         layout.row().prop(arm, "ghost_type", expand=True)
223
224         split = layout.split()
225
226         col = split.column(align=True)
227
228         if arm.ghost_type == 'RANGE':
229             col.prop(arm, "ghost_frame_start", text="Start")
230             col.prop(arm, "ghost_frame_end", text="End")
231             col.prop(arm, "ghost_size", text="Step")
232         elif arm.ghost_type == 'CURRENT_FRAME':
233             col.prop(arm, "ghost_step", text="Range")
234             col.prop(arm, "ghost_size", text="Step")
235
236         col = split.column()
237         col.label(text="Display:")
238         col.prop(arm, "show_only_ghost_selected", text="Selected Only")
239
240
241 class DATA_PT_iksolver_itasc(ArmatureButtonsPanel, Panel):
242     bl_label = "Inverse Kinematics"
243     bl_options = {'DEFAULT_CLOSED'}
244
245     @classmethod
246     def poll(cls, context):
247         ob = context.object
248         return (ob and ob.pose)
249
250     def draw(self, context):
251         layout = self.layout
252
253         ob = context.object
254         itasc = ob.pose.ik_param
255
256         layout.prop(ob.pose, "ik_solver")
257
258         if itasc:
259             layout.row().prop(itasc, "mode", expand=True)
260             simulation = (itasc.mode == 'SIMULATION')
261             if simulation:
262                 layout.label(text="Reiteration:")
263                 layout.row().prop(itasc, "reiteration_method", expand=True)
264
265             row = layout.row()
266             row.active = not simulation or itasc.reiteration_method != 'NEVER'
267             row.prop(itasc, "precision")
268             row.prop(itasc, "iterations")
269
270             if simulation:
271                 layout.prop(itasc, "use_auto_step")
272                 row = layout.row()
273                 if itasc.use_auto_step:
274                     row.prop(itasc, "step_min", text="Min")
275                     row.prop(itasc, "step_max", text="Max")
276                 else:
277                     row.prop(itasc, "step_count")
278
279             layout.prop(itasc, "solver")
280             if simulation:
281                 layout.prop(itasc, "feedback")
282                 layout.prop(itasc, "velocity_max")
283             if itasc.solver == 'DLS':
284                 row = layout.row()
285                 row.prop(itasc, "damping_max", text="Damp", slider=True)
286                 row.prop(itasc, "damping_epsilon", text="Eps", slider=True)
287
288 from bl_ui.properties_animviz import (
289         MotionPathButtonsPanel,
290         OnionSkinButtonsPanel,
291         )
292
293
294 class DATA_PT_motion_paths(MotionPathButtonsPanel, Panel):
295     #bl_label = "Bones Motion Paths"
296     bl_context = "data"
297
298     @classmethod
299     def poll(cls, context):
300         # XXX: include pose-mode check?
301         return (context.object) and (context.armature)
302
303     def draw(self, context):
304         # layout = self.layout
305
306         ob = context.object
307         avs = ob.pose.animation_visualization
308
309         pchan = context.active_pose_bone
310         mpath = pchan.motion_path if pchan else None
311
312         self.draw_settings(context, avs, mpath, bones=True)
313
314
315 class DATA_PT_onion_skinning(OnionSkinButtonsPanel):  # , Panel): # inherit from panel when ready
316     #bl_label = "Bones Onion Skinning"
317     bl_context = "data"
318
319     @classmethod
320     def poll(cls, context):
321         # XXX: include pose-mode check?
322         return (context.object) and (context.armature)
323
324     def draw(self, context):
325         ob = context.object
326
327         self.draw_settings(context, ob.pose.animation_visualization, bones=True)
328
329
330 class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
331     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME', 'BLENDER_CLAY', 'BLENDER_EEVEE'}
332     _context_path = "object.data"
333     _property_type = bpy.types.Armature
334
335
336 classes = (
337     DATA_PT_context_arm,
338     DATA_PT_skeleton,
339     DATA_PT_display,
340     DATA_MT_bone_group_specials,
341     DATA_PT_bone_groups,
342     DATA_PT_pose_library,
343     DATA_PT_ghost,
344     DATA_PT_iksolver_itasc,
345     DATA_PT_motion_paths,
346     DATA_PT_custom_props_arm,
347 )
348
349 if __name__ == "__main__":  # only for live edit.
350     from bpy.utils import register_class
351     for cls in classes:
352         register_class(cls)