NLA SoC: Transform Code for NLA-Strips recoded (still buggy)
[blender.git] / source / blender / editors / transform / transform_generics.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <string.h>
31 #include <math.h>
32
33 #include "MEM_guardedalloc.h"
34
35 #include "BLO_sys_types.h" // for intptr_t support
36
37 #include "DNA_anim_types.h"
38 #include "DNA_action_types.h"
39 #include "DNA_armature_types.h"
40 #include "DNA_constraint_types.h"
41 #include "DNA_curve_types.h"
42 #include "DNA_lattice_types.h"
43 #include "DNA_mesh_types.h"
44 #include "DNA_modifier_types.h"
45 #include "DNA_nla_types.h"
46 #include "DNA_node_types.h"
47 #include "DNA_object_types.h"
48 #include "DNA_object_force.h"
49 #include "DNA_particle_types.h"
50 #include "DNA_screen_types.h"
51 #include "DNA_space_types.h"
52 #include "DNA_scene_types.h"
53 #include "DNA_userdef_types.h"
54 #include "DNA_view3d_types.h"
55 #include "DNA_windowmanager_types.h"
56
57 #include "RNA_access.h"
58
59 //#include "BIF_screen.h"
60 //#include "BIF_mywindow.h"
61 #include "BIF_gl.h"
62 //#include "BIF_editaction.h"
63 //#include "BIF_editmesh.h"
64 //#include "BIF_editnla.h"
65 //#include "BIF_editsima.h"
66 //#include "BIF_editparticle.h"
67 //#include "BIF_meshtools.h"
68 #include "BIF_retopo.h"
69
70 #include "BKE_action.h"
71 #include "BKE_anim.h"
72 #include "BKE_armature.h"
73 #include "BKE_cloth.h"
74 #include "BKE_curve.h"
75 #include "BKE_depsgraph.h"
76 #include "BKE_displist.h"
77 #include "BKE_depsgraph.h"
78 #include "BKE_fcurve.h"
79 #include "BKE_global.h"
80 #include "BKE_group.h"
81 #include "BKE_lattice.h"
82 #include "BKE_key.h"
83 #include "BKE_mesh.h"
84 #include "BKE_modifier.h"
85 #include "BKE_nla.h"
86 #include "BKE_object.h"
87 #include "BKE_utildefines.h"
88 #include "BKE_context.h"
89
90 #include "ED_anim_api.h"
91 #include "ED_armature.h"
92 #include "ED_image.h"
93 #include "ED_keyframing.h"
94 #include "ED_mesh.h"
95 #include "ED_space_api.h"
96 #include "ED_uvedit.h"
97 #include "ED_view3d.h"
98
99 //#include "BDR_unwrapper.h"
100
101 #include "BLI_arithb.h"
102 #include "BLI_blenlib.h"
103 #include "BLI_editVert.h"
104 #include "BLI_rand.h"
105
106 #include "RNA_access.h"
107
108 #include "WM_types.h"
109
110 #include "UI_resources.h"
111
112 //#include "blendef.h"
113 //
114 //#include "mydevice.h"
115
116 #include "transform.h"
117
118 extern ListBase editelems;
119
120 extern TransInfo Trans; /* From transform.c */
121
122 /* ************************** Functions *************************** */
123
124 void getViewVector(TransInfo *t, float coord[3], float vec[3])
125 {
126         if (t->persp != V3D_ORTHO)
127         {
128                 float p1[4], p2[4];
129
130                 VECCOPY(p1, coord);
131                 p1[3] = 1.0f;
132                 VECCOPY(p2, p1);
133                 p2[3] = 1.0f;
134                 Mat4MulVec4fl(t->viewmat, p2);
135
136                 p2[0] = 2.0f * p2[0];
137                 p2[1] = 2.0f * p2[1];
138                 p2[2] = 2.0f * p2[2];
139
140                 Mat4MulVec4fl(t->viewinv, p2);
141
142                 VecSubf(vec, p1, p2);
143         }
144         else {
145                 VECCOPY(vec, t->viewinv[2]);
146         }
147         Normalize(vec);
148 }
149
150 /* ************************** GENERICS **************************** */
151
152 static void clipMirrorModifier(TransInfo *t, Object *ob)
153 {
154         ModifierData *md= ob->modifiers.first;
155         float tolerance[3] = {0.0f, 0.0f, 0.0f};
156         int axis = 0;
157
158         for (; md; md=md->next) {
159                 if (md->type==eModifierType_Mirror) {
160                         MirrorModifierData *mmd = (MirrorModifierData*) md;     
161                 
162                         if(mmd->flag & MOD_MIR_CLIPPING) {
163                                 axis = 0;
164                                 if(mmd->flag & MOD_MIR_AXIS_X) {
165                                         axis |= 1;
166                                         tolerance[0] = mmd->tolerance;
167                                 }
168                                 if(mmd->flag & MOD_MIR_AXIS_Y) {
169                                         axis |= 2;
170                                         tolerance[1] = mmd->tolerance;
171                                 }
172                                 if(mmd->flag & MOD_MIR_AXIS_Z) {
173                                         axis |= 4;
174                                         tolerance[2] = mmd->tolerance;
175                                 }
176                                 if (axis) {
177                                         float mtx[4][4], imtx[4][4];
178                                         int i;
179                                         TransData *td = t->data;
180                 
181                                         if (mmd->mirror_ob) {
182                                                 float obinv[4][4];
183
184                                                 Mat4Invert(obinv, mmd->mirror_ob->obmat);
185                                                 Mat4MulMat4(mtx, ob->obmat, obinv);
186                                                 Mat4Invert(imtx, mtx);
187                                         }
188
189                                         for(i = 0 ; i < t->total; i++, td++) {
190                                                 int clip;
191                                                 float loc[3], iloc[3];
192
193                                                 if (td->flag & TD_NOACTION)
194                                                         break;
195                                                 if (td->loc==NULL)
196                                                         break;
197                                                         
198                                                 if (td->flag & TD_SKIP)
199                                                         continue;
200                         
201                                                 VecCopyf(loc,  td->loc);
202                                                 VecCopyf(iloc, td->iloc);
203
204                                                 if (mmd->mirror_ob) {
205                                                         VecMat4MulVecfl(loc, mtx, loc);
206                                                         VecMat4MulVecfl(iloc, mtx, iloc);
207                                                 }
208
209                                                 clip = 0;
210                                                 if(axis & 1) {
211                                                         if(fabs(iloc[0])<=tolerance[0] || 
212                                                            loc[0]*iloc[0]<0.0f) {
213                                                                 loc[0]= 0.0f;
214                                                                 clip = 1;
215                                                         }
216                                                 }
217                         
218                                                 if(axis & 2) {
219                                                         if(fabs(iloc[1])<=tolerance[1] || 
220                                                            loc[1]*iloc[1]<0.0f) {
221                                                                 loc[1]= 0.0f;
222                                                                 clip = 1;
223                                                         }
224                                                 }
225                                                 if(axis & 4) {
226                                                         if(fabs(iloc[2])<=tolerance[2] || 
227                                                            loc[2]*iloc[2]<0.0f) {
228                                                                 loc[2]= 0.0f;
229                                                                 clip = 1;
230                                                         }
231                                                 }
232                                                 if (clip) {
233                                                         if (mmd->mirror_ob) {
234                                                                 VecMat4MulVecfl(loc, imtx, loc);
235                                                         }
236                                                         VecCopyf(td->loc, loc);
237                                                 }
238                                         }
239                                 }
240
241                         }
242                 }
243         }
244 }
245
246 /* assumes obedit set to mesh object */
247 static void editmesh_apply_to_mirror(TransInfo *t)
248 {
249         TransData *td = t->data;
250         EditVert *eve;
251         int i;
252         
253         for(i = 0 ; i < t->total; i++, td++) {
254                 if (td->flag & TD_NOACTION)
255                         break;
256                 if (td->loc==NULL)
257                         break;
258                 if (td->flag & TD_SKIP)
259                         continue;
260                 
261                 eve = td->extra;
262                 if(eve) {
263                         eve->co[0]= -td->loc[0];
264                         eve->co[1]= td->loc[1];
265                         eve->co[2]= td->loc[2];
266                 }               
267         }               
268 }
269
270 /* called for updating while transform acts, once per redraw */
271 void recalcData(TransInfo *t)
272 {
273         Scene *scene = t->scene;
274         Base *base;
275         
276         if (t->obedit) {
277         }
278         else if(G.f & G_PARTICLEEDIT) {
279                 flushTransParticles(t);
280         }
281         if (t->spacetype==SPACE_NODE) {
282                 flushTransNodes(t);
283         }
284         else if (t->spacetype==SPACE_SEQ) {
285                 flushTransSeq(t);
286         }
287         else if (t->spacetype == SPACE_IPO) {
288                 SpaceIpo *sipo= (SpaceIpo *)t->sa->spacedata.first;
289                 Scene *scene;
290                 
291                 ListBase anim_data = {NULL, NULL};
292                 bAnimContext ac;
293                 int filter;
294                 
295                 bAnimListElem *ale;
296                 int dosort = 0;
297                 
298                 
299                 /* initialise relevant anim-context 'context' data from TransInfo data */
300                         /* NOTE: sync this with the code in ANIM_animdata_get_context() */
301                 memset(&ac, 0, sizeof(bAnimContext));
302                 
303                 scene= ac.scene= t->scene;
304                 ac.obact= OBACT;
305                 ac.sa= t->sa;
306                 ac.ar= t->ar;
307                 ac.spacetype= (t->sa)? t->sa->spacetype : 0;
308                 ac.regiontype= (t->ar)? t->ar->regiontype : 0;
309                 
310                 ANIM_animdata_context_getdata(&ac);
311                 
312                 /* do the flush first */
313                 flushTransGraphData(t);
314                 
315                 /* get curves to check if a re-sort is needed */
316                 filter= (ANIMFILTER_VISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY | ANIMFILTER_CURVEVISIBLE);
317                 ANIM_animdata_filter(&ac, &anim_data, filter, ac.data, ac.datatype);
318                 
319                 /* now test if there is a need to re-sort */
320                 for (ale= anim_data.first; ale; ale= ale->next) {
321                         FCurve *fcu= (FCurve *)ale->key_data;
322                         
323                         /* watch it: if the time is wrong: do not correct handles yet */
324                         if (test_time_fcurve(fcu))
325                                 dosort++;
326                         else
327                                 calchandles_fcurve(fcu);
328                 }
329                 
330                 /* do resort and other updates? */
331                 if (dosort) remake_graph_transdata(t, &anim_data);
332                 //if (sipo->showkey) update_ipokey_val();
333                 
334                 /* now free temp channels */
335                 BLI_freelistN(&anim_data);
336                 
337                 /* update realtime - not working? */
338                 if (sipo->lock) {
339                 
340                 }
341         }
342         else if (t->spacetype == SPACE_NLA) {
343                 TransDataNla *tdn= (TransDataNla *)t->customData;
344                 int i;
345                 
346                 /* for each strip we've got, perform some additional validation of the values that got set before 
347                  * using RNA to set the value (which does some special operations when setting these values to make
348                  * sure that everything works ok)
349                  */
350                 for (i = 0; i < t->total; i++, tdn++) {
351                         NlaStrip *strip= tdn->strip;
352                         PointerRNA strip_ptr;
353                         short pExceeded, nExceeded, iter;
354                         int delta_y1, delta_y2;
355                         
356                         /* if this tdn has no handles, that means it is just a dummy that should be skipped */
357                         if (tdn->handle == 0)
358                                 continue;
359                                 
360                         /* if cancelling transform, just write the values without validating, then move on */
361                         if (t->state == TRANS_CANCEL) {
362                                 /* clear the values by directly overwriting the originals, but also need to restore 
363                                  * endpoints of neighboring transition-strips
364                                  */
365                                  
366                                 /* start */
367                                 strip->start= tdn->h1[0];
368                                 
369                                 if ((strip->prev) && (strip->prev->type == NLASTRIP_TYPE_TRANSITION))
370                                         strip->prev->end= tdn->h1[0];
371                                  
372                                 /* end */
373                                 strip->end= tdn->h2[0];
374                                 
375                                 if ((strip->next) && (strip->next->type == NLASTRIP_TYPE_TRANSITION))
376                                         strip->next->start= tdn->h2[0];
377                                         
378                                 /* restore to original track (if needed) */
379                                 if (tdn->oldTrack != tdn->nlt) {
380                                         /* just append to end of list for now, since strips get sorted in special_aftertrans_update() */
381                                         BLI_remlink(&tdn->nlt->strips, strip);
382                                         BLI_addtail(&tdn->oldTrack->strips, strip);
383                                 }
384                                 
385                                 continue;
386                         }
387                         
388                         /* firstly, check if the proposed transform locations would overlap with any neighbouring strips 
389                          * (barring transitions) which are absolute barriers since they are not being moved
390                          *
391                          * this is done as a iterative procedure (done 5 times max for now)
392                          */
393                         for (iter=0; iter < 5; iter++) {
394                                 pExceeded= ((strip->prev) && (strip->prev->type != NLASTRIP_TYPE_TRANSITION) && (tdn->h1[0] < strip->prev->end));
395                                 nExceeded= ((strip->next) && (strip->next->type != NLASTRIP_TYPE_TRANSITION) && (tdn->h2[0] > strip->next->start));
396                                 
397                                 if ((pExceeded && nExceeded) || (iter == 4) ) {
398                                         /* both endpoints exceeded (or iteration ping-pong'd meaning that we need a compromise) 
399                                          *      - simply crop strip to fit within the bounds of the strips bounding it 
400                                          *      - if there were no neighbours, clear the transforms (make it default to the strip's current values)
401                                          */
402                                         if (strip->prev && strip->next) {
403                                                 tdn->h1[0]= strip->prev->end;
404                                                 tdn->h2[0]= strip->next->start;
405                                         }
406                                         else {
407                                                 tdn->h1[0]= strip->start;
408                                                 tdn->h2[0]= strip->end;
409                                         }
410                                 }
411                                 else if (nExceeded) {
412                                         /* move backwards */
413                                         float offset= tdn->h2[0] - strip->next->start;
414                                         
415                                         tdn->h1[0] -= offset;
416                                         tdn->h2[0] -= offset;
417                                 }
418                                 else if (pExceeded) {
419                                         /* more forwards */
420                                         float offset= strip->prev->end - tdn->h1[0];
421                                         
422                                         tdn->h1[0] += offset;
423                                         tdn->h2[0] += offset;
424                                 }
425                                 else /* all is fine and well */
426                                         break;
427                         }
428                         
429                         /* use RNA to write the values... */
430                         // TODO: do we need to write in 2 passes to make sure that no truncation goes on?
431                         RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &strip_ptr);
432                         
433                         RNA_float_set(&strip_ptr, "start_frame", tdn->h1[0]);
434                         RNA_float_set(&strip_ptr, "end_frame", tdn->h2[0]);
435                         
436                         /* flush transforms to child strips (since this should be a meta) */
437                         BKE_nlameta_flush_transforms(strip);
438                         
439                         
440                         /* now, check if we need to try and move track 
441                          *      - we need to calculate both, as only one may have been altered by transform if only 1 handle moved
442                          */
443                         // FIXME: the conversion from vertical distance to track index needs work!
444                         delta_y1= ((int)tdn->h1[0] / NLACHANNEL_SKIP - tdn->trackIndex);
445                         delta_y2= ((int)tdn->h2[0] / NLACHANNEL_SKIP - tdn->trackIndex);
446                         
447                         if (delta_y1 || delta_y2) {
448                                 NlaTrack *track;
449                                 int delta = (delta_y2) ? delta_y2 : delta_y1;
450                                 int n;
451                                 
452                                 /* move in the requested direction, checking at each layer if there's space for strip to pass through, 
453                                  * stopping on the last track available or that we're able to fit in
454                                  */
455                                 if (delta > 0) {
456                                         for (track=tdn->nlt->next, n=0; (track) && (n < delta); track=track->next, n++) {
457                                                 /* check if space in this track for the strip */
458                                                 if (BKE_nlatrack_has_space(track, strip->start, strip->end)) {
459                                                         /* move strip to this track */
460                                                         BLI_remlink(&tdn->nlt->strips, strip);
461                                                         BKE_nlatrack_add_strip(track, strip);
462                                                         
463                                                         tdn->nlt= track;
464                                                         tdn->trackIndex += (n + 1); /* + 1, since n==0 would mean that we didn't change track */
465                                                 }
466                                                 else /* can't move any further */
467                                                         break;
468                                         }
469                                 }
470                                 else {
471                                         /* make delta 'positive' before using it, since we now know to go backwards */
472                                         delta= -delta;
473                                         
474                                         for (track=tdn->nlt->prev, n=0; (track) && (n < delta); track=track->prev, n++) {
475                                                 /* check if space in this track for the strip */
476                                                 if (BKE_nlatrack_has_space(track, strip->start, strip->end)) {
477                                                         /* move strip to this track */
478                                                         BLI_remlink(&tdn->nlt->strips, strip);
479                                                         BKE_nlatrack_add_strip(track, strip);
480                                                         
481                                                         tdn->nlt= track;
482                                                         tdn->trackIndex -= (n - 1); /* - 1, since n==0 would mean that we didn't change track */
483                                                 }
484                                                 else /* can't move any further */
485                                                         break;
486                                         }
487                                 }
488                         }
489                 }
490         }
491         else if (t->obedit) {
492                 if ELEM(t->obedit->type, OB_CURVE, OB_SURF) {
493                         Curve *cu= t->obedit->data;
494                         Nurb *nu= cu->editnurb->first;
495                         
496                         DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA);  /* sets recalc flags */
497                         
498                         if (t->state == TRANS_CANCEL) {
499                                 while(nu) {
500                                         calchandlesNurb(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
501                                         nu= nu->next;
502                                 }
503                         } else {
504                                 /* Normal updating */
505                                 while(nu) {
506                                         test2DNurb(nu);
507                                         calchandlesNurb(nu);
508                                         nu= nu->next;
509                                 }
510                                 /* TRANSFORM_FIX_ME */
511                                 // retopo_do_all();
512                         }
513                 }
514                 else if(t->obedit->type==OB_LATTICE) {
515                         Lattice *la= t->obedit->data;
516                         DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA);  /* sets recalc flags */
517                         
518                         if(la->editlatt->flag & LT_OUTSIDE) outside_lattice(la->editlatt);
519                 }
520                 else if (t->obedit->type == OB_MESH) {
521                         if(t->spacetype==SPACE_IMAGE) {
522                                 SpaceImage *sima= t->sa->spacedata.first;
523
524                                 flushTransUVs(t);
525                                 if(sima->flag & SI_LIVE_UNWRAP)
526                                         ED_uvedit_live_unwrap_re_solve();
527         
528                                 DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA);
529                         } else {
530                                 EditMesh *em = ((Mesh*)t->obedit->data)->edit_mesh;
531                                 /* mirror modifier clipping? */
532                                 if(t->state != TRANS_CANCEL) {
533                                         /* TRANSFORM_FIX_ME */
534 //                                      if ((G.qual & LR_CTRLKEY)==0) {
535 //                                              /* Only retopo if not snapping, Note, this is the only case of G.qual being used, but we have no T_SHIFT_MOD - Campbell */
536 //                                              retopo_do_all();
537 //                                      }
538                                         clipMirrorModifier(t, t->obedit);
539                                 }
540                                 if((t->options & CTX_NO_MIRROR) == 0 && (t->flag & T_MIRROR))
541                                         editmesh_apply_to_mirror(t);
542                                 
543                                 DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA);  /* sets recalc flags */
544                                 
545                                 recalc_editnormals(em);
546                         }
547                 }
548                 else if(t->obedit->type==OB_ARMATURE) { /* no recalc flag, does pose */
549                         bArmature *arm= t->obedit->data;
550                         ListBase *edbo = arm->edbo;
551                         EditBone *ebo;
552                         TransData *td = t->data;
553                         int i;
554                         
555                         /* Ensure all bones are correctly adjusted */
556                         for (ebo = edbo->first; ebo; ebo = ebo->next){
557                                 
558                                 if ((ebo->flag & BONE_CONNECTED) && ebo->parent){
559                                         /* If this bone has a parent tip that has been moved */
560                                         if (ebo->parent->flag & BONE_TIPSEL){
561                                                 VECCOPY (ebo->head, ebo->parent->tail);
562                                                 if(t->mode==TFM_BONE_ENVELOPE) ebo->rad_head= ebo->parent->rad_tail;
563                                         }
564                                         /* If this bone has a parent tip that has NOT been moved */
565                                         else{
566                                                 VECCOPY (ebo->parent->tail, ebo->head);
567                                                 if(t->mode==TFM_BONE_ENVELOPE) ebo->parent->rad_tail= ebo->rad_head;
568                                         }
569                                 }
570                                 
571                                 /* on extrude bones, oldlength==0.0f, so we scale radius of points */
572                                 ebo->length= VecLenf(ebo->head, ebo->tail);
573                                 if(ebo->oldlength==0.0f) {
574                                         ebo->rad_head= 0.25f*ebo->length;
575                                         ebo->rad_tail= 0.10f*ebo->length;
576                                         ebo->dist= 0.25f*ebo->length;
577                                         if(ebo->parent) {
578                                                 if(ebo->rad_head > ebo->parent->rad_tail)
579                                                         ebo->rad_head= ebo->parent->rad_tail;
580                                         }
581                                 }
582                                 else if(t->mode!=TFM_BONE_ENVELOPE) {
583                                         /* if bones change length, lets do that for the deform distance as well */
584                                         ebo->dist*= ebo->length/ebo->oldlength;
585                                         ebo->rad_head*= ebo->length/ebo->oldlength;
586                                         ebo->rad_tail*= ebo->length/ebo->oldlength;
587                                         ebo->oldlength= ebo->length;
588                                 }
589                         }
590                         
591                         
592                         if (t->mode != TFM_BONE_ROLL)
593                         {
594                                 /* fix roll */
595                                 for(i = 0; i < t->total; i++, td++)
596                                 {
597                                         if (td->extra)
598                                         {
599                                                 float vec[3], up_axis[3];
600                                                 float qrot[4];
601                                                 
602                                                 ebo = td->extra;
603                                                 VECCOPY(up_axis, td->axismtx[2]);
604                                                 
605                                                 if (t->mode != TFM_ROTATION)
606                                                 {
607                                                         VecSubf(vec, ebo->tail, ebo->head);
608                                                         Normalize(vec);
609                                                         RotationBetweenVectorsToQuat(qrot, td->axismtx[1], vec);
610                                                         QuatMulVecf(qrot, up_axis);
611                                                 }
612                                                 else
613                                                 {
614                                                         Mat3MulVecfl(t->mat, up_axis);
615                                                 }
616                                                 
617                                                 ebo->roll = ED_rollBoneToVector(ebo, up_axis);
618                                         }
619                                 }
620                         }
621                         
622                         if(arm->flag & ARM_MIRROR_EDIT) 
623                                 transform_armature_mirror_update(t->obedit);
624                         
625                 }
626                 else
627                         DAG_object_flush_update(scene, t->obedit, OB_RECALC_DATA);  /* sets recalc flags */
628         }
629         else if( (t->flag & T_POSE) && t->poseobj) {
630                 Object *ob= t->poseobj;
631                 bArmature *arm= ob->data;
632                 
633                 /* if animtimer is running, and the object already has animation data,
634                  * check if the auto-record feature means that we should record 'samples'
635                  * (i.e. uneditable animation values)
636                  */
637                 // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
638                 // TODO: maybe the ob->adt check isn't really needed? makes it too difficult to use...
639                 if (/*(ob->adt) && */(t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
640                         short targetless_ik= (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet!
641                         autokeyframe_pose_cb_func(t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
642                 }
643                 
644                 /* old optimize trick... this enforces to bypass the depgraph */
645                 if (!(arm->flag & ARM_DELAYDEFORM)) {
646                         DAG_object_flush_update(scene, ob, OB_RECALC_DATA);  /* sets recalc flags */
647                 }
648                 else
649                         where_is_pose(scene, ob);
650         }
651         else {
652                 for(base= FIRSTBASE; base; base= base->next) {
653                         Object *ob= base->object;
654                         
655                         /* this flag is from depgraph, was stored in initialize phase, handled in drawview.c */
656                         if(base->flag & BA_HAS_RECALC_OB)
657                                 ob->recalc |= OB_RECALC_OB;
658                         if(base->flag & BA_HAS_RECALC_DATA)
659                                 ob->recalc |= OB_RECALC_DATA;
660                         
661                         /* if object/base is selected */
662                         if ((base->flag & SELECT) || (ob->flag & SELECT)) {
663                                 /* if animtimer is running, and the object already has animation data,
664                                  * check if the auto-record feature means that we should record 'samples'
665                                  * (i.e. uneditable animation values)
666                                  */
667                                 // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
668                                 // TODO: maybe the ob->adt check isn't really needed? makes it too difficult to use...
669                                 if (/*(ob->adt) && */(t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
670                                         autokeyframe_ob_cb_func(t->scene, (View3D *)t->view, ob, t->mode);
671                                 }
672                         }
673                         
674                         /* proxy exception */
675                         if(ob->proxy)
676                                 ob->proxy->recalc |= ob->recalc;
677                         if(ob->proxy_group)
678                                 group_tag_recalc(ob->proxy_group->dup_group);
679                 } 
680         }
681
682         /* update shaded drawmode while transform */
683         if(t->spacetype==SPACE_VIEW3D && ((View3D*)t->view)->drawtype == OB_SHADED)
684                 reshadeall_displist(t->scene);
685 }
686
687 void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)
688 {
689         float v1[3], v2[3], v3[3];
690         char col[3], col2[3];
691         
692         if (t->spacetype == SPACE_VIEW3D)
693         {
694                 View3D *v3d = t->view;
695                 
696                 glPushMatrix();
697                 
698                 //if(t->obedit) glLoadMatrixf(t->obedit->obmat);        // sets opengl viewing
699                 
700         
701                 VecCopyf(v3, dir);
702                 VecMulf(v3, v3d->far);
703                 
704                 VecSubf(v2, center, v3);
705                 VecAddf(v1, center, v3);
706         
707                 if (options & DRAWLIGHT) {
708                         col[0] = col[1] = col[2] = 220;
709                 }
710                 else {
711                         UI_GetThemeColor3ubv(TH_GRID, col);
712                 }
713                 UI_make_axis_color(col, col2, axis);
714                 glColor3ubv((GLubyte *)col2);
715         
716                 setlinestyle(0);
717                 glBegin(GL_LINE_STRIP); 
718                         glVertex3fv(v1); 
719                         glVertex3fv(v2); 
720                 glEnd();
721                 
722                 glPopMatrix();
723         }
724 }
725
726 void resetTransRestrictions(TransInfo *t)
727 {
728         t->flag &= ~T_ALL_RESTRICTIONS;
729 }
730
731 int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
732 {
733         Scene *sce = CTX_data_scene(C);
734         ToolSettings *ts = CTX_data_tool_settings(C);
735         ARegion *ar = CTX_wm_region(C);
736         ScrArea *sa = CTX_wm_area(C);
737         Object *obedit = CTX_data_edit_object(C);
738         
739         /* moving: is shown in drawobject() (transform color) */
740 //  TRANSFORM_FIX_ME    
741 //      if(obedit || (t->flag & T_POSE) ) G.moving= G_TRANSFORM_EDIT;
742 //      else if(G.f & G_PARTICLEEDIT) G.moving= G_TRANSFORM_PARTICLE;
743 //      else G.moving= G_TRANSFORM_OBJ;
744         
745         t->scene = sce;
746         t->sa = sa;
747         t->ar = ar;
748         t->obedit = obedit;
749         t->settings = ts;
750
751         t->data = NULL;
752         t->ext = NULL;
753
754         t->helpline = HLP_NONE;
755
756         t->flag = 0;
757         
758         t->redraw = 1; /* redraw first time */
759         
760         if (event)
761         {
762                 t->imval[0] = event->x - t->ar->winrct.xmin;
763                 t->imval[1] = event->y - t->ar->winrct.ymin;
764                 
765                 t->event_type = event->type;
766         }
767         else
768         {
769                 t->imval[0] = 0;
770                 t->imval[1] = 0;
771         }
772         
773         t->con.imval[0] = t->imval[0];
774         t->con.imval[1] = t->imval[1];
775
776         t->mval[0] = t->imval[0];
777         t->mval[1] = t->imval[1];
778
779         t->transform            = NULL;
780         t->handleEvent          = NULL;
781
782         t->total                        = 0;
783
784         t->val = 0.0f;
785
786         t->vec[0]                       =
787                 t->vec[1]               =
788                 t->vec[2]               = 0.0f;
789         
790         t->center[0]            =
791                 t->center[1]    =
792                 t->center[2]    = 0.0f;
793         
794         Mat3One(t->mat);
795         
796         t->spacetype = sa->spacetype;
797         if(t->spacetype == SPACE_VIEW3D)
798         {
799                 View3D *v3d = sa->spacedata.first;
800                 
801                 t->view = v3d;
802                 t->animtimer= CTX_wm_screen(C)->animtimer;
803                 
804                 if(v3d->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
805                 t->around = v3d->around;
806
807                 if (op && RNA_struct_find_property(op->ptr, "constraint_axis") && RNA_property_is_set(op->ptr, "constraint_orientation"))
808                 {
809                         t->current_orientation = RNA_int_get(op->ptr, "constraint_orientation");
810
811                         if (t->current_orientation >= V3D_MANIP_CUSTOM + BIF_countTransformOrientation(C) - 1)
812                         {
813                                 t->current_orientation = V3D_MANIP_GLOBAL;
814                         }
815                 }
816                 else
817                 {
818                         t->current_orientation = v3d->twmode;
819                 }
820         }
821         else if(t->spacetype==SPACE_IMAGE || t->spacetype==SPACE_NODE)
822         {
823                 SpaceImage *sima = sa->spacedata.first;
824                 // XXX for now, get View2D  from the active region
825                 t->view = &ar->v2d;
826                 t->around = sima->around;
827         }
828         else
829         {
830                 // XXX for now, get View2D  from the active region
831                 t->view = &ar->v2d;
832                 
833                 t->around = V3D_CENTER;
834         }
835
836         if (op && RNA_struct_find_property(op->ptr, "mirror") && RNA_property_is_set(op->ptr, "mirror"))
837         {
838                 if (RNA_boolean_get(op->ptr, "mirror"))
839                 {
840                         t->flag |= T_MIRROR;
841                 }
842         }
843         // Need stuff to take it from edit mesh or whatnot here
844         else
845         {
846                 if (t->obedit && t->obedit->type == OB_MESH && ts->editbutflag & B_MESH_X_MIRROR)
847                 {
848                         t->flag |= T_MIRROR;
849                 }
850         }
851
852         /* setting PET flag */
853         if (op && RNA_struct_find_property(op->ptr, "proportional") && RNA_property_is_set(op->ptr, "proportional"))
854         {
855                 switch(RNA_enum_get(op->ptr, "proportional"))
856                 {
857                 case 2: /* XXX connected constant */
858                         t->flag |= T_PROP_CONNECTED;
859                 case 1: /* XXX prop on constant */
860                         t->flag |= T_PROP_EDIT;
861                         break;
862                 }
863         }
864         else
865         {
866                 if ((t->options & CTX_NO_PET) == 0 && (ts->proportional)) {
867                         t->flag |= T_PROP_EDIT;
868                         
869                         if(ts->proportional == 2)
870                                 t->flag |= T_PROP_CONNECTED;    // yes i know, has to become define
871                 }
872         }
873
874         if (op && RNA_struct_find_property(op->ptr, "proportional_size") && RNA_property_is_set(op->ptr, "proportional_size"))
875         {
876                 t->prop_size = RNA_float_get(op->ptr, "proportional_size");
877         }
878         else
879         {
880                 t->prop_size = ts->proportional_size;
881         }
882         
883         if (op && RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && RNA_property_is_set(op->ptr, "proportional_editing_falloff"))
884         {
885                 t->prop_mode = RNA_enum_get(op->ptr, "proportional_editing_falloff");
886         }
887         else
888         {
889                 t->prop_mode = ts->prop_mode;
890         }
891
892         /* TRANSFORM_FIX_ME rna restrictions */
893         if (t->prop_size <= 0)
894         {
895                 t->prop_size = 1.0f;
896         }
897
898         setTransformViewMatrices(t);
899         initNumInput(&t->num);
900         initNDofInput(&t->ndof);
901         
902         return 1;
903 }
904
905 /* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
906 void postTrans (TransInfo *t) 
907 {
908         TransData *td;
909
910         if (t->draw_handle)
911         {
912                 ED_region_draw_cb_exit(t->ar->type, t->draw_handle);
913         }
914         
915         /* postTrans can be called when nothing is selected, so data is NULL already */
916         if (t->data) {
917                 int a;
918
919                 /* since ipokeys are optional on objects, we mallocced them per trans-data */
920                 for(a=0, td= t->data; a<t->total; a++, td++) {
921                         if(td->tdi) MEM_freeN(td->tdi);
922                         if (td->flag & TD_BEZTRIPLE) MEM_freeN(td->hdata); 
923                 }
924                 MEM_freeN(t->data);
925         }
926
927         if (t->ext) MEM_freeN(t->ext);
928         if (t->data2d) {
929                 MEM_freeN(t->data2d);
930                 t->data2d= NULL;
931         }
932
933         if(t->spacetype==SPACE_IMAGE) {
934                 SpaceImage *sima= t->sa->spacedata.first;
935                 if(sima->flag & SI_LIVE_UNWRAP)
936                         ED_uvedit_live_unwrap_end(t->state == TRANS_CANCEL);
937         }
938         else if(ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA)) {
939                 if (t->customData)
940                         MEM_freeN(t->customData);
941         }
942 }
943
944 void applyTransObjects(TransInfo *t)
945 {
946         TransData *td;
947         
948         for (td = t->data; td < t->data + t->total; td++) {
949                 VECCOPY(td->iloc, td->loc);
950                 if (td->ext->rot) {
951                         VECCOPY(td->ext->irot, td->ext->rot);
952                 }
953                 if (td->ext->size) {
954                         VECCOPY(td->ext->isize, td->ext->size);
955                 }
956         }       
957         recalcData(t);
958
959
960 /* helper for below */
961 static void restore_ipokey(float *poin, float *old)
962 {
963         if(poin) {
964                 poin[0]= old[0];
965                 poin[-3]= old[3];
966                 poin[3]= old[6];
967         }
968 }
969
970 static void restoreElement(TransData *td) {
971         /* TransData for crease has no loc */
972         if (td->loc) {
973                 VECCOPY(td->loc, td->iloc);
974         }
975         if (td->val) {
976                 *td->val = td->ival;
977         }
978         if (td->ext && (td->flag&TD_NO_EXT)==0) {
979                 if (td->ext->rot) {
980                         VECCOPY(td->ext->rot, td->ext->irot);
981                 }
982                 if (td->ext->size) {
983                         VECCOPY(td->ext->size, td->ext->isize);
984                 }
985                 if(td->flag & TD_USEQUAT) {
986                         if (td->ext->quat) {
987                                 QUATCOPY(td->ext->quat, td->ext->iquat);
988                         }
989                 }
990         }
991         
992         if (td->flag & TD_BEZTRIPLE) {
993                 *(td->hdata->h1) = td->hdata->ih1;
994                 *(td->hdata->h2) = td->hdata->ih2;
995         }
996         
997         if(td->tdi) {
998                 TransDataIpokey *tdi= td->tdi;
999                 
1000                 restore_ipokey(tdi->locx, tdi->oldloc);
1001                 restore_ipokey(tdi->locy, tdi->oldloc+1);
1002                 restore_ipokey(tdi->locz, tdi->oldloc+2);
1003
1004                 restore_ipokey(tdi->rotx, tdi->oldrot);
1005                 restore_ipokey(tdi->roty, tdi->oldrot+1);
1006                 restore_ipokey(tdi->rotz, tdi->oldrot+2);
1007                 
1008                 restore_ipokey(tdi->sizex, tdi->oldsize);
1009                 restore_ipokey(tdi->sizey, tdi->oldsize+1);
1010                 restore_ipokey(tdi->sizez, tdi->oldsize+2);
1011         }
1012 }
1013
1014 void restoreTransObjects(TransInfo *t)
1015 {
1016         TransData *td;
1017         
1018         for (td = t->data; td < t->data + t->total; td++) {
1019                 restoreElement(td);
1020         }
1021         
1022         Mat3One(t->mat);
1023         
1024         recalcData(t);
1025 }
1026
1027 void calculateCenter2D(TransInfo *t)
1028 {
1029         if (t->flag & (T_EDIT|T_POSE)) {
1030                 Object *ob= t->obedit?t->obedit:t->poseobj;
1031                 float vec[3];
1032                 
1033                 VECCOPY(vec, t->center);
1034                 Mat4MulVecfl(ob->obmat, vec);
1035                 projectIntView(t, vec, t->center2d);
1036         }
1037         else {
1038                 projectIntView(t, t->center, t->center2d);
1039         }
1040 }
1041
1042 void calculateCenterCursor(TransInfo *t)
1043 {
1044         float *cursor;
1045
1046         cursor = give_cursor(t->scene, t->view);
1047         VECCOPY(t->center, cursor);
1048
1049         /* If edit or pose mode, move cursor in local space */
1050         if (t->flag & (T_EDIT|T_POSE)) {
1051                 Object *ob = t->obedit?t->obedit:t->poseobj;
1052                 float mat[3][3], imat[3][3];
1053                 
1054                 VecSubf(t->center, t->center, ob->obmat[3]);
1055                 Mat3CpyMat4(mat, ob->obmat);
1056                 Mat3Inv(imat, mat);
1057                 Mat3MulVecfl(imat, t->center);
1058         }
1059         
1060         calculateCenter2D(t);
1061 }
1062
1063 void calculateCenterCursor2D(TransInfo *t)
1064 {
1065         View2D *v2d= t->view;
1066         float aspx=1.0, aspy=1.0;
1067         
1068         if(t->spacetype==SPACE_IMAGE) /* only space supported right now but may change */
1069                 ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
1070
1071         if (v2d) {
1072                 t->center[0] = v2d->cursor[0] * aspx; 
1073                 t->center[1] = v2d->cursor[1] * aspy; 
1074         }
1075
1076         calculateCenter2D(t);
1077 }
1078
1079 void calculateCenterMedian(TransInfo *t)
1080 {
1081         float partial[3] = {0.0f, 0.0f, 0.0f};
1082         int total = 0;
1083         int i;
1084         
1085         for(i = 0; i < t->total; i++) {
1086                 if (t->data[i].flag & TD_SELECTED) {
1087                         if (!(t->data[i].flag & TD_NOCENTER))
1088                         {
1089                                 VecAddf(partial, partial, t->data[i].center);
1090                                 total++;
1091                         }
1092                 }
1093                 else {
1094                         /* 
1095                            All the selected elements are at the head of the array 
1096                            which means we can stop when it finds unselected data
1097                         */
1098                         break;
1099                 }
1100         }
1101         if(i)
1102                 VecMulf(partial, 1.0f / total);
1103         VECCOPY(t->center, partial);
1104
1105         calculateCenter2D(t);
1106 }
1107
1108 void calculateCenterBound(TransInfo *t)
1109 {
1110         float max[3];
1111         float min[3];
1112         int i;
1113         for(i = 0; i < t->total; i++) {
1114                 if (i) {
1115                         if (t->data[i].flag & TD_SELECTED) {
1116                                 if (!(t->data[i].flag & TD_NOCENTER))
1117                                         MinMax3(min, max, t->data[i].center);
1118                         }
1119                         else {
1120                                 /* 
1121                                    All the selected elements are at the head of the array 
1122                                    which means we can stop when it finds unselected data
1123                                 */
1124                                 break;
1125                         }
1126                 }
1127                 else {
1128                         VECCOPY(max, t->data[i].center);
1129                         VECCOPY(min, t->data[i].center);
1130                 }
1131         }
1132         VecAddf(t->center, min, max);
1133         VecMulf(t->center, 0.5);
1134
1135         calculateCenter2D(t);
1136 }
1137
1138 void calculateCenter(TransInfo *t) 
1139 {
1140         switch(t->around) {
1141         case V3D_CENTER:
1142                 calculateCenterBound(t);
1143                 break;
1144         case V3D_CENTROID:
1145                 calculateCenterMedian(t);
1146                 break;
1147         case V3D_CURSOR:
1148                 if(t->spacetype==SPACE_IMAGE)
1149                         calculateCenterCursor2D(t);
1150                 else
1151                         calculateCenterCursor(t);
1152                 break;
1153         case V3D_LOCAL:
1154                 /* Individual element center uses median center for helpline and such */
1155                 calculateCenterMedian(t);
1156                 break;
1157         case V3D_ACTIVE:
1158                 {
1159                 /* set median, and if if if... do object center */
1160 #if 0 // TRANSFORM_FIX_ME
1161                 EditSelection ese;
1162                 /* EDIT MODE ACTIVE EDITMODE ELEMENT */
1163
1164                 if (t->obedit && t->obedit->type == OB_MESH && EM_get_actSelection(&ese)) {
1165                         EM_editselection_center(t->center, &ese);
1166                         calculateCenter2D(t);
1167                         break;
1168                 } /* END EDIT MODE ACTIVE ELEMENT */
1169 #endif
1170                 
1171                 calculateCenterMedian(t);
1172                 if((t->flag & (T_EDIT|T_POSE))==0)
1173                 {
1174                         Scene *scene = t->scene;
1175                         Object *ob= OBACT;
1176                         if(ob)
1177                         {
1178                                 VECCOPY(t->center, ob->obmat[3]);
1179                                 projectIntView(t, t->center, t->center2d);
1180                         }
1181                 }
1182                 
1183                 }
1184         }
1185
1186         /* setting constraint center */
1187         VECCOPY(t->con.center, t->center);
1188         if(t->flag & (T_EDIT|T_POSE))
1189         {
1190                 Object *ob= t->obedit?t->obedit:t->poseobj;
1191                 Mat4MulVecfl(ob->obmat, t->con.center);
1192         }
1193
1194         /* voor panning from cameraview */
1195         if(t->flag & T_OBJECT)
1196         {
1197                 if(t->spacetype==SPACE_VIEW3D)
1198                 {
1199                         View3D *v3d = t->view;
1200                         Scene *scene = t->scene;
1201                         RegionView3D *rv3d = t->ar->regiondata;
1202                         
1203                         if(v3d->camera == OBACT && rv3d->persp==V3D_CAMOB)
1204                         {
1205                                 float axis[3];
1206                                 /* persinv is nasty, use viewinv instead, always right */
1207                                 VECCOPY(axis, t->viewinv[2]);
1208                                 Normalize(axis);
1209         
1210                                 /* 6.0 = 6 grid units */
1211                                 axis[0]= t->center[0]- 6.0f*axis[0];
1212                                 axis[1]= t->center[1]- 6.0f*axis[1];
1213                                 axis[2]= t->center[2]- 6.0f*axis[2];
1214                                 
1215                                 projectIntView(t, axis, t->center2d);
1216                                 
1217                                 /* rotate only needs correct 2d center, grab needs initgrabz() value */
1218                                 if(t->mode==TFM_TRANSLATION)
1219                                 {
1220                                         VECCOPY(t->center, axis);
1221                                         VECCOPY(t->con.center, t->center);
1222                                 }
1223                         }
1224                 }
1225         }       
1226
1227         if(t->spacetype==SPACE_VIEW3D)
1228         {
1229                 /* initgrabz() defines a factor for perspective depth correction, used in window_to_3d_delta() */
1230                 if(t->flag & (T_EDIT|T_POSE)) {
1231                         Object *ob= t->obedit?t->obedit:t->poseobj;
1232                         float vec[3];
1233                         
1234                         VECCOPY(vec, t->center);
1235                         Mat4MulVecfl(ob->obmat, vec);
1236                         initgrabz(t->ar->regiondata, vec[0], vec[1], vec[2]);
1237                 }
1238                 else {
1239                         initgrabz(t->ar->regiondata, t->center[0], t->center[1], t->center[2]);
1240                 } 
1241         }
1242 }
1243
1244 void calculatePropRatio(TransInfo *t)
1245 {
1246         TransData *td = t->data;
1247         int i;
1248         float dist;
1249         short connected = t->flag & T_PROP_CONNECTED;
1250         
1251         if (t->flag & T_PROP_EDIT) {
1252                 for(i = 0 ; i < t->total; i++, td++) {
1253                         if (td->flag & TD_SELECTED) {
1254                                 td->factor = 1.0f;
1255                         }
1256                         else if ((connected && 
1257                                                 (td->flag & TD_NOTCONNECTED || td->dist > t->prop_size))
1258                                 ||
1259                                         (connected == 0 &&
1260                                                 td->rdist > t->prop_size)) {
1261                                 /* 
1262                                    The elements are sorted according to their dist member in the array,
1263                                    that means we can stop when it finds one element outside of the propsize.
1264                                 */
1265                                 td->flag |= TD_NOACTION;
1266                                 td->factor = 0.0f;
1267                                 restoreElement(td);
1268                         }
1269                         else {
1270                                 /* Use rdist for falloff calculations, it is the real distance */
1271                                 td->flag &= ~TD_NOACTION;
1272                                 dist= (t->prop_size-td->rdist)/t->prop_size;
1273                                 
1274                                 /*
1275                                  * Clamp to positive numbers.
1276                                  * Certain corner cases with connectivity and individual centers
1277                                  * can give values of rdist larger than propsize.
1278                                  */
1279                                 if (dist < 0.0f)
1280                                         dist = 0.0f;
1281                                 
1282                                 switch(t->prop_mode) {
1283                                 case PROP_SHARP:
1284                                         td->factor= dist*dist;
1285                                         break;
1286                                 case PROP_SMOOTH:
1287                                         td->factor= 3.0f*dist*dist - 2.0f*dist*dist*dist;
1288                                         break;
1289                                 case PROP_ROOT:
1290                                         td->factor = (float)sqrt(dist);
1291                                         break;
1292                                 case PROP_LIN:
1293                                         td->factor = dist;
1294                                         break;
1295                                 case PROP_CONST:
1296                                         td->factor = 1.0f;
1297                                         break;
1298                                 case PROP_SPHERE:
1299                                         td->factor = (float)sqrt(2*dist - dist * dist);
1300                                         break;
1301                                 case PROP_RANDOM:
1302                                         BLI_srand( BLI_rand() ); /* random seed */
1303                                         td->factor = BLI_frand()*dist;
1304                                         break;
1305                                 default:
1306                                         td->factor = 1;
1307                                 }
1308                         }
1309                 }
1310                 switch(t->prop_mode) {
1311                 case PROP_SHARP:
1312                         strcpy(t->proptext, "(Sharp)");
1313                         break;
1314                 case PROP_SMOOTH:
1315                         strcpy(t->proptext, "(Smooth)");
1316                         break;
1317                 case PROP_ROOT:
1318                         strcpy(t->proptext, "(Root)");
1319                         break;
1320                 case PROP_LIN:
1321                         strcpy(t->proptext, "(Linear)");
1322                         break;
1323                 case PROP_CONST:
1324                         strcpy(t->proptext, "(Constant)");
1325                         break;
1326                 case PROP_SPHERE:
1327                         strcpy(t->proptext, "(Sphere)");
1328                         break;
1329                 case PROP_RANDOM:
1330                         strcpy(t->proptext, "(Random)");
1331                         break;
1332                 default:
1333                         strcpy(t->proptext, "");
1334                 }
1335         }
1336         else {
1337                 for(i = 0 ; i < t->total; i++, td++) {
1338                         td->factor = 1.0;
1339                 }
1340                 strcpy(t->proptext, "");
1341         }
1342 }
1343
1344 TransInfo *BIF_GetTransInfo()
1345 {
1346         return NULL;
1347 }
1348
1349 float get_drawsize(ARegion *ar, float *co)
1350 {
1351         RegionView3D *rv3d= ar->regiondata;
1352         float size, vec[3], len1, len2;
1353         
1354         /* size calculus, depending ortho/persp settings, like initgrabz() */
1355         size= rv3d->persmat[0][3]*co[0]+ rv3d->persmat[1][3]*co[1]+ rv3d->persmat[2][3]*co[2]+ rv3d->persmat[3][3];
1356         
1357         VECCOPY(vec, rv3d->persinv[0]);
1358         len1= Normalize(vec);
1359         VECCOPY(vec, rv3d->persinv[1]);
1360         len2= Normalize(vec);
1361         
1362         size*= 0.01f*(len1>len2?len1:len2);
1363
1364         /* correct for window size to make widgets appear fixed size */
1365         if(ar->winx > ar->winy) size*= 1000.0f/(float)ar->winx;
1366         else size*= 1000.0f/(float)ar->winy;
1367
1368         return size;
1369 }