ce05bbf7b0ff99a08f3315d14def0426ceee831c
[blender.git] / source / blender / editors / space_view3d / view3d_ops.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_view3d/view3d_ops.c
28  *  \ingroup spview3d
29  */
30
31
32 #include <stdlib.h>
33 #include <math.h>
34
35
36 #include "DNA_object_types.h"
37 #include "DNA_scene_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_view3d_types.h"
41
42 #include "BKE_blender.h"
43 #include "BKE_context.h"
44 #include "BKE_main.h"
45
46 #include "BLI_math.h"
47 #include "BLI_blenlib.h"
48 #include "BLI_utildefines.h"
49
50 #include "RNA_access.h"
51
52 #include "WM_api.h"
53 #include "WM_types.h"
54
55 #include "ED_screen.h"
56 #include "ED_transform.h"
57
58 #include "view3d_intern.h"
59
60 /* ************************** copy paste ***************************** */
61
62 static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
63 {
64         char str[FILE_MAX];
65         
66         BKE_copybuffer_begin();
67         
68         /* context, selection, could be generalized */
69         CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
70         {
71                 BKE_copybuffer_tag_ID(&ob->id);
72                 
73         }
74         CTX_DATA_END;
75         
76         BLI_make_file_string("/", str, BLI_temporary_dir(), "copybuffer.blend");
77         BKE_copybuffer_save(str, op->reports);
78         
79         return OPERATOR_FINISHED;
80 }
81
82 static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
83 {
84         
85         /* identifiers */
86         ot->name = "Copy Selection to Buffer";
87         ot->idname = "VIEW3D_OT_copybuffer";
88         ot->description = "Selected objects are saved in a temp file";
89         
90         /* api callbacks */
91         ot->invoke = WM_operator_confirm;
92         ot->exec = view3d_copybuffer_exec;
93         ot->poll = ED_operator_view3d_active;
94 }
95
96 static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
97 {
98         char str[FILE_MAX];
99         
100         BLI_make_file_string("/", str, BLI_temporary_dir(), "copybuffer.blend");
101         BKE_copybuffer_paste(C, str, op->reports);
102
103         WM_event_add_notifier(C, NC_WINDOW, NULL);
104         
105         return OPERATOR_FINISHED;
106 }
107
108 static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
109 {
110         
111         /* identifiers */
112         ot->name = "Paste Selection from Buffer";
113         ot->idname = "VIEW3D_OT_pastebuffer";
114         ot->description = "Contents of copybuffer gets pasted";
115         
116         /* api callbacks */
117         ot->invoke = WM_operator_confirm;
118         ot->exec = view3d_pastebuffer_exec;
119         ot->poll = ED_operator_view3d_active;
120         
121         /* flags */
122         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
123 }
124
125 /* ************************** registration **********************************/
126
127 void view3d_operatortypes(void)
128 {
129         WM_operatortype_append(VIEW3D_OT_rotate);
130         WM_operatortype_append(VIEW3D_OT_move);
131         WM_operatortype_append(VIEW3D_OT_zoom);
132         WM_operatortype_append(VIEW3D_OT_zoom_camera_1_to_1);
133         WM_operatortype_append(VIEW3D_OT_dolly);
134         WM_operatortype_append(VIEW3D_OT_ndof_orbit);
135         WM_operatortype_append(VIEW3D_OT_ndof_pan);
136         WM_operatortype_append(VIEW3D_OT_ndof_all);
137         WM_operatortype_append(VIEW3D_OT_view_all);
138         WM_operatortype_append(VIEW3D_OT_viewnumpad);
139         WM_operatortype_append(VIEW3D_OT_view_orbit);
140         WM_operatortype_append(VIEW3D_OT_view_pan);
141         WM_operatortype_append(VIEW3D_OT_view_persportho);
142         WM_operatortype_append(VIEW3D_OT_background_image_add);
143         WM_operatortype_append(VIEW3D_OT_background_image_remove);
144         WM_operatortype_append(VIEW3D_OT_view_selected);
145         WM_operatortype_append(VIEW3D_OT_view_lock_clear);
146         WM_operatortype_append(VIEW3D_OT_view_lock_to_active);
147         WM_operatortype_append(VIEW3D_OT_view_center_cursor);
148         WM_operatortype_append(VIEW3D_OT_view_center_camera);
149         WM_operatortype_append(VIEW3D_OT_select);
150         WM_operatortype_append(VIEW3D_OT_select_border);
151         WM_operatortype_append(VIEW3D_OT_clip_border);
152         WM_operatortype_append(VIEW3D_OT_select_circle);
153         WM_operatortype_append(VIEW3D_OT_smoothview);
154         WM_operatortype_append(VIEW3D_OT_render_border);
155         WM_operatortype_append(VIEW3D_OT_clear_render_border);
156         WM_operatortype_append(VIEW3D_OT_zoom_border);
157         WM_operatortype_append(VIEW3D_OT_manipulator);
158         WM_operatortype_append(VIEW3D_OT_enable_manipulator);
159         WM_operatortype_append(VIEW3D_OT_cursor3d);
160         WM_operatortype_append(VIEW3D_OT_select_lasso);
161         WM_operatortype_append(VIEW3D_OT_select_menu);
162         WM_operatortype_append(VIEW3D_OT_camera_to_view);
163         WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
164         WM_operatortype_append(VIEW3D_OT_object_as_camera);
165         WM_operatortype_append(VIEW3D_OT_localview);
166         WM_operatortype_append(VIEW3D_OT_game_start);
167         WM_operatortype_append(VIEW3D_OT_fly);
168         WM_operatortype_append(VIEW3D_OT_layers);
169         WM_operatortype_append(VIEW3D_OT_copybuffer);
170         WM_operatortype_append(VIEW3D_OT_pastebuffer);
171         
172         WM_operatortype_append(VIEW3D_OT_properties);
173         WM_operatortype_append(VIEW3D_OT_toolshelf);
174         
175         WM_operatortype_append(VIEW3D_OT_snap_selected_to_grid);
176         WM_operatortype_append(VIEW3D_OT_snap_selected_to_cursor);
177         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_grid);
178         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_center);
179         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_selected);
180         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_active);
181                 
182         transform_operatortypes();
183 }
184
185 void view3d_keymap(wmKeyConfig *keyconf)
186 {
187         wmKeyMap *keymap;
188         wmKeyMapItem *kmi;
189         
190         keymap = WM_keymap_find(keyconf, "3D View Generic", SPACE_VIEW3D, 0);
191
192         WM_keymap_add_item(keymap, "VIEW3D_OT_properties", NKEY, KM_PRESS, 0, 0);
193         WM_keymap_add_item(keymap, "VIEW3D_OT_toolshelf", TKEY, KM_PRESS, 0, 0);
194         
195         /* only for region 3D window */
196         keymap = WM_keymap_find(keyconf, "3D View", SPACE_VIEW3D, 0);
197
198         /* 3D mouse align */
199         /* note: positioned here so keymaps show keyboard keys if assigned */
200         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, KM_SHIFT, 0);
201         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_FRONT);
202         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
203         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, KM_SHIFT, 0);
204         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_RIGHT);
205         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
206         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, KM_SHIFT, 0);
207         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_TOP);
208         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
209
210         kmi = WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
211         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
212         /*
213          * Doesn't work with KM_SHIFT, have to use KM_ANY and filter in invoke
214          * */
215         // WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
216         
217         WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0);
218         
219         WM_keymap_verify_item(keymap, "VIEW3D_OT_rotate", MIDDLEMOUSE, KM_PRESS, 0, 0);
220         WM_keymap_verify_item(keymap, "VIEW3D_OT_move", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
221         WM_keymap_verify_item(keymap, "VIEW3D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
222         WM_keymap_verify_item(keymap, "VIEW3D_OT_dolly", MIDDLEMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
223         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, KM_CTRL, 0);
224         RNA_boolean_set(kmi->ptr, "use_all_regions", TRUE);
225         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
226         RNA_boolean_set(kmi->ptr, "use_all_regions", FALSE);
227
228         WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_to_active", PADPERIOD, KM_PRESS, KM_SHIFT, 0);
229         WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_clear", PADPERIOD, KM_PRESS, KM_ALT, 0);
230
231         WM_keymap_verify_item(keymap, "VIEW3D_OT_fly", FKEY, KM_PRESS, KM_SHIFT, 0);
232
233         WM_keymap_verify_item(keymap, "VIEW3D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);
234         
235         WM_keymap_add_item(keymap, "VIEW3D_OT_rotate", MOUSEPAN, 0, KM_ALT, 0);
236         WM_keymap_add_item(keymap, "VIEW3D_OT_rotate", MOUSEROTATE, 0, 0, 0);
237         WM_keymap_add_item(keymap, "VIEW3D_OT_move", MOUSEPAN, 0, 0, 0);
238         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MOUSEZOOM, 0, 0, 0);
239         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MOUSEPAN, 0, KM_CTRL, 0);
240         
241         /*numpad +/-*/
242         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", PADPLUSKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
243         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", PADMINUS, KM_PRESS, 0, 0)->ptr, "delta", -1);
244
245         /*ctrl +/-*/
246         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", EQUALKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", 1);
247         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MINUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", -1);
248         
249         /*wheel mouse forward/back*/
250         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELINMOUSE, KM_PRESS, 0, 0)->ptr, "delta", 1);
251         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELOUTMOUSE, KM_PRESS, 0, 0)->ptr, "delta", -1);
252
253         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_camera_1_to_1", PADENTER, KM_PRESS, KM_SHIFT, 0);
254
255         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_camera", HOMEKEY, KM_PRESS, 0, 0); /* only with camera view */
256
257         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_cursor", HOMEKEY, KM_PRESS, KM_ALT, 0);
258
259         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
260         RNA_boolean_set(kmi->ptr, "center", FALSE); /* only without camera view */
261         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, KM_CTRL, 0);
262         RNA_boolean_set(kmi->ptr, "use_all_regions", TRUE);
263         RNA_boolean_set(kmi->ptr, "center", FALSE); /* only without camera view */
264         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0);
265         RNA_boolean_set(kmi->ptr, "center", TRUE);
266
267         /* numpad view hotkeys*/
268         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA);
269         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT);
270         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD2, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPDOWN);
271         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT);
272         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD4, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
273         WM_keymap_add_item(keymap, "VIEW3D_OT_view_persportho", PAD5, KM_PRESS, 0, 0);
274         
275         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD6, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
276         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP);
277         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD8, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPUP);
278         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BACK);
279         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_LEFT);
280         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BOTTOM);
281         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD2, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANDOWN);
282         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD4, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANLEFT);
283         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD6, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANRIGHT);
284         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANUP);
285         
286         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANRIGHT);
287         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANLEFT);
288         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_PANUP);
289         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_PANDOWN);
290
291         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", WHEELUPMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
292         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
293         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", WHEELUPMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0)->ptr, "type", V3D_VIEW_STEPUP);
294         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0)->ptr, "type", V3D_VIEW_STEPDOWN);
295         
296         /* active aligned, replaces '*' key in 2.4x */
297         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT, 0);
298         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_FRONT);
299         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
300         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT, 0);
301         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_RIGHT);
302         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
303         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT, 0);
304         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_TOP);
305         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
306         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
307         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BACK);
308         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
309         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
310         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_LEFT);
311         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
312         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
313         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BOTTOM);
314         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
315
316         WM_keymap_add_item(keymap, "VIEW3D_OT_localview", PADSLASHKEY, KM_PRESS, 0, 0);
317         
318         /* layers, shift + alt are properties set in invoke() */
319         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", ACCENTGRAVEKEY, KM_PRESS, 0, 0)->ptr, "nr", 0);
320         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", ONEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 1);
321         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", TWOKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 2);
322         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", THREEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 3);
323         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", FOURKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 4);
324         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", FIVEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 5);
325         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", SIXKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 6);
326         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", SEVENKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 7);
327         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", EIGHTKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 8);
328         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", NINEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 9);
329         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", ZEROKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 10);
330         
331         /* drawtype */
332
333         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, 0, 0);
334         RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
335         RNA_string_set(kmi->ptr, "value_1", "SOLID");
336         RNA_string_set(kmi->ptr, "value_2", "WIREFRAME");
337
338         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, KM_ALT, 0);
339         RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
340         RNA_string_set(kmi->ptr, "value_1", "SOLID");
341         RNA_string_set(kmi->ptr, "value_2", "TEXTURED");
342
343         /* selection*/
344         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
345         RNA_boolean_set(kmi->ptr, "extend", FALSE);
346         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
347         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
348         RNA_boolean_set(kmi->ptr, "center", FALSE);
349         RNA_boolean_set(kmi->ptr, "object", FALSE);
350         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
351         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
352         RNA_boolean_set(kmi->ptr, "extend", FALSE);
353         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
354         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
355         RNA_boolean_set(kmi->ptr, "center", FALSE);
356         RNA_boolean_set(kmi->ptr, "object", FALSE);
357         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
358         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
359         RNA_boolean_set(kmi->ptr, "extend", FALSE);
360         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
361         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
362         RNA_boolean_set(kmi->ptr, "center", TRUE);
363         RNA_boolean_set(kmi->ptr, "object", TRUE); /* use Ctrl+Select for 2 purposes */
364         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
365         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
366         RNA_boolean_set(kmi->ptr, "extend", FALSE);
367         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
368         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
369         RNA_boolean_set(kmi->ptr, "center", FALSE);
370         RNA_boolean_set(kmi->ptr, "object", FALSE);
371         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
372
373         /* selection key-combinations */
374         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
375         RNA_boolean_set(kmi->ptr, "extend", TRUE);
376         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
377         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
378         RNA_boolean_set(kmi->ptr, "center", TRUE);
379         RNA_boolean_set(kmi->ptr, "object", FALSE);
380         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
381         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0);
382         RNA_boolean_set(kmi->ptr, "extend", FALSE);
383         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
384         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
385         RNA_boolean_set(kmi->ptr, "center", TRUE);
386         RNA_boolean_set(kmi->ptr, "object", FALSE);
387         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
388         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0);
389         RNA_boolean_set(kmi->ptr, "extend", FALSE);
390         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
391         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
392         RNA_boolean_set(kmi->ptr, "center", FALSE);
393         RNA_boolean_set(kmi->ptr, "object", FALSE);
394         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
395         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL | KM_ALT, 0);
396         RNA_boolean_set(kmi->ptr, "extend", FALSE);
397         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
398         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
399         RNA_boolean_set(kmi->ptr, "center", TRUE);
400         RNA_boolean_set(kmi->ptr, "object", FALSE);
401         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
402
403         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
404         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
405         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
406         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
407         RNA_boolean_set(kmi->ptr, "deselect", TRUE);
408         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
409         
410         WM_keymap_add_item(keymap, "VIEW3D_OT_clip_border", BKEY, KM_PRESS, KM_ALT, 0);
411         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
412
413         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_SHIFT, 0);
414         RNA_boolean_set(kmi->ptr, "camera_only", TRUE);
415         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_CTRL, 0);
416         RNA_boolean_set(kmi->ptr, "camera_only", FALSE);
417
418         WM_keymap_add_item(keymap, "VIEW3D_OT_clear_render_border", BKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
419         
420         WM_keymap_add_item(keymap, "VIEW3D_OT_camera_to_view", PAD0, KM_PRESS, KM_ALT | KM_CTRL, 0);
421         WM_keymap_add_item(keymap, "VIEW3D_OT_object_as_camera", PAD0, KM_PRESS, KM_CTRL, 0);
422         
423         WM_keymap_add_menu(keymap, "VIEW3D_MT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
424         
425 #ifdef __APPLE__
426         WM_keymap_add_item(keymap, "VIEW3D_OT_copybuffer", CKEY, KM_PRESS, KM_OSKEY, 0);
427         WM_keymap_add_item(keymap, "VIEW3D_OT_pastebuffer", VKEY, KM_PRESS, KM_OSKEY, 0);
428 #endif
429         WM_keymap_add_item(keymap, "VIEW3D_OT_copybuffer", CKEY, KM_PRESS, KM_CTRL, 0);
430         WM_keymap_add_item(keymap, "VIEW3D_OT_pastebuffer", VKEY, KM_PRESS, KM_CTRL, 0);
431         
432         /* context ops */
433         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0);
434         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
435         RNA_string_set(kmi->ptr, "value", "BOUNDING_BOX_CENTER");
436
437         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0); /* 2.4x allowed Comma+Shift too, rather not use both */
438         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
439         RNA_string_set(kmi->ptr, "value", "MEDIAN_POINT");
440
441         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", COMMAKEY, KM_PRESS, KM_ALT, 0); /* new in 2.5 */
442         RNA_string_set(kmi->ptr, "data_path", "space_data.use_pivot_point_align");
443
444         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SPACEKEY, KM_PRESS, KM_CTRL, 0); /* new in 2.5 */
445         RNA_string_set(kmi->ptr, "data_path", "space_data.show_manipulator");
446
447         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0);
448         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
449         RNA_string_set(kmi->ptr, "value", "CURSOR");
450
451         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_CTRL, 0);
452         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
453         RNA_string_set(kmi->ptr, "value", "INDIVIDUAL_ORIGINS");
454
455         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_ALT, 0);
456         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
457         RNA_string_set(kmi->ptr, "value", "ACTIVE_ELEMENT");
458
459         transform_keymap_for_space(keyconf, keymap, SPACE_VIEW3D);
460
461         fly_modal_keymap(keyconf);
462         viewrotate_modal_keymap(keyconf);
463         viewmove_modal_keymap(keyconf);
464         viewzoom_modal_keymap(keyconf);
465         viewdolly_modal_keymap(keyconf);
466 }
467