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