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