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