Bugfix #6531
[blender.git] / source / blender / src / buttons_object.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "MEM_guardedalloc.h"
43
44 #include "DNA_ID.h"
45 #include "DNA_screen_types.h"
46 #include "DNA_space_types.h"
47 #include "DNA_scene_types.h"
48
49 #include "BKE_action.h"
50 #include "BKE_global.h"
51 #include "BKE_main.h"
52 #include "BKE_library.h"
53 #include "BKE_softbody.h"
54 #include "BKE_utildefines.h"
55
56 #include "BLI_blenlib.h"
57 #include "BLI_arithb.h"
58
59 #include "BSE_filesel.h"
60 #include "BSE_headerbuttons.h"
61
62 #include "BIF_butspace.h"
63 #include "BIF_editaction.h"
64 #include "BIF_gl.h"
65 #include "BIF_glutil.h"
66 #include "BIF_graphics.h"
67 #include "BIF_interface.h"
68 #include "BIF_keyval.h"
69 #include "BIF_mainqueue.h"
70 #include "BIF_mywindow.h"
71 #include "BIF_poseobject.h"
72 #include "BIF_resources.h"
73 #include "BIF_screen.h"
74 #include "BIF_space.h"
75 #include "BIF_toolbox.h"
76
77 #include "BDR_drawobject.h"
78 #include "BDR_editcurve.h"
79
80 #include "mydevice.h"
81 #include "blendef.h"
82
83 /* -----includes for this file specific----- */
84
85
86 #include "DNA_action_types.h"
87 #include "DNA_armature_types.h"
88 #include "DNA_camera_types.h"
89 #include "DNA_constraint_types.h"
90 #include "DNA_curve_types.h"
91 #include "DNA_effect_types.h"
92 #include "DNA_group_types.h"
93 #include "DNA_image_types.h"
94 #include "DNA_key_types.h"
95 #include "DNA_lamp_types.h"
96 #include "DNA_lattice_types.h"
97 #include "DNA_material_types.h"
98 #include "DNA_meta_types.h"
99 #include "DNA_mesh_types.h"
100 #include "DNA_modifier_types.h"
101 #include "DNA_object_types.h"
102 #include "DNA_object_force.h"
103 #include "DNA_object_fluidsim.h"
104 #include "DNA_radio_types.h"
105 #include "DNA_screen_types.h"
106 #include "DNA_sound_types.h"
107 #include "DNA_texture_types.h"
108 #include "DNA_userdef_types.h"
109 #include "DNA_vfont_types.h"
110 #include "DNA_view3d_types.h"
111 #include "DNA_world_types.h"
112
113 #include "BKE_anim.h"
114 #include "BKE_armature.h"
115 #include "BKE_constraint.h"
116 #include "BKE_curve.h"
117 #include "BKE_deform.h"
118 #include "BKE_depsgraph.h"
119 #include "BKE_displist.h"
120 #include "BKE_effect.h"
121 #include "BKE_font.h"
122 #include "BKE_group.h"
123 #include "BKE_image.h"
124 #include "BKE_ipo.h"
125 #include "BKE_lattice.h"
126 #include "BKE_material.h"
127 #include "BKE_mball.h"
128 #include "BKE_mesh.h"
129 #include "BKE_modifier.h"
130 #include "BKE_object.h"
131 #include "BKE_sound.h"
132 #include "BKE_texture.h"
133 #include "BKE_utildefines.h"
134 #include "BKE_DerivedMesh.h"
135
136 #include "LBM_fluidsim.h"
137 #include "elbeem.h"
138
139 #include "BIF_editconstraint.h"
140 #include "BIF_editdeform.h"
141
142 #include "BSE_editipo.h"
143 #include "BSE_edit.h"
144
145 #include "BDR_editobject.h"
146
147 #include "butspace.h" // own module
148
149 static float prspeed=0.0;
150 float prlen=0.0;
151
152
153 /* ********************* CONSTRAINT ***************************** */
154
155 static void constraint_active_func(void *ob_v, void *con_v)
156 {
157         Object *ob= ob_v;
158         bConstraint *con;
159         ListBase *lb;
160         
161         /* lets be nice and escape if its active already */
162         if(con_v) {
163                 con= con_v;
164                 if(con->flag & CONSTRAINT_ACTIVE) return;
165         }
166         
167         lb= get_active_constraints(ob);
168         
169         for(con= lb->first; con; con= con->next) {
170                 if(con==con_v) con->flag |= CONSTRAINT_ACTIVE;
171                 else con->flag &= ~CONSTRAINT_ACTIVE;
172         }
173
174         /* make sure ipowin and buttons shows it */
175         if(ob->ipowin==ID_CO) {
176                 allqueue(REDRAWIPO, ID_CO);
177                 allspace(REMAKEIPO, 0);
178                 allqueue(REDRAWNLA, 0);
179         }
180         allqueue(REDRAWBUTSOBJECT, 0);
181 }
182
183 static void add_constraint_to_active(Object *ob, bConstraint *con)
184 {
185         ListBase *list;
186         
187         list = get_active_constraints(ob);
188         if (list) {
189                 unique_constraint_name(con, list);
190                 BLI_addtail(list, con);
191                 
192                 con->flag |= CONSTRAINT_ACTIVE;
193                 for(con= con->prev; con; con= con->prev)
194                         con->flag &= ~CONSTRAINT_ACTIVE;
195         }
196 }
197
198 /* returns base ID for Ipo, sets actname to channel if appropriate */
199 /* should not make action... */
200 void get_constraint_ipo_context(void *ob_v, char *actname)
201 {
202         Object *ob= ob_v;
203         
204         /* todo; check object if it has ob-level action ipo */
205         
206         if (ob->flag & OB_POSEMODE) {
207                 bPoseChannel *pchan;
208                 
209                 pchan = get_active_posechannel(ob);
210                 if (pchan) {
211                         BLI_strncpy(actname, pchan->name, 32);
212                 }
213         }
214         else if(ob->ipoflag & OB_ACTION_OB)
215                 strcpy(actname, "Object");
216 }       
217
218 /* initialize UI to show Ipo window and make sure channels etc exist */
219 static void enable_constraint_ipo_func (void *ob_v, void *con_v)
220 {
221         Object *ob= ob_v;
222         bConstraint *con = con_v;
223         char actname[32]="";
224         
225         /* verifies if active constraint is set and shown in UI */
226         constraint_active_func(ob_v, con_v);
227         
228         /* the context */
229         get_constraint_ipo_context(ob, actname);
230         
231         /* adds ipo & channels & curve if needed */
232         verify_ipo((ID *)ob, ID_CO, actname, con->name);
233         
234         /* make sure ipowin shows it */
235         ob->ipowin= ID_CO;
236         allqueue(REDRAWIPO, ID_CO);
237         allspace(REMAKEIPO, 0);
238         allqueue(REDRAWNLA, 0);
239 }
240
241
242 static void add_influence_key_to_constraint_func (void *ob_v, void *con_v)
243 {
244         Object *ob= ob_v;
245         bConstraint *con = con_v;
246         IpoCurve *icu;
247         char actname[32]="";
248         
249         /* verifies if active constraint is set and shown in UI */
250         constraint_active_func(ob_v, con_v);
251         
252         /* the context */
253         get_constraint_ipo_context(ob, actname);
254
255         /* adds ipo & channels & curve if needed */
256         icu= verify_ipocurve((ID *)ob, ID_CO, actname, con->name, CO_ENFORCE);
257
258         if(ob->action)
259                 insert_vert_ipo(icu, get_action_frame(ob, (float)CFRA), con->enforce);
260         else
261                 insert_vert_ipo(icu, CFRA, con->enforce);
262         
263         /* make sure ipowin shows it */
264         ob->ipowin= ID_CO;
265         allqueue(REDRAWIPO, ID_CO);
266         allspace(REMAKEIPO, 0);
267         allqueue(REDRAWNLA, 0);
268         
269         BIF_undo_push("Insert Influence Key");
270 }
271
272 void del_constr_func (void *ob_v, void *con_v)
273 {
274         bConstraint *con= con_v;
275         bConstraintChannel *chan;
276         ListBase *lb;
277         
278         /* remove ipo channel */
279         lb= get_active_constraint_channels(ob_v, 0);
280         if(lb) {
281                 chan = get_constraint_channel(lb, con->name);
282                 if(chan) {
283                         if(chan->ipo) chan->ipo->id.us--;
284                         BLI_freelinkN(lb, chan);
285                 }
286         }
287         /* remove constraint itself */
288         lb= get_active_constraints(ob_v);
289         free_constraint_data (con);
290         BLI_freelinkN(lb, con);
291         
292         constraint_active_func(ob_v, NULL);
293 }
294
295 static void del_constraint_func (void *ob_v, void *con_v)
296 {
297         del_constr_func (ob_v, con_v);
298         BIF_undo_push("Delete constraint");
299         allqueue(REDRAWBUTSOBJECT, 0);
300         allqueue(REDRAWIPO, 0); 
301 }
302
303 static void verify_constraint_name_func (void *con_v, void *name_v)
304 {
305         Object *ob= OBACT;
306         bConstraint *con= con_v;
307         char oldname[32];       
308         
309         if (!con)
310                 return;
311         
312         /* put on the stack */
313         BLI_strncpy(oldname, (char *)name_v, 32);
314         
315         rename_constraint(ob, con, oldname);
316         
317         constraint_active_func(ob, con);
318         allqueue(REDRAWACTION, 0); 
319 }
320
321 void get_constraint_typestring (char *str, void *con_v)
322 {
323         bConstraint *con= con_v;
324
325         switch (con->type){
326         case CONSTRAINT_TYPE_CHILDOF:
327                 strcpy (str, "Child Of");
328                 return;
329         case CONSTRAINT_TYPE_NULL:
330                 strcpy (str, "Null");
331                 return;
332         case CONSTRAINT_TYPE_TRACKTO:
333                 strcpy (str, "Track To");
334                 return;
335         case CONSTRAINT_TYPE_MINMAX:
336                 strcpy (str, "Floor");
337                 return;
338         case CONSTRAINT_TYPE_KINEMATIC:
339                 strcpy (str, "IK Solver");
340                 return;
341         case CONSTRAINT_TYPE_ROTLIKE:
342                 strcpy (str, "Copy Rotation");
343                 return;
344         case CONSTRAINT_TYPE_LOCLIKE:
345                 strcpy (str, "Copy Location");
346                 return;
347         case CONSTRAINT_TYPE_SIZELIKE:
348                 strcpy (str, "Copy Scale");
349                 return;
350         case CONSTRAINT_TYPE_ACTION:
351                 strcpy (str, "Action");
352                 return;
353         case CONSTRAINT_TYPE_LOCKTRACK:
354                 strcpy (str, "Locked Track");
355                 return;
356         case CONSTRAINT_TYPE_FOLLOWPATH:
357                 strcpy (str, "Follow Path");
358                 return;
359         case CONSTRAINT_TYPE_STRETCHTO:
360                 strcpy (str, "Stretch To");
361                 return;
362         case CONSTRAINT_TYPE_LOCLIMIT:
363                 strcpy (str, "Limit Location");
364                 return;
365         case CONSTRAINT_TYPE_ROTLIMIT:
366                 strcpy (str, "Limit Rotation");
367                 return;
368         case CONSTRAINT_TYPE_SIZELIMIT:
369                 strcpy (str, "Limit Scale");
370                 return;
371         case CONSTRAINT_TYPE_RIGIDBODYJOINT:
372                 strcpy (str, "Rigid Body");
373                 return;
374         case CONSTRAINT_TYPE_CLAMPTO:
375                 strcpy (str, "Clamp To");
376                 return;
377         default:
378                 strcpy (str, "Unknown");
379                 return;
380         }
381 }
382
383 static int get_constraint_col(bConstraint *con)
384 {
385         switch (con->type) {
386         case CONSTRAINT_TYPE_NULL:
387                 return TH_BUT_NEUTRAL;
388         case CONSTRAINT_TYPE_KINEMATIC:
389                 return TH_BUT_SETTING2;
390         case CONSTRAINT_TYPE_TRACKTO:
391                 return TH_BUT_SETTING;
392         case CONSTRAINT_TYPE_ROTLIKE:
393                 return TH_BUT_SETTING1;
394         case CONSTRAINT_TYPE_LOCLIKE:
395                 return TH_BUT_POPUP;
396         case CONSTRAINT_TYPE_MINMAX:
397                 return TH_BUT_POPUP;
398         case CONSTRAINT_TYPE_SIZELIKE:
399                 return TH_BUT_POPUP;
400         case CONSTRAINT_TYPE_ACTION:
401                 return TH_BUT_ACTION;
402         case CONSTRAINT_TYPE_LOCKTRACK:
403                 return TH_BUT_SETTING;
404         case CONSTRAINT_TYPE_FOLLOWPATH:
405                 return TH_BUT_SETTING2;
406         case CONSTRAINT_TYPE_STRETCHTO:
407                 return TH_BUT_SETTING;
408         case CONSTRAINT_TYPE_LOCLIMIT:
409                 return TH_BUT_POPUP;
410         case CONSTRAINT_TYPE_ROTLIMIT:
411                 return TH_BUT_POPUP;
412         case CONSTRAINT_TYPE_SIZELIMIT:
413                 return TH_BUT_POPUP;
414         case CONSTRAINT_TYPE_RIGIDBODYJOINT:
415                 return TH_BUT_SETTING;
416         default:
417                 return TH_REDALERT;
418         }
419 }
420
421 void const_moveUp(void *ob_v, void *con_v)
422 {
423         bConstraint *con, *constr= con_v;
424         ListBase *conlist;
425         
426         if(constr->prev) {
427                 conlist = get_active_constraints(ob_v);
428                 for(con= conlist->first; con; con= con->next) {
429                         if(con==constr) {
430                                 BLI_remlink(conlist, con);
431                                 BLI_insertlink(conlist, con->prev->prev, con);
432                                 break;
433                         }
434                 }
435         }
436 }
437
438 static void constraint_moveUp(void *ob_v, void *con_v)
439 {
440         const_moveUp(ob_v, con_v);
441         BIF_undo_push("Move constraint");
442 }
443
444 void const_moveDown(void *ob_v, void *con_v)
445 {
446         bConstraint *con, *constr= con_v;
447         ListBase *conlist;
448         
449         if(constr->next) {
450                 conlist = get_active_constraints(ob_v);
451                 for(con= conlist->first; con; con= con->next) {
452                         if(con==constr) {
453                                 BLI_remlink(conlist, con);
454                                 BLI_insertlink(conlist, con->next, con);
455                                 break;
456                         }
457                 }
458         }
459 }
460
461 static void constraint_moveDown(void *ob_v, void *con_v)
462 {
463         const_moveDown(ob_v, con_v);
464         BIF_undo_push("Move constraint");
465 }
466
467 /* autocomplete callback for  buttons */
468 void autocomplete_bone(char *str, void *arg_v)
469 {
470         Object *ob= (Object *)arg_v;
471         char truncate[40]= {0};
472         
473         if(ob==NULL || ob->pose==NULL) return;
474         
475         /* search if str matches the beginning of name */
476         if(str[0]) {
477                 bPoseChannel *pchan;
478                 
479                 for(pchan= ob->pose->chanbase.first; pchan; pchan= pchan->next) {
480                         int a;
481                         
482                         for(a=0; a<31; a++) {
483                                 if(str[a]==0 || str[a]!=pchan->name[a])
484                                         break;
485                         }
486                         /* found a match */
487                         if(str[a]==0) {
488                                 /* first match */
489                                 if(truncate[0]==0)
490                                         BLI_strncpy(truncate, pchan->name, 32);
491                                 else {
492                                         /* remove from truncate what is not in bone->name */
493                                         for(a=0; a<31; a++) {
494                                                 if(truncate[a]!=pchan->name[a])
495                                                         truncate[a]= 0;
496                                         }
497                                 }
498                         }
499                 }
500                 if(truncate[0])
501                         BLI_strncpy(str, truncate, 32);
502         }
503 }
504
505 /* autocomplete callback for buttons */
506 void autocomplete_vgroup(char *str, void *arg_v)
507 {
508         Object *ob= (Object *)arg_v;
509         char truncate[40]= {0};
510         
511         if(ob==NULL) return;
512         
513         /* search if str matches the beginning of a name */
514         if(str[0]) {
515                 bDeformGroup *dg;
516                 
517                 for(dg= ob->defbase.first; dg; dg= dg->next) {
518                         int a;
519                         if(dg->name==str) continue;
520                         
521                         for(a=0; a<31; a++) {
522                                 if(str[a]==0 || str[a]!=dg->name[a])
523                                         break;
524                         }
525                         /* found a match */
526                         if(str[a]==0) {
527                                 /* first match */
528                                 if(truncate[0]==0)
529                                         BLI_strncpy(truncate, dg->name, 32);
530                                 else {
531                                         /* remove from truncate what is not in bone->name */
532                                         for(a=0; a<31; a++) {
533                                                 if(truncate[a]!=dg->name[a])
534                                                         truncate[a]= 0;
535                                         }
536                                 }
537                         }
538                 }
539                 if(truncate[0])
540                         BLI_strncpy(str, truncate, 32);
541         }
542 }
543
544 static void draw_constraint (uiBlock *block, ListBase *list, bConstraint *con, short *xco, short *yco)
545 {
546         Object *ob= OBACT, *target;
547         uiBut *but;
548         char typestr[64], *subtarget;
549         short height, width = 265, is_armature_target;
550         int curCol, rb_col;
551
552         target= get_constraint_target(con, &subtarget);
553         is_armature_target= (target && target->type==OB_ARMATURE);
554         
555         /* unless button has own callback, it adds this callback to button */
556         uiBlockSetFunc(block, constraint_active_func, ob, con);
557         
558         get_constraint_typestring (typestr, con);
559
560         curCol = get_constraint_col(con);
561
562         /* Draw constraint header */
563         uiBlockSetEmboss(block, UI_EMBOSSN);
564         
565         /* rounded header */
566         rb_col= (con->flag & CONSTRAINT_ACTIVE)?40:20;
567         uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-1, width+40, 22, NULL, 5.0, 0.0, 
568                          (con->flag & CONSTRAINT_EXPAND)?3:15 , rb_col-20, ""); 
569         
570         /* open/close */
571         uiDefIconButBitS(block, ICONTOG, CONSTRAINT_EXPAND, B_CONSTRAINT_TEST, ICON_DISCLOSURE_TRI_RIGHT, *xco-10, *yco, 20, 20, &con->flag, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Constraint");
572         
573         /* up down */
574         uiBlockSetEmboss(block, UI_EMBOSS);
575         but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_UP, *xco+width-50, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier up in stack");
576         uiButSetFunc(but, constraint_moveUp, ob, con);
577         
578         but = uiDefIconBut(block, BUT, B_CONSTRAINT_TEST, VICON_MOVE_DOWN, *xco+width-50+20, *yco, 16, 18, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier down in stack");
579         uiButSetFunc(but, constraint_moveDown, ob, con);
580         
581         if (con->flag & CONSTRAINT_EXPAND) {
582                 
583                 if (con->flag & CONSTRAINT_DISABLE) {
584                         BIF_ThemeColor(TH_REDALERT);
585                         uiBlockSetCol(block, TH_REDALERT);
586                 }
587                 else {
588                         BIF_ThemeColor(curCol);
589                 }
590
591                 /*if (type==TARGET_BONE)
592                         but = uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Bone Constraint%t|Track To%x2|IK Solver%x3|Copy Rotation%x8|Copy Location%x9|Action%x12|Null%x0", *xco+20, *yco, 100, 20, &con->type, 0.0, 0.0, 0.0, 0.0, "Constraint type"); 
593                 else
594                         but = uiDefButC(block, MENU, B_CONSTRAINT_TEST, "Object Constraint%t|Track To%x2|Copy Rotation%x8|Copy Location%x9|Null%x0", *xco+20, *yco, 100, 20, &con->type, 0.0, 0.0, 0.0, 0.0, "Constraint type"); 
595                 */
596                 uiBlockSetEmboss(block, UI_EMBOSS);
597                 
598                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
599                 
600                 but = uiDefBut(block, TEX, B_CONSTRAINT_TEST, "", *xco+120, *yco, 85, 18, con->name, 0.0, 29.0, 0.0, 0.0, "Constraint name"); 
601                 uiButSetFunc(but, verify_constraint_name_func, con, NULL);
602         }       
603         else {
604                 uiBlockSetEmboss(block, UI_EMBOSSN);
605
606                 if (con->flag & CONSTRAINT_DISABLE) {
607                         uiBlockSetCol(block, TH_REDALERT);
608                         BIF_ThemeColor(TH_REDALERT);
609                 }
610                 else {
611                         BIF_ThemeColor(curCol);
612                 }
613                 
614                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, typestr, *xco+10, *yco, 100, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
615                 
616                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, con->name, *xco+120, *yco-1, 135, 19, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
617         }
618
619         uiBlockSetCol(block, TH_AUTO);  
620         
621         uiBlockSetEmboss(block, UI_EMBOSSN);
622         
623         but = uiDefIconBut(block, BUT, B_CONSTRAINT_CHANGETARGET, ICON_X, *xco+262, *yco, 19, 19, list, 0.0, 0.0, 0.0, 0.0, "Delete constraint");
624         uiButSetFunc(but, del_constraint_func, ob, con);
625
626         uiBlockSetEmboss(block, UI_EMBOSS);
627
628
629         /* Draw constraint data*/
630         if (!(con->flag & CONSTRAINT_EXPAND)) {
631                 (*yco)-=21;
632         }
633         else {
634                 switch (con->type){
635                 case CONSTRAINT_TYPE_ACTION:
636                         {
637                                 bActionConstraint *data = con->data;
638
639                                 height = 88;
640                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
641                                 
642                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
643
644                                 /* Draw target parameters */
645                                 uiBlockBeginAlign(block);
646                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
647
648                                 if (is_armature_target){
649                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
650                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
651                                 }
652                                 else {
653                                         strcpy (data->subtarget, "");
654                                 }
655                                 
656                                 uiBlockEndAlign(block);
657
658                                 /* Draw action button */
659                                 uiBlockBeginAlign(block);
660                                 uiDefButS(block, TOG, B_CONSTRAINT_TEST, "Local",                                               *xco+((width/2)-117), *yco-46, 78, 18, &data->local, 0, 0, 0, 0, "Use true local rotation difference");
661                                 uiDefIDPoinBut(block, test_actionpoin_but, ID_AC, B_CONSTRAINT_TEST, "AC:",     *xco+((width/2)-117), *yco-64, 78, 18, &data->act, "Action containing the keyed motion for this bone"); 
662                                 uiDefButS(block, MENU, B_CONSTRAINT_TEST, "Key on%t|X Rot%x0|Y Rot%x1|Z Rot%x2", *xco+((width/2)-117), *yco-84, 78, 18, &data->type, 0, 24, 0, 0, "Specify which transformation channel from the target is used to key the action");
663
664                                 uiBlockBeginAlign(block);
665                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "Start:", *xco+((width/2)-36), *yco-64, 78, 18, &data->start, 1, MAXFRAME, 0.0, 0.0, "Starting frame of the keyed motion"); 
666                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "End:", *xco+((width/2)-36), *yco-84, 78, 18, &data->end, 1, MAXFRAME, 0.0, 0.0, "Ending frame of the keyed motion"); 
667                                 
668                                 uiBlockBeginAlign(block);
669                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Min:", *xco+((width/2)+45), *yco-64, 78, 18, &data->min, -180, 180, 0, 0, "Minimum value for target channel range");
670                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Max:", *xco+((width/2)+45), *yco-84, 78, 18, &data->max, -180, 180, 0, 0, "Maximum value for target channel range");
671                                 uiBlockEndAlign(block);
672                         }
673                         break;
674                 case CONSTRAINT_TYPE_LOCLIKE:
675                         {
676                                 bLocateLikeConstraint *data = con->data;
677                                 
678                                 height = 91;
679                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
680
681                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
682
683                                 /* Draw target parameters */
684                                 uiBlockBeginAlign(block);
685                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
686
687                                 if (is_armature_target) {
688                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
689                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
690                                 }
691                                 else {
692                                         strcpy (data->subtarget, "");
693                                 }
694                                 
695                                 uiBlockEndAlign(block);
696                                 
697                                 /* Draw XYZ toggles */
698                                 uiBlockBeginAlign(block);
699                                 but=uiDefButBitI(block, TOG, LOCLIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
700                                 but=uiDefButBitI(block, TOG, LOCLIKE_X_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert X component");
701                                 but=uiDefButBitI(block, TOG, LOCLIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
702                                 but=uiDefButBitI(block, TOG, LOCLIKE_Y_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Y component");
703                                 but=uiDefButBitI(block, TOG, LOCLIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+96), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
704                                 but=uiDefButBitI(block, TOG, LOCLIKE_Z_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+128), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Z component");
705                                 uiBlockEndAlign(block);
706                                 
707                                 /* Draw options */
708                                 uiDefButBitI(block, TOG, LOCLIKE_OFFSET, B_CONSTRAINT_TEST, "Offset", *xco+(width/3), *yco-89, (width/3), 18, &data->flag, 0, 24, 0, 0, "Add original location onto copied location");
709                                 if (is_armature_target) {
710                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco, *yco-89, (width/3), 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
711                                         uiDefButBitI(block, TOG, LOCLIKE_TIP, B_CONSTRAINT_TEST, "Target Bone Tip", *xco+(width/3*2), *yco-89, (width/3), 18, &data->flag, 0, 24, 0, 0, "Copy Location of Target Bone's Tip");
712                                 }
713                         }
714                         break;
715                 case CONSTRAINT_TYPE_ROTLIKE:
716                         {
717                                 bRotateLikeConstraint *data = con->data;
718                                 
719                                 height = 91;
720                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
721                                 
722                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
723
724                                 /* Draw target parameters */
725                                 uiBlockBeginAlign(block);
726                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
727
728                                 if (is_armature_target) {
729                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
730                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
731                                 }
732                                 else {
733                                         strcpy (data->subtarget, "");
734                                 }
735                                 
736                                 uiBlockEndAlign(block);
737                                 
738                                 /* Draw XYZ toggles */
739                                 uiBlockBeginAlign(block);
740                                 if (is_armature_target)          
741                     uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+((width/2)-98), *yco-64, 50, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
742                                 but=uiDefButBitI(block, TOG, ROTLIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
743                                 but=uiDefButBitI(block, TOG, ROTLIKE_X_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert X component");
744                                 but=uiDefButBitI(block, TOG, ROTLIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
745                                 but=uiDefButBitI(block, TOG, ROTLIKE_Y_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Y component");
746                                 but=uiDefButBitI(block, TOG, ROTLIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+96), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
747                                 but=uiDefButBitI(block, TOG, ROTLIKE_Z_INVERT, B_CONSTRAINT_TEST, "-", *xco+((width/2)+128), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Invert Z component");
748                                 uiBlockEndAlign(block);
749                         }
750                         break;
751                 case CONSTRAINT_TYPE_SIZELIKE:
752                         {
753                                 bSizeLikeConstraint *data = con->data;
754                                 height = 91;
755                         
756                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
757
758                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
759
760                                 /* Draw target parameters */
761                                 uiBlockBeginAlign(block);
762                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
763                                 
764                                 if (is_armature_target) {
765                                         but= uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
766                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
767                                 }
768                                 else {
769                                         strcpy (data->subtarget, "");
770                                 }
771                                 
772                                 uiBlockEndAlign(block);
773
774                                 /* Draw XYZ toggles */
775                                 uiBlockBeginAlign(block);
776                                 if (is_armature_target)
777                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+((width/2)-98), *yco-64, 50, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
778                                 but=uiDefButBitI(block, TOG, SIZELIKE_X, B_CONSTRAINT_TEST, "X", *xco+((width/2)-48), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy X component");
779                                 but=uiDefButBitI(block, TOG, SIZELIKE_Y, B_CONSTRAINT_TEST, "Y", *xco+((width/2)-16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Y component");
780                                 but=uiDefButBitI(block, TOG, SIZELIKE_Z, B_CONSTRAINT_TEST, "Z", *xco+((width/2)+16), *yco-64, 32, 18, &data->flag, 0, 24, 0, 0, "Copy Z component");
781                                 uiBlockEndAlign(block);
782                         }
783                         break;
784                 case CONSTRAINT_TYPE_KINEMATIC:
785                         {
786                                 bKinematicConstraint *data = con->data;
787                                 
788                                 height = 111;
789                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
790                                 
791                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
792
793                                 /* Draw target parameters */
794                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_ROT, B_CONSTRAINT_TEST, "Rot", *xco, *yco-24,60,19, &data->flag, 0, 0, 0, 0, "Chain follows rotation of target");
795                                 
796                                 uiBlockBeginAlign(block);
797                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 19, &data->tar, "Target Object"); 
798
799                                 if (is_armature_target) {
800                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,19, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
801                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
802                                 }
803                                 else {
804                                         strcpy (data->subtarget, "");
805                                 }
806         
807                                 uiBlockBeginAlign(block);
808                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_TIP, B_CONSTRAINT_TEST, "Use Tip", *xco, *yco-64, 137, 19, &data->flag, 0, 0, 0, 0, "Include Bone's tip als last element in Chain");
809                                 uiDefButI(block, NUM, B_CONSTRAINT_TEST, "ChainLen:", *xco, *yco-84,137,19, &data->rootbone, 0, 255, 0, 0, "If not zero, the amount of bones in this chain");
810                                 
811                                 uiBlockBeginAlign(block);
812                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "PosW ", *xco+147, *yco-64, 137, 19, &data->weight, 0.01, 1.0, 2, 2, "For Tree-IK: weight of position control for this target");
813                                 uiDefButF(block, NUMSLI, B_CONSTRAINT_TEST, "RotW ", *xco+147, *yco-84, 137, 19, &data->orientweight, 0.01, 1.0, 2, 2, "For Tree-IK: Weight of orientation control for this target");
814
815                                 uiBlockBeginAlign(block);
816                                 uiDefButS(block, NUM, B_CONSTRAINT_TEST, "Iterations:", *xco, *yco-109, 137, 19, &data->iterations, 1, 10000, 0, 0, "Maximum number of solving iterations"); 
817                                 uiBlockBeginAlign(block);
818                                 uiDefButBitS(block, TOG, CONSTRAINT_IK_STRETCH, B_CONSTRAINT_TEST, "Stretch", *xco+147, *yco-109,137,19, &data->flag, 0, 0, 0, 0, "Enable IK stretching");
819                                 
820                         }
821                         break;
822                 case CONSTRAINT_TYPE_TRACKTO:
823                         {
824                                 bTrackToConstraint *data = con->data;
825
826                                 height = 66;
827                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
828                                 
829                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
830
831                                 /* Draw target parameters */
832                                 uiBlockBeginAlign(block);
833                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
834
835                                 if (is_armature_target) {
836                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
837                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
838                                 }
839                                 else {
840                                         strcpy (data->subtarget, "");
841                                 }
842                                 
843                                 uiBlockEndAlign(block);
844
845                                 uiBlockBeginAlign(block);
846                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Align:", *xco+5, *yco-42, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
847
848                                 uiDefButBitI(block, TOG, 1, B_CONSTRAINT_TEST, "TargetZ", *xco+60, *yco-42, 50, 18, &data->flags, 0, 1, 0, 0, "Target Z axis, not world Z axis, will constrain up direction");
849                                 uiBlockEndAlign(block);
850
851                                 uiBlockBeginAlign(block);
852                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
853                                 
854                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+39, *yco-64,17,18, &data->reserved1, 12.0, 0.0, 0, 0, "X axis points to the target object");
855                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+56, *yco-64,17,18, &data->reserved1, 12.0, 1.0, 0, 0, "Y axis points to the target object");
856                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+73, *yco-64,17,18, &data->reserved1, 12.0, 2.0, 0, 0, "Z axis points to the target object");
857                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-X",    *xco+90, *yco-64,24,18, &data->reserved1, 12.0, 3.0, 0, 0, "-X axis points to the target object");
858                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Y",    *xco+114, *yco-64,24,18, &data->reserved1, 12.0, 4.0, 0, 0, "-Y axis points to the target object");
859                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Z",    *xco+138, *yco-64,24,18, &data->reserved1, 12.0, 5.0, 0, 0, "-Z axis points to the target object");
860                                 uiBlockEndAlign(block);
861                                 
862                                 uiBlockBeginAlign(block);
863                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
864                                 
865                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+204, *yco-64,17,18, &data->reserved2, 13.0, 0.0, 0, 0, "X axis points upward");
866                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+221, *yco-64,17,18, &data->reserved2, 13.0, 1.0, 0, 0, "Y axis points upward");
867                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+238, *yco-64,17,18, &data->reserved2, 13.0, 2.0, 0, 0, "Z axis points upward");
868                                 uiBlockEndAlign(block);
869                         }
870                         break;
871                 case CONSTRAINT_TYPE_MINMAX:
872                         {
873                                 bMinMaxConstraint *data = con->data;
874
875                                 height = 66;
876                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
877                                 
878                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
879
880                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Offset:", *xco, *yco-44, 100, 18, &data->offset, -100, 100, 100.0, 0.0, "Offset from the position of the object center"); 
881
882                                 /* Draw target parameters */
883                                 uiBlockBeginAlign(block);
884                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
885
886                                 if (is_armature_target) {
887                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
888                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
889                                 }
890                                 else {
891                                         strcpy (data->subtarget, "");
892                                 }
893                                 
894                                 uiBlockEndAlign(block);
895
896                                 but=uiDefButI(block, TOG|BIT|0, B_CONSTRAINT_TEST, "Sticky", *xco, *yco-24, 44, 18, &data->flag, 0, 24, 0, 0, "Immobilize object while constrained");
897                                 but=uiDefButI(block, TOG|BIT|2, B_CONSTRAINT_TEST, "Use Rot", *xco+44, *yco-24, 64, 18, &data->flag, 0, 24, 0, 0, "Use target object rotation");
898                                 
899                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Max/Min:", *xco-8, *yco-64, 54, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
900
901                                 uiBlockBeginAlign(block);                       
902                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+51, *yco-64,17,18, &data->minmaxflag, 12.0, 0.0, 0, 0, "Will not pass below X of target");
903                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+67, *yco-64,17,18, &data->minmaxflag, 12.0, 1.0, 0, 0, "Will not pass below Y of target");
904                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+85, *yco-64,17,18, &data->minmaxflag, 12.0, 2.0, 0, 0, "Will not pass below Z of target");
905                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-X",    *xco+102, *yco-64,24,18, &data->minmaxflag, 12.0, 3.0, 0, 0, "Will not pass above X of target");
906                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Y",    *xco+126, *yco-64,24,18, &data->minmaxflag, 12.0, 4.0, 0, 0, "Will not pass above Y of target");
907                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Z",    *xco+150, *yco-64,24,18, &data->minmaxflag, 12.0, 5.0, 0, 0, "Will not pass above Z of target");
908                                 uiBlockEndAlign(block);
909                         }
910                         break;
911                 case CONSTRAINT_TYPE_LOCKTRACK:
912                         {
913                                 bLockTrackConstraint *data = con->data;
914                                 height = 66;
915                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
916
917                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
918
919                                 /* Draw target parameters */
920                                 uiBlockBeginAlign(block);
921                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
922
923                                 if (is_armature_target) {
924                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
925                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
926                                 }
927                                 else {
928                                         strcpy (data->subtarget, "");
929                                 }
930                                 
931                                 uiBlockEndAlign(block);
932                                 
933                                 uiBlockBeginAlign(block);
934                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "To:", *xco+12, *yco-64, 25, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
935                                 
936                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+39, *yco-64,17,18, &data->trackflag, 12.0, 0.0, 0, 0, "X axis points to the target object");
937                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+56, *yco-64,17,18, &data->trackflag, 12.0, 1.0, 0, 0, "Y axis points to the target object");
938                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+73, *yco-64,17,18, &data->trackflag, 12.0, 2.0, 0, 0, "Z axis points to the target object");
939                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-X",    *xco+90, *yco-64,24,18, &data->trackflag, 12.0, 3.0, 0, 0, "-X axis points to the target object");
940                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Y",    *xco+114, *yco-64,24,18, &data->trackflag, 12.0, 4.0, 0, 0, "-Y axis points to the target object");
941                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Z",    *xco+138, *yco-64,24,18, &data->trackflag, 12.0, 5.0, 0, 0, "-Z axis points to the target object");
942                                 uiBlockEndAlign(block);
943                                 
944                                 uiBlockBeginAlign(block);
945                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Lock:", *xco+166, *yco-64, 38, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
946                                 
947                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+204, *yco-64,17,18, &data->lockflag, 13.0, 0.0, 0, 0, "X axis is locked");
948                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+221, *yco-64,17,18, &data->lockflag, 13.0, 1.0, 0, 0, "Y axis is locked");
949                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+238, *yco-64,17,18, &data->lockflag, 13.0, 2.0, 0, 0, "Z axis is locked");
950                                 uiBlockEndAlign(block);
951                         }
952                         break;
953                 case CONSTRAINT_TYPE_FOLLOWPATH:
954                         {
955                                 bFollowPathConstraint *data = con->data;
956
957                                 height = 66;
958                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
959                                 
960                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
961
962                                 /* Draw target parameters */
963                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
964                                 
965                                 /* Draw Curve Follow toggle */
966                                 but=uiDefButBitI(block, TOG, 1, B_CONSTRAINT_TEST, "CurveFollow", *xco+39, *yco-44, 100, 18, &data->followflag, 0, 24, 0, 0, "Object will follow the heading and banking of the curve");
967
968                                 /* Draw Offset number button */
969                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Offset:", *xco+155, *yco-44, 100, 18, &data->offset, -MAXFRAMEF, MAXFRAMEF, 100.0, 0.0, "Offset from the position corresponding to the time frame"); 
970
971                                 uiBlockBeginAlign(block);
972                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Fw:", *xco+12, *yco-64, 27, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
973                                 
974                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+39, *yco-64,17,18, &data->trackflag, 12.0, 0.0, 0, 0, "The axis that points forward along the path");
975                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+56, *yco-64,17,18, &data->trackflag, 12.0, 1.0, 0, 0, "The axis that points forward along the path");
976                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+73, *yco-64,17,18, &data->trackflag, 12.0, 2.0, 0, 0, "The axis that points forward along the path");
977                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-X",    *xco+90, *yco-64,24,18, &data->trackflag, 12.0, 3.0, 0, 0, "The axis that points forward along the path");
978                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Y",    *xco+114, *yco-64,24,18, &data->trackflag, 12.0, 4.0, 0, 0, "The axis that points forward along the path");
979                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"-Z",    *xco+138, *yco-64,24,18, &data->trackflag, 12.0, 5.0, 0, 0, "The axis that points forward along the path");
980                                 uiBlockEndAlign(block);
981                                 
982                                 uiBlockBeginAlign(block);
983                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Up:", *xco+174, *yco-64, 30, 18, NULL, 0.0, 0.0, 0.0, 0.0, "");
984                                 
985                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",     *xco+204, *yco-64,17,18, &data->upflag, 13.0, 0.0, 0, 0, "The axis that points upward");
986                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Y",     *xco+221, *yco-64,17,18, &data->upflag, 13.0, 1.0, 0, 0, "The axis that points upward");
987                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",     *xco+238, *yco-64,17,18, &data->upflag, 13.0, 2.0, 0, 0, "The axis that points upward");
988                                 uiBlockEndAlign(block);
989                         }
990                         break;
991                 case CONSTRAINT_TYPE_STRETCHTO:
992                         {
993                                 bStretchToConstraint *data = con->data;
994                                 
995                                 height = 105;
996                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
997                                 
998                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
999
1000                                 /* Draw target parameters */
1001                                 uiBlockBeginAlign(block);
1002                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1003
1004                                 if (is_armature_target) {
1005                                         but=uiDefBut(block, TEX, B_CONSTRAINT_CHANGETARGET, "BO:", *xco+120, *yco-42,135,18, &data->subtarget, 0, 24, 0, 0, "Subtarget Bone");
1006                                         uiButSetCompleteFunc(but, autocomplete_bone, (void *)data->tar);
1007                                 }
1008                                 else {
1009                                         strcpy (data->subtarget, "");
1010                                 }
1011                                 
1012                                 uiBlockEndAlign(block);
1013
1014                                 
1015                                 uiBlockBeginAlign(block);
1016                                 uiDefButF(block,BUTM,B_CONSTRAINT_TEST,"R",*xco, *yco-60,20,18,&(data->orglength),0.0,0,0,0,"Recalculate RLength");
1017                                 uiDefButF(block,NUM,B_CONSTRAINT_TEST,"Rest Length:",*xco+18, *yco-60,237,18,&(data->orglength),0.0,100,0.5,0.5,"Length at Rest Position");
1018                                 uiBlockEndAlign(block);
1019
1020                                 uiDefButF(block,NUM,B_CONSTRAINT_TEST,"Volume Variation:",*xco+18, *yco-82,237,18,&(data->bulge),0.0,100,0.5,0.5,"Factor between volume variation and stretching");
1021
1022                                 uiBlockBeginAlign(block);
1023                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Vol:",*xco+14, *yco-104,30,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1024                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"XZ",     *xco+44, *yco-104,30,18, &data->volmode, 12.0, 0.0, 0, 0, "Keep Volume: Scaling X & Z");
1025                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",      *xco+74, *yco-104,20,18, &data->volmode, 12.0, 1.0, 0, 0, "Keep Volume: Scaling X");
1026                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",      *xco+94, *yco-104,20,18, &data->volmode, 12.0, 2.0, 0, 0, "Keep Volume: Scaling Z");
1027                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"NONE", *xco+114, *yco-104,50,18, &data->volmode, 12.0, 3.0, 0, 0, "Ignore Volume");
1028                                 uiBlockEndAlign(block);
1029
1030                                 
1031                                 uiBlockBeginAlign(block);
1032                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Plane:",*xco+175, *yco-104,40,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1033                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"X",       *xco+215, *yco-104,20,18, &data->plane, 12.0, 0.0, 0, 0, "Keep X axis");
1034                                 uiDefButI(block, ROW,B_CONSTRAINT_TEST,"Z",       *xco+235, *yco-104,20,18, &data->plane, 12.0, 2.0, 0, 0, "Keep Z axis");
1035                                 uiBlockEndAlign(block);
1036                                 }
1037                         break;
1038                 case CONSTRAINT_TYPE_LOCLIMIT:
1039                         {
1040                                 bLocLimitConstraint *data = con->data;
1041                                 
1042                                 int togButWidth = 50;
1043                                 int textButWidth = ((width/2)-togButWidth);
1044                                 
1045                                 height = 106; 
1046                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1047                                 
1048                                 /* Draw Pairs of LimitToggle+LimitValue */
1049                                 uiBlockBeginAlign(block); 
1050                                 uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1051                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-28, (textButWidth-5), 18, &(data->xmin), -1000, 1000, 0.1,0.5,"Lowest x value to allow"); 
1052                                 uiBlockEndAlign(block); 
1053                                 
1054                                 uiBlockBeginAlign(block); 
1055                                 uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "maxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-28, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum x value"); 
1056                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-28, (textButWidth-5), 18, &(data->xmax), -1000, 1000, 0.1,0.5,"Highest x value to allow"); 
1057                                 uiBlockEndAlign(block); 
1058                                 
1059                                 uiBlockBeginAlign(block); 
1060                                 uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1061                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-50, (textButWidth-5), 18, &(data->ymin), -1000, 1000, 0.1,0.5,"Lowest y value to allow"); 
1062                                 uiBlockEndAlign(block);
1063                                 
1064                                 uiBlockBeginAlign(block); 
1065                                 uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "maxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-50, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum y value"); 
1066                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-50, (textButWidth-5), 18, &(data->ymax), -1000, 1000, 0.1,0.5,"Highest y value to allow"); 
1067                                 uiBlockEndAlign(block); 
1068                                 
1069                                 uiBlockBeginAlign(block); 
1070                                 uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1071                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-72, (textButWidth-5), 18, &(data->zmin), -1000, 1000, 0.1,0.5,"Lowest z value to allow"); 
1072                                 uiBlockEndAlign(block);
1073                                 
1074                                 uiBlockBeginAlign(block); 
1075                                 uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "maxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-72, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum z value"); 
1076                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-72, (textButWidth-5), 18, &(data->zmax), -1000, 1000, 0.1,0.5,"Highest z value to allow"); 
1077                                 uiBlockEndAlign(block);
1078                                 
1079                                 uiBlockBeginAlign(block);
1080                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Co-ordinate Space:",*xco, *yco-100,150,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1081                                 
1082                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE))
1083                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &con->flag, 0, 24, 0, 0, "Limit locations relative to the bone's rest-position");
1084                                 else if (ob->parent != NULL)
1085                                         uiDefButBitS(block, TOG, LIMIT_NOPARENT, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &data->flag2, 0, 24, 0, 0, "Limit locations relative to parent, not origin/world");
1086                                 else 
1087                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"World",*xco+160, *yco-100,60,18, NULL, 0.0, 0.0, 0.0, 0.0, "Limit locations relative to origin/world"); 
1088                                 
1089                                 uiBlockEndAlign(block);
1090                         }
1091                         break;
1092                 case CONSTRAINT_TYPE_ROTLIMIT:
1093                         {
1094                                 bRotLimitConstraint *data = con->data;
1095                                 int normButWidth = (width/3);
1096                                 
1097                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE))
1098                                         height = 106; 
1099                                 else
1100                                         height = 78;
1101                                 
1102                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1103                                 
1104                                 /* Draw Pairs of LimitToggle+LimitValue */
1105                                 uiBlockBeginAlign(block); 
1106                                 uiDefButBitS(block, TOG, LIMIT_XROT, B_CONSTRAINT_TEST, "LimitX", *xco, *yco-28, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on x-axis"); 
1107                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-28, normButWidth, 18, &(data->xmin), -360, 360, 0.1,0.5,"Lowest x value to allow"); 
1108                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-28, normButWidth, 18, &(data->xmax), -360, 360, 0.1,0.5,"Highest x value to allow"); 
1109                                 uiBlockEndAlign(block); 
1110                                 
1111                                 uiBlockBeginAlign(block); 
1112                                 uiDefButBitS(block, TOG, LIMIT_YROT, B_CONSTRAINT_TEST, "LimitY", *xco, *yco-50, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on y-axis"); 
1113                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-50, normButWidth, 18, &(data->ymin), -360, 360, 0.1,0.5,"Lowest y value to allow"); 
1114                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-50, normButWidth, 18, &(data->ymax), -360, 360, 0.1,0.5,"Highest y value to allow"); 
1115                                 uiBlockEndAlign(block); 
1116                                 
1117                                 uiBlockBeginAlign(block); 
1118                                 uiDefButBitS(block, TOG, LIMIT_ZROT, B_CONSTRAINT_TEST, "LimitZ", *xco, *yco-72, normButWidth, 18, &data->flag, 0, 24, 0, 0, "Limit rotation on z-axis"); 
1119                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "min:", *xco+normButWidth, *yco-72, normButWidth, 18, &(data->zmin), -360, 360, 0.1,0.5,"Lowest z value to allow"); 
1120                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "max:", *xco+(normButWidth * 2), *yco-72, normButWidth, 18, &(data->zmax), -360, 360, 0.1,0.5,"Highest z value to allow"); 
1121                                 uiBlockEndAlign(block); 
1122                                 
1123                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE)) {
1124                                         uiBlockBeginAlign(block);
1125                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Co-ordinate Space:",*xco, *yco-100,150,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1126                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
1127                                         uiBlockEndAlign(block);
1128                                 }
1129                         }
1130                         break;
1131                 case CONSTRAINT_TYPE_SIZELIMIT:
1132                         {
1133                                 bSizeLimitConstraint *data = con->data;
1134                                 
1135                                 int togButWidth = 50;
1136                                 int textButWidth = ((width/2)-togButWidth);
1137                                 
1138                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE))
1139                                         height = 106; 
1140                                 else
1141                                         height = 78;
1142                                         
1143                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1144                                 
1145                                 /* Draw Pairs of LimitToggle+LimitValue */
1146                                 uiBlockBeginAlign(block); 
1147                                 uiDefButBitS(block, TOG, LIMIT_XMIN, B_CONSTRAINT_TEST, "minX", *xco, *yco-28, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x value"); 
1148                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-28, (textButWidth-5), 18, &(data->xmin), 0.0001, 1000, 0.1,0.5,"Lowest x value to allow"); 
1149                                 uiBlockEndAlign(block); 
1150
1151                                 uiBlockBeginAlign(block); 
1152                                 uiDefButBitS(block, TOG, LIMIT_XMAX, B_CONSTRAINT_TEST, "maxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-28, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum x value"); 
1153                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-28, (textButWidth-5), 18, &(data->xmax), 0.0001, 1000, 0.1,0.5,"Highest x value to allow"); 
1154                                 uiBlockEndAlign(block); 
1155
1156
1157                                 uiBlockBeginAlign(block); 
1158                                 uiDefButBitS(block, TOG, LIMIT_YMIN, B_CONSTRAINT_TEST, "minY", *xco, *yco-50, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y value"); 
1159                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-50, (textButWidth-5), 18, &(data->ymin), 0.0001, 1000, 0.1,0.5,"Lowest y value to allow"); 
1160                                 uiBlockEndAlign(block); 
1161
1162                                 uiBlockBeginAlign(block); 
1163                                 uiDefButBitS(block, TOG, LIMIT_YMAX, B_CONSTRAINT_TEST, "maxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-50, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum y value"); 
1164                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-50, (textButWidth-5), 18, &(data->ymax), 0.0001, 1000, 0.1,0.5,"Highest y value to allow"); 
1165                                 uiBlockEndAlign(block); 
1166
1167
1168                                 uiBlockBeginAlign(block); 
1169                                 uiDefButBitS(block, TOG, LIMIT_ZMIN, B_CONSTRAINT_TEST, "minZ", *xco, *yco-72, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z value"); 
1170                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-72, (textButWidth-5), 18, &(data->zmin), 0.0001, 1000, 0.1,0.5,"Lowest z value to allow"); 
1171                                 uiBlockEndAlign(block); 
1172
1173                                 uiBlockBeginAlign(block); 
1174                                 uiDefButBitS(block, TOG, LIMIT_ZMAX, B_CONSTRAINT_TEST, "maxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-72, 50, 18, &data->flag, 0, 24, 0, 0, "Use maximum z value"); 
1175                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-72, (textButWidth-5), 18, &(data->zmax), 0.0001, 1000, 0.1,0.5,"Highest z value to allow"); 
1176                                 uiBlockEndAlign(block);
1177                                 
1178                                 if (ob->type == OB_ARMATURE && (ob->flag & OB_POSEMODE)) {
1179                                         uiBlockBeginAlign(block);
1180                                         uiDefBut(block, LABEL, B_CONSTRAINT_TEST,"Co-ordinate Space:",*xco, *yco-100,150,18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1181                                         uiDefButBitS(block, TOG, CONSTRAINT_LOCAL, B_CONSTRAINT_TEST, "Local", *xco+160, *yco-100, 60, 18, &con->flag, 0, 24, 0, 0, "Work on a Pose's local transform");
1182                                         uiBlockEndAlign(block);
1183                                 }
1184                         }
1185                         break;
1186                 case CONSTRAINT_TYPE_RIGIDBODYJOINT:
1187                         {
1188                                 bRigidBodyJointConstraint *data = con->data;
1189                                 float extremeLin = 999.f;
1190                                 float extremeAngX = 180.f;
1191                                 float extremeAngY = 45.f;
1192                                 float extremeAngZ = 45.f;
1193                                 int togButWidth = 70;
1194                                 int offsetY = 150;
1195                                 int textButWidth = ((width/2)-togButWidth);
1196
1197                                 uiDefButI(block, MENU, B_CONSTRAINT_TEST, "Joint Types%t|Ball%x1|Hinge%x2|Generic (experimental)%x12",//|Extra Force%x6",
1198                                                                                                 *xco, *yco-25, 150, 18, &data->type, 0, 0, 0, 0, "Choose the joint type");
1199                 height = 140;
1200                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF)
1201                                         height = 270;
1202                                 
1203                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, "");
1204
1205                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "toObject:", *xco, *yco-50, 130, 18, &data->tar, "Child Object");
1206                                 uiDefButBitS(block, TOG, CONSTRAINT_DRAW_PIVOT, B_CONSTRAINT_TEST, "ShowPivot", *xco+135, *yco-50, 130, 18, &data->flag, 0, 24, 0, 0, "Show pivot position and rotation");                              
1207
1208                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot X:", *xco, *yco-75, 130, 18, &data->pivX, -1000, 1000, 100, 0.0, "Offset pivot on X");
1209                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Y:", *xco, *yco-100, 130, 18, &data->pivY, -1000, 1000, 100, 0.0, "Offset pivot on Y");
1210                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Pivot Z:", *xco, *yco-125, 130, 18, &data->pivZ, -1000, 1000, 100, 0.0, "Offset pivot on z");
1211                                 
1212                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax X:", *xco+135, *yco-75, 130, 18, &data->axX, -360, 360, 1500, 0.0, "Rotate pivot on X Axis (in degrees)");
1213                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Y:", *xco+135, *yco-100, 130, 18, &data->axY, -360, 360, 1500, 0.0, "Rotate pivot on Y Axis (in degrees)");
1214                                 uiDefButF(block, NUM, B_CONSTRAINT_TEST, "Ax Z:", *xco+135, *yco-125, 130, 18, &data->axZ, -360, 360, 1500, 0.0, "Rotate pivot on Z Axis (in degrees)");
1215                                 
1216                                 if (data->type==CONSTRAINT_RB_GENERIC6DOF){
1217                                         /* Draw Pairs of LimitToggle+LimitValue */
1218                                         uiBlockBeginAlign(block); 
1219                                         uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1220                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"min x limit"); 
1221
1222                                         uiBlockBeginAlign(block); 
1223                                         uiDefButBitS(block, TOG, 1, B_CONSTRAINT_TEST, "LinMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
1224                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[0]), -extremeLin, extremeLin, 0.1,0.5,"max x limit"); 
1225
1226                                         offsetY += 20;
1227                                         uiBlockBeginAlign(block); 
1228                                         uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1229                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"min y limit"); 
1230
1231                                         uiBlockBeginAlign(block); 
1232                                         uiDefButBitS(block, TOG, 2, B_CONSTRAINT_TEST, "LinMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
1233                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[1]), -extremeLin, extremeLin, 0.1,0.5,"max y limit"); 
1234
1235                                         offsetY += 20;
1236                                         uiBlockBeginAlign(block); 
1237                                         uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1238                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"min z limit"); 
1239
1240                                         uiBlockBeginAlign(block); 
1241                                         uiDefButBitS(block, TOG, 4, B_CONSTRAINT_TEST, "LinMaxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
1242                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[2]), -extremeLin, extremeLin, 0.1,0.5,"max z limit"); 
1243                                         offsetY += 20;
1244                         
1245                                         /* Draw Pairs of LimitToggle+LimitValue */
1246                                         uiBlockBeginAlign(block); 
1247                                         uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMinX", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum x limit"); 
1248                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"min x limit"); 
1249                                         uiBlockBeginAlign(block); 
1250                                         uiDefButBitS(block, TOG, 8, B_CONSTRAINT_TEST, "AngMaxX", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum x limit"); 
1251                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[3]), -extremeAngX, extremeAngX, 0.1,0.5,"max x limit"); 
1252
1253                                         offsetY += 20;
1254                                         uiBlockBeginAlign(block); 
1255                                         uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMinY", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum y limit"); 
1256                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"min y limit"); 
1257
1258                                         uiBlockBeginAlign(block); 
1259                                         uiDefButBitS(block, TOG, 16, B_CONSTRAINT_TEST, "AngMaxY", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum y limit"); 
1260                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[4]), -extremeAngY, extremeAngY, 0.1,0.5,"max y limit"); 
1261
1262                                         offsetY += 20;
1263                                         uiBlockBeginAlign(block); 
1264                                         uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMinZ", *xco, *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use minimum z limit"); 
1265                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+togButWidth, *yco-offsetY, (textButWidth-5), 18, &(data->minLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"min z limit"); 
1266
1267                                         uiBlockBeginAlign(block); 
1268                                         uiDefButBitS(block, TOG, 32, B_CONSTRAINT_TEST, "AngMaxZ", *xco+(width-(textButWidth-5)-togButWidth), *yco-offsetY, togButWidth, 18, &data->flag, 0, 24, 0, 0, "Use maximum z limit"); 
1269                                         uiDefButF(block, NUM, B_CONSTRAINT_TEST, "", *xco+(width-textButWidth-5), *yco-offsetY, (textButWidth), 18, &(data->maxLimit[5]), -extremeAngZ, extremeAngZ, 0.1,0.5,"max z limit"); 
1270                                         uiBlockEndAlign(block);
1271                                 }
1272                         }
1273                         break;
1274                 case CONSTRAINT_TYPE_CLAMPTO:
1275                         {
1276                                 bClampToConstraint *data = con->data;
1277                                 
1278                                 height = 66;
1279                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1280                                 
1281                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Target:", *xco+65, *yco-24, 50, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1282
1283                                 /* Draw target parameters */
1284                                 uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_CONSTRAINT_CHANGETARGET, "OB:", *xco+120, *yco-24, 135, 18, &data->tar, "Target Object"); 
1285                                 
1286                                 /* Draw XYZ toggles */
1287                                 uiBlockBeginAlign(block);
1288                                 uiDefBut(block, LABEL, B_CONSTRAINT_TEST, "Main Axis:", *xco, *yco-64, 90, 18, NULL, 0.0, 0.0, 0.0, 0.0, ""); 
1289                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Auto", *xco+100, *yco-64, 50, 18, &data->flag, 12.0, CLAMPTO_AUTO, 0, 0, "Automatically determine main-axis of movement");
1290                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "X", *xco+150, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_X, 0, 0, "Main axis of movement is x-axis");
1291                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Y", *xco+182, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_Y, 0, 0, "Main axis of movement is y-axis");
1292                                 uiDefButI(block, ROW, B_CONSTRAINT_TEST, "Z", *xco+214, *yco-64, 32, 18, &data->flag, 12.0, CLAMPTO_Z, 0, 0, "Main axis of movement is z-axis");
1293                                 uiBlockEndAlign(block);
1294                         }
1295                         break;
1296                 case CONSTRAINT_TYPE_NULL:
1297                         {
1298                                 height = 17;
1299                                 uiDefBut(block, ROUNDBOX, B_DIFF, "", *xco-10, *yco-height, width+40,height-1, NULL, 5.0, 0.0, 12, rb_col, ""); 
1300                                 
1301                         }
1302                         break;
1303                 default:
1304                         height = 0;
1305                         break;
1306                 }
1307
1308                 (*yco)-=(24+height);
1309         }
1310
1311         if ((con->type != CONSTRAINT_TYPE_NULL) && (con->type!=CONSTRAINT_TYPE_RIGIDBODYJOINT)) {
1312                 uiBlockBeginAlign(block);
1313                 uiDefButF(block, NUMSLI, B_CONSTRAINT_INF, "Influence ", *xco, *yco, 197, 20, &(con->enforce), 0.0, 1.0, 0.0, 0.0, "Amount of influence this constraint will have on the final solution");
1314                 but = uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Show", *xco+200, *yco, 45, 20, 0, 0.0, 1.0, 0.0, 0.0, "Show constraint's ipo in the Ipo window, adds a channel if not there");
1315                 /* If this is on an object or bone, add ipo channel the constraint */
1316                 uiButSetFunc (but, enable_constraint_ipo_func, ob, con);
1317                 but = uiDefBut(block, BUT, B_CONSTRAINT_TEST, "Key", *xco+245, *yco, 40, 20, 0, 0.0, 1.0, 0.0, 0.0, "Add an influence keyframe to the constraint");
1318                 /* Add a keyframe to the influence IPO */
1319                 uiButSetFunc (but, add_influence_key_to_constraint_func, ob, con);
1320                 uiBlockEndAlign(block);
1321                 (*yco)-=24;
1322         } 
1323         else {
1324                 (*yco)-=3;
1325         }
1326 }
1327
1328 static uiBlock *add_constraintmenu(void *arg_unused)
1329 {
1330         Object *ob= OBACT;
1331         uiBlock *block;
1332         ListBase *conlist;
1333         short yco= 0;
1334         
1335         conlist = get_active_constraints(ob);
1336         
1337         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1338
1339         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIKE,"Copy Location",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1340         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIKE,"Copy Rotation",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1341         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIKE,"Copy Scale",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1342         
1343         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1344         
1345         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCLIMIT,"Limit Location",               0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1346         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ROTLIMIT,"Limit Rotation",               0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1347         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_SIZELIMIT,"Limit Scale",                 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1348         
1349         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1350         
1351         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_TRACKTO,"Track To",              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1352         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_MINMAX,"Floor",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1353         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_LOCKTRACK,"Locked Track",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1354         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_FOLLOWPATH,"Follow Path",                0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1355         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_CLAMPTO,"Clamp To",              0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1356         
1357         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1358         
1359         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_STRETCHTO,"Stretch To",          0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1360
1361         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_RIGIDBODYJOINT,"Rigid Body Joint", 0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");//rcruiz
1362
1363         if (ob->flag & OB_POSEMODE) {
1364                 uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1365                 
1366                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_KINEMATIC,"IK Solver",           0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1367                 uiDefBut(block, BUTM, B_CONSTRAINT_ADD_ACTION,"Action",         0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1368                 
1369         }
1370         uiDefBut(block, SEPR, 0, "",                                    0, yco-=6, 120, 6, NULL, 0.0, 0.0, 0, 0, "");
1371
1372         uiDefBut(block, BUTM, B_CONSTRAINT_ADD_NULL,"Null",             0, yco-=20, 160, 19, NULL, 0.0, 0.0, 1, 0, "");
1373         
1374         uiTextBoundsBlock(block, 50);
1375         uiBlockSetDirection(block, UI_DOWN);
1376                 
1377         return block;
1378 }
1379
1380 void do_constraintbuts(unsigned short event)
1381 {
1382         Object *ob= OBACT;
1383         
1384         switch(event) {
1385         case B_CONSTRAINT_TEST:
1386                 break;  // no handling
1387         case B_CONSTRAINT_INF:
1388                 /* influence; do not execute actions for 1 dag_flush */
1389                 if(ob->pose)
1390                         ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK);
1391
1392         case B_CONSTRAINT_CHANGETARGET:
1393                 if(ob->pose) ob->pose->flag |= POSE_RECALC;     // checks & sorts pose channels
1394                 DAG_scene_sort(G.scene);
1395                 break;
1396                 
1397         case B_CONSTRAINT_ADD_NULL:
1398                 {
1399                         bConstraint *con;
1400                         
1401                         con = add_new_constraint(CONSTRAINT_TYPE_NULL);
1402                         add_constraint_to_active(ob, con);
1403
1404                         BIF_undo_push("Add constraint");
1405                 }
1406                 break;
1407         case B_CONSTRAINT_ADD_KINEMATIC:
1408                 {
1409                         bConstraint *con;
1410                         
1411                         con = add_new_constraint(CONSTRAINT_TYPE_KINEMATIC);
1412                         add_constraint_to_active(ob, con);
1413
1414                         BIF_undo_push("Add constraint");
1415                 }
1416                 break;
1417         case B_CONSTRAINT_ADD_TRACKTO:
1418                 {
1419                         bConstraint *con;
1420
1421                         con = add_new_constraint(CONSTRAINT_TYPE_TRACKTO);
1422                         add_constraint_to_active(ob, con);
1423
1424                         BIF_undo_push("Add constraint");
1425                 }
1426                 break;
1427         case B_CONSTRAINT_ADD_MINMAX:
1428                 {
1429                         bConstraint *con;
1430
1431                         con = add_new_constraint(CONSTRAINT_TYPE_MINMAX);
1432                         add_constraint_to_active(ob, con);
1433
1434                         BIF_undo_push("Add constraint");
1435                 }
1436                 break;
1437         case B_CONSTRAINT_ADD_ROTLIKE:
1438                 {
1439                         bConstraint *con;
1440
1441                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIKE);
1442                         add_constraint_to_active(ob, con);
1443
1444                         BIF_undo_push("Add constraint");
1445                 }
1446                 break;
1447         case B_CONSTRAINT_ADD_LOCLIKE:
1448                 {
1449                         bConstraint *con;
1450
1451                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIKE);
1452                         add_constraint_to_active(ob, con);
1453
1454                         BIF_undo_push("Add constraint");
1455                 }
1456                 break;
1457         case B_CONSTRAINT_ADD_SIZELIKE:
1458                 {
1459                         bConstraint *con;
1460  
1461                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIKE);
1462                         add_constraint_to_active(ob, con);
1463   
1464                         BIF_undo_push("Add constraint");
1465                 }
1466                 break;
1467         case B_CONSTRAINT_ADD_ACTION:
1468                 {
1469                         bConstraint *con;
1470
1471                         con = add_new_constraint(CONSTRAINT_TYPE_ACTION);
1472                         add_constraint_to_active(ob, con);
1473
1474                         BIF_undo_push("Add constraint");
1475                 }
1476                 break;
1477         case B_CONSTRAINT_ADD_LOCKTRACK:
1478                 {
1479                         bConstraint *con;
1480
1481                         con = add_new_constraint(CONSTRAINT_TYPE_LOCKTRACK);
1482                         add_constraint_to_active(ob, con);
1483
1484                         BIF_undo_push("Add constraint");
1485                 }
1486                 break;
1487         case B_CONSTRAINT_ADD_FOLLOWPATH:
1488                 {
1489                         bConstraint *con;
1490
1491                         con = add_new_constraint(CONSTRAINT_TYPE_FOLLOWPATH);
1492                         add_constraint_to_active(ob, con);
1493
1494                 }
1495                 break;
1496         case B_CONSTRAINT_ADD_STRETCHTO:
1497                 {
1498                         bConstraint *con;
1499                         con = add_new_constraint(CONSTRAINT_TYPE_STRETCHTO);
1500                         add_constraint_to_active(ob, con);
1501                                 
1502                         BIF_undo_push("Add constraint");
1503                 }
1504                 break;
1505         case B_CONSTRAINT_ADD_LOCLIMIT:
1506                 {
1507                         bConstraint *con;
1508
1509                         con = add_new_constraint(CONSTRAINT_TYPE_LOCLIMIT);
1510                         add_constraint_to_active(ob, con);
1511
1512                         BIF_undo_push("Add constraint");
1513                 }
1514                 break;
1515         case B_CONSTRAINT_ADD_ROTLIMIT:
1516                 {
1517                         bConstraint *con;
1518
1519                         con = add_new_constraint(CONSTRAINT_TYPE_ROTLIMIT);
1520                         add_constraint_to_active(ob, con);
1521
1522                         BIF_undo_push("Add constraint");
1523                 }
1524                 break;
1525         case B_CONSTRAINT_ADD_SIZELIMIT:
1526                 {
1527                         bConstraint *con;
1528
1529                         con = add_new_constraint(CONSTRAINT_TYPE_SIZELIMIT);
1530                         add_constraint_to_active(ob, con);
1531
1532                         BIF_undo_push("Add constraint");
1533                 }
1534                 break;
1535         case B_CONSTRAINT_ADD_RIGIDBODYJOINT:
1536                 {
1537                         bConstraint *con;
1538                         con = add_new_constraint(CONSTRAINT_TYPE_RIGIDBODYJOINT);
1539                         add_constraint_to_active(ob, con);
1540
1541                         BIF_undo_push("Add constraint");
1542                 }
1543                 break;
1544         case B_CONSTRAINT_ADD_CLAMPTO:
1545                 {
1546                         bConstraint *con;
1547                         con = add_new_constraint(CONSTRAINT_TYPE_CLAMPTO);
1548                         add_constraint_to_active(ob, con);
1549
1550                         BIF_undo_push("Add constraint");
1551                 }
1552                 break;
1553
1554         default:
1555                 break;
1556         }
1557
1558         object_test_constraints(ob);
1559         
1560         if(ob->pose) update_pose_constraint_flags(ob->pose);
1561         
1562         if(ob->type==OB_ARMATURE) DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA|OB_RECALC_OB);
1563         else DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1564         
1565         allqueue (REDRAWVIEW3D, 0);
1566         allqueue (REDRAWBUTSOBJECT, 0);
1567 }
1568
1569 void softbody_bake(Object *ob)
1570 {
1571         Base *base;
1572         SoftBody *sb;
1573         ScrArea *sa;
1574         float frameleno= G.scene->r.framelen;
1575         int cfrao= CFRA, sfra=100000, efra=0, didbreak =0;
1576         
1577         
1578         G.scene->r.framelen= 1.0;               // baking has to be in uncorrected time
1579         sbSetInterruptCallBack(blender_test_break); // make softbody module ESC aware
1580         G.afbreek=0; // init global break system
1581         
1582         if(ob) {
1583                 sb= ob->soft;
1584                 sfra= MIN2(sfra, sb->sfra);
1585                 efra= MAX2(efra, sb->efra);
1586                 sbObjectToSoftbody(ob); // put softbody in restposition, free bake
1587                 ob->softflag |= OB_SB_BAKEDO;
1588         }
1589         else {
1590                 for(base=G.scene->base.first; base; base= base->next) {
1591                         if(TESTBASE(base)) {
1592                                 if(base->object->soft) {
1593                                         sb= base->object->soft;
1594                                         sfra= MIN2(sfra, sb->sfra);
1595                                         efra= MAX2(efra, sb->efra);
1596                                         sbObjectToSoftbody(base->object);       // put softbody in restposition, free bake
1597                                         base->object->softflag |= OB_SB_BAKEDO;
1598                                 }
1599                         }
1600                 }
1601         }
1602         
1603         CFRA= sfra;
1604         update_for_newframe_muted();    // put everything on this frame
1605         
1606         curarea->win_swap= 0;           // clean swapbuffers
1607         
1608         for(; CFRA <= efra; CFRA++) {
1609                 set_timecursor(CFRA);
1610                 
1611                 update_for_newframe_muted();
1612                 
1613                 for(sa= G.curscreen->areabase.first; sa; sa= sa->next) {
1614                         if(sa->spacetype == SPACE_VIEW3D) {
1615                                 scrarea_do_windraw(sa);
1616                         }
1617                 }
1618                 screen_swapbuffers();
1619                 //blender_test_break() has a granularity of 10 ms, who cares .. baking the unit cube is kinda boring
1620                 if (blender_test_break()){ 
1621                         didbreak = 1;
1622                         break;
1623                 }
1624
1625         }
1626         if((didbreak)&&(G.qual!=LR_SHIFTKEY)) {
1627                 if(ob) 
1628                         sbObjectToSoftbody(ob); // free bake
1629                 else {
1630                         for(base=G.scene->base.first; base; base= base->next) {
1631                                 if(TESTBASE(base)) {
1632                                         if(base->object->soft) {
1633                                                 sbObjectToSoftbody(base->object);       // free bake
1634                                         }
1635                                 }
1636                         }
1637                 }
1638         }
1639         
1640         /* restore */
1641         waitcursor(0);
1642         sbSetInterruptCallBack(NULL); // softbody module won't ESC
1643         G.afbreek=0; // reset global break system
1644         
1645         if(ob) 
1646                 ob->softflag &= ~OB_SB_BAKEDO;
1647         else {
1648                 for(base=G.scene->base.first; base; base= base->next)
1649                         if(TESTBASE(base))
1650                                 if(base->object->soft)
1651                                         base->object->softflag &= ~OB_SB_BAKEDO;
1652         }
1653         
1654         CFRA= cfrao;
1655         G.scene->r.framelen= frameleno;
1656         update_for_newframe_muted();
1657         allqueue(REDRAWVIEW3D, 0);
1658         allqueue(REDRAWBUTSOBJECT, 0);
1659 }
1660
1661 // store processed path & file prefix for fluidsim bake directory
1662 void fluidsimFilesel(char *selection)
1663 {
1664         Object *ob = OBACT;
1665         char srcDir[FILE_MAXDIR+FILE_MAXFILE], srcFile[FILE_MAXFILE];
1666         char prefix[FILE_MAXFILE];
1667         char *srch, *srchSub, *srchExt, *lastFound;
1668         int isElbeemSurf = 0;
1669
1670         // make prefix
1671         strcpy(srcDir, selection);
1672         BLI_splitdirstring(srcDir, srcFile);
1673         strcpy(prefix, srcFile);
1674         // check if this is a previously generated surface mesh file
1675         srch = strstr(prefix, "fluidsurface_");
1676         // TODO search from back...
1677         if(srch) {
1678                 srchSub = strstr(prefix,"_preview_");
1679                 if(!srchSub) srchSub = strstr(prefix,"_final_");
1680                 srchExt = strstr(prefix,".gz.bobj");
1681                 if(!srchExt) srchExt = strstr(prefix,".bobj");
1682                 if(srchSub && srchExt) {
1683                         *srch = '\0';
1684                         isElbeemSurf = 1;
1685                 }
1686         }
1687         if(!isElbeemSurf) {
1688                 // try to remove suffix
1689                 lastFound = NULL;
1690                 srch = strchr(prefix, '.'); // search last . from extension
1691                 while(srch) {
1692                         lastFound = srch;
1693                         if(srch) {
1694                                 srch++;
1695                                 srch = strchr(srch, '.');
1696                         }
1697                 }
1698                 if(lastFound) {
1699                         *lastFound = '\0';
1700                 } 
1701         }
1702
1703         if(ob->fluidsimSettings) {
1704                 strcpy(ob->fluidsimSettings->surfdataPath, srcDir);
1705                 //not necessary? strcat(ob->fluidsimSettings->surfdataPath, "/");
1706                 strcat(ob->fluidsimSettings->surfdataPath, prefix);
1707
1708                 // redraw view & buttons...
1709                 allqueue(REDRAWBUTSOBJECT, 0);
1710                 allqueue(REDRAWVIEW3D, 0);
1711                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1712         }
1713 }
1714
1715 void do_object_panels(unsigned short event)
1716 {
1717         Object *ob;
1718         Effect *eff;
1719         
1720         ob= OBACT;
1721         if(ob==NULL)
1722                 return;
1723         
1724         switch(event) {
1725         case B_TRACKBUTS:
1726                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
1727                 allqueue(REDRAWVIEW3D, 0);
1728                 break;
1729         case B_RECALCPATH:
1730                 DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
1731                 allqueue(REDRAWVIEW3D, 0);
1732                 break;
1733         case B_DUPLI_FRAME:
1734                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFACES|OB_DUPLIGROUP);
1735                 allqueue(REDRAWVIEW3D, 0);
1736                 allqueue(REDRAWBUTSOBJECT, 0);
1737                 break;
1738         case B_DUPLI_VERTS:
1739                 ob->transflag &= ~(OB_DUPLIFRAMES|OB_DUPLIFACES|OB_DUPLIGROUP);
1740                 DAG_scene_sort(G.scene);
1741                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1742                 allqueue(REDRAWVIEW3D, 0);
1743                 allqueue(REDRAWBUTSOBJECT, 0);
1744                 break;
1745         case B_DUPLI_FACES:
1746                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIGROUP);
1747                 allqueue(REDRAWVIEW3D, 0);
1748                 allqueue(REDRAWBUTSOBJECT, 0);
1749                 break;
1750         case B_DUPLI_GROUP:
1751                 ob->transflag &= ~(OB_DUPLIVERTS|OB_DUPLIFRAMES|OB_DUPLIFACES);
1752                 allqueue(REDRAWVIEW3D, 0);
1753                 allqueue(REDRAWBUTSOBJECT, 0);
1754                 break;
1755                 
1756         case B_PRINTSPEED:
1757                 {
1758                         float vec[3];
1759                         CFRA++;
1760                         do_ob_ipo(ob);
1761                         where_is_object(ob);
1762                         VECCOPY(vec, ob->obmat[3]);
1763                         CFRA--;
1764                         do_ob_ipo(ob);
1765                         where_is_object(ob);
1766                         VecSubf(vec, vec, ob->obmat[3]);
1767                         prspeed= Normalize(vec);
1768                         scrarea_queue_winredraw(curarea);
1769                 }
1770                 break;
1771         case B_PRINTLEN:
1772                 if(ob->type==OB_CURVE) {
1773                         Curve *cu=ob->data;
1774                         
1775                         if(cu->path) prlen= cu->path->totdist; else prlen= -1.0;
1776                         scrarea_queue_winredraw(curarea);
1777                 } 
1778                 break;
1779         case B_RELKEY:
1780                 allspace(REMAKEIPO, 0);
1781                 allqueue(REDRAWBUTSOBJECT, 0);
1782                 allqueue(REDRAWBUTSEDIT, 0);
1783                 allqueue(REDRAWIPO, 0);
1784                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1785                 break;
1786         case B_CURVECHECK:
1787                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1788                 allqueue(REDRAWVIEW3D, 0);
1789                 break;
1790         
1791         case B_SOFTBODY_CHANGE:
1792                 ob->softflag |= OB_SB_REDO;
1793                 allqueue(REDRAWBUTSOBJECT, 0);
1794                 allqueue(REDRAWVIEW3D, 0);
1795                 break;
1796         case B_SOFTBODY_DEL_VG:
1797                 if(ob->soft) {
1798                         ob->soft->vertgroup= 0;
1799                         ob->softflag |= OB_SB_REDO;
1800                         allqueue(REDRAWBUTSOBJECT, 0);
1801                         allqueue(REDRAWVIEW3D, 0);
1802                 }
1803                 break;
1804         case B_SOFTBODY_BAKE:
1805                 if(ob->soft) softbody_bake(ob);
1806                 break;
1807         case B_SOFTBODY_BAKE_FREE:
1808                 if(ob->soft) sbObjectToSoftbody(ob);
1809                 allqueue(REDRAWBUTSOBJECT, 0);
1810                 allqueue(REDRAWVIEW3D, 0);
1811                 break;
1812         case B_FLUIDSIM_BAKE:
1813                 /* write config files (currently no simulation) */
1814                 fluidsimBake(ob);
1815                 break;
1816         case B_FLUIDSIM_MAKEPART:
1817                 {
1818                         PartEff *paf= NULL;
1819                         /* prepare fluidsim particle display */
1820                         // simplified delete effect, create new - recalc some particles...
1821                         if(ob==NULL || ob->type!=OB_MESH) break;
1822                         ob->fluidsimSettings->type = 0;
1823                         // reset type, and init particle system once normally
1824                         paf= give_parteff(ob); 
1825                         if( (BLI_countlist(&ob->effect)<MAX_EFFECT) && 
1826                             (!paf)) { 
1827                                 // create new entry
1828                                 copy_act_effect(ob); DAG_scene_sort(G.scene); }
1829                         paf = give_parteff(ob);
1830                         if(paf) {
1831                                 paf->totpart = 1000; paf->sta = paf->end = 1.0; // generate some particles...
1832                                 build_particle_system(ob);
1833                                 ob->fluidsimSettings->type = OB_FLUIDSIM_PARTICLE;
1834                         }
1835                 }
1836                 allqueue(REDRAWVIEW3D, 0);
1837                 allqueue(REDRAWBUTSOBJECT, 0);
1838                 break;
1839         case B_FLUIDSIM_SELDIR: 
1840                 {
1841                         ScrArea *sa = closest_bigger_area();
1842                         /* choose dir for surface files */
1843                         areawinset(sa->win);
1844                         activate_fileselect(FILE_SPECIAL, "Select Directory", ob->fluidsimSettings->surfdataPath, fluidsimFilesel);
1845                 }
1846                 break;
1847         case B_FLUIDSIM_FORCEREDRAW:
1848                 /* force redraw */
1849                 allqueue(REDRAWBUTSOBJECT, 0);
1850                 allqueue(REDRAWVIEW3D, 0);
1851                 DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
1852                 break;
1853         case B_GROUP_RELINK:
1854                 group_relink_nla_objects(ob);
1855                 allqueue(REDRAWVIEW3D, 0);
1856                 break;
1857                 
1858         default:
1859                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
1860                         int a=B_SELEFFECT;
1861                         
1862                         eff= ob->effect.first;
1863                         while(eff) {
1864                                 if(event==a) eff->flag |= SELECT;
1865                                 else eff->flag &= ~SELECT;
1866                                 
1867                                 a++;
1868                                 eff= eff->next;
1869                         }
1870                         allqueue(REDRAWBUTSOBJECT, 0);
1871                 }
1872         }
1873
1874 }
1875
1876 static void do_add_groupmenu(void *arg, int event)
1877 {
1878         Object *ob= OBACT;
1879         
1880         if(ob) {
1881                 
1882                 if(event== -1) {
1883                         Group *group= add_group( "Group" );
1884                         add_to_group(group, ob);
1885                 }
1886                 else
1887                         add_to_group(BLI_findlink(&G.main->group, event), ob);
1888                         
1889                 ob->flag |= OB_FROMGROUP;
1890                 BASACT->flag |= OB_FROMGROUP;
1891                 allqueue(REDRAWBUTSOBJECT, 0);
1892                 allqueue(REDRAWVIEW3D, 0);
1893         }               
1894 }
1895
1896 static uiBlock *add_groupmenu(void *arg_unused)
1897 {
1898         uiBlock *block;
1899         Group *group;
1900         short yco= 0;
1901         char str[32];
1902         
1903         block= uiNewBlock(&curarea->uiblocks, "add_constraintmenu", UI_EMBOSSP, UI_HELV, curarea->win);
1904         uiBlockSetButmFunc(block, do_add_groupmenu, NULL);
1905
1906         uiDefBut(block, BUTM, B_NOP, "ADD NEW",         0, 20, 160, 19, NULL, 0.0, 0.0, 1, -1, "");
1907         for(group= G.main->group.first; group; group= group->id.next, yco++) {
1908                 if(group->id.lib) strcpy(str, "L  ");
1909                 else strcpy(str, "   ");
1910                 strcat(str, group->id.name+2);
1911                 uiDefBut(block, BUTM, B_NOP, str,       0, -20*yco, 160, 19, NULL, 0.0, 0.0, 1, yco, "");
1912         }
1913         
1914         uiTextBoundsBlock(block, 50);
1915         uiBlockSetDirection(block, UI_DOWN);    
1916         
1917         return block;
1918 }
1919
1920 static void group_ob_rem(void *gr_v, void *ob_v)
1921 {
1922         Object *ob= OBACT;
1923         
1924         rem_from_group(gr_v, ob);
1925         if(find_group(ob)==NULL) {
1926                 ob->flag &= ~OB_FROMGROUP;
1927                 BASACT->flag &= ~OB_FROMGROUP;
1928         }
1929         allqueue(REDRAWBUTSOBJECT, 0);
1930         allqueue(REDRAWVIEW3D, 0);
1931
1932 }
1933
1934 static void group_local(void *gr_v, void *unused)
1935 {
1936         Group *group= gr_v;
1937         
1938         group->id.lib= NULL;
1939         
1940         allqueue(REDRAWBUTSOBJECT, 0);
1941         allqueue(REDRAWVIEW3D, 0);
1942         
1943 }
1944
1945 static void object_panel_object(Object *ob)
1946 {
1947         uiBlock *block;
1948         uiBut *but;
1949         Group *group;
1950         int a, xco, yco=0;
1951         short dx= 33, dy= 30;
1952
1953         block= uiNewBlock(&curarea->uiblocks, "object_panel_object", UI_EMBOSS, UI_HELV, curarea->win);
1954         if(uiNewPanel(curarea, block, "Object and Links", "Object", 0, 0, 318, 204)==0) return;
1955         
1956         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
1957         
1958         /* object name */
1959         uiBlockSetCol(block, TH_BUT_SETTING2);
1960         xco= std_libbuttons(block, 10, 180, 0, NULL, 0, ID_OB, 0, &ob->id, NULL, &(G.buts->menunr), B_OBALONE, B_OBLOCAL, 0, 0, B_KEEPDATA);
1961         uiBlockSetCol(block, TH_AUTO);
1962         
1963         /* parent */
1964         uiDefIDPoinBut(block, test_obpoin_but, ID_OB, B_OBJECTPANELPARENT, "Par:", xco+5, 180, 305-xco, 20, &ob->parent, "Parent Object"); 
1965         
1966         but = uiDefButS(block, NUM, B_NOP, "PassIndex:",                xco+5, 150, 305-xco, 20, &ob->index, 0.0, 1000.0, 0, 0, "Index # for the IndexOB render pass.");
1967
1968         uiDefBlockBut(block, add_groupmenu, NULL, "Add to Group", 10,150,150,20, "Add Object to a new Group");
1969
1970         /* all groups */
1971         for(group= G.main->group.first; group; group= group->id.next) {
1972                 if(object_in_group(ob, group)) {
1973                         xco= 160;
1974                         
1975                         uiBlockBeginAlign(block);
1976                         but = uiDefBut(block, TEX, B_IDNAME, "GR:",     10, 120-yco, 150, 20, group->id.name+2, 0.0, 21.0, 0, 0, "Displays Group name. Click to change.");
1977                         uiButSetFunc(but, test_idbutton_cb, group->id.name, NULL);
1978                         
1979                         if(group->id.lib) {
1980                                 but= uiDefIconBut(block, BUT, B_NOP, ICON_PARLIB, 160, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Make Group local");
1981                                 uiButSetFunc(but, group_local, group, NULL);
1982                                 xco= 180;
1983                         }
1984                         but = uiDefIconBut(block, BUT, B_NOP, VICON_X, xco, 120-yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove Group membership");
1985                         uiButSetFunc(but, group_ob_rem, group, ob);
1986                         
1987                         yco+= 20;
1988                         xco= 10;
1989                         
1990                         /* layers */
1991                         uiBlockBeginAlign(block);
1992                         for(a=0; a<5; a++)
1993                                 uiDefButBitI(block, TOG, 1<<a, REDRAWVIEW3D, "",        (short)(xco+a*(dx/2)), 120-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
1994                         for(a=0; a<5; a++)
1995                                 uiDefButBitI(block, TOG, 1<<(a+10), REDRAWVIEW3D, "",   (short)(xco+a*(dx/2)), 105-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
1996                         
1997                         xco+= 7;
1998                         uiBlockBeginAlign(block);
1999                         for(a=5; a<10; a++)
2000                                 uiDefButBitI(block, TOG, 1<<a, REDRAWVIEW3D, "",        (short)(xco+a*(dx/2)), 120-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
2001                         for(a=5; a<10; a++)
2002                                 uiDefButBitI(block, TOG, 1<<(a+10), REDRAWVIEW3D, "",   (short)(xco+a*(dx/2)), 105-yco, (short)(dx/2), (short)(dy/2), (int *)&(group->layer), 0, 0, 0, 0, "");
2003                         
2004                         uiBlockEndAlign(block);
2005                         
2006                         yco+= 40;
2007                 }
2008         }
2009         
2010         if(120-yco < -10)
2011                 uiNewPanelHeight(block, 204 - (120-yco));
2012 }
2013
2014 static void object_panel_anim(Object *ob)
2015 {
2016         uiBlock *block;
2017         char str[32];
2018         
2019         block= uiNewBlock(&curarea->uiblocks, "object_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2020         if(uiNewPanel(curarea, block, "Anim settings", "Object", 320, 0, 318, 204)==0) return;
2021         
2022         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2023         
2024         uiBlockBeginAlign(block);
2025         uiDefButS(block, ROW,B_TRACKBUTS,"TrackX",      24,180,59,19, &ob->trackflag, 12.0, 0.0, 0, 0, "Specify the axis that points to another object");
2026         uiDefButS(block, ROW,B_TRACKBUTS,"Y",           85,180,19,19, &ob->trackflag, 12.0, 1.0, 0, 0, "Specify the axis that points to another object");
2027         uiDefButS(block, ROW,B_TRACKBUTS,"Z",           104,180,19,19, &ob->trackflag, 12.0, 2.0, 0, 0, "Specify the axis that points to another object");
2028         uiDefButS(block, ROW,B_TRACKBUTS,"-X",          124,180,24,19, &ob->trackflag, 12.0, 3.0, 0, 0, "Specify the axis that points to another object");
2029         uiDefButS(block, ROW,B_TRACKBUTS,"-Y",          150,180,24,19, &ob->trackflag, 12.0, 4.0, 0, 0, "Specify the axis that points to another object");
2030         uiDefButS(block, ROW,B_TRACKBUTS,"-Z",          178,180,24,19, &ob->trackflag, 12.0, 5.0, 0, 0, "Specify the axis that points to another object");
2031         uiBlockBeginAlign(block);
2032         uiDefButS(block, ROW,REDRAWVIEW3D,"UpX",        226,180,45,19, &ob->upflag, 13.0, 0.0, 0, 0, "Specify the axis that points up");
2033         uiDefButS(block, ROW,REDRAWVIEW3D,"Y",          274,180,20,19, &ob->upflag, 13.0, 1.0, 0, 0, "Specify the axis that points up");
2034         uiDefButS(block, ROW,REDRAWVIEW3D,"Z",          298,180,19,19, &ob->upflag, 13.0, 2.0, 0, 0, "Specify the axis that points up");
2035         
2036         uiBlockBeginAlign(block);
2037         uiDefButBitS(block, TOG, OB_DRAWKEY, REDRAWVIEW3D, "Draw Key",          24,155,71,19, &ob->ipoflag, 0, 0, 0, 0, "Draw object as key position");
2038         uiDefButBitS(block, TOG, OB_DRAWKEYSEL, REDRAWVIEW3D, "Draw Key Sel",   97,155,81,19, &ob->ipoflag, 0, 0, 0, 0, "Limit the drawing of object keys");
2039         uiDefButBitS(block, TOG, OB_POWERTRACK, REDRAWVIEW3D, "Powertrack",             180,155,78,19, &ob->transflag, 0, 0, 0, 0, "Switch objects rotation off");
2040         uiDefButBitS(block, TOG, PARSLOW, 0, "SlowPar",                                 260,155,56,19, &ob->partype, 0, 0, 0, 0, "Create a delay in the parent relationship");
2041         uiBlockBeginAlign(block);
2042         
2043         uiDefButBitS(block, TOG, OB_DUPLIFRAMES, B_DUPLI_FRAME, "DupliFrames",  24,130,95,20, &ob->transflag, 0, 0, 0, 0, "Make copy of object for every frame");
2044         uiDefButBitS(block, TOG, OB_DUPLIVERTS, B_DUPLI_VERTS, "DupliVerts",            119,130,95,20, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all vertices");
2045         uiDefButBitS(block, TOG, OB_DUPLIFACES, B_DUPLI_FACES, "DupliFaces",            214,130,102,20, &ob->transflag, 0, 0, 0, 0, "Duplicate child objects on all faces");
2046         uiDefButBitS(block, TOG, OB_DUPLIGROUP, B_DUPLI_GROUP, "DupliGroup",            24,110,150,20, &ob->transflag, 0, 0, 0, 0, "Enable group instancing");
2047         if(ob->transflag & OB_DUPLIFRAMES)
2048                 uiDefButBitS(block, TOG, OB_DUPLINOSPEED, REDRAWVIEW3D, "No Speed",             174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Set dupliframes to still, regardless of frame");
2049         else if(ob->transflag & OB_DUPLIVERTS)
2050                 uiDefButBitS(block, TOG, OB_DUPLIROT, REDRAWVIEW3D, "Rot",                              174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Rotate dupli according to vertex normal");
2051         else if(ob->transflag & OB_DUPLIFACES)
2052                 uiDefButBitS(block, TOG, OB_DUPLIFACES_SCALE, REDRAWVIEW3D, "Scale",                    174,110,142,20, &ob->transflag, 0, 0, 0, 0, "Scale dupli based on face size");
2053         else
2054                 uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_GROUP_RELINK, "GR:", 174,110,142,20, &ob->dup_group, "Instance an existing group");
2055
2056         uiBlockBeginAlign(block);
2057         /* DupSta and DupEnd are both shorts, so the maxframe is greater then their range
2058         just limit the buttons to the max short */
2059         uiDefButI(block, NUM, REDRAWVIEW3D, "DupSta:",          24,85,141,19, &ob->dupsta, 1.0, 32767, 0, 0, "Specify startframe for Dupliframes");
2060         uiDefButI(block, NUM, REDRAWVIEW3D, "DupOn:",           170,85,146,19, &ob->dupon, 1.0, 1500.0, 0, 0, "Specify the number of frames to use between DupOff frames");
2061         uiDefButI(block, NUM, REDRAWVIEW3D, "DupEnd",           24,65,140,19, &ob->dupend, 1.0, 32767, 0, 0, "Specify endframe for Dupliframes");
2062         uiDefButI(block, NUM, REDRAWVIEW3D, "DupOff",           171,65,145,19, &ob->dupoff, 0.0, 1500.0, 0, 0, "Specify recurring frames to exclude from the Dupliframes");
2063         uiBlockBeginAlign(block);
2064         uiDefButBitS(block, TOG, OB_OFFS_OB, REDRAWALL, "Offs Ob",                      24,35,56,20, &ob->ipoflag, 0, 0, 0, 0, "Not functional at the moment!");
2065         uiDefButBitS(block, TOG, OB_OFFS_PARENT, REDRAWALL, "Offs Par",                 82,35,56,20 , &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the parent");
2066         uiDefButBitS(block, TOG, OB_OFFS_PARTICLE, REDRAWALL, "Offs Particle",          140,35,103,20, &ob->ipoflag, 0, 0, 0, 0, "Let the timeoffset work on the particle effect");
2067         
2068         uiBlockBeginAlign(block);
2069         uiDefButF(block, NUM, REDRAWALL, "TimeOffset:",                 24,10,115,20, &ob->sf, -MAXFRAMEF, MAXFRAMEF, 100, 0, "Specify an offset in frames");
2070         uiDefBut(block, BUT, B_AUTOTIMEOFS, "Automatic Time",   139,10,104,20, 0, 0, 0, 0, 0, "Generate automatic timeoffset values for all selected frames");
2071         uiDefBut(block, BUT, B_PRINTSPEED,      "PrSpeed",                      248,10,67,20, 0, 0, 0, 0, 0, "Print objectspeed");
2072         uiBlockEndAlign(block);
2073         
2074         sprintf(str, "%.4f", prspeed);
2075         uiDefBut(block, LABEL, 0, str,                                                  247,35,63,31, NULL, 1.0, 0, 0, 0, "");
2076         
2077 }
2078
2079 static void object_panel_draw(Object *ob)
2080 {
2081         uiBlock *block;
2082         int xco, a, dx, dy;
2083         
2084         block= uiNewBlock(&curarea->uiblocks, "object_panel_draw", UI_EMBOSS, UI_HELV, curarea->win);
2085         if(uiNewPanel(curarea, block, "Draw", "Object", 640, 0, 318, 204)==0) return;
2086         
2087         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2088         
2089         /* LAYERS */
2090         xco= 120;
2091         dx= 35;
2092         dy= 30;
2093         
2094         uiDefBut(block, LABEL, 0, "Layers",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
2095         
2096         uiBlockBeginAlign(block);
2097         for(a=0; a<5; a++)
2098                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2099         for(a=0; a<5; a++)
2100                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2101         
2102         xco+= 7;
2103         uiBlockBeginAlign(block);
2104         for(a=5; a<10; a++)
2105                 uiDefButBitI(block, TOG, 1<<a, B_OBLAY+a, "",   (short)(xco+a*(dx/2)), 180, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2106         for(a=5; a<10; a++)
2107                 uiDefButBitI(block, TOG, 1<<(a+10), B_OBLAY+a+10, "",   (short)(xco+a*(dx/2)), 165, (short)(dx/2), (short)(dy/2), (int *)&(BASACT->lay), 0, 0, 0, 0, "");
2108         
2109         uiBlockEndAlign(block);
2110         
2111         uiDefBut(block, LABEL, 0, "Drawtype",                                           10,120,100,20, NULL, 0, 0, 0, 0, "");
2112         
2113         uiBlockBeginAlign(block);
2114         uiDefButC(block, ROW, REDRAWVIEW3D, "Shaded",   10,100,100, 20, &ob->dt, 0, OB_SHADED, 0, 0, "Draw active object shaded or textured");
2115         uiDefButC(block, ROW, REDRAWVIEW3D, "Solid",    10,80,100, 20, &ob->dt, 0, OB_SOLID, 0, 0, "Draw active object in solid");
2116         uiDefButC(block, ROW, REDRAWVIEW3D, "Wire",             10,60, 100, 20, &ob->dt, 0, OB_WIRE, 0, 0, "Draw active object in wireframe");
2117         uiDefButC(block, ROW, REDRAWVIEW3D, "Bounds",   10,40, 100, 20, &ob->dt, 0, OB_BOUNDBOX, 0, 0, "Only draw object with bounding box");
2118         uiBlockEndAlign(block);
2119         
2120         uiDefBut(block, LABEL, 0, "Draw Extra",                                                 120,120,90,20, NULL, 0, 0, 0, 0, "");
2121         
2122         uiBlockBeginAlign(block);
2123         uiDefButBitC(block, TOG, OB_BOUNDBOX, REDRAWVIEW3D, "Bounds",                           120, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's bounds");
2124         uiDefButBitC(block, TOG, OB_DRAWNAME, REDRAWVIEW3D, "Name",             210, 100, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's name");
2125         
2126         uiDefButS(block, MENU, REDRAWVIEW3D, "Boundary Display%t|Box%x0|Sphere%x1|Cylinder%x2|Cone%x3|Polyheder%x4",
2127                           120, 80, 90, 20, &ob->boundtype, 0, 0, 0, 0, "Selects the boundary display type");
2128         uiDefButBitC(block, TOG, OB_AXIS, REDRAWVIEW3D, "Axis",                 210, 80, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's center and axis");
2129         
2130         uiDefButBitC(block, TOG, OB_TEXSPACE, REDRAWVIEW3D, "TexSpace", 120, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Displays the active object's texture space");
2131         uiDefButBitC(block, TOG, OB_DRAWWIRE, REDRAWVIEW3D, "Wire",             210, 60, 90, 20, &ob->dtx, 0, 0, 0, 0, "Adds the active object's wireframe over solid drawing");
2132         
2133         uiDefButBitC(block, TOG, OB_DRAWTRANSP, REDRAWVIEW3D, "Transp", 120, 40, 90, 20, &ob->dtx, 0, 0, 0, 0, "Enables transparent materials for the active object (Mesh only)");
2134         uiDefButBitC(block, TOG, OB_DRAWXRAY, REDRAWVIEW3D, "X-ray",    210, 40, 90, 20, &ob->dtx, 0, 0, 0, 0, "Makes the active object draw in front of others");
2135         
2136 }
2137
2138 void object_panel_constraint(char *context)
2139 {
2140         uiBlock *block;
2141         Object *ob= OBACT;
2142         ListBase *conlist;
2143         bConstraint *curcon;
2144         short xco, yco;
2145         char str[64];
2146         
2147         block= uiNewBlock(&curarea->uiblocks, "object_panel_constraint", UI_EMBOSS, UI_HELV, curarea->win);
2148         if(uiNewPanel(curarea, block, "Constraints", context, 960, 0, 318, 204)==0) return;
2149         
2150         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2151         
2152         /* this is a variable height panel, newpanel doesnt force new size on existing panels */
2153         /* so first we make it default height */
2154         uiNewPanelHeight(block, 204);
2155         
2156         if(G.obedit==OBACT) return;     // ??
2157         
2158         conlist = get_active_constraints(OBACT);
2159         
2160         if (conlist) {
2161                 
2162                 uiDefBlockBut(block, add_constraintmenu, NULL, "Add Constraint", 0, 190, 130, 20, "Add a new constraint");
2163                 
2164                 /* print active object or bone */
2165                 str[0]= 0;
2166                 if (ob->flag & OB_POSEMODE){
2167                         bPoseChannel *pchan= get_active_posechannel(ob);
2168                         if(pchan) sprintf(str, "To Bone: %s", pchan->name);
2169                 }
2170                 else {
2171                         sprintf(str, "To Object: %s", ob->id.name+2);
2172                 }
2173                 uiDefBut(block, LABEL, 1, str,  150, 190, 150, 20, NULL, 0.0, 0.0, 0, 0, "Displays Active Object or Bone name");
2174                 
2175                 /* Go through the list of constraints and draw them */
2176                 xco = 10;
2177                 yco = 160;
2178                 
2179                 for (curcon = conlist->first; curcon; curcon=curcon->next) {
2180                         /* hrms, the temporal constraint should not draw! */
2181                         if(curcon->type==CONSTRAINT_TYPE_KINEMATIC) {
2182                                 bKinematicConstraint *data= curcon->data;
2183                                 if(data->flag & CONSTRAINT_IK_TEMP)
2184                                         continue;
2185                         }
2186                         /* Draw default constraint header */
2187                         draw_constraint(block, conlist, curcon, &xco, &yco);    
2188                 }
2189                 
2190                 if(yco < 0) uiNewPanelHeight(block, 204-yco);
2191                 
2192         }
2193 }
2194
2195 void do_effects_panels(unsigned short event)
2196 {
2197         Object *ob;
2198         Base *base;
2199         Effect *eff, *effn;
2200         PartEff *paf;
2201         
2202         ob= OBACT;
2203
2204         switch(event) {
2205
2206     case B_AUTOTIMEOFS:
2207                 auto_timeoffs();
2208                 break;
2209         case B_FRAMEMAP:
2210                 G.scene->r.framelen= G.scene->r.framapto;
2211                 G.scene->r.framelen/= G.scene->r.images;
2212                 allqueue(REDRAWALL, 0);
2213                 break;
2214         case B_NEWEFFECT:
2215                 if(ob) {
2216                         if(ob->fluidsimFlag & OB_FLUIDSIM_ENABLE) { 
2217                                 // NT particles and fluid meshes currently dont work together -> switch off beforehand
2218                                 if(ob->fluidsimSettings->type == OB_FLUIDSIM_DOMAIN) {
2219                                         pupmenu("Fluidsim Particle Error%t|Please disable the fluidsim domain before activating particles.%x0");
2220                                         break;
2221                                         //ob->fluidsimFlag = 0; ob->fluidsimSettings->type = 0; allqueue(REDRAWVIEW3D, 0); 
2222                                 }
2223                         }
2224                         if (BLI_countlist(&ob->effect)==MAX_EFFECT)
2225                                 error("Unable to add: effect limit reached");
2226                         else
2227                                 copy_act_effect(ob);
2228                 }
2229                 DAG_scene_sort(G.scene);
2230                 BIF_undo_push("New effect");
2231                 allqueue(REDRAWBUTSOBJECT, 0);
2232                 break;
2233         case B_DELEFFECT:
2234                 if(ob==NULL || ob->type!=OB_MESH) break;
2235                 eff= ob->effect.first;
2236                 while(eff) {
2237                         effn= eff->next;
2238                         if(eff->flag & SELECT) {
2239                                 BLI_remlink(&ob->effect, eff);
2240                                 free_effect(eff);
2241                                 break;
2242                         }
2243                         eff= effn;
2244                 }
2245                 BIF_undo_push("Delete effect");
2246                 allqueue(REDRAWVIEW3D, 0);
2247                 allqueue(REDRAWBUTSOBJECT, 0);
2248                 break;
2249         case B_NEXTEFFECT:
2250                 if(ob==0 || ob->type!=OB_MESH) break;
2251                 eff= ob->effect.first;
2252                 while(eff) {
2253                         if(eff->flag & SELECT) {
2254                                 if(eff->next) {
2255                                         eff->flag &= ~SELECT;
2256                                         eff->next->flag |= SELECT;
2257                                 }
2258                                 break;
2259                         }
2260                         eff= eff->next;
2261                 }
2262                 allqueue(REDRAWBUTSOBJECT, 0);
2263                 break;
2264         case B_PREVEFFECT:
2265                 if(ob==0 || ob->type!=OB_MESH) break;
2266                 eff= ob->effect.first;
2267                 while(eff) {
2268                         if(eff->flag & SELECT) {
2269                                 if(eff->prev) {
2270                                         eff->flag &= ~SELECT;
2271                                         eff->prev->flag |= SELECT;
2272                                 }
2273                                 break;
2274                         }
2275                         eff= eff->next;
2276                 }
2277                 allqueue(REDRAWBUTSOBJECT, 0);
2278                 break;
2279         case B_EFFECT_DEP:
2280                 DAG_scene_sort(G.scene);
2281                 /* no break, pass on */
2282         case B_CALCEFFECT:
2283                 if(ob==NULL || ob->type!=OB_MESH) break;
2284                 eff= ob->effect.first;
2285                 while(eff) {
2286                         if(eff->flag & SELECT) {
2287                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
2288                         }
2289                         eff= eff->next;
2290                 }
2291                 allqueue(REDRAWVIEW3D, 0);
2292                 allqueue(REDRAWBUTSOBJECT, 0);
2293                 break;
2294         case B_PAF_SET_VG:
2295                 
2296                 paf= give_parteff(ob);
2297                 if(paf) {
2298                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname);
2299                         if(dg)
2300                                 paf->vertgroup= get_defgroup_num(ob, dg)+1;
2301                         else
2302                                 paf->vertgroup= 0;
2303                         
2304                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2305                         allqueue(REDRAWVIEW3D, 0);
2306                 }
2307                 break;
2308         case B_PAF_SET_VG1:
2309                 
2310                 paf= give_parteff(ob);
2311                 if(paf) {
2312                         bDeformGroup *dg= get_named_vertexgroup(ob, paf->vgroupname_v);
2313                         if(dg)
2314                                 paf->vertgroup_v= get_defgroup_num(ob, dg)+1;
2315                         else
2316                                 paf->vertgroup_v= 0;
2317                         
2318                         DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
2319                         allqueue(REDRAWVIEW3D, 0);
2320                 }
2321                 break;
2322         case B_FIELD_DEP:
2323                 /* do this before scene sort, that one checks for CU_PATH */
2324                 if(ob->type==OB_CURVE && ob->pd->forcefield==PFIELD_GUIDE) {
2325                         Curve *cu= ob->data;
2326                         
2327                         cu->flag |= (CU_PATH|CU_3D);
2328                         do_curvebuts(B_CU3D);   /* all curves too */
2329                 }
2330                 DAG_scene_sort(G.scene);
2331
2332                 if(ob->type==OB_CURVE && ob->pd->forcefield==PFIELD_GUIDE)
2333                         DAG_object_flush_update(G.scene, ob, OB_RECALC);
2334                 else
2335                         DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2336
2337                 allqueue(REDRAWVIEW3D, 0);
2338                 allqueue(REDRAWBUTSOBJECT, 0);
2339                 break;
2340         case B_FIELD_CHANGE:
2341                 DAG_object_flush_update(G.scene, ob, OB_RECALC_OB);
2342                 allqueue(REDRAWVIEW3D, 0);
2343                 break;
2344         case B_RECALCAL:
2345                 if (G.vd==NULL)
2346                         break;
2347                 
2348                 base= FIRSTBASE;
2349                 while(base) {
2350                         if(base->lay & G.vd->lay) {
2351                                 ob= base->object;
2352                                 eff= ob->effect.first;
2353                                 while(eff) {
2354                                         if(eff->flag & SELECT) {
2355                                                 if(eff->type==EFF_PARTICLE) build_particle_system(ob);
2356                                         }
2357                                         eff= eff->next;
2358                                 }
2359                         }
2360                         base= base->next;
2361                 }
2362                 allqueue(REDRAWVIEW3D, 0);
2363                 break;
2364         default:
2365                 if(event>=B_SELEFFECT && event<B_SELEFFECT+MAX_EFFECT) {
2366                         ob= OBACT;
2367                         if(ob) {
2368                                 int a=B_SELEFFECT;
2369                                 
2370                                 eff= ob->effect.first;
2371                                 while(eff) {
2372                                         if(event==a) eff->flag |= SELECT;
2373                                         else eff->flag &= ~SELECT;
2374                                         
2375                                         a++;
2376                                         eff= eff->next;
2377                                 }
2378                                 allqueue(REDRAWBUTSOBJECT, 0);
2379                         }
2380                 }
2381         }
2382
2383 }
2384
2385 /* Panel for particle interaction settings */
2386 static void object_panel_fields(Object *ob)
2387 {
2388         uiBlock *block;
2389
2390         block= uiNewBlock(&curarea->uiblocks, "object_panel_fields", UI_EMBOSS, UI_HELV, curarea->win);
2391         if(uiNewPanel(curarea, block, "Fields and Deflection", "Physics", 0, 0, 318, 204)==0) return;
2392
2393         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2394         
2395         /* should become button, option? */
2396         if(ob->pd==NULL) {
2397                 ob->pd= MEM_callocN(sizeof(PartDeflect), "PartDeflect");
2398                 /* and if needed, init here */
2399                 ob->pd->pdef_sbdamp = 0.1f;
2400                 ob->pd->pdef_sbift  = 0.2f;
2401                 ob->pd->pdef_sboft  = 0.02f;
2402         }
2403         
2404         if(ob->pd) {
2405                 PartDeflect *pd= ob->pd;
2406                 char *menustr= MEM_mallocN(256, "temp string");
2407                 char *tipstr="Choose field type";
2408                 
2409                 uiDefBut(block, LABEL, 0, "Fields",             10,180,140,20, NULL, 0.0, 0, 0, 0, "");
2410                 
2411                 /* setup menu button */
2412                 sprintf(menustr, "Field Type%%t|None %%x0|Spherical %%x%d|Wind %%x%d|Vortex %%x%d|Curve Guide %%x%d", 
2413                                 PFIELD_FORCE, PFIELD_WIND, PFIELD_VORTEX, PFIELD_GUIDE);
2414                 
2415                 if(pd->forcefield==PFIELD_FORCE) tipstr= "Object center attracts or repels particles";
2416                 else if(pd->forcefield==PFIELD_WIND) tipstr= "Constant force applied in direction of Object Z axis";
2417                 else if(pd->forcefield==PFIELD_VORTEX) tipstr= "Particles swirl around Z-axis of the Object";
2418                 else if(pd->forcefield==PFIELD_GUIDE) tipstr= "Use a Curve Path to guide particles";
2419                 
2420                 uiDefButS(block, MENU, B_FIELD_DEP, menustr,                    10,160,140,20, &pd->forcefield, 0.0, 0.0, 0, 0, tipstr);
2421                 MEM_freeN(menustr);
2422                 
2423                 if(pd->forcefield) {
2424                         uiBlockBeginAlign(block);
2425                         if(pd->forcefield == PFIELD_GUIDE) {
2426                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "MinDist: ",      10,120,140,20, &pd->f_strength, 0.0, 1000.0, 10, 0, "The distance from which particles are affected fully.");
2427                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Fall-off: ",     10,100,140,20, &pd->f_power, 0.0, 10.0, 10, 0, "Falloff factor, between mindist and maxdist");
2428                         }
2429                         else {  
2430                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Strength: ",     10,110,140,20, &pd->f_strength, -1000, 1000, 10, 0, "Strength of force field");
2431                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Fall-off: ",     10,90,140,20, &pd->f_power, 0, 10, 10, 0, "Falloff power (real gravitational fallof = 2)");
2432                         }
2433                         
2434                         uiBlockBeginAlign(block);
2435                         uiDefButBitS(block, TOG, PFIELD_USEMAX, B_FIELD_CHANGE, "Use MaxDist",  10,60,140,20, &pd->flag, 0.0, 0, 0, 0, "Use a maximum distance for the field to work");
2436                         uiDefButF(block, NUM, B_FIELD_CHANGE, "MaxDist: ",      10,40,140,20, &pd->maxdist, 0, 1000.0, 10, 0, "Maximum distance for the field to work");
2437                         uiBlockEndAlign(block);
2438                         
2439                         if(pd->forcefield == PFIELD_GUIDE)
2440                                 uiDefButBitS(block, TOG, PFIELD_GUIDE_PATH_ADD, B_FIELD_CHANGE, "Additive",     10,10,140,20, &pd->flag, 0.0, 0, 0, 0, "Based on distance/falloff it adds a portion of the entire path");
2441                         
2442                 }
2443                 
2444                 uiDefBut(block, LABEL, 0, "Deflection", 160,180,140,20, NULL, 0.0, 0, 0, 0, "");
2445                         
2446                 /* only meshes collide now */
2447                 if(ob->type==OB_MESH) {
2448                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",160,160,150,20, &pd->deflect, 0, 0, 0, 0, "Deflects particles based on collision");
2449                         if(pd->deflect) {
2450                                 uiDefBut(block, LABEL, 0, "Particles",                  160,140,150,20, NULL, 0.0, 0, 0, 0, "");
2451                                 
2452                                 uiBlockBeginAlign(block);
2453                                 uiDefButF(block, NUM, B_DIFF, "Damping: ",              160,120,150,20, &pd->pdef_damp, 0.0, 1.0, 10, 0, "Amount of damping during particle collision");
2454                                 uiDefButF(block, NUM, B_DIFF, "Rnd Damping: ",  160,100,150,20, &pd->pdef_rdamp, 0.0, 1.0, 10, 0, "Random variation of damping");
2455                                 uiDefButF(block, NUM, B_DIFF, "Permeability: ", 160,80,150,20, &pd->pdef_perm, 0.0, 1.0, 10, 0, "Chance that the particle will pass through the mesh");
2456                                 uiBlockEndAlign(block);
2457                                 
2458                                 uiDefBut(block, LABEL, 0, "Soft Body",                  160,60,150,20, NULL, 0.0, 0, 0, 0, "");
2459
2460                                 uiBlockBeginAlign(block);
2461                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Damping:",       160,40,150,20, &pd->pdef_sbdamp, 0.0, 1.0, 10, 0, "Amount of damping during soft body collision");
2462                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Inner:", 160,20,150,20, &pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2463                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Outer:", 160, 0,150,20, &pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2464                         }
2465                 }               
2466         }
2467 }
2468
2469
2470 /* Panel for softbodies */
2471 static void object_softbodies__enable(void *ob_v, void *arg2)
2472 {
2473         Object *ob = ob_v;
2474         ModifierData *md = modifiers_findByType(ob, eModifierType_Softbody);
2475
2476         if (modifiers_isSoftbodyEnabled(ob)) {
2477                 if (md) {
2478                         md->mode &= ~(eModifierMode_Render|eModifierMode_Realtime);
2479                 }
2480         } else {
2481                 if (!md) {
2482                         md = modifier_new(eModifierType_Softbody);
2483                         BLI_addhead(&ob->modifiers, md);
2484                 }
2485
2486                 md->mode |= eModifierMode_Render|eModifierMode_Realtime;
2487
2488                 if (!ob->soft) {
2489                         ob->soft= sbNew();
2490                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
2491                 }
2492         }
2493
2494         allqueue(REDRAWBUTSEDIT, 0);
2495 }
2496
2497 static void object_softbodies_II(Object *ob)
2498 {
2499         uiBlock *block;
2500         static int val;
2501
2502         block= uiNewBlock(&curarea->uiblocks, "object_softbodies_II", UI_EMBOSS, UI_HELV, curarea->win);
2503         uiNewPanelTabbed("Soft Body", "Physics");
2504         if(uiNewPanel(curarea, block, "Soft Body Collision", "Physics", 651, 0, 318, 204)==0) return;
2505
2506         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2507
2508         val = modifiers_isSoftbodyEnabled(ob);
2509         if(!val) {
2510                 uiDefBut(block, LABEL, 0, "",10,10,1,2, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2511                 uiBlockBeginAlign(block);
2512                 uiDefBut(block, LABEL, 0, "Object is not a softbody",10,190,300,20, NULL, 0.0, 0, 0, 0, ""); 
2513                 uiDefBut(block, LABEL, 0, "However it can deflect a softbody",10,170,300,20, NULL, 0.0, 0, 0, 0, ""); 
2514                 /* OTHER OBJECTS COLLISION STUFF */
2515                 if (ob->type==OB_MESH){
2516                         uiBlockBeginAlign(block);
2517                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",10,50,150,20, &ob->pd->deflect, 0, 0, 0, 0, "Makes this object visible to softbody objects");
2518                         if(ob->pd->deflect) {
2519                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Damping:",       160,50,150,20, &ob->pd->pdef_sbdamp, 0.0, 1.0, 10, 0, "Amount of damping during soft body collision");
2520                             uiDefButBitS(block, TOG,OB_SB_COLLFINAL , B_DIFF, "Ev.M.Stack",10,30,150,20, &ob->softflag, 0, 0, 0, 0, "Pick collision object from modifier stack");
2521                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Inner:", 160,30,150,20, &ob->pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2522                                 uiDefButF(block, NUM, B_FIELD_CHANGE, "Outer:", 160,10,150,20, &ob->pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2523                         }
2524                 }
2525                 uiBlockEndAlign(block);
2526         }
2527         else{
2528                 SoftBody *sb= ob->soft;
2529                 /* SELF COLLISION STUFF */
2530                 if ((ob->type==OB_MESH)||(ob->type==OB_CURVE) ) {
2531                         uiBlockBeginAlign(block);
2532                         if (ob->softflag & OB_SB_EDGES){
2533                                 uiDefButBitS(block, TOG, OB_SB_SELF, B_SOFTBODY_CHANGE, "Self Collision",               10,170,150,20, &ob->softflag, 0, 0, 0, 0, "enable naive vertex ball self collision");
2534                                 if(ob->softflag & OB_SB_SELF){
2535                                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Ball Size:", 160,170,150,20, &sb->colball, -10.0,  10.0, 10, 0, "Absolute ball size or factor if not manual adjusted");
2536                                         uiDefButS(block, ROW, B_DIFF, "Man",10,150,60,20, &sb->sbc_mode, 4.0,(float)0, 0, 0, "Manual adjust");
2537                                         uiDefButS(block, ROW, B_DIFF, "Av",70,150,60,20, &sb->sbc_mode, 4.0,(float)1, 0, 0, "Average Spring lenght * Ball Size");
2538                                         uiDefButS(block, ROW, B_DIFF, "Min",130,150,60,20, &sb->sbc_mode, 4.0,(float)2, 0, 0, "Minimal Spring lenght * Ball Size");
2539                                         uiDefButS(block, ROW, B_DIFF, "Max",190,150,60,20, &sb->sbc_mode, 4.0,(float)3, 0, 0, "Maximal Spring lenght * Ball Size");
2540                                         uiDefButS(block, ROW, B_DIFF, "AvMiMa",250,150,60,20, &sb->sbc_mode, 4.0,(float)4, 0, 0, "(Min+Max)/2 * Ball Size");
2541                                         uiDefButF(block, NUM, B_DIFF, "B Stiff:", 10,130,150,20, &sb->ballstiff, 0.001,  100.0, 10, 0, "Ball inflating presure");
2542                                         uiDefButF(block, NUM, B_DIFF, "B Damp:", 160,130,150,20, &sb->balldamp,  0.001,  1.0, 10, 0, "Blending to inelastic collision");
2543                                 }
2544                         }
2545                         else{
2546                                 uiDefBut(block, LABEL, 0, "<Self Collision> not available because there",10,170,300,20, NULL, 0.0, 0, 0, 0, ""); 
2547                                 uiDefBut(block, LABEL, 0, "are no edges, enable <Use Edges>",10,150,300,20, NULL, 0.0, 0, 0, 0, ""); 
2548                         }
2549
2550                         uiBlockEndAlign(block);
2551                         /*SOLVER SETTINGS*/
2552                         uiDefButF(block, NUM, B_DIFF, "Error Lim:",     10,100,130,20, &sb->rklimit , 0.001, 10.0, 10, 0, "The Runge-Kutta ODE solver error limit, low value gives more precision, high values speed");
2553                         uiDefButBitS(block, TOG, SBSO_OLDERR, B_DIFF,"O", 140,100,20,20, &sb->solverflags,  0,  0, 0, 0, "Old Error Calculation");
2554                         uiDefButS(block, NUM, B_DIFF, "Fuzzy:", 160,100,130,20, &sb->fuzzyness,  1.00,  100.0, 10, 0, "Fuzzyness while on collision, high values make collsion handling faster but less stable");
2555                         uiDefButBitS(block, TOG, SBSO_MONITOR, B_DIFF,"M", 290,100,20,20, &sb->solverflags,  0,  0, 0, 0, "Turn on SB diagnose console prints");
2556                         uiDefButS(block, NUM, B_DIFF, "MinS:", 10,80,100,20, &sb->minloops,  0.00,  30000.0, 10, 0, "Minimal # solver steps/frame ");
2557                         uiDefButS(block, NUM, B_DIFF, "MaxS:", 110,80,100,20, &sb->maxloops,  0.00,  30000.0, 10, 0, "Maximal # solver steps/frame ");
2558                         uiDefButS(block, NUM, B_DIFF, "Choke:", 210,80,100,20, &sb->choke, 0.00,  100.0, 10, 0, "'Viscosity' inside collision target ");
2559                 }
2560                 /* OTHER OBJECTS COLLISION STUFF */
2561                 if (ob->type==OB_MESH){
2562                         uiDefButBitS(block, TOG, 1, B_REDR, "Deflection",10,50,150,20, &ob->pd->deflect, 0, 0, 0, 0, "Makes this object visible to other softbody objects");
2563                         if(ob->pd->deflect) {
2564                                 uiDefButF(block, NUM, B_DIFF, "Damping:",       160,50,150,20, &ob->pd->pdef_sbdamp, 0.0, 1.0, 10, 0, "Amount of damping during soft body collision");
2565                             uiDefButBitS(block, TOG,OB_SB_COLLFINAL , B_DIFF, "Ev.M.Stack",10,30,150,20, &ob->softflag, 0, 0, 0, 0, "Pick collision object from modifier stack");
2566                                 uiDefButF(block, NUM, B_DIFF, "Inner:", 160,30,150,20, &ob->pd->pdef_sbift, 0.001, 1.0, 10, 0, "Inner face thickness");
2567                                 uiDefButF(block, NUM, B_DIFF, "Outer:", 160,10,150,20, &ob->pd->pdef_sboft, 0.001, 1.0, 10, 0, "Outer face thickness");
2568                         }
2569                 }
2570                 uiDefBut(block, LABEL, 0, "",10,10,1,2, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2571         }
2572         uiBlockEndAlign(block);
2573 }
2574
2575 static void object_softbodies(Object *ob)
2576 {
2577         uiBlock *block;
2578         static int val;
2579         uiBut *but;
2580         block= uiNewBlock(&curarea->uiblocks, "object_softbodies", UI_EMBOSS, UI_HELV, curarea->win);
2581         if(uiNewPanel(curarea, block, "Soft Body", "Physics", 640, 0, 318, 204)==0) return;
2582
2583         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2584
2585         val = modifiers_isSoftbodyEnabled(ob);
2586         but = uiDefButI(block, TOG, REDRAWBUTSOBJECT, "Soft Body",      10,200,130,20, &val, 0, 0, 0, 0, "Sets object to become soft body");
2587         uiButSetFunc(but, object_softbodies__enable, ob, NULL);
2588         uiDefBut(block, LABEL, 0, "",10,10,300,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2589
2590         if(modifiers_isSoftbodyEnabled(ob)){
2591                 SoftBody *sb= ob->soft;
2592                 int defCount;
2593                 char *menustr;
2594
2595                 if(sb==NULL) {
2596                         sb= ob->soft= sbNew();
2597                         ob->softflag |= OB_SB_GOAL|OB_SB_EDGES;
2598                 }
2599
2600                 uiDefButBitS(block, TOG, OB_SB_BAKESET, REDRAWBUTSOBJECT, "Bake settings",      180,200,130,20, &ob->softflag, 0, 0, 0, 0, "To convert simulation into baked (cached) result");
2601
2602                 if(sb->keys) uiSetButLock(1, "Soft Body is baked, free it first");
2603
2604                 if(ob->softflag & OB_SB_BAKESET) {
2605                         uiBlockBeginAlign(block);
2606                         uiDefButI(block, NUM, B_DIFF, "Start:",                 10, 170,100,20, &sb->sfra, 1.0, 10000.0, 10, 0, "Start frame for baking");
2607                         uiDefButI(block, NUM, B_DIFF, "End:",                   110, 170,100,20, &sb->efra, 1.0, 10000.0, 10, 0, "End frame for baking");
2608                         uiDefButI(block, NUM, B_DIFF, "Interval:",              210, 170,100,20, &sb->interval, 1.0, 10.0, 10, 0, "Interval in frames between baked keys");
2609                         uiBlockEndAlign(block);
2610
2611                         uiDefButS(block, TOG, B_DIFF, "Local",                  10, 145,100,20, &sb->local, 0.0, 0.0, 0, 0, "Use local coordinates for baking");
2612
2613
2614                         uiClearButLock();
2615                         uiBlockBeginAlign(block);
2616
2617                         if(sb->keys) {
2618                                 char str[128];
2619                                 uiDefIconTextBut(block, BUT, B_SOFTBODY_BAKE_FREE, ICON_X, "FREE BAKE", 10, 120,300,20, NULL, 0.0, 0.0, 0, 0, "Free baked result");
2620                                 sprintf(str, "Stored %d vertices %d keys %.3f MB", sb->totpoint, sb->totkey, ((float)16*sb->totpoint*sb->totkey)/(1024.0*1024.0));
2621                                 uiDefBut(block, LABEL, 0, str, 10, 100,300,20, NULL, 0.0, 0.0, 00, 0, "");
2622                         }
2623                         else                            
2624                                 uiDefBut(block, BUT, B_SOFTBODY_BAKE, "BAKE",   10, 120,300,20, NULL, 0.0, 0.0, 10, 0, "Start baking. Press ESC to exit without baking");
2625
2626                 }
2627                 else {
2628                         /* GENERAL STUFF */
2629                         static char str[128];
2630                         if (sb->totpoint){
2631                         sprintf(str, "Vertex Mass; Object mass %f [k]",sb->nodemass*sb->totpoint/1000.0f);
2632                         }
2633                         else{
2634                         sprintf(str, "Vertex Mass");
2635                         }
2636                         uiBlockBeginAlign(block);
2637                         uiDefButF(block, NUM, B_DIFF, "Friction:", 10, 170,150,20, &sb->mediafrict, 0.0, 50.0, 10, 0, "General media friction for point movements");
2638                         uiDefButF(block, NUM, B_DIFF, "Mass:",     160, 170,150,20, &sb->nodemass , 0.001, 50000.0, 10, 0, str);
2639                         uiDefButF(block, NUM, B_DIFF, "Grav:",     10,150,150,20, &sb->grav , 0.0, 10.0, 10, 0, "Apply gravitation to point movement");
2640                         uiDefButF(block, NUM, B_DIFF, "Speed:",    160,150,150,20, &sb->physics_speed , 0.01, 100.0, 10, 0, "Tweak timing for physics to control frequency and speed");
2641                         uiBlockEndAlign(block);
2642
2643                         /* GOAL STUFF */
2644                         uiBlockBeginAlign(block);
2645                         uiDefButBitS(block, TOG, OB_SB_GOAL, B_SOFTBODY_CHANGE, "Use Goal",     10,120,130,20, &ob->softflag, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
2646                         if (ob->softflag & OB_SB_GOAL){
2647                                 if(ob->type==OB_MESH) {
2648                                         menustr= get_vertexgroup_menustr(ob);
2649                                         defCount=BLI_countlist(&ob->defbase);
2650                                         if(defCount==0) sb->vertgroup= 0;
2651                                         uiDefButS(block, MENU, B_SOFTBODY_CHANGE, menustr,      140,120,20,20, &sb->vertgroup, 0, defCount, 0, 0, "Browses available vertex groups");
2652                                         MEM_freeN (menustr);
2653
2654                                         if(sb->vertgroup) {
2655                                                 bDeformGroup *defGroup = BLI_findlink(&ob->defbase, sb->vertgroup-1);
2656                                                 if(defGroup)
2657                                                         uiDefBut(block, BUT, B_DIFF, defGroup->name,    160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Name of current vertex group");
2658                                                 else
2659                                                         uiDefBut(block, BUT, B_DIFF, "(no group)",      160,120,130,20, NULL, 0.0, 0.0, 0, 0, "Vertex Group doesn't exist anymore");
2660                                                 uiDefIconBut(block, BUT, B_SOFTBODY_DEL_VG, ICON_X, 290,120,20,20, 0, 0, 0, 0, 0, "Disable use of vertex group");
2661                                         }
2662                                         else
2663                                                 uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:",       160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
2664                                 }
2665                                 else {
2666                                         uiDefButS(block, TOG, B_SOFTBODY_CHANGE, "W",                   140,120,20,20, &sb->vertgroup, 0, 1, 0, 0, "Use control point weight values");
2667                                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Goal:",       160,120,150,20, &sb->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
2668                                 }
2669
2670                                 uiDefButF(block, NUM, B_DIFF, "G Stiff:",       10,100,150,20, &sb->goalspring, 0.0, 0.999, 10, 0, "Goal (vertex target position) spring stiffness");
2671                                 uiDefButF(block, NUM, B_DIFF, "G Damp:",        160,100,150,20, &sb->goalfrict  , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
2672                                 uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "G Min:",              10,80,150,20, &sb->mingoal, 0.0, 1.0, 10, 0, "Goal minimum, vertex group weights are scaled to match this range");
2673                                 uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "G Max:",              160,80,150,20, &sb->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
2674                         }
2675                         uiBlockEndAlign(block);
2676
2677                         /* EDGE SPRING STUFF */
2678                         if(ob->type!=OB_SURF) {
2679                                 uiBlockBeginAlign(block);
2680                                 uiDefButBitS(block, TOG, OB_SB_EDGES, B_SOFTBODY_CHANGE, "Use Edges",           10,50,90,20, &ob->softflag, 0, 0, 0, 0, "Use Edges as springs");
2681                         if (ob->softflag & OB_SB_EDGES){
2682                                 uiDefButBitS(block, TOG, OB_SB_QUADS, B_SOFTBODY_CHANGE, "Stiff Quads",         110,50,90,20, &ob->softflag, 0, 0, 0, 0, "Adds diagonal springs on 4-gons");
2683                                 uiDefButBitS(block, TOG, OB_SB_EDGECOLL, B_DIFF, "CEdge",               220,50,45,20, &ob->softflag, 0, 0, 0, 0, "Edge collide too"); 
2684                                 uiDefButBitS(block, TOG, OB_SB_FACECOLL, B_DIFF, "CFace",               265,50,45,20, &ob->softflag, 0, 0, 0, 0, "Faces collide too SLOOOOOW warning "); 
2685                                 uiDefButF(block, NUM, B_DIFF, "E Stiff:",       10,30,150,20, &sb->inspring, 0.0,  0.999, 10, 0, "Edge spring stiffness");
2686                                 uiDefButF(block, NUM, B_DIFF, "E Damp:",        160,30,150,20, &sb->infrict, 0.0,  50.0, 10, 0, "Edge spring friction");
2687                                 uiDefButS(block, NUM, B_DIFF, "Aero:",     10,10,150,20, &sb->aeroedge,  0.00,  30000.0, 10, 0, "Make edges 'sail'");
2688                                 if(ob->type==OB_MESH) {
2689                                         uiDefButF(block, NUM, B_SOFTBODY_CHANGE, "Rigidity:", 160,10,150,20, &sb->secondspring, 0.0,  10.0, 10, 0, "Strenght of Springs over 2 Edges");
2690                                 }
2691                                 else sb->secondspring = 0;
2692                                 uiDefBut(block, LABEL, 0, "",10,10,1,0, NULL, 0.0, 0, 0, 0, ""); /* tell UI we go to 10,10*/
2693                         }
2694                                 uiBlockEndAlign(block);
2695                         }
2696                 }
2697         }
2698         uiBlockEndAlign(block);
2699 }
2700
2701 static void object_panel_particles_motion(Object *ob)
2702 {
2703         uiBlock *block;
2704         uiBut *but;
2705         PartEff *paf= give_parteff(ob);
2706
2707         if (paf==NULL) return;
2708                 
2709         block= uiNewBlock(&curarea->uiblocks, "object_panel_particles_motion", UI_EMBOSS, UI_HELV, curarea->win);
2710         uiNewPanelTabbed("Particles ", "Physics");
2711         if(uiNewPanel(curarea, block, "Particle Motion", "Physics", 320, 0, 318, 204)==0) return;
2712         
2713         if(ob->id.lib) uiSetButLock(1, "Can't edit library data");
2714         
2715         /* top row */
2716         uiBlockBeginAlign(block);
2717         uiDefButI(block, NUM, B_CALCEFFECT, "Keys:",    0,180,75,20, &paf->totkey, 1.0, 100.0, 0, 0, "Specify the number of key positions");
2718         uiDefButBitS(block, TOG, PAF_BSPLINE, B_CALCEFFECT, "Bspline",  75,180,75,20, &paf->flag, 0, 0, 0, 0, "Use B spline formula for particle interpolation");
2719         uiDefButI(block, NUM, B_CALCEFFECT, "Seed:",    150,180,75,20, &paf->seed, 0.0, 255.0, 0, 0, "Set an offset in the random table");
2720         uiDefButF(block, NUM, B_CALCEFFECT, "RLife:",   225,180,85,20, &paf->randlife, 0.0, 2.0, 10, 1, "Give the particlelife a random variation");
2721         uiBlockEndAlign(block);
2722         
2723         /* left collumn */
2724         uiDefBut(block, LABEL, 0, "Velocity:",                  0,160,150,20, NULL, 0.0, 0, 0, 0, "");
2725         uiBlockBeginAlign(block);
2726         uiBlockSetCol(block, TH_BUT_SETTING2);
2727         uiDefButF(block, NUM, B_CALCEFFECT, "Normal:",          0,140,150,18, &paf->normfac, -2.0, 2.0, 1, 3, "Let the mesh give the particle a starting speed");
2728         uiDefButF(block, NUM, B_CALCEFFECT, "Object:",          0,122,150,18, &paf->obfac, -1.0, 1.0, 1, 3, "Let the object give the particle a starting speed");
2729         uiDefButF(block, NUM, B_CALCEFFECT, "Random:",          0,104,150,18, &paf->randfac, 0.0, 2.0, 1, 3, "Give the startingspeed a random variation");
2730         uiDefButF(block, NUM, B_CALCEFFECT, "Texture:",         0,86,150,18, &paf->texfac, 0.0, 2.0, 1, 3, "Let the texture give the particle a starting speed");
2731         uiDefButF(block, NUM, B_CALCEFFECT, "Damping:",         0,68,150,18, &paf->damp, 0.0, 1.0, 1, 3, "Specify the damping factor");
2732         uiBlockSetCol(block, TH_AUTO);
2733         but=uiDefBut(block, TEX, B_PAF_SET_VG1, "VGroup:",      0,50,150,18, paf->vgroupname_v, 0, 31, 0, 0, "Name of vertex group to use for speed control");
2734         uiButSetCompleteFunc(but, autocomplete_vgroup, (void *)OBACT);
2735         uiBlockEndAlign(block);
2736         
2737         uiDefBut(block, LABEL, 0, "Texture Emission",                   0,30,150,20, NULL, 0.0, 0, 0, 0, "");
2738         uiBlockBeginAlign(block);
2739         uiDefButBitS(block, TOG3, PAF_TEXTIME, B_CALCEFFECT, "TexEmit",         0,10,75,20, &(paf->flag2), 0, 0, 0, 0, "Use a texture to define emission of particles");
2740         uiDefButS(block, NUM, B_CALCEFFECT, "Tex:",             75,10,75,20, &paf->timetex, 1.0, 10.0, 0, 0, "Specify texture used for the texture emission");
2741         
2742         /* right collumn */
2743         uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_CALCEFFECT, "GR:", 160, 155, 150, 20, &paf->group, "Limit Force Fields to this Group"); 
2744
2745         uiBlockBeginAlign(block);
2746         uiDefBut(block, LABEL, 0, "Force:",                             160,130,75,20, NULL, 0.0, 0, 0, 0, "");
2747         uiDefButF(block, NUM, B_CALCEFFECT, "X:",               235,130,75,20, paf->force, -1.0, 1.0, 1, 2, "Specify the X axis of a continues force");
2748         uiDefButF(block, NUM, B_CALCEFFECT, "Y:",               160,110,75,20, paf->force+1,-1.0, 1.0, 1, 2, "Specify the Y axis of a continues force");
2749         uiDefButF(block, NUM, B_CALCEFFECT, "Z:",               235,110,75,20, paf->force+2, -1.0, 1.0, 1, 2, "Specify the Z axis of a continues force");
2750         
2751         uiBlockBeginAlign(block);
2752         uiDefButS(block, NUM, B_CALCEFFECT, "Tex:",             160,80,75,20, &paf->speedtex, 1.0, 10.0, 0, 2, "Specify the texture used for force");
2753         uiDefButF(block, NUM, B_CALCEFFECT, "X:",               235,80,75,20, paf->defvec, -1.0, 1.0, 1, 2, "Specify the X axis of a force, determined by the texture");