remove unused includes
[blender.git] / source / blender / editors / armature / armature_ops.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. 
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2009 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <stdlib.h>
30 #include <math.h>
31
32 #include "MEM_guardedalloc.h"
33
34
35 #include "BLI_math.h"
36 #include "BLI_blenlib.h"
37
38
39 #include "RNA_access.h"
40
41 #include "WM_api.h"
42 #include "WM_types.h"
43
44 #include "ED_armature.h"
45 #include "ED_screen.h"
46 #include "ED_transform.h"
47
48 #include "armature_intern.h"
49
50 /* ************************** registration **********************************/
51
52 /* Both operators ARMATURE_OT_xxx and POSE_OT_xxx here */
53 void ED_operatortypes_armature(void)
54 {
55         /* EDIT ARMATURE */
56         WM_operatortype_append(ARMATURE_OT_bone_primitive_add);
57         
58         WM_operatortype_append(ARMATURE_OT_align);
59         WM_operatortype_append(ARMATURE_OT_calculate_roll);
60         WM_operatortype_append(ARMATURE_OT_switch_direction);
61         WM_operatortype_append(ARMATURE_OT_subdivs);
62         WM_operatortype_append(ARMATURE_OT_subdivide_simple);
63         WM_operatortype_append(ARMATURE_OT_subdivide_multi);
64         
65         WM_operatortype_append(ARMATURE_OT_parent_set);
66         WM_operatortype_append(ARMATURE_OT_parent_clear);
67         
68         WM_operatortype_append(ARMATURE_OT_select_all);
69         WM_operatortype_append(ARMATURE_OT_select_inverse);
70         WM_operatortype_append(ARMATURE_OT_select_hierarchy);
71         WM_operatortype_append(ARMATURE_OT_select_linked);
72
73         WM_operatortype_append(ARMATURE_OT_delete);
74         WM_operatortype_append(ARMATURE_OT_duplicate);
75         WM_operatortype_append(ARMATURE_OT_extrude);
76         WM_operatortype_append(ARMATURE_OT_click_extrude);
77         WM_operatortype_append(ARMATURE_OT_fill);
78         WM_operatortype_append(ARMATURE_OT_merge);
79         WM_operatortype_append(ARMATURE_OT_separate);
80         
81         WM_operatortype_append(ARMATURE_OT_autoside_names);
82         WM_operatortype_append(ARMATURE_OT_flip_names);
83         
84         WM_operatortype_append(ARMATURE_OT_flags_set);
85         
86         WM_operatortype_append(ARMATURE_OT_armature_layers);
87         WM_operatortype_append(ARMATURE_OT_bone_layers);
88
89         /* SKETCH */    
90         WM_operatortype_append(SKETCH_OT_gesture);
91         WM_operatortype_append(SKETCH_OT_delete);
92         WM_operatortype_append(SKETCH_OT_draw_stroke);
93         WM_operatortype_append(SKETCH_OT_draw_preview);
94         WM_operatortype_append(SKETCH_OT_finish_stroke);
95         WM_operatortype_append(SKETCH_OT_cancel_stroke);
96         WM_operatortype_append(SKETCH_OT_convert);
97         WM_operatortype_append(SKETCH_OT_select);
98
99         /* POSE */
100         WM_operatortype_append(POSE_OT_hide);
101         WM_operatortype_append(POSE_OT_reveal);
102         
103         WM_operatortype_append(POSE_OT_armature_apply);
104         WM_operatortype_append(POSE_OT_visual_transform_apply);
105         
106         WM_operatortype_append(POSE_OT_rot_clear);
107         WM_operatortype_append(POSE_OT_loc_clear);
108         WM_operatortype_append(POSE_OT_scale_clear);
109         
110         WM_operatortype_append(POSE_OT_copy);
111         WM_operatortype_append(POSE_OT_paste);
112         
113         WM_operatortype_append(POSE_OT_select_all);
114         WM_operatortype_append(POSE_OT_select_inverse);
115
116         WM_operatortype_append(POSE_OT_select_parent);
117         WM_operatortype_append(POSE_OT_select_hierarchy);
118         WM_operatortype_append(POSE_OT_select_linked);
119         WM_operatortype_append(POSE_OT_select_constraint_target);
120         WM_operatortype_append(POSE_OT_select_grouped);
121         
122         WM_operatortype_append(POSE_OT_group_add);
123         WM_operatortype_append(POSE_OT_group_remove);
124         WM_operatortype_append(POSE_OT_group_assign);
125         WM_operatortype_append(POSE_OT_group_unassign);
126         WM_operatortype_append(POSE_OT_group_select);
127         WM_operatortype_append(POSE_OT_group_deselect);
128         
129         WM_operatortype_append(POSE_OT_paths_calculate);
130         WM_operatortype_append(POSE_OT_paths_clear);
131         
132         WM_operatortype_append(POSE_OT_autoside_names);
133         WM_operatortype_append(POSE_OT_flip_names);
134         
135         WM_operatortype_append(POSE_OT_quaternions_flip);
136         
137         WM_operatortype_append(POSE_OT_flags_set);
138         
139         WM_operatortype_append(POSE_OT_armature_layers);
140         WM_operatortype_append(POSE_OT_bone_layers);
141         
142         /* POSELIB */
143         WM_operatortype_append(POSELIB_OT_browse_interactive);
144         
145         WM_operatortype_append(POSELIB_OT_pose_add);
146         WM_operatortype_append(POSELIB_OT_pose_remove);
147         WM_operatortype_append(POSELIB_OT_pose_rename);
148         
149         /* POSE SLIDING */
150         WM_operatortype_append(POSE_OT_push);
151         WM_operatortype_append(POSE_OT_relax);
152         WM_operatortype_append(POSE_OT_breakdown);
153 }
154
155 void ED_operatormacros_armature(void)
156 {
157         wmOperatorType *ot;
158         wmOperatorTypeMacro *otmacro;
159         
160         ot= WM_operatortype_append_macro("ARMATURE_OT_duplicate_move", "Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
161         WM_operatortype_macro_define(ot, "ARMATURE_OT_duplicate");
162         otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
163         RNA_enum_set(otmacro->ptr, "proportional", 0);
164
165         ot= WM_operatortype_append_macro("ARMATURE_OT_extrude_move", "Extrude", OPTYPE_UNDO|OPTYPE_REGISTER);
166         otmacro=WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude");
167         RNA_enum_set(otmacro->ptr, "forked", 0);
168         otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
169         RNA_enum_set(otmacro->ptr, "proportional", 0);
170         
171         // XXX would it be nicer to just be able to have standard extrude_move, but set the forked property separate?
172         // that would require fixing a properties bug 19733
173         ot= WM_operatortype_append_macro("ARMATURE_OT_extrude_forked", "Extrude Forked", OPTYPE_UNDO|OPTYPE_REGISTER);
174         otmacro=WM_operatortype_macro_define(ot, "ARMATURE_OT_extrude");
175         RNA_enum_set(otmacro->ptr, "forked", 1);
176         otmacro= WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
177         RNA_enum_set(otmacro->ptr, "proportional", 0);
178 }
179
180 void ED_keymap_armature(wmKeyConfig *keyconf)
181 {
182         wmKeyMap *keymap;
183         wmKeyMapItem *kmi;
184         
185         /* Armature ------------------------ */
186         keymap= WM_keymap_find(keyconf, "Armature", 0, 0);
187         keymap->poll= ED_operator_editarmature;
188         
189         /* Armature -> Etch-A-Ton ------------------------ */
190         WM_keymap_add_item(keymap, "SKETCH_OT_delete", XKEY, KM_PRESS, 0, 0);
191         WM_keymap_add_item(keymap, "SKETCH_OT_delete", DELKEY, KM_PRESS, 0, 0);
192         WM_keymap_add_item(keymap, "SKETCH_OT_finish_stroke", RIGHTMOUSE, KM_PRESS, 0, 0);
193         WM_keymap_add_item(keymap, "SKETCH_OT_cancel_stroke", ESCKEY, KM_PRESS, 0, 0);
194         // Already part of view3d select
195         //WM_keymap_add_item(keymap, "SKETCH_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
196
197         /* sketch poll checks mode */   
198         WM_keymap_add_item(keymap, "SKETCH_OT_gesture", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
199         WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
200         kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
201         RNA_boolean_set(kmi->ptr, "snap", 1);
202         WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, 0, 0);
203         kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, KM_CTRL, 0);
204         RNA_boolean_set(kmi->ptr, "snap", 1);
205
206         /* only set in editmode armature, by space_view3d listener */
207 //      WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0);
208         WM_keymap_add_item(keymap, "ARMATURE_OT_align", AKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
209         WM_keymap_add_item(keymap, "ARMATURE_OT_calculate_roll", NKEY, KM_PRESS, KM_CTRL, 0);
210         
211         WM_keymap_add_item(keymap, "ARMATURE_OT_switch_direction", FKEY, KM_PRESS, KM_ALT, 0);
212         
213         WM_keymap_add_item(keymap, "ARMATURE_OT_bone_primitive_add", AKEY, KM_PRESS, KM_SHIFT, 0);
214         
215         WM_keymap_add_item(keymap, "ARMATURE_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
216         WM_keymap_add_item(keymap, "ARMATURE_OT_parent_clear", PKEY, KM_PRESS, KM_ALT, 0);
217         
218         WM_keymap_add_item(keymap, "ARMATURE_OT_select_all", AKEY, KM_PRESS, 0, 0);
219         WM_keymap_add_item(keymap, "ARMATURE_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
220         
221         kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
222                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_PARENT);
223         kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
224                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_PARENT);
225                 RNA_boolean_set(kmi->ptr, "extend", 1);
226         
227         kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
228                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_CHILD);
229         kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
230                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_CHILD);
231                 RNA_boolean_set(kmi->ptr, "extend", 1);
232
233         WM_keymap_add_item(keymap, "ARMATURE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
234         
235         WM_keymap_add_item(keymap, "ARMATURE_OT_delete", XKEY, KM_PRESS, 0, 0);
236         WM_keymap_add_item(keymap, "ARMATURE_OT_delete", DELKEY, KM_PRESS, 0, 0);
237         WM_keymap_add_item(keymap, "ARMATURE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
238         WM_keymap_add_item(keymap, "ARMATURE_OT_extrude_move", EKEY, KM_PRESS, 0, 0);
239         WM_keymap_add_item(keymap, "ARMATURE_OT_extrude_forked", EKEY, KM_PRESS, KM_SHIFT, 0);
240         WM_keymap_add_item(keymap, "ARMATURE_OT_click_extrude", LEFTMOUSE, KM_CLICK, KM_CTRL, 0);
241         WM_keymap_add_item(keymap, "ARMATURE_OT_fill", FKEY, KM_PRESS, 0, 0);
242         WM_keymap_add_item(keymap, "ARMATURE_OT_merge", MKEY, KM_PRESS, KM_ALT, 0);
243         
244         WM_keymap_add_item(keymap, "ARMATURE_OT_separate", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
245         
246                 /* set flags */
247         kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
248                 RNA_enum_set(kmi->ptr, "mode", 2); // toggle
249         kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
250                 RNA_enum_set(kmi->ptr, "mode", 1); // enable
251         kmi= WM_keymap_add_item(keymap, "ARMATURE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
252                 RNA_enum_set(kmi->ptr, "mode", 0); // clear
253                 
254                 /* armature/bone layers */
255         WM_keymap_add_item(keymap, "ARMATURE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
256         WM_keymap_add_item(keymap, "ARMATURE_OT_bone_layers", MKEY, KM_PRESS, 0, 0);
257         
258                 /* special transforms: */
259                 /*      1) envelope/b-bone size */
260         kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
261                 RNA_enum_set(kmi->ptr, "mode", TFM_BONESIZE);
262                 /*      2) set roll */
263         kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", RKEY, KM_PRESS, KM_CTRL, 0);
264                 RNA_enum_set(kmi->ptr, "mode", TFM_BONE_ROLL);
265                 
266                 /* menus */
267         WM_keymap_add_menu(keymap, "VIEW3D_MT_armature_specials", WKEY, KM_PRESS, 0, 0);
268
269         /* Pose ------------------------ */
270         /* only set in posemode, by space_view3d listener */
271         keymap= WM_keymap_find(keyconf, "Pose", 0, 0);
272         keymap->poll= ED_operator_posemode;
273         
274         // XXX: set parent is object-based operator, but it should also be available here...
275         WM_keymap_add_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
276         
277         WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, 0, 0);
278         kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
279                 RNA_boolean_set(kmi->ptr, "unselected", 1);
280         WM_keymap_add_item(keymap, "POSE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
281         
282         WM_keymap_add_menu(keymap, "VIEW3D_MT_pose_apply", AKEY, KM_PRESS, KM_CTRL, 0);
283         
284         // TODO: clear pose
285         WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0);
286         WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0);
287         WM_keymap_add_item(keymap, "POSE_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
288         
289         WM_keymap_add_item(keymap, "POSE_OT_quaternions_flip", FKEY, KM_PRESS, KM_ALT, 0);
290         
291         WM_keymap_add_item(keymap, "POSE_OT_copy", CKEY, KM_PRESS, KM_CTRL, 0);
292         WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL, 0);
293         kmi= WM_keymap_add_item(keymap, "POSE_OT_paste", VKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
294                 RNA_boolean_set(kmi->ptr, "flipped", 1);
295         
296         WM_keymap_add_item(keymap, "POSE_OT_select_all", AKEY, KM_PRESS, 0, 0);
297         WM_keymap_add_item(keymap, "POSE_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
298
299         WM_keymap_add_item(keymap, "POSE_OT_select_parent", PKEY, KM_PRESS, KM_SHIFT, 0);
300
301         kmi= WM_keymap_add_item(keymap, "POSE_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, 0, 0);
302                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_PARENT);
303         kmi= WM_keymap_add_item(keymap, "POSE_OT_select_hierarchy", LEFTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
304                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_PARENT);
305                 RNA_boolean_set(kmi->ptr, "extend", 1);
306         
307         kmi= WM_keymap_add_item(keymap, "POSE_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, 0, 0);
308                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_CHILD);
309         kmi= WM_keymap_add_item(keymap, "POSE_OT_select_hierarchy", RIGHTBRACKETKEY, KM_PRESS, KM_SHIFT, 0);
310                 RNA_enum_set(kmi->ptr, "direction", BONE_SELECT_CHILD);
311                 RNA_boolean_set(kmi->ptr, "extend", 1);
312
313         WM_keymap_add_item(keymap, "POSE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
314         WM_keymap_add_item(keymap, "POSE_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
315         
316         WM_keymap_add_item(keymap, "POSE_OT_constraint_add_with_targets", CKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
317         WM_keymap_add_item(keymap, "POSE_OT_constraints_clear", CKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
318         WM_keymap_add_item(keymap, "POSE_OT_ik_add", IKEY, KM_PRESS, /*KM_CTRL|*/KM_SHIFT, 0);
319         WM_keymap_add_item(keymap, "POSE_OT_ik_clear", IKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
320         
321         WM_keymap_add_menu(keymap, "VIEW3D_MT_pose_group", GKEY, KM_PRESS, KM_CTRL, 0);
322         
323                 /* set flags */
324         kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_SHIFT, 0);
325                 RNA_enum_set(kmi->ptr, "mode", 2); // toggle
326         kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
327                 RNA_enum_set(kmi->ptr, "mode", 1); // enable
328         kmi= WM_keymap_add_item(keymap, "POSE_OT_flags_set", WKEY, KM_PRESS, KM_ALT, 0);
329                 RNA_enum_set(kmi->ptr, "mode", 0); // clear
330                 
331                 /* armature/bone layers */
332         WM_keymap_add_item(keymap, "POSE_OT_armature_layers", MKEY, KM_PRESS, KM_SHIFT, 0);
333         WM_keymap_add_item(keymap, "POSE_OT_bone_layers", MKEY, KM_PRESS, 0, 0);
334         
335                 /* special transforms: */
336                 /*      1) envelope/b-bone size */
337         kmi= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
338                 RNA_enum_set(kmi->ptr, "mode", TFM_BONESIZE);
339         
340                 /* keyframes management */
341         WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_insert_menu", IKEY, KM_PRESS, 0, 0);
342         WM_keymap_verify_item(keymap, "ANIM_OT_keyframe_delete_v3d", IKEY, KM_PRESS, KM_ALT, 0);
343         WM_keymap_verify_item(keymap, "ANIM_OT_keying_set_active_set", IKEY, KM_PRESS, KM_CTRL|KM_SHIFT|KM_ALT, 0);
344         
345         /* Pose -> PoseLib ------------- */
346         /* only set in posemode, by space_view3d listener */
347         WM_keymap_add_item(keymap, "POSELIB_OT_browse_interactive", LKEY, KM_PRESS, KM_CTRL, 0);
348         
349         WM_keymap_add_item(keymap, "POSELIB_OT_pose_add", LKEY, KM_PRESS, KM_SHIFT, 0);
350         WM_keymap_add_item(keymap, "POSELIB_OT_pose_remove", LKEY, KM_PRESS, KM_ALT, 0);
351         WM_keymap_add_item(keymap, "POSELIB_OT_pose_rename", LKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
352         
353         /* Pose -> Pose Sliding ------------- */
354         /* only set in posemode, by space_view3d listener */
355         WM_keymap_add_item(keymap, "POSE_OT_push", EKEY, KM_PRESS, KM_CTRL, 0);
356         WM_keymap_add_item(keymap, "POSE_OT_relax", EKEY, KM_PRESS, KM_ALT, 0);
357         WM_keymap_add_item(keymap, "POSE_OT_breakdown", EKEY, KM_PRESS, KM_SHIFT, 0);
358 }
359