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