Fix T61536: can't snap vertex to another vertex in edit mode using curves
[blender.git] / source / blender / editors / transform / transform_ops.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16
17 /** \file \ingroup edtransform
18  */
19
20 #include "MEM_guardedalloc.h"
21
22 #include "DNA_mesh_types.h"
23 #include "DNA_object_types.h"
24 #include "DNA_scene_types.h"
25
26 #include "BLI_math.h"
27 #include "BLI_utildefines.h"
28
29 #include "BLT_translation.h"
30
31 #include "BKE_context.h"
32 #include "BKE_global.h"
33 #include "BKE_report.h"
34 #include "BKE_editmesh.h"
35 #include "BKE_scene.h"
36
37 #include "RNA_access.h"
38 #include "RNA_define.h"
39 #include "RNA_enum_types.h"
40
41 #include "WM_api.h"
42 #include "WM_message.h"
43 #include "WM_types.h"
44 #include "WM_toolsystem.h"
45
46 #include "UI_interface.h"
47 #include "UI_resources.h"
48
49 #include "ED_screen.h"
50 /* for USE_LOOPSLIDE_HACK only */
51 #include "ED_mesh.h"
52
53 #include "transform.h"
54
55 typedef struct TransformModeItem {
56         const char *idname;
57         int mode;
58         void (*opfunc)(wmOperatorType *);
59 } TransformModeItem;
60
61 static const float VecOne[3] = {1, 1, 1};
62
63 static const char OP_TRANSLATION[] = "TRANSFORM_OT_translate";
64 static const char OP_ROTATION[] = "TRANSFORM_OT_rotate";
65 static const char OP_TOSPHERE[] = "TRANSFORM_OT_tosphere";
66 static const char OP_RESIZE[] = "TRANSFORM_OT_resize";
67 static const char OP_SKIN_RESIZE[] = "TRANSFORM_OT_skin_resize";
68 static const char OP_SHEAR[] = "TRANSFORM_OT_shear";
69 static const char OP_BEND[] = "TRANSFORM_OT_bend";
70 static const char OP_SHRINK_FATTEN[] = "TRANSFORM_OT_shrink_fatten";
71 static const char OP_PUSH_PULL[] = "TRANSFORM_OT_push_pull";
72 static const char OP_TILT[] = "TRANSFORM_OT_tilt";
73 static const char OP_TRACKBALL[] = "TRANSFORM_OT_trackball";
74 static const char OP_MIRROR[] = "TRANSFORM_OT_mirror";
75 static const char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide";
76 static const char OP_VERT_SLIDE[] = "TRANSFORM_OT_vert_slide";
77 static const char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease";
78 static const char OP_EDGE_BWEIGHT[] = "TRANSFORM_OT_edge_bevelweight";
79 static const char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide";
80 static const char OP_NORMAL_ROTATION[] = "TRANSFORM_OT_rotate_normal";
81
82 static void TRANSFORM_OT_translate(struct wmOperatorType *ot);
83 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot);
84 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot);
85 static void TRANSFORM_OT_resize(struct wmOperatorType *ot);
86 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot);
87 static void TRANSFORM_OT_shear(struct wmOperatorType *ot);
88 static void TRANSFORM_OT_bend(struct wmOperatorType *ot);
89 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot);
90 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot);
91 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot);
92 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot);
93 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot);
94 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot);
95 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot);
96 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot);
97 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot);
98 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot);
99 static void TRANSFORM_OT_rotate_normal(struct wmOperatorType *ot);
100
101 static TransformModeItem transform_modes[] =
102 {
103         {OP_TRANSLATION, TFM_TRANSLATION, TRANSFORM_OT_translate},
104         {OP_ROTATION, TFM_ROTATION, TRANSFORM_OT_rotate},
105         {OP_TOSPHERE, TFM_TOSPHERE, TRANSFORM_OT_tosphere},
106         {OP_RESIZE, TFM_RESIZE, TRANSFORM_OT_resize},
107         {OP_SKIN_RESIZE, TFM_SKIN_RESIZE, TRANSFORM_OT_skin_resize},
108         {OP_SHEAR, TFM_SHEAR, TRANSFORM_OT_shear},
109         {OP_BEND, TFM_BEND, TRANSFORM_OT_bend},
110         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN, TRANSFORM_OT_shrink_fatten},
111         {OP_PUSH_PULL, TFM_PUSHPULL, TRANSFORM_OT_push_pull},
112         {OP_TILT, TFM_TILT, TRANSFORM_OT_tilt},
113         {OP_TRACKBALL, TFM_TRACKBALL, TRANSFORM_OT_trackball},
114         {OP_MIRROR, TFM_MIRROR, TRANSFORM_OT_mirror},
115         {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide},
116         {OP_VERT_SLIDE, TFM_VERT_SLIDE, TRANSFORM_OT_vert_slide},
117         {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease},
118         {OP_EDGE_BWEIGHT, TFM_BWEIGHT, TRANSFORM_OT_edge_bevelweight},
119         {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide},
120         {OP_NORMAL_ROTATION, TFM_NORMAL_ROTATION, TRANSFORM_OT_rotate_normal},
121         {NULL, 0},
122 };
123
124 const EnumPropertyItem rna_enum_transform_mode_types[] =
125 {
126         {TFM_INIT, "INIT", 0, "Init", ""},
127         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
128         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
129         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
130         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
131         {TFM_SKIN_RESIZE, "SKIN_RESIZE", 0, "Skin Resize", ""},
132         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
133         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
134         {TFM_BEND, "BEND", 0, "Bend", ""},
135         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
136         {TFM_TILT, "TILT", 0, "Tilt", ""},
137         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
138         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
139         {TFM_CREASE, "CREASE", 0, "Crease", ""},
140         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
141         {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
142         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
143         {TFM_BONE_ENVELOPE_DIST, "BONE_ENVELOPE_DIST", 0, "Bone_Envelope_Distance", ""},
144         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
145         {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""},
146         {TFM_GPENCIL_SHRINKFATTEN, "GPENCIL_SHRINKFATTEN", 0, "GPencil_Shrinkfatten", ""},
147         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
148         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
149         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
150         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
151         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
152         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
153         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
154         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
155         {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
156         {TFM_SEQ_SLIDE, "SEQSLIDE", 0, "Sequence Slide", ""},
157         {0, NULL, 0, NULL, NULL},
158 };
159
160 static int select_orientation_exec(bContext *C, wmOperator *op)
161 {
162         Scene *scene = CTX_data_scene(C);
163         int orientation = RNA_enum_get(op->ptr, "orientation");
164
165         BKE_scene_orientation_slot_set_index(&scene->orientation_slots[SCE_ORIENT_DEFAULT], orientation);
166
167         WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
168
169         struct wmMsgBus *mbus = CTX_wm_message_bus(C);
170         WM_msg_publish_rna_prop(mbus, &scene->id, scene, TransformOrientationSlot, type);
171
172         return OPERATOR_FINISHED;
173 }
174
175 static int select_orientation_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
176 {
177         uiPopupMenu *pup;
178         uiLayout *layout;
179
180         pup = UI_popup_menu_begin(C, IFACE_("Orientation"), ICON_NONE);
181         layout = UI_popup_menu_layout(pup);
182         uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
183         UI_popup_menu_end(C, pup);
184
185         return OPERATOR_INTERFACE;
186 }
187
188 static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
189 {
190         PropertyRNA *prop;
191
192         /* identifiers */
193         ot->name   = "Select Orientation";
194         ot->description = "Select transformation orientation";
195         ot->idname = "TRANSFORM_OT_select_orientation";
196         ot->flag   = OPTYPE_UNDO;
197
198         /* api callbacks */
199         ot->invoke = select_orientation_invoke;
200         ot->exec   = select_orientation_exec;
201         ot->poll   = ED_operator_view3d_active;
202
203         prop = RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
204         RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
205         RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
206 }
207
208
209 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
210 {
211         Scene *scene = CTX_data_scene(C);
212         BIF_removeTransformOrientationIndex(C, scene->orientation_slots[SCE_ORIENT_DEFAULT].index_custom);
213
214         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
215
216         return OPERATOR_FINISHED;
217 }
218
219 static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
220 {
221         return delete_orientation_exec(C, op);
222 }
223
224 static bool delete_orientation_poll(bContext *C)
225 {
226         Scene *scene = CTX_data_scene(C);
227
228         if (ED_operator_areaactive(C) == 0)
229                 return 0;
230
231         return ((scene->orientation_slots[SCE_ORIENT_DEFAULT].type >= V3D_ORIENT_CUSTOM) &&
232                 (scene->orientation_slots[SCE_ORIENT_DEFAULT].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                         bool 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
406                  * (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         /* Orientation/Constraints. */
515         {
516                 /* Hide orientation axis if no constraints are set, since it wont be used. */
517                 PropertyRNA *prop_con = RNA_struct_find_property(op->ptr, "constraint_axis");
518                 if (prop_con && !RNA_property_is_set(op->ptr, prop_con)) {
519                         if (STRPREFIX(prop_id, "constraint")) {
520                                 return false;
521                         }
522                 }
523         }
524
525         /* Proportional Editing. */
526         {
527                 PropertyRNA *prop_pet = RNA_struct_find_property(op->ptr, "proportional");
528                 if (prop_pet && (prop_pet != prop) &&
529                     (RNA_property_enum_get(op->ptr, prop_pet) == PROP_EDIT_OFF))
530                 {
531                         if (STRPREFIX(prop_id, "proportional")) {
532                                 return false;
533                         }
534                 }
535         }
536
537         return true;
538 }
539
540 void Transform_Properties(struct wmOperatorType *ot, int flags)
541 {
542         PropertyRNA *prop;
543
544         if (flags & P_AXIS) {
545                 prop = RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
546                 RNA_def_property_array(prop, 3);
547                 /* Make this not hidden when there's a nice axis selection widget */
548                 RNA_def_property_flag(prop, PROP_HIDDEN);
549                 RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
550         }
551
552         if (flags & P_AXIS_ORTHO) {
553                 prop = RNA_def_property(ot->srna, "axis_ortho", PROP_FLOAT, PROP_DIRECTION);
554                 RNA_def_property_array(prop, 3);
555                 /* Make this not hidden when there's a nice axis selection widget */
556                 RNA_def_property_flag(prop, PROP_HIDDEN);
557                 RNA_def_property_ui_text(prop, "Axis", "The orthogonal axis around which the transformation occurs");
558         }
559
560         if (flags & P_CONSTRAINT) {
561                 RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
562
563                 /* Set by 'constraint_orientation' or gizmo which acts on non-standard orientation. */
564                 prop = RNA_def_float_matrix(ot->srna, "constraint_matrix", 3, 3, NULL, 0.0f, 0.0f, "Matrix", "", 0.0f, 0.0f);
565                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
566
567                 prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
568                 RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
569                 RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
570
571         }
572
573         if (flags & P_MIRROR) {
574                 prop = RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
575                 if (flags & P_MIRROR_DUMMY) {
576                         /* only used so macros can disable this option */
577                         RNA_def_property_flag(prop, PROP_HIDDEN);
578                 }
579         }
580
581
582         if (flags & P_PROPORTIONAL) {
583                 RNA_def_enum(ot->srna, "proportional", rna_enum_proportional_editing_items, 0, "Proportional Editing", "");
584                 prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", rna_enum_proportional_falloff_items, 0,
585                                     "Proportional Falloff", "Falloff type for proportional editing mode");
586                 /* Abusing id_curve :/ */
587                 RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE);
588                 RNA_def_float(ot->srna, "proportional_size", 1, T_PROP_SIZE_MIN, T_PROP_SIZE_MAX,
589                               "Proportional Size", "", 0.001f, 100.0f);
590         }
591
592         if (flags & P_SNAP) {
593                 prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
594                 RNA_def_property_flag(prop, PROP_HIDDEN);
595
596                 if (flags & P_GEO_SNAP) {
597                         prop = RNA_def_enum(ot->srna, "snap_target", rna_enum_snap_target_items, 0, "Target", "");
598                         RNA_def_property_flag(prop, PROP_HIDDEN);
599                         prop = RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
600                         RNA_def_property_flag(prop, PROP_HIDDEN);
601
602                         if (flags & P_ALIGN_SNAP) {
603                                 prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
604                                 RNA_def_property_flag(prop, PROP_HIDDEN);
605                                 prop = RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
606                                 RNA_def_property_flag(prop, PROP_HIDDEN);
607                         }
608                 }
609         }
610
611         if (flags & P_GPENCIL_EDIT) {
612                 prop = RNA_def_boolean(ot->srna, "gpencil_strokes", 0, "Edit Grease Pencil", "Edit selected Grease Pencil strokes");
613                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
614         }
615
616         if (flags & P_CURSOR_EDIT) {
617                 prop = RNA_def_boolean(ot->srna, "cursor_transform", 0, "Transform Cursor", "");
618                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
619         }
620
621         if ((flags & P_OPTIONS) && !(flags & P_NO_TEXSPACE)) {
622                 prop = RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
623                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
624                 prop = RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
625                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
626         }
627
628         if (flags & P_CORRECT_UV) {
629                 RNA_def_boolean(ot->srna, "correct_uv", true, "Correct UVs", "Correct UV coordinates when transforming");
630         }
631
632         if (flags & P_CENTER) {
633                 /* For gizmos that define their own center. */
634                 prop = RNA_def_property(ot->srna, "center_override", PROP_FLOAT, PROP_XYZ);
635                 RNA_def_property_array(prop, 3);
636                 RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
637                 RNA_def_property_ui_text(prop, "Center Override", "Force using this center value (when set)");
638         }
639
640         if ((flags & P_NO_DEFAULTS) == 0) {
641                 prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
642                 RNA_def_property_flag(prop, PROP_HIDDEN);
643
644                 prop = RNA_def_boolean(ot->srna, "use_accurate", 0, "Accurate", "Use accurate transformation");
645                 RNA_def_property_flag(prop, PROP_HIDDEN);
646         }
647 }
648
649 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
650 {
651         /* identifiers */
652         ot->name   = "Move";
653         ot->description = "Move selected items";
654         ot->idname = OP_TRANSLATION;
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_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Move", "", -FLT_MAX, FLT_MAX);
666
667         WM_operatortype_props_advanced_begin(ot);
668
669         Transform_Properties(
670                 ot,
671                 P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS |
672                 P_GPENCIL_EDIT | P_CURSOR_EDIT);
673 }
674
675 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
676 {
677         /* identifiers */
678         ot->name   = "Resize";
679         ot->description = "Scale (resize) selected items";
680         ot->idname = OP_RESIZE;
681         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
682
683         /* api callbacks */
684         ot->invoke = transform_invoke;
685         ot->exec   = transform_exec;
686         ot->modal  = transform_modal;
687         ot->cancel = transform_cancel;
688         ot->poll   = ED_operator_screenactive;
689         ot->poll_property = transform_poll_property;
690
691         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Scale", "", -FLT_MAX, FLT_MAX);
692
693         WM_operatortype_props_advanced_begin(ot);
694
695         Transform_Properties(
696                 ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CENTER);
697 }
698
699 static bool skin_resize_poll(bContext *C)
700 {
701         struct Object *obedit = CTX_data_edit_object(C);
702         if (obedit && obedit->type == OB_MESH) {
703                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
704                 return (em && CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN));
705         }
706         return 0;
707 }
708
709 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
710 {
711         /* identifiers */
712         ot->name   = "Skin Resize";
713         ot->description = "Scale selected vertices' skin radii";
714         ot->idname = OP_SKIN_RESIZE;
715         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
716
717         /* api callbacks */
718         ot->invoke = transform_invoke;
719         ot->exec   = transform_exec;
720         ot->modal  = transform_modal;
721         ot->cancel = transform_cancel;
722         ot->poll   = skin_resize_poll;
723         ot->poll_property = transform_poll_property;
724
725         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Scale", "", -FLT_MAX, FLT_MAX);
726
727         WM_operatortype_props_advanced_begin(ot);
728
729         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
730 }
731
732 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
733 {
734         /* identifiers */
735         ot->name   = "Trackball";
736         ot->description = "Trackball style rotation of selected items";
737         ot->idname = OP_TRACKBALL;
738         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
739
740         /* api callbacks */
741         ot->invoke = transform_invoke;
742         ot->exec   = transform_exec;
743         ot->modal  = transform_modal;
744         ot->cancel = transform_cancel;
745         ot->poll   = ED_operator_screenactive;
746         ot->poll_property = transform_poll_property;
747
748         /* Maybe we could use float_vector_xyz here too? */
749         RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
750
751         WM_operatortype_props_advanced_begin(ot);
752
753         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
754 }
755
756 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
757 {
758         /* identifiers */
759         ot->name = "Rotate";
760         ot->description = "Rotate selected items";
761         ot->idname = OP_ROTATION;
762         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
763
764         /* api callbacks */
765         ot->invoke = transform_invoke;
766         ot->exec   = transform_exec;
767         ot->modal  = transform_modal;
768         ot->cancel = transform_cancel;
769         ot->poll   = ED_operator_screenactive;
770         ot->poll_property = transform_poll_property;
771
772         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
773
774         WM_operatortype_props_advanced_begin(ot);
775
776         Transform_Properties(
777                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT | P_CENTER);
778 }
779
780 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
781 {
782         /* identifiers */
783         ot->name = "Tilt";
784         /* optional -
785          * "Tilt selected vertices"
786          * "Specify an extra axis rotation for selected vertices of 3D curve" */
787         ot->description = "Tilt selected control vertices of 3D curve";
788         ot->idname = OP_TILT;
789         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
790
791         /* api callbacks */
792         ot->invoke = transform_invoke;
793         ot->exec   = transform_exec;
794         ot->modal  = transform_modal;
795         ot->cancel = transform_cancel;
796         ot->poll   = ED_operator_editcurve_3d;
797         ot->poll_property = transform_poll_property;
798
799         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
800
801         WM_operatortype_props_advanced_begin(ot);
802
803         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
804 }
805
806 static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
807 {
808         /* identifiers */
809         ot->name   = "Bend";
810         ot->description = "Bend selected items between the 3D cursor and the mouse";
811         ot->idname = OP_BEND;
812         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
813
814         /* api callbacks */
815         ot->invoke = transform_invoke;
816         // ot->exec   = transform_exec;  // unsupported
817         ot->modal  = transform_modal;
818         ot->cancel = transform_cancel;
819         ot->poll   = ED_operator_region_view3d_active;
820         ot->poll_property = transform_poll_property;
821
822         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
823
824         WM_operatortype_props_advanced_begin(ot);
825
826         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
827 }
828
829 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
830 {
831         /* identifiers */
832         ot->name   = "Shear";
833         ot->description = "Shear selected items along the horizontal screen axis";
834         ot->idname = OP_SHEAR;
835         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
836
837         /* api callbacks */
838         ot->invoke = transform_invoke;
839         ot->exec   = transform_exec;
840         ot->modal  = transform_modal;
841         ot->cancel = transform_cancel;
842         ot->poll   = ED_operator_screenactive;
843         ot->poll_property = transform_poll_property;
844
845         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
846         RNA_def_enum(ot->srna, "shear_axis", rna_enum_axis_xy_items, 0, "Shear Axis", "");
847
848         WM_operatortype_props_advanced_begin(ot);
849
850         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_AXIS | P_AXIS_ORTHO);
851 }
852
853 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
854 {
855         /* identifiers */
856         ot->name   = "Push/Pull";
857         ot->description = "Push/Pull selected items";
858         ot->idname = OP_PUSH_PULL;
859         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
860
861         /* api callbacks */
862         ot->invoke = transform_invoke;
863         ot->exec   = transform_exec;
864         ot->modal  = transform_modal;
865         ot->cancel = transform_cancel;
866         ot->poll   = ED_operator_screenactive;
867         ot->poll_property = transform_poll_property;
868
869         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
870
871         WM_operatortype_props_advanced_begin(ot);
872
873         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_CENTER);
874 }
875
876 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
877 {
878         /* identifiers */
879         ot->name   = "Shrink/Fatten";
880         ot->description = "Shrink/fatten selected vertices along normals";
881         ot->idname = OP_SHRINK_FATTEN;
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_editmesh;
890         ot->poll_property = transform_poll_property;
891
892         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
893
894         RNA_def_boolean(ot->srna, "use_even_offset", false, "Offset Even", "Scale the offset to give more even thickness");
895
896         WM_operatortype_props_advanced_begin(ot);
897
898         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
899 }
900
901 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
902 {
903         /* identifiers */
904         ot->name   = "To Sphere";
905         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()"
906         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
907         ot->idname = OP_TOSPHERE;
908         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
909
910         /* api callbacks */
911         ot->invoke = transform_invoke;
912         ot->exec   = transform_exec;
913         ot->modal  = transform_modal;
914         ot->cancel = transform_cancel;
915         ot->poll   = ED_operator_screenactive;
916         ot->poll_property = transform_poll_property;
917
918         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
919
920         WM_operatortype_props_advanced_begin(ot);
921
922         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
923 }
924
925 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
926 {
927         /* identifiers */
928         ot->name   = "Mirror";
929         ot->description = "Mirror selected items around one or more axes";
930         ot->idname = OP_MIRROR;
931         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
932
933         /* api callbacks */
934         ot->invoke = transform_invoke;
935         ot->exec   = transform_exec;
936         ot->modal  = transform_modal;
937         ot->cancel = transform_cancel;
938         ot->poll   = ED_operator_screenactive;
939         ot->poll_property = transform_poll_property;
940
941         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_GPENCIL_EDIT | P_CENTER);
942 }
943
944 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
945 {
946         PropertyRNA *prop;
947
948         /* identifiers */
949         ot->name   = "Edge Slide";
950         ot->description = "Slide an edge loop along a mesh";
951         ot->idname = OP_EDGE_SLIDE;
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_region_view3d;
960         ot->poll_property = transform_poll_property;
961
962         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
963
964         prop = RNA_def_boolean(ot->srna, "single_side", false, "Single Side", "");
965         RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
966         RNA_def_boolean(ot->srna, "use_even", false, "Even",
967                         "Make the edge loop match the shape of the adjacent edge loop");
968
969         WM_operatortype_props_advanced_begin(ot);
970
971         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
972                         "When Even mode is active, flips between the two adjacent edge loops");
973         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
974                         "Clamp within the edge extents");
975
976         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
977 }
978
979 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
980 {
981         /* identifiers */
982         ot->name   = "Vertex Slide";
983         ot->description = "Slide a vertex along a mesh";
984         ot->idname = OP_VERT_SLIDE;
985         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
986
987         /* api callbacks */
988         ot->invoke = transform_invoke;
989         ot->exec   = transform_exec;
990         ot->modal  = transform_modal;
991         ot->cancel = transform_cancel;
992         ot->poll   = ED_operator_editmesh_region_view3d;
993         ot->poll_property = transform_poll_property;
994
995         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
996         RNA_def_boolean(ot->srna, "use_even", false, "Even",
997                         "Make the edge loop match the shape of the adjacent edge loop");
998
999         WM_operatortype_props_advanced_begin(ot);
1000
1001         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
1002                         "When Even mode is active, flips between the two adjacent edge loops");
1003         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
1004                         "Clamp within the edge extents");
1005
1006         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
1007 }
1008
1009 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
1010 {
1011         /* identifiers */
1012         ot->name   = "Edge Crease";
1013         ot->description = "Change the crease of edges";
1014         ot->idname = OP_EDGE_CREASE;
1015         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1016
1017         /* api callbacks */
1018         ot->invoke = transform_invoke;
1019         ot->exec   = transform_exec;
1020         ot->modal  = transform_modal;
1021         ot->cancel = transform_cancel;
1022         ot->poll   = ED_operator_editmesh;
1023         ot->poll_property = transform_poll_property;
1024
1025         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
1026
1027         WM_operatortype_props_advanced_begin(ot);
1028
1029         Transform_Properties(ot, P_SNAP);
1030 }
1031
1032 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
1033 {
1034         /* identifiers */
1035         ot->name   = "Edge Bevel Weight";
1036         ot->description = "Change the bevel weight of edges";
1037         ot->idname = OP_EDGE_BWEIGHT;
1038         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1039
1040         /* api callbacks */
1041         ot->invoke = transform_invoke;
1042         ot->exec   = transform_exec;
1043         ot->modal  = transform_modal;
1044         ot->cancel = transform_cancel;
1045         ot->poll   = ED_operator_editmesh;
1046
1047         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
1048
1049         WM_operatortype_props_advanced_begin(ot);
1050
1051         Transform_Properties(ot, P_SNAP);
1052 }
1053
1054 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
1055 {
1056         /* identifiers */
1057         ot->name   = "Sequence Slide";
1058         ot->description = "Slide a sequence strip in time";
1059         ot->idname = OP_SEQ_SLIDE;
1060         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1061
1062         /* api callbacks */
1063         ot->invoke = transform_invoke;
1064         ot->exec   = transform_exec;
1065         ot->modal  = transform_modal;
1066         ot->cancel = transform_cancel;
1067         ot->poll   = ED_operator_sequencer_active;
1068
1069         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
1070
1071         WM_operatortype_props_advanced_begin(ot);
1072
1073         Transform_Properties(ot, P_SNAP);
1074 }
1075
1076 static void TRANSFORM_OT_rotate_normal(struct wmOperatorType *ot)
1077 {
1078         /* identifiers */
1079         ot->name = "Normal Rotate";
1080         ot->description = "Rotate split normal of selected items";
1081         ot->idname = OP_NORMAL_ROTATION;
1082         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1083
1084         /* api callbacks */
1085         ot->invoke = transform_invoke;
1086         ot->exec = transform_exec;
1087         ot->modal = transform_modal;
1088         ot->cancel = transform_cancel;
1089         ot->poll = ED_operator_editmesh_auto_smooth;
1090
1091         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
1092
1093         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_MIRROR);
1094 }
1095
1096
1097 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
1098 {
1099         PropertyRNA *prop;
1100
1101         /* identifiers */
1102         ot->name   = "Transform";
1103         ot->description = "Transform selected items by mode type";
1104         ot->idname = "TRANSFORM_OT_transform";
1105         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
1106
1107         /* api callbacks */
1108         ot->invoke = transform_invoke;
1109         ot->exec   = transform_exec;
1110         ot->modal  = transform_modal;
1111         ot->cancel = transform_cancel;
1112         ot->poll   = ED_operator_screenactive;
1113         ot->poll_property = transform_poll_property;
1114
1115         prop = RNA_def_enum(ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
1116         RNA_def_property_flag(prop, PROP_HIDDEN);
1117
1118         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
1119
1120         WM_operatortype_props_advanced_begin(ot);
1121
1122         Transform_Properties(
1123                 ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT | P_CENTER);
1124 }
1125
1126 static int transform_from_gizmo_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
1127 {
1128         bToolRef *tref = WM_toolsystem_ref_from_context(C);
1129         if (tref) {
1130                 ARegion *ar = CTX_wm_region(C);
1131                 wmGizmoMap *gzmap = ar->gizmo_map;
1132                 wmGizmoGroup *gzgroup = gzmap ? WM_gizmomap_group_find(gzmap, "TRANSFORM_GGT_gizmo") : NULL;
1133                 if (gzgroup != NULL) {
1134                         PointerRNA gzg_ptr;
1135                         WM_toolsystem_ref_properties_ensure_from_gizmo_group(tref, gzgroup->type, &gzg_ptr);
1136                         const int drag_action = RNA_enum_get(&gzg_ptr, "drag_action");
1137                         const char *op_id = NULL;
1138                         switch (drag_action) {
1139                                 case SCE_GIZMO_SHOW_TRANSLATE:
1140                                         op_id = "TRANSFORM_OT_translate";
1141                                         break;
1142                                 case SCE_GIZMO_SHOW_ROTATE:
1143                                         op_id = "TRANSFORM_OT_rotate";
1144                                         break;
1145                                 case SCE_GIZMO_SHOW_SCALE:
1146                                         op_id = "TRANSFORM_OT_resize";
1147                                         break;
1148                                 default:
1149                                         break;
1150                         }
1151                         if (op_id) {
1152                                 wmOperatorType *ot = WM_operatortype_find(op_id, true);
1153                                 PointerRNA op_ptr;
1154                                 WM_operator_properties_create_ptr(&op_ptr, ot);
1155                                 RNA_boolean_set(&op_ptr, "release_confirm", true);
1156                                 WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &op_ptr);
1157                                 WM_operator_properties_free(&op_ptr);
1158                                 return OPERATOR_FINISHED;
1159                         }
1160                 }
1161         }
1162         return OPERATOR_PASS_THROUGH;
1163 }
1164
1165 /* Use with 'TRANSFORM_GGT_gizmo'. */
1166 static void TRANSFORM_OT_from_gizmo(struct wmOperatorType *ot)
1167 {
1168         /* identifiers */
1169         ot->name   = "Transform From Gizmo";
1170         ot->description = "Transform selected items by mode type";
1171         ot->idname = "TRANSFORM_OT_from_gizmo";
1172         ot->flag = 0;
1173
1174         /* api callbacks */
1175         ot->invoke = transform_from_gizmo_invoke;
1176 }
1177
1178 void transform_operatortypes(void)
1179 {
1180         TransformModeItem *tmode;
1181
1182         for (tmode = transform_modes; tmode->idname; tmode++) {
1183                 WM_operatortype_append(tmode->opfunc);
1184         }
1185
1186         WM_operatortype_append(TRANSFORM_OT_transform);
1187
1188         WM_operatortype_append(TRANSFORM_OT_select_orientation);
1189         WM_operatortype_append(TRANSFORM_OT_create_orientation);
1190         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
1191
1192         WM_operatortype_append(TRANSFORM_OT_from_gizmo);
1193 }
1194
1195 void ED_keymap_transform(wmKeyConfig *keyconf)
1196 {
1197         wmKeyMap *modalmap = transform_modal_keymap(keyconf);
1198
1199         TransformModeItem *tmode;
1200
1201         for (tmode = transform_modes; tmode->idname; tmode++) {
1202                 WM_modalkeymap_assign(modalmap, tmode->idname);
1203         }
1204         WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
1205 }