soc-2008-mxcurioni: merged changes to revision 23516
[blender.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 char OP_MIRROR[] = "TFM_OT_mirror";
102 char OP_EDGE_SLIDE[] = "TFM_OT_edge_slide";
103
104
105 TransformModeItem transform_modes[] =
106 {
107         {OP_TRANSLATION, TFM_TRANSLATION},
108         {OP_ROTATION, TFM_ROTATION},
109         {OP_TOSPHERE, TFM_TOSPHERE},
110         {OP_RESIZE, TFM_RESIZE},
111         {OP_SHEAR, TFM_SHEAR},
112         {OP_WARP, TFM_WARP},
113         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN},
114         {OP_TILT, TFM_TILT},
115         {OP_TRACKBALL, TFM_TRACKBALL},
116         {OP_MIRROR, TFM_MIRROR},
117         {OP_EDGE_SLIDE, TFM_EDGE_SLIDE},
118         {NULL, 0}
119 };
120
121 static int select_orientation_exec(bContext *C, wmOperator *op)
122 {
123         int orientation = RNA_enum_get(op->ptr, "orientation");
124
125         BIF_selectTransformOrientationValue(C, orientation);
126
127         return OPERATOR_FINISHED;
128 }
129
130 static int select_orientation_invoke(bContext *C, wmOperator *op, wmEvent *event)
131 {
132         uiPopupMenu *pup;
133         uiLayout *layout;
134
135         pup= uiPupMenuBegin(C, "Orientation", 0);
136         layout= uiPupMenuLayout(pup);
137         uiItemsEnumO(layout, "TFM_OT_select_orientation", "orientation");
138         uiPupMenuEnd(C, pup);
139
140         return OPERATOR_CANCELLED;
141 }
142
143 static EnumPropertyItem *select_orientation_itemf(bContext *C, PointerRNA *ptr, int *free)
144 {
145         *free= 1;
146         return BIF_enumTransformOrientation(C);
147 }
148
149 void TFM_OT_select_orientation(struct wmOperatorType *ot)
150 {
151         PropertyRNA *prop;
152
153         /* identifiers */
154         ot->name   = "Select Orientation";
155         ot->description= "Select orientation type.";
156         ot->idname = "TFM_OT_select_orientation";
157
158         /* api callbacks */
159         ot->invoke = select_orientation_invoke;
160         ot->exec   = select_orientation_exec;
161         ot->poll   = ED_operator_areaactive;
162
163         prop= RNA_def_enum(ot->srna, "orientation", orientation_items, V3D_MANIP_GLOBAL, "Orientation", "DOC_BROKEN");
164         RNA_def_enum_funcs(prop, select_orientation_itemf);
165 }
166
167 static void transformops_exit(bContext *C, wmOperator *op)
168 {
169         saveTransform(C, op->customdata, op);
170         MEM_freeN(op->customdata);
171         op->customdata = NULL;
172         G.moving = 0;
173 }
174
175 static int transformops_data(bContext *C, wmOperator *op, wmEvent *event)
176 {
177         int retval = 1;
178         if (op->customdata == NULL)
179         {
180                 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
181                 TransformModeItem *tmode;
182                 int mode = -1;
183
184                 for (tmode = transform_modes; tmode->idname; tmode++)
185                 {
186                         if (op->type->idname == tmode->idname)
187                         {
188                                 mode = tmode->mode;
189                         }
190                 }
191
192                 if (mode == -1)
193                 {
194                         mode = RNA_int_get(op->ptr, "mode");
195                 }
196
197                 retval = initTransform(C, t, op, event, mode);
198                 G.moving = 1;
199
200                 /* store data */
201                 op->customdata = t;
202         }
203
204         return retval; /* return 0 on error */
205 }
206
207 static int transform_modal(bContext *C, wmOperator *op, wmEvent *event)
208 {
209         int exit_code;
210
211         TransInfo *t = op->customdata;
212
213         transformEvent(t, event);
214
215         transformApply(C, t);
216
217
218         exit_code = transformEnd(C, t);
219
220         if (exit_code != OPERATOR_RUNNING_MODAL)
221         {
222                 transformops_exit(C, op);
223         }
224
225         return exit_code;
226 }
227
228 static int transform_cancel(bContext *C, wmOperator *op)
229 {
230         TransInfo *t = op->customdata;
231
232         t->state = TRANS_CANCEL;
233         transformEnd(C, t);
234         transformops_exit(C, op);
235
236         return OPERATOR_CANCELLED;
237 }
238
239 static int transform_exec(bContext *C, wmOperator *op)
240 {
241         TransInfo *t;
242
243         if (!transformops_data(C, op, NULL))
244         {
245                 return OPERATOR_CANCELLED;
246         }
247
248         t = op->customdata;
249
250         t->options |= CTX_AUTOCONFIRM;
251
252         transformApply(C, t);
253
254         transformEnd(C, t);
255
256         transformops_exit(C, op);
257
258         return OPERATOR_FINISHED;
259 }
260
261 static int transform_invoke(bContext *C, wmOperator *op, wmEvent *event)
262 {
263         if (!transformops_data(C, op, event))
264         {
265                 return OPERATOR_CANCELLED;
266         }
267
268         if(RNA_property_is_set(op->ptr, "value")) {
269                 return transform_exec(C, op);
270         }
271         else {
272                 TransInfo *t = op->customdata;
273
274                 /* add temp handler */
275                 WM_event_add_modal_handler(C, op);
276
277                 t->flag |= T_MODAL; // XXX meh maybe somewhere else
278
279                 return OPERATOR_RUNNING_MODAL;
280         }
281 }
282
283 void Properties_Proportional(struct wmOperatorType *ot)
284 {
285         RNA_def_enum(ot->srna, "proportional", proportional_mode_types, 0, "Proportional Editing", "");
286         RNA_def_enum(ot->srna, "proportional_editing_falloff", prop_mode_items, 0, "Proportional Editing Falloff", "Falloff type for proportional editing mode.");
287         RNA_def_float(ot->srna, "proportional_size", 1, 0, FLT_MAX, "Proportional Size", "", 0, 100);
288 }
289
290 void Properties_Snapping(struct wmOperatorType *ot, short align)
291 {
292         RNA_def_boolean(ot->srna, "snap", 0, "Snap to Point", "");
293         RNA_def_enum(ot->srna, "snap_mode", snap_mode_types, 0, "Mode", "");
294         RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
295
296         if (align)
297         {
298                 RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
299                 RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
300         }
301 }
302
303 void Properties_Constraints(struct wmOperatorType *ot)
304 {
305         PropertyRNA *prop;
306
307         RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
308         prop= RNA_def_enum(ot->srna, "constraint_orientation", orientation_items, V3D_MANIP_GLOBAL, "Orientation", "DOC_BROKEN");
309         RNA_def_enum_funcs(prop, select_orientation_itemf);
310 }
311
312 void TFM_OT_translate(struct wmOperatorType *ot)
313 {
314         /* identifiers */
315         ot->name   = "Translate";
316         ot->description= "Translate selected items.";
317         ot->idname = OP_TRANSLATION;
318         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
319
320         /* api callbacks */
321         ot->invoke = transform_invoke;
322         ot->exec   = transform_exec;
323         ot->modal  = transform_modal;
324         ot->cancel  = transform_cancel;
325         ot->poll   = ED_operator_areaactive;
326
327         RNA_def_float_vector(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
328
329         Properties_Proportional(ot);
330
331         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
332
333         Properties_Constraints(ot);
334
335         Properties_Snapping(ot, 1);
336 }
337
338 void TFM_OT_resize(struct wmOperatorType *ot)
339 {
340         /* identifiers */
341         ot->name   = "Resize";
342         ot->description= "Resize selected items."; 
343         ot->idname = OP_RESIZE;
344         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
345
346         /* api callbacks */
347         ot->invoke = transform_invoke;
348         ot->exec   = transform_exec;
349         ot->modal  = transform_modal;
350         ot->cancel  = transform_cancel;
351         ot->poll   = ED_operator_areaactive;
352
353         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
354
355         Properties_Proportional(ot);
356
357         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
358
359         Properties_Constraints(ot);
360
361         Properties_Snapping(ot, 0);
362 }
363
364
365 void TFM_OT_trackball(struct wmOperatorType *ot)
366 {
367         /* identifiers */
368         ot->name   = "Trackball";
369         ot->description= "Trackball style rotation of selected items.";
370         ot->idname = OP_TRACKBALL;
371         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
372
373         /* api callbacks */
374         ot->invoke = transform_invoke;
375         ot->exec   = transform_exec;
376         ot->modal  = transform_modal;
377         ot->cancel  = transform_cancel;
378         ot->poll   = ED_operator_areaactive;
379
380         RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "angle", "", -FLT_MAX, FLT_MAX);
381
382         Properties_Proportional(ot);
383
384         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
385 }
386
387 void TFM_OT_rotate(struct wmOperatorType *ot)
388 {
389         /* identifiers */
390         ot->name   = "Rotate";
391         ot->description= "Rotate selected items.";
392         ot->idname = OP_ROTATION;
393         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
394
395         /* api callbacks */
396         ot->invoke = transform_invoke;
397         ot->exec   = transform_exec;
398         ot->modal  = transform_modal;
399         ot->cancel  = transform_cancel;
400         ot->poll   = ED_operator_areaactive;
401
402         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
403
404         Properties_Proportional(ot);
405
406         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
407
408         Properties_Constraints(ot);
409
410         Properties_Snapping(ot, 0);
411 }
412
413 void TFM_OT_tilt(struct wmOperatorType *ot)
414 {
415         /* identifiers */
416         ot->name   = "Tilt";
417     /*optionals - 
418         "Tilt selected vertices."
419         "Specify an extra axis rotation for selected vertices of 3d curve." */
420         ot->description= "Tilt selected control vertices of 3d curve."; 
421         ot->idname = OP_TILT;
422         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
423
424         /* api callbacks */
425         ot->invoke = transform_invoke;
426         ot->exec   = transform_exec;
427         ot->modal  = transform_modal;
428         ot->cancel  = transform_cancel;
429         ot->poll   = ED_operator_editcurve;
430
431         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
432
433         Properties_Proportional(ot);
434
435         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
436
437         Properties_Constraints(ot);
438 }
439
440 void TFM_OT_warp(struct wmOperatorType *ot)
441 {
442         /* identifiers */
443         ot->name   = "Warp";
444         ot->description= "Warp selected items around the cursor.";
445         ot->idname = OP_WARP;
446         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
447
448         /* api callbacks */
449         ot->invoke = transform_invoke;
450         ot->exec   = transform_exec;
451         ot->modal  = transform_modal;
452         ot->cancel  = transform_cancel;
453         ot->poll   = ED_operator_areaactive;
454
455         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", 0, 1);
456
457         Properties_Proportional(ot);
458
459         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
460
461         // XXX Shear axis?
462 //      Properties_Constraints(ot);
463 }
464
465 void TFM_OT_shear(struct wmOperatorType *ot)
466 {
467         /* identifiers */
468         ot->name   = "Shear";
469         ot->description= "Shear selected items along the horizontal screen axis.";
470         ot->idname = OP_SHEAR;
471         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
472
473         /* api callbacks */
474         ot->invoke = transform_invoke;
475         ot->exec   = transform_exec;
476         ot->modal  = transform_modal;
477         ot->cancel  = transform_cancel;
478         ot->poll   = ED_operator_areaactive;
479
480         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
481
482         Properties_Proportional(ot);
483
484         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
485
486         // XXX Shear axis?
487 //      Properties_Constraints(ot);
488 }
489
490 void TFM_OT_shrink_fatten(struct wmOperatorType *ot)
491 {
492         /* identifiers */
493         ot->name   = "Shrink/Fatten";
494         ot->description= "Shrink/fatten selected vertices along normals.";
495         ot->idname = OP_SHRINK_FATTEN;
496         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
497
498         /* api callbacks */
499         ot->invoke = transform_invoke;
500         ot->exec   = transform_exec;
501         ot->modal  = transform_modal;
502         ot->cancel  = transform_cancel;
503         ot->poll   = ED_operator_editmesh;
504
505         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
506
507         Properties_Proportional(ot);
508
509         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
510 }
511
512 void TFM_OT_tosphere(struct wmOperatorType *ot)
513 {
514         /* identifiers */
515         ot->name   = "To Sphere";
516     //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" 
517         ot->description= "Move selected vertices outward in a spherical shape around mesh center.";
518         ot->idname = OP_TOSPHERE;
519         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
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_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
529
530         Properties_Proportional(ot);
531
532         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
533 }
534
535 void TFM_OT_mirror(struct wmOperatorType *ot)
536 {
537         /* identifiers */
538         ot->name   = "Mirror";
539         ot->description= "Mirror selected vertices around one or more axes.";
540         ot->idname = OP_MIRROR;
541         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
542
543         /* api callbacks */
544         ot->invoke = transform_invoke;
545         ot->exec   = transform_exec;
546         ot->modal  = transform_modal;
547         ot->cancel  = transform_cancel;
548         ot->poll   = ED_operator_areaactive;
549
550         Properties_Proportional(ot);
551         Properties_Constraints(ot);
552 }
553
554 void TFM_OT_edge_slide(struct wmOperatorType *ot)
555 {
556         /* identifiers */
557         ot->name   = "Edge Slide";
558         ot->description= "Slide an edge loop along a mesh."; 
559         ot->idname = OP_EDGE_SLIDE;
560         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
561
562         /* api callbacks */
563         ot->invoke = transform_invoke;
564         ot->exec   = transform_exec;
565         ot->modal  = transform_modal;
566         ot->cancel  = transform_cancel;
567         ot->poll   = ED_operator_editmesh;
568
569         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
570
571         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
572 }
573
574 void TFM_OT_transform(struct wmOperatorType *ot)
575 {
576         static EnumPropertyItem transform_mode_types[] = {
577                         {TFM_INIT, "INIT", 0, "Init", ""},
578                         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
579                         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
580                         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
581                         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
582                         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
583                         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
584                         {TFM_WARP, "WARP", 0, "Warp", ""},
585                         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
586                         {TFM_TILT, "TILT", 0, "Tilt", ""},
587                         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
588                         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
589                         {TFM_CREASE, "CREASE", 0, "Crease", ""},
590                         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
591                         {TFM_BONESIZE, "BONESIZE", 0, "Bonesize", ""},
592                         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
593                         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
594                         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
595                         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
596                         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
597                         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
598                         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
599                         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
600                         {TFM_BEVEL, "BEVEL", 0, "Bevel", ""},
601                         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
602                         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
603                         {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
604                         {0, NULL, 0, NULL, NULL}
605         };
606
607         /* identifiers */
608         ot->name   = "Transform";
609         ot->description= "Transform selected items by mode type.";
610         ot->idname = "TFM_OT_transform";
611         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
612
613         /* api callbacks */
614         ot->invoke = transform_invoke;
615         ot->exec   = transform_exec;
616         ot->modal  = transform_modal;
617         ot->cancel  = transform_cancel;
618         ot->poll   = ED_operator_areaactive;
619
620         RNA_def_enum(ot->srna, "mode", transform_mode_types, 0, "Mode", "");
621
622         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
623
624         Properties_Proportional(ot);
625         RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
626
627         Properties_Constraints(ot);
628 }
629
630 void transform_operatortypes(void)
631 {
632         WM_operatortype_append(TFM_OT_transform);
633         WM_operatortype_append(TFM_OT_translate);
634         WM_operatortype_append(TFM_OT_rotate);
635         WM_operatortype_append(TFM_OT_tosphere);
636         WM_operatortype_append(TFM_OT_resize);
637         WM_operatortype_append(TFM_OT_shear);
638         WM_operatortype_append(TFM_OT_warp);
639         WM_operatortype_append(TFM_OT_shrink_fatten);
640         WM_operatortype_append(TFM_OT_tilt);
641         WM_operatortype_append(TFM_OT_trackball);
642         WM_operatortype_append(TFM_OT_mirror);
643         WM_operatortype_append(TFM_OT_edge_slide);
644
645         WM_operatortype_append(TFM_OT_select_orientation);
646 }
647
648 void transform_keymap_for_space(struct wmWindowManager *wm, struct wmKeyMap *keymap, int spaceid)
649 {
650         wmKeymapItem *km;
651         
652         /* transform.c, only adds modal map once, checks if it's there */
653         transform_modal_keymap(wm);
654         
655         switch(spaceid)
656         {
657                 case SPACE_VIEW3D:
658                         km = WM_keymap_add_item(keymap, "TFM_OT_translate", GKEY, KM_PRESS, 0, 0);
659
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
666                         km = WM_keymap_add_item(keymap, "TFM_OT_warp", WKEY, KM_PRESS, KM_SHIFT, 0);
667
668                         km = WM_keymap_add_item(keymap, "TFM_OT_tosphere", SKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
669
670                         km = WM_keymap_add_item(keymap, "TFM_OT_shear", SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0);
671
672                         km = WM_keymap_add_item(keymap, "TFM_OT_shrink_fatten", SKEY, KM_PRESS, KM_ALT, 0);
673
674                         km = WM_keymap_add_item(keymap, "TFM_OT_tilt", TKEY, KM_PRESS, 0, 0);
675
676                         km = WM_keymap_add_item(keymap, "TFM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
677
678                         break;
679                 case SPACE_ACTION:
680                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0);
681                         RNA_int_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
682
683                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
684                         RNA_int_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
685
686                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0);
687                         RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND);
688
689                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, 0, 0);
690                         RNA_int_set(km->ptr, "mode", TFM_TIME_SCALE);
691
692                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", TKEY, KM_PRESS, 0, 0);
693                         RNA_int_set(km->ptr, "mode", TFM_TIME_SLIDE);
694                         break;
695                 case SPACE_IPO:
696                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", GKEY, KM_PRESS, 0, 0);
697
698                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
699
700                                 // XXX the 'mode' identifier here is not quite right
701                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0);
702                         RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND);
703
704                         km = WM_keymap_add_item(keymap, "TFM_OT_rotate", RKEY, KM_PRESS, 0, 0);
705
706                         km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
707                         break;
708                 case SPACE_NLA:
709                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0);
710                         RNA_int_set(km->ptr, "mode", TFM_TRANSLATION);
711                         
712                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
713                         RNA_int_set(km->ptr, "mode", TFM_TRANSLATION);
714                         
715                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0);
716                         RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND);
717                         
718                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", SKEY, KM_PRESS, 0, 0);
719                         RNA_int_set(km->ptr, "mode", TFM_TIME_SCALE);
720                         break;
721                 case SPACE_NODE:
722                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", GKEY, KM_PRESS, 0, 0);
723
724                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
725                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
726
727                         km = WM_keymap_add_item(keymap, "TFM_OT_rotate", RKEY, KM_PRESS, 0, 0);
728
729                         km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
730                         break;
731                 case SPACE_SEQ:
732                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", GKEY, KM_PRESS, 0, 0);
733
734                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
735
736                         km= WM_keymap_add_item(keymap, "TFM_OT_transform", EKEY, KM_PRESS, 0, 0);
737                         RNA_int_set(km->ptr, "mode", TFM_TIME_EXTEND);
738                         break;
739                 case SPACE_IMAGE:
740                         km = WM_keymap_add_item(keymap, "TFM_OT_translate", GKEY, KM_PRESS, 0, 0);
741
742                         km= WM_keymap_add_item(keymap, "TFM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
743
744                         km = WM_keymap_add_item(keymap, "TFM_OT_rotate", RKEY, KM_PRESS, 0, 0);
745
746                         km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0);
747
748                         km = WM_keymap_add_item(keymap, "TFM_OT_mirror", MKEY, KM_PRESS, 0, 0);
749                         break;
750                 default:
751                         break;
752         }
753 }
754