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