Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / physics / physics_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) 2009 Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Blender Foundation
22  *
23  * ***** END GPL LICENSE BLOCK *****
24  */
25
26 /** \file blender/editors/physics/physics_ops.c
27  *  \ingroup edphys
28  */
29
30 #include <stdlib.h>
31
32 #include "RNA_access.h"
33
34 #include "WM_api.h"
35 #include "WM_types.h"
36
37 #include "ED_physics.h"
38 #include "ED_object.h"
39
40 #include "physics_intern.h" // own include
41
42
43 /***************************** particles ***********************************/
44
45 static void operatortypes_particle(void)
46 {
47         WM_operatortype_append(PARTICLE_OT_select_all);
48         WM_operatortype_append(PARTICLE_OT_select_roots);
49         WM_operatortype_append(PARTICLE_OT_select_tips);
50         WM_operatortype_append(PARTICLE_OT_select_random);
51         WM_operatortype_append(PARTICLE_OT_select_linked);
52         WM_operatortype_append(PARTICLE_OT_select_less);
53         WM_operatortype_append(PARTICLE_OT_select_more);
54
55         WM_operatortype_append(PARTICLE_OT_hide);
56         WM_operatortype_append(PARTICLE_OT_reveal);
57
58         WM_operatortype_append(PARTICLE_OT_rekey);
59         WM_operatortype_append(PARTICLE_OT_subdivide);
60         WM_operatortype_append(PARTICLE_OT_remove_doubles);
61         WM_operatortype_append(PARTICLE_OT_weight_set);
62         WM_operatortype_append(PARTICLE_OT_delete);
63         WM_operatortype_append(PARTICLE_OT_mirror);
64
65         WM_operatortype_append(PARTICLE_OT_brush_edit);
66
67         WM_operatortype_append(PARTICLE_OT_shape_cut);
68
69         WM_operatortype_append(PARTICLE_OT_particle_edit_toggle);
70         WM_operatortype_append(PARTICLE_OT_edited_clear);
71
72         WM_operatortype_append(PARTICLE_OT_unify_length);
73
74
75         WM_operatortype_append(OBJECT_OT_particle_system_add);
76         WM_operatortype_append(OBJECT_OT_particle_system_remove);
77
78         WM_operatortype_append(PARTICLE_OT_new);
79         WM_operatortype_append(PARTICLE_OT_new_target);
80         WM_operatortype_append(PARTICLE_OT_target_remove);
81         WM_operatortype_append(PARTICLE_OT_target_move_up);
82         WM_operatortype_append(PARTICLE_OT_target_move_down);
83         WM_operatortype_append(PARTICLE_OT_connect_hair);
84         WM_operatortype_append(PARTICLE_OT_disconnect_hair);
85         WM_operatortype_append(PARTICLE_OT_copy_particle_systems);
86         WM_operatortype_append(PARTICLE_OT_duplicate_particle_system);
87
88         WM_operatortype_append(PARTICLE_OT_dupliob_copy);
89         WM_operatortype_append(PARTICLE_OT_dupliob_remove);
90         WM_operatortype_append(PARTICLE_OT_dupliob_move_up);
91         WM_operatortype_append(PARTICLE_OT_dupliob_move_down);
92
93         WM_operatortype_append(RIGIDBODY_OT_object_add);
94         WM_operatortype_append(RIGIDBODY_OT_object_remove);
95
96         WM_operatortype_append(RIGIDBODY_OT_objects_add);
97         WM_operatortype_append(RIGIDBODY_OT_objects_remove);
98
99         WM_operatortype_append(RIGIDBODY_OT_shape_change);
100         WM_operatortype_append(RIGIDBODY_OT_mass_calculate);
101
102         WM_operatortype_append(RIGIDBODY_OT_constraint_add);
103         WM_operatortype_append(RIGIDBODY_OT_constraint_remove);
104
105         WM_operatortype_append(RIGIDBODY_OT_world_add);
106         WM_operatortype_append(RIGIDBODY_OT_world_remove);
107 //      WM_operatortype_append(RIGIDBODY_OT_world_export);
108 }
109
110 static void keymap_particle(wmKeyConfig *keyconf)
111 {
112         wmKeyMapItem *kmi;
113         wmKeyMap *keymap;
114
115         keymap = WM_keymap_find(keyconf, "Particle", 0, 0);
116         keymap->poll = PE_poll;
117
118         kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", AKEY, KM_PRESS, 0, 0);
119         RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
120         kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
121         RNA_enum_set(kmi->ptr, "action", SEL_INVERT);
122
123         WM_keymap_add_item(keymap, "PARTICLE_OT_select_more", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
124         WM_keymap_add_item(keymap, "PARTICLE_OT_select_less", PADMINUS, KM_PRESS, KM_CTRL, 0);
125
126         kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, 0, 0);
127         RNA_boolean_set(kmi->ptr, "deselect", false);
128         kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_select_linked", LKEY, KM_PRESS, KM_SHIFT, 0);
129         RNA_boolean_set(kmi->ptr, "deselect", true);
130
131         WM_keymap_add_item(keymap, "PARTICLE_OT_delete", XKEY, KM_PRESS, 0, 0);
132         WM_keymap_add_item(keymap, "PARTICLE_OT_delete", DELKEY, KM_PRESS, 0, 0);
133
134         WM_keymap_add_item(keymap, "PARTICLE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0);
135         kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, 0, 0);
136         RNA_boolean_set(kmi->ptr, "unselected", false);
137         kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
138         RNA_boolean_set(kmi->ptr, "unselected", true);
139
140         WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, 0, 0);
141         WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
142
143         /* size radial control */
144         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, 0, 0);
145         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.particle_edit.brush.size");
146
147         /* size radial control */
148         kmi = WM_keymap_add_item(keymap, "WM_OT_radial_control", FKEY, KM_PRESS, KM_SHIFT, 0);
149         RNA_string_set(kmi->ptr, "data_path_primary", "tool_settings.particle_edit.brush.strength");
150
151         WM_keymap_add_menu(keymap, "VIEW3D_MT_particle_specials", WKEY, KM_PRESS, 0, 0);
152
153         WM_keymap_add_item(keymap, "PARTICLE_OT_weight_set", KKEY, KM_PRESS, KM_SHIFT, 0);
154
155         ED_keymap_proportional_cycle(keyconf, keymap);
156         ED_keymap_proportional_editmode(keyconf, keymap, false);
157 }
158
159 /******************************* boids *************************************/
160
161 static void operatortypes_boids(void)
162 {
163         WM_operatortype_append(BOID_OT_rule_add);
164         WM_operatortype_append(BOID_OT_rule_del);
165         WM_operatortype_append(BOID_OT_rule_move_up);
166         WM_operatortype_append(BOID_OT_rule_move_down);
167
168         WM_operatortype_append(BOID_OT_state_add);
169         WM_operatortype_append(BOID_OT_state_del);
170         WM_operatortype_append(BOID_OT_state_move_up);
171         WM_operatortype_append(BOID_OT_state_move_down);
172 }
173
174 /********************************* fluid ***********************************/
175
176 static void operatortypes_fluid(void)
177 {
178         WM_operatortype_append(FLUID_OT_bake);
179 }
180
181 /**************************** point cache **********************************/
182
183 static void operatortypes_pointcache(void)
184 {
185         WM_operatortype_append(PTCACHE_OT_bake_all);
186         WM_operatortype_append(PTCACHE_OT_free_bake_all);
187         WM_operatortype_append(PTCACHE_OT_bake);
188         WM_operatortype_append(PTCACHE_OT_free_bake);
189         WM_operatortype_append(PTCACHE_OT_bake_from_cache);
190         WM_operatortype_append(PTCACHE_OT_add);
191         WM_operatortype_append(PTCACHE_OT_remove);
192 }
193
194 /********************************* dynamic paint ***********************************/
195
196 static void operatortypes_dynamicpaint(void)
197 {
198         WM_operatortype_append(DPAINT_OT_bake);
199         WM_operatortype_append(DPAINT_OT_surface_slot_add);
200         WM_operatortype_append(DPAINT_OT_surface_slot_remove);
201         WM_operatortype_append(DPAINT_OT_type_toggle);
202         WM_operatortype_append(DPAINT_OT_output_toggle);
203 }
204
205 //static void keymap_pointcache(wmWindowManager *wm)
206 //{
207 //      wmKeyMap *keymap = WM_keymap_find(wm, "Pointcache", 0, 0);
208 //
209 //      WM_keymap_add_item(keymap, "PHYSICS_OT_bake_all", AKEY, KM_PRESS, 0, 0);
210 //      WM_keymap_add_item(keymap, "PHYSICS_OT_free_all", PADPLUSKEY, KM_PRESS, KM_CTRL, 0);
211 //      WM_keymap_add_item(keymap, "PHYSICS_OT_bake_particle_system", PADMINUS, KM_PRESS, KM_CTRL, 0);
212 //      WM_keymap_add_item(keymap, "PHYSICS_OT_free_particle_system", LKEY, KM_PRESS, 0, 0);
213 //}
214
215 /****************************** general ************************************/
216
217 void ED_operatortypes_physics(void)
218 {
219         operatortypes_particle();
220         operatortypes_boids();
221         operatortypes_fluid();
222         operatortypes_pointcache();
223         operatortypes_dynamicpaint();
224 }
225
226 void ED_keymap_physics(wmKeyConfig *keyconf)
227 {
228         keymap_particle(keyconf);
229         //keymap_pointcache(keyconf);
230 }
231
232
233