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