Merge branch 'blender2.8' into soc-2018-bevel
[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 #include "MEM_guardedalloc.h"
28
29 #include "DNA_mesh_types.h"
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32
33 #include "BLI_math.h"
34 #include "BLI_utildefines.h"
35
36 #include "BLT_translation.h"
37
38 #include "BKE_context.h"
39 #include "BKE_global.h"
40 #include "BKE_report.h"
41 #include "BKE_editmesh.h"
42
43 #include "RNA_access.h"
44 #include "RNA_define.h"
45 #include "RNA_enum_types.h"
46
47 #include "WM_api.h"
48 #include "WM_types.h"
49
50 #include "UI_interface.h"
51 #include "UI_resources.h"
52
53 #include "ED_screen.h"
54 /* for USE_LOOPSLIDE_HACK only */
55 #include "ED_mesh.h"
56
57 #include "transform.h"
58
59 typedef struct TransformModeItem {
60         const char *idname;
61         int mode;
62         void (*opfunc)(wmOperatorType *);
63 } TransformModeItem;
64
65 static const float VecOne[3] = {1, 1, 1};
66
67 static const char OP_TRANSLATION[] = "TRANSFORM_OT_translate";
68 static const char OP_ROTATION[] = "TRANSFORM_OT_rotate";
69 static const char OP_TOSPHERE[] = "TRANSFORM_OT_tosphere";
70 static const char OP_RESIZE[] = "TRANSFORM_OT_resize";
71 static const char OP_SKIN_RESIZE[] = "TRANSFORM_OT_skin_resize";
72 static const char OP_SHEAR[] = "TRANSFORM_OT_shear";
73 static const char OP_BEND[] = "TRANSFORM_OT_bend";
74 static const char OP_SHRINK_FATTEN[] = "TRANSFORM_OT_shrink_fatten";
75 static const char OP_PUSH_PULL[] = "TRANSFORM_OT_push_pull";
76 static const char OP_TILT[] = "TRANSFORM_OT_tilt";
77 static const char OP_TRACKBALL[] = "TRANSFORM_OT_trackball";
78 static const char OP_MIRROR[] = "TRANSFORM_OT_mirror";
79 static const char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide";
80 static const char OP_VERT_SLIDE[] = "TRANSFORM_OT_vert_slide";
81 static const char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease";
82 static const char OP_EDGE_BWEIGHT[] = "TRANSFORM_OT_edge_bevelweight";
83 static const char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide";
84 static const char OP_NORMAL_ROTATION[] = "TRANSFORM_OT_rotate_normal";
85
86 static void TRANSFORM_OT_translate(struct wmOperatorType *ot);
87 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot);
88 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot);
89 static void TRANSFORM_OT_resize(struct wmOperatorType *ot);
90 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot);
91 static void TRANSFORM_OT_shear(struct wmOperatorType *ot);
92 static void TRANSFORM_OT_bend(struct wmOperatorType *ot);
93 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot);
94 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot);
95 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot);
96 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot);
97 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot);
98 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot);
99 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot);
100 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot);
101 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot);
102 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot);
103 static void TRANSFORM_OT_rotate_normal(struct wmOperatorType *ot);
104
105 static TransformModeItem transform_modes[] =
106 {
107         {OP_TRANSLATION, TFM_TRANSLATION, TRANSFORM_OT_translate},
108         {OP_ROTATION, TFM_ROTATION, TRANSFORM_OT_rotate},
109         {OP_TOSPHERE, TFM_TOSPHERE, TRANSFORM_OT_tosphere},
110         {OP_RESIZE, TFM_RESIZE, TRANSFORM_OT_resize},
111         {OP_SKIN_RESIZE, TFM_SKIN_RESIZE, TRANSFORM_OT_skin_resize},
112         {OP_SHEAR, TFM_SHEAR, TRANSFORM_OT_shear},
113         {OP_BEND, TFM_BEND, TRANSFORM_OT_bend},
114         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN, TRANSFORM_OT_shrink_fatten},
115         {OP_PUSH_PULL, TFM_PUSHPULL, TRANSFORM_OT_push_pull},
116         {OP_TILT, TFM_TILT, TRANSFORM_OT_tilt},
117         {OP_TRACKBALL, TFM_TRACKBALL, TRANSFORM_OT_trackball},
118         {OP_MIRROR, TFM_MIRROR, TRANSFORM_OT_mirror},
119         {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide},
120         {OP_VERT_SLIDE, TFM_VERT_SLIDE, TRANSFORM_OT_vert_slide},
121         {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease},
122         {OP_EDGE_BWEIGHT, TFM_BWEIGHT, TRANSFORM_OT_edge_bevelweight},
123         {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide},
124         {OP_NORMAL_ROTATION, TFM_NORMAL_ROTATION, TRANSFORM_OT_rotate_normal},
125         {NULL, 0}
126 };
127
128 const EnumPropertyItem rna_enum_transform_mode_types[] =
129 {
130         {TFM_INIT, "INIT", 0, "Init", ""},
131         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
132         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
133         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
134         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
135         {TFM_SKIN_RESIZE, "SKIN_RESIZE", 0, "Skin Resize", ""},
136         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
137         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
138         {TFM_BEND, "BEND", 0, "Bend", ""},
139         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
140         {TFM_TILT, "TILT", 0, "Tilt", ""},
141         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
142         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
143         {TFM_CREASE, "CREASE", 0, "Crease", ""},
144         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
145         {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
146         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
147         {TFM_BONE_ENVELOPE_DIST, "BONE_ENVELOPE_DIST", 0, "Bone_Envelope_Distance", ""},
148         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
149         {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""},
150         {TFM_GPENCIL_SHRINKFATTEN, "GPENCIL_SHRINKFATTEN", 0, "GPencil_Shrinkfatten", ""},
151         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
152         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
153         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
154         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
155         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
156         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
157         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
158         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
159         {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
160         {TFM_SEQ_SLIDE, "SEQSLIDE", 0, "Sequence Slide", ""},
161         {0, NULL, 0, NULL, NULL}
162 };
163
164 static int select_orientation_exec(bContext *C, wmOperator *op)
165 {
166         Scene *scene = CTX_data_scene(C);
167         int orientation = RNA_enum_get(op->ptr, "orientation");
168
169         BIF_selectTransformOrientationValue(scene, orientation);
170
171         WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
172
173         return OPERATOR_FINISHED;
174 }
175
176 static int select_orientation_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
177 {
178         uiPopupMenu *pup;
179         uiLayout *layout;
180
181         pup = UI_popup_menu_begin(C, IFACE_("Orientation"), ICON_NONE);
182         layout = UI_popup_menu_layout(pup);
183         uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
184         UI_popup_menu_end(C, pup);
185
186         return OPERATOR_INTERFACE;
187 }
188
189 static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
190 {
191         PropertyRNA *prop;
192
193         /* identifiers */
194         ot->name   = "Select Orientation";
195         ot->description = "Select transformation orientation";
196         ot->idname = "TRANSFORM_OT_select_orientation";
197         ot->flag   = OPTYPE_UNDO;
198
199         /* api callbacks */
200         ot->invoke = select_orientation_invoke;
201         ot->exec   = select_orientation_exec;
202         ot->poll   = ED_operator_view3d_active;
203
204         prop = RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
205         RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
206         RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
207 }
208
209
210 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
211 {
212         Scene *scene = CTX_data_scene(C);
213         BIF_removeTransformOrientationIndex(C, scene->orientation_index_custom);
214
215         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
216
217         return OPERATOR_FINISHED;
218 }
219
220 static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
221 {
222         return delete_orientation_exec(C, op);
223 }
224
225 static int delete_orientation_poll(bContext *C)
226 {
227         Scene *scene = CTX_data_scene(C);
228
229         if (ED_operator_areaactive(C) == 0)
230                 return 0;
231
232         return (scene->orientation_type >= V3D_MANIP_CUSTOM) && (scene->orientation_index_custom != -1);
233 }
234
235 static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
236 {
237         /* identifiers */
238         ot->name   = "Delete Orientation";
239         ot->description = "Delete transformation orientation";
240         ot->idname = "TRANSFORM_OT_delete_orientation";
241         ot->flag   = OPTYPE_UNDO;
242
243         /* api callbacks */
244         ot->invoke = delete_orientation_invoke;
245         ot->exec   = delete_orientation_exec;
246         ot->poll   = delete_orientation_poll;
247 }
248
249 static int create_orientation_exec(bContext *C, wmOperator *op)
250 {
251         char name[MAX_NAME];
252         const bool use = RNA_boolean_get(op->ptr, "use");
253         const bool overwrite = RNA_boolean_get(op->ptr, "overwrite");
254         const bool use_view = RNA_boolean_get(op->ptr, "use_view");
255         View3D *v3d = CTX_wm_view3d(C);
256
257         RNA_string_get(op->ptr, "name", name);
258
259         if (use && !v3d) {
260                 BKE_report(op->reports, RPT_ERROR, "Create Orientation's 'use' parameter only valid in a 3DView context");
261                 return OPERATOR_CANCELLED;
262         }
263
264         BIF_createTransformOrientation(C, op->reports, name, use_view, use, overwrite);
265
266         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
267         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
268
269         return OPERATOR_FINISHED;
270 }
271
272 static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
273 {
274         /* identifiers */
275         ot->name   = "Create Orientation";
276         ot->description = "Create transformation orientation from selection";
277         ot->idname = "TRANSFORM_OT_create_orientation";
278         ot->flag   = OPTYPE_REGISTER | OPTYPE_UNDO;
279
280         /* api callbacks */
281         ot->exec   = create_orientation_exec;
282         ot->poll   = ED_operator_areaactive;
283
284         RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the new custom orientation");
285         RNA_def_boolean(ot->srna, "use_view", false, "Use View",
286                         "Use the current view instead of the active object to create the new orientation");
287
288         WM_operatortype_props_advanced_begin(ot);
289
290         RNA_def_boolean(ot->srna, "use", false, "Use after creation", "Select orientation after its creation");
291         RNA_def_boolean(ot->srna, "overwrite", false, "Overwrite previous",
292                         "Overwrite previously created orientation with same name");
293 }
294
295
296 #ifdef USE_LOOPSLIDE_HACK
297 /**
298  * Special hack for MESH_OT_loopcut_slide so we get back to the selection mode
299  */
300 static void transformops_loopsel_hack(bContext *C, wmOperator *op)
301 {
302         if (op->type->idname == OP_EDGE_SLIDE) {
303                 if (op->opm && op->opm->opm && op->opm->opm->prev) {
304                         wmOperator *op_prev = op->opm->opm->prev;
305                         Scene *scene = CTX_data_scene(C);
306                         int mesh_select_mode[3];
307                         PropertyRNA *prop = RNA_struct_find_property(op_prev->ptr, "mesh_select_mode_init");
308
309                         if (prop && RNA_property_is_set(op_prev->ptr, prop)) {
310                                 ToolSettings *ts = scene->toolsettings;
311                                 short selectmode_orig;
312
313                                 RNA_property_boolean_get_array(op_prev->ptr, prop, mesh_select_mode);
314                                 selectmode_orig = ((mesh_select_mode[0] ? SCE_SELECT_VERTEX : 0) |
315                                                    (mesh_select_mode[1] ? SCE_SELECT_EDGE   : 0) |
316                                                    (mesh_select_mode[2] ? SCE_SELECT_FACE   : 0));
317
318                                 /* still switch if we were originally in face select mode */
319                                 if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
320                                         Object *obedit = CTX_data_edit_object(C);
321                                         BMEditMesh *em = BKE_editmesh_from_object(obedit);
322                                         em->selectmode = ts->selectmode = selectmode_orig;
323                                         EDBM_selectmode_set(em);
324                                 }
325                         }
326                 }
327         }
328 }
329 #else
330 /* prevent removal by cleanup */
331 #  error "loopslide hack removed!"
332 #endif  /* USE_LOOPSLIDE_HACK */
333
334
335 static void transformops_exit(bContext *C, wmOperator *op)
336 {
337 #ifdef USE_LOOPSLIDE_HACK
338         transformops_loopsel_hack(C, op);
339 #endif
340
341         saveTransform(C, op->customdata, op);
342         MEM_freeN(op->customdata);
343         op->customdata = NULL;
344         G.moving = 0;
345 }
346
347 static int transformops_data(bContext *C, wmOperator *op, const wmEvent *event)
348 {
349         int retval = 1;
350         if (op->customdata == NULL) {
351                 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
352                 TransformModeItem *tmode;
353                 int mode = -1;
354
355                 for (tmode = transform_modes; tmode->idname; tmode++) {
356                         if (op->type->idname == tmode->idname) {
357                                 mode = tmode->mode;
358                                 break;
359                         }
360                 }
361
362                 if (mode == -1) {
363                         mode = RNA_enum_get(op->ptr, "mode");
364                 }
365
366                 retval = initTransform(C, t, op, event, mode);
367
368                 /* store data */
369                 if (retval) {
370                         G.moving = special_transform_moving(t);
371                         op->customdata = t;
372                 }
373                 else {
374                         MEM_freeN(t);
375                 }
376         }
377
378         return retval; /* return 0 on error */
379 }
380
381 static int transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
382 {
383         int exit_code;
384
385         TransInfo *t = op->customdata;
386         const enum TfmMode mode_prev = t->mode;
387
388 #if defined(WITH_INPUT_NDOF) && 0
389         // stable 2D mouse coords map to different 3D coords while the 3D mouse is active
390         // in other words, 2D deltas are no longer good enough!
391         // disable until individual 'transformers' behave better
392
393         if (event->type == NDOF_MOTION)
394                 return OPERATOR_PASS_THROUGH;
395 #endif
396
397         /* XXX insert keys are called here, and require context */
398         t->context = C;
399         exit_code = transformEvent(t, event);
400         t->context = NULL;
401
402         /* XXX, workaround: active needs to be calculated before transforming,
403          * since we're not reading from 'td->center' in this case. see: T40241 */
404         if (t->tsnap.target == SCE_SNAP_TARGET_ACTIVE) {
405                 /* In camera view, tsnap callback is not set (see initSnappingMode() in transfrom_snap.c, and T40348). */
406                 if (t->tsnap.targetSnap && ((t->tsnap.status & TARGET_INIT) == 0)) {
407                         t->tsnap.targetSnap(t);
408                 }
409         }
410
411         transformApply(C, t);
412
413         exit_code |= transformEnd(C, t);
414
415         if ((exit_code & OPERATOR_RUNNING_MODAL) == 0) {
416                 transformops_exit(C, op);
417                 exit_code &= ~OPERATOR_PASS_THROUGH; /* preventively remove passthrough */
418         }
419         else {
420                 if (mode_prev != t->mode) {
421                         /* WARNING: this is not normal to switch operator types
422                          * normally it would not be supported but transform happens
423                          * to share callbacks between different operators. */
424                         wmOperatorType *ot_new = NULL;
425                         TransformModeItem *item = transform_modes;
426                         while (item->idname) {
427                                 if (item->mode == t->mode) {
428                                         ot_new = WM_operatortype_find(item->idname, false);
429                                         break;
430                                 }
431                                 item++;
432                         }
433
434                         BLI_assert(ot_new != NULL);
435                         if (ot_new) {
436                                 WM_operator_type_set(op, ot_new);
437                         }
438                         /* end suspicious code */
439                 }
440         }
441
442         return exit_code;
443 }
444
445 static void transform_cancel(bContext *C, wmOperator *op)
446 {
447         TransInfo *t = op->customdata;
448
449         t->state = TRANS_CANCEL;
450         transformEnd(C, t);
451         transformops_exit(C, op);
452 }
453
454 static int transform_exec(bContext *C, wmOperator *op)
455 {
456         TransInfo *t;
457
458         if (!transformops_data(C, op, NULL)) {
459                 G.moving = 0;
460                 return OPERATOR_CANCELLED;
461         }
462
463         t = op->customdata;
464
465         t->options |= CTX_AUTOCONFIRM;
466
467         transformApply(C, t);
468
469         transformEnd(C, t);
470
471         transformops_exit(C, op);
472
473         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
474
475         return OPERATOR_FINISHED;
476 }
477
478 static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
479 {
480         if (!transformops_data(C, op, event)) {
481                 G.moving = 0;
482                 return OPERATOR_CANCELLED;
483         }
484
485         /* When modal, allow 'value' to set initial offset. */
486         if ((event == NULL) &&
487             RNA_struct_property_is_set(op->ptr, "value"))
488         {
489                 return transform_exec(C, op);
490         }
491         else {
492                 /* add temp handler */
493                 WM_event_add_modal_handler(C, op);
494
495                 op->flag |= OP_IS_MODAL_GRAB_CURSOR; // XXX maybe we want this with the manipulator only?
496
497                 /* Use when modal input has some transformation to begin with. */
498                 {
499                         TransInfo *t = op->customdata;
500                         if (UNLIKELY(!is_zero_v4(t->values_modal_offset))) {
501                                 transformApply(C, t);
502                         }
503                 }
504
505                 return OPERATOR_RUNNING_MODAL;
506         }
507 }
508
509 void Transform_Properties(struct wmOperatorType *ot, int flags)
510 {
511         PropertyRNA *prop;
512
513         if (flags & P_AXIS) {
514                 prop = RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
515                 RNA_def_property_array(prop, 3);
516                 /* Make this not hidden when there's a nice axis selection widget */
517                 RNA_def_property_flag(prop, PROP_HIDDEN);
518                 RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
519         }
520
521         if (flags & P_CONSTRAINT) {
522                 RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
523                 prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
524                 RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
525                 RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
526         }
527
528         if (flags & P_MIRROR) {
529                 prop = RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
530                 if (flags & P_MIRROR_DUMMY) {
531                         /* only used so macros can disable this option */
532                         RNA_def_property_flag(prop, PROP_HIDDEN);
533                 }
534         }
535
536
537         if (flags & P_PROPORTIONAL) {
538                 RNA_def_enum(ot->srna, "proportional", rna_enum_proportional_editing_items, 0, "Proportional Editing", "");
539                 prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", rna_enum_proportional_falloff_items, 0,
540                                     "Proportional Editing Falloff", "Falloff type for proportional editing mode");
541                 RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
542                 RNA_def_float(ot->srna, "proportional_size", 1, T_PROP_SIZE_MIN, T_PROP_SIZE_MAX,
543                               "Proportional Size", "", 0.001f, 100.0f);
544         }
545
546         if (flags & P_SNAP) {
547                 prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
548                 RNA_def_property_flag(prop, PROP_HIDDEN);
549
550                 if (flags & P_GEO_SNAP) {
551                         prop = RNA_def_enum(ot->srna, "snap_target", rna_enum_snap_target_items, 0, "Target", "");
552                         RNA_def_property_flag(prop, PROP_HIDDEN);
553                         prop = RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
554                         RNA_def_property_flag(prop, PROP_HIDDEN);
555
556                         if (flags & P_ALIGN_SNAP) {
557                                 prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
558                                 RNA_def_property_flag(prop, PROP_HIDDEN);
559                                 prop = RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
560                                 RNA_def_property_flag(prop, PROP_HIDDEN);
561                         }
562                 }
563         }
564
565         if (flags & P_GPENCIL_EDIT) {
566                 RNA_def_boolean(ot->srna, "gpencil_strokes", 0, "Edit Grease Pencil", "Edit selected Grease Pencil strokes");
567         }
568
569         if (flags & P_CURSOR_EDIT) {
570                 RNA_def_boolean(ot->srna, "cursor_transform", 0, "Transform Cursor", "");
571         }
572
573         if ((flags & P_OPTIONS) && !(flags & P_NO_TEXSPACE)) {
574                 RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
575                 prop = RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
576                 RNA_def_property_flag(prop, PROP_HIDDEN);
577         }
578
579         if (flags & P_CORRECT_UV) {
580                 RNA_def_boolean(ot->srna, "correct_uv", true, "Correct UVs", "Correct UV coordinates when transforming");
581         }
582
583         if (flags & P_CENTER) {
584                 /* For manipulators that define their own center. */
585                 prop = RNA_def_property(ot->srna, "center_override", PROP_FLOAT, PROP_XYZ);
586                 RNA_def_property_array(prop, 3);
587                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
588                 RNA_def_property_ui_text(prop, "Center Override", "Force using this center value (when set)");
589         }
590
591         if ((flags & P_NO_DEFAULTS) == 0) {
592                 prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
593                 RNA_def_property_flag(prop, PROP_HIDDEN);
594
595                 prop = RNA_def_boolean(ot->srna, "use_accurate", 0, "Accurate", "Use accurate transformation");
596                 RNA_def_property_flag(prop, PROP_HIDDEN);
597         }
598 }
599
600 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
601 {
602         /* identifiers */
603         ot->name   = "Translate";
604         ot->description = "Translate (move) selected items";
605         ot->idname = OP_TRANSLATION;
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_screenactive;
614
615         RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
616
617         WM_operatortype_props_advanced_begin(ot);
618
619         Transform_Properties(
620                 ot,
621                 P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS |
622                 P_GPENCIL_EDIT | P_CURSOR_EDIT);
623 }
624
625 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
626 {
627         /* identifiers */
628         ot->name   = "Resize";
629         ot->description = "Scale (resize) selected items";
630         ot->idname = OP_RESIZE;
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_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
641
642         WM_operatortype_props_advanced_begin(ot);
643
644         Transform_Properties(
645                 ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CENTER);
646 }
647
648 static int skin_resize_poll(bContext *C)
649 {
650         struct Object *obedit = CTX_data_edit_object(C);
651         if (obedit && obedit->type == OB_MESH) {
652                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
653                 return (em && CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN));
654         }
655         return 0;
656 }
657
658 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
659 {
660         /* identifiers */
661         ot->name   = "Skin Resize";
662         ot->description = "Scale selected vertices' skin radii";
663         ot->idname = OP_SKIN_RESIZE;
664         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
665
666         /* api callbacks */
667         ot->invoke = transform_invoke;
668         ot->exec   = transform_exec;
669         ot->modal  = transform_modal;
670         ot->cancel = transform_cancel;
671         ot->poll   = skin_resize_poll;
672
673         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
674
675         WM_operatortype_props_advanced_begin(ot);
676
677         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
678 }
679
680 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
681 {
682         /* identifiers */
683         ot->name   = "Trackball";
684         ot->description = "Trackball style rotation of selected items";
685         ot->idname = OP_TRACKBALL;
686         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
687
688         /* api callbacks */
689         ot->invoke = transform_invoke;
690         ot->exec   = transform_exec;
691         ot->modal  = transform_modal;
692         ot->cancel = transform_cancel;
693         ot->poll   = ED_operator_screenactive;
694
695         /* Maybe we could use float_vector_xyz here too? */
696         RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
697
698         WM_operatortype_props_advanced_begin(ot);
699
700         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
701 }
702
703 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
704 {
705         /* identifiers */
706         ot->name = "Rotate";
707         ot->description = "Rotate selected items";
708         ot->idname = OP_ROTATION;
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_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
719
720         WM_operatortype_props_advanced_begin(ot);
721
722         Transform_Properties(
723                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT | P_CENTER);
724 }
725
726 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
727 {
728         /* identifiers */
729         ot->name = "Tilt";
730         /* optional -
731          * "Tilt selected vertices"
732          * "Specify an extra axis rotation for selected vertices of 3D curve" */
733         ot->description = "Tilt selected control vertices of 3D curve";
734         ot->idname = OP_TILT;
735         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
736
737         /* api callbacks */
738         ot->invoke = transform_invoke;
739         ot->exec   = transform_exec;
740         ot->modal  = transform_modal;
741         ot->cancel = transform_cancel;
742         ot->poll   = ED_operator_editcurve_3d;
743
744         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
745
746         WM_operatortype_props_advanced_begin(ot);
747
748         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
749 }
750
751 static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
752 {
753         /* identifiers */
754         ot->name   = "Bend";
755         ot->description = "Bend selected items between the 3D cursor and the mouse";
756         ot->idname = OP_BEND;
757         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
758
759         /* api callbacks */
760         ot->invoke = transform_invoke;
761         // ot->exec   = transform_exec;  // unsupported
762         ot->modal  = transform_modal;
763         ot->cancel = transform_cancel;
764         ot->poll   = ED_operator_region_view3d_active;
765
766         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
767
768         WM_operatortype_props_advanced_begin(ot);
769
770         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
771 }
772
773 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
774 {
775         /* identifiers */
776         ot->name   = "Shear";
777         ot->description = "Shear selected items along the horizontal screen axis";
778         ot->idname = OP_SHEAR;
779         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
780
781         /* api callbacks */
782         ot->invoke = transform_invoke;
783         ot->exec   = transform_exec;
784         ot->modal  = transform_modal;
785         ot->cancel = transform_cancel;
786         ot->poll   = ED_operator_screenactive;
787
788         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
789
790         WM_operatortype_props_advanced_begin(ot);
791
792         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
793         // XXX Shear axis?
794 }
795
796 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
797 {
798         /* identifiers */
799         ot->name   = "Push/Pull";
800         ot->description = "Push/Pull selected items";
801         ot->idname = OP_PUSH_PULL;
802         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
803
804         /* api callbacks */
805         ot->invoke = transform_invoke;
806         ot->exec   = transform_exec;
807         ot->modal  = transform_modal;
808         ot->cancel = transform_cancel;
809         ot->poll   = ED_operator_screenactive;
810
811         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
812
813         WM_operatortype_props_advanced_begin(ot);
814
815         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_CENTER);
816 }
817
818 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
819 {
820         /* identifiers */
821         ot->name   = "Shrink/Fatten";
822         ot->description = "Shrink/fatten selected vertices along normals";
823         ot->idname = OP_SHRINK_FATTEN;
824         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
825
826         /* api callbacks */
827         ot->invoke = transform_invoke;
828         ot->exec   = transform_exec;
829         ot->modal  = transform_modal;
830         ot->cancel = transform_cancel;
831         ot->poll   = ED_operator_editmesh;
832
833         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
834
835         RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness");
836
837         WM_operatortype_props_advanced_begin(ot);
838
839         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
840 }
841
842 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
843 {
844         /* identifiers */
845         ot->name   = "To Sphere";
846         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()"
847         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
848         ot->idname = OP_TOSPHERE;
849         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
850
851         /* api callbacks */
852         ot->invoke = transform_invoke;
853         ot->exec   = transform_exec;
854         ot->modal  = transform_modal;
855         ot->cancel = transform_cancel;
856         ot->poll   = ED_operator_screenactive;
857
858         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
859
860         WM_operatortype_props_advanced_begin(ot);
861
862         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
863 }
864
865 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
866 {
867         /* identifiers */
868         ot->name   = "Mirror";
869         ot->description = "Mirror selected items around one or more axes";
870         ot->idname = OP_MIRROR;
871         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
872
873         /* api callbacks */
874         ot->invoke = transform_invoke;
875         ot->exec   = transform_exec;
876         ot->modal  = transform_modal;
877         ot->cancel = transform_cancel;
878         ot->poll   = ED_operator_screenactive;
879
880         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_GPENCIL_EDIT | P_CENTER);
881 }
882
883 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
884 {
885         PropertyRNA *prop;
886
887         /* identifiers */
888         ot->name   = "Edge Slide";
889         ot->description = "Slide an edge loop along a mesh";
890         ot->idname = OP_EDGE_SLIDE;
891         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
892
893         /* api callbacks */
894         ot->invoke = transform_invoke;
895         ot->exec   = transform_exec;
896         ot->modal  = transform_modal;
897         ot->cancel = transform_cancel;
898         ot->poll   = ED_operator_editmesh_region_view3d;
899
900         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
901
902         prop = RNA_def_boolean(ot->srna, "single_side", false, "Single Side", "");
903         RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
904         RNA_def_boolean(ot->srna, "use_even", false, "Even",
905                         "Make the edge loop match the shape of the adjacent edge loop");
906
907         WM_operatortype_props_advanced_begin(ot);
908
909         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
910                         "When Even mode is active, flips between the two adjacent edge loops");
911         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
912                         "Clamp within the edge extents");
913
914         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
915 }
916
917 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
918 {
919         /* identifiers */
920         ot->name   = "Vertex Slide";
921         ot->description = "Slide a vertex along a mesh";
922         ot->idname = OP_VERT_SLIDE;
923         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
924
925         /* api callbacks */
926         ot->invoke = transform_invoke;
927         ot->exec   = transform_exec;
928         ot->modal  = transform_modal;
929         ot->cancel = transform_cancel;
930         ot->poll   = ED_operator_editmesh_region_view3d;
931
932         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
933         RNA_def_boolean(ot->srna, "use_even", false, "Even",
934                         "Make the edge loop match the shape of the adjacent edge loop");
935
936         WM_operatortype_props_advanced_begin(ot);
937
938         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
939                         "When Even mode is active, flips between the two adjacent edge loops");
940         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
941                         "Clamp within the edge extents");
942
943         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
944 }
945
946 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
947 {
948         /* identifiers */
949         ot->name   = "Edge Crease";
950         ot->description = "Change the crease of edges";
951         ot->idname = OP_EDGE_CREASE;
952         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
953
954         /* api callbacks */
955         ot->invoke = transform_invoke;
956         ot->exec   = transform_exec;
957         ot->modal  = transform_modal;
958         ot->cancel = transform_cancel;
959         ot->poll   = ED_operator_editmesh;
960
961         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
962
963         WM_operatortype_props_advanced_begin(ot);
964
965         Transform_Properties(ot, P_SNAP);
966 }
967
968 static int edge_bevelweight_exec(bContext *C, wmOperator *op)
969 {
970         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
971
972         /* auto-enable bevel edge weight drawing, then chain to common transform code */
973         me->drawflag |= ME_DRAWBWEIGHTS;
974
975         return transform_exec(C, op);
976 }
977
978 static int edge_bevelweight_invoke(bContext *C, wmOperator *op, const wmEvent *event)
979 {
980         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
981
982         /* auto-enable bevel edge weight drawing, then chain to common transform code */
983         me->drawflag |= ME_DRAWBWEIGHTS;
984
985         return transform_invoke(C, op, event);
986 }
987
988
989 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
990 {
991         /* identifiers */
992         ot->name   = "Edge Bevel Weight";
993         ot->description = "Change the bevel weight of edges";
994         ot->idname = OP_EDGE_BWEIGHT;
995         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
996
997         /* api callbacks */
998         ot->invoke = edge_bevelweight_invoke;
999         ot->exec   = edge_bevelweight_exec;
1000         ot->modal  = transform_modal;
1001         ot->cancel = transform_cancel;
1002         ot->poll   = ED_operator_editmesh;
1003
1004         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
1005
1006         WM_operatortype_props_advanced_begin(ot);
1007
1008         Transform_Properties(ot, P_SNAP);
1009 }
1010
1011 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
1012 {
1013         /* identifiers */
1014         ot->name   = "Sequence Slide";
1015         ot->description = "Slide a sequence strip in time";
1016         ot->idname = OP_SEQ_SLIDE;
1017         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1018
1019         /* api callbacks */
1020         ot->invoke = transform_invoke;
1021         ot->exec   = transform_exec;
1022         ot->modal  = transform_modal;
1023         ot->cancel = transform_cancel;
1024         ot->poll   = ED_operator_sequencer_active;
1025
1026         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
1027
1028         WM_operatortype_props_advanced_begin(ot);
1029
1030         Transform_Properties(ot, P_SNAP);
1031 }
1032
1033 static void TRANSFORM_OT_rotate_normal(struct wmOperatorType *ot)
1034 {
1035         /* identifiers */
1036         ot->name = "Normal Rotate";
1037         ot->description = "Rotate split normal of selected items";
1038         ot->idname = OP_NORMAL_ROTATION;
1039         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1040
1041         /* api callbacks */
1042         ot->invoke = transform_invoke;
1043         ot->exec = transform_exec;
1044         ot->modal = transform_modal;
1045         ot->cancel = transform_cancel;
1046         ot->poll = ED_operator_editmesh_auto_smooth;
1047
1048         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
1049
1050         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_MIRROR);
1051 }
1052
1053
1054 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
1055 {
1056         PropertyRNA *prop;
1057
1058         /* identifiers */
1059         ot->name   = "Transform";
1060         ot->description = "Transform selected items by mode type";
1061         ot->idname = "TRANSFORM_OT_transform";
1062         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1063
1064         /* api callbacks */
1065         ot->invoke = transform_invoke;
1066         ot->exec   = transform_exec;
1067         ot->modal  = transform_modal;
1068         ot->cancel = transform_cancel;
1069         ot->poll   = ED_operator_screenactive;
1070
1071         prop = RNA_def_enum(ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
1072         RNA_def_property_flag(prop, PROP_HIDDEN);
1073
1074         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
1075
1076         WM_operatortype_props_advanced_begin(ot);
1077
1078         Transform_Properties(
1079                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT | P_CENTER);
1080 }
1081
1082 void transform_operatortypes(void)
1083 {
1084         TransformModeItem *tmode;
1085
1086         for (tmode = transform_modes; tmode->idname; tmode++) {
1087                 WM_operatortype_append(tmode->opfunc);
1088         }
1089
1090         WM_operatortype_append(TRANSFORM_OT_transform);
1091
1092         WM_operatortype_append(TRANSFORM_OT_select_orientation);
1093         WM_operatortype_append(TRANSFORM_OT_create_orientation);
1094         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
1095 }
1096
1097 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
1098 {
1099         wmKeyMapItem *kmi;
1100         wmKeyMap *modalmap;
1101
1102         /* transform.c, only adds modal map once, checks if it's there */
1103         modalmap = transform_modal_keymap(keyconf);
1104
1105         /* assign map to operators only the first time */
1106         if (modalmap) {
1107                 TransformModeItem *tmode;
1108
1109                 for (tmode = transform_modes; tmode->idname; tmode++) {
1110                         WM_modalkeymap_assign(modalmap, tmode->idname);
1111                 }
1112                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
1113         }
1114
1115         switch (spaceid) {
1116                 case SPACE_VIEW3D:
1117                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1118
1119                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1120
1121                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1122
1123                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1124
1125                         WM_keymap_add_item(keymap, OP_BEND, WKEY, KM_PRESS, KM_SHIFT, 0);
1126
1127                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
1128
1129                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1130
1131                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
1132
1133                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
1134                         RNA_boolean_set(kmi->ptr, "use", true);
1135
1136                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
1137
1138                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1139                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1140
1141                         /* Will fall-through to texture-space transform. */
1142                         kmi = WM_keymap_add_item(keymap, "OBJECT_OT_transform_axis_target", TKEY, KM_PRESS, KM_SHIFT, 0);
1143
1144                         kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
1145                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1146
1147                         kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
1148                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1149
1150                         WM_keymap_add_item(keymap, OP_SKIN_RESIZE, AKEY, KM_PRESS, KM_CTRL, 0);
1151
1152                         break;
1153                 case SPACE_ACTION:
1154                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1155                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1156
1157                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1158                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1159
1160                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1161                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1162
1163                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1164                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1165
1166                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
1167                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
1168                         break;
1169                 case SPACE_IPO:
1170                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1171
1172                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1173
1174                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1175                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1176
1177                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1178
1179                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1180                         break;
1181                 case SPACE_NLA:
1182                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1183                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1184
1185                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1186                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1187
1188                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1189                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1190
1191                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1192                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1193                         break;
1194                 case SPACE_NODE:
1195                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
1196                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
1197                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
1198                         /* NB: small trick: macro operator poll may fail due to library data edit,
1199                          * in that case the secondary regular operators are called with same keymap.
1200                          */
1201                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
1202                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1203                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
1204                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1205                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
1206                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1207
1208                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1209
1210                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1211
1212                         /* detach and translate */
1213                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", DKEY, KM_PRESS, KM_ALT, 0);
1214                         /* XXX release_confirm is set in the macro operator definition */
1215                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links_release", EVT_TWEAK_A, KM_ANY, KM_ALT, 0);
1216                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", EVT_TWEAK_S, KM_ANY, KM_ALT, 0);
1217
1218                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1219                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1220                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1221                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_node_element");
1222                         break;
1223                 case SPACE_SEQ:
1224                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
1225
1226                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
1227
1228                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1229                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1230                         break;
1231                 case SPACE_IMAGE:
1232                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1233
1234                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1235
1236                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1237
1238                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1239
1240                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1241
1242                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
1243
1244                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1245                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1246
1247                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1248                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_uv_element");
1249                         break;
1250                 case SPACE_CLIP:
1251                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1252                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1253                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1254                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1255                         break;
1256                 default:
1257                         break;
1258         }
1259 }
1260