Cleanup: trailing space
[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_types.h"
49
50 #include "UI_interface.h"
51 #include "UI_resources.h"
52
53 #include "ED_screen.h"
54 /* for USE_LOOPSLIDE_HACK only */
55 #include "ED_mesh.h"
56
57 #include "transform.h"
58
59 typedef struct TransformModeItem {
60         const char *idname;
61         int mode;
62         void (*opfunc)(wmOperatorType *);
63 } TransformModeItem;
64
65 static const float VecOne[3] = {1, 1, 1};
66
67 static const char OP_TRANSLATION[] = "TRANSFORM_OT_translate";
68 static const char OP_ROTATION[] = "TRANSFORM_OT_rotate";
69 static const char OP_TOSPHERE[] = "TRANSFORM_OT_tosphere";
70 static const char OP_RESIZE[] = "TRANSFORM_OT_resize";
71 static const char OP_SKIN_RESIZE[] = "TRANSFORM_OT_skin_resize";
72 static const char OP_SHEAR[] = "TRANSFORM_OT_shear";
73 static const char OP_BEND[] = "TRANSFORM_OT_bend";
74 static const char OP_SHRINK_FATTEN[] = "TRANSFORM_OT_shrink_fatten";
75 static const char OP_PUSH_PULL[] = "TRANSFORM_OT_push_pull";
76 static const char OP_TILT[] = "TRANSFORM_OT_tilt";
77 static const char OP_TRACKBALL[] = "TRANSFORM_OT_trackball";
78 static const char OP_MIRROR[] = "TRANSFORM_OT_mirror";
79 static const char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide";
80 static const char OP_VERT_SLIDE[] = "TRANSFORM_OT_vert_slide";
81 static const char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease";
82 static const char OP_EDGE_BWEIGHT[] = "TRANSFORM_OT_edge_bevelweight";
83 static const char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide";
84
85 static void TRANSFORM_OT_translate(struct wmOperatorType *ot);
86 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot);
87 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot);
88 static void TRANSFORM_OT_resize(struct wmOperatorType *ot);
89 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot);
90 static void TRANSFORM_OT_shear(struct wmOperatorType *ot);
91 static void TRANSFORM_OT_bend(struct wmOperatorType *ot);
92 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot);
93 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot);
94 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot);
95 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot);
96 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot);
97 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot);
98 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot);
99 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot);
100 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot);
101 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot);
102
103 static TransformModeItem transform_modes[] =
104 {
105         {OP_TRANSLATION, TFM_TRANSLATION, TRANSFORM_OT_translate},
106         {OP_ROTATION, TFM_ROTATION, TRANSFORM_OT_rotate},
107         {OP_TOSPHERE, TFM_TOSPHERE, TRANSFORM_OT_tosphere},
108         {OP_RESIZE, TFM_RESIZE, TRANSFORM_OT_resize},
109         {OP_SKIN_RESIZE, TFM_SKIN_RESIZE, TRANSFORM_OT_skin_resize},
110         {OP_SHEAR, TFM_SHEAR, TRANSFORM_OT_shear},
111         {OP_BEND, TFM_BEND, TRANSFORM_OT_bend},
112         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN, TRANSFORM_OT_shrink_fatten},
113         {OP_PUSH_PULL, TFM_PUSHPULL, TRANSFORM_OT_push_pull},
114         {OP_TILT, TFM_TILT, TRANSFORM_OT_tilt},
115         {OP_TRACKBALL, TFM_TRACKBALL, TRANSFORM_OT_trackball},
116         {OP_MIRROR, TFM_MIRROR, TRANSFORM_OT_mirror},
117         {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide},
118         {OP_VERT_SLIDE, TFM_VERT_SLIDE, TRANSFORM_OT_vert_slide},
119         {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease},
120         {OP_EDGE_BWEIGHT, TFM_BWEIGHT, TRANSFORM_OT_edge_bevelweight},
121         {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide},
122         {NULL, 0}
123 };
124
125 const EnumPropertyItem rna_enum_transform_mode_types[] =
126 {
127         {TFM_INIT, "INIT", 0, "Init", ""},
128         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
129         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
130         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
131         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
132         {TFM_SKIN_RESIZE, "SKIN_RESIZE", 0, "Skin Resize", ""},
133         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
134         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
135         {TFM_BEND, "BEND", 0, "Bend", ""},
136         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
137         {TFM_TILT, "TILT", 0, "Tilt", ""},
138         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
139         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
140         {TFM_CREASE, "CREASE", 0, "Crease", ""},
141         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
142         {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
143         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
144         {TFM_BONE_ENVELOPE_DIST, "BONE_ENVELOPE_DIST", 0, "Bone_Envelope_Distance", ""},
145         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
146         {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""},
147         {TFM_GPENCIL_SHRINKFATTEN, "GPENCIL_SHRINKFATTEN", 0, "GPencil_Shrinkfatten", ""},
148         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
149         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
150         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
151         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
152         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
153         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
154         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
155         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
156         {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
157         {TFM_SEQ_SLIDE, "SEQSLIDE", 0, "Sequence Slide", ""},
158         {0, NULL, 0, NULL, NULL}
159 };
160
161 static int select_orientation_exec(bContext *C, wmOperator *op)
162 {
163         int orientation = RNA_enum_get(op->ptr, "orientation");
164
165         BIF_selectTransformOrientationValue(C, orientation);
166
167         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
168
169         return OPERATOR_FINISHED;
170 }
171
172 static int select_orientation_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
173 {
174         uiPopupMenu *pup;
175         uiLayout *layout;
176
177         pup = UI_popup_menu_begin(C, IFACE_("Orientation"), ICON_NONE);
178         layout = UI_popup_menu_layout(pup);
179         uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
180         UI_popup_menu_end(C, pup);
181
182         return OPERATOR_INTERFACE;
183 }
184
185 static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
186 {
187         PropertyRNA *prop;
188
189         /* identifiers */
190         ot->name   = "Select Orientation";
191         ot->description = "Select transformation orientation";
192         ot->idname = "TRANSFORM_OT_select_orientation";
193         ot->flag   = OPTYPE_UNDO;
194
195         /* api callbacks */
196         ot->invoke = select_orientation_invoke;
197         ot->exec   = select_orientation_exec;
198         ot->poll   = ED_operator_view3d_active;
199
200         prop = RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
201         RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
202         RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
203 }
204
205
206 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
207 {
208         View3D *v3d = CTX_wm_view3d(C);
209         int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
210
211         BIF_removeTransformOrientationIndex(C, selected_index);
212
213         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
214         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
215
216         return OPERATOR_FINISHED;
217 }
218
219 static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
220 {
221         return delete_orientation_exec(C, op);
222 }
223
224 static int delete_orientation_poll(bContext *C)
225 {
226         int selected_index = -1;
227         View3D *v3d = CTX_wm_view3d(C);
228
229         if (ED_operator_areaactive(C) == 0)
230                 return 0;
231
232
233         if (v3d) {
234                 selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
235         }
236
237         return selected_index >= 0;
238 }
239
240 static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
241 {
242         /* identifiers */
243         ot->name   = "Delete Orientation";
244         ot->description = "Delete transformation orientation";
245         ot->idname = "TRANSFORM_OT_delete_orientation";
246         ot->flag   = OPTYPE_UNDO;
247
248         /* api callbacks */
249         ot->invoke = delete_orientation_invoke;
250         ot->exec   = delete_orientation_exec;
251         ot->poll   = delete_orientation_poll;
252 }
253
254 static int create_orientation_exec(bContext *C, wmOperator *op)
255 {
256         char name[MAX_NAME];
257         const bool use = RNA_boolean_get(op->ptr, "use");
258         const bool overwrite = RNA_boolean_get(op->ptr, "overwrite");
259         const bool use_view = RNA_boolean_get(op->ptr, "use_view");
260         View3D *v3d = CTX_wm_view3d(C);
261
262         RNA_string_get(op->ptr, "name", name);
263
264         if (use && !v3d) {
265                 BKE_report(op->reports, RPT_ERROR, "Create Orientation's 'use' parameter only valid in a 3DView context");
266                 return OPERATOR_CANCELLED;
267         }
268
269         BIF_createTransformOrientation(C, op->reports, name, use_view, use, overwrite);
270
271         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
272         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
273
274         return OPERATOR_FINISHED;
275 }
276
277 static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
278 {
279         /* identifiers */
280         ot->name   = "Create Orientation";
281         ot->description = "Create transformation orientation from selection";
282         ot->idname = "TRANSFORM_OT_create_orientation";
283         ot->flag   = OPTYPE_REGISTER | OPTYPE_UNDO;
284
285         /* api callbacks */
286         ot->exec   = create_orientation_exec;
287         ot->poll   = ED_operator_areaactive;
288
289         RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the new custom orientation");
290         RNA_def_boolean(ot->srna, "use_view", false, "Use View",
291                         "Use the current view instead of the active object to create the new orientation");
292         RNA_def_boolean(ot->srna, "use", false, "Use after creation", "Select orientation after its creation");
293         RNA_def_boolean(ot->srna, "overwrite", false, "Overwrite previous",
294                         "Overwrite previously created orientation with same name");
295 }
296
297
298 #ifdef USE_LOOPSLIDE_HACK
299 /**
300  * Special hack for MESH_OT_loopcut_slide so we get back to the selection mode
301  */
302 static void transformops_loopsel_hack(bContext *C, wmOperator *op)
303 {
304         if (op->type->idname == OP_EDGE_SLIDE) {
305                 if (op->opm && op->opm->opm && op->opm->opm->prev) {
306                         wmOperator *op_prev = op->opm->opm->prev;
307                         Scene *scene = CTX_data_scene(C);
308                         int mesh_select_mode[3];
309                         PropertyRNA *prop = RNA_struct_find_property(op_prev->ptr, "mesh_select_mode_init");
310
311                         if (prop && RNA_property_is_set(op_prev->ptr, prop)) {
312                                 ToolSettings *ts = scene->toolsettings;
313                                 short selectmode_orig;
314
315                                 RNA_property_boolean_get_array(op_prev->ptr, prop, mesh_select_mode);
316                                 selectmode_orig = ((mesh_select_mode[0] ? SCE_SELECT_VERTEX : 0) |
317                                                    (mesh_select_mode[1] ? SCE_SELECT_EDGE   : 0) |
318                                                    (mesh_select_mode[2] ? SCE_SELECT_FACE   : 0));
319
320                                 /* still switch if we were originally in face select mode */
321                                 if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
322                                         BMEditMesh *em = BKE_editmesh_from_object(scene->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         if (RNA_struct_property_is_set(op->ptr, "value")) {
487                 return transform_exec(C, op);
488         }
489         else {
490                 /* add temp handler */
491                 WM_event_add_modal_handler(C, op);
492
493                 op->flag |= OP_IS_MODAL_GRAB_CURSOR; // XXX maybe we want this with the manipulator only?
494                 return OPERATOR_RUNNING_MODAL;
495         }
496 }
497
498 void Transform_Properties(struct wmOperatorType *ot, int flags)
499 {
500         PropertyRNA *prop;
501
502         if (flags & P_AXIS) {
503                 prop = RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
504                 RNA_def_property_array(prop, 3);
505                 /* Make this not hidden when there's a nice axis selection widget */
506                 RNA_def_property_flag(prop, PROP_HIDDEN);
507                 RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
508         }
509
510         if (flags & P_CONSTRAINT) {
511                 RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
512                 prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
513                 RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
514                 RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
515         }
516
517         if (flags & P_MIRROR) {
518                 prop = RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
519                 if (flags & P_MIRROR_DUMMY) {
520                         /* only used so macros can disable this option */
521                         RNA_def_property_flag(prop, PROP_HIDDEN);
522                 }
523         }
524
525
526         if (flags & P_PROPORTIONAL) {
527                 RNA_def_enum(ot->srna, "proportional", rna_enum_proportional_editing_items, 0, "Proportional Editing", "");
528                 prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", rna_enum_proportional_falloff_items, 0,
529                                     "Proportional Editing Falloff", "Falloff type for proportional editing mode");
530                 RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
531                 RNA_def_float(ot->srna, "proportional_size", 1, T_PROP_SIZE_MIN, T_PROP_SIZE_MAX,
532                               "Proportional Size", "", 0.001f, 100.0f);
533         }
534
535         if (flags & P_SNAP) {
536                 prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
537                 RNA_def_property_flag(prop, PROP_HIDDEN);
538
539                 if (flags & P_GEO_SNAP) {
540                         prop = RNA_def_enum(ot->srna, "snap_target", rna_enum_snap_target_items, 0, "Target", "");
541                         RNA_def_property_flag(prop, PROP_HIDDEN);
542                         prop = RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
543                         RNA_def_property_flag(prop, PROP_HIDDEN);
544
545                         if (flags & P_ALIGN_SNAP) {
546                                 prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
547                                 RNA_def_property_flag(prop, PROP_HIDDEN);
548                                 prop = RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
549                                 RNA_def_property_flag(prop, PROP_HIDDEN);
550                         }
551                 }
552         }
553
554         if (flags & P_GPENCIL_EDIT) {
555                 RNA_def_boolean(ot->srna, "gpencil_strokes", 0, "Edit Grease Pencil", "Edit selected Grease Pencil strokes");
556         }
557
558         if ((flags & P_OPTIONS) && !(flags & P_NO_TEXSPACE)) {
559                 RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
560                 prop = RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
561                 RNA_def_property_flag(prop, PROP_HIDDEN);
562         }
563
564         if (flags & P_CORRECT_UV) {
565                 RNA_def_boolean(ot->srna, "correct_uv", 0, "Correct UVs", "Correct UV coordinates when transforming");
566         }
567
568         if (flags & P_CENTER) {
569                 /* For manipulators that define their own center. */
570                 prop = RNA_def_property(ot->srna, "center_override", PROP_FLOAT, PROP_XYZ);
571                 RNA_def_property_array(prop, 3);
572                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
573                 RNA_def_property_ui_text(prop, "Center Override", "Force using this center value (when set)");
574         }
575
576         if ((flags & P_NO_DEFAULTS) == 0) {
577                 prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
578                 RNA_def_property_flag(prop, PROP_HIDDEN);
579
580                 prop = RNA_def_boolean(ot->srna, "use_accurate", 0, "Accurate", "Use accurate transformation");
581                 RNA_def_property_flag(prop, PROP_HIDDEN);
582         }
583 }
584
585 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
586 {
587         /* identifiers */
588         ot->name   = "Translate";
589         ot->description = "Translate (move) selected items";
590         ot->idname = OP_TRANSLATION;
591         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
592
593         /* api callbacks */
594         ot->invoke = transform_invoke;
595         ot->exec   = transform_exec;
596         ot->modal  = transform_modal;
597         ot->cancel = transform_cancel;
598         ot->poll   = ED_operator_screenactive;
599
600         RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
601
602         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
603 }
604
605 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
606 {
607         /* identifiers */
608         ot->name   = "Resize";
609         ot->description = "Scale (resize) selected items";
610         ot->idname = OP_RESIZE;
611         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
612
613         /* api callbacks */
614         ot->invoke = transform_invoke;
615         ot->exec   = transform_exec;
616         ot->modal  = transform_modal;
617         ot->cancel = transform_cancel;
618         ot->poll   = ED_operator_screenactive;
619
620         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
621
622         Transform_Properties(
623                 ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CENTER);
624 }
625
626 static int skin_resize_poll(bContext *C)
627 {
628         struct Object *obedit = CTX_data_edit_object(C);
629         if (obedit && obedit->type == OB_MESH) {
630                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
631                 return (em && CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN));
632         }
633         return 0;
634 }
635
636 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
637 {
638         /* identifiers */
639         ot->name   = "Skin Resize";
640         ot->description = "Scale selected vertices' skin radii";
641         ot->idname = OP_SKIN_RESIZE;
642         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
643
644         /* api callbacks */
645         ot->invoke = transform_invoke;
646         ot->exec   = transform_exec;
647         ot->modal  = transform_modal;
648         ot->cancel = transform_cancel;
649         ot->poll   = skin_resize_poll;
650
651         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
652
653         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
654 }
655
656 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
657 {
658         /* identifiers */
659         ot->name   = "Trackball";
660         ot->description = "Trackball style rotation of selected items";
661         ot->idname = OP_TRACKBALL;
662         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
663
664         /* api callbacks */
665         ot->invoke = transform_invoke;
666         ot->exec   = transform_exec;
667         ot->modal  = transform_modal;
668         ot->cancel = transform_cancel;
669         ot->poll   = ED_operator_screenactive;
670
671         /* Maybe we could use float_vector_xyz here too? */
672         RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
673
674         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
675 }
676
677 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
678 {
679         /* identifiers */
680         ot->name = "Rotate";
681         ot->description = "Rotate selected items";
682         ot->idname = OP_ROTATION;
683         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
684
685         /* api callbacks */
686         ot->invoke = transform_invoke;
687         ot->exec   = transform_exec;
688         ot->modal  = transform_modal;
689         ot->cancel = transform_cancel;
690         ot->poll   = ED_operator_screenactive;
691
692         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
693
694         Transform_Properties(
695                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT | P_CENTER);
696 }
697
698 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
699 {
700         /* identifiers */
701         ot->name = "Tilt";
702         /* optional -
703          * "Tilt selected vertices"
704          * "Specify an extra axis rotation for selected vertices of 3D curve" */
705         ot->description = "Tilt selected control vertices of 3D curve";
706         ot->idname = OP_TILT;
707         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
708
709         /* api callbacks */
710         ot->invoke = transform_invoke;
711         ot->exec   = transform_exec;
712         ot->modal  = transform_modal;
713         ot->cancel = transform_cancel;
714         ot->poll   = ED_operator_editcurve_3d;
715
716         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
717
718         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
719 }
720
721 static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
722 {
723         /* identifiers */
724         ot->name   = "Bend";
725         ot->description = "Bend selected items between the 3D cursor and the mouse";
726         ot->idname = OP_BEND;
727         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
728
729         /* api callbacks */
730         ot->invoke = transform_invoke;
731         // ot->exec   = transform_exec;  // unsupported
732         ot->modal  = transform_modal;
733         ot->cancel = transform_cancel;
734         ot->poll   = ED_operator_region_view3d_active;
735
736         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
737
738         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
739 }
740
741 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
742 {
743         /* identifiers */
744         ot->name   = "Shear";
745         ot->description = "Shear selected items along the horizontal screen axis";
746         ot->idname = OP_SHEAR;
747         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
748
749         /* api callbacks */
750         ot->invoke = transform_invoke;
751         ot->exec   = transform_exec;
752         ot->modal  = transform_modal;
753         ot->cancel = transform_cancel;
754         ot->poll   = ED_operator_screenactive;
755
756         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
757
758         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
759         // XXX Shear axis?
760 }
761
762 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
763 {
764         /* identifiers */
765         ot->name   = "Push/Pull";
766         ot->description = "Push/Pull selected items";
767         ot->idname = OP_PUSH_PULL;
768         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
769
770         /* api callbacks */
771         ot->invoke = transform_invoke;
772         ot->exec   = transform_exec;
773         ot->modal  = transform_modal;
774         ot->cancel = transform_cancel;
775         ot->poll   = ED_operator_screenactive;
776
777         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
778
779         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_CENTER);
780 }
781
782 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
783 {
784         /* identifiers */
785         ot->name   = "Shrink/Fatten";
786         ot->description = "Shrink/fatten selected vertices along normals";
787         ot->idname = OP_SHRINK_FATTEN;
788         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
789
790         /* api callbacks */
791         ot->invoke = transform_invoke;
792         ot->exec   = transform_exec;
793         ot->modal  = transform_modal;
794         ot->cancel = transform_cancel;
795         ot->poll   = ED_operator_editmesh;
796
797         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
798
799         RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness");
800
801         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
802 }
803
804 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
805 {
806         /* identifiers */
807         ot->name   = "To Sphere";
808         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()"
809         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
810         ot->idname = OP_TOSPHERE;
811         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
812
813         /* api callbacks */
814         ot->invoke = transform_invoke;
815         ot->exec   = transform_exec;
816         ot->modal  = transform_modal;
817         ot->cancel = transform_cancel;
818         ot->poll   = ED_operator_screenactive;
819
820         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
821
822         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
823 }
824
825 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
826 {
827         /* identifiers */
828         ot->name   = "Mirror";
829         ot->description = "Mirror selected items around one or more axes";
830         ot->idname = OP_MIRROR;
831         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
832
833         /* api callbacks */
834         ot->invoke = transform_invoke;
835         ot->exec   = transform_exec;
836         ot->modal  = transform_modal;
837         ot->cancel = transform_cancel;
838         ot->poll   = ED_operator_screenactive;
839
840         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_GPENCIL_EDIT | P_CENTER);
841 }
842
843 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
844 {
845         PropertyRNA *prop;
846
847         /* identifiers */
848         ot->name   = "Edge Slide";
849         ot->description = "Slide an edge loop along a mesh";
850         ot->idname = OP_EDGE_SLIDE;
851         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
852
853         /* api callbacks */
854         ot->invoke = transform_invoke;
855         ot->exec   = transform_exec;
856         ot->modal  = transform_modal;
857         ot->cancel = transform_cancel;
858         ot->poll   = ED_operator_editmesh_region_view3d;
859
860         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
861
862         prop = RNA_def_boolean(ot->srna, "single_side", false, "Single Side", "");
863         RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
864         RNA_def_boolean(ot->srna, "use_even", false, "Even",
865                         "Make the edge loop match the shape of the adjacent edge loop");
866         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
867                         "When Even mode is active, flips between the two adjacent edge loops");
868         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
869                         "Clamp within the edge extents");
870
871         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
872 }
873
874 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
875 {
876         /* identifiers */
877         ot->name   = "Vertex Slide";
878         ot->description = "Slide a vertex along a mesh";
879         ot->idname = OP_VERT_SLIDE;
880         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
881
882         /* api callbacks */
883         ot->invoke = transform_invoke;
884         ot->exec   = transform_exec;
885         ot->modal  = transform_modal;
886         ot->cancel = transform_cancel;
887         ot->poll   = ED_operator_editmesh_region_view3d;
888
889         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
890         RNA_def_boolean(ot->srna, "use_even", false, "Even",
891                         "Make the edge loop match the shape of the adjacent edge loop");
892         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
893                         "When Even mode is active, flips between the two adjacent edge loops");
894         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
895                         "Clamp within the edge extents");
896
897         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
898 }
899
900 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
901 {
902         /* identifiers */
903         ot->name   = "Edge Crease";
904         ot->description = "Change the crease of edges";
905         ot->idname = OP_EDGE_CREASE;
906         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
907
908         /* api callbacks */
909         ot->invoke = transform_invoke;
910         ot->exec   = transform_exec;
911         ot->modal  = transform_modal;
912         ot->cancel = transform_cancel;
913         ot->poll   = ED_operator_editmesh;
914
915         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
916
917         Transform_Properties(ot, P_SNAP);
918 }
919
920 static int edge_bevelweight_exec(bContext *C, wmOperator *op)
921 {
922         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
923
924         /* auto-enable bevel edge weight drawing, then chain to common transform code */
925         me->drawflag |= ME_DRAWBWEIGHTS;
926
927         return transform_exec(C, op);
928 }
929
930 static int edge_bevelweight_invoke(bContext *C, wmOperator *op, const wmEvent *event)
931 {
932         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
933
934         /* auto-enable bevel edge weight drawing, then chain to common transform code */
935         me->drawflag |= ME_DRAWBWEIGHTS;
936
937         return transform_invoke(C, op, event);
938 }
939
940
941 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
942 {
943         /* identifiers */
944         ot->name   = "Edge Bevel Weight";
945         ot->description = "Change the bevel weight of edges";
946         ot->idname = OP_EDGE_BWEIGHT;
947         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
948
949         /* api callbacks */
950         ot->invoke = edge_bevelweight_invoke;
951         ot->exec   = edge_bevelweight_exec;
952         ot->modal  = transform_modal;
953         ot->cancel = transform_cancel;
954         ot->poll   = ED_operator_editmesh;
955
956         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
957
958         Transform_Properties(ot, P_SNAP);
959 }
960
961 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
962 {
963         /* identifiers */
964         ot->name   = "Sequence Slide";
965         ot->description = "Slide a sequence strip in time";
966         ot->idname = OP_SEQ_SLIDE;
967         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
968
969         /* api callbacks */
970         ot->invoke = transform_invoke;
971         ot->exec   = transform_exec;
972         ot->modal  = transform_modal;
973         ot->cancel = transform_cancel;
974         ot->poll   = ED_operator_sequencer_active;
975
976         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
977
978         Transform_Properties(ot, P_SNAP);
979 }
980
981 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
982 {
983         PropertyRNA *prop;
984
985         /* identifiers */
986         ot->name   = "Transform";
987         ot->description = "Transform selected items by mode type";
988         ot->idname = "TRANSFORM_OT_transform";
989         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
990
991         /* api callbacks */
992         ot->invoke = transform_invoke;
993         ot->exec   = transform_exec;
994         ot->modal  = transform_modal;
995         ot->cancel = transform_cancel;
996         ot->poll   = ED_operator_screenactive;
997
998         prop = RNA_def_enum(ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
999         RNA_def_property_flag(prop, PROP_HIDDEN);
1000
1001         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
1002
1003         Transform_Properties(
1004                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT | P_CENTER);
1005 }
1006
1007 void transform_operatortypes(void)
1008 {
1009         TransformModeItem *tmode;
1010
1011         for (tmode = transform_modes; tmode->idname; tmode++) {
1012                 WM_operatortype_append(tmode->opfunc);
1013         }
1014
1015         WM_operatortype_append(TRANSFORM_OT_transform);
1016
1017         WM_operatortype_append(TRANSFORM_OT_select_orientation);
1018         WM_operatortype_append(TRANSFORM_OT_create_orientation);
1019         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
1020 }
1021
1022 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
1023 {
1024         wmKeyMapItem *kmi;
1025         wmKeyMap *modalmap;
1026
1027         /* transform.c, only adds modal map once, checks if it's there */
1028         modalmap = transform_modal_keymap(keyconf);
1029
1030         /* assign map to operators only the first time */
1031         if (modalmap) {
1032                 TransformModeItem *tmode;
1033
1034                 for (tmode = transform_modes; tmode->idname; tmode++) {
1035                         WM_modalkeymap_assign(modalmap, tmode->idname);
1036                 }
1037                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
1038         }
1039
1040         switch (spaceid) {
1041                 case SPACE_VIEW3D:
1042                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1043
1044                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1045
1046                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1047
1048                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1049
1050                         WM_keymap_add_item(keymap, OP_BEND, WKEY, KM_PRESS, KM_SHIFT, 0);
1051
1052                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
1053
1054                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1055
1056                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
1057
1058                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
1059                         RNA_boolean_set(kmi->ptr, "use", true);
1060
1061                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
1062
1063                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1064                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1065
1066                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1067                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_element");
1068
1069
1070                         kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
1071                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1072
1073                         kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
1074                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1075
1076                         WM_keymap_add_item(keymap, OP_SKIN_RESIZE, AKEY, KM_PRESS, KM_CTRL, 0);
1077
1078                         break;
1079                 case SPACE_ACTION:
1080                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1081                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1082
1083                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1084                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1085
1086                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1087                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1088
1089                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1090                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1091
1092                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
1093                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
1094                         break;
1095                 case SPACE_IPO:
1096                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1097
1098                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1099
1100                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1101                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1102
1103                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1104
1105                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1106                         break;
1107                 case SPACE_NLA:
1108                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1109                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1110
1111                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1112                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1113
1114                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1115                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1116
1117                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1118                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1119                         break;
1120                 case SPACE_NODE:
1121                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
1122                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
1123                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
1124                         /* NB: small trick: macro operator poll may fail due to library data edit,
1125                          * in that case the secondary regular operators are called with same keymap.
1126                          */
1127                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
1128                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1129                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
1130                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1131                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
1132                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1133
1134                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1135
1136                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1137
1138                         /* detach and translate */
1139                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", DKEY, KM_PRESS, KM_ALT, 0);
1140                         /* XXX release_confirm is set in the macro operator definition */
1141                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links_release", EVT_TWEAK_A, KM_ANY, KM_ALT, 0);
1142                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", EVT_TWEAK_S, KM_ANY, KM_ALT, 0);
1143
1144                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1145                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1146                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1147                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_node_element");
1148                         break;
1149                 case SPACE_SEQ:
1150                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
1151
1152                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
1153
1154                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1155                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1156                         break;
1157                 case SPACE_IMAGE:
1158                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1159
1160                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1161
1162                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1163
1164                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1165
1166                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1167
1168                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
1169
1170                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1171                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1172
1173                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1174                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_uv_element");
1175                         break;
1176                 case SPACE_CLIP:
1177                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1178                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1179                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1180                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1181                         break;
1182                 default:
1183                         break;
1184         }
1185 }
1186