Merge branch 'master' into blender2.8
[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_group_types.h"
38 #include "DNA_scene_types.h"
39 #include "DNA_screen_types.h"
40 #include "DNA_space_types.h"
41 #include "DNA_view3d_types.h"
42
43 #include "BLI_blenlib.h"
44 #include "BLI_utildefines.h"
45
46 #include "BKE_appdir.h"
47 #include "BKE_blender_copybuffer.h"
48 #include "BKE_collection.h"
49 #include "BKE_context.h"
50 #include "BKE_main.h"
51 #include "BKE_report.h"
52
53 #include "RNA_access.h"
54 #include "RNA_define.h"
55
56 #include "WM_api.h"
57 #include "WM_types.h"
58
59 #include "ED_screen.h"
60 #include "ED_transform.h"
61
62 #include "view3d_intern.h"
63
64 #ifdef WIN32
65 #  include "BLI_math_base.h" /* M_PI */
66 #endif
67
68 /* ************************** copy paste ***************************** */
69
70 static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
71 {
72         Main *bmain = CTX_data_main(C);
73         char str[FILE_MAX];
74
75         BKE_copybuffer_begin(bmain);
76
77         /* context, selection, could be generalized */
78         CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
79         {
80                 BKE_copybuffer_tag_ID(&ob->id);
81         }
82         CTX_DATA_END;
83
84         for (Collection *collection = bmain->collection.first; collection; collection = collection->id.next) {
85                 for (CollectionObject *cob = collection->gobject.first; cob; cob = cob->next) {
86                         Object *object = cob->ob;
87
88                         if (object && (object->id.tag & LIB_TAG_DOIT)) {
89                                 BKE_copybuffer_tag_ID(&collection->id);
90                                 /* don't expand out to all other objects */
91                                 collection->id.tag &= ~LIB_TAG_NEED_EXPAND;
92                                 break;
93                         }
94                 }
95         }
96
97         BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer.blend");
98         BKE_copybuffer_save(bmain, str, op->reports);
99
100         BKE_report(op->reports, RPT_INFO, "Copied selected objects to buffer");
101
102         return OPERATOR_FINISHED;
103 }
104
105 static void VIEW3D_OT_copybuffer(wmOperatorType *ot)
106 {
107
108         /* identifiers */
109         ot->name = "Copy Selection to Buffer";
110         ot->idname = "VIEW3D_OT_copybuffer";
111         ot->description = "Selected objects are saved in a temp file";
112
113         /* api callbacks */
114         ot->exec = view3d_copybuffer_exec;
115         ot->poll = ED_operator_scene;
116 }
117
118 static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
119 {
120         char str[FILE_MAX];
121         short flag = 0;
122
123         if (RNA_boolean_get(op->ptr, "autoselect"))
124                 flag |= FILE_AUTOSELECT;
125         if (RNA_boolean_get(op->ptr, "active_collection"))
126                 flag |= FILE_ACTIVE_COLLECTION;
127
128         BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer.blend");
129         if (BKE_copybuffer_paste(C, str, flag, op->reports)) {
130                 WM_event_add_notifier(C, NC_WINDOW, NULL);
131
132                 BKE_report(op->reports, RPT_INFO, "Objects pasted from buffer");
133
134                 return OPERATOR_FINISHED;
135         }
136
137         BKE_report(op->reports, RPT_INFO, "No buffer to paste from");
138
139         return OPERATOR_CANCELLED;
140 }
141
142 static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
143 {
144
145         /* identifiers */
146         ot->name = "Paste Selection from Buffer";
147         ot->idname = "VIEW3D_OT_pastebuffer";
148         ot->description = "Contents of copy buffer gets pasted";
149
150         /* api callbacks */
151         ot->exec = view3d_pastebuffer_exec;
152         ot->poll = ED_operator_scene_editable;
153
154         /* flags */
155         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
156
157         RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
158         RNA_def_boolean(ot->srna, "active_collection", true, "Active Collection", "Put pasted objects on the active collection");
159 }
160
161 /* ************************** registration **********************************/
162
163 void view3d_operatortypes(void)
164 {
165         WM_operatortype_append(VIEW3D_OT_rotate);
166         WM_operatortype_append(VIEW3D_OT_move);
167         WM_operatortype_append(VIEW3D_OT_zoom);
168         WM_operatortype_append(VIEW3D_OT_zoom_camera_1_to_1);
169         WM_operatortype_append(VIEW3D_OT_dolly);
170 #ifdef WITH_INPUT_NDOF
171         WM_operatortype_append(VIEW3D_OT_ndof_orbit_zoom);
172         WM_operatortype_append(VIEW3D_OT_ndof_orbit);
173         WM_operatortype_append(VIEW3D_OT_ndof_pan);
174         WM_operatortype_append(VIEW3D_OT_ndof_all);
175 #endif /* WITH_INPUT_NDOF */
176         WM_operatortype_append(VIEW3D_OT_view_all);
177         WM_operatortype_append(VIEW3D_OT_viewnumpad);
178         WM_operatortype_append(VIEW3D_OT_view_orbit);
179         WM_operatortype_append(VIEW3D_OT_view_roll);
180         WM_operatortype_append(VIEW3D_OT_view_pan);
181         WM_operatortype_append(VIEW3D_OT_view_persportho);
182         WM_operatortype_append(VIEW3D_OT_background_image_add);
183         WM_operatortype_append(VIEW3D_OT_background_image_remove);
184         WM_operatortype_append(VIEW3D_OT_view_selected);
185         WM_operatortype_append(VIEW3D_OT_view_lock_clear);
186         WM_operatortype_append(VIEW3D_OT_view_lock_to_active);
187         WM_operatortype_append(VIEW3D_OT_view_center_cursor);
188         WM_operatortype_append(VIEW3D_OT_view_center_pick);
189         WM_operatortype_append(VIEW3D_OT_view_center_camera);
190         WM_operatortype_append(VIEW3D_OT_view_center_lock);
191         WM_operatortype_append(VIEW3D_OT_select);
192         WM_operatortype_append(VIEW3D_OT_select_border);
193         WM_operatortype_append(VIEW3D_OT_clip_border);
194         WM_operatortype_append(VIEW3D_OT_select_circle);
195         WM_operatortype_append(VIEW3D_OT_smoothview);
196         WM_operatortype_append(VIEW3D_OT_render_border);
197         WM_operatortype_append(VIEW3D_OT_clear_render_border);
198         WM_operatortype_append(VIEW3D_OT_zoom_border);
199         WM_operatortype_append(VIEW3D_OT_cursor3d);
200         WM_operatortype_append(VIEW3D_OT_select_lasso);
201         WM_operatortype_append(VIEW3D_OT_select_menu);
202         WM_operatortype_append(VIEW3D_OT_camera_to_view);
203         WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
204         WM_operatortype_append(VIEW3D_OT_object_as_camera);
205         WM_operatortype_append(VIEW3D_OT_fly);
206         WM_operatortype_append(VIEW3D_OT_walk);
207         WM_operatortype_append(VIEW3D_OT_navigate);
208         WM_operatortype_append(VIEW3D_OT_ruler);
209         WM_operatortype_append(VIEW3D_OT_layers);
210         WM_operatortype_append(VIEW3D_OT_copybuffer);
211         WM_operatortype_append(VIEW3D_OT_pastebuffer);
212
213         WM_operatortype_append(VIEW3D_OT_properties);
214         WM_operatortype_append(VIEW3D_OT_toolshelf);
215
216         WM_operatortype_append(VIEW3D_OT_snap_selected_to_grid);
217         WM_operatortype_append(VIEW3D_OT_snap_selected_to_cursor);
218         WM_operatortype_append(VIEW3D_OT_snap_selected_to_active);
219         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_grid);
220         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_center);
221         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_selected);
222         WM_operatortype_append(VIEW3D_OT_snap_cursor_to_active);
223
224         WM_operatortype_append(VIEW3D_OT_toggle_render);
225         WM_operatortype_append(VIEW3D_OT_toggle_xray_draw_option);
226
227         WM_operatortype_append(VIEW3D_OT_ruler_add);
228
229         transform_operatortypes();
230 }
231
232 void view3d_keymap(wmKeyConfig *keyconf)
233 {
234         wmKeyMap *keymap;
235         wmKeyMapItem *kmi;
236
237         keymap = WM_keymap_find(keyconf, "3D View Generic", SPACE_VIEW3D, 0);
238
239         WM_keymap_add_item(keymap, "VIEW3D_OT_properties", NKEY, KM_PRESS, 0, 0);
240         WM_keymap_add_item(keymap, "VIEW3D_OT_toolshelf", TKEY, KM_PRESS, 0, 0);
241
242         /* only for region 3D window */
243         keymap = WM_keymap_find(keyconf, "3D View", SPACE_VIEW3D, 0);
244
245         WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_CLICK, 0, 0);
246
247         WM_keymap_verify_item(keymap, "VIEW3D_OT_rotate", MIDDLEMOUSE, KM_PRESS, 0, 0);
248         WM_keymap_verify_item(keymap, "VIEW3D_OT_move", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
249         WM_keymap_verify_item(keymap, "VIEW3D_OT_zoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
250         WM_keymap_verify_item(keymap, "VIEW3D_OT_dolly", MIDDLEMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0);
251         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, KM_CTRL, 0);
252         RNA_boolean_set(kmi->ptr, "use_all_regions", true);
253         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
254         RNA_boolean_set(kmi->ptr, "use_all_regions", false);
255
256         WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_to_active", PADPERIOD, KM_PRESS, KM_SHIFT, 0);
257         WM_keymap_verify_item(keymap, "VIEW3D_OT_view_lock_clear", PADPERIOD, KM_PRESS, KM_ALT, 0);
258
259         WM_keymap_verify_item(keymap, "VIEW3D_OT_navigate", FKEY, KM_PRESS, KM_SHIFT, 0);
260
261         WM_keymap_verify_item(keymap, "VIEW3D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);
262
263         WM_keymap_add_item(keymap, "VIEW3D_OT_rotate", MOUSEPAN, 0, 0, 0);
264         WM_keymap_add_item(keymap, "VIEW3D_OT_rotate", MOUSEROTATE, 0, 0, 0);
265         WM_keymap_add_item(keymap, "VIEW3D_OT_move", MOUSEPAN, 0, KM_SHIFT, 0);
266         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MOUSEZOOM, 0, 0, 0);
267         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MOUSEPAN, 0, KM_CTRL, 0);
268
269         /*numpad +/-*/
270         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", PADPLUSKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
271         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", PADMINUS, KM_PRESS, 0, 0)->ptr, "delta", -1);
272         /*ctrl +/-*/
273         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", EQUALKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", 1);
274         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", MINUSKEY, KM_PRESS, KM_CTRL, 0)->ptr, "delta", -1);
275
276         /*wheel mouse forward/back*/
277         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELINMOUSE, KM_PRESS, 0, 0)->ptr, "delta", 1);
278         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_zoom", WHEELOUTMOUSE, KM_PRESS, 0, 0)->ptr, "delta", -1);
279
280         /* ... and for dolly */
281         /*numpad +/-*/
282         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_dolly", PADPLUSKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "delta", 1);
283         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_dolly", PADMINUS, KM_PRESS, KM_SHIFT, 0)->ptr, "delta", -1);
284         /*ctrl +/-*/
285         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_dolly", EQUALKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, "delta", 1);
286         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_dolly", MINUSKEY, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, "delta", -1);
287
288         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_camera_1_to_1", PADENTER, KM_PRESS, KM_SHIFT, 0);
289
290         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_camera", HOMEKEY, KM_PRESS, 0, 0); /* only with camera view */
291         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_lock", HOMEKEY, KM_PRESS, 0, 0); /* only with lock view */
292
293         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_cursor", HOMEKEY, KM_PRESS, KM_ALT, 0);
294         WM_keymap_add_item(keymap, "VIEW3D_OT_view_center_pick", FKEY, KM_PRESS, KM_ALT, 0);
295
296         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
297         RNA_boolean_set(kmi->ptr, "center", false); /* only without camera view */
298         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", HOMEKEY, KM_PRESS, KM_CTRL, 0);
299         RNA_boolean_set(kmi->ptr, "use_all_regions", true);
300         RNA_boolean_set(kmi->ptr, "center", false); /* only without camera view */
301         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_all", CKEY, KM_PRESS, KM_SHIFT, 0);
302         RNA_boolean_set(kmi->ptr, "center", true);
303
304         /* numpad view hotkeys*/
305         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_CAMERA);
306         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT);
307         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD2, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPDOWN);
308         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT);
309         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD4, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
310         WM_keymap_add_item(keymap, "VIEW3D_OT_view_persportho", PAD5, KM_PRESS, 0, 0);
311
312         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD6, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
313         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP);
314         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD8, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPUP);
315         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BACK);
316         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_LEFT);
317         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_CTRL, 0)->ptr, "type", RV3D_VIEW_BOTTOM);
318         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD2, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANDOWN);
319         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD4, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANLEFT);
320         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD6, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANRIGHT);
321         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANUP);
322         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_roll", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
323         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_roll", PAD6, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
324         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_orbit", PAD9, KM_PRESS, 0, 0);
325         RNA_enum_set(kmi->ptr, "type", V3D_VIEW_STEPRIGHT);
326         RNA_float_set(kmi->ptr, "angle", (float)M_PI);
327
328         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANRIGHT);
329         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0)->ptr, "type", V3D_VIEW_PANLEFT);
330         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_PANUP);
331         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_pan", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", V3D_VIEW_PANDOWN);
332
333         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);
334         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);
335         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);
336         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);
337
338         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_roll", WHEELUPMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
339         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_roll", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL | KM_SHIFT, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
340
341         /* active aligned, replaces '*' key in 2.4x */
342         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT, 0);
343         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_FRONT);
344         RNA_boolean_set(kmi->ptr, "align_active", true);
345         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT, 0);
346         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_RIGHT);
347         RNA_boolean_set(kmi->ptr, "align_active", true);
348         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT, 0);
349         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_TOP);
350         RNA_boolean_set(kmi->ptr, "align_active", true);
351         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
352         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BACK);
353         RNA_boolean_set(kmi->ptr, "align_active", true);
354         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
355         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_LEFT);
356         RNA_boolean_set(kmi->ptr, "align_active", true);
357         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
358         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BOTTOM);
359         RNA_boolean_set(kmi->ptr, "align_active", true);
360
361 #ifdef WITH_INPUT_NDOF
362         /* note: positioned here so keymaps show keyboard keys if assigned */
363         /* 3D mouse */
364         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_orbit_zoom", NDOF_MOTION, 0, 0, 0);
365         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_orbit", NDOF_MOTION, 0, KM_CTRL, 0);
366         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_pan", NDOF_MOTION, 0, KM_SHIFT, 0);
367         WM_keymap_add_item(keymap, "VIEW3D_OT_ndof_all", NDOF_MOTION, 0, KM_CTRL | KM_SHIFT, 0);
368         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_view_selected", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
369         RNA_boolean_set(kmi->ptr, "use_all_regions", false);
370         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_roll", NDOF_BUTTON_ROLL_CCW, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPLEFT);
371         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_view_roll", NDOF_BUTTON_ROLL_CCW, KM_PRESS, 0, 0)->ptr, "type", V3D_VIEW_STEPRIGHT);
372
373         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_FRONT);
374         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BACK, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BACK);
375         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_LEFT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_LEFT);
376         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_RIGHT);
377         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_TOP);
378         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_BOTTOM, KM_PRESS, 0, 0)->ptr, "type", RV3D_VIEW_BOTTOM);
379
380         /* 3D mouse align */
381         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_FRONT, KM_PRESS, KM_SHIFT, 0);
382         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_FRONT);
383         RNA_boolean_set(kmi->ptr, "align_active", true);
384         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_RIGHT, KM_PRESS, KM_SHIFT, 0);
385         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_RIGHT);
386         RNA_boolean_set(kmi->ptr, "align_active", true);
387         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", NDOF_BUTTON_TOP, KM_PRESS, KM_SHIFT, 0);
388         RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_TOP);
389         RNA_boolean_set(kmi->ptr, "align_active", true);
390 #endif /* WITH_INPUT_NDOF */
391
392         /* drawtype */
393         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, KM_ALT, 0);
394         RNA_string_set(kmi->ptr, "data_path", "space_data.shading.type");
395         RNA_string_set(kmi->ptr, "value_1", "SOLID");
396         RNA_string_set(kmi->ptr, "value_2", "TEXTURED");
397
398         WM_keymap_add_item(keymap, "VIEW3D_OT_toggle_render", ZKEY, KM_PRESS, KM_SHIFT, 0);
399         WM_keymap_add_item(keymap, "VIEW3D_OT_toggle_xray_draw_option", ZKEY, KM_PRESS, 0, 0);
400
401         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", ZKEY, KM_PRESS, 0, 0);
402         RNA_string_set(kmi->ptr, "data_path", "space_data.use_occlude_geometry");
403
404         /* selection*/
405         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
406         RNA_boolean_set(kmi->ptr, "extend", false);
407         RNA_boolean_set(kmi->ptr, "deselect", false);
408         RNA_boolean_set(kmi->ptr, "toggle", false);
409         RNA_boolean_set(kmi->ptr, "center", false);
410         RNA_boolean_set(kmi->ptr, "object", false);
411         RNA_boolean_set(kmi->ptr, "enumerate", false);
412         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
413         RNA_boolean_set(kmi->ptr, "extend", false);
414         RNA_boolean_set(kmi->ptr, "deselect", false);
415         RNA_boolean_set(kmi->ptr, "toggle", true);
416         RNA_boolean_set(kmi->ptr, "center", false);
417         RNA_boolean_set(kmi->ptr, "object", false);
418         RNA_boolean_set(kmi->ptr, "enumerate", false);
419         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL, 0);
420         RNA_boolean_set(kmi->ptr, "extend", false);
421         RNA_boolean_set(kmi->ptr, "deselect", false);
422         RNA_boolean_set(kmi->ptr, "toggle", false);
423         RNA_boolean_set(kmi->ptr, "center", true);
424         RNA_boolean_set(kmi->ptr, "object", true); /* use Ctrl+Select for 2 purposes */
425         RNA_boolean_set(kmi->ptr, "enumerate", false);
426         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_ALT, 0);
427         RNA_boolean_set(kmi->ptr, "extend", false);
428         RNA_boolean_set(kmi->ptr, "deselect", false);
429         RNA_boolean_set(kmi->ptr, "toggle", false);
430         RNA_boolean_set(kmi->ptr, "center", false);
431         RNA_boolean_set(kmi->ptr, "object", false);
432         RNA_boolean_set(kmi->ptr, "enumerate", true);
433
434         /* selection key-combinations */
435         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
436         RNA_boolean_set(kmi->ptr, "extend", true);
437         RNA_boolean_set(kmi->ptr, "deselect", false);
438         RNA_boolean_set(kmi->ptr, "toggle", true);
439         RNA_boolean_set(kmi->ptr, "center", true);
440         RNA_boolean_set(kmi->ptr, "object", false);
441         RNA_boolean_set(kmi->ptr, "enumerate", false);
442         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_CTRL | KM_ALT, 0);
443         RNA_boolean_set(kmi->ptr, "extend", false);
444         RNA_boolean_set(kmi->ptr, "deselect", false);
445         RNA_boolean_set(kmi->ptr, "toggle", false);
446         RNA_boolean_set(kmi->ptr, "center", true);
447         RNA_boolean_set(kmi->ptr, "object", false);
448         RNA_boolean_set(kmi->ptr, "enumerate", true);
449         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_ALT, 0);
450         RNA_boolean_set(kmi->ptr, "extend", false);
451         RNA_boolean_set(kmi->ptr, "deselect", false);
452         RNA_boolean_set(kmi->ptr, "toggle", true);
453         RNA_boolean_set(kmi->ptr, "center", false);
454         RNA_boolean_set(kmi->ptr, "object", false);
455         RNA_boolean_set(kmi->ptr, "enumerate", true);
456         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT | KM_CTRL | KM_ALT, 0);
457         RNA_boolean_set(kmi->ptr, "extend", false);
458         RNA_boolean_set(kmi->ptr, "deselect", false);
459         RNA_boolean_set(kmi->ptr, "toggle", true);
460         RNA_boolean_set(kmi->ptr, "center", true);
461         RNA_boolean_set(kmi->ptr, "object", false);
462         RNA_boolean_set(kmi->ptr, "enumerate", true);
463
464         WM_keymap_add_item(keymap, "VIEW3D_OT_select_border", BKEY, KM_PRESS, 0, 0);
465         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_CTRL, 0);
466         RNA_boolean_set(kmi->ptr, "deselect", false);
467         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_select_lasso", EVT_TWEAK_A, KM_ANY, KM_SHIFT | KM_CTRL, 0);
468         RNA_boolean_set(kmi->ptr, "deselect", true);
469         WM_keymap_add_item(keymap, "VIEW3D_OT_select_circle", CKEY, KM_PRESS, 0, 0);
470
471         WM_keymap_add_item(keymap, "VIEW3D_OT_clip_border", BKEY, KM_PRESS, KM_ALT, 0);
472         WM_keymap_add_item(keymap, "VIEW3D_OT_zoom_border", BKEY, KM_PRESS, KM_SHIFT, 0);
473
474         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_SHIFT, 0);
475         RNA_boolean_set(kmi->ptr, "camera_only", true);
476         kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_CTRL, 0);
477         RNA_boolean_set(kmi->ptr, "camera_only", false);
478
479         WM_keymap_add_item(keymap, "VIEW3D_OT_clear_render_border", BKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
480
481         WM_keymap_add_item(keymap, "VIEW3D_OT_camera_to_view", PAD0, KM_PRESS, KM_ALT | KM_CTRL, 0);
482         WM_keymap_add_item(keymap, "VIEW3D_OT_object_as_camera", PAD0, KM_PRESS, KM_CTRL, 0);
483
484         WM_keymap_add_menu(keymap, "VIEW3D_MT_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
485
486 #ifdef __APPLE__
487         WM_keymap_add_item(keymap, "VIEW3D_OT_copybuffer", CKEY, KM_PRESS, KM_OSKEY, 0);
488         WM_keymap_add_item(keymap, "VIEW3D_OT_pastebuffer", VKEY, KM_PRESS, KM_OSKEY, 0);
489 #endif
490         WM_keymap_add_item(keymap, "VIEW3D_OT_copybuffer", CKEY, KM_PRESS, KM_CTRL, 0);
491         WM_keymap_add_item(keymap, "VIEW3D_OT_pastebuffer", VKEY, KM_PRESS, KM_CTRL, 0);
492
493         /* context ops */
494         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, 0, 0);
495         RNA_string_set(kmi->ptr, "data_path", "tool_settings.transform_pivot_point");
496         RNA_string_set(kmi->ptr, "value", "BOUNDING_BOX_CENTER");
497
498         /* 2.4x allowed Comma+Shift too, rather not use both */
499         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", COMMAKEY, KM_PRESS, KM_CTRL, 0);
500         RNA_string_set(kmi->ptr, "data_path", "tool_settings.transform_pivot_point");
501         RNA_string_set(kmi->ptr, "value", "MEDIAN_POINT");
502
503         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", COMMAKEY, KM_PRESS, KM_ALT, 0); /* new in 2.5 */
504         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_transform_pivot_point_align");
505
506         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, 0, 0);
507         RNA_string_set(kmi->ptr, "data_path", "tool_settings.transform_pivot_point");
508         RNA_string_set(kmi->ptr, "value", "CURSOR");
509
510         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_CTRL, 0);
511         RNA_string_set(kmi->ptr, "data_path", "tool_settings.transform_pivot_point");
512         RNA_string_set(kmi->ptr, "value", "INDIVIDUAL_ORIGINS");
513
514         kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", PERIODKEY, KM_PRESS, KM_ALT, 0);
515         RNA_string_set(kmi->ptr, "data_path", "tool_settings.transform_pivot_point");
516         RNA_string_set(kmi->ptr, "value", "ACTIVE_ELEMENT");
517
518         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", SPACEKEY, KM_PRESS, KM_CTRL, 0); /* new in 2.5 */
519         RNA_string_set(kmi->ptr, "data_path", "space_data.show_manipulator");
520
521         transform_keymap_for_space(keyconf, keymap, SPACE_VIEW3D);
522
523         fly_modal_keymap(keyconf);
524         walk_modal_keymap(keyconf);
525         viewrotate_modal_keymap(keyconf);
526         viewmove_modal_keymap(keyconf);
527         viewzoom_modal_keymap(keyconf);
528         viewdolly_modal_keymap(keyconf);
529 }
530