45afeeb7da94e277361c9a91219639a54f3a448a
[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 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", proportional_editing_items, 0, "Proportional Editing", "");
528                 prop = RNA_def_enum(ot->srna, "proportional_edit_falloff", 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", 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         PropertyRNA *prop;
688
689         /* identifiers */
690         ot->name = "Tilt";
691         /* optionals - 
692          * "Tilt selected vertices"
693          * "Specify an extra axis rotation for selected vertices of 3D curve" */
694         ot->description = "Tilt selected control vertices of 3D curve"; 
695         ot->idname = OP_TILT;
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_editcurve_3d;
704
705         prop = RNA_def_float(ot->srna, "value", 0.0, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
706         RNA_def_property_subtype(prop, PROP_ANGLE);
707
708         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
709 }
710
711 static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
712 {
713         /* identifiers */
714         ot->name   = "Bend";
715         ot->description = "Bend selected items between the 3D cursor and the mouse";
716         ot->idname = OP_BEND;
717         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
718
719         /* api callbacks */
720         ot->invoke = transform_invoke;
721         // ot->exec   = transform_exec;  // unsupported
722         ot->modal  = transform_modal;
723         ot->cancel = transform_cancel;
724         ot->poll   = ED_operator_region_view3d_active;
725
726         RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
727
728         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
729 }
730
731 static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
732 {
733         /* identifiers */
734         ot->name   = "Shear";
735         ot->description = "Shear selected items along the horizontal screen axis";
736         ot->idname = OP_SHEAR;
737         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
738
739         /* api callbacks */
740         ot->invoke = transform_invoke;
741         ot->exec   = transform_exec;
742         ot->modal  = transform_modal;
743         ot->cancel = transform_cancel;
744         ot->poll   = ED_operator_screenactive;
745
746         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
747
748         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
749         // XXX Shear axis?
750 }
751
752 static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
753 {
754         /* identifiers */
755         ot->name   = "Push/Pull";
756         ot->description = "Push/Pull selected items";
757         ot->idname = OP_PUSH_PULL;
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_screenactive;
766
767         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
768
769         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
770 }
771
772 static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
773 {
774         /* identifiers */
775         ot->name   = "Shrink/Fatten";
776         ot->description = "Shrink/fatten selected vertices along normals";
777         ot->idname = OP_SHRINK_FATTEN;
778         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
779
780         /* api callbacks */
781         ot->invoke = transform_invoke;
782         ot->exec   = transform_exec;
783         ot->modal  = transform_modal;
784         ot->cancel = transform_cancel;
785         ot->poll   = ED_operator_editmesh;
786
787         RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
788
789         RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness");
790
791         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
792 }
793
794 static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
795 {
796         /* identifiers */
797         ot->name   = "To Sphere";
798         //added "around mesh center" to differentiate between "MESH_OT_vertices_to_sphere()" 
799         ot->description = "Move selected vertices outward in a spherical shape around mesh center";
800         ot->idname = OP_TOSPHERE;
801         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
802
803         /* api callbacks */
804         ot->invoke = transform_invoke;
805         ot->exec   = transform_exec;
806         ot->modal  = transform_modal;
807         ot->cancel = transform_cancel;
808         ot->poll   = ED_operator_screenactive;
809
810         RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
811
812         Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
813 }
814
815 static void TRANSFORM_OT_mirror(struct wmOperatorType *ot)
816 {
817         /* identifiers */
818         ot->name   = "Mirror";
819         ot->description = "Mirror selected vertices around one or more axes";
820         ot->idname = OP_MIRROR;
821         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
822
823         /* api callbacks */
824         ot->invoke = transform_invoke;
825         ot->exec   = transform_exec;
826         ot->modal  = transform_modal;
827         ot->cancel = transform_cancel;
828         ot->poll   = ED_operator_screenactive;
829
830         Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_GPENCIL_EDIT);
831 }
832
833 static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
834 {
835         PropertyRNA *prop;
836
837         /* identifiers */
838         ot->name   = "Edge Slide";
839         ot->description = "Slide an edge loop along a mesh"; 
840         ot->idname = OP_EDGE_SLIDE;
841         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
842
843         /* api callbacks */
844         ot->invoke = transform_invoke;
845         ot->exec   = transform_exec;
846         ot->modal  = transform_modal;
847         ot->cancel = transform_cancel;
848         ot->poll   = ED_operator_editmesh_region_view3d;
849
850         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
851
852         prop = RNA_def_boolean(ot->srna, "single_side", false, "Single Side", "");
853         RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
854         RNA_def_boolean(ot->srna, "use_even", false, "Even",
855                         "Make the edge loop match the shape of the adjacent edge loop");
856         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
857                         "When Even mode is active, flips between the two adjacent edge loops");
858         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
859                         "Clamp within the edge extents");
860
861         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
862 }
863
864 static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
865 {
866         /* identifiers */
867         ot->name   = "Vertex Slide";
868         ot->description = "Slide a vertex along a mesh";
869         ot->idname = OP_VERT_SLIDE;
870         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
871
872         /* api callbacks */
873         ot->invoke = transform_invoke;
874         ot->exec   = transform_exec;
875         ot->modal  = transform_modal;
876         ot->cancel = transform_cancel;
877         ot->poll   = ED_operator_editmesh_region_view3d;
878
879         RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
880         RNA_def_boolean(ot->srna, "use_even", false, "Even",
881                         "Make the edge loop match the shape of the adjacent edge loop");
882         RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
883                         "When Even mode is active, flips between the two adjacent edge loops");
884         RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
885                         "Clamp within the edge extents");
886
887         Transform_Properties(ot, P_MIRROR | P_SNAP | P_CORRECT_UV);
888 }
889
890 static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
891 {
892         /* identifiers */
893         ot->name   = "Edge Crease";
894         ot->description = "Change the crease of edges";
895         ot->idname = OP_EDGE_CREASE;
896         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
897
898         /* api callbacks */
899         ot->invoke = transform_invoke;
900         ot->exec   = transform_exec;
901         ot->modal  = transform_modal;
902         ot->cancel = transform_cancel;
903         ot->poll   = ED_operator_editmesh;
904
905         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
906
907         Transform_Properties(ot, P_SNAP);
908 }
909
910 static int edge_bevelweight_exec(bContext *C, wmOperator *op)
911 {
912         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
913
914         /* auto-enable bevel edge weight drawing, then chain to common transform code */
915         me->drawflag |= ME_DRAWBWEIGHTS;
916
917         return transform_exec(C, op);
918 }
919
920 static int edge_bevelweight_invoke(bContext *C, wmOperator *op, const wmEvent *event)
921 {
922         Mesh *me = (Mesh *)CTX_data_edit_object(C)->data;
923
924         /* auto-enable bevel edge weight drawing, then chain to common transform code */
925         me->drawflag |= ME_DRAWBWEIGHTS;
926
927         return transform_invoke(C, op, event);
928 }
929
930
931 static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
932 {
933         /* identifiers */
934         ot->name   = "Edge Bevel Weight";
935         ot->description = "Change the bevel weight of edges";
936         ot->idname = OP_EDGE_BWEIGHT;
937         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
938
939         /* api callbacks */
940         ot->invoke = edge_bevelweight_invoke;
941         ot->exec   = edge_bevelweight_exec;
942         ot->modal  = transform_modal;
943         ot->cancel = transform_cancel;
944         ot->poll   = ED_operator_editmesh;
945
946         RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
947
948         Transform_Properties(ot, P_SNAP);
949 }
950
951 static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
952 {
953         /* identifiers */
954         ot->name   = "Sequence Slide";
955         ot->description = "Slide a sequence strip in time";
956         ot->idname = OP_SEQ_SLIDE;
957         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
958
959         /* api callbacks */
960         ot->invoke = transform_invoke;
961         ot->exec   = transform_exec;
962         ot->modal  = transform_modal;
963         ot->cancel = transform_cancel;
964         ot->poll   = ED_operator_sequencer_active;
965
966         RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
967
968         Transform_Properties(ot, P_SNAP);
969 }
970
971 static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
972 {
973         PropertyRNA *prop;
974
975         /* identifiers */
976         ot->name   = "Transform";
977         ot->description = "Transform selected items by mode type";
978         ot->idname = "TRANSFORM_OT_transform";
979         ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
980
981         /* api callbacks */
982         ot->invoke = transform_invoke;
983         ot->exec   = transform_exec;
984         ot->modal  = transform_modal;
985         ot->cancel = transform_cancel;
986         ot->poll   = ED_operator_screenactive;
987
988         prop = RNA_def_enum(ot->srna, "mode", transform_mode_types, TFM_TRANSLATION, "Mode", "");
989         RNA_def_property_flag(prop, PROP_HIDDEN);
990
991         RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
992
993         Transform_Properties(ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT);
994 }
995
996 void transform_operatortypes(void)
997 {
998         TransformModeItem *tmode;
999
1000         for (tmode = transform_modes; tmode->idname; tmode++) {
1001                 WM_operatortype_append(tmode->opfunc);
1002         }
1003
1004         WM_operatortype_append(TRANSFORM_OT_transform);
1005
1006         WM_operatortype_append(TRANSFORM_OT_select_orientation);
1007         WM_operatortype_append(TRANSFORM_OT_create_orientation);
1008         WM_operatortype_append(TRANSFORM_OT_delete_orientation);
1009 }
1010
1011 void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spaceid)
1012 {
1013         wmKeyMapItem *kmi;
1014         wmKeyMap *modalmap;
1015         
1016         /* transform.c, only adds modal map once, checks if it's there */
1017         modalmap = transform_modal_keymap(keyconf);
1018
1019         /* assign map to operators only the first time */
1020         if (modalmap) {
1021                 TransformModeItem *tmode;
1022
1023                 for (tmode = transform_modes; tmode->idname; tmode++) {
1024                         WM_modalkeymap_assign(modalmap, tmode->idname);
1025                 }
1026                 WM_modalkeymap_assign(modalmap, "TRANSFORM_OT_transform");
1027         }
1028         
1029         switch (spaceid) {
1030                 case SPACE_VIEW3D:
1031                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1032
1033                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1034
1035                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1036
1037                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1038
1039                         WM_keymap_add_item(keymap, OP_BEND, WKEY, KM_PRESS, KM_SHIFT, 0);
1040
1041                         WM_keymap_add_item(keymap, OP_TOSPHERE, SKEY, KM_PRESS, KM_ALT | KM_SHIFT, 0);
1042
1043                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1044
1045                         WM_keymap_add_item(keymap, "TRANSFORM_OT_select_orientation", SPACEKEY, KM_PRESS, KM_ALT, 0);
1046
1047                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_create_orientation", SPACEKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
1048                         RNA_boolean_set(kmi->ptr, "use", true);
1049
1050                         WM_keymap_add_item(keymap, OP_MIRROR, MKEY, KM_PRESS, KM_CTRL, 0);
1051
1052                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1053                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1054
1055                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1056                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_element");
1057
1058
1059                         kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
1060                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1061
1062                         kmi = WM_keymap_add_item(keymap, OP_RESIZE, TKEY, KM_PRESS, KM_SHIFT | KM_ALT, 0);
1063                         RNA_boolean_set(kmi->ptr, "texture_space", true);
1064
1065                         WM_keymap_add_item(keymap, OP_SKIN_RESIZE, AKEY, KM_PRESS, KM_CTRL, 0);
1066
1067                         break;
1068                 case SPACE_ACTION:
1069                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1070                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1071                         
1072                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1073                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_TRANSLATE);
1074                         
1075                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1076                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1077                         
1078                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1079                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1080                         
1081                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", TKEY, KM_PRESS, KM_SHIFT, 0);
1082                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SLIDE);
1083                         break;
1084                 case SPACE_IPO:
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                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1090                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1091                         
1092                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1093                         
1094                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1095                         break;
1096                 case SPACE_NLA:
1097                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", GKEY, KM_PRESS, 0, 0);
1098                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1099                         
1100                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EVT_TWEAK_S, KM_ANY, 0, 0);
1101                         RNA_enum_set(kmi->ptr, "mode", TFM_TRANSLATION);
1102                         
1103                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1104                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1105                         
1106                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", SKEY, KM_PRESS, 0, 0);
1107                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_SCALE);
1108                         break;
1109                 case SPACE_NODE:
1110                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", GKEY, KM_PRESS, 0, 0);
1111                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_A, KM_ANY, 0, 0);
1112                         WM_keymap_add_item(keymap, "NODE_OT_translate_attach", EVT_TWEAK_S, KM_ANY, 0, 0);
1113                         /* NB: small trick: macro operator poll may fail due to library data edit,
1114                          * in that case the secondary regular operators are called with same keymap.
1115                          */
1116                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", GKEY, KM_PRESS, 0, 0);
1117                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1118                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_A, KM_ANY, 0, 0);
1119                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1120                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_translate", EVT_TWEAK_S, KM_ANY, 0, 0);
1121                         RNA_boolean_set(kmi->ptr, "release_confirm", true);
1122
1123                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1124
1125                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1126
1127                         /* detach and translate */
1128                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", DKEY, KM_PRESS, KM_ALT, 0);
1129                         /* XXX release_confirm is set in the macro operator definition */
1130                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links_release", EVT_TWEAK_A, KM_ANY, KM_ALT, 0);
1131                         WM_keymap_add_item(keymap, "NODE_OT_move_detach_links", EVT_TWEAK_S, KM_ANY, KM_ALT, 0);
1132
1133                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1134                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1135                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1136                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_node_element");
1137                         break;
1138                 case SPACE_SEQ:
1139                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, GKEY, KM_PRESS, 0, 0);
1140
1141                         WM_keymap_add_item(keymap, OP_SEQ_SLIDE, EVT_TWEAK_S, KM_ANY, 0, 0);
1142
1143                         kmi = WM_keymap_add_item(keymap, "TRANSFORM_OT_transform", EKEY, KM_PRESS, 0, 0);
1144                         RNA_enum_set(kmi->ptr, "mode", TFM_TIME_EXTEND);
1145                         break;
1146                 case SPACE_IMAGE:
1147                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1148
1149                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1150
1151                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1152
1153                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1154
1155                         WM_keymap_add_item(keymap, OP_SHEAR, SKEY, KM_PRESS, KM_ALT | KM_CTRL | KM_SHIFT, 0);
1156
1157                         WM_keymap_add_item(keymap, "TRANSFORM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0);
1158
1159                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0);
1160                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.use_snap");
1161
1162                         kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
1163                         RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_uv_element");
1164                         break;
1165                 case SPACE_CLIP:
1166                         WM_keymap_add_item(keymap, OP_TRANSLATION, GKEY, KM_PRESS, 0, 0);
1167                         WM_keymap_add_item(keymap, OP_TRANSLATION, EVT_TWEAK_S, KM_ANY, 0, 0);
1168                         WM_keymap_add_item(keymap, OP_RESIZE, SKEY, KM_PRESS, 0, 0);
1169                         WM_keymap_add_item(keymap, OP_ROTATION, RKEY, KM_PRESS, 0, 0);
1170                         break;
1171                 default:
1172                         break;
1173         }
1174 }
1175