CMake: Use GCC7's -Wimplicit-fallthrough=5
[blender.git] / source / blender / editors / transform / transform.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  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/editors/transform/transform.c
29  *  \ingroup edtransform
30  */
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <math.h>
36 #include <float.h>
37
38 #include "MEM_guardedalloc.h"
39
40 #include "DNA_anim_types.h"
41 #include "DNA_armature_types.h"
42 #include "DNA_constraint_types.h"
43 #include "DNA_mask_types.h"
44 #include "DNA_movieclip_types.h"
45 #include "DNA_scene_types.h"  /* PET modes */
46
47 #include "BLI_alloca.h"
48 #include "BLI_utildefines.h"
49 #include "BLI_math.h"
50 #include "BLI_rect.h"
51 #include "BLI_listbase.h"
52 #include "BLI_string.h"
53 #include "BLI_ghash.h"
54 #include "BLI_stackdefines.h"
55 #include "BLI_memarena.h"
56
57 #include "BKE_nla.h"
58 #include "BKE_editmesh.h"
59 #include "BKE_editmesh_bvh.h"
60 #include "BKE_context.h"
61 #include "BKE_constraint.h"
62 #include "BKE_particle.h"
63 #include "BKE_unit.h"
64 #include "BKE_mask.h"
65 #include "BKE_report.h"
66
67 #include "BIF_gl.h"
68 #include "BIF_glutil.h"
69
70 #include "ED_image.h"
71 #include "ED_keyframing.h"
72 #include "ED_screen.h"
73 #include "ED_space_api.h"
74 #include "ED_markers.h"
75 #include "ED_view3d.h"
76 #include "ED_mesh.h"
77 #include "ED_clip.h"
78 #include "ED_node.h"
79
80 #include "WM_types.h"
81 #include "WM_api.h"
82
83 #include "UI_view2d.h"
84 #include "UI_interface.h"
85 #include "UI_interface_icons.h"
86 #include "UI_resources.h"
87
88 #include "RNA_access.h"
89
90 #include "BLF_api.h"
91 #include "BLT_translation.h"
92
93 #include "transform.h"
94
95 /* Disabling, since when you type you know what you are doing, and being able to set it to zero is handy. */
96 // #define USE_NUM_NO_ZERO
97
98 static void drawTransformApply(const struct bContext *C, ARegion *ar, void *arg);
99 static void doEdgeSlide(TransInfo *t, float perc);
100 static void doVertSlide(TransInfo *t, float perc);
101
102 static void drawEdgeSlide(TransInfo *t);
103 static void drawVertSlide(TransInfo *t);
104 static void postInputRotation(TransInfo *t, float values[3]);
105
106 static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], const short around);
107 static void initSnapSpatial(TransInfo *t, float r_snap[3]);
108
109
110 /* Transform Callbacks */
111 static void initBend(TransInfo *t);
112 static eRedrawFlag handleEventBend(TransInfo *t, const struct wmEvent *event);
113 static void Bend(TransInfo *t, const int mval[2]);
114
115 static void initShear(TransInfo *t);
116 static eRedrawFlag handleEventShear(TransInfo *t, const struct wmEvent *event);
117 static void applyShear(TransInfo *t, const int mval[2]);
118
119 static void initResize(TransInfo *t);
120 static void applyResize(TransInfo *t, const int mval[2]);
121
122 static void initSkinResize(TransInfo *t);
123 static void applySkinResize(TransInfo *t, const int mval[2]);
124
125 static void initTranslation(TransInfo *t);
126 static void applyTranslation(TransInfo *t, const int mval[2]);
127
128 static void initToSphere(TransInfo *t);
129 static void applyToSphere(TransInfo *t, const int mval[2]);
130
131 static void initRotation(TransInfo *t);
132 static void applyRotation(TransInfo *t, const int mval[2]);
133
134 static void initShrinkFatten(TransInfo *t);
135 static void applyShrinkFatten(TransInfo *t, const int mval[2]);
136
137 static void initTilt(TransInfo *t);
138 static void applyTilt(TransInfo *t, const int mval[2]);
139
140 static void initCurveShrinkFatten(TransInfo *t);
141 static void applyCurveShrinkFatten(TransInfo *t, const int mval[2]);
142
143 static void initMaskShrinkFatten(TransInfo *t);
144 static void applyMaskShrinkFatten(TransInfo *t, const int mval[2]);
145
146 static void initGPShrinkFatten(TransInfo *t);
147 static void applyGPShrinkFatten(TransInfo *t, const int mval[2]);
148
149 static void initTrackball(TransInfo *t);
150 static void applyTrackball(TransInfo *t, const int mval[2]);
151
152 static void initPushPull(TransInfo *t);
153 static void applyPushPull(TransInfo *t, const int mval[2]);
154
155 static void initBevelWeight(TransInfo *t);
156 static void applyBevelWeight(TransInfo *t, const int mval[2]);
157
158 static void initCrease(TransInfo *t);
159 static void applyCrease(TransInfo *t, const int mval[2]);
160
161 static void initBoneSize(TransInfo *t);
162 static void applyBoneSize(TransInfo *t, const int mval[2]);
163
164 static void initBoneEnvelope(TransInfo *t);
165 static void applyBoneEnvelope(TransInfo *t, const int mval[2]);
166
167 static void initBoneRoll(TransInfo *t);
168 static void applyBoneRoll(TransInfo *t, const int mval[2]);
169
170 static void initEdgeSlide_ex(TransInfo *t, bool use_double_side, bool use_even, bool flipped, bool use_clamp);
171 static void initEdgeSlide(TransInfo *t);
172 static eRedrawFlag handleEventEdgeSlide(TransInfo *t, const struct wmEvent *event);
173 static void applyEdgeSlide(TransInfo *t, const int mval[2]);
174
175 static void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp);
176 static void initVertSlide(TransInfo *t);
177 static eRedrawFlag handleEventVertSlide(TransInfo *t, const struct wmEvent *event);
178 static void applyVertSlide(TransInfo *t, const int mval[2]);
179
180 static void initTimeTranslate(TransInfo *t);
181 static void applyTimeTranslate(TransInfo *t, const int mval[2]);
182
183 static void initTimeSlide(TransInfo *t);
184 static void applyTimeSlide(TransInfo *t, const int mval[2]);
185
186 static void initTimeScale(TransInfo *t);
187 static void applyTimeScale(TransInfo *t, const int mval[2]);
188
189 static void initBakeTime(TransInfo *t);
190 static void applyBakeTime(TransInfo *t, const int mval[2]);
191
192 static void initMirror(TransInfo *t);
193 static void applyMirror(TransInfo *t, const int mval[2]);
194
195 static void initAlign(TransInfo *t);
196 static void applyAlign(TransInfo *t, const int mval[2]);
197
198 static void initSeqSlide(TransInfo *t);
199 static void applySeqSlide(TransInfo *t, const int mval[2]);
200 /* end transform callbacks */
201
202
203 static bool transdata_check_local_center(TransInfo *t, short around)
204 {
205         return ((around == V3D_AROUND_LOCAL_ORIGINS) && (
206                     (t->flag & (T_OBJECT | T_POSE)) ||
207                     (t->obedit && ELEM(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)) ||
208                     (t->spacetype == SPACE_IPO) ||
209                     (t->options & (CTX_MOVIECLIP | CTX_MASK | CTX_PAINT_CURVE)))
210                 );
211 }
212
213 bool transdata_check_local_islands(TransInfo *t, short around)
214 {
215         return ((around == V3D_AROUND_LOCAL_ORIGINS) && (
216                 (t->obedit && ELEM(t->obedit->type, OB_MESH))));
217 }
218
219 /* ************************** SPACE DEPENDANT CODE **************************** */
220
221 void setTransformViewMatrices(TransInfo *t)
222 {
223         if (t->spacetype == SPACE_VIEW3D && t->ar && t->ar->regiontype == RGN_TYPE_WINDOW) {
224                 RegionView3D *rv3d = t->ar->regiondata;
225
226                 copy_m4_m4(t->viewmat, rv3d->viewmat);
227                 copy_m4_m4(t->viewinv, rv3d->viewinv);
228                 copy_m4_m4(t->persmat, rv3d->persmat);
229                 copy_m4_m4(t->persinv, rv3d->persinv);
230                 t->persp = rv3d->persp;
231         }
232         else {
233                 unit_m4(t->viewmat);
234                 unit_m4(t->viewinv);
235                 unit_m4(t->persmat);
236                 unit_m4(t->persinv);
237                 t->persp = RV3D_ORTHO;
238         }
239
240         calculateCenter2D(t);
241 }
242
243 void setTransformViewAspect(TransInfo *t, float r_aspect[3])
244 {
245         copy_v3_fl(r_aspect, 1.0f);
246
247         if (t->spacetype == SPACE_IMAGE) {
248                 SpaceImage *sima = t->sa->spacedata.first;
249
250                 if (t->options & CTX_MASK) {
251                         ED_space_image_get_aspect(sima, &r_aspect[0], &r_aspect[1]);
252                 }
253                 else if (t->options & CTX_PAINT_CURVE) {
254                         /* pass */
255                 }
256                 else {
257                         ED_space_image_get_uv_aspect(sima, &r_aspect[0], &r_aspect[1]);
258                 }
259         }
260         else if (t->spacetype == SPACE_CLIP) {
261                 SpaceClip *sclip = t->sa->spacedata.first;
262
263                 if (t->options & CTX_MOVIECLIP) {
264                         ED_space_clip_get_aspect_dimension_aware(sclip, &r_aspect[0], &r_aspect[1]);
265                 }
266                 else {
267                         ED_space_clip_get_aspect(sclip, &r_aspect[0], &r_aspect[1]);
268                 }
269         }
270         else if (t->spacetype == SPACE_IPO) {
271                 /* depemds on context of usage */
272         }
273 }
274
275 static void convertViewVec2D(View2D *v2d, float r_vec[3], int dx, int dy)
276 {
277         float divx = BLI_rcti_size_x(&v2d->mask);
278         float divy = BLI_rcti_size_y(&v2d->mask);
279
280         r_vec[0] = BLI_rctf_size_x(&v2d->cur) * dx / divx;
281         r_vec[1] = BLI_rctf_size_y(&v2d->cur) * dy / divy;
282         r_vec[2] = 0.0f;
283 }
284
285 static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy)
286 {
287         float divx = BLI_rcti_size_x(&v2d->mask);
288         float divy = BLI_rcti_size_y(&v2d->mask);
289
290         float mulx = BLI_rctf_size_x(&v2d->cur);
291         float muly = BLI_rctf_size_y(&v2d->cur);
292
293         /* difference with convertViewVec2D */
294         /* clamp w/h, mask only */
295         if (mulx / divx < muly / divy) {
296                 divy = divx;
297                 muly = mulx;
298         }
299         else {
300                 divx = divy;
301                 mulx = muly;
302         }
303         /* end difference */
304
305         r_vec[0] = mulx * dx / divx;
306         r_vec[1] = muly * dy / divy;
307         r_vec[2] = 0.0f;
308 }
309
310 void convertViewVec(TransInfo *t, float r_vec[3], double dx, double dy)
311 {
312         if ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) {
313                 if (t->options & CTX_PAINT_CURVE) {
314                         r_vec[0] = dx;
315                         r_vec[1] = dy;
316                 }
317                 else {
318                         const float mval_f[2] = {(float)dx, (float)dy};
319                         ED_view3d_win_to_delta(t->ar, mval_f, r_vec, t->zfac);
320                 }
321         }
322         else if (t->spacetype == SPACE_IMAGE) {
323                 if (t->options & CTX_MASK) {
324                         convertViewVec2D_mask(t->view, r_vec, dx, dy);
325                 }
326                 else if (t->options & CTX_PAINT_CURVE) {
327                         r_vec[0] = dx;
328                         r_vec[1] = dy;
329                 }
330                 else {
331                         convertViewVec2D(t->view, r_vec, dx, dy);
332                 }
333
334                 r_vec[0] *= t->aspect[0];
335                 r_vec[1] *= t->aspect[1];
336         }
337         else if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
338                 convertViewVec2D(t->view, r_vec, dx, dy);
339         }
340         else if (ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) {
341                 convertViewVec2D(&t->ar->v2d, r_vec, dx, dy);
342         }
343         else if (t->spacetype == SPACE_CLIP) {
344                 if (t->options & CTX_MASK) {
345                         convertViewVec2D_mask(t->view, r_vec, dx, dy);
346                 }
347                 else {
348                         convertViewVec2D(t->view, r_vec, dx, dy);
349                 }
350
351                 r_vec[0] *= t->aspect[0];
352                 r_vec[1] *= t->aspect[1];
353         }
354         else {
355                 printf("%s: called in an invalid context\n", __func__);
356                 zero_v3(r_vec);
357         }
358 }
359
360 void projectIntViewEx(TransInfo *t, const float vec[3], int adr[2], const eV3DProjTest flag)
361 {
362         if (t->spacetype == SPACE_VIEW3D) {
363                 if (t->ar->regiontype == RGN_TYPE_WINDOW) {
364                         if (ED_view3d_project_int_global(t->ar, vec, adr, flag) != V3D_PROJ_RET_OK) {
365                                 adr[0] = (int)2140000000.0f;  /* this is what was done in 2.64, perhaps we can be smarter? */
366                                 adr[1] = (int)2140000000.0f;
367                         }
368                 }
369         }
370         else if (t->spacetype == SPACE_IMAGE) {
371                 SpaceImage *sima = t->sa->spacedata.first;
372
373                 if (t->options & CTX_MASK) {
374                         float v[2];
375
376                         v[0] = vec[0] / t->aspect[0];
377                         v[1] = vec[1] / t->aspect[1];
378
379                         BKE_mask_coord_to_image(sima->image, &sima->iuser, v, v);
380
381                         ED_image_point_pos__reverse(sima, t->ar, v, v);
382
383                         adr[0] = v[0];
384                         adr[1] = v[1];
385                 }
386                 else if (t->options & CTX_PAINT_CURVE) {
387                         adr[0] = vec[0];
388                         adr[1] = vec[1];
389                 }
390                 else {
391                         float v[2];
392
393                         v[0] = vec[0] / t->aspect[0];
394                         v[1] = vec[1] / t->aspect[1];
395
396                         UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]);
397                 }
398         }
399         else if (t->spacetype == SPACE_ACTION) {
400                 int out[2] = {0, 0};
401 #if 0
402                 SpaceAction *sact = t->sa->spacedata.first;
403
404                 if (sact->flag & SACTION_DRAWTIME) {
405                         //vec[0] = vec[0]/((t->scene->r.frs_sec / t->scene->r.frs_sec_base));
406                         /* same as below */
407                         UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]);
408                 }
409                 else
410 #endif
411                 {
412                         UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]);
413                 }
414
415                 adr[0] = out[0];
416                 adr[1] = out[1];
417         }
418         else if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
419                 int out[2] = {0, 0};
420
421                 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]);
422                 adr[0] = out[0];
423                 adr[1] = out[1];
424         }
425         else if (t->spacetype == SPACE_SEQ) { /* XXX not tested yet, but should work */
426                 int out[2] = {0, 0};
427
428                 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &out[0], &out[1]);
429                 adr[0] = out[0];
430                 adr[1] = out[1];
431         }
432         else if (t->spacetype == SPACE_CLIP) {
433                 SpaceClip *sc = t->sa->spacedata.first;
434
435                 if (t->options & CTX_MASK) {
436                         MovieClip *clip = ED_space_clip_get_clip(sc);
437
438                         if (clip) {
439                                 float v[2];
440
441                                 v[0] = vec[0] / t->aspect[0];
442                                 v[1] = vec[1] / t->aspect[1];
443
444                                 BKE_mask_coord_to_movieclip(sc->clip, &sc->user, v, v);
445
446                                 ED_clip_point_stable_pos__reverse(sc, t->ar, v, v);
447
448                                 adr[0] = v[0];
449                                 adr[1] = v[1];
450                         }
451                         else {
452                                 adr[0] = 0;
453                                 adr[1] = 0;
454                         }
455                 }
456                 else if (t->options & CTX_MOVIECLIP) {
457                         float v[2];
458
459                         v[0] = vec[0] / t->aspect[0];
460                         v[1] = vec[1] / t->aspect[1];
461
462                         UI_view2d_view_to_region(t->view, v[0], v[1], &adr[0], &adr[1]);
463                 }
464                 else {
465                         BLI_assert(0);
466                 }
467         }
468         else if (t->spacetype == SPACE_NODE) {
469                 UI_view2d_view_to_region((View2D *)t->view, vec[0], vec[1], &adr[0], &adr[1]);
470         }
471 }
472 void projectIntView(TransInfo *t, const float vec[3], int adr[2])
473 {
474         projectIntViewEx(t, vec, adr, V3D_PROJ_TEST_NOP);
475 }
476
477 void projectFloatViewEx(TransInfo *t, const float vec[3], float adr[2], const eV3DProjTest flag)
478 {
479         switch (t->spacetype) {
480                 case SPACE_VIEW3D:
481                 {
482                         if (t->options & CTX_PAINT_CURVE) {
483                                 adr[0] = vec[0];
484                                 adr[1] = vec[1];
485                         }
486                         else if (t->ar->regiontype == RGN_TYPE_WINDOW) {
487                                 /* allow points behind the view [#33643] */
488                                 if (ED_view3d_project_float_global(t->ar, vec, adr, flag) != V3D_PROJ_RET_OK) {
489                                         /* XXX, 2.64 and prior did this, weak! */
490                                         adr[0] = t->ar->winx / 2.0f;
491                                         adr[1] = t->ar->winy / 2.0f;
492                                 }
493                                 return;
494                         }
495                         break;
496                 }
497                 default:
498                 {
499                         int a[2] = {0, 0};
500                         projectIntView(t, vec, a);
501                         adr[0] = a[0];
502                         adr[1] = a[1];
503                         break;
504                 }
505         }
506 }
507 void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
508 {
509         projectFloatViewEx(t, vec, adr, V3D_PROJ_TEST_NOP);
510 }
511
512 void applyAspectRatio(TransInfo *t, float vec[2])
513 {
514         if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION) && !(t->options & CTX_PAINT_CURVE)) {
515                 SpaceImage *sima = t->sa->spacedata.first;
516
517                 if ((sima->flag & SI_COORDFLOATS) == 0) {
518                         int width, height;
519                         ED_space_image_get_size(sima, &width, &height);
520
521                         vec[0] *= width;
522                         vec[1] *= height;
523                 }
524
525                 vec[0] /= t->aspect[0];
526                 vec[1] /= t->aspect[1];
527         }
528         else if ((t->spacetype == SPACE_CLIP) && (t->mode == TFM_TRANSLATION)) {
529                 if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
530                         vec[0] /= t->aspect[0];
531                         vec[1] /= t->aspect[1];
532                 }
533         }
534 }
535
536 void removeAspectRatio(TransInfo *t, float vec[2])
537 {
538         if ((t->spacetype == SPACE_IMAGE) && (t->mode == TFM_TRANSLATION)) {
539                 SpaceImage *sima = t->sa->spacedata.first;
540
541                 if ((sima->flag & SI_COORDFLOATS) == 0) {
542                         int width, height;
543                         ED_space_image_get_size(sima, &width, &height);
544
545                         vec[0] /= width;
546                         vec[1] /= height;
547                 }
548
549                 vec[0] *= t->aspect[0];
550                 vec[1] *= t->aspect[1];
551         }
552         else if ((t->spacetype == SPACE_CLIP) && (t->mode == TFM_TRANSLATION)) {
553                 if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
554                         vec[0] *= t->aspect[0];
555                         vec[1] *= t->aspect[1];
556                 }
557         }
558 }
559
560 static void viewRedrawForce(const bContext *C, TransInfo *t)
561 {
562         if (t->options & CTX_GPENCIL_STROKES) {
563                 WM_event_add_notifier(C, NC_GPENCIL | NA_EDITED, NULL);
564         }
565         else if (t->spacetype == SPACE_VIEW3D) {
566                 if (t->options & CTX_PAINT_CURVE) {
567                         wmWindow *window = CTX_wm_window(C);
568                         WM_paint_cursor_tag_redraw(window, t->ar);
569                 }
570                 else {
571                         /* Do we need more refined tags? */
572                         if (t->flag & T_POSE)
573                                 WM_event_add_notifier(C, NC_OBJECT | ND_POSE, NULL);
574                         else
575                                 WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
576
577                         /* for realtime animation record - send notifiers recognised by animation editors */
578                         // XXX: is this notifier a lame duck?
579                         if ((t->animtimer) && IS_AUTOKEY_ON(t->scene))
580                                 WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, NULL);
581
582                 }
583         }
584         else if (t->spacetype == SPACE_ACTION) {
585                 //SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first;
586                 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
587         }
588         else if (t->spacetype == SPACE_IPO) {
589                 //SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
590                 WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
591         }
592         else if (t->spacetype == SPACE_NLA) {
593                 WM_event_add_notifier(C, NC_ANIMATION | ND_NLA | NA_EDITED, NULL);
594         }
595         else if (t->spacetype == SPACE_NODE) {
596                 //ED_area_tag_redraw(t->sa);
597                 WM_event_add_notifier(C, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
598         }
599         else if (t->spacetype == SPACE_SEQ) {
600                 WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, NULL);
601         }
602         else if (t->spacetype == SPACE_IMAGE) {
603                 if (t->options & CTX_MASK) {
604                         Mask *mask = CTX_data_edit_mask(C);
605
606                         WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
607                 }
608                 else if (t->options & CTX_PAINT_CURVE) {
609                         wmWindow *window = CTX_wm_window(C);
610                         WM_paint_cursor_tag_redraw(window, t->ar);
611                 }
612                 else {
613                         // XXX how to deal with lock?
614                         SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first;
615                         if (sima->lock) WM_event_add_notifier(C, NC_GEOM | ND_DATA, t->obedit->data);
616                         else ED_area_tag_redraw(t->sa);
617                 }
618         }
619         else if (t->spacetype == SPACE_CLIP) {
620                 SpaceClip *sc = (SpaceClip *)t->sa->spacedata.first;
621
622                 if (ED_space_clip_check_show_trackedit(sc)) {
623                         MovieClip *clip = ED_space_clip_get_clip(sc);
624
625                         /* objects could be parented to tracking data, so send this for viewport refresh */
626                         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
627
628                         WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
629                 }
630                 else if (ED_space_clip_check_show_maskedit(sc)) {
631                         Mask *mask = CTX_data_edit_mask(C);
632
633                         WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
634                 }
635         }
636 }
637
638 static void viewRedrawPost(bContext *C, TransInfo *t)
639 {
640         ED_area_headerprint(t->sa, NULL);
641         
642         if (t->spacetype == SPACE_VIEW3D) {
643                 /* if autokeying is enabled, send notifiers that keyframes were added */
644                 if (IS_AUTOKEY_ON(t->scene))
645                         WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
646
647                 /* redraw UV editor */
648                 if (ELEM(t->mode, TFM_VERT_SLIDE, TFM_EDGE_SLIDE) &&
649                     (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT))
650                 {
651                         WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
652                 }
653                 
654                 /* XXX temp, first hack to get auto-render in compositor work (ton) */
655                 WM_event_add_notifier(C, NC_SCENE | ND_TRANSFORM_DONE, CTX_data_scene(C));
656
657         }
658         
659 #if 0 // TRANSFORM_FIX_ME
660         if (t->spacetype == SPACE_VIEW3D) {
661                 allqueue(REDRAWBUTSOBJECT, 0);
662                 allqueue(REDRAWVIEW3D, 0);
663         }
664         else if (t->spacetype == SPACE_IMAGE) {
665                 allqueue(REDRAWIMAGE, 0);
666                 allqueue(REDRAWVIEW3D, 0);
667         }
668         else if (ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_IPO)) {
669                 allqueue(REDRAWVIEW3D, 0);
670                 allqueue(REDRAWACTION, 0);
671                 allqueue(REDRAWNLA, 0);
672                 allqueue(REDRAWIPO, 0);
673                 allqueue(REDRAWTIME, 0);
674                 allqueue(REDRAWBUTSOBJECT, 0);
675         }
676
677         scrarea_queue_headredraw(curarea);
678 #endif
679 }
680
681 /* ************************** TRANSFORMATIONS **************************** */
682
683 static void view_editmove(unsigned short UNUSED(event))
684 {
685 #if 0 // TRANSFORM_FIX_ME
686         int refresh = 0;
687         /* Regular:   Zoom in */
688         /* Shift:     Scroll up */
689         /* Ctrl:      Scroll right */
690         /* Alt-Shift: Rotate up */
691         /* Alt-Ctrl:  Rotate right */
692
693         /* only work in 3D window for now
694          * In the end, will have to send to event to a 2D window handler instead
695          */
696         if (Trans.flag & T_2D_EDIT)
697                 return;
698
699         switch (event) {
700                 case WHEELUPMOUSE:
701                         if (G.qual & LR_SHIFTKEY) {
702                                 if (G.qual & LR_ALTKEY) {
703                                         G.qual &= ~LR_SHIFTKEY;
704                                         persptoetsen(PAD2);
705                                         G.qual |= LR_SHIFTKEY;
706                                 }
707                                 else {
708                                         persptoetsen(PAD2);
709                                 }
710                         }
711                         else if (G.qual & LR_CTRLKEY) {
712                                 if (G.qual & LR_ALTKEY) {
713                                         G.qual &= ~LR_CTRLKEY;
714                                         persptoetsen(PAD4);
715                                         G.qual |= LR_CTRLKEY;
716                                 }
717                                 else {
718                                         persptoetsen(PAD4);
719                                 }
720                         }
721                         else if (U.uiflag & USER_WHEELZOOMDIR)
722                                 persptoetsen(PADMINUS);
723                         else
724                                 persptoetsen(PADPLUSKEY);
725
726                         refresh = 1;
727                         break;
728                 case WHEELDOWNMOUSE:
729                         if (G.qual & LR_SHIFTKEY) {
730                                 if (G.qual & LR_ALTKEY) {
731                                         G.qual &= ~LR_SHIFTKEY;
732                                         persptoetsen(PAD8);
733                                         G.qual |= LR_SHIFTKEY;
734                                 }
735                                 else {
736                                         persptoetsen(PAD8);
737                                 }
738                         }
739                         else if (G.qual & LR_CTRLKEY) {
740                                 if (G.qual & LR_ALTKEY) {
741                                         G.qual &= ~LR_CTRLKEY;
742                                         persptoetsen(PAD6);
743                                         G.qual |= LR_CTRLKEY;
744                                 }
745                                 else {
746                                         persptoetsen(PAD6);
747                                 }
748                         }
749                         else if (U.uiflag & USER_WHEELZOOMDIR)
750                                 persptoetsen(PADPLUSKEY);
751                         else
752                                 persptoetsen(PADMINUS);
753
754                         refresh = 1;
755                         break;
756         }
757
758         if (refresh)
759                 setTransformViewMatrices(&Trans);
760 #endif
761 }
762
763 /* ************************************************* */
764
765 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
766 enum {
767         TFM_MODAL_CANCEL         = 1,
768         TFM_MODAL_CONFIRM        = 2,
769         TFM_MODAL_TRANSLATE      = 3,
770         TFM_MODAL_ROTATE         = 4,
771         TFM_MODAL_RESIZE         = 5,
772         TFM_MODAL_SNAP_INV_ON    = 6,
773         TFM_MODAL_SNAP_INV_OFF   = 7,
774         TFM_MODAL_SNAP_TOGGLE    = 8,
775         TFM_MODAL_AXIS_X         = 9,
776         TFM_MODAL_AXIS_Y         = 10,
777         TFM_MODAL_AXIS_Z         = 11,
778         TFM_MODAL_PLANE_X        = 12,
779         TFM_MODAL_PLANE_Y        = 13,
780         TFM_MODAL_PLANE_Z        = 14,
781         TFM_MODAL_CONS_OFF       = 15,
782         TFM_MODAL_ADD_SNAP       = 16,
783         TFM_MODAL_REMOVE_SNAP    = 17,
784
785 /*      18 and 19 used by numinput, defined in transform.h */
786
787         TFM_MODAL_PROPSIZE_UP    = 20,
788         TFM_MODAL_PROPSIZE_DOWN  = 21,
789         TFM_MODAL_AUTOIK_LEN_INC = 22,
790         TFM_MODAL_AUTOIK_LEN_DEC = 23,
791
792         TFM_MODAL_EDGESLIDE_UP   = 24,
793         TFM_MODAL_EDGESLIDE_DOWN = 25,
794
795 /* for analog input, like trackpad */
796         TFM_MODAL_PROPSIZE       = 26,
797 /* node editor insert offset (aka auto-offset) direction toggle */
798         TFM_MODAL_INSERTOFS_TOGGLE_DIR         = 27,
799 };
800
801 /* called in transform_ops.c, on each regeneration of keymaps */
802 wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
803 {
804         static EnumPropertyItem modal_items[] = {
805                 {TFM_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
806                 {TFM_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
807                 {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
808                 {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
809                 {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
810                 {TFM_MODAL_SNAP_INV_ON, "SNAP_INV_ON", 0, "Invert Snap On", ""},
811                 {TFM_MODAL_SNAP_INV_OFF, "SNAP_INV_OFF", 0, "Invert Snap Off", ""},
812                 {TFM_MODAL_SNAP_TOGGLE, "SNAP_TOGGLE", 0, "Snap Toggle", ""},
813                 {TFM_MODAL_AXIS_X, "AXIS_X", 0, "Orientation X axis", ""},
814                 {TFM_MODAL_AXIS_Y, "AXIS_Y", 0, "Orientation Y axis", ""},
815                 {TFM_MODAL_AXIS_Z, "AXIS_Z", 0, "Orientation Z axis", ""},
816                 {TFM_MODAL_PLANE_X, "PLANE_X", 0, "Orientation X plane", ""},
817                 {TFM_MODAL_PLANE_Y, "PLANE_Y", 0, "Orientation Y plane", ""},
818                 {TFM_MODAL_PLANE_Z, "PLANE_Z", 0, "Orientation Z plane", ""},
819                 {TFM_MODAL_CONS_OFF, "CONS_OFF", 0, "Remove Constraints", ""},
820                 {TFM_MODAL_ADD_SNAP, "ADD_SNAP", 0, "Add Snap Point", ""},
821                 {TFM_MODAL_REMOVE_SNAP, "REMOVE_SNAP", 0, "Remove Last Snap Point", ""},
822                 {NUM_MODAL_INCREMENT_UP, "INCREMENT_UP", 0, "Numinput Increment Up", ""},
823                 {NUM_MODAL_INCREMENT_DOWN, "INCREMENT_DOWN", 0, "Numinput Increment Down", ""},
824                 {TFM_MODAL_PROPSIZE_UP, "PROPORTIONAL_SIZE_UP", 0, "Increase Proportional Influence", ""},
825                 {TFM_MODAL_PROPSIZE_DOWN, "PROPORTIONAL_SIZE_DOWN", 0, "Decrease Proportional Influence", ""},
826                 {TFM_MODAL_AUTOIK_LEN_INC, "AUTOIK_CHAIN_LEN_UP", 0, "Increase Max AutoIK Chain Length", ""},
827                 {TFM_MODAL_AUTOIK_LEN_DEC, "AUTOIK_CHAIN_LEN_DOWN", 0, "Decrease Max AutoIK Chain Length", ""},
828                 {TFM_MODAL_EDGESLIDE_UP, "EDGESLIDE_EDGE_NEXT", 0, "Select next Edge Slide Edge", ""},
829                 {TFM_MODAL_EDGESLIDE_DOWN, "EDGESLIDE_PREV_NEXT", 0, "Select previous Edge Slide Edge", ""},
830                 {TFM_MODAL_PROPSIZE, "PROPORTIONAL_SIZE", 0, "Adjust Proportional Influence", ""},
831                 {TFM_MODAL_INSERTOFS_TOGGLE_DIR, "INSERTOFS_TOGGLE_DIR", 0, "Toggle Direction for Node Auto-offset", ""},
832                 {0, NULL, 0, NULL, NULL}
833         };
834         
835         wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Transform Modal Map");
836         
837         /* this function is called for each spacetype, only needs to add map once */
838         if (keymap && keymap->modal_items) return NULL;
839         
840         keymap = WM_modalkeymap_add(keyconf, "Transform Modal Map", modal_items);
841         
842         /* items for modal map */
843         WM_modalkeymap_add_item(keymap, ESCKEY,    KM_PRESS, KM_ANY, 0, TFM_MODAL_CANCEL);
844         WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
845         WM_modalkeymap_add_item(keymap, RETKEY,    KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
846         WM_modalkeymap_add_item(keymap, PADENTER,  KM_PRESS, KM_ANY, 0, TFM_MODAL_CONFIRM);
847
848         WM_modalkeymap_add_item(keymap, GKEY, KM_PRESS, 0, 0, TFM_MODAL_TRANSLATE);
849         WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE);
850         WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE);
851         
852         WM_modalkeymap_add_item(keymap, TABKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_SNAP_TOGGLE);
853
854         WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
855         WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
856
857         WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_INV_ON);
858         WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TFM_MODAL_SNAP_INV_OFF);
859         
860         WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, TFM_MODAL_ADD_SNAP);
861         WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, KM_ALT, 0, TFM_MODAL_REMOVE_SNAP);
862
863         WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
864         WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
865         WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_PROPSIZE_UP);
866         WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_PROPSIZE_DOWN);
867         WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_UP);
868         WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, 0, 0, TFM_MODAL_PROPSIZE_DOWN);
869         WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_PROPSIZE_UP);
870         WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_PROPSIZE_DOWN);
871         WM_modalkeymap_add_item(keymap, MOUSEPAN, 0, 0, 0, TFM_MODAL_PROPSIZE);
872
873         WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_ALT, 0, TFM_MODAL_EDGESLIDE_UP);
874         WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_ALT, 0, TFM_MODAL_EDGESLIDE_DOWN);
875         
876         WM_modalkeymap_add_item(keymap, PAGEUPKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
877         WM_modalkeymap_add_item(keymap, PAGEDOWNKEY, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
878         WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_INC);
879         WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0, TFM_MODAL_AUTOIK_LEN_DEC);
880
881         /* node editor only */
882         WM_modalkeymap_add_item(keymap, TKEY, KM_PRESS, 0, 0, TFM_MODAL_INSERTOFS_TOGGLE_DIR);
883
884         return keymap;
885 }
886
887 static void transform_event_xyz_constraint(TransInfo *t, short key_type, char cmode)
888 {
889         if (!(t->flag & T_NO_CONSTRAINT)) {
890                 int constraint_axis, constraint_plane;
891                 const bool edit_2d = (t->flag & T_2D_EDIT) != 0;
892                 const char *msg1 = "", *msg2 = "", *msg3 = "";
893                 char axis;
894         
895                 /* Initialize */
896                 switch (key_type) {
897                         case XKEY:
898                                 msg1 = IFACE_("along X");
899                                 msg2 = IFACE_("along %s X");
900                                 msg3 = IFACE_("locking %s X");
901                                 axis = 'X';
902                                 constraint_axis = CON_AXIS0;
903                                 break;
904                         case YKEY:
905                                 msg1 = IFACE_("along Y");
906                                 msg2 = IFACE_("along %s Y");
907                                 msg3 = IFACE_("locking %s Y");
908                                 axis = 'Y';
909                                 constraint_axis = CON_AXIS1;
910                                 break;
911                         case ZKEY:
912                                 msg1 = IFACE_("along Z");
913                                 msg2 = IFACE_("along %s Z");
914                                 msg3 = IFACE_("locking %s Z");
915                                 axis = 'Z';
916                                 constraint_axis = CON_AXIS2;
917                                 break;
918                         default:
919                                 /* Invalid key */
920                                 return;
921                 }
922                 constraint_plane = ((CON_AXIS0 | CON_AXIS1 | CON_AXIS2) & (~constraint_axis));
923
924                 if (edit_2d && (key_type != ZKEY)) {
925                         if (cmode == axis) {
926                                 stopConstraint(t);
927                         }
928                         else {
929                                 setUserConstraint(t, V3D_MANIP_GLOBAL, constraint_axis, msg1);
930                         }
931                 }
932                 else if (!edit_2d) {
933                         if (cmode == axis) {
934                                 if (t->con.orientation != V3D_MANIP_GLOBAL) {
935                                         stopConstraint(t);
936                                 }
937                                 else {
938                                         short orientation = (t->current_orientation != V3D_MANIP_GLOBAL ?
939                                                              t->current_orientation : V3D_MANIP_LOCAL);
940                                         if (!(t->modifiers & MOD_CONSTRAINT_PLANE))
941                                                 setUserConstraint(t, orientation, constraint_axis, msg2);
942                                         else if (t->modifiers & MOD_CONSTRAINT_PLANE)
943                                                 setUserConstraint(t, orientation, constraint_plane, msg3);
944                                 }
945                         }
946                         else {
947                                 if (!(t->modifiers & MOD_CONSTRAINT_PLANE))
948                                         setUserConstraint(t, V3D_MANIP_GLOBAL, constraint_axis, msg2);
949                                 else if (t->modifiers & MOD_CONSTRAINT_PLANE)
950                                         setUserConstraint(t, V3D_MANIP_GLOBAL, constraint_plane, msg3);
951                         }
952                 }
953                 t->redraw |= TREDRAW_HARD;
954         }
955 }
956
957 int transformEvent(TransInfo *t, const wmEvent *event)
958 {
959         char cmode = constraintModeToChar(t);
960         bool handled = false;
961         const int modifiers_prev = t->modifiers;
962
963         t->redraw |= handleMouseInput(t, &t->mouse, event);
964
965         /* Handle modal numinput events first, if already activated. */
966         if (((event->val == KM_PRESS) || (event->type == EVT_MODAL_MAP)) &&
967             hasNumInput(&t->num) && handleNumInput(t->context, &(t->num), event))
968         {
969                 t->redraw |= TREDRAW_HARD;
970                 handled = true;
971         }
972         else if (event->type == MOUSEMOVE) {
973                 if (t->modifiers & MOD_CONSTRAINT_SELECT)
974                         t->con.mode |= CON_SELECT;
975
976                 copy_v2_v2_int(t->mval, event->mval);
977
978                 // t->redraw |= TREDRAW_SOFT; /* Use this for soft redraw. Might cause flicker in object mode */
979                 t->redraw |= TREDRAW_HARD;
980
981                 if (t->state == TRANS_STARTING) {
982                         t->state = TRANS_RUNNING;
983                 }
984
985                 applyMouseInput(t, &t->mouse, t->mval, t->values);
986
987                 // Snapping mouse move events
988                 t->redraw |= handleSnapping(t, event);
989                 handled = true;
990         }
991         /* handle modal keymap first */
992         else if (event->type == EVT_MODAL_MAP) {
993                 switch (event->val) {
994                         case TFM_MODAL_CANCEL:
995                                 t->state = TRANS_CANCEL;
996                                 handled = true;
997                                 break;
998                         case TFM_MODAL_CONFIRM:
999                                 t->state = TRANS_CONFIRM;
1000                                 handled = true;
1001                                 break;
1002                         case TFM_MODAL_TRANSLATE:
1003                                 /* only switch when... */
1004                                 if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
1005                                         restoreTransObjects(t);
1006                                         resetTransModal(t);
1007                                         resetTransRestrictions(t);
1008                                         initTranslation(t);
1009                                         initSnapping(t, NULL); // need to reinit after mode change
1010                                         t->redraw |= TREDRAW_HARD;
1011                                         WM_event_add_mousemove(t->context);
1012                                         handled = true;
1013                                 }
1014                                 else if (t->mode == TFM_SEQ_SLIDE) {
1015                                         t->flag ^= T_ALT_TRANSFORM;
1016                                         t->redraw |= TREDRAW_HARD;
1017                                         handled = true;
1018                                 }
1019                                 else {
1020                                         if (t->obedit && t->obedit->type == OB_MESH) {
1021                                                 if ((t->mode == TFM_TRANSLATION) && (t->spacetype == SPACE_VIEW3D)) {
1022                                                         restoreTransObjects(t);
1023                                                         resetTransModal(t);
1024                                                         resetTransRestrictions(t);
1025
1026                                                         /* first try edge slide */
1027                                                         initEdgeSlide(t);
1028                                                         /* if that fails, do vertex slide */
1029                                                         if (t->state == TRANS_CANCEL) {
1030                                                                 t->state = TRANS_STARTING;
1031                                                                 initVertSlide(t);
1032                                                         }
1033                                                         /* vert slide can fail on unconnected vertices (rare but possible) */
1034                                                         if (t->state == TRANS_CANCEL) {
1035                                                                 t->mode = TFM_TRANSLATION;
1036                                                                 t->state = TRANS_STARTING;
1037                                                                 restoreTransObjects(t);
1038                                                                 resetTransRestrictions(t);
1039                                                                 initTranslation(t);
1040                                                         }
1041                                                         initSnapping(t, NULL); // need to reinit after mode change
1042                                                         t->redraw |= TREDRAW_HARD;
1043                                                         handled = true;
1044                                                         WM_event_add_mousemove(t->context);
1045                                                 }
1046                                         }
1047                                         else if (t->options & (CTX_MOVIECLIP | CTX_MASK)) {
1048                                                 if (t->mode == TFM_TRANSLATION) {
1049                                                         restoreTransObjects(t);
1050
1051                                                         t->flag ^= T_ALT_TRANSFORM;
1052                                                         t->redraw |= TREDRAW_HARD;
1053                                                         handled = true;
1054                                                 }
1055                                         }
1056                                 }
1057                                 break;
1058                         case TFM_MODAL_ROTATE:
1059                                 /* only switch when... */
1060                                 if (!(t->options & CTX_TEXTURE) && !(t->options & (CTX_MOVIECLIP | CTX_MASK))) {
1061                                         if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
1062                                                 restoreTransObjects(t);
1063                                                 resetTransModal(t);
1064                                                 resetTransRestrictions(t);
1065                                                 
1066                                                 if (t->mode == TFM_ROTATION) {
1067                                                         initTrackball(t);
1068                                                 }
1069                                                 else {
1070                                                         initRotation(t);
1071                                                 }
1072                                                 initSnapping(t, NULL); // need to reinit after mode change
1073                                                 t->redraw |= TREDRAW_HARD;
1074                                                 handled = true;
1075                                         }
1076                                 }
1077                                 break;
1078                         case TFM_MODAL_RESIZE:
1079                                 /* only switch when... */
1080                                 if (ELEM(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL, TFM_EDGE_SLIDE, TFM_VERT_SLIDE)) {
1081
1082                                         /* Scale isn't normally very useful after extrude along normals, see T39756 */
1083                                         if ((t->con.mode & CON_APPLY) && (t->con.orientation == V3D_MANIP_NORMAL)) {
1084                                                 stopConstraint(t);
1085                                         }
1086
1087                                         restoreTransObjects(t);
1088                                         resetTransModal(t);
1089                                         resetTransRestrictions(t);
1090                                         initResize(t);
1091                                         initSnapping(t, NULL); // need to reinit after mode change
1092                                         t->redraw |= TREDRAW_HARD;
1093                                         handled = true;
1094                                 }
1095                                 else if (t->mode == TFM_SHRINKFATTEN) {
1096                                         t->flag ^= T_ALT_TRANSFORM;
1097                                         t->redraw |= TREDRAW_HARD;
1098                                         handled = true;
1099                                 }
1100                                 else if (t->mode == TFM_RESIZE) {
1101                                         if (t->options & CTX_MOVIECLIP) {
1102                                                 restoreTransObjects(t);
1103
1104                                                 t->flag ^= T_ALT_TRANSFORM;
1105                                                 t->redraw |= TREDRAW_HARD;
1106                                                 handled = true;
1107                                         }
1108                                 }
1109                                 break;
1110                                 
1111                         case TFM_MODAL_SNAP_INV_ON:
1112                                 t->modifiers |= MOD_SNAP_INVERT;
1113                                 t->redraw |= TREDRAW_HARD;
1114                                 handled = true;
1115                                 break;
1116                         case TFM_MODAL_SNAP_INV_OFF:
1117                                 t->modifiers &= ~MOD_SNAP_INVERT;
1118                                 t->redraw |= TREDRAW_HARD;
1119                                 handled = true;
1120                                 break;
1121                         case TFM_MODAL_SNAP_TOGGLE:
1122                                 t->modifiers ^= MOD_SNAP;
1123                                 t->redraw |= TREDRAW_HARD;
1124                                 handled = true;
1125                                 break;
1126                         case TFM_MODAL_AXIS_X:
1127                                 if (!(t->flag & T_NO_CONSTRAINT)) {
1128                                         transform_event_xyz_constraint(t, XKEY, cmode);
1129                                         t->redraw |= TREDRAW_HARD;
1130                                         handled = true;
1131                                 }
1132                                 break;
1133                         case TFM_MODAL_AXIS_Y:
1134                                 if ((t->flag & T_NO_CONSTRAINT) == 0) {
1135                                         transform_event_xyz_constraint(t, YKEY, cmode);
1136                                         t->redraw |= TREDRAW_HARD;
1137                                         handled = true;
1138                                 }
1139                                 break;
1140                         case TFM_MODAL_AXIS_Z:
1141                                 if ((t->flag & (T_NO_CONSTRAINT)) == 0) {
1142                                         transform_event_xyz_constraint(t, ZKEY, cmode);
1143                                         t->redraw |= TREDRAW_HARD;
1144                                         handled = true;
1145                                 }
1146                                 break;
1147                         case TFM_MODAL_PLANE_X:
1148                                 if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) {
1149                                         if (cmode == 'X') {
1150                                                 stopConstraint(t);
1151                                         }
1152                                         else {
1153                                                 setUserConstraint(t, t->current_orientation, (CON_AXIS1 | CON_AXIS2), IFACE_("locking %s X"));
1154                                         }
1155                                         t->redraw |= TREDRAW_HARD;
1156                                         handled = true;
1157                                 }
1158                                 break;
1159                         case TFM_MODAL_PLANE_Y:
1160                                 if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) {
1161                                         if (cmode == 'Y') {
1162                                                 stopConstraint(t);
1163                                         }
1164                                         else {
1165                                                 setUserConstraint(t, t->current_orientation, (CON_AXIS0 | CON_AXIS2), IFACE_("locking %s Y"));
1166                                         }
1167                                         t->redraw |= TREDRAW_HARD;
1168                                         handled = true;
1169                                 }
1170                                 break;
1171                         case TFM_MODAL_PLANE_Z:
1172                                 if ((t->flag & (T_NO_CONSTRAINT | T_2D_EDIT)) == 0) {
1173                                         if (cmode == 'Z') {
1174                                                 stopConstraint(t);
1175                                         }
1176                                         else {
1177                                                 setUserConstraint(t, t->current_orientation, (CON_AXIS0 | CON_AXIS1), IFACE_("locking %s Z"));
1178                                         }
1179                                         t->redraw |= TREDRAW_HARD;
1180                                         handled = true;
1181                                 }
1182                                 break;
1183                         case TFM_MODAL_CONS_OFF:
1184                                 if ((t->flag & T_NO_CONSTRAINT) == 0) {
1185                                         stopConstraint(t);
1186                                         t->redraw |= TREDRAW_HARD;
1187                                         handled = true;
1188                                 }
1189                                 break;
1190                         case TFM_MODAL_ADD_SNAP:
1191                                 addSnapPoint(t);
1192                                 t->redraw |= TREDRAW_HARD;
1193                                 handled = true;
1194                                 break;
1195                         case TFM_MODAL_REMOVE_SNAP:
1196                                 removeSnapPoint(t);
1197                                 t->redraw |= TREDRAW_HARD;
1198                                 handled = true;
1199                                 break;
1200                         case TFM_MODAL_PROPSIZE:
1201                                 /* MOUSEPAN usage... */
1202                                 if (t->flag & T_PROP_EDIT) {
1203                                         float fac = 1.0f + 0.005f *(event->y - event->prevy);
1204                                         t->prop_size *= fac;
1205                                         if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO) {
1206                                                 t->prop_size = max_ff(min_ff(t->prop_size, ((View3D *)t->view)->far), T_PROP_SIZE_MIN);
1207                                         }
1208                                         else {
1209                                                 t->prop_size = max_ff(min_ff(t->prop_size, T_PROP_SIZE_MAX), T_PROP_SIZE_MIN);
1210                                         }
1211                                         calculatePropRatio(t);
1212                                         t->redraw |= TREDRAW_HARD;
1213                                         handled = true;
1214                                 }
1215                                 break;
1216                         case TFM_MODAL_PROPSIZE_UP:
1217                                 if (t->flag & T_PROP_EDIT) {
1218                                         t->prop_size *= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f;
1219                                         if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO) {
1220                                                 t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
1221                                         }
1222                                         else {
1223                                                 t->prop_size = min_ff(t->prop_size, T_PROP_SIZE_MAX);
1224                                         }
1225                                         calculatePropRatio(t);
1226                                         t->redraw |= TREDRAW_HARD;
1227                                         handled = true;
1228                                 }
1229                                 break;
1230                         case TFM_MODAL_PROPSIZE_DOWN:
1231                                 if (t->flag & T_PROP_EDIT) {
1232                                         t->prop_size /= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f;
1233                                         t->prop_size = max_ff(t->prop_size, T_PROP_SIZE_MIN);
1234                                         calculatePropRatio(t);
1235                                         t->redraw |= TREDRAW_HARD;
1236                                         handled = true;
1237                                 }
1238                                 break;
1239                         case TFM_MODAL_AUTOIK_LEN_INC:
1240                                 if (t->flag & T_AUTOIK) {
1241                                         transform_autoik_update(t, 1);
1242                                         t->redraw |= TREDRAW_HARD;
1243                                         handled = true;
1244                                 }
1245                                 break;
1246                         case TFM_MODAL_AUTOIK_LEN_DEC:
1247                                 if (t->flag & T_AUTOIK) {
1248                                         transform_autoik_update(t, -1);
1249                                         t->redraw |= TREDRAW_HARD;
1250                                         handled = true;
1251                                 }
1252                                 break;
1253                         case TFM_MODAL_INSERTOFS_TOGGLE_DIR:
1254                                 if (t->spacetype == SPACE_NODE) {
1255                                         SpaceNode *snode = (SpaceNode *)t->sa->spacedata.first;
1256
1257                                         BLI_assert(t->sa->spacetype == t->spacetype);
1258
1259                                         if (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_RIGHT) {
1260                                                 snode->insert_ofs_dir = SNODE_INSERTOFS_DIR_LEFT;
1261                                         }
1262                                         else if (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_LEFT) {
1263                                                 snode->insert_ofs_dir = SNODE_INSERTOFS_DIR_RIGHT;
1264                                         }
1265                                         else {
1266                                                 BLI_assert(0);
1267                                         }
1268
1269                                         t->redraw |= TREDRAW_SOFT;
1270                                 }
1271                                 break;
1272                         /* Those two are only handled in transform's own handler, see T44634! */
1273                         case TFM_MODAL_EDGESLIDE_UP:
1274                         case TFM_MODAL_EDGESLIDE_DOWN:
1275                         default:
1276                                 break;
1277                 }
1278         }
1279         /* else do non-mapped events */
1280         else if (event->val == KM_PRESS) {
1281                 switch (event->type) {
1282                         case RIGHTMOUSE:
1283                                 t->state = TRANS_CANCEL;
1284                                 handled = true;
1285                                 break;
1286                         /* enforce redraw of transform when modifiers are used */
1287                         case LEFTSHIFTKEY:
1288                         case RIGHTSHIFTKEY:
1289                                 t->modifiers |= MOD_CONSTRAINT_PLANE;
1290                                 t->redraw |= TREDRAW_HARD;
1291                                 handled = true;
1292                                 break;
1293
1294                         case SPACEKEY:
1295                                 t->state = TRANS_CONFIRM;
1296                                 handled = true;
1297                                 break;
1298
1299                         case MIDDLEMOUSE:
1300                                 if ((t->flag & T_NO_CONSTRAINT) == 0) {
1301                                         /* exception for switching to dolly, or trackball, in camera view */
1302                                         if (t->flag & T_CAMERA) {
1303                                                 if (t->mode == TFM_TRANSLATION)
1304                                                         setLocalConstraint(t, (CON_AXIS2), IFACE_("along local Z"));
1305                                                 else if (t->mode == TFM_ROTATION) {
1306                                                         restoreTransObjects(t);
1307                                                         initTrackball(t);
1308                                                 }
1309                                         }
1310                                         else {
1311                                                 t->modifiers |= MOD_CONSTRAINT_SELECT;
1312                                                 if (t->con.mode & CON_APPLY) {
1313                                                         stopConstraint(t);
1314                                                 }
1315                                                 else {
1316                                                         if (event->shift) {
1317                                                                 initSelectConstraint(t, t->spacemtx);
1318                                                         }
1319                                                         else {
1320                                                                 /* bit hackish... but it prevents mmb select to print the orientation from menu */
1321                                                                 float mati[3][3];
1322                                                                 strcpy(t->spacename, "global");
1323                                                                 unit_m3(mati);
1324                                                                 initSelectConstraint(t, mati);
1325                                                         }
1326                                                         postSelectConstraint(t);
1327                                                 }
1328                                         }
1329                                         t->redraw |= TREDRAW_HARD;
1330                                         handled = true;
1331                                 }
1332                                 break;
1333                         case ESCKEY:
1334                                 t->state = TRANS_CANCEL;
1335                                 handled = true;
1336                                 break;
1337                         case PADENTER:
1338                         case RETKEY:
1339                                 t->state = TRANS_CONFIRM;
1340                                 handled = true;
1341                                 break;
1342                         case GKEY:
1343                                 /* only switch when... */
1344                                 if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL)) {
1345                                         restoreTransObjects(t);
1346                                         resetTransModal(t);
1347                                         resetTransRestrictions(t);
1348                                         initTranslation(t);
1349                                         initSnapping(t, NULL); // need to reinit after mode change
1350                                         t->redraw |= TREDRAW_HARD;
1351                                         handled = true;
1352                                 }
1353                                 break;
1354                         case SKEY:
1355                                 /* only switch when... */
1356                                 if (ELEM(t->mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL)) {
1357                                         restoreTransObjects(t);
1358                                         resetTransModal(t);
1359                                         resetTransRestrictions(t);
1360                                         initResize(t);
1361                                         initSnapping(t, NULL); // need to reinit after mode change
1362                                         t->redraw |= TREDRAW_HARD;
1363                                         handled = true;
1364                                 }
1365                                 break;
1366                         case RKEY:
1367                                 /* only switch when... */
1368                                 if (!(t->options & CTX_TEXTURE)) {
1369                                         if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL, TFM_TRANSLATION)) {
1370                                                 restoreTransObjects(t);
1371                                                 resetTransModal(t);
1372                                                 resetTransRestrictions(t);
1373
1374                                                 if (t->mode == TFM_ROTATION) {
1375                                                         initTrackball(t);
1376                                                 }
1377                                                 else {
1378                                                         initRotation(t);
1379                                                 }
1380                                                 initSnapping(t, NULL); // need to reinit after mode change
1381                                                 t->redraw |= TREDRAW_HARD;
1382                                                 handled = true;
1383                                         }
1384                                 }
1385                                 break;
1386                         case CKEY:
1387                                 if (event->alt) {
1388                                         if (!(t->options & CTX_NO_PET)) {
1389                                                 t->flag ^= T_PROP_CONNECTED;
1390                                                 sort_trans_data_dist(t);
1391                                                 calculatePropRatio(t);
1392                                                 t->redraw = TREDRAW_HARD;
1393                                                 handled = true;
1394                                         }
1395                                 }
1396                                 else {
1397                                         if (!(t->flag & T_NO_CONSTRAINT)) {
1398                                                 stopConstraint(t);
1399                                                 t->redraw |= TREDRAW_HARD;
1400                                                 handled = true;
1401                                         }
1402                                 }
1403                                 break;
1404                         case XKEY:
1405                         case YKEY:
1406                         case ZKEY:
1407                                 if (!(t->flag & T_NO_CONSTRAINT)) {
1408                                         transform_event_xyz_constraint(t, event->type, cmode);
1409                                         handled = true;
1410                                 }
1411                                 break;
1412                         case OKEY:
1413                                 if (t->flag & T_PROP_EDIT && event->shift) {
1414                                         t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX;
1415                                         calculatePropRatio(t);
1416                                         t->redraw |= TREDRAW_HARD;
1417                                         handled = true;
1418                                 }
1419                                 break;
1420                         case PADPLUSKEY:
1421                                 if (event->alt && t->flag & T_PROP_EDIT) {
1422                                         t->prop_size *= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f;
1423                                         if (t->spacetype == SPACE_VIEW3D && t->persp != RV3D_ORTHO)
1424                                                 t->prop_size = min_ff(t->prop_size, ((View3D *)t->view)->far);
1425                                         calculatePropRatio(t);
1426                                         t->redraw = TREDRAW_HARD;
1427                                         handled = true;
1428                                 }
1429                                 break;
1430                         case PAGEUPKEY:
1431                         case WHEELDOWNMOUSE:
1432                                 if (t->flag & T_AUTOIK) {
1433                                         transform_autoik_update(t, 1);
1434                                 }
1435                                 else {
1436                                         view_editmove(event->type);
1437                                 }
1438                                 t->redraw = TREDRAW_HARD;
1439                                 handled = true;
1440                                 break;
1441                         case PADMINUS:
1442                                 if (event->alt && t->flag & T_PROP_EDIT) {
1443                                         t->prop_size /= (t->modifiers & MOD_PRECISION) ? 1.01f : 1.1f;
1444                                         calculatePropRatio(t);
1445                                         t->redraw = TREDRAW_HARD;
1446                                         handled = true;
1447                                 }
1448                                 break;
1449                         case PAGEDOWNKEY:
1450                         case WHEELUPMOUSE:
1451                                 if (t->flag & T_AUTOIK) {
1452                                         transform_autoik_update(t, -1);
1453                                 }
1454                                 else {
1455                                         view_editmove(event->type);
1456                                 }
1457                                 t->redraw = TREDRAW_HARD;
1458                                 handled = true;
1459                                 break;
1460                         case LEFTALTKEY:
1461                         case RIGHTALTKEY:
1462                                 if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
1463                                         t->flag |= T_ALT_TRANSFORM;
1464                                         t->redraw |= TREDRAW_HARD;
1465                                         handled = true;
1466                                 }
1467                                 break;
1468                         default:
1469                                 break;
1470                 }
1471
1472                 /* Snapping key events */
1473                 t->redraw |= handleSnapping(t, event);
1474         }
1475         else if (event->val == KM_RELEASE) {
1476                 switch (event->type) {
1477                         case LEFTSHIFTKEY:
1478                         case RIGHTSHIFTKEY:
1479                                 t->modifiers &= ~MOD_CONSTRAINT_PLANE;
1480                                 t->redraw |= TREDRAW_HARD;
1481                                 handled = true;
1482                                 break;
1483
1484                         case MIDDLEMOUSE:
1485                                 if ((t->flag & T_NO_CONSTRAINT) == 0) {
1486                                         t->modifiers &= ~MOD_CONSTRAINT_SELECT;
1487                                         postSelectConstraint(t);
1488                                         t->redraw |= TREDRAW_HARD;
1489                                         handled = true;
1490                                 }
1491                                 break;
1492                         case LEFTALTKEY:
1493                         case RIGHTALTKEY:
1494                                 if (ELEM(t->spacetype, SPACE_SEQ, SPACE_VIEW3D)) {
1495                                         t->flag &= ~T_ALT_TRANSFORM;
1496                                         t->redraw |= TREDRAW_HARD;
1497                                         handled = true;
1498                                 }
1499                                 break;
1500                         default:
1501                                 break;
1502                 }
1503
1504                 /* confirm transform if launch key is released after mouse move */
1505                 if (t->flag & T_RELEASE_CONFIRM) {
1506                         /* XXX Keyrepeat bug in Xorg messes this up, will test when fixed */
1507                         if (event->type == t->launch_event && (t->launch_event == LEFTMOUSE || t->launch_event == RIGHTMOUSE)) {
1508                                 t->state = TRANS_CONFIRM;
1509                         }
1510                 }
1511         }
1512
1513         /* if we change snap options, get the unsnapped values back */
1514         if ((t->modifiers   & (MOD_SNAP | MOD_SNAP_INVERT)) !=
1515             (modifiers_prev & (MOD_SNAP | MOD_SNAP_INVERT)))
1516         {
1517                 applyMouseInput(t, &t->mouse, t->mval, t->values);
1518         }
1519
1520         /* Per transform event, if present */
1521         if (t->handleEvent &&
1522             (!handled ||
1523              /* Needed for vertex slide, see [#38756] */
1524              (event->type == MOUSEMOVE)))
1525         {
1526                 t->redraw |= t->handleEvent(t, event);
1527         }
1528
1529         /* Try to init modal numinput now, if possible. */
1530         if (!(handled || t->redraw) && ((event->val == KM_PRESS) || (event->type == EVT_MODAL_MAP)) &&
1531             handleNumInput(t->context, &(t->num), event))
1532         {
1533                 t->redraw |= TREDRAW_HARD;
1534                 handled = true;
1535         }
1536
1537         if (handled || t->redraw) {
1538                 return 0;
1539         }
1540         else {
1541                 return OPERATOR_PASS_THROUGH;
1542         }
1543 }
1544
1545 bool calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], float cent2d[2])
1546 {
1547         TransInfo *t = MEM_callocN(sizeof(TransInfo), "TransInfo data");
1548         bool success;
1549
1550         t->state = TRANS_RUNNING;
1551
1552         /* avoid calculating PET */
1553         t->options = CTX_NO_PET;
1554
1555         t->mode = TFM_DUMMY;
1556
1557         initTransInfo(C, t, NULL, NULL);
1558
1559         /* avoid doing connectivity lookups (when V3D_AROUND_LOCAL_ORIGINS is set) */
1560         t->around = V3D_AROUND_CENTER_BOUNDS;
1561
1562         createTransData(C, t);              // make TransData structs from selection
1563
1564         t->around = centerMode;             // override userdefined mode
1565
1566         if (t->total == 0) {
1567                 success = false;
1568         }
1569         else {
1570                 success = true;
1571
1572                 calculateCenter(t);
1573
1574                 if (cent2d) {
1575                         copy_v2_v2(cent2d, t->center2d);
1576                 }
1577
1578                 if (cent3d) {
1579                         // Copy center from constraint center. Transform center can be local
1580                         copy_v3_v3(cent3d, t->center_global);
1581                 }
1582         }
1583
1584
1585         /* aftertrans does insert keyframes, and clears base flags; doesn't read transdata */
1586         special_aftertrans_update(C, t);
1587
1588         postTrans(C, t);
1589
1590         MEM_freeN(t);
1591
1592         return success;
1593 }
1594
1595 typedef enum {
1596         UP,
1597         DOWN,
1598         LEFT,
1599         RIGHT
1600 } ArrowDirection;
1601 static void drawArrow(ArrowDirection d, short offset, short length, short size)
1602 {
1603         switch (d) {
1604                 case LEFT:
1605                         offset = -offset;
1606                         length = -length;
1607                         size = -size;
1608                         ATTR_FALLTHROUGH;
1609                 case RIGHT:
1610                         glBegin(GL_LINES);
1611                         glVertex2s(offset, 0);
1612                         glVertex2s(offset + length, 0);
1613                         glVertex2s(offset + length, 0);
1614                         glVertex2s(offset + length - size, -size);
1615                         glVertex2s(offset + length, 0);
1616                         glVertex2s(offset + length - size,  size);
1617                         glEnd();
1618                         break;
1619
1620                 case DOWN:
1621                         offset = -offset;
1622                         length = -length;
1623                         size = -size;
1624                         ATTR_FALLTHROUGH;
1625                 case UP:
1626                         glBegin(GL_LINES);
1627                         glVertex2s(0, offset);
1628                         glVertex2s(0, offset + length);
1629                         glVertex2s(0, offset + length);
1630                         glVertex2s(-size, offset + length - size);
1631                         glVertex2s(0, offset + length);
1632                         glVertex2s(size, offset + length - size);
1633                         glEnd();
1634                         break;
1635         }
1636 }
1637
1638 static void drawArrowHead(ArrowDirection d, short size)
1639 {
1640         switch (d) {
1641                 case LEFT:
1642                         size = -size;
1643                         ATTR_FALLTHROUGH;
1644                 case RIGHT:
1645                         glBegin(GL_LINES);
1646                         glVertex2s(0, 0);
1647                         glVertex2s(-size, -size);
1648                         glVertex2s(0, 0);
1649                         glVertex2s(-size,  size);
1650                         glEnd();
1651                         break;
1652
1653                 case DOWN:
1654                         size = -size;
1655                         ATTR_FALLTHROUGH;
1656                 case UP:
1657                         glBegin(GL_LINES);
1658                         glVertex2s(0, 0);
1659                         glVertex2s(-size, -size);
1660                         glVertex2s(0, 0);
1661                         glVertex2s(size, -size);
1662                         glEnd();
1663                         break;
1664         }
1665 }
1666
1667 static void drawArc(float size, float angle_start, float angle_end, int segments)
1668 {
1669         float delta = (angle_end - angle_start) / segments;
1670         float angle;
1671         int a;
1672
1673         glBegin(GL_LINE_STRIP);
1674
1675         for (angle = angle_start, a = 0; a < segments; angle += delta, a++) {
1676                 glVertex2f(cosf(angle) * size, sinf(angle) * size);
1677         }
1678         glVertex2f(cosf(angle_end) * size, sinf(angle_end) * size);
1679
1680         glEnd();
1681 }
1682
1683 static int helpline_poll(bContext *C)
1684 {
1685         ARegion *ar = CTX_wm_region(C);
1686         
1687         if (ar && ar->regiontype == RGN_TYPE_WINDOW)
1688                 return 1;
1689         return 0;
1690 }
1691
1692 static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
1693 {
1694         TransInfo *t = (TransInfo *)customdata;
1695
1696         if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR)) {
1697                 float vecrot[3], cent[2];
1698                 int mval[2];
1699
1700                 mval[0] = x;
1701                 mval[1] = y;
1702
1703                 copy_v3_v3(vecrot, t->center);
1704                 if (t->flag & T_EDIT) {
1705                         Object *ob = t->obedit;
1706                         if (ob) mul_m4_v3(ob->obmat, vecrot);
1707                 }
1708                 else if (t->flag & T_POSE) {
1709                         Object *ob = t->poseobj;
1710                         if (ob) mul_m4_v3(ob->obmat, vecrot);
1711                 }
1712
1713                 projectFloatViewEx(t, vecrot, cent, V3D_PROJ_TEST_CLIP_ZERO);
1714
1715                 glPushMatrix();
1716
1717                 switch (t->helpline) {
1718                         case HLP_SPRING:
1719                                 UI_ThemeColor(TH_VIEW_OVERLAY);
1720
1721                                 setlinestyle(3);
1722                                 glLineWidth(1);
1723                                 glBegin(GL_LINES);
1724                                 glVertex2iv(t->mval);
1725                                 glVertex2fv(cent);
1726                                 glEnd();
1727
1728                                 glTranslate2iv(mval);
1729                                 glRotatef(-RAD2DEGF(atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1])), 0, 0, 1);
1730
1731                                 setlinestyle(0);
1732                                 glLineWidth(3.0);
1733                                 drawArrow(UP, 5, 10, 5);
1734                                 drawArrow(DOWN, 5, 10, 5);
1735                                 break;
1736                         case HLP_HARROW:
1737                                 UI_ThemeColor(TH_VIEW_OVERLAY);
1738
1739                                 glTranslate2iv(mval);
1740
1741                                 glLineWidth(3.0);
1742                                 drawArrow(RIGHT, 5, 10, 5);
1743                                 drawArrow(LEFT, 5, 10, 5);
1744                                 break;
1745                         case HLP_VARROW:
1746                                 UI_ThemeColor(TH_VIEW_OVERLAY);
1747
1748                                 glTranslate2iv(mval);
1749
1750                                 glLineWidth(3.0);
1751                                 drawArrow(UP, 5, 10, 5);
1752                                 drawArrow(DOWN, 5, 10, 5);
1753                                 break;
1754                         case HLP_ANGLE:
1755                         {
1756                                 float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
1757                                 float angle = atan2f(dy, dx);
1758                                 float dist = hypotf(dx, dy);
1759                                 float delta_angle = min_ff(15.0f / dist, (float)M_PI / 4.0f);
1760                                 float spacing_angle = min_ff(5.0f / dist, (float)M_PI / 12.0f);
1761                                 UI_ThemeColor(TH_VIEW_OVERLAY);
1762
1763                                 setlinestyle(3);
1764                                 glLineWidth(1);
1765                                 glBegin(GL_LINES);
1766                                 glVertex2iv(t->mval);
1767                                 glVertex2fv(cent);
1768                                 glEnd();
1769
1770                                 glTranslatef(cent[0] - t->mval[0] + mval[0], cent[1] - t->mval[1] + mval[1], 0);
1771
1772                                 setlinestyle(0);
1773                                 glLineWidth(3.0);
1774                                 drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
1775                                 drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
1776
1777                                 glPushMatrix();
1778
1779                                 glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
1780                                 glRotatef(RAD2DEGF(angle - delta_angle), 0, 0, 1);
1781
1782                                 drawArrowHead(DOWN, 5);
1783
1784                                 glPopMatrix();
1785
1786                                 glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
1787                                 glRotatef(RAD2DEGF(angle + delta_angle), 0, 0, 1);
1788
1789                                 drawArrowHead(UP, 5);
1790                                 break;
1791                         }
1792                         case HLP_TRACKBALL:
1793                         {
1794                                 unsigned char col[3], col2[3];
1795                                 UI_GetThemeColor3ubv(TH_GRID, col);
1796
1797                                 glTranslate2iv(mval);
1798
1799                                 glLineWidth(3.0);
1800
1801                                 UI_make_axis_color(col, col2, 'X');
1802                                 glColor3ubv((GLubyte *)col2);
1803
1804                                 drawArrow(RIGHT, 5, 10, 5);
1805                                 drawArrow(LEFT, 5, 10, 5);
1806
1807                                 UI_make_axis_color(col, col2, 'Y');
1808                                 glColor3ubv((GLubyte *)col2);
1809
1810                                 drawArrow(UP, 5, 10, 5);
1811                                 drawArrow(DOWN, 5, 10, 5);
1812                                 break;
1813                         }
1814                 }
1815
1816                 glPopMatrix();
1817         }
1818 }
1819
1820 static void drawTransformView(const struct bContext *C, ARegion *UNUSED(ar), void *arg)
1821 {
1822         TransInfo *t = arg;
1823         
1824         glLineWidth(1.0);
1825
1826         drawConstraint(t);
1827         drawPropCircle(C, t);
1828         drawSnapping(C, t);
1829
1830         /* edge slide, vert slide */
1831         drawEdgeSlide(t);
1832         drawVertSlide(t);
1833 }
1834
1835 /* just draw a little warning message in the top-right corner of the viewport to warn that autokeying is enabled */
1836 static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
1837 {
1838         rcti rect;
1839         const char *printable = IFACE_("Auto Keying On");
1840         float      printable_size[2];
1841         int xco, yco;
1842
1843         ED_region_visible_rect(ar, &rect);
1844         
1845         BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
1846         
1847         xco = (rect.xmax - U.widget_unit) - (int)printable_size[0];
1848         yco = (rect.ymax - U.widget_unit);
1849         
1850         /* warning text (to clarify meaning of overlays)
1851          * - original color was red to match the icon, but that clashes badly with a less nasty border
1852          */
1853         UI_ThemeColorShade(TH_TEXT_HI, -50);
1854 #ifdef WITH_INTERNATIONAL
1855         BLF_draw_default(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
1856 #else
1857         BLF_draw_default_ascii(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
1858 #endif
1859         
1860         /* autokey recording icon... */
1861         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1862         glEnable(GL_BLEND);
1863         
1864         xco -= U.widget_unit;
1865         yco -= (int)printable_size[1] / 2;
1866
1867         UI_icon_draw(xco, yco, ICON_REC);
1868         
1869         glDisable(GL_BLEND);
1870 }
1871
1872 static void drawTransformPixel(const struct bContext *UNUSED(C), ARegion *ar, void *arg)
1873 {       
1874         TransInfo *t = arg;
1875         Scene *scene = t->scene;
1876         Object *ob = OBACT;
1877         
1878         /* draw autokeyframing hint in the corner 
1879          * - only draw if enabled (advanced users may be distracted/annoyed), 
1880          *   for objects that will be autokeyframed (no point ohterwise),
1881          *   AND only for the active region (as showing all is too overwhelming)
1882          */
1883         if ((U.autokey_flag & AUTOKEY_FLAG_NOWARNING) == 0) {
1884                 if (ar == t->ar) {
1885                         if (t->flag & (T_OBJECT | T_POSE)) {
1886                                 if (ob && autokeyframe_cfra_can_key(scene, &ob->id)) {
1887                                         drawAutoKeyWarning(t, ar);
1888                                 }
1889                         }
1890                 }
1891         }
1892 }
1893
1894 /**
1895  * \see #initTransform which reads values from the operator.
1896  */
1897 void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
1898 {
1899         ToolSettings *ts = CTX_data_tool_settings(C);
1900         int constraint_axis[3] = {0, 0, 0};
1901         int proportional = 0;
1902         PropertyRNA *prop;
1903
1904         // Save back mode in case we're in the generic operator
1905         if ((prop = RNA_struct_find_property(op->ptr, "mode"))) {
1906                 RNA_property_enum_set(op->ptr, prop, t->mode);
1907         }
1908
1909         if ((prop = RNA_struct_find_property(op->ptr, "value"))) {
1910                 float values[4];
1911
1912                 copy_v4_v4(values, (t->flag & T_AUTOVALUES) ? t->auto_values : t->values);
1913
1914                 if (RNA_property_array_check(prop)) {
1915                         RNA_property_float_set_array(op->ptr, prop, values);
1916                 }
1917                 else {
1918                         RNA_property_float_set(op->ptr, prop, values[0]);
1919                 }
1920         }
1921
1922         /* convert flag to enum */
1923         switch (t->flag & T_PROP_EDIT_ALL) {
1924                 case T_PROP_EDIT:
1925                         proportional = PROP_EDIT_ON;
1926                         break;
1927                 case (T_PROP_EDIT | T_PROP_CONNECTED):
1928                         proportional = PROP_EDIT_CONNECTED;
1929                         break;
1930                 case (T_PROP_EDIT | T_PROP_PROJECTED):
1931                         proportional = PROP_EDIT_PROJECTED;
1932                         break;
1933                 default:
1934                         proportional = PROP_EDIT_OFF;
1935                         break;
1936         }
1937
1938         // If modal, save settings back in scene if not set as operator argument
1939         if (t->flag & T_MODAL) {
1940                 /* save settings if not set in operator */
1941
1942                 /* skip saving proportional edit if it was not actually used */
1943                 if (!(t->options & CTX_NO_PET)) {
1944                         if ((prop = RNA_struct_find_property(op->ptr, "proportional")) &&
1945                             !RNA_property_is_set(op->ptr, prop))
1946                         {
1947                                 if (t->spacetype == SPACE_IPO)
1948                                         ts->proportional_fcurve = proportional;
1949                                 else if (t->spacetype == SPACE_ACTION)
1950                                         ts->proportional_action = proportional;
1951                                 else if (t->obedit)
1952                                         ts->proportional = proportional;
1953                                 else if (t->options & CTX_MASK)
1954                                         ts->proportional_mask = (proportional != PROP_EDIT_OFF);
1955                                 else
1956                                         ts->proportional_objects = (proportional != PROP_EDIT_OFF);
1957                         }
1958
1959                         if ((prop = RNA_struct_find_property(op->ptr, "proportional_size")) &&
1960                             !RNA_property_is_set(op->ptr, prop))
1961                         {
1962                                 ts->proportional_size = t->prop_size;
1963                         }
1964
1965                         if ((prop = RNA_struct_find_property(op->ptr, "proportional_edit_falloff")) &&
1966                             !RNA_property_is_set(op->ptr, prop))
1967                         {
1968                                 ts->prop_mode = t->prop_mode;
1969                         }
1970                 }
1971                 
1972                 /* do we check for parameter? */
1973                 if (t->modifiers & MOD_SNAP) {
1974                         ts->snap_flag |= SCE_SNAP;
1975                 }
1976                 else {
1977                         ts->snap_flag &= ~SCE_SNAP;
1978                 }
1979
1980                 if (t->spacetype == SPACE_VIEW3D) {
1981                         if ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
1982                             !RNA_property_is_set(op->ptr, prop))
1983                         {
1984                                 View3D *v3d = t->view;
1985
1986                                 v3d->twmode = t->current_orientation;
1987                         }
1988                 }
1989         }
1990         
1991         if ((prop = RNA_struct_find_property(op->ptr, "proportional"))) {
1992                 RNA_property_enum_set(op->ptr, prop, proportional);
1993                 RNA_enum_set(op->ptr, "proportional_edit_falloff", t->prop_mode);
1994                 RNA_float_set(op->ptr, "proportional_size", t->prop_size);
1995         }
1996
1997         if ((prop = RNA_struct_find_property(op->ptr, "axis"))) {
1998                 RNA_property_float_set_array(op->ptr, prop, t->axis);
1999         }
2000
2001         if ((prop = RNA_struct_find_property(op->ptr, "mirror"))) {
2002                 RNA_property_boolean_set(op->ptr, prop, (t->flag & T_MIRROR) != 0);
2003         }
2004
2005         if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis"))) {
2006                 /* constraint orientation can be global, event if user selects something else
2007                  * so use the orientation in the constraint if set
2008                  * */
2009                 if (t->con.mode & CON_APPLY) {
2010                         RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
2011                 }
2012                 else {
2013                         RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
2014                 }
2015
2016                 if (t->con.mode & CON_APPLY) {
2017                         if (t->con.mode & CON_AXIS0) {
2018                                 constraint_axis[0] = 1;
2019                         }
2020                         if (t->con.mode & CON_AXIS1) {
2021                                 constraint_axis[1] = 1;
2022                         }
2023                         if (t->con.mode & CON_AXIS2) {
2024                                 constraint_axis[2] = 1;
2025                         }
2026                 }
2027
2028                 RNA_property_boolean_set_array(op->ptr, prop, constraint_axis);
2029         }
2030
2031         {
2032                 const char *prop_id = NULL;
2033                 if (t->mode == TFM_SHRINKFATTEN) {
2034                         prop_id = "use_even_offset";
2035                 }
2036
2037                 if (prop_id && (prop = RNA_struct_find_property(op->ptr, prop_id))) {
2038
2039                         RNA_property_boolean_set(op->ptr, prop, (t->flag & T_ALT_TRANSFORM) != 0);
2040                 }
2041         }
2042
2043         if ((prop = RNA_struct_find_property(op->ptr, "correct_uv"))) {
2044                 RNA_property_boolean_set(op->ptr, prop, (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) != 0);
2045         }
2046 }
2047
2048 /**
2049  * \note  caller needs to free 't' on a 0 return
2050  * \warning  \a event might be NULL (when tweaking from redo panel)
2051  * \see #saveTransform which writes these values back.
2052  */
2053 bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event, int mode)
2054 {
2055         int options = 0;
2056         PropertyRNA *prop;
2057
2058         t->context = C;
2059
2060         /* added initialize, for external calls to set stuff in TransInfo, like undo string */
2061
2062         t->state = TRANS_STARTING;
2063
2064         if ((prop = RNA_struct_find_property(op->ptr, "texture_space")) && RNA_property_is_set(op->ptr, prop)) {
2065                 if (RNA_property_boolean_get(op->ptr, prop)) {
2066                         options |= CTX_TEXTURE;
2067                 }
2068         }
2069         
2070         if ((prop = RNA_struct_find_property(op->ptr, "gpencil_strokes")) && RNA_property_is_set(op->ptr, prop)) {
2071                 if (RNA_property_boolean_get(op->ptr, prop)) {
2072                         options |= CTX_GPENCIL_STROKES;
2073                 }
2074         }
2075
2076         t->options = options;
2077
2078         t->mode = mode;
2079
2080         t->launch_event = event ? event->type : -1;
2081
2082         if (t->launch_event == EVT_TWEAK_R) {
2083                 t->launch_event = RIGHTMOUSE;
2084         }
2085         else if (t->launch_event == EVT_TWEAK_L) {
2086                 t->launch_event = LEFTMOUSE;
2087         }
2088
2089         // XXX Remove this when wm_operator_call_internal doesn't use window->eventstate (which can have type = 0)
2090         // For manipulator only, so assume LEFTMOUSE
2091         if (t->launch_event == 0) {
2092                 t->launch_event = LEFTMOUSE;
2093         }
2094
2095         unit_m3(t->spacemtx);
2096
2097         initTransInfo(C, t, op, event);
2098         initTransformOrientation(C, t);
2099
2100         if (t->spacetype == SPACE_VIEW3D) {
2101                 t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);
2102                 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
2103                 t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
2104                 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
2105         }
2106         else if (t->spacetype == SPACE_IMAGE) {
2107                 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
2108                 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
2109                 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
2110         }
2111         else if (t->spacetype == SPACE_CLIP) {
2112                 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
2113                 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
2114         }
2115         else if (t->spacetype == SPACE_NODE) {
2116                 /*t->draw_handle_apply = ED_region_draw_cb_activate(t->ar->type, drawTransformApply, t, REGION_DRAW_PRE_VIEW);*/
2117                 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
2118                 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
2119         }
2120         else if (t->spacetype == SPACE_IPO) {
2121                 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
2122                 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
2123                 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
2124         }
2125         else if (t->spacetype == SPACE_ACTION) {
2126                 t->draw_handle_view = ED_region_draw_cb_activate(t->ar->type, drawTransformView, t, REGION_DRAW_POST_VIEW);
2127                 //t->draw_handle_pixel = ED_region_draw_cb_activate(t->ar->type, drawTransformPixel, t, REGION_DRAW_POST_PIXEL);
2128                 t->draw_handle_cursor = WM_paint_cursor_activate(CTX_wm_manager(C), helpline_poll, drawHelpline, t);
2129         }
2130
2131         createTransData(C, t);          // make TransData structs from selection
2132
2133         if (t->total == 0) {
2134                 postTrans(C, t);
2135                 return 0;
2136         }
2137
2138         if (event) {
2139                 /* keymap for shortcut header prints */
2140                 t->keymap = WM_keymap_active(CTX_wm_manager(C), op->type->modalkeymap);
2141
2142                 /* Stupid code to have Ctrl-Click on manipulator work ok
2143                  *
2144                  * do this only for translation/rotation/resize due to only this
2145                  * moded are available from manipulator and doing such check could
2146                  * lead to keymap conflicts for other modes (see #31584)
2147                  */
2148                 if (ELEM(mode, TFM_TRANSLATION, TFM_ROTATION, TFM_RESIZE)) {
2149                         wmKeyMapItem *kmi;
2150
2151                         for (kmi = t->keymap->items.first; kmi; kmi = kmi->next) {
2152                                 if (kmi->propvalue == TFM_MODAL_SNAP_INV_ON && kmi->val == KM_PRESS) {
2153                                         if ((ELEM(kmi->type, LEFTCTRLKEY, RIGHTCTRLKEY) &&   event->ctrl)  ||
2154                                             (ELEM(kmi->type, LEFTSHIFTKEY, RIGHTSHIFTKEY) && event->shift) ||
2155                                             (ELEM(kmi->type, LEFTALTKEY, RIGHTALTKEY) &&     event->alt)   ||
2156                                             ((kmi->type == OSKEY) &&                         event->oskey) )
2157                                         {
2158                                                 t->modifiers |= MOD_SNAP_INVERT;
2159                                         }
2160                                         break;
2161                                 }
2162                         }
2163                 }
2164         }
2165
2166         initSnapping(t, op); // Initialize snapping data AFTER mode flags
2167
2168         initSnapSpatial(t, t->snap_spatial);
2169
2170         /* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
2171         /* EVIL2: we gave as argument also texture space context bit... was cleared */
2172         /* EVIL3: extend mode for animation editors also switches modes... but is best way to avoid duplicate code */
2173         mode = t->mode;
2174
2175         calculatePropRatio(t);
2176         calculateCenter(t);
2177
2178         if (event) {
2179                 /* Initialize accurate transform to settings requested by keymap. */
2180                 bool use_accurate = false;
2181                 if ((prop = RNA_struct_find_property(op->ptr, "use_accurate")) && RNA_property_is_set(op->ptr, prop)) {
2182                         if (RNA_property_boolean_get(op->ptr, prop)) {
2183                                 use_accurate = true;
2184                         }
2185                 }
2186                 initMouseInput(t, &t->mouse, t->center2d, event->mval, use_accurate);
2187         }
2188
2189         switch (mode) {
2190                 case TFM_TRANSLATION:
2191                         initTranslation(t);
2192                         break;
2193                 case TFM_ROTATION:
2194                         initRotation(t);
2195                         break;
2196                 case TFM_RESIZE:
2197                         initResize(t);
2198                         break;
2199                 case TFM_SKIN_RESIZE:
2200                         initSkinResize(t);
2201                         break;
2202                 case TFM_TOSPHERE:
2203                         initToSphere(t);
2204                         break;
2205                 case TFM_SHEAR:
2206                         initShear(t);
2207                         break;
2208                 case TFM_BEND:
2209                         initBend(t);
2210                         break;
2211                 case TFM_SHRINKFATTEN:
2212                         initShrinkFatten(t);
2213                         break;
2214                 case TFM_TILT:
2215                         initTilt(t);
2216                         break;
2217                 case TFM_CURVE_SHRINKFATTEN:
2218                         initCurveShrinkFatten(t);
2219                         break;
2220                 case TFM_MASK_SHRINKFATTEN:
2221                         initMaskShrinkFatten(t);
2222                         break;
2223                 case TFM_GPENCIL_SHRINKFATTEN:
2224                         initGPShrinkFatten(t);
2225                         break;
2226                 case TFM_TRACKBALL:
2227                         initTrackball(t);
2228                         break;
2229                 case TFM_PUSHPULL:
2230                         initPushPull(t);
2231                         break;
2232                 case TFM_CREASE:
2233                         initCrease(t);
2234                         break;
2235                 case TFM_BONESIZE:
2236                 {   /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
2237                         bArmature *arm = t->poseobj->data;
2238                         if (arm->drawtype == ARM_ENVELOPE) {
2239                                 initBoneEnvelope(t);
2240                                 t->mode = TFM_BONE_ENVELOPE_DIST;
2241                         }
2242                         else {
2243                                 initBoneSize(t);
2244                         }
2245                         break;
2246                 }
2247                 case TFM_BONE_ENVELOPE:
2248                         initBoneEnvelope(t);
2249                         break;
2250                 case TFM_BONE_ENVELOPE_DIST:
2251                         initBoneEnvelope(t);
2252                         t->mode = TFM_BONE_ENVELOPE_DIST;
2253                         break;
2254                 case TFM_EDGE_SLIDE:
2255                 case TFM_VERT_SLIDE:
2256                 {
2257                         const bool use_even = (op ? RNA_boolean_get(op->ptr, "use_even") : false);
2258                         const bool flipped = (op ? RNA_boolean_get(op->ptr, "flipped") : false);
2259                         const bool use_clamp = (op ? RNA_boolean_get(op->ptr, "use_clamp") : true);
2260                         if (mode == TFM_EDGE_SLIDE) {
2261                                 const bool use_double_side = (op ? !RNA_boolean_get(op->ptr, "single_side") : true);
2262                                 initEdgeSlide_ex(t, use_double_side, use_even, flipped, use_clamp);
2263                         }
2264                         else {
2265                                 initVertSlide_ex(t, use_even, flipped, use_clamp);
2266                         }
2267                         break;
2268                 }
2269                 case TFM_BONE_ROLL:
2270                         initBoneRoll(t);
2271                         break;
2272                 case TFM_TIME_TRANSLATE:
2273                         initTimeTranslate(t);
2274                         break;
2275                 case TFM_TIME_SLIDE:
2276                         initTimeSlide(t);
2277                         break;
2278                 case TFM_TIME_SCALE:
2279                         initTimeScale(t);
2280                         break;
2281                 case TFM_TIME_DUPLICATE:
2282                         /* same as TFM_TIME_EXTEND, but we need the mode info for later
2283                          * so that duplicate-culling will work properly
2284                          */
2285                         if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA))
2286                                 initTranslation(t);
2287                         else
2288                                 initTimeTranslate(t);
2289                         t->mode = mode;
2290                         break;
2291                 case TFM_TIME_EXTEND:
2292                         /* now that transdata has been made, do like for TFM_TIME_TRANSLATE (for most Animation
2293                          * Editors because they have only 1D transforms for time values) or TFM_TRANSLATION
2294                          * (for Graph/NLA Editors only since they uses 'standard' transforms to get 2D movement)
2295                          * depending on which editor this was called from
2296                          */
2297                         if (ELEM(t->spacetype, SPACE_IPO, SPACE_NLA))
2298                                 initTranslation(t);
2299                         else
2300                                 initTimeTranslate(t);
2301                         break;
2302                 case TFM_BAKE_TIME:
2303                         initBakeTime(t);
2304                         break;
2305                 case TFM_MIRROR:
2306                         initMirror(t);
2307                         break;
2308                 case TFM_BWEIGHT:
2309                         initBevelWeight(t);
2310                         break;
2311                 case TFM_ALIGN:
2312                         initAlign(t);
2313                         break;
2314                 case TFM_SEQ_SLIDE:
2315                         initSeqSlide(t);
2316                         break;
2317         }
2318
2319         if (t->state == TRANS_CANCEL) {
2320                 postTrans(C, t);
2321                 return 0;
2322         }
2323
2324         /* Transformation axis from operator */
2325         if ((prop = RNA_struct_find_property(op->ptr, "axis")) && RNA_property_is_set(op->ptr, prop)) {
2326                 RNA_property_float_get_array(op->ptr, prop, t->axis);
2327                 normalize_v3(t->axis);
2328                 copy_v3_v3(t->axis_orig, t->axis);
2329         }
2330
2331         /* Constraint init from operator */
2332         if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis")) && RNA_property_is_set(op->ptr, prop)) {
2333                 int constraint_axis[3];
2334
2335                 RNA_property_boolean_get_array(op->ptr, prop, constraint_axis);
2336
2337                 if (constraint_axis[0] || constraint_axis[1] || constraint_axis[2]) {
2338                         t->con.mode |= CON_APPLY;
2339
2340                         if (constraint_axis[0]) {
2341                                 t->con.mode |= CON_AXIS0;
2342                         }
2343                         if (constraint_axis[1]) {
2344                                 t->con.mode |= CON_AXIS1;
2345                         }
2346                         if (constraint_axis[2]) {
2347                                 t->con.mode |= CON_AXIS2;
2348                         }
2349
2350                         setUserConstraint(t, t->current_orientation, t->con.mode, "%s");
2351                 }
2352         }
2353
2354         /* overwrite initial values if operator supplied a non-null vector
2355          *
2356          * keep last so we can apply the constraints space.
2357          */
2358         if ((prop = RNA_struct_find_property(op->ptr, "value")) && RNA_property_is_set(op->ptr, prop)) {
2359                 float values[4] = {0}; /* in case value isn't length 4, avoid uninitialized memory  */
2360
2361                 if (RNA_property_array_check(prop)) {
2362                         RNA_float_get_array(op->ptr, "value", values);
2363                 }
2364                 else {
2365                         values[0] = RNA_float_get(op->ptr, "value");
2366                 }
2367
2368                 copy_v4_v4(t->values, values);
2369                 copy_v4_v4(t->auto_values, values);
2370                 t->flag |= T_AUTOVALUES;
2371         }
2372
2373         t->context = NULL;
2374
2375         return 1;
2376 }
2377
2378 void transformApply(bContext *C, TransInfo *t)
2379 {
2380         t->context = C;
2381
2382         if ((t->redraw & TREDRAW_HARD) || (t->draw_handle_apply == NULL && (t->redraw & TREDRAW_SOFT))) {
2383                 selectConstraint(t);
2384                 if (t->transform) {
2385                         t->transform(t, t->mval);  // calls recalcData()
2386                         viewRedrawForce(C, t);
2387                 }
2388                 t->redraw = TREDRAW_NOTHING;
2389         }
2390         else if (t->redraw & TREDRAW_SOFT) {
2391                 viewRedrawForce(C, t);
2392         }
2393
2394         /* If auto confirm is on, break after one pass */
2395         if (t->options & CTX_AUTOCONFIRM) {
2396                 t->state = TRANS_CONFIRM;
2397         }
2398
2399         t->context = NULL;
2400 }
2401
2402 static void drawTransformApply(const bContext *C, ARegion *UNUSED(ar), void *arg)
2403 {
2404         TransInfo *t = arg;
2405
2406         if (t->redraw & TREDRAW_SOFT) {
2407                 t->redraw |= TREDRAW_HARD;
2408                 transformApply((bContext *)C, t);
2409         }
2410 }
2411
2412 int transformEnd(bContext *C, TransInfo *t)
2413 {
2414         int exit_code = OPERATOR_RUNNING_MODAL;
2415
2416         t->context = C;
2417
2418         if (t->state != TRANS_STARTING && t->state != TRANS_RUNNING) {
2419                 /* handle restoring objects */
2420                 if (t->state == TRANS_CANCEL) {
2421                         /* exception, edge slide transformed UVs too */
2422                         if (t->mode == TFM_EDGE_SLIDE) {
2423                                 doEdgeSlide(t, 0.0f);
2424                         }
2425                         else if (t->mode == TFM_VERT_SLIDE) {
2426                                 doVertSlide(t, 0.0f);
2427                         }
2428                         
2429                         exit_code = OPERATOR_CANCELLED;
2430                         restoreTransObjects(t); // calls recalcData()
2431                 }
2432                 else {
2433                         exit_code = OPERATOR_FINISHED;
2434                 }
2435
2436                 /* aftertrans does insert keyframes, and clears base flags; doesn't read transdata */
2437                 special_aftertrans_update(C, t);
2438
2439                 /* free data */
2440                 postTrans(C, t);
2441
2442                 /* send events out for redraws */
2443                 viewRedrawPost(C, t);
2444
2445                 viewRedrawForce(C, t);
2446         }
2447
2448         t->context = NULL;
2449
2450         return exit_code;
2451 }
2452
2453 /* ************************** TRANSFORM LOCKS **************************** */
2454
2455 static void protectedTransBits(short protectflag, float vec[3])
2456 {
2457         if (protectflag & OB_LOCK_LOCX)
2458                 vec[0] = 0.0f;
2459         if (protectflag & OB_LOCK_LOCY)
2460                 vec[1] = 0.0f;
2461         if (protectflag & OB_LOCK_LOCZ)
2462                 vec[2] = 0.0f;
2463 }
2464
2465 static void protectedSizeBits(short protectflag, float size[3])
2466 {
2467         if (protectflag & OB_LOCK_SCALEX)
2468                 size[0] = 1.0f;
2469         if (protectflag & OB_LOCK_SCALEY)
2470                 size[1] = 1.0f;
2471         if (protectflag & OB_LOCK_SCALEZ)
2472                 size[2] = 1.0f;
2473 }
2474
2475 static void protectedRotateBits(short protectflag, float eul[3], const float oldeul[3])
2476 {
2477         if (protectflag & OB_LOCK_ROTX)
2478                 eul[0] = oldeul[0];
2479         if (protectflag & OB_LOCK_ROTY)
2480                 eul[1] = oldeul[1];
2481         if (protectflag & OB_LOCK_ROTZ)
2482                 eul[2] = oldeul[2];
2483 }
2484
2485
2486 /* this function only does the delta rotation */
2487 /* axis-angle is usually internally stored as quats... */
2488 static void protectedAxisAngleBits(short protectflag, float axis[3], float *angle, float oldAxis[3], float oldAngle)
2489 {
2490         /* check that protection flags are set */
2491         if ((protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) == 0)
2492                 return;
2493         
2494         if (protectflag & OB_LOCK_ROT4D) {
2495                 /* axis-angle getting limited as 4D entities that they are... */
2496                 if (protectflag & OB_LOCK_ROTW)
2497                         *angle = oldAngle;
2498                 if (protectflag & OB_LOCK_ROTX)
2499                         axis[0] = oldAxis[0];
2500                 if (protectflag & OB_LOCK_ROTY)
2501                         axis[1] = oldAxis[1];
2502                 if (protectflag & OB_LOCK_ROTZ)
2503                         axis[2] = oldAxis[2];
2504         }
2505         else {
2506                 /* axis-angle get limited with euler... */
2507                 float eul[3], oldeul[3];
2508                 
2509                 axis_angle_to_eulO(eul, EULER_ORDER_DEFAULT, axis, *angle);
2510                 axis_angle_to_eulO(oldeul, EULER_ORDER_DEFAULT, oldAxis, oldAngle);
2511                 
2512                 if (protectflag & OB_LOCK_ROTX)
2513                         eul[0] = oldeul[0];
2514                 if (protectflag & OB_LOCK_ROTY)
2515                         eul[1] = oldeul[1];
2516                 if (protectflag & OB_LOCK_ROTZ)
2517                         eul[2] = oldeul[2];
2518                 
2519                 eulO_to_axis_angle(axis, angle, eul, EULER_ORDER_DEFAULT);
2520                 
2521                 /* when converting to axis-angle, we need a special exception for the case when there is no axis */
2522                 if (IS_EQF(axis[0], axis[1]) && IS_EQF(axis[1], axis[2])) {
2523                         /* for now, rotate around y-axis then (so that it simply becomes the roll) */
2524                         axis[1] = 1.0f;
2525                 }
2526         }
2527 }
2528
2529 /* this function only does the delta rotation */
2530 static void protectedQuaternionBits(short protectflag, float quat[4], const float oldquat[4])
2531 {
2532         /* check that protection flags are set */
2533         if ((protectflag & (OB_LOCK_ROTX | OB_LOCK_ROTY | OB_LOCK_ROTZ | OB_LOCK_ROTW)) == 0)
2534                 return;
2535         
2536         if (protectflag & OB_LOCK_ROT4D) {
2537                 /* quaternions getting limited as 4D entities that they are... */
2538                 if (protectflag & OB_LOCK_ROTW)
2539                         quat[0] = oldquat[0];
2540                 if (protectflag & OB_LOCK_ROTX)
2541                         quat[1] = oldquat[1];
2542                 if (protectflag & OB_LOCK_ROTY)
2543                         quat[2] = oldquat[2];
2544                 if (protectflag & OB_LOCK_ROTZ)
2545                         quat[3] = oldquat[3];
2546         }
2547         else {
2548                 /* quaternions get limited with euler... (compatibility mode) */
2549                 float eul[3], oldeul[3], nquat[4], noldquat[4];
2550                 float qlen;
2551
2552                 qlen = normalize_qt_qt(nquat, quat);
2553                 normalize_qt_qt(noldquat, oldquat);
2554
2555                 quat_to_eul(eul, nquat);
2556                 quat_to_eul(oldeul, noldquat);
2557
2558                 if (protectflag & OB_LOCK_ROTX)
2559                         eul[0] = oldeul[0];
2560                 if (protectflag & OB_LOCK_ROTY)
2561                         eul[1] = oldeul[1];
2562                 if (protectflag & OB_LOCK_ROTZ)
2563                         eul[2] = oldeul[2];
2564
2565                 eul_to_quat(quat, eul);
2566
2567                 /* restore original quat size */
2568                 mul_qt_fl(quat, qlen);
2569                 
2570                 /* quaternions flip w sign to accumulate rotations correctly */
2571                 if ((nquat[0] < 0.0f && quat[0] > 0.0f) ||
2572                     (nquat[0] > 0.0f && quat[0] < 0.0f))
2573                 {
2574                         mul_qt_fl(quat, -1.0f);
2575                 }
2576         }
2577 }
2578
2579 /* ******************* TRANSFORM LIMITS ********************** */
2580
2581 static void constraintTransLim(TransInfo *t, TransData *td)
2582 {
2583         if (td->con) {
2584                 const bConstraintTypeInfo *ctiLoc = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_LOCLIMIT);
2585                 const bConstraintTypeInfo *ctiDist = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_DISTLIMIT);
2586                 
2587                 bConstraintOb cob = {NULL};
2588                 bConstraint *con;
2589                 float ctime = (float)(t->scene->r.cfra);
2590                 
2591                 /* Make a temporary bConstraintOb for using these limit constraints
2592                  *  - they only care that cob->matrix is correctly set ;-)
2593                  *      - current space should be local
2594                  */
2595                 unit_m4(cob.matrix);
2596                 copy_v3_v3(cob.matrix[3], td->loc);
2597                 
2598                 /* Evaluate valid constraints */
2599                 for (con = td->con; con; con = con->next) {
2600                         const bConstraintTypeInfo *cti = NULL;
2601                         ListBase targets = {NULL, NULL};
2602                         
2603                         /* only consider constraint if enabled */
2604                         if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) continue;
2605                         if (con->enforce == 0.0f) continue;
2606                         
2607                         /* only use it if it's tagged for this purpose (and the right type) */
2608                         if (con->type == CONSTRAINT_TYPE_LOCLIMIT) {
2609                                 bLocLimitConstraint *data = con->data;
2610                                 
2611                                 if ((data->flag2 & LIMIT_TRANSFORM) == 0)
2612                                         continue;
2613                                 cti = ctiLoc;
2614                         }
2615                         else if (con->type == CONSTRAINT_TYPE_DISTLIMIT) {
2616                                 bDistLimitConstraint *data = con->data;
2617                                 
2618                                 if ((data->flag & LIMITDIST_TRANSFORM) == 0)
2619                                         continue;
2620                                 cti = ctiDist;
2621                         }
2622                         
2623                         if (cti) {
2624                                 /* do space conversions */
2625                                 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2626                                         /* just multiply by td->mtx (this should be ok) */
2627                                         mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
2628                                 }
2629                                 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2630                                         /* skip... incompatable spacetype */
2631                                         continue;
2632                                 }
2633                                 
2634                                 /* get constraint targets if needed */
2635                                 BKE_constraint_targets_for_solving_get(con, &cob, &targets, ctime);
2636                                 
2637                                 /* do constraint */
2638                                 cti->evaluate_constraint(con, &cob, &targets);
2639                                 
2640                                 /* convert spaces again */
2641                                 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2642                                         /* just multiply by td->smtx (this should be ok) */
2643                                         mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
2644                                 }
2645                                 
2646                                 /* free targets list */
2647                                 BLI_freelistN(&targets);
2648                         }
2649                 }
2650                 
2651                 /* copy results from cob->matrix */
2652                 copy_v3_v3(td->loc, cob.matrix[3]);
2653         }
2654 }
2655
2656 static void constraintob_from_transdata(bConstraintOb *cob, TransData *td)
2657 {
2658         /* Make a temporary bConstraintOb for use by limit constraints
2659          *  - they only care that cob->matrix is correctly set ;-)
2660          *      - current space should be local
2661          */
2662         memset(cob, 0, sizeof(bConstraintOb));
2663         if (td->ext) {
2664                 if (td->ext->rotOrder == ROT_MODE_QUAT) {
2665                         /* quats */
2666                         /* objects and bones do normalization first too, otherwise
2667                          * we don't necessarily end up with a rotation matrix, and
2668                          * then conversion back to quat gives a different result */
2669                         float quat[4];
2670                         normalize_qt_qt(quat, td->ext->quat);
2671                         quat_to_mat4(cob->matrix, quat);
2672                 }
2673                 else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2674                         /* axis angle */
2675                         axis_angle_to_mat4(cob->matrix, td->ext->rotAxis, *td->ext->rotAngle);
2676                 }
2677                 else {
2678                         /* eulers */
2679                         eulO_to_mat4(cob->matrix, td->ext->rot, td->ext->rotOrder);
2680                 }
2681         }
2682 }
2683
2684 static void constraintRotLim(TransInfo *UNUSED(t), TransData *td)
2685 {
2686         if (td->con) {
2687                 const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_ROTLIMIT);
2688                 bConstraintOb cob;
2689                 bConstraint *con;
2690                 bool do_limit = false;
2691
2692                 /* Evaluate valid constraints */
2693                 for (con = td->con; con; con = con->next) {
2694                         /* only consider constraint if enabled */
2695                         if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) continue;
2696                         if (con->enforce == 0.0f) continue;
2697
2698                         /* we're only interested in Limit-Rotation constraints */
2699                         if (con->type == CONSTRAINT_TYPE_ROTLIMIT) {
2700                                 bRotLimitConstraint *data = con->data;
2701
2702                                 /* only use it if it's tagged for this purpose */
2703                                 if ((data->flag2 & LIMIT_TRANSFORM) == 0)
2704                                         continue;
2705
2706                                 /* skip incompatable spacetypes */
2707                                 if (!ELEM(con->ownspace, CONSTRAINT_SPACE_WORLD, CONSTRAINT_SPACE_LOCAL))
2708                                         continue;
2709
2710                                 /* only do conversion if necessary, to preserve quats and eulers */
2711                                 if (do_limit == false) {
2712                                         constraintob_from_transdata(&cob, td);
2713                                         do_limit = true;
2714                                 }
2715
2716                                 /* do space conversions */
2717                                 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2718                                         /* just multiply by td->mtx (this should be ok) */
2719                                         mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
2720                                 }
2721                                 
2722                                 /* do constraint */
2723                                 cti->evaluate_constraint(con, &cob, NULL);
2724                                 
2725                                 /* convert spaces again */
2726                                 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2727                                         /* just multiply by td->smtx (this should be ok) */
2728                                         mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
2729                                 }
2730                         }
2731                 }
2732                 
2733                 if (do_limit) {
2734                         /* copy results from cob->matrix */
2735                         if (td->ext->rotOrder == ROT_MODE_QUAT) {
2736                                 /* quats */
2737                                 mat4_to_quat(td->ext->quat, cob.matrix);
2738                         }
2739                         else if (td->ext->rotOrder == ROT_MODE_AXISANGLE) {
2740                                 /* axis angle */
2741                                 mat4_to_axis_angle(td->ext->rotAxis, td->ext->rotAngle, cob.matrix);
2742                         }
2743                         else {
2744                                 /* eulers */
2745                                 mat4_to_eulO(td->ext->rot, td->ext->rotOrder, cob.matrix);
2746                         }
2747                 }
2748         }
2749 }
2750
2751 static void constraintSizeLim(TransInfo *t, TransData *td)
2752 {
2753         if (td->con && td->ext) {
2754                 const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_from_type(CONSTRAINT_TYPE_SIZELIMIT);
2755                 bConstraintOb cob = {NULL};
2756                 bConstraint *con;
2757                 float size_sign[3], size_abs[3];
2758                 int i;
2759                 
2760                 /* Make a temporary bConstraintOb for using these limit constraints
2761                  *  - they only care that cob->matrix is correctly set ;-)
2762                  *      - current space should be local
2763                  */
2764                 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2765                         /* scale val and reset size */
2766                         return; // TODO: fix this case
2767                 }
2768                 else {
2769                         /* Reset val if SINGLESIZE but using a constraint */
2770                         if (td->flag & TD_SINGLESIZE)
2771                                 return;
2772
2773                         /* separate out sign to apply back later */
2774                         for (i = 0; i < 3; i++) {
2775                                 size_sign[i] = signf(td->ext->size[i]);
2776                                 size_abs[i] = fabsf(td->ext->size[i]);
2777                         }
2778                         
2779                         size_to_mat4(cob.matrix, size_abs);
2780                 }
2781                 
2782                 /* Evaluate valid constraints */
2783                 for (con = td->con; con; con = con->next) {
2784                         /* only consider constraint if enabled */
2785                         if (con->flag & (CONSTRAINT_DISABLE | CONSTRAINT_OFF)) continue;
2786                         if (con->enforce == 0.0f) continue;
2787                         
2788                         /* we're only interested in Limit-Scale constraints */
2789                         if (con->type == CONSTRAINT_TYPE_SIZELIMIT) {
2790                                 bSizeLimitConstraint *data = con->data;
2791                                 
2792                                 /* only use it if it's tagged for this purpose */
2793                                 if ((data->flag2 & LIMIT_TRANSFORM) == 0)
2794                                         continue;
2795                                 
2796                                 /* do space conversions */
2797                                 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2798                                         /* just multiply by td->mtx (this should be ok) */
2799                                         mul_m4_m3m4(cob.matrix, td->mtx, cob.matrix);
2800                                 }
2801                                 else if (con->ownspace != CONSTRAINT_SPACE_LOCAL) {
2802                                         /* skip... incompatible spacetype */
2803                                         continue;
2804                                 }
2805                                 
2806                                 /* do constraint */
2807                                 cti->evaluate_constraint(con, &cob, NULL);
2808                                 
2809                                 /* convert spaces again */
2810                                 if (con->ownspace == CONSTRAINT_SPACE_WORLD) {
2811                                         /* just multiply by td->smtx (this should be ok) */
2812                                         mul_m4_m3m4(cob.matrix, td->smtx, cob.matrix);
2813                                 }
2814                         }
2815                 }
2816
2817                 /* copy results from cob->matrix */
2818                 if ((td->flag & TD_SINGLESIZE) && !(t->con.mode & CON_APPLY)) {
2819                         /* scale val and reset size */
2820                         return; // TODO: fix this case
2821                 }
2822                 else {
2823                         /* Reset val if SINGLESIZE but using a constraint */
2824                         if (td->flag & TD_SINGLESIZE)
2825                                 return;
2826
2827                         /* extrace scale from matrix and apply back sign */
2828                         mat4_to_size(td->ext->size, cob.matrix);
2829                         mul_v3_v3(td->ext->size, size_sign);
2830                 }
2831         }
2832 }
2833
2834
2835 /* -------------------------------------------------------------------- */
2836 /* Transform (Bend) */
2837
2838 /** \name Transform Bend
2839  * \{ */
2840
2841 struct BendCustomData {
2842         float warp_sta[3];
2843         float warp_end[3];
2844
2845         float warp_nor[3];
2846         float warp_tan[3];
2847
2848   &nb