Fix #35640, part 2. Check id.lib in poll functions for operators which do critical...
[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_object_types.h"
30 #include "DNA_scene_types.h"
31
32 #include "BLI_math.h"
33 #include "BLI_utildefines.h"
34
35 #include "BLF_translation.h"
36
37 #include "BKE_context.h"
38 #include "BKE_global.h"
39 #include "BKE_armature.h"
40 #include "BKE_report.h"
41
42 #include "RNA_access.h"
43 #include "RNA_define.h"
44 #include "RNA_enum_types.h"
45
46 #include "WM_api.h"
47 #include "WM_types.h"
48
49 #include "UI_interface.h"
50 #include "UI_resources.h"
51
52 #include "ED_screen.h"
53 #include "ED_mesh.h"
54
55 #include "transform.h"
56
57 typedef struct TransformModeItem {
58         char *idname;
59         int mode;
60         void (*opfunc)(wmOperatorType *);
61 } TransformModeItem;
62
63 static float VecOne[3] = {1, 1, 1};
64
65 static char OP_TRANSLATION[] = "TRANSFORM_OT_translate";
66 static char OP_ROTATION[] = "TRANSFORM_OT_rotate";
67 static char OP_TOSPHERE[] = "TRANSFORM_OT_tosphere";
68 static char OP_RESIZE[] = "TRANSFORM_OT_resize";
69 static char OP_SKIN_RESIZE[] = "TRANSFORM_OT_skin_resize";
70 static char OP_SHEAR[] = "TRANSFORM_OT_shear";
71 static char OP_WARP[] = "TRANSFORM_OT_warp";
72 static char OP_SHRINK_FATTEN[] = "TRANSFORM_OT_shrink_fatten";
73 static char OP_PUSH_PULL[] = "TRANSFORM_OT_push_pull";
74 static char OP_TILT[] = "TRANSFORM_OT_tilt";
75 static char OP_TRACKBALL[] = "TRANSFORM_OT_trackball";
76 static char OP_MIRROR[] = "TRANSFORM_OT_mirror";
77 static char OP_EDGE_SLIDE[] = "TRANSFORM_OT_edge_slide";
78 static char OP_VERT_SLIDE[] = "TRANSFORM_OT_vert_slide";
79 static char OP_EDGE_CREASE[] = "TRANSFORM_OT_edge_crease";
80 static char OP_EDGE_BWEIGHT[] = "TRANSFORM_OT_edge_bevelweight";
81 static char OP_SEQ_SLIDE[] = "TRANSFORM_OT_seq_slide";
82
83 static void TRANSFORM_OT_translate(struct wmOperatorType *ot);
84 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot);
85 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot);
86 static void TRANSFORM_OT_resize(struct wmOperatorType *ot);
87 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot);
88 static void TRANSFORM_OT_shear(struct wmOperatorType *ot);
89 static void TRANSFORM_OT_warp(struct wmOperatorType *ot);
90 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot);
91 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot);
92 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot);
93 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot);
94 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot);
95 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot);
96 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot);
97 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot);
98 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot);
99 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot);
100
101 static TransformModeItem transform_modes[] =
102 {
103         {OP_TRANSLATION, TFM_TRANSLATION, TRANSFORM_OT_translate},
104         {OP_ROTATION, TFM_ROTATION, TRANSFORM_OT_rotate},
105         {OP_TOSPHERE, TFM_TOSPHERE, TRANSFORM_OT_tosphere},
106         {OP_RESIZE, TFM_RESIZE, TRANSFORM_OT_resize},
107         {OP_SKIN_RESIZE, TFM_SKIN_RESIZE, TRANSFORM_OT_skin_resize},
108         {OP_SHEAR, TFM_SHEAR, TRANSFORM_OT_shear},
109         {OP_WARP, TFM_WARP, TRANSFORM_OT_warp},
110         {OP_SHRINK_FATTEN, TFM_SHRINKFATTEN, TRANSFORM_OT_shrink_fatten},
111         {OP_PUSH_PULL, TFM_PUSHPULL, TRANSFORM_OT_push_pull},
112         {OP_TILT, TFM_TILT, TRANSFORM_OT_tilt},
113         {OP_TRACKBALL, TFM_TRACKBALL, TRANSFORM_OT_trackball},
114         {OP_MIRROR, TFM_MIRROR, TRANSFORM_OT_mirror},
115         {OP_EDGE_SLIDE, TFM_EDGE_SLIDE, TRANSFORM_OT_edge_slide},
116         {OP_VERT_SLIDE, TFM_VERT_SLIDE, TRANSFORM_OT_vert_slide},
117         {OP_EDGE_CREASE, TFM_CREASE, TRANSFORM_OT_edge_crease},
118         {OP_EDGE_BWEIGHT, TFM_BWEIGHT, TRANSFORM_OT_edge_bevelweight},
119         {OP_SEQ_SLIDE, TFM_SEQ_SLIDE, TRANSFORM_OT_seq_slide},
120         {NULL, 0}
121 };
122
123 EnumPropertyItem transform_mode_types[] =
124 {
125         {TFM_INIT, "INIT", 0, "Init", ""},
126         {TFM_DUMMY, "DUMMY", 0, "Dummy", ""},
127         {TFM_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
128         {TFM_ROTATION, "ROTATION", 0, "Rotation", ""},
129         {TFM_RESIZE, "RESIZE", 0, "Resize", ""},
130         {TFM_SKIN_RESIZE, "SKIN_RESIZE", 0, "Skin Resize", ""},
131         {TFM_TOSPHERE, "TOSPHERE", 0, "Tosphere", ""},
132         {TFM_SHEAR, "SHEAR", 0, "Shear", ""},
133         {TFM_WARP, "WARP", 0, "Warp", ""},
134         {TFM_SHRINKFATTEN, "SHRINKFATTEN", 0, "Shrinkfatten", ""},
135         {TFM_TILT, "TILT", 0, "Tilt", ""},
136         {TFM_TRACKBALL, "TRACKBALL", 0, "Trackball", ""},
137         {TFM_PUSHPULL, "PUSHPULL", 0, "Pushpull", ""},
138         {TFM_CREASE, "CREASE", 0, "Crease", ""},
139         {TFM_MIRROR, "MIRROR", 0, "Mirror", ""},
140         {TFM_BONESIZE, "BONE_SIZE", 0, "Bonesize", ""},
141         {TFM_BONE_ENVELOPE, "BONE_ENVELOPE", 0, "Bone_Envelope", ""},
142         {TFM_CURVE_SHRINKFATTEN, "CURVE_SHRINKFATTEN", 0, "Curve_Shrinkfatten", ""},
143         {TFM_MASK_SHRINKFATTEN, "MASK_SHRINKFATTEN", 0, "Mask_Shrinkfatten", ""},
144         {TFM_BONE_ROLL, "BONE_ROLL", 0, "Bone_Roll", ""},
145         {TFM_TIME_TRANSLATE, "TIME_TRANSLATE", 0, "Time_Translate", ""},
146         {TFM_TIME_SLIDE, "TIME_SLIDE", 0, "Time_Slide", ""},
147         {TFM_TIME_SCALE, "TIME_SCALE", 0, "Time_Scale", ""},
148         {TFM_TIME_EXTEND, "TIME_EXTEND", 0, "Time_Extend", ""},
149         {TFM_BAKE_TIME, "BAKE_TIME", 0, "Bake_Time", ""},
150         {TFM_BWEIGHT, "BWEIGHT", 0, "Bweight", ""},
151         {TFM_ALIGN, "ALIGN", 0, "Align", ""},
152         {TFM_EDGE_SLIDE, "EDGESLIDE", 0, "Edge Slide", ""},
153         {TFM_SEQ_SLIDE, "SEQSLIDE", 0, "Sequence Slide", ""},
154         {0, NULL, 0, NULL, NULL}
155 };
156
157 static int select_orientation_exec(bContext *C, wmOperator *op)
158 {
159         int orientation = RNA_enum_get(op->ptr, "orientation");
160
161         BIF_selectTransformOrientationValue(C, orientation);
162         
163         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
164
165         return OPERATOR_FINISHED;
166 }
167
168 static int select_orientation_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
169 {
170         uiPopupMenu *pup;
171         uiLayout *layout;
172
173         pup = uiPupMenuBegin(C, IFACE_("Orientation"), ICON_NONE);
174         layout = uiPupMenuLayout(pup);
175         uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
176         uiPupMenuEnd(C, pup);
177
178         return OPERATOR_CANCELLED;
179 }
180
181 static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
182 {
183         PropertyRNA *prop;
184
185         /* identifiers */
186         ot->name   = "Select Orientation";
187         ot->description = "Select transformation orientation";
188         ot->idname = "TRANSFORM_OT_select_orientation";
189         ot->flag   = OPTYPE_UNDO;
190
191         /* api callbacks */
192         ot->invoke = select_orientation_invoke;
193         ot->exec   = select_orientation_exec;
194         ot->poll   = ED_operator_view3d_active;
195
196         prop = RNA_def_property(ot->srna, "orientation", PROP_ENUM, PROP_NONE);
197         RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
198         RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
199 }
200
201
202 static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
203 {
204         View3D *v3d = CTX_wm_view3d(C);
205         int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
206
207         BIF_removeTransformOrientationIndex(C, selected_index);
208         
209         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
210         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
211
212         return OPERATOR_FINISHED;
213 }
214
215 static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
216 {
217         return delete_orientation_exec(C, op);
218 }
219
220 static int delete_orientation_poll(bContext *C)
221 {
222         int selected_index = -1;
223         View3D *v3d = CTX_wm_view3d(C);
224         
225         if (ED_operator_areaactive(C) == 0)
226                 return 0;
227         
228         
229         if (v3d) {
230                 selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
231         }
232         
233         return selected_index >= 0;
234 }
235
236 static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
237 {
238         /* identifiers */
239         ot->name   = "Delete Orientation";
240         ot->description = "Delete transformation orientation";
241         ot->idname = "TRANSFORM_OT_delete_orientation";
242         ot->flag   = OPTYPE_UNDO;
243
244         /* api callbacks */
245         ot->invoke = delete_orientation_invoke;
246         ot->exec   = delete_orientation_exec;
247         ot->poll   = delete_orientation_poll;
248 }
249
250 static int create_orientation_exec(bContext *C, wmOperator *op)
251 {
252         char name[MAX_NAME];
253         int use = RNA_boolean_get(op->ptr, "use");
254         int overwrite = RNA_boolean_get(op->ptr, "overwrite");
255         int use_view = RNA_boolean_get(op->ptr, "use_view");
256
257         RNA_string_get(op->ptr, "name", name);
258
259         if (use && !CTX_wm_view3d(C)) {
260                 BKE_report(op->reports, RPT_ERROR, "Create Orientation's 'use' parameter only valid in a 3DView context");
261                 return OPERATOR_CANCELLED;
262         }
263
264         BIF_createTransformOrientation(C, op->reports, name, use_view, use, overwrite);
265
266         WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
267         WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
268         
269         return OPERATOR_FINISHED;
270 }
271
272 static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
273 {
274         /* identifiers */
275         ot->name   = "Create Orientation";
276         ot->description = "Create transformation orientation from selection";
277         ot->idname = "TRANSFORM_OT_create_orientation";
278         ot->flag   = OPTYPE_REGISTER | OPTYPE_UNDO;
279
280         /* api callbacks */
281         ot->exec   = create_orientation_exec;
282         ot->poll   = ED_operator_areaactive;
283
284         RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Name of the new custom orientation");
285         RNA_def_boolean(ot->srna, "use_view", FALSE, "Use View",
286                         "Use the current view instead of the active object to create the new orientation");
287         RNA_def_boolean(ot->srna, "use", FALSE, "Use after creation", "Select orientation after its creation");
288         RNA_def_boolean(ot->srna, "overwrite", FALSE, "Overwrite previous",
289                         "Overwrite previously created orientation with same name");
290 }
291
292
293 #ifdef USE_LOOPSLIDE_HACK
294 /**
295  * Special hack for MESH_OT_loopcut_slide so we get back to the selection mode
296  */
297 static void transformops_loopsel_hack(bContext *C, wmOperator *op)
298 {
299         if (op->type->idname == OP_EDGE_SLIDE) {
300                 if (op->opm && op->opm->opm && op->opm->opm->prev) {
301                         wmOperator *op_prev = op->opm->opm->prev;
302                         Scene *scene = CTX_data_scene(C);
303                         int mesh_select_mode[3];
304                         PropertyRNA *prop = RNA_struct_find_property(op_prev->ptr, "mesh_select_mode_init");
305
306                         if (prop && RNA_property_is_set(op_prev->ptr, prop)) {
307                                 ToolSettings *ts = scene->toolsettings;
308                                 short selectmode_orig;
309
310                                 RNA_property_boolean_get_array(op_prev->ptr, prop, mesh_select_mode);
311                                 selectmode_orig = ((mesh_select_mode[0] ? SCE_SELECT_VERTEX : 0) |
312                                                    (mesh_select_mode[1] ? SCE_SELECT_EDGE   : 0) |
313                                                    (mesh_select_mode[2] ? SCE_SELECT_FACE   : 0));
314
315                                 /* still switch if we were originally in face select mode */
316                                 if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
317                                         BMEditMesh *em = BKE_editmesh_from_object(scene->obedit);
318                                         em->selectmode = ts->selectmode = selectmode_orig;
319                                         EDBM_selectmode_set(em);
320                                 }
321                         }
322                 }
323         }
324 }
325 #endif  /* USE_LOOPSLIDE_HACK */
326
327
328 static void transformops_exit(bContext *C, wmOperator *op)
329 {
330 #ifdef USE_LOOPSLIDE_HACK
331         transformops_loopsel_hack(C, op);
332 #endif
333
334         saveTransform(C, op->customdata, op);
335         MEM_freeN(op->customdata);
336         op->customdata = NULL;
337         G.moving = 0;
338 }
339
340 static int transformops_data(bContext *C, wmOperator *op, const wmEvent *event)
341 {
342         int retval = 1;
343         if (op->customdata == NULL) {
344                 TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data2");
345                 TransformModeItem *tmode;
346                 int mode = -1;
347
348                 for (tmode = transform_modes; tmode->idname; tmode++) {
349                         if (op->type->idname == tmode->idname) {
350                                 mode = tmode->mode;
351                                 break;
352                         }
353                 }
354
355                 if (mode == -1) {
356                         mode = RNA_enum_get(op->ptr, "mode");
357                 }
358
359                 retval = initTransform(C, t, op, event, mode);
360                 G.moving = 1;
361
362                 /* store data */
363                 if (retval) {
364                         op->customdata = t;
365                 }
366                 else {
367                         MEM_freeN(t);
368                 }
369         }
370
371         return retval; /* return 0 on error */
372 }
373
374 static int transform_modal(bContext *C, wmOperator *op, const wmEvent *event)
375 {
376         int exit_code;
377
378         TransInfo *t = op->customdata;
379         const enum TfmMode mode_prev = t->mode;
380
381 #if 0
382         // stable 2D mouse coords map to different 3D coords while the 3D mouse is active
383         // in other words, 2D deltas are no longer good enough!
384         // disable until individual 'transformers' behave better
385
386         if (event->type == NDOF_MOTION)
387                 return OPERATOR_PASS_THROUGH;
388 #endif
389
390         /* XXX insert keys are called here, and require context */
391         t->context = C;
392         exit_code = transformEvent(t, event);
393         t->context = NULL;
394
395         transformApply(C, t);
396
397         exit_code |= transformEnd(C, t);
398
399         if ((exit_code & OPERATOR_RUNNING_MODAL) == 0) {
400                 transformops_exit(C, op);
401                 exit_code &= ~OPERATOR_PASS_THROUGH; /* preventively remove passthrough */
402         }
403         else {
404                 if (mode_prev != t->mode) {
405                         /* WARNING: this is not normal to switch operator types
406                          * normally it would not be supported but transform happens
407                          * to share callbacks between differernt operators. */
408                         wmOperatorType *ot_new = NULL;
409                         TransformModeItem *item = transform_modes;
410                         while (item->idname) {
411                                 if (item->mode == t->mode) {
412                                         ot_new = WM_operatortype_find(item->idname, false);
413                                         break;
414                                 }
415                                 item++;
416                         }
417
418                         BLI_assert(ot_new != NULL);
419                         if (ot_new) {
420                                 WM_operator_type_set(op, ot_new);
421                         }
422                         /* end suspicious code */
423                 }
424         }
425
426         return exit_code;
427 }
428
429 static int transform_cancel(bContext *C, wmOperator *op)
430 {
431         TransInfo *t = op->customdata;
432
433         t->state = TRANS_CANCEL;
434         transformEnd(C, t);
435         transformops_exit(C, op);
436
437         return OPERATOR_CANCELLED;
438 }
439
440 static int transform_exec(bContext *C, wmOperator *op)
441 {
442         TransInfo *t;
443
444         if (!transformops_data(C, op, NULL)) {
445                 G.moving = 0;
446                 return OPERATOR_CANCELLED;
447         }
448
449         t = op->customdata;
450
451         t->options |= CTX_AUTOCONFIRM;
452
453         transformApply(C, t);
454
455         transformEnd(C, t);
456
457         transformops_exit(C, op);
458         
459         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
460
461         return OPERATOR_FINISHED;
462 }
463
464 static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
465 {
466         if (!transformops_data(C, op, event)) {
467                 G.moving = 0;
468                 return OPERATOR_CANCELLED;
469         }
470
471         if (RNA_struct_property_is_set(op->ptr, "value")) {
472                 return transform_exec(C, op);
473         }
474         else {
475                 /* add temp handler */
476                 WM_event_add_modal_handler(C, op);
477
478                 op->flag |= OP_GRAB_POINTER; // XXX maybe we want this with the manipulator only?
479                 return OPERATOR_RUNNING_MODAL;
480         }
481 }
482
483 void Transform_Properties(struct wmOperatorType *ot, int flags)
484 {
485         PropertyRNA *prop;
486
487         if (flags & P_AXIS) {
488                 prop = RNA_def_property(ot->srna, "axis", PROP_FLOAT, PROP_DIRECTION);
489                 RNA_def_property_array(prop, 3);
490                 /* Make this not hidden when there's a nice axis selection widget */
491                 RNA_def_property_flag(prop, PROP_HIDDEN);
492                 RNA_def_property_ui_text(prop, "Axis", "The axis around which the transformation occurs");
493         }
494
495         if (flags & P_CONSTRAINT) {
496                 RNA_def_boolean_vector(ot->srna, "constraint_axis", 3, NULL, "Constraint Axis", "");
497                 prop = RNA_def_property(ot->srna, "constraint_orientation", PROP_ENUM, PROP_NONE);
498                 RNA_def_property_ui_text(prop, "Orientation", "Transformation orientation");
499                 RNA_def_enum_funcs(prop, rna_TransformOrientation_itemf);
500         }
501
502         if (flags & P_MIRROR) {
503                 RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
504         }
505
506
507         if (flags & P_PROPORTIONAL) {
508                 RNA_def_enum(ot->srna, "proportional", proportional_editing_items, 0, "Proportional Editing", "");
509                 prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", proportional_falloff_items, 0,
510                                     "Proportional Editing Falloff", "Falloff type for proportional editing mode");
511                 RNA_def_property_translation_context(prop, BLF_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
512                 RNA_def_float(ot->srna, "proportional_size", 1, 0.00001f, FLT_MAX, "Proportional Size", "", 0.001, 100);
513         }
514
515         if (flags & P_SNAP) {
516                 prop = RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
517                 RNA_def_property_flag(prop, PROP_HIDDEN);
518
519                 if (flags & P_GEO_SNAP) {
520                         prop = RNA_def_enum(ot->srna, "snap_target", snap_target_items, 0, "Target", "");
521                         RNA_def_property_flag(prop, PROP_HIDDEN);
522                         prop = RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX);
523                         RNA_def_property_flag(prop, PROP_HIDDEN);
524                         
525                         if (flags & P_ALIGN_SNAP) {
526                                 prop = RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
527                                 RNA_def_property_flag(prop, PROP_HIDDEN);
528                                 prop = RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
529                                 RNA_def_property_flag(prop, PROP_HIDDEN);
530                         }
531                 }
532         }
533
534         if (flags & P_OPTIONS) {
535                 RNA_def_boolean(ot->srna, "texture_space", 0, "Edit Texture Space", "Edit Object data texture space");
536         }
537
538         if (flags & P_CORRECT_UV) {
539                 RNA_def_boolean(ot->srna, "correct_uv", 0, "Correct UVs", "Correct UV coordinates when transforming");
540         }
541
542         // 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
543         /*prop =*/ RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "Always confirm operation when releasing button");
544         //RNA_def_property_flag(prop, PROP_HIDDEN);
545 }
546
547 static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
548 {
549         /* identifiers */
550         ot->name   = "Translate";
551         ot->description = "Translate (move) selected items";
552         ot->idname = OP_TRANSLATION;
553         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
554
555         /* api callbacks */
556         ot->invoke = transform_invoke;
557         ot->exec   = transform_exec;
558         ot->modal  = transform_modal;
559         ot->cancel = transform_cancel;
560         ot->poll   = ED_operator_screenactive;
561
562         RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
563
564         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS);
565 }
566
567 static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
568 {
569         /* identifiers */
570         ot->name   = "Resize";
571         ot->description = "Scale (resize) selected items"; 
572         ot->idname = OP_RESIZE;
573         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
574
575         /* api callbacks */
576         ot->invoke = transform_invoke;
577         ot->exec   = transform_exec;
578         ot->modal  = transform_modal;
579         ot->cancel = transform_cancel;
580         ot->poll   = ED_operator_screenactive;
581
582         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
583
584         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS);
585 }
586
587 static int skin_resize_poll(bContext *C)
588 {
589         struct Object *obedit = CTX_data_edit_object(C);
590         if (obedit && obedit->type == OB_MESH) {
591                 BMEditMesh *em = BKE_editmesh_from_object(obedit);
592                 return (em && CustomData_has_layer(&em->bm->vdata, CD_MVERT_SKIN));
593         }
594         return 0;
595 }
596
597 static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
598 {
599         /* identifiers */
600         ot->name   = "Skin Resize";
601         ot->description = "Scale selected vertices' skin radii"; 
602         ot->idname = OP_SKIN_RESIZE;
603         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
604
605         /* api callbacks */
606         ot->invoke = transform_invoke;
607         ot->exec   = transform_exec;
608         ot->modal  = transform_modal;
609         ot->cancel = transform_cancel;
610         ot->poll   = skin_resize_poll;
611
612         RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
613
614         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS);
615 }
616
617 static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
618 {
619         PropertyRNA *prop;
620
621         /* identifiers */
622         ot->name   = "Trackball";
623         ot->description = "Trackball style rotation of selected items";
624         ot->idname = OP_TRACKBALL;
625         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
626
627         /* api callbacks */
628         ot->invoke = transform_invoke;
629         ot->exec   = transform_exec;
630         ot->modal  = transform_modal;
631         ot->cancel = transform_cancel;
632         ot->poll   = ED_operator_screenactive;
633
634         /* Maybe we could use float_vector_xyz here too? */
635         prop = RNA_def_float_vector(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
636         RNA_def_property_subtype(prop, PROP_ANGLE);
637
638         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
639 }
640
641 static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
642 {
643         PropertyRNA *prop;
644
645         /* identifiers */
646         ot->name = "Rotate";
647         ot->description = "Rotate selected items";
648         ot->idname = OP_ROTATION;
649         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
650
651         /* api callbacks */
652         ot->invoke = transform_invoke;
653         ot->exec   = transform_exec;
654         ot->modal  = transform_modal;
655         ot->cancel = transform_cancel;
656         ot->poll   = ED_operator_screenactive;
657
658         prop = RNA_def_float(ot->srna, "value", 0.0f, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
659         RNA_def_property_subtype(prop, PROP_ANGLE);
660
661         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP);
662 }
663
664 static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
665 {
666         PropertyRNA *prop;
667
668         /* identifiers */
669         ot->name = "Tilt";
670         /* optionals - 
671          * "Tilt selected vertices"
672          * "Specify an extra axis rotation for selected vertices of 3D curve" */
673         ot->description = "Tilt selected control vertices of 3D curve"; 
674         ot->idname = OP_TILT;
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_editcurve_3d;
683
684         prop = RNA_def_float(ot->srna, "value", 0.0, -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_PROPORTIONAL | P_MIRROR | P_SNAP);
688 }
689
690 static void TRANSFORM_OT_warp(struct wmOperatorType *ot)
691 {
692         /* identifiers */
693         ot->name   = "Warp";
694         ot->description = "Warp selected items around the cursor";
695         ot->idname = OP_WARP;
696         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
697
698         /* api callbacks */
699         ot->invoke = transform_invoke;
700         ot->exec   = transform_exec;
701         ot->modal  = transform_modal;
702         ot->cancel = transform_cancel;
703         ot->poll   = ED_operator_screenactive;
704
705         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
706
707         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
708         // XXX Warp axis?
709 }
710
711 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
712 {
713         /* identifiers */
714         ot->name   = "Shear";
715         ot->description = "Shear selected items along the horizontal screen axis";
716         ot->idname = OP_SHEAR;
717         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
718
719         /* api callbacks */
720         ot->invoke = transform_invoke;
721         ot->exec   = transform_exec;
722         ot->modal  = transform_modal;
723         ot->cancel = transform_cancel;
724         ot->poll   = ED_operator_screenactive;
725
726         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
727
728         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
729         // XXX Shear axis?
730 }
731
732 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
733 {
734         /* identifiers */
735         ot->name   = "Push/Pull";
736         ot->description = "Push/Pull selected items";
737         ot->idname = OP_PUSH_PULL;
738         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
739
740         /* api callbacks */
741         ot->invoke = transform_invoke;
742         ot->exec   = transform_exec;
743         ot->modal  = transform_modal;
744         ot->cancel = transform_cancel;
745         ot->poll   = ED_operator_screenactive;
746
747         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
748
749         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
750 }
751
752 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
753 {
754         /* identifiers */
755         ot->name   = "Shrink/Fatten";
756         ot->description = "Shrink/fatten selected vertices along normals";
757         ot->idname = OP_SHRINK_FATTEN;
758         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
759
760         /* api callbacks */
761         ot->invoke = transform_invoke;
762         ot->exec   = transform_exec;
763         ot->modal  = transform_modal;
764         ot->cancel = transform_cancel;
765         ot->poll   = ED_operator_editmesh;
766
767         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
768
769         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
770 }
771
772 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
773 {
774         /* identifiers */
775         ot->name   = "To Sphere";
776         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" 
777         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
778         ot->idname = OP_TOSPHERE;
779         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
780
781         /* api callbacks */
782         ot->invoke = transform_invoke;
783         ot->exec   = transform_exec;
784         ot->modal  = transform_modal;
785         ot->cancel = transform_cancel;
786         ot->poll   = ED_operator_screenactive;
787
788         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
789
790         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
791 }
792
793 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
794 {
795         /* identifiers */
796         ot->name   = "Mirror";
797         ot->description = "Mirror selected vertices around one or more axes";
798         ot->idname = OP_MIRROR;
799         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
800
801         /* api callbacks */
802         ot->invoke = transform_invoke;
803         ot->exec   = transform_exec;
804         ot->modal  = transform_modal;
805         ot->cancel = transform_cancel;
806         ot->poll   = ED_operator_screenactive;
807
808         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL);
809 }
810
811 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
812 {
813         /* identifiers */
814         ot->name   = "Edge Slide";
815         ot->description = "Slide an edge loop along a mesh"; 
816         ot->idname = OP_EDGE_SLIDE;
817         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
818
819         /* api callbacks */
820         ot->invoke = transform_invoke;
821         ot->exec   = transform_exec;
822         ot->modal  = transform_modal;
823         ot->cancel = transform_cancel;
824         ot->poll   = ED_operator_editmesh;
825
826         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
827
828         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
829 }
830
831 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
832 {
833         /* identifiers */
834         ot->name   = "Vertex Slide";
835         ot->description = "Slide a vertex along a mesh";
836         ot->idname = OP_VERT_SLIDE;
837         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
838
839         /* api callbacks */
840         ot->invoke = transform_invoke;
841         ot->exec   = transform_exec;
842         ot->modal  = transform_modal;
843         ot->cancel = transform_cancel;
844         ot->poll   = ED_operator_editmesh;
845
846         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
847
848         Transform_Properties(ot, P_MIRROR | P_SNAP);
849 }
850
851 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
852 {
853         /* identifiers */
854         ot->name   = "Edge Crease";
855         ot->description = "Change the crease of edges";
856         ot->idname = OP_EDGE_CREASE;
857         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
858
859         /* api callbacks */
860         ot->invoke = transform_invoke;
861         ot->exec   = transform_exec;
862         ot->modal  = transform_modal;
863         ot->cancel = transform_cancel;
864         ot->poll   = ED_operator_editmesh;
865
866         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
867
868         Transform_Properties(ot, P_SNAP);
869 }
870
871 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
872 {
873         /* identifiers */
874         ot->name   = "Edge Bevel Weight";
875         ot->description = "Change the bevel weight of edges";
876         ot->idname = OP_EDGE_BWEIGHT;
877         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
878
879         /* api callbacks */
880         ot->invoke = transform_invoke;
881         ot->exec   = transform_exec;
882         ot->modal  = transform_modal;
883         ot->cancel = transform_cancel;
884         ot->poll   = ED_operator_editmesh;
885
886         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
887
888         Transform_Properties(ot, P_SNAP);
889 }
890
891 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
892 {
893         /* identifiers */
894         ot->name   = "Sequence Slide";
895         ot->description = "Slide a sequence strip in time";
896         ot->idname = OP_SEQ_SLIDE;
897         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
898
899         /* api callbacks */
900         ot->invoke = transform_invoke;
901         ot->exec   = transform_exec;
902         ot->modal  = transform_modal;
903         ot->cancel = transform_cancel;
904         ot->poll   = ED_operator_sequencer_active;
905
906         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
907
908         Transform_Properties(ot, P_SNAP);
909 }
910
911 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
912 {
913         PropertyRNA *prop;
914
915         /* identifiers */
916         ot->name   = "Transform";
917         ot->description = "Transform selected items by mode type";
918         ot->idname = "TRANSFORM_OT_transform";
919         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
920
921         /* api callbacks */
922         ot->invoke = transform_invoke;
923         ot->exec   = transform_exec;
924         ot->modal  = transform_modal;
925         ot->cancel = transform_cancel;
926         ot->poll   = ED_operator_screenactive;
927
928         prop = RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
929         RNA_def_property_flag(prop, PROP_HIDDEN);
930
931         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
932
933         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP);
934 }
935
936 void transform_operatortypes(void)
937 {
938         TransformModeItem *tmode;
939
940         for (tmode = transform_modes; tmode->idname; tmode++) {
941                 WM_operatortype_append(tmode->opfunc);
942         }
943
944         WM_operatortype_append(TRANSFORM_OT_transform);
945
946         WM_operatortype_append(TRANSFORM_OT_select_orientation);
947         WM_operatortype_append(TRANSFORM_OT_create_orientation);
948         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
949 }
950
951 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
952 {
953         wmKeyMapItem *kmi;
954         wmKeyMap *modalmap;
955         
956         /* transform.c, only adds modal map once, checks if it's there */
957         modalmap = transform_modal_keymap(keyconf);
958
959         /* assign map to operators only the first time */
960         if (modalmap) {
961                 TransformModeItem *tmode;
962
963                 for (tmode = transform_modes; tmode->idname; tmode++) {
964                         WM_modalkeymap_assign(modalmap, tmode->idname);
965                 }
966                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
967         }
968         
969         switch (spaceid) {
970                 case SPACE_VIEW3D:
971                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
972
973                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
974
975                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
976
977                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
978
979                         WM_keymap_add_item(keymap, OP_WARP, WKEY, KM_PRESS, KM_SHIFT, 0);
980
981                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
982
983                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
984
985                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
986
987                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
988                         RNA_boolean_set(kmi->ptr, "use", TRUE);
989
990                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
991
992                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
993                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
994
995                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
996                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_element");
997
998
999                         kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
1000                         RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
1001
1002                         kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
1003                         RNA_boolean_set(kmi->ptr, "texture_space", TRUE);
1004
1005                         WM_keymap_add_item(keymap, OP_SKIN_RESIZE, AKEY, KM_PRESS, KM_CTRL, 0);
1006
1007                         break;
1008                 case SPACE_ACTION:
1009                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1010                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1011                         
1012                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1013                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1014                         
1015                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1016                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1017                         
1018                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1019                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1020                         
1021                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
1022                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
1023                         break;
1024                 case SPACE_IPO:
1025                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1026                         
1027                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1028                         
1029                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1030                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
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                         break;
1036                 case SPACE_NLA:
1037                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1038                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1039                         
1040                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1041                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1042                         
1043                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1044                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1045                         
1046                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1047                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1048                         break;
1049                 case SPACE_NODE:
1050                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
1051                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
1052                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
1053                         /* NB: small trick: macro operator poll may fail due to library data edit,
1054                          * in that case the secondary regular operators are called with same keymap.
1055                          */
1056                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
1057                         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
1058                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
1059                         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
1060                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
1061                         RNA_boolean_set(kmi->ptr, "release_confirm", TRUE);
1062
1063                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1064
1065                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1066
1067                         /* detach and translate */
1068                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", DKEY, KM_PRESS, KM_ALT, 0);
1069                         /* XXX release_confirm is set in the macro operator definition */
1070                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links_release", EVT_TWEAK_A, KM_ANY, KM_ALT, 0);
1071                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", EVT_TWEAK_S, KM_ANY, KM_ALT, 0);
1072
1073                         /* dettach and translate */
1074                         WM_keymap_add_item(keymap, "NODE_OT_detach_translate_attach", FKEY, KM_PRESS, KM_ALT, 0);
1075                         break;
1076                 case SPACE_SEQ:
1077                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
1078
1079                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
1080
1081                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1082                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1083                         break;
1084                 case SPACE_IMAGE:
1085                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1086
1087                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
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
1093                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1094
1095                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
1096
1097                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1098                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1099
1100                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1101                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_uv_element");
1102                         break;
1103                 case SPACE_CLIP:
1104                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1105                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1106                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1107                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1108                         break;
1109                 default:
1110                         break;
1111         }
1112 }
1113