RNA
[blender-staging.git] / source / blender / editors / transform / transform_ops.c
1 /**
2  * $Id: transform_ops.c 17542 2008-11-23 15:27:53Z theeth $
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): none yet.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include "MEM_guardedalloc.h"
26
27 #include "DNA_scene_types.h"
28 #include "DNA_space_types.h"
29 #include "DNA_windowmanager_types.h"
30
31 #include "RNA_access.h"
32 #include "RNA_define.h"
33 #include "RNA_enum_types.h"
34
35 #include "BLI_arithb.h"
36
37 #include "BKE_utildefines.h"
38 #include "BKE_context.h"
39
40 #include "WM_api.h"
41 #include "WM_types.h"
42
43 #include "UI_interface.h"
44
45 #include "ED_screen.h"
46
47 #include "transform.h"
48
49 typedef struct TransformModeItem
50 {
51         char *idname;
52         int             mode;
53 } TransformModeItem;
54
55 static float VecOne[3] = {1, 1, 1};
56
57 /* need constants for this */
58 EnumPropertyItem proportional_mode_types[] = {
59                 {0, "OFF", 0, "Off", ""},
60                 {1, "ON", 0, "On", ""},
61                 {2, "CONNECTED", 0, "Connected", ""},
62                 {0, NULL, 0, NULL, NULL}
63 };
64
65 EnumPropertyItem snap_mode_types[] = {
66                 {SCE_SNAP_TARGET_CLOSEST, "CLOSEST", 0, "Closest", ""},
67                 {SCE_SNAP_TARGET_CENTER,  "CENTER", 0, "Center", ""},
68                 {SCE_SNAP_TARGET_MEDIAN,  "MEDIAN", 0, "Median", ""},
69                 {SCE_SNAP_TARGET_ACTIVE,  "ACTIVE", 0, "Active", ""},
70                 {0, NULL, 0, NULL, NULL}
71 };
72
73 EnumPropertyItem proportional_falloff_types[] = {
74                 {PROP_SMOOTH, "SMOOTH", 0, "Smooth", ""},
75                 {PROP_SPHERE, "SPHERE", 0, "Sphere", ""},
76                 {PROP_ROOT, "ROOT", 0, "Root", ""},
77                 {PROP_SHARP, "SHARP", 0, "Sharp", ""},
78                 {PROP_LIN, "LINEAR", 0, "Linear", ""},
79                 {PROP_CONST, "CONSTANT", 0, "Constant", ""},
80                 {PROP_RANDOM, "RANDOM", 0, "Random", ""},
81                 {0, NULL, 0, NULL, NULL}
82 };
83
84 char OP_TRANSLATION[] = "TFM_OT_translation";
85 char OP_ROTATION[] = "TFM_OT_rotation";
86 char OP_TOSPHERE[] = "TFM_OT_tosphere";
87 char OP_RESIZE[] = "TFM_OT_resize";
88 char OP_SHEAR[] = "TFM_OT_shear";
89 char OP_WARP[] = "TFM_OT_warp";
90 char OP_SHRINK_FATTEN[] = "TFM_OT_shrink_fatten";
91 char OP_TILT[] = "TFM_OT_tilt";
92
93
94 TransformModeItem transform_modes[] =
95 {
96         {OP_TRANSLATION, TFM_TRANSLATION},
97         {OP_ROTATION, TFM_ROTATION},
98         {OP_TOSPHERE, TFM_TOSPHERE},
99         {OP_RESIZE, TFM_RESIZE},
100         {OP_SHEAR, TFM_SHEAR},
101         {OP_WARP, TFM_WARP},
102         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN},
103         {OP_TILT, TFM_TILT},
104         {NULL, 0}
105 };
106
107 static int select_orientation_exec(bContext *C, wmOperator *op)
108 {
109         int orientation = RNA_enum_get(op->ptr, "orientation");
110         int custom_index= RNA_int_get(op->ptr, "custom_index");;
111
112         if(orientation == V3D_MANIP_CUSTOM)
113                 orientation += custom_index;
114         
115         BIF_selectTransformOrientationValue(C, orientation);
116
117         return OPERATOR_FINISHED;
118 }
119
120 static int select_orientation_invoke(bContext *C, wmOperator *op, wmEvent *event)
121 {
122         uiPopupMenu *pup;
123         uiLayout *layout;
124         
125         pup= uiPupMenuBegin(C, "Orientation", 0);
126         layout= uiPupMenuLayout(pup);
127         BIF_menuTransformOrientation(C, layout, NULL);
128         uiPupMenuEnd(C, pup);
129         
130         return OPERATOR_CANCELLED;
131 }
132         
133 void TFM_OT_select_orientation(struct wmOperatorType *ot)
134 {
135         static EnumPropertyItem orientation_items[]= {
136                 {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", ""},
137                 {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal", ""},
138                 {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", ""},
139                 {V3D_MANIP_VIEW, "VIEW", 0, "View", ""},
140                 {V3D_MANIP_CUSTOM, "CUSTOM", 0, "Custom", ""},
141                 {0, NULL, 0, NULL, NULL}};
142
143         /* identifiers */
144         ot->name   = "Select Orientation";
145         ot->idname = "TFM_OT_select_orientation";
146
147         /* api callbacks */
148         ot->invoke = select_orientation_invoke;
149         ot->exec   = select_orientation_exec;
150         ot->poll   = ED_operator_areaactive;
151
152         RNA_def_enum(ot->srna, "orientation", orientation_items, V3D_MANIP_CUSTOM, "Orientation", "DOC_BROKEN");
153         RNA_def_int(ot->srna, "custom_index", 0, 0, INT_MAX, "Custom Index", "", 0, INT_MAX);
154 }
155
156 static void transformops_exit(bContext *C, wmOperator *op)
157 {
158         saveTransform(C, op->customdata, op);
159         MEM_freeN(op->customdata);
160         op->customdata = NULL;
161 }
162
163 static int transformops_data(bContext *C, wmOperator *op, wmEvent *event)
164 {
165         int retval = 1;
166         if (op->customdata == NULL)
167         {
168                 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
169                 TransformModeItem *tmode;
170                 int mode = -1;
171
172                 for (tmode = transform_modes; tmode->idname; tmode++)
173                 {
174                         if (op->type->idname == tmode->idname)
175                         {
176                                 mode = tmode->mode;
177                         }
178                 }
179
180                 if (mode == -1)
181                 {
182                         mode = RNA_int_get(op->ptr, "mode");
183                 }
184
185                 retval = initTransform(C, t, op, event, mode);
186         
187                 /* store data */
188                 op->customdata = t;
189         }
190         
191         return retval; /* return 0 on error */
192 }
193
194 static int transform_modal(bContext *C, wmOperator *op, wmEvent *event)
195 {
196         int exit_code;
197         
198         TransInfo *t = op->customdata;
199         
200         transformEvent(t, event);
201         
202         transformApply(C, t);
203         
204         
205         exit_code = transformEnd(C, t);
206         
207         if (exit_code != OPERATOR_RUNNING_MODAL)
208         {
209                 transformops_exit(C, op);
210         }
211
212         return exit_code;
213 }
214
215 static int transform_cancel(bContext *C, wmOperator *op)
216 {
217         TransInfo *t = op->customdata;
218         
219         t->state = TRANS_CANCEL;
220         transformEnd(C, t);
221         transformops_exit(C, op);
222         
223         return OPERATOR_CANCELLED;
224 }
225
226 static int transform_exec(bContext *C, wmOperator *op)
227 {
228         TransInfo *t;
229
230         if (!transformops_data(C, op, NULL))
231         {
232                 return OPERATOR_CANCELLED;
233         }
234
235         t = op->customdata;
236
237         t->options |= CTX_AUTOCONFIRM;
238
239         transformApply(C, t);
240         
241         transformEnd(C, t);
242
243         transformops_exit(C, op);
244         
245         return OPERATOR_FINISHED;
246 }
247
248 static int transform_invoke(bContext *C, wmOperator *op, wmEvent *event)
249 {
250         if (!transformops_data(C, op, event))
251         {
252                 return OPERATOR_CANCELLED;
253         }
254
255         if(RNA_property_is_set(op->ptr, "value")) {
256                 return transform_exec(C, op);
257         }
258         else {
259                 TransInfo *t = op->customdata;
260
261                 /* add temp handler */
262                 WM_event_add_modal_handler(C, &CTX_wm_window(C)->handlers, op);
263
264                 t->flag |= T_MODAL; // XXX meh maybe somewhere else
265
266                 return OPERATOR_RUNNING_MODAL;
267         }
268 }
269
270 void Properties_Proportional(struct wmOperatorType *ot)
271 {
272         RNA_def_enum(ot->srna, "proportional", proportional_mode_types, 0, "Proportional Editing", "");
273         RNA_def_enum(ot->srna, "proportional_editing_falloff", prop_mode_items, 0, "Proportional Editing Falloff", "Falloff type for proportional editing mode.");
274         RNA_def_float(ot->srna, "proportional_size", 1, 0, FLT_MAX, "Proportional Size", "", 0, 100);
275 }
276
277 void Properties_Snapping(struct wmOperatorType *ot, short align)
278 {
279         RNA_def_boolean(ot->srna, "snap", 0, "Snap to Point", "");
280         RNA_def_enum(ot->srna, "snap_mode", snap_mode_types, 0, "Mode", "");
281         RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
282         
283         if (align)
284         {
285                 RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
286                 RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
287         }
288 }
289
290 void Properties_Constraints(struct wmOperatorType *ot)
291 {
292         RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
293         RNA_def_int(ot->srna, "constraint_orientation", 0, 0, INT_MAX, "Constraint Orientation", "", 0, INT_MAX);
294 }
295
296 void TFM_OT_translation(struct wmOperatorType *ot)
297 {
298         /* identifiers */
299         ot->name   = "Translation";
300         ot->idname = OP_TRANSLATION;
301         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
302
303         /* api callbacks */
304         ot->invoke = transform_invoke;
305         ot->exec   = transform_exec;
306         ot->modal  = transform_modal;
307         ot->cancel  = transform_cancel;
308         ot->poll   = ED_operator_areaactive;
309
310         RNA_def_float_vector(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
311
312         Properties_Proportional(ot);
313
314         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
315
316         Properties_Constraints(ot);
317         
318         Properties_Snapping(ot, 1);
319 }
320
321 void TFM_OT_resize(struct wmOperatorType *ot)
322 {
323         /* identifiers */
324         ot->name   = "Resize";
325         ot->idname = OP_RESIZE;
326         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
327
328         /* api callbacks */
329         ot->invoke = transform_invoke;
330         ot->exec   = transform_exec;
331         ot->modal  = transform_modal;
332         ot->cancel  = transform_cancel;
333         ot->poll   = ED_operator_areaactive;
334
335         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
336
337         Properties_Proportional(ot);
338
339         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
340
341         Properties_Constraints(ot);
342         
343         Properties_Snapping(ot, 0);
344 }
345
346 void TFM_OT_rotation(struct wmOperatorType *ot)
347 {
348         /* identifiers */
349         ot->name   = "Rotation";
350         ot->idname = OP_ROTATION;
351         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
352
353         /* api callbacks */
354         ot->invoke = transform_invoke;
355         ot->exec   = transform_exec;
356         ot->modal  = transform_modal;
357         ot->cancel  = transform_cancel;
358         ot->poll   = ED_operator_areaactive;
359
360         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
361
362         Properties_Proportional(ot);
363
364         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
365
366         Properties_Constraints(ot);
367         
368         Properties_Snapping(ot, 0);
369 }
370
371 void TFM_OT_tilt(struct wmOperatorType *ot)
372 {
373         /* identifiers */
374         ot->name   = "Tilt";
375         ot->idname = OP_TILT;
376         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
377
378         /* api callbacks */
379         ot->invoke = transform_invoke;
380         ot->exec   = transform_exec;
381         ot->modal  = transform_modal;
382         ot->cancel  = transform_cancel;
383         ot->poll   = ED_operator_editcurve;
384
385         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
386
387         Properties_Proportional(ot);
388
389         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
390
391         Properties_Constraints(ot);
392 }
393
394 void TFM_OT_warp(struct wmOperatorType *ot)
395 {
396         /* identifiers */
397         ot->name   = "Warp";
398         ot->idname = OP_WARP;
399         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
400
401         /* api callbacks */
402         ot->invoke = transform_invoke;
403         ot->exec   = transform_exec;
404         ot->modal  = transform_modal;
405         ot->cancel  = transform_cancel;
406         ot->poll   = ED_operator_areaactive;
407
408         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", 0, 1);
409
410         Properties_Proportional(ot);
411
412         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
413
414         // XXX Shear axis?
415 //      Properties_Constraints(ot);
416 }
417
418 void TFM_OT_shear(struct wmOperatorType *ot)
419 {
420         /* identifiers */
421         ot->name   = "Shear";
422         ot->idname = OP_SHEAR;
423         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
424
425         /* api callbacks */
426         ot->invoke = transform_invoke;
427         ot->exec   = transform_exec;
428         ot->modal  = transform_modal;
429         ot->cancel  = transform_cancel;
430         ot->poll   = ED_operator_areaactive;
431
432         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
433
434         Properties_Proportional(ot);
435
436         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
437
438         // XXX Shear axis?
439 //      Properties_Constraints(ot);
440 }
441
442 void TFM_OT_shrink_fatten(struct wmOperatorType *ot)
443 {
444         /* identifiers */
445         ot->name   = "Shrink/Fatten";
446         ot->idname = OP_SHRINK_FATTEN;
447         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
448
449         /* api callbacks */
450         ot->invoke = transform_invoke;
451         ot->exec   = transform_exec;
452         ot->modal  = transform_modal;
453         ot->cancel  = transform_cancel;
454         ot->poll   = ED_operator_editmesh;
455
456         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
457
458         Properties_Proportional(ot);
459
460         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
461 }
462
463 void TFM_OT_tosphere(struct wmOperatorType *ot)
464 {
465         /* identifiers */
466         ot->name   = "To Sphere";
467         ot->idname = OP_TOSPHERE;
468         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
469
470         /* api callbacks */
471         ot->invoke = transform_invoke;
472         ot->exec   = transform_exec;
473         ot->modal  = transform_modal;
474         ot->cancel  = transform_cancel;
475         ot->poll   = ED_operator_areaactive;
476
477         RNA_def_float_percentage(ot->srna, "value", 0, 0, 1, "Percentage", "", 0, 1);
478
479         Properties_Proportional(ot);
480
481         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
482 }
483
484 void TFM_OT_transform(struct wmOperatorType *ot)
485 {
486         static EnumPropertyItem transform_mode_types[] = {
487                         {TFM_INIT, "INIT", 0, "Init", ""},
488                         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
489                         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
490                         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
491                         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
492                         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
493                         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
494                         {TFM_WARP, "WARP", 0, "Warp", ""},
495                         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
496                         {TFM_TILT, "TILT", 0, "Tilt", ""},
497                         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
498                         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
499                         {TFM_CREASE, "CREASE", 0, "Crease", ""},
500                         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
501                         {TFM_BONESIZE, "BONESIZE", 0, "Bonesize", ""},
502                         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
503                         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
504                         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
505                         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
506                         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
507                         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
508                         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
509                         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
510                         {TFM_BEVEL, "BEVEL", 0, "Bevel", ""},
511                         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
512                         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
513                         {0, NULL, 0, NULL, NULL}
514         };
515
516         /* identifiers */
517         ot->name   = "Transform";
518         ot->idname = "TFM_OT_transform";
519         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
520
521         /* api callbacks */
522         ot->invoke = transform_invoke;
523         ot->exec   = transform_exec;
524         ot->modal  = transform_modal;
525         ot->cancel  = transform_cancel;
526         ot->poll   = ED_operator_areaactive;
527
528         RNA_def_enum(ot->srna, "mode", transform_mode_types, 0, "Mode", "");
529
530         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
531
532         Properties_Proportional(ot);
533         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
534
535         RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
536         RNA_def_int(ot->srna, "constraint_orientation", 0, 0, INT_MAX, "Constraint Orientation", "", 0, INT_MAX);
537 }
538
539 void transform_operatortypes(void)
540 {
541         WM_operatortype_append(TFM_OT_transform);
542         WM_operatortype_append(TFM_OT_translation);
543         WM_operatortype_append(TFM_OT_rotation);
544         WM_operatortype_append(TFM_OT_tosphere);
545         WM_operatortype_append(TFM_OT_resize);
546         WM_operatortype_append(TFM_OT_shear);
547         WM_operatortype_append(TFM_OT_warp);
548         WM_operatortype_append(TFM_OT_shrink_fatten);
549         WM_operatortype_append(TFM_OT_tilt);
550
551         WM_operatortype_append(TFM_OT_select_orientation);
552 }
553  
554 void transform_keymap_for_space(struct wmWindowManager *wm, struct ListBase *keymap, int spaceid)
555 {
556         wmKeymapItem *km;
557         switch(spaceid)
558         {
559                 case SPACE_VIEW3D:
560                         km = WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0);
561                         
562                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0);
563                         
564                         km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0);
565
566                         km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
567
568                         km = WM_keymap_add_item(keymap, "TFM_OT_warp", WKEY, KM_PRESS, KM_SHIFT, 0);
569
570                         km = WM_keymap_add_item(keymap, "TFM_OT_tosphere", SKEY, KM_PRESS, KM_CTRL|KM_SHIFT, 0);
571                         
572                         km = WM_keymap_add_item(keymap, "TFM_OT_shear", SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0);
573                         
574                         km = WM_keymap_add_item(keymap, "TFM_OT_shrink_fatten", SKEY, KM_PRESS, KM_ALT, 0);
575
576                         km = WM_keymap_add_item(keymap, "TFM_OT_tilt", TKEY, KM_PRESS, 0, 0);
577
578                         km = WM_keymap_add_item(keymap, "TFM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
579
580                         break;
581                 case SPACE_ACTION:
582                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0);
583                         RNA_int_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
584                         
585                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
586                         RNA_int_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
587                         
588                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0);
589                         RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND);
590                         
591                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, 0, 0);
592                         RNA_int_set(km->ptr, "mode", TFM_TIME_SCALE);
593                         
594                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", TKEY, KM_PRESS, 0, 0);
595                         RNA_int_set(km->ptr, "mode", TFM_TIME_SLIDE);
596                         break;
597                 case SPACE_IPO:
598                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0);
599                         
600                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0);
601                         
602                                 // XXX the 'mode' identifier here is not quite right
603                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0);
604                         RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND);
605                         
606                         km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0);
607                         
608                         km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
609                         break;
610                 case SPACE_NODE:
611                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0);
612                         
613                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_A, KM_ANY, 0, 0);
614                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0);
615                         
616                         km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0);
617                         
618                         km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
619                         break;
620                 case SPACE_SEQ:
621                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0);
622                         
623                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0);
624                         
625                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0);
626                         RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND);
627                         break;
628                 case SPACE_IMAGE:
629                         km = WM_keymap_add_item(keymap, "TFM_OT_translation", GKEY, KM_PRESS, 0, 0);
630                         
631                         km= WM_keymap_add_item(keymap, "TFM_OT_translation", EVT_TWEAK_S, KM_ANY, 0, 0);
632                         
633                         km = WM_keymap_add_item(keymap, "TFM_OT_rotation", RKEY, KM_PRESS, 0, 0);
634
635                         km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
636
637                         km = WM_keymap_add_item(keymap, "TFM_OT_transform", MKEY, KM_PRESS, 0, 0);
638                         RNA_int_set(km->ptr, "mode", TFM_MIRROR);
639                         break;
640                 default:
641                         break;
642         }
643 }
644