Rename operator 'Join Shapes' to 'Transfer Mix'.
[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 <stdlib.h>
25 #include <math.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_screen.h"
41 #include "ED_select_utils.h"
42 #include "ED_object.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_or_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_add);
113   WM_operatortype_append(OBJECT_OT_add_named);
114   WM_operatortype_append(OBJECT_OT_effector_add);
115   WM_operatortype_append(OBJECT_OT_collection_instance_add);
116   WM_operatortype_append(OBJECT_OT_metaball_add);
117   WM_operatortype_append(OBJECT_OT_duplicates_make_real);
118   WM_operatortype_append(OBJECT_OT_duplicate);
119   WM_operatortype_append(OBJECT_OT_join);
120   WM_operatortype_append(OBJECT_OT_shape_key_transfer_mix);
121   WM_operatortype_append(OBJECT_OT_convert);
122
123   WM_operatortype_append(OBJECT_OT_modifier_add);
124   WM_operatortype_append(OBJECT_OT_modifier_remove);
125   WM_operatortype_append(OBJECT_OT_modifier_move_up);
126   WM_operatortype_append(OBJECT_OT_modifier_move_down);
127   WM_operatortype_append(OBJECT_OT_modifier_apply);
128   WM_operatortype_append(OBJECT_OT_modifier_convert);
129   WM_operatortype_append(OBJECT_OT_modifier_copy);
130   WM_operatortype_append(OBJECT_OT_multires_subdivide);
131   WM_operatortype_append(OBJECT_OT_multires_reshape);
132   WM_operatortype_append(OBJECT_OT_multires_higher_levels_delete);
133   WM_operatortype_append(OBJECT_OT_multires_base_apply);
134   WM_operatortype_append(OBJECT_OT_multires_external_save);
135   WM_operatortype_append(OBJECT_OT_multires_external_pack);
136   WM_operatortype_append(OBJECT_OT_skin_root_mark);
137   WM_operatortype_append(OBJECT_OT_skin_loose_mark_clear);
138   WM_operatortype_append(OBJECT_OT_skin_radii_equalize);
139   WM_operatortype_append(OBJECT_OT_skin_armature_create);
140
141   /* grease pencil modifiers */
142   WM_operatortype_append(OBJECT_OT_gpencil_modifier_add);
143   WM_operatortype_append(OBJECT_OT_gpencil_modifier_remove);
144   WM_operatortype_append(OBJECT_OT_gpencil_modifier_move_up);
145   WM_operatortype_append(OBJECT_OT_gpencil_modifier_move_down);
146   WM_operatortype_append(OBJECT_OT_gpencil_modifier_apply);
147   WM_operatortype_append(OBJECT_OT_gpencil_modifier_copy);
148
149   /* shader fx */
150   WM_operatortype_append(OBJECT_OT_shaderfx_add);
151   WM_operatortype_append(OBJECT_OT_shaderfx_remove);
152   WM_operatortype_append(OBJECT_OT_shaderfx_move_up);
153   WM_operatortype_append(OBJECT_OT_shaderfx_move_down);
154
155   WM_operatortype_append(OBJECT_OT_correctivesmooth_bind);
156   WM_operatortype_append(OBJECT_OT_meshdeform_bind);
157   WM_operatortype_append(OBJECT_OT_explode_refresh);
158   WM_operatortype_append(OBJECT_OT_ocean_bake);
159
160   WM_operatortype_append(OBJECT_OT_constraint_add);
161   WM_operatortype_append(OBJECT_OT_constraint_add_with_targets);
162   WM_operatortype_append(POSE_OT_constraint_add);
163   WM_operatortype_append(POSE_OT_constraint_add_with_targets);
164   WM_operatortype_append(OBJECT_OT_constraints_copy);
165   WM_operatortype_append(POSE_OT_constraints_copy);
166   WM_operatortype_append(OBJECT_OT_constraints_clear);
167   WM_operatortype_append(POSE_OT_constraints_clear);
168   WM_operatortype_append(POSE_OT_ik_add);
169   WM_operatortype_append(POSE_OT_ik_clear);
170   WM_operatortype_append(CONSTRAINT_OT_delete);
171   WM_operatortype_append(CONSTRAINT_OT_move_up);
172   WM_operatortype_append(CONSTRAINT_OT_move_down);
173   WM_operatortype_append(CONSTRAINT_OT_stretchto_reset);
174   WM_operatortype_append(CONSTRAINT_OT_limitdistance_reset);
175   WM_operatortype_append(CONSTRAINT_OT_childof_set_inverse);
176   WM_operatortype_append(CONSTRAINT_OT_childof_clear_inverse);
177   WM_operatortype_append(CONSTRAINT_OT_objectsolver_set_inverse);
178   WM_operatortype_append(CONSTRAINT_OT_objectsolver_clear_inverse);
179   WM_operatortype_append(CONSTRAINT_OT_followpath_path_animate);
180
181   WM_operatortype_append(OBJECT_OT_vertex_group_add);
182   WM_operatortype_append(OBJECT_OT_vertex_group_remove);
183   WM_operatortype_append(OBJECT_OT_vertex_group_assign);
184   WM_operatortype_append(OBJECT_OT_vertex_group_assign_new);
185   WM_operatortype_append(OBJECT_OT_vertex_group_remove_from);
186   WM_operatortype_append(OBJECT_OT_vertex_group_select);
187   WM_operatortype_append(OBJECT_OT_vertex_group_deselect);
188   WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_linked);
189   WM_operatortype_append(OBJECT_OT_vertex_group_copy_to_selected);
190   WM_operatortype_append(OBJECT_OT_vertex_group_copy);
191   WM_operatortype_append(OBJECT_OT_vertex_group_normalize);
192   WM_operatortype_append(OBJECT_OT_vertex_group_normalize_all);
193   WM_operatortype_append(OBJECT_OT_vertex_group_lock);
194   WM_operatortype_append(OBJECT_OT_vertex_group_fix);
195   WM_operatortype_append(OBJECT_OT_vertex_group_invert);
196   WM_operatortype_append(OBJECT_OT_vertex_group_levels);
197   WM_operatortype_append(OBJECT_OT_vertex_group_smooth);
198   WM_operatortype_append(OBJECT_OT_vertex_group_clean);
199   WM_operatortype_append(OBJECT_OT_vertex_group_quantize);
200   WM_operatortype_append(OBJECT_OT_vertex_group_limit_total);
201   WM_operatortype_append(OBJECT_OT_vertex_group_mirror);
202   WM_operatortype_append(OBJECT_OT_vertex_group_set_active);
203   WM_operatortype_append(OBJECT_OT_vertex_group_sort);
204   WM_operatortype_append(OBJECT_OT_vertex_group_move);
205   WM_operatortype_append(OBJECT_OT_vertex_weight_paste);
206   WM_operatortype_append(OBJECT_OT_vertex_weight_delete);
207   WM_operatortype_append(OBJECT_OT_vertex_weight_set_active);
208   WM_operatortype_append(OBJECT_OT_vertex_weight_normalize_active_vertex);
209   WM_operatortype_append(OBJECT_OT_vertex_weight_copy);
210
211   WM_operatortype_append(OBJECT_OT_face_map_add);
212   WM_operatortype_append(OBJECT_OT_face_map_remove);
213   WM_operatortype_append(OBJECT_OT_face_map_assign);
214   WM_operatortype_append(OBJECT_OT_face_map_remove_from);
215   WM_operatortype_append(OBJECT_OT_face_map_select);
216   WM_operatortype_append(OBJECT_OT_face_map_deselect);
217   WM_operatortype_append(OBJECT_OT_face_map_move);
218
219   WM_operatortype_append(TRANSFORM_OT_vertex_warp);
220
221   WM_operatortype_append(OBJECT_OT_move_to_collection);
222   WM_operatortype_append(OBJECT_OT_link_to_collection);
223
224   WM_operatortype_append(OBJECT_OT_shape_key_add);
225   WM_operatortype_append(OBJECT_OT_shape_key_remove);
226   WM_operatortype_append(OBJECT_OT_shape_key_clear);
227   WM_operatortype_append(OBJECT_OT_shape_key_retime);
228   WM_operatortype_append(OBJECT_OT_shape_key_mirror);
229   WM_operatortype_append(OBJECT_OT_shape_key_move);
230
231   WM_operatortype_append(OBJECT_OT_collection_add);
232   WM_operatortype_append(OBJECT_OT_collection_link);
233   WM_operatortype_append(OBJECT_OT_collection_remove);
234   WM_operatortype_append(OBJECT_OT_collection_unlink);
235   WM_operatortype_append(OBJECT_OT_collection_objects_select);
236
237   WM_operatortype_append(OBJECT_OT_hook_add_selob);
238   WM_operatortype_append(OBJECT_OT_hook_add_newob);
239   WM_operatortype_append(OBJECT_OT_hook_remove);
240   WM_operatortype_append(OBJECT_OT_hook_select);
241   WM_operatortype_append(OBJECT_OT_hook_assign);
242   WM_operatortype_append(OBJECT_OT_hook_reset);
243   WM_operatortype_append(OBJECT_OT_hook_recenter);
244
245   WM_operatortype_append(OBJECT_OT_bake_image);
246   WM_operatortype_append(OBJECT_OT_bake);
247   WM_operatortype_append(OBJECT_OT_drop_named_material);
248   WM_operatortype_append(OBJECT_OT_unlink_data);
249   WM_operatortype_append(OBJECT_OT_laplaciandeform_bind);
250
251   WM_operatortype_append(TRANSFORM_OT_vertex_random);
252
253   WM_operatortype_append(OBJECT_OT_data_transfer);
254   WM_operatortype_append(OBJECT_OT_datalayout_transfer);
255   WM_operatortype_append(OBJECT_OT_surfacedeform_bind);
256
257   WM_operatortype_append(OBJECT_OT_hide_view_clear);
258   WM_operatortype_append(OBJECT_OT_hide_view_set);
259   WM_operatortype_append(OBJECT_OT_hide_collection);
260 }
261
262 void ED_operatormacros_object(void)
263 {
264   wmOperatorType *ot;
265   wmOperatorTypeMacro *otmacro;
266
267   ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move",
268                                     "Duplicate Objects",
269                                     "Duplicate selected objects and move them",
270                                     OPTYPE_UNDO | OPTYPE_REGISTER);
271   if (ot) {
272     WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
273     otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
274     RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
275   }
276
277   /* grr, should be able to pass options on... */
278   ot = WM_operatortype_append_macro("OBJECT_OT_duplicate_move_linked",
279                                     "Duplicate Linked",
280                                     "Duplicate selected objects and move them",
281                                     OPTYPE_UNDO | OPTYPE_REGISTER);
282   if (ot) {
283     otmacro = WM_operatortype_macro_define(ot, "OBJECT_OT_duplicate");
284     RNA_boolean_set(otmacro->ptr, "linked", true);
285     otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
286     RNA_boolean_set(otmacro->ptr, "use_proportional_edit", false);
287   }
288 }
289
290 static bool object_mode_poll(bContext *C)
291 {
292   Object *ob = CTX_data_active_object(C);
293   return (!ob || ob->mode == OB_MODE_OBJECT);
294 }
295
296 void ED_keymap_object(wmKeyConfig *keyconf)
297 {
298   wmKeyMap *keymap;
299
300   /* Objects, Regardless of Mode -------------------------------------------------- */
301   keymap = WM_keymap_ensure(keyconf, "Object Non-modal", 0, 0);
302
303   /* Object Mode ---------------------------------------------------------------- */
304   /* Note: this keymap gets disabled in non-objectmode,  */
305   keymap = WM_keymap_ensure(keyconf, "Object Mode", 0, 0);
306   keymap->poll = object_mode_poll;
307 }