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