GPencil: Fix keymap error for Fill Boundary strokes
[blender.git] / source / blender / editors / object / object_ops.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup edobj
22  */
23
24 #include <math.h>
25 #include <stdlib.h>
26
27 #include "DNA_object_types.h"
28 #include "DNA_scene_types.h"
29
30 #include "BLI_utildefines.h"
31
32 #include "BKE_context.h"
33
34 #include "RNA_access.h"
35 #include "RNA_enum_types.h"
36
37 #include "WM_api.h"
38 #include "WM_types.h"
39
40 #include "ED_object.h"
41 #include "ED_screen.h"
42 #include "ED_select_utils.h"
43
44 #include "DEG_depsgraph.h"
45
46 #include "object_intern.h"
47
48 /* ************************** registration **********************************/
49
50 void ED_operatortypes_object(void)
51 {
52   WM_operatortype_append(OBJECT_OT_location_clear);
53   WM_operatortype_append(OBJECT_OT_rotation_clear);
54   WM_operatortype_append(OBJECT_OT_scale_clear);
55   WM_operatortype_append(OBJECT_OT_origin_clear);
56   WM_operatortype_append(OBJECT_OT_visual_transform_apply);
57   WM_operatortype_append(OBJECT_OT_transform_apply);
58   WM_operatortype_append(OBJECT_OT_transform_axis_target);
59   WM_operatortype_append(OBJECT_OT_origin_set);
60
61   WM_operatortype_append(OBJECT_OT_mode_set);
62   WM_operatortype_append(OBJECT_OT_mode_set_with_submode);
63   WM_operatortype_append(OBJECT_OT_editmode_toggle);
64   WM_operatortype_append(OBJECT_OT_posemode_toggle);
65   WM_operatortype_append(OBJECT_OT_proxy_make);
66   WM_operatortype_append(OBJECT_OT_shade_smooth);
67   WM_operatortype_append(OBJECT_OT_shade_flat);
68   WM_operatortype_append(OBJECT_OT_paths_calculate);
69   WM_operatortype_append(OBJECT_OT_paths_update);
70   WM_operatortype_append(OBJECT_OT_paths_clear);
71   WM_operatortype_append(OBJECT_OT_paths_range_update);
72   WM_operatortype_append(OBJECT_OT_forcefield_toggle);
73
74   WM_operatortype_append(OBJECT_OT_parent_set);
75   WM_operatortype_append(OBJECT_OT_parent_no_inverse_set);
76   WM_operatortype_append(OBJECT_OT_parent_clear);
77   WM_operatortype_append(OBJECT_OT_vertex_parent_set);
78   WM_operatortype_append(OBJECT_OT_track_set);
79   WM_operatortype_append(OBJECT_OT_track_clear);
80   WM_operatortype_append(OBJECT_OT_make_local);
81   WM_operatortype_append(OBJECT_OT_make_override_library);
82   WM_operatortype_append(OBJECT_OT_make_single_user);
83   WM_operatortype_append(OBJECT_OT_make_links_scene);
84   WM_operatortype_append(OBJECT_OT_make_links_data);
85
86   WM_operatortype_append(OBJECT_OT_select_random);
87   WM_operatortype_append(OBJECT_OT_select_all);
88   WM_operatortype_append(OBJECT_OT_select_same_collection);
89   WM_operatortype_append(OBJECT_OT_select_by_type);
90   WM_operatortype_append(OBJECT_OT_select_linked);
91   WM_operatortype_append(OBJECT_OT_select_grouped);
92   WM_operatortype_append(OBJECT_OT_select_mirror);
93   WM_operatortype_append(OBJECT_OT_select_more);
94   WM_operatortype_append(OBJECT_OT_select_less);
95
96   WM_operatortype_append(COLLECTION_OT_create);
97   WM_operatortype_append(COLLECTION_OT_objects_remove_all);
98   WM_operatortype_append(COLLECTION_OT_objects_remove);
99   WM_operatortype_append(COLLECTION_OT_objects_add_active);
100   WM_operatortype_append(COLLECTION_OT_objects_remove_active);
101
102   WM_operatortype_append(OBJECT_OT_delete);
103   WM_operatortype_append(OBJECT_OT_text_add);
104   WM_operatortype_append(OBJECT_OT_armature_add);
105   WM_operatortype_append(OBJECT_OT_empty_add);
106   WM_operatortype_append(OBJECT_OT_lightprobe_add);
107   WM_operatortype_append(OBJECT_OT_drop_named_image);
108   WM_operatortype_append(OBJECT_OT_gpencil_add);
109   WM_operatortype_append(OBJECT_OT_light_add);
110   WM_operatortype_append(OBJECT_OT_camera_add);
111   WM_operatortype_append(OBJECT_OT_speaker_add);
112   WM_operatortype_append(OBJECT_OT_hair_add);
113   WM_operatortype_append(OBJECT_OT_pointcloud_add);
114   WM_operatortype_append(OBJECT_OT_volume_add);
115   WM_operatortype_append(OBJECT_OT_volume_import);
116   WM_operatortype_append(OBJECT_OT_add);
117   WM_operatortype_append(OBJECT_OT_add_named);
118   WM_operatortype_append(OBJECT_OT_effector_add);
119   WM_operatortype_append(OBJECT_OT_collection_instance_add);
120   WM_operatortype_append(OBJECT_OT_metaball_add);
121   WM_operatortype_append(OBJECT_OT_duplicates_make_real);
122   WM_operatortype_append(OBJECT_OT_duplicate);
123   WM_operatortype_append(OBJECT_OT_join);
124   WM_operatortype_append(OBJECT_OT_join_shapes);
125   WM_operatortype_append(OBJECT_OT_convert);
126
127   WM_operatortype_append(OBJECT_OT_modifier_add);
128   WM_operatortype_append(OBJECT_OT_modifier_remove);
129   WM_operatortype_append(OBJECT_OT_modifier_move_up);
130   WM_operatortype_append(OBJECT_OT_modifier_move_down);
131   WM_operatortype_append(OBJECT_OT_modifier_move_to_index);
132   WM_operatortype_append(OBJECT_OT_modifier_apply);
133   WM_operatortype_append(OBJECT_OT_modifier_apply_as_shapekey);
134   WM_operatortype_append(OBJECT_OT_modifier_convert);
135   WM_operatortype_append(OBJECT_OT_modifier_copy);
136   WM_operatortype_append(OBJECT_OT_multires_subdivide);
137   WM_operatortype_append(OBJECT_OT_multires_reshape);
138   WM_operatortype_append(OBJECT_OT_multires_higher_levels_delete);
139   WM_operatortype_append(OBJECT_OT_multires_base_apply);
140   WM_operatortype_append(OBJECT_OT_multires_unsubdivide);
141   WM_operatortype_append(OBJECT_OT_multires_rebuild_subdiv);
142   WM_operatortype_append(OBJECT_OT_multires_external_save);
143   WM_operatortype_append(OBJECT_OT_multires_external_pack);
144   WM_operatortype_append(OBJECT_OT_skin_root_mark);
145   WM_operatortype_append(OBJECT_OT_skin_loose_mark_clear);
146   WM_operatortype_append(OBJECT_OT_skin_radii_equalize);
147   WM_operatortype_append(OBJECT_OT_skin_armature_create);
148
149   /* grease pencil modifiers */
150   WM_operatortype_append(OBJECT_OT_gpencil_modifier_add);
151   WM_operatortype_append(OBJECT_OT_gpencil_modifier_remove);
152   WM_operatortype_append(OBJECT_OT_gpencil_modifier_move_up);
153   WM_operatortype_append(OBJECT_OT_gpencil_modifier_move_down);
154   WM_operatortype_append(OBJECT_OT_gpencil_modifier_move_to_index);
155   WM_operatortype_append(OBJECT_OT_gpencil_modifier_apply);
156   WM_operatortype_append(OBJECT_OT_gpencil_modifier_copy);
157
158   /* shader fx */
159   WM_operatortype_append(OBJECT_OT_shaderfx_add);
160   WM_operatortype_append(OBJECT_OT_shaderfx_remove);
161   WM_operatortype_append(OBJECT_OT_shaderfx_move_up);
162   WM_operatortype_append(OBJECT_OT_shaderfx_move_down);
163   WM_operatortype_append(OBJECT_OT_shaderfx_move_to_index);
164
165   WM_operatortype_append(OBJECT_OT_correctivesmooth_bind);
166   WM_operatortype_append(OBJECT_OT_meshdeform_bind);
167   WM_operatortype_append(OBJECT_OT_explode_refresh);
168   WM_operatortype_append(OBJECT_OT_ocean_bake);
169
170   WM_operatortype_append(OBJECT_OT_constraint_add);
171   WM_operatortype_append(OBJECT_OT_constraint_add_with_targets);
172   WM_operatortype_append(POSE_OT_constraint_add);
173   WM_operatortype_append(POSE_OT_constraint_add_with_targets);
174   WM_operatortype_append(OBJECT_OT_constraints_copy);
175   WM_operatortype_append(POSE_OT_constraints_copy);
176   WM_operatortype_append(OBJECT_OT_constraints_clear);
177   WM_operatortype_append(POSE_OT_constraints_clear);
178   WM_operatortype_append(POSE_OT_ik_add);
179   WM_operatortype_append(POSE_OT_ik_clear);
180   WM_operatortype_append(CONSTRAINT_OT_delete);
181   WM_operatortype_append(CONSTRAINT_OT_move_up);
182   WM_operatortype_append(CONSTRAINT_OT_move_down);
183   WM_operatortype_append(CONSTRAINT_OT_move_to_index);
184   WM_operatortype_append(CONSTRAINT_OT_stretchto_reset);
185   WM_operatortype_append(CONSTRAINT_OT_limitdistance_reset);
186   WM_operatortype_append(CONSTRAINT_OT_childof_set_inverse);
187   WM_operatortype_append(CONSTRAINT_OT_childof_clear_inverse);
188   WM_operatortype_append(CONSTRAINT_OT_objectsolver_set_inverse);
189   WM_operatortype_append(CONSTRAINT_OT_objectsolver_clear_inverse);
190   WM_operatortype_append(CONSTRAINT_OT_followpath_path_animate);
191
192   WM_operatortype_append(OBJECT_OT_vertex_group_add);
193   WM_operatortype_append(OBJECT_OT_vertex_group_remove);
194   WM_operatortype_append(OBJECT_OT_vertex_group_assign);
195   WM_operatortype_append(OBJECT_OT_vertex_group_assign_new);
196   WM_operatortype_append(OBJECT_OT_vertex_group_remove_from);
197   WM_operatortype_append(OBJECT_OT_vertex_group_select);
198   WM_operatortype_append(OBJECT_OT_vertex_group_deselect);
199   WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked);
200   WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected);
201   WM_operatortype_append(OBJECT_OT_vertex_group_copy);
202   WM_operatortype_append(OBJECT_OT_vertex_group_normalize);
203   WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all);
204   WM_operatortype_append(OBJECT_OT_vertex_group_lock);
205   WM_operatortype_append(OBJECT_OT_vertex_group_fix);
206   WM_operatortype_append(OBJECT_OT_vertex_group_invert);
207   WM_operatortype_append(OBJECT_OT_vertex_group_levels);
208   WM_operatortype_append(OBJECT_OT_vertex_group_smooth);
209   WM_operatortype_append(OBJECT_OT_vertex_group_clean);
210   WM_operatortype_append(OBJECT_OT_vertex_group_quantize);
211   WM_operatortype_append(OBJECT_OT_vertex_group_limit_total);
212   WM_operatortype_append(OBJECT_OT_vertex_group_mirror);
213   WM_operatortype_append(OBJECT_OT_vertex_group_set_active);
214   WM_operatortype_append(OBJECT_OT_vertex_group_sort);
215   WM_operatortype_append(OBJECT_OT_vertex_group_move);
216   WM_operatortype_append(OBJECT_OT_vertex_weight_paste);
217   WM_operatortype_append(OBJECT_OT_vertex_weight_delete);
218   WM_operatortype_append(OBJECT_OT_vertex_weight_set_active);
219   WM_operatortype_append(OBJECT_OT_vertex_weight_normalize_active_vertex);
220   WM_operatortype_append(OBJECT_OT_vertex_weight_copy);
221
222   WM_operatortype_append(OBJECT_OT_face_map_add);
223   WM_operatortype_append(OBJECT_OT_face_map_remove);
224   WM_operatortype_append(OBJECT_OT_face_map_assign);
225   WM_operatortype_append(OBJECT_OT_face_map_remove_from);
226   WM_operatortype_append(OBJECT_OT_face_map_select);
227   WM_operatortype_append(OBJECT_OT_face_map_deselect);
228   WM_operatortype_append(OBJECT_OT_face_map_move);
229
230   WM_operatortype_append(TRANSFORM_OT_vertex_warp);
231
232   WM_operatortype_append(OBJECT_OT_move_to_collection);
233   WM_operatortype_append(OBJECT_OT_link_to_collection);
234
235   WM_operatortype_append(OBJECT_OT_shape_key_add);
236   WM_operatortype_append(OBJECT_OT_shape_key_remove);
237   WM_operatortype_append(OBJECT_OT_shape_key_clear);
238   WM_operatortype_append(OBJECT_OT_shape_key_retime);
239   WM_operatortype_append(OBJECT_OT_shape_key_mirror);
240   WM_operatortype_append(OBJECT_OT_shape_key_move);
241
242   WM_operatortype_append(OBJECT_OT_collection_add);
243   WM_operatortype_append(OBJECT_OT_collection_link);
244   WM_operatortype_append(OBJECT_OT_collection_remove);
245   WM_operatortype_append(OBJECT_OT_collection_unlink);
246   WM_operatortype_append(OBJECT_OT_collection_objects_select);
247
248   WM_operatortype_append(OBJECT_OT_hook_add_selob);
249   WM_operatortype_append(OBJECT_OT_hook_add_newob);
250   WM_operatortype_append(OBJECT_OT_hook_remove);
251   WM_operatortype_append(OBJECT_OT_hook_select);
252   WM_operatortype_append(OBJECT_OT_hook_assign);
253   WM_operatortype_append(OBJECT_OT_hook_reset);
254   WM_operatortype_append(OBJECT_OT_hook_recenter);
255
256   WM_operatortype_append(OBJECT_OT_bake_image);
257   WM_operatortype_append(OBJECT_OT_bake);
258   WM_operatortype_append(OBJECT_OT_drop_named_material);
259   WM_operatortype_append(OBJECT_OT_unlink_data);
260   WM_operatortype_append(OBJECT_OT_laplaciandeform_bind);
261
262   WM_operatortype_append(TRANSFORM_OT_vertex_random);
263
264   WM_operatortype_append(OBJECT_OT_data_transfer);
265   WM_operatortype_append(OBJECT_OT_datalayout_transfer);
266   WM_operatortype_append(OBJECT_OT_surfacedeform_bind);
267
268   WM_operatortype_append(OBJECT_OT_hide_view_clear);
269   WM_operatortype_append(OBJECT_OT_hide_view_set);
270   WM_operatortype_append(OBJECT_OT_hide_collection);
271
272   WM_operatortype_append(OBJECT_OT_voxel_remesh);
273   WM_operatortype_append(OBJECT_OT_voxel_size_edit);
274
275   WM_operatortype_append(OBJECT_OT_quadriflow_remesh);
276 }
277
278 void ED_operatormacros_object(void)
279 {
280   wmOperatorType *ot;
281   wmOperatorTypeMacro *otmacro;
282
283   ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move",
284                                     "Duplicate Objects",
285                                     "Duplicate selected objects and move them",
286                                     OPTYPE_UNDO | OPTYPE_REGISTER);
287   if (ot) {
288     WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
289     otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
290     RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
291   }
292
293   /* grr, should be able to pass options on... */
294   ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move_linked",
295                                     "Duplicate Linked",
296                                     "Duplicate selected objects and move them",
297                                     OPTYPE_UNDO | OPTYPE_REGISTER);
298   if (ot) {
299     otmacro = WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
300     RNA_boolean_set(otmacro->ptr, "linked", true);
301     otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
302     RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
303   }
304 }
305
306 static bool object_mode_poll(bContext *C)
307 {
308   Object *ob = CTX_data_active_object(C);
309   return (!ob || ob->mode == OB_MODE_OBJECT);
310 }
311
312 void ED_keymap_object(wmKeyConfig *keyconf)
313 {
314   wmKeyMap *keymap;
315
316   /* Objects, Regardless of Mode -------------------------------------------------- */
317   keymap = WM_keymap_ensure(keyconf, "Object Non-modal", 0, 0);
318
319   /* Object Mode ---------------------------------------------------------------- */
320   /* Note: this keymap gets disabled in non-objectmode,  */
321   keymap = WM_keymap_ensure(keyconf, "Object Mode", 0, 0);
322   keymap->poll = object_mode_poll;
323 }