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