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