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