Merging r38951 through r38987 from trunk into soc-2011-tomato
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): none yet.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 /** \file blender/editors/transform/transform_ops.c
26  *  \ingroup edtransform
27  */
28
29
30 #include "MEM_guardedalloc.h"
31
32 #include "DNA_scene_types.h"
33
34 #include "RNA_access.h"
35 #include "RNA_define.h"
36 #include "RNA_enum_types.h"
37
38 #include "BLI_math.h"
39 #include "BLI_utildefines.h"
40
41 #include "BKE_context.h"
42 #include "BKE_global.h"
43 #include "BKE_armature.h"
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 #include "UI_interface.h"
49 #include "UI_resources.h"
50
51 #include "ED_screen.h"
52
53 #include "transform.h"
54
55 typedef struct TransformModeItem
56 {
57         char *idname;
58         int             mode;
59         void (*opfunc)(wmOperatorType*);
60 } TransformModeItem;
61
62 static float VecOne[3] = {1, 1, 1};
63
64 static char OP_TRANSLATION[] = "TRANSFORM_OT_translate";
65 static char OP_ROTATION[] = "TRANSFORM_OT_rotate";
66 static char OP_TOSPHERE[] = "TRANSFORM_OT_tosphere";
67 static char OP_RESIZE[] = "TRANSFORM_OT_resize";
68 static char OP_SHEAR[] = "TRANSFORM_OT_shear";
69 static char OP_WARP[] = "TRANSFORM_OT_warp";
70 static char OP_SHRINK_FATTEN[] = "TRANSFORM_OT_shrink_fatten";
71 static char OP_PUSH_PULL[] = "TRANSFORM_OT_push_pull";
72 static char OP_TILT[] = "TRANSFORM_OT_tilt";
73 static char OP_TRACKBALL[] = "TRANSFORM_OT_trackball";
74 static char OP_MIRROR[] = "TRANSFORM_OT_mirror";
75 static char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide";
76 static char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease";
77 static char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide";
78
79 void TRANSFORM_OT_translate(struct wmOperatorType *ot);
80 void TRANSFORM_OT_rotate(struct wmOperatorType *ot);
81 void TRANSFORM_OT_tosphere(struct wmOperatorType *ot);
82 void TRANSFORM_OT_resize(struct wmOperatorType *ot);
83 void TRANSFORM_OT_shear(struct wmOperatorType *ot);
84 void TRANSFORM_OT_warp(struct wmOperatorType *ot);
85 void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot);
86 void TRANSFORM_OT_push_pull(struct wmOperatorType *ot);
87 void TRANSFORM_OT_tilt(struct wmOperatorType *ot);
88 void TRANSFORM_OT_trackball(struct wmOperatorType *ot);
89 void TRANSFORM_OT_mirror(struct wmOperatorType *ot);
90 void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot);
91 void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot);
92 void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot);
93
94 static TransformModeItem transform_modes[] =
95 {
96         {OP_TRANSLATION, TFM_TRANSLATION, TRANSFORM_OT_translate},
97         {OP_ROTATION, TFM_ROTATION, TRANSFORM_OT_rotate},
98         {OP_TOSPHERE, TFM_TOSPHERE, TRANSFORM_OT_tosphere},
99         {OP_RESIZE, TFM_RESIZE, TRANSFORM_OT_resize},
100         {OP_SHEAR, TFM_SHEAR, TRANSFORM_OT_shear},
101         {OP_WARP, TFM_WARP, TRANSFORM_OT_warp},
102         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN, TRANSFORM_OT_shrink_fatten},
103         {OP_PUSH_PULL, TFM_PUSHPULL, TRANSFORM_OT_push_pull},
104         {OP_TILT, TFM_TILT, TRANSFORM_OT_tilt},
105         {OP_TRACKBALL, TFM_TRACKBALL, TRANSFORM_OT_trackball},
106         {OP_MIRROR, TFM_MIRROR, TRANSFORM_OT_mirror},
107         {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide},
108         {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease},
109         {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide},
110         {NULL, 0}
111 };
112
113 EnumPropertyItem transform_mode_types[] =
114 {
115         {TFM_INIT, "INIT", 0, "Init", ""},
116         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
117         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
118         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
119         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
120         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
121         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
122         {TFM_WARP, "WARP", 0, "Warp", ""},
123         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
124         {TFM_TILT, "TILT", 0, "Tilt", ""},
125         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
126         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
127         {TFM_CREASE, "CREASE", 0, "Crease", ""},
128         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
129         {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
130         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
131         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
132         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
133         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
134         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
135         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
136         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
137         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
138         {TFM_BEVEL, "BEVEL", 0, "Bevel", ""},
139         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
140         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
141         {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
142         {TFM_SEQ_SLIDE, "SEQSLIDE", 0, "Sequence Slide", ""},
143         {0, NULL, 0, NULL, NULL}
144 };
145
146 static int snap_type_exec(bContext *C, wmOperator *op)
147 {
148         ToolSettings *ts= CTX_data_tool_settings(C);
149
150         ts->snap_mode = RNA_enum_get(op->ptr,"type");
151
152         WM_event_add_notifier(C, NC_SCENE|ND_TOOLSETTINGS, NULL); /* header redraw */
153
154         return OPERATOR_FINISHED;
155 }
156
157 static void TRANSFORM_OT_snap_type(wmOperatorType *ot)
158 {
159         /* identifiers */
160         ot->name= "Snap Type";
161         ot->description= "Set the snap element type";
162         ot->idname= "TRANSFORM_OT_snap_type";
163
164         /* api callbacks */
165         ot->invoke= WM_menu_invoke;
166         ot->exec= snap_type_exec;
167
168         ot->poll= ED_operator_areaactive;
169
170         /* flags */
171         ot->flag= OPTYPE_UNDO;
172
173         /* props */
174         ot->prop= RNA_def_enum(ot->srna, "type", snap_element_items, 0, "Type", "Set the snap element type");
175
176 }
177
178 static int select_orientation_exec(bContext *C, wmOperator *op)
179 {
180         int orientation = RNA_enum_get(op->ptr, "orientation");
181
182         BIF_selectTransformOrientationValue(C, orientation);
183         
184         WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
185
186         return OPERATOR_FINISHED;
187 }
188
189 static int select_orientation_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event))
190 {
191         uiPopupMenu *pup;
192         uiLayout *layout;
193
194         pup= uiPupMenuBegin(C, "Orientation", ICON_NONE);
195         layout= uiPupMenuLayout(pup);
196         uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
197         uiPupMenuEnd(C, pup);
198
199         return OPERATOR_CANCELLED;
200 }
201
202 static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
203 {
204         PropertyRNA *prop;
205
206         /* identifiers */
207         ot->name   = "Select Orientation";
208         ot->description= "Select transformation orientation";
209         ot->idname = "TRANSFORM_OT_select_orientation";
210         ot->flag   = OPTYPE_UNDO;
211
212         /* api callbacks */
213         ot->invoke = select_orientation_invoke;
214         ot->exec   = select_orientation_exec;
215         ot->poll   = ED_operator_view3d_active;
216
217         prop= RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
218         RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
219         RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
220 }
221
222
223 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
224 {
225         View3D *v3d = CTX_wm_view3d(C);
226         int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
227
228         BIF_removeTransformOrientationIndex(C, selected_index);
229         
230         WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
231         WM_event_add_notifier(C, NC_SCENE|NA_EDITED, CTX_data_scene(C));
232
233         return OPERATOR_FINISHED;
234 }
235
236 static int delete_orientation_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
237 {
238         return delete_orientation_exec(C, op);
239 }
240
241 static int delete_orientation_poll(bContext *C)
242 {
243         int selected_index = -1;
244         View3D *v3d = CTX_wm_view3d(C);
245         
246         if (ED_operator_areaactive(C) == 0)
247                 return 0;
248         
249         
250         if(v3d) {
251                 selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
252         }
253         
254         return selected_index >= 0;
255 }
256
257 static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
258 {
259         /* identifiers */
260         ot->name   = "Delete Orientation";
261         ot->description= "Delete transformation orientation";
262         ot->idname = "TRANSFORM_OT_delete_orientation";
263         ot->flag   = OPTYPE_UNDO;
264
265         /* api callbacks */
266         ot->invoke = delete_orientation_invoke;
267         ot->exec   = delete_orientation_exec;
268         ot->poll   = delete_orientation_poll;
269 }
270
271 static int create_orientation_exec(bContext *C, wmOperator *op)
272 {
273         char name[36];
274         int use = RNA_boolean_get(op->ptr, "use");
275         int overwrite = RNA_boolean_get(op->ptr, "overwrite");
276         
277         RNA_string_get(op->ptr, "name", name);
278
279         BIF_createTransformOrientation(C, op->reports, name, use, overwrite);
280
281         WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, CTX_wm_view3d(C));
282         WM_event_add_notifier(C, NC_SCENE|NA_EDITED, CTX_data_scene(C));
283         
284         return OPERATOR_FINISHED;
285 }
286
287 static int create_orientation_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
288 {
289         return create_orientation_exec(C, op);
290 }
291
292 static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
293 {
294         /* identifiers */
295         ot->name   = "Create Orientation";
296         ot->description= "Create transformation orientation from selection";
297         ot->idname = "TRANSFORM_OT_create_orientation";
298         ot->flag   = OPTYPE_REGISTER|OPTYPE_UNDO;
299
300         /* api callbacks */
301         ot->invoke = create_orientation_invoke;
302         ot->exec   = create_orientation_exec;
303         ot->poll   = ED_operator_areaactive;
304         ot->flag   = OPTYPE_REGISTER|OPTYPE_UNDO;
305
306         RNA_def_string(ot->srna, "name", "", 35, "Name", "Text to insert at the cursor position.");
307         RNA_def_boolean(ot->srna, "use", 0, "Use after creation", "Select orientation after its creation");
308         RNA_def_boolean(ot->srna, "overwrite", 0, "Overwrite previous", "Overwrite previously created orientation with same name");
309 }
310
311 static void transformops_exit(bContext *C, wmOperator *op)
312 {
313         saveTransform(C, op->customdata, op);
314         MEM_freeN(op->customdata);
315         op->customdata = NULL;
316         G.moving = 0;
317 }
318
319 static int transformops_data(bContext *C, wmOperator *op, wmEvent *event)
320 {
321         int retval = 1;
322         if (op->customdata == NULL)
323         {
324                 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
325                 TransformModeItem *tmode;
326                 int mode = -1;
327
328                 for (tmode = transform_modes; tmode->idname; tmode++)
329                 {
330                         if (op->type->idname == tmode->idname)
331                         {
332                                 mode = tmode->mode;
333                                 break;
334                         }
335                 }
336
337                 if (mode == -1)
338                 {
339                         mode = RNA_enum_get(op->ptr, "mode");
340                 }
341
342                 retval = initTransform(C, t, op, event, mode);
343                 G.moving = 1;
344
345                 /* store data */
346                 if(retval) {
347                         op->customdata = t;
348                 }
349                 else {
350                         MEM_freeN(t);
351                 }
352         }
353
354         return retval; /* return 0 on error */
355 }
356
357 static int transform_modal(bContext *C, wmOperator *op, wmEvent *event)
358 {
359         int exit_code;
360
361         TransInfo *t = op->customdata;
362
363         #if 0
364         // stable 2D mouse coords map to different 3D coords while the 3D mouse is active
365         // in other words, 2D deltas are no longer good enough!
366         // disable until individual 'transformers' behave better
367
368         if (event->type == NDOF_MOTION)
369         {
370                 /* puts("transform_modal: passing through NDOF_MOTION"); */
371                 return OPERATOR_PASS_THROUGH;
372         }
373         #endif
374
375         /* XXX insert keys are called here, and require context */
376         t->context= C;
377         exit_code = transformEvent(t, event);
378         t->context= NULL;
379
380         transformApply(C, t);
381
382         exit_code |= transformEnd(C, t);
383
384         if ((exit_code & OPERATOR_RUNNING_MODAL) == 0)
385         {
386                 transformops_exit(C, op);
387                 exit_code &= ~OPERATOR_PASS_THROUGH; /* preventively remove passthrough */
388         }
389
390         return exit_code;
391 }
392
393 static int transform_cancel(bContext *C, wmOperator *op)
394 {
395         TransInfo *t = op->customdata;
396
397         t->state = TRANS_CANCEL;
398         transformEnd(C, t);
399         transformops_exit(C, op);
400
401         return OPERATOR_CANCELLED;
402 }
403
404 static int transform_exec(bContext *C, wmOperator *op)
405 {
406         TransInfo *t;
407
408         if (!transformops_data(C, op, NULL))
409         {
410                 G.moving = 0;
411                 return OPERATOR_CANCELLED;
412         }
413
414         t = op->customdata;
415
416         t->options |= CTX_AUTOCONFIRM;
417
418         transformApply(C, t);
419
420         transformEnd(C, t);
421
422         transformops_exit(C, op);
423         
424         WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
425
426         return OPERATOR_FINISHED;
427 }
428
429 static int transform_invoke(bContext *C, wmOperator *op, wmEvent *event)
430 {
431         if (!transformops_data(C, op, event))
432         {
433                 G.moving = 0;
434                 return OPERATOR_CANCELLED;
435         }
436
437         if(RNA_property_is_set(op->ptr, "value")) {
438                 return transform_exec(C, op);
439         }
440         else {
441                 /* add temp handler */
442                 WM_event_add_modal_handler(C, op);
443
444                 op->flag |= OP_GRAB_POINTER; // XXX maybe we want this with the manipulator only?
445                 return OPERATOR_RUNNING_MODAL;
446         }
447 }
448
449 void Transform_Properties(struct wmOperatorType *ot, int flags)
450 {
451         PropertyRNA *prop;
452
453         if (flags & P_AXIS)
454         {
455                 prop= RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
456                 RNA_def_property_array(prop, 3);
457                 /* Make this not hidden when there's a nice axis selection widget */
458                 RNA_def_property_flag(prop, PROP_HIDDEN);
459                 RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
460
461         }
462
463         if (flags & P_CONSTRAINT)
464         {
465                 RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
466                 prop= RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
467                 RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
468                 RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
469
470                 
471         }
472
473         if (flags & P_MIRROR)
474         {
475                 RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
476         }
477
478
479         if (flags & P_PROPORTIONAL)
480         {
481                 RNA_def_enum(ot->srna, "proportional", proportional_editing_items, 0, "Proportional Editing", "");
482                 RNA_def_enum(ot->srna, "proportional_edit_falloff", proportional_falloff_items, 0, "Proportional Editing Falloff", "Falloff type for proportional editing mode.");
483                 RNA_def_float(ot->srna, "proportional_size", 1, 0.00001f, FLT_MAX, "Proportional Size", "", 0.001, 100);
484         }
485
486         if (flags & P_SNAP)
487         {
488                 prop= RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
489                 RNA_def_property_flag(prop, PROP_HIDDEN);
490
491                 if (flags & P_GEO_SNAP) {
492                         prop= RNA_def_enum(ot->srna, "snap_target", snap_target_items, 0, "Target", "");
493                         RNA_def_property_flag(prop, PROP_HIDDEN);
494                         prop= RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
495                         RNA_def_property_flag(prop, PROP_HIDDEN);
496                         
497                         if (flags & P_ALIGN_SNAP) {
498                                 prop= RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
499                                 RNA_def_property_flag(prop, PROP_HIDDEN);
500                                 prop= RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
501                                 RNA_def_property_flag(prop, PROP_HIDDEN);
502                         }
503                 }
504         }
505         
506         if (flags & P_OPTIONS)
507         {
508                 RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Object data texture space", "");
509         }
510
511         if (flags & P_CORRECT_UV)
512         {
513                 RNA_def_boolean(ot->srna, "correct_uv", 0, "Correct UV coords when transforming", "");
514         }
515
516         // Add confirm method all the time. At the end because it's not really that important and should be hidden only in log, not in keymap edit
517         /*prop =*/ RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
518         //RNA_def_property_flag(prop, PROP_HIDDEN);
519 }
520
521 void TRANSFORM_OT_translate(struct wmOperatorType *ot)
522 {
523         /* identifiers */
524         ot->name   = "Translate";
525         ot->description= "Translate selected items";
526         ot->idname = OP_TRANSLATION;
527         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
528
529         /* api callbacks */
530         ot->invoke = transform_invoke;
531         ot->exec   = transform_exec;
532         ot->modal  = transform_modal;
533         ot->cancel  = transform_cancel;
534         ot->poll   = ED_operator_screenactive;
535
536         RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
537
538         Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_ALIGN_SNAP|P_OPTIONS);
539 }
540
541 void TRANSFORM_OT_resize(struct wmOperatorType *ot)
542 {
543         /* identifiers */
544         ot->name   = "Resize";
545         ot->description= "Resize selected items"; 
546         ot->idname = OP_RESIZE;
547         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
548
549         /* api callbacks */
550         ot->invoke = transform_invoke;
551         ot->exec   = transform_exec;
552         ot->modal  = transform_modal;
553         ot->cancel  = transform_cancel;
554         ot->poll   = ED_operator_screenactive;
555
556         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
557
558         Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_GEO_SNAP|P_OPTIONS);
559 }
560
561
562 void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
563 {
564         /* identifiers */
565         ot->name   = "Trackball";
566         ot->description= "Trackball style rotation of selected items";
567         ot->idname = OP_TRACKBALL;
568         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
569
570         /* api callbacks */
571         ot->invoke = transform_invoke;
572         ot->exec   = transform_exec;
573         ot->modal  = transform_modal;
574         ot->cancel  = transform_cancel;
575         ot->poll   = ED_operator_screenactive;
576
577         RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "angle", "", -FLT_MAX, FLT_MAX);
578
579         Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
580 }
581
582 void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
583 {
584         /* identifiers */
585         ot->name   = "Rotate";
586         ot->description= "Rotate selected items";
587         ot->idname = OP_ROTATION;
588         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
589
590         /* api callbacks */
591         ot->invoke = transform_invoke;
592         ot->exec   = transform_exec;
593         ot->modal  = transform_modal;
594         ot->cancel  = transform_cancel;
595         ot->poll   = ED_operator_screenactive;
596
597         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
598
599         Transform_Properties(ot, P_AXIS|P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_GEO_SNAP);
600 }
601
602 void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
603 {
604         /* identifiers */
605         ot->name   = "Tilt";
606         /*optionals - 
607                 "Tilt selected vertices."
608                 "Specify an extra axis rotation for selected vertices of 3d curve." */
609         ot->description= "Tilt selected control vertices of 3d curve"; 
610         ot->idname = OP_TILT;
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_editcurve;
619
620         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI*2, M_PI*2);
621
622         Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_SNAP);
623 }
624
625 void TRANSFORM_OT_warp(struct wmOperatorType *ot)
626 {
627         /* identifiers */
628         ot->name   = "Warp";
629         ot->description= "Warp selected items around the cursor";
630         ot->idname = OP_WARP;
631         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
632
633         /* api callbacks */
634         ot->invoke = transform_invoke;
635         ot->exec   = transform_exec;
636         ot->modal  = transform_modal;
637         ot->cancel  = transform_cancel;
638         ot->poll   = ED_operator_screenactive;
639
640         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", 0, 1);
641
642         Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
643         // XXX Warp axis?
644 }
645
646 void TRANSFORM_OT_shear(struct wmOperatorType *ot)
647 {
648         /* identifiers */
649         ot->name   = "Shear";
650         ot->description= "Shear selected items along the horizontal screen axis";
651         ot->idname = OP_SHEAR;
652         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
653
654         /* api callbacks */
655         ot->invoke = transform_invoke;
656         ot->exec   = transform_exec;
657         ot->modal  = transform_modal;
658         ot->cancel  = transform_cancel;
659         ot->poll   = ED_operator_screenactive;
660
661         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
662
663         Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
664         // XXX Shear axis?
665 }
666
667 void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
668 {
669         /* identifiers */
670         ot->name   = "Push/Pull";
671         ot->description= "Push/Pull selected items";
672         ot->idname = OP_PUSH_PULL;
673         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
674
675         /* api callbacks */
676         ot->invoke = transform_invoke;
677         ot->exec   = transform_exec;
678         ot->modal  = transform_modal;
679         ot->cancel  = transform_cancel;
680         ot->poll   = ED_operator_screenactive;
681
682         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
683
684         Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
685 }
686
687 void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
688 {
689         /* identifiers */
690         ot->name   = "Shrink/Fatten";
691         ot->description= "Shrink/fatten selected vertices along normals";
692         ot->idname = OP_SHRINK_FATTEN;
693         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
694
695         /* api callbacks */
696         ot->invoke = transform_invoke;
697         ot->exec   = transform_exec;
698         ot->modal  = transform_modal;
699         ot->cancel  = transform_cancel;
700         ot->poll   = ED_operator_editmesh;
701
702         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
703
704         Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
705 }
706
707 void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
708 {
709         /* identifiers */
710         ot->name   = "To Sphere";
711         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" 
712         ot->description= "Move selected vertices outward in a spherical shape around mesh center";
713         ot->idname = OP_TOSPHERE;
714         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
715
716         /* api callbacks */
717         ot->invoke = transform_invoke;
718         ot->exec   = transform_exec;
719         ot->modal  = transform_modal;
720         ot->cancel  = transform_cancel;
721         ot->poll   = ED_operator_screenactive;
722
723         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
724
725         Transform_Properties(ot, P_PROPORTIONAL|P_MIRROR|P_SNAP);
726 }
727
728 void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
729 {
730         /* identifiers */
731         ot->name   = "Mirror";
732         ot->description= "Mirror selected vertices around one or more axes";
733         ot->idname = OP_MIRROR;
734         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
735
736         /* api callbacks */
737         ot->invoke = transform_invoke;
738         ot->exec   = transform_exec;
739         ot->modal  = transform_modal;
740         ot->cancel  = transform_cancel;
741         ot->poll   = ED_operator_screenactive;
742
743         Transform_Properties(ot, P_CONSTRAINT|P_PROPORTIONAL);
744 }
745
746 void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
747 {
748         /* identifiers */
749         ot->name   = "Edge Slide";
750         ot->description= "Slide an edge loop along a mesh"; 
751         ot->idname = OP_EDGE_SLIDE;
752         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
753
754         /* api callbacks */
755         ot->invoke = transform_invoke;
756         ot->exec   = transform_exec;
757         ot->modal  = transform_modal;
758         ot->cancel  = transform_cancel;
759         ot->poll   = ED_operator_editmesh;
760
761         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
762
763         Transform_Properties(ot, P_MIRROR|P_SNAP|P_CORRECT_UV);
764 }
765
766 void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
767 {
768         /* identifiers */
769         ot->name   = "Edge Crease";
770         ot->description= "Change the crease of edges";
771         ot->idname = OP_EDGE_CREASE;
772         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
773
774         /* api callbacks */
775         ot->invoke = transform_invoke;
776         ot->exec   = transform_exec;
777         ot->modal  = transform_modal;
778         ot->cancel  = transform_cancel;
779         ot->poll   = ED_operator_editmesh;
780
781         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
782
783         Transform_Properties(ot, P_SNAP);
784 }
785
786 void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
787 {
788         /* identifiers */
789         ot->name   = "Sequence Slide";
790         ot->description= "Slide a sequence strip in time";
791         ot->idname = OP_SEQ_SLIDE;
792         ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
793
794         /* api callbacks */
795         ot->invoke = transform_invoke;
796         ot->exec   = transform_exec;
797         ot->modal  = transform_modal;
798         ot->cancel  = transform_cancel;
799         ot->poll   = ED_operator_sequencer_active;
800
801         RNA_def_float_vector(ot->srna, "value", 2, VecOne, -FLT_MAX, FLT_MAX, "angle", "", -FLT_MAX, FLT_MAX);
802
803         Transform_Properties(ot, P_SNAP);
804 }
805
806 void TRANSFORM_OT_transform(struct wmOperatorType *ot)
807 {
808         PropertyRNA *prop;
809
810         /* identifiers */
811         ot->name   = "Transform";
812         ot->description= "Transform selected items by mode type";
813         ot->idname = "TRANSFORM_OT_transform";
814         ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
815
816         /* api callbacks */
817         ot->invoke = transform_invoke;
818         ot->exec   = transform_exec;
819         ot->modal  = transform_modal;
820         ot->cancel  = transform_cancel;
821         ot->poll   = ED_operator_screenactive;
822
823         prop= RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
824         RNA_def_property_flag(prop, PROP_HIDDEN);
825
826         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
827
828         Transform_Properties(ot, P_AXIS|P_CONSTRAINT|P_PROPORTIONAL|P_MIRROR|P_ALIGN_SNAP);
829 }
830
831 void transform_operatortypes(void)
832 {
833         TransformModeItem *tmode;
834
835         for (tmode = transform_modes; tmode->idname; tmode++)
836         {
837                 WM_operatortype_append(tmode->opfunc);
838         }
839
840         WM_operatortype_append(TRANSFORM_OT_transform);
841
842         WM_operatortype_append(TRANSFORM_OT_select_orientation);
843         WM_operatortype_append(TRANSFORM_OT_create_orientation);
844         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
845
846         WM_operatortype_append(TRANSFORM_OT_snap_type);
847 }
848
849 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
850 {
851         wmKeyMapItem *km;
852         wmKeyMap *modalmap;
853         
854         /* transform.c, only adds modal map once, checks if it's there */
855         modalmap = transform_modal_keymap(keyconf);
856
857         /* assign map to operators only the first time */
858         if (modalmap) {
859                 TransformModeItem *tmode;
860
861                 for (tmode = transform_modes; tmode->idname; tmode++)
862                 {
863                         WM_modalkeymap_assign(modalmap, tmode->idname);
864                 }
865                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
866         }
867         
868         switch(spaceid)
869         {
870                 case SPACE_VIEW3D:
871                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
872
873                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
874
875                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
876
877                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
878
879                         WM_keymap_add_item(keymap, OP_WARP, WKEY, KM_PRESS, KM_SHIFT, 0);
880
881                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0);
882
883                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0);
884
885                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
886
887                         km = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL|KM_ALT, 0);
888                         RNA_boolean_set(km->ptr, "use", 1);
889
890                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
891
892                         km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
893                         RNA_string_set(km->ptr, "data_path", "tool_settings.use_snap");
894
895                         WM_keymap_add_item(keymap, "TRANSFORM_OT_snap_type", TABKEY, KM_PRESS, KM_SHIFT|KM_CTRL, 0);
896
897                         km = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
898                         RNA_boolean_set(km->ptr, "texture_space", 1);
899
900                         km = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT|KM_ALT, 0);
901                         RNA_boolean_set(km->ptr, "texture_space", 1);
902
903                         break;
904                 case SPACE_ACTION:
905                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
906                         RNA_enum_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
907                         
908                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
909                         RNA_enum_set(km->ptr, "mode", TFM_TIME_TRANSLATE);
910                         
911                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
912                         RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
913                         
914                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
915                         RNA_enum_set(km->ptr, "mode", TFM_TIME_SCALE);
916                         
917                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, 0, 0);
918                         RNA_enum_set(km->ptr, "mode", TFM_TIME_SLIDE);
919                         break;
920                 case SPACE_IPO:
921                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
922                         
923                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
924                         
925                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
926                         RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
927                         
928                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
929                         
930                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
931                         break;
932                 case SPACE_NLA:
933                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
934                         RNA_enum_set(km->ptr, "mode", TFM_TRANSLATION);
935                         
936                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
937                         RNA_enum_set(km->ptr, "mode", TFM_TRANSLATION);
938                         
939                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
940                         RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
941                         
942                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
943                         RNA_enum_set(km->ptr, "mode", TFM_TIME_SCALE);
944                         break;
945                 case SPACE_NODE:
946                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
947
948                         km= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_A, KM_ANY, 0, 0);
949                         RNA_boolean_set(km->ptr, "release_confirm", 1);
950                         km= WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
951                         RNA_boolean_set(km->ptr, "release_confirm", 1);
952
953                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
954
955                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
956                         break;
957                 case SPACE_SEQ:
958                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
959
960                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
961
962                         km= WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
963                         RNA_enum_set(km->ptr, "mode", TFM_TIME_EXTEND);
964                         break;
965                 case SPACE_IMAGE:
966                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
967
968                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
969
970                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
971
972                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
973
974                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT|KM_CTRL|KM_SHIFT, 0);
975
976                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
977
978                         km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
979                         RNA_string_set(km->ptr, "data_path", "tool_settings.use_snap");
980                         break;
981                 case SPACE_CLIP:
982                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
983                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
984                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
985                         break;
986                 default:
987                         break;
988         }
989 }
990