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