Trackpad fixes & changes:
[blender-staging.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 copy buffer 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_zoom);
135         WM_operatortype_append(VIEW3D_OT_ndof_orbit);
136         WM_operatortype_append(VIEW3D_OT_ndof_pan);
137         WM_operatortype_append(VIEW3D_OT_ndof_all);
138         WM_operatortype_append(VIEW3D_OT_view_all);
139         WM_operatortype_append(VIEW3D_OT_viewnumpad);
140         WM_operatortype_append(VIEW3D_OT_view_orbit);
141         WM_operatortype_append(VIEW3D_OT_view_pan);
142         WM_operatortype_append(VIEW3D_OT_view_persportho);
143         WM_operatortype_append(VIEW3D_OT_background_image_add);
144         WM_operatortype_append(VIEW3D_OT_background_image_remove);
145         WM_operatortype_append(VIEW3D_OT_view_selected);
146         WM_operatortype_append(VIEW3D_OT_view_lock_clear);
147         WM_operatortype_append(VIEW3D_OT_view_lock_to_active);
148         WM_operatortype_append(VIEW3D_OT_view_center_cursor);
149         WM_operatortype_append(VIEW3D_OT_view_center_camera);
150         WM_operatortype_append(VIEW3D_OT_select);
151         WM_operatortype_append(VIEW3D_OT_select_border);
152         WM_operatortype_append(VIEW3D_OT_clip_border);
153         WM_operatortype_append(VIEW3D_OT_select_circle);
154         WM_operatortype_append(VIEW3D_OT_smoothview);
155         WM_operatortype_append(VIEW3D_OT_render_border);
156         WM_operatortype_append(VIEW3D_OT_clear_render_border);
157         WM_operatortype_append(VIEW3D_OT_zoom_border);
158         WM_operatortype_append(VIEW3D_OT_manipulator);
159         WM_operatortype_append(VIEW3D_OT_enable_manipulator);
160         WM_operatortype_append(VIEW3D_OT_cursor3d);
161         WM_operatortype_append(VIEW3D_OT_select_lasso);
162         WM_operatortype_append(VIEW3D_OT_select_menu);
163         WM_operatortype_append(VIEW3D_OT_camera_to_view);
164         WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
165         WM_operatortype_append(VIEW3D_OT_object_as_camera);
166         WM_operatortype_append(VIEW3D_OT_localview);
167         WM_operatortype_append(VIEW3D_OT_game_start);
168         WM_operatortype_append(VIEW3D_OT_fly);
169         WM_operatortype_append(VIEW3D_OT_layers);
170         WM_operatortype_append(VIEW3D_OT_copybuffer);
171         WM_operatortype_append(VIEW3D_OT_pastebuffer);
172         
173         WM_operatortype_append(VIEW3D_OT_properties);
174         WM_operatortype_append(VIEW3D_OT_toolshelf);
175         
176         WM_operatortype_append(VIEW3D_OT_snap_selected_to_grid);
177         WM_operatortype_append(VIEW3D_OT_snap_selected_to_cursor);
178         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_grid);
179         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_center);
180         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_selected);
181         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_active);
182                 
183         transform_operatortypes();
184 }
185
186 void view3d_keymap(wmKeyConfig *keyconf)
187 {
188         wmKeyMap *keymap;
189         wmKeyMapItem *kmi;
190         
191         keymap = WM_keymap_find(keyconf, "3D View Generic", SPACE_VIEW3D, 0);
192
193         WM_keymap_add_item(keymap, "VIEW3D_OT_properties", NKEY, KM_PRESS, 0, 0);
194         WM_keymap_add_item(keymap, "VIEW3D_OT_toolshelf", TKEY, KM_PRESS, 0, 0);
195         
196         /* only for region 3D window */
197         keymap = WM_keymap_find(keyconf, "3D View", SPACE_VIEW3D, 0);
198
199
200         /* NDOF: begin */
201         /* note: positioned here so keymaps show keyboard keys if assigned */
202         /* 3D mouse */
203         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_orbit_zoom", NDOF_MOTION, 0, 0, 0);
204         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_orbit", NDOF_MOTION, 0, KM_CTRL, 0);
205         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_pan", NDOF_MOTION, 0, KM_SHIFT, 0);
206         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_all", NDOF_MOTION, 0, KM_CTRL | KM_SHIFT, 0);
207         WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
208         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT);
209         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BACK, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BACK);
210         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_LEFT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_LEFT);
211         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT);
212         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP);
213         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BOTTOM, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BOTTOM);
214
215         /* 3D mouse align */
216         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, KM_SHIFT, 0);
217         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_FRONT);
218         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
219         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, KM_SHIFT, 0);
220         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_RIGHT);
221         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
222         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, KM_SHIFT, 0);
223         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_TOP);
224         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
225         /* NDOF: end */
226
227
228         kmi = WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
229         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
230         /*
231          * Doesn't work with KM_SHIFT, have to use KM_ANY and filter in invoke
232          * */
233         // WM_keymap_verify_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
234         
235         WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0);
236         
237         WM_keymap_verify_item(keymap, "VIEW3D_OT_rotate", MIDDLEMOUSE, KM_PRESS, 0, 0);
238         WM_keymap_verify_item(keymap, "VIEW3D_OT_move", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
239         WM_keymap_verify_item(keymap, "VIEW3D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
240         WM_keymap_verify_item(keymap, "VIEW3D_OT_dolly", MIDDLEMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
241         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, KM_CTRL, 0);
242         RNA_boolean_set(kmi->ptr, "use_all_regions", TRUE);
243         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
244         RNA_boolean_set(kmi->ptr, "use_all_regions", FALSE);
245
246         WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_to_active", PADPERIOD, KM_PRESS, KM_SHIFT, 0);
247         WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_clear", PADPERIOD, KM_PRESS, KM_ALT, 0);
248
249         WM_keymap_verify_item(keymap, "VIEW3D_OT_fly", FKEY, KM_PRESS, KM_SHIFT, 0);
250
251         WM_keymap_verify_item(keymap, "VIEW3D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);
252         
253         WM_keymap_add_item(keymap, "VIEW3D_OT_rotate", MOUSEPAN, 0, 0, 0);
254         WM_keymap_add_item(keymap, "VIEW3D_OT_rotate", MOUSEROTATE, 0, 0, 0);
255         WM_keymap_add_item(keymap, "VIEW3D_OT_move", MOUSEPAN, 0, KM_SHIFT, 0);
256         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MOUSEZOOM, 0, 0, 0);
257         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MOUSEPAN, 0, KM_CTRL, 0);
258         
259         /*numpad +/-*/
260         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", PADPLUSKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
261         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", PADMINUS, KM_PRESS, 0, 0)->ptr, "delta", -1);
262
263         /*ctrl +/-*/
264         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", EQUALKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", 1);
265         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MINUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", -1);
266         
267         /*wheel mouse forward/back*/
268         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELINMOUSE, KM_PRESS, 0, 0)->ptr, "delta", 1);
269         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELOUTMOUSE, KM_PRESS, 0, 0)->ptr, "delta", -1);
270
271         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_camera_1_to_1", PADENTER, KM_PRESS, KM_SHIFT, 0);
272
273         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_camera", HOMEKEY, KM_PRESS, 0, 0); /* only with camera view */
274
275         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_cursor", HOMEKEY, KM_PRESS, KM_ALT, 0);
276
277         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
278         RNA_boolean_set(kmi->ptr, "center", FALSE); /* only without camera view */
279         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, KM_CTRL, 0);
280         RNA_boolean_set(kmi->ptr, "use_all_regions", TRUE);
281         RNA_boolean_set(kmi->ptr, "center", FALSE); /* only without camera view */
282         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0);
283         RNA_boolean_set(kmi->ptr, "center", TRUE);
284
285         /* numpad view hotkeys*/
286         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA);
287         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT);
288         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD2, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPDOWN);
289         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT);
290         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD4, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
291         WM_keymap_add_item(keymap, "VIEW3D_OT_view_persportho", PAD5, KM_PRESS, 0, 0);
292         
293         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD6, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
294         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP);
295         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD8, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPUP);
296         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BACK);
297         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_LEFT);
298         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BOTTOM);
299         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD2, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANDOWN);
300         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD4, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANLEFT);
301         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD6, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANRIGHT);
302         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANUP);
303         
304         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANRIGHT);
305         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANLEFT);
306         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_PANUP);
307         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_PANDOWN);
308
309         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);
310         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);
311         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);
312         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);
313         
314         /* active aligned, replaces '*' key in 2.4x */
315         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT, 0);
316         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_FRONT);
317         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
318         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT, 0);
319         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_RIGHT);
320         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
321         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT, 0);
322         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_TOP);
323         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
324         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
325         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BACK);
326         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
327         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
328         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_LEFT);
329         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
330         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
331         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BOTTOM);
332         RNA_boolean_set(kmi->ptr, "align_active", TRUE);
333
334         WM_keymap_add_item(keymap, "VIEW3D_OT_localview", PADSLASHKEY, KM_PRESS, 0, 0);
335         
336         /* layers, shift + alt are properties set in invoke() */
337         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", ACCENTGRAVEKEY, KM_PRESS, 0, 0)->ptr, "nr", 0);
338         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", ONEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 1);
339         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", TWOKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 2);
340         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", THREEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 3);
341         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", FOURKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 4);
342         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", FIVEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 5);
343         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", SIXKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 6);
344         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", SEVENKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 7);
345         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", EIGHTKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 8);
346         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", NINEKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 9);
347         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_layers", ZEROKEY, KM_PRESS, KM_ANY, 0)->ptr, "nr", 10);
348         
349         /* drawtype */
350
351         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, 0, 0);
352         RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
353         RNA_string_set(kmi->ptr, "value_1", "SOLID");
354         RNA_string_set(kmi->ptr, "value_2", "WIREFRAME");
355
356         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, KM_ALT, 0);
357         RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
358         RNA_string_set(kmi->ptr, "value_1", "SOLID");
359         RNA_string_set(kmi->ptr, "value_2", "TEXTURED");
360
361         /* selection*/
362         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
363         RNA_boolean_set(kmi->ptr, "extend", FALSE);
364         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
365         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
366         RNA_boolean_set(kmi->ptr, "center", FALSE);
367         RNA_boolean_set(kmi->ptr, "object", FALSE);
368         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
369         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
370         RNA_boolean_set(kmi->ptr, "extend", FALSE);
371         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
372         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
373         RNA_boolean_set(kmi->ptr, "center", FALSE);
374         RNA_boolean_set(kmi->ptr, "object", FALSE);
375         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
376         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
377         RNA_boolean_set(kmi->ptr, "extend", FALSE);
378         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
379         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
380         RNA_boolean_set(kmi->ptr, "center", TRUE);
381         RNA_boolean_set(kmi->ptr, "object", TRUE); /* use Ctrl+Select for 2 purposes */
382         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
383         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
384         RNA_boolean_set(kmi->ptr, "extend", FALSE);
385         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
386         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
387         RNA_boolean_set(kmi->ptr, "center", FALSE);
388         RNA_boolean_set(kmi->ptr, "object", FALSE);
389         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
390
391         /* selection key-combinations */
392         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
393         RNA_boolean_set(kmi->ptr, "extend", TRUE);
394         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
395         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
396         RNA_boolean_set(kmi->ptr, "center", TRUE);
397         RNA_boolean_set(kmi->ptr, "object", FALSE);
398         RNA_boolean_set(kmi->ptr, "enumerate", FALSE);
399         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0);
400         RNA_boolean_set(kmi->ptr, "extend", FALSE);
401         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
402         RNA_boolean_set(kmi->ptr, "toggle", FALSE);
403         RNA_boolean_set(kmi->ptr, "center", TRUE);
404         RNA_boolean_set(kmi->ptr, "object", FALSE);
405         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
406         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0);
407         RNA_boolean_set(kmi->ptr, "extend", FALSE);
408         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
409         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
410         RNA_boolean_set(kmi->ptr, "center", FALSE);
411         RNA_boolean_set(kmi->ptr, "object", FALSE);
412         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
413         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL | KM_ALT, 0);
414         RNA_boolean_set(kmi->ptr, "extend", FALSE);
415         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
416         RNA_boolean_set(kmi->ptr, "toggle", TRUE);
417         RNA_boolean_set(kmi->ptr, "center", TRUE);
418         RNA_boolean_set(kmi->ptr, "object", FALSE);
419         RNA_boolean_set(kmi->ptr, "enumerate", TRUE);
420
421         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
422         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
423         RNA_boolean_set(kmi->ptr, "deselect", FALSE);
424         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
425         RNA_boolean_set(kmi->ptr, "deselect", TRUE);
426         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
427         
428         WM_keymap_add_item(keymap, "VIEW3D_OT_clip_border", BKEY, KM_PRESS, KM_ALT, 0);
429         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
430
431         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_SHIFT, 0);
432         RNA_boolean_set(kmi->ptr, "camera_only", TRUE);
433         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_CTRL, 0);
434         RNA_boolean_set(kmi->ptr, "camera_only", FALSE);
435
436         WM_keymap_add_item(keymap, "VIEW3D_OT_clear_render_border", BKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
437         
438         WM_keymap_add_item(keymap, "VIEW3D_OT_camera_to_view", PAD0, KM_PRESS, KM_ALT | KM_CTRL, 0);
439         WM_keymap_add_item(keymap, "VIEW3D_OT_object_as_camera", PAD0, KM_PRESS, KM_CTRL, 0);
440         
441         WM_keymap_add_menu(keymap, "VIEW3D_MT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
442         
443 #ifdef __APPLE__
444         WM_keymap_add_item(keymap, "VIEW3D_OT_copybuffer", CKEY, KM_PRESS, KM_OSKEY, 0);
445         WM_keymap_add_item(keymap, "VIEW3D_OT_pastebuffer", VKEY, KM_PRESS, KM_OSKEY, 0);
446 #endif
447         WM_keymap_add_item(keymap, "VIEW3D_OT_copybuffer", CKEY, KM_PRESS, KM_CTRL, 0);
448         WM_keymap_add_item(keymap, "VIEW3D_OT_pastebuffer", VKEY, KM_PRESS, KM_CTRL, 0);
449         
450         /* context ops */
451         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0);
452         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
453         RNA_string_set(kmi->ptr, "value", "BOUNDING_BOX_CENTER");
454
455         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 */
456         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
457         RNA_string_set(kmi->ptr, "value", "MEDIAN_POINT");
458
459         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", COMMAKEY, KM_PRESS, KM_ALT, 0); /* new in 2.5 */
460         RNA_string_set(kmi->ptr, "data_path", "space_data.use_pivot_point_align");
461
462         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SPACEKEY, KM_PRESS, KM_CTRL, 0); /* new in 2.5 */
463         RNA_string_set(kmi->ptr, "data_path", "space_data.show_manipulator");
464
465         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0);
466         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
467         RNA_string_set(kmi->ptr, "value", "CURSOR");
468
469         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_CTRL, 0);
470         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
471         RNA_string_set(kmi->ptr, "value", "INDIVIDUAL_ORIGINS");
472
473         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_ALT, 0);
474         RNA_string_set(kmi->ptr, "data_path", "space_data.pivot_point");
475         RNA_string_set(kmi->ptr, "value", "ACTIVE_ELEMENT");
476
477         transform_keymap_for_space(keyconf, keymap, SPACE_VIEW3D);
478
479         fly_modal_keymap(keyconf);
480         viewrotate_modal_keymap(keyconf);
481         viewmove_modal_keymap(keyconf);
482         viewzoom_modal_keymap(keyconf);
483         viewdolly_modal_keymap(keyconf);
484 }
485