svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22099:22130
[blender.git] / source / blender / editors / object / object_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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2008 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 #include "DNA_object_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_view3d_types.h"
40 #include "DNA_windowmanager_types.h"
41
42 #include "BLI_arithb.h"
43 #include "BLI_blenlib.h"
44
45 #include "BKE_context.h"
46 #include "BKE_global.h"
47 #include "BKE_utildefines.h"
48
49 #include "RNA_access.h"
50 #include "RNA_define.h"
51
52 #include "WM_api.h"
53 #include "WM_types.h"
54
55 #include "ED_screen.h"
56 #include "ED_object.h"
57
58 #include "object_intern.h"
59
60
61 /* ************************** registration **********************************/
62
63
64 void ED_operatortypes_object(void)
65 {
66         wmOperatorType *ot;
67         
68         WM_operatortype_append(OBJECT_OT_editmode_toggle);
69         WM_operatortype_append(OBJECT_OT_posemode_toggle);
70         WM_operatortype_append(OBJECT_OT_parent_set);
71         WM_operatortype_append(OBJECT_OT_parent_clear);
72         WM_operatortype_append(OBJECT_OT_track_set);
73         WM_operatortype_append(OBJECT_OT_track_clear);
74         WM_operatortype_append(OBJECT_OT_select_inverse);
75         WM_operatortype_append(OBJECT_OT_select_random);
76         WM_operatortype_append(OBJECT_OT_select_all_toggle);
77         WM_operatortype_append(OBJECT_OT_select_by_type);
78         WM_operatortype_append(OBJECT_OT_select_by_layer);
79         WM_operatortype_append(OBJECT_OT_select_linked);
80         WM_operatortype_append(OBJECT_OT_select_grouped);
81         WM_operatortype_append(OBJECT_OT_location_clear);
82         WM_operatortype_append(OBJECT_OT_rotation_clear);
83         WM_operatortype_append(OBJECT_OT_scale_clear);
84         WM_operatortype_append(OBJECT_OT_origin_clear);
85         WM_operatortype_append(OBJECT_OT_restrictview_clear);
86         WM_operatortype_append(OBJECT_OT_restrictview_set);
87         WM_operatortype_append(OBJECT_OT_slowparent_set);
88         WM_operatortype_append(OBJECT_OT_slowparent_clear);
89         WM_operatortype_append(OBJECT_OT_center_set);
90         WM_operatortype_append(OBJECT_OT_duplicates_make_real);
91         WM_operatortype_append(OBJECT_OT_duplicate);
92         WM_operatortype_append(OBJECT_OT_join);
93         WM_operatortype_append(OBJECT_OT_proxy_make);
94         WM_operatortype_append(OBJECT_OT_shade_smooth);
95         WM_operatortype_append(OBJECT_OT_shade_flat);
96         WM_operatortype_append(GROUP_OT_group_create);
97         WM_operatortype_append(GROUP_OT_objects_remove);
98         WM_operatortype_append(GROUP_OT_objects_add_active);
99         WM_operatortype_append(GROUP_OT_objects_remove_active);
100
101         WM_operatortype_append(OBJECT_OT_delete);
102         WM_operatortype_append(OBJECT_OT_mesh_add);
103         WM_operatortype_append(OBJECT_OT_curve_add);
104         WM_operatortype_append(OBJECT_OT_text_add);
105         WM_operatortype_append(OBJECT_OT_surface_add);
106         WM_operatortype_append(OBJECT_OT_armature_add);
107         WM_operatortype_append(OBJECT_OT_object_add);
108         WM_operatortype_append(OBJECT_OT_primitive_add);
109         WM_operatortype_append(OBJECT_OT_mesh_add);
110         WM_operatortype_append(OBJECT_OT_metaball_add);
111
112         WM_operatortype_append(OBJECT_OT_modifier_add);
113         WM_operatortype_append(OBJECT_OT_modifier_remove);
114         WM_operatortype_append(OBJECT_OT_modifier_move_up);
115         WM_operatortype_append(OBJECT_OT_modifier_move_down);
116         WM_operatortype_append(OBJECT_OT_modifier_apply);
117         WM_operatortype_append(OBJECT_OT_modifier_convert);
118         WM_operatortype_append(OBJECT_OT_modifier_copy);
119         WM_operatortype_append(OBJECT_OT_multires_subdivide);
120         WM_operatortype_append(OBJECT_OT_modifier_mdef_bind);
121
122         WM_operatortype_append(OBJECT_OT_constraint_add);
123         WM_operatortype_append(OBJECT_OT_constraint_add_with_targets);
124         WM_operatortype_append(POSE_OT_constraint_add);
125         WM_operatortype_append(POSE_OT_constraint_add_with_targets);
126         WM_operatortype_append(OBJECT_OT_constraints_clear);
127         WM_operatortype_append(POSE_OT_constraints_clear);
128         WM_operatortype_append(POSE_OT_ik_add);
129         WM_operatortype_append(POSE_OT_ik_clear);
130         WM_operatortype_append(CONSTRAINT_OT_delete);
131         WM_operatortype_append(CONSTRAINT_OT_move_up);
132         WM_operatortype_append(CONSTRAINT_OT_move_down);
133         WM_operatortype_append(CONSTRAINT_OT_stretchto_reset);
134         WM_operatortype_append(CONSTRAINT_OT_limitdistance_reset);
135         WM_operatortype_append(CONSTRAINT_OT_childof_set_inverse);
136         WM_operatortype_append(CONSTRAINT_OT_childof_clear_inverse);
137
138         WM_operatortype_append(OBJECT_OT_vertex_group_add);
139         WM_operatortype_append(OBJECT_OT_vertex_group_remove);
140         WM_operatortype_append(OBJECT_OT_vertex_group_assign);
141         WM_operatortype_append(OBJECT_OT_vertex_group_remove_from);
142         WM_operatortype_append(OBJECT_OT_vertex_group_select);
143         WM_operatortype_append(OBJECT_OT_vertex_group_deselect);
144         WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked);
145         WM_operatortype_append(OBJECT_OT_vertex_group_copy);
146
147         WM_operatortype_append(OBJECT_OT_shape_key_add);
148         WM_operatortype_append(OBJECT_OT_shape_key_remove);
149
150         WM_operatortype_append(LATTICE_OT_select_all_toggle);
151         WM_operatortype_append(LATTICE_OT_make_regular);
152         
153         /* macros */
154         ot= WM_operatortype_append_macro("OBJECT_OT_duplicate_move", "Add Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
155         if(ot) {
156                 WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
157                 WM_operatortype_macro_define(ot, "TFM_OT_translate");
158         }
159 }
160
161 void ED_keymap_object(wmWindowManager *wm)
162 {
163         ListBase *keymap= WM_keymap_listbase(wm, "Object Non-modal", 0, 0);
164         
165         /* Note: this keymap works disregarding mode */
166         WM_keymap_add_item(keymap, "OBJECT_OT_editmode_toggle", TABKEY, KM_PRESS, 0, 0);
167         WM_keymap_add_item(keymap, "OBJECT_OT_posemode_toggle", TABKEY, KM_PRESS, KM_CTRL, 0);
168         WM_keymap_add_item(keymap, "OBJECT_OT_center_set", CKEY, KM_PRESS, KM_ALT|KM_SHIFT|KM_CTRL, 0);
169
170         /* Note: this keymap gets disabled in non-objectmode,  */
171         keymap= WM_keymap_listbase(wm, "Object Mode", 0, 0);
172         
173         WM_keymap_add_item(keymap, "OBJECT_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
174         WM_keymap_add_item(keymap, "OBJECT_OT_select_inverse", IKEY, KM_PRESS, KM_CTRL, 0);
175         WM_keymap_add_item(keymap, "OBJECT_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);
176         WM_keymap_add_item(keymap, "OBJECT_OT_select_grouped", GKEY, KM_PRESS, KM_SHIFT, 0);
177         
178         WM_keymap_verify_item(keymap, "OBJECT_OT_parent_set", PKEY, KM_PRESS, KM_CTRL, 0);
179         WM_keymap_verify_item(keymap, "OBJECT_OT_parent_clear", PKEY, KM_PRESS, KM_ALT, 0);
180         WM_keymap_verify_item(keymap, "OBJECT_OT_track_set", TKEY, KM_PRESS, KM_CTRL, 0);
181         WM_keymap_verify_item(keymap, "OBJECT_OT_track_clear", TKEY, KM_PRESS, KM_ALT, 0);
182         
183         WM_keymap_verify_item(keymap, "OBJECT_OT_constraint_add_with_targets", CKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
184         WM_keymap_verify_item(keymap, "OBJECT_OT_constraints_clear", CKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
185         
186         WM_keymap_verify_item(keymap, "OBJECT_OT_location_clear", GKEY, KM_PRESS, KM_ALT, 0);
187         WM_keymap_verify_item(keymap, "OBJECT_OT_rotation_clear", RKEY, KM_PRESS, KM_ALT, 0);
188         WM_keymap_verify_item(keymap, "OBJECT_OT_scale_clear", SKEY, KM_PRESS, KM_ALT, 0);
189         WM_keymap_verify_item(keymap, "OBJECT_OT_origin_clear", OKEY, KM_PRESS, KM_ALT, 0);
190         
191         WM_keymap_add_item(keymap, "OBJECT_OT_restrictview_clear", HKEY, KM_PRESS, KM_ALT, 0);
192         WM_keymap_add_item(keymap, "OBJECT_OT_restrictview_set", HKEY, KM_PRESS, 0, 0);
193         RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_restrictview_set", HKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "unselected", 1);
194         
195         WM_keymap_verify_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, 0, 0);
196         WM_keymap_verify_item(keymap, "OBJECT_OT_primitive_add", AKEY, KM_PRESS, KM_SHIFT, 0);
197         WM_keymap_add_item(keymap, "OBJECT_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
198         RNA_boolean_set(WM_keymap_add_item(keymap, "OBJECT_OT_duplicate", DKEY, KM_PRESS, KM_ALT, 0)->ptr, "linked", 1);
199         WM_keymap_add_item(keymap, "OBJECT_OT_join", JKEY, KM_PRESS, KM_CTRL, 0);
200         WM_keymap_add_item(keymap, "OBJECT_OT_proxy_make", PKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
201         
202         // XXX this should probably be in screen instead... here for testing purposes in the meantime... - Aligorith
203         WM_keymap_verify_item(keymap, "ANIM_OT_insert_keyframe_menu", IKEY, KM_PRESS, 0, 0);
204         WM_keymap_verify_item(keymap, "ANIM_OT_delete_keyframe_v3d", IKEY, KM_PRESS, KM_ALT, 0);
205         
206         WM_keymap_verify_item(keymap, "GROUP_OT_group_create", GKEY, KM_PRESS, KM_CTRL, 0);
207         WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove", GKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
208         WM_keymap_verify_item(keymap, "GROUP_OT_objects_add_active", GKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
209         WM_keymap_verify_item(keymap, "GROUP_OT_objects_remove_active", GKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
210
211         /* Lattice */
212         keymap= WM_keymap_listbase(wm, "Lattice", 0, 0);
213
214         WM_keymap_add_item(keymap, "LATTICE_OT_select_all_toggle", AKEY, KM_PRESS, 0, 0);
215 }
216