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