Cleanup: typo
[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, 0.00001f, FLT_MAX, "Proportional Size", "", 0.001, 100);
532         }
533
534         if (flags & P_SNAP) {
535                 prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
536                 RNA_def_property_flag(prop, PROP_HIDDEN);
537
538                 if (flags & P_GEO_SNAP) {
539                         prop = RNA_def_enum(ot->srna, "snap_target", rna_enum_snap_target_items, 0, "Target", "");
540                         RNA_def_property_flag(prop, PROP_HIDDEN);
541                         prop = RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
542                         RNA_def_property_flag(prop, PROP_HIDDEN);
543                         
544                         if (flags & P_ALIGN_SNAP) {
545                                 prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
546                                 RNA_def_property_flag(prop, PROP_HIDDEN);
547                                 prop = RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
548                                 RNA_def_property_flag(prop, PROP_HIDDEN);
549                         }
550                 }
551         }
552         
553         if (flags & P_GPENCIL_EDIT) {
554                 RNA_def_boolean(ot->srna, "gpencil_strokes", 0, "Edit Grease Pencil", "Edit selected Grease Pencil strokes");
555         }
556         
557         if ((flags & P_OPTIONS) && !(flags & P_NO_TEXSPACE)) {
558                 RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
559                 prop = RNA_def_boolean(ot->srna, "remove_on_cancel", 0, "Remove on Cancel", "Remove elements on cancel");
560                 RNA_def_property_flag(prop, PROP_HIDDEN);
561         }
562
563         if (flags & P_CORRECT_UV) {
564                 RNA_def_boolean(ot->srna, "correct_uv", 0, "Correct UVs", "Correct UV coordinates when transforming");
565         }
566
567         if ((flags & P_NO_DEFAULTS) == 0) {
568                 // 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
569                 /*prop =*/ RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
570                 //RNA_def_property_flag(prop, PROP_HIDDEN);
571         }
572 }
573
574 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
575 {
576         /* identifiers */
577         ot->name   = "Translate";
578         ot->description = "Translate (move) selected items";
579         ot->idname = OP_TRANSLATION;
580         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
581
582         /* api callbacks */
583         ot->invoke = transform_invoke;
584         ot->exec   = transform_exec;
585         ot->modal  = transform_modal;
586         ot->cancel = transform_cancel;
587         ot->poll   = ED_operator_screenactive;
588
589         RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
590
591         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
592 }
593
594 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
595 {
596         /* identifiers */
597         ot->name   = "Resize";
598         ot->description = "Scale (resize) selected items"; 
599         ot->idname = OP_RESIZE;
600         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
601
602         /* api callbacks */
603         ot->invoke = transform_invoke;
604         ot->exec   = transform_exec;
605         ot->modal  = transform_modal;
606         ot->cancel = transform_cancel;
607         ot->poll   = ED_operator_screenactive;
608
609         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
610
611         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
612 }
613
614 static int skin_resize_poll(bContext *C)
615 {
616         struct Object *obedit = CTX_data_edit_object(C);
617         if (obedit && obedit->type == OB_MESH) {
618                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
619                 return (em && CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN));
620         }
621         return 0;
622 }
623
624 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
625 {
626         /* identifiers */
627         ot->name   = "Skin Resize";
628         ot->description = "Scale selected vertices' skin radii"; 
629         ot->idname = OP_SKIN_RESIZE;
630         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
631
632         /* api callbacks */
633         ot->invoke = transform_invoke;
634         ot->exec   = transform_exec;
635         ot->modal  = transform_modal;
636         ot->cancel = transform_cancel;
637         ot->poll   = skin_resize_poll;
638
639         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
640
641         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
642 }
643
644 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
645 {
646         /* identifiers */
647         ot->name   = "Trackball";
648         ot->description = "Trackball style rotation of selected items";
649         ot->idname = OP_TRACKBALL;
650         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
651
652         /* api callbacks */
653         ot->invoke = transform_invoke;
654         ot->exec   = transform_exec;
655         ot->modal  = transform_modal;
656         ot->cancel = transform_cancel;
657         ot->poll   = ED_operator_screenactive;
658
659         /* Maybe we could use float_vector_xyz here too? */
660         RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
661
662         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
663 }
664
665 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
666 {
667         /* identifiers */
668         ot->name = "Rotate";
669         ot->description = "Rotate selected items";
670         ot->idname = OP_ROTATION;
671         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
672
673         /* api callbacks */
674         ot->invoke = transform_invoke;
675         ot->exec   = transform_exec;
676         ot->modal  = transform_modal;
677         ot->cancel = transform_cancel;
678         ot->poll   = ED_operator_screenactive;
679
680         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
681
682         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT);
683 }
684
685 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
686 {
687         /* identifiers */
688         ot->name = "Tilt";
689         /* optional -
690          * "Tilt selected vertices"
691          * "Specify an extra axis rotation for selected vertices of 3D curve" */
692         ot->description = "Tilt selected control vertices of 3D curve"; 
693         ot->idname = OP_TILT;
694         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
695
696         /* api callbacks */
697         ot->invoke = transform_invoke;
698         ot->exec   = transform_exec;
699         ot->modal  = transform_modal;
700         ot->cancel = transform_cancel;
701         ot->poll   = ED_operator_editcurve_3d;
702
703         RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
704
705         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
706 }
707
708 static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
709 {
710         /* identifiers */
711         ot->name   = "Bend";
712         ot->description = "Bend selected items between the 3D cursor and the mouse";
713         ot->idname = OP_BEND;
714         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
715
716         /* api callbacks */
717         ot->invoke = transform_invoke;
718         // ot->exec   = transform_exec;  // unsupported
719         ot->modal  = transform_modal;
720         ot->cancel = transform_cancel;
721         ot->poll   = ED_operator_region_view3d_active;
722
723         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
724
725         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
726 }
727
728 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
729 {
730         /* identifiers */
731         ot->name   = "Shear";
732         ot->description = "Shear selected items along the horizontal screen axis";
733         ot->idname = OP_SHEAR;
734         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
735
736         /* api callbacks */
737         ot->invoke = transform_invoke;
738         ot->exec   = transform_exec;
739         ot->modal  = transform_modal;
740         ot->cancel = transform_cancel;
741         ot->poll   = ED_operator_screenactive;
742
743         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
744
745         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
746         // XXX Shear axis?
747 }
748
749 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
750 {
751         /* identifiers */
752         ot->name   = "Push/Pull";
753         ot->description = "Push/Pull selected items";
754         ot->idname = OP_PUSH_PULL;
755         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
756
757         /* api callbacks */
758         ot->invoke = transform_invoke;
759         ot->exec   = transform_exec;
760         ot->modal  = transform_modal;
761         ot->cancel = transform_cancel;
762         ot->poll   = ED_operator_screenactive;
763
764         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
765
766         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
767 }
768
769 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
770 {
771         /* identifiers */
772         ot->name   = "Shrink/Fatten";
773         ot->description = "Shrink/fatten selected vertices along normals";
774         ot->idname = OP_SHRINK_FATTEN;
775         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
776
777         /* api callbacks */
778         ot->invoke = transform_invoke;
779         ot->exec   = transform_exec;
780         ot->modal  = transform_modal;
781         ot->cancel = transform_cancel;
782         ot->poll   = ED_operator_editmesh;
783
784         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
785
786         RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness");
787
788         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
789 }
790
791 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
792 {
793         /* identifiers */
794         ot->name   = "To Sphere";
795         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" 
796         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
797         ot->idname = OP_TOSPHERE;
798         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
799
800         /* api callbacks */
801         ot->invoke = transform_invoke;
802         ot->exec   = transform_exec;
803         ot->modal  = transform_modal;
804         ot->cancel = transform_cancel;
805         ot->poll   = ED_operator_screenactive;
806
807         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
808
809         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
810 }
811
812 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
813 {
814         /* identifiers */
815         ot->name   = "Mirror";
816         ot->description = "Mirror selected items around one or more axes";
817         ot->idname = OP_MIRROR;
818         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
819
820         /* api callbacks */
821         ot->invoke = transform_invoke;
822         ot->exec   = transform_exec;
823         ot->modal  = transform_modal;
824         ot->cancel = transform_cancel;
825         ot->poll   = ED_operator_screenactive;
826
827         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_GPENCIL_EDIT);
828 }
829
830 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
831 {
832         PropertyRNA *prop;
833
834         /* identifiers */
835         ot->name   = "Edge Slide";
836         ot->description = "Slide an edge loop along a mesh"; 
837         ot->idname = OP_EDGE_SLIDE;
838         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
839
840         /* api callbacks */
841         ot->invoke = transform_invoke;
842         ot->exec   = transform_exec;
843         ot->modal  = transform_modal;
844         ot->cancel = transform_cancel;
845         ot->poll   = ED_operator_editmesh_region_view3d;
846
847         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
848
849         prop = RNA_def_boolean(ot->srna, "single_side", false, "Single Side", "");
850         RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
851         RNA_def_boolean(ot->srna, "use_even", false, "Even",
852                         "Make the edge loop match the shape of the adjacent edge loop");
853         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
854                         "When Even mode is active, flips between the two adjacent edge loops");
855         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
856                         "Clamp within the edge extents");
857
858         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
859 }
860
861 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
862 {
863         /* identifiers */
864         ot->name   = "Vertex Slide";
865         ot->description = "Slide a vertex along a mesh";
866         ot->idname = OP_VERT_SLIDE;
867         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
868
869         /* api callbacks */
870         ot->invoke = transform_invoke;
871         ot->exec   = transform_exec;
872         ot->modal  = transform_modal;
873         ot->cancel = transform_cancel;
874         ot->poll   = ED_operator_editmesh_region_view3d;
875
876         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
877         RNA_def_boolean(ot->srna, "use_even", false, "Even",
878                         "Make the edge loop match the shape of the adjacent edge loop");
879         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
880                         "When Even mode is active, flips between the two adjacent edge loops");
881         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
882                         "Clamp within the edge extents");
883
884         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
885 }
886
887 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
888 {
889         /* identifiers */
890         ot->name   = "Edge Crease";
891         ot->description = "Change the crease of edges";
892         ot->idname = OP_EDGE_CREASE;
893         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
894
895         /* api callbacks */
896         ot->invoke = transform_invoke;
897         ot->exec   = transform_exec;
898         ot->modal  = transform_modal;
899         ot->cancel = transform_cancel;
900         ot->poll   = ED_operator_editmesh;
901
902         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
903
904         Transform_Properties(ot, P_SNAP);
905 }
906
907 static int edge_bevelweight_exec(bContext *C, wmOperator *op)
908 {
909         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
910
911         /* auto-enable bevel edge weight drawing, then chain to common transform code */
912         me->drawflag |= ME_DRAWBWEIGHTS;
913
914         return transform_exec(C, op);
915 }
916
917 static int edge_bevelweight_invoke(bContext *C, wmOperator *op, const wmEvent *event)
918 {
919         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
920
921         /* auto-enable bevel edge weight drawing, then chain to common transform code */
922         me->drawflag |= ME_DRAWBWEIGHTS;
923
924         return transform_invoke(C, op, event);
925 }
926
927
928 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
929 {
930         /* identifiers */
931         ot->name   = "Edge Bevel Weight";
932         ot->description = "Change the bevel weight of edges";
933         ot->idname = OP_EDGE_BWEIGHT;
934         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
935
936         /* api callbacks */
937         ot->invoke = edge_bevelweight_invoke;
938         ot->exec   = edge_bevelweight_exec;
939         ot->modal  = transform_modal;
940         ot->cancel = transform_cancel;
941         ot->poll   = ED_operator_editmesh;
942
943         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
944
945         Transform_Properties(ot, P_SNAP);
946 }
947
948 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
949 {
950         /* identifiers */
951         ot->name   = "Sequence Slide";
952         ot->description = "Slide a sequence strip in time";
953         ot->idname = OP_SEQ_SLIDE;
954         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
955
956         /* api callbacks */
957         ot->invoke = transform_invoke;
958         ot->exec   = transform_exec;
959         ot->modal  = transform_modal;
960         ot->cancel = transform_cancel;
961         ot->poll   = ED_operator_sequencer_active;
962
963         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
964
965         Transform_Properties(ot, P_SNAP);
966 }
967
968 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
969 {
970         PropertyRNA *prop;
971
972         /* identifiers */
973         ot->name   = "Transform";
974         ot->description = "Transform selected items by mode type";
975         ot->idname = "TRANSFORM_OT_transform";
976         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
977
978         /* api callbacks */
979         ot->invoke = transform_invoke;
980         ot->exec   = transform_exec;
981         ot->modal  = transform_modal;
982         ot->cancel = transform_cancel;
983         ot->poll   = ED_operator_screenactive;
984
985         prop = RNA_def_enum(ot->srna, "mode", rna_enum_transform_mode_types, TFM_TRANSLATION, "Mode", "");
986         RNA_def_property_flag(prop, PROP_HIDDEN);
987
988         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
989
990         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT);
991 }
992
993 void transform_operatortypes(void)
994 {
995         TransformModeItem *tmode;
996
997         for (tmode = transform_modes; tmode->idname; tmode++) {
998                 WM_operatortype_append(tmode->opfunc);
999         }
1000
1001         WM_operatortype_append(TRANSFORM_OT_transform);
1002
1003         WM_operatortype_append(TRANSFORM_OT_select_orientation);
1004         WM_operatortype_append(TRANSFORM_OT_create_orientation);
1005         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
1006 }
1007
1008 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
1009 {
1010         wmKeyMapItem *kmi;
1011         wmKeyMap *modalmap;
1012         
1013         /* transform.c, only adds modal map once, checks if it's there */
1014         modalmap = transform_modal_keymap(keyconf);
1015
1016         /* assign map to operators only the first time */
1017         if (modalmap) {
1018                 TransformModeItem *tmode;
1019
1020                 for (tmode = transform_modes; tmode->idname; tmode++) {
1021                         WM_modalkeymap_assign(modalmap, tmode->idname);
1022                 }
1023                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
1024         }
1025         
1026         switch (spaceid) {
1027                 case SPACE_VIEW3D:
1028                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1029
1030                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1031
1032                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1033
1034                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1035
1036                         WM_keymap_add_item(keymap, OP_BEND, WKEY, KM_PRESS, KM_SHIFT, 0);
1037
1038                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
1039
1040                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1041
1042                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
1043
1044                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
1045                         RNA_boolean_set(kmi->ptr, "use", true);
1046
1047                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
1048
1049                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1050                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1051
1052                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1053                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_element");
1054
1055
1056                         kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
1057                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1058
1059                         kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
1060                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1061
1062                         WM_keymap_add_item(keymap, OP_SKIN_RESIZE, AKEY, KM_PRESS, KM_CTRL, 0);
1063
1064                         break;
1065                 case SPACE_ACTION:
1066                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1067                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1068                         
1069                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1070                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1071                         
1072                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1073                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1074                         
1075                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1076                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1077                         
1078                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
1079                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
1080                         break;
1081                 case SPACE_IPO:
1082                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1083                         
1084                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1085                         
1086                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1087                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1088                         
1089                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1090                         
1091                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1092                         break;
1093                 case SPACE_NLA:
1094                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1095                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1096                         
1097                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1098                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1099                         
1100                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1101                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1102                         
1103                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1104                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1105                         break;
1106                 case SPACE_NODE:
1107                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
1108                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
1109                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
1110                         /* NB: small trick: macro operator poll may fail due to library data edit,
1111                          * in that case the secondary regular operators are called with same keymap.
1112                          */
1113                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
1114                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1115                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
1116                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1117                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
1118                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1119
1120                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1121
1122                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1123
1124                         /* detach and translate */
1125                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", DKEY, KM_PRESS, KM_ALT, 0);
1126                         /* XXX release_confirm is set in the macro operator definition */
1127                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links_release", EVT_TWEAK_A, KM_ANY, KM_ALT, 0);
1128                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", EVT_TWEAK_S, KM_ANY, KM_ALT, 0);
1129
1130                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1131                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1132                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1133                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_node_element");
1134                         break;
1135                 case SPACE_SEQ:
1136                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
1137
1138                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
1139
1140                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1141                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1142                         break;
1143                 case SPACE_IMAGE:
1144                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1145
1146                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1147
1148                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1149
1150                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1151
1152                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1153
1154                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
1155
1156                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1157                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1158
1159                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1160                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_uv_element");
1161                         break;
1162                 case SPACE_CLIP:
1163                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1164                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1165                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1166                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1167                         break;
1168                 default:
1169                         break;
1170         }
1171 }
1172