WM: remove duplicate ui-list functions
[blender.git] / source / blender / editors / transform / transform_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  * Contributor(s): none yet.
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/editors/transform/transform_ops.c
24  *  \ingroup edtransform
25  */
26
27 #include "MEM_guardedalloc.h"
28
29 #include "DNA_mesh_types.h"
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32
33 #include "BLI_math.h"
34 #include "BLI_utildefines.h"
35
36 #include "BLT_translation.h"
37
38 #include "BKE_context.h"
39 #include "BKE_global.h"
40 #include "BKE_report.h"
41 #include "BKE_editmesh.h"
42
43 #include "RNA_access.h"
44 #include "RNA_define.h"
45 #include "RNA_enum_types.h"
46
47 #include "WM_api.h"
48 #include "WM_message.h"
49 #include "WM_types.h"
50
51 #include "UI_interface.h"
52 #include "UI_resources.h"
53
54 #include "ED_screen.h"
55 /* for USE_LOOPSLIDE_HACK only */
56 #include "ED_mesh.h"
57
58 #include "transform.h"
59
60 typedef struct TransformModeItem {
61         const char *idname;
62         int mode;
63         void (*opfunc)(wmOperatorType *);
64 } TransformModeItem;
65
66 static const float VecOne[3] = {1, 1, 1};
67
68 static const char OP_TRANSLATION[] = "TRANSFORM_OT_translate";
69 static const char OP_ROTATION[] = "TRANSFORM_OT_rotate";
70 static const char OP_TOSPHERE[] = "TRANSFORM_OT_tosphere";
71 static const char OP_RESIZE[] = "TRANSFORM_OT_resize";
72 static const char OP_SKIN_RESIZE[] = "TRANSFORM_OT_skin_resize";
73 static const char OP_SHEAR[] = "TRANSFORM_OT_shear";
74 static const char OP_BEND[] = "TRANSFORM_OT_bend";
75 static const char OP_SHRINK_FATTEN[] = "TRANSFORM_OT_shrink_fatten";
76 static const char OP_PUSH_PULL[] = "TRANSFORM_OT_push_pull";
77 static const char OP_TILT[] = "TRANSFORM_OT_tilt";
78 static const char OP_TRACKBALL[] = "TRANSFORM_OT_trackball";
79 static const char OP_MIRROR[] = "TRANSFORM_OT_mirror";
80 static const char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide";
81 static const char OP_VERT_SLIDE[] = "TRANSFORM_OT_vert_slide";
82 static const char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease";
83 static const char OP_EDGE_BWEIGHT[] = "TRANSFORM_OT_edge_bevelweight";
84 static const char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide";
85
86 static void TRANSFORM_OT_translate(struct wmOperatorType *ot);
87 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot);
88 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot);
89 static void TRANSFORM_OT_resize(struct wmOperatorType *ot);
90 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot);
91 static void TRANSFORM_OT_shear(struct wmOperatorType *ot);
92 static void TRANSFORM_OT_bend(struct wmOperatorType *ot);
93 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot);
94 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot);
95 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot);
96 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot);
97 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot);
98 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot);
99 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot);
100 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot);
101 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot);
102 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot);
103
104 static TransformModeItem transform_modes[] =
105 {
106         {OP_TRANSLATION, TFM_TRANSLATION, TRANSFORM_OT_translate},
107         {OP_ROTATION, TFM_ROTATION, TRANSFORM_OT_rotate},
108         {OP_TOSPHERE, TFM_TOSPHERE, TRANSFORM_OT_tosphere},
109         {OP_RESIZE, TFM_RESIZE, TRANSFORM_OT_resize},
110         {OP_SKIN_RESIZE, TFM_SKIN_RESIZE, TRANSFORM_OT_skin_resize},
111         {OP_SHEAR, TFM_SHEAR, TRANSFORM_OT_shear},
112         {OP_BEND, TFM_BEND, TRANSFORM_OT_bend},
113         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN, TRANSFORM_OT_shrink_fatten},
114         {OP_PUSH_PULL, TFM_PUSHPULL, TRANSFORM_OT_push_pull},
115         {OP_TILT, TFM_TILT, TRANSFORM_OT_tilt},
116         {OP_TRACKBALL, TFM_TRACKBALL, TRANSFORM_OT_trackball},
117         {OP_MIRROR, TFM_MIRROR, TRANSFORM_OT_mirror},
118         {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide},
119         {OP_VERT_SLIDE, TFM_VERT_SLIDE, TRANSFORM_OT_vert_slide},
120         {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease},
121         {OP_EDGE_BWEIGHT, TFM_BWEIGHT, TRANSFORM_OT_edge_bevelweight},
122         {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide},
123         {NULL, 0}
124 };
125
126 const EnumPropertyItem rna_enum_transform_mode_types[] =
127 {
128         {TFM_INIT, "INIT", 0, "Init", ""},
129         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
130         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
131         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
132         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
133         {TFM_SKIN_RESIZE, "SKIN_RESIZE", 0, "Skin Resize", ""},
134         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
135         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
136         {TFM_BEND, "BEND", 0, "Bend", ""},
137         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
138         {TFM_TILT, "TILT", 0, "Tilt", ""},
139         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
140         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
141         {TFM_CREASE, "CREASE", 0, "Crease", ""},
142         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
143         {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
144         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
145         {TFM_BONE_ENVELOPE_DIST, "BONE_ENVELOPE_DIST", 0, "Bone_Envelope_Distance", ""},
146         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
147         {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""},
148         {TFM_GPENCIL_SHRINKFATTEN, "GPENCIL_SHRINKFATTEN", 0, "GPencil_Shrinkfatten", ""},
149         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
150         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
151         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
152         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
153         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
154         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
155         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
156         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
157         {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
158         {TFM_SEQ_SLIDE, "SEQSLIDE", 0, "Sequence Slide", ""},
159         {0, NULL, 0, NULL, NULL}
160 };
161
162 static int select_orientation_exec(bContext *C, wmOperator *op)
163 {
164         Scene *scene = CTX_data_scene(C);
165         int orientation = RNA_enum_get(op->ptr, "orientation");
166
167         BIF_selectTransformOrientationValue(scene, orientation);
168
169         WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
170
171         struct wmMsgBus *mbus = CTX_wm_message_bus(C);
172         WM_msg_publish_rna_prop(mbus, &scene->id, scene, Scene, transform_orientation);
173
174         return OPERATOR_FINISHED;
175 }
176
177 static int select_orientation_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
178 {
179         uiPopupMenu *pup;
180         uiLayout *layout;
181
182         pup = UI_popup_menu_begin(C, IFACE_("Orientation"), ICON_NONE);
183         layout = UI_popup_menu_layout(pup);
184         uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
185         UI_popup_menu_end(C, pup);
186
187         return OPERATOR_INTERFACE;
188 }
189
190 static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
191 {
192         PropertyRNA *prop;
193
194         /* identifiers */
195         ot->name   = "Select Orientation";
196         ot->description = "Select transformation orientation";
197         ot->idname = "TRANSFORM_OT_select_orientation";
198         ot->flag   = OPTYPE_UNDO;
199
200         /* api callbacks */
201         ot->invoke = select_orientation_invoke;
202         ot->exec   = select_orientation_exec;
203         ot->poll   = ED_operator_view3d_active;
204
205         prop = RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
206         RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
207         RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
208 }
209
210
211 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
212 {
213         Scene *scene = CTX_data_scene(C);
214         BIF_removeTransformOrientationIndex(C, scene->orientation_index_custom);
215
216         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
217
218         return OPERATOR_FINISHED;
219 }
220
221 static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
222 {
223         return delete_orientation_exec(C, op);
224 }
225
226 static bool delete_orientation_poll(bContext *C)
227 {
228         Scene *scene = CTX_data_scene(C);
229
230         if (ED_operator_areaactive(C) == 0)
231                 return 0;
232
233         return (scene->orientation_type >= V3D_MANIP_CUSTOM) && (scene->orientation_index_custom != -1);
234 }
235
236 static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
237 {
238         /* identifiers */
239         ot->name   = "Delete Orientation";
240         ot->description = "Delete transformation orientation";
241         ot->idname = "TRANSFORM_OT_delete_orientation";
242         ot->flag   = OPTYPE_UNDO;
243
244         /* api callbacks */
245         ot->invoke = delete_orientation_invoke;
246         ot->exec   = delete_orientation_exec;
247         ot->poll   = delete_orientation_poll;
248 }
249
250 static int create_orientation_exec(bContext *C, wmOperator *op)
251 {
252         char name[MAX_NAME];
253         const bool use = RNA_boolean_get(op->ptr, "use");
254         const bool overwrite = RNA_boolean_get(op->ptr, "overwrite");
255         const bool use_view = RNA_boolean_get(op->ptr, "use_view");
256         View3D *v3d = CTX_wm_view3d(C);
257
258         RNA_string_get(op->ptr, "name", name);
259
260         if (use && !v3d) {
261                 BKE_report(op->reports, RPT_ERROR, "Create Orientation's 'use' parameter only valid in a 3DView context");
262                 return OPERATOR_CANCELLED;
263         }
264
265         BIF_createTransformOrientation(C, op->reports, name, use_view, use, overwrite);
266
267         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
268         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
269
270         return OPERATOR_FINISHED;
271 }
272
273 static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
274 {
275         /* identifiers */
276         ot->name   = "Create Orientation";
277         ot->description = "Create transformation orientation from selection";
278         ot->idname = "TRANSFORM_OT_create_orientation";
279         ot->flag   = OPTYPE_REGISTER | OPTYPE_UNDO;
280
281         /* api callbacks */
282         ot->exec   = create_orientation_exec;
283         ot->poll   = ED_operator_areaactive;
284
285         RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the new custom orientation");
286         RNA_def_boolean(ot->srna, "use_view", false, "Use View",
287                         "Use the current view instead of the active object to create the new orientation");
288
289         WM_operatortype_props_advanced_begin(ot);
290
291         RNA_def_boolean(ot->srna, "use", false, "Use after creation", "Select orientation after its creation");
292         RNA_def_boolean(ot->srna, "overwrite", false, "Overwrite previous",
293                         "Overwrite previously created orientation with same name");
294 }
295
296
297 #ifdef USE_LOOPSLIDE_HACK
298 /**
299  * Special hack for MESH_OT_loopcut_slide so we get back to the selection mode
300  */
301 static void transformops_loopsel_hack(bContext *C, wmOperator *op)
302 {
303         if (op->type->idname == OP_EDGE_SLIDE) {
304                 if (op->opm && op->opm->opm && op->opm->opm->prev) {
305                         wmOperator *op_prev = op->opm->opm->prev;
306                         Scene *scene = CTX_data_scene(C);
307                         bool mesh_select_mode[3];
308                         PropertyRNA *prop = RNA_struct_find_property(op_prev->ptr, "mesh_select_mode_init");
309
310                         if (prop && RNA_property_is_set(op_prev->ptr, prop)) {
311                                 ToolSettings *ts = scene->toolsettings;
312                                 short selectmode_orig;
313
314                                 RNA_property_boolean_get_array(op_prev->ptr, prop, mesh_select_mode);
315                                 selectmode_orig = ((mesh_select_mode[0] ? SCE_SELECT_VERTEX : 0) |
316                                                    (mesh_select_mode[1] ? SCE_SELECT_EDGE   : 0) |
317                                                    (mesh_select_mode[2] ? SCE_SELECT_FACE   : 0));
318
319                                 /* still switch if we were originally in face select mode */
320                                 if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
321                                         Object *obedit = CTX_data_edit_object(C);
322                                         BMEditMesh *em = BKE_editmesh_from_object(obedit);
323                                         em->selectmode = ts->selectmode = selectmode_orig;
324                                         EDBM_selectmode_set(em);
325                                 }
326                         }
327                 }
328         }
329 }
330 #else
331 /* prevent removal by cleanup */
332 #  error "loopslide hack removed!"
333 #endif  /* USE_LOOPSLIDE_HACK */
334
335
336 static void transformops_exit(bContext *C, wmOperator *op)
337 {
338 #ifdef USE_LOOPSLIDE_HACK
339         transformops_loopsel_hack(C, op);
340 #endif
341
342         saveTransform(C, op->customdata, op);
343         MEM_freeN(op->customdata);
344         op->customdata = NULL;
345         G.moving = 0;
346 }
347
348 static int transformops_data(bContext *C, wmOperator *op, const wmEvent *event)
349 {
350         int retval = 1;
351         if (op->customdata == NULL) {
352                 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
353                 TransformModeItem *tmode;
354                 int mode = -1;
355
356                 for (tmode = transform_modes; tmode->idname; tmode++) {
357                         if (op->type->idname == tmode->idname) {
358                                 mode = tmode->mode;
359                                 break;
360                         }
361                 }
362
363                 if (mode == -1) {
364                         mode = RNA_enum_get(op->ptr, "mode");
365                 }
366
367                 retval = initTransform(C, t, op, event, mode);
368
369                 /* store data */
370                 if (retval) {
371                         G.moving = special_transform_moving(t);
372                         op->customdata = t;
373                 }
374                 else {
375                         MEM_freeN(t);
376                 }
377         }
378
379         return retval; /* return 0 on error */
380 }
381
382 static int transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
383 {
384         int exit_code;
385
386         TransInfo *t = op->customdata;
387         const enum TfmMode mode_prev = t->mode;
388
389 #if defined(WITH_INPUT_NDOF) && 0
390         // stable 2D mouse coords map to different 3D coords while the 3D mouse is active
391         // in other words, 2D deltas are no longer good enough!
392         // disable until individual 'transformers' behave better
393
394         if (event->type == NDOF_MOTION)
395                 return OPERATOR_PASS_THROUGH;
396 #endif
397
398         /* XXX insert keys are called here, and require context */
399         t->context = C;
400         exit_code = transformEvent(t, event);
401         t->context = NULL;
402
403         /* XXX, workaround: active needs to be calculated before transforming,
404          * since we're not reading from 'td->center' in this case. see: T40241 */
405         if (t->tsnap.target == SCE_SNAP_TARGET_ACTIVE) {
406                 /* In camera view, tsnap callback is not set (see initSnappingMode() in transfrom_snap.c, and T40348). */
407                 if (t->tsnap.targetSnap && ((t->tsnap.status & TARGET_INIT) == 0)) {
408                         t->tsnap.targetSnap(t);
409                 }
410         }
411
412         transformApply(C, t);
413
414         exit_code |= transformEnd(C, t);
415
416         if ((exit_code & OPERATOR_RUNNING_MODAL) == 0) {
417                 transformops_exit(C, op);
418                 exit_code &= ~OPERATOR_PASS_THROUGH; /* preventively remove passthrough */
419         }
420         else {
421                 if (mode_prev != t->mode) {
422                         /* WARNING: this is not normal to switch operator types
423                          * normally it would not be supported but transform happens
424                          * to share callbacks between different operators. */
425                         wmOperatorType *ot_new = NULL;
426                         TransformModeItem *item = transform_modes;
427                         while (item->idname) {
428                                 if (item->mode == t->mode) {
429                                         ot_new = WM_operatortype_find(item->idname, false);
430                                         break;
431                                 }
432                                 item++;
433                         }
434
435                         BLI_assert(ot_new != NULL);
436                         if (ot_new) {
437                                 WM_operator_type_set(op, ot_new);
438                         }
439                         /* end suspicious code */
440                 }
441         }
442
443         return exit_code;
444 }
445
446 static void transform_cancel(bContext *C, wmOperator *op)
447 {
448         TransInfo *t = op->customdata;
449
450         t->state = TRANS_CANCEL;
451         transformEnd(C, t);
452         transformops_exit(C, op);
453 }
454
455 static int transform_exec(bContext *C, wmOperator *op)
456 {
457         TransInfo *t;
458
459         if (!transformops_data(C, op, NULL)) {
460                 G.moving = 0;
461                 return OPERATOR_CANCELLED;
462         }
463
464         t = op->customdata;
465
466         t->options |= CTX_AUTOCONFIRM;
467
468         transformApply(C, t);
469
470         transformEnd(C, t);
471
472         transformops_exit(C, op);
473
474         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
475
476         return OPERATOR_FINISHED;
477 }
478
479 static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
480 {
481         if (!transformops_data(C, op, event)) {
482                 G.moving = 0;
483                 return OPERATOR_CANCELLED;
484         }
485
486         /* When modal, allow 'value' to set initial offset. */
487         if ((event == NULL) &&
488             RNA_struct_property_is_set(op->ptr, "value"))
489         {
490                 return transform_exec(C, op);
491         }
492         else {
493                 /* add temp handler */
494                 WM_event_add_modal_handler(C, op);
495
496                 op->flag |= OP_IS_MODAL_GRAB_CURSOR; // XXX maybe we want this with the gizmo only?
497
498                 /* Use when modal input has some transformation to begin with. */
499                 {
500                         TransInfo *t = op->customdata;
501                         if (UNLIKELY(!is_zero_v4(t->values_modal_offset))) {
502                                 transformApply(C, t);
503                         }
504                 }
505
506                 return OPERATOR_RUNNING_MODAL;
507         }
508 }
509
510 void Transform_Properties(struct wmOperatorType *ot, int flags)
511 {
512         PropertyRNA *prop;
513
514         if (flags & P_AXIS) {
515                 prop = RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
516                 RNA_def_property_array(prop, 3);
517                 /* Make this not hidden when there's a nice axis selection widget */
518                 RNA_def_property_flag(prop, PROP_HIDDEN);
519                 RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
520         }
521
522         if (flags & P_CONSTRAINT) {
523                 RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
524                 prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
525                 RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
526                 RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
527         }
528
529         if (flags & P_MIRROR) {
530                 prop = RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
531                 if (flags & P_MIRROR_DUMMY) {
532                         /* only used so macros can disable this option */
533                         RNA_def_property_flag(prop, PROP_HIDDEN);
534                 }
535         }
536
537
538         if (flags & P_PROPORTIONAL) {
539                 RNA_def_enum(ot->srna, "proportional", rna_enum_proportional_editing_items, 0, "Proportional Editing", "");
540                 prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", rna_enum_proportional_falloff_items, 0,
541                                     "Proportional Falloff", "Falloff type for proportional editing mode");
542                 RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
543                 RNA_def_float(ot->srna, "proportional_size", 1, T_PROP_SIZE_MIN, T_PROP_SIZE_MAX,
544                               "Proportional Size", "", 0.001f, 100.0f);
545         }
546
547         if (flags & P_SNAP) {
548                 prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
549                 RNA_def_property_flag(prop, PROP_HIDDEN);
550
551                 if (flags & P_GEO_SNAP) {
552                         prop = RNA_def_enum(ot->srna, "snap_target", rna_enum_snap_target_items, 0, "Target", "");
553                         RNA_def_property_flag(prop, PROP_HIDDEN);
554                         prop = RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
555                         RNA_def_property_flag(prop, PROP_HIDDEN);
556
557                         if (flags & P_ALIGN_SNAP) {
558                                 prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
559                                 RNA_def_property_flag(prop, PROP_HIDDEN);
560                                 prop = RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
561                                 RNA_def_property_flag(prop, PROP_HIDDEN);
562                         }
563                 }
564         }
565
566         if (flags & P_GPENCIL_EDIT) {
567                 prop = RNA_def_boolean(ot->srna, "gpencil_strokes", 0, "Edit Grease Pencil", "Edit selected Grease Pencil strokes");
568                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
569         }
570
571         if (flags & P_CURSOR_EDIT) {
572                 prop = RNA_def_boolean(ot->srna, "cursor_transform", 0, "Transform Cursor", "");
573                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
574         }
575
576         if ((flags & P_OPTIONS) && !(flags & P_NO_TEXSPACE)) {
577                 prop = RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
578                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
579                 prop = RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
580                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
581         }
582
583         if (flags & P_CORRECT_UV) {
584                 RNA_def_boolean(ot->srna, "correct_uv", true, "Correct UVs", "Correct UV coordinates when transforming");
585         }
586
587         if (flags & P_CENTER) {
588                 /* For gizmos that define their own center. */
589                 prop = RNA_def_property(ot->srna, "center_override", PROP_FLOAT, PROP_XYZ);
590                 RNA_def_property_array(prop, 3);
591                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
592                 RNA_def_property_ui_text(prop, "Center Override", "Force using this center value (when set)");
593         }
594
595         if ((flags & P_NO_DEFAULTS) == 0) {
596                 prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
597                 RNA_def_property_flag(prop, PROP_HIDDEN);
598
599                 prop = RNA_def_boolean(ot->srna, "use_accurate", 0, "Accurate", "Use accurate transformation");
600                 RNA_def_property_flag(prop, PROP_HIDDEN);
601         }
602 }
603
604 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
605 {
606         /* identifiers */
607         ot->name   = "Translate";
608         ot->description = "Translate (move) selected items";
609         ot->idname = OP_TRANSLATION;
610         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
611
612         /* api callbacks */
613         ot->invoke = transform_invoke;
614         ot->exec   = transform_exec;
615         ot->modal  = transform_modal;
616         ot->cancel = transform_cancel;
617         ot->poll   = ED_operator_screenactive;
618
619         RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
620
621         WM_operatortype_props_advanced_begin(ot);
622
623         Transform_Properties(
624                 ot,
625                 P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS |
626                 P_GPENCIL_EDIT | P_CURSOR_EDIT);
627 }
628
629 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
630 {
631         /* identifiers */
632         ot->name   = "Resize";
633         ot->description = "Scale (resize) selected items";
634         ot->idname = OP_RESIZE;
635         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
636
637         /* api callbacks */
638         ot->invoke = transform_invoke;
639         ot->exec   = transform_exec;
640         ot->modal  = transform_modal;
641         ot->cancel = transform_cancel;
642         ot->poll   = ED_operator_screenactive;
643
644         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
645
646         WM_operatortype_props_advanced_begin(ot);
647
648         Transform_Properties(
649                 ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CENTER);
650 }
651
652 static bool skin_resize_poll(bContext *C)
653 {
654         struct Object *obedit = CTX_data_edit_object(C);
655         if (obedit && obedit->type == OB_MESH) {
656                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
657                 return (em && CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN));
658         }
659         return 0;
660 }
661
662 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
663 {
664         /* identifiers */
665         ot->name   = "Skin Resize";
666         ot->description = "Scale selected vertices' skin radii";
667         ot->idname = OP_SKIN_RESIZE;
668         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
669
670         /* api callbacks */
671         ot->invoke = transform_invoke;
672         ot->exec   = transform_exec;
673         ot->modal  = transform_modal;
674         ot->cancel = transform_cancel;
675         ot->poll   = skin_resize_poll;
676
677         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
678
679         WM_operatortype_props_advanced_begin(ot);
680
681         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
682 }
683
684 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
685 {
686         /* identifiers */
687         ot->name   = "Trackball";
688         ot->description = "Trackball style rotation of selected items";
689         ot->idname = OP_TRACKBALL;
690         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
691
692         /* api callbacks */
693         ot->invoke = transform_invoke;
694         ot->exec   = transform_exec;
695         ot->modal  = transform_modal;
696         ot->cancel = transform_cancel;
697         ot->poll   = ED_operator_screenactive;
698
699         /* Maybe we could use float_vector_xyz here too? */
700         RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
701
702         WM_operatortype_props_advanced_begin(ot);
703
704         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
705 }
706
707 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
708 {
709         /* identifiers */
710         ot->name = "Rotate";
711         ot->description = "Rotate selected items";
712         ot->idname = OP_ROTATION;
713         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
714
715         /* api callbacks */
716         ot->invoke = transform_invoke;
717         ot->exec   = transform_exec;
718         ot->modal  = transform_modal;
719         ot->cancel = transform_cancel;
720         ot->poll   = ED_operator_screenactive;
721
722         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
723
724         WM_operatortype_props_advanced_begin(ot);
725
726         Transform_Properties(
727                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT | P_CENTER);
728 }
729
730 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
731 {
732         /* identifiers */
733         ot->name = "Tilt";
734         /* optional -
735          * "Tilt selected vertices"
736          * "Specify an extra axis rotation for selected vertices of 3D curve" */
737         ot->description = "Tilt selected control vertices of 3D curve";
738         ot->idname = OP_TILT;
739         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
740
741         /* api callbacks */
742         ot->invoke = transform_invoke;
743         ot->exec   = transform_exec;
744         ot->modal  = transform_modal;
745         ot->cancel = transform_cancel;
746         ot->poll   = ED_operator_editcurve_3d;
747
748         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
749
750         WM_operatortype_props_advanced_begin(ot);
751
752         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
753 }
754
755 static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
756 {
757         /* identifiers */
758         ot->name   = "Bend";
759         ot->description = "Bend selected items between the 3D cursor and the mouse";
760         ot->idname = OP_BEND;
761         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
762
763         /* api callbacks */
764         ot->invoke = transform_invoke;
765         // ot->exec   = transform_exec;  // unsupported
766         ot->modal  = transform_modal;
767         ot->cancel = transform_cancel;
768         ot->poll   = ED_operator_region_view3d_active;
769
770         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
771
772         WM_operatortype_props_advanced_begin(ot);
773
774         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
775 }
776
777 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
778 {
779         /* identifiers */
780         ot->name   = "Shear";
781         ot->description = "Shear selected items along the horizontal screen axis";
782         ot->idname = OP_SHEAR;
783         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
784
785         /* api callbacks */
786         ot->invoke = transform_invoke;
787         ot->exec   = transform_exec;
788         ot->modal  = transform_modal;
789         ot->cancel = transform_cancel;
790         ot->poll   = ED_operator_screenactive;
791
792         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
793
794         WM_operatortype_props_advanced_begin(ot);
795
796         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
797         // XXX Shear axis?
798 }
799
800 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
801 {
802         /* identifiers */
803         ot->name   = "Push/Pull";
804         ot->description = "Push/Pull selected items";
805         ot->idname = OP_PUSH_PULL;
806         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
807
808         /* api callbacks */
809         ot->invoke = transform_invoke;
810         ot->exec   = transform_exec;
811         ot->modal  = transform_modal;
812         ot->cancel = transform_cancel;
813         ot->poll   = ED_operator_screenactive;
814
815         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
816
817         WM_operatortype_props_advanced_begin(ot);
818
819         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_CENTER);
820 }
821
822 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
823 {
824         /* identifiers */
825         ot->name   = "Shrink/Fatten";
826         ot->description = "Shrink/fatten selected vertices along normals";
827         ot->idname = OP_SHRINK_FATTEN;
828         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
829
830         /* api callbacks */
831         ot->invoke = transform_invoke;
832         ot->exec   = transform_exec;
833         ot->modal  = transform_modal;
834         ot->cancel = transform_cancel;
835         ot->poll   = ED_operator_editmesh;
836
837         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
838
839         RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness");
840
841         WM_operatortype_props_advanced_begin(ot);
842
843         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
844 }
845
846 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
847 {
848         /* identifiers */
849         ot->name   = "To Sphere";
850         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()"
851         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
852         ot->idname = OP_TOSPHERE;
853         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
854
855         /* api callbacks */
856         ot->invoke = transform_invoke;
857         ot->exec   = transform_exec;
858         ot->modal  = transform_modal;
859         ot->cancel = transform_cancel;
860         ot->poll   = ED_operator_screenactive;
861
862         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
863
864         WM_operatortype_props_advanced_begin(ot);
865
866         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
867 }
868
869 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
870 {
871         /* identifiers */
872         ot->name   = "Mirror";
873         ot->description = "Mirror selected items around one or more axes";
874         ot->idname = OP_MIRROR;
875         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
876
877         /* api callbacks */
878         ot->invoke = transform_invoke;
879         ot->exec   = transform_exec;
880         ot->modal  = transform_modal;
881         ot->cancel = transform_cancel;
882         ot->poll   = ED_operator_screenactive;
883
884         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_GPENCIL_EDIT | P_CENTER);
885 }
886
887 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
888 {
889         PropertyRNA *prop;
890
891         /* identifiers */
892         ot->name   = "Edge Slide";
893         ot->description = "Slide an edge loop along a mesh";
894         ot->idname = OP_EDGE_SLIDE;
895         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
896
897         /* api callbacks */
898         ot->invoke = transform_invoke;
899         ot->exec   = transform_exec;
900         ot->modal  = transform_modal;
901         ot->cancel = transform_cancel;
902         ot->poll   = ED_operator_editmesh_region_view3d;
903
904         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
905
906         prop = RNA_def_boolean(ot->srna, "single_side", false, "Single Side", "");
907         RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
908         RNA_def_boolean(ot->srna, "use_even", false, "Even",
909                         "Make the edge loop match the shape of the adjacent edge loop");
910
911         WM_operatortype_props_advanced_begin(ot);
912
913         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
914                         "When Even mode is active, flips between the two adjacent edge loops");
915         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
916                         "Clamp within the edge extents");
917
918         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
919 }
920
921 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
922 {
923         /* identifiers */
924         ot->name   = "Vertex Slide";
925         ot->description = "Slide a vertex along a mesh";
926         ot->idname = OP_VERT_SLIDE;
927         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
928
929         /* api callbacks */
930         ot->invoke = transform_invoke;
931         ot->exec   = transform_exec;
932         ot->modal  = transform_modal;
933         ot->cancel = transform_cancel;
934         ot->poll   = ED_operator_editmesh_region_view3d;
935
936         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
937         RNA_def_boolean(ot->srna, "use_even", false, "Even",
938                         "Make the edge loop match the shape of the adjacent edge loop");
939
940         WM_operatortype_props_advanced_begin(ot);
941
942         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
943                         "When Even mode is active, flips between the two adjacent edge loops");
944         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
945                         "Clamp within the edge extents");
946
947         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
948 }
949
950 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
951 {
952         /* identifiers */
953         ot->name   = "Edge Crease";
954         ot->description = "Change the crease of edges";
955         ot->idname = OP_EDGE_CREASE;
956         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
957
958         /* api callbacks */
959         ot->invoke = transform_invoke;
960         ot->exec   = transform_exec;
961         ot->modal  = transform_modal;
962         ot->cancel = transform_cancel;
963         ot->poll   = ED_operator_editmesh;
964
965         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
966
967         WM_operatortype_props_advanced_begin(ot);
968
969         Transform_Properties(ot, P_SNAP);
970 }
971
972 static int edge_bevelweight_exec(bContext *C, wmOperator *op)
973 {
974         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
975
976         /* auto-enable bevel edge weight drawing, then chain to common transform code */
977         me->drawflag |= ME_DRAWBWEIGHTS;
978
979         return transform_exec(C, op);
980 }
981
982 static int edge_bevelweight_invoke(bContext *C, wmOperator *op, const wmEvent *event)
983 {
984         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
985
986         /* auto-enable bevel edge weight drawing, then chain to common transform code */
987         me->drawflag |= ME_DRAWBWEIGHTS;
988
989         return transform_invoke(C, op, event);
990 }
991
992
993 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
994 {
995         /* identifiers */
996         ot->name   = "Edge Bevel Weight";
997         ot->description = "Change the bevel weight of edges";
998         ot->idname = OP_EDGE_BWEIGHT;
999         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1000
1001         /* api callbacks */
1002         ot->invoke = edge_bevelweight_invoke;
1003         ot->exec   = edge_bevelweight_exec;
1004         ot->modal  = transform_modal;
1005         ot->cancel = transform_cancel;
1006         ot->poll   = ED_operator_editmesh;
1007
1008         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
1009
1010         WM_operatortype_props_advanced_begin(ot);
1011
1012         Transform_Properties(ot, P_SNAP);
1013 }
1014
1015 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
1016 {
1017         /* identifiers */
1018         ot->name   = "Sequence Slide";
1019         ot->description = "Slide a sequence strip in time";
1020         ot->idname = OP_SEQ_SLIDE;
1021         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1022
1023         /* api callbacks */
1024         ot->invoke = transform_invoke;
1025         ot->exec   = transform_exec;
1026         ot->modal  = transform_modal;
1027         ot->cancel = transform_cancel;
1028         ot->poll   = ED_operator_sequencer_active;
1029
1030         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
1031
1032         WM_operatortype_props_advanced_begin(ot);
1033
1034         Transform_Properties(ot, P_SNAP);
1035 }
1036
1037 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
1038 {
1039         PropertyRNA *prop;
1040
1041         /* identifiers */
1042         ot->name   = "Transform";
1043         ot->description = "Transform selected items by mode type";
1044         ot->idname = "TRANSFORM_OT_transform";
1045         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1046
1047         /* api callbacks */
1048         ot->invoke = transform_invoke;
1049         ot->exec   = transform_exec;
1050         ot->modal  = transform_modal;
1051         ot->cancel = transform_cancel;
1052         ot->poll   = ED_operator_screenactive;
1053
1054         prop = RNA_def_enum(ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
1055         RNA_def_property_flag(prop, PROP_HIDDEN);
1056
1057         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
1058
1059         WM_operatortype_props_advanced_begin(ot);
1060
1061         Transform_Properties(
1062                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT | P_CENTER);
1063 }
1064
1065 void transform_operatortypes(void)
1066 {
1067         TransformModeItem *tmode;
1068
1069         for (tmode = transform_modes; tmode->idname; tmode++) {
1070                 WM_operatortype_append(tmode->opfunc);
1071         }
1072
1073         WM_operatortype_append(TRANSFORM_OT_transform);
1074
1075         WM_operatortype_append(TRANSFORM_OT_select_orientation);
1076         WM_operatortype_append(TRANSFORM_OT_create_orientation);
1077         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
1078 }
1079
1080 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
1081 {
1082         wmKeyMapItem *kmi;
1083         wmKeyMap *modalmap;
1084
1085         /* transform.c, only adds modal map once, checks if it's there */
1086         modalmap = transform_modal_keymap(keyconf);
1087
1088         /* assign map to operators only the first time */
1089         if (modalmap) {
1090                 TransformModeItem *tmode;
1091
1092                 for (tmode = transform_modes; tmode->idname; tmode++) {
1093                         WM_modalkeymap_assign(modalmap, tmode->idname);
1094                 }
1095                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
1096         }
1097
1098         switch (spaceid) {
1099                 case SPACE_VIEW3D:
1100                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1101
1102                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1103
1104                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1105
1106                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1107
1108                         WM_keymap_add_item(keymap, OP_BEND, WKEY, KM_PRESS, KM_SHIFT, 0);
1109
1110                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
1111
1112                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1113
1114                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
1115
1116 #ifdef USE_WM_KEYMAP_27X
1117                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
1118                         RNA_boolean_set(kmi->ptr, "use", true);
1119 #endif
1120
1121                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
1122
1123                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1124                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1125
1126                         WM_keymap_add_panel(keymap, "VIEW3D_PT_snapping", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1127
1128                         /* Will fall-through to texture-space transform. */
1129                         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_transform_axis_target", TKEY, KM_PRESS, KM_SHIFT, 0);
1130
1131 #ifdef USE_WM_KEYMAP_27X
1132                         kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
1133                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1134
1135                         kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
1136                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1137 #endif
1138
1139                         WM_keymap_add_item(keymap, OP_SKIN_RESIZE, AKEY, KM_PRESS, KM_CTRL, 0);
1140
1141                         break;
1142                 case SPACE_ACTION:
1143                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1144                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1145
1146                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1147                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1148
1149                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1150                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1151
1152                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1153                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1154
1155                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
1156                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
1157                         break;
1158                 case SPACE_IPO:
1159                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1160
1161                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1162
1163                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1164                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1165
1166                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1167
1168                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1169                         break;
1170                 case SPACE_NLA:
1171                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1172                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1173
1174                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1175                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1176
1177                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1178                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1179
1180                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1181                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1182                         break;
1183                 case SPACE_NODE:
1184                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
1185                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
1186                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
1187                         /* NB: small trick: macro operator poll may fail due to library data edit,
1188                          * in that case the secondary regular operators are called with same keymap.
1189                          */
1190                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
1191                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1192                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
1193                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1194                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
1195                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1196
1197                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1198
1199                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1200
1201                         /* detach and translate */
1202                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", DKEY, KM_PRESS, KM_ALT, 0);
1203                         /* XXX release_confirm is set in the macro operator definition */
1204                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links_release", EVT_TWEAK_A, KM_ANY, KM_ALT, 0);
1205                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", EVT_TWEAK_S, KM_ANY, KM_ALT, 0);
1206
1207                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1208                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1209                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1210                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_node_element");
1211                         break;
1212                 case SPACE_SEQ:
1213                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
1214
1215                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
1216
1217                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1218                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1219                         break;
1220                 case SPACE_IMAGE:
1221                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1222
1223                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1224
1225                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1226
1227                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1228
1229                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1230
1231                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
1232
1233                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1234                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1235
1236                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1237                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_uv_element");
1238                         break;
1239                 case SPACE_CLIP:
1240                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1241                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1242                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1243                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1244                         break;
1245                 default:
1246                         break;
1247         }
1248 }