Merging r57695 through r57725 from trunk into soc-2013-desgraph_mt
[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_armature.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 #include "ED_mesh.h"
54
55 #include "transform.h"
56
57 typedef struct TransformModeItem {
58         char *idname;
59         int mode;
60         void (*opfunc)(wmOperatorType *);
61 } TransformModeItem;
62
63 static 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_WARP[] = "TRANSFORM_OT_warp";
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_warp(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_WARP, TFM_WARP, TRANSFORM_OT_warp},
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_WARP, "WARP", 0, "Warp", ""},
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, CTX_wm_view3d(C));
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         int use = RNA_boolean_get(op->ptr, "use");
254         int overwrite = RNA_boolean_get(op->ptr, "overwrite");
255         int use_view = RNA_boolean_get(op->ptr, "use_view");
256
257         RNA_string_get(op->ptr, "name", name);
258
259         if (use && !CTX_wm_view3d(C)) {
260                 BKE_report(op->reports, RPT_ERROR, "Create Orientation's 'use' parameter only valid in a 3DView context");
261                 return OPERATOR_CANCELLED;
262         }
263
264         BIF_createTransformOrientation(C, op->reports, name, use_view, use, overwrite);
265
266         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
267         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
268         
269         return OPERATOR_FINISHED;
270 }
271
272 static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
273 {
274         /* identifiers */
275         ot->name   = "Create Orientation";
276         ot->description = "Create transformation orientation from selection";
277         ot->idname = "TRANSFORM_OT_create_orientation";
278         ot->flag   = OPTYPE_REGISTER | OPTYPE_UNDO;
279
280         /* api callbacks */
281         ot->exec   = create_orientation_exec;
282         ot->poll   = ED_operator_areaactive;
283
284         RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the new custom orientation");
285         RNA_def_boolean(ot->srna, "use_view", FALSE, "Use View",
286                         "Use the current view instead of the active object to create the new orientation");
287         RNA_def_boolean(ot->srna, "use", FALSE, "Use after creation", "Select orientation after its creation");
288         RNA_def_boolean(ot->srna, "overwrite", FALSE, "Overwrite previous",
289                         "Overwrite previously created orientation with same name");
290 }
291
292
293 #ifdef USE_LOOPSLIDE_HACK
294 /**
295  * Special hack for MESH_OT_loopcut_slide so we get back to the selection mode
296  */
297 static void transformops_loopsel_hack(bContext *C, wmOperator *op)
298 {
299         if (op->type->idname == OP_EDGE_SLIDE) {
300                 if (op->opm && op->opm->opm && op->opm->opm->prev) {
301                         wmOperator *op_prev = op->opm->opm->prev;
302                         Scene *scene = CTX_data_scene(C);
303                         int mesh_select_mode[3];
304                         PropertyRNA *prop = RNA_struct_find_property(op_prev->ptr, "mesh_select_mode_init");
305
306                         if (prop && RNA_property_is_set(op_prev->ptr, prop)) {
307                                 ToolSettings *ts = scene->toolsettings;
308                                 short selectmode_orig;
309
310                                 RNA_property_boolean_get_array(op_prev->ptr, prop, mesh_select_mode);
311                                 selectmode_orig = ((mesh_select_mode[0] ? SCE_SELECT_VERTEX : 0) |
312                                                    (mesh_select_mode[1] ? SCE_SELECT_EDGE   : 0) |
313                                                    (mesh_select_mode[2] ? SCE_SELECT_FACE   : 0));
314
315                                 /* still switch if we were originally in face select mode */
316                                 if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
317                                         BMEditMesh *em = BKE_editmesh_from_object(scene->obedit);
318                                         em->selectmode = ts->selectmode = selectmode_orig;
319                                         EDBM_selectmode_set(em);
320                                 }
321                         }
322                 }
323         }
324 }
325 #endif  /* USE_LOOPSLIDE_HACK */
326
327
328 static void transformops_exit(bContext *C, wmOperator *op)
329 {
330 #ifdef USE_LOOPSLIDE_HACK
331         transformops_loopsel_hack(C, op);
332 #endif
333
334         saveTransform(C, op->customdata, op);
335         MEM_freeN(op->customdata);
336         op->customdata = NULL;
337         G.moving = 0;
338 }
339
340 static int transformops_data(bContext *C, wmOperator *op, const wmEvent *event)
341 {
342         int retval = 1;
343         if (op->customdata == NULL) {
344                 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
345                 TransformModeItem *tmode;
346                 int mode = -1;
347
348                 for (tmode = transform_modes; tmode->idname; tmode++) {
349                         if (op->type->idname == tmode->idname) {
350                                 mode = tmode->mode;
351                                 break;
352                         }
353                 }
354
355                 if (mode == -1) {
356                         mode = RNA_enum_get(op->ptr, "mode");
357                 }
358
359                 retval = initTransform(C, t, op, event, mode);
360
361                 /* store data */
362                 if (retval) {
363                         G.moving = special_transform_moving(t);
364                         op->customdata = t;
365                 }
366                 else {
367                         MEM_freeN(t);
368                 }
369         }
370
371         return retval; /* return 0 on error */
372 }
373
374 static int transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
375 {
376         int exit_code;
377
378         TransInfo *t = op->customdata;
379         const enum TfmMode mode_prev = t->mode;
380
381 #if 0
382         // stable 2D mouse coords map to different 3D coords while the 3D mouse is active
383         // in other words, 2D deltas are no longer good enough!
384         // disable until individual 'transformers' behave better
385
386         if (event->type == NDOF_MOTION)
387                 return OPERATOR_PASS_THROUGH;
388 #endif
389
390         /* XXX insert keys are called here, and require context */
391         t->context = C;
392         exit_code = transformEvent(t, event);
393         t->context = NULL;
394
395         transformApply(C, t);
396
397         exit_code |= transformEnd(C, t);
398
399         if ((exit_code & OPERATOR_RUNNING_MODAL) == 0) {
400                 transformops_exit(C, op);
401                 exit_code &= ~OPERATOR_PASS_THROUGH; /* preventively remove passthrough */
402         }
403         else {
404                 if (mode_prev != t->mode) {
405                         /* WARNING: this is not normal to switch operator types
406                          * normally it would not be supported but transform happens
407                          * to share callbacks between differernt operators. */
408                         wmOperatorType *ot_new = NULL;
409                         TransformModeItem *item = transform_modes;
410                         while (item->idname) {
411                                 if (item->mode == t->mode) {
412                                         ot_new = WM_operatortype_find(item->idname, false);
413                                         break;
414                                 }
415                                 item++;
416                         }
417
418                         BLI_assert(ot_new != NULL);
419                         if (ot_new) {
420                                 WM_operator_type_set(op, ot_new);
421                         }
422                         /* end suspicious code */
423                 }
424         }
425
426         return exit_code;
427 }
428
429 static int transform_cancel(bContext *C, wmOperator *op)
430 {
431         TransInfo *t = op->customdata;
432
433         t->state = TRANS_CANCEL;
434         transformEnd(C, t);
435         transformops_exit(C, op);
436
437         return OPERATOR_CANCELLED;
438 }
439
440 static int transform_exec(bContext *C, wmOperator *op)
441 {
442         TransInfo *t;
443
444         if (!transformops_data(C, op, NULL)) {
445                 G.moving = 0;
446                 return OPERATOR_CANCELLED;
447         }
448
449         t = op->customdata;
450
451         t->options |= CTX_AUTOCONFIRM;
452
453         transformApply(C, t);
454
455         transformEnd(C, t);
456
457         transformops_exit(C, op);
458         
459         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
460
461         return OPERATOR_FINISHED;
462 }
463
464 static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
465 {
466         if (!transformops_data(C, op, event)) {
467                 G.moving = 0;
468                 return OPERATOR_CANCELLED;
469         }
470
471         if (RNA_struct_property_is_set(op->ptr, "value")) {
472                 return transform_exec(C, op);
473         }
474         else {
475                 /* add temp handler */
476                 WM_event_add_modal_handler(C, op);
477
478                 op->flag |= OP_GRAB_POINTER; // XXX maybe we want this with the manipulator only?
479                 return OPERATOR_RUNNING_MODAL;
480         }
481 }
482
483 void Transform_Properties(struct wmOperatorType *ot, int flags)
484 {
485         PropertyRNA *prop;
486
487         if (flags & P_AXIS) {
488                 prop = RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
489                 RNA_def_property_array(prop, 3);
490                 /* Make this not hidden when there's a nice axis selection widget */
491                 RNA_def_property_flag(prop, PROP_HIDDEN);
492                 RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
493         }
494
495         if (flags & P_CONSTRAINT) {
496                 RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
497                 prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
498                 RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
499                 RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
500         }
501
502         if (flags & P_MIRROR) {
503                 prop = RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
504                 if (flags & P_MIRROR_DUMMY) {
505                         /* only used so macros can disable this option */
506                         RNA_def_property_flag(prop, PROP_HIDDEN);
507                 }
508         }
509
510
511         if (flags & P_PROPORTIONAL) {
512                 RNA_def_enum(ot->srna, "proportional", proportional_editing_items, 0, "Proportional Editing", "");
513                 prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", proportional_falloff_items, 0,
514                                     "Proportional Editing Falloff", "Falloff type for proportional editing mode");
515                 RNA_def_property_translation_context(prop, BLF_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
516                 RNA_def_float(ot->srna, "proportional_size", 1, 0.00001f, FLT_MAX, "Proportional Size", "", 0.001, 100);
517         }
518
519         if (flags & P_SNAP) {
520                 prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
521                 RNA_def_property_flag(prop, PROP_HIDDEN);
522
523                 if (flags & P_GEO_SNAP) {
524                         prop = RNA_def_enum(ot->srna, "snap_target", snap_target_items, 0, "Target", "");
525                         RNA_def_property_flag(prop, PROP_HIDDEN);
526                         prop = RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
527                         RNA_def_property_flag(prop, PROP_HIDDEN);
528                         
529                         if (flags & P_ALIGN_SNAP) {
530                                 prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
531                                 RNA_def_property_flag(prop, PROP_HIDDEN);
532                                 prop = RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
533                                 RNA_def_property_flag(prop, PROP_HIDDEN);
534                         }
535                 }
536         }
537
538         if (flags & P_OPTIONS) {
539                 RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
540         }
541
542         if (flags & P_CORRECT_UV) {
543                 RNA_def_boolean(ot->srna, "correct_uv", 0, "Correct UVs", "Correct UV coordinates when transforming");
544         }
545
546         if ((flags & P_NO_DEFAULTS) == 0) {
547                 // 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
548                 /*prop =*/ RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
549                 //RNA_def_property_flag(prop, PROP_HIDDEN);
550         }
551 }
552
553 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
554 {
555         /* identifiers */
556         ot->name   = "Translate";
557         ot->description = "Translate (move) selected items";
558         ot->idname = OP_TRANSLATION;
559         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
560
561         /* api callbacks */
562         ot->invoke = transform_invoke;
563         ot->exec   = transform_exec;
564         ot->modal  = transform_modal;
565         ot->cancel = transform_cancel;
566         ot->poll   = ED_operator_screenactive;
567
568         RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
569
570         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS);
571 }
572
573 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
574 {
575         /* identifiers */
576         ot->name   = "Resize";
577         ot->description = "Scale (resize) selected items"; 
578         ot->idname = OP_RESIZE;
579         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
580
581         /* api callbacks */
582         ot->invoke = transform_invoke;
583         ot->exec   = transform_exec;
584         ot->modal  = transform_modal;
585         ot->cancel = transform_cancel;
586         ot->poll   = ED_operator_screenactive;
587
588         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
589
590         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS);
591 }
592
593 static int skin_resize_poll(bContext *C)
594 {
595         struct Object *obedit = CTX_data_edit_object(C);
596         if (obedit && obedit->type == OB_MESH) {
597                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
598                 return (em && CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN));
599         }
600         return 0;
601 }
602
603 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
604 {
605         /* identifiers */
606         ot->name   = "Skin Resize";
607         ot->description = "Scale selected vertices' skin radii"; 
608         ot->idname = OP_SKIN_RESIZE;
609         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
610
611         /* api callbacks */
612         ot->invoke = transform_invoke;
613         ot->exec   = transform_exec;
614         ot->modal  = transform_modal;
615         ot->cancel = transform_cancel;
616         ot->poll   = skin_resize_poll;
617
618         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
619
620         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS);
621 }
622
623 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
624 {
625         PropertyRNA *prop;
626
627         /* identifiers */
628         ot->name   = "Trackball";
629         ot->description = "Trackball style rotation of selected items";
630         ot->idname = OP_TRACKBALL;
631         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
632
633         /* api callbacks */
634         ot->invoke = transform_invoke;
635         ot->exec   = transform_exec;
636         ot->modal  = transform_modal;
637         ot->cancel = transform_cancel;
638         ot->poll   = ED_operator_screenactive;
639
640         /* Maybe we could use float_vector_xyz here too? */
641         prop = RNA_def_float_vector(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
642         RNA_def_property_subtype(prop, PROP_ANGLE);
643
644         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
645 }
646
647 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
648 {
649         PropertyRNA *prop;
650
651         /* identifiers */
652         ot->name = "Rotate";
653         ot->description = "Rotate selected items";
654         ot->idname = OP_ROTATION;
655         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
656
657         /* api callbacks */
658         ot->invoke = transform_invoke;
659         ot->exec   = transform_exec;
660         ot->modal  = transform_modal;
661         ot->cancel = transform_cancel;
662         ot->poll   = ED_operator_screenactive;
663
664         prop = RNA_def_float(ot->srna, "value", 0.0f, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
665         RNA_def_property_subtype(prop, PROP_ANGLE);
666
667         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP);
668 }
669
670 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
671 {
672         PropertyRNA *prop;
673
674         /* identifiers */
675         ot->name = "Tilt";
676         /* optionals - 
677          * "Tilt selected vertices"
678          * "Specify an extra axis rotation for selected vertices of 3D curve" */
679         ot->description = "Tilt selected control vertices of 3D curve"; 
680         ot->idname = OP_TILT;
681         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
682
683         /* api callbacks */
684         ot->invoke = transform_invoke;
685         ot->exec   = transform_exec;
686         ot->modal  = transform_modal;
687         ot->cancel = transform_cancel;
688         ot->poll   = ED_operator_editcurve_3d;
689
690         prop = RNA_def_float(ot->srna, "value", 0.0, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
691         RNA_def_property_subtype(prop, PROP_ANGLE);
692
693         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
694 }
695
696 static void TRANSFORM_OT_warp(struct wmOperatorType *ot)
697 {
698         /* identifiers */
699         ot->name   = "Warp";
700         ot->description = "Warp selected items around the cursor";
701         ot->idname = OP_WARP;
702         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
703
704         /* api callbacks */
705         ot->invoke = transform_invoke;
706         ot->exec   = transform_exec;
707         ot->modal  = transform_modal;
708         ot->cancel = transform_cancel;
709         ot->poll   = ED_operator_screenactive;
710
711         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
712
713         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
714         // XXX Warp axis?
715 }
716
717 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
718 {
719         /* identifiers */
720         ot->name   = "Shear";
721         ot->description = "Shear selected items along the horizontal screen axis";
722         ot->idname = OP_SHEAR;
723         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
724
725         /* api callbacks */
726         ot->invoke = transform_invoke;
727         ot->exec   = transform_exec;
728         ot->modal  = transform_modal;
729         ot->cancel = transform_cancel;
730         ot->poll   = ED_operator_screenactive;
731
732         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
733
734         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
735         // XXX Shear axis?
736 }
737
738 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
739 {
740         /* identifiers */
741         ot->name   = "Push/Pull";
742         ot->description = "Push/Pull selected items";
743         ot->idname = OP_PUSH_PULL;
744         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
745
746         /* api callbacks */
747         ot->invoke = transform_invoke;
748         ot->exec   = transform_exec;
749         ot->modal  = transform_modal;
750         ot->cancel = transform_cancel;
751         ot->poll   = ED_operator_screenactive;
752
753         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
754
755         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
756 }
757
758 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
759 {
760         /* identifiers */
761         ot->name   = "Shrink/Fatten";
762         ot->description = "Shrink/fatten selected vertices along normals";
763         ot->idname = OP_SHRINK_FATTEN;
764         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
765
766         /* api callbacks */
767         ot->invoke = transform_invoke;
768         ot->exec   = transform_exec;
769         ot->modal  = transform_modal;
770         ot->cancel = transform_cancel;
771         ot->poll   = ED_operator_editmesh;
772
773         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
774
775         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
776 }
777
778 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
779 {
780         /* identifiers */
781         ot->name   = "To Sphere";
782         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" 
783         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
784         ot->idname = OP_TOSPHERE;
785         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
786
787         /* api callbacks */
788         ot->invoke = transform_invoke;
789         ot->exec   = transform_exec;
790         ot->modal  = transform_modal;
791         ot->cancel = transform_cancel;
792         ot->poll   = ED_operator_screenactive;
793
794         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
795
796         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
797 }
798
799 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
800 {
801         /* identifiers */
802         ot->name   = "Mirror";
803         ot->description = "Mirror selected vertices around one or more axes";
804         ot->idname = OP_MIRROR;
805         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
806
807         /* api callbacks */
808         ot->invoke = transform_invoke;
809         ot->exec   = transform_exec;
810         ot->modal  = transform_modal;
811         ot->cancel = transform_cancel;
812         ot->poll   = ED_operator_screenactive;
813
814         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL);
815 }
816
817 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
818 {
819         /* identifiers */
820         ot->name   = "Edge Slide";
821         ot->description = "Slide an edge loop along a mesh"; 
822         ot->idname = OP_EDGE_SLIDE;
823         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
824
825         /* api callbacks */
826         ot->invoke = transform_invoke;
827         ot->exec   = transform_exec;
828         ot->modal  = transform_modal;
829         ot->cancel = transform_cancel;
830         ot->poll   = ED_operator_editmesh;
831
832         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
833
834         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
835 }
836
837 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
838 {
839         /* identifiers */
840         ot->name   = "Vertex Slide";
841         ot->description = "Slide a vertex along a mesh";
842         ot->idname = OP_VERT_SLIDE;
843         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
844
845         /* api callbacks */
846         ot->invoke = transform_invoke;
847         ot->exec   = transform_exec;
848         ot->modal  = transform_modal;
849         ot->cancel = transform_cancel;
850         ot->poll   = ED_operator_editmesh;
851
852         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
853
854         Transform_Properties(ot, P_MIRROR | P_SNAP);
855 }
856
857 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
858 {
859         /* identifiers */
860         ot->name   = "Edge Crease";
861         ot->description = "Change the crease of edges";
862         ot->idname = OP_EDGE_CREASE;
863         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
864
865         /* api callbacks */
866         ot->invoke = transform_invoke;
867         ot->exec   = transform_exec;
868         ot->modal  = transform_modal;
869         ot->cancel = transform_cancel;
870         ot->poll   = ED_operator_editmesh;
871
872         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
873
874         Transform_Properties(ot, P_SNAP);
875 }
876
877 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
878 {
879         /* identifiers */
880         ot->name   = "Edge Bevel Weight";
881         ot->description = "Change the bevel weight of edges";
882         ot->idname = OP_EDGE_BWEIGHT;
883         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
884
885         /* api callbacks */
886         ot->invoke = transform_invoke;
887         ot->exec   = transform_exec;
888         ot->modal  = transform_modal;
889         ot->cancel = transform_cancel;
890         ot->poll   = ED_operator_editmesh;
891
892         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
893
894         Transform_Properties(ot, P_SNAP);
895 }
896
897 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
898 {
899         /* identifiers */
900         ot->name   = "Sequence Slide";
901         ot->description = "Slide a sequence strip in time";
902         ot->idname = OP_SEQ_SLIDE;
903         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
904
905         /* api callbacks */
906         ot->invoke = transform_invoke;
907         ot->exec   = transform_exec;
908         ot->modal  = transform_modal;
909         ot->cancel = transform_cancel;
910         ot->poll   = ED_operator_sequencer_active;
911
912         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
913
914         Transform_Properties(ot, P_SNAP);
915 }
916
917 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
918 {
919         PropertyRNA *prop;
920
921         /* identifiers */
922         ot->name   = "Transform";
923         ot->description = "Transform selected items by mode type";
924         ot->idname = "TRANSFORM_OT_transform";
925         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
926
927         /* api callbacks */
928         ot->invoke = transform_invoke;
929         ot->exec   = transform_exec;
930         ot->modal  = transform_modal;
931         ot->cancel = transform_cancel;
932         ot->poll   = ED_operator_screenactive;
933
934         prop = RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
935         RNA_def_property_flag(prop, PROP_HIDDEN);
936
937         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
938
939         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP);
940 }
941
942 void transform_operatortypes(void)
943 {
944         TransformModeItem *tmode;
945
946         for (tmode = transform_modes; tmode->idname; tmode++) {
947                 WM_operatortype_append(tmode->opfunc);
948         }
949
950         WM_operatortype_append(TRANSFORM_OT_transform);
951
952         WM_operatortype_append(TRANSFORM_OT_select_orientation);
953         WM_operatortype_append(TRANSFORM_OT_create_orientation);
954         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
955 }
956
957 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
958 {
959         wmKeyMapItem *kmi;
960         wmKeyMap *modalmap;
961         
962         /* transform.c, only adds modal map once, checks if it's there */
963         modalmap = transform_modal_keymap(keyconf);
964
965         /* assign map to operators only the first time */
966         if (modalmap) {
967                 TransformModeItem *tmode;
968
969                 for (tmode = transform_modes; tmode->idname; tmode++) {
970                         WM_modalkeymap_assign(modalmap, tmode->idname);
971                 }
972                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
973         }
974         
975         switch (spaceid) {
976                 case SPACE_VIEW3D:
977                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
978
979                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
980
981                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
982
983                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
984
985                         WM_keymap_add_item(keymap, OP_WARP, WKEY, KM_PRESS, KM_SHIFT, 0);
986
987                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
988
989                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
990
991                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
992
993                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
994                         RNA_boolean_set(kmi->ptr, "use", TRUE);
995
996                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
997
998                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
999                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1000
1001                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1002                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_element");
1003
1004
1005                         kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
1006                         RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
1007
1008                         kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
1009                         RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
1010
1011                         WM_keymap_add_item(keymap, OP_SKIN_RESIZE, AKEY, KM_PRESS, KM_CTRL, 0);
1012
1013                         break;
1014                 case SPACE_ACTION:
1015                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1016                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1017                         
1018                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1019                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1020                         
1021                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1022                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1023                         
1024                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1025                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1026                         
1027                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
1028                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
1029                         break;
1030                 case SPACE_IPO:
1031                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1032                         
1033                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1034                         
1035                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1036                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1037                         
1038                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1039                         
1040                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1041                         break;
1042                 case SPACE_NLA:
1043                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1044                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1045                         
1046                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1047                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1048                         
1049                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1050                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1051                         
1052                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1053                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1054                         break;
1055                 case SPACE_NODE:
1056                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
1057                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
1058                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
1059                         /* NB: small trick: macro operator poll may fail due to library data edit,
1060                          * in that case the secondary regular operators are called with same keymap.
1061                          */
1062                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
1063                         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
1064                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
1065                         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
1066                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
1067                         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
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
1073                         /* detach and translate */
1074                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", DKEY, KM_PRESS, KM_ALT, 0);
1075                         /* XXX release_confirm is set in the macro operator definition */
1076                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links_release", EVT_TWEAK_A, KM_ANY, KM_ALT, 0);
1077                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", EVT_TWEAK_S, KM_ANY, KM_ALT, 0);
1078
1079                         /* dettach and translate */
1080                         WM_keymap_add_item(keymap, "NODE_OT_detach_translate_attach", FKEY, KM_PRESS, KM_ALT, 0);
1081                         break;
1082                 case SPACE_SEQ:
1083                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
1084
1085                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
1086
1087                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1088                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1089                         break;
1090                 case SPACE_IMAGE:
1091                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1092
1093                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1094
1095                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1096
1097                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1098
1099                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1100
1101                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
1102
1103                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1104                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1105
1106                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1107                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_uv_element");
1108                         break;
1109                 case SPACE_CLIP:
1110                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1111                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1112                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1113                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1114                         break;
1115                 default:
1116                         break;
1117         }
1118 }
1119