RNA: forgot to rename some values in the keymaps in last commit.
[blender.git] / source / blender / editors / space_view3d / view3d_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 "BIF_transform.h"
50
51 #include "RNA_access.h"
52 #include "RNA_define.h"
53
54 #include "WM_api.h"
55 #include "WM_types.h"
56
57 #include "ED_screen.h"
58
59 #include "view3d_intern.h"
60
61
62 /* ************************** registration **********************************/
63
64 void view3d_operatortypes(void)
65 {
66         WM_operatortype_append(VIEW3D_OT_viewrotate);
67         WM_operatortype_append(VIEW3D_OT_viewmove);
68         WM_operatortype_append(VIEW3D_OT_viewzoom);
69         WM_operatortype_append(VIEW3D_OT_viewhome);
70         WM_operatortype_append(VIEW3D_OT_viewnumpad);
71         WM_operatortype_append(VIEW3D_OT_viewcenter);
72         WM_operatortype_append(VIEW3D_OT_select);
73         WM_operatortype_append(VIEW3D_OT_borderselect);
74         WM_operatortype_append(VIEW3D_OT_clipping);
75         WM_operatortype_append(VIEW3D_OT_circle_select);
76         WM_operatortype_append(VIEW3D_OT_smoothview);
77         WM_operatortype_append(VIEW3D_OT_render_border);
78         WM_operatortype_append(VIEW3D_OT_border_zoom);
79         WM_operatortype_append(VIEW3D_OT_cursor3d);
80         WM_operatortype_append(VIEW3D_OT_lasso_select);
81         WM_operatortype_append(VIEW3D_OT_setcameratoview);
82         WM_operatortype_append(VIEW3D_OT_drawtype);
83         WM_operatortype_append(VIEW3D_OT_vpaint_toggle);
84         WM_operatortype_append(VIEW3D_OT_wpaint_toggle);
85         WM_operatortype_append(VIEW3D_OT_vpaint);
86         WM_operatortype_append(VIEW3D_OT_wpaint);
87         
88         transform_operatortypes();
89 }
90
91 void view3d_keymap(wmWindowManager *wm)
92 {
93         ListBase *keymap= WM_keymap_listbase(wm, "View3D", SPACE_VIEW3D, 0);
94         wmKeymapItem *km;
95         
96         /* paint poll checks mode */
97         WM_keymap_verify_item(keymap, "VIEW3D_OT_vpaint", LEFTMOUSE, KM_PRESS, 0, 0);
98         WM_keymap_verify_item(keymap, "VIEW3D_OT_wpaint", LEFTMOUSE, KM_PRESS, 0, 0);
99
100         WM_keymap_verify_item(keymap, "SCULPT_OT_brush_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
101         
102         WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0);
103         
104         WM_keymap_verify_item(keymap, "VIEW3D_OT_viewrotate", MIDDLEMOUSE, KM_PRESS, 0, 0);
105         WM_keymap_verify_item(keymap, "VIEW3D_OT_viewmove", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
106         WM_keymap_verify_item(keymap, "VIEW3D_OT_viewzoom", MIDDLEMOUSE, KM_PRESS, KM_CTRL, 0);
107         WM_keymap_verify_item(keymap, "VIEW3D_OT_viewcenter", PADPERIOD, KM_PRESS, 0, 0);
108         
109         WM_keymap_verify_item(keymap, "VIEW3D_OT_smoothview", TIMER1, KM_ANY, KM_ANY, 0);
110         
111         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewzoom", PADPLUSKEY, KM_PRESS, 0, 0)->ptr, "delta", 1);
112         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewzoom", PADMINUS, KM_PRESS, 0, 0)->ptr, "delta", -1);
113         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewzoom", WHEELINMOUSE, KM_PRESS, 0, 0)->ptr, "delta", 1);
114         RNA_int_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewzoom", WHEELOUTMOUSE, KM_PRESS, 0, 0)->ptr, "delta", -1);
115
116         RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewhome", HOMEKEY, KM_PRESS, 0, 0)->ptr, "center", 0);
117         RNA_boolean_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewhome", CKEY, KM_PRESS, KM_SHIFT, 0)->ptr, "center", 1);
118
119         /* numpad view hotkeys*/
120         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD0, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_CAMERA);
121         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_FRONT);
122         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD2, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_STEPDOWN);
123         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_RIGHT);
124         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD4, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_STEPLEFT);
125         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD5, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_PERSPORTHO);
126         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD6, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_STEPRIGHT);
127         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_TOP);
128         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD8, KM_PRESS, 0, 0)->ptr, "view", V3D_VIEW_STEPUP);
129         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD1, KM_PRESS, KM_CTRL, 0)->ptr, "view", V3D_VIEW_BACK);
130         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD3, KM_PRESS, KM_CTRL, 0)->ptr, "view", V3D_VIEW_LEFT);
131         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_CTRL, 0)->ptr, "view", V3D_VIEW_BOTTOM);
132         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD2, KM_PRESS, KM_CTRL, 0)->ptr, "view", V3D_VIEW_PANDOWN);
133         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD4, KM_PRESS, KM_CTRL, 0)->ptr, "view", V3D_VIEW_PANLEFT);
134         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD6, KM_PRESS, KM_CTRL, 0)->ptr, "view", V3D_VIEW_PANRIGHT);
135         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD8, KM_PRESS, KM_CTRL, 0)->ptr, "view", V3D_VIEW_PANUP);
136
137         /* drawtype */
138         km = WM_keymap_add_item(keymap, "VIEW3D_OT_drawtype", ZKEY, KM_PRESS, 0, 0);
139         RNA_int_set(km->ptr, "draw_type", OB_SOLID);
140         RNA_int_set(km->ptr, "draw┬░type_alternate", OB_WIRE);
141
142         km = WM_keymap_add_item(keymap, "VIEW3D_OT_drawtype", ZKEY, KM_PRESS, KM_ALT, 0);
143         RNA_int_set(km->ptr, "draw_type", OB_TEXTURE);
144         RNA_int_set(km->ptr, "draw_type_alternate", OB_SOLID);
145
146         km = WM_keymap_add_item(keymap, "VIEW3D_OT_drawtype", ZKEY, KM_PRESS, KM_SHIFT, 0);
147         RNA_int_set(km->ptr, "draw_type", OB_SHADED);
148         RNA_int_set(km->ptr, "draw_type_alternate", OB_WIRE);
149
150         /* selection*/
151         WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
152         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0)->ptr, "type", 1);
153         WM_keymap_add_item(keymap, "VIEW3D_OT_borderselect", BKEY, KM_PRESS, 0, 0);
154         WM_keymap_add_item(keymap, "VIEW3D_OT_lasso_select", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
155         RNA_enum_set(WM_keymap_add_item(keymap, "VIEW3D_OT_lasso_select", LEFTMOUSE, KM_PRESS, KM_SHIFT|KM_CTRL, 0)->ptr, "type", 1);
156         WM_keymap_add_item(keymap, "VIEW3D_OT_circle_select", CKEY, KM_PRESS, 0, 0);
157         
158         WM_keymap_add_item(keymap, "VIEW3D_OT_clipping", BKEY, KM_PRESS, KM_ALT, 0);
159         WM_keymap_add_item(keymap, "VIEW3D_OT_border_zoom", BKEY, KM_PRESS, KM_SHIFT, 0);
160         WM_keymap_add_item(keymap, "VIEW3D_OT_render_border", BKEY, KM_PRESS, KM_SHIFT, 0);
161         
162         WM_keymap_add_item(keymap, "VIEW3D_OT_set_camera_to_view", PAD0, KM_PRESS, KM_ALT|KM_CTRL, 0);
163         
164         WM_keymap_add_item(keymap, "VIEW3D_OT_vpaint_toggle", VKEY, KM_PRESS, 0, 0);
165         WM_keymap_add_item(keymap, "VIEW3D_OT_wpaint_toggle", TABKEY, KM_PRESS, KM_CTRL, 0);
166
167         /* TODO - this is just while we have no way to load a text datablock */
168         km = WM_keymap_add_item(keymap, "SCRIPT_OT_run_pyfile", PKEY, KM_PRESS, 0, 0);
169         RNA_string_set(km->ptr, "filename", "test.py");
170
171         transform_keymap_for_space(wm, keymap, SPACE_VIEW3D);
172
173         /* generates event, in end to make select work */
174         WM_keymap_verify_item(keymap, "WM_OT_tweak_gesture", SELECTMOUSE, KM_PRESS, 0, 0);
175
176 }
177