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