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